tooltip_win.h revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
14e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
24e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
34e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// found in the LICENSE file.
44e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
54e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#ifndef UI_VIEWS_COREWM_TOOLTIP_WIN_H_
64e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#define UI_VIEWS_COREWM_TOOLTIP_WIN_H_
74e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
84e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "base/basictypes.h"
94e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "base/compiler_specific.h"
104e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "base/strings/string16.h"
114e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ui/gfx/point.h"
124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ui/views/corewm/tooltip.h"
134e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include <windows.h>
154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include <commctrl.h>
164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)namespace views {
184e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)namespace corewm {
194e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Implementation of Tooltip that uses the native win32 control for showing the
214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// tooltip.
224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)class VIEWS_EXPORT TooltipWin : public Tooltip {
234e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) public:
244e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  explicit TooltipWin(HWND parent);
254e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  virtual ~TooltipWin();
264e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // HandleNotify() is forwarded from DesktopWindowTreeHostWin to keep the
284e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // native tooltip in sync.
294e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  bool HandleNotify(int w_param, NMHDR* l_param, LRESULT* l_result);
304e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
314e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) private:
324e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Ensures |tooltip_hwnd_| is valid. Returns true if valid, false if there
334e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // a problem creating |tooltip_hwnd_|.
344e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  bool EnsureTooltipWindow();
354e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
364e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Sets the position of the tooltip.
374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  void PositionTooltip();
384e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
394e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Tooltip:
404e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  virtual void SetText(aura::Window* window,
414e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)                       const base::string16& tooltip_text,
424e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)                       const gfx::Point& location) OVERRIDE;
434e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  virtual void Show() OVERRIDE;
444e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  virtual void Hide() OVERRIDE;
454e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  virtual bool IsVisible() OVERRIDE;
464e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
474e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // The window |tooltip_hwnd_| is parented to.
484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  HWND parent_hwnd_;
494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
504e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Shows the tooltip.
514e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  HWND tooltip_hwnd_;
524e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Used to modify the tooltip.
544e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  TOOLINFO toolinfo_;
554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
564e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Is the tooltip showing?
574e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  bool showing_;
584e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
594e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // Location to show the tooltip at. In order to position the tooltip we need
604e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // to know the size. The size is only available from TTN_SHOW, so we have to
614e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // cache it.
624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  gfx::Point location_;
634e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
644e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(TooltipWin);
654e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)};
664e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
674e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}  // namespace corewm
684e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}  // namespace views
694e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
704e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#endif  // UI_VIEWS_COREWM_TOOLTIP_WIN_H_
71