#include "wx/helpbase.h"
#include "wx/app.h"
-#ifdef __WXMSW__
-#include "wx/msw/private.h"
-#endif
-
#if wxUSE_HELP
IMPLEMENT_CLASS(wxHelpControllerBase, wxObject)
* Invokes context-sensitive help
*/
+// This class exists in order to eat events until the left mouse
+// button is pressed
+class wxContextHelpEvtHandler: public wxEvtHandler
+{
+public:
+ wxContextHelpEvtHandler(wxContextHelp* contextHelp)
+ {
+ m_contextHelp = contextHelp;
+ }
+
+ virtual bool ProcessEvent(wxEvent& event);
+
+//// Data
+ wxContextHelp* m_contextHelp;
+};
+
IMPLEMENT_DYNAMIC_CLASS(wxContextHelp, wxObject)
wxContextHelp::wxContextHelp(wxWindow* win, bool beginHelp)
EndContextHelp();
}
+// Begin 'context help mode'
bool wxContextHelp::BeginContextHelp(wxWindow* win)
{
if (!win)
return FALSE;
wxCursor cursor(wxCURSOR_QUESTION_ARROW);
- wxSetCursor(cursor);
+ wxCursor oldCursor = win->GetCursor();
+ win->SetCursor(cursor);
+
+#ifdef __WXMSW__
+ // wxSetCursor(cursor);
+#endif
+
+ win->PushEventHandler(new wxContextHelpEvtHandler(this));
win->CaptureMouse();
- EventLoop(cursor, win);
+ EventLoop();
win->ReleaseMouse();
+ win->PopEventHandler(TRUE);
+
+ win->SetCursor(oldCursor);
+
+ if (m_status)
+ {
+ wxPoint pt;
+ wxWindow* winAtPtr = wxFindWindowAtPointer(pt);
+ if (winAtPtr)
+ DispatchEvent(winAtPtr, pt);
+ }
+
return TRUE;
}
return TRUE;
}
-bool wxContextHelp::EventLoop(const wxCursor& cursor, wxWindow* win)
+bool wxContextHelp::EventLoop()
{
-#ifdef __WXMSW__
m_inHelp = TRUE;
while ( m_inHelp )
{
- MSG msg;
- if (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
+ if (wxTheApp->Pending())
{
- if (!ProcessHelpMessage((WXMSG*) & msg, cursor, win))
- {
- m_inHelp = FALSE;
- }
+ wxTheApp->Dispatch();
}
else
{
}
}
return TRUE;
-#else
- return FALSE;
-#endif
}
-#ifdef __WXMSW__
-bool wxContextHelp::ProcessHelpMessage(WXMSG* wxmsg, const wxCursor& cursor, wxWindow* winInQuestion)
+bool wxContextHelpEvtHandler::ProcessEvent(wxEvent& event)
{
- MSG& msg = * (MSG*) wxmsg;
-
- if (msg.message == WM_KEYDOWN || msg.wParam == VK_ESCAPE)
+ switch (event.GetEventType())
{
- PeekMessage(&msg, NULL, msg.message, msg.message, PM_REMOVE);
- return FALSE;
- }
-
- if (msg.message == WM_CAPTURECHANGED)
- {
- PeekMessage(&msg, NULL, msg.message, msg.message, PM_REMOVE);
- return FALSE;
- }
-
- if (msg.message == WM_ACTIVATE)
- {
- PeekMessage(&msg, NULL, msg.message, msg.message, PM_REMOVE);
- return FALSE;
- }
-
- if ((msg.message >= WM_MOUSEFIRST && msg.message <= WM_MOUSELAST))
-// || (msg.message >= WM_NCMOUSEFIRST && msg.message <= WM_NCMOUSELAST))
- {
- wxSetCursor(cursor);
-
- HWND hWndHit = ::WindowFromPoint(msg.pt);
-
- wxWindow* win = wxFindWinFromHandle((WXHWND) hWndHit) ;
- HWND hWnd = hWndHit;
-
- // Try to find a window with a wxWindow associated with it
- while (!win && (hWnd != 0))
+ case wxEVT_LEFT_DOWN:
{
- hWnd = ::GetParent(hWnd);
- win = wxFindWinFromHandle((WXHWND) hWnd) ;
+ //wxMouseEvent& mouseEvent = (wxMouseEvent&) event;
+ m_contextHelp->SetStatus(TRUE);
+ m_contextHelp->EndContextHelp();
+ return TRUE;
+ break;
}
-
- if (win)
+ case wxEVT_CHAR:
+ case wxEVT_KEY_DOWN:
+ case wxEVT_ACTIVATE:
+ case wxEVT_MOUSE_CAPTURE_CHANGED:
{
- // It's a wxWindows window
- if (msg.message != WM_LBUTTONDOWN)
- {
- // Hit one of our owned windows -- eat the message.
- PeekMessage(&msg, NULL, msg.message, msg.message, PM_REMOVE);
- return TRUE;
- }
- int iHit = (int)::SendMessage(hWndHit, WM_NCHITTEST, 0,
- MAKELONG(msg.pt.x, msg.pt.y));
- if (iHit == HTMENU || iHit == HTSYSMENU)
- {
- // Eat this message, send the event and return
- PeekMessage(&msg, NULL, msg.message, msg.message, PM_REMOVE);
- DispatchEvent(win, wxPoint(msg.pt.x, msg.pt.y));
- return FALSE;
- }
- else if (iHit == HTCLIENT)
- {
- PeekMessage(&msg, NULL, msg.message, msg.message, PM_REMOVE);
- DispatchEvent(win, wxPoint(msg.pt.x, msg.pt.y));
- return FALSE;
- }
- else
- {
- PeekMessage(&msg, NULL, msg.message, msg.message, PM_REMOVE);
- return FALSE;
- }
+ m_contextHelp->SetStatus(FALSE);
+ m_contextHelp->EndContextHelp();
+ return TRUE;
+ break;
}
- else
+ case wxEVT_PAINT:
+ case wxEVT_ERASE_BACKGROUND:
{
- // Someone else's message
- if (PeekMessage(&msg, NULL, msg.message, msg.message, PM_REMOVE))
- {
- ::TranslateMessage(&msg);
- ::DispatchMessage(&msg);
- }
- return TRUE;
+ event.Skip();
+ return FALSE;
+ break;
}
}
- else
- {
- // allow all other messages to go through (capture still set)
- if (PeekMessage(&msg, NULL, msg.message, msg.message, PM_REMOVE))
- DispatchMessage(&msg);
- return TRUE;
- }
return TRUE;
}
-#endif
// Dispatch the help event to the relevant window
bool wxContextHelp::DispatchEvent(wxWindow* win, const wxPoint& pt)
return eventProcessed;
}
-
#endif // wxUSE_HELP