OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "printing/printing_context_win.h" | 5 #include "printing/printing_context_win.h" |
6 | 6 |
7 #include <winspool.h> | 7 #include <winspool.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 : PrintingContext(app_locale), | 168 : PrintingContext(app_locale), |
169 context_(NULL), | 169 context_(NULL), |
170 dialog_box_(NULL), | 170 dialog_box_(NULL), |
171 print_dialog_func_(&PrintDlgEx) { | 171 print_dialog_func_(&PrintDlgEx) { |
172 } | 172 } |
173 | 173 |
174 PrintingContextWin::~PrintingContextWin() { | 174 PrintingContextWin::~PrintingContextWin() { |
175 ReleaseContext(); | 175 ReleaseContext(); |
176 } | 176 } |
177 | 177 |
| 178 // TODO(vitalybuka): Implement as ui::BaseShellDialog crbug.com/180997. |
178 void PrintingContextWin::AskUserForSettings( | 179 void PrintingContextWin::AskUserForSettings( |
179 gfx::NativeView view, int max_pages, bool has_selection, | 180 gfx::NativeView view, int max_pages, bool has_selection, |
180 const PrintSettingsCallback& callback) { | 181 const PrintSettingsCallback& callback) { |
181 DCHECK(!in_print_job_); | 182 DCHECK(!in_print_job_); |
182 // TODO(scottmg): Possibly this has to move into the threaded runner too? | |
183 if (win8::IsSingleWindowMetroMode()) { | 183 if (win8::IsSingleWindowMetroMode()) { |
184 // The system dialog can not be opened while running in Metro. | 184 // The system dialog can not be opened while running in Metro. |
185 // But we can programatically launch the Metro print device charm though. | 185 // But we can programatically launch the Metro print device charm though. |
186 HMODULE metro_module = base::win::GetMetroModule(); | 186 HMODULE metro_module = base::win::GetMetroModule(); |
187 if (metro_module != NULL) { | 187 if (metro_module != NULL) { |
188 typedef void (*MetroShowPrintUI)(); | 188 typedef void (*MetroShowPrintUI)(); |
189 MetroShowPrintUI metro_show_print_ui = | 189 MetroShowPrintUI metro_show_print_ui = |
190 reinterpret_cast<MetroShowPrintUI>( | 190 reinterpret_cast<MetroShowPrintUI>( |
191 ::GetProcAddress(metro_module, "MetroShowPrintUI")); | 191 ::GetProcAddress(metro_module, "MetroShowPrintUI")); |
192 if (metro_show_print_ui) { | 192 if (metro_show_print_ui) { |
(...skipping 12 matching lines...) Expand all Loading... |
205 | 205 |
206 // Show the OS-dependent dialog box. | 206 // Show the OS-dependent dialog box. |
207 // If the user press | 207 // If the user press |
208 // - OK, the settings are reset and reinitialized with the new settings. OK is | 208 // - OK, the settings are reset and reinitialized with the new settings. OK is |
209 // returned. | 209 // returned. |
210 // - Apply then Cancel, the settings are reset and reinitialized with the new | 210 // - Apply then Cancel, the settings are reset and reinitialized with the new |
211 // settings. CANCEL is returned. | 211 // settings. CANCEL is returned. |
212 // - Cancel, the settings are not changed, the previous setting, if it was | 212 // - Cancel, the settings are not changed, the previous setting, if it was |
213 // initialized before, are kept. CANCEL is returned. | 213 // initialized before, are kept. CANCEL is returned. |
214 // On failure, the settings are reset and FAILED is returned. | 214 // On failure, the settings are reset and FAILED is returned. |
215 PRINTDLGEX* dialog_options = | 215 PRINTDLGEX dialog_options = { sizeof(PRINTDLGEX) }; |
216 reinterpret_cast<PRINTDLGEX*>(malloc(sizeof(PRINTDLGEX))); | 216 dialog_options.hwndOwner = window; |
217 ZeroMemory(dialog_options, sizeof(PRINTDLGEX)); | |
218 dialog_options->lStructSize = sizeof(PRINTDLGEX); | |
219 dialog_options->hwndOwner = window; | |
220 // Disable options we don't support currently. | 217 // Disable options we don't support currently. |
221 // TODO(maruel): Reuse the previously loaded settings! | 218 // TODO(maruel): Reuse the previously loaded settings! |
222 dialog_options->Flags = PD_RETURNDC | PD_USEDEVMODECOPIESANDCOLLATE | | 219 dialog_options.Flags = PD_RETURNDC | PD_USEDEVMODECOPIESANDCOLLATE | |
223 PD_NOCURRENTPAGE | PD_HIDEPRINTTOFILE; | 220 PD_NOCURRENTPAGE | PD_HIDEPRINTTOFILE; |
224 if (!has_selection) | 221 if (!has_selection) |
225 dialog_options->Flags |= PD_NOSELECTION; | 222 dialog_options.Flags |= PD_NOSELECTION; |
226 | 223 |
227 const size_t max_page_ranges = 32; | 224 PRINTPAGERANGE ranges[32]; |
228 PRINTPAGERANGE* ranges = new PRINTPAGERANGE[max_page_ranges]; | 225 dialog_options.nStartPage = START_PAGE_GENERAL; |
229 dialog_options->lpPageRanges = ranges; | |
230 dialog_options->nStartPage = START_PAGE_GENERAL; | |
231 if (max_pages) { | 226 if (max_pages) { |
232 // Default initialize to print all the pages. | 227 // Default initialize to print all the pages. |
233 memset(ranges, 0, sizeof(ranges)); | 228 memset(ranges, 0, sizeof(ranges)); |
234 ranges[0].nFromPage = 1; | 229 ranges[0].nFromPage = 1; |
235 ranges[0].nToPage = max_pages; | 230 ranges[0].nToPage = max_pages; |
236 dialog_options->nPageRanges = 1; | 231 dialog_options.nPageRanges = 1; |
237 dialog_options->nMaxPageRanges = max_page_ranges; | 232 dialog_options.nMaxPageRanges = arraysize(ranges); |
238 dialog_options->nMinPage = 1; | 233 dialog_options.nMinPage = 1; |
239 dialog_options->nMaxPage = max_pages; | 234 dialog_options.nMaxPage = max_pages; |
| 235 dialog_options.lpPageRanges = ranges; |
240 } else { | 236 } else { |
241 // No need to bother, we don't know how many pages are available. | 237 // No need to bother, we don't know how many pages are available. |
242 dialog_options->Flags |= PD_NOPAGENUMS; | 238 dialog_options.Flags |= PD_NOPAGENUMS; |
243 } | 239 } |
244 | 240 |
245 callback_ = callback; | 241 HRESULT hr = (*print_dialog_func_)(&dialog_options); |
246 print_settings_dialog_ = new ui::PrintSettingsDialogWin(this); | 242 if (hr != S_OK) { |
247 print_settings_dialog_->GetPrintSettings( | 243 ResetSettings(); |
248 print_dialog_func_, window, dialog_options); | 244 callback.Run(FAILED); |
| 245 } |
| 246 |
| 247 // TODO(maruel): Support PD_PRINTTOFILE. |
| 248 callback.Run(ParseDialogResultEx(dialog_options)); |
249 } | 249 } |
250 | 250 |
251 PrintingContext::Result PrintingContextWin::UseDefaultSettings() { | 251 PrintingContext::Result PrintingContextWin::UseDefaultSettings() { |
252 DCHECK(!in_print_job_); | 252 DCHECK(!in_print_job_); |
253 | 253 |
254 PRINTDLG dialog_options = { sizeof(PRINTDLG) }; | 254 PRINTDLG dialog_options = { sizeof(PRINTDLG) }; |
255 dialog_options.Flags = PD_RETURNDC | PD_RETURNDEFAULT; | 255 dialog_options.Flags = PD_RETURNDC | PD_RETURNDEFAULT; |
256 if (PrintDlg(&dialog_options)) | 256 if (PrintDlg(&dialog_options)) |
257 return ParseDialogResult(dialog_options); | 257 return ParseDialogResult(dialog_options); |
258 | 258 |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 if (context_) { | 520 if (context_) { |
521 DeleteDC(context_); | 521 DeleteDC(context_); |
522 context_ = NULL; | 522 context_ = NULL; |
523 } | 523 } |
524 } | 524 } |
525 | 525 |
526 gfx::NativeDrawingContext PrintingContextWin::context() const { | 526 gfx::NativeDrawingContext PrintingContextWin::context() const { |
527 return context_; | 527 return context_; |
528 } | 528 } |
529 | 529 |
530 void PrintingContextWin::PrintSettingsConfirmed(PRINTDLGEX* dialog_options) { | |
531 // TODO(maruel): Support PD_PRINTTOFILE. | |
532 callback_.Run(ParseDialogResultEx(*dialog_options)); | |
533 delete [] dialog_options->lpPageRanges; | |
534 free(dialog_options); | |
535 } | |
536 | |
537 void PrintingContextWin::PrintSettingsCancelled(PRINTDLGEX* dialog_options) { | |
538 ResetSettings(); | |
539 callback_.Run(FAILED); | |
540 delete [] dialog_options->lpPageRanges; | |
541 free(dialog_options); | |
542 } | |
543 | |
544 // static | 530 // static |
545 BOOL PrintingContextWin::AbortProc(HDC hdc, int nCode) { | 531 BOOL PrintingContextWin::AbortProc(HDC hdc, int nCode) { |
546 if (nCode) { | 532 if (nCode) { |
547 // TODO(maruel): Need a way to find the right instance to set. Should | 533 // TODO(maruel): Need a way to find the right instance to set. Should |
548 // leverage PrintJobManager here? | 534 // leverage PrintJobManager here? |
549 // abort_printing_ = true; | 535 // abort_printing_ = true; |
550 } | 536 } |
551 return true; | 537 return true; |
552 } | 538 } |
553 | 539 |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 | 728 |
743 if (dialog_options.hDevMode != NULL) | 729 if (dialog_options.hDevMode != NULL) |
744 GlobalFree(dialog_options.hDevMode); | 730 GlobalFree(dialog_options.hDevMode); |
745 if (dialog_options.hDevNames != NULL) | 731 if (dialog_options.hDevNames != NULL) |
746 GlobalFree(dialog_options.hDevNames); | 732 GlobalFree(dialog_options.hDevNames); |
747 | 733 |
748 return context_ ? OK : FAILED; | 734 return context_ ? OK : FAILED; |
749 } | 735 } |
750 | 736 |
751 } // namespace printing | 737 } // namespace printing |
OLD | NEW |