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"
31 #include "wx/dcclient.h"
37 #if wxUSE_DRAG_AND_DROP
42 #include "wx/sysopt.h"
43 #include "wx/mgl/private.h"
45 #include "wx/dcscreen.h"
51 #include "wx/tooltip.h"
54 // ---------------------------------------------------------------------------
56 // ---------------------------------------------------------------------------
58 // MGL window manager and associated DC.
59 winmng_t
*g_winMng
= NULL
;
60 MGLDevCtx
*g_displayDC
= NULL
;
62 // the window that has keyboard focus:
63 static wxWindowMGL
*gs_focusedWindow
= NULL
;
64 // the window that is about to be focused after currently focused
66 static wxWindow
*gs_toBeFocusedWindow
= NULL
;
67 // the window that is currently under mouse cursor:
68 static wxWindowMGL
*gs_windowUnderMouse
= NULL
;
69 // the window that has mouse capture
70 static wxWindowMGL
*gs_mouseCapture
= NULL
;
71 // the frame that is currently active (i.e. its child has focus). It is
72 // used to generate wxActivateEvents
73 static wxWindowMGL
*gs_activeFrame
= NULL
;
75 // ---------------------------------------------------------------------------
77 // ---------------------------------------------------------------------------
79 // Custom identifiers used to distinguish between various event handlers
80 // and capture handlers passed to MGL_wm
83 wxMGL_CAPTURE_MOUSE
= 1,
84 wxMGL_CAPTURE_KEYB
= 2
88 // ---------------------------------------------------------------------------
90 // ---------------------------------------------------------------------------
92 // Returns toplevel grandparent of given window:
93 static wxWindowMGL
* wxGetTopLevelParent(wxWindowMGL
*win
)
96 while (p
&& !p
->IsTopLevel())
101 // An easy way to capture screenshots:
102 static void wxCaptureScreenshot(bool activeWindowOnly
)
105 #define SCREENSHOT_FILENAME _T("sshot%03i.png")
107 #define SCREENSHOT_FILENAME _T("screenshot-%03i.png")
109 static int screenshot_num
= 0;
114 screenshot
.Printf(SCREENSHOT_FILENAME
, screenshot_num
++);
115 } while ( wxFileExists(screenshot
) && screenshot_num
< 1000 );
117 wxRect
r(0, 0, g_displayDC
->sizex(), g_displayDC
->sizey());
119 if ( activeWindowOnly
&& gs_activeFrame
)
121 r
.Intersect(gs_activeFrame
->GetRect());
124 g_displayDC
->savePNGFromDC(screenshot
.mb_str(),
125 r
.x
, r
. y
, r
.x
+r
.width
, r
.y
+r
.height
);
127 wxMessageBox(wxString::Format(_T("Screenshot captured: %s"),
128 screenshot
.c_str()));
131 // ---------------------------------------------------------------------------
133 // ---------------------------------------------------------------------------
135 static void MGLAPI
wxWindowPainter(window_t
*wnd
, MGLDC
*dc
)
137 wxWindowMGL
*w
= (wxWindow
*) wnd
->userData
;
139 if ( w
&& !(w
->GetWindowStyle() & wxTRANSPARENT_WINDOW
) )
142 w
->HandlePaint(&ctx
);
146 static ibool MGLAPI
wxWindowMouseHandler(window_t
*wnd
, event_t
*e
)
148 wxWindowMGL
*win
= (wxWindowMGL
*)MGL_wmGetWindowUserData(wnd
);
149 wxPoint
orig(win
->GetClientAreaOrigin());
152 MGL_wmCoordGlobalToLocal(win
->GetHandle(),
153 e
->where_x
, e
->where_y
, &where
.x
, &where
.y
);
155 for (wxWindowMGL
*w
= win
; w
; w
= w
->GetParent())
157 if ( !w
->IsEnabled() )
159 if ( w
->IsTopLevel() )
163 wxEventType type
= wxEVT_NULL
;
165 event
.SetEventObject(win
);
166 event
.SetTimestamp(e
->when
);
167 event
.m_x
= where
.x
- orig
.x
;
168 event
.m_y
= where
.y
- orig
.y
;
169 event
.m_shiftDown
= ( e
->modifiers
& EVT_SHIFTKEY
) != 0;
170 event
.m_controlDown
= ( e
->modifiers
& EVT_CTRLSTATE
) != 0;
171 event
.m_altDown
= ( e
->modifiers
& EVT_LEFTALT
) != 0;
172 event
.m_metaDown
= ( e
->modifiers
& EVT_RIGHTALT
) != 0;
173 event
.m_leftDown
= ( e
->modifiers
& EVT_LEFTBUT
) != 0;
174 event
.m_middleDown
= ( e
->modifiers
& EVT_MIDDLEBUT
) != 0;
175 event
.m_rightDown
= ( e
->modifiers
& EVT_RIGHTBUT
) != 0;
180 // Change focus if the user clicks outside focused window:
181 if ( win
->AcceptsFocus() && wxWindow::FindFocus() != win
)
184 if ( e
->message
& EVT_DBLCLICK
)
186 if ( e
->message
& EVT_LEFTBMASK
)
187 type
= wxEVT_LEFT_DCLICK
;
188 else if ( e
->message
& EVT_MIDDLEBMASK
)
189 type
= wxEVT_MIDDLE_DCLICK
;
190 else if ( e
->message
& EVT_RIGHTBMASK
)
191 type
= wxEVT_RIGHT_DCLICK
;
195 if ( e
->message
& EVT_LEFTBMASK
)
196 type
= wxEVT_LEFT_DOWN
;
197 else if ( e
->message
& EVT_MIDDLEBMASK
)
198 type
= wxEVT_MIDDLE_DOWN
;
199 else if ( e
->message
& EVT_RIGHTBMASK
)
200 type
= wxEVT_RIGHT_DOWN
;
206 if ( e
->message
& EVT_LEFTBMASK
)
207 type
= wxEVT_LEFT_UP
;
208 else if ( e
->message
& EVT_MIDDLEBMASK
)
209 type
= wxEVT_MIDDLE_UP
;
210 else if ( e
->message
& EVT_RIGHTBMASK
)
211 type
= wxEVT_RIGHT_UP
;
215 if ( !gs_mouseCapture
)
217 if ( win
!= gs_windowUnderMouse
)
219 if ( gs_windowUnderMouse
)
221 wxMouseEvent
event2(event
);
222 MGL_wmCoordGlobalToLocal(gs_windowUnderMouse
->GetHandle(),
223 e
->where_x
, e
->where_y
,
224 &event2
.m_x
, &event2
.m_y
);
226 wxPoint
orig(gs_windowUnderMouse
->GetClientAreaOrigin());
227 event2
.m_x
-= orig
.x
;
228 event2
.m_y
-= orig
.y
;
230 event2
.SetEventObject(gs_windowUnderMouse
);
231 event2
.SetEventType(wxEVT_LEAVE_WINDOW
);
232 gs_windowUnderMouse
->GetEventHandler()->ProcessEvent(event2
);
235 wxMouseEvent
event3(event
);
236 event3
.SetEventType(wxEVT_ENTER_WINDOW
);
237 win
->GetEventHandler()->ProcessEvent(event3
);
239 gs_windowUnderMouse
= win
;
242 else // gs_mouseCapture
244 bool inside
= (where
.x
>= 0 &&
246 where
.x
< win
->GetSize().x
&&
247 where
.y
< win
->GetSize().y
);
248 if ( (inside
&& gs_windowUnderMouse
!= win
) ||
249 (!inside
&& gs_windowUnderMouse
== win
) )
251 wxMouseEvent
evt(inside
?
252 wxEVT_ENTER_WINDOW
: wxEVT_LEAVE_WINDOW
);
253 evt
.SetEventObject(win
);
254 win
->GetEventHandler()->ProcessEvent(evt
);
255 gs_windowUnderMouse
= inside
? win
: NULL
;
266 if ( type
== wxEVT_NULL
)
272 event
.SetEventType(type
);
273 return win
->GetEventHandler()->ProcessEvent(event
);
277 static long wxScanToKeyCode(event_t
*event
, bool translate
)
279 // VS: make it __WXDEBUG__-only, since we have lots of wxLogTrace calls
280 // here and the arguments would be stored in non-debug executable even
281 // though wxLogTrace would be no-op...
283 #define KEY(mgl_key,wx_key) \
285 wxLogTrace(_T("keyevents"), \
286 _T("key " #mgl_key ", mapped to " #wx_key)); \
290 #define KEY(mgl_key,wx_key) \
291 case mgl_key: key = wx_key; break;
298 switch ( EVT_scanCode(event
->message
) )
300 KEY (KB_padMinus
, WXK_NUMPAD_SUBTRACT
)
301 KEY (KB_padPlus
, WXK_NUMPAD_ADD
)
302 KEY (KB_padTimes
, WXK_NUMPAD_MULTIPLY
)
303 KEY (KB_padDivide
, WXK_NUMPAD_DIVIDE
)
304 KEY (KB_padCenter
, WXK_NUMPAD_SEPARATOR
) // ?
305 KEY (KB_padLeft
, WXK_NUMPAD_LEFT
)
306 KEY (KB_padRight
, WXK_NUMPAD_RIGHT
)
307 KEY (KB_padUp
, WXK_NUMPAD_UP
)
308 KEY (KB_padDown
, WXK_NUMPAD_DOWN
)
309 KEY (KB_padInsert
, WXK_NUMPAD_INSERT
)
310 KEY (KB_padDelete
, WXK_NUMPAD_DELETE
)
311 KEY (KB_padHome
, WXK_NUMPAD_HOME
)
312 KEY (KB_padEnd
, WXK_NUMPAD_END
)
313 KEY (KB_padPageUp
, WXK_NUMPAD_PAGEUP
)
314 //KEY (KB_padPageUp, WXK_NUMPAD_PRIOR)
315 KEY (KB_padPageDown
, WXK_NUMPAD_PAGEDOWN
)
316 //KEY (KB_padPageDown, WXK_NUMPAD_NEXT)
327 KEY (KB_minus
, WXK_SUBTRACT
)
328 KEY (KB_equals
, WXK_ADD
)
329 KEY (KB_backSlash
, '\\')
340 KEY (KB_leftSquareBrace
,'[')
341 KEY (KB_rightSquareBrace
,']')
351 KEY (KB_semicolon
, ';')
352 KEY (KB_apostrophe
, '\'')
362 KEY (KB_divide
, WXK_DIVIDE
)
363 KEY (KB_space
, WXK_SPACE
)
372 switch ( EVT_scanCode(event
->message
) )
374 KEY (KB_padEnter
, WXK_NUMPAD_ENTER
)
384 KEY (KB_F10
, WXK_F10
)
385 KEY (KB_F11
, WXK_F11
)
386 KEY (KB_F12
, WXK_F12
)
387 KEY (KB_left
, WXK_LEFT
)
388 KEY (KB_right
, WXK_RIGHT
)
390 KEY (KB_down
, WXK_DOWN
)
391 KEY (KB_insert
, WXK_INSERT
)
392 KEY (KB_delete
, WXK_DELETE
)
393 KEY (KB_home
, WXK_HOME
)
394 KEY (KB_end
, WXK_END
)
395 KEY (KB_pageUp
, WXK_PAGEUP
)
396 KEY (KB_pageDown
, WXK_PAGEDOWN
)
397 KEY (KB_capsLock
, WXK_CAPITAL
)
398 KEY (KB_numLock
, WXK_NUMLOCK
)
399 KEY (KB_scrollLock
, WXK_SCROLL
)
400 KEY (KB_leftShift
, WXK_SHIFT
)
401 KEY (KB_rightShift
, WXK_SHIFT
)
402 KEY (KB_leftCtrl
, WXK_CONTROL
)
403 KEY (KB_rightCtrl
, WXK_CONTROL
)
404 KEY (KB_leftAlt
, WXK_ALT
)
405 KEY (KB_rightAlt
, WXK_ALT
)
406 KEY (KB_leftWindows
, WXK_START
)
407 KEY (KB_rightWindows
, WXK_START
)
408 KEY (KB_menu
, WXK_MENU
)
409 KEY (KB_sysReq
, WXK_SNAPSHOT
)
410 KEY (KB_esc
, WXK_ESCAPE
)
411 KEY (KB_backspace
, WXK_BACK
)
412 KEY (KB_tab
, WXK_TAB
)
413 KEY (KB_enter
, WXK_RETURN
)
416 key
= EVT_asciiCode(event
->message
);
426 static bool wxHandleSpecialKeys(wxKeyEvent
& event
)
428 // Add an easy way to capture screenshots:
429 if ( event
.m_keyCode
== WXK_SNAPSHOT
430 #ifdef __WXDEBUG__ // FIXME_MGL - remove when KB_sysReq works in MGL!
431 || (event
.m_keyCode
== WXK_F1
&&
432 event
.m_shiftDown
&& event
.m_controlDown
)
436 wxCaptureScreenshot(event
.m_altDown
/*only active wnd?*/);
443 static ibool MGLAPI
wxWindowKeybHandler(window_t
*wnd
, event_t
*e
)
445 wxWindowMGL
*win
= (wxWindowMGL
*)MGL_wmGetWindowUserData(wnd
);
447 if ( !win
->IsEnabled() ) return FALSE
;
450 MGL_wmCoordGlobalToLocal(win
->GetHandle(),
451 e
->where_x
, e
->where_y
, &where
.x
, &where
.y
);
454 event
.SetEventObject(win
);
455 event
.SetTimestamp(e
->when
);
456 event
.m_keyCode
= wxScanToKeyCode(e
, true);
457 event
.m_scanCode
= 0; // not used by wx at all
460 event
.m_shiftDown
= ( e
->modifiers
& EVT_SHIFTKEY
) != 0;
461 event
.m_controlDown
= ( e
->modifiers
& EVT_CTRLSTATE
) != 0;
462 event
.m_altDown
= ( e
->modifiers
& EVT_LEFTALT
) != 0;
463 event
.m_metaDown
= ( e
->modifiers
& EVT_RIGHTALT
) != 0;
465 if ( e
->what
== EVT_KEYUP
)
467 event
.SetEventType(wxEVT_KEY_UP
);
468 return win
->GetEventHandler()->ProcessEvent(event
);
475 event
.SetEventType(wxEVT_KEY_DOWN
);
478 ret
= win
->GetEventHandler()->ProcessEvent(event
);
480 // wxMSW doesn't send char events with Alt pressed
481 // Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x
482 // will only be sent if it is not in an accelerator table:
483 event2
.m_keyCode
= wxScanToKeyCode(e
, false);
484 if ( !ret
&& event2
.m_keyCode
!= 0 )
486 event2
.SetEventType(wxEVT_CHAR
);
487 ret
= win
->GetEventHandler()->ProcessEvent(event2
);
490 // Synthetize navigation key event, but do it only if the TAB key
491 // wasn't handled yet:
492 if ( !ret
&& event
.m_keyCode
== WXK_TAB
&&
493 win
->GetParent() && win
->GetParent()->HasFlag(wxTAB_TRAVERSAL
) )
495 wxNavigationKeyEvent navEvent
;
496 navEvent
.SetEventObject(win
->GetParent());
497 // Shift-TAB goes in reverse direction:
498 navEvent
.SetDirection(!event
.m_shiftDown
);
499 // Ctrl-TAB changes the (parent) window, i.e. switch notebook page:
500 navEvent
.SetWindowChange(event
.m_controlDown
);
501 navEvent
.SetCurrentFocus(wxStaticCast(win
, wxWindow
));
502 ret
= win
->GetParent()->GetEventHandler()->ProcessEvent(navEvent
);
505 // Finally, process special meaning keys that are usually
506 // a responsibility of OS or window manager:
508 ret
= wxHandleSpecialKeys(event
);
514 // ---------------------------------------------------------------------------
516 // ---------------------------------------------------------------------------
518 // in wxUniv this class is abstract because it doesn't have DoPopupMenu()
519 IMPLEMENT_ABSTRACT_CLASS(wxWindowMGL
, wxWindowBase
)
521 BEGIN_EVENT_TABLE(wxWindowMGL
, wxWindowBase
)
524 // ===========================================================================
526 // ===========================================================================
528 // ----------------------------------------------------------------------------
529 // constructors and such
530 // ----------------------------------------------------------------------------
532 extern wxVideoMode
wxGetDefaultDisplayMode();
534 void wxWindowMGL::Init()
536 // First of all, make sure window manager is up and running. If it is
537 // not the case, initialize it in default display mode
540 if ( !wxTheApp
->SetDisplayMode(wxGetDefaultDisplayMode()) )
541 wxLogFatalError(_("Cannot initialize display."));
549 m_eraseBackground
= -1;
553 wxWindowMGL::~wxWindowMGL()
557 m_isBeingDeleted
= true;
559 if ( gs_mouseCapture
== this )
562 if (gs_activeFrame
== this)
564 gs_activeFrame
= NULL
;
565 // activate next frame in Z-order:
568 wxWindowMGL
*win
= (wxWindowMGL
*)m_wnd
->prev
->userData
;
571 else if ( m_wnd
->next
)
573 wxWindowMGL
*win
= (wxWindowMGL
*)m_wnd
->next
->userData
;
578 if ( gs_focusedWindow
== this )
581 if ( gs_windowUnderMouse
== this )
582 gs_windowUnderMouse
= NULL
;
587 MGL_wmDestroyWindow(m_wnd
);
590 // real construction (Init() must have been called before!)
591 bool wxWindowMGL::Create(wxWindow
*parent
,
596 const wxString
& name
)
598 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
602 parent
->AddChild(this);
605 x
= pos
.x
, y
= pos
.y
;
607 x
= 0; // FIXME_MGL, something better, see GTK+
609 y
= 0; // FIXME_MGL, something better, see GTK+
610 AdjustForParentClientOrigin(x
, y
, 0);
611 w
= WidthDefault(size
.x
);
612 h
= HeightDefault(size
.y
);
615 window_t
*wnd_parent
= parent
? parent
->GetHandle() : NULL
;
617 if ( style
& wxFULL_REPAINT_ON_RESIZE
)
619 mgl_style
|= MGL_WM_FULL_REPAINT_ON_RESIZE
;
621 if ( style
& wxSTAY_ON_TOP
)
623 mgl_style
|= MGL_WM_ALWAYS_ON_TOP
;
625 if ( style
& wxPOPUP_WINDOW
)
627 mgl_style
|= MGL_WM_ALWAYS_ON_TOP
;
628 // it is created hidden as other top level windows
633 window_t
*wnd
= MGL_wmCreateWindow(g_winMng
, wnd_parent
, x
, y
, w
, h
);
635 MGL_wmSetWindowFlags(wnd
, mgl_style
);
636 MGL_wmShowWindow(wnd
, m_isShown
);
643 void wxWindowMGL::SetMGLwindow_t(struct window_t
*wnd
)
646 MGL_wmDestroyWindow(m_wnd
);
649 if ( !m_wnd
) return;
651 m_isShown
= (bool)m_wnd
->visible
;
653 MGL_wmSetWindowUserData(m_wnd
, (void*) this);
654 MGL_wmSetWindowPainter(m_wnd
, wxWindowPainter
);
655 MGL_wmPushWindowEventHandler(m_wnd
, wxWindowMouseHandler
, EVT_MOUSEEVT
, 0);
656 MGL_wmPushWindowEventHandler(m_wnd
, wxWindowKeybHandler
, EVT_KEYEVT
, 0);
659 MGL_wmSetWindowCursor(m_wnd
, *m_cursor
.GetMGLCursor());
661 MGL_wmSetWindowCursor(m_wnd
, *wxSTANDARD_CURSOR
->GetMGLCursor());
664 // ---------------------------------------------------------------------------
666 // ---------------------------------------------------------------------------
668 void wxWindowMGL::SetFocus()
670 if ( gs_focusedWindow
== this ) return;
672 wxWindowMGL
*oldFocusedWindow
= gs_focusedWindow
;
674 if ( gs_focusedWindow
)
676 gs_toBeFocusedWindow
= (wxWindow
*)this;
677 gs_focusedWindow
->KillFocus();
678 gs_toBeFocusedWindow
= NULL
;
681 gs_focusedWindow
= this;
683 MGL_wmCaptureEvents(GetHandle(), EVT_KEYEVT
, wxMGL_CAPTURE_KEYB
);
685 wxWindowMGL
*active
= wxGetTopLevelParent(this);
686 if ( !(m_windowStyle
& wxPOPUP_WINDOW
) && active
!= gs_activeFrame
)
688 if ( gs_activeFrame
)
690 wxActivateEvent
event(wxEVT_ACTIVATE
, false, gs_activeFrame
->GetId());
691 event
.SetEventObject(gs_activeFrame
);
692 gs_activeFrame
->GetEventHandler()->ProcessEvent(event
);
695 gs_activeFrame
= active
;
696 wxActivateEvent
event(wxEVT_ACTIVATE
, true, gs_activeFrame
->GetId());
697 event
.SetEventObject(gs_activeFrame
);
698 gs_activeFrame
->GetEventHandler()->ProcessEvent(event
);
701 wxFocusEvent
event(wxEVT_SET_FOCUS
, GetId());
702 event
.SetEventObject(this);
703 event
.SetWindow((wxWindow
*)oldFocusedWindow
);
704 GetEventHandler()->ProcessEvent(event
);
707 // caret needs to be informed about focus change
708 wxCaret
*caret
= GetCaret();
711 #endif // wxUSE_CARET
714 void wxWindowMGL::KillFocus()
716 if ( gs_focusedWindow
!= this ) return;
717 gs_focusedWindow
= NULL
;
719 if ( m_isBeingDeleted
) return;
721 MGL_wmUncaptureEvents(GetHandle(), wxMGL_CAPTURE_KEYB
);
724 // caret needs to be informed about focus change
725 wxCaret
*caret
= GetCaret();
727 caret
->OnKillFocus();
728 #endif // wxUSE_CARET
730 wxFocusEvent
event(wxEVT_KILL_FOCUS
, GetId());
731 event
.SetEventObject(this);
732 event
.SetWindow(gs_toBeFocusedWindow
);
733 GetEventHandler()->ProcessEvent(event
);
736 // ----------------------------------------------------------------------------
737 // this wxWindowBase function is implemented here (in platform-specific file)
738 // because it is static and so couldn't be made virtual
739 // ----------------------------------------------------------------------------
740 wxWindow
*wxWindowBase::DoFindFocus()
742 return (wxWindow
*)gs_focusedWindow
;
745 bool wxWindowMGL::Show(bool show
)
747 if ( !wxWindowBase::Show(show
) )
750 MGL_wmShowWindow(m_wnd
, show
);
752 if (!show
&& gs_activeFrame
== this)
754 // activate next frame in Z-order:
757 wxWindowMGL
*win
= (wxWindowMGL
*)m_wnd
->prev
->userData
;
760 else if ( m_wnd
->next
)
762 wxWindowMGL
*win
= (wxWindowMGL
*)m_wnd
->next
->userData
;
767 gs_activeFrame
= NULL
;
774 // Raise the window to the top of the Z order
775 void wxWindowMGL::Raise()
777 MGL_wmRaiseWindow(m_wnd
);
780 // Lower the window to the bottom of the Z order
781 void wxWindowMGL::Lower()
783 MGL_wmLowerWindow(m_wnd
);
786 void wxWindowMGL::DoCaptureMouse()
788 if ( gs_mouseCapture
)
789 MGL_wmUncaptureEvents(gs_mouseCapture
->m_wnd
, wxMGL_CAPTURE_MOUSE
);
791 gs_mouseCapture
= this;
792 MGL_wmCaptureEvents(m_wnd
, EVT_MOUSEEVT
, wxMGL_CAPTURE_MOUSE
);
795 void wxWindowMGL::DoReleaseMouse()
797 wxASSERT_MSG( gs_mouseCapture
== this, wxT("attempt to release mouse, but this window hasn't captured it") );
799 MGL_wmUncaptureEvents(m_wnd
, wxMGL_CAPTURE_MOUSE
);
800 gs_mouseCapture
= NULL
;
803 /* static */ wxWindow
*wxWindowBase::GetCapture()
805 return (wxWindow
*)gs_mouseCapture
;
808 bool wxWindowMGL::SetCursor(const wxCursor
& cursor
)
810 if ( !wxWindowBase::SetCursor(cursor
) )
817 MGL_wmSetWindowCursor(m_wnd
, *m_cursor
.GetMGLCursor());
819 MGL_wmSetWindowCursor(m_wnd
, *wxSTANDARD_CURSOR
->GetMGLCursor());
824 void wxWindowMGL::WarpPointer(int x
, int y
)
827 wxDisplaySize(&w
, &h
);
829 ClientToScreen(&x
, &y
);
839 EVT_setMousePos(x
, y
);
842 // Set this window to be the child of 'parent'.
843 bool wxWindowMGL::Reparent(wxWindowBase
*parent
)
845 if ( !wxWindowBase::Reparent(parent
) )
848 MGL_wmReparentWindow(m_wnd
, parent
->GetHandle());
854 // ---------------------------------------------------------------------------
856 // ---------------------------------------------------------------------------
858 #if wxUSE_DRAG_AND_DROP
860 void wxWindowMGL::SetDropTarget(wxDropTarget
*pDropTarget
)
862 if ( m_dropTarget
!= 0 ) {
863 m_dropTarget
->Revoke(m_hWnd
);
867 m_dropTarget
= pDropTarget
;
868 if ( m_dropTarget
!= 0 )
869 m_dropTarget
->Register(m_hWnd
);
872 #endif // wxUSE_DRAG_AND_DROP
874 // old style file-manager drag&drop support: we retain the old-style
875 // DragAcceptFiles in parallel with SetDropTarget.
876 void wxWindowMGL::DragAcceptFiles(bool WXUNUSED(accept
))
879 HWND hWnd
= GetHwnd();
881 ::DragAcceptFiles(hWnd
, (BOOL
)accept
);
885 // ---------------------------------------------------------------------------
886 // moving and resizing
887 // ---------------------------------------------------------------------------
890 void wxWindowMGL::DoGetSize(int *x
, int *y
) const
892 wxASSERT_MSG( m_wnd
, wxT("invalid window") );
894 if (x
) *x
= m_wnd
->width
;
895 if (y
) *y
= m_wnd
->height
;
898 void wxWindowMGL::DoGetPosition(int *x
, int *y
) const
900 wxASSERT_MSG( m_wnd
, wxT("invalid window") );
903 AdjustForParentClientOrigin(pX
, pY
, 0);
905 if (x
) *x
= m_wnd
->x
- pX
;
906 if (y
) *y
= m_wnd
->y
- pY
;
909 void wxWindowMGL::DoScreenToClient(int *x
, int *y
) const
912 MGL_wmCoordGlobalToLocal(m_wnd
, 0, 0, &ax
, &ay
);
919 void wxWindowMGL::DoClientToScreen(int *x
, int *y
) const
922 MGL_wmCoordLocalToGlobal(m_wnd
, 0, 0, &ax
, &ay
);
929 // Get size *available for subwindows* i.e. excluding menu bar etc.
930 void wxWindowMGL::DoGetClientSize(int *x
, int *y
) const
935 void wxWindowMGL::DoMoveWindow(int x
, int y
, int width
, int height
)
937 wxRect
rcClient(GetClientRect());
939 MGL_wmSetWindowPosition(m_wnd
, x
, y
, width
, height
);
941 // When the origin or a window stays fixed but the height or width
942 // changes, invalidate the old and new non-client areas
943 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) &&
944 m_wnd
->x
== x
&& m_wnd
->y
== y
&&
945 rcClient
.Intersect(GetClientRect()) != wxRect(0, 0, width
, height
) )
947 wxRegion
rgn(0, 0, width
, height
);
948 rgn
.Subtract(rcClient
);
950 // This should work I think, but doesn't seem to:
951 //MGL_wmInvalidateWindowRegion(m_wnd, rgn.GetMGLRegion().rgnPointer());
953 // Use MGL_wmInvalidateWindowRect instead:
954 for (wxRegionIterator
it(rgn
); it
; it
++)
959 rc
.right
= rc
.left
+ it
.GetW();
960 rc
.bottom
= rc
.top
+ it
.GetH();
961 MGL_wmInvalidateWindowRect(m_wnd
, &rc
);
966 // set the size of the window: if the dimensions are positive, just use them,
967 // but if any of them is equal to -1, it means that we must find the value for
968 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
969 // which case -1 is a valid value for x and y)
971 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
972 // the width/height to best suit our contents, otherwise we reuse the current
974 void wxWindowMGL::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
976 // get the current size and position...
977 int currentX
, currentY
;
978 GetPosition(¤tX
, ¤tY
);
979 int currentW
,currentH
;
980 GetSize(¤tW
, ¤tH
);
982 // ... and don't do anything (avoiding flicker) if it's already ok
983 if ( x
== currentX
&& y
== currentY
&&
984 width
== currentW
&& height
== currentH
)
989 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
991 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
994 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
999 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1001 size
= DoGetBestSize();
1006 // just take the current one
1013 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1017 size
= DoGetBestSize();
1019 //else: already called DoGetBestSize() above
1025 // just take the current one
1030 int maxWidth
= GetMaxWidth(),
1031 minWidth
= GetMinWidth(),
1032 maxHeight
= GetMaxHeight(),
1033 minHeight
= GetMinHeight();
1035 if ( minWidth
!= -1 && width
< minWidth
) width
= minWidth
;
1036 if ( maxWidth
!= -1 && width
> maxWidth
) width
= maxWidth
;
1037 if ( minHeight
!= -1 && height
< minHeight
) height
= minHeight
;
1038 if ( maxHeight
!= -1 && height
> maxHeight
) height
= maxHeight
;
1040 if ( m_wnd
->x
!= x
|| m_wnd
->y
!= y
||
1041 (int)m_wnd
->width
!= width
|| (int)m_wnd
->height
!= height
)
1043 DoMoveWindow(x
, y
, width
, height
);
1045 wxSize
newSize(width
, height
);
1046 wxSizeEvent
event(newSize
, GetId());
1047 event
.SetEventObject(this);
1048 GetEventHandler()->ProcessEvent(event
);
1052 void wxWindowMGL::DoSetClientSize(int width
, int height
)
1054 SetSize(width
, height
);
1057 // ---------------------------------------------------------------------------
1059 // ---------------------------------------------------------------------------
1061 int wxWindowMGL::GetCharHeight() const
1065 return dc
.GetCharHeight();
1068 int wxWindowMGL::GetCharWidth() const
1072 return dc
.GetCharWidth();
1075 void wxWindowMGL::GetTextExtent(const wxString
& string
,
1077 int *descent
, int *externalLeading
,
1078 const wxFont
*theFont
) const
1083 dc
.GetTextExtent(string
, x
, y
, descent
, externalLeading
, (wxFont
*)theFont
);
1087 // ---------------------------------------------------------------------------
1089 // ---------------------------------------------------------------------------
1091 void wxWindowMGL::Clear()
1093 wxClientDC
dc((wxWindow
*)this);
1094 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1095 dc
.SetBackground(brush
);
1099 #include "wx/menu.h"
1100 void wxWindowMGL::Refresh(bool eraseBack
, const wxRect
*rect
)
1102 if ( m_eraseBackground
== -1 )
1103 m_eraseBackground
= eraseBack
;
1105 m_eraseBackground
|= eraseBack
;
1110 r
.left
= rect
->GetLeft(), r
.right
= rect
->GetRight();
1111 r
.top
= rect
->GetTop(), r
.bottom
= rect
->GetBottom();
1112 MGL_wmInvalidateWindowRect(GetHandle(), &r
);
1115 MGL_wmInvalidateWindow(GetHandle());
1118 void wxWindowMGL::Update()
1121 MGL_wmUpdateDC(g_winMng
);
1124 void wxWindowMGL::Freeze()
1127 m_refreshAfterThaw
= false;
1130 void wxWindowMGL::Thaw()
1133 if ( m_refreshAfterThaw
)
1137 void wxWindowMGL::HandlePaint(MGLDevCtx
*dc
)
1141 // Don't paint anything if the window is frozen.
1142 m_refreshAfterThaw
= true;
1147 // FIXME_MGL -- debugging stuff, to be removed!
1148 static int debugPaintEvents
= -1;
1149 if ( debugPaintEvents
== -1 )
1150 debugPaintEvents
= wxGetEnv(wxT("WXMGL_DEBUG_PAINT_EVENTS"), NULL
);
1151 if ( debugPaintEvents
)
1153 dc
->setColorRGB(255,0,255);
1154 dc
->fillRect(-1000,-1000,2000,2000);
1160 dc
->getClipRegion(clip
);
1161 m_updateRegion
= wxRegion(clip
);
1165 // must hide caret temporarily, otherwise we'd get rendering artifacts
1166 wxCaret
*caret
= GetCaret();
1169 #endif // wxUSE_CARET
1171 if ( m_eraseBackground
!= 0 )
1173 wxWindowDC
dc((wxWindow
*)this);
1174 wxEraseEvent
eventEr(m_windowId
, &dc
);
1175 eventEr
.SetEventObject(this);
1176 GetEventHandler()->ProcessEvent(eventEr
);
1178 m_eraseBackground
= -1;
1180 wxNcPaintEvent
eventNc(GetId());
1181 eventNc
.SetEventObject(this);
1182 GetEventHandler()->ProcessEvent(eventNc
);
1184 wxPaintEvent
eventPt(GetId());
1185 eventPt
.SetEventObject(this);
1186 GetEventHandler()->ProcessEvent(eventPt
);
1191 #endif // wxUSE_CARET
1193 m_paintMGLDC
= NULL
;
1194 m_updateRegion
.Clear();
1198 // Find the wxWindow at the current mouse position, returning the mouse
1200 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1202 return wxFindWindowAtPoint(pt
= wxGetMousePosition());
1205 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
1207 window_t
*wnd
= MGL_wmGetWindowAtPosition(g_winMng
, pt
.x
, pt
.y
);
1208 return (wxWindow
*)wnd
->userData
;
1212 // ---------------------------------------------------------------------------
1213 // idle events processing
1214 // ---------------------------------------------------------------------------
1216 void wxWindowMGL::OnInternalIdle()
1218 if (wxUpdateUIEvent::CanUpdate(this))
1219 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);