| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef BASE_WINDOW_IMPL_H_ | |
| 6 #define BASE_WINDOW_IMPL_H_ | |
| 7 | |
| 8 #include <atlbase.h> | |
| 9 #include <atlapp.h> | |
| 10 #include <atlmisc.h> | |
| 11 #include <atlcrack.h> | |
| 12 | |
| 13 #include <string> | |
| 14 | |
| 15 #include "base/gfx/native_widget_types.h" | |
| 16 #include "base/gfx/rect.h" | |
| 17 #include "base/logging.h" | |
| 18 | |
| 19 namespace base { | |
| 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 /////////////////////////////////////////////////////////////////////////////// | |
| 35 // | |
| 36 // WindowImpl | |
| 37 // A convenience class that encapsulates the details of creating and | |
| 38 // destroying a HWND. This class also hosts the windows procedure used by all | |
| 39 // Windows. | |
| 40 // | |
| 41 /////////////////////////////////////////////////////////////////////////////// | |
| 42 class WindowImpl : public MessageMapInterface { | |
| 43 public: | |
| 44 WindowImpl(); | |
| 45 virtual ~WindowImpl(); | |
| 46 | |
| 47 // Initializes the Window with a parent and an initial desired size. | |
| 48 void Init(HWND parent, const gfx::Rect& bounds); | |
| 49 | |
| 50 // Retrieves the default window icon to use for windows if none is specified. | |
| 51 virtual HICON GetDefaultWindowIcon() const; | |
| 52 | |
| 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. | |
| 57 // In other words, if you invoke this after invoking Init, nothing happens. | |
| 58 void set_window_style(DWORD style) { window_style_ = style; } | |
| 59 DWORD window_style() const { return window_style_; } | |
| 60 | |
| 61 // Sets the extended window styles. See comment about |set_window_style|. | |
| 62 void set_window_ex_style(DWORD style) { window_ex_style_ = style; } | |
| 63 DWORD window_ex_style() const { return window_ex_style_; } | |
| 64 | |
| 65 // Sets the class style to use. The default is CS_DBLCLKS. | |
| 66 void set_initial_class_style(UINT class_style) { | |
| 67 // We dynamically generate the class name, so don't register it globally! | |
| 68 DCHECK_EQ((class_style & CS_GLOBALCLASS), 0); | |
| 69 class_style_ = class_style; | |
| 70 } | |
| 71 UINT initial_class_style() { return class_style_; } | |
| 72 | |
| 73 protected: | |
| 74 // Handles the WndProc callback for this object. | |
| 75 virtual LRESULT OnWndProc(UINT message, WPARAM w_param, LPARAM l_param); | |
| 76 | |
| 77 private: | |
| 78 friend class ClassRegistrar; | |
| 79 | |
| 80 // The window procedure used by all Windows. | |
| 81 static LRESULT CALLBACK WndProc(HWND window, | |
| 82 UINT message, | |
| 83 WPARAM w_param, | |
| 84 LPARAM l_param); | |
| 85 | |
| 86 // Gets the window class name to use when creating the corresponding HWND. | |
| 87 // If necessary, this registers the window class. | |
| 88 std::wstring GetWindowClassName(); | |
| 89 | |
| 90 // All classes registered by WidgetWin start with this name. | |
| 91 static const wchar_t* const kBaseClassName; | |
| 92 | |
| 93 // Window Styles used when creating the window. | |
| 94 DWORD window_style_; | |
| 95 | |
| 96 // Window Extended Styles used when creating the window. | |
| 97 DWORD window_ex_style_; | |
| 98 | |
| 99 // Style of the class to use. | |
| 100 UINT class_style_; | |
| 101 | |
| 102 // Our hwnd. | |
| 103 HWND hwnd_; | |
| 104 | |
| 105 DISALLOW_COPY_AND_ASSIGN(WindowImpl); | |
| 106 }; | |
| 107 | |
| 108 } // namespace base | |
| 109 | |
| 110 #endif // BASE_WINDOW_IMPL_H_ | |
| OLD | NEW |