| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2006-2008 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 CHROME_BROWSER_PRINTING_WIN_PRINTING_CONTEXT_H__ | |
| 6 #define CHROME_BROWSER_PRINTING_WIN_PRINTING_CONTEXT_H__ | |
| 7 | |
| 8 #include <ocidl.h> | |
| 9 #include <commdlg.h> | |
| 10 #include <string> | |
| 11 | |
| 12 #include "base/basictypes.h" | |
| 13 #include "chrome/browser/printing/print_settings.h" | |
| 14 | |
| 15 namespace printing { | |
| 16 | |
| 17 // Describe the user selected printing context for Windows. This includes the | |
| 18 // OS-dependent UI to ask the user about the print settings. This class directly | |
| 19 // talk to the printer and manages the document and pages breaks. | |
| 20 class PrintingContext { | |
| 21 public: | |
| 22 // Tri-state result for user behavior-dependent functions. | |
| 23 enum Result { | |
| 24 OK, | |
| 25 CANCEL, | |
| 26 FAILED, | |
| 27 }; | |
| 28 | |
| 29 PrintingContext(); | |
| 30 ~PrintingContext(); | |
| 31 | |
| 32 // Asks the user what printer and format should be used to print. Updates the | |
| 33 // context with the select device settings. | |
| 34 Result AskUserForSettings(HWND window, int max_pages, bool has_selection); | |
| 35 | |
| 36 // Selects the user's default printer and format. Updates the context with the | |
| 37 // default device settings. | |
| 38 Result UseDefaultSettings(); | |
| 39 | |
| 40 // Initializes with predefined settings. | |
| 41 Result InitWithSettings(const PrintSettings& settings); | |
| 42 | |
| 43 // Reinitializes the settings to uninitialized for object reuse. | |
| 44 void ResetSettings(); | |
| 45 | |
| 46 // Does platform specific setup of the printer before the printing. Signal the | |
| 47 // printer that a document is about to be spooled. | |
| 48 // Warning: This function enters a message loop. That may cause side effects | |
| 49 // like IPC message processing! Some printers have side-effects on this call | |
| 50 // like virtual printers that ask the user for the path of the saved document; | |
| 51 // for example a PDF printer. | |
| 52 Result NewDocument(const std::wstring& document_name); | |
| 53 | |
| 54 // Starts a new page. | |
| 55 Result NewPage(); | |
| 56 | |
| 57 // Closes the printed page. | |
| 58 Result PageDone(); | |
| 59 | |
| 60 // Closes the printing job. After this call the object is ready to start a new | |
| 61 // document. | |
| 62 Result DocumentDone(); | |
| 63 | |
| 64 // Cancels printing. Can be used in a multithreaded context. Takes effect | |
| 65 // immediately. | |
| 66 void Cancel(); | |
| 67 | |
| 68 // Dismiss the Print... dialog box if shown. | |
| 69 void DismissDialog(); | |
| 70 | |
| 71 HDC context() { | |
| 72 return hdc_; | |
| 73 } | |
| 74 | |
| 75 const PrintSettings& settings() const { | |
| 76 return settings_; | |
| 77 } | |
| 78 | |
| 79 private: | |
| 80 // Class that manages the PrintDlgEx() callbacks. This is meant to be a | |
| 81 // temporary object used during the Print... dialog display. | |
| 82 class CallbackHandler; | |
| 83 | |
| 84 // Does bookkeeping when an error occurs. | |
| 85 PrintingContext::Result OnError(); | |
| 86 | |
| 87 // Used in response to the user canceling the printing. | |
| 88 static BOOL CALLBACK AbortProc(HDC hdc, int nCode); | |
| 89 | |
| 90 // Reads the settings from the selected device context. Updates settings_ and | |
| 91 // its margins. | |
| 92 bool InitializeSettings(const DEVMODE& dev_mode, | |
| 93 const std::wstring& new_device_name, | |
| 94 const PRINTPAGERANGE* ranges, | |
| 95 int number_ranges, | |
| 96 bool selection_only); | |
| 97 | |
| 98 // Retrieves the printer's default low-level settings. hdc_ is allocated with | |
| 99 // this call. | |
| 100 bool GetPrinterSettings(HANDLE printer, | |
| 101 const std::wstring& device_name); | |
| 102 | |
| 103 // Allocates the HDC for a specific DEVMODE. | |
| 104 bool AllocateContext(const std::wstring& printer_name, | |
| 105 const DEVMODE* dev_mode); | |
| 106 | |
| 107 // Parses the result of a PRINTDLGEX result. | |
| 108 Result ParseDialogResultEx(const PRINTDLGEX& dialog_options); | |
| 109 Result ParseDialogResult(const PRINTDLG& dialog_options); | |
| 110 | |
| 111 // The selected printer context. | |
| 112 HDC hdc_; | |
| 113 | |
| 114 // Complete print context settings. | |
| 115 PrintSettings settings_; | |
| 116 | |
| 117 #ifndef NDEBUG | |
| 118 // Current page number in the print job. | |
| 119 int page_number_; | |
| 120 #endif | |
| 121 | |
| 122 // The dialog box for the time it is shown. | |
| 123 volatile HWND dialog_box_; | |
| 124 | |
| 125 // The dialog box has been dismissed. | |
| 126 volatile bool dialog_box_dismissed_; | |
| 127 | |
| 128 // Is a print job being done. | |
| 129 volatile bool in_print_job_; | |
| 130 | |
| 131 // Did the user cancel the print job. | |
| 132 volatile bool abort_printing_; | |
| 133 | |
| 134 DISALLOW_EVIL_CONSTRUCTORS(PrintingContext); | |
| 135 }; | |
| 136 | |
| 137 } // namespace printing | |
| 138 | |
| 139 #endif // CHROME_BROWSER_PRINTING_WIN_PRINTING_CONTEXT_H__ | |
| OLD | NEW |