cshelp.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: cshelp.h
  3. // Purpose: interface of wxHelpProvider
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @class wxHelpProvider
  9. wxHelpProvider is an abstract class used by a program implementing
  10. context-sensitive help to show the help text for the given window.
  11. The current help provider must be explicitly set by the application using
  12. Set().
  13. @library{wxcore}
  14. @category{help}
  15. @see wxContextHelp, wxContextHelpButton, wxSimpleHelpProvider,
  16. wxHelpControllerHelpProvider, wxWindow::SetHelpText(),
  17. wxWindow::GetHelpTextAtPoint()
  18. */
  19. class wxHelpProvider
  20. {
  21. public:
  22. /**
  23. Virtual destructor for any base class.
  24. */
  25. virtual ~wxHelpProvider();
  26. /**
  27. Associates the text with the given window.
  28. @remarks
  29. Although all help providers have these functions to allow making
  30. wxWindow::SetHelpText() work, not all of them implement the functions.
  31. */
  32. virtual void AddHelp(wxWindowBase* window, const wxString& text);
  33. /**
  34. Associates the text with the given ID.
  35. This help text will be shown for all windows with ID @a id, unless they
  36. have more specific help text associated using the other AddHelp()
  37. prototype. May be used to set the same help string for all Cancel
  38. buttons in the application, for example.
  39. @remarks
  40. Although all help providers have these functions to allow making
  41. wxWindow::SetHelpText() work, not all of them implement the functions.
  42. */
  43. virtual void AddHelp(wxWindowID id, const wxString& text);
  44. /**
  45. Returns pointer to help provider instance.
  46. Unlike some other classes, the help provider is not created on demand.
  47. This must be explicitly done by the application using Set().
  48. */
  49. static wxHelpProvider* Get();
  50. /**
  51. This version associates the given text with all windows with this id.
  52. May be used to set the same help string for all Cancel buttons in
  53. the application, for example.
  54. */
  55. virtual wxString GetHelp(const wxWindowBase* window) = 0;
  56. /**
  57. Removes the association between the window pointer and the help text.
  58. This is called by the wxWindow destructor. Without this, the table of
  59. help strings will fill up and when window pointers are reused, the
  60. wrong help string will be found.
  61. */
  62. virtual void RemoveHelp(wxWindowBase* window);
  63. /**
  64. Set the current, application-wide help provider.
  65. @return Pointer to previous help provider or @NULL if there wasn't any.
  66. */
  67. static wxHelpProvider* Set(wxHelpProvider* helpProvider);
  68. /**
  69. Shows help for the given window.
  70. Override this function if the help doesn't depend on the exact position
  71. inside the window, otherwise you need to override ShowHelpAtPoint().
  72. Returns @true if help was shown, or @false if no help was available for
  73. this window.
  74. */
  75. virtual bool ShowHelp(wxWindowBase* window);
  76. /**
  77. This function may be overridden to show help for the window when it
  78. should depend on the position inside the window, By default this method
  79. forwards to ShowHelp(), so it is enough to only implement the latter if
  80. the help doesn't depend on the position.
  81. @param window
  82. Window to show help text for.
  83. @param point
  84. Coordinates of the mouse at the moment of help event emission.
  85. @param origin
  86. Help event origin, see wxHelpEvent::GetOrigin.
  87. @return @true if help was shown, or @false if no help was available
  88. for this window.
  89. @since 2.7.0
  90. */
  91. virtual bool ShowHelpAtPoint(wxWindowBase* window, const wxPoint& point,
  92. wxHelpEvent::Origin origin);
  93. };
  94. /**
  95. @class wxHelpControllerHelpProvider
  96. wxHelpControllerHelpProvider is an implementation of wxHelpProvider which
  97. supports both context identifiers and plain text help strings. If the help
  98. text is an integer, it is passed to wxHelpController::DisplayContextPopup().
  99. Otherwise, it shows the string in a tooltip as per wxSimpleHelpProvider. If
  100. you use this with a wxCHMHelpController instance on windows, it will use
  101. the native style of tip window instead of wxTipWindow.
  102. You can use the convenience function wxContextId() to convert an integer
  103. context id to a string for passing to wxWindow::SetHelpText().
  104. @library{wxcore}
  105. @category{help}
  106. @see wxHelpProvider, wxSimpleHelpProvider, wxContextHelp,
  107. wxWindow::SetHelpText(), wxWindow::GetHelpTextAtPoint()
  108. */
  109. class wxHelpControllerHelpProvider : public wxSimpleHelpProvider
  110. {
  111. public:
  112. /**
  113. Note that the instance doesn't own the help controller. The help
  114. controller should be deleted separately.
  115. */
  116. wxHelpControllerHelpProvider(wxHelpControllerBase* hc = NULL);
  117. /**
  118. Returns the help controller associated with this help provider.
  119. */
  120. wxHelpControllerBase* GetHelpController() const;
  121. /**
  122. Sets the help controller associated with this help provider.
  123. */
  124. void SetHelpController(wxHelpControllerBase* hc);
  125. };
  126. /**
  127. @class wxContextHelp
  128. This class changes the cursor to a query and puts the application into a
  129. 'context-sensitive help mode'. When the user left-clicks on a window
  130. within the specified window, a @c wxEVT_HELP event is sent to that control,
  131. and the application may respond to it by popping up some help.
  132. For example:
  133. @code
  134. wxContextHelp contextHelp(myWindow);
  135. @endcode
  136. There are a couple of ways to invoke this behaviour implicitly:
  137. - Use the wxDIALOG_EX_CONTEXTHELP style for a dialog (Windows only). This
  138. will put a question mark in the titlebar, and Windows will put the
  139. application into context-sensitive help mode automatically, with further
  140. programming.
  141. - Create a wxContextHelpButton, whose predefined behaviour is
  142. to create a context help object. Normally you will write your application
  143. so that this button is only added to a dialog for non-Windows platforms
  144. (use wxDIALOG_EX_CONTEXTHELP on Windows).
  145. Note that on Mac OS X, the cursor does not change when in context-sensitive
  146. help mode.
  147. @library{wxcore}
  148. @category{help}
  149. @see wxHelpEvent, wxHelpController, wxContextHelpButton
  150. */
  151. class wxContextHelp : public wxObject
  152. {
  153. public:
  154. /**
  155. Constructs a context help object, calling BeginContextHelp() if
  156. @a doNow is @true (the default).
  157. If @a window is @NULL, the top window is used.
  158. */
  159. wxContextHelp(wxWindow* window = NULL, bool doNow = true);
  160. /**
  161. Destroys the context help object.
  162. */
  163. virtual ~wxContextHelp();
  164. /**
  165. Puts the application into context-sensitive help mode. @a window is the
  166. window which will be used to catch events; if @NULL, the top window
  167. will be used.
  168. Returns @true if the application was successfully put into
  169. context-sensitive help mode.
  170. This function only returns when the event loop has finished.
  171. */
  172. bool BeginContextHelp(wxWindow* window);
  173. /**
  174. Ends context-sensitive help mode. Not normally called by the
  175. application.
  176. */
  177. bool EndContextHelp();
  178. };
  179. /**
  180. @class wxContextHelpButton
  181. Instances of this class may be used to add a question mark button that when
  182. pressed, puts the application into context-help mode. It does this by
  183. creating a wxContextHelp object which itself generates a @c wxEVT_HELP event
  184. when the user clicks on a window.
  185. On Windows, you may add a question-mark icon to a dialog by use of the
  186. wxDIALOG_EX_CONTEXTHELP extra style, but on other platforms you will have
  187. to add a button explicitly, usually next to OK, Cancel or similar buttons.
  188. @library{wxcore}
  189. @category{help}
  190. @see wxBitmapButton, wxContextHelp
  191. */
  192. class wxContextHelpButton : public wxBitmapButton
  193. {
  194. public:
  195. /**
  196. Constructor, creating and showing a context help button.
  197. @param parent
  198. Parent window. Must not be @NULL.
  199. @param id
  200. Button identifier. Defaults to wxID_CONTEXT_HELP.
  201. @param pos
  202. Button position.
  203. If ::wxDefaultPosition is specified then a default position is chosen.
  204. @param size
  205. Button size.
  206. If ::wxDefaultSize is specified then the button is sized appropriately
  207. for the question mark bitmap.
  208. @param style
  209. Window style.
  210. @remarks
  211. Normally you only need pass the parent window to the constructor, and
  212. use the defaults for the remaining parameters.
  213. */
  214. wxContextHelpButton(wxWindow* parent,
  215. wxWindowID id = wxID_CONTEXT_HELP,
  216. const wxPoint& pos = wxDefaultPosition,
  217. const wxSize& size = wxDefaultSize,
  218. long style = wxBU_AUTODRAW);
  219. };
  220. /**
  221. @class wxSimpleHelpProvider
  222. wxSimpleHelpProvider is an implementation of wxHelpProvider which supports
  223. only plain text help strings, and shows the string associated with the
  224. control (if any) in a tooltip.
  225. @library{wxcore}
  226. @category{help}
  227. @see wxHelpProvider, wxHelpControllerHelpProvider, wxContextHelp,
  228. wxWindow::SetHelpText()(, wxWindow::GetHelpTextAtPoint()
  229. */
  230. class wxSimpleHelpProvider : public wxHelpProvider
  231. {
  232. public:
  233. };