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()
113 : m_bestSize(wxDefaultSize
)
115 // no window yet, no parent nor children
116 m_parent
= (wxWindow
*)NULL
;
117 m_windowId
= wxID_ANY
;
119 // no constraints on the minimal window size
125 // window are created enabled and visible by default
129 // the default event handler is just this window
130 m_eventHandler
= this;
134 m_windowValidator
= (wxValidator
*) NULL
;
135 #endif // wxUSE_VALIDATORS
137 // the colours/fonts are default for now, so leave m_font,
138 // m_backgroundColour and m_foregroundColour uninitialized and set those
147 #if wxUSE_CONSTRAINTS
148 // no constraints whatsoever
149 m_constraints
= (wxLayoutConstraints
*) NULL
;
150 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
151 #endif // wxUSE_CONSTRAINTS
153 m_windowSizer
= (wxSizer
*) NULL
;
154 m_containingSizer
= (wxSizer
*) NULL
;
155 m_autoLayout
= false;
157 #if wxUSE_DRAG_AND_DROP
158 m_dropTarget
= (wxDropTarget
*)NULL
;
159 #endif // wxUSE_DRAG_AND_DROP
162 m_tooltip
= (wxToolTip
*)NULL
;
163 #endif // wxUSE_TOOLTIPS
166 m_caret
= (wxCaret
*)NULL
;
167 #endif // wxUSE_CARET
170 m_hasCustomPalette
= false;
171 #endif // wxUSE_PALETTE
173 #if wxUSE_ACCESSIBILITY
177 m_virtualSize
= wxDefaultSize
;
182 m_maxVirtualHeight
= -1;
184 m_windowVariant
= wxWINDOW_VARIANT_NORMAL
;
186 // Whether we're using the current theme for this window (wxGTK only for now)
187 m_themeEnabled
= false;
189 // VZ: this one shouldn't exist...
190 m_isBeingDeleted
= false;
193 // common part of window creation process
194 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
196 const wxPoint
& WXUNUSED(pos
),
199 const wxValidator
& wxVALIDATOR_PARAM(validator
),
200 const wxString
& name
)
203 // wxGTK doesn't allow to create controls with static box as the parent so
204 // this will result in a crash when the program is ported to wxGTK so warn
207 // if you get this assert, the correct solution is to create the controls
208 // as siblings of the static box
209 wxASSERT_MSG( !parent
|| !wxDynamicCast(parent
, wxStaticBox
),
210 _T("wxStaticBox can't be used as a window parent!") );
211 #endif // wxUSE_STATBOX
213 // ids are limited to 16 bits under MSW so if you care about portability,
214 // it's not a good idea to use ids out of this range (and negative ids are
215 // reserved for wxWindows own usage)
216 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767),
217 _T("invalid id value") );
219 // generate a new id if the user doesn't care about it
220 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
223 SetWindowStyleFlag(style
);
226 // Set the minsize to be the size passed to the ctor (if any) for
227 // non-TLWs. This is so items used in a sizer will use this explicitly
228 // set size for layout, instead of falling back the (probably smaller)
235 SetValidator(validator
);
236 #endif // wxUSE_VALIDATORS
238 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
239 // have it too - like this it's possible to set it only in the top level
240 // dialog/frame and all children will inherit it by defult
241 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
243 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
249 // ----------------------------------------------------------------------------
251 // ----------------------------------------------------------------------------
254 wxWindowBase::~wxWindowBase()
256 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
258 // FIXME if these 2 cases result from programming errors in the user code
259 // we should probably assert here instead of silently fixing them
261 // Just in case the window has been Closed, but we're then deleting
262 // immediately: don't leave dangling pointers.
263 wxPendingDelete
.DeleteObject(this);
265 // Just in case we've loaded a top-level window via LoadNativeDialog but
266 // we weren't a dialog class
267 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
269 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
271 // reset the dangling pointer our parent window may keep to us
274 if ( m_parent
->GetDefaultItem() == this )
276 m_parent
->SetDefaultItem(NULL
);
279 m_parent
->RemoveChild(this);
284 #endif // wxUSE_CARET
287 delete m_windowValidator
;
288 #endif // wxUSE_VALIDATORS
290 #if wxUSE_CONSTRAINTS
291 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
292 // at deleted windows as they delete themselves.
293 DeleteRelatedConstraints();
297 // This removes any dangling pointers to this window in other windows'
298 // constraintsInvolvedIn lists.
299 UnsetConstraints(m_constraints
);
300 delete m_constraints
;
301 m_constraints
= NULL
;
303 #endif // wxUSE_CONSTRAINTS
305 if ( m_containingSizer
)
306 m_containingSizer
->Detach( (wxWindow
*)this );
308 delete m_windowSizer
;
310 #if wxUSE_DRAG_AND_DROP
312 #endif // wxUSE_DRAG_AND_DROP
316 #endif // wxUSE_TOOLTIPS
318 #if wxUSE_ACCESSIBILITY
323 bool wxWindowBase::Destroy()
330 bool wxWindowBase::Close(bool force
)
332 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
333 event
.SetEventObject(this);
334 event
.SetCanVeto(!force
);
336 // return false if window wasn't closed because the application vetoed the
338 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
341 bool wxWindowBase::DestroyChildren()
343 wxWindowList::compatibility_iterator node
;
346 // we iterate until the list becomes empty
347 node
= GetChildren().GetFirst();
351 wxWindow
*child
= node
->GetData();
353 // note that we really want to call delete and not ->Destroy() here
354 // because we want to delete the child immediately, before we are
355 // deleted, and delayed deletion would result in problems as our (top
356 // level) child could outlive its parent
359 wxASSERT_MSG( !GetChildren().Find(child
),
360 wxT("child didn't remove itself using RemoveChild()") );
366 // ----------------------------------------------------------------------------
367 // size/position related methods
368 // ----------------------------------------------------------------------------
370 // centre the window with respect to its parent in either (or both) directions
371 void wxWindowBase::Centre(int direction
)
373 // the position/size of the parent window or of the entire screen
375 int widthParent
, heightParent
;
377 wxWindow
*parent
= NULL
;
379 if ( !(direction
& wxCENTRE_ON_SCREEN
) )
381 // find the parent to centre this window on: it should be the
382 // immediate parent for the controls but the top level parent for the
383 // top level windows (like dialogs)
384 parent
= GetParent();
387 while ( parent
&& !parent
->IsTopLevel() )
389 parent
= parent
->GetParent();
393 // there is no wxTopLevelWindow under wxMotif yet
395 // we shouldn't center the dialog on the iconized window: under
396 // Windows, for example, this places it completely off the screen
399 wxTopLevelWindow
*winTop
= wxDynamicCast(parent
, wxTopLevelWindow
);
400 if ( winTop
&& winTop
->IsIconized() )
405 #endif // __WXMOTIF__
407 // did we find the parent?
411 direction
|= wxCENTRE_ON_SCREEN
;
415 if ( direction
& wxCENTRE_ON_SCREEN
)
417 // centre with respect to the whole screen
418 wxDisplaySize(&widthParent
, &heightParent
);
424 // centre on the parent
425 parent
->GetSize(&widthParent
, &heightParent
);
427 // adjust to the parents position
428 posParent
= parent
->GetPosition();
432 // centre inside the parents client rectangle
433 parent
->GetClientSize(&widthParent
, &heightParent
);
438 GetSize(&width
, &height
);
443 if ( direction
& wxHORIZONTAL
)
444 xNew
= (widthParent
- width
)/2;
446 if ( direction
& wxVERTICAL
)
447 yNew
= (heightParent
- height
)/2;
452 // Base size of the visible dimensions of the display
453 // to take into account the taskbar
454 wxRect rect
= wxGetClientDisplayRect();
455 wxSize
size (rect
.width
,rect
.height
);
457 // NB: in wxMSW, negative position may not neccessary mean "out of screen",
458 // but it may mean that the window is placed on other than the main
459 // display. Therefore we only make sure centered window is on the main display
460 // if the parent is at least partially present here.
461 if (posParent
.x
+ widthParent
>= 0) // if parent is (partially) on the main display
465 else if (xNew
+width
> size
.x
)
466 xNew
= size
.x
-width
-1;
468 if (posParent
.y
+ heightParent
>= 0) // if parent is (partially) on the main display
470 if (yNew
+height
> size
.y
)
471 yNew
= size
.y
-height
-1;
473 // Make certain that the title bar is initially visible
474 // always, even if this would push the bottom of the
475 // dialog of the visible area of the display
480 // move the window to this position (keeping the old size but using
481 // SetSize() and not Move() to allow xNew and/or yNew to be -1)
482 SetSize(xNew
, yNew
, width
, height
, wxSIZE_ALLOW_MINUS_ONE
);
485 // fits the window around the children
486 void wxWindowBase::Fit()
488 if ( GetChildren().GetCount() > 0 )
490 SetClientSize(DoGetBestSize());
492 //else: do nothing if we have no children
495 // fits virtual size (ie. scrolled area etc.) around children
496 void wxWindowBase::FitInside()
498 if ( GetChildren().GetCount() > 0 )
500 SetVirtualSize( GetBestVirtualSize() );
504 // return the size best suited for the current window
505 wxSize
wxWindowBase::DoGetBestSize() const
509 return m_windowSizer
->GetMinSize();
511 #if wxUSE_CONSTRAINTS
512 else if ( m_constraints
)
514 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
516 // our minimal acceptable size is such that all our windows fit inside
520 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
522 node
= node
->GetNext() )
524 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
527 // it's not normal that we have an unconstrained child, but
528 // what can we do about it?
532 int x
= c
->right
.GetValue(),
533 y
= c
->bottom
.GetValue();
541 // TODO: we must calculate the overlaps somehow, otherwise we
542 // will never return a size bigger than the current one :-(
545 return wxSize(maxX
, maxY
);
547 #endif // wxUSE_CONSTRAINTS
548 else if ( GetChildren().GetCount() > 0 )
550 // our minimal acceptable size is such that all our windows fit inside
554 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
556 node
= node
->GetNext() )
558 wxWindow
*win
= node
->GetData();
559 if ( win
->IsTopLevel()
561 || wxDynamicCast(win
, wxStatusBar
)
562 #endif // wxUSE_STATUSBAR
565 // dialogs and frames lie in different top level windows -
566 // don't deal with them here; as for the status bars, they
567 // don't lie in the client area at all
572 win
->GetPosition(&wx
, &wy
);
574 // if the window hadn't been positioned yet, assume that it is in
581 win
->GetSize(&ww
, &wh
);
582 if ( wx
+ ww
> maxX
)
584 if ( wy
+ wh
> maxY
)
588 // for compatibility with the old versions and because it really looks
589 // slightly more pretty like this, add a pad
593 return wxSize(maxX
, maxY
);
597 // Windows which don't implement DoGetBestSize and aren't parents.
598 // This emulates the behavior of a wxSizer without wxADJUST_MINSIZE
600 // If you get the following message you should do one of two things
601 // 1. Do what it says (best)
602 // 2. m_bestSize = GetSize() at end of Create() (hack)
603 if(m_bestSize
== wxDefaultSize
)
605 wxLogDebug(wxT("Class %s (or superclass) should implement DoGetBestSize()"),GetClassInfo()->GetClassName());
606 wxConstCast(this,wxWindowBase
)->m_bestSize
= GetSize();
612 // by default the origin is not shifted
613 wxPoint
wxWindowBase::GetClientAreaOrigin() const
615 return wxPoint(0, 0);
618 // set the min/max size of the window
619 void wxWindowBase::SetSizeHints(int minW
, int minH
,
621 int WXUNUSED(incW
), int WXUNUSED(incH
))
623 // setting min width greater than max width leads to infinite loops under
624 // X11 and generally doesn't make any sense, so don't allow it
625 wxCHECK_RET( (minW
== -1 || maxW
== -1 || minW
<= maxW
) &&
626 (minH
== -1 || maxH
== -1 || minH
<= maxH
),
627 _T("min width/height must be less than max width/height!") );
635 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
637 if ( m_windowVariant
!= variant
)
639 m_windowVariant
= variant
;
641 DoSetWindowVariant(variant
);
645 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
647 // adjust the font height to correspond to our new variant (notice that
648 // we're only called if something really changed)
649 wxFont font
= GetFont();
650 int size
= font
.GetPointSize();
653 case wxWINDOW_VARIANT_NORMAL
:
656 case wxWINDOW_VARIANT_SMALL
:
661 case wxWINDOW_VARIANT_MINI
:
666 case wxWINDOW_VARIANT_LARGE
:
672 wxFAIL_MSG(_T("unexpected window variant"));
676 font
.SetPointSize(size
);
680 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
683 m_minVirtualWidth
= minW
;
684 m_maxVirtualWidth
= maxW
;
685 m_minVirtualHeight
= minH
;
686 m_maxVirtualHeight
= maxH
;
689 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
691 if ( m_minVirtualWidth
!= -1 && m_minVirtualWidth
> x
)
692 x
= m_minVirtualWidth
;
693 if ( m_maxVirtualWidth
!= -1 && m_maxVirtualWidth
< x
)
694 x
= m_maxVirtualWidth
;
695 if ( m_minVirtualHeight
!= -1 && m_minVirtualHeight
> y
)
696 y
= m_minVirtualHeight
;
697 if ( m_maxVirtualHeight
!= -1 && m_maxVirtualHeight
< y
)
698 y
= m_maxVirtualHeight
;
700 m_virtualSize
= wxSize(x
, y
);
703 wxSize
wxWindowBase::DoGetVirtualSize() const
705 wxSize
s( GetClientSize() );
707 return wxSize( wxMax( m_virtualSize
.GetWidth(), s
.GetWidth() ),
708 wxMax( m_virtualSize
.GetHeight(), s
.GetHeight() ) );
711 // ----------------------------------------------------------------------------
712 // show/hide/enable/disable the window
713 // ----------------------------------------------------------------------------
715 bool wxWindowBase::Show(bool show
)
717 if ( show
!= m_isShown
)
729 bool wxWindowBase::Enable(bool enable
)
731 if ( enable
!= m_isEnabled
)
733 m_isEnabled
= enable
;
742 // ----------------------------------------------------------------------------
744 // ----------------------------------------------------------------------------
746 bool wxWindowBase::IsTopLevel() const
751 // ----------------------------------------------------------------------------
752 // reparenting the window
753 // ----------------------------------------------------------------------------
755 void wxWindowBase::AddChild(wxWindowBase
*child
)
757 wxCHECK_RET( child
, wxT("can't add a NULL child") );
759 // this should never happen and it will lead to a crash later if it does
760 // because RemoveChild() will remove only one node from the children list
761 // and the other(s) one(s) will be left with dangling pointers in them
762 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
764 GetChildren().Append((wxWindow
*)child
);
765 child
->SetParent(this);
768 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
770 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
772 GetChildren().DeleteObject((wxWindow
*)child
);
773 child
->SetParent(NULL
);
776 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
778 wxWindow
*oldParent
= GetParent();
779 if ( newParent
== oldParent
)
785 // unlink this window from the existing parent.
788 oldParent
->RemoveChild(this);
792 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
795 // add it to the new one
798 newParent
->AddChild(this);
802 wxTopLevelWindows
.Append((wxWindow
*)this);
808 // ----------------------------------------------------------------------------
809 // event handler stuff
810 // ----------------------------------------------------------------------------
812 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
814 wxEvtHandler
*handlerOld
= GetEventHandler();
816 handler
->SetNextHandler(handlerOld
);
819 GetEventHandler()->SetPreviousHandler(handler
);
821 SetEventHandler(handler
);
824 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
826 wxEvtHandler
*handlerA
= GetEventHandler();
829 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
830 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
833 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
834 SetEventHandler(handlerB
);
839 handlerA
= (wxEvtHandler
*)NULL
;
846 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
848 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
850 wxEvtHandler
*handlerPrev
= NULL
,
851 *handlerCur
= GetEventHandler();
854 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
856 if ( handlerCur
== handler
)
860 handlerPrev
->SetNextHandler(handlerNext
);
864 SetEventHandler(handlerNext
);
869 handlerNext
->SetPreviousHandler ( handlerPrev
);
872 handler
->SetNextHandler(NULL
);
873 handler
->SetPreviousHandler(NULL
);
878 handlerPrev
= handlerCur
;
879 handlerCur
= handlerNext
;
882 wxFAIL_MSG( _T("where has the event handler gone?") );
887 // ----------------------------------------------------------------------------
889 // ----------------------------------------------------------------------------
891 void wxWindowBase::InheritAttributes()
893 const wxWindow
* const parent
= GetParent();
897 // we only inherit attributes which had been explicitly set for the parent
898 // which ensures that this only happens if the user really wants it and
899 // not by default which wouldn't make any sense in modern GUIs where the
900 // controls don't all use the same fonts (nor colours)
901 if ( parent
->m_hasFont
&& !m_hasFont
)
902 SetFont(parent
->GetFont());
904 // in addition, there is a possibility to explicitly forbid inheriting
905 // colours at each class level by overriding ShouldInheritColours()
906 if ( ShouldInheritColours() )
908 if ( parent
->m_hasFgCol
&& !m_hasFgCol
)
909 SetForegroundColour(parent
->GetForegroundColour());
911 if ( parent
->m_hasBgCol
&& !m_hasBgCol
)
912 SetBackgroundColour(parent
->GetBackgroundColour());
916 /* static */ wxVisualAttributes
917 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
919 // it is important to return valid values for all attributes from here,
920 // GetXXX() below rely on this
921 wxVisualAttributes attrs
;
922 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
923 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
924 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
929 wxColour
wxWindowBase::GetBackgroundColour() const
931 if ( !m_backgroundColour
.Ok() )
933 wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") );
935 // get our default background colour
936 wxColour colBg
= GetDefaultAttributes().colBg
;
938 // we must return some valid colour to avoid redoing this every time
939 // and also to avoid surprizing the applications written for older
940 // wxWindows versions where GetBackgroundColour() always returned
941 // something -- so give them something even if it doesn't make sense
942 // for this window (e.g. it has a themed background)
944 colBg
= GetClassDefaultAttributes().colBg
;
946 // cache it for the next call
947 wxConstCast(this, wxWindowBase
)->m_backgroundColour
= colBg
;
950 return m_backgroundColour
;
953 wxColour
wxWindowBase::GetForegroundColour() const
955 // logic is the same as above
956 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
958 wxASSERT_MSG( !m_hasFgCol
, _T("we have invalid explicit fg colour?") );
960 wxColour colFg
= GetDefaultAttributes().colFg
;
963 colFg
= GetClassDefaultAttributes().colFg
;
965 wxConstCast(this, wxWindowBase
)->m_foregroundColour
= colFg
;
968 return m_foregroundColour
;
971 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
973 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
976 m_backgroundColour
= colour
;
983 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
985 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
988 m_foregroundColour
= colour
;
995 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
997 // setting an invalid cursor is ok, it means that we don't have any special
999 if ( m_cursor
== cursor
)
1010 wxFont
& wxWindowBase::DoGetFont() const
1012 // logic is the same as in GetBackgroundColour()
1015 wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") );
1017 wxFont font
= GetDefaultAttributes().font
;
1019 font
= GetClassDefaultAttributes().font
;
1021 wxConstCast(this, wxWindowBase
)->m_font
= font
;
1024 // cast is here for non-const GetFont() convenience
1025 return wxConstCast(this, wxWindowBase
)->m_font
;
1028 bool wxWindowBase::SetFont(const wxFont
& font
)
1033 if ( font
== m_font
)
1048 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1050 m_hasCustomPalette
= true;
1053 // VZ: can anyone explain me what do we do here?
1054 wxWindowDC
d((wxWindow
*) this);
1058 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1060 wxWindow
*win
= (wxWindow
*)this;
1061 while ( win
&& !win
->HasCustomPalette() )
1063 win
= win
->GetParent();
1069 #endif // wxUSE_PALETTE
1072 void wxWindowBase::SetCaret(wxCaret
*caret
)
1083 wxASSERT_MSG( m_caret
->GetWindow() == this,
1084 wxT("caret should be created associated to this window") );
1087 #endif // wxUSE_CARET
1089 #if wxUSE_VALIDATORS
1090 // ----------------------------------------------------------------------------
1092 // ----------------------------------------------------------------------------
1094 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1096 if ( m_windowValidator
)
1097 delete m_windowValidator
;
1099 m_windowValidator
= (wxValidator
*)validator
.Clone();
1101 if ( m_windowValidator
)
1102 m_windowValidator
->SetWindow(this);
1104 #endif // wxUSE_VALIDATORS
1106 // ----------------------------------------------------------------------------
1107 // update region stuff
1108 // ----------------------------------------------------------------------------
1110 wxRect
wxWindowBase::GetUpdateClientRect() const
1112 wxRegion rgnUpdate
= GetUpdateRegion();
1113 rgnUpdate
.Intersect(GetClientRect());
1114 wxRect rectUpdate
= rgnUpdate
.GetBox();
1115 wxPoint ptOrigin
= GetClientAreaOrigin();
1116 rectUpdate
.x
-= ptOrigin
.x
;
1117 rectUpdate
.y
-= ptOrigin
.y
;
1122 bool wxWindowBase::IsExposed(int x
, int y
) const
1124 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1127 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
1129 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1132 void wxWindowBase::ClearBackground()
1134 // wxGTK uses its own version, no need to add never used code
1136 wxClientDC
dc((wxWindow
*)this);
1137 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1138 dc
.SetBackground(brush
);
1143 // ----------------------------------------------------------------------------
1144 // find child window by id or name
1145 // ----------------------------------------------------------------------------
1147 wxWindow
*wxWindowBase::FindWindow( long id
)
1149 if ( id
== m_windowId
)
1150 return (wxWindow
*)this;
1152 wxWindowBase
*res
= (wxWindow
*)NULL
;
1153 wxWindowList::compatibility_iterator node
;
1154 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1156 wxWindowBase
*child
= node
->GetData();
1157 res
= child
->FindWindow( id
);
1160 return (wxWindow
*)res
;
1163 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
1165 if ( name
== m_windowName
)
1166 return (wxWindow
*)this;
1168 wxWindowBase
*res
= (wxWindow
*)NULL
;
1169 wxWindowList::compatibility_iterator node
;
1170 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1172 wxWindow
*child
= node
->GetData();
1173 res
= child
->FindWindow(name
);
1176 return (wxWindow
*)res
;
1180 // find any window by id or name or label: If parent is non-NULL, look through
1181 // children for a label or title matching the specified string. If NULL, look
1182 // through all top-level windows.
1184 // to avoid duplicating code we reuse the same helper function but with
1185 // different comparators
1187 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1188 const wxString
& label
, long id
);
1191 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1194 return win
->GetLabel() == label
;
1198 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1201 return win
->GetName() == label
;
1205 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1208 return win
->GetId() == id
;
1211 // recursive helper for the FindWindowByXXX() functions
1213 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1214 const wxString
& label
,
1216 wxFindWindowCmp cmp
)
1220 // see if this is the one we're looking for
1221 if ( (*cmp
)(parent
, label
, id
) )
1222 return (wxWindow
*)parent
;
1224 // It wasn't, so check all its children
1225 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1227 node
= node
->GetNext() )
1229 // recursively check each child
1230 wxWindow
*win
= (wxWindow
*)node
->GetData();
1231 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1241 // helper for FindWindowByXXX()
1243 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1244 const wxString
& label
,
1246 wxFindWindowCmp cmp
)
1250 // just check parent and all its children
1251 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1254 // start at very top of wx's windows
1255 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1257 node
= node
->GetNext() )
1259 // recursively check each window & its children
1260 wxWindow
*win
= node
->GetData();
1261 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1271 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1273 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1278 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1280 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1284 // fall back to the label
1285 win
= FindWindowByLabel(title
, parent
);
1293 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1295 return wxFindWindowHelper(parent
, _T(""), id
, wxFindWindowCmpIds
);
1298 // ----------------------------------------------------------------------------
1299 // dialog oriented functions
1300 // ----------------------------------------------------------------------------
1302 void wxWindowBase::MakeModal(bool modal
)
1304 // Disable all other windows
1307 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1310 wxWindow
*win
= node
->GetData();
1312 win
->Enable(!modal
);
1314 node
= node
->GetNext();
1319 bool wxWindowBase::Validate()
1321 #if wxUSE_VALIDATORS
1322 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1324 wxWindowList::compatibility_iterator node
;
1325 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1327 wxWindowBase
*child
= node
->GetData();
1328 wxValidator
*validator
= child
->GetValidator();
1329 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1334 if ( recurse
&& !child
->Validate() )
1339 #endif // wxUSE_VALIDATORS
1344 bool wxWindowBase::TransferDataToWindow()
1346 #if wxUSE_VALIDATORS
1347 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1349 wxWindowList::compatibility_iterator node
;
1350 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1352 wxWindowBase
*child
= node
->GetData();
1353 wxValidator
*validator
= child
->GetValidator();
1354 if ( validator
&& !validator
->TransferToWindow() )
1356 wxLogWarning(_("Could not transfer data to window"));
1358 wxLog::FlushActive();
1366 if ( !child
->TransferDataToWindow() )
1368 // warning already given
1373 #endif // wxUSE_VALIDATORS
1378 bool wxWindowBase::TransferDataFromWindow()
1380 #if wxUSE_VALIDATORS
1381 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1383 wxWindowList::compatibility_iterator node
;
1384 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1386 wxWindow
*child
= node
->GetData();
1387 wxValidator
*validator
= child
->GetValidator();
1388 if ( validator
&& !validator
->TransferFromWindow() )
1390 // nop warning here because the application is supposed to give
1391 // one itself - we don't know here what might have gone wrongly
1398 if ( !child
->TransferDataFromWindow() )
1400 // warning already given
1405 #endif // wxUSE_VALIDATORS
1410 void wxWindowBase::InitDialog()
1412 wxInitDialogEvent
event(GetId());
1413 event
.SetEventObject( this );
1414 GetEventHandler()->ProcessEvent(event
);
1417 // ----------------------------------------------------------------------------
1418 // context-sensitive help support
1419 // ----------------------------------------------------------------------------
1423 // associate this help text with this window
1424 void wxWindowBase::SetHelpText(const wxString
& text
)
1426 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1429 helpProvider
->AddHelp(this, text
);
1433 // associate this help text with all windows with the same id as this
1435 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1437 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1440 helpProvider
->AddHelp(GetId(), text
);
1444 // get the help string associated with this window (may be empty)
1445 wxString
wxWindowBase::GetHelpText() const
1448 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1451 text
= helpProvider
->GetHelp(this);
1457 // show help for this window
1458 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1460 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1463 if ( helpProvider
->ShowHelp(this) )
1465 // skip the event.Skip() below
1473 #endif // wxUSE_HELP
1475 // ----------------------------------------------------------------------------
1476 // tooltipsroot.Replace("\\", "/");
1477 // ----------------------------------------------------------------------------
1481 void wxWindowBase::SetToolTip( const wxString
&tip
)
1483 // don't create the new tooltip if we already have one
1486 m_tooltip
->SetTip( tip
);
1490 SetToolTip( new wxToolTip( tip
) );
1493 // setting empty tooltip text does not remove the tooltip any more - use
1494 // SetToolTip((wxToolTip *)NULL) for this
1497 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1502 m_tooltip
= tooltip
;
1505 #endif // wxUSE_TOOLTIPS
1507 // ----------------------------------------------------------------------------
1508 // constraints and sizers
1509 // ----------------------------------------------------------------------------
1511 #if wxUSE_CONSTRAINTS
1513 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1515 if ( m_constraints
)
1517 UnsetConstraints(m_constraints
);
1518 delete m_constraints
;
1520 m_constraints
= constraints
;
1521 if ( m_constraints
)
1523 // Make sure other windows know they're part of a 'meaningful relationship'
1524 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1525 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1526 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1527 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1528 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1529 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1530 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1531 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1532 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1533 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1534 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1535 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1536 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1537 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1538 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1539 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1543 // This removes any dangling pointers to this window in other windows'
1544 // constraintsInvolvedIn lists.
1545 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1549 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1550 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1551 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1552 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1553 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1554 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1555 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1556 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1557 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1558 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1559 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1560 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1561 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1562 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1563 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1564 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1568 // Back-pointer to other windows we're involved with, so if we delete this
1569 // window, we must delete any constraints we're involved with.
1570 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1572 if ( !m_constraintsInvolvedIn
)
1573 m_constraintsInvolvedIn
= new wxWindowList
;
1574 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1575 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1578 // REMOVE back-pointer to other windows we're involved with.
1579 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1581 if ( m_constraintsInvolvedIn
)
1582 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1585 // Reset any constraints that mention this window
1586 void wxWindowBase::DeleteRelatedConstraints()
1588 if ( m_constraintsInvolvedIn
)
1590 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1593 wxWindow
*win
= node
->GetData();
1594 wxLayoutConstraints
*constr
= win
->GetConstraints();
1596 // Reset any constraints involving this window
1599 constr
->left
.ResetIfWin(this);
1600 constr
->top
.ResetIfWin(this);
1601 constr
->right
.ResetIfWin(this);
1602 constr
->bottom
.ResetIfWin(this);
1603 constr
->width
.ResetIfWin(this);
1604 constr
->height
.ResetIfWin(this);
1605 constr
->centreX
.ResetIfWin(this);
1606 constr
->centreY
.ResetIfWin(this);
1609 wxWindowList::compatibility_iterator next
= node
->GetNext();
1610 m_constraintsInvolvedIn
->Erase(node
);
1614 delete m_constraintsInvolvedIn
;
1615 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1619 #endif // wxUSE_CONSTRAINTS
1621 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1623 if ( sizer
== m_windowSizer
)
1627 delete m_windowSizer
;
1629 m_windowSizer
= sizer
;
1631 SetAutoLayout( sizer
!= NULL
);
1634 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1636 SetSizer( sizer
, deleteOld
);
1637 sizer
->SetSizeHints( (wxWindow
*) this );
1640 #if wxUSE_CONSTRAINTS
1642 void wxWindowBase::SatisfyConstraints()
1644 wxLayoutConstraints
*constr
= GetConstraints();
1645 bool wasOk
= constr
&& constr
->AreSatisfied();
1647 ResetConstraints(); // Mark all constraints as unevaluated
1651 // if we're a top level panel (i.e. our parent is frame/dialog), our
1652 // own constraints will never be satisfied any more unless we do it
1656 while ( noChanges
> 0 )
1658 LayoutPhase1(&noChanges
);
1662 LayoutPhase2(&noChanges
);
1665 #endif // wxUSE_CONSTRAINTS
1667 bool wxWindowBase::Layout()
1669 // If there is a sizer, use it instead of the constraints
1673 GetVirtualSize(&w
, &h
);
1674 GetSizer()->SetDimension( 0, 0, w
, h
);
1676 #if wxUSE_CONSTRAINTS
1679 SatisfyConstraints(); // Find the right constraints values
1680 SetConstraintSizes(); // Recursively set the real window sizes
1687 #if wxUSE_CONSTRAINTS
1689 // first phase of the constraints evaluation: set our own constraints
1690 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1692 wxLayoutConstraints
*constr
= GetConstraints();
1694 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1697 // second phase: set the constraints for our children
1698 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1705 // Layout grand children
1711 // Do a phase of evaluating child constraints
1712 bool wxWindowBase::DoPhase(int phase
)
1714 // the list containing the children for which the constraints are already
1716 wxWindowList succeeded
;
1718 // the max number of iterations we loop before concluding that we can't set
1720 static const int maxIterations
= 500;
1722 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1726 // loop over all children setting their constraints
1727 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1729 node
= node
->GetNext() )
1731 wxWindow
*child
= node
->GetData();
1732 if ( child
->IsTopLevel() )
1734 // top level children are not inside our client area
1738 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1740 // this one is either already ok or nothing we can do about it
1744 int tempNoChanges
= 0;
1745 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1746 : child
->LayoutPhase2(&tempNoChanges
);
1747 noChanges
+= tempNoChanges
;
1751 succeeded
.Append(child
);
1757 // constraints are set
1765 void wxWindowBase::ResetConstraints()
1767 wxLayoutConstraints
*constr
= GetConstraints();
1770 constr
->left
.SetDone(false);
1771 constr
->top
.SetDone(false);
1772 constr
->right
.SetDone(false);
1773 constr
->bottom
.SetDone(false);
1774 constr
->width
.SetDone(false);
1775 constr
->height
.SetDone(false);
1776 constr
->centreX
.SetDone(false);
1777 constr
->centreY
.SetDone(false);
1780 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1783 wxWindow
*win
= node
->GetData();
1784 if ( !win
->IsTopLevel() )
1785 win
->ResetConstraints();
1786 node
= node
->GetNext();
1790 // Need to distinguish between setting the 'fake' size for windows and sizers,
1791 // and setting the real values.
1792 void wxWindowBase::SetConstraintSizes(bool recurse
)
1794 wxLayoutConstraints
*constr
= GetConstraints();
1795 if ( constr
&& constr
->AreSatisfied() )
1797 int x
= constr
->left
.GetValue();
1798 int y
= constr
->top
.GetValue();
1799 int w
= constr
->width
.GetValue();
1800 int h
= constr
->height
.GetValue();
1802 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1803 (constr
->height
.GetRelationship() != wxAsIs
) )
1805 SetSize(x
, y
, w
, h
);
1809 // If we don't want to resize this window, just move it...
1815 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1816 GetClassInfo()->GetClassName(),
1822 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1825 wxWindow
*win
= node
->GetData();
1826 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1827 win
->SetConstraintSizes();
1828 node
= node
->GetNext();
1833 // Only set the size/position of the constraint (if any)
1834 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1836 wxLayoutConstraints
*constr
= GetConstraints();
1841 constr
->left
.SetValue(x
);
1842 constr
->left
.SetDone(true);
1846 constr
->top
.SetValue(y
);
1847 constr
->top
.SetDone(true);
1851 constr
->width
.SetValue(w
);
1852 constr
->width
.SetDone(true);
1856 constr
->height
.SetValue(h
);
1857 constr
->height
.SetDone(true);
1862 void wxWindowBase::MoveConstraint(int x
, int y
)
1864 wxLayoutConstraints
*constr
= GetConstraints();
1869 constr
->left
.SetValue(x
);
1870 constr
->left
.SetDone(true);
1874 constr
->top
.SetValue(y
);
1875 constr
->top
.SetDone(true);
1880 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1882 wxLayoutConstraints
*constr
= GetConstraints();
1885 *w
= constr
->width
.GetValue();
1886 *h
= constr
->height
.GetValue();
1892 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1894 wxLayoutConstraints
*constr
= GetConstraints();
1897 *w
= constr
->width
.GetValue();
1898 *h
= constr
->height
.GetValue();
1901 GetClientSize(w
, h
);
1904 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1906 wxLayoutConstraints
*constr
= GetConstraints();
1909 *x
= constr
->left
.GetValue();
1910 *y
= constr
->top
.GetValue();
1916 #endif // wxUSE_CONSTRAINTS
1918 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
1920 // don't do it for the dialogs/frames - they float independently of their
1922 if ( !IsTopLevel() )
1924 wxWindow
*parent
= GetParent();
1925 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
1927 wxPoint
pt(parent
->GetClientAreaOrigin());
1934 // ----------------------------------------------------------------------------
1935 // do Update UI processing for child controls
1936 // ----------------------------------------------------------------------------
1938 void wxWindowBase::UpdateWindowUI(long flags
)
1940 wxUpdateUIEvent
event(GetId());
1941 event
.m_eventObject
= this;
1943 if ( GetEventHandler()->ProcessEvent(event
) )
1945 DoUpdateWindowUI(event
);
1948 if (flags
& wxUPDATE_UI_RECURSE
)
1950 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1953 wxWindow
* child
= (wxWindow
*) node
->GetData();
1954 child
->UpdateWindowUI(flags
);
1955 node
= node
->GetNext();
1960 // do the window-specific processing after processing the update event
1961 // TODO: take specific knowledge out of this function and
1962 // put in each control's base class. Unfortunately we don't
1963 // yet have base implementation files for wxCheckBox and wxRadioButton.
1964 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
1966 if ( event
.GetSetEnabled() )
1967 Enable(event
.GetEnabled());
1970 if ( event
.GetSetText() )
1972 wxControl
*control
= wxDynamicCastThis(wxControl
);
1975 if ( event
.GetText() != control
->GetLabel() )
1976 control
->SetLabel(event
.GetText());
1979 wxCheckBox
*checkbox
= wxDynamicCastThis(wxCheckBox
);
1982 if ( event
.GetSetChecked() )
1983 checkbox
->SetValue(event
.GetChecked());
1985 #endif // wxUSE_CHECKBOX
1988 wxRadioButton
*radiobtn
= wxDynamicCastThis(wxRadioButton
);
1991 if ( event
.GetSetChecked() )
1992 radiobtn
->SetValue(event
.GetChecked());
1994 #endif // wxUSE_RADIOBTN
2000 // call internal idle recursively
2001 // may be obsolete (wait until OnIdle scheme stabilises)
2002 void wxWindowBase::ProcessInternalIdle()
2006 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2009 wxWindow
*child
= node
->GetData();
2010 child
->ProcessInternalIdle();
2011 node
= node
->GetNext();
2016 // ----------------------------------------------------------------------------
2017 // dialog units translations
2018 // ----------------------------------------------------------------------------
2020 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
2022 int charWidth
= GetCharWidth();
2023 int charHeight
= GetCharHeight();
2024 wxPoint
pt2(-1, -1);
2026 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
2028 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2033 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
2035 int charWidth
= GetCharWidth();
2036 int charHeight
= GetCharHeight();
2037 wxPoint
pt2(-1, -1);
2039 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
2041 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2046 // ----------------------------------------------------------------------------
2048 // ----------------------------------------------------------------------------
2050 // propagate the colour change event to the subwindows
2051 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2053 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2056 // Only propagate to non-top-level windows
2057 wxWindow
*win
= node
->GetData();
2058 if ( !win
->IsTopLevel() )
2060 wxSysColourChangedEvent event2
;
2061 event
.m_eventObject
= win
;
2062 win
->GetEventHandler()->ProcessEvent(event2
);
2065 node
= node
->GetNext();
2069 // the default action is to populate dialog with data when it's created,
2070 // and nudge the UI into displaying itself correctly in case
2071 // we've turned the wxUpdateUIEvents frequency down low.
2072 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2074 TransferDataToWindow();
2076 // Update the UI at this point
2077 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2080 // process Ctrl-Alt-mclick
2081 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2084 if ( event
.ControlDown() && event
.AltDown() )
2086 // don't translate these strings
2089 #ifdef __WXUNIVERSAL__
2091 #endif // __WXUNIVERSAL__
2093 switch ( wxGetOsVersion() )
2095 case wxMOTIF_X
: port
+= _T("Motif"); break;
2097 case wxMAC_DARWIN
: port
+= _T("Mac"); break;
2098 case wxBEOS
: port
+= _T("BeOS"); break;
2102 case wxGTK_BEOS
: port
+= _T("GTK"); break;
2108 case wxWIN386
: port
+= _T("MS Windows"); break;
2112 case wxMGL_OS2
: port
+= _T("MGL"); break;
2114 case wxOS2_PM
: port
+= _T("OS/2"); break;
2115 default: port
+= _T("unknown"); break;
2118 wxMessageBox(wxString::Format(
2120 " wxWindows Library (%s port)\nVersion %u.%u.%u%s, compiled at %s %s\n Copyright (c) 1995-2002 wxWindows team"
2134 _T("wxWindows information"),
2135 wxICON_INFORMATION
| wxOK
,
2139 #endif // wxUSE_MSGDLG
2145 // ----------------------------------------------------------------------------
2147 // ----------------------------------------------------------------------------
2149 #if wxUSE_ACCESSIBILITY
2150 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2152 if (m_accessible
&& (accessible
!= m_accessible
))
2153 delete m_accessible
;
2154 m_accessible
= accessible
;
2156 m_accessible
->SetWindow((wxWindow
*) this);
2159 // Returns the accessible object, creating if necessary.
2160 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2163 m_accessible
= CreateAccessible();
2164 return m_accessible
;
2167 // Override to create a specific accessible object.
2168 wxAccessible
* wxWindowBase::CreateAccessible()
2170 return new wxWindowAccessible((wxWindow
*) this);
2176 // ----------------------------------------------------------------------------
2177 // list classes implementation
2178 // ----------------------------------------------------------------------------
2180 void wxWindowListNode::DeleteData()
2182 delete (wxWindow
*)GetData();
2186 // ----------------------------------------------------------------------------
2188 // ----------------------------------------------------------------------------
2190 wxBorder
wxWindowBase::GetBorder(long flags
) const
2192 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2193 if ( border
== wxBORDER_DEFAULT
)
2195 border
= GetDefaultBorder();
2201 wxBorder
wxWindowBase::GetDefaultBorder() const
2203 return wxBORDER_NONE
;
2206 // ----------------------------------------------------------------------------
2208 // ----------------------------------------------------------------------------
2210 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2212 // here we just check if the point is inside the window or not
2214 // check the top and left border first
2215 bool outside
= x
< 0 || y
< 0;
2218 // check the right and bottom borders too
2219 wxSize size
= GetSize();
2220 outside
= x
>= size
.x
|| y
>= size
.y
;
2223 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2226 // ----------------------------------------------------------------------------
2228 // ----------------------------------------------------------------------------
2230 struct WXDLLEXPORT wxWindowNext
2234 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2236 void wxWindowBase::CaptureMouse()
2238 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this);
2240 wxWindow
*winOld
= GetCapture();
2243 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2246 wxWindowNext
*item
= new wxWindowNext
;
2248 item
->next
= ms_winCaptureNext
;
2249 ms_winCaptureNext
= item
;
2251 //else: no mouse capture to save
2256 void wxWindowBase::ReleaseMouse()
2258 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this);
2260 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2264 if ( ms_winCaptureNext
)
2266 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2268 wxWindowNext
*item
= ms_winCaptureNext
;
2269 ms_winCaptureNext
= item
->next
;
2272 //else: stack is empty, no previous capture
2274 wxLogTrace(_T("mousecapture"),
2275 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2282 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2283 int WXUNUSED(modifiers
),
2284 int WXUNUSED(keycode
))
2290 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2296 #endif // wxUSE_HOTKEY
2298 void wxWindowBase::SendDestroyEvent()
2300 wxWindowDestroyEvent event
;
2301 event
.SetEventObject(this);
2302 event
.SetId(GetId());
2303 GetEventHandler()->ProcessEvent(event
);
2306 // ----------------------------------------------------------------------------
2308 // ----------------------------------------------------------------------------
2310 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2312 #if wxUSE_VALIDATORS
2313 // Can only use the validator of the window which
2314 // is receiving the event
2315 if ( event
.GetEventObject() == this )
2317 wxValidator
*validator
= GetValidator();
2318 if ( validator
&& validator
->ProcessEvent(event
) )
2323 #endif // wxUSE_VALIDATORS
2328 bool wxWindowBase::TryParent(wxEvent
& event
)
2330 // carry on up the parent-child hierarchy if the propgation count hasn't
2332 if ( event
.ShouldPropagate() )
2334 // honour the requests to stop propagation at this window: this is
2335 // used by the dialogs, for example, to prevent processing the events
2336 // from the dialog controls in the parent frame which rarely, if ever,
2338 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2340 wxWindow
*parent
= GetParent();
2341 if ( parent
&& !parent
->IsBeingDeleted() )
2343 wxPropagateOnce
propagateOnce(event
);
2345 return parent
->GetEventHandler()->ProcessEvent(event
);
2350 return wxEvtHandler::TryParent(event
);
2353 // ----------------------------------------------------------------------------
2355 // ----------------------------------------------------------------------------
2357 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2359 while ( win
&& !win
->IsTopLevel() )
2360 win
= win
->GetParent();
2365 #if wxUSE_ACCESSIBILITY
2366 // ----------------------------------------------------------------------------
2367 // accessible object for windows
2368 // ----------------------------------------------------------------------------
2370 // Can return either a child object, or an integer
2371 // representing the child element, starting from 1.
2372 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2374 wxASSERT( GetWindow() != NULL
);
2378 return wxACC_NOT_IMPLEMENTED
;
2381 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2382 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2384 wxASSERT( GetWindow() != NULL
);
2388 wxWindow
* win
= NULL
;
2395 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2397 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2404 rect
= win
->GetRect();
2405 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2406 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2410 return wxACC_NOT_IMPLEMENTED
;
2413 // Navigates from fromId to toId/toObject.
2414 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2415 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2417 wxASSERT( GetWindow() != NULL
);
2423 case wxNAVDIR_FIRSTCHILD
:
2425 if (GetWindow()->GetChildren().GetCount() == 0)
2427 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2428 *toObject
= childWindow
->GetOrCreateAccessible();
2432 case wxNAVDIR_LASTCHILD
:
2434 if (GetWindow()->GetChildren().GetCount() == 0)
2436 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2437 *toObject
= childWindow
->GetOrCreateAccessible();
2441 case wxNAVDIR_RIGHT
:
2445 wxWindowList::compatibility_iterator node
=
2446 wxWindowList::compatibility_iterator();
2449 // Can't navigate to sibling of this window
2450 // if we're a top-level window.
2451 if (!GetWindow()->GetParent())
2452 return wxACC_NOT_IMPLEMENTED
;
2454 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2458 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2459 node
= GetWindow()->GetChildren().Item(fromId
-1);
2462 if (node
&& node
->GetNext())
2464 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2465 *toObject
= nextWindow
->GetOrCreateAccessible();
2473 case wxNAVDIR_PREVIOUS
:
2475 wxWindowList::compatibility_iterator node
=
2476 wxWindowList::compatibility_iterator();
2479 // Can't navigate to sibling of this window
2480 // if we're a top-level window.
2481 if (!GetWindow()->GetParent())
2482 return wxACC_NOT_IMPLEMENTED
;
2484 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2488 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2489 node
= GetWindow()->GetChildren().Item(fromId
-1);
2492 if (node
&& node
->GetPrevious())
2494 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2495 *toObject
= previousWindow
->GetOrCreateAccessible();
2503 return wxACC_NOT_IMPLEMENTED
;
2506 // Gets the name of the specified object.
2507 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2509 wxASSERT( GetWindow() != NULL
);
2515 // If a child, leave wxWindows to call the function on the actual
2518 return wxACC_NOT_IMPLEMENTED
;
2520 // This will eventually be replaced by specialised
2521 // accessible classes, one for each kind of wxWindows
2522 // control or window.
2523 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2524 title
= ((wxButton
*) GetWindow())->GetLabel();
2526 title
= GetWindow()->GetName();
2528 if (!title
.IsEmpty())
2534 return wxACC_NOT_IMPLEMENTED
;
2537 // Gets the number of children.
2538 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2540 wxASSERT( GetWindow() != NULL
);
2544 *childId
= (int) GetWindow()->GetChildren().GetCount();
2548 // Gets the specified child (starting from 1).
2549 // If *child is NULL and return value is wxACC_OK,
2550 // this means that the child is a simple element and
2551 // not an accessible object.
2552 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2554 wxASSERT( GetWindow() != NULL
);
2564 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2567 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2568 *child
= childWindow
->GetOrCreateAccessible();
2575 // Gets the parent, or NULL.
2576 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2578 wxASSERT( GetWindow() != NULL
);
2582 wxWindow
* parentWindow
= GetWindow()->GetParent();
2590 *parent
= parentWindow
->GetOrCreateAccessible();
2598 // Performs the default action. childId is 0 (the action for this object)
2599 // or > 0 (the action for a child).
2600 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2601 // window (e.g. an edit control).
2602 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
2604 wxASSERT( GetWindow() != NULL
);
2608 return wxACC_NOT_IMPLEMENTED
;
2611 // Gets the default action for this object (0) or > 0 (the action for a child).
2612 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2613 // string if there is no action.
2614 // The retrieved string describes the action that is performed on an object,
2615 // not what the object does as a result. For example, a toolbar button that prints
2616 // a document has a default action of "Press" rather than "Prints the current document."
2617 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
2619 wxASSERT( GetWindow() != NULL
);
2623 return wxACC_NOT_IMPLEMENTED
;
2626 // Returns the description for this object or a child.
2627 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
2629 wxASSERT( GetWindow() != NULL
);
2633 wxString
ht(GetWindow()->GetHelpText());
2639 return wxACC_NOT_IMPLEMENTED
;
2642 // Returns help text for this object or a child, similar to tooltip text.
2643 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
2645 wxASSERT( GetWindow() != NULL
);
2649 wxString
ht(GetWindow()->GetHelpText());
2655 return wxACC_NOT_IMPLEMENTED
;
2658 // Returns the keyboard shortcut for this object or child.
2659 // Return e.g. ALT+K
2660 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
2662 wxASSERT( GetWindow() != NULL
);
2666 return wxACC_NOT_IMPLEMENTED
;
2669 // Returns a role constant.
2670 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
2672 wxASSERT( GetWindow() != NULL
);
2676 // If a child, leave wxWindows to call the function on the actual
2679 return wxACC_NOT_IMPLEMENTED
;
2681 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2682 return wxACC_NOT_IMPLEMENTED
;
2684 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2685 return wxACC_NOT_IMPLEMENTED
;
2688 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2689 return wxACC_NOT_IMPLEMENTED
;
2692 //*role = wxROLE_SYSTEM_CLIENT;
2693 *role
= wxROLE_SYSTEM_CLIENT
;
2697 return wxACC_NOT_IMPLEMENTED
;
2701 // Returns a state constant.
2702 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
2704 wxASSERT( GetWindow() != NULL
);
2708 // If a child, leave wxWindows to call the function on the actual
2711 return wxACC_NOT_IMPLEMENTED
;
2713 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2714 return wxACC_NOT_IMPLEMENTED
;
2717 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2718 return wxACC_NOT_IMPLEMENTED
;
2721 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2722 return wxACC_NOT_IMPLEMENTED
;
2729 return wxACC_NOT_IMPLEMENTED
;
2733 // Returns a localized string representing the value for the object
2735 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
2737 wxASSERT( GetWindow() != NULL
);
2741 return wxACC_NOT_IMPLEMENTED
;
2744 // Selects the object or child.
2745 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
2747 wxASSERT( GetWindow() != NULL
);
2751 return wxACC_NOT_IMPLEMENTED
;
2754 // Gets the window with the keyboard focus.
2755 // If childId is 0 and child is NULL, no object in
2756 // this subhierarchy has the focus.
2757 // If this object has the focus, child should be 'this'.
2758 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
2760 wxASSERT( GetWindow() != NULL
);
2764 return wxACC_NOT_IMPLEMENTED
;
2767 // Gets a variant representing the selected children
2769 // Acceptable values:
2770 // - a null variant (IsNull() returns TRUE)
2771 // - a list variant (GetType() == wxT("list")
2772 // - an integer representing the selected child element,
2773 // or 0 if this object is selected (GetType() == wxT("long")
2774 // - a "void*" pointer to a wxAccessible child object
2775 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
2777 wxASSERT( GetWindow() != NULL
);
2781 return wxACC_NOT_IMPLEMENTED
;
2784 #endif // wxUSE_ACCESSIBILITY