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