1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Context sensitive help class implementation
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "cshelp.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
31 #include "wx/cshelp.h"
34 * Invokes context-sensitive help
37 // This class exists in order to eat events until the left mouse
39 class wxContextHelpEvtHandler
: public wxEvtHandler
42 wxContextHelpEvtHandler(wxContextHelp
* contextHelp
)
44 m_contextHelp
= contextHelp
;
47 virtual bool ProcessEvent(wxEvent
& event
);
50 wxContextHelp
* m_contextHelp
;
53 IMPLEMENT_DYNAMIC_CLASS(wxContextHelp
, wxObject
)
55 wxContextHelp::wxContextHelp(wxWindow
* win
, bool beginHelp
)
60 BeginContextHelp(win
);
63 wxContextHelp::~wxContextHelp()
69 // Begin 'context help mode'
70 bool wxContextHelp::BeginContextHelp(wxWindow
* win
)
73 win
= wxTheApp
->GetTopWindow();
77 wxCursor
cursor(wxCURSOR_QUESTION_ARROW
);
78 wxCursor oldCursor
= win
->GetCursor();
79 win
->SetCursor(cursor
);
82 // wxSetCursor(cursor);
85 win
->PushEventHandler(new wxContextHelpEvtHandler(this));
93 win
->PopEventHandler(TRUE
);
95 win
->SetCursor(oldCursor
);
100 wxWindow
* winAtPtr
= wxFindWindowAtPointer(pt
);
102 DispatchEvent(winAtPtr
, pt
);
108 bool wxContextHelp::EndContextHelp()
115 bool wxContextHelp::EventLoop()
120 if (wxTheApp
->Pending())
122 wxTheApp
->Dispatch();
126 wxTheApp
->ProcessIdle();
132 bool wxContextHelpEvtHandler::ProcessEvent(wxEvent
& event
)
134 switch (event
.GetEventType())
136 case wxEVT_LEFT_DOWN
:
138 //wxMouseEvent& mouseEvent = (wxMouseEvent&) event;
139 m_contextHelp
->SetStatus(TRUE
);
140 m_contextHelp
->EndContextHelp();
147 case wxEVT_MOUSE_CAPTURE_CHANGED
:
149 m_contextHelp
->SetStatus(FALSE
);
150 m_contextHelp
->EndContextHelp();
155 case wxEVT_ERASE_BACKGROUND
:
166 // Dispatch the help event to the relevant window
167 bool wxContextHelp::DispatchEvent(wxWindow
* win
, const wxPoint
& pt
)
169 wxWindow
* subjectOfHelp
= win
;
170 bool eventProcessed
= FALSE
;
171 while (subjectOfHelp
&& !eventProcessed
)
173 wxHelpEvent
helpEvent(wxEVT_HELP
, subjectOfHelp
->GetId(), pt
) ;
174 helpEvent
.SetEventObject(this);
175 eventProcessed
= win
->GetEventHandler()->ProcessEvent(helpEvent
);
177 // Go up the window hierarchy until the event is handled (or not).
178 // I.e. keep submitting ancestor windows until one is recognised
179 // by the app code that processes the ids and displays help.
180 subjectOfHelp
= subjectOfHelp
->GetParent();
182 return eventProcessed
;
186 * wxContextHelpButton
187 * You can add this to your dialogs (especially on non-Windows platforms)
188 * to put the application into context help mode.
191 #if !defined(__WXMSW__)
192 static char * csquery_xpm
[] = {
209 IMPLEMENT_CLASS(wxContextHelpButton
, wxBitmapButton
)
211 BEGIN_EVENT_TABLE(wxContextHelpButton
, wxBitmapButton
)
212 EVT_BUTTON(wxID_CONTEXT_HELP
, wxContextHelpButton::OnContextHelp
)
215 wxContextHelpButton::wxContextHelpButton(wxWindow
* parent
,
220 : wxBitmapButton(parent
, id
, wxBITMAP(csquery
),
225 void wxContextHelpButton::OnContextHelp(wxCommandEvent
& event
)
227 wxContextHelp
contextHelp(GetParent());