Index: ui/views/widget/hwnd_subclass.cc |
=================================================================== |
--- ui/views/widget/hwnd_subclass.cc (revision 0) |
+++ ui/views/widget/hwnd_subclass.cc (revision 0) |
@@ -0,0 +1,81 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "ui/views/widget/hwnd_subclass.h" |
+ |
+#include "base/logging.h" |
+#include "ui/base/win/hwnd_util.h" |
+ |
+namespace { |
+const char* kHWNDSubclassKey = "__VIEWS_HWND_SUBCLASS_PROC__"; |
+ |
+LRESULT CALLBACK WndProc(HWND hwnd, |
+ UINT message, |
+ WPARAM w_param, |
+ LPARAM l_param) { |
+ views::HWNDSubclass* wrapped_wnd_proc = |
+ reinterpret_cast<views::HWNDSubclass*>( |
+ ui::ViewProp::GetValue(hwnd, kHWNDSubclassKey)); |
+ return wrapped_wnd_proc ? wrapped_wnd_proc->OnWndProc(hwnd, |
+ message, |
+ w_param, |
+ l_param) : 0; |
cpu_(ooo_6.6-7.5)
2012/04/27 20:20:25
why return 0 instead of CallWindowProc?
|
+} |
+ |
+} |
+ |
+namespace views { |
+ |
+HWNDSubclass::HWNDSubclass(gfx::AcceleratedWidget target) |
cpu_(ooo_6.6-7.5)
2012/04/27 20:20:25
so a gfx::AcceleatedWidget is a hwnd? in the h fil
|
+ : target_(target), |
+ original_wnd_proc_(GetClassWndProc(target)), |
cpu_(ooo_6.6-7.5)
2012/04/27 20:20:25
but the window could be already be subclassed...
|
+ ALLOW_THIS_IN_INITIALIZER_LIST(prop_(target, kHWNDSubclassKey, this)) { |
+ ui::SetWindowProc(target_, &WndProc); |
+} |
+ |
+HWNDSubclass::~HWNDSubclass() { |
+ // This is important, since otherwise we will try to access this object again |
+ // via a destroyed ViewProp. |
+ ui::SetWindowProc(target_, original_wnd_proc_); |
cpu_(ooo_6.6-7.5)
2012/04/27 20:20:25
I wont't bother unsubclassing, see my comment of l
|
+} |
+ |
+LRESULT HWNDSubclass::OnWndProc(HWND hwnd, |
+ UINT message, |
+ WPARAM w_param, |
+ LPARAM l_param) { |
+ LRESULT l_result = 0; |
+ bool consumed = FilterMessage(hwnd, message, w_param, l_param, &l_result); |
+ if (consumed) |
+ return l_result; |
+ |
+ // In most cases, |original_wnd_proc_| will take care of calling |
+ // DefWindowProc. |
+ return CallWindowProc(original_wnd_proc_, hwnd, message, w_param, l_param); |
+} |
+ |
+bool HWNDSubclass::FilterMessage(HWND hwnd, |
+ UINT message, |
+ WPARAM w_param, |
+ LPARAM l_param, |
+ LRESULT* l_result) { |
+ return false; |
+} |
+ |
+// static |
+WNDPROC HWNDSubclass::GetClassWndProc(HWND target) { |
+ wchar_t class_name[MAX_PATH]; |
+ ::GetClassName(target, class_name, MAX_PATH); |
+ |
+ WNDCLASSEX wndclassex = {0}; |
+ wndclassex.cbSize = sizeof(wndclassex); |
+ GetClassInfoEx(GetModuleHandle(NULL), class_name, &wndclassex); |
+ return wndclassex.lpfnWndProc; |
+} |
+ |
+// static |
+WNDPROC HWNDSubclass::GetCurrentWndProc(HWND target) { |
+ return reinterpret_cast<WNDPROC>(GetWindowLong(target, GWL_WNDPROC)); |
cpu_(ooo_6.6-7.5)
2012/04/27 20:20:25
are we using this function?
|
+} |
+ |
+} // namespace views |
Property changes on: ui\views\widget\hwnd_subclass.cc |
___________________________________________________________________ |
Added: svn:eol-style |
+ LF |