summaryrefslogtreecommitdiffstats
path: root/views/controls
diff options
context:
space:
mode:
Diffstat (limited to 'views/controls')
-rw-r--r--views/controls/menu/native_menu_win.cc12
-rw-r--r--views/controls/native_control.cc45
-rw-r--r--views/controls/native_control.h3
-rw-r--r--views/controls/native_control_win.cc6
-rw-r--r--views/controls/native_control_win.h9
5 files changed, 46 insertions, 29 deletions
diff --git a/views/controls/menu/native_menu_win.cc b/views/controls/menu/native_menu_win.cc
index 6236913..9993d4e 100644
--- a/views/controls/menu/native_menu_win.cc
+++ b/views/controls/menu/native_menu_win.cc
@@ -9,6 +9,7 @@
#include "app/l10n_util_win.h"
#include "base/logging.h"
#include "base/stl_util-inl.h"
+#include "base/win_util.h"
#include "gfx/canvas_skia.h"
#include "gfx/font.h"
#include "third_party/skia/include/core/SkBitmap.h"
@@ -55,18 +56,16 @@ class NativeMenuWin::MenuHostWindow {
RegisterClass();
hwnd_ = CreateWindowEx(l10n_util::GetExtendedStyles(), kWindowClassName,
L"", 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL);
- SetProp(hwnd_, kMenuHostWindowKey, this);
+ win_util::SetWindowUserData(hwnd_, this);
}
~MenuHostWindow() {
- RemoveProp(hwnd_, kMenuHostWindowKey);
DestroyWindow(hwnd_);
}
HWND hwnd() const { return hwnd_; }
private:
- static const wchar_t* kMenuHostWindowKey;
static const wchar_t* kWindowClassName;
void RegisterClass() {
@@ -276,7 +275,8 @@ class NativeMenuWin::MenuHostWindow {
WPARAM w_param,
LPARAM l_param) {
MenuHostWindow* host =
- reinterpret_cast<MenuHostWindow*>(GetProp(window, kMenuHostWindowKey));
+ reinterpret_cast<MenuHostWindow*>(win_util::GetWindowUserData(window));
+ // host is null during initial construction.
LRESULT l_result = 0;
if (!host || !host->ProcessWindowMessage(window, message, w_param, l_param,
&l_result)) {
@@ -294,10 +294,6 @@ class NativeMenuWin::MenuHostWindow {
const wchar_t* NativeMenuWin::MenuHostWindow::kWindowClassName =
L"ViewsMenuHostWindow";
-const wchar_t* NativeMenuWin::MenuHostWindow::kMenuHostWindowKey =
- L"__MENU_HOST_WINDOW__";
-
-
////////////////////////////////////////////////////////////////////////////////
// NativeMenuWin, public:
diff --git a/views/controls/native_control.cc b/views/controls/native_control.cc
index a0ff1b0..ef719c9 100644
--- a/views/controls/native_control.cc
+++ b/views/controls/native_control.cc
@@ -13,7 +13,9 @@
#include "app/keyboard_code_conversion_win.h"
#include "app/keyboard_codes.h"
#include "app/l10n_util_win.h"
+#include "app/win/scoped_prop.h"
#include "base/logging.h"
+#include "base/scoped_ptr.h"
#include "base/win_util.h"
#include "gfx/native_theme_win.h"
#include "views/background.h"
@@ -24,11 +26,6 @@
namespace views {
-// Maps to the original WNDPROC for the controller window before we subclassed
-// it.
-static const wchar_t* const kHandlerKey =
- L"__CONTROL_ORIGINAL_MESSAGE_HANDLER__";
-
// Maps to the NativeControl.
static const wchar_t* const kNativeControlKey = L"__NATIVE_CONTROL__";
@@ -37,10 +34,14 @@ class NativeControlContainer : public CWindowImpl<NativeControlContainer,
CWinTraits<WS_CHILD | WS_CLIPSIBLINGS |
WS_CLIPCHILDREN>> {
public:
+ explicit NativeControlContainer(NativeControl* parent)
+ : parent_(parent),
+ control_(NULL),
+ original_handler_(NULL) {
+ }
- explicit NativeControlContainer(NativeControl* parent) : parent_(parent),
- control_(NULL) {
- Create(parent->GetWidget()->GetNativeView());
+ void Init() {
+ Create(parent_->GetWidget()->GetNativeView());
::ShowWindow(m_hWnd, SW_SHOW);
}
@@ -78,17 +79,18 @@ class NativeControlContainer : public CWindowImpl<NativeControlContainer,
parent_->NativeControlDestroyed();
delete this;
}
+
private:
+ friend class NativeControl;
LRESULT OnCreate(LPCREATESTRUCT create_struct) {
control_ = parent_->CreateNativeControl(m_hWnd);
// We subclass the control hwnd so we get the WM_KEYDOWN messages.
- WNDPROC original_handler =
- win_util::SetWindowProc(control_,
- &NativeControl::NativeControlWndProc);
- SetProp(control_, kHandlerKey, original_handler);
- SetProp(control_, kNativeControlKey , parent_);
+ original_handler_ = win_util::SetWindowProc(
+ control_, &NativeControl::NativeControlWndProc);
+ prop_.reset(
+ new app::win::ScopedProp(control_, kNativeControlKey , parent_));
::ShowWindow(control_, SW_SHOW);
return 1;
@@ -160,6 +162,12 @@ class NativeControlContainer : public CWindowImpl<NativeControlContainer,
NativeControl* parent_;
HWND control_;
+
+ // Message handler that was set before we reset it.
+ WNDPROC original_handler_;
+
+ scoped_ptr<app::win::ScopedProp> prop_;
+
DISALLOW_COPY_AND_ASSIGN(NativeControlContainer);
};
@@ -188,6 +196,7 @@ void NativeControl::ValidateNativeControl() {
if (!container_ && IsVisible()) {
container_ = new NativeControlContainer(this);
+ container_->Init();
hwnd_view_->Attach(*container_);
if (!enabled_)
EnableWindow(GetNativeControlHWND(), enabled_);
@@ -350,14 +359,15 @@ DWORD NativeControl::GetAdditionalRTLStyle() const {
}
// static
-LRESULT CALLBACK NativeControl::NativeControlWndProc(HWND window, UINT message,
+LRESULT CALLBACK NativeControl::NativeControlWndProc(HWND window,
+ UINT message,
WPARAM w_param,
LPARAM l_param) {
- HANDLE original_handler = GetProp(window, kHandlerKey);
- DCHECK(original_handler);
NativeControl* native_control =
static_cast<NativeControl*>(GetProp(window, kNativeControlKey));
DCHECK(native_control);
+ WNDPROC original_handler = native_control->container_->original_handler_;
+ DCHECK(original_handler);
if (message == WM_KEYDOWN &&
native_control->OnKeyDown(app::KeyboardCodeForWindowsKeyCode(w_param))) {
@@ -373,8 +383,7 @@ LRESULT CALLBACK NativeControl::NativeControlWndProc(HWND window, UINT message,
} else if (message == WM_DESTROY) {
win_util::SetWindowProc(window,
reinterpret_cast<WNDPROC>(original_handler));
- RemoveProp(window, kHandlerKey);
- RemoveProp(window, kNativeControlKey);
+ native_control->container_->prop_.reset();
}
return CallWindowProc(reinterpret_cast<WNDPROC>(original_handler), window,
diff --git a/views/controls/native_control.h b/views/controls/native_control.h
index 5a180d2..75a2a49 100644
--- a/views/controls/native_control.h
+++ b/views/controls/native_control.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 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.
@@ -42,6 +42,7 @@ class NativeControl : public View {
// Overridden to do nothing.
virtual void Paint(gfx::Canvas* canvas);
+
protected:
friend class NativeControlContainer;
diff --git a/views/controls/native_control_win.cc b/views/controls/native_control_win.cc
index ba27f85..0c6d257 100644
--- a/views/controls/native_control_win.cc
+++ b/views/controls/native_control_win.cc
@@ -7,6 +7,7 @@
#include <windowsx.h>
#include "app/l10n_util_win.h"
+#include "app/win/scoped_prop.h"
#include "base/logging.h"
#include "base/win_util.h"
#include "views/focus/focus_manager.h"
@@ -129,8 +130,8 @@ void NativeControlWin::ShowContextMenu(const gfx::Point& location) {
void NativeControlWin::NativeControlCreated(HWND native_control) {
// Associate this object with the control's HWND so that WidgetWin can find
// this object when it receives messages from it.
- // Note that we never unset this property. We don't have to.
- SetProp(native_control, kNativeControlWinKey, this);
+ prop_.reset(
+ new app::win::ScopedProp(native_control, kNativeControlWinKey, this));
// Subclass so we get WM_KEYDOWN and WM_SETFOCUS messages.
original_wndproc_ =
@@ -210,6 +211,7 @@ LRESULT NativeControlWin::NativeControlWndProc(HWND window,
NOTREACHED();
}
} else if (message == WM_DESTROY) {
+ native_control->prop_.reset();
win_util::SetWindowProc(window, native_control->original_wndproc_);
}
diff --git a/views/controls/native_control_win.h b/views/controls/native_control_win.h
index 1b0273b..6d0fdf0 100644
--- a/views/controls/native_control_win.h
+++ b/views/controls/native_control_win.h
@@ -6,9 +6,16 @@
#define VIEWS_CONTROLS_NATIVE_CONTROL_WIN_H_
#pragma once
+#include "base/scoped_ptr.h"
#include "views/controls/combobox/combobox.h"
#include "views/controls/native/native_view_host.h"
+namespace app {
+namespace win {
+class ScopedProp;
+}
+}
+
namespace views {
// A View that hosts a native Windows control.
@@ -86,6 +93,8 @@ class NativeControlWin : public NativeViewHost {
// The window procedure before we subclassed.
WNDPROC original_wndproc_;
+ scoped_ptr<app::win::ScopedProp> prop_;
+
DISALLOW_COPY_AND_ASSIGN(NativeControlWin);
};