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. 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/memory/scoped_ptr.h" 14 #include "build/build_config.h" 15 #include "printing/printing_context.h" 16 #include "ui/gfx/native_widget_types.h" 17 18 namespace printing { 19 20 class PRINTING_EXPORT PrintingContextWin : public PrintingContext { 21 public: 22 explicit PrintingContextWin(const std::string& app_locale); 23 ~PrintingContextWin(); 24 25 // PrintingContext implementation. 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; 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; 42 43 // Allocates the HDC for a specific DEVMODE. 44 static bool AllocateContext(const std::wstring& printer_name, 45 const DEVMODE* dev_mode, 46 gfx::NativeDrawingContext* context); 47 48 protected: 49 virtual HRESULT ShowPrintDialog(PRINTDLGEX* options); 50 51 private: 52 // Class that manages the PrintDlgEx() callbacks. This is meant to be a 53 // temporary object used during the Print... dialog display. 54 class CallbackHandler; 55 56 // Used in response to the user canceling the printing. 57 static BOOL CALLBACK AbortProc(HDC hdc, int nCode); 58 59 // Reads the settings from the selected device context. Updates settings_ and 60 // its margins. 61 bool InitializeSettings(const DEVMODE& dev_mode, 62 const std::wstring& new_device_name, 63 const PRINTPAGERANGE* ranges, 64 int number_ranges, 65 bool selection_only); 66 67 // Retrieves the printer's default low-level settings. On Windows, context_ is 68 // allocated with this call. 69 bool GetPrinterSettings(HANDLE printer, 70 const std::wstring& device_name); 71 72 // Parses the result of a PRINTDLGEX result. 73 Result ParseDialogResultEx(const PRINTDLGEX& dialog_options); 74 Result ParseDialogResult(const PRINTDLG& dialog_options); 75 76 // The selected printer context. 77 HDC context_; 78 79 // The dialog box for the time it is shown. 80 volatile HWND dialog_box_; 81 82 DISALLOW_COPY_AND_ASSIGN(PrintingContextWin); 83 }; 84 85 } // namespace printing 86 87 #endif // PRINTING_PRINTING_CONTEXT_WIN_H_ 88