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 // wxCreateMGL_WM creates MGL display DC and associates it with winmng_t
94 // structure. Dimensions and depth of the DC are fetched from wxSystemOptions
96 // This function is *not* called from wxApp's initialization but rather at
97 // the time when WM is needed, i.e. when first wxWindow is created. This
98 // has two important effects:
99 // a) it is possible to write windowless wxMGL apps
100 // b) the app has plenty of time in wxApp::OnInit to feed wxSystemOptions
101 // with desired settings
103 // FIXME_MGL -- move to app.cpp??
104 static void wxDesktopPainter(window_t
*wnd
, MGLDC
*dc
)
106 // FIXME_MGL - for now...
107 MGL_setColorRGB(0x63, 0x63, 0x96);
108 MGL_fillRectCoord(0, 0, wnd
->width
, wnd
->height
);
112 bool wxCreateMGL_WM()
115 int width
= 640, height
= 480, depth
= 16;
116 int refresh
= MGL_DEFAULT_REFRESH
;
118 #if wxUSE_SYSTEM_OPTIONS
119 // FIXME_MGL -- so what is The Proper Way?
120 if ( wxSystemOptions::HasOption(wxT("mgl.screen-width") )
121 width
= wxSystemOptions::GetOptionInt(wxT("mgl.screen-width"));
122 if ( wxSystemOptions::HasOption(wxT("mgl.screen-height") )
123 height
= wxSystemOptions::GetOptionInt(wxT("mgl.screen-height"));
124 if ( wxSystemOptions::HasOption(wxT("mgl.screen-depth") )
125 depth
= wxSystemOptions::GetOptionInt(wxT("mgl.screen-depth"));
126 if ( wxSystemOptions::HasOption(wxT("mgl.screen-refresh") )
127 refresh
= wxSystemOptions::GetOptionInt(wxT("mgl.screen-refresh"));
130 mode
= MGL_findMode(width
, height
, depth
);
133 wxLogWarning(_("Mode %ix%i-%i not available, falling back to default mode."), width
, height
, depth
);
134 mode
= 0; // always available
136 g_displayDC
= new MGLDisplayDC(mode
, 1, refresh
);
137 if ( !g_displayDC
->isValid() )
144 g_winMng
= MGL_wmCreate(g_displayDC
->getDC());
148 MGL_wmSetWindowPainter(MGL_wmGetRootWindow(g_winMng
), wxDesktopPainter
);
153 void wxDestroyMGL_WM()
157 MGL_wmDestroy(g_winMng
);
167 // Returns toplevel grandparent of given window:
168 static wxWindowMGL
* wxGetTopLevelParent(wxWindowMGL
*win
)
170 wxWindowMGL
*p
= win
;
171 while (p
&& !p
->IsTopLevel())
176 // ---------------------------------------------------------------------------
178 // ---------------------------------------------------------------------------
180 static void wxWindowPainter(window_t
*wnd
, MGLDC
*dc
)
182 wxWindowMGL
*w
= (wxWindow
*) wnd
->userData
;
183 if ( w
&& !(w
->GetWindowStyle() & wxTRANSPARENT_WINDOW
) )
186 w
->HandlePaint(&ctx
);
188 // FIXME_MGL -- root window should be a regular window so that
189 // enter/leave and activate/deactivate events work correctly
192 static ibool
wxWindowMouseHandler(window_t
*wnd
, event_t
*e
)
194 wxWindowMGL
*win
= (wxWindowMGL
*)MGL_wmGetWindowUserData(wnd
);
197 MGL_wmCoordGlobalToLocal(win
->GetHandle(),
198 e
->where_x
, e
->where_y
, &where
.x
, &where
.y
);
200 if ( !win
->IsEnabled() ) return FALSE
;
202 wxEventType type
= wxEVT_NULL
;
204 event
.SetEventObject(win
);
205 event
.SetTimestamp(e
->when
);
208 event
.m_shiftDown
= e
->modifiers
& EVT_SHIFTKEY
;
209 event
.m_controlDown
= e
->modifiers
& EVT_CTRLSTATE
;
210 event
.m_altDown
= e
->modifiers
& EVT_LEFTALT
;
211 event
.m_metaDown
= e
->modifiers
& EVT_RIGHTALT
;
212 event
.m_leftDown
= e
->modifiers
& EVT_LEFTBUT
;
213 event
.m_middleDown
= e
->modifiers
& EVT_MIDDLEBUT
;
214 event
.m_rightDown
= e
->modifiers
& EVT_RIGHTBUT
;
219 if ( e
->message
& EVT_LEFTBMASK
)
220 type
= (e
->message
& EVT_DBLCLICK
) ?
221 wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
;
222 else if ( e
->message
& EVT_MIDDLEBMASK
)
223 type
= (e
->message
& EVT_DBLCLICK
) ?
224 wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
;
225 else if ( e
->message
& EVT_RIGHTBMASK
)
226 type
= (e
->message
& EVT_DBLCLICK
) ?
227 wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
;
231 if ( e
->message
& EVT_LEFTBMASK
)
232 type
= wxEVT_LEFT_UP
;
233 else if ( e
->message
& EVT_MIDDLEBMASK
)
234 type
= wxEVT_MIDDLE_UP
;
235 else if ( e
->message
& EVT_RIGHTBMASK
)
236 type
= wxEVT_RIGHT_UP
;
240 if ( !gs_mouseCapture
)
242 if ( win
!= gs_windowUnderMouse
)
244 if ( gs_windowUnderMouse
)
246 wxMouseEvent
event2(event
);
247 MGL_wmCoordGlobalToLocal(gs_windowUnderMouse
->GetHandle(),
248 e
->where_x
, e
->where_y
,
249 &event2
.m_x
, &event2
.m_y
);
251 event2
.SetEventObject(gs_windowUnderMouse
);
252 event2
.SetEventType(wxEVT_LEAVE_WINDOW
);
253 gs_windowUnderMouse
->GetEventHandler()->ProcessEvent(event2
);
256 wxMouseEvent
event3(event
);
257 event3
.SetEventType(wxEVT_ENTER_WINDOW
);
258 win
->GetEventHandler()->ProcessEvent(event3
);
260 gs_windowUnderMouse
= win
;
263 else // gs_mouseCapture
265 bool inside
= (where
.x
>= 0 &&
267 where
.x
< win
->GetSize().x
&&
268 where
.y
< win
->GetSize().y
);
269 if ( (inside
&& gs_windowUnderMouse
!= win
) ||
270 (!inside
&& gs_windowUnderMouse
== win
) )
272 wxMouseEvent
evt(inside
?
273 wxEVT_ENTER_WINDOW
: wxEVT_LEAVE_WINDOW
);
274 evt
.SetEventObject(win
);
275 win
->GetEventHandler()->ProcessEvent(evt
);
276 gs_windowUnderMouse
= inside
? win
: NULL
;
287 if ( type
== wxEVT_NULL
)
293 event
.SetEventType(type
);
294 return win
->GetEventHandler()->ProcessEvent(event
);
298 static long wxScanToKeyCode(event_t
*event
)
300 #define KEY(mgl,wx) case mgl: key = wx; break;
303 switch ( EVT_scanCode(event
->message
) )
305 KEY (KB_padEnter
, WXK_NUMPAD_ENTER
)
306 KEY (KB_padMinus
, WXK_NUMPAD_SUBTRACT
)
307 KEY (KB_padPlus
, WXK_NUMPAD_ADD
)
308 KEY (KB_padTimes
, WXK_NUMPAD_MULTIPLY
)
309 KEY (KB_padDivide
, WXK_NUMPAD_DIVIDE
)
310 KEY (KB_padLeft
, WXK_NUMPAD_LEFT
)
311 KEY (KB_padRight
, WXK_NUMPAD_RIGHT
)
312 KEY (KB_padUp
, WXK_NUMPAD_UP
)
313 KEY (KB_padDown
, WXK_NUMPAD_DOWN
)
314 KEY (KB_padInsert
, WXK_NUMPAD_INSERT
)
315 KEY (KB_padDelete
, WXK_NUMPAD_DELETE
)
316 KEY (KB_padHome
, WXK_NUMPAD_HOME
)
317 KEY (KB_padEnd
, WXK_NUMPAD_END
)
318 KEY (KB_padPageUp
, WXK_NUMPAD_PAGEUP
)
319 //KEY (KB_padPageUp, WXK_NUMPAD_PRIOR)
320 KEY (KB_padPageDown
, WXK_NUMPAD_PAGEDOWN
)
321 //KEY (KB_padPageDown, WXK_NUMPAD_NEXT)
322 KEY (KB_padCenter
, WXK_NUMPAD_SEPARATOR
) // ?
332 KEY (KB_F10
, WXK_F10
)
333 KEY (KB_F11
, WXK_F11
)
334 KEY (KB_F12
, WXK_F12
)
335 KEY (KB_left
, WXK_LEFT
)
336 KEY (KB_right
, WXK_RIGHT
)
338 KEY (KB_down
, WXK_DOWN
)
339 KEY (KB_insert
, WXK_INSERT
)
340 KEY (KB_delete
, WXK_DELETE
)
341 KEY (KB_home
, WXK_HOME
)
342 KEY (KB_end
, WXK_END
)
343 KEY (KB_pageUp
, WXK_PAGEUP
)
344 KEY (KB_pageDown
, WXK_PAGEDOWN
)
345 KEY (KB_capsLock
, WXK_CAPITAL
)
346 KEY (KB_numLock
, WXK_NUMLOCK
)
347 KEY (KB_scrollLock
, WXK_SCROLL
)
348 KEY (KB_leftShift
, WXK_SHIFT
)
349 KEY (KB_rightShift
, WXK_SHIFT
)
350 KEY (KB_leftCtrl
, WXK_CONTROL
)
351 KEY (KB_rightCtrl
, WXK_CONTROL
)
352 KEY (KB_leftAlt
, WXK_ALT
)
353 KEY (KB_rightAlt
, WXK_ALT
)
354 KEY (KB_leftWindows
, WXK_START
)
355 KEY (KB_rightWindows
, WXK_START
)
356 KEY (KB_menu
, WXK_MENU
)
357 KEY (KB_sysReq
, WXK_SNAPSHOT
)
358 KEY (KB_esc
, WXK_ESCAPE
)
369 KEY (KB_minus
, WXK_SUBTRACT
)
370 KEY (KB_equals
, WXK_ADD
)
371 KEY (KB_backSlash
, '\\')
372 KEY (KB_backspace
, WXK_BACK
)
373 KEY (KB_tab
, WXK_TAB
)
384 KEY (KB_leftSquareBrace
,'[')
385 KEY (KB_rightSquareBrace
,']')
386 KEY (KB_enter
, WXK_RETURN
)
396 KEY (KB_semicolon
, ';')
397 KEY (KB_apostrophe
, '\'')
407 KEY (KB_divide
, WXK_DIVIDE
)
408 KEY (KB_space
, WXK_SPACE
)
412 key
= EVT_asciiCode(event
->message
);
421 static long wxAsciiToKeyCode(event_t
*event
)
423 return (long)EVT_asciiCode(event
->message
);
426 static ibool
wxWindowKeybHandler(window_t
*wnd
, event_t
*e
)
428 wxWindowMGL
*win
= (wxWindowMGL
*)MGL_wmGetWindowUserData(wnd
);
430 if ( !win
->IsEnabled() ) return FALSE
;
433 MGL_wmCoordGlobalToLocal(win
->GetHandle(),
434 e
->where_x
, e
->where_y
, &where
.x
, &where
.y
);
437 event
.SetEventObject(win
);
438 event
.SetTimestamp(e
->when
);
439 event
.m_keyCode
= wxScanToKeyCode(e
);
440 event
.m_scanCode
= 0; // not used by wx at all
443 event
.m_shiftDown
= e
->modifiers
& EVT_SHIFTKEY
;
444 event
.m_controlDown
= e
->modifiers
& EVT_CTRLSTATE
;
445 event
.m_altDown
= e
->modifiers
& EVT_LEFTALT
;
446 event
.m_metaDown
= e
->modifiers
& EVT_RIGHTALT
;
448 if ( e
->what
== EVT_KEYUP
)
450 event
.SetEventType(wxEVT_KEY_UP
);
451 return win
->GetEventHandler()->ProcessEvent(event
);
458 event
.SetEventType(wxEVT_KEY_DOWN
);
461 ret
= win
->GetEventHandler()->ProcessEvent(event
);
466 for (wxWindowMGL
*w
= win
; w
; w
= w
->GetParent())
468 int command
= w
->GetAcceleratorTable()->GetCommand(event
);
471 wxCommandEvent
eventc(wxEVT_COMMAND_MENU_SELECTED
, command
);
472 ret
= w
->GetEventHandler()->ProcessEvent(eventc
);
475 if ( w
->IsTopLevel() )
479 #endif // wxUSE_ACCEL
481 /* wxMSW doesn't send char events with Alt pressed */
482 /* Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x
483 will only be sent if it is not in an accelerator table. */
484 event2
.m_keyCode
= wxAsciiToKeyCode(e
);
485 if ( !ret
&& event2
.m_keyCode
!= 0 )
487 event2
.SetEventType(wxEVT_CHAR
);
488 ret
= win
->GetEventHandler()->ProcessEvent(event2
);
495 // ---------------------------------------------------------------------------
497 // ---------------------------------------------------------------------------
499 // in wxUniv this class is abstract because it doesn't have DoPopupMenu()
500 IMPLEMENT_ABSTRACT_CLASS(wxWindowMGL
, wxWindowBase
)
502 BEGIN_EVENT_TABLE(wxWindowMGL
, wxWindowBase
)
505 // ===========================================================================
507 // ===========================================================================
509 // ----------------------------------------------------------------------------
510 // constructors and such
511 // ----------------------------------------------------------------------------
513 void wxWindowMGL::Init()
521 m_isBeingDeleted
= FALSE
;
525 m_eraseBackground
= -1;
529 wxWindowMGL::~wxWindowMGL()
531 m_isBeingDeleted
= TRUE
;
533 if ( gs_mouseCapture
== this )
535 if (gs_activeFrame
== this)
536 gs_activeFrame
= NULL
;
537 if ( gs_focusedWindow
== this )
539 if ( gs_windowUnderMouse
== this )
540 gs_windowUnderMouse
= NULL
;
542 // VS: destroy children first and _then_ detach *this from its parent.
543 // If we'd do it the other way around, children wouldn't be able
544 // find their parent frame (see above).
548 m_parent
->RemoveChild(this);
551 MGL_wmDestroyWindow(m_wnd
);
554 // real construction (Init() must have been called before!)
555 bool wxWindowMGL::Create(wxWindow
*parent
,
560 const wxString
& name
)
562 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
566 parent
->AddChild(this);
569 x
= pos
.x
, y
= pos
.y
;
571 x
= 0; // FIXME_MGL, something better, see GTK+
573 y
= 0; // FIXME_MGL, something better, see GTK+
574 w
= WidthDefault(size
.x
);
575 h
= HeightDefault(size
.y
);
578 window_t
*wnd_parent
= parent
? parent
->GetHandle() : NULL
;
580 if ( !(style
& wxNO_FULL_REPAINT_ON_RESIZE
) )
582 mgl_style
|= MGL_WM_FULL_REPAINT_ON_RESIZE
;
584 if ( style
& wxSTAY_ON_TOP
)
586 mgl_style
|= MGL_WM_ALWAYS_ON_TOP
;
588 if ( style
& wxPOPUP_WINDOW
)
590 mgl_style
|= MGL_WM_ALWAYS_ON_TOP
;
591 // it is created hidden as other top level windows
596 m_wnd
= MGL_wmCreateWindow(g_winMng
, wnd_parent
, x
, y
, w
, h
);
598 MGL_wmSetWindowFlags(m_wnd
, mgl_style
);
599 MGL_wmSetWindowUserData(m_wnd
, (void*) this);
600 MGL_wmSetWindowPainter(m_wnd
, wxWindowPainter
);
601 MGL_wmShowWindow(m_wnd
, m_isShown
);
602 MGL_wmSetWindowCursor(m_wnd
, *wxSTANDARD_CURSOR
->GetMGLCursor());
604 MGL_wmPushWindowEventHandler(m_wnd
, wxWindowMouseHandler
, EVT_MOUSEEVT
, 0);
605 MGL_wmPushWindowEventHandler(m_wnd
, wxWindowKeybHandler
, EVT_KEYEVT
, 0);
610 // ---------------------------------------------------------------------------
612 // ---------------------------------------------------------------------------
614 void wxWindowMGL::SetFocus()
616 if ( gs_focusedWindow
)
617 gs_focusedWindow
->KillFocus();
619 gs_focusedWindow
= this;
621 MGL_wmCaptureEvents(GetHandle(), EVT_KEYEVT
, wxMGL_CAPTURE_KEYB
);
624 // caret needs to be informed about focus change
625 wxCaret
*caret
= GetCaret();
628 #endif // wxUSE_CARET
630 wxWindowMGL
*active
= wxGetTopLevelParent(this);
631 if ( active
!= gs_activeFrame
)
633 if ( gs_activeFrame
)
635 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, gs_activeFrame
->GetId());
636 event
.SetEventObject(gs_activeFrame
);
637 gs_activeFrame
->GetEventHandler()->ProcessEvent(event
);
640 gs_activeFrame
= active
;
641 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, gs_activeFrame
->GetId());
642 event
.SetEventObject(gs_activeFrame
);
643 gs_activeFrame
->GetEventHandler()->ProcessEvent(event
);
646 wxFocusEvent
event(wxEVT_SET_FOCUS
, GetId());
647 event
.SetEventObject(this);
648 GetEventHandler()->ProcessEvent(event
);
651 void wxWindowMGL::KillFocus()
653 if ( gs_focusedWindow
!= this ) return;
654 gs_focusedWindow
= NULL
;
656 if ( m_isBeingDeleted
) return;
658 MGL_wmUncaptureEvents(GetHandle(), wxMGL_CAPTURE_KEYB
);
661 // caret needs to be informed about focus change
662 wxCaret
*caret
= GetCaret();
664 caret
->OnKillFocus();
665 #endif // wxUSE_CARET
669 // FIXME_MGL - this is wrong, see wxGTK!
670 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, GetId());
671 event
.SetEventObject(this);
672 GetEventHandler()->ProcessEvent(event
);
675 wxFocusEvent
event(wxEVT_KILL_FOCUS
, GetId());
676 event
.SetEventObject(this);
677 GetEventHandler()->ProcessEvent(event
);
680 // ----------------------------------------------------------------------------
681 // this wxWindowBase function is implemented here (in platform-specific file)
682 // because it is static and so couldn't be made virtual
683 // ----------------------------------------------------------------------------
684 wxWindow
*wxWindowBase::FindFocus()
686 return (wxWindow
*)gs_focusedWindow
;
689 bool wxWindowMGL::Show(bool show
)
691 if ( !wxWindowBase::Show(show
) )
694 MGL_wmShowWindow(m_wnd
, show
);
698 // Raise the window to the top of the Z order
699 void wxWindowMGL::Raise()
701 MGL_wmRaiseWindow(m_wnd
);
704 // Lower the window to the bottom of the Z order
705 void wxWindowMGL::Lower()
707 MGL_wmLowerWindow(m_wnd
);
710 void wxWindowMGL::CaptureMouse()
712 if ( gs_mouseCapture
)
713 MGL_wmUncaptureEvents(gs_mouseCapture
->m_wnd
, wxMGL_CAPTURE_MOUSE
);
715 gs_mouseCapture
= this;
716 MGL_wmCaptureEvents(m_wnd
, EVT_MOUSEEVT
, wxMGL_CAPTURE_MOUSE
);
719 void wxWindowMGL::ReleaseMouse()
721 wxASSERT_MSG( gs_mouseCapture
== this, wxT("attempt to release mouse, but this window hasn't captured it") )
723 MGL_wmUncaptureEvents(m_wnd
, wxMGL_CAPTURE_MOUSE
);
724 gs_mouseCapture
= NULL
;
727 /* static */ wxWindow
*wxWindowBase::GetCapture()
729 return (wxWindow
*)gs_mouseCapture
;
732 bool wxWindowMGL::SetCursor(const wxCursor
& cursor
)
734 if ( !wxWindowBase::SetCursor(cursor
) )
741 MGL_wmSetWindowCursor(m_wnd
, *m_cursor
.GetMGLCursor());
743 MGL_wmSetWindowCursor(m_wnd
, *wxSTANDARD_CURSOR
->GetMGLCursor());
748 void wxWindowMGL::WarpPointer(int x
, int y
)
750 ClientToScreen(&x
, &y
);
751 EVT_setMousePos(x
, y
);
754 #if WXWIN_COMPATIBILITY
755 // If nothing defined for this, try the parent.
756 // E.g. we may be a button loaded from a resource, with no callback function
758 void wxWindowMGL::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
760 if ( GetEventHandler()->ProcessEvent(event
) )
763 m_parent
->GetEventHandler()->OnCommand(win
, event
);
765 #endif // WXWIN_COMPATIBILITY_2
767 #if WXWIN_COMPATIBILITY
768 wxObject
* wxWindowMGL::GetChild(int number
) const
770 // Return a pointer to the Nth object in the Panel
771 wxNode
*node
= GetChildren().First();
777 wxObject
*obj
= (wxObject
*)node
->Data();
783 #endif // WXWIN_COMPATIBILITY
785 // Set this window to be the child of 'parent'.
786 bool wxWindowMGL::Reparent(wxWindowBase
*parent
)
788 if ( !wxWindowBase::Reparent(parent
) )
791 MGL_wmReparentWindow(m_wnd
, parent
->GetHandle());
797 // ---------------------------------------------------------------------------
799 // ---------------------------------------------------------------------------
801 #if wxUSE_DRAG_AND_DROP
803 void wxWindowMGL::SetDropTarget(wxDropTarget
*pDropTarget
)
805 if ( m_dropTarget
!= 0 ) {
806 m_dropTarget
->Revoke(m_hWnd
);
810 m_dropTarget
= pDropTarget
;
811 if ( m_dropTarget
!= 0 )
812 m_dropTarget
->Register(m_hWnd
);
815 #endif // wxUSE_DRAG_AND_DROP
817 // old style file-manager drag&drop support: we retain the old-style
818 // DragAcceptFiles in parallel with SetDropTarget.
819 void wxWindowMGL::DragAcceptFiles(bool accept
)
822 HWND hWnd
= GetHwnd();
824 ::DragAcceptFiles(hWnd
, (BOOL
)accept
);
828 // ---------------------------------------------------------------------------
829 // moving and resizing
830 // ---------------------------------------------------------------------------
833 void wxWindowMGL::DoGetSize(int *x
, int *y
) const
835 if (x
) *x
= m_wnd
->width
;
836 if (y
) *y
= m_wnd
->height
;
839 void wxWindowMGL::DoGetPosition(int *x
, int *y
) const
841 if (x
) *x
= m_wnd
->x
;
842 if (y
) *y
= m_wnd
->y
;
845 void wxWindowMGL::DoScreenToClient(int *x
, int *y
) const
848 MGL_wmCoordGlobalToLocal(m_wnd
, 0, 0, &ax
, &ay
);
855 void wxWindowMGL::DoClientToScreen(int *x
, int *y
) const
858 MGL_wmCoordLocalToGlobal(m_wnd
, 0, 0, &ax
, &ay
);
865 // Get size *available for subwindows* i.e. excluding menu bar etc.
866 void wxWindowMGL::DoGetClientSize(int *x
, int *y
) const
871 void wxWindowMGL::DoMoveWindow(int x
, int y
, int width
, int height
)
873 MGL_wmSetWindowPosition(GetHandle(), x
, y
, width
, height
);
876 // set the size of the window: if the dimensions are positive, just use them,
877 // but if any of them is equal to -1, it means that we must find the value for
878 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
879 // which case -1 is a valid value for x and y)
881 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
882 // the width/height to best suit our contents, otherwise we reuse the current
884 void wxWindowMGL::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
886 // get the current size and position...
887 int currentX
, currentY
;
888 GetPosition(¤tX
, ¤tY
);
889 int currentW
,currentH
;
890 GetSize(¤tW
, ¤tH
);
892 // ... and don't do anything (avoiding flicker) if it's already ok
893 if ( x
== currentX
&& y
== currentY
&&
894 width
== currentW
&& height
== currentH
)
899 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
901 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
904 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
909 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
911 size
= DoGetBestSize();
916 // just take the current one
923 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
927 size
= DoGetBestSize();
929 //else: already called DoGetBestSize() above
935 // just take the current one
940 DoMoveWindow(x
, y
, width
, height
);
942 wxSizeEvent
event(wxSize(width
, height
), GetId());
943 event
.SetEventObject(this);
944 GetEventHandler()->ProcessEvent(event
);
947 void wxWindowMGL::DoSetClientSize(int width
, int height
)
949 SetSize(width
, height
);
952 // ---------------------------------------------------------------------------
954 // ---------------------------------------------------------------------------
956 int wxWindowMGL::GetCharHeight() const
960 return dc
.GetCharHeight();
963 int wxWindowMGL::GetCharWidth() const
967 return dc
.GetCharWidth();
970 void wxWindowMGL::GetTextExtent(const wxString
& string
,
972 int *descent
, int *externalLeading
,
973 const wxFont
*theFont
) const
978 dc
.GetTextExtent(string
, x
, y
, descent
, externalLeading
, (wxFont
*)theFont
);
981 #if wxUSE_CARET && WXWIN_COMPATIBILITY
982 // ---------------------------------------------------------------------------
983 // Caret manipulation
984 // ---------------------------------------------------------------------------
986 void wxWindowMGL::CreateCaret(int w
, int h
)
988 SetCaret(new wxCaret(this, w
, h
));
991 void wxWindowMGL::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
993 wxFAIL_MSG("not implemented");
996 void wxWindowMGL::ShowCaret(bool show
)
998 wxCHECK_RET( m_caret
, "no caret to show" );
1000 m_caret
->Show(show
);
1003 void wxWindowMGL::DestroyCaret()
1008 void wxWindowMGL::SetCaretPos(int x
, int y
)
1010 wxCHECK_RET( m_caret
, "no caret to move" );
1012 m_caret
->Move(x
, y
);
1015 void wxWindowMGL::GetCaretPos(int *x
, int *y
) const
1017 wxCHECK_RET( m_caret
, "no caret to get position of" );
1019 m_caret
->GetPosition(x
, y
);
1021 #endif // wxUSE_CARET
1024 // ---------------------------------------------------------------------------
1026 // ---------------------------------------------------------------------------
1028 void wxWindowMGL::Clear()
1030 wxClientDC
dc((wxWindow
*)this);
1031 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1032 dc
.SetBackground(brush
);
1036 void wxWindowMGL::Refresh(bool eraseBack
, const wxRect
*rect
)
1038 if ( m_eraseBackground
== -1 )
1039 m_eraseBackground
= eraseBack
;
1041 m_eraseBackground
|= eraseBack
;
1046 r
.left
= rect
->GetLeft(), r
.right
= rect
->GetRight();
1047 r
.top
= rect
->GetTop(), r
.bottom
= rect
->GetBottom();
1048 MGL_wmInvalidateWindowRect(GetHandle(), &r
);
1051 MGL_wmInvalidateWindow(GetHandle());
1054 void wxWindowMGL::Update()
1057 MGL_wmUpdateDC(g_winMng
);
1060 void wxWindowMGL::Freeze()
1063 m_refreshAfterThaw
= FALSE
;
1066 void wxWindowMGL::Thaw()
1069 if ( m_refreshAfterThaw
)
1073 void wxWindowMGL::HandlePaint(MGLDevCtx
*dc
)
1077 // Don't paint anything if the window is frozen.
1078 m_refreshAfterThaw
= TRUE
;
1083 dc
->getClipRegion(clip
);
1084 m_updateRegion
= wxRegion(clip
);
1087 if ( m_eraseBackground
!= 0 )
1089 wxWindowDC
dc((wxWindow
*)this);
1090 wxEraseEvent
eventEr(m_windowId
, &dc
);
1091 eventEr
.SetEventObject(this);
1092 GetEventHandler()->ProcessEvent(eventEr
);
1094 m_eraseBackground
= -1;
1096 wxNcPaintEvent
eventNc(GetId());
1097 eventNc
.SetEventObject(this);
1098 GetEventHandler()->ProcessEvent(eventNc
);
1100 wxPaintEvent
eventPt(GetId());
1101 eventPt
.SetEventObject(this);
1102 GetEventHandler()->ProcessEvent(eventPt
);
1104 m_paintMGLDC
= NULL
;
1105 m_updateRegion
.Clear();
1109 // Find the wxWindow at the current mouse position, returning the mouse
1111 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1113 return wxFindWindowAtPoint(pt
= wxGetMousePosition());
1116 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
1118 window_t
*wnd
= MGL_wmGetWindowAtPosition(g_winMng
, pt
.x
, pt
.y
);
1119 return (wxWindow
*)wnd
->userData
;