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 license
9 /////////////////////////////////////////////////////////////////////////////
11 // ===========================================================================
13 // ===========================================================================
15 // ---------------------------------------------------------------------------
17 // ---------------------------------------------------------------------------
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(_("Screenshot captured: ") + wxString(screenshot
));
135 // ---------------------------------------------------------------------------
137 // ---------------------------------------------------------------------------
139 static void MGLAPI
wxWindowPainter(window_t
*wnd
, MGLDC
*dc
)
141 wxWindowMGL
*w
= (wxWindow
*) wnd
->userData
;
143 if ( w
&& !(w
->GetWindowStyle() & wxTRANSPARENT_WINDOW
) )
146 w
->HandlePaint(&ctx
);
150 static ibool MGLAPI
wxWindowMouseHandler(window_t
*wnd
, event_t
*e
)
152 wxWindowMGL
*win
= (wxWindowMGL
*)MGL_wmGetWindowUserData(wnd
);
153 wxPoint
orig(win
->GetClientAreaOrigin());
156 MGL_wmCoordGlobalToLocal(win
->GetHandle(),
157 e
->where_x
, e
->where_y
, &where
.x
, &where
.y
);
159 for (wxWindowMGL
*w
= win
; w
; w
= w
->GetParent())
161 if ( !w
->IsEnabled() )
163 if ( w
->IsTopLevel() )
167 wxEventType type
= wxEVT_NULL
;
169 event
.SetEventObject(win
);
170 event
.SetTimestamp(e
->when
);
171 event
.m_x
= where
.x
- orig
.x
;
172 event
.m_y
= where
.y
- orig
.y
;
173 event
.m_shiftDown
= e
->modifiers
& EVT_SHIFTKEY
;
174 event
.m_controlDown
= e
->modifiers
& EVT_CTRLSTATE
;
175 event
.m_altDown
= e
->modifiers
& EVT_LEFTALT
;
176 event
.m_metaDown
= e
->modifiers
& EVT_RIGHTALT
;
177 event
.m_leftDown
= e
->modifiers
& EVT_LEFTBUT
;
178 event
.m_middleDown
= e
->modifiers
& EVT_MIDDLEBUT
;
179 event
.m_rightDown
= e
->modifiers
& EVT_RIGHTBUT
;
184 // Change focus if the user clicks outside focused window:
185 if ( win
->AcceptsFocus() && wxWindow::FindFocus() != win
)
188 if ( e
->message
& EVT_DBLCLICK
)
190 if ( e
->message
& EVT_LEFTBMASK
)
191 type
= wxEVT_LEFT_DCLICK
;
192 else if ( e
->message
& EVT_MIDDLEBMASK
)
193 type
= wxEVT_MIDDLE_DCLICK
;
194 else if ( e
->message
& EVT_RIGHTBMASK
)
195 type
= wxEVT_RIGHT_DCLICK
;
199 if ( e
->message
& EVT_LEFTBMASK
)
200 type
= wxEVT_LEFT_DOWN
;
201 else if ( e
->message
& EVT_MIDDLEBMASK
)
202 type
= wxEVT_MIDDLE_DOWN
;
203 else if ( e
->message
& EVT_RIGHTBMASK
)
204 type
= wxEVT_RIGHT_DOWN
;
210 if ( e
->message
& EVT_LEFTBMASK
)
211 type
= wxEVT_LEFT_UP
;
212 else if ( e
->message
& EVT_MIDDLEBMASK
)
213 type
= wxEVT_MIDDLE_UP
;
214 else if ( e
->message
& EVT_RIGHTBMASK
)
215 type
= wxEVT_RIGHT_UP
;
219 if ( !gs_mouseCapture
)
221 if ( win
!= gs_windowUnderMouse
)
223 if ( gs_windowUnderMouse
)
225 wxMouseEvent
event2(event
);
226 MGL_wmCoordGlobalToLocal(gs_windowUnderMouse
->GetHandle(),
227 e
->where_x
, e
->where_y
,
228 &event2
.m_x
, &event2
.m_y
);
230 wxPoint
orig(gs_windowUnderMouse
->GetClientAreaOrigin());
231 event2
.m_x
-= orig
.x
;
232 event2
.m_y
-= orig
.y
;
234 event2
.SetEventObject(gs_windowUnderMouse
);
235 event2
.SetEventType(wxEVT_LEAVE_WINDOW
);
236 gs_windowUnderMouse
->GetEventHandler()->ProcessEvent(event2
);
239 wxMouseEvent
event3(event
);
240 event3
.SetEventType(wxEVT_ENTER_WINDOW
);
241 win
->GetEventHandler()->ProcessEvent(event3
);
243 gs_windowUnderMouse
= win
;
246 else // gs_mouseCapture
248 bool inside
= (where
.x
>= 0 &&
250 where
.x
< win
->GetSize().x
&&
251 where
.y
< win
->GetSize().y
);
252 if ( (inside
&& gs_windowUnderMouse
!= win
) ||
253 (!inside
&& gs_windowUnderMouse
== win
) )
255 wxMouseEvent
evt(inside
?
256 wxEVT_ENTER_WINDOW
: wxEVT_LEAVE_WINDOW
);
257 evt
.SetEventObject(win
);
258 win
->GetEventHandler()->ProcessEvent(evt
);
259 gs_windowUnderMouse
= inside
? win
: NULL
;
270 if ( type
== wxEVT_NULL
)
276 event
.SetEventType(type
);
277 return win
->GetEventHandler()->ProcessEvent(event
);
281 static long wxScanToKeyCode(event_t
*event
, bool translate
)
283 // VS: make it __WXDEBUG__-only, since we have lots of wxLogTrace calls
284 // here and the arguments would be stored in non-debug executable even
285 // though wxLogTrace would be no-op...
287 #define KEY(mgl_key,wx_key) \
289 wxLogTrace(_T("keyevents"), \
290 _T("key " #mgl_key ", mapped to " #wx_key)); \
294 #define KEY(mgl_key,wx_key) \
295 case mgl_key: key = wx_key; break;
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
, WXK_NUMPAD_SEPARATOR
) // ?
309 KEY (KB_padLeft
, WXK_NUMPAD_LEFT
)
310 KEY (KB_padRight
, WXK_NUMPAD_RIGHT
)
311 KEY (KB_padUp
, WXK_NUMPAD_UP
)
312 KEY (KB_padDown
, WXK_NUMPAD_DOWN
)
313 KEY (KB_padInsert
, WXK_NUMPAD_INSERT
)
314 KEY (KB_padDelete
, WXK_NUMPAD_DELETE
)
315 KEY (KB_padHome
, WXK_NUMPAD_HOME
)
316 KEY (KB_padEnd
, WXK_NUMPAD_END
)
317 KEY (KB_padPageUp
, WXK_NUMPAD_PAGEUP
)
318 //KEY (KB_padPageUp, WXK_NUMPAD_PRIOR)
319 KEY (KB_padPageDown
, WXK_NUMPAD_PAGEDOWN
)
320 //KEY (KB_padPageDown, WXK_NUMPAD_NEXT)
331 KEY (KB_minus
, WXK_SUBTRACT
)
332 KEY (KB_equals
, WXK_ADD
)
333 KEY (KB_backSlash
, '\\')
344 KEY (KB_leftSquareBrace
,'[')
345 KEY (KB_rightSquareBrace
,']')
355 KEY (KB_semicolon
, ';')
356 KEY (KB_apostrophe
, '\'')
366 KEY (KB_divide
, WXK_DIVIDE
)
367 KEY (KB_space
, WXK_SPACE
)
376 switch ( EVT_scanCode(event
->message
) )
378 KEY (KB_padEnter
, WXK_NUMPAD_ENTER
)
388 KEY (KB_F10
, WXK_F10
)
389 KEY (KB_F11
, WXK_F11
)
390 KEY (KB_F12
, WXK_F12
)
391 KEY (KB_left
, WXK_LEFT
)
392 KEY (KB_right
, WXK_RIGHT
)
394 KEY (KB_down
, WXK_DOWN
)
395 KEY (KB_insert
, WXK_INSERT
)
396 KEY (KB_delete
, WXK_DELETE
)
397 KEY (KB_home
, WXK_HOME
)
398 KEY (KB_end
, WXK_END
)
399 KEY (KB_pageUp
, WXK_PAGEUP
)
400 KEY (KB_pageDown
, WXK_PAGEDOWN
)
401 KEY (KB_capsLock
, WXK_CAPITAL
)
402 KEY (KB_numLock
, WXK_NUMLOCK
)
403 KEY (KB_scrollLock
, WXK_SCROLL
)
404 KEY (KB_leftShift
, WXK_SHIFT
)
405 KEY (KB_rightShift
, WXK_SHIFT
)
406 KEY (KB_leftCtrl
, WXK_CONTROL
)
407 KEY (KB_rightCtrl
, WXK_CONTROL
)
408 KEY (KB_leftAlt
, WXK_ALT
)
409 KEY (KB_rightAlt
, WXK_ALT
)
410 KEY (KB_leftWindows
, WXK_START
)
411 KEY (KB_rightWindows
, WXK_START
)
412 KEY (KB_menu
, WXK_MENU
)
413 KEY (KB_sysReq
, WXK_SNAPSHOT
)
414 KEY (KB_esc
, WXK_ESCAPE
)
415 KEY (KB_backspace
, WXK_BACK
)
416 KEY (KB_tab
, WXK_TAB
)
417 KEY (KB_enter
, WXK_RETURN
)
420 key
= EVT_asciiCode(event
->message
);
430 static bool wxHandleSpecialKeys(wxKeyEvent
& event
)
432 // Add an easy way to capture screenshots:
433 if ( event
.m_keyCode
== WXK_SNAPSHOT
434 #ifdef __WXDEBUG__ // FIXME_MGL - remove when KB_sysReq works in MGL!
435 || (event
.m_keyCode
== WXK_F1
&&
436 event
.m_shiftDown
&& event
.m_controlDown
)
440 wxCaptureScreenshot(event
.m_altDown
/*only active wnd?*/);
447 static ibool MGLAPI
wxWindowKeybHandler(window_t
*wnd
, event_t
*e
)
449 wxWindowMGL
*win
= (wxWindowMGL
*)MGL_wmGetWindowUserData(wnd
);
451 if ( !win
->IsEnabled() ) return FALSE
;
454 MGL_wmCoordGlobalToLocal(win
->GetHandle(),
455 e
->where_x
, e
->where_y
, &where
.x
, &where
.y
);
458 event
.SetEventObject(win
);
459 event
.SetTimestamp(e
->when
);
460 event
.m_keyCode
= wxScanToKeyCode(e
, TRUE
);
461 event
.m_scanCode
= 0; // not used by wx at all
464 event
.m_shiftDown
= e
->modifiers
& EVT_SHIFTKEY
;
465 event
.m_controlDown
= e
->modifiers
& EVT_CTRLSTATE
;
466 event
.m_altDown
= e
->modifiers
& EVT_LEFTALT
;
467 event
.m_metaDown
= e
->modifiers
& EVT_RIGHTALT
;
469 if ( e
->what
== EVT_KEYUP
)
471 event
.SetEventType(wxEVT_KEY_UP
);
472 return win
->GetEventHandler()->ProcessEvent(event
);
479 event
.SetEventType(wxEVT_KEY_DOWN
);
482 ret
= win
->GetEventHandler()->ProcessEvent(event
);
484 // wxMSW doesn't send char events with Alt pressed
485 // Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x
486 // will only be sent if it is not in an accelerator table:
487 event2
.m_keyCode
= wxScanToKeyCode(e
, FALSE
);
488 if ( !ret
&& event2
.m_keyCode
!= 0 )
490 event2
.SetEventType(wxEVT_CHAR
);
491 ret
= win
->GetEventHandler()->ProcessEvent(event2
);
494 // Synthetize navigation key event, but do it only if the TAB key
495 // wasn't handled yet:
496 if ( !ret
&& event
.m_keyCode
== WXK_TAB
&&
497 win
->GetParent() && win
->GetParent()->HasFlag(wxTAB_TRAVERSAL
) )
499 wxNavigationKeyEvent navEvent
;
500 navEvent
.SetEventObject(win
->GetParent());
501 // Shift-TAB goes in reverse direction:
502 navEvent
.SetDirection(!event
.m_shiftDown
);
503 // Ctrl-TAB changes the (parent) window, i.e. switch notebook page:
504 navEvent
.SetWindowChange(event
.m_controlDown
);
505 navEvent
.SetCurrentFocus(wxStaticCast(win
, wxWindow
));
506 ret
= win
->GetParent()->GetEventHandler()->ProcessEvent(navEvent
);
509 // Finally, process special meaning keys that are usually
510 // a responsibility of OS or window manager:
512 ret
= wxHandleSpecialKeys(event
);
518 // ---------------------------------------------------------------------------
520 // ---------------------------------------------------------------------------
522 // in wxUniv this class is abstract because it doesn't have DoPopupMenu()
523 IMPLEMENT_ABSTRACT_CLASS(wxWindowMGL
, wxWindowBase
)
525 BEGIN_EVENT_TABLE(wxWindowMGL
, wxWindowBase
)
526 EVT_IDLE(wxWindowMGL::OnIdle
)
529 // ===========================================================================
531 // ===========================================================================
533 // ----------------------------------------------------------------------------
534 // constructors and such
535 // ----------------------------------------------------------------------------
537 extern wxDisplayModeInfo
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 wxFatalError(_("Cannot initialize display."));
555 m_isBeingDeleted
= FALSE
;
559 m_eraseBackground
= -1;
563 wxWindowMGL::~wxWindowMGL()
565 m_isBeingDeleted
= TRUE
;
567 if ( gs_mouseCapture
== this )
570 if (gs_activeFrame
== this)
572 gs_activeFrame
= NULL
;
573 // activate next frame in Z-order:
576 wxWindowMGL
*win
= (wxWindowMGL
*)m_wnd
->prev
->userData
;
579 else if ( m_wnd
->next
)
581 wxWindowMGL
*win
= (wxWindowMGL
*)m_wnd
->next
->userData
;
586 if ( gs_focusedWindow
== this )
589 if ( gs_windowUnderMouse
== this )
590 gs_windowUnderMouse
= NULL
;
592 // VS: destroy children first and _then_ detach *this from its parent.
593 // If we'd do it the other way around, children wouldn't be able
594 // find their parent frame (see above).
598 m_parent
->RemoveChild(this);
601 MGL_wmDestroyWindow(m_wnd
);
604 // real construction (Init() must have been called before!)
605 bool wxWindowMGL::Create(wxWindow
*parent
,
610 const wxString
& name
)
612 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
616 parent
->AddChild(this);
619 x
= pos
.x
, y
= pos
.y
;
621 x
= 0; // FIXME_MGL, something better, see GTK+
623 y
= 0; // FIXME_MGL, something better, see GTK+
624 AdjustForParentClientOrigin(x
, y
, 0);
625 w
= WidthDefault(size
.x
);
626 h
= HeightDefault(size
.y
);
629 window_t
*wnd_parent
= parent
? parent
->GetHandle() : NULL
;
631 if ( !(style
& wxNO_FULL_REPAINT_ON_RESIZE
) )
633 mgl_style
|= MGL_WM_FULL_REPAINT_ON_RESIZE
;
635 if ( style
& wxSTAY_ON_TOP
)
637 mgl_style
|= MGL_WM_ALWAYS_ON_TOP
;
639 if ( style
& wxPOPUP_WINDOW
)
641 mgl_style
|= MGL_WM_ALWAYS_ON_TOP
;
642 // it is created hidden as other top level windows
647 window_t
*wnd
= MGL_wmCreateWindow(g_winMng
, wnd_parent
, x
, y
, w
, h
);
649 MGL_wmSetWindowFlags(wnd
, mgl_style
);
650 MGL_wmShowWindow(wnd
, m_isShown
);
657 void wxWindowMGL::SetMGLwindow_t(struct window_t
*wnd
)
660 MGL_wmDestroyWindow(m_wnd
);
663 if ( !m_wnd
) return;
665 m_isShown
= m_wnd
->visible
;
667 MGL_wmSetWindowUserData(m_wnd
, (void*) this);
668 MGL_wmSetWindowPainter(m_wnd
, wxWindowPainter
);
669 MGL_wmPushWindowEventHandler(m_wnd
, wxWindowMouseHandler
, EVT_MOUSEEVT
, 0);
670 MGL_wmPushWindowEventHandler(m_wnd
, wxWindowKeybHandler
, EVT_KEYEVT
, 0);
673 MGL_wmSetWindowCursor(m_wnd
, *m_cursor
.GetMGLCursor());
675 MGL_wmSetWindowCursor(m_wnd
, *wxSTANDARD_CURSOR
->GetMGLCursor());
678 // ---------------------------------------------------------------------------
680 // ---------------------------------------------------------------------------
682 void wxWindowMGL::SetFocus()
684 if ( gs_focusedWindow
== this ) return;
686 wxWindowMGL
*oldFocusedWindow
= gs_focusedWindow
;
688 if ( gs_focusedWindow
)
690 gs_toBeFocusedWindow
= (wxWindow
*)this;
691 gs_focusedWindow
->KillFocus();
692 gs_toBeFocusedWindow
= NULL
;
695 gs_focusedWindow
= this;
697 MGL_wmCaptureEvents(GetHandle(), EVT_KEYEVT
, wxMGL_CAPTURE_KEYB
);
699 wxWindowMGL
*active
= wxGetTopLevelParent(this);
700 if ( !(m_windowStyle
& wxPOPUP_WINDOW
) && active
!= gs_activeFrame
)
702 if ( gs_activeFrame
)
704 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, gs_activeFrame
->GetId());
705 event
.SetEventObject(gs_activeFrame
);
706 gs_activeFrame
->GetEventHandler()->ProcessEvent(event
);
709 gs_activeFrame
= active
;
710 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, gs_activeFrame
->GetId());
711 event
.SetEventObject(gs_activeFrame
);
712 gs_activeFrame
->GetEventHandler()->ProcessEvent(event
);
715 wxFocusEvent
event(wxEVT_SET_FOCUS
, GetId());
716 event
.SetEventObject(this);
717 event
.SetWindow((wxWindow
*)oldFocusedWindow
);
718 GetEventHandler()->ProcessEvent(event
);
721 // caret needs to be informed about focus change
722 wxCaret
*caret
= GetCaret();
725 #endif // wxUSE_CARET
728 void wxWindowMGL::KillFocus()
730 if ( gs_focusedWindow
!= this ) return;
731 gs_focusedWindow
= NULL
;
733 if ( m_isBeingDeleted
) return;
735 MGL_wmUncaptureEvents(GetHandle(), wxMGL_CAPTURE_KEYB
);
738 // caret needs to be informed about focus change
739 wxCaret
*caret
= GetCaret();
741 caret
->OnKillFocus();
742 #endif // wxUSE_CARET
744 wxFocusEvent
event(wxEVT_KILL_FOCUS
, GetId());
745 event
.SetEventObject(this);
746 event
.SetWindow(gs_toBeFocusedWindow
);
747 GetEventHandler()->ProcessEvent(event
);
750 // ----------------------------------------------------------------------------
751 // this wxWindowBase function is implemented here (in platform-specific file)
752 // because it is static and so couldn't be made virtual
753 // ----------------------------------------------------------------------------
754 wxWindow
*wxWindowBase::FindFocus()
756 return (wxWindow
*)gs_focusedWindow
;
759 bool wxWindowMGL::Show(bool show
)
761 if ( !wxWindowBase::Show(show
) )
764 MGL_wmShowWindow(m_wnd
, show
);
766 if (!show
&& gs_activeFrame
== this)
768 // activate next frame in Z-order:
771 wxWindowMGL
*win
= (wxWindowMGL
*)m_wnd
->prev
->userData
;
774 else if ( m_wnd
->next
)
776 wxWindowMGL
*win
= (wxWindowMGL
*)m_wnd
->next
->userData
;
781 gs_activeFrame
= NULL
;
788 // Raise the window to the top of the Z order
789 void wxWindowMGL::Raise()
791 MGL_wmRaiseWindow(m_wnd
);
794 // Lower the window to the bottom of the Z order
795 void wxWindowMGL::Lower()
797 MGL_wmLowerWindow(m_wnd
);
800 void wxWindowMGL::DoCaptureMouse()
802 if ( gs_mouseCapture
)
803 MGL_wmUncaptureEvents(gs_mouseCapture
->m_wnd
, wxMGL_CAPTURE_MOUSE
);
805 gs_mouseCapture
= this;
806 MGL_wmCaptureEvents(m_wnd
, EVT_MOUSEEVT
, wxMGL_CAPTURE_MOUSE
);
809 void wxWindowMGL::DoReleaseMouse()
811 wxASSERT_MSG( gs_mouseCapture
== this, wxT("attempt to release mouse, but this window hasn't captured it") )
813 MGL_wmUncaptureEvents(m_wnd
, wxMGL_CAPTURE_MOUSE
);
814 gs_mouseCapture
= NULL
;
817 /* static */ wxWindow
*wxWindowBase::GetCapture()
819 return (wxWindow
*)gs_mouseCapture
;
822 bool wxWindowMGL::SetCursor(const wxCursor
& cursor
)
824 if ( !wxWindowBase::SetCursor(cursor
) )
831 MGL_wmSetWindowCursor(m_wnd
, *m_cursor
.GetMGLCursor());
833 MGL_wmSetWindowCursor(m_wnd
, *wxSTANDARD_CURSOR
->GetMGLCursor());
838 void wxWindowMGL::WarpPointer(int x
, int y
)
841 wxDisplaySize(&w
, &h
);
843 ClientToScreen(&x
, &y
);
853 EVT_setMousePos(x
, y
);
856 #if WXWIN_COMPATIBILITY
857 // If nothing defined for this, try the parent.
858 // E.g. we may be a button loaded from a resource, with no callback function
860 void wxWindowMGL::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
862 if ( GetEventHandler()->ProcessEvent(event
) )
865 m_parent
->GetEventHandler()->OnCommand(win
, event
);
867 #endif // WXWIN_COMPATIBILITY_2
869 #if WXWIN_COMPATIBILITY
870 wxObject
* wxWindowMGL::GetChild(int number
) const
872 // Return a pointer to the Nth object in the Panel
873 wxNode
*node
= GetChildren().First();
879 wxObject
*obj
= (wxObject
*)node
->Data();
885 #endif // WXWIN_COMPATIBILITY
887 // Set this window to be the child of 'parent'.
888 bool wxWindowMGL::Reparent(wxWindowBase
*parent
)
890 if ( !wxWindowBase::Reparent(parent
) )
893 MGL_wmReparentWindow(m_wnd
, parent
->GetHandle());
899 // ---------------------------------------------------------------------------
901 // ---------------------------------------------------------------------------
903 #if wxUSE_DRAG_AND_DROP
905 void wxWindowMGL::SetDropTarget(wxDropTarget
*pDropTarget
)
907 if ( m_dropTarget
!= 0 ) {
908 m_dropTarget
->Revoke(m_hWnd
);
912 m_dropTarget
= pDropTarget
;
913 if ( m_dropTarget
!= 0 )
914 m_dropTarget
->Register(m_hWnd
);
917 #endif // wxUSE_DRAG_AND_DROP
919 // old style file-manager drag&drop support: we retain the old-style
920 // DragAcceptFiles in parallel with SetDropTarget.
921 void wxWindowMGL::DragAcceptFiles(bool accept
)
924 HWND hWnd
= GetHwnd();
926 ::DragAcceptFiles(hWnd
, (BOOL
)accept
);
930 // ---------------------------------------------------------------------------
931 // moving and resizing
932 // ---------------------------------------------------------------------------
935 void wxWindowMGL::DoGetSize(int *x
, int *y
) const
937 wxASSERT_MSG( m_wnd
, wxT("invalid window") );
939 if (x
) *x
= m_wnd
->width
;
940 if (y
) *y
= m_wnd
->height
;
943 void wxWindowMGL::DoGetPosition(int *x
, int *y
) const
945 wxASSERT_MSG( m_wnd
, wxT("invalid window") );
948 AdjustForParentClientOrigin(pX
, pY
, 0);
950 if (x
) *x
= m_wnd
->x
- pX
;
951 if (y
) *y
= m_wnd
->y
- pY
;
954 void wxWindowMGL::DoScreenToClient(int *x
, int *y
) const
957 MGL_wmCoordGlobalToLocal(m_wnd
, 0, 0, &ax
, &ay
);
964 void wxWindowMGL::DoClientToScreen(int *x
, int *y
) const
967 MGL_wmCoordLocalToGlobal(m_wnd
, 0, 0, &ax
, &ay
);
974 // Get size *available for subwindows* i.e. excluding menu bar etc.
975 void wxWindowMGL::DoGetClientSize(int *x
, int *y
) const
980 void wxWindowMGL::DoMoveWindow(int x
, int y
, int width
, int height
)
982 MGL_wmSetWindowPosition(GetHandle(), x
, y
, width
, height
);
985 // set the size of the window: if the dimensions are positive, just use them,
986 // but if any of them is equal to -1, it means that we must find the value for
987 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
988 // which case -1 is a valid value for x and y)
990 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
991 // the width/height to best suit our contents, otherwise we reuse the current
993 void wxWindowMGL::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
995 // get the current size and position...
996 int currentX
, currentY
;
997 GetPosition(¤tX
, ¤tY
);
998 int currentW
,currentH
;
999 GetSize(¤tW
, ¤tH
);
1001 // ... and don't do anything (avoiding flicker) if it's already ok
1002 if ( x
== currentX
&& y
== currentY
&&
1003 width
== currentW
&& height
== currentH
)
1008 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1010 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
1013 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
1015 wxSize
size(-1, -1);
1018 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1020 size
= DoGetBestSize();
1025 // just take the current one
1032 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1036 size
= DoGetBestSize();
1038 //else: already called DoGetBestSize() above
1044 // just take the current one
1049 int maxWidth
= GetMaxWidth(),
1050 minWidth
= GetMinWidth(),
1051 maxHeight
= GetMaxHeight(),
1052 minHeight
= GetMinHeight();
1054 if ( minWidth
!= -1 && width
< minWidth
) width
= minWidth
;
1055 if ( maxWidth
!= -1 && width
> maxWidth
) width
= maxWidth
;
1056 if ( minHeight
!= -1 && height
< minHeight
) height
= minHeight
;
1057 if ( maxHeight
!= -1 && height
> maxHeight
) height
= maxHeight
;
1059 if ( m_wnd
->x
!= x
|| m_wnd
->y
!= y
||
1060 (int)m_wnd
->width
!= width
|| (int)m_wnd
->height
!= height
)
1062 DoMoveWindow(x
, y
, width
, height
);
1064 wxSizeEvent
event(wxSize(width
, height
), GetId());
1065 event
.SetEventObject(this);
1066 GetEventHandler()->ProcessEvent(event
);
1070 void wxWindowMGL::DoSetClientSize(int width
, int height
)
1072 SetSize(width
, height
);
1075 // ---------------------------------------------------------------------------
1077 // ---------------------------------------------------------------------------
1079 int wxWindowMGL::GetCharHeight() const
1083 return dc
.GetCharHeight();
1086 int wxWindowMGL::GetCharWidth() const
1090 return dc
.GetCharWidth();
1093 void wxWindowMGL::GetTextExtent(const wxString
& string
,
1095 int *descent
, int *externalLeading
,
1096 const wxFont
*theFont
) const
1101 dc
.GetTextExtent(string
, x
, y
, descent
, externalLeading
, (wxFont
*)theFont
);
1104 #if wxUSE_CARET && WXWIN_COMPATIBILITY
1105 // ---------------------------------------------------------------------------
1106 // Caret manipulation
1107 // ---------------------------------------------------------------------------
1109 void wxWindowMGL::CreateCaret(int w
, int h
)
1111 SetCaret(new wxCaret(this, w
, h
));
1114 void wxWindowMGL::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
1116 wxFAIL_MSG("not implemented");
1119 void wxWindowMGL::ShowCaret(bool show
)
1121 wxCHECK_RET( m_caret
, "no caret to show" );
1123 m_caret
->Show(show
);
1126 void wxWindowMGL::DestroyCaret()
1131 void wxWindowMGL::SetCaretPos(int x
, int y
)
1133 wxCHECK_RET( m_caret
, "no caret to move" );
1135 m_caret
->Move(x
, y
);
1138 void wxWindowMGL::GetCaretPos(int *x
, int *y
) const
1140 wxCHECK_RET( m_caret
, "no caret to get position of" );
1142 m_caret
->GetPosition(x
, y
);
1144 #endif // wxUSE_CARET
1147 // ---------------------------------------------------------------------------
1149 // ---------------------------------------------------------------------------
1151 void wxWindowMGL::Clear()
1153 wxClientDC
dc((wxWindow
*)this);
1154 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1155 dc
.SetBackground(brush
);
1159 #include "wx/menu.h"
1160 void wxWindowMGL::Refresh(bool eraseBack
, const wxRect
*rect
)
1162 if ( m_eraseBackground
== -1 )
1163 m_eraseBackground
= eraseBack
;
1165 m_eraseBackground
|= eraseBack
;
1170 r
.left
= rect
->GetLeft(), r
.right
= rect
->GetRight();
1171 r
.top
= rect
->GetTop(), r
.bottom
= rect
->GetBottom();
1172 MGL_wmInvalidateWindowRect(GetHandle(), &r
);
1175 MGL_wmInvalidateWindow(GetHandle());
1178 void wxWindowMGL::Update()
1181 MGL_wmUpdateDC(g_winMng
);
1184 void wxWindowMGL::Freeze()
1187 m_refreshAfterThaw
= FALSE
;
1190 void wxWindowMGL::Thaw()
1193 if ( m_refreshAfterThaw
)
1197 void wxWindowMGL::HandlePaint(MGLDevCtx
*dc
)
1201 // Don't paint anything if the window is frozen.
1202 m_refreshAfterThaw
= TRUE
;
1207 // FIXME_MGL -- debugging stuff, to be removed!
1208 static int debugPaintEvents
= -1;
1209 if ( debugPaintEvents
== -1 )
1210 debugPaintEvents
= wxGetEnv(wxT("WXMGL_DEBUG_PAINT_EVENTS"), NULL
);
1211 if ( debugPaintEvents
)
1213 dc
->setColorRGB(255,0,255);
1214 dc
->fillRect(-1000,-1000,2000,2000);
1220 dc
->getClipRegion(clip
);
1221 m_updateRegion
= wxRegion(clip
);
1225 // must hide caret temporarily, otherwise we'd get rendering artifacts
1226 wxCaret
*caret
= GetCaret();
1229 #endif // wxUSE_CARET
1231 if ( m_eraseBackground
!= 0 )
1233 wxWindowDC
dc((wxWindow
*)this);
1234 wxEraseEvent
eventEr(m_windowId
, &dc
);
1235 eventEr
.SetEventObject(this);
1236 GetEventHandler()->ProcessEvent(eventEr
);
1238 m_eraseBackground
= -1;
1240 wxNcPaintEvent
eventNc(GetId());
1241 eventNc
.SetEventObject(this);
1242 GetEventHandler()->ProcessEvent(eventNc
);
1244 wxPaintEvent
eventPt(GetId());
1245 eventPt
.SetEventObject(this);
1246 GetEventHandler()->ProcessEvent(eventPt
);
1251 #endif // wxUSE_CARET
1253 m_paintMGLDC
= NULL
;
1254 m_updateRegion
.Clear();
1258 // Find the wxWindow at the current mouse position, returning the mouse
1260 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1262 return wxFindWindowAtPoint(pt
= wxGetMousePosition());
1265 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
1267 window_t
*wnd
= MGL_wmGetWindowAtPosition(g_winMng
, pt
.x
, pt
.y
);
1268 return (wxWindow
*)wnd
->userData
;
1272 // ---------------------------------------------------------------------------
1273 // idle events processing
1274 // ---------------------------------------------------------------------------
1276 void wxWindowMGL::OnIdle(wxIdleEvent
& WXUNUSED(event
))