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 // ----------------------------------------------------------------------------
74 int wxWindowBase::ms_lastControlId
= -200;
76 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
78 // ----------------------------------------------------------------------------
80 // ----------------------------------------------------------------------------
82 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
83 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
84 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
85 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick
)
88 EVT_HELP(-1, wxWindowBase::OnHelp
)
93 // ============================================================================
94 // implementation of the common functionality of the wxWindow class
95 // ============================================================================
97 // ----------------------------------------------------------------------------
99 // ----------------------------------------------------------------------------
101 // the default initialization
102 void wxWindowBase::InitBase()
104 // no window yet, no parent nor children
105 m_parent
= (wxWindow
*)NULL
;
107 m_children
.DeleteContents( FALSE
); // don't auto delete node data
109 // no constraints on the minimal window size
115 // window is created enabled but it's not visible yet
119 // the default event handler is just this window
120 m_eventHandler
= this;
124 m_windowValidator
= (wxValidator
*) NULL
;
125 #endif // wxUSE_VALIDATORS
127 // use the system default colours
128 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
129 m_foregroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
131 // don't set the font here for wxMSW as we don't call WM_SETFONT here and
132 // so the font is *not* really set - but calls to SetFont() later won't do
133 // anything because m_font appears to be already set!
135 m_font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
138 // the colours/fonts are default for now
147 // an optimization for the event processing: checking this flag is much
148 // faster than using IsKindOf(CLASSINFO(wxWindow))
151 #if wxUSE_CONSTRAINTS
152 // no constraints whatsoever
153 m_constraints
= (wxLayoutConstraints
*) NULL
;
154 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
155 #endif // wxUSE_CONSTRAINTS
157 m_windowSizer
= (wxSizer
*) NULL
;
158 m_containingSizer
= (wxSizer
*) NULL
;
159 m_autoLayout
= FALSE
;
161 #if wxUSE_DRAG_AND_DROP
162 m_dropTarget
= (wxDropTarget
*)NULL
;
163 #endif // wxUSE_DRAG_AND_DROP
166 m_tooltip
= (wxToolTip
*)NULL
;
167 #endif // wxUSE_TOOLTIPS
170 m_caret
= (wxCaret
*)NULL
;
171 #endif // wxUSE_CARET
174 m_hasCustomPalette
= FALSE
;
175 #endif // wxUSE_PALETTE
177 m_virtualSize
= wxDefaultSize
;
182 m_maxVirtualHeight
= -1;
184 // Whether we're using the current theme for this window (wxGTK only for now)
185 m_themeEnabled
= FALSE
;
188 // common part of window creation process
189 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
191 const wxPoint
& WXUNUSED(pos
),
192 const wxSize
& WXUNUSED(size
),
194 const wxValidator
& validator
,
195 const wxString
& name
)
197 // m_isWindow is set to TRUE in wxWindowBase::Init() as well as many other
198 // member variables - check that it has been called (will catch the case
199 // when a new ctor is added which doesn't call InitWindow)
200 wxASSERT_MSG( m_isWindow
, wxT("Init() must have been called before!") );
202 // generate a new id if the user doesn't care about it
203 m_windowId
= id
== -1 ? NewControlId() : id
;
206 SetWindowStyleFlag(style
);
210 SetValidator(validator
);
211 #endif // wxUSE_VALIDATORS
213 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
214 // have it too - like this it's possible to set it only in the top level
215 // dialog/frame and all children will inherit it by defult
216 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
218 SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY
);
224 // ----------------------------------------------------------------------------
226 // ----------------------------------------------------------------------------
229 wxWindowBase::~wxWindowBase()
231 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
233 // FIXME if these 2 cases result from programming errors in the user code
234 // we should probably assert here instead of silently fixing them
236 // Just in case the window has been Closed, but we're then deleting
237 // immediately: don't leave dangling pointers.
238 wxPendingDelete
.DeleteObject(this);
240 // Just in case we've loaded a top-level window via LoadNativeDialog but
241 // we weren't a dialog class
242 wxTopLevelWindows
.DeleteObject(this);
244 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
249 #endif // wxUSE_CARET
252 if ( m_windowValidator
)
253 delete m_windowValidator
;
254 #endif // wxUSE_VALIDATORS
256 #if wxUSE_CONSTRAINTS
257 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
258 // at deleted windows as they delete themselves.
259 DeleteRelatedConstraints();
263 // This removes any dangling pointers to this window in other windows'
264 // constraintsInvolvedIn lists.
265 UnsetConstraints(m_constraints
);
266 delete m_constraints
;
267 m_constraints
= NULL
;
270 #endif // wxUSE_CONSTRAINTS
272 if ( m_containingSizer
)
273 m_containingSizer
->Remove((wxWindow
*)this);
276 delete m_windowSizer
;
278 #if wxUSE_DRAG_AND_DROP
281 #endif // wxUSE_DRAG_AND_DROP
286 #endif // wxUSE_TOOLTIPS
288 // reset the dangling pointer our parent window may keep to us
289 if ( m_parent
&& m_parent
->GetDefaultItem() == this )
291 m_parent
->SetDefaultItem(NULL
);
295 bool wxWindowBase::Destroy()
302 bool wxWindowBase::Close(bool force
)
304 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
305 event
.SetEventObject(this);
306 #if WXWIN_COMPATIBILITY
307 event
.SetForce(force
);
308 #endif // WXWIN_COMPATIBILITY
309 event
.SetCanVeto(!force
);
311 // return FALSE if window wasn't closed because the application vetoed the
313 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
316 bool wxWindowBase::DestroyChildren()
318 wxWindowList::Node
*node
;
321 // we iterate until the list becomes empty
322 node
= GetChildren().GetFirst();
326 wxWindow
*child
= node
->GetData();
328 wxASSERT_MSG( child
, wxT("children list contains empty nodes") );
333 wxASSERT_MSG( !GetChildren().Find(child
),
334 wxT("child didn't remove itself using RemoveChild()") );
340 // ----------------------------------------------------------------------------
341 // size/position related methods
342 // ----------------------------------------------------------------------------
344 // centre the window with respect to its parent in either (or both) directions
345 void wxWindowBase::Centre(int direction
)
347 // the position/size of the parent window or of the entire screen
349 int widthParent
, heightParent
;
351 wxWindow
*parent
= NULL
;
353 if ( !(direction
& wxCENTRE_ON_SCREEN
) )
355 // find the parent to centre this window on: it should be the
356 // immediate parent for the controls but the top level parent for the
357 // top level windows (like dialogs)
358 parent
= GetParent();
361 while ( parent
&& !parent
->IsTopLevel() )
363 parent
= parent
->GetParent();
367 // there is no wxTopLevelWindow under wxMotif yet
369 // we shouldn't center the dialog on the iconized window: under
370 // Windows, for example, this places it completely off the screen
373 wxTopLevelWindow
*winTop
= wxDynamicCast(parent
, wxTopLevelWindow
);
374 if ( winTop
&& winTop
->IsIconized() )
379 #endif // __WXMOTIF__
381 // did we find the parent?
385 direction
|= wxCENTRE_ON_SCREEN
;
389 if ( direction
& wxCENTRE_ON_SCREEN
)
391 // centre with respect to the whole screen
392 wxDisplaySize(&widthParent
, &heightParent
);
398 // centre on the parent
399 parent
->GetSize(&widthParent
, &heightParent
);
401 // adjust to the parents position
402 posParent
= parent
->GetPosition();
406 // centre inside the parents client rectangle
407 parent
->GetClientSize(&widthParent
, &heightParent
);
412 GetSize(&width
, &height
);
417 if ( direction
& wxHORIZONTAL
)
418 xNew
= (widthParent
- width
)/2;
420 if ( direction
& wxVERTICAL
)
421 yNew
= (heightParent
- height
)/2;
426 // Base size of the visible dimensions of the display
427 // to take into account the taskbar
428 wxRect rect
= wxGetClientDisplayRect();
429 wxSize
size (rect
.width
,rect
.height
);
431 // NB: in wxMSW, negative position may not neccessary mean "out of screen",
432 // but it may mean that the window is placed on other than the main
433 // display. Therefore we only make sure centered window is on the main display
434 // if the parent is at least partially present here.
435 if (posParent
.x
+ widthParent
>= 0) // if parent is (partially) on the main display
439 else if (xNew
+width
> size
.x
)
440 xNew
= size
.x
-width
-1;
442 if (posParent
.y
+ heightParent
>= 0) // if parent is (partially) on the main display
444 if (yNew
+height
> size
.y
)
445 yNew
= size
.y
-height
-1;
447 // Make certain that the title bar is initially visible
448 // always, even if this would push the bottom of the
449 // dialog of the visible area of the display
454 // move the window to this position (keeping the old size but using
455 // SetSize() and not Move() to allow xNew and/or yNew to be -1)
456 SetSize(xNew
, yNew
, width
, height
, wxSIZE_ALLOW_MINUS_ONE
);
459 // fits the window around the children
460 void wxWindowBase::Fit()
462 if ( GetChildren().GetCount() > 0 )
464 SetClientSize(DoGetBestSize());
466 //else: do nothing if we have no children
469 // return the size best suited for the current window
470 wxSize
wxWindowBase::DoGetBestSize() const
474 return m_windowSizer
->GetMinSize();
476 #if wxUSE_CONSTRAINTS
477 else if ( m_constraints
)
479 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
481 // our minimal acceptable size is such that all our windows fit inside
485 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
487 node
= node
->GetNext() )
489 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
492 // it's not normal that we have an unconstrained child, but
493 // what can we do about it?
497 int x
= c
->right
.GetValue(),
498 y
= c
->bottom
.GetValue();
506 // TODO: we must calculate the overlaps somehow, otherwise we
507 // will never return a size bigger than the current one :-(
510 return wxSize(maxX
, maxY
);
512 #endif // wxUSE_CONSTRAINTS
513 else if ( GetChildren().GetCount() > 0 )
515 // our minimal acceptable size is such that all our windows fit inside
519 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
521 node
= node
->GetNext() )
523 wxWindow
*win
= node
->GetData();
524 if ( win
->IsTopLevel()
526 || wxDynamicCast(win
, wxStatusBar
)
527 #endif // wxUSE_STATUSBAR
530 // dialogs and frames lie in different top level windows -
531 // don't deal with them here; as for the status bars, they
532 // don't lie in the client area at all
537 win
->GetPosition(&wx
, &wy
);
539 // if the window hadn't been positioned yet, assume that it is in
546 win
->GetSize(&ww
, &wh
);
547 if ( wx
+ ww
> maxX
)
549 if ( wy
+ wh
> maxY
)
553 // for compatibility with the old versions and because it really looks
554 // slightly more pretty like this, add a pad
558 return wxSize(maxX
, maxY
);
562 // for a generic window there is no natural best size - just use the
568 // by default the origin is not shifted
569 wxPoint
wxWindowBase::GetClientAreaOrigin() const
571 return wxPoint(0, 0);
574 // set the min/max size of the window
575 void wxWindowBase::SetSizeHints(int minW
, int minH
,
577 int WXUNUSED(incW
), int WXUNUSED(incH
))
585 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
588 m_minVirtualWidth
= minW
;
589 m_maxVirtualWidth
= maxW
;
590 m_minVirtualHeight
= minH
;
591 m_maxVirtualHeight
= maxH
;
593 SetVirtualSize( GetClientSize() );
596 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
598 if ( m_minVirtualWidth
!= -1 && m_minVirtualWidth
> x
)
599 x
= m_minVirtualWidth
;
600 if ( m_maxVirtualWidth
!= -1 && m_maxVirtualWidth
< x
)
601 x
= m_maxVirtualWidth
;
602 if ( m_minVirtualHeight
!= -1 && m_minVirtualHeight
> y
)
603 y
= m_minVirtualHeight
;
604 if ( m_maxVirtualHeight
!= -1 && m_maxVirtualHeight
< y
)
605 y
= m_maxVirtualHeight
;
607 m_virtualSize
= wxSize(x
, y
);
610 wxSize
wxWindowBase::DoGetVirtualSize() const
612 wxSize
s( GetClientSize() );
614 if( m_virtualSize
.GetWidth() != -1 )
615 s
.SetWidth( m_virtualSize
.GetWidth() );
616 if( m_virtualSize
.GetHeight() != -1 )
617 s
.SetHeight( m_virtualSize
.GetHeight() );
622 // ----------------------------------------------------------------------------
623 // show/hide/enable/disable the window
624 // ----------------------------------------------------------------------------
626 bool wxWindowBase::Show(bool show
)
628 if ( show
!= m_isShown
)
640 bool wxWindowBase::Enable(bool enable
)
642 if ( enable
!= m_isEnabled
)
644 m_isEnabled
= enable
;
653 // ----------------------------------------------------------------------------
655 // ----------------------------------------------------------------------------
657 bool wxWindowBase::IsTopLevel() const
662 // ----------------------------------------------------------------------------
663 // reparenting the window
664 // ----------------------------------------------------------------------------
666 void wxWindowBase::AddChild(wxWindowBase
*child
)
668 wxCHECK_RET( child
, wxT("can't add a NULL child") );
670 // this should never happen and it will lead to a crash later if it does
671 // because RemoveChild() will remove only one node from the children list
672 // and the other(s) one(s) will be left with dangling pointers in them
673 wxASSERT_MSG( !GetChildren().Find(child
), _T("AddChild() called twice") );
675 GetChildren().Append(child
);
676 child
->SetParent(this);
679 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
681 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
683 GetChildren().DeleteObject(child
);
684 child
->SetParent((wxWindow
*)NULL
);
687 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
689 wxWindow
*oldParent
= GetParent();
690 if ( newParent
== oldParent
)
696 // unlink this window from the existing parent.
699 oldParent
->RemoveChild(this);
703 wxTopLevelWindows
.DeleteObject(this);
706 // add it to the new one
709 newParent
->AddChild(this);
713 wxTopLevelWindows
.Append(this);
719 // ----------------------------------------------------------------------------
720 // event handler stuff
721 // ----------------------------------------------------------------------------
723 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
725 wxEvtHandler
*handlerOld
= GetEventHandler();
727 handler
->SetNextHandler(handlerOld
);
730 GetEventHandler()->SetPreviousHandler(handler
);
732 SetEventHandler(handler
);
735 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
737 wxEvtHandler
*handlerA
= GetEventHandler();
740 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
741 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
744 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
745 SetEventHandler(handlerB
);
750 handlerA
= (wxEvtHandler
*)NULL
;
757 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
759 wxCHECK_MSG( handler
, FALSE
, _T("RemoveEventHandler(NULL) called") );
761 wxEvtHandler
*handlerPrev
= NULL
,
762 *handlerCur
= GetEventHandler();
765 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
767 if ( handlerCur
== handler
)
771 handlerPrev
->SetNextHandler(handlerNext
);
775 SetEventHandler(handlerNext
);
780 handlerNext
->SetPreviousHandler ( handlerPrev
);
782 handler
->SetNextHandler(NULL
);
787 handlerPrev
= handlerCur
;
788 handlerCur
= handlerNext
;
791 wxFAIL_MSG( _T("where has the event handler gone?") );
796 // ----------------------------------------------------------------------------
798 // ----------------------------------------------------------------------------
800 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
802 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
805 m_backgroundColour
= colour
;
812 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
814 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
817 m_foregroundColour
= colour
;
824 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
826 // setting an invalid cursor is ok, it means that we don't have any special
828 if ( m_cursor
== cursor
)
839 bool wxWindowBase::SetFont(const wxFont
& font
)
841 // don't try to set invalid font, always fall back to the default
842 const wxFont
& fontOk
= font
.Ok() ? font
: *wxSWISS_FONT
;
844 if ( fontOk
== m_font
)
859 void wxWindowBase::SetPalette(const wxPalette
& pal
)
861 m_hasCustomPalette
= TRUE
;
864 // VZ: can anyone explain me what do we do here?
865 wxWindowDC
d((wxWindow
*) this);
869 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
871 wxWindow
*win
= (wxWindow
*)this;
872 while ( win
&& !win
->HasCustomPalette() )
874 win
= win
->GetParent();
880 #endif // wxUSE_PALETTE
883 void wxWindowBase::SetCaret(wxCaret
*caret
)
894 wxASSERT_MSG( m_caret
->GetWindow() == this,
895 wxT("caret should be created associated to this window") );
898 #endif // wxUSE_CARET
901 // ----------------------------------------------------------------------------
903 // ----------------------------------------------------------------------------
905 void wxWindowBase::SetValidator(const wxValidator
& validator
)
907 if ( m_windowValidator
)
908 delete m_windowValidator
;
910 m_windowValidator
= (wxValidator
*)validator
.Clone();
912 if ( m_windowValidator
)
913 m_windowValidator
->SetWindow(this) ;
915 #endif // wxUSE_VALIDATORS
917 // ----------------------------------------------------------------------------
918 // update region stuff
919 // ----------------------------------------------------------------------------
921 wxRect
wxWindowBase::GetUpdateClientRect() const
923 wxRegion rgnUpdate
= GetUpdateRegion();
924 rgnUpdate
.Intersect(GetClientRect());
925 wxRect rectUpdate
= rgnUpdate
.GetBox();
926 wxPoint ptOrigin
= GetClientAreaOrigin();
927 rectUpdate
.x
-= ptOrigin
.x
;
928 rectUpdate
.y
-= ptOrigin
.y
;
933 bool wxWindowBase::IsExposed(int x
, int y
) const
935 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
938 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
940 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
943 // ----------------------------------------------------------------------------
944 // find child window by id or name
945 // ----------------------------------------------------------------------------
947 wxWindow
*wxWindowBase::FindWindow( long id
)
949 if ( id
== m_windowId
)
950 return (wxWindow
*)this;
952 wxWindowBase
*res
= (wxWindow
*)NULL
;
953 wxWindowList::Node
*node
;
954 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
956 wxWindowBase
*child
= node
->GetData();
957 res
= child
->FindWindow( id
);
960 return (wxWindow
*)res
;
963 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
965 if ( name
== m_windowName
)
966 return (wxWindow
*)this;
968 wxWindowBase
*res
= (wxWindow
*)NULL
;
969 wxWindowList::Node
*node
;
970 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
972 wxWindow
*child
= node
->GetData();
973 res
= child
->FindWindow(name
);
976 return (wxWindow
*)res
;
980 // find any window by id or name or label: If parent is non-NULL, look through
981 // children for a label or title matching the specified string. If NULL, look
982 // through all top-level windows.
984 // to avoid duplicating code we reuse the same helper function but with
985 // different comparators
987 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
988 const wxString
& label
, long id
);
991 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
994 return win
->GetLabel() == label
;
998 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1001 return win
->GetName() == label
;
1005 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1008 return win
->GetId() == id
;
1011 // recursive helper for the FindWindowByXXX() functions
1013 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1014 const wxString
& label
,
1016 wxFindWindowCmp cmp
)
1020 // see if this is the one we're looking for
1021 if ( (*cmp
)(parent
, label
, id
) )
1022 return (wxWindow
*)parent
;
1024 // It wasn't, so check all its children
1025 for ( wxWindowList::Node
* node
= parent
->GetChildren().GetFirst();
1027 node
= node
->GetNext() )
1029 // recursively check each child
1030 wxWindow
*win
= (wxWindow
*)node
->GetData();
1031 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1041 // helper for FindWindowByXXX()
1043 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1044 const wxString
& label
,
1046 wxFindWindowCmp cmp
)
1050 // just check parent and all its children
1051 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1054 // start at very top of wx's windows
1055 for ( wxWindowList::Node
* node
= wxTopLevelWindows
.GetFirst();
1057 node
= node
->GetNext() )
1059 // recursively check each window & its children
1060 wxWindow
*win
= node
->GetData();
1061 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1071 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1073 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1078 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1080 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1084 // fall back to the label
1085 win
= FindWindowByLabel(title
, parent
);
1093 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1095 return wxFindWindowHelper(parent
, _T(""), id
, wxFindWindowCmpIds
);
1098 // ----------------------------------------------------------------------------
1099 // dialog oriented functions
1100 // ----------------------------------------------------------------------------
1102 void wxWindowBase::MakeModal(bool modal
)
1104 // Disable all other windows
1107 wxWindowList::Node
*node
= wxTopLevelWindows
.GetFirst();
1110 wxWindow
*win
= node
->GetData();
1112 win
->Enable(!modal
);
1114 node
= node
->GetNext();
1119 bool wxWindowBase::Validate()
1121 #if wxUSE_VALIDATORS
1122 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1124 wxWindowList::Node
*node
;
1125 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1127 wxWindowBase
*child
= node
->GetData();
1128 wxValidator
*validator
= child
->GetValidator();
1129 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1134 if ( recurse
&& !child
->Validate() )
1139 #endif // wxUSE_VALIDATORS
1144 bool wxWindowBase::TransferDataToWindow()
1146 #if wxUSE_VALIDATORS
1147 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1149 wxWindowList::Node
*node
;
1150 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1152 wxWindowBase
*child
= node
->GetData();
1153 wxValidator
*validator
= child
->GetValidator();
1154 if ( validator
&& !validator
->TransferToWindow() )
1156 wxLogWarning(_("Could not transfer data to window"));
1157 wxLog::FlushActive();
1164 if ( !child
->TransferDataToWindow() )
1166 // warning already given
1171 #endif // wxUSE_VALIDATORS
1176 bool wxWindowBase::TransferDataFromWindow()
1178 #if wxUSE_VALIDATORS
1179 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1181 wxWindowList::Node
*node
;
1182 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1184 wxWindow
*child
= node
->GetData();
1185 wxValidator
*validator
= child
->GetValidator();
1186 if ( validator
&& !validator
->TransferFromWindow() )
1188 // nop warning here because the application is supposed to give
1189 // one itself - we don't know here what might have gone wrongly
1196 if ( !child
->TransferDataFromWindow() )
1198 // warning already given
1203 #endif // wxUSE_VALIDATORS
1208 void wxWindowBase::InitDialog()
1210 wxInitDialogEvent
event(GetId());
1211 event
.SetEventObject( this );
1212 GetEventHandler()->ProcessEvent(event
);
1215 // ----------------------------------------------------------------------------
1216 // context-sensitive help support
1217 // ----------------------------------------------------------------------------
1221 // associate this help text with this window
1222 void wxWindowBase::SetHelpText(const wxString
& text
)
1224 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1227 helpProvider
->AddHelp(this, text
);
1231 // associate this help text with all windows with the same id as this
1233 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1235 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1238 helpProvider
->AddHelp(GetId(), text
);
1242 // get the help string associated with this window (may be empty)
1243 wxString
wxWindowBase::GetHelpText() const
1246 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1249 text
= helpProvider
->GetHelp(this);
1255 // show help for this window
1256 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1258 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1261 if ( helpProvider
->ShowHelp(this) )
1263 // skip the event.Skip() below
1271 #endif // wxUSE_HELP
1273 // ----------------------------------------------------------------------------
1274 // tooltipsroot.Replace("\\", "/");
1275 // ----------------------------------------------------------------------------
1279 void wxWindowBase::SetToolTip( const wxString
&tip
)
1281 // don't create the new tooltip if we already have one
1284 m_tooltip
->SetTip( tip
);
1288 SetToolTip( new wxToolTip( tip
) );
1291 // setting empty tooltip text does not remove the tooltip any more - use
1292 // SetToolTip((wxToolTip *)NULL) for this
1295 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1300 m_tooltip
= tooltip
;
1303 #endif // wxUSE_TOOLTIPS
1305 // ----------------------------------------------------------------------------
1306 // constraints and sizers
1307 // ----------------------------------------------------------------------------
1309 #if wxUSE_CONSTRAINTS
1311 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1313 if ( m_constraints
)
1315 UnsetConstraints(m_constraints
);
1316 delete m_constraints
;
1318 m_constraints
= constraints
;
1319 if ( m_constraints
)
1321 // Make sure other windows know they're part of a 'meaningful relationship'
1322 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1323 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1324 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1325 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1326 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1327 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1328 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1329 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1330 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1331 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1332 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1333 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1334 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1335 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1336 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1337 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1341 // This removes any dangling pointers to this window in other windows'
1342 // constraintsInvolvedIn lists.
1343 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1347 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1348 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1349 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1350 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1351 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1352 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1353 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1354 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1355 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1356 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1357 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1358 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1359 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1360 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1361 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1362 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1366 // Back-pointer to other windows we're involved with, so if we delete this
1367 // window, we must delete any constraints we're involved with.
1368 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1370 if ( !m_constraintsInvolvedIn
)
1371 m_constraintsInvolvedIn
= new wxWindowList
;
1372 if ( !m_constraintsInvolvedIn
->Find(otherWin
) )
1373 m_constraintsInvolvedIn
->Append(otherWin
);
1376 // REMOVE back-pointer to other windows we're involved with.
1377 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1379 if ( m_constraintsInvolvedIn
)
1380 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
1383 // Reset any constraints that mention this window
1384 void wxWindowBase::DeleteRelatedConstraints()
1386 if ( m_constraintsInvolvedIn
)
1388 wxWindowList::Node
*node
= m_constraintsInvolvedIn
->GetFirst();
1391 wxWindow
*win
= node
->GetData();
1392 wxLayoutConstraints
*constr
= win
->GetConstraints();
1394 // Reset any constraints involving this window
1397 constr
->left
.ResetIfWin(this);
1398 constr
->top
.ResetIfWin(this);
1399 constr
->right
.ResetIfWin(this);
1400 constr
->bottom
.ResetIfWin(this);
1401 constr
->width
.ResetIfWin(this);
1402 constr
->height
.ResetIfWin(this);
1403 constr
->centreX
.ResetIfWin(this);
1404 constr
->centreY
.ResetIfWin(this);
1407 wxWindowList::Node
*next
= node
->GetNext();
1412 delete m_constraintsInvolvedIn
;
1413 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1417 #endif // wxUSE_CONSTRAINTS
1419 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1422 delete m_windowSizer
;
1424 m_windowSizer
= sizer
;
1426 SetAutoLayout( sizer
!= NULL
);
1429 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1431 SetSizer( sizer
, deleteOld
);
1432 sizer
->SetSizeHints( (wxWindow
*) this );
1435 #if wxUSE_CONSTRAINTS
1437 void wxWindowBase::SatisfyConstraints()
1439 wxLayoutConstraints
*constr
= GetConstraints();
1440 bool wasOk
= constr
&& constr
->AreSatisfied();
1442 ResetConstraints(); // Mark all constraints as unevaluated
1446 // if we're a top level panel (i.e. our parent is frame/dialog), our
1447 // own constraints will never be satisfied any more unless we do it
1451 while ( noChanges
> 0 )
1453 LayoutPhase1(&noChanges
);
1457 LayoutPhase2(&noChanges
);
1460 #endif // wxUSE_CONSTRAINTS
1462 bool wxWindowBase::Layout()
1464 // If there is a sizer, use it instead of the constraints
1468 GetVirtualSize(&w
, &h
);
1469 GetSizer()->SetDimension( 0, 0, w
, h
);
1471 #if wxUSE_CONSTRAINTS
1474 SatisfyConstraints(); // Find the right constraints values
1475 SetConstraintSizes(); // Recursively set the real window sizes
1482 #if wxUSE_CONSTRAINTS
1484 // first phase of the constraints evaluation: set our own constraints
1485 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1487 wxLayoutConstraints
*constr
= GetConstraints();
1489 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1492 // second phase: set the constraints for our children
1493 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1500 // Layout grand children
1506 // Do a phase of evaluating child constraints
1507 bool wxWindowBase::DoPhase(int phase
)
1509 // the list containing the children for which the constraints are already
1511 wxWindowList succeeded
;
1513 // the max number of iterations we loop before concluding that we can't set
1515 static const int maxIterations
= 500;
1517 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1521 // loop over all children setting their constraints
1522 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
1524 node
= node
->GetNext() )
1526 wxWindow
*child
= node
->GetData();
1527 if ( child
->IsTopLevel() )
1529 // top level children are not inside our client area
1533 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1535 // this one is either already ok or nothing we can do about it
1539 int tempNoChanges
= 0;
1540 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1541 : child
->LayoutPhase2(&tempNoChanges
);
1542 noChanges
+= tempNoChanges
;
1546 succeeded
.Append(child
);
1552 // constraints are set
1560 void wxWindowBase::ResetConstraints()
1562 wxLayoutConstraints
*constr
= GetConstraints();
1565 constr
->left
.SetDone(FALSE
);
1566 constr
->top
.SetDone(FALSE
);
1567 constr
->right
.SetDone(FALSE
);
1568 constr
->bottom
.SetDone(FALSE
);
1569 constr
->width
.SetDone(FALSE
);
1570 constr
->height
.SetDone(FALSE
);
1571 constr
->centreX
.SetDone(FALSE
);
1572 constr
->centreY
.SetDone(FALSE
);
1575 wxWindowList::Node
*node
= GetChildren().GetFirst();
1578 wxWindow
*win
= node
->GetData();
1579 if ( !win
->IsTopLevel() )
1580 win
->ResetConstraints();
1581 node
= node
->GetNext();
1585 // Need to distinguish between setting the 'fake' size for windows and sizers,
1586 // and setting the real values.
1587 void wxWindowBase::SetConstraintSizes(bool recurse
)
1589 wxLayoutConstraints
*constr
= GetConstraints();
1590 if ( constr
&& constr
->AreSatisfied() )
1592 int x
= constr
->left
.GetValue();
1593 int y
= constr
->top
.GetValue();
1594 int w
= constr
->width
.GetValue();
1595 int h
= constr
->height
.GetValue();
1597 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1598 (constr
->height
.GetRelationship() != wxAsIs
) )
1600 SetSize(x
, y
, w
, h
);
1604 // If we don't want to resize this window, just move it...
1610 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1611 GetClassInfo()->GetClassName(),
1617 wxWindowList::Node
*node
= GetChildren().GetFirst();
1620 wxWindow
*win
= node
->GetData();
1621 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1622 win
->SetConstraintSizes();
1623 node
= node
->GetNext();
1628 // Only set the size/position of the constraint (if any)
1629 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1631 wxLayoutConstraints
*constr
= GetConstraints();
1636 constr
->left
.SetValue(x
);
1637 constr
->left
.SetDone(TRUE
);
1641 constr
->top
.SetValue(y
);
1642 constr
->top
.SetDone(TRUE
);
1646 constr
->width
.SetValue(w
);
1647 constr
->width
.SetDone(TRUE
);
1651 constr
->height
.SetValue(h
);
1652 constr
->height
.SetDone(TRUE
);
1657 void wxWindowBase::MoveConstraint(int x
, int y
)
1659 wxLayoutConstraints
*constr
= GetConstraints();
1664 constr
->left
.SetValue(x
);
1665 constr
->left
.SetDone(TRUE
);
1669 constr
->top
.SetValue(y
);
1670 constr
->top
.SetDone(TRUE
);
1675 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1677 wxLayoutConstraints
*constr
= GetConstraints();
1680 *w
= constr
->width
.GetValue();
1681 *h
= constr
->height
.GetValue();
1687 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1689 wxLayoutConstraints
*constr
= GetConstraints();
1692 *w
= constr
->width
.GetValue();
1693 *h
= constr
->height
.GetValue();
1696 GetClientSize(w
, h
);
1699 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1701 wxLayoutConstraints
*constr
= GetConstraints();
1704 *x
= constr
->left
.GetValue();
1705 *y
= constr
->top
.GetValue();
1711 #endif // wxUSE_CONSTRAINTS
1713 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
1715 // don't do it for the dialogs/frames - they float independently of their
1717 if ( !IsTopLevel() )
1719 wxWindow
*parent
= GetParent();
1720 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
1722 wxPoint
pt(parent
->GetClientAreaOrigin());
1729 // ----------------------------------------------------------------------------
1730 // do Update UI processing for child controls
1731 // ----------------------------------------------------------------------------
1733 // TODO: should this be implemented for the child window rather
1734 // than the parent? Then you can override it e.g. for wxCheckBox
1735 // to do the Right Thing rather than having to assume a fixed number
1736 // of control classes.
1737 void wxWindowBase::UpdateWindowUI()
1740 wxUpdateUIEvent
event(GetId());
1741 event
.m_eventObject
= this;
1743 if ( GetEventHandler()->ProcessEvent(event
) )
1745 if ( event
.GetSetEnabled() )
1746 Enable(event
.GetEnabled());
1748 if ( event
.GetSetText() )
1750 wxControl
*control
= wxDynamicCastThis(wxControl
);
1754 wxTextCtrl
*text
= wxDynamicCast(control
, wxTextCtrl
);
1756 text
->SetValue(event
.GetText());
1758 #endif // wxUSE_TEXTCTRL
1759 control
->SetLabel(event
.GetText());
1764 wxCheckBox
*checkbox
= wxDynamicCastThis(wxCheckBox
);
1767 if ( event
.GetSetChecked() )
1768 checkbox
->SetValue(event
.GetChecked());
1770 #endif // wxUSE_CHECKBOX
1773 wxRadioButton
*radiobtn
= wxDynamicCastThis(wxRadioButton
);
1776 if ( event
.GetSetChecked() )
1777 radiobtn
->SetValue(event
.GetChecked());
1779 #endif // wxUSE_RADIOBTN
1781 #endif // wxUSE_CONTROLS
1784 // ----------------------------------------------------------------------------
1785 // dialog units translations
1786 // ----------------------------------------------------------------------------
1788 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1790 int charWidth
= GetCharWidth();
1791 int charHeight
= GetCharHeight();
1792 wxPoint
pt2(-1, -1);
1794 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1796 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1801 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1803 int charWidth
= GetCharWidth();
1804 int charHeight
= GetCharHeight();
1805 wxPoint
pt2(-1, -1);
1807 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1809 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1814 // ----------------------------------------------------------------------------
1816 // ----------------------------------------------------------------------------
1818 // propagate the colour change event to the subwindows
1819 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1821 wxWindowList::Node
*node
= GetChildren().GetFirst();
1824 // Only propagate to non-top-level windows
1825 wxWindow
*win
= node
->GetData();
1826 if ( !win
->IsTopLevel() )
1828 wxSysColourChangedEvent event2
;
1829 event
.m_eventObject
= win
;
1830 win
->GetEventHandler()->ProcessEvent(event2
);
1833 node
= node
->GetNext();
1837 // the default action is to populate dialog with data when it's created
1838 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1840 TransferDataToWindow();
1843 // process Ctrl-Alt-mclick
1844 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
1847 if ( event
.ControlDown() && event
.AltDown() )
1849 // don't translate these strings
1852 #ifdef __WXUNIVERSAL__
1854 #endif // __WXUNIVERSAL__
1856 switch ( wxGetOsVersion() )
1858 case wxMOTIF_X
: port
= _T("Motif"); break;
1860 case wxMAC_DARWIN
: port
= _T("Mac"); break;
1861 case wxBEOS
: port
= _T("BeOS"); break;
1865 case wxGTK_BEOS
: port
= _T("GTK"); break;
1871 case wxWIN386
: port
= _T("MS Windows"); break;
1875 case wxMGL_OS2
: port
= _T("MGL"); break;
1877 case wxOS2_PM
: port
= _T("OS/2"); break;
1878 default: port
= _T("unknown"); break;
1881 wxMessageBox(wxString::Format(
1883 " wxWindows Library (%s port)\nVersion %u.%u.%u%s, compiled at %s %s\n Copyright (c) 1995-2002 wxWindows team"
1897 _T("wxWindows information"),
1898 wxICON_INFORMATION
| wxOK
,
1902 #endif // wxUSE_MSGDLG
1908 // ----------------------------------------------------------------------------
1909 // list classes implementation
1910 // ----------------------------------------------------------------------------
1912 void wxWindowListNode::DeleteData()
1914 delete (wxWindow
*)GetData();
1917 // ----------------------------------------------------------------------------
1919 // ----------------------------------------------------------------------------
1921 wxBorder
wxWindowBase::GetBorder() const
1923 wxBorder border
= (wxBorder
)(m_windowStyle
& wxBORDER_MASK
);
1924 if ( border
== wxBORDER_DEFAULT
)
1926 border
= GetDefaultBorder();
1932 wxBorder
wxWindowBase::GetDefaultBorder() const
1934 return wxBORDER_NONE
;
1937 // ----------------------------------------------------------------------------
1939 // ----------------------------------------------------------------------------
1941 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
1943 // here we just check if the point is inside the window or not
1945 // check the top and left border first
1946 bool outside
= x
< 0 || y
< 0;
1949 // check the right and bottom borders too
1950 wxSize size
= GetSize();
1951 outside
= x
>= size
.x
|| y
>= size
.y
;
1954 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
1957 // ----------------------------------------------------------------------------
1959 // ----------------------------------------------------------------------------
1961 struct WXDLLEXPORT wxWindowNext
1965 } *wxWindowBase::ms_winCaptureNext
= NULL
;
1967 void wxWindowBase::CaptureMouse()
1969 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this);
1971 wxWindow
*winOld
= GetCapture();
1974 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
1977 wxWindowNext
*item
= new wxWindowNext
;
1979 item
->next
= ms_winCaptureNext
;
1980 ms_winCaptureNext
= item
;
1982 //else: no mouse capture to save
1987 void wxWindowBase::ReleaseMouse()
1989 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this);
1991 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
1995 if ( ms_winCaptureNext
)
1997 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
1999 wxWindowNext
*item
= ms_winCaptureNext
;
2000 ms_winCaptureNext
= item
->next
;
2003 //else: stack is empty, no previous capture
2005 wxLogTrace(_T("mousecapture"),
2006 _T("After ReleaseMouse() mouse is captured by %p"),
2010 // ----------------------------------------------------------------------------
2012 // ----------------------------------------------------------------------------
2014 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2016 while ( win
&& !win
->IsTopLevel() )
2017 win
= win
->GetParent();