tooltip.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/msw/tooltip.h
  3. // Purpose: wxToolTip class - tooltip control
  4. // Author: Vadim Zeitlin
  5. // Modified by:
  6. // Created: 31.01.99
  7. // Copyright: (c) 1999 Robert Roebling, Vadim Zeitlin
  8. // Licence: wxWindows licence
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_MSW_TOOLTIP_H_
  11. #define _WX_MSW_TOOLTIP_H_
  12. #include "wx/object.h"
  13. #include "wx/gdicmn.h"
  14. class WXDLLIMPEXP_FWD_CORE wxWindow;
  15. class wxToolTipOtherWindows;
  16. class WXDLLIMPEXP_CORE wxToolTip : public wxObject
  17. {
  18. public:
  19. // ctor & dtor
  20. wxToolTip(const wxString &tip);
  21. virtual ~wxToolTip();
  22. // ctor used by wxStatusBar to associate a tooltip to a portion of
  23. // the status bar window:
  24. wxToolTip(wxWindow* win, unsigned int id,
  25. const wxString &tip, const wxRect& rc);
  26. // accessors
  27. // tip text
  28. void SetTip(const wxString& tip);
  29. const wxString& GetTip() const { return m_text; }
  30. // the window we're associated with
  31. void SetWindow(wxWindow *win);
  32. wxWindow *GetWindow() const { return m_window; }
  33. // controlling tooltip behaviour: globally change tooltip parameters
  34. // enable or disable the tooltips globally
  35. static void Enable(bool flag);
  36. // set the delay after which the tooltip appears
  37. static void SetDelay(long milliseconds);
  38. // set the delay after which the tooltip disappears or how long the
  39. // tooltip remains visible
  40. static void SetAutoPop(long milliseconds);
  41. // set the delay between subsequent tooltips to appear
  42. static void SetReshow(long milliseconds);
  43. // set maximum width for the new tooltips: -1 disables wrapping
  44. // entirely, 0 restores the default behaviour
  45. static void SetMaxWidth(int width);
  46. // implementation only from now on
  47. // -------------------------------
  48. // should be called in response to WM_MOUSEMOVE
  49. static void RelayEvent(WXMSG *msg);
  50. // add a window to the tooltip control
  51. void AddOtherWindow(WXHWND hwnd);
  52. // remove any tooltip from the window
  53. static void Remove(WXHWND hwnd, unsigned int id, const wxRect& rc);
  54. // Set the rectangle we're associated with. This rectangle is only used for
  55. // the main window, not any sub-windows added with Add() so in general it
  56. // makes sense to use it for tooltips associated with a single window only.
  57. void SetRect(const wxRect& rc);
  58. private:
  59. // Adds a window other than our main m_window to this tooltip.
  60. void DoAddHWND(WXHWND hWnd);
  61. // Perform the specified operation for the given window only.
  62. void DoSetTip(WXHWND hWnd);
  63. void DoRemove(WXHWND hWnd);
  64. // Call the given function for all windows we're associated with.
  65. void DoForAllWindows(void (wxToolTip::*func)(WXHWND));
  66. // the one and only one tooltip control we use - never access it directly
  67. // but use GetToolTipCtrl() which will create it when needed
  68. static WXHWND ms_hwndTT;
  69. // create the tooltip ctrl if it doesn't exist yet and return its HWND
  70. static WXHWND GetToolTipCtrl();
  71. // new tooltip maximum width, defaults to min(display width, 400)
  72. static int ms_maxWidth;
  73. // remove this tooltip from the tooltip control
  74. void Remove();
  75. // adjust tooltip max width based on current tooltip text
  76. bool AdjustMaxWidth();
  77. wxString m_text; // tooltip text
  78. wxWindow* m_window; // main window we're associated with
  79. wxToolTipOtherWindows *m_others; // other windows associated with it or NULL
  80. wxRect m_rect; // the rect of the window for which this tooltip is shown
  81. // (or a rect with width/height == 0 to show it for the entire window)
  82. unsigned int m_id; // the id of this tooltip (ignored when m_rect width/height is 0)
  83. DECLARE_ABSTRACT_CLASS(wxToolTip)
  84. wxDECLARE_NO_COPY_CLASS(wxToolTip);
  85. };
  86. #endif // _WX_MSW_TOOLTIP_H_