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 m_font
= *wxSWISS_FONT
; // and this?
127 // an optimization for the event processing: checking this flag is much
128 // faster than using IsKindOf(CLASSINFO(wxWindow))
131 #if wxUSE_CONSTRAINTS
132 // no constraints whatsoever
133 m_constraints
= (wxLayoutConstraints
*) NULL
;
134 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
135 m_windowSizer
= (wxSizer
*) NULL
;
136 m_autoLayout
= FALSE
;
137 #endif // wxUSE_CONSTRAINTS
139 #if wxUSE_DRAG_AND_DROP
140 m_dropTarget
= (wxDropTarget
*)NULL
;
141 #endif // wxUSE_DRAG_AND_DROP
144 m_tooltip
= (wxToolTip
*)NULL
;
145 #endif // wxUSE_TOOLTIPS
148 m_caret
= (wxCaret
*)NULL
;
149 #endif // wxUSE_CARET
152 // common part of window creation process
153 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
155 const wxPoint
& WXUNUSED(pos
),
156 const wxSize
& WXUNUSED(size
),
159 # if defined(__VISAGECPP__)
160 const wxValidator
* validator
,
162 const wxValidator
& validator
,
165 const wxString
& name
)
167 // m_isWindow is set to TRUE in wxWindowBase::Init() as well as many other
168 // member variables - check that it has been called (will catch the case
169 // when a new ctor is added which doesn't call InitWindow)
170 wxASSERT_MSG( m_isWindow
, wxT("Init() must have been called before!") );
172 // generate a new id if the user doesn't care about it
173 m_windowId
= id
== -1 ? NewControlId() : id
;
176 SetWindowStyleFlag(style
);
178 SetValidator(validator
);
183 // ----------------------------------------------------------------------------
185 // ----------------------------------------------------------------------------
188 wxWindowBase::~wxWindowBase()
190 // FIXME if these 2 cases result from programming errors in the user code
191 // we should probably assert here instead of silently fixing them
193 // Just in case the window has been Closed, but we're then deleting
194 // immediately: don't leave dangling pointers.
195 wxPendingDelete
.DeleteObject(this);
197 // Just in case we've loaded a top-level window via LoadNativeDialog but
198 // we weren't a dialog class
199 wxTopLevelWindows
.DeleteObject(this);
201 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
203 // make sure that there are no dangling pointers left pointing to us
204 wxPanel
*panel
= wxDynamicCast(GetParent(), wxPanel
);
207 if ( panel
->GetLastFocus() == this )
209 panel
->SetLastFocus((wxWindow
*)NULL
);
216 #endif // wxUSE_CARET
219 if ( m_windowValidator
)
220 delete m_windowValidator
;
221 #endif // wxUSE_VALIDATORS
223 // we only delete object data, not untyped
224 if ( m_clientDataType
== ClientData_Object
)
225 delete m_clientObject
;
227 #if wxUSE_CONSTRAINTS
228 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
229 // at deleted windows as they delete themselves.
230 DeleteRelatedConstraints();
234 // This removes any dangling pointers to this window in other windows'
235 // constraintsInvolvedIn lists.
236 UnsetConstraints(m_constraints
);
237 delete m_constraints
;
238 m_constraints
= NULL
;
242 delete m_windowSizer
;
244 #endif // wxUSE_CONSTRAINTS
246 #if wxUSE_DRAG_AND_DROP
249 #endif // wxUSE_DRAG_AND_DROP
254 #endif // wxUSE_TOOLTIPS
257 bool wxWindowBase::Destroy()
264 bool wxWindowBase::Close(bool force
)
266 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
267 event
.SetEventObject(this);
268 #if WXWIN_COMPATIBILITY
269 event
.SetForce(force
);
270 #endif // WXWIN_COMPATIBILITY
271 event
.SetCanVeto(!force
);
273 // return FALSE if window wasn't closed because the application vetoed the
275 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
278 bool wxWindowBase::DestroyChildren()
280 wxWindowList::Node
*node
;
283 // we iterate until the list becomes empty
284 node
= GetChildren().GetFirst();
288 wxWindow
*child
= node
->GetData();
290 wxASSERT_MSG( child
, wxT("children list contains empty nodes") );
294 wxASSERT_MSG( !GetChildren().Find(child
),
295 wxT("child didn't remove itself using RemoveChild()") );
301 // ----------------------------------------------------------------------------
302 // centre/fit the window
303 // ----------------------------------------------------------------------------
305 // centre the window with respect to its parent in either (or both) directions
306 void wxWindowBase::Centre(int direction
)
308 int widthParent
, heightParent
;
310 wxWindow
*parent
= GetParent();
314 direction
|= wxCENTRE_ON_SCREEN
;
317 if ( direction
& wxCENTRE_ON_SCREEN
)
319 // centre with respect to the whole screen
320 wxDisplaySize(&widthParent
, &heightParent
);
324 // centre inside the parents rectangle
325 parent
->GetClientSize(&widthParent
, &heightParent
);
329 GetSize(&width
, &height
);
334 if ( direction
& wxHORIZONTAL
)
335 xNew
= (widthParent
- width
)/2;
337 if ( direction
& wxVERTICAL
)
338 yNew
= (heightParent
- height
)/2;
340 // controls are always centered on their parent because it doesn't make
341 // sense to centre them on the screen
342 if ( !(direction
& wxCENTRE_ON_SCREEN
) || wxDynamicCast(this, wxControl
) )
344 // theo nly chance to get this is to have a wxControl without parent
345 wxCHECK_RET( parent
, wxT("a control must have a parent") );
347 // adjust to the parents client area origin
348 wxPoint posParent
= parent
->ClientToScreen(wxPoint(0, 0));
357 // fits the window around the children
358 void wxWindowBase::Fit()
363 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
365 node
= node
->GetNext() )
367 wxWindow
*win
= node
->GetData();
368 if ( win
->IsTopLevel() )
370 // dialogs and frames lie in different top level windows - don't
371 // deal with them here
376 win
->GetPosition(&wx
, &wy
);
377 win
->GetSize(&ww
, &wh
);
378 if ( wx
+ ww
> maxX
)
380 if ( wy
+ wh
> maxY
)
385 SetClientSize(maxX
+ 7, maxY
+ 14);
388 // set the min/max size of the window
390 void wxWindowBase::SetSizeHints(int minW
, int minH
,
392 int WXUNUSED(incW
), int WXUNUSED(incH
))
400 // ----------------------------------------------------------------------------
401 // show/hide/enable/disable the window
402 // ----------------------------------------------------------------------------
404 bool wxWindowBase::Show(bool show
)
406 if ( show
!= m_isShown
)
418 bool wxWindowBase::Enable(bool enable
)
420 if ( enable
!= m_isEnabled
)
422 m_isEnabled
= enable
;
431 // ----------------------------------------------------------------------------
433 // ----------------------------------------------------------------------------
435 bool wxWindowBase::IsTopLevel() const
440 // ----------------------------------------------------------------------------
441 // reparenting the window
442 // ----------------------------------------------------------------------------
444 void wxWindowBase::AddChild(wxWindowBase
*child
)
446 wxCHECK_RET( child
, wxT("can't add a NULL child") );
448 GetChildren().Append(child
);
449 child
->SetParent(this);
452 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
454 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
456 GetChildren().DeleteObject(child
);
457 child
->SetParent((wxWindow
*)NULL
);
460 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
462 wxWindow
*oldParent
= GetParent();
463 if ( newParent
== oldParent
)
469 // unlink this window from the existing parent.
472 oldParent
->RemoveChild(this);
476 wxTopLevelWindows
.DeleteObject(this);
479 // add it to the new one
482 newParent
->AddChild(this);
486 wxTopLevelWindows
.Append(this);
492 // ----------------------------------------------------------------------------
493 // event handler stuff
494 // ----------------------------------------------------------------------------
496 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
498 handler
->SetNextHandler(GetEventHandler());
499 SetEventHandler(handler
);
502 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
504 wxEvtHandler
*handlerA
= GetEventHandler();
507 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
508 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
509 SetEventHandler(handlerB
);
513 handlerA
= (wxEvtHandler
*)NULL
;
520 // ----------------------------------------------------------------------------
522 // ----------------------------------------------------------------------------
524 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
526 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
529 m_backgroundColour
= colour
;
534 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
536 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
539 m_foregroundColour
= colour
;
544 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
546 // don't try to set invalid cursor, always fall back to the default
547 const wxCursor
& cursorOk
= cursor
.Ok() ? cursor
: *wxSTANDARD_CURSOR
;
549 if ( (wxCursor
&)cursorOk
== m_cursor
)
560 bool wxWindowBase::SetFont(const wxFont
& font
)
562 // don't try to set invalid font, always fall back to the default
563 const wxFont
& fontOk
= font
.Ok() ? font
: *wxSWISS_FONT
;
565 if ( (wxFont
&)fontOk
== m_font
)
577 void wxWindowBase::SetCaret(wxCaret
*caret
)
588 wxASSERT_MSG( m_caret
->GetWindow() == this,
589 wxT("caret should be created associated to this window") );
592 #endif // wxUSE_CARET
595 // ----------------------------------------------------------------------------
597 // ----------------------------------------------------------------------------
599 # if defined(__VISAGECPP__)
600 void wxWindowBase::SetValidator(const wxValidator
* validator
)
602 if ( m_windowValidator
)
603 delete m_windowValidator
;
605 m_windowValidator
= (wxValidator
*)validator
->Clone();
607 if ( m_windowValidator
)
608 m_windowValidator
->SetWindow(this) ;
611 void wxWindowBase::SetValidator(const wxValidator
& validator
)
613 if ( m_windowValidator
)
614 delete m_windowValidator
;
616 m_windowValidator
= (wxValidator
*)validator
.Clone();
618 if ( m_windowValidator
)
619 m_windowValidator
->SetWindow(this) ;
621 # endif // __VISAGECPP__
622 #endif // wxUSE_VALIDATORS
624 // ----------------------------------------------------------------------------
625 // update region testing
626 // ----------------------------------------------------------------------------
628 bool wxWindowBase::IsExposed(int x
, int y
) const
630 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
633 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
635 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
638 // ----------------------------------------------------------------------------
639 // find window by id or name
640 // ----------------------------------------------------------------------------
642 wxWindow
*wxWindowBase::FindWindow( long id
)
644 if ( id
== m_windowId
)
645 return (wxWindow
*)this;
647 wxWindowBase
*res
= (wxWindow
*)NULL
;
648 wxWindowList::Node
*node
;
649 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
651 wxWindowBase
*child
= node
->GetData();
652 res
= child
->FindWindow( id
);
655 return (wxWindow
*)res
;
658 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
660 if ( name
== m_windowName
)
661 return (wxWindow
*)this;
663 wxWindowBase
*res
= (wxWindow
*)NULL
;
664 wxWindowList::Node
*node
;
665 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
667 wxWindow
*child
= node
->GetData();
668 res
= child
->FindWindow(name
);
671 return (wxWindow
*)res
;
674 // ----------------------------------------------------------------------------
675 // dialog oriented functions
676 // ----------------------------------------------------------------------------
678 void wxWindowBase::MakeModal(bool modal
)
680 // Disable all other windows
683 wxWindowList::Node
*node
= wxTopLevelWindows
.GetFirst();
686 wxWindow
*win
= node
->GetData();
690 node
= node
->GetNext();
695 bool wxWindowBase::Validate()
698 wxWindowList::Node
*node
;
699 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
701 wxWindowBase
*child
= node
->GetData();
702 wxValidator
*validator
= child
->GetValidator();
703 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
708 #endif // wxUSE_VALIDATORS
713 bool wxWindowBase::TransferDataToWindow()
716 wxWindowList::Node
*node
;
717 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
719 wxWindowBase
*child
= node
->GetData();
720 wxValidator
*validator
= child
->GetValidator();
721 if ( validator
&& !validator
->TransferToWindow() )
723 wxLog
*log
= wxLog::GetActiveTarget();
726 wxLogWarning(_("Could not transfer data to window"));
733 #endif // wxUSE_VALIDATORS
738 bool wxWindowBase::TransferDataFromWindow()
741 wxWindowList::Node
*node
;
742 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
744 wxWindow
*child
= node
->GetData();
745 if ( child
->GetValidator() &&
746 !child
->GetValidator()->TransferFromWindow() )
751 #endif // wxUSE_VALIDATORS
756 void wxWindowBase::InitDialog()
758 wxInitDialogEvent
event(GetId());
759 event
.SetEventObject( this );
760 GetEventHandler()->ProcessEvent(event
);
763 // ----------------------------------------------------------------------------
765 // ----------------------------------------------------------------------------
769 void wxWindowBase::SetToolTip( const wxString
&tip
)
771 // don't create the new tooltip if we already have one
774 m_tooltip
->SetTip( tip
);
778 SetToolTip( new wxToolTip( tip
) );
781 // setting empty tooltip text does not remove the tooltip any more - use
782 // SetToolTip((wxToolTip *)NULL) for this
785 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
793 #endif // wxUSE_TOOLTIPS
795 // ----------------------------------------------------------------------------
796 // constraints and sizers
797 // ----------------------------------------------------------------------------
799 #if wxUSE_CONSTRAINTS
801 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
805 UnsetConstraints(m_constraints
);
806 delete m_constraints
;
808 m_constraints
= constraints
;
811 // Make sure other windows know they're part of a 'meaningful relationship'
812 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
813 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
814 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
815 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
816 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
817 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
818 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
819 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
820 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
821 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
822 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
823 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
824 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
825 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
826 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
827 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
831 // This removes any dangling pointers to this window in other windows'
832 // constraintsInvolvedIn lists.
833 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
837 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
838 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
839 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
840 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
841 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
842 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
843 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
844 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
845 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
846 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
847 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
848 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
849 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
850 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
851 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
852 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
856 // Back-pointer to other windows we're involved with, so if we delete this
857 // window, we must delete any constraints we're involved with.
858 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
860 if ( !m_constraintsInvolvedIn
)
861 m_constraintsInvolvedIn
= new wxWindowList
;
862 if ( !m_constraintsInvolvedIn
->Find(otherWin
) )
863 m_constraintsInvolvedIn
->Append(otherWin
);
866 // REMOVE back-pointer to other windows we're involved with.
867 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
869 if ( m_constraintsInvolvedIn
)
870 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
873 // Reset any constraints that mention this window
874 void wxWindowBase::DeleteRelatedConstraints()
876 if ( m_constraintsInvolvedIn
)
878 wxWindowList::Node
*node
= m_constraintsInvolvedIn
->GetFirst();
881 wxWindow
*win
= node
->GetData();
882 wxLayoutConstraints
*constr
= win
->GetConstraints();
884 // Reset any constraints involving this window
887 constr
->left
.ResetIfWin(this);
888 constr
->top
.ResetIfWin(this);
889 constr
->right
.ResetIfWin(this);
890 constr
->bottom
.ResetIfWin(this);
891 constr
->width
.ResetIfWin(this);
892 constr
->height
.ResetIfWin(this);
893 constr
->centreX
.ResetIfWin(this);
894 constr
->centreY
.ResetIfWin(this);
897 wxWindowList::Node
*next
= node
->GetNext();
902 delete m_constraintsInvolvedIn
;
903 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
907 void wxWindowBase::SetSizer(wxSizer
*sizer
)
909 if (m_windowSizer
) delete m_windowSizer
;
911 m_windowSizer
= sizer
;
914 bool wxWindowBase::Layout()
917 GetClientSize(&w
, &h
);
919 // If there is a sizer, use it instead of the constraints
922 GetSizer()->SetDimension( 0, 0, w
, h
);
926 if ( GetConstraints() )
928 GetConstraints()->width
.SetValue(w
);
929 GetConstraints()->height
.SetValue(h
);
932 // Evaluate child constraints
933 ResetConstraints(); // Mark all constraints as unevaluated
934 DoPhase(1); // Just one phase need if no sizers involved
936 SetConstraintSizes(); // Recursively set the real window sizes
942 // Do a phase of evaluating constraints: the default behaviour. wxSizers may
943 // do a similar thing, but also impose their own 'constraints' and order the
944 // evaluation differently.
945 bool wxWindowBase::LayoutPhase1(int *noChanges
)
947 wxLayoutConstraints
*constr
= GetConstraints();
950 return constr
->SatisfyConstraints(this, noChanges
);
956 bool wxWindowBase::LayoutPhase2(int *noChanges
)
966 // Do a phase of evaluating child constraints
967 bool wxWindowBase::DoPhase(int phase
)
969 int noIterations
= 0;
970 int maxIterations
= 500;
973 wxWindowList succeeded
;
974 while ((noChanges
> 0) && (noIterations
< maxIterations
))
978 wxWindowList::Node
*node
= GetChildren().GetFirst();
981 wxWindow
*child
= node
->GetData();
982 if ( !child
->IsTopLevel() )
984 wxLayoutConstraints
*constr
= child
->GetConstraints();
987 if ( !succeeded
.Find(child
) )
989 int tempNoChanges
= 0;
990 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
991 noChanges
+= tempNoChanges
;
994 succeeded
.Append(child
);
999 node
= node
->GetNext();
1008 void wxWindowBase::ResetConstraints()
1010 wxLayoutConstraints
*constr
= GetConstraints();
1013 constr
->left
.SetDone(FALSE
);
1014 constr
->top
.SetDone(FALSE
);
1015 constr
->right
.SetDone(FALSE
);
1016 constr
->bottom
.SetDone(FALSE
);
1017 constr
->width
.SetDone(FALSE
);
1018 constr
->height
.SetDone(FALSE
);
1019 constr
->centreX
.SetDone(FALSE
);
1020 constr
->centreY
.SetDone(FALSE
);
1022 wxWindowList::Node
*node
= GetChildren().GetFirst();
1025 wxWindow
*win
= node
->GetData();
1026 if ( !win
->IsTopLevel() )
1027 win
->ResetConstraints();
1028 node
= node
->GetNext();
1032 // Need to distinguish between setting the 'fake' size for windows and sizers,
1033 // and setting the real values.
1034 void wxWindowBase::SetConstraintSizes(bool recurse
)
1036 wxLayoutConstraints
*constr
= GetConstraints();
1037 if ( constr
&& constr
->left
.GetDone() && constr
->right
.GetDone( ) &&
1038 constr
->width
.GetDone() && constr
->height
.GetDone())
1040 int x
= constr
->left
.GetValue();
1041 int y
= constr
->top
.GetValue();
1042 int w
= constr
->width
.GetValue();
1043 int h
= constr
->height
.GetValue();
1045 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1046 (constr
->height
.GetRelationship() != wxAsIs
) )
1048 SetSize(x
, y
, w
, h
);
1052 // If we don't want to resize this window, just move it...
1058 wxChar
*windowClass
= GetClassInfo()->GetClassName();
1061 if ( GetName() == wxT("") )
1062 winName
= wxT("unnamed");
1064 winName
= GetName();
1065 wxLogDebug( wxT("Constraint(s) not satisfied for window of type %s, name %s:\n"),
1066 (const wxChar
*)windowClass
,
1067 (const wxChar
*)winName
);
1068 if ( !constr
->left
.GetDone()) wxLogDebug( wxT(" unsatisfied 'left' constraint.\n") );
1069 if ( !constr
->right
.GetDone()) wxLogDebug( wxT(" unsatisfied 'right' constraint.\n") );
1070 if ( !constr
->width
.GetDone()) wxLogDebug( wxT(" unsatisfied 'width' constraint.\n") );
1071 if ( !constr
->height
.GetDone()) wxLogDebug( wxT(" unsatisfied 'height' constraint.\n") );
1072 wxLogDebug( wxT("Please check constraints: try adding AsIs() constraints.\n") );
1077 wxWindowList::Node
*node
= GetChildren().GetFirst();
1080 wxWindow
*win
= node
->GetData();
1081 if ( !win
->IsTopLevel() )
1082 win
->SetConstraintSizes();
1083 node
= node
->GetNext();
1088 // Only set the size/position of the constraint (if any)
1089 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1091 wxLayoutConstraints
*constr
= GetConstraints();
1096 constr
->left
.SetValue(x
);
1097 constr
->left
.SetDone(TRUE
);
1101 constr
->top
.SetValue(y
);
1102 constr
->top
.SetDone(TRUE
);
1106 constr
->width
.SetValue(w
);
1107 constr
->width
.SetDone(TRUE
);
1111 constr
->height
.SetValue(h
);
1112 constr
->height
.SetDone(TRUE
);
1117 void wxWindowBase::MoveConstraint(int x
, int y
)
1119 wxLayoutConstraints
*constr
= GetConstraints();
1124 constr
->left
.SetValue(x
);
1125 constr
->left
.SetDone(TRUE
);
1129 constr
->top
.SetValue(y
);
1130 constr
->top
.SetDone(TRUE
);
1135 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1137 wxLayoutConstraints
*constr
= GetConstraints();
1140 *w
= constr
->width
.GetValue();
1141 *h
= constr
->height
.GetValue();
1147 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1149 wxLayoutConstraints
*constr
= GetConstraints();
1152 *w
= constr
->width
.GetValue();
1153 *h
= constr
->height
.GetValue();
1156 GetClientSize(w
, h
);
1159 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1161 wxLayoutConstraints
*constr
= GetConstraints();
1164 *x
= constr
->left
.GetValue();
1165 *y
= constr
->top
.GetValue();
1171 #endif // wxUSE_CONSTRAINTS
1173 // ----------------------------------------------------------------------------
1174 // do Update UI processing for child controls
1175 // ----------------------------------------------------------------------------
1177 // TODO: should this be implemented for the child window rather
1178 // than the parent? Then you can override it e.g. for wxCheckBox
1179 // to do the Right Thing rather than having to assume a fixed number
1180 // of control classes.
1181 void wxWindowBase::UpdateWindowUI()
1183 wxUpdateUIEvent
event(GetId());
1184 event
.m_eventObject
= this;
1186 if ( GetEventHandler()->ProcessEvent(event
) )
1188 if ( event
.GetSetEnabled() )
1189 Enable(event
.GetEnabled());
1191 if ( event
.GetSetText() )
1193 wxControl
*control
= wxDynamicCast(this, wxControl
);
1196 wxTextCtrl
*text
= wxDynamicCast(control
, wxTextCtrl
);
1198 text
->SetValue(event
.GetText());
1200 control
->SetLabel(event
.GetText());
1205 wxCheckBox
*checkbox
= wxDynamicCast(this, wxCheckBox
);
1208 if ( event
.GetSetChecked() )
1209 checkbox
->SetValue(event
.GetChecked());
1211 #endif // wxUSE_CHECKBOX
1213 #if wxUSE_RADIOBUTTON
1214 wxRadioButton
*radiobtn
= wxDynamicCast(this, wxRadioButton
);
1217 if ( event
.GetSetChecked() )
1218 radiobtn
->SetValue(event
.GetChecked());
1220 #endif // wxUSE_RADIOBUTTON
1224 // ----------------------------------------------------------------------------
1225 // dialog units translations
1226 // ----------------------------------------------------------------------------
1228 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1230 int charWidth
= GetCharWidth();
1231 int charHeight
= GetCharHeight();
1232 wxPoint
pt2(-1, -1);
1234 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1236 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1241 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1243 int charWidth
= GetCharWidth();
1244 int charHeight
= GetCharHeight();
1245 wxPoint
pt2(-1, -1);
1247 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1249 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1254 // ----------------------------------------------------------------------------
1256 // ----------------------------------------------------------------------------
1258 void wxWindowBase::DoSetClientObject( wxClientData
*data
)
1260 wxASSERT_MSG( m_clientDataType
!= ClientData_Void
,
1261 wxT("can't have both object and void client data") );
1263 if ( m_clientObject
)
1264 delete m_clientObject
;
1266 m_clientObject
= data
;
1267 m_clientDataType
= ClientData_Object
;
1270 wxClientData
*wxWindowBase::DoGetClientObject() const
1272 wxASSERT_MSG( m_clientDataType
== ClientData_Object
,
1273 wxT("this window doesn't have object client data") );
1275 return m_clientObject
;
1278 void wxWindowBase::DoSetClientData( void *data
)
1280 wxASSERT_MSG( m_clientDataType
!= ClientData_Object
,
1281 wxT("can't have both object and void client data") );
1283 m_clientData
= data
;
1284 m_clientDataType
= ClientData_Void
;
1287 void *wxWindowBase::DoGetClientData() const
1289 wxASSERT_MSG( m_clientDataType
== ClientData_Void
,
1290 wxT("this window doesn't have void client data") );
1292 return m_clientData
;
1295 // ----------------------------------------------------------------------------
1297 // ----------------------------------------------------------------------------
1299 // propagate the colour change event to the subwindows
1300 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1302 wxWindowList::Node
*node
= GetChildren().GetFirst();
1305 // Only propagate to non-top-level windows
1306 wxWindow
*win
= node
->GetData();
1307 if ( !win
->IsTopLevel() )
1309 wxSysColourChangedEvent event2
;
1310 event
.m_eventObject
= win
;
1311 win
->GetEventHandler()->ProcessEvent(event2
);
1314 node
= node
->GetNext();
1318 // the default action is to populate dialog with data when it's created
1319 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1321 TransferDataToWindow();
1324 // ----------------------------------------------------------------------------
1325 // list classes implementation
1326 // ----------------------------------------------------------------------------
1328 void wxWindowListNode::DeleteData()
1330 delete (wxWindow
*)GetData();