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 // fits virtual size (ie. scrolled area etc.) around children
474 void wxWindowBase::FitInside()
476 if ( GetChildren().GetCount() > 0 )
478 SetVirtualSize( GetBestVirtualSize() );
482 // return the size best suited for the current window
483 wxSize
wxWindowBase::DoGetBestSize() const
487 return m_windowSizer
->GetMinSize();
489 #if wxUSE_CONSTRAINTS
490 else if ( m_constraints
)
492 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
494 // our minimal acceptable size is such that all our windows fit inside
498 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
500 node
= node
->GetNext() )
502 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
505 // it's not normal that we have an unconstrained child, but
506 // what can we do about it?
510 int x
= c
->right
.GetValue(),
511 y
= c
->bottom
.GetValue();
519 // TODO: we must calculate the overlaps somehow, otherwise we
520 // will never return a size bigger than the current one :-(
523 return wxSize(maxX
, maxY
);
525 #endif // wxUSE_CONSTRAINTS
526 else if ( GetChildren().GetCount() > 0 )
528 // our minimal acceptable size is such that all our windows fit inside
532 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
534 node
= node
->GetNext() )
536 wxWindow
*win
= node
->GetData();
537 if ( win
->IsTopLevel()
539 || wxDynamicCast(win
, wxStatusBar
)
540 #endif // wxUSE_STATUSBAR
543 // dialogs and frames lie in different top level windows -
544 // don't deal with them here; as for the status bars, they
545 // don't lie in the client area at all
550 win
->GetPosition(&wx
, &wy
);
552 // if the window hadn't been positioned yet, assume that it is in
559 win
->GetSize(&ww
, &wh
);
560 if ( wx
+ ww
> maxX
)
562 if ( wy
+ wh
> maxY
)
566 // for compatibility with the old versions and because it really looks
567 // slightly more pretty like this, add a pad
571 return wxSize(maxX
, maxY
);
575 // for a generic window there is no natural best size - just use the
581 // by default the origin is not shifted
582 wxPoint
wxWindowBase::GetClientAreaOrigin() const
584 return wxPoint(0, 0);
587 // set the min/max size of the window
588 void wxWindowBase::SetSizeHints(int minW
, int minH
,
590 int WXUNUSED(incW
), int WXUNUSED(incH
))
598 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
601 m_minVirtualWidth
= minW
;
602 m_maxVirtualWidth
= maxW
;
603 m_minVirtualHeight
= minH
;
604 m_maxVirtualHeight
= maxH
;
607 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
609 if ( m_minVirtualWidth
!= -1 && m_minVirtualWidth
> x
)
610 x
= m_minVirtualWidth
;
611 if ( m_maxVirtualWidth
!= -1 && m_maxVirtualWidth
< x
)
612 x
= m_maxVirtualWidth
;
613 if ( m_minVirtualHeight
!= -1 && m_minVirtualHeight
> y
)
614 y
= m_minVirtualHeight
;
615 if ( m_maxVirtualHeight
!= -1 && m_maxVirtualHeight
< y
)
616 y
= m_maxVirtualHeight
;
618 m_virtualSize
= wxSize(x
, y
);
621 wxSize
wxWindowBase::DoGetVirtualSize() const
623 wxSize
s( GetClientSize() );
625 if( m_virtualSize
.GetWidth() != -1 )
626 s
.SetWidth( m_virtualSize
.GetWidth() );
627 if( m_virtualSize
.GetHeight() != -1 )
628 s
.SetHeight( m_virtualSize
.GetHeight() );
633 // ----------------------------------------------------------------------------
634 // show/hide/enable/disable the window
635 // ----------------------------------------------------------------------------
637 bool wxWindowBase::Show(bool show
)
639 if ( show
!= m_isShown
)
651 bool wxWindowBase::Enable(bool enable
)
653 if ( enable
!= m_isEnabled
)
655 m_isEnabled
= enable
;
664 // ----------------------------------------------------------------------------
666 // ----------------------------------------------------------------------------
668 bool wxWindowBase::IsTopLevel() const
673 // ----------------------------------------------------------------------------
674 // reparenting the window
675 // ----------------------------------------------------------------------------
677 void wxWindowBase::AddChild(wxWindowBase
*child
)
679 wxCHECK_RET( child
, wxT("can't add a NULL child") );
681 // this should never happen and it will lead to a crash later if it does
682 // because RemoveChild() will remove only one node from the children list
683 // and the other(s) one(s) will be left with dangling pointers in them
684 wxASSERT_MSG( !GetChildren().Find(child
), _T("AddChild() called twice") );
686 GetChildren().Append(child
);
687 child
->SetParent(this);
690 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
692 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
694 GetChildren().DeleteObject(child
);
695 child
->SetParent((wxWindow
*)NULL
);
698 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
700 wxWindow
*oldParent
= GetParent();
701 if ( newParent
== oldParent
)
707 // unlink this window from the existing parent.
710 oldParent
->RemoveChild(this);
714 wxTopLevelWindows
.DeleteObject(this);
717 // add it to the new one
720 newParent
->AddChild(this);
724 wxTopLevelWindows
.Append(this);
730 // ----------------------------------------------------------------------------
731 // event handler stuff
732 // ----------------------------------------------------------------------------
734 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
736 wxEvtHandler
*handlerOld
= GetEventHandler();
738 handler
->SetNextHandler(handlerOld
);
741 GetEventHandler()->SetPreviousHandler(handler
);
743 SetEventHandler(handler
);
746 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
748 wxEvtHandler
*handlerA
= GetEventHandler();
751 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
752 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
755 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
756 SetEventHandler(handlerB
);
761 handlerA
= (wxEvtHandler
*)NULL
;
768 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
770 wxCHECK_MSG( handler
, FALSE
, _T("RemoveEventHandler(NULL) called") );
772 wxEvtHandler
*handlerPrev
= NULL
,
773 *handlerCur
= GetEventHandler();
776 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
778 if ( handlerCur
== handler
)
782 handlerPrev
->SetNextHandler(handlerNext
);
786 SetEventHandler(handlerNext
);
791 handlerNext
->SetPreviousHandler ( handlerPrev
);
793 handler
->SetNextHandler(NULL
);
798 handlerPrev
= handlerCur
;
799 handlerCur
= handlerNext
;
802 wxFAIL_MSG( _T("where has the event handler gone?") );
807 // ----------------------------------------------------------------------------
809 // ----------------------------------------------------------------------------
811 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
813 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
816 m_backgroundColour
= colour
;
823 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
825 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
828 m_foregroundColour
= colour
;
835 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
837 // setting an invalid cursor is ok, it means that we don't have any special
839 if ( m_cursor
== cursor
)
850 bool wxWindowBase::SetFont(const wxFont
& font
)
852 // don't try to set invalid font, always fall back to the default
853 const wxFont
& fontOk
= font
.Ok() ? font
: *wxSWISS_FONT
;
855 if ( fontOk
== m_font
)
870 void wxWindowBase::SetPalette(const wxPalette
& pal
)
872 m_hasCustomPalette
= TRUE
;
875 // VZ: can anyone explain me what do we do here?
876 wxWindowDC
d((wxWindow
*) this);
880 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
882 wxWindow
*win
= (wxWindow
*)this;
883 while ( win
&& !win
->HasCustomPalette() )
885 win
= win
->GetParent();
891 #endif // wxUSE_PALETTE
894 void wxWindowBase::SetCaret(wxCaret
*caret
)
905 wxASSERT_MSG( m_caret
->GetWindow() == this,
906 wxT("caret should be created associated to this window") );
909 #endif // wxUSE_CARET
912 // ----------------------------------------------------------------------------
914 // ----------------------------------------------------------------------------
916 void wxWindowBase::SetValidator(const wxValidator
& validator
)
918 if ( m_windowValidator
)
919 delete m_windowValidator
;
921 m_windowValidator
= (wxValidator
*)validator
.Clone();
923 if ( m_windowValidator
)
924 m_windowValidator
->SetWindow(this) ;
926 #endif // wxUSE_VALIDATORS
928 // ----------------------------------------------------------------------------
929 // update region stuff
930 // ----------------------------------------------------------------------------
932 wxRect
wxWindowBase::GetUpdateClientRect() const
934 wxRegion rgnUpdate
= GetUpdateRegion();
935 rgnUpdate
.Intersect(GetClientRect());
936 wxRect rectUpdate
= rgnUpdate
.GetBox();
937 wxPoint ptOrigin
= GetClientAreaOrigin();
938 rectUpdate
.x
-= ptOrigin
.x
;
939 rectUpdate
.y
-= ptOrigin
.y
;
944 bool wxWindowBase::IsExposed(int x
, int y
) const
946 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
949 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
951 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
954 // ----------------------------------------------------------------------------
955 // find child window by id or name
956 // ----------------------------------------------------------------------------
958 wxWindow
*wxWindowBase::FindWindow( long id
)
960 if ( id
== m_windowId
)
961 return (wxWindow
*)this;
963 wxWindowBase
*res
= (wxWindow
*)NULL
;
964 wxWindowList::Node
*node
;
965 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
967 wxWindowBase
*child
= node
->GetData();
968 res
= child
->FindWindow( id
);
971 return (wxWindow
*)res
;
974 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
976 if ( name
== m_windowName
)
977 return (wxWindow
*)this;
979 wxWindowBase
*res
= (wxWindow
*)NULL
;
980 wxWindowList::Node
*node
;
981 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
983 wxWindow
*child
= node
->GetData();
984 res
= child
->FindWindow(name
);
987 return (wxWindow
*)res
;
991 // find any window by id or name or label: If parent is non-NULL, look through
992 // children for a label or title matching the specified string. If NULL, look
993 // through all top-level windows.
995 // to avoid duplicating code we reuse the same helper function but with
996 // different comparators
998 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
999 const wxString
& label
, long id
);
1002 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1005 return win
->GetLabel() == label
;
1009 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1012 return win
->GetName() == label
;
1016 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1019 return win
->GetId() == id
;
1022 // recursive helper for the FindWindowByXXX() functions
1024 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1025 const wxString
& label
,
1027 wxFindWindowCmp cmp
)
1031 // see if this is the one we're looking for
1032 if ( (*cmp
)(parent
, label
, id
) )
1033 return (wxWindow
*)parent
;
1035 // It wasn't, so check all its children
1036 for ( wxWindowList::Node
* node
= parent
->GetChildren().GetFirst();
1038 node
= node
->GetNext() )
1040 // recursively check each child
1041 wxWindow
*win
= (wxWindow
*)node
->GetData();
1042 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1052 // helper for FindWindowByXXX()
1054 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1055 const wxString
& label
,
1057 wxFindWindowCmp cmp
)
1061 // just check parent and all its children
1062 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1065 // start at very top of wx's windows
1066 for ( wxWindowList::Node
* node
= wxTopLevelWindows
.GetFirst();
1068 node
= node
->GetNext() )
1070 // recursively check each window & its children
1071 wxWindow
*win
= node
->GetData();
1072 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1082 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1084 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1089 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1091 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1095 // fall back to the label
1096 win
= FindWindowByLabel(title
, parent
);
1104 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1106 return wxFindWindowHelper(parent
, _T(""), id
, wxFindWindowCmpIds
);
1109 // ----------------------------------------------------------------------------
1110 // dialog oriented functions
1111 // ----------------------------------------------------------------------------
1113 void wxWindowBase::MakeModal(bool modal
)
1115 // Disable all other windows
1118 wxWindowList::Node
*node
= wxTopLevelWindows
.GetFirst();
1121 wxWindow
*win
= node
->GetData();
1123 win
->Enable(!modal
);
1125 node
= node
->GetNext();
1130 bool wxWindowBase::Validate()
1132 #if wxUSE_VALIDATORS
1133 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1135 wxWindowList::Node
*node
;
1136 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1138 wxWindowBase
*child
= node
->GetData();
1139 wxValidator
*validator
= child
->GetValidator();
1140 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1145 if ( recurse
&& !child
->Validate() )
1150 #endif // wxUSE_VALIDATORS
1155 bool wxWindowBase::TransferDataToWindow()
1157 #if wxUSE_VALIDATORS
1158 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1160 wxWindowList::Node
*node
;
1161 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1163 wxWindowBase
*child
= node
->GetData();
1164 wxValidator
*validator
= child
->GetValidator();
1165 if ( validator
&& !validator
->TransferToWindow() )
1167 wxLogWarning(_("Could not transfer data to window"));
1168 wxLog::FlushActive();
1175 if ( !child
->TransferDataToWindow() )
1177 // warning already given
1182 #endif // wxUSE_VALIDATORS
1187 bool wxWindowBase::TransferDataFromWindow()
1189 #if wxUSE_VALIDATORS
1190 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1192 wxWindowList::Node
*node
;
1193 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1195 wxWindow
*child
= node
->GetData();
1196 wxValidator
*validator
= child
->GetValidator();
1197 if ( validator
&& !validator
->TransferFromWindow() )
1199 // nop warning here because the application is supposed to give
1200 // one itself - we don't know here what might have gone wrongly
1207 if ( !child
->TransferDataFromWindow() )
1209 // warning already given
1214 #endif // wxUSE_VALIDATORS
1219 void wxWindowBase::InitDialog()
1221 wxInitDialogEvent
event(GetId());
1222 event
.SetEventObject( this );
1223 GetEventHandler()->ProcessEvent(event
);
1226 // ----------------------------------------------------------------------------
1227 // context-sensitive help support
1228 // ----------------------------------------------------------------------------
1232 // associate this help text with this window
1233 void wxWindowBase::SetHelpText(const wxString
& text
)
1235 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1238 helpProvider
->AddHelp(this, text
);
1242 // associate this help text with all windows with the same id as this
1244 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1246 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1249 helpProvider
->AddHelp(GetId(), text
);
1253 // get the help string associated with this window (may be empty)
1254 wxString
wxWindowBase::GetHelpText() const
1257 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1260 text
= helpProvider
->GetHelp(this);
1266 // show help for this window
1267 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1269 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1272 if ( helpProvider
->ShowHelp(this) )
1274 // skip the event.Skip() below
1282 #endif // wxUSE_HELP
1284 // ----------------------------------------------------------------------------
1285 // tooltipsroot.Replace("\\", "/");
1286 // ----------------------------------------------------------------------------
1290 void wxWindowBase::SetToolTip( const wxString
&tip
)
1292 // don't create the new tooltip if we already have one
1295 m_tooltip
->SetTip( tip
);
1299 SetToolTip( new wxToolTip( tip
) );
1302 // setting empty tooltip text does not remove the tooltip any more - use
1303 // SetToolTip((wxToolTip *)NULL) for this
1306 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1311 m_tooltip
= tooltip
;
1314 #endif // wxUSE_TOOLTIPS
1316 // ----------------------------------------------------------------------------
1317 // constraints and sizers
1318 // ----------------------------------------------------------------------------
1320 #if wxUSE_CONSTRAINTS
1322 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1324 if ( m_constraints
)
1326 UnsetConstraints(m_constraints
);
1327 delete m_constraints
;
1329 m_constraints
= constraints
;
1330 if ( m_constraints
)
1332 // Make sure other windows know they're part of a 'meaningful relationship'
1333 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1334 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1335 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1336 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1337 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1338 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1339 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1340 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1341 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1342 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1343 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1344 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1345 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1346 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1347 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1348 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1352 // This removes any dangling pointers to this window in other windows'
1353 // constraintsInvolvedIn lists.
1354 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1358 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1359 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1360 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1361 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1362 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1363 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1364 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1365 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1366 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1367 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1368 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1369 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1370 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1371 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1372 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1373 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1377 // Back-pointer to other windows we're involved with, so if we delete this
1378 // window, we must delete any constraints we're involved with.
1379 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1381 if ( !m_constraintsInvolvedIn
)
1382 m_constraintsInvolvedIn
= new wxWindowList
;
1383 if ( !m_constraintsInvolvedIn
->Find(otherWin
) )
1384 m_constraintsInvolvedIn
->Append(otherWin
);
1387 // REMOVE back-pointer to other windows we're involved with.
1388 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1390 if ( m_constraintsInvolvedIn
)
1391 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
1394 // Reset any constraints that mention this window
1395 void wxWindowBase::DeleteRelatedConstraints()
1397 if ( m_constraintsInvolvedIn
)
1399 wxWindowList::Node
*node
= m_constraintsInvolvedIn
->GetFirst();
1402 wxWindow
*win
= node
->GetData();
1403 wxLayoutConstraints
*constr
= win
->GetConstraints();
1405 // Reset any constraints involving this window
1408 constr
->left
.ResetIfWin(this);
1409 constr
->top
.ResetIfWin(this);
1410 constr
->right
.ResetIfWin(this);
1411 constr
->bottom
.ResetIfWin(this);
1412 constr
->width
.ResetIfWin(this);
1413 constr
->height
.ResetIfWin(this);
1414 constr
->centreX
.ResetIfWin(this);
1415 constr
->centreY
.ResetIfWin(this);
1418 wxWindowList::Node
*next
= node
->GetNext();
1423 delete m_constraintsInvolvedIn
;
1424 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1428 #endif // wxUSE_CONSTRAINTS
1430 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1433 delete m_windowSizer
;
1435 m_windowSizer
= sizer
;
1437 SetAutoLayout( sizer
!= NULL
);
1440 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1442 SetSizer( sizer
, deleteOld
);
1443 sizer
->SetSizeHints( (wxWindow
*) this );
1446 #if wxUSE_CONSTRAINTS
1448 void wxWindowBase::SatisfyConstraints()
1450 wxLayoutConstraints
*constr
= GetConstraints();
1451 bool wasOk
= constr
&& constr
->AreSatisfied();
1453 ResetConstraints(); // Mark all constraints as unevaluated
1457 // if we're a top level panel (i.e. our parent is frame/dialog), our
1458 // own constraints will never be satisfied any more unless we do it
1462 while ( noChanges
> 0 )
1464 LayoutPhase1(&noChanges
);
1468 LayoutPhase2(&noChanges
);
1471 #endif // wxUSE_CONSTRAINTS
1473 bool wxWindowBase::Layout()
1475 // If there is a sizer, use it instead of the constraints
1479 GetVirtualSize(&w
, &h
);
1480 GetSizer()->SetDimension( 0, 0, w
, h
);
1482 #if wxUSE_CONSTRAINTS
1485 SatisfyConstraints(); // Find the right constraints values
1486 SetConstraintSizes(); // Recursively set the real window sizes
1493 #if wxUSE_CONSTRAINTS
1495 // first phase of the constraints evaluation: set our own constraints
1496 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1498 wxLayoutConstraints
*constr
= GetConstraints();
1500 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1503 // second phase: set the constraints for our children
1504 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1511 // Layout grand children
1517 // Do a phase of evaluating child constraints
1518 bool wxWindowBase::DoPhase(int phase
)
1520 // the list containing the children for which the constraints are already
1522 wxWindowList succeeded
;
1524 // the max number of iterations we loop before concluding that we can't set
1526 static const int maxIterations
= 500;
1528 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1532 // loop over all children setting their constraints
1533 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
1535 node
= node
->GetNext() )
1537 wxWindow
*child
= node
->GetData();
1538 if ( child
->IsTopLevel() )
1540 // top level children are not inside our client area
1544 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1546 // this one is either already ok or nothing we can do about it
1550 int tempNoChanges
= 0;
1551 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1552 : child
->LayoutPhase2(&tempNoChanges
);
1553 noChanges
+= tempNoChanges
;
1557 succeeded
.Append(child
);
1563 // constraints are set
1571 void wxWindowBase::ResetConstraints()
1573 wxLayoutConstraints
*constr
= GetConstraints();
1576 constr
->left
.SetDone(FALSE
);
1577 constr
->top
.SetDone(FALSE
);
1578 constr
->right
.SetDone(FALSE
);
1579 constr
->bottom
.SetDone(FALSE
);
1580 constr
->width
.SetDone(FALSE
);
1581 constr
->height
.SetDone(FALSE
);
1582 constr
->centreX
.SetDone(FALSE
);
1583 constr
->centreY
.SetDone(FALSE
);
1586 wxWindowList::Node
*node
= GetChildren().GetFirst();
1589 wxWindow
*win
= node
->GetData();
1590 if ( !win
->IsTopLevel() )
1591 win
->ResetConstraints();
1592 node
= node
->GetNext();
1596 // Need to distinguish between setting the 'fake' size for windows and sizers,
1597 // and setting the real values.
1598 void wxWindowBase::SetConstraintSizes(bool recurse
)
1600 wxLayoutConstraints
*constr
= GetConstraints();
1601 if ( constr
&& constr
->AreSatisfied() )
1603 int x
= constr
->left
.GetValue();
1604 int y
= constr
->top
.GetValue();
1605 int w
= constr
->width
.GetValue();
1606 int h
= constr
->height
.GetValue();
1608 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1609 (constr
->height
.GetRelationship() != wxAsIs
) )
1611 SetSize(x
, y
, w
, h
);
1615 // If we don't want to resize this window, just move it...
1621 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1622 GetClassInfo()->GetClassName(),
1628 wxWindowList::Node
*node
= GetChildren().GetFirst();
1631 wxWindow
*win
= node
->GetData();
1632 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1633 win
->SetConstraintSizes();
1634 node
= node
->GetNext();
1639 // Only set the size/position of the constraint (if any)
1640 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1642 wxLayoutConstraints
*constr
= GetConstraints();
1647 constr
->left
.SetValue(x
);
1648 constr
->left
.SetDone(TRUE
);
1652 constr
->top
.SetValue(y
);
1653 constr
->top
.SetDone(TRUE
);
1657 constr
->width
.SetValue(w
);
1658 constr
->width
.SetDone(TRUE
);
1662 constr
->height
.SetValue(h
);
1663 constr
->height
.SetDone(TRUE
);
1668 void wxWindowBase::MoveConstraint(int x
, int y
)
1670 wxLayoutConstraints
*constr
= GetConstraints();
1675 constr
->left
.SetValue(x
);
1676 constr
->left
.SetDone(TRUE
);
1680 constr
->top
.SetValue(y
);
1681 constr
->top
.SetDone(TRUE
);
1686 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1688 wxLayoutConstraints
*constr
= GetConstraints();
1691 *w
= constr
->width
.GetValue();
1692 *h
= constr
->height
.GetValue();
1698 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1700 wxLayoutConstraints
*constr
= GetConstraints();
1703 *w
= constr
->width
.GetValue();
1704 *h
= constr
->height
.GetValue();
1707 GetClientSize(w
, h
);
1710 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1712 wxLayoutConstraints
*constr
= GetConstraints();
1715 *x
= constr
->left
.GetValue();
1716 *y
= constr
->top
.GetValue();
1722 #endif // wxUSE_CONSTRAINTS
1724 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
1726 // don't do it for the dialogs/frames - they float independently of their
1728 if ( !IsTopLevel() )
1730 wxWindow
*parent
= GetParent();
1731 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
1733 wxPoint
pt(parent
->GetClientAreaOrigin());
1740 // ----------------------------------------------------------------------------
1741 // do Update UI processing for child controls
1742 // ----------------------------------------------------------------------------
1744 // TODO: should this be implemented for the child window rather
1745 // than the parent? Then you can override it e.g. for wxCheckBox
1746 // to do the Right Thing rather than having to assume a fixed number
1747 // of control classes.
1748 void wxWindowBase::UpdateWindowUI()
1751 wxUpdateUIEvent
event(GetId());
1752 event
.m_eventObject
= this;
1754 if ( GetEventHandler()->ProcessEvent(event
) )
1756 if ( event
.GetSetEnabled() )
1757 Enable(event
.GetEnabled());
1759 if ( event
.GetSetText() )
1761 wxControl
*control
= wxDynamicCastThis(wxControl
);
1765 wxTextCtrl
*text
= wxDynamicCast(control
, wxTextCtrl
);
1768 if ( event
.GetText() != text
->GetValue() )
1769 text
->SetValue(event
.GetText());
1772 #endif // wxUSE_TEXTCTRL
1774 if ( event
.GetText() != control
->GetLabel() )
1775 control
->SetLabel(event
.GetText());
1781 wxCheckBox
*checkbox
= wxDynamicCastThis(wxCheckBox
);
1784 if ( event
.GetSetChecked() )
1785 checkbox
->SetValue(event
.GetChecked());
1787 #endif // wxUSE_CHECKBOX
1790 wxRadioButton
*radiobtn
= wxDynamicCastThis(wxRadioButton
);
1793 if ( event
.GetSetChecked() )
1794 radiobtn
->SetValue(event
.GetChecked());
1796 #endif // wxUSE_RADIOBTN
1798 #endif // wxUSE_CONTROLS
1801 // ----------------------------------------------------------------------------
1802 // dialog units translations
1803 // ----------------------------------------------------------------------------
1805 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1807 int charWidth
= GetCharWidth();
1808 int charHeight
= GetCharHeight();
1809 wxPoint
pt2(-1, -1);
1811 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1813 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1818 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1820 int charWidth
= GetCharWidth();
1821 int charHeight
= GetCharHeight();
1822 wxPoint
pt2(-1, -1);
1824 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1826 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1831 // ----------------------------------------------------------------------------
1833 // ----------------------------------------------------------------------------
1835 // propagate the colour change event to the subwindows
1836 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1838 wxWindowList::Node
*node
= GetChildren().GetFirst();
1841 // Only propagate to non-top-level windows
1842 wxWindow
*win
= node
->GetData();
1843 if ( !win
->IsTopLevel() )
1845 wxSysColourChangedEvent event2
;
1846 event
.m_eventObject
= win
;
1847 win
->GetEventHandler()->ProcessEvent(event2
);
1850 node
= node
->GetNext();
1854 // the default action is to populate dialog with data when it's created
1855 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1857 TransferDataToWindow();
1860 // process Ctrl-Alt-mclick
1861 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
1864 if ( event
.ControlDown() && event
.AltDown() )
1866 // don't translate these strings
1869 #ifdef __WXUNIVERSAL__
1871 #endif // __WXUNIVERSAL__
1873 switch ( wxGetOsVersion() )
1875 case wxMOTIF_X
: port
= _T("Motif"); break;
1877 case wxMAC_DARWIN
: port
= _T("Mac"); break;
1878 case wxBEOS
: port
= _T("BeOS"); break;
1882 case wxGTK_BEOS
: port
= _T("GTK"); break;
1888 case wxWIN386
: port
= _T("MS Windows"); break;
1892 case wxMGL_OS2
: port
= _T("MGL"); break;
1894 case wxOS2_PM
: port
= _T("OS/2"); break;
1895 default: port
= _T("unknown"); break;
1898 wxMessageBox(wxString::Format(
1900 " wxWindows Library (%s port)\nVersion %u.%u.%u%s, compiled at %s %s\n Copyright (c) 1995-2002 wxWindows team"
1914 _T("wxWindows information"),
1915 wxICON_INFORMATION
| wxOK
,
1919 #endif // wxUSE_MSGDLG
1925 // ----------------------------------------------------------------------------
1926 // list classes implementation
1927 // ----------------------------------------------------------------------------
1929 void wxWindowListNode::DeleteData()
1931 delete (wxWindow
*)GetData();
1934 // ----------------------------------------------------------------------------
1936 // ----------------------------------------------------------------------------
1938 wxBorder
wxWindowBase::GetBorder() const
1940 wxBorder border
= (wxBorder
)(m_windowStyle
& wxBORDER_MASK
);
1941 if ( border
== wxBORDER_DEFAULT
)
1943 border
= GetDefaultBorder();
1949 wxBorder
wxWindowBase::GetDefaultBorder() const
1951 return wxBORDER_NONE
;
1954 // ----------------------------------------------------------------------------
1956 // ----------------------------------------------------------------------------
1958 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
1960 // here we just check if the point is inside the window or not
1962 // check the top and left border first
1963 bool outside
= x
< 0 || y
< 0;
1966 // check the right and bottom borders too
1967 wxSize size
= GetSize();
1968 outside
= x
>= size
.x
|| y
>= size
.y
;
1971 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
1974 // ----------------------------------------------------------------------------
1976 // ----------------------------------------------------------------------------
1978 struct WXDLLEXPORT wxWindowNext
1982 } *wxWindowBase::ms_winCaptureNext
= NULL
;
1984 void wxWindowBase::CaptureMouse()
1986 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this);
1988 wxWindow
*winOld
= GetCapture();
1991 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
1994 wxWindowNext
*item
= new wxWindowNext
;
1996 item
->next
= ms_winCaptureNext
;
1997 ms_winCaptureNext
= item
;
1999 //else: no mouse capture to save
2004 void wxWindowBase::ReleaseMouse()
2006 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this);
2008 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2012 if ( ms_winCaptureNext
)
2014 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2016 wxWindowNext
*item
= ms_winCaptureNext
;
2017 ms_winCaptureNext
= item
->next
;
2020 //else: stack is empty, no previous capture
2022 wxLogTrace(_T("mousecapture"),
2023 _T("After ReleaseMouse() mouse is captured by %p"),
2027 // ----------------------------------------------------------------------------
2029 // ----------------------------------------------------------------------------
2031 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2033 while ( win
&& !win
->IsTopLevel() )
2034 win
= win
->GetParent();