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 PrintingContextWin
: public PrintingContext
{
22 explicit PrintingContextWin(const std::string
& app_locale
);
23 ~PrintingContextWin();
25 // PrintingContext implementation.
26 virtual void AskUserForSettings(gfx::NativeView parent_view
,
29 PrintSettingsCallback
* callback
);
30 virtual Result
UseDefaultSettings();
31 virtual Result
UpdatePrinterSettings(
32 const base::DictionaryValue
& job_settings
,
33 const PageRanges
& ranges
);
34 virtual Result
InitWithSettings(const PrintSettings
& settings
);
35 virtual Result
NewDocument(const string16
& document_name
);
36 virtual Result
NewPage();
37 virtual Result
PageDone();
38 virtual Result
DocumentDone();
39 virtual void Cancel();
40 virtual void ReleaseContext();
41 virtual gfx::NativeDrawingContext
context() const;
43 #if defined(UNIT_TEST)
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
);
55 // Retrieves the content of a GetPrinter call.
56 static void GetPrinterHelper(HANDLE printer
, int level
,
57 scoped_array
<uint8
>* buffer
);
60 // Class that manages the PrintDlgEx() callbacks. This is meant to be a
61 // temporary object used during the Print... dialog display.
62 class CallbackHandler
;
64 // Used in response to the user canceling the printing.
65 static BOOL CALLBACK
AbortProc(HDC hdc
, int nCode
);
67 // Reads the settings from the selected device context. Updates settings_ and
69 bool InitializeSettings(const DEVMODE
& dev_mode
,
70 const std::wstring
& new_device_name
,
71 const PRINTPAGERANGE
* ranges
,
75 // Retrieves the printer's default low-level settings. On Windows, context_ is
76 // allocated with this call.
77 bool GetPrinterSettings(HANDLE printer
,
78 const std::wstring
& device_name
);
80 // Parses the result of a PRINTDLGEX result.
81 Result
ParseDialogResultEx(const PRINTDLGEX
& dialog_options
);
82 Result
ParseDialogResult(const PRINTDLG
& dialog_options
);
84 // The selected printer context.
87 // The dialog box for the time it is shown.
88 volatile HWND dialog_box_
;
90 // Function pointer that defaults to PrintDlgEx. It can be changed using
91 // SetPrintDialog() in tests.
92 HRESULT (__stdcall
*print_dialog_func_
)(LPPRINTDLGEX
);
94 DISALLOW_COPY_AND_ASSIGN(PrintingContextWin
);
97 } // namespace printing
99 #endif // PRINTING_PRINTING_CONTEXT_WIN_H_