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 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
355 node
= node
->GetNext() )
357 wxWindow
*win
= node
->GetData();
358 if ( win
->IsTopLevel() )
360 // dialogs and frames lie in different top level windows - don't
361 // deal with them here
366 win
->GetPosition(&wx
, &wy
);
367 win
->GetSize(&ww
, &wh
);
368 if ( wx
+ ww
> maxX
)
370 if ( wy
+ wh
> maxY
)
375 SetClientSize(maxX
+ 7, maxY
+ 14);
378 // set the min/max size of the window
380 void wxWindowBase::SetSizeHints(int minW
, int minH
,
382 int WXUNUSED(incW
), int WXUNUSED(incH
))
390 // ----------------------------------------------------------------------------
391 // show/hide/enable/disable the window
392 // ----------------------------------------------------------------------------
394 bool wxWindowBase::Show(bool show
)
396 if ( show
!= m_isShown
)
408 bool wxWindowBase::Enable(bool enable
)
410 if ( enable
!= m_isEnabled
)
412 m_isEnabled
= enable
;
421 // ----------------------------------------------------------------------------
423 // ----------------------------------------------------------------------------
425 bool wxWindowBase::IsTopLevel() const
427 return wxDynamicCast(this, wxFrame
) || wxDynamicCast(this, wxDialog
);
430 // ----------------------------------------------------------------------------
431 // reparenting the window
432 // ----------------------------------------------------------------------------
434 void wxWindowBase::AddChild(wxWindowBase
*child
)
436 wxCHECK_RET( child
, _T("can't add a NULL child") );
438 GetChildren().Append(child
);
439 child
->SetParent(this);
442 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
444 wxCHECK_RET( child
, _T("can't remove a NULL child") );
446 GetChildren().DeleteObject(child
);
447 child
->SetParent((wxWindow
*)NULL
);
450 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
452 wxWindow
*oldParent
= GetParent();
453 if ( newParent
== oldParent
)
459 // unlink this window from the existing parent.
462 oldParent
->RemoveChild(this);
466 wxTopLevelWindows
.DeleteObject(this);
469 // add it to the new one
472 newParent
->AddChild(this);
476 wxTopLevelWindows
.Append(this);
482 // ----------------------------------------------------------------------------
483 // event handler stuff
484 // ----------------------------------------------------------------------------
486 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
488 handler
->SetNextHandler(GetEventHandler());
489 SetEventHandler(handler
);
492 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
494 wxEvtHandler
*handlerA
= GetEventHandler();
497 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
498 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
499 SetEventHandler(handlerB
);
503 handlerA
= (wxEvtHandler
*)NULL
;
510 // ----------------------------------------------------------------------------
512 // ----------------------------------------------------------------------------
514 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
516 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
519 m_backgroundColour
= colour
;
524 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
526 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
529 m_foregroundColour
= colour
;
534 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
536 // don't try to set invalid cursor, always fall back to the default
537 const wxCursor
& cursorOk
= cursor
.Ok() ? cursor
: *wxSTANDARD_CURSOR
;
539 if ( cursorOk
== m_cursor
)
550 bool wxWindowBase::SetFont(const wxFont
& font
)
552 // don't try to set invalid font, always fall back to the default
553 const wxFont
& fontOk
= font
.Ok() ? font
: *wxSWISS_FONT
;
555 if ( fontOk
== m_font
)
567 void wxWindowBase::SetCaret(wxCaret
*caret
)
578 wxASSERT_MSG( m_caret
->GetWindow() == this,
579 _T("caret should be created associated to this window") );
582 #endif // wxUSE_CARET
585 // ----------------------------------------------------------------------------
587 // ----------------------------------------------------------------------------
589 void wxWindowBase::SetValidator(const wxValidator
& validator
)
591 if ( m_windowValidator
)
592 delete m_windowValidator
;
594 m_windowValidator
= (wxValidator
*)validator
.Clone();
596 if ( m_windowValidator
)
597 m_windowValidator
->SetWindow(this) ;
599 #endif // wxUSE_VALIDATORS
601 // ----------------------------------------------------------------------------
602 // update region testing
603 // ----------------------------------------------------------------------------
605 bool wxWindowBase::IsExposed(int x
, int y
) const
607 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
610 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
612 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
615 // ----------------------------------------------------------------------------
616 // find window by id or name
617 // ----------------------------------------------------------------------------
619 wxWindow
*wxWindowBase::FindWindow( long id
)
621 if ( id
== m_windowId
)
622 return (wxWindow
*)this;
624 wxWindowBase
*res
= (wxWindow
*)NULL
;
625 wxWindowList::Node
*node
;
626 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
628 wxWindowBase
*child
= node
->GetData();
629 res
= child
->FindWindow( id
);
632 return (wxWindow
*)res
;
635 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
637 if ( name
== m_windowName
)
638 return (wxWindow
*)this;
640 wxWindowBase
*res
= (wxWindow
*)NULL
;
641 wxWindowList::Node
*node
;
642 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
644 wxWindow
*child
= node
->GetData();
645 res
= child
->FindWindow(name
);
648 return (wxWindow
*)res
;
651 // ----------------------------------------------------------------------------
652 // dialog oriented functions
653 // ----------------------------------------------------------------------------
655 void wxWindowBase::MakeModal(bool modal
)
657 // Disable all other windows
660 wxWindowList::Node
*node
= wxTopLevelWindows
.GetFirst();
663 wxWindow
*win
= node
->GetData();
667 node
= node
->GetNext();
672 bool wxWindowBase::Validate()
675 wxWindowList::Node
*node
;
676 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
678 wxWindowBase
*child
= node
->GetData();
679 wxValidator
*validator
= child
->GetValidator();
680 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
685 #endif // wxUSE_VALIDATORS
690 bool wxWindowBase::TransferDataToWindow()
693 wxWindowList::Node
*node
;
694 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
696 wxWindowBase
*child
= node
->GetData();
697 wxValidator
*validator
= child
->GetValidator();
698 if ( validator
&& !validator
->TransferToWindow() )
700 wxLog
*log
= wxLog::GetActiveTarget();
703 wxLogWarning(_("Could not transfer data to window"));
710 #endif // wxUSE_VALIDATORS
715 bool wxWindowBase::TransferDataFromWindow()
718 wxWindowList::Node
*node
;
719 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
721 wxWindow
*child
= node
->GetData();
722 if ( child
->GetValidator() &&
723 !child
->GetValidator()->TransferFromWindow() )
728 #endif // wxUSE_VALIDATORS
733 void wxWindowBase::InitDialog()
735 wxInitDialogEvent
event(GetId());
736 event
.SetEventObject( this );
737 GetEventHandler()->ProcessEvent(event
);
740 // ----------------------------------------------------------------------------
742 // ----------------------------------------------------------------------------
746 void wxWindowBase::SetToolTip( const wxString
&tip
)
748 // don't create the new tooltip if we already have one
751 m_tooltip
->SetTip( tip
);
755 SetToolTip( new wxToolTip( tip
) );
758 // setting empty tooltip text does not remove the tooltip any more - use
759 // SetToolTip((wxToolTip *)NULL) for this
762 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
770 #endif // wxUSE_TOOLTIPS
772 // ----------------------------------------------------------------------------
773 // constraints and sizers
774 // ----------------------------------------------------------------------------
776 #if wxUSE_CONSTRAINTS
778 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
782 UnsetConstraints(m_constraints
);
783 delete m_constraints
;
785 m_constraints
= constraints
;
788 // Make sure other windows know they're part of a 'meaningful relationship'
789 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
790 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
791 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
792 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
793 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
794 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
795 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
796 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
797 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
798 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
799 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
800 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
801 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
802 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
803 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
804 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
808 // This removes any dangling pointers to this window in other windows'
809 // constraintsInvolvedIn lists.
810 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
814 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
815 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
816 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
817 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
818 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
819 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
820 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
821 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
822 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
823 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
824 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
825 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
826 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
827 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
828 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
829 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
833 // Back-pointer to other windows we're involved with, so if we delete this
834 // window, we must delete any constraints we're involved with.
835 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
837 if ( !m_constraintsInvolvedIn
)
838 m_constraintsInvolvedIn
= new wxWindowList
;
839 if ( !m_constraintsInvolvedIn
->Find(otherWin
) )
840 m_constraintsInvolvedIn
->Append(otherWin
);
843 // REMOVE back-pointer to other windows we're involved with.
844 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
846 if ( m_constraintsInvolvedIn
)
847 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
850 // Reset any constraints that mention this window
851 void wxWindowBase::DeleteRelatedConstraints()
853 if ( m_constraintsInvolvedIn
)
855 wxWindowList::Node
*node
= m_constraintsInvolvedIn
->GetFirst();
858 wxWindow
*win
= node
->GetData();
859 wxLayoutConstraints
*constr
= win
->GetConstraints();
861 // Reset any constraints involving this window
864 constr
->left
.ResetIfWin(this);
865 constr
->top
.ResetIfWin(this);
866 constr
->right
.ResetIfWin(this);
867 constr
->bottom
.ResetIfWin(this);
868 constr
->width
.ResetIfWin(this);
869 constr
->height
.ResetIfWin(this);
870 constr
->centreX
.ResetIfWin(this);
871 constr
->centreY
.ResetIfWin(this);
874 wxWindowList::Node
*next
= node
->GetNext();
879 delete m_constraintsInvolvedIn
;
880 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
884 void wxWindowBase::SetSizer(wxSizer
*sizer
)
886 m_windowSizer
= sizer
;
888 sizer
->SetSizerParent(this);
891 bool wxWindowBase::Layout()
893 if ( GetConstraints() )
896 GetClientSize(&w
, &h
);
897 GetConstraints()->width
.SetValue(w
);
898 GetConstraints()->height
.SetValue(h
);
901 // If top level (one sizer), evaluate the sizer's constraints.
905 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
906 GetSizer()->LayoutPhase1(&noChanges
);
907 GetSizer()->LayoutPhase2(&noChanges
);
908 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
913 // Otherwise, evaluate child constraints
914 ResetConstraints(); // Mark all constraints as unevaluated
915 DoPhase(1); // Just one phase need if no sizers involved
917 SetConstraintSizes(); // Recursively set the real window sizes
923 // Do a phase of evaluating constraints: the default behaviour. wxSizers may
924 // do a similar thing, but also impose their own 'constraints' and order the
925 // evaluation differently.
926 bool wxWindowBase::LayoutPhase1(int *noChanges
)
928 wxLayoutConstraints
*constr
= GetConstraints();
931 return constr
->SatisfyConstraints(this, noChanges
);
937 bool wxWindowBase::LayoutPhase2(int *noChanges
)
947 // Do a phase of evaluating child constraints
948 bool wxWindowBase::DoPhase(int phase
)
950 int noIterations
= 0;
951 int maxIterations
= 500;
954 wxWindowList succeeded
;
955 while ((noChanges
> 0) && (noIterations
< maxIterations
))
959 wxWindowList::Node
*node
= GetChildren().GetFirst();
962 wxWindow
*child
= node
->GetData();
963 if ( !child
->IsTopLevel() )
965 wxLayoutConstraints
*constr
= child
->GetConstraints();
968 if ( !succeeded
.Find(child
) )
970 int tempNoChanges
= 0;
971 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
972 noChanges
+= tempNoChanges
;
975 succeeded
.Append(child
);
980 node
= node
->GetNext();
989 void wxWindowBase::ResetConstraints()
991 wxLayoutConstraints
*constr
= GetConstraints();
994 constr
->left
.SetDone(FALSE
);
995 constr
->top
.SetDone(FALSE
);
996 constr
->right
.SetDone(FALSE
);
997 constr
->bottom
.SetDone(FALSE
);
998 constr
->width
.SetDone(FALSE
);
999 constr
->height
.SetDone(FALSE
);
1000 constr
->centreX
.SetDone(FALSE
);
1001 constr
->centreY
.SetDone(FALSE
);
1003 wxWindowList::Node
*node
= GetChildren().GetFirst();
1006 wxWindow
*win
= node
->GetData();
1007 if ( !win
->IsTopLevel() )
1008 win
->ResetConstraints();
1009 node
= node
->GetNext();
1013 // Need to distinguish between setting the 'fake' size for windows and sizers,
1014 // and setting the real values.
1015 void wxWindowBase::SetConstraintSizes(bool recurse
)
1017 wxLayoutConstraints
*constr
= GetConstraints();
1018 if ( constr
&& constr
->left
.GetDone() && constr
->right
.GetDone( ) &&
1019 constr
->width
.GetDone() && constr
->height
.GetDone())
1021 int x
= constr
->left
.GetValue();
1022 int y
= constr
->top
.GetValue();
1023 int w
= constr
->width
.GetValue();
1024 int h
= constr
->height
.GetValue();
1026 // If we don't want to resize this window, just move it...
1027 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1028 (constr
->height
.GetRelationship() != wxAsIs
))
1030 // Calls Layout() recursively. AAAGH. How can we stop that.
1031 // Simply take Layout() out of non-top level OnSizes.
1032 SizerSetSize(x
, y
, w
, h
);
1041 wxChar
*windowClass
= GetClassInfo()->GetClassName();
1044 if ( GetName() == _T("") )
1045 winName
= _T("unnamed");
1047 winName
= GetName();
1048 wxLogDebug( _T("Constraint(s) not satisfied for window of type %s, name %s:\n"),
1049 (const wxChar
*)windowClass
,
1050 (const wxChar
*)winName
);
1051 if ( !constr
->left
.GetDone()) wxLogDebug( _T(" unsatisfied 'left' constraint.\n") );
1052 if ( !constr
->right
.GetDone()) wxLogDebug( _T(" unsatisfied 'right' constraint.\n") );
1053 if ( !constr
->width
.GetDone()) wxLogDebug( _T(" unsatisfied 'width' constraint.\n") );
1054 if ( !constr
->height
.GetDone()) wxLogDebug( _T(" unsatisfied 'height' constraint.\n") );
1055 wxLogDebug( _T("Please check constraints: try adding AsIs() constraints.\n") );
1060 wxWindowList::Node
*node
= GetChildren().GetFirst();
1063 wxWindow
*win
= node
->GetData();
1064 if ( !win
->IsTopLevel() )
1065 win
->SetConstraintSizes();
1066 node
= node
->GetNext();
1071 // This assumes that all sizers are 'on' the same window, i.e. the parent of
1073 void wxWindowBase::TransformSizerToActual(int *x
, int *y
) const
1075 if ( !m_sizerParent
|| m_sizerParent
->IsTopLevel() )
1079 m_sizerParent
->GetPosition(&xp
, &yp
);
1080 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
1085 void wxWindowBase::SizerSetSize(int x
, int y
, int w
, int h
)
1089 TransformSizerToActual(&xx
, &yy
);
1090 SetSize(xx
, yy
, w
, h
);
1093 void wxWindowBase::SizerMove(int x
, int y
)
1097 TransformSizerToActual(&xx
, &yy
);
1101 // Only set the size/position of the constraint (if any)
1102 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1104 wxLayoutConstraints
*constr
= GetConstraints();
1109 constr
->left
.SetValue(x
);
1110 constr
->left
.SetDone(TRUE
);
1114 constr
->top
.SetValue(y
);
1115 constr
->top
.SetDone(TRUE
);
1119 constr
->width
.SetValue(w
);
1120 constr
->width
.SetDone(TRUE
);
1124 constr
->height
.SetValue(h
);
1125 constr
->height
.SetDone(TRUE
);
1130 void wxWindowBase::MoveConstraint(int x
, int y
)
1132 wxLayoutConstraints
*constr
= GetConstraints();
1137 constr
->left
.SetValue(x
);
1138 constr
->left
.SetDone(TRUE
);
1142 constr
->top
.SetValue(y
);
1143 constr
->top
.SetDone(TRUE
);
1148 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1150 wxLayoutConstraints
*constr
= GetConstraints();
1153 *w
= constr
->width
.GetValue();
1154 *h
= constr
->height
.GetValue();
1160 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1162 wxLayoutConstraints
*constr
= GetConstraints();
1165 *w
= constr
->width
.GetValue();
1166 *h
= constr
->height
.GetValue();
1169 GetClientSize(w
, h
);
1172 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1174 wxLayoutConstraints
*constr
= GetConstraints();
1177 *x
= constr
->left
.GetValue();
1178 *y
= constr
->top
.GetValue();
1184 #endif // wxUSE_CONSTRAINTS
1186 // ----------------------------------------------------------------------------
1187 // do Update UI processing for child controls
1188 // ----------------------------------------------------------------------------
1190 // TODO: should this be implemented for the child window rather
1191 // than the parent? Then you can override it e.g. for wxCheckBox
1192 // to do the Right Thing rather than having to assume a fixed number
1193 // of control classes.
1194 void wxWindowBase::UpdateWindowUI()
1196 wxWindowID id
= GetId();
1199 wxUpdateUIEvent
event(id
);
1200 event
.m_eventObject
= this;
1202 if ( GetEventHandler()->ProcessEvent(event
) )
1204 if ( event
.GetSetEnabled() )
1205 Enable(event
.GetEnabled());
1207 if ( event
.GetSetText() )
1209 wxControl
*control
= wxDynamicCast(this, wxControl
);
1211 control
->SetLabel(event
.GetText());
1215 wxCheckBox
*checkbox
= wxDynamicCast(this, wxCheckBox
);
1218 if ( event
.GetSetChecked() )
1219 checkbox
->SetValue(event
.GetChecked());
1221 #endif // wxUSE_CHECKBOX
1223 #if wxUSE_RADIOBUTTON
1224 wxRadioButton
*radiobtn
= wxDynamicCast(this, wxRadioButton
);
1227 if ( event
.GetSetChecked() )
1228 radiobtn
->SetValue(event
.GetChecked());
1230 #endif // wxUSE_RADIOBUTTON
1235 // ----------------------------------------------------------------------------
1236 // dialog units translations
1237 // ----------------------------------------------------------------------------
1239 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1241 int charWidth
= GetCharWidth();
1242 int charHeight
= GetCharHeight();
1244 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1245 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1250 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1252 int charWidth
= GetCharWidth();
1253 int charHeight
= GetCharHeight();
1255 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1256 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1261 // ----------------------------------------------------------------------------
1263 // ----------------------------------------------------------------------------
1265 // propagate the colour change event to the subwindows
1266 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1268 wxWindowList::Node
*node
= GetChildren().GetFirst();
1271 // Only propagate to non-top-level windows
1272 wxWindow
*win
= node
->GetData();
1273 if ( !win
->IsTopLevel() )
1275 wxSysColourChangedEvent event2
;
1276 event
.m_eventObject
= win
;
1277 win
->GetEventHandler()->ProcessEvent(event2
);
1280 node
= node
->GetNext();
1284 // the default action is to populate dialog with data when it's created
1285 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1287 TransferDataToWindow();
1290 // ----------------------------------------------------------------------------
1291 // list classes implementation
1292 // ----------------------------------------------------------------------------
1294 void wxWindowListNode::DeleteData()
1296 delete (wxWindow
*)GetData();