1 // Copyright 2013 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 UI_SHELL_DIALOGS_PRINT_SETTINGS_DIALOG_WIN_H_
6 #define UI_SHELL_DIALOGS_PRINT_SETTINGS_DIALOG_WIN_H_
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop/message_loop.h"
14 #include "base/message_loop/message_loop_proxy.h"
15 #include "ui/shell_dialogs/base_shell_dialog_win.h"
16 #include "ui/shell_dialogs/shell_dialogs_export.h"
20 // A thin wrapper around the native window print dialog that uses
21 // BaseShellDialog to have the dialog run on a background thread.
22 class SHELL_DIALOGS_EXPORT PrintSettingsDialogWin
23 : public base::RefCountedThreadSafe
<PrintSettingsDialogWin
>,
24 public BaseShellDialogImpl
{
26 class SHELL_DIALOGS_EXPORT Observer
{
28 virtual void PrintSettingsConfirmed(PRINTDLGEX
* dialog_options
) = 0;
29 virtual void PrintSettingsCancelled(PRINTDLGEX
* dialog_options
) = 0;
31 typedef HRESULT(__stdcall
* PrintDialogFunc
)(PRINTDLGEX
*);
33 explicit PrintSettingsDialogWin(Observer
* observer
);
34 virtual ~PrintSettingsDialogWin();
36 // Called to open the system print dialog on a background thread.
37 // |print_dialog_func| should generally be ::PrintDlgEx, however alternate
38 // functions are used for testing. |owning_window| is the parent HWND, and
39 // |dialog_options| is passed to |print_dialog_func|.
40 void GetPrintSettings(
41 PrintDialogFunc print_dialog_func
,
43 PRINTDLGEX
* dialog_options
);
46 // A struct for holding all the state necessary for displaying the print
48 struct ExecutePrintSettingsParams
{
49 ExecutePrintSettingsParams(RunState run_state
,
51 PrintDialogFunc print_dialog_func
,
52 PRINTDLGEX
* dialog_options
)
53 : run_state(run_state
),
55 print_dialog_func(print_dialog_func
),
56 dialog_options(dialog_options
),
57 ui_proxy(base::MessageLoopForUI::current()->message_loop_proxy()) {}
61 PrintDialogFunc print_dialog_func
;
62 PRINTDLGEX
* dialog_options
;
63 scoped_refptr
<base::MessageLoopProxy
> ui_proxy
;
66 // Runs the print dialog. Should be run on the the BaseShellDialogImpl thread.
67 // Posts back to PrintSettingsCompleted on the UI thread on completion.
68 void ExecutePrintSettings(const ExecutePrintSettingsParams
& params
);
70 // Handler for the result of the print settings dialog. Should be run on the
71 // UI thread, and notifies the observer of the result of the dialog.
72 void PrintSettingsCompleted(HRESULT hresult
,
73 const ExecutePrintSettingsParams
& params
);
75 // Observer that's notified when the dialog is confirmed or cancelled.
78 DISALLOW_COPY_AND_ASSIGN(PrintSettingsDialogWin
);
83 #endif // UI_SHELL_DIALOGS_PRINT_SETTINGS_DIALOG_WIN_H_