1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mgl/window.cpp
4 // Author: Vaclav Slavik
5 // (based on GTK & MSW implementations)
7 // Copyright: (c) 2001 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 currently under mouse cursor:
70 static wxWindowMGL
*gs_windowUnderMouse
= NULL
;
71 // the window that has mouse capture
72 static wxWindowMGL
*gs_mouseCapture
= NULL
;
73 // the frame that is currently active (i.e. its child has focus). It is
74 // used to generate wxActivateEvents
75 static wxWindowMGL
*gs_activeFrame
= NULL
;
77 // ---------------------------------------------------------------------------
79 // ---------------------------------------------------------------------------
81 // Custom identifiers used to distinguish between various event handlers
82 // and capture handlers passed to MGL_wm
85 wxMGL_CAPTURE_MOUSE
= 1,
86 wxMGL_CAPTURE_KEYB
= 2
90 // ---------------------------------------------------------------------------
92 // ---------------------------------------------------------------------------
94 // Returns toplevel grandparent of given window:
95 static wxWindowMGL
* wxGetTopLevelParent(wxWindowMGL
*win
)
98 while (p
&& !p
->IsTopLevel())
103 // An easy way to capture screenshots:
104 static void wxCaptureScreenshot()
107 #define SCREENSHOT_FILENAME _T("sshot%03i.png")
109 #define SCREENSHOT_FILENAME _T("screenshot-%03i.png")
111 static int screenshot_num
= 0;
116 screenshot
.Printf(SCREENSHOT_FILENAME
, screenshot_num
++);
117 } while ( wxFileExists(screenshot
) && screenshot_num
< 1000 );
119 g_displayDC
->savePNGFromDC(screenshot
.mb_str(), 0, 0,
120 g_displayDC
->sizex(),
121 g_displayDC
->sizey());
123 wxMessageBox(_("Screenshot captured: ") + wxString(screenshot
));
126 // ---------------------------------------------------------------------------
128 // ---------------------------------------------------------------------------
130 static void MGLAPI
wxWindowPainter(window_t
*wnd
, MGLDC
*dc
)
132 wxWindowMGL
*w
= (wxWindow
*) wnd
->userData
;
134 if ( w
&& !(w
->GetWindowStyle() & wxTRANSPARENT_WINDOW
) )
137 w
->HandlePaint(&ctx
);
141 static ibool MGLAPI
wxWindowMouseHandler(window_t
*wnd
, event_t
*e
)
143 wxWindowMGL
*win
= (wxWindowMGL
*)MGL_wmGetWindowUserData(wnd
);
144 wxPoint
orig(win
->GetClientAreaOrigin());
147 MGL_wmCoordGlobalToLocal(win
->GetHandle(),
148 e
->where_x
, e
->where_y
, &where
.x
, &where
.y
);
150 for (wxWindowMGL
*w
= win
; w
; w
= w
->GetParent())
152 if ( !w
->IsEnabled() )
154 if ( w
->IsTopLevel() )
158 wxEventType type
= wxEVT_NULL
;
160 event
.SetEventObject(win
);
161 event
.SetTimestamp(e
->when
);
162 event
.m_x
= where
.x
- orig
.x
;
163 event
.m_y
= where
.y
- orig
.y
;
164 event
.m_shiftDown
= e
->modifiers
& EVT_SHIFTKEY
;
165 event
.m_controlDown
= e
->modifiers
& EVT_CTRLSTATE
;
166 event
.m_altDown
= e
->modifiers
& EVT_LEFTALT
;
167 event
.m_metaDown
= e
->modifiers
& EVT_RIGHTALT
;
168 event
.m_leftDown
= e
->modifiers
& EVT_LEFTBUT
;
169 event
.m_middleDown
= e
->modifiers
& EVT_MIDDLEBUT
;
170 event
.m_rightDown
= e
->modifiers
& EVT_RIGHTBUT
;
175 if ( e
->message
& EVT_LEFTBMASK
)
176 type
= (e
->message
& EVT_DBLCLICK
) ?
177 wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
;
178 else if ( e
->message
& EVT_MIDDLEBMASK
)
179 type
= (e
->message
& EVT_DBLCLICK
) ?
180 wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
;
181 else if ( e
->message
& EVT_RIGHTBMASK
)
182 type
= (e
->message
& EVT_DBLCLICK
) ?
183 wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
;
185 if ( win
->AcceptsFocus() && wxWindow::FindFocus() != win
)
191 if ( e
->message
& EVT_LEFTBMASK
)
192 type
= wxEVT_LEFT_UP
;
193 else if ( e
->message
& EVT_MIDDLEBMASK
)
194 type
= wxEVT_MIDDLE_UP
;
195 else if ( e
->message
& EVT_RIGHTBMASK
)
196 type
= wxEVT_RIGHT_UP
;
200 if ( !gs_mouseCapture
)
202 if ( win
!= gs_windowUnderMouse
)
204 if ( gs_windowUnderMouse
)
206 wxMouseEvent
event2(event
);
207 MGL_wmCoordGlobalToLocal(gs_windowUnderMouse
->GetHandle(),
208 e
->where_x
, e
->where_y
,
209 &event2
.m_x
, &event2
.m_y
);
211 wxPoint
orig(gs_windowUnderMouse
->GetClientAreaOrigin());
212 event2
.m_x
-= orig
.x
;
213 event2
.m_y
-= orig
.y
;
215 event2
.SetEventObject(gs_windowUnderMouse
);
216 event2
.SetEventType(wxEVT_LEAVE_WINDOW
);
217 gs_windowUnderMouse
->GetEventHandler()->ProcessEvent(event2
);
220 wxMouseEvent
event3(event
);
221 event3
.SetEventType(wxEVT_ENTER_WINDOW
);
222 win
->GetEventHandler()->ProcessEvent(event3
);
224 gs_windowUnderMouse
= win
;
227 else // gs_mouseCapture
229 bool inside
= (where
.x
>= 0 &&
231 where
.x
< win
->GetSize().x
&&
232 where
.y
< win
->GetSize().y
);
233 if ( (inside
&& gs_windowUnderMouse
!= win
) ||
234 (!inside
&& gs_windowUnderMouse
== win
) )
236 wxMouseEvent
evt(inside
?
237 wxEVT_ENTER_WINDOW
: wxEVT_LEAVE_WINDOW
);
238 evt
.SetEventObject(win
);
239 win
->GetEventHandler()->ProcessEvent(evt
);
240 gs_windowUnderMouse
= inside
? win
: NULL
;
251 if ( type
== wxEVT_NULL
)
257 event
.SetEventType(type
);
258 return win
->GetEventHandler()->ProcessEvent(event
);
262 static long wxScanToKeyCode(event_t
*event
, bool translate
)
264 // VS: make it __WXDEBUG__-only, since we have lots of wxLogTrace calls
265 // here and the arguments would be stored in non-debug executable even
266 // though wxLogTrace would be no-op...
268 #define KEY(mgl_key,wx_key) \
270 wxLogTrace(_T("keyevents"), \
271 _T("key " #mgl_key ", mapped to " #wx_key)); \
275 #define KEY(mgl_key,wx_key) \
276 case mgl_key: key = wx_key; break;
283 switch ( EVT_scanCode(event
->message
) )
285 KEY (KB_padMinus
, WXK_NUMPAD_SUBTRACT
)
286 KEY (KB_padPlus
, WXK_NUMPAD_ADD
)
287 KEY (KB_padTimes
, WXK_NUMPAD_MULTIPLY
)
288 KEY (KB_padDivide
, WXK_NUMPAD_DIVIDE
)
289 KEY (KB_padCenter
, WXK_NUMPAD_SEPARATOR
) // ?
290 KEY (KB_padLeft
, WXK_NUMPAD_LEFT
)
291 KEY (KB_padRight
, WXK_NUMPAD_RIGHT
)
292 KEY (KB_padUp
, WXK_NUMPAD_UP
)
293 KEY (KB_padDown
, WXK_NUMPAD_DOWN
)
294 KEY (KB_padInsert
, WXK_NUMPAD_INSERT
)
295 KEY (KB_padDelete
, WXK_NUMPAD_DELETE
)
296 KEY (KB_padHome
, WXK_NUMPAD_HOME
)
297 KEY (KB_padEnd
, WXK_NUMPAD_END
)
298 KEY (KB_padPageUp
, WXK_NUMPAD_PAGEUP
)
299 //KEY (KB_padPageUp, WXK_NUMPAD_PRIOR)
300 KEY (KB_padPageDown
, WXK_NUMPAD_PAGEDOWN
)
301 //KEY (KB_padPageDown, WXK_NUMPAD_NEXT)
312 KEY (KB_minus
, WXK_SUBTRACT
)
313 KEY (KB_equals
, WXK_ADD
)
314 KEY (KB_backSlash
, '\\')
325 KEY (KB_leftSquareBrace
,'[')
326 KEY (KB_rightSquareBrace
,']')
336 KEY (KB_semicolon
, ';')
337 KEY (KB_apostrophe
, '\'')
347 KEY (KB_divide
, WXK_DIVIDE
)
348 KEY (KB_space
, WXK_SPACE
)
357 switch ( EVT_scanCode(event
->message
) )
359 KEY (KB_padEnter
, WXK_NUMPAD_ENTER
)
369 KEY (KB_F10
, WXK_F10
)
370 KEY (KB_F11
, WXK_F11
)
371 KEY (KB_F12
, WXK_F12
)
372 KEY (KB_left
, WXK_LEFT
)
373 KEY (KB_right
, WXK_RIGHT
)
375 KEY (KB_down
, WXK_DOWN
)
376 KEY (KB_insert
, WXK_INSERT
)
377 KEY (KB_delete
, WXK_DELETE
)
378 KEY (KB_home
, WXK_HOME
)
379 KEY (KB_end
, WXK_END
)
380 KEY (KB_pageUp
, WXK_PAGEUP
)
381 KEY (KB_pageDown
, WXK_PAGEDOWN
)
382 KEY (KB_capsLock
, WXK_CAPITAL
)
383 KEY (KB_numLock
, WXK_NUMLOCK
)
384 KEY (KB_scrollLock
, WXK_SCROLL
)
385 KEY (KB_leftShift
, WXK_SHIFT
)
386 KEY (KB_rightShift
, WXK_SHIFT
)
387 KEY (KB_leftCtrl
, WXK_CONTROL
)
388 KEY (KB_rightCtrl
, WXK_CONTROL
)
389 KEY (KB_leftAlt
, WXK_ALT
)
390 KEY (KB_rightAlt
, WXK_ALT
)
391 KEY (KB_leftWindows
, WXK_START
)
392 KEY (KB_rightWindows
, WXK_START
)
393 KEY (KB_menu
, WXK_MENU
)
394 KEY (KB_sysReq
, WXK_SNAPSHOT
)
395 KEY (KB_esc
, WXK_ESCAPE
)
396 KEY (KB_backspace
, WXK_BACK
)
397 KEY (KB_tab
, WXK_TAB
)
398 KEY (KB_enter
, WXK_RETURN
)
401 key
= EVT_asciiCode(event
->message
);
411 static bool wxHandleSpecialKeys(wxKeyEvent
& event
)
413 // Add an easy way to capture screenshots:
414 if ( event
.m_keyCode
== WXK_SNAPSHOT
415 #ifdef __WXDEBUG__ // FIXME_MGL - remove when KB_sysReq works in MGL!
416 || (event
.m_keyCode
== WXK_F1
&&
417 event
.m_shiftDown
&& event
.m_controlDown
)
421 wxCaptureScreenshot();
425 if ( event
.m_keyCode
== WXK_F4
&& event
.m_altDown
&&
426 gs_activeFrame
!= NULL
)
428 gs_activeFrame
->Close();
435 static ibool MGLAPI
wxWindowKeybHandler(window_t
*wnd
, event_t
*e
)
437 wxWindowMGL
*win
= (wxWindowMGL
*)MGL_wmGetWindowUserData(wnd
);
439 if ( !win
->IsEnabled() ) return FALSE
;
442 MGL_wmCoordGlobalToLocal(win
->GetHandle(),
443 e
->where_x
, e
->where_y
, &where
.x
, &where
.y
);
446 event
.SetEventObject(win
);
447 event
.SetTimestamp(e
->when
);
448 event
.m_keyCode
= wxScanToKeyCode(e
, TRUE
);
449 event
.m_scanCode
= 0; // not used by wx at all
452 event
.m_shiftDown
= e
->modifiers
& EVT_SHIFTKEY
;
453 event
.m_controlDown
= e
->modifiers
& EVT_CTRLSTATE
;
454 event
.m_altDown
= e
->modifiers
& EVT_LEFTALT
;
455 event
.m_metaDown
= e
->modifiers
& EVT_RIGHTALT
;
457 if ( e
->what
== EVT_KEYUP
)
459 event
.SetEventType(wxEVT_KEY_UP
);
460 return win
->GetEventHandler()->ProcessEvent(event
);
467 event
.SetEventType(wxEVT_KEY_DOWN
);
470 ret
= win
->GetEventHandler()->ProcessEvent(event
);
472 // wxMSW doesn't send char events with Alt pressed
473 // Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x
474 // will only be sent if it is not in an accelerator table:
475 event2
.m_keyCode
= wxScanToKeyCode(e
, FALSE
);
476 if ( !ret
&& event2
.m_keyCode
!= 0 )
478 event2
.SetEventType(wxEVT_CHAR
);
479 ret
= win
->GetEventHandler()->ProcessEvent(event2
);
482 // Synthetize navigation key event, but do it only if the TAB key
483 // wasn't handled yet:
484 if ( !ret
&& event
.m_keyCode
== WXK_TAB
&&
485 win
->GetParent() && win
->GetParent()->HasFlag(wxTAB_TRAVERSAL
) )
487 wxNavigationKeyEvent navEvent
;
488 navEvent
.SetEventObject(win
->GetParent());
489 // Shift-TAB goes in reverse direction:
490 navEvent
.SetDirection(!event
.m_shiftDown
);
491 // Ctrl-TAB changes the (parent) window, i.e. switch notebook page:
492 navEvent
.SetWindowChange(event
.m_controlDown
);
493 navEvent
.SetCurrentFocus(wxStaticCast(win
, wxWindow
));
494 ret
= win
->GetParent()->GetEventHandler()->ProcessEvent(navEvent
);
497 // Finally, process special meaning keys that are usually
498 // a responsibility of OS or window manager:
500 ret
= wxHandleSpecialKeys(event
);
506 // ---------------------------------------------------------------------------
508 // ---------------------------------------------------------------------------
510 // in wxUniv this class is abstract because it doesn't have DoPopupMenu()
511 IMPLEMENT_ABSTRACT_CLASS(wxWindowMGL
, wxWindowBase
)
513 BEGIN_EVENT_TABLE(wxWindowMGL
, wxWindowBase
)
514 EVT_IDLE(wxWindowMGL::OnIdle
)
517 // ===========================================================================
519 // ===========================================================================
521 // ----------------------------------------------------------------------------
522 // constructors and such
523 // ----------------------------------------------------------------------------
525 extern wxDisplayModeInfo
wxGetDefaultDisplayMode();
527 void wxWindowMGL::Init()
529 // First of all, make sure window manager is up and running. If it is
530 // not the case, initialize it in default display mode
533 if ( !wxTheApp
->SetDisplayMode(wxGetDefaultDisplayMode()) )
534 wxFatalError(_("Cannot initialize display."));
543 m_isBeingDeleted
= FALSE
;
547 m_eraseBackground
= -1;
551 wxWindowMGL::~wxWindowMGL()
553 m_isBeingDeleted
= TRUE
;
555 if ( gs_mouseCapture
== this )
558 if (gs_activeFrame
== this)
560 gs_activeFrame
= NULL
;
561 // activate next frame in Z-order:
564 wxWindowMGL
*win
= (wxWindowMGL
*)m_wnd
->prev
->userData
;
569 if ( gs_focusedWindow
== this )
572 if ( gs_windowUnderMouse
== this )
573 gs_windowUnderMouse
= NULL
;
575 // VS: destroy children first and _then_ detach *this from its parent.
576 // If we'd do it the other way around, children wouldn't be able
577 // find their parent frame (see above).
581 m_parent
->RemoveChild(this);
584 MGL_wmDestroyWindow(m_wnd
);
587 // real construction (Init() must have been called before!)
588 bool wxWindowMGL::Create(wxWindow
*parent
,
593 const wxString
& name
)
595 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
599 parent
->AddChild(this);
602 x
= pos
.x
, y
= pos
.y
;
604 x
= 0; // FIXME_MGL, something better, see GTK+
606 y
= 0; // FIXME_MGL, something better, see GTK+
607 AdjustForParentClientOrigin(x
, y
, 0);
608 w
= WidthDefault(size
.x
);
609 h
= HeightDefault(size
.y
);
612 window_t
*wnd_parent
= parent
? parent
->GetHandle() : NULL
;
614 if ( !(style
& wxNO_FULL_REPAINT_ON_RESIZE
) )
616 mgl_style
|= MGL_WM_FULL_REPAINT_ON_RESIZE
;
618 if ( style
& wxSTAY_ON_TOP
)
620 mgl_style
|= MGL_WM_ALWAYS_ON_TOP
;
622 if ( style
& wxPOPUP_WINDOW
)
624 mgl_style
|= MGL_WM_ALWAYS_ON_TOP
;
625 // it is created hidden as other top level windows
630 window_t
*wnd
= MGL_wmCreateWindow(g_winMng
, wnd_parent
, x
, y
, w
, h
);
632 MGL_wmSetWindowFlags(wnd
, mgl_style
);
633 MGL_wmShowWindow(wnd
, m_isShown
);
640 void wxWindowMGL::SetMGLwindow_t(struct window_t
*wnd
)
643 MGL_wmDestroyWindow(m_wnd
);
646 if ( !m_wnd
) return;
648 m_isShown
= m_wnd
->visible
;
650 MGL_wmSetWindowUserData(m_wnd
, (void*) this);
651 MGL_wmSetWindowPainter(m_wnd
, wxWindowPainter
);
652 MGL_wmPushWindowEventHandler(m_wnd
, wxWindowMouseHandler
, EVT_MOUSEEVT
, 0);
653 MGL_wmPushWindowEventHandler(m_wnd
, wxWindowKeybHandler
, EVT_KEYEVT
, 0);
656 MGL_wmSetWindowCursor(m_wnd
, *m_cursor
.GetMGLCursor());
658 MGL_wmSetWindowCursor(m_wnd
, *wxSTANDARD_CURSOR
->GetMGLCursor());
661 // ---------------------------------------------------------------------------
663 // ---------------------------------------------------------------------------
665 void wxWindowMGL::SetFocus()
667 if ( gs_focusedWindow
== this ) return;
669 if ( gs_focusedWindow
)
670 gs_focusedWindow
->KillFocus();
672 gs_focusedWindow
= this;
674 MGL_wmCaptureEvents(GetHandle(), EVT_KEYEVT
, wxMGL_CAPTURE_KEYB
);
676 wxWindowMGL
*active
= wxGetTopLevelParent(this);
677 if ( !(m_windowStyle
& wxPOPUP_WINDOW
) && active
!= gs_activeFrame
)
679 if ( gs_activeFrame
)
681 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, gs_activeFrame
->GetId());
682 event
.SetEventObject(gs_activeFrame
);
683 gs_activeFrame
->GetEventHandler()->ProcessEvent(event
);
686 gs_activeFrame
= active
;
687 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, gs_activeFrame
->GetId());
688 event
.SetEventObject(gs_activeFrame
);
689 gs_activeFrame
->GetEventHandler()->ProcessEvent(event
);
692 wxFocusEvent
event(wxEVT_SET_FOCUS
, GetId());
693 event
.SetEventObject(this);
694 GetEventHandler()->ProcessEvent(event
);
697 // caret needs to be informed about focus change
698 wxCaret
*caret
= GetCaret();
701 #endif // wxUSE_CARET
704 void wxWindowMGL::KillFocus()
706 if ( gs_focusedWindow
!= this ) return;
707 gs_focusedWindow
= NULL
;
709 if ( m_isBeingDeleted
) return;
711 MGL_wmUncaptureEvents(GetHandle(), wxMGL_CAPTURE_KEYB
);
714 // caret needs to be informed about focus change
715 wxCaret
*caret
= GetCaret();
717 caret
->OnKillFocus();
718 #endif // wxUSE_CARET
720 wxFocusEvent
event(wxEVT_KILL_FOCUS
, GetId());
721 event
.SetEventObject(this);
722 GetEventHandler()->ProcessEvent(event
);
725 // ----------------------------------------------------------------------------
726 // this wxWindowBase function is implemented here (in platform-specific file)
727 // because it is static and so couldn't be made virtual
728 // ----------------------------------------------------------------------------
729 wxWindow
*wxWindowBase::FindFocus()
731 return (wxWindow
*)gs_focusedWindow
;
734 bool wxWindowMGL::Show(bool show
)
736 if ( !wxWindowBase::Show(show
) )
739 MGL_wmShowWindow(m_wnd
, show
);
741 if (!show
&& gs_activeFrame
== this)
743 // activate next frame in Z-order:
746 wxWindowMGL
*win
= (wxWindowMGL
*)m_wnd
->prev
->userData
;
754 // Raise the window to the top of the Z order
755 void wxWindowMGL::Raise()
757 MGL_wmRaiseWindow(m_wnd
);
760 // Lower the window to the bottom of the Z order
761 void wxWindowMGL::Lower()
763 MGL_wmLowerWindow(m_wnd
);
766 void wxWindowMGL::DoCaptureMouse()
768 if ( gs_mouseCapture
)
769 MGL_wmUncaptureEvents(gs_mouseCapture
->m_wnd
, wxMGL_CAPTURE_MOUSE
);
771 gs_mouseCapture
= this;
772 MGL_wmCaptureEvents(m_wnd
, EVT_MOUSEEVT
, wxMGL_CAPTURE_MOUSE
);
775 void wxWindowMGL::DoReleaseMouse()
777 wxASSERT_MSG( gs_mouseCapture
== this, wxT("attempt to release mouse, but this window hasn't captured it") )
779 MGL_wmUncaptureEvents(m_wnd
, wxMGL_CAPTURE_MOUSE
);
780 gs_mouseCapture
= NULL
;
783 /* static */ wxWindow
*wxWindowBase::GetCapture()
785 return (wxWindow
*)gs_mouseCapture
;
788 bool wxWindowMGL::SetCursor(const wxCursor
& cursor
)
790 if ( !wxWindowBase::SetCursor(cursor
) )
797 MGL_wmSetWindowCursor(m_wnd
, *m_cursor
.GetMGLCursor());
799 MGL_wmSetWindowCursor(m_wnd
, *wxSTANDARD_CURSOR
->GetMGLCursor());
804 void wxWindowMGL::WarpPointer(int x
, int y
)
806 ClientToScreen(&x
, &y
);
807 EVT_setMousePos(x
, y
);
810 #if WXWIN_COMPATIBILITY
811 // If nothing defined for this, try the parent.
812 // E.g. we may be a button loaded from a resource, with no callback function
814 void wxWindowMGL::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
816 if ( GetEventHandler()->ProcessEvent(event
) )
819 m_parent
->GetEventHandler()->OnCommand(win
, event
);
821 #endif // WXWIN_COMPATIBILITY_2
823 #if WXWIN_COMPATIBILITY
824 wxObject
* wxWindowMGL::GetChild(int number
) const
826 // Return a pointer to the Nth object in the Panel
827 wxNode
*node
= GetChildren().First();
833 wxObject
*obj
= (wxObject
*)node
->Data();
839 #endif // WXWIN_COMPATIBILITY
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 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") )
901 if (x
) *x
= m_wnd
->x
;
902 if (y
) *y
= m_wnd
->y
;
905 void wxWindowMGL::DoScreenToClient(int *x
, int *y
) const
908 MGL_wmCoordGlobalToLocal(m_wnd
, 0, 0, &ax
, &ay
);
915 void wxWindowMGL::DoClientToScreen(int *x
, int *y
) const
918 MGL_wmCoordLocalToGlobal(m_wnd
, 0, 0, &ax
, &ay
);
925 // Get size *available for subwindows* i.e. excluding menu bar etc.
926 void wxWindowMGL::DoGetClientSize(int *x
, int *y
) const
931 void wxWindowMGL::DoMoveWindow(int x
, int y
, int width
, int height
)
933 MGL_wmSetWindowPosition(GetHandle(), x
, y
, width
, height
);
936 // set the size of the window: if the dimensions are positive, just use them,
937 // but if any of them is equal to -1, it means that we must find the value for
938 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
939 // which case -1 is a valid value for x and y)
941 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
942 // the width/height to best suit our contents, otherwise we reuse the current
944 void wxWindowMGL::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
946 // get the current size and position...
947 int currentX
, currentY
;
948 GetPosition(¤tX
, ¤tY
);
949 int currentW
,currentH
;
950 GetSize(¤tW
, ¤tH
);
952 // ... and don't do anything (avoiding flicker) if it's already ok
953 if ( x
== currentX
&& y
== currentY
&&
954 width
== currentW
&& height
== currentH
)
959 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
961 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
964 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
969 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
971 size
= DoGetBestSize();
976 // just take the current one
983 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
987 size
= DoGetBestSize();
989 //else: already called DoGetBestSize() above
995 // just take the current one
1000 int maxWidth
= GetMaxWidth(),
1001 minWidth
= GetMinWidth(),
1002 maxHeight
= GetMaxHeight(),
1003 minHeight
= GetMinHeight();
1005 if ( minWidth
!= -1 && width
< minWidth
) width
= minWidth
;
1006 if ( maxWidth
!= -1 && width
> maxWidth
) width
= maxWidth
;
1007 if ( minHeight
!= -1 && height
< minHeight
) height
= minHeight
;
1008 if ( maxHeight
!= -1 && height
> maxHeight
) height
= maxHeight
;
1010 if ( m_wnd
->x
!= x
|| m_wnd
->y
!= y
||
1011 (int)m_wnd
->width
!= width
|| (int)m_wnd
->height
!= height
)
1013 DoMoveWindow(x
, y
, width
, height
);
1015 wxSizeEvent
event(wxSize(width
, height
), GetId());
1016 event
.SetEventObject(this);
1017 GetEventHandler()->ProcessEvent(event
);
1021 void wxWindowMGL::DoSetClientSize(int width
, int height
)
1023 SetSize(width
, height
);
1026 // ---------------------------------------------------------------------------
1028 // ---------------------------------------------------------------------------
1030 int wxWindowMGL::GetCharHeight() const
1034 return dc
.GetCharHeight();
1037 int wxWindowMGL::GetCharWidth() const
1041 return dc
.GetCharWidth();
1044 void wxWindowMGL::GetTextExtent(const wxString
& string
,
1046 int *descent
, int *externalLeading
,
1047 const wxFont
*theFont
) const
1052 dc
.GetTextExtent(string
, x
, y
, descent
, externalLeading
, (wxFont
*)theFont
);
1055 #if wxUSE_CARET && WXWIN_COMPATIBILITY
1056 // ---------------------------------------------------------------------------
1057 // Caret manipulation
1058 // ---------------------------------------------------------------------------
1060 void wxWindowMGL::CreateCaret(int w
, int h
)
1062 SetCaret(new wxCaret(this, w
, h
));
1065 void wxWindowMGL::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
1067 wxFAIL_MSG("not implemented");
1070 void wxWindowMGL::ShowCaret(bool show
)
1072 wxCHECK_RET( m_caret
, "no caret to show" );
1074 m_caret
->Show(show
);
1077 void wxWindowMGL::DestroyCaret()
1082 void wxWindowMGL::SetCaretPos(int x
, int y
)
1084 wxCHECK_RET( m_caret
, "no caret to move" );
1086 m_caret
->Move(x
, y
);
1089 void wxWindowMGL::GetCaretPos(int *x
, int *y
) const
1091 wxCHECK_RET( m_caret
, "no caret to get position of" );
1093 m_caret
->GetPosition(x
, y
);
1095 #endif // wxUSE_CARET
1098 // ---------------------------------------------------------------------------
1100 // ---------------------------------------------------------------------------
1102 void wxWindowMGL::Clear()
1104 wxClientDC
dc((wxWindow
*)this);
1105 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1106 dc
.SetBackground(brush
);
1110 #include "wx/menu.h"
1111 void wxWindowMGL::Refresh(bool eraseBack
, const wxRect
*rect
)
1113 if ( m_eraseBackground
== -1 )
1114 m_eraseBackground
= eraseBack
;
1116 m_eraseBackground
|= eraseBack
;
1121 r
.left
= rect
->GetLeft(), r
.right
= rect
->GetRight();
1122 r
.top
= rect
->GetTop(), r
.bottom
= rect
->GetBottom();
1123 MGL_wmInvalidateWindowRect(GetHandle(), &r
);
1126 MGL_wmInvalidateWindow(GetHandle());
1129 void wxWindowMGL::Update()
1132 MGL_wmUpdateDC(g_winMng
);
1135 void wxWindowMGL::Freeze()
1138 m_refreshAfterThaw
= FALSE
;
1141 void wxWindowMGL::Thaw()
1144 if ( m_refreshAfterThaw
)
1148 void wxWindowMGL::HandlePaint(MGLDevCtx
*dc
)
1152 // Don't paint anything if the window is frozen.
1153 m_refreshAfterThaw
= TRUE
;
1158 // FIXME_MGL -- debugging stuff, to be removed!
1159 static int debugPaintEvents
= -1;
1160 if ( debugPaintEvents
== -1 )
1161 debugPaintEvents
= wxGetEnv(wxT("WXMGL_DEBUG_PAINT_EVENTS"), NULL
);
1162 if ( debugPaintEvents
)
1164 dc
->setColorRGB(255,0,255);
1165 dc
->fillRect(-1000,-1000,2000,2000);
1171 dc
->getClipRegion(clip
);
1172 m_updateRegion
= wxRegion(clip
);
1176 // must hide caret temporarily, otherwise we'd get rendering artifacts
1177 wxCaret
*caret
= GetCaret();
1180 #endif // wxUSE_CARET
1182 if ( m_eraseBackground
!= 0 )
1184 wxWindowDC
dc((wxWindow
*)this);
1185 wxEraseEvent
eventEr(m_windowId
, &dc
);
1186 eventEr
.SetEventObject(this);
1187 GetEventHandler()->ProcessEvent(eventEr
);
1189 m_eraseBackground
= -1;
1191 wxNcPaintEvent
eventNc(GetId());
1192 eventNc
.SetEventObject(this);
1193 GetEventHandler()->ProcessEvent(eventNc
);
1195 wxPaintEvent
eventPt(GetId());
1196 eventPt
.SetEventObject(this);
1197 GetEventHandler()->ProcessEvent(eventPt
);
1202 #endif // wxUSE_CARET
1204 m_paintMGLDC
= NULL
;
1205 m_updateRegion
.Clear();
1209 // Find the wxWindow at the current mouse position, returning the mouse
1211 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1213 return wxFindWindowAtPoint(pt
= wxGetMousePosition());
1216 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
1218 window_t
*wnd
= MGL_wmGetWindowAtPosition(g_winMng
, pt
.x
, pt
.y
);
1219 return (wxWindow
*)wnd
->userData
;
1223 // ---------------------------------------------------------------------------
1224 // idle events processing
1225 // ---------------------------------------------------------------------------
1227 void wxWindowMGL::OnIdle(wxIdleEvent
& WXUNUSED(event
))