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"
50 #if defined(__WXMAC__) && wxUSE_SCROLLBAR
51 #include "wx/scrolbar.h"
55 #include "wx/layout.h"
56 #endif // wxUSE_CONSTRAINTS
60 #if wxUSE_DRAG_AND_DROP
62 #endif // wxUSE_DRAG_AND_DROP
64 #if wxUSE_ACCESSIBILITY
65 #include "wx/access.h"
69 #include "wx/cshelp.h"
73 #include "wx/tooltip.h"
74 #endif // wxUSE_TOOLTIPS
80 // ----------------------------------------------------------------------------
82 // ----------------------------------------------------------------------------
85 int wxWindowBase::ms_lastControlId
= 2000;
87 int wxWindowBase::ms_lastControlId
= -200;
90 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
92 // ----------------------------------------------------------------------------
94 // ----------------------------------------------------------------------------
96 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
97 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
98 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
99 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick
)
102 EVT_HELP(wxID_ANY
, wxWindowBase::OnHelp
)
107 // ============================================================================
108 // implementation of the common functionality of the wxWindow class
109 // ============================================================================
111 // ----------------------------------------------------------------------------
113 // ----------------------------------------------------------------------------
115 // the default initialization
116 wxWindowBase::wxWindowBase()
118 // no window yet, no parent nor children
119 m_parent
= (wxWindow
*)NULL
;
120 m_windowId
= wxID_ANY
;
122 // no constraints on the minimal window size
128 // window are created enabled and visible by default
132 // the default event handler is just this window
133 m_eventHandler
= this;
137 m_windowValidator
= (wxValidator
*) NULL
;
138 #endif // wxUSE_VALIDATORS
140 // the colours/fonts are default for now, so leave m_font,
141 // m_backgroundColour and m_foregroundColour uninitialized and set those
150 #if wxUSE_CONSTRAINTS
151 // no constraints whatsoever
152 m_constraints
= (wxLayoutConstraints
*) NULL
;
153 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
154 #endif // wxUSE_CONSTRAINTS
156 m_windowSizer
= (wxSizer
*) NULL
;
157 m_containingSizer
= (wxSizer
*) NULL
;
158 m_autoLayout
= false;
160 #if wxUSE_DRAG_AND_DROP
161 m_dropTarget
= (wxDropTarget
*)NULL
;
162 #endif // wxUSE_DRAG_AND_DROP
165 m_tooltip
= (wxToolTip
*)NULL
;
166 #endif // wxUSE_TOOLTIPS
169 m_caret
= (wxCaret
*)NULL
;
170 #endif // wxUSE_CARET
173 m_hasCustomPalette
= false;
174 #endif // wxUSE_PALETTE
176 #if wxUSE_ACCESSIBILITY
180 m_virtualSize
= wxDefaultSize
;
185 m_maxVirtualHeight
= -1;
187 m_windowVariant
= wxWINDOW_VARIANT_NORMAL
;
189 // Whether we're using the current theme for this window (wxGTK only for now)
190 m_themeEnabled
= false;
192 // VZ: this one shouldn't exist...
193 m_isBeingDeleted
= false;
196 // common part of window creation process
197 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
199 const wxPoint
& WXUNUSED(pos
),
200 const wxSize
& WXUNUSED(size
),
202 const wxValidator
& wxVALIDATOR_PARAM(validator
),
203 const wxString
& name
)
206 // wxGTK doesn't allow to create controls with static box as the parent so
207 // this will result in a crash when the program is ported to wxGTK so warn
210 // if you get this assert, the correct solution is to create the controls
211 // as siblings of the static box
212 wxASSERT_MSG( !parent
|| !wxDynamicCast(parent
, wxStaticBox
),
213 _T("wxStaticBox can't be used as a window parent!") );
214 #endif // wxUSE_STATBOX
216 // ids are limited to 16 bits under MSW so if you care about portability,
217 // it's not a good idea to use ids out of this range (and negative ids are
218 // reserved for wxWindows own usage)
219 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767),
220 _T("invalid id value") );
222 // generate a new id if the user doesn't care about it
223 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
226 SetWindowStyleFlag(style
);
230 SetValidator(validator
);
231 #endif // wxUSE_VALIDATORS
233 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
234 // have it too - like this it's possible to set it only in the top level
235 // dialog/frame and all children will inherit it by defult
236 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
238 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
244 // ----------------------------------------------------------------------------
246 // ----------------------------------------------------------------------------
249 wxWindowBase::~wxWindowBase()
251 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
253 // FIXME if these 2 cases result from programming errors in the user code
254 // we should probably assert here instead of silently fixing them
256 // Just in case the window has been Closed, but we're then deleting
257 // immediately: don't leave dangling pointers.
258 wxPendingDelete
.DeleteObject(this);
260 // Just in case we've loaded a top-level window via LoadNativeDialog but
261 // we weren't a dialog class
262 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
264 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
266 // reset the dangling pointer our parent window may keep to us
269 if ( m_parent
->GetDefaultItem() == this )
271 m_parent
->SetDefaultItem(NULL
);
274 m_parent
->RemoveChild(this);
279 #endif // wxUSE_CARET
282 delete m_windowValidator
;
283 #endif // wxUSE_VALIDATORS
285 #if wxUSE_CONSTRAINTS
286 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
287 // at deleted windows as they delete themselves.
288 DeleteRelatedConstraints();
292 // This removes any dangling pointers to this window in other windows'
293 // constraintsInvolvedIn lists.
294 UnsetConstraints(m_constraints
);
295 delete m_constraints
;
296 m_constraints
= NULL
;
298 #endif // wxUSE_CONSTRAINTS
300 if ( m_containingSizer
)
301 m_containingSizer
->Detach( (wxWindow
*)this );
303 delete m_windowSizer
;
305 #if wxUSE_DRAG_AND_DROP
307 #endif // wxUSE_DRAG_AND_DROP
311 #endif // wxUSE_TOOLTIPS
313 #if wxUSE_ACCESSIBILITY
318 bool wxWindowBase::Destroy()
325 bool wxWindowBase::Close(bool force
)
327 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
328 event
.SetEventObject(this);
329 event
.SetCanVeto(!force
);
331 // return false if window wasn't closed because the application vetoed the
333 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
336 bool wxWindowBase::DestroyChildren()
338 wxWindowList::compatibility_iterator node
;
341 // we iterate until the list becomes empty
342 node
= GetChildren().GetFirst();
346 wxWindow
*child
= node
->GetData();
348 // note that we really want to call delete and not ->Destroy() here
349 // because we want to delete the child immediately, before we are
350 // deleted, and delayed deletion would result in problems as our (top
351 // level) child could outlive its parent
354 wxASSERT_MSG( !GetChildren().Find(child
),
355 wxT("child didn't remove itself using RemoveChild()") );
361 // ----------------------------------------------------------------------------
362 // size/position related methods
363 // ----------------------------------------------------------------------------
365 // centre the window with respect to its parent in either (or both) directions
366 void wxWindowBase::Centre(int direction
)
368 // the position/size of the parent window or of the entire screen
370 int widthParent
, heightParent
;
372 wxWindow
*parent
= NULL
;
374 if ( !(direction
& wxCENTRE_ON_SCREEN
) )
376 // find the parent to centre this window on: it should be the
377 // immediate parent for the controls but the top level parent for the
378 // top level windows (like dialogs)
379 parent
= GetParent();
382 while ( parent
&& !parent
->IsTopLevel() )
384 parent
= parent
->GetParent();
388 // there is no wxTopLevelWindow under wxMotif yet
390 // we shouldn't center the dialog on the iconized window: under
391 // Windows, for example, this places it completely off the screen
394 wxTopLevelWindow
*winTop
= wxDynamicCast(parent
, wxTopLevelWindow
);
395 if ( winTop
&& winTop
->IsIconized() )
400 #endif // __WXMOTIF__
402 // did we find the parent?
406 direction
|= wxCENTRE_ON_SCREEN
;
410 if ( direction
& wxCENTRE_ON_SCREEN
)
412 // centre with respect to the whole screen
413 wxDisplaySize(&widthParent
, &heightParent
);
419 // centre on the parent
420 parent
->GetSize(&widthParent
, &heightParent
);
422 // adjust to the parents position
423 posParent
= parent
->GetPosition();
427 // centre inside the parents client rectangle
428 parent
->GetClientSize(&widthParent
, &heightParent
);
433 GetSize(&width
, &height
);
438 if ( direction
& wxHORIZONTAL
)
439 xNew
= (widthParent
- width
)/2;
441 if ( direction
& wxVERTICAL
)
442 yNew
= (heightParent
- height
)/2;
447 // Base size of the visible dimensions of the display
448 // to take into account the taskbar
449 wxRect rect
= wxGetClientDisplayRect();
450 wxSize
size (rect
.width
,rect
.height
);
452 // NB: in wxMSW, negative position may not neccessary mean "out of screen",
453 // but it may mean that the window is placed on other than the main
454 // display. Therefore we only make sure centered window is on the main display
455 // if the parent is at least partially present here.
456 if (posParent
.x
+ widthParent
>= 0) // if parent is (partially) on the main display
460 else if (xNew
+width
> size
.x
)
461 xNew
= size
.x
-width
-1;
463 if (posParent
.y
+ heightParent
>= 0) // if parent is (partially) on the main display
465 if (yNew
+height
> size
.y
)
466 yNew
= size
.y
-height
-1;
468 // Make certain that the title bar is initially visible
469 // always, even if this would push the bottom of the
470 // dialog of the visible area of the display
475 // move the window to this position (keeping the old size but using
476 // SetSize() and not Move() to allow xNew and/or yNew to be -1)
477 SetSize(xNew
, yNew
, width
, height
, wxSIZE_ALLOW_MINUS_ONE
);
480 // fits the window around the children
481 void wxWindowBase::Fit()
483 if ( GetChildren().GetCount() > 0 )
485 SetClientSize(DoGetBestSize());
487 //else: do nothing if we have no children
490 // fits virtual size (ie. scrolled area etc.) around children
491 void wxWindowBase::FitInside()
493 if ( GetChildren().GetCount() > 0 )
495 SetVirtualSize( GetBestVirtualSize() );
499 // On Mac, scrollbars are explicitly children.
501 static bool wxHasRealChildren(const wxWindowBase
* win
)
503 int realChildCount
= 0;
505 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
507 node
= node
->GetNext() )
509 wxWindow
*win
= node
->GetData();
510 if ( !win
->IsTopLevel() && win
->IsShown() && !win
->IsKindOf(CLASSINFO(wxScrollBar
)))
513 return (realChildCount
> 0);
517 // return the size best suited for the current window
518 wxSize
wxWindowBase::DoGetBestSize() const
522 return m_windowSizer
->GetMinSize();
524 #if wxUSE_CONSTRAINTS
525 else if ( m_constraints
)
527 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
529 // our minimal acceptable size is such that all our windows fit inside
533 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
535 node
= node
->GetNext() )
537 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
540 // it's not normal that we have an unconstrained child, but
541 // what can we do about it?
545 int x
= c
->right
.GetValue(),
546 y
= c
->bottom
.GetValue();
554 // TODO: we must calculate the overlaps somehow, otherwise we
555 // will never return a size bigger than the current one :-(
558 return wxSize(maxX
, maxY
);
560 #endif // wxUSE_CONSTRAINTS
561 else if ( !GetChildren().empty()
563 && wxHasRealChildren(this)
567 // our minimal acceptable size is such that all our visible child windows fit inside
571 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
573 node
= node
->GetNext() )
575 wxWindow
*win
= node
->GetData();
576 if ( win
->IsTopLevel() || ( ! win
->IsShown() )
578 || wxDynamicCast(win
, wxStatusBar
)
579 #endif // wxUSE_STATUSBAR
582 // dialogs and frames lie in different top level windows -
583 // don't deal with them here; as for the status bars, they
584 // don't lie in the client area at all
589 win
->GetPosition(&wx
, &wy
);
591 // if the window hadn't been positioned yet, assume that it is in
598 win
->GetSize(&ww
, &wh
);
599 if ( wx
+ ww
> maxX
)
601 if ( wy
+ wh
> maxY
)
605 // for compatibility with the old versions and because it really looks
606 // slightly more pretty like this, add a pad
610 return wxSize(maxX
, maxY
);
612 else // ! has children
614 // for a generic window there is no natural best size - just use either the
615 // minimum size if there is one, or the current size
616 if ( GetMinSize().IsFullySpecified() )
623 void wxWindowBase::SetBestSize(const wxSize
& size
)
625 // the size only needs to be changed if the current size is incomplete,
626 // i.e. one of the components was specified as default -- so if both
627 // were given, simply don't do anything and in particular don't call
628 // potentially expensive DoGetBestSize()
630 if ( size
.x
== -1 || size
.y
== -1 )
632 sizeBest
= DoGetBestSize();
640 else // have explicit size
645 // don't shrink the control below its best size
646 m_minWidth
= sizeBest
.x
;
647 m_minHeight
= sizeBest
.y
;
650 // by default the origin is not shifted
651 wxPoint
wxWindowBase::GetClientAreaOrigin() const
653 return wxPoint(0, 0);
656 // set the min/max size of the window
657 void wxWindowBase::SetSizeHints(int minW
, int minH
,
659 int WXUNUSED(incW
), int WXUNUSED(incH
))
661 // setting min width greater than max width leads to infinite loops under
662 // X11 and generally doesn't make any sense, so don't allow it
663 wxCHECK_RET( (minW
== -1 || maxW
== -1 || minW
<= maxW
) &&
664 (minH
== -1 || maxH
== -1 || minH
<= maxH
),
665 _T("min width/height must be less than max width/height!") );
673 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
675 if ( m_windowVariant
!= variant
)
677 m_windowVariant
= variant
;
679 DoSetWindowVariant(variant
);
683 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
685 // adjust the font height to correspond to our new variant (notice that
686 // we're only called if something really changed)
687 wxFont font
= GetFont();
688 int size
= font
.GetPointSize();
691 case wxWINDOW_VARIANT_NORMAL
:
694 case wxWINDOW_VARIANT_SMALL
:
699 case wxWINDOW_VARIANT_MINI
:
704 case wxWINDOW_VARIANT_LARGE
:
710 wxFAIL_MSG(_T("unexpected window variant"));
714 font
.SetPointSize(size
);
718 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
721 m_minVirtualWidth
= minW
;
722 m_maxVirtualWidth
= maxW
;
723 m_minVirtualHeight
= minH
;
724 m_maxVirtualHeight
= maxH
;
727 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
729 if ( m_minVirtualWidth
!= -1 && m_minVirtualWidth
> x
)
730 x
= m_minVirtualWidth
;
731 if ( m_maxVirtualWidth
!= -1 && m_maxVirtualWidth
< x
)
732 x
= m_maxVirtualWidth
;
733 if ( m_minVirtualHeight
!= -1 && m_minVirtualHeight
> y
)
734 y
= m_minVirtualHeight
;
735 if ( m_maxVirtualHeight
!= -1 && m_maxVirtualHeight
< y
)
736 y
= m_maxVirtualHeight
;
738 m_virtualSize
= wxSize(x
, y
);
741 wxSize
wxWindowBase::DoGetVirtualSize() const
743 wxSize
s( GetClientSize() );
745 return wxSize( wxMax( m_virtualSize
.GetWidth(), s
.GetWidth() ),
746 wxMax( m_virtualSize
.GetHeight(), s
.GetHeight() ) );
749 // ----------------------------------------------------------------------------
750 // show/hide/enable/disable the window
751 // ----------------------------------------------------------------------------
753 bool wxWindowBase::Show(bool show
)
755 if ( show
!= m_isShown
)
767 bool wxWindowBase::Enable(bool enable
)
769 if ( enable
!= m_isEnabled
)
771 m_isEnabled
= enable
;
780 // ----------------------------------------------------------------------------
782 // ----------------------------------------------------------------------------
784 bool wxWindowBase::IsTopLevel() const
789 // ----------------------------------------------------------------------------
790 // reparenting the window
791 // ----------------------------------------------------------------------------
793 void wxWindowBase::AddChild(wxWindowBase
*child
)
795 wxCHECK_RET( child
, wxT("can't add a NULL child") );
797 // this should never happen and it will lead to a crash later if it does
798 // because RemoveChild() will remove only one node from the children list
799 // and the other(s) one(s) will be left with dangling pointers in them
800 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
802 GetChildren().Append((wxWindow
*)child
);
803 child
->SetParent(this);
806 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
808 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
810 GetChildren().DeleteObject((wxWindow
*)child
);
811 child
->SetParent(NULL
);
814 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
816 wxWindow
*oldParent
= GetParent();
817 if ( newParent
== oldParent
)
823 // unlink this window from the existing parent.
826 oldParent
->RemoveChild(this);
830 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
833 // add it to the new one
836 newParent
->AddChild(this);
840 wxTopLevelWindows
.Append((wxWindow
*)this);
846 // ----------------------------------------------------------------------------
847 // event handler stuff
848 // ----------------------------------------------------------------------------
850 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
852 wxEvtHandler
*handlerOld
= GetEventHandler();
854 handler
->SetNextHandler(handlerOld
);
857 GetEventHandler()->SetPreviousHandler(handler
);
859 SetEventHandler(handler
);
862 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
864 wxEvtHandler
*handlerA
= GetEventHandler();
867 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
868 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
871 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
872 SetEventHandler(handlerB
);
877 handlerA
= (wxEvtHandler
*)NULL
;
884 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
886 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
888 wxEvtHandler
*handlerPrev
= NULL
,
889 *handlerCur
= GetEventHandler();
892 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
894 if ( handlerCur
== handler
)
898 handlerPrev
->SetNextHandler(handlerNext
);
902 SetEventHandler(handlerNext
);
907 handlerNext
->SetPreviousHandler ( handlerPrev
);
910 handler
->SetNextHandler(NULL
);
911 handler
->SetPreviousHandler(NULL
);
916 handlerPrev
= handlerCur
;
917 handlerCur
= handlerNext
;
920 wxFAIL_MSG( _T("where has the event handler gone?") );
925 // ----------------------------------------------------------------------------
927 // ----------------------------------------------------------------------------
929 void wxWindowBase::InheritAttributes()
931 const wxWindowBase
* const parent
= GetParent();
935 // we only inherit attributes which had been explicitly set for the parent
936 // which ensures that this only happens if the user really wants it and
937 // not by default which wouldn't make any sense in modern GUIs where the
938 // controls don't all use the same fonts (nor colours)
939 if ( parent
->m_hasFont
&& !m_hasFont
)
940 SetFont(parent
->GetFont());
942 // in addition, there is a possibility to explicitly forbid inheriting
943 // colours at each class level by overriding ShouldInheritColours()
944 if ( ShouldInheritColours() )
946 if ( parent
->m_hasFgCol
&& !m_hasFgCol
)
947 SetForegroundColour(parent
->GetForegroundColour());
949 if ( parent
->m_hasBgCol
&& !m_hasBgCol
)
950 SetBackgroundColour(parent
->GetBackgroundColour());
954 /* static */ wxVisualAttributes
955 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
957 // it is important to return valid values for all attributes from here,
958 // GetXXX() below rely on this
959 wxVisualAttributes attrs
;
960 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
961 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
962 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
967 wxColour
wxWindowBase::GetBackgroundColour() const
969 if ( !m_backgroundColour
.Ok() )
971 wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") );
973 // get our default background colour
974 wxColour colBg
= GetDefaultAttributes().colBg
;
976 // we must return some valid colour to avoid redoing this every time
977 // and also to avoid surprizing the applications written for older
978 // wxWindows versions where GetBackgroundColour() always returned
979 // something -- so give them something even if it doesn't make sense
980 // for this window (e.g. it has a themed background)
982 colBg
= GetClassDefaultAttributes().colBg
;
984 // cache it for the next call
985 wxConstCast(this, wxWindowBase
)->m_backgroundColour
= colBg
;
988 return m_backgroundColour
;
991 wxColour
wxWindowBase::GetForegroundColour() const
993 // logic is the same as above
994 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
996 wxASSERT_MSG( !m_hasFgCol
, _T("we have invalid explicit fg colour?") );
998 wxColour colFg
= GetDefaultAttributes().colFg
;
1001 colFg
= GetClassDefaultAttributes().colFg
;
1003 wxConstCast(this, wxWindowBase
)->m_foregroundColour
= colFg
;
1006 return m_foregroundColour
;
1009 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
1011 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
1014 m_backgroundColour
= colour
;
1021 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
1023 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
1026 m_foregroundColour
= colour
;
1033 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
1035 // setting an invalid cursor is ok, it means that we don't have any special
1037 if ( m_cursor
== cursor
)
1048 wxFont
& wxWindowBase::DoGetFont() const
1050 // logic is the same as in GetBackgroundColour()
1053 wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") );
1055 wxFont font
= GetDefaultAttributes().font
;
1057 font
= GetClassDefaultAttributes().font
;
1059 wxConstCast(this, wxWindowBase
)->m_font
= font
;
1062 // cast is here for non-const GetFont() convenience
1063 return wxConstCast(this, wxWindowBase
)->m_font
;
1066 bool wxWindowBase::SetFont(const wxFont
& font
)
1071 if ( font
== m_font
)
1086 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1088 m_hasCustomPalette
= true;
1091 // VZ: can anyone explain me what do we do here?
1092 wxWindowDC
d((wxWindow
*) this);
1096 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1098 wxWindow
*win
= (wxWindow
*)this;
1099 while ( win
&& !win
->HasCustomPalette() )
1101 win
= win
->GetParent();
1107 #endif // wxUSE_PALETTE
1110 void wxWindowBase::SetCaret(wxCaret
*caret
)
1121 wxASSERT_MSG( m_caret
->GetWindow() == this,
1122 wxT("caret should be created associated to this window") );
1125 #endif // wxUSE_CARET
1127 #if wxUSE_VALIDATORS
1128 // ----------------------------------------------------------------------------
1130 // ----------------------------------------------------------------------------
1132 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1134 if ( m_windowValidator
)
1135 delete m_windowValidator
;
1137 m_windowValidator
= (wxValidator
*)validator
.Clone();
1139 if ( m_windowValidator
)
1140 m_windowValidator
->SetWindow(this);
1142 #endif // wxUSE_VALIDATORS
1144 // ----------------------------------------------------------------------------
1145 // update region stuff
1146 // ----------------------------------------------------------------------------
1148 wxRect
wxWindowBase::GetUpdateClientRect() const
1150 wxRegion rgnUpdate
= GetUpdateRegion();
1151 rgnUpdate
.Intersect(GetClientRect());
1152 wxRect rectUpdate
= rgnUpdate
.GetBox();
1153 wxPoint ptOrigin
= GetClientAreaOrigin();
1154 rectUpdate
.x
-= ptOrigin
.x
;
1155 rectUpdate
.y
-= ptOrigin
.y
;
1160 bool wxWindowBase::IsExposed(int x
, int y
) const
1162 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1165 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
1167 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1170 void wxWindowBase::ClearBackground()
1172 // wxGTK uses its own version, no need to add never used code
1174 wxClientDC
dc((wxWindow
*)this);
1175 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1176 dc
.SetBackground(brush
);
1181 // ----------------------------------------------------------------------------
1182 // find child window by id or name
1183 // ----------------------------------------------------------------------------
1185 wxWindow
*wxWindowBase::FindWindow( long id
)
1187 if ( id
== m_windowId
)
1188 return (wxWindow
*)this;
1190 wxWindowBase
*res
= (wxWindow
*)NULL
;
1191 wxWindowList::compatibility_iterator node
;
1192 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1194 wxWindowBase
*child
= node
->GetData();
1195 res
= child
->FindWindow( id
);
1198 return (wxWindow
*)res
;
1201 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
1203 if ( name
== m_windowName
)
1204 return (wxWindow
*)this;
1206 wxWindowBase
*res
= (wxWindow
*)NULL
;
1207 wxWindowList::compatibility_iterator node
;
1208 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1210 wxWindow
*child
= node
->GetData();
1211 res
= child
->FindWindow(name
);
1214 return (wxWindow
*)res
;
1218 // find any window by id or name or label: If parent is non-NULL, look through
1219 // children for a label or title matching the specified string. If NULL, look
1220 // through all top-level windows.
1222 // to avoid duplicating code we reuse the same helper function but with
1223 // different comparators
1225 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1226 const wxString
& label
, long id
);
1229 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1232 return win
->GetLabel() == label
;
1236 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1239 return win
->GetName() == label
;
1243 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1246 return win
->GetId() == id
;
1249 // recursive helper for the FindWindowByXXX() functions
1251 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1252 const wxString
& label
,
1254 wxFindWindowCmp cmp
)
1258 // see if this is the one we're looking for
1259 if ( (*cmp
)(parent
, label
, id
) )
1260 return (wxWindow
*)parent
;
1262 // It wasn't, so check all its children
1263 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1265 node
= node
->GetNext() )
1267 // recursively check each child
1268 wxWindow
*win
= (wxWindow
*)node
->GetData();
1269 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1279 // helper for FindWindowByXXX()
1281 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1282 const wxString
& label
,
1284 wxFindWindowCmp cmp
)
1288 // just check parent and all its children
1289 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1292 // start at very top of wx's windows
1293 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1295 node
= node
->GetNext() )
1297 // recursively check each window & its children
1298 wxWindow
*win
= node
->GetData();
1299 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1309 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1311 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1316 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1318 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1322 // fall back to the label
1323 win
= FindWindowByLabel(title
, parent
);
1331 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1333 return wxFindWindowHelper(parent
, _T(""), id
, wxFindWindowCmpIds
);
1336 // ----------------------------------------------------------------------------
1337 // dialog oriented functions
1338 // ----------------------------------------------------------------------------
1340 void wxWindowBase::MakeModal(bool modal
)
1342 // Disable all other windows
1345 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1348 wxWindow
*win
= node
->GetData();
1350 win
->Enable(!modal
);
1352 node
= node
->GetNext();
1357 bool wxWindowBase::Validate()
1359 #if wxUSE_VALIDATORS
1360 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1362 wxWindowList::compatibility_iterator node
;
1363 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1365 wxWindowBase
*child
= node
->GetData();
1366 wxValidator
*validator
= child
->GetValidator();
1367 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1372 if ( recurse
&& !child
->Validate() )
1377 #endif // wxUSE_VALIDATORS
1382 bool wxWindowBase::TransferDataToWindow()
1384 #if wxUSE_VALIDATORS
1385 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1387 wxWindowList::compatibility_iterator node
;
1388 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1390 wxWindowBase
*child
= node
->GetData();
1391 wxValidator
*validator
= child
->GetValidator();
1392 if ( validator
&& !validator
->TransferToWindow() )
1394 wxLogWarning(_("Could not transfer data to window"));
1396 wxLog::FlushActive();
1404 if ( !child
->TransferDataToWindow() )
1406 // warning already given
1411 #endif // wxUSE_VALIDATORS
1416 bool wxWindowBase::TransferDataFromWindow()
1418 #if wxUSE_VALIDATORS
1419 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1421 wxWindowList::compatibility_iterator node
;
1422 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1424 wxWindow
*child
= node
->GetData();
1425 wxValidator
*validator
= child
->GetValidator();
1426 if ( validator
&& !validator
->TransferFromWindow() )
1428 // nop warning here because the application is supposed to give
1429 // one itself - we don't know here what might have gone wrongly
1436 if ( !child
->TransferDataFromWindow() )
1438 // warning already given
1443 #endif // wxUSE_VALIDATORS
1448 void wxWindowBase::InitDialog()
1450 wxInitDialogEvent
event(GetId());
1451 event
.SetEventObject( this );
1452 GetEventHandler()->ProcessEvent(event
);
1455 // ----------------------------------------------------------------------------
1456 // context-sensitive help support
1457 // ----------------------------------------------------------------------------
1461 // associate this help text with this window
1462 void wxWindowBase::SetHelpText(const wxString
& text
)
1464 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1467 helpProvider
->AddHelp(this, text
);
1471 // associate this help text with all windows with the same id as this
1473 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1475 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1478 helpProvider
->AddHelp(GetId(), text
);
1482 // get the help string associated with this window (may be empty)
1483 wxString
wxWindowBase::GetHelpText() const
1486 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1489 text
= helpProvider
->GetHelp(this);
1495 // show help for this window
1496 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1498 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1501 if ( helpProvider
->ShowHelp(this) )
1503 // skip the event.Skip() below
1511 #endif // wxUSE_HELP
1513 // ----------------------------------------------------------------------------
1514 // tooltipsroot.Replace("\\", "/");
1515 // ----------------------------------------------------------------------------
1519 void wxWindowBase::SetToolTip( const wxString
&tip
)
1521 // don't create the new tooltip if we already have one
1524 m_tooltip
->SetTip( tip
);
1528 SetToolTip( new wxToolTip( tip
) );
1531 // setting empty tooltip text does not remove the tooltip any more - use
1532 // SetToolTip((wxToolTip *)NULL) for this
1535 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1540 m_tooltip
= tooltip
;
1543 #endif // wxUSE_TOOLTIPS
1545 // ----------------------------------------------------------------------------
1546 // constraints and sizers
1547 // ----------------------------------------------------------------------------
1549 #if wxUSE_CONSTRAINTS
1551 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1553 if ( m_constraints
)
1555 UnsetConstraints(m_constraints
);
1556 delete m_constraints
;
1558 m_constraints
= constraints
;
1559 if ( m_constraints
)
1561 // Make sure other windows know they're part of a 'meaningful relationship'
1562 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1563 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1564 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1565 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1566 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1567 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1568 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1569 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1570 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1571 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1572 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1573 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1574 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1575 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1576 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1577 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1581 // This removes any dangling pointers to this window in other windows'
1582 // constraintsInvolvedIn lists.
1583 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1587 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1588 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1589 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1590 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1591 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1592 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1593 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1594 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1595 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1596 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1597 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1598 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1599 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1600 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1601 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1602 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1606 // Back-pointer to other windows we're involved with, so if we delete this
1607 // window, we must delete any constraints we're involved with.
1608 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1610 if ( !m_constraintsInvolvedIn
)
1611 m_constraintsInvolvedIn
= new wxWindowList
;
1612 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1613 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1616 // REMOVE back-pointer to other windows we're involved with.
1617 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1619 if ( m_constraintsInvolvedIn
)
1620 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1623 // Reset any constraints that mention this window
1624 void wxWindowBase::DeleteRelatedConstraints()
1626 if ( m_constraintsInvolvedIn
)
1628 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1631 wxWindow
*win
= node
->GetData();
1632 wxLayoutConstraints
*constr
= win
->GetConstraints();
1634 // Reset any constraints involving this window
1637 constr
->left
.ResetIfWin(this);
1638 constr
->top
.ResetIfWin(this);
1639 constr
->right
.ResetIfWin(this);
1640 constr
->bottom
.ResetIfWin(this);
1641 constr
->width
.ResetIfWin(this);
1642 constr
->height
.ResetIfWin(this);
1643 constr
->centreX
.ResetIfWin(this);
1644 constr
->centreY
.ResetIfWin(this);
1647 wxWindowList::compatibility_iterator next
= node
->GetNext();
1648 m_constraintsInvolvedIn
->Erase(node
);
1652 delete m_constraintsInvolvedIn
;
1653 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1657 #endif // wxUSE_CONSTRAINTS
1659 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1661 if ( sizer
== m_windowSizer
)
1665 delete m_windowSizer
;
1667 m_windowSizer
= sizer
;
1669 SetAutoLayout( sizer
!= NULL
);
1672 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1674 SetSizer( sizer
, deleteOld
);
1675 sizer
->SetSizeHints( (wxWindow
*) this );
1679 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
1681 // adding a window to a sizer twice is going to result in fatal and
1682 // hard to debug problems later because when deleting the second
1683 // associated wxSizerItem we're going to dereference a dangling
1684 // pointer; so try to detect this as early as possible
1685 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
1686 _T("Adding a window to the same sizer twice?") );
1688 m_containingSizer
= sizer
;
1691 #if wxUSE_CONSTRAINTS
1693 void wxWindowBase::SatisfyConstraints()
1695 wxLayoutConstraints
*constr
= GetConstraints();
1696 bool wasOk
= constr
&& constr
->AreSatisfied();
1698 ResetConstraints(); // Mark all constraints as unevaluated
1702 // if we're a top level panel (i.e. our parent is frame/dialog), our
1703 // own constraints will never be satisfied any more unless we do it
1707 while ( noChanges
> 0 )
1709 LayoutPhase1(&noChanges
);
1713 LayoutPhase2(&noChanges
);
1716 #endif // wxUSE_CONSTRAINTS
1718 bool wxWindowBase::Layout()
1720 // If there is a sizer, use it instead of the constraints
1724 GetVirtualSize(&w
, &h
);
1725 GetSizer()->SetDimension( 0, 0, w
, h
);
1727 #if wxUSE_CONSTRAINTS
1730 SatisfyConstraints(); // Find the right constraints values
1731 SetConstraintSizes(); // Recursively set the real window sizes
1738 #if wxUSE_CONSTRAINTS
1740 // first phase of the constraints evaluation: set our own constraints
1741 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1743 wxLayoutConstraints
*constr
= GetConstraints();
1745 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1748 // second phase: set the constraints for our children
1749 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1756 // Layout grand children
1762 // Do a phase of evaluating child constraints
1763 bool wxWindowBase::DoPhase(int phase
)
1765 // the list containing the children for which the constraints are already
1767 wxWindowList succeeded
;
1769 // the max number of iterations we loop before concluding that we can't set
1771 static const int maxIterations
= 500;
1773 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1777 // loop over all children setting their constraints
1778 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1780 node
= node
->GetNext() )
1782 wxWindow
*child
= node
->GetData();
1783 if ( child
->IsTopLevel() )
1785 // top level children are not inside our client area
1789 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1791 // this one is either already ok or nothing we can do about it
1795 int tempNoChanges
= 0;
1796 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1797 : child
->LayoutPhase2(&tempNoChanges
);
1798 noChanges
+= tempNoChanges
;
1802 succeeded
.Append(child
);
1808 // constraints are set
1816 void wxWindowBase::ResetConstraints()
1818 wxLayoutConstraints
*constr
= GetConstraints();
1821 constr
->left
.SetDone(false);
1822 constr
->top
.SetDone(false);
1823 constr
->right
.SetDone(false);
1824 constr
->bottom
.SetDone(false);
1825 constr
->width
.SetDone(false);
1826 constr
->height
.SetDone(false);
1827 constr
->centreX
.SetDone(false);
1828 constr
->centreY
.SetDone(false);
1831 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1834 wxWindow
*win
= node
->GetData();
1835 if ( !win
->IsTopLevel() )
1836 win
->ResetConstraints();
1837 node
= node
->GetNext();
1841 // Need to distinguish between setting the 'fake' size for windows and sizers,
1842 // and setting the real values.
1843 void wxWindowBase::SetConstraintSizes(bool recurse
)
1845 wxLayoutConstraints
*constr
= GetConstraints();
1846 if ( constr
&& constr
->AreSatisfied() )
1848 int x
= constr
->left
.GetValue();
1849 int y
= constr
->top
.GetValue();
1850 int w
= constr
->width
.GetValue();
1851 int h
= constr
->height
.GetValue();
1853 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1854 (constr
->height
.GetRelationship() != wxAsIs
) )
1856 SetSize(x
, y
, w
, h
);
1860 // If we don't want to resize this window, just move it...
1866 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1867 GetClassInfo()->GetClassName(),
1873 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1876 wxWindow
*win
= node
->GetData();
1877 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1878 win
->SetConstraintSizes();
1879 node
= node
->GetNext();
1884 // Only set the size/position of the constraint (if any)
1885 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1887 wxLayoutConstraints
*constr
= GetConstraints();
1892 constr
->left
.SetValue(x
);
1893 constr
->left
.SetDone(true);
1897 constr
->top
.SetValue(y
);
1898 constr
->top
.SetDone(true);
1902 constr
->width
.SetValue(w
);
1903 constr
->width
.SetDone(true);
1907 constr
->height
.SetValue(h
);
1908 constr
->height
.SetDone(true);
1913 void wxWindowBase::MoveConstraint(int x
, int y
)
1915 wxLayoutConstraints
*constr
= GetConstraints();
1920 constr
->left
.SetValue(x
);
1921 constr
->left
.SetDone(true);
1925 constr
->top
.SetValue(y
);
1926 constr
->top
.SetDone(true);
1931 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1933 wxLayoutConstraints
*constr
= GetConstraints();
1936 *w
= constr
->width
.GetValue();
1937 *h
= constr
->height
.GetValue();
1943 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1945 wxLayoutConstraints
*constr
= GetConstraints();
1948 *w
= constr
->width
.GetValue();
1949 *h
= constr
->height
.GetValue();
1952 GetClientSize(w
, h
);
1955 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1957 wxLayoutConstraints
*constr
= GetConstraints();
1960 *x
= constr
->left
.GetValue();
1961 *y
= constr
->top
.GetValue();
1967 #endif // wxUSE_CONSTRAINTS
1969 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
1971 // don't do it for the dialogs/frames - they float independently of their
1973 if ( !IsTopLevel() )
1975 wxWindow
*parent
= GetParent();
1976 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
1978 wxPoint
pt(parent
->GetClientAreaOrigin());
1985 // ----------------------------------------------------------------------------
1986 // do Update UI processing for child controls
1987 // ----------------------------------------------------------------------------
1989 void wxWindowBase::UpdateWindowUI(long flags
)
1991 wxUpdateUIEvent
event(GetId());
1992 event
.m_eventObject
= this;
1994 if ( GetEventHandler()->ProcessEvent(event
) )
1996 DoUpdateWindowUI(event
);
1999 if (flags
& wxUPDATE_UI_RECURSE
)
2001 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2004 wxWindow
* child
= (wxWindow
*) node
->GetData();
2005 child
->UpdateWindowUI(flags
);
2006 node
= node
->GetNext();
2011 // do the window-specific processing after processing the update event
2012 // TODO: take specific knowledge out of this function and
2013 // put in each control's base class. Unfortunately we don't
2014 // yet have base implementation files for wxCheckBox and wxRadioButton.
2015 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
2017 if ( event
.GetSetEnabled() )
2018 Enable(event
.GetEnabled());
2021 if ( event
.GetSetText() )
2023 wxControl
*control
= wxDynamicCastThis(wxControl
);
2026 if ( event
.GetText() != control
->GetLabel() )
2027 control
->SetLabel(event
.GetText());
2030 wxCheckBox
*checkbox
= wxDynamicCastThis(wxCheckBox
);
2033 if ( event
.GetSetChecked() )
2034 checkbox
->SetValue(event
.GetChecked());
2036 #endif // wxUSE_CHECKBOX
2039 wxRadioButton
*radiobtn
= wxDynamicCastThis(wxRadioButton
);
2042 if ( event
.GetSetChecked() )
2043 radiobtn
->SetValue(event
.GetChecked());
2045 #endif // wxUSE_RADIOBTN
2051 // call internal idle recursively
2052 // may be obsolete (wait until OnIdle scheme stabilises)
2053 void wxWindowBase::ProcessInternalIdle()
2057 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2060 wxWindow
*child
= node
->GetData();
2061 child
->ProcessInternalIdle();
2062 node
= node
->GetNext();
2067 // ----------------------------------------------------------------------------
2068 // dialog units translations
2069 // ----------------------------------------------------------------------------
2071 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
2073 int charWidth
= GetCharWidth();
2074 int charHeight
= GetCharHeight();
2075 wxPoint
pt2(-1, -1);
2077 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
2079 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2084 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
2086 int charWidth
= GetCharWidth();
2087 int charHeight
= GetCharHeight();
2088 wxPoint
pt2(-1, -1);
2090 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
2092 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2097 // ----------------------------------------------------------------------------
2099 // ----------------------------------------------------------------------------
2101 // propagate the colour change event to the subwindows
2102 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2104 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2107 // Only propagate to non-top-level windows
2108 wxWindow
*win
= node
->GetData();
2109 if ( !win
->IsTopLevel() )
2111 wxSysColourChangedEvent event2
;
2112 event
.m_eventObject
= win
;
2113 win
->GetEventHandler()->ProcessEvent(event2
);
2116 node
= node
->GetNext();
2120 // the default action is to populate dialog with data when it's created,
2121 // and nudge the UI into displaying itself correctly in case
2122 // we've turned the wxUpdateUIEvents frequency down low.
2123 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2125 TransferDataToWindow();
2127 // Update the UI at this point
2128 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2131 // process Ctrl-Alt-mclick
2132 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2135 if ( event
.ControlDown() && event
.AltDown() )
2137 // don't translate these strings
2140 #ifdef __WXUNIVERSAL__
2142 #endif // __WXUNIVERSAL__
2144 switch ( wxGetOsVersion() )
2146 case wxMOTIF_X
: port
+= _T("Motif"); break;
2148 case wxMAC_DARWIN
: port
+= _T("Mac"); break;
2149 case wxBEOS
: port
+= _T("BeOS"); break;
2153 case wxGTK_BEOS
: port
+= _T("GTK"); break;
2159 case wxWIN386
: port
+= _T("MS Windows"); break;
2163 case wxMGL_OS2
: port
+= _T("MGL"); break;
2165 case wxOS2_PM
: port
+= _T("OS/2"); break;
2166 default: port
+= _T("unknown"); break;
2169 wxMessageBox(wxString::Format(
2171 " wxWindows Library (%s port)\nVersion %u.%u.%u%s, compiled at %s %s\n Copyright (c) 1995-2002 wxWindows team"
2185 _T("wxWindows information"),
2186 wxICON_INFORMATION
| wxOK
,
2190 #endif // wxUSE_MSGDLG
2196 // ----------------------------------------------------------------------------
2198 // ----------------------------------------------------------------------------
2200 #if wxUSE_ACCESSIBILITY
2201 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2203 if (m_accessible
&& (accessible
!= m_accessible
))
2204 delete m_accessible
;
2205 m_accessible
= accessible
;
2207 m_accessible
->SetWindow((wxWindow
*) this);
2210 // Returns the accessible object, creating if necessary.
2211 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2214 m_accessible
= CreateAccessible();
2215 return m_accessible
;
2218 // Override to create a specific accessible object.
2219 wxAccessible
* wxWindowBase::CreateAccessible()
2221 return new wxWindowAccessible((wxWindow
*) this);
2227 // ----------------------------------------------------------------------------
2228 // list classes implementation
2229 // ----------------------------------------------------------------------------
2231 void wxWindowListNode::DeleteData()
2233 delete (wxWindow
*)GetData();
2237 // ----------------------------------------------------------------------------
2239 // ----------------------------------------------------------------------------
2241 wxBorder
wxWindowBase::GetBorder(long flags
) const
2243 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2244 if ( border
== wxBORDER_DEFAULT
)
2246 border
= GetDefaultBorder();
2252 wxBorder
wxWindowBase::GetDefaultBorder() const
2254 return wxBORDER_NONE
;
2257 // ----------------------------------------------------------------------------
2259 // ----------------------------------------------------------------------------
2261 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2263 // here we just check if the point is inside the window or not
2265 // check the top and left border first
2266 bool outside
= x
< 0 || y
< 0;
2269 // check the right and bottom borders too
2270 wxSize size
= GetSize();
2271 outside
= x
>= size
.x
|| y
>= size
.y
;
2274 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2277 // ----------------------------------------------------------------------------
2279 // ----------------------------------------------------------------------------
2281 struct WXDLLEXPORT wxWindowNext
2285 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2287 void wxWindowBase::CaptureMouse()
2289 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this);
2291 wxWindow
*winOld
= GetCapture();
2294 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2297 wxWindowNext
*item
= new wxWindowNext
;
2299 item
->next
= ms_winCaptureNext
;
2300 ms_winCaptureNext
= item
;
2302 //else: no mouse capture to save
2307 void wxWindowBase::ReleaseMouse()
2309 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this);
2311 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2315 if ( ms_winCaptureNext
)
2317 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2319 wxWindowNext
*item
= ms_winCaptureNext
;
2320 ms_winCaptureNext
= item
->next
;
2323 //else: stack is empty, no previous capture
2325 wxLogTrace(_T("mousecapture"),
2326 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2333 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2334 int WXUNUSED(modifiers
),
2335 int WXUNUSED(keycode
))
2341 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2347 #endif // wxUSE_HOTKEY
2349 void wxWindowBase::SendDestroyEvent()
2351 wxWindowDestroyEvent event
;
2352 event
.SetEventObject(this);
2353 event
.SetId(GetId());
2354 GetEventHandler()->ProcessEvent(event
);
2357 // ----------------------------------------------------------------------------
2359 // ----------------------------------------------------------------------------
2361 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2363 #if wxUSE_VALIDATORS
2364 // Can only use the validator of the window which
2365 // is receiving the event
2366 if ( event
.GetEventObject() == this )
2368 wxValidator
*validator
= GetValidator();
2369 if ( validator
&& validator
->ProcessEvent(event
) )
2374 #endif // wxUSE_VALIDATORS
2379 bool wxWindowBase::TryParent(wxEvent
& event
)
2381 // carry on up the parent-child hierarchy if the propgation count hasn't
2383 if ( event
.ShouldPropagate() )
2385 // honour the requests to stop propagation at this window: this is
2386 // used by the dialogs, for example, to prevent processing the events
2387 // from the dialog controls in the parent frame which rarely, if ever,
2389 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2391 wxWindow
*parent
= GetParent();
2392 if ( parent
&& !parent
->IsBeingDeleted() )
2394 wxPropagateOnce
propagateOnce(event
);
2396 return parent
->GetEventHandler()->ProcessEvent(event
);
2401 return wxEvtHandler::TryParent(event
);
2404 // ----------------------------------------------------------------------------
2406 // ----------------------------------------------------------------------------
2408 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2410 while ( win
&& !win
->IsTopLevel() )
2411 win
= win
->GetParent();
2416 #if wxUSE_ACCESSIBILITY
2417 // ----------------------------------------------------------------------------
2418 // accessible object for windows
2419 // ----------------------------------------------------------------------------
2421 // Can return either a child object, or an integer
2422 // representing the child element, starting from 1.
2423 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2425 wxASSERT( GetWindow() != NULL
);
2429 return wxACC_NOT_IMPLEMENTED
;
2432 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2433 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2435 wxASSERT( GetWindow() != NULL
);
2439 wxWindow
* win
= NULL
;
2446 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2448 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2455 rect
= win
->GetRect();
2456 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2457 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2461 return wxACC_NOT_IMPLEMENTED
;
2464 // Navigates from fromId to toId/toObject.
2465 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2466 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2468 wxASSERT( GetWindow() != NULL
);
2474 case wxNAVDIR_FIRSTCHILD
:
2476 if (GetWindow()->GetChildren().GetCount() == 0)
2478 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2479 *toObject
= childWindow
->GetOrCreateAccessible();
2483 case wxNAVDIR_LASTCHILD
:
2485 if (GetWindow()->GetChildren().GetCount() == 0)
2487 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2488 *toObject
= childWindow
->GetOrCreateAccessible();
2492 case wxNAVDIR_RIGHT
:
2496 wxWindowList::compatibility_iterator node
=
2497 wxWindowList::compatibility_iterator();
2500 // Can't navigate to sibling of this window
2501 // if we're a top-level window.
2502 if (!GetWindow()->GetParent())
2503 return wxACC_NOT_IMPLEMENTED
;
2505 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2509 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2510 node
= GetWindow()->GetChildren().Item(fromId
-1);
2513 if (node
&& node
->GetNext())
2515 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2516 *toObject
= nextWindow
->GetOrCreateAccessible();
2524 case wxNAVDIR_PREVIOUS
:
2526 wxWindowList::compatibility_iterator node
=
2527 wxWindowList::compatibility_iterator();
2530 // Can't navigate to sibling of this window
2531 // if we're a top-level window.
2532 if (!GetWindow()->GetParent())
2533 return wxACC_NOT_IMPLEMENTED
;
2535 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2539 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2540 node
= GetWindow()->GetChildren().Item(fromId
-1);
2543 if (node
&& node
->GetPrevious())
2545 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2546 *toObject
= previousWindow
->GetOrCreateAccessible();
2554 return wxACC_NOT_IMPLEMENTED
;
2557 // Gets the name of the specified object.
2558 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2560 wxASSERT( GetWindow() != NULL
);
2566 // If a child, leave wxWindows to call the function on the actual
2569 return wxACC_NOT_IMPLEMENTED
;
2571 // This will eventually be replaced by specialised
2572 // accessible classes, one for each kind of wxWindows
2573 // control or window.
2574 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2575 title
= ((wxButton
*) GetWindow())->GetLabel();
2577 title
= GetWindow()->GetName();
2579 if (!title
.IsEmpty())
2585 return wxACC_NOT_IMPLEMENTED
;
2588 // Gets the number of children.
2589 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2591 wxASSERT( GetWindow() != NULL
);
2595 *childId
= (int) GetWindow()->GetChildren().GetCount();
2599 // Gets the specified child (starting from 1).
2600 // If *child is NULL and return value is wxACC_OK,
2601 // this means that the child is a simple element and
2602 // not an accessible object.
2603 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2605 wxASSERT( GetWindow() != NULL
);
2615 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2618 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2619 *child
= childWindow
->GetOrCreateAccessible();
2626 // Gets the parent, or NULL.
2627 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2629 wxASSERT( GetWindow() != NULL
);
2633 wxWindow
* parentWindow
= GetWindow()->GetParent();
2641 *parent
= parentWindow
->GetOrCreateAccessible();
2649 // Performs the default action. childId is 0 (the action for this object)
2650 // or > 0 (the action for a child).
2651 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2652 // window (e.g. an edit control).
2653 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
2655 wxASSERT( GetWindow() != NULL
);
2659 return wxACC_NOT_IMPLEMENTED
;
2662 // Gets the default action for this object (0) or > 0 (the action for a child).
2663 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2664 // string if there is no action.
2665 // The retrieved string describes the action that is performed on an object,
2666 // not what the object does as a result. For example, a toolbar button that prints
2667 // a document has a default action of "Press" rather than "Prints the current document."
2668 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
2670 wxASSERT( GetWindow() != NULL
);
2674 return wxACC_NOT_IMPLEMENTED
;
2677 // Returns the description for this object or a child.
2678 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
2680 wxASSERT( GetWindow() != NULL
);
2684 wxString
ht(GetWindow()->GetHelpText());
2690 return wxACC_NOT_IMPLEMENTED
;
2693 // Returns help text for this object or a child, similar to tooltip text.
2694 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
2696 wxASSERT( GetWindow() != NULL
);
2700 wxString
ht(GetWindow()->GetHelpText());
2706 return wxACC_NOT_IMPLEMENTED
;
2709 // Returns the keyboard shortcut for this object or child.
2710 // Return e.g. ALT+K
2711 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
2713 wxASSERT( GetWindow() != NULL
);
2717 return wxACC_NOT_IMPLEMENTED
;
2720 // Returns a role constant.
2721 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
2723 wxASSERT( GetWindow() != NULL
);
2727 // If a child, leave wxWindows to call the function on the actual
2730 return wxACC_NOT_IMPLEMENTED
;
2732 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2733 return wxACC_NOT_IMPLEMENTED
;
2735 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2736 return wxACC_NOT_IMPLEMENTED
;
2739 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2740 return wxACC_NOT_IMPLEMENTED
;
2743 //*role = wxROLE_SYSTEM_CLIENT;
2744 *role
= wxROLE_SYSTEM_CLIENT
;
2748 return wxACC_NOT_IMPLEMENTED
;
2752 // Returns a state constant.
2753 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
2755 wxASSERT( GetWindow() != NULL
);
2759 // If a child, leave wxWindows to call the function on the actual
2762 return wxACC_NOT_IMPLEMENTED
;
2764 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2765 return wxACC_NOT_IMPLEMENTED
;
2768 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2769 return wxACC_NOT_IMPLEMENTED
;
2772 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2773 return wxACC_NOT_IMPLEMENTED
;
2780 return wxACC_NOT_IMPLEMENTED
;
2784 // Returns a localized string representing the value for the object
2786 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
2788 wxASSERT( GetWindow() != NULL
);
2792 return wxACC_NOT_IMPLEMENTED
;
2795 // Selects the object or child.
2796 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
2798 wxASSERT( GetWindow() != NULL
);
2802 return wxACC_NOT_IMPLEMENTED
;
2805 // Gets the window with the keyboard focus.
2806 // If childId is 0 and child is NULL, no object in
2807 // this subhierarchy has the focus.
2808 // If this object has the focus, child should be 'this'.
2809 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
2811 wxASSERT( GetWindow() != NULL
);
2815 return wxACC_NOT_IMPLEMENTED
;
2818 // Gets a variant representing the selected children
2820 // Acceptable values:
2821 // - a null variant (IsNull() returns TRUE)
2822 // - a list variant (GetType() == wxT("list")
2823 // - an integer representing the selected child element,
2824 // or 0 if this object is selected (GetType() == wxT("long")
2825 // - a "void*" pointer to a wxAccessible child object
2826 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
2828 wxASSERT( GetWindow() != NULL
);
2832 return wxACC_NOT_IMPLEMENTED
;
2835 #endif // wxUSE_ACCESSIBILITY