1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mgl/window.cpp
4 // Author: Vaclav Slavik
5 // (based on GTK & MSW implementations)
7 // Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ===========================================================================
13 // ===========================================================================
15 // ---------------------------------------------------------------------------
17 // ---------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
27 #include "wx/window.h"
28 #include "wx/msgdlg.h"
32 #include "wx/dcclient.h"
38 #if wxUSE_DRAG_AND_DROP
43 #include "wx/sysopt.h"
44 #include "wx/mgl/private.h"
46 #include "wx/dcscreen.h"
52 #include "wx/tooltip.h"
55 // ---------------------------------------------------------------------------
57 // ---------------------------------------------------------------------------
59 // MGL window manager and associated DC.
60 winmng_t
*g_winMng
= NULL
;
61 MGLDevCtx
*g_displayDC
= NULL
;
63 // the window that has keyboard focus:
64 static wxWindowMGL
*gs_focusedWindow
= NULL
;
65 // the window that is about to be focused after currently focused
67 static wxWindow
*gs_toBeFocusedWindow
= NULL
;
68 // the window that is currently under mouse cursor:
69 static wxWindowMGL
*gs_windowUnderMouse
= NULL
;
70 // the window that has mouse capture
71 static wxWindowMGL
*gs_mouseCapture
= NULL
;
72 // the frame that is currently active (i.e. its child has focus). It is
73 // used to generate wxActivateEvents
74 static wxWindowMGL
*gs_activeFrame
= NULL
;
76 // ---------------------------------------------------------------------------
78 // ---------------------------------------------------------------------------
80 // Custom identifiers used to distinguish between various event handlers
81 // and capture handlers passed to MGL_wm
84 wxMGL_CAPTURE_MOUSE
= 1,
85 wxMGL_CAPTURE_KEYB
= 2
89 // ---------------------------------------------------------------------------
91 // ---------------------------------------------------------------------------
93 // Returns toplevel grandparent of given window:
94 static wxWindowMGL
* wxGetTopLevelParent(wxWindowMGL
*win
)
97 while (p
&& !p
->IsTopLevel())
102 // An easy way to capture screenshots:
103 static void wxCaptureScreenshot(bool activeWindowOnly
)
106 #define SCREENSHOT_FILENAME _T("sshot%03i.png")
108 #define SCREENSHOT_FILENAME _T("screenshot-%03i.png")
110 static int screenshot_num
= 0;
115 screenshot
.Printf(SCREENSHOT_FILENAME
, screenshot_num
++);
116 } while ( wxFileExists(screenshot
) && screenshot_num
< 1000 );
118 wxRect
r(0, 0, g_displayDC
->sizex(), g_displayDC
->sizey());
120 if ( activeWindowOnly
&& gs_activeFrame
)
122 r
.Intersect(gs_activeFrame
->GetRect());
125 g_displayDC
->savePNGFromDC(screenshot
.mb_str(),
126 r
.x
, r
. y
, r
.x
+r
.width
, r
.y
+r
.height
);
128 wxMessageBox(wxString::Format(_T("Screenshot captured: %s"),
129 screenshot
.c_str()));
132 // ---------------------------------------------------------------------------
134 // ---------------------------------------------------------------------------
136 static void MGLAPI
wxWindowPainter(window_t
*wnd
, MGLDC
*dc
)
138 wxWindowMGL
*w
= (wxWindow
*) wnd
->userData
;
140 if ( w
&& !(w
->GetWindowStyle() & wxTRANSPARENT_WINDOW
) )
143 w
->HandlePaint(&ctx
);
147 static ibool MGLAPI
wxWindowMouseHandler(window_t
*wnd
, event_t
*e
)
149 wxWindowMGL
*win
= (wxWindowMGL
*)MGL_wmGetWindowUserData(wnd
);
150 wxPoint
orig(win
->GetClientAreaOrigin());
153 MGL_wmCoordGlobalToLocal(win
->GetHandle(),
154 e
->where_x
, e
->where_y
, &where
.x
, &where
.y
);
156 for (wxWindowMGL
*w
= win
; w
; w
= w
->GetParent())
158 if ( !w
->IsEnabled() )
160 if ( w
->IsTopLevel() )
164 wxEventType type
= wxEVT_NULL
;
166 event
.SetEventObject(win
);
167 event
.SetTimestamp(e
->when
);
168 event
.m_x
= where
.x
- orig
.x
;
169 event
.m_y
= where
.y
- orig
.y
;
170 event
.m_shiftDown
= ( e
->modifiers
& EVT_SHIFTKEY
) == EVT_SHIFTKEY
;
171 event
.m_controlDown
= ( e
->modifiers
& EVT_CTRLSTATE
) == EVT_CTRLSTATE
;
172 event
.m_altDown
= ( e
->modifiers
& EVT_LEFTALT
) == EVT_LEFTALT
;
173 event
.m_metaDown
= ( e
->modifiers
& EVT_RIGHTALT
) == EVT_RIGHTALT
;
174 event
.m_leftDown
= ( e
->modifiers
& EVT_LEFTBUT
) == EVT_LEFTBUT
;
175 event
.m_middleDown
= ( e
->modifiers
& EVT_MIDDLEBUT
) == EVT_MIDDLEBUT
;
176 event
.m_rightDown
= ( e
->modifiers
& EVT_RIGHTBUT
) == EVT_RIGHTBUT
;
181 // Change focus if the user clicks outside focused window:
182 if ( win
->AcceptsFocus() && wxWindow::FindFocus() != win
)
185 if ( e
->message
& EVT_DBLCLICK
)
187 if ( e
->message
& EVT_LEFTBMASK
)
188 type
= wxEVT_LEFT_DCLICK
;
189 else if ( e
->message
& EVT_MIDDLEBMASK
)
190 type
= wxEVT_MIDDLE_DCLICK
;
191 else if ( e
->message
& EVT_RIGHTBMASK
)
192 type
= wxEVT_RIGHT_DCLICK
;
196 if ( e
->message
& EVT_LEFTBMASK
)
197 type
= wxEVT_LEFT_DOWN
;
198 else if ( e
->message
& EVT_MIDDLEBMASK
)
199 type
= wxEVT_MIDDLE_DOWN
;
200 else if ( e
->message
& EVT_RIGHTBMASK
)
201 type
= wxEVT_RIGHT_DOWN
;
207 if ( e
->message
& EVT_LEFTBMASK
)
208 type
= wxEVT_LEFT_UP
;
209 else if ( e
->message
& EVT_MIDDLEBMASK
)
210 type
= wxEVT_MIDDLE_UP
;
211 else if ( e
->message
& EVT_RIGHTBMASK
)
212 type
= wxEVT_RIGHT_UP
;
216 if ( !gs_mouseCapture
)
218 if ( win
!= gs_windowUnderMouse
)
220 if ( gs_windowUnderMouse
)
222 wxMouseEvent
event2(event
);
223 MGL_wmCoordGlobalToLocal(gs_windowUnderMouse
->GetHandle(),
224 e
->where_x
, e
->where_y
,
225 &event2
.m_x
, &event2
.m_y
);
227 wxPoint
orig(gs_windowUnderMouse
->GetClientAreaOrigin());
228 event2
.m_x
-= orig
.x
;
229 event2
.m_y
-= orig
.y
;
231 event2
.SetEventObject(gs_windowUnderMouse
);
232 event2
.SetEventType(wxEVT_LEAVE_WINDOW
);
233 gs_windowUnderMouse
->GetEventHandler()->ProcessEvent(event2
);
236 wxMouseEvent
event3(event
);
237 event3
.SetEventType(wxEVT_ENTER_WINDOW
);
238 win
->GetEventHandler()->ProcessEvent(event3
);
240 gs_windowUnderMouse
= win
;
243 else // gs_mouseCapture
245 bool inside
= (where
.x
>= 0 &&
247 where
.x
< win
->GetSize().x
&&
248 where
.y
< win
->GetSize().y
);
249 if ( (inside
&& gs_windowUnderMouse
!= win
) ||
250 (!inside
&& gs_windowUnderMouse
== win
) )
252 wxMouseEvent
evt(inside
?
253 wxEVT_ENTER_WINDOW
: wxEVT_LEAVE_WINDOW
);
254 evt
.SetEventObject(win
);
255 win
->GetEventHandler()->ProcessEvent(evt
);
256 gs_windowUnderMouse
= inside
? win
: NULL
;
267 if ( type
== wxEVT_NULL
)
273 event
.SetEventType(type
);
274 return win
->GetEventHandler()->ProcessEvent(event
);
278 static long wxScanToKeyCode(event_t
*event
, bool translate
)
280 // VS: make it __WXDEBUG__-only, since we have lots of wxLogTrace calls
281 // here and the arguments would be stored in non-debug executable even
282 // though wxLogTrace would be no-op...
284 #define KEY(mgl_key,wx_key) \
286 wxLogTrace(_T("keyevents"), \
287 _T("key " #mgl_key ", mapped to " #wx_key)); \
291 #define KEY(mgl_key,wx_key) \
292 case mgl_key: key = wx_key; break;
299 switch ( EVT_scanCode(event
->message
) )
301 KEY (KB_padMinus
, WXK_NUMPAD_SUBTRACT
)
302 KEY (KB_padPlus
, WXK_NUMPAD_ADD
)
303 KEY (KB_padTimes
, WXK_NUMPAD_MULTIPLY
)
304 KEY (KB_padDivide
, WXK_NUMPAD_DIVIDE
)
305 KEY (KB_padCenter
, WXK_NUMPAD_SEPARATOR
) // ?
306 KEY (KB_padLeft
, WXK_NUMPAD_LEFT
)
307 KEY (KB_padRight
, WXK_NUMPAD_RIGHT
)
308 KEY (KB_padUp
, WXK_NUMPAD_UP
)
309 KEY (KB_padDown
, WXK_NUMPAD_DOWN
)
310 KEY (KB_padInsert
, WXK_NUMPAD_INSERT
)
311 KEY (KB_padDelete
, WXK_NUMPAD_DELETE
)
312 KEY (KB_padHome
, WXK_NUMPAD_HOME
)
313 KEY (KB_padEnd
, WXK_NUMPAD_END
)
314 KEY (KB_padPageUp
, WXK_NUMPAD_PAGEUP
)
315 //KEY (KB_padPageUp, WXK_NUMPAD_PRIOR)
316 KEY (KB_padPageDown
, WXK_NUMPAD_PAGEDOWN
)
317 //KEY (KB_padPageDown, WXK_NUMPAD_NEXT)
328 KEY (KB_minus
, WXK_SUBTRACT
)
329 KEY (KB_equals
, WXK_ADD
)
330 KEY (KB_backSlash
, '\\')
341 KEY (KB_leftSquareBrace
,'[')
342 KEY (KB_rightSquareBrace
,']')
352 KEY (KB_semicolon
, ';')
353 KEY (KB_apostrophe
, '\'')
363 KEY (KB_divide
, WXK_DIVIDE
)
364 KEY (KB_space
, WXK_SPACE
)
373 switch ( EVT_scanCode(event
->message
) )
375 KEY (KB_padEnter
, WXK_NUMPAD_ENTER
)
385 KEY (KB_F10
, WXK_F10
)
386 KEY (KB_F11
, WXK_F11
)
387 KEY (KB_F12
, WXK_F12
)
388 KEY (KB_left
, WXK_LEFT
)
389 KEY (KB_right
, WXK_RIGHT
)
391 KEY (KB_down
, WXK_DOWN
)
392 KEY (KB_insert
, WXK_INSERT
)
393 KEY (KB_delete
, WXK_DELETE
)
394 KEY (KB_home
, WXK_HOME
)
395 KEY (KB_end
, WXK_END
)
396 KEY (KB_pageUp
, WXK_PAGEUP
)
397 KEY (KB_pageDown
, WXK_PAGEDOWN
)
398 KEY (KB_capsLock
, WXK_CAPITAL
)
399 KEY (KB_numLock
, WXK_NUMLOCK
)
400 KEY (KB_scrollLock
, WXK_SCROLL
)
401 KEY (KB_leftShift
, WXK_SHIFT
)
402 KEY (KB_rightShift
, WXK_SHIFT
)
403 KEY (KB_leftCtrl
, WXK_CONTROL
)
404 KEY (KB_rightCtrl
, WXK_CONTROL
)
405 KEY (KB_leftAlt
, WXK_ALT
)
406 KEY (KB_rightAlt
, WXK_ALT
)
407 KEY (KB_leftWindows
, WXK_START
)
408 KEY (KB_rightWindows
, WXK_START
)
409 KEY (KB_menu
, WXK_MENU
)
410 KEY (KB_sysReq
, WXK_SNAPSHOT
)
411 KEY (KB_esc
, WXK_ESCAPE
)
412 KEY (KB_backspace
, WXK_BACK
)
413 KEY (KB_tab
, WXK_TAB
)
414 KEY (KB_enter
, WXK_RETURN
)
417 key
= EVT_asciiCode(event
->message
);
427 static bool wxHandleSpecialKeys(wxKeyEvent
& event
)
429 // Add an easy way to capture screenshots:
430 if ( event
.m_keyCode
== WXK_SNAPSHOT
431 #ifdef __WXDEBUG__ // FIXME_MGL - remove when KB_sysReq works in MGL!
432 || (event
.m_keyCode
== WXK_F1
&&
433 event
.m_shiftDown
&& event
.m_controlDown
)
437 wxCaptureScreenshot(event
.m_altDown
/*only active wnd?*/);
444 static ibool MGLAPI
wxWindowKeybHandler(window_t
*wnd
, event_t
*e
)
446 wxWindowMGL
*win
= (wxWindowMGL
*)MGL_wmGetWindowUserData(wnd
);
448 if ( !win
->IsEnabled() ) return FALSE
;
451 MGL_wmCoordGlobalToLocal(win
->GetHandle(),
452 e
->where_x
, e
->where_y
, &where
.x
, &where
.y
);
455 event
.SetEventObject(win
);
456 event
.SetTimestamp(e
->when
);
457 event
.m_keyCode
= wxScanToKeyCode(e
, true);
458 event
.m_scanCode
= 0; // not used by wx at all
461 event
.m_shiftDown
= ( e
->modifiers
& EVT_SHIFTKEY
) == EVT_SHIFTKEY
;
462 event
.m_controlDown
= ( e
->modifiers
& EVT_CTRLSTATE
) == EVT_CTRLSTATE
;
463 event
.m_altDown
= ( e
->modifiers
& EVT_LEFTALT
) == EVT_LEFTALT
;
464 event
.m_metaDown
= ( e
->modifiers
& EVT_RIGHTALT
) == EVT_RIGHTALT
;
466 if ( e
->what
== EVT_KEYUP
)
468 event
.SetEventType(wxEVT_KEY_UP
);
469 return win
->GetEventHandler()->ProcessEvent(event
);
476 event
.SetEventType(wxEVT_KEY_DOWN
);
479 ret
= win
->GetEventHandler()->ProcessEvent(event
);
481 // wxMSW doesn't send char events with Alt pressed
482 // Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x
483 // will only be sent if it is not in an accelerator table:
484 event2
.m_keyCode
= wxScanToKeyCode(e
, false);
485 if ( !ret
&& event2
.m_keyCode
!= 0 )
487 event2
.SetEventType(wxEVT_CHAR
);
488 ret
= win
->GetEventHandler()->ProcessEvent(event2
);
491 // Synthetize navigation key event, but do it only if the TAB key
492 // wasn't handled yet:
493 if ( !ret
&& event
.m_keyCode
== WXK_TAB
&&
494 win
->GetParent() && win
->GetParent()->HasFlag(wxTAB_TRAVERSAL
) )
496 wxNavigationKeyEvent navEvent
;
497 navEvent
.SetEventObject(win
->GetParent());
498 // Shift-TAB goes in reverse direction:
499 navEvent
.SetDirection(!event
.m_shiftDown
);
500 // Ctrl-TAB changes the (parent) window, i.e. switch notebook page:
501 navEvent
.SetWindowChange(event
.m_controlDown
);
502 navEvent
.SetCurrentFocus(wxStaticCast(win
, wxWindow
));
503 ret
= win
->GetParent()->GetEventHandler()->ProcessEvent(navEvent
);
506 // Finally, process special meaning keys that are usually
507 // a responsibility of OS or window manager:
509 ret
= wxHandleSpecialKeys(event
);
515 // ---------------------------------------------------------------------------
517 // ---------------------------------------------------------------------------
519 // in wxUniv this class is abstract because it doesn't have DoPopupMenu()
520 IMPLEMENT_ABSTRACT_CLASS(wxWindowMGL
, wxWindowBase
)
522 BEGIN_EVENT_TABLE(wxWindowMGL
, wxWindowBase
)
525 // ===========================================================================
527 // ===========================================================================
529 // ----------------------------------------------------------------------------
530 // constructors and such
531 // ----------------------------------------------------------------------------
533 extern wxVideoMode
wxGetDefaultDisplayMode();
535 void wxWindowMGL::Init()
537 // First of all, make sure window manager is up and running. If it is
538 // not the case, initialize it in default display mode
541 if ( !wxTheApp
->SetDisplayMode(wxGetDefaultDisplayMode()) )
542 wxLogFatalError(_("Cannot initialize display."));
550 m_eraseBackground
= -1;
554 wxWindowMGL::~wxWindowMGL()
558 m_isBeingDeleted
= true;
560 if ( gs_mouseCapture
== this )
563 if (gs_activeFrame
== this)
565 gs_activeFrame
= NULL
;
566 // activate next frame in Z-order:
569 wxWindowMGL
*win
= (wxWindowMGL
*)m_wnd
->prev
->userData
;
572 else if ( m_wnd
->next
)
574 wxWindowMGL
*win
= (wxWindowMGL
*)m_wnd
->next
->userData
;
579 if ( gs_focusedWindow
== this )
582 if ( gs_windowUnderMouse
== this )
583 gs_windowUnderMouse
= NULL
;
588 MGL_wmDestroyWindow(m_wnd
);
591 // real construction (Init() must have been called before!)
592 bool wxWindowMGL::Create(wxWindow
*parent
,
597 const wxString
& name
)
599 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
603 parent
->AddChild(this);
606 x
= pos
.x
, y
= pos
.y
;
608 x
= 0; // FIXME_MGL, something better, see GTK+
610 y
= 0; // FIXME_MGL, something better, see GTK+
611 AdjustForParentClientOrigin(x
, y
, 0);
612 w
= WidthDefault(size
.x
);
613 h
= HeightDefault(size
.y
);
616 window_t
*wnd_parent
= parent
? parent
->GetHandle() : NULL
;
618 if ( style
& wxFULL_REPAINT_ON_RESIZE
)
620 mgl_style
|= MGL_WM_FULL_REPAINT_ON_RESIZE
;
622 if ( style
& wxSTAY_ON_TOP
)
624 mgl_style
|= MGL_WM_ALWAYS_ON_TOP
;
626 if ( style
& wxPOPUP_WINDOW
)
628 mgl_style
|= MGL_WM_ALWAYS_ON_TOP
;
629 // it is created hidden as other top level windows
634 window_t
*wnd
= MGL_wmCreateWindow(g_winMng
, wnd_parent
, x
, y
, w
, h
);
636 MGL_wmSetWindowFlags(wnd
, mgl_style
);
637 MGL_wmShowWindow(wnd
, m_isShown
);
644 void wxWindowMGL::SetMGLwindow_t(struct window_t
*wnd
)
647 MGL_wmDestroyWindow(m_wnd
);
650 if ( !m_wnd
) return;
652 m_isShown
= (bool)m_wnd
->visible
;
654 MGL_wmSetWindowUserData(m_wnd
, (void*) this);
655 MGL_wmSetWindowPainter(m_wnd
, wxWindowPainter
);
656 MGL_wmPushWindowEventHandler(m_wnd
, wxWindowMouseHandler
, EVT_MOUSEEVT
, 0);
657 MGL_wmPushWindowEventHandler(m_wnd
, wxWindowKeybHandler
, EVT_KEYEVT
, 0);
660 MGL_wmSetWindowCursor(m_wnd
, *m_cursor
.GetMGLCursor());
662 MGL_wmSetWindowCursor(m_wnd
, *wxSTANDARD_CURSOR
->GetMGLCursor());
665 // ---------------------------------------------------------------------------
667 // ---------------------------------------------------------------------------
669 void wxWindowMGL::SetFocus()
671 if ( gs_focusedWindow
== this ) return;
673 wxWindowMGL
*oldFocusedWindow
= gs_focusedWindow
;
675 if ( gs_focusedWindow
)
677 gs_toBeFocusedWindow
= (wxWindow
*)this;
678 gs_focusedWindow
->KillFocus();
679 gs_toBeFocusedWindow
= NULL
;
682 gs_focusedWindow
= this;
684 MGL_wmCaptureEvents(GetHandle(), EVT_KEYEVT
, wxMGL_CAPTURE_KEYB
);
686 wxWindowMGL
*active
= wxGetTopLevelParent(this);
687 if ( !(m_windowStyle
& wxPOPUP_WINDOW
) && active
!= gs_activeFrame
)
689 if ( gs_activeFrame
)
691 wxActivateEvent
event(wxEVT_ACTIVATE
, false, gs_activeFrame
->GetId());
692 event
.SetEventObject(gs_activeFrame
);
693 gs_activeFrame
->GetEventHandler()->ProcessEvent(event
);
696 gs_activeFrame
= active
;
697 wxActivateEvent
event(wxEVT_ACTIVATE
, true, gs_activeFrame
->GetId());
698 event
.SetEventObject(gs_activeFrame
);
699 gs_activeFrame
->GetEventHandler()->ProcessEvent(event
);
702 wxFocusEvent
event(wxEVT_SET_FOCUS
, GetId());
703 event
.SetEventObject(this);
704 event
.SetWindow((wxWindow
*)oldFocusedWindow
);
705 GetEventHandler()->ProcessEvent(event
);
708 // caret needs to be informed about focus change
709 wxCaret
*caret
= GetCaret();
712 #endif // wxUSE_CARET
715 void wxWindowMGL::KillFocus()
717 if ( gs_focusedWindow
!= this ) return;
718 gs_focusedWindow
= NULL
;
720 if ( m_isBeingDeleted
) return;
722 MGL_wmUncaptureEvents(GetHandle(), wxMGL_CAPTURE_KEYB
);
725 // caret needs to be informed about focus change
726 wxCaret
*caret
= GetCaret();
728 caret
->OnKillFocus();
729 #endif // wxUSE_CARET
731 wxFocusEvent
event(wxEVT_KILL_FOCUS
, GetId());
732 event
.SetEventObject(this);
733 event
.SetWindow(gs_toBeFocusedWindow
);
734 GetEventHandler()->ProcessEvent(event
);
737 // ----------------------------------------------------------------------------
738 // this wxWindowBase function is implemented here (in platform-specific file)
739 // because it is static and so couldn't be made virtual
740 // ----------------------------------------------------------------------------
741 wxWindow
*wxWindowBase::DoFindFocus()
743 return (wxWindow
*)gs_focusedWindow
;
746 bool wxWindowMGL::Show(bool show
)
748 if ( !wxWindowBase::Show(show
) )
751 MGL_wmShowWindow(m_wnd
, show
);
753 if (!show
&& gs_activeFrame
== this)
755 // activate next frame in Z-order:
758 wxWindowMGL
*win
= (wxWindowMGL
*)m_wnd
->prev
->userData
;
761 else if ( m_wnd
->next
)
763 wxWindowMGL
*win
= (wxWindowMGL
*)m_wnd
->next
->userData
;
768 gs_activeFrame
= NULL
;
775 // Raise the window to the top of the Z order
776 void wxWindowMGL::Raise()
778 MGL_wmRaiseWindow(m_wnd
);
781 // Lower the window to the bottom of the Z order
782 void wxWindowMGL::Lower()
784 MGL_wmLowerWindow(m_wnd
);
787 void wxWindowMGL::DoCaptureMouse()
789 if ( gs_mouseCapture
)
790 MGL_wmUncaptureEvents(gs_mouseCapture
->m_wnd
, wxMGL_CAPTURE_MOUSE
);
792 gs_mouseCapture
= this;
793 MGL_wmCaptureEvents(m_wnd
, EVT_MOUSEEVT
, wxMGL_CAPTURE_MOUSE
);
796 void wxWindowMGL::DoReleaseMouse()
798 wxASSERT_MSG( gs_mouseCapture
== this, wxT("attempt to release mouse, but this window hasn't captured it") );
800 MGL_wmUncaptureEvents(m_wnd
, wxMGL_CAPTURE_MOUSE
);
801 gs_mouseCapture
= NULL
;
804 /* static */ wxWindow
*wxWindowBase::GetCapture()
806 return (wxWindow
*)gs_mouseCapture
;
809 bool wxWindowMGL::SetCursor(const wxCursor
& cursor
)
811 if ( !wxWindowBase::SetCursor(cursor
) )
818 MGL_wmSetWindowCursor(m_wnd
, *m_cursor
.GetMGLCursor());
820 MGL_wmSetWindowCursor(m_wnd
, *wxSTANDARD_CURSOR
->GetMGLCursor());
825 void wxWindowMGL::WarpPointer(int x
, int y
)
828 wxDisplaySize(&w
, &h
);
830 ClientToScreen(&x
, &y
);
840 EVT_setMousePos(x
, y
);
843 // Set this window to be the child of 'parent'.
844 bool wxWindowMGL::Reparent(wxWindowBase
*parent
)
846 if ( !wxWindowBase::Reparent(parent
) )
849 MGL_wmReparentWindow(m_wnd
, parent
->GetHandle());
855 // ---------------------------------------------------------------------------
857 // ---------------------------------------------------------------------------
859 #if wxUSE_DRAG_AND_DROP
861 void wxWindowMGL::SetDropTarget(wxDropTarget
*pDropTarget
)
863 if ( m_dropTarget
!= 0 ) {
864 m_dropTarget
->Revoke(m_hWnd
);
868 m_dropTarget
= pDropTarget
;
869 if ( m_dropTarget
!= 0 )
870 m_dropTarget
->Register(m_hWnd
);
873 #endif // wxUSE_DRAG_AND_DROP
875 // old style file-manager drag&drop support: we retain the old-style
876 // DragAcceptFiles in parallel with SetDropTarget.
877 void wxWindowMGL::DragAcceptFiles(bool WXUNUSED(accept
))
880 HWND hWnd
= GetHwnd();
882 ::DragAcceptFiles(hWnd
, (BOOL
)accept
);
886 // ---------------------------------------------------------------------------
887 // moving and resizing
888 // ---------------------------------------------------------------------------
891 void wxWindowMGL::DoGetSize(int *x
, int *y
) const
893 wxASSERT_MSG( m_wnd
, wxT("invalid window") );
895 if (x
) *x
= m_wnd
->width
;
896 if (y
) *y
= m_wnd
->height
;
899 void wxWindowMGL::DoGetPosition(int *x
, int *y
) const
901 wxASSERT_MSG( m_wnd
, wxT("invalid window") );
904 AdjustForParentClientOrigin(pX
, pY
, 0);
906 if (x
) *x
= m_wnd
->x
- pX
;
907 if (y
) *y
= m_wnd
->y
- pY
;
910 void wxWindowMGL::DoScreenToClient(int *x
, int *y
) const
913 MGL_wmCoordGlobalToLocal(m_wnd
, 0, 0, &ax
, &ay
);
920 void wxWindowMGL::DoClientToScreen(int *x
, int *y
) const
923 MGL_wmCoordLocalToGlobal(m_wnd
, 0, 0, &ax
, &ay
);
930 // Get size *available for subwindows* i.e. excluding menu bar etc.
931 void wxWindowMGL::DoGetClientSize(int *x
, int *y
) const
936 void wxWindowMGL::DoMoveWindow(int x
, int y
, int width
, int height
)
938 wxRect
rcClient(GetClientRect());
940 MGL_wmSetWindowPosition(m_wnd
, x
, y
, width
, height
);
942 // When the origin or a window stays fixed but the height or width
943 // changes, invalidate the old and new non-client areas
944 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) &&
945 m_wnd
->x
== x
&& m_wnd
->y
== y
&&
946 rcClient
.Intersect(GetClientRect()) != wxRect(0, 0, width
, height
) )
948 wxRegion
rgn(0, 0, width
, height
);
949 rgn
.Subtract(rcClient
);
951 // This should work I think, but doesn't seem to:
952 //MGL_wmInvalidateWindowRegion(m_wnd, rgn.GetMGLRegion().rgnPointer());
954 // Use MGL_wmInvalidateWindowRect instead:
955 for (wxRegionIterator
it(rgn
); it
; it
++)
960 rc
.right
= rc
.left
+ it
.GetW();
961 rc
.bottom
= rc
.top
+ it
.GetH();
962 MGL_wmInvalidateWindowRect(m_wnd
, &rc
);
967 // set the size of the window: if the dimensions are positive, just use them,
968 // but if any of them is equal to -1, it means that we must find the value for
969 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
970 // which case -1 is a valid value for x and y)
972 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
973 // the width/height to best suit our contents, otherwise we reuse the current
975 void wxWindowMGL::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
977 // get the current size and position...
978 int currentX
, currentY
;
979 GetPosition(¤tX
, ¤tY
);
980 int currentW
,currentH
;
981 GetSize(¤tW
, ¤tH
);
983 // ... and don't do anything (avoiding flicker) if it's already ok
984 if ( x
== currentX
&& y
== currentY
&&
985 width
== currentW
&& height
== currentH
)
990 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
992 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
995 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1000 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1002 size
= DoGetBestSize();
1007 // just take the current one
1014 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1018 size
= DoGetBestSize();
1020 //else: already called DoGetBestSize() above
1026 // just take the current one
1031 int maxWidth
= GetMaxWidth(),
1032 minWidth
= GetMinWidth(),
1033 maxHeight
= GetMaxHeight(),
1034 minHeight
= GetMinHeight();
1036 if ( minWidth
!= -1 && width
< minWidth
) width
= minWidth
;
1037 if ( maxWidth
!= -1 && width
> maxWidth
) width
= maxWidth
;
1038 if ( minHeight
!= -1 && height
< minHeight
) height
= minHeight
;
1039 if ( maxHeight
!= -1 && height
> maxHeight
) height
= maxHeight
;
1041 if ( m_wnd
->x
!= x
|| m_wnd
->y
!= y
||
1042 (int)m_wnd
->width
!= width
|| (int)m_wnd
->height
!= height
)
1044 DoMoveWindow(x
, y
, width
, height
);
1046 wxSize
newSize(width
, height
);
1047 wxSizeEvent
event(newSize
, GetId());
1048 event
.SetEventObject(this);
1049 GetEventHandler()->ProcessEvent(event
);
1053 void wxWindowMGL::DoSetClientSize(int width
, int height
)
1055 SetSize(width
, height
);
1058 // ---------------------------------------------------------------------------
1060 // ---------------------------------------------------------------------------
1062 int wxWindowMGL::GetCharHeight() const
1066 return dc
.GetCharHeight();
1069 int wxWindowMGL::GetCharWidth() const
1073 return dc
.GetCharWidth();
1076 void wxWindowMGL::GetTextExtent(const wxString
& string
,
1078 int *descent
, int *externalLeading
,
1079 const wxFont
*theFont
) const
1084 dc
.GetTextExtent(string
, x
, y
, descent
, externalLeading
, (wxFont
*)theFont
);
1088 // ---------------------------------------------------------------------------
1090 // ---------------------------------------------------------------------------
1092 void wxWindowMGL::Clear()
1094 wxClientDC
dc((wxWindow
*)this);
1095 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1096 dc
.SetBackground(brush
);
1100 #include "wx/menu.h"
1101 void wxWindowMGL::Refresh(bool eraseBack
, const wxRect
*rect
)
1103 if ( m_eraseBackground
== -1 )
1104 m_eraseBackground
= eraseBack
;
1106 m_eraseBackground
|= eraseBack
;
1111 r
.left
= rect
->GetLeft(), r
.right
= rect
->GetRight();
1112 r
.top
= rect
->GetTop(), r
.bottom
= rect
->GetBottom();
1113 MGL_wmInvalidateWindowRect(GetHandle(), &r
);
1116 MGL_wmInvalidateWindow(GetHandle());
1119 void wxWindowMGL::Update()
1122 MGL_wmUpdateDC(g_winMng
);
1125 void wxWindowMGL::Freeze()
1128 m_refreshAfterThaw
= false;
1131 void wxWindowMGL::Thaw()
1134 if ( m_refreshAfterThaw
)
1138 void wxWindowMGL::HandlePaint(MGLDevCtx
*dc
)
1142 // Don't paint anything if the window is frozen.
1143 m_refreshAfterThaw
= true;
1148 // FIXME_MGL -- debugging stuff, to be removed!
1149 static int debugPaintEvents
= -1;
1150 if ( debugPaintEvents
== -1 )
1151 debugPaintEvents
= wxGetEnv(wxT("WXMGL_DEBUG_PAINT_EVENTS"), NULL
);
1152 if ( debugPaintEvents
)
1154 dc
->setColorRGB(255,0,255);
1155 dc
->fillRect(-1000,-1000,2000,2000);
1161 dc
->getClipRegion(clip
);
1162 m_updateRegion
= wxRegion(clip
);
1166 // must hide caret temporarily, otherwise we'd get rendering artifacts
1167 wxCaret
*caret
= GetCaret();
1170 #endif // wxUSE_CARET
1172 if ( m_eraseBackground
!= 0 )
1174 wxWindowDC
dc((wxWindow
*)this);
1175 wxEraseEvent
eventEr(m_windowId
, &dc
);
1176 eventEr
.SetEventObject(this);
1177 GetEventHandler()->ProcessEvent(eventEr
);
1179 m_eraseBackground
= -1;
1181 wxNcPaintEvent
eventNc(GetId());
1182 eventNc
.SetEventObject(this);
1183 GetEventHandler()->ProcessEvent(eventNc
);
1185 wxPaintEvent
eventPt(GetId());
1186 eventPt
.SetEventObject(this);
1187 GetEventHandler()->ProcessEvent(eventPt
);
1192 #endif // wxUSE_CARET
1194 m_paintMGLDC
= NULL
;
1195 m_updateRegion
.Clear();
1199 // Find the wxWindow at the current mouse position, returning the mouse
1201 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1203 return wxFindWindowAtPoint(pt
= wxGetMousePosition());
1206 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
1208 window_t
*wnd
= MGL_wmGetWindowAtPosition(g_winMng
, pt
.x
, pt
.y
);
1209 return (wxWindow
*)wnd
->userData
;
1213 // ---------------------------------------------------------------------------
1214 // idle events processing
1215 // ---------------------------------------------------------------------------
1217 void wxWindowMGL::OnInternalIdle()
1219 if (wxUpdateUIEvent::CanUpdate(this))
1220 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);