Add support for generating jars from protos and add cacheinvalidation_java.
[chromium-blink-merge.git] / printing / printing_context_win.h
blobb167a0a91cd387f7d84483f73dd2fa9fa360ea25
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.
5 #ifndef PRINTING_PRINTING_CONTEXT_WIN_H_
6 #define PRINTING_PRINTING_CONTEXT_WIN_H_
8 #include <ocidl.h>
9 #include <commdlg.h>
11 #include <string>
13 #include "base/memory/scoped_ptr.h"
14 #include "build/build_config.h"
15 #include "printing/printing_context.h"
16 #include "ui/gfx/native_widget_types.h"
18 namespace printing {
20 class PRINTING_EXPORT PrintingContextWin : public PrintingContext {
21 public:
22 explicit PrintingContextWin(const std::string& app_locale);
23 ~PrintingContextWin();
25 // PrintingContext implementation.
26 virtual void AskUserForSettings(
27 gfx::NativeView parent_view,
28 int max_pages,
29 bool has_selection,
30 const PrintSettingsCallback& callback) OVERRIDE;
31 virtual Result UseDefaultSettings() OVERRIDE;
32 virtual Result UpdatePrinterSettings(
33 const base::DictionaryValue& job_settings,
34 const PageRanges& ranges) OVERRIDE;
35 virtual Result InitWithSettings(const PrintSettings& settings) OVERRIDE;
36 virtual Result NewDocument(const string16& document_name) OVERRIDE;
37 virtual Result NewPage() OVERRIDE;
38 virtual Result PageDone() OVERRIDE;
39 virtual Result DocumentDone() OVERRIDE;
40 virtual void Cancel() OVERRIDE;
41 virtual void ReleaseContext() OVERRIDE;
42 virtual gfx::NativeDrawingContext context() const OVERRIDE;
44 #if defined(UNIT_TEST) || defined(PRINTING_IMPLEMENTATION)
45 // Sets a fake PrintDlgEx function pointer in tests.
46 void SetPrintDialog(HRESULT (__stdcall *print_dialog_func)(LPPRINTDLGEX)) {
47 print_dialog_func_ = print_dialog_func;
49 #endif // defined(UNIT_TEST)
51 // Allocates the HDC for a specific DEVMODE.
52 static bool AllocateContext(const std::wstring& printer_name,
53 const DEVMODE* dev_mode,
54 gfx::NativeDrawingContext* context);
56 // Retrieves the content of a GetPrinter call.
57 static void GetPrinterHelper(HANDLE printer, int level,
58 scoped_array<uint8>* buffer);
60 private:
61 // Class that manages the PrintDlgEx() callbacks. This is meant to be a
62 // temporary object used during the Print... dialog display.
63 class CallbackHandler;
65 // Used in response to the user canceling the printing.
66 static BOOL CALLBACK AbortProc(HDC hdc, int nCode);
68 // Reads the settings from the selected device context. Updates settings_ and
69 // its margins.
70 bool InitializeSettings(const DEVMODE& dev_mode,
71 const std::wstring& new_device_name,
72 const PRINTPAGERANGE* ranges,
73 int number_ranges,
74 bool selection_only);
76 // Retrieves the printer's default low-level settings. On Windows, context_ is
77 // allocated with this call.
78 bool GetPrinterSettings(HANDLE printer,
79 const std::wstring& device_name);
81 // Parses the result of a PRINTDLGEX result.
82 Result ParseDialogResultEx(const PRINTDLGEX& dialog_options);
83 Result ParseDialogResult(const PRINTDLG& dialog_options);
85 // The selected printer context.
86 HDC context_;
88 // The dialog box for the time it is shown.
89 volatile HWND dialog_box_;
91 // Function pointer that defaults to PrintDlgEx. It can be changed using
92 // SetPrintDialog() in tests.
93 HRESULT (__stdcall *print_dialog_func_)(LPPRINTDLGEX);
95 DISALLOW_COPY_AND_ASSIGN(PrintingContextWin);
98 } // namespace printing
100 #endif // PRINTING_PRINTING_CONTEXT_WIN_H_