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"
47 #endif // wxUSE_CONSTRAINTS
49 #if wxUSE_DRAG_AND_DROP
51 #endif // wxUSE_DRAG_AND_DROP
54 #include "wx/tooltip.h"
55 #endif // wxUSE_TOOLTIPS
61 // ----------------------------------------------------------------------------
63 // ----------------------------------------------------------------------------
65 int wxWindowBase::ms_lastControlId
= -200;
67 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
69 // ----------------------------------------------------------------------------
71 // ----------------------------------------------------------------------------
73 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
74 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
75 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
78 // ============================================================================
79 // implementation of the common functionality of the wxWindow class
80 // ============================================================================
82 // ----------------------------------------------------------------------------
84 // ----------------------------------------------------------------------------
86 // the default initialization
87 void wxWindowBase::InitBase()
89 // no window yet, no parent nor children
90 m_parent
= (wxWindow
*)NULL
;
92 m_children
.DeleteContents( FALSE
); // don't auto delete node data
94 // no constraints on the minimal window size
100 // window is created enabled but it's not visible yet
104 // no client data (yet)
106 m_clientDataType
= ClientData_None
;
108 // the default event handler is just this window
109 m_eventHandler
= this;
113 m_windowValidator
= (wxValidator
*) NULL
;
114 #endif // wxUSE_VALIDATORS
116 // use the system default colours
117 wxSystemSettings settings
;
119 m_backgroundColour
= settings
.GetSystemColour(wxSYS_COLOUR_BTNFACE
);
120 m_foregroundColour
= *wxBLACK
; // TODO take this from sys settings too?
121 m_font
= *wxSWISS_FONT
; // and this?
126 // an optimization for the event processing: checking this flag is much
127 // faster than using IsKindOf(CLASSINFO(wxWindow))
130 #if wxUSE_CONSTRAINTS
131 // no constraints whatsoever
132 m_constraints
= (wxLayoutConstraints
*) NULL
;
133 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
134 m_windowSizer
= (wxSizer
*) 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
),
158 # if defined(__VISAGECPP__)
159 const wxValidator
* validator
,
161 const wxValidator
& validator
,
164 const wxString
& name
)
166 // m_isWindow is set to TRUE in wxWindowBase::Init() as well as many other
167 // member variables - check that it has been called (will catch the case
168 // when a new ctor is added which doesn't call InitWindow)
169 wxASSERT_MSG( m_isWindow
, wxT("Init() must have been called before!") );
171 // generate a new id if the user doesn't care about it
172 m_windowId
= id
== -1 ? NewControlId() : id
;
175 SetWindowStyleFlag(style
);
177 SetValidator(validator
);
182 // ----------------------------------------------------------------------------
184 // ----------------------------------------------------------------------------
187 wxWindowBase::~wxWindowBase()
189 // FIXME if these 2 cases result from programming errors in the user code
190 // we should probably assert here instead of silently fixing them
192 // Just in case the window has been Closed, but we're then deleting
193 // immediately: don't leave dangling pointers.
194 wxPendingDelete
.DeleteObject(this);
196 // Just in case we've loaded a top-level window via LoadNativeDialog but
197 // we weren't a dialog class
198 wxTopLevelWindows
.DeleteObject(this);
200 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
202 // make sure that there are no dangling pointers left pointing to us
203 wxPanel
*panel
= wxDynamicCast(GetParent(), wxPanel
);
206 if ( panel
->GetLastFocus() == this )
208 panel
->SetLastFocus((wxWindow
*)NULL
);
215 #endif // wxUSE_CARET
218 if ( m_windowValidator
)
219 delete m_windowValidator
;
220 #endif // wxUSE_VALIDATORS
222 // we only delete object data, not untyped
223 if ( m_clientDataType
== ClientData_Object
)
224 delete m_clientObject
;
226 #if wxUSE_CONSTRAINTS
227 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
228 // at deleted windows as they delete themselves.
229 DeleteRelatedConstraints();
233 // This removes any dangling pointers to this window in other windows'
234 // constraintsInvolvedIn lists.
235 UnsetConstraints(m_constraints
);
236 delete m_constraints
;
237 m_constraints
= NULL
;
241 delete m_windowSizer
;
243 #endif // wxUSE_CONSTRAINTS
245 #if wxUSE_DRAG_AND_DROP
248 #endif // wxUSE_DRAG_AND_DROP
253 #endif // wxUSE_TOOLTIPS
256 bool wxWindowBase::Destroy()
263 bool wxWindowBase::Close(bool force
)
265 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
266 event
.SetEventObject(this);
267 #if WXWIN_COMPATIBILITY
268 event
.SetForce(force
);
269 #endif // WXWIN_COMPATIBILITY
270 event
.SetCanVeto(!force
);
272 // return FALSE if window wasn't closed because the application vetoed the
274 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
277 bool wxWindowBase::DestroyChildren()
279 wxWindowList::Node
*node
;
282 // we iterate until the list becomes empty
283 node
= GetChildren().GetFirst();
287 wxWindow
*child
= node
->GetData();
289 wxASSERT_MSG( child
, wxT("children list contains empty nodes") );
293 wxASSERT_MSG( !GetChildren().Find(child
),
294 wxT("child didn't remove itself using RemoveChild()") );
300 // ----------------------------------------------------------------------------
301 // centre/fit the window
302 // ----------------------------------------------------------------------------
304 // centre the window with respect to its parent in either (or both) directions
305 void wxWindowBase::Centre(int direction
)
307 int widthParent
, heightParent
;
309 wxWindow
*parent
= GetParent();
313 direction
|= wxCENTRE_ON_SCREEN
;
316 if ( direction
& wxCENTRE_ON_SCREEN
)
318 // centre with respect to the whole screen
319 wxDisplaySize(&widthParent
, &heightParent
);
323 // centre inside the parents rectangle
324 parent
->GetClientSize(&widthParent
, &heightParent
);
328 GetSize(&width
, &height
);
333 if ( direction
& wxHORIZONTAL
)
334 xNew
= (widthParent
- width
)/2;
336 if ( direction
& wxVERTICAL
)
337 yNew
= (heightParent
- height
)/2;
339 // controls are always centered on their parent because it doesn't make
340 // sense to centre them on the screen
341 if ( !(direction
& wxCENTRE_ON_SCREEN
) || wxDynamicCast(this, wxControl
) )
343 // theo nly chance to get this is to have a wxControl without parent
344 wxCHECK_RET( parent
, wxT("a control must have a parent") );
346 // adjust to the parents client area origin
347 wxPoint posParent
= parent
->ClientToScreen(wxPoint(0, 0));
356 // fits the window around the children
357 void wxWindowBase::Fit()
362 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
364 node
= node
->GetNext() )
366 wxWindow
*win
= node
->GetData();
367 if ( win
->IsTopLevel() )
369 // dialogs and frames lie in different top level windows - don't
370 // deal with them here
375 win
->GetPosition(&wx
, &wy
);
376 win
->GetSize(&ww
, &wh
);
377 if ( wx
+ ww
> maxX
)
379 if ( wy
+ wh
> maxY
)
384 SetClientSize(maxX
+ 7, maxY
+ 14);
387 // set the min/max size of the window
389 void wxWindowBase::SetSizeHints(int minW
, int minH
,
391 int WXUNUSED(incW
), int WXUNUSED(incH
))
399 // ----------------------------------------------------------------------------
400 // show/hide/enable/disable the window
401 // ----------------------------------------------------------------------------
403 bool wxWindowBase::Show(bool show
)
405 if ( show
!= m_isShown
)
417 bool wxWindowBase::Enable(bool enable
)
419 if ( enable
!= m_isEnabled
)
421 m_isEnabled
= enable
;
430 // ----------------------------------------------------------------------------
432 // ----------------------------------------------------------------------------
434 bool wxWindowBase::IsTopLevel() const
439 // ----------------------------------------------------------------------------
440 // reparenting the window
441 // ----------------------------------------------------------------------------
443 void wxWindowBase::AddChild(wxWindowBase
*child
)
445 wxCHECK_RET( child
, wxT("can't add a NULL child") );
447 GetChildren().Append(child
);
448 child
->SetParent(this);
451 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
453 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
455 GetChildren().DeleteObject(child
);
456 child
->SetParent((wxWindow
*)NULL
);
459 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
461 wxWindow
*oldParent
= GetParent();
462 if ( newParent
== oldParent
)
468 // unlink this window from the existing parent.
471 oldParent
->RemoveChild(this);
475 wxTopLevelWindows
.DeleteObject(this);
478 // add it to the new one
481 newParent
->AddChild(this);
485 wxTopLevelWindows
.Append(this);
491 // ----------------------------------------------------------------------------
492 // event handler stuff
493 // ----------------------------------------------------------------------------
495 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
497 handler
->SetNextHandler(GetEventHandler());
498 SetEventHandler(handler
);
501 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
503 wxEvtHandler
*handlerA
= GetEventHandler();
506 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
507 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
508 SetEventHandler(handlerB
);
512 handlerA
= (wxEvtHandler
*)NULL
;
519 // ----------------------------------------------------------------------------
521 // ----------------------------------------------------------------------------
523 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
525 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
528 m_backgroundColour
= colour
;
533 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
535 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
538 m_foregroundColour
= colour
;
543 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
545 // don't try to set invalid cursor, always fall back to the default
546 const wxCursor
& cursorOk
= cursor
.Ok() ? cursor
: *wxSTANDARD_CURSOR
;
548 if ( (wxCursor
&)cursorOk
== m_cursor
)
559 bool wxWindowBase::SetFont(const wxFont
& font
)
561 // don't try to set invalid font, always fall back to the default
562 const wxFont
& fontOk
= font
.Ok() ? font
: *wxSWISS_FONT
;
564 if ( (wxFont
&)fontOk
== m_font
)
576 void wxWindowBase::SetCaret(wxCaret
*caret
)
587 wxASSERT_MSG( m_caret
->GetWindow() == this,
588 wxT("caret should be created associated to this window") );
591 #endif // wxUSE_CARET
594 // ----------------------------------------------------------------------------
596 // ----------------------------------------------------------------------------
598 # if defined(__VISAGECPP__)
599 void wxWindowBase::SetValidator(const wxValidator
* validator
)
601 if ( m_windowValidator
)
602 delete m_windowValidator
;
604 m_windowValidator
= (wxValidator
*)validator
->Clone();
606 if ( m_windowValidator
)
607 m_windowValidator
->SetWindow(this) ;
610 void wxWindowBase::SetValidator(const wxValidator
& validator
)
612 if ( m_windowValidator
)
613 delete m_windowValidator
;
615 m_windowValidator
= (wxValidator
*)validator
.Clone();
617 if ( m_windowValidator
)
618 m_windowValidator
->SetWindow(this) ;
620 # endif // __VISAGECPP__
621 #endif // wxUSE_VALIDATORS
623 // ----------------------------------------------------------------------------
624 // update region testing
625 // ----------------------------------------------------------------------------
627 bool wxWindowBase::IsExposed(int x
, int y
) const
629 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
632 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
634 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
637 // ----------------------------------------------------------------------------
638 // find window by id or name
639 // ----------------------------------------------------------------------------
641 wxWindow
*wxWindowBase::FindWindow( long id
)
643 if ( id
== m_windowId
)
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 wxWindowBase
*child
= node
->GetData();
651 res
= child
->FindWindow( id
);
654 return (wxWindow
*)res
;
657 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
659 if ( name
== m_windowName
)
660 return (wxWindow
*)this;
662 wxWindowBase
*res
= (wxWindow
*)NULL
;
663 wxWindowList::Node
*node
;
664 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
666 wxWindow
*child
= node
->GetData();
667 res
= child
->FindWindow(name
);
670 return (wxWindow
*)res
;
673 // ----------------------------------------------------------------------------
674 // dialog oriented functions
675 // ----------------------------------------------------------------------------
677 void wxWindowBase::MakeModal(bool modal
)
679 // Disable all other windows
682 wxWindowList::Node
*node
= wxTopLevelWindows
.GetFirst();
685 wxWindow
*win
= node
->GetData();
689 node
= node
->GetNext();
694 bool wxWindowBase::Validate()
697 wxWindowList::Node
*node
;
698 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
700 wxWindowBase
*child
= node
->GetData();
701 wxValidator
*validator
= child
->GetValidator();
702 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
707 #endif // wxUSE_VALIDATORS
712 bool wxWindowBase::TransferDataToWindow()
715 wxWindowList::Node
*node
;
716 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
718 wxWindowBase
*child
= node
->GetData();
719 wxValidator
*validator
= child
->GetValidator();
720 if ( validator
&& !validator
->TransferToWindow() )
722 wxLog
*log
= wxLog::GetActiveTarget();
725 wxLogWarning(_("Could not transfer data to window"));
732 #endif // wxUSE_VALIDATORS
737 bool wxWindowBase::TransferDataFromWindow()
740 wxWindowList::Node
*node
;
741 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
743 wxWindow
*child
= node
->GetData();
744 if ( child
->GetValidator() &&
745 !child
->GetValidator()->TransferFromWindow() )
750 #endif // wxUSE_VALIDATORS
755 void wxWindowBase::InitDialog()
757 wxInitDialogEvent
event(GetId());
758 event
.SetEventObject( this );
759 GetEventHandler()->ProcessEvent(event
);
762 // ----------------------------------------------------------------------------
764 // ----------------------------------------------------------------------------
768 void wxWindowBase::SetToolTip( const wxString
&tip
)
770 // don't create the new tooltip if we already have one
773 m_tooltip
->SetTip( tip
);
777 SetToolTip( new wxToolTip( tip
) );
780 // setting empty tooltip text does not remove the tooltip any more - use
781 // SetToolTip((wxToolTip *)NULL) for this
784 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
792 #endif // wxUSE_TOOLTIPS
794 // ----------------------------------------------------------------------------
795 // constraints and sizers
796 // ----------------------------------------------------------------------------
798 #if wxUSE_CONSTRAINTS
800 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
804 UnsetConstraints(m_constraints
);
805 delete m_constraints
;
807 m_constraints
= constraints
;
810 // Make sure other windows know they're part of a 'meaningful relationship'
811 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
812 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
813 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
814 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
815 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
816 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
817 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
818 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
819 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
820 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
821 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
822 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
823 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
824 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
825 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
826 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
830 // This removes any dangling pointers to this window in other windows'
831 // constraintsInvolvedIn lists.
832 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
836 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
837 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
838 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
839 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
840 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
841 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
842 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
843 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
844 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
845 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
846 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
847 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
848 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
849 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
850 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
851 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
855 // Back-pointer to other windows we're involved with, so if we delete this
856 // window, we must delete any constraints we're involved with.
857 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
859 if ( !m_constraintsInvolvedIn
)
860 m_constraintsInvolvedIn
= new wxWindowList
;
861 if ( !m_constraintsInvolvedIn
->Find(otherWin
) )
862 m_constraintsInvolvedIn
->Append(otherWin
);
865 // REMOVE back-pointer to other windows we're involved with.
866 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
868 if ( m_constraintsInvolvedIn
)
869 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
872 // Reset any constraints that mention this window
873 void wxWindowBase::DeleteRelatedConstraints()
875 if ( m_constraintsInvolvedIn
)
877 wxWindowList::Node
*node
= m_constraintsInvolvedIn
->GetFirst();
880 wxWindow
*win
= node
->GetData();
881 wxLayoutConstraints
*constr
= win
->GetConstraints();
883 // Reset any constraints involving this window
886 constr
->left
.ResetIfWin(this);
887 constr
->top
.ResetIfWin(this);
888 constr
->right
.ResetIfWin(this);
889 constr
->bottom
.ResetIfWin(this);
890 constr
->width
.ResetIfWin(this);
891 constr
->height
.ResetIfWin(this);
892 constr
->centreX
.ResetIfWin(this);
893 constr
->centreY
.ResetIfWin(this);
896 wxWindowList::Node
*next
= node
->GetNext();
901 delete m_constraintsInvolvedIn
;
902 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
906 void wxWindowBase::SetSizer(wxSizer
*sizer
)
908 if (m_windowSizer
) delete m_windowSizer
;
910 m_windowSizer
= sizer
;
913 bool wxWindowBase::Layout()
916 GetClientSize(&w
, &h
);
918 // If there is a sizer, use it instead of the constraints
921 GetSizer()->SetDimension( 0, 0, w
, h
);
925 if ( GetConstraints() )
927 GetConstraints()->width
.SetValue(w
);
928 GetConstraints()->height
.SetValue(h
);
931 // Evaluate child constraints
932 ResetConstraints(); // Mark all constraints as unevaluated
933 DoPhase(1); // Just one phase need if no sizers involved
935 SetConstraintSizes(); // Recursively set the real window sizes
941 // Do a phase of evaluating constraints: the default behaviour. wxSizers may
942 // do a similar thing, but also impose their own 'constraints' and order the
943 // evaluation differently.
944 bool wxWindowBase::LayoutPhase1(int *noChanges
)
946 wxLayoutConstraints
*constr
= GetConstraints();
949 return constr
->SatisfyConstraints(this, noChanges
);
955 bool wxWindowBase::LayoutPhase2(int *noChanges
)
965 // Do a phase of evaluating child constraints
966 bool wxWindowBase::DoPhase(int phase
)
968 int noIterations
= 0;
969 int maxIterations
= 500;
972 wxWindowList succeeded
;
973 while ((noChanges
> 0) && (noIterations
< maxIterations
))
977 wxWindowList::Node
*node
= GetChildren().GetFirst();
980 wxWindow
*child
= node
->GetData();
981 if ( !child
->IsTopLevel() )
983 wxLayoutConstraints
*constr
= child
->GetConstraints();
986 if ( !succeeded
.Find(child
) )
988 int tempNoChanges
= 0;
989 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
990 noChanges
+= tempNoChanges
;
993 succeeded
.Append(child
);
998 node
= node
->GetNext();
1007 void wxWindowBase::ResetConstraints()
1009 wxLayoutConstraints
*constr
= GetConstraints();
1012 constr
->left
.SetDone(FALSE
);
1013 constr
->top
.SetDone(FALSE
);
1014 constr
->right
.SetDone(FALSE
);
1015 constr
->bottom
.SetDone(FALSE
);
1016 constr
->width
.SetDone(FALSE
);
1017 constr
->height
.SetDone(FALSE
);
1018 constr
->centreX
.SetDone(FALSE
);
1019 constr
->centreY
.SetDone(FALSE
);
1021 wxWindowList::Node
*node
= GetChildren().GetFirst();
1024 wxWindow
*win
= node
->GetData();
1025 if ( !win
->IsTopLevel() )
1026 win
->ResetConstraints();
1027 node
= node
->GetNext();
1031 // Need to distinguish between setting the 'fake' size for windows and sizers,
1032 // and setting the real values.
1033 void wxWindowBase::SetConstraintSizes(bool recurse
)
1035 wxLayoutConstraints
*constr
= GetConstraints();
1036 if ( constr
&& constr
->left
.GetDone() && constr
->right
.GetDone( ) &&
1037 constr
->width
.GetDone() && constr
->height
.GetDone())
1039 int x
= constr
->left
.GetValue();
1040 int y
= constr
->top
.GetValue();
1041 int w
= constr
->width
.GetValue();
1042 int h
= constr
->height
.GetValue();
1044 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1045 (constr
->height
.GetRelationship() != wxAsIs
) )
1047 SetSize(x
, y
, w
, h
);
1051 // If we don't want to resize this window, just move it...
1057 wxChar
*windowClass
= GetClassInfo()->GetClassName();
1060 if ( GetName() == wxT("") )
1061 winName
= wxT("unnamed");
1063 winName
= GetName();
1064 wxLogDebug( wxT("Constraint(s) not satisfied for window of type %s, name %s:\n"),
1065 (const wxChar
*)windowClass
,
1066 (const wxChar
*)winName
);
1067 if ( !constr
->left
.GetDone()) wxLogDebug( wxT(" unsatisfied 'left' constraint.\n") );
1068 if ( !constr
->right
.GetDone()) wxLogDebug( wxT(" unsatisfied 'right' constraint.\n") );
1069 if ( !constr
->width
.GetDone()) wxLogDebug( wxT(" unsatisfied 'width' constraint.\n") );
1070 if ( !constr
->height
.GetDone()) wxLogDebug( wxT(" unsatisfied 'height' constraint.\n") );
1071 wxLogDebug( wxT("Please check constraints: try adding AsIs() constraints.\n") );
1076 wxWindowList::Node
*node
= GetChildren().GetFirst();
1079 wxWindow
*win
= node
->GetData();
1080 if ( !win
->IsTopLevel() )
1081 win
->SetConstraintSizes();
1082 node
= node
->GetNext();
1087 // Only set the size/position of the constraint (if any)
1088 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1090 wxLayoutConstraints
*constr
= GetConstraints();
1095 constr
->left
.SetValue(x
);
1096 constr
->left
.SetDone(TRUE
);
1100 constr
->top
.SetValue(y
);
1101 constr
->top
.SetDone(TRUE
);
1105 constr
->width
.SetValue(w
);
1106 constr
->width
.SetDone(TRUE
);
1110 constr
->height
.SetValue(h
);
1111 constr
->height
.SetDone(TRUE
);
1116 void wxWindowBase::MoveConstraint(int x
, int y
)
1118 wxLayoutConstraints
*constr
= GetConstraints();
1123 constr
->left
.SetValue(x
);
1124 constr
->left
.SetDone(TRUE
);
1128 constr
->top
.SetValue(y
);
1129 constr
->top
.SetDone(TRUE
);
1134 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1136 wxLayoutConstraints
*constr
= GetConstraints();
1139 *w
= constr
->width
.GetValue();
1140 *h
= constr
->height
.GetValue();
1146 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1148 wxLayoutConstraints
*constr
= GetConstraints();
1151 *w
= constr
->width
.GetValue();
1152 *h
= constr
->height
.GetValue();
1155 GetClientSize(w
, h
);
1158 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1160 wxLayoutConstraints
*constr
= GetConstraints();
1163 *x
= constr
->left
.GetValue();
1164 *y
= constr
->top
.GetValue();
1170 #endif // wxUSE_CONSTRAINTS
1172 // ----------------------------------------------------------------------------
1173 // do Update UI processing for child controls
1174 // ----------------------------------------------------------------------------
1176 // TODO: should this be implemented for the child window rather
1177 // than the parent? Then you can override it e.g. for wxCheckBox
1178 // to do the Right Thing rather than having to assume a fixed number
1179 // of control classes.
1180 void wxWindowBase::UpdateWindowUI()
1182 wxWindowID id
= GetId();
1185 wxUpdateUIEvent
event(id
);
1186 event
.m_eventObject
= this;
1188 if ( GetEventHandler()->ProcessEvent(event
) )
1190 if ( event
.GetSetEnabled() )
1191 Enable(event
.GetEnabled());
1193 if ( event
.GetSetText() )
1195 wxControl
*control
= wxDynamicCast(this, wxControl
);
1197 control
->SetLabel(event
.GetText());
1201 wxCheckBox
*checkbox
= wxDynamicCast(this, wxCheckBox
);
1204 if ( event
.GetSetChecked() )
1205 checkbox
->SetValue(event
.GetChecked());
1207 #endif // wxUSE_CHECKBOX
1209 #if wxUSE_RADIOBUTTON
1210 wxRadioButton
*radiobtn
= wxDynamicCast(this, wxRadioButton
);
1213 if ( event
.GetSetChecked() )
1214 radiobtn
->SetValue(event
.GetChecked());
1216 #endif // wxUSE_RADIOBUTTON
1221 // ----------------------------------------------------------------------------
1222 // dialog units translations
1223 // ----------------------------------------------------------------------------
1225 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1227 int charWidth
= GetCharWidth();
1228 int charHeight
= GetCharHeight();
1229 wxPoint
pt2(-1, -1);
1231 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1233 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1238 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1240 int charWidth
= GetCharWidth();
1241 int charHeight
= GetCharHeight();
1242 wxPoint
pt2(-1, -1);
1244 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1246 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1251 // ----------------------------------------------------------------------------
1253 // ----------------------------------------------------------------------------
1255 void wxWindowBase::DoSetClientObject( wxClientData
*data
)
1257 wxASSERT_MSG( m_clientDataType
!= ClientData_Void
,
1258 wxT("can't have both object and void client data") );
1260 if ( m_clientObject
)
1261 delete m_clientObject
;
1263 m_clientObject
= data
;
1264 m_clientDataType
= ClientData_Object
;
1267 wxClientData
*wxWindowBase::DoGetClientObject() const
1269 wxASSERT_MSG( m_clientDataType
== ClientData_Object
,
1270 wxT("this window doesn't have object client data") );
1272 return m_clientObject
;
1275 void wxWindowBase::DoSetClientData( void *data
)
1277 wxASSERT_MSG( m_clientDataType
!= ClientData_Object
,
1278 wxT("can't have both object and void client data") );
1280 m_clientData
= data
;
1281 m_clientDataType
= ClientData_Void
;
1284 void *wxWindowBase::DoGetClientData() const
1286 wxASSERT_MSG( m_clientDataType
== ClientData_Void
,
1287 wxT("this window doesn't have void client data") );
1289 return m_clientData
;
1292 // ----------------------------------------------------------------------------
1294 // ----------------------------------------------------------------------------
1296 // propagate the colour change event to the subwindows
1297 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1299 wxWindowList::Node
*node
= GetChildren().GetFirst();
1302 // Only propagate to non-top-level windows
1303 wxWindow
*win
= node
->GetData();
1304 if ( !win
->IsTopLevel() )
1306 wxSysColourChangedEvent event2
;
1307 event
.m_eventObject
= win
;
1308 win
->GetEventHandler()->ProcessEvent(event2
);
1311 node
= node
->GetNext();
1315 // the default action is to populate dialog with data when it's created
1316 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1318 TransferDataToWindow();
1321 // ----------------------------------------------------------------------------
1322 // list classes implementation
1323 // ----------------------------------------------------------------------------
1325 void wxWindowListNode::DeleteData()
1327 delete (wxWindow
*)GetData();