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