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
);
132 static ibool
wxWindowMouseHandler(window_t
*wnd
, event_t
*e
)
134 wxWindowMGL
*win
= (wxWindowMGL
*)MGL_wmGetWindowUserData(wnd
);
137 MGL_wmCoordGlobalToLocal(win
->GetHandle(),
138 e
->where_x
, e
->where_y
, &where
.x
, &where
.y
);
140 for (wxWindowMGL
*w
= win
; w
; w
= w
->GetParent())
142 if ( !w
->IsEnabled() )
144 if ( w
->IsTopLevel() )
148 wxEventType type
= wxEVT_NULL
;
150 event
.SetEventObject(win
);
151 event
.SetTimestamp(e
->when
);
154 event
.m_shiftDown
= e
->modifiers
& EVT_SHIFTKEY
;
155 event
.m_controlDown
= e
->modifiers
& EVT_CTRLSTATE
;
156 event
.m_altDown
= e
->modifiers
& EVT_LEFTALT
;
157 event
.m_metaDown
= e
->modifiers
& EVT_RIGHTALT
;
158 event
.m_leftDown
= e
->modifiers
& EVT_LEFTBUT
;
159 event
.m_middleDown
= e
->modifiers
& EVT_MIDDLEBUT
;
160 event
.m_rightDown
= e
->modifiers
& EVT_RIGHTBUT
;
165 if ( e
->message
& EVT_LEFTBMASK
)
166 type
= (e
->message
& EVT_DBLCLICK
) ?
167 wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
;
168 else if ( e
->message
& EVT_MIDDLEBMASK
)
169 type
= (e
->message
& EVT_DBLCLICK
) ?
170 wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
;
171 else if ( e
->message
& EVT_RIGHTBMASK
)
172 type
= (e
->message
& EVT_DBLCLICK
) ?
173 wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
;
177 if ( e
->message
& EVT_LEFTBMASK
)
178 type
= wxEVT_LEFT_UP
;
179 else if ( e
->message
& EVT_MIDDLEBMASK
)
180 type
= wxEVT_MIDDLE_UP
;
181 else if ( e
->message
& EVT_RIGHTBMASK
)
182 type
= wxEVT_RIGHT_UP
;
186 if ( !gs_mouseCapture
)
188 if ( win
!= gs_windowUnderMouse
)
190 if ( gs_windowUnderMouse
)
192 wxMouseEvent
event2(event
);
193 MGL_wmCoordGlobalToLocal(gs_windowUnderMouse
->GetHandle(),
194 e
->where_x
, e
->where_y
,
195 &event2
.m_x
, &event2
.m_y
);
197 event2
.SetEventObject(gs_windowUnderMouse
);
198 event2
.SetEventType(wxEVT_LEAVE_WINDOW
);
199 gs_windowUnderMouse
->GetEventHandler()->ProcessEvent(event2
);
202 wxMouseEvent
event3(event
);
203 event3
.SetEventType(wxEVT_ENTER_WINDOW
);
204 win
->GetEventHandler()->ProcessEvent(event3
);
206 gs_windowUnderMouse
= win
;
209 else // gs_mouseCapture
211 bool inside
= (where
.x
>= 0 &&
213 where
.x
< win
->GetSize().x
&&
214 where
.y
< win
->GetSize().y
);
215 if ( (inside
&& gs_windowUnderMouse
!= win
) ||
216 (!inside
&& gs_windowUnderMouse
== win
) )
218 wxMouseEvent
evt(inside
?
219 wxEVT_ENTER_WINDOW
: wxEVT_LEAVE_WINDOW
);
220 evt
.SetEventObject(win
);
221 win
->GetEventHandler()->ProcessEvent(evt
);
222 gs_windowUnderMouse
= inside
? win
: NULL
;
233 if ( type
== wxEVT_NULL
)
239 event
.SetEventType(type
);
240 return win
->GetEventHandler()->ProcessEvent(event
);
244 static long wxScanToKeyCode(event_t
*event
)
246 #define KEY(mgl,wx) case mgl: key = wx; break;
249 switch ( EVT_scanCode(event
->message
) )
251 KEY (KB_padEnter
, WXK_NUMPAD_ENTER
)
252 KEY (KB_padMinus
, WXK_NUMPAD_SUBTRACT
)
253 KEY (KB_padPlus
, WXK_NUMPAD_ADD
)
254 KEY (KB_padTimes
, WXK_NUMPAD_MULTIPLY
)
255 KEY (KB_padDivide
, WXK_NUMPAD_DIVIDE
)
256 KEY (KB_padLeft
, WXK_NUMPAD_LEFT
)
257 KEY (KB_padRight
, WXK_NUMPAD_RIGHT
)
258 KEY (KB_padUp
, WXK_NUMPAD_UP
)
259 KEY (KB_padDown
, WXK_NUMPAD_DOWN
)
260 KEY (KB_padInsert
, WXK_NUMPAD_INSERT
)
261 KEY (KB_padDelete
, WXK_NUMPAD_DELETE
)
262 KEY (KB_padHome
, WXK_NUMPAD_HOME
)
263 KEY (KB_padEnd
, WXK_NUMPAD_END
)
264 KEY (KB_padPageUp
, WXK_NUMPAD_PAGEUP
)
265 //KEY (KB_padPageUp, WXK_NUMPAD_PRIOR)
266 KEY (KB_padPageDown
, WXK_NUMPAD_PAGEDOWN
)
267 //KEY (KB_padPageDown, WXK_NUMPAD_NEXT)
268 KEY (KB_padCenter
, WXK_NUMPAD_SEPARATOR
) // ?
278 KEY (KB_F10
, WXK_F10
)
279 KEY (KB_F11
, WXK_F11
)
280 KEY (KB_F12
, WXK_F12
)
281 KEY (KB_left
, WXK_LEFT
)
282 KEY (KB_right
, WXK_RIGHT
)
284 KEY (KB_down
, WXK_DOWN
)
285 KEY (KB_insert
, WXK_INSERT
)
286 KEY (KB_delete
, WXK_DELETE
)
287 KEY (KB_home
, WXK_HOME
)
288 KEY (KB_end
, WXK_END
)
289 KEY (KB_pageUp
, WXK_PAGEUP
)
290 KEY (KB_pageDown
, WXK_PAGEDOWN
)
291 KEY (KB_capsLock
, WXK_CAPITAL
)
292 KEY (KB_numLock
, WXK_NUMLOCK
)
293 KEY (KB_scrollLock
, WXK_SCROLL
)
294 KEY (KB_leftShift
, WXK_SHIFT
)
295 KEY (KB_rightShift
, WXK_SHIFT
)
296 KEY (KB_leftCtrl
, WXK_CONTROL
)
297 KEY (KB_rightCtrl
, WXK_CONTROL
)
298 KEY (KB_leftAlt
, WXK_ALT
)
299 KEY (KB_rightAlt
, WXK_ALT
)
300 KEY (KB_leftWindows
, WXK_START
)
301 KEY (KB_rightWindows
, WXK_START
)
302 KEY (KB_menu
, WXK_MENU
)
303 KEY (KB_sysReq
, WXK_SNAPSHOT
)
304 KEY (KB_esc
, WXK_ESCAPE
)
315 KEY (KB_minus
, WXK_SUBTRACT
)
316 KEY (KB_equals
, WXK_ADD
)
317 KEY (KB_backSlash
, '\\')
318 KEY (KB_backspace
, WXK_BACK
)
319 KEY (KB_tab
, WXK_TAB
)
330 KEY (KB_leftSquareBrace
,'[')
331 KEY (KB_rightSquareBrace
,']')
332 KEY (KB_enter
, WXK_RETURN
)
342 KEY (KB_semicolon
, ';')
343 KEY (KB_apostrophe
, '\'')
353 KEY (KB_divide
, WXK_DIVIDE
)
354 KEY (KB_space
, WXK_SPACE
)
358 key
= EVT_asciiCode(event
->message
);
367 static long wxAsciiToKeyCode(event_t
*event
)
369 return (long)EVT_asciiCode(event
->message
);
372 static ibool
wxWindowKeybHandler(window_t
*wnd
, event_t
*e
)
374 wxWindowMGL
*win
= (wxWindowMGL
*)MGL_wmGetWindowUserData(wnd
);
376 if ( !win
->IsEnabled() ) return FALSE
;
379 MGL_wmCoordGlobalToLocal(win
->GetHandle(),
380 e
->where_x
, e
->where_y
, &where
.x
, &where
.y
);
383 event
.SetEventObject(win
);
384 event
.SetTimestamp(e
->when
);
385 event
.m_keyCode
= wxScanToKeyCode(e
);
386 event
.m_scanCode
= 0; // not used by wx at all
389 event
.m_shiftDown
= e
->modifiers
& EVT_SHIFTKEY
;
390 event
.m_controlDown
= e
->modifiers
& EVT_CTRLSTATE
;
391 event
.m_altDown
= e
->modifiers
& EVT_LEFTALT
;
392 event
.m_metaDown
= e
->modifiers
& EVT_RIGHTALT
;
394 if ( e
->what
== EVT_KEYUP
)
396 event
.SetEventType(wxEVT_KEY_UP
);
397 return win
->GetEventHandler()->ProcessEvent(event
);
404 event
.SetEventType(wxEVT_KEY_DOWN
);
407 ret
= win
->GetEventHandler()->ProcessEvent(event
);
411 // Add an easy way to capture screenshots:
412 if ( event
.m_keyCode
== WXK_F1
&&
413 event
.m_shiftDown
&& event
.m_controlDown
)
420 for (wxWindowMGL
*w
= win
; w
; w
= w
->GetParent())
422 int command
= w
->GetAcceleratorTable()->GetCommand(event
);
425 wxCommandEvent
eventc(wxEVT_COMMAND_MENU_SELECTED
, command
);
426 ret
= w
->GetEventHandler()->ProcessEvent(eventc
);
429 if ( w
->IsTopLevel() )
433 #endif // wxUSE_ACCEL
435 /* wxMSW doesn't send char events with Alt pressed */
436 /* Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x
437 will only be sent if it is not in an accelerator table. */
438 event2
.m_keyCode
= wxAsciiToKeyCode(e
);
439 if ( !ret
&& event2
.m_keyCode
!= 0 )
441 event2
.SetEventType(wxEVT_CHAR
);
442 ret
= win
->GetEventHandler()->ProcessEvent(event2
);
449 // ---------------------------------------------------------------------------
451 // ---------------------------------------------------------------------------
453 // in wxUniv this class is abstract because it doesn't have DoPopupMenu()
454 IMPLEMENT_ABSTRACT_CLASS(wxWindowMGL
, wxWindowBase
)
456 BEGIN_EVENT_TABLE(wxWindowMGL
, wxWindowBase
)
459 // ===========================================================================
461 // ===========================================================================
463 // ----------------------------------------------------------------------------
464 // constructors and such
465 // ----------------------------------------------------------------------------
467 void wxWindowMGL::Init()
469 // First of all, make sure window manager is up and running. If it is
470 // not the case, initialize it in default display mode
472 wxTheApp
->SetDisplayMode(wxDisplayModeInfo(wxSize(640, 480), 16));
480 m_isBeingDeleted
= FALSE
;
484 m_eraseBackground
= -1;
488 wxWindowMGL::~wxWindowMGL()
490 m_isBeingDeleted
= TRUE
;
492 if ( gs_mouseCapture
== this )
495 if (gs_activeFrame
== this)
497 gs_activeFrame
= NULL
;
498 // activate next frame in Z-order:
501 wxWindowMGL
*win
= (wxWindowMGL
*)m_wnd
->prev
->userData
;
506 if ( gs_focusedWindow
== this )
509 if ( gs_windowUnderMouse
== this )
510 gs_windowUnderMouse
= NULL
;
512 // VS: destroy children first and _then_ detach *this from its parent.
513 // If we'd do it the other way around, children wouldn't be able
514 // find their parent frame (see above).
518 m_parent
->RemoveChild(this);
521 MGL_wmDestroyWindow(m_wnd
);
524 // real construction (Init() must have been called before!)
525 bool wxWindowMGL::Create(wxWindow
*parent
,
530 const wxString
& name
)
532 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
536 parent
->AddChild(this);
539 x
= pos
.x
, y
= pos
.y
;
541 x
= 0; // FIXME_MGL, something better, see GTK+
543 y
= 0; // FIXME_MGL, something better, see GTK+
544 w
= WidthDefault(size
.x
);
545 h
= HeightDefault(size
.y
);
548 window_t
*wnd_parent
= parent
? parent
->GetHandle() : NULL
;
550 if ( !(style
& wxNO_FULL_REPAINT_ON_RESIZE
) )
552 mgl_style
|= MGL_WM_FULL_REPAINT_ON_RESIZE
;
554 if ( style
& wxSTAY_ON_TOP
)
556 mgl_style
|= MGL_WM_ALWAYS_ON_TOP
;
558 if ( style
& wxPOPUP_WINDOW
)
560 mgl_style
|= MGL_WM_ALWAYS_ON_TOP
;
561 // it is created hidden as other top level windows
566 window_t
*wnd
= MGL_wmCreateWindow(g_winMng
, wnd_parent
, x
, y
, w
, h
);
568 MGL_wmSetWindowFlags(wnd
, mgl_style
);
569 MGL_wmShowWindow(wnd
, m_isShown
);
576 void wxWindowMGL::SetMGLwindow_t(struct window_t
*wnd
)
579 MGL_wmDestroyWindow(m_wnd
);
582 if ( !m_wnd
) return;
584 m_isShown
= m_wnd
->visible
;
586 MGL_wmSetWindowUserData(m_wnd
, (void*) this);
587 MGL_wmSetWindowPainter(m_wnd
, wxWindowPainter
);
588 MGL_wmPushWindowEventHandler(m_wnd
, wxWindowMouseHandler
, EVT_MOUSEEVT
, 0);
589 MGL_wmPushWindowEventHandler(m_wnd
, wxWindowKeybHandler
, EVT_KEYEVT
, 0);
592 MGL_wmSetWindowCursor(m_wnd
, *m_cursor
.GetMGLCursor());
594 MGL_wmSetWindowCursor(m_wnd
, *wxSTANDARD_CURSOR
->GetMGLCursor());
597 // ---------------------------------------------------------------------------
599 // ---------------------------------------------------------------------------
601 void wxWindowMGL::SetFocus()
603 if ( gs_focusedWindow
== this ) return;
605 if ( gs_focusedWindow
)
606 gs_focusedWindow
->KillFocus();
608 gs_focusedWindow
= this;
610 MGL_wmCaptureEvents(GetHandle(), EVT_KEYEVT
, wxMGL_CAPTURE_KEYB
);
613 // caret needs to be informed about focus change
614 wxCaret
*caret
= GetCaret();
617 #endif // wxUSE_CARET
619 wxWindowMGL
*active
= wxGetTopLevelParent(this);
620 if ( !(m_windowStyle
& wxPOPUP_WINDOW
) && active
!= gs_activeFrame
)
622 if ( gs_activeFrame
)
624 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, gs_activeFrame
->GetId());
625 event
.SetEventObject(gs_activeFrame
);
626 gs_activeFrame
->GetEventHandler()->ProcessEvent(event
);
629 gs_activeFrame
= active
;
630 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, gs_activeFrame
->GetId());
631 event
.SetEventObject(gs_activeFrame
);
632 gs_activeFrame
->GetEventHandler()->ProcessEvent(event
);
635 wxFocusEvent
event(wxEVT_SET_FOCUS
, GetId());
636 event
.SetEventObject(this);
637 GetEventHandler()->ProcessEvent(event
);
640 void wxWindowMGL::KillFocus()
642 if ( gs_focusedWindow
!= this ) return;
643 gs_focusedWindow
= NULL
;
645 if ( m_isBeingDeleted
) return;
647 MGL_wmUncaptureEvents(GetHandle(), wxMGL_CAPTURE_KEYB
);
650 // caret needs to be informed about focus change
651 wxCaret
*caret
= GetCaret();
653 caret
->OnKillFocus();
654 #endif // wxUSE_CARET
656 wxFocusEvent
event(wxEVT_KILL_FOCUS
, GetId());
657 event
.SetEventObject(this);
658 GetEventHandler()->ProcessEvent(event
);
661 // ----------------------------------------------------------------------------
662 // this wxWindowBase function is implemented here (in platform-specific file)
663 // because it is static and so couldn't be made virtual
664 // ----------------------------------------------------------------------------
665 wxWindow
*wxWindowBase::FindFocus()
667 return (wxWindow
*)gs_focusedWindow
;
670 bool wxWindowMGL::Show(bool show
)
672 if ( !wxWindowBase::Show(show
) )
675 MGL_wmShowWindow(m_wnd
, show
);
677 if (!show
&& gs_activeFrame
== this)
679 // activate next frame in Z-order:
682 wxWindowMGL
*win
= (wxWindowMGL
*)m_wnd
->prev
->userData
;
690 // Raise the window to the top of the Z order
691 void wxWindowMGL::Raise()
693 MGL_wmRaiseWindow(m_wnd
);
696 // Lower the window to the bottom of the Z order
697 void wxWindowMGL::Lower()
699 MGL_wmLowerWindow(m_wnd
);
702 void wxWindowMGL::CaptureMouse()
704 if ( gs_mouseCapture
)
705 MGL_wmUncaptureEvents(gs_mouseCapture
->m_wnd
, wxMGL_CAPTURE_MOUSE
);
707 gs_mouseCapture
= this;
708 MGL_wmCaptureEvents(m_wnd
, EVT_MOUSEEVT
, wxMGL_CAPTURE_MOUSE
);
711 void wxWindowMGL::ReleaseMouse()
713 wxASSERT_MSG( gs_mouseCapture
== this, wxT("attempt to release mouse, but this window hasn't captured it") )
715 MGL_wmUncaptureEvents(m_wnd
, wxMGL_CAPTURE_MOUSE
);
716 gs_mouseCapture
= NULL
;
719 /* static */ wxWindow
*wxWindowBase::GetCapture()
721 return (wxWindow
*)gs_mouseCapture
;
724 bool wxWindowMGL::SetCursor(const wxCursor
& cursor
)
726 if ( !wxWindowBase::SetCursor(cursor
) )
733 MGL_wmSetWindowCursor(m_wnd
, *m_cursor
.GetMGLCursor());
735 MGL_wmSetWindowCursor(m_wnd
, *wxSTANDARD_CURSOR
->GetMGLCursor());
740 void wxWindowMGL::WarpPointer(int x
, int y
)
742 ClientToScreen(&x
, &y
);
743 EVT_setMousePos(x
, y
);
746 #if WXWIN_COMPATIBILITY
747 // If nothing defined for this, try the parent.
748 // E.g. we may be a button loaded from a resource, with no callback function
750 void wxWindowMGL::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
752 if ( GetEventHandler()->ProcessEvent(event
) )
755 m_parent
->GetEventHandler()->OnCommand(win
, event
);
757 #endif // WXWIN_COMPATIBILITY_2
759 #if WXWIN_COMPATIBILITY
760 wxObject
* wxWindowMGL::GetChild(int number
) const
762 // Return a pointer to the Nth object in the Panel
763 wxNode
*node
= GetChildren().First();
769 wxObject
*obj
= (wxObject
*)node
->Data();
775 #endif // WXWIN_COMPATIBILITY
777 // Set this window to be the child of 'parent'.
778 bool wxWindowMGL::Reparent(wxWindowBase
*parent
)
780 if ( !wxWindowBase::Reparent(parent
) )
783 MGL_wmReparentWindow(m_wnd
, parent
->GetHandle());
789 // ---------------------------------------------------------------------------
791 // ---------------------------------------------------------------------------
793 #if wxUSE_DRAG_AND_DROP
795 void wxWindowMGL::SetDropTarget(wxDropTarget
*pDropTarget
)
797 if ( m_dropTarget
!= 0 ) {
798 m_dropTarget
->Revoke(m_hWnd
);
802 m_dropTarget
= pDropTarget
;
803 if ( m_dropTarget
!= 0 )
804 m_dropTarget
->Register(m_hWnd
);
807 #endif // wxUSE_DRAG_AND_DROP
809 // old style file-manager drag&drop support: we retain the old-style
810 // DragAcceptFiles in parallel with SetDropTarget.
811 void wxWindowMGL::DragAcceptFiles(bool accept
)
814 HWND hWnd
= GetHwnd();
816 ::DragAcceptFiles(hWnd
, (BOOL
)accept
);
820 // ---------------------------------------------------------------------------
821 // moving and resizing
822 // ---------------------------------------------------------------------------
825 void wxWindowMGL::DoGetSize(int *x
, int *y
) const
827 if (x
) *x
= m_wnd
->width
;
828 if (y
) *y
= m_wnd
->height
;
831 void wxWindowMGL::DoGetPosition(int *x
, int *y
) const
833 if (x
) *x
= m_wnd
->x
;
834 if (y
) *y
= m_wnd
->y
;
837 void wxWindowMGL::DoScreenToClient(int *x
, int *y
) const
840 MGL_wmCoordGlobalToLocal(m_wnd
, 0, 0, &ax
, &ay
);
847 void wxWindowMGL::DoClientToScreen(int *x
, int *y
) const
850 MGL_wmCoordLocalToGlobal(m_wnd
, 0, 0, &ax
, &ay
);
857 // Get size *available for subwindows* i.e. excluding menu bar etc.
858 void wxWindowMGL::DoGetClientSize(int *x
, int *y
) const
863 void wxWindowMGL::DoMoveWindow(int x
, int y
, int width
, int height
)
865 MGL_wmSetWindowPosition(GetHandle(), x
, y
, width
, height
);
868 // set the size of the window: if the dimensions are positive, just use them,
869 // but if any of them is equal to -1, it means that we must find the value for
870 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
871 // which case -1 is a valid value for x and y)
873 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
874 // the width/height to best suit our contents, otherwise we reuse the current
876 void wxWindowMGL::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
878 // get the current size and position...
879 int currentX
, currentY
;
880 GetPosition(¤tX
, ¤tY
);
881 int currentW
,currentH
;
882 GetSize(¤tW
, ¤tH
);
884 // ... and don't do anything (avoiding flicker) if it's already ok
885 if ( x
== currentX
&& y
== currentY
&&
886 width
== currentW
&& height
== currentH
)
891 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
893 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
896 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
901 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
903 size
= DoGetBestSize();
908 // just take the current one
915 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
919 size
= DoGetBestSize();
921 //else: already called DoGetBestSize() above
927 // just take the current one
932 if ( m_wnd
->x
!= x
|| m_wnd
->y
!= y
||
933 (int)m_wnd
->width
!= width
|| (int)m_wnd
->height
!= height
)
935 DoMoveWindow(x
, y
, width
, height
);
937 wxSizeEvent
event(wxSize(width
, height
), GetId());
938 event
.SetEventObject(this);
939 GetEventHandler()->ProcessEvent(event
);
943 void wxWindowMGL::DoSetClientSize(int width
, int height
)
945 SetSize(width
, height
);
948 // ---------------------------------------------------------------------------
950 // ---------------------------------------------------------------------------
952 int wxWindowMGL::GetCharHeight() const
956 return dc
.GetCharHeight();
959 int wxWindowMGL::GetCharWidth() const
963 return dc
.GetCharWidth();
966 void wxWindowMGL::GetTextExtent(const wxString
& string
,
968 int *descent
, int *externalLeading
,
969 const wxFont
*theFont
) const
974 dc
.GetTextExtent(string
, x
, y
, descent
, externalLeading
, (wxFont
*)theFont
);
977 #if wxUSE_CARET && WXWIN_COMPATIBILITY
978 // ---------------------------------------------------------------------------
979 // Caret manipulation
980 // ---------------------------------------------------------------------------
982 void wxWindowMGL::CreateCaret(int w
, int h
)
984 SetCaret(new wxCaret(this, w
, h
));
987 void wxWindowMGL::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
989 wxFAIL_MSG("not implemented");
992 void wxWindowMGL::ShowCaret(bool show
)
994 wxCHECK_RET( m_caret
, "no caret to show" );
999 void wxWindowMGL::DestroyCaret()
1004 void wxWindowMGL::SetCaretPos(int x
, int y
)
1006 wxCHECK_RET( m_caret
, "no caret to move" );
1008 m_caret
->Move(x
, y
);
1011 void wxWindowMGL::GetCaretPos(int *x
, int *y
) const
1013 wxCHECK_RET( m_caret
, "no caret to get position of" );
1015 m_caret
->GetPosition(x
, y
);
1017 #endif // wxUSE_CARET
1020 // ---------------------------------------------------------------------------
1022 // ---------------------------------------------------------------------------
1024 void wxWindowMGL::Clear()
1026 wxClientDC
dc((wxWindow
*)this);
1027 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1028 dc
.SetBackground(brush
);
1032 #include "wx/menu.h"
1033 void wxWindowMGL::Refresh(bool eraseBack
, const wxRect
*rect
)
1035 if ( m_eraseBackground
== -1 )
1036 m_eraseBackground
= eraseBack
;
1038 m_eraseBackground
|= eraseBack
;
1043 r
.left
= rect
->GetLeft(), r
.right
= rect
->GetRight();
1044 r
.top
= rect
->GetTop(), r
.bottom
= rect
->GetBottom();
1045 MGL_wmInvalidateWindowRect(GetHandle(), &r
);
1048 MGL_wmInvalidateWindow(GetHandle());
1051 void wxWindowMGL::Update()
1054 MGL_wmUpdateDC(g_winMng
);
1057 void wxWindowMGL::Freeze()
1060 m_refreshAfterThaw
= FALSE
;
1063 void wxWindowMGL::Thaw()
1066 if ( m_refreshAfterThaw
)
1070 void wxWindowMGL::HandlePaint(MGLDevCtx
*dc
)
1074 // Don't paint anything if the window is frozen.
1075 m_refreshAfterThaw
= TRUE
;
1079 #if 0 // FIXME_MGL -- debugging stuff!
1080 dc
->setColorRGB(255,0,255);
1081 dc
->fillRect(-1000,-1000,2000,2000);
1086 dc
->getClipRegion(clip
);
1087 m_updateRegion
= wxRegion(clip
);
1090 if ( m_eraseBackground
!= 0 )
1092 wxWindowDC
dc((wxWindow
*)this);
1093 wxEraseEvent
eventEr(m_windowId
, &dc
);
1094 eventEr
.SetEventObject(this);
1095 GetEventHandler()->ProcessEvent(eventEr
);
1097 m_eraseBackground
= -1;
1099 wxNcPaintEvent
eventNc(GetId());
1100 eventNc
.SetEventObject(this);
1101 GetEventHandler()->ProcessEvent(eventNc
);
1103 wxPaintEvent
eventPt(GetId());
1104 eventPt
.SetEventObject(this);
1105 GetEventHandler()->ProcessEvent(eventPt
);
1107 m_paintMGLDC
= NULL
;
1108 m_updateRegion
.Clear();
1112 // Find the wxWindow at the current mouse position, returning the mouse
1114 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1116 return wxFindWindowAtPoint(pt
= wxGetMousePosition());
1119 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
1121 window_t
*wnd
= MGL_wmGetWindowAtPosition(g_winMng
, pt
.x
, pt
.y
);
1122 return (wxWindow
*)wnd
->userData
;