1 // Copyright (c) 2012 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.
5 #include "printing/printing_context_gtk.h"
8 #include <gtk/gtkunixprint.h>
10 #include "base/logging.h"
11 #include "base/values.h"
12 #include "printing/metafile.h"
13 #include "printing/print_dialog_gtk_interface.h"
14 #include "printing/print_job_constants.h"
15 #include "printing/units.h"
19 // Function pointer for creating print dialogs. |callback| is only used when
20 // |show_dialog| is true.
21 printing::PrintDialogGtkInterface
* (*create_dialog_func_
)(
22 printing::PrintingContextGtk
* context
) = NULL
;
29 PrintingContext
* PrintingContext::Create(const std::string
& app_locale
) {
30 return static_cast<PrintingContext
*>(new PrintingContextGtk(app_locale
));
33 PrintingContextGtk::PrintingContextGtk(const std::string
& app_locale
)
34 : PrintingContext(app_locale
),
38 PrintingContextGtk::~PrintingContextGtk() {
42 print_dialog_
->ReleaseDialog();
46 void PrintingContextGtk::SetCreatePrintDialogFunction(
47 PrintDialogGtkInterface
* (*create_dialog_func
)(
48 PrintingContextGtk
* context
)) {
49 DCHECK(create_dialog_func
);
50 DCHECK(!create_dialog_func_
);
51 create_dialog_func_
= create_dialog_func
;
54 void PrintingContextGtk::PrintDocument(const Metafile
* metafile
) {
55 DCHECK(print_dialog_
);
57 print_dialog_
->PrintDocument(metafile
, document_name_
);
60 void PrintingContextGtk::AskUserForSettings(
61 gfx::NativeView parent_view
,
64 const PrintSettingsCallback
& callback
) {
65 print_dialog_
->ShowDialog(parent_view
, has_selection
, callback
);
68 PrintingContext::Result
PrintingContextGtk::UseDefaultSettings() {
69 DCHECK(!in_print_job_
);
73 print_dialog_
= create_dialog_func_(this);
74 print_dialog_
->AddRefToDialog();
76 print_dialog_
->UseDefaultSettings();
81 PrintingContext::Result
PrintingContextGtk::UpdatePrinterSettings(
82 const DictionaryValue
& job_settings
, const PageRanges
& ranges
) {
83 DCHECK(!in_print_job_
);
86 print_dialog_
= create_dialog_func_(this);
87 print_dialog_
->AddRefToDialog();
90 if (!print_dialog_
->UpdateSettings(job_settings
, ranges
, &settings_
))
96 PrintingContext::Result
PrintingContextGtk::InitWithSettings(
97 const PrintSettings
& settings
) {
98 DCHECK(!in_print_job_
);
100 settings_
= settings
;
105 PrintingContext::Result
PrintingContextGtk::NewDocument(
106 const string16
& document_name
) {
107 DCHECK(!in_print_job_
);
108 in_print_job_
= true;
110 document_name_
= document_name
;
115 PrintingContext::Result
PrintingContextGtk::NewPage() {
118 DCHECK(in_print_job_
);
120 // Intentional No-op.
125 PrintingContext::Result
PrintingContextGtk::PageDone() {
128 DCHECK(in_print_job_
);
130 // Intentional No-op.
135 PrintingContext::Result
PrintingContextGtk::DocumentDone() {
138 DCHECK(in_print_job_
);
144 void PrintingContextGtk::Cancel() {
145 abort_printing_
= true;
146 in_print_job_
= false;
149 void PrintingContextGtk::ReleaseContext() {
150 // Intentional No-op.
153 gfx::NativeDrawingContext
PrintingContextGtk::context() const {
154 // Intentional No-op.
158 } // namespace printing