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") );
197 #endif // wxUSE_CARET
200 if ( m_windowValidator
)
201 delete m_windowValidator
;
202 #endif // wxUSE_VALIDATORS
204 if ( m_clientObject
)
205 delete m_clientObject
;
207 #if wxUSE_CONSTRAINTS
208 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
209 // at deleted windows as they delete themselves.
210 DeleteRelatedConstraints();
214 // This removes any dangling pointers to this window in other windows'
215 // constraintsInvolvedIn lists.
216 UnsetConstraints(m_constraints
);
217 delete m_constraints
;
218 m_constraints
= NULL
;
222 delete m_windowSizer
;
224 // If this is a child of a sizer, remove self from parent
226 m_sizerParent
->RemoveChild(this);
227 #endif // wxUSE_CONSTRAINTS
229 #if wxUSE_DRAG_AND_DROP
232 #endif // wxUSE_DRAG_AND_DROP
237 #endif // wxUSE_TOOLTIPS
240 bool wxWindowBase::Destroy()
247 bool wxWindowBase::Close(bool force
)
249 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
250 event
.SetEventObject(this);
251 #if WXWIN_COMPATIBILITY
252 event
.SetForce(force
);
253 #endif // WXWIN_COMPATIBILITY
254 event
.SetCanVeto(!force
);
256 // return FALSE if window wasn't closed because the application vetoed the
258 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
261 bool wxWindowBase::DestroyChildren()
263 wxWindowList::Node
*node
;
266 // we iterate until the list becomes empty
267 node
= GetChildren().GetFirst();
271 wxWindow
*child
= node
->GetData();
273 wxASSERT_MSG( child
, _T("children list contains empty nodes") );
277 wxASSERT_MSG( !GetChildren().Find(child
),
278 _T("child didn't remove itself using RemoveChild()") );
284 // ----------------------------------------------------------------------------
285 // centre/fit the window
286 // ----------------------------------------------------------------------------
288 // centre the window with respect to its parent in either (or both) directions
289 void wxWindowBase::Centre(int direction
)
291 int widthParent
, heightParent
;
293 wxWindow
*parent
= GetParent();
296 parent
->GetClientSize(&widthParent
, &heightParent
);
300 // centre with respect to the whole screen
301 wxDisplaySize(&widthParent
, &heightParent
);
305 GetSize(&width
, &height
);
310 if ( direction
& wxHORIZONTAL
)
311 new_x
= (widthParent
- width
)/2;
313 if ( direction
& wxVERTICAL
)
314 new_y
= (heightParent
- height
)/2;
319 // Center TopLevel windows over thier parent instead of the whole screen
320 void wxWindowBase::CentreOnParent(int direction
)
325 wxWindow
* parent
= GetParent();
328 if (!parent
|| !IsTopLevel()) {
333 psze
= parent
->GetSize();
334 ppos
= parent
->ClientToScreen(wxPoint(0,0));
339 if (direction
== wxBOTH
|| direction
== wxHORIZONTAL
)
340 x
= ppos
.x
+ (psze
.x
- wsze
.x
)/2;
341 if (direction
== wxBOTH
|| direction
== wxVERTICAL
)
342 y
= ppos
.y
+ (psze
.y
- wsze
.y
)/2;
347 // fits the window around the children
348 void wxWindowBase::Fit()
353 wxWindowList::Node
*node
= GetChildren().GetFirst();
356 wxWindow
*win
= node
->GetData();
357 if ( win
->IsTopLevel() )
359 // dialogs and frames lie in different top level windows - don't
360 // deal with them here
365 win
->GetPosition(&wx
, &wy
);
366 win
->GetSize(&ww
, &wh
);
367 if ( wx
+ ww
> maxX
)
369 if ( wy
+ wh
> maxY
)
372 node
= node
->GetNext();
376 SetClientSize(maxX
+ 7, maxY
+ 14);
379 // set the min/max size of the window
381 void wxWindowBase::SetSizeHints(int minW
, int minH
,
383 int WXUNUSED(incW
), int WXUNUSED(incH
))
391 // ----------------------------------------------------------------------------
392 // show/hide/enable/disable the window
393 // ----------------------------------------------------------------------------
395 bool wxWindowBase::Show(bool show
)
397 if ( show
!= m_isShown
)
409 bool wxWindowBase::Enable(bool enable
)
411 if ( enable
!= m_isEnabled
)
413 m_isEnabled
= enable
;
422 // ----------------------------------------------------------------------------
424 // ----------------------------------------------------------------------------
426 bool wxWindowBase::IsTopLevel() const
428 return wxDynamicCast(this, wxFrame
) || wxDynamicCast(this, wxDialog
);
431 // ----------------------------------------------------------------------------
432 // reparenting the window
433 // ----------------------------------------------------------------------------
435 void wxWindowBase::AddChild(wxWindowBase
*child
)
437 wxCHECK_RET( child
, _T("can't add a NULL child") );
439 GetChildren().Append(child
);
440 child
->SetParent(this);
443 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
445 wxCHECK_RET( child
, _T("can't remove a NULL child") );
447 GetChildren().DeleteObject(child
);
448 child
->SetParent((wxWindow
*)NULL
);
451 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
453 wxWindow
*oldParent
= GetParent();
454 if ( newParent
== oldParent
)
460 // unlink this window from the existing parent.
463 oldParent
->RemoveChild(this);
467 wxTopLevelWindows
.DeleteObject(this);
470 // add it to the new one
473 newParent
->AddChild(this);
477 wxTopLevelWindows
.Append(this);
483 // ----------------------------------------------------------------------------
484 // event handler stuff
485 // ----------------------------------------------------------------------------
487 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
489 handler
->SetNextHandler(GetEventHandler());
490 SetEventHandler(handler
);
493 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
495 wxEvtHandler
*handlerA
= GetEventHandler();
498 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
499 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
500 SetEventHandler(handlerB
);
504 handlerA
= (wxEvtHandler
*)NULL
;
511 // ----------------------------------------------------------------------------
513 // ----------------------------------------------------------------------------
515 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
517 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
520 m_backgroundColour
= colour
;
525 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
527 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
530 m_foregroundColour
= colour
;
535 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
537 // don't try to set invalid cursor, always fall back to the default
538 const wxCursor
& cursorOk
= cursor
.Ok() ? cursor
: *wxSTANDARD_CURSOR
;
540 if ( cursorOk
== m_cursor
)
551 bool wxWindowBase::SetFont(const wxFont
& font
)
553 // don't try to set invalid font, always fall back to the default
554 const wxFont
& fontOk
= font
.Ok() ? font
: *wxSWISS_FONT
;
556 if ( fontOk
== m_font
)
568 void wxWindowBase::SetCaret(wxCaret
*caret
)
579 wxASSERT_MSG( m_caret
->GetWindow() == this,
580 _T("caret should be created associated to this window") );
583 #endif // wxUSE_CARET
586 // ----------------------------------------------------------------------------
588 // ----------------------------------------------------------------------------
590 void wxWindowBase::SetValidator(const wxValidator
& validator
)
592 if ( m_windowValidator
)
593 delete m_windowValidator
;
595 m_windowValidator
= (wxValidator
*)validator
.Clone();
597 if ( m_windowValidator
)
598 m_windowValidator
->SetWindow(this) ;
600 #endif // wxUSE_VALIDATORS
602 // ----------------------------------------------------------------------------
603 // update region testing
604 // ----------------------------------------------------------------------------
606 bool wxWindowBase::IsExposed(int x
, int y
) const
608 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
611 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
613 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
616 // ----------------------------------------------------------------------------
617 // find window by id or name
618 // ----------------------------------------------------------------------------
620 wxWindow
*wxWindowBase::FindWindow( long id
)
622 if ( id
== m_windowId
)
623 return (wxWindow
*)this;
625 wxWindowBase
*res
= (wxWindow
*)NULL
;
626 wxWindowList::Node
*node
;
627 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
629 wxWindowBase
*child
= node
->GetData();
630 res
= child
->FindWindow( id
);
633 return (wxWindow
*)res
;
636 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
638 if ( name
== m_windowName
)
639 return (wxWindow
*)this;
641 wxWindowBase
*res
= (wxWindow
*)NULL
;
642 wxWindowList::Node
*node
;
643 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
645 wxWindow
*child
= node
->GetData();
646 res
= child
->FindWindow(name
);
649 return (wxWindow
*)res
;
652 // ----------------------------------------------------------------------------
653 // dialog oriented functions
654 // ----------------------------------------------------------------------------
656 void wxWindowBase::MakeModal(bool modal
)
658 // Disable all other windows
661 wxWindowList::Node
*node
= wxTopLevelWindows
.GetFirst();
664 wxWindow
*win
= node
->GetData();
668 node
= node
->GetNext();
673 bool wxWindowBase::Validate()
676 wxWindowList::Node
*node
;
677 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
679 wxWindowBase
*child
= node
->GetData();
680 wxValidator
*validator
= child
->GetValidator();
681 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
686 #endif // wxUSE_VALIDATORS
691 bool wxWindowBase::TransferDataToWindow()
694 wxWindowList::Node
*node
;
695 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
697 wxWindowBase
*child
= node
->GetData();
698 wxValidator
*validator
= child
->GetValidator();
699 if ( validator
&& !validator
->TransferToWindow() )
701 wxLog
*log
= wxLog::GetActiveTarget();
704 wxLogWarning(_("Could not transfer data to window"));
711 #endif // wxUSE_VALIDATORS
716 bool wxWindowBase::TransferDataFromWindow()
719 wxWindowList::Node
*node
;
720 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
722 wxWindow
*child
= node
->GetData();
723 if ( child
->GetValidator() &&
724 !child
->GetValidator()->TransferFromWindow() )
729 #endif // wxUSE_VALIDATORS
734 void wxWindowBase::InitDialog()
736 wxInitDialogEvent
event(GetId());
737 event
.SetEventObject( this );
738 GetEventHandler()->ProcessEvent(event
);
741 // ----------------------------------------------------------------------------
743 // ----------------------------------------------------------------------------
747 void wxWindowBase::SetToolTip( const wxString
&tip
)
749 // don't create the new tooltip if we already have one
752 m_tooltip
->SetTip( tip
);
756 SetToolTip( new wxToolTip( tip
) );
759 // setting empty tooltip text does not remove the tooltip any more - use
760 // SetToolTip((wxToolTip *)NULL) for this
763 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
771 #endif // wxUSE_TOOLTIPS
773 // ----------------------------------------------------------------------------
774 // constraints and sizers
775 // ----------------------------------------------------------------------------
777 #if wxUSE_CONSTRAINTS
779 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
783 UnsetConstraints(m_constraints
);
784 delete m_constraints
;
786 m_constraints
= constraints
;
789 // Make sure other windows know they're part of a 'meaningful relationship'
790 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
791 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
792 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
793 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
794 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
795 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
796 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
797 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
798 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
799 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
800 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
801 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
802 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
803 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
804 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
805 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
809 // This removes any dangling pointers to this window in other windows'
810 // constraintsInvolvedIn lists.
811 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
815 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
816 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
817 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
818 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
819 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
820 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
821 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
822 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
823 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
824 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
825 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
826 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
827 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
828 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
829 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
830 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
834 // Back-pointer to other windows we're involved with, so if we delete this
835 // window, we must delete any constraints we're involved with.
836 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
838 if ( !m_constraintsInvolvedIn
)
839 m_constraintsInvolvedIn
= new wxWindowList
;
840 if ( !m_constraintsInvolvedIn
->Find(otherWin
) )
841 m_constraintsInvolvedIn
->Append(otherWin
);
844 // REMOVE back-pointer to other windows we're involved with.
845 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
847 if ( m_constraintsInvolvedIn
)
848 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
851 // Reset any constraints that mention this window
852 void wxWindowBase::DeleteRelatedConstraints()
854 if ( m_constraintsInvolvedIn
)
856 wxWindowList::Node
*node
= m_constraintsInvolvedIn
->GetFirst();
859 wxWindow
*win
= node
->GetData();
860 wxLayoutConstraints
*constr
= win
->GetConstraints();
862 // Reset any constraints involving this window
865 constr
->left
.ResetIfWin(this);
866 constr
->top
.ResetIfWin(this);
867 constr
->right
.ResetIfWin(this);
868 constr
->bottom
.ResetIfWin(this);
869 constr
->width
.ResetIfWin(this);
870 constr
->height
.ResetIfWin(this);
871 constr
->centreX
.ResetIfWin(this);
872 constr
->centreY
.ResetIfWin(this);
875 wxWindowList::Node
*next
= node
->GetNext();
880 delete m_constraintsInvolvedIn
;
881 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
885 void wxWindowBase::SetSizer(wxSizer
*sizer
)
887 m_windowSizer
= sizer
;
889 sizer
->SetSizerParent(this);
892 bool wxWindowBase::Layout()
894 if ( GetConstraints() )
897 GetClientSize(&w
, &h
);
898 GetConstraints()->width
.SetValue(w
);
899 GetConstraints()->height
.SetValue(h
);
902 // If top level (one sizer), evaluate the sizer's constraints.
906 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
907 GetSizer()->LayoutPhase1(&noChanges
);
908 GetSizer()->LayoutPhase2(&noChanges
);
909 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
914 // Otherwise, evaluate child constraints
915 ResetConstraints(); // Mark all constraints as unevaluated
916 DoPhase(1); // Just one phase need if no sizers involved
918 SetConstraintSizes(); // Recursively set the real window sizes
924 // Do a phase of evaluating constraints: the default behaviour. wxSizers may
925 // do a similar thing, but also impose their own 'constraints' and order the
926 // evaluation differently.
927 bool wxWindowBase::LayoutPhase1(int *noChanges
)
929 wxLayoutConstraints
*constr
= GetConstraints();
932 return constr
->SatisfyConstraints(this, noChanges
);
938 bool wxWindowBase::LayoutPhase2(int *noChanges
)
948 // Do a phase of evaluating child constraints
949 bool wxWindowBase::DoPhase(int phase
)
951 int noIterations
= 0;
952 int maxIterations
= 500;
955 wxWindowList succeeded
;
956 while ((noChanges
> 0) && (noIterations
< maxIterations
))
960 wxWindowList::Node
*node
= GetChildren().GetFirst();
963 wxWindow
*child
= node
->GetData();
964 if ( !child
->IsTopLevel() )
966 wxLayoutConstraints
*constr
= child
->GetConstraints();
969 if ( !succeeded
.Find(child
) )
971 int tempNoChanges
= 0;
972 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
973 noChanges
+= tempNoChanges
;
976 succeeded
.Append(child
);
981 node
= node
->GetNext();
990 void wxWindowBase::ResetConstraints()
992 wxLayoutConstraints
*constr
= GetConstraints();
995 constr
->left
.SetDone(FALSE
);
996 constr
->top
.SetDone(FALSE
);
997 constr
->right
.SetDone(FALSE
);
998 constr
->bottom
.SetDone(FALSE
);
999 constr
->width
.SetDone(FALSE
);
1000 constr
->height
.SetDone(FALSE
);
1001 constr
->centreX
.SetDone(FALSE
);
1002 constr
->centreY
.SetDone(FALSE
);
1004 wxWindowList::Node
*node
= GetChildren().GetFirst();
1007 wxWindow
*win
= node
->GetData();
1008 if ( !win
->IsTopLevel() )
1009 win
->ResetConstraints();
1010 node
= node
->GetNext();
1014 // Need to distinguish between setting the 'fake' size for windows and sizers,
1015 // and setting the real values.
1016 void wxWindowBase::SetConstraintSizes(bool recurse
)
1018 wxLayoutConstraints
*constr
= GetConstraints();
1019 if ( constr
&& constr
->left
.GetDone() && constr
->right
.GetDone( ) &&
1020 constr
->width
.GetDone() && constr
->height
.GetDone())
1022 int x
= constr
->left
.GetValue();
1023 int y
= constr
->top
.GetValue();
1024 int w
= constr
->width
.GetValue();
1025 int h
= constr
->height
.GetValue();
1027 // If we don't want to resize this window, just move it...
1028 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1029 (constr
->height
.GetRelationship() != wxAsIs
))
1031 // Calls Layout() recursively. AAAGH. How can we stop that.
1032 // Simply take Layout() out of non-top level OnSizes.
1033 SizerSetSize(x
, y
, w
, h
);
1042 wxChar
*windowClass
= GetClassInfo()->GetClassName();
1045 if ( GetName() == _T("") )
1046 winName
= _T("unnamed");
1048 winName
= GetName();
1049 wxLogDebug( _T("Constraint(s) not satisfied for window of type %s, name %s:\n"),
1050 (const wxChar
*)windowClass
,
1051 (const wxChar
*)winName
);
1052 if ( !constr
->left
.GetDone()) wxLogDebug( _T(" unsatisfied 'left' constraint.\n") );
1053 if ( !constr
->right
.GetDone()) wxLogDebug( _T(" unsatisfied 'right' constraint.\n") );
1054 if ( !constr
->width
.GetDone()) wxLogDebug( _T(" unsatisfied 'width' constraint.\n") );
1055 if ( !constr
->height
.GetDone()) wxLogDebug( _T(" unsatisfied 'height' constraint.\n") );
1056 wxLogDebug( _T("Please check constraints: try adding AsIs() constraints.\n") );
1061 wxWindowList::Node
*node
= GetChildren().GetFirst();
1064 wxWindow
*win
= node
->GetData();
1065 if ( !win
->IsTopLevel() )
1066 win
->SetConstraintSizes();
1067 node
= node
->GetNext();
1072 // This assumes that all sizers are 'on' the same window, i.e. the parent of
1074 void wxWindowBase::TransformSizerToActual(int *x
, int *y
) const
1076 if ( !m_sizerParent
|| m_sizerParent
->IsTopLevel() )
1080 m_sizerParent
->GetPosition(&xp
, &yp
);
1081 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
1086 void wxWindowBase::SizerSetSize(int x
, int y
, int w
, int h
)
1090 TransformSizerToActual(&xx
, &yy
);
1091 SetSize(xx
, yy
, w
, h
);
1094 void wxWindowBase::SizerMove(int x
, int y
)
1098 TransformSizerToActual(&xx
, &yy
);
1102 // Only set the size/position of the constraint (if any)
1103 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1105 wxLayoutConstraints
*constr
= GetConstraints();
1110 constr
->left
.SetValue(x
);
1111 constr
->left
.SetDone(TRUE
);
1115 constr
->top
.SetValue(y
);
1116 constr
->top
.SetDone(TRUE
);
1120 constr
->width
.SetValue(w
);
1121 constr
->width
.SetDone(TRUE
);
1125 constr
->height
.SetValue(h
);
1126 constr
->height
.SetDone(TRUE
);
1131 void wxWindowBase::MoveConstraint(int x
, int y
)
1133 wxLayoutConstraints
*constr
= GetConstraints();
1138 constr
->left
.SetValue(x
);
1139 constr
->left
.SetDone(TRUE
);
1143 constr
->top
.SetValue(y
);
1144 constr
->top
.SetDone(TRUE
);
1149 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1151 wxLayoutConstraints
*constr
= GetConstraints();
1154 *w
= constr
->width
.GetValue();
1155 *h
= constr
->height
.GetValue();
1161 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1163 wxLayoutConstraints
*constr
= GetConstraints();
1166 *w
= constr
->width
.GetValue();
1167 *h
= constr
->height
.GetValue();
1170 GetClientSize(w
, h
);
1173 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1175 wxLayoutConstraints
*constr
= GetConstraints();
1178 *x
= constr
->left
.GetValue();
1179 *y
= constr
->top
.GetValue();
1185 #endif // wxUSE_CONSTRAINTS
1187 // ----------------------------------------------------------------------------
1188 // do Update UI processing for child controls
1189 // ----------------------------------------------------------------------------
1191 // TODO: should this be implemented for the child window rather
1192 // than the parent? Then you can override it e.g. for wxCheckBox
1193 // to do the Right Thing rather than having to assume a fixed number
1194 // of control classes.
1195 void wxWindowBase::UpdateWindowUI()
1197 wxWindowID id
= GetId();
1200 wxUpdateUIEvent
event(id
);
1201 event
.m_eventObject
= this;
1203 if ( GetEventHandler()->ProcessEvent(event
) )
1205 if ( event
.GetSetEnabled() )
1206 Enable(event
.GetEnabled());
1208 if ( event
.GetSetText() )
1210 wxControl
*control
= wxDynamicCast(this, wxControl
);
1212 control
->SetLabel(event
.GetText());
1216 wxCheckBox
*checkbox
= wxDynamicCast(this, wxCheckBox
);
1219 if ( event
.GetSetChecked() )
1220 checkbox
->SetValue(event
.GetChecked());
1222 #endif // wxUSE_CHECKBOX
1224 #if wxUSE_RADIOBUTTON
1225 wxRadioButton
*radiobtn
= wxDynamicCast(this, wxRadioButton
);
1228 if ( event
.GetSetChecked() )
1229 radiobtn
->SetValue(event
.GetChecked());
1231 #endif // wxUSE_RADIOBUTTON
1236 // ----------------------------------------------------------------------------
1237 // dialog units translations
1238 // ----------------------------------------------------------------------------
1240 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1242 int charWidth
= GetCharWidth();
1243 int charHeight
= GetCharHeight();
1245 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1246 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1251 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1253 int charWidth
= GetCharWidth();
1254 int charHeight
= GetCharHeight();
1256 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1257 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1262 // ----------------------------------------------------------------------------
1264 // ----------------------------------------------------------------------------
1266 // propagate the colour change event to the subwindows
1267 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1269 wxWindowList::Node
*node
= GetChildren().GetFirst();
1272 // Only propagate to non-top-level windows
1273 wxWindow
*win
= node
->GetData();
1274 if ( !win
->IsTopLevel() )
1276 wxSysColourChangedEvent event2
;
1277 event
.m_eventObject
= win
;
1278 win
->GetEventHandler()->ProcessEvent(event2
);
1281 node
= node
->GetNext();
1285 // the default action is to populate dialog with data when it's created
1286 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1288 TransferDataToWindow();
1291 // ----------------------------------------------------------------------------
1292 // list classes implementation
1293 // ----------------------------------------------------------------------------
1295 void wxWindowListNode::DeleteData()
1297 delete (wxWindow
*)GetData();