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())
177 // Add an easy way to capture screenshots:
178 static void CaptureScreenshot()
182 static int screenshot_num
= 0;
183 char screenshot
[128];
184 sprintf(screenshot
, "screenshot-%03i.png", screenshot_num
++);
185 g_displayDC
->savePNGFromDC(screenshot
, 0, 0,
186 g_displayDC
->sizex(),
187 g_displayDC
->sizey());
191 // ---------------------------------------------------------------------------
193 // ---------------------------------------------------------------------------
195 static void wxWindowPainter(window_t
*wnd
, MGLDC
*dc
)
197 wxWindowMGL
*w
= (wxWindow
*) wnd
->userData
;
199 if ( w
&& !(w
->GetWindowStyle() & wxTRANSPARENT_WINDOW
) )
202 w
->HandlePaint(&ctx
);
204 // FIXME_MGL -- root window should be a regular window so that
205 // enter/leave and activate/deactivate events work correctly
208 static ibool
wxWindowMouseHandler(window_t
*wnd
, event_t
*e
)
210 wxWindowMGL
*win
= (wxWindowMGL
*)MGL_wmGetWindowUserData(wnd
);
213 MGL_wmCoordGlobalToLocal(win
->GetHandle(),
214 e
->where_x
, e
->where_y
, &where
.x
, &where
.y
);
216 for (wxWindowMGL
*w
= win
; w
; w
= w
->GetParent())
218 if ( !w
->IsEnabled() )
220 if ( w
->IsTopLevel() )
224 wxEventType type
= wxEVT_NULL
;
226 event
.SetEventObject(win
);
227 event
.SetTimestamp(e
->when
);
230 event
.m_shiftDown
= e
->modifiers
& EVT_SHIFTKEY
;
231 event
.m_controlDown
= e
->modifiers
& EVT_CTRLSTATE
;
232 event
.m_altDown
= e
->modifiers
& EVT_LEFTALT
;
233 event
.m_metaDown
= e
->modifiers
& EVT_RIGHTALT
;
234 event
.m_leftDown
= e
->modifiers
& EVT_LEFTBUT
;
235 event
.m_middleDown
= e
->modifiers
& EVT_MIDDLEBUT
;
236 event
.m_rightDown
= e
->modifiers
& EVT_RIGHTBUT
;
241 if ( e
->message
& EVT_LEFTBMASK
)
242 type
= (e
->message
& EVT_DBLCLICK
) ?
243 wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
;
244 else if ( e
->message
& EVT_MIDDLEBMASK
)
245 type
= (e
->message
& EVT_DBLCLICK
) ?
246 wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
;
247 else if ( e
->message
& EVT_RIGHTBMASK
)
248 type
= (e
->message
& EVT_DBLCLICK
) ?
249 wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
;
253 if ( e
->message
& EVT_LEFTBMASK
)
254 type
= wxEVT_LEFT_UP
;
255 else if ( e
->message
& EVT_MIDDLEBMASK
)
256 type
= wxEVT_MIDDLE_UP
;
257 else if ( e
->message
& EVT_RIGHTBMASK
)
258 type
= wxEVT_RIGHT_UP
;
262 if ( !gs_mouseCapture
)
264 if ( win
!= gs_windowUnderMouse
)
266 if ( gs_windowUnderMouse
)
268 wxMouseEvent
event2(event
);
269 MGL_wmCoordGlobalToLocal(gs_windowUnderMouse
->GetHandle(),
270 e
->where_x
, e
->where_y
,
271 &event2
.m_x
, &event2
.m_y
);
273 event2
.SetEventObject(gs_windowUnderMouse
);
274 event2
.SetEventType(wxEVT_LEAVE_WINDOW
);
275 gs_windowUnderMouse
->GetEventHandler()->ProcessEvent(event2
);
278 wxMouseEvent
event3(event
);
279 event3
.SetEventType(wxEVT_ENTER_WINDOW
);
280 win
->GetEventHandler()->ProcessEvent(event3
);
282 gs_windowUnderMouse
= win
;
285 else // gs_mouseCapture
287 bool inside
= (where
.x
>= 0 &&
289 where
.x
< win
->GetSize().x
&&
290 where
.y
< win
->GetSize().y
);
291 if ( (inside
&& gs_windowUnderMouse
!= win
) ||
292 (!inside
&& gs_windowUnderMouse
== win
) )
294 wxMouseEvent
evt(inside
?
295 wxEVT_ENTER_WINDOW
: wxEVT_LEAVE_WINDOW
);
296 evt
.SetEventObject(win
);
297 win
->GetEventHandler()->ProcessEvent(evt
);
298 gs_windowUnderMouse
= inside
? win
: NULL
;
309 if ( type
== wxEVT_NULL
)
315 event
.SetEventType(type
);
316 return win
->GetEventHandler()->ProcessEvent(event
);
320 static long wxScanToKeyCode(event_t
*event
)
322 #define KEY(mgl,wx) case mgl: key = wx; break;
325 switch ( EVT_scanCode(event
->message
) )
327 KEY (KB_padEnter
, WXK_NUMPAD_ENTER
)
328 KEY (KB_padMinus
, WXK_NUMPAD_SUBTRACT
)
329 KEY (KB_padPlus
, WXK_NUMPAD_ADD
)
330 KEY (KB_padTimes
, WXK_NUMPAD_MULTIPLY
)
331 KEY (KB_padDivide
, WXK_NUMPAD_DIVIDE
)
332 KEY (KB_padLeft
, WXK_NUMPAD_LEFT
)
333 KEY (KB_padRight
, WXK_NUMPAD_RIGHT
)
334 KEY (KB_padUp
, WXK_NUMPAD_UP
)
335 KEY (KB_padDown
, WXK_NUMPAD_DOWN
)
336 KEY (KB_padInsert
, WXK_NUMPAD_INSERT
)
337 KEY (KB_padDelete
, WXK_NUMPAD_DELETE
)
338 KEY (KB_padHome
, WXK_NUMPAD_HOME
)
339 KEY (KB_padEnd
, WXK_NUMPAD_END
)
340 KEY (KB_padPageUp
, WXK_NUMPAD_PAGEUP
)
341 //KEY (KB_padPageUp, WXK_NUMPAD_PRIOR)
342 KEY (KB_padPageDown
, WXK_NUMPAD_PAGEDOWN
)
343 //KEY (KB_padPageDown, WXK_NUMPAD_NEXT)
344 KEY (KB_padCenter
, WXK_NUMPAD_SEPARATOR
) // ?
354 KEY (KB_F10
, WXK_F10
)
355 KEY (KB_F11
, WXK_F11
)
356 KEY (KB_F12
, WXK_F12
)
357 KEY (KB_left
, WXK_LEFT
)
358 KEY (KB_right
, WXK_RIGHT
)
360 KEY (KB_down
, WXK_DOWN
)
361 KEY (KB_insert
, WXK_INSERT
)
362 KEY (KB_delete
, WXK_DELETE
)
363 KEY (KB_home
, WXK_HOME
)
364 KEY (KB_end
, WXK_END
)
365 KEY (KB_pageUp
, WXK_PAGEUP
)
366 KEY (KB_pageDown
, WXK_PAGEDOWN
)
367 KEY (KB_capsLock
, WXK_CAPITAL
)
368 KEY (KB_numLock
, WXK_NUMLOCK
)
369 KEY (KB_scrollLock
, WXK_SCROLL
)
370 KEY (KB_leftShift
, WXK_SHIFT
)
371 KEY (KB_rightShift
, WXK_SHIFT
)
372 KEY (KB_leftCtrl
, WXK_CONTROL
)
373 KEY (KB_rightCtrl
, WXK_CONTROL
)
374 KEY (KB_leftAlt
, WXK_ALT
)
375 KEY (KB_rightAlt
, WXK_ALT
)
376 KEY (KB_leftWindows
, WXK_START
)
377 KEY (KB_rightWindows
, WXK_START
)
378 KEY (KB_menu
, WXK_MENU
)
379 KEY (KB_sysReq
, WXK_SNAPSHOT
)
380 KEY (KB_esc
, WXK_ESCAPE
)
391 KEY (KB_minus
, WXK_SUBTRACT
)
392 KEY (KB_equals
, WXK_ADD
)
393 KEY (KB_backSlash
, '\\')
394 KEY (KB_backspace
, WXK_BACK
)
395 KEY (KB_tab
, WXK_TAB
)
406 KEY (KB_leftSquareBrace
,'[')
407 KEY (KB_rightSquareBrace
,']')
408 KEY (KB_enter
, WXK_RETURN
)
418 KEY (KB_semicolon
, ';')
419 KEY (KB_apostrophe
, '\'')
429 KEY (KB_divide
, WXK_DIVIDE
)
430 KEY (KB_space
, WXK_SPACE
)
434 key
= EVT_asciiCode(event
->message
);
443 static long wxAsciiToKeyCode(event_t
*event
)
445 return (long)EVT_asciiCode(event
->message
);
448 static ibool
wxWindowKeybHandler(window_t
*wnd
, event_t
*e
)
450 wxWindowMGL
*win
= (wxWindowMGL
*)MGL_wmGetWindowUserData(wnd
);
452 if ( !win
->IsEnabled() ) return FALSE
;
455 MGL_wmCoordGlobalToLocal(win
->GetHandle(),
456 e
->where_x
, e
->where_y
, &where
.x
, &where
.y
);
459 event
.SetEventObject(win
);
460 event
.SetTimestamp(e
->when
);
461 event
.m_keyCode
= wxScanToKeyCode(e
);
462 event
.m_scanCode
= 0; // not used by wx at all
465 event
.m_shiftDown
= e
->modifiers
& EVT_SHIFTKEY
;
466 event
.m_controlDown
= e
->modifiers
& EVT_CTRLSTATE
;
467 event
.m_altDown
= e
->modifiers
& EVT_LEFTALT
;
468 event
.m_metaDown
= e
->modifiers
& EVT_RIGHTALT
;
470 if ( e
->what
== EVT_KEYUP
)
472 event
.SetEventType(wxEVT_KEY_UP
);
473 return win
->GetEventHandler()->ProcessEvent(event
);
480 event
.SetEventType(wxEVT_KEY_DOWN
);
483 ret
= win
->GetEventHandler()->ProcessEvent(event
);
487 // Add an easy way to capture screenshots:
488 if ( event
.m_keyCode
== WXK_F1
&&
489 event
.m_shiftDown
&& event
.m_controlDown
)
496 for (wxWindowMGL
*w
= win
; w
; w
= w
->GetParent())
498 int command
= w
->GetAcceleratorTable()->GetCommand(event
);
501 wxCommandEvent
eventc(wxEVT_COMMAND_MENU_SELECTED
, command
);
502 ret
= w
->GetEventHandler()->ProcessEvent(eventc
);
505 if ( w
->IsTopLevel() )
509 #endif // wxUSE_ACCEL
511 /* wxMSW doesn't send char events with Alt pressed */
512 /* Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x
513 will only be sent if it is not in an accelerator table. */
514 event2
.m_keyCode
= wxAsciiToKeyCode(e
);
515 if ( !ret
&& event2
.m_keyCode
!= 0 )
517 event2
.SetEventType(wxEVT_CHAR
);
518 ret
= win
->GetEventHandler()->ProcessEvent(event2
);
525 // ---------------------------------------------------------------------------
527 // ---------------------------------------------------------------------------
529 // in wxUniv this class is abstract because it doesn't have DoPopupMenu()
530 IMPLEMENT_ABSTRACT_CLASS(wxWindowMGL
, wxWindowBase
)
532 BEGIN_EVENT_TABLE(wxWindowMGL
, wxWindowBase
)
535 // ===========================================================================
537 // ===========================================================================
539 // ----------------------------------------------------------------------------
540 // constructors and such
541 // ----------------------------------------------------------------------------
543 void wxWindowMGL::Init()
551 m_isBeingDeleted
= FALSE
;
555 m_eraseBackground
= -1;
559 wxWindowMGL::~wxWindowMGL()
561 m_isBeingDeleted
= TRUE
;
563 if ( gs_mouseCapture
== this )
566 if (gs_activeFrame
== this)
568 gs_activeFrame
= NULL
;
569 // activate next frame in Z-order:
572 wxWindowMGL
*win
= (wxWindowMGL
*)m_wnd
->prev
->userData
;
577 if ( gs_focusedWindow
== this )
580 if ( gs_windowUnderMouse
== this )
581 gs_windowUnderMouse
= NULL
;
583 // VS: destroy children first and _then_ detach *this from its parent.
584 // If we'd do it the other way around, children wouldn't be able
585 // find their parent frame (see above).
589 m_parent
->RemoveChild(this);
592 MGL_wmDestroyWindow(m_wnd
);
595 // real construction (Init() must have been called before!)
596 bool wxWindowMGL::Create(wxWindow
*parent
,
601 const wxString
& name
)
603 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
607 parent
->AddChild(this);
610 x
= pos
.x
, y
= pos
.y
;
612 x
= 0; // FIXME_MGL, something better, see GTK+
614 y
= 0; // FIXME_MGL, something better, see GTK+
615 w
= WidthDefault(size
.x
);
616 h
= HeightDefault(size
.y
);
619 window_t
*wnd_parent
= parent
? parent
->GetHandle() : NULL
;
621 if ( !(style
& wxNO_FULL_REPAINT_ON_RESIZE
) )
623 mgl_style
|= MGL_WM_FULL_REPAINT_ON_RESIZE
;
625 if ( style
& wxSTAY_ON_TOP
)
627 mgl_style
|= MGL_WM_ALWAYS_ON_TOP
;
629 if ( style
& wxPOPUP_WINDOW
)
631 mgl_style
|= MGL_WM_ALWAYS_ON_TOP
;
632 // it is created hidden as other top level windows
637 m_wnd
= MGL_wmCreateWindow(g_winMng
, wnd_parent
, x
, y
, w
, h
);
639 MGL_wmSetWindowFlags(m_wnd
, mgl_style
);
640 MGL_wmSetWindowUserData(m_wnd
, (void*) this);
641 MGL_wmSetWindowPainter(m_wnd
, wxWindowPainter
);
642 MGL_wmShowWindow(m_wnd
, m_isShown
);
643 MGL_wmSetWindowCursor(m_wnd
, *wxSTANDARD_CURSOR
->GetMGLCursor());
645 MGL_wmPushWindowEventHandler(m_wnd
, wxWindowMouseHandler
, EVT_MOUSEEVT
, 0);
646 MGL_wmPushWindowEventHandler(m_wnd
, wxWindowKeybHandler
, EVT_KEYEVT
, 0);
651 // ---------------------------------------------------------------------------
653 // ---------------------------------------------------------------------------
655 void wxWindowMGL::SetFocus()
657 if ( gs_focusedWindow
== this ) return;
659 if ( gs_focusedWindow
)
660 gs_focusedWindow
->KillFocus();
662 gs_focusedWindow
= this;
664 MGL_wmCaptureEvents(GetHandle(), EVT_KEYEVT
, wxMGL_CAPTURE_KEYB
);
667 // caret needs to be informed about focus change
668 wxCaret
*caret
= GetCaret();
671 #endif // wxUSE_CARET
673 wxWindowMGL
*active
= wxGetTopLevelParent(this);
674 if ( !(m_windowStyle
& wxPOPUP_WINDOW
) && active
!= gs_activeFrame
)
676 if ( gs_activeFrame
)
678 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, gs_activeFrame
->GetId());
679 event
.SetEventObject(gs_activeFrame
);
680 gs_activeFrame
->GetEventHandler()->ProcessEvent(event
);
683 gs_activeFrame
= active
;
684 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, gs_activeFrame
->GetId());
685 event
.SetEventObject(gs_activeFrame
);
686 gs_activeFrame
->GetEventHandler()->ProcessEvent(event
);
689 wxFocusEvent
event(wxEVT_SET_FOCUS
, GetId());
690 event
.SetEventObject(this);
691 GetEventHandler()->ProcessEvent(event
);
694 void wxWindowMGL::KillFocus()
696 if ( gs_focusedWindow
!= this ) return;
697 gs_focusedWindow
= NULL
;
699 if ( m_isBeingDeleted
) return;
701 MGL_wmUncaptureEvents(GetHandle(), wxMGL_CAPTURE_KEYB
);
704 // caret needs to be informed about focus change
705 wxCaret
*caret
= GetCaret();
707 caret
->OnKillFocus();
708 #endif // wxUSE_CARET
710 wxFocusEvent
event(wxEVT_KILL_FOCUS
, GetId());
711 event
.SetEventObject(this);
712 GetEventHandler()->ProcessEvent(event
);
715 // ----------------------------------------------------------------------------
716 // this wxWindowBase function is implemented here (in platform-specific file)
717 // because it is static and so couldn't be made virtual
718 // ----------------------------------------------------------------------------
719 wxWindow
*wxWindowBase::FindFocus()
721 return (wxWindow
*)gs_focusedWindow
;
724 bool wxWindowMGL::Show(bool show
)
726 if ( !wxWindowBase::Show(show
) )
729 MGL_wmShowWindow(m_wnd
, show
);
731 if (!show
&& gs_activeFrame
== this)
733 // activate next frame in Z-order:
736 wxWindowMGL
*win
= (wxWindowMGL
*)m_wnd
->prev
->userData
;
744 // Raise the window to the top of the Z order
745 void wxWindowMGL::Raise()
747 MGL_wmRaiseWindow(m_wnd
);
750 // Lower the window to the bottom of the Z order
751 void wxWindowMGL::Lower()
753 MGL_wmLowerWindow(m_wnd
);
756 void wxWindowMGL::CaptureMouse()
758 if ( gs_mouseCapture
)
759 MGL_wmUncaptureEvents(gs_mouseCapture
->m_wnd
, wxMGL_CAPTURE_MOUSE
);
761 gs_mouseCapture
= this;
762 MGL_wmCaptureEvents(m_wnd
, EVT_MOUSEEVT
, wxMGL_CAPTURE_MOUSE
);
765 void wxWindowMGL::ReleaseMouse()
767 wxASSERT_MSG( gs_mouseCapture
== this, wxT("attempt to release mouse, but this window hasn't captured it") )
769 MGL_wmUncaptureEvents(m_wnd
, wxMGL_CAPTURE_MOUSE
);
770 gs_mouseCapture
= NULL
;
773 /* static */ wxWindow
*wxWindowBase::GetCapture()
775 return (wxWindow
*)gs_mouseCapture
;
778 bool wxWindowMGL::SetCursor(const wxCursor
& cursor
)
780 if ( !wxWindowBase::SetCursor(cursor
) )
787 MGL_wmSetWindowCursor(m_wnd
, *m_cursor
.GetMGLCursor());
789 MGL_wmSetWindowCursor(m_wnd
, *wxSTANDARD_CURSOR
->GetMGLCursor());
794 void wxWindowMGL::WarpPointer(int x
, int y
)
796 ClientToScreen(&x
, &y
);
797 EVT_setMousePos(x
, y
);
800 #if WXWIN_COMPATIBILITY
801 // If nothing defined for this, try the parent.
802 // E.g. we may be a button loaded from a resource, with no callback function
804 void wxWindowMGL::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
806 if ( GetEventHandler()->ProcessEvent(event
) )
809 m_parent
->GetEventHandler()->OnCommand(win
, event
);
811 #endif // WXWIN_COMPATIBILITY_2
813 #if WXWIN_COMPATIBILITY
814 wxObject
* wxWindowMGL::GetChild(int number
) const
816 // Return a pointer to the Nth object in the Panel
817 wxNode
*node
= GetChildren().First();
823 wxObject
*obj
= (wxObject
*)node
->Data();
829 #endif // WXWIN_COMPATIBILITY
831 // Set this window to be the child of 'parent'.
832 bool wxWindowMGL::Reparent(wxWindowBase
*parent
)
834 if ( !wxWindowBase::Reparent(parent
) )
837 MGL_wmReparentWindow(m_wnd
, parent
->GetHandle());
843 // ---------------------------------------------------------------------------
845 // ---------------------------------------------------------------------------
847 #if wxUSE_DRAG_AND_DROP
849 void wxWindowMGL::SetDropTarget(wxDropTarget
*pDropTarget
)
851 if ( m_dropTarget
!= 0 ) {
852 m_dropTarget
->Revoke(m_hWnd
);
856 m_dropTarget
= pDropTarget
;
857 if ( m_dropTarget
!= 0 )
858 m_dropTarget
->Register(m_hWnd
);
861 #endif // wxUSE_DRAG_AND_DROP
863 // old style file-manager drag&drop support: we retain the old-style
864 // DragAcceptFiles in parallel with SetDropTarget.
865 void wxWindowMGL::DragAcceptFiles(bool accept
)
868 HWND hWnd
= GetHwnd();
870 ::DragAcceptFiles(hWnd
, (BOOL
)accept
);
874 // ---------------------------------------------------------------------------
875 // moving and resizing
876 // ---------------------------------------------------------------------------
879 void wxWindowMGL::DoGetSize(int *x
, int *y
) const
881 if (x
) *x
= m_wnd
->width
;
882 if (y
) *y
= m_wnd
->height
;
885 void wxWindowMGL::DoGetPosition(int *x
, int *y
) const
887 if (x
) *x
= m_wnd
->x
;
888 if (y
) *y
= m_wnd
->y
;
891 void wxWindowMGL::DoScreenToClient(int *x
, int *y
) const
894 MGL_wmCoordGlobalToLocal(m_wnd
, 0, 0, &ax
, &ay
);
901 void wxWindowMGL::DoClientToScreen(int *x
, int *y
) const
904 MGL_wmCoordLocalToGlobal(m_wnd
, 0, 0, &ax
, &ay
);
911 // Get size *available for subwindows* i.e. excluding menu bar etc.
912 void wxWindowMGL::DoGetClientSize(int *x
, int *y
) const
917 void wxWindowMGL::DoMoveWindow(int x
, int y
, int width
, int height
)
919 MGL_wmSetWindowPosition(GetHandle(), x
, y
, width
, height
);
922 // set the size of the window: if the dimensions are positive, just use them,
923 // but if any of them is equal to -1, it means that we must find the value for
924 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
925 // which case -1 is a valid value for x and y)
927 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
928 // the width/height to best suit our contents, otherwise we reuse the current
930 void wxWindowMGL::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
932 // get the current size and position...
933 int currentX
, currentY
;
934 GetPosition(¤tX
, ¤tY
);
935 int currentW
,currentH
;
936 GetSize(¤tW
, ¤tH
);
938 // ... and don't do anything (avoiding flicker) if it's already ok
939 if ( x
== currentX
&& y
== currentY
&&
940 width
== currentW
&& height
== currentH
)
945 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
947 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
950 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
955 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
957 size
= DoGetBestSize();
962 // just take the current one
969 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
973 size
= DoGetBestSize();
975 //else: already called DoGetBestSize() above
981 // just take the current one
986 DoMoveWindow(x
, y
, width
, height
);
988 wxSizeEvent
event(wxSize(width
, height
), GetId());
989 event
.SetEventObject(this);
990 GetEventHandler()->ProcessEvent(event
);
993 void wxWindowMGL::DoSetClientSize(int width
, int height
)
995 SetSize(width
, height
);
998 // ---------------------------------------------------------------------------
1000 // ---------------------------------------------------------------------------
1002 int wxWindowMGL::GetCharHeight() const
1006 return dc
.GetCharHeight();
1009 int wxWindowMGL::GetCharWidth() const
1013 return dc
.GetCharWidth();
1016 void wxWindowMGL::GetTextExtent(const wxString
& string
,
1018 int *descent
, int *externalLeading
,
1019 const wxFont
*theFont
) const
1024 dc
.GetTextExtent(string
, x
, y
, descent
, externalLeading
, (wxFont
*)theFont
);
1027 #if wxUSE_CARET && WXWIN_COMPATIBILITY
1028 // ---------------------------------------------------------------------------
1029 // Caret manipulation
1030 // ---------------------------------------------------------------------------
1032 void wxWindowMGL::CreateCaret(int w
, int h
)
1034 SetCaret(new wxCaret(this, w
, h
));
1037 void wxWindowMGL::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
1039 wxFAIL_MSG("not implemented");
1042 void wxWindowMGL::ShowCaret(bool show
)
1044 wxCHECK_RET( m_caret
, "no caret to show" );
1046 m_caret
->Show(show
);
1049 void wxWindowMGL::DestroyCaret()
1054 void wxWindowMGL::SetCaretPos(int x
, int y
)
1056 wxCHECK_RET( m_caret
, "no caret to move" );
1058 m_caret
->Move(x
, y
);
1061 void wxWindowMGL::GetCaretPos(int *x
, int *y
) const
1063 wxCHECK_RET( m_caret
, "no caret to get position of" );
1065 m_caret
->GetPosition(x
, y
);
1067 #endif // wxUSE_CARET
1070 // ---------------------------------------------------------------------------
1072 // ---------------------------------------------------------------------------
1074 void wxWindowMGL::Clear()
1076 wxClientDC
dc((wxWindow
*)this);
1077 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1078 dc
.SetBackground(brush
);
1082 #include "wx/menu.h"
1083 void wxWindowMGL::Refresh(bool eraseBack
, const wxRect
*rect
)
1085 if ( m_eraseBackground
== -1 )
1086 m_eraseBackground
= eraseBack
;
1088 m_eraseBackground
|= eraseBack
;
1093 r
.left
= rect
->GetLeft(), r
.right
= rect
->GetRight();
1094 r
.top
= rect
->GetTop(), r
.bottom
= rect
->GetBottom();
1095 MGL_wmInvalidateWindowRect(GetHandle(), &r
);
1098 MGL_wmInvalidateWindow(GetHandle());
1101 void wxWindowMGL::Update()
1104 MGL_wmUpdateDC(g_winMng
);
1107 void wxWindowMGL::Freeze()
1110 m_refreshAfterThaw
= FALSE
;
1113 void wxWindowMGL::Thaw()
1116 if ( m_refreshAfterThaw
)
1120 void wxWindowMGL::HandlePaint(MGLDevCtx
*dc
)
1124 // Don't paint anything if the window is frozen.
1125 m_refreshAfterThaw
= TRUE
;
1129 #if 0 // FIXME_MGL -- debugging stuff!
1130 dc
->setColorRGB(255,0,255);
1131 dc
->fillRect(-1000,-1000,2000,2000);
1136 dc
->getClipRegion(clip
);
1137 m_updateRegion
= wxRegion(clip
);
1140 if ( m_eraseBackground
!= 0 )
1142 wxWindowDC
dc((wxWindow
*)this);
1143 wxEraseEvent
eventEr(m_windowId
, &dc
);
1144 eventEr
.SetEventObject(this);
1145 GetEventHandler()->ProcessEvent(eventEr
);
1147 m_eraseBackground
= -1;
1149 wxNcPaintEvent
eventNc(GetId());
1150 eventNc
.SetEventObject(this);
1151 GetEventHandler()->ProcessEvent(eventNc
);
1153 wxPaintEvent
eventPt(GetId());
1154 eventPt
.SetEventObject(this);
1155 GetEventHandler()->ProcessEvent(eventPt
);
1157 m_paintMGLDC
= NULL
;
1158 m_updateRegion
.Clear();
1162 // Find the wxWindow at the current mouse position, returning the mouse
1164 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1166 return wxFindWindowAtPoint(pt
= wxGetMousePosition());
1169 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
1171 window_t
*wnd
= MGL_wmGetWindowAtPosition(g_winMng
, pt
.x
, pt
.y
);
1172 return (wxWindow
*)wnd
->userData
;