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
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
60 int wxWindowBase::ms_lastControlId
= -200;
62 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
64 // ----------------------------------------------------------------------------
66 // ----------------------------------------------------------------------------
68 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
69 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
70 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
73 // ============================================================================
74 // implementation of the common functionality of the wxWindow class
75 // ============================================================================
77 // ----------------------------------------------------------------------------
79 // ----------------------------------------------------------------------------
81 // the default initialization
82 void wxWindowBase::InitBase()
84 // no window yet, no parent nor children
85 m_parent
= (wxWindow
*)NULL
;
87 m_children
.DeleteContents( FALSE
); // don't auto delete node data
89 // no constraints on the minimal window size
95 // window is created enabled but it's not visible yet
100 m_clientObject
= (wxClientData
*)NULL
;
103 // the default event handler is just this window
104 m_eventHandler
= this;
107 m_windowValidator
= (wxValidator
*) NULL
;
109 // use the system default colours
110 wxSystemSettings settings
;
112 m_backgroundColour
= settings
.GetSystemColour(wxSYS_COLOUR_BTNFACE
);
113 m_foregroundColour
= *wxBLACK
; // TODO take this from sys settings too?
114 m_font
= *wxSWISS_FONT
; // and this?
119 // an optimization for the event processing: checking this flag is much
120 // faster than using IsKindOf(CLASSINFO(wxWindow))
123 #if wxUSE_CONSTRAINTS
124 // no constraints whatsoever
125 m_constraints
= (wxLayoutConstraints
*) NULL
;
126 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
127 m_windowSizer
= (wxSizer
*) NULL
;
128 m_sizerParent
= (wxWindowBase
*) NULL
;
129 m_autoLayout
= FALSE
;
130 #endif // wxUSE_CONSTRAINTS
132 #if wxUSE_DRAG_AND_DROP
133 m_dropTarget
= (wxDropTarget
*)NULL
;
134 #endif // wxUSE_DRAG_AND_DROP
137 m_tooltip
= (wxToolTip
*)NULL
;
138 #endif // wxUSE_TOOLTIPS
141 // common part of window creation process
142 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
144 const wxPoint
& WXUNUSED(pos
),
145 const wxSize
& WXUNUSED(size
),
147 const wxString
& name
)
149 // m_isWindow is set to TRUE in wxWindowBase::Init() as well as many other
150 // member variables - check that it has been called (will catch the case
151 // when a new ctor is added which doesn't call InitWindow)
152 wxASSERT_MSG( m_isWindow
, _T("Init() must have been called before!") );
154 // generate a new id if the user doesn't care about it
155 m_windowId
= id
== -1 ? NewControlId() : id
;
158 SetWindowStyleFlag(style
);
164 // ----------------------------------------------------------------------------
166 // ----------------------------------------------------------------------------
169 wxWindowBase::~wxWindowBase()
171 // FIXME if these 2 cases result from programming errors in the user code
172 // we should probably assert here instead of silently fixing them
174 // Just in case the window has been Closed, but we're then deleting
175 // immediately: don't leave dangling pointers.
176 wxPendingDelete
.DeleteObject(this);
178 // Just in case we've loaded a top-level window via LoadNativeDialog but
179 // we weren't a dialog class
180 wxTopLevelWindows
.DeleteObject(this);
182 wxASSERT_MSG( GetChildren().GetCount() == 0, _T("children not destroyed") );
184 if ( m_windowValidator
)
185 delete m_windowValidator
;
187 if ( m_clientObject
)
188 delete m_clientObject
;
190 #if wxUSE_CONSTRAINTS
191 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
192 // at deleted windows as they delete themselves.
193 DeleteRelatedConstraints();
197 // This removes any dangling pointers to this window in other windows'
198 // constraintsInvolvedIn lists.
199 UnsetConstraints(m_constraints
);
200 delete m_constraints
;
201 m_constraints
= NULL
;
205 delete m_windowSizer
;
207 // If this is a child of a sizer, remove self from parent
209 m_sizerParent
->RemoveChild(this);
210 #endif // wxUSE_CONSTRAINTS
212 #if wxUSE_DRAG_AND_DROP
215 #endif // wxUSE_DRAG_AND_DROP
220 #endif // wxUSE_TOOLTIPS
223 bool wxWindowBase::Destroy()
230 bool wxWindowBase::Close(bool force
)
232 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
233 event
.SetEventObject(this);
234 #if WXWIN_COMPATIBILITY
235 event
.SetForce(force
);
236 #endif // WXWIN_COMPATIBILITY
237 event
.SetCanVeto(!force
);
239 // return FALSE if window wasn't closed because the application vetoed the
241 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
244 bool wxWindowBase::DestroyChildren()
246 wxWindowList::Node
*node
;
249 // we iterate until the list becomes empty
250 node
= GetChildren().GetFirst();
254 wxWindow
*child
= node
->GetData();
256 wxASSERT_MSG( child
, _T("children list contains empty nodes") );
260 wxASSERT_MSG( !GetChildren().Find(child
),
261 _T("child didn't remove itself using RemoveChild()") );
267 // ----------------------------------------------------------------------------
268 // centre/fit the window
269 // ----------------------------------------------------------------------------
271 // centre the window with respect to its parent in either (or both) directions
272 void wxWindowBase::Centre(int direction
)
274 int widthParent
, heightParent
;
276 wxWindow
*parent
= GetParent();
279 parent
->GetClientSize(&widthParent
, &heightParent
);
283 // centre with respect to the whole screen
284 wxDisplaySize(&widthParent
, &heightParent
);
288 GetSize(&width
, &height
);
293 if ( direction
& wxHORIZONTAL
)
294 new_x
= (widthParent
- width
)/2;
296 if ( direction
& wxVERTICAL
)
297 new_y
= (heightParent
- height
)/2;
302 // fits the window around the children
303 void wxWindowBase::Fit()
308 wxWindowList::Node
*node
= GetChildren().GetFirst();
311 wxWindow
*win
= node
->GetData();
312 if ( win
->IsKindOf(CLASSINFO(wxFrame
)) ||
313 win
->IsKindOf(CLASSINFO(wxDialog
)) )
315 // dialogs and frames line in different top level windows - don't
316 // deal with them here
321 win
->GetPosition(&wx
, &wy
);
322 win
->GetSize(&ww
, &wh
);
323 if ( wx
+ ww
> maxX
)
325 if ( wy
+ wh
> maxY
)
328 node
= node
->GetNext();
332 SetClientSize(maxX
+ 7, maxY
+ 14);
335 // set the min/max size of the window
337 void wxWindowBase::SetSizeHints(int minW
, int minH
,
339 int WXUNUSED(incW
), int WXUNUSED(incH
))
347 // ----------------------------------------------------------------------------
348 // show/hide/enable/disable the window
349 // ----------------------------------------------------------------------------
351 bool wxWindowBase::Show(bool show
)
353 if ( show
!= m_isShown
)
365 bool wxWindowBase::Enable(bool enable
)
367 if ( enable
!= m_isEnabled
)
369 m_isEnabled
= enable
;
379 // ----------------------------------------------------------------------------
380 // reparenting the window
381 // ----------------------------------------------------------------------------
383 void wxWindowBase::AddChild(wxWindowBase
*child
)
385 wxCHECK_RET( child
, _T("can't add a NULL child") );
387 GetChildren().Append(child
);
388 child
->SetParent(this);
391 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
393 wxCHECK_RET( child
, _T("can't remove a NULL child") );
395 GetChildren().DeleteObject(child
);
396 child
->SetParent((wxWindow
*)NULL
);
399 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
401 wxWindow
*oldParent
= GetParent();
402 if ( newParent
== oldParent
)
408 // unlink this window from the existing parent.
411 oldParent
->RemoveChild(this);
415 wxTopLevelWindows
.DeleteObject(this);
418 // add it to the new one
421 newParent
->AddChild(this);
425 wxTopLevelWindows
.Append(this);
431 // ----------------------------------------------------------------------------
432 // event handler stuff
433 // ----------------------------------------------------------------------------
435 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
437 handler
->SetNextHandler(GetEventHandler());
438 SetEventHandler(handler
);
441 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
443 wxEvtHandler
*handlerA
= GetEventHandler();
446 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
447 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
448 SetEventHandler(handlerB
);
452 handlerA
= (wxEvtHandler
*)NULL
;
459 // ----------------------------------------------------------------------------
461 // ----------------------------------------------------------------------------
463 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
465 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
468 m_backgroundColour
= colour
;
473 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
475 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
478 m_foregroundColour
= colour
;
483 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
485 // don't try to set invalid cursor, always fall back to the default
486 const wxCursor
& cursorOk
= cursor
.Ok() ? cursor
: *wxSTANDARD_CURSOR
;
488 if ( cursorOk
== m_cursor
)
499 bool wxWindowBase::SetFont(const wxFont
& font
)
501 // don't try to set invalid font, always fall back to the default
502 const wxFont
& fontOk
= font
.Ok() ? font
: *wxSWISS_FONT
;
504 if ( fontOk
== m_font
)
515 // ----------------------------------------------------------------------------
517 // ----------------------------------------------------------------------------
519 void wxWindowBase::SetValidator(const wxValidator
& validator
)
521 if ( m_windowValidator
)
522 delete m_windowValidator
;
524 m_windowValidator
= (wxValidator
*)validator
.Clone();
526 if ( m_windowValidator
)
527 m_windowValidator
->SetWindow(this) ;
530 // ----------------------------------------------------------------------------
531 // update region testing
532 // ----------------------------------------------------------------------------
534 bool wxWindowBase::IsExposed(int x
, int y
) const
536 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
539 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
541 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
544 // ----------------------------------------------------------------------------
545 // find window by id or name
546 // ----------------------------------------------------------------------------
548 wxWindow
*wxWindowBase::FindWindow( long id
)
550 if ( id
== m_windowId
)
551 return (wxWindow
*)this;
553 wxWindowBase
*res
= (wxWindow
*)NULL
;
554 wxWindowList::Node
*node
;
555 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
557 wxWindowBase
*child
= node
->GetData();
558 res
= child
->FindWindow( id
);
561 return (wxWindow
*)res
;
564 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
566 if ( name
== m_windowName
)
567 return (wxWindow
*)this;
569 wxWindowBase
*res
= (wxWindow
*)NULL
;
570 wxWindowList::Node
*node
;
571 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
573 wxWindow
*child
= node
->GetData();
574 res
= child
->FindWindow(name
);
577 return (wxWindow
*)res
;
580 // ----------------------------------------------------------------------------
581 // dialog oriented functions
582 // ----------------------------------------------------------------------------
584 void wxWindowBase::MakeModal(bool WXUNUSED(modal
))
586 wxFAIL_MSG(_T("TODO"));
589 bool wxWindowBase::Validate()
591 wxWindowList::Node
*node
;
592 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
594 wxWindowBase
*child
= node
->GetData();
595 wxValidator
*validator
= child
->GetValidator();
596 if ( validator
&& validator
->Validate(this) )
605 bool wxWindowBase::TransferDataToWindow()
607 wxWindowList::Node
*node
;
608 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
610 wxWindowBase
*child
= node
->GetData();
611 wxValidator
*validator
= child
->GetValidator();
612 if ( validator
&& !validator
->TransferToWindow() )
614 wxLog
*log
= wxLog::GetActiveTarget();
617 wxLogWarning(_("Could not transfer data to window"));
628 bool wxWindowBase::TransferDataFromWindow()
630 wxWindowList::Node
*node
;
631 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
633 wxWindow
*child
= node
->GetData();
634 if ( child
->GetValidator() &&
635 !child
->GetValidator()->TransferFromWindow() )
644 void wxWindowBase::InitDialog()
646 wxInitDialogEvent
event(GetId());
647 event
.SetEventObject( this );
648 GetEventHandler()->ProcessEvent(event
);
651 // ----------------------------------------------------------------------------
653 // ----------------------------------------------------------------------------
657 void wxWindowBase::SetToolTip( const wxString
&tip
)
659 // don't create the new tooltip if we already have one
662 m_tooltip
->SetTip( tip
);
666 SetToolTip( new wxToolTip( tip
) );
669 // setting empty tooltip text does not remove the tooltip any more - use
670 // SetToolTip((wxToolTip *)NULL) for this
673 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
681 #endif // wxUSE_TOOLTIPS
683 // ----------------------------------------------------------------------------
684 // constraints and sizers
685 // ----------------------------------------------------------------------------
687 #if wxUSE_CONSTRAINTS
689 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
693 UnsetConstraints(m_constraints
);
694 delete m_constraints
;
696 m_constraints
= constraints
;
699 // Make sure other windows know they're part of a 'meaningful relationship'
700 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
701 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
702 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
703 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
704 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
705 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
706 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
707 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
708 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
709 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
710 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
711 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
712 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
713 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
714 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
715 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
719 // This removes any dangling pointers to this window in other windows'
720 // constraintsInvolvedIn lists.
721 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
725 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
726 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
727 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
728 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
729 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
730 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
731 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
732 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
733 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
734 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
735 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
736 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
737 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
738 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
739 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
740 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
744 // Back-pointer to other windows we're involved with, so if we delete this
745 // window, we must delete any constraints we're involved with.
746 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
748 if ( !m_constraintsInvolvedIn
)
749 m_constraintsInvolvedIn
= new wxWindowList
;
750 if ( !m_constraintsInvolvedIn
->Find(otherWin
) )
751 m_constraintsInvolvedIn
->Append(otherWin
);
754 // REMOVE back-pointer to other windows we're involved with.
755 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
757 if ( m_constraintsInvolvedIn
)
758 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
761 // Reset any constraints that mention this window
762 void wxWindowBase::DeleteRelatedConstraints()
764 if ( m_constraintsInvolvedIn
)
766 wxWindowList::Node
*node
= m_constraintsInvolvedIn
->GetFirst();
769 wxWindow
*win
= node
->GetData();
770 wxLayoutConstraints
*constr
= win
->GetConstraints();
772 // Reset any constraints involving this window
775 constr
->left
.ResetIfWin(this);
776 constr
->top
.ResetIfWin(this);
777 constr
->right
.ResetIfWin(this);
778 constr
->bottom
.ResetIfWin(this);
779 constr
->width
.ResetIfWin(this);
780 constr
->height
.ResetIfWin(this);
781 constr
->centreX
.ResetIfWin(this);
782 constr
->centreY
.ResetIfWin(this);
785 wxWindowList::Node
*next
= node
->GetNext();
790 delete m_constraintsInvolvedIn
;
791 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
795 void wxWindowBase::SetSizer(wxSizer
*sizer
)
797 m_windowSizer
= sizer
;
799 sizer
->SetSizerParent(this);
802 bool wxWindowBase::Layout()
804 if ( GetConstraints() )
807 GetClientSize(&w
, &h
);
808 GetConstraints()->width
.SetValue(w
);
809 GetConstraints()->height
.SetValue(h
);
812 // If top level (one sizer), evaluate the sizer's constraints.
816 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
817 GetSizer()->LayoutPhase1(&noChanges
);
818 GetSizer()->LayoutPhase2(&noChanges
);
819 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
824 // Otherwise, evaluate child constraints
825 ResetConstraints(); // Mark all constraints as unevaluated
826 DoPhase(1); // Just one phase need if no sizers involved
828 SetConstraintSizes(); // Recursively set the real window sizes
834 // Do a phase of evaluating constraints: the default behaviour. wxSizers may
835 // do a similar thing, but also impose their own 'constraints' and order the
836 // evaluation differently.
837 bool wxWindowBase::LayoutPhase1(int *noChanges
)
839 wxLayoutConstraints
*constr
= GetConstraints();
842 return constr
->SatisfyConstraints(this, noChanges
);
848 bool wxWindowBase::LayoutPhase2(int *noChanges
)
858 // Do a phase of evaluating child constraints
859 bool wxWindowBase::DoPhase(int phase
)
861 int noIterations
= 0;
862 int maxIterations
= 500;
865 wxWindowList succeeded
;
866 while ((noChanges
> 0) && (noIterations
< maxIterations
))
870 wxWindowList::Node
*node
= GetChildren().GetFirst();
873 wxWindow
*child
= node
->GetData();
874 if ( !child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)) )
876 wxLayoutConstraints
*constr
= child
->GetConstraints();
879 if ( !succeeded
.Find(child
) )
881 int tempNoChanges
= 0;
882 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
883 noChanges
+= tempNoChanges
;
886 succeeded
.Append(child
);
891 node
= node
->GetNext();
900 void wxWindowBase::ResetConstraints()
902 wxLayoutConstraints
*constr
= GetConstraints();
905 constr
->left
.SetDone(FALSE
);
906 constr
->top
.SetDone(FALSE
);
907 constr
->right
.SetDone(FALSE
);
908 constr
->bottom
.SetDone(FALSE
);
909 constr
->width
.SetDone(FALSE
);
910 constr
->height
.SetDone(FALSE
);
911 constr
->centreX
.SetDone(FALSE
);
912 constr
->centreY
.SetDone(FALSE
);
914 wxWindowList::Node
*node
= GetChildren().GetFirst();
917 wxWindow
*win
= node
->GetData();
918 if ( !win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)) )
919 win
->ResetConstraints();
920 node
= node
->GetNext();
924 // Need to distinguish between setting the 'fake' size for windows and sizers,
925 // and setting the real values.
926 void wxWindowBase::SetConstraintSizes(bool recurse
)
928 wxLayoutConstraints
*constr
= GetConstraints();
929 if ( constr
&& constr
->left
.GetDone() && constr
->right
.GetDone( ) &&
930 constr
->width
.GetDone() && constr
->height
.GetDone())
932 int x
= constr
->left
.GetValue();
933 int y
= constr
->top
.GetValue();
934 int w
= constr
->width
.GetValue();
935 int h
= constr
->height
.GetValue();
937 // If we don't want to resize this window, just move it...
938 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
939 (constr
->height
.GetRelationship() != wxAsIs
))
941 // Calls Layout() recursively. AAAGH. How can we stop that.
942 // Simply take Layout() out of non-top level OnSizes.
943 SizerSetSize(x
, y
, w
, h
);
952 wxChar
*windowClass
= GetClassInfo()->GetClassName();
955 if ( GetName() == _T("") )
956 winName
= _T("unnamed");
959 wxLogDebug( _T("Constraint(s) not satisfied for window of type %s, name %s:\n"),
960 (const wxChar
*)windowClass
,
961 (const wxChar
*)winName
);
962 if ( !constr
->left
.GetDone()) wxLogDebug( _T(" unsatisfied 'left' constraint.\n") );
963 if ( !constr
->right
.GetDone()) wxLogDebug( _T(" unsatisfied 'right' constraint.\n") );
964 if ( !constr
->width
.GetDone()) wxLogDebug( _T(" unsatisfied 'width' constraint.\n") );
965 if ( !constr
->height
.GetDone()) wxLogDebug( _T(" unsatisfied 'height' constraint.\n") );
966 wxLogDebug( _T("Please check constraints: try adding AsIs() constraints.\n") );
971 wxWindowList::Node
*node
= GetChildren().GetFirst();
974 wxWindow
*win
= node
->GetData();
975 if ( !win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)) )
976 win
->SetConstraintSizes();
977 node
= node
->GetNext();
982 // This assumes that all sizers are 'on' the same window, i.e. the parent of
984 void wxWindowBase::TransformSizerToActual(int *x
, int *y
) const
986 if ( !m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
) ) ||
987 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
991 m_sizerParent
->GetPosition(&xp
, &yp
);
992 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
997 void wxWindowBase::SizerSetSize(int x
, int y
, int w
, int h
)
1001 TransformSizerToActual(&xx
, &yy
);
1002 SetSize(xx
, yy
, w
, h
);
1005 void wxWindowBase::SizerMove(int x
, int y
)
1009 TransformSizerToActual(&xx
, &yy
);
1013 // Only set the size/position of the constraint (if any)
1014 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1016 wxLayoutConstraints
*constr
= GetConstraints();
1021 constr
->left
.SetValue(x
);
1022 constr
->left
.SetDone(TRUE
);
1026 constr
->top
.SetValue(y
);
1027 constr
->top
.SetDone(TRUE
);
1031 constr
->width
.SetValue(w
);
1032 constr
->width
.SetDone(TRUE
);
1036 constr
->height
.SetValue(h
);
1037 constr
->height
.SetDone(TRUE
);
1042 void wxWindowBase::MoveConstraint(int x
, int y
)
1044 wxLayoutConstraints
*constr
= GetConstraints();
1049 constr
->left
.SetValue(x
);
1050 constr
->left
.SetDone(TRUE
);
1054 constr
->top
.SetValue(y
);
1055 constr
->top
.SetDone(TRUE
);
1060 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1062 wxLayoutConstraints
*constr
= GetConstraints();
1065 *w
= constr
->width
.GetValue();
1066 *h
= constr
->height
.GetValue();
1072 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1074 wxLayoutConstraints
*constr
= GetConstraints();
1077 *w
= constr
->width
.GetValue();
1078 *h
= constr
->height
.GetValue();
1081 GetClientSize(w
, h
);
1084 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1086 wxLayoutConstraints
*constr
= GetConstraints();
1089 *x
= constr
->left
.GetValue();
1090 *y
= constr
->top
.GetValue();
1096 #endif // wxUSE_CONSTRAINTS
1098 // ----------------------------------------------------------------------------
1099 // do Update UI processing for child controls
1100 // ----------------------------------------------------------------------------
1102 // TODO: should this be implemented for the child window rather
1103 // than the parent? Then you can override it e.g. for wxCheckBox
1104 // to do the Right Thing rather than having to assume a fixed number
1105 // of control classes.
1106 void wxWindowBase::UpdateWindowUI()
1108 wxWindowID id
= GetId();
1111 wxUpdateUIEvent
event(id
);
1112 event
.m_eventObject
= this;
1114 if ( GetEventHandler()->ProcessEvent(event
) )
1116 if ( event
.GetSetEnabled() )
1117 Enable(event
.GetEnabled());
1119 if ( event
.GetSetText() && IsKindOf(CLASSINFO(wxControl
)) )
1120 ((wxControl
*)this)->SetLabel(event
.GetText());
1122 if ( IsKindOf(CLASSINFO(wxCheckBox
)) )
1124 if ( event
.GetSetChecked() )
1125 ((wxCheckBox
*)this)->SetValue(event
.GetChecked());
1127 else if ( IsKindOf(CLASSINFO(wxRadioButton
)) )
1129 if ( event
.GetSetChecked() )
1130 ((wxRadioButton
*) this)->SetValue(event
.GetChecked());
1136 // ----------------------------------------------------------------------------
1137 // dialog units translations
1138 // ----------------------------------------------------------------------------
1140 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1142 int charWidth
= GetCharWidth();
1143 int charHeight
= GetCharHeight();
1145 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1146 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1151 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1153 int charWidth
= GetCharWidth();
1154 int charHeight
= GetCharHeight();
1156 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1157 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1162 // ----------------------------------------------------------------------------
1164 // ----------------------------------------------------------------------------
1166 // propagate the colour change event to the subwindows
1167 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1169 wxWindowList::Node
*node
= GetChildren().GetFirst();
1172 // Only propagate to non-top-level windows
1173 wxWindow
*win
= node
->GetData();
1174 if ( !win
->IsTopLevel() )
1176 wxSysColourChangedEvent event2
;
1177 event
.m_eventObject
= win
;
1178 win
->GetEventHandler()->ProcessEvent(event2
);
1181 node
= node
->GetNext();
1185 // the default action is to populate dialog with data when it's created
1186 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1188 TransferDataToWindow();
1191 // ----------------------------------------------------------------------------
1192 // list classes implementation
1193 // ----------------------------------------------------------------------------
1195 void wxWindowListNode::DeleteData()
1197 delete (wxWindow
*)GetData();