diff options
author | kmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-21 20:58:44 +0000 |
---|---|---|
committer | kmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-21 20:58:44 +0000 |
commit | 89f5aa8cd1f29a63a989907c454495993659854e (patch) | |
tree | 576b8450fbe372256e6433345a48ba06642e0794 /printing/printing_context_mac.mm | |
parent | 6f3b9f925c3e52a63bb320ce1c6caf67701b335c (diff) | |
download | chromium_src-89f5aa8cd1f29a63a989907c454495993659854e.zip chromium_src-89f5aa8cd1f29a63a989907c454495993659854e.tar.gz chromium_src-89f5aa8cd1f29a63a989907c454495993659854e.tar.bz2 |
PrintPreview: [MAC] Set the selected printer for the current print job.
BUG=76123
TEST=Enable print preview on mac. Press ctrl+p to print a page. On print preview tab, select a printer and press print button.
Review URL: http://codereview.chromium.org/6698013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78919 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing/printing_context_mac.mm')
-rw-r--r-- | printing/printing_context_mac.mm | 47 |
1 files changed, 35 insertions, 12 deletions
diff --git a/printing/printing_context_mac.mm b/printing/printing_context_mac.mm index c297fad..1e354e0 100644 --- a/printing/printing_context_mac.mm +++ b/printing/printing_context_mac.mm @@ -10,6 +10,7 @@ #include "base/logging.h" #include "base/mac/scoped_cftyperef.h" #include "base/sys_string_conversions.h" +#include "base/values.h" #include "printing/print_settings_initializer_mac.h" namespace printing { @@ -50,6 +51,7 @@ void PrintingContextMac::AskUserForSettings(gfx::NativeView parent_view, options |= NSPrintPanelShowsScaling; [panel setOptions:options]; + // Set the print job title text. if (parent_view) { NSString* job_title = [[parent_view window] title]; if (job_title) { @@ -80,18 +82,47 @@ PrintingContext::Result PrintingContextMac::UseDefaultSettings() { } PrintingContext::Result PrintingContextMac::UpdatePrintSettings( - const PageRanges& ranges) { + const DictionaryValue* const job_settings, const PageRanges& ranges) { DCHECK(!in_print_job_); // TODO (kmadhusu): Update other print job settings such as number of copies, // collate, etc., - // Update the print range information. - settings_.ranges = ranges; + ResetSettings(); + print_info_.reset([[NSPrintInfo sharedPrintInfo] copy]); + + std::string printer_name; + if (!job_settings->GetString("printerName", &printer_name)) + return OnError(); + + NSString* new_printer_name = base::SysUTF8ToNSString(printer_name); + if (!new_printer_name) + return OnError(); + + if (![[[print_info_.get() printer] name] isEqualToString:new_printer_name]) { + NSPrinter* new_printer = [NSPrinter printerWithName:new_printer_name]; + if (new_printer == nil) + return OnError(); + [print_info_.get() setPrinter:new_printer]; + } + + InitPrintSettingsFromPrintInfo(ranges); return OK; } +void PrintingContextMac::InitPrintSettingsFromPrintInfo( + const PageRanges& ranges) { + PMPrintSession print_session = + static_cast<PMPrintSession>([print_info_.get() PMPrintSession]); + PMPageFormat page_format = + static_cast<PMPageFormat>([print_info_.get() PMPageFormat]); + PMPrinter printer; + PMSessionGetCurrentPrinter(print_session, &printer); + PrintSettingsInitializerMac::InitPrintSettings( + printer, page_format, ranges, false, &settings_); +} + void PrintingContextMac::ParsePrintInfo(NSPrintInfo* print_info) { ResetSettings(); print_info_.reset([print_info retain]); @@ -103,15 +134,7 @@ void PrintingContextMac::ParsePrintInfo(NSPrintInfo* print_info) { range.to = [[print_info_dict objectForKey:NSPrintLastPage] intValue] - 1; page_ranges.push_back(range); } - PMPrintSession print_session = - static_cast<PMPrintSession>([print_info_.get() PMPrintSession]); - PMPageFormat page_format = - static_cast<PMPageFormat>([print_info_.get() PMPageFormat]); - PMPrinter printer; - PMSessionGetCurrentPrinter(print_session, &printer); - - PrintSettingsInitializerMac::InitPrintSettings( - printer, page_format, page_ranges, false, &settings_); + InitPrintSettingsFromPrintInfo(page_ranges); } PrintingContext::Result PrintingContextMac::InitWithSettings( |