Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: ui/base/win/hwnd_subclass.cc

Issue 10256008: Adds a class that makes it easy to subclass a HWND and filter messages sent to it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/base/win/hwnd_subclass.h ('k') | ui/base/win/hwnd_subclass_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(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/base/win/hwnd_subclass.h"
6
7 #include "base/logging.h"
8 #include "ui/base/win/hwnd_util.h"
9
10 namespace {
11 const char kHWNDSubclassKey[] = "__UI_BASE_WIN_HWND_SUBCLASS_PROC__";
12
13 LRESULT CALLBACK WndProc(HWND hwnd,
14 UINT message,
15 WPARAM w_param,
16 LPARAM l_param) {
17 ui::HWNDSubclass* wrapped_wnd_proc =
18 reinterpret_cast<ui::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)
24 : DefWindowProc(hwnd, message, w_param, l_param);
25 }
26
27 WNDPROC GetCurrentWndProc(HWND target) {
28 return reinterpret_cast<WNDPROC>(GetWindowLong(target, GWL_WNDPROC));
29 }
30
31 } // namespace
32
33 namespace ui {
34
35 HWNDSubclass::HWNDSubclass(HWND target)
36 : target_(target),
37 original_wnd_proc_(GetCurrentWndProc(target)),
38 ALLOW_THIS_IN_INITIALIZER_LIST(prop_(target, kHWNDSubclassKey, this)) {
39 ui::SetWindowProc(target_, &WndProc);
40 }
41
42 HWNDSubclass::~HWNDSubclass() {
43 }
44
45 void HWNDSubclass::SetFilter(HWNDMessageFilter* filter) {
46 filter_.reset(filter);
47 }
48
49 LRESULT HWNDSubclass::OnWndProc(HWND hwnd,
50 UINT message,
51 WPARAM w_param,
52 LPARAM l_param) {
53 if (filter_.get()) {
54 LRESULT l_result = 0;
55 if (filter_->FilterMessage(hwnd, message, w_param, l_param, &l_result))
56 return l_result;
57 }
58
59 // In most cases, |original_wnd_proc_| will take care of calling
60 // DefWindowProc.
61 return CallWindowProc(original_wnd_proc_, hwnd, message, w_param, l_param);
62 }
63
64 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/win/hwnd_subclass.h ('k') | ui/base/win/hwnd_subclass_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698