+ MGLDevCtx ctx(dc);
+ w->HandlePaint(&ctx);
+ }
+}
+
+static ibool MGLAPI wxWindowMouseHandler(window_t *wnd, event_t *e)
+{
+ wxWindowMGL *win = (wxWindowMGL*)MGL_wmGetWindowUserData(wnd);
+ wxPoint orig(win->GetClientAreaOrigin());
+ wxPoint where;
+
+ g_buttonState = e->modifiers;
+
+ MGL_wmCoordGlobalToLocal(win->GetHandle(),
+ e->where_x, e->where_y, &where.x, &where.y);
+
+ for (wxWindowMGL *w = win; w; w = w->GetParent())
+ {
+ if ( !w->IsEnabled() )
+ return FALSE;
+ if ( w->IsTopLevel() )
+ break;
+ }
+
+ wxEventType type = wxEVT_NULL;
+ wxMouseEvent event;
+ event.SetEventObject(win);
+ event.SetTimestamp(e->when);
+ event.m_x = where.x - orig.x;
+ event.m_y = where.y - orig.y;
+ event.m_shiftDown = ( e->modifiers & EVT_SHIFTKEY ) != 0;
+ event.m_controlDown = ( e->modifiers & EVT_CTRLSTATE ) != 0;
+ event.m_altDown = ( e->modifiers & EVT_LEFTALT ) != 0;
+ event.m_metaDown = ( e->modifiers & EVT_RIGHTALT ) != 0;
+ event.m_leftDown = ( e->modifiers & EVT_LEFTBUT ) != 0;
+ event.m_middleDown = ( e->modifiers & EVT_MIDDLEBUT ) != 0;
+ event.m_rightDown = ( e->modifiers & EVT_RIGHTBUT ) != 0;
+
+ switch (e->what)
+ {
+ case EVT_MOUSEDOWN:
+ // Change focus if the user clicks outside focused window:
+ if ( win->CanAcceptFocus() && wxWindow::FindFocus() != win )
+ win->SetFocus();
+
+ if ( e->message & EVT_DBLCLICK )
+ {
+ if ( e->message & EVT_LEFTBMASK )
+ type = wxEVT_LEFT_DCLICK;
+ else if ( e->message & EVT_MIDDLEBMASK )
+ type = wxEVT_MIDDLE_DCLICK;
+ else if ( e->message & EVT_RIGHTBMASK )
+ type = wxEVT_RIGHT_DCLICK;
+ }
+ else
+ {
+ if ( e->message & EVT_LEFTBMASK )
+ type = wxEVT_LEFT_DOWN;
+ else if ( e->message & EVT_MIDDLEBMASK )
+ type = wxEVT_MIDDLE_DOWN;
+ else if ( e->message & EVT_RIGHTBMASK )
+ type = wxEVT_RIGHT_DOWN;
+ }
+
+ break;
+
+ case EVT_MOUSEUP:
+ if ( e->message & EVT_LEFTBMASK )
+ type = wxEVT_LEFT_UP;
+ else if ( e->message & EVT_MIDDLEBMASK )
+ type = wxEVT_MIDDLE_UP;
+ else if ( e->message & EVT_RIGHTBMASK )
+ type = wxEVT_RIGHT_UP;
+ break;
+
+ case EVT_MOUSEMOVE:
+ if ( !gs_mouseCapture )
+ {
+ if ( win != gs_windowUnderMouse )
+ {
+ if ( gs_windowUnderMouse )
+ {
+ wxMouseEvent event2(event);
+ MGL_wmCoordGlobalToLocal(gs_windowUnderMouse->GetHandle(),
+ e->where_x, e->where_y,
+ &event2.m_x, &event2.m_y);
+
+ wxPoint orig(gs_windowUnderMouse->GetClientAreaOrigin());
+ event2.m_x -= orig.x;
+ event2.m_y -= orig.y;
+
+ event2.SetEventObject(gs_windowUnderMouse);
+ event2.SetEventType(wxEVT_LEAVE_WINDOW);
+ gs_windowUnderMouse->HandleWindowEvent(event2);
+ }
+
+ wxMouseEvent event3(event);
+ event3.SetEventType(wxEVT_ENTER_WINDOW);
+ win->HandleWindowEvent(event3);
+
+ gs_windowUnderMouse = win;
+ }
+ }
+ else // gs_mouseCapture
+ {
+ bool inside = (where.x >= 0 &&
+ where.y >= 0 &&
+ where.x < win->GetSize().x &&
+ where.y < win->GetSize().y);
+ if ( (inside && gs_windowUnderMouse != win) ||
+ (!inside && gs_windowUnderMouse == win) )
+ {
+ wxMouseEvent evt(inside ?
+ wxEVT_ENTER_WINDOW : wxEVT_LEAVE_WINDOW);
+ evt.SetEventObject(win);
+ win->HandleWindowEvent(evt);
+ gs_windowUnderMouse = inside ? win : NULL;
+ }
+ }
+
+ type = wxEVT_MOTION;
+ break;
+
+ default:
+ break;