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/checkbox.h"
39 #include "wx/radiobut.h"
40 #include "wx/settings.h"
41 #include "wx/dialog.h"
45 #include "wx/layout.h"
46 #endif // wxUSE_CONSTRAINTS
48 #if wxUSE_DRAG_AND_DROP
50 #endif // wxUSE_DRAG_AND_DROP
53 #include "wx/tooltip.h"
54 #endif // wxUSE_TOOLTIPS
60 // ----------------------------------------------------------------------------
62 // ----------------------------------------------------------------------------
64 int wxWindowBase::ms_lastControlId
= -200;
66 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
68 // ----------------------------------------------------------------------------
70 // ----------------------------------------------------------------------------
72 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
73 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
74 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
77 // ============================================================================
78 // implementation of the common functionality of the wxWindow class
79 // ============================================================================
81 // ----------------------------------------------------------------------------
83 // ----------------------------------------------------------------------------
85 // the default initialization
86 void wxWindowBase::InitBase()
88 // no window yet, no parent nor children
89 m_parent
= (wxWindow
*)NULL
;
91 m_children
.DeleteContents( FALSE
); // don't auto delete node data
93 // no constraints on the minimal window size
99 // window is created enabled but it's not visible yet
103 // no client data (yet)
105 m_clientDataType
= ClientData_None
;
107 // the default event handler is just this window
108 m_eventHandler
= this;
112 m_windowValidator
= (wxValidator
*) NULL
;
113 #endif // wxUSE_VALIDATORS
115 // use the system default colours
116 wxSystemSettings settings
;
118 m_backgroundColour
= settings
.GetSystemColour(wxSYS_COLOUR_BTNFACE
);
119 m_foregroundColour
= *wxBLACK
; // TODO take this from sys settings too?
120 m_font
= *wxSWISS_FONT
; // and this?
125 // an optimization for the event processing: checking this flag is much
126 // faster than using IsKindOf(CLASSINFO(wxWindow))
129 #if wxUSE_CONSTRAINTS
130 // no constraints whatsoever
131 m_constraints
= (wxLayoutConstraints
*) NULL
;
132 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
133 m_windowSizer
= (wxSizer
*) NULL
;
134 m_sizerParent
= (wxWindowBase
*) NULL
;
135 m_autoLayout
= FALSE
;
136 #endif // wxUSE_CONSTRAINTS
138 #if wxUSE_DRAG_AND_DROP
139 m_dropTarget
= (wxDropTarget
*)NULL
;
140 #endif // wxUSE_DRAG_AND_DROP
143 m_tooltip
= (wxToolTip
*)NULL
;
144 #endif // wxUSE_TOOLTIPS
147 m_caret
= (wxCaret
*)NULL
;
148 #endif // wxUSE_CARET
151 // common part of window creation process
152 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
154 const wxPoint
& WXUNUSED(pos
),
155 const wxSize
& WXUNUSED(size
),
157 const wxValidator
& validator
,
158 const wxString
& name
)
160 // m_isWindow is set to TRUE in wxWindowBase::Init() as well as many other
161 // member variables - check that it has been called (will catch the case
162 // when a new ctor is added which doesn't call InitWindow)
163 wxASSERT_MSG( m_isWindow
, _T("Init() must have been called before!") );
165 // generate a new id if the user doesn't care about it
166 m_windowId
= id
== -1 ? NewControlId() : id
;
169 SetWindowStyleFlag(style
);
171 SetValidator(validator
);
176 // ----------------------------------------------------------------------------
178 // ----------------------------------------------------------------------------
181 wxWindowBase::~wxWindowBase()
183 // FIXME if these 2 cases result from programming errors in the user code
184 // we should probably assert here instead of silently fixing them
186 // Just in case the window has been Closed, but we're then deleting
187 // immediately: don't leave dangling pointers.
188 wxPendingDelete
.DeleteObject(this);
190 // Just in case we've loaded a top-level window via LoadNativeDialog but
191 // we weren't a dialog class
192 wxTopLevelWindows
.DeleteObject(this);
194 wxASSERT_MSG( GetChildren().GetCount() == 0, _T("children not destroyed") );
196 // make sure that there are no dangling pointers left pointing to us
197 wxPanel
*panel
= wxDynamicCast(GetParent(), wxPanel
);
200 if ( panel
->GetLastFocus() == this )
202 panel
->SetLastFocus((wxWindow
*)NULL
);
209 #endif // wxUSE_CARET
212 if ( m_windowValidator
)
213 delete m_windowValidator
;
214 #endif // wxUSE_VALIDATORS
216 if ( m_clientObject
)
217 delete m_clientObject
;
219 #if wxUSE_CONSTRAINTS
220 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
221 // at deleted windows as they delete themselves.
222 DeleteRelatedConstraints();
226 // This removes any dangling pointers to this window in other windows'
227 // constraintsInvolvedIn lists.
228 UnsetConstraints(m_constraints
);
229 delete m_constraints
;
230 m_constraints
= NULL
;
234 delete m_windowSizer
;
236 // If this is a child of a sizer, remove self from parent
238 m_sizerParent
->RemoveChild(this);
239 #endif // wxUSE_CONSTRAINTS
241 #if wxUSE_DRAG_AND_DROP
244 #endif // wxUSE_DRAG_AND_DROP
249 #endif // wxUSE_TOOLTIPS
252 bool wxWindowBase::Destroy()
259 bool wxWindowBase::Close(bool force
)
261 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
262 event
.SetEventObject(this);
263 #if WXWIN_COMPATIBILITY
264 event
.SetForce(force
);
265 #endif // WXWIN_COMPATIBILITY
266 event
.SetCanVeto(!force
);
268 // return FALSE if window wasn't closed because the application vetoed the
270 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
273 bool wxWindowBase::DestroyChildren()
275 wxWindowList::Node
*node
;
278 // we iterate until the list becomes empty
279 node
= GetChildren().GetFirst();
283 wxWindow
*child
= node
->GetData();
285 wxASSERT_MSG( child
, _T("children list contains empty nodes") );
289 wxASSERT_MSG( !GetChildren().Find(child
),
290 _T("child didn't remove itself using RemoveChild()") );
296 // ----------------------------------------------------------------------------
297 // centre/fit the window
298 // ----------------------------------------------------------------------------
300 // centre the window with respect to its parent in either (or both) directions
301 void wxWindowBase::Centre(int direction
)
303 int widthParent
, heightParent
;
305 wxWindow
*parent
= GetParent();
309 direction
|= wxCENTRE_ON_SCREEN
;
312 if ( direction
& wxCENTRE_ON_SCREEN
)
314 // centre with respect to the whole screen
315 wxDisplaySize(&widthParent
, &heightParent
);
319 // centre inside the parents rectangle
320 parent
->GetClientSize(&widthParent
, &heightParent
);
324 GetSize(&width
, &height
);
329 if ( direction
& wxHORIZONTAL
)
330 xNew
= (widthParent
- width
)/2;
332 if ( direction
& wxVERTICAL
)
333 yNew
= (heightParent
- height
)/2;
335 // controls are always centered on their parent because it doesn't make
336 // sense to centre them on the screen
337 if ( !(direction
& wxCENTRE_ON_SCREEN
) || wxDynamicCast(this, wxControl
) )
339 // theo nly chance to get this is to have a wxControl without parent
340 wxCHECK_RET( parent
, _T("a control must have a parent") );
342 // adjust to the parents client area origin
343 wxPoint posParent
= parent
->ClientToScreen(wxPoint(0, 0));
352 // fits the window around the children
353 void wxWindowBase::Fit()
358 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
360 node
= node
->GetNext() )
362 wxWindow
*win
= node
->GetData();
363 if ( win
->IsTopLevel() )
365 // dialogs and frames lie in different top level windows - don't
366 // deal with them here
371 win
->GetPosition(&wx
, &wy
);
372 win
->GetSize(&ww
, &wh
);
373 if ( wx
+ ww
> maxX
)
375 if ( wy
+ wh
> maxY
)
380 SetClientSize(maxX
+ 7, maxY
+ 14);
383 // set the min/max size of the window
385 void wxWindowBase::SetSizeHints(int minW
, int minH
,
387 int WXUNUSED(incW
), int WXUNUSED(incH
))
395 // ----------------------------------------------------------------------------
396 // show/hide/enable/disable the window
397 // ----------------------------------------------------------------------------
399 bool wxWindowBase::Show(bool show
)
401 if ( show
!= m_isShown
)
413 bool wxWindowBase::Enable(bool enable
)
415 if ( enable
!= m_isEnabled
)
417 m_isEnabled
= enable
;
426 // ----------------------------------------------------------------------------
428 // ----------------------------------------------------------------------------
430 bool wxWindowBase::IsTopLevel() const
432 return wxDynamicCast(this, wxFrame
) || wxDynamicCast(this, wxDialog
);
435 // ----------------------------------------------------------------------------
436 // reparenting the window
437 // ----------------------------------------------------------------------------
439 void wxWindowBase::AddChild(wxWindowBase
*child
)
441 wxCHECK_RET( child
, _T("can't add a NULL child") );
443 GetChildren().Append(child
);
444 child
->SetParent(this);
447 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
449 wxCHECK_RET( child
, _T("can't remove a NULL child") );
451 GetChildren().DeleteObject(child
);
452 child
->SetParent((wxWindow
*)NULL
);
455 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
457 wxWindow
*oldParent
= GetParent();
458 if ( newParent
== oldParent
)
464 // unlink this window from the existing parent.
467 oldParent
->RemoveChild(this);
471 wxTopLevelWindows
.DeleteObject(this);
474 // add it to the new one
477 newParent
->AddChild(this);
481 wxTopLevelWindows
.Append(this);
487 // ----------------------------------------------------------------------------
488 // event handler stuff
489 // ----------------------------------------------------------------------------
491 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
493 handler
->SetNextHandler(GetEventHandler());
494 SetEventHandler(handler
);
497 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
499 wxEvtHandler
*handlerA
= GetEventHandler();
502 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
503 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
504 SetEventHandler(handlerB
);
508 handlerA
= (wxEvtHandler
*)NULL
;
515 // ----------------------------------------------------------------------------
517 // ----------------------------------------------------------------------------
519 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
521 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
524 m_backgroundColour
= colour
;
529 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
531 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
534 m_foregroundColour
= colour
;
539 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
541 // don't try to set invalid cursor, always fall back to the default
542 const wxCursor
& cursorOk
= cursor
.Ok() ? cursor
: *wxSTANDARD_CURSOR
;
544 if ( (wxCursor
&)cursorOk
== m_cursor
)
555 bool wxWindowBase::SetFont(const wxFont
& font
)
557 // don't try to set invalid font, always fall back to the default
558 const wxFont
& fontOk
= font
.Ok() ? font
: *wxSWISS_FONT
;
560 if ( (wxFont
&)fontOk
== m_font
)
572 void wxWindowBase::SetCaret(wxCaret
*caret
)
583 wxASSERT_MSG( m_caret
->GetWindow() == this,
584 _T("caret should be created associated to this window") );
587 #endif // wxUSE_CARET
590 // ----------------------------------------------------------------------------
592 // ----------------------------------------------------------------------------
594 void wxWindowBase::SetValidator(const wxValidator
& validator
)
596 if ( m_windowValidator
)
597 delete m_windowValidator
;
599 m_windowValidator
= (wxValidator
*)validator
.Clone();
601 if ( m_windowValidator
)
602 m_windowValidator
->SetWindow(this) ;
604 #endif // wxUSE_VALIDATORS
606 // ----------------------------------------------------------------------------
607 // update region testing
608 // ----------------------------------------------------------------------------
610 bool wxWindowBase::IsExposed(int x
, int y
) const
612 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
615 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
617 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
620 // ----------------------------------------------------------------------------
621 // find window by id or name
622 // ----------------------------------------------------------------------------
624 wxWindow
*wxWindowBase::FindWindow( long id
)
626 if ( id
== m_windowId
)
627 return (wxWindow
*)this;
629 wxWindowBase
*res
= (wxWindow
*)NULL
;
630 wxWindowList::Node
*node
;
631 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
633 wxWindowBase
*child
= node
->GetData();
634 res
= child
->FindWindow( id
);
637 return (wxWindow
*)res
;
640 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
642 if ( name
== m_windowName
)
643 return (wxWindow
*)this;
645 wxWindowBase
*res
= (wxWindow
*)NULL
;
646 wxWindowList::Node
*node
;
647 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
649 wxWindow
*child
= node
->GetData();
650 res
= child
->FindWindow(name
);
653 return (wxWindow
*)res
;
656 // ----------------------------------------------------------------------------
657 // dialog oriented functions
658 // ----------------------------------------------------------------------------
660 void wxWindowBase::MakeModal(bool modal
)
662 // Disable all other windows
665 wxWindowList::Node
*node
= wxTopLevelWindows
.GetFirst();
668 wxWindow
*win
= node
->GetData();
672 node
= node
->GetNext();
677 bool wxWindowBase::Validate()
680 wxWindowList::Node
*node
;
681 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
683 wxWindowBase
*child
= node
->GetData();
684 wxValidator
*validator
= child
->GetValidator();
685 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
690 #endif // wxUSE_VALIDATORS
695 bool wxWindowBase::TransferDataToWindow()
698 wxWindowList::Node
*node
;
699 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
701 wxWindowBase
*child
= node
->GetData();
702 wxValidator
*validator
= child
->GetValidator();
703 if ( validator
&& !validator
->TransferToWindow() )
705 wxLog
*log
= wxLog::GetActiveTarget();
708 wxLogWarning(_("Could not transfer data to window"));
715 #endif // wxUSE_VALIDATORS
720 bool wxWindowBase::TransferDataFromWindow()
723 wxWindowList::Node
*node
;
724 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
726 wxWindow
*child
= node
->GetData();
727 if ( child
->GetValidator() &&
728 !child
->GetValidator()->TransferFromWindow() )
733 #endif // wxUSE_VALIDATORS
738 void wxWindowBase::InitDialog()
740 wxInitDialogEvent
event(GetId());
741 event
.SetEventObject( this );
742 GetEventHandler()->ProcessEvent(event
);
745 // ----------------------------------------------------------------------------
747 // ----------------------------------------------------------------------------
751 void wxWindowBase::SetToolTip( const wxString
&tip
)
753 // don't create the new tooltip if we already have one
756 m_tooltip
->SetTip( tip
);
760 SetToolTip( new wxToolTip( tip
) );
763 // setting empty tooltip text does not remove the tooltip any more - use
764 // SetToolTip((wxToolTip *)NULL) for this
767 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
775 #endif // wxUSE_TOOLTIPS
777 // ----------------------------------------------------------------------------
778 // constraints and sizers
779 // ----------------------------------------------------------------------------
781 #if wxUSE_CONSTRAINTS
783 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
787 UnsetConstraints(m_constraints
);
788 delete m_constraints
;
790 m_constraints
= constraints
;
793 // Make sure other windows know they're part of a 'meaningful relationship'
794 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
795 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
796 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
797 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
798 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
799 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
800 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
801 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
802 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
803 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
804 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
805 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
806 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
807 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
808 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
809 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
813 // This removes any dangling pointers to this window in other windows'
814 // constraintsInvolvedIn lists.
815 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
819 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
820 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
821 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
822 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
823 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
824 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
825 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
826 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
827 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
828 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
829 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
830 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
831 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
832 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
833 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
834 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
838 // Back-pointer to other windows we're involved with, so if we delete this
839 // window, we must delete any constraints we're involved with.
840 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
842 if ( !m_constraintsInvolvedIn
)
843 m_constraintsInvolvedIn
= new wxWindowList
;
844 if ( !m_constraintsInvolvedIn
->Find(otherWin
) )
845 m_constraintsInvolvedIn
->Append(otherWin
);
848 // REMOVE back-pointer to other windows we're involved with.
849 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
851 if ( m_constraintsInvolvedIn
)
852 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
855 // Reset any constraints that mention this window
856 void wxWindowBase::DeleteRelatedConstraints()
858 if ( m_constraintsInvolvedIn
)
860 wxWindowList::Node
*node
= m_constraintsInvolvedIn
->GetFirst();
863 wxWindow
*win
= node
->GetData();
864 wxLayoutConstraints
*constr
= win
->GetConstraints();
866 // Reset any constraints involving this window
869 constr
->left
.ResetIfWin(this);
870 constr
->top
.ResetIfWin(this);
871 constr
->right
.ResetIfWin(this);
872 constr
->bottom
.ResetIfWin(this);
873 constr
->width
.ResetIfWin(this);
874 constr
->height
.ResetIfWin(this);
875 constr
->centreX
.ResetIfWin(this);
876 constr
->centreY
.ResetIfWin(this);
879 wxWindowList::Node
*next
= node
->GetNext();
884 delete m_constraintsInvolvedIn
;
885 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
889 void wxWindowBase::SetSizer(wxSizer
*sizer
)
891 m_windowSizer
= sizer
;
893 sizer
->SetSizerParent(this);
896 bool wxWindowBase::Layout()
898 if ( GetConstraints() )
901 GetClientSize(&w
, &h
);
902 GetConstraints()->width
.SetValue(w
);
903 GetConstraints()->height
.SetValue(h
);
906 // If top level (one sizer), evaluate the sizer's constraints.
910 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
911 GetSizer()->LayoutPhase1(&noChanges
);
912 GetSizer()->LayoutPhase2(&noChanges
);
913 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
918 // Otherwise, evaluate child constraints
919 ResetConstraints(); // Mark all constraints as unevaluated
920 DoPhase(1); // Just one phase need if no sizers involved
922 SetConstraintSizes(); // Recursively set the real window sizes
928 // Do a phase of evaluating constraints: the default behaviour. wxSizers may
929 // do a similar thing, but also impose their own 'constraints' and order the
930 // evaluation differently.
931 bool wxWindowBase::LayoutPhase1(int *noChanges
)
933 wxLayoutConstraints
*constr
= GetConstraints();
936 return constr
->SatisfyConstraints(this, noChanges
);
942 bool wxWindowBase::LayoutPhase2(int *noChanges
)
952 // Do a phase of evaluating child constraints
953 bool wxWindowBase::DoPhase(int phase
)
955 int noIterations
= 0;
956 int maxIterations
= 500;
959 wxWindowList succeeded
;
960 while ((noChanges
> 0) && (noIterations
< maxIterations
))
964 wxWindowList::Node
*node
= GetChildren().GetFirst();
967 wxWindow
*child
= node
->GetData();
968 if ( !child
->IsTopLevel() )
970 wxLayoutConstraints
*constr
= child
->GetConstraints();
973 if ( !succeeded
.Find(child
) )
975 int tempNoChanges
= 0;
976 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
977 noChanges
+= tempNoChanges
;
980 succeeded
.Append(child
);
985 node
= node
->GetNext();
994 void wxWindowBase::ResetConstraints()
996 wxLayoutConstraints
*constr
= GetConstraints();
999 constr
->left
.SetDone(FALSE
);
1000 constr
->top
.SetDone(FALSE
);
1001 constr
->right
.SetDone(FALSE
);
1002 constr
->bottom
.SetDone(FALSE
);
1003 constr
->width
.SetDone(FALSE
);
1004 constr
->height
.SetDone(FALSE
);
1005 constr
->centreX
.SetDone(FALSE
);
1006 constr
->centreY
.SetDone(FALSE
);
1008 wxWindowList::Node
*node
= GetChildren().GetFirst();
1011 wxWindow
*win
= node
->GetData();
1012 if ( !win
->IsTopLevel() )
1013 win
->ResetConstraints();
1014 node
= node
->GetNext();
1018 // Need to distinguish between setting the 'fake' size for windows and sizers,
1019 // and setting the real values.
1020 void wxWindowBase::SetConstraintSizes(bool recurse
)
1022 wxLayoutConstraints
*constr
= GetConstraints();
1023 if ( constr
&& constr
->left
.GetDone() && constr
->right
.GetDone( ) &&
1024 constr
->width
.GetDone() && constr
->height
.GetDone())
1026 int x
= constr
->left
.GetValue();
1027 int y
= constr
->top
.GetValue();
1028 int w
= constr
->width
.GetValue();
1029 int h
= constr
->height
.GetValue();
1031 // If we don't want to resize this window, just move it...
1032 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1033 (constr
->height
.GetRelationship() != wxAsIs
))
1035 // Calls Layout() recursively. AAAGH. How can we stop that.
1036 // Simply take Layout() out of non-top level OnSizes.
1037 SizerSetSize(x
, y
, w
, h
);
1046 wxChar
*windowClass
= GetClassInfo()->GetClassName();
1049 if ( GetName() == _T("") )
1050 winName
= _T("unnamed");
1052 winName
= GetName();
1053 wxLogDebug( _T("Constraint(s) not satisfied for window of type %s, name %s:\n"),
1054 (const wxChar
*)windowClass
,
1055 (const wxChar
*)winName
);
1056 if ( !constr
->left
.GetDone()) wxLogDebug( _T(" unsatisfied 'left' constraint.\n") );
1057 if ( !constr
->right
.GetDone()) wxLogDebug( _T(" unsatisfied 'right' constraint.\n") );
1058 if ( !constr
->width
.GetDone()) wxLogDebug( _T(" unsatisfied 'width' constraint.\n") );
1059 if ( !constr
->height
.GetDone()) wxLogDebug( _T(" unsatisfied 'height' constraint.\n") );
1060 wxLogDebug( _T("Please check constraints: try adding AsIs() constraints.\n") );
1065 wxWindowList::Node
*node
= GetChildren().GetFirst();
1068 wxWindow
*win
= node
->GetData();
1069 if ( !win
->IsTopLevel() )
1070 win
->SetConstraintSizes();
1071 node
= node
->GetNext();
1076 // This assumes that all sizers are 'on' the same window, i.e. the parent of
1078 void wxWindowBase::TransformSizerToActual(int *x
, int *y
) const
1080 if ( !m_sizerParent
|| m_sizerParent
->IsTopLevel() )
1084 m_sizerParent
->GetPosition(&xp
, &yp
);
1085 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
1090 void wxWindowBase::SizerSetSize(int x
, int y
, int w
, int h
)
1094 TransformSizerToActual(&xx
, &yy
);
1095 SetSize(xx
, yy
, w
, h
);
1098 void wxWindowBase::SizerMove(int x
, int y
)
1102 TransformSizerToActual(&xx
, &yy
);
1106 // Only set the size/position of the constraint (if any)
1107 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1109 wxLayoutConstraints
*constr
= GetConstraints();
1114 constr
->left
.SetValue(x
);
1115 constr
->left
.SetDone(TRUE
);
1119 constr
->top
.SetValue(y
);
1120 constr
->top
.SetDone(TRUE
);
1124 constr
->width
.SetValue(w
);
1125 constr
->width
.SetDone(TRUE
);
1129 constr
->height
.SetValue(h
);
1130 constr
->height
.SetDone(TRUE
);
1135 void wxWindowBase::MoveConstraint(int x
, int y
)
1137 wxLayoutConstraints
*constr
= GetConstraints();
1142 constr
->left
.SetValue(x
);
1143 constr
->left
.SetDone(TRUE
);
1147 constr
->top
.SetValue(y
);
1148 constr
->top
.SetDone(TRUE
);
1153 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1155 wxLayoutConstraints
*constr
= GetConstraints();
1158 *w
= constr
->width
.GetValue();
1159 *h
= constr
->height
.GetValue();
1165 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1167 wxLayoutConstraints
*constr
= GetConstraints();
1170 *w
= constr
->width
.GetValue();
1171 *h
= constr
->height
.GetValue();
1174 GetClientSize(w
, h
);
1177 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1179 wxLayoutConstraints
*constr
= GetConstraints();
1182 *x
= constr
->left
.GetValue();
1183 *y
= constr
->top
.GetValue();
1189 #endif // wxUSE_CONSTRAINTS
1191 // ----------------------------------------------------------------------------
1192 // do Update UI processing for child controls
1193 // ----------------------------------------------------------------------------
1195 // TODO: should this be implemented for the child window rather
1196 // than the parent? Then you can override it e.g. for wxCheckBox
1197 // to do the Right Thing rather than having to assume a fixed number
1198 // of control classes.
1199 void wxWindowBase::UpdateWindowUI()
1201 wxWindowID id
= GetId();
1204 wxUpdateUIEvent
event(id
);
1205 event
.m_eventObject
= this;
1207 if ( GetEventHandler()->ProcessEvent(event
) )
1209 if ( event
.GetSetEnabled() )
1210 Enable(event
.GetEnabled());
1212 if ( event
.GetSetText() )
1214 wxControl
*control
= wxDynamicCast(this, wxControl
);
1216 control
->SetLabel(event
.GetText());
1220 wxCheckBox
*checkbox
= wxDynamicCast(this, wxCheckBox
);
1223 if ( event
.GetSetChecked() )
1224 checkbox
->SetValue(event
.GetChecked());
1226 #endif // wxUSE_CHECKBOX
1228 #if wxUSE_RADIOBUTTON
1229 wxRadioButton
*radiobtn
= wxDynamicCast(this, wxRadioButton
);
1232 if ( event
.GetSetChecked() )
1233 radiobtn
->SetValue(event
.GetChecked());
1235 #endif // wxUSE_RADIOBUTTON
1240 // ----------------------------------------------------------------------------
1241 // dialog units translations
1242 // ----------------------------------------------------------------------------
1244 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1246 int charWidth
= GetCharWidth();
1247 int charHeight
= GetCharHeight();
1248 wxPoint
pt2(-1, -1);
1250 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1252 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1257 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1259 int charWidth
= GetCharWidth();
1260 int charHeight
= GetCharHeight();
1261 wxPoint
pt2(-1, -1);
1263 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1265 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1270 // ----------------------------------------------------------------------------
1272 // ----------------------------------------------------------------------------
1274 void wxWindowBase::DoSetClientObject( wxClientData
*data
)
1276 wxASSERT_MSG( m_clientDataType
!= ClientData_Void
,
1277 _T("can't have both object and void client data") );
1279 if ( m_clientObject
)
1280 delete m_clientObject
;
1282 m_clientObject
= data
;
1283 m_clientDataType
= ClientData_Object
;
1286 wxClientData
*wxWindowBase::DoGetClientObject() const
1288 wxASSERT_MSG( m_clientDataType
== ClientData_Object
,
1289 _T("this window doesn't have object client data") );
1291 return m_clientObject
;
1294 void wxWindowBase::DoSetClientData( void *data
)
1296 wxASSERT_MSG( m_clientDataType
!= ClientData_Object
,
1297 _T("can't have both object and void client data") );
1299 m_clientData
= data
;
1300 m_clientDataType
= ClientData_Void
;
1303 void *wxWindowBase::DoGetClientData() const
1305 wxASSERT_MSG( m_clientDataType
== ClientData_Void
,
1306 _T("this window doesn't have void client data") );
1308 return m_clientData
;
1311 // ----------------------------------------------------------------------------
1313 // ----------------------------------------------------------------------------
1315 // propagate the colour change event to the subwindows
1316 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1318 wxWindowList::Node
*node
= GetChildren().GetFirst();
1321 // Only propagate to non-top-level windows
1322 wxWindow
*win
= node
->GetData();
1323 if ( !win
->IsTopLevel() )
1325 wxSysColourChangedEvent event2
;
1326 event
.m_eventObject
= win
;
1327 win
->GetEventHandler()->ProcessEvent(event2
);
1330 node
= node
->GetNext();
1334 // the default action is to populate dialog with data when it's created
1335 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1337 TransferDataToWindow();
1340 // ----------------------------------------------------------------------------
1341 // list classes implementation
1342 // ----------------------------------------------------------------------------
1344 void wxWindowListNode::DeleteData()
1346 delete (wxWindow
*)GetData();