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 "views/widget/aero_tooltip_manager.h" | 5 #include "views/widget/aero_tooltip_manager.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <atlbase.h> | 8 #include <atlbase.h> |
9 #include <atlapp.h> // for GET_X/Y_LPARAM | 9 #include <atlapp.h> // for GET_X/Y_LPARAM |
10 #include <commctrl.h> | 10 #include <commctrl.h> |
11 #include <shlobj.h> | 11 #include <shlobj.h> |
12 | 12 |
13 #include "app/l10n_util_win.h" | 13 #include "app/l10n_util_win.h" |
14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
15 | 15 |
16 namespace views { | 16 namespace views { |
17 | 17 |
18 /////////////////////////////////////////////////////////////////////////////// | 18 /////////////////////////////////////////////////////////////////////////////// |
19 // AeroTooltipManager, public: | 19 // AeroTooltipManager, public: |
20 | 20 |
21 AeroTooltipManager::AeroTooltipManager(Widget* widget, HWND parent) | 21 AeroTooltipManager::AeroTooltipManager(Widget* widget) |
22 : TooltipManager(widget, parent), | 22 : TooltipManagerWin(widget), |
23 initial_delay_(0) { | 23 initial_delay_(0) { |
24 } | 24 } |
25 | 25 |
26 AeroTooltipManager::~AeroTooltipManager() { | 26 AeroTooltipManager::~AeroTooltipManager() { |
27 if (initial_timer_) | 27 if (initial_timer_) |
28 initial_timer_->Disown(); | 28 initial_timer_->Disown(); |
29 } | 29 } |
30 | 30 |
31 void AeroTooltipManager::OnMouse(UINT u_msg, WPARAM w_param, LPARAM l_param) { | 31 void AeroTooltipManager::OnMouse(UINT u_msg, WPARAM w_param, LPARAM l_param) { |
32 if (initial_timer_) | 32 if (initial_timer_) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 } | 64 } |
65 | 65 |
66 /////////////////////////////////////////////////////////////////////////////// | 66 /////////////////////////////////////////////////////////////////////////////// |
67 // AeroTooltipManager, private: | 67 // AeroTooltipManager, private: |
68 | 68 |
69 void AeroTooltipManager::Init() { | 69 void AeroTooltipManager::Init() { |
70 // Create the tooltip control. | 70 // Create the tooltip control. |
71 tooltip_hwnd_ = CreateWindowEx( | 71 tooltip_hwnd_ = CreateWindowEx( |
72 WS_EX_TRANSPARENT | l10n_util::GetExtendedTooltipStyles(), | 72 WS_EX_TRANSPARENT | l10n_util::GetExtendedTooltipStyles(), |
73 TOOLTIPS_CLASS, NULL, TTS_NOPREFIX, 0, 0, 0, 0, | 73 TOOLTIPS_CLASS, NULL, TTS_NOPREFIX, 0, 0, 0, 0, |
74 parent_, NULL, NULL, NULL); | 74 GetParent(), NULL, NULL, NULL); |
75 | 75 |
76 l10n_util::AdjustUIFontForWindow(tooltip_hwnd_); | 76 l10n_util::AdjustUIFontForWindow(tooltip_hwnd_); |
77 | 77 |
78 // Add one tool that is used for all tooltips. | 78 // Add one tool that is used for all tooltips. |
79 toolinfo_.cbSize = sizeof(toolinfo_); | 79 toolinfo_.cbSize = sizeof(toolinfo_); |
80 | 80 |
81 // We use tracking tooltips on Vista to allow us to manually control the | 81 // We use tracking tooltips on Vista to allow us to manually control the |
82 // visibility of the tooltip. | 82 // visibility of the tooltip. |
83 toolinfo_.uFlags = TTF_TRANSPARENT | TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE; | 83 toolinfo_.uFlags = TTF_TRANSPARENT | TTF_IDISHWND | TTF_TRACK | TTF_ABSOLUTE; |
84 toolinfo_.hwnd = parent_; | 84 toolinfo_.hwnd = GetParent(); |
85 toolinfo_.uId = (UINT_PTR)parent_; | 85 toolinfo_.uId = (UINT_PTR)GetParent(); |
86 | 86 |
87 // Setting this tells windows to call parent_ back (using a WM_NOTIFY | 87 // Setting this tells windows to call GetParent() back (using a WM_NOTIFY |
88 // message) for the actual tooltip contents. | 88 // message) for the actual tooltip contents. |
89 toolinfo_.lpszText = LPSTR_TEXTCALLBACK; | 89 toolinfo_.lpszText = LPSTR_TEXTCALLBACK; |
90 SetRectEmpty(&toolinfo_.rect); | 90 SetRectEmpty(&toolinfo_.rect); |
91 ::SendMessage(tooltip_hwnd_, TTM_ADDTOOL, 0, (LPARAM)&toolinfo_); | 91 ::SendMessage(tooltip_hwnd_, TTM_ADDTOOL, 0, (LPARAM)&toolinfo_); |
92 } | 92 } |
93 | 93 |
94 void AeroTooltipManager::OnTimer() { | 94 void AeroTooltipManager::OnTimer() { |
95 initial_timer_ = NULL; | 95 initial_timer_ = NULL; |
96 | 96 |
97 POINT pt; | 97 POINT pt; |
98 pt.x = last_mouse_x_; | 98 pt.x = last_mouse_x_; |
99 pt.y = last_mouse_y_; | 99 pt.y = last_mouse_y_; |
100 ::ClientToScreen(parent_, &pt); | 100 ::ClientToScreen(GetParent(), &pt); |
101 | 101 |
102 // Set the position and visibility. | 102 // Set the position and visibility. |
103 if (!tooltip_showing_) { | 103 if (!tooltip_showing_) { |
104 ::SendMessage(tooltip_hwnd_, TTM_POPUP, 0, 0); | 104 ::SendMessage(tooltip_hwnd_, TTM_POPUP, 0, 0); |
105 ::SendMessage(tooltip_hwnd_, TTM_TRACKPOSITION, 0, MAKELPARAM(pt.x, pt.y)); | 105 ::SendMessage(tooltip_hwnd_, TTM_TRACKPOSITION, 0, MAKELPARAM(pt.x, pt.y)); |
106 ::SendMessage(tooltip_hwnd_, TTM_TRACKACTIVATE, true, (LPARAM)&toolinfo_); | 106 ::SendMessage(tooltip_hwnd_, TTM_TRACKACTIVATE, true, (LPARAM)&toolinfo_); |
107 } | 107 } |
108 } | 108 } |
109 | 109 |
110 /////////////////////////////////////////////////////////////////////////////// | 110 /////////////////////////////////////////////////////////////////////////////// |
111 // AeroTooltipManager::InitialTimer | 111 // AeroTooltipManager::InitialTimer |
112 | 112 |
113 AeroTooltipManager::InitialTimer::InitialTimer(AeroTooltipManager* manager, | 113 AeroTooltipManager::InitialTimer::InitialTimer(AeroTooltipManager* manager, |
114 int time) : manager_(manager) { | 114 int time) : manager_(manager) { |
115 MessageLoop::current()->PostDelayedTask(FROM_HERE, NewRunnableMethod( | 115 MessageLoop::current()->PostDelayedTask(FROM_HERE, NewRunnableMethod( |
116 this, &InitialTimer::Execute), time); | 116 this, &InitialTimer::Execute), time); |
117 } | 117 } |
118 | 118 |
119 void AeroTooltipManager::InitialTimer::Disown() { | 119 void AeroTooltipManager::InitialTimer::Disown() { |
120 manager_ = NULL; | 120 manager_ = NULL; |
121 } | 121 } |
122 | 122 |
123 void AeroTooltipManager::InitialTimer::Execute() { | 123 void AeroTooltipManager::InitialTimer::Execute() { |
124 if (manager_) | 124 if (manager_) |
125 manager_->OnTimer(); | 125 manager_->OnTimer(); |
126 } | 126 } |
127 | 127 |
128 } // namespace views | 128 } // namespace views |
OLD | NEW |