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/textctrl.h"
41 #include "wx/settings.h"
42 #include "wx/dialog.h"
43 #include "wx/msgdlg.h"
47 #include "wx/layout.h"
49 #endif // wxUSE_CONSTRAINTS
51 #if wxUSE_DRAG_AND_DROP
53 #endif // wxUSE_DRAG_AND_DROP
56 #include "wx/tooltip.h"
57 #endif // wxUSE_TOOLTIPS
63 // ----------------------------------------------------------------------------
65 // ----------------------------------------------------------------------------
67 int wxWindowBase::ms_lastControlId
= -200;
69 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
71 // ----------------------------------------------------------------------------
73 // ----------------------------------------------------------------------------
75 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
76 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
77 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
78 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick
)
81 // ============================================================================
82 // implementation of the common functionality of the wxWindow class
83 // ============================================================================
85 // ----------------------------------------------------------------------------
87 // ----------------------------------------------------------------------------
89 // the default initialization
90 void wxWindowBase::InitBase()
92 // no window yet, no parent nor children
93 m_parent
= (wxWindow
*)NULL
;
95 m_children
.DeleteContents( FALSE
); // don't auto delete node data
97 // no constraints on the minimal window size
103 // window is created enabled but it's not visible yet
107 // no client data (yet)
109 m_clientDataType
= ClientData_None
;
111 // the default event handler is just this window
112 m_eventHandler
= this;
116 m_windowValidator
= (wxValidator
*) NULL
;
117 #endif // wxUSE_VALIDATORS
119 // use the system default colours
120 wxSystemSettings settings
;
122 m_backgroundColour
= settings
.GetSystemColour(wxSYS_COLOUR_BTNFACE
);
123 // m_foregroundColour = *wxBLACK; // TODO take this from sys settings too?
124 m_foregroundColour
= wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOWTEXT
);
126 // GRG, changed Mar/2000
127 #if 0 // !defined(__WXMAC__) && !defined(__WXGTK__)
128 m_font
= *wxSWISS_FONT
; // and this?
130 m_font
= settings
.GetSystemFont(wxSYS_DEFAULT_GUI_FONT
);
136 // an optimization for the event processing: checking this flag is much
137 // faster than using IsKindOf(CLASSINFO(wxWindow))
140 #if wxUSE_CONSTRAINTS
141 // no constraints whatsoever
142 m_constraints
= (wxLayoutConstraints
*) NULL
;
143 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
144 m_windowSizer
= (wxSizer
*) NULL
;
145 m_autoLayout
= FALSE
;
146 #endif // wxUSE_CONSTRAINTS
148 #if wxUSE_DRAG_AND_DROP
149 m_dropTarget
= (wxDropTarget
*)NULL
;
150 #endif // wxUSE_DRAG_AND_DROP
153 m_tooltip
= (wxToolTip
*)NULL
;
154 #endif // wxUSE_TOOLTIPS
157 m_caret
= (wxCaret
*)NULL
;
158 #endif // wxUSE_CARET
161 // common part of window creation process
162 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
164 const wxPoint
& WXUNUSED(pos
),
165 const wxSize
& WXUNUSED(size
),
167 const wxValidator
& validator
,
168 const wxString
& name
)
170 // m_isWindow is set to TRUE in wxWindowBase::Init() as well as many other
171 // member variables - check that it has been called (will catch the case
172 // when a new ctor is added which doesn't call InitWindow)
173 wxASSERT_MSG( m_isWindow
, wxT("Init() must have been called before!") );
175 // generate a new id if the user doesn't care about it
176 m_windowId
= id
== -1 ? NewControlId() : id
;
179 SetWindowStyleFlag(style
);
183 SetValidator(validator
);
184 #endif // wxUSE_VALIDATORS
186 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
187 // have it too - like this it's possible to set it only in the top level
188 // dialog/frame and all children will inherit it by defult
189 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
191 SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY
);
197 // ----------------------------------------------------------------------------
199 // ----------------------------------------------------------------------------
202 wxWindowBase::~wxWindowBase()
204 // FIXME if these 2 cases result from programming errors in the user code
205 // we should probably assert here instead of silently fixing them
207 // Just in case the window has been Closed, but we're then deleting
208 // immediately: don't leave dangling pointers.
209 wxPendingDelete
.DeleteObject(this);
211 // Just in case we've loaded a top-level window via LoadNativeDialog but
212 // we weren't a dialog class
213 wxTopLevelWindows
.DeleteObject(this);
215 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
217 // make sure that there are no dangling pointers left pointing to us
218 wxPanel
*panel
= wxDynamicCast(GetParent(), wxPanel
);
221 if ( panel
->GetLastFocus() == this )
223 panel
->SetLastFocus((wxWindow
*)NULL
);
230 #endif // wxUSE_CARET
233 if ( m_windowValidator
)
234 delete m_windowValidator
;
235 #endif // wxUSE_VALIDATORS
237 // we only delete object data, not untyped
238 if ( m_clientDataType
== ClientData_Object
)
239 delete m_clientObject
;
241 #if wxUSE_CONSTRAINTS
242 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
243 // at deleted windows as they delete themselves.
244 DeleteRelatedConstraints();
248 // This removes any dangling pointers to this window in other windows'
249 // constraintsInvolvedIn lists.
250 UnsetConstraints(m_constraints
);
251 delete m_constraints
;
252 m_constraints
= NULL
;
256 delete m_windowSizer
;
258 #endif // wxUSE_CONSTRAINTS
260 #if wxUSE_DRAG_AND_DROP
263 #endif // wxUSE_DRAG_AND_DROP
268 #endif // wxUSE_TOOLTIPS
271 bool wxWindowBase::Destroy()
278 bool wxWindowBase::Close(bool force
)
280 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
281 event
.SetEventObject(this);
282 #if WXWIN_COMPATIBILITY
283 event
.SetForce(force
);
284 #endif // WXWIN_COMPATIBILITY
285 event
.SetCanVeto(!force
);
287 // return FALSE if window wasn't closed because the application vetoed the
289 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
292 bool wxWindowBase::DestroyChildren()
294 wxWindowList::Node
*node
;
297 // we iterate until the list becomes empty
298 node
= GetChildren().GetFirst();
302 wxWindow
*child
= node
->GetData();
304 wxASSERT_MSG( child
, wxT("children list contains empty nodes") );
308 wxASSERT_MSG( !GetChildren().Find(child
),
309 wxT("child didn't remove itself using RemoveChild()") );
315 // ----------------------------------------------------------------------------
316 // size/position related methods
317 // ----------------------------------------------------------------------------
319 // centre the window with respect to its parent in either (or both) directions
320 void wxWindowBase::Centre(int direction
)
322 int widthParent
, heightParent
;
324 wxWindow
*parent
= GetParent();
328 direction
|= wxCENTRE_ON_SCREEN
;
331 if ( direction
& wxCENTRE_ON_SCREEN
)
333 // centre with respect to the whole screen
334 wxDisplaySize(&widthParent
, &heightParent
);
338 // centre inside the parents rectangle
339 parent
->GetClientSize(&widthParent
, &heightParent
);
343 GetSize(&width
, &height
);
348 if ( direction
& wxHORIZONTAL
)
349 xNew
= (widthParent
- width
)/2;
351 if ( direction
& wxVERTICAL
)
352 yNew
= (heightParent
- height
)/2;
354 // controls are always centered on their parent because it doesn't make
355 // sense to centre them on the screen
356 if ( !(direction
& wxCENTRE_ON_SCREEN
) || !IsTopLevel() )
358 // the only chance to get this is to have a not top level window
359 // without parent which shouldn't happen
360 wxCHECK_RET( parent
, wxT("this window must have a parent") );
362 // adjust to the parents client area origin
363 wxPoint posParent
= parent
->ClientToScreen(wxPoint(0, 0));
369 // move the centre of this window to this position
373 // fits the window around the children
374 void wxWindowBase::Fit()
376 if ( GetChildren().GetCount() > 0 )
378 SetClientSize(DoGetBestSize());
380 //else: do nothing if we have no children
383 // return the size best suited for the current window
384 wxSize
wxWindowBase::DoGetBestSize() const
386 if ( GetChildren().GetCount() > 0 )
388 // our minimal acceptable size is such that all our windows fit inside
392 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
394 node
= node
->GetNext() )
396 wxWindow
*win
= node
->GetData();
397 if ( win
->IsTopLevel() )
399 // dialogs and frames lie in different top level windows -
400 // don't deal with them here
405 win
->GetPosition(&wx
, &wy
);
407 // if the window hadn't been positioned yet, assume that it is in
414 win
->GetSize(&ww
, &wh
);
415 if ( wx
+ ww
> maxX
)
417 if ( wy
+ wh
> maxY
)
422 return wxSize(maxX
+ 7, maxY
+ 14);
426 // for a generic window there is no natural best size - just use the
432 // set the min/max size of the window
433 void wxWindowBase::SetSizeHints(int minW
, int minH
,
435 int WXUNUSED(incW
), int WXUNUSED(incH
))
443 // ----------------------------------------------------------------------------
444 // show/hide/enable/disable the window
445 // ----------------------------------------------------------------------------
447 bool wxWindowBase::Show(bool show
)
449 if ( show
!= m_isShown
)
461 bool wxWindowBase::Enable(bool enable
)
463 if ( enable
!= m_isEnabled
)
465 m_isEnabled
= enable
;
474 // ----------------------------------------------------------------------------
476 // ----------------------------------------------------------------------------
478 bool wxWindowBase::IsTopLevel() const
483 // ----------------------------------------------------------------------------
484 // reparenting the window
485 // ----------------------------------------------------------------------------
487 void wxWindowBase::AddChild(wxWindowBase
*child
)
489 wxCHECK_RET( child
, wxT("can't add a NULL child") );
491 GetChildren().Append(child
);
492 child
->SetParent(this);
495 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
497 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
499 GetChildren().DeleteObject(child
);
500 child
->SetParent((wxWindow
*)NULL
);
503 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
505 wxWindow
*oldParent
= GetParent();
506 if ( newParent
== oldParent
)
512 // unlink this window from the existing parent.
515 oldParent
->RemoveChild(this);
519 wxTopLevelWindows
.DeleteObject(this);
522 // add it to the new one
525 newParent
->AddChild(this);
529 wxTopLevelWindows
.Append(this);
535 // ----------------------------------------------------------------------------
536 // event handler stuff
537 // ----------------------------------------------------------------------------
539 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
541 handler
->SetNextHandler(GetEventHandler());
542 SetEventHandler(handler
);
545 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
547 wxEvtHandler
*handlerA
= GetEventHandler();
550 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
551 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
552 SetEventHandler(handlerB
);
556 handlerA
= (wxEvtHandler
*)NULL
;
563 // ----------------------------------------------------------------------------
565 // ----------------------------------------------------------------------------
567 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
569 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
572 m_backgroundColour
= colour
;
577 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
579 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
582 m_foregroundColour
= colour
;
587 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
589 // don't try to set invalid cursor, always fall back to the default
590 const wxCursor
& cursorOk
= cursor
.Ok() ? cursor
: *wxSTANDARD_CURSOR
;
592 if ( (wxCursor
&)cursorOk
== m_cursor
)
603 bool wxWindowBase::SetFont(const wxFont
& font
)
605 // don't try to set invalid font, always fall back to the default
606 const wxFont
& fontOk
= font
.Ok() ? font
: *wxSWISS_FONT
;
608 if ( (wxFont
&)fontOk
== m_font
)
620 void wxWindowBase::SetCaret(wxCaret
*caret
)
631 wxASSERT_MSG( m_caret
->GetWindow() == this,
632 wxT("caret should be created associated to this window") );
635 #endif // wxUSE_CARET
638 // ----------------------------------------------------------------------------
640 // ----------------------------------------------------------------------------
642 void wxWindowBase::SetValidator(const wxValidator
& validator
)
644 if ( m_windowValidator
)
645 delete m_windowValidator
;
647 m_windowValidator
= (wxValidator
*)validator
.Clone();
649 if ( m_windowValidator
)
650 m_windowValidator
->SetWindow(this) ;
652 #endif // wxUSE_VALIDATORS
654 // ----------------------------------------------------------------------------
655 // update region testing
656 // ----------------------------------------------------------------------------
658 bool wxWindowBase::IsExposed(int x
, int y
) const
660 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
663 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
665 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
668 // ----------------------------------------------------------------------------
669 // find window by id or name
670 // ----------------------------------------------------------------------------
672 wxWindow
*wxWindowBase::FindWindow( long id
)
674 if ( id
== m_windowId
)
675 return (wxWindow
*)this;
677 wxWindowBase
*res
= (wxWindow
*)NULL
;
678 wxWindowList::Node
*node
;
679 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
681 wxWindowBase
*child
= node
->GetData();
682 res
= child
->FindWindow( id
);
685 return (wxWindow
*)res
;
688 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
690 if ( name
== m_windowName
)
691 return (wxWindow
*)this;
693 wxWindowBase
*res
= (wxWindow
*)NULL
;
694 wxWindowList::Node
*node
;
695 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
697 wxWindow
*child
= node
->GetData();
698 res
= child
->FindWindow(name
);
701 return (wxWindow
*)res
;
704 // ----------------------------------------------------------------------------
705 // dialog oriented functions
706 // ----------------------------------------------------------------------------
708 void wxWindowBase::MakeModal(bool modal
)
710 // Disable all other windows
713 wxWindowList::Node
*node
= wxTopLevelWindows
.GetFirst();
716 wxWindow
*win
= node
->GetData();
720 node
= node
->GetNext();
725 bool wxWindowBase::Validate()
728 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
730 wxWindowList::Node
*node
;
731 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
733 wxWindowBase
*child
= node
->GetData();
734 wxValidator
*validator
= child
->GetValidator();
735 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
740 if ( recurse
&& !child
->Validate() )
745 #endif // wxUSE_VALIDATORS
750 bool wxWindowBase::TransferDataToWindow()
753 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
755 wxWindowList::Node
*node
;
756 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
758 wxWindowBase
*child
= node
->GetData();
759 wxValidator
*validator
= child
->GetValidator();
760 if ( validator
&& !validator
->TransferToWindow() )
762 wxLogWarning(_("Could not transfer data to window"));
763 wxLog::FlushActive();
770 if ( !child
->TransferDataToWindow() )
772 // warning already given
777 #endif // wxUSE_VALIDATORS
782 bool wxWindowBase::TransferDataFromWindow()
785 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
787 wxWindowList::Node
*node
;
788 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
790 wxWindow
*child
= node
->GetData();
791 wxValidator
*validator
= child
->GetValidator();
792 if ( validator
&& !validator
->TransferFromWindow() )
794 // nop warning here because the application is supposed to give
795 // one itself - we don't know here what might have gone wrongly
802 if ( !child
->TransferDataFromWindow() )
804 // warning already given
809 #endif // wxUSE_VALIDATORS
814 void wxWindowBase::InitDialog()
816 wxInitDialogEvent
event(GetId());
817 event
.SetEventObject( this );
818 GetEventHandler()->ProcessEvent(event
);
821 // ----------------------------------------------------------------------------
823 // ----------------------------------------------------------------------------
827 void wxWindowBase::SetToolTip( const wxString
&tip
)
829 // don't create the new tooltip if we already have one
832 m_tooltip
->SetTip( tip
);
836 SetToolTip( new wxToolTip( tip
) );
839 // setting empty tooltip text does not remove the tooltip any more - use
840 // SetToolTip((wxToolTip *)NULL) for this
843 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
851 #endif // wxUSE_TOOLTIPS
853 // ----------------------------------------------------------------------------
854 // constraints and sizers
855 // ----------------------------------------------------------------------------
857 #if wxUSE_CONSTRAINTS
859 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
863 UnsetConstraints(m_constraints
);
864 delete m_constraints
;
866 m_constraints
= constraints
;
869 // Make sure other windows know they're part of a 'meaningful relationship'
870 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
871 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
872 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
873 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
874 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
875 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
876 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
877 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
878 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
879 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
880 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
881 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
882 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
883 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
884 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
885 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
889 // This removes any dangling pointers to this window in other windows'
890 // constraintsInvolvedIn lists.
891 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
895 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
896 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
897 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
898 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
899 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
900 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
901 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
902 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
903 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
904 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
905 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
906 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
907 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
908 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
909 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
910 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
914 // Back-pointer to other windows we're involved with, so if we delete this
915 // window, we must delete any constraints we're involved with.
916 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
918 if ( !m_constraintsInvolvedIn
)
919 m_constraintsInvolvedIn
= new wxWindowList
;
920 if ( !m_constraintsInvolvedIn
->Find(otherWin
) )
921 m_constraintsInvolvedIn
->Append(otherWin
);
924 // REMOVE back-pointer to other windows we're involved with.
925 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
927 if ( m_constraintsInvolvedIn
)
928 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
931 // Reset any constraints that mention this window
932 void wxWindowBase::DeleteRelatedConstraints()
934 if ( m_constraintsInvolvedIn
)
936 wxWindowList::Node
*node
= m_constraintsInvolvedIn
->GetFirst();
939 wxWindow
*win
= node
->GetData();
940 wxLayoutConstraints
*constr
= win
->GetConstraints();
942 // Reset any constraints involving this window
945 constr
->left
.ResetIfWin(this);
946 constr
->top
.ResetIfWin(this);
947 constr
->right
.ResetIfWin(this);
948 constr
->bottom
.ResetIfWin(this);
949 constr
->width
.ResetIfWin(this);
950 constr
->height
.ResetIfWin(this);
951 constr
->centreX
.ResetIfWin(this);
952 constr
->centreY
.ResetIfWin(this);
955 wxWindowList::Node
*next
= node
->GetNext();
960 delete m_constraintsInvolvedIn
;
961 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
965 void wxWindowBase::SetSizer(wxSizer
*sizer
)
967 if (m_windowSizer
) delete m_windowSizer
;
969 m_windowSizer
= sizer
;
972 bool wxWindowBase::Layout()
974 // If there is a sizer, use it instead of the constraints
978 GetClientSize(&w
, &h
);
980 GetSizer()->SetDimension( 0, 0, w
, h
);
984 wxLayoutConstraints
*constr
= GetConstraints();
985 bool wasOk
= constr
&& constr
->AreSatisfied();
987 ResetConstraints(); // Mark all constraints as unevaluated
989 // if we're a top level panel (i.e. our parent is frame/dialog), our
990 // own constraints will never be satisfied any more unless we do it
995 while ( noChanges
> 0 )
997 constr
->SatisfyConstraints(this, &noChanges
);
1001 DoPhase(1); // Layout children
1002 DoPhase(2); // Layout grand children
1003 SetConstraintSizes(); // Recursively set the real window sizes
1010 // Do a phase of evaluating constraints: the default behaviour. wxSizers may
1011 // do a similar thing, but also impose their own 'constraints' and order the
1012 // evaluation differently.
1013 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1015 wxLayoutConstraints
*constr
= GetConstraints();
1018 return constr
->SatisfyConstraints(this, noChanges
);
1024 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1034 // Do a phase of evaluating child constraints
1035 bool wxWindowBase::DoPhase(int phase
)
1037 int noIterations
= 0;
1038 int maxIterations
= 500;
1041 wxWindowList succeeded
;
1042 while ((noChanges
> 0) && (noIterations
< maxIterations
))
1046 wxWindowList::Node
*node
= GetChildren().GetFirst();
1049 wxWindow
*child
= node
->GetData();
1050 if ( !child
->IsTopLevel() )
1052 wxLayoutConstraints
*constr
= child
->GetConstraints();
1055 if ( !succeeded
.Find(child
) )
1057 int tempNoChanges
= 0;
1058 bool success
= ( (phase
== 1) ? child
->LayoutPhase1(&tempNoChanges
) : child
->LayoutPhase2(&tempNoChanges
) ) ;
1059 noChanges
+= tempNoChanges
;
1062 succeeded
.Append(child
);
1067 node
= node
->GetNext();
1076 void wxWindowBase::ResetConstraints()
1078 wxLayoutConstraints
*constr
= GetConstraints();
1081 constr
->left
.SetDone(FALSE
);
1082 constr
->top
.SetDone(FALSE
);
1083 constr
->right
.SetDone(FALSE
);
1084 constr
->bottom
.SetDone(FALSE
);
1085 constr
->width
.SetDone(FALSE
);
1086 constr
->height
.SetDone(FALSE
);
1087 constr
->centreX
.SetDone(FALSE
);
1088 constr
->centreY
.SetDone(FALSE
);
1091 wxWindowList::Node
*node
= GetChildren().GetFirst();
1094 wxWindow
*win
= node
->GetData();
1095 if ( !win
->IsTopLevel() )
1096 win
->ResetConstraints();
1097 node
= node
->GetNext();
1101 // Need to distinguish between setting the 'fake' size for windows and sizers,
1102 // and setting the real values.
1103 void wxWindowBase::SetConstraintSizes(bool recurse
)
1105 wxLayoutConstraints
*constr
= GetConstraints();
1106 if ( constr
&& constr
->AreSatisfied() )
1108 int x
= constr
->left
.GetValue();
1109 int y
= constr
->top
.GetValue();
1110 int w
= constr
->width
.GetValue();
1111 int h
= constr
->height
.GetValue();
1113 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1114 (constr
->height
.GetRelationship() != wxAsIs
) )
1116 SetSize(x
, y
, w
, h
);
1120 // If we don't want to resize this window, just move it...
1126 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1127 GetClassInfo()->GetClassName(),
1133 wxWindowList::Node
*node
= GetChildren().GetFirst();
1136 wxWindow
*win
= node
->GetData();
1137 if ( !win
->IsTopLevel() )
1138 win
->SetConstraintSizes();
1139 node
= node
->GetNext();
1144 // Only set the size/position of the constraint (if any)
1145 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1147 wxLayoutConstraints
*constr
= GetConstraints();
1152 constr
->left
.SetValue(x
);
1153 constr
->left
.SetDone(TRUE
);
1157 constr
->top
.SetValue(y
);
1158 constr
->top
.SetDone(TRUE
);
1162 constr
->width
.SetValue(w
);
1163 constr
->width
.SetDone(TRUE
);
1167 constr
->height
.SetValue(h
);
1168 constr
->height
.SetDone(TRUE
);
1173 void wxWindowBase::MoveConstraint(int x
, int y
)
1175 wxLayoutConstraints
*constr
= GetConstraints();
1180 constr
->left
.SetValue(x
);
1181 constr
->left
.SetDone(TRUE
);
1185 constr
->top
.SetValue(y
);
1186 constr
->top
.SetDone(TRUE
);
1191 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1193 wxLayoutConstraints
*constr
= GetConstraints();
1196 *w
= constr
->width
.GetValue();
1197 *h
= constr
->height
.GetValue();
1203 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1205 wxLayoutConstraints
*constr
= GetConstraints();
1208 *w
= constr
->width
.GetValue();
1209 *h
= constr
->height
.GetValue();
1212 GetClientSize(w
, h
);
1215 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1217 wxLayoutConstraints
*constr
= GetConstraints();
1220 *x
= constr
->left
.GetValue();
1221 *y
= constr
->top
.GetValue();
1227 #endif // wxUSE_CONSTRAINTS
1229 // ----------------------------------------------------------------------------
1230 // do Update UI processing for child controls
1231 // ----------------------------------------------------------------------------
1233 // TODO: should this be implemented for the child window rather
1234 // than the parent? Then you can override it e.g. for wxCheckBox
1235 // to do the Right Thing rather than having to assume a fixed number
1236 // of control classes.
1237 void wxWindowBase::UpdateWindowUI()
1239 wxUpdateUIEvent
event(GetId());
1240 event
.m_eventObject
= this;
1242 if ( GetEventHandler()->ProcessEvent(event
) )
1244 if ( event
.GetSetEnabled() )
1245 Enable(event
.GetEnabled());
1247 if ( event
.GetSetText() )
1249 wxControl
*control
= wxDynamicCast(this, wxControl
);
1252 wxTextCtrl
*text
= wxDynamicCast(control
, wxTextCtrl
);
1254 text
->SetValue(event
.GetText());
1256 control
->SetLabel(event
.GetText());
1261 wxCheckBox
*checkbox
= wxDynamicCast(this, wxCheckBox
);
1264 if ( event
.GetSetChecked() )
1265 checkbox
->SetValue(event
.GetChecked());
1267 #endif // wxUSE_CHECKBOX
1270 wxRadioButton
*radiobtn
= wxDynamicCast(this, wxRadioButton
);
1273 if ( event
.GetSetChecked() )
1274 radiobtn
->SetValue(event
.GetChecked());
1276 #endif // wxUSE_RADIOBTN
1280 // ----------------------------------------------------------------------------
1281 // dialog units translations
1282 // ----------------------------------------------------------------------------
1284 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1286 int charWidth
= GetCharWidth();
1287 int charHeight
= GetCharHeight();
1288 wxPoint
pt2(-1, -1);
1290 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1292 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1297 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1299 int charWidth
= GetCharWidth();
1300 int charHeight
= GetCharHeight();
1301 wxPoint
pt2(-1, -1);
1303 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1305 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1310 // ----------------------------------------------------------------------------
1312 // ----------------------------------------------------------------------------
1314 void wxWindowBase::DoSetClientObject( wxClientData
*data
)
1316 wxASSERT_MSG( m_clientDataType
!= ClientData_Void
,
1317 wxT("can't have both object and void client data") );
1319 if ( m_clientObject
)
1320 delete m_clientObject
;
1322 m_clientObject
= data
;
1323 m_clientDataType
= ClientData_Object
;
1326 wxClientData
*wxWindowBase::DoGetClientObject() const
1328 // it's not an error to call GetClientObject() on a window which doesn't
1329 // have client data at all - NULL will be returned
1330 wxASSERT_MSG( m_clientDataType
!= ClientData_Void
,
1331 wxT("this window doesn't have object client data") );
1333 return m_clientObject
;
1336 void wxWindowBase::DoSetClientData( void *data
)
1338 wxASSERT_MSG( m_clientDataType
!= ClientData_Object
,
1339 wxT("can't have both object and void client data") );
1341 m_clientData
= data
;
1342 m_clientDataType
= ClientData_Void
;
1345 void *wxWindowBase::DoGetClientData() const
1347 // it's not an error to call GetClientData() on a window which doesn't have
1348 // client data at all - NULL will be returned
1349 wxASSERT_MSG( m_clientDataType
!= ClientData_Object
,
1350 wxT("this window doesn't have void client data") );
1352 return m_clientData
;
1355 // ----------------------------------------------------------------------------
1357 // ----------------------------------------------------------------------------
1359 // propagate the colour change event to the subwindows
1360 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1362 wxWindowList::Node
*node
= GetChildren().GetFirst();
1365 // Only propagate to non-top-level windows
1366 wxWindow
*win
= node
->GetData();
1367 if ( !win
->IsTopLevel() )
1369 wxSysColourChangedEvent event2
;
1370 event
.m_eventObject
= win
;
1371 win
->GetEventHandler()->ProcessEvent(event2
);
1374 node
= node
->GetNext();
1378 // the default action is to populate dialog with data when it's created
1379 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1381 TransferDataToWindow();
1384 // process Ctrl-Alt-mclick
1385 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
1387 if ( event
.ControlDown() && event
.AltDown() )
1389 // don't translate these strings
1391 switch ( wxGetOsVersion() )
1393 case wxMOTIF_X
: port
= _T("Motif"); break;
1394 case wxMACINTOSH
: port
= _T("Mac"); break;
1395 case wxBEOS
: port
= _T("BeOS"); break;
1399 case wxGTK_BEOS
: port
= _T("GTK"); break;
1405 case wxWIN386
: port
= _T("MS Windows"); break;
1409 case wxMGL_OS2
: port
= _T("MGL"); break;
1411 case wxOS2_PM
: port
= _T("OS/2"); break;
1412 default: port
= _T("unknown"); break;
1415 wxMessageBox(wxString::Format(
1417 " wxWindows Library (%s port)\n"
1418 "Version %u.%u.%u, compiled at %s %s\n"
1419 " Copyright (c) 1995-2000 wxWindows team"
1428 _T("wxWindows information"),
1429 wxICON_INFORMATION
| wxOK
,
1438 // ----------------------------------------------------------------------------
1439 // list classes implementation
1440 // ----------------------------------------------------------------------------
1442 void wxWindowListNode::DeleteData()
1444 delete (wxWindow
*)GetData();