]>
git.saurik.com Git - wxWidgets.git/blob - src/common/helpbase.cpp
2a1b47943c5e28a2d82c43e3a16dc170c097f95b
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"
30 #include "wx/msw/private.h"
35 IMPLEMENT_CLASS(wxHelpControllerBase
, wxObject
)
38 * Invokes context-sensitive help
41 IMPLEMENT_DYNAMIC_CLASS(wxContextHelp
, wxObject
)
43 wxContextHelp::wxContextHelp(wxWindow
* win
, bool beginHelp
)
48 BeginContextHelp(win
);
51 wxContextHelp::~wxContextHelp()
57 bool wxContextHelp::BeginContextHelp(wxWindow
* win
)
60 win
= wxTheApp
->GetTopWindow();
64 wxCursor
cursor(wxCURSOR_QUESTION_ARROW
);
69 EventLoop(cursor
, win
);
76 bool wxContextHelp::EndContextHelp()
83 bool wxContextHelp::EventLoop(const wxCursor
& cursor
, wxWindow
* win
)
90 if (::PeekMessage(&msg
, NULL
, 0, 0, PM_NOREMOVE
))
92 if (!ProcessHelpMessage((WXMSG
*) & msg
, cursor
, win
))
99 wxTheApp
->ProcessIdle();
109 bool wxContextHelp::ProcessHelpMessage(WXMSG
* wxmsg
, const wxCursor
& cursor
, wxWindow
* winInQuestion
)
111 MSG
& msg
= * (MSG
*) wxmsg
;
113 if (msg
.message
== WM_KEYDOWN
|| msg
.wParam
== VK_ESCAPE
)
115 PeekMessage(&msg
, NULL
, msg
.message
, msg
.message
, PM_REMOVE
);
119 if (msg
.message
== WM_CAPTURECHANGED
)
121 PeekMessage(&msg
, NULL
, msg
.message
, msg
.message
, PM_REMOVE
);
125 if (msg
.message
== WM_ACTIVATE
)
127 PeekMessage(&msg
, NULL
, msg
.message
, msg
.message
, PM_REMOVE
);
131 if ((msg
.message
>= WM_MOUSEFIRST
&& msg
.message
<= WM_MOUSELAST
))
132 // || (msg.message >= WM_NCMOUSEFIRST && msg.message <= WM_NCMOUSELAST))
136 HWND hWndHit
= ::WindowFromPoint(msg
.pt
);
138 wxWindow
* win
= wxFindWinFromHandle((WXHWND
) hWndHit
) ;
141 // Try to find a window with a wxWindow associated with it
142 while (!win
&& (hWnd
!= 0))
144 hWnd
= ::GetParent(hWnd
);
145 win
= wxFindWinFromHandle((WXHWND
) hWnd
) ;
150 // It's a wxWindows window
151 if (msg
.message
!= WM_LBUTTONDOWN
)
153 // Hit one of our owned windows -- eat the message.
154 PeekMessage(&msg
, NULL
, msg
.message
, msg
.message
, PM_REMOVE
);
157 int iHit
= (int)::SendMessage(hWndHit
, WM_NCHITTEST
, 0,
158 MAKELONG(msg
.pt
.x
, msg
.pt
.y
));
159 if (iHit
== HTMENU
|| iHit
== HTSYSMENU
)
161 // Eat this message, send the event and return
162 PeekMessage(&msg
, NULL
, msg
.message
, msg
.message
, PM_REMOVE
);
163 DispatchEvent(win
, wxPoint(msg
.pt
.x
, msg
.pt
.y
));
166 else if (iHit
== HTCLIENT
)
168 PeekMessage(&msg
, NULL
, msg
.message
, msg
.message
, PM_REMOVE
);
169 DispatchEvent(win
, wxPoint(msg
.pt
.x
, msg
.pt
.y
));
174 PeekMessage(&msg
, NULL
, msg
.message
, msg
.message
, PM_REMOVE
);
180 // Someone else's message
181 if (PeekMessage(&msg
, NULL
, msg
.message
, msg
.message
, PM_REMOVE
))
183 ::TranslateMessage(&msg
);
184 ::DispatchMessage(&msg
);
191 // allow all other messages to go through (capture still set)
192 if (PeekMessage(&msg
, NULL
, msg
.message
, msg
.message
, PM_REMOVE
))
193 DispatchMessage(&msg
);
201 // Dispatch the help event to the relevant window
202 bool wxContextHelp::DispatchEvent(wxWindow
* win
, const wxPoint
& pt
)
204 wxWindow
* subjectOfHelp
= win
;
205 bool eventProcessed
= FALSE
;
206 while (subjectOfHelp
&& !eventProcessed
)
208 wxHelpEvent
helpEvent(wxEVT_HELP
, subjectOfHelp
->GetId(), pt
) ;
209 helpEvent
.SetEventObject(this);
210 eventProcessed
= win
->GetEventHandler()->ProcessEvent(helpEvent
);
212 // Go up the window hierarchy until the event is handled (or not).
213 // I.e. keep submitting ancestor windows until one is recognised
214 // by the app code that processes the ids and displays help.
215 subjectOfHelp
= subjectOfHelp
->GetParent();
217 return eventProcessed
;