]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: wx/cshelp.h | |
3 | // Purpose: Context-sensitive help support classes | |
4 | // Author: Julian Smart, Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 08/09/2000 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 2000 Julian Smart, Vadim Zeitlin | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_CSHELPH__ | |
13 | #define _WX_CSHELPH__ | |
14 | ||
15 | #ifdef __GNUG__ | |
16 | #pragma interface "cshelp.h" | |
17 | #endif | |
18 | ||
19 | #include "wx/defs.h" | |
20 | #include "wx/help.h" | |
21 | ||
22 | #if wxUSE_HELP | |
23 | ||
24 | #include "wx/bmpbuttn.h" | |
25 | ||
26 | // ---------------------------------------------------------------------------- | |
27 | // classes used to implement context help UI | |
28 | // ---------------------------------------------------------------------------- | |
29 | ||
30 | /* | |
31 | * wxContextHelp | |
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. | |
35 | */ | |
36 | ||
37 | class WXDLLEXPORT wxContextHelp : public wxObject | |
38 | { | |
39 | public: | |
40 | wxContextHelp(wxWindow* win = NULL, bool beginHelp = TRUE); | |
41 | virtual ~wxContextHelp(); | |
42 | ||
43 | bool BeginContextHelp(wxWindow* win); | |
44 | bool EndContextHelp(); | |
45 | ||
46 | bool EventLoop(); | |
47 | bool DispatchEvent(wxWindow* win, const wxPoint& pt); | |
48 | ||
49 | void SetStatus(bool status) { m_status = status; } | |
50 | ||
51 | protected: | |
52 | bool m_inHelp; | |
53 | bool m_status; // TRUE if the user left-clicked | |
54 | ||
55 | private: | |
56 | DECLARE_DYNAMIC_CLASS(wxContextHelp) | |
57 | }; | |
58 | ||
59 | /* | |
60 | * wxContextHelpButton | |
61 | * You can add this to your dialogs (especially on non-Windows platforms) | |
62 | * to put the application into context help mode. | |
63 | */ | |
64 | ||
65 | class WXDLLEXPORT wxContextHelpButton : public wxBitmapButton | |
66 | { | |
67 | public: | |
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); | |
73 | ||
74 | void OnContextHelp(wxCommandEvent& event); | |
75 | ||
76 | private: | |
77 | DECLARE_CLASS(wxContextHelpButton) | |
78 | DECLARE_EVENT_TABLE() | |
79 | }; | |
80 | ||
81 | #endif // wxUSE_HELP | |
82 | ||
83 | // ---------------------------------------------------------------------------- | |
84 | // classes used to implement context help support | |
85 | // ---------------------------------------------------------------------------- | |
86 | ||
87 | // wxHelpProvider is an abstract class used by the program implementing context help to | |
88 | // show the help text (or whatever: it may be HTML page or anything else) for | |
89 | // the given window. | |
90 | // | |
91 | // The current help provider must be explicitly set by the application using | |
92 | // wxHelpProvider::Set(). | |
93 | class WXDLLEXPORT wxHelpProvider | |
94 | { | |
95 | public: | |
96 | // get/set the current (application-global) help provider (Set() returns | |
97 | // the previous one) | |
98 | static wxHelpProvider *Set(wxHelpProvider *helpProvider) | |
99 | { | |
100 | wxHelpProvider *helpProviderOld = ms_helpProvider; | |
101 | ms_helpProvider = helpProvider; | |
102 | return helpProviderOld; | |
103 | } | |
104 | ||
105 | // unlike some other class, the help provider is not created on demand, | |
106 | // this must be explicitly done by the application | |
107 | static wxHelpProvider *Get() { return ms_helpProvider; } | |
108 | ||
109 | // get the help string (whose interpretation is help provider dependent | |
110 | // except that empty string always means that no help is associated with | |
111 | // the window) for this window | |
112 | virtual wxString GetHelp(const wxWindowBase *window) = 0; | |
113 | ||
114 | // do show help for the given window (uses GetHelp() internally if | |
115 | // applicable), return TRUE if it was done or FALSE if no help available | |
116 | // for this window | |
117 | virtual bool ShowHelp(wxWindowBase *window) = 0; | |
118 | ||
119 | // associate the text with the given window or id: although all help | |
120 | // providers have these functions to allow making wxWindow::SetHelpText() | |
121 | // work, not all of them implement them | |
122 | virtual void AddHelp(wxWindowBase *window, const wxString& text); | |
123 | ||
124 | // this version associates the given text with all window with this id | |
125 | // (may be used to set the same help string for all [Cancel] buttons in | |
126 | // the application, for example) | |
127 | virtual void AddHelp(wxWindowID id, const wxString& text); | |
128 | ||
129 | // virtual dtor for any base class | |
130 | virtual ~wxHelpProvider(); | |
131 | ||
132 | private: | |
133 | static wxHelpProvider *ms_helpProvider; | |
134 | }; | |
135 | ||
136 | // wxSimpleHelpProvider is an implementation of wxHelpProvider which supports | |
137 | // only plain text help strings and shows the string associated with the | |
138 | // control (if any) in a tooltip | |
139 | class WXDLLEXPORT wxSimpleHelpProvider : public wxHelpProvider | |
140 | { | |
141 | public: | |
142 | // implement wxHelpProvider methods | |
143 | virtual wxString GetHelp(const wxWindowBase *window); | |
144 | virtual bool ShowHelp(wxWindowBase *window); | |
145 | virtual void AddHelp(wxWindowBase *window, const wxString& text); | |
146 | virtual void AddHelp(wxWindowID id, const wxString& text); | |
147 | ||
148 | protected: | |
149 | // we use 2 hashes for storing the help strings associated with windows | |
150 | // and the ids | |
151 | wxStringHashTable m_hashWindows, | |
152 | m_hashIds; | |
153 | }; | |
154 | ||
155 | // wxHelpControllerHelpProvider is an implementation of wxHelpProvider which supports | |
156 | // both context identifiers and plain text help strings. If the help text is an integer, | |
157 | // it is passed to wxHelpController::DisplayContextPopup. Otherwise, it shows the string | |
158 | // in a tooltip as per wxSimpleHelpProvider. | |
159 | class WXDLLEXPORT wxHelpControllerHelpProvider : public wxSimpleHelpProvider | |
160 | { | |
161 | public: | |
162 | // Note that it doesn't own the help controller. The help controller | |
163 | // should be deleted separately. | |
164 | wxHelpControllerHelpProvider(wxHelpControllerBase* hc = (wxHelpControllerBase*) NULL); | |
165 | ||
166 | // implement wxHelpProvider methods | |
167 | virtual bool ShowHelp(wxWindowBase *window); | |
168 | ||
169 | // Other accessors | |
170 | void SetHelpController(wxHelpControllerBase* hc) { m_helpController = hc; } | |
171 | wxHelpControllerBase* GetHelpController() const { return m_helpController; } | |
172 | ||
173 | protected: | |
174 | wxHelpControllerBase* m_helpController; | |
175 | }; | |
176 | ||
177 | // Convenience function for turning context id into wxString | |
178 | wxString wxContextId(int id); | |
179 | ||
180 | #endif // _WX_CSHELPH__ | |
181 |