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 // ----------------------------------------------------------------------------
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(-1, wxWindowBase::OnHelp
)
103 // ============================================================================
104 // implementation of the common functionality of the wxWindow class
105 // ============================================================================
107 // ----------------------------------------------------------------------------
109 // ----------------------------------------------------------------------------
111 // the default initialization
112 void wxWindowBase::InitBase()
114 // no window yet, no parent nor children
115 m_parent
= (wxWindow
*)NULL
;
117 m_children
.DeleteContents( FALSE
); // don't auto delete node data
119 // no constraints on the minimal window size
125 // window is created enabled but it's not visible yet
129 // the default event handler is just this window
130 m_eventHandler
= this;
134 m_windowValidator
= (wxValidator
*) NULL
;
135 #endif // wxUSE_VALIDATORS
137 // use the system default colours
138 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
139 m_foregroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
141 // don't set the font here for wxMSW as we don't call WM_SETFONT here and
142 // so the font is *not* really set - but calls to SetFont() later won't do
143 // anything because m_font appears to be already set!
145 m_font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
148 // the colours/fonts are default for now
153 m_isBeingDeleted
= FALSE
;
159 // an optimization for the event processing: checking this flag is much
160 // faster than using IsKindOf(CLASSINFO(wxWindow))
163 #if wxUSE_CONSTRAINTS
164 // no constraints whatsoever
165 m_constraints
= (wxLayoutConstraints
*) NULL
;
166 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
167 #endif // wxUSE_CONSTRAINTS
169 m_windowSizer
= (wxSizer
*) NULL
;
170 m_containingSizer
= (wxSizer
*) NULL
;
171 m_autoLayout
= FALSE
;
173 #if wxUSE_DRAG_AND_DROP
174 m_dropTarget
= (wxDropTarget
*)NULL
;
175 #endif // wxUSE_DRAG_AND_DROP
178 m_tooltip
= (wxToolTip
*)NULL
;
179 #endif // wxUSE_TOOLTIPS
182 m_caret
= (wxCaret
*)NULL
;
183 #endif // wxUSE_CARET
186 m_hasCustomPalette
= FALSE
;
187 #endif // wxUSE_PALETTE
189 #if wxUSE_ACCESSIBILITY
193 m_virtualSize
= wxDefaultSize
;
198 m_maxVirtualHeight
= -1;
200 // Whether we're using the current theme for this window (wxGTK only for now)
201 m_themeEnabled
= FALSE
;
204 // common part of window creation process
205 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
207 const wxPoint
& WXUNUSED(pos
),
208 const wxSize
& WXUNUSED(size
),
210 const wxValidator
& validator
,
211 const wxString
& name
)
213 // m_isWindow is set to TRUE in wxWindowBase::Init() as well as many other
214 // member variables - check that it has been called (will catch the case
215 // when a new ctor is added which doesn't call InitWindow)
216 wxASSERT_MSG( m_isWindow
, wxT("Init() must have been called before!") );
219 // wxGTK doesn't allow to create controls with static box as the parent so
220 // this will result in a crash when the program is ported to wxGTK so warn
223 // if you get this assert, the correct solution is to create the controls
224 // as siblings of the static box
225 wxASSERT_MSG( !parent
|| !wxDynamicCast(parent
, wxStaticBox
),
226 _T("wxStaticBox can't be used as a window parent!") );
227 #endif // wxUSE_STATBOX
229 // ids are limited to 16 bits under MSW so if you care about portability,
230 // it's not a good idea to use ids out of this range (and negative ids are
231 // reserved for wxWindows own usage)
232 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767),
233 _T("invalid id value") );
235 // generate a new id if the user doesn't care about it
236 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
239 SetWindowStyleFlag(style
);
243 SetValidator(validator
);
244 #endif // wxUSE_VALIDATORS
246 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
247 // have it too - like this it's possible to set it only in the top level
248 // dialog/frame and all children will inherit it by defult
249 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
251 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
257 // ----------------------------------------------------------------------------
259 // ----------------------------------------------------------------------------
262 wxWindowBase::~wxWindowBase()
264 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
266 // FIXME if these 2 cases result from programming errors in the user code
267 // we should probably assert here instead of silently fixing them
269 // Just in case the window has been Closed, but we're then deleting
270 // immediately: don't leave dangling pointers.
271 wxPendingDelete
.DeleteObject(this);
273 // Just in case we've loaded a top-level window via LoadNativeDialog but
274 // we weren't a dialog class
275 wxTopLevelWindows
.DeleteObject(this);
277 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
282 #endif // wxUSE_CARET
285 if ( m_windowValidator
)
286 delete m_windowValidator
;
287 #endif // wxUSE_VALIDATORS
289 #if wxUSE_CONSTRAINTS
290 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
291 // at deleted windows as they delete themselves.
292 DeleteRelatedConstraints();
296 // This removes any dangling pointers to this window in other windows'
297 // constraintsInvolvedIn lists.
298 UnsetConstraints(m_constraints
);
299 delete m_constraints
;
300 m_constraints
= NULL
;
303 #endif // wxUSE_CONSTRAINTS
305 if ( m_containingSizer
)
306 m_containingSizer
->Detach( (wxWindow
*)this );
309 delete m_windowSizer
;
311 #if wxUSE_DRAG_AND_DROP
314 #endif // wxUSE_DRAG_AND_DROP
319 #endif // wxUSE_TOOLTIPS
321 #if wxUSE_ACCESSIBILITY
326 // reset the dangling pointer our parent window may keep to us
327 if ( m_parent
&& m_parent
->GetDefaultItem() == this )
329 m_parent
->SetDefaultItem(NULL
);
333 bool wxWindowBase::Destroy()
340 bool wxWindowBase::Close(bool force
)
342 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
343 event
.SetEventObject(this);
344 #if WXWIN_COMPATIBILITY
345 event
.SetForce(force
);
346 #endif // WXWIN_COMPATIBILITY
347 event
.SetCanVeto(!force
);
349 // return FALSE if window wasn't closed because the application vetoed the
351 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
354 bool wxWindowBase::DestroyChildren()
356 wxWindowList::Node
*node
;
359 // we iterate until the list becomes empty
360 node
= GetChildren().GetFirst();
364 wxWindow
*child
= node
->GetData();
366 wxASSERT_MSG( child
, wxT("children list contains empty nodes") );
371 wxASSERT_MSG( !GetChildren().Find(child
),
372 wxT("child didn't remove itself using RemoveChild()") );
378 // ----------------------------------------------------------------------------
379 // size/position related methods
380 // ----------------------------------------------------------------------------
382 // centre the window with respect to its parent in either (or both) directions
383 void wxWindowBase::Centre(int direction
)
385 // the position/size of the parent window or of the entire screen
387 int widthParent
, heightParent
;
389 wxWindow
*parent
= NULL
;
391 if ( !(direction
& wxCENTRE_ON_SCREEN
) )
393 // find the parent to centre this window on: it should be the
394 // immediate parent for the controls but the top level parent for the
395 // top level windows (like dialogs)
396 parent
= GetParent();
399 while ( parent
&& !parent
->IsTopLevel() )
401 parent
= parent
->GetParent();
405 // there is no wxTopLevelWindow under wxMotif yet
407 // we shouldn't center the dialog on the iconized window: under
408 // Windows, for example, this places it completely off the screen
411 wxTopLevelWindow
*winTop
= wxDynamicCast(parent
, wxTopLevelWindow
);
412 if ( winTop
&& winTop
->IsIconized() )
417 #endif // __WXMOTIF__
419 // did we find the parent?
423 direction
|= wxCENTRE_ON_SCREEN
;
427 if ( direction
& wxCENTRE_ON_SCREEN
)
429 // centre with respect to the whole screen
430 wxDisplaySize(&widthParent
, &heightParent
);
436 // centre on the parent
437 parent
->GetSize(&widthParent
, &heightParent
);
439 // adjust to the parents position
440 posParent
= parent
->GetPosition();
444 // centre inside the parents client rectangle
445 parent
->GetClientSize(&widthParent
, &heightParent
);
450 GetSize(&width
, &height
);
455 if ( direction
& wxHORIZONTAL
)
456 xNew
= (widthParent
- width
)/2;
458 if ( direction
& wxVERTICAL
)
459 yNew
= (heightParent
- height
)/2;
464 // Base size of the visible dimensions of the display
465 // to take into account the taskbar
466 wxRect rect
= wxGetClientDisplayRect();
467 wxSize
size (rect
.width
,rect
.height
);
469 // NB: in wxMSW, negative position may not neccessary mean "out of screen",
470 // but it may mean that the window is placed on other than the main
471 // display. Therefore we only make sure centered window is on the main display
472 // if the parent is at least partially present here.
473 if (posParent
.x
+ widthParent
>= 0) // if parent is (partially) on the main display
477 else if (xNew
+width
> size
.x
)
478 xNew
= size
.x
-width
-1;
480 if (posParent
.y
+ heightParent
>= 0) // if parent is (partially) on the main display
482 if (yNew
+height
> size
.y
)
483 yNew
= size
.y
-height
-1;
485 // Make certain that the title bar is initially visible
486 // always, even if this would push the bottom of the
487 // dialog of the visible area of the display
492 // move the window to this position (keeping the old size but using
493 // SetSize() and not Move() to allow xNew and/or yNew to be -1)
494 SetSize(xNew
, yNew
, width
, height
, wxSIZE_ALLOW_MINUS_ONE
);
497 // fits the window around the children
498 void wxWindowBase::Fit()
500 if ( GetChildren().GetCount() > 0 )
502 SetClientSize(DoGetBestSize());
504 //else: do nothing if we have no children
507 // fits virtual size (ie. scrolled area etc.) around children
508 void wxWindowBase::FitInside()
510 if ( GetChildren().GetCount() > 0 )
512 SetVirtualSize( GetBestVirtualSize() );
516 // return the size best suited for the current window
517 wxSize
wxWindowBase::DoGetBestSize() const
521 return m_windowSizer
->GetMinSize();
523 #if wxUSE_CONSTRAINTS
524 else if ( m_constraints
)
526 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
528 // our minimal acceptable size is such that all our windows fit inside
532 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
534 node
= node
->GetNext() )
536 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
539 // it's not normal that we have an unconstrained child, but
540 // what can we do about it?
544 int x
= c
->right
.GetValue(),
545 y
= c
->bottom
.GetValue();
553 // TODO: we must calculate the overlaps somehow, otherwise we
554 // will never return a size bigger than the current one :-(
557 return wxSize(maxX
, maxY
);
559 #endif // wxUSE_CONSTRAINTS
560 else if ( GetChildren().GetCount() > 0 )
562 // our minimal acceptable size is such that all our windows fit inside
566 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
568 node
= node
->GetNext() )
570 wxWindow
*win
= node
->GetData();
571 if ( win
->IsTopLevel()
573 || wxDynamicCast(win
, wxStatusBar
)
574 #endif // wxUSE_STATUSBAR
577 // dialogs and frames lie in different top level windows -
578 // don't deal with them here; as for the status bars, they
579 // don't lie in the client area at all
584 win
->GetPosition(&wx
, &wy
);
586 // if the window hadn't been positioned yet, assume that it is in
593 win
->GetSize(&ww
, &wh
);
594 if ( wx
+ ww
> maxX
)
596 if ( wy
+ wh
> maxY
)
600 // for compatibility with the old versions and because it really looks
601 // slightly more pretty like this, add a pad
605 return wxSize(maxX
, maxY
);
609 // for a generic window there is no natural best size - just use the
615 // by default the origin is not shifted
616 wxPoint
wxWindowBase::GetClientAreaOrigin() const
618 return wxPoint(0, 0);
621 // set the min/max size of the window
622 void wxWindowBase::SetSizeHints(int minW
, int minH
,
624 int WXUNUSED(incW
), int WXUNUSED(incH
))
626 // setting min width greater than max width leads to infinite loops under
627 // X11 and generally doesn't make any sense, so don't allow it
628 wxCHECK_RET( (minW
== -1 || maxW
== -1 || minW
<= maxW
) &&
629 (minH
== -1 || maxH
== -1 || minH
<= maxH
),
630 _T("min width/height must be less than max width/height!") );
638 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
641 m_minVirtualWidth
= minW
;
642 m_maxVirtualWidth
= maxW
;
643 m_minVirtualHeight
= minH
;
644 m_maxVirtualHeight
= maxH
;
647 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
649 if ( m_minVirtualWidth
!= -1 && m_minVirtualWidth
> x
)
650 x
= m_minVirtualWidth
;
651 if ( m_maxVirtualWidth
!= -1 && m_maxVirtualWidth
< x
)
652 x
= m_maxVirtualWidth
;
653 if ( m_minVirtualHeight
!= -1 && m_minVirtualHeight
> y
)
654 y
= m_minVirtualHeight
;
655 if ( m_maxVirtualHeight
!= -1 && m_maxVirtualHeight
< y
)
656 y
= m_maxVirtualHeight
;
658 m_virtualSize
= wxSize(x
, y
);
661 wxSize
wxWindowBase::DoGetVirtualSize() const
663 wxSize
s( GetClientSize() );
665 return wxSize( wxMax( m_virtualSize
.GetWidth(), s
.GetWidth() ),
666 wxMax( m_virtualSize
.GetHeight(), s
.GetHeight() ) );
669 // ----------------------------------------------------------------------------
670 // show/hide/enable/disable the window
671 // ----------------------------------------------------------------------------
673 bool wxWindowBase::Show(bool show
)
675 if ( show
!= m_isShown
)
687 bool wxWindowBase::Enable(bool enable
)
689 if ( enable
!= m_isEnabled
)
691 m_isEnabled
= enable
;
700 // ----------------------------------------------------------------------------
702 // ----------------------------------------------------------------------------
704 bool wxWindowBase::IsTopLevel() const
709 // ----------------------------------------------------------------------------
710 // reparenting the window
711 // ----------------------------------------------------------------------------
713 void wxWindowBase::AddChild(wxWindowBase
*child
)
715 wxCHECK_RET( child
, wxT("can't add a NULL child") );
717 // this should never happen and it will lead to a crash later if it does
718 // because RemoveChild() will remove only one node from the children list
719 // and the other(s) one(s) will be left with dangling pointers in them
720 wxASSERT_MSG( !GetChildren().Find(child
), _T("AddChild() called twice") );
722 GetChildren().Append(child
);
723 child
->SetParent(this);
726 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
728 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
730 GetChildren().DeleteObject(child
);
731 child
->SetParent((wxWindow
*)NULL
);
734 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
736 wxWindow
*oldParent
= GetParent();
737 if ( newParent
== oldParent
)
743 // unlink this window from the existing parent.
746 oldParent
->RemoveChild(this);
750 wxTopLevelWindows
.DeleteObject(this);
753 // add it to the new one
756 newParent
->AddChild(this);
760 wxTopLevelWindows
.Append(this);
766 // ----------------------------------------------------------------------------
767 // event handler stuff
768 // ----------------------------------------------------------------------------
770 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
772 wxEvtHandler
*handlerOld
= GetEventHandler();
774 handler
->SetNextHandler(handlerOld
);
777 GetEventHandler()->SetPreviousHandler(handler
);
779 SetEventHandler(handler
);
782 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
784 wxEvtHandler
*handlerA
= GetEventHandler();
787 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
788 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
791 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
792 SetEventHandler(handlerB
);
797 handlerA
= (wxEvtHandler
*)NULL
;
804 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
806 wxCHECK_MSG( handler
, FALSE
, _T("RemoveEventHandler(NULL) called") );
808 wxEvtHandler
*handlerPrev
= NULL
,
809 *handlerCur
= GetEventHandler();
812 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
814 if ( handlerCur
== handler
)
818 handlerPrev
->SetNextHandler(handlerNext
);
822 SetEventHandler(handlerNext
);
827 handlerNext
->SetPreviousHandler ( handlerPrev
);
829 handler
->SetNextHandler(NULL
);
834 handlerPrev
= handlerCur
;
835 handlerCur
= handlerNext
;
838 wxFAIL_MSG( _T("where has the event handler gone?") );
843 // ----------------------------------------------------------------------------
845 // ----------------------------------------------------------------------------
847 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
849 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
852 m_backgroundColour
= colour
;
859 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
861 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
864 m_foregroundColour
= colour
;
871 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
873 // setting an invalid cursor is ok, it means that we don't have any special
875 if ( m_cursor
== cursor
)
886 bool wxWindowBase::SetFont(const wxFont
& font
)
888 // don't try to set invalid font, always fall back to the default
889 const wxFont
& fontOk
= font
.Ok() ? font
: *wxSWISS_FONT
;
891 if ( fontOk
== m_font
)
906 void wxWindowBase::SetPalette(const wxPalette
& pal
)
908 m_hasCustomPalette
= TRUE
;
911 // VZ: can anyone explain me what do we do here?
912 wxWindowDC
d((wxWindow
*) this);
916 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
918 wxWindow
*win
= (wxWindow
*)this;
919 while ( win
&& !win
->HasCustomPalette() )
921 win
= win
->GetParent();
927 #endif // wxUSE_PALETTE
930 void wxWindowBase::SetCaret(wxCaret
*caret
)
941 wxASSERT_MSG( m_caret
->GetWindow() == this,
942 wxT("caret should be created associated to this window") );
945 #endif // wxUSE_CARET
948 // ----------------------------------------------------------------------------
950 // ----------------------------------------------------------------------------
952 void wxWindowBase::SetValidator(const wxValidator
& validator
)
954 if ( m_windowValidator
)
955 delete m_windowValidator
;
957 m_windowValidator
= (wxValidator
*)validator
.Clone();
959 if ( m_windowValidator
)
960 m_windowValidator
->SetWindow(this) ;
962 #endif // wxUSE_VALIDATORS
964 // ----------------------------------------------------------------------------
965 // update region stuff
966 // ----------------------------------------------------------------------------
968 wxRect
wxWindowBase::GetUpdateClientRect() const
970 wxRegion rgnUpdate
= GetUpdateRegion();
971 rgnUpdate
.Intersect(GetClientRect());
972 wxRect rectUpdate
= rgnUpdate
.GetBox();
973 wxPoint ptOrigin
= GetClientAreaOrigin();
974 rectUpdate
.x
-= ptOrigin
.x
;
975 rectUpdate
.y
-= ptOrigin
.y
;
980 bool wxWindowBase::IsExposed(int x
, int y
) const
982 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
985 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
987 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
990 // ----------------------------------------------------------------------------
991 // find child window by id or name
992 // ----------------------------------------------------------------------------
994 wxWindow
*wxWindowBase::FindWindow( long id
)
996 if ( id
== m_windowId
)
997 return (wxWindow
*)this;
999 wxWindowBase
*res
= (wxWindow
*)NULL
;
1000 wxWindowList::Node
*node
;
1001 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1003 wxWindowBase
*child
= node
->GetData();
1004 res
= child
->FindWindow( id
);
1007 return (wxWindow
*)res
;
1010 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
1012 if ( name
== m_windowName
)
1013 return (wxWindow
*)this;
1015 wxWindowBase
*res
= (wxWindow
*)NULL
;
1016 wxWindowList::Node
*node
;
1017 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1019 wxWindow
*child
= node
->GetData();
1020 res
= child
->FindWindow(name
);
1023 return (wxWindow
*)res
;
1027 // find any window by id or name or label: If parent is non-NULL, look through
1028 // children for a label or title matching the specified string. If NULL, look
1029 // through all top-level windows.
1031 // to avoid duplicating code we reuse the same helper function but with
1032 // different comparators
1034 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1035 const wxString
& label
, long id
);
1038 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1041 return win
->GetLabel() == label
;
1045 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1048 return win
->GetName() == label
;
1052 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1055 return win
->GetId() == id
;
1058 // recursive helper for the FindWindowByXXX() functions
1060 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1061 const wxString
& label
,
1063 wxFindWindowCmp cmp
)
1067 // see if this is the one we're looking for
1068 if ( (*cmp
)(parent
, label
, id
) )
1069 return (wxWindow
*)parent
;
1071 // It wasn't, so check all its children
1072 for ( wxWindowList::Node
* node
= parent
->GetChildren().GetFirst();
1074 node
= node
->GetNext() )
1076 // recursively check each child
1077 wxWindow
*win
= (wxWindow
*)node
->GetData();
1078 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1088 // helper for FindWindowByXXX()
1090 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1091 const wxString
& label
,
1093 wxFindWindowCmp cmp
)
1097 // just check parent and all its children
1098 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1101 // start at very top of wx's windows
1102 for ( wxWindowList::Node
* node
= wxTopLevelWindows
.GetFirst();
1104 node
= node
->GetNext() )
1106 // recursively check each window & its children
1107 wxWindow
*win
= node
->GetData();
1108 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1118 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1120 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1125 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1127 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1131 // fall back to the label
1132 win
= FindWindowByLabel(title
, parent
);
1140 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1142 return wxFindWindowHelper(parent
, _T(""), id
, wxFindWindowCmpIds
);
1145 // ----------------------------------------------------------------------------
1146 // dialog oriented functions
1147 // ----------------------------------------------------------------------------
1149 void wxWindowBase::MakeModal(bool modal
)
1151 // Disable all other windows
1154 wxWindowList::Node
*node
= wxTopLevelWindows
.GetFirst();
1157 wxWindow
*win
= node
->GetData();
1159 win
->Enable(!modal
);
1161 node
= node
->GetNext();
1166 bool wxWindowBase::Validate()
1168 #if wxUSE_VALIDATORS
1169 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1171 wxWindowList::Node
*node
;
1172 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1174 wxWindowBase
*child
= node
->GetData();
1175 wxValidator
*validator
= child
->GetValidator();
1176 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1181 if ( recurse
&& !child
->Validate() )
1186 #endif // wxUSE_VALIDATORS
1191 bool wxWindowBase::TransferDataToWindow()
1193 #if wxUSE_VALIDATORS
1194 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1196 wxWindowList::Node
*node
;
1197 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1199 wxWindowBase
*child
= node
->GetData();
1200 wxValidator
*validator
= child
->GetValidator();
1201 if ( validator
&& !validator
->TransferToWindow() )
1203 wxLogWarning(_("Could not transfer data to window"));
1205 wxLog::FlushActive();
1213 if ( !child
->TransferDataToWindow() )
1215 // warning already given
1220 #endif // wxUSE_VALIDATORS
1225 bool wxWindowBase::TransferDataFromWindow()
1227 #if wxUSE_VALIDATORS
1228 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1230 wxWindowList::Node
*node
;
1231 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1233 wxWindow
*child
= node
->GetData();
1234 wxValidator
*validator
= child
->GetValidator();
1235 if ( validator
&& !validator
->TransferFromWindow() )
1237 // nop warning here because the application is supposed to give
1238 // one itself - we don't know here what might have gone wrongly
1245 if ( !child
->TransferDataFromWindow() )
1247 // warning already given
1252 #endif // wxUSE_VALIDATORS
1257 void wxWindowBase::InitDialog()
1259 wxInitDialogEvent
event(GetId());
1260 event
.SetEventObject( this );
1261 GetEventHandler()->ProcessEvent(event
);
1264 // ----------------------------------------------------------------------------
1265 // context-sensitive help support
1266 // ----------------------------------------------------------------------------
1270 // associate this help text with this window
1271 void wxWindowBase::SetHelpText(const wxString
& text
)
1273 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1276 helpProvider
->AddHelp(this, text
);
1280 // associate this help text with all windows with the same id as this
1282 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1284 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1287 helpProvider
->AddHelp(GetId(), text
);
1291 // get the help string associated with this window (may be empty)
1292 wxString
wxWindowBase::GetHelpText() const
1295 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1298 text
= helpProvider
->GetHelp(this);
1304 // show help for this window
1305 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1307 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1310 if ( helpProvider
->ShowHelp(this) )
1312 // skip the event.Skip() below
1320 #endif // wxUSE_HELP
1322 // ----------------------------------------------------------------------------
1323 // tooltipsroot.Replace("\\", "/");
1324 // ----------------------------------------------------------------------------
1328 void wxWindowBase::SetToolTip( const wxString
&tip
)
1330 // don't create the new tooltip if we already have one
1333 m_tooltip
->SetTip( tip
);
1337 SetToolTip( new wxToolTip( tip
) );
1340 // setting empty tooltip text does not remove the tooltip any more - use
1341 // SetToolTip((wxToolTip *)NULL) for this
1344 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1349 m_tooltip
= tooltip
;
1352 #endif // wxUSE_TOOLTIPS
1354 // ----------------------------------------------------------------------------
1355 // constraints and sizers
1356 // ----------------------------------------------------------------------------
1358 #if wxUSE_CONSTRAINTS
1360 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1362 if ( m_constraints
)
1364 UnsetConstraints(m_constraints
);
1365 delete m_constraints
;
1367 m_constraints
= constraints
;
1368 if ( m_constraints
)
1370 // Make sure other windows know they're part of a 'meaningful relationship'
1371 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1372 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1373 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1374 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1375 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1376 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1377 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1378 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1379 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1380 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1381 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1382 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1383 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1384 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1385 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1386 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1390 // This removes any dangling pointers to this window in other windows'
1391 // constraintsInvolvedIn lists.
1392 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1396 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1397 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1398 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1399 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1400 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1401 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1402 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1403 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1404 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1405 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1406 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1407 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1408 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1409 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1410 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1411 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1415 // Back-pointer to other windows we're involved with, so if we delete this
1416 // window, we must delete any constraints we're involved with.
1417 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1419 if ( !m_constraintsInvolvedIn
)
1420 m_constraintsInvolvedIn
= new wxWindowList
;
1421 if ( !m_constraintsInvolvedIn
->Find(otherWin
) )
1422 m_constraintsInvolvedIn
->Append(otherWin
);
1425 // REMOVE back-pointer to other windows we're involved with.
1426 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1428 if ( m_constraintsInvolvedIn
)
1429 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
1432 // Reset any constraints that mention this window
1433 void wxWindowBase::DeleteRelatedConstraints()
1435 if ( m_constraintsInvolvedIn
)
1437 wxWindowList::Node
*node
= m_constraintsInvolvedIn
->GetFirst();
1440 wxWindow
*win
= node
->GetData();
1441 wxLayoutConstraints
*constr
= win
->GetConstraints();
1443 // Reset any constraints involving this window
1446 constr
->left
.ResetIfWin(this);
1447 constr
->top
.ResetIfWin(this);
1448 constr
->right
.ResetIfWin(this);
1449 constr
->bottom
.ResetIfWin(this);
1450 constr
->width
.ResetIfWin(this);
1451 constr
->height
.ResetIfWin(this);
1452 constr
->centreX
.ResetIfWin(this);
1453 constr
->centreY
.ResetIfWin(this);
1456 wxWindowList::Node
*next
= node
->GetNext();
1461 delete m_constraintsInvolvedIn
;
1462 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1466 #endif // wxUSE_CONSTRAINTS
1468 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1471 delete m_windowSizer
;
1473 m_windowSizer
= sizer
;
1475 SetAutoLayout( sizer
!= NULL
);
1478 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1480 SetSizer( sizer
, deleteOld
);
1481 sizer
->SetSizeHints( (wxWindow
*) this );
1484 #if wxUSE_CONSTRAINTS
1486 void wxWindowBase::SatisfyConstraints()
1488 wxLayoutConstraints
*constr
= GetConstraints();
1489 bool wasOk
= constr
&& constr
->AreSatisfied();
1491 ResetConstraints(); // Mark all constraints as unevaluated
1495 // if we're a top level panel (i.e. our parent is frame/dialog), our
1496 // own constraints will never be satisfied any more unless we do it
1500 while ( noChanges
> 0 )
1502 LayoutPhase1(&noChanges
);
1506 LayoutPhase2(&noChanges
);
1509 #endif // wxUSE_CONSTRAINTS
1511 bool wxWindowBase::Layout()
1513 // If there is a sizer, use it instead of the constraints
1517 GetVirtualSize(&w
, &h
);
1518 GetSizer()->SetDimension( 0, 0, w
, h
);
1520 #if wxUSE_CONSTRAINTS
1523 SatisfyConstraints(); // Find the right constraints values
1524 SetConstraintSizes(); // Recursively set the real window sizes
1531 #if wxUSE_CONSTRAINTS
1533 // first phase of the constraints evaluation: set our own constraints
1534 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1536 wxLayoutConstraints
*constr
= GetConstraints();
1538 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1541 // second phase: set the constraints for our children
1542 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1549 // Layout grand children
1555 // Do a phase of evaluating child constraints
1556 bool wxWindowBase::DoPhase(int phase
)
1558 // the list containing the children for which the constraints are already
1560 wxWindowList succeeded
;
1562 // the max number of iterations we loop before concluding that we can't set
1564 static const int maxIterations
= 500;
1566 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1570 // loop over all children setting their constraints
1571 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
1573 node
= node
->GetNext() )
1575 wxWindow
*child
= node
->GetData();
1576 if ( child
->IsTopLevel() )
1578 // top level children are not inside our client area
1582 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1584 // this one is either already ok or nothing we can do about it
1588 int tempNoChanges
= 0;
1589 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1590 : child
->LayoutPhase2(&tempNoChanges
);
1591 noChanges
+= tempNoChanges
;
1595 succeeded
.Append(child
);
1601 // constraints are set
1609 void wxWindowBase::ResetConstraints()
1611 wxLayoutConstraints
*constr
= GetConstraints();
1614 constr
->left
.SetDone(FALSE
);
1615 constr
->top
.SetDone(FALSE
);
1616 constr
->right
.SetDone(FALSE
);
1617 constr
->bottom
.SetDone(FALSE
);
1618 constr
->width
.SetDone(FALSE
);
1619 constr
->height
.SetDone(FALSE
);
1620 constr
->centreX
.SetDone(FALSE
);
1621 constr
->centreY
.SetDone(FALSE
);
1624 wxWindowList::Node
*node
= GetChildren().GetFirst();
1627 wxWindow
*win
= node
->GetData();
1628 if ( !win
->IsTopLevel() )
1629 win
->ResetConstraints();
1630 node
= node
->GetNext();
1634 // Need to distinguish between setting the 'fake' size for windows and sizers,
1635 // and setting the real values.
1636 void wxWindowBase::SetConstraintSizes(bool recurse
)
1638 wxLayoutConstraints
*constr
= GetConstraints();
1639 if ( constr
&& constr
->AreSatisfied() )
1641 int x
= constr
->left
.GetValue();
1642 int y
= constr
->top
.GetValue();
1643 int w
= constr
->width
.GetValue();
1644 int h
= constr
->height
.GetValue();
1646 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1647 (constr
->height
.GetRelationship() != wxAsIs
) )
1649 SetSize(x
, y
, w
, h
);
1653 // If we don't want to resize this window, just move it...
1659 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1660 GetClassInfo()->GetClassName(),
1666 wxWindowList::Node
*node
= GetChildren().GetFirst();
1669 wxWindow
*win
= node
->GetData();
1670 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1671 win
->SetConstraintSizes();
1672 node
= node
->GetNext();
1677 // Only set the size/position of the constraint (if any)
1678 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1680 wxLayoutConstraints
*constr
= GetConstraints();
1685 constr
->left
.SetValue(x
);
1686 constr
->left
.SetDone(TRUE
);
1690 constr
->top
.SetValue(y
);
1691 constr
->top
.SetDone(TRUE
);
1695 constr
->width
.SetValue(w
);
1696 constr
->width
.SetDone(TRUE
);
1700 constr
->height
.SetValue(h
);
1701 constr
->height
.SetDone(TRUE
);
1706 void wxWindowBase::MoveConstraint(int x
, int y
)
1708 wxLayoutConstraints
*constr
= GetConstraints();
1713 constr
->left
.SetValue(x
);
1714 constr
->left
.SetDone(TRUE
);
1718 constr
->top
.SetValue(y
);
1719 constr
->top
.SetDone(TRUE
);
1724 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1726 wxLayoutConstraints
*constr
= GetConstraints();
1729 *w
= constr
->width
.GetValue();
1730 *h
= constr
->height
.GetValue();
1736 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1738 wxLayoutConstraints
*constr
= GetConstraints();
1741 *w
= constr
->width
.GetValue();
1742 *h
= constr
->height
.GetValue();
1745 GetClientSize(w
, h
);
1748 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1750 wxLayoutConstraints
*constr
= GetConstraints();
1753 *x
= constr
->left
.GetValue();
1754 *y
= constr
->top
.GetValue();
1760 #endif // wxUSE_CONSTRAINTS
1762 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
1764 // don't do it for the dialogs/frames - they float independently of their
1766 if ( !IsTopLevel() )
1768 wxWindow
*parent
= GetParent();
1769 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
1771 wxPoint
pt(parent
->GetClientAreaOrigin());
1778 // ----------------------------------------------------------------------------
1779 // do Update UI processing for child controls
1780 // ----------------------------------------------------------------------------
1782 // TODO: should this be implemented for the child window rather
1783 // than the parent? Then you can override it e.g. for wxCheckBox
1784 // to do the Right Thing rather than having to assume a fixed number
1785 // of control classes.
1786 void wxWindowBase::UpdateWindowUI()
1789 wxUpdateUIEvent
event(GetId());
1790 event
.m_eventObject
= this;
1792 if ( GetEventHandler()->ProcessEvent(event
) )
1794 if ( event
.GetSetEnabled() )
1795 Enable(event
.GetEnabled());
1797 if ( event
.GetSetText() )
1799 wxControl
*control
= wxDynamicCastThis(wxControl
);
1803 wxTextCtrl
*text
= wxDynamicCast(control
, wxTextCtrl
);
1806 if ( event
.GetText() != text
->GetValue() )
1807 text
->SetValue(event
.GetText());
1810 #endif // wxUSE_TEXTCTRL
1812 if ( event
.GetText() != control
->GetLabel() )
1813 control
->SetLabel(event
.GetText());
1819 wxCheckBox
*checkbox
= wxDynamicCastThis(wxCheckBox
);
1822 if ( event
.GetSetChecked() )
1823 checkbox
->SetValue(event
.GetChecked());
1825 #endif // wxUSE_CHECKBOX
1828 wxRadioButton
*radiobtn
= wxDynamicCastThis(wxRadioButton
);
1831 if ( event
.GetSetChecked() )
1832 radiobtn
->SetValue(event
.GetChecked());
1834 #endif // wxUSE_RADIOBTN
1836 #endif // wxUSE_CONTROLS
1839 // ----------------------------------------------------------------------------
1840 // dialog units translations
1841 // ----------------------------------------------------------------------------
1843 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1845 int charWidth
= GetCharWidth();
1846 int charHeight
= GetCharHeight();
1847 wxPoint
pt2(-1, -1);
1849 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1851 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1856 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1858 int charWidth
= GetCharWidth();
1859 int charHeight
= GetCharHeight();
1860 wxPoint
pt2(-1, -1);
1862 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1864 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1869 // ----------------------------------------------------------------------------
1871 // ----------------------------------------------------------------------------
1873 // propagate the colour change event to the subwindows
1874 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1876 wxWindowList::Node
*node
= GetChildren().GetFirst();
1879 // Only propagate to non-top-level windows
1880 wxWindow
*win
= node
->GetData();
1881 if ( !win
->IsTopLevel() )
1883 wxSysColourChangedEvent event2
;
1884 event
.m_eventObject
= win
;
1885 win
->GetEventHandler()->ProcessEvent(event2
);
1888 node
= node
->GetNext();
1892 // the default action is to populate dialog with data when it's created
1893 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1895 TransferDataToWindow();
1898 // process Ctrl-Alt-mclick
1899 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
1902 if ( event
.ControlDown() && event
.AltDown() )
1904 // don't translate these strings
1907 #ifdef __WXUNIVERSAL__
1909 #endif // __WXUNIVERSAL__
1911 switch ( wxGetOsVersion() )
1913 case wxMOTIF_X
: port
+= _T("Motif"); break;
1915 case wxMAC_DARWIN
: port
+= _T("Mac"); break;
1916 case wxBEOS
: port
+= _T("BeOS"); break;
1920 case wxGTK_BEOS
: port
+= _T("GTK"); break;
1926 case wxWIN386
: port
+= _T("MS Windows"); break;
1930 case wxMGL_OS2
: port
+= _T("MGL"); break;
1932 case wxOS2_PM
: port
+= _T("OS/2"); break;
1933 default: port
+= _T("unknown"); break;
1936 wxMessageBox(wxString::Format(
1938 " wxWindows Library (%s port)\nVersion %u.%u.%u%s, compiled at %s %s\n Copyright (c) 1995-2002 wxWindows team"
1952 _T("wxWindows information"),
1953 wxICON_INFORMATION
| wxOK
,
1957 #endif // wxUSE_MSGDLG
1963 // ----------------------------------------------------------------------------
1965 // ----------------------------------------------------------------------------
1967 #if wxUSE_ACCESSIBILITY
1968 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
1970 if (m_accessible
&& (accessible
!= m_accessible
))
1971 delete m_accessible
;
1972 m_accessible
= accessible
;
1974 m_accessible
->SetWindow((wxWindow
*) this);
1977 // Returns the accessible object, creating if necessary.
1978 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
1981 m_accessible
= CreateAccessible();
1982 return m_accessible
;
1985 // Override to create a specific accessible object.
1986 wxAccessible
* wxWindowBase::CreateAccessible()
1988 return new wxWindowAccessible((wxWindow
*) this);
1993 // ----------------------------------------------------------------------------
1994 // list classes implementation
1995 // ----------------------------------------------------------------------------
1997 void wxWindowListNode::DeleteData()
1999 delete (wxWindow
*)GetData();
2002 // ----------------------------------------------------------------------------
2004 // ----------------------------------------------------------------------------
2006 wxBorder
wxWindowBase::GetBorder() const
2008 wxBorder border
= (wxBorder
)(m_windowStyle
& wxBORDER_MASK
);
2009 if ( border
== wxBORDER_DEFAULT
)
2011 border
= GetDefaultBorder();
2017 wxBorder
wxWindowBase::GetDefaultBorder() const
2019 return wxBORDER_NONE
;
2022 // ----------------------------------------------------------------------------
2024 // ----------------------------------------------------------------------------
2026 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2028 // here we just check if the point is inside the window or not
2030 // check the top and left border first
2031 bool outside
= x
< 0 || y
< 0;
2034 // check the right and bottom borders too
2035 wxSize size
= GetSize();
2036 outside
= x
>= size
.x
|| y
>= size
.y
;
2039 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2042 // ----------------------------------------------------------------------------
2044 // ----------------------------------------------------------------------------
2046 struct WXDLLEXPORT wxWindowNext
2050 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2052 void wxWindowBase::CaptureMouse()
2054 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this);
2056 wxWindow
*winOld
= GetCapture();
2059 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2062 wxWindowNext
*item
= new wxWindowNext
;
2064 item
->next
= ms_winCaptureNext
;
2065 ms_winCaptureNext
= item
;
2067 //else: no mouse capture to save
2072 void wxWindowBase::ReleaseMouse()
2074 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this);
2076 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2080 if ( ms_winCaptureNext
)
2082 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2084 wxWindowNext
*item
= ms_winCaptureNext
;
2085 ms_winCaptureNext
= item
->next
;
2088 //else: stack is empty, no previous capture
2090 wxLogTrace(_T("mousecapture"),
2091 _T("After ReleaseMouse() mouse is captured by %p"),
2096 void wxWindowBase::SendDestroyEvent()
2098 wxWindowDestroyEvent event
;
2099 event
.SetEventObject(this);
2100 event
.SetId(GetId());
2101 GetEventHandler()->ProcessEvent(event
);
2104 // ----------------------------------------------------------------------------
2106 // ----------------------------------------------------------------------------
2108 #if wxUSE_VALIDATORS
2110 bool wxWindowBase::TryValidator(wxEvent
& event
)
2112 // Can only use the validator of the window which
2113 // is receiving the event
2114 if ( event
.GetEventObject() == this )
2116 wxValidator
*validator
= GetValidator();
2117 if ( validator
&& validator
->ProcessEvent(event
) )
2126 #endif // wxUSE_VALIDATORS
2128 bool wxWindowBase::TryParent(wxEvent
& event
)
2130 // Carry on up the parent-child hierarchy, but only if event is a command
2131 // event: it wouldn't make sense for a parent to receive a child's size
2132 // event, for example
2133 if ( event
.IsCommandEvent() )
2135 // honour the requests to stop propagation at this window: this is
2136 // used by the dialogs, for example, to prevent processing the events
2137 // from the dialog controls in the parent frame which rarely, if ever,
2139 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2141 wxWindow
*parent
= GetParent();
2142 if ( parent
&& !parent
->IsBeingDeleted() )
2143 return parent
->GetEventHandler()->ProcessEvent(event
);
2147 return wxEvtHandler::TryParent(event
);
2150 // ----------------------------------------------------------------------------
2152 // ----------------------------------------------------------------------------
2154 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2156 while ( win
&& !win
->IsTopLevel() )
2157 win
= win
->GetParent();
2162 #if wxUSE_ACCESSIBILITY
2163 // ----------------------------------------------------------------------------
2164 // accessible object for windows
2165 // ----------------------------------------------------------------------------
2167 // Can return either a child object, or an integer
2168 // representing the child element, starting from 1.
2169 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& pt
, int* childId
, wxAccessible
** childObject
)
2171 wxASSERT( GetWindow() != NULL
);
2175 return wxACC_NOT_IMPLEMENTED
;
2178 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2179 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2181 wxASSERT( GetWindow() != NULL
);
2185 wxWindow
* win
= NULL
;
2192 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2194 win
= (wxWindow
*) GetWindow()->GetChildren().Nth(elementId
-1)->GetData();
2201 rect
= win
->GetRect();
2202 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2203 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2207 return wxACC_NOT_IMPLEMENTED
;
2210 // Navigates from fromId to toId/toObject.
2211 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2212 int* toId
, wxAccessible
** toObject
)
2214 wxASSERT( GetWindow() != NULL
);
2220 case wxNAVDIR_FIRSTCHILD
:
2222 if (GetWindow()->GetChildren().GetCount() == 0)
2224 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2225 *toObject
= childWindow
->GetOrCreateAccessible();
2229 case wxNAVDIR_LASTCHILD
:
2231 if (GetWindow()->GetChildren().GetCount() == 0)
2233 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2234 *toObject
= childWindow
->GetOrCreateAccessible();
2238 case wxNAVDIR_RIGHT
:
2242 wxWindowList::Node
*node
= NULL
;
2245 // Can't navigate to sibling of this window
2246 // if we're a top-level window.
2247 if (!GetWindow()->GetParent())
2248 return wxACC_NOT_IMPLEMENTED
;
2250 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2254 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2255 node
= (wxWindowList::Node
*) GetWindow()->GetChildren().Nth(fromId
-1);
2258 if (node
&& node
->GetNext())
2260 wxWindow
* nextWindow
= (wxWindow
*) node
->GetNext()->Data();
2261 *toObject
= nextWindow
->GetOrCreateAccessible();
2269 case wxNAVDIR_PREVIOUS
:
2271 wxWindowList::Node
*node
= NULL
;
2274 // Can't navigate to sibling of this window
2275 // if we're a top-level window.
2276 if (!GetWindow()->GetParent())
2277 return wxACC_NOT_IMPLEMENTED
;
2279 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2283 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2284 node
= (wxWindowList::Node
*) GetWindow()->GetChildren().Nth(fromId
-1);
2287 if (node
&& node
->GetPrevious())
2289 wxWindow
* previousWindow
= (wxWindow
*) node
->GetPrevious()->Data();
2290 *toObject
= previousWindow
->GetOrCreateAccessible();
2298 return wxACC_NOT_IMPLEMENTED
;
2301 // Gets the name of the specified object.
2302 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2304 wxASSERT( GetWindow() != NULL
);
2310 // If a child, leave wxWindows to call the function on the actual
2313 return wxACC_NOT_IMPLEMENTED
;
2315 // This will eventually be replaced by specialised
2316 // accessible classes, one for each kind of wxWindows
2317 // control or window.
2318 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2319 title
= ((wxButton
*) GetWindow())->GetLabel();
2321 title
= GetWindow()->GetName();
2323 if (!title
.IsEmpty())
2329 return wxACC_NOT_IMPLEMENTED
;
2332 // Gets the number of children.
2333 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2335 wxASSERT( GetWindow() != NULL
);
2339 *childId
= (int) GetWindow()->GetChildren().GetCount();
2343 // Gets the specified child (starting from 1).
2344 // If *child is NULL and return value is wxACC_OK,
2345 // this means that the child is a simple element and
2346 // not an accessible object.
2347 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2349 wxASSERT( GetWindow() != NULL
);
2359 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2362 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().Nth(childId
-1)->GetData();
2363 *child
= childWindow
->GetOrCreateAccessible();
2370 // Gets the parent, or NULL.
2371 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2373 wxASSERT( GetWindow() != NULL
);
2377 wxWindow
* parentWindow
= GetWindow()->GetParent();
2385 *parent
= parentWindow
->GetOrCreateAccessible();
2393 // Performs the default action. childId is 0 (the action for this object)
2394 // or > 0 (the action for a child).
2395 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2396 // window (e.g. an edit control).
2397 wxAccStatus
wxWindowAccessible::DoDefaultAction(int childId
)
2399 wxASSERT( GetWindow() != NULL
);
2403 return wxACC_NOT_IMPLEMENTED
;
2406 // Gets the default action for this object (0) or > 0 (the action for a child).
2407 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2408 // string if there is no action.
2409 // The retrieved string describes the action that is performed on an object,
2410 // not what the object does as a result. For example, a toolbar button that prints
2411 // a document has a default action of "Press" rather than "Prints the current document."
2412 wxAccStatus
wxWindowAccessible::GetDefaultAction(int childId
, wxString
* actionName
)
2414 wxASSERT( GetWindow() != NULL
);
2418 return wxACC_NOT_IMPLEMENTED
;
2421 // Returns the description for this object or a child.
2422 wxAccStatus
wxWindowAccessible::GetDescription(int childId
, wxString
* description
)
2424 wxASSERT( GetWindow() != NULL
);
2428 wxString
ht(GetWindow()->GetHelpText());
2434 return wxACC_NOT_IMPLEMENTED
;
2437 // Returns help text for this object or a child, similar to tooltip text.
2438 wxAccStatus
wxWindowAccessible::GetHelpText(int childId
, wxString
* helpText
)
2440 wxASSERT( GetWindow() != NULL
);
2444 wxString
ht(GetWindow()->GetHelpText());
2450 return wxACC_NOT_IMPLEMENTED
;
2453 // Returns the keyboard shortcut for this object or child.
2454 // Return e.g. ALT+K
2455 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int childId
, wxString
* shortcut
)
2457 wxASSERT( GetWindow() != NULL
);
2461 return wxACC_NOT_IMPLEMENTED
;
2464 // Returns a role constant.
2465 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
2467 wxASSERT( GetWindow() != NULL
);
2471 // If a child, leave wxWindows to call the function on the actual
2474 return wxACC_NOT_IMPLEMENTED
;
2476 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2477 return wxACC_NOT_IMPLEMENTED
;
2479 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2480 return wxACC_NOT_IMPLEMENTED
;
2483 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2484 return wxACC_NOT_IMPLEMENTED
;
2487 //*role = wxROLE_SYSTEM_CLIENT;
2488 *role
= wxROLE_SYSTEM_CLIENT
;
2491 return wxACC_NOT_IMPLEMENTED
;
2494 // Returns a state constant.
2495 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
2497 wxASSERT( GetWindow() != NULL
);
2501 // If a child, leave wxWindows to call the function on the actual
2504 return wxACC_NOT_IMPLEMENTED
;
2506 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2507 return wxACC_NOT_IMPLEMENTED
;
2510 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2511 return wxACC_NOT_IMPLEMENTED
;
2514 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2515 return wxACC_NOT_IMPLEMENTED
;
2521 return wxACC_NOT_IMPLEMENTED
;
2524 // Returns a localized string representing the value for the object
2526 wxAccStatus
wxWindowAccessible::GetValue(int childId
, wxString
* strValue
)
2528 wxASSERT( GetWindow() != NULL
);
2532 return wxACC_NOT_IMPLEMENTED
;
2535 // Selects the object or child.
2536 wxAccStatus
wxWindowAccessible::Select(int childId
, wxAccSelectionFlags selectFlags
)
2538 wxASSERT( GetWindow() != NULL
);
2542 return wxACC_NOT_IMPLEMENTED
;
2545 // Gets the window with the keyboard focus.
2546 // If childId is 0 and child is NULL, no object in
2547 // this subhierarchy has the focus.
2548 // If this object has the focus, child should be 'this'.
2549 wxAccStatus
wxWindowAccessible::GetFocus(int* childId
, wxAccessible
** child
)
2551 wxASSERT( GetWindow() != NULL
);
2555 return wxACC_NOT_IMPLEMENTED
;
2558 // Gets a variant representing the selected children
2560 // Acceptable values:
2561 // - a null variant (IsNull() returns TRUE)
2562 // - a list variant (GetType() == wxT("list")
2563 // - an integer representing the selected child element,
2564 // or 0 if this object is selected (GetType() == wxT("long")
2565 // - a "void*" pointer to a wxAccessible child object
2566 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* selections
)
2568 wxASSERT( GetWindow() != NULL
);
2572 return wxACC_NOT_IMPLEMENTED
;
2575 #endif // wxUSE_ACCESSIBILITY