aboutsummaryrefslogtreecommitdiffstats
path: root/embed/mozilla/EphyUtils.cpp
diff options
context:
space:
mode:
authorChristian Persch <chpe@cvs.gnome.org>2006-06-19 02:52:03 +0800
committerChristian Persch <chpe@src.gnome.org>2006-06-19 02:52:03 +0800
commitc6573cb04bdc216e7e5ea3657cb1186eaf0f1095 (patch)
tree769cc33a1564a50d1414cb6b6b6f7306c1635840 /embed/mozilla/EphyUtils.cpp
parent0db1af2c76d4cae33992f82a1736f6ed743b7dc1 (diff)
downloadgsoc2013-epiphany-c6573cb04bdc216e7e5ea3657cb1186eaf0f1095.tar
gsoc2013-epiphany-c6573cb04bdc216e7e5ea3657cb1186eaf0f1095.tar.gz
gsoc2013-epiphany-c6573cb04bdc216e7e5ea3657cb1186eaf0f1095.tar.bz2
gsoc2013-epiphany-c6573cb04bdc216e7e5ea3657cb1186eaf0f1095.tar.lz
gsoc2013-epiphany-c6573cb04bdc216e7e5ea3657cb1186eaf0f1095.tar.xz
gsoc2013-epiphany-c6573cb04bdc216e7e5ea3657cb1186eaf0f1095.tar.zst
gsoc2013-epiphany-c6573cb04bdc216e7e5ea3657cb1186eaf0f1095.zip
A embed/mozilla/GeckoPrintService.cpp: A
2006-06-18 Christian Persch <chpe@cvs.gnome.org> * configure.ac: * data/default-prefs-common.js: * embed/Makefile.am: * embed/ephy-embed-shell.c: (ephy_embed_shell_dispose), (ephy_embed_shell_set_page_setup), (ephy_embed_shell_get_page_setup), (ephy_embed_shell_set_print_settings), (ephy_embed_shell_get_print_settings): * embed/ephy-embed-shell.h: * embed/mozilla/EphyBrowser.cpp: * embed/mozilla/EphyBrowser.h: * embed/mozilla/EphyUtils.cpp: * embed/mozilla/EphyUtils.h: * embed/mozilla/Makefile.am: A embed/mozilla/GeckoPrintService.cpp: A embed/mozilla/GeckoPrintService.h: A embed/mozilla/GeckoPrintSession.cpp: A embed/mozilla/GeckoPrintSession.h: * embed/mozilla/MozRegisterComponents.cpp: R embed/mozilla/PrintingPromptService.cpp: R embed/mozilla/PrintingPromptService.h: * embed/mozilla/mozilla-embed-single.cpp: R embed/print-dialog.c: R embed/print-dialog.h: * src/ephy-shell.c: (ephy_shell_dispose), (ephy_shell_get_prefs_dialog): * src/ephy-shell.h: * src/epiphany.defs: * src/window-commands.c: (page_setup_done_cb), (window_cmd_file_print_setup): Drop libgnomeprint[ui] and use gtk printing.
Diffstat (limited to 'embed/mozilla/EphyUtils.cpp')
-rw-r--r--embed/mozilla/EphyUtils.cpp235
1 files changed, 31 insertions, 204 deletions
diff --git a/embed/mozilla/EphyUtils.cpp b/embed/mozilla/EphyUtils.cpp
index b0ed8df4b..ab6d78e1a 100644
--- a/embed/mozilla/EphyUtils.cpp
+++ b/embed/mozilla/EphyUtils.cpp
@@ -35,11 +35,11 @@
#include <nsServiceManagerUtils.h>
#include <nsStringAPI.h>
#include <nsXPCOM.h>
+#include <nsIXPConnect.h>
#include "ephy-embed-shell.h"
#include "ephy-embed-single.h"
#include "ephy-file-helpers.h"
-#include "print-dialog.h"
#include "EphyUtils.h"
@@ -139,211 +139,38 @@ EphyUtils::FindGtkParent (nsIDOMWindow *aDOMWindow)
return toplevel;
}
-nsresult
-EphyUtils::CollatePrintSettings (EmbedPrintInfo *info,
- nsIPrintSettings *options,
- gboolean preview)
+char *
+EphyUtils::ConvertUTF16toUTF8 (const PRUnichar *aText,
+ PRInt32 aMaxLength)
{
- NS_ENSURE_ARG (options);
-
- /* FIXME: for CUPS printers, print directly instead of to a tmp file? */
- const static PRUnichar pName[] = { 'P', 'o', 's', 't', 'S', 'c', 'r', 'i', 'p', 't', '/', 'd', 'e', 'f', 'a', 'u', 'l', 't', '\0' };
- options->SetPrinterName(nsString(pName).get());
-
- const static int frame_types[] = {
- nsIPrintSettings::kFramesAsIs,
- nsIPrintSettings::kSelectedFrame,
- nsIPrintSettings::kEachFrameSep
- };
-
- switch (info->range)
- {
- case GNOME_PRINT_RANGE_CURRENT:
- case GNOME_PRINT_RANGE_SELECTION_UNSENSITIVE:
- case GNOME_PRINT_RANGE_ALL:
- options->SetPrintRange (nsIPrintSettings::kRangeAllPages);
- break;
- case GNOME_PRINT_RANGE_RANGE:
- options->SetPrintRange (nsIPrintSettings::kRangeSpecifiedPageRange);
- options->SetStartPageRange (info->from_page);
- options->SetEndPageRange (info->to_page);
- break;
- case GNOME_PRINT_RANGE_SELECTION:
- options->SetPrintRange (nsIPrintSettings::kRangeSelection);
- break;
- }
-
- const GnomePrintUnit *unit, *inch, *mm;
- double value;
-
- mm = gnome_print_unit_get_by_abbreviation ((const guchar *) "mm");
- inch = gnome_print_unit_get_by_abbreviation ((const guchar *) "in");
- g_assert (mm != NULL && inch != NULL);
-
- /* top margin */
- if (gnome_print_config_get_length (info->config,
- (const guchar *) GNOME_PRINT_KEY_PAGE_MARGIN_TOP,
- &value, &unit)
- && gnome_print_convert_distance (&value, unit, inch))
- {
- options->SetMarginTop (value);
- }
-
- /* bottom margin */
- if (gnome_print_config_get_length (info->config,
- (const guchar *) GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM,
- &value, &unit)
- && gnome_print_convert_distance (&value, unit, inch))
- {
- options->SetMarginBottom (value);
- }
-
- /* left margin */
- if (gnome_print_config_get_length (info->config,
- (const guchar *) GNOME_PRINT_KEY_PAGE_MARGIN_LEFT,
- &value, &unit)
- && gnome_print_convert_distance (&value, unit, inch))
- {
- options->SetMarginLeft (value);
- }
-
- /* right margin */
- if (gnome_print_config_get_length (info->config,
- (const guchar *) GNOME_PRINT_KEY_PAGE_MARGIN_RIGHT,
- &value, &unit)
- && gnome_print_convert_distance (&value, unit, inch))
- {
- options->SetMarginRight (value);
- }
-
-
- nsString tmp;
-
- NS_CStringToUTF16 (nsCString(info->header_left_string),
- NS_CSTRING_ENCODING_UTF8, tmp);
- options->SetHeaderStrLeft (tmp.get());
-
- NS_CStringToUTF16 (nsCString(info->header_center_string),
- NS_CSTRING_ENCODING_UTF8, tmp);
- options->SetHeaderStrCenter (tmp.get());
-
- NS_CStringToUTF16 (nsCString(info->header_right_string),
- NS_CSTRING_ENCODING_UTF8, tmp);
- options->SetHeaderStrRight (tmp.get());
-
- NS_CStringToUTF16 (nsCString(info->footer_left_string),
- NS_CSTRING_ENCODING_UTF8, tmp);
- options->SetFooterStrLeft (tmp.get());
-
- NS_CStringToUTF16 (nsCString(info->footer_center_string),
- NS_CSTRING_ENCODING_UTF8, tmp);
- options->SetFooterStrCenter(tmp.get());
-
- NS_CStringToUTF16 (nsCString(info->footer_right_string),
- NS_CSTRING_ENCODING_UTF8, tmp);
- options->SetFooterStrRight(tmp.get());
+ if (aText == nsnull) return NULL;
+
+ /* This depends on the assumption that
+ * typeof(PRUnichar) == typeof (gunichar2) == uint16,
+ * which should be pretty safe.
+ */
+ glong n_read = 0, n_written = 0;
+ char *converted = g_utf16_to_utf8 ((gunichar2*) aText, aMaxLength,
+ &n_read, &n_written, NULL);
+ /* FIXME loop from the end while !g_unichar_isspace (char)? */
+
+ return converted;
+}
- options->SetPrintToFile (PR_FALSE);
-
- if (preview)
- {
- options->SetPrintToFile (PR_FALSE);
- }
- else
- {
- char *base;
- const char *temp_dir;
-
- temp_dir = ephy_file_tmp_dir ();
- base = g_build_filename (temp_dir, "printXXXXXX", (char *) NULL);
- info->tempfile = ephy_file_tmp_filename (base, "ps");
- g_free (base);
-
- if (info->tempfile == NULL) return NS_ERROR_FAILURE;
+/* This isn't completely accurate: if you do window.prompt in one window, then
+ * call this in another window, it still returns TRUE ! Those are the wonders
+ * of recursive mainloops :-(
+ */
+PRBool
+EphyJSUtils::IsCalledFromScript ()
+{
+ nsresult rv;
+ nsCOMPtr<nsIXPConnect> xpc(do_GetService(nsIXPConnect::GetCID(), &rv));
+ NS_ENSURE_SUCCESS (rv, PR_FALSE);
- NS_CStringToUTF16 (nsCString(info->tempfile),
- NS_CSTRING_ENCODING_UTF8, tmp);
- options->SetPrintToFile (PR_TRUE);
- options->SetToFileName (tmp.get());
- }
-
- /* paper size */
- options->SetPaperSize (nsIPrintSettings::kPaperSizeDefined);
- options->SetPaperSizeUnit (nsIPrintSettings::kPaperSizeMillimeters);
-
- if (gnome_print_config_get_length (info->config,
- (const guchar *) GNOME_PRINT_KEY_PAPER_WIDTH,
- &value, &unit)
- && gnome_print_convert_distance (&value, unit, mm))
- {
- options->SetPaperWidth (value);
- }
-
- if (gnome_print_config_get_length (info->config,
- (const guchar *) GNOME_PRINT_KEY_PAPER_HEIGHT,
- &value, &unit)
- && gnome_print_convert_distance (&value, unit, mm))
- {
- options->SetPaperHeight (value);
- }
-
- /* Mozilla bug https://bugzilla.mozilla.org/show_bug.cgi?id=307404
- * means that we cannot actually use any paper sizes except mozilla's
- * builtin list, and we must refer to them *by name*!
- */
-#ifndef HAVE_GECKO_1_9
- /* Gnome-Print names some papers differently than what moz understands */
- static const struct
- {
- const char *gppaper;
- const char *mozpaper;
- }
- paper_table [] =
- {
- { "USLetter", "Letter" },
- { "USLegal", "Legal" }
- };
-#endif /* !HAVE_GECKO_1_9 */
-
- /* paper name */
- char *string = (char *) gnome_print_config_get (info->config,
- (const guchar *) GNOME_PRINT_KEY_PAPER_SIZE);
- const char *paper = string;
-
-#ifndef HAVE_GECKO_1_9
- for (PRUint32 i = 0; i < G_N_ELEMENTS (paper_table); i++)
- {
- if (string != NULL &&
- g_ascii_strcasecmp (paper_table[i].gppaper, string) == 0)
- {
- paper = paper_table[i].mozpaper;
- break;
- }
- }
-#endif /* !HAVE_GECKO_1_9 */
-
- NS_CStringToUTF16 (nsCString(paper),
- NS_CSTRING_ENCODING_UTF8, tmp);
- options->SetPaperName (tmp.get());
- g_free (string);
-
- /* paper orientation */
- string = (char *) gnome_print_config_get (info->config,
- (const guchar *) GNOME_PRINT_KEY_ORIENTATION);
- if (string == NULL) string = g_strdup ("R0");
-
- if (strncmp (string, "R90", 3) == 0 || strncmp (string, "R270", 4) == 0)
- {
- options->SetOrientation (nsIPrintSettings::kLandscapeOrientation);
- }
- else
- {
- options->SetOrientation (nsIPrintSettings::kPortraitOrientation);
- }
- g_free (string);
-
- options->SetPrintInColor (info->print_color);
- options->SetPrintFrameType (frame_types[info->frame_type]);
+ nsCOMPtr<nsIXPCNativeCallContext> ncc;
+ rv = xpc->GetCurrentNativeCallContext (getter_AddRefs (ncc));
+ NS_ENSURE_SUCCESS(rv, PR_FALSE);
- return NS_OK;
+ return nsnull != ncc;
}