]>
Commit | Line | Data |
---|---|---|
fb6261e9 | 1 | ///////////////////////////////////////////////////////////////////////////// |
bd83cb56 VZ |
2 | // Name: wx/cshelp.h |
3 | // Purpose: Context-sensitive help support classes | |
4 | // Author: Julian Smart, Vadim Zeitlin | |
fb6261e9 JS |
5 | // Modified by: |
6 | // Created: 08/09/2000 | |
7 | // RCS-ID: $Id$ | |
bd83cb56 | 8 | // Copyright: (c) 2000 Julian Smart, Vadim Zeitlin |
fb6261e9 JS |
9 | // Licence: wxWindows licence |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_CSHELPH__ | |
13 | #define _WX_CSHELPH__ | |
14 | ||
12028905 | 15 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
bd83cb56 | 16 | #pragma interface "cshelp.h" |
fb6261e9 JS |
17 | #endif |
18 | ||
19 | #include "wx/defs.h" | |
20 | ||
21 | #if wxUSE_HELP | |
22 | ||
56029a74 | 23 | #include "wx/help.h" |
ae500232 | 24 | |
ba8c1601 | 25 | #include "wx/hashmap.h" |
ae500232 | 26 | #if wxUSE_BMPBUTTON |
fb6261e9 | 27 | #include "wx/bmpbuttn.h" |
ae500232 | 28 | #endif |
fb6261e9 | 29 | |
bd83cb56 VZ |
30 | // ---------------------------------------------------------------------------- |
31 | // classes used to implement context help UI | |
32 | // ---------------------------------------------------------------------------- | |
33 | ||
fb6261e9 JS |
34 | /* |
35 | * wxContextHelp | |
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. | |
39 | */ | |
40 | ||
bd83cb56 | 41 | class WXDLLEXPORT wxContextHelp : public wxObject |
fb6261e9 | 42 | { |
fb6261e9 JS |
43 | public: |
44 | wxContextHelp(wxWindow* win = NULL, bool beginHelp = TRUE); | |
bd83cb56 | 45 | virtual ~wxContextHelp(); |
fb6261e9 JS |
46 | |
47 | bool BeginContextHelp(wxWindow* win); | |
48 | bool EndContextHelp(); | |
49 | ||
50 | bool EventLoop(); | |
51 | bool DispatchEvent(wxWindow* win, const wxPoint& pt); | |
52 | ||
53 | void SetStatus(bool status) { m_status = status; } | |
54 | ||
55 | protected: | |
fb6261e9 JS |
56 | bool m_inHelp; |
57 | bool m_status; // TRUE if the user left-clicked | |
bd83cb56 VZ |
58 | |
59 | private: | |
60 | DECLARE_DYNAMIC_CLASS(wxContextHelp) | |
fb6261e9 JS |
61 | }; |
62 | ||
ae500232 | 63 | #if wxUSE_BMPBUTTON |
fb6261e9 JS |
64 | /* |
65 | * wxContextHelpButton | |
66 | * You can add this to your dialogs (especially on non-Windows platforms) | |
67 | * to put the application into context help mode. | |
68 | */ | |
69 | ||
bd83cb56 | 70 | class WXDLLEXPORT wxContextHelpButton : public wxBitmapButton |
fb6261e9 JS |
71 | { |
72 | public: | |
bd83cb56 VZ |
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); | |
fb6261e9 JS |
78 | |
79 | void OnContextHelp(wxCommandEvent& event); | |
80 | ||
bd83cb56 | 81 | private: |
fc7a2a60 | 82 | DECLARE_DYNAMIC_CLASS_NO_COPY(wxContextHelpButton) |
fb6261e9 JS |
83 | DECLARE_EVENT_TABLE() |
84 | }; | |
85 | ||
ae500232 JS |
86 | #endif |
87 | ||
bd83cb56 VZ |
88 | // ---------------------------------------------------------------------------- |
89 | // classes used to implement context help support | |
90 | // ---------------------------------------------------------------------------- | |
91 | ||
5100cabf | 92 | // wxHelpProvider is an abstract class used by the program implementing context help to |
bd83cb56 VZ |
93 | // show the help text (or whatever: it may be HTML page or anything else) for |
94 | // the given window. | |
95 | // | |
96 | // The current help provider must be explicitly set by the application using | |
97 | // wxHelpProvider::Set(). | |
98 | class WXDLLEXPORT wxHelpProvider | |
99 | { | |
100 | public: | |
101 | // get/set the current (application-global) help provider (Set() returns | |
102 | // the previous one) | |
103 | static wxHelpProvider *Set(wxHelpProvider *helpProvider) | |
104 | { | |
105 | wxHelpProvider *helpProviderOld = ms_helpProvider; | |
106 | ms_helpProvider = helpProvider; | |
107 | return helpProviderOld; | |
108 | } | |
109 | ||
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; } | |
113 | ||
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; | |
118 | ||
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 | |
121 | // for this window | |
122 | virtual bool ShowHelp(wxWindowBase *window) = 0; | |
123 | ||
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); | |
128 | ||
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); | |
133 | ||
53e112a0 JS |
134 | // removes the association |
135 | virtual void RemoveHelp(wxWindowBase* window); | |
136 | ||
bd83cb56 VZ |
137 | // virtual dtor for any base class |
138 | virtual ~wxHelpProvider(); | |
139 | ||
140 | private: | |
141 | static wxHelpProvider *ms_helpProvider; | |
142 | }; | |
143 | ||
61fef19b VZ |
144 | WX_DECLARE_EXPORTED_HASH_MAP( long, wxString, wxIntegerHash, wxIntegerEqual, |
145 | wxLongToStringHashMap ); | |
ba8c1601 | 146 | |
bd83cb56 VZ |
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 | |
151 | { | |
152 | public: | |
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); | |
53e112a0 | 158 | virtual void RemoveHelp(wxWindowBase* window); |
bd83cb56 VZ |
159 | |
160 | protected: | |
161 | // we use 2 hashes for storing the help strings associated with windows | |
162 | // and the ids | |
ba8c1601 MB |
163 | wxLongToStringHashMap m_hashWindows, |
164 | m_hashIds; | |
bd83cb56 VZ |
165 | }; |
166 | ||
5100cabf JS |
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 | |
172 | { | |
173 | public: | |
174 | // Note that it doesn't own the help controller. The help controller | |
175 | // should be deleted separately. | |
176 | wxHelpControllerHelpProvider(wxHelpControllerBase* hc = (wxHelpControllerBase*) NULL); | |
177 | ||
178 | // implement wxHelpProvider methods | |
179 | virtual bool ShowHelp(wxWindowBase *window); | |
180 | ||
181 | // Other accessors | |
182 | void SetHelpController(wxHelpControllerBase* hc) { m_helpController = hc; } | |
183 | wxHelpControllerBase* GetHelpController() const { return m_helpController; } | |
184 | ||
185 | protected: | |
186 | wxHelpControllerBase* m_helpController; | |
22f3361e VZ |
187 | |
188 | DECLARE_NO_COPY_CLASS(wxHelpControllerHelpProvider) | |
5100cabf JS |
189 | }; |
190 | ||
191 | // Convenience function for turning context id into wxString | |
4e28924c | 192 | WXDLLEXPORT wxString wxContextId(int id); |
5100cabf | 193 | |
56029a74 VZ |
194 | #endif // wxUSE_HELP |
195 | ||
bd83cb56 VZ |
196 | #endif // _WX_CSHELPH__ |
197 |