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 /////////////////////////////////////////////////////////////////////////////
21 #include "wx/hashmap.h"
23 #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
)
62 * You can add this to your dialogs (especially on non-Windows platforms)
63 * to put the application into context help mode.
66 class WXDLLEXPORT wxContextHelpButton
: public wxBitmapButton
69 wxContextHelpButton(wxWindow
* parent
,
70 wxWindowID id
= wxID_CONTEXT_HELP
,
71 const wxPoint
& pos
= wxDefaultPosition
,
72 const wxSize
& size
= wxDefaultSize
,
73 long style
= wxBU_AUTODRAW
);
75 void OnContextHelp(wxCommandEvent
& event
);
78 DECLARE_DYNAMIC_CLASS_NO_COPY(wxContextHelpButton
)
84 // ----------------------------------------------------------------------------
85 // classes used to implement context help support
86 // ----------------------------------------------------------------------------
88 // wxHelpProvider is an abstract class used by the program implementing context help to
89 // show the help text (or whatever: it may be HTML page or anything else) for
92 // The current help provider must be explicitly set by the application using
93 // wxHelpProvider::Set().
94 class WXDLLEXPORT wxHelpProvider
97 // get/set the current (application-global) help provider (Set() returns
99 static wxHelpProvider
*Set(wxHelpProvider
*helpProvider
)
101 wxHelpProvider
*helpProviderOld
= ms_helpProvider
;
102 ms_helpProvider
= helpProvider
;
103 return helpProviderOld
;
106 // unlike some other class, the help provider is not created on demand,
107 // this must be explicitly done by the application
108 static wxHelpProvider
*Get() { return ms_helpProvider
; }
110 // get the help string (whose interpretation is help provider dependent
111 // except that empty string always means that no help is associated with
112 // the window) for this window
113 virtual wxString
GetHelp(const wxWindowBase
*window
) = 0;
115 // do show help for the given window (uses GetHelp() internally if
116 // applicable), return true if it was done or false if no help available
118 virtual bool ShowHelp(wxWindowBase
*window
) = 0;
120 // associate the text with the given window or id: although all help
121 // providers have these functions to allow making wxWindow::SetHelpText()
122 // work, not all of them implement them
123 virtual void AddHelp(wxWindowBase
*window
, const wxString
& text
);
125 // this version associates the given text with all window with this id
126 // (may be used to set the same help string for all [Cancel] buttons in
127 // the application, for example)
128 virtual void AddHelp(wxWindowID id
, const wxString
& text
);
130 // removes the association
131 virtual void RemoveHelp(wxWindowBase
* window
);
133 // virtual dtor for any base class
134 virtual ~wxHelpProvider();
137 static wxHelpProvider
*ms_helpProvider
;
140 WX_DECLARE_EXPORTED_HASH_MAP( wxUIntPtr
, wxString
, wxIntegerHash
,
141 wxIntegerEqual
, wxSimpleHelpProviderHashMap
);
143 // wxSimpleHelpProvider is an implementation of wxHelpProvider which supports
144 // only plain text help strings and shows the string associated with the
145 // control (if any) in a tooltip
146 class WXDLLEXPORT wxSimpleHelpProvider
: public wxHelpProvider
149 // implement wxHelpProvider methods
150 virtual wxString
GetHelp(const wxWindowBase
*window
);
151 virtual bool ShowHelp(wxWindowBase
*window
);
152 virtual void AddHelp(wxWindowBase
*window
, const wxString
& text
);
153 virtual void AddHelp(wxWindowID id
, const wxString
& text
);
154 virtual void RemoveHelp(wxWindowBase
* window
);
157 // we use 2 hashes for storing the help strings associated with windows
159 wxSimpleHelpProviderHashMap m_hashWindows
,
163 // wxHelpControllerHelpProvider is an implementation of wxHelpProvider which supports
164 // both context identifiers and plain text help strings. If the help text is an integer,
165 // it is passed to wxHelpController::DisplayContextPopup. Otherwise, it shows the string
166 // in a tooltip as per wxSimpleHelpProvider.
167 class WXDLLEXPORT wxHelpControllerHelpProvider
: public wxSimpleHelpProvider
170 // Note that it doesn't own the help controller. The help controller
171 // should be deleted separately.
172 wxHelpControllerHelpProvider(wxHelpControllerBase
* hc
= (wxHelpControllerBase
*) NULL
);
174 // implement wxHelpProvider methods
175 virtual bool ShowHelp(wxWindowBase
*window
);
178 void SetHelpController(wxHelpControllerBase
* hc
) { m_helpController
= hc
; }
179 wxHelpControllerBase
* GetHelpController() const { return m_helpController
; }
182 wxHelpControllerBase
* m_helpController
;
184 DECLARE_NO_COPY_CLASS(wxHelpControllerHelpProvider
)
187 // Convenience function for turning context id into wxString
188 WXDLLEXPORT wxString
wxContextId(int id
);
192 #endif // _WX_CSHELPH__