1 /////////////////////////////////////////////////////////////////////////////
2 // Name: common/window.cpp
3 // Purpose: common (to all ports) wxWindow functions
4 // Author: Julian Smart, Vadim Zeitlin
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "windowbase.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
32 #include "wx/string.h"
37 #include "wx/window.h"
38 #include "wx/checkbox.h"
39 #include "wx/radiobut.h"
40 #include "wx/settings.h"
41 #include "wx/dialog.h"
45 #include "wx/layout.h"
46 #endif // wxUSE_CONSTRAINTS
48 #if wxUSE_DRAG_AND_DROP
50 #endif // wxUSE_DRAG_AND_DROP
53 #include "wx/tooltip.h"
54 #endif // wxUSE_TOOLTIPS
60 // ----------------------------------------------------------------------------
62 // ----------------------------------------------------------------------------
64 int wxWindowBase::ms_lastControlId
= -200;
66 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
68 // ----------------------------------------------------------------------------
70 // ----------------------------------------------------------------------------
72 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
73 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
74 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
77 // ============================================================================
78 // implementation of the common functionality of the wxWindow class
79 // ============================================================================
81 // ----------------------------------------------------------------------------
83 // ----------------------------------------------------------------------------
85 // the default initialization
86 void wxWindowBase::InitBase()
88 // no window yet, no parent nor children
89 m_parent
= (wxWindow
*)NULL
;
91 m_children
.DeleteContents( FALSE
); // don't auto delete node data
93 // no constraints on the minimal window size
99 // window is created enabled but it's not visible yet
104 m_clientObject
= (wxClientData
*)NULL
;
107 // the default event handler is just this window
108 m_eventHandler
= this;
112 m_windowValidator
= (wxValidator
*) NULL
;
113 #endif // wxUSE_VALIDATORS
115 // use the system default colours
116 wxSystemSettings settings
;
118 m_backgroundColour
= settings
.GetSystemColour(wxSYS_COLOUR_BTNFACE
);
119 m_foregroundColour
= *wxBLACK
; // TODO take this from sys settings too?
120 m_font
= *wxSWISS_FONT
; // and this?
125 // an optimization for the event processing: checking this flag is much
126 // faster than using IsKindOf(CLASSINFO(wxWindow))
129 #if wxUSE_CONSTRAINTS
130 // no constraints whatsoever
131 m_constraints
= (wxLayoutConstraints
*) NULL
;
132 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
133 m_windowSizer
= (wxSizer
*) NULL
;
134 m_sizerParent
= (wxWindowBase
*) NULL
;
135 m_autoLayout
= FALSE
;
136 #endif // wxUSE_CONSTRAINTS
138 #if wxUSE_DRAG_AND_DROP
139 m_dropTarget
= (wxDropTarget
*)NULL
;
140 #endif // wxUSE_DRAG_AND_DROP
143 m_tooltip
= (wxToolTip
*)NULL
;
144 #endif // wxUSE_TOOLTIPS
147 m_caret
= (wxCaret
*)NULL
;
148 #endif // wxUSE_CARET
151 // common part of window creation process
152 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
154 const wxPoint
& WXUNUSED(pos
),
155 const wxSize
& WXUNUSED(size
),
157 const wxString
& name
)
159 // m_isWindow is set to TRUE in wxWindowBase::Init() as well as many other
160 // member variables - check that it has been called (will catch the case
161 // when a new ctor is added which doesn't call InitWindow)
162 wxASSERT_MSG( m_isWindow
, _T("Init() must have been called before!") );
164 // generate a new id if the user doesn't care about it
165 m_windowId
= id
== -1 ? NewControlId() : id
;
168 SetWindowStyleFlag(style
);
174 // ----------------------------------------------------------------------------
176 // ----------------------------------------------------------------------------
179 wxWindowBase::~wxWindowBase()
181 // FIXME if these 2 cases result from programming errors in the user code
182 // we should probably assert here instead of silently fixing them
184 // Just in case the window has been Closed, but we're then deleting
185 // immediately: don't leave dangling pointers.
186 wxPendingDelete
.DeleteObject(this);
188 // Just in case we've loaded a top-level window via LoadNativeDialog but
189 // we weren't a dialog class
190 wxTopLevelWindows
.DeleteObject(this);
192 wxASSERT_MSG( GetChildren().GetCount() == 0, _T("children not destroyed") );
194 // make sure that there are no dangling pointers left pointing to us
195 wxPanel
*panel
= wxDynamicCast(GetParent(), wxPanel
);
198 if ( panel
->GetLastFocus() == this )
200 panel
->SetLastFocus((wxWindow
*)NULL
);
207 #endif // wxUSE_CARET
210 if ( m_windowValidator
)
211 delete m_windowValidator
;
212 #endif // wxUSE_VALIDATORS
214 if ( m_clientObject
)
215 delete m_clientObject
;
217 #if wxUSE_CONSTRAINTS
218 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
219 // at deleted windows as they delete themselves.
220 DeleteRelatedConstraints();
224 // This removes any dangling pointers to this window in other windows'
225 // constraintsInvolvedIn lists.
226 UnsetConstraints(m_constraints
);
227 delete m_constraints
;
228 m_constraints
= NULL
;
232 delete m_windowSizer
;
234 // If this is a child of a sizer, remove self from parent
236 m_sizerParent
->RemoveChild(this);
237 #endif // wxUSE_CONSTRAINTS
239 #if wxUSE_DRAG_AND_DROP
242 #endif // wxUSE_DRAG_AND_DROP
247 #endif // wxUSE_TOOLTIPS
250 bool wxWindowBase::Destroy()
257 bool wxWindowBase::Close(bool force
)
259 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
260 event
.SetEventObject(this);
261 #if WXWIN_COMPATIBILITY
262 event
.SetForce(force
);
263 #endif // WXWIN_COMPATIBILITY
264 event
.SetCanVeto(!force
);
266 // return FALSE if window wasn't closed because the application vetoed the
268 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
271 bool wxWindowBase::DestroyChildren()
273 wxWindowList::Node
*node
;
276 // we iterate until the list becomes empty
277 node
= GetChildren().GetFirst();
281 wxWindow
*child
= node
->GetData();
283 wxASSERT_MSG( child
, _T("children list contains empty nodes") );
287 wxASSERT_MSG( !GetChildren().Find(child
),
288 _T("child didn't remove itself using RemoveChild()") );
294 // ----------------------------------------------------------------------------
295 // centre/fit the window
296 // ----------------------------------------------------------------------------
298 // centre the window with respect to its parent in either (or both) directions
299 void wxWindowBase::Centre(int direction
)
301 int widthParent
, heightParent
;
303 wxWindow
*parent
= GetParent();
306 parent
->GetClientSize(&widthParent
, &heightParent
);
310 // centre with respect to the whole screen
311 wxDisplaySize(&widthParent
, &heightParent
);
315 GetSize(&width
, &height
);
320 if ( direction
& wxHORIZONTAL
)
321 new_x
= (widthParent
- width
)/2;
323 if ( direction
& wxVERTICAL
)
324 new_y
= (heightParent
- height
)/2;
329 // Center TopLevel windows over thier parent instead of the whole screen
330 void wxWindowBase::CentreOnParent(int direction
)
335 wxWindow
* parent
= GetParent();
338 if (!parent
|| !IsTopLevel()) {
343 psze
= parent
->GetSize();
344 ppos
= parent
->ClientToScreen(wxPoint(0,0));
349 if (direction
== wxBOTH
|| direction
== wxHORIZONTAL
)
350 x
= ppos
.x
+ (psze
.x
- wsze
.x
)/2;
351 if (direction
== wxBOTH
|| direction
== wxVERTICAL
)
352 y
= ppos
.y
+ (psze
.y
- wsze
.y
)/2;
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
437 return wxDynamicCast(this, wxFrame
) || wxDynamicCast(this, wxDialog
);
440 // ----------------------------------------------------------------------------
441 // reparenting the window
442 // ----------------------------------------------------------------------------
444 void wxWindowBase::AddChild(wxWindowBase
*child
)
446 wxCHECK_RET( child
, _T("can't add a NULL child") );
448 GetChildren().Append(child
);
449 child
->SetParent(this);
452 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
454 wxCHECK_RET( child
, _T("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 ( 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 ( fontOk
== m_font
)
577 void wxWindowBase::SetCaret(wxCaret
*caret
)
588 wxASSERT_MSG( m_caret
->GetWindow() == this,
589 _T("caret should be created associated to this window") );
592 #endif // wxUSE_CARET
595 // ----------------------------------------------------------------------------
597 // ----------------------------------------------------------------------------
599 void wxWindowBase::SetValidator(const wxValidator
& validator
)
601 if ( m_windowValidator
)
602 delete m_windowValidator
;
604 m_windowValidator
= (wxValidator
*)validator
.Clone();
606 if ( m_windowValidator
)
607 m_windowValidator
->SetWindow(this) ;
609 #endif // wxUSE_VALIDATORS
611 // ----------------------------------------------------------------------------
612 // update region testing
613 // ----------------------------------------------------------------------------
615 bool wxWindowBase::IsExposed(int x
, int y
) const
617 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
620 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
622 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
625 // ----------------------------------------------------------------------------
626 // find window by id or name
627 // ----------------------------------------------------------------------------
629 wxWindow
*wxWindowBase::FindWindow( long id
)
631 if ( id
== m_windowId
)
632 return (wxWindow
*)this;
634 wxWindowBase
*res
= (wxWindow
*)NULL
;
635 wxWindowList::Node
*node
;
636 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
638 wxWindowBase
*child
= node
->GetData();
639 res
= child
->FindWindow( id
);
642 return (wxWindow
*)res
;
645 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
647 if ( name
== m_windowName
)
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 wxWindow
*child
= node
->GetData();
655 res
= child
->FindWindow(name
);
658 return (wxWindow
*)res
;
661 // ----------------------------------------------------------------------------
662 // dialog oriented functions
663 // ----------------------------------------------------------------------------
665 void wxWindowBase::MakeModal(bool modal
)
667 // Disable all other windows
670 wxWindowList::Node
*node
= wxTopLevelWindows
.GetFirst();
673 wxWindow
*win
= node
->GetData();
677 node
= node
->GetNext();
682 bool wxWindowBase::Validate()
685 wxWindowList::Node
*node
;
686 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
688 wxWindowBase
*child
= node
->GetData();
689 wxValidator
*validator
= child
->GetValidator();
690 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
695 #endif // wxUSE_VALIDATORS
700 bool wxWindowBase::TransferDataToWindow()
703 wxWindowList::Node
*node
;
704 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
706 wxWindowBase
*child
= node
->GetData();
707 wxValidator
*validator
= child
->GetValidator();
708 if ( validator
&& !validator
->TransferToWindow() )
710 wxLog
*log
= wxLog::GetActiveTarget();
713 wxLogWarning(_("Could not transfer data to window"));
720 #endif // wxUSE_VALIDATORS
725 bool wxWindowBase::TransferDataFromWindow()
728 wxWindowList::Node
*node
;
729 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
731 wxWindow
*child
= node
->GetData();
732 if ( child
->GetValidator() &&
733 !child
->GetValidator()->TransferFromWindow() )
738 #endif // wxUSE_VALIDATORS
743 void wxWindowBase::InitDialog()
745 wxInitDialogEvent
event(GetId());
746 event
.SetEventObject( this );
747 GetEventHandler()->ProcessEvent(event
);
750 // ----------------------------------------------------------------------------
752 // ----------------------------------------------------------------------------
756 void wxWindowBase::SetToolTip( const wxString
&tip
)
758 // don't create the new tooltip if we already have one
761 m_tooltip
->SetTip( tip
);
765 SetToolTip( new wxToolTip( tip
) );
768 // setting empty tooltip text does not remove the tooltip any more - use
769 // SetToolTip((wxToolTip *)NULL) for this
772 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
780 #endif // wxUSE_TOOLTIPS
782 // ----------------------------------------------------------------------------
783 // constraints and sizers
784 // ----------------------------------------------------------------------------
786 #if wxUSE_CONSTRAINTS
788 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
792 UnsetConstraints(m_constraints
);
793 delete m_constraints
;
795 m_constraints
= constraints
;
798 // Make sure other windows know they're part of a 'meaningful relationship'
799 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
800 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
801 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
802 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
803 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
804 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
805 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
806 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
807 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
808 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
809 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
810 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
811 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
812 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
813 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
814 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
818 // This removes any dangling pointers to this window in other windows'
819 // constraintsInvolvedIn lists.
820 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
824 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
825 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
826 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
827 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
828 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
829 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
830 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
831 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
832 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
833 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
834 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
835 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
836 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
837 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
838 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
839 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
843 // Back-pointer to other windows we're involved with, so if we delete this
844 // window, we must delete any constraints we're involved with.
845 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
847 if ( !m_constraintsInvolvedIn
)
848 m_constraintsInvolvedIn
= new wxWindowList
;
849 if ( !m_constraintsInvolvedIn
->Find(otherWin
) )
850 m_constraintsInvolvedIn
->Append(otherWin
);
853 // REMOVE back-pointer to other windows we're involved with.
854 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
856 if ( m_constraintsInvolvedIn
)
857 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
860 // Reset any constraints that mention this window
861 void wxWindowBase::DeleteRelatedConstraints()
863 if ( m_constraintsInvolvedIn
)
865 wxWindowList::Node
*node
= m_constraintsInvolvedIn
->GetFirst();
868 wxWindow
*win
= node
->GetData();
869 wxLayoutConstraints
*constr
= win
->GetConstraints();
871 // Reset any constraints involving this window
874 constr
->left
.ResetIfWin(this);
875 constr
->top
.ResetIfWin(this);
876 constr
->right
.ResetIfWin(this);
877 constr
->bottom
.ResetIfWin(this);
878 constr
->width
.ResetIfWin(this);
879 constr
->height
.ResetIfWin(this);
880 constr
->centreX
.ResetIfWin(this);
881 constr
->centreY
.ResetIfWin(this);
884 wxWindowList::Node
*next
= node
->GetNext();
889 delete m_constraintsInvolvedIn
;
890 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
894 void wxWindowBase::SetSizer(wxSizer
*sizer
)
896 m_windowSizer
= sizer
;
898 sizer
->SetSizerParent(this);
901 bool wxWindowBase::Layout()
903 if ( GetConstraints() )
906 GetClientSize(&w
, &h
);
907 GetConstraints()->width
.SetValue(w
);
908 GetConstraints()->height
.SetValue(h
);
911 // If top level (one sizer), evaluate the sizer's constraints.
915 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
916 GetSizer()->LayoutPhase1(&noChanges
);
917 GetSizer()->LayoutPhase2(&noChanges
);
918 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
923 // Otherwise, evaluate child constraints
924 ResetConstraints(); // Mark all constraints as unevaluated
925 DoPhase(1); // Just one phase need if no sizers involved
927 SetConstraintSizes(); // Recursively set the real window sizes
933 // Do a phase of evaluating constraints: the default behaviour. wxSizers may
934 // do a similar thing, but also impose their own 'constraints' and order the
935 // evaluation differently.
936 bool wxWindowBase::LayoutPhase1(int *noChanges
)
938 wxLayoutConstraints
*constr
= GetConstraints();
941 return constr
->SatisfyConstraints(this, noChanges
);
947 bool wxWindowBase::LayoutPhase2(int *noChanges
)
957 // Do a phase of evaluating child constraints
958 bool wxWindowBase::DoPhase(int phase
)
960 int noIterations
= 0;
961 int maxIterations
= 500;
964 wxWindowList succeeded
;
965 while ((noChanges
> 0) && (noIterations
< maxIterations
))
969 wxWindowList::Node
*node
= GetChildren().GetFirst();
972 wxWindow
*child
= node
->GetData();
973 if ( !child
->IsTopLevel() )
975 wxLayoutConstraints
*constr
= child
->GetConstraints();
978 if ( !succeeded
.Find(child
) )
980 int tempNoChanges
= 0;
981 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
982 noChanges
+= tempNoChanges
;
985 succeeded
.Append(child
);
990 node
= node
->GetNext();
999 void wxWindowBase::ResetConstraints()
1001 wxLayoutConstraints
*constr
= GetConstraints();
1004 constr
->left
.SetDone(FALSE
);
1005 constr
->top
.SetDone(FALSE
);
1006 constr
->right
.SetDone(FALSE
);
1007 constr
->bottom
.SetDone(FALSE
);
1008 constr
->width
.SetDone(FALSE
);
1009 constr
->height
.SetDone(FALSE
);
1010 constr
->centreX
.SetDone(FALSE
);
1011 constr
->centreY
.SetDone(FALSE
);
1013 wxWindowList::Node
*node
= GetChildren().GetFirst();
1016 wxWindow
*win
= node
->GetData();
1017 if ( !win
->IsTopLevel() )
1018 win
->ResetConstraints();
1019 node
= node
->GetNext();
1023 // Need to distinguish between setting the 'fake' size for windows and sizers,
1024 // and setting the real values.
1025 void wxWindowBase::SetConstraintSizes(bool recurse
)
1027 wxLayoutConstraints
*constr
= GetConstraints();
1028 if ( constr
&& constr
->left
.GetDone() && constr
->right
.GetDone( ) &&
1029 constr
->width
.GetDone() && constr
->height
.GetDone())
1031 int x
= constr
->left
.GetValue();
1032 int y
= constr
->top
.GetValue();
1033 int w
= constr
->width
.GetValue();
1034 int h
= constr
->height
.GetValue();
1036 // If we don't want to resize this window, just move it...
1037 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1038 (constr
->height
.GetRelationship() != wxAsIs
))
1040 // Calls Layout() recursively. AAAGH. How can we stop that.
1041 // Simply take Layout() out of non-top level OnSizes.
1042 SizerSetSize(x
, y
, w
, h
);
1051 wxChar
*windowClass
= GetClassInfo()->GetClassName();
1054 if ( GetName() == _T("") )
1055 winName
= _T("unnamed");
1057 winName
= GetName();
1058 wxLogDebug( _T("Constraint(s) not satisfied for window of type %s, name %s:\n"),
1059 (const wxChar
*)windowClass
,
1060 (const wxChar
*)winName
);
1061 if ( !constr
->left
.GetDone()) wxLogDebug( _T(" unsatisfied 'left' constraint.\n") );
1062 if ( !constr
->right
.GetDone()) wxLogDebug( _T(" unsatisfied 'right' constraint.\n") );
1063 if ( !constr
->width
.GetDone()) wxLogDebug( _T(" unsatisfied 'width' constraint.\n") );
1064 if ( !constr
->height
.GetDone()) wxLogDebug( _T(" unsatisfied 'height' constraint.\n") );
1065 wxLogDebug( _T("Please check constraints: try adding AsIs() constraints.\n") );
1070 wxWindowList::Node
*node
= GetChildren().GetFirst();
1073 wxWindow
*win
= node
->GetData();
1074 if ( !win
->IsTopLevel() )
1075 win
->SetConstraintSizes();
1076 node
= node
->GetNext();
1081 // This assumes that all sizers are 'on' the same window, i.e. the parent of
1083 void wxWindowBase::TransformSizerToActual(int *x
, int *y
) const
1085 if ( !m_sizerParent
|| m_sizerParent
->IsTopLevel() )
1089 m_sizerParent
->GetPosition(&xp
, &yp
);
1090 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
1095 void wxWindowBase::SizerSetSize(int x
, int y
, int w
, int h
)
1099 TransformSizerToActual(&xx
, &yy
);
1100 SetSize(xx
, yy
, w
, h
);
1103 void wxWindowBase::SizerMove(int x
, int y
)
1107 TransformSizerToActual(&xx
, &yy
);
1111 // Only set the size/position of the constraint (if any)
1112 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1114 wxLayoutConstraints
*constr
= GetConstraints();
1119 constr
->left
.SetValue(x
);
1120 constr
->left
.SetDone(TRUE
);
1124 constr
->top
.SetValue(y
);
1125 constr
->top
.SetDone(TRUE
);
1129 constr
->width
.SetValue(w
);
1130 constr
->width
.SetDone(TRUE
);
1134 constr
->height
.SetValue(h
);
1135 constr
->height
.SetDone(TRUE
);
1140 void wxWindowBase::MoveConstraint(int x
, int y
)
1142 wxLayoutConstraints
*constr
= GetConstraints();
1147 constr
->left
.SetValue(x
);
1148 constr
->left
.SetDone(TRUE
);
1152 constr
->top
.SetValue(y
);
1153 constr
->top
.SetDone(TRUE
);
1158 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1160 wxLayoutConstraints
*constr
= GetConstraints();
1163 *w
= constr
->width
.GetValue();
1164 *h
= constr
->height
.GetValue();
1170 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1172 wxLayoutConstraints
*constr
= GetConstraints();
1175 *w
= constr
->width
.GetValue();
1176 *h
= constr
->height
.GetValue();
1179 GetClientSize(w
, h
);
1182 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1184 wxLayoutConstraints
*constr
= GetConstraints();
1187 *x
= constr
->left
.GetValue();
1188 *y
= constr
->top
.GetValue();
1194 #endif // wxUSE_CONSTRAINTS
1196 // ----------------------------------------------------------------------------
1197 // do Update UI processing for child controls
1198 // ----------------------------------------------------------------------------
1200 // TODO: should this be implemented for the child window rather
1201 // than the parent? Then you can override it e.g. for wxCheckBox
1202 // to do the Right Thing rather than having to assume a fixed number
1203 // of control classes.
1204 void wxWindowBase::UpdateWindowUI()
1206 wxWindowID id
= GetId();
1209 wxUpdateUIEvent
event(id
);
1210 event
.m_eventObject
= this;
1212 if ( GetEventHandler()->ProcessEvent(event
) )
1214 if ( event
.GetSetEnabled() )
1215 Enable(event
.GetEnabled());
1217 if ( event
.GetSetText() )
1219 wxControl
*control
= wxDynamicCast(this, wxControl
);
1221 control
->SetLabel(event
.GetText());
1225 wxCheckBox
*checkbox
= wxDynamicCast(this, wxCheckBox
);
1228 if ( event
.GetSetChecked() )
1229 checkbox
->SetValue(event
.GetChecked());
1231 #endif // wxUSE_CHECKBOX
1233 #if wxUSE_RADIOBUTTON
1234 wxRadioButton
*radiobtn
= wxDynamicCast(this, wxRadioButton
);
1237 if ( event
.GetSetChecked() )
1238 radiobtn
->SetValue(event
.GetChecked());
1240 #endif // wxUSE_RADIOBUTTON
1245 // ----------------------------------------------------------------------------
1246 // dialog units translations
1247 // ----------------------------------------------------------------------------
1249 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1251 int charWidth
= GetCharWidth();
1252 int charHeight
= GetCharHeight();
1254 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1255 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1260 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1262 int charWidth
= GetCharWidth();
1263 int charHeight
= GetCharHeight();
1265 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1266 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1271 // ----------------------------------------------------------------------------
1273 // ----------------------------------------------------------------------------
1275 // propagate the colour change event to the subwindows
1276 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1278 wxWindowList::Node
*node
= GetChildren().GetFirst();
1281 // Only propagate to non-top-level windows
1282 wxWindow
*win
= node
->GetData();
1283 if ( !win
->IsTopLevel() )
1285 wxSysColourChangedEvent event2
;
1286 event
.m_eventObject
= win
;
1287 win
->GetEventHandler()->ProcessEvent(event2
);
1290 node
= node
->GetNext();
1294 // the default action is to populate dialog with data when it's created
1295 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1297 TransferDataToWindow();
1300 // ----------------------------------------------------------------------------
1301 // list classes implementation
1302 // ----------------------------------------------------------------------------
1304 void wxWindowListNode::DeleteData()
1306 delete (wxWindow
*)GetData();