diff options
author | Christian Persch <chpe@cvs.gnome.org> | 2004-07-11 02:45:23 +0800 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2004-07-11 02:45:23 +0800 |
commit | e3745955787160572f5bc2feb46f293c0f96894f (patch) | |
tree | 59614375b33eadad3f283fb31578d4360b788c6e /embed | |
parent | b26c1e1243cb943f67fc42b646862919238501fc (diff) | |
download | gsoc2013-epiphany-e3745955787160572f5bc2feb46f293c0f96894f.tar gsoc2013-epiphany-e3745955787160572f5bc2feb46f293c0f96894f.tar.gz gsoc2013-epiphany-e3745955787160572f5bc2feb46f293c0f96894f.tar.bz2 gsoc2013-epiphany-e3745955787160572f5bc2feb46f293c0f96894f.tar.lz gsoc2013-epiphany-e3745955787160572f5bc2feb46f293c0f96894f.tar.xz gsoc2013-epiphany-e3745955787160572f5bc2feb46f293c0f96894f.tar.zst gsoc2013-epiphany-e3745955787160572f5bc2feb46f293c0f96894f.zip |
Make print and print setup go trough nsIPrintingPromptService (backported
2004-07-10 Christian Persch <chpe@cvs.gnome.org>
* configure.in:
* data/glade/print.glade:
* embed/ephy-embed-single.c: (ephy_embed_single_print_setup):
* embed/ephy-embed-single.h:
* embed/ephy-embed.c: (ephy_embed_print),
(ephy_embed_set_print_preview_mode):
* embed/ephy-embed.h:
* embed/mozilla/EphyBrowser.cpp:
* embed/mozilla/EphyBrowser.h:
* embed/mozilla/MozillaPrivate.cpp:
* embed/mozilla/MozillaPrivate.h:
* embed/mozilla/PrintingPromptService.cpp:
* embed/mozilla/mozilla-embed-single.cpp:
* embed/mozilla/mozilla-embed.cpp:
* embed/print-dialog.c: (ephy_print_get_print_info),
(ephy_print_dialog_response_cb),
(ephy_print_setup_dialog_help_button_cb), (ephy_print_dialog_new):
* embed/print-dialog.h:
* src/ephy-shell.c: (ephy_shell_init), (ephy_shell_finalize),
(ephy_shell_get_prefs_dialog):
* src/ephy-shell.h:
* src/ephy-window.c: (ephy_window_delete_event_cb),
(ephy_window_finalize), (update_embed_dialogs), (ephy_window_find):
* src/ppview-toolbar.c: (toolbar_cmd_ppv_close):
* src/window-commands.c: (window_cmd_file_print_setup),
(window_cmd_file_print_preview), (window_cmd_file_print):
Make print and print setup go trough nsIPrintingPromptService
(backported from HEAD).
Diffstat (limited to 'embed')
-rw-r--r-- | embed/ephy-embed-single.c | 7 | ||||
-rw-r--r-- | embed/ephy-embed-single.h | 3 | ||||
-rw-r--r-- | embed/ephy-embed.c | 10 | ||||
-rw-r--r-- | embed/ephy-embed.h | 49 | ||||
-rw-r--r-- | embed/mozilla/EphyBrowser.cpp | 56 | ||||
-rw-r--r-- | embed/mozilla/EphyBrowser.h | 5 | ||||
-rw-r--r-- | embed/mozilla/MozillaPrivate.cpp | 5 | ||||
-rw-r--r-- | embed/mozilla/MozillaPrivate.h | 5 | ||||
-rw-r--r-- | embed/mozilla/PrintingPromptService.cpp | 11 | ||||
-rw-r--r-- | embed/mozilla/mozilla-embed-single.cpp | 22 | ||||
-rw-r--r-- | embed/mozilla/mozilla-embed.cpp | 32 | ||||
-rwxr-xr-x | embed/print-dialog.c | 45 | ||||
-rw-r--r-- | embed/print-dialog.h | 39 |
13 files changed, 132 insertions, 157 deletions
diff --git a/embed/ephy-embed-single.c b/embed/ephy-embed-single.c index c0303af7c..39349db85 100644 --- a/embed/ephy-embed-single.c +++ b/embed/ephy-embed-single.c @@ -156,3 +156,10 @@ ephy_embed_single_get_font_list (EphyEmbedSingle *single, EphyEmbedSingleIface *iface = EPHY_EMBED_SINGLE_GET_IFACE (single); return iface->get_font_list (single, langGroup); } + +void +ephy_embed_single_print_setup (EphyEmbedSingle *single) +{ + EphyEmbedSingleIface *iface = EPHY_EMBED_SINGLE_GET_IFACE (single); + iface->print_setup (single); +} diff --git a/embed/ephy-embed-single.h b/embed/ephy-embed-single.h index f9db7cfb9..4089f85cd 100644 --- a/embed/ephy-embed-single.h +++ b/embed/ephy-embed-single.h @@ -56,6 +56,7 @@ struct EphyEmbedSingleIface const char* url); GList * (* get_font_list) (EphyEmbedSingle *shell, const char *langGroup); + void (* print_setup) (EphyEmbedSingle *single); }; GType ephy_embed_single_get_type (void); @@ -73,6 +74,8 @@ void ephy_embed_single_load_proxy_autoconf (EphyEmbedSingle *shell, GList *ephy_embed_single_get_font_list (EphyEmbedSingle *shell, const char *langGroup); +void ephy_embed_single_print_setup (EphyEmbedSingle *single); + G_END_DECLS #endif diff --git a/embed/ephy-embed.c b/embed/ephy-embed.c index ce7c74013..aa5acc242 100644 --- a/embed/ephy-embed.c +++ b/embed/ephy-embed.c @@ -379,18 +379,18 @@ ephy_embed_get_encoding_info (EphyEmbed *embed) } void -ephy_embed_print (EphyEmbed *embed, - EmbedPrintInfo *info) +ephy_embed_print (EphyEmbed *embed) { EphyEmbedIface *iface = EPHY_EMBED_GET_IFACE (embed); - iface->print (embed, info); + iface->print (embed); } void -ephy_embed_print_preview_close (EphyEmbed *embed) +ephy_embed_set_print_preview_mode (EphyEmbed *embed, + gboolean preview_mode) { EphyEmbedIface *iface = EPHY_EMBED_GET_IFACE (embed); - iface->print_preview_close (embed); + iface->set_print_preview_mode (embed, preview_mode); } int diff --git a/embed/ephy-embed.h b/embed/ephy-embed.h index 0099385dd..4cfbd8922 100644 --- a/embed/ephy-embed.h +++ b/embed/ephy-embed.h @@ -76,43 +76,6 @@ typedef enum EMBED_RELOAD_FORCE = 1 << 1 } EmbedReloadFlags; -typedef struct -{ - gboolean print_to_file; - char *printer; - char *file; - char *paper; - int top_margin; - int bottom_margin; - int left_margin; - int right_margin; - int pages; - int from_page; - int to_page; - int frame_type; - int orientation; - gboolean print_color; - gboolean preview; - - /* - * &T - title - * &U - Document URL - * &D - Date/Time - * &P - Page Number - * &PT - Page Number with total Number of Pages (example: 1 of 34) - * - * So, if headerLeftStr = "&T" the title and the document URL - * will be printed out on the top left-hand side of each page. - */ - char *header_left_string; - char *header_center_string; - char *header_right_string; - char *footer_left_string; - char *footer_center_string; - char *footer_right_string; -} -EmbedPrintInfo; - typedef enum { PRINTPREVIEW_GOTO_PAGENUM = 0, @@ -216,9 +179,9 @@ struct EphyEmbedIface void (* set_encoding) (EphyEmbed *embed, const char *encoding); EphyEncodingInfo * (* get_encoding_info) (EphyEmbed *embed); - void (* print) (EphyEmbed *embed, - EmbedPrintInfo *info); - void (* print_preview_close) (EphyEmbed *embed); + void (* print) (EphyEmbed *embed); + void (* set_print_preview_mode) (EphyEmbed *embed, + gboolean mode); int (* print_preview_n_pages) (EphyEmbed *embed); void (* print_preview_navigate) (EphyEmbed *embed, EmbedPrintPreviewNavType type, @@ -304,10 +267,10 @@ void ephy_embed_set_encoding (EphyEmbed *embed, EphyEncodingInfo *ephy_embed_get_encoding_info (EphyEmbed *embed); /* Print */ -void ephy_embed_print (EphyEmbed *embed, - EmbedPrintInfo *info); +void ephy_embed_print (EphyEmbed *embed); -void ephy_embed_print_preview_close (EphyEmbed *embed); +void ephy_embed_set_print_preview_mode (EphyEmbed *embed, + gboolean preview_mode); int ephy_embed_print_preview_n_pages (EphyEmbed *embed); diff --git a/embed/mozilla/EphyBrowser.cpp b/embed/mozilla/EphyBrowser.cpp index 9101ea31f..ee7e84412 100644 --- a/embed/mozilla/EphyBrowser.cpp +++ b/embed/mozilla/EphyBrowser.cpp @@ -83,6 +83,8 @@ #include "nsPromiseFlatString.h" #include "nsString.h" #include "ContentHandler.h" +#include "MozillaPrivate.h" +#include "print-dialog.h" EphyEventListener::EphyEventListener(void) : mOwner(nsnull) @@ -301,43 +303,49 @@ EphyBrowser::DetachListeners(void) return NS_OK; } -nsresult EphyBrowser::Print (nsIPrintSettings *options, PRBool preview) +nsresult EphyBrowser::Print () { - nsresult result; - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); nsCOMPtr<nsIWebBrowserPrint> print(do_GetInterface(mWebBrowser)); NS_ENSURE_TRUE (print, NS_ERROR_FAILURE); - if (!preview) - { - result = print->Print (options, nsnull); - } - else - { - result = print->PrintPreview(options, nsnull, nsnull); - } - - return result; + return print->Print (nsnull, nsnull); } -nsresult EphyBrowser::PrintPreviewClose (void) +nsresult EphyBrowser::SetPrintPreviewMode (PRBool previewMode) { nsresult rv; - PRBool isPreview = PR_FALSE; NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); nsCOMPtr<nsIWebBrowserPrint> print(do_GetInterface(mWebBrowser)); NS_ENSURE_TRUE (print, NS_ERROR_FAILURE); - rv = print->GetDoingPrintPreview(&isPreview); - NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); + if (previewMode) + { + EmbedPrintInfo *info; - if (isPreview == PR_TRUE) + nsCOMPtr<nsIPrintSettings> settings; + print->GetGlobalPrintSettings (getter_AddRefs(settings)); + + info = ephy_print_get_print_info (); + MozillaCollatePrintSettings (info, settings, TRUE); + ephy_print_info_free (info); + + rv = print->PrintPreview (nsnull, mDOMWindow, nsnull); + } + else { - rv = print->ExitPrintPreview(); + PRBool isPreview = PR_FALSE; + + rv = print->GetDoingPrintPreview(&isPreview); + NS_ENSURE_SUCCESS (rv, NS_ERROR_FAILURE); + + if (isPreview == PR_TRUE) + { + rv = print->ExitPrintPreview(); + } } return rv; @@ -363,16 +371,6 @@ nsresult EphyBrowser::PrintPreviewNavigate(PRInt16 navType, PRInt32 pageNum) return print->PrintPreviewNavigate(navType, pageNum); } -nsresult EphyBrowser::GetPrintSettings (nsIPrintSettings **options) -{ - NS_ENSURE_TRUE (mWebBrowser, NS_ERROR_FAILURE); - - nsCOMPtr<nsIWebBrowserPrint> print(do_GetInterface(mWebBrowser)); - NS_ENSURE_TRUE (print, NS_ERROR_FAILURE); - - return print->GetGlobalPrintSettings(options); -} - nsresult EphyBrowser::GetSHistory (nsISHistory **aSHistory) { nsresult result; diff --git a/embed/mozilla/EphyBrowser.h b/embed/mozilla/EphyBrowser.h index 27a1e399c..f6e3fe260 100644 --- a/embed/mozilla/EphyBrowser.h +++ b/embed/mozilla/EphyBrowser.h @@ -88,9 +88,8 @@ public: nsresult SetZoom (float aTextZoom, PRBool reflow); nsresult GetZoom (float *aTextZoom); - nsresult Print (nsIPrintSettings *options, PRBool preview); - nsresult GetPrintSettings (nsIPrintSettings * *options); - nsresult PrintPreviewClose (void); + nsresult Print (); + nsresult SetPrintPreviewMode (PRBool previewMode); nsresult PrintPreviewNumPages (int *numPages); nsresult PrintPreviewNavigate(PRInt16 navType, PRInt32 pageNum); diff --git a/embed/mozilla/MozillaPrivate.cpp b/embed/mozilla/MozillaPrivate.cpp index 41b144969..46bd005c9 100644 --- a/embed/mozilla/MozillaPrivate.cpp +++ b/embed/mozilla/MozillaPrivate.cpp @@ -76,7 +76,8 @@ GtkWidget *MozillaFindGtkParent (nsIDOMWindow *aDOMWindow) #define MM_TO_INCH(x) (((double) x) / 25.4) NS_METHOD MozillaCollatePrintSettings (const EmbedPrintInfo *info, - nsIPrintSettings *options) + nsIPrintSettings *options, + gboolean preview) { const static int frame_types[] = { nsIPrintSettings::kFramesAsIs, @@ -129,7 +130,7 @@ NS_METHOD MozillaCollatePrintSettings (const EmbedPrintInfo *info, * in print preview mode if we set "print to file" to true. * See epiphany bug #119818. */ - if (info->preview) + if (preview) { options->SetPrintToFile (PR_FALSE); } diff --git a/embed/mozilla/MozillaPrivate.h b/embed/mozilla/MozillaPrivate.h index c2f9a4b42..0fa96021d 100644 --- a/embed/mozilla/MozillaPrivate.h +++ b/embed/mozilla/MozillaPrivate.h @@ -1,11 +1,12 @@ #include <nsIPrintSettings.h> #include <nsIDOMWindow.h> -#include "ephy-embed.h" +#include "print-dialog.h" GtkWidget *MozillaFindEmbed (nsIDOMWindow *aDOMWindow); GtkWidget *MozillaFindGtkParent (nsIDOMWindow *aDOMWindow); NS_METHOD MozillaCollatePrintSettings (const EmbedPrintInfo *info, - nsIPrintSettings *settings); + nsIPrintSettings *settings, + gboolean preview); diff --git a/embed/mozilla/PrintingPromptService.cpp b/embed/mozilla/PrintingPromptService.cpp index 16dc3c2e9..cf8645ffa 100644 --- a/embed/mozilla/PrintingPromptService.cpp +++ b/embed/mozilla/PrintingPromptService.cpp @@ -71,7 +71,7 @@ NS_IMETHODIMP GPrintingPromptService::ShowPrintDialog(nsIDOMWindow *parent, nsIW GtkWidget *gtkParent = MozillaFindGtkParent(parent); NS_ENSURE_TRUE (gtkParent, NS_ERROR_FAILURE); - dialog = ephy_print_dialog_new (gtkParent, embed, TRUE); + dialog = ephy_print_dialog_new (gtkParent, embed); ephy_dialog_set_modal (dialog, TRUE); int ret = ephy_dialog_run (dialog); @@ -95,7 +95,7 @@ NS_IMETHODIMP GPrintingPromptService::ShowPrintDialog(nsIDOMWindow *parent, nsIW info->pages = 0; } - MozillaCollatePrintSettings (info, printSettings); + MozillaCollatePrintSettings (info, printSettings, FALSE); ephy_print_info_free (info); @@ -125,7 +125,12 @@ NS_IMETHODIMP GPrintingPromptService::ShowPageSetup(nsIDOMWindow *parent, nsIPri dialog = ephy_print_setup_dialog_new (); ephy_dialog_set_modal (dialog, TRUE); - int ret = ephy_dialog_run (dialog); + int ret; + do + { + ret = ephy_dialog_run (dialog); + } while (ret == GTK_RESPONSE_HELP); + if (ret == GTK_RESPONSE_OK) { rv = NS_OK; diff --git a/embed/mozilla/mozilla-embed-single.cpp b/embed/mozilla/mozilla-embed-single.cpp index 01564d034..ffab10d8f 100644 --- a/embed/mozilla/mozilla-embed-single.cpp +++ b/embed/mozilla/mozilla-embed-single.cpp @@ -76,6 +76,9 @@ #include <nsIURI.h> #include <nsNetUtil.h> #include <nsIHttpAuthManager.h> +#include <nsIPrintSettings.h> +#include <nsIPrintSettingsService.h> +#include <nsIPrintingPromptService.h> // FIXME: For setting the locale. hopefully gtkmozembed will do itself soon #include <nsIChromeRegistry.h> @@ -591,6 +594,24 @@ impl_get_font_list (EphyEmbedSingle *shell, return g_list_reverse (l); } +static void +impl_print_setup (EphyEmbedSingle *single) +{ + nsCOMPtr<nsIPrintSettingsService> pss + (do_GetService ("@mozilla.org/gfx/printsettings-service;1")); + if (!pss) return; + + nsCOMPtr<nsIPrintSettings> settings; + pss->GetGlobalPrintSettings (getter_AddRefs (settings)); + if (!settings) return; + + nsCOMPtr<nsIPrintingPromptService> prompt + (do_GetService ("@mozilla.org/embedcomp/printingprompt-service;1")); + if (!prompt) return; + + prompt->ShowPageSetup (nsnull, settings, nsnull); +} + static GList * impl_list_cookies (EphyCookieManager *manager) { @@ -873,6 +894,7 @@ ephy_embed_single_iface_init (EphyEmbedSingleIface *iface) iface->set_offline_mode = impl_set_offline_mode; iface->load_proxy_autoconf = impl_load_proxy_autoconf; iface->get_font_list = impl_get_font_list; + iface->print_setup = impl_print_setup; } static void diff --git a/embed/mozilla/mozilla-embed.cpp b/embed/mozilla/mozilla-embed.cpp index f52e25ca1..ee67049d1 100644 --- a/embed/mozilla/mozilla-embed.cpp +++ b/embed/mozilla/mozilla-embed.cpp @@ -686,39 +686,19 @@ impl_get_security_level (EphyEmbed *embed, } static void -impl_print (EphyEmbed *embed, - EmbedPrintInfo *info) +impl_print (EphyEmbed *embed) { MozillaEmbedPrivate *mpriv = MOZILLA_EMBED(embed)->priv; - nsresult result; - - nsCOMPtr<nsIPrintSettings> options; - result = mpriv->browser->GetPrintSettings(getter_AddRefs(options)); - if (NS_FAILED (result) || !options) return; - - /* work around mozilla bug which borks when printing selection without having one */ - if (info->pages == 2 && ephy_command_manager_can_do_command - (EPHY_COMMAND_MANAGER (embed), "cmd_copy") == FALSE) - { - info->pages = 0; - } - - MozillaCollatePrintSettings(info, options); - - options->SetPrintSilent (PR_TRUE); - - result = mpriv->browser->Print(options, info->preview); - - /* Workaround for bug 125984 */ - options->SetPrintSilent (PR_FALSE); + + mpriv->browser->Print (); } static void -impl_print_preview_close (EphyEmbed *embed) +impl_set_print_preview_mode (EphyEmbed *embed, gboolean preview_mode) { MozillaEmbedPrivate *mpriv = MOZILLA_EMBED(embed)->priv; - mpriv->browser->PrintPreviewClose(); + mpriv->browser->SetPrintPreviewMode (preview_mode); } static int @@ -1140,7 +1120,7 @@ ephy_embed_iface_init (EphyEmbedIface *iface) iface->set_encoding = impl_set_encoding; iface->get_encoding_info = impl_get_encoding_info; iface->print = impl_print; - iface->print_preview_close = impl_print_preview_close; + iface->set_print_preview_mode = impl_set_print_preview_mode; iface->print_preview_n_pages = impl_print_preview_n_pages; iface->print_preview_navigate = impl_print_preview_navigate; iface->has_modified_forms = impl_has_modified_forms; diff --git a/embed/print-dialog.c b/embed/print-dialog.c index a18728faa..b9de37e7b 100755 --- a/embed/print-dialog.c +++ b/embed/print-dialog.c @@ -131,8 +131,6 @@ void ephy_print_dialog_response_cb (GtkWidget *widget, EphyDialog *dialog); void ephy_print_dialog_browse_button_cb (GtkWidget *widget, EphyDialog *dialog); -void ephy_print_setup_dialog_close_button_cb (GtkWidget *widget, - EphyDialog *dialog); void ephy_print_setup_dialog_help_button_cb (GtkWidget *widget, EphyDialog *dialog); @@ -200,7 +198,6 @@ ephy_print_get_print_info (void) info->footer_center_string = g_strdup(""); info->frame_type = 0; - info->preview = FALSE; return info; } @@ -210,39 +207,14 @@ ephy_print_dialog_response_cb (GtkWidget *widget, int response, EphyDialog *dialog) { - EphyEmbed *embed; - EmbedPrintInfo *info; - gboolean only_collect_info; - - only_collect_info = GPOINTER_TO_INT - (g_object_get_data (G_OBJECT (dialog), "only-collect-info")); - - if (only_collect_info) - { - return; - } - switch (response) { - case GTK_RESPONSE_OK: - info = ephy_print_get_print_info (); - - embed = ephy_embed_dialog_get_embed (EPHY_EMBED_DIALOG (dialog)); - g_return_if_fail (EPHY_IS_EMBED (embed)); - - ephy_embed_print (embed, info); - - ephy_print_info_free (info); - - break; case GTK_RESPONSE_HELP: ephy_gui_help (GTK_WINDOW (widget), "epiphany", "to-print-page"); return; default: break; } - - g_object_unref (dialog); } static void @@ -295,23 +267,15 @@ ephy_print_dialog_browse_button_cb (GtkWidget *widget, } void -ephy_print_setup_dialog_close_button_cb (GtkWidget *widget, - EphyDialog *dialog) -{ - g_object_unref (dialog); -} - -void ephy_print_setup_dialog_help_button_cb (GtkWidget *widget, - EphyDialog *dialog) + EphyDialog *dialog) { - ephy_gui_help (GTK_WINDOW (dialog), "epiphany", "using-print-setup"); + ephy_gui_help (GTK_WINDOW (widget), "epiphany", "using-print-setup"); } EphyDialog * ephy_print_dialog_new (GtkWidget *parent, - EphyEmbed *embed, - gboolean only_collect_info) + EphyEmbed *embed) { EphyDialog *dialog; GtkWidget *window, *button; @@ -343,9 +307,6 @@ ephy_print_dialog_new (GtkWidget *parent, button = ephy_dialog_get_control (dialog, print_props[BROWSE_PROP].id); gtk_widget_set_sensitive (button, eel_gconf_key_is_writable (CONF_PRINT_FILE)); - g_object_set_data (G_OBJECT (dialog), "only-collect-info", - GINT_TO_POINTER (only_collect_info)); - return dialog; } diff --git a/embed/print-dialog.h b/embed/print-dialog.h index f7801d8f5..81a5d5f24 100644 --- a/embed/print-dialog.h +++ b/embed/print-dialog.h @@ -31,9 +31,44 @@ G_BEGIN_DECLS +typedef struct +{ + gboolean print_to_file; + char *printer; + char *file; + char *paper; + int top_margin; + int bottom_margin; + int left_margin; + int right_margin; + int pages; + int from_page; + int to_page; + int frame_type; + int orientation; + gboolean print_color; + + /* + * &T - title + * &U - Document URL + * &D - Date/Time + * &P - Page Number + * &PT - Page Number with total Number of Pages (example: 1 of 34) + * + * So, if headerLeftStr = "&T" the title and the document URL + * will be printed out on the top left-hand side of each page. + */ + char *header_left_string; + char *header_center_string; + char *header_right_string; + char *footer_left_string; + char *footer_center_string; + char *footer_right_string; +} +EmbedPrintInfo; + EphyDialog *ephy_print_dialog_new (GtkWidget *parent, - EphyEmbed *embed, - gboolean only_collect_info); + EphyEmbed *embed); EphyDialog *ephy_print_setup_dialog_new (void); |