1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Context-sensitive help support classes
4 // Author: Julian Smart, Vadim Zeitlin
8 // Copyright: (c) 2000 Julian Smart, Vadim Zeitlin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 #if defined(__GNUG__) && !defined(__APPLE__)
16 #pragma interface "cshelp.h"
24 #include "wx/bmpbuttn.h"
26 // ----------------------------------------------------------------------------
27 // classes used to implement context help UI
28 // ----------------------------------------------------------------------------
32 * Invokes context-sensitive help. When the user
33 * clicks on a window, a wxEVT_HELP event will be sent to that
34 * window for the application to display help for.
37 class WXDLLEXPORT wxContextHelp
: public wxObject
40 wxContextHelp(wxWindow
* win
= NULL
, bool beginHelp
= TRUE
);
41 virtual ~wxContextHelp();
43 bool BeginContextHelp(wxWindow
* win
);
44 bool EndContextHelp();
47 bool DispatchEvent(wxWindow
* win
, const wxPoint
& pt
);
49 void SetStatus(bool status
) { m_status
= status
; }
53 bool m_status
; // TRUE if the user left-clicked
56 DECLARE_DYNAMIC_CLASS(wxContextHelp
)
61 * You can add this to your dialogs (especially on non-Windows platforms)
62 * to put the application into context help mode.
65 class WXDLLEXPORT wxContextHelpButton
: public wxBitmapButton
68 wxContextHelpButton(wxWindow
* parent
,
69 wxWindowID id
= wxID_CONTEXT_HELP
,
70 const wxPoint
& pos
= wxDefaultPosition
,
71 const wxSize
& size
= wxDefaultSize
,
72 long style
= wxBU_AUTODRAW
);
74 void OnContextHelp(wxCommandEvent
& event
);
77 DECLARE_CLASS(wxContextHelpButton
)
81 // ----------------------------------------------------------------------------
82 // classes used to implement context help support
83 // ----------------------------------------------------------------------------
85 // wxHelpProvider is an abstract class used by the program implementing context help to
86 // show the help text (or whatever: it may be HTML page or anything else) for
89 // The current help provider must be explicitly set by the application using
90 // wxHelpProvider::Set().
91 class WXDLLEXPORT wxHelpProvider
94 // get/set the current (application-global) help provider (Set() returns
96 static wxHelpProvider
*Set(wxHelpProvider
*helpProvider
)
98 wxHelpProvider
*helpProviderOld
= ms_helpProvider
;
99 ms_helpProvider
= helpProvider
;
100 return helpProviderOld
;
103 // unlike some other class, the help provider is not created on demand,
104 // this must be explicitly done by the application
105 static wxHelpProvider
*Get() { return ms_helpProvider
; }
107 // get the help string (whose interpretation is help provider dependent
108 // except that empty string always means that no help is associated with
109 // the window) for this window
110 virtual wxString
GetHelp(const wxWindowBase
*window
) = 0;
112 // do show help for the given window (uses GetHelp() internally if
113 // applicable), return TRUE if it was done or FALSE if no help available
115 virtual bool ShowHelp(wxWindowBase
*window
) = 0;
117 // associate the text with the given window or id: although all help
118 // providers have these functions to allow making wxWindow::SetHelpText()
119 // work, not all of them implement them
120 virtual void AddHelp(wxWindowBase
*window
, const wxString
& text
);
122 // this version associates the given text with all window with this id
123 // (may be used to set the same help string for all [Cancel] buttons in
124 // the application, for example)
125 virtual void AddHelp(wxWindowID id
, const wxString
& text
);
127 // removes the association
128 virtual void RemoveHelp(wxWindowBase
* window
);
130 // virtual dtor for any base class
131 virtual ~wxHelpProvider();
134 static wxHelpProvider
*ms_helpProvider
;
137 // wxSimpleHelpProvider is an implementation of wxHelpProvider which supports
138 // only plain text help strings and shows the string associated with the
139 // control (if any) in a tooltip
140 class WXDLLEXPORT wxSimpleHelpProvider
: public wxHelpProvider
143 // implement wxHelpProvider methods
144 virtual wxString
GetHelp(const wxWindowBase
*window
);
145 virtual bool ShowHelp(wxWindowBase
*window
);
146 virtual void AddHelp(wxWindowBase
*window
, const wxString
& text
);
147 virtual void AddHelp(wxWindowID id
, const wxString
& text
);
148 virtual void RemoveHelp(wxWindowBase
* window
);
151 // we use 2 hashes for storing the help strings associated with windows
153 wxStringHashTable m_hashWindows
,
157 // wxHelpControllerHelpProvider is an implementation of wxHelpProvider which supports
158 // both context identifiers and plain text help strings. If the help text is an integer,
159 // it is passed to wxHelpController::DisplayContextPopup. Otherwise, it shows the string
160 // in a tooltip as per wxSimpleHelpProvider.
161 class WXDLLEXPORT wxHelpControllerHelpProvider
: public wxSimpleHelpProvider
164 // Note that it doesn't own the help controller. The help controller
165 // should be deleted separately.
166 wxHelpControllerHelpProvider(wxHelpControllerBase
* hc
= (wxHelpControllerBase
*) NULL
);
168 // implement wxHelpProvider methods
169 virtual bool ShowHelp(wxWindowBase
*window
);
172 void SetHelpController(wxHelpControllerBase
* hc
) { m_helpController
= hc
; }
173 wxHelpControllerBase
* GetHelpController() const { return m_helpController
; }
176 wxHelpControllerBase
* m_helpController
;
179 // Convenience function for turning context id into wxString
180 WXDLLEXPORT wxString
wxContextId(int id
);
184 #endif // _WX_CSHELPH__