| OLD | NEW |
| (Empty) |
| 1 // Copyright 2008-2009 Google Inc. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 // you may not use this file except in compliance with the License. | |
| 5 // You may obtain a copy of the License at | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 // ======================================================================== | |
| 15 | |
| 16 #ifndef OMAHA_UI_UI_H_ | |
| 17 #define OMAHA_UI_UI_H_ | |
| 18 | |
| 19 #include <atlbase.h> | |
| 20 #include <atlstr.h> | |
| 21 #include <vector> | |
| 22 #include "base/basictypes.h" | |
| 23 #include "base/scoped_ptr.h" | |
| 24 #include "omaha/base/scoped_any.h" | |
| 25 #include "omaha/base/wtl_atlapp_wrapper.h" | |
| 26 // TODO(omaha3): Depending on how separate the UI is, we may want to separate | |
| 27 // the UI-specific resources, especially the dialogs. Can we handle bidi | |
| 28 // independent of languages? This would allow simple replacement of Omaha's | |
| 29 // UI without impacting the core or error messages. | |
| 30 #include "omaha/client/resource.h" | |
| 31 | |
| 32 namespace omaha { | |
| 33 | |
| 34 class HighresTimer; | |
| 35 | |
| 36 class OmahaWndEvents { | |
| 37 public: | |
| 38 virtual ~OmahaWndEvents() {} | |
| 39 virtual void DoClose() = 0; | |
| 40 virtual void DoExit() = 0; | |
| 41 }; | |
| 42 | |
| 43 // Implements the UI progress window. | |
| 44 class OmahaWnd | |
| 45 : public CAxDialogImpl<OmahaWnd>, | |
| 46 public CMessageFilter { | |
| 47 typedef CAxDialogImpl<OmahaWnd> Base; | |
| 48 public: | |
| 49 virtual ~OmahaWnd(); | |
| 50 | |
| 51 // The dialog resource ID as required by CAxDialogImpl. | |
| 52 const int IDD; | |
| 53 | |
| 54 virtual HRESULT Initialize(); | |
| 55 | |
| 56 // CMessageFilter interface method. | |
| 57 BOOL PreTranslateMessage(MSG* msg) { | |
| 58 return CWindow::IsDialogMessage(msg); | |
| 59 } | |
| 60 | |
| 61 void SetEventSink(OmahaWndEvents* ev) { events_sink_ = ev; } | |
| 62 | |
| 63 // TODO(omaha3): Move these to constructor. They are fundamental to the UI. | |
| 64 // TODO(omaha3): Move is_machine_ to CompleteWnd if we do not use UI displayed | |
| 65 // events. There it will be used to create the URL if we do not move that too. | |
| 66 void set_is_machine(bool is_machine) { is_machine_ = is_machine; } | |
| 67 void set_bundle_name(const CString& name) { bundle_name_ = name; } | |
| 68 | |
| 69 virtual void Show(); | |
| 70 | |
| 71 BEGIN_MSG_MAP(OmahaWnd) | |
| 72 MESSAGE_HANDLER(WM_CLOSE, OnClose) | |
| 73 MESSAGE_HANDLER(WM_NCDESTROY, OnNCDestroy) | |
| 74 COMMAND_ID_HANDLER(IDCANCEL, OnCancel) | |
| 75 CHAIN_MSG_MAP(Base) | |
| 76 END_MSG_MAP() | |
| 77 | |
| 78 protected: | |
| 79 #pragma warning(disable : 4510 4610) | |
| 80 // C4510: default constructor could not be generated | |
| 81 // C4610: struct can never be instantiated - user defined constructor required | |
| 82 struct ControlAttributes { | |
| 83 const bool is_visible_; | |
| 84 const bool is_enabled_; | |
| 85 const bool is_button_; | |
| 86 const bool is_default_; | |
| 87 }; | |
| 88 #pragma warning(default : 4510 4610) | |
| 89 | |
| 90 OmahaWnd(int dialog_id, CMessageLoop* message_loop, HWND parent); | |
| 91 | |
| 92 // Message and command handlers. | |
| 93 LRESULT OnClose(UINT msg, WPARAM wparam, LPARAM lparam, BOOL& handled);
// NOLINT | |
| 94 LRESULT OnNCDestroy(UINT msg, WPARAM wparam, LPARAM lparam, BOOL& handled);
// NOLINT | |
| 95 LRESULT OnCancel(WORD notify_code, WORD id, HWND wnd_ctl, BOOL& handled);
// NOLINT | |
| 96 | |
| 97 // Handles requests to close the window. Returns true if the window is closed. | |
| 98 virtual bool MaybeCloseWindow() = 0; | |
| 99 | |
| 100 // Handles entering the completion mode. | |
| 101 // Returns whether to continue with OnComplete operations. | |
| 102 bool OnComplete(); | |
| 103 | |
| 104 // TODO(omaha3): May need to be public to implement | |
| 105 // COMPLETION_CODE_SUCCESS_CLOSE_UI outside the UI. | |
| 106 // Closes the window. | |
| 107 HRESULT CloseWindow(); | |
| 108 void InitializeDialog(); | |
| 109 | |
| 110 HRESULT EnableClose(bool enable); | |
| 111 HRESULT EnableSystemCloseButton(bool enable); | |
| 112 | |
| 113 void SetControlAttributes(int control_id, | |
| 114 const ControlAttributes& attributes); | |
| 115 | |
| 116 void SetVisible(bool visible) { | |
| 117 ShowWindow(visible ? SW_SHOWNORMAL : SW_HIDE); | |
| 118 } | |
| 119 | |
| 120 DWORD thread_id() { return thread_id_; } | |
| 121 CMessageLoop* message_loop() { return message_loop_; } | |
| 122 bool is_complete() { return is_complete_; } | |
| 123 bool is_close_enabled() { return is_close_enabled_; } | |
| 124 bool is_machine() { return is_machine_; } | |
| 125 const CString& bundle_name() { return bundle_name_; } | |
| 126 | |
| 127 static const ControlAttributes kVisibleTextAttributes; | |
| 128 static const ControlAttributes kDefaultActiveButtonAttributes; | |
| 129 static const ControlAttributes kNonDefaultActiveButtonAttributes; | |
| 130 static const ControlAttributes kVisibleImageAttributes; | |
| 131 static const ControlAttributes kDisabledNonButtonAttributes; | |
| 132 | |
| 133 private: | |
| 134 HRESULT SetWindowIcon(); | |
| 135 | |
| 136 void MaybeRequestExitProcess(); | |
| 137 void RequestExitProcess(); | |
| 138 | |
| 139 CMessageLoop* message_loop_; | |
| 140 HWND parent_; | |
| 141 DWORD thread_id_; | |
| 142 | |
| 143 bool is_complete_; | |
| 144 bool is_close_enabled_; | |
| 145 | |
| 146 OmahaWndEvents* events_sink_; | |
| 147 | |
| 148 bool is_machine_; | |
| 149 CString bundle_name_; | |
| 150 | |
| 151 | |
| 152 // Handle to large icon to show when ALT-TAB | |
| 153 scoped_hicon hicon_; | |
| 154 | |
| 155 DISALLOW_EVIL_CONSTRUCTORS(OmahaWnd); | |
| 156 }; | |
| 157 | |
| 158 // Registers the specified common control classes from the common control DLL. | |
| 159 // Calls are cumulative, meaning control_classes are added to existing classes. | |
| 160 // UIs that use common controls should call this method to ensure that the UI | |
| 161 // supports visual styles. | |
| 162 HRESULT InitializeCommonControls(DWORD control_classes); | |
| 163 | |
| 164 } // namespace omaha | |
| 165 | |
| 166 #endif // OMAHA_UI_UI_H_ | |
| OLD | NEW |