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.h" | 5 #include "views/controls/native_control.h" |
6 | 6 |
7 #include <atlbase.h> | 7 #include <atlbase.h> |
8 #include <atlapp.h> | 8 #include <atlapp.h> |
9 #include <atlcrack.h> | 9 #include <atlcrack.h> |
10 #include <atlframe.h> | 10 #include <atlframe.h> |
11 #include <atlmisc.h> | 11 #include <atlmisc.h> |
12 | 12 |
13 #include "app/keyboard_code_conversion_win.h" | 13 #include "app/keyboard_code_conversion_win.h" |
14 #include "app/keyboard_codes.h" | 14 #include "app/keyboard_codes.h" |
15 #include "app/l10n_util_win.h" | 15 #include "app/l10n_util_win.h" |
16 #include "app/view_prop.h" | 16 #include "app/win/scoped_prop.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/scoped_ptr.h" | 18 #include "base/scoped_ptr.h" |
19 #include "base/win_util.h" | 19 #include "base/win_util.h" |
20 #include "gfx/native_theme_win.h" | 20 #include "gfx/native_theme_win.h" |
21 #include "views/background.h" | 21 #include "views/background.h" |
22 #include "views/border.h" | 22 #include "views/border.h" |
23 #include "views/controls/native/native_view_host.h" | 23 #include "views/controls/native/native_view_host.h" |
24 #include "views/focus/focus_manager.h" | 24 #include "views/focus/focus_manager.h" |
25 #include "views/widget/widget.h" | 25 #include "views/widget/widget.h" |
26 | 26 |
27 using app::ViewProp; | |
28 | |
29 namespace views { | 27 namespace views { |
30 | 28 |
31 // Maps to the NativeControl. | 29 // Maps to the NativeControl. |
32 static const char* const kNativeControlKey = "__NATIVE_CONTROL__"; | 30 static const wchar_t* const kNativeControlKey = L"__NATIVE_CONTROL__"; |
33 | 31 |
34 class NativeControlContainer : public CWindowImpl<NativeControlContainer, | 32 class NativeControlContainer : public CWindowImpl<NativeControlContainer, |
35 CWindow, | 33 CWindow, |
36 CWinTraits<WS_CHILD | WS_CLIPSIBLINGS | | 34 CWinTraits<WS_CHILD | WS_CLIPSIBLINGS | |
37 WS_CLIPCHILDREN>> { | 35 WS_CLIPCHILDREN>> { |
38 public: | 36 public: |
39 explicit NativeControlContainer(NativeControl* parent) | 37 explicit NativeControlContainer(NativeControl* parent) |
40 : parent_(parent), | 38 : parent_(parent), |
41 control_(NULL), | 39 control_(NULL), |
42 original_handler_(NULL) { | 40 original_handler_(NULL) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 | 82 |
85 private: | 83 private: |
86 friend class NativeControl; | 84 friend class NativeControl; |
87 | 85 |
88 LRESULT OnCreate(LPCREATESTRUCT create_struct) { | 86 LRESULT OnCreate(LPCREATESTRUCT create_struct) { |
89 control_ = parent_->CreateNativeControl(m_hWnd); | 87 control_ = parent_->CreateNativeControl(m_hWnd); |
90 | 88 |
91 // We subclass the control hwnd so we get the WM_KEYDOWN messages. | 89 // We subclass the control hwnd so we get the WM_KEYDOWN messages. |
92 original_handler_ = win_util::SetWindowProc( | 90 original_handler_ = win_util::SetWindowProc( |
93 control_, &NativeControl::NativeControlWndProc); | 91 control_, &NativeControl::NativeControlWndProc); |
94 prop_.reset(new ViewProp(control_, kNativeControlKey , parent_)); | 92 prop_.reset( |
| 93 new app::win::ScopedProp(control_, kNativeControlKey , parent_)); |
95 | 94 |
96 ::ShowWindow(control_, SW_SHOW); | 95 ::ShowWindow(control_, SW_SHOW); |
97 return 1; | 96 return 1; |
98 } | 97 } |
99 | 98 |
100 LRESULT OnEraseBkgnd(HDC dc) { | 99 LRESULT OnEraseBkgnd(HDC dc) { |
101 return 1; | 100 return 1; |
102 } | 101 } |
103 | 102 |
104 void OnPaint(HDC ignore) { | 103 void OnPaint(HDC ignore) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 LRESULT OnCtlColorStatic(HDC dc, HWND control) { | 159 LRESULT OnCtlColorStatic(HDC dc, HWND control) { |
161 return OnCtlColor(WM_CTLCOLORSTATIC, dc, control); | 160 return OnCtlColor(WM_CTLCOLORSTATIC, dc, control); |
162 } | 161 } |
163 | 162 |
164 NativeControl* parent_; | 163 NativeControl* parent_; |
165 HWND control_; | 164 HWND control_; |
166 | 165 |
167 // Message handler that was set before we reset it. | 166 // Message handler that was set before we reset it. |
168 WNDPROC original_handler_; | 167 WNDPROC original_handler_; |
169 | 168 |
170 scoped_ptr<ViewProp> prop_; | 169 scoped_ptr<app::win::ScopedProp> prop_; |
171 | 170 |
172 DISALLOW_COPY_AND_ASSIGN(NativeControlContainer); | 171 DISALLOW_COPY_AND_ASSIGN(NativeControlContainer); |
173 }; | 172 }; |
174 | 173 |
175 NativeControl::NativeControl() : hwnd_view_(NULL), | 174 NativeControl::NativeControl() : hwnd_view_(NULL), |
176 container_(NULL), | 175 container_(NULL), |
177 fixed_width_(-1), | 176 fixed_width_(-1), |
178 horizontal_alignment_(CENTER), | 177 horizontal_alignment_(CENTER), |
179 fixed_height_(-1), | 178 fixed_height_(-1), |
180 vertical_alignment_(CENTER) { | 179 vertical_alignment_(CENTER) { |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 ex_style |= l10n_util::GetExtendedTooltipStyles(); | 356 ex_style |= l10n_util::GetExtendedTooltipStyles(); |
358 | 357 |
359 return ex_style; | 358 return ex_style; |
360 } | 359 } |
361 | 360 |
362 // static | 361 // static |
363 LRESULT CALLBACK NativeControl::NativeControlWndProc(HWND window, | 362 LRESULT CALLBACK NativeControl::NativeControlWndProc(HWND window, |
364 UINT message, | 363 UINT message, |
365 WPARAM w_param, | 364 WPARAM w_param, |
366 LPARAM l_param) { | 365 LPARAM l_param) { |
367 NativeControl* native_control = static_cast<NativeControl*>( | 366 NativeControl* native_control = |
368 ViewProp::GetValue(window, kNativeControlKey)); | 367 static_cast<NativeControl*>(GetProp(window, kNativeControlKey)); |
369 DCHECK(native_control); | 368 DCHECK(native_control); |
370 WNDPROC original_handler = native_control->container_->original_handler_; | 369 WNDPROC original_handler = native_control->container_->original_handler_; |
371 DCHECK(original_handler); | 370 DCHECK(original_handler); |
372 | 371 |
373 if (message == WM_KEYDOWN && | 372 if (message == WM_KEYDOWN && |
374 native_control->OnKeyDown(app::KeyboardCodeForWindowsKeyCode(w_param))) { | 373 native_control->OnKeyDown(app::KeyboardCodeForWindowsKeyCode(w_param))) { |
375 return 0; | 374 return 0; |
376 } else if (message == WM_SETFOCUS) { | 375 } else if (message == WM_SETFOCUS) { |
377 // Let the focus manager know that the focus changed. | 376 // Let the focus manager know that the focus changed. |
378 FocusManager* focus_manager = native_control->GetFocusManager(); | 377 FocusManager* focus_manager = native_control->GetFocusManager(); |
379 if (focus_manager) { | 378 if (focus_manager) { |
380 focus_manager->SetFocusedView(native_control); | 379 focus_manager->SetFocusedView(native_control); |
381 } else { | 380 } else { |
382 NOTREACHED(); | 381 NOTREACHED(); |
383 } | 382 } |
384 } else if (message == WM_DESTROY) { | 383 } else if (message == WM_DESTROY) { |
385 win_util::SetWindowProc(window, | 384 win_util::SetWindowProc(window, |
386 reinterpret_cast<WNDPROC>(original_handler)); | 385 reinterpret_cast<WNDPROC>(original_handler)); |
387 native_control->container_->prop_.reset(); | 386 native_control->container_->prop_.reset(); |
388 } | 387 } |
389 | 388 |
390 return CallWindowProc(reinterpret_cast<WNDPROC>(original_handler), window, | 389 return CallWindowProc(reinterpret_cast<WNDPROC>(original_handler), window, |
391 message, w_param, l_param); | 390 message, w_param, l_param); |
392 } | 391 } |
393 | 392 |
394 } // namespace views | 393 } // namespace views |
OLD | NEW |