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") );
194 // make sure that there are no dangling pointers left pointing to us
195 wxPanel
*panel
= wxDynamicCast(GetParent(), wxPanel
);
198 if ( panel
->GetLastFocus() == this )
200 panel
->SetLastFocus((wxWindow
*)NULL
);
207 #endif // wxUSE_CARET
210 if ( m_windowValidator
)
211 delete m_windowValidator
;
212 #endif // wxUSE_VALIDATORS
214 if ( m_clientObject
)
215 delete m_clientObject
;
217 #if wxUSE_CONSTRAINTS
218 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
219 // at deleted windows as they delete themselves.
220 DeleteRelatedConstraints();
224 // This removes any dangling pointers to this window in other windows'
225 // constraintsInvolvedIn lists.
226 UnsetConstraints(m_constraints
);
227 delete m_constraints
;
228 m_constraints
= NULL
;
232 delete m_windowSizer
;
234 // If this is a child of a sizer, remove self from parent
236 m_sizerParent
->RemoveChild(this);
237 #endif // wxUSE_CONSTRAINTS
239 #if wxUSE_DRAG_AND_DROP
242 #endif // wxUSE_DRAG_AND_DROP
247 #endif // wxUSE_TOOLTIPS
250 bool wxWindowBase::Destroy()
257 bool wxWindowBase::Close(bool force
)
259 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
260 event
.SetEventObject(this);
261 #if WXWIN_COMPATIBILITY
262 event
.SetForce(force
);
263 #endif // WXWIN_COMPATIBILITY
264 event
.SetCanVeto(!force
);
266 // return FALSE if window wasn't closed because the application vetoed the
268 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
271 bool wxWindowBase::DestroyChildren()
273 wxWindowList::Node
*node
;
276 // we iterate until the list becomes empty
277 node
= GetChildren().GetFirst();
281 wxWindow
*child
= node
->GetData();
283 wxASSERT_MSG( child
, _T("children list contains empty nodes") );
287 wxASSERT_MSG( !GetChildren().Find(child
),
288 _T("child didn't remove itself using RemoveChild()") );
294 // ----------------------------------------------------------------------------
295 // centre/fit the window
296 // ----------------------------------------------------------------------------
298 // centre the window with respect to its parent in either (or both) directions
299 void wxWindowBase::Centre(int direction
)
301 int widthParent
, heightParent
;
303 wxWindow
*parent
= GetParent();
306 parent
->GetClientSize(&widthParent
, &heightParent
);
310 // centre with respect to the whole screen
311 wxDisplaySize(&widthParent
, &heightParent
);
315 GetSize(&width
, &height
);
320 if ( direction
& wxHORIZONTAL
)
321 xNew
= (widthParent
- width
)/2;
323 if ( direction
& wxVERTICAL
)
324 yNew
= (heightParent
- height
)/2;
326 // controls are always centered on their parent because it doesn't make
327 // sense to centre them on the screen
328 if ( (direction
& wxCENTER_FRAME
) || wxDynamicCast(this, wxControl
) )
330 // adjust to the parents client area origin
331 wxPoint posParent
= parent
->ClientToScreen(wxPoint(0, 0));
340 // fits the window around the children
341 void wxWindowBase::Fit()
346 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
348 node
= node
->GetNext() )
350 wxWindow
*win
= node
->GetData();
351 if ( win
->IsTopLevel() )
353 // dialogs and frames lie in different top level windows - don't
354 // deal with them here
359 win
->GetPosition(&wx
, &wy
);
360 win
->GetSize(&ww
, &wh
);
361 if ( wx
+ ww
> maxX
)
363 if ( wy
+ wh
> maxY
)
368 SetClientSize(maxX
+ 7, maxY
+ 14);
371 // set the min/max size of the window
373 void wxWindowBase::SetSizeHints(int minW
, int minH
,
375 int WXUNUSED(incW
), int WXUNUSED(incH
))
383 // ----------------------------------------------------------------------------
384 // show/hide/enable/disable the window
385 // ----------------------------------------------------------------------------
387 bool wxWindowBase::Show(bool show
)
389 if ( show
!= m_isShown
)
401 bool wxWindowBase::Enable(bool enable
)
403 if ( enable
!= m_isEnabled
)
405 m_isEnabled
= enable
;
414 // ----------------------------------------------------------------------------
416 // ----------------------------------------------------------------------------
418 bool wxWindowBase::IsTopLevel() const
420 return wxDynamicCast(this, wxFrame
) || wxDynamicCast(this, wxDialog
);
423 // ----------------------------------------------------------------------------
424 // reparenting the window
425 // ----------------------------------------------------------------------------
427 void wxWindowBase::AddChild(wxWindowBase
*child
)
429 wxCHECK_RET( child
, _T("can't add a NULL child") );
431 GetChildren().Append(child
);
432 child
->SetParent(this);
435 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
437 wxCHECK_RET( child
, _T("can't remove a NULL child") );
439 GetChildren().DeleteObject(child
);
440 child
->SetParent((wxWindow
*)NULL
);
443 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
445 wxWindow
*oldParent
= GetParent();
446 if ( newParent
== oldParent
)
452 // unlink this window from the existing parent.
455 oldParent
->RemoveChild(this);
459 wxTopLevelWindows
.DeleteObject(this);
462 // add it to the new one
465 newParent
->AddChild(this);
469 wxTopLevelWindows
.Append(this);
475 // ----------------------------------------------------------------------------
476 // event handler stuff
477 // ----------------------------------------------------------------------------
479 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
481 handler
->SetNextHandler(GetEventHandler());
482 SetEventHandler(handler
);
485 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
487 wxEvtHandler
*handlerA
= GetEventHandler();
490 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
491 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
492 SetEventHandler(handlerB
);
496 handlerA
= (wxEvtHandler
*)NULL
;
503 // ----------------------------------------------------------------------------
505 // ----------------------------------------------------------------------------
507 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
509 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
512 m_backgroundColour
= colour
;
517 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
519 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
522 m_foregroundColour
= colour
;
527 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
529 // don't try to set invalid cursor, always fall back to the default
530 const wxCursor
& cursorOk
= cursor
.Ok() ? cursor
: *wxSTANDARD_CURSOR
;
532 if ( cursorOk
== m_cursor
)
543 bool wxWindowBase::SetFont(const wxFont
& font
)
545 // don't try to set invalid font, always fall back to the default
546 const wxFont
& fontOk
= font
.Ok() ? font
: *wxSWISS_FONT
;
548 if ( fontOk
== m_font
)
560 void wxWindowBase::SetCaret(wxCaret
*caret
)
571 wxASSERT_MSG( m_caret
->GetWindow() == this,
572 _T("caret should be created associated to this window") );
575 #endif // wxUSE_CARET
578 // ----------------------------------------------------------------------------
580 // ----------------------------------------------------------------------------
582 void wxWindowBase::SetValidator(const wxValidator
& validator
)
584 if ( m_windowValidator
)
585 delete m_windowValidator
;
587 m_windowValidator
= (wxValidator
*)validator
.Clone();
589 if ( m_windowValidator
)
590 m_windowValidator
->SetWindow(this) ;
592 #endif // wxUSE_VALIDATORS
594 // ----------------------------------------------------------------------------
595 // update region testing
596 // ----------------------------------------------------------------------------
598 bool wxWindowBase::IsExposed(int x
, int y
) const
600 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
603 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
605 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
608 // ----------------------------------------------------------------------------
609 // find window by id or name
610 // ----------------------------------------------------------------------------
612 wxWindow
*wxWindowBase::FindWindow( long id
)
614 if ( id
== m_windowId
)
615 return (wxWindow
*)this;
617 wxWindowBase
*res
= (wxWindow
*)NULL
;
618 wxWindowList::Node
*node
;
619 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
621 wxWindowBase
*child
= node
->GetData();
622 res
= child
->FindWindow( id
);
625 return (wxWindow
*)res
;
628 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
630 if ( name
== m_windowName
)
631 return (wxWindow
*)this;
633 wxWindowBase
*res
= (wxWindow
*)NULL
;
634 wxWindowList::Node
*node
;
635 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
637 wxWindow
*child
= node
->GetData();
638 res
= child
->FindWindow(name
);
641 return (wxWindow
*)res
;
644 // ----------------------------------------------------------------------------
645 // dialog oriented functions
646 // ----------------------------------------------------------------------------
648 void wxWindowBase::MakeModal(bool modal
)
650 // Disable all other windows
653 wxWindowList::Node
*node
= wxTopLevelWindows
.GetFirst();
656 wxWindow
*win
= node
->GetData();
660 node
= node
->GetNext();
665 bool wxWindowBase::Validate()
668 wxWindowList::Node
*node
;
669 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
671 wxWindowBase
*child
= node
->GetData();
672 wxValidator
*validator
= child
->GetValidator();
673 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
678 #endif // wxUSE_VALIDATORS
683 bool wxWindowBase::TransferDataToWindow()
686 wxWindowList::Node
*node
;
687 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
689 wxWindowBase
*child
= node
->GetData();
690 wxValidator
*validator
= child
->GetValidator();
691 if ( validator
&& !validator
->TransferToWindow() )
693 wxLog
*log
= wxLog::GetActiveTarget();
696 wxLogWarning(_("Could not transfer data to window"));
703 #endif // wxUSE_VALIDATORS
708 bool wxWindowBase::TransferDataFromWindow()
711 wxWindowList::Node
*node
;
712 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
714 wxWindow
*child
= node
->GetData();
715 if ( child
->GetValidator() &&
716 !child
->GetValidator()->TransferFromWindow() )
721 #endif // wxUSE_VALIDATORS
726 void wxWindowBase::InitDialog()
728 wxInitDialogEvent
event(GetId());
729 event
.SetEventObject( this );
730 GetEventHandler()->ProcessEvent(event
);
733 // ----------------------------------------------------------------------------
735 // ----------------------------------------------------------------------------
739 void wxWindowBase::SetToolTip( const wxString
&tip
)
741 // don't create the new tooltip if we already have one
744 m_tooltip
->SetTip( tip
);
748 SetToolTip( new wxToolTip( tip
) );
751 // setting empty tooltip text does not remove the tooltip any more - use
752 // SetToolTip((wxToolTip *)NULL) for this
755 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
763 #endif // wxUSE_TOOLTIPS
765 // ----------------------------------------------------------------------------
766 // constraints and sizers
767 // ----------------------------------------------------------------------------
769 #if wxUSE_CONSTRAINTS
771 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
775 UnsetConstraints(m_constraints
);
776 delete m_constraints
;
778 m_constraints
= constraints
;
781 // Make sure other windows know they're part of a 'meaningful relationship'
782 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
783 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
784 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
785 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
786 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
787 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
788 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
789 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
790 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
791 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
792 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
793 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
794 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
795 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
796 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
797 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
801 // This removes any dangling pointers to this window in other windows'
802 // constraintsInvolvedIn lists.
803 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
807 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
808 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
809 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
810 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
811 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
812 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
813 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
814 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
815 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
816 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
817 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
818 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
819 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
820 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
821 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
822 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
826 // Back-pointer to other windows we're involved with, so if we delete this
827 // window, we must delete any constraints we're involved with.
828 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
830 if ( !m_constraintsInvolvedIn
)
831 m_constraintsInvolvedIn
= new wxWindowList
;
832 if ( !m_constraintsInvolvedIn
->Find(otherWin
) )
833 m_constraintsInvolvedIn
->Append(otherWin
);
836 // REMOVE back-pointer to other windows we're involved with.
837 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
839 if ( m_constraintsInvolvedIn
)
840 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
843 // Reset any constraints that mention this window
844 void wxWindowBase::DeleteRelatedConstraints()
846 if ( m_constraintsInvolvedIn
)
848 wxWindowList::Node
*node
= m_constraintsInvolvedIn
->GetFirst();
851 wxWindow
*win
= node
->GetData();
852 wxLayoutConstraints
*constr
= win
->GetConstraints();
854 // Reset any constraints involving this window
857 constr
->left
.ResetIfWin(this);
858 constr
->top
.ResetIfWin(this);
859 constr
->right
.ResetIfWin(this);
860 constr
->bottom
.ResetIfWin(this);
861 constr
->width
.ResetIfWin(this);
862 constr
->height
.ResetIfWin(this);
863 constr
->centreX
.ResetIfWin(this);
864 constr
->centreY
.ResetIfWin(this);
867 wxWindowList::Node
*next
= node
->GetNext();
872 delete m_constraintsInvolvedIn
;
873 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
877 void wxWindowBase::SetSizer(wxSizer
*sizer
)
879 m_windowSizer
= sizer
;
881 sizer
->SetSizerParent(this);
884 bool wxWindowBase::Layout()
886 if ( GetConstraints() )
889 GetClientSize(&w
, &h
);
890 GetConstraints()->width
.SetValue(w
);
891 GetConstraints()->height
.SetValue(h
);
894 // If top level (one sizer), evaluate the sizer's constraints.
898 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
899 GetSizer()->LayoutPhase1(&noChanges
);
900 GetSizer()->LayoutPhase2(&noChanges
);
901 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
906 // Otherwise, evaluate child constraints
907 ResetConstraints(); // Mark all constraints as unevaluated
908 DoPhase(1); // Just one phase need if no sizers involved
910 SetConstraintSizes(); // Recursively set the real window sizes
916 // Do a phase of evaluating constraints: the default behaviour. wxSizers may
917 // do a similar thing, but also impose their own 'constraints' and order the
918 // evaluation differently.
919 bool wxWindowBase::LayoutPhase1(int *noChanges
)
921 wxLayoutConstraints
*constr
= GetConstraints();
924 return constr
->SatisfyConstraints(this, noChanges
);
930 bool wxWindowBase::LayoutPhase2(int *noChanges
)
940 // Do a phase of evaluating child constraints
941 bool wxWindowBase::DoPhase(int phase
)
943 int noIterations
= 0;
944 int maxIterations
= 500;
947 wxWindowList succeeded
;
948 while ((noChanges
> 0) && (noIterations
< maxIterations
))
952 wxWindowList::Node
*node
= GetChildren().GetFirst();
955 wxWindow
*child
= node
->GetData();
956 if ( !child
->IsTopLevel() )
958 wxLayoutConstraints
*constr
= child
->GetConstraints();
961 if ( !succeeded
.Find(child
) )
963 int tempNoChanges
= 0;
964 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
965 noChanges
+= tempNoChanges
;
968 succeeded
.Append(child
);
973 node
= node
->GetNext();
982 void wxWindowBase::ResetConstraints()
984 wxLayoutConstraints
*constr
= GetConstraints();
987 constr
->left
.SetDone(FALSE
);
988 constr
->top
.SetDone(FALSE
);
989 constr
->right
.SetDone(FALSE
);
990 constr
->bottom
.SetDone(FALSE
);
991 constr
->width
.SetDone(FALSE
);
992 constr
->height
.SetDone(FALSE
);
993 constr
->centreX
.SetDone(FALSE
);
994 constr
->centreY
.SetDone(FALSE
);
996 wxWindowList::Node
*node
= GetChildren().GetFirst();
999 wxWindow
*win
= node
->GetData();
1000 if ( !win
->IsTopLevel() )
1001 win
->ResetConstraints();
1002 node
= node
->GetNext();
1006 // Need to distinguish between setting the 'fake' size for windows and sizers,
1007 // and setting the real values.
1008 void wxWindowBase::SetConstraintSizes(bool recurse
)
1010 wxLayoutConstraints
*constr
= GetConstraints();
1011 if ( constr
&& constr
->left
.GetDone() && constr
->right
.GetDone( ) &&
1012 constr
->width
.GetDone() && constr
->height
.GetDone())
1014 int x
= constr
->left
.GetValue();
1015 int y
= constr
->top
.GetValue();
1016 int w
= constr
->width
.GetValue();
1017 int h
= constr
->height
.GetValue();
1019 // If we don't want to resize this window, just move it...
1020 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1021 (constr
->height
.GetRelationship() != wxAsIs
))
1023 // Calls Layout() recursively. AAAGH. How can we stop that.
1024 // Simply take Layout() out of non-top level OnSizes.
1025 SizerSetSize(x
, y
, w
, h
);
1034 wxChar
*windowClass
= GetClassInfo()->GetClassName();
1037 if ( GetName() == _T("") )
1038 winName
= _T("unnamed");
1040 winName
= GetName();
1041 wxLogDebug( _T("Constraint(s) not satisfied for window of type %s, name %s:\n"),
1042 (const wxChar
*)windowClass
,
1043 (const wxChar
*)winName
);
1044 if ( !constr
->left
.GetDone()) wxLogDebug( _T(" unsatisfied 'left' constraint.\n") );
1045 if ( !constr
->right
.GetDone()) wxLogDebug( _T(" unsatisfied 'right' constraint.\n") );
1046 if ( !constr
->width
.GetDone()) wxLogDebug( _T(" unsatisfied 'width' constraint.\n") );
1047 if ( !constr
->height
.GetDone()) wxLogDebug( _T(" unsatisfied 'height' constraint.\n") );
1048 wxLogDebug( _T("Please check constraints: try adding AsIs() constraints.\n") );
1053 wxWindowList::Node
*node
= GetChildren().GetFirst();
1056 wxWindow
*win
= node
->GetData();
1057 if ( !win
->IsTopLevel() )
1058 win
->SetConstraintSizes();
1059 node
= node
->GetNext();
1064 // This assumes that all sizers are 'on' the same window, i.e. the parent of
1066 void wxWindowBase::TransformSizerToActual(int *x
, int *y
) const
1068 if ( !m_sizerParent
|| m_sizerParent
->IsTopLevel() )
1072 m_sizerParent
->GetPosition(&xp
, &yp
);
1073 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
1078 void wxWindowBase::SizerSetSize(int x
, int y
, int w
, int h
)
1082 TransformSizerToActual(&xx
, &yy
);
1083 SetSize(xx
, yy
, w
, h
);
1086 void wxWindowBase::SizerMove(int x
, int y
)
1090 TransformSizerToActual(&xx
, &yy
);
1094 // Only set the size/position of the constraint (if any)
1095 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1097 wxLayoutConstraints
*constr
= GetConstraints();
1102 constr
->left
.SetValue(x
);
1103 constr
->left
.SetDone(TRUE
);
1107 constr
->top
.SetValue(y
);
1108 constr
->top
.SetDone(TRUE
);
1112 constr
->width
.SetValue(w
);
1113 constr
->width
.SetDone(TRUE
);
1117 constr
->height
.SetValue(h
);
1118 constr
->height
.SetDone(TRUE
);
1123 void wxWindowBase::MoveConstraint(int x
, int y
)
1125 wxLayoutConstraints
*constr
= GetConstraints();
1130 constr
->left
.SetValue(x
);
1131 constr
->left
.SetDone(TRUE
);
1135 constr
->top
.SetValue(y
);
1136 constr
->top
.SetDone(TRUE
);
1141 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1143 wxLayoutConstraints
*constr
= GetConstraints();
1146 *w
= constr
->width
.GetValue();
1147 *h
= constr
->height
.GetValue();
1153 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1155 wxLayoutConstraints
*constr
= GetConstraints();
1158 *w
= constr
->width
.GetValue();
1159 *h
= constr
->height
.GetValue();
1162 GetClientSize(w
, h
);
1165 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1167 wxLayoutConstraints
*constr
= GetConstraints();
1170 *x
= constr
->left
.GetValue();
1171 *y
= constr
->top
.GetValue();
1177 #endif // wxUSE_CONSTRAINTS
1179 // ----------------------------------------------------------------------------
1180 // do Update UI processing for child controls
1181 // ----------------------------------------------------------------------------
1183 // TODO: should this be implemented for the child window rather
1184 // than the parent? Then you can override it e.g. for wxCheckBox
1185 // to do the Right Thing rather than having to assume a fixed number
1186 // of control classes.
1187 void wxWindowBase::UpdateWindowUI()
1189 wxWindowID id
= GetId();
1192 wxUpdateUIEvent
event(id
);
1193 event
.m_eventObject
= this;
1195 if ( GetEventHandler()->ProcessEvent(event
) )
1197 if ( event
.GetSetEnabled() )
1198 Enable(event
.GetEnabled());
1200 if ( event
.GetSetText() )
1202 wxControl
*control
= wxDynamicCast(this, wxControl
);
1204 control
->SetLabel(event
.GetText());
1208 wxCheckBox
*checkbox
= wxDynamicCast(this, wxCheckBox
);
1211 if ( event
.GetSetChecked() )
1212 checkbox
->SetValue(event
.GetChecked());
1214 #endif // wxUSE_CHECKBOX
1216 #if wxUSE_RADIOBUTTON
1217 wxRadioButton
*radiobtn
= wxDynamicCast(this, wxRadioButton
);
1220 if ( event
.GetSetChecked() )
1221 radiobtn
->SetValue(event
.GetChecked());
1223 #endif // wxUSE_RADIOBUTTON
1228 // ----------------------------------------------------------------------------
1229 // dialog units translations
1230 // ----------------------------------------------------------------------------
1232 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1234 int charWidth
= GetCharWidth();
1235 int charHeight
= GetCharHeight();
1236 wxPoint
pt2(-1, -1);
1238 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1240 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1245 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1247 int charWidth
= GetCharWidth();
1248 int charHeight
= GetCharHeight();
1249 wxPoint
pt2(-1, -1);
1251 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1253 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1258 // ----------------------------------------------------------------------------
1260 // ----------------------------------------------------------------------------
1262 // propagate the colour change event to the subwindows
1263 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1265 wxWindowList::Node
*node
= GetChildren().GetFirst();
1268 // Only propagate to non-top-level windows
1269 wxWindow
*win
= node
->GetData();
1270 if ( !win
->IsTopLevel() )
1272 wxSysColourChangedEvent event2
;
1273 event
.m_eventObject
= win
;
1274 win
->GetEventHandler()->ProcessEvent(event2
);
1277 node
= node
->GetNext();
1281 // the default action is to populate dialog with data when it's created
1282 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1284 TransferDataToWindow();
1287 // ----------------------------------------------------------------------------
1288 // list classes implementation
1289 // ----------------------------------------------------------------------------
1291 void wxWindowListNode::DeleteData()
1293 delete (wxWindow
*)GetData();