| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 BASE_WINDOW_IMPL_H_ | 5 #ifndef BASE_WINDOW_IMPL_H_ |
| 6 #define BASE_WINDOW_IMPL_H_ | 6 #define BASE_WINDOW_IMPL_H_ |
| 7 | 7 |
| 8 #include <atlbase.h> | 8 #include <atlbase.h> |
| 9 #include <atlapp.h> | 9 #include <atlapp.h> |
| 10 #include <atlmisc.h> | 10 #include <atlmisc.h> |
| 11 #include <atlcrack.h> | 11 #include <atlcrack.h> |
| 12 | 12 |
| 13 #include <string> | 13 #include <string> |
| 14 | 14 |
| 15 #include "base/gfx/native_widget_types.h" | 15 #include "base/gfx/native_widget_types.h" |
| 16 #include "base/gfx/rect.h" | 16 #include "base/gfx/rect.h" |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 | 18 |
| 19 namespace base { | 19 namespace base { |
| 20 | 20 |
| 21 // An interface implemented by classes that use message maps. | |
| 22 // ProcessWindowMessage is implemented by the BEGIN_MESSAGE_MAP_EX macro. | |
| 23 class MessageMapInterface { | |
| 24 public: | |
| 25 // Processes one message from the window's message queue. | |
| 26 virtual BOOL ProcessWindowMessage(HWND window, | |
| 27 UINT message, | |
| 28 WPARAM w_param, | |
| 29 LPARAM l_param, | |
| 30 LRESULT& result, | |
| 31 DWORD msg_mad_id = 0) = 0; | |
| 32 }; | |
| 33 | |
| 34 /////////////////////////////////////////////////////////////////////////////// | 21 /////////////////////////////////////////////////////////////////////////////// |
| 35 // | 22 // |
| 36 // WindowImpl | 23 // WindowImpl |
| 37 // A convenience class that encapsulates the details of creating and | 24 // A convenience class that encapsulates the details of creating and |
| 38 // destroying a HWND. This class also hosts the windows procedure used by all | 25 // destroying a HWND. This class also hosts the windows procedure used by all |
| 39 // Windows. | 26 // Windows. |
| 40 // | 27 // |
| 41 /////////////////////////////////////////////////////////////////////////////// | 28 /////////////////////////////////////////////////////////////////////////////// |
| 42 class WindowImpl : public MessageMapInterface { | 29 class WindowImpl { |
| 43 public: | 30 public: |
| 44 WindowImpl(); | 31 WindowImpl(); |
| 45 virtual ~WindowImpl(); | 32 virtual ~WindowImpl(); |
| 46 | 33 |
| 47 // Initializes the Window with a parent and an initial desired size. | 34 BEGIN_MSG_MAP_EX(WindowImpl) |
| 48 void Init(HWND parent, const gfx::Rect& bounds); | 35 // No messages to handle |
| 36 END_MSG_MAP() |
| 37 |
| 38 // Initialize the Window with a parent and an initial desired size. |
| 39 virtual void Init(HWND parent, const gfx::Rect& bounds); |
| 40 |
| 41 // Returns the gfx::NativeView associated with this Window. |
| 42 virtual gfx::NativeView GetNativeView() const; |
| 49 | 43 |
| 50 // Retrieves the default window icon to use for windows if none is specified. | 44 // Retrieves the default window icon to use for windows if none is specified. |
| 51 virtual HICON GetDefaultWindowIcon() const; | 45 virtual HICON GetDefaultWindowIcon() const; |
| 52 | 46 |
| 53 // Returns the HWND associated with this Window. | |
| 54 HWND hwnd() const { return hwnd_; } | |
| 55 | |
| 56 // Sets the window styles. This is ONLY used when the window is created. | 47 // Sets the window styles. This is ONLY used when the window is created. |
| 57 // In other words, if you invoke this after invoking Init, nothing happens. | 48 // In other words, if you invoke this after invoking Init, nothing happens. |
| 58 void set_window_style(DWORD style) { window_style_ = style; } | 49 void set_window_style(DWORD style) { window_style_ = style; } |
| 59 DWORD window_style() const { return window_style_; } | 50 DWORD window_style() const { return window_style_; } |
| 60 | 51 |
| 61 // Sets the extended window styles. See comment about |set_window_style|. | 52 // Sets the extended window styles. See comment about |set_window_style|. |
| 62 void set_window_ex_style(DWORD style) { window_ex_style_ = style; } | 53 void set_window_ex_style(DWORD style) { window_ex_style_ = style; } |
| 63 DWORD window_ex_style() const { return window_ex_style_; } | 54 DWORD window_ex_style() const { return window_ex_style_; } |
| 64 | 55 |
| 65 // Sets the class style to use. The default is CS_DBLCLKS. | 56 // Sets the class style to use. The default is CS_DBLCLKS. |
| 66 void set_initial_class_style(UINT class_style) { | 57 void set_initial_class_style(UINT class_style) { |
| 67 // We dynamically generate the class name, so don't register it globally! | 58 // We dynamically generate the class name, so don't register it globally! |
| 68 DCHECK_EQ((class_style & CS_GLOBALCLASS), 0); | 59 DCHECK_EQ((class_style & CS_GLOBALCLASS), 0); |
| 69 class_style_ = class_style; | 60 class_style_ = class_style; |
| 70 } | 61 } |
| 71 UINT initial_class_style() { return class_style_; } | 62 UINT initial_class_style() { return class_style_; } |
| 72 | 63 |
| 73 protected: | 64 protected: |
| 65 // Call close instead of this to Destroy the window. |
| 66 BOOL DestroyWindow(); |
| 67 |
| 74 // Handles the WndProc callback for this object. | 68 // Handles the WndProc callback for this object. |
| 75 virtual LRESULT OnWndProc(UINT message, WPARAM w_param, LPARAM l_param); | 69 virtual LRESULT OnWndProc(UINT message, WPARAM w_param, LPARAM l_param); |
| 76 | 70 |
| 77 private: | 71 private: |
| 78 friend class ClassRegistrar; | 72 friend class ClassRegistrar; |
| 79 | 73 |
| 80 // The window procedure used by all Windows. | 74 // The windows procedure used by all Windows. |
| 81 static LRESULT CALLBACK WndProc(HWND window, | 75 static LRESULT CALLBACK WndProc(HWND window, |
| 82 UINT message, | 76 UINT message, |
| 83 WPARAM w_param, | 77 WPARAM w_param, |
| 84 LPARAM l_param); | 78 LPARAM l_param); |
| 85 | 79 |
| 86 // Gets the window class name to use when creating the corresponding HWND. | 80 // Gets the window class name to use when creating the corresponding HWND. |
| 87 // If necessary, this registers the window class. | 81 // If necessary, this registers the window class. |
| 88 std::wstring GetWindowClassName(); | 82 std::wstring GetWindowClassName(); |
| 89 | 83 |
| 90 // All classes registered by WidgetWin start with this name. | 84 // All classes registered by WidgetWin start with this name. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 101 | 95 |
| 102 // Our hwnd. | 96 // Our hwnd. |
| 103 HWND hwnd_; | 97 HWND hwnd_; |
| 104 | 98 |
| 105 DISALLOW_COPY_AND_ASSIGN(WindowImpl); | 99 DISALLOW_COPY_AND_ASSIGN(WindowImpl); |
| 106 }; | 100 }; |
| 107 | 101 |
| 108 } // namespace base | 102 } // namespace base |
| 109 | 103 |
| 110 #endif // BASE_WINDOW_IMPL_H_ | 104 #endif // BASE_WINDOW_IMPL_H_ |
| OLD | NEW |