|
OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #include "ui/views/widget/hwnd_subclass.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "ui/base/win/hwnd_util.h" | |
9 | |
10 namespace { | |
11 const char* kHWNDSubclassKey = "__VIEWS_HWND_SUBCLASS_PROC__"; | |
12 | |
13 LRESULT CALLBACK WndProc(HWND hwnd, | |
14 UINT message, | |
15 WPARAM w_param, | |
16 LPARAM l_param) { | |
17 views::HWNDSubclass* wrapped_wnd_proc = | |
18 reinterpret_cast<views::HWNDSubclass*>( | |
19 ui::ViewProp::GetValue(hwnd, kHWNDSubclassKey)); | |
20 return wrapped_wnd_proc ? wrapped_wnd_proc->OnWndProc(hwnd, | |
21 message, | |
22 w_param, | |
23 l_param) : 0; | |
cpu_(ooo_6.6-7.5)
2012/04/27 20:20:25
why return 0 instead of CallWindowProc?
| |
24 } | |
25 | |
26 } | |
27 | |
28 namespace views { | |
29 | |
30 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
| |
31 : target_(target), | |
32 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...
| |
33 ALLOW_THIS_IN_INITIALIZER_LIST(prop_(target, kHWNDSubclassKey, this)) { | |
34 ui::SetWindowProc(target_, &WndProc); | |
35 } | |
36 | |
37 HWNDSubclass::~HWNDSubclass() { | |
38 // This is important, since otherwise we will try to access this object again | |
39 // via a destroyed ViewProp. | |
40 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
| |
41 } | |
42 | |
43 LRESULT HWNDSubclass::OnWndProc(HWND hwnd, | |
44 UINT message, | |
45 WPARAM w_param, | |
46 LPARAM l_param) { | |
47 LRESULT l_result = 0; | |
48 bool consumed = FilterMessage(hwnd, message, w_param, l_param, &l_result); | |
49 if (consumed) | |
50 return l_result; | |
51 | |
52 // In most cases, |original_wnd_proc_| will take care of calling | |
53 // DefWindowProc. | |
54 return CallWindowProc(original_wnd_proc_, hwnd, message, w_param, l_param); | |
55 } | |
56 | |
57 bool HWNDSubclass::FilterMessage(HWND hwnd, | |
58 UINT message, | |
59 WPARAM w_param, | |
60 LPARAM l_param, | |
61 LRESULT* l_result) { | |
62 return false; | |
63 } | |
64 | |
65 // static | |
66 WNDPROC HWNDSubclass::GetClassWndProc(HWND target) { | |
67 wchar_t class_name[MAX_PATH]; | |
68 ::GetClassName(target, class_name, MAX_PATH); | |
69 | |
70 WNDCLASSEX wndclassex = {0}; | |
71 wndclassex.cbSize = sizeof(wndclassex); | |
72 GetClassInfoEx(GetModuleHandle(NULL), class_name, &wndclassex); | |
73 return wndclassex.lpfnWndProc; | |
74 } | |
75 | |
76 // static | |
77 WNDPROC HWNDSubclass::GetCurrentWndProc(HWND target) { | |
78 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?
| |
79 } | |
80 | |
81 } // namespace views | |
OLD | NEW |