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"
25 #include "wx/hashmap.h"
27 #include "wx/bmpbuttn.h"
30 // ----------------------------------------------------------------------------
31 // classes used to implement context help UI
32 // ----------------------------------------------------------------------------
36 * Invokes context-sensitive help. When the user
37 * clicks on a window, a wxEVT_HELP event will be sent to that
38 * window for the application to display help for.
41 class WXDLLEXPORT wxContextHelp
: public wxObject
44 wxContextHelp(wxWindow
* win
= NULL
, bool beginHelp
= TRUE
);
45 virtual ~wxContextHelp();
47 bool BeginContextHelp(wxWindow
* win
);
48 bool EndContextHelp();
51 bool DispatchEvent(wxWindow
* win
, const wxPoint
& pt
);
53 void SetStatus(bool status
) { m_status
= status
; }
57 bool m_status
; // TRUE if the user left-clicked
60 DECLARE_DYNAMIC_CLASS(wxContextHelp
)
66 * You can add this to your dialogs (especially on non-Windows platforms)
67 * to put the application into context help mode.
70 class WXDLLEXPORT wxContextHelpButton
: public wxBitmapButton
73 wxContextHelpButton(wxWindow
* parent
,
74 wxWindowID id
= wxID_CONTEXT_HELP
,
75 const wxPoint
& pos
= wxDefaultPosition
,
76 const wxSize
& size
= wxDefaultSize
,
77 long style
= wxBU_AUTODRAW
);
79 void OnContextHelp(wxCommandEvent
& event
);
82 DECLARE_DYNAMIC_CLASS_NO_COPY(wxContextHelpButton
)
88 // ----------------------------------------------------------------------------
89 // classes used to implement context help support
90 // ----------------------------------------------------------------------------
92 // wxHelpProvider is an abstract class used by the program implementing context help to
93 // show the help text (or whatever: it may be HTML page or anything else) for
96 // The current help provider must be explicitly set by the application using
97 // wxHelpProvider::Set().
98 class WXDLLEXPORT wxHelpProvider
101 // get/set the current (application-global) help provider (Set() returns
103 static wxHelpProvider
*Set(wxHelpProvider
*helpProvider
)
105 wxHelpProvider
*helpProviderOld
= ms_helpProvider
;
106 ms_helpProvider
= helpProvider
;
107 return helpProviderOld
;
110 // unlike some other class, the help provider is not created on demand,
111 // this must be explicitly done by the application
112 static wxHelpProvider
*Get() { return ms_helpProvider
; }
114 // get the help string (whose interpretation is help provider dependent
115 // except that empty string always means that no help is associated with
116 // the window) for this window
117 virtual wxString
GetHelp(const wxWindowBase
*window
) = 0;
119 // do show help for the given window (uses GetHelp() internally if
120 // applicable), return TRUE if it was done or FALSE if no help available
122 virtual bool ShowHelp(wxWindowBase
*window
) = 0;
124 // associate the text with the given window or id: although all help
125 // providers have these functions to allow making wxWindow::SetHelpText()
126 // work, not all of them implement them
127 virtual void AddHelp(wxWindowBase
*window
, const wxString
& text
);
129 // this version associates the given text with all window with this id
130 // (may be used to set the same help string for all [Cancel] buttons in
131 // the application, for example)
132 virtual void AddHelp(wxWindowID id
, const wxString
& text
);
134 // removes the association
135 virtual void RemoveHelp(wxWindowBase
* window
);
137 // virtual dtor for any base class
138 virtual ~wxHelpProvider();
141 static wxHelpProvider
*ms_helpProvider
;
144 WX_DECLARE_HASH_MAP( long, wxString
, wxIntegerHash
, wxIntegerEqual
,
145 wxLongToStringHashMap
);
147 // wxSimpleHelpProvider is an implementation of wxHelpProvider which supports
148 // only plain text help strings and shows the string associated with the
149 // control (if any) in a tooltip
150 class WXDLLEXPORT wxSimpleHelpProvider
: public wxHelpProvider
153 // implement wxHelpProvider methods
154 virtual wxString
GetHelp(const wxWindowBase
*window
);
155 virtual bool ShowHelp(wxWindowBase
*window
);
156 virtual void AddHelp(wxWindowBase
*window
, const wxString
& text
);
157 virtual void AddHelp(wxWindowID id
, const wxString
& text
);
158 virtual void RemoveHelp(wxWindowBase
* window
);
161 // we use 2 hashes for storing the help strings associated with windows
163 wxLongToStringHashMap m_hashWindows
,
167 // wxHelpControllerHelpProvider is an implementation of wxHelpProvider which supports
168 // both context identifiers and plain text help strings. If the help text is an integer,
169 // it is passed to wxHelpController::DisplayContextPopup. Otherwise, it shows the string
170 // in a tooltip as per wxSimpleHelpProvider.
171 class WXDLLEXPORT wxHelpControllerHelpProvider
: public wxSimpleHelpProvider
174 // Note that it doesn't own the help controller. The help controller
175 // should be deleted separately.
176 wxHelpControllerHelpProvider(wxHelpControllerBase
* hc
= (wxHelpControllerBase
*) NULL
);
178 // implement wxHelpProvider methods
179 virtual bool ShowHelp(wxWindowBase
*window
);
182 void SetHelpController(wxHelpControllerBase
* hc
) { m_helpController
= hc
; }
183 wxHelpControllerBase
* GetHelpController() const { return m_helpController
; }
186 wxHelpControllerBase
* m_helpController
;
188 DECLARE_NO_COPY_CLASS(wxHelpControllerHelpProvider
)
191 // Convenience function for turning context id into wxString
192 WXDLLEXPORT wxString
wxContextId(int id
);
196 #endif // _WX_CSHELPH__