[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 | |
| 20 | class PrintingContextWin : public PrintingContext { |
| 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. |
| 26 | virtual void AskUserForSettings(gfx::NativeView parent_view, |
| 27 | int max_pages, |
| 28 | bool has_selection, |
| 29 | PrintSettingsCallback* callback); |
| 30 | virtual Result UseDefaultSettings(); |
[email protected] | c82d3f21 | 2011-03-22 01:18:30 | [diff] [blame] | 31 | virtual Result UpdatePrintSettings(const DictionaryValue& job_settings, |
[email protected] | 89f5aa8c | 2011-03-21 20:58:44 | [diff] [blame] | 32 | const PageRanges& ranges); |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 33 | virtual Result InitWithSettings(const PrintSettings& settings); |
| 34 | virtual Result NewDocument(const string16& document_name); |
| 35 | virtual Result NewPage(); |
| 36 | virtual Result PageDone(); |
| 37 | virtual Result DocumentDone(); |
| 38 | virtual void Cancel(); |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 39 | virtual void ReleaseContext(); |
| 40 | virtual gfx::NativeDrawingContext context() const; |
| 41 | |
| 42 | #if defined(UNIT_TEST) |
| 43 | // Sets a fake PrintDlgEx function pointer in tests. |
| 44 | void SetPrintDialog(HRESULT (__stdcall *print_dialog_func)(LPPRINTDLGEX)) { |
| 45 | print_dialog_func_ = print_dialog_func; |
| 46 | } |
| 47 | #endif // defined(UNIT_TEST) |
| 48 | |
| 49 | // Allocates the HDC for a specific DEVMODE. |
| 50 | static bool AllocateContext(const std::wstring& printer_name, |
| 51 | const DEVMODE* dev_mode, |
| 52 | gfx::NativeDrawingContext* context); |
| 53 | |
| 54 | // Retrieves the content of a GetPrinter call. |
| 55 | static void GetPrinterHelper(HANDLE printer, int level, |
| 56 | scoped_array<uint8>* buffer); |
| 57 | |
| 58 | private: |
| 59 | // Class that manages the PrintDlgEx() callbacks. This is meant to be a |
| 60 | // temporary object used during the Print... dialog display. |
| 61 | class CallbackHandler; |
| 62 | |
| 63 | // Used in response to the user canceling the printing. |
| 64 | static BOOL CALLBACK AbortProc(HDC hdc, int nCode); |
| 65 | |
| 66 | // Reads the settings from the selected device context. Updates settings_ and |
| 67 | // its margins. |
| 68 | bool InitializeSettings(const DEVMODE& dev_mode, |
| 69 | const std::wstring& new_device_name, |
| 70 | const PRINTPAGERANGE* ranges, |
| 71 | int number_ranges, |
| 72 | bool selection_only); |
| 73 | |
| 74 | // Retrieves the printer's default low-level settings. On Windows, context_ is |
| 75 | // allocated with this call. |
| 76 | bool GetPrinterSettings(HANDLE printer, |
| 77 | const std::wstring& device_name); |
| 78 | |
| 79 | // Parses the result of a PRINTDLGEX result. |
| 80 | Result ParseDialogResultEx(const PRINTDLGEX& dialog_options); |
| 81 | Result ParseDialogResult(const PRINTDLG& dialog_options); |
| 82 | |
| 83 | // The selected printer context. |
| 84 | HDC context_; |
| 85 | |
| 86 | // The dialog box for the time it is shown. |
| 87 | volatile HWND dialog_box_; |
| 88 | |
| 89 | // Function pointer that defaults to PrintDlgEx. It can be changed using |
| 90 | // SetPrintDialog() in tests. |
| 91 | HRESULT (__stdcall *print_dialog_func_)(LPPRINTDLGEX); |
| 92 | |
| 93 | DISALLOW_COPY_AND_ASSIGN(PrintingContextWin); |
| 94 | }; |
| 95 | |
| 96 | } // namespace printing |
| 97 | |
| 98 | #endif // PRINTING_PRINTING_CONTEXT_WIN_H_ |