OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef UI_SHELL_DIALOGS_PRINT_SETTINGS_DIALOG_WIN_H_ |
| 6 #define UI_SHELL_DIALOGS_PRINT_SETTINGS_DIALOG_WIN_H_ |
| 7 |
| 8 #include <ocidl.h> |
| 9 #include <commdlg.h> |
| 10 |
| 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" |
| 17 |
| 18 namespace ui { |
| 19 |
| 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 { |
| 25 public: |
| 26 class SHELL_DIALOGS_EXPORT Observer { |
| 27 public: |
| 28 virtual void PrintSettingsConfirmed(PRINTDLGEX* dialog_options) = 0; |
| 29 virtual void PrintSettingsCancelled(PRINTDLGEX* dialog_options) = 0; |
| 30 }; |
| 31 typedef HRESULT(__stdcall* PrintDialogFunc)(PRINTDLGEX*); |
| 32 |
| 33 explicit PrintSettingsDialogWin(Observer* observer); |
| 34 virtual ~PrintSettingsDialogWin(); |
| 35 |
| 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, |
| 42 HWND owning_window, |
| 43 PRINTDLGEX* dialog_options); |
| 44 |
| 45 private: |
| 46 // A struct for holding all the state necessary for displaying the print |
| 47 // settings dialog. |
| 48 struct ExecutePrintSettingsParams { |
| 49 ExecutePrintSettingsParams(RunState run_state, |
| 50 HWND owner, |
| 51 PrintDialogFunc print_dialog_func, |
| 52 PRINTDLGEX* dialog_options) |
| 53 : run_state(run_state), |
| 54 owner(owner), |
| 55 print_dialog_func(print_dialog_func), |
| 56 dialog_options(dialog_options), |
| 57 ui_proxy(base::MessageLoopForUI::current()->message_loop_proxy()) {} |
| 58 |
| 59 RunState run_state; |
| 60 HWND owner; |
| 61 PrintDialogFunc print_dialog_func; |
| 62 PRINTDLGEX* dialog_options; |
| 63 scoped_refptr<base::MessageLoopProxy> ui_proxy; |
| 64 }; |
| 65 |
| 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); |
| 69 |
| 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); |
| 74 |
| 75 // Observer that's notified when the dialog is confirmed or cancelled. |
| 76 Observer* observer_; |
| 77 |
| 78 DISALLOW_COPY_AND_ASSIGN(PrintSettingsDialogWin); |
| 79 }; |
| 80 |
| 81 } // namespace ui |
| 82 |
| 83 #endif // UI_SHELL_DIALOGS_PRINT_SETTINGS_DIALOG_WIN_H_ |
OLD | NEW |