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 width
=800, height
=600;
121 if ( wxSystemOptions::HasOption(wxT("mgl.screen-width") )
122 width
= wxSystemOptions::GetOptionInt(wxT("mgl.screen-width"));
123 if ( wxSystemOptions::HasOption(wxT("mgl.screen-height") )
124 height
= wxSystemOptions::GetOptionInt(wxT("mgl.screen-height"));
125 if ( wxSystemOptions::HasOption(wxT("mgl.screen-depth") )
126 depth
= wxSystemOptions::GetOptionInt(wxT("mgl.screen-depth"));
127 if ( wxSystemOptions::HasOption(wxT("mgl.screen-refresh") )
128 refresh
= wxSystemOptions::GetOptionInt(wxT("mgl.screen-refresh"));
131 mode
= MGL_findMode(width
, height
, depth
);
134 wxLogWarning(_("Mode %ix%i-%i not available, falling back to default mode."), width
, height
, depth
);
135 mode
= 0; // always available
137 g_displayDC
= new MGLDisplayDC(mode
, 1, refresh
);
138 if ( !g_displayDC
->isValid() )
145 g_winMng
= MGL_wmCreate(g_displayDC
->getDC());
149 MGL_wmSetWindowPainter(MGL_wmGetRootWindow(g_winMng
), wxDesktopPainter
);
154 void wxDestroyMGL_WM()
158 MGL_wmDestroy(g_winMng
);
168 // Returns toplevel grandparent of given window:
169 static wxWindowMGL
* wxGetTopLevelParent(wxWindowMGL
*win
)
171 wxWindowMGL
*p
= win
;
172 while (p
&& !p
->IsTopLevel())
177 // ---------------------------------------------------------------------------
179 // ---------------------------------------------------------------------------
181 static void wxWindowPainter(window_t
*wnd
, MGLDC
*dc
)
183 wxWindowMGL
*w
= (wxWindow
*) wnd
->userData
;
185 if ( w
&& !(w
->GetWindowStyle() & wxTRANSPARENT_WINDOW
) )
188 w
->HandlePaint(&ctx
);
190 // FIXME_MGL -- root window should be a regular window so that
191 // enter/leave and activate/deactivate events work correctly
194 static ibool
wxWindowMouseHandler(window_t
*wnd
, event_t
*e
)
196 wxWindowMGL
*win
= (wxWindowMGL
*)MGL_wmGetWindowUserData(wnd
);
199 MGL_wmCoordGlobalToLocal(win
->GetHandle(),
200 e
->where_x
, e
->where_y
, &where
.x
, &where
.y
);
202 if ( !win
->IsEnabled() ) return FALSE
;
204 wxEventType type
= wxEVT_NULL
;
206 event
.SetEventObject(win
);
207 event
.SetTimestamp(e
->when
);
210 event
.m_shiftDown
= e
->modifiers
& EVT_SHIFTKEY
;
211 event
.m_controlDown
= e
->modifiers
& EVT_CTRLSTATE
;
212 event
.m_altDown
= e
->modifiers
& EVT_LEFTALT
;
213 event
.m_metaDown
= e
->modifiers
& EVT_RIGHTALT
;
214 event
.m_leftDown
= e
->modifiers
& EVT_LEFTBUT
;
215 event
.m_middleDown
= e
->modifiers
& EVT_MIDDLEBUT
;
216 event
.m_rightDown
= e
->modifiers
& EVT_RIGHTBUT
;
221 if ( e
->message
& EVT_LEFTBMASK
)
222 type
= (e
->message
& EVT_DBLCLICK
) ?
223 wxEVT_LEFT_DCLICK
: wxEVT_LEFT_DOWN
;
224 else if ( e
->message
& EVT_MIDDLEBMASK
)
225 type
= (e
->message
& EVT_DBLCLICK
) ?
226 wxEVT_MIDDLE_DCLICK
: wxEVT_MIDDLE_DOWN
;
227 else if ( e
->message
& EVT_RIGHTBMASK
)
228 type
= (e
->message
& EVT_DBLCLICK
) ?
229 wxEVT_RIGHT_DCLICK
: wxEVT_RIGHT_DOWN
;
233 if ( e
->message
& EVT_LEFTBMASK
)
234 type
= wxEVT_LEFT_UP
;
235 else if ( e
->message
& EVT_MIDDLEBMASK
)
236 type
= wxEVT_MIDDLE_UP
;
237 else if ( e
->message
& EVT_RIGHTBMASK
)
238 type
= wxEVT_RIGHT_UP
;
242 if ( !gs_mouseCapture
)
244 if ( win
!= gs_windowUnderMouse
)
246 if ( gs_windowUnderMouse
)
248 wxMouseEvent
event2(event
);
249 MGL_wmCoordGlobalToLocal(gs_windowUnderMouse
->GetHandle(),
250 e
->where_x
, e
->where_y
,
251 &event2
.m_x
, &event2
.m_y
);
253 event2
.SetEventObject(gs_windowUnderMouse
);
254 event2
.SetEventType(wxEVT_LEAVE_WINDOW
);
255 gs_windowUnderMouse
->GetEventHandler()->ProcessEvent(event2
);
258 wxMouseEvent
event3(event
);
259 event3
.SetEventType(wxEVT_ENTER_WINDOW
);
260 win
->GetEventHandler()->ProcessEvent(event3
);
262 gs_windowUnderMouse
= win
;
265 else // gs_mouseCapture
267 bool inside
= (where
.x
>= 0 &&
269 where
.x
< win
->GetSize().x
&&
270 where
.y
< win
->GetSize().y
);
271 if ( (inside
&& gs_windowUnderMouse
!= win
) ||
272 (!inside
&& gs_windowUnderMouse
== win
) )
274 wxMouseEvent
evt(inside
?
275 wxEVT_ENTER_WINDOW
: wxEVT_LEAVE_WINDOW
);
276 evt
.SetEventObject(win
);
277 win
->GetEventHandler()->ProcessEvent(evt
);
278 gs_windowUnderMouse
= inside
? win
: NULL
;
289 if ( type
== wxEVT_NULL
)
295 event
.SetEventType(type
);
296 return win
->GetEventHandler()->ProcessEvent(event
);
300 static long wxScanToKeyCode(event_t
*event
)
302 #define KEY(mgl,wx) case mgl: key = wx; break;
305 switch ( EVT_scanCode(event
->message
) )
307 KEY (KB_padEnter
, WXK_NUMPAD_ENTER
)
308 KEY (KB_padMinus
, WXK_NUMPAD_SUBTRACT
)
309 KEY (KB_padPlus
, WXK_NUMPAD_ADD
)
310 KEY (KB_padTimes
, WXK_NUMPAD_MULTIPLY
)
311 KEY (KB_padDivide
, WXK_NUMPAD_DIVIDE
)
312 KEY (KB_padLeft
, WXK_NUMPAD_LEFT
)
313 KEY (KB_padRight
, WXK_NUMPAD_RIGHT
)
314 KEY (KB_padUp
, WXK_NUMPAD_UP
)
315 KEY (KB_padDown
, WXK_NUMPAD_DOWN
)
316 KEY (KB_padInsert
, WXK_NUMPAD_INSERT
)
317 KEY (KB_padDelete
, WXK_NUMPAD_DELETE
)
318 KEY (KB_padHome
, WXK_NUMPAD_HOME
)
319 KEY (KB_padEnd
, WXK_NUMPAD_END
)
320 KEY (KB_padPageUp
, WXK_NUMPAD_PAGEUP
)
321 //KEY (KB_padPageUp, WXK_NUMPAD_PRIOR)
322 KEY (KB_padPageDown
, WXK_NUMPAD_PAGEDOWN
)
323 //KEY (KB_padPageDown, WXK_NUMPAD_NEXT)
324 KEY (KB_padCenter
, WXK_NUMPAD_SEPARATOR
) // ?
334 KEY (KB_F10
, WXK_F10
)
335 KEY (KB_F11
, WXK_F11
)
336 KEY (KB_F12
, WXK_F12
)
337 KEY (KB_left
, WXK_LEFT
)
338 KEY (KB_right
, WXK_RIGHT
)
340 KEY (KB_down
, WXK_DOWN
)
341 KEY (KB_insert
, WXK_INSERT
)
342 KEY (KB_delete
, WXK_DELETE
)
343 KEY (KB_home
, WXK_HOME
)
344 KEY (KB_end
, WXK_END
)
345 KEY (KB_pageUp
, WXK_PAGEUP
)
346 KEY (KB_pageDown
, WXK_PAGEDOWN
)
347 KEY (KB_capsLock
, WXK_CAPITAL
)
348 KEY (KB_numLock
, WXK_NUMLOCK
)
349 KEY (KB_scrollLock
, WXK_SCROLL
)
350 KEY (KB_leftShift
, WXK_SHIFT
)
351 KEY (KB_rightShift
, WXK_SHIFT
)
352 KEY (KB_leftCtrl
, WXK_CONTROL
)
353 KEY (KB_rightCtrl
, WXK_CONTROL
)
354 KEY (KB_leftAlt
, WXK_ALT
)
355 KEY (KB_rightAlt
, WXK_ALT
)
356 KEY (KB_leftWindows
, WXK_START
)
357 KEY (KB_rightWindows
, WXK_START
)
358 KEY (KB_menu
, WXK_MENU
)
359 KEY (KB_sysReq
, WXK_SNAPSHOT
)
360 KEY (KB_esc
, WXK_ESCAPE
)
371 KEY (KB_minus
, WXK_SUBTRACT
)
372 KEY (KB_equals
, WXK_ADD
)
373 KEY (KB_backSlash
, '\\')
374 KEY (KB_backspace
, WXK_BACK
)
375 KEY (KB_tab
, WXK_TAB
)
386 KEY (KB_leftSquareBrace
,'[')
387 KEY (KB_rightSquareBrace
,']')
388 KEY (KB_enter
, WXK_RETURN
)
398 KEY (KB_semicolon
, ';')
399 KEY (KB_apostrophe
, '\'')
409 KEY (KB_divide
, WXK_DIVIDE
)
410 KEY (KB_space
, WXK_SPACE
)
414 key
= EVT_asciiCode(event
->message
);
423 static long wxAsciiToKeyCode(event_t
*event
)
425 return (long)EVT_asciiCode(event
->message
);
428 static ibool
wxWindowKeybHandler(window_t
*wnd
, event_t
*e
)
430 wxWindowMGL
*win
= (wxWindowMGL
*)MGL_wmGetWindowUserData(wnd
);
432 if ( !win
->IsEnabled() ) return FALSE
;
435 MGL_wmCoordGlobalToLocal(win
->GetHandle(),
436 e
->where_x
, e
->where_y
, &where
.x
, &where
.y
);
439 event
.SetEventObject(win
);
440 event
.SetTimestamp(e
->when
);
441 event
.m_keyCode
= wxScanToKeyCode(e
);
442 event
.m_scanCode
= 0; // not used by wx at all
445 event
.m_shiftDown
= e
->modifiers
& EVT_SHIFTKEY
;
446 event
.m_controlDown
= e
->modifiers
& EVT_CTRLSTATE
;
447 event
.m_altDown
= e
->modifiers
& EVT_LEFTALT
;
448 event
.m_metaDown
= e
->modifiers
& EVT_RIGHTALT
;
450 if ( e
->what
== EVT_KEYUP
)
452 event
.SetEventType(wxEVT_KEY_UP
);
453 return win
->GetEventHandler()->ProcessEvent(event
);
460 event
.SetEventType(wxEVT_KEY_DOWN
);
463 ret
= win
->GetEventHandler()->ProcessEvent(event
);
468 for (wxWindowMGL
*w
= win
; w
; w
= w
->GetParent())
470 int command
= w
->GetAcceleratorTable()->GetCommand(event
);
473 wxCommandEvent
eventc(wxEVT_COMMAND_MENU_SELECTED
, command
);
474 ret
= w
->GetEventHandler()->ProcessEvent(eventc
);
477 if ( w
->IsTopLevel() )
481 #endif // wxUSE_ACCEL
483 /* wxMSW doesn't send char events with Alt pressed */
484 /* Only send wxEVT_CHAR event if not processed yet. Thus, ALT-x
485 will only be sent if it is not in an accelerator table. */
486 event2
.m_keyCode
= wxAsciiToKeyCode(e
);
487 if ( !ret
&& event2
.m_keyCode
!= 0 )
489 event2
.SetEventType(wxEVT_CHAR
);
490 ret
= win
->GetEventHandler()->ProcessEvent(event2
);
497 // ---------------------------------------------------------------------------
499 // ---------------------------------------------------------------------------
501 // in wxUniv this class is abstract because it doesn't have DoPopupMenu()
502 IMPLEMENT_ABSTRACT_CLASS(wxWindowMGL
, wxWindowBase
)
504 BEGIN_EVENT_TABLE(wxWindowMGL
, wxWindowBase
)
507 // ===========================================================================
509 // ===========================================================================
511 // ----------------------------------------------------------------------------
512 // constructors and such
513 // ----------------------------------------------------------------------------
515 void wxWindowMGL::Init()
523 m_isBeingDeleted
= FALSE
;
527 m_eraseBackground
= -1;
531 wxWindowMGL::~wxWindowMGL()
533 m_isBeingDeleted
= TRUE
;
535 if ( gs_mouseCapture
== this )
538 if (gs_activeFrame
== this)
540 gs_activeFrame
= NULL
;
541 // activate next frame in Z-order:
544 wxWindowMGL
*win
= (wxWindowMGL
*)m_wnd
->prev
->userData
;
549 if ( gs_focusedWindow
== this )
552 if ( gs_windowUnderMouse
== this )
553 gs_windowUnderMouse
= NULL
;
555 // VS: destroy children first and _then_ detach *this from its parent.
556 // If we'd do it the other way around, children wouldn't be able
557 // find their parent frame (see above).
561 m_parent
->RemoveChild(this);
564 MGL_wmDestroyWindow(m_wnd
);
567 // real construction (Init() must have been called before!)
568 bool wxWindowMGL::Create(wxWindow
*parent
,
573 const wxString
& name
)
575 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
579 parent
->AddChild(this);
582 x
= pos
.x
, y
= pos
.y
;
584 x
= 0; // FIXME_MGL, something better, see GTK+
586 y
= 0; // FIXME_MGL, something better, see GTK+
587 w
= WidthDefault(size
.x
);
588 h
= HeightDefault(size
.y
);
591 window_t
*wnd_parent
= parent
? parent
->GetHandle() : NULL
;
593 if ( !(style
& wxNO_FULL_REPAINT_ON_RESIZE
) )
595 mgl_style
|= MGL_WM_FULL_REPAINT_ON_RESIZE
;
597 if ( style
& wxSTAY_ON_TOP
)
599 mgl_style
|= MGL_WM_ALWAYS_ON_TOP
;
601 if ( style
& wxPOPUP_WINDOW
)
603 mgl_style
|= MGL_WM_ALWAYS_ON_TOP
;
604 // it is created hidden as other top level windows
609 m_wnd
= MGL_wmCreateWindow(g_winMng
, wnd_parent
, x
, y
, w
, h
);
611 MGL_wmSetWindowFlags(m_wnd
, mgl_style
);
612 MGL_wmSetWindowUserData(m_wnd
, (void*) this);
613 MGL_wmSetWindowPainter(m_wnd
, wxWindowPainter
);
614 MGL_wmShowWindow(m_wnd
, m_isShown
);
615 MGL_wmSetWindowCursor(m_wnd
, *wxSTANDARD_CURSOR
->GetMGLCursor());
617 MGL_wmPushWindowEventHandler(m_wnd
, wxWindowMouseHandler
, EVT_MOUSEEVT
, 0);
618 MGL_wmPushWindowEventHandler(m_wnd
, wxWindowKeybHandler
, EVT_KEYEVT
, 0);
623 // ---------------------------------------------------------------------------
625 // ---------------------------------------------------------------------------
627 void wxWindowMGL::SetFocus()
629 if ( gs_focusedWindow
== this ) return;
631 if ( gs_focusedWindow
)
632 gs_focusedWindow
->KillFocus();
634 gs_focusedWindow
= this;
636 MGL_wmCaptureEvents(GetHandle(), EVT_KEYEVT
, wxMGL_CAPTURE_KEYB
);
639 // caret needs to be informed about focus change
640 wxCaret
*caret
= GetCaret();
643 #endif // wxUSE_CARET
645 wxWindowMGL
*active
= wxGetTopLevelParent(this);
646 if ( !(m_windowStyle
& wxPOPUP_WINDOW
) && active
!= gs_activeFrame
)
648 if ( gs_activeFrame
)
650 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, gs_activeFrame
->GetId());
651 event
.SetEventObject(gs_activeFrame
);
652 gs_activeFrame
->GetEventHandler()->ProcessEvent(event
);
655 gs_activeFrame
= active
;
656 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, gs_activeFrame
->GetId());
657 event
.SetEventObject(gs_activeFrame
);
658 gs_activeFrame
->GetEventHandler()->ProcessEvent(event
);
661 wxFocusEvent
event(wxEVT_SET_FOCUS
, GetId());
662 event
.SetEventObject(this);
663 GetEventHandler()->ProcessEvent(event
);
666 void wxWindowMGL::KillFocus()
668 if ( gs_focusedWindow
!= this ) return;
669 gs_focusedWindow
= NULL
;
671 if ( m_isBeingDeleted
) return;
673 MGL_wmUncaptureEvents(GetHandle(), wxMGL_CAPTURE_KEYB
);
676 // caret needs to be informed about focus change
677 wxCaret
*caret
= GetCaret();
679 caret
->OnKillFocus();
680 #endif // wxUSE_CARET
682 wxFocusEvent
event(wxEVT_KILL_FOCUS
, GetId());
683 event
.SetEventObject(this);
684 GetEventHandler()->ProcessEvent(event
);
687 // ----------------------------------------------------------------------------
688 // this wxWindowBase function is implemented here (in platform-specific file)
689 // because it is static and so couldn't be made virtual
690 // ----------------------------------------------------------------------------
691 wxWindow
*wxWindowBase::FindFocus()
693 return (wxWindow
*)gs_focusedWindow
;
696 bool wxWindowMGL::Show(bool show
)
698 if ( !wxWindowBase::Show(show
) )
701 MGL_wmShowWindow(m_wnd
, show
);
703 if (!show
&& gs_activeFrame
== this)
705 // activate next frame in Z-order:
708 wxWindowMGL
*win
= (wxWindowMGL
*)m_wnd
->prev
->userData
;
716 // Raise the window to the top of the Z order
717 void wxWindowMGL::Raise()
719 MGL_wmRaiseWindow(m_wnd
);
722 // Lower the window to the bottom of the Z order
723 void wxWindowMGL::Lower()
725 MGL_wmLowerWindow(m_wnd
);
728 void wxWindowMGL::CaptureMouse()
730 if ( gs_mouseCapture
)
731 MGL_wmUncaptureEvents(gs_mouseCapture
->m_wnd
, wxMGL_CAPTURE_MOUSE
);
733 gs_mouseCapture
= this;
734 MGL_wmCaptureEvents(m_wnd
, EVT_MOUSEEVT
, wxMGL_CAPTURE_MOUSE
);
737 void wxWindowMGL::ReleaseMouse()
739 wxASSERT_MSG( gs_mouseCapture
== this, wxT("attempt to release mouse, but this window hasn't captured it") )
741 MGL_wmUncaptureEvents(m_wnd
, wxMGL_CAPTURE_MOUSE
);
742 gs_mouseCapture
= NULL
;
745 /* static */ wxWindow
*wxWindowBase::GetCapture()
747 return (wxWindow
*)gs_mouseCapture
;
750 bool wxWindowMGL::SetCursor(const wxCursor
& cursor
)
752 if ( !wxWindowBase::SetCursor(cursor
) )
759 MGL_wmSetWindowCursor(m_wnd
, *m_cursor
.GetMGLCursor());
761 MGL_wmSetWindowCursor(m_wnd
, *wxSTANDARD_CURSOR
->GetMGLCursor());
766 void wxWindowMGL::WarpPointer(int x
, int y
)
768 ClientToScreen(&x
, &y
);
769 EVT_setMousePos(x
, y
);
772 #if WXWIN_COMPATIBILITY
773 // If nothing defined for this, try the parent.
774 // E.g. we may be a button loaded from a resource, with no callback function
776 void wxWindowMGL::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
778 if ( GetEventHandler()->ProcessEvent(event
) )
781 m_parent
->GetEventHandler()->OnCommand(win
, event
);
783 #endif // WXWIN_COMPATIBILITY_2
785 #if WXWIN_COMPATIBILITY
786 wxObject
* wxWindowMGL::GetChild(int number
) const
788 // Return a pointer to the Nth object in the Panel
789 wxNode
*node
= GetChildren().First();
795 wxObject
*obj
= (wxObject
*)node
->Data();
801 #endif // WXWIN_COMPATIBILITY
803 // Set this window to be the child of 'parent'.
804 bool wxWindowMGL::Reparent(wxWindowBase
*parent
)
806 if ( !wxWindowBase::Reparent(parent
) )
809 MGL_wmReparentWindow(m_wnd
, parent
->GetHandle());
815 // ---------------------------------------------------------------------------
817 // ---------------------------------------------------------------------------
819 #if wxUSE_DRAG_AND_DROP
821 void wxWindowMGL::SetDropTarget(wxDropTarget
*pDropTarget
)
823 if ( m_dropTarget
!= 0 ) {
824 m_dropTarget
->Revoke(m_hWnd
);
828 m_dropTarget
= pDropTarget
;
829 if ( m_dropTarget
!= 0 )
830 m_dropTarget
->Register(m_hWnd
);
833 #endif // wxUSE_DRAG_AND_DROP
835 // old style file-manager drag&drop support: we retain the old-style
836 // DragAcceptFiles in parallel with SetDropTarget.
837 void wxWindowMGL::DragAcceptFiles(bool accept
)
840 HWND hWnd
= GetHwnd();
842 ::DragAcceptFiles(hWnd
, (BOOL
)accept
);
846 // ---------------------------------------------------------------------------
847 // moving and resizing
848 // ---------------------------------------------------------------------------
851 void wxWindowMGL::DoGetSize(int *x
, int *y
) const
853 if (x
) *x
= m_wnd
->width
;
854 if (y
) *y
= m_wnd
->height
;
857 void wxWindowMGL::DoGetPosition(int *x
, int *y
) const
859 if (x
) *x
= m_wnd
->x
;
860 if (y
) *y
= m_wnd
->y
;
863 void wxWindowMGL::DoScreenToClient(int *x
, int *y
) const
866 MGL_wmCoordGlobalToLocal(m_wnd
, 0, 0, &ax
, &ay
);
873 void wxWindowMGL::DoClientToScreen(int *x
, int *y
) const
876 MGL_wmCoordLocalToGlobal(m_wnd
, 0, 0, &ax
, &ay
);
883 // Get size *available for subwindows* i.e. excluding menu bar etc.
884 void wxWindowMGL::DoGetClientSize(int *x
, int *y
) const
889 void wxWindowMGL::DoMoveWindow(int x
, int y
, int width
, int height
)
891 MGL_wmSetWindowPosition(GetHandle(), x
, y
, width
, height
);
894 // set the size of the window: if the dimensions are positive, just use them,
895 // but if any of them is equal to -1, it means that we must find the value for
896 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
897 // which case -1 is a valid value for x and y)
899 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
900 // the width/height to best suit our contents, otherwise we reuse the current
902 void wxWindowMGL::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
904 // get the current size and position...
905 int currentX
, currentY
;
906 GetPosition(¤tX
, ¤tY
);
907 int currentW
,currentH
;
908 GetSize(¤tW
, ¤tH
);
910 // ... and don't do anything (avoiding flicker) if it's already ok
911 if ( x
== currentX
&& y
== currentY
&&
912 width
== currentW
&& height
== currentH
)
917 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
919 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
922 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
927 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
929 size
= DoGetBestSize();
934 // just take the current one
941 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
945 size
= DoGetBestSize();
947 //else: already called DoGetBestSize() above
953 // just take the current one
958 DoMoveWindow(x
, y
, width
, height
);
960 wxSizeEvent
event(wxSize(width
, height
), GetId());
961 event
.SetEventObject(this);
962 GetEventHandler()->ProcessEvent(event
);
965 void wxWindowMGL::DoSetClientSize(int width
, int height
)
967 SetSize(width
, height
);
970 // ---------------------------------------------------------------------------
972 // ---------------------------------------------------------------------------
974 int wxWindowMGL::GetCharHeight() const
978 return dc
.GetCharHeight();
981 int wxWindowMGL::GetCharWidth() const
985 return dc
.GetCharWidth();
988 void wxWindowMGL::GetTextExtent(const wxString
& string
,
990 int *descent
, int *externalLeading
,
991 const wxFont
*theFont
) const
996 dc
.GetTextExtent(string
, x
, y
, descent
, externalLeading
, (wxFont
*)theFont
);
999 #if wxUSE_CARET && WXWIN_COMPATIBILITY
1000 // ---------------------------------------------------------------------------
1001 // Caret manipulation
1002 // ---------------------------------------------------------------------------
1004 void wxWindowMGL::CreateCaret(int w
, int h
)
1006 SetCaret(new wxCaret(this, w
, h
));
1009 void wxWindowMGL::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
1011 wxFAIL_MSG("not implemented");
1014 void wxWindowMGL::ShowCaret(bool show
)
1016 wxCHECK_RET( m_caret
, "no caret to show" );
1018 m_caret
->Show(show
);
1021 void wxWindowMGL::DestroyCaret()
1026 void wxWindowMGL::SetCaretPos(int x
, int y
)
1028 wxCHECK_RET( m_caret
, "no caret to move" );
1030 m_caret
->Move(x
, y
);
1033 void wxWindowMGL::GetCaretPos(int *x
, int *y
) const
1035 wxCHECK_RET( m_caret
, "no caret to get position of" );
1037 m_caret
->GetPosition(x
, y
);
1039 #endif // wxUSE_CARET
1042 // ---------------------------------------------------------------------------
1044 // ---------------------------------------------------------------------------
1046 void wxWindowMGL::Clear()
1048 wxClientDC
dc((wxWindow
*)this);
1049 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1050 dc
.SetBackground(brush
);
1054 #include "wx/menu.h"
1055 void wxWindowMGL::Refresh(bool eraseBack
, const wxRect
*rect
)
1057 if ( m_eraseBackground
== -1 )
1058 m_eraseBackground
= eraseBack
;
1060 m_eraseBackground
|= eraseBack
;
1065 r
.left
= rect
->GetLeft(), r
.right
= rect
->GetRight();
1066 r
.top
= rect
->GetTop(), r
.bottom
= rect
->GetBottom();
1067 MGL_wmInvalidateWindowRect(GetHandle(), &r
);
1070 MGL_wmInvalidateWindow(GetHandle());
1073 void wxWindowMGL::Update()
1076 MGL_wmUpdateDC(g_winMng
);
1079 void wxWindowMGL::Freeze()
1082 m_refreshAfterThaw
= FALSE
;
1085 void wxWindowMGL::Thaw()
1088 if ( m_refreshAfterThaw
)
1092 void wxWindowMGL::HandlePaint(MGLDevCtx
*dc
)
1096 // Don't paint anything if the window is frozen.
1097 m_refreshAfterThaw
= TRUE
;
1102 dc
->getClipRegion(clip
);
1103 m_updateRegion
= wxRegion(clip
);
1106 if ( m_eraseBackground
!= 0 )
1108 wxWindowDC
dc((wxWindow
*)this);
1109 wxEraseEvent
eventEr(m_windowId
, &dc
);
1110 eventEr
.SetEventObject(this);
1111 GetEventHandler()->ProcessEvent(eventEr
);
1113 m_eraseBackground
= -1;
1115 wxNcPaintEvent
eventNc(GetId());
1116 eventNc
.SetEventObject(this);
1117 GetEventHandler()->ProcessEvent(eventNc
);
1119 wxPaintEvent
eventPt(GetId());
1120 eventPt
.SetEventObject(this);
1121 GetEventHandler()->ProcessEvent(eventPt
);
1123 m_paintMGLDC
= NULL
;
1124 m_updateRegion
.Clear();
1128 // Find the wxWindow at the current mouse position, returning the mouse
1130 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1132 return wxFindWindowAtPoint(pt
= wxGetMousePosition());
1135 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
1137 window_t
*wnd
= MGL_wmGetWindowAtPosition(g_winMng
, pt
.x
, pt
.y
);
1138 return (wxWindow
*)wnd
->userData
;