1 // Copyright (c) 2012 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.
5 #ifndef UI_GFX_WIN_WINDOW_IMPL_H_
6 #define UI_GFX_WIN_WINDOW_IMPL_H_
15 #include "base/logging.h"
16 #include "ui/gfx/gfx_export.h"
17 #include "ui/gfx/native_widget_types.h"
18 #include "ui/gfx/rect.h"
22 // An interface implemented by classes that use message maps.
23 // ProcessWindowMessage is implemented by the BEGIN_MESSAGE_MAP_EX macro.
24 class MessageMapInterface {
26 // Processes one message from the window's message queue.
27 virtual BOOL ProcessWindowMessage(HWND window,
32 DWORD msg_map_id = 0) = 0;
35 ///////////////////////////////////////////////////////////////////////////////
38 // A convenience class that encapsulates the details of creating and
39 // destroying a HWND. This class also hosts the windows procedure used by all
42 ///////////////////////////////////////////////////////////////////////////////
43 class GFX_EXPORT WindowImpl : public MessageMapInterface {
46 virtual ~WindowImpl();
48 // Initializes the Window with a parent and an initial desired size.
49 void Init(HWND parent, const gfx::Rect& bounds);
51 // Returns the default window icon to use for windows of this type.
52 virtual HICON GetDefaultWindowIcon() const;
54 // Returns the HWND associated with this Window.
55 HWND hwnd() const { return hwnd_; }
57 // Sets the window styles. This is ONLY used when the window is created.
58 // In other words, if you invoke this after invoking Init, nothing happens.
59 void set_window_style(DWORD style) { window_style_ = style; }
60 DWORD window_style() const { return window_style_; }
62 // Sets the extended window styles. See comment about |set_window_style|.
63 void set_window_ex_style(DWORD style) { window_ex_style_ = style; }
64 DWORD window_ex_style() const { return window_ex_style_; }
66 // Sets the class style to use. The default is CS_DBLCLKS.
67 void set_initial_class_style(UINT class_style) {
68 // We dynamically generate the class name, so don't register it globally!
69 DCHECK_EQ((class_style & CS_GLOBALCLASS), 0u);
70 class_style_ = class_style;
72 UINT initial_class_style() const { return class_style_; }
75 // Handles the WndProc callback for this object.
76 virtual LRESULT OnWndProc(UINT message, WPARAM w_param, LPARAM l_param);
78 // Subclasses must call this method from their destructors to ensure that
79 // this object is properly disassociated from the HWND during destruction,
80 // otherwise it's possible this object may still exist while a subclass is
85 friend class ClassRegistrar;
87 // The window procedure used by all Windows.
88 static LRESULT CALLBACK WndProc(HWND window,
93 // Gets the window class atom to use when creating the corresponding HWND.
94 // If necessary, this registers the window class.
95 ATOM GetWindowClassAtom();
97 // All classes registered by WindowImpl start with this name.
98 static const wchar_t* const kBaseClassName;
100 // Window Styles used when creating the window.
103 // Window Extended Styles used when creating the window.
104 DWORD window_ex_style_;
106 // Style of the class to use.
113 // TODO(sky): nuke this when get crash data.
115 bool got_valid_hwnd_;
118 DISALLOW_COPY_AND_ASSIGN(WindowImpl);
123 #endif // UI_GFX_WIN_WINDOW_IMPL_H_