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 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
28 #include "wx/string.h"
33 #include "wx/window.h"
34 #include "wx/checkbox.h"
35 #include "wx/radiobut.h"
36 #include "wx/settings.h"
37 #include "wx/dialog.h"
41 #include "wx/layout.h"
42 #endif // wxUSE_CONSTRAINTS
44 #if wxUSE_DRAG_AND_DROP
46 #endif // wxUSE_DRAG_AND_DROP
49 #include "wx/tooltip.h"
50 #endif // wxUSE_TOOLTIPS
52 // ----------------------------------------------------------------------------
54 // ----------------------------------------------------------------------------
56 int wxWindowBase::ms_lastControlId
= 0;
58 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
60 // ----------------------------------------------------------------------------
62 // ----------------------------------------------------------------------------
64 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
65 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
66 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
69 // ============================================================================
70 // implementation of the common functionality of the wxWindow class
71 // ============================================================================
73 // ----------------------------------------------------------------------------
75 // ----------------------------------------------------------------------------
77 // the default initialization
78 void wxWindowBase::InitBase()
80 // no window yet, no parent nor children
81 // m_widget = (WXWidget)0;
82 m_parent
= (wxWindow
*)NULL
;
84 m_children
.DeleteContents( FALSE
); // don't auto delete node data
86 // no constraints on the minimal window size
92 // window is created enabled but it's not visible yet
97 m_clientObject
= (wxClientData
*)NULL
;
100 // the default event handler is just this window
101 m_eventHandler
= this;
104 m_windowValidator
= (wxValidator
*) NULL
;
106 // use the system default colours
107 wxSystemSettings settings
;
109 m_backgroundColour
= settings
.GetSystemColour(wxSYS_COLOUR_BTNFACE
);
110 m_foregroundColour
= *wxBLACK
; // TODO take this from sys settings too?
111 m_font
= *wxSWISS_FONT
; // and this?
116 // an optimization for the event processing: checking this flag is much
117 // faster than using IsKindOf(CLASSINFO(wxWindow))
120 #if wxUSE_CONSTRAINTS
121 // no constraints whatsoever
122 m_constraints
= (wxLayoutConstraints
*) NULL
;
123 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
124 m_windowSizer
= (wxSizer
*) NULL
;
125 m_sizerParent
= (wxWindowBase
*) NULL
;
126 m_autoLayout
= FALSE
;
127 #endif // wxUSE_CONSTRAINTS
129 #if wxUSE_DRAG_AND_DROP
130 m_dropTarget
= (wxDropTarget
*)NULL
;
131 #endif // wxUSE_DRAG_AND_DROP
134 m_tooltip
= (wxToolTip
*)NULL
;
135 #endif // wxUSE_TOOLTIPS
138 // common part of window creation process
139 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
144 const wxString
& name
)
146 // m_isWindow is set to TRUE in wxWindowBase::Init() as well as many other
147 // member variables - check that it has been called (will catch the case
148 // when a new ctor is added which doesn't call InitWindow)
149 wxASSERT_MSG( m_isWindow
, _T("Init() must have been called before!") );
151 // generate a new id if the user doesn't care about it
152 m_windowId
= id
== -1 ? NewControlId() : id
;
155 SetWindowStyleFlag(style
);
161 // ----------------------------------------------------------------------------
163 // ----------------------------------------------------------------------------
166 wxWindowBase::~wxWindowBase()
168 // FIXME if these 2 cases result from programming errors in the user code
169 // we should probably assert here instead of silently fixing them
171 // Just in case the window has been Closed, but we're then deleting
172 // immediately: don't leave dangling pointers.
173 wxPendingDelete
.DeleteObject(this);
175 // Just in case we've loaded a top-level window via LoadNativeDialog but
176 // we weren't a dialog class
177 wxTopLevelWindows
.DeleteObject(this);
181 if ( m_windowValidator
)
182 delete m_windowValidator
;
184 if ( m_clientObject
)
185 delete m_clientObject
;
187 #if wxUSE_CONSTRAINTS
188 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
189 // at deleted windows as they delete themselves.
190 DeleteRelatedConstraints();
194 // This removes any dangling pointers to this window in other windows'
195 // constraintsInvolvedIn lists.
196 UnsetConstraints(m_constraints
);
197 delete m_constraints
;
198 m_constraints
= NULL
;
202 delete m_windowSizer
;
204 // If this is a child of a sizer, remove self from parent
206 m_sizerParent
->RemoveChild(this);
207 #endif // wxUSE_CONSTRAINTS
209 #if wxUSE_DRAG_AND_DROP
212 #endif // wxUSE_DRAG_AND_DROP
217 #endif // wxUSE_TOOLTIPS
220 bool wxWindowBase::Destroy()
227 bool wxWindowBase::Close(bool force
)
229 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
230 event
.SetEventObject(this);
231 #if WXWIN_COMPATIBILITY
232 event
.SetForce(force
);
233 #endif // WXWIN_COMPATIBILITY
234 event
.SetCanVeto(!force
);
236 // return FALSE if window wasn't closed because the application vetoed the
238 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
241 bool wxWindowBase::DestroyChildren()
243 wxWindowList::Node
*node
;
244 for ( node
= GetChildren().GetFirst(); node
; node
= node
->GetNext() )
246 wxWindow
*child
= node
->GetData();
256 // ----------------------------------------------------------------------------
257 // centre/fit the window
258 // ----------------------------------------------------------------------------
260 // centre the window with respect to its parent in either (or both) directions
261 void wxWindowBase::Centre(int direction
)
263 int widthParent
, heightParent
;
265 wxWindow
*parent
= GetParent();
268 parent
->GetClientSize(&widthParent
, &heightParent
);
272 // centre with respect to the whole screen
273 wxDisplaySize(&widthParent
, &heightParent
);
277 GetSize(&width
, &height
);
282 if ( direction
& wxHORIZONTAL
)
283 new_x
= (widthParent
- width
)/2;
285 if ( direction
& wxVERTICAL
)
286 new_y
= (heightParent
- height
)/2;
291 // fits the window around the children
292 void wxWindowBase::Fit()
297 wxWindowList::Node
*node
= GetChildren().GetFirst();
300 wxWindow
*win
= node
->GetData();
302 win
->GetPosition(&wx
, &wy
);
303 win
->GetSize(&ww
, &wh
);
304 if ( wx
+ ww
> maxX
)
306 if ( wy
+ wh
> maxY
)
309 node
= node
->GetNext();
313 SetClientSize(maxX
+ 7, maxY
+ 14);
316 // set the min/max size of the window
318 void wxWindowBase::SetSizeHints(int minW
, int minH
,
320 int WXUNUSED(incW
), int WXUNUSED(incH
))
328 // ----------------------------------------------------------------------------
329 // show/hide/enable/disable the window
330 // ----------------------------------------------------------------------------
332 bool wxWindowBase::Show(bool show
)
334 if ( show
!= m_isShown
)
346 bool wxWindowBase::Enable(bool enable
)
348 if ( enable
!= m_isEnabled
)
350 m_isEnabled
= enable
;
360 // ----------------------------------------------------------------------------
361 // reparenting the window
362 // ----------------------------------------------------------------------------
364 void wxWindowBase::AddChild(wxWindowBase
*child
)
366 wxCHECK_RET( child
, _T("can't add a NULL child") );
368 GetChildren().Append(child
);
369 child
->SetParent(this);
372 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
374 wxCHECK_RET( child
, _T("can't remove a NULL child") );
376 GetChildren().DeleteObject(child
);
377 child
->SetParent((wxWindow
*)NULL
);
380 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
382 wxWindow
*oldParent
= GetParent();
383 if ( newParent
== oldParent
)
389 // unlink this window from the existing parent.
392 oldParent
->RemoveChild(this);
396 wxTopLevelWindows
.DeleteObject(this);
399 // add it to the new one
402 newParent
->AddChild(this);
406 wxTopLevelWindows
.Append(this);
412 // ----------------------------------------------------------------------------
413 // event handler stuff
414 // ----------------------------------------------------------------------------
416 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
418 handler
->SetNextHandler(GetEventHandler());
419 SetEventHandler(handler
);
422 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
424 wxEvtHandler
*handlerA
= GetEventHandler();
427 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
428 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
429 SetEventHandler(handlerB
);
433 handlerA
= (wxEvtHandler
*)NULL
;
440 // ----------------------------------------------------------------------------
442 // ----------------------------------------------------------------------------
444 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
446 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
449 m_backgroundColour
= colour
;
454 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
456 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
459 m_foregroundColour
= colour
;
464 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
466 // don't try to set invalid cursor, always fall back to the default
467 const wxCursor
& cursorOk
= cursor
.Ok() ? cursor
: *wxSTANDARD_CURSOR
;
469 if ( cursorOk
== m_cursor
)
480 bool wxWindowBase::SetFont(const wxFont
& font
)
482 // don't try to set invalid font, always fall back to the default
483 const wxFont
& fontOk
= font
.Ok() ? font
: *wxSWISS_FONT
;
485 if ( fontOk
== m_font
)
496 // ----------------------------------------------------------------------------
498 // ----------------------------------------------------------------------------
500 void wxWindowBase::SetValidator(const wxValidator
& validator
)
502 if ( m_windowValidator
)
503 delete m_windowValidator
;
505 m_windowValidator
= (wxValidator
*)validator
.Clone();
507 if ( m_windowValidator
)
508 m_windowValidator
->SetWindow(this) ;
511 // ----------------------------------------------------------------------------
512 // update region testing
513 // ----------------------------------------------------------------------------
515 bool wxWindowBase::IsExposed(int x
, int y
) const
517 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
520 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
522 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
525 // ----------------------------------------------------------------------------
526 // find window by id or name
527 // ----------------------------------------------------------------------------
529 wxWindow
*wxWindowBase::FindWindow( long id
)
531 if ( id
== m_windowId
)
532 return (wxWindow
*)this;
534 wxWindowBase
*res
= (wxWindow
*)NULL
;
535 wxWindowList::Node
*node
;
536 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
538 wxWindowBase
*child
= node
->GetData();
539 res
= child
->FindWindow( id
);
542 return (wxWindow
*)res
;
545 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
547 if ( name
== m_windowName
)
548 return (wxWindow
*)this;
550 wxWindowBase
*res
= (wxWindow
*)NULL
;
551 wxWindowList::Node
*node
;
552 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
554 wxWindow
*child
= node
->GetData();
555 res
= child
->FindWindow(name
);
558 return (wxWindow
*)res
;
561 // ----------------------------------------------------------------------------
562 // dialog oriented functions
563 // ----------------------------------------------------------------------------
565 void wxWindowBase::MakeModal(bool modal
)
570 bool wxWindowBase::Validate()
572 wxWindowList::Node
*node
;
573 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
575 wxWindowBase
*child
= node
->GetData();
576 wxValidator
*validator
= child
->GetValidator();
577 if ( validator
&& validator
->Validate(this) )
586 bool wxWindowBase::TransferDataToWindow()
588 wxWindowList::Node
*node
;
589 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
591 wxWindowBase
*child
= node
->GetData();
592 wxValidator
*validator
= child
->GetValidator();
593 if ( validator
&& !validator
->TransferToWindow() )
595 wxLog
*log
= wxLog::GetActiveTarget();
598 wxLogWarning(_("Could not transfer data to window"));
609 bool wxWindowBase::TransferDataFromWindow()
611 wxWindowList::Node
*node
;
612 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
614 wxWindow
*child
= node
->GetData();
615 if ( child
->GetValidator() &&
616 !child
->GetValidator()->TransferFromWindow() )
625 void wxWindowBase::InitDialog()
627 wxInitDialogEvent
event(GetId());
628 event
.SetEventObject( this );
629 GetEventHandler()->ProcessEvent(event
);
632 // ----------------------------------------------------------------------------
634 // ----------------------------------------------------------------------------
638 void wxWindowBase::SetToolTip( const wxString
&tip
)
640 // don't create the new tooltip if we already have one
643 m_tooltip
->SetTip( tip
);
647 SetToolTip( new wxToolTip( tip
) );
650 // setting empty tooltip text does not remove the tooltip any more - use
651 // SetToolTip((wxToolTip *)NULL) for this
654 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
662 #endif // wxUSE_TOOLTIPS
664 // ----------------------------------------------------------------------------
665 // constraints and sizers
666 // ----------------------------------------------------------------------------
668 #if wxUSE_CONSTRAINTS
670 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
674 UnsetConstraints(m_constraints
);
675 delete m_constraints
;
677 m_constraints
= constraints
;
680 // Make sure other windows know they're part of a 'meaningful relationship'
681 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
682 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
683 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
684 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
685 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
686 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
687 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
688 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
689 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
690 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
691 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
692 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
693 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
694 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
695 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
696 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
700 // This removes any dangling pointers to this window in other windows'
701 // constraintsInvolvedIn lists.
702 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
706 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
707 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
708 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
709 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
710 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
711 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
712 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
713 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
714 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
715 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
716 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
717 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
718 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
719 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
720 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
721 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
725 // Back-pointer to other windows we're involved with, so if we delete this
726 // window, we must delete any constraints we're involved with.
727 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
729 if ( !m_constraintsInvolvedIn
)
730 m_constraintsInvolvedIn
= new wxWindowList
;
731 if ( !m_constraintsInvolvedIn
->Find(otherWin
) )
732 m_constraintsInvolvedIn
->Append(otherWin
);
735 // REMOVE back-pointer to other windows we're involved with.
736 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
738 if ( m_constraintsInvolvedIn
)
739 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
742 // Reset any constraints that mention this window
743 void wxWindowBase::DeleteRelatedConstraints()
745 if ( m_constraintsInvolvedIn
)
747 wxWindowList::Node
*node
= m_constraintsInvolvedIn
->GetFirst();
750 wxWindow
*win
= node
->GetData();
751 wxLayoutConstraints
*constr
= win
->GetConstraints();
753 // Reset any constraints involving this window
756 constr
->left
.ResetIfWin(this);
757 constr
->top
.ResetIfWin(this);
758 constr
->right
.ResetIfWin(this);
759 constr
->bottom
.ResetIfWin(this);
760 constr
->width
.ResetIfWin(this);
761 constr
->height
.ResetIfWin(this);
762 constr
->centreX
.ResetIfWin(this);
763 constr
->centreY
.ResetIfWin(this);
766 wxWindowList::Node
*next
= node
->GetNext();
771 delete m_constraintsInvolvedIn
;
772 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
776 void wxWindowBase::SetSizer(wxSizer
*sizer
)
778 m_windowSizer
= sizer
;
780 sizer
->SetSizerParent(this);
783 bool wxWindowBase::Layout()
785 if ( GetConstraints() )
788 GetClientSize(&w
, &h
);
789 GetConstraints()->width
.SetValue(w
);
790 GetConstraints()->height
.SetValue(h
);
793 // If top level (one sizer), evaluate the sizer's constraints.
797 GetSizer()->ResetConstraints(); // Mark all constraints as unevaluated
798 GetSizer()->LayoutPhase1(&noChanges
);
799 GetSizer()->LayoutPhase2(&noChanges
);
800 GetSizer()->SetConstraintSizes(); // Recursively set the real window sizes
805 // Otherwise, evaluate child constraints
806 ResetConstraints(); // Mark all constraints as unevaluated
807 DoPhase(1); // Just one phase need if no sizers involved
809 SetConstraintSizes(); // Recursively set the real window sizes
815 // Do a phase of evaluating constraints: the default behaviour. wxSizers may
816 // do a similar thing, but also impose their own 'constraints' and order the
817 // evaluation differently.
818 bool wxWindowBase::LayoutPhase1(int *noChanges
)
820 wxLayoutConstraints
*constr
= GetConstraints();
823 return constr
->SatisfyConstraints(this, noChanges
);
829 bool wxWindowBase::LayoutPhase2(int *noChanges
)
839 // Do a phase of evaluating child constraints
840 bool wxWindowBase::DoPhase(int phase
)
842 int noIterations
= 0;
843 int maxIterations
= 500;
846 wxWindowList succeeded
;
847 while ((noChanges
> 0) && (noIterations
< maxIterations
))
851 wxWindowList::Node
*node
= GetChildren().GetFirst();
854 wxWindow
*child
= node
->GetData();
855 if ( !child
->IsKindOf(CLASSINFO(wxFrame
)) && !child
->IsKindOf(CLASSINFO(wxDialog
)) )
857 wxLayoutConstraints
*constr
= child
->GetConstraints();
860 if ( !succeeded
.Find(child
) )
862 int tempNoChanges
= 0;
863 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
864 noChanges
+= tempNoChanges
;
867 succeeded
.Append(child
);
872 node
= node
->GetNext();
881 void wxWindowBase::ResetConstraints()
883 wxLayoutConstraints
*constr
= GetConstraints();
886 constr
->left
.SetDone(FALSE
);
887 constr
->top
.SetDone(FALSE
);
888 constr
->right
.SetDone(FALSE
);
889 constr
->bottom
.SetDone(FALSE
);
890 constr
->width
.SetDone(FALSE
);
891 constr
->height
.SetDone(FALSE
);
892 constr
->centreX
.SetDone(FALSE
);
893 constr
->centreY
.SetDone(FALSE
);
895 wxWindowList::Node
*node
= GetChildren().GetFirst();
898 wxWindow
*win
= node
->GetData();
899 if ( !win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)) )
900 win
->ResetConstraints();
901 node
= node
->GetNext();
905 // Need to distinguish between setting the 'fake' size for windows and sizers,
906 // and setting the real values.
907 void wxWindowBase::SetConstraintSizes(bool recurse
)
909 wxLayoutConstraints
*constr
= GetConstraints();
910 if ( constr
&& constr
->left
.GetDone() && constr
->right
.GetDone( ) &&
911 constr
->width
.GetDone() && constr
->height
.GetDone())
913 int x
= constr
->left
.GetValue();
914 int y
= constr
->top
.GetValue();
915 int w
= constr
->width
.GetValue();
916 int h
= constr
->height
.GetValue();
918 // If we don't want to resize this window, just move it...
919 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
920 (constr
->height
.GetRelationship() != wxAsIs
))
922 // Calls Layout() recursively. AAAGH. How can we stop that.
923 // Simply take Layout() out of non-top level OnSizes.
924 SizerSetSize(x
, y
, w
, h
);
933 wxChar
*windowClass
= GetClassInfo()->GetClassName();
936 if ( GetName() == _T("") )
937 winName
= _T("unnamed");
940 wxLogDebug( _T("Constraint(s) not satisfied for window of type %s, name %s:\n"),
941 (const wxChar
*)windowClass
,
942 (const wxChar
*)winName
);
943 if ( !constr
->left
.GetDone()) wxLogDebug( _T(" unsatisfied 'left' constraint.\n") );
944 if ( !constr
->right
.GetDone()) wxLogDebug( _T(" unsatisfied 'right' constraint.\n") );
945 if ( !constr
->width
.GetDone()) wxLogDebug( _T(" unsatisfied 'width' constraint.\n") );
946 if ( !constr
->height
.GetDone()) wxLogDebug( _T(" unsatisfied 'height' constraint.\n") );
947 wxLogDebug( _T("Please check constraints: try adding AsIs() constraints.\n") );
952 wxWindowList::Node
*node
= GetChildren().GetFirst();
955 wxWindow
*win
= node
->GetData();
956 if ( !win
->IsKindOf(CLASSINFO(wxFrame
)) && !win
->IsKindOf(CLASSINFO(wxDialog
)) )
957 win
->SetConstraintSizes();
958 node
= node
->GetNext();
963 // This assumes that all sizers are 'on' the same window, i.e. the parent of
965 void wxWindowBase::TransformSizerToActual(int *x
, int *y
) const
967 if ( !m_sizerParent
|| m_sizerParent
->IsKindOf(CLASSINFO(wxDialog
) ) ||
968 m_sizerParent
->IsKindOf(CLASSINFO(wxFrame
)) )
972 m_sizerParent
->GetPosition(&xp
, &yp
);
973 m_sizerParent
->TransformSizerToActual(&xp
, &yp
);
978 void wxWindowBase::SizerSetSize(int x
, int y
, int w
, int h
)
982 TransformSizerToActual(&xx
, &yy
);
983 SetSize(xx
, yy
, w
, h
);
986 void wxWindowBase::SizerMove(int x
, int y
)
990 TransformSizerToActual(&xx
, &yy
);
994 // Only set the size/position of the constraint (if any)
995 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
997 wxLayoutConstraints
*constr
= GetConstraints();
1002 constr
->left
.SetValue(x
);
1003 constr
->left
.SetDone(TRUE
);
1007 constr
->top
.SetValue(y
);
1008 constr
->top
.SetDone(TRUE
);
1012 constr
->width
.SetValue(w
);
1013 constr
->width
.SetDone(TRUE
);
1017 constr
->height
.SetValue(h
);
1018 constr
->height
.SetDone(TRUE
);
1023 void wxWindowBase::MoveConstraint(int x
, int y
)
1025 wxLayoutConstraints
*constr
= GetConstraints();
1030 constr
->left
.SetValue(x
);
1031 constr
->left
.SetDone(TRUE
);
1035 constr
->top
.SetValue(y
);
1036 constr
->top
.SetDone(TRUE
);
1041 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1043 wxLayoutConstraints
*constr
= GetConstraints();
1046 *w
= constr
->width
.GetValue();
1047 *h
= constr
->height
.GetValue();
1053 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1055 wxLayoutConstraints
*constr
= GetConstraints();
1058 *w
= constr
->width
.GetValue();
1059 *h
= constr
->height
.GetValue();
1062 GetClientSize(w
, h
);
1065 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1067 wxLayoutConstraints
*constr
= GetConstraints();
1070 *x
= constr
->left
.GetValue();
1071 *y
= constr
->top
.GetValue();
1077 #endif // wxUSE_CONSTRAINTS
1079 // ----------------------------------------------------------------------------
1080 // do Update UI processing for child controls
1081 // ----------------------------------------------------------------------------
1083 // TODO: should this be implemented for the child window rather
1084 // than the parent? Then you can override it e.g. for wxCheckBox
1085 // to do the Right Thing rather than having to assume a fixed number
1086 // of control classes.
1087 void wxWindowBase::UpdateWindowUI()
1089 wxWindowID id
= GetId();
1092 wxUpdateUIEvent
event(id
);
1093 event
.m_eventObject
= this;
1095 if ( GetEventHandler()->ProcessEvent(event
) )
1097 if ( event
.GetSetEnabled() )
1098 Enable(event
.GetEnabled());
1100 if ( event
.GetSetText() && IsKindOf(CLASSINFO(wxControl
)) )
1101 ((wxControl
*)this)->SetLabel(event
.GetText());
1103 if ( IsKindOf(CLASSINFO(wxCheckBox
)) )
1105 if ( event
.GetSetChecked() )
1106 ((wxCheckBox
*)this)->SetValue(event
.GetChecked());
1108 // TODO No radio buttons in wxGTK yet
1110 else if ( IsKindOf(CLASSINFO(wxRadioButton
)) )
1112 if ( event
.GetSetChecked() )
1113 ((wxRadioButton
*) this)->SetValue(event
.GetChecked());
1120 // ----------------------------------------------------------------------------
1121 // dialog units translations
1122 // ----------------------------------------------------------------------------
1124 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1126 int charWidth
= GetCharWidth();
1127 int charHeight
= GetCharHeight();
1129 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1130 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1135 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1137 int charWidth
= GetCharWidth();
1138 int charHeight
= GetCharHeight();
1140 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1141 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1146 // ----------------------------------------------------------------------------
1148 // ----------------------------------------------------------------------------
1150 // propagate the colour change event to the subwindows
1151 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1153 wxWindowList::Node
*node
= GetChildren().GetFirst();
1156 // Only propagate to non-top-level windows
1157 wxWindow
*win
= node
->GetData();
1158 if ( !win
->IsTopLevel() )
1160 wxSysColourChangedEvent event2
;
1161 event
.m_eventObject
= win
;
1162 win
->GetEventHandler()->ProcessEvent(event2
);
1165 node
= node
->GetNext();
1169 // the default action is to populate dialog with data when it's created
1170 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1172 TransferDataToWindow();
1175 // ----------------------------------------------------------------------------
1176 // list classes implementation
1177 // ----------------------------------------------------------------------------
1179 void wxWindowListNode::DeleteData()
1181 delete (wxWindow
*)GetData();