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 // wxSetCursor(cursor);
86 win
->PushEventHandler(new wxContextHelpEvtHandler(this));
94 win
->PopEventHandler(TRUE
);
96 win
->SetCursor(oldCursor
);
101 wxWindow
* winAtPtr
= wxFindWindowAtPointer(pt
);
103 DispatchEvent(winAtPtr
, pt
);
109 bool wxContextHelp::EndContextHelp()
116 bool wxContextHelp::EventLoop()
121 if (wxTheApp
->Pending())
123 wxTheApp
->Dispatch();
127 wxTheApp
->ProcessIdle();
133 bool wxContextHelpEvtHandler::ProcessEvent(wxEvent
& event
)
135 switch (event
.GetEventType())
137 case wxEVT_LEFT_DOWN
:
139 //wxMouseEvent& mouseEvent = (wxMouseEvent&) event;
140 m_contextHelp
->SetStatus(TRUE
);
141 m_contextHelp
->EndContextHelp();
148 case wxEVT_MOUSE_CAPTURE_CHANGED
:
150 m_contextHelp
->SetStatus(FALSE
);
151 m_contextHelp
->EndContextHelp();
156 case wxEVT_ERASE_BACKGROUND
:
167 // Dispatch the help event to the relevant window
168 bool wxContextHelp::DispatchEvent(wxWindow
* win
, const wxPoint
& pt
)
170 wxWindow
* subjectOfHelp
= win
;
171 bool eventProcessed
= FALSE
;
172 while (subjectOfHelp
&& !eventProcessed
)
174 wxHelpEvent
helpEvent(wxEVT_HELP
, subjectOfHelp
->GetId(), pt
) ;
175 helpEvent
.SetEventObject(this);
176 eventProcessed
= win
->GetEventHandler()->ProcessEvent(helpEvent
);
178 // Go up the window hierarchy until the event is handled (or not).
179 // I.e. keep submitting ancestor windows until one is recognised
180 // by the app code that processes the ids and displays help.
181 subjectOfHelp
= subjectOfHelp
->GetParent();
183 return eventProcessed
;