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"
47 #include "wx/dcclient.h"
51 #include "wx/layout.h"
52 #endif // wxUSE_CONSTRAINTS
56 #if wxUSE_DRAG_AND_DROP
58 #endif // wxUSE_DRAG_AND_DROP
61 #include "wx/cshelp.h"
65 #include "wx/tooltip.h"
66 #endif // wxUSE_TOOLTIPS
72 // ----------------------------------------------------------------------------
74 // ----------------------------------------------------------------------------
77 int wxWindowBase::ms_lastControlId
= 2000;
79 int wxWindowBase::ms_lastControlId
= -200;
82 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
84 // ----------------------------------------------------------------------------
86 // ----------------------------------------------------------------------------
88 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
89 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
90 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
91 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick
)
94 EVT_HELP(-1, wxWindowBase::OnHelp
)
99 // ============================================================================
100 // implementation of the common functionality of the wxWindow class
101 // ============================================================================
103 // ----------------------------------------------------------------------------
105 // ----------------------------------------------------------------------------
107 // the default initialization
108 void wxWindowBase::InitBase()
110 // no window yet, no parent nor children
111 m_parent
= (wxWindow
*)NULL
;
113 m_children
.DeleteContents( FALSE
); // don't auto delete node data
115 // no constraints on the minimal window size
121 // window is created enabled but it's not visible yet
125 // the default event handler is just this window
126 m_eventHandler
= this;
130 m_windowValidator
= (wxValidator
*) NULL
;
131 #endif // wxUSE_VALIDATORS
133 // use the system default colours
134 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
135 m_foregroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
137 // don't set the font here for wxMSW as we don't call WM_SETFONT here and
138 // so the font is *not* really set - but calls to SetFont() later won't do
139 // anything because m_font appears to be already set!
141 m_font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
144 // the colours/fonts are default for now
153 // an optimization for the event processing: checking this flag is much
154 // faster than using IsKindOf(CLASSINFO(wxWindow))
157 #if wxUSE_CONSTRAINTS
158 // no constraints whatsoever
159 m_constraints
= (wxLayoutConstraints
*) NULL
;
160 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
161 #endif // wxUSE_CONSTRAINTS
163 m_windowSizer
= (wxSizer
*) NULL
;
164 m_containingSizer
= (wxSizer
*) NULL
;
165 m_autoLayout
= FALSE
;
167 #if wxUSE_DRAG_AND_DROP
168 m_dropTarget
= (wxDropTarget
*)NULL
;
169 #endif // wxUSE_DRAG_AND_DROP
172 m_tooltip
= (wxToolTip
*)NULL
;
173 #endif // wxUSE_TOOLTIPS
176 m_caret
= (wxCaret
*)NULL
;
177 #endif // wxUSE_CARET
180 m_hasCustomPalette
= FALSE
;
181 #endif // wxUSE_PALETTE
183 m_virtualSize
= wxDefaultSize
;
188 m_maxVirtualHeight
= -1;
190 // Whether we're using the current theme for this window (wxGTK only for now)
191 m_themeEnabled
= FALSE
;
194 // common part of window creation process
195 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
197 const wxPoint
& WXUNUSED(pos
),
198 const wxSize
& WXUNUSED(size
),
200 const wxValidator
& validator
,
201 const wxString
& name
)
203 // m_isWindow is set to TRUE in wxWindowBase::Init() as well as many other
204 // member variables - check that it has been called (will catch the case
205 // when a new ctor is added which doesn't call InitWindow)
206 wxASSERT_MSG( m_isWindow
, wxT("Init() must have been called before!") );
209 // wxGTK doesn't allow to create controls with static box as the parent so
210 // this will result in a crash when the program is ported to wxGTK so warn
213 // if you get this assert, the correct solution is to create the controls
214 // as siblings of the static box
215 wxASSERT_MSG( !parent
|| !wxDynamicCast(parent
, wxStaticBox
),
216 _T("wxStaticBox can't be used as a window parent!") );
217 #endif // wxUSE_STATBOX
219 // generate a new id if the user doesn't care about it
220 m_windowId
= id
== -1 ? NewControlId() : id
;
223 SetWindowStyleFlag(style
);
227 SetValidator(validator
);
228 #endif // wxUSE_VALIDATORS
230 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
231 // have it too - like this it's possible to set it only in the top level
232 // dialog/frame and all children will inherit it by defult
233 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
235 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
241 // ----------------------------------------------------------------------------
243 // ----------------------------------------------------------------------------
246 wxWindowBase::~wxWindowBase()
248 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
250 // FIXME if these 2 cases result from programming errors in the user code
251 // we should probably assert here instead of silently fixing them
253 // Just in case the window has been Closed, but we're then deleting
254 // immediately: don't leave dangling pointers.
255 wxPendingDelete
.DeleteObject(this);
257 // Just in case we've loaded a top-level window via LoadNativeDialog but
258 // we weren't a dialog class
259 wxTopLevelWindows
.DeleteObject(this);
261 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
266 #endif // wxUSE_CARET
269 if ( m_windowValidator
)
270 delete m_windowValidator
;
271 #endif // wxUSE_VALIDATORS
273 #if wxUSE_CONSTRAINTS
274 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
275 // at deleted windows as they delete themselves.
276 DeleteRelatedConstraints();
280 // This removes any dangling pointers to this window in other windows'
281 // constraintsInvolvedIn lists.
282 UnsetConstraints(m_constraints
);
283 delete m_constraints
;
284 m_constraints
= NULL
;
287 #endif // wxUSE_CONSTRAINTS
289 if ( m_containingSizer
)
290 m_containingSizer
->Detach( (wxWindow
*)this );
293 delete m_windowSizer
;
295 #if wxUSE_DRAG_AND_DROP
298 #endif // wxUSE_DRAG_AND_DROP
303 #endif // wxUSE_TOOLTIPS
305 // reset the dangling pointer our parent window may keep to us
306 if ( m_parent
&& m_parent
->GetDefaultItem() == this )
308 m_parent
->SetDefaultItem(NULL
);
312 bool wxWindowBase::Destroy()
319 bool wxWindowBase::Close(bool force
)
321 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
322 event
.SetEventObject(this);
323 #if WXWIN_COMPATIBILITY
324 event
.SetForce(force
);
325 #endif // WXWIN_COMPATIBILITY
326 event
.SetCanVeto(!force
);
328 // return FALSE if window wasn't closed because the application vetoed the
330 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
333 bool wxWindowBase::DestroyChildren()
335 wxWindowList::Node
*node
;
338 // we iterate until the list becomes empty
339 node
= GetChildren().GetFirst();
343 wxWindow
*child
= node
->GetData();
345 wxASSERT_MSG( child
, wxT("children list contains empty nodes") );
350 wxASSERT_MSG( !GetChildren().Find(child
),
351 wxT("child didn't remove itself using RemoveChild()") );
357 // ----------------------------------------------------------------------------
358 // size/position related methods
359 // ----------------------------------------------------------------------------
361 // centre the window with respect to its parent in either (or both) directions
362 void wxWindowBase::Centre(int direction
)
364 // the position/size of the parent window or of the entire screen
366 int widthParent
, heightParent
;
368 wxWindow
*parent
= NULL
;
370 if ( !(direction
& wxCENTRE_ON_SCREEN
) )
372 // find the parent to centre this window on: it should be the
373 // immediate parent for the controls but the top level parent for the
374 // top level windows (like dialogs)
375 parent
= GetParent();
378 while ( parent
&& !parent
->IsTopLevel() )
380 parent
= parent
->GetParent();
384 // there is no wxTopLevelWindow under wxMotif yet
386 // we shouldn't center the dialog on the iconized window: under
387 // Windows, for example, this places it completely off the screen
390 wxTopLevelWindow
*winTop
= wxDynamicCast(parent
, wxTopLevelWindow
);
391 if ( winTop
&& winTop
->IsIconized() )
396 #endif // __WXMOTIF__
398 // did we find the parent?
402 direction
|= wxCENTRE_ON_SCREEN
;
406 if ( direction
& wxCENTRE_ON_SCREEN
)
408 // centre with respect to the whole screen
409 wxDisplaySize(&widthParent
, &heightParent
);
415 // centre on the parent
416 parent
->GetSize(&widthParent
, &heightParent
);
418 // adjust to the parents position
419 posParent
= parent
->GetPosition();
423 // centre inside the parents client rectangle
424 parent
->GetClientSize(&widthParent
, &heightParent
);
429 GetSize(&width
, &height
);
434 if ( direction
& wxHORIZONTAL
)
435 xNew
= (widthParent
- width
)/2;
437 if ( direction
& wxVERTICAL
)
438 yNew
= (heightParent
- height
)/2;
443 // Base size of the visible dimensions of the display
444 // to take into account the taskbar
445 wxRect rect
= wxGetClientDisplayRect();
446 wxSize
size (rect
.width
,rect
.height
);
448 // NB: in wxMSW, negative position may not neccessary mean "out of screen",
449 // but it may mean that the window is placed on other than the main
450 // display. Therefore we only make sure centered window is on the main display
451 // if the parent is at least partially present here.
452 if (posParent
.x
+ widthParent
>= 0) // if parent is (partially) on the main display
456 else if (xNew
+width
> size
.x
)
457 xNew
= size
.x
-width
-1;
459 if (posParent
.y
+ heightParent
>= 0) // if parent is (partially) on the main display
461 if (yNew
+height
> size
.y
)
462 yNew
= size
.y
-height
-1;
464 // Make certain that the title bar is initially visible
465 // always, even if this would push the bottom of the
466 // dialog of the visible area of the display
471 // move the window to this position (keeping the old size but using
472 // SetSize() and not Move() to allow xNew and/or yNew to be -1)
473 SetSize(xNew
, yNew
, width
, height
, wxSIZE_ALLOW_MINUS_ONE
);
476 // fits the window around the children
477 void wxWindowBase::Fit()
479 if ( GetChildren().GetCount() > 0 )
481 SetClientSize(DoGetBestSize());
483 //else: do nothing if we have no children
486 // fits virtual size (ie. scrolled area etc.) around children
487 void wxWindowBase::FitInside()
489 if ( GetChildren().GetCount() > 0 )
491 SetVirtualSize( GetBestVirtualSize() );
495 // return the size best suited for the current window
496 wxSize
wxWindowBase::DoGetBestSize() const
500 return m_windowSizer
->GetMinSize();
502 #if wxUSE_CONSTRAINTS
503 else if ( m_constraints
)
505 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
507 // our minimal acceptable size is such that all our windows fit inside
511 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
513 node
= node
->GetNext() )
515 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
518 // it's not normal that we have an unconstrained child, but
519 // what can we do about it?
523 int x
= c
->right
.GetValue(),
524 y
= c
->bottom
.GetValue();
532 // TODO: we must calculate the overlaps somehow, otherwise we
533 // will never return a size bigger than the current one :-(
536 return wxSize(maxX
, maxY
);
538 #endif // wxUSE_CONSTRAINTS
539 else if ( GetChildren().GetCount() > 0 )
541 // our minimal acceptable size is such that all our windows fit inside
545 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
547 node
= node
->GetNext() )
549 wxWindow
*win
= node
->GetData();
550 if ( win
->IsTopLevel()
552 || wxDynamicCast(win
, wxStatusBar
)
553 #endif // wxUSE_STATUSBAR
556 // dialogs and frames lie in different top level windows -
557 // don't deal with them here; as for the status bars, they
558 // don't lie in the client area at all
563 win
->GetPosition(&wx
, &wy
);
565 // if the window hadn't been positioned yet, assume that it is in
572 win
->GetSize(&ww
, &wh
);
573 if ( wx
+ ww
> maxX
)
575 if ( wy
+ wh
> maxY
)
579 // for compatibility with the old versions and because it really looks
580 // slightly more pretty like this, add a pad
584 return wxSize(maxX
, maxY
);
588 // for a generic window there is no natural best size - just use the
594 // by default the origin is not shifted
595 wxPoint
wxWindowBase::GetClientAreaOrigin() const
597 return wxPoint(0, 0);
600 // set the min/max size of the window
601 void wxWindowBase::SetSizeHints(int minW
, int minH
,
603 int WXUNUSED(incW
), int WXUNUSED(incH
))
611 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
614 m_minVirtualWidth
= minW
;
615 m_maxVirtualWidth
= maxW
;
616 m_minVirtualHeight
= minH
;
617 m_maxVirtualHeight
= maxH
;
620 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
622 if ( m_minVirtualWidth
!= -1 && m_minVirtualWidth
> x
)
623 x
= m_minVirtualWidth
;
624 if ( m_maxVirtualWidth
!= -1 && m_maxVirtualWidth
< x
)
625 x
= m_maxVirtualWidth
;
626 if ( m_minVirtualHeight
!= -1 && m_minVirtualHeight
> y
)
627 y
= m_minVirtualHeight
;
628 if ( m_maxVirtualHeight
!= -1 && m_maxVirtualHeight
< y
)
629 y
= m_maxVirtualHeight
;
631 m_virtualSize
= wxSize(x
, y
);
634 wxSize
wxWindowBase::DoGetVirtualSize() const
636 wxSize
s( GetClientSize() );
638 return wxSize( wxMax( m_virtualSize
.GetWidth(), s
.GetWidth() ),
639 wxMax( m_virtualSize
.GetHeight(), s
.GetHeight() ) );
642 // ----------------------------------------------------------------------------
643 // show/hide/enable/disable the window
644 // ----------------------------------------------------------------------------
646 bool wxWindowBase::Show(bool show
)
648 if ( show
!= m_isShown
)
660 bool wxWindowBase::Enable(bool enable
)
662 if ( enable
!= m_isEnabled
)
664 m_isEnabled
= enable
;
673 // ----------------------------------------------------------------------------
675 // ----------------------------------------------------------------------------
677 bool wxWindowBase::IsTopLevel() const
682 // ----------------------------------------------------------------------------
683 // reparenting the window
684 // ----------------------------------------------------------------------------
686 void wxWindowBase::AddChild(wxWindowBase
*child
)
688 wxCHECK_RET( child
, wxT("can't add a NULL child") );
690 // this should never happen and it will lead to a crash later if it does
691 // because RemoveChild() will remove only one node from the children list
692 // and the other(s) one(s) will be left with dangling pointers in them
693 wxASSERT_MSG( !GetChildren().Find(child
), _T("AddChild() called twice") );
695 GetChildren().Append(child
);
696 child
->SetParent(this);
699 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
701 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
703 GetChildren().DeleteObject(child
);
704 child
->SetParent((wxWindow
*)NULL
);
707 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
709 wxWindow
*oldParent
= GetParent();
710 if ( newParent
== oldParent
)
716 // unlink this window from the existing parent.
719 oldParent
->RemoveChild(this);
723 wxTopLevelWindows
.DeleteObject(this);
726 // add it to the new one
729 newParent
->AddChild(this);
733 wxTopLevelWindows
.Append(this);
739 // ----------------------------------------------------------------------------
740 // event handler stuff
741 // ----------------------------------------------------------------------------
743 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
745 wxEvtHandler
*handlerOld
= GetEventHandler();
747 handler
->SetNextHandler(handlerOld
);
750 GetEventHandler()->SetPreviousHandler(handler
);
752 SetEventHandler(handler
);
755 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
757 wxEvtHandler
*handlerA
= GetEventHandler();
760 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
761 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
764 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
765 SetEventHandler(handlerB
);
770 handlerA
= (wxEvtHandler
*)NULL
;
777 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
779 wxCHECK_MSG( handler
, FALSE
, _T("RemoveEventHandler(NULL) called") );
781 wxEvtHandler
*handlerPrev
= NULL
,
782 *handlerCur
= GetEventHandler();
785 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
787 if ( handlerCur
== handler
)
791 handlerPrev
->SetNextHandler(handlerNext
);
795 SetEventHandler(handlerNext
);
800 handlerNext
->SetPreviousHandler ( handlerPrev
);
802 handler
->SetNextHandler(NULL
);
807 handlerPrev
= handlerCur
;
808 handlerCur
= handlerNext
;
811 wxFAIL_MSG( _T("where has the event handler gone?") );
816 // ----------------------------------------------------------------------------
818 // ----------------------------------------------------------------------------
820 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
822 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
825 m_backgroundColour
= colour
;
832 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
834 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
837 m_foregroundColour
= colour
;
844 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
846 // setting an invalid cursor is ok, it means that we don't have any special
848 if ( m_cursor
== cursor
)
859 bool wxWindowBase::SetFont(const wxFont
& font
)
861 // don't try to set invalid font, always fall back to the default
862 const wxFont
& fontOk
= font
.Ok() ? font
: *wxSWISS_FONT
;
864 if ( fontOk
== m_font
)
879 void wxWindowBase::SetPalette(const wxPalette
& pal
)
881 m_hasCustomPalette
= TRUE
;
884 // VZ: can anyone explain me what do we do here?
885 wxWindowDC
d((wxWindow
*) this);
889 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
891 wxWindow
*win
= (wxWindow
*)this;
892 while ( win
&& !win
->HasCustomPalette() )
894 win
= win
->GetParent();
900 #endif // wxUSE_PALETTE
903 void wxWindowBase::SetCaret(wxCaret
*caret
)
914 wxASSERT_MSG( m_caret
->GetWindow() == this,
915 wxT("caret should be created associated to this window") );
918 #endif // wxUSE_CARET
921 // ----------------------------------------------------------------------------
923 // ----------------------------------------------------------------------------
925 void wxWindowBase::SetValidator(const wxValidator
& validator
)
927 if ( m_windowValidator
)
928 delete m_windowValidator
;
930 m_windowValidator
= (wxValidator
*)validator
.Clone();
932 if ( m_windowValidator
)
933 m_windowValidator
->SetWindow(this) ;
935 #endif // wxUSE_VALIDATORS
937 // ----------------------------------------------------------------------------
938 // update region stuff
939 // ----------------------------------------------------------------------------
941 wxRect
wxWindowBase::GetUpdateClientRect() const
943 wxRegion rgnUpdate
= GetUpdateRegion();
944 rgnUpdate
.Intersect(GetClientRect());
945 wxRect rectUpdate
= rgnUpdate
.GetBox();
946 wxPoint ptOrigin
= GetClientAreaOrigin();
947 rectUpdate
.x
-= ptOrigin
.x
;
948 rectUpdate
.y
-= ptOrigin
.y
;
953 bool wxWindowBase::IsExposed(int x
, int y
) const
955 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
958 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
960 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
963 // ----------------------------------------------------------------------------
964 // find child window by id or name
965 // ----------------------------------------------------------------------------
967 wxWindow
*wxWindowBase::FindWindow( long id
)
969 if ( id
== m_windowId
)
970 return (wxWindow
*)this;
972 wxWindowBase
*res
= (wxWindow
*)NULL
;
973 wxWindowList::Node
*node
;
974 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
976 wxWindowBase
*child
= node
->GetData();
977 res
= child
->FindWindow( id
);
980 return (wxWindow
*)res
;
983 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
985 if ( name
== m_windowName
)
986 return (wxWindow
*)this;
988 wxWindowBase
*res
= (wxWindow
*)NULL
;
989 wxWindowList::Node
*node
;
990 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
992 wxWindow
*child
= node
->GetData();
993 res
= child
->FindWindow(name
);
996 return (wxWindow
*)res
;
1000 // find any window by id or name or label: If parent is non-NULL, look through
1001 // children for a label or title matching the specified string. If NULL, look
1002 // through all top-level windows.
1004 // to avoid duplicating code we reuse the same helper function but with
1005 // different comparators
1007 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1008 const wxString
& label
, long id
);
1011 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1014 return win
->GetLabel() == label
;
1018 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1021 return win
->GetName() == label
;
1025 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1028 return win
->GetId() == id
;
1031 // recursive helper for the FindWindowByXXX() functions
1033 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1034 const wxString
& label
,
1036 wxFindWindowCmp cmp
)
1040 // see if this is the one we're looking for
1041 if ( (*cmp
)(parent
, label
, id
) )
1042 return (wxWindow
*)parent
;
1044 // It wasn't, so check all its children
1045 for ( wxWindowList::Node
* node
= parent
->GetChildren().GetFirst();
1047 node
= node
->GetNext() )
1049 // recursively check each child
1050 wxWindow
*win
= (wxWindow
*)node
->GetData();
1051 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1061 // helper for FindWindowByXXX()
1063 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1064 const wxString
& label
,
1066 wxFindWindowCmp cmp
)
1070 // just check parent and all its children
1071 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1074 // start at very top of wx's windows
1075 for ( wxWindowList::Node
* node
= wxTopLevelWindows
.GetFirst();
1077 node
= node
->GetNext() )
1079 // recursively check each window & its children
1080 wxWindow
*win
= node
->GetData();
1081 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1091 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1093 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1098 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1100 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1104 // fall back to the label
1105 win
= FindWindowByLabel(title
, parent
);
1113 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1115 return wxFindWindowHelper(parent
, _T(""), id
, wxFindWindowCmpIds
);
1118 // ----------------------------------------------------------------------------
1119 // dialog oriented functions
1120 // ----------------------------------------------------------------------------
1122 void wxWindowBase::MakeModal(bool modal
)
1124 // Disable all other windows
1127 wxWindowList::Node
*node
= wxTopLevelWindows
.GetFirst();
1130 wxWindow
*win
= node
->GetData();
1132 win
->Enable(!modal
);
1134 node
= node
->GetNext();
1139 bool wxWindowBase::Validate()
1141 #if wxUSE_VALIDATORS
1142 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1144 wxWindowList::Node
*node
;
1145 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1147 wxWindowBase
*child
= node
->GetData();
1148 wxValidator
*validator
= child
->GetValidator();
1149 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1154 if ( recurse
&& !child
->Validate() )
1159 #endif // wxUSE_VALIDATORS
1164 bool wxWindowBase::TransferDataToWindow()
1166 #if wxUSE_VALIDATORS
1167 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1169 wxWindowList::Node
*node
;
1170 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1172 wxWindowBase
*child
= node
->GetData();
1173 wxValidator
*validator
= child
->GetValidator();
1174 if ( validator
&& !validator
->TransferToWindow() )
1176 wxLogWarning(_("Could not transfer data to window"));
1178 wxLog::FlushActive();
1186 if ( !child
->TransferDataToWindow() )
1188 // warning already given
1193 #endif // wxUSE_VALIDATORS
1198 bool wxWindowBase::TransferDataFromWindow()
1200 #if wxUSE_VALIDATORS
1201 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1203 wxWindowList::Node
*node
;
1204 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1206 wxWindow
*child
= node
->GetData();
1207 wxValidator
*validator
= child
->GetValidator();
1208 if ( validator
&& !validator
->TransferFromWindow() )
1210 // nop warning here because the application is supposed to give
1211 // one itself - we don't know here what might have gone wrongly
1218 if ( !child
->TransferDataFromWindow() )
1220 // warning already given
1225 #endif // wxUSE_VALIDATORS
1230 void wxWindowBase::InitDialog()
1232 wxInitDialogEvent
event(GetId());
1233 event
.SetEventObject( this );
1234 GetEventHandler()->ProcessEvent(event
);
1237 // ----------------------------------------------------------------------------
1238 // context-sensitive help support
1239 // ----------------------------------------------------------------------------
1243 // associate this help text with this window
1244 void wxWindowBase::SetHelpText(const wxString
& text
)
1246 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1249 helpProvider
->AddHelp(this, text
);
1253 // associate this help text with all windows with the same id as this
1255 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1257 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1260 helpProvider
->AddHelp(GetId(), text
);
1264 // get the help string associated with this window (may be empty)
1265 wxString
wxWindowBase::GetHelpText() const
1268 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1271 text
= helpProvider
->GetHelp(this);
1277 // show help for this window
1278 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1280 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1283 if ( helpProvider
->ShowHelp(this) )
1285 // skip the event.Skip() below
1293 #endif // wxUSE_HELP
1295 // ----------------------------------------------------------------------------
1296 // tooltipsroot.Replace("\\", "/");
1297 // ----------------------------------------------------------------------------
1301 void wxWindowBase::SetToolTip( const wxString
&tip
)
1303 // don't create the new tooltip if we already have one
1306 m_tooltip
->SetTip( tip
);
1310 SetToolTip( new wxToolTip( tip
) );
1313 // setting empty tooltip text does not remove the tooltip any more - use
1314 // SetToolTip((wxToolTip *)NULL) for this
1317 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1322 m_tooltip
= tooltip
;
1325 #endif // wxUSE_TOOLTIPS
1327 // ----------------------------------------------------------------------------
1328 // constraints and sizers
1329 // ----------------------------------------------------------------------------
1331 #if wxUSE_CONSTRAINTS
1333 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1335 if ( m_constraints
)
1337 UnsetConstraints(m_constraints
);
1338 delete m_constraints
;
1340 m_constraints
= constraints
;
1341 if ( m_constraints
)
1343 // Make sure other windows know they're part of a 'meaningful relationship'
1344 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1345 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1346 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1347 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1348 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1349 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1350 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1351 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1352 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1353 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1354 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1355 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1356 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1357 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1358 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1359 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1363 // This removes any dangling pointers to this window in other windows'
1364 // constraintsInvolvedIn lists.
1365 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1369 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1370 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1371 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1372 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1373 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1374 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1375 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1376 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1377 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1378 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1379 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1380 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1381 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1382 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1383 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1384 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1388 // Back-pointer to other windows we're involved with, so if we delete this
1389 // window, we must delete any constraints we're involved with.
1390 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1392 if ( !m_constraintsInvolvedIn
)
1393 m_constraintsInvolvedIn
= new wxWindowList
;
1394 if ( !m_constraintsInvolvedIn
->Find(otherWin
) )
1395 m_constraintsInvolvedIn
->Append(otherWin
);
1398 // REMOVE back-pointer to other windows we're involved with.
1399 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1401 if ( m_constraintsInvolvedIn
)
1402 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
1405 // Reset any constraints that mention this window
1406 void wxWindowBase::DeleteRelatedConstraints()
1408 if ( m_constraintsInvolvedIn
)
1410 wxWindowList::Node
*node
= m_constraintsInvolvedIn
->GetFirst();
1413 wxWindow
*win
= node
->GetData();
1414 wxLayoutConstraints
*constr
= win
->GetConstraints();
1416 // Reset any constraints involving this window
1419 constr
->left
.ResetIfWin(this);
1420 constr
->top
.ResetIfWin(this);
1421 constr
->right
.ResetIfWin(this);
1422 constr
->bottom
.ResetIfWin(this);
1423 constr
->width
.ResetIfWin(this);
1424 constr
->height
.ResetIfWin(this);
1425 constr
->centreX
.ResetIfWin(this);
1426 constr
->centreY
.ResetIfWin(this);
1429 wxWindowList::Node
*next
= node
->GetNext();
1434 delete m_constraintsInvolvedIn
;
1435 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1439 #endif // wxUSE_CONSTRAINTS
1441 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1444 delete m_windowSizer
;
1446 m_windowSizer
= sizer
;
1448 SetAutoLayout( sizer
!= NULL
);
1451 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1453 SetSizer( sizer
, deleteOld
);
1454 sizer
->SetSizeHints( (wxWindow
*) this );
1457 #if wxUSE_CONSTRAINTS
1459 void wxWindowBase::SatisfyConstraints()
1461 wxLayoutConstraints
*constr
= GetConstraints();
1462 bool wasOk
= constr
&& constr
->AreSatisfied();
1464 ResetConstraints(); // Mark all constraints as unevaluated
1468 // if we're a top level panel (i.e. our parent is frame/dialog), our
1469 // own constraints will never be satisfied any more unless we do it
1473 while ( noChanges
> 0 )
1475 LayoutPhase1(&noChanges
);
1479 LayoutPhase2(&noChanges
);
1482 #endif // wxUSE_CONSTRAINTS
1484 bool wxWindowBase::Layout()
1486 // If there is a sizer, use it instead of the constraints
1490 GetVirtualSize(&w
, &h
);
1491 GetSizer()->SetDimension( 0, 0, w
, h
);
1493 #if wxUSE_CONSTRAINTS
1496 SatisfyConstraints(); // Find the right constraints values
1497 SetConstraintSizes(); // Recursively set the real window sizes
1504 #if wxUSE_CONSTRAINTS
1506 // first phase of the constraints evaluation: set our own constraints
1507 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1509 wxLayoutConstraints
*constr
= GetConstraints();
1511 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1514 // second phase: set the constraints for our children
1515 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1522 // Layout grand children
1528 // Do a phase of evaluating child constraints
1529 bool wxWindowBase::DoPhase(int phase
)
1531 // the list containing the children for which the constraints are already
1533 wxWindowList succeeded
;
1535 // the max number of iterations we loop before concluding that we can't set
1537 static const int maxIterations
= 500;
1539 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1543 // loop over all children setting their constraints
1544 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
1546 node
= node
->GetNext() )
1548 wxWindow
*child
= node
->GetData();
1549 if ( child
->IsTopLevel() )
1551 // top level children are not inside our client area
1555 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1557 // this one is either already ok or nothing we can do about it
1561 int tempNoChanges
= 0;
1562 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1563 : child
->LayoutPhase2(&tempNoChanges
);
1564 noChanges
+= tempNoChanges
;
1568 succeeded
.Append(child
);
1574 // constraints are set
1582 void wxWindowBase::ResetConstraints()
1584 wxLayoutConstraints
*constr
= GetConstraints();
1587 constr
->left
.SetDone(FALSE
);
1588 constr
->top
.SetDone(FALSE
);
1589 constr
->right
.SetDone(FALSE
);
1590 constr
->bottom
.SetDone(FALSE
);
1591 constr
->width
.SetDone(FALSE
);
1592 constr
->height
.SetDone(FALSE
);
1593 constr
->centreX
.SetDone(FALSE
);
1594 constr
->centreY
.SetDone(FALSE
);
1597 wxWindowList::Node
*node
= GetChildren().GetFirst();
1600 wxWindow
*win
= node
->GetData();
1601 if ( !win
->IsTopLevel() )
1602 win
->ResetConstraints();
1603 node
= node
->GetNext();
1607 // Need to distinguish between setting the 'fake' size for windows and sizers,
1608 // and setting the real values.
1609 void wxWindowBase::SetConstraintSizes(bool recurse
)
1611 wxLayoutConstraints
*constr
= GetConstraints();
1612 if ( constr
&& constr
->AreSatisfied() )
1614 int x
= constr
->left
.GetValue();
1615 int y
= constr
->top
.GetValue();
1616 int w
= constr
->width
.GetValue();
1617 int h
= constr
->height
.GetValue();
1619 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1620 (constr
->height
.GetRelationship() != wxAsIs
) )
1622 SetSize(x
, y
, w
, h
);
1626 // If we don't want to resize this window, just move it...
1632 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1633 GetClassInfo()->GetClassName(),
1639 wxWindowList::Node
*node
= GetChildren().GetFirst();
1642 wxWindow
*win
= node
->GetData();
1643 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1644 win
->SetConstraintSizes();
1645 node
= node
->GetNext();
1650 // Only set the size/position of the constraint (if any)
1651 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1653 wxLayoutConstraints
*constr
= GetConstraints();
1658 constr
->left
.SetValue(x
);
1659 constr
->left
.SetDone(TRUE
);
1663 constr
->top
.SetValue(y
);
1664 constr
->top
.SetDone(TRUE
);
1668 constr
->width
.SetValue(w
);
1669 constr
->width
.SetDone(TRUE
);
1673 constr
->height
.SetValue(h
);
1674 constr
->height
.SetDone(TRUE
);
1679 void wxWindowBase::MoveConstraint(int x
, int y
)
1681 wxLayoutConstraints
*constr
= GetConstraints();
1686 constr
->left
.SetValue(x
);
1687 constr
->left
.SetDone(TRUE
);
1691 constr
->top
.SetValue(y
);
1692 constr
->top
.SetDone(TRUE
);
1697 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1699 wxLayoutConstraints
*constr
= GetConstraints();
1702 *w
= constr
->width
.GetValue();
1703 *h
= constr
->height
.GetValue();
1709 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1711 wxLayoutConstraints
*constr
= GetConstraints();
1714 *w
= constr
->width
.GetValue();
1715 *h
= constr
->height
.GetValue();
1718 GetClientSize(w
, h
);
1721 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1723 wxLayoutConstraints
*constr
= GetConstraints();
1726 *x
= constr
->left
.GetValue();
1727 *y
= constr
->top
.GetValue();
1733 #endif // wxUSE_CONSTRAINTS
1735 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
1737 // don't do it for the dialogs/frames - they float independently of their
1739 if ( !IsTopLevel() )
1741 wxWindow
*parent
= GetParent();
1742 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
1744 wxPoint
pt(parent
->GetClientAreaOrigin());
1751 // ----------------------------------------------------------------------------
1752 // do Update UI processing for child controls
1753 // ----------------------------------------------------------------------------
1755 // TODO: should this be implemented for the child window rather
1756 // than the parent? Then you can override it e.g. for wxCheckBox
1757 // to do the Right Thing rather than having to assume a fixed number
1758 // of control classes.
1759 void wxWindowBase::UpdateWindowUI()
1762 wxUpdateUIEvent
event(GetId());
1763 event
.m_eventObject
= this;
1765 if ( GetEventHandler()->ProcessEvent(event
) )
1767 if ( event
.GetSetEnabled() )
1768 Enable(event
.GetEnabled());
1770 if ( event
.GetSetText() )
1772 wxControl
*control
= wxDynamicCastThis(wxControl
);
1776 wxTextCtrl
*text
= wxDynamicCast(control
, wxTextCtrl
);
1779 if ( event
.GetText() != text
->GetValue() )
1780 text
->SetValue(event
.GetText());
1783 #endif // wxUSE_TEXTCTRL
1785 if ( event
.GetText() != control
->GetLabel() )
1786 control
->SetLabel(event
.GetText());
1792 wxCheckBox
*checkbox
= wxDynamicCastThis(wxCheckBox
);
1795 if ( event
.GetSetChecked() )
1796 checkbox
->SetValue(event
.GetChecked());
1798 #endif // wxUSE_CHECKBOX
1801 wxRadioButton
*radiobtn
= wxDynamicCastThis(wxRadioButton
);
1804 if ( event
.GetSetChecked() )
1805 radiobtn
->SetValue(event
.GetChecked());
1807 #endif // wxUSE_RADIOBTN
1809 #endif // wxUSE_CONTROLS
1812 // ----------------------------------------------------------------------------
1813 // dialog units translations
1814 // ----------------------------------------------------------------------------
1816 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1818 int charWidth
= GetCharWidth();
1819 int charHeight
= GetCharHeight();
1820 wxPoint
pt2(-1, -1);
1822 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1824 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1829 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1831 int charWidth
= GetCharWidth();
1832 int charHeight
= GetCharHeight();
1833 wxPoint
pt2(-1, -1);
1835 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1837 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1842 // ----------------------------------------------------------------------------
1844 // ----------------------------------------------------------------------------
1846 // propagate the colour change event to the subwindows
1847 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1849 wxWindowList::Node
*node
= GetChildren().GetFirst();
1852 // Only propagate to non-top-level windows
1853 wxWindow
*win
= node
->GetData();
1854 if ( !win
->IsTopLevel() )
1856 wxSysColourChangedEvent event2
;
1857 event
.m_eventObject
= win
;
1858 win
->GetEventHandler()->ProcessEvent(event2
);
1861 node
= node
->GetNext();
1865 // the default action is to populate dialog with data when it's created
1866 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1868 TransferDataToWindow();
1871 // process Ctrl-Alt-mclick
1872 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
1875 if ( event
.ControlDown() && event
.AltDown() )
1877 // don't translate these strings
1880 #ifdef __WXUNIVERSAL__
1882 #endif // __WXUNIVERSAL__
1884 switch ( wxGetOsVersion() )
1886 case wxMOTIF_X
: port
+= _T("Motif"); break;
1888 case wxMAC_DARWIN
: port
+= _T("Mac"); break;
1889 case wxBEOS
: port
+= _T("BeOS"); break;
1893 case wxGTK_BEOS
: port
+= _T("GTK"); break;
1899 case wxWIN386
: port
+= _T("MS Windows"); break;
1903 case wxMGL_OS2
: port
+= _T("MGL"); break;
1905 case wxOS2_PM
: port
+= _T("OS/2"); break;
1906 default: port
+= _T("unknown"); break;
1909 wxMessageBox(wxString::Format(
1911 " wxWindows Library (%s port)\nVersion %u.%u.%u%s, compiled at %s %s\n Copyright (c) 1995-2002 wxWindows team"
1925 _T("wxWindows information"),
1926 wxICON_INFORMATION
| wxOK
,
1930 #endif // wxUSE_MSGDLG
1936 // ----------------------------------------------------------------------------
1937 // list classes implementation
1938 // ----------------------------------------------------------------------------
1940 void wxWindowListNode::DeleteData()
1942 delete (wxWindow
*)GetData();
1945 // ----------------------------------------------------------------------------
1947 // ----------------------------------------------------------------------------
1949 wxBorder
wxWindowBase::GetBorder() const
1951 wxBorder border
= (wxBorder
)(m_windowStyle
& wxBORDER_MASK
);
1952 if ( border
== wxBORDER_DEFAULT
)
1954 border
= GetDefaultBorder();
1960 wxBorder
wxWindowBase::GetDefaultBorder() const
1962 return wxBORDER_NONE
;
1965 // ----------------------------------------------------------------------------
1967 // ----------------------------------------------------------------------------
1969 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
1971 // here we just check if the point is inside the window or not
1973 // check the top and left border first
1974 bool outside
= x
< 0 || y
< 0;
1977 // check the right and bottom borders too
1978 wxSize size
= GetSize();
1979 outside
= x
>= size
.x
|| y
>= size
.y
;
1982 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
1985 // ----------------------------------------------------------------------------
1987 // ----------------------------------------------------------------------------
1989 struct WXDLLEXPORT wxWindowNext
1993 } *wxWindowBase::ms_winCaptureNext
= NULL
;
1995 void wxWindowBase::CaptureMouse()
1997 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this);
1999 wxWindow
*winOld
= GetCapture();
2002 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2005 wxWindowNext
*item
= new wxWindowNext
;
2007 item
->next
= ms_winCaptureNext
;
2008 ms_winCaptureNext
= item
;
2010 //else: no mouse capture to save
2015 void wxWindowBase::ReleaseMouse()
2017 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this);
2019 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2023 if ( ms_winCaptureNext
)
2025 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2027 wxWindowNext
*item
= ms_winCaptureNext
;
2028 ms_winCaptureNext
= item
->next
;
2031 //else: stack is empty, no previous capture
2033 wxLogTrace(_T("mousecapture"),
2034 _T("After ReleaseMouse() mouse is captured by %p"),
2038 // ----------------------------------------------------------------------------
2040 // ----------------------------------------------------------------------------
2042 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2044 while ( win
&& !win
->IsTopLevel() )
2045 win
= win
->GetParent();