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
->GetWindowStyle() & 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
);
183 MGL_wmCoordGlobalToLocal(win
->GetHandle(),
184 e
->where_x
, e
->where_y
, &where
.x
, &where
.y
);
186 if ( !win
->IsEnabled() ) return FALSE
;
188 wxEventType type
= wxEVT_NULL
;
190 event
.SetEventObject(win
);
191 event
.SetTimestamp(e
->when
);
194 event
.m_shiftDown
= e
->modifiers
& EVT_SHIFTKEY
;
195 event
.m_controlDown
= e
->modifiers
& EVT_CTRLSTATE
;
196 event
.m_altDown
= e
->modifiers
& EVT_LEFTALT
;
197 event
.m_metaDown
= e
->modifiers
& EVT_RIGHTALT
;
198 event
.m_leftDown
= e
->modifiers
& EVT_LEFTBUT
;
199 event
.m_middleDown
= e
->modifiers
& EVT_MIDDLEBUT
;
200 event
.m_rightDown
= e
->modifiers
& EVT_RIGHTBUT
;
205 if ( e
->message
& EVT_LEFTBMASK
)
206 type
= (e
->message
& EVT_DBLCLICK
) ?
207 wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
;
208 else if ( e
->message
& EVT_MIDDLEBMASK
)
209 type
= (e
->message
& EVT_DBLCLICK
) ?
210 wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
;
211 else if ( e
->message
& EVT_RIGHTBMASK
)
212 type
= (e
->message
& EVT_DBLCLICK
) ?
213 wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
;
217 if ( e
->message
& EVT_LEFTBMASK
)
218 type
= wxEVT_LEFT_UP
;
219 else if ( e
->message
& EVT_MIDDLEBMASK
)
220 type
= wxEVT_MIDDLE_UP
;
221 else if ( e
->message
& EVT_RIGHTBMASK
)
222 type
= wxEVT_RIGHT_UP
;
226 if ( win
!= g_windowUnderMouse
)
228 if ( g_windowUnderMouse
)
230 wxMouseEvent
event2(event
);
231 MGL_wmCoordGlobalToLocal(g_windowUnderMouse
->GetHandle(),
232 e
->where_x
, e
->where_y
,
233 &event2
.m_x
, &event2
.m_y
);
235 event2
.SetEventObject(g_windowUnderMouse
);
236 event2
.SetEventType(wxEVT_LEAVE_WINDOW
);
237 g_windowUnderMouse
->GetEventHandler()->ProcessEvent(event2
);
240 wxMouseEvent
event3(event
);
241 event3
.SetEventType(wxEVT_ENTER_WINDOW
);
242 win
->GetEventHandler()->ProcessEvent(event3
);
244 g_windowUnderMouse
= win
;
254 if ( type
== wxEVT_NULL
)
260 event
.SetEventType(type
);
261 return win
->GetEventHandler()->ProcessEvent(event
);
265 static long wxScanToKeyCode(event_t
*event
)
267 #define KEY(mgl,wx) case mgl: key = wx; break;
270 switch ( EVT_scanCode(event
->message
) )
272 KEY (KB_padEnter
, WXK_NUMPAD_ENTER
)
273 KEY (KB_padMinus
, WXK_NUMPAD_SUBTRACT
)
274 KEY (KB_padPlus
, WXK_NUMPAD_ADD
)
275 KEY (KB_padTimes
, WXK_NUMPAD_MULTIPLY
)
276 KEY (KB_padDivide
, WXK_NUMPAD_DIVIDE
)
277 KEY (KB_padLeft
, WXK_NUMPAD_LEFT
)
278 KEY (KB_padRight
, WXK_NUMPAD_RIGHT
)
279 KEY (KB_padUp
, WXK_NUMPAD_UP
)
280 KEY (KB_padDown
, WXK_NUMPAD_DOWN
)
281 KEY (KB_padInsert
, WXK_NUMPAD_INSERT
)
282 KEY (KB_padDelete
, WXK_NUMPAD_DELETE
)
283 KEY (KB_padHome
, WXK_NUMPAD_HOME
)
284 KEY (KB_padEnd
, WXK_NUMPAD_END
)
285 KEY (KB_padPageUp
, WXK_NUMPAD_PAGEUP
)
286 //KEY (KB_padPageUp, WXK_NUMPAD_PRIOR)
287 KEY (KB_padPageDown
, WXK_NUMPAD_PAGEDOWN
)
288 //KEY (KB_padPageDown, WXK_NUMPAD_NEXT)
289 KEY (KB_padCenter
, WXK_NUMPAD_SEPARATOR
) // ?
299 KEY (KB_F10
, WXK_F10
)
300 KEY (KB_F11
, WXK_F11
)
301 KEY (KB_F12
, WXK_F12
)
302 KEY (KB_left
, WXK_LEFT
)
303 KEY (KB_right
, WXK_RIGHT
)
305 KEY (KB_down
, WXK_DOWN
)
306 KEY (KB_insert
, WXK_INSERT
)
307 KEY (KB_delete
, WXK_DELETE
)
308 KEY (KB_home
, WXK_HOME
)
309 KEY (KB_end
, WXK_END
)
310 KEY (KB_pageUp
, WXK_PAGEUP
)
311 KEY (KB_pageDown
, WXK_PAGEDOWN
)
312 KEY (KB_capsLock
, WXK_CAPITAL
)
313 KEY (KB_numLock
, WXK_NUMLOCK
)
314 KEY (KB_scrollLock
, WXK_SCROLL
)
315 KEY (KB_leftShift
, WXK_SHIFT
)
316 KEY (KB_rightShift
, WXK_SHIFT
)
317 KEY (KB_leftCtrl
, WXK_CONTROL
)
318 KEY (KB_rightCtrl
, WXK_CONTROL
)
319 KEY (KB_leftAlt
, WXK_ALT
)
320 KEY (KB_rightAlt
, WXK_ALT
)
321 KEY (KB_leftWindows
, WXK_START
)
322 KEY (KB_rightWindows
, WXK_START
)
323 KEY (KB_menu
, WXK_MENU
)
324 KEY (KB_sysReq
, WXK_SNAPSHOT
)
325 KEY (KB_esc
, WXK_ESCAPE
)
336 KEY (KB_minus
, WXK_SUBTRACT
)
337 KEY (KB_equals
, WXK_ADD
)
338 KEY (KB_backSlash
, '\\')
339 KEY (KB_backspace
, WXK_BACK
)
340 KEY (KB_tab
, WXK_TAB
)
351 KEY (KB_leftSquareBrace
,'[')
352 KEY (KB_rightSquareBrace
,']')
353 KEY (KB_enter
, WXK_RETURN
)
363 KEY (KB_semicolon
, ';')
364 KEY (KB_apostrophe
, '\'')
374 KEY (KB_divide
, WXK_DIVIDE
)
375 KEY (KB_space
, WXK_SPACE
)
379 key
= EVT_asciiCode(event
->message
);
388 static long wxAsciiToKeyCode(event_t
*event
)
390 return (long)EVT_asciiCode(event
->message
);
393 static ibool
wxWindowKeybHandler(window_t
*wnd
, event_t
*e
)
395 wxWindowMGL
*win
= (wxWindowMGL
*)MGL_wmGetWindowUserData(wnd
);
397 if ( !win
->IsEnabled() ) return FALSE
;
400 MGL_wmCoordGlobalToLocal(win
->GetHandle(),
401 e
->where_x
, e
->where_y
, &where
.x
, &where
.y
);
404 event
.SetEventObject(win
);
405 event
.SetTimestamp(e
->when
);
406 event
.m_keyCode
= wxScanToKeyCode(e
);
407 event
.m_scanCode
= 0; // not used by wx at all
410 event
.m_shiftDown
= e
->modifiers
& EVT_SHIFTKEY
;
411 event
.m_controlDown
= e
->modifiers
& EVT_CTRLSTATE
;
412 event
.m_altDown
= e
->modifiers
& EVT_LEFTALT
;
413 event
.m_metaDown
= e
->modifiers
& EVT_RIGHTALT
;
415 if ( e
->what
== EVT_KEYUP
)
417 event
.SetEventType(wxEVT_KEY_UP
);
418 return win
->GetEventHandler()->ProcessEvent(event
);
425 event
.SetEventType(wxEVT_KEY_DOWN
);
428 ret
= win
->GetEventHandler()->ProcessEvent(event
);
433 for (wxWindowMGL
*w
= win
; w
; w
= w
->GetParent())
435 int command
= w
->GetAcceleratorTable()->GetCommand(event
);
438 wxCommandEvent
eventc(wxEVT_COMMAND_MENU_SELECTED
, command
);
439 ret
= w
->GetEventHandler()->ProcessEvent(eventc
);
442 if ( w
->IsTopLevel() )
446 #endif // wxUSE_ACCEL
448 /* wxMSW doesn't send char events with Alt pressed */
449 /* Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x
450 will only be sent if it is not in an accelerator table. */
451 event2
.m_keyCode
= wxAsciiToKeyCode(e
);
452 if ( !ret
&& event2
.m_keyCode
!= 0 )
454 event2
.SetEventType(wxEVT_CHAR
);
455 ret
= win
->GetEventHandler()->ProcessEvent(event2
);
462 // ---------------------------------------------------------------------------
464 // ---------------------------------------------------------------------------
466 // in wxUniv this class is abstract because it doesn't have DoPopupMenu()
467 IMPLEMENT_ABSTRACT_CLASS(wxWindowMGL
, wxWindowBase
)
469 BEGIN_EVENT_TABLE(wxWindowMGL
, wxWindowBase
)
472 // ===========================================================================
474 // ===========================================================================
476 // ----------------------------------------------------------------------------
477 // constructors and such
478 // ----------------------------------------------------------------------------
480 void wxWindowMGL::Init()
488 m_isBeingDeleted
= FALSE
;
492 m_eraseBackground
= -1;
496 wxWindowMGL::~wxWindowMGL()
498 m_isBeingDeleted
= TRUE
;
500 if ( g_focusedWindow
== this )
502 if ( g_windowUnderMouse
== this )
503 g_windowUnderMouse
= NULL
;
505 // VS: destroy children first and _then_ detach *this from its parent.
506 // If we'd do it the other way around, children wouldn't be able
507 // find their parent frame (see above).
511 m_parent
->RemoveChild(this);
514 MGL_wmDestroyWindow(m_wnd
);
517 // real construction (Init() must have been called before!)
518 bool wxWindowMGL::Create(wxWindow
*parent
,
523 const wxString
& name
)
525 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
529 parent
->AddChild(this);
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
);
542 if ( !(style
& wxNO_FULL_REPAINT_ON_RESIZE
) )
544 mgl_style
|= MGL_WM_FULL_REPAINT_ON_RESIZE
;
546 if ( style
& wxSTAY_ON_TOP
)
548 mgl_style
|= MGL_WM_ALWAYS_ON_TOP
;
550 if ( style
& wxPOPUP_WINDOW
)
552 mgl_style
|= MGL_WM_ALWAYS_ON_TOP
;
553 // it is created hidden as other top level windows
557 m_wnd
= MGL_wmCreateWindow(g_winMng
,
558 parent
? parent
->GetHandle() : NULL
,
561 MGL_wmSetWindowFlags(m_wnd
, mgl_style
);
562 MGL_wmSetWindowUserData(m_wnd
, (void*) this);
563 MGL_wmSetWindowPainter(m_wnd
, wxWindowPainter
);
564 MGL_wmShowWindow(m_wnd
, m_isShown
);
565 MGL_wmSetWindowCursor(m_wnd
, *wxSTANDARD_CURSOR
->GetMGLCursor());
567 MGL_wmPushWindowEventHandler(m_wnd
, wxWindowMouseHandler
, EVT_MOUSEEVT
, 0);
568 MGL_wmPushWindowEventHandler(m_wnd
, wxWindowKeybHandler
, EVT_KEYEVT
, 0);
573 // ---------------------------------------------------------------------------
575 // ---------------------------------------------------------------------------
577 void wxWindowMGL::SetFocus()
580 g_focusedWindow
->KillFocus();
582 g_focusedWindow
= this;
584 MGL_wmCaptureEvents(GetHandle(), EVT_KEYEVT
, wxMGL_CAPTURE_KEYB
);
587 // caret needs to be informed about focus change
588 wxCaret
*caret
= GetCaret();
591 #endif // wxUSE_CARET
595 // FIXME_MGL - this is wrong, see wxGTK!
596 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, GetId());
597 event
.SetEventObject(this);
598 GetEventHandler()->ProcessEvent(event
);
601 wxFocusEvent
event(wxEVT_SET_FOCUS
, GetId());
602 event
.SetEventObject(this);
603 GetEventHandler()->ProcessEvent(event
);
606 void wxWindowMGL::KillFocus()
608 if ( g_focusedWindow
!= this ) return;
609 g_focusedWindow
= NULL
;
611 if ( m_isBeingDeleted
) return;
613 MGL_wmUncaptureEvents(GetHandle(), wxMGL_CAPTURE_KEYB
);
616 // caret needs to be informed about focus change
617 wxCaret
*caret
= GetCaret();
619 caret
->OnKillFocus();
620 #endif // wxUSE_CARET
624 // FIXME_MGL - this is wrong, see wxGTK!
625 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, GetId());
626 event
.SetEventObject(this);
627 GetEventHandler()->ProcessEvent(event
);
630 wxFocusEvent
event(wxEVT_KILL_FOCUS
, GetId());
631 event
.SetEventObject(this);
632 GetEventHandler()->ProcessEvent(event
);
635 // ----------------------------------------------------------------------------
636 // this wxWindowBase function is implemented here (in platform-specific file)
637 // because it is static and so couldn't be made virtual
638 // ----------------------------------------------------------------------------
639 wxWindow
*wxWindowBase::FindFocus()
641 return (wxWindow
*)g_focusedWindow
;
644 bool wxWindowMGL::Show(bool show
)
646 if ( !wxWindowBase::Show(show
) )
649 MGL_wmShowWindow(m_wnd
, show
);
653 // Raise the window to the top of the Z order
654 void wxWindowMGL::Raise()
656 MGL_wmRaiseWindow(m_wnd
);
659 // Lower the window to the bottom of the Z order
660 void wxWindowMGL::Lower()
662 MGL_wmLowerWindow(m_wnd
);
665 void wxWindowMGL::CaptureMouse()
667 MGL_wmCaptureEvents(m_wnd
, EVT_MOUSEEVT
, wxMGL_CAPTURE_MOUSE
);
670 void wxWindowMGL::ReleaseMouse()
672 MGL_wmUncaptureEvents(m_wnd
, wxMGL_CAPTURE_MOUSE
);
675 /* static */ wxWindow
*wxWindowBase::GetCapture()
677 for (captureentry_t
*c
= g_winMng
->capturedEvents
; c
; c
= c
->next
)
679 if ( c
->id
== wxMGL_CAPTURE_MOUSE
)
680 return (wxWindow
*)c
->wnd
->userData
;
685 bool wxWindowMGL::SetCursor(const wxCursor
& cursor
)
687 if ( !wxWindowBase::SetCursor(cursor
) )
694 MGL_wmSetWindowCursor(m_wnd
, *m_cursor
.GetMGLCursor());
696 MGL_wmSetWindowCursor(m_wnd
, *wxSTANDARD_CURSOR
->GetMGLCursor());
701 void wxWindowMGL::WarpPointer(int x
, int y
)
703 ClientToScreen(&x
, &y
);
704 EVT_setMousePos(x
, y
);
707 #if WXWIN_COMPATIBILITY
708 // If nothing defined for this, try the parent.
709 // E.g. we may be a button loaded from a resource, with no callback function
711 void wxWindowMGL::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
713 if ( GetEventHandler()->ProcessEvent(event
) )
716 m_parent
->GetEventHandler()->OnCommand(win
, event
);
718 #endif // WXWIN_COMPATIBILITY_2
720 #if WXWIN_COMPATIBILITY
721 wxObject
* wxWindowMGL::GetChild(int number
) const
723 // Return a pointer to the Nth object in the Panel
724 wxNode
*node
= GetChildren().First();
730 wxObject
*obj
= (wxObject
*)node
->Data();
736 #endif // WXWIN_COMPATIBILITY
738 // Set this window to be the child of 'parent'.
739 bool wxWindowMGL::Reparent(wxWindowBase
*parent
)
741 if ( !wxWindowBase::Reparent(parent
) )
744 MGL_wmReparentWindow(m_wnd
, parent
->GetHandle());
750 // ---------------------------------------------------------------------------
752 // ---------------------------------------------------------------------------
754 #if wxUSE_DRAG_AND_DROP
756 void wxWindowMGL::SetDropTarget(wxDropTarget
*pDropTarget
)
758 if ( m_dropTarget
!= 0 ) {
759 m_dropTarget
->Revoke(m_hWnd
);
763 m_dropTarget
= pDropTarget
;
764 if ( m_dropTarget
!= 0 )
765 m_dropTarget
->Register(m_hWnd
);
768 #endif // wxUSE_DRAG_AND_DROP
770 // old style file-manager drag&drop support: we retain the old-style
771 // DragAcceptFiles in parallel with SetDropTarget.
772 void wxWindowMGL::DragAcceptFiles(bool accept
)
775 HWND hWnd
= GetHwnd();
777 ::DragAcceptFiles(hWnd
, (BOOL
)accept
);
781 // ---------------------------------------------------------------------------
782 // moving and resizing
783 // ---------------------------------------------------------------------------
786 void wxWindowMGL::DoGetSize(int *x
, int *y
) const
788 if (x
) *x
= m_wnd
->width
;
789 if (y
) *y
= m_wnd
->height
;
792 void wxWindowMGL::DoGetPosition(int *x
, int *y
) const
794 if (x
) *x
= m_wnd
->x
;
795 if (y
) *y
= m_wnd
->y
;
798 void wxWindowMGL::DoScreenToClient(int *x
, int *y
) const
801 MGL_wmCoordGlobalToLocal(m_wnd
, 0, 0, &ax
, &ay
);
808 void wxWindowMGL::DoClientToScreen(int *x
, int *y
) const
811 MGL_wmCoordLocalToGlobal(m_wnd
, 0, 0, &ax
, &ay
);
818 // Get size *available for subwindows* i.e. excluding menu bar etc.
819 void wxWindowMGL::DoGetClientSize(int *x
, int *y
) const
824 void wxWindowMGL::DoMoveWindow(int x
, int y
, int width
, int height
)
826 MGL_wmSetWindowPosition(GetHandle(), x
, y
, width
, height
);
829 // set the size of the window: if the dimensions are positive, just use them,
830 // but if any of them is equal to -1, it means that we must find the value for
831 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
832 // which case -1 is a valid value for x and y)
834 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
835 // the width/height to best suit our contents, otherwise we reuse the current
837 void wxWindowMGL::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
839 // get the current size and position...
840 int currentX
, currentY
;
841 GetPosition(¤tX
, ¤tY
);
842 int currentW
,currentH
;
843 GetSize(¤tW
, ¤tH
);
845 // ... and don't do anything (avoiding flicker) if it's already ok
846 if ( x
== currentX
&& y
== currentY
&&
847 width
== currentW
&& height
== currentH
)
852 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
854 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
857 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
862 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
864 size
= DoGetBestSize();
869 // just take the current one
876 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
880 size
= DoGetBestSize();
882 //else: already called DoGetBestSize() above
888 // just take the current one
893 DoMoveWindow(x
, y
, width
, height
);
895 wxSizeEvent
event(wxSize(width
, height
), GetId());
896 event
.SetEventObject(this);
897 GetEventHandler()->ProcessEvent(event
);
900 void wxWindowMGL::DoSetClientSize(int width
, int height
)
902 SetSize(width
, height
);
905 // ---------------------------------------------------------------------------
907 // ---------------------------------------------------------------------------
909 int wxWindowMGL::GetCharHeight() const
913 return dc
.GetCharHeight();
916 int wxWindowMGL::GetCharWidth() const
920 return dc
.GetCharWidth();
923 void wxWindowMGL::GetTextExtent(const wxString
& string
,
925 int *descent
, int *externalLeading
,
926 const wxFont
*theFont
) const
931 dc
.GetTextExtent(string
, x
, y
, descent
, externalLeading
, (wxFont
*)theFont
);
934 #if wxUSE_CARET && WXWIN_COMPATIBILITY
935 // ---------------------------------------------------------------------------
936 // Caret manipulation
937 // ---------------------------------------------------------------------------
939 void wxWindowMGL::CreateCaret(int w
, int h
)
941 SetCaret(new wxCaret(this, w
, h
));
944 void wxWindowMGL::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
946 wxFAIL_MSG("not implemented");
949 void wxWindowMGL::ShowCaret(bool show
)
951 wxCHECK_RET( m_caret
, "no caret to show" );
956 void wxWindowMGL::DestroyCaret()
961 void wxWindowMGL::SetCaretPos(int x
, int y
)
963 wxCHECK_RET( m_caret
, "no caret to move" );
968 void wxWindowMGL::GetCaretPos(int *x
, int *y
) const
970 wxCHECK_RET( m_caret
, "no caret to get position of" );
972 m_caret
->GetPosition(x
, y
);
974 #endif // wxUSE_CARET
977 // ---------------------------------------------------------------------------
979 // ---------------------------------------------------------------------------
981 void wxWindowMGL::Clear()
983 wxClientDC
dc((wxWindow
*)this);
984 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
985 dc
.SetBackground(brush
);
989 void wxWindowMGL::Refresh(bool eraseBack
, const wxRect
*rect
)
991 if ( m_eraseBackground
== -1 )
992 m_eraseBackground
= eraseBack
;
994 m_eraseBackground
|= eraseBack
;
999 r
.left
= rect
->GetLeft(), r
.right
= rect
->GetRight();
1000 r
.top
= rect
->GetTop(), r
.bottom
= rect
->GetBottom();
1001 MGL_wmInvalidateWindowRect(GetHandle(), &r
);
1004 MGL_wmInvalidateWindow(GetHandle());
1007 void wxWindowMGL::Update()
1010 MGL_wmUpdateDC(g_winMng
);
1013 void wxWindowMGL::Freeze()
1016 m_refreshAfterThaw
= FALSE
;
1019 void wxWindowMGL::Thaw()
1022 if ( m_refreshAfterThaw
)
1026 void wxWindowMGL::HandlePaint(MGLDevCtx
*dc
)
1030 // Don't paint anything if the window is frozen.
1031 m_refreshAfterThaw
= TRUE
;
1036 dc
->getClipRegion(clip
);
1037 m_updateRegion
= wxRegion(clip
);
1040 if ( m_eraseBackground
!= 0 )
1042 wxWindowDC
dc((wxWindow
*)this);
1043 wxEraseEvent
eventEr(m_windowId
, &dc
);
1044 eventEr
.SetEventObject(this);
1045 GetEventHandler()->ProcessEvent(eventEr
);
1047 m_eraseBackground
= -1;
1049 wxNcPaintEvent
eventNc(GetId());
1050 eventNc
.SetEventObject(this);
1051 GetEventHandler()->ProcessEvent(eventNc
);
1053 wxPaintEvent
eventPt(GetId());
1054 eventPt
.SetEventObject(this);
1055 GetEventHandler()->ProcessEvent(eventPt
);
1057 m_paintMGLDC
= NULL
;
1058 m_updateRegion
.Clear();
1062 // Find the wxWindow at the current mouse position, returning the mouse
1064 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1066 return wxFindWindowAtPoint(pt
= wxGetMousePosition());
1069 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
1071 window_t
*wnd
= MGL_wmGetWindowAtPosition(g_winMng
, pt
.x
, pt
.y
);
1072 return (wxWindow
*)wnd
->userData
;