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"
47 #endif // wxUSE_CONSTRAINTS
49 #if wxUSE_DRAG_AND_DROP
51 #endif // wxUSE_DRAG_AND_DROP
54 #include "wx/tooltip.h"
55 #endif // wxUSE_TOOLTIPS
61 // ----------------------------------------------------------------------------
63 // ----------------------------------------------------------------------------
65 int wxWindowBase::ms_lastControlId
= -200;
67 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
69 // ----------------------------------------------------------------------------
71 // ----------------------------------------------------------------------------
73 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
74 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
75 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
78 // ============================================================================
79 // implementation of the common functionality of the wxWindow class
80 // ============================================================================
82 // ----------------------------------------------------------------------------
84 // ----------------------------------------------------------------------------
86 // the default initialization
87 void wxWindowBase::InitBase()
89 // no window yet, no parent nor children
90 m_parent
= (wxWindow
*)NULL
;
92 m_children
.DeleteContents( FALSE
); // don't auto delete node data
94 // no constraints on the minimal window size
100 // window is created enabled but it's not visible yet
104 // no client data (yet)
106 m_clientDataType
= ClientData_None
;
108 // the default event handler is just this window
109 m_eventHandler
= this;
113 m_windowValidator
= (wxValidator
*) NULL
;
114 #endif // wxUSE_VALIDATORS
116 // use the system default colours
117 wxSystemSettings settings
;
119 m_backgroundColour
= settings
.GetSystemColour(wxSYS_COLOUR_BTNFACE
);
120 m_foregroundColour
= *wxBLACK
; // TODO take this from sys settings too?
121 m_font
= *wxSWISS_FONT
; // and this?
126 // an optimization for the event processing: checking this flag is much
127 // faster than using IsKindOf(CLASSINFO(wxWindow))
130 #if wxUSE_CONSTRAINTS
131 // no constraints whatsoever
132 m_constraints
= (wxLayoutConstraints
*) NULL
;
133 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
134 m_windowSizer
= (wxSizer
*) 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 wxValidator
& validator
,
158 const wxString
& name
)
160 // m_isWindow is set to TRUE in wxWindowBase::Init() as well as many other
161 // member variables - check that it has been called (will catch the case
162 // when a new ctor is added which doesn't call InitWindow)
163 wxASSERT_MSG( m_isWindow
, wxT("Init() must have been called before!") );
165 // generate a new id if the user doesn't care about it
166 m_windowId
= id
== -1 ? NewControlId() : id
;
169 SetWindowStyleFlag(style
);
171 SetValidator(validator
);
176 // ----------------------------------------------------------------------------
178 // ----------------------------------------------------------------------------
181 wxWindowBase::~wxWindowBase()
183 // FIXME if these 2 cases result from programming errors in the user code
184 // we should probably assert here instead of silently fixing them
186 // Just in case the window has been Closed, but we're then deleting
187 // immediately: don't leave dangling pointers.
188 wxPendingDelete
.DeleteObject(this);
190 // Just in case we've loaded a top-level window via LoadNativeDialog but
191 // we weren't a dialog class
192 wxTopLevelWindows
.DeleteObject(this);
194 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
196 // make sure that there are no dangling pointers left pointing to us
197 wxPanel
*panel
= wxDynamicCast(GetParent(), wxPanel
);
200 if ( panel
->GetLastFocus() == this )
202 panel
->SetLastFocus((wxWindow
*)NULL
);
209 #endif // wxUSE_CARET
212 if ( m_windowValidator
)
213 delete m_windowValidator
;
214 #endif // wxUSE_VALIDATORS
216 // we only delete object data, not untyped
217 if ( m_clientDataType
== ClientData_Object
)
218 delete m_clientObject
;
220 #if wxUSE_CONSTRAINTS
221 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
222 // at deleted windows as they delete themselves.
223 DeleteRelatedConstraints();
227 // This removes any dangling pointers to this window in other windows'
228 // constraintsInvolvedIn lists.
229 UnsetConstraints(m_constraints
);
230 delete m_constraints
;
231 m_constraints
= NULL
;
235 delete m_windowSizer
;
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
, wxT("children list contains empty nodes") );
287 wxASSERT_MSG( !GetChildren().Find(child
),
288 wxT("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();
307 direction
|= wxCENTRE_ON_SCREEN
;
310 if ( direction
& wxCENTRE_ON_SCREEN
)
312 // centre with respect to the whole screen
313 wxDisplaySize(&widthParent
, &heightParent
);
317 // centre inside the parents rectangle
318 parent
->GetClientSize(&widthParent
, &heightParent
);
322 GetSize(&width
, &height
);
327 if ( direction
& wxHORIZONTAL
)
328 xNew
= (widthParent
- width
)/2;
330 if ( direction
& wxVERTICAL
)
331 yNew
= (heightParent
- height
)/2;
333 // controls are always centered on their parent because it doesn't make
334 // sense to centre them on the screen
335 if ( !(direction
& wxCENTRE_ON_SCREEN
) || wxDynamicCast(this, wxControl
) )
337 // theo nly chance to get this is to have a wxControl without parent
338 wxCHECK_RET( parent
, wxT("a control must have a parent") );
340 // adjust to the parents client area origin
341 wxPoint posParent
= parent
->ClientToScreen(wxPoint(0, 0));
350 // fits the window around the children
351 void wxWindowBase::Fit()
356 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
358 node
= node
->GetNext() )
360 wxWindow
*win
= node
->GetData();
361 if ( win
->IsTopLevel() )
363 // dialogs and frames lie in different top level windows - don't
364 // deal with them here
369 win
->GetPosition(&wx
, &wy
);
370 win
->GetSize(&ww
, &wh
);
371 if ( wx
+ ww
> maxX
)
373 if ( wy
+ wh
> maxY
)
378 SetClientSize(maxX
+ 7, maxY
+ 14);
381 // set the min/max size of the window
383 void wxWindowBase::SetSizeHints(int minW
, int minH
,
385 int WXUNUSED(incW
), int WXUNUSED(incH
))
393 // ----------------------------------------------------------------------------
394 // show/hide/enable/disable the window
395 // ----------------------------------------------------------------------------
397 bool wxWindowBase::Show(bool show
)
399 if ( show
!= m_isShown
)
411 bool wxWindowBase::Enable(bool enable
)
413 if ( enable
!= m_isEnabled
)
415 m_isEnabled
= enable
;
424 // ----------------------------------------------------------------------------
426 // ----------------------------------------------------------------------------
428 bool wxWindowBase::IsTopLevel() const
433 // ----------------------------------------------------------------------------
434 // reparenting the window
435 // ----------------------------------------------------------------------------
437 void wxWindowBase::AddChild(wxWindowBase
*child
)
439 wxCHECK_RET( child
, wxT("can't add a NULL child") );
441 GetChildren().Append(child
);
442 child
->SetParent(this);
445 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
447 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
449 GetChildren().DeleteObject(child
);
450 child
->SetParent((wxWindow
*)NULL
);
453 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
455 wxWindow
*oldParent
= GetParent();
456 if ( newParent
== oldParent
)
462 // unlink this window from the existing parent.
465 oldParent
->RemoveChild(this);
469 wxTopLevelWindows
.DeleteObject(this);
472 // add it to the new one
475 newParent
->AddChild(this);
479 wxTopLevelWindows
.Append(this);
485 // ----------------------------------------------------------------------------
486 // event handler stuff
487 // ----------------------------------------------------------------------------
489 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
491 handler
->SetNextHandler(GetEventHandler());
492 SetEventHandler(handler
);
495 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
497 wxEvtHandler
*handlerA
= GetEventHandler();
500 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
501 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
502 SetEventHandler(handlerB
);
506 handlerA
= (wxEvtHandler
*)NULL
;
513 // ----------------------------------------------------------------------------
515 // ----------------------------------------------------------------------------
517 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
519 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
522 m_backgroundColour
= colour
;
527 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
529 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
532 m_foregroundColour
= colour
;
537 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
539 // don't try to set invalid cursor, always fall back to the default
540 const wxCursor
& cursorOk
= cursor
.Ok() ? cursor
: *wxSTANDARD_CURSOR
;
542 if ( (wxCursor
&)cursorOk
== m_cursor
)
553 bool wxWindowBase::SetFont(const wxFont
& font
)
555 // don't try to set invalid font, always fall back to the default
556 const wxFont
& fontOk
= font
.Ok() ? font
: *wxSWISS_FONT
;
558 if ( (wxFont
&)fontOk
== m_font
)
570 void wxWindowBase::SetCaret(wxCaret
*caret
)
581 wxASSERT_MSG( m_caret
->GetWindow() == this,
582 wxT("caret should be created associated to this window") );
585 #endif // wxUSE_CARET
588 // ----------------------------------------------------------------------------
590 // ----------------------------------------------------------------------------
592 void wxWindowBase::SetValidator(const wxValidator
& validator
)
594 if ( m_windowValidator
)
595 delete m_windowValidator
;
597 m_windowValidator
= (wxValidator
*)validator
.Clone();
599 if ( m_windowValidator
)
600 m_windowValidator
->SetWindow(this) ;
602 #endif // wxUSE_VALIDATORS
604 // ----------------------------------------------------------------------------
605 // update region testing
606 // ----------------------------------------------------------------------------
608 bool wxWindowBase::IsExposed(int x
, int y
) const
610 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
613 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
615 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
618 // ----------------------------------------------------------------------------
619 // find window by id or name
620 // ----------------------------------------------------------------------------
622 wxWindow
*wxWindowBase::FindWindow( long id
)
624 if ( id
== m_windowId
)
625 return (wxWindow
*)this;
627 wxWindowBase
*res
= (wxWindow
*)NULL
;
628 wxWindowList::Node
*node
;
629 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
631 wxWindowBase
*child
= node
->GetData();
632 res
= child
->FindWindow( id
);
635 return (wxWindow
*)res
;
638 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
640 if ( name
== m_windowName
)
641 return (wxWindow
*)this;
643 wxWindowBase
*res
= (wxWindow
*)NULL
;
644 wxWindowList::Node
*node
;
645 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
647 wxWindow
*child
= node
->GetData();
648 res
= child
->FindWindow(name
);
651 return (wxWindow
*)res
;
654 // ----------------------------------------------------------------------------
655 // dialog oriented functions
656 // ----------------------------------------------------------------------------
658 void wxWindowBase::MakeModal(bool modal
)
660 // Disable all other windows
663 wxWindowList::Node
*node
= wxTopLevelWindows
.GetFirst();
666 wxWindow
*win
= node
->GetData();
670 node
= node
->GetNext();
675 bool wxWindowBase::Validate()
678 wxWindowList::Node
*node
;
679 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
681 wxWindowBase
*child
= node
->GetData();
682 wxValidator
*validator
= child
->GetValidator();
683 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
688 #endif // wxUSE_VALIDATORS
693 bool wxWindowBase::TransferDataToWindow()
696 wxWindowList::Node
*node
;
697 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
699 wxWindowBase
*child
= node
->GetData();
700 wxValidator
*validator
= child
->GetValidator();
701 if ( validator
&& !validator
->TransferToWindow() )
703 wxLog
*log
= wxLog::GetActiveTarget();
706 wxLogWarning(_("Could not transfer data to window"));
713 #endif // wxUSE_VALIDATORS
718 bool wxWindowBase::TransferDataFromWindow()
721 wxWindowList::Node
*node
;
722 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
724 wxWindow
*child
= node
->GetData();
725 if ( child
->GetValidator() &&
726 !child
->GetValidator()->TransferFromWindow() )
731 #endif // wxUSE_VALIDATORS
736 void wxWindowBase::InitDialog()
738 wxInitDialogEvent
event(GetId());
739 event
.SetEventObject( this );
740 GetEventHandler()->ProcessEvent(event
);
743 // ----------------------------------------------------------------------------
745 // ----------------------------------------------------------------------------
749 void wxWindowBase::SetToolTip( const wxString
&tip
)
751 // don't create the new tooltip if we already have one
754 m_tooltip
->SetTip( tip
);
758 SetToolTip( new wxToolTip( tip
) );
761 // setting empty tooltip text does not remove the tooltip any more - use
762 // SetToolTip((wxToolTip *)NULL) for this
765 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
773 #endif // wxUSE_TOOLTIPS
775 // ----------------------------------------------------------------------------
776 // constraints and sizers
777 // ----------------------------------------------------------------------------
779 #if wxUSE_CONSTRAINTS
781 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
785 UnsetConstraints(m_constraints
);
786 delete m_constraints
;
788 m_constraints
= constraints
;
791 // Make sure other windows know they're part of a 'meaningful relationship'
792 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
793 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
794 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
795 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
796 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
797 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
798 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
799 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
800 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
801 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
802 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
803 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
804 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
805 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
806 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
807 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
811 // This removes any dangling pointers to this window in other windows'
812 // constraintsInvolvedIn lists.
813 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
817 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
818 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
819 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
820 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
821 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
822 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
823 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
824 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
825 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
826 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
827 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
828 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
829 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
830 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
831 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
832 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
836 // Back-pointer to other windows we're involved with, so if we delete this
837 // window, we must delete any constraints we're involved with.
838 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
840 if ( !m_constraintsInvolvedIn
)
841 m_constraintsInvolvedIn
= new wxWindowList
;
842 if ( !m_constraintsInvolvedIn
->Find(otherWin
) )
843 m_constraintsInvolvedIn
->Append(otherWin
);
846 // REMOVE back-pointer to other windows we're involved with.
847 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
849 if ( m_constraintsInvolvedIn
)
850 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
853 // Reset any constraints that mention this window
854 void wxWindowBase::DeleteRelatedConstraints()
856 if ( m_constraintsInvolvedIn
)
858 wxWindowList::Node
*node
= m_constraintsInvolvedIn
->GetFirst();
861 wxWindow
*win
= node
->GetData();
862 wxLayoutConstraints
*constr
= win
->GetConstraints();
864 // Reset any constraints involving this window
867 constr
->left
.ResetIfWin(this);
868 constr
->top
.ResetIfWin(this);
869 constr
->right
.ResetIfWin(this);
870 constr
->bottom
.ResetIfWin(this);
871 constr
->width
.ResetIfWin(this);
872 constr
->height
.ResetIfWin(this);
873 constr
->centreX
.ResetIfWin(this);
874 constr
->centreY
.ResetIfWin(this);
877 wxWindowList::Node
*next
= node
->GetNext();
882 delete m_constraintsInvolvedIn
;
883 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
887 void wxWindowBase::SetSizer(wxSizer
*sizer
)
889 if (m_windowSizer
) delete m_windowSizer
;
891 m_windowSizer
= sizer
;
894 bool wxWindowBase::Layout()
897 GetClientSize(&w
, &h
);
899 // If there is a sizer, use it instead of the constraints
902 GetSizer()->SetDimension( 0, 0, w
, h
);
906 if ( GetConstraints() )
908 GetConstraints()->width
.SetValue(w
);
909 GetConstraints()->height
.SetValue(h
);
912 // Evaluate child constraints
913 ResetConstraints(); // Mark all constraints as unevaluated
914 DoPhase(1); // Just one phase need if no sizers involved
916 SetConstraintSizes(); // Recursively set the real window sizes
922 // Do a phase of evaluating constraints: the default behaviour. wxSizers may
923 // do a similar thing, but also impose their own 'constraints' and order the
924 // evaluation differently.
925 bool wxWindowBase::LayoutPhase1(int *noChanges
)
927 wxLayoutConstraints
*constr
= GetConstraints();
930 return constr
->SatisfyConstraints(this, noChanges
);
936 bool wxWindowBase::LayoutPhase2(int *noChanges
)
946 // Do a phase of evaluating child constraints
947 bool wxWindowBase::DoPhase(int phase
)
949 int noIterations
= 0;
950 int maxIterations
= 500;
953 wxWindowList succeeded
;
954 while ((noChanges
> 0) && (noIterations
< maxIterations
))
958 wxWindowList::Node
*node
= GetChildren().GetFirst();
961 wxWindow
*child
= node
->GetData();
962 if ( !child
->IsTopLevel() )
964 wxLayoutConstraints
*constr
= child
->GetConstraints();
967 if ( !succeeded
.Find(child
) )
969 int tempNoChanges
= 0;
970 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
971 noChanges
+= tempNoChanges
;
974 succeeded
.Append(child
);
979 node
= node
->GetNext();
988 void wxWindowBase::ResetConstraints()
990 wxLayoutConstraints
*constr
= GetConstraints();
993 constr
->left
.SetDone(FALSE
);
994 constr
->top
.SetDone(FALSE
);
995 constr
->right
.SetDone(FALSE
);
996 constr
->bottom
.SetDone(FALSE
);
997 constr
->width
.SetDone(FALSE
);
998 constr
->height
.SetDone(FALSE
);
999 constr
->centreX
.SetDone(FALSE
);
1000 constr
->centreY
.SetDone(FALSE
);
1002 wxWindowList::Node
*node
= GetChildren().GetFirst();
1005 wxWindow
*win
= node
->GetData();
1006 if ( !win
->IsTopLevel() )
1007 win
->ResetConstraints();
1008 node
= node
->GetNext();
1012 // Need to distinguish between setting the 'fake' size for windows and sizers,
1013 // and setting the real values.
1014 void wxWindowBase::SetConstraintSizes(bool recurse
)
1016 wxLayoutConstraints
*constr
= GetConstraints();
1017 if ( constr
&& constr
->left
.GetDone() && constr
->right
.GetDone( ) &&
1018 constr
->width
.GetDone() && constr
->height
.GetDone())
1020 int x
= constr
->left
.GetValue();
1021 int y
= constr
->top
.GetValue();
1022 int w
= constr
->width
.GetValue();
1023 int h
= constr
->height
.GetValue();
1025 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1026 (constr
->height
.GetRelationship() != wxAsIs
) )
1028 SetSize(x
, y
, w
, h
);
1032 // If we don't want to resize this window, just move it...
1038 wxChar
*windowClass
= GetClassInfo()->GetClassName();
1041 if ( GetName() == wxT("") )
1042 winName
= wxT("unnamed");
1044 winName
= GetName();
1045 wxLogDebug( wxT("Constraint(s) not satisfied for window of type %s, name %s:\n"),
1046 (const wxChar
*)windowClass
,
1047 (const wxChar
*)winName
);
1048 if ( !constr
->left
.GetDone()) wxLogDebug( wxT(" unsatisfied 'left' constraint.\n") );
1049 if ( !constr
->right
.GetDone()) wxLogDebug( wxT(" unsatisfied 'right' constraint.\n") );
1050 if ( !constr
->width
.GetDone()) wxLogDebug( wxT(" unsatisfied 'width' constraint.\n") );
1051 if ( !constr
->height
.GetDone()) wxLogDebug( wxT(" unsatisfied 'height' constraint.\n") );
1052 wxLogDebug( wxT("Please check constraints: try adding AsIs() constraints.\n") );
1057 wxWindowList::Node
*node
= GetChildren().GetFirst();
1060 wxWindow
*win
= node
->GetData();
1061 if ( !win
->IsTopLevel() )
1062 win
->SetConstraintSizes();
1063 node
= node
->GetNext();
1068 // Only set the size/position of the constraint (if any)
1069 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1071 wxLayoutConstraints
*constr
= GetConstraints();
1076 constr
->left
.SetValue(x
);
1077 constr
->left
.SetDone(TRUE
);
1081 constr
->top
.SetValue(y
);
1082 constr
->top
.SetDone(TRUE
);
1086 constr
->width
.SetValue(w
);
1087 constr
->width
.SetDone(TRUE
);
1091 constr
->height
.SetValue(h
);
1092 constr
->height
.SetDone(TRUE
);
1097 void wxWindowBase::MoveConstraint(int x
, int y
)
1099 wxLayoutConstraints
*constr
= GetConstraints();
1104 constr
->left
.SetValue(x
);
1105 constr
->left
.SetDone(TRUE
);
1109 constr
->top
.SetValue(y
);
1110 constr
->top
.SetDone(TRUE
);
1115 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1117 wxLayoutConstraints
*constr
= GetConstraints();
1120 *w
= constr
->width
.GetValue();
1121 *h
= constr
->height
.GetValue();
1127 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1129 wxLayoutConstraints
*constr
= GetConstraints();
1132 *w
= constr
->width
.GetValue();
1133 *h
= constr
->height
.GetValue();
1136 GetClientSize(w
, h
);
1139 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1141 wxLayoutConstraints
*constr
= GetConstraints();
1144 *x
= constr
->left
.GetValue();
1145 *y
= constr
->top
.GetValue();
1151 #endif // wxUSE_CONSTRAINTS
1153 // ----------------------------------------------------------------------------
1154 // do Update UI processing for child controls
1155 // ----------------------------------------------------------------------------
1157 // TODO: should this be implemented for the child window rather
1158 // than the parent? Then you can override it e.g. for wxCheckBox
1159 // to do the Right Thing rather than having to assume a fixed number
1160 // of control classes.
1161 void wxWindowBase::UpdateWindowUI()
1163 wxWindowID id
= GetId();
1166 wxUpdateUIEvent
event(id
);
1167 event
.m_eventObject
= this;
1169 if ( GetEventHandler()->ProcessEvent(event
) )
1171 if ( event
.GetSetEnabled() )
1172 Enable(event
.GetEnabled());
1174 if ( event
.GetSetText() )
1176 wxControl
*control
= wxDynamicCast(this, wxControl
);
1178 control
->SetLabel(event
.GetText());
1182 wxCheckBox
*checkbox
= wxDynamicCast(this, wxCheckBox
);
1185 if ( event
.GetSetChecked() )
1186 checkbox
->SetValue(event
.GetChecked());
1188 #endif // wxUSE_CHECKBOX
1190 #if wxUSE_RADIOBUTTON
1191 wxRadioButton
*radiobtn
= wxDynamicCast(this, wxRadioButton
);
1194 if ( event
.GetSetChecked() )
1195 radiobtn
->SetValue(event
.GetChecked());
1197 #endif // wxUSE_RADIOBUTTON
1202 // ----------------------------------------------------------------------------
1203 // dialog units translations
1204 // ----------------------------------------------------------------------------
1206 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1208 int charWidth
= GetCharWidth();
1209 int charHeight
= GetCharHeight();
1210 wxPoint
pt2(-1, -1);
1212 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1214 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1219 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1221 int charWidth
= GetCharWidth();
1222 int charHeight
= GetCharHeight();
1223 wxPoint
pt2(-1, -1);
1225 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1227 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1232 // ----------------------------------------------------------------------------
1234 // ----------------------------------------------------------------------------
1236 void wxWindowBase::DoSetClientObject( wxClientData
*data
)
1238 wxASSERT_MSG( m_clientDataType
!= ClientData_Void
,
1239 wxT("can't have both object and void client data") );
1241 if ( m_clientObject
)
1242 delete m_clientObject
;
1244 m_clientObject
= data
;
1245 m_clientDataType
= ClientData_Object
;
1248 wxClientData
*wxWindowBase::DoGetClientObject() const
1250 wxASSERT_MSG( m_clientDataType
== ClientData_Object
,
1251 wxT("this window doesn't have object client data") );
1253 return m_clientObject
;
1256 void wxWindowBase::DoSetClientData( void *data
)
1258 wxASSERT_MSG( m_clientDataType
!= ClientData_Object
,
1259 wxT("can't have both object and void client data") );
1261 m_clientData
= data
;
1262 m_clientDataType
= ClientData_Void
;
1265 void *wxWindowBase::DoGetClientData() const
1267 wxASSERT_MSG( m_clientDataType
== ClientData_Void
,
1268 wxT("this window doesn't have void client data") );
1270 return m_clientData
;
1273 // ----------------------------------------------------------------------------
1275 // ----------------------------------------------------------------------------
1277 // propagate the colour change event to the subwindows
1278 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1280 wxWindowList::Node
*node
= GetChildren().GetFirst();
1283 // Only propagate to non-top-level windows
1284 wxWindow
*win
= node
->GetData();
1285 if ( !win
->IsTopLevel() )
1287 wxSysColourChangedEvent event2
;
1288 event
.m_eventObject
= win
;
1289 win
->GetEventHandler()->ProcessEvent(event2
);
1292 node
= node
->GetNext();
1296 // the default action is to populate dialog with data when it's created
1297 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1299 TransferDataToWindow();
1302 // ----------------------------------------------------------------------------
1303 // list classes implementation
1304 // ----------------------------------------------------------------------------
1306 void wxWindowListNode::DeleteData()
1308 delete (wxWindow
*)GetData();