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
*g_focusedWindow
= NULL
;
68 // the window that is currently under mouse cursor:
69 static wxWindowMGL
*g_windowUnderMouse
= NULL
;
71 // ---------------------------------------------------------------------------
73 // ---------------------------------------------------------------------------
75 // Custom identifiers used to distinguish between various event handlers
76 // and capture handlers passed to MGL_wm
79 wxMGL_CAPTURE_MOUSE
= 1,
80 wxMGL_CAPTURE_KEYB
= 2
84 // ---------------------------------------------------------------------------
86 // ---------------------------------------------------------------------------
88 // wxCreateMGL_WM creates MGL display DC and associates it with winmng_t
89 // structure. Dimensions and depth of the DC are fetched from wxSystemOptions
91 // This function is *not* called from wxApp's initialization but rather at
92 // the time when WM is needed, i.e. when first wxWindow is created. This
93 // has two important effects:
94 // a) it is possible to write windowless wxMGL apps
95 // b) the app has plenty of time in wxApp::OnInit to feed wxSystemOptions
96 // with desired settings
98 // FIXME_MGL -- move to app.cpp??
99 static void wxDesktopPainter(window_t
*wnd
, MGLDC
*dc
)
101 // FIXME_MGL - for now...
102 MGL_setColorRGB(0x63, 0x63, 0x96);
103 MGL_fillRectCoord(0, 0, wnd
->width
, wnd
->height
);
107 bool wxCreateMGL_WM()
110 int width
= 640, height
= 480, depth
= 16;
111 int refresh
= MGL_DEFAULT_REFRESH
;
113 #if wxUSE_SYSTEM_OPTIONS
114 // FIXME_MGL -- so what is The Proper Way?
115 if ( wxSystemOptions::HasOption(wxT("mgl.screen-width") )
116 width
= wxSystemOptions::GetOptionInt(wxT("mgl.screen-width"));
117 if ( wxSystemOptions::HasOption(wxT("mgl.screen-height") )
118 height
= wxSystemOptions::GetOptionInt(wxT("mgl.screen-height"));
119 if ( wxSystemOptions::HasOption(wxT("mgl.screen-depth") )
120 depth
= wxSystemOptions::GetOptionInt(wxT("mgl.screen-depth"));
121 if ( wxSystemOptions::HasOption(wxT("mgl.screen-refresh") )
122 refresh
= wxSystemOptions::GetOptionInt(wxT("mgl.screen-refresh"));
125 mode
= MGL_findMode(width
, height
, depth
);
128 wxLogWarning(_("Mode %ix%i-%i not available, falling back to default mode."), width
, height
, depth
);
129 mode
= 0; // always available
131 g_displayDC
= new MGLDisplayDC(mode
, 1, refresh
);
132 if ( !g_displayDC
->isValid() )
139 g_winMng
= MGL_wmCreate(g_displayDC
->getDC());
143 MGL_wmSetWindowPainter(MGL_wmGetRootWindow(g_winMng
), wxDesktopPainter
);
148 void wxDestroyMGL_WM()
152 MGL_wmDestroy(g_winMng
);
162 // ---------------------------------------------------------------------------
164 // ---------------------------------------------------------------------------
166 static void wxWindowPainter(window_t
*wnd
, MGLDC
*dc
)
168 wxWindowMGL
*w
= (wxWindow
*) wnd
->userData
;
169 if (w
&& !(w
->GetStyle() & wxTRANSPARENT_WINDOW
))
172 w
->HandlePaint(&ctx
);
174 // FIXME_MGL -- root window should be a regular window so that
175 // enter/leave and activate/deactivate events work correctly
178 static ibool
wxWindowMouseHandler(window_t
*wnd
, event_t
*e
)
180 wxWindowMGL
*win
= (wxWindowMGL
*)MGL_wmGetWindowUserData(wnd
);
181 wxPoint where
= win
->ScreenToClient(wxPoint(e
->where_x
, e
->where_y
));
183 wxEventType type
= wxEVT_NULL
;
185 event
.SetEventObject(win
);
186 event
.SetTimestamp(e
->when
);
189 event
.m_shiftDown
= e
->modifiers
& EVT_SHIFTKEY
;
190 event
.m_controlDown
= e
->modifiers
& EVT_CTRLSTATE
;
191 event
.m_altDown
= e
->modifiers
& EVT_LEFTALT
;
192 event
.m_metaDown
= e
->modifiers
& EVT_RIGHTALT
;
193 event
.m_leftDown
= e
->modifiers
& EVT_LEFTBUT
;
194 event
.m_middleDown
= e
->modifiers
& EVT_MIDDLEBUT
;
195 event
.m_rightDown
= e
->modifiers
& EVT_RIGHTBUT
;
200 if ( e
->message
& EVT_LEFTBMASK
)
201 type
= (e
->message
& EVT_DBLCLICK
) ?
202 wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
;
203 else if ( e
->message
& EVT_MIDDLEBMASK
)
204 type
= (e
->message
& EVT_DBLCLICK
) ?
205 wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
;
206 else if ( e
->message
& EVT_RIGHTBMASK
)
207 type
= (e
->message
& EVT_DBLCLICK
) ?
208 wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
;
212 if ( e
->message
& EVT_LEFTBMASK
)
213 type
= wxEVT_LEFT_UP
;
214 else if ( e
->message
& EVT_MIDDLEBMASK
)
215 type
= wxEVT_MIDDLE_UP
;
216 else if ( e
->message
& EVT_RIGHTBMASK
)
217 type
= wxEVT_RIGHT_UP
;
221 if ( win
!= g_windowUnderMouse
)
223 if ( g_windowUnderMouse
)
225 wxMouseEvent
event2(event
);
226 wxPoint where2
= g_windowUnderMouse
->ScreenToClient(
227 wxPoint(e
->where_x
, e
->where_y
));
228 event2
.m_x
= where2
.x
;
229 event2
.m_y
= where2
.y
;
230 event2
.SetEventObject(g_windowUnderMouse
);
231 event2
.SetEventType(wxEVT_LEAVE_WINDOW
);
232 g_windowUnderMouse
->GetEventHandler()->ProcessEvent(event2
);
235 wxMouseEvent
event3(event
);
236 event3
.SetEventType(wxEVT_ENTER_WINDOW
);
237 win
->GetEventHandler()->ProcessEvent(event3
);
239 g_windowUnderMouse
= win
;
249 if ( type
== wxEVT_NULL
)
255 event
.SetEventType(type
);
256 return win
->GetEventHandler()->ProcessEvent(event
);
260 static long wxScanToKeyCode(event_t
*event
)
262 #define KEY(mgl,wx) case mgl: key = wx; break;
265 switch ( EVT_scanCode(event
->message
) )
267 KEY (KB_padEnter
, WXK_NUMPAD_ENTER
)
268 KEY (KB_padMinus
, WXK_NUMPAD_SUBTRACT
)
269 KEY (KB_padPlus
, WXK_NUMPAD_ADD
)
270 KEY (KB_padTimes
, WXK_NUMPAD_MULTIPLY
)
271 KEY (KB_padDivide
, WXK_NUMPAD_DIVIDE
)
272 KEY (KB_padLeft
, WXK_NUMPAD_LEFT
)
273 KEY (KB_padRight
, WXK_NUMPAD_RIGHT
)
274 KEY (KB_padUp
, WXK_NUMPAD_UP
)
275 KEY (KB_padDown
, WXK_NUMPAD_DOWN
)
276 KEY (KB_padInsert
, WXK_NUMPAD_INSERT
)
277 KEY (KB_padDelete
, WXK_NUMPAD_DELETE
)
278 KEY (KB_padHome
, WXK_NUMPAD_HOME
)
279 KEY (KB_padEnd
, WXK_NUMPAD_END
)
280 KEY (KB_padPageUp
, WXK_NUMPAD_PAGEUP
)
281 //KEY (KB_padPageUp, WXK_NUMPAD_PRIOR)
282 KEY (KB_padPageDown
, WXK_NUMPAD_PAGEDOWN
)
283 //KEY (KB_padPageDown, WXK_NUMPAD_NEXT)
284 KEY (KB_padCenter
, WXK_NUMPAD_SEPARATOR
) // ?
294 KEY (KB_F10
, WXK_F10
)
295 KEY (KB_F11
, WXK_F11
)
296 KEY (KB_F12
, WXK_F12
)
297 KEY (KB_left
, WXK_LEFT
)
298 KEY (KB_right
, WXK_RIGHT
)
300 KEY (KB_down
, WXK_DOWN
)
301 KEY (KB_insert
, WXK_INSERT
)
302 KEY (KB_delete
, WXK_DELETE
)
303 KEY (KB_home
, WXK_HOME
)
304 KEY (KB_end
, WXK_END
)
305 KEY (KB_pageUp
, WXK_PAGEUP
)
306 KEY (KB_pageDown
, WXK_PAGEDOWN
)
307 KEY (KB_capsLock
, WXK_CAPITAL
)
308 KEY (KB_numLock
, WXK_NUMLOCK
)
309 KEY (KB_scrollLock
, WXK_SCROLL
)
310 KEY (KB_leftShift
, WXK_SHIFT
)
311 KEY (KB_rightShift
, WXK_SHIFT
)
312 KEY (KB_leftCtrl
, WXK_CONTROL
)
313 KEY (KB_rightCtrl
, WXK_CONTROL
)
314 KEY (KB_leftAlt
, WXK_ALT
)
315 KEY (KB_rightAlt
, WXK_ALT
)
316 KEY (KB_leftWindows
, WXK_START
)
317 KEY (KB_rightWindows
, WXK_START
)
318 KEY (KB_menu
, WXK_MENU
)
319 KEY (KB_sysReq
, WXK_SNAPSHOT
)
320 KEY (KB_esc
, WXK_ESCAPE
)
331 KEY (KB_minus
, WXK_SUBTRACT
)
332 KEY (KB_equals
, WXK_ADD
)
333 KEY (KB_backSlash
, '\\')
334 KEY (KB_backspace
, WXK_BACK
)
335 KEY (KB_tab
, WXK_TAB
)
346 KEY (KB_leftSquareBrace
,'[')
347 KEY (KB_rightSquareBrace
,']')
348 KEY (KB_enter
, WXK_RETURN
)
358 KEY (KB_semicolon
, ';')
359 KEY (KB_apostrophe
, '\'')
369 KEY (KB_divide
, WXK_DIVIDE
)
370 KEY (KB_space
, WXK_SPACE
)
374 key
= EVT_asciiCode(event
->message
);
381 static long wxAsciiToKeyCode(event_t
*event
)
383 return (long)EVT_asciiCode(event
->message
);
386 static ibool
wxWindowKeybHandler(window_t
*wnd
, event_t
*e
)
388 wxEventType type
= wxEVT_NULL
;
389 wxWindowMGL
*win
= (wxWindowMGL
*)MGL_wmGetWindowUserData(wnd
);
390 wxPoint where
= win
->ScreenToClient(wxPoint(e
->where_x
, e
->where_y
));
393 event
.SetEventObject(win
);
394 event
.SetTimestamp(e
->when
);
395 event
.m_keyCode
= wxScanToKeyCode(e
);
396 event
.m_scanCode
= 0; // not used by wx at all
399 event
.m_shiftDown
= e
->modifiers
& EVT_SHIFTKEY
;
400 event
.m_controlDown
= e
->modifiers
& EVT_CTRLSTATE
;
401 event
.m_altDown
= e
->modifiers
& EVT_LEFTALT
;
402 event
.m_metaDown
= e
->modifiers
& EVT_RIGHTALT
;
404 if ( e
->what
== EVT_KEYUP
)
406 event
.SetEventType(wxEVT_KEY_UP
);
407 return win
->GetEventHandler()->ProcessEvent(event
);
414 event
.SetEventType(wxEVT_KEY_DOWN
);
417 ret
= win
->GetEventHandler()->ProcessEvent(event
);
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 ( g_focusedWindow
== this )
491 if ( g_windowUnderMouse
== this )
492 g_windowUnderMouse
= NULL
;
494 // VS: destroy children first and _then_ detach *this from its parent.
495 // If we'd do it the other way around, children wouldn't be able
496 // find their parent frame (see above).
500 m_parent
->RemoveChild(this);
503 MGL_wmDestroyWindow(m_wnd
);
506 // real construction (Init() must have been called before!)
507 bool wxWindowMGL::Create(wxWindow
*parent
,
512 const wxString
& name
)
514 // FIXME_MGL -- temporary!
515 //wxCHECK_MSG( parent, FALSE, wxT("can't create wxWindow without parent") );
517 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
520 if ( parent
) // FIXME_MGL temporary
521 parent
->AddChild(this);
523 m_isShown
=FALSE
;// FIXME_MGL -- temporary, simulates wxTLW/wxFrame
525 if ( style
& wxPOPUP_WINDOW
)
527 // it is created hidden as other top level windows
532 x
= pos
.x
, y
= pos
.y
;
534 x
= 0; // FIXME_MGL, something better, see GTK+
536 y
= 0; // FIXME_MGL, something better, see GTK+
537 w
= WidthDefault(size
.x
);
538 h
= HeightDefault(size
.y
);
541 if ( !(style
& wxNO_FULL_REPAINT_ON_RESIZE
) )
542 mgl_style
|= MGL_WM_FULL_REPAINT_ON_RESIZE
;
543 if ( style
& wxSTAY_ON_TOP
)
544 mgl_style
|= MGL_WM_ALWAYS_ON_TOP
;
546 m_wnd
= MGL_wmCreateWindow(g_winMng
,
547 parent
? parent
->GetHandle() : NULL
,
550 MGL_wmSetWindowFlags(m_wnd
, mgl_style
);
551 MGL_wmSetWindowUserData(m_wnd
, (void*) this);
552 MGL_wmSetWindowPainter(m_wnd
, wxWindowPainter
);
553 MGL_wmShowWindow(m_wnd
, m_isShown
);
554 MGL_wmSetWindowCursor(m_wnd
, *wxSTANDARD_CURSOR
->GetMGLCursor());
556 MGL_wmPushWindowEventHandler(m_wnd
, wxWindowMouseHandler
, EVT_MOUSEEVT
, 0);
557 MGL_wmPushWindowEventHandler(m_wnd
, wxWindowKeybHandler
, EVT_KEYEVT
, 0);
562 // ---------------------------------------------------------------------------
564 // ---------------------------------------------------------------------------
566 void wxWindowMGL::SetFocus()
569 g_focusedWindow
->KillFocus();
571 g_focusedWindow
= this;
573 MGL_wmCaptureEvents(GetHandle(), EVT_KEYEVT
, wxMGL_CAPTURE_KEYB
);
576 // caret needs to be informed about focus change
577 wxCaret
*caret
= GetCaret();
580 #endif // wxUSE_CARET
584 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, GetId());
585 event
.SetEventObject(this);
586 GetEventHandler()->ProcessEvent(event
);
589 wxFocusEvent
event(wxEVT_SET_FOCUS
, GetId());
590 event
.SetEventObject(this);
591 GetEventHandler()->ProcessEvent(event
);
594 void wxWindowMGL::KillFocus()
596 if ( g_focusedWindow
!= this ) return;
597 g_focusedWindow
= NULL
;
599 if ( m_isBeingDeleted
) return;
601 MGL_wmUncaptureEvents(GetHandle(), wxMGL_CAPTURE_KEYB
);
604 // caret needs to be informed about focus change
605 wxCaret
*caret
= GetCaret();
607 caret
->OnKillFocus();
608 #endif // wxUSE_CARET
612 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, GetId());
613 event
.SetEventObject(this);
614 GetEventHandler()->ProcessEvent(event
);
617 wxFocusEvent
event(wxEVT_KILL_FOCUS
, GetId());
618 event
.SetEventObject(this);
619 GetEventHandler()->ProcessEvent(event
);
622 // ----------------------------------------------------------------------------
623 // this wxWindowBase function is implemented here (in platform-specific file)
624 // because it is static and so couldn't be made virtual
625 // ----------------------------------------------------------------------------
626 wxWindow
*wxWindowBase::FindFocus()
628 return (wxWindow
*)g_focusedWindow
;
631 bool wxWindowMGL::Show(bool show
)
633 if ( !wxWindowBase::Show(show
) )
636 MGL_wmShowWindow(m_wnd
, show
);
640 // Raise the window to the top of the Z order
641 void wxWindowMGL::Raise()
643 MGL_wmRaiseWindow(m_wnd
);
646 // Lower the window to the bottom of the Z order
647 void wxWindowMGL::Lower()
649 MGL_wmLowerWindow(m_wnd
);
652 void wxWindowMGL::CaptureMouse()
654 MGL_wmCaptureEvents(m_wnd
, EVT_MOUSEEVT
, wxMGL_CAPTURE_MOUSE
);
657 void wxWindowMGL::ReleaseMouse()
659 MGL_wmUncaptureEvents(m_wnd
, wxMGL_CAPTURE_MOUSE
);
662 /* static */ wxWindow
*wxWindowBase::GetCapture()
664 for (captureentry_t
*c
= g_winMng
->capturedEvents
; c
; c
= c
->next
)
666 if ( c
->id
== wxMGL_CAPTURE_MOUSE
)
667 return (wxWindow
*)c
->wnd
->userData
;
672 bool wxWindowMGL::SetCursor(const wxCursor
& cursor
)
674 if ( !wxWindowBase::SetCursor(cursor
) )
681 MGL_wmSetWindowCursor(m_wnd
, *m_cursor
.GetMGLCursor());
683 MGL_wmSetWindowCursor(m_wnd
, *wxSTANDARD_CURSOR
->GetMGLCursor());
688 void wxWindowMGL::WarpPointer(int x
, int y
)
690 ClientToScreen(&x
, &y
);
691 EVT_setMousePos(x
, y
);
694 #if WXWIN_COMPATIBILITY
695 // If nothing defined for this, try the parent.
696 // E.g. we may be a button loaded from a resource, with no callback function
698 void wxWindowMGL::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
700 if ( GetEventHandler()->ProcessEvent(event
) )
703 m_parent
->GetEventHandler()->OnCommand(win
, event
);
705 #endif // WXWIN_COMPATIBILITY_2
707 #if WXWIN_COMPATIBILITY
708 wxObject
* wxWindowMGL::GetChild(int number
) const
710 // Return a pointer to the Nth object in the Panel
711 wxNode
*node
= GetChildren().First();
717 wxObject
*obj
= (wxObject
*)node
->Data();
723 #endif // WXWIN_COMPATIBILITY
725 // Set this window to be the child of 'parent'.
726 bool wxWindowMGL::Reparent(wxWindowBase
*parent
)
728 if ( !wxWindowBase::Reparent(parent
) )
731 MGL_wmReparentWindow(m_wnd
, parent
->GetHandle());
737 // ---------------------------------------------------------------------------
739 // ---------------------------------------------------------------------------
741 #if wxUSE_DRAG_AND_DROP
743 void wxWindowMGL::SetDropTarget(wxDropTarget
*pDropTarget
)
745 if ( m_dropTarget
!= 0 ) {
746 m_dropTarget
->Revoke(m_hWnd
);
750 m_dropTarget
= pDropTarget
;
751 if ( m_dropTarget
!= 0 )
752 m_dropTarget
->Register(m_hWnd
);
755 #endif // wxUSE_DRAG_AND_DROP
757 // old style file-manager drag&drop support: we retain the old-style
758 // DragAcceptFiles in parallel with SetDropTarget.
759 void wxWindowMGL::DragAcceptFiles(bool accept
)
762 HWND hWnd
= GetHwnd();
764 ::DragAcceptFiles(hWnd
, (BOOL
)accept
);
768 // ---------------------------------------------------------------------------
769 // moving and resizing
770 // ---------------------------------------------------------------------------
773 void wxWindowMGL::DoGetSize(int *x
, int *y
) const
775 if (x
) *x
= m_wnd
->width
;
776 if (y
) *y
= m_wnd
->height
;
779 void wxWindowMGL::DoGetPosition(int *x
, int *y
) const
781 if (x
) *x
= m_wnd
->x
;
782 if (y
) *y
= m_wnd
->y
;
785 void wxWindowMGL::DoScreenToClient(int *x
, int *y
) const
788 wxPoint co
= GetClientAreaOrigin();
790 MGL_wmCoordGlobalToLocal(m_wnd
, m_wnd
->x
, m_wnd
->y
, &ax
, &ay
);
799 void wxWindowMGL::DoClientToScreen(int *x
, int *y
) const
802 wxPoint co
= GetClientAreaOrigin();
804 MGL_wmCoordGlobalToLocal(m_wnd
, m_wnd
->x
+co
.x
, m_wnd
->y
+co
.y
, &ax
, &ay
);
811 // Get size *available for subwindows* i.e. excluding menu bar etc.
812 void wxWindowMGL::DoGetClientSize(int *x
, int *y
) const
817 void wxWindowMGL::DoMoveWindow(int x
, int y
, int width
, int height
)
819 MGL_wmSetWindowPosition(GetHandle(), x
, y
, width
, height
);
822 // set the size of the window: if the dimensions are positive, just use them,
823 // but if any of them is equal to -1, it means that we must find the value for
824 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
825 // which case -1 is a valid value for x and y)
827 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
828 // the width/height to best suit our contents, otherwise we reuse the current
830 void wxWindowMGL::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
832 // get the current size and position...
833 int currentX
, currentY
;
834 GetPosition(¤tX
, ¤tY
);
835 int currentW
,currentH
;
836 GetSize(¤tW
, ¤tH
);
838 // ... and don't do anything (avoiding flicker) if it's already ok
839 if ( x
== currentX
&& y
== currentY
&&
840 width
== currentW
&& height
== currentH
)
845 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
847 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
850 #if 0 // FIXME_MGL -- what's this good for?
851 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
857 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
859 size
= DoGetBestSize();
864 // just take the current one
871 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
875 size
= DoGetBestSize();
877 //else: already called DoGetBestSize() above
883 // just take the current one
888 DoMoveWindow(x
, y
, width
, height
);
890 wxSizeEvent
event(wxSize(width
, height
), GetId());
891 event
.SetEventObject(this);
892 GetEventHandler()->ProcessEvent(event
);
895 void wxWindowMGL::DoSetClientSize(int width
, int height
)
897 SetSize(width
, height
);
900 // ---------------------------------------------------------------------------
902 // ---------------------------------------------------------------------------
904 int wxWindowMGL::GetCharHeight() const
908 return dc
.GetCharHeight();
911 int wxWindowMGL::GetCharWidth() const
915 return dc
.GetCharWidth();
918 void wxWindowMGL::GetTextExtent(const wxString
& string
,
920 int *descent
, int *externalLeading
,
921 const wxFont
*theFont
) const
926 dc
.GetTextExtent(string
, x
, y
, descent
, externalLeading
, (wxFont
*)theFont
);
929 #if wxUSE_CARET && WXWIN_COMPATIBILITY
930 // ---------------------------------------------------------------------------
931 // Caret manipulation
932 // ---------------------------------------------------------------------------
934 void wxWindowMGL::CreateCaret(int w
, int h
)
936 SetCaret(new wxCaret(this, w
, h
));
939 void wxWindowMGL::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
941 wxFAIL_MSG("not implemented");
944 void wxWindowMGL::ShowCaret(bool show
)
946 wxCHECK_RET( m_caret
, "no caret to show" );
951 void wxWindowMGL::DestroyCaret()
956 void wxWindowMGL::SetCaretPos(int x
, int y
)
958 wxCHECK_RET( m_caret
, "no caret to move" );
963 void wxWindowMGL::GetCaretPos(int *x
, int *y
) const
965 wxCHECK_RET( m_caret
, "no caret to get position of" );
967 m_caret
->GetPosition(x
, y
);
969 #endif // wxUSE_CARET
972 // ---------------------------------------------------------------------------
974 // ---------------------------------------------------------------------------
976 void wxWindowMGL::Clear()
978 wxClientDC
dc((wxWindow
*)this);
979 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
980 dc
.SetBackground(brush
);
984 void wxWindowMGL::Refresh(bool eraseBack
, const wxRect
*rect
)
986 if ( m_eraseBackground
== -1 )
987 m_eraseBackground
= eraseBack
;
989 m_eraseBackground
|= eraseBack
;
994 r
.left
= rect
->GetLeft(), r
.right
= rect
->GetRight();
995 r
.top
= rect
->GetTop(), r
.bottom
= rect
->GetBottom();
996 MGL_wmInvalidateWindowRect(GetHandle(), &r
);
999 MGL_wmInvalidateWindow(GetHandle());
1002 void wxWindowMGL::Update()
1005 MGL_wmUpdateDC(g_winMng
);
1008 void wxWindowMGL::Freeze()
1011 m_refreshAfterThaw
= FALSE
;
1014 void wxWindowMGL::Thaw()
1017 if ( m_refreshAfterThaw
)
1021 void wxWindowMGL::HandlePaint(MGLDevCtx
*dc
)
1025 // Don't paint anything if the window is frozen.
1026 m_refreshAfterThaw
= TRUE
;
1031 dc
->getClipRegion(clip
);
1032 m_updateRegion
= wxRegion(clip
);
1035 if ( m_eraseBackground
!= 0 )
1037 wxWindowDC
dc((wxWindow
*)this);
1038 wxEraseEvent
eventEr(m_windowId
, &dc
);
1039 eventEr
.SetEventObject(this);
1040 GetEventHandler()->ProcessEvent(eventEr
);
1042 m_eraseBackground
= -1;
1044 wxNcPaintEvent
eventNc(GetId());
1045 eventNc
.SetEventObject(this);
1046 GetEventHandler()->ProcessEvent(eventNc
);
1048 wxPaintEvent
eventPt(GetId());
1049 eventPt
.SetEventObject(this);
1050 GetEventHandler()->ProcessEvent(eventPt
);
1052 m_paintMGLDC
= NULL
;
1053 m_updateRegion
.Clear();
1057 // Find the wxWindow at the current mouse position, returning the mouse
1059 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1061 return wxFindWindowAtPoint(pt
= wxGetMousePosition());
1064 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
1066 window_t
*wnd
= MGL_wmGetWindowAtPosition(g_winMng
, pt
.x
, pt
.y
);
1067 return (wxWindow
*)wnd
->userData
;