OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_PRINTING_PRINT_DIALOG_GTK_H_ | 5 #ifndef CHROME_BROWSER_PRINTING_PRINT_DIALOG_GTK_H_ |
6 #define CHROME_BROWSER_PRINTING_PRINT_DIALOG_GTK_H_ | 6 #define CHROME_BROWSER_PRINTING_PRINT_DIALOG_GTK_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <gtk/gtk.h> | 9 #include <gtk/gtk.h> |
| 10 #include <gtk/gtkprintunixdialog.h> |
10 | 11 |
11 #include "base/basictypes.h" | |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
| 13 #include "base/ref_counted.h" |
| 14 #include "printing/native_metafile.h" |
| 15 #include "printing/printing_context_cairo.h" |
13 #include "ui/base/gtk/gtk_signal.h" | 16 #include "ui/base/gtk/gtk_signal.h" |
14 | 17 |
15 class Browser; | 18 namespace base { |
| 19 class WaitableEvent; |
| 20 } |
16 | 21 |
17 typedef struct _GtkPrintJob GtkPrintJob; | 22 using printing::NativeMetafile; |
| 23 using printing::PrintingContextCairo; |
18 | 24 |
19 // Currently this dialog only allows the user to choose a printer. | 25 class PrintDialogGtk : public base::RefCountedThreadSafe<PrintDialogGtk> { |
20 class PrintDialogGtk { | |
21 public: | 26 public: |
22 static bool DialogShowing(); | 27 // Creates and returns a print dialog. The dialog will initialize the settings |
| 28 // for |context| and call |callback| to inform the print workflow of the |
| 29 // dialog results. |
| 30 static void* CreatePrintDialog( |
| 31 PrintingContextCairo::PrintSettingsCallback* callback, |
| 32 PrintingContextCairo* context); |
23 | 33 |
24 // Called on the IO thread. | 34 // Prints a document named |document_name| based on the settings in |
25 static void CreatePrintDialogForPdf(const FilePath& path); | 35 // |print_dialog|, with data from |metafile|. |
| 36 // Called from the print worker thread. |
| 37 static void PrintDocument(void* print_dialog, |
| 38 const NativeMetafile* metafile, |
| 39 const string16& document_name); |
26 | 40 |
27 private: | 41 private: |
28 explicit PrintDialogGtk(const FilePath& path_to_pdf); | 42 friend class base::RefCountedThreadSafe<PrintDialogGtk>; |
| 43 |
| 44 PrintDialogGtk(PrintingContextCairo::PrintSettingsCallback* callback, |
| 45 PrintingContextCairo* context); |
29 ~PrintDialogGtk(); | 46 ~PrintDialogGtk(); |
30 | 47 |
31 static void CreateDialogImpl(const FilePath& path); | 48 // Handles dialog response. |
32 | |
33 CHROMEGTK_CALLBACK_1(PrintDialogGtk, void, OnResponse, gint); | 49 CHROMEGTK_CALLBACK_1(PrintDialogGtk, void, OnResponse, gint); |
34 | 50 |
| 51 // Saves data in |metafile| to disk for document named |document_name|. |
| 52 void SaveDocumentToDisk(const NativeMetafile* metafile, |
| 53 const string16& document_name); |
| 54 |
| 55 // Prints document named |document_name|. |
| 56 void SendDocumentToPrinter(const string16& document_name); |
| 57 |
| 58 // Handles print job response. |
35 static void OnJobCompletedThunk(GtkPrintJob* print_job, | 59 static void OnJobCompletedThunk(GtkPrintJob* print_job, |
36 gpointer user_data, | 60 gpointer user_data, |
37 GError* error); | 61 GError* error); |
38 void OnJobCompleted(GtkPrintJob* job, GError* error); | 62 void OnJobCompleted(GtkPrintJob* print_job, GError* error); |
39 | 63 |
| 64 void set_save_document_event(base::WaitableEvent* event); |
| 65 |
| 66 // Printing dialog callback. |
| 67 PrintingContextCairo::PrintSettingsCallback* callback_; |
| 68 PrintingContextCairo* context_; |
| 69 |
| 70 // Print dialog settings. |
| 71 GtkWidget* dialog_; |
| 72 GtkPageSetup* page_setup_; |
| 73 GtkPrinter* printer_; |
| 74 GtkPrintSettings* gtk_settings_; |
| 75 |
| 76 // Event to signal when save document finishes. |
| 77 base::WaitableEvent* save_document_event_; |
40 FilePath path_to_pdf_; | 78 FilePath path_to_pdf_; |
41 | 79 |
42 GtkWidget* dialog_; | |
43 | |
44 Browser* browser_; | |
45 | |
46 DISALLOW_COPY_AND_ASSIGN(PrintDialogGtk); | 80 DISALLOW_COPY_AND_ASSIGN(PrintDialogGtk); |
47 }; | 81 }; |
48 | 82 |
49 #endif // CHROME_BROWSER_PRINTING_PRINT_DIALOG_GTK_H_ | 83 #endif // CHROME_BROWSER_PRINTING_PRINT_DIALOG_GTK_H_ |
OLD | NEW |