1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/cshelp.cpp
3 // Purpose: Context sensitive help class implementation
4 // Author: Julian Smart, Vadim Zeitlin
8 // Copyright: (c) 2000 Julian Smart, Vadim Zeitlin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
17 #pragma implementation "cshelp.h"
20 // ----------------------------------------------------------------------------
22 // ----------------------------------------------------------------------------
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
34 // FIXME: temporary needed for wxSimpleHelpProvider compilation, to be
37 #include "wx/msgdlg.h"
42 #include "wx/cshelp.h"
44 // ----------------------------------------------------------------------------
45 // wxContextHelpEvtHandler private class
46 // ----------------------------------------------------------------------------
48 // This class exists in order to eat events until the left mouse button is
50 class wxContextHelpEvtHandler
: public wxEvtHandler
53 wxContextHelpEvtHandler(wxContextHelp
* contextHelp
)
55 m_contextHelp
= contextHelp
;
58 virtual bool ProcessEvent(wxEvent
& event
);
61 wxContextHelp
* m_contextHelp
;
64 // ============================================================================
66 // ============================================================================
68 // ----------------------------------------------------------------------------
70 // ----------------------------------------------------------------------------
73 * Invokes context-sensitive help
77 IMPLEMENT_DYNAMIC_CLASS(wxContextHelp
, wxObject
)
79 wxContextHelp::wxContextHelp(wxWindow
* win
, bool beginHelp
)
84 BeginContextHelp(win
);
87 wxContextHelp::~wxContextHelp()
93 // Begin 'context help mode'
94 bool wxContextHelp::BeginContextHelp(wxWindow
* win
)
97 win
= wxTheApp
->GetTopWindow();
101 wxCursor
cursor(wxCURSOR_QUESTION_ARROW
);
102 wxCursor oldCursor
= win
->GetCursor();
103 win
->SetCursor(cursor
);
106 // wxSetCursor(cursor);
109 win
->PushEventHandler(new wxContextHelpEvtHandler(this));
117 win
->PopEventHandler(TRUE
);
119 win
->SetCursor(oldCursor
);
124 wxWindow
* winAtPtr
= wxFindWindowAtPointer(pt
);
126 DispatchEvent(winAtPtr
, pt
);
132 bool wxContextHelp::EndContextHelp()
139 bool wxContextHelp::EventLoop()
144 if (wxTheApp
->Pending())
146 wxTheApp
->Dispatch();
150 wxTheApp
->ProcessIdle();
156 bool wxContextHelpEvtHandler::ProcessEvent(wxEvent
& event
)
158 switch (event
.GetEventType())
160 case wxEVT_LEFT_DOWN
:
162 //wxMouseEvent& mouseEvent = (wxMouseEvent&) event;
163 m_contextHelp
->SetStatus(TRUE
);
164 m_contextHelp
->EndContextHelp();
171 case wxEVT_MOUSE_CAPTURE_CHANGED
:
173 m_contextHelp
->SetStatus(FALSE
);
174 m_contextHelp
->EndContextHelp();
179 case wxEVT_ERASE_BACKGROUND
:
190 // Dispatch the help event to the relevant window
191 bool wxContextHelp::DispatchEvent(wxWindow
* win
, const wxPoint
& pt
)
193 wxWindow
* subjectOfHelp
= win
;
194 bool eventProcessed
= FALSE
;
195 while (subjectOfHelp
&& !eventProcessed
)
197 wxHelpEvent
helpEvent(wxEVT_HELP
, subjectOfHelp
->GetId(), pt
) ;
198 helpEvent
.SetEventObject(this);
199 eventProcessed
= win
->GetEventHandler()->ProcessEvent(helpEvent
);
201 // Go up the window hierarchy until the event is handled (or not).
202 // I.e. keep submitting ancestor windows until one is recognised
203 // by the app code that processes the ids and displays help.
204 subjectOfHelp
= subjectOfHelp
->GetParent();
206 return eventProcessed
;
209 // ----------------------------------------------------------------------------
210 // wxContextHelpButton
211 // ----------------------------------------------------------------------------
214 * wxContextHelpButton
215 * You can add this to your dialogs (especially on non-Windows platforms)
216 * to put the application into context help mode.
219 #if !defined(__WXMSW__)
220 static char * csquery_xpm
[] = {
237 IMPLEMENT_CLASS(wxContextHelpButton
, wxBitmapButton
)
239 BEGIN_EVENT_TABLE(wxContextHelpButton
, wxBitmapButton
)
240 EVT_BUTTON(wxID_CONTEXT_HELP
, wxContextHelpButton::OnContextHelp
)
243 wxContextHelpButton::wxContextHelpButton(wxWindow
* parent
,
248 : wxBitmapButton(parent
, id
, wxBITMAP(csquery
),
253 void wxContextHelpButton::OnContextHelp(wxCommandEvent
& event
)
255 wxContextHelp
contextHelp(GetParent());
258 // ----------------------------------------------------------------------------
260 // ----------------------------------------------------------------------------
262 wxHelpProvider
*wxHelpProvider::ms_helpProvider
= (wxHelpProvider
*)NULL
;
264 // trivial implementation of some methods which we don't want to make pure
265 // virtual for convenience
267 void wxHelpProvider::AddHelp(wxWindowBase
* WXUNUSED(window
),
268 const wxString
& WXUNUSED(text
))
272 void wxHelpProvider::AddHelp(wxWindowID
WXUNUSED(id
),
273 const wxString
& WXUNUSED(text
))
277 wxHelpProvider::~wxHelpProvider()
281 // ----------------------------------------------------------------------------
282 // wxSimpleHelpProvider
283 // ----------------------------------------------------------------------------
285 wxString
wxSimpleHelpProvider::GetHelp(const wxWindowBase
*window
)
288 wxString text
= m_hashWindows
.Get((long)window
, &wasFound
);
290 text
= m_hashIds
.Get(window
->GetId());
295 void wxSimpleHelpProvider::AddHelp(wxWindowBase
*window
, const wxString
& text
)
297 m_hashWindows
.Put((long)window
, text
);
300 void wxSimpleHelpProvider::AddHelp(wxWindowID id
, const wxString
& text
)
302 m_hashIds
.Put(id
, text
);
305 bool wxSimpleHelpProvider::ShowHelp(wxWindowBase
*window
)
307 wxString text
= GetHelp(window
);
310 wxMessageBox(text
, _("Help"), wxICON_INFORMATION
| wxOK
,