richtooltip.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: interface/wx/richtooltip.h
  3. // Purpose: wxRichToolTip class documentation
  4. // Author: Vadim Zeitlin
  5. // Created: 2011-10-18
  6. // Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
  7. // Licence: wxWindows licence
  8. ///////////////////////////////////////////////////////////////////////////////
  9. /**
  10. Support tip kinds for wxRichToolTip.
  11. This enum describes the kind of the tip shown which combines both the tip
  12. position and appearance because the two are related (when the tip is
  13. positioned asymmetrically, a right handed triangle is used but an
  14. equilateral one when it's in the middle of a side).
  15. Automatic selects the tip appearance best suited for the current platform
  16. and the position best suited for the window the tooltip is shown for, i.e.
  17. chosen in such a way that the tooltip is always fully on screen.
  18. Other values describe the position of the tooltip itself, not the window it
  19. relates to. E.g. wxTipKind_Top places the tip on the top of the tooltip and
  20. so the tooltip itself is located beneath its associated window.
  21. */
  22. enum wxTipKind
  23. {
  24. /// Don't show any tip, the tooltip will be (roughly) rectangular.
  25. wxTipKind_None,
  26. /// Show a right triangle tip in the top left corner of the tooltip.
  27. wxTipKind_TopLeft,
  28. /// Show an equilateral triangle tip in the middle of the tooltip top side.
  29. wxTipKind_Top,
  30. /// Show a right triangle tip in the top right corner of the tooltip.
  31. wxTipKind_TopRight,
  32. /// Show a right triangle tip in the bottom left corner of the tooltip.
  33. wxTipKind_BottomLeft,
  34. /// Show an equilateral triangle tip in the middle of the tooltip bottom side.
  35. wxTipKind_Bottom,
  36. /// Show a right triangle tip in the bottom right corner of the tooltip.
  37. wxTipKind_BottomRight,
  38. /**
  39. Choose the appropriate tip shape and position automatically.
  40. This is the default and shouldn't normally need to be changed.
  41. Notice that currently wxTipKind_Top or wxTipKind_Bottom are used under
  42. Mac while one of the other four values is selected for the other
  43. platforms.
  44. */
  45. wxTipKind_Auto
  46. };
  47. /**
  48. Allows to show a tool tip with more customizations than wxToolTip.
  49. Using this class is very simple, to give a standard warning for a password
  50. text control if the password was entered correctly you could simply do:
  51. @code
  52. wxTextCtrl* password = new wxTextCtrl(..., wxTE_PASSWORD);
  53. ...
  54. wxRichToolTip tip("Caps Lock is on",
  55. "You might have made an error in your password\n"
  56. "entry because Caps Lock is turned on.\n"
  57. "\n"
  58. "Press Caps Lock key to turn it off.");
  59. tip.SetIcon(wxICON_WARNING);
  60. tip.ShowFor(password);
  61. @endcode
  62. Currently this class has generic implementation that can be used with any
  63. window and implements all the functionality but doesn't exactly match the
  64. appearance of the native tooltips (even though it makes some efforts to
  65. use the style most appropriate for the current platform) and a native MSW
  66. version which can be only used with text controls and doesn't provide as
  67. much in the way of customization. Because of this, it's inadvisable to
  68. customize the tooltips unnecessarily as doing this turns off auto-detection
  69. of the native style in the generic version and may prevent the native MSW
  70. version from being used at all.
  71. Notice that this class is not derived from wxWindow and hence doesn't
  72. represent a window, even if its ShowFor() method does create one internally
  73. to show the tooltip.
  74. The images below show some examples of rich tooltips on different
  75. platforms, with various customizations applied.
  76. @library{wxadv}
  77. @category{miscwnd}
  78. @appearance{richtooltip}
  79. @since 2.9.3
  80. */
  81. class wxRichToolTip
  82. {
  83. public:
  84. /**
  85. Constructor must specify the tooltip title and main message.
  86. The main message can contain embedded new lines. Both the title and
  87. message must be non-empty.
  88. Additional attributes can be set later.
  89. */
  90. wxRichToolTip(const wxString& title, const wxString& message);
  91. /**
  92. Set the background colour.
  93. If two colours are specified, the background is drawn using a gradient
  94. from top to bottom, otherwise a single solid colour is used.
  95. By default the colour or colours most appropriate for the current
  96. platform are used. If a colour is explicitly set, native MSW version
  97. won't be used as it doesn't support setting the colour.
  98. */
  99. void SetBackgroundColour(const wxColour& col,
  100. const wxColour& colEnd = wxColour());
  101. /**
  102. Set the small icon to show.
  103. The icon can be either one of the standard information/warning/error
  104. ones, i.e. wxICON_INFORMATION, wxICON_WARNING or wxICON_ERROR
  105. respectively (the question icon doesn't make sense for a tooltip so
  106. wxICON_QUESTION can't be used here) or a custom icon. The latter is
  107. unsupported by the native MSW implementation of this class so the use
  108. of a standard icon is preferred.
  109. */
  110. //@{
  111. void SetIcon(int icon = wxICON_INFORMATION);
  112. void SetIcon(const wxIcon& icon);
  113. //@}
  114. /**
  115. Set timeout after which the tooltip should disappear and
  116. optionally set a delay before the tooltip is shown, in milliseconds.
  117. By default the tooltip is shown immediately and hidden after a
  118. system-dependent interval of time elapses. This method can be used to
  119. change this or also disable hiding the tooltip automatically entirely
  120. by passing 0 in this parameter (but doing this will prevent the native
  121. MSW version from being used).
  122. Notice that the tooltip will always be hidden if the user presses a key
  123. or clicks a mouse button.
  124. Parameter @a millisecondsDelay is new since wxWidgets 2.9.5.
  125. */
  126. void SetTimeout(unsigned millisecondsTimeout, unsigned millisecondsDelay = 0);
  127. /**
  128. Choose the tip kind, possibly none.
  129. See wxTipKind documentation for the possible choices here.
  130. By default the tip is positioned automatically, as if wxTipKind_Auto
  131. was used. Native MSW implementation doesn't support setting the tip
  132. kind explicitly and won't be used if this method is called with any
  133. value other than wxTipKind_Auto.
  134. Notice that using non automatic tooltip kind may result in the tooltip
  135. being positioned partially off screen and it's the callers
  136. responsibility to ensure that this doesn't happen in this case.
  137. */
  138. void SetTipKind(wxTipKind tipKind);
  139. /**
  140. Set the title text font.
  141. By default it's emphasized using the font style or colour appropriate
  142. for the current platform. Calling this method prevents the native MSW
  143. implementation from being used as it doesn't support changing the font.
  144. */
  145. void SetTitleFont(const wxFont& font);
  146. /**
  147. Show the tooltip for the given window and optionally specify where to
  148. show the tooltip.
  149. By default the tooltip tip points to the (middle of the) specified
  150. window which must be non-@NULL or, if @a rect is non-@NULL, the middle
  151. of the specified wxRect.
  152. The coordinates of the @a rect parameter are relative to the given window.
  153. Currently the native MSW implementation is used only if @a win is a
  154. wxTextCtrl and @a rect is @NULL. This limitation may be removed in the
  155. future.
  156. Parameter @a rect is new since wxWidgets 2.9.5.
  157. */
  158. void ShowFor(wxWindow* win, const wxRect* rect = NULL);
  159. /**
  160. Destructor.
  161. Notice that destroying this object does not hide the tooltip if it's
  162. currently shown, it will be hidden and destroyed when the user
  163. dismisses it or the timeout expires.
  164. The destructor is non-virtual as this class is not supposed to be
  165. derived from.
  166. */
  167. ~wxRichToolTip();
  168. };