[email protected] | 7868ecab | 2011-03-05 00:12:53 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef PRINTING_PRINTING_CONTEXT_WIN_H_ |
| 6 | #define PRINTING_PRINTING_CONTEXT_WIN_H_ |
| 7 | |
| 8 | #include <ocidl.h> |
| 9 | #include <commdlg.h> |
| 10 | |
| 11 | #include <string> |
| 12 | |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 13 | #include "base/memory/scoped_ptr.h" |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 14 | #include "build/build_config.h" |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 15 | #include "printing/printing_context.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 16 | #include "ui/gfx/native_widget_types.h" |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 17 | |
| 18 | namespace printing { |
| 19 | |
[email protected] | 69f5b1e6 | 2011-09-01 06:34:04 | [diff] [blame] | 20 | class PRINTING_EXPORT PrintingContextWin : public PrintingContext { |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 21 | public: |
[email protected] | ee5f36e4 | 2010-12-03 22:40:37 | [diff] [blame] | 22 | explicit PrintingContextWin(const std::string& app_locale); |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 23 | ~PrintingContextWin(); |
| 24 | |
| 25 | // PrintingContext implementation. |
[email protected] | abe4811 | 2011-11-19 01:58:38 | [diff] [blame] | 26 | virtual void AskUserForSettings( |
| 27 | gfx::NativeView parent_view, |
| 28 | int max_pages, |
| 29 | bool has_selection, |
| 30 | const PrintSettingsCallback& callback) OVERRIDE; |
| 31 | virtual Result UseDefaultSettings() OVERRIDE; |
[email protected] | 55b23a0 | 2011-08-17 23:09:36 | [diff] [blame] | 32 | virtual Result UpdatePrinterSettings( |
| 33 | const base::DictionaryValue& job_settings, |
[email protected] | abe4811 | 2011-11-19 01:58:38 | [diff] [blame] | 34 | const PageRanges& ranges) OVERRIDE; |
| 35 | virtual Result InitWithSettings(const PrintSettings& settings) OVERRIDE; |
| 36 | virtual Result NewDocument(const string16& document_name) OVERRIDE; |
| 37 | virtual Result NewPage() OVERRIDE; |
| 38 | virtual Result PageDone() OVERRIDE; |
| 39 | virtual Result DocumentDone() OVERRIDE; |
| 40 | virtual void Cancel() OVERRIDE; |
| 41 | virtual void ReleaseContext() OVERRIDE; |
| 42 | virtual gfx::NativeDrawingContext context() const OVERRIDE; |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 43 | |
[email protected] | 69f5b1e6 | 2011-09-01 06:34:04 | [diff] [blame] | 44 | #if defined(UNIT_TEST) || defined(PRINTING_IMPLEMENTATION) |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 45 | // Sets a fake PrintDlgEx function pointer in tests. |
| 46 | void SetPrintDialog(HRESULT (__stdcall *print_dialog_func)(LPPRINTDLGEX)) { |
| 47 | print_dialog_func_ = print_dialog_func; |
| 48 | } |
| 49 | #endif // defined(UNIT_TEST) |
| 50 | |
| 51 | // Allocates the HDC for a specific DEVMODE. |
| 52 | static bool AllocateContext(const std::wstring& printer_name, |
| 53 | const DEVMODE* dev_mode, |
| 54 | gfx::NativeDrawingContext* context); |
| 55 | |
| 56 | // Retrieves the content of a GetPrinter call. |
| 57 | static void GetPrinterHelper(HANDLE printer, int level, |
| 58 | scoped_array<uint8>* buffer); |
| 59 | |
| 60 | private: |
| 61 | // Class that manages the PrintDlgEx() callbacks. This is meant to be a |
| 62 | // temporary object used during the Print... dialog display. |
| 63 | class CallbackHandler; |
| 64 | |
| 65 | // Used in response to the user canceling the printing. |
| 66 | static BOOL CALLBACK AbortProc(HDC hdc, int nCode); |
| 67 | |
| 68 | // Reads the settings from the selected device context. Updates settings_ and |
| 69 | // its margins. |
| 70 | bool InitializeSettings(const DEVMODE& dev_mode, |
| 71 | const std::wstring& new_device_name, |
| 72 | const PRINTPAGERANGE* ranges, |
| 73 | int number_ranges, |
| 74 | bool selection_only); |
| 75 | |
| 76 | // Retrieves the printer's default low-level settings. On Windows, context_ is |
| 77 | // allocated with this call. |
| 78 | bool GetPrinterSettings(HANDLE printer, |
| 79 | const std::wstring& device_name); |
| 80 | |
| 81 | // Parses the result of a PRINTDLGEX result. |
| 82 | Result ParseDialogResultEx(const PRINTDLGEX& dialog_options); |
| 83 | Result ParseDialogResult(const PRINTDLG& dialog_options); |
| 84 | |
| 85 | // The selected printer context. |
| 86 | HDC context_; |
| 87 | |
| 88 | // The dialog box for the time it is shown. |
| 89 | volatile HWND dialog_box_; |
| 90 | |
| 91 | // Function pointer that defaults to PrintDlgEx. It can be changed using |
| 92 | // SetPrintDialog() in tests. |
| 93 | HRESULT (__stdcall *print_dialog_func_)(LPPRINTDLGEX); |
| 94 | |
| 95 | DISALLOW_COPY_AND_ASSIGN(PrintingContextWin); |
| 96 | }; |
| 97 | |
| 98 | } // namespace printing |
| 99 | |
| 100 | #endif // PRINTING_PRINTING_CONTEXT_WIN_H_ |