]>
git.saurik.com Git - wxWidgets.git/blob - src/common/helpbase.cpp
1468954b39bdc0946db2d0dcea9472e493eef94b
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"
31 #include "wx/msw/private.h"
36 IMPLEMENT_CLASS(wxHelpControllerBase
, wxObject
)
39 * Invokes context-sensitive help
42 IMPLEMENT_DYNAMIC_CLASS(wxContextHelp
, wxObject
)
44 wxContextHelp::wxContextHelp(wxWindow
* win
, bool beginHelp
)
49 BeginContextHelp(win
);
52 wxContextHelp::~wxContextHelp()
58 bool wxContextHelp::BeginContextHelp(wxWindow
* win
)
61 win
= wxTheApp
->GetTopWindow();
65 wxCursor
cursor(wxCURSOR_QUESTION_ARROW
);
70 EventLoop(cursor
, win
);
77 bool wxContextHelp::EndContextHelp()
84 bool wxContextHelp::EventLoop(const wxCursor
& cursor
, wxWindow
* win
)
91 if (::PeekMessage(&msg
, NULL
, 0, 0, PM_NOREMOVE
))
93 if (!ProcessHelpMessage((WXMSG
*) & msg
, cursor
, win
))
100 wxTheApp
->ProcessIdle();
110 bool wxContextHelp::ProcessHelpMessage(WXMSG
* wxmsg
, const wxCursor
& cursor
, wxWindow
* winInQuestion
)
112 MSG
& msg
= * (MSG
*) wxmsg
;
114 if (msg
.message
== WM_KEYDOWN
|| msg
.wParam
== VK_ESCAPE
)
116 PeekMessage(&msg
, NULL
, msg
.message
, msg
.message
, PM_REMOVE
);
120 if (msg
.message
== WM_CAPTURECHANGED
)
122 PeekMessage(&msg
, NULL
, msg
.message
, msg
.message
, PM_REMOVE
);
126 if (msg
.message
== WM_ACTIVATE
)
128 PeekMessage(&msg
, NULL
, msg
.message
, msg
.message
, PM_REMOVE
);
132 if ((msg
.message
>= WM_MOUSEFIRST
&& msg
.message
<= WM_MOUSELAST
))
133 // || (msg.message >= WM_NCMOUSEFIRST && msg.message <= WM_NCMOUSELAST))
137 HWND hWndHit
= ::WindowFromPoint(msg
.pt
);
139 wxWindow
* win
= wxFindWinFromHandle((WXHWND
) hWndHit
) ;
142 // Try to find a window with a wxWindow associated with it
143 while (!win
&& (hWnd
!= 0))
145 hWnd
= ::GetParent(hWnd
);
146 win
= wxFindWinFromHandle((WXHWND
) hWnd
) ;
151 // It's a wxWindows window
152 if (msg
.message
!= WM_LBUTTONDOWN
)
154 // Hit one of our owned windows -- eat the message.
155 PeekMessage(&msg
, NULL
, msg
.message
, msg
.message
, PM_REMOVE
);
158 int iHit
= (int)::SendMessage(hWndHit
, WM_NCHITTEST
, 0,
159 MAKELONG(msg
.pt
.x
, msg
.pt
.y
));
160 if (iHit
== HTMENU
|| iHit
== HTSYSMENU
)
162 // Eat this message, send the event and return
163 PeekMessage(&msg
, NULL
, msg
.message
, msg
.message
, PM_REMOVE
);
164 DispatchEvent(win
, wxPoint(msg
.pt
.x
, msg
.pt
.y
));
167 else if (iHit
== HTCLIENT
)
169 PeekMessage(&msg
, NULL
, msg
.message
, msg
.message
, PM_REMOVE
);
170 DispatchEvent(win
, wxPoint(msg
.pt
.x
, msg
.pt
.y
));
175 PeekMessage(&msg
, NULL
, msg
.message
, msg
.message
, PM_REMOVE
);
181 // Someone else's message
182 if (PeekMessage(&msg
, NULL
, msg
.message
, msg
.message
, PM_REMOVE
))
184 ::TranslateMessage(&msg
);
185 ::DispatchMessage(&msg
);
192 // allow all other messages to go through (capture still set)
193 if (PeekMessage(&msg
, NULL
, msg
.message
, msg
.message
, PM_REMOVE
))
194 DispatchMessage(&msg
);
202 // Dispatch the help event to the relevant window
203 bool wxContextHelp::DispatchEvent(wxWindow
* win
, const wxPoint
& pt
)
205 wxWindow
* subjectOfHelp
= win
;
206 bool eventProcessed
= FALSE
;
207 while (subjectOfHelp
&& !eventProcessed
)
209 wxHelpEvent
helpEvent(wxEVT_HELP
, subjectOfHelp
->GetId(), pt
) ;
210 helpEvent
.SetEventObject(this);
211 eventProcessed
= win
->GetEventHandler()->ProcessEvent(helpEvent
);
213 // Go up the window hierarchy until the event is handled (or not).
214 // I.e. keep submitting ancestor windows until one is recognised
215 // by the app code that processes the ids and displays help.
216 subjectOfHelp
= subjectOfHelp
->GetParent();
218 return eventProcessed
;