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
= 0;
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 // No, we keep the -1 from now on. RR.
156 // m_windowId = id == -1 ? NewControlId() : id;
159 SetWindowStyleFlag(style
);
165 // ----------------------------------------------------------------------------
167 // ----------------------------------------------------------------------------
170 wxWindowBase::~wxWindowBase()
172 // FIXME if these 2 cases result from programming errors in the user code
173 // we should probably assert here instead of silently fixing them
175 // Just in case the window has been Closed, but we're then deleting
176 // immediately: don't leave dangling pointers.
177 wxPendingDelete
.DeleteObject(this);
179 // Just in case we've loaded a top-level window via LoadNativeDialog but
180 // we weren't a dialog class
181 wxTopLevelWindows
.DeleteObject(this);
183 wxASSERT_MSG( GetChildren().GetCount() == 0, "children not destroyed" );
185 if ( m_windowValidator
)
186 delete m_windowValidator
;
188 if ( m_clientObject
)
189 delete m_clientObject
;
191 #if wxUSE_CONSTRAINTS
192 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
193 // at deleted windows as they delete themselves.
194 DeleteRelatedConstraints();
198 // This removes any dangling pointers to this window in other windows'
199 // constraintsInvolvedIn lists.
200 UnsetConstraints(m_constraints
);
201 delete m_constraints
;
202 m_constraints
= NULL
;
206 delete m_windowSizer
;
208 // If this is a child of a sizer, remove self from parent
210 m_sizerParent
->RemoveChild(this);
211 #endif // wxUSE_CONSTRAINTS
213 #if wxUSE_DRAG_AND_DROP
216 #endif // wxUSE_DRAG_AND_DROP
221 #endif // wxUSE_TOOLTIPS
224 bool wxWindowBase::Destroy()
231 bool wxWindowBase::Close(bool force
)
233 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
234 event
.SetEventObject(this);
235 #if WXWIN_COMPATIBILITY
236 event
.SetForce(force
);
237 #endif // WXWIN_COMPATIBILITY
238 event
.SetCanVeto(!force
);
240 // return FALSE if window wasn't closed because the application vetoed the
242 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
245 bool wxWindowBase::DestroyChildren()
247 wxWindowList::Node
*node
;
248 while ( (node
= GetChildren().GetFirst()) )
250 wxWindow
*child
= node
->GetData();
252 wxASSERT_MSG( child
, "m_children contains empty nodes" );
256 wxASSERT_MSG( !GetChildren().Find(child
), "child didn't remove itself using RemoveChild()" );
262 // ----------------------------------------------------------------------------
263 // centre/fit the window
264 // ----------------------------------------------------------------------------
266 // centre the window with respect to its parent in either (or both) directions
267 void wxWindowBase::Centre(int direction
)
269 int widthParent
, heightParent
;
271 wxWindow
*parent
= GetParent();
274 parent
->GetClientSize(&widthParent
, &heightParent
);
278 // centre with respect to the whole screen
279 wxDisplaySize(&widthParent
, &heightParent
);
283 GetSize(&width
, &height
);
288 if ( direction
& wxHORIZONTAL
)
289 new_x
= (widthParent
- width
)/2;
291 if ( direction
& wxVERTICAL
)
292 new_y
= (heightParent
- height
)/2;
297 // fits the window around the children
298 void wxWindowBase::Fit()
303 wxWindowList::Node
*node
= GetChildren().GetFirst();
306 wxWindow
*win
= node
->GetData();
308 win
->GetPosition(&wx
, &wy
);
309 win
->GetSize(&ww
, &wh
);
310 if ( wx
+ ww
> maxX
)
312 if ( wy
+ wh
> maxY
)
315 node
= node
->GetNext();
319 SetClientSize(maxX
+ 7, maxY
+ 14);
322 // set the min/max size of the window
324 void wxWindowBase::SetSizeHints(int minW
, int minH
,
326 int WXUNUSED(incW
), int WXUNUSED(incH
))
334 // ----------------------------------------------------------------------------
335 // show/hide/enable/disable the window
336 // ----------------------------------------------------------------------------
338 bool wxWindowBase::Show(bool show
)
340 if ( show
!= m_isShown
)
352 bool wxWindowBase::Enable(bool enable
)
354 if ( enable
!= m_isEnabled
)
356 m_isEnabled
= enable
;
366 // ----------------------------------------------------------------------------
367 // reparenting the window
368 // ----------------------------------------------------------------------------
370 void wxWindowBase::AddChild(wxWindowBase
*child
)
372 wxCHECK_RET( child
, _T("can't add a NULL child") );
374 GetChildren().Append(child
);
375 child
->SetParent(this);
378 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
380 wxCHECK_RET( child
, _T("can't remove a NULL child") );
382 GetChildren().DeleteObject(child
);
383 child
->SetParent((wxWindow
*)NULL
);
386 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
388 wxWindow
*oldParent
= GetParent();
389 if ( newParent
== oldParent
)
395 // unlink this window from the existing parent.
398 oldParent
->RemoveChild(this);
402 wxTopLevelWindows
.DeleteObject(this);
405 // add it to the new one
408 newParent
->AddChild(this);
412 wxTopLevelWindows
.Append(this);
418 // ----------------------------------------------------------------------------
419 // event handler stuff
420 // ----------------------------------------------------------------------------
422 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
424 handler
->SetNextHandler(GetEventHandler());
425 SetEventHandler(handler
);
428 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
430 wxEvtHandler
*handlerA
= GetEventHandler();
433 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
434 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
435 SetEventHandler(handlerB
);
439 handlerA
= (wxEvtHandler
*)NULL
;
446 // ----------------------------------------------------------------------------
448 // ----------------------------------------------------------------------------
450 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
452 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
455 m_backgroundColour
= colour
;
460 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
462 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
465 m_foregroundColour
= colour
;
470 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
472 // don't try to set invalid cursor, always fall back to the default
473 const wxCursor
& cursorOk
= cursor
.Ok() ? cursor
: *wxSTANDARD_CURSOR
;
475 if ( cursorOk
== m_cursor
)
486 bool wxWindowBase::SetFont(const wxFont
& font
)
488 // don't try to set invalid font, always fall back to the default
489 const wxFont
& fontOk
= font
.Ok() ? font
: *wxSWISS_FONT
;
491 if ( fontOk
== m_font
)
502 // ----------------------------------------------------------------------------
504 // ----------------------------------------------------------------------------
506 void wxWindowBase::SetValidator(const wxValidator
& validator
)
508 if ( m_windowValidator
)
509 delete m_windowValidator
;
511 m_windowValidator
= (wxValidator
*)validator
.Clone();
513 if ( m_windowValidator
)
514 m_windowValidator
->SetWindow(this) ;
517 // ----------------------------------------------------------------------------
518 // update region testing
519 // ----------------------------------------------------------------------------
521 bool wxWindowBase::IsExposed(int x
, int y
) const
523 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
526 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
528 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
531 // ----------------------------------------------------------------------------
532 // find window by id or name
533 // ----------------------------------------------------------------------------
535 wxWindow
*wxWindowBase::FindWindow( long id
)
537 if ( id
== m_windowId
)
538 return (wxWindow
*)this;
540 wxWindowBase
*res
= (wxWindow
*)NULL
;
541 wxWindowList::Node
*node
;
542 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
544 wxWindowBase
*child
= node
->GetData();
545 res
= child
->FindWindow( id
);
548 return (wxWindow
*)res
;
551 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
553 if ( name
== m_windowName
)
554 return (wxWindow
*)this;
556 wxWindowBase
*res
= (wxWindow
*)NULL
;
557 wxWindowList::Node
*node
;
558 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
560 wxWindow
*child
= node
->GetData();
561 res
= child
->FindWindow(name
);
564 return (wxWindow
*)res
;
567 // ----------------------------------------------------------------------------
568 // dialog oriented functions
569 // ----------------------------------------------------------------------------
571 void wxWindowBase::MakeModal(bool WXUNUSED(modal
))
576 bool wxWindowBase::Validate()
578 wxWindowList::Node
*node
;
579 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
581 wxWindowBase
*child
= node
->GetData();
582 wxValidator
*validator
= child
->GetValidator();
583 if ( validator
&& validator
->Validate(this) )
592 bool wxWindowBase::TransferDataToWindow()
594 wxWindowList::Node
*node
;
595 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
597 wxWindowBase
*child
= node
->GetData();
598 wxValidator
*validator
= child
->GetValidator();
599 if ( validator
&& !validator
->TransferToWindow() )
601 wxLog
*log
= wxLog::GetActiveTarget();
604 wxLogWarning(_("Could not transfer data to window"));
615 bool wxWindowBase::TransferDataFromWindow()
617 wxWindowList::Node
*node
;
618 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
620 wxWindow
*child
= node
->GetData();
621 if ( child
->GetValidator() &&
622 !child
->GetValidator()->TransferFromWindow() )
631 void wxWindowBase::InitDialog()
633 wxInitDialogEvent
event(GetId());
634 event
.SetEventObject( this );
635 GetEventHandler()->ProcessEvent(event
);
638 // ----------------------------------------------------------------------------
640 // ----------------------------------------------------------------------------
644 void wxWindowBase::SetToolTip( const wxString
&tip
)
646 // don't create the new tooltip if we already have one
649 m_tooltip
->SetTip( tip
);
653 SetToolTip( new wxToolTip( tip
) );
656 // setting empty tooltip text does not remove the tooltip any more - use
657 // SetToolTip((wxToolTip *)NULL) for this
660 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
668 #endif // wxUSE_TOOLTIPS
670 // ----------------------------------------------------------------------------
671 // constraints and sizers
672 // ----------------------------------------------------------------------------
674 #if wxUSE_CONSTRAINTS
676 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
680 UnsetConstraints(m_constraints
);
681 delete m_constraints
;
683 m_constraints
= constraints
;
686 // Make sure other windows know they're part of a 'meaningful relationship'
687 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
688 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
689 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
690 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
691 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
692 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
693 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
694 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
695 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
696 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
697 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
698 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
699 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
700 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
701 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
702 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
706 // This removes any dangling pointers to this window in other windows'
707 // constraintsInvolvedIn lists.
708 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
712 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
713 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
714 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
715 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
716 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
717 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
718 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
719 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
720 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
721 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
722 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
723 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
724 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
725 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
726 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
727 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
731 // Back-pointer to other windows we're involved with, so if we delete this
732 // window, we must delete any constraints we're involved with.
733 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
735 if ( !m_constraintsInvolvedIn
)
736 m_constraintsInvolvedIn
= new wxWindowList
;
737 if ( !m_constraintsInvolvedIn
->Find(otherWin
) )
738 m_constraintsInvolvedIn
->Append(otherWin
);
741 // REMOVE back-pointer to other windows we're involved with.
742 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
744 if ( m_constraintsInvolvedIn
)
745 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
748 // Reset any constraints that mention this window
749 void wxWindowBase::DeleteRelatedConstraints()
751 if ( m_constraintsInvolvedIn
)
753 wxWindowList::Node
*node
= m_constraintsInvolvedIn
->GetFirst();
756 wxWindow
*win
= node
->GetData();
757 wxLayoutConstraints
*constr
= win
->GetConstraints();
759 // Reset any constraints involving this window
762 constr
->left
.ResetIfWin(this);
763 constr
->top
.ResetIfWin(this);
764 constr
->right
.ResetIfWin(this);
765 constr
->bottom
.ResetIfWin(this);
766 constr
->width
.ResetIfWin(this);
767 constr
->height
.ResetIfWin(this);
768 constr
->centreX
.ResetIfWin(this);
769 constr
->centreY
.ResetIfWin(this);
772 wxWindowList::Node
*next
= node
->GetNext();
777 delete m_constraintsInvolvedIn
;
778 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
782 void wxWindowBase::SetSizer(wxSizer
*sizer
)
784 m_windowSizer
= sizer
;
786 sizer
->SetSizerParent(this);
789 bool wxWindowBase::Layout()
791 if ( GetConstraints() )
794 GetClientSize(&w
, &h
);
795 GetConstraints()->width
.SetValue(w
);
796 GetConstraints()->height
.SetValue(h
);
799 // If top level (one sizer), evaluate the sizer's constraints.
803 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
804 GetSizer()->LayoutPhase1(&noChanges
);
805 GetSizer()->LayoutPhase2(&noChanges
);
806 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
811 // Otherwise, evaluate child constraints
812 ResetConstraints(); // Mark all constraints as unevaluated
813 DoPhase(1); // Just one phase need if no sizers involved
815 SetConstraintSizes(); // Recursively set the real window sizes
821 // Do a phase of evaluating constraints: the default behaviour. wxSizers may
822 // do a similar thing, but also impose their own 'constraints' and order the
823 // evaluation differently.
824 bool wxWindowBase::LayoutPhase1(int *noChanges
)
826 wxLayoutConstraints
*constr
= GetConstraints();
829 return constr
->SatisfyConstraints(this, noChanges
);
835 bool wxWindowBase::LayoutPhase2(int *noChanges
)
845 // Do a phase of evaluating child constraints
846 bool wxWindowBase::DoPhase(int phase
)
848 int noIterations
= 0;
849 int maxIterations
= 500;
852 wxWindowList succeeded
;
853 while ((noChanges
> 0) && (noIterations
< maxIterations
))
857 wxWindowList::Node
*node
= GetChildren().GetFirst();
860 wxWindow
*child
= node
->GetData();
861 if ( !child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)) )
863 wxLayoutConstraints
*constr
= child
->GetConstraints();
866 if ( !succeeded
.Find(child
) )
868 int tempNoChanges
= 0;
869 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
870 noChanges
+= tempNoChanges
;
873 succeeded
.Append(child
);
878 node
= node
->GetNext();
887 void wxWindowBase::ResetConstraints()
889 wxLayoutConstraints
*constr
= GetConstraints();
892 constr
->left
.SetDone(FALSE
);
893 constr
->top
.SetDone(FALSE
);
894 constr
->right
.SetDone(FALSE
);
895 constr
->bottom
.SetDone(FALSE
);
896 constr
->width
.SetDone(FALSE
);
897 constr
->height
.SetDone(FALSE
);
898 constr
->centreX
.SetDone(FALSE
);
899 constr
->centreY
.SetDone(FALSE
);
901 wxWindowList::Node
*node
= GetChildren().GetFirst();
904 wxWindow
*win
= node
->GetData();
905 if ( !win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)) )
906 win
->ResetConstraints();
907 node
= node
->GetNext();
911 // Need to distinguish between setting the 'fake' size for windows and sizers,
912 // and setting the real values.
913 void wxWindowBase::SetConstraintSizes(bool recurse
)
915 wxLayoutConstraints
*constr
= GetConstraints();
916 if ( constr
&& constr
->left
.GetDone() && constr
->right
.GetDone( ) &&
917 constr
->width
.GetDone() && constr
->height
.GetDone())
919 int x
= constr
->left
.GetValue();
920 int y
= constr
->top
.GetValue();
921 int w
= constr
->width
.GetValue();
922 int h
= constr
->height
.GetValue();
924 // If we don't want to resize this window, just move it...
925 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
926 (constr
->height
.GetRelationship() != wxAsIs
))
928 // Calls Layout() recursively. AAAGH. How can we stop that.
929 // Simply take Layout() out of non-top level OnSizes.
930 SizerSetSize(x
, y
, w
, h
);
939 wxChar
*windowClass
= GetClassInfo()->GetClassName();
942 if ( GetName() == _T("") )
943 winName
= _T("unnamed");
946 wxLogDebug( _T("Constraint(s) not satisfied for window of type %s, name %s:\n"),
947 (const wxChar
*)windowClass
,
948 (const wxChar
*)winName
);
949 if ( !constr
->left
.GetDone()) wxLogDebug( _T(" unsatisfied 'left' constraint.\n") );
950 if ( !constr
->right
.GetDone()) wxLogDebug( _T(" unsatisfied 'right' constraint.\n") );
951 if ( !constr
->width
.GetDone()) wxLogDebug( _T(" unsatisfied 'width' constraint.\n") );
952 if ( !constr
->height
.GetDone()) wxLogDebug( _T(" unsatisfied 'height' constraint.\n") );
953 wxLogDebug( _T("Please check constraints: try adding AsIs() constraints.\n") );
958 wxWindowList::Node
*node
= GetChildren().GetFirst();
961 wxWindow
*win
= node
->GetData();
962 if ( !win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)) )
963 win
->SetConstraintSizes();
964 node
= node
->GetNext();
969 // This assumes that all sizers are 'on' the same window, i.e. the parent of
971 void wxWindowBase::TransformSizerToActual(int *x
, int *y
) const
973 if ( !m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
) ) ||
974 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
978 m_sizerParent
->GetPosition(&xp
, &yp
);
979 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
984 void wxWindowBase::SizerSetSize(int x
, int y
, int w
, int h
)
988 TransformSizerToActual(&xx
, &yy
);
989 SetSize(xx
, yy
, w
, h
);
992 void wxWindowBase::SizerMove(int x
, int y
)
996 TransformSizerToActual(&xx
, &yy
);
1000 // Only set the size/position of the constraint (if any)
1001 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1003 wxLayoutConstraints
*constr
= GetConstraints();
1008 constr
->left
.SetValue(x
);
1009 constr
->left
.SetDone(TRUE
);
1013 constr
->top
.SetValue(y
);
1014 constr
->top
.SetDone(TRUE
);
1018 constr
->width
.SetValue(w
);
1019 constr
->width
.SetDone(TRUE
);
1023 constr
->height
.SetValue(h
);
1024 constr
->height
.SetDone(TRUE
);
1029 void wxWindowBase::MoveConstraint(int x
, int y
)
1031 wxLayoutConstraints
*constr
= GetConstraints();
1036 constr
->left
.SetValue(x
);
1037 constr
->left
.SetDone(TRUE
);
1041 constr
->top
.SetValue(y
);
1042 constr
->top
.SetDone(TRUE
);
1047 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1049 wxLayoutConstraints
*constr
= GetConstraints();
1052 *w
= constr
->width
.GetValue();
1053 *h
= constr
->height
.GetValue();
1059 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1061 wxLayoutConstraints
*constr
= GetConstraints();
1064 *w
= constr
->width
.GetValue();
1065 *h
= constr
->height
.GetValue();
1068 GetClientSize(w
, h
);
1071 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1073 wxLayoutConstraints
*constr
= GetConstraints();
1076 *x
= constr
->left
.GetValue();
1077 *y
= constr
->top
.GetValue();
1083 #endif // wxUSE_CONSTRAINTS
1085 // ----------------------------------------------------------------------------
1086 // do Update UI processing for child controls
1087 // ----------------------------------------------------------------------------
1089 // TODO: should this be implemented for the child window rather
1090 // than the parent? Then you can override it e.g. for wxCheckBox
1091 // to do the Right Thing rather than having to assume a fixed number
1092 // of control classes.
1093 void wxWindowBase::UpdateWindowUI()
1095 wxWindowID id
= GetId();
1098 wxUpdateUIEvent
event(id
);
1099 event
.m_eventObject
= this;
1101 if ( GetEventHandler()->ProcessEvent(event
) )
1103 if ( event
.GetSetEnabled() )
1104 Enable(event
.GetEnabled());
1106 if ( event
.GetSetText() && IsKindOf(CLASSINFO(wxControl
)) )
1107 ((wxControl
*)this)->SetLabel(event
.GetText());
1109 if ( IsKindOf(CLASSINFO(wxCheckBox
)) )
1111 if ( event
.GetSetChecked() )
1112 ((wxCheckBox
*)this)->SetValue(event
.GetChecked());
1114 // TODO No radio buttons in wxGTK yet
1116 else if ( IsKindOf(CLASSINFO(wxRadioButton
)) )
1118 if ( event
.GetSetChecked() )
1119 ((wxRadioButton
*) this)->SetValue(event
.GetChecked());
1126 // ----------------------------------------------------------------------------
1127 // dialog units translations
1128 // ----------------------------------------------------------------------------
1130 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1132 int charWidth
= GetCharWidth();
1133 int charHeight
= GetCharHeight();
1135 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1136 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1141 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1143 int charWidth
= GetCharWidth();
1144 int charHeight
= GetCharHeight();
1146 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1147 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1152 // ----------------------------------------------------------------------------
1154 // ----------------------------------------------------------------------------
1156 // propagate the colour change event to the subwindows
1157 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1159 wxWindowList::Node
*node
= GetChildren().GetFirst();
1162 // Only propagate to non-top-level windows
1163 wxWindow
*win
= node
->GetData();
1164 if ( !win
->IsTopLevel() )
1166 wxSysColourChangedEvent event2
;
1167 event
.m_eventObject
= win
;
1168 win
->GetEventHandler()->ProcessEvent(event2
);
1171 node
= node
->GetNext();
1175 // the default action is to populate dialog with data when it's created
1176 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1178 TransferDataToWindow();
1181 // ----------------------------------------------------------------------------
1182 // list classes implementation
1183 // ----------------------------------------------------------------------------
1185 void wxWindowListNode::DeleteData()
1187 delete (wxWindow
*)GetData();