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 // fits the window around the children
320 void wxWindowBase::Fit()
325 wxWindowList::Node
*node
= GetChildren().GetFirst();
328 wxWindow
*win
= node
->GetData();
329 if ( win
->IsTopLevel() )
331 // dialogs and frames lie in different top level windows - don't
332 // deal with them here
337 win
->GetPosition(&wx
, &wy
);
338 win
->GetSize(&ww
, &wh
);
339 if ( wx
+ ww
> maxX
)
341 if ( wy
+ wh
> maxY
)
344 node
= node
->GetNext();
348 SetClientSize(maxX
+ 7, maxY
+ 14);
351 // set the min/max size of the window
353 void wxWindowBase::SetSizeHints(int minW
, int minH
,
355 int WXUNUSED(incW
), int WXUNUSED(incH
))
363 // ----------------------------------------------------------------------------
364 // show/hide/enable/disable the window
365 // ----------------------------------------------------------------------------
367 bool wxWindowBase::Show(bool show
)
369 if ( show
!= m_isShown
)
381 bool wxWindowBase::Enable(bool enable
)
383 if ( enable
!= m_isEnabled
)
385 m_isEnabled
= enable
;
394 // ----------------------------------------------------------------------------
396 // ----------------------------------------------------------------------------
398 bool wxWindowBase::IsTopLevel() const
400 return wxDynamicCast(this, wxFrame
) || wxDynamicCast(this, wxDialog
);
403 // ----------------------------------------------------------------------------
404 // reparenting the window
405 // ----------------------------------------------------------------------------
407 void wxWindowBase::AddChild(wxWindowBase
*child
)
409 wxCHECK_RET( child
, _T("can't add a NULL child") );
411 GetChildren().Append(child
);
412 child
->SetParent(this);
415 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
417 wxCHECK_RET( child
, _T("can't remove a NULL child") );
419 GetChildren().DeleteObject(child
);
420 child
->SetParent((wxWindow
*)NULL
);
423 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
425 wxWindow
*oldParent
= GetParent();
426 if ( newParent
== oldParent
)
432 // unlink this window from the existing parent.
435 oldParent
->RemoveChild(this);
439 wxTopLevelWindows
.DeleteObject(this);
442 // add it to the new one
445 newParent
->AddChild(this);
449 wxTopLevelWindows
.Append(this);
455 // ----------------------------------------------------------------------------
456 // event handler stuff
457 // ----------------------------------------------------------------------------
459 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
461 handler
->SetNextHandler(GetEventHandler());
462 SetEventHandler(handler
);
465 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
467 wxEvtHandler
*handlerA
= GetEventHandler();
470 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
471 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
472 SetEventHandler(handlerB
);
476 handlerA
= (wxEvtHandler
*)NULL
;
483 // ----------------------------------------------------------------------------
485 // ----------------------------------------------------------------------------
487 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
489 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
492 m_backgroundColour
= colour
;
497 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
499 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
502 m_foregroundColour
= colour
;
507 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
509 // don't try to set invalid cursor, always fall back to the default
510 const wxCursor
& cursorOk
= cursor
.Ok() ? cursor
: *wxSTANDARD_CURSOR
;
512 if ( cursorOk
== m_cursor
)
523 bool wxWindowBase::SetFont(const wxFont
& font
)
525 // don't try to set invalid font, always fall back to the default
526 const wxFont
& fontOk
= font
.Ok() ? font
: *wxSWISS_FONT
;
528 if ( fontOk
== m_font
)
540 void wxWindowBase::SetCaret(wxCaret
*caret
)
551 wxASSERT_MSG( m_caret
->GetWindow() == this,
552 "caret should be created associated to this window" );
555 #endif // wxUSE_CARET
558 // ----------------------------------------------------------------------------
560 // ----------------------------------------------------------------------------
562 void wxWindowBase::SetValidator(const wxValidator
& validator
)
564 if ( m_windowValidator
)
565 delete m_windowValidator
;
567 m_windowValidator
= (wxValidator
*)validator
.Clone();
569 if ( m_windowValidator
)
570 m_windowValidator
->SetWindow(this) ;
572 #endif // wxUSE_VALIDATORS
574 // ----------------------------------------------------------------------------
575 // update region testing
576 // ----------------------------------------------------------------------------
578 bool wxWindowBase::IsExposed(int x
, int y
) const
580 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
583 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
585 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
588 // ----------------------------------------------------------------------------
589 // find window by id or name
590 // ----------------------------------------------------------------------------
592 wxWindow
*wxWindowBase::FindWindow( long id
)
594 if ( id
== m_windowId
)
595 return (wxWindow
*)this;
597 wxWindowBase
*res
= (wxWindow
*)NULL
;
598 wxWindowList::Node
*node
;
599 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
601 wxWindowBase
*child
= node
->GetData();
602 res
= child
->FindWindow( id
);
605 return (wxWindow
*)res
;
608 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
610 if ( name
== m_windowName
)
611 return (wxWindow
*)this;
613 wxWindowBase
*res
= (wxWindow
*)NULL
;
614 wxWindowList::Node
*node
;
615 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
617 wxWindow
*child
= node
->GetData();
618 res
= child
->FindWindow(name
);
621 return (wxWindow
*)res
;
624 // ----------------------------------------------------------------------------
625 // dialog oriented functions
626 // ----------------------------------------------------------------------------
628 void wxWindowBase::MakeModal(bool modal
)
630 // Disable all other windows
633 wxWindowList::Node
*node
= wxTopLevelWindows
.GetFirst();
636 wxWindow
*win
= node
->GetData();
640 node
= node
->GetNext();
645 bool wxWindowBase::Validate()
648 wxWindowList::Node
*node
;
649 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
651 wxWindowBase
*child
= node
->GetData();
652 wxValidator
*validator
= child
->GetValidator();
653 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
658 #endif // wxUSE_VALIDATORS
663 bool wxWindowBase::TransferDataToWindow()
666 wxWindowList::Node
*node
;
667 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
669 wxWindowBase
*child
= node
->GetData();
670 wxValidator
*validator
= child
->GetValidator();
671 if ( validator
&& !validator
->TransferToWindow() )
673 wxLog
*log
= wxLog::GetActiveTarget();
676 wxLogWarning(_("Could not transfer data to window"));
683 #endif // wxUSE_VALIDATORS
688 bool wxWindowBase::TransferDataFromWindow()
691 wxWindowList::Node
*node
;
692 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
694 wxWindow
*child
= node
->GetData();
695 if ( child
->GetValidator() &&
696 !child
->GetValidator()->TransferFromWindow() )
701 #endif // wxUSE_VALIDATORS
706 void wxWindowBase::InitDialog()
708 wxInitDialogEvent
event(GetId());
709 event
.SetEventObject( this );
710 GetEventHandler()->ProcessEvent(event
);
713 // ----------------------------------------------------------------------------
715 // ----------------------------------------------------------------------------
719 void wxWindowBase::SetToolTip( const wxString
&tip
)
721 // don't create the new tooltip if we already have one
724 m_tooltip
->SetTip( tip
);
728 SetToolTip( new wxToolTip( tip
) );
731 // setting empty tooltip text does not remove the tooltip any more - use
732 // SetToolTip((wxToolTip *)NULL) for this
735 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
743 #endif // wxUSE_TOOLTIPS
745 // ----------------------------------------------------------------------------
746 // constraints and sizers
747 // ----------------------------------------------------------------------------
749 #if wxUSE_CONSTRAINTS
751 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
755 UnsetConstraints(m_constraints
);
756 delete m_constraints
;
758 m_constraints
= constraints
;
761 // Make sure other windows know they're part of a 'meaningful relationship'
762 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
763 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
764 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
765 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
766 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
767 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
768 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
769 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
770 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
771 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
772 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
773 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
774 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
775 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
776 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
777 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
781 // This removes any dangling pointers to this window in other windows'
782 // constraintsInvolvedIn lists.
783 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
787 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
788 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
789 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
790 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
791 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
792 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
793 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
794 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
795 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
796 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
797 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
798 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
799 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
800 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
801 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
802 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
806 // Back-pointer to other windows we're involved with, so if we delete this
807 // window, we must delete any constraints we're involved with.
808 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
810 if ( !m_constraintsInvolvedIn
)
811 m_constraintsInvolvedIn
= new wxWindowList
;
812 if ( !m_constraintsInvolvedIn
->Find(otherWin
) )
813 m_constraintsInvolvedIn
->Append(otherWin
);
816 // REMOVE back-pointer to other windows we're involved with.
817 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
819 if ( m_constraintsInvolvedIn
)
820 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
823 // Reset any constraints that mention this window
824 void wxWindowBase::DeleteRelatedConstraints()
826 if ( m_constraintsInvolvedIn
)
828 wxWindowList::Node
*node
= m_constraintsInvolvedIn
->GetFirst();
831 wxWindow
*win
= node
->GetData();
832 wxLayoutConstraints
*constr
= win
->GetConstraints();
834 // Reset any constraints involving this window
837 constr
->left
.ResetIfWin(this);
838 constr
->top
.ResetIfWin(this);
839 constr
->right
.ResetIfWin(this);
840 constr
->bottom
.ResetIfWin(this);
841 constr
->width
.ResetIfWin(this);
842 constr
->height
.ResetIfWin(this);
843 constr
->centreX
.ResetIfWin(this);
844 constr
->centreY
.ResetIfWin(this);
847 wxWindowList::Node
*next
= node
->GetNext();
852 delete m_constraintsInvolvedIn
;
853 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
857 void wxWindowBase::SetSizer(wxSizer
*sizer
)
859 m_windowSizer
= sizer
;
861 sizer
->SetSizerParent(this);
864 bool wxWindowBase::Layout()
866 if ( GetConstraints() )
869 GetClientSize(&w
, &h
);
870 GetConstraints()->width
.SetValue(w
);
871 GetConstraints()->height
.SetValue(h
);
874 // If top level (one sizer), evaluate the sizer's constraints.
878 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
879 GetSizer()->LayoutPhase1(&noChanges
);
880 GetSizer()->LayoutPhase2(&noChanges
);
881 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
886 // Otherwise, evaluate child constraints
887 ResetConstraints(); // Mark all constraints as unevaluated
888 DoPhase(1); // Just one phase need if no sizers involved
890 SetConstraintSizes(); // Recursively set the real window sizes
896 // Do a phase of evaluating constraints: the default behaviour. wxSizers may
897 // do a similar thing, but also impose their own 'constraints' and order the
898 // evaluation differently.
899 bool wxWindowBase::LayoutPhase1(int *noChanges
)
901 wxLayoutConstraints
*constr
= GetConstraints();
904 return constr
->SatisfyConstraints(this, noChanges
);
910 bool wxWindowBase::LayoutPhase2(int *noChanges
)
920 // Do a phase of evaluating child constraints
921 bool wxWindowBase::DoPhase(int phase
)
923 int noIterations
= 0;
924 int maxIterations
= 500;
927 wxWindowList succeeded
;
928 while ((noChanges
> 0) && (noIterations
< maxIterations
))
932 wxWindowList::Node
*node
= GetChildren().GetFirst();
935 wxWindow
*child
= node
->GetData();
936 if ( !child
->IsTopLevel() )
938 wxLayoutConstraints
*constr
= child
->GetConstraints();
941 if ( !succeeded
.Find(child
) )
943 int tempNoChanges
= 0;
944 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
945 noChanges
+= tempNoChanges
;
948 succeeded
.Append(child
);
953 node
= node
->GetNext();
962 void wxWindowBase::ResetConstraints()
964 wxLayoutConstraints
*constr
= GetConstraints();
967 constr
->left
.SetDone(FALSE
);
968 constr
->top
.SetDone(FALSE
);
969 constr
->right
.SetDone(FALSE
);
970 constr
->bottom
.SetDone(FALSE
);
971 constr
->width
.SetDone(FALSE
);
972 constr
->height
.SetDone(FALSE
);
973 constr
->centreX
.SetDone(FALSE
);
974 constr
->centreY
.SetDone(FALSE
);
976 wxWindowList::Node
*node
= GetChildren().GetFirst();
979 wxWindow
*win
= node
->GetData();
980 if ( !win
->IsTopLevel() )
981 win
->ResetConstraints();
982 node
= node
->GetNext();
986 // Need to distinguish between setting the 'fake' size for windows and sizers,
987 // and setting the real values.
988 void wxWindowBase::SetConstraintSizes(bool recurse
)
990 wxLayoutConstraints
*constr
= GetConstraints();
991 if ( constr
&& constr
->left
.GetDone() && constr
->right
.GetDone( ) &&
992 constr
->width
.GetDone() && constr
->height
.GetDone())
994 int x
= constr
->left
.GetValue();
995 int y
= constr
->top
.GetValue();
996 int w
= constr
->width
.GetValue();
997 int h
= constr
->height
.GetValue();
999 // If we don't want to resize this window, just move it...
1000 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1001 (constr
->height
.GetRelationship() != wxAsIs
))
1003 // Calls Layout() recursively. AAAGH. How can we stop that.
1004 // Simply take Layout() out of non-top level OnSizes.
1005 SizerSetSize(x
, y
, w
, h
);
1014 wxChar
*windowClass
= GetClassInfo()->GetClassName();
1017 if ( GetName() == _T("") )
1018 winName
= _T("unnamed");
1020 winName
= GetName();
1021 wxLogDebug( _T("Constraint(s) not satisfied for window of type %s, name %s:\n"),
1022 (const wxChar
*)windowClass
,
1023 (const wxChar
*)winName
);
1024 if ( !constr
->left
.GetDone()) wxLogDebug( _T(" unsatisfied 'left' constraint.\n") );
1025 if ( !constr
->right
.GetDone()) wxLogDebug( _T(" unsatisfied 'right' constraint.\n") );
1026 if ( !constr
->width
.GetDone()) wxLogDebug( _T(" unsatisfied 'width' constraint.\n") );
1027 if ( !constr
->height
.GetDone()) wxLogDebug( _T(" unsatisfied 'height' constraint.\n") );
1028 wxLogDebug( _T("Please check constraints: try adding AsIs() constraints.\n") );
1033 wxWindowList::Node
*node
= GetChildren().GetFirst();
1036 wxWindow
*win
= node
->GetData();
1037 if ( !win
->IsTopLevel() )
1038 win
->SetConstraintSizes();
1039 node
= node
->GetNext();
1044 // This assumes that all sizers are 'on' the same window, i.e. the parent of
1046 void wxWindowBase::TransformSizerToActual(int *x
, int *y
) const
1048 if ( !m_sizerParent
|| m_sizerParent
->IsTopLevel() )
1052 m_sizerParent
->GetPosition(&xp
, &yp
);
1053 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
1058 void wxWindowBase::SizerSetSize(int x
, int y
, int w
, int h
)
1062 TransformSizerToActual(&xx
, &yy
);
1063 SetSize(xx
, yy
, w
, h
);
1066 void wxWindowBase::SizerMove(int x
, int y
)
1070 TransformSizerToActual(&xx
, &yy
);
1074 // Only set the size/position of the constraint (if any)
1075 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1077 wxLayoutConstraints
*constr
= GetConstraints();
1082 constr
->left
.SetValue(x
);
1083 constr
->left
.SetDone(TRUE
);
1087 constr
->top
.SetValue(y
);
1088 constr
->top
.SetDone(TRUE
);
1092 constr
->width
.SetValue(w
);
1093 constr
->width
.SetDone(TRUE
);
1097 constr
->height
.SetValue(h
);
1098 constr
->height
.SetDone(TRUE
);
1103 void wxWindowBase::MoveConstraint(int x
, int y
)
1105 wxLayoutConstraints
*constr
= GetConstraints();
1110 constr
->left
.SetValue(x
);
1111 constr
->left
.SetDone(TRUE
);
1115 constr
->top
.SetValue(y
);
1116 constr
->top
.SetDone(TRUE
);
1121 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1123 wxLayoutConstraints
*constr
= GetConstraints();
1126 *w
= constr
->width
.GetValue();
1127 *h
= constr
->height
.GetValue();
1133 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1135 wxLayoutConstraints
*constr
= GetConstraints();
1138 *w
= constr
->width
.GetValue();
1139 *h
= constr
->height
.GetValue();
1142 GetClientSize(w
, h
);
1145 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1147 wxLayoutConstraints
*constr
= GetConstraints();
1150 *x
= constr
->left
.GetValue();
1151 *y
= constr
->top
.GetValue();
1157 #endif // wxUSE_CONSTRAINTS
1159 // ----------------------------------------------------------------------------
1160 // do Update UI processing for child controls
1161 // ----------------------------------------------------------------------------
1163 // TODO: should this be implemented for the child window rather
1164 // than the parent? Then you can override it e.g. for wxCheckBox
1165 // to do the Right Thing rather than having to assume a fixed number
1166 // of control classes.
1167 void wxWindowBase::UpdateWindowUI()
1169 wxWindowID id
= GetId();
1172 wxUpdateUIEvent
event(id
);
1173 event
.m_eventObject
= this;
1175 if ( GetEventHandler()->ProcessEvent(event
) )
1177 if ( event
.GetSetEnabled() )
1178 Enable(event
.GetEnabled());
1180 if ( event
.GetSetText() )
1182 wxControl
*control
= wxDynamicCast(this, wxControl
);
1184 control
->SetLabel(event
.GetText());
1188 wxCheckBox
*checkbox
= wxDynamicCast(this, wxCheckBox
);
1191 if ( event
.GetSetChecked() )
1192 checkbox
->SetValue(event
.GetChecked());
1194 #endif // wxUSE_CHECKBOX
1196 #if wxUSE_RADIOBUTTON
1197 wxRadioButton
*radiobtn
= wxDynamicCast(this, wxRadioButton
);
1200 if ( event
.GetSetChecked() )
1201 radiobtn
->SetValue(event
.GetChecked());
1203 #endif // wxUSE_RADIOBUTTON
1208 // ----------------------------------------------------------------------------
1209 // dialog units translations
1210 // ----------------------------------------------------------------------------
1212 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1214 int charWidth
= GetCharWidth();
1215 int charHeight
= GetCharHeight();
1217 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1218 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1223 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1225 int charWidth
= GetCharWidth();
1226 int charHeight
= GetCharHeight();
1228 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1229 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1234 // ----------------------------------------------------------------------------
1236 // ----------------------------------------------------------------------------
1238 // propagate the colour change event to the subwindows
1239 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1241 wxWindowList::Node
*node
= GetChildren().GetFirst();
1244 // Only propagate to non-top-level windows
1245 wxWindow
*win
= node
->GetData();
1246 if ( !win
->IsTopLevel() )
1248 wxSysColourChangedEvent event2
;
1249 event
.m_eventObject
= win
;
1250 win
->GetEventHandler()->ProcessEvent(event2
);
1253 node
= node
->GetNext();
1257 // the default action is to populate dialog with data when it's created
1258 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1260 TransferDataToWindow();
1263 // ----------------------------------------------------------------------------
1264 // list classes implementation
1265 // ----------------------------------------------------------------------------
1267 void wxWindowListNode::DeleteData()
1269 delete (wxWindow
*)GetData();