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;
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 wxString
& name
)
159 // m_isWindow is set to TRUE in wxWindowBase::Init() as well as many other
160 // member variables - check that it has been called (will catch the case
161 // when a new ctor is added which doesn't call InitWindow)
162 wxASSERT_MSG( m_isWindow
, _T("Init() must have been called before!") );
164 // generate a new id if the user doesn't care about it
165 m_windowId
= id
== -1 ? NewControlId() : id
;
168 SetWindowStyleFlag(style
);
174 // ----------------------------------------------------------------------------
176 // ----------------------------------------------------------------------------
179 wxWindowBase::~wxWindowBase()
181 // FIXME if these 2 cases result from programming errors in the user code
182 // we should probably assert here instead of silently fixing them
184 // Just in case the window has been Closed, but we're then deleting
185 // immediately: don't leave dangling pointers.
186 wxPendingDelete
.DeleteObject(this);
188 // Just in case we've loaded a top-level window via LoadNativeDialog but
189 // we weren't a dialog class
190 wxTopLevelWindows
.DeleteObject(this);
192 wxASSERT_MSG( GetChildren().GetCount() == 0, _T("children not destroyed") );
197 #endif // wxUSE_CARET
200 if ( m_windowValidator
)
201 delete m_windowValidator
;
202 #endif // wxUSE_VALIDATORS
204 if ( m_clientObject
)
205 delete m_clientObject
;
207 #if wxUSE_CONSTRAINTS
208 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
209 // at deleted windows as they delete themselves.
210 DeleteRelatedConstraints();
214 // This removes any dangling pointers to this window in other windows'
215 // constraintsInvolvedIn lists.
216 UnsetConstraints(m_constraints
);
217 delete m_constraints
;
218 m_constraints
= NULL
;
222 delete m_windowSizer
;
224 // If this is a child of a sizer, remove self from parent
226 m_sizerParent
->RemoveChild(this);
227 #endif // wxUSE_CONSTRAINTS
229 #if wxUSE_DRAG_AND_DROP
232 #endif // wxUSE_DRAG_AND_DROP
237 #endif // wxUSE_TOOLTIPS
240 bool wxWindowBase::Destroy()
247 bool wxWindowBase::Close(bool force
)
249 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
250 event
.SetEventObject(this);
251 #if WXWIN_COMPATIBILITY
252 event
.SetForce(force
);
253 #endif // WXWIN_COMPATIBILITY
254 event
.SetCanVeto(!force
);
256 // return FALSE if window wasn't closed because the application vetoed the
258 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
261 bool wxWindowBase::DestroyChildren()
263 wxWindowList::Node
*node
;
266 // we iterate until the list becomes empty
267 node
= GetChildren().GetFirst();
271 wxWindow
*child
= node
->GetData();
273 wxASSERT_MSG( child
, _T("children list contains empty nodes") );
277 wxASSERT_MSG( !GetChildren().Find(child
),
278 _T("child didn't remove itself using RemoveChild()") );
284 // ----------------------------------------------------------------------------
285 // centre/fit the window
286 // ----------------------------------------------------------------------------
288 // centre the window with respect to its parent in either (or both) directions
289 void wxWindowBase::Centre(int direction
)
291 int widthParent
, heightParent
;
293 wxWindow
*parent
= GetParent();
296 parent
->GetClientSize(&widthParent
, &heightParent
);
300 // centre with respect to the whole screen
301 wxDisplaySize(&widthParent
, &heightParent
);
305 GetSize(&width
, &height
);
310 if ( direction
& wxHORIZONTAL
)
311 new_x
= (widthParent
- width
)/2;
313 if ( direction
& wxVERTICAL
)
314 new_y
= (heightParent
- height
)/2;
319 // fits the window around the children
320 void wxWindowBase::Fit()
325 wxWindowList::Node
*node
= GetChildren().GetFirst();
328 wxWindow
*win
= node
->GetData();
329 if ( win
->IsKindOf(CLASSINFO(wxFrame
)) ||
330 win
->IsKindOf(CLASSINFO(wxDialog
)) )
332 // dialogs and frames line in different top level windows - don't
333 // deal with them here
338 win
->GetPosition(&wx
, &wy
);
339 win
->GetSize(&ww
, &wh
);
340 if ( wx
+ ww
> maxX
)
342 if ( wy
+ wh
> maxY
)
345 node
= node
->GetNext();
349 SetClientSize(maxX
+ 7, maxY
+ 14);
352 // set the min/max size of the window
354 void wxWindowBase::SetSizeHints(int minW
, int minH
,
356 int WXUNUSED(incW
), int WXUNUSED(incH
))
364 // ----------------------------------------------------------------------------
365 // show/hide/enable/disable the window
366 // ----------------------------------------------------------------------------
368 bool wxWindowBase::Show(bool show
)
370 if ( show
!= m_isShown
)
382 bool wxWindowBase::Enable(bool enable
)
384 if ( enable
!= m_isEnabled
)
386 m_isEnabled
= enable
;
396 // ----------------------------------------------------------------------------
397 // reparenting the window
398 // ----------------------------------------------------------------------------
400 void wxWindowBase::AddChild(wxWindowBase
*child
)
402 wxCHECK_RET( child
, _T("can't add a NULL child") );
404 GetChildren().Append(child
);
405 child
->SetParent(this);
408 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
410 wxCHECK_RET( child
, _T("can't remove a NULL child") );
412 GetChildren().DeleteObject(child
);
413 child
->SetParent((wxWindow
*)NULL
);
416 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
418 wxWindow
*oldParent
= GetParent();
419 if ( newParent
== oldParent
)
425 // unlink this window from the existing parent.
428 oldParent
->RemoveChild(this);
432 wxTopLevelWindows
.DeleteObject(this);
435 // add it to the new one
438 newParent
->AddChild(this);
442 wxTopLevelWindows
.Append(this);
448 // ----------------------------------------------------------------------------
449 // event handler stuff
450 // ----------------------------------------------------------------------------
452 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
454 handler
->SetNextHandler(GetEventHandler());
455 SetEventHandler(handler
);
458 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
460 wxEvtHandler
*handlerA
= GetEventHandler();
463 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
464 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
465 SetEventHandler(handlerB
);
469 handlerA
= (wxEvtHandler
*)NULL
;
476 // ----------------------------------------------------------------------------
478 // ----------------------------------------------------------------------------
480 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
482 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
485 m_backgroundColour
= colour
;
490 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
492 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
495 m_foregroundColour
= colour
;
500 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
502 // don't try to set invalid cursor, always fall back to the default
503 const wxCursor
& cursorOk
= cursor
.Ok() ? cursor
: *wxSTANDARD_CURSOR
;
505 if ( cursorOk
== m_cursor
)
516 bool wxWindowBase::SetFont(const wxFont
& font
)
518 // don't try to set invalid font, always fall back to the default
519 const wxFont
& fontOk
= font
.Ok() ? font
: *wxSWISS_FONT
;
521 if ( fontOk
== m_font
)
533 void wxWindowBase::SetCaret(wxCaret
*caret
)
544 wxASSERT_MSG( m_caret
->GetWindow() == this,
545 "caret should be created associated to this window" );
548 #endif // wxUSE_CARET
551 // ----------------------------------------------------------------------------
553 // ----------------------------------------------------------------------------
555 void wxWindowBase::SetValidator(const wxValidator
& validator
)
557 if ( m_windowValidator
)
558 delete m_windowValidator
;
560 m_windowValidator
= (wxValidator
*)validator
.Clone();
562 if ( m_windowValidator
)
563 m_windowValidator
->SetWindow(this) ;
565 #endif // wxUSE_VALIDATORS
567 // ----------------------------------------------------------------------------
568 // update region testing
569 // ----------------------------------------------------------------------------
571 bool wxWindowBase::IsExposed(int x
, int y
) const
573 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
576 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
578 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
581 // ----------------------------------------------------------------------------
582 // find window by id or name
583 // ----------------------------------------------------------------------------
585 wxWindow
*wxWindowBase::FindWindow( long id
)
587 if ( id
== m_windowId
)
588 return (wxWindow
*)this;
590 wxWindowBase
*res
= (wxWindow
*)NULL
;
591 wxWindowList::Node
*node
;
592 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
594 wxWindowBase
*child
= node
->GetData();
595 res
= child
->FindWindow( id
);
598 return (wxWindow
*)res
;
601 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
603 if ( name
== m_windowName
)
604 return (wxWindow
*)this;
606 wxWindowBase
*res
= (wxWindow
*)NULL
;
607 wxWindowList::Node
*node
;
608 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
610 wxWindow
*child
= node
->GetData();
611 res
= child
->FindWindow(name
);
614 return (wxWindow
*)res
;
617 // ----------------------------------------------------------------------------
618 // dialog oriented functions
619 // ----------------------------------------------------------------------------
621 void wxWindowBase::MakeModal(bool WXUNUSED(modal
))
623 wxFAIL_MSG(_T("TODO"));
626 bool wxWindowBase::Validate()
629 wxWindowList::Node
*node
;
630 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
632 wxWindowBase
*child
= node
->GetData();
633 wxValidator
*validator
= child
->GetValidator();
634 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
639 #endif // wxUSE_VALIDATORS
644 bool wxWindowBase::TransferDataToWindow()
647 wxWindowList::Node
*node
;
648 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
650 wxWindowBase
*child
= node
->GetData();
651 wxValidator
*validator
= child
->GetValidator();
652 if ( validator
&& !validator
->TransferToWindow() )
654 wxLog
*log
= wxLog::GetActiveTarget();
657 wxLogWarning(_("Could not transfer data to window"));
664 #endif // wxUSE_VALIDATORS
669 bool wxWindowBase::TransferDataFromWindow()
672 wxWindowList::Node
*node
;
673 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
675 wxWindow
*child
= node
->GetData();
676 if ( child
->GetValidator() &&
677 !child
->GetValidator()->TransferFromWindow() )
682 #endif // wxUSE_VALIDATORS
687 void wxWindowBase::InitDialog()
689 wxInitDialogEvent
event(GetId());
690 event
.SetEventObject( this );
691 GetEventHandler()->ProcessEvent(event
);
694 // ----------------------------------------------------------------------------
696 // ----------------------------------------------------------------------------
700 void wxWindowBase::SetToolTip( const wxString
&tip
)
702 // don't create the new tooltip if we already have one
705 m_tooltip
->SetTip( tip
);
709 SetToolTip( new wxToolTip( tip
) );
712 // setting empty tooltip text does not remove the tooltip any more - use
713 // SetToolTip((wxToolTip *)NULL) for this
716 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
724 #endif // wxUSE_TOOLTIPS
726 // ----------------------------------------------------------------------------
727 // constraints and sizers
728 // ----------------------------------------------------------------------------
730 #if wxUSE_CONSTRAINTS
732 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
736 UnsetConstraints(m_constraints
);
737 delete m_constraints
;
739 m_constraints
= constraints
;
742 // Make sure other windows know they're part of a 'meaningful relationship'
743 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
744 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
745 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
746 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
747 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
748 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
749 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
750 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
751 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
752 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
753 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
754 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
755 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
756 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
757 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
758 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
762 // This removes any dangling pointers to this window in other windows'
763 // constraintsInvolvedIn lists.
764 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
768 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
769 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
770 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
771 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
772 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
773 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
774 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
775 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
776 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
777 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
778 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
779 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
780 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
781 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
782 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
783 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
787 // Back-pointer to other windows we're involved with, so if we delete this
788 // window, we must delete any constraints we're involved with.
789 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
791 if ( !m_constraintsInvolvedIn
)
792 m_constraintsInvolvedIn
= new wxWindowList
;
793 if ( !m_constraintsInvolvedIn
->Find(otherWin
) )
794 m_constraintsInvolvedIn
->Append(otherWin
);
797 // REMOVE back-pointer to other windows we're involved with.
798 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
800 if ( m_constraintsInvolvedIn
)
801 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
804 // Reset any constraints that mention this window
805 void wxWindowBase::DeleteRelatedConstraints()
807 if ( m_constraintsInvolvedIn
)
809 wxWindowList::Node
*node
= m_constraintsInvolvedIn
->GetFirst();
812 wxWindow
*win
= node
->GetData();
813 wxLayoutConstraints
*constr
= win
->GetConstraints();
815 // Reset any constraints involving this window
818 constr
->left
.ResetIfWin(this);
819 constr
->top
.ResetIfWin(this);
820 constr
->right
.ResetIfWin(this);
821 constr
->bottom
.ResetIfWin(this);
822 constr
->width
.ResetIfWin(this);
823 constr
->height
.ResetIfWin(this);
824 constr
->centreX
.ResetIfWin(this);
825 constr
->centreY
.ResetIfWin(this);
828 wxWindowList::Node
*next
= node
->GetNext();
833 delete m_constraintsInvolvedIn
;
834 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
838 void wxWindowBase::SetSizer(wxSizer
*sizer
)
840 m_windowSizer
= sizer
;
842 sizer
->SetSizerParent(this);
845 bool wxWindowBase::Layout()
847 if ( GetConstraints() )
850 GetClientSize(&w
, &h
);
851 GetConstraints()->width
.SetValue(w
);
852 GetConstraints()->height
.SetValue(h
);
855 // If top level (one sizer), evaluate the sizer's constraints.
859 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
860 GetSizer()->LayoutPhase1(&noChanges
);
861 GetSizer()->LayoutPhase2(&noChanges
);
862 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
867 // Otherwise, evaluate child constraints
868 ResetConstraints(); // Mark all constraints as unevaluated
869 DoPhase(1); // Just one phase need if no sizers involved
871 SetConstraintSizes(); // Recursively set the real window sizes
877 // Do a phase of evaluating constraints: the default behaviour. wxSizers may
878 // do a similar thing, but also impose their own 'constraints' and order the
879 // evaluation differently.
880 bool wxWindowBase::LayoutPhase1(int *noChanges
)
882 wxLayoutConstraints
*constr
= GetConstraints();
885 return constr
->SatisfyConstraints(this, noChanges
);
891 bool wxWindowBase::LayoutPhase2(int *noChanges
)
901 // Do a phase of evaluating child constraints
902 bool wxWindowBase::DoPhase(int phase
)
904 int noIterations
= 0;
905 int maxIterations
= 500;
908 wxWindowList succeeded
;
909 while ((noChanges
> 0) && (noIterations
< maxIterations
))
913 wxWindowList::Node
*node
= GetChildren().GetFirst();
916 wxWindow
*child
= node
->GetData();
917 if ( !child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)) )
919 wxLayoutConstraints
*constr
= child
->GetConstraints();
922 if ( !succeeded
.Find(child
) )
924 int tempNoChanges
= 0;
925 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
926 noChanges
+= tempNoChanges
;
929 succeeded
.Append(child
);
934 node
= node
->GetNext();
943 void wxWindowBase::ResetConstraints()
945 wxLayoutConstraints
*constr
= GetConstraints();
948 constr
->left
.SetDone(FALSE
);
949 constr
->top
.SetDone(FALSE
);
950 constr
->right
.SetDone(FALSE
);
951 constr
->bottom
.SetDone(FALSE
);
952 constr
->width
.SetDone(FALSE
);
953 constr
->height
.SetDone(FALSE
);
954 constr
->centreX
.SetDone(FALSE
);
955 constr
->centreY
.SetDone(FALSE
);
957 wxWindowList::Node
*node
= GetChildren().GetFirst();
960 wxWindow
*win
= node
->GetData();
961 if ( !win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)) )
962 win
->ResetConstraints();
963 node
= node
->GetNext();
967 // Need to distinguish between setting the 'fake' size for windows and sizers,
968 // and setting the real values.
969 void wxWindowBase::SetConstraintSizes(bool recurse
)
971 wxLayoutConstraints
*constr
= GetConstraints();
972 if ( constr
&& constr
->left
.GetDone() && constr
->right
.GetDone( ) &&
973 constr
->width
.GetDone() && constr
->height
.GetDone())
975 int x
= constr
->left
.GetValue();
976 int y
= constr
->top
.GetValue();
977 int w
= constr
->width
.GetValue();
978 int h
= constr
->height
.GetValue();
980 // If we don't want to resize this window, just move it...
981 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
982 (constr
->height
.GetRelationship() != wxAsIs
))
984 // Calls Layout() recursively. AAAGH. How can we stop that.
985 // Simply take Layout() out of non-top level OnSizes.
986 SizerSetSize(x
, y
, w
, h
);
995 wxChar
*windowClass
= GetClassInfo()->GetClassName();
998 if ( GetName() == _T("") )
999 winName
= _T("unnamed");
1001 winName
= GetName();
1002 wxLogDebug( _T("Constraint(s) not satisfied for window of type %s, name %s:\n"),
1003 (const wxChar
*)windowClass
,
1004 (const wxChar
*)winName
);
1005 if ( !constr
->left
.GetDone()) wxLogDebug( _T(" unsatisfied 'left' constraint.\n") );
1006 if ( !constr
->right
.GetDone()) wxLogDebug( _T(" unsatisfied 'right' constraint.\n") );
1007 if ( !constr
->width
.GetDone()) wxLogDebug( _T(" unsatisfied 'width' constraint.\n") );
1008 if ( !constr
->height
.GetDone()) wxLogDebug( _T(" unsatisfied 'height' constraint.\n") );
1009 wxLogDebug( _T("Please check constraints: try adding AsIs() constraints.\n") );
1014 wxWindowList::Node
*node
= GetChildren().GetFirst();
1017 wxWindow
*win
= node
->GetData();
1018 if ( !win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)) )
1019 win
->SetConstraintSizes();
1020 node
= node
->GetNext();
1025 // This assumes that all sizers are 'on' the same window, i.e. the parent of
1027 void wxWindowBase::TransformSizerToActual(int *x
, int *y
) const
1029 if ( !m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
) ) ||
1030 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
1034 m_sizerParent
->GetPosition(&xp
, &yp
);
1035 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
1040 void wxWindowBase::SizerSetSize(int x
, int y
, int w
, int h
)
1044 TransformSizerToActual(&xx
, &yy
);
1045 SetSize(xx
, yy
, w
, h
);
1048 void wxWindowBase::SizerMove(int x
, int y
)
1052 TransformSizerToActual(&xx
, &yy
);
1056 // Only set the size/position of the constraint (if any)
1057 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1059 wxLayoutConstraints
*constr
= GetConstraints();
1064 constr
->left
.SetValue(x
);
1065 constr
->left
.SetDone(TRUE
);
1069 constr
->top
.SetValue(y
);
1070 constr
->top
.SetDone(TRUE
);
1074 constr
->width
.SetValue(w
);
1075 constr
->width
.SetDone(TRUE
);
1079 constr
->height
.SetValue(h
);
1080 constr
->height
.SetDone(TRUE
);
1085 void wxWindowBase::MoveConstraint(int x
, int y
)
1087 wxLayoutConstraints
*constr
= GetConstraints();
1092 constr
->left
.SetValue(x
);
1093 constr
->left
.SetDone(TRUE
);
1097 constr
->top
.SetValue(y
);
1098 constr
->top
.SetDone(TRUE
);
1103 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1105 wxLayoutConstraints
*constr
= GetConstraints();
1108 *w
= constr
->width
.GetValue();
1109 *h
= constr
->height
.GetValue();
1115 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1117 wxLayoutConstraints
*constr
= GetConstraints();
1120 *w
= constr
->width
.GetValue();
1121 *h
= constr
->height
.GetValue();
1124 GetClientSize(w
, h
);
1127 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1129 wxLayoutConstraints
*constr
= GetConstraints();
1132 *x
= constr
->left
.GetValue();
1133 *y
= constr
->top
.GetValue();
1139 #endif // wxUSE_CONSTRAINTS
1141 // ----------------------------------------------------------------------------
1142 // do Update UI processing for child controls
1143 // ----------------------------------------------------------------------------
1145 // TODO: should this be implemented for the child window rather
1146 // than the parent? Then you can override it e.g. for wxCheckBox
1147 // to do the Right Thing rather than having to assume a fixed number
1148 // of control classes.
1149 void wxWindowBase::UpdateWindowUI()
1151 wxWindowID id
= GetId();
1154 wxUpdateUIEvent
event(id
);
1155 event
.m_eventObject
= this;
1157 if ( GetEventHandler()->ProcessEvent(event
) )
1159 if ( event
.GetSetEnabled() )
1160 Enable(event
.GetEnabled());
1162 if ( event
.GetSetText() && IsKindOf(CLASSINFO(wxControl
)) )
1163 ((wxControl
*)this)->SetLabel(event
.GetText());
1166 if ( IsKindOf(CLASSINFO(wxCheckBox
)) )
1168 if ( event
.GetSetChecked() )
1169 ((wxCheckBox
*)this)->SetValue(event
.GetChecked());
1171 #endif // wxUSE_CHECKBOX
1173 #if wxUSE_RADIOBUTTON
1174 if ( IsKindOf(CLASSINFO(wxRadioButton
)) )
1176 if ( event
.GetSetChecked() )
1177 ((wxRadioButton
*) this)->SetValue(event
.GetChecked());
1179 #endif // wxUSE_RADIOBUTTON
1184 // ----------------------------------------------------------------------------
1185 // dialog units translations
1186 // ----------------------------------------------------------------------------
1188 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1190 int charWidth
= GetCharWidth();
1191 int charHeight
= GetCharHeight();
1193 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1194 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1199 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1201 int charWidth
= GetCharWidth();
1202 int charHeight
= GetCharHeight();
1204 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1205 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1210 // ----------------------------------------------------------------------------
1212 // ----------------------------------------------------------------------------
1214 // propagate the colour change event to the subwindows
1215 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1217 wxWindowList::Node
*node
= GetChildren().GetFirst();
1220 // Only propagate to non-top-level windows
1221 wxWindow
*win
= node
->GetData();
1222 if ( !win
->IsTopLevel() )
1224 wxSysColourChangedEvent event2
;
1225 event
.m_eventObject
= win
;
1226 win
->GetEventHandler()->ProcessEvent(event2
);
1229 node
= node
->GetNext();
1233 // the default action is to populate dialog with data when it's created
1234 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1236 TransferDataToWindow();
1239 // ----------------------------------------------------------------------------
1240 // list classes implementation
1241 // ----------------------------------------------------------------------------
1243 void wxWindowListNode::DeleteData()
1245 delete (wxWindow
*)GetData();