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?
122 #if !defined(__WXMAC__) && !defined(__WXGTK__)
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 const wxValidator
& validator
,
164 const wxString
& name
)
166 // m_isWindow is set to TRUE in wxWindowBase::Init() as well as many other
167 // member variables - check that it has been called (will catch the case
168 // when a new ctor is added which doesn't call InitWindow)
169 wxASSERT_MSG( m_isWindow
, wxT("Init() must have been called before!") );
171 // generate a new id if the user doesn't care about it
172 m_windowId
= id
== -1 ? NewControlId() : id
;
175 SetWindowStyleFlag(style
);
177 SetValidator(validator
);
182 // ----------------------------------------------------------------------------
184 // ----------------------------------------------------------------------------
187 wxWindowBase::~wxWindowBase()
189 // FIXME if these 2 cases result from programming errors in the user code
190 // we should probably assert here instead of silently fixing them
192 // Just in case the window has been Closed, but we're then deleting
193 // immediately: don't leave dangling pointers.
194 wxPendingDelete
.DeleteObject(this);
196 // Just in case we've loaded a top-level window via LoadNativeDialog but
197 // we weren't a dialog class
198 wxTopLevelWindows
.DeleteObject(this);
200 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
202 // make sure that there are no dangling pointers left pointing to us
203 wxPanel
*panel
= wxDynamicCast(GetParent(), wxPanel
);
206 if ( panel
->GetLastFocus() == this )
208 panel
->SetLastFocus((wxWindow
*)NULL
);
215 #endif // wxUSE_CARET
218 if ( m_windowValidator
)
219 delete m_windowValidator
;
220 #endif // wxUSE_VALIDATORS
222 // we only delete object data, not untyped
223 if ( m_clientDataType
== ClientData_Object
)
224 delete m_clientObject
;
226 #if wxUSE_CONSTRAINTS
227 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
228 // at deleted windows as they delete themselves.
229 DeleteRelatedConstraints();
233 // This removes any dangling pointers to this window in other windows'
234 // constraintsInvolvedIn lists.
235 UnsetConstraints(m_constraints
);
236 delete m_constraints
;
237 m_constraints
= NULL
;
241 delete m_windowSizer
;
243 #endif // wxUSE_CONSTRAINTS
245 #if wxUSE_DRAG_AND_DROP
248 #endif // wxUSE_DRAG_AND_DROP
253 #endif // wxUSE_TOOLTIPS
256 bool wxWindowBase::Destroy()
263 bool wxWindowBase::Close(bool force
)
265 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
266 event
.SetEventObject(this);
267 #if WXWIN_COMPATIBILITY
268 event
.SetForce(force
);
269 #endif // WXWIN_COMPATIBILITY
270 event
.SetCanVeto(!force
);
272 // return FALSE if window wasn't closed because the application vetoed the
274 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
277 bool wxWindowBase::DestroyChildren()
279 wxWindowList::Node
*node
;
282 // we iterate until the list becomes empty
283 node
= GetChildren().GetFirst();
287 wxWindow
*child
= node
->GetData();
289 wxASSERT_MSG( child
, wxT("children list contains empty nodes") );
293 wxASSERT_MSG( !GetChildren().Find(child
),
294 wxT("child didn't remove itself using RemoveChild()") );
300 // ----------------------------------------------------------------------------
301 // size/position related methods
302 // ----------------------------------------------------------------------------
304 // centre the window with respect to its parent in either (or both) directions
305 void wxWindowBase::Centre(int direction
)
307 int widthParent
, heightParent
;
309 wxWindow
*parent
= GetParent();
313 direction
|= wxCENTRE_ON_SCREEN
;
316 if ( direction
& wxCENTRE_ON_SCREEN
)
318 // centre with respect to the whole screen
319 wxDisplaySize(&widthParent
, &heightParent
);
323 // centre inside the parents rectangle
324 parent
->GetClientSize(&widthParent
, &heightParent
);
328 GetSize(&width
, &height
);
333 if ( direction
& wxHORIZONTAL
)
334 xNew
= (widthParent
- width
)/2;
336 if ( direction
& wxVERTICAL
)
337 yNew
= (heightParent
- height
)/2;
339 // controls are always centered on their parent because it doesn't make
340 // sense to centre them on the screen
341 if ( !(direction
& wxCENTRE_ON_SCREEN
) || wxDynamicCast(this, wxControl
) )
343 // theo nly chance to get this is to have a wxControl without parent
344 wxCHECK_RET( parent
, wxT("a control must have a parent") );
346 // adjust to the parents client area origin
347 wxPoint posParent
= parent
->ClientToScreen(wxPoint(0, 0));
353 // move the centre of this window to this position
357 // fits the window around the children
358 void wxWindowBase::Fit()
360 if ( GetChildren().GetCount() > 0 )
362 SetClientSize(DoGetBestSize());
364 //else: do nothing if we have no children
367 // return the size best suited for the current window
368 wxSize
wxWindowBase::DoGetBestSize() const
370 if ( GetChildren().GetCount() > 0 )
372 // our minimal acceptable size is such that all our windows fit inside
376 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
378 node
= node
->GetNext() )
380 wxWindow
*win
= node
->GetData();
381 if ( win
->IsTopLevel() )
383 // dialogs and frames lie in different top level windows -
384 // don't deal with them here
389 win
->GetPosition(&wx
, &wy
);
390 win
->GetSize(&ww
, &wh
);
391 if ( wx
+ ww
> maxX
)
393 if ( wy
+ wh
> maxY
)
398 return wxSize(maxX
+ 7, maxY
+ 14);
402 // for a generic window there is no natural best size - just use the
408 // set the min/max size of the window
409 void wxWindowBase::SetSizeHints(int minW
, int minH
,
411 int WXUNUSED(incW
), int WXUNUSED(incH
))
419 // ----------------------------------------------------------------------------
420 // show/hide/enable/disable the window
421 // ----------------------------------------------------------------------------
423 bool wxWindowBase::Show(bool show
)
425 if ( show
!= m_isShown
)
437 bool wxWindowBase::Enable(bool enable
)
439 if ( enable
!= m_isEnabled
)
441 m_isEnabled
= enable
;
450 // ----------------------------------------------------------------------------
452 // ----------------------------------------------------------------------------
454 bool wxWindowBase::IsTopLevel() const
459 // ----------------------------------------------------------------------------
460 // reparenting the window
461 // ----------------------------------------------------------------------------
463 void wxWindowBase::AddChild(wxWindowBase
*child
)
465 wxCHECK_RET( child
, wxT("can't add a NULL child") );
467 GetChildren().Append(child
);
468 child
->SetParent(this);
471 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
473 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
475 GetChildren().DeleteObject(child
);
476 child
->SetParent((wxWindow
*)NULL
);
479 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
481 wxWindow
*oldParent
= GetParent();
482 if ( newParent
== oldParent
)
488 // unlink this window from the existing parent.
491 oldParent
->RemoveChild(this);
495 wxTopLevelWindows
.DeleteObject(this);
498 // add it to the new one
501 newParent
->AddChild(this);
505 wxTopLevelWindows
.Append(this);
511 // ----------------------------------------------------------------------------
512 // event handler stuff
513 // ----------------------------------------------------------------------------
515 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
517 handler
->SetNextHandler(GetEventHandler());
518 SetEventHandler(handler
);
521 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
523 wxEvtHandler
*handlerA
= GetEventHandler();
526 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
527 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
528 SetEventHandler(handlerB
);
532 handlerA
= (wxEvtHandler
*)NULL
;
539 // ----------------------------------------------------------------------------
541 // ----------------------------------------------------------------------------
543 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
545 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
548 m_backgroundColour
= colour
;
553 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
555 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
558 m_foregroundColour
= colour
;
563 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
565 // don't try to set invalid cursor, always fall back to the default
566 const wxCursor
& cursorOk
= cursor
.Ok() ? cursor
: *wxSTANDARD_CURSOR
;
568 if ( (wxCursor
&)cursorOk
== m_cursor
)
579 bool wxWindowBase::SetFont(const wxFont
& font
)
581 // don't try to set invalid font, always fall back to the default
582 const wxFont
& fontOk
= font
.Ok() ? font
: *wxSWISS_FONT
;
584 if ( (wxFont
&)fontOk
== m_font
)
596 void wxWindowBase::SetCaret(wxCaret
*caret
)
607 wxASSERT_MSG( m_caret
->GetWindow() == this,
608 wxT("caret should be created associated to this window") );
611 #endif // wxUSE_CARET
614 // ----------------------------------------------------------------------------
616 // ----------------------------------------------------------------------------
618 void wxWindowBase::SetValidator(const wxValidator
& validator
)
620 if ( m_windowValidator
)
621 delete m_windowValidator
;
623 m_windowValidator
= (wxValidator
*)validator
.Clone();
625 if ( m_windowValidator
)
626 m_windowValidator
->SetWindow(this) ;
628 #endif // wxUSE_VALIDATORS
630 // ----------------------------------------------------------------------------
631 // update region testing
632 // ----------------------------------------------------------------------------
634 bool wxWindowBase::IsExposed(int x
, int y
) const
636 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
639 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
641 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
644 // ----------------------------------------------------------------------------
645 // find window by id or name
646 // ----------------------------------------------------------------------------
648 wxWindow
*wxWindowBase::FindWindow( long id
)
650 if ( id
== m_windowId
)
651 return (wxWindow
*)this;
653 wxWindowBase
*res
= (wxWindow
*)NULL
;
654 wxWindowList::Node
*node
;
655 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
657 wxWindowBase
*child
= node
->GetData();
658 res
= child
->FindWindow( id
);
661 return (wxWindow
*)res
;
664 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
666 if ( name
== m_windowName
)
667 return (wxWindow
*)this;
669 wxWindowBase
*res
= (wxWindow
*)NULL
;
670 wxWindowList::Node
*node
;
671 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
673 wxWindow
*child
= node
->GetData();
674 res
= child
->FindWindow(name
);
677 return (wxWindow
*)res
;
680 // ----------------------------------------------------------------------------
681 // dialog oriented functions
682 // ----------------------------------------------------------------------------
684 void wxWindowBase::MakeModal(bool modal
)
686 // Disable all other windows
689 wxWindowList::Node
*node
= wxTopLevelWindows
.GetFirst();
692 wxWindow
*win
= node
->GetData();
696 node
= node
->GetNext();
701 bool wxWindowBase::Validate()
704 wxWindowList::Node
*node
;
705 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
707 wxWindowBase
*child
= node
->GetData();
708 wxValidator
*validator
= child
->GetValidator();
709 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
714 #endif // wxUSE_VALIDATORS
719 bool wxWindowBase::TransferDataToWindow()
722 wxWindowList::Node
*node
;
723 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
725 wxWindowBase
*child
= node
->GetData();
726 wxValidator
*validator
= child
->GetValidator();
727 if ( validator
&& !validator
->TransferToWindow() )
729 wxLog
*log
= wxLog::GetActiveTarget();
732 wxLogWarning(_("Could not transfer data to window"));
739 #endif // wxUSE_VALIDATORS
744 bool wxWindowBase::TransferDataFromWindow()
747 wxWindowList::Node
*node
;
748 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
750 wxWindow
*child
= node
->GetData();
751 if ( child
->GetValidator() &&
752 !child
->GetValidator()->TransferFromWindow() )
757 #endif // wxUSE_VALIDATORS
762 void wxWindowBase::InitDialog()
764 wxInitDialogEvent
event(GetId());
765 event
.SetEventObject( this );
766 GetEventHandler()->ProcessEvent(event
);
769 // ----------------------------------------------------------------------------
771 // ----------------------------------------------------------------------------
775 void wxWindowBase::SetToolTip( const wxString
&tip
)
777 // don't create the new tooltip if we already have one
780 m_tooltip
->SetTip( tip
);
784 SetToolTip( new wxToolTip( tip
) );
787 // setting empty tooltip text does not remove the tooltip any more - use
788 // SetToolTip((wxToolTip *)NULL) for this
791 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
799 #endif // wxUSE_TOOLTIPS
801 // ----------------------------------------------------------------------------
802 // constraints and sizers
803 // ----------------------------------------------------------------------------
805 #if wxUSE_CONSTRAINTS
807 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
811 UnsetConstraints(m_constraints
);
812 delete m_constraints
;
814 m_constraints
= constraints
;
817 // Make sure other windows know they're part of a 'meaningful relationship'
818 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
819 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
820 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
821 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
822 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
823 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
824 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
825 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
826 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
827 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
828 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
829 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
830 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
831 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
832 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
833 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
837 // This removes any dangling pointers to this window in other windows'
838 // constraintsInvolvedIn lists.
839 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
843 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
844 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
845 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
846 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
847 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
848 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
849 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
850 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
851 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
852 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
853 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
854 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
855 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
856 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
857 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
858 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
862 // Back-pointer to other windows we're involved with, so if we delete this
863 // window, we must delete any constraints we're involved with.
864 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
866 if ( !m_constraintsInvolvedIn
)
867 m_constraintsInvolvedIn
= new wxWindowList
;
868 if ( !m_constraintsInvolvedIn
->Find(otherWin
) )
869 m_constraintsInvolvedIn
->Append(otherWin
);
872 // REMOVE back-pointer to other windows we're involved with.
873 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
875 if ( m_constraintsInvolvedIn
)
876 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
879 // Reset any constraints that mention this window
880 void wxWindowBase::DeleteRelatedConstraints()
882 if ( m_constraintsInvolvedIn
)
884 wxWindowList::Node
*node
= m_constraintsInvolvedIn
->GetFirst();
887 wxWindow
*win
= node
->GetData();
888 wxLayoutConstraints
*constr
= win
->GetConstraints();
890 // Reset any constraints involving this window
893 constr
->left
.ResetIfWin(this);
894 constr
->top
.ResetIfWin(this);
895 constr
->right
.ResetIfWin(this);
896 constr
->bottom
.ResetIfWin(this);
897 constr
->width
.ResetIfWin(this);
898 constr
->height
.ResetIfWin(this);
899 constr
->centreX
.ResetIfWin(this);
900 constr
->centreY
.ResetIfWin(this);
903 wxWindowList::Node
*next
= node
->GetNext();
908 delete m_constraintsInvolvedIn
;
909 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
913 void wxWindowBase::SetSizer(wxSizer
*sizer
)
915 if (m_windowSizer
) delete m_windowSizer
;
917 m_windowSizer
= sizer
;
920 bool wxWindowBase::Layout()
923 GetClientSize(&w
, &h
);
925 // If there is a sizer, use it instead of the constraints
928 GetSizer()->SetDimension( 0, 0, w
, h
);
932 if ( GetConstraints() )
934 GetConstraints()->width
.SetValue(w
);
935 GetConstraints()->height
.SetValue(h
);
938 // Evaluate child constraints
939 ResetConstraints(); // Mark all constraints as unevaluated
940 DoPhase(1); // Just one phase need if no sizers involved
942 SetConstraintSizes(); // Recursively set the real window sizes
948 // Do a phase of evaluating constraints: the default behaviour. wxSizers may
949 // do a similar thing, but also impose their own 'constraints' and order the
950 // evaluation differently.
951 bool wxWindowBase::LayoutPhase1(int *noChanges
)
953 wxLayoutConstraints
*constr
= GetConstraints();
956 return constr
->SatisfyConstraints(this, noChanges
);
962 bool wxWindowBase::LayoutPhase2(int *noChanges
)
972 // Do a phase of evaluating child constraints
973 bool wxWindowBase::DoPhase(int phase
)
975 int noIterations
= 0;
976 int maxIterations
= 500;
979 wxWindowList succeeded
;
980 while ((noChanges
> 0) && (noIterations
< maxIterations
))
984 wxWindowList::Node
*node
= GetChildren().GetFirst();
987 wxWindow
*child
= node
->GetData();
988 if ( !child
->IsTopLevel() )
990 wxLayoutConstraints
*constr
= child
->GetConstraints();
993 if ( !succeeded
.Find(child
) )
995 int tempNoChanges
= 0;
996 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
997 noChanges
+= tempNoChanges
;
1000 succeeded
.Append(child
);
1005 node
= node
->GetNext();
1014 void wxWindowBase::ResetConstraints()
1016 wxLayoutConstraints
*constr
= GetConstraints();
1019 constr
->left
.SetDone(FALSE
);
1020 constr
->top
.SetDone(FALSE
);
1021 constr
->right
.SetDone(FALSE
);
1022 constr
->bottom
.SetDone(FALSE
);
1023 constr
->width
.SetDone(FALSE
);
1024 constr
->height
.SetDone(FALSE
);
1025 constr
->centreX
.SetDone(FALSE
);
1026 constr
->centreY
.SetDone(FALSE
);
1028 wxWindowList::Node
*node
= GetChildren().GetFirst();
1031 wxWindow
*win
= node
->GetData();
1032 if ( !win
->IsTopLevel() )
1033 win
->ResetConstraints();
1034 node
= node
->GetNext();
1038 // Need to distinguish between setting the 'fake' size for windows and sizers,
1039 // and setting the real values.
1040 void wxWindowBase::SetConstraintSizes(bool recurse
)
1042 wxLayoutConstraints
*constr
= GetConstraints();
1043 if ( constr
&& constr
->left
.GetDone() && constr
->right
.GetDone( ) &&
1044 constr
->width
.GetDone() && constr
->height
.GetDone())
1046 int x
= constr
->left
.GetValue();
1047 int y
= constr
->top
.GetValue();
1048 int w
= constr
->width
.GetValue();
1049 int h
= constr
->height
.GetValue();
1051 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1052 (constr
->height
.GetRelationship() != wxAsIs
) )
1054 SetSize(x
, y
, w
, h
);
1058 // If we don't want to resize this window, just move it...
1064 wxChar
*windowClass
= GetClassInfo()->GetClassName();
1067 if ( GetName() == wxT("") )
1068 winName
= wxT("unnamed");
1070 winName
= GetName();
1071 wxLogDebug( wxT("Constraint(s) not satisfied for window of type %s, name %s:\n"),
1072 (const wxChar
*)windowClass
,
1073 (const wxChar
*)winName
);
1074 if ( !constr
->left
.GetDone()) wxLogDebug( wxT(" unsatisfied 'left' constraint.\n") );
1075 if ( !constr
->right
.GetDone()) wxLogDebug( wxT(" unsatisfied 'right' constraint.\n") );
1076 if ( !constr
->width
.GetDone()) wxLogDebug( wxT(" unsatisfied 'width' constraint.\n") );
1077 if ( !constr
->height
.GetDone()) wxLogDebug( wxT(" unsatisfied 'height' constraint.\n") );
1078 wxLogDebug( wxT("Please check constraints: try adding AsIs() constraints.\n") );
1083 wxWindowList::Node
*node
= GetChildren().GetFirst();
1086 wxWindow
*win
= node
->GetData();
1087 if ( !win
->IsTopLevel() )
1088 win
->SetConstraintSizes();
1089 node
= node
->GetNext();
1094 // Only set the size/position of the constraint (if any)
1095 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1097 wxLayoutConstraints
*constr
= GetConstraints();
1102 constr
->left
.SetValue(x
);
1103 constr
->left
.SetDone(TRUE
);
1107 constr
->top
.SetValue(y
);
1108 constr
->top
.SetDone(TRUE
);
1112 constr
->width
.SetValue(w
);
1113 constr
->width
.SetDone(TRUE
);
1117 constr
->height
.SetValue(h
);
1118 constr
->height
.SetDone(TRUE
);
1123 void wxWindowBase::MoveConstraint(int x
, int y
)
1125 wxLayoutConstraints
*constr
= GetConstraints();
1130 constr
->left
.SetValue(x
);
1131 constr
->left
.SetDone(TRUE
);
1135 constr
->top
.SetValue(y
);
1136 constr
->top
.SetDone(TRUE
);
1141 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1143 wxLayoutConstraints
*constr
= GetConstraints();
1146 *w
= constr
->width
.GetValue();
1147 *h
= constr
->height
.GetValue();
1153 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1155 wxLayoutConstraints
*constr
= GetConstraints();
1158 *w
= constr
->width
.GetValue();
1159 *h
= constr
->height
.GetValue();
1162 GetClientSize(w
, h
);
1165 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1167 wxLayoutConstraints
*constr
= GetConstraints();
1170 *x
= constr
->left
.GetValue();
1171 *y
= constr
->top
.GetValue();
1177 #endif // wxUSE_CONSTRAINTS
1179 // ----------------------------------------------------------------------------
1180 // do Update UI processing for child controls
1181 // ----------------------------------------------------------------------------
1183 // TODO: should this be implemented for the child window rather
1184 // than the parent? Then you can override it e.g. for wxCheckBox
1185 // to do the Right Thing rather than having to assume a fixed number
1186 // of control classes.
1187 void wxWindowBase::UpdateWindowUI()
1189 wxUpdateUIEvent
event(GetId());
1190 event
.m_eventObject
= this;
1192 if ( GetEventHandler()->ProcessEvent(event
) )
1194 if ( event
.GetSetEnabled() )
1195 Enable(event
.GetEnabled());
1197 if ( event
.GetSetText() )
1199 wxControl
*control
= wxDynamicCast(this, wxControl
);
1202 wxTextCtrl
*text
= wxDynamicCast(control
, wxTextCtrl
);
1204 text
->SetValue(event
.GetText());
1206 control
->SetLabel(event
.GetText());
1211 wxCheckBox
*checkbox
= wxDynamicCast(this, wxCheckBox
);
1214 if ( event
.GetSetChecked() )
1215 checkbox
->SetValue(event
.GetChecked());
1217 #endif // wxUSE_CHECKBOX
1219 #if wxUSE_RADIOBUTTON
1220 wxRadioButton
*radiobtn
= wxDynamicCast(this, wxRadioButton
);
1223 if ( event
.GetSetChecked() )
1224 radiobtn
->SetValue(event
.GetChecked());
1226 #endif // wxUSE_RADIOBUTTON
1230 // ----------------------------------------------------------------------------
1231 // dialog units translations
1232 // ----------------------------------------------------------------------------
1234 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1236 int charWidth
= GetCharWidth();
1237 int charHeight
= GetCharHeight();
1238 wxPoint
pt2(-1, -1);
1240 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1242 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1247 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1249 int charWidth
= GetCharWidth();
1250 int charHeight
= GetCharHeight();
1251 wxPoint
pt2(-1, -1);
1253 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1255 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1260 // ----------------------------------------------------------------------------
1262 // ----------------------------------------------------------------------------
1264 void wxWindowBase::DoSetClientObject( wxClientData
*data
)
1266 wxASSERT_MSG( m_clientDataType
!= ClientData_Void
,
1267 wxT("can't have both object and void client data") );
1269 if ( m_clientObject
)
1270 delete m_clientObject
;
1272 m_clientObject
= data
;
1273 m_clientDataType
= ClientData_Object
;
1276 wxClientData
*wxWindowBase::DoGetClientObject() const
1278 wxASSERT_MSG( m_clientDataType
== ClientData_Object
,
1279 wxT("this window doesn't have object client data") );
1281 return m_clientObject
;
1284 void wxWindowBase::DoSetClientData( void *data
)
1286 wxASSERT_MSG( m_clientDataType
!= ClientData_Object
,
1287 wxT("can't have both object and void client data") );
1289 m_clientData
= data
;
1290 m_clientDataType
= ClientData_Void
;
1293 void *wxWindowBase::DoGetClientData() const
1295 wxASSERT_MSG( m_clientDataType
== ClientData_Void
,
1296 wxT("this window doesn't have void client data") );
1298 return m_clientData
;
1301 // ----------------------------------------------------------------------------
1303 // ----------------------------------------------------------------------------
1305 // propagate the colour change event to the subwindows
1306 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1308 wxWindowList::Node
*node
= GetChildren().GetFirst();
1311 // Only propagate to non-top-level windows
1312 wxWindow
*win
= node
->GetData();
1313 if ( !win
->IsTopLevel() )
1315 wxSysColourChangedEvent event2
;
1316 event
.m_eventObject
= win
;
1317 win
->GetEventHandler()->ProcessEvent(event2
);
1320 node
= node
->GetNext();
1324 // the default action is to populate dialog with data when it's created
1325 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1327 TransferDataToWindow();
1330 // ----------------------------------------------------------------------------
1331 // list classes implementation
1332 // ----------------------------------------------------------------------------
1334 void wxWindowListNode::DeleteData()
1336 delete (wxWindow
*)GetData();