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 gfx::Size
PrintingContextGtk::GetPdfPaperSizeDeviceUnits() {
82 GtkPageSetup
* page_setup
= gtk_page_setup_new();
84 gfx::SizeF
paper_size(
85 gtk_page_setup_get_paper_width(page_setup
, GTK_UNIT_INCH
),
86 gtk_page_setup_get_paper_height(page_setup
, GTK_UNIT_INCH
));
88 g_object_unref(page_setup
);
91 paper_size
.width() * settings_
.device_units_per_inch(),
92 paper_size
.height() * settings_
.device_units_per_inch());
95 PrintingContext::Result
PrintingContextGtk::UpdatePrinterSettings(
96 bool external_preview
) {
97 DCHECK(!in_print_job_
);
98 DCHECK(!external_preview
) << "Not implemented";
100 if (!print_dialog_
) {
101 print_dialog_
= create_dialog_func_(this);
102 print_dialog_
->AddRefToDialog();
105 if (!print_dialog_
->UpdateSettings(&settings_
))
111 PrintingContext::Result
PrintingContextGtk::InitWithSettings(
112 const PrintSettings
& settings
) {
113 DCHECK(!in_print_job_
);
115 settings_
= settings
;
120 PrintingContext::Result
PrintingContextGtk::NewDocument(
121 const base::string16
& document_name
) {
122 DCHECK(!in_print_job_
);
123 in_print_job_
= true;
125 document_name_
= document_name
;
130 PrintingContext::Result
PrintingContextGtk::NewPage() {
133 DCHECK(in_print_job_
);
135 // Intentional No-op.
140 PrintingContext::Result
PrintingContextGtk::PageDone() {
143 DCHECK(in_print_job_
);
145 // Intentional No-op.
150 PrintingContext::Result
PrintingContextGtk::DocumentDone() {
153 DCHECK(in_print_job_
);
159 void PrintingContextGtk::Cancel() {
160 abort_printing_
= true;
161 in_print_job_
= false;
164 void PrintingContextGtk::ReleaseContext() {
165 // Intentional No-op.
168 gfx::NativeDrawingContext
PrintingContextGtk::context() const {
169 // Intentional No-op.
173 } // namespace printing