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
104 m_clientObject
= (wxClientData
*)NULL
;
107 // the default event handler is just this window
108 m_eventHandler
= this;
111 m_windowValidator
= (wxValidator
*) NULL
;
113 // use the system default colours
114 wxSystemSettings settings
;
116 m_backgroundColour
= settings
.GetSystemColour(wxSYS_COLOUR_BTNFACE
);
117 m_foregroundColour
= *wxBLACK
; // TODO take this from sys settings too?
118 m_font
= *wxSWISS_FONT
; // and this?
123 // an optimization for the event processing: checking this flag is much
124 // faster than using IsKindOf(CLASSINFO(wxWindow))
127 #if wxUSE_CONSTRAINTS
128 // no constraints whatsoever
129 m_constraints
= (wxLayoutConstraints
*) NULL
;
130 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
131 m_windowSizer
= (wxSizer
*) NULL
;
132 m_sizerParent
= (wxWindowBase
*) NULL
;
133 m_autoLayout
= FALSE
;
134 #endif // wxUSE_CONSTRAINTS
136 #if wxUSE_DRAG_AND_DROP
137 m_dropTarget
= (wxDropTarget
*)NULL
;
138 #endif // wxUSE_DRAG_AND_DROP
141 m_tooltip
= (wxToolTip
*)NULL
;
142 #endif // wxUSE_TOOLTIPS
145 m_caret
= (wxCaret
*)NULL
;
146 #endif // wxUSE_CARET
149 // common part of window creation process
150 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
152 const wxPoint
& WXUNUSED(pos
),
153 const wxSize
& WXUNUSED(size
),
155 const wxString
& name
)
157 // m_isWindow is set to TRUE in wxWindowBase::Init() as well as many other
158 // member variables - check that it has been called (will catch the case
159 // when a new ctor is added which doesn't call InitWindow)
160 wxASSERT_MSG( m_isWindow
, _T("Init() must have been called before!") );
162 // generate a new id if the user doesn't care about it
163 m_windowId
= id
== -1 ? NewControlId() : id
;
166 SetWindowStyleFlag(style
);
172 // ----------------------------------------------------------------------------
174 // ----------------------------------------------------------------------------
177 wxWindowBase::~wxWindowBase()
179 // FIXME if these 2 cases result from programming errors in the user code
180 // we should probably assert here instead of silently fixing them
182 // Just in case the window has been Closed, but we're then deleting
183 // immediately: don't leave dangling pointers.
184 wxPendingDelete
.DeleteObject(this);
186 // Just in case we've loaded a top-level window via LoadNativeDialog but
187 // we weren't a dialog class
188 wxTopLevelWindows
.DeleteObject(this);
190 wxASSERT_MSG( GetChildren().GetCount() == 0, _T("children not destroyed") );
195 #endif // wxUSE_CARET
197 if ( m_windowValidator
)
198 delete m_windowValidator
;
200 if ( m_clientObject
)
201 delete m_clientObject
;
203 #if wxUSE_CONSTRAINTS
204 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
205 // at deleted windows as they delete themselves.
206 DeleteRelatedConstraints();
210 // This removes any dangling pointers to this window in other windows'
211 // constraintsInvolvedIn lists.
212 UnsetConstraints(m_constraints
);
213 delete m_constraints
;
214 m_constraints
= NULL
;
218 delete m_windowSizer
;
220 // If this is a child of a sizer, remove self from parent
222 m_sizerParent
->RemoveChild(this);
223 #endif // wxUSE_CONSTRAINTS
225 #if wxUSE_DRAG_AND_DROP
228 #endif // wxUSE_DRAG_AND_DROP
233 #endif // wxUSE_TOOLTIPS
236 bool wxWindowBase::Destroy()
243 bool wxWindowBase::Close(bool force
)
245 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
246 event
.SetEventObject(this);
247 #if WXWIN_COMPATIBILITY
248 event
.SetForce(force
);
249 #endif // WXWIN_COMPATIBILITY
250 event
.SetCanVeto(!force
);
252 // return FALSE if window wasn't closed because the application vetoed the
254 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
257 bool wxWindowBase::DestroyChildren()
259 wxWindowList::Node
*node
;
262 // we iterate until the list becomes empty
263 node
= GetChildren().GetFirst();
267 wxWindow
*child
= node
->GetData();
269 wxASSERT_MSG( child
, _T("children list contains empty nodes") );
273 wxASSERT_MSG( !GetChildren().Find(child
),
274 _T("child didn't remove itself using RemoveChild()") );
280 // ----------------------------------------------------------------------------
281 // centre/fit the window
282 // ----------------------------------------------------------------------------
284 // centre the window with respect to its parent in either (or both) directions
285 void wxWindowBase::Centre(int direction
)
287 int widthParent
, heightParent
;
289 wxWindow
*parent
= GetParent();
292 parent
->GetClientSize(&widthParent
, &heightParent
);
296 // centre with respect to the whole screen
297 wxDisplaySize(&widthParent
, &heightParent
);
301 GetSize(&width
, &height
);
306 if ( direction
& wxHORIZONTAL
)
307 new_x
= (widthParent
- width
)/2;
309 if ( direction
& wxVERTICAL
)
310 new_y
= (heightParent
- height
)/2;
315 // fits the window around the children
316 void wxWindowBase::Fit()
321 wxWindowList::Node
*node
= GetChildren().GetFirst();
324 wxWindow
*win
= node
->GetData();
325 if ( win
->IsKindOf(CLASSINFO(wxFrame
)) ||
326 win
->IsKindOf(CLASSINFO(wxDialog
)) )
328 // dialogs and frames line in different top level windows - don't
329 // deal with them here
334 win
->GetPosition(&wx
, &wy
);
335 win
->GetSize(&ww
, &wh
);
336 if ( wx
+ ww
> maxX
)
338 if ( wy
+ wh
> maxY
)
341 node
= node
->GetNext();
345 SetClientSize(maxX
+ 7, maxY
+ 14);
348 // set the min/max size of the window
350 void wxWindowBase::SetSizeHints(int minW
, int minH
,
352 int WXUNUSED(incW
), int WXUNUSED(incH
))
360 // ----------------------------------------------------------------------------
361 // show/hide/enable/disable the window
362 // ----------------------------------------------------------------------------
364 bool wxWindowBase::Show(bool show
)
366 if ( show
!= m_isShown
)
378 bool wxWindowBase::Enable(bool enable
)
380 if ( enable
!= m_isEnabled
)
382 m_isEnabled
= enable
;
392 // ----------------------------------------------------------------------------
393 // reparenting the window
394 // ----------------------------------------------------------------------------
396 void wxWindowBase::AddChild(wxWindowBase
*child
)
398 wxCHECK_RET( child
, _T("can't add a NULL child") );
400 GetChildren().Append(child
);
401 child
->SetParent(this);
404 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
406 wxCHECK_RET( child
, _T("can't remove a NULL child") );
408 GetChildren().DeleteObject(child
);
409 child
->SetParent((wxWindow
*)NULL
);
412 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
414 wxWindow
*oldParent
= GetParent();
415 if ( newParent
== oldParent
)
421 // unlink this window from the existing parent.
424 oldParent
->RemoveChild(this);
428 wxTopLevelWindows
.DeleteObject(this);
431 // add it to the new one
434 newParent
->AddChild(this);
438 wxTopLevelWindows
.Append(this);
444 // ----------------------------------------------------------------------------
445 // event handler stuff
446 // ----------------------------------------------------------------------------
448 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
450 handler
->SetNextHandler(GetEventHandler());
451 SetEventHandler(handler
);
454 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
456 wxEvtHandler
*handlerA
= GetEventHandler();
459 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
460 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
461 SetEventHandler(handlerB
);
465 handlerA
= (wxEvtHandler
*)NULL
;
472 // ----------------------------------------------------------------------------
474 // ----------------------------------------------------------------------------
476 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
478 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
481 m_backgroundColour
= colour
;
486 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
488 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
491 m_foregroundColour
= colour
;
496 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
498 // don't try to set invalid cursor, always fall back to the default
499 const wxCursor
& cursorOk
= cursor
.Ok() ? cursor
: *wxSTANDARD_CURSOR
;
501 if ( cursorOk
== m_cursor
)
512 bool wxWindowBase::SetFont(const wxFont
& font
)
514 // don't try to set invalid font, always fall back to the default
515 const wxFont
& fontOk
= font
.Ok() ? font
: *wxSWISS_FONT
;
517 if ( fontOk
== m_font
)
529 void wxWindowBase::SetCaret(wxCaret
*caret
)
540 wxASSERT_MSG( m_caret
->GetWindow() == this,
541 "caret should be created associated to this window" );
544 #endif // wxUSE_CARET
546 // ----------------------------------------------------------------------------
548 // ----------------------------------------------------------------------------
550 void wxWindowBase::SetValidator(const wxValidator
& validator
)
552 if ( m_windowValidator
)
553 delete m_windowValidator
;
555 m_windowValidator
= (wxValidator
*)validator
.Clone();
557 if ( m_windowValidator
)
558 m_windowValidator
->SetWindow(this) ;
561 // ----------------------------------------------------------------------------
562 // update region testing
563 // ----------------------------------------------------------------------------
565 bool wxWindowBase::IsExposed(int x
, int y
) const
567 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
570 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
572 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
575 // ----------------------------------------------------------------------------
576 // find window by id or name
577 // ----------------------------------------------------------------------------
579 wxWindow
*wxWindowBase::FindWindow( long id
)
581 if ( id
== m_windowId
)
582 return (wxWindow
*)this;
584 wxWindowBase
*res
= (wxWindow
*)NULL
;
585 wxWindowList::Node
*node
;
586 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
588 wxWindowBase
*child
= node
->GetData();
589 res
= child
->FindWindow( id
);
592 return (wxWindow
*)res
;
595 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
597 if ( name
== m_windowName
)
598 return (wxWindow
*)this;
600 wxWindowBase
*res
= (wxWindow
*)NULL
;
601 wxWindowList::Node
*node
;
602 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
604 wxWindow
*child
= node
->GetData();
605 res
= child
->FindWindow(name
);
608 return (wxWindow
*)res
;
611 // ----------------------------------------------------------------------------
612 // dialog oriented functions
613 // ----------------------------------------------------------------------------
615 void wxWindowBase::MakeModal(bool WXUNUSED(modal
))
617 wxFAIL_MSG(_T("TODO"));
620 bool wxWindowBase::Validate()
622 wxWindowList::Node
*node
;
623 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
625 wxWindowBase
*child
= node
->GetData();
626 wxValidator
*validator
= child
->GetValidator();
627 if ( validator
&& validator
->Validate(this) )
636 bool wxWindowBase::TransferDataToWindow()
638 wxWindowList::Node
*node
;
639 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
641 wxWindowBase
*child
= node
->GetData();
642 wxValidator
*validator
= child
->GetValidator();
643 if ( validator
&& !validator
->TransferToWindow() )
645 wxLog
*log
= wxLog::GetActiveTarget();
648 wxLogWarning(_("Could not transfer data to window"));
659 bool wxWindowBase::TransferDataFromWindow()
661 wxWindowList::Node
*node
;
662 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
664 wxWindow
*child
= node
->GetData();
665 if ( child
->GetValidator() &&
666 !child
->GetValidator()->TransferFromWindow() )
675 void wxWindowBase::InitDialog()
677 wxInitDialogEvent
event(GetId());
678 event
.SetEventObject( this );
679 GetEventHandler()->ProcessEvent(event
);
682 // ----------------------------------------------------------------------------
684 // ----------------------------------------------------------------------------
688 void wxWindowBase::SetToolTip( const wxString
&tip
)
690 // don't create the new tooltip if we already have one
693 m_tooltip
->SetTip( tip
);
697 SetToolTip( new wxToolTip( tip
) );
700 // setting empty tooltip text does not remove the tooltip any more - use
701 // SetToolTip((wxToolTip *)NULL) for this
704 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
712 #endif // wxUSE_TOOLTIPS
714 // ----------------------------------------------------------------------------
715 // constraints and sizers
716 // ----------------------------------------------------------------------------
718 #if wxUSE_CONSTRAINTS
720 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
724 UnsetConstraints(m_constraints
);
725 delete m_constraints
;
727 m_constraints
= constraints
;
730 // Make sure other windows know they're part of a 'meaningful relationship'
731 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
732 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
733 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
734 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
735 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
736 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
737 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
738 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
739 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
740 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
741 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
742 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
743 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
744 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
745 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
746 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
750 // This removes any dangling pointers to this window in other windows'
751 // constraintsInvolvedIn lists.
752 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
756 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
757 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
758 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
759 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
760 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
761 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
762 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
763 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
764 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
765 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
766 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
767 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
768 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
769 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
770 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
771 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
775 // Back-pointer to other windows we're involved with, so if we delete this
776 // window, we must delete any constraints we're involved with.
777 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
779 if ( !m_constraintsInvolvedIn
)
780 m_constraintsInvolvedIn
= new wxWindowList
;
781 if ( !m_constraintsInvolvedIn
->Find(otherWin
) )
782 m_constraintsInvolvedIn
->Append(otherWin
);
785 // REMOVE back-pointer to other windows we're involved with.
786 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
788 if ( m_constraintsInvolvedIn
)
789 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
792 // Reset any constraints that mention this window
793 void wxWindowBase::DeleteRelatedConstraints()
795 if ( m_constraintsInvolvedIn
)
797 wxWindowList::Node
*node
= m_constraintsInvolvedIn
->GetFirst();
800 wxWindow
*win
= node
->GetData();
801 wxLayoutConstraints
*constr
= win
->GetConstraints();
803 // Reset any constraints involving this window
806 constr
->left
.ResetIfWin(this);
807 constr
->top
.ResetIfWin(this);
808 constr
->right
.ResetIfWin(this);
809 constr
->bottom
.ResetIfWin(this);
810 constr
->width
.ResetIfWin(this);
811 constr
->height
.ResetIfWin(this);
812 constr
->centreX
.ResetIfWin(this);
813 constr
->centreY
.ResetIfWin(this);
816 wxWindowList::Node
*next
= node
->GetNext();
821 delete m_constraintsInvolvedIn
;
822 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
826 void wxWindowBase::SetSizer(wxSizer
*sizer
)
828 m_windowSizer
= sizer
;
830 sizer
->SetSizerParent(this);
833 bool wxWindowBase::Layout()
835 if ( GetConstraints() )
838 GetClientSize(&w
, &h
);
839 GetConstraints()->width
.SetValue(w
);
840 GetConstraints()->height
.SetValue(h
);
843 // If top level (one sizer), evaluate the sizer's constraints.
847 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
848 GetSizer()->LayoutPhase1(&noChanges
);
849 GetSizer()->LayoutPhase2(&noChanges
);
850 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
855 // Otherwise, evaluate child constraints
856 ResetConstraints(); // Mark all constraints as unevaluated
857 DoPhase(1); // Just one phase need if no sizers involved
859 SetConstraintSizes(); // Recursively set the real window sizes
865 // Do a phase of evaluating constraints: the default behaviour. wxSizers may
866 // do a similar thing, but also impose their own 'constraints' and order the
867 // evaluation differently.
868 bool wxWindowBase::LayoutPhase1(int *noChanges
)
870 wxLayoutConstraints
*constr
= GetConstraints();
873 return constr
->SatisfyConstraints(this, noChanges
);
879 bool wxWindowBase::LayoutPhase2(int *noChanges
)
889 // Do a phase of evaluating child constraints
890 bool wxWindowBase::DoPhase(int phase
)
892 int noIterations
= 0;
893 int maxIterations
= 500;
896 wxWindowList succeeded
;
897 while ((noChanges
> 0) && (noIterations
< maxIterations
))
901 wxWindowList::Node
*node
= GetChildren().GetFirst();
904 wxWindow
*child
= node
->GetData();
905 if ( !child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)) )
907 wxLayoutConstraints
*constr
= child
->GetConstraints();
910 if ( !succeeded
.Find(child
) )
912 int tempNoChanges
= 0;
913 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
914 noChanges
+= tempNoChanges
;
917 succeeded
.Append(child
);
922 node
= node
->GetNext();
931 void wxWindowBase::ResetConstraints()
933 wxLayoutConstraints
*constr
= GetConstraints();
936 constr
->left
.SetDone(FALSE
);
937 constr
->top
.SetDone(FALSE
);
938 constr
->right
.SetDone(FALSE
);
939 constr
->bottom
.SetDone(FALSE
);
940 constr
->width
.SetDone(FALSE
);
941 constr
->height
.SetDone(FALSE
);
942 constr
->centreX
.SetDone(FALSE
);
943 constr
->centreY
.SetDone(FALSE
);
945 wxWindowList::Node
*node
= GetChildren().GetFirst();
948 wxWindow
*win
= node
->GetData();
949 if ( !win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)) )
950 win
->ResetConstraints();
951 node
= node
->GetNext();
955 // Need to distinguish between setting the 'fake' size for windows and sizers,
956 // and setting the real values.
957 void wxWindowBase::SetConstraintSizes(bool recurse
)
959 wxLayoutConstraints
*constr
= GetConstraints();
960 if ( constr
&& constr
->left
.GetDone() && constr
->right
.GetDone( ) &&
961 constr
->width
.GetDone() && constr
->height
.GetDone())
963 int x
= constr
->left
.GetValue();
964 int y
= constr
->top
.GetValue();
965 int w
= constr
->width
.GetValue();
966 int h
= constr
->height
.GetValue();
968 // If we don't want to resize this window, just move it...
969 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
970 (constr
->height
.GetRelationship() != wxAsIs
))
972 // Calls Layout() recursively. AAAGH. How can we stop that.
973 // Simply take Layout() out of non-top level OnSizes.
974 SizerSetSize(x
, y
, w
, h
);
983 wxChar
*windowClass
= GetClassInfo()->GetClassName();
986 if ( GetName() == _T("") )
987 winName
= _T("unnamed");
990 wxLogDebug( _T("Constraint(s) not satisfied for window of type %s, name %s:\n"),
991 (const wxChar
*)windowClass
,
992 (const wxChar
*)winName
);
993 if ( !constr
->left
.GetDone()) wxLogDebug( _T(" unsatisfied 'left' constraint.\n") );
994 if ( !constr
->right
.GetDone()) wxLogDebug( _T(" unsatisfied 'right' constraint.\n") );
995 if ( !constr
->width
.GetDone()) wxLogDebug( _T(" unsatisfied 'width' constraint.\n") );
996 if ( !constr
->height
.GetDone()) wxLogDebug( _T(" unsatisfied 'height' constraint.\n") );
997 wxLogDebug( _T("Please check constraints: try adding AsIs() constraints.\n") );
1002 wxWindowList::Node
*node
= GetChildren().GetFirst();
1005 wxWindow
*win
= node
->GetData();
1006 if ( !win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)) )
1007 win
->SetConstraintSizes();
1008 node
= node
->GetNext();
1013 // This assumes that all sizers are 'on' the same window, i.e. the parent of
1015 void wxWindowBase::TransformSizerToActual(int *x
, int *y
) const
1017 if ( !m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
) ) ||
1018 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
1022 m_sizerParent
->GetPosition(&xp
, &yp
);
1023 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
1028 void wxWindowBase::SizerSetSize(int x
, int y
, int w
, int h
)
1032 TransformSizerToActual(&xx
, &yy
);
1033 SetSize(xx
, yy
, w
, h
);
1036 void wxWindowBase::SizerMove(int x
, int y
)
1040 TransformSizerToActual(&xx
, &yy
);
1044 // Only set the size/position of the constraint (if any)
1045 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1047 wxLayoutConstraints
*constr
= GetConstraints();
1052 constr
->left
.SetValue(x
);
1053 constr
->left
.SetDone(TRUE
);
1057 constr
->top
.SetValue(y
);
1058 constr
->top
.SetDone(TRUE
);
1062 constr
->width
.SetValue(w
);
1063 constr
->width
.SetDone(TRUE
);
1067 constr
->height
.SetValue(h
);
1068 constr
->height
.SetDone(TRUE
);
1073 void wxWindowBase::MoveConstraint(int x
, int y
)
1075 wxLayoutConstraints
*constr
= GetConstraints();
1080 constr
->left
.SetValue(x
);
1081 constr
->left
.SetDone(TRUE
);
1085 constr
->top
.SetValue(y
);
1086 constr
->top
.SetDone(TRUE
);
1091 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1093 wxLayoutConstraints
*constr
= GetConstraints();
1096 *w
= constr
->width
.GetValue();
1097 *h
= constr
->height
.GetValue();
1103 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1105 wxLayoutConstraints
*constr
= GetConstraints();
1108 *w
= constr
->width
.GetValue();
1109 *h
= constr
->height
.GetValue();
1112 GetClientSize(w
, h
);
1115 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1117 wxLayoutConstraints
*constr
= GetConstraints();
1120 *x
= constr
->left
.GetValue();
1121 *y
= constr
->top
.GetValue();
1127 #endif // wxUSE_CONSTRAINTS
1129 // ----------------------------------------------------------------------------
1130 // do Update UI processing for child controls
1131 // ----------------------------------------------------------------------------
1133 // TODO: should this be implemented for the child window rather
1134 // than the parent? Then you can override it e.g. for wxCheckBox
1135 // to do the Right Thing rather than having to assume a fixed number
1136 // of control classes.
1137 void wxWindowBase::UpdateWindowUI()
1139 wxWindowID id
= GetId();
1142 wxUpdateUIEvent
event(id
);
1143 event
.m_eventObject
= this;
1145 if ( GetEventHandler()->ProcessEvent(event
) )
1147 if ( event
.GetSetEnabled() )
1148 Enable(event
.GetEnabled());
1150 if ( event
.GetSetText() && IsKindOf(CLASSINFO(wxControl
)) )
1151 ((wxControl
*)this)->SetLabel(event
.GetText());
1153 if ( IsKindOf(CLASSINFO(wxCheckBox
)) )
1155 if ( event
.GetSetChecked() )
1156 ((wxCheckBox
*)this)->SetValue(event
.GetChecked());
1158 else if ( IsKindOf(CLASSINFO(wxRadioButton
)) )
1160 if ( event
.GetSetChecked() )
1161 ((wxRadioButton
*) this)->SetValue(event
.GetChecked());
1167 // ----------------------------------------------------------------------------
1168 // dialog units translations
1169 // ----------------------------------------------------------------------------
1171 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1173 int charWidth
= GetCharWidth();
1174 int charHeight
= GetCharHeight();
1176 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1177 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1182 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1184 int charWidth
= GetCharWidth();
1185 int charHeight
= GetCharHeight();
1187 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1188 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1193 // ----------------------------------------------------------------------------
1195 // ----------------------------------------------------------------------------
1197 // propagate the colour change event to the subwindows
1198 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1200 wxWindowList::Node
*node
= GetChildren().GetFirst();
1203 // Only propagate to non-top-level windows
1204 wxWindow
*win
= node
->GetData();
1205 if ( !win
->IsTopLevel() )
1207 wxSysColourChangedEvent event2
;
1208 event
.m_eventObject
= win
;
1209 win
->GetEventHandler()->ProcessEvent(event2
);
1212 node
= node
->GetNext();
1216 // the default action is to populate dialog with data when it's created
1217 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1219 TransferDataToWindow();
1222 // ----------------------------------------------------------------------------
1223 // list classes implementation
1224 // ----------------------------------------------------------------------------
1226 void wxWindowListNode::DeleteData()
1228 delete (wxWindow
*)GetData();