Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(227)

Side by Side Diff: printing/printing_context_win.cc

Issue 27441003: Use BaseShellDialog for print dialog on Windows (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « printing/printing_context_win.h ('k') | ui/shell_dialogs.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 : PrintingContext(app_locale), 182 : PrintingContext(app_locale),
183 context_(NULL), 183 context_(NULL),
184 dialog_box_(NULL), 184 dialog_box_(NULL),
185 print_dialog_func_(&PrintDlgEx) { 185 print_dialog_func_(&PrintDlgEx) {
186 } 186 }
187 187
188 PrintingContextWin::~PrintingContextWin() { 188 PrintingContextWin::~PrintingContextWin() {
189 ReleaseContext(); 189 ReleaseContext();
190 } 190 }
191 191
192 // TODO(vitalybuka): Implement as ui::BaseShellDialog crbug.com/180997.
193 void PrintingContextWin::AskUserForSettings( 192 void PrintingContextWin::AskUserForSettings(
194 gfx::NativeView view, int max_pages, bool has_selection, 193 gfx::NativeView view, int max_pages, bool has_selection,
195 const PrintSettingsCallback& callback) { 194 const PrintSettingsCallback& callback) {
196 DCHECK(!in_print_job_); 195 DCHECK(!in_print_job_);
196 // TODO(scottmg): Possibly this has to move into the threaded runner too?
197 if (win8::IsSingleWindowMetroMode()) { 197 if (win8::IsSingleWindowMetroMode()) {
198 // The system dialog can not be opened while running in Metro. 198 // The system dialog can not be opened while running in Metro.
199 // But we can programatically launch the Metro print device charm though. 199 // But we can programatically launch the Metro print device charm though.
200 HMODULE metro_module = base::win::GetMetroModule(); 200 HMODULE metro_module = base::win::GetMetroModule();
201 if (metro_module != NULL) { 201 if (metro_module != NULL) {
202 typedef void (*MetroShowPrintUI)(); 202 typedef void (*MetroShowPrintUI)();
203 MetroShowPrintUI metro_show_print_ui = 203 MetroShowPrintUI metro_show_print_ui =
204 reinterpret_cast<MetroShowPrintUI>( 204 reinterpret_cast<MetroShowPrintUI>(
205 ::GetProcAddress(metro_module, "MetroShowPrintUI")); 205 ::GetProcAddress(metro_module, "MetroShowPrintUI"));
206 if (metro_show_print_ui) { 206 if (metro_show_print_ui) {
(...skipping 12 matching lines...) Expand all
219 219
220 // Show the OS-dependent dialog box. 220 // Show the OS-dependent dialog box.
221 // If the user press 221 // If the user press
222 // - OK, the settings are reset and reinitialized with the new settings. OK is 222 // - OK, the settings are reset and reinitialized with the new settings. OK is
223 // returned. 223 // returned.
224 // - Apply then Cancel, the settings are reset and reinitialized with the new 224 // - Apply then Cancel, the settings are reset and reinitialized with the new
225 // settings. CANCEL is returned. 225 // settings. CANCEL is returned.
226 // - Cancel, the settings are not changed, the previous setting, if it was 226 // - Cancel, the settings are not changed, the previous setting, if it was
227 // initialized before, are kept. CANCEL is returned. 227 // initialized before, are kept. CANCEL is returned.
228 // On failure, the settings are reset and FAILED is returned. 228 // On failure, the settings are reset and FAILED is returned.
229 PRINTDLGEX dialog_options = { sizeof(PRINTDLGEX) }; 229 PRINTDLGEX* dialog_options =
230 dialog_options.hwndOwner = window; 230 reinterpret_cast<PRINTDLGEX*>(malloc(sizeof(PRINTDLGEX)));
231 ZeroMemory(dialog_options, sizeof(PRINTDLGEX));
232 dialog_options->lStructSize = sizeof(PRINTDLGEX);
233 dialog_options->hwndOwner = window;
231 // Disable options we don't support currently. 234 // Disable options we don't support currently.
232 // TODO(maruel): Reuse the previously loaded settings! 235 // TODO(maruel): Reuse the previously loaded settings!
233 dialog_options.Flags = PD_RETURNDC | PD_USEDEVMODECOPIESANDCOLLATE | 236 dialog_options->Flags = PD_RETURNDC | PD_USEDEVMODECOPIESANDCOLLATE |
234 PD_NOCURRENTPAGE | PD_HIDEPRINTTOFILE; 237 PD_NOCURRENTPAGE | PD_HIDEPRINTTOFILE;
235 if (!has_selection) 238 if (!has_selection)
236 dialog_options.Flags |= PD_NOSELECTION; 239 dialog_options->Flags |= PD_NOSELECTION;
237 240
238 PRINTPAGERANGE ranges[32]; 241 const size_t max_page_ranges = 32;
239 dialog_options.nStartPage = START_PAGE_GENERAL; 242 PRINTPAGERANGE* ranges = new PRINTPAGERANGE[max_page_ranges];
243 dialog_options->lpPageRanges = ranges;
244 dialog_options->nStartPage = START_PAGE_GENERAL;
240 if (max_pages) { 245 if (max_pages) {
241 // Default initialize to print all the pages. 246 // Default initialize to print all the pages.
242 memset(ranges, 0, sizeof(ranges)); 247 memset(ranges, 0, sizeof(ranges));
243 ranges[0].nFromPage = 1; 248 ranges[0].nFromPage = 1;
244 ranges[0].nToPage = max_pages; 249 ranges[0].nToPage = max_pages;
245 dialog_options.nPageRanges = 1; 250 dialog_options->nPageRanges = 1;
246 dialog_options.nMaxPageRanges = arraysize(ranges); 251 dialog_options->nMaxPageRanges = max_page_ranges;
247 dialog_options.nMinPage = 1; 252 dialog_options->nMinPage = 1;
248 dialog_options.nMaxPage = max_pages; 253 dialog_options->nMaxPage = max_pages;
249 dialog_options.lpPageRanges = ranges;
250 } else { 254 } else {
251 // No need to bother, we don't know how many pages are available. 255 // No need to bother, we don't know how many pages are available.
252 dialog_options.Flags |= PD_NOPAGENUMS; 256 dialog_options->Flags |= PD_NOPAGENUMS;
253 } 257 }
254 258
255 HRESULT hr = (*print_dialog_func_)(&dialog_options); 259 callback_ = callback;
256 if (hr != S_OK) { 260 print_settings_dialog_ = new ui::PrintSettingsDialogWin(this);
257 ResetSettings(); 261 print_settings_dialog_->GetPrintSettings(
258 callback.Run(FAILED); 262 print_dialog_func_, window, dialog_options);
259 }
260
261 // TODO(maruel): Support PD_PRINTTOFILE.
262 callback.Run(ParseDialogResultEx(dialog_options));
263 } 263 }
264 264
265 PrintingContext::Result PrintingContextWin::UseDefaultSettings() { 265 PrintingContext::Result PrintingContextWin::UseDefaultSettings() {
266 DCHECK(!in_print_job_); 266 DCHECK(!in_print_job_);
267 267
268 PRINTDLG dialog_options = { sizeof(PRINTDLG) }; 268 PRINTDLG dialog_options = { sizeof(PRINTDLG) };
269 dialog_options.Flags = PD_RETURNDC | PD_RETURNDEFAULT; 269 dialog_options.Flags = PD_RETURNDC | PD_RETURNDEFAULT;
270 if (PrintDlg(&dialog_options)) 270 if (PrintDlg(&dialog_options))
271 return ParseDialogResult(dialog_options); 271 return ParseDialogResult(dialog_options);
272 272
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 if (context_) { 558 if (context_) {
559 DeleteDC(context_); 559 DeleteDC(context_);
560 context_ = NULL; 560 context_ = NULL;
561 } 561 }
562 } 562 }
563 563
564 gfx::NativeDrawingContext PrintingContextWin::context() const { 564 gfx::NativeDrawingContext PrintingContextWin::context() const {
565 return context_; 565 return context_;
566 } 566 }
567 567
568 void PrintingContextWin::PrintSettingsConfirmed(PRINTDLGEX* dialog_options) {
569 // TODO(maruel): Support PD_PRINTTOFILE.
570 callback_.Run(ParseDialogResultEx(*dialog_options));
571 delete [] dialog_options->lpPageRanges;
572 free(dialog_options);
573 }
574
575 void PrintingContextWin::PrintSettingsCancelled(PRINTDLGEX* dialog_options) {
576 ResetSettings();
577 callback_.Run(FAILED);
578 delete [] dialog_options->lpPageRanges;
579 free(dialog_options);
580 }
581
568 // static 582 // static
569 BOOL PrintingContextWin::AbortProc(HDC hdc, int nCode) { 583 BOOL PrintingContextWin::AbortProc(HDC hdc, int nCode) {
570 if (nCode) { 584 if (nCode) {
571 // TODO(maruel): Need a way to find the right instance to set. Should 585 // TODO(maruel): Need a way to find the right instance to set. Should
572 // leverage PrintJobManager here? 586 // leverage PrintJobManager here?
573 // abort_printing_ = true; 587 // abort_printing_ = true;
574 } 588 }
575 return true; 589 return true;
576 } 590 }
577 591
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
769 783
770 if (dialog_options.hDevMode != NULL) 784 if (dialog_options.hDevMode != NULL)
771 GlobalFree(dialog_options.hDevMode); 785 GlobalFree(dialog_options.hDevMode);
772 if (dialog_options.hDevNames != NULL) 786 if (dialog_options.hDevNames != NULL)
773 GlobalFree(dialog_options.hDevNames); 787 GlobalFree(dialog_options.hDevNames);
774 788
775 return context_ ? OK : FAILED; 789 return context_ ? OK : FAILED;
776 } 790 }
777 791
778 } // namespace printing 792 } // namespace printing
OLDNEW
« no previous file with comments | « printing/printing_context_win.h ('k') | ui/shell_dialogs.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698