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 licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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/control.h"
39 #include "wx/checkbox.h"
40 #include "wx/radiobut.h"
41 #include "wx/statbox.h"
42 #include "wx/textctrl.h"
43 #include "wx/settings.h"
44 #include "wx/dialog.h"
45 #include "wx/msgdlg.h"
46 #include "wx/statusbr.h"
47 #include "wx/dcclient.h"
51 #include "wx/layout.h"
52 #endif // wxUSE_CONSTRAINTS
56 #if wxUSE_DRAG_AND_DROP
58 #endif // wxUSE_DRAG_AND_DROP
60 #if wxUSE_ACCESSIBILITY
61 #include "wx/access.h"
65 #include "wx/cshelp.h"
69 #include "wx/tooltip.h"
70 #endif // wxUSE_TOOLTIPS
76 // ----------------------------------------------------------------------------
78 // ----------------------------------------------------------------------------
81 int wxWindowBase::ms_lastControlId
= 2000;
83 int wxWindowBase::ms_lastControlId
= -200;
86 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
88 // ----------------------------------------------------------------------------
90 // ----------------------------------------------------------------------------
92 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
93 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
94 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
95 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick
)
98 EVT_HELP(wxID_ANY
, wxWindowBase::OnHelp
)
103 // ============================================================================
104 // implementation of the common functionality of the wxWindow class
105 // ============================================================================
107 // ----------------------------------------------------------------------------
109 // ----------------------------------------------------------------------------
111 // the default initialization
112 wxWindowBase::wxWindowBase()
114 // no window yet, no parent nor children
115 m_parent
= (wxWindow
*)NULL
;
116 m_windowId
= wxID_ANY
;
118 // no constraints on the minimal window size
124 // window are created enabled and visible by default
128 // the default event handler is just this window
129 m_eventHandler
= this;
133 m_windowValidator
= (wxValidator
*) NULL
;
134 #endif // wxUSE_VALIDATORS
136 // the colours/fonts are default for now, so leave m_font,
137 // m_backgroundColour and m_foregroundColour uninitialized and set those
146 #if wxUSE_CONSTRAINTS
147 // no constraints whatsoever
148 m_constraints
= (wxLayoutConstraints
*) NULL
;
149 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
150 #endif // wxUSE_CONSTRAINTS
152 m_windowSizer
= (wxSizer
*) NULL
;
153 m_containingSizer
= (wxSizer
*) NULL
;
154 m_autoLayout
= false;
156 #if wxUSE_DRAG_AND_DROP
157 m_dropTarget
= (wxDropTarget
*)NULL
;
158 #endif // wxUSE_DRAG_AND_DROP
161 m_tooltip
= (wxToolTip
*)NULL
;
162 #endif // wxUSE_TOOLTIPS
165 m_caret
= (wxCaret
*)NULL
;
166 #endif // wxUSE_CARET
169 m_hasCustomPalette
= false;
170 #endif // wxUSE_PALETTE
172 #if wxUSE_ACCESSIBILITY
176 m_virtualSize
= wxDefaultSize
;
181 m_maxVirtualHeight
= -1;
183 m_windowVariant
= wxWINDOW_VARIANT_NORMAL
;
185 // Whether we're using the current theme for this window (wxGTK only for now)
186 m_themeEnabled
= false;
188 // VZ: this one shouldn't exist...
189 m_isBeingDeleted
= false;
192 // common part of window creation process
193 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
195 const wxPoint
& WXUNUSED(pos
),
196 const wxSize
& WXUNUSED(size
),
198 const wxValidator
& wxVALIDATOR_PARAM(validator
),
199 const wxString
& name
)
202 // wxGTK doesn't allow to create controls with static box as the parent so
203 // this will result in a crash when the program is ported to wxGTK so warn
206 // if you get this assert, the correct solution is to create the controls
207 // as siblings of the static box
208 wxASSERT_MSG( !parent
|| !wxDynamicCast(parent
, wxStaticBox
),
209 _T("wxStaticBox can't be used as a window parent!") );
210 #endif // wxUSE_STATBOX
212 // ids are limited to 16 bits under MSW so if you care about portability,
213 // it's not a good idea to use ids out of this range (and negative ids are
214 // reserved for wxWindows own usage)
215 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767),
216 _T("invalid id value") );
218 // generate a new id if the user doesn't care about it
219 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
222 SetWindowStyleFlag(style
);
226 SetValidator(validator
);
227 #endif // wxUSE_VALIDATORS
229 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
230 // have it too - like this it's possible to set it only in the top level
231 // dialog/frame and all children will inherit it by defult
232 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
234 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
240 // ----------------------------------------------------------------------------
242 // ----------------------------------------------------------------------------
245 wxWindowBase::~wxWindowBase()
247 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
249 // FIXME if these 2 cases result from programming errors in the user code
250 // we should probably assert here instead of silently fixing them
252 // Just in case the window has been Closed, but we're then deleting
253 // immediately: don't leave dangling pointers.
254 wxPendingDelete
.DeleteObject(this);
256 // Just in case we've loaded a top-level window via LoadNativeDialog but
257 // we weren't a dialog class
258 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
260 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
262 // reset the dangling pointer our parent window may keep to us
265 if ( m_parent
->GetDefaultItem() == this )
267 m_parent
->SetDefaultItem(NULL
);
270 m_parent
->RemoveChild(this);
275 #endif // wxUSE_CARET
278 delete m_windowValidator
;
279 #endif // wxUSE_VALIDATORS
281 #if wxUSE_CONSTRAINTS
282 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
283 // at deleted windows as they delete themselves.
284 DeleteRelatedConstraints();
288 // This removes any dangling pointers to this window in other windows'
289 // constraintsInvolvedIn lists.
290 UnsetConstraints(m_constraints
);
291 delete m_constraints
;
292 m_constraints
= NULL
;
294 #endif // wxUSE_CONSTRAINTS
296 if ( m_containingSizer
)
297 m_containingSizer
->Detach( (wxWindow
*)this );
299 delete m_windowSizer
;
301 #if wxUSE_DRAG_AND_DROP
303 #endif // wxUSE_DRAG_AND_DROP
307 #endif // wxUSE_TOOLTIPS
309 #if wxUSE_ACCESSIBILITY
314 bool wxWindowBase::Destroy()
321 bool wxWindowBase::Close(bool force
)
323 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
324 event
.SetEventObject(this);
325 event
.SetCanVeto(!force
);
327 // return false if window wasn't closed because the application vetoed the
329 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
332 bool wxWindowBase::DestroyChildren()
334 wxWindowList::compatibility_iterator node
;
337 // we iterate until the list becomes empty
338 node
= GetChildren().GetFirst();
342 wxWindow
*child
= node
->GetData();
344 // note that we really want to call delete and not ->Destroy() here
345 // because we want to delete the child immediately, before we are
346 // deleted, and delayed deletion would result in problems as our (top
347 // level) child could outlive its parent
350 wxASSERT_MSG( !GetChildren().Find(child
),
351 wxT("child didn't remove itself using RemoveChild()") );
357 // ----------------------------------------------------------------------------
358 // size/position related methods
359 // ----------------------------------------------------------------------------
361 // centre the window with respect to its parent in either (or both) directions
362 void wxWindowBase::Centre(int direction
)
364 // the position/size of the parent window or of the entire screen
366 int widthParent
, heightParent
;
368 wxWindow
*parent
= NULL
;
370 if ( !(direction
& wxCENTRE_ON_SCREEN
) )
372 // find the parent to centre this window on: it should be the
373 // immediate parent for the controls but the top level parent for the
374 // top level windows (like dialogs)
375 parent
= GetParent();
378 while ( parent
&& !parent
->IsTopLevel() )
380 parent
= parent
->GetParent();
384 // there is no wxTopLevelWindow under wxMotif yet
386 // we shouldn't center the dialog on the iconized window: under
387 // Windows, for example, this places it completely off the screen
390 wxTopLevelWindow
*winTop
= wxDynamicCast(parent
, wxTopLevelWindow
);
391 if ( winTop
&& winTop
->IsIconized() )
396 #endif // __WXMOTIF__
398 // did we find the parent?
402 direction
|= wxCENTRE_ON_SCREEN
;
406 if ( direction
& wxCENTRE_ON_SCREEN
)
408 // centre with respect to the whole screen
409 wxDisplaySize(&widthParent
, &heightParent
);
415 // centre on the parent
416 parent
->GetSize(&widthParent
, &heightParent
);
418 // adjust to the parents position
419 posParent
= parent
->GetPosition();
423 // centre inside the parents client rectangle
424 parent
->GetClientSize(&widthParent
, &heightParent
);
429 GetSize(&width
, &height
);
434 if ( direction
& wxHORIZONTAL
)
435 xNew
= (widthParent
- width
)/2;
437 if ( direction
& wxVERTICAL
)
438 yNew
= (heightParent
- height
)/2;
443 // Base size of the visible dimensions of the display
444 // to take into account the taskbar
445 wxRect rect
= wxGetClientDisplayRect();
446 wxSize
size (rect
.width
,rect
.height
);
448 // NB: in wxMSW, negative position may not neccessary mean "out of screen",
449 // but it may mean that the window is placed on other than the main
450 // display. Therefore we only make sure centered window is on the main display
451 // if the parent is at least partially present here.
452 if (posParent
.x
+ widthParent
>= 0) // if parent is (partially) on the main display
456 else if (xNew
+width
> size
.x
)
457 xNew
= size
.x
-width
-1;
459 if (posParent
.y
+ heightParent
>= 0) // if parent is (partially) on the main display
461 if (yNew
+height
> size
.y
)
462 yNew
= size
.y
-height
-1;
464 // Make certain that the title bar is initially visible
465 // always, even if this would push the bottom of the
466 // dialog of the visible area of the display
471 // move the window to this position (keeping the old size but using
472 // SetSize() and not Move() to allow xNew and/or yNew to be -1)
473 SetSize(xNew
, yNew
, width
, height
, wxSIZE_ALLOW_MINUS_ONE
);
476 // fits the window around the children
477 void wxWindowBase::Fit()
479 if ( GetChildren().GetCount() > 0 )
481 SetClientSize(DoGetBestSize());
483 //else: do nothing if we have no children
486 // fits virtual size (ie. scrolled area etc.) around children
487 void wxWindowBase::FitInside()
489 if ( GetChildren().GetCount() > 0 )
491 SetVirtualSize( GetBestVirtualSize() );
495 // return the size best suited for the current window
496 wxSize
wxWindowBase::DoGetBestSize() const
500 return m_windowSizer
->GetMinSize();
502 #if wxUSE_CONSTRAINTS
503 else if ( m_constraints
)
505 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
507 // our minimal acceptable size is such that all our windows fit inside
511 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
513 node
= node
->GetNext() )
515 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
518 // it's not normal that we have an unconstrained child, but
519 // what can we do about it?
523 int x
= c
->right
.GetValue(),
524 y
= c
->bottom
.GetValue();
532 // TODO: we must calculate the overlaps somehow, otherwise we
533 // will never return a size bigger than the current one :-(
536 return wxSize(maxX
, maxY
);
538 #endif // wxUSE_CONSTRAINTS
539 else if ( !GetChildren().empty() )
541 // our minimal acceptable size is such that all our visible child windows fit inside
545 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
547 node
= node
->GetNext() )
549 wxWindow
*win
= node
->GetData();
550 if ( win
->IsTopLevel() || ( ! win
->IsShown() )
552 || wxDynamicCast(win
, wxStatusBar
)
553 #endif // wxUSE_STATUSBAR
556 // dialogs and frames lie in different top level windows -
557 // don't deal with them here; as for the status bars, they
558 // don't lie in the client area at all
563 win
->GetPosition(&wx
, &wy
);
565 // if the window hadn't been positioned yet, assume that it is in
572 win
->GetSize(&ww
, &wh
);
573 if ( wx
+ ww
> maxX
)
575 if ( wy
+ wh
> maxY
)
579 // for compatibility with the old versions and because it really looks
580 // slightly more pretty like this, add a pad
584 return wxSize(maxX
, maxY
);
586 else // ! has children
588 // for a generic window there is no natural best size - just use either the
589 // minimum size if there is one, or the current size
590 if ( GetMinSize().IsFullySpecified() )
597 void wxWindowBase::SetBestSize(const wxSize
& size
)
599 // the size only needs to be changed if the current size is incomplete,
600 // i.e. one of the components was specified as default -- so if both
601 // were given, simply don't do anything and in particular don't call
602 // potentially expensive DoGetBestSize()
604 if ( size
.x
== -1 || size
.y
== -1 )
606 sizeBest
= DoGetBestSize();
614 else // have explicit size
619 // don't shrink the control below its best size
620 m_minWidth
= sizeBest
.x
;
621 m_minHeight
= sizeBest
.y
;
624 // by default the origin is not shifted
625 wxPoint
wxWindowBase::GetClientAreaOrigin() const
627 return wxPoint(0, 0);
630 // set the min/max size of the window
631 void wxWindowBase::SetSizeHints(int minW
, int minH
,
633 int WXUNUSED(incW
), int WXUNUSED(incH
))
635 // setting min width greater than max width leads to infinite loops under
636 // X11 and generally doesn't make any sense, so don't allow it
637 wxCHECK_RET( (minW
== -1 || maxW
== -1 || minW
<= maxW
) &&
638 (minH
== -1 || maxH
== -1 || minH
<= maxH
),
639 _T("min width/height must be less than max width/height!") );
647 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
649 if ( m_windowVariant
!= variant
)
651 m_windowVariant
= variant
;
653 DoSetWindowVariant(variant
);
657 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
659 // adjust the font height to correspond to our new variant (notice that
660 // we're only called if something really changed)
661 wxFont font
= GetFont();
662 int size
= font
.GetPointSize();
665 case wxWINDOW_VARIANT_NORMAL
:
668 case wxWINDOW_VARIANT_SMALL
:
673 case wxWINDOW_VARIANT_MINI
:
678 case wxWINDOW_VARIANT_LARGE
:
684 wxFAIL_MSG(_T("unexpected window variant"));
688 font
.SetPointSize(size
);
692 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
695 m_minVirtualWidth
= minW
;
696 m_maxVirtualWidth
= maxW
;
697 m_minVirtualHeight
= minH
;
698 m_maxVirtualHeight
= maxH
;
701 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
703 if ( m_minVirtualWidth
!= -1 && m_minVirtualWidth
> x
)
704 x
= m_minVirtualWidth
;
705 if ( m_maxVirtualWidth
!= -1 && m_maxVirtualWidth
< x
)
706 x
= m_maxVirtualWidth
;
707 if ( m_minVirtualHeight
!= -1 && m_minVirtualHeight
> y
)
708 y
= m_minVirtualHeight
;
709 if ( m_maxVirtualHeight
!= -1 && m_maxVirtualHeight
< y
)
710 y
= m_maxVirtualHeight
;
712 m_virtualSize
= wxSize(x
, y
);
715 wxSize
wxWindowBase::DoGetVirtualSize() const
717 wxSize
s( GetClientSize() );
719 return wxSize( wxMax( m_virtualSize
.GetWidth(), s
.GetWidth() ),
720 wxMax( m_virtualSize
.GetHeight(), s
.GetHeight() ) );
723 // ----------------------------------------------------------------------------
724 // show/hide/enable/disable the window
725 // ----------------------------------------------------------------------------
727 bool wxWindowBase::Show(bool show
)
729 if ( show
!= m_isShown
)
741 bool wxWindowBase::Enable(bool enable
)
743 if ( enable
!= m_isEnabled
)
745 m_isEnabled
= enable
;
754 // ----------------------------------------------------------------------------
756 // ----------------------------------------------------------------------------
758 bool wxWindowBase::IsTopLevel() const
763 // ----------------------------------------------------------------------------
764 // reparenting the window
765 // ----------------------------------------------------------------------------
767 void wxWindowBase::AddChild(wxWindowBase
*child
)
769 wxCHECK_RET( child
, wxT("can't add a NULL child") );
771 // this should never happen and it will lead to a crash later if it does
772 // because RemoveChild() will remove only one node from the children list
773 // and the other(s) one(s) will be left with dangling pointers in them
774 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
776 GetChildren().Append((wxWindow
*)child
);
777 child
->SetParent(this);
780 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
782 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
784 GetChildren().DeleteObject((wxWindow
*)child
);
785 child
->SetParent(NULL
);
788 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
790 wxWindow
*oldParent
= GetParent();
791 if ( newParent
== oldParent
)
797 // unlink this window from the existing parent.
800 oldParent
->RemoveChild(this);
804 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
807 // add it to the new one
810 newParent
->AddChild(this);
814 wxTopLevelWindows
.Append((wxWindow
*)this);
820 // ----------------------------------------------------------------------------
821 // event handler stuff
822 // ----------------------------------------------------------------------------
824 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
826 wxEvtHandler
*handlerOld
= GetEventHandler();
828 handler
->SetNextHandler(handlerOld
);
831 GetEventHandler()->SetPreviousHandler(handler
);
833 SetEventHandler(handler
);
836 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
838 wxEvtHandler
*handlerA
= GetEventHandler();
841 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
842 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
845 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
846 SetEventHandler(handlerB
);
851 handlerA
= (wxEvtHandler
*)NULL
;
858 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
860 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
862 wxEvtHandler
*handlerPrev
= NULL
,
863 *handlerCur
= GetEventHandler();
866 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
868 if ( handlerCur
== handler
)
872 handlerPrev
->SetNextHandler(handlerNext
);
876 SetEventHandler(handlerNext
);
881 handlerNext
->SetPreviousHandler ( handlerPrev
);
884 handler
->SetNextHandler(NULL
);
885 handler
->SetPreviousHandler(NULL
);
890 handlerPrev
= handlerCur
;
891 handlerCur
= handlerNext
;
894 wxFAIL_MSG( _T("where has the event handler gone?") );
899 // ----------------------------------------------------------------------------
901 // ----------------------------------------------------------------------------
903 void wxWindowBase::InheritAttributes()
905 const wxWindowBase
* const parent
= GetParent();
909 // we only inherit attributes which had been explicitly set for the parent
910 // which ensures that this only happens if the user really wants it and
911 // not by default which wouldn't make any sense in modern GUIs where the
912 // controls don't all use the same fonts (nor colours)
913 if ( parent
->m_hasFont
&& !m_hasFont
)
914 SetFont(parent
->GetFont());
916 // in addition, there is a possibility to explicitly forbid inheriting
917 // colours at each class level by overriding ShouldInheritColours()
918 if ( ShouldInheritColours() )
920 if ( parent
->m_hasFgCol
&& !m_hasFgCol
)
921 SetForegroundColour(parent
->GetForegroundColour());
923 if ( parent
->m_hasBgCol
&& !m_hasBgCol
)
924 SetBackgroundColour(parent
->GetBackgroundColour());
928 /* static */ wxVisualAttributes
929 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
931 // it is important to return valid values for all attributes from here,
932 // GetXXX() below rely on this
933 wxVisualAttributes attrs
;
934 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
935 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
936 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
941 wxColour
wxWindowBase::GetBackgroundColour() const
943 if ( !m_backgroundColour
.Ok() )
945 wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") );
947 // get our default background colour
948 wxColour colBg
= GetDefaultAttributes().colBg
;
950 // we must return some valid colour to avoid redoing this every time
951 // and also to avoid surprizing the applications written for older
952 // wxWindows versions where GetBackgroundColour() always returned
953 // something -- so give them something even if it doesn't make sense
954 // for this window (e.g. it has a themed background)
956 colBg
= GetClassDefaultAttributes().colBg
;
958 // cache it for the next call
959 wxConstCast(this, wxWindowBase
)->m_backgroundColour
= colBg
;
962 return m_backgroundColour
;
965 wxColour
wxWindowBase::GetForegroundColour() const
967 // logic is the same as above
968 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
970 wxASSERT_MSG( !m_hasFgCol
, _T("we have invalid explicit fg colour?") );
972 wxColour colFg
= GetDefaultAttributes().colFg
;
975 colFg
= GetClassDefaultAttributes().colFg
;
977 wxConstCast(this, wxWindowBase
)->m_foregroundColour
= colFg
;
980 return m_foregroundColour
;
983 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
985 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
988 m_backgroundColour
= colour
;
995 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
997 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
1000 m_foregroundColour
= colour
;
1007 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
1009 // setting an invalid cursor is ok, it means that we don't have any special
1011 if ( m_cursor
== cursor
)
1022 wxFont
& wxWindowBase::DoGetFont() const
1024 // logic is the same as in GetBackgroundColour()
1027 wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") );
1029 wxFont font
= GetDefaultAttributes().font
;
1031 font
= GetClassDefaultAttributes().font
;
1033 wxConstCast(this, wxWindowBase
)->m_font
= font
;
1036 // cast is here for non-const GetFont() convenience
1037 return wxConstCast(this, wxWindowBase
)->m_font
;
1040 bool wxWindowBase::SetFont(const wxFont
& font
)
1045 if ( font
== m_font
)
1060 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1062 m_hasCustomPalette
= true;
1065 // VZ: can anyone explain me what do we do here?
1066 wxWindowDC
d((wxWindow
*) this);
1070 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1072 wxWindow
*win
= (wxWindow
*)this;
1073 while ( win
&& !win
->HasCustomPalette() )
1075 win
= win
->GetParent();
1081 #endif // wxUSE_PALETTE
1084 void wxWindowBase::SetCaret(wxCaret
*caret
)
1095 wxASSERT_MSG( m_caret
->GetWindow() == this,
1096 wxT("caret should be created associated to this window") );
1099 #endif // wxUSE_CARET
1101 #if wxUSE_VALIDATORS
1102 // ----------------------------------------------------------------------------
1104 // ----------------------------------------------------------------------------
1106 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1108 if ( m_windowValidator
)
1109 delete m_windowValidator
;
1111 m_windowValidator
= (wxValidator
*)validator
.Clone();
1113 if ( m_windowValidator
)
1114 m_windowValidator
->SetWindow(this);
1116 #endif // wxUSE_VALIDATORS
1118 // ----------------------------------------------------------------------------
1119 // update region stuff
1120 // ----------------------------------------------------------------------------
1122 wxRect
wxWindowBase::GetUpdateClientRect() const
1124 wxRegion rgnUpdate
= GetUpdateRegion();
1125 rgnUpdate
.Intersect(GetClientRect());
1126 wxRect rectUpdate
= rgnUpdate
.GetBox();
1127 wxPoint ptOrigin
= GetClientAreaOrigin();
1128 rectUpdate
.x
-= ptOrigin
.x
;
1129 rectUpdate
.y
-= ptOrigin
.y
;
1134 bool wxWindowBase::IsExposed(int x
, int y
) const
1136 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1139 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
1141 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1144 void wxWindowBase::ClearBackground()
1146 // wxGTK uses its own version, no need to add never used code
1148 wxClientDC
dc((wxWindow
*)this);
1149 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1150 dc
.SetBackground(brush
);
1155 // ----------------------------------------------------------------------------
1156 // find child window by id or name
1157 // ----------------------------------------------------------------------------
1159 wxWindow
*wxWindowBase::FindWindow( long id
)
1161 if ( id
== m_windowId
)
1162 return (wxWindow
*)this;
1164 wxWindowBase
*res
= (wxWindow
*)NULL
;
1165 wxWindowList::compatibility_iterator node
;
1166 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1168 wxWindowBase
*child
= node
->GetData();
1169 res
= child
->FindWindow( id
);
1172 return (wxWindow
*)res
;
1175 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
1177 if ( name
== m_windowName
)
1178 return (wxWindow
*)this;
1180 wxWindowBase
*res
= (wxWindow
*)NULL
;
1181 wxWindowList::compatibility_iterator node
;
1182 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1184 wxWindow
*child
= node
->GetData();
1185 res
= child
->FindWindow(name
);
1188 return (wxWindow
*)res
;
1192 // find any window by id or name or label: If parent is non-NULL, look through
1193 // children for a label or title matching the specified string. If NULL, look
1194 // through all top-level windows.
1196 // to avoid duplicating code we reuse the same helper function but with
1197 // different comparators
1199 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1200 const wxString
& label
, long id
);
1203 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1206 return win
->GetLabel() == label
;
1210 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1213 return win
->GetName() == label
;
1217 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1220 return win
->GetId() == id
;
1223 // recursive helper for the FindWindowByXXX() functions
1225 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1226 const wxString
& label
,
1228 wxFindWindowCmp cmp
)
1232 // see if this is the one we're looking for
1233 if ( (*cmp
)(parent
, label
, id
) )
1234 return (wxWindow
*)parent
;
1236 // It wasn't, so check all its children
1237 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1239 node
= node
->GetNext() )
1241 // recursively check each child
1242 wxWindow
*win
= (wxWindow
*)node
->GetData();
1243 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1253 // helper for FindWindowByXXX()
1255 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1256 const wxString
& label
,
1258 wxFindWindowCmp cmp
)
1262 // just check parent and all its children
1263 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1266 // start at very top of wx's windows
1267 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1269 node
= node
->GetNext() )
1271 // recursively check each window & its children
1272 wxWindow
*win
= node
->GetData();
1273 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1283 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1285 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1290 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1292 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1296 // fall back to the label
1297 win
= FindWindowByLabel(title
, parent
);
1305 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1307 return wxFindWindowHelper(parent
, _T(""), id
, wxFindWindowCmpIds
);
1310 // ----------------------------------------------------------------------------
1311 // dialog oriented functions
1312 // ----------------------------------------------------------------------------
1314 void wxWindowBase::MakeModal(bool modal
)
1316 // Disable all other windows
1319 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1322 wxWindow
*win
= node
->GetData();
1324 win
->Enable(!modal
);
1326 node
= node
->GetNext();
1331 bool wxWindowBase::Validate()
1333 #if wxUSE_VALIDATORS
1334 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1336 wxWindowList::compatibility_iterator node
;
1337 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1339 wxWindowBase
*child
= node
->GetData();
1340 wxValidator
*validator
= child
->GetValidator();
1341 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1346 if ( recurse
&& !child
->Validate() )
1351 #endif // wxUSE_VALIDATORS
1356 bool wxWindowBase::TransferDataToWindow()
1358 #if wxUSE_VALIDATORS
1359 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1361 wxWindowList::compatibility_iterator node
;
1362 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1364 wxWindowBase
*child
= node
->GetData();
1365 wxValidator
*validator
= child
->GetValidator();
1366 if ( validator
&& !validator
->TransferToWindow() )
1368 wxLogWarning(_("Could not transfer data to window"));
1370 wxLog::FlushActive();
1378 if ( !child
->TransferDataToWindow() )
1380 // warning already given
1385 #endif // wxUSE_VALIDATORS
1390 bool wxWindowBase::TransferDataFromWindow()
1392 #if wxUSE_VALIDATORS
1393 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1395 wxWindowList::compatibility_iterator node
;
1396 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1398 wxWindow
*child
= node
->GetData();
1399 wxValidator
*validator
= child
->GetValidator();
1400 if ( validator
&& !validator
->TransferFromWindow() )
1402 // nop warning here because the application is supposed to give
1403 // one itself - we don't know here what might have gone wrongly
1410 if ( !child
->TransferDataFromWindow() )
1412 // warning already given
1417 #endif // wxUSE_VALIDATORS
1422 void wxWindowBase::InitDialog()
1424 wxInitDialogEvent
event(GetId());
1425 event
.SetEventObject( this );
1426 GetEventHandler()->ProcessEvent(event
);
1429 // ----------------------------------------------------------------------------
1430 // context-sensitive help support
1431 // ----------------------------------------------------------------------------
1435 // associate this help text with this window
1436 void wxWindowBase::SetHelpText(const wxString
& text
)
1438 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1441 helpProvider
->AddHelp(this, text
);
1445 // associate this help text with all windows with the same id as this
1447 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1449 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1452 helpProvider
->AddHelp(GetId(), text
);
1456 // get the help string associated with this window (may be empty)
1457 wxString
wxWindowBase::GetHelpText() const
1460 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1463 text
= helpProvider
->GetHelp(this);
1469 // show help for this window
1470 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1472 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1475 if ( helpProvider
->ShowHelp(this) )
1477 // skip the event.Skip() below
1485 #endif // wxUSE_HELP
1487 // ----------------------------------------------------------------------------
1488 // tooltipsroot.Replace("\\", "/");
1489 // ----------------------------------------------------------------------------
1493 void wxWindowBase::SetToolTip( const wxString
&tip
)
1495 // don't create the new tooltip if we already have one
1498 m_tooltip
->SetTip( tip
);
1502 SetToolTip( new wxToolTip( tip
) );
1505 // setting empty tooltip text does not remove the tooltip any more - use
1506 // SetToolTip((wxToolTip *)NULL) for this
1509 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1514 m_tooltip
= tooltip
;
1517 #endif // wxUSE_TOOLTIPS
1519 // ----------------------------------------------------------------------------
1520 // constraints and sizers
1521 // ----------------------------------------------------------------------------
1523 #if wxUSE_CONSTRAINTS
1525 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1527 if ( m_constraints
)
1529 UnsetConstraints(m_constraints
);
1530 delete m_constraints
;
1532 m_constraints
= constraints
;
1533 if ( m_constraints
)
1535 // Make sure other windows know they're part of a 'meaningful relationship'
1536 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1537 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1538 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1539 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1540 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1541 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1542 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1543 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1544 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1545 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1546 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1547 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1548 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1549 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1550 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1551 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1555 // This removes any dangling pointers to this window in other windows'
1556 // constraintsInvolvedIn lists.
1557 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1561 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1562 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1563 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1564 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1565 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1566 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1567 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1568 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1569 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1570 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1571 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1572 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1573 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1574 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1575 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1576 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1580 // Back-pointer to other windows we're involved with, so if we delete this
1581 // window, we must delete any constraints we're involved with.
1582 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1584 if ( !m_constraintsInvolvedIn
)
1585 m_constraintsInvolvedIn
= new wxWindowList
;
1586 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1587 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1590 // REMOVE back-pointer to other windows we're involved with.
1591 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1593 if ( m_constraintsInvolvedIn
)
1594 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1597 // Reset any constraints that mention this window
1598 void wxWindowBase::DeleteRelatedConstraints()
1600 if ( m_constraintsInvolvedIn
)
1602 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1605 wxWindow
*win
= node
->GetData();
1606 wxLayoutConstraints
*constr
= win
->GetConstraints();
1608 // Reset any constraints involving this window
1611 constr
->left
.ResetIfWin(this);
1612 constr
->top
.ResetIfWin(this);
1613 constr
->right
.ResetIfWin(this);
1614 constr
->bottom
.ResetIfWin(this);
1615 constr
->width
.ResetIfWin(this);
1616 constr
->height
.ResetIfWin(this);
1617 constr
->centreX
.ResetIfWin(this);
1618 constr
->centreY
.ResetIfWin(this);
1621 wxWindowList::compatibility_iterator next
= node
->GetNext();
1622 m_constraintsInvolvedIn
->Erase(node
);
1626 delete m_constraintsInvolvedIn
;
1627 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1631 #endif // wxUSE_CONSTRAINTS
1633 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1635 if ( sizer
== m_windowSizer
)
1639 delete m_windowSizer
;
1641 m_windowSizer
= sizer
;
1643 SetAutoLayout( sizer
!= NULL
);
1646 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1648 SetSizer( sizer
, deleteOld
);
1649 sizer
->SetSizeHints( (wxWindow
*) this );
1653 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
1655 // adding a window to a sizer twice is going to result in fatal and
1656 // hard to debug problems later because when deleting the second
1657 // associated wxSizerItem we're going to dereference a dangling
1658 // pointer; so try to detect this as early as possible
1659 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
1660 _T("Adding a window to the same sizer twice?") );
1662 m_containingSizer
= sizer
;
1665 #if wxUSE_CONSTRAINTS
1667 void wxWindowBase::SatisfyConstraints()
1669 wxLayoutConstraints
*constr
= GetConstraints();
1670 bool wasOk
= constr
&& constr
->AreSatisfied();
1672 ResetConstraints(); // Mark all constraints as unevaluated
1676 // if we're a top level panel (i.e. our parent is frame/dialog), our
1677 // own constraints will never be satisfied any more unless we do it
1681 while ( noChanges
> 0 )
1683 LayoutPhase1(&noChanges
);
1687 LayoutPhase2(&noChanges
);
1690 #endif // wxUSE_CONSTRAINTS
1692 bool wxWindowBase::Layout()
1694 // If there is a sizer, use it instead of the constraints
1698 GetVirtualSize(&w
, &h
);
1699 GetSizer()->SetDimension( 0, 0, w
, h
);
1701 #if wxUSE_CONSTRAINTS
1704 SatisfyConstraints(); // Find the right constraints values
1705 SetConstraintSizes(); // Recursively set the real window sizes
1712 #if wxUSE_CONSTRAINTS
1714 // first phase of the constraints evaluation: set our own constraints
1715 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1717 wxLayoutConstraints
*constr
= GetConstraints();
1719 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1722 // second phase: set the constraints for our children
1723 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1730 // Layout grand children
1736 // Do a phase of evaluating child constraints
1737 bool wxWindowBase::DoPhase(int phase
)
1739 // the list containing the children for which the constraints are already
1741 wxWindowList succeeded
;
1743 // the max number of iterations we loop before concluding that we can't set
1745 static const int maxIterations
= 500;
1747 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1751 // loop over all children setting their constraints
1752 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1754 node
= node
->GetNext() )
1756 wxWindow
*child
= node
->GetData();
1757 if ( child
->IsTopLevel() )
1759 // top level children are not inside our client area
1763 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1765 // this one is either already ok or nothing we can do about it
1769 int tempNoChanges
= 0;
1770 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1771 : child
->LayoutPhase2(&tempNoChanges
);
1772 noChanges
+= tempNoChanges
;
1776 succeeded
.Append(child
);
1782 // constraints are set
1790 void wxWindowBase::ResetConstraints()
1792 wxLayoutConstraints
*constr
= GetConstraints();
1795 constr
->left
.SetDone(false);
1796 constr
->top
.SetDone(false);
1797 constr
->right
.SetDone(false);
1798 constr
->bottom
.SetDone(false);
1799 constr
->width
.SetDone(false);
1800 constr
->height
.SetDone(false);
1801 constr
->centreX
.SetDone(false);
1802 constr
->centreY
.SetDone(false);
1805 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1808 wxWindow
*win
= node
->GetData();
1809 if ( !win
->IsTopLevel() )
1810 win
->ResetConstraints();
1811 node
= node
->GetNext();
1815 // Need to distinguish between setting the 'fake' size for windows and sizers,
1816 // and setting the real values.
1817 void wxWindowBase::SetConstraintSizes(bool recurse
)
1819 wxLayoutConstraints
*constr
= GetConstraints();
1820 if ( constr
&& constr
->AreSatisfied() )
1822 int x
= constr
->left
.GetValue();
1823 int y
= constr
->top
.GetValue();
1824 int w
= constr
->width
.GetValue();
1825 int h
= constr
->height
.GetValue();
1827 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1828 (constr
->height
.GetRelationship() != wxAsIs
) )
1830 SetSize(x
, y
, w
, h
);
1834 // If we don't want to resize this window, just move it...
1840 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1841 GetClassInfo()->GetClassName(),
1847 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1850 wxWindow
*win
= node
->GetData();
1851 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1852 win
->SetConstraintSizes();
1853 node
= node
->GetNext();
1858 // Only set the size/position of the constraint (if any)
1859 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1861 wxLayoutConstraints
*constr
= GetConstraints();
1866 constr
->left
.SetValue(x
);
1867 constr
->left
.SetDone(true);
1871 constr
->top
.SetValue(y
);
1872 constr
->top
.SetDone(true);
1876 constr
->width
.SetValue(w
);
1877 constr
->width
.SetDone(true);
1881 constr
->height
.SetValue(h
);
1882 constr
->height
.SetDone(true);
1887 void wxWindowBase::MoveConstraint(int x
, int y
)
1889 wxLayoutConstraints
*constr
= GetConstraints();
1894 constr
->left
.SetValue(x
);
1895 constr
->left
.SetDone(true);
1899 constr
->top
.SetValue(y
);
1900 constr
->top
.SetDone(true);
1905 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1907 wxLayoutConstraints
*constr
= GetConstraints();
1910 *w
= constr
->width
.GetValue();
1911 *h
= constr
->height
.GetValue();
1917 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1919 wxLayoutConstraints
*constr
= GetConstraints();
1922 *w
= constr
->width
.GetValue();
1923 *h
= constr
->height
.GetValue();
1926 GetClientSize(w
, h
);
1929 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1931 wxLayoutConstraints
*constr
= GetConstraints();
1934 *x
= constr
->left
.GetValue();
1935 *y
= constr
->top
.GetValue();
1941 #endif // wxUSE_CONSTRAINTS
1943 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
1945 // don't do it for the dialogs/frames - they float independently of their
1947 if ( !IsTopLevel() )
1949 wxWindow
*parent
= GetParent();
1950 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
1952 wxPoint
pt(parent
->GetClientAreaOrigin());
1959 // ----------------------------------------------------------------------------
1960 // do Update UI processing for child controls
1961 // ----------------------------------------------------------------------------
1963 void wxWindowBase::UpdateWindowUI(long flags
)
1965 wxUpdateUIEvent
event(GetId());
1966 event
.m_eventObject
= this;
1968 if ( GetEventHandler()->ProcessEvent(event
) )
1970 DoUpdateWindowUI(event
);
1973 if (flags
& wxUPDATE_UI_RECURSE
)
1975 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1978 wxWindow
* child
= (wxWindow
*) node
->GetData();
1979 child
->UpdateWindowUI(flags
);
1980 node
= node
->GetNext();
1985 // do the window-specific processing after processing the update event
1986 // TODO: take specific knowledge out of this function and
1987 // put in each control's base class. Unfortunately we don't
1988 // yet have base implementation files for wxCheckBox and wxRadioButton.
1989 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
1991 if ( event
.GetSetEnabled() )
1992 Enable(event
.GetEnabled());
1995 if ( event
.GetSetText() )
1997 wxControl
*control
= wxDynamicCastThis(wxControl
);
2000 if ( event
.GetText() != control
->GetLabel() )
2001 control
->SetLabel(event
.GetText());
2004 wxCheckBox
*checkbox
= wxDynamicCastThis(wxCheckBox
);
2007 if ( event
.GetSetChecked() )
2008 checkbox
->SetValue(event
.GetChecked());
2010 #endif // wxUSE_CHECKBOX
2013 wxRadioButton
*radiobtn
= wxDynamicCastThis(wxRadioButton
);
2016 if ( event
.GetSetChecked() )
2017 radiobtn
->SetValue(event
.GetChecked());
2019 #endif // wxUSE_RADIOBTN
2025 // call internal idle recursively
2026 // may be obsolete (wait until OnIdle scheme stabilises)
2027 void wxWindowBase::ProcessInternalIdle()
2031 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2034 wxWindow
*child
= node
->GetData();
2035 child
->ProcessInternalIdle();
2036 node
= node
->GetNext();
2041 // ----------------------------------------------------------------------------
2042 // dialog units translations
2043 // ----------------------------------------------------------------------------
2045 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
2047 int charWidth
= GetCharWidth();
2048 int charHeight
= GetCharHeight();
2049 wxPoint
pt2(-1, -1);
2051 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
2053 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2058 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
2060 int charWidth
= GetCharWidth();
2061 int charHeight
= GetCharHeight();
2062 wxPoint
pt2(-1, -1);
2064 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
2066 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2071 // ----------------------------------------------------------------------------
2073 // ----------------------------------------------------------------------------
2075 // propagate the colour change event to the subwindows
2076 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2078 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2081 // Only propagate to non-top-level windows
2082 wxWindow
*win
= node
->GetData();
2083 if ( !win
->IsTopLevel() )
2085 wxSysColourChangedEvent event2
;
2086 event
.m_eventObject
= win
;
2087 win
->GetEventHandler()->ProcessEvent(event2
);
2090 node
= node
->GetNext();
2094 // the default action is to populate dialog with data when it's created,
2095 // and nudge the UI into displaying itself correctly in case
2096 // we've turned the wxUpdateUIEvents frequency down low.
2097 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2099 TransferDataToWindow();
2101 // Update the UI at this point
2102 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2105 // process Ctrl-Alt-mclick
2106 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2109 if ( event
.ControlDown() && event
.AltDown() )
2111 // don't translate these strings
2114 #ifdef __WXUNIVERSAL__
2116 #endif // __WXUNIVERSAL__
2118 switch ( wxGetOsVersion() )
2120 case wxMOTIF_X
: port
+= _T("Motif"); break;
2122 case wxMAC_DARWIN
: port
+= _T("Mac"); break;
2123 case wxBEOS
: port
+= _T("BeOS"); break;
2127 case wxGTK_BEOS
: port
+= _T("GTK"); break;
2133 case wxWIN386
: port
+= _T("MS Windows"); break;
2137 case wxMGL_OS2
: port
+= _T("MGL"); break;
2139 case wxOS2_PM
: port
+= _T("OS/2"); break;
2140 default: port
+= _T("unknown"); break;
2143 wxMessageBox(wxString::Format(
2145 " wxWindows Library (%s port)\nVersion %u.%u.%u%s, compiled at %s %s\n Copyright (c) 1995-2002 wxWindows team"
2159 _T("wxWindows information"),
2160 wxICON_INFORMATION
| wxOK
,
2164 #endif // wxUSE_MSGDLG
2170 // ----------------------------------------------------------------------------
2172 // ----------------------------------------------------------------------------
2174 #if wxUSE_ACCESSIBILITY
2175 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2177 if (m_accessible
&& (accessible
!= m_accessible
))
2178 delete m_accessible
;
2179 m_accessible
= accessible
;
2181 m_accessible
->SetWindow((wxWindow
*) this);
2184 // Returns the accessible object, creating if necessary.
2185 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2188 m_accessible
= CreateAccessible();
2189 return m_accessible
;
2192 // Override to create a specific accessible object.
2193 wxAccessible
* wxWindowBase::CreateAccessible()
2195 return new wxWindowAccessible((wxWindow
*) this);
2201 // ----------------------------------------------------------------------------
2202 // list classes implementation
2203 // ----------------------------------------------------------------------------
2205 void wxWindowListNode::DeleteData()
2207 delete (wxWindow
*)GetData();
2211 // ----------------------------------------------------------------------------
2213 // ----------------------------------------------------------------------------
2215 wxBorder
wxWindowBase::GetBorder(long flags
) const
2217 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2218 if ( border
== wxBORDER_DEFAULT
)
2220 border
= GetDefaultBorder();
2226 wxBorder
wxWindowBase::GetDefaultBorder() const
2228 return wxBORDER_NONE
;
2231 // ----------------------------------------------------------------------------
2233 // ----------------------------------------------------------------------------
2235 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2237 // here we just check if the point is inside the window or not
2239 // check the top and left border first
2240 bool outside
= x
< 0 || y
< 0;
2243 // check the right and bottom borders too
2244 wxSize size
= GetSize();
2245 outside
= x
>= size
.x
|| y
>= size
.y
;
2248 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2251 // ----------------------------------------------------------------------------
2253 // ----------------------------------------------------------------------------
2255 struct WXDLLEXPORT wxWindowNext
2259 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2261 void wxWindowBase::CaptureMouse()
2263 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this);
2265 wxWindow
*winOld
= GetCapture();
2268 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2271 wxWindowNext
*item
= new wxWindowNext
;
2273 item
->next
= ms_winCaptureNext
;
2274 ms_winCaptureNext
= item
;
2276 //else: no mouse capture to save
2281 void wxWindowBase::ReleaseMouse()
2283 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this);
2285 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2289 if ( ms_winCaptureNext
)
2291 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2293 wxWindowNext
*item
= ms_winCaptureNext
;
2294 ms_winCaptureNext
= item
->next
;
2297 //else: stack is empty, no previous capture
2299 wxLogTrace(_T("mousecapture"),
2300 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2307 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2308 int WXUNUSED(modifiers
),
2309 int WXUNUSED(keycode
))
2315 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2321 #endif // wxUSE_HOTKEY
2323 void wxWindowBase::SendDestroyEvent()
2325 wxWindowDestroyEvent event
;
2326 event
.SetEventObject(this);
2327 event
.SetId(GetId());
2328 GetEventHandler()->ProcessEvent(event
);
2331 // ----------------------------------------------------------------------------
2333 // ----------------------------------------------------------------------------
2335 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2337 #if wxUSE_VALIDATORS
2338 // Can only use the validator of the window which
2339 // is receiving the event
2340 if ( event
.GetEventObject() == this )
2342 wxValidator
*validator
= GetValidator();
2343 if ( validator
&& validator
->ProcessEvent(event
) )
2348 #endif // wxUSE_VALIDATORS
2353 bool wxWindowBase::TryParent(wxEvent
& event
)
2355 // carry on up the parent-child hierarchy if the propgation count hasn't
2357 if ( event
.ShouldPropagate() )
2359 // honour the requests to stop propagation at this window: this is
2360 // used by the dialogs, for example, to prevent processing the events
2361 // from the dialog controls in the parent frame which rarely, if ever,
2363 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2365 wxWindow
*parent
= GetParent();
2366 if ( parent
&& !parent
->IsBeingDeleted() )
2368 wxPropagateOnce
propagateOnce(event
);
2370 return parent
->GetEventHandler()->ProcessEvent(event
);
2375 return wxEvtHandler::TryParent(event
);
2378 // ----------------------------------------------------------------------------
2380 // ----------------------------------------------------------------------------
2382 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2384 while ( win
&& !win
->IsTopLevel() )
2385 win
= win
->GetParent();
2390 #if wxUSE_ACCESSIBILITY
2391 // ----------------------------------------------------------------------------
2392 // accessible object for windows
2393 // ----------------------------------------------------------------------------
2395 // Can return either a child object, or an integer
2396 // representing the child element, starting from 1.
2397 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2399 wxASSERT( GetWindow() != NULL
);
2403 return wxACC_NOT_IMPLEMENTED
;
2406 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2407 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2409 wxASSERT( GetWindow() != NULL
);
2413 wxWindow
* win
= NULL
;
2420 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2422 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2429 rect
= win
->GetRect();
2430 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2431 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2435 return wxACC_NOT_IMPLEMENTED
;
2438 // Navigates from fromId to toId/toObject.
2439 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2440 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2442 wxASSERT( GetWindow() != NULL
);
2448 case wxNAVDIR_FIRSTCHILD
:
2450 if (GetWindow()->GetChildren().GetCount() == 0)
2452 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2453 *toObject
= childWindow
->GetOrCreateAccessible();
2457 case wxNAVDIR_LASTCHILD
:
2459 if (GetWindow()->GetChildren().GetCount() == 0)
2461 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2462 *toObject
= childWindow
->GetOrCreateAccessible();
2466 case wxNAVDIR_RIGHT
:
2470 wxWindowList::compatibility_iterator node
=
2471 wxWindowList::compatibility_iterator();
2474 // Can't navigate to sibling of this window
2475 // if we're a top-level window.
2476 if (!GetWindow()->GetParent())
2477 return wxACC_NOT_IMPLEMENTED
;
2479 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2483 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2484 node
= GetWindow()->GetChildren().Item(fromId
-1);
2487 if (node
&& node
->GetNext())
2489 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2490 *toObject
= nextWindow
->GetOrCreateAccessible();
2498 case wxNAVDIR_PREVIOUS
:
2500 wxWindowList::compatibility_iterator node
=
2501 wxWindowList::compatibility_iterator();
2504 // Can't navigate to sibling of this window
2505 // if we're a top-level window.
2506 if (!GetWindow()->GetParent())
2507 return wxACC_NOT_IMPLEMENTED
;
2509 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2513 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2514 node
= GetWindow()->GetChildren().Item(fromId
-1);
2517 if (node
&& node
->GetPrevious())
2519 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2520 *toObject
= previousWindow
->GetOrCreateAccessible();
2528 return wxACC_NOT_IMPLEMENTED
;
2531 // Gets the name of the specified object.
2532 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2534 wxASSERT( GetWindow() != NULL
);
2540 // If a child, leave wxWindows to call the function on the actual
2543 return wxACC_NOT_IMPLEMENTED
;
2545 // This will eventually be replaced by specialised
2546 // accessible classes, one for each kind of wxWindows
2547 // control or window.
2548 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2549 title
= ((wxButton
*) GetWindow())->GetLabel();
2551 title
= GetWindow()->GetName();
2553 if (!title
.IsEmpty())
2559 return wxACC_NOT_IMPLEMENTED
;
2562 // Gets the number of children.
2563 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2565 wxASSERT( GetWindow() != NULL
);
2569 *childId
= (int) GetWindow()->GetChildren().GetCount();
2573 // Gets the specified child (starting from 1).
2574 // If *child is NULL and return value is wxACC_OK,
2575 // this means that the child is a simple element and
2576 // not an accessible object.
2577 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2579 wxASSERT( GetWindow() != NULL
);
2589 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2592 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2593 *child
= childWindow
->GetOrCreateAccessible();
2600 // Gets the parent, or NULL.
2601 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2603 wxASSERT( GetWindow() != NULL
);
2607 wxWindow
* parentWindow
= GetWindow()->GetParent();
2615 *parent
= parentWindow
->GetOrCreateAccessible();
2623 // Performs the default action. childId is 0 (the action for this object)
2624 // or > 0 (the action for a child).
2625 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2626 // window (e.g. an edit control).
2627 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
2629 wxASSERT( GetWindow() != NULL
);
2633 return wxACC_NOT_IMPLEMENTED
;
2636 // Gets the default action for this object (0) or > 0 (the action for a child).
2637 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2638 // string if there is no action.
2639 // The retrieved string describes the action that is performed on an object,
2640 // not what the object does as a result. For example, a toolbar button that prints
2641 // a document has a default action of "Press" rather than "Prints the current document."
2642 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
2644 wxASSERT( GetWindow() != NULL
);
2648 return wxACC_NOT_IMPLEMENTED
;
2651 // Returns the description for this object or a child.
2652 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
2654 wxASSERT( GetWindow() != NULL
);
2658 wxString
ht(GetWindow()->GetHelpText());
2664 return wxACC_NOT_IMPLEMENTED
;
2667 // Returns help text for this object or a child, similar to tooltip text.
2668 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
2670 wxASSERT( GetWindow() != NULL
);
2674 wxString
ht(GetWindow()->GetHelpText());
2680 return wxACC_NOT_IMPLEMENTED
;
2683 // Returns the keyboard shortcut for this object or child.
2684 // Return e.g. ALT+K
2685 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
2687 wxASSERT( GetWindow() != NULL
);
2691 return wxACC_NOT_IMPLEMENTED
;
2694 // Returns a role constant.
2695 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
2697 wxASSERT( GetWindow() != NULL
);
2701 // If a child, leave wxWindows to call the function on the actual
2704 return wxACC_NOT_IMPLEMENTED
;
2706 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2707 return wxACC_NOT_IMPLEMENTED
;
2709 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2710 return wxACC_NOT_IMPLEMENTED
;
2713 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2714 return wxACC_NOT_IMPLEMENTED
;
2717 //*role = wxROLE_SYSTEM_CLIENT;
2718 *role
= wxROLE_SYSTEM_CLIENT
;
2722 return wxACC_NOT_IMPLEMENTED
;
2726 // Returns a state constant.
2727 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
2729 wxASSERT( GetWindow() != NULL
);
2733 // If a child, leave wxWindows to call the function on the actual
2736 return wxACC_NOT_IMPLEMENTED
;
2738 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2739 return wxACC_NOT_IMPLEMENTED
;
2742 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2743 return wxACC_NOT_IMPLEMENTED
;
2746 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2747 return wxACC_NOT_IMPLEMENTED
;
2754 return wxACC_NOT_IMPLEMENTED
;
2758 // Returns a localized string representing the value for the object
2760 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
2762 wxASSERT( GetWindow() != NULL
);
2766 return wxACC_NOT_IMPLEMENTED
;
2769 // Selects the object or child.
2770 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
2772 wxASSERT( GetWindow() != NULL
);
2776 return wxACC_NOT_IMPLEMENTED
;
2779 // Gets the window with the keyboard focus.
2780 // If childId is 0 and child is NULL, no object in
2781 // this subhierarchy has the focus.
2782 // If this object has the focus, child should be 'this'.
2783 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
2785 wxASSERT( GetWindow() != NULL
);
2789 return wxACC_NOT_IMPLEMENTED
;
2792 // Gets a variant representing the selected children
2794 // Acceptable values:
2795 // - a null variant (IsNull() returns TRUE)
2796 // - a list variant (GetType() == wxT("list")
2797 // - an integer representing the selected child element,
2798 // or 0 if this object is selected (GetType() == wxT("long")
2799 // - a "void*" pointer to a wxAccessible child object
2800 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
2802 wxASSERT( GetWindow() != NULL
);
2806 return wxACC_NOT_IMPLEMENTED
;
2809 #endif // wxUSE_ACCESSIBILITY