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/textctrl.h"
41 #include "wx/settings.h"
42 #include "wx/dialog.h"
46 #include "wx/layout.h"
48 #endif // wxUSE_CONSTRAINTS
50 #if wxUSE_DRAG_AND_DROP
52 #endif // wxUSE_DRAG_AND_DROP
55 #include "wx/tooltip.h"
56 #endif // wxUSE_TOOLTIPS
62 // ----------------------------------------------------------------------------
64 // ----------------------------------------------------------------------------
66 int wxWindowBase::ms_lastControlId
= -200;
68 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
70 // ----------------------------------------------------------------------------
72 // ----------------------------------------------------------------------------
74 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
75 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
76 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
79 // ============================================================================
80 // implementation of the common functionality of the wxWindow class
81 // ============================================================================
83 // ----------------------------------------------------------------------------
85 // ----------------------------------------------------------------------------
87 // the default initialization
88 void wxWindowBase::InitBase()
90 // no window yet, no parent nor children
91 m_parent
= (wxWindow
*)NULL
;
93 m_children
.DeleteContents( FALSE
); // don't auto delete node data
95 // no constraints on the minimal window size
101 // window is created enabled but it's not visible yet
105 // no client data (yet)
107 m_clientDataType
= ClientData_None
;
109 // the default event handler is just this window
110 m_eventHandler
= this;
114 m_windowValidator
= (wxValidator
*) NULL
;
115 #endif // wxUSE_VALIDATORS
117 // use the system default colours
118 wxSystemSettings settings
;
120 m_backgroundColour
= settings
.GetSystemColour(wxSYS_COLOUR_BTNFACE
);
121 // m_foregroundColour = *wxBLACK; // TODO take this from sys settings too?
122 m_foregroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOWTEXT
);
124 #if !defined(__WXMAC__) && !defined(__WXGTK__)
125 m_font
= *wxSWISS_FONT
; // and this?
127 m_font
= settings
.GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
132 // an optimization for the event processing: checking this flag is much
133 // faster than using IsKindOf(CLASSINFO(wxWindow))
136 #if wxUSE_CONSTRAINTS
137 // no constraints whatsoever
138 m_constraints
= (wxLayoutConstraints
*) NULL
;
139 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
140 m_windowSizer
= (wxSizer
*) NULL
;
141 m_autoLayout
= FALSE
;
142 #endif // wxUSE_CONSTRAINTS
144 #if wxUSE_DRAG_AND_DROP
145 m_dropTarget
= (wxDropTarget
*)NULL
;
146 #endif // wxUSE_DRAG_AND_DROP
149 m_tooltip
= (wxToolTip
*)NULL
;
150 #endif // wxUSE_TOOLTIPS
153 m_caret
= (wxCaret
*)NULL
;
154 #endif // wxUSE_CARET
157 // common part of window creation process
158 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
160 const wxPoint
& WXUNUSED(pos
),
161 const wxSize
& WXUNUSED(size
),
163 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
);
179 SetValidator(validator
);
180 #endif // wxUSE_VALIDATORS
185 // ----------------------------------------------------------------------------
187 // ----------------------------------------------------------------------------
190 wxWindowBase::~wxWindowBase()
192 // FIXME if these 2 cases result from programming errors in the user code
193 // we should probably assert here instead of silently fixing them
195 // Just in case the window has been Closed, but we're then deleting
196 // immediately: don't leave dangling pointers.
197 wxPendingDelete
.DeleteObject(this);
199 // Just in case we've loaded a top-level window via LoadNativeDialog but
200 // we weren't a dialog class
201 wxTopLevelWindows
.DeleteObject(this);
203 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
205 // make sure that there are no dangling pointers left pointing to us
206 wxPanel
*panel
= wxDynamicCast(GetParent(), wxPanel
);
209 if ( panel
->GetLastFocus() == this )
211 panel
->SetLastFocus((wxWindow
*)NULL
);
218 #endif // wxUSE_CARET
221 if ( m_windowValidator
)
222 delete m_windowValidator
;
223 #endif // wxUSE_VALIDATORS
225 // we only delete object data, not untyped
226 if ( m_clientDataType
== ClientData_Object
)
227 delete m_clientObject
;
229 #if wxUSE_CONSTRAINTS
230 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
231 // at deleted windows as they delete themselves.
232 DeleteRelatedConstraints();
236 // This removes any dangling pointers to this window in other windows'
237 // constraintsInvolvedIn lists.
238 UnsetConstraints(m_constraints
);
239 delete m_constraints
;
240 m_constraints
= NULL
;
244 delete m_windowSizer
;
246 #endif // wxUSE_CONSTRAINTS
248 #if wxUSE_DRAG_AND_DROP
251 #endif // wxUSE_DRAG_AND_DROP
256 #endif // wxUSE_TOOLTIPS
259 bool wxWindowBase::Destroy()
266 bool wxWindowBase::Close(bool force
)
268 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
269 event
.SetEventObject(this);
270 #if WXWIN_COMPATIBILITY
271 event
.SetForce(force
);
272 #endif // WXWIN_COMPATIBILITY
273 event
.SetCanVeto(!force
);
275 // return FALSE if window wasn't closed because the application vetoed the
277 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
280 bool wxWindowBase::DestroyChildren()
282 wxWindowList::Node
*node
;
285 // we iterate until the list becomes empty
286 node
= GetChildren().GetFirst();
290 wxWindow
*child
= node
->GetData();
292 wxASSERT_MSG( child
, wxT("children list contains empty nodes") );
296 wxASSERT_MSG( !GetChildren().Find(child
),
297 wxT("child didn't remove itself using RemoveChild()") );
303 // ----------------------------------------------------------------------------
304 // size/position related methods
305 // ----------------------------------------------------------------------------
307 // centre the window with respect to its parent in either (or both) directions
308 void wxWindowBase::Centre(int direction
)
310 int widthParent
, heightParent
;
312 wxWindow
*parent
= GetParent();
316 direction
|= wxCENTRE_ON_SCREEN
;
319 if ( direction
& wxCENTRE_ON_SCREEN
)
321 // centre with respect to the whole screen
322 wxDisplaySize(&widthParent
, &heightParent
);
326 // centre inside the parents rectangle
327 parent
->GetClientSize(&widthParent
, &heightParent
);
331 GetSize(&width
, &height
);
336 if ( direction
& wxHORIZONTAL
)
337 xNew
= (widthParent
- width
)/2;
339 if ( direction
& wxVERTICAL
)
340 yNew
= (heightParent
- height
)/2;
342 // controls are always centered on their parent because it doesn't make
343 // sense to centre them on the screen
344 if ( !(direction
& wxCENTRE_ON_SCREEN
) || wxDynamicCast(this, wxControl
) )
346 // theo nly chance to get this is to have a wxControl without parent
347 wxCHECK_RET( parent
, wxT("a control must have a parent") );
349 // adjust to the parents client area origin
350 wxPoint posParent
= parent
->ClientToScreen(wxPoint(0, 0));
356 // move the centre of this window to this position
360 // fits the window around the children
361 void wxWindowBase::Fit()
363 if ( GetChildren().GetCount() > 0 )
365 SetClientSize(DoGetBestSize());
367 //else: do nothing if we have no children
370 // return the size best suited for the current window
371 wxSize
wxWindowBase::DoGetBestSize() const
373 if ( GetChildren().GetCount() > 0 )
375 // our minimal acceptable size is such that all our windows fit inside
379 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
381 node
= node
->GetNext() )
383 wxWindow
*win
= node
->GetData();
384 if ( win
->IsTopLevel() )
386 // dialogs and frames lie in different top level windows -
387 // don't deal with them here
392 win
->GetPosition(&wx
, &wy
);
393 win
->GetSize(&ww
, &wh
);
394 if ( wx
+ ww
> maxX
)
396 if ( wy
+ wh
> maxY
)
401 return wxSize(maxX
+ 7, maxY
+ 14);
405 // for a generic window there is no natural best size - just use the
411 // set the min/max size of the window
412 void wxWindowBase::SetSizeHints(int minW
, int minH
,
414 int WXUNUSED(incW
), int WXUNUSED(incH
))
422 // ----------------------------------------------------------------------------
423 // show/hide/enable/disable the window
424 // ----------------------------------------------------------------------------
426 bool wxWindowBase::Show(bool show
)
428 if ( show
!= m_isShown
)
440 bool wxWindowBase::Enable(bool enable
)
442 if ( enable
!= m_isEnabled
)
444 m_isEnabled
= enable
;
453 // ----------------------------------------------------------------------------
455 // ----------------------------------------------------------------------------
457 bool wxWindowBase::IsTopLevel() const
462 // ----------------------------------------------------------------------------
463 // reparenting the window
464 // ----------------------------------------------------------------------------
466 void wxWindowBase::AddChild(wxWindowBase
*child
)
468 wxCHECK_RET( child
, wxT("can't add a NULL child") );
470 GetChildren().Append(child
);
471 child
->SetParent(this);
474 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
476 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
478 GetChildren().DeleteObject(child
);
479 child
->SetParent((wxWindow
*)NULL
);
482 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
484 wxWindow
*oldParent
= GetParent();
485 if ( newParent
== oldParent
)
491 // unlink this window from the existing parent.
494 oldParent
->RemoveChild(this);
498 wxTopLevelWindows
.DeleteObject(this);
501 // add it to the new one
504 newParent
->AddChild(this);
508 wxTopLevelWindows
.Append(this);
514 // ----------------------------------------------------------------------------
515 // event handler stuff
516 // ----------------------------------------------------------------------------
518 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
520 handler
->SetNextHandler(GetEventHandler());
521 SetEventHandler(handler
);
524 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
526 wxEvtHandler
*handlerA
= GetEventHandler();
529 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
530 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
531 SetEventHandler(handlerB
);
535 handlerA
= (wxEvtHandler
*)NULL
;
542 // ----------------------------------------------------------------------------
544 // ----------------------------------------------------------------------------
546 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
548 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
551 m_backgroundColour
= colour
;
556 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
558 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
561 m_foregroundColour
= colour
;
566 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
568 // don't try to set invalid cursor, always fall back to the default
569 const wxCursor
& cursorOk
= cursor
.Ok() ? cursor
: *wxSTANDARD_CURSOR
;
571 if ( (wxCursor
&)cursorOk
== m_cursor
)
582 bool wxWindowBase::SetFont(const wxFont
& font
)
584 // don't try to set invalid font, always fall back to the default
585 const wxFont
& fontOk
= font
.Ok() ? font
: *wxSWISS_FONT
;
587 if ( (wxFont
&)fontOk
== m_font
)
599 void wxWindowBase::SetCaret(wxCaret
*caret
)
610 wxASSERT_MSG( m_caret
->GetWindow() == this,
611 wxT("caret should be created associated to this window") );
614 #endif // wxUSE_CARET
617 // ----------------------------------------------------------------------------
619 // ----------------------------------------------------------------------------
621 void wxWindowBase::SetValidator(const wxValidator
& validator
)
623 if ( m_windowValidator
)
624 delete m_windowValidator
;
626 m_windowValidator
= (wxValidator
*)validator
.Clone();
628 if ( m_windowValidator
)
629 m_windowValidator
->SetWindow(this) ;
631 #endif // wxUSE_VALIDATORS
633 // ----------------------------------------------------------------------------
634 // update region testing
635 // ----------------------------------------------------------------------------
637 bool wxWindowBase::IsExposed(int x
, int y
) const
639 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
642 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
644 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
647 // ----------------------------------------------------------------------------
648 // find window by id or name
649 // ----------------------------------------------------------------------------
651 wxWindow
*wxWindowBase::FindWindow( long id
)
653 if ( id
== m_windowId
)
654 return (wxWindow
*)this;
656 wxWindowBase
*res
= (wxWindow
*)NULL
;
657 wxWindowList::Node
*node
;
658 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
660 wxWindowBase
*child
= node
->GetData();
661 res
= child
->FindWindow( id
);
664 return (wxWindow
*)res
;
667 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
669 if ( name
== m_windowName
)
670 return (wxWindow
*)this;
672 wxWindowBase
*res
= (wxWindow
*)NULL
;
673 wxWindowList::Node
*node
;
674 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
676 wxWindow
*child
= node
->GetData();
677 res
= child
->FindWindow(name
);
680 return (wxWindow
*)res
;
683 // ----------------------------------------------------------------------------
684 // dialog oriented functions
685 // ----------------------------------------------------------------------------
687 void wxWindowBase::MakeModal(bool modal
)
689 // Disable all other windows
692 wxWindowList::Node
*node
= wxTopLevelWindows
.GetFirst();
695 wxWindow
*win
= node
->GetData();
699 node
= node
->GetNext();
704 bool wxWindowBase::Validate()
707 wxWindowList::Node
*node
;
708 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
710 wxWindowBase
*child
= node
->GetData();
711 wxValidator
*validator
= child
->GetValidator();
712 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
717 #endif // wxUSE_VALIDATORS
722 bool wxWindowBase::TransferDataToWindow()
725 wxWindowList::Node
*node
;
726 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
728 wxWindowBase
*child
= node
->GetData();
729 wxValidator
*validator
= child
->GetValidator();
730 if ( validator
&& !validator
->TransferToWindow() )
732 wxLog
*log
= wxLog::GetActiveTarget();
735 wxLogWarning(_("Could not transfer data to window"));
742 #endif // wxUSE_VALIDATORS
747 bool wxWindowBase::TransferDataFromWindow()
750 wxWindowList::Node
*node
;
751 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
753 wxWindow
*child
= node
->GetData();
754 if ( child
->GetValidator() &&
755 !child
->GetValidator()->TransferFromWindow() )
760 #endif // wxUSE_VALIDATORS
765 void wxWindowBase::InitDialog()
767 wxInitDialogEvent
event(GetId());
768 event
.SetEventObject( this );
769 GetEventHandler()->ProcessEvent(event
);
772 // ----------------------------------------------------------------------------
774 // ----------------------------------------------------------------------------
778 void wxWindowBase::SetToolTip( const wxString
&tip
)
780 // don't create the new tooltip if we already have one
783 m_tooltip
->SetTip( tip
);
787 SetToolTip( new wxToolTip( tip
) );
790 // setting empty tooltip text does not remove the tooltip any more - use
791 // SetToolTip((wxToolTip *)NULL) for this
794 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
802 #endif // wxUSE_TOOLTIPS
804 // ----------------------------------------------------------------------------
805 // constraints and sizers
806 // ----------------------------------------------------------------------------
808 #if wxUSE_CONSTRAINTS
810 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
814 UnsetConstraints(m_constraints
);
815 delete m_constraints
;
817 m_constraints
= constraints
;
820 // Make sure other windows know they're part of a 'meaningful relationship'
821 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
822 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
823 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
824 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
825 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
826 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
827 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
828 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
829 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
830 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
831 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
832 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
833 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
834 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
835 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
836 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
840 // This removes any dangling pointers to this window in other windows'
841 // constraintsInvolvedIn lists.
842 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
846 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
847 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
848 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
849 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
850 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
851 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
852 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
853 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
854 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
855 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
856 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
857 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
858 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
859 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
860 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
861 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
865 // Back-pointer to other windows we're involved with, so if we delete this
866 // window, we must delete any constraints we're involved with.
867 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
869 if ( !m_constraintsInvolvedIn
)
870 m_constraintsInvolvedIn
= new wxWindowList
;
871 if ( !m_constraintsInvolvedIn
->Find(otherWin
) )
872 m_constraintsInvolvedIn
->Append(otherWin
);
875 // REMOVE back-pointer to other windows we're involved with.
876 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
878 if ( m_constraintsInvolvedIn
)
879 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
882 // Reset any constraints that mention this window
883 void wxWindowBase::DeleteRelatedConstraints()
885 if ( m_constraintsInvolvedIn
)
887 wxWindowList::Node
*node
= m_constraintsInvolvedIn
->GetFirst();
890 wxWindow
*win
= node
->GetData();
891 wxLayoutConstraints
*constr
= win
->GetConstraints();
893 // Reset any constraints involving this window
896 constr
->left
.ResetIfWin(this);
897 constr
->top
.ResetIfWin(this);
898 constr
->right
.ResetIfWin(this);
899 constr
->bottom
.ResetIfWin(this);
900 constr
->width
.ResetIfWin(this);
901 constr
->height
.ResetIfWin(this);
902 constr
->centreX
.ResetIfWin(this);
903 constr
->centreY
.ResetIfWin(this);
906 wxWindowList::Node
*next
= node
->GetNext();
911 delete m_constraintsInvolvedIn
;
912 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
916 void wxWindowBase::SetSizer(wxSizer
*sizer
)
918 if (m_windowSizer
) delete m_windowSizer
;
920 m_windowSizer
= sizer
;
923 bool wxWindowBase::Layout()
925 // If there is a sizer, use it instead of the constraints
929 GetClientSize(&w
, &h
);
931 GetSizer()->SetDimension( 0, 0, w
, h
);
935 // Evaluate child constraints
936 ResetConstraints(); // Mark all constraints as unevaluated
937 DoPhase(1); // Just one phase need if no sizers involved
939 SetConstraintSizes(); // Recursively set the real window sizes
946 // Do a phase of evaluating constraints: the default behaviour. wxSizers may
947 // do a similar thing, but also impose their own 'constraints' and order the
948 // evaluation differently.
949 bool wxWindowBase::LayoutPhase1(int *noChanges
)
951 wxLayoutConstraints
*constr
= GetConstraints();
954 return constr
->SatisfyConstraints(this, noChanges
);
960 bool wxWindowBase::LayoutPhase2(int *noChanges
)
970 // Do a phase of evaluating child constraints
971 bool wxWindowBase::DoPhase(int phase
)
973 int noIterations
= 0;
974 int maxIterations
= 500;
977 wxWindowList succeeded
;
978 while ((noChanges
> 0) && (noIterations
< maxIterations
))
982 wxWindowList::Node
*node
= GetChildren().GetFirst();
985 wxWindow
*child
= node
->GetData();
986 if ( !child
->IsTopLevel() )
988 wxLayoutConstraints
*constr
= child
->GetConstraints();
991 if ( !succeeded
.Find(child
) )
993 int tempNoChanges
= 0;
994 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
995 noChanges
+= tempNoChanges
;
998 succeeded
.Append(child
);
1003 node
= node
->GetNext();
1012 void wxWindowBase::ResetConstraints()
1014 wxLayoutConstraints
*constr
= GetConstraints();
1017 constr
->left
.SetDone(FALSE
);
1018 constr
->top
.SetDone(FALSE
);
1019 constr
->right
.SetDone(FALSE
);
1020 constr
->bottom
.SetDone(FALSE
);
1021 constr
->width
.SetDone(FALSE
);
1022 constr
->height
.SetDone(FALSE
);
1023 constr
->centreX
.SetDone(FALSE
);
1024 constr
->centreY
.SetDone(FALSE
);
1027 wxWindowList::Node
*node
= GetChildren().GetFirst();
1030 wxWindow
*win
= node
->GetData();
1031 if ( !win
->IsTopLevel() )
1032 win
->ResetConstraints();
1033 node
= node
->GetNext();
1037 // Need to distinguish between setting the 'fake' size for windows and sizers,
1038 // and setting the real values.
1039 void wxWindowBase::SetConstraintSizes(bool recurse
)
1041 wxLayoutConstraints
*constr
= GetConstraints();
1042 if ( constr
&& constr
->left
.GetDone() && constr
->right
.GetDone( ) &&
1043 constr
->width
.GetDone() && constr
->height
.GetDone())
1045 int x
= constr
->left
.GetValue();
1046 int y
= constr
->top
.GetValue();
1047 int w
= constr
->width
.GetValue();
1048 int h
= constr
->height
.GetValue();
1050 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1051 (constr
->height
.GetRelationship() != wxAsIs
) )
1053 SetSize(x
, y
, w
, h
);
1057 // If we don't want to resize this window, just move it...
1063 wxString winName
= GetName();
1065 winName
= wxT("unnamed");
1066 wxLogDebug(wxT("Constraint not satisfied for %s, name '%s'."),
1067 GetClassInfo()->GetClassName(),
1073 wxWindowList::Node
*node
= GetChildren().GetFirst();
1076 wxWindow
*win
= node
->GetData();
1077 if ( !win
->IsTopLevel() )
1078 win
->SetConstraintSizes();
1079 node
= node
->GetNext();
1084 // Only set the size/position of the constraint (if any)
1085 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1087 wxLayoutConstraints
*constr
= GetConstraints();
1092 constr
->left
.SetValue(x
);
1093 constr
->left
.SetDone(TRUE
);
1097 constr
->top
.SetValue(y
);
1098 constr
->top
.SetDone(TRUE
);
1102 constr
->width
.SetValue(w
);
1103 constr
->width
.SetDone(TRUE
);
1107 constr
->height
.SetValue(h
);
1108 constr
->height
.SetDone(TRUE
);
1113 void wxWindowBase::MoveConstraint(int x
, int y
)
1115 wxLayoutConstraints
*constr
= GetConstraints();
1120 constr
->left
.SetValue(x
);
1121 constr
->left
.SetDone(TRUE
);
1125 constr
->top
.SetValue(y
);
1126 constr
->top
.SetDone(TRUE
);
1131 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1133 wxLayoutConstraints
*constr
= GetConstraints();
1136 *w
= constr
->width
.GetValue();
1137 *h
= constr
->height
.GetValue();
1143 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1145 wxLayoutConstraints
*constr
= GetConstraints();
1148 *w
= constr
->width
.GetValue();
1149 *h
= constr
->height
.GetValue();
1152 GetClientSize(w
, h
);
1155 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1157 wxLayoutConstraints
*constr
= GetConstraints();
1160 *x
= constr
->left
.GetValue();
1161 *y
= constr
->top
.GetValue();
1167 #endif // wxUSE_CONSTRAINTS
1169 // ----------------------------------------------------------------------------
1170 // do Update UI processing for child controls
1171 // ----------------------------------------------------------------------------
1173 // TODO: should this be implemented for the child window rather
1174 // than the parent? Then you can override it e.g. for wxCheckBox
1175 // to do the Right Thing rather than having to assume a fixed number
1176 // of control classes.
1177 void wxWindowBase::UpdateWindowUI()
1179 wxUpdateUIEvent
event(GetId());
1180 event
.m_eventObject
= this;
1182 if ( GetEventHandler()->ProcessEvent(event
) )
1184 if ( event
.GetSetEnabled() )
1185 Enable(event
.GetEnabled());
1187 if ( event
.GetSetText() )
1189 wxControl
*control
= wxDynamicCast(this, wxControl
);
1192 wxTextCtrl
*text
= wxDynamicCast(control
, wxTextCtrl
);
1194 text
->SetValue(event
.GetText());
1196 control
->SetLabel(event
.GetText());
1201 wxCheckBox
*checkbox
= wxDynamicCast(this, wxCheckBox
);
1204 if ( event
.GetSetChecked() )
1205 checkbox
->SetValue(event
.GetChecked());
1207 #endif // wxUSE_CHECKBOX
1210 wxRadioButton
*radiobtn
= wxDynamicCast(this, wxRadioButton
);
1213 if ( event
.GetSetChecked() )
1214 radiobtn
->SetValue(event
.GetChecked());
1216 #endif // wxUSE_RADIOBTN
1220 // ----------------------------------------------------------------------------
1221 // dialog units translations
1222 // ----------------------------------------------------------------------------
1224 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1226 int charWidth
= GetCharWidth();
1227 int charHeight
= GetCharHeight();
1228 wxPoint
pt2(-1, -1);
1230 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1232 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1237 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1239 int charWidth
= GetCharWidth();
1240 int charHeight
= GetCharHeight();
1241 wxPoint
pt2(-1, -1);
1243 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1245 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1250 // ----------------------------------------------------------------------------
1252 // ----------------------------------------------------------------------------
1254 void wxWindowBase::DoSetClientObject( wxClientData
*data
)
1256 wxASSERT_MSG( m_clientDataType
!= ClientData_Void
,
1257 wxT("can't have both object and void client data") );
1259 if ( m_clientObject
)
1260 delete m_clientObject
;
1262 m_clientObject
= data
;
1263 m_clientDataType
= ClientData_Object
;
1266 wxClientData
*wxWindowBase::DoGetClientObject() const
1268 // it's not an error to call GetClientObject() on a window which doesn't
1269 // have client data at all - NULL will be returned
1270 wxASSERT_MSG( m_clientDataType
!= ClientData_Void
,
1271 wxT("this window doesn't have object client data") );
1273 return m_clientObject
;
1276 void wxWindowBase::DoSetClientData( void *data
)
1278 wxASSERT_MSG( m_clientDataType
!= ClientData_Object
,
1279 wxT("can't have both object and void client data") );
1281 m_clientData
= data
;
1282 m_clientDataType
= ClientData_Void
;
1285 void *wxWindowBase::DoGetClientData() const
1287 // it's not an error to call GetClientData() on a window which doesn't have
1288 // client data at all - NULL will be returned
1289 wxASSERT_MSG( m_clientDataType
!= ClientData_Object
,
1290 wxT("this window doesn't have void client data") );
1292 return m_clientData
;
1295 // ----------------------------------------------------------------------------
1297 // ----------------------------------------------------------------------------
1299 // propagate the colour change event to the subwindows
1300 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1302 wxWindowList::Node
*node
= GetChildren().GetFirst();
1305 // Only propagate to non-top-level windows
1306 wxWindow
*win
= node
->GetData();
1307 if ( !win
->IsTopLevel() )
1309 wxSysColourChangedEvent event2
;
1310 event
.m_eventObject
= win
;
1311 win
->GetEventHandler()->ProcessEvent(event2
);
1314 node
= node
->GetNext();
1318 // the default action is to populate dialog with data when it's created
1319 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1321 TransferDataToWindow();
1324 // ----------------------------------------------------------------------------
1325 // list classes implementation
1326 // ----------------------------------------------------------------------------
1328 void wxWindowListNode::DeleteData()
1330 delete (wxWindow
*)GetData();