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/statbox.h"
42 #include "wx/textctrl.h"
43 #include "wx/settings.h"
44 #include "wx/dialog.h"
45 #include "wx/msgdlg.h"
46 #include "wx/statusbr.h"
50 #include "wx/layout.h"
51 #endif // wxUSE_CONSTRAINTS
55 #if wxUSE_DRAG_AND_DROP
57 #endif // wxUSE_DRAG_AND_DROP
60 #include "wx/cshelp.h"
64 #include "wx/tooltip.h"
65 #endif // wxUSE_TOOLTIPS
71 // ----------------------------------------------------------------------------
73 // ----------------------------------------------------------------------------
76 int wxWindowBase::ms_lastControlId
= 2000;
78 int wxWindowBase::ms_lastControlId
= -200;
81 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
83 // ----------------------------------------------------------------------------
85 // ----------------------------------------------------------------------------
87 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
88 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
89 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
90 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick
)
93 EVT_HELP(-1, wxWindowBase::OnHelp
)
98 // ============================================================================
99 // implementation of the common functionality of the wxWindow class
100 // ============================================================================
102 // ----------------------------------------------------------------------------
104 // ----------------------------------------------------------------------------
106 // the default initialization
107 void wxWindowBase::InitBase()
109 // no window yet, no parent nor children
110 m_parent
= (wxWindow
*)NULL
;
112 m_children
.DeleteContents( FALSE
); // don't auto delete node data
114 // no constraints on the minimal window size
120 // window is created enabled but it's not visible yet
124 // the default event handler is just this window
125 m_eventHandler
= this;
129 m_windowValidator
= (wxValidator
*) NULL
;
130 #endif // wxUSE_VALIDATORS
132 // use the system default colours
133 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
134 m_foregroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
136 // don't set the font here for wxMSW as we don't call WM_SETFONT here and
137 // so the font is *not* really set - but calls to SetFont() later won't do
138 // anything because m_font appears to be already set!
140 m_font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
143 // the colours/fonts are default for now
152 // an optimization for the event processing: checking this flag is much
153 // faster than using IsKindOf(CLASSINFO(wxWindow))
156 #if wxUSE_CONSTRAINTS
157 // no constraints whatsoever
158 m_constraints
= (wxLayoutConstraints
*) NULL
;
159 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
160 #endif // wxUSE_CONSTRAINTS
162 m_windowSizer
= (wxSizer
*) NULL
;
163 m_containingSizer
= (wxSizer
*) NULL
;
164 m_autoLayout
= FALSE
;
166 #if wxUSE_DRAG_AND_DROP
167 m_dropTarget
= (wxDropTarget
*)NULL
;
168 #endif // wxUSE_DRAG_AND_DROP
171 m_tooltip
= (wxToolTip
*)NULL
;
172 #endif // wxUSE_TOOLTIPS
175 m_caret
= (wxCaret
*)NULL
;
176 #endif // wxUSE_CARET
179 m_hasCustomPalette
= FALSE
;
180 #endif // wxUSE_PALETTE
182 m_virtualSize
= wxDefaultSize
;
187 m_maxVirtualHeight
= -1;
189 // Whether we're using the current theme for this window (wxGTK only for now)
190 m_themeEnabled
= FALSE
;
193 // common part of window creation process
194 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
196 const wxPoint
& WXUNUSED(pos
),
197 const wxSize
& WXUNUSED(size
),
199 const wxValidator
& validator
,
200 const wxString
& name
)
202 // m_isWindow is set to TRUE in wxWindowBase::Init() as well as many other
203 // member variables - check that it has been called (will catch the case
204 // when a new ctor is added which doesn't call InitWindow)
205 wxASSERT_MSG( m_isWindow
, wxT("Init() must have been called before!") );
208 // wxGTK doesn't allow to create controls with static box as the parent so
209 // this will result in a crash when the program is ported to wxGTK so warn
212 // if you get this assert, the correct solution is to create the controls
213 // as siblings of the static box
214 wxASSERT_MSG( !parent
|| !wxDynamicCast(parent
, wxStaticBox
),
215 _T("wxStaticBox can't be used as a window parent!") );
216 #endif // wxUSE_STATBOX
218 // generate a new id if the user doesn't care about it
219 m_windowId
= id
== -1 ? NewControlId() : id
;
222 SetWindowStyleFlag(style
);
226 SetValidator(validator
);
227 #endif // wxUSE_VALIDATORS
229 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
230 // have it too - like this it's possible to set it only in the top level
231 // dialog/frame and all children will inherit it by defult
232 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
234 SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY
);
240 // ----------------------------------------------------------------------------
242 // ----------------------------------------------------------------------------
245 wxWindowBase::~wxWindowBase()
247 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
249 // FIXME if these 2 cases result from programming errors in the user code
250 // we should probably assert here instead of silently fixing them
252 // Just in case the window has been Closed, but we're then deleting
253 // immediately: don't leave dangling pointers.
254 wxPendingDelete
.DeleteObject(this);
256 // Just in case we've loaded a top-level window via LoadNativeDialog but
257 // we weren't a dialog class
258 wxTopLevelWindows
.DeleteObject(this);
260 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
265 #endif // wxUSE_CARET
268 if ( m_windowValidator
)
269 delete m_windowValidator
;
270 #endif // wxUSE_VALIDATORS
272 #if wxUSE_CONSTRAINTS
273 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
274 // at deleted windows as they delete themselves.
275 DeleteRelatedConstraints();
279 // This removes any dangling pointers to this window in other windows'
280 // constraintsInvolvedIn lists.
281 UnsetConstraints(m_constraints
);
282 delete m_constraints
;
283 m_constraints
= NULL
;
286 #endif // wxUSE_CONSTRAINTS
288 if ( m_containingSizer
)
289 m_containingSizer
->Detach( (wxWindow
*)this );
292 delete m_windowSizer
;
294 #if wxUSE_DRAG_AND_DROP
297 #endif // wxUSE_DRAG_AND_DROP
302 #endif // wxUSE_TOOLTIPS
304 // reset the dangling pointer our parent window may keep to us
305 if ( m_parent
&& m_parent
->GetDefaultItem() == this )
307 m_parent
->SetDefaultItem(NULL
);
311 bool wxWindowBase::Destroy()
318 bool wxWindowBase::Close(bool force
)
320 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
321 event
.SetEventObject(this);
322 #if WXWIN_COMPATIBILITY
323 event
.SetForce(force
);
324 #endif // WXWIN_COMPATIBILITY
325 event
.SetCanVeto(!force
);
327 // return FALSE if window wasn't closed because the application vetoed the
329 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
332 bool wxWindowBase::DestroyChildren()
334 wxWindowList::Node
*node
;
337 // we iterate until the list becomes empty
338 node
= GetChildren().GetFirst();
342 wxWindow
*child
= node
->GetData();
344 wxASSERT_MSG( child
, wxT("children list contains empty nodes") );
349 wxASSERT_MSG( !GetChildren().Find(child
),
350 wxT("child didn't remove itself using RemoveChild()") );
356 // ----------------------------------------------------------------------------
357 // size/position related methods
358 // ----------------------------------------------------------------------------
360 // centre the window with respect to its parent in either (or both) directions
361 void wxWindowBase::Centre(int direction
)
363 // the position/size of the parent window or of the entire screen
365 int widthParent
, heightParent
;
367 wxWindow
*parent
= NULL
;
369 if ( !(direction
& wxCENTRE_ON_SCREEN
) )
371 // find the parent to centre this window on: it should be the
372 // immediate parent for the controls but the top level parent for the
373 // top level windows (like dialogs)
374 parent
= GetParent();
377 while ( parent
&& !parent
->IsTopLevel() )
379 parent
= parent
->GetParent();
383 // there is no wxTopLevelWindow under wxMotif yet
385 // we shouldn't center the dialog on the iconized window: under
386 // Windows, for example, this places it completely off the screen
389 wxTopLevelWindow
*winTop
= wxDynamicCast(parent
, wxTopLevelWindow
);
390 if ( winTop
&& winTop
->IsIconized() )
395 #endif // __WXMOTIF__
397 // did we find the parent?
401 direction
|= wxCENTRE_ON_SCREEN
;
405 if ( direction
& wxCENTRE_ON_SCREEN
)
407 // centre with respect to the whole screen
408 wxDisplaySize(&widthParent
, &heightParent
);
414 // centre on the parent
415 parent
->GetSize(&widthParent
, &heightParent
);
417 // adjust to the parents position
418 posParent
= parent
->GetPosition();
422 // centre inside the parents client rectangle
423 parent
->GetClientSize(&widthParent
, &heightParent
);
428 GetSize(&width
, &height
);
433 if ( direction
& wxHORIZONTAL
)
434 xNew
= (widthParent
- width
)/2;
436 if ( direction
& wxVERTICAL
)
437 yNew
= (heightParent
- height
)/2;
442 // Base size of the visible dimensions of the display
443 // to take into account the taskbar
444 wxRect rect
= wxGetClientDisplayRect();
445 wxSize
size (rect
.width
,rect
.height
);
447 // NB: in wxMSW, negative position may not neccessary mean "out of screen",
448 // but it may mean that the window is placed on other than the main
449 // display. Therefore we only make sure centered window is on the main display
450 // if the parent is at least partially present here.
451 if (posParent
.x
+ widthParent
>= 0) // if parent is (partially) on the main display
455 else if (xNew
+width
> size
.x
)
456 xNew
= size
.x
-width
-1;
458 if (posParent
.y
+ heightParent
>= 0) // if parent is (partially) on the main display
460 if (yNew
+height
> size
.y
)
461 yNew
= size
.y
-height
-1;
463 // Make certain that the title bar is initially visible
464 // always, even if this would push the bottom of the
465 // dialog of the visible area of the display
470 // move the window to this position (keeping the old size but using
471 // SetSize() and not Move() to allow xNew and/or yNew to be -1)
472 SetSize(xNew
, yNew
, width
, height
, wxSIZE_ALLOW_MINUS_ONE
);
475 // fits the window around the children
476 void wxWindowBase::Fit()
478 if ( GetChildren().GetCount() > 0 )
480 SetClientSize(DoGetBestSize());
482 //else: do nothing if we have no children
485 // fits virtual size (ie. scrolled area etc.) around children
486 void wxWindowBase::FitInside()
488 if ( GetChildren().GetCount() > 0 )
490 SetVirtualSize( GetBestVirtualSize() );
494 // return the size best suited for the current window
495 wxSize
wxWindowBase::DoGetBestSize() const
499 return m_windowSizer
->GetMinSize();
501 #if wxUSE_CONSTRAINTS
502 else if ( m_constraints
)
504 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
506 // our minimal acceptable size is such that all our windows fit inside
510 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
512 node
= node
->GetNext() )
514 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
517 // it's not normal that we have an unconstrained child, but
518 // what can we do about it?
522 int x
= c
->right
.GetValue(),
523 y
= c
->bottom
.GetValue();
531 // TODO: we must calculate the overlaps somehow, otherwise we
532 // will never return a size bigger than the current one :-(
535 return wxSize(maxX
, maxY
);
537 #endif // wxUSE_CONSTRAINTS
538 else if ( GetChildren().GetCount() > 0 )
540 // our minimal acceptable size is such that all our windows fit inside
544 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
546 node
= node
->GetNext() )
548 wxWindow
*win
= node
->GetData();
549 if ( win
->IsTopLevel()
551 || wxDynamicCast(win
, wxStatusBar
)
552 #endif // wxUSE_STATUSBAR
555 // dialogs and frames lie in different top level windows -
556 // don't deal with them here; as for the status bars, they
557 // don't lie in the client area at all
562 win
->GetPosition(&wx
, &wy
);
564 // if the window hadn't been positioned yet, assume that it is in
571 win
->GetSize(&ww
, &wh
);
572 if ( wx
+ ww
> maxX
)
574 if ( wy
+ wh
> maxY
)
578 // for compatibility with the old versions and because it really looks
579 // slightly more pretty like this, add a pad
583 return wxSize(maxX
, maxY
);
587 // for a generic window there is no natural best size - just use the
593 // by default the origin is not shifted
594 wxPoint
wxWindowBase::GetClientAreaOrigin() const
596 return wxPoint(0, 0);
599 // set the min/max size of the window
600 void wxWindowBase::SetSizeHints(int minW
, int minH
,
602 int WXUNUSED(incW
), int WXUNUSED(incH
))
610 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
613 m_minVirtualWidth
= minW
;
614 m_maxVirtualWidth
= maxW
;
615 m_minVirtualHeight
= minH
;
616 m_maxVirtualHeight
= maxH
;
619 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
621 if ( m_minVirtualWidth
!= -1 && m_minVirtualWidth
> x
)
622 x
= m_minVirtualWidth
;
623 if ( m_maxVirtualWidth
!= -1 && m_maxVirtualWidth
< x
)
624 x
= m_maxVirtualWidth
;
625 if ( m_minVirtualHeight
!= -1 && m_minVirtualHeight
> y
)
626 y
= m_minVirtualHeight
;
627 if ( m_maxVirtualHeight
!= -1 && m_maxVirtualHeight
< y
)
628 y
= m_maxVirtualHeight
;
630 m_virtualSize
= wxSize(x
, y
);
633 wxSize
wxWindowBase::DoGetVirtualSize() const
635 wxSize
s( GetClientSize() );
637 if( m_virtualSize
.GetWidth() != -1 )
638 s
.SetWidth( m_virtualSize
.GetWidth() );
639 if( m_virtualSize
.GetHeight() != -1 )
640 s
.SetHeight( m_virtualSize
.GetHeight() );
645 // ----------------------------------------------------------------------------
646 // show/hide/enable/disable the window
647 // ----------------------------------------------------------------------------
649 bool wxWindowBase::Show(bool show
)
651 if ( show
!= m_isShown
)
663 bool wxWindowBase::Enable(bool enable
)
665 if ( enable
!= m_isEnabled
)
667 m_isEnabled
= enable
;
676 // ----------------------------------------------------------------------------
678 // ----------------------------------------------------------------------------
680 bool wxWindowBase::IsTopLevel() const
685 // ----------------------------------------------------------------------------
686 // reparenting the window
687 // ----------------------------------------------------------------------------
689 void wxWindowBase::AddChild(wxWindowBase
*child
)
691 wxCHECK_RET( child
, wxT("can't add a NULL child") );
693 // this should never happen and it will lead to a crash later if it does
694 // because RemoveChild() will remove only one node from the children list
695 // and the other(s) one(s) will be left with dangling pointers in them
696 wxASSERT_MSG( !GetChildren().Find(child
), _T("AddChild() called twice") );
698 GetChildren().Append(child
);
699 child
->SetParent(this);
702 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
704 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
706 GetChildren().DeleteObject(child
);
707 child
->SetParent((wxWindow
*)NULL
);
710 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
712 wxWindow
*oldParent
= GetParent();
713 if ( newParent
== oldParent
)
719 // unlink this window from the existing parent.
722 oldParent
->RemoveChild(this);
726 wxTopLevelWindows
.DeleteObject(this);
729 // add it to the new one
732 newParent
->AddChild(this);
736 wxTopLevelWindows
.Append(this);
742 // ----------------------------------------------------------------------------
743 // event handler stuff
744 // ----------------------------------------------------------------------------
746 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
748 wxEvtHandler
*handlerOld
= GetEventHandler();
750 handler
->SetNextHandler(handlerOld
);
753 GetEventHandler()->SetPreviousHandler(handler
);
755 SetEventHandler(handler
);
758 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
760 wxEvtHandler
*handlerA
= GetEventHandler();
763 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
764 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
767 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
768 SetEventHandler(handlerB
);
773 handlerA
= (wxEvtHandler
*)NULL
;
780 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
782 wxCHECK_MSG( handler
, FALSE
, _T("RemoveEventHandler(NULL) called") );
784 wxEvtHandler
*handlerPrev
= NULL
,
785 *handlerCur
= GetEventHandler();
788 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
790 if ( handlerCur
== handler
)
794 handlerPrev
->SetNextHandler(handlerNext
);
798 SetEventHandler(handlerNext
);
803 handlerNext
->SetPreviousHandler ( handlerPrev
);
805 handler
->SetNextHandler(NULL
);
810 handlerPrev
= handlerCur
;
811 handlerCur
= handlerNext
;
814 wxFAIL_MSG( _T("where has the event handler gone?") );
819 // ----------------------------------------------------------------------------
821 // ----------------------------------------------------------------------------
823 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
825 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
828 m_backgroundColour
= colour
;
835 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
837 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
840 m_foregroundColour
= colour
;
847 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
849 // setting an invalid cursor is ok, it means that we don't have any special
851 if ( m_cursor
== cursor
)
862 bool wxWindowBase::SetFont(const wxFont
& font
)
864 // don't try to set invalid font, always fall back to the default
865 const wxFont
& fontOk
= font
.Ok() ? font
: *wxSWISS_FONT
;
867 if ( fontOk
== m_font
)
882 void wxWindowBase::SetPalette(const wxPalette
& pal
)
884 m_hasCustomPalette
= TRUE
;
887 // VZ: can anyone explain me what do we do here?
888 wxWindowDC
d((wxWindow
*) this);
892 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
894 wxWindow
*win
= (wxWindow
*)this;
895 while ( win
&& !win
->HasCustomPalette() )
897 win
= win
->GetParent();
903 #endif // wxUSE_PALETTE
906 void wxWindowBase::SetCaret(wxCaret
*caret
)
917 wxASSERT_MSG( m_caret
->GetWindow() == this,
918 wxT("caret should be created associated to this window") );
921 #endif // wxUSE_CARET
924 // ----------------------------------------------------------------------------
926 // ----------------------------------------------------------------------------
928 void wxWindowBase::SetValidator(const wxValidator
& validator
)
930 if ( m_windowValidator
)
931 delete m_windowValidator
;
933 m_windowValidator
= (wxValidator
*)validator
.Clone();
935 if ( m_windowValidator
)
936 m_windowValidator
->SetWindow(this) ;
938 #endif // wxUSE_VALIDATORS
940 // ----------------------------------------------------------------------------
941 // update region stuff
942 // ----------------------------------------------------------------------------
944 wxRect
wxWindowBase::GetUpdateClientRect() const
946 wxRegion rgnUpdate
= GetUpdateRegion();
947 rgnUpdate
.Intersect(GetClientRect());
948 wxRect rectUpdate
= rgnUpdate
.GetBox();
949 wxPoint ptOrigin
= GetClientAreaOrigin();
950 rectUpdate
.x
-= ptOrigin
.x
;
951 rectUpdate
.y
-= ptOrigin
.y
;
956 bool wxWindowBase::IsExposed(int x
, int y
) const
958 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
961 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
963 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
966 // ----------------------------------------------------------------------------
967 // find child window by id or name
968 // ----------------------------------------------------------------------------
970 wxWindow
*wxWindowBase::FindWindow( long id
)
972 if ( id
== m_windowId
)
973 return (wxWindow
*)this;
975 wxWindowBase
*res
= (wxWindow
*)NULL
;
976 wxWindowList::Node
*node
;
977 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
979 wxWindowBase
*child
= node
->GetData();
980 res
= child
->FindWindow( id
);
983 return (wxWindow
*)res
;
986 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
988 if ( name
== m_windowName
)
989 return (wxWindow
*)this;
991 wxWindowBase
*res
= (wxWindow
*)NULL
;
992 wxWindowList::Node
*node
;
993 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
995 wxWindow
*child
= node
->GetData();
996 res
= child
->FindWindow(name
);
999 return (wxWindow
*)res
;
1003 // find any window by id or name or label: If parent is non-NULL, look through
1004 // children for a label or title matching the specified string. If NULL, look
1005 // through all top-level windows.
1007 // to avoid duplicating code we reuse the same helper function but with
1008 // different comparators
1010 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1011 const wxString
& label
, long id
);
1014 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1017 return win
->GetLabel() == label
;
1021 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1024 return win
->GetName() == label
;
1028 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1031 return win
->GetId() == id
;
1034 // recursive helper for the FindWindowByXXX() functions
1036 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1037 const wxString
& label
,
1039 wxFindWindowCmp cmp
)
1043 // see if this is the one we're looking for
1044 if ( (*cmp
)(parent
, label
, id
) )
1045 return (wxWindow
*)parent
;
1047 // It wasn't, so check all its children
1048 for ( wxWindowList::Node
* node
= parent
->GetChildren().GetFirst();
1050 node
= node
->GetNext() )
1052 // recursively check each child
1053 wxWindow
*win
= (wxWindow
*)node
->GetData();
1054 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1064 // helper for FindWindowByXXX()
1066 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1067 const wxString
& label
,
1069 wxFindWindowCmp cmp
)
1073 // just check parent and all its children
1074 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1077 // start at very top of wx's windows
1078 for ( wxWindowList::Node
* node
= wxTopLevelWindows
.GetFirst();
1080 node
= node
->GetNext() )
1082 // recursively check each window & its children
1083 wxWindow
*win
= node
->GetData();
1084 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1094 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1096 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1101 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1103 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1107 // fall back to the label
1108 win
= FindWindowByLabel(title
, parent
);
1116 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1118 return wxFindWindowHelper(parent
, _T(""), id
, wxFindWindowCmpIds
);
1121 // ----------------------------------------------------------------------------
1122 // dialog oriented functions
1123 // ----------------------------------------------------------------------------
1125 void wxWindowBase::MakeModal(bool modal
)
1127 // Disable all other windows
1130 wxWindowList::Node
*node
= wxTopLevelWindows
.GetFirst();
1133 wxWindow
*win
= node
->GetData();
1135 win
->Enable(!modal
);
1137 node
= node
->GetNext();
1142 bool wxWindowBase::Validate()
1144 #if wxUSE_VALIDATORS
1145 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1147 wxWindowList::Node
*node
;
1148 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1150 wxWindowBase
*child
= node
->GetData();
1151 wxValidator
*validator
= child
->GetValidator();
1152 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1157 if ( recurse
&& !child
->Validate() )
1162 #endif // wxUSE_VALIDATORS
1167 bool wxWindowBase::TransferDataToWindow()
1169 #if wxUSE_VALIDATORS
1170 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1172 wxWindowList::Node
*node
;
1173 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1175 wxWindowBase
*child
= node
->GetData();
1176 wxValidator
*validator
= child
->GetValidator();
1177 if ( validator
&& !validator
->TransferToWindow() )
1179 wxLogWarning(_("Could not transfer data to window"));
1181 wxLog::FlushActive();
1189 if ( !child
->TransferDataToWindow() )
1191 // warning already given
1196 #endif // wxUSE_VALIDATORS
1201 bool wxWindowBase::TransferDataFromWindow()
1203 #if wxUSE_VALIDATORS
1204 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1206 wxWindowList::Node
*node
;
1207 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1209 wxWindow
*child
= node
->GetData();
1210 wxValidator
*validator
= child
->GetValidator();
1211 if ( validator
&& !validator
->TransferFromWindow() )
1213 // nop warning here because the application is supposed to give
1214 // one itself - we don't know here what might have gone wrongly
1221 if ( !child
->TransferDataFromWindow() )
1223 // warning already given
1228 #endif // wxUSE_VALIDATORS
1233 void wxWindowBase::InitDialog()
1235 wxInitDialogEvent
event(GetId());
1236 event
.SetEventObject( this );
1237 GetEventHandler()->ProcessEvent(event
);
1240 // ----------------------------------------------------------------------------
1241 // context-sensitive help support
1242 // ----------------------------------------------------------------------------
1246 // associate this help text with this window
1247 void wxWindowBase::SetHelpText(const wxString
& text
)
1249 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1252 helpProvider
->AddHelp(this, text
);
1256 // associate this help text with all windows with the same id as this
1258 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1260 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1263 helpProvider
->AddHelp(GetId(), text
);
1267 // get the help string associated with this window (may be empty)
1268 wxString
wxWindowBase::GetHelpText() const
1271 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1274 text
= helpProvider
->GetHelp(this);
1280 // show help for this window
1281 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1283 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1286 if ( helpProvider
->ShowHelp(this) )
1288 // skip the event.Skip() below
1296 #endif // wxUSE_HELP
1298 // ----------------------------------------------------------------------------
1299 // tooltipsroot.Replace("\\", "/");
1300 // ----------------------------------------------------------------------------
1304 void wxWindowBase::SetToolTip( const wxString
&tip
)
1306 // don't create the new tooltip if we already have one
1309 m_tooltip
->SetTip( tip
);
1313 SetToolTip( new wxToolTip( tip
) );
1316 // setting empty tooltip text does not remove the tooltip any more - use
1317 // SetToolTip((wxToolTip *)NULL) for this
1320 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1325 m_tooltip
= tooltip
;
1328 #endif // wxUSE_TOOLTIPS
1330 // ----------------------------------------------------------------------------
1331 // constraints and sizers
1332 // ----------------------------------------------------------------------------
1334 #if wxUSE_CONSTRAINTS
1336 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1338 if ( m_constraints
)
1340 UnsetConstraints(m_constraints
);
1341 delete m_constraints
;
1343 m_constraints
= constraints
;
1344 if ( m_constraints
)
1346 // Make sure other windows know they're part of a 'meaningful relationship'
1347 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1348 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1349 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1350 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1351 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1352 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1353 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1354 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1355 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1356 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1357 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1358 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1359 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1360 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1361 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1362 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1366 // This removes any dangling pointers to this window in other windows'
1367 // constraintsInvolvedIn lists.
1368 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1372 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1373 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1374 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1375 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1376 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1377 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1378 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1379 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1380 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1381 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1382 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1383 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1384 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1385 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1386 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1387 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1391 // Back-pointer to other windows we're involved with, so if we delete this
1392 // window, we must delete any constraints we're involved with.
1393 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1395 if ( !m_constraintsInvolvedIn
)
1396 m_constraintsInvolvedIn
= new wxWindowList
;
1397 if ( !m_constraintsInvolvedIn
->Find(otherWin
) )
1398 m_constraintsInvolvedIn
->Append(otherWin
);
1401 // REMOVE back-pointer to other windows we're involved with.
1402 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1404 if ( m_constraintsInvolvedIn
)
1405 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
1408 // Reset any constraints that mention this window
1409 void wxWindowBase::DeleteRelatedConstraints()
1411 if ( m_constraintsInvolvedIn
)
1413 wxWindowList::Node
*node
= m_constraintsInvolvedIn
->GetFirst();
1416 wxWindow
*win
= node
->GetData();
1417 wxLayoutConstraints
*constr
= win
->GetConstraints();
1419 // Reset any constraints involving this window
1422 constr
->left
.ResetIfWin(this);
1423 constr
->top
.ResetIfWin(this);
1424 constr
->right
.ResetIfWin(this);
1425 constr
->bottom
.ResetIfWin(this);
1426 constr
->width
.ResetIfWin(this);
1427 constr
->height
.ResetIfWin(this);
1428 constr
->centreX
.ResetIfWin(this);
1429 constr
->centreY
.ResetIfWin(this);
1432 wxWindowList::Node
*next
= node
->GetNext();
1437 delete m_constraintsInvolvedIn
;
1438 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1442 #endif // wxUSE_CONSTRAINTS
1444 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1447 delete m_windowSizer
;
1449 m_windowSizer
= sizer
;
1451 SetAutoLayout( sizer
!= NULL
);
1454 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1456 SetSizer( sizer
, deleteOld
);
1457 sizer
->SetSizeHints( (wxWindow
*) this );
1460 #if wxUSE_CONSTRAINTS
1462 void wxWindowBase::SatisfyConstraints()
1464 wxLayoutConstraints
*constr
= GetConstraints();
1465 bool wasOk
= constr
&& constr
->AreSatisfied();
1467 ResetConstraints(); // Mark all constraints as unevaluated
1471 // if we're a top level panel (i.e. our parent is frame/dialog), our
1472 // own constraints will never be satisfied any more unless we do it
1476 while ( noChanges
> 0 )
1478 LayoutPhase1(&noChanges
);
1482 LayoutPhase2(&noChanges
);
1485 #endif // wxUSE_CONSTRAINTS
1487 bool wxWindowBase::Layout()
1489 // If there is a sizer, use it instead of the constraints
1493 GetVirtualSize(&w
, &h
);
1494 GetSizer()->SetDimension( 0, 0, w
, h
);
1496 #if wxUSE_CONSTRAINTS
1499 SatisfyConstraints(); // Find the right constraints values
1500 SetConstraintSizes(); // Recursively set the real window sizes
1507 #if wxUSE_CONSTRAINTS
1509 // first phase of the constraints evaluation: set our own constraints
1510 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1512 wxLayoutConstraints
*constr
= GetConstraints();
1514 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1517 // second phase: set the constraints for our children
1518 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1525 // Layout grand children
1531 // Do a phase of evaluating child constraints
1532 bool wxWindowBase::DoPhase(int phase
)
1534 // the list containing the children for which the constraints are already
1536 wxWindowList succeeded
;
1538 // the max number of iterations we loop before concluding that we can't set
1540 static const int maxIterations
= 500;
1542 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1546 // loop over all children setting their constraints
1547 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
1549 node
= node
->GetNext() )
1551 wxWindow
*child
= node
->GetData();
1552 if ( child
->IsTopLevel() )
1554 // top level children are not inside our client area
1558 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1560 // this one is either already ok or nothing we can do about it
1564 int tempNoChanges
= 0;
1565 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1566 : child
->LayoutPhase2(&tempNoChanges
);
1567 noChanges
+= tempNoChanges
;
1571 succeeded
.Append(child
);
1577 // constraints are set
1585 void wxWindowBase::ResetConstraints()
1587 wxLayoutConstraints
*constr
= GetConstraints();
1590 constr
->left
.SetDone(FALSE
);
1591 constr
->top
.SetDone(FALSE
);
1592 constr
->right
.SetDone(FALSE
);
1593 constr
->bottom
.SetDone(FALSE
);
1594 constr
->width
.SetDone(FALSE
);
1595 constr
->height
.SetDone(FALSE
);
1596 constr
->centreX
.SetDone(FALSE
);
1597 constr
->centreY
.SetDone(FALSE
);
1600 wxWindowList::Node
*node
= GetChildren().GetFirst();
1603 wxWindow
*win
= node
->GetData();
1604 if ( !win
->IsTopLevel() )
1605 win
->ResetConstraints();
1606 node
= node
->GetNext();
1610 // Need to distinguish between setting the 'fake' size for windows and sizers,
1611 // and setting the real values.
1612 void wxWindowBase::SetConstraintSizes(bool recurse
)
1614 wxLayoutConstraints
*constr
= GetConstraints();
1615 if ( constr
&& constr
->AreSatisfied() )
1617 int x
= constr
->left
.GetValue();
1618 int y
= constr
->top
.GetValue();
1619 int w
= constr
->width
.GetValue();
1620 int h
= constr
->height
.GetValue();
1622 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1623 (constr
->height
.GetRelationship() != wxAsIs
) )
1625 SetSize(x
, y
, w
, h
);
1629 // If we don't want to resize this window, just move it...
1635 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1636 GetClassInfo()->GetClassName(),
1642 wxWindowList::Node
*node
= GetChildren().GetFirst();
1645 wxWindow
*win
= node
->GetData();
1646 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1647 win
->SetConstraintSizes();
1648 node
= node
->GetNext();
1653 // Only set the size/position of the constraint (if any)
1654 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1656 wxLayoutConstraints
*constr
= GetConstraints();
1661 constr
->left
.SetValue(x
);
1662 constr
->left
.SetDone(TRUE
);
1666 constr
->top
.SetValue(y
);
1667 constr
->top
.SetDone(TRUE
);
1671 constr
->width
.SetValue(w
);
1672 constr
->width
.SetDone(TRUE
);
1676 constr
->height
.SetValue(h
);
1677 constr
->height
.SetDone(TRUE
);
1682 void wxWindowBase::MoveConstraint(int x
, int y
)
1684 wxLayoutConstraints
*constr
= GetConstraints();
1689 constr
->left
.SetValue(x
);
1690 constr
->left
.SetDone(TRUE
);
1694 constr
->top
.SetValue(y
);
1695 constr
->top
.SetDone(TRUE
);
1700 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1702 wxLayoutConstraints
*constr
= GetConstraints();
1705 *w
= constr
->width
.GetValue();
1706 *h
= constr
->height
.GetValue();
1712 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1714 wxLayoutConstraints
*constr
= GetConstraints();
1717 *w
= constr
->width
.GetValue();
1718 *h
= constr
->height
.GetValue();
1721 GetClientSize(w
, h
);
1724 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1726 wxLayoutConstraints
*constr
= GetConstraints();
1729 *x
= constr
->left
.GetValue();
1730 *y
= constr
->top
.GetValue();
1736 #endif // wxUSE_CONSTRAINTS
1738 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
1740 // don't do it for the dialogs/frames - they float independently of their
1742 if ( !IsTopLevel() )
1744 wxWindow
*parent
= GetParent();
1745 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
1747 wxPoint
pt(parent
->GetClientAreaOrigin());
1754 // ----------------------------------------------------------------------------
1755 // do Update UI processing for child controls
1756 // ----------------------------------------------------------------------------
1758 // TODO: should this be implemented for the child window rather
1759 // than the parent? Then you can override it e.g. for wxCheckBox
1760 // to do the Right Thing rather than having to assume a fixed number
1761 // of control classes.
1762 void wxWindowBase::UpdateWindowUI()
1765 wxUpdateUIEvent
event(GetId());
1766 event
.m_eventObject
= this;
1768 if ( GetEventHandler()->ProcessEvent(event
) )
1770 if ( event
.GetSetEnabled() )
1771 Enable(event
.GetEnabled());
1773 if ( event
.GetSetText() )
1775 wxControl
*control
= wxDynamicCastThis(wxControl
);
1779 wxTextCtrl
*text
= wxDynamicCast(control
, wxTextCtrl
);
1782 if ( event
.GetText() != text
->GetValue() )
1783 text
->SetValue(event
.GetText());
1786 #endif // wxUSE_TEXTCTRL
1788 if ( event
.GetText() != control
->GetLabel() )
1789 control
->SetLabel(event
.GetText());
1795 wxCheckBox
*checkbox
= wxDynamicCastThis(wxCheckBox
);
1798 if ( event
.GetSetChecked() )
1799 checkbox
->SetValue(event
.GetChecked());
1801 #endif // wxUSE_CHECKBOX
1804 wxRadioButton
*radiobtn
= wxDynamicCastThis(wxRadioButton
);
1807 if ( event
.GetSetChecked() )
1808 radiobtn
->SetValue(event
.GetChecked());
1810 #endif // wxUSE_RADIOBTN
1812 #endif // wxUSE_CONTROLS
1815 // ----------------------------------------------------------------------------
1816 // dialog units translations
1817 // ----------------------------------------------------------------------------
1819 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1821 int charWidth
= GetCharWidth();
1822 int charHeight
= GetCharHeight();
1823 wxPoint
pt2(-1, -1);
1825 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1827 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1832 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1834 int charWidth
= GetCharWidth();
1835 int charHeight
= GetCharHeight();
1836 wxPoint
pt2(-1, -1);
1838 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1840 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1845 // ----------------------------------------------------------------------------
1847 // ----------------------------------------------------------------------------
1849 // propagate the colour change event to the subwindows
1850 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1852 wxWindowList::Node
*node
= GetChildren().GetFirst();
1855 // Only propagate to non-top-level windows
1856 wxWindow
*win
= node
->GetData();
1857 if ( !win
->IsTopLevel() )
1859 wxSysColourChangedEvent event2
;
1860 event
.m_eventObject
= win
;
1861 win
->GetEventHandler()->ProcessEvent(event2
);
1864 node
= node
->GetNext();
1868 // the default action is to populate dialog with data when it's created
1869 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1871 TransferDataToWindow();
1874 // process Ctrl-Alt-mclick
1875 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
1878 if ( event
.ControlDown() && event
.AltDown() )
1880 // don't translate these strings
1883 #ifdef __WXUNIVERSAL__
1885 #endif // __WXUNIVERSAL__
1887 switch ( wxGetOsVersion() )
1889 case wxMOTIF_X
: port
+= _T("Motif"); break;
1891 case wxMAC_DARWIN
: port
+= _T("Mac"); break;
1892 case wxBEOS
: port
+= _T("BeOS"); break;
1896 case wxGTK_BEOS
: port
+= _T("GTK"); break;
1902 case wxWIN386
: port
+= _T("MS Windows"); break;
1906 case wxMGL_OS2
: port
+= _T("MGL"); break;
1908 case wxOS2_PM
: port
+= _T("OS/2"); break;
1909 default: port
+= _T("unknown"); break;
1912 wxMessageBox(wxString::Format(
1914 " wxWindows Library (%s port)\nVersion %u.%u.%u%s, compiled at %s %s\n Copyright (c) 1995-2002 wxWindows team"
1928 _T("wxWindows information"),
1929 wxICON_INFORMATION
| wxOK
,
1933 #endif // wxUSE_MSGDLG
1939 // ----------------------------------------------------------------------------
1940 // list classes implementation
1941 // ----------------------------------------------------------------------------
1943 void wxWindowListNode::DeleteData()
1945 delete (wxWindow
*)GetData();
1948 // ----------------------------------------------------------------------------
1950 // ----------------------------------------------------------------------------
1952 wxBorder
wxWindowBase::GetBorder() const
1954 wxBorder border
= (wxBorder
)(m_windowStyle
& wxBORDER_MASK
);
1955 if ( border
== wxBORDER_DEFAULT
)
1957 border
= GetDefaultBorder();
1963 wxBorder
wxWindowBase::GetDefaultBorder() const
1965 return wxBORDER_NONE
;
1968 // ----------------------------------------------------------------------------
1970 // ----------------------------------------------------------------------------
1972 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
1974 // here we just check if the point is inside the window or not
1976 // check the top and left border first
1977 bool outside
= x
< 0 || y
< 0;
1980 // check the right and bottom borders too
1981 wxSize size
= GetSize();
1982 outside
= x
>= size
.x
|| y
>= size
.y
;
1985 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
1988 // ----------------------------------------------------------------------------
1990 // ----------------------------------------------------------------------------
1992 struct WXDLLEXPORT wxWindowNext
1996 } *wxWindowBase::ms_winCaptureNext
= NULL
;
1998 void wxWindowBase::CaptureMouse()
2000 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this);
2002 wxWindow
*winOld
= GetCapture();
2005 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2008 wxWindowNext
*item
= new wxWindowNext
;
2010 item
->next
= ms_winCaptureNext
;
2011 ms_winCaptureNext
= item
;
2013 //else: no mouse capture to save
2018 void wxWindowBase::ReleaseMouse()
2020 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this);
2022 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2026 if ( ms_winCaptureNext
)
2028 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2030 wxWindowNext
*item
= ms_winCaptureNext
;
2031 ms_winCaptureNext
= item
->next
;
2034 //else: stack is empty, no previous capture
2036 wxLogTrace(_T("mousecapture"),
2037 _T("After ReleaseMouse() mouse is captured by %p"),
2041 // ----------------------------------------------------------------------------
2043 // ----------------------------------------------------------------------------
2045 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2047 while ( win
&& !win
->IsTopLevel() )
2048 win
= win
->GetParent();