1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Help system base classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "helpbase.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
27 #include "wx/helpbase.h"
32 IMPLEMENT_CLASS(wxHelpControllerBase
, wxObject
)
35 * Invokes context-sensitive help
38 // This class exists in order to eat events until the left mouse
40 class wxContextHelpEvtHandler
: public wxEvtHandler
43 wxContextHelpEvtHandler(wxContextHelp
* contextHelp
)
45 m_contextHelp
= contextHelp
;
48 virtual bool ProcessEvent(wxEvent
& event
);
51 wxContextHelp
* m_contextHelp
;
54 IMPLEMENT_DYNAMIC_CLASS(wxContextHelp
, wxObject
)
56 wxContextHelp
::wxContextHelp(wxWindow
* win
, bool beginHelp
)
61 BeginContextHelp(win
);
64 wxContextHelp
::~wxContextHelp()
70 // Begin 'context help mode'
71 bool wxContextHelp
::BeginContextHelp(wxWindow
* win
)
74 win
= wxTheApp
->GetTopWindow();
78 wxCursor
cursor(wxCURSOR_QUESTION_ARROW
);
79 wxCursor oldCursor
= win
->GetCursor();
80 win
->SetCursor(cursor
);
83 win
->PushEventHandler(new wxContextHelpEvtHandler(this));
91 win
->PopEventHandler(TRUE
);
93 win
->SetCursor(oldCursor
);
98 wxWindow
* winAtPtr
= wxFindWindowAtPointer(pt
);
100 DispatchEvent(winAtPtr
, pt
);
106 bool wxContextHelp
::EndContextHelp()
113 bool wxContextHelp
::EventLoop()
118 if (wxTheApp
->Pending())
120 wxTheApp
->Dispatch();
124 wxTheApp
->ProcessIdle();
130 bool wxContextHelpEvtHandler
::ProcessEvent(wxEvent
& event
)
132 switch (event
.GetEventType())
134 case wxEVT_LEFT_DOWN
:
136 wxMouseEvent
& mouseEvent
= (wxMouseEvent
&) event
;
137 m_contextHelp
->SetStatus(TRUE
);
138 m_contextHelp
->EndContextHelp();
145 case wxEVT_MOUSE_CAPTURE_CHANGED
:
147 m_contextHelp
->SetStatus(FALSE
);
148 m_contextHelp
->EndContextHelp();
153 case wxEVT_ERASE_BACKGROUND
:
164 // Dispatch the help event to the relevant window
165 bool wxContextHelp
::DispatchEvent(wxWindow
* win
, const wxPoint
& pt
)
167 wxWindow
* subjectOfHelp
= win
;
168 bool eventProcessed
= FALSE
;
169 while (subjectOfHelp
&& !eventProcessed
)
171 wxHelpEvent
helpEvent(wxEVT_HELP
, subjectOfHelp
->GetId(), pt
) ;
172 helpEvent
.SetEventObject(this);
173 eventProcessed
= win
->GetEventHandler()->ProcessEvent(helpEvent
);
175 // Go up the window hierarchy until the event is handled (or not).
176 // I.e. keep submitting ancestor windows until one is recognised
177 // by the app code that processes the ids and displays help.
178 subjectOfHelp
= subjectOfHelp
->GetParent();
180 return eventProcessed
;