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"
40 #if wxUSE_DRAG_AND_DROP
44 #include "wx/sysopt.h"
45 #include "wx/mgl/private.h"
46 #include "wx/dcscreen.h"
52 #include "wx/tooltip.h"
55 // ---------------------------------------------------------------------------
57 // ---------------------------------------------------------------------------
59 // MGL window manager and associated DC.
60 winmng_t
*g_winMng
= NULL
;
61 MGLDevCtx
*g_displayDC
= NULL
;
63 // the window that has keyboard focus:
64 static wxWindowMGL
*gs_focusedWindow
= NULL
;
65 // the window that is about to be focused after currently focused
67 static wxWindow
*gs_toBeFocusedWindow
= NULL
;
68 // the window that is currently under mouse cursor:
69 static wxWindowMGL
*gs_windowUnderMouse
= NULL
;
70 // the window that has mouse capture
71 static wxWindowMGL
*gs_mouseCapture
= NULL
;
72 // the frame that is currently active (i.e. its child has focus). It is
73 // used to generate wxActivateEvents
74 static wxWindowMGL
*gs_activeFrame
= NULL
;
76 // ---------------------------------------------------------------------------
78 // ---------------------------------------------------------------------------
80 // Custom identifiers used to distinguish between various event handlers
81 // and capture handlers passed to MGL_wm
84 wxMGL_CAPTURE_MOUSE
= 1,
85 wxMGL_CAPTURE_KEYB
= 2
89 // ---------------------------------------------------------------------------
91 // ---------------------------------------------------------------------------
93 // Returns toplevel grandparent of given window:
94 static wxWindowMGL
* wxGetTopLevelParent(wxWindowMGL
*win
)
97 while (p
&& !p
->IsTopLevel())
102 // An easy way to capture screenshots:
103 static void wxCaptureScreenshot(bool activeWindowOnly
)
106 #define SCREENSHOT_FILENAME _T("sshot%03i.png")
108 #define SCREENSHOT_FILENAME _T("screenshot-%03i.png")
110 static int screenshot_num
= 0;
115 screenshot
.Printf(SCREENSHOT_FILENAME
, screenshot_num
++);
116 } while ( wxFileExists(screenshot
) && screenshot_num
< 1000 );
118 wxRect
r(0, 0, g_displayDC
->sizex(), g_displayDC
->sizey());
120 if ( activeWindowOnly
&& gs_activeFrame
)
122 r
.Intersect(gs_activeFrame
->GetRect());
125 g_displayDC
->savePNGFromDC(screenshot
.mb_str(),
126 r
.x
, r
. y
, r
.x
+r
.width
, r
.y
+r
.height
);
128 wxMessageBox(wxString::Format(_T("Screenshot captured: %s"),
129 screenshot
.c_str()));
132 // ---------------------------------------------------------------------------
134 // ---------------------------------------------------------------------------
136 static void MGLAPI
wxWindowPainter(window_t
*wnd
, MGLDC
*dc
)
138 wxWindowMGL
*w
= (wxWindow
*) wnd
->userData
;
140 if ( w
&& !(w
->GetWindowStyle() & wxTRANSPARENT_WINDOW
) )
143 w
->HandlePaint(&ctx
);
147 static ibool MGLAPI
wxWindowMouseHandler(window_t
*wnd
, event_t
*e
)
149 wxWindowMGL
*win
= (wxWindowMGL
*)MGL_wmGetWindowUserData(wnd
);
150 wxPoint
orig(win
->GetClientAreaOrigin());
153 MGL_wmCoordGlobalToLocal(win
->GetHandle(),
154 e
->where_x
, e
->where_y
, &where
.x
, &where
.y
);
156 for (wxWindowMGL
*w
= win
; w
; w
= w
->GetParent())
158 if ( !w
->IsEnabled() )
160 if ( w
->IsTopLevel() )
164 wxEventType type
= wxEVT_NULL
;
166 event
.SetEventObject(win
);
167 event
.SetTimestamp(e
->when
);
168 event
.m_x
= where
.x
- orig
.x
;
169 event
.m_y
= where
.y
- orig
.y
;
170 event
.m_shiftDown
= ( e
->modifiers
& EVT_SHIFTKEY
) != 0;
171 event
.m_controlDown
= ( e
->modifiers
& EVT_CTRLSTATE
) != 0;
172 event
.m_altDown
= ( e
->modifiers
& EVT_LEFTALT
) != 0;
173 event
.m_metaDown
= ( e
->modifiers
& EVT_RIGHTALT
) != 0;
174 event
.m_leftDown
= ( e
->modifiers
& EVT_LEFTBUT
) != 0;
175 event
.m_middleDown
= ( e
->modifiers
& EVT_MIDDLEBUT
) != 0;
176 event
.m_rightDown
= ( e
->modifiers
& EVT_RIGHTBUT
) != 0;
181 // Change focus if the user clicks outside focused window:
182 if ( win
->AcceptsFocus() && wxWindow::FindFocus() != win
)
185 if ( e
->message
& EVT_DBLCLICK
)
187 if ( e
->message
& EVT_LEFTBMASK
)
188 type
= wxEVT_LEFT_DCLICK
;
189 else if ( e
->message
& EVT_MIDDLEBMASK
)
190 type
= wxEVT_MIDDLE_DCLICK
;
191 else if ( e
->message
& EVT_RIGHTBMASK
)
192 type
= wxEVT_RIGHT_DCLICK
;
196 if ( e
->message
& EVT_LEFTBMASK
)
197 type
= wxEVT_LEFT_DOWN
;
198 else if ( e
->message
& EVT_MIDDLEBMASK
)
199 type
= wxEVT_MIDDLE_DOWN
;
200 else if ( e
->message
& EVT_RIGHTBMASK
)
201 type
= wxEVT_RIGHT_DOWN
;
207 if ( e
->message
& EVT_LEFTBMASK
)
208 type
= wxEVT_LEFT_UP
;
209 else if ( e
->message
& EVT_MIDDLEBMASK
)
210 type
= wxEVT_MIDDLE_UP
;
211 else if ( e
->message
& EVT_RIGHTBMASK
)
212 type
= wxEVT_RIGHT_UP
;
216 if ( !gs_mouseCapture
)
218 if ( win
!= gs_windowUnderMouse
)
220 if ( gs_windowUnderMouse
)
222 wxMouseEvent
event2(event
);
223 MGL_wmCoordGlobalToLocal(gs_windowUnderMouse
->GetHandle(),
224 e
->where_x
, e
->where_y
,
225 &event2
.m_x
, &event2
.m_y
);
227 wxPoint
orig(gs_windowUnderMouse
->GetClientAreaOrigin());
228 event2
.m_x
-= orig
.x
;
229 event2
.m_y
-= orig
.y
;
231 event2
.SetEventObject(gs_windowUnderMouse
);
232 event2
.SetEventType(wxEVT_LEAVE_WINDOW
);
233 gs_windowUnderMouse
->GetEventHandler()->ProcessEvent(event2
);
236 wxMouseEvent
event3(event
);
237 event3
.SetEventType(wxEVT_ENTER_WINDOW
);
238 win
->GetEventHandler()->ProcessEvent(event3
);
240 gs_windowUnderMouse
= win
;
243 else // gs_mouseCapture
245 bool inside
= (where
.x
>= 0 &&
247 where
.x
< win
->GetSize().x
&&
248 where
.y
< win
->GetSize().y
);
249 if ( (inside
&& gs_windowUnderMouse
!= win
) ||
250 (!inside
&& gs_windowUnderMouse
== win
) )
252 wxMouseEvent
evt(inside
?
253 wxEVT_ENTER_WINDOW
: wxEVT_LEAVE_WINDOW
);
254 evt
.SetEventObject(win
);
255 win
->GetEventHandler()->ProcessEvent(evt
);
256 gs_windowUnderMouse
= inside
? win
: NULL
;
267 if ( type
== wxEVT_NULL
)
273 event
.SetEventType(type
);
274 return win
->GetEventHandler()->ProcessEvent(event
);
278 static long wxScanToKeyCode(event_t
*event
, bool translate
)
280 // VS: make it __WXDEBUG__-only, since we have lots of wxLogTrace calls
281 // here and the arguments would be stored in non-debug executable even
282 // though wxLogTrace would be no-op...
284 #define KEY(mgl_key,wx_key) \
286 wxLogTrace(_T("keyevents"), \
287 _T("key " #mgl_key ", mapped to " #wx_key)); \
291 #define KEY(mgl_key,wx_key) \
292 case mgl_key: key = wx_key; break;
299 switch ( EVT_scanCode(event
->message
) )
301 KEY (KB_padMinus
, WXK_NUMPAD_SUBTRACT
)
302 KEY (KB_padPlus
, WXK_NUMPAD_ADD
)
303 KEY (KB_padTimes
, WXK_NUMPAD_MULTIPLY
)
304 KEY (KB_padDivide
, WXK_NUMPAD_DIVIDE
)
305 KEY (KB_padCenter
, WXK_NUMPAD_SEPARATOR
) // ?
306 KEY (KB_padLeft
, WXK_NUMPAD_LEFT
)
307 KEY (KB_padRight
, WXK_NUMPAD_RIGHT
)
308 KEY (KB_padUp
, WXK_NUMPAD_UP
)
309 KEY (KB_padDown
, WXK_NUMPAD_DOWN
)
310 KEY (KB_padInsert
, WXK_NUMPAD_INSERT
)
311 KEY (KB_padDelete
, WXK_NUMPAD_DELETE
)
312 KEY (KB_padHome
, WXK_NUMPAD_HOME
)
313 KEY (KB_padEnd
, WXK_NUMPAD_END
)
314 KEY (KB_padPageUp
, WXK_NUMPAD_PAGEUP
)
315 KEY (KB_padPageDown
, WXK_NUMPAD_PAGEDOWN
)
326 KEY (KB_minus
, WXK_SUBTRACT
)
327 KEY (KB_equals
, WXK_ADD
)
328 KEY (KB_backSlash
, '\\')
339 KEY (KB_leftSquareBrace
,'[')
340 KEY (KB_rightSquareBrace
,']')
350 KEY (KB_semicolon
, ';')
351 KEY (KB_apostrophe
, '\'')
361 KEY (KB_divide
, WXK_DIVIDE
)
362 KEY (KB_space
, WXK_SPACE
)
371 switch ( EVT_scanCode(event
->message
) )
373 KEY (KB_padEnter
, WXK_NUMPAD_ENTER
)
383 KEY (KB_F10
, WXK_F10
)
384 KEY (KB_F11
, WXK_F11
)
385 KEY (KB_F12
, WXK_F12
)
386 KEY (KB_left
, WXK_LEFT
)
387 KEY (KB_right
, WXK_RIGHT
)
389 KEY (KB_down
, WXK_DOWN
)
390 KEY (KB_insert
, WXK_INSERT
)
391 KEY (KB_delete
, WXK_DELETE
)
392 KEY (KB_home
, WXK_HOME
)
393 KEY (KB_end
, WXK_END
)
394 KEY (KB_pageUp
, WXK_PAGEUP
)
395 KEY (KB_pageDown
, WXK_PAGEDOWN
)
396 KEY (KB_capsLock
, WXK_CAPITAL
)
397 KEY (KB_numLock
, WXK_NUMLOCK
)
398 KEY (KB_scrollLock
, WXK_SCROLL
)
399 KEY (KB_leftShift
, WXK_SHIFT
)
400 KEY (KB_rightShift
, WXK_SHIFT
)
401 KEY (KB_leftCtrl
, WXK_CONTROL
)
402 KEY (KB_rightCtrl
, WXK_CONTROL
)
403 KEY (KB_leftAlt
, WXK_ALT
)
404 KEY (KB_rightAlt
, WXK_ALT
)
405 KEY (KB_leftWindows
, WXK_START
)
406 KEY (KB_rightWindows
, WXK_START
)
407 KEY (KB_menu
, WXK_MENU
)
408 KEY (KB_sysReq
, WXK_SNAPSHOT
)
409 KEY (KB_esc
, WXK_ESCAPE
)
410 KEY (KB_backspace
, WXK_BACK
)
411 KEY (KB_tab
, WXK_TAB
)
412 KEY (KB_enter
, WXK_RETURN
)
415 key
= EVT_asciiCode(event
->message
);
425 static bool wxHandleSpecialKeys(wxKeyEvent
& event
)
427 // Add an easy way to capture screenshots:
428 if ( event
.m_keyCode
== WXK_SNAPSHOT
429 #ifdef __WXDEBUG__ // FIXME_MGL - remove when KB_sysReq works in MGL!
430 || (event
.m_keyCode
== WXK_F1
&&
431 event
.m_shiftDown
&& event
.m_controlDown
)
435 wxCaptureScreenshot(event
.m_altDown
/*only active wnd?*/);
442 static ibool MGLAPI
wxWindowKeybHandler(window_t
*wnd
, event_t
*e
)
444 wxWindowMGL
*win
= (wxWindowMGL
*)MGL_wmGetWindowUserData(wnd
);
446 if ( !win
->IsEnabled() ) return FALSE
;
449 MGL_wmCoordGlobalToLocal(win
->GetHandle(),
450 e
->where_x
, e
->where_y
, &where
.x
, &where
.y
);
453 event
.SetEventObject(win
);
454 event
.SetTimestamp(e
->when
);
455 event
.m_keyCode
= wxScanToKeyCode(e
, true);
456 event
.m_scanCode
= 0; // not used by wx at all
459 event
.m_shiftDown
= ( e
->modifiers
& EVT_SHIFTKEY
) != 0;
460 event
.m_controlDown
= ( e
->modifiers
& EVT_CTRLSTATE
) != 0;
461 event
.m_altDown
= ( e
->modifiers
& EVT_LEFTALT
) != 0;
462 event
.m_metaDown
= ( e
->modifiers
& EVT_RIGHTALT
) != 0;
464 if ( e
->what
== EVT_KEYUP
)
466 event
.SetEventType(wxEVT_KEY_UP
);
467 return win
->GetEventHandler()->ProcessEvent(event
);
474 event
.SetEventType(wxEVT_KEY_DOWN
);
477 ret
= win
->GetEventHandler()->ProcessEvent(event
);
479 // wxMSW doesn't send char events with Alt pressed
480 // Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x
481 // will only be sent if it is not in an accelerator table:
482 event2
.m_keyCode
= wxScanToKeyCode(e
, false);
483 if ( !ret
&& event2
.m_keyCode
!= 0 )
485 event2
.SetEventType(wxEVT_CHAR
);
486 ret
= win
->GetEventHandler()->ProcessEvent(event2
);
489 // Synthetize navigation key event, but do it only if the TAB key
490 // wasn't handled yet:
491 if ( !ret
&& event
.m_keyCode
== WXK_TAB
&&
492 win
->GetParent() && win
->GetParent()->HasFlag(wxTAB_TRAVERSAL
) )
494 wxNavigationKeyEvent navEvent
;
495 navEvent
.SetEventObject(win
->GetParent());
496 // Shift-TAB goes in reverse direction:
497 navEvent
.SetDirection(!event
.m_shiftDown
);
498 // Ctrl-TAB changes the (parent) window, i.e. switch notebook page:
499 navEvent
.SetWindowChange(event
.m_controlDown
);
500 navEvent
.SetCurrentFocus(wxStaticCast(win
, wxWindow
));
501 ret
= win
->GetParent()->GetEventHandler()->ProcessEvent(navEvent
);
504 // Finally, process special meaning keys that are usually
505 // a responsibility of OS or window manager:
507 ret
= wxHandleSpecialKeys(event
);
513 // ---------------------------------------------------------------------------
515 // ---------------------------------------------------------------------------
517 // in wxUniv this class is abstract because it doesn't have DoPopupMenu()
518 IMPLEMENT_ABSTRACT_CLASS(wxWindowMGL
, wxWindowBase
)
520 BEGIN_EVENT_TABLE(wxWindowMGL
, wxWindowBase
)
523 // ===========================================================================
525 // ===========================================================================
527 // ----------------------------------------------------------------------------
528 // constructors and such
529 // ----------------------------------------------------------------------------
531 extern wxVideoMode
wxGetDefaultDisplayMode();
533 void wxWindowMGL::Init()
535 // First of all, make sure window manager is up and running. If it is
536 // not the case, initialize it in default display mode
539 if ( !wxTheApp
->SetDisplayMode(wxGetDefaultDisplayMode()) )
540 wxLogFatalError(_("Cannot initialize display."));
548 m_eraseBackground
= -1;
552 wxWindowMGL::~wxWindowMGL()
556 m_isBeingDeleted
= true;
558 if ( gs_mouseCapture
== this )
561 if (gs_activeFrame
== this)
563 gs_activeFrame
= NULL
;
564 // activate next frame in Z-order:
567 wxWindowMGL
*win
= (wxWindowMGL
*)m_wnd
->prev
->userData
;
570 else if ( m_wnd
->next
)
572 wxWindowMGL
*win
= (wxWindowMGL
*)m_wnd
->next
->userData
;
577 if ( gs_focusedWindow
== this )
580 if ( gs_windowUnderMouse
== this )
581 gs_windowUnderMouse
= NULL
;
586 MGL_wmDestroyWindow(m_wnd
);
589 // real construction (Init() must have been called before!)
590 bool wxWindowMGL::Create(wxWindow
*parent
,
595 const wxString
& name
)
597 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
601 parent
->AddChild(this);
604 x
= pos
.x
, y
= pos
.y
;
606 x
= 0; // FIXME_MGL, something better, see GTK+
608 y
= 0; // FIXME_MGL, something better, see GTK+
609 AdjustForParentClientOrigin(x
, y
, 0);
610 w
= WidthDefault(size
.x
);
611 h
= HeightDefault(size
.y
);
614 window_t
*wnd_parent
= parent
? parent
->GetHandle() : NULL
;
616 if ( style
& wxFULL_REPAINT_ON_RESIZE
)
618 mgl_style
|= MGL_WM_FULL_REPAINT_ON_RESIZE
;
620 if ( style
& wxSTAY_ON_TOP
)
622 mgl_style
|= MGL_WM_ALWAYS_ON_TOP
;
624 if ( style
& wxPOPUP_WINDOW
)
626 mgl_style
|= MGL_WM_ALWAYS_ON_TOP
;
627 // it is created hidden as other top level windows
632 window_t
*wnd
= MGL_wmCreateWindow(g_winMng
, wnd_parent
, x
, y
, w
, h
);
634 MGL_wmSetWindowFlags(wnd
, mgl_style
);
635 MGL_wmShowWindow(wnd
, m_isShown
);
642 void wxWindowMGL::SetMGLwindow_t(struct window_t
*wnd
)
645 MGL_wmDestroyWindow(m_wnd
);
648 if ( !m_wnd
) return;
650 m_isShown
= (bool)m_wnd
->visible
;
652 MGL_wmSetWindowUserData(m_wnd
, (void*) this);
653 MGL_wmSetWindowPainter(m_wnd
, wxWindowPainter
);
654 MGL_wmPushWindowEventHandler(m_wnd
, wxWindowMouseHandler
, EVT_MOUSEEVT
, 0);
655 MGL_wmPushWindowEventHandler(m_wnd
, wxWindowKeybHandler
, EVT_KEYEVT
, 0);
658 MGL_wmSetWindowCursor(m_wnd
, *m_cursor
.GetMGLCursor());
660 MGL_wmSetWindowCursor(m_wnd
, *wxSTANDARD_CURSOR
->GetMGLCursor());
663 // ---------------------------------------------------------------------------
665 // ---------------------------------------------------------------------------
667 void wxWindowMGL::SetFocus()
669 if ( gs_focusedWindow
== this ) return;
671 wxWindowMGL
*oldFocusedWindow
= gs_focusedWindow
;
673 if ( gs_focusedWindow
)
675 gs_toBeFocusedWindow
= (wxWindow
*)this;
676 gs_focusedWindow
->KillFocus();
677 gs_toBeFocusedWindow
= NULL
;
680 gs_focusedWindow
= this;
682 MGL_wmCaptureEvents(GetHandle(), EVT_KEYEVT
, wxMGL_CAPTURE_KEYB
);
684 wxWindowMGL
*active
= wxGetTopLevelParent(this);
685 if ( !(m_windowStyle
& wxPOPUP_WINDOW
) && active
!= gs_activeFrame
)
687 if ( gs_activeFrame
)
689 wxActivateEvent
event(wxEVT_ACTIVATE
, false, gs_activeFrame
->GetId());
690 event
.SetEventObject(gs_activeFrame
);
691 gs_activeFrame
->GetEventHandler()->ProcessEvent(event
);
694 gs_activeFrame
= active
;
695 wxActivateEvent
event(wxEVT_ACTIVATE
, true, gs_activeFrame
->GetId());
696 event
.SetEventObject(gs_activeFrame
);
697 gs_activeFrame
->GetEventHandler()->ProcessEvent(event
);
700 wxFocusEvent
event(wxEVT_SET_FOCUS
, GetId());
701 event
.SetEventObject(this);
702 event
.SetWindow((wxWindow
*)oldFocusedWindow
);
703 GetEventHandler()->ProcessEvent(event
);
706 // caret needs to be informed about focus change
707 wxCaret
*caret
= GetCaret();
710 #endif // wxUSE_CARET
713 void wxWindowMGL::KillFocus()
715 if ( gs_focusedWindow
!= this ) return;
716 gs_focusedWindow
= NULL
;
718 if ( m_isBeingDeleted
) return;
720 MGL_wmUncaptureEvents(GetHandle(), wxMGL_CAPTURE_KEYB
);
723 // caret needs to be informed about focus change
724 wxCaret
*caret
= GetCaret();
726 caret
->OnKillFocus();
727 #endif // wxUSE_CARET
729 wxFocusEvent
event(wxEVT_KILL_FOCUS
, GetId());
730 event
.SetEventObject(this);
731 event
.SetWindow(gs_toBeFocusedWindow
);
732 GetEventHandler()->ProcessEvent(event
);
735 // ----------------------------------------------------------------------------
736 // this wxWindowBase function is implemented here (in platform-specific file)
737 // because it is static and so couldn't be made virtual
738 // ----------------------------------------------------------------------------
739 wxWindow
*wxWindowBase::DoFindFocus()
741 return (wxWindow
*)gs_focusedWindow
;
744 bool wxWindowMGL::Show(bool show
)
746 if ( !wxWindowBase::Show(show
) )
749 MGL_wmShowWindow(m_wnd
, show
);
751 if (!show
&& gs_activeFrame
== this)
753 // activate next frame in Z-order:
756 wxWindowMGL
*win
= (wxWindowMGL
*)m_wnd
->prev
->userData
;
759 else if ( m_wnd
->next
)
761 wxWindowMGL
*win
= (wxWindowMGL
*)m_wnd
->next
->userData
;
766 gs_activeFrame
= NULL
;
773 // Raise the window to the top of the Z order
774 void wxWindowMGL::Raise()
776 MGL_wmRaiseWindow(m_wnd
);
779 // Lower the window to the bottom of the Z order
780 void wxWindowMGL::Lower()
782 MGL_wmLowerWindow(m_wnd
);
785 void wxWindowMGL::DoCaptureMouse()
787 if ( gs_mouseCapture
)
788 MGL_wmUncaptureEvents(gs_mouseCapture
->m_wnd
, wxMGL_CAPTURE_MOUSE
);
790 gs_mouseCapture
= this;
791 MGL_wmCaptureEvents(m_wnd
, EVT_MOUSEEVT
, wxMGL_CAPTURE_MOUSE
);
794 void wxWindowMGL::DoReleaseMouse()
796 wxASSERT_MSG( gs_mouseCapture
== this, wxT("attempt to release mouse, but this window hasn't captured it") );
798 MGL_wmUncaptureEvents(m_wnd
, wxMGL_CAPTURE_MOUSE
);
799 gs_mouseCapture
= NULL
;
802 /* static */ wxWindow
*wxWindowBase::GetCapture()
804 return (wxWindow
*)gs_mouseCapture
;
807 bool wxWindowMGL::SetCursor(const wxCursor
& cursor
)
809 if ( !wxWindowBase::SetCursor(cursor
) )
816 MGL_wmSetWindowCursor(m_wnd
, *m_cursor
.GetMGLCursor());
818 MGL_wmSetWindowCursor(m_wnd
, *wxSTANDARD_CURSOR
->GetMGLCursor());
823 void wxWindowMGL::WarpPointer(int x
, int y
)
826 wxDisplaySize(&w
, &h
);
828 ClientToScreen(&x
, &y
);
838 EVT_setMousePos(x
, y
);
841 // Set this window to be the child of 'parent'.
842 bool wxWindowMGL::Reparent(wxWindowBase
*parent
)
844 if ( !wxWindowBase::Reparent(parent
) )
847 MGL_wmReparentWindow(m_wnd
, parent
->GetHandle());
853 // ---------------------------------------------------------------------------
855 // ---------------------------------------------------------------------------
857 #if wxUSE_DRAG_AND_DROP
859 void wxWindowMGL::SetDropTarget(wxDropTarget
*pDropTarget
)
861 if ( m_dropTarget
!= 0 ) {
862 m_dropTarget
->Revoke(m_hWnd
);
866 m_dropTarget
= pDropTarget
;
867 if ( m_dropTarget
!= 0 )
868 m_dropTarget
->Register(m_hWnd
);
871 #endif // wxUSE_DRAG_AND_DROP
873 // old style file-manager drag&drop support: we retain the old-style
874 // DragAcceptFiles in parallel with SetDropTarget.
875 void wxWindowMGL::DragAcceptFiles(bool WXUNUSED(accept
))
878 HWND hWnd
= GetHwnd();
880 ::DragAcceptFiles(hWnd
, (BOOL
)accept
);
884 // ---------------------------------------------------------------------------
885 // moving and resizing
886 // ---------------------------------------------------------------------------
889 void wxWindowMGL::DoGetSize(int *x
, int *y
) const
891 wxASSERT_MSG( m_wnd
, wxT("invalid window") );
893 if (x
) *x
= m_wnd
->width
;
894 if (y
) *y
= m_wnd
->height
;
897 void wxWindowMGL::DoGetPosition(int *x
, int *y
) const
899 wxASSERT_MSG( m_wnd
, wxT("invalid window") );
902 AdjustForParentClientOrigin(pX
, pY
, 0);
904 if (x
) *x
= m_wnd
->x
- pX
;
905 if (y
) *y
= m_wnd
->y
- pY
;
908 void wxWindowMGL::DoScreenToClient(int *x
, int *y
) const
911 MGL_wmCoordGlobalToLocal(m_wnd
, 0, 0, &ax
, &ay
);
918 void wxWindowMGL::DoClientToScreen(int *x
, int *y
) const
921 MGL_wmCoordLocalToGlobal(m_wnd
, 0, 0, &ax
, &ay
);
928 // Get size *available for subwindows* i.e. excluding menu bar etc.
929 void wxWindowMGL::DoGetClientSize(int *x
, int *y
) const
934 void wxWindowMGL::DoMoveWindow(int x
, int y
, int width
, int height
)
936 wxRect
rcClient(GetClientRect());
938 MGL_wmSetWindowPosition(m_wnd
, x
, y
, width
, height
);
940 // When the origin or a window stays fixed but the height or width
941 // changes, invalidate the old and new non-client areas
942 if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE
) &&
943 m_wnd
->x
== x
&& m_wnd
->y
== y
&&
944 rcClient
.Intersect(GetClientRect()) != wxRect(0, 0, width
, height
) )
946 wxRegion
rgn(0, 0, width
, height
);
947 rgn
.Subtract(rcClient
);
949 // This should work I think, but doesn't seem to:
950 //MGL_wmInvalidateWindowRegion(m_wnd, rgn.GetMGLRegion().rgnPointer());
952 // Use MGL_wmInvalidateWindowRect instead:
953 for (wxRegionIterator
it(rgn
); it
; it
++)
958 rc
.right
= rc
.left
+ it
.GetW();
959 rc
.bottom
= rc
.top
+ it
.GetH();
960 MGL_wmInvalidateWindowRect(m_wnd
, &rc
);
965 // set the size of the window: if the dimensions are positive, just use them,
966 // but if any of them is equal to -1, it means that we must find the value for
967 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
968 // which case -1 is a valid value for x and y)
970 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
971 // the width/height to best suit our contents, otherwise we reuse the current
973 void wxWindowMGL::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
975 // get the current size and position...
976 int currentX
, currentY
;
977 GetPosition(¤tX
, ¤tY
);
978 int currentW
,currentH
;
979 GetSize(¤tW
, ¤tH
);
981 // ... and don't do anything (avoiding flicker) if it's already ok
982 if ( x
== currentX
&& y
== currentY
&&
983 width
== currentW
&& height
== currentH
)
988 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
990 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
993 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
998 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
1000 size
= DoGetBestSize();
1005 // just take the current one
1012 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
1016 size
= DoGetBestSize();
1018 //else: already called DoGetBestSize() above
1024 // just take the current one
1029 int maxWidth
= GetMaxWidth(),
1030 minWidth
= GetMinWidth(),
1031 maxHeight
= GetMaxHeight(),
1032 minHeight
= GetMinHeight();
1034 if ( minWidth
!= -1 && width
< minWidth
) width
= minWidth
;
1035 if ( maxWidth
!= -1 && width
> maxWidth
) width
= maxWidth
;
1036 if ( minHeight
!= -1 && height
< minHeight
) height
= minHeight
;
1037 if ( maxHeight
!= -1 && height
> maxHeight
) height
= maxHeight
;
1039 if ( m_wnd
->x
!= x
|| m_wnd
->y
!= y
||
1040 (int)m_wnd
->width
!= width
|| (int)m_wnd
->height
!= height
)
1042 DoMoveWindow(x
, y
, width
, height
);
1044 wxSize
newSize(width
, height
);
1045 wxSizeEvent
event(newSize
, GetId());
1046 event
.SetEventObject(this);
1047 GetEventHandler()->ProcessEvent(event
);
1051 void wxWindowMGL::DoSetClientSize(int width
, int height
)
1053 SetSize(width
, height
);
1056 // ---------------------------------------------------------------------------
1058 // ---------------------------------------------------------------------------
1060 int wxWindowMGL::GetCharHeight() const
1064 return dc
.GetCharHeight();
1067 int wxWindowMGL::GetCharWidth() const
1071 return dc
.GetCharWidth();
1074 void wxWindowMGL::GetTextExtent(const wxString
& string
,
1076 int *descent
, int *externalLeading
,
1077 const wxFont
*theFont
) const
1082 dc
.GetTextExtent(string
, x
, y
, descent
, externalLeading
, (wxFont
*)theFont
);
1086 // ---------------------------------------------------------------------------
1088 // ---------------------------------------------------------------------------
1090 void wxWindowMGL::Clear()
1092 wxClientDC
dc((wxWindow
*)this);
1093 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1094 dc
.SetBackground(brush
);
1098 #include "wx/menu.h"
1099 void wxWindowMGL::Refresh(bool eraseBack
, const wxRect
*rect
)
1101 if ( m_eraseBackground
== -1 )
1102 m_eraseBackground
= eraseBack
;
1104 m_eraseBackground
|= eraseBack
;
1109 r
.left
= rect
->GetLeft(), r
.right
= rect
->GetRight();
1110 r
.top
= rect
->GetTop(), r
.bottom
= rect
->GetBottom();
1111 MGL_wmInvalidateWindowRect(GetHandle(), &r
);
1114 MGL_wmInvalidateWindow(GetHandle());
1117 void wxWindowMGL::Update()
1120 MGL_wmUpdateDC(g_winMng
);
1123 void wxWindowMGL::Freeze()
1126 m_refreshAfterThaw
= false;
1129 void wxWindowMGL::Thaw()
1132 if ( m_refreshAfterThaw
)
1136 void wxWindowMGL::HandlePaint(MGLDevCtx
*dc
)
1140 // Don't paint anything if the window is frozen.
1141 m_refreshAfterThaw
= true;
1146 // FIXME_MGL -- debugging stuff, to be removed!
1147 static int debugPaintEvents
= -1;
1148 if ( debugPaintEvents
== -1 )
1149 debugPaintEvents
= wxGetEnv(wxT("WXMGL_DEBUG_PAINT_EVENTS"), NULL
);
1150 if ( debugPaintEvents
)
1152 dc
->setColorRGB(255,0,255);
1153 dc
->fillRect(-1000,-1000,2000,2000);
1159 dc
->getClipRegion(clip
);
1160 m_updateRegion
= wxRegion(clip
);
1164 // must hide caret temporarily, otherwise we'd get rendering artifacts
1165 wxCaret
*caret
= GetCaret();
1168 #endif // wxUSE_CARET
1170 if ( m_eraseBackground
!= 0 )
1172 wxWindowDC
dc((wxWindow
*)this);
1173 wxEraseEvent
eventEr(m_windowId
, &dc
);
1174 eventEr
.SetEventObject(this);
1175 GetEventHandler()->ProcessEvent(eventEr
);
1177 m_eraseBackground
= -1;
1179 wxNcPaintEvent
eventNc(GetId());
1180 eventNc
.SetEventObject(this);
1181 GetEventHandler()->ProcessEvent(eventNc
);
1183 wxPaintEvent
eventPt(GetId());
1184 eventPt
.SetEventObject(this);
1185 GetEventHandler()->ProcessEvent(eventPt
);
1190 #endif // wxUSE_CARET
1192 m_paintMGLDC
= NULL
;
1193 m_updateRegion
.Clear();
1197 // Find the wxWindow at the current mouse position, returning the mouse
1199 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1201 return wxFindWindowAtPoint(pt
= wxGetMousePosition());
1204 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
1206 window_t
*wnd
= MGL_wmGetWindowAtPosition(g_winMng
, pt
.x
, pt
.y
);
1207 return (wxWindow
*)wnd
->userData
;
1211 // ---------------------------------------------------------------------------
1212 // idle events processing
1213 // ---------------------------------------------------------------------------
1215 void wxWindowMGL::OnInternalIdle()
1217 if (wxUpdateUIEvent::CanUpdate(this))
1218 UpdateWindowUI(wxUPDATE_UI_FROMIDLE
);