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"
35 #include "wx/dcclient.h"
42 #if wxUSE_DRAG_AND_DROP
47 #include "wx/sysopt.h"
48 #include "wx/mgl/private.h"
50 #include "wx/dcscreen.h"
55 #include "wx/tooltip.h"
58 // ---------------------------------------------------------------------------
60 // ---------------------------------------------------------------------------
62 // MGL window manager and associated DC.
63 winmng_t
*g_winMng
= NULL
;
64 MGLDevCtx
*g_displayDC
= NULL
;
66 // the window that has keyboard focus:
67 static wxWindowMGL
*gs_focusedWindow
= 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())
103 // Add an easy way to capture screenshots:
104 static void CaptureScreenshot()
108 static int screenshot_num
= 0;
109 char screenshot
[128];
110 sprintf(screenshot
, "screenshot-%03i.png", screenshot_num
++);
111 g_displayDC
->savePNGFromDC(screenshot
, 0, 0,
112 g_displayDC
->sizex(),
113 g_displayDC
->sizey());
117 // ---------------------------------------------------------------------------
119 // ---------------------------------------------------------------------------
121 static void wxWindowPainter(window_t
*wnd
, MGLDC
*dc
)
123 wxWindowMGL
*w
= (wxWindow
*) wnd
->userData
;
125 if ( w
&& !(w
->GetWindowStyle() & wxTRANSPARENT_WINDOW
) )
128 w
->HandlePaint(&ctx
);
130 // FIXME_MGL -- root window should be a regular window so that
131 // enter/leave and activate/deactivate events work correctly
134 static ibool
wxWindowMouseHandler(window_t
*wnd
, event_t
*e
)
136 wxWindowMGL
*win
= (wxWindowMGL
*)MGL_wmGetWindowUserData(wnd
);
139 MGL_wmCoordGlobalToLocal(win
->GetHandle(),
140 e
->where_x
, e
->where_y
, &where
.x
, &where
.y
);
142 for (wxWindowMGL
*w
= win
; w
; w
= w
->GetParent())
144 if ( !w
->IsEnabled() )
146 if ( w
->IsTopLevel() )
150 wxEventType type
= wxEVT_NULL
;
152 event
.SetEventObject(win
);
153 event
.SetTimestamp(e
->when
);
156 event
.m_shiftDown
= e
->modifiers
& EVT_SHIFTKEY
;
157 event
.m_controlDown
= e
->modifiers
& EVT_CTRLSTATE
;
158 event
.m_altDown
= e
->modifiers
& EVT_LEFTALT
;
159 event
.m_metaDown
= e
->modifiers
& EVT_RIGHTALT
;
160 event
.m_leftDown
= e
->modifiers
& EVT_LEFTBUT
;
161 event
.m_middleDown
= e
->modifiers
& EVT_MIDDLEBUT
;
162 event
.m_rightDown
= e
->modifiers
& EVT_RIGHTBUT
;
167 if ( e
->message
& EVT_LEFTBMASK
)
168 type
= (e
->message
& EVT_DBLCLICK
) ?
169 wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
;
170 else if ( e
->message
& EVT_MIDDLEBMASK
)
171 type
= (e
->message
& EVT_DBLCLICK
) ?
172 wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
;
173 else if ( e
->message
& EVT_RIGHTBMASK
)
174 type
= (e
->message
& EVT_DBLCLICK
) ?
175 wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
;
179 if ( e
->message
& EVT_LEFTBMASK
)
180 type
= wxEVT_LEFT_UP
;
181 else if ( e
->message
& EVT_MIDDLEBMASK
)
182 type
= wxEVT_MIDDLE_UP
;
183 else if ( e
->message
& EVT_RIGHTBMASK
)
184 type
= wxEVT_RIGHT_UP
;
188 if ( !gs_mouseCapture
)
190 if ( win
!= gs_windowUnderMouse
)
192 if ( gs_windowUnderMouse
)
194 wxMouseEvent
event2(event
);
195 MGL_wmCoordGlobalToLocal(gs_windowUnderMouse
->GetHandle(),
196 e
->where_x
, e
->where_y
,
197 &event2
.m_x
, &event2
.m_y
);
199 event2
.SetEventObject(gs_windowUnderMouse
);
200 event2
.SetEventType(wxEVT_LEAVE_WINDOW
);
201 gs_windowUnderMouse
->GetEventHandler()->ProcessEvent(event2
);
204 wxMouseEvent
event3(event
);
205 event3
.SetEventType(wxEVT_ENTER_WINDOW
);
206 win
->GetEventHandler()->ProcessEvent(event3
);
208 gs_windowUnderMouse
= win
;
211 else // gs_mouseCapture
213 bool inside
= (where
.x
>= 0 &&
215 where
.x
< win
->GetSize().x
&&
216 where
.y
< win
->GetSize().y
);
217 if ( (inside
&& gs_windowUnderMouse
!= win
) ||
218 (!inside
&& gs_windowUnderMouse
== win
) )
220 wxMouseEvent
evt(inside
?
221 wxEVT_ENTER_WINDOW
: wxEVT_LEAVE_WINDOW
);
222 evt
.SetEventObject(win
);
223 win
->GetEventHandler()->ProcessEvent(evt
);
224 gs_windowUnderMouse
= inside
? win
: NULL
;
235 if ( type
== wxEVT_NULL
)
241 event
.SetEventType(type
);
242 return win
->GetEventHandler()->ProcessEvent(event
);
246 static long wxScanToKeyCode(event_t
*event
)
248 #define KEY(mgl,wx) case mgl: key = wx; break;
251 switch ( EVT_scanCode(event
->message
) )
253 KEY (KB_padEnter
, WXK_NUMPAD_ENTER
)
254 KEY (KB_padMinus
, WXK_NUMPAD_SUBTRACT
)
255 KEY (KB_padPlus
, WXK_NUMPAD_ADD
)
256 KEY (KB_padTimes
, WXK_NUMPAD_MULTIPLY
)
257 KEY (KB_padDivide
, WXK_NUMPAD_DIVIDE
)
258 KEY (KB_padLeft
, WXK_NUMPAD_LEFT
)
259 KEY (KB_padRight
, WXK_NUMPAD_RIGHT
)
260 KEY (KB_padUp
, WXK_NUMPAD_UP
)
261 KEY (KB_padDown
, WXK_NUMPAD_DOWN
)
262 KEY (KB_padInsert
, WXK_NUMPAD_INSERT
)
263 KEY (KB_padDelete
, WXK_NUMPAD_DELETE
)
264 KEY (KB_padHome
, WXK_NUMPAD_HOME
)
265 KEY (KB_padEnd
, WXK_NUMPAD_END
)
266 KEY (KB_padPageUp
, WXK_NUMPAD_PAGEUP
)
267 //KEY (KB_padPageUp, WXK_NUMPAD_PRIOR)
268 KEY (KB_padPageDown
, WXK_NUMPAD_PAGEDOWN
)
269 //KEY (KB_padPageDown, WXK_NUMPAD_NEXT)
270 KEY (KB_padCenter
, WXK_NUMPAD_SEPARATOR
) // ?
280 KEY (KB_F10
, WXK_F10
)
281 KEY (KB_F11
, WXK_F11
)
282 KEY (KB_F12
, WXK_F12
)
283 KEY (KB_left
, WXK_LEFT
)
284 KEY (KB_right
, WXK_RIGHT
)
286 KEY (KB_down
, WXK_DOWN
)
287 KEY (KB_insert
, WXK_INSERT
)
288 KEY (KB_delete
, WXK_DELETE
)
289 KEY (KB_home
, WXK_HOME
)
290 KEY (KB_end
, WXK_END
)
291 KEY (KB_pageUp
, WXK_PAGEUP
)
292 KEY (KB_pageDown
, WXK_PAGEDOWN
)
293 KEY (KB_capsLock
, WXK_CAPITAL
)
294 KEY (KB_numLock
, WXK_NUMLOCK
)
295 KEY (KB_scrollLock
, WXK_SCROLL
)
296 KEY (KB_leftShift
, WXK_SHIFT
)
297 KEY (KB_rightShift
, WXK_SHIFT
)
298 KEY (KB_leftCtrl
, WXK_CONTROL
)
299 KEY (KB_rightCtrl
, WXK_CONTROL
)
300 KEY (KB_leftAlt
, WXK_ALT
)
301 KEY (KB_rightAlt
, WXK_ALT
)
302 KEY (KB_leftWindows
, WXK_START
)
303 KEY (KB_rightWindows
, WXK_START
)
304 KEY (KB_menu
, WXK_MENU
)
305 KEY (KB_sysReq
, WXK_SNAPSHOT
)
306 KEY (KB_esc
, WXK_ESCAPE
)
317 KEY (KB_minus
, WXK_SUBTRACT
)
318 KEY (KB_equals
, WXK_ADD
)
319 KEY (KB_backSlash
, '\\')
320 KEY (KB_backspace
, WXK_BACK
)
321 KEY (KB_tab
, WXK_TAB
)
332 KEY (KB_leftSquareBrace
,'[')
333 KEY (KB_rightSquareBrace
,']')
334 KEY (KB_enter
, WXK_RETURN
)
344 KEY (KB_semicolon
, ';')
345 KEY (KB_apostrophe
, '\'')
355 KEY (KB_divide
, WXK_DIVIDE
)
356 KEY (KB_space
, WXK_SPACE
)
360 key
= EVT_asciiCode(event
->message
);
369 static long wxAsciiToKeyCode(event_t
*event
)
371 return (long)EVT_asciiCode(event
->message
);
374 static ibool
wxWindowKeybHandler(window_t
*wnd
, event_t
*e
)
376 wxWindowMGL
*win
= (wxWindowMGL
*)MGL_wmGetWindowUserData(wnd
);
378 if ( !win
->IsEnabled() ) return FALSE
;
381 MGL_wmCoordGlobalToLocal(win
->GetHandle(),
382 e
->where_x
, e
->where_y
, &where
.x
, &where
.y
);
385 event
.SetEventObject(win
);
386 event
.SetTimestamp(e
->when
);
387 event
.m_keyCode
= wxScanToKeyCode(e
);
388 event
.m_scanCode
= 0; // not used by wx at all
391 event
.m_shiftDown
= e
->modifiers
& EVT_SHIFTKEY
;
392 event
.m_controlDown
= e
->modifiers
& EVT_CTRLSTATE
;
393 event
.m_altDown
= e
->modifiers
& EVT_LEFTALT
;
394 event
.m_metaDown
= e
->modifiers
& EVT_RIGHTALT
;
396 if ( e
->what
== EVT_KEYUP
)
398 event
.SetEventType(wxEVT_KEY_UP
);
399 return win
->GetEventHandler()->ProcessEvent(event
);
406 event
.SetEventType(wxEVT_KEY_DOWN
);
409 ret
= win
->GetEventHandler()->ProcessEvent(event
);
413 // Add an easy way to capture screenshots:
414 if ( event
.m_keyCode
== WXK_F1
&&
415 event
.m_shiftDown
&& event
.m_controlDown
)
422 for (wxWindowMGL
*w
= win
; w
; w
= w
->GetParent())
424 int command
= w
->GetAcceleratorTable()->GetCommand(event
);
427 wxCommandEvent
eventc(wxEVT_COMMAND_MENU_SELECTED
, command
);
428 ret
= w
->GetEventHandler()->ProcessEvent(eventc
);
431 if ( w
->IsTopLevel() )
435 #endif // wxUSE_ACCEL
437 /* wxMSW doesn't send char events with Alt pressed */
438 /* Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x
439 will only be sent if it is not in an accelerator table. */
440 event2
.m_keyCode
= wxAsciiToKeyCode(e
);
441 if ( !ret
&& event2
.m_keyCode
!= 0 )
443 event2
.SetEventType(wxEVT_CHAR
);
444 ret
= win
->GetEventHandler()->ProcessEvent(event2
);
451 // ---------------------------------------------------------------------------
453 // ---------------------------------------------------------------------------
455 // in wxUniv this class is abstract because it doesn't have DoPopupMenu()
456 IMPLEMENT_ABSTRACT_CLASS(wxWindowMGL
, wxWindowBase
)
458 BEGIN_EVENT_TABLE(wxWindowMGL
, wxWindowBase
)
461 // ===========================================================================
463 // ===========================================================================
465 // ----------------------------------------------------------------------------
466 // constructors and such
467 // ----------------------------------------------------------------------------
469 void wxWindowMGL::Init()
477 m_isBeingDeleted
= FALSE
;
481 m_eraseBackground
= -1;
485 wxWindowMGL::~wxWindowMGL()
487 m_isBeingDeleted
= TRUE
;
489 if ( gs_mouseCapture
== this )
492 if (gs_activeFrame
== this)
494 gs_activeFrame
= NULL
;
495 // activate next frame in Z-order:
498 wxWindowMGL
*win
= (wxWindowMGL
*)m_wnd
->prev
->userData
;
503 if ( gs_focusedWindow
== this )
506 if ( gs_windowUnderMouse
== this )
507 gs_windowUnderMouse
= NULL
;
509 // VS: destroy children first and _then_ detach *this from its parent.
510 // If we'd do it the other way around, children wouldn't be able
511 // find their parent frame (see above).
515 m_parent
->RemoveChild(this);
518 MGL_wmDestroyWindow(m_wnd
);
521 // real construction (Init() must have been called before!)
522 bool wxWindowMGL::Create(wxWindow
*parent
,
527 const wxString
& name
)
529 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
533 parent
->AddChild(this);
536 x
= pos
.x
, y
= pos
.y
;
538 x
= 0; // FIXME_MGL, something better, see GTK+
540 y
= 0; // FIXME_MGL, something better, see GTK+
541 w
= WidthDefault(size
.x
);
542 h
= HeightDefault(size
.y
);
545 window_t
*wnd_parent
= parent
? parent
->GetHandle() : NULL
;
547 if ( !(style
& wxNO_FULL_REPAINT_ON_RESIZE
) )
549 mgl_style
|= MGL_WM_FULL_REPAINT_ON_RESIZE
;
551 if ( style
& wxSTAY_ON_TOP
)
553 mgl_style
|= MGL_WM_ALWAYS_ON_TOP
;
555 if ( style
& wxPOPUP_WINDOW
)
557 mgl_style
|= MGL_WM_ALWAYS_ON_TOP
;
558 // it is created hidden as other top level windows
563 window_t
*wnd
= MGL_wmCreateWindow(g_winMng
, wnd_parent
, x
, y
, w
, h
);
565 MGL_wmSetWindowFlags(wnd
, mgl_style
);
566 MGL_wmShowWindow(wnd
, m_isShown
);
573 void wxWindowMGL::SetMGLwindow_t(struct window_t
*wnd
)
576 MGL_wmDestroyWindow(m_wnd
);
579 if ( !m_wnd
) return;
581 m_isShown
= m_wnd
->visible
;
583 MGL_wmSetWindowUserData(m_wnd
, (void*) this);
584 MGL_wmSetWindowPainter(m_wnd
, wxWindowPainter
);
585 MGL_wmPushWindowEventHandler(m_wnd
, wxWindowMouseHandler
, EVT_MOUSEEVT
, 0);
586 MGL_wmPushWindowEventHandler(m_wnd
, wxWindowKeybHandler
, EVT_KEYEVT
, 0);
589 MGL_wmSetWindowCursor(m_wnd
, *m_cursor
.GetMGLCursor());
591 MGL_wmSetWindowCursor(m_wnd
, *wxSTANDARD_CURSOR
->GetMGLCursor());
594 // ---------------------------------------------------------------------------
596 // ---------------------------------------------------------------------------
598 void wxWindowMGL::SetFocus()
600 if ( gs_focusedWindow
== this ) return;
602 if ( gs_focusedWindow
)
603 gs_focusedWindow
->KillFocus();
605 gs_focusedWindow
= this;
607 MGL_wmCaptureEvents(GetHandle(), EVT_KEYEVT
, wxMGL_CAPTURE_KEYB
);
610 // caret needs to be informed about focus change
611 wxCaret
*caret
= GetCaret();
614 #endif // wxUSE_CARET
616 wxWindowMGL
*active
= wxGetTopLevelParent(this);
617 if ( !(m_windowStyle
& wxPOPUP_WINDOW
) && active
!= gs_activeFrame
)
619 if ( gs_activeFrame
)
621 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, gs_activeFrame
->GetId());
622 event
.SetEventObject(gs_activeFrame
);
623 gs_activeFrame
->GetEventHandler()->ProcessEvent(event
);
626 gs_activeFrame
= active
;
627 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, gs_activeFrame
->GetId());
628 event
.SetEventObject(gs_activeFrame
);
629 gs_activeFrame
->GetEventHandler()->ProcessEvent(event
);
632 wxFocusEvent
event(wxEVT_SET_FOCUS
, GetId());
633 event
.SetEventObject(this);
634 GetEventHandler()->ProcessEvent(event
);
637 void wxWindowMGL::KillFocus()
639 if ( gs_focusedWindow
!= this ) return;
640 gs_focusedWindow
= NULL
;
642 if ( m_isBeingDeleted
) return;
644 MGL_wmUncaptureEvents(GetHandle(), wxMGL_CAPTURE_KEYB
);
647 // caret needs to be informed about focus change
648 wxCaret
*caret
= GetCaret();
650 caret
->OnKillFocus();
651 #endif // wxUSE_CARET
653 wxFocusEvent
event(wxEVT_KILL_FOCUS
, GetId());
654 event
.SetEventObject(this);
655 GetEventHandler()->ProcessEvent(event
);
658 // ----------------------------------------------------------------------------
659 // this wxWindowBase function is implemented here (in platform-specific file)
660 // because it is static and so couldn't be made virtual
661 // ----------------------------------------------------------------------------
662 wxWindow
*wxWindowBase::FindFocus()
664 return (wxWindow
*)gs_focusedWindow
;
667 bool wxWindowMGL::Show(bool show
)
669 if ( !wxWindowBase::Show(show
) )
672 MGL_wmShowWindow(m_wnd
, show
);
674 if (!show
&& gs_activeFrame
== this)
676 // activate next frame in Z-order:
679 wxWindowMGL
*win
= (wxWindowMGL
*)m_wnd
->prev
->userData
;
687 // Raise the window to the top of the Z order
688 void wxWindowMGL::Raise()
690 MGL_wmRaiseWindow(m_wnd
);
693 // Lower the window to the bottom of the Z order
694 void wxWindowMGL::Lower()
696 MGL_wmLowerWindow(m_wnd
);
699 void wxWindowMGL::CaptureMouse()
701 if ( gs_mouseCapture
)
702 MGL_wmUncaptureEvents(gs_mouseCapture
->m_wnd
, wxMGL_CAPTURE_MOUSE
);
704 gs_mouseCapture
= this;
705 MGL_wmCaptureEvents(m_wnd
, EVT_MOUSEEVT
, wxMGL_CAPTURE_MOUSE
);
708 void wxWindowMGL::ReleaseMouse()
710 wxASSERT_MSG( gs_mouseCapture
== this, wxT("attempt to release mouse, but this window hasn't captured it") )
712 MGL_wmUncaptureEvents(m_wnd
, wxMGL_CAPTURE_MOUSE
);
713 gs_mouseCapture
= NULL
;
716 /* static */ wxWindow
*wxWindowBase::GetCapture()
718 return (wxWindow
*)gs_mouseCapture
;
721 bool wxWindowMGL::SetCursor(const wxCursor
& cursor
)
723 if ( !wxWindowBase::SetCursor(cursor
) )
730 MGL_wmSetWindowCursor(m_wnd
, *m_cursor
.GetMGLCursor());
732 MGL_wmSetWindowCursor(m_wnd
, *wxSTANDARD_CURSOR
->GetMGLCursor());
737 void wxWindowMGL::WarpPointer(int x
, int y
)
739 ClientToScreen(&x
, &y
);
740 EVT_setMousePos(x
, y
);
743 #if WXWIN_COMPATIBILITY
744 // If nothing defined for this, try the parent.
745 // E.g. we may be a button loaded from a resource, with no callback function
747 void wxWindowMGL::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
749 if ( GetEventHandler()->ProcessEvent(event
) )
752 m_parent
->GetEventHandler()->OnCommand(win
, event
);
754 #endif // WXWIN_COMPATIBILITY_2
756 #if WXWIN_COMPATIBILITY
757 wxObject
* wxWindowMGL::GetChild(int number
) const
759 // Return a pointer to the Nth object in the Panel
760 wxNode
*node
= GetChildren().First();
766 wxObject
*obj
= (wxObject
*)node
->Data();
772 #endif // WXWIN_COMPATIBILITY
774 // Set this window to be the child of 'parent'.
775 bool wxWindowMGL::Reparent(wxWindowBase
*parent
)
777 if ( !wxWindowBase::Reparent(parent
) )
780 MGL_wmReparentWindow(m_wnd
, parent
->GetHandle());
786 // ---------------------------------------------------------------------------
788 // ---------------------------------------------------------------------------
790 #if wxUSE_DRAG_AND_DROP
792 void wxWindowMGL::SetDropTarget(wxDropTarget
*pDropTarget
)
794 if ( m_dropTarget
!= 0 ) {
795 m_dropTarget
->Revoke(m_hWnd
);
799 m_dropTarget
= pDropTarget
;
800 if ( m_dropTarget
!= 0 )
801 m_dropTarget
->Register(m_hWnd
);
804 #endif // wxUSE_DRAG_AND_DROP
806 // old style file-manager drag&drop support: we retain the old-style
807 // DragAcceptFiles in parallel with SetDropTarget.
808 void wxWindowMGL::DragAcceptFiles(bool accept
)
811 HWND hWnd
= GetHwnd();
813 ::DragAcceptFiles(hWnd
, (BOOL
)accept
);
817 // ---------------------------------------------------------------------------
818 // moving and resizing
819 // ---------------------------------------------------------------------------
822 void wxWindowMGL::DoGetSize(int *x
, int *y
) const
824 if (x
) *x
= m_wnd
->width
;
825 if (y
) *y
= m_wnd
->height
;
828 void wxWindowMGL::DoGetPosition(int *x
, int *y
) const
830 if (x
) *x
= m_wnd
->x
;
831 if (y
) *y
= m_wnd
->y
;
834 void wxWindowMGL::DoScreenToClient(int *x
, int *y
) const
837 MGL_wmCoordGlobalToLocal(m_wnd
, 0, 0, &ax
, &ay
);
844 void wxWindowMGL::DoClientToScreen(int *x
, int *y
) const
847 MGL_wmCoordLocalToGlobal(m_wnd
, 0, 0, &ax
, &ay
);
854 // Get size *available for subwindows* i.e. excluding menu bar etc.
855 void wxWindowMGL::DoGetClientSize(int *x
, int *y
) const
860 void wxWindowMGL::DoMoveWindow(int x
, int y
, int width
, int height
)
862 MGL_wmSetWindowPosition(GetHandle(), x
, y
, width
, height
);
865 // set the size of the window: if the dimensions are positive, just use them,
866 // but if any of them is equal to -1, it means that we must find the value for
867 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
868 // which case -1 is a valid value for x and y)
870 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
871 // the width/height to best suit our contents, otherwise we reuse the current
873 void wxWindowMGL::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
875 // get the current size and position...
876 int currentX
, currentY
;
877 GetPosition(¤tX
, ¤tY
);
878 int currentW
,currentH
;
879 GetSize(¤tW
, ¤tH
);
881 // ... and don't do anything (avoiding flicker) if it's already ok
882 if ( x
== currentX
&& y
== currentY
&&
883 width
== currentW
&& height
== currentH
)
888 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
890 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
893 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
898 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
900 size
= DoGetBestSize();
905 // just take the current one
912 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
916 size
= DoGetBestSize();
918 //else: already called DoGetBestSize() above
924 // just take the current one
929 DoMoveWindow(x
, y
, width
, height
);
931 wxSizeEvent
event(wxSize(width
, height
), GetId());
932 event
.SetEventObject(this);
933 GetEventHandler()->ProcessEvent(event
);
936 void wxWindowMGL::DoSetClientSize(int width
, int height
)
938 SetSize(width
, height
);
941 // ---------------------------------------------------------------------------
943 // ---------------------------------------------------------------------------
945 int wxWindowMGL::GetCharHeight() const
949 return dc
.GetCharHeight();
952 int wxWindowMGL::GetCharWidth() const
956 return dc
.GetCharWidth();
959 void wxWindowMGL::GetTextExtent(const wxString
& string
,
961 int *descent
, int *externalLeading
,
962 const wxFont
*theFont
) const
967 dc
.GetTextExtent(string
, x
, y
, descent
, externalLeading
, (wxFont
*)theFont
);
970 #if wxUSE_CARET && WXWIN_COMPATIBILITY
971 // ---------------------------------------------------------------------------
972 // Caret manipulation
973 // ---------------------------------------------------------------------------
975 void wxWindowMGL::CreateCaret(int w
, int h
)
977 SetCaret(new wxCaret(this, w
, h
));
980 void wxWindowMGL::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
982 wxFAIL_MSG("not implemented");
985 void wxWindowMGL::ShowCaret(bool show
)
987 wxCHECK_RET( m_caret
, "no caret to show" );
992 void wxWindowMGL::DestroyCaret()
997 void wxWindowMGL::SetCaretPos(int x
, int y
)
999 wxCHECK_RET( m_caret
, "no caret to move" );
1001 m_caret
->Move(x
, y
);
1004 void wxWindowMGL::GetCaretPos(int *x
, int *y
) const
1006 wxCHECK_RET( m_caret
, "no caret to get position of" );
1008 m_caret
->GetPosition(x
, y
);
1010 #endif // wxUSE_CARET
1013 // ---------------------------------------------------------------------------
1015 // ---------------------------------------------------------------------------
1017 void wxWindowMGL::Clear()
1019 wxClientDC
dc((wxWindow
*)this);
1020 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1021 dc
.SetBackground(brush
);
1025 #include "wx/menu.h"
1026 void wxWindowMGL::Refresh(bool eraseBack
, const wxRect
*rect
)
1028 if ( m_eraseBackground
== -1 )
1029 m_eraseBackground
= eraseBack
;
1031 m_eraseBackground
|= eraseBack
;
1036 r
.left
= rect
->GetLeft(), r
.right
= rect
->GetRight();
1037 r
.top
= rect
->GetTop(), r
.bottom
= rect
->GetBottom();
1038 MGL_wmInvalidateWindowRect(GetHandle(), &r
);
1041 MGL_wmInvalidateWindow(GetHandle());
1044 void wxWindowMGL::Update()
1047 MGL_wmUpdateDC(g_winMng
);
1050 void wxWindowMGL::Freeze()
1053 m_refreshAfterThaw
= FALSE
;
1056 void wxWindowMGL::Thaw()
1059 if ( m_refreshAfterThaw
)
1063 void wxWindowMGL::HandlePaint(MGLDevCtx
*dc
)
1067 // Don't paint anything if the window is frozen.
1068 m_refreshAfterThaw
= TRUE
;
1072 #if 0 // FIXME_MGL -- debugging stuff!
1073 dc
->setColorRGB(255,0,255);
1074 dc
->fillRect(-1000,-1000,2000,2000);
1079 dc
->getClipRegion(clip
);
1080 m_updateRegion
= wxRegion(clip
);
1083 if ( m_eraseBackground
!= 0 )
1085 wxWindowDC
dc((wxWindow
*)this);
1086 wxEraseEvent
eventEr(m_windowId
, &dc
);
1087 eventEr
.SetEventObject(this);
1088 GetEventHandler()->ProcessEvent(eventEr
);
1090 m_eraseBackground
= -1;
1092 wxNcPaintEvent
eventNc(GetId());
1093 eventNc
.SetEventObject(this);
1094 GetEventHandler()->ProcessEvent(eventNc
);
1096 wxPaintEvent
eventPt(GetId());
1097 eventPt
.SetEventObject(this);
1098 GetEventHandler()->ProcessEvent(eventPt
);
1100 m_paintMGLDC
= NULL
;
1101 m_updateRegion
.Clear();
1105 // Find the wxWindow at the current mouse position, returning the mouse
1107 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1109 return wxFindWindowAtPoint(pt
= wxGetMousePosition());
1112 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
1114 window_t
*wnd
= MGL_wmGetWindowAtPosition(g_winMng
, pt
.x
, pt
.y
);
1115 return (wxWindow
*)wnd
->userData
;