Correct blacklist entry message
[chromium-blink-merge.git] / ui / views / widget / tooltip_manager_win.h
blobe12dfbb2859e155d250a21e3a07d8c248bc21370
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_
8 #include <windows.h>
9 #include <commctrl.h>
10 #include <string>
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"
19 namespace gfx {
20 class Point;
23 namespace views {
25 class View;
26 class Widget;
28 // TooltipManager implementation for Windows.
30 // This class is intended to be used by NativeWidgetWin. To use this, you must
31 // do the following:
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,
40 // BOOL& handled) {
41 // tooltip_manager_->OnMouse(u_msg, w_param, l_param);
42 // handled = FALSE;
43 // return 0;
44 // }
46 // LRESULT XXX::OnNotify(int w_param, NMHDR* l_param) {
47 // bool handled;
48 // LRESULT result = tooltip_manager_->OnNotify(w_param, l_param, &handled);
49 // SetMsgHandled(handled);
50 // return result;
51 // }
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 {
59 public:
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
66 // and not used.
67 bool Init();
69 // TooltipManager:
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);
78 protected:
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.
86 HWND tooltip_hwnd_;
88 // Tooltip information.
89 TOOLINFO toolinfo_;
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_;
97 private:
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
103 // positive value.
104 int CalcTooltipHeight();
106 // Hosting Widget.
107 Widget* widget_;
109 // The View the mouse is under. This is null if the mouse isn't under a
110 // View.
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
115 // refreshed.
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.
125 int line_count_;
127 // Width of the last tooltip.
128 int tooltip_width_;
130 DISALLOW_COPY_AND_ASSIGN(TooltipManagerWin);
133 } // namespace views
135 #endif // UI_VIEWS_WIDGET_TOOLTIP_MANAGER_WIN_H_