Fix DisownOpener and related tests.
[chromium-blink-merge.git] / printing / printing_context_win.h
blob6c1e42041b655e0c0f91a4c14bf7d598cf49bc3e
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 gfx::Size GetPdfPaperSizeDeviceUnits() OVERRIDE;
33 virtual Result UpdatePrinterSettings(bool external_preview) OVERRIDE;
34 virtual Result InitWithSettings(const PrintSettings& settings) OVERRIDE;
35 virtual Result NewDocument(const base::string16& document_name) OVERRIDE;
36 virtual Result NewPage() OVERRIDE;
37 virtual Result PageDone() OVERRIDE;
38 virtual Result DocumentDone() OVERRIDE;
39 virtual void Cancel() OVERRIDE;
40 virtual void ReleaseContext() OVERRIDE;
41 virtual gfx::NativeDrawingContext context() const OVERRIDE;
43 // Allocates the HDC for a specific DEVMODE.
44 static bool AllocateContext(const std::wstring& printer_name,
45 const DEVMODE* dev_mode,
46 gfx::NativeDrawingContext* context);
48 protected:
49 virtual HRESULT ShowPrintDialog(PRINTDLGEX* options);
51 private:
52 // Class that manages the PrintDlgEx() callbacks. This is meant to be a
53 // temporary object used during the Print... dialog display.
54 class CallbackHandler;
56 // Used in response to the user canceling the printing.
57 static BOOL CALLBACK AbortProc(HDC hdc, int nCode);
59 // Reads the settings from the selected device context. Updates settings_ and
60 // its margins.
61 bool InitializeSettings(const DEVMODE& dev_mode,
62 const std::wstring& new_device_name,
63 const PRINTPAGERANGE* ranges,
64 int number_ranges,
65 bool selection_only);
67 // Retrieves the printer's default low-level settings. On Windows, context_ is
68 // allocated with this call.
69 bool GetPrinterSettings(HANDLE printer,
70 const std::wstring& device_name);
72 // Parses the result of a PRINTDLGEX result.
73 Result ParseDialogResultEx(const PRINTDLGEX& dialog_options);
74 Result ParseDialogResult(const PRINTDLG& dialog_options);
76 // The selected printer context.
77 HDC context_;
79 // The dialog box for the time it is shown.
80 volatile HWND dialog_box_;
82 DISALLOW_COPY_AND_ASSIGN(PrintingContextWin);
85 } // namespace printing
87 #endif // PRINTING_PRINTING_CONTEXT_WIN_H_