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 #ifndef VIEWS_WIDGET_TOOLTIP_MANAGER_H_ | 5 #ifndef VIEWS_WIDGET_TOOLTIP_MANAGER_WIN_H_ |
6 #define VIEWS_WIDGET_TOOLTIP_MANAGER_H_ | 6 #define VIEWS_WIDGET_TOOLTIP_MANAGER_WIN_H_ |
7 | 7 |
8 #include <windows.h> | 8 #include <windows.h> |
9 #include <commctrl.h> | 9 #include <commctrl.h> |
| 10 #include <string> |
10 | 11 |
11 #include <string> | |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/gfx/native_widget_types.h" |
13 #include "base/task.h" | 14 #include "base/task.h" |
| 15 #include "views/widget/tooltip_manager.h" |
14 | 16 |
15 namespace gfx { | 17 namespace gfx { |
16 class Font; | 18 class Font; |
17 } | 19 } |
18 | 20 |
19 namespace views { | 21 namespace views { |
20 | 22 |
21 class View; | 23 class View; |
22 class Widget; | 24 class Widget; |
23 | 25 |
24 // TooltipManager takes care of the wiring to support tooltips for Views. | 26 // TooltipManager implementation for Windows. |
25 // This class is intended to be used by Widgets. To use this, you must | 27 // |
| 28 // This class is intended to be used by WidgetWin. To use this, you must |
26 // do the following: | 29 // do the following: |
27 // Add the following to your MSG_MAP: | 30 // Add the following to your MSG_MAP: |
28 // | 31 // |
29 // MESSAGE_RANGE_HANDLER(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseRange) | 32 // MESSAGE_RANGE_HANDLER(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseRange) |
30 // MESSAGE_RANGE_HANDLER(WM_NCMOUSEMOVE, WM_NCMOUSEMOVE, OnMouseRange) | 33 // MESSAGE_RANGE_HANDLER(WM_NCMOUSEMOVE, WM_NCMOUSEMOVE, OnMouseRange) |
31 // MSG_WM_NOTIFY(OnNotify) | 34 // MSG_WM_NOTIFY(OnNotify) |
32 // | 35 // |
33 // With the following implementations: | 36 // With the following implementations: |
34 // LRESULT XXX::OnMouseRange(UINT u_msg, WPARAM w_param, LPARAM l_param, | 37 // LRESULT XXX::OnMouseRange(UINT u_msg, WPARAM w_param, LPARAM l_param, |
35 // BOOL& handled) { | 38 // BOOL& handled) { |
36 // tooltip_manager_->OnMouse(u_msg, w_param, l_param); | 39 // tooltip_manager_->OnMouse(u_msg, w_param, l_param); |
37 // handled = FALSE; | 40 // handled = FALSE; |
38 // return 0; | 41 // return 0; |
39 // } | 42 // } |
40 // | 43 // |
41 // LRESULT XXX::OnNotify(int w_param, NMHDR* l_param) { | 44 // LRESULT XXX::OnNotify(int w_param, NMHDR* l_param) { |
42 // bool handled; | 45 // bool handled; |
43 // LRESULT result = tooltip_manager_->OnNotify(w_param, l_param, &handled); | 46 // LRESULT result = tooltip_manager_->OnNotify(w_param, l_param, &handled); |
44 // SetMsgHandled(handled); | 47 // SetMsgHandled(handled); |
45 // return result; | 48 // return result; |
46 // } | 49 // } |
47 // | 50 // |
48 // And of course you'll need to create the TooltipManager! | 51 // And of course you'll need to create the TooltipManager! |
49 // | 52 // |
50 // Lastly, you'll need to override GetTooltipManager. | 53 // Lastly, you'll need to override GetTooltipManager. |
51 // | 54 // |
52 // See XPFrame for an example of this in action. | 55 // See WidgetWin for an example of this in action. |
53 class TooltipManager { | 56 class TooltipManagerWin : public TooltipManager { |
54 public: | 57 public: |
55 // Returns the height of tooltips. This should only be invoked from within | |
56 // GetTooltipTextOrigin. | |
57 static int GetTooltipHeight(); | |
58 | |
59 // Returns the default font used by tooltips. | |
60 static gfx::Font GetDefaultFont(); | |
61 | |
62 // Returns the separator for lines of text in a tooltip. | |
63 static const std::wstring& GetLineSeparator(); | |
64 | |
65 // Creates a TooltipManager for the specified Widget and parent window. | 58 // Creates a TooltipManager for the specified Widget and parent window. |
66 TooltipManager(Widget* widget, HWND parent); | 59 explicit TooltipManagerWin(Widget* widget); |
67 virtual ~TooltipManager(); | 60 virtual ~TooltipManagerWin(); |
68 | 61 |
69 // Notification that the view hierarchy has changed in some way. | 62 // Notification that the view hierarchy has changed in some way. |
70 void UpdateTooltip(); | 63 virtual void UpdateTooltip(); |
71 | 64 |
72 // Invoked when the tooltip text changes for the specified views. | 65 // Invoked when the tooltip text changes for the specified views. |
73 void TooltipTextChanged(View* view); | 66 virtual void TooltipTextChanged(View* view); |
74 | 67 |
75 // Invoked when toolbar icon gets focus. | 68 // Invoked when toolbar icon gets focus. |
76 void ShowKeyboardTooltip(View* view); | 69 virtual void ShowKeyboardTooltip(View* view); |
77 | 70 |
78 // Invoked when toolbar loses focus. | 71 // Invoked when toolbar loses focus. |
79 void HideKeyboardTooltip(); | 72 virtual void HideKeyboardTooltip(); |
80 | 73 |
81 // Message handlers. These forward to the tooltip control. | 74 // Message handlers. These forward to the tooltip control. |
82 virtual void OnMouse(UINT u_msg, WPARAM w_param, LPARAM l_param); | 75 virtual void OnMouse(UINT u_msg, WPARAM w_param, LPARAM l_param); |
83 LRESULT OnNotify(int w_param, NMHDR* l_param, bool* handled); | 76 LRESULT OnNotify(int w_param, NMHDR* l_param, bool* handled); |
84 // Not used directly by TooltipManager, but provided for AeroTooltipManager. | 77 // Not used directly by TooltipManager, but provided for AeroTooltipManager. |
85 virtual void OnMouseLeave() {} | 78 virtual void OnMouseLeave() {} |
86 | 79 |
87 protected: | 80 protected: |
88 virtual void Init(); | 81 virtual void Init(); |
89 | 82 |
| 83 // Returns the Widget we're showing tooltips for. |
| 84 gfx::NativeView GetParent(); |
| 85 |
90 // Updates the tooltip for the specified location. | 86 // Updates the tooltip for the specified location. |
91 void UpdateTooltip(int x, int y); | 87 void UpdateTooltip(int x, int y); |
92 | 88 |
93 // Parent window the tooltip is added to. | |
94 HWND parent_; | |
95 | |
96 // Tooltip control window. | 89 // Tooltip control window. |
97 HWND tooltip_hwnd_; | 90 HWND tooltip_hwnd_; |
98 | 91 |
99 // Tooltip information. | 92 // Tooltip information. |
100 TOOLINFO toolinfo_; | 93 TOOLINFO toolinfo_; |
101 | 94 |
102 // Last location of the mouse. This is in the coordinates of the rootview. | 95 // Last location of the mouse. This is in the coordinates of the rootview. |
103 int last_mouse_x_; | 96 int last_mouse_x_; |
104 int last_mouse_y_; | 97 int last_mouse_y_; |
105 | 98 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 | 138 |
146 // The clipped tooltip. | 139 // The clipped tooltip. |
147 std::wstring clipped_text_; | 140 std::wstring clipped_text_; |
148 | 141 |
149 // Number of lines in the tooltip. | 142 // Number of lines in the tooltip. |
150 int line_count_; | 143 int line_count_; |
151 | 144 |
152 // Width of the last tooltip. | 145 // Width of the last tooltip. |
153 int tooltip_width_; | 146 int tooltip_width_; |
154 | 147 |
155 // Height for a tooltip; lazily calculated. | |
156 static int tooltip_height_; | |
157 | |
158 // control window for tooltip displayed using keyboard. | 148 // control window for tooltip displayed using keyboard. |
159 HWND keyboard_tooltip_hwnd_; | 149 HWND keyboard_tooltip_hwnd_; |
160 | 150 |
161 // Used to register DestroyTooltipWindow function with PostDelayedTask | 151 // Used to register DestroyTooltipWindow function with PostDelayedTask |
162 // function. | 152 // function. |
163 ScopedRunnableMethodFactory<TooltipManager> keyboard_tooltip_factory_; | 153 ScopedRunnableMethodFactory<TooltipManagerWin> keyboard_tooltip_factory_; |
164 | 154 |
165 DISALLOW_EVIL_CONSTRUCTORS(TooltipManager); | 155 DISALLOW_COPY_AND_ASSIGN(TooltipManagerWin); |
166 }; | 156 }; |
167 | 157 |
168 } // namespace views | 158 } // namespace views |
169 | 159 |
170 #endif // VIEWS_WIDGET_TOOLTIP_MANAGER_H_ | 160 #endif // VIEWS_WIDGET_TOOLTIP_MANAGER_WIN_H_ |
OLD | NEW |