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
103 // no client data (yet)
105 m_clientDataType
= ClientData_None
;
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 wxValidator
& validator
,
158 const wxString
& name
)
160 // m_isWindow is set to TRUE in wxWindowBase::Init() as well as many other
161 // member variables - check that it has been called (will catch the case
162 // when a new ctor is added which doesn't call InitWindow)
163 wxASSERT_MSG( m_isWindow
, _T("Init() must have been called before!") );
165 // generate a new id if the user doesn't care about it
166 m_windowId
= id
== -1 ? NewControlId() : id
;
169 SetWindowStyleFlag(style
);
171 SetValidator(validator
);
176 // ----------------------------------------------------------------------------
178 // ----------------------------------------------------------------------------
181 wxWindowBase::~wxWindowBase()
183 // FIXME if these 2 cases result from programming errors in the user code
184 // we should probably assert here instead of silently fixing them
186 // Just in case the window has been Closed, but we're then deleting
187 // immediately: don't leave dangling pointers.
188 wxPendingDelete
.DeleteObject(this);
190 // Just in case we've loaded a top-level window via LoadNativeDialog but
191 // we weren't a dialog class
192 wxTopLevelWindows
.DeleteObject(this);
194 wxASSERT_MSG( GetChildren().GetCount() == 0, _T("children not destroyed") );
196 // make sure that there are no dangling pointers left pointing to us
197 wxPanel
*panel
= wxDynamicCast(GetParent(), wxPanel
);
200 if ( panel
->GetLastFocus() == this )
202 panel
->SetLastFocus((wxWindow
*)NULL
);
209 #endif // wxUSE_CARET
212 if ( m_windowValidator
)
213 delete m_windowValidator
;
214 #endif // wxUSE_VALIDATORS
216 // we only delete object data, not untyped
217 if ( m_clientDataType
== ClientData_Object
)
218 delete m_clientObject
;
220 #if wxUSE_CONSTRAINTS
221 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
222 // at deleted windows as they delete themselves.
223 DeleteRelatedConstraints();
227 // This removes any dangling pointers to this window in other windows'
228 // constraintsInvolvedIn lists.
229 UnsetConstraints(m_constraints
);
230 delete m_constraints
;
231 m_constraints
= NULL
;
235 delete m_windowSizer
;
237 // If this is a child of a sizer, remove self from parent
239 m_sizerParent
->RemoveChild(this);
240 #endif // wxUSE_CONSTRAINTS
242 #if wxUSE_DRAG_AND_DROP
245 #endif // wxUSE_DRAG_AND_DROP
250 #endif // wxUSE_TOOLTIPS
253 bool wxWindowBase::Destroy()
260 bool wxWindowBase::Close(bool force
)
262 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
263 event
.SetEventObject(this);
264 #if WXWIN_COMPATIBILITY
265 event
.SetForce(force
);
266 #endif // WXWIN_COMPATIBILITY
267 event
.SetCanVeto(!force
);
269 // return FALSE if window wasn't closed because the application vetoed the
271 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
274 bool wxWindowBase::DestroyChildren()
276 wxWindowList::Node
*node
;
279 // we iterate until the list becomes empty
280 node
= GetChildren().GetFirst();
284 wxWindow
*child
= node
->GetData();
286 wxASSERT_MSG( child
, _T("children list contains empty nodes") );
290 wxASSERT_MSG( !GetChildren().Find(child
),
291 _T("child didn't remove itself using RemoveChild()") );
297 // ----------------------------------------------------------------------------
298 // centre/fit the window
299 // ----------------------------------------------------------------------------
301 // centre the window with respect to its parent in either (or both) directions
302 void wxWindowBase::Centre(int direction
)
304 int widthParent
, heightParent
;
306 wxWindow
*parent
= GetParent();
310 direction
|= wxCENTRE_ON_SCREEN
;
313 if ( direction
& wxCENTRE_ON_SCREEN
)
315 // centre with respect to the whole screen
316 wxDisplaySize(&widthParent
, &heightParent
);
320 // centre inside the parents rectangle
321 parent
->GetClientSize(&widthParent
, &heightParent
);
325 GetSize(&width
, &height
);
330 if ( direction
& wxHORIZONTAL
)
331 xNew
= (widthParent
- width
)/2;
333 if ( direction
& wxVERTICAL
)
334 yNew
= (heightParent
- height
)/2;
336 // controls are always centered on their parent because it doesn't make
337 // sense to centre them on the screen
338 if ( !(direction
& wxCENTRE_ON_SCREEN
) || wxDynamicCast(this, wxControl
) )
340 // theo nly chance to get this is to have a wxControl without parent
341 wxCHECK_RET( parent
, _T("a control must have a parent") );
343 // adjust to the parents client area origin
344 wxPoint posParent
= parent
->ClientToScreen(wxPoint(0, 0));
353 // fits the window around the children
354 void wxWindowBase::Fit()
359 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
361 node
= node
->GetNext() )
363 wxWindow
*win
= node
->GetData();
364 if ( win
->IsTopLevel() )
366 // dialogs and frames lie in different top level windows - don't
367 // deal with them here
372 win
->GetPosition(&wx
, &wy
);
373 win
->GetSize(&ww
, &wh
);
374 if ( wx
+ ww
> maxX
)
376 if ( wy
+ wh
> maxY
)
381 SetClientSize(maxX
+ 7, maxY
+ 14);
384 // set the min/max size of the window
386 void wxWindowBase::SetSizeHints(int minW
, int minH
,
388 int WXUNUSED(incW
), int WXUNUSED(incH
))
396 // ----------------------------------------------------------------------------
397 // show/hide/enable/disable the window
398 // ----------------------------------------------------------------------------
400 bool wxWindowBase::Show(bool show
)
402 if ( show
!= m_isShown
)
414 bool wxWindowBase::Enable(bool enable
)
416 if ( enable
!= m_isEnabled
)
418 m_isEnabled
= enable
;
427 // ----------------------------------------------------------------------------
429 // ----------------------------------------------------------------------------
431 bool wxWindowBase::IsTopLevel() const
433 return wxDynamicCast(this, wxFrame
) || wxDynamicCast(this, wxDialog
);
436 // ----------------------------------------------------------------------------
437 // reparenting the window
438 // ----------------------------------------------------------------------------
440 void wxWindowBase::AddChild(wxWindowBase
*child
)
442 wxCHECK_RET( child
, _T("can't add a NULL child") );
444 GetChildren().Append(child
);
445 child
->SetParent(this);
448 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
450 wxCHECK_RET( child
, _T("can't remove a NULL child") );
452 GetChildren().DeleteObject(child
);
453 child
->SetParent((wxWindow
*)NULL
);
456 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
458 wxWindow
*oldParent
= GetParent();
459 if ( newParent
== oldParent
)
465 // unlink this window from the existing parent.
468 oldParent
->RemoveChild(this);
472 wxTopLevelWindows
.DeleteObject(this);
475 // add it to the new one
478 newParent
->AddChild(this);
482 wxTopLevelWindows
.Append(this);
488 // ----------------------------------------------------------------------------
489 // event handler stuff
490 // ----------------------------------------------------------------------------
492 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
494 handler
->SetNextHandler(GetEventHandler());
495 SetEventHandler(handler
);
498 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
500 wxEvtHandler
*handlerA
= GetEventHandler();
503 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
504 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
505 SetEventHandler(handlerB
);
509 handlerA
= (wxEvtHandler
*)NULL
;
516 // ----------------------------------------------------------------------------
518 // ----------------------------------------------------------------------------
520 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
522 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
525 m_backgroundColour
= colour
;
530 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
532 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
535 m_foregroundColour
= colour
;
540 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
542 // don't try to set invalid cursor, always fall back to the default
543 const wxCursor
& cursorOk
= cursor
.Ok() ? cursor
: *wxSTANDARD_CURSOR
;
545 if ( (wxCursor
&)cursorOk
== m_cursor
)
556 bool wxWindowBase::SetFont(const wxFont
& font
)
558 // don't try to set invalid font, always fall back to the default
559 const wxFont
& fontOk
= font
.Ok() ? font
: *wxSWISS_FONT
;
561 if ( (wxFont
&)fontOk
== m_font
)
573 void wxWindowBase::SetCaret(wxCaret
*caret
)
584 wxASSERT_MSG( m_caret
->GetWindow() == this,
585 _T("caret should be created associated to this window") );
588 #endif // wxUSE_CARET
591 // ----------------------------------------------------------------------------
593 // ----------------------------------------------------------------------------
595 void wxWindowBase::SetValidator(const wxValidator
& validator
)
597 if ( m_windowValidator
)
598 delete m_windowValidator
;
600 m_windowValidator
= (wxValidator
*)validator
.Clone();
602 if ( m_windowValidator
)
603 m_windowValidator
->SetWindow(this) ;
605 #endif // wxUSE_VALIDATORS
607 // ----------------------------------------------------------------------------
608 // update region testing
609 // ----------------------------------------------------------------------------
611 bool wxWindowBase::IsExposed(int x
, int y
) const
613 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
616 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
618 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
621 // ----------------------------------------------------------------------------
622 // find window by id or name
623 // ----------------------------------------------------------------------------
625 wxWindow
*wxWindowBase::FindWindow( long id
)
627 if ( id
== m_windowId
)
628 return (wxWindow
*)this;
630 wxWindowBase
*res
= (wxWindow
*)NULL
;
631 wxWindowList::Node
*node
;
632 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
634 wxWindowBase
*child
= node
->GetData();
635 res
= child
->FindWindow( id
);
638 return (wxWindow
*)res
;
641 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
643 if ( name
== m_windowName
)
644 return (wxWindow
*)this;
646 wxWindowBase
*res
= (wxWindow
*)NULL
;
647 wxWindowList::Node
*node
;
648 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
650 wxWindow
*child
= node
->GetData();
651 res
= child
->FindWindow(name
);
654 return (wxWindow
*)res
;
657 // ----------------------------------------------------------------------------
658 // dialog oriented functions
659 // ----------------------------------------------------------------------------
661 void wxWindowBase::MakeModal(bool modal
)
663 // Disable all other windows
666 wxWindowList::Node
*node
= wxTopLevelWindows
.GetFirst();
669 wxWindow
*win
= node
->GetData();
673 node
= node
->GetNext();
678 bool wxWindowBase::Validate()
681 wxWindowList::Node
*node
;
682 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
684 wxWindowBase
*child
= node
->GetData();
685 wxValidator
*validator
= child
->GetValidator();
686 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
691 #endif // wxUSE_VALIDATORS
696 bool wxWindowBase::TransferDataToWindow()
699 wxWindowList::Node
*node
;
700 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
702 wxWindowBase
*child
= node
->GetData();
703 wxValidator
*validator
= child
->GetValidator();
704 if ( validator
&& !validator
->TransferToWindow() )
706 wxLog
*log
= wxLog::GetActiveTarget();
709 wxLogWarning(_("Could not transfer data to window"));
716 #endif // wxUSE_VALIDATORS
721 bool wxWindowBase::TransferDataFromWindow()
724 wxWindowList::Node
*node
;
725 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
727 wxWindow
*child
= node
->GetData();
728 if ( child
->GetValidator() &&
729 !child
->GetValidator()->TransferFromWindow() )
734 #endif // wxUSE_VALIDATORS
739 void wxWindowBase::InitDialog()
741 wxInitDialogEvent
event(GetId());
742 event
.SetEventObject( this );
743 GetEventHandler()->ProcessEvent(event
);
746 // ----------------------------------------------------------------------------
748 // ----------------------------------------------------------------------------
752 void wxWindowBase::SetToolTip( const wxString
&tip
)
754 // don't create the new tooltip if we already have one
757 m_tooltip
->SetTip( tip
);
761 SetToolTip( new wxToolTip( tip
) );
764 // setting empty tooltip text does not remove the tooltip any more - use
765 // SetToolTip((wxToolTip *)NULL) for this
768 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
776 #endif // wxUSE_TOOLTIPS
778 // ----------------------------------------------------------------------------
779 // constraints and sizers
780 // ----------------------------------------------------------------------------
782 #if wxUSE_CONSTRAINTS
784 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
788 UnsetConstraints(m_constraints
);
789 delete m_constraints
;
791 m_constraints
= constraints
;
794 // Make sure other windows know they're part of a 'meaningful relationship'
795 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
796 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
797 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
798 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
799 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
800 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
801 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
802 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
803 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
804 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
805 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
806 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
807 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
808 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
809 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
810 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
814 // This removes any dangling pointers to this window in other windows'
815 // constraintsInvolvedIn lists.
816 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
820 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
821 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
822 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
823 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
824 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
825 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
826 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
827 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
828 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
829 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
830 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
831 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
832 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
833 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
834 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
835 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
839 // Back-pointer to other windows we're involved with, so if we delete this
840 // window, we must delete any constraints we're involved with.
841 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
843 if ( !m_constraintsInvolvedIn
)
844 m_constraintsInvolvedIn
= new wxWindowList
;
845 if ( !m_constraintsInvolvedIn
->Find(otherWin
) )
846 m_constraintsInvolvedIn
->Append(otherWin
);
849 // REMOVE back-pointer to other windows we're involved with.
850 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
852 if ( m_constraintsInvolvedIn
)
853 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
856 // Reset any constraints that mention this window
857 void wxWindowBase::DeleteRelatedConstraints()
859 if ( m_constraintsInvolvedIn
)
861 wxWindowList::Node
*node
= m_constraintsInvolvedIn
->GetFirst();
864 wxWindow
*win
= node
->GetData();
865 wxLayoutConstraints
*constr
= win
->GetConstraints();
867 // Reset any constraints involving this window
870 constr
->left
.ResetIfWin(this);
871 constr
->top
.ResetIfWin(this);
872 constr
->right
.ResetIfWin(this);
873 constr
->bottom
.ResetIfWin(this);
874 constr
->width
.ResetIfWin(this);
875 constr
->height
.ResetIfWin(this);
876 constr
->centreX
.ResetIfWin(this);
877 constr
->centreY
.ResetIfWin(this);
880 wxWindowList::Node
*next
= node
->GetNext();
885 delete m_constraintsInvolvedIn
;
886 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
890 void wxWindowBase::SetSizer(wxSizer
*sizer
)
892 m_windowSizer
= sizer
;
894 sizer
->SetSizerParent(this);
897 bool wxWindowBase::Layout()
899 if ( GetConstraints() )
902 GetClientSize(&w
, &h
);
903 GetConstraints()->width
.SetValue(w
);
904 GetConstraints()->height
.SetValue(h
);
907 // If top level (one sizer), evaluate the sizer's constraints.
911 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
912 GetSizer()->LayoutPhase1(&noChanges
);
913 GetSizer()->LayoutPhase2(&noChanges
);
914 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
919 // Otherwise, evaluate child constraints
920 ResetConstraints(); // Mark all constraints as unevaluated
921 DoPhase(1); // Just one phase need if no sizers involved
923 SetConstraintSizes(); // Recursively set the real window sizes
929 // Do a phase of evaluating constraints: the default behaviour. wxSizers may
930 // do a similar thing, but also impose their own 'constraints' and order the
931 // evaluation differently.
932 bool wxWindowBase::LayoutPhase1(int *noChanges
)
934 wxLayoutConstraints
*constr
= GetConstraints();
937 return constr
->SatisfyConstraints(this, noChanges
);
943 bool wxWindowBase::LayoutPhase2(int *noChanges
)
953 // Do a phase of evaluating child constraints
954 bool wxWindowBase::DoPhase(int phase
)
956 int noIterations
= 0;
957 int maxIterations
= 500;
960 wxWindowList succeeded
;
961 while ((noChanges
> 0) && (noIterations
< maxIterations
))
965 wxWindowList::Node
*node
= GetChildren().GetFirst();
968 wxWindow
*child
= node
->GetData();
969 if ( !child
->IsTopLevel() )
971 wxLayoutConstraints
*constr
= child
->GetConstraints();
974 if ( !succeeded
.Find(child
) )
976 int tempNoChanges
= 0;
977 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
978 noChanges
+= tempNoChanges
;
981 succeeded
.Append(child
);
986 node
= node
->GetNext();
995 void wxWindowBase::ResetConstraints()
997 wxLayoutConstraints
*constr
= GetConstraints();
1000 constr
->left
.SetDone(FALSE
);
1001 constr
->top
.SetDone(FALSE
);
1002 constr
->right
.SetDone(FALSE
);
1003 constr
->bottom
.SetDone(FALSE
);
1004 constr
->width
.SetDone(FALSE
);
1005 constr
->height
.SetDone(FALSE
);
1006 constr
->centreX
.SetDone(FALSE
);
1007 constr
->centreY
.SetDone(FALSE
);
1009 wxWindowList::Node
*node
= GetChildren().GetFirst();
1012 wxWindow
*win
= node
->GetData();
1013 if ( !win
->IsTopLevel() )
1014 win
->ResetConstraints();
1015 node
= node
->GetNext();
1019 // Need to distinguish between setting the 'fake' size for windows and sizers,
1020 // and setting the real values.
1021 void wxWindowBase::SetConstraintSizes(bool recurse
)
1023 wxLayoutConstraints
*constr
= GetConstraints();
1024 if ( constr
&& constr
->left
.GetDone() && constr
->right
.GetDone( ) &&
1025 constr
->width
.GetDone() && constr
->height
.GetDone())
1027 int x
= constr
->left
.GetValue();
1028 int y
= constr
->top
.GetValue();
1029 int w
= constr
->width
.GetValue();
1030 int h
= constr
->height
.GetValue();
1032 // If we don't want to resize this window, just move it...
1033 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1034 (constr
->height
.GetRelationship() != wxAsIs
))
1036 // Calls Layout() recursively. AAAGH. How can we stop that.
1037 // Simply take Layout() out of non-top level OnSizes.
1038 SizerSetSize(x
, y
, w
, h
);
1047 wxChar
*windowClass
= GetClassInfo()->GetClassName();
1050 if ( GetName() == _T("") )
1051 winName
= _T("unnamed");
1053 winName
= GetName();
1054 wxLogDebug( _T("Constraint(s) not satisfied for window of type %s, name %s:\n"),
1055 (const wxChar
*)windowClass
,
1056 (const wxChar
*)winName
);
1057 if ( !constr
->left
.GetDone()) wxLogDebug( _T(" unsatisfied 'left' constraint.\n") );
1058 if ( !constr
->right
.GetDone()) wxLogDebug( _T(" unsatisfied 'right' constraint.\n") );
1059 if ( !constr
->width
.GetDone()) wxLogDebug( _T(" unsatisfied 'width' constraint.\n") );
1060 if ( !constr
->height
.GetDone()) wxLogDebug( _T(" unsatisfied 'height' constraint.\n") );
1061 wxLogDebug( _T("Please check constraints: try adding AsIs() constraints.\n") );
1066 wxWindowList::Node
*node
= GetChildren().GetFirst();
1069 wxWindow
*win
= node
->GetData();
1070 if ( !win
->IsTopLevel() )
1071 win
->SetConstraintSizes();
1072 node
= node
->GetNext();
1077 // This assumes that all sizers are 'on' the same window, i.e. the parent of
1079 void wxWindowBase::TransformSizerToActual(int *x
, int *y
) const
1081 if ( !m_sizerParent
|| m_sizerParent
->IsTopLevel() )
1085 m_sizerParent
->GetPosition(&xp
, &yp
);
1086 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
1091 void wxWindowBase::SizerSetSize(int x
, int y
, int w
, int h
)
1095 TransformSizerToActual(&xx
, &yy
);
1096 SetSize(xx
, yy
, w
, h
);
1099 void wxWindowBase::SizerMove(int x
, int y
)
1103 TransformSizerToActual(&xx
, &yy
);
1107 // Only set the size/position of the constraint (if any)
1108 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1110 wxLayoutConstraints
*constr
= GetConstraints();
1115 constr
->left
.SetValue(x
);
1116 constr
->left
.SetDone(TRUE
);
1120 constr
->top
.SetValue(y
);
1121 constr
->top
.SetDone(TRUE
);
1125 constr
->width
.SetValue(w
);
1126 constr
->width
.SetDone(TRUE
);
1130 constr
->height
.SetValue(h
);
1131 constr
->height
.SetDone(TRUE
);
1136 void wxWindowBase::MoveConstraint(int x
, int y
)
1138 wxLayoutConstraints
*constr
= GetConstraints();
1143 constr
->left
.SetValue(x
);
1144 constr
->left
.SetDone(TRUE
);
1148 constr
->top
.SetValue(y
);
1149 constr
->top
.SetDone(TRUE
);
1154 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1156 wxLayoutConstraints
*constr
= GetConstraints();
1159 *w
= constr
->width
.GetValue();
1160 *h
= constr
->height
.GetValue();
1166 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1168 wxLayoutConstraints
*constr
= GetConstraints();
1171 *w
= constr
->width
.GetValue();
1172 *h
= constr
->height
.GetValue();
1175 GetClientSize(w
, h
);
1178 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1180 wxLayoutConstraints
*constr
= GetConstraints();
1183 *x
= constr
->left
.GetValue();
1184 *y
= constr
->top
.GetValue();
1190 #endif // wxUSE_CONSTRAINTS
1192 // ----------------------------------------------------------------------------
1193 // do Update UI processing for child controls
1194 // ----------------------------------------------------------------------------
1196 // TODO: should this be implemented for the child window rather
1197 // than the parent? Then you can override it e.g. for wxCheckBox
1198 // to do the Right Thing rather than having to assume a fixed number
1199 // of control classes.
1200 void wxWindowBase::UpdateWindowUI()
1202 wxWindowID id
= GetId();
1205 wxUpdateUIEvent
event(id
);
1206 event
.m_eventObject
= this;
1208 if ( GetEventHandler()->ProcessEvent(event
) )
1210 if ( event
.GetSetEnabled() )
1211 Enable(event
.GetEnabled());
1213 if ( event
.GetSetText() )
1215 wxControl
*control
= wxDynamicCast(this, wxControl
);
1217 control
->SetLabel(event
.GetText());
1221 wxCheckBox
*checkbox
= wxDynamicCast(this, wxCheckBox
);
1224 if ( event
.GetSetChecked() )
1225 checkbox
->SetValue(event
.GetChecked());
1227 #endif // wxUSE_CHECKBOX
1229 #if wxUSE_RADIOBUTTON
1230 wxRadioButton
*radiobtn
= wxDynamicCast(this, wxRadioButton
);
1233 if ( event
.GetSetChecked() )
1234 radiobtn
->SetValue(event
.GetChecked());
1236 #endif // wxUSE_RADIOBUTTON
1241 // ----------------------------------------------------------------------------
1242 // dialog units translations
1243 // ----------------------------------------------------------------------------
1245 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1247 int charWidth
= GetCharWidth();
1248 int charHeight
= GetCharHeight();
1249 wxPoint
pt2(-1, -1);
1251 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1253 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1258 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1260 int charWidth
= GetCharWidth();
1261 int charHeight
= GetCharHeight();
1262 wxPoint
pt2(-1, -1);
1264 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1266 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1271 // ----------------------------------------------------------------------------
1273 // ----------------------------------------------------------------------------
1275 void wxWindowBase::DoSetClientObject( wxClientData
*data
)
1277 wxASSERT_MSG( m_clientDataType
!= ClientData_Void
,
1278 _T("can't have both object and void client data") );
1280 if ( m_clientObject
)
1281 delete m_clientObject
;
1283 m_clientObject
= data
;
1284 m_clientDataType
= ClientData_Object
;
1287 wxClientData
*wxWindowBase::DoGetClientObject() const
1289 wxASSERT_MSG( m_clientDataType
== ClientData_Object
,
1290 _T("this window doesn't have object client data") );
1292 return m_clientObject
;
1295 void wxWindowBase::DoSetClientData( void *data
)
1297 wxASSERT_MSG( m_clientDataType
!= ClientData_Object
,
1298 _T("can't have both object and void client data") );
1300 m_clientData
= data
;
1301 m_clientDataType
= ClientData_Void
;
1304 void *wxWindowBase::DoGetClientData() const
1306 wxASSERT_MSG( m_clientDataType
== ClientData_Void
,
1307 _T("this window doesn't have void client data") );
1309 return m_clientData
;
1312 // ----------------------------------------------------------------------------
1314 // ----------------------------------------------------------------------------
1316 // propagate the colour change event to the subwindows
1317 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1319 wxWindowList::Node
*node
= GetChildren().GetFirst();
1322 // Only propagate to non-top-level windows
1323 wxWindow
*win
= node
->GetData();
1324 if ( !win
->IsTopLevel() )
1326 wxSysColourChangedEvent event2
;
1327 event
.m_eventObject
= win
;
1328 win
->GetEventHandler()->ProcessEvent(event2
);
1331 node
= node
->GetNext();
1335 // the default action is to populate dialog with data when it's created
1336 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1338 TransferDataToWindow();
1341 // ----------------------------------------------------------------------------
1342 // list classes implementation
1343 // ----------------------------------------------------------------------------
1345 void wxWindowListNode::DeleteData()
1347 delete (wxWindow
*)GetData();