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 MGLAPI
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 MGLAPI
wxWindowMouseHandler(window_t
*wnd
, event_t
*e
)
134 wxWindowMGL
*win
= (wxWindowMGL
*)MGL_wmGetWindowUserData(wnd
);
135 wxPoint
orig(win
->GetClientAreaOrigin());
138 MGL_wmCoordGlobalToLocal(win
->GetHandle(),
139 e
->where_x
, e
->where_y
, &where
.x
, &where
.y
);
141 for (wxWindowMGL
*w
= win
; w
; w
= w
->GetParent())
143 if ( !w
->IsEnabled() )
145 if ( w
->IsTopLevel() )
149 wxEventType type
= wxEVT_NULL
;
151 event
.SetEventObject(win
);
152 event
.SetTimestamp(e
->when
);
153 event
.m_x
= where
.x
- orig
.x
;
154 event
.m_y
= where
.y
- orig
.y
;
155 event
.m_shiftDown
= e
->modifiers
& EVT_SHIFTKEY
;
156 event
.m_controlDown
= e
->modifiers
& EVT_CTRLSTATE
;
157 event
.m_altDown
= e
->modifiers
& EVT_LEFTALT
;
158 event
.m_metaDown
= e
->modifiers
& EVT_RIGHTALT
;
159 event
.m_leftDown
= e
->modifiers
& EVT_LEFTBUT
;
160 event
.m_middleDown
= e
->modifiers
& EVT_MIDDLEBUT
;
161 event
.m_rightDown
= e
->modifiers
& EVT_RIGHTBUT
;
166 if ( e
->message
& EVT_LEFTBMASK
)
167 type
= (e
->message
& EVT_DBLCLICK
) ?
168 wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
;
169 else if ( e
->message
& EVT_MIDDLEBMASK
)
170 type
= (e
->message
& EVT_DBLCLICK
) ?
171 wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
;
172 else if ( e
->message
& EVT_RIGHTBMASK
)
173 type
= (e
->message
& EVT_DBLCLICK
) ?
174 wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
;
178 if ( e
->message
& EVT_LEFTBMASK
)
179 type
= wxEVT_LEFT_UP
;
180 else if ( e
->message
& EVT_MIDDLEBMASK
)
181 type
= wxEVT_MIDDLE_UP
;
182 else if ( e
->message
& EVT_RIGHTBMASK
)
183 type
= wxEVT_RIGHT_UP
;
187 if ( !gs_mouseCapture
)
189 if ( win
!= gs_windowUnderMouse
)
191 if ( gs_windowUnderMouse
)
193 wxMouseEvent
event2(event
);
194 MGL_wmCoordGlobalToLocal(gs_windowUnderMouse
->GetHandle(),
195 e
->where_x
, e
->where_y
,
196 &event2
.m_x
, &event2
.m_y
);
198 wxPoint
orig(gs_windowUnderMouse
->GetClientAreaOrigin());
199 event2
.m_x
-= orig
.x
;
200 event2
.m_y
-= orig
.y
;
202 event2
.SetEventObject(gs_windowUnderMouse
);
203 event2
.SetEventType(wxEVT_LEAVE_WINDOW
);
204 gs_windowUnderMouse
->GetEventHandler()->ProcessEvent(event2
);
207 wxMouseEvent
event3(event
);
208 event3
.SetEventType(wxEVT_ENTER_WINDOW
);
209 win
->GetEventHandler()->ProcessEvent(event3
);
211 gs_windowUnderMouse
= win
;
214 else // gs_mouseCapture
216 bool inside
= (where
.x
>= 0 &&
218 where
.x
< win
->GetSize().x
&&
219 where
.y
< win
->GetSize().y
);
220 if ( (inside
&& gs_windowUnderMouse
!= win
) ||
221 (!inside
&& gs_windowUnderMouse
== win
) )
223 wxMouseEvent
evt(inside
?
224 wxEVT_ENTER_WINDOW
: wxEVT_LEAVE_WINDOW
);
225 evt
.SetEventObject(win
);
226 win
->GetEventHandler()->ProcessEvent(evt
);
227 gs_windowUnderMouse
= inside
? win
: NULL
;
238 if ( type
== wxEVT_NULL
)
244 event
.SetEventType(type
);
245 return win
->GetEventHandler()->ProcessEvent(event
);
249 static long wxScanToKeyCode(event_t
*event
)
251 #define KEY(mgl,wx) case mgl: key = wx; break;
254 switch ( EVT_scanCode(event
->message
) )
256 KEY (KB_padEnter
, WXK_NUMPAD_ENTER
)
257 KEY (KB_padMinus
, WXK_NUMPAD_SUBTRACT
)
258 KEY (KB_padPlus
, WXK_NUMPAD_ADD
)
259 KEY (KB_padTimes
, WXK_NUMPAD_MULTIPLY
)
260 KEY (KB_padDivide
, WXK_NUMPAD_DIVIDE
)
261 KEY (KB_padLeft
, WXK_NUMPAD_LEFT
)
262 KEY (KB_padRight
, WXK_NUMPAD_RIGHT
)
263 KEY (KB_padUp
, WXK_NUMPAD_UP
)
264 KEY (KB_padDown
, WXK_NUMPAD_DOWN
)
265 KEY (KB_padInsert
, WXK_NUMPAD_INSERT
)
266 KEY (KB_padDelete
, WXK_NUMPAD_DELETE
)
267 KEY (KB_padHome
, WXK_NUMPAD_HOME
)
268 KEY (KB_padEnd
, WXK_NUMPAD_END
)
269 KEY (KB_padPageUp
, WXK_NUMPAD_PAGEUP
)
270 //KEY (KB_padPageUp, WXK_NUMPAD_PRIOR)
271 KEY (KB_padPageDown
, WXK_NUMPAD_PAGEDOWN
)
272 //KEY (KB_padPageDown, WXK_NUMPAD_NEXT)
273 KEY (KB_padCenter
, WXK_NUMPAD_SEPARATOR
) // ?
283 KEY (KB_F10
, WXK_F10
)
284 KEY (KB_F11
, WXK_F11
)
285 KEY (KB_F12
, WXK_F12
)
286 KEY (KB_left
, WXK_LEFT
)
287 KEY (KB_right
, WXK_RIGHT
)
289 KEY (KB_down
, WXK_DOWN
)
290 KEY (KB_insert
, WXK_INSERT
)
291 KEY (KB_delete
, WXK_DELETE
)
292 KEY (KB_home
, WXK_HOME
)
293 KEY (KB_end
, WXK_END
)
294 KEY (KB_pageUp
, WXK_PAGEUP
)
295 KEY (KB_pageDown
, WXK_PAGEDOWN
)
296 KEY (KB_capsLock
, WXK_CAPITAL
)
297 KEY (KB_numLock
, WXK_NUMLOCK
)
298 KEY (KB_scrollLock
, WXK_SCROLL
)
299 KEY (KB_leftShift
, WXK_SHIFT
)
300 KEY (KB_rightShift
, WXK_SHIFT
)
301 KEY (KB_leftCtrl
, WXK_CONTROL
)
302 KEY (KB_rightCtrl
, WXK_CONTROL
)
303 KEY (KB_leftAlt
, WXK_ALT
)
304 KEY (KB_rightAlt
, WXK_ALT
)
305 KEY (KB_leftWindows
, WXK_START
)
306 KEY (KB_rightWindows
, WXK_START
)
307 KEY (KB_menu
, WXK_MENU
)
308 KEY (KB_sysReq
, WXK_SNAPSHOT
)
309 KEY (KB_esc
, WXK_ESCAPE
)
320 KEY (KB_minus
, WXK_SUBTRACT
)
321 KEY (KB_equals
, WXK_ADD
)
322 KEY (KB_backSlash
, '\\')
323 KEY (KB_backspace
, WXK_BACK
)
324 KEY (KB_tab
, WXK_TAB
)
335 KEY (KB_leftSquareBrace
,'[')
336 KEY (KB_rightSquareBrace
,']')
337 KEY (KB_enter
, WXK_RETURN
)
347 KEY (KB_semicolon
, ';')
348 KEY (KB_apostrophe
, '\'')
358 KEY (KB_divide
, WXK_DIVIDE
)
359 KEY (KB_space
, WXK_SPACE
)
363 key
= EVT_asciiCode(event
->message
);
372 static long wxAsciiToKeyCode(event_t
*event
)
374 return (long)EVT_asciiCode(event
->message
);
377 static ibool MGLAPI
wxWindowKeybHandler(window_t
*wnd
, event_t
*e
)
379 wxWindowMGL
*win
= (wxWindowMGL
*)MGL_wmGetWindowUserData(wnd
);
381 if ( !win
->IsEnabled() ) return FALSE
;
384 MGL_wmCoordGlobalToLocal(win
->GetHandle(),
385 e
->where_x
, e
->where_y
, &where
.x
, &where
.y
);
388 event
.SetEventObject(win
);
389 event
.SetTimestamp(e
->when
);
390 event
.m_keyCode
= wxScanToKeyCode(e
);
391 event
.m_scanCode
= 0; // not used by wx at all
394 event
.m_shiftDown
= e
->modifiers
& EVT_SHIFTKEY
;
395 event
.m_controlDown
= e
->modifiers
& EVT_CTRLSTATE
;
396 event
.m_altDown
= e
->modifiers
& EVT_LEFTALT
;
397 event
.m_metaDown
= e
->modifiers
& EVT_RIGHTALT
;
399 if ( e
->what
== EVT_KEYUP
)
401 event
.SetEventType(wxEVT_KEY_UP
);
402 return win
->GetEventHandler()->ProcessEvent(event
);
409 event
.SetEventType(wxEVT_KEY_DOWN
);
412 ret
= win
->GetEventHandler()->ProcessEvent(event
);
416 // Add an easy way to capture screenshots:
417 if ( event
.m_keyCode
== WXK_F1
&&
418 event
.m_shiftDown
&& event
.m_controlDown
)
425 for (wxWindowMGL
*w
= win
; w
; w
= w
->GetParent())
427 int command
= w
->GetAcceleratorTable()->GetCommand(event
);
430 wxCommandEvent
eventc(wxEVT_COMMAND_MENU_SELECTED
, command
);
431 ret
= w
->GetEventHandler()->ProcessEvent(eventc
);
434 if ( w
->IsTopLevel() )
438 #endif // wxUSE_ACCEL
440 /* wxMSW doesn't send char events with Alt pressed */
441 /* Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x
442 will only be sent if it is not in an accelerator table. */
443 event2
.m_keyCode
= wxAsciiToKeyCode(e
);
444 if ( !ret
&& event2
.m_keyCode
!= 0 )
446 event2
.SetEventType(wxEVT_CHAR
);
447 ret
= win
->GetEventHandler()->ProcessEvent(event2
);
454 // ---------------------------------------------------------------------------
456 // ---------------------------------------------------------------------------
458 // in wxUniv this class is abstract because it doesn't have DoPopupMenu()
459 IMPLEMENT_ABSTRACT_CLASS(wxWindowMGL
, wxWindowBase
)
461 BEGIN_EVENT_TABLE(wxWindowMGL
, wxWindowBase
)
464 // ===========================================================================
466 // ===========================================================================
468 // ----------------------------------------------------------------------------
469 // constructors and such
470 // ----------------------------------------------------------------------------
472 extern wxDisplayModeInfo
wxGetDefaultDisplayMode();
474 void wxWindowMGL::Init()
476 // First of all, make sure window manager is up and running. If it is
477 // not the case, initialize it in default display mode
480 if ( !wxTheApp
->SetDisplayMode(wxGetDefaultDisplayMode()) )
481 wxFatalError(_("Cannot initialize display."));
490 m_isBeingDeleted
= FALSE
;
494 m_eraseBackground
= -1;
498 wxWindowMGL::~wxWindowMGL()
500 m_isBeingDeleted
= TRUE
;
502 if ( gs_mouseCapture
== this )
505 if (gs_activeFrame
== this)
507 gs_activeFrame
= NULL
;
508 // activate next frame in Z-order:
511 wxWindowMGL
*win
= (wxWindowMGL
*)m_wnd
->prev
->userData
;
516 if ( gs_focusedWindow
== this )
519 if ( gs_windowUnderMouse
== this )
520 gs_windowUnderMouse
= NULL
;
522 // VS: destroy children first and _then_ detach *this from its parent.
523 // If we'd do it the other way around, children wouldn't be able
524 // find their parent frame (see above).
528 m_parent
->RemoveChild(this);
531 MGL_wmDestroyWindow(m_wnd
);
534 // real construction (Init() must have been called before!)
535 bool wxWindowMGL::Create(wxWindow
*parent
,
540 const wxString
& name
)
542 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
546 parent
->AddChild(this);
549 x
= pos
.x
, y
= pos
.y
;
551 x
= 0; // FIXME_MGL, something better, see GTK+
553 y
= 0; // FIXME_MGL, something better, see GTK+
554 w
= WidthDefault(size
.x
);
555 h
= HeightDefault(size
.y
);
558 window_t
*wnd_parent
= parent
? parent
->GetHandle() : NULL
;
560 if ( !(style
& wxNO_FULL_REPAINT_ON_RESIZE
) )
562 mgl_style
|= MGL_WM_FULL_REPAINT_ON_RESIZE
;
564 if ( style
& wxSTAY_ON_TOP
)
566 mgl_style
|= MGL_WM_ALWAYS_ON_TOP
;
568 if ( style
& wxPOPUP_WINDOW
)
570 mgl_style
|= MGL_WM_ALWAYS_ON_TOP
;
571 // it is created hidden as other top level windows
576 window_t
*wnd
= MGL_wmCreateWindow(g_winMng
, wnd_parent
, x
, y
, w
, h
);
578 MGL_wmSetWindowFlags(wnd
, mgl_style
);
579 MGL_wmShowWindow(wnd
, m_isShown
);
586 void wxWindowMGL::SetMGLwindow_t(struct window_t
*wnd
)
589 MGL_wmDestroyWindow(m_wnd
);
592 if ( !m_wnd
) return;
594 m_isShown
= m_wnd
->visible
;
596 MGL_wmSetWindowUserData(m_wnd
, (void*) this);
597 MGL_wmSetWindowPainter(m_wnd
, wxWindowPainter
);
598 MGL_wmPushWindowEventHandler(m_wnd
, wxWindowMouseHandler
, EVT_MOUSEEVT
, 0);
599 MGL_wmPushWindowEventHandler(m_wnd
, wxWindowKeybHandler
, EVT_KEYEVT
, 0);
602 MGL_wmSetWindowCursor(m_wnd
, *m_cursor
.GetMGLCursor());
604 MGL_wmSetWindowCursor(m_wnd
, *wxSTANDARD_CURSOR
->GetMGLCursor());
607 // ---------------------------------------------------------------------------
609 // ---------------------------------------------------------------------------
611 void wxWindowMGL::SetFocus()
613 if ( gs_focusedWindow
== this ) return;
615 if ( gs_focusedWindow
)
616 gs_focusedWindow
->KillFocus();
618 gs_focusedWindow
= this;
620 MGL_wmCaptureEvents(GetHandle(), EVT_KEYEVT
, wxMGL_CAPTURE_KEYB
);
623 // caret needs to be informed about focus change
624 wxCaret
*caret
= GetCaret();
627 #endif // wxUSE_CARET
629 wxWindowMGL
*active
= wxGetTopLevelParent(this);
630 if ( !(m_windowStyle
& wxPOPUP_WINDOW
) && active
!= gs_activeFrame
)
632 if ( gs_activeFrame
)
634 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, gs_activeFrame
->GetId());
635 event
.SetEventObject(gs_activeFrame
);
636 gs_activeFrame
->GetEventHandler()->ProcessEvent(event
);
639 gs_activeFrame
= active
;
640 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, gs_activeFrame
->GetId());
641 event
.SetEventObject(gs_activeFrame
);
642 gs_activeFrame
->GetEventHandler()->ProcessEvent(event
);
645 wxFocusEvent
event(wxEVT_SET_FOCUS
, GetId());
646 event
.SetEventObject(this);
647 GetEventHandler()->ProcessEvent(event
);
650 void wxWindowMGL::KillFocus()
652 if ( gs_focusedWindow
!= this ) return;
653 gs_focusedWindow
= NULL
;
655 if ( m_isBeingDeleted
) return;
657 MGL_wmUncaptureEvents(GetHandle(), wxMGL_CAPTURE_KEYB
);
660 // caret needs to be informed about focus change
661 wxCaret
*caret
= GetCaret();
663 caret
->OnKillFocus();
664 #endif // wxUSE_CARET
666 wxFocusEvent
event(wxEVT_KILL_FOCUS
, GetId());
667 event
.SetEventObject(this);
668 GetEventHandler()->ProcessEvent(event
);
671 // ----------------------------------------------------------------------------
672 // this wxWindowBase function is implemented here (in platform-specific file)
673 // because it is static and so couldn't be made virtual
674 // ----------------------------------------------------------------------------
675 wxWindow
*wxWindowBase::FindFocus()
677 return (wxWindow
*)gs_focusedWindow
;
680 bool wxWindowMGL::Show(bool show
)
682 if ( !wxWindowBase::Show(show
) )
685 MGL_wmShowWindow(m_wnd
, show
);
687 if (!show
&& gs_activeFrame
== this)
689 // activate next frame in Z-order:
692 wxWindowMGL
*win
= (wxWindowMGL
*)m_wnd
->prev
->userData
;
700 // Raise the window to the top of the Z order
701 void wxWindowMGL::Raise()
703 MGL_wmRaiseWindow(m_wnd
);
706 // Lower the window to the bottom of the Z order
707 void wxWindowMGL::Lower()
709 MGL_wmLowerWindow(m_wnd
);
712 void wxWindowMGL::DoCaptureMouse()
714 if ( gs_mouseCapture
)
715 MGL_wmUncaptureEvents(gs_mouseCapture
->m_wnd
, wxMGL_CAPTURE_MOUSE
);
717 gs_mouseCapture
= this;
718 MGL_wmCaptureEvents(m_wnd
, EVT_MOUSEEVT
, wxMGL_CAPTURE_MOUSE
);
721 void wxWindowMGL::DoReleaseMouse()
723 wxASSERT_MSG( gs_mouseCapture
== this, wxT("attempt to release mouse, but this window hasn't captured it") )
725 MGL_wmUncaptureEvents(m_wnd
, wxMGL_CAPTURE_MOUSE
);
726 gs_mouseCapture
= NULL
;
729 /* static */ wxWindow
*wxWindowBase::GetCapture()
731 return (wxWindow
*)gs_mouseCapture
;
734 bool wxWindowMGL::SetCursor(const wxCursor
& cursor
)
736 if ( !wxWindowBase::SetCursor(cursor
) )
743 MGL_wmSetWindowCursor(m_wnd
, *m_cursor
.GetMGLCursor());
745 MGL_wmSetWindowCursor(m_wnd
, *wxSTANDARD_CURSOR
->GetMGLCursor());
750 void wxWindowMGL::WarpPointer(int x
, int y
)
752 ClientToScreen(&x
, &y
);
753 EVT_setMousePos(x
, y
);
756 #if WXWIN_COMPATIBILITY
757 // If nothing defined for this, try the parent.
758 // E.g. we may be a button loaded from a resource, with no callback function
760 void wxWindowMGL::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
762 if ( GetEventHandler()->ProcessEvent(event
) )
765 m_parent
->GetEventHandler()->OnCommand(win
, event
);
767 #endif // WXWIN_COMPATIBILITY_2
769 #if WXWIN_COMPATIBILITY
770 wxObject
* wxWindowMGL::GetChild(int number
) const
772 // Return a pointer to the Nth object in the Panel
773 wxNode
*node
= GetChildren().First();
779 wxObject
*obj
= (wxObject
*)node
->Data();
785 #endif // WXWIN_COMPATIBILITY
787 // Set this window to be the child of 'parent'.
788 bool wxWindowMGL::Reparent(wxWindowBase
*parent
)
790 if ( !wxWindowBase::Reparent(parent
) )
793 MGL_wmReparentWindow(m_wnd
, parent
->GetHandle());
799 // ---------------------------------------------------------------------------
801 // ---------------------------------------------------------------------------
803 #if wxUSE_DRAG_AND_DROP
805 void wxWindowMGL::SetDropTarget(wxDropTarget
*pDropTarget
)
807 if ( m_dropTarget
!= 0 ) {
808 m_dropTarget
->Revoke(m_hWnd
);
812 m_dropTarget
= pDropTarget
;
813 if ( m_dropTarget
!= 0 )
814 m_dropTarget
->Register(m_hWnd
);
817 #endif // wxUSE_DRAG_AND_DROP
819 // old style file-manager drag&drop support: we retain the old-style
820 // DragAcceptFiles in parallel with SetDropTarget.
821 void wxWindowMGL::DragAcceptFiles(bool accept
)
824 HWND hWnd
= GetHwnd();
826 ::DragAcceptFiles(hWnd
, (BOOL
)accept
);
830 // ---------------------------------------------------------------------------
831 // moving and resizing
832 // ---------------------------------------------------------------------------
835 void wxWindowMGL::DoGetSize(int *x
, int *y
) const
837 if (x
) *x
= m_wnd
->width
;
838 if (y
) *y
= m_wnd
->height
;
841 void wxWindowMGL::DoGetPosition(int *x
, int *y
) const
843 if (x
) *x
= m_wnd
->x
;
844 if (y
) *y
= m_wnd
->y
;
847 void wxWindowMGL::DoScreenToClient(int *x
, int *y
) const
850 MGL_wmCoordGlobalToLocal(m_wnd
, 0, 0, &ax
, &ay
);
857 void wxWindowMGL::DoClientToScreen(int *x
, int *y
) const
860 MGL_wmCoordLocalToGlobal(m_wnd
, 0, 0, &ax
, &ay
);
867 // Get size *available for subwindows* i.e. excluding menu bar etc.
868 void wxWindowMGL::DoGetClientSize(int *x
, int *y
) const
873 void wxWindowMGL::DoMoveWindow(int x
, int y
, int width
, int height
)
875 MGL_wmSetWindowPosition(GetHandle(), x
, y
, width
, height
);
878 // set the size of the window: if the dimensions are positive, just use them,
879 // but if any of them is equal to -1, it means that we must find the value for
880 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
881 // which case -1 is a valid value for x and y)
883 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
884 // the width/height to best suit our contents, otherwise we reuse the current
886 void wxWindowMGL::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
888 // get the current size and position...
889 int currentX
, currentY
;
890 GetPosition(¤tX
, ¤tY
);
891 int currentW
,currentH
;
892 GetSize(¤tW
, ¤tH
);
894 // ... and don't do anything (avoiding flicker) if it's already ok
895 if ( x
== currentX
&& y
== currentY
&&
896 width
== currentW
&& height
== currentH
)
901 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
903 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
906 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
911 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
913 size
= DoGetBestSize();
918 // just take the current one
925 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
929 size
= DoGetBestSize();
931 //else: already called DoGetBestSize() above
937 // just take the current one
942 if ( m_wnd
->x
!= x
|| m_wnd
->y
!= y
||
943 (int)m_wnd
->width
!= width
|| (int)m_wnd
->height
!= height
)
945 DoMoveWindow(x
, y
, width
, height
);
947 wxSizeEvent
event(wxSize(width
, height
), GetId());
948 event
.SetEventObject(this);
949 GetEventHandler()->ProcessEvent(event
);
953 void wxWindowMGL::DoSetClientSize(int width
, int height
)
955 SetSize(width
, height
);
958 // ---------------------------------------------------------------------------
960 // ---------------------------------------------------------------------------
962 int wxWindowMGL::GetCharHeight() const
966 return dc
.GetCharHeight();
969 int wxWindowMGL::GetCharWidth() const
973 return dc
.GetCharWidth();
976 void wxWindowMGL::GetTextExtent(const wxString
& string
,
978 int *descent
, int *externalLeading
,
979 const wxFont
*theFont
) const
984 dc
.GetTextExtent(string
, x
, y
, descent
, externalLeading
, (wxFont
*)theFont
);
987 #if wxUSE_CARET && WXWIN_COMPATIBILITY
988 // ---------------------------------------------------------------------------
989 // Caret manipulation
990 // ---------------------------------------------------------------------------
992 void wxWindowMGL::CreateCaret(int w
, int h
)
994 SetCaret(new wxCaret(this, w
, h
));
997 void wxWindowMGL::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
999 wxFAIL_MSG("not implemented");
1002 void wxWindowMGL::ShowCaret(bool show
)
1004 wxCHECK_RET( m_caret
, "no caret to show" );
1006 m_caret
->Show(show
);
1009 void wxWindowMGL::DestroyCaret()
1014 void wxWindowMGL::SetCaretPos(int x
, int y
)
1016 wxCHECK_RET( m_caret
, "no caret to move" );
1018 m_caret
->Move(x
, y
);
1021 void wxWindowMGL::GetCaretPos(int *x
, int *y
) const
1023 wxCHECK_RET( m_caret
, "no caret to get position of" );
1025 m_caret
->GetPosition(x
, y
);
1027 #endif // wxUSE_CARET
1030 // ---------------------------------------------------------------------------
1032 // ---------------------------------------------------------------------------
1034 void wxWindowMGL::Clear()
1036 wxClientDC
dc((wxWindow
*)this);
1037 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1038 dc
.SetBackground(brush
);
1042 #include "wx/menu.h"
1043 void wxWindowMGL::Refresh(bool eraseBack
, const wxRect
*rect
)
1045 if ( m_eraseBackground
== -1 )
1046 m_eraseBackground
= eraseBack
;
1048 m_eraseBackground
|= eraseBack
;
1053 r
.left
= rect
->GetLeft(), r
.right
= rect
->GetRight();
1054 r
.top
= rect
->GetTop(), r
.bottom
= rect
->GetBottom();
1055 MGL_wmInvalidateWindowRect(GetHandle(), &r
);
1058 MGL_wmInvalidateWindow(GetHandle());
1061 void wxWindowMGL::Update()
1064 MGL_wmUpdateDC(g_winMng
);
1067 void wxWindowMGL::Freeze()
1070 m_refreshAfterThaw
= FALSE
;
1073 void wxWindowMGL::Thaw()
1076 if ( m_refreshAfterThaw
)
1080 void wxWindowMGL::HandlePaint(MGLDevCtx
*dc
)
1084 // Don't paint anything if the window is frozen.
1085 m_refreshAfterThaw
= TRUE
;
1089 #if 0 // FIXME_MGL -- debugging stuff!
1090 dc
->setColorRGB(255,0,255);
1091 dc
->fillRect(-1000,-1000,2000,2000);
1096 dc
->getClipRegion(clip
);
1097 m_updateRegion
= wxRegion(clip
);
1100 if ( m_eraseBackground
!= 0 )
1102 wxWindowDC
dc((wxWindow
*)this);
1103 wxEraseEvent
eventEr(m_windowId
, &dc
);
1104 eventEr
.SetEventObject(this);
1105 GetEventHandler()->ProcessEvent(eventEr
);
1107 m_eraseBackground
= -1;
1109 wxNcPaintEvent
eventNc(GetId());
1110 eventNc
.SetEventObject(this);
1111 GetEventHandler()->ProcessEvent(eventNc
);
1113 wxPaintEvent
eventPt(GetId());
1114 eventPt
.SetEventObject(this);
1115 GetEventHandler()->ProcessEvent(eventPt
);
1117 m_paintMGLDC
= NULL
;
1118 m_updateRegion
.Clear();
1122 // Find the wxWindow at the current mouse position, returning the mouse
1124 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1126 return wxFindWindowAtPoint(pt
= wxGetMousePosition());
1129 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
1131 window_t
*wnd
= MGL_wmGetWindowAtPosition(g_winMng
, pt
.x
, pt
.y
);
1132 return (wxWindow
*)wnd
->userData
;