Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef PRINTING_PRINTING_CONTEXT_MAC_H_ |
| 6 | #define PRINTING_PRINTING_CONTEXT_MAC_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 10 | #include "base/mac/scoped_nsobject.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 11 | #include "printing/print_job_constants.h" |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 12 | #include "printing/printing_context.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 13 | |
| 14 | #ifdef __OBJC__ |
| 15 | @class NSPrintInfo; |
| 16 | #else |
| 17 | class NSPrintInfo; |
| 18 | #endif // __OBJC__ |
| 19 | |
| 20 | namespace printing { |
| 21 | |
| 22 | class PRINTING_EXPORT PrintingContextMac : public PrintingContext { |
| 23 | public: |
| 24 | explicit PrintingContextMac(const std::string& app_locale); |
| 25 | virtual ~PrintingContextMac(); |
| 26 | |
| 27 | // PrintingContext implementation. |
| 28 | virtual void AskUserForSettings( |
| 29 | gfx::NativeView parent_view, |
| 30 | int max_pages, |
| 31 | bool has_selection, |
| 32 | const PrintSettingsCallback& callback) OVERRIDE; |
| 33 | virtual Result UseDefaultSettings() OVERRIDE; |
| 34 | virtual Result UpdatePrinterSettings( |
| 35 | const base::DictionaryValue& job_settings, |
| 36 | const PageRanges& ranges) OVERRIDE; |
| 37 | virtual Result InitWithSettings(const PrintSettings& settings) OVERRIDE; |
| 38 | virtual Result NewDocument(const string16& document_name) OVERRIDE; |
| 39 | virtual Result NewPage() OVERRIDE; |
| 40 | virtual Result PageDone() OVERRIDE; |
| 41 | virtual Result DocumentDone() OVERRIDE; |
| 42 | virtual void Cancel() OVERRIDE; |
| 43 | virtual void ReleaseContext() OVERRIDE; |
| 44 | virtual gfx::NativeDrawingContext context() const OVERRIDE; |
| 45 | |
| 46 | private: |
| 47 | // Initializes PrintSettings from |print_info_|. This must be called |
| 48 | // after changes to |print_info_| in order for the changes to take effect in |
| 49 | // printing. |
| 50 | // This function ignores the page range information specified in the print |
| 51 | // info object and use |ranges| instead. |
| 52 | void InitPrintSettingsFromPrintInfo(const PageRanges& ranges); |
| 53 | |
| 54 | // Returns the set of page ranges constructed from |print_info_|. |
| 55 | PageRanges GetPageRangesFromPrintInfo(); |
| 56 | |
| 57 | // Updates |print_info_| to use the given printer. |
| 58 | // Returns true if the printer was set else returns false. |
| 59 | bool SetPrinter(const std::string& device_name); |
| 60 | |
| 61 | // Updates |print_info_| page format with user default paper information. |
| 62 | // Returns true if the paper was set else returns false. |
| 63 | bool UpdatePageFormatWithPaperInfo(); |
| 64 | |
| 65 | // Sets the print job destination type as preview job. |
| 66 | // Returns true if the print job destination type is set. |
| 67 | bool SetPrintPreviewJob(); |
| 68 | |
| 69 | // Sets |copies| in PMPrintSettings. |
| 70 | // Returns true if the number of copies is set. |
| 71 | bool SetCopiesInPrintSettings(int copies); |
| 72 | |
| 73 | // Sets |collate| in PMPrintSettings. |
| 74 | // Returns true if |collate| is set. |
| 75 | bool SetCollateInPrintSettings(bool collate); |
| 76 | |
| 77 | // Sets orientation in native print info object. |
| 78 | // Returns true if the orientation was set. |
| 79 | bool SetOrientationIsLandscape(bool landscape); |
| 80 | |
| 81 | // Sets duplex mode in PMPrintSettings. |
| 82 | // Returns true if duplex mode is set. |
| 83 | bool SetDuplexModeInPrintSettings(DuplexMode mode); |
| 84 | |
| 85 | // Sets output color mode in PMPrintSettings. |
| 86 | // Returns true if color mode is set. |
| 87 | bool SetOutputColor(int color_mode); |
| 88 | |
| 89 | // The native print info object. |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 90 | base::scoped_nsobject<NSPrintInfo> print_info_; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 91 | |
| 92 | // The current page's context; only valid between NewPage and PageDone call |
| 93 | // pairs. |
| 94 | CGContext* context_; |
| 95 | |
| 96 | DISALLOW_COPY_AND_ASSIGN(PrintingContextMac); |
| 97 | }; |
| 98 | |
| 99 | } // namespace printing |
| 100 | |
| 101 | #endif // PRINTING_PRINTING_CONTEXT_MAC_H_ |