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/textctrl.h"
41 #include "wx/settings.h"
42 #include "wx/dialog.h"
46 #include "wx/layout.h"
48 #endif // wxUSE_CONSTRAINTS
50 #if wxUSE_DRAG_AND_DROP
52 #endif // wxUSE_DRAG_AND_DROP
55 #include "wx/tooltip.h"
56 #endif // wxUSE_TOOLTIPS
62 // ----------------------------------------------------------------------------
64 // ----------------------------------------------------------------------------
66 int wxWindowBase::ms_lastControlId
= -200;
68 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
70 // ----------------------------------------------------------------------------
72 // ----------------------------------------------------------------------------
74 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
75 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
76 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
79 // ============================================================================
80 // implementation of the common functionality of the wxWindow class
81 // ============================================================================
83 // ----------------------------------------------------------------------------
85 // ----------------------------------------------------------------------------
87 // the default initialization
88 void wxWindowBase::InitBase()
90 // no window yet, no parent nor children
91 m_parent
= (wxWindow
*)NULL
;
93 m_children
.DeleteContents( FALSE
); // don't auto delete node data
95 // no constraints on the minimal window size
101 // window is created enabled but it's not visible yet
105 // no client data (yet)
107 m_clientDataType
= ClientData_None
;
109 // the default event handler is just this window
110 m_eventHandler
= this;
114 m_windowValidator
= (wxValidator
*) NULL
;
115 #endif // wxUSE_VALIDATORS
117 // use the system default colours
118 wxSystemSettings settings
;
120 m_backgroundColour
= settings
.GetSystemColour(wxSYS_COLOUR_BTNFACE
);
121 m_foregroundColour
= *wxBLACK
; // TODO take this from sys settings too?
123 m_font
= *wxSWISS_FONT
; // and this?
125 m_font
= settings
.GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
130 // an optimization for the event processing: checking this flag is much
131 // faster than using IsKindOf(CLASSINFO(wxWindow))
134 #if wxUSE_CONSTRAINTS
135 // no constraints whatsoever
136 m_constraints
= (wxLayoutConstraints
*) NULL
;
137 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
138 m_windowSizer
= (wxSizer
*) NULL
;
139 m_autoLayout
= FALSE
;
140 #endif // wxUSE_CONSTRAINTS
142 #if wxUSE_DRAG_AND_DROP
143 m_dropTarget
= (wxDropTarget
*)NULL
;
144 #endif // wxUSE_DRAG_AND_DROP
147 m_tooltip
= (wxToolTip
*)NULL
;
148 #endif // wxUSE_TOOLTIPS
151 m_caret
= (wxCaret
*)NULL
;
152 #endif // wxUSE_CARET
155 // common part of window creation process
156 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
158 const wxPoint
& WXUNUSED(pos
),
159 const wxSize
& WXUNUSED(size
),
162 # if defined(__VISAGECPP__)
163 const wxValidator
* validator
,
165 const wxValidator
& validator
,
168 const wxString
& name
)
170 // m_isWindow is set to TRUE in wxWindowBase::Init() as well as many other
171 // member variables - check that it has been called (will catch the case
172 // when a new ctor is added which doesn't call InitWindow)
173 wxASSERT_MSG( m_isWindow
, wxT("Init() must have been called before!") );
175 // generate a new id if the user doesn't care about it
176 m_windowId
= id
== -1 ? NewControlId() : id
;
179 SetWindowStyleFlag(style
);
181 SetValidator(validator
);
186 // ----------------------------------------------------------------------------
188 // ----------------------------------------------------------------------------
191 wxWindowBase::~wxWindowBase()
193 // FIXME if these 2 cases result from programming errors in the user code
194 // we should probably assert here instead of silently fixing them
196 // Just in case the window has been Closed, but we're then deleting
197 // immediately: don't leave dangling pointers.
198 wxPendingDelete
.DeleteObject(this);
200 // Just in case we've loaded a top-level window via LoadNativeDialog but
201 // we weren't a dialog class
202 wxTopLevelWindows
.DeleteObject(this);
204 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
206 // make sure that there are no dangling pointers left pointing to us
207 wxPanel
*panel
= wxDynamicCast(GetParent(), wxPanel
);
210 if ( panel
->GetLastFocus() == this )
212 panel
->SetLastFocus((wxWindow
*)NULL
);
219 #endif // wxUSE_CARET
222 if ( m_windowValidator
)
223 delete m_windowValidator
;
224 #endif // wxUSE_VALIDATORS
226 // we only delete object data, not untyped
227 if ( m_clientDataType
== ClientData_Object
)
228 delete m_clientObject
;
230 #if wxUSE_CONSTRAINTS
231 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
232 // at deleted windows as they delete themselves.
233 DeleteRelatedConstraints();
237 // This removes any dangling pointers to this window in other windows'
238 // constraintsInvolvedIn lists.
239 UnsetConstraints(m_constraints
);
240 delete m_constraints
;
241 m_constraints
= NULL
;
245 delete m_windowSizer
;
247 #endif // wxUSE_CONSTRAINTS
249 #if wxUSE_DRAG_AND_DROP
252 #endif // wxUSE_DRAG_AND_DROP
257 #endif // wxUSE_TOOLTIPS
260 bool wxWindowBase::Destroy()
267 bool wxWindowBase::Close(bool force
)
269 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
270 event
.SetEventObject(this);
271 #if WXWIN_COMPATIBILITY
272 event
.SetForce(force
);
273 #endif // WXWIN_COMPATIBILITY
274 event
.SetCanVeto(!force
);
276 // return FALSE if window wasn't closed because the application vetoed the
278 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
281 bool wxWindowBase::DestroyChildren()
283 wxWindowList::Node
*node
;
286 // we iterate until the list becomes empty
287 node
= GetChildren().GetFirst();
291 wxWindow
*child
= node
->GetData();
293 wxASSERT_MSG( child
, wxT("children list contains empty nodes") );
297 wxASSERT_MSG( !GetChildren().Find(child
),
298 wxT("child didn't remove itself using RemoveChild()") );
304 // ----------------------------------------------------------------------------
305 // centre/fit the window
306 // ----------------------------------------------------------------------------
308 // centre the window with respect to its parent in either (or both) directions
309 void wxWindowBase::Centre(int direction
)
311 int widthParent
, heightParent
;
313 wxWindow
*parent
= GetParent();
317 direction
|= wxCENTRE_ON_SCREEN
;
320 if ( direction
& wxCENTRE_ON_SCREEN
)
322 // centre with respect to the whole screen
323 wxDisplaySize(&widthParent
, &heightParent
);
327 // centre inside the parents rectangle
328 parent
->GetClientSize(&widthParent
, &heightParent
);
332 GetSize(&width
, &height
);
337 if ( direction
& wxHORIZONTAL
)
338 xNew
= (widthParent
- width
)/2;
340 if ( direction
& wxVERTICAL
)
341 yNew
= (heightParent
- height
)/2;
343 // controls are always centered on their parent because it doesn't make
344 // sense to centre them on the screen
345 if ( !(direction
& wxCENTRE_ON_SCREEN
) || wxDynamicCast(this, wxControl
) )
347 // theo nly chance to get this is to have a wxControl without parent
348 wxCHECK_RET( parent
, wxT("a control must have a parent") );
350 // adjust to the parents client area origin
351 wxPoint posParent
= parent
->ClientToScreen(wxPoint(0, 0));
357 // move the centre of this window to this position
361 // fits the window around the children
362 void wxWindowBase::Fit()
367 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
369 node
= node
->GetNext() )
371 wxWindow
*win
= node
->GetData();
372 if ( win
->IsTopLevel() )
374 // dialogs and frames lie in different top level windows - don't
375 // deal with them here
380 win
->GetPosition(&wx
, &wy
);
381 win
->GetSize(&ww
, &wh
);
382 if ( wx
+ ww
> maxX
)
384 if ( wy
+ wh
> maxY
)
389 SetClientSize(maxX
+ 7, maxY
+ 14);
392 // set the min/max size of the window
394 void wxWindowBase::SetSizeHints(int minW
, int minH
,
396 int WXUNUSED(incW
), int WXUNUSED(incH
))
404 // ----------------------------------------------------------------------------
405 // show/hide/enable/disable the window
406 // ----------------------------------------------------------------------------
408 bool wxWindowBase::Show(bool show
)
410 if ( show
!= m_isShown
)
422 bool wxWindowBase::Enable(bool enable
)
424 if ( enable
!= m_isEnabled
)
426 m_isEnabled
= enable
;
435 // ----------------------------------------------------------------------------
437 // ----------------------------------------------------------------------------
439 bool wxWindowBase::IsTopLevel() const
444 // ----------------------------------------------------------------------------
445 // reparenting the window
446 // ----------------------------------------------------------------------------
448 void wxWindowBase::AddChild(wxWindowBase
*child
)
450 wxCHECK_RET( child
, wxT("can't add a NULL child") );
452 GetChildren().Append(child
);
453 child
->SetParent(this);
456 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
458 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
460 GetChildren().DeleteObject(child
);
461 child
->SetParent((wxWindow
*)NULL
);
464 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
466 wxWindow
*oldParent
= GetParent();
467 if ( newParent
== oldParent
)
473 // unlink this window from the existing parent.
476 oldParent
->RemoveChild(this);
480 wxTopLevelWindows
.DeleteObject(this);
483 // add it to the new one
486 newParent
->AddChild(this);
490 wxTopLevelWindows
.Append(this);
496 // ----------------------------------------------------------------------------
497 // event handler stuff
498 // ----------------------------------------------------------------------------
500 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
502 handler
->SetNextHandler(GetEventHandler());
503 SetEventHandler(handler
);
506 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
508 wxEvtHandler
*handlerA
= GetEventHandler();
511 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
512 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
513 SetEventHandler(handlerB
);
517 handlerA
= (wxEvtHandler
*)NULL
;
524 // ----------------------------------------------------------------------------
526 // ----------------------------------------------------------------------------
528 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
530 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
533 m_backgroundColour
= colour
;
538 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
540 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
543 m_foregroundColour
= colour
;
548 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
550 // don't try to set invalid cursor, always fall back to the default
551 const wxCursor
& cursorOk
= cursor
.Ok() ? cursor
: *wxSTANDARD_CURSOR
;
553 if ( (wxCursor
&)cursorOk
== m_cursor
)
564 bool wxWindowBase::SetFont(const wxFont
& font
)
566 // don't try to set invalid font, always fall back to the default
567 const wxFont
& fontOk
= font
.Ok() ? font
: *wxSWISS_FONT
;
569 if ( (wxFont
&)fontOk
== m_font
)
581 void wxWindowBase::SetCaret(wxCaret
*caret
)
592 wxASSERT_MSG( m_caret
->GetWindow() == this,
593 wxT("caret should be created associated to this window") );
596 #endif // wxUSE_CARET
599 // ----------------------------------------------------------------------------
601 // ----------------------------------------------------------------------------
603 # if defined(__VISAGECPP__)
604 void wxWindowBase::SetValidator(const wxValidator
* validator
)
606 if ( m_windowValidator
)
607 delete m_windowValidator
;
609 m_windowValidator
= (wxValidator
*)validator
->Clone();
611 if ( m_windowValidator
)
612 m_windowValidator
->SetWindow(this) ;
615 void wxWindowBase::SetValidator(const wxValidator
& validator
)
617 if ( m_windowValidator
)
618 delete m_windowValidator
;
620 m_windowValidator
= (wxValidator
*)validator
.Clone();
622 if ( m_windowValidator
)
623 m_windowValidator
->SetWindow(this) ;
625 # endif // __VISAGECPP__
626 #endif // wxUSE_VALIDATORS
628 // ----------------------------------------------------------------------------
629 // update region testing
630 // ----------------------------------------------------------------------------
632 bool wxWindowBase::IsExposed(int x
, int y
) const
634 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
637 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
639 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
642 // ----------------------------------------------------------------------------
643 // find window by id or name
644 // ----------------------------------------------------------------------------
646 wxWindow
*wxWindowBase::FindWindow( long id
)
648 if ( id
== m_windowId
)
649 return (wxWindow
*)this;
651 wxWindowBase
*res
= (wxWindow
*)NULL
;
652 wxWindowList::Node
*node
;
653 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
655 wxWindowBase
*child
= node
->GetData();
656 res
= child
->FindWindow( id
);
659 return (wxWindow
*)res
;
662 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
664 if ( name
== m_windowName
)
665 return (wxWindow
*)this;
667 wxWindowBase
*res
= (wxWindow
*)NULL
;
668 wxWindowList::Node
*node
;
669 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
671 wxWindow
*child
= node
->GetData();
672 res
= child
->FindWindow(name
);
675 return (wxWindow
*)res
;
678 // ----------------------------------------------------------------------------
679 // dialog oriented functions
680 // ----------------------------------------------------------------------------
682 void wxWindowBase::MakeModal(bool modal
)
684 // Disable all other windows
687 wxWindowList::Node
*node
= wxTopLevelWindows
.GetFirst();
690 wxWindow
*win
= node
->GetData();
694 node
= node
->GetNext();
699 bool wxWindowBase::Validate()
702 wxWindowList::Node
*node
;
703 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
705 wxWindowBase
*child
= node
->GetData();
706 wxValidator
*validator
= child
->GetValidator();
707 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
712 #endif // wxUSE_VALIDATORS
717 bool wxWindowBase::TransferDataToWindow()
720 wxWindowList::Node
*node
;
721 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
723 wxWindowBase
*child
= node
->GetData();
724 wxValidator
*validator
= child
->GetValidator();
725 if ( validator
&& !validator
->TransferToWindow() )
727 wxLog
*log
= wxLog::GetActiveTarget();
730 wxLogWarning(_("Could not transfer data to window"));
737 #endif // wxUSE_VALIDATORS
742 bool wxWindowBase::TransferDataFromWindow()
745 wxWindowList::Node
*node
;
746 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
748 wxWindow
*child
= node
->GetData();
749 if ( child
->GetValidator() &&
750 !child
->GetValidator()->TransferFromWindow() )
755 #endif // wxUSE_VALIDATORS
760 void wxWindowBase::InitDialog()
762 wxInitDialogEvent
event(GetId());
763 event
.SetEventObject( this );
764 GetEventHandler()->ProcessEvent(event
);
767 // ----------------------------------------------------------------------------
769 // ----------------------------------------------------------------------------
773 void wxWindowBase::SetToolTip( const wxString
&tip
)
775 // don't create the new tooltip if we already have one
778 m_tooltip
->SetTip( tip
);
782 SetToolTip( new wxToolTip( tip
) );
785 // setting empty tooltip text does not remove the tooltip any more - use
786 // SetToolTip((wxToolTip *)NULL) for this
789 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
797 #endif // wxUSE_TOOLTIPS
799 // ----------------------------------------------------------------------------
800 // constraints and sizers
801 // ----------------------------------------------------------------------------
803 #if wxUSE_CONSTRAINTS
805 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
809 UnsetConstraints(m_constraints
);
810 delete m_constraints
;
812 m_constraints
= constraints
;
815 // Make sure other windows know they're part of a 'meaningful relationship'
816 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
817 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
818 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
819 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
820 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
821 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
822 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
823 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
824 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
825 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
826 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
827 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
828 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
829 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
830 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
831 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
835 // This removes any dangling pointers to this window in other windows'
836 // constraintsInvolvedIn lists.
837 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
841 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
842 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
843 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
844 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
845 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
846 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
847 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
848 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
849 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
850 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
851 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
852 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
853 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
854 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
855 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
856 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
860 // Back-pointer to other windows we're involved with, so if we delete this
861 // window, we must delete any constraints we're involved with.
862 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
864 if ( !m_constraintsInvolvedIn
)
865 m_constraintsInvolvedIn
= new wxWindowList
;
866 if ( !m_constraintsInvolvedIn
->Find(otherWin
) )
867 m_constraintsInvolvedIn
->Append(otherWin
);
870 // REMOVE back-pointer to other windows we're involved with.
871 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
873 if ( m_constraintsInvolvedIn
)
874 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
877 // Reset any constraints that mention this window
878 void wxWindowBase::DeleteRelatedConstraints()
880 if ( m_constraintsInvolvedIn
)
882 wxWindowList::Node
*node
= m_constraintsInvolvedIn
->GetFirst();
885 wxWindow
*win
= node
->GetData();
886 wxLayoutConstraints
*constr
= win
->GetConstraints();
888 // Reset any constraints involving this window
891 constr
->left
.ResetIfWin(this);
892 constr
->top
.ResetIfWin(this);
893 constr
->right
.ResetIfWin(this);
894 constr
->bottom
.ResetIfWin(this);
895 constr
->width
.ResetIfWin(this);
896 constr
->height
.ResetIfWin(this);
897 constr
->centreX
.ResetIfWin(this);
898 constr
->centreY
.ResetIfWin(this);
901 wxWindowList::Node
*next
= node
->GetNext();
906 delete m_constraintsInvolvedIn
;
907 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
911 void wxWindowBase::SetSizer(wxSizer
*sizer
)
913 if (m_windowSizer
) delete m_windowSizer
;
915 m_windowSizer
= sizer
;
918 bool wxWindowBase::Layout()
921 GetClientSize(&w
, &h
);
923 // If there is a sizer, use it instead of the constraints
926 GetSizer()->SetDimension( 0, 0, w
, h
);
930 if ( GetConstraints() )
932 GetConstraints()->width
.SetValue(w
);
933 GetConstraints()->height
.SetValue(h
);
936 // Evaluate child constraints
937 ResetConstraints(); // Mark all constraints as unevaluated
938 DoPhase(1); // Just one phase need if no sizers involved
940 SetConstraintSizes(); // Recursively set the real window sizes
946 // Do a phase of evaluating constraints: the default behaviour. wxSizers may
947 // do a similar thing, but also impose their own 'constraints' and order the
948 // evaluation differently.
949 bool wxWindowBase::LayoutPhase1(int *noChanges
)
951 wxLayoutConstraints
*constr
= GetConstraints();
954 return constr
->SatisfyConstraints(this, noChanges
);
960 bool wxWindowBase::LayoutPhase2(int *noChanges
)
970 // Do a phase of evaluating child constraints
971 bool wxWindowBase::DoPhase(int phase
)
973 int noIterations
= 0;
974 int maxIterations
= 500;
977 wxWindowList succeeded
;
978 while ((noChanges
> 0) && (noIterations
< maxIterations
))
982 wxWindowList::Node
*node
= GetChildren().GetFirst();
985 wxWindow
*child
= node
->GetData();
986 if ( !child
->IsTopLevel() )
988 wxLayoutConstraints
*constr
= child
->GetConstraints();
991 if ( !succeeded
.Find(child
) )
993 int tempNoChanges
= 0;
994 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
995 noChanges
+= tempNoChanges
;
998 succeeded
.Append(child
);
1003 node
= node
->GetNext();
1012 void wxWindowBase::ResetConstraints()
1014 wxLayoutConstraints
*constr
= GetConstraints();
1017 constr
->left
.SetDone(FALSE
);
1018 constr
->top
.SetDone(FALSE
);
1019 constr
->right
.SetDone(FALSE
);
1020 constr
->bottom
.SetDone(FALSE
);
1021 constr
->width
.SetDone(FALSE
);
1022 constr
->height
.SetDone(FALSE
);
1023 constr
->centreX
.SetDone(FALSE
);
1024 constr
->centreY
.SetDone(FALSE
);
1026 wxWindowList::Node
*node
= GetChildren().GetFirst();
1029 wxWindow
*win
= node
->GetData();
1030 if ( !win
->IsTopLevel() )
1031 win
->ResetConstraints();
1032 node
= node
->GetNext();
1036 // Need to distinguish between setting the 'fake' size for windows and sizers,
1037 // and setting the real values.
1038 void wxWindowBase::SetConstraintSizes(bool recurse
)
1040 wxLayoutConstraints
*constr
= GetConstraints();
1041 if ( constr
&& constr
->left
.GetDone() && constr
->right
.GetDone( ) &&
1042 constr
->width
.GetDone() && constr
->height
.GetDone())
1044 int x
= constr
->left
.GetValue();
1045 int y
= constr
->top
.GetValue();
1046 int w
= constr
->width
.GetValue();
1047 int h
= constr
->height
.GetValue();
1049 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1050 (constr
->height
.GetRelationship() != wxAsIs
) )
1052 SetSize(x
, y
, w
, h
);
1056 // If we don't want to resize this window, just move it...
1062 wxChar
*windowClass
= GetClassInfo()->GetClassName();
1065 if ( GetName() == wxT("") )
1066 winName
= wxT("unnamed");
1068 winName
= GetName();
1069 wxLogDebug( wxT("Constraint(s) not satisfied for window of type %s, name %s:\n"),
1070 (const wxChar
*)windowClass
,
1071 (const wxChar
*)winName
);
1072 if ( !constr
->left
.GetDone()) wxLogDebug( wxT(" unsatisfied 'left' constraint.\n") );
1073 if ( !constr
->right
.GetDone()) wxLogDebug( wxT(" unsatisfied 'right' constraint.\n") );
1074 if ( !constr
->width
.GetDone()) wxLogDebug( wxT(" unsatisfied 'width' constraint.\n") );
1075 if ( !constr
->height
.GetDone()) wxLogDebug( wxT(" unsatisfied 'height' constraint.\n") );
1076 wxLogDebug( wxT("Please check constraints: try adding AsIs() constraints.\n") );
1081 wxWindowList::Node
*node
= GetChildren().GetFirst();
1084 wxWindow
*win
= node
->GetData();
1085 if ( !win
->IsTopLevel() )
1086 win
->SetConstraintSizes();
1087 node
= node
->GetNext();
1092 // Only set the size/position of the constraint (if any)
1093 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1095 wxLayoutConstraints
*constr
= GetConstraints();
1100 constr
->left
.SetValue(x
);
1101 constr
->left
.SetDone(TRUE
);
1105 constr
->top
.SetValue(y
);
1106 constr
->top
.SetDone(TRUE
);
1110 constr
->width
.SetValue(w
);
1111 constr
->width
.SetDone(TRUE
);
1115 constr
->height
.SetValue(h
);
1116 constr
->height
.SetDone(TRUE
);
1121 void wxWindowBase::MoveConstraint(int x
, int y
)
1123 wxLayoutConstraints
*constr
= GetConstraints();
1128 constr
->left
.SetValue(x
);
1129 constr
->left
.SetDone(TRUE
);
1133 constr
->top
.SetValue(y
);
1134 constr
->top
.SetDone(TRUE
);
1139 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1141 wxLayoutConstraints
*constr
= GetConstraints();
1144 *w
= constr
->width
.GetValue();
1145 *h
= constr
->height
.GetValue();
1151 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1153 wxLayoutConstraints
*constr
= GetConstraints();
1156 *w
= constr
->width
.GetValue();
1157 *h
= constr
->height
.GetValue();
1160 GetClientSize(w
, h
);
1163 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1165 wxLayoutConstraints
*constr
= GetConstraints();
1168 *x
= constr
->left
.GetValue();
1169 *y
= constr
->top
.GetValue();
1175 #endif // wxUSE_CONSTRAINTS
1177 // ----------------------------------------------------------------------------
1178 // do Update UI processing for child controls
1179 // ----------------------------------------------------------------------------
1181 // TODO: should this be implemented for the child window rather
1182 // than the parent? Then you can override it e.g. for wxCheckBox
1183 // to do the Right Thing rather than having to assume a fixed number
1184 // of control classes.
1185 void wxWindowBase::UpdateWindowUI()
1187 wxUpdateUIEvent
event(GetId());
1188 event
.m_eventObject
= this;
1190 if ( GetEventHandler()->ProcessEvent(event
) )
1192 if ( event
.GetSetEnabled() )
1193 Enable(event
.GetEnabled());
1195 if ( event
.GetSetText() )
1197 wxControl
*control
= wxDynamicCast(this, wxControl
);
1200 wxTextCtrl
*text
= wxDynamicCast(control
, wxTextCtrl
);
1202 text
->SetValue(event
.GetText());
1204 control
->SetLabel(event
.GetText());
1209 wxCheckBox
*checkbox
= wxDynamicCast(this, wxCheckBox
);
1212 if ( event
.GetSetChecked() )
1213 checkbox
->SetValue(event
.GetChecked());
1215 #endif // wxUSE_CHECKBOX
1217 #if wxUSE_RADIOBUTTON
1218 wxRadioButton
*radiobtn
= wxDynamicCast(this, wxRadioButton
);
1221 if ( event
.GetSetChecked() )
1222 radiobtn
->SetValue(event
.GetChecked());
1224 #endif // wxUSE_RADIOBUTTON
1228 // ----------------------------------------------------------------------------
1229 // dialog units translations
1230 // ----------------------------------------------------------------------------
1232 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1234 int charWidth
= GetCharWidth();
1235 int charHeight
= GetCharHeight();
1236 wxPoint
pt2(-1, -1);
1238 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1240 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1245 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1247 int charWidth
= GetCharWidth();
1248 int charHeight
= GetCharHeight();
1249 wxPoint
pt2(-1, -1);
1251 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1253 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1258 // ----------------------------------------------------------------------------
1260 // ----------------------------------------------------------------------------
1262 void wxWindowBase::DoSetClientObject( wxClientData
*data
)
1264 wxASSERT_MSG( m_clientDataType
!= ClientData_Void
,
1265 wxT("can't have both object and void client data") );
1267 if ( m_clientObject
)
1268 delete m_clientObject
;
1270 m_clientObject
= data
;
1271 m_clientDataType
= ClientData_Object
;
1274 wxClientData
*wxWindowBase::DoGetClientObject() const
1276 wxASSERT_MSG( m_clientDataType
== ClientData_Object
,
1277 wxT("this window doesn't have object client data") );
1279 return m_clientObject
;
1282 void wxWindowBase::DoSetClientData( void *data
)
1284 wxASSERT_MSG( m_clientDataType
!= ClientData_Object
,
1285 wxT("can't have both object and void client data") );
1287 m_clientData
= data
;
1288 m_clientDataType
= ClientData_Void
;
1291 void *wxWindowBase::DoGetClientData() const
1293 wxASSERT_MSG( m_clientDataType
== ClientData_Void
,
1294 wxT("this window doesn't have void client data") );
1296 return m_clientData
;
1299 // ----------------------------------------------------------------------------
1301 // ----------------------------------------------------------------------------
1303 // propagate the colour change event to the subwindows
1304 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1306 wxWindowList::Node
*node
= GetChildren().GetFirst();
1309 // Only propagate to non-top-level windows
1310 wxWindow
*win
= node
->GetData();
1311 if ( !win
->IsTopLevel() )
1313 wxSysColourChangedEvent event2
;
1314 event
.m_eventObject
= win
;
1315 win
->GetEventHandler()->ProcessEvent(event2
);
1318 node
= node
->GetNext();
1322 // the default action is to populate dialog with data when it's created
1323 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1325 TransferDataToWindow();
1328 // ----------------------------------------------------------------------------
1329 // list classes implementation
1330 // ----------------------------------------------------------------------------
1332 void wxWindowListNode::DeleteData()
1334 delete (wxWindow
*)GetData();