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.
5 #ifndef PRINTING_PRINTING_CONTEXT_WIN_H_
6 #define PRINTING_PRINTING_CONTEXT_WIN_H_
13 #include "base/memory/scoped_ptr.h"
14 #include "build/build_config.h"
15 #include "printing/printing_context.h"
16 #include "ui/gfx/native_widget_types.h"
20 class PRINTING_EXPORT PrintingContextWin : public PrintingContext {
22 explicit PrintingContextWin(const std::string& app_locale);
23 ~PrintingContextWin();
25 // PrintingContext implementation.
26 virtual void AskUserForSettings(
27 gfx::NativeView parent_view,
30 const PrintSettingsCallback& callback) OVERRIDE;
31 virtual Result UseDefaultSettings() OVERRIDE;
32 virtual gfx::Size GetPdfPaperSizeDeviceUnits() OVERRIDE;
33 virtual Result UpdatePrinterSettings(bool external_preview) OVERRIDE;
34 virtual Result InitWithSettings(const PrintSettings& settings) OVERRIDE;
35 virtual Result NewDocument(const base::string16& document_name) OVERRIDE;
36 virtual Result NewPage() OVERRIDE;
37 virtual Result PageDone() OVERRIDE;
38 virtual Result DocumentDone() OVERRIDE;
39 virtual void Cancel() OVERRIDE;
40 virtual void ReleaseContext() OVERRIDE;
41 virtual gfx::NativeDrawingContext context() const OVERRIDE;
43 #if defined(UNIT_TEST) || defined(PRINTING_IMPLEMENTATION)
44 // Sets a fake PrintDlgEx function pointer in tests.
45 void SetPrintDialog(HRESULT (__stdcall *print_dialog_func)(LPPRINTDLGEX)) {
46 print_dialog_func_ = print_dialog_func;
48 #endif // defined(UNIT_TEST)
50 // Allocates the HDC for a specific DEVMODE.
51 static bool AllocateContext(const std::wstring& printer_name,
52 const DEVMODE* dev_mode,
53 gfx::NativeDrawingContext* context);
56 // Class that manages the PrintDlgEx() callbacks. This is meant to be a
57 // temporary object used during the Print... dialog display.
58 class CallbackHandler;
60 // Used in response to the user canceling the printing.
61 static BOOL CALLBACK AbortProc(HDC hdc, int nCode);
63 // Reads the settings from the selected device context. Updates settings_ and
65 bool InitializeSettings(const DEVMODE& dev_mode,
66 const std::wstring& new_device_name,
67 const PRINTPAGERANGE* ranges,
71 // Retrieves the printer's default low-level settings. On Windows, context_ is
72 // allocated with this call.
73 bool GetPrinterSettings(HANDLE printer,
74 const std::wstring& device_name);
76 // Parses the result of a PRINTDLGEX result.
77 Result ParseDialogResultEx(const PRINTDLGEX& dialog_options);
78 Result ParseDialogResult(const PRINTDLG& dialog_options);
80 // The selected printer context.
83 // The dialog box for the time it is shown.
84 volatile HWND dialog_box_;
86 // Function pointer that defaults to PrintDlgEx. It can be changed using
87 // SetPrintDialog() in tests.
88 HRESULT (__stdcall *print_dialog_func_)(LPPRINTDLGEX);
90 DISALLOW_COPY_AND_ASSIGN(PrintingContextWin);
93 } // namespace printing
95 #endif // PRINTING_PRINTING_CONTEXT_WIN_H_