OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "views/controls/native_control_win.h" | 5 #include "views/controls/native_control_win.h" |
6 | 6 |
7 #include <windowsx.h> | 7 #include <windowsx.h> |
8 | 8 |
9 #include "app/l10n_util_win.h" | 9 #include "app/l10n_util_win.h" |
10 #include "app/view_prop.h" | 10 #include "app/win/scoped_prop.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/win_util.h" | 12 #include "base/win_util.h" |
13 #include "views/focus/focus_manager.h" | 13 #include "views/focus/focus_manager.h" |
14 | 14 |
15 using app::ViewProp; | |
16 | |
17 namespace views { | 15 namespace views { |
18 | 16 |
19 static const char* const kNativeControlWinKey = "__NATIVE_CONTROL_WIN__"; | 17 static const wchar_t* kNativeControlWinKey = L"__NATIVE_CONTROL_WIN__"; |
20 | 18 |
21 //////////////////////////////////////////////////////////////////////////////// | 19 //////////////////////////////////////////////////////////////////////////////// |
22 // NativeControlWin, public: | 20 // NativeControlWin, public: |
23 | 21 |
24 NativeControlWin::NativeControlWin() { | 22 NativeControlWin::NativeControlWin() { |
25 } | 23 } |
26 | 24 |
27 NativeControlWin::~NativeControlWin() { | 25 NativeControlWin::~NativeControlWin() { |
28 HWND hwnd = native_view(); | 26 HWND hwnd = native_view(); |
29 if (hwnd) { | 27 if (hwnd) { |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 | 123 |
126 if (location.x() == -1 && location.y() == -1) | 124 if (location.x() == -1 && location.y() == -1) |
127 View::ShowContextMenu(GetKeyboardContextMenuLocation(), false); | 125 View::ShowContextMenu(GetKeyboardContextMenuLocation(), false); |
128 else | 126 else |
129 View::ShowContextMenu(location, true); | 127 View::ShowContextMenu(location, true); |
130 } | 128 } |
131 | 129 |
132 void NativeControlWin::NativeControlCreated(HWND native_control) { | 130 void NativeControlWin::NativeControlCreated(HWND native_control) { |
133 // Associate this object with the control's HWND so that WidgetWin can find | 131 // Associate this object with the control's HWND so that WidgetWin can find |
134 // this object when it receives messages from it. | 132 // this object when it receives messages from it. |
135 props_.push_back(new ViewProp(native_control, kNativeControlWinKey, this)); | 133 props_.push_back( |
| 134 new app::win::ScopedProp(native_control, kNativeControlWinKey, this)); |
136 props_.push_back(ChildWindowMessageProcessor::Register(native_control, this)); | 135 props_.push_back(ChildWindowMessageProcessor::Register(native_control, this)); |
137 | 136 |
138 // Subclass so we get WM_KEYDOWN and WM_SETFOCUS messages. | 137 // Subclass so we get WM_KEYDOWN and WM_SETFOCUS messages. |
139 original_wndproc_ = | 138 original_wndproc_ = |
140 win_util::SetWindowProc(native_control, | 139 win_util::SetWindowProc(native_control, |
141 &NativeControlWin::NativeControlWndProc); | 140 &NativeControlWin::NativeControlWndProc); |
142 | 141 |
143 Attach(native_control); | 142 Attach(native_control); |
144 // native_view() is now valid. | 143 // native_view() is now valid. |
145 | 144 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 | 189 |
191 // COLOR_BTNFACE is the default for dialog box backgrounds. | 190 // COLOR_BTNFACE is the default for dialog box backgrounds. |
192 return reinterpret_cast<LRESULT>(GetSysColorBrush(COLOR_BTNFACE)); | 191 return reinterpret_cast<LRESULT>(GetSysColorBrush(COLOR_BTNFACE)); |
193 } | 192 } |
194 | 193 |
195 // static | 194 // static |
196 LRESULT NativeControlWin::NativeControlWndProc(HWND window, | 195 LRESULT NativeControlWin::NativeControlWndProc(HWND window, |
197 UINT message, | 196 UINT message, |
198 WPARAM w_param, | 197 WPARAM w_param, |
199 LPARAM l_param) { | 198 LPARAM l_param) { |
200 NativeControlWin* native_control = reinterpret_cast<NativeControlWin*>( | 199 NativeControlWin* native_control = |
201 ViewProp::GetValue(window, kNativeControlWinKey)); | 200 static_cast<NativeControlWin*>(GetProp(window, kNativeControlWinKey)); |
202 DCHECK(native_control); | 201 DCHECK(native_control); |
203 | 202 |
204 if (message == WM_KEYDOWN && | 203 if (message == WM_KEYDOWN && |
205 native_control->OnKeyDown(static_cast<int>(w_param))) { | 204 native_control->OnKeyDown(static_cast<int>(w_param))) { |
206 return 0; | 205 return 0; |
207 } else if (message == WM_SETFOCUS) { | 206 } else if (message == WM_SETFOCUS) { |
208 // Let the focus manager know that the focus changed. | 207 // Let the focus manager know that the focus changed. |
209 FocusManager* focus_manager = native_control->GetFocusManager(); | 208 FocusManager* focus_manager = native_control->GetFocusManager(); |
210 if (focus_manager) { | 209 if (focus_manager) { |
211 focus_manager->SetFocusedView(native_control->focus_view()); | 210 focus_manager->SetFocusedView(native_control->focus_view()); |
212 } else { | 211 } else { |
213 NOTREACHED(); | 212 NOTREACHED(); |
214 } | 213 } |
215 } else if (message == WM_DESTROY) { | 214 } else if (message == WM_DESTROY) { |
216 native_control->props_.reset(); | 215 native_control->props_.reset(); |
217 win_util::SetWindowProc(window, native_control->original_wndproc_); | 216 win_util::SetWindowProc(window, native_control->original_wndproc_); |
218 } | 217 } |
219 | 218 |
220 return CallWindowProc(native_control->original_wndproc_, window, message, | 219 return CallWindowProc(native_control->original_wndproc_, window, message, |
221 w_param, l_param); | 220 w_param, l_param); |
222 } | 221 } |
223 | 222 |
224 } // namespace views | 223 } // namespace views |
OLD | NEW |