Revert 97987 - Switching NaCl IRT to be built inside the chrome build.
[chromium-blink-merge.git] / printing / printing_context_win.h
blobc8307368129ee58f26fdf774b44da305d62fb608
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 PrintingContextWin : public PrintingContext {
21 public:
22 explicit PrintingContextWin(const std::string& app_locale);
23 ~PrintingContextWin();
25 // PrintingContext implementation.
26 virtual void AskUserForSettings(gfx::NativeView parent_view,
27 int max_pages,
28 bool has_selection,
29 PrintSettingsCallback* callback);
30 virtual Result UseDefaultSettings();
31 virtual Result UpdatePrinterSettings(
32 const base::DictionaryValue& job_settings,
33 const PageRanges& ranges);
34 virtual Result InitWithSettings(const PrintSettings& settings);
35 virtual Result NewDocument(const string16& document_name);
36 virtual Result NewPage();
37 virtual Result PageDone();
38 virtual Result DocumentDone();
39 virtual void Cancel();
40 virtual void ReleaseContext();
41 virtual gfx::NativeDrawingContext context() const;
43 #if defined(UNIT_TEST)
44 // Sets a fake PrintDlgEx function pointer in tests.
45 void SetPrintDialog(HRESULT (__stdcall *print_dialog_func)(LPPRINTDLGEX)) {
46 print_dialog_func_ = print_dialog_func;
48 #endif // defined(UNIT_TEST)
50 // Allocates the HDC for a specific DEVMODE.
51 static bool AllocateContext(const std::wstring& printer_name,
52 const DEVMODE* dev_mode,
53 gfx::NativeDrawingContext* context);
55 // Retrieves the content of a GetPrinter call.
56 static void GetPrinterHelper(HANDLE printer, int level,
57 scoped_array<uint8>* buffer);
59 private:
60 // Class that manages the PrintDlgEx() callbacks. This is meant to be a
61 // temporary object used during the Print... dialog display.
62 class CallbackHandler;
64 // Used in response to the user canceling the printing.
65 static BOOL CALLBACK AbortProc(HDC hdc, int nCode);
67 // Reads the settings from the selected device context. Updates settings_ and
68 // its margins.
69 bool InitializeSettings(const DEVMODE& dev_mode,
70 const std::wstring& new_device_name,
71 const PRINTPAGERANGE* ranges,
72 int number_ranges,
73 bool selection_only);
75 // Retrieves the printer's default low-level settings. On Windows, context_ is
76 // allocated with this call.
77 bool GetPrinterSettings(HANDLE printer,
78 const std::wstring& device_name);
80 // Parses the result of a PRINTDLGEX result.
81 Result ParseDialogResultEx(const PRINTDLGEX& dialog_options);
82 Result ParseDialogResult(const PRINTDLG& dialog_options);
84 // The selected printer context.
85 HDC context_;
87 // The dialog box for the time it is shown.
88 volatile HWND dialog_box_;
90 // Function pointer that defaults to PrintDlgEx. It can be changed using
91 // SetPrintDialog() in tests.
92 HRESULT (__stdcall *print_dialog_func_)(LPPRINTDLGEX);
94 DISALLOW_COPY_AND_ASSIGN(PrintingContextWin);
97 } // namespace printing
99 #endif // PRINTING_PRINTING_CONTEXT_WIN_H_