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 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
28 #include "wx/string.h"
33 #include "wx/window.h"
34 #include "wx/checkbox.h"
35 #include "wx/radiobut.h"
36 #include "wx/settings.h"
37 #include "wx/dialog.h"
41 #include "wx/layout.h"
42 #endif // wxUSE_CONSTRAINTS
44 #if wxUSE_DRAG_AND_DROP
46 #endif // wxUSE_DRAG_AND_DROP
49 #include "wx/tooltip.h"
50 #endif // wxUSE_TOOLTIPS
52 // ----------------------------------------------------------------------------
54 // ----------------------------------------------------------------------------
56 int wxWindowBase::ms_lastControlId
= 0;
58 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
60 // ----------------------------------------------------------------------------
62 // ----------------------------------------------------------------------------
64 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
65 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
66 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
69 // ============================================================================
70 // implementation of the common functionality of the wxWindow class
71 // ============================================================================
73 // ----------------------------------------------------------------------------
75 // ----------------------------------------------------------------------------
77 // the default initialization
78 void wxWindowBase::InitBase()
80 // no window yet, no parent nor children
81 m_widget
= (WXWidget
)0;
82 m_parent
= (wxWindow
*)NULL
;
84 m_children
.DeleteContents( FALSE
); // don't auto delete node data
86 // no constraints on the minimal window size
92 // window is created enabled but it's not visible yet
97 m_clientObject
= (wxClientData
*)NULL
;
100 // the default event handler is just this window
101 m_eventHandler
= this;
104 m_windowValidator
= (wxValidator
*) NULL
;
106 // use the system default colours
107 wxSystemSettings settings
;
109 m_backgroundColour
= settings
.GetSystemColour(wxSYS_COLOUR_BTNFACE
);
110 m_foregroundColour
= *wxBLACK
; // TODO take this from sys settings too?
111 m_font
= *wxSWISS_FONT
; // and this?
116 // an optimization for the event processing: checking this flag is much
117 // faster than using IsKindOf(CLASSINFO(wxWindow))
120 #if wxUSE_CONSTRAINTS
121 // no constraints whatsoever
122 m_constraints
= (wxLayoutConstraints
*) NULL
;
123 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
124 m_windowSizer
= (wxSizer
*) NULL
;
125 m_sizerParent
= (wxWindowBase
*) NULL
;
126 m_autoLayout
= FALSE
;
127 #endif // wxUSE_CONSTRAINTS
129 #if wxUSE_DRAG_AND_DROP
130 m_dropTarget
= (wxDropTarget
*)NULL
;
131 #endif // wxUSE_DRAG_AND_DROP
134 m_tooltip
= (wxToolTip
*)NULL
;
135 #endif // wxUSE_TOOLTIPS
138 // common part of window creation process
139 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
144 const wxString
& name
)
146 // m_isWindow is set to TRUE in wxWindowBase::Init() as well as many other
147 // member variables - check that it has been called (will catch the case
148 // when a new ctor is added which doesn't call InitWindow)
149 wxASSERT_MSG( m_isWindow
, _T("Init() must have been called before!") );
151 // generate a new id if the user doesn't care about it
152 m_windowId
= id
== -1 ? NewControlId() : id
;
155 SetWindowStyleFlag(style
);
161 // ----------------------------------------------------------------------------
163 // ----------------------------------------------------------------------------
166 wxWindowBase::~wxWindowBase()
168 // FIXME if these 2 cases result from programming errors in the user code
169 // we should probably assert here instead of silently fixing them
171 // Just in case the window has been Closed, but we're then deleting
172 // immediately: don't leave dangling pointers.
173 wxPendingDelete
.DeleteObject(this);
175 // Just in case we've loaded a top-level window via LoadNativeDialog but
176 // we weren't a dialog class
177 wxTopLevelWindows
.DeleteObject(this);
181 if ( m_windowValidator
)
182 delete m_windowValidator
;
184 if ( m_clientObject
)
185 delete m_clientObject
;
187 #if wxUSE_CONSTRAINTS
188 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
189 // at deleted windows as they delete themselves.
190 DeleteRelatedConstraints();
194 // This removes any dangling pointers to this window in other windows'
195 // constraintsInvolvedIn lists.
196 UnsetConstraints(m_constraints
);
197 delete m_constraints
;
198 m_constraints
= NULL
;
202 delete m_windowSizer
;
204 // If this is a child of a sizer, remove self from parent
206 m_sizerParent
->RemoveChild(this);
207 #endif // wxUSE_CONSTRAINTS
209 #if wxUSE_DRAG_AND_DROP
212 #endif // wxUSE_DRAG_AND_DROP
217 #endif // wxUSE_TOOLTIPS
220 bool wxWindowBase::Destroy()
227 bool wxWindowBase::Close(bool force
)
229 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
230 event
.SetEventObject(this);
231 #if WXWIN_COMPATIBILITY
232 event
.SetForce(force
);
233 #endif // WXWIN_COMPATIBILITY
234 event
.SetCanVeto(!force
);
236 // return FALSE if window wasn't closed because the application vetoed the
238 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
241 bool wxWindowBase::DestroyChildren()
243 wxWindowList::Node
*node
;
244 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
246 wxWindow
*child
= node
->GetData();
257 // ----------------------------------------------------------------------------
258 // centre/fit the window
259 // ----------------------------------------------------------------------------
261 // centre the window with respect to its parent in either (or both) directions
262 void wxWindowBase::Centre(int direction
)
264 int widthParent
, heightParent
;
266 wxWindow
*parent
= GetParent();
269 parent
->GetClientSize(&widthParent
, &heightParent
);
273 // centre with respect to the whole screen
274 wxDisplaySize(&widthParent
, &heightParent
);
278 GetSize(&width
, &height
);
283 if ( direction
& wxHORIZONTAL
)
284 new_x
= (widthParent
- width
)/2;
286 if ( direction
& wxVERTICAL
)
287 new_y
= (heightParent
- height
)/2;
292 // fits the window around the children
293 void wxWindowBase::Fit()
298 wxWindowList::Node
*node
= GetChildren().GetFirst();
301 wxWindow
*win
= node
->GetData();
303 win
->GetPosition(&wx
, &wy
);
304 win
->GetSize(&ww
, &wh
);
305 if ( wx
+ ww
> maxX
)
307 if ( wy
+ wh
> maxY
)
310 node
= node
->GetNext();
314 SetClientSize(maxX
+ 7, maxY
+ 14);
317 // set the min/max size of the window
319 void wxWindowBase::SetSizeHints(int minW
, int minH
,
321 int WXUNUSED(incW
), int WXUNUSED(incH
))
329 // ----------------------------------------------------------------------------
330 // show/hide/enable/disable the window
331 // ----------------------------------------------------------------------------
333 bool wxWindowBase::Show(bool show
)
335 if ( show
!= m_isShown
)
347 bool wxWindowBase::Enable(bool enable
)
349 if ( enable
!= m_isEnabled
)
351 m_isEnabled
= enable
;
361 // ----------------------------------------------------------------------------
362 // reparenting the window
363 // ----------------------------------------------------------------------------
365 void wxWindowBase::AddChild(wxWindowBase
*child
)
367 wxCHECK_RET( child
, _T("can't add a NULL child") );
369 GetChildren().Append(child
);
370 child
->SetParent(this);
373 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
375 wxCHECK_RET( child
, _T("can't remove a NULL child") );
377 GetChildren().DeleteObject(child
);
378 child
->SetParent((wxWindow
*)NULL
);
381 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
383 wxWindow
*oldParent
= GetParent();
384 if ( newParent
== oldParent
)
390 // unlink this window from the existing parent.
393 oldParent
->RemoveChild(this);
397 wxTopLevelWindows
.DeleteObject(this);
400 // add it to the new one
403 newParent
->AddChild(this);
407 wxTopLevelWindows
.Append(this);
413 // ----------------------------------------------------------------------------
414 // event handler stuff
415 // ----------------------------------------------------------------------------
417 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
419 handler
->SetNextHandler(GetEventHandler());
420 SetEventHandler(handler
);
423 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
425 wxEvtHandler
*handlerA
= GetEventHandler();
428 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
429 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
430 SetEventHandler(handlerB
);
434 handlerA
= (wxEvtHandler
*)NULL
;
441 // ----------------------------------------------------------------------------
443 // ----------------------------------------------------------------------------
445 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
447 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
450 m_backgroundColour
= colour
;
455 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
457 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
460 m_foregroundColour
= colour
;
465 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
467 // don't try to set invalid cursor, always fall back to the default
468 const wxCursor
& cursorOk
= cursor
.Ok() ? cursor
: *wxSTANDARD_CURSOR
;
470 if ( cursorOk
== m_cursor
)
481 bool wxWindowBase::SetFont(const wxFont
& font
)
483 // don't try to set invalid font, always fall back to the default
484 const wxFont
& fontOk
= font
.Ok() ? font
: *wxSWISS_FONT
;
486 if ( fontOk
== m_font
)
497 // ----------------------------------------------------------------------------
499 // ----------------------------------------------------------------------------
501 void wxWindowBase::SetValidator(const wxValidator
& validator
)
503 if ( m_windowValidator
)
504 delete m_windowValidator
;
506 m_windowValidator
= (wxValidator
*)validator
.Clone();
508 if ( m_windowValidator
)
509 m_windowValidator
->SetWindow(this) ;
512 // ----------------------------------------------------------------------------
513 // update region testing
514 // ----------------------------------------------------------------------------
516 bool wxWindowBase::IsExposed(int x
, int y
) const
518 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
521 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
523 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
526 // ----------------------------------------------------------------------------
527 // find window by id or name
528 // ----------------------------------------------------------------------------
530 wxWindow
*wxWindowBase::FindWindow( long id
)
532 if ( id
== m_windowId
)
533 return (wxWindow
*)this;
535 wxWindowBase
*res
= (wxWindow
*)NULL
;
536 wxWindowList::Node
*node
;
537 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
539 wxWindowBase
*child
= node
->GetData();
540 res
= child
->FindWindow( id
);
543 return (wxWindow
*)res
;
546 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
548 if ( name
== m_windowName
)
549 return (wxWindow
*)this;
551 wxWindowBase
*res
= (wxWindow
*)NULL
;
552 wxWindowList::Node
*node
;
553 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
555 wxWindow
*child
= node
->GetData();
556 res
= child
->FindWindow(name
);
559 return (wxWindow
*)res
;
562 // ----------------------------------------------------------------------------
563 // dialog oriented functions
564 // ----------------------------------------------------------------------------
566 void wxWindowBase::MakeModal(bool modal
)
571 bool wxWindowBase::Validate()
573 wxWindowList::Node
*node
;
574 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
576 wxWindowBase
*child
= node
->GetData();
577 wxValidator
*validator
= child
->GetValidator();
578 if ( validator
&& validator
->Validate(this) )
587 bool wxWindowBase::TransferDataToWindow()
589 wxWindowList::Node
*node
;
590 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
592 wxWindowBase
*child
= node
->GetData();
593 wxValidator
*validator
= child
->GetValidator();
594 if ( validator
&& !validator
->TransferToWindow() )
596 wxLog
*log
= wxLog::GetActiveTarget();
599 wxLogWarning(_("Could not transfer data to window"));
610 bool wxWindowBase::TransferDataFromWindow()
612 wxWindowList::Node
*node
;
613 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
615 wxWindow
*child
= node
->GetData();
616 if ( child
->GetValidator() &&
617 !child
->GetValidator()->TransferFromWindow() )
626 void wxWindowBase::InitDialog()
628 wxInitDialogEvent
event(GetId());
629 event
.SetEventObject( this );
630 GetEventHandler()->ProcessEvent(event
);
633 // ----------------------------------------------------------------------------
635 // ----------------------------------------------------------------------------
639 void wxWindowBase::SetToolTip( const wxString
&tip
)
641 // don't create the new tooltip if we already have one
644 m_tooltip
->SetTip( tip
);
648 SetToolTip( new wxToolTip( tip
) );
651 // setting empty tooltip text does not remove the tooltip any more - use
652 // SetToolTip((wxToolTip *)NULL) for this
655 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
663 #endif // wxUSE_TOOLTIPS
665 // ----------------------------------------------------------------------------
666 // constraints and sizers
667 // ----------------------------------------------------------------------------
669 #if wxUSE_CONSTRAINTS
671 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
675 UnsetConstraints(m_constraints
);
676 delete m_constraints
;
678 m_constraints
= constraints
;
681 // Make sure other windows know they're part of a 'meaningful relationship'
682 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
683 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
684 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
685 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
686 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
687 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
688 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
689 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
690 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
691 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
692 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
693 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
694 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
695 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
696 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
697 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
701 // This removes any dangling pointers to this window in other windows'
702 // constraintsInvolvedIn lists.
703 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
707 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
708 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
709 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
710 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
711 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
712 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
713 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
714 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
715 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
716 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
717 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
718 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
719 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
720 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
721 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
722 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
726 // Back-pointer to other windows we're involved with, so if we delete this
727 // window, we must delete any constraints we're involved with.
728 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
730 if ( !m_constraintsInvolvedIn
)
731 m_constraintsInvolvedIn
= new wxWindowList
;
732 if ( !m_constraintsInvolvedIn
->Find(otherWin
) )
733 m_constraintsInvolvedIn
->Append(otherWin
);
736 // REMOVE back-pointer to other windows we're involved with.
737 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
739 if ( m_constraintsInvolvedIn
)
740 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
743 // Reset any constraints that mention this window
744 void wxWindowBase::DeleteRelatedConstraints()
746 if ( m_constraintsInvolvedIn
)
748 wxWindowList::Node
*node
= m_constraintsInvolvedIn
->GetFirst();
751 wxWindow
*win
= node
->GetData();
752 wxLayoutConstraints
*constr
= win
->GetConstraints();
754 // Reset any constraints involving this window
757 constr
->left
.ResetIfWin(this);
758 constr
->top
.ResetIfWin(this);
759 constr
->right
.ResetIfWin(this);
760 constr
->bottom
.ResetIfWin(this);
761 constr
->width
.ResetIfWin(this);
762 constr
->height
.ResetIfWin(this);
763 constr
->centreX
.ResetIfWin(this);
764 constr
->centreY
.ResetIfWin(this);
767 wxWindowList::Node
*next
= node
->GetNext();
772 delete m_constraintsInvolvedIn
;
773 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
777 void wxWindowBase::SetSizer(wxSizer
*sizer
)
779 m_windowSizer
= sizer
;
781 sizer
->SetSizerParent(this);
784 bool wxWindowBase::Layout()
786 if ( GetConstraints() )
789 GetClientSize(&w
, &h
);
790 GetConstraints()->width
.SetValue(w
);
791 GetConstraints()->height
.SetValue(h
);
794 // If top level (one sizer), evaluate the sizer's constraints.
798 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
799 GetSizer()->LayoutPhase1(&noChanges
);
800 GetSizer()->LayoutPhase2(&noChanges
);
801 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
806 // Otherwise, evaluate child constraints
807 ResetConstraints(); // Mark all constraints as unevaluated
808 DoPhase(1); // Just one phase need if no sizers involved
810 SetConstraintSizes(); // Recursively set the real window sizes
816 // Do a phase of evaluating constraints: the default behaviour. wxSizers may
817 // do a similar thing, but also impose their own 'constraints' and order the
818 // evaluation differently.
819 bool wxWindowBase::LayoutPhase1(int *noChanges
)
821 wxLayoutConstraints
*constr
= GetConstraints();
824 return constr
->SatisfyConstraints(this, noChanges
);
830 bool wxWindowBase::LayoutPhase2(int *noChanges
)
840 // Do a phase of evaluating child constraints
841 bool wxWindowBase::DoPhase(int phase
)
843 int noIterations
= 0;
844 int maxIterations
= 500;
847 wxWindowList succeeded
;
848 while ((noChanges
> 0) && (noIterations
< maxIterations
))
852 wxWindowList::Node
*node
= GetChildren().GetFirst();
855 wxWindow
*child
= node
->GetData();
856 if ( !child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)) )
858 wxLayoutConstraints
*constr
= child
->GetConstraints();
861 if ( !succeeded
.Find(child
) )
863 int tempNoChanges
= 0;
864 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
865 noChanges
+= tempNoChanges
;
868 succeeded
.Append(child
);
873 node
= node
->GetNext();
882 void wxWindowBase::ResetConstraints()
884 wxLayoutConstraints
*constr
= GetConstraints();
887 constr
->left
.SetDone(FALSE
);
888 constr
->top
.SetDone(FALSE
);
889 constr
->right
.SetDone(FALSE
);
890 constr
->bottom
.SetDone(FALSE
);
891 constr
->width
.SetDone(FALSE
);
892 constr
->height
.SetDone(FALSE
);
893 constr
->centreX
.SetDone(FALSE
);
894 constr
->centreY
.SetDone(FALSE
);
896 wxWindowList::Node
*node
= GetChildren().GetFirst();
899 wxWindow
*win
= node
->GetData();
900 if ( !win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)) )
901 win
->ResetConstraints();
902 node
= node
->GetNext();
906 // Need to distinguish between setting the 'fake' size for windows and sizers,
907 // and setting the real values.
908 void wxWindowBase::SetConstraintSizes(bool recurse
)
910 wxLayoutConstraints
*constr
= GetConstraints();
911 if ( constr
&& constr
->left
.GetDone() && constr
->right
.GetDone( ) &&
912 constr
->width
.GetDone() && constr
->height
.GetDone())
914 int x
= constr
->left
.GetValue();
915 int y
= constr
->top
.GetValue();
916 int w
= constr
->width
.GetValue();
917 int h
= constr
->height
.GetValue();
919 // If we don't want to resize this window, just move it...
920 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
921 (constr
->height
.GetRelationship() != wxAsIs
))
923 // Calls Layout() recursively. AAAGH. How can we stop that.
924 // Simply take Layout() out of non-top level OnSizes.
925 SizerSetSize(x
, y
, w
, h
);
934 wxChar
*windowClass
= GetClassInfo()->GetClassName();
937 if ( GetName() == _T("") )
938 winName
= _T("unnamed");
941 wxLogDebug( _T("Constraint(s) not satisfied for window of type %s, name %s:\n"),
942 (const wxChar
*)windowClass
,
943 (const wxChar
*)winName
);
944 if ( !constr
->left
.GetDone()) wxLogDebug( _T(" unsatisfied 'left' constraint.\n") );
945 if ( !constr
->right
.GetDone()) wxLogDebug( _T(" unsatisfied 'right' constraint.\n") );
946 if ( !constr
->width
.GetDone()) wxLogDebug( _T(" unsatisfied 'width' constraint.\n") );
947 if ( !constr
->height
.GetDone()) wxLogDebug( _T(" unsatisfied 'height' constraint.\n") );
948 wxLogDebug( _T("Please check constraints: try adding AsIs() constraints.\n") );
953 wxWindowList::Node
*node
= GetChildren().GetFirst();
956 wxWindow
*win
= node
->GetData();
957 if ( !win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)) )
958 win
->SetConstraintSizes();
959 node
= node
->GetNext();
964 // This assumes that all sizers are 'on' the same window, i.e. the parent of
966 void wxWindowBase::TransformSizerToActual(int *x
, int *y
) const
968 if ( !m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
) ) ||
969 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
973 m_sizerParent
->GetPosition(&xp
, &yp
);
974 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
979 void wxWindowBase::SizerSetSize(int x
, int y
, int w
, int h
)
983 TransformSizerToActual(&xx
, &yy
);
984 SetSize(xx
, yy
, w
, h
);
987 void wxWindowBase::SizerMove(int x
, int y
)
991 TransformSizerToActual(&xx
, &yy
);
995 // Only set the size/position of the constraint (if any)
996 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
998 wxLayoutConstraints
*constr
= GetConstraints();
1003 constr
->left
.SetValue(x
);
1004 constr
->left
.SetDone(TRUE
);
1008 constr
->top
.SetValue(y
);
1009 constr
->top
.SetDone(TRUE
);
1013 constr
->width
.SetValue(w
);
1014 constr
->width
.SetDone(TRUE
);
1018 constr
->height
.SetValue(h
);
1019 constr
->height
.SetDone(TRUE
);
1024 void wxWindowBase::MoveConstraint(int x
, int y
)
1026 wxLayoutConstraints
*constr
= GetConstraints();
1031 constr
->left
.SetValue(x
);
1032 constr
->left
.SetDone(TRUE
);
1036 constr
->top
.SetValue(y
);
1037 constr
->top
.SetDone(TRUE
);
1042 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1044 wxLayoutConstraints
*constr
= GetConstraints();
1047 *w
= constr
->width
.GetValue();
1048 *h
= constr
->height
.GetValue();
1054 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1056 wxLayoutConstraints
*constr
= GetConstraints();
1059 *w
= constr
->width
.GetValue();
1060 *h
= constr
->height
.GetValue();
1063 GetClientSize(w
, h
);
1066 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1068 wxLayoutConstraints
*constr
= GetConstraints();
1071 *x
= constr
->left
.GetValue();
1072 *y
= constr
->top
.GetValue();
1078 #endif // wxUSE_CONSTRAINTS
1080 // ----------------------------------------------------------------------------
1081 // do Update UI processing for child controls
1082 // ----------------------------------------------------------------------------
1084 // TODO: should this be implemented for the child window rather
1085 // than the parent? Then you can override it e.g. for wxCheckBox
1086 // to do the Right Thing rather than having to assume a fixed number
1087 // of control classes.
1088 void wxWindowBase::UpdateWindowUI()
1090 wxWindowID id
= GetId();
1093 wxUpdateUIEvent
event(id
);
1094 event
.m_eventObject
= this;
1096 if ( GetEventHandler()->ProcessEvent(event
) )
1098 if ( event
.GetSetEnabled() )
1099 Enable(event
.GetEnabled());
1101 if ( event
.GetSetText() && IsKindOf(CLASSINFO(wxControl
)) )
1102 ((wxControl
*)this)->SetLabel(event
.GetText());
1104 if ( IsKindOf(CLASSINFO(wxCheckBox
)) )
1106 if ( event
.GetSetChecked() )
1107 ((wxCheckBox
*)this)->SetValue(event
.GetChecked());
1109 // TODO No radio buttons in wxGTK yet
1111 else if ( IsKindOf(CLASSINFO(wxRadioButton
)) )
1113 if ( event
.GetSetChecked() )
1114 ((wxRadioButton
*) this)->SetValue(event
.GetChecked());
1121 // ----------------------------------------------------------------------------
1122 // dialog units translations
1123 // ----------------------------------------------------------------------------
1125 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1127 int charWidth
= GetCharWidth();
1128 int charHeight
= GetCharHeight();
1130 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1131 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1136 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1138 int charWidth
= GetCharWidth();
1139 int charHeight
= GetCharHeight();
1141 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1142 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1147 // ----------------------------------------------------------------------------
1149 // ----------------------------------------------------------------------------
1151 // propagate the colour change event to the subwindows
1152 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1154 wxWindowList::Node
*node
= GetChildren().GetFirst();
1157 // Only propagate to non-top-level windows
1158 wxWindow
*win
= node
->GetData();
1159 if ( !win
->IsTopLevel() )
1161 wxSysColourChangedEvent event2
;
1162 event
.m_eventObject
= win
;
1163 win
->GetEventHandler()->ProcessEvent(event2
);
1166 node
= node
->GetNext();
1170 // the default action is to populate dialog with data when it's created
1171 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1173 TransferDataToWindow();
1176 // ----------------------------------------------------------------------------
1177 // list classes implementation
1178 // ----------------------------------------------------------------------------
1180 void wxWindowListNode::DeleteData()
1182 delete (wxWindow
*)GetData();