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 PRINTING_PRINTING_CONTEXT_H_ | 5 #ifndef PRINTING_PRINTING_CONTEXT_H_ |
6 #define PRINTING_PRINTING_CONTEXT_H_ | 6 #define PRINTING_PRINTING_CONTEXT_H_ |
7 | 7 |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 | 9 |
10 #if defined(OS_WIN) | 10 #if defined(OS_WIN) |
11 #include <ocidl.h> | 11 #include <ocidl.h> |
12 #include <commdlg.h> | 12 #include <commdlg.h> |
13 #endif | 13 #endif |
14 | 14 |
15 #include <string> | 15 #include <string> |
16 | 16 |
| 17 #include "app/gfx/native_widget_types.h" |
17 #include "base/basictypes.h" | 18 #include "base/basictypes.h" |
| 19 #include "base/logging.h" |
18 #include "printing/print_settings.h" | 20 #include "printing/print_settings.h" |
19 | 21 |
| 22 #if defined(OS_MACOSX) |
| 23 #include "base/scoped_cftyperef.h" |
| 24 #ifdef __OBJC__ |
| 25 @class NSPrintInfo; |
| 26 #else |
| 27 class NSPrintInfo; |
| 28 #endif // __OBJC__ |
| 29 #endif // OS_MACOSX |
| 30 |
20 namespace printing { | 31 namespace printing { |
21 | 32 |
22 // Describe the user selected printing context for Windows. This includes the | 33 // Describe the user selected printing context for Windows. This includes the |
23 // OS-dependent UI to ask the user about the print settings. This class directly | 34 // OS-dependent UI to ask the user about the print settings. This class directly |
24 // talk to the printer and manages the document and pages breaks. | 35 // talk to the printer and manages the document and pages breaks. |
25 class PrintingContext { | 36 class PrintingContext { |
26 public: | 37 public: |
27 // Tri-state result for user behavior-dependent functions. | 38 // Tri-state result for user behavior-dependent functions. |
28 enum Result { | 39 enum Result { |
29 OK, | 40 OK, |
30 CANCEL, | 41 CANCEL, |
31 FAILED, | 42 FAILED, |
32 }; | 43 }; |
33 | 44 |
34 PrintingContext(); | 45 PrintingContext(); |
35 ~PrintingContext(); | 46 ~PrintingContext(); |
36 | 47 |
37 #if defined(OS_WIN) | |
38 // Asks the user what printer and format should be used to print. Updates the | 48 // Asks the user what printer and format should be used to print. Updates the |
39 // context with the select device settings. | 49 // context with the select device settings. |
40 Result AskUserForSettings(HWND window, int max_pages, bool has_selection); | 50 Result AskUserForSettings(gfx::NativeWindow window, int max_pages, |
41 #endif | 51 bool has_selection); |
42 | 52 |
43 // Selects the user's default printer and format. Updates the context with the | 53 // Selects the user's default printer and format. Updates the context with the |
44 // default device settings. | 54 // default device settings. |
45 Result UseDefaultSettings(); | 55 Result UseDefaultSettings(); |
46 | 56 |
47 // Initializes with predefined settings. | 57 // Initializes with predefined settings. |
48 Result InitWithSettings(const PrintSettings& settings); | 58 Result InitWithSettings(const PrintSettings& settings); |
49 | 59 |
50 // Reinitializes the settings to uninitialized for object reuse. | 60 // Reinitializes the settings to uninitialized for object reuse. |
51 void ResetSettings(); | 61 void ResetSettings(); |
(...skipping 16 matching lines...) Expand all Loading... |
68 // document. | 78 // document. |
69 Result DocumentDone(); | 79 Result DocumentDone(); |
70 | 80 |
71 // Cancels printing. Can be used in a multi-threaded context. Takes effect | 81 // Cancels printing. Can be used in a multi-threaded context. Takes effect |
72 // immediately. | 82 // immediately. |
73 void Cancel(); | 83 void Cancel(); |
74 | 84 |
75 // Dismiss the Print... dialog box if shown. | 85 // Dismiss the Print... dialog box if shown. |
76 void DismissDialog(); | 86 void DismissDialog(); |
77 | 87 |
78 #if defined(OS_WIN) | 88 gfx::NativeDrawingContext context() { |
79 HDC context() { | 89 #if defined(OS_WIN) || defined(OS_MACOSX) |
80 return hdc_; | 90 return context_; |
| 91 #else |
| 92 NOTIMPLEMENTED(); |
| 93 return NULL; |
| 94 #endif |
81 } | 95 } |
82 #endif | |
83 | 96 |
84 const PrintSettings& settings() const { | 97 const PrintSettings& settings() const { |
85 return settings_; | 98 return settings_; |
86 } | 99 } |
87 | 100 |
88 private: | 101 private: |
89 // Class that manages the PrintDlgEx() callbacks. This is meant to be a | 102 // Class that manages the PrintDlgEx() callbacks. This is meant to be a |
90 // temporary object used during the Print... dialog display. | 103 // temporary object used during the Print... dialog display. |
91 class CallbackHandler; | 104 class CallbackHandler; |
92 | 105 |
93 // Does bookkeeping when an error occurs. | 106 // Does bookkeeping when an error occurs. |
94 PrintingContext::Result OnError(); | 107 PrintingContext::Result OnError(); |
95 | 108 |
96 #if defined(OS_WIN) | 109 #if defined(OS_WIN) |
97 // Used in response to the user canceling the printing. | 110 // Used in response to the user canceling the printing. |
98 static BOOL CALLBACK AbortProc(HDC hdc, int nCode); | 111 static BOOL CALLBACK AbortProc(HDC hdc, int nCode); |
99 | 112 |
100 // Reads the settings from the selected device context. Updates settings_ and | 113 // Reads the settings from the selected device context. Updates settings_ and |
101 // its margins. | 114 // its margins. |
102 bool InitializeSettings(const DEVMODE& dev_mode, | 115 bool InitializeSettings(const DEVMODE& dev_mode, |
103 const std::wstring& new_device_name, | 116 const std::wstring& new_device_name, |
104 const PRINTPAGERANGE* ranges, | 117 const PRINTPAGERANGE* ranges, |
105 int number_ranges, | 118 int number_ranges, |
106 bool selection_only); | 119 bool selection_only); |
107 | 120 |
108 // Retrieves the printer's default low-level settings. hdc_ is allocated with | 121 // Retrieves the printer's default low-level settings. On Windows, context_ is |
109 // this call. | 122 // allocated with this call. |
110 bool GetPrinterSettings(HANDLE printer, | 123 bool GetPrinterSettings(HANDLE printer, |
111 const std::wstring& device_name); | 124 const std::wstring& device_name); |
112 | 125 |
113 // Allocates the HDC for a specific DEVMODE. | 126 // Allocates the HDC for a specific DEVMODE. |
114 bool AllocateContext(const std::wstring& printer_name, | 127 bool AllocateContext(const std::wstring& printer_name, |
115 const DEVMODE* dev_mode); | 128 const DEVMODE* dev_mode); |
116 | 129 |
117 // Parses the result of a PRINTDLGEX result. | 130 // Parses the result of a PRINTDLGEX result. |
118 Result ParseDialogResultEx(const PRINTDLGEX& dialog_options); | 131 Result ParseDialogResultEx(const PRINTDLGEX& dialog_options); |
119 Result ParseDialogResult(const PRINTDLG& dialog_options); | 132 Result ParseDialogResult(const PRINTDLG& dialog_options); |
120 | 133 |
121 // The selected printer context. | 134 #elif defined(OS_MACOSX) |
122 HDC hdc_; | 135 // Read the settings from the given NSPrintInfo (and cache it for later use). |
| 136 void ParsePrintInfo(NSPrintInfo* print_info); |
| 137 #endif |
| 138 |
| 139 // On Windows, the selected printer context. |
| 140 // On Mac, the current page's context; only valid between NewPage and PageDone |
| 141 // call pairs. |
| 142 gfx::NativeDrawingContext context_; |
| 143 |
| 144 #if defined(OS_MACOSX) |
| 145 // The native print info object. |
| 146 NSPrintInfo* print_info_; |
123 #endif | 147 #endif |
124 | 148 |
125 // Complete print context settings. | 149 // Complete print context settings. |
126 PrintSettings settings_; | 150 PrintSettings settings_; |
127 | 151 |
128 #ifndef NDEBUG | 152 #ifndef NDEBUG |
129 // Current page number in the print job. | 153 // Current page number in the print job. |
130 int page_number_; | 154 int page_number_; |
131 #endif | 155 #endif |
132 | 156 |
(...skipping 10 matching lines...) Expand all Loading... |
143 | 167 |
144 // Did the user cancel the print job. | 168 // Did the user cancel the print job. |
145 volatile bool abort_printing_; | 169 volatile bool abort_printing_; |
146 | 170 |
147 DISALLOW_EVIL_CONSTRUCTORS(PrintingContext); | 171 DISALLOW_EVIL_CONSTRUCTORS(PrintingContext); |
148 }; | 172 }; |
149 | 173 |
150 } // namespace printing | 174 } // namespace printing |
151 | 175 |
152 #endif // PRINTING_PRINTING_CONTEXT_H_ | 176 #endif // PRINTING_PRINTING_CONTEXT_H_ |
OLD | NEW |