OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_VIEWS_WINDOW_H__ | 5 #ifndef CHROME_VIEWS_WINDOW_H__ |
6 #define CHROME_VIEWS_WINDOW_H__ | 6 #define CHROME_VIEWS_WINDOW_H__ |
7 | 7 |
8 #include "chrome/common/notification_registrar.h" | 8 #include "chrome/common/notification_registrar.h" |
9 #include "chrome/views/client_view.h" | 9 #include "chrome/views/client_view.h" |
10 #include "chrome/views/non_client_view.h" | 10 #include "chrome/views/non_client_view.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 | 61 |
62 // Sizes and/or places the window to the specified bounds, size or position. | 62 // Sizes and/or places the window to the specified bounds, size or position. |
63 void SetBounds(const gfx::Rect& bounds); | 63 void SetBounds(const gfx::Rect& bounds); |
64 // As above, except the window is inserted after |other_hwnd| in the window | 64 // As above, except the window is inserted after |other_hwnd| in the window |
65 // Z-order. If this window's HWND is not yet visible, other_hwnd's monitor | 65 // Z-order. If this window's HWND is not yet visible, other_hwnd's monitor |
66 // is used as the constraining rectangle, rather than this window's hwnd's | 66 // is used as the constraining rectangle, rather than this window's hwnd's |
67 // monitor. | 67 // monitor. |
68 void SetBounds(const gfx::Rect& bounds, HWND other_hwnd); | 68 void SetBounds(const gfx::Rect& bounds, HWND other_hwnd); |
69 | 69 |
70 // Closes the window, ultimately destroying it. | 70 // Closes the window, ultimately destroying it. |
71 virtual void Close(); | 71 void Close(); |
72 | 72 |
73 // Whether or not the window is maximized or minimized. | 73 // Whether or not the window is maximized or minimized. |
74 bool IsMaximized() const; | 74 bool IsMaximized() const; |
75 bool IsMinimized() const; | 75 bool IsMinimized() const; |
76 | 76 |
77 // Toggles the enable state for the Close button (and the Close menu item in | 77 // Toggles the enable state for the Close button (and the Close menu item in |
78 // the system menu). | 78 // the system menu). |
79 virtual void EnableClose(bool enable); | 79 void EnableClose(bool enable); |
80 | 80 |
81 // Prevents the window from being rendered as deactivated when |disable| is | 81 // Prevents the window from being rendered as deactivated the next time it is. |
82 // true, until called with |disable| false. Used when a sub-window is to be | 82 // This state is reset automatically as soon as the window becomes actiated |
83 // shown that shouldn't visually de-activate the window. | 83 // again. There is no ability to control the state through this API as this |
84 // Subclasses can override this to perform additional actions when this value | 84 // leads to sync problems. |
85 // changes. | 85 void DisableInactiveRendering(); |
86 virtual void DisableInactiveRendering(bool disable); | |
87 | 86 |
| 87 // Tell the window to update its title from the delegate. |
| 88 void UpdateWindowTitle(); |
| 89 |
| 90 // Tell the window to update its icon from the delegate. |
| 91 void UpdateWindowIcon(); |
| 92 |
| 93 // Executes the specified SC_command. |
| 94 void ExecuteSystemMenuCommand(int command); |
| 95 |
| 96 // Shortcut to access the determination of whether or not we're using a |
| 97 // native frame. This triggers different rendering modes in certain views and |
| 98 // should be used in preference to calling win_util::ShouldUseVistaFrame. |
| 99 bool UseNativeFrame() const { return non_client_view_->UseNativeFrame(); } |
| 100 |
| 101 // Returns the bounds of the window required to display the content area |
| 102 // at the specified bounds. |
| 103 gfx::Rect GetWindowBoundsForClientBounds(const gfx::Rect& client_bounds); |
| 104 |
| 105 // Creates an appropriate NonClientFrameView for this window. |
| 106 virtual NonClientFrameView* CreateFrameViewForWindow(); |
| 107 |
| 108 // Updates the frame after an event caused it to be changed. |
| 109 virtual void UpdateFrameAfterFrameChange(); |
| 110 |
| 111 // Accessors and setters for various properties. |
88 WindowDelegate* window_delegate() const { return window_delegate_; } | 112 WindowDelegate* window_delegate() const { return window_delegate_; } |
89 | 113 HWND owning_window() const { return owning_hwnd_; } |
| 114 ClientView* client_view() const { return non_client_view_->client_view(); } |
| 115 bool is_active() const { return is_active_; } |
90 void set_focus_on_creation(bool focus_on_creation) { | 116 void set_focus_on_creation(bool focus_on_creation) { |
91 focus_on_creation_ = focus_on_creation; | 117 focus_on_creation_ = focus_on_creation; |
92 } | 118 } |
93 | 119 |
94 // Tell the window to update its title from the delegate. | |
95 virtual void UpdateWindowTitle(); | |
96 | |
97 // Tell the window to update its icon from the delegate. | |
98 virtual void UpdateWindowIcon(); | |
99 | |
100 // Executes the specified SC_command. | |
101 void ExecuteSystemMenuCommand(int command); | |
102 | |
103 // The parent of this window. | |
104 HWND owning_window() const { return owning_hwnd_; } | |
105 | |
106 // Shortcut to access the ClientView associated with this window. | |
107 ClientView* client_view() const { return non_client_view_->client_view(); } | |
108 | |
109 // Returns the preferred size of the contents view of this window based on | 120 // Returns the preferred size of the contents view of this window based on |
110 // its localized size data. The width in cols is held in a localized string | 121 // its localized size data. The width in cols is held in a localized string |
111 // resource identified by |col_resource_id|, the height in the same fashion. | 122 // resource identified by |col_resource_id|, the height in the same fashion. |
112 // TODO(beng): This should eventually live somewhere else, probably closer to | 123 // TODO(beng): This should eventually live somewhere else, probably closer to |
113 // ClientView. | 124 // ClientView. |
114 static int GetLocalizedContentsWidth(int col_resource_id); | 125 static int GetLocalizedContentsWidth(int col_resource_id); |
115 static int GetLocalizedContentsHeight(int row_resource_id); | 126 static int GetLocalizedContentsHeight(int row_resource_id); |
116 static gfx::Size GetLocalizedContentsSize(int col_resource_id, | 127 static gfx::Size GetLocalizedContentsSize(int col_resource_id, |
117 int row_resource_id); | 128 int row_resource_id); |
118 | 129 |
(...skipping 18 matching lines...) Expand all Loading... |
137 // Returns true if the Window is considered to be an "app window" - i.e. any | 148 // Returns true if the Window is considered to be an "app window" - i.e. any |
138 // window which when it is the last of its type closed causes the application | 149 // window which when it is the last of its type closed causes the application |
139 // to exit. | 150 // to exit. |
140 virtual bool IsAppWindow() const { return false; } | 151 virtual bool IsAppWindow() const { return false; } |
141 | 152 |
142 // Shows the system menu at the specified screen point. | 153 // Shows the system menu at the specified screen point. |
143 void RunSystemMenu(const gfx::Point& point); | 154 void RunSystemMenu(const gfx::Point& point); |
144 | 155 |
145 // Overridden from WidgetWin: | 156 // Overridden from WidgetWin: |
146 virtual void OnActivate(UINT action, BOOL minimized, HWND window); | 157 virtual void OnActivate(UINT action, BOOL minimized, HWND window); |
| 158 virtual void OnActivateApp(BOOL active, DWORD thread_id); |
147 virtual LRESULT OnAppCommand(HWND window, short app_command, WORD device, | 159 virtual LRESULT OnAppCommand(HWND window, short app_command, WORD device, |
148 int keystate); | 160 int keystate); |
149 virtual void OnCommand(UINT notification_code, int command_id, HWND window); | 161 virtual void OnCommand(UINT notification_code, int command_id, HWND window); |
150 virtual void OnDestroy(); | 162 virtual void OnDestroy(); |
| 163 virtual LRESULT OnDwmCompositionChanged(UINT msg, WPARAM w_param, |
| 164 LPARAM l_param); |
151 virtual void OnInitMenu(HMENU menu); | 165 virtual void OnInitMenu(HMENU menu); |
152 virtual void OnMouseLeave(); | 166 virtual void OnMouseLeave(); |
153 virtual LRESULT OnNCActivate(BOOL active); | 167 virtual LRESULT OnNCActivate(BOOL active); |
154 virtual LRESULT OnNCCalcSize(BOOL mode, LPARAM l_param); | 168 virtual LRESULT OnNCCalcSize(BOOL mode, LPARAM l_param); |
155 virtual LRESULT OnNCHitTest(const CPoint& point); | 169 virtual LRESULT OnNCHitTest(const CPoint& point); |
156 virtual LRESULT OnNCUAHDrawCaption(UINT msg, WPARAM w_param, LPARAM l_param); | |
157 virtual LRESULT OnNCUAHDrawFrame(UINT msg, WPARAM w_param, LPARAM l_param); | |
158 virtual void OnNCPaint(HRGN rgn); | 170 virtual void OnNCPaint(HRGN rgn); |
159 virtual void OnNCLButtonDown(UINT ht_component, const CPoint& point); | 171 virtual void OnNCLButtonDown(UINT ht_component, const CPoint& point); |
160 virtual void OnNCRButtonDown(UINT ht_component, const CPoint& point); | 172 virtual void OnNCRButtonDown(UINT ht_component, const CPoint& point); |
| 173 virtual LRESULT OnNCUAHDrawCaption(UINT msg, WPARAM w_param, LPARAM l_param); |
| 174 virtual LRESULT OnNCUAHDrawFrame(UINT msg, WPARAM w_param, LPARAM l_param); |
161 virtual LRESULT OnSetCursor(HWND window, UINT hittest_code, UINT message); | 175 virtual LRESULT OnSetCursor(HWND window, UINT hittest_code, UINT message); |
162 virtual LRESULT OnSetIcon(UINT size_type, HICON new_icon); | 176 virtual LRESULT OnSetIcon(UINT size_type, HICON new_icon); |
163 virtual LRESULT OnSetText(const wchar_t* text); | 177 virtual LRESULT OnSetText(const wchar_t* text); |
164 virtual void OnSize(UINT size_param, const CSize& new_size); | 178 virtual void OnSize(UINT size_param, const CSize& new_size); |
165 virtual void OnSysCommand(UINT notification_code, CPoint click); | 179 virtual void OnSysCommand(UINT notification_code, CPoint click); |
| 180 virtual Window* AsWindow() { return this; } |
| 181 virtual const Window* AsWindow() const { return this; } |
166 | 182 |
167 // The View that provides the non-client area of the window (title bar, | 183 // The View that provides the non-client area of the window (title bar, |
168 // window controls, sizing borders etc). To use an implementation other than | 184 // window controls, sizing borders etc). To use an implementation other than |
169 // the default, this class must be subclassed and this value set to the | 185 // the default, this class must be subclassed and this value set to the |
170 // desired implementation before calling |Init|. | 186 // desired implementation before calling |Init|. |
171 NonClientView* non_client_view_; | 187 NonClientView* non_client_view_; |
172 | 188 |
173 // Accessor for disable_inactive_rendering_. | 189 // Accessor for disable_inactive_rendering_. |
174 bool disable_inactive_rendering() const { | 190 bool disable_inactive_rendering() const { |
175 return disable_inactive_rendering_; | 191 return disable_inactive_rendering_; |
176 } | 192 } |
177 | 193 |
178 private: | 194 private: |
179 // Sets the specified view as the ClientView of this Window. The ClientView | |
180 // is responsible for laying out the Window's contents view, as well as | |
181 // performing basic hit-testing, and perhaps other responsibilities depending | |
182 // on the implementation. The Window's view hierarchy takes ownership of the | |
183 // ClientView unless the ClientView specifies otherwise. This must be called | |
184 // only once, and after the native window has been created. | |
185 // This is called by Init. |client_view| cannot be NULL. | |
186 void SetClientView(ClientView* client_view); | |
187 | |
188 // Set the window as modal (by disabling all the other windows). | 195 // Set the window as modal (by disabling all the other windows). |
189 void BecomeModal(); | 196 void BecomeModal(); |
190 | 197 |
191 // Sets-up the focus manager with the view that should have focus when the | 198 // Sets-up the focus manager with the view that should have focus when the |
192 // window is shown the first time. If NULL is returned, the focus goes to the | 199 // window is shown the first time. If NULL is returned, the focus goes to the |
193 // button if there is one, otherwise the to the Cancel button. | 200 // button if there is one, otherwise the to the Cancel button. |
194 void SetInitialFocus(); | 201 void SetInitialFocus(); |
195 | 202 |
196 // Place and size the window when it is created. |create_bounds| are the | 203 // Place and size the window when it is created. |create_bounds| are the |
197 // bounds used when the window was created. | 204 // bounds used when the window was created. |
(...skipping 19 matching lines...) Expand all Loading... |
217 // Asks the delegate if any to save the window's location and size. | 224 // Asks the delegate if any to save the window's location and size. |
218 void SaveWindowPosition(); | 225 void SaveWindowPosition(); |
219 | 226 |
220 // Lock or unlock the window from being able to redraw itself in response to | 227 // Lock or unlock the window from being able to redraw itself in response to |
221 // updates to its invalid region. | 228 // updates to its invalid region. |
222 class ScopedRedrawLock; | 229 class ScopedRedrawLock; |
223 void LockUpdates(); | 230 void LockUpdates(); |
224 void UnlockUpdates(); | 231 void UnlockUpdates(); |
225 | 232 |
226 // Resets the window region for the current window bounds if necessary. | 233 // Resets the window region for the current window bounds if necessary. |
227 void ResetWindowRegion(); | 234 // If |force| is true, the window region is reset to NULL even for native |
| 235 // frame windows. |
| 236 void ResetWindowRegion(bool force); |
228 | 237 |
229 // Converts a non-client mouse down message to a regular ChromeViews event | 238 // Converts a non-client mouse down message to a regular ChromeViews event |
230 // and handle it. |point| is the mouse position of the message in screen | 239 // and handle it. |point| is the mouse position of the message in screen |
231 // coords. |flags| are flags that would be passed with a WM_L/M/RBUTTON* | 240 // coords. |flags| are flags that would be passed with a WM_L/M/RBUTTON* |
232 // message and relate to things like which button was pressed. These are | 241 // message and relate to things like which button was pressed. These are |
233 // combined with flags relating to the current key state. | 242 // combined with flags relating to the current key state. |
234 void ProcessNCMousePress(const CPoint& point, int flags); | 243 void ProcessNCMousePress(const CPoint& point, int flags); |
235 | 244 |
| 245 // Calls the default WM_NCACTIVATE handler with the specified activation |
| 246 // value, safely wrapping the call in a ScopedRedrawLock to prevent frame |
| 247 // flicker. |
| 248 LRESULT CallDefaultNCActivateHandler(BOOL active); |
| 249 |
236 // Static resource initialization. | 250 // Static resource initialization. |
237 static void InitClass(); | 251 static void InitClass(); |
238 enum ResizeCursor { | 252 enum ResizeCursor { |
239 RC_NORMAL = 0, RC_VERTICAL, RC_HORIZONTAL, RC_NESW, RC_NWSE | 253 RC_NORMAL = 0, RC_VERTICAL, RC_HORIZONTAL, RC_NESW, RC_NWSE |
240 }; | 254 }; |
241 static HCURSOR resize_cursors_[6]; | 255 static HCURSOR resize_cursors_[6]; |
242 | 256 |
243 // Our window delegate (see Init method for documentation). | 257 // Our window delegate (see Init method for documentation). |
244 WindowDelegate* window_delegate_; | 258 WindowDelegate* window_delegate_; |
245 | 259 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 | 305 |
292 // Hold onto notifications. | 306 // Hold onto notifications. |
293 NotificationRegistrar notification_registrar_; | 307 NotificationRegistrar notification_registrar_; |
294 | 308 |
295 DISALLOW_COPY_AND_ASSIGN(Window); | 309 DISALLOW_COPY_AND_ASSIGN(Window); |
296 }; | 310 }; |
297 | 311 |
298 } // namespace views | 312 } // namespace views |
299 | 313 |
300 #endif // CHROME_VIEWS_WINDOW_H__ | 314 #endif // CHROME_VIEWS_WINDOW_H__ |
OLD | NEW |