NCBI C++ ToolKit
tooltip_handler.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef __GUI_WIDGETS_GL___TOOLTIP_HANDLER__HPP
2 #define __GUI_WIDGETS_GL___TOOLTIP_HANDLER__HPP
3 
4 /* $Id: tooltip_handler.hpp 21488 2010-06-08 13:54:09Z falkrb $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Vladimir Tereshkov
30  *
31  * File Description:
32  *
33  */
34 
35 #include <corelib/ncbistl.hpp>
36 
38 
39 #include <math.h>
40 
41 #include <wx/timer.h>
42 
44 
45 ////////////////////////////////////////////////////////////////////////////////
46 ///
48 {
49 public:
50  public:
51  virtual ~ITooltipHandlerHost() { }
52 
53  /// Returns "true" if client wants to dispaly a tooltip. "x" and "y" are
54  /// cordinates of the mouse pointer
55  virtual bool TC_NeedTooltip(const wxPoint & pt) = 0;
56 
57  /// Returns tooltip string and coordinates for area tootlip associated
58  /// with. Client may choose not modify x, y, w, z, in that case tooltip
59  /// will be associated with current mouse position.
60  virtual string TC_GetTooltip(const wxRect & rect) = 0;
61 
62  /// Returns pointer to the widget hosting ITooltipClient.
63  /// Default implementation returns "this";
64  virtual wxWindow* TC_GetWindow() = 0;
65 
66 };
67 
68 class CTooltipWnd;
69 
70 
71 // tooltip class
72 class CTooltip : public wxTimer
73 {
74 protected:
75  bool m_bNewText;
76  wxString m_Text;
79 
80  // Screen coordniates of mouse when tip enabled
81  wxPoint m_ScreenPos;
82  // Mouse position on Window when tip enabled
83  wxPoint m_BasePos;
84  // Offset between m_BasePos and position tip shown
85  wxPoint m_PosDelta;
86 
87  bool m_On;
88 public:
90  ~CTooltip();
91 
92  // sets text for tooltip
93  void SetText(const string & text);
94 
95  // host is needed to access tooltip-ed wxWindow
97  {
98  m_Host = host;
99  }
100 
101  // new or old text
102  bool NewText() const { return m_bNewText; }
103 
104  // switch tooltip off (should work on mac/gtk)
105  void Off();
106  // switch tooltip On
107  void On(wxPoint point);
108  void Move();
109  void WinMove();
110  bool IsOn() const { return m_On; }
111  bool IsShown() const;
112  wxPoint GetScreenPos() const { return m_ScreenPos; }
113 
114  // mouse move default tooltip handle
115  void HideAndShow(wxPoint point);
116  void Hide();
117  // wxTimer
118  void Notify();
119 };
120 
121 ////////////////////////////////////////////////////////////////////////////////
122 /// CTooltipHandler
123 
125  public wxEvtHandler,
126  public IGlEventHandler
127 {
128  DECLARE_EVENT_TABLE()
129 public:
130  enum EMode {
131  eHideOnMove, /// if mouse moves tooltip hides and reappears only after delay
132  eTrackOnMove, /// if mouse moves tooltip reappears immediatly in a new position
133  /// if text is the same
134  eStayOnMove /// if tooltip area and text remain the same - tooltip will remain on screen
135  /// and will not move
136  };
137 
138  CTooltipHandler();
139  virtual ~CTooltipHandler();
140 
141  virtual void SetMode(EMode mode);
142  virtual void SetHost(ITooltipHandlerHost* host);
144 
145  /// @name IGlEventHandler implementaion
146  /// @{
147  virtual void SetPane(CGlPane* pane);
148  virtual wxEvtHandler* GetEvtHandler();
149  /// @}
150 
151  void OnLeftDown(wxMouseEvent& event);
152  void OnRightDown(wxMouseEvent& event);
153  void OnMotion(wxMouseEvent& event);
154  void OnMouseCaptureLost(wxMouseCaptureLostEvent& evt);
155  void OnKeyDown(wxKeyEvent& event);
156  void OnKillFocus(wxFocusEvent& event);
157  void OnSize(wxSizeEvent& event);
158  void OnTimer(wxTimerEvent& event);
159 
160 
161 protected:
167 };
168 
169 
171 
172 #endif
class CGlPane
Definition: glpane.hpp:62
CTooltipHandler.
ITooltipHandlerHost * m_Host
IGenericHandlerHost * GetGenericHost()
@ eTrackOnMove
if mouse moves tooltip hides and reappears only after delay
~CTooltip()
class CTooltip
wxString m_Text
wxPoint m_PosDelta
bool IsOn() const
wxPoint m_BasePos
ITooltipHandlerHost * m_Host
void SetHost(ITooltipHandlerHost *host)
CTooltipWnd * m_TooltipWnd
void On(wxPoint point)
void SetText(const string &text)
bool IsShown() const
wxPoint m_ScreenPos
void HideAndShow(wxPoint point)
wxPoint GetScreenPos() const
bool NewText() const
IGenericHandlerHost.
IGlEventHandler.
virtual void SetPane(CGlPane *)
virtual wxEvtHandler * GetEvtHandler()=0
virtual ~ITooltipHandlerHost()
virtual string TC_GetTooltip(const wxRect &rect)=0
Returns tooltip string and coordinates for area tootlip associated with.
virtual bool TC_NeedTooltip(const wxPoint &pt)=0
Returns "true" if client wants to dispaly a tooltip.
virtual wxWindow * TC_GetWindow()=0
Returns pointer to the widget hosting ITooltipClient.
#define false
Definition: bool.h:36
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NCBI_GUIWIDGETS_GL_EXPORT
Definition: gui_export.h:529
static void text(MDB_val *v)
Definition: mdb_dump.c:62
mdb_mode_t mode
Definition: lmdb++.h:38
The NCBI C++/STL use hints.
Modified on Tue Apr 16 20:08:35 2024 by modify_doxy.py rev. 669887