1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef UI_VIEWS_WIDGET_TOOLTIP_MANAGER_WIN_H_
6 #define UI_VIEWS_WIDGET_TOOLTIP_MANAGER_WIN_H_
12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h"
14 #include "base/strings/string16.h"
15 #include "ui/gfx/native_widget_types.h"
16 #include "ui/gfx/point.h"
17 #include "ui/views/widget/tooltip_manager.h"
28 // TooltipManager implementation for Windows.
30 // This class is intended to be used by NativeWidgetWin. To use this, you must
32 // Add the following to your MSG_MAP:
34 // MESSAGE_RANGE_HANDLER(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseRange)
35 // MESSAGE_RANGE_HANDLER(WM_NCMOUSEMOVE, WM_NCMOUSEMOVE, OnMouseRange)
36 // MSG_WM_NOTIFY(OnNotify)
38 // With the following implementations:
39 // LRESULT XXX::OnMouseRange(UINT u_msg, WPARAM w_param, LPARAM l_param,
41 // tooltip_manager_->OnMouse(u_msg, w_param, l_param);
46 // LRESULT XXX::OnNotify(int w_param, NMHDR* l_param) {
48 // LRESULT result = tooltip_manager_->OnNotify(w_param, l_param, &handled);
49 // SetMsgHandled(handled);
53 // And of course you'll need to create the TooltipManager!
55 // Lastly, you'll need to override GetTooltipManager.
57 // See NativeWidgetWin for an example of this in action.
58 class TooltipManagerWin
: public TooltipManager
{
60 // Creates a TooltipManager for the specified Widget and parent window.
61 explicit TooltipManagerWin(Widget
* widget
);
62 virtual ~TooltipManagerWin();
64 // Initializes the TooltipManager returning whether initialization was
65 // successful. If this returns false the TooltipManager should be destroyed
70 virtual const gfx::FontList
& TooltipManagerWin::GetFontList() const OVERRIDE
;
71 virtual void UpdateTooltip() OVERRIDE
;
72 virtual void TooltipTextChanged(View
* view
) OVERRIDE
;
74 // Message handlers. These forward to the tooltip control.
75 virtual void OnMouse(UINT u_msg
, WPARAM w_param
, LPARAM l_param
);
76 LRESULT
OnNotify(int w_param
, NMHDR
* l_param
, bool* handled
);
79 // Returns the Widget we're showing tooltips for.
80 gfx::NativeView
GetParent();
82 // Updates the tooltip for the specified location.
83 void UpdateTooltip(const gfx::Point
& location
);
85 // Tooltip control window.
88 // Tooltip information.
91 // Last location of the mouse. This is in the coordinates of the rootview.
92 gfx::Point last_mouse_pos_
;
94 // Whether or not the tooltip is showing.
95 bool tooltip_showing_
;
98 // Sets the tooltip position based on the x/y position of the text. If the
99 // tooltip fits, true is returned.
100 bool SetTooltipPosition(int text_x
, int text_y
);
102 // Calculates the preferred height for tooltips. This always returns a
104 int CalcTooltipHeight();
109 // The View the mouse is under. This is null if the mouse isn't under a
111 View
* last_tooltip_view_
;
113 // Whether or not the view under the mouse needs to be refreshed. If this
114 // is true, when the tooltip is asked for the view under the mouse is
116 bool last_view_out_of_sync_
;
118 // Text for tooltip from the view.
119 string16 tooltip_text_
;
121 // The clipped tooltip.
122 string16 clipped_text_
;
124 // Number of lines in the tooltip.
127 // Width of the last tooltip.
130 DISALLOW_COPY_AND_ASSIGN(TooltipManagerWin
);
135 #endif // UI_VIEWS_WIDGET_TOOLTIP_MANAGER_WIN_H_