1 /////////////////////////////////////////////////////////////////////////////
2 // Name: common/window.cpp
3 // Purpose: common (to all ports) wxWindow functions
4 // Author: Julian Smart, Vadim Zeitlin
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "windowbase.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
32 #include "wx/string.h"
37 #include "wx/window.h"
38 #include "wx/control.h"
39 #include "wx/checkbox.h"
40 #include "wx/radiobut.h"
41 #include "wx/textctrl.h"
42 #include "wx/settings.h"
43 #include "wx/dialog.h"
44 #include "wx/msgdlg.h"
45 #include "wx/statusbr.h"
49 #include "wx/layout.h"
50 #endif // wxUSE_CONSTRAINTS
54 #if wxUSE_DRAG_AND_DROP
56 #endif // wxUSE_DRAG_AND_DROP
59 #include "wx/cshelp.h"
63 #include "wx/tooltip.h"
64 #endif // wxUSE_TOOLTIPS
70 // ----------------------------------------------------------------------------
72 // ----------------------------------------------------------------------------
75 int wxWindowBase::ms_lastControlId
= 2000;
77 int wxWindowBase::ms_lastControlId
= -200;
80 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
82 // ----------------------------------------------------------------------------
84 // ----------------------------------------------------------------------------
86 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
87 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
88 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
89 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick
)
92 EVT_HELP(-1, wxWindowBase::OnHelp
)
97 // ============================================================================
98 // implementation of the common functionality of the wxWindow class
99 // ============================================================================
101 // ----------------------------------------------------------------------------
103 // ----------------------------------------------------------------------------
105 // the default initialization
106 void wxWindowBase::InitBase()
108 // no window yet, no parent nor children
109 m_parent
= (wxWindow
*)NULL
;
111 m_children
.DeleteContents( FALSE
); // don't auto delete node data
113 // no constraints on the minimal window size
119 // window is created enabled but it's not visible yet
123 // the default event handler is just this window
124 m_eventHandler
= this;
128 m_windowValidator
= (wxValidator
*) NULL
;
129 #endif // wxUSE_VALIDATORS
131 // use the system default colours
132 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
133 m_foregroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
135 // don't set the font here for wxMSW as we don't call WM_SETFONT here and
136 // so the font is *not* really set - but calls to SetFont() later won't do
137 // anything because m_font appears to be already set!
139 m_font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
142 // the colours/fonts are default for now
151 // an optimization for the event processing: checking this flag is much
152 // faster than using IsKindOf(CLASSINFO(wxWindow))
155 #if wxUSE_CONSTRAINTS
156 // no constraints whatsoever
157 m_constraints
= (wxLayoutConstraints
*) NULL
;
158 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
159 #endif // wxUSE_CONSTRAINTS
161 m_windowSizer
= (wxSizer
*) NULL
;
162 m_containingSizer
= (wxSizer
*) NULL
;
163 m_autoLayout
= FALSE
;
165 #if wxUSE_DRAG_AND_DROP
166 m_dropTarget
= (wxDropTarget
*)NULL
;
167 #endif // wxUSE_DRAG_AND_DROP
170 m_tooltip
= (wxToolTip
*)NULL
;
171 #endif // wxUSE_TOOLTIPS
174 m_caret
= (wxCaret
*)NULL
;
175 #endif // wxUSE_CARET
178 m_hasCustomPalette
= FALSE
;
179 #endif // wxUSE_PALETTE
181 m_virtualSize
= wxDefaultSize
;
186 m_maxVirtualHeight
= -1;
188 // Whether we're using the current theme for this window (wxGTK only for now)
189 m_themeEnabled
= FALSE
;
192 // common part of window creation process
193 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
195 const wxPoint
& WXUNUSED(pos
),
196 const wxSize
& WXUNUSED(size
),
198 const wxValidator
& validator
,
199 const wxString
& name
)
201 // m_isWindow is set to TRUE in wxWindowBase::Init() as well as many other
202 // member variables - check that it has been called (will catch the case
203 // when a new ctor is added which doesn't call InitWindow)
204 wxASSERT_MSG( m_isWindow
, wxT("Init() must have been called before!") );
206 // generate a new id if the user doesn't care about it
207 m_windowId
= id
== -1 ? NewControlId() : id
;
210 SetWindowStyleFlag(style
);
214 SetValidator(validator
);
215 #endif // wxUSE_VALIDATORS
217 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
218 // have it too - like this it's possible to set it only in the top level
219 // dialog/frame and all children will inherit it by defult
220 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
222 SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY
);
228 // ----------------------------------------------------------------------------
230 // ----------------------------------------------------------------------------
233 wxWindowBase::~wxWindowBase()
235 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
237 // FIXME if these 2 cases result from programming errors in the user code
238 // we should probably assert here instead of silently fixing them
240 // Just in case the window has been Closed, but we're then deleting
241 // immediately: don't leave dangling pointers.
242 wxPendingDelete
.DeleteObject(this);
244 // Just in case we've loaded a top-level window via LoadNativeDialog but
245 // we weren't a dialog class
246 wxTopLevelWindows
.DeleteObject(this);
248 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
253 #endif // wxUSE_CARET
256 if ( m_windowValidator
)
257 delete m_windowValidator
;
258 #endif // wxUSE_VALIDATORS
260 #if wxUSE_CONSTRAINTS
261 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
262 // at deleted windows as they delete themselves.
263 DeleteRelatedConstraints();
267 // This removes any dangling pointers to this window in other windows'
268 // constraintsInvolvedIn lists.
269 UnsetConstraints(m_constraints
);
270 delete m_constraints
;
271 m_constraints
= NULL
;
274 #endif // wxUSE_CONSTRAINTS
276 if ( m_containingSizer
)
277 m_containingSizer
->Remove((wxWindow
*)this);
280 delete m_windowSizer
;
282 #if wxUSE_DRAG_AND_DROP
285 #endif // wxUSE_DRAG_AND_DROP
290 #endif // wxUSE_TOOLTIPS
292 // reset the dangling pointer our parent window may keep to us
293 if ( m_parent
&& m_parent
->GetDefaultItem() == this )
295 m_parent
->SetDefaultItem(NULL
);
299 bool wxWindowBase::Destroy()
306 bool wxWindowBase::Close(bool force
)
308 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
309 event
.SetEventObject(this);
310 #if WXWIN_COMPATIBILITY
311 event
.SetForce(force
);
312 #endif // WXWIN_COMPATIBILITY
313 event
.SetCanVeto(!force
);
315 // return FALSE if window wasn't closed because the application vetoed the
317 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
320 bool wxWindowBase::DestroyChildren()
322 wxWindowList::Node
*node
;
325 // we iterate until the list becomes empty
326 node
= GetChildren().GetFirst();
330 wxWindow
*child
= node
->GetData();
332 wxASSERT_MSG( child
, wxT("children list contains empty nodes") );
337 wxASSERT_MSG( !GetChildren().Find(child
),
338 wxT("child didn't remove itself using RemoveChild()") );
344 // ----------------------------------------------------------------------------
345 // size/position related methods
346 // ----------------------------------------------------------------------------
348 // centre the window with respect to its parent in either (or both) directions
349 void wxWindowBase::Centre(int direction
)
351 // the position/size of the parent window or of the entire screen
353 int widthParent
, heightParent
;
355 wxWindow
*parent
= NULL
;
357 if ( !(direction
& wxCENTRE_ON_SCREEN
) )
359 // find the parent to centre this window on: it should be the
360 // immediate parent for the controls but the top level parent for the
361 // top level windows (like dialogs)
362 parent
= GetParent();
365 while ( parent
&& !parent
->IsTopLevel() )
367 parent
= parent
->GetParent();
371 // there is no wxTopLevelWindow under wxMotif yet
373 // we shouldn't center the dialog on the iconized window: under
374 // Windows, for example, this places it completely off the screen
377 wxTopLevelWindow
*winTop
= wxDynamicCast(parent
, wxTopLevelWindow
);
378 if ( winTop
&& winTop
->IsIconized() )
383 #endif // __WXMOTIF__
385 // did we find the parent?
389 direction
|= wxCENTRE_ON_SCREEN
;
393 if ( direction
& wxCENTRE_ON_SCREEN
)
395 // centre with respect to the whole screen
396 wxDisplaySize(&widthParent
, &heightParent
);
402 // centre on the parent
403 parent
->GetSize(&widthParent
, &heightParent
);
405 // adjust to the parents position
406 posParent
= parent
->GetPosition();
410 // centre inside the parents client rectangle
411 parent
->GetClientSize(&widthParent
, &heightParent
);
416 GetSize(&width
, &height
);
421 if ( direction
& wxHORIZONTAL
)
422 xNew
= (widthParent
- width
)/2;
424 if ( direction
& wxVERTICAL
)
425 yNew
= (heightParent
- height
)/2;
430 // Base size of the visible dimensions of the display
431 // to take into account the taskbar
432 wxRect rect
= wxGetClientDisplayRect();
433 wxSize
size (rect
.width
,rect
.height
);
435 // NB: in wxMSW, negative position may not neccessary mean "out of screen",
436 // but it may mean that the window is placed on other than the main
437 // display. Therefore we only make sure centered window is on the main display
438 // if the parent is at least partially present here.
439 if (posParent
.x
+ widthParent
>= 0) // if parent is (partially) on the main display
443 else if (xNew
+width
> size
.x
)
444 xNew
= size
.x
-width
-1;
446 if (posParent
.y
+ heightParent
>= 0) // if parent is (partially) on the main display
448 if (yNew
+height
> size
.y
)
449 yNew
= size
.y
-height
-1;
451 // Make certain that the title bar is initially visible
452 // always, even if this would push the bottom of the
453 // dialog of the visible area of the display
458 // move the window to this position (keeping the old size but using
459 // SetSize() and not Move() to allow xNew and/or yNew to be -1)
460 SetSize(xNew
, yNew
, width
, height
, wxSIZE_ALLOW_MINUS_ONE
);
463 // fits the window around the children
464 void wxWindowBase::Fit()
466 if ( GetChildren().GetCount() > 0 )
468 SetClientSize(DoGetBestSize());
470 //else: do nothing if we have no children
473 // return the size best suited for the current window
474 wxSize
wxWindowBase::DoGetBestSize() const
478 return m_windowSizer
->GetMinSize();
480 #if wxUSE_CONSTRAINTS
481 else if ( m_constraints
)
483 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
485 // our minimal acceptable size is such that all our windows fit inside
489 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
491 node
= node
->GetNext() )
493 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
496 // it's not normal that we have an unconstrained child, but
497 // what can we do about it?
501 int x
= c
->right
.GetValue(),
502 y
= c
->bottom
.GetValue();
510 // TODO: we must calculate the overlaps somehow, otherwise we
511 // will never return a size bigger than the current one :-(
514 return wxSize(maxX
, maxY
);
516 #endif // wxUSE_CONSTRAINTS
517 else if ( GetChildren().GetCount() > 0 )
519 // our minimal acceptable size is such that all our windows fit inside
523 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
525 node
= node
->GetNext() )
527 wxWindow
*win
= node
->GetData();
528 if ( win
->IsTopLevel()
530 || wxDynamicCast(win
, wxStatusBar
)
531 #endif // wxUSE_STATUSBAR
534 // dialogs and frames lie in different top level windows -
535 // don't deal with them here; as for the status bars, they
536 // don't lie in the client area at all
541 win
->GetPosition(&wx
, &wy
);
543 // if the window hadn't been positioned yet, assume that it is in
550 win
->GetSize(&ww
, &wh
);
551 if ( wx
+ ww
> maxX
)
553 if ( wy
+ wh
> maxY
)
557 // for compatibility with the old versions and because it really looks
558 // slightly more pretty like this, add a pad
562 return wxSize(maxX
, maxY
);
566 // for a generic window there is no natural best size - just use the
572 // by default the origin is not shifted
573 wxPoint
wxWindowBase::GetClientAreaOrigin() const
575 return wxPoint(0, 0);
578 // set the min/max size of the window
579 void wxWindowBase::SetSizeHints(int minW
, int minH
,
581 int WXUNUSED(incW
), int WXUNUSED(incH
))
589 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
592 m_minVirtualWidth
= minW
;
593 m_maxVirtualWidth
= maxW
;
594 m_minVirtualHeight
= minH
;
595 m_maxVirtualHeight
= maxH
;
597 SetVirtualSize( GetClientSize() );
600 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
602 if ( m_minVirtualWidth
!= -1 && m_minVirtualWidth
> x
)
603 x
= m_minVirtualWidth
;
604 if ( m_maxVirtualWidth
!= -1 && m_maxVirtualWidth
< x
)
605 x
= m_maxVirtualWidth
;
606 if ( m_minVirtualHeight
!= -1 && m_minVirtualHeight
> y
)
607 y
= m_minVirtualHeight
;
608 if ( m_maxVirtualHeight
!= -1 && m_maxVirtualHeight
< y
)
609 y
= m_maxVirtualHeight
;
611 m_virtualSize
= wxSize(x
, y
);
614 wxSize
wxWindowBase::DoGetVirtualSize() const
616 wxSize
s( GetClientSize() );
618 if( m_virtualSize
.GetWidth() != -1 )
619 s
.SetWidth( m_virtualSize
.GetWidth() );
620 if( m_virtualSize
.GetHeight() != -1 )
621 s
.SetHeight( m_virtualSize
.GetHeight() );
626 // ----------------------------------------------------------------------------
627 // show/hide/enable/disable the window
628 // ----------------------------------------------------------------------------
630 bool wxWindowBase::Show(bool show
)
632 if ( show
!= m_isShown
)
644 bool wxWindowBase::Enable(bool enable
)
646 if ( enable
!= m_isEnabled
)
648 m_isEnabled
= enable
;
657 // ----------------------------------------------------------------------------
659 // ----------------------------------------------------------------------------
661 bool wxWindowBase::IsTopLevel() const
666 // ----------------------------------------------------------------------------
667 // reparenting the window
668 // ----------------------------------------------------------------------------
670 void wxWindowBase::AddChild(wxWindowBase
*child
)
672 wxCHECK_RET( child
, wxT("can't add a NULL child") );
674 // this should never happen and it will lead to a crash later if it does
675 // because RemoveChild() will remove only one node from the children list
676 // and the other(s) one(s) will be left with dangling pointers in them
677 wxASSERT_MSG( !GetChildren().Find(child
), _T("AddChild() called twice") );
679 GetChildren().Append(child
);
680 child
->SetParent(this);
683 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
685 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
687 GetChildren().DeleteObject(child
);
688 child
->SetParent((wxWindow
*)NULL
);
691 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
693 wxWindow
*oldParent
= GetParent();
694 if ( newParent
== oldParent
)
700 // unlink this window from the existing parent.
703 oldParent
->RemoveChild(this);
707 wxTopLevelWindows
.DeleteObject(this);
710 // add it to the new one
713 newParent
->AddChild(this);
717 wxTopLevelWindows
.Append(this);
723 // ----------------------------------------------------------------------------
724 // event handler stuff
725 // ----------------------------------------------------------------------------
727 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
729 wxEvtHandler
*handlerOld
= GetEventHandler();
731 handler
->SetNextHandler(handlerOld
);
734 GetEventHandler()->SetPreviousHandler(handler
);
736 SetEventHandler(handler
);
739 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
741 wxEvtHandler
*handlerA
= GetEventHandler();
744 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
745 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
748 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
749 SetEventHandler(handlerB
);
754 handlerA
= (wxEvtHandler
*)NULL
;
761 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
763 wxCHECK_MSG( handler
, FALSE
, _T("RemoveEventHandler(NULL) called") );
765 wxEvtHandler
*handlerPrev
= NULL
,
766 *handlerCur
= GetEventHandler();
769 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
771 if ( handlerCur
== handler
)
775 handlerPrev
->SetNextHandler(handlerNext
);
779 SetEventHandler(handlerNext
);
784 handlerNext
->SetPreviousHandler ( handlerPrev
);
786 handler
->SetNextHandler(NULL
);
791 handlerPrev
= handlerCur
;
792 handlerCur
= handlerNext
;
795 wxFAIL_MSG( _T("where has the event handler gone?") );
800 // ----------------------------------------------------------------------------
802 // ----------------------------------------------------------------------------
804 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
806 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
809 m_backgroundColour
= colour
;
816 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
818 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
821 m_foregroundColour
= colour
;
828 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
830 // setting an invalid cursor is ok, it means that we don't have any special
832 if ( m_cursor
== cursor
)
843 bool wxWindowBase::SetFont(const wxFont
& font
)
845 // don't try to set invalid font, always fall back to the default
846 const wxFont
& fontOk
= font
.Ok() ? font
: *wxSWISS_FONT
;
848 if ( fontOk
== m_font
)
863 void wxWindowBase::SetPalette(const wxPalette
& pal
)
865 m_hasCustomPalette
= TRUE
;
868 // VZ: can anyone explain me what do we do here?
869 wxWindowDC
d((wxWindow
*) this);
873 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
875 wxWindow
*win
= (wxWindow
*)this;
876 while ( win
&& !win
->HasCustomPalette() )
878 win
= win
->GetParent();
884 #endif // wxUSE_PALETTE
887 void wxWindowBase::SetCaret(wxCaret
*caret
)
898 wxASSERT_MSG( m_caret
->GetWindow() == this,
899 wxT("caret should be created associated to this window") );
902 #endif // wxUSE_CARET
905 // ----------------------------------------------------------------------------
907 // ----------------------------------------------------------------------------
909 void wxWindowBase::SetValidator(const wxValidator
& validator
)
911 if ( m_windowValidator
)
912 delete m_windowValidator
;
914 m_windowValidator
= (wxValidator
*)validator
.Clone();
916 if ( m_windowValidator
)
917 m_windowValidator
->SetWindow(this) ;
919 #endif // wxUSE_VALIDATORS
921 // ----------------------------------------------------------------------------
922 // update region stuff
923 // ----------------------------------------------------------------------------
925 wxRect
wxWindowBase::GetUpdateClientRect() const
927 wxRegion rgnUpdate
= GetUpdateRegion();
928 rgnUpdate
.Intersect(GetClientRect());
929 wxRect rectUpdate
= rgnUpdate
.GetBox();
930 wxPoint ptOrigin
= GetClientAreaOrigin();
931 rectUpdate
.x
-= ptOrigin
.x
;
932 rectUpdate
.y
-= ptOrigin
.y
;
937 bool wxWindowBase::IsExposed(int x
, int y
) const
939 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
942 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
944 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
947 // ----------------------------------------------------------------------------
948 // find child window by id or name
949 // ----------------------------------------------------------------------------
951 wxWindow
*wxWindowBase::FindWindow( long id
)
953 if ( id
== m_windowId
)
954 return (wxWindow
*)this;
956 wxWindowBase
*res
= (wxWindow
*)NULL
;
957 wxWindowList::Node
*node
;
958 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
960 wxWindowBase
*child
= node
->GetData();
961 res
= child
->FindWindow( id
);
964 return (wxWindow
*)res
;
967 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
969 if ( name
== m_windowName
)
970 return (wxWindow
*)this;
972 wxWindowBase
*res
= (wxWindow
*)NULL
;
973 wxWindowList::Node
*node
;
974 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
976 wxWindow
*child
= node
->GetData();
977 res
= child
->FindWindow(name
);
980 return (wxWindow
*)res
;
984 // find any window by id or name or label: If parent is non-NULL, look through
985 // children for a label or title matching the specified string. If NULL, look
986 // through all top-level windows.
988 // to avoid duplicating code we reuse the same helper function but with
989 // different comparators
991 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
992 const wxString
& label
, long id
);
995 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
998 return win
->GetLabel() == label
;
1002 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1005 return win
->GetName() == label
;
1009 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1012 return win
->GetId() == id
;
1015 // recursive helper for the FindWindowByXXX() functions
1017 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1018 const wxString
& label
,
1020 wxFindWindowCmp cmp
)
1024 // see if this is the one we're looking for
1025 if ( (*cmp
)(parent
, label
, id
) )
1026 return (wxWindow
*)parent
;
1028 // It wasn't, so check all its children
1029 for ( wxWindowList::Node
* node
= parent
->GetChildren().GetFirst();
1031 node
= node
->GetNext() )
1033 // recursively check each child
1034 wxWindow
*win
= (wxWindow
*)node
->GetData();
1035 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1045 // helper for FindWindowByXXX()
1047 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1048 const wxString
& label
,
1050 wxFindWindowCmp cmp
)
1054 // just check parent and all its children
1055 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1058 // start at very top of wx's windows
1059 for ( wxWindowList::Node
* node
= wxTopLevelWindows
.GetFirst();
1061 node
= node
->GetNext() )
1063 // recursively check each window & its children
1064 wxWindow
*win
= node
->GetData();
1065 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1075 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1077 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1082 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1084 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1088 // fall back to the label
1089 win
= FindWindowByLabel(title
, parent
);
1097 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1099 return wxFindWindowHelper(parent
, _T(""), id
, wxFindWindowCmpIds
);
1102 // ----------------------------------------------------------------------------
1103 // dialog oriented functions
1104 // ----------------------------------------------------------------------------
1106 void wxWindowBase::MakeModal(bool modal
)
1108 // Disable all other windows
1111 wxWindowList::Node
*node
= wxTopLevelWindows
.GetFirst();
1114 wxWindow
*win
= node
->GetData();
1116 win
->Enable(!modal
);
1118 node
= node
->GetNext();
1123 bool wxWindowBase::Validate()
1125 #if wxUSE_VALIDATORS
1126 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1128 wxWindowList::Node
*node
;
1129 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1131 wxWindowBase
*child
= node
->GetData();
1132 wxValidator
*validator
= child
->GetValidator();
1133 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1138 if ( recurse
&& !child
->Validate() )
1143 #endif // wxUSE_VALIDATORS
1148 bool wxWindowBase::TransferDataToWindow()
1150 #if wxUSE_VALIDATORS
1151 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1153 wxWindowList::Node
*node
;
1154 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1156 wxWindowBase
*child
= node
->GetData();
1157 wxValidator
*validator
= child
->GetValidator();
1158 if ( validator
&& !validator
->TransferToWindow() )
1160 wxLogWarning(_("Could not transfer data to window"));
1161 wxLog::FlushActive();
1168 if ( !child
->TransferDataToWindow() )
1170 // warning already given
1175 #endif // wxUSE_VALIDATORS
1180 bool wxWindowBase::TransferDataFromWindow()
1182 #if wxUSE_VALIDATORS
1183 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1185 wxWindowList::Node
*node
;
1186 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1188 wxWindow
*child
= node
->GetData();
1189 wxValidator
*validator
= child
->GetValidator();
1190 if ( validator
&& !validator
->TransferFromWindow() )
1192 // nop warning here because the application is supposed to give
1193 // one itself - we don't know here what might have gone wrongly
1200 if ( !child
->TransferDataFromWindow() )
1202 // warning already given
1207 #endif // wxUSE_VALIDATORS
1212 void wxWindowBase::InitDialog()
1214 wxInitDialogEvent
event(GetId());
1215 event
.SetEventObject( this );
1216 GetEventHandler()->ProcessEvent(event
);
1219 // ----------------------------------------------------------------------------
1220 // context-sensitive help support
1221 // ----------------------------------------------------------------------------
1225 // associate this help text with this window
1226 void wxWindowBase::SetHelpText(const wxString
& text
)
1228 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1231 helpProvider
->AddHelp(this, text
);
1235 // associate this help text with all windows with the same id as this
1237 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1239 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1242 helpProvider
->AddHelp(GetId(), text
);
1246 // get the help string associated with this window (may be empty)
1247 wxString
wxWindowBase::GetHelpText() const
1250 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1253 text
= helpProvider
->GetHelp(this);
1259 // show help for this window
1260 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1262 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1265 if ( helpProvider
->ShowHelp(this) )
1267 // skip the event.Skip() below
1275 #endif // wxUSE_HELP
1277 // ----------------------------------------------------------------------------
1278 // tooltipsroot.Replace("\\", "/");
1279 // ----------------------------------------------------------------------------
1283 void wxWindowBase::SetToolTip( const wxString
&tip
)
1285 // don't create the new tooltip if we already have one
1288 m_tooltip
->SetTip( tip
);
1292 SetToolTip( new wxToolTip( tip
) );
1295 // setting empty tooltip text does not remove the tooltip any more - use
1296 // SetToolTip((wxToolTip *)NULL) for this
1299 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1304 m_tooltip
= tooltip
;
1307 #endif // wxUSE_TOOLTIPS
1309 // ----------------------------------------------------------------------------
1310 // constraints and sizers
1311 // ----------------------------------------------------------------------------
1313 #if wxUSE_CONSTRAINTS
1315 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1317 if ( m_constraints
)
1319 UnsetConstraints(m_constraints
);
1320 delete m_constraints
;
1322 m_constraints
= constraints
;
1323 if ( m_constraints
)
1325 // Make sure other windows know they're part of a 'meaningful relationship'
1326 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1327 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1328 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1329 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1330 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1331 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1332 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1333 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1334 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1335 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1336 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1337 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1338 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1339 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1340 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1341 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1345 // This removes any dangling pointers to this window in other windows'
1346 // constraintsInvolvedIn lists.
1347 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1351 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1352 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1353 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1354 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1355 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1356 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1357 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1358 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1359 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1360 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1361 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1362 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1363 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1364 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1365 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1366 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1370 // Back-pointer to other windows we're involved with, so if we delete this
1371 // window, we must delete any constraints we're involved with.
1372 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1374 if ( !m_constraintsInvolvedIn
)
1375 m_constraintsInvolvedIn
= new wxWindowList
;
1376 if ( !m_constraintsInvolvedIn
->Find(otherWin
) )
1377 m_constraintsInvolvedIn
->Append(otherWin
);
1380 // REMOVE back-pointer to other windows we're involved with.
1381 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1383 if ( m_constraintsInvolvedIn
)
1384 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
1387 // Reset any constraints that mention this window
1388 void wxWindowBase::DeleteRelatedConstraints()
1390 if ( m_constraintsInvolvedIn
)
1392 wxWindowList::Node
*node
= m_constraintsInvolvedIn
->GetFirst();
1395 wxWindow
*win
= node
->GetData();
1396 wxLayoutConstraints
*constr
= win
->GetConstraints();
1398 // Reset any constraints involving this window
1401 constr
->left
.ResetIfWin(this);
1402 constr
->top
.ResetIfWin(this);
1403 constr
->right
.ResetIfWin(this);
1404 constr
->bottom
.ResetIfWin(this);
1405 constr
->width
.ResetIfWin(this);
1406 constr
->height
.ResetIfWin(this);
1407 constr
->centreX
.ResetIfWin(this);
1408 constr
->centreY
.ResetIfWin(this);
1411 wxWindowList::Node
*next
= node
->GetNext();
1416 delete m_constraintsInvolvedIn
;
1417 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1421 #endif // wxUSE_CONSTRAINTS
1423 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1426 delete m_windowSizer
;
1428 m_windowSizer
= sizer
;
1430 SetAutoLayout( sizer
!= NULL
);
1433 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1435 SetSizer( sizer
, deleteOld
);
1436 sizer
->SetSizeHints( (wxWindow
*) this );
1439 #if wxUSE_CONSTRAINTS
1441 void wxWindowBase::SatisfyConstraints()
1443 wxLayoutConstraints
*constr
= GetConstraints();
1444 bool wasOk
= constr
&& constr
->AreSatisfied();
1446 ResetConstraints(); // Mark all constraints as unevaluated
1450 // if we're a top level panel (i.e. our parent is frame/dialog), our
1451 // own constraints will never be satisfied any more unless we do it
1455 while ( noChanges
> 0 )
1457 LayoutPhase1(&noChanges
);
1461 LayoutPhase2(&noChanges
);
1464 #endif // wxUSE_CONSTRAINTS
1466 bool wxWindowBase::Layout()
1468 // If there is a sizer, use it instead of the constraints
1472 GetVirtualSize(&w
, &h
);
1473 GetSizer()->SetDimension( 0, 0, w
, h
);
1475 #if wxUSE_CONSTRAINTS
1478 SatisfyConstraints(); // Find the right constraints values
1479 SetConstraintSizes(); // Recursively set the real window sizes
1486 #if wxUSE_CONSTRAINTS
1488 // first phase of the constraints evaluation: set our own constraints
1489 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1491 wxLayoutConstraints
*constr
= GetConstraints();
1493 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1496 // second phase: set the constraints for our children
1497 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1504 // Layout grand children
1510 // Do a phase of evaluating child constraints
1511 bool wxWindowBase::DoPhase(int phase
)
1513 // the list containing the children for which the constraints are already
1515 wxWindowList succeeded
;
1517 // the max number of iterations we loop before concluding that we can't set
1519 static const int maxIterations
= 500;
1521 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1525 // loop over all children setting their constraints
1526 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
1528 node
= node
->GetNext() )
1530 wxWindow
*child
= node
->GetData();
1531 if ( child
->IsTopLevel() )
1533 // top level children are not inside our client area
1537 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1539 // this one is either already ok or nothing we can do about it
1543 int tempNoChanges
= 0;
1544 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1545 : child
->LayoutPhase2(&tempNoChanges
);
1546 noChanges
+= tempNoChanges
;
1550 succeeded
.Append(child
);
1556 // constraints are set
1564 void wxWindowBase::ResetConstraints()
1566 wxLayoutConstraints
*constr
= GetConstraints();
1569 constr
->left
.SetDone(FALSE
);
1570 constr
->top
.SetDone(FALSE
);
1571 constr
->right
.SetDone(FALSE
);
1572 constr
->bottom
.SetDone(FALSE
);
1573 constr
->width
.SetDone(FALSE
);
1574 constr
->height
.SetDone(FALSE
);
1575 constr
->centreX
.SetDone(FALSE
);
1576 constr
->centreY
.SetDone(FALSE
);
1579 wxWindowList::Node
*node
= GetChildren().GetFirst();
1582 wxWindow
*win
= node
->GetData();
1583 if ( !win
->IsTopLevel() )
1584 win
->ResetConstraints();
1585 node
= node
->GetNext();
1589 // Need to distinguish between setting the 'fake' size for windows and sizers,
1590 // and setting the real values.
1591 void wxWindowBase::SetConstraintSizes(bool recurse
)
1593 wxLayoutConstraints
*constr
= GetConstraints();
1594 if ( constr
&& constr
->AreSatisfied() )
1596 int x
= constr
->left
.GetValue();
1597 int y
= constr
->top
.GetValue();
1598 int w
= constr
->width
.GetValue();
1599 int h
= constr
->height
.GetValue();
1601 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1602 (constr
->height
.GetRelationship() != wxAsIs
) )
1604 SetSize(x
, y
, w
, h
);
1608 // If we don't want to resize this window, just move it...
1614 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1615 GetClassInfo()->GetClassName(),
1621 wxWindowList::Node
*node
= GetChildren().GetFirst();
1624 wxWindow
*win
= node
->GetData();
1625 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1626 win
->SetConstraintSizes();
1627 node
= node
->GetNext();
1632 // Only set the size/position of the constraint (if any)
1633 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1635 wxLayoutConstraints
*constr
= GetConstraints();
1640 constr
->left
.SetValue(x
);
1641 constr
->left
.SetDone(TRUE
);
1645 constr
->top
.SetValue(y
);
1646 constr
->top
.SetDone(TRUE
);
1650 constr
->width
.SetValue(w
);
1651 constr
->width
.SetDone(TRUE
);
1655 constr
->height
.SetValue(h
);
1656 constr
->height
.SetDone(TRUE
);
1661 void wxWindowBase::MoveConstraint(int x
, int y
)
1663 wxLayoutConstraints
*constr
= GetConstraints();
1668 constr
->left
.SetValue(x
);
1669 constr
->left
.SetDone(TRUE
);
1673 constr
->top
.SetValue(y
);
1674 constr
->top
.SetDone(TRUE
);
1679 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1681 wxLayoutConstraints
*constr
= GetConstraints();
1684 *w
= constr
->width
.GetValue();
1685 *h
= constr
->height
.GetValue();
1691 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1693 wxLayoutConstraints
*constr
= GetConstraints();
1696 *w
= constr
->width
.GetValue();
1697 *h
= constr
->height
.GetValue();
1700 GetClientSize(w
, h
);
1703 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1705 wxLayoutConstraints
*constr
= GetConstraints();
1708 *x
= constr
->left
.GetValue();
1709 *y
= constr
->top
.GetValue();
1715 #endif // wxUSE_CONSTRAINTS
1717 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
1719 // don't do it for the dialogs/frames - they float independently of their
1721 if ( !IsTopLevel() )
1723 wxWindow
*parent
= GetParent();
1724 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
1726 wxPoint
pt(parent
->GetClientAreaOrigin());
1733 // ----------------------------------------------------------------------------
1734 // do Update UI processing for child controls
1735 // ----------------------------------------------------------------------------
1737 // TODO: should this be implemented for the child window rather
1738 // than the parent? Then you can override it e.g. for wxCheckBox
1739 // to do the Right Thing rather than having to assume a fixed number
1740 // of control classes.
1741 void wxWindowBase::UpdateWindowUI()
1744 wxUpdateUIEvent
event(GetId());
1745 event
.m_eventObject
= this;
1747 if ( GetEventHandler()->ProcessEvent(event
) )
1749 if ( event
.GetSetEnabled() )
1750 Enable(event
.GetEnabled());
1752 if ( event
.GetSetText() )
1754 wxControl
*control
= wxDynamicCastThis(wxControl
);
1758 wxTextCtrl
*text
= wxDynamicCast(control
, wxTextCtrl
);
1760 text
->SetValue(event
.GetText());
1762 #endif // wxUSE_TEXTCTRL
1763 control
->SetLabel(event
.GetText());
1768 wxCheckBox
*checkbox
= wxDynamicCastThis(wxCheckBox
);
1771 if ( event
.GetSetChecked() )
1772 checkbox
->SetValue(event
.GetChecked());
1774 #endif // wxUSE_CHECKBOX
1777 wxRadioButton
*radiobtn
= wxDynamicCastThis(wxRadioButton
);
1780 if ( event
.GetSetChecked() )
1781 radiobtn
->SetValue(event
.GetChecked());
1783 #endif // wxUSE_RADIOBTN
1785 #endif // wxUSE_CONTROLS
1788 // ----------------------------------------------------------------------------
1789 // dialog units translations
1790 // ----------------------------------------------------------------------------
1792 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1794 int charWidth
= GetCharWidth();
1795 int charHeight
= GetCharHeight();
1796 wxPoint
pt2(-1, -1);
1798 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1800 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1805 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1807 int charWidth
= GetCharWidth();
1808 int charHeight
= GetCharHeight();
1809 wxPoint
pt2(-1, -1);
1811 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1813 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1818 // ----------------------------------------------------------------------------
1820 // ----------------------------------------------------------------------------
1822 // propagate the colour change event to the subwindows
1823 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1825 wxWindowList::Node
*node
= GetChildren().GetFirst();
1828 // Only propagate to non-top-level windows
1829 wxWindow
*win
= node
->GetData();
1830 if ( !win
->IsTopLevel() )
1832 wxSysColourChangedEvent event2
;
1833 event
.m_eventObject
= win
;
1834 win
->GetEventHandler()->ProcessEvent(event2
);
1837 node
= node
->GetNext();
1841 // the default action is to populate dialog with data when it's created
1842 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1844 TransferDataToWindow();
1847 // process Ctrl-Alt-mclick
1848 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
1851 if ( event
.ControlDown() && event
.AltDown() )
1853 // don't translate these strings
1856 #ifdef __WXUNIVERSAL__
1858 #endif // __WXUNIVERSAL__
1860 switch ( wxGetOsVersion() )
1862 case wxMOTIF_X
: port
= _T("Motif"); break;
1864 case wxMAC_DARWIN
: port
= _T("Mac"); break;
1865 case wxBEOS
: port
= _T("BeOS"); break;
1869 case wxGTK_BEOS
: port
= _T("GTK"); break;
1875 case wxWIN386
: port
= _T("MS Windows"); break;
1879 case wxMGL_OS2
: port
= _T("MGL"); break;
1881 case wxOS2_PM
: port
= _T("OS/2"); break;
1882 default: port
= _T("unknown"); break;
1885 wxMessageBox(wxString::Format(
1887 " wxWindows Library (%s port)\nVersion %u.%u.%u%s, compiled at %s %s\n Copyright (c) 1995-2002 wxWindows team"
1901 _T("wxWindows information"),
1902 wxICON_INFORMATION
| wxOK
,
1906 #endif // wxUSE_MSGDLG
1912 // ----------------------------------------------------------------------------
1913 // list classes implementation
1914 // ----------------------------------------------------------------------------
1916 void wxWindowListNode::DeleteData()
1918 delete (wxWindow
*)GetData();
1921 // ----------------------------------------------------------------------------
1923 // ----------------------------------------------------------------------------
1925 wxBorder
wxWindowBase::GetBorder() const
1927 wxBorder border
= (wxBorder
)(m_windowStyle
& wxBORDER_MASK
);
1928 if ( border
== wxBORDER_DEFAULT
)
1930 border
= GetDefaultBorder();
1936 wxBorder
wxWindowBase::GetDefaultBorder() const
1938 return wxBORDER_NONE
;
1941 // ----------------------------------------------------------------------------
1943 // ----------------------------------------------------------------------------
1945 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
1947 // here we just check if the point is inside the window or not
1949 // check the top and left border first
1950 bool outside
= x
< 0 || y
< 0;
1953 // check the right and bottom borders too
1954 wxSize size
= GetSize();
1955 outside
= x
>= size
.x
|| y
>= size
.y
;
1958 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
1961 // ----------------------------------------------------------------------------
1963 // ----------------------------------------------------------------------------
1965 struct WXDLLEXPORT wxWindowNext
1969 } *wxWindowBase::ms_winCaptureNext
= NULL
;
1971 void wxWindowBase::CaptureMouse()
1973 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this);
1975 wxWindow
*winOld
= GetCapture();
1978 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
1981 wxWindowNext
*item
= new wxWindowNext
;
1983 item
->next
= ms_winCaptureNext
;
1984 ms_winCaptureNext
= item
;
1986 //else: no mouse capture to save
1991 void wxWindowBase::ReleaseMouse()
1993 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this);
1995 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
1999 if ( ms_winCaptureNext
)
2001 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2003 wxWindowNext
*item
= ms_winCaptureNext
;
2004 ms_winCaptureNext
= item
->next
;
2007 //else: stack is empty, no previous capture
2009 wxLogTrace(_T("mousecapture"),
2010 _T("After ReleaseMouse() mouse is captured by %p"),
2014 // ----------------------------------------------------------------------------
2016 // ----------------------------------------------------------------------------
2018 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2020 while ( win
&& !win
->IsTopLevel() )
2021 win
= win
->GetParent();