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 )
536 if (gs_activeFrame
== this)
538 gs_activeFrame
= NULL
;
539 // activate next frame in Z-order:
542 wxWindowMGL
*win
= (wxWindowMGL
*)m_wnd
->prev
->userData
;
547 if ( gs_focusedWindow
== this )
550 if ( gs_windowUnderMouse
== this )
551 gs_windowUnderMouse
= NULL
;
553 // VS: destroy children first and _then_ detach *this from its parent.
554 // If we'd do it the other way around, children wouldn't be able
555 // find their parent frame (see above).
559 m_parent
->RemoveChild(this);
562 MGL_wmDestroyWindow(m_wnd
);
565 // real construction (Init() must have been called before!)
566 bool wxWindowMGL::Create(wxWindow
*parent
,
571 const wxString
& name
)
573 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
577 parent
->AddChild(this);
580 x
= pos
.x
, y
= pos
.y
;
582 x
= 0; // FIXME_MGL, something better, see GTK+
584 y
= 0; // FIXME_MGL, something better, see GTK+
585 w
= WidthDefault(size
.x
);
586 h
= HeightDefault(size
.y
);
589 window_t
*wnd_parent
= parent
? parent
->GetHandle() : NULL
;
591 if ( !(style
& wxNO_FULL_REPAINT_ON_RESIZE
) )
593 mgl_style
|= MGL_WM_FULL_REPAINT_ON_RESIZE
;
595 if ( style
& wxSTAY_ON_TOP
)
597 mgl_style
|= MGL_WM_ALWAYS_ON_TOP
;
599 if ( style
& wxPOPUP_WINDOW
)
601 mgl_style
|= MGL_WM_ALWAYS_ON_TOP
;
602 // it is created hidden as other top level windows
607 m_wnd
= MGL_wmCreateWindow(g_winMng
, wnd_parent
, x
, y
, w
, h
);
609 MGL_wmSetWindowFlags(m_wnd
, mgl_style
);
610 MGL_wmSetWindowUserData(m_wnd
, (void*) this);
611 MGL_wmSetWindowPainter(m_wnd
, wxWindowPainter
);
612 MGL_wmShowWindow(m_wnd
, m_isShown
);
613 MGL_wmSetWindowCursor(m_wnd
, *wxSTANDARD_CURSOR
->GetMGLCursor());
615 MGL_wmPushWindowEventHandler(m_wnd
, wxWindowMouseHandler
, EVT_MOUSEEVT
, 0);
616 MGL_wmPushWindowEventHandler(m_wnd
, wxWindowKeybHandler
, EVT_KEYEVT
, 0);
621 // ---------------------------------------------------------------------------
623 // ---------------------------------------------------------------------------
625 void wxWindowMGL::SetFocus()
627 if ( gs_focusedWindow
)
628 gs_focusedWindow
->KillFocus();
630 gs_focusedWindow
= this;
632 MGL_wmCaptureEvents(GetHandle(), EVT_KEYEVT
, wxMGL_CAPTURE_KEYB
);
635 // caret needs to be informed about focus change
636 wxCaret
*caret
= GetCaret();
639 #endif // wxUSE_CARET
641 wxWindowMGL
*active
= wxGetTopLevelParent(this);
642 if ( active
!= gs_activeFrame
)
644 if ( gs_activeFrame
)
646 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, gs_activeFrame
->GetId());
647 event
.SetEventObject(gs_activeFrame
);
648 gs_activeFrame
->GetEventHandler()->ProcessEvent(event
);
651 gs_activeFrame
= active
;
652 wxActivateEvent
event(wxEVT_ACTIVATE
, TRUE
, gs_activeFrame
->GetId());
653 event
.SetEventObject(gs_activeFrame
);
654 gs_activeFrame
->GetEventHandler()->ProcessEvent(event
);
657 wxFocusEvent
event(wxEVT_SET_FOCUS
, GetId());
658 event
.SetEventObject(this);
659 GetEventHandler()->ProcessEvent(event
);
662 void wxWindowMGL::KillFocus()
664 if ( gs_focusedWindow
!= this ) return;
665 gs_focusedWindow
= NULL
;
667 if ( m_isBeingDeleted
) return;
669 MGL_wmUncaptureEvents(GetHandle(), wxMGL_CAPTURE_KEYB
);
672 // caret needs to be informed about focus change
673 wxCaret
*caret
= GetCaret();
675 caret
->OnKillFocus();
676 #endif // wxUSE_CARET
680 // FIXME_MGL - this is wrong, see wxGTK!
681 wxActivateEvent
event(wxEVT_ACTIVATE
, FALSE
, GetId());
682 event
.SetEventObject(this);
683 GetEventHandler()->ProcessEvent(event
);
686 wxFocusEvent
event(wxEVT_KILL_FOCUS
, GetId());
687 event
.SetEventObject(this);
688 GetEventHandler()->ProcessEvent(event
);
691 // ----------------------------------------------------------------------------
692 // this wxWindowBase function is implemented here (in platform-specific file)
693 // because it is static and so couldn't be made virtual
694 // ----------------------------------------------------------------------------
695 wxWindow
*wxWindowBase::FindFocus()
697 return (wxWindow
*)gs_focusedWindow
;
700 bool wxWindowMGL::Show(bool show
)
702 if ( !wxWindowBase::Show(show
) )
705 MGL_wmShowWindow(m_wnd
, show
);
709 // Raise the window to the top of the Z order
710 void wxWindowMGL::Raise()
712 MGL_wmRaiseWindow(m_wnd
);
715 // Lower the window to the bottom of the Z order
716 void wxWindowMGL::Lower()
718 MGL_wmLowerWindow(m_wnd
);
721 void wxWindowMGL::CaptureMouse()
723 if ( gs_mouseCapture
)
724 MGL_wmUncaptureEvents(gs_mouseCapture
->m_wnd
, wxMGL_CAPTURE_MOUSE
);
726 gs_mouseCapture
= this;
727 MGL_wmCaptureEvents(m_wnd
, EVT_MOUSEEVT
, wxMGL_CAPTURE_MOUSE
);
730 void wxWindowMGL::ReleaseMouse()
732 wxASSERT_MSG( gs_mouseCapture
== this, wxT("attempt to release mouse, but this window hasn't captured it") )
734 MGL_wmUncaptureEvents(m_wnd
, wxMGL_CAPTURE_MOUSE
);
735 gs_mouseCapture
= NULL
;
738 /* static */ wxWindow
*wxWindowBase::GetCapture()
740 return (wxWindow
*)gs_mouseCapture
;
743 bool wxWindowMGL::SetCursor(const wxCursor
& cursor
)
745 if ( !wxWindowBase::SetCursor(cursor
) )
752 MGL_wmSetWindowCursor(m_wnd
, *m_cursor
.GetMGLCursor());
754 MGL_wmSetWindowCursor(m_wnd
, *wxSTANDARD_CURSOR
->GetMGLCursor());
759 void wxWindowMGL::WarpPointer(int x
, int y
)
761 ClientToScreen(&x
, &y
);
762 EVT_setMousePos(x
, y
);
765 #if WXWIN_COMPATIBILITY
766 // If nothing defined for this, try the parent.
767 // E.g. we may be a button loaded from a resource, with no callback function
769 void wxWindowMGL::OnCommand(wxWindow
& win
, wxCommandEvent
& event
)
771 if ( GetEventHandler()->ProcessEvent(event
) )
774 m_parent
->GetEventHandler()->OnCommand(win
, event
);
776 #endif // WXWIN_COMPATIBILITY_2
778 #if WXWIN_COMPATIBILITY
779 wxObject
* wxWindowMGL::GetChild(int number
) const
781 // Return a pointer to the Nth object in the Panel
782 wxNode
*node
= GetChildren().First();
788 wxObject
*obj
= (wxObject
*)node
->Data();
794 #endif // WXWIN_COMPATIBILITY
796 // Set this window to be the child of 'parent'.
797 bool wxWindowMGL::Reparent(wxWindowBase
*parent
)
799 if ( !wxWindowBase::Reparent(parent
) )
802 MGL_wmReparentWindow(m_wnd
, parent
->GetHandle());
808 // ---------------------------------------------------------------------------
810 // ---------------------------------------------------------------------------
812 #if wxUSE_DRAG_AND_DROP
814 void wxWindowMGL::SetDropTarget(wxDropTarget
*pDropTarget
)
816 if ( m_dropTarget
!= 0 ) {
817 m_dropTarget
->Revoke(m_hWnd
);
821 m_dropTarget
= pDropTarget
;
822 if ( m_dropTarget
!= 0 )
823 m_dropTarget
->Register(m_hWnd
);
826 #endif // wxUSE_DRAG_AND_DROP
828 // old style file-manager drag&drop support: we retain the old-style
829 // DragAcceptFiles in parallel with SetDropTarget.
830 void wxWindowMGL::DragAcceptFiles(bool accept
)
833 HWND hWnd
= GetHwnd();
835 ::DragAcceptFiles(hWnd
, (BOOL
)accept
);
839 // ---------------------------------------------------------------------------
840 // moving and resizing
841 // ---------------------------------------------------------------------------
844 void wxWindowMGL::DoGetSize(int *x
, int *y
) const
846 if (x
) *x
= m_wnd
->width
;
847 if (y
) *y
= m_wnd
->height
;
850 void wxWindowMGL::DoGetPosition(int *x
, int *y
) const
852 if (x
) *x
= m_wnd
->x
;
853 if (y
) *y
= m_wnd
->y
;
856 void wxWindowMGL::DoScreenToClient(int *x
, int *y
) const
859 MGL_wmCoordGlobalToLocal(m_wnd
, 0, 0, &ax
, &ay
);
866 void wxWindowMGL::DoClientToScreen(int *x
, int *y
) const
869 MGL_wmCoordLocalToGlobal(m_wnd
, 0, 0, &ax
, &ay
);
876 // Get size *available for subwindows* i.e. excluding menu bar etc.
877 void wxWindowMGL::DoGetClientSize(int *x
, int *y
) const
882 void wxWindowMGL::DoMoveWindow(int x
, int y
, int width
, int height
)
884 MGL_wmSetWindowPosition(GetHandle(), x
, y
, width
, height
);
887 // set the size of the window: if the dimensions are positive, just use them,
888 // but if any of them is equal to -1, it means that we must find the value for
889 // it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
890 // which case -1 is a valid value for x and y)
892 // If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
893 // the width/height to best suit our contents, otherwise we reuse the current
895 void wxWindowMGL::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
897 // get the current size and position...
898 int currentX
, currentY
;
899 GetPosition(¤tX
, ¤tY
);
900 int currentW
,currentH
;
901 GetSize(¤tW
, ¤tH
);
903 // ... and don't do anything (avoiding flicker) if it's already ok
904 if ( x
== currentX
&& y
== currentY
&&
905 width
== currentW
&& height
== currentH
)
910 if ( x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
912 if ( y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
) )
915 AdjustForParentClientOrigin(x
, y
, sizeFlags
);
920 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
922 size
= DoGetBestSize();
927 // just take the current one
934 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
938 size
= DoGetBestSize();
940 //else: already called DoGetBestSize() above
946 // just take the current one
951 DoMoveWindow(x
, y
, width
, height
);
953 wxSizeEvent
event(wxSize(width
, height
), GetId());
954 event
.SetEventObject(this);
955 GetEventHandler()->ProcessEvent(event
);
958 void wxWindowMGL::DoSetClientSize(int width
, int height
)
960 SetSize(width
, height
);
963 // ---------------------------------------------------------------------------
965 // ---------------------------------------------------------------------------
967 int wxWindowMGL::GetCharHeight() const
971 return dc
.GetCharHeight();
974 int wxWindowMGL::GetCharWidth() const
978 return dc
.GetCharWidth();
981 void wxWindowMGL::GetTextExtent(const wxString
& string
,
983 int *descent
, int *externalLeading
,
984 const wxFont
*theFont
) const
989 dc
.GetTextExtent(string
, x
, y
, descent
, externalLeading
, (wxFont
*)theFont
);
992 #if wxUSE_CARET && WXWIN_COMPATIBILITY
993 // ---------------------------------------------------------------------------
994 // Caret manipulation
995 // ---------------------------------------------------------------------------
997 void wxWindowMGL::CreateCaret(int w
, int h
)
999 SetCaret(new wxCaret(this, w
, h
));
1002 void wxWindowMGL::CreateCaret(const wxBitmap
*WXUNUSED(bitmap
))
1004 wxFAIL_MSG("not implemented");
1007 void wxWindowMGL::ShowCaret(bool show
)
1009 wxCHECK_RET( m_caret
, "no caret to show" );
1011 m_caret
->Show(show
);
1014 void wxWindowMGL::DestroyCaret()
1019 void wxWindowMGL::SetCaretPos(int x
, int y
)
1021 wxCHECK_RET( m_caret
, "no caret to move" );
1023 m_caret
->Move(x
, y
);
1026 void wxWindowMGL::GetCaretPos(int *x
, int *y
) const
1028 wxCHECK_RET( m_caret
, "no caret to get position of" );
1030 m_caret
->GetPosition(x
, y
);
1032 #endif // wxUSE_CARET
1035 // ---------------------------------------------------------------------------
1037 // ---------------------------------------------------------------------------
1039 void wxWindowMGL::Clear()
1041 wxClientDC
dc((wxWindow
*)this);
1042 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1043 dc
.SetBackground(brush
);
1047 void wxWindowMGL::Refresh(bool eraseBack
, const wxRect
*rect
)
1049 if ( m_eraseBackground
== -1 )
1050 m_eraseBackground
= eraseBack
;
1052 m_eraseBackground
|= eraseBack
;
1057 r
.left
= rect
->GetLeft(), r
.right
= rect
->GetRight();
1058 r
.top
= rect
->GetTop(), r
.bottom
= rect
->GetBottom();
1059 MGL_wmInvalidateWindowRect(GetHandle(), &r
);
1062 MGL_wmInvalidateWindow(GetHandle());
1065 void wxWindowMGL::Update()
1068 MGL_wmUpdateDC(g_winMng
);
1071 void wxWindowMGL::Freeze()
1074 m_refreshAfterThaw
= FALSE
;
1077 void wxWindowMGL::Thaw()
1080 if ( m_refreshAfterThaw
)
1084 void wxWindowMGL::HandlePaint(MGLDevCtx
*dc
)
1088 // Don't paint anything if the window is frozen.
1089 m_refreshAfterThaw
= TRUE
;
1094 dc
->getClipRegion(clip
);
1095 m_updateRegion
= wxRegion(clip
);
1098 if ( m_eraseBackground
!= 0 )
1100 wxWindowDC
dc((wxWindow
*)this);
1101 wxEraseEvent
eventEr(m_windowId
, &dc
);
1102 eventEr
.SetEventObject(this);
1103 GetEventHandler()->ProcessEvent(eventEr
);
1105 m_eraseBackground
= -1;
1107 wxNcPaintEvent
eventNc(GetId());
1108 eventNc
.SetEventObject(this);
1109 GetEventHandler()->ProcessEvent(eventNc
);
1111 wxPaintEvent
eventPt(GetId());
1112 eventPt
.SetEventObject(this);
1113 GetEventHandler()->ProcessEvent(eventPt
);
1115 m_paintMGLDC
= NULL
;
1116 m_updateRegion
.Clear();
1120 // Find the wxWindow at the current mouse position, returning the mouse
1122 wxWindow
* wxFindWindowAtPointer(wxPoint
& pt
)
1124 return wxFindWindowAtPoint(pt
= wxGetMousePosition());
1127 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
1129 window_t
*wnd
= MGL_wmGetWindowAtPosition(g_winMng
, pt
.x
, pt
.y
);
1130 return (wxWindow
*)wnd
->userData
;