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"
26 #include "wx/window.h"
29 #include "wx/msgdlg.h"
32 #include "wx/dcclient.h"
38 #include "wx/dcscreen.h"
42 #if wxUSE_DRAG_AND_DROP
46 #include "wx/sysopt.h"
47 #include "wx/mgl/private.h"
53 #include "wx/tooltip.h"
56 // ---------------------------------------------------------------------------
58 // ---------------------------------------------------------------------------
60 // MGL window manager and associated DC.
61 winmng_t
*g_winMng
= NULL
;
62 MGLDevCtx
*g_displayDC
= NULL
;
64 // the window that has keyboard focus:
65 static wxWindowMGL
*gs_focusedWindow
= NULL
;
66 // the window that is about to be focused after currently focused
68 static wxWindow
*gs_toBeFocusedWindow
= NULL
;
69 // the window that is currently under mouse cursor:
70 static wxWindowMGL
*gs_windowUnderMouse
= NULL
;
71 // the window that has mouse capture
72 static wxWindowMGL
*gs_mouseCapture
= NULL
;
73 // the frame that is currently active (i.e. its child has focus). It is
74 // used to generate wxActivateEvents
75 static wxWindowMGL
*gs_activeFrame
= NULL
;
77 // ---------------------------------------------------------------------------
79 // ---------------------------------------------------------------------------
81 // Custom identifiers used to distinguish between various event handlers
82 // and capture handlers passed to MGL_wm
85 wxMGL_CAPTURE_MOUSE
= 1,
86 wxMGL_CAPTURE_KEYB
= 2
90 // ---------------------------------------------------------------------------
92 // ---------------------------------------------------------------------------
94 // Returns toplevel grandparent of given window:
95 static wxWindowMGL
* wxGetTopLevelParent(wxWindowMGL
*win
)
98 while (p
&& !p
->IsTopLevel())
103 // An easy way to capture screenshots:
104 static void wxCaptureScreenshot(bool activeWindowOnly
)
107 #define SCREENSHOT_FILENAME _T("sshot%03i.png")
109 #define SCREENSHOT_FILENAME _T("screenshot-%03i.png")
111 static int screenshot_num
= 0;
116 screenshot
.Printf(SCREENSHOT_FILENAME
, screenshot_num
++);
117 } while ( wxFileExists(screenshot
) && screenshot_num
< 1000 );
119 wxRect
r(0, 0, g_displayDC
->sizex(), g_displayDC
->sizey());
121 if ( activeWindowOnly
&& gs_activeFrame
)
123 r
.Intersect(gs_activeFrame
->GetRect());
126 g_displayDC
->savePNGFromDC(screenshot
.mb_str(),
127 r
.x
, r
. y
, r
.x
+r
.width
, r
.y
+r
.height
);
129 wxMessageBox(wxString::Format(_T("Screenshot captured: %s"),
130 screenshot
.c_str()));
133 // ---------------------------------------------------------------------------
135 // ---------------------------------------------------------------------------
137 static void MGLAPI
wxWindowPainter(window_t
*wnd
, MGLDC
*dc
)
139 wxWindowMGL
*w
= (wxWindow
*) wnd
->userData
;
141 if ( w
&& !(w
->GetWindowStyle() & wxTRANSPARENT_WINDOW
) )
144 w
->HandlePaint(&ctx
);
148 static ibool MGLAPI
wxWindowMouseHandler(window_t
*wnd
, event_t
*e
)
150 wxWindowMGL
*win
= (wxWindowMGL
*)MGL_wmGetWindowUserData(wnd
);
151 wxPoint
orig(win
->GetClientAreaOrigin());
154 MGL_wmCoordGlobalToLocal(win
->GetHandle(),
155 e
->where_x
, e
->where_y
, &where
.x
, &where
.y
);
157 for (wxWindowMGL
*w
= win
; w
; w
= w
->GetParent())
159 if ( !w
->IsEnabled() )
161 if ( w
->IsTopLevel() )
165 wxEventType type
= wxEVT_NULL
;
167 event
.SetEventObject(win
);
168 event
.SetTimestamp(e
->when
);
169 event
.m_x
= where
.x
- orig
.x
;
170 event
.m_y
= where
.y
- orig
.y
;
171 event
.m_shiftDown
= ( e
->modifiers
& EVT_SHIFTKEY
) != 0;
172 event
.m_controlDown
= ( e
->modifiers
& EVT_CTRLSTATE
) != 0;
173 event
.m_altDown
= ( e
->modifiers
& EVT_LEFTALT
) != 0;
174 event
.m_metaDown
= ( e
->modifiers
& EVT_RIGHTALT
) != 0;
175 event
.m_leftDown
= ( e
->modifiers
& EVT_LEFTBUT
) != 0;
176 event
.m_middleDown
= ( e
->modifiers
& EVT_MIDDLEBUT
) != 0;
177 event
.m_rightDown
= ( e
->modifiers
& EVT_RIGHTBUT
) != 0;
182 // Change focus if the user clicks outside focused window:
183 if ( win
->AcceptsFocus() && wxWindow::FindFocus() != win
)
186 if ( e
->message
& EVT_DBLCLICK
)
188 if ( e
->message
& EVT_LEFTBMASK
)
189 type
= wxEVT_LEFT_DCLICK
;
190 else if ( e
->message
& EVT_MIDDLEBMASK
)
191 type
= wxEVT_MIDDLE_DCLICK
;
192 else if ( e
->message
& EVT_RIGHTBMASK
)
193 type
= wxEVT_RIGHT_DCLICK
;
197 if ( e
->message
& EVT_LEFTBMASK
)
198 type
= wxEVT_LEFT_DOWN
;
199 else if ( e
->message
& EVT_MIDDLEBMASK
)
200 type
= wxEVT_MIDDLE_DOWN
;
201 else if ( e
->message
& EVT_RIGHTBMASK
)
202 type
= wxEVT_RIGHT_DOWN
;
208 if ( e
->message
& EVT_LEFTBMASK
)
209 type
= wxEVT_LEFT_UP
;
210 else if ( e
->message
& EVT_MIDDLEBMASK
)
211 type
= wxEVT_MIDDLE_UP
;
212 else if ( e
->message
& EVT_RIGHTBMASK
)
213 type
= wxEVT_RIGHT_UP
;
217 if ( !gs_mouseCapture
)
219 if ( win
!= gs_windowUnderMouse
)
221 if ( gs_windowUnderMouse
)
223 wxMouseEvent
event2(event
);
224 MGL_wmCoordGlobalToLocal(gs_windowUnderMouse
->GetHandle(),
225 e
->where_x
, e
->where_y
,
226 &event2
.m_x
, &event2
.m_y
);
228 wxPoint
orig(gs_windowUnderMouse
->GetClientAreaOrigin());
229 event2
.m_x
-= orig
.x
;
230 event2
.m_y
-= orig
.y
;
232 event2
.SetEventObject(gs_windowUnderMouse
);
233 event2
.SetEventType(wxEVT_LEAVE_WINDOW
);
234 gs_windowUnderMouse
->GetEventHandler()->ProcessEvent(event2
);
237 wxMouseEvent
event3(event
);
238 event3
.SetEventType(wxEVT_ENTER_WINDOW
);
239 win
->GetEventHandler()->ProcessEvent(event3
);
241 gs_windowUnderMouse
= win
;
244 else // gs_mouseCapture
246 bool inside
= (where
.x
>= 0 &&
248 where
.x
< win
->GetSize().x
&&
249 where
.y
< win
->GetSize().y
);
250 if ( (inside
&& gs_windowUnderMouse
!= win
) ||
251 (!inside
&& gs_windowUnderMouse
== win
) )
253 wxMouseEvent
evt(inside
?
254 wxEVT_ENTER_WINDOW
: wxEVT_LEAVE_WINDOW
);
255 evt
.SetEventObject(win
);
256 win
->GetEventHandler()->ProcessEvent(evt
);
257 gs_windowUnderMouse
= inside
? win
: NULL
;
268 if ( type
== wxEVT_NULL
)
274 event
.SetEventType(type
);
275 return win
->GetEventHandler()->ProcessEvent(event
);
279 static long wxScanToKeyCode(event_t
*event
, bool translate
)
281 // VS: make it __WXDEBUG__-only, since we have lots of wxLogTrace calls
282 // here and the arguments would be stored in non-debug executable even
283 // though wxLogTrace would be no-op...
285 #define KEY(mgl_key,wx_key) \
287 wxLogTrace(_T("keyevents"), \
288 _T("key " #mgl_key ", mapped to " #wx_key)); \
292 #define KEY(mgl_key,wx_key) \
293 case mgl_key: key = wx_key; break;
300 bool numlock
= (event
->modifiers
& EVT_NUMLOCK
) != 0;
302 switch ( EVT_scanCode(event
->message
) )
304 KEY (KB_padMinus
, WXK_NUMPAD_SUBTRACT
)
305 KEY (KB_padPlus
, WXK_NUMPAD_ADD
)
306 KEY (KB_padTimes
, WXK_NUMPAD_MULTIPLY
)
307 KEY (KB_padDivide
, WXK_NUMPAD_DIVIDE
)
308 KEY (KB_padCenter
, numlock
? WXK_NUMPAD5
: WXK_NUMPAD_SEPARATOR
) // ?
309 KEY (KB_padLeft
, numlock
? WXK_NUMPAD4
: WXK_NUMPAD_LEFT
)
310 KEY (KB_padRight
, numlock
? WXK_NUMPAD6
: WXK_NUMPAD_RIGHT
)
311 KEY (KB_padUp
, numlock
? WXK_NUMPAD8
: WXK_NUMPAD_UP
)
312 KEY (KB_padDown
, numlock
? WXK_NUMPAD2
: WXK_NUMPAD_DOWN
)
313 KEY (KB_padInsert
, numlock
? WXK_NUMPAD0
: WXK_NUMPAD_INSERT
)
314 KEY (KB_padDelete
, numlock
? WXK_DECIMAL
: WXK_NUMPAD_DELETE
)
315 KEY (KB_padHome
, numlock
? WXK_NUMPAD7
: WXK_NUMPAD_HOME
)
316 KEY (KB_padEnd
, numlock
? WXK_NUMPAD1
: WXK_NUMPAD_END
)
317 KEY (KB_padPageUp
, numlock
? WXK_NUMPAD9
: WXK_NUMPAD_PAGEUP
)
318 KEY (KB_padPageDown
, numlock
? WXK_NUMPAD3
: WXK_NUMPAD_PAGEDOWN
)
329 KEY (KB_minus
, WXK_SUBTRACT
)
330 KEY (KB_equals
, WXK_ADD
)
331 KEY (KB_backSlash
, '\\')
342 KEY (KB_leftSquareBrace
,'[')
343 KEY (KB_rightSquareBrace
,']')
353 KEY (KB_semicolon
, ';')
354 KEY (KB_apostrophe
, '\'')
364 KEY (KB_divide
, WXK_DIVIDE
)
365 KEY (KB_space
, WXK_SPACE
)
374 switch ( EVT_scanCode(event
->message
) )
376 KEY (KB_padEnter
, WXK_NUMPAD_ENTER
)
386 KEY (KB_F10
, WXK_F10
)
387 KEY (KB_F11
, WXK_F11
)
388 KEY (KB_F12
, WXK_F12
)
389 KEY (KB_left
, WXK_LEFT
)
390 KEY (KB_right
, WXK_RIGHT
)
392 KEY (KB_down
, WXK_DOWN
)
393 KEY (KB_insert
, WXK_INSERT
)
394 KEY (KB_delete
, WXK_DELETE
)
395 KEY (KB_home
, WXK_HOME
)
396 KEY (KB_end
, WXK_END
)
397 KEY (KB_pageUp
, WXK_PAGEUP
)
398 KEY (KB_pageDown
, WXK_PAGEDOWN
)
399 KEY (KB_capsLock
, WXK_CAPITAL
)
400 KEY (KB_numLock
, WXK_NUMLOCK
)
401 KEY (KB_scrollLock
, WXK_SCROLL
)
402 KEY (KB_leftShift
, WXK_SHIFT
)
403 KEY (KB_rightShift
, WXK_SHIFT
)
404 KEY (KB_leftCtrl
, WXK_CONTROL
)
405 KEY (KB_rightCtrl
, WXK_CONTROL
)
406 KEY (KB_leftAlt
, WXK_ALT
)
407 KEY (KB_rightAlt
, WXK_ALT
)
408 KEY (KB_leftWindows
, WXK_START
)
409 KEY (KB_rightWindows
, WXK_START
)
410 KEY (KB_menu
, WXK_MENU
)
411 KEY (KB_sysReq
, WXK_SNAPSHOT
)
412 KEY (KB_esc
, WXK_ESCAPE
)
413 KEY (KB_backspace
, WXK_BACK
)
414 KEY (KB_tab
, WXK_TAB
)
415 KEY (KB_enter
, WXK_RETURN
)
418 key
= EVT_asciiCode(event
->message
);
428 static bool wxHandleSpecialKeys(wxKeyEvent
& event
)
430 // Add an easy way to capture screenshots:
431 if ( event
.m_keyCode
== WXK_SNAPSHOT
432 #ifdef __WXDEBUG__ // FIXME_MGL - remove when KB_sysReq works in MGL!
433 || (event
.m_keyCode
== WXK_F1
&&
434 event
.m_shiftDown
&& event
.m_controlDown
)
438 wxCaptureScreenshot(event
.m_altDown
/*only active wnd?*/);
445 static ibool MGLAPI
wxWindowKeybHandler(window_t
*wnd
, event_t
*e
)
447 wxWindowMGL
*win
= (wxWindowMGL
*)MGL_wmGetWindowUserData(wnd
);
449 if ( !win
->IsEnabled() ) return FALSE
;
452 MGL_wmCoordGlobalToLocal(win
->GetHandle(),
453 e
->where_x
, e
->where_y
, &where
.x
, &where
.y
);
456 event
.SetEventObject(win
);
457 event
.SetTimestamp(e
->when
);
458 event
.m_keyCode
= wxScanToKeyCode(e
, true);
459 event
.m_scanCode
= 0; // not used by wx at all
462 event
.m_shiftDown
= ( e
->modifiers
& EVT_SHIFTKEY
) != 0;
463 event
.m_controlDown
= ( e
->modifiers
& EVT_CTRLSTATE
) != 0;
464 event
.m_altDown
= ( e
->modifiers
& EVT_LEFTALT
) != 0;
465 event
.m_metaDown
= ( e
->modifiers
& EVT_RIGHTALT
) != 0;
467 if ( e
->what
== EVT_KEYUP
)
469 event
.SetEventType(wxEVT_KEY_UP
);
470 return win
->GetEventHandler()->ProcessEvent(event
);
477 event
.SetEventType(wxEVT_KEY_DOWN
);
480 ret
= win
->GetEventHandler()->ProcessEvent(event
);
482 // wxMSW doesn't send char events with Alt pressed
483 // Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x
484 // will only be sent if it is not in an accelerator table:
485 event2
.m_keyCode
= wxScanToKeyCode(e
, false);
486 if ( !ret
&& event2
.m_keyCode
!= 0 )
488 event2
.SetEventType(wxEVT_CHAR
);
489 ret
= win
->GetEventHandler()->ProcessEvent(event2
);
492 // Synthetize navigation key event, but do it only if the TAB key
493 // wasn't handled yet:
494 if ( !ret
&& event
.m_keyCode
== WXK_TAB
&&
495 win
->GetParent() && win
->GetParent()->HasFlag(wxTAB_TRAVERSAL
) )
497 wxNavigationKeyEvent navEvent
;
498 navEvent
.SetEventObject(win
->GetParent());
499 // Shift-TAB goes in reverse direction:
500 navEvent
.SetDirection(!event
.m_shiftDown
);
501 // Ctrl-TAB changes the (parent) window, i.e. switch notebook page:
502 navEvent
.SetWindowChange(event
.m_controlDown
);
503 navEvent
.SetCurrentFocus(wxStaticCast(win
, wxWindow
));
504 ret
= win
->GetParent()->GetEventHandler()->ProcessEvent(navEvent
);
507 // Finally, process special meaning keys that are usually
508 // a responsibility of OS or window manager:
510 ret
= wxHandleSpecialKeys(event
);
516 // ---------------------------------------------------------------------------
518 // ---------------------------------------------------------------------------
520 // in wxUniv this class is abstract because it doesn't have DoPopupMenu()
521 IMPLEMENT_ABSTRACT_CLASS(wxWindowMGL
, wxWindowBase
)
523 BEGIN_EVENT_TABLE(wxWindowMGL
, wxWindowBase
)
526 // ===========================================================================
528 // ===========================================================================
530 // ----------------------------------------------------------------------------
531 // constructors and such
532 // ----------------------------------------------------------------------------
534 extern wxVideoMode
wxGetDefaultDisplayMode();
536 void wxWindowMGL::Init()
538 // First of all, make sure window manager is up and running. If it is
539 // not the case, initialize it in default display mode
542 if ( !wxTheApp
->SetDisplayMode(wxGetDefaultDisplayMode()) )
543 wxLogFatalError(_("Cannot initialize display."));
551 m_eraseBackground
= -1;
555 wxWindowMGL::~wxWindowMGL()
559 m_isBeingDeleted
= true;
561 if ( gs_mouseCapture
== this )
564 if (gs_activeFrame
== this)
566 gs_activeFrame
= NULL
;
567 // activate next frame in Z-order:
570 wxWindowMGL
*win
= (wxWindowMGL
*)m_wnd
->prev
->userData
;
573 else if ( m_wnd
->next
)
575 wxWindowMGL
*win
= (wxWindowMGL
*)m_wnd
->next
->userData
;
580 if ( gs_focusedWindow
== this )
583 if ( gs_windowUnderMouse
== this )
584 gs_windowUnderMouse
= NULL
;
589 MGL_wmDestroyWindow(m_wnd
);
592 // real construction (Init() must have been called before!)
593 bool wxWindowMGL::Create(wxWindow
*parent
,
598 const wxString
& name
)
600 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
604 parent
->AddChild(this);
607 x
= pos
.x
, y
= pos
.y
;
609 x
= 0; // FIXME_MGL, something better, see GTK+
611 y
= 0; // FIXME_MGL, something better, see GTK+
612 AdjustForParentClientOrigin(x
, y
, 0);
613 w
= WidthDefault(size
.x
);
614 h
= HeightDefault(size
.y
);
617 window_t
*wnd_parent
= parent
? parent
->GetHandle() : NULL
;
619 if ( style
& wxFULL_REPAINT_ON_RESIZE
)
621 mgl_style
|= MGL_WM_FULL_REPAINT_ON_RESIZE
;
623 if ( style
& wxSTAY_ON_TOP
)
625 mgl_style
|= MGL_WM_ALWAYS_ON_TOP
;
627 if ( style
& wxPOPUP_WINDOW
)
629 mgl_style
|= MGL_WM_ALWAYS_ON_TOP
;
630 // it is created hidden as other top level windows
635 window_t
*wnd
= MGL_wmCreateWindow(g_winMng
, wnd_parent
, x
, y
, w
, h
);
637 MGL_wmSetWindowFlags(wnd
, mgl_style
);
638 MGL_wmShowWindow(wnd
, m_isShown
);
645 void wxWindowMGL::SetMGLwindow_t(struct window_t
*wnd
)
648 MGL_wmDestroyWindow(m_wnd
);
651 if ( !m_wnd
) return;
653 m_isShown
= (bool)m_wnd
->visible
;
655 MGL_wmSetWindowUserData(m_wnd
, (void*) this);
656 MGL_wmSetWindowPainter(m_wnd
, wxWindowPainter
);
657 MGL_wmPushWindowEventHandler(m_wnd
, wxWindowMouseHandler
, EVT_MOUSEEVT
, 0);
658 MGL_wmPushWindowEventHandler(m_wnd
, wxWindowKeybHandler
, EVT_KEYEVT
, 0);
661 MGL_wmSetWindowCursor(m_wnd
, *m_cursor
.GetMGLCursor());
663 MGL_wmSetWindowCursor(m_wnd
, *wxSTANDARD_CURSOR
->GetMGLCursor());
666 // ---------------------------------------------------------------------------
668 // ---------------------------------------------------------------------------
670 void wxWindowMGL::SetFocus()
672 if ( gs_focusedWindow
== this ) return;
674 wxWindowMGL
*oldFocusedWindow
= gs_focusedWindow
;
676 if ( gs_focusedWindow
)
678 gs_toBeFocusedWindow
= (wxWindow
*)this;
679 gs_focusedWindow
->KillFocus();
680 gs_toBeFocusedWindow
= NULL
;
683 gs_focusedWindow
= this;
685 MGL_wmCaptureEvents(GetHandle(), EVT_KEYEVT
, wxMGL_CAPTURE_KEYB
);
687 wxWindowMGL
*active
= wxGetTopLevelParent(this);
688 if ( !(m_windowStyle
& wxPOPUP_WINDOW
) && active
!= gs_activeFrame
)
690 if ( gs_activeFrame
)
692 wxActivateEvent
event(wxEVT_ACTIVATE
, false, gs_activeFrame
->GetId());
693 event
.SetEventObject(gs_activeFrame
);
694 gs_activeFrame
->GetEventHandler()->ProcessEvent(event
);
697 gs_activeFrame
= active
;
698 wxActivateEvent
event(wxEVT_ACTIVATE
, true, gs_activeFrame
->GetId());
699 event
.SetEventObject(gs_activeFrame
);
700 gs_activeFrame
->GetEventHandler()->ProcessEvent(event
);
703 wxFocusEvent
event(wxEVT_SET_FOCUS
, GetId());
704 event
.SetEventObject(this);
705 event
.SetWindow((wxWindow
*)oldFocusedWindow
);
706 GetEventHandler()->ProcessEvent(event
);
709 // caret needs to be informed about focus change
710 wxCaret
*caret
= GetCaret();
713 #endif // wxUSE_CARET
716 void wxWindowMGL::KillFocus()
718 if ( gs_focusedWindow
!= this ) return;
719 gs_focusedWindow
= NULL
;
721 if ( m_isBeingDeleted
) return;
723 MGL_wmUncaptureEvents(GetHandle(), wxMGL_CAPTURE_KEYB
);
726 // caret needs to be informed about focus change
727 wxCaret
*caret
= GetCaret();
729 caret
->OnKillFocus();
730 #endif // wxUSE_CARET
732 wxFocusEvent
event(wxEVT_KILL_FOCUS
, GetId());
733 event
.SetEventObject(this);
734 event
.SetWindow(gs_toBeFocusedWindow
);
735 GetEventHandler()->ProcessEvent(event
);
738 // ----------------------------------------------------------------------------
739 // this wxWindowBase function is implemented here (in platform-specific file)
740 // because it is static and so couldn't be made virtual
741 // ----------------------------------------------------------------------------
742 wxWindow
*wxWindowBase::DoFindFocus()
744 return (wxWindow
*)gs_focusedWindow
;
747 bool wxWindowMGL::Show(bool show
)
749 if ( !wxWindowBase::Show(show
) )
752 MGL_wmShowWindow(m_wnd
, show
);
754 if (!show
&& gs_activeFrame
== this)
756 // activate next frame in Z-order:
759 wxWindowMGL
*win
= (wxWindowMGL
*)m_wnd
->prev
->userData
;
762 else if ( m_wnd
->next
)
764 wxWindowMGL
*win
= (wxWindowMGL
*)m_wnd
->next
->userData
;
769 gs_activeFrame
= NULL
;
776 // Raise the window to the top of the Z order
777 void wxWindowMGL::Raise()
779 MGL_wmRaiseWindow(m_wnd
);
782 // Lower the window to the bottom of the Z order
783 void wxWindowMGL::Lower()
785 MGL_wmLowerWindow(m_wnd
);
788 void wxWindowMGL::DoCaptureMouse()
790 if ( gs_mouseCapture
)
791 MGL_wmUncaptureEvents(gs_mouseCapture
->m_wnd
, wxMGL_CAPTURE_MOUSE
);
793 gs_mouseCapture
= this;
794 MGL_wmCaptureEvents(m_wnd
, EVT_MOUSEEVT
, wxMGL_CAPTURE_MOUSE
);
797 void wxWindowMGL::DoReleaseMouse()
799 wxASSERT_MSG( gs_mouseCapture
== this, wxT("attempt to release mouse, but this window hasn't captured it") );
801 MGL_wmUncaptureEvents(m_wnd
, wxMGL_CAPTURE_MOUSE
);
802 gs_mouseCapture
= NULL
;
805 /* static */ wxWindow
*wxWindowBase::GetCapture()
807 return (wxWindow
*)gs_mouseCapture
;
810 bool wxWindowMGL::SetCursor(const wxCursor
& cursor
)
812 if ( !wxWindowBase::SetCursor(cursor
) )
819 MGL_wmSetWindowCursor(m_wnd
, *m_cursor
.GetMGLCursor());
821 MGL_wmSetWindowCursor(m_wnd
, *wxSTANDARD_CURSOR
->GetMGLCursor());
826 void wxWindowMGL::WarpPointer(int x
, int y
)
829 wxDisplaySize(&w
, &h
);
831 ClientToScreen(&x
, &y
);
841 EVT_setMousePos(x
, y
);
844 // Set this window to be the child of 'parent'.
845 bool wxWindowMGL::Reparent(wxWindowBase
*parent
)
847 if ( !wxWindowBase::Reparent(parent
) )
850 MGL_wmReparentWindow(m_wnd
, parent
->GetHandle());
856 // ---------------------------------------------------------------------------
858 // ---------------------------------------------------------------------------
860 #if wxUSE_DRAG_AND_DROP
862 void wxWindowMGL::SetDropTarget(wxDropTarget
*pDropTarget
)
864 if ( m_dropTarget
!= 0 ) {
865 m_dropTarget
->Revoke(m_hWnd
);
869 m_dropTarget
= pDropTarget
;
870 if ( m_dropTarget
!= 0 )
871 m_dropTarget
->Register(m_hWnd
);
874 #endif // wxUSE_DRAG_AND_DROP
876 // old style file-manager drag&drop support: we retain the old-style
877 // DragAcceptFiles in parallel with SetDropTarget.
878 void wxWindowMGL::DragAcceptFiles(bool WXUNUSED(accept
))
881 HWND hWnd
= GetHwnd();
883 ::DragAcceptFiles(hWnd
, (BOOL
)accept
);
887 // ---------------------------------------------------------------------------
888 // moving and resizing
889 // ---------------------------------------------------------------------------
892 void wxWindowMGL::DoGetSize(int *x
, int *y
) const
894 wxASSERT_MSG( m_wnd
, wxT("invalid window") );
896 if (x
) *x
= m_wnd
->width
;
897 if (y
) *y
= m_wnd
->height
;
900 void wxWindowMGL::DoGetPosition(int *x
, int *y
) const
902 wxASSERT_MSG( m_wnd
, wxT("invalid window") );
905 AdjustForParentClientOrigin(pX
, pY
, 0);
907 if (x
) *x
= m_wnd
->x
- pX
;
908 if (y
) *y
= m_wnd
->y
- pY
;
911 void wxWindowMGL::DoScreenToClient(int *x
, int *y
) const
914 MGL_wmCoordGlobalToLocal(m_wnd
, 0, 0, &ax
, &ay
);
921 void wxWindowMGL::DoClientToScreen(int *x
, int *y
) const
924 MGL_wmCoordLocalToGlobal(m_wnd
, 0, 0, &ax
, &ay
);
931 // Get size *available for subwindows* i.e. excluding menu bar etc.
932 void wxWindowMGL::DoGetClientSize(int *x
, int *y
) const
937 void wxWindowMGL::DoMoveWindow(int x
, int y
, int width
, int height
)
939 wxRect
rcClient(GetClientRect());
941 MGL_wmSetWindowPosition(m_wnd
, x
, y
, width
, height
);
943 // When the origin or a window stays fixed but the height or width
944 // changes, invalidate the old and new non-client areas
945 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) &&
946 m_wnd
->x
== x
&& m_wnd
->y
== y
&&
947 rcClient
.Intersect(GetClientRect()) != wxRect(0, 0, width
, height
) )
949 wxRegion
rgn(0, 0, width
, height
);
950 rgn
.Subtract(rcClient
);
952 // This should work I think, but doesn't seem to:
953 //MGL_wmInvalidateWindowRegion(m_wnd, rgn.GetMGLRegion().rgnPointer());
955 // Use MGL_wmInvalidateWindowRect instead:
956 for (wxRegionIterator
it(rgn
); it
; it
++)
961 rc
.right
= rc
.left
+ it
.GetW();
962 rc
.bottom
= rc
.top
+ it
.GetH();
963 MGL_wmInvalidateWindowRect(m_wnd
, &rc
);
968 // set the size of the window: if the dimensions are positive, just use them,
969 // but if any of them is equal to -1, it means that we must find the value for
970 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
971 // which case -1 is a valid value for x and y)
973 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
974 // the width/height to best suit our contents, otherwise we reuse the current
976 void wxWindowMGL::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
978 // get the current size and position...
979 int currentX
, currentY
;
980 GetPosition(¤tX
, ¤tY
);
981 int currentW
,currentH
;
982 GetSize(¤tW
, ¤tH
);
984 // ... and don't do anything (avoiding flicker) if it's already ok
985 if ( x
== currentX
&& y
== currentY
&&
986 width
== currentW
&& height
== currentH
)
991 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
993 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
996 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1001 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1003 size
= DoGetBestSize();
1008 // just take the current one
1015 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1019 size
= DoGetBestSize();
1021 //else: already called DoGetBestSize() above
1027 // just take the current one
1032 int maxWidth
= GetMaxWidth(),
1033 minWidth
= GetMinWidth(),
1034 maxHeight
= GetMaxHeight(),
1035 minHeight
= GetMinHeight();
1037 if ( minWidth
!= -1 && width
< minWidth
) width
= minWidth
;
1038 if ( maxWidth
!= -1 && width
> maxWidth
) width
= maxWidth
;
1039 if ( minHeight
!= -1 && height
< minHeight
) height
= minHeight
;
1040 if ( maxHeight
!= -1 && height
> maxHeight
) height
= maxHeight
;
1042 if ( m_wnd
->x
!= x
|| m_wnd
->y
!= y
||
1043 (int)m_wnd
->width
!= width
|| (int)m_wnd
->height
!= height
)
1045 DoMoveWindow(x
, y
, width
, height
);
1047 wxSize
newSize(width
, height
);
1048 wxSizeEvent
event(newSize
, GetId());
1049 event
.SetEventObject(this);
1050 GetEventHandler()->ProcessEvent(event
);
1054 void wxWindowMGL::DoSetClientSize(int width
, int height
)
1056 SetSize(width
, height
);
1059 // ---------------------------------------------------------------------------
1061 // ---------------------------------------------------------------------------
1063 int wxWindowMGL::GetCharHeight() const
1067 return dc
.GetCharHeight();
1070 int wxWindowMGL::GetCharWidth() const
1074 return dc
.GetCharWidth();
1077 void wxWindowMGL::GetTextExtent(const wxString
& string
,
1079 int *descent
, int *externalLeading
,
1080 const wxFont
*theFont
) const
1085 dc
.GetTextExtent(string
, x
, y
, descent
, externalLeading
, (wxFont
*)theFont
);
1089 // ---------------------------------------------------------------------------
1091 // ---------------------------------------------------------------------------
1093 void wxWindowMGL::Clear()
1095 wxClientDC
dc((wxWindow
*)this);
1096 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1097 dc
.SetBackground(brush
);
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
);