| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. | 3 // LICENSE file. |
| 4 | 4 |
| 5 #include "views/controls/native_control_win.h" | 5 #include "views/controls/native_control_win.h" |
| 6 | 6 |
| 7 #include "app/l10n_util_win.h" | 7 #include "app/l10n_util_win.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/win_util.h" | 9 #include "base/win_util.h" |
| 10 #include "views/focus/focus_manager.h" | 10 #include "views/focus/focus_manager.h" |
| 11 | 11 |
| 12 namespace views { | 12 namespace views { |
| 13 | 13 |
| 14 // static | 14 // static |
| 15 const wchar_t* NativeControlWin::kNativeControlWinKey = | 15 const wchar_t* NativeControlWin::kNativeControlWinKey = |
| 16 L"__NATIVE_CONTROL_WIN__"; | 16 L"__NATIVE_CONTROL_WIN__"; |
| 17 | 17 |
| 18 static const wchar_t* kNativeControlOriginalWndProcKey = | |
| 19 L"__NATIVE_CONTROL_ORIGINAL_WNDPROC__"; | |
| 20 | |
| 21 // static | |
| 22 WNDPROC NativeControlWin::original_wndproc_ = NULL; | |
| 23 | |
| 24 //////////////////////////////////////////////////////////////////////////////// | 18 //////////////////////////////////////////////////////////////////////////////// |
| 25 // NativeControlWin, public: | 19 // NativeControlWin, public: |
| 26 | 20 |
| 27 NativeControlWin::NativeControlWin() { | 21 NativeControlWin::NativeControlWin() { |
| 28 } | 22 } |
| 29 | 23 |
| 30 NativeControlWin::~NativeControlWin() { | 24 NativeControlWin::~NativeControlWin() { |
| 31 HWND hwnd = native_view(); | 25 HWND hwnd = native_view(); |
| 32 if (hwnd) { | 26 if (hwnd) { |
| 33 // Destroy the hwnd if it still exists. Otherwise we won't have shut things | 27 // Destroy the hwnd if it still exists. Otherwise we won't have shut things |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 } | 105 } |
| 112 View::ShowContextMenu(x, y, is_mouse); | 106 View::ShowContextMenu(x, y, is_mouse); |
| 113 } | 107 } |
| 114 | 108 |
| 115 void NativeControlWin::NativeControlCreated(HWND native_control) { | 109 void NativeControlWin::NativeControlCreated(HWND native_control) { |
| 116 // Associate this object with the control's HWND so that WidgetWin can find | 110 // Associate this object with the control's HWND so that WidgetWin can find |
| 117 // this object when it receives messages from it. | 111 // this object when it receives messages from it. |
| 118 // Note that we never unset this property. We don't have to. | 112 // Note that we never unset this property. We don't have to. |
| 119 SetProp(native_control, kNativeControlWinKey, this); | 113 SetProp(native_control, kNativeControlWinKey, this); |
| 120 | 114 |
| 121 // Subclass the window so we can monitor for key presses. It's important that | 115 // Subclass so we get WM_KEYDOWN and WM_SETFOCUS messages. |
| 122 // we *only* do this if the derived class wants to intercept keypresses, | 116 original_wndproc_ = |
| 123 // because otherwise the subclass can mysteriously interfere with certain | 117 win_util::SetWindowProc(native_control, |
| 124 // other controls, like the combobox, and cause weird effects. | 118 &NativeControlWin::NativeControlWndProc); |
| 125 if (NotifyOnKeyDown()) { | |
| 126 original_wndproc_ = | |
| 127 win_util::SetWindowProc(native_control, | |
| 128 &NativeControlWin::NativeControlWndProc); | |
| 129 SetProp(native_control, kNativeControlOriginalWndProcKey, | |
| 130 original_wndproc_); | |
| 131 } | |
| 132 | 119 |
| 133 Attach(native_control); | 120 Attach(native_control); |
| 134 // native_view() is now valid. | 121 // native_view() is now valid. |
| 135 | 122 |
| 136 // Update the newly created HWND with any resident enabled state. | 123 // Update the newly created HWND with any resident enabled state. |
| 137 EnableWindow(native_view(), IsEnabled()); | 124 EnableWindow(native_view(), IsEnabled()); |
| 138 | 125 |
| 139 // This message ensures that the focus border is shown. | 126 // This message ensures that the focus border is shown. |
| 140 SendMessage(native_view(), WM_CHANGEUISTATE, | 127 SendMessage(native_view(), WM_CHANGEUISTATE, |
| 141 MAKEWPARAM(UIS_CLEAR, UISF_HIDEFOCUS), 0); | 128 MAKEWPARAM(UIS_CLEAR, UISF_HIDEFOCUS), 0); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 171 |
| 185 // static | 172 // static |
| 186 LRESULT NativeControlWin::NativeControlWndProc(HWND window, | 173 LRESULT NativeControlWin::NativeControlWndProc(HWND window, |
| 187 UINT message, | 174 UINT message, |
| 188 WPARAM w_param, | 175 WPARAM w_param, |
| 189 LPARAM l_param) { | 176 LPARAM l_param) { |
| 190 NativeControlWin* native_control = | 177 NativeControlWin* native_control = |
| 191 static_cast<NativeControlWin*>(GetProp(window, kNativeControlWinKey)); | 178 static_cast<NativeControlWin*>(GetProp(window, kNativeControlWinKey)); |
| 192 DCHECK(native_control); | 179 DCHECK(native_control); |
| 193 | 180 |
| 194 if (message == WM_KEYDOWN && native_control->NotifyOnKeyDown()) { | 181 if (message == WM_KEYDOWN && |
| 195 if (native_control->OnKeyDown(static_cast<int>(w_param))) | 182 native_control->OnKeyDown(static_cast<int>(w_param))) { |
| 196 return 0; | 183 return 0; |
| 197 } else if (message == WM_SETFOCUS) { | 184 } else if (message == WM_SETFOCUS) { |
| 198 // Let the focus manager know that the focus changed. | 185 // Let the focus manager know that the focus changed. |
| 199 FocusManager* focus_manager = | 186 FocusManager* focus_manager = |
| 200 FocusManager::GetFocusManager(native_control->native_view()); | 187 FocusManager::GetFocusManager(native_control->native_view()); |
| 201 if (focus_manager) { | 188 if (focus_manager) { |
| 202 focus_manager->SetFocusedView(native_control->focus_view()); | 189 focus_manager->SetFocusedView(native_control->focus_view()); |
| 203 } else { | 190 } else { |
| 204 NOTREACHED(); | 191 NOTREACHED(); |
| 205 } | 192 } |
| 206 } else if (message == WM_DESTROY) { | 193 } else if (message == WM_DESTROY) { |
| 207 win_util::SetWindowProc(window, native_control->original_wndproc_); | 194 win_util::SetWindowProc(window, native_control->original_wndproc_); |
| 208 } | 195 } |
| 209 | 196 |
| 210 return CallWindowProc(native_control->original_wndproc_, window, message, | 197 return CallWindowProc(native_control->original_wndproc_, window, message, |
| 211 w_param, l_param); | 198 w_param, l_param); |
| 212 } | 199 } |
| 213 | 200 |
| 214 } // namespace views | 201 } // namespace views |
| OLD | NEW |