OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/views/native_control.h" | 5 #include "chrome/views/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> |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 } | 72 } |
73 | 73 |
74 void OnFinalMessage(HWND hwnd) { | 74 void OnFinalMessage(HWND hwnd) { |
75 if (parent_) | 75 if (parent_) |
76 parent_->NativeControlDestroyed(); | 76 parent_->NativeControlDestroyed(); |
77 delete this; | 77 delete this; |
78 } | 78 } |
79 private: | 79 private: |
80 | 80 |
81 LRESULT OnCreate(LPCREATESTRUCT create_struct) { | 81 LRESULT OnCreate(LPCREATESTRUCT create_struct) { |
82 TRACK_HWND_CREATION(m_hWnd); | |
83 | |
84 control_ = parent_->CreateNativeControl(m_hWnd); | 82 control_ = parent_->CreateNativeControl(m_hWnd); |
85 TRACK_HWND_CREATION(control_); | |
86 | |
87 FocusManager::InstallFocusSubclass(control_, parent_); | 83 FocusManager::InstallFocusSubclass(control_, parent_); |
88 | 84 if (parent_->NotifyOnKeyDown()) { |
89 // We subclass the control hwnd so we get the WM_KEYDOWN messages. | 85 // We subclass the control hwnd so we get the WM_KEYDOWN messages. |
90 WNDPROC original_handler = | 86 WNDPROC original_handler = |
91 win_util::SetWindowProc(control_, | 87 win_util::SetWindowProc(control_, |
92 &NativeControl::NativeControlWndProc); | 88 &NativeControl::NativeControlWndProc); |
93 SetProp(control_, kHandlerKey, original_handler); | 89 SetProp(control_, kHandlerKey, original_handler); |
94 SetProp(control_, kNativeControlKey , parent_); | 90 SetProp(control_, kNativeControlKey , parent_); |
95 | 91 } |
96 ::ShowWindow(control_, SW_SHOW); | 92 ::ShowWindow(control_, SW_SHOW); |
97 return 1; | 93 return 1; |
98 } | 94 } |
99 | 95 |
100 LRESULT OnEraseBkgnd(HDC dc) { | 96 LRESULT OnEraseBkgnd(HDC dc) { |
101 return 1; | 97 return 1; |
102 } | 98 } |
103 | 99 |
104 void OnPaint(HDC ignore) { | 100 void OnPaint(HDC ignore) { |
105 PAINTSTRUCT ps; | 101 PAINTSTRUCT ps; |
(...skipping 12 matching lines...) Expand all Loading... |
118 LRESULT OnNotify(int w_param, LPNMHDR l_param) { | 114 LRESULT OnNotify(int w_param, LPNMHDR l_param) { |
119 if (parent_) | 115 if (parent_) |
120 return parent_->OnNotify(w_param, l_param); | 116 return parent_->OnNotify(w_param, l_param); |
121 else | 117 else |
122 return 0; | 118 return 0; |
123 } | 119 } |
124 | 120 |
125 void OnDestroy() { | 121 void OnDestroy() { |
126 if (parent_) | 122 if (parent_) |
127 parent_->OnDestroy(); | 123 parent_->OnDestroy(); |
128 TRACK_HWND_DESTRUCTION(m_hWnd); | |
129 } | 124 } |
130 | 125 |
131 void OnContextMenu(HWND window, const CPoint& location) { | 126 void OnContextMenu(HWND window, const CPoint& location) { |
132 if (parent_) | 127 if (parent_) |
133 parent_->OnContextMenu(location); | 128 parent_->OnContextMenu(location); |
134 } | 129 } |
135 | 130 |
136 // We need to find an ancestor with a non-null background, and | 131 // We need to find an ancestor with a non-null background, and |
137 // ask it for a (solid color) brush that approximates | 132 // ask it for a (solid color) brush that approximates |
138 // the background. The caller will use this when drawing | 133 // the background. The caller will use this when drawing |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 // static | 356 // static |
362 LRESULT CALLBACK NativeControl::NativeControlWndProc(HWND window, UINT message, | 357 LRESULT CALLBACK NativeControl::NativeControlWndProc(HWND window, UINT message, |
363 WPARAM w_param, | 358 WPARAM w_param, |
364 LPARAM l_param) { | 359 LPARAM l_param) { |
365 HANDLE original_handler = GetProp(window, kHandlerKey); | 360 HANDLE original_handler = GetProp(window, kHandlerKey); |
366 DCHECK(original_handler); | 361 DCHECK(original_handler); |
367 NativeControl* native_control = | 362 NativeControl* native_control = |
368 static_cast<NativeControl*>(GetProp(window, kNativeControlKey)); | 363 static_cast<NativeControl*>(GetProp(window, kNativeControlKey)); |
369 DCHECK(native_control); | 364 DCHECK(native_control); |
370 | 365 |
371 if (message == WM_KEYDOWN && native_control->NotifyOnKeyDown()) { | 366 if (message == WM_KEYDOWN) { |
372 if (native_control->OnKeyDown(static_cast<int>(w_param))) | 367 if (native_control->OnKeyDown(static_cast<int>(w_param))) |
373 return 0; | 368 return 0; |
374 } else if (message == WM_DESTROY) { | 369 } else if (message == WM_DESTROY) { |
375 win_util::SetWindowProc(window, | 370 win_util::SetWindowProc(window, |
376 reinterpret_cast<WNDPROC>(original_handler)); | 371 reinterpret_cast<WNDPROC>(original_handler)); |
377 RemoveProp(window, kHandlerKey); | 372 RemoveProp(window, kHandlerKey); |
378 RemoveProp(window, kNativeControlKey); | 373 RemoveProp(window, kNativeControlKey); |
379 TRACK_HWND_DESTRUCTION(window); | |
380 } | 374 } |
381 | 375 |
382 return CallWindowProc(reinterpret_cast<WNDPROC>(original_handler), window, | 376 return CallWindowProc(reinterpret_cast<WNDPROC>(original_handler), window, |
383 message, w_param, l_param); | 377 message, w_param, l_param); |
384 } | 378 } |
385 | 379 |
386 } // namespace views | 380 } // namespace views |
387 | 381 |
OLD | NEW |