summaryrefslogtreecommitdiffstats
path: root/views/widget/widget_win.cc
diff options
context:
space:
mode:
Diffstat (limited to 'views/widget/widget_win.cc')
-rw-r--r--views/widget/widget_win.cc101
1 files changed, 69 insertions, 32 deletions
diff --git a/views/widget/widget_win.cc b/views/widget/widget_win.cc
index a3dc3ce..1853d5e 100644
--- a/views/widget/widget_win.cc
+++ b/views/widget/widget_win.cc
@@ -25,6 +25,7 @@ namespace views {
// Property used to link the HWND to its RootView.
static const wchar_t* const kRootViewWindowProperty = L"__ROOT_VIEW__";
+static const wchar_t* kWidgetKey = L"__VIEWS_WIDGET__";
bool SetRootViewForHWND(HWND hwnd, RootView* root_view) {
return SetProp(hwnd, kRootViewWindowProperty, root_view) ? true : false;
@@ -60,6 +61,25 @@ WidgetWin::~WidgetWin() {
MessageLoopForUI::current()->RemoveObserver(this);
}
+// static
+WidgetWin* WidgetWin::GetWidget(HWND hwnd) {
+ return reinterpret_cast<WidgetWin*>(win_util::GetWindowUserData(hwnd));
+}
+
+void WidgetWin::SetUseLayeredBuffer(bool use_layered_buffer) {
+ if (use_layered_buffer_ == use_layered_buffer)
+ return;
+
+ use_layered_buffer_ = use_layered_buffer;
+ if (!hwnd())
+ return;
+
+ if (use_layered_buffer_)
+ LayoutRootView();
+ else
+ contents_.reset(NULL);
+}
+
///////////////////////////////////////////////////////////////////////////////
// Widget implementation:
@@ -287,6 +307,10 @@ bool WidgetWin::IsActive() const {
return win_util::IsWindowActive(hwnd());
}
+TooltipManager* WidgetWin::GetTooltipManager() {
+ return tooltip_manager_.get();
+}
+
void WidgetWin::GenerateMousePressedForView(View* view,
const gfx::Point& point) {
gfx::Point point_in_widget(point);
@@ -295,8 +319,28 @@ void WidgetWin::GenerateMousePressedForView(View* view,
ProcessMousePressed(point_in_widget.ToPOINT(), MK_LBUTTON, false, false);
}
-TooltipManager* WidgetWin::GetTooltipManager() {
- return tooltip_manager_.get();
+bool WidgetWin::GetAccelerator(int cmd_id, Accelerator* accelerator) {
+ return false;
+}
+
+Window* WidgetWin::GetWindow() {
+ return GetWindowImpl(hwnd());
+}
+
+const Window* WidgetWin::GetWindow() const {
+ return GetWindowImpl(hwnd());
+}
+
+void WidgetWin::SetNativeWindowProperty(const std::wstring& name,
+ void* value) {
+ if (value)
+ SetProp(hwnd(), name.c_str(), value);
+ else
+ RemoveProp(hwnd(), name.c_str());
+}
+
+void* WidgetWin::GetNativeWindowProperty(const std::wstring& name) {
+ return GetProp(hwnd(), name.c_str());
}
ThemeProvider* WidgetWin::GetThemeProvider() const {
@@ -315,13 +359,10 @@ ThemeProvider* WidgetWin::GetThemeProvider() const {
return default_theme_provider_.get();
}
-Window* WidgetWin::GetWindow() {
- return GetWindowImpl(hwnd());
+ThemeProvider* WidgetWin::GetDefaultThemeProvider() const {
+ return default_theme_provider_.get();
}
-const Window* WidgetWin::GetWindow() const {
- return GetWindowImpl(hwnd());
-}
FocusManager* WidgetWin::GetFocusManager() {
if (focus_manager_.get())
@@ -342,31 +383,6 @@ void WidgetWin::ViewHierarchyChanged(bool is_add, View *parent,
drop_target_->ResetTargetViewIfEquals(child);
}
-bool WidgetWin::GetAccelerator(int cmd_id, Accelerator* accelerator) {
- return false;
-}
-
-void WidgetWin::SetUseLayeredBuffer(bool use_layered_buffer) {
- if (use_layered_buffer_ == use_layered_buffer)
- return;
-
- use_layered_buffer_ = use_layered_buffer;
- if (!hwnd())
- return;
-
- if (use_layered_buffer_) {
- // Force creation of the buffer at the right size.
- LayoutRootView();
- } else {
- contents_.reset(NULL);
- }
-}
-
-// static
-WidgetWin* WidgetWin::GetWidget(HWND hwnd) {
- return reinterpret_cast<WidgetWin*>(win_util::GetWindowUserData(hwnd));
-}
-
////////////////////////////////////////////////////////////////////////////////
// MessageLoop::Observer
@@ -454,10 +470,13 @@ void WidgetWin::OnCommand(UINT notification_code, int command_id, HWND window) {
}
LRESULT WidgetWin::OnCreate(CREATESTRUCT* create_struct) {
+ SetNativeWindowProperty(kWidgetKey, this);
return 0;
}
void WidgetWin::OnDestroy() {
+ SetNativeWindowProperty(kWidgetKey, NULL);
+
if (drop_target_.get()) {
RevokeDragDrop(hwnd());
drop_target_ = NULL;
@@ -1184,4 +1203,22 @@ RootView* Widget::FindRootView(HWND hwnd) {
return root_view;
}
+////////////////////////////////////////////////////////////////////////////////
+// Widget, public:
+
+// static
+Widget* Widget::GetWidgetFromNativeView(gfx::NativeView native_view) {
+ if (IsWindow(native_view)) {
+ HANDLE raw_widget = GetProp(native_view, kWidgetKey);
+ if (raw_widget)
+ return reinterpret_cast<Widget*>(raw_widget);
+ }
+ return NULL;
+}
+
+// static
+Widget* Widget::GetWidgetFromNativeWindow(gfx::NativeWindow native_window) {
+ return Widget::GetWidgetFromNativeView(native_window);
+}
+
} // namespace views