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
103 // no client data (yet)
105 m_clientDataType
= ClientData_None
;
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 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
, _T("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, _T("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 if ( m_clientObject
)
217 delete m_clientObject
;
219 #if wxUSE_CONSTRAINTS
220 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
221 // at deleted windows as they delete themselves.
222 DeleteRelatedConstraints();
226 // This removes any dangling pointers to this window in other windows'
227 // constraintsInvolvedIn lists.
228 UnsetConstraints(m_constraints
);
229 delete m_constraints
;
230 m_constraints
= NULL
;
234 delete m_windowSizer
;
236 // If this is a child of a sizer, remove self from parent
238 m_sizerParent
->RemoveChild(this);
239 #endif // wxUSE_CONSTRAINTS
241 #if wxUSE_DRAG_AND_DROP
244 #endif // wxUSE_DRAG_AND_DROP
249 #endif // wxUSE_TOOLTIPS
252 bool wxWindowBase::Destroy()
259 bool wxWindowBase::Close(bool force
)
261 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
262 event
.SetEventObject(this);
263 #if WXWIN_COMPATIBILITY
264 event
.SetForce(force
);
265 #endif // WXWIN_COMPATIBILITY
266 event
.SetCanVeto(!force
);
268 // return FALSE if window wasn't closed because the application vetoed the
270 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
273 bool wxWindowBase::DestroyChildren()
275 wxWindowList::Node
*node
;
278 // we iterate until the list becomes empty
279 node
= GetChildren().GetFirst();
283 wxWindow
*child
= node
->GetData();
285 wxASSERT_MSG( child
, _T("children list contains empty nodes") );
289 wxASSERT_MSG( !GetChildren().Find(child
),
290 _T("child didn't remove itself using RemoveChild()") );
296 // ----------------------------------------------------------------------------
297 // centre/fit the window
298 // ----------------------------------------------------------------------------
300 // centre the window with respect to its parent in either (or both) directions
301 void wxWindowBase::Centre(int direction
)
303 int widthParent
, heightParent
;
305 wxWindow
*parent
= GetParent();
308 parent
->GetClientSize(&widthParent
, &heightParent
);
312 // centre with respect to the whole screen
313 wxDisplaySize(&widthParent
, &heightParent
);
317 GetSize(&width
, &height
);
322 if ( direction
& wxHORIZONTAL
)
323 xNew
= (widthParent
- width
)/2;
325 if ( direction
& wxVERTICAL
)
326 yNew
= (heightParent
- height
)/2;
328 // controls are always centered on their parent because it doesn't make
329 // sense to centre them on the screen
330 if ( (direction
& wxCENTER_FRAME
) || wxDynamicCast(this, wxControl
) )
332 // adjust to the parents client area origin
333 wxPoint posParent
= parent
->ClientToScreen(wxPoint(0, 0));
342 // fits the window around the children
343 void wxWindowBase::Fit()
348 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
350 node
= node
->GetNext() )
352 wxWindow
*win
= node
->GetData();
353 if ( win
->IsTopLevel() )
355 // dialogs and frames lie in different top level windows - don't
356 // deal with them here
361 win
->GetPosition(&wx
, &wy
);
362 win
->GetSize(&ww
, &wh
);
363 if ( wx
+ ww
> maxX
)
365 if ( wy
+ wh
> maxY
)
370 SetClientSize(maxX
+ 7, maxY
+ 14);
373 // set the min/max size of the window
375 void wxWindowBase::SetSizeHints(int minW
, int minH
,
377 int WXUNUSED(incW
), int WXUNUSED(incH
))
385 // ----------------------------------------------------------------------------
386 // show/hide/enable/disable the window
387 // ----------------------------------------------------------------------------
389 bool wxWindowBase::Show(bool show
)
391 if ( show
!= m_isShown
)
403 bool wxWindowBase::Enable(bool enable
)
405 if ( enable
!= m_isEnabled
)
407 m_isEnabled
= enable
;
416 // ----------------------------------------------------------------------------
418 // ----------------------------------------------------------------------------
420 bool wxWindowBase::IsTopLevel() const
422 return wxDynamicCast(this, wxFrame
) || wxDynamicCast(this, wxDialog
);
425 // ----------------------------------------------------------------------------
426 // reparenting the window
427 // ----------------------------------------------------------------------------
429 void wxWindowBase::AddChild(wxWindowBase
*child
)
431 wxCHECK_RET( child
, _T("can't add a NULL child") );
433 GetChildren().Append(child
);
434 child
->SetParent(this);
437 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
439 wxCHECK_RET( child
, _T("can't remove a NULL child") );
441 GetChildren().DeleteObject(child
);
442 child
->SetParent((wxWindow
*)NULL
);
445 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
447 wxWindow
*oldParent
= GetParent();
448 if ( newParent
== oldParent
)
454 // unlink this window from the existing parent.
457 oldParent
->RemoveChild(this);
461 wxTopLevelWindows
.DeleteObject(this);
464 // add it to the new one
467 newParent
->AddChild(this);
471 wxTopLevelWindows
.Append(this);
477 // ----------------------------------------------------------------------------
478 // event handler stuff
479 // ----------------------------------------------------------------------------
481 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
483 handler
->SetNextHandler(GetEventHandler());
484 SetEventHandler(handler
);
487 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
489 wxEvtHandler
*handlerA
= GetEventHandler();
492 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
493 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
494 SetEventHandler(handlerB
);
498 handlerA
= (wxEvtHandler
*)NULL
;
505 // ----------------------------------------------------------------------------
507 // ----------------------------------------------------------------------------
509 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
511 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
514 m_backgroundColour
= colour
;
519 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
521 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
524 m_foregroundColour
= colour
;
529 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
531 // don't try to set invalid cursor, always fall back to the default
532 const wxCursor
& cursorOk
= cursor
.Ok() ? cursor
: *wxSTANDARD_CURSOR
;
534 if ( cursorOk
== m_cursor
)
545 bool wxWindowBase::SetFont(const wxFont
& font
)
547 // don't try to set invalid font, always fall back to the default
548 const wxFont
& fontOk
= font
.Ok() ? font
: *wxSWISS_FONT
;
550 if ( fontOk
== m_font
)
562 void wxWindowBase::SetCaret(wxCaret
*caret
)
573 wxASSERT_MSG( m_caret
->GetWindow() == this,
574 _T("caret should be created associated to this window") );
577 #endif // wxUSE_CARET
580 // ----------------------------------------------------------------------------
582 // ----------------------------------------------------------------------------
584 void wxWindowBase::SetValidator(const wxValidator
& validator
)
586 if ( m_windowValidator
)
587 delete m_windowValidator
;
589 m_windowValidator
= (wxValidator
*)validator
.Clone();
591 if ( m_windowValidator
)
592 m_windowValidator
->SetWindow(this) ;
594 #endif // wxUSE_VALIDATORS
596 // ----------------------------------------------------------------------------
597 // update region testing
598 // ----------------------------------------------------------------------------
600 bool wxWindowBase::IsExposed(int x
, int y
) const
602 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
605 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
607 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
610 // ----------------------------------------------------------------------------
611 // find window by id or name
612 // ----------------------------------------------------------------------------
614 wxWindow
*wxWindowBase::FindWindow( long id
)
616 if ( id
== m_windowId
)
617 return (wxWindow
*)this;
619 wxWindowBase
*res
= (wxWindow
*)NULL
;
620 wxWindowList::Node
*node
;
621 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
623 wxWindowBase
*child
= node
->GetData();
624 res
= child
->FindWindow( id
);
627 return (wxWindow
*)res
;
630 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
632 if ( name
== m_windowName
)
633 return (wxWindow
*)this;
635 wxWindowBase
*res
= (wxWindow
*)NULL
;
636 wxWindowList::Node
*node
;
637 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
639 wxWindow
*child
= node
->GetData();
640 res
= child
->FindWindow(name
);
643 return (wxWindow
*)res
;
646 // ----------------------------------------------------------------------------
647 // dialog oriented functions
648 // ----------------------------------------------------------------------------
650 void wxWindowBase::MakeModal(bool modal
)
652 // Disable all other windows
655 wxWindowList::Node
*node
= wxTopLevelWindows
.GetFirst();
658 wxWindow
*win
= node
->GetData();
662 node
= node
->GetNext();
667 bool wxWindowBase::Validate()
670 wxWindowList::Node
*node
;
671 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
673 wxWindowBase
*child
= node
->GetData();
674 wxValidator
*validator
= child
->GetValidator();
675 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
680 #endif // wxUSE_VALIDATORS
685 bool wxWindowBase::TransferDataToWindow()
688 wxWindowList::Node
*node
;
689 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
691 wxWindowBase
*child
= node
->GetData();
692 wxValidator
*validator
= child
->GetValidator();
693 if ( validator
&& !validator
->TransferToWindow() )
695 wxLog
*log
= wxLog::GetActiveTarget();
698 wxLogWarning(_("Could not transfer data to window"));
705 #endif // wxUSE_VALIDATORS
710 bool wxWindowBase::TransferDataFromWindow()
713 wxWindowList::Node
*node
;
714 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
716 wxWindow
*child
= node
->GetData();
717 if ( child
->GetValidator() &&
718 !child
->GetValidator()->TransferFromWindow() )
723 #endif // wxUSE_VALIDATORS
728 void wxWindowBase::InitDialog()
730 wxInitDialogEvent
event(GetId());
731 event
.SetEventObject( this );
732 GetEventHandler()->ProcessEvent(event
);
735 // ----------------------------------------------------------------------------
737 // ----------------------------------------------------------------------------
741 void wxWindowBase::SetToolTip( const wxString
&tip
)
743 // don't create the new tooltip if we already have one
746 m_tooltip
->SetTip( tip
);
750 SetToolTip( new wxToolTip( tip
) );
753 // setting empty tooltip text does not remove the tooltip any more - use
754 // SetToolTip((wxToolTip *)NULL) for this
757 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
765 #endif // wxUSE_TOOLTIPS
767 // ----------------------------------------------------------------------------
768 // constraints and sizers
769 // ----------------------------------------------------------------------------
771 #if wxUSE_CONSTRAINTS
773 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
777 UnsetConstraints(m_constraints
);
778 delete m_constraints
;
780 m_constraints
= constraints
;
783 // Make sure other windows know they're part of a 'meaningful relationship'
784 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
785 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
786 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
787 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
788 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
789 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
790 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
791 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
792 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
793 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
794 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
795 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
796 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
797 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
798 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
799 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
803 // This removes any dangling pointers to this window in other windows'
804 // constraintsInvolvedIn lists.
805 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
809 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
810 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
811 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
812 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
813 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
814 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
815 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
816 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
817 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
818 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
819 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
820 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
821 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
822 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
823 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
824 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
828 // Back-pointer to other windows we're involved with, so if we delete this
829 // window, we must delete any constraints we're involved with.
830 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
832 if ( !m_constraintsInvolvedIn
)
833 m_constraintsInvolvedIn
= new wxWindowList
;
834 if ( !m_constraintsInvolvedIn
->Find(otherWin
) )
835 m_constraintsInvolvedIn
->Append(otherWin
);
838 // REMOVE back-pointer to other windows we're involved with.
839 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
841 if ( m_constraintsInvolvedIn
)
842 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
845 // Reset any constraints that mention this window
846 void wxWindowBase::DeleteRelatedConstraints()
848 if ( m_constraintsInvolvedIn
)
850 wxWindowList::Node
*node
= m_constraintsInvolvedIn
->GetFirst();
853 wxWindow
*win
= node
->GetData();
854 wxLayoutConstraints
*constr
= win
->GetConstraints();
856 // Reset any constraints involving this window
859 constr
->left
.ResetIfWin(this);
860 constr
->top
.ResetIfWin(this);
861 constr
->right
.ResetIfWin(this);
862 constr
->bottom
.ResetIfWin(this);
863 constr
->width
.ResetIfWin(this);
864 constr
->height
.ResetIfWin(this);
865 constr
->centreX
.ResetIfWin(this);
866 constr
->centreY
.ResetIfWin(this);
869 wxWindowList::Node
*next
= node
->GetNext();
874 delete m_constraintsInvolvedIn
;
875 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
879 void wxWindowBase::SetSizer(wxSizer
*sizer
)
881 m_windowSizer
= sizer
;
883 sizer
->SetSizerParent(this);
886 bool wxWindowBase::Layout()
888 if ( GetConstraints() )
891 GetClientSize(&w
, &h
);
892 GetConstraints()->width
.SetValue(w
);
893 GetConstraints()->height
.SetValue(h
);
896 // If top level (one sizer), evaluate the sizer's constraints.
900 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
901 GetSizer()->LayoutPhase1(&noChanges
);
902 GetSizer()->LayoutPhase2(&noChanges
);
903 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
908 // Otherwise, evaluate child constraints
909 ResetConstraints(); // Mark all constraints as unevaluated
910 DoPhase(1); // Just one phase need if no sizers involved
912 SetConstraintSizes(); // Recursively set the real window sizes
918 // Do a phase of evaluating constraints: the default behaviour. wxSizers may
919 // do a similar thing, but also impose their own 'constraints' and order the
920 // evaluation differently.
921 bool wxWindowBase::LayoutPhase1(int *noChanges
)
923 wxLayoutConstraints
*constr
= GetConstraints();
926 return constr
->SatisfyConstraints(this, noChanges
);
932 bool wxWindowBase::LayoutPhase2(int *noChanges
)
942 // Do a phase of evaluating child constraints
943 bool wxWindowBase::DoPhase(int phase
)
945 int noIterations
= 0;
946 int maxIterations
= 500;
949 wxWindowList succeeded
;
950 while ((noChanges
> 0) && (noIterations
< maxIterations
))
954 wxWindowList::Node
*node
= GetChildren().GetFirst();
957 wxWindow
*child
= node
->GetData();
958 if ( !child
->IsTopLevel() )
960 wxLayoutConstraints
*constr
= child
->GetConstraints();
963 if ( !succeeded
.Find(child
) )
965 int tempNoChanges
= 0;
966 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
967 noChanges
+= tempNoChanges
;
970 succeeded
.Append(child
);
975 node
= node
->GetNext();
984 void wxWindowBase::ResetConstraints()
986 wxLayoutConstraints
*constr
= GetConstraints();
989 constr
->left
.SetDone(FALSE
);
990 constr
->top
.SetDone(FALSE
);
991 constr
->right
.SetDone(FALSE
);
992 constr
->bottom
.SetDone(FALSE
);
993 constr
->width
.SetDone(FALSE
);
994 constr
->height
.SetDone(FALSE
);
995 constr
->centreX
.SetDone(FALSE
);
996 constr
->centreY
.SetDone(FALSE
);
998 wxWindowList::Node
*node
= GetChildren().GetFirst();
1001 wxWindow
*win
= node
->GetData();
1002 if ( !win
->IsTopLevel() )
1003 win
->ResetConstraints();
1004 node
= node
->GetNext();
1008 // Need to distinguish between setting the 'fake' size for windows and sizers,
1009 // and setting the real values.
1010 void wxWindowBase::SetConstraintSizes(bool recurse
)
1012 wxLayoutConstraints
*constr
= GetConstraints();
1013 if ( constr
&& constr
->left
.GetDone() && constr
->right
.GetDone( ) &&
1014 constr
->width
.GetDone() && constr
->height
.GetDone())
1016 int x
= constr
->left
.GetValue();
1017 int y
= constr
->top
.GetValue();
1018 int w
= constr
->width
.GetValue();
1019 int h
= constr
->height
.GetValue();
1021 // If we don't want to resize this window, just move it...
1022 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1023 (constr
->height
.GetRelationship() != wxAsIs
))
1025 // Calls Layout() recursively. AAAGH. How can we stop that.
1026 // Simply take Layout() out of non-top level OnSizes.
1027 SizerSetSize(x
, y
, w
, h
);
1036 wxChar
*windowClass
= GetClassInfo()->GetClassName();
1039 if ( GetName() == _T("") )
1040 winName
= _T("unnamed");
1042 winName
= GetName();
1043 wxLogDebug( _T("Constraint(s) not satisfied for window of type %s, name %s:\n"),
1044 (const wxChar
*)windowClass
,
1045 (const wxChar
*)winName
);
1046 if ( !constr
->left
.GetDone()) wxLogDebug( _T(" unsatisfied 'left' constraint.\n") );
1047 if ( !constr
->right
.GetDone()) wxLogDebug( _T(" unsatisfied 'right' constraint.\n") );
1048 if ( !constr
->width
.GetDone()) wxLogDebug( _T(" unsatisfied 'width' constraint.\n") );
1049 if ( !constr
->height
.GetDone()) wxLogDebug( _T(" unsatisfied 'height' constraint.\n") );
1050 wxLogDebug( _T("Please check constraints: try adding AsIs() constraints.\n") );
1055 wxWindowList::Node
*node
= GetChildren().GetFirst();
1058 wxWindow
*win
= node
->GetData();
1059 if ( !win
->IsTopLevel() )
1060 win
->SetConstraintSizes();
1061 node
= node
->GetNext();
1066 // This assumes that all sizers are 'on' the same window, i.e. the parent of
1068 void wxWindowBase::TransformSizerToActual(int *x
, int *y
) const
1070 if ( !m_sizerParent
|| m_sizerParent
->IsTopLevel() )
1074 m_sizerParent
->GetPosition(&xp
, &yp
);
1075 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
1080 void wxWindowBase::SizerSetSize(int x
, int y
, int w
, int h
)
1084 TransformSizerToActual(&xx
, &yy
);
1085 SetSize(xx
, yy
, w
, h
);
1088 void wxWindowBase::SizerMove(int x
, int y
)
1092 TransformSizerToActual(&xx
, &yy
);
1096 // Only set the size/position of the constraint (if any)
1097 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1099 wxLayoutConstraints
*constr
= GetConstraints();
1104 constr
->left
.SetValue(x
);
1105 constr
->left
.SetDone(TRUE
);
1109 constr
->top
.SetValue(y
);
1110 constr
->top
.SetDone(TRUE
);
1114 constr
->width
.SetValue(w
);
1115 constr
->width
.SetDone(TRUE
);
1119 constr
->height
.SetValue(h
);
1120 constr
->height
.SetDone(TRUE
);
1125 void wxWindowBase::MoveConstraint(int x
, int y
)
1127 wxLayoutConstraints
*constr
= GetConstraints();
1132 constr
->left
.SetValue(x
);
1133 constr
->left
.SetDone(TRUE
);
1137 constr
->top
.SetValue(y
);
1138 constr
->top
.SetDone(TRUE
);
1143 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1145 wxLayoutConstraints
*constr
= GetConstraints();
1148 *w
= constr
->width
.GetValue();
1149 *h
= constr
->height
.GetValue();
1155 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1157 wxLayoutConstraints
*constr
= GetConstraints();
1160 *w
= constr
->width
.GetValue();
1161 *h
= constr
->height
.GetValue();
1164 GetClientSize(w
, h
);
1167 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1169 wxLayoutConstraints
*constr
= GetConstraints();
1172 *x
= constr
->left
.GetValue();
1173 *y
= constr
->top
.GetValue();
1179 #endif // wxUSE_CONSTRAINTS
1181 // ----------------------------------------------------------------------------
1182 // do Update UI processing for child controls
1183 // ----------------------------------------------------------------------------
1185 // TODO: should this be implemented for the child window rather
1186 // than the parent? Then you can override it e.g. for wxCheckBox
1187 // to do the Right Thing rather than having to assume a fixed number
1188 // of control classes.
1189 void wxWindowBase::UpdateWindowUI()
1191 wxWindowID id
= GetId();
1194 wxUpdateUIEvent
event(id
);
1195 event
.m_eventObject
= this;
1197 if ( GetEventHandler()->ProcessEvent(event
) )
1199 if ( event
.GetSetEnabled() )
1200 Enable(event
.GetEnabled());
1202 if ( event
.GetSetText() )
1204 wxControl
*control
= wxDynamicCast(this, wxControl
);
1206 control
->SetLabel(event
.GetText());
1210 wxCheckBox
*checkbox
= wxDynamicCast(this, wxCheckBox
);
1213 if ( event
.GetSetChecked() )
1214 checkbox
->SetValue(event
.GetChecked());
1216 #endif // wxUSE_CHECKBOX
1218 #if wxUSE_RADIOBUTTON
1219 wxRadioButton
*radiobtn
= wxDynamicCast(this, wxRadioButton
);
1222 if ( event
.GetSetChecked() )
1223 radiobtn
->SetValue(event
.GetChecked());
1225 #endif // wxUSE_RADIOBUTTON
1230 // ----------------------------------------------------------------------------
1231 // dialog units translations
1232 // ----------------------------------------------------------------------------
1234 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1236 int charWidth
= GetCharWidth();
1237 int charHeight
= GetCharHeight();
1238 wxPoint
pt2(-1, -1);
1240 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1242 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1247 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1249 int charWidth
= GetCharWidth();
1250 int charHeight
= GetCharHeight();
1251 wxPoint
pt2(-1, -1);
1253 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1255 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1260 // ----------------------------------------------------------------------------
1262 // ----------------------------------------------------------------------------
1264 void wxWindowBase::DoSetClientObject( wxClientData
*data
)
1266 wxASSERT_MSG( m_clientDataType
!= ClientData_Void
,
1267 _T("can't have both object and void client data") );
1269 if ( m_clientObject
)
1270 delete m_clientObject
;
1272 m_clientObject
= data
;
1273 m_clientDataType
= ClientData_Object
;
1276 wxClientData
*wxWindowBase::DoGetClientObject() const
1278 wxASSERT_MSG( m_clientDataType
== ClientData_Object
,
1279 _T("this window doesn't have object client data") );
1281 return m_clientObject
;
1284 void wxWindowBase::DoSetClientData( void *data
)
1286 wxASSERT_MSG( m_clientDataType
!= ClientData_Object
,
1287 _T("can't have both object and void client data") );
1289 m_clientData
= data
;
1290 m_clientDataType
= ClientData_Void
;
1293 void *wxWindowBase::DoGetClientData() const
1295 wxASSERT_MSG( m_clientDataType
== ClientData_Void
,
1296 _T("this window doesn't have void client data") );
1298 return m_clientData
;
1301 // ----------------------------------------------------------------------------
1303 // ----------------------------------------------------------------------------
1305 // propagate the colour change event to the subwindows
1306 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1308 wxWindowList::Node
*node
= GetChildren().GetFirst();
1311 // Only propagate to non-top-level windows
1312 wxWindow
*win
= node
->GetData();
1313 if ( !win
->IsTopLevel() )
1315 wxSysColourChangedEvent event2
;
1316 event
.m_eventObject
= win
;
1317 win
->GetEventHandler()->ProcessEvent(event2
);
1320 node
= node
->GetNext();
1324 // the default action is to populate dialog with data when it's created
1325 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1327 TransferDataToWindow();
1330 // ----------------------------------------------------------------------------
1331 // list classes implementation
1332 // ----------------------------------------------------------------------------
1334 void wxWindowListNode::DeleteData()
1336 delete (wxWindow
*)GetData();