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));
360 // fits the window around the children
361 void wxWindowBase::Fit()
366 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
368 node
= node
->GetNext() )
370 wxWindow
*win
= node
->GetData();
371 if ( win
->IsTopLevel() )
373 // dialogs and frames lie in different top level windows - don't
374 // deal with them here
379 win
->GetPosition(&wx
, &wy
);
380 win
->GetSize(&ww
, &wh
);
381 if ( wx
+ ww
> maxX
)
383 if ( wy
+ wh
> maxY
)
388 SetClientSize(maxX
+ 7, maxY
+ 14);
391 // set the min/max size of the window
393 void wxWindowBase::SetSizeHints(int minW
, int minH
,
395 int WXUNUSED(incW
), int WXUNUSED(incH
))
403 // ----------------------------------------------------------------------------
404 // show/hide/enable/disable the window
405 // ----------------------------------------------------------------------------
407 bool wxWindowBase::Show(bool show
)
409 if ( show
!= m_isShown
)
421 bool wxWindowBase::Enable(bool enable
)
423 if ( enable
!= m_isEnabled
)
425 m_isEnabled
= enable
;
434 // ----------------------------------------------------------------------------
436 // ----------------------------------------------------------------------------
438 bool wxWindowBase::IsTopLevel() const
443 // ----------------------------------------------------------------------------
444 // reparenting the window
445 // ----------------------------------------------------------------------------
447 void wxWindowBase::AddChild(wxWindowBase
*child
)
449 wxCHECK_RET( child
, wxT("can't add a NULL child") );
451 GetChildren().Append(child
);
452 child
->SetParent(this);
455 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
457 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
459 GetChildren().DeleteObject(child
);
460 child
->SetParent((wxWindow
*)NULL
);
463 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
465 wxWindow
*oldParent
= GetParent();
466 if ( newParent
== oldParent
)
472 // unlink this window from the existing parent.
475 oldParent
->RemoveChild(this);
479 wxTopLevelWindows
.DeleteObject(this);
482 // add it to the new one
485 newParent
->AddChild(this);
489 wxTopLevelWindows
.Append(this);
495 // ----------------------------------------------------------------------------
496 // event handler stuff
497 // ----------------------------------------------------------------------------
499 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
501 handler
->SetNextHandler(GetEventHandler());
502 SetEventHandler(handler
);
505 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
507 wxEvtHandler
*handlerA
= GetEventHandler();
510 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
511 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
512 SetEventHandler(handlerB
);
516 handlerA
= (wxEvtHandler
*)NULL
;
523 // ----------------------------------------------------------------------------
525 // ----------------------------------------------------------------------------
527 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
529 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
532 m_backgroundColour
= colour
;
537 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
539 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
542 m_foregroundColour
= colour
;
547 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
549 // don't try to set invalid cursor, always fall back to the default
550 const wxCursor
& cursorOk
= cursor
.Ok() ? cursor
: *wxSTANDARD_CURSOR
;
552 if ( (wxCursor
&)cursorOk
== m_cursor
)
563 bool wxWindowBase::SetFont(const wxFont
& font
)
565 // don't try to set invalid font, always fall back to the default
566 const wxFont
& fontOk
= font
.Ok() ? font
: *wxSWISS_FONT
;
568 if ( (wxFont
&)fontOk
== m_font
)
580 void wxWindowBase::SetCaret(wxCaret
*caret
)
591 wxASSERT_MSG( m_caret
->GetWindow() == this,
592 wxT("caret should be created associated to this window") );
595 #endif // wxUSE_CARET
598 // ----------------------------------------------------------------------------
600 // ----------------------------------------------------------------------------
602 # if defined(__VISAGECPP__)
603 void wxWindowBase::SetValidator(const wxValidator
* validator
)
605 if ( m_windowValidator
)
606 delete m_windowValidator
;
608 m_windowValidator
= (wxValidator
*)validator
->Clone();
610 if ( m_windowValidator
)
611 m_windowValidator
->SetWindow(this) ;
614 void wxWindowBase::SetValidator(const wxValidator
& validator
)
616 if ( m_windowValidator
)
617 delete m_windowValidator
;
619 m_windowValidator
= (wxValidator
*)validator
.Clone();
621 if ( m_windowValidator
)
622 m_windowValidator
->SetWindow(this) ;
624 # endif // __VISAGECPP__
625 #endif // wxUSE_VALIDATORS
627 // ----------------------------------------------------------------------------
628 // update region testing
629 // ----------------------------------------------------------------------------
631 bool wxWindowBase::IsExposed(int x
, int y
) const
633 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
636 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
638 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
641 // ----------------------------------------------------------------------------
642 // find window by id or name
643 // ----------------------------------------------------------------------------
645 wxWindow
*wxWindowBase::FindWindow( long id
)
647 if ( id
== m_windowId
)
648 return (wxWindow
*)this;
650 wxWindowBase
*res
= (wxWindow
*)NULL
;
651 wxWindowList::Node
*node
;
652 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
654 wxWindowBase
*child
= node
->GetData();
655 res
= child
->FindWindow( id
);
658 return (wxWindow
*)res
;
661 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
663 if ( name
== m_windowName
)
664 return (wxWindow
*)this;
666 wxWindowBase
*res
= (wxWindow
*)NULL
;
667 wxWindowList::Node
*node
;
668 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
670 wxWindow
*child
= node
->GetData();
671 res
= child
->FindWindow(name
);
674 return (wxWindow
*)res
;
677 // ----------------------------------------------------------------------------
678 // dialog oriented functions
679 // ----------------------------------------------------------------------------
681 void wxWindowBase::MakeModal(bool modal
)
683 // Disable all other windows
686 wxWindowList::Node
*node
= wxTopLevelWindows
.GetFirst();
689 wxWindow
*win
= node
->GetData();
693 node
= node
->GetNext();
698 bool wxWindowBase::Validate()
701 wxWindowList::Node
*node
;
702 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
704 wxWindowBase
*child
= node
->GetData();
705 wxValidator
*validator
= child
->GetValidator();
706 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
711 #endif // wxUSE_VALIDATORS
716 bool wxWindowBase::TransferDataToWindow()
719 wxWindowList::Node
*node
;
720 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
722 wxWindowBase
*child
= node
->GetData();
723 wxValidator
*validator
= child
->GetValidator();
724 if ( validator
&& !validator
->TransferToWindow() )
726 wxLog
*log
= wxLog::GetActiveTarget();
729 wxLogWarning(_("Could not transfer data to window"));
736 #endif // wxUSE_VALIDATORS
741 bool wxWindowBase::TransferDataFromWindow()
744 wxWindowList::Node
*node
;
745 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
747 wxWindow
*child
= node
->GetData();
748 if ( child
->GetValidator() &&
749 !child
->GetValidator()->TransferFromWindow() )
754 #endif // wxUSE_VALIDATORS
759 void wxWindowBase::InitDialog()
761 wxInitDialogEvent
event(GetId());
762 event
.SetEventObject( this );
763 GetEventHandler()->ProcessEvent(event
);
766 // ----------------------------------------------------------------------------
768 // ----------------------------------------------------------------------------
772 void wxWindowBase::SetToolTip( const wxString
&tip
)
774 // don't create the new tooltip if we already have one
777 m_tooltip
->SetTip( tip
);
781 SetToolTip( new wxToolTip( tip
) );
784 // setting empty tooltip text does not remove the tooltip any more - use
785 // SetToolTip((wxToolTip *)NULL) for this
788 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
796 #endif // wxUSE_TOOLTIPS
798 // ----------------------------------------------------------------------------
799 // constraints and sizers
800 // ----------------------------------------------------------------------------
802 #if wxUSE_CONSTRAINTS
804 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
808 UnsetConstraints(m_constraints
);
809 delete m_constraints
;
811 m_constraints
= constraints
;
814 // Make sure other windows know they're part of a 'meaningful relationship'
815 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
816 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
817 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
818 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
819 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
820 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
821 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
822 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
823 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
824 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
825 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
826 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
827 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
828 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
829 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
830 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
834 // This removes any dangling pointers to this window in other windows'
835 // constraintsInvolvedIn lists.
836 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
840 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
841 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
842 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
843 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
844 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
845 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
846 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
847 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
848 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
849 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
850 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
851 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
852 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
853 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
854 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
855 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
859 // Back-pointer to other windows we're involved with, so if we delete this
860 // window, we must delete any constraints we're involved with.
861 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
863 if ( !m_constraintsInvolvedIn
)
864 m_constraintsInvolvedIn
= new wxWindowList
;
865 if ( !m_constraintsInvolvedIn
->Find(otherWin
) )
866 m_constraintsInvolvedIn
->Append(otherWin
);
869 // REMOVE back-pointer to other windows we're involved with.
870 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
872 if ( m_constraintsInvolvedIn
)
873 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
876 // Reset any constraints that mention this window
877 void wxWindowBase::DeleteRelatedConstraints()
879 if ( m_constraintsInvolvedIn
)
881 wxWindowList::Node
*node
= m_constraintsInvolvedIn
->GetFirst();
884 wxWindow
*win
= node
->GetData();
885 wxLayoutConstraints
*constr
= win
->GetConstraints();
887 // Reset any constraints involving this window
890 constr
->left
.ResetIfWin(this);
891 constr
->top
.ResetIfWin(this);
892 constr
->right
.ResetIfWin(this);
893 constr
->bottom
.ResetIfWin(this);
894 constr
->width
.ResetIfWin(this);
895 constr
->height
.ResetIfWin(this);
896 constr
->centreX
.ResetIfWin(this);
897 constr
->centreY
.ResetIfWin(this);
900 wxWindowList::Node
*next
= node
->GetNext();
905 delete m_constraintsInvolvedIn
;
906 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
910 void wxWindowBase::SetSizer(wxSizer
*sizer
)
912 if (m_windowSizer
) delete m_windowSizer
;
914 m_windowSizer
= sizer
;
917 bool wxWindowBase::Layout()
920 GetClientSize(&w
, &h
);
922 // If there is a sizer, use it instead of the constraints
925 GetSizer()->SetDimension( 0, 0, w
, h
);
929 if ( GetConstraints() )
931 GetConstraints()->width
.SetValue(w
);
932 GetConstraints()->height
.SetValue(h
);
935 // Evaluate child constraints
936 ResetConstraints(); // Mark all constraints as unevaluated
937 DoPhase(1); // Just one phase need if no sizers involved
939 SetConstraintSizes(); // Recursively set the real window sizes
945 // Do a phase of evaluating constraints: the default behaviour. wxSizers may
946 // do a similar thing, but also impose their own 'constraints' and order the
947 // evaluation differently.
948 bool wxWindowBase::LayoutPhase1(int *noChanges
)
950 wxLayoutConstraints
*constr
= GetConstraints();
953 return constr
->SatisfyConstraints(this, noChanges
);
959 bool wxWindowBase::LayoutPhase2(int *noChanges
)
969 // Do a phase of evaluating child constraints
970 bool wxWindowBase::DoPhase(int phase
)
972 int noIterations
= 0;
973 int maxIterations
= 500;
976 wxWindowList succeeded
;
977 while ((noChanges
> 0) && (noIterations
< maxIterations
))
981 wxWindowList::Node
*node
= GetChildren().GetFirst();
984 wxWindow
*child
= node
->GetData();
985 if ( !child
->IsTopLevel() )
987 wxLayoutConstraints
*constr
= child
->GetConstraints();
990 if ( !succeeded
.Find(child
) )
992 int tempNoChanges
= 0;
993 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
994 noChanges
+= tempNoChanges
;
997 succeeded
.Append(child
);
1002 node
= node
->GetNext();
1011 void wxWindowBase::ResetConstraints()
1013 wxLayoutConstraints
*constr
= GetConstraints();
1016 constr
->left
.SetDone(FALSE
);
1017 constr
->top
.SetDone(FALSE
);
1018 constr
->right
.SetDone(FALSE
);
1019 constr
->bottom
.SetDone(FALSE
);
1020 constr
->width
.SetDone(FALSE
);
1021 constr
->height
.SetDone(FALSE
);
1022 constr
->centreX
.SetDone(FALSE
);
1023 constr
->centreY
.SetDone(FALSE
);
1025 wxWindowList::Node
*node
= GetChildren().GetFirst();
1028 wxWindow
*win
= node
->GetData();
1029 if ( !win
->IsTopLevel() )
1030 win
->ResetConstraints();
1031 node
= node
->GetNext();
1035 // Need to distinguish between setting the 'fake' size for windows and sizers,
1036 // and setting the real values.
1037 void wxWindowBase::SetConstraintSizes(bool recurse
)
1039 wxLayoutConstraints
*constr
= GetConstraints();
1040 if ( constr
&& constr
->left
.GetDone() && constr
->right
.GetDone( ) &&
1041 constr
->width
.GetDone() && constr
->height
.GetDone())
1043 int x
= constr
->left
.GetValue();
1044 int y
= constr
->top
.GetValue();
1045 int w
= constr
->width
.GetValue();
1046 int h
= constr
->height
.GetValue();
1048 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1049 (constr
->height
.GetRelationship() != wxAsIs
) )
1051 SetSize(x
, y
, w
, h
);
1055 // If we don't want to resize this window, just move it...
1061 wxChar
*windowClass
= GetClassInfo()->GetClassName();
1064 if ( GetName() == wxT("") )
1065 winName
= wxT("unnamed");
1067 winName
= GetName();
1068 wxLogDebug( wxT("Constraint(s) not satisfied for window of type %s, name %s:\n"),
1069 (const wxChar
*)windowClass
,
1070 (const wxChar
*)winName
);
1071 if ( !constr
->left
.GetDone()) wxLogDebug( wxT(" unsatisfied 'left' constraint.\n") );
1072 if ( !constr
->right
.GetDone()) wxLogDebug( wxT(" unsatisfied 'right' constraint.\n") );
1073 if ( !constr
->width
.GetDone()) wxLogDebug( wxT(" unsatisfied 'width' constraint.\n") );
1074 if ( !constr
->height
.GetDone()) wxLogDebug( wxT(" unsatisfied 'height' constraint.\n") );
1075 wxLogDebug( wxT("Please check constraints: try adding AsIs() constraints.\n") );
1080 wxWindowList::Node
*node
= GetChildren().GetFirst();
1083 wxWindow
*win
= node
->GetData();
1084 if ( !win
->IsTopLevel() )
1085 win
->SetConstraintSizes();
1086 node
= node
->GetNext();
1091 // Only set the size/position of the constraint (if any)
1092 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1094 wxLayoutConstraints
*constr
= GetConstraints();
1099 constr
->left
.SetValue(x
);
1100 constr
->left
.SetDone(TRUE
);
1104 constr
->top
.SetValue(y
);
1105 constr
->top
.SetDone(TRUE
);
1109 constr
->width
.SetValue(w
);
1110 constr
->width
.SetDone(TRUE
);
1114 constr
->height
.SetValue(h
);
1115 constr
->height
.SetDone(TRUE
);
1120 void wxWindowBase::MoveConstraint(int x
, int y
)
1122 wxLayoutConstraints
*constr
= GetConstraints();
1127 constr
->left
.SetValue(x
);
1128 constr
->left
.SetDone(TRUE
);
1132 constr
->top
.SetValue(y
);
1133 constr
->top
.SetDone(TRUE
);
1138 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1140 wxLayoutConstraints
*constr
= GetConstraints();
1143 *w
= constr
->width
.GetValue();
1144 *h
= constr
->height
.GetValue();
1150 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1152 wxLayoutConstraints
*constr
= GetConstraints();
1155 *w
= constr
->width
.GetValue();
1156 *h
= constr
->height
.GetValue();
1159 GetClientSize(w
, h
);
1162 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1164 wxLayoutConstraints
*constr
= GetConstraints();
1167 *x
= constr
->left
.GetValue();
1168 *y
= constr
->top
.GetValue();
1174 #endif // wxUSE_CONSTRAINTS
1176 // ----------------------------------------------------------------------------
1177 // do Update UI processing for child controls
1178 // ----------------------------------------------------------------------------
1180 // TODO: should this be implemented for the child window rather
1181 // than the parent? Then you can override it e.g. for wxCheckBox
1182 // to do the Right Thing rather than having to assume a fixed number
1183 // of control classes.
1184 void wxWindowBase::UpdateWindowUI()
1186 wxUpdateUIEvent
event(GetId());
1187 event
.m_eventObject
= this;
1189 if ( GetEventHandler()->ProcessEvent(event
) )
1191 if ( event
.GetSetEnabled() )
1192 Enable(event
.GetEnabled());
1194 if ( event
.GetSetText() )
1196 wxControl
*control
= wxDynamicCast(this, wxControl
);
1199 wxTextCtrl
*text
= wxDynamicCast(control
, wxTextCtrl
);
1201 text
->SetValue(event
.GetText());
1203 control
->SetLabel(event
.GetText());
1208 wxCheckBox
*checkbox
= wxDynamicCast(this, wxCheckBox
);
1211 if ( event
.GetSetChecked() )
1212 checkbox
->SetValue(event
.GetChecked());
1214 #endif // wxUSE_CHECKBOX
1216 #if wxUSE_RADIOBUTTON
1217 wxRadioButton
*radiobtn
= wxDynamicCast(this, wxRadioButton
);
1220 if ( event
.GetSetChecked() )
1221 radiobtn
->SetValue(event
.GetChecked());
1223 #endif // wxUSE_RADIOBUTTON
1227 // ----------------------------------------------------------------------------
1228 // dialog units translations
1229 // ----------------------------------------------------------------------------
1231 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1233 int charWidth
= GetCharWidth();
1234 int charHeight
= GetCharHeight();
1235 wxPoint
pt2(-1, -1);
1237 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1239 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1244 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1246 int charWidth
= GetCharWidth();
1247 int charHeight
= GetCharHeight();
1248 wxPoint
pt2(-1, -1);
1250 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1252 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1257 // ----------------------------------------------------------------------------
1259 // ----------------------------------------------------------------------------
1261 void wxWindowBase::DoSetClientObject( wxClientData
*data
)
1263 wxASSERT_MSG( m_clientDataType
!= ClientData_Void
,
1264 wxT("can't have both object and void client data") );
1266 if ( m_clientObject
)
1267 delete m_clientObject
;
1269 m_clientObject
= data
;
1270 m_clientDataType
= ClientData_Object
;
1273 wxClientData
*wxWindowBase::DoGetClientObject() const
1275 wxASSERT_MSG( m_clientDataType
== ClientData_Object
,
1276 wxT("this window doesn't have object client data") );
1278 return m_clientObject
;
1281 void wxWindowBase::DoSetClientData( void *data
)
1283 wxASSERT_MSG( m_clientDataType
!= ClientData_Object
,
1284 wxT("can't have both object and void client data") );
1286 m_clientData
= data
;
1287 m_clientDataType
= ClientData_Void
;
1290 void *wxWindowBase::DoGetClientData() const
1292 wxASSERT_MSG( m_clientDataType
== ClientData_Void
,
1293 wxT("this window doesn't have void client data") );
1295 return m_clientData
;
1298 // ----------------------------------------------------------------------------
1300 // ----------------------------------------------------------------------------
1302 // propagate the colour change event to the subwindows
1303 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1305 wxWindowList::Node
*node
= GetChildren().GetFirst();
1308 // Only propagate to non-top-level windows
1309 wxWindow
*win
= node
->GetData();
1310 if ( !win
->IsTopLevel() )
1312 wxSysColourChangedEvent event2
;
1313 event
.m_eventObject
= win
;
1314 win
->GetEventHandler()->ProcessEvent(event2
);
1317 node
= node
->GetNext();
1321 // the default action is to populate dialog with data when it's created
1322 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1324 TransferDataToWindow();
1327 // ----------------------------------------------------------------------------
1328 // list classes implementation
1329 // ----------------------------------------------------------------------------
1331 void wxWindowListNode::DeleteData()
1333 delete (wxWindow
*)GetData();