blob: b167a0a91cd387f7d84483f73dd2fa9fa360ea25 [file] [log] [blame]
[email protected]7868ecab2011-03-05 00:12:531// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]51e8d9352010-10-06 22:21:172// 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_WIN_H_
6#define PRINTING_PRINTING_CONTEXT_WIN_H_
7
8#include <ocidl.h>
9#include <commdlg.h>
10
11#include <string>
12
[email protected]3b63f8f42011-03-28 01:54:1513#include "base/memory/scoped_ptr.h"
[email protected]51e8d9352010-10-06 22:21:1714#include "build/build_config.h"
[email protected]51e8d9352010-10-06 22:21:1715#include "printing/printing_context.h"
[email protected]08397d52011-02-05 01:53:3816#include "ui/gfx/native_widget_types.h"
[email protected]51e8d9352010-10-06 22:21:1717
18namespace printing {
19
[email protected]69f5b1e62011-09-01 06:34:0420class PRINTING_EXPORT PrintingContextWin : public PrintingContext {
[email protected]51e8d9352010-10-06 22:21:1721 public:
[email protected]ee5f36e42010-12-03 22:40:3722 explicit PrintingContextWin(const std::string& app_locale);
[email protected]51e8d9352010-10-06 22:21:1723 ~PrintingContextWin();
24
25 // PrintingContext implementation.
[email protected]abe48112011-11-19 01:58:3826 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;
[email protected]55b23a02011-08-17 23:09:3632 virtual Result UpdatePrinterSettings(
33 const base::DictionaryValue& job_settings,
[email protected]abe48112011-11-19 01:58:3834 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;
[email protected]51e8d9352010-10-06 22:21:1743
[email protected]69f5b1e62011-09-01 06:34:0444#if defined(UNIT_TEST) || defined(PRINTING_IMPLEMENTATION)
[email protected]51e8d9352010-10-06 22:21:1745 // Sets a fake PrintDlgEx function pointer in tests.
46 void SetPrintDialog(HRESULT (__stdcall *print_dialog_func)(LPPRINTDLGEX)) {
47 print_dialog_func_ = print_dialog_func;
48 }
49#endif // defined(UNIT_TEST)
50
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);
55
56 // Retrieves the content of a GetPrinter call.
57 static void GetPrinterHelper(HANDLE printer, int level,
58 scoped_array<uint8>* buffer);
59
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;
64
65 // Used in response to the user canceling the printing.
66 static BOOL CALLBACK AbortProc(HDC hdc, int nCode);
67
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);
75
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);
80
81 // Parses the result of a PRINTDLGEX result.
82 Result ParseDialogResultEx(const PRINTDLGEX& dialog_options);
83 Result ParseDialogResult(const PRINTDLG& dialog_options);
84
85 // The selected printer context.
86 HDC context_;
87
88 // The dialog box for the time it is shown.
89 volatile HWND dialog_box_;
90
91 // Function pointer that defaults to PrintDlgEx. It can be changed using
92 // SetPrintDialog() in tests.
93 HRESULT (__stdcall *print_dialog_func_)(LPPRINTDLGEX);
94
95 DISALLOW_COPY_AND_ASSIGN(PrintingContextWin);
96};
97
98} // namespace printing
99
100#endif // PRINTING_PRINTING_CONTEXT_WIN_H_