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
= 0;
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);
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
;
247 for ( node
= GetChildren().GetFirst(); node
; node
= node
->GetNext() )
249 wxWindow
*child
= node
->GetData();
259 // ----------------------------------------------------------------------------
260 // centre/fit the window
261 // ----------------------------------------------------------------------------
263 // centre the window with respect to its parent in either (or both) directions
264 void wxWindowBase::Centre(int direction
)
266 int widthParent
, heightParent
;
268 wxWindow
*parent
= GetParent();
271 parent
->GetClientSize(&widthParent
, &heightParent
);
275 // centre with respect to the whole screen
276 wxDisplaySize(&widthParent
, &heightParent
);
280 GetSize(&width
, &height
);
285 if ( direction
& wxHORIZONTAL
)
286 new_x
= (widthParent
- width
)/2;
288 if ( direction
& wxVERTICAL
)
289 new_y
= (heightParent
- height
)/2;
294 // fits the window around the children
295 void wxWindowBase::Fit()
300 wxWindowList::Node
*node
= GetChildren().GetFirst();
303 wxWindow
*win
= node
->GetData();
305 win
->GetPosition(&wx
, &wy
);
306 win
->GetSize(&ww
, &wh
);
307 if ( wx
+ ww
> maxX
)
309 if ( wy
+ wh
> maxY
)
312 node
= node
->GetNext();
316 SetClientSize(maxX
+ 7, maxY
+ 14);
319 // set the min/max size of the window
321 void wxWindowBase::SetSizeHints(int minW
, int minH
,
323 int WXUNUSED(incW
), int WXUNUSED(incH
))
331 // ----------------------------------------------------------------------------
332 // show/hide/enable/disable the window
333 // ----------------------------------------------------------------------------
335 bool wxWindowBase::Show(bool show
)
337 if ( show
!= m_isShown
)
349 bool wxWindowBase::Enable(bool enable
)
351 if ( enable
!= m_isEnabled
)
353 m_isEnabled
= enable
;
363 // ----------------------------------------------------------------------------
364 // reparenting the window
365 // ----------------------------------------------------------------------------
367 void wxWindowBase::AddChild(wxWindowBase
*child
)
369 wxCHECK_RET( child
, _T("can't add a NULL child") );
371 GetChildren().Append(child
);
372 child
->SetParent(this);
375 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
377 wxCHECK_RET( child
, _T("can't remove a NULL child") );
379 GetChildren().DeleteObject(child
);
380 child
->SetParent((wxWindow
*)NULL
);
383 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
385 wxWindow
*oldParent
= GetParent();
386 if ( newParent
== oldParent
)
392 // unlink this window from the existing parent.
395 oldParent
->RemoveChild(this);
399 wxTopLevelWindows
.DeleteObject(this);
402 // add it to the new one
405 newParent
->AddChild(this);
409 wxTopLevelWindows
.Append(this);
415 // ----------------------------------------------------------------------------
416 // event handler stuff
417 // ----------------------------------------------------------------------------
419 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
421 handler
->SetNextHandler(GetEventHandler());
422 SetEventHandler(handler
);
425 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
427 wxEvtHandler
*handlerA
= GetEventHandler();
430 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
431 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
432 SetEventHandler(handlerB
);
436 handlerA
= (wxEvtHandler
*)NULL
;
443 // ----------------------------------------------------------------------------
445 // ----------------------------------------------------------------------------
447 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
449 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
452 m_backgroundColour
= colour
;
457 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
459 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
462 m_foregroundColour
= colour
;
467 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
469 // don't try to set invalid cursor, always fall back to the default
470 const wxCursor
& cursorOk
= cursor
.Ok() ? cursor
: *wxSTANDARD_CURSOR
;
472 if ( cursorOk
== m_cursor
)
483 bool wxWindowBase::SetFont(const wxFont
& font
)
485 // don't try to set invalid font, always fall back to the default
486 const wxFont
& fontOk
= font
.Ok() ? font
: *wxSWISS_FONT
;
488 if ( fontOk
== m_font
)
499 // ----------------------------------------------------------------------------
501 // ----------------------------------------------------------------------------
503 void wxWindowBase::SetValidator(const wxValidator
& validator
)
505 if ( m_windowValidator
)
506 delete m_windowValidator
;
508 m_windowValidator
= (wxValidator
*)validator
.Clone();
510 if ( m_windowValidator
)
511 m_windowValidator
->SetWindow(this) ;
514 // ----------------------------------------------------------------------------
515 // update region testing
516 // ----------------------------------------------------------------------------
518 bool wxWindowBase::IsExposed(int x
, int y
) const
520 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
523 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
525 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
528 // ----------------------------------------------------------------------------
529 // find window by id or name
530 // ----------------------------------------------------------------------------
532 wxWindow
*wxWindowBase::FindWindow( long id
)
534 if ( id
== m_windowId
)
535 return (wxWindow
*)this;
537 wxWindowBase
*res
= (wxWindow
*)NULL
;
538 wxWindowList::Node
*node
;
539 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
541 wxWindowBase
*child
= node
->GetData();
542 res
= child
->FindWindow( id
);
545 return (wxWindow
*)res
;
548 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
550 if ( name
== m_windowName
)
551 return (wxWindow
*)this;
553 wxWindowBase
*res
= (wxWindow
*)NULL
;
554 wxWindowList::Node
*node
;
555 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
557 wxWindow
*child
= node
->GetData();
558 res
= child
->FindWindow(name
);
561 return (wxWindow
*)res
;
564 // ----------------------------------------------------------------------------
565 // dialog oriented functions
566 // ----------------------------------------------------------------------------
568 void wxWindowBase::MakeModal(bool WXUNUSED(modal
))
573 bool wxWindowBase::Validate()
575 wxWindowList::Node
*node
;
576 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
578 wxWindowBase
*child
= node
->GetData();
579 wxValidator
*validator
= child
->GetValidator();
580 if ( validator
&& validator
->Validate(this) )
589 bool wxWindowBase::TransferDataToWindow()
591 wxWindowList::Node
*node
;
592 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
594 wxWindowBase
*child
= node
->GetData();
595 wxValidator
*validator
= child
->GetValidator();
596 if ( validator
&& !validator
->TransferToWindow() )
598 wxLog
*log
= wxLog::GetActiveTarget();
601 wxLogWarning(_("Could not transfer data to window"));
612 bool wxWindowBase::TransferDataFromWindow()
614 wxWindowList::Node
*node
;
615 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
617 wxWindow
*child
= node
->GetData();
618 if ( child
->GetValidator() &&
619 !child
->GetValidator()->TransferFromWindow() )
628 void wxWindowBase::InitDialog()
630 wxInitDialogEvent
event(GetId());
631 event
.SetEventObject( this );
632 GetEventHandler()->ProcessEvent(event
);
635 // ----------------------------------------------------------------------------
637 // ----------------------------------------------------------------------------
641 void wxWindowBase::SetToolTip( const wxString
&tip
)
643 // don't create the new tooltip if we already have one
646 m_tooltip
->SetTip( tip
);
650 SetToolTip( new wxToolTip( tip
) );
653 // setting empty tooltip text does not remove the tooltip any more - use
654 // SetToolTip((wxToolTip *)NULL) for this
657 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
665 #endif // wxUSE_TOOLTIPS
667 // ----------------------------------------------------------------------------
668 // constraints and sizers
669 // ----------------------------------------------------------------------------
671 #if wxUSE_CONSTRAINTS
673 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
677 UnsetConstraints(m_constraints
);
678 delete m_constraints
;
680 m_constraints
= constraints
;
683 // Make sure other windows know they're part of a 'meaningful relationship'
684 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
685 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
686 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
687 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
688 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
689 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
690 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
691 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
692 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
693 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
694 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
695 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
696 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
697 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
698 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
699 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
703 // This removes any dangling pointers to this window in other windows'
704 // constraintsInvolvedIn lists.
705 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
709 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
710 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
711 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
712 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
713 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
714 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
715 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
716 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
717 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
718 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
719 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
720 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
721 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
722 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
723 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
724 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
728 // Back-pointer to other windows we're involved with, so if we delete this
729 // window, we must delete any constraints we're involved with.
730 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
732 if ( !m_constraintsInvolvedIn
)
733 m_constraintsInvolvedIn
= new wxWindowList
;
734 if ( !m_constraintsInvolvedIn
->Find(otherWin
) )
735 m_constraintsInvolvedIn
->Append(otherWin
);
738 // REMOVE back-pointer to other windows we're involved with.
739 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
741 if ( m_constraintsInvolvedIn
)
742 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
745 // Reset any constraints that mention this window
746 void wxWindowBase::DeleteRelatedConstraints()
748 if ( m_constraintsInvolvedIn
)
750 wxWindowList::Node
*node
= m_constraintsInvolvedIn
->GetFirst();
753 wxWindow
*win
= node
->GetData();
754 wxLayoutConstraints
*constr
= win
->GetConstraints();
756 // Reset any constraints involving this window
759 constr
->left
.ResetIfWin(this);
760 constr
->top
.ResetIfWin(this);
761 constr
->right
.ResetIfWin(this);
762 constr
->bottom
.ResetIfWin(this);
763 constr
->width
.ResetIfWin(this);
764 constr
->height
.ResetIfWin(this);
765 constr
->centreX
.ResetIfWin(this);
766 constr
->centreY
.ResetIfWin(this);
769 wxWindowList::Node
*next
= node
->GetNext();
774 delete m_constraintsInvolvedIn
;
775 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
779 void wxWindowBase::SetSizer(wxSizer
*sizer
)
781 m_windowSizer
= sizer
;
783 sizer
->SetSizerParent(this);
786 bool wxWindowBase::Layout()
788 if ( GetConstraints() )
791 GetClientSize(&w
, &h
);
792 GetConstraints()->width
.SetValue(w
);
793 GetConstraints()->height
.SetValue(h
);
796 // If top level (one sizer), evaluate the sizer's constraints.
800 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
801 GetSizer()->LayoutPhase1(&noChanges
);
802 GetSizer()->LayoutPhase2(&noChanges
);
803 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
808 // Otherwise, evaluate child constraints
809 ResetConstraints(); // Mark all constraints as unevaluated
810 DoPhase(1); // Just one phase need if no sizers involved
812 SetConstraintSizes(); // Recursively set the real window sizes
818 // Do a phase of evaluating constraints: the default behaviour. wxSizers may
819 // do a similar thing, but also impose their own 'constraints' and order the
820 // evaluation differently.
821 bool wxWindowBase::LayoutPhase1(int *noChanges
)
823 wxLayoutConstraints
*constr
= GetConstraints();
826 return constr
->SatisfyConstraints(this, noChanges
);
832 bool wxWindowBase::LayoutPhase2(int *noChanges
)
842 // Do a phase of evaluating child constraints
843 bool wxWindowBase::DoPhase(int phase
)
845 int noIterations
= 0;
846 int maxIterations
= 500;
849 wxWindowList succeeded
;
850 while ((noChanges
> 0) && (noIterations
< maxIterations
))
854 wxWindowList::Node
*node
= GetChildren().GetFirst();
857 wxWindow
*child
= node
->GetData();
858 if ( !child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)) )
860 wxLayoutConstraints
*constr
= child
->GetConstraints();
863 if ( !succeeded
.Find(child
) )
865 int tempNoChanges
= 0;
866 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
867 noChanges
+= tempNoChanges
;
870 succeeded
.Append(child
);
875 node
= node
->GetNext();
884 void wxWindowBase::ResetConstraints()
886 wxLayoutConstraints
*constr
= GetConstraints();
889 constr
->left
.SetDone(FALSE
);
890 constr
->top
.SetDone(FALSE
);
891 constr
->right
.SetDone(FALSE
);
892 constr
->bottom
.SetDone(FALSE
);
893 constr
->width
.SetDone(FALSE
);
894 constr
->height
.SetDone(FALSE
);
895 constr
->centreX
.SetDone(FALSE
);
896 constr
->centreY
.SetDone(FALSE
);
898 wxWindowList::Node
*node
= GetChildren().GetFirst();
901 wxWindow
*win
= node
->GetData();
902 if ( !win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)) )
903 win
->ResetConstraints();
904 node
= node
->GetNext();
908 // Need to distinguish between setting the 'fake' size for windows and sizers,
909 // and setting the real values.
910 void wxWindowBase::SetConstraintSizes(bool recurse
)
912 wxLayoutConstraints
*constr
= GetConstraints();
913 if ( constr
&& constr
->left
.GetDone() && constr
->right
.GetDone( ) &&
914 constr
->width
.GetDone() && constr
->height
.GetDone())
916 int x
= constr
->left
.GetValue();
917 int y
= constr
->top
.GetValue();
918 int w
= constr
->width
.GetValue();
919 int h
= constr
->height
.GetValue();
921 // If we don't want to resize this window, just move it...
922 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
923 (constr
->height
.GetRelationship() != wxAsIs
))
925 // Calls Layout() recursively. AAAGH. How can we stop that.
926 // Simply take Layout() out of non-top level OnSizes.
927 SizerSetSize(x
, y
, w
, h
);
936 wxChar
*windowClass
= GetClassInfo()->GetClassName();
939 if ( GetName() == _T("") )
940 winName
= _T("unnamed");
943 wxLogDebug( _T("Constraint(s) not satisfied for window of type %s, name %s:\n"),
944 (const wxChar
*)windowClass
,
945 (const wxChar
*)winName
);
946 if ( !constr
->left
.GetDone()) wxLogDebug( _T(" unsatisfied 'left' constraint.\n") );
947 if ( !constr
->right
.GetDone()) wxLogDebug( _T(" unsatisfied 'right' constraint.\n") );
948 if ( !constr
->width
.GetDone()) wxLogDebug( _T(" unsatisfied 'width' constraint.\n") );
949 if ( !constr
->height
.GetDone()) wxLogDebug( _T(" unsatisfied 'height' constraint.\n") );
950 wxLogDebug( _T("Please check constraints: try adding AsIs() constraints.\n") );
955 wxWindowList::Node
*node
= GetChildren().GetFirst();
958 wxWindow
*win
= node
->GetData();
959 if ( !win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)) )
960 win
->SetConstraintSizes();
961 node
= node
->GetNext();
966 // This assumes that all sizers are 'on' the same window, i.e. the parent of
968 void wxWindowBase::TransformSizerToActual(int *x
, int *y
) const
970 if ( !m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
) ) ||
971 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
975 m_sizerParent
->GetPosition(&xp
, &yp
);
976 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
981 void wxWindowBase::SizerSetSize(int x
, int y
, int w
, int h
)
985 TransformSizerToActual(&xx
, &yy
);
986 SetSize(xx
, yy
, w
, h
);
989 void wxWindowBase::SizerMove(int x
, int y
)
993 TransformSizerToActual(&xx
, &yy
);
997 // Only set the size/position of the constraint (if any)
998 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1000 wxLayoutConstraints
*constr
= GetConstraints();
1005 constr
->left
.SetValue(x
);
1006 constr
->left
.SetDone(TRUE
);
1010 constr
->top
.SetValue(y
);
1011 constr
->top
.SetDone(TRUE
);
1015 constr
->width
.SetValue(w
);
1016 constr
->width
.SetDone(TRUE
);
1020 constr
->height
.SetValue(h
);
1021 constr
->height
.SetDone(TRUE
);
1026 void wxWindowBase::MoveConstraint(int x
, int y
)
1028 wxLayoutConstraints
*constr
= GetConstraints();
1033 constr
->left
.SetValue(x
);
1034 constr
->left
.SetDone(TRUE
);
1038 constr
->top
.SetValue(y
);
1039 constr
->top
.SetDone(TRUE
);
1044 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1046 wxLayoutConstraints
*constr
= GetConstraints();
1049 *w
= constr
->width
.GetValue();
1050 *h
= constr
->height
.GetValue();
1056 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1058 wxLayoutConstraints
*constr
= GetConstraints();
1061 *w
= constr
->width
.GetValue();
1062 *h
= constr
->height
.GetValue();
1065 GetClientSize(w
, h
);
1068 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1070 wxLayoutConstraints
*constr
= GetConstraints();
1073 *x
= constr
->left
.GetValue();
1074 *y
= constr
->top
.GetValue();
1080 #endif // wxUSE_CONSTRAINTS
1082 // ----------------------------------------------------------------------------
1083 // do Update UI processing for child controls
1084 // ----------------------------------------------------------------------------
1086 // TODO: should this be implemented for the child window rather
1087 // than the parent? Then you can override it e.g. for wxCheckBox
1088 // to do the Right Thing rather than having to assume a fixed number
1089 // of control classes.
1090 void wxWindowBase::UpdateWindowUI()
1092 wxWindowID id
= GetId();
1095 wxUpdateUIEvent
event(id
);
1096 event
.m_eventObject
= this;
1098 if ( GetEventHandler()->ProcessEvent(event
) )
1100 if ( event
.GetSetEnabled() )
1101 Enable(event
.GetEnabled());
1103 if ( event
.GetSetText() && IsKindOf(CLASSINFO(wxControl
)) )
1104 ((wxControl
*)this)->SetLabel(event
.GetText());
1106 if ( IsKindOf(CLASSINFO(wxCheckBox
)) )
1108 if ( event
.GetSetChecked() )
1109 ((wxCheckBox
*)this)->SetValue(event
.GetChecked());
1111 // TODO No radio buttons in wxGTK yet
1113 else if ( IsKindOf(CLASSINFO(wxRadioButton
)) )
1115 if ( event
.GetSetChecked() )
1116 ((wxRadioButton
*) this)->SetValue(event
.GetChecked());
1123 // ----------------------------------------------------------------------------
1124 // dialog units translations
1125 // ----------------------------------------------------------------------------
1127 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1129 int charWidth
= GetCharWidth();
1130 int charHeight
= GetCharHeight();
1132 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1133 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1138 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1140 int charWidth
= GetCharWidth();
1141 int charHeight
= GetCharHeight();
1143 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1144 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1149 // ----------------------------------------------------------------------------
1151 // ----------------------------------------------------------------------------
1153 // propagate the colour change event to the subwindows
1154 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1156 wxWindowList::Node
*node
= GetChildren().GetFirst();
1159 // Only propagate to non-top-level windows
1160 wxWindow
*win
= node
->GetData();
1161 if ( !win
->IsTopLevel() )
1163 wxSysColourChangedEvent event2
;
1164 event
.m_eventObject
= win
;
1165 win
->GetEventHandler()->ProcessEvent(event2
);
1168 node
= node
->GetNext();
1172 // the default action is to populate dialog with data when it's created
1173 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1175 TransferDataToWindow();
1178 // ----------------------------------------------------------------------------
1179 // list classes implementation
1180 // ----------------------------------------------------------------------------
1182 void wxWindowListNode::DeleteData()
1184 delete (wxWindow
*)GetData();