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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
20 #pragma implementation "window.h"
23 // For compilers that support precompilation, includes "wx.h".
24 #include "wx/wxprec.h"
31 #include "wx/window.h"
32 #include "wx/msgdlg.h"
36 #include "wx/dcclient.h"
43 #if wxUSE_DRAG_AND_DROP
48 #include "wx/sysopt.h"
49 #include "wx/mgl/private.h"
51 #include "wx/dcscreen.h"
56 #include "wx/tooltip.h"
59 // ---------------------------------------------------------------------------
61 // ---------------------------------------------------------------------------
63 // MGL window manager and associated DC.
64 winmng_t
*g_winMng
= NULL
;
65 MGLDevCtx
*g_displayDC
= NULL
;
67 // the window that has keyboard focus:
68 static wxWindowMGL
*gs_focusedWindow
= NULL
;
69 // the window that is about to be focused after currently focused
71 static wxWindow
*gs_toBeFocusedWindow
= NULL
;
72 // the window that is currently under mouse cursor:
73 static wxWindowMGL
*gs_windowUnderMouse
= NULL
;
74 // the window that has mouse capture
75 static wxWindowMGL
*gs_mouseCapture
= NULL
;
76 // the frame that is currently active (i.e. its child has focus). It is
77 // used to generate wxActivateEvents
78 static wxWindowMGL
*gs_activeFrame
= NULL
;
80 // ---------------------------------------------------------------------------
82 // ---------------------------------------------------------------------------
84 // Custom identifiers used to distinguish between various event handlers
85 // and capture handlers passed to MGL_wm
88 wxMGL_CAPTURE_MOUSE
= 1,
89 wxMGL_CAPTURE_KEYB
= 2
93 // ---------------------------------------------------------------------------
95 // ---------------------------------------------------------------------------
97 // Returns toplevel grandparent of given window:
98 static wxWindowMGL
* wxGetTopLevelParent(wxWindowMGL
*win
)
100 wxWindowMGL
*p
= win
;
101 while (p
&& !p
->IsTopLevel())
106 // An easy way to capture screenshots:
107 static void wxCaptureScreenshot(bool activeWindowOnly
)
110 #define SCREENSHOT_FILENAME _T("sshot%03i.png")
112 #define SCREENSHOT_FILENAME _T("screenshot-%03i.png")
114 static int screenshot_num
= 0;
119 screenshot
.Printf(SCREENSHOT_FILENAME
, screenshot_num
++);
120 } while ( wxFileExists(screenshot
) && screenshot_num
< 1000 );
122 wxRect
r(0, 0, g_displayDC
->sizex(), g_displayDC
->sizey());
124 if ( activeWindowOnly
&& gs_activeFrame
)
126 r
.Intersect(gs_activeFrame
->GetRect());
129 g_displayDC
->savePNGFromDC(screenshot
.mb_str(),
130 r
.x
, r
. y
, r
.x
+r
.width
, r
.y
+r
.height
);
132 wxMessageBox(wxString::Format(_T("Screenshot captured: %s"),
133 screenshot
.c_str()));
136 // ---------------------------------------------------------------------------
138 // ---------------------------------------------------------------------------
140 static void MGLAPI
wxWindowPainter(window_t
*wnd
, MGLDC
*dc
)
142 wxWindowMGL
*w
= (wxWindow
*) wnd
->userData
;
144 if ( w
&& !(w
->GetWindowStyle() & wxTRANSPARENT_WINDOW
) )
147 w
->HandlePaint(&ctx
);
151 static ibool MGLAPI
wxWindowMouseHandler(window_t
*wnd
, event_t
*e
)
153 wxWindowMGL
*win
= (wxWindowMGL
*)MGL_wmGetWindowUserData(wnd
);
154 wxPoint
orig(win
->GetClientAreaOrigin());
157 MGL_wmCoordGlobalToLocal(win
->GetHandle(),
158 e
->where_x
, e
->where_y
, &where
.x
, &where
.y
);
160 for (wxWindowMGL
*w
= win
; w
; w
= w
->GetParent())
162 if ( !w
->IsEnabled() )
164 if ( w
->IsTopLevel() )
168 wxEventType type
= wxEVT_NULL
;
170 event
.SetEventObject(win
);
171 event
.SetTimestamp(e
->when
);
172 event
.m_x
= where
.x
- orig
.x
;
173 event
.m_y
= where
.y
- orig
.y
;
174 event
.m_shiftDown
= e
->modifiers
& EVT_SHIFTKEY
;
175 event
.m_controlDown
= e
->modifiers
& EVT_CTRLSTATE
;
176 event
.m_altDown
= e
->modifiers
& EVT_LEFTALT
;
177 event
.m_metaDown
= e
->modifiers
& EVT_RIGHTALT
;
178 event
.m_leftDown
= e
->modifiers
& EVT_LEFTBUT
;
179 event
.m_middleDown
= e
->modifiers
& EVT_MIDDLEBUT
;
180 event
.m_rightDown
= e
->modifiers
& EVT_RIGHTBUT
;
185 // Change focus if the user clicks outside focused window:
186 if ( win
->AcceptsFocus() && wxWindow::FindFocus() != win
)
189 if ( e
->message
& EVT_DBLCLICK
)
191 if ( e
->message
& EVT_LEFTBMASK
)
192 type
= wxEVT_LEFT_DCLICK
;
193 else if ( e
->message
& EVT_MIDDLEBMASK
)
194 type
= wxEVT_MIDDLE_DCLICK
;
195 else if ( e
->message
& EVT_RIGHTBMASK
)
196 type
= wxEVT_RIGHT_DCLICK
;
200 if ( e
->message
& EVT_LEFTBMASK
)
201 type
= wxEVT_LEFT_DOWN
;
202 else if ( e
->message
& EVT_MIDDLEBMASK
)
203 type
= wxEVT_MIDDLE_DOWN
;
204 else if ( e
->message
& EVT_RIGHTBMASK
)
205 type
= wxEVT_RIGHT_DOWN
;
211 if ( e
->message
& EVT_LEFTBMASK
)
212 type
= wxEVT_LEFT_UP
;
213 else if ( e
->message
& EVT_MIDDLEBMASK
)
214 type
= wxEVT_MIDDLE_UP
;
215 else if ( e
->message
& EVT_RIGHTBMASK
)
216 type
= wxEVT_RIGHT_UP
;
220 if ( !gs_mouseCapture
)
222 if ( win
!= gs_windowUnderMouse
)
224 if ( gs_windowUnderMouse
)
226 wxMouseEvent
event2(event
);
227 MGL_wmCoordGlobalToLocal(gs_windowUnderMouse
->GetHandle(),
228 e
->where_x
, e
->where_y
,
229 &event2
.m_x
, &event2
.m_y
);
231 wxPoint
orig(gs_windowUnderMouse
->GetClientAreaOrigin());
232 event2
.m_x
-= orig
.x
;
233 event2
.m_y
-= orig
.y
;
235 event2
.SetEventObject(gs_windowUnderMouse
);
236 event2
.SetEventType(wxEVT_LEAVE_WINDOW
);
237 gs_windowUnderMouse
->GetEventHandler()->ProcessEvent(event2
);
240 wxMouseEvent
event3(event
);
241 event3
.SetEventType(wxEVT_ENTER_WINDOW
);
242 win
->GetEventHandler()->ProcessEvent(event3
);
244 gs_windowUnderMouse
= win
;
247 else // gs_mouseCapture
249 bool inside
= (where
.x
>= 0 &&
251 where
.x
< win
->GetSize().x
&&
252 where
.y
< win
->GetSize().y
);
253 if ( (inside
&& gs_windowUnderMouse
!= win
) ||
254 (!inside
&& gs_windowUnderMouse
== win
) )
256 wxMouseEvent
evt(inside
?
257 wxEVT_ENTER_WINDOW
: wxEVT_LEAVE_WINDOW
);
258 evt
.SetEventObject(win
);
259 win
->GetEventHandler()->ProcessEvent(evt
);
260 gs_windowUnderMouse
= inside
? win
: NULL
;
271 if ( type
== wxEVT_NULL
)
277 event
.SetEventType(type
);
278 return win
->GetEventHandler()->ProcessEvent(event
);
282 static long wxScanToKeyCode(event_t
*event
, bool translate
)
284 // VS: make it __WXDEBUG__-only, since we have lots of wxLogTrace calls
285 // here and the arguments would be stored in non-debug executable even
286 // though wxLogTrace would be no-op...
288 #define KEY(mgl_key,wx_key) \
290 wxLogTrace(_T("keyevents"), \
291 _T("key " #mgl_key ", mapped to " #wx_key)); \
295 #define KEY(mgl_key,wx_key) \
296 case mgl_key: key = wx_key; break;
303 switch ( EVT_scanCode(event
->message
) )
305 KEY (KB_padMinus
, WXK_NUMPAD_SUBTRACT
)
306 KEY (KB_padPlus
, WXK_NUMPAD_ADD
)
307 KEY (KB_padTimes
, WXK_NUMPAD_MULTIPLY
)
308 KEY (KB_padDivide
, WXK_NUMPAD_DIVIDE
)
309 KEY (KB_padCenter
, WXK_NUMPAD_SEPARATOR
) // ?
310 KEY (KB_padLeft
, WXK_NUMPAD_LEFT
)
311 KEY (KB_padRight
, WXK_NUMPAD_RIGHT
)
312 KEY (KB_padUp
, WXK_NUMPAD_UP
)
313 KEY (KB_padDown
, WXK_NUMPAD_DOWN
)
314 KEY (KB_padInsert
, WXK_NUMPAD_INSERT
)
315 KEY (KB_padDelete
, WXK_NUMPAD_DELETE
)
316 KEY (KB_padHome
, WXK_NUMPAD_HOME
)
317 KEY (KB_padEnd
, WXK_NUMPAD_END
)
318 KEY (KB_padPageUp
, WXK_NUMPAD_PAGEUP
)
319 //KEY (KB_padPageUp, WXK_NUMPAD_PRIOR)
320 KEY (KB_padPageDown
, WXK_NUMPAD_PAGEDOWN
)
321 //KEY (KB_padPageDown, WXK_NUMPAD_NEXT)
332 KEY (KB_minus
, WXK_SUBTRACT
)
333 KEY (KB_equals
, WXK_ADD
)
334 KEY (KB_backSlash
, '\\')
345 KEY (KB_leftSquareBrace
,'[')
346 KEY (KB_rightSquareBrace
,']')
356 KEY (KB_semicolon
, ';')
357 KEY (KB_apostrophe
, '\'')
367 KEY (KB_divide
, WXK_DIVIDE
)
368 KEY (KB_space
, WXK_SPACE
)
377 switch ( EVT_scanCode(event
->message
) )
379 KEY (KB_padEnter
, WXK_NUMPAD_ENTER
)
389 KEY (KB_F10
, WXK_F10
)
390 KEY (KB_F11
, WXK_F11
)
391 KEY (KB_F12
, WXK_F12
)
392 KEY (KB_left
, WXK_LEFT
)
393 KEY (KB_right
, WXK_RIGHT
)
395 KEY (KB_down
, WXK_DOWN
)
396 KEY (KB_insert
, WXK_INSERT
)
397 KEY (KB_delete
, WXK_DELETE
)
398 KEY (KB_home
, WXK_HOME
)
399 KEY (KB_end
, WXK_END
)
400 KEY (KB_pageUp
, WXK_PAGEUP
)
401 KEY (KB_pageDown
, WXK_PAGEDOWN
)
402 KEY (KB_capsLock
, WXK_CAPITAL
)
403 KEY (KB_numLock
, WXK_NUMLOCK
)
404 KEY (KB_scrollLock
, WXK_SCROLL
)
405 KEY (KB_leftShift
, WXK_SHIFT
)
406 KEY (KB_rightShift
, WXK_SHIFT
)
407 KEY (KB_leftCtrl
, WXK_CONTROL
)
408 KEY (KB_rightCtrl
, WXK_CONTROL
)
409 KEY (KB_leftAlt
, WXK_ALT
)
410 KEY (KB_rightAlt
, WXK_ALT
)
411 KEY (KB_leftWindows
, WXK_START
)
412 KEY (KB_rightWindows
, WXK_START
)
413 KEY (KB_menu
, WXK_MENU
)
414 KEY (KB_sysReq
, WXK_SNAPSHOT
)
415 KEY (KB_esc
, WXK_ESCAPE
)
416 KEY (KB_backspace
, WXK_BACK
)
417 KEY (KB_tab
, WXK_TAB
)
418 KEY (KB_enter
, WXK_RETURN
)
421 key
= EVT_asciiCode(event
->message
);
431 static bool wxHandleSpecialKeys(wxKeyEvent
& event
)
433 // Add an easy way to capture screenshots:
434 if ( event
.m_keyCode
== WXK_SNAPSHOT
435 #ifdef __WXDEBUG__ // FIXME_MGL - remove when KB_sysReq works in MGL!
436 || (event
.m_keyCode
== WXK_F1
&&
437 event
.m_shiftDown
&& event
.m_controlDown
)
441 wxCaptureScreenshot(event
.m_altDown
/*only active wnd?*/);
448 static ibool MGLAPI
wxWindowKeybHandler(window_t
*wnd
, event_t
*e
)
450 wxWindowMGL
*win
= (wxWindowMGL
*)MGL_wmGetWindowUserData(wnd
);
452 if ( !win
->IsEnabled() ) return FALSE
;
455 MGL_wmCoordGlobalToLocal(win
->GetHandle(),
456 e
->where_x
, e
->where_y
, &where
.x
, &where
.y
);
459 event
.SetEventObject(win
);
460 event
.SetTimestamp(e
->when
);
461 event
.m_keyCode
= wxScanToKeyCode(e
, TRUE
);
462 event
.m_scanCode
= 0; // not used by wx at all
465 event
.m_shiftDown
= e
->modifiers
& EVT_SHIFTKEY
;
466 event
.m_controlDown
= e
->modifiers
& EVT_CTRLSTATE
;
467 event
.m_altDown
= e
->modifiers
& EVT_LEFTALT
;
468 event
.m_metaDown
= e
->modifiers
& EVT_RIGHTALT
;
470 if ( e
->what
== EVT_KEYUP
)
472 event
.SetEventType(wxEVT_KEY_UP
);
473 return win
->GetEventHandler()->ProcessEvent(event
);
480 event
.SetEventType(wxEVT_KEY_DOWN
);
483 ret
= win
->GetEventHandler()->ProcessEvent(event
);
485 // wxMSW doesn't send char events with Alt pressed
486 // Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x
487 // will only be sent if it is not in an accelerator table:
488 event2
.m_keyCode
= wxScanToKeyCode(e
, FALSE
);
489 if ( !ret
&& event2
.m_keyCode
!= 0 )
491 event2
.SetEventType(wxEVT_CHAR
);
492 ret
= win
->GetEventHandler()->ProcessEvent(event2
);
495 // Synthetize navigation key event, but do it only if the TAB key
496 // wasn't handled yet:
497 if ( !ret
&& event
.m_keyCode
== WXK_TAB
&&
498 win
->GetParent() && win
->GetParent()->HasFlag(wxTAB_TRAVERSAL
) )
500 wxNavigationKeyEvent navEvent
;
501 navEvent
.SetEventObject(win
->GetParent());
502 // Shift-TAB goes in reverse direction:
503 navEvent
.SetDirection(!event
.m_shiftDown
);
504 // Ctrl-TAB changes the (parent) window, i.e. switch notebook page:
505 navEvent
.SetWindowChange(event
.m_controlDown
);
506 navEvent
.SetCurrentFocus(wxStaticCast(win
, wxWindow
));
507 ret
= win
->GetParent()->GetEventHandler()->ProcessEvent(navEvent
);
510 // Finally, process special meaning keys that are usually
511 // a responsibility of OS or window manager:
513 ret
= wxHandleSpecialKeys(event
);
519 // ---------------------------------------------------------------------------
521 // ---------------------------------------------------------------------------
523 // in wxUniv this class is abstract because it doesn't have DoPopupMenu()
524 IMPLEMENT_ABSTRACT_CLASS(wxWindowMGL
, wxWindowBase
)
526 BEGIN_EVENT_TABLE(wxWindowMGL
, wxWindowBase
)
529 // ===========================================================================
531 // ===========================================================================
533 // ----------------------------------------------------------------------------
534 // constructors and such
535 // ----------------------------------------------------------------------------
537 extern wxVideoMode
wxGetDefaultDisplayMode();
539 void wxWindowMGL::Init()
541 // First of all, make sure window manager is up and running. If it is
542 // not the case, initialize it in default display mode
545 if ( !wxTheApp
->SetDisplayMode(wxGetDefaultDisplayMode()) )
546 wxLogFatalError(_("Cannot initialize display."));
554 m_eraseBackground
= -1;
558 wxWindowMGL::~wxWindowMGL()
562 m_isBeingDeleted
= TRUE
;
564 if ( gs_mouseCapture
== this )
567 if (gs_activeFrame
== this)
569 gs_activeFrame
= NULL
;
570 // activate next frame in Z-order:
573 wxWindowMGL
*win
= (wxWindowMGL
*)m_wnd
->prev
->userData
;
576 else if ( m_wnd
->next
)
578 wxWindowMGL
*win
= (wxWindowMGL
*)m_wnd
->next
->userData
;
583 if ( gs_focusedWindow
== this )
586 if ( gs_windowUnderMouse
== this )
587 gs_windowUnderMouse
= NULL
;
592 MGL_wmDestroyWindow(m_wnd
);
595 // real construction (Init() must have been called before!)
596 bool wxWindowMGL::Create(wxWindow
*parent
,
601 const wxString
& name
)
603 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
607 parent
->AddChild(this);
610 x
= pos
.x
, y
= pos
.y
;
612 x
= 0; // FIXME_MGL, something better, see GTK+
614 y
= 0; // FIXME_MGL, something better, see GTK+
615 AdjustForParentClientOrigin(x
, y
, 0);
616 w
= WidthDefault(size
.x
);
617 h
= HeightDefault(size
.y
);
620 window_t
*wnd_parent
= parent
? parent
->GetHandle() : NULL
;
622 if ( style
& wxFULL_REPAINT_ON_RESIZE
)
624 mgl_style
|= MGL_WM_FULL_REPAINT_ON_RESIZE
;
626 if ( style
& wxSTAY_ON_TOP
)
628 mgl_style
|= MGL_WM_ALWAYS_ON_TOP
;
630 if ( style
& wxPOPUP_WINDOW
)
632 mgl_style
|= MGL_WM_ALWAYS_ON_TOP
;
633 // it is created hidden as other top level windows
638 window_t
*wnd
= MGL_wmCreateWindow(g_winMng
, wnd_parent
, x
, y
, w
, h
);
640 MGL_wmSetWindowFlags(wnd
, mgl_style
);
641 MGL_wmShowWindow(wnd
, m_isShown
);
648 void wxWindowMGL::SetMGLwindow_t(struct window_t
*wnd
)
651 MGL_wmDestroyWindow(m_wnd
);
654 if ( !m_wnd
) return;
656 m_isShown
= m_wnd
->visible
;
658 MGL_wmSetWindowUserData(m_wnd
, (void*) this);
659 MGL_wmSetWindowPainter(m_wnd
, wxWindowPainter
);
660 MGL_wmPushWindowEventHandler(m_wnd
, wxWindowMouseHandler
, EVT_MOUSEEVT
, 0);
661 MGL_wmPushWindowEventHandler(m_wnd
, wxWindowKeybHandler
, EVT_KEYEVT
, 0);
664 MGL_wmSetWindowCursor(m_wnd
, *m_cursor
.GetMGLCursor());
666 MGL_wmSetWindowCursor(m_wnd
, *wxSTANDARD_CURSOR
->GetMGLCursor());
669 // ---------------------------------------------------------------------------
671 // ---------------------------------------------------------------------------
673 void wxWindowMGL::SetFocus()
675 if ( gs_focusedWindow
== this ) return;
677 wxWindowMGL
*oldFocusedWindow
= gs_focusedWindow
;
679 if ( gs_focusedWindow
)
681 gs_toBeFocusedWindow
= (wxWindow
*)this;
682 gs_focusedWindow
->KillFocus();
683 gs_toBeFocusedWindow
= NULL
;
686 gs_focusedWindow
= this;
688 MGL_wmCaptureEvents(GetHandle(), EVT_KEYEVT
, wxMGL_CAPTURE_KEYB
);
690 wxWindowMGL
*active
= wxGetTopLevelParent(this);
691 if ( !(m_windowStyle
& wxPOPUP_WINDOW
) && active
!= gs_activeFrame
)
693 if ( gs_activeFrame
)
695 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, gs_activeFrame
->GetId());
696 event
.SetEventObject(gs_activeFrame
);
697 gs_activeFrame
->GetEventHandler()->ProcessEvent(event
);
700 gs_activeFrame
= active
;
701 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, gs_activeFrame
->GetId());
702 event
.SetEventObject(gs_activeFrame
);
703 gs_activeFrame
->GetEventHandler()->ProcessEvent(event
);
706 wxFocusEvent
event(wxEVT_SET_FOCUS
, GetId());
707 event
.SetEventObject(this);
708 event
.SetWindow((wxWindow
*)oldFocusedWindow
);
709 GetEventHandler()->ProcessEvent(event
);
712 // caret needs to be informed about focus change
713 wxCaret
*caret
= GetCaret();
716 #endif // wxUSE_CARET
719 void wxWindowMGL::KillFocus()
721 if ( gs_focusedWindow
!= this ) return;
722 gs_focusedWindow
= NULL
;
724 if ( m_isBeingDeleted
) return;
726 MGL_wmUncaptureEvents(GetHandle(), wxMGL_CAPTURE_KEYB
);
729 // caret needs to be informed about focus change
730 wxCaret
*caret
= GetCaret();
732 caret
->OnKillFocus();
733 #endif // wxUSE_CARET
735 wxFocusEvent
event(wxEVT_KILL_FOCUS
, GetId());
736 event
.SetEventObject(this);
737 event
.SetWindow(gs_toBeFocusedWindow
);
738 GetEventHandler()->ProcessEvent(event
);
741 // ----------------------------------------------------------------------------
742 // this wxWindowBase function is implemented here (in platform-specific file)
743 // because it is static and so couldn't be made virtual
744 // ----------------------------------------------------------------------------
745 wxWindow
*wxWindowBase::FindFocus()
747 return (wxWindow
*)gs_focusedWindow
;
750 bool wxWindowMGL::Show(bool show
)
752 if ( !wxWindowBase::Show(show
) )
755 MGL_wmShowWindow(m_wnd
, show
);
757 if (!show
&& gs_activeFrame
== this)
759 // activate next frame in Z-order:
762 wxWindowMGL
*win
= (wxWindowMGL
*)m_wnd
->prev
->userData
;
765 else if ( m_wnd
->next
)
767 wxWindowMGL
*win
= (wxWindowMGL
*)m_wnd
->next
->userData
;
772 gs_activeFrame
= NULL
;
779 // Raise the window to the top of the Z order
780 void wxWindowMGL::Raise()
782 MGL_wmRaiseWindow(m_wnd
);
785 // Lower the window to the bottom of the Z order
786 void wxWindowMGL::Lower()
788 MGL_wmLowerWindow(m_wnd
);
791 void wxWindowMGL::DoCaptureMouse()
793 if ( gs_mouseCapture
)
794 MGL_wmUncaptureEvents(gs_mouseCapture
->m_wnd
, wxMGL_CAPTURE_MOUSE
);
796 gs_mouseCapture
= this;
797 MGL_wmCaptureEvents(m_wnd
, EVT_MOUSEEVT
, wxMGL_CAPTURE_MOUSE
);
800 void wxWindowMGL::DoReleaseMouse()
802 wxASSERT_MSG( gs_mouseCapture
== this, wxT("attempt to release mouse, but this window hasn't captured it") );
804 MGL_wmUncaptureEvents(m_wnd
, wxMGL_CAPTURE_MOUSE
);
805 gs_mouseCapture
= NULL
;
808 /* static */ wxWindow
*wxWindowBase::GetCapture()
810 return (wxWindow
*)gs_mouseCapture
;
813 bool wxWindowMGL::SetCursor(const wxCursor
& cursor
)
815 if ( !wxWindowBase::SetCursor(cursor
) )
822 MGL_wmSetWindowCursor(m_wnd
, *m_cursor
.GetMGLCursor());
824 MGL_wmSetWindowCursor(m_wnd
, *wxSTANDARD_CURSOR
->GetMGLCursor());
829 void wxWindowMGL::WarpPointer(int x
, int y
)
832 wxDisplaySize(&w
, &h
);
834 ClientToScreen(&x
, &y
);
844 EVT_setMousePos(x
, y
);
847 // Set this window to be the child of 'parent'.
848 bool wxWindowMGL::Reparent(wxWindowBase
*parent
)
850 if ( !wxWindowBase::Reparent(parent
) )
853 MGL_wmReparentWindow(m_wnd
, parent
->GetHandle());
859 // ---------------------------------------------------------------------------
861 // ---------------------------------------------------------------------------
863 #if wxUSE_DRAG_AND_DROP
865 void wxWindowMGL::SetDropTarget(wxDropTarget
*pDropTarget
)
867 if ( m_dropTarget
!= 0 ) {
868 m_dropTarget
->Revoke(m_hWnd
);
872 m_dropTarget
= pDropTarget
;
873 if ( m_dropTarget
!= 0 )
874 m_dropTarget
->Register(m_hWnd
);
877 #endif // wxUSE_DRAG_AND_DROP
879 // old style file-manager drag&drop support: we retain the old-style
880 // DragAcceptFiles in parallel with SetDropTarget.
881 void wxWindowMGL::DragAcceptFiles(bool accept
)
884 HWND hWnd
= GetHwnd();
886 ::DragAcceptFiles(hWnd
, (BOOL
)accept
);
890 // ---------------------------------------------------------------------------
891 // moving and resizing
892 // ---------------------------------------------------------------------------
895 void wxWindowMGL::DoGetSize(int *x
, int *y
) const
897 wxASSERT_MSG( m_wnd
, wxT("invalid window") );
899 if (x
) *x
= m_wnd
->width
;
900 if (y
) *y
= m_wnd
->height
;
903 void wxWindowMGL::DoGetPosition(int *x
, int *y
) const
905 wxASSERT_MSG( m_wnd
, wxT("invalid window") );
908 AdjustForParentClientOrigin(pX
, pY
, 0);
910 if (x
) *x
= m_wnd
->x
- pX
;
911 if (y
) *y
= m_wnd
->y
- pY
;
914 void wxWindowMGL::DoScreenToClient(int *x
, int *y
) const
917 MGL_wmCoordGlobalToLocal(m_wnd
, 0, 0, &ax
, &ay
);
924 void wxWindowMGL::DoClientToScreen(int *x
, int *y
) const
927 MGL_wmCoordLocalToGlobal(m_wnd
, 0, 0, &ax
, &ay
);
934 // Get size *available for subwindows* i.e. excluding menu bar etc.
935 void wxWindowMGL::DoGetClientSize(int *x
, int *y
) const
940 void wxWindowMGL::DoMoveWindow(int x
, int y
, int width
, int height
)
942 MGL_wmSetWindowPosition(GetHandle(), x
, y
, width
, height
);
945 // set the size of the window: if the dimensions are positive, just use them,
946 // but if any of them is equal to -1, it means that we must find the value for
947 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
948 // which case -1 is a valid value for x and y)
950 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
951 // the width/height to best suit our contents, otherwise we reuse the current
953 void wxWindowMGL::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
955 // get the current size and position...
956 int currentX
, currentY
;
957 GetPosition(¤tX
, ¤tY
);
958 int currentW
,currentH
;
959 GetSize(¤tW
, ¤tH
);
961 // ... and don't do anything (avoiding flicker) if it's already ok
962 if ( x
== currentX
&& y
== currentY
&&
963 width
== currentW
&& height
== currentH
)
968 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
970 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
973 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
978 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
980 size
= DoGetBestSize();
985 // just take the current one
992 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
996 size
= DoGetBestSize();
998 //else: already called DoGetBestSize() above
1004 // just take the current one
1009 int maxWidth
= GetMaxWidth(),
1010 minWidth
= GetMinWidth(),
1011 maxHeight
= GetMaxHeight(),
1012 minHeight
= GetMinHeight();
1014 if ( minWidth
!= -1 && width
< minWidth
) width
= minWidth
;
1015 if ( maxWidth
!= -1 && width
> maxWidth
) width
= maxWidth
;
1016 if ( minHeight
!= -1 && height
< minHeight
) height
= minHeight
;
1017 if ( maxHeight
!= -1 && height
> maxHeight
) height
= maxHeight
;
1019 if ( m_wnd
->x
!= x
|| m_wnd
->y
!= y
||
1020 (int)m_wnd
->width
!= width
|| (int)m_wnd
->height
!= height
)
1022 DoMoveWindow(x
, y
, width
, height
);
1024 wxSizeEvent
event(wxSize(width
, height
), GetId());
1025 event
.SetEventObject(this);
1026 GetEventHandler()->ProcessEvent(event
);
1030 void wxWindowMGL::DoSetClientSize(int width
, int height
)
1032 SetSize(width
, height
);
1035 // ---------------------------------------------------------------------------
1037 // ---------------------------------------------------------------------------
1039 int wxWindowMGL::GetCharHeight() const
1043 return dc
.GetCharHeight();
1046 int wxWindowMGL::GetCharWidth() const
1050 return dc
.GetCharWidth();
1053 void wxWindowMGL::GetTextExtent(const wxString
& string
,
1055 int *descent
, int *externalLeading
,
1056 const wxFont
*theFont
) const
1061 dc
.GetTextExtent(string
, x
, y
, descent
, externalLeading
, (wxFont
*)theFont
);
1065 // ---------------------------------------------------------------------------
1067 // ---------------------------------------------------------------------------
1069 void wxWindowMGL::Clear()
1071 wxClientDC
dc((wxWindow
*)this);
1072 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1073 dc
.SetBackground(brush
);
1077 #include "wx/menu.h"
1078 void wxWindowMGL::Refresh(bool eraseBack
, const wxRect
*rect
)
1080 if ( m_eraseBackground
== -1 )
1081 m_eraseBackground
= eraseBack
;
1083 m_eraseBackground
|= eraseBack
;
1088 r
.left
= rect
->GetLeft(), r
.right
= rect
->GetRight();
1089 r
.top
= rect
->GetTop(), r
.bottom
= rect
->GetBottom();
1090 MGL_wmInvalidateWindowRect(GetHandle(), &r
);
1093 MGL_wmInvalidateWindow(GetHandle());
1096 void wxWindowMGL::Update()
1099 MGL_wmUpdateDC(g_winMng
);
1102 void wxWindowMGL::Freeze()
1105 m_refreshAfterThaw
= FALSE
;
1108 void wxWindowMGL::Thaw()
1111 if ( m_refreshAfterThaw
)
1115 void wxWindowMGL::HandlePaint(MGLDevCtx
*dc
)
1119 // Don't paint anything if the window is frozen.
1120 m_refreshAfterThaw
= TRUE
;
1125 // FIXME_MGL -- debugging stuff, to be removed!
1126 static int debugPaintEvents
= -1;
1127 if ( debugPaintEvents
== -1 )
1128 debugPaintEvents
= wxGetEnv(wxT("WXMGL_DEBUG_PAINT_EVENTS"), NULL
);
1129 if ( debugPaintEvents
)
1131 dc
->setColorRGB(255,0,255);
1132 dc
->fillRect(-1000,-1000,2000,2000);
1138 dc
->getClipRegion(clip
);
1139 m_updateRegion
= wxRegion(clip
);
1143 // must hide caret temporarily, otherwise we'd get rendering artifacts
1144 wxCaret
*caret
= GetCaret();
1147 #endif // wxUSE_CARET
1149 if ( m_eraseBackground
!= 0 )
1151 wxWindowDC
dc((wxWindow
*)this);
1152 wxEraseEvent
eventEr(m_windowId
, &dc
);
1153 eventEr
.SetEventObject(this);
1154 GetEventHandler()->ProcessEvent(eventEr
);
1156 m_eraseBackground
= -1;
1158 wxNcPaintEvent
eventNc(GetId());
1159 eventNc
.SetEventObject(this);
1160 GetEventHandler()->ProcessEvent(eventNc
);
1162 wxPaintEvent
eventPt(GetId());
1163 eventPt
.SetEventObject(this);
1164 GetEventHandler()->ProcessEvent(eventPt
);
1169 #endif // wxUSE_CARET
1171 m_paintMGLDC
= NULL
;
1172 m_updateRegion
.Clear();
1176 // Find the wxWindow at the current mouse position, returning the mouse
1178 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1180 return wxFindWindowAtPoint(pt
= wxGetMousePosition());
1183 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
1185 window_t
*wnd
= MGL_wmGetWindowAtPosition(g_winMng
, pt
.x
, pt
.y
);
1186 return (wxWindow
*)wnd
->userData
;
1190 // ---------------------------------------------------------------------------
1191 // idle events processing
1192 // ---------------------------------------------------------------------------
1194 void wxWindowMGL::OnInternalIdle()
1196 if (wxUpdateUIEvent::CanUpdate(this))
1197 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);