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
),
197 const wxSize
& WXUNUSED(size
),
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
);
227 SetValidator(validator
);
228 #endif // wxUSE_VALIDATORS
230 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
231 // have it too - like this it's possible to set it only in the top level
232 // dialog/frame and all children will inherit it by defult
233 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
235 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
241 // ----------------------------------------------------------------------------
243 // ----------------------------------------------------------------------------
246 wxWindowBase::~wxWindowBase()
248 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
250 // FIXME if these 2 cases result from programming errors in the user code
251 // we should probably assert here instead of silently fixing them
253 // Just in case the window has been Closed, but we're then deleting
254 // immediately: don't leave dangling pointers.
255 wxPendingDelete
.DeleteObject(this);
257 // Just in case we've loaded a top-level window via LoadNativeDialog but
258 // we weren't a dialog class
259 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
261 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
263 // reset the dangling pointer our parent window may keep to us
266 if ( m_parent
->GetDefaultItem() == this )
268 m_parent
->SetDefaultItem(NULL
);
271 m_parent
->RemoveChild(this);
276 #endif // wxUSE_CARET
279 delete m_windowValidator
;
280 #endif // wxUSE_VALIDATORS
282 #if wxUSE_CONSTRAINTS
283 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
284 // at deleted windows as they delete themselves.
285 DeleteRelatedConstraints();
289 // This removes any dangling pointers to this window in other windows'
290 // constraintsInvolvedIn lists.
291 UnsetConstraints(m_constraints
);
292 delete m_constraints
;
293 m_constraints
= NULL
;
295 #endif // wxUSE_CONSTRAINTS
297 if ( m_containingSizer
)
298 m_containingSizer
->Detach( (wxWindow
*)this );
300 delete m_windowSizer
;
302 #if wxUSE_DRAG_AND_DROP
304 #endif // wxUSE_DRAG_AND_DROP
308 #endif // wxUSE_TOOLTIPS
310 #if wxUSE_ACCESSIBILITY
315 bool wxWindowBase::Destroy()
322 bool wxWindowBase::Close(bool force
)
324 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
325 event
.SetEventObject(this);
326 event
.SetCanVeto(!force
);
328 // return false if window wasn't closed because the application vetoed the
330 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
333 bool wxWindowBase::DestroyChildren()
335 wxWindowList::compatibility_iterator node
;
338 // we iterate until the list becomes empty
339 node
= GetChildren().GetFirst();
343 wxWindow
*child
= node
->GetData();
345 // note that we really want to call delete and not ->Destroy() here
346 // because we want to delete the child immediately, before we are
347 // deleted, and delayed deletion would result in problems as our (top
348 // level) child could outlive its parent
351 wxASSERT_MSG( !GetChildren().Find(child
),
352 wxT("child didn't remove itself using RemoveChild()") );
358 // ----------------------------------------------------------------------------
359 // size/position related methods
360 // ----------------------------------------------------------------------------
362 // centre the window with respect to its parent in either (or both) directions
363 void wxWindowBase::Centre(int direction
)
365 // the position/size of the parent window or of the entire screen
367 int widthParent
, heightParent
;
369 wxWindow
*parent
= NULL
;
371 if ( !(direction
& wxCENTRE_ON_SCREEN
) )
373 // find the parent to centre this window on: it should be the
374 // immediate parent for the controls but the top level parent for the
375 // top level windows (like dialogs)
376 parent
= GetParent();
379 while ( parent
&& !parent
->IsTopLevel() )
381 parent
= parent
->GetParent();
385 // there is no wxTopLevelWindow under wxMotif yet
387 // we shouldn't center the dialog on the iconized window: under
388 // Windows, for example, this places it completely off the screen
391 wxTopLevelWindow
*winTop
= wxDynamicCast(parent
, wxTopLevelWindow
);
392 if ( winTop
&& winTop
->IsIconized() )
397 #endif // __WXMOTIF__
399 // did we find the parent?
403 direction
|= wxCENTRE_ON_SCREEN
;
407 if ( direction
& wxCENTRE_ON_SCREEN
)
409 // centre with respect to the whole screen
410 wxDisplaySize(&widthParent
, &heightParent
);
416 // centre on the parent
417 parent
->GetSize(&widthParent
, &heightParent
);
419 // adjust to the parents position
420 posParent
= parent
->GetPosition();
424 // centre inside the parents client rectangle
425 parent
->GetClientSize(&widthParent
, &heightParent
);
430 GetSize(&width
, &height
);
435 if ( direction
& wxHORIZONTAL
)
436 xNew
= (widthParent
- width
)/2;
438 if ( direction
& wxVERTICAL
)
439 yNew
= (heightParent
- height
)/2;
444 // Base size of the visible dimensions of the display
445 // to take into account the taskbar
446 wxRect rect
= wxGetClientDisplayRect();
447 wxSize
size (rect
.width
,rect
.height
);
449 // NB: in wxMSW, negative position may not neccessary mean "out of screen",
450 // but it may mean that the window is placed on other than the main
451 // display. Therefore we only make sure centered window is on the main display
452 // if the parent is at least partially present here.
453 if (posParent
.x
+ widthParent
>= 0) // if parent is (partially) on the main display
457 else if (xNew
+width
> size
.x
)
458 xNew
= size
.x
-width
-1;
460 if (posParent
.y
+ heightParent
>= 0) // if parent is (partially) on the main display
462 if (yNew
+height
> size
.y
)
463 yNew
= size
.y
-height
-1;
465 // Make certain that the title bar is initially visible
466 // always, even if this would push the bottom of the
467 // dialog of the visible area of the display
472 // move the window to this position (keeping the old size but using
473 // SetSize() and not Move() to allow xNew and/or yNew to be -1)
474 SetSize(xNew
, yNew
, width
, height
, wxSIZE_ALLOW_MINUS_ONE
);
477 // fits the window around the children
478 void wxWindowBase::Fit()
480 if ( GetChildren().GetCount() > 0 )
482 SetClientSize(DoGetBestSize());
484 //else: do nothing if we have no children
487 // fits virtual size (ie. scrolled area etc.) around children
488 void wxWindowBase::FitInside()
490 if ( GetChildren().GetCount() > 0 )
492 SetVirtualSize( GetBestVirtualSize() );
496 // return the size best suited for the current window
497 wxSize
wxWindowBase::DoGetBestSize() const
501 return m_windowSizer
->GetMinSize();
503 #if wxUSE_CONSTRAINTS
504 else if ( m_constraints
)
506 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
508 // our minimal acceptable size is such that all our windows fit inside
512 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
514 node
= node
->GetNext() )
516 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
519 // it's not normal that we have an unconstrained child, but
520 // what can we do about it?
524 int x
= c
->right
.GetValue(),
525 y
= c
->bottom
.GetValue();
533 // TODO: we must calculate the overlaps somehow, otherwise we
534 // will never return a size bigger than the current one :-(
537 return wxSize(maxX
, maxY
);
539 #endif // wxUSE_CONSTRAINTS
540 else if ( GetChildren().GetCount() > 0 )
542 // our minimal acceptable size is such that all our windows fit inside
546 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
548 node
= node
->GetNext() )
550 wxWindow
*win
= node
->GetData();
551 if ( win
->IsTopLevel()
553 || wxDynamicCast(win
, wxStatusBar
)
554 #endif // wxUSE_STATUSBAR
557 // dialogs and frames lie in different top level windows -
558 // don't deal with them here; as for the status bars, they
559 // don't lie in the client area at all
564 win
->GetPosition(&wx
, &wy
);
566 // if the window hadn't been positioned yet, assume that it is in
573 win
->GetSize(&ww
, &wh
);
574 if ( wx
+ ww
> maxX
)
576 if ( wy
+ wh
> maxY
)
580 // for compatibility with the old versions and because it really looks
581 // slightly more pretty like this, add a pad
585 return wxSize(maxX
, maxY
);
589 // Windows which don't implement DoGetBestSize and aren't parents.
590 // This emulates the behavior of a wxSizer without wxADJUST_MINSIZE
592 // If you get the following message you should do one of two things
593 // 1. Do what it says (best)
594 // 2. m_bestSize = GetSize() at end of Create() (hack)
595 if(m_bestSize
== wxDefaultSize
)
597 wxLogDebug(wxT("Class %s (or superclass) should implement DoGetBestSize()"),GetClassInfo()->GetClassName());
598 wxConstCast(this,wxWindowBase
)->m_bestSize
= GetSize();
604 // by default the origin is not shifted
605 wxPoint
wxWindowBase::GetClientAreaOrigin() const
607 return wxPoint(0, 0);
610 // set the min/max size of the window
611 void wxWindowBase::SetSizeHints(int minW
, int minH
,
613 int WXUNUSED(incW
), int WXUNUSED(incH
))
615 // setting min width greater than max width leads to infinite loops under
616 // X11 and generally doesn't make any sense, so don't allow it
617 wxCHECK_RET( (minW
== -1 || maxW
== -1 || minW
<= maxW
) &&
618 (minH
== -1 || maxH
== -1 || minH
<= maxH
),
619 _T("min width/height must be less than max width/height!") );
627 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
629 if ( m_windowVariant
!= variant
)
631 m_windowVariant
= variant
;
633 DoSetWindowVariant(variant
);
637 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
639 // adjust the font height to correspond to our new variant (notice that
640 // we're only called if something really changed)
641 wxFont font
= GetFont();
642 int size
= font
.GetPointSize();
645 case wxWINDOW_VARIANT_NORMAL
:
648 case wxWINDOW_VARIANT_SMALL
:
653 case wxWINDOW_VARIANT_MINI
:
658 case wxWINDOW_VARIANT_LARGE
:
664 wxFAIL_MSG(_T("unexpected window variant"));
668 font
.SetPointSize(size
);
672 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
675 m_minVirtualWidth
= minW
;
676 m_maxVirtualWidth
= maxW
;
677 m_minVirtualHeight
= minH
;
678 m_maxVirtualHeight
= maxH
;
681 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
683 if ( m_minVirtualWidth
!= -1 && m_minVirtualWidth
> x
)
684 x
= m_minVirtualWidth
;
685 if ( m_maxVirtualWidth
!= -1 && m_maxVirtualWidth
< x
)
686 x
= m_maxVirtualWidth
;
687 if ( m_minVirtualHeight
!= -1 && m_minVirtualHeight
> y
)
688 y
= m_minVirtualHeight
;
689 if ( m_maxVirtualHeight
!= -1 && m_maxVirtualHeight
< y
)
690 y
= m_maxVirtualHeight
;
692 m_virtualSize
= wxSize(x
, y
);
695 wxSize
wxWindowBase::DoGetVirtualSize() const
697 wxSize
s( GetClientSize() );
699 return wxSize( wxMax( m_virtualSize
.GetWidth(), s
.GetWidth() ),
700 wxMax( m_virtualSize
.GetHeight(), s
.GetHeight() ) );
703 // ----------------------------------------------------------------------------
704 // show/hide/enable/disable the window
705 // ----------------------------------------------------------------------------
707 bool wxWindowBase::Show(bool show
)
709 if ( show
!= m_isShown
)
721 bool wxWindowBase::Enable(bool enable
)
723 if ( enable
!= m_isEnabled
)
725 m_isEnabled
= enable
;
734 // ----------------------------------------------------------------------------
736 // ----------------------------------------------------------------------------
738 bool wxWindowBase::IsTopLevel() const
743 // ----------------------------------------------------------------------------
744 // reparenting the window
745 // ----------------------------------------------------------------------------
747 void wxWindowBase::AddChild(wxWindowBase
*child
)
749 wxCHECK_RET( child
, wxT("can't add a NULL child") );
751 // this should never happen and it will lead to a crash later if it does
752 // because RemoveChild() will remove only one node from the children list
753 // and the other(s) one(s) will be left with dangling pointers in them
754 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
756 GetChildren().Append((wxWindow
*)child
);
757 child
->SetParent(this);
760 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
762 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
764 GetChildren().DeleteObject((wxWindow
*)child
);
765 child
->SetParent(NULL
);
768 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
770 wxWindow
*oldParent
= GetParent();
771 if ( newParent
== oldParent
)
777 // unlink this window from the existing parent.
780 oldParent
->RemoveChild(this);
784 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
787 // add it to the new one
790 newParent
->AddChild(this);
794 wxTopLevelWindows
.Append((wxWindow
*)this);
800 // ----------------------------------------------------------------------------
801 // event handler stuff
802 // ----------------------------------------------------------------------------
804 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
806 wxEvtHandler
*handlerOld
= GetEventHandler();
808 handler
->SetNextHandler(handlerOld
);
811 GetEventHandler()->SetPreviousHandler(handler
);
813 SetEventHandler(handler
);
816 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
818 wxEvtHandler
*handlerA
= GetEventHandler();
821 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
822 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
825 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
826 SetEventHandler(handlerB
);
831 handlerA
= (wxEvtHandler
*)NULL
;
838 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
840 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
842 wxEvtHandler
*handlerPrev
= NULL
,
843 *handlerCur
= GetEventHandler();
846 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
848 if ( handlerCur
== handler
)
852 handlerPrev
->SetNextHandler(handlerNext
);
856 SetEventHandler(handlerNext
);
861 handlerNext
->SetPreviousHandler ( handlerPrev
);
864 handler
->SetNextHandler(NULL
);
865 handler
->SetPreviousHandler(NULL
);
870 handlerPrev
= handlerCur
;
871 handlerCur
= handlerNext
;
874 wxFAIL_MSG( _T("where has the event handler gone?") );
879 // ----------------------------------------------------------------------------
881 // ----------------------------------------------------------------------------
883 /* static */ wxVisualAttributes
884 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
886 // it is important to return valid values for all attributes from here,
887 // GetXXX() below rely on this
888 wxVisualAttributes attrs
;
889 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
890 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
891 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
896 wxColour
wxWindowBase::GetBackgroundColour() const
898 if ( !m_backgroundColour
.Ok() )
900 wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") );
902 // get our default background colour
903 wxColour colBg
= GetDefaultAttributes().colBg
;
905 // we must return some valid colour to avoid redoing this every time
906 // and also to avoid surprizing the applications written for older
907 // wxWindows versions where GetBackgroundColour() always returned
908 // something -- so give them something even if it doesn't make sense
909 // for this window (e.g. it has a themed background)
911 colBg
= GetClassDefaultAttributes().colBg
;
913 // cache it for the next call
914 wxConstCast(this, wxWindowBase
)->m_backgroundColour
= colBg
;
917 return m_backgroundColour
;
920 wxColour
wxWindowBase::GetForegroundColour() const
922 // logic is the same as above
923 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
925 wxASSERT_MSG( !m_hasFgCol
, _T("we have invalid explicit fg colour?") );
927 wxColour colFg
= GetDefaultAttributes().colFg
;
930 colFg
= GetClassDefaultAttributes().colFg
;
932 wxConstCast(this, wxWindowBase
)->m_foregroundColour
= colFg
;
935 return m_foregroundColour
;
938 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
940 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
943 m_backgroundColour
= colour
;
950 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
952 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
955 m_foregroundColour
= colour
;
962 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
964 // setting an invalid cursor is ok, it means that we don't have any special
966 if ( m_cursor
== cursor
)
977 wxFont
& wxWindowBase::DoGetFont() const
979 // logic is the same as in GetBackgroundColour()
982 wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") );
984 wxFont font
= GetDefaultAttributes().font
;
986 font
= GetClassDefaultAttributes().font
;
988 wxConstCast(this, wxWindowBase
)->m_font
= font
;
991 // cast is here for non-const GetFont() convenience
992 return wxConstCast(this, wxWindowBase
)->m_font
;
995 bool wxWindowBase::SetFont(const wxFont
& font
)
1000 if ( font
== m_font
)
1015 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1017 m_hasCustomPalette
= true;
1020 // VZ: can anyone explain me what do we do here?
1021 wxWindowDC
d((wxWindow
*) this);
1025 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1027 wxWindow
*win
= (wxWindow
*)this;
1028 while ( win
&& !win
->HasCustomPalette() )
1030 win
= win
->GetParent();
1036 #endif // wxUSE_PALETTE
1039 void wxWindowBase::SetCaret(wxCaret
*caret
)
1050 wxASSERT_MSG( m_caret
->GetWindow() == this,
1051 wxT("caret should be created associated to this window") );
1054 #endif // wxUSE_CARET
1056 #if wxUSE_VALIDATORS
1057 // ----------------------------------------------------------------------------
1059 // ----------------------------------------------------------------------------
1061 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1063 if ( m_windowValidator
)
1064 delete m_windowValidator
;
1066 m_windowValidator
= (wxValidator
*)validator
.Clone();
1068 if ( m_windowValidator
)
1069 m_windowValidator
->SetWindow(this);
1071 #endif // wxUSE_VALIDATORS
1073 // ----------------------------------------------------------------------------
1074 // update region stuff
1075 // ----------------------------------------------------------------------------
1077 wxRect
wxWindowBase::GetUpdateClientRect() const
1079 wxRegion rgnUpdate
= GetUpdateRegion();
1080 rgnUpdate
.Intersect(GetClientRect());
1081 wxRect rectUpdate
= rgnUpdate
.GetBox();
1082 wxPoint ptOrigin
= GetClientAreaOrigin();
1083 rectUpdate
.x
-= ptOrigin
.x
;
1084 rectUpdate
.y
-= ptOrigin
.y
;
1089 bool wxWindowBase::IsExposed(int x
, int y
) const
1091 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1094 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
1096 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1099 void wxWindowBase::ClearBackground()
1101 // wxGTK uses its own version, no need to add never used code
1103 wxClientDC
dc((wxWindow
*)this);
1104 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1105 dc
.SetBackground(brush
);
1110 // ----------------------------------------------------------------------------
1111 // find child window by id or name
1112 // ----------------------------------------------------------------------------
1114 wxWindow
*wxWindowBase::FindWindow( long id
)
1116 if ( id
== m_windowId
)
1117 return (wxWindow
*)this;
1119 wxWindowBase
*res
= (wxWindow
*)NULL
;
1120 wxWindowList::compatibility_iterator node
;
1121 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1123 wxWindowBase
*child
= node
->GetData();
1124 res
= child
->FindWindow( id
);
1127 return (wxWindow
*)res
;
1130 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
1132 if ( name
== m_windowName
)
1133 return (wxWindow
*)this;
1135 wxWindowBase
*res
= (wxWindow
*)NULL
;
1136 wxWindowList::compatibility_iterator node
;
1137 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1139 wxWindow
*child
= node
->GetData();
1140 res
= child
->FindWindow(name
);
1143 return (wxWindow
*)res
;
1147 // find any window by id or name or label: If parent is non-NULL, look through
1148 // children for a label or title matching the specified string. If NULL, look
1149 // through all top-level windows.
1151 // to avoid duplicating code we reuse the same helper function but with
1152 // different comparators
1154 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1155 const wxString
& label
, long id
);
1158 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1161 return win
->GetLabel() == label
;
1165 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1168 return win
->GetName() == label
;
1172 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1175 return win
->GetId() == id
;
1178 // recursive helper for the FindWindowByXXX() functions
1180 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1181 const wxString
& label
,
1183 wxFindWindowCmp cmp
)
1187 // see if this is the one we're looking for
1188 if ( (*cmp
)(parent
, label
, id
) )
1189 return (wxWindow
*)parent
;
1191 // It wasn't, so check all its children
1192 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1194 node
= node
->GetNext() )
1196 // recursively check each child
1197 wxWindow
*win
= (wxWindow
*)node
->GetData();
1198 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1208 // helper for FindWindowByXXX()
1210 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1211 const wxString
& label
,
1213 wxFindWindowCmp cmp
)
1217 // just check parent and all its children
1218 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1221 // start at very top of wx's windows
1222 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1224 node
= node
->GetNext() )
1226 // recursively check each window & its children
1227 wxWindow
*win
= node
->GetData();
1228 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1238 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1240 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1245 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1247 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1251 // fall back to the label
1252 win
= FindWindowByLabel(title
, parent
);
1260 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1262 return wxFindWindowHelper(parent
, _T(""), id
, wxFindWindowCmpIds
);
1265 // ----------------------------------------------------------------------------
1266 // dialog oriented functions
1267 // ----------------------------------------------------------------------------
1269 void wxWindowBase::MakeModal(bool modal
)
1271 // Disable all other windows
1274 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1277 wxWindow
*win
= node
->GetData();
1279 win
->Enable(!modal
);
1281 node
= node
->GetNext();
1286 bool wxWindowBase::Validate()
1288 #if wxUSE_VALIDATORS
1289 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1291 wxWindowList::compatibility_iterator node
;
1292 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1294 wxWindowBase
*child
= node
->GetData();
1295 wxValidator
*validator
= child
->GetValidator();
1296 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1301 if ( recurse
&& !child
->Validate() )
1306 #endif // wxUSE_VALIDATORS
1311 bool wxWindowBase::TransferDataToWindow()
1313 #if wxUSE_VALIDATORS
1314 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1316 wxWindowList::compatibility_iterator node
;
1317 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1319 wxWindowBase
*child
= node
->GetData();
1320 wxValidator
*validator
= child
->GetValidator();
1321 if ( validator
&& !validator
->TransferToWindow() )
1323 wxLogWarning(_("Could not transfer data to window"));
1325 wxLog::FlushActive();
1333 if ( !child
->TransferDataToWindow() )
1335 // warning already given
1340 #endif // wxUSE_VALIDATORS
1345 bool wxWindowBase::TransferDataFromWindow()
1347 #if wxUSE_VALIDATORS
1348 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1350 wxWindowList::compatibility_iterator node
;
1351 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1353 wxWindow
*child
= node
->GetData();
1354 wxValidator
*validator
= child
->GetValidator();
1355 if ( validator
&& !validator
->TransferFromWindow() )
1357 // nop warning here because the application is supposed to give
1358 // one itself - we don't know here what might have gone wrongly
1365 if ( !child
->TransferDataFromWindow() )
1367 // warning already given
1372 #endif // wxUSE_VALIDATORS
1377 void wxWindowBase::InitDialog()
1379 wxInitDialogEvent
event(GetId());
1380 event
.SetEventObject( this );
1381 GetEventHandler()->ProcessEvent(event
);
1384 // ----------------------------------------------------------------------------
1385 // context-sensitive help support
1386 // ----------------------------------------------------------------------------
1390 // associate this help text with this window
1391 void wxWindowBase::SetHelpText(const wxString
& text
)
1393 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1396 helpProvider
->AddHelp(this, text
);
1400 // associate this help text with all windows with the same id as this
1402 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1404 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1407 helpProvider
->AddHelp(GetId(), text
);
1411 // get the help string associated with this window (may be empty)
1412 wxString
wxWindowBase::GetHelpText() const
1415 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1418 text
= helpProvider
->GetHelp(this);
1424 // show help for this window
1425 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1427 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1430 if ( helpProvider
->ShowHelp(this) )
1432 // skip the event.Skip() below
1440 #endif // wxUSE_HELP
1442 // ----------------------------------------------------------------------------
1443 // tooltipsroot.Replace("\\", "/");
1444 // ----------------------------------------------------------------------------
1448 void wxWindowBase::SetToolTip( const wxString
&tip
)
1450 // don't create the new tooltip if we already have one
1453 m_tooltip
->SetTip( tip
);
1457 SetToolTip( new wxToolTip( tip
) );
1460 // setting empty tooltip text does not remove the tooltip any more - use
1461 // SetToolTip((wxToolTip *)NULL) for this
1464 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1469 m_tooltip
= tooltip
;
1472 #endif // wxUSE_TOOLTIPS
1474 // ----------------------------------------------------------------------------
1475 // constraints and sizers
1476 // ----------------------------------------------------------------------------
1478 #if wxUSE_CONSTRAINTS
1480 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1482 if ( m_constraints
)
1484 UnsetConstraints(m_constraints
);
1485 delete m_constraints
;
1487 m_constraints
= constraints
;
1488 if ( m_constraints
)
1490 // Make sure other windows know they're part of a 'meaningful relationship'
1491 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1492 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1493 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1494 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1495 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1496 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1497 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1498 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1499 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1500 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1501 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1502 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1503 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1504 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1505 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1506 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1510 // This removes any dangling pointers to this window in other windows'
1511 // constraintsInvolvedIn lists.
1512 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1516 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1517 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1518 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1519 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1520 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1521 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1522 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1523 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1524 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1525 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1526 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1527 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1528 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1529 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1530 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1531 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1535 // Back-pointer to other windows we're involved with, so if we delete this
1536 // window, we must delete any constraints we're involved with.
1537 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1539 if ( !m_constraintsInvolvedIn
)
1540 m_constraintsInvolvedIn
= new wxWindowList
;
1541 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1542 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1545 // REMOVE back-pointer to other windows we're involved with.
1546 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1548 if ( m_constraintsInvolvedIn
)
1549 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1552 // Reset any constraints that mention this window
1553 void wxWindowBase::DeleteRelatedConstraints()
1555 if ( m_constraintsInvolvedIn
)
1557 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1560 wxWindow
*win
= node
->GetData();
1561 wxLayoutConstraints
*constr
= win
->GetConstraints();
1563 // Reset any constraints involving this window
1566 constr
->left
.ResetIfWin(this);
1567 constr
->top
.ResetIfWin(this);
1568 constr
->right
.ResetIfWin(this);
1569 constr
->bottom
.ResetIfWin(this);
1570 constr
->width
.ResetIfWin(this);
1571 constr
->height
.ResetIfWin(this);
1572 constr
->centreX
.ResetIfWin(this);
1573 constr
->centreY
.ResetIfWin(this);
1576 wxWindowList::compatibility_iterator next
= node
->GetNext();
1577 m_constraintsInvolvedIn
->Erase(node
);
1581 delete m_constraintsInvolvedIn
;
1582 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1586 #endif // wxUSE_CONSTRAINTS
1588 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1590 if ( sizer
== m_windowSizer
)
1594 delete m_windowSizer
;
1596 m_windowSizer
= sizer
;
1598 SetAutoLayout( sizer
!= NULL
);
1601 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1603 SetSizer( sizer
, deleteOld
);
1604 sizer
->SetSizeHints( (wxWindow
*) this );
1607 #if wxUSE_CONSTRAINTS
1609 void wxWindowBase::SatisfyConstraints()
1611 wxLayoutConstraints
*constr
= GetConstraints();
1612 bool wasOk
= constr
&& constr
->AreSatisfied();
1614 ResetConstraints(); // Mark all constraints as unevaluated
1618 // if we're a top level panel (i.e. our parent is frame/dialog), our
1619 // own constraints will never be satisfied any more unless we do it
1623 while ( noChanges
> 0 )
1625 LayoutPhase1(&noChanges
);
1629 LayoutPhase2(&noChanges
);
1632 #endif // wxUSE_CONSTRAINTS
1634 bool wxWindowBase::Layout()
1636 // If there is a sizer, use it instead of the constraints
1640 GetVirtualSize(&w
, &h
);
1641 GetSizer()->SetDimension( 0, 0, w
, h
);
1643 #if wxUSE_CONSTRAINTS
1646 SatisfyConstraints(); // Find the right constraints values
1647 SetConstraintSizes(); // Recursively set the real window sizes
1654 #if wxUSE_CONSTRAINTS
1656 // first phase of the constraints evaluation: set our own constraints
1657 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1659 wxLayoutConstraints
*constr
= GetConstraints();
1661 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1664 // second phase: set the constraints for our children
1665 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1672 // Layout grand children
1678 // Do a phase of evaluating child constraints
1679 bool wxWindowBase::DoPhase(int phase
)
1681 // the list containing the children for which the constraints are already
1683 wxWindowList succeeded
;
1685 // the max number of iterations we loop before concluding that we can't set
1687 static const int maxIterations
= 500;
1689 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1693 // loop over all children setting their constraints
1694 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1696 node
= node
->GetNext() )
1698 wxWindow
*child
= node
->GetData();
1699 if ( child
->IsTopLevel() )
1701 // top level children are not inside our client area
1705 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1707 // this one is either already ok or nothing we can do about it
1711 int tempNoChanges
= 0;
1712 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1713 : child
->LayoutPhase2(&tempNoChanges
);
1714 noChanges
+= tempNoChanges
;
1718 succeeded
.Append(child
);
1724 // constraints are set
1732 void wxWindowBase::ResetConstraints()
1734 wxLayoutConstraints
*constr
= GetConstraints();
1737 constr
->left
.SetDone(false);
1738 constr
->top
.SetDone(false);
1739 constr
->right
.SetDone(false);
1740 constr
->bottom
.SetDone(false);
1741 constr
->width
.SetDone(false);
1742 constr
->height
.SetDone(false);
1743 constr
->centreX
.SetDone(false);
1744 constr
->centreY
.SetDone(false);
1747 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1750 wxWindow
*win
= node
->GetData();
1751 if ( !win
->IsTopLevel() )
1752 win
->ResetConstraints();
1753 node
= node
->GetNext();
1757 // Need to distinguish between setting the 'fake' size for windows and sizers,
1758 // and setting the real values.
1759 void wxWindowBase::SetConstraintSizes(bool recurse
)
1761 wxLayoutConstraints
*constr
= GetConstraints();
1762 if ( constr
&& constr
->AreSatisfied() )
1764 int x
= constr
->left
.GetValue();
1765 int y
= constr
->top
.GetValue();
1766 int w
= constr
->width
.GetValue();
1767 int h
= constr
->height
.GetValue();
1769 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1770 (constr
->height
.GetRelationship() != wxAsIs
) )
1772 SetSize(x
, y
, w
, h
);
1776 // If we don't want to resize this window, just move it...
1782 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1783 GetClassInfo()->GetClassName(),
1789 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1792 wxWindow
*win
= node
->GetData();
1793 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1794 win
->SetConstraintSizes();
1795 node
= node
->GetNext();
1800 // Only set the size/position of the constraint (if any)
1801 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1803 wxLayoutConstraints
*constr
= GetConstraints();
1808 constr
->left
.SetValue(x
);
1809 constr
->left
.SetDone(true);
1813 constr
->top
.SetValue(y
);
1814 constr
->top
.SetDone(true);
1818 constr
->width
.SetValue(w
);
1819 constr
->width
.SetDone(true);
1823 constr
->height
.SetValue(h
);
1824 constr
->height
.SetDone(true);
1829 void wxWindowBase::MoveConstraint(int x
, int y
)
1831 wxLayoutConstraints
*constr
= GetConstraints();
1836 constr
->left
.SetValue(x
);
1837 constr
->left
.SetDone(true);
1841 constr
->top
.SetValue(y
);
1842 constr
->top
.SetDone(true);
1847 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1849 wxLayoutConstraints
*constr
= GetConstraints();
1852 *w
= constr
->width
.GetValue();
1853 *h
= constr
->height
.GetValue();
1859 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1861 wxLayoutConstraints
*constr
= GetConstraints();
1864 *w
= constr
->width
.GetValue();
1865 *h
= constr
->height
.GetValue();
1868 GetClientSize(w
, h
);
1871 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1873 wxLayoutConstraints
*constr
= GetConstraints();
1876 *x
= constr
->left
.GetValue();
1877 *y
= constr
->top
.GetValue();
1883 #endif // wxUSE_CONSTRAINTS
1885 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
1887 // don't do it for the dialogs/frames - they float independently of their
1889 if ( !IsTopLevel() )
1891 wxWindow
*parent
= GetParent();
1892 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
1894 wxPoint
pt(parent
->GetClientAreaOrigin());
1901 // ----------------------------------------------------------------------------
1902 // do Update UI processing for child controls
1903 // ----------------------------------------------------------------------------
1905 void wxWindowBase::UpdateWindowUI(long flags
)
1907 wxUpdateUIEvent
event(GetId());
1908 event
.m_eventObject
= this;
1910 if ( GetEventHandler()->ProcessEvent(event
) )
1912 DoUpdateWindowUI(event
);
1915 if (flags
& wxUPDATE_UI_RECURSE
)
1917 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1920 wxWindow
* child
= (wxWindow
*) node
->GetData();
1921 child
->UpdateWindowUI(flags
);
1922 node
= node
->GetNext();
1927 // do the window-specific processing after processing the update event
1928 // TODO: take specific knowledge out of this function and
1929 // put in each control's base class. Unfortunately we don't
1930 // yet have base implementation files for wxCheckBox and wxRadioButton.
1931 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
1933 if ( event
.GetSetEnabled() )
1934 Enable(event
.GetEnabled());
1937 if ( event
.GetSetText() )
1939 wxControl
*control
= wxDynamicCastThis(wxControl
);
1942 if ( event
.GetText() != control
->GetLabel() )
1943 control
->SetLabel(event
.GetText());
1946 wxCheckBox
*checkbox
= wxDynamicCastThis(wxCheckBox
);
1949 if ( event
.GetSetChecked() )
1950 checkbox
->SetValue(event
.GetChecked());
1952 #endif // wxUSE_CHECKBOX
1955 wxRadioButton
*radiobtn
= wxDynamicCastThis(wxRadioButton
);
1958 if ( event
.GetSetChecked() )
1959 radiobtn
->SetValue(event
.GetChecked());
1961 #endif // wxUSE_RADIOBTN
1967 // call internal idle recursively
1968 // may be obsolete (wait until OnIdle scheme stabilises)
1969 void wxWindowBase::ProcessInternalIdle()
1973 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1976 wxWindow
*child
= node
->GetData();
1977 child
->ProcessInternalIdle();
1978 node
= node
->GetNext();
1983 // ----------------------------------------------------------------------------
1984 // dialog units translations
1985 // ----------------------------------------------------------------------------
1987 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1989 int charWidth
= GetCharWidth();
1990 int charHeight
= GetCharHeight();
1991 wxPoint
pt2(-1, -1);
1993 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
1995 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2000 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
2002 int charWidth
= GetCharWidth();
2003 int charHeight
= GetCharHeight();
2004 wxPoint
pt2(-1, -1);
2006 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
2008 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2013 // ----------------------------------------------------------------------------
2015 // ----------------------------------------------------------------------------
2017 // propagate the colour change event to the subwindows
2018 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2020 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2023 // Only propagate to non-top-level windows
2024 wxWindow
*win
= node
->GetData();
2025 if ( !win
->IsTopLevel() )
2027 wxSysColourChangedEvent event2
;
2028 event
.m_eventObject
= win
;
2029 win
->GetEventHandler()->ProcessEvent(event2
);
2032 node
= node
->GetNext();
2036 // the default action is to populate dialog with data when it's created,
2037 // and nudge the UI into displaying itself correctly in case
2038 // we've turned the wxUpdateUIEvents frequency down low.
2039 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2041 TransferDataToWindow();
2043 // Update the UI at this point
2044 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2047 // process Ctrl-Alt-mclick
2048 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2051 if ( event
.ControlDown() && event
.AltDown() )
2053 // don't translate these strings
2056 #ifdef __WXUNIVERSAL__
2058 #endif // __WXUNIVERSAL__
2060 switch ( wxGetOsVersion() )
2062 case wxMOTIF_X
: port
+= _T("Motif"); break;
2064 case wxMAC_DARWIN
: port
+= _T("Mac"); break;
2065 case wxBEOS
: port
+= _T("BeOS"); break;
2069 case wxGTK_BEOS
: port
+= _T("GTK"); break;
2075 case wxWIN386
: port
+= _T("MS Windows"); break;
2079 case wxMGL_OS2
: port
+= _T("MGL"); break;
2081 case wxOS2_PM
: port
+= _T("OS/2"); break;
2082 default: port
+= _T("unknown"); break;
2085 wxMessageBox(wxString::Format(
2087 " wxWindows Library (%s port)\nVersion %u.%u.%u%s, compiled at %s %s\n Copyright (c) 1995-2002 wxWindows team"
2101 _T("wxWindows information"),
2102 wxICON_INFORMATION
| wxOK
,
2106 #endif // wxUSE_MSGDLG
2112 // ----------------------------------------------------------------------------
2114 // ----------------------------------------------------------------------------
2116 #if wxUSE_ACCESSIBILITY
2117 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2119 if (m_accessible
&& (accessible
!= m_accessible
))
2120 delete m_accessible
;
2121 m_accessible
= accessible
;
2123 m_accessible
->SetWindow((wxWindow
*) this);
2126 // Returns the accessible object, creating if necessary.
2127 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2130 m_accessible
= CreateAccessible();
2131 return m_accessible
;
2134 // Override to create a specific accessible object.
2135 wxAccessible
* wxWindowBase::CreateAccessible()
2137 return new wxWindowAccessible((wxWindow
*) this);
2143 // ----------------------------------------------------------------------------
2144 // list classes implementation
2145 // ----------------------------------------------------------------------------
2147 void wxWindowListNode::DeleteData()
2149 delete (wxWindow
*)GetData();
2153 // ----------------------------------------------------------------------------
2155 // ----------------------------------------------------------------------------
2157 wxBorder
wxWindowBase::GetBorder(long flags
) const
2159 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2160 if ( border
== wxBORDER_DEFAULT
)
2162 border
= GetDefaultBorder();
2168 wxBorder
wxWindowBase::GetDefaultBorder() const
2170 return wxBORDER_NONE
;
2173 // ----------------------------------------------------------------------------
2175 // ----------------------------------------------------------------------------
2177 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2179 // here we just check if the point is inside the window or not
2181 // check the top and left border first
2182 bool outside
= x
< 0 || y
< 0;
2185 // check the right and bottom borders too
2186 wxSize size
= GetSize();
2187 outside
= x
>= size
.x
|| y
>= size
.y
;
2190 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2193 // ----------------------------------------------------------------------------
2195 // ----------------------------------------------------------------------------
2197 struct WXDLLEXPORT wxWindowNext
2201 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2203 void wxWindowBase::CaptureMouse()
2205 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this);
2207 wxWindow
*winOld
= GetCapture();
2210 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2213 wxWindowNext
*item
= new wxWindowNext
;
2215 item
->next
= ms_winCaptureNext
;
2216 ms_winCaptureNext
= item
;
2218 //else: no mouse capture to save
2223 void wxWindowBase::ReleaseMouse()
2225 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this);
2227 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2231 if ( ms_winCaptureNext
)
2233 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2235 wxWindowNext
*item
= ms_winCaptureNext
;
2236 ms_winCaptureNext
= item
->next
;
2239 //else: stack is empty, no previous capture
2241 wxLogTrace(_T("mousecapture"),
2242 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2249 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2250 int WXUNUSED(modifiers
),
2251 int WXUNUSED(keycode
))
2257 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2263 #endif // wxUSE_HOTKEY
2265 void wxWindowBase::SendDestroyEvent()
2267 wxWindowDestroyEvent event
;
2268 event
.SetEventObject(this);
2269 event
.SetId(GetId());
2270 GetEventHandler()->ProcessEvent(event
);
2273 // ----------------------------------------------------------------------------
2275 // ----------------------------------------------------------------------------
2277 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2279 #if wxUSE_VALIDATORS
2280 // Can only use the validator of the window which
2281 // is receiving the event
2282 if ( event
.GetEventObject() == this )
2284 wxValidator
*validator
= GetValidator();
2285 if ( validator
&& validator
->ProcessEvent(event
) )
2290 #endif // wxUSE_VALIDATORS
2295 bool wxWindowBase::TryParent(wxEvent
& event
)
2297 // carry on up the parent-child hierarchy if the propgation count hasn't
2299 if ( event
.ShouldPropagate() )
2301 // honour the requests to stop propagation at this window: this is
2302 // used by the dialogs, for example, to prevent processing the events
2303 // from the dialog controls in the parent frame which rarely, if ever,
2305 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2307 wxWindow
*parent
= GetParent();
2308 if ( parent
&& !parent
->IsBeingDeleted() )
2310 wxPropagateOnce
propagateOnce(event
);
2312 return parent
->GetEventHandler()->ProcessEvent(event
);
2317 return wxEvtHandler::TryParent(event
);
2320 // ----------------------------------------------------------------------------
2322 // ----------------------------------------------------------------------------
2324 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2326 while ( win
&& !win
->IsTopLevel() )
2327 win
= win
->GetParent();
2332 #if wxUSE_ACCESSIBILITY
2333 // ----------------------------------------------------------------------------
2334 // accessible object for windows
2335 // ----------------------------------------------------------------------------
2337 // Can return either a child object, or an integer
2338 // representing the child element, starting from 1.
2339 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2341 wxASSERT( GetWindow() != NULL
);
2345 return wxACC_NOT_IMPLEMENTED
;
2348 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2349 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2351 wxASSERT( GetWindow() != NULL
);
2355 wxWindow
* win
= NULL
;
2362 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2364 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2371 rect
= win
->GetRect();
2372 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2373 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2377 return wxACC_NOT_IMPLEMENTED
;
2380 // Navigates from fromId to toId/toObject.
2381 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2382 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2384 wxASSERT( GetWindow() != NULL
);
2390 case wxNAVDIR_FIRSTCHILD
:
2392 if (GetWindow()->GetChildren().GetCount() == 0)
2394 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2395 *toObject
= childWindow
->GetOrCreateAccessible();
2399 case wxNAVDIR_LASTCHILD
:
2401 if (GetWindow()->GetChildren().GetCount() == 0)
2403 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2404 *toObject
= childWindow
->GetOrCreateAccessible();
2408 case wxNAVDIR_RIGHT
:
2412 wxWindowList::compatibility_iterator node
=
2413 wxWindowList::compatibility_iterator();
2416 // Can't navigate to sibling of this window
2417 // if we're a top-level window.
2418 if (!GetWindow()->GetParent())
2419 return wxACC_NOT_IMPLEMENTED
;
2421 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2425 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2426 node
= GetWindow()->GetChildren().Item(fromId
-1);
2429 if (node
&& node
->GetNext())
2431 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2432 *toObject
= nextWindow
->GetOrCreateAccessible();
2440 case wxNAVDIR_PREVIOUS
:
2442 wxWindowList::compatibility_iterator node
=
2443 wxWindowList::compatibility_iterator();
2446 // Can't navigate to sibling of this window
2447 // if we're a top-level window.
2448 if (!GetWindow()->GetParent())
2449 return wxACC_NOT_IMPLEMENTED
;
2451 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2455 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2456 node
= GetWindow()->GetChildren().Item(fromId
-1);
2459 if (node
&& node
->GetPrevious())
2461 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2462 *toObject
= previousWindow
->GetOrCreateAccessible();
2470 return wxACC_NOT_IMPLEMENTED
;
2473 // Gets the name of the specified object.
2474 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2476 wxASSERT( GetWindow() != NULL
);
2482 // If a child, leave wxWindows to call the function on the actual
2485 return wxACC_NOT_IMPLEMENTED
;
2487 // This will eventually be replaced by specialised
2488 // accessible classes, one for each kind of wxWindows
2489 // control or window.
2490 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2491 title
= ((wxButton
*) GetWindow())->GetLabel();
2493 title
= GetWindow()->GetName();
2495 if (!title
.IsEmpty())
2501 return wxACC_NOT_IMPLEMENTED
;
2504 // Gets the number of children.
2505 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2507 wxASSERT( GetWindow() != NULL
);
2511 *childId
= (int) GetWindow()->GetChildren().GetCount();
2515 // Gets the specified child (starting from 1).
2516 // If *child is NULL and return value is wxACC_OK,
2517 // this means that the child is a simple element and
2518 // not an accessible object.
2519 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2521 wxASSERT( GetWindow() != NULL
);
2531 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2534 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2535 *child
= childWindow
->GetOrCreateAccessible();
2542 // Gets the parent, or NULL.
2543 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2545 wxASSERT( GetWindow() != NULL
);
2549 wxWindow
* parentWindow
= GetWindow()->GetParent();
2557 *parent
= parentWindow
->GetOrCreateAccessible();
2565 // Performs the default action. childId is 0 (the action for this object)
2566 // or > 0 (the action for a child).
2567 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2568 // window (e.g. an edit control).
2569 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
2571 wxASSERT( GetWindow() != NULL
);
2575 return wxACC_NOT_IMPLEMENTED
;
2578 // Gets the default action for this object (0) or > 0 (the action for a child).
2579 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2580 // string if there is no action.
2581 // The retrieved string describes the action that is performed on an object,
2582 // not what the object does as a result. For example, a toolbar button that prints
2583 // a document has a default action of "Press" rather than "Prints the current document."
2584 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
2586 wxASSERT( GetWindow() != NULL
);
2590 return wxACC_NOT_IMPLEMENTED
;
2593 // Returns the description for this object or a child.
2594 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
2596 wxASSERT( GetWindow() != NULL
);
2600 wxString
ht(GetWindow()->GetHelpText());
2606 return wxACC_NOT_IMPLEMENTED
;
2609 // Returns help text for this object or a child, similar to tooltip text.
2610 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
2612 wxASSERT( GetWindow() != NULL
);
2616 wxString
ht(GetWindow()->GetHelpText());
2622 return wxACC_NOT_IMPLEMENTED
;
2625 // Returns the keyboard shortcut for this object or child.
2626 // Return e.g. ALT+K
2627 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
2629 wxASSERT( GetWindow() != NULL
);
2633 return wxACC_NOT_IMPLEMENTED
;
2636 // Returns a role constant.
2637 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
2639 wxASSERT( GetWindow() != NULL
);
2643 // If a child, leave wxWindows to call the function on the actual
2646 return wxACC_NOT_IMPLEMENTED
;
2648 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2649 return wxACC_NOT_IMPLEMENTED
;
2651 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2652 return wxACC_NOT_IMPLEMENTED
;
2655 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2656 return wxACC_NOT_IMPLEMENTED
;
2659 //*role = wxROLE_SYSTEM_CLIENT;
2660 *role
= wxROLE_SYSTEM_CLIENT
;
2664 return wxACC_NOT_IMPLEMENTED
;
2668 // Returns a state constant.
2669 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
2671 wxASSERT( GetWindow() != NULL
);
2675 // If a child, leave wxWindows to call the function on the actual
2678 return wxACC_NOT_IMPLEMENTED
;
2680 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2681 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
;
2696 return wxACC_NOT_IMPLEMENTED
;
2700 // Returns a localized string representing the value for the object
2702 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
2704 wxASSERT( GetWindow() != NULL
);
2708 return wxACC_NOT_IMPLEMENTED
;
2711 // Selects the object or child.
2712 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
2714 wxASSERT( GetWindow() != NULL
);
2718 return wxACC_NOT_IMPLEMENTED
;
2721 // Gets the window with the keyboard focus.
2722 // If childId is 0 and child is NULL, no object in
2723 // this subhierarchy has the focus.
2724 // If this object has the focus, child should be 'this'.
2725 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
2727 wxASSERT( GetWindow() != NULL
);
2731 return wxACC_NOT_IMPLEMENTED
;
2734 // Gets a variant representing the selected children
2736 // Acceptable values:
2737 // - a null variant (IsNull() returns TRUE)
2738 // - a list variant (GetType() == wxT("list")
2739 // - an integer representing the selected child element,
2740 // or 0 if this object is selected (GetType() == wxT("long")
2741 // - a "void*" pointer to a wxAccessible child object
2742 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
2744 wxASSERT( GetWindow() != NULL
);
2748 return wxACC_NOT_IMPLEMENTED
;
2751 #endif // wxUSE_ACCESSIBILITY