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
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
60 int wxWindowBase::ms_lastControlId
= -2;
62 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
64 // ----------------------------------------------------------------------------
66 // ----------------------------------------------------------------------------
68 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
69 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
70 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
73 // ============================================================================
74 // implementation of the common functionality of the wxWindow class
75 // ============================================================================
77 // ----------------------------------------------------------------------------
79 // ----------------------------------------------------------------------------
81 // the default initialization
82 void wxWindowBase::InitBase()
84 // no window yet, no parent nor children
85 m_parent
= (wxWindow
*)NULL
;
87 m_children
.DeleteContents( FALSE
); // don't auto delete node data
89 // no constraints on the minimal window size
95 // window is created enabled but it's not visible yet
100 m_clientObject
= (wxClientData
*)NULL
;
103 // the default event handler is just this window
104 m_eventHandler
= this;
107 m_windowValidator
= (wxValidator
*) NULL
;
109 // use the system default colours
110 wxSystemSettings settings
;
112 m_backgroundColour
= settings
.GetSystemColour(wxSYS_COLOUR_BTNFACE
);
113 m_foregroundColour
= *wxBLACK
; // TODO take this from sys settings too?
114 m_font
= *wxSWISS_FONT
; // and this?
119 // an optimization for the event processing: checking this flag is much
120 // faster than using IsKindOf(CLASSINFO(wxWindow))
123 #if wxUSE_CONSTRAINTS
124 // no constraints whatsoever
125 m_constraints
= (wxLayoutConstraints
*) NULL
;
126 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
127 m_windowSizer
= (wxSizer
*) NULL
;
128 m_sizerParent
= (wxWindowBase
*) NULL
;
129 m_autoLayout
= FALSE
;
130 #endif // wxUSE_CONSTRAINTS
132 #if wxUSE_DRAG_AND_DROP
133 m_dropTarget
= (wxDropTarget
*)NULL
;
134 #endif // wxUSE_DRAG_AND_DROP
137 m_tooltip
= (wxToolTip
*)NULL
;
138 #endif // wxUSE_TOOLTIPS
141 // common part of window creation process
142 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
144 const wxPoint
& WXUNUSED(pos
),
145 const wxSize
& WXUNUSED(size
),
147 const wxString
& name
)
149 // m_isWindow is set to TRUE in wxWindowBase::Init() as well as many other
150 // member variables - check that it has been called (will catch the case
151 // when a new ctor is added which doesn't call InitWindow)
152 wxASSERT_MSG( m_isWindow
, _T("Init() must have been called before!") );
154 // generate a new id if the user doesn't care about it
155 m_windowId
= id
== -1 ? NewControlId() : id
;
158 SetWindowStyleFlag(style
);
164 // ----------------------------------------------------------------------------
166 // ----------------------------------------------------------------------------
169 wxWindowBase::~wxWindowBase()
171 // FIXME if these 2 cases result from programming errors in the user code
172 // we should probably assert here instead of silently fixing them
174 // Just in case the window has been Closed, but we're then deleting
175 // immediately: don't leave dangling pointers.
176 wxPendingDelete
.DeleteObject(this);
178 // Just in case we've loaded a top-level window via LoadNativeDialog but
179 // we weren't a dialog class
180 wxTopLevelWindows
.DeleteObject(this);
182 wxASSERT_MSG( GetChildren().GetCount() == 0, _T("children not destroyed") );
184 if ( m_windowValidator
)
185 delete m_windowValidator
;
187 if ( m_clientObject
)
188 delete m_clientObject
;
190 #if wxUSE_CONSTRAINTS
191 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
192 // at deleted windows as they delete themselves.
193 DeleteRelatedConstraints();
197 // This removes any dangling pointers to this window in other windows'
198 // constraintsInvolvedIn lists.
199 UnsetConstraints(m_constraints
);
200 delete m_constraints
;
201 m_constraints
= NULL
;
205 delete m_windowSizer
;
207 // If this is a child of a sizer, remove self from parent
209 m_sizerParent
->RemoveChild(this);
210 #endif // wxUSE_CONSTRAINTS
212 #if wxUSE_DRAG_AND_DROP
215 #endif // wxUSE_DRAG_AND_DROP
220 #endif // wxUSE_TOOLTIPS
223 bool wxWindowBase::Destroy()
230 bool wxWindowBase::Close(bool force
)
232 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
233 event
.SetEventObject(this);
234 #if WXWIN_COMPATIBILITY
235 event
.SetForce(force
);
236 #endif // WXWIN_COMPATIBILITY
237 event
.SetCanVeto(!force
);
239 // return FALSE if window wasn't closed because the application vetoed the
241 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
244 bool wxWindowBase::DestroyChildren()
246 wxWindowList::Node
*node
;
249 // we iterate until the list becomes empty
250 node
= GetChildren().GetFirst();
254 wxWindow
*child
= node
->GetData();
256 wxASSERT_MSG( child
, _T("children list contains empty nodes") );
260 wxASSERT_MSG( !GetChildren().Find(child
),
261 _T("child didn't remove itself using RemoveChild()") );
267 // ----------------------------------------------------------------------------
268 // centre/fit the window
269 // ----------------------------------------------------------------------------
271 // centre the window with respect to its parent in either (or both) directions
272 void wxWindowBase::Centre(int direction
)
274 int widthParent
, heightParent
;
276 wxWindow
*parent
= GetParent();
279 parent
->GetClientSize(&widthParent
, &heightParent
);
283 // centre with respect to the whole screen
284 wxDisplaySize(&widthParent
, &heightParent
);
288 GetSize(&width
, &height
);
293 if ( direction
& wxHORIZONTAL
)
294 new_x
= (widthParent
- width
)/2;
296 if ( direction
& wxVERTICAL
)
297 new_y
= (heightParent
- height
)/2;
302 // fits the window around the children
303 void wxWindowBase::Fit()
308 wxWindowList::Node
*node
= GetChildren().GetFirst();
311 wxWindow
*win
= node
->GetData();
313 win
->GetPosition(&wx
, &wy
);
314 win
->GetSize(&ww
, &wh
);
315 if ( wx
+ ww
> maxX
)
317 if ( wy
+ wh
> maxY
)
320 node
= node
->GetNext();
324 SetClientSize(maxX
+ 7, maxY
+ 14);
327 // set the min/max size of the window
329 void wxWindowBase::SetSizeHints(int minW
, int minH
,
331 int WXUNUSED(incW
), int WXUNUSED(incH
))
339 // ----------------------------------------------------------------------------
340 // show/hide/enable/disable the window
341 // ----------------------------------------------------------------------------
343 bool wxWindowBase::Show(bool show
)
345 if ( show
!= m_isShown
)
357 bool wxWindowBase::Enable(bool enable
)
359 if ( enable
!= m_isEnabled
)
361 m_isEnabled
= enable
;
371 // ----------------------------------------------------------------------------
372 // reparenting the window
373 // ----------------------------------------------------------------------------
375 void wxWindowBase::AddChild(wxWindowBase
*child
)
377 wxCHECK_RET( child
, _T("can't add a NULL child") );
379 GetChildren().Append(child
);
380 child
->SetParent(this);
383 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
385 wxCHECK_RET( child
, _T("can't remove a NULL child") );
387 GetChildren().DeleteObject(child
);
388 child
->SetParent((wxWindow
*)NULL
);
391 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
393 wxWindow
*oldParent
= GetParent();
394 if ( newParent
== oldParent
)
400 // unlink this window from the existing parent.
403 oldParent
->RemoveChild(this);
407 wxTopLevelWindows
.DeleteObject(this);
410 // add it to the new one
413 newParent
->AddChild(this);
417 wxTopLevelWindows
.Append(this);
423 // ----------------------------------------------------------------------------
424 // event handler stuff
425 // ----------------------------------------------------------------------------
427 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
429 handler
->SetNextHandler(GetEventHandler());
430 SetEventHandler(handler
);
433 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
435 wxEvtHandler
*handlerA
= GetEventHandler();
438 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
439 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
440 SetEventHandler(handlerB
);
444 handlerA
= (wxEvtHandler
*)NULL
;
451 // ----------------------------------------------------------------------------
453 // ----------------------------------------------------------------------------
455 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
457 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
460 m_backgroundColour
= colour
;
465 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
467 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
470 m_foregroundColour
= colour
;
475 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
477 // don't try to set invalid cursor, always fall back to the default
478 const wxCursor
& cursorOk
= cursor
.Ok() ? cursor
: *wxSTANDARD_CURSOR
;
480 if ( cursorOk
== m_cursor
)
491 bool wxWindowBase::SetFont(const wxFont
& font
)
493 // don't try to set invalid font, always fall back to the default
494 const wxFont
& fontOk
= font
.Ok() ? font
: *wxSWISS_FONT
;
496 if ( fontOk
== m_font
)
507 // ----------------------------------------------------------------------------
509 // ----------------------------------------------------------------------------
511 void wxWindowBase::SetValidator(const wxValidator
& validator
)
513 if ( m_windowValidator
)
514 delete m_windowValidator
;
516 m_windowValidator
= (wxValidator
*)validator
.Clone();
518 if ( m_windowValidator
)
519 m_windowValidator
->SetWindow(this) ;
522 // ----------------------------------------------------------------------------
523 // update region testing
524 // ----------------------------------------------------------------------------
526 bool wxWindowBase::IsExposed(int x
, int y
) const
528 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
531 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
533 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
536 // ----------------------------------------------------------------------------
537 // find window by id or name
538 // ----------------------------------------------------------------------------
540 wxWindow
*wxWindowBase::FindWindow( long id
)
542 if ( id
== m_windowId
)
543 return (wxWindow
*)this;
545 wxWindowBase
*res
= (wxWindow
*)NULL
;
546 wxWindowList::Node
*node
;
547 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
549 wxWindowBase
*child
= node
->GetData();
550 res
= child
->FindWindow( id
);
553 return (wxWindow
*)res
;
556 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
558 if ( name
== m_windowName
)
559 return (wxWindow
*)this;
561 wxWindowBase
*res
= (wxWindow
*)NULL
;
562 wxWindowList::Node
*node
;
563 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
565 wxWindow
*child
= node
->GetData();
566 res
= child
->FindWindow(name
);
569 return (wxWindow
*)res
;
572 // ----------------------------------------------------------------------------
573 // dialog oriented functions
574 // ----------------------------------------------------------------------------
576 void wxWindowBase::MakeModal(bool WXUNUSED(modal
))
578 wxFAIL_MSG(_T("TODO"));
581 bool wxWindowBase::Validate()
583 wxWindowList::Node
*node
;
584 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
586 wxWindowBase
*child
= node
->GetData();
587 wxValidator
*validator
= child
->GetValidator();
588 if ( validator
&& validator
->Validate(this) )
597 bool wxWindowBase::TransferDataToWindow()
599 wxWindowList::Node
*node
;
600 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
602 wxWindowBase
*child
= node
->GetData();
603 wxValidator
*validator
= child
->GetValidator();
604 if ( validator
&& !validator
->TransferToWindow() )
606 wxLog
*log
= wxLog::GetActiveTarget();
609 wxLogWarning(_("Could not transfer data to window"));
620 bool wxWindowBase::TransferDataFromWindow()
622 wxWindowList::Node
*node
;
623 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
625 wxWindow
*child
= node
->GetData();
626 if ( child
->GetValidator() &&
627 !child
->GetValidator()->TransferFromWindow() )
636 void wxWindowBase::InitDialog()
638 wxInitDialogEvent
event(GetId());
639 event
.SetEventObject( this );
640 GetEventHandler()->ProcessEvent(event
);
643 // ----------------------------------------------------------------------------
645 // ----------------------------------------------------------------------------
649 void wxWindowBase::SetToolTip( const wxString
&tip
)
651 // don't create the new tooltip if we already have one
654 m_tooltip
->SetTip( tip
);
658 SetToolTip( new wxToolTip( tip
) );
661 // setting empty tooltip text does not remove the tooltip any more - use
662 // SetToolTip((wxToolTip *)NULL) for this
665 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
673 #endif // wxUSE_TOOLTIPS
675 // ----------------------------------------------------------------------------
676 // constraints and sizers
677 // ----------------------------------------------------------------------------
679 #if wxUSE_CONSTRAINTS
681 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
685 UnsetConstraints(m_constraints
);
686 delete m_constraints
;
688 m_constraints
= constraints
;
691 // Make sure other windows know they're part of a 'meaningful relationship'
692 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
693 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
694 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
695 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
696 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
697 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
698 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
699 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
700 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
701 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
702 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
703 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
704 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
705 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
706 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
707 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
711 // This removes any dangling pointers to this window in other windows'
712 // constraintsInvolvedIn lists.
713 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
717 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
718 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
719 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
720 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
721 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
722 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
723 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
724 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
725 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
726 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
727 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
728 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
729 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
730 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
731 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
732 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
736 // Back-pointer to other windows we're involved with, so if we delete this
737 // window, we must delete any constraints we're involved with.
738 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
740 if ( !m_constraintsInvolvedIn
)
741 m_constraintsInvolvedIn
= new wxWindowList
;
742 if ( !m_constraintsInvolvedIn
->Find(otherWin
) )
743 m_constraintsInvolvedIn
->Append(otherWin
);
746 // REMOVE back-pointer to other windows we're involved with.
747 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
749 if ( m_constraintsInvolvedIn
)
750 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
753 // Reset any constraints that mention this window
754 void wxWindowBase::DeleteRelatedConstraints()
756 if ( m_constraintsInvolvedIn
)
758 wxWindowList::Node
*node
= m_constraintsInvolvedIn
->GetFirst();
761 wxWindow
*win
= node
->GetData();
762 wxLayoutConstraints
*constr
= win
->GetConstraints();
764 // Reset any constraints involving this window
767 constr
->left
.ResetIfWin(this);
768 constr
->top
.ResetIfWin(this);
769 constr
->right
.ResetIfWin(this);
770 constr
->bottom
.ResetIfWin(this);
771 constr
->width
.ResetIfWin(this);
772 constr
->height
.ResetIfWin(this);
773 constr
->centreX
.ResetIfWin(this);
774 constr
->centreY
.ResetIfWin(this);
777 wxWindowList::Node
*next
= node
->GetNext();
782 delete m_constraintsInvolvedIn
;
783 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
787 void wxWindowBase::SetSizer(wxSizer
*sizer
)
789 m_windowSizer
= sizer
;
791 sizer
->SetSizerParent(this);
794 bool wxWindowBase::Layout()
796 if ( GetConstraints() )
799 GetClientSize(&w
, &h
);
800 GetConstraints()->width
.SetValue(w
);
801 GetConstraints()->height
.SetValue(h
);
804 // If top level (one sizer), evaluate the sizer's constraints.
808 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
809 GetSizer()->LayoutPhase1(&noChanges
);
810 GetSizer()->LayoutPhase2(&noChanges
);
811 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
816 // Otherwise, evaluate child constraints
817 ResetConstraints(); // Mark all constraints as unevaluated
818 DoPhase(1); // Just one phase need if no sizers involved
820 SetConstraintSizes(); // Recursively set the real window sizes
826 // Do a phase of evaluating constraints: the default behaviour. wxSizers may
827 // do a similar thing, but also impose their own 'constraints' and order the
828 // evaluation differently.
829 bool wxWindowBase::LayoutPhase1(int *noChanges
)
831 wxLayoutConstraints
*constr
= GetConstraints();
834 return constr
->SatisfyConstraints(this, noChanges
);
840 bool wxWindowBase::LayoutPhase2(int *noChanges
)
850 // Do a phase of evaluating child constraints
851 bool wxWindowBase::DoPhase(int phase
)
853 int noIterations
= 0;
854 int maxIterations
= 500;
857 wxWindowList succeeded
;
858 while ((noChanges
> 0) && (noIterations
< maxIterations
))
862 wxWindowList::Node
*node
= GetChildren().GetFirst();
865 wxWindow
*child
= node
->GetData();
866 if ( !child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)) )
868 wxLayoutConstraints
*constr
= child
->GetConstraints();
871 if ( !succeeded
.Find(child
) )
873 int tempNoChanges
= 0;
874 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
875 noChanges
+= tempNoChanges
;
878 succeeded
.Append(child
);
883 node
= node
->GetNext();
892 void wxWindowBase::ResetConstraints()
894 wxLayoutConstraints
*constr
= GetConstraints();
897 constr
->left
.SetDone(FALSE
);
898 constr
->top
.SetDone(FALSE
);
899 constr
->right
.SetDone(FALSE
);
900 constr
->bottom
.SetDone(FALSE
);
901 constr
->width
.SetDone(FALSE
);
902 constr
->height
.SetDone(FALSE
);
903 constr
->centreX
.SetDone(FALSE
);
904 constr
->centreY
.SetDone(FALSE
);
906 wxWindowList::Node
*node
= GetChildren().GetFirst();
909 wxWindow
*win
= node
->GetData();
910 if ( !win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)) )
911 win
->ResetConstraints();
912 node
= node
->GetNext();
916 // Need to distinguish between setting the 'fake' size for windows and sizers,
917 // and setting the real values.
918 void wxWindowBase::SetConstraintSizes(bool recurse
)
920 wxLayoutConstraints
*constr
= GetConstraints();
921 if ( constr
&& constr
->left
.GetDone() && constr
->right
.GetDone( ) &&
922 constr
->width
.GetDone() && constr
->height
.GetDone())
924 int x
= constr
->left
.GetValue();
925 int y
= constr
->top
.GetValue();
926 int w
= constr
->width
.GetValue();
927 int h
= constr
->height
.GetValue();
929 // If we don't want to resize this window, just move it...
930 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
931 (constr
->height
.GetRelationship() != wxAsIs
))
933 // Calls Layout() recursively. AAAGH. How can we stop that.
934 // Simply take Layout() out of non-top level OnSizes.
935 SizerSetSize(x
, y
, w
, h
);
944 wxChar
*windowClass
= GetClassInfo()->GetClassName();
947 if ( GetName() == _T("") )
948 winName
= _T("unnamed");
951 wxLogDebug( _T("Constraint(s) not satisfied for window of type %s, name %s:\n"),
952 (const wxChar
*)windowClass
,
953 (const wxChar
*)winName
);
954 if ( !constr
->left
.GetDone()) wxLogDebug( _T(" unsatisfied 'left' constraint.\n") );
955 if ( !constr
->right
.GetDone()) wxLogDebug( _T(" unsatisfied 'right' constraint.\n") );
956 if ( !constr
->width
.GetDone()) wxLogDebug( _T(" unsatisfied 'width' constraint.\n") );
957 if ( !constr
->height
.GetDone()) wxLogDebug( _T(" unsatisfied 'height' constraint.\n") );
958 wxLogDebug( _T("Please check constraints: try adding AsIs() constraints.\n") );
963 wxWindowList::Node
*node
= GetChildren().GetFirst();
966 wxWindow
*win
= node
->GetData();
967 if ( !win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)) )
968 win
->SetConstraintSizes();
969 node
= node
->GetNext();
974 // This assumes that all sizers are 'on' the same window, i.e. the parent of
976 void wxWindowBase::TransformSizerToActual(int *x
, int *y
) const
978 if ( !m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
) ) ||
979 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
983 m_sizerParent
->GetPosition(&xp
, &yp
);
984 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
989 void wxWindowBase::SizerSetSize(int x
, int y
, int w
, int h
)
993 TransformSizerToActual(&xx
, &yy
);
994 SetSize(xx
, yy
, w
, h
);
997 void wxWindowBase::SizerMove(int x
, int y
)
1001 TransformSizerToActual(&xx
, &yy
);
1005 // Only set the size/position of the constraint (if any)
1006 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1008 wxLayoutConstraints
*constr
= GetConstraints();
1013 constr
->left
.SetValue(x
);
1014 constr
->left
.SetDone(TRUE
);
1018 constr
->top
.SetValue(y
);
1019 constr
->top
.SetDone(TRUE
);
1023 constr
->width
.SetValue(w
);
1024 constr
->width
.SetDone(TRUE
);
1028 constr
->height
.SetValue(h
);
1029 constr
->height
.SetDone(TRUE
);
1034 void wxWindowBase::MoveConstraint(int x
, int y
)
1036 wxLayoutConstraints
*constr
= GetConstraints();
1041 constr
->left
.SetValue(x
);
1042 constr
->left
.SetDone(TRUE
);
1046 constr
->top
.SetValue(y
);
1047 constr
->top
.SetDone(TRUE
);
1052 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1054 wxLayoutConstraints
*constr
= GetConstraints();
1057 *w
= constr
->width
.GetValue();
1058 *h
= constr
->height
.GetValue();
1064 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1066 wxLayoutConstraints
*constr
= GetConstraints();
1069 *w
= constr
->width
.GetValue();
1070 *h
= constr
->height
.GetValue();
1073 GetClientSize(w
, h
);
1076 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1078 wxLayoutConstraints
*constr
= GetConstraints();
1081 *x
= constr
->left
.GetValue();
1082 *y
= constr
->top
.GetValue();
1088 #endif // wxUSE_CONSTRAINTS
1090 // ----------------------------------------------------------------------------
1091 // do Update UI processing for child controls
1092 // ----------------------------------------------------------------------------
1094 // TODO: should this be implemented for the child window rather
1095 // than the parent? Then you can override it e.g. for wxCheckBox
1096 // to do the Right Thing rather than having to assume a fixed number
1097 // of control classes.
1098 void wxWindowBase::UpdateWindowUI()
1100 wxWindowID id
= GetId();
1103 wxUpdateUIEvent
event(id
);
1104 event
.m_eventObject
= this;
1106 if ( GetEventHandler()->ProcessEvent(event
) )
1108 if ( event
.GetSetEnabled() )
1109 Enable(event
.GetEnabled());
1111 if ( event
.GetSetText() && IsKindOf(CLASSINFO(wxControl
)) )
1112 ((wxControl
*)this)->SetLabel(event
.GetText());
1114 if ( IsKindOf(CLASSINFO(wxCheckBox
)) )
1116 if ( event
.GetSetChecked() )
1117 ((wxCheckBox
*)this)->SetValue(event
.GetChecked());
1119 // TODO No radio buttons in wxGTK yet
1121 else if ( IsKindOf(CLASSINFO(wxRadioButton
)) )
1123 if ( event
.GetSetChecked() )
1124 ((wxRadioButton
*) this)->SetValue(event
.GetChecked());
1131 // ----------------------------------------------------------------------------
1132 // dialog units translations
1133 // ----------------------------------------------------------------------------
1135 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1137 int charWidth
= GetCharWidth();
1138 int charHeight
= GetCharHeight();
1140 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1141 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1146 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1148 int charWidth
= GetCharWidth();
1149 int charHeight
= GetCharHeight();
1151 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1152 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1157 // ----------------------------------------------------------------------------
1159 // ----------------------------------------------------------------------------
1161 // propagate the colour change event to the subwindows
1162 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1164 wxWindowList::Node
*node
= GetChildren().GetFirst();
1167 // Only propagate to non-top-level windows
1168 wxWindow
*win
= node
->GetData();
1169 if ( !win
->IsTopLevel() )
1171 wxSysColourChangedEvent event2
;
1172 event
.m_eventObject
= win
;
1173 win
->GetEventHandler()->ProcessEvent(event2
);
1176 node
= node
->GetNext();
1180 // the default action is to populate dialog with data when it's created
1181 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1183 TransferDataToWindow();
1186 // ----------------------------------------------------------------------------
1187 // list classes implementation
1188 // ----------------------------------------------------------------------------
1190 void wxWindowListNode::DeleteData()
1192 delete (wxWindow
*)GetData();