OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "printing/printing_context_gtk.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "base/values.h" | |
9 #include "printing/metafile.h" | |
10 #include "printing/print_job_constants.h" | |
11 #include "printing/units.h" | |
12 | |
13 #include <gtk/gtk.h> | |
Scott Byer
2011/11/03 22:22:35
Since these are no longer guarded, the include ord
Albert Bodenhamer
2011/11/03 23:58:40
Done.
| |
14 #include <gtk/gtkprintunixdialog.h> | |
15 #include "printing/print_dialog_gtk_interface.h" | |
16 | |
17 namespace { | |
18 // Function pointer for creating print dialogs. |callback| is only used when | |
19 // |show_dialog| is true. | |
20 static printing::PrintDialogGtkInterface* (*create_dialog_func_)( | |
21 printing::PrintingContextGtk* context) = NULL; | |
22 } // namespace | |
23 | |
24 namespace printing { | |
25 | |
26 // static | |
27 PrintingContext* PrintingContext::Create(const std::string& app_locale) { | |
28 return static_cast<PrintingContext*>(new PrintingContextGtk(app_locale)); | |
29 } | |
30 | |
31 PrintingContextGtk::PrintingContextGtk(const std::string& app_locale) | |
32 : PrintingContext(app_locale), | |
33 print_dialog_(NULL) { | |
34 } | |
35 | |
36 PrintingContextGtk::~PrintingContextGtk() { | |
37 ReleaseContext(); | |
38 | |
39 if (print_dialog_) | |
40 print_dialog_->ReleaseDialog(); | |
41 } | |
42 | |
43 // static | |
44 void PrintingContextGtk::SetCreatePrintDialogFunction( | |
45 PrintDialogGtkInterface* (*create_dialog_func)( | |
46 PrintingContextGtk* context)) { | |
47 DCHECK(create_dialog_func); | |
48 DCHECK(!create_dialog_func_); | |
49 create_dialog_func_ = create_dialog_func; | |
50 } | |
51 | |
52 void PrintingContextGtk::PrintDocument(const Metafile* metafile) { | |
53 DCHECK(print_dialog_); | |
54 DCHECK(metafile); | |
55 print_dialog_->PrintDocument(metafile, document_name_); | |
56 } | |
57 | |
58 void PrintingContextGtk::AskUserForSettings( | |
59 gfx::NativeView parent_view, | |
60 int max_pages, | |
61 bool has_selection, | |
62 PrintSettingsCallback* callback) { | |
63 print_dialog_->ShowDialog(callback); | |
64 } | |
65 | |
66 PrintingContext::Result PrintingContextGtk::UseDefaultSettings() { | |
67 DCHECK(!in_print_job_); | |
68 | |
69 ResetSettings(); | |
70 if (!print_dialog_) { | |
71 print_dialog_ = create_dialog_func_(this); | |
72 print_dialog_->AddRefToDialog(); | |
73 } | |
74 print_dialog_->UseDefaultSettings(); | |
75 | |
76 return OK; | |
77 } | |
78 | |
79 PrintingContext::Result PrintingContextGtk::UpdatePrinterSettings( | |
80 const DictionaryValue& job_settings, const PageRanges& ranges) { | |
81 DCHECK(!in_print_job_); | |
82 | |
83 if (!print_dialog_) { | |
84 print_dialog_ = create_dialog_func_(this); | |
85 print_dialog_->AddRefToDialog(); | |
86 } | |
87 | |
88 if (!print_dialog_->UpdateSettings(job_settings, ranges, &settings_)) | |
89 return OnError(); | |
90 | |
91 return OK; | |
92 } | |
93 | |
94 PrintingContext::Result PrintingContextGtk::InitWithSettings( | |
95 const PrintSettings& settings) { | |
96 DCHECK(!in_print_job_); | |
97 | |
98 settings_ = settings; | |
99 | |
100 return OK; | |
101 } | |
102 | |
103 PrintingContext::Result PrintingContextGtk::NewDocument( | |
104 const string16& document_name) { | |
105 DCHECK(!in_print_job_); | |
106 in_print_job_ = true; | |
107 | |
108 document_name_ = document_name; | |
109 | |
110 return OK; | |
111 } | |
112 | |
113 PrintingContext::Result PrintingContextGtk::NewPage() { | |
114 if (abort_printing_) | |
115 return CANCEL; | |
116 DCHECK(in_print_job_); | |
117 | |
118 // Intentional No-op. | |
119 | |
120 return OK; | |
121 } | |
122 | |
123 PrintingContext::Result PrintingContextGtk::PageDone() { | |
124 if (abort_printing_) | |
125 return CANCEL; | |
126 DCHECK(in_print_job_); | |
127 | |
128 // Intentional No-op. | |
129 | |
130 return OK; | |
131 } | |
132 | |
133 PrintingContext::Result PrintingContextGtk::DocumentDone() { | |
134 if (abort_printing_) | |
135 return CANCEL; | |
136 DCHECK(in_print_job_); | |
137 | |
138 ResetSettings(); | |
139 return OK; | |
140 } | |
141 | |
142 void PrintingContextGtk::Cancel() { | |
143 abort_printing_ = true; | |
144 in_print_job_ = false; | |
145 } | |
146 | |
147 void PrintingContextGtk::ReleaseContext() { | |
148 // Intentional No-op. | |
149 } | |
150 | |
151 gfx::NativeDrawingContext PrintingContextGtk::context() const { | |
152 // Intentional No-op. | |
153 return NULL; | |
154 } | |
155 | |
156 } // namespace printing | |
OLD | NEW |