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 #if wxUSE_CONSTRAINTS
160 // no constraints whatsoever
161 m_constraints
= (wxLayoutConstraints
*) NULL
;
162 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
163 #endif // wxUSE_CONSTRAINTS
165 m_windowSizer
= (wxSizer
*) NULL
;
166 m_containingSizer
= (wxSizer
*) NULL
;
167 m_autoLayout
= FALSE
;
169 #if wxUSE_DRAG_AND_DROP
170 m_dropTarget
= (wxDropTarget
*)NULL
;
171 #endif // wxUSE_DRAG_AND_DROP
174 m_tooltip
= (wxToolTip
*)NULL
;
175 #endif // wxUSE_TOOLTIPS
178 m_caret
= (wxCaret
*)NULL
;
179 #endif // wxUSE_CARET
182 m_hasCustomPalette
= FALSE
;
183 #endif // wxUSE_PALETTE
185 #if wxUSE_ACCESSIBILITY
189 m_virtualSize
= wxDefaultSize
;
194 m_maxVirtualHeight
= -1;
196 // Whether we're using the current theme for this window (wxGTK only for now)
197 m_themeEnabled
= FALSE
;
200 // common part of window creation process
201 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
203 const wxPoint
& WXUNUSED(pos
),
204 const wxSize
& WXUNUSED(size
),
206 const wxValidator
& validator
,
207 const wxString
& name
)
209 // m_isWindow is set to TRUE in wxWindowBase::Init() as well as many other
210 // member variables - check that it has been called (will catch the case
211 // when a new ctor is added which doesn't call InitWindow)
212 wxASSERT_MSG( m_isWindow
, wxT("Init() must have been called before!") );
215 // wxGTK doesn't allow to create controls with static box as the parent so
216 // this will result in a crash when the program is ported to wxGTK so warn
219 // if you get this assert, the correct solution is to create the controls
220 // as siblings of the static box
221 wxASSERT_MSG( !parent
|| !wxDynamicCast(parent
, wxStaticBox
),
222 _T("wxStaticBox can't be used as a window parent!") );
223 #endif // wxUSE_STATBOX
225 // ids are limited to 16 bits under MSW so if you care about portability,
226 // it's not a good idea to use ids out of this range (and negative ids are
227 // reserved for wxWindows own usage)
228 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767),
229 _T("invalid id value") );
231 // generate a new id if the user doesn't care about it
232 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
235 SetWindowStyleFlag(style
);
239 SetValidator(validator
);
240 #endif // wxUSE_VALIDATORS
242 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
243 // have it too - like this it's possible to set it only in the top level
244 // dialog/frame and all children will inherit it by defult
245 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
247 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
253 // ----------------------------------------------------------------------------
255 // ----------------------------------------------------------------------------
258 wxWindowBase::~wxWindowBase()
260 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
262 // FIXME if these 2 cases result from programming errors in the user code
263 // we should probably assert here instead of silently fixing them
265 // Just in case the window has been Closed, but we're then deleting
266 // immediately: don't leave dangling pointers.
267 wxPendingDelete
.DeleteObject(this);
269 // Just in case we've loaded a top-level window via LoadNativeDialog but
270 // we weren't a dialog class
271 wxTopLevelWindows
.DeleteObject(this);
273 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
278 #endif // wxUSE_CARET
281 if ( m_windowValidator
)
282 delete m_windowValidator
;
283 #endif // wxUSE_VALIDATORS
285 #if wxUSE_CONSTRAINTS
286 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
287 // at deleted windows as they delete themselves.
288 DeleteRelatedConstraints();
292 // This removes any dangling pointers to this window in other windows'
293 // constraintsInvolvedIn lists.
294 UnsetConstraints(m_constraints
);
295 delete m_constraints
;
296 m_constraints
= NULL
;
299 #endif // wxUSE_CONSTRAINTS
301 if ( m_containingSizer
)
302 m_containingSizer
->Detach( (wxWindow
*)this );
305 delete m_windowSizer
;
307 #if wxUSE_DRAG_AND_DROP
310 #endif // wxUSE_DRAG_AND_DROP
315 #endif // wxUSE_TOOLTIPS
317 #if wxUSE_ACCESSIBILITY
322 // reset the dangling pointer our parent window may keep to us
323 if ( m_parent
&& m_parent
->GetDefaultItem() == this )
325 m_parent
->SetDefaultItem(NULL
);
329 bool wxWindowBase::Destroy()
336 bool wxWindowBase::Close(bool force
)
338 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
339 event
.SetEventObject(this);
340 #if WXWIN_COMPATIBILITY
341 event
.SetForce(force
);
342 #endif // WXWIN_COMPATIBILITY
343 event
.SetCanVeto(!force
);
345 // return FALSE if window wasn't closed because the application vetoed the
347 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
350 bool wxWindowBase::DestroyChildren()
352 wxWindowList::Node
*node
;
355 // we iterate until the list becomes empty
356 node
= GetChildren().GetFirst();
360 wxWindow
*child
= node
->GetData();
362 wxASSERT_MSG( child
, wxT("children list contains empty nodes") );
367 wxASSERT_MSG( !GetChildren().Find(child
),
368 wxT("child didn't remove itself using RemoveChild()") );
374 // ----------------------------------------------------------------------------
375 // size/position related methods
376 // ----------------------------------------------------------------------------
378 // centre the window with respect to its parent in either (or both) directions
379 void wxWindowBase::Centre(int direction
)
381 // the position/size of the parent window or of the entire screen
383 int widthParent
, heightParent
;
385 wxWindow
*parent
= NULL
;
387 if ( !(direction
& wxCENTRE_ON_SCREEN
) )
389 // find the parent to centre this window on: it should be the
390 // immediate parent for the controls but the top level parent for the
391 // top level windows (like dialogs)
392 parent
= GetParent();
395 while ( parent
&& !parent
->IsTopLevel() )
397 parent
= parent
->GetParent();
401 // there is no wxTopLevelWindow under wxMotif yet
403 // we shouldn't center the dialog on the iconized window: under
404 // Windows, for example, this places it completely off the screen
407 wxTopLevelWindow
*winTop
= wxDynamicCast(parent
, wxTopLevelWindow
);
408 if ( winTop
&& winTop
->IsIconized() )
413 #endif // __WXMOTIF__
415 // did we find the parent?
419 direction
|= wxCENTRE_ON_SCREEN
;
423 if ( direction
& wxCENTRE_ON_SCREEN
)
425 // centre with respect to the whole screen
426 wxDisplaySize(&widthParent
, &heightParent
);
432 // centre on the parent
433 parent
->GetSize(&widthParent
, &heightParent
);
435 // adjust to the parents position
436 posParent
= parent
->GetPosition();
440 // centre inside the parents client rectangle
441 parent
->GetClientSize(&widthParent
, &heightParent
);
446 GetSize(&width
, &height
);
451 if ( direction
& wxHORIZONTAL
)
452 xNew
= (widthParent
- width
)/2;
454 if ( direction
& wxVERTICAL
)
455 yNew
= (heightParent
- height
)/2;
460 // Base size of the visible dimensions of the display
461 // to take into account the taskbar
462 wxRect rect
= wxGetClientDisplayRect();
463 wxSize
size (rect
.width
,rect
.height
);
465 // NB: in wxMSW, negative position may not neccessary mean "out of screen",
466 // but it may mean that the window is placed on other than the main
467 // display. Therefore we only make sure centered window is on the main display
468 // if the parent is at least partially present here.
469 if (posParent
.x
+ widthParent
>= 0) // if parent is (partially) on the main display
473 else if (xNew
+width
> size
.x
)
474 xNew
= size
.x
-width
-1;
476 if (posParent
.y
+ heightParent
>= 0) // if parent is (partially) on the main display
478 if (yNew
+height
> size
.y
)
479 yNew
= size
.y
-height
-1;
481 // Make certain that the title bar is initially visible
482 // always, even if this would push the bottom of the
483 // dialog of the visible area of the display
488 // move the window to this position (keeping the old size but using
489 // SetSize() and not Move() to allow xNew and/or yNew to be -1)
490 SetSize(xNew
, yNew
, width
, height
, wxSIZE_ALLOW_MINUS_ONE
);
493 // fits the window around the children
494 void wxWindowBase::Fit()
496 if ( GetChildren().GetCount() > 0 )
498 SetClientSize(DoGetBestSize());
500 //else: do nothing if we have no children
503 // fits virtual size (ie. scrolled area etc.) around children
504 void wxWindowBase::FitInside()
506 if ( GetChildren().GetCount() > 0 )
508 SetVirtualSize( GetBestVirtualSize() );
512 // return the size best suited for the current window
513 wxSize
wxWindowBase::DoGetBestSize() const
517 return m_windowSizer
->GetMinSize();
519 #if wxUSE_CONSTRAINTS
520 else if ( m_constraints
)
522 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
524 // our minimal acceptable size is such that all our windows fit inside
528 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
530 node
= node
->GetNext() )
532 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
535 // it's not normal that we have an unconstrained child, but
536 // what can we do about it?
540 int x
= c
->right
.GetValue(),
541 y
= c
->bottom
.GetValue();
549 // TODO: we must calculate the overlaps somehow, otherwise we
550 // will never return a size bigger than the current one :-(
553 return wxSize(maxX
, maxY
);
555 #endif // wxUSE_CONSTRAINTS
556 else if ( GetChildren().GetCount() > 0 )
558 // our minimal acceptable size is such that all our windows fit inside
562 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
564 node
= node
->GetNext() )
566 wxWindow
*win
= node
->GetData();
567 if ( win
->IsTopLevel()
569 || wxDynamicCast(win
, wxStatusBar
)
570 #endif // wxUSE_STATUSBAR
573 // dialogs and frames lie in different top level windows -
574 // don't deal with them here; as for the status bars, they
575 // don't lie in the client area at all
580 win
->GetPosition(&wx
, &wy
);
582 // if the window hadn't been positioned yet, assume that it is in
589 win
->GetSize(&ww
, &wh
);
590 if ( wx
+ ww
> maxX
)
592 if ( wy
+ wh
> maxY
)
596 // for compatibility with the old versions and because it really looks
597 // slightly more pretty like this, add a pad
601 return wxSize(maxX
, maxY
);
605 // for a generic window there is no natural best size - just use the
611 // by default the origin is not shifted
612 wxPoint
wxWindowBase::GetClientAreaOrigin() const
614 return wxPoint(0, 0);
617 // set the min/max size of the window
618 void wxWindowBase::SetSizeHints(int minW
, int minH
,
620 int WXUNUSED(incW
), int WXUNUSED(incH
))
622 // setting min width greater than max width leads to infinite loops under
623 // X11 and generally doesn't make any sense, so don't allow it
624 wxCHECK_RET( (minW
== -1 || maxW
== -1 || minW
<= maxW
) &&
625 (minH
== -1 || maxH
== -1 || minH
<= maxH
),
626 _T("min width/height must be less than max width/height!") );
634 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
637 m_minVirtualWidth
= minW
;
638 m_maxVirtualWidth
= maxW
;
639 m_minVirtualHeight
= minH
;
640 m_maxVirtualHeight
= maxH
;
643 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
645 if ( m_minVirtualWidth
!= -1 && m_minVirtualWidth
> x
)
646 x
= m_minVirtualWidth
;
647 if ( m_maxVirtualWidth
!= -1 && m_maxVirtualWidth
< x
)
648 x
= m_maxVirtualWidth
;
649 if ( m_minVirtualHeight
!= -1 && m_minVirtualHeight
> y
)
650 y
= m_minVirtualHeight
;
651 if ( m_maxVirtualHeight
!= -1 && m_maxVirtualHeight
< y
)
652 y
= m_maxVirtualHeight
;
654 m_virtualSize
= wxSize(x
, y
);
657 wxSize
wxWindowBase::DoGetVirtualSize() const
659 wxSize
s( GetClientSize() );
661 return wxSize( wxMax( m_virtualSize
.GetWidth(), s
.GetWidth() ),
662 wxMax( m_virtualSize
.GetHeight(), s
.GetHeight() ) );
665 // ----------------------------------------------------------------------------
666 // show/hide/enable/disable the window
667 // ----------------------------------------------------------------------------
669 bool wxWindowBase::Show(bool show
)
671 if ( show
!= m_isShown
)
683 bool wxWindowBase::Enable(bool enable
)
685 if ( enable
!= m_isEnabled
)
687 m_isEnabled
= enable
;
696 // ----------------------------------------------------------------------------
698 // ----------------------------------------------------------------------------
700 bool wxWindowBase::IsTopLevel() const
705 // ----------------------------------------------------------------------------
706 // reparenting the window
707 // ----------------------------------------------------------------------------
709 void wxWindowBase::AddChild(wxWindowBase
*child
)
711 wxCHECK_RET( child
, wxT("can't add a NULL child") );
713 // this should never happen and it will lead to a crash later if it does
714 // because RemoveChild() will remove only one node from the children list
715 // and the other(s) one(s) will be left with dangling pointers in them
716 wxASSERT_MSG( !GetChildren().Find(child
), _T("AddChild() called twice") );
718 GetChildren().Append(child
);
719 child
->SetParent(this);
722 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
724 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
726 GetChildren().DeleteObject(child
);
727 child
->SetParent((wxWindow
*)NULL
);
730 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
732 wxWindow
*oldParent
= GetParent();
733 if ( newParent
== oldParent
)
739 // unlink this window from the existing parent.
742 oldParent
->RemoveChild(this);
746 wxTopLevelWindows
.DeleteObject(this);
749 // add it to the new one
752 newParent
->AddChild(this);
756 wxTopLevelWindows
.Append(this);
762 // ----------------------------------------------------------------------------
763 // event handler stuff
764 // ----------------------------------------------------------------------------
766 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
768 wxEvtHandler
*handlerOld
= GetEventHandler();
770 handler
->SetNextHandler(handlerOld
);
773 GetEventHandler()->SetPreviousHandler(handler
);
775 SetEventHandler(handler
);
778 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
780 wxEvtHandler
*handlerA
= GetEventHandler();
783 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
784 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
787 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
788 SetEventHandler(handlerB
);
793 handlerA
= (wxEvtHandler
*)NULL
;
800 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
802 wxCHECK_MSG( handler
, FALSE
, _T("RemoveEventHandler(NULL) called") );
804 wxEvtHandler
*handlerPrev
= NULL
,
805 *handlerCur
= GetEventHandler();
808 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
810 if ( handlerCur
== handler
)
814 handlerPrev
->SetNextHandler(handlerNext
);
818 SetEventHandler(handlerNext
);
823 handlerNext
->SetPreviousHandler ( handlerPrev
);
825 handler
->SetNextHandler(NULL
);
830 handlerPrev
= handlerCur
;
831 handlerCur
= handlerNext
;
834 wxFAIL_MSG( _T("where has the event handler gone?") );
839 // ----------------------------------------------------------------------------
841 // ----------------------------------------------------------------------------
843 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
845 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
848 m_backgroundColour
= colour
;
855 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
857 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
860 m_foregroundColour
= colour
;
867 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
869 // setting an invalid cursor is ok, it means that we don't have any special
871 if ( m_cursor
== cursor
)
882 bool wxWindowBase::SetFont(const wxFont
& font
)
884 // don't try to set invalid font, always fall back to the default
885 const wxFont
& fontOk
= font
.Ok() ? font
: *wxSWISS_FONT
;
887 if ( fontOk
== m_font
)
902 void wxWindowBase::SetPalette(const wxPalette
& pal
)
904 m_hasCustomPalette
= TRUE
;
907 // VZ: can anyone explain me what do we do here?
908 wxWindowDC
d((wxWindow
*) this);
912 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
914 wxWindow
*win
= (wxWindow
*)this;
915 while ( win
&& !win
->HasCustomPalette() )
917 win
= win
->GetParent();
923 #endif // wxUSE_PALETTE
926 void wxWindowBase::SetCaret(wxCaret
*caret
)
937 wxASSERT_MSG( m_caret
->GetWindow() == this,
938 wxT("caret should be created associated to this window") );
941 #endif // wxUSE_CARET
944 // ----------------------------------------------------------------------------
946 // ----------------------------------------------------------------------------
948 void wxWindowBase::SetValidator(const wxValidator
& validator
)
950 if ( m_windowValidator
)
951 delete m_windowValidator
;
953 m_windowValidator
= (wxValidator
*)validator
.Clone();
955 if ( m_windowValidator
)
956 m_windowValidator
->SetWindow(this) ;
958 #endif // wxUSE_VALIDATORS
960 // ----------------------------------------------------------------------------
961 // update region stuff
962 // ----------------------------------------------------------------------------
964 wxRect
wxWindowBase::GetUpdateClientRect() const
966 wxRegion rgnUpdate
= GetUpdateRegion();
967 rgnUpdate
.Intersect(GetClientRect());
968 wxRect rectUpdate
= rgnUpdate
.GetBox();
969 wxPoint ptOrigin
= GetClientAreaOrigin();
970 rectUpdate
.x
-= ptOrigin
.x
;
971 rectUpdate
.y
-= ptOrigin
.y
;
976 bool wxWindowBase::IsExposed(int x
, int y
) const
978 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
981 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
983 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
986 // ----------------------------------------------------------------------------
987 // find child window by id or name
988 // ----------------------------------------------------------------------------
990 wxWindow
*wxWindowBase::FindWindow( long id
)
992 if ( id
== m_windowId
)
993 return (wxWindow
*)this;
995 wxWindowBase
*res
= (wxWindow
*)NULL
;
996 wxWindowList::Node
*node
;
997 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
999 wxWindowBase
*child
= node
->GetData();
1000 res
= child
->FindWindow( id
);
1003 return (wxWindow
*)res
;
1006 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
1008 if ( name
== m_windowName
)
1009 return (wxWindow
*)this;
1011 wxWindowBase
*res
= (wxWindow
*)NULL
;
1012 wxWindowList::Node
*node
;
1013 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1015 wxWindow
*child
= node
->GetData();
1016 res
= child
->FindWindow(name
);
1019 return (wxWindow
*)res
;
1023 // find any window by id or name or label: If parent is non-NULL, look through
1024 // children for a label or title matching the specified string. If NULL, look
1025 // through all top-level windows.
1027 // to avoid duplicating code we reuse the same helper function but with
1028 // different comparators
1030 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1031 const wxString
& label
, long id
);
1034 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1037 return win
->GetLabel() == label
;
1041 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1044 return win
->GetName() == label
;
1048 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1051 return win
->GetId() == id
;
1054 // recursive helper for the FindWindowByXXX() functions
1056 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1057 const wxString
& label
,
1059 wxFindWindowCmp cmp
)
1063 // see if this is the one we're looking for
1064 if ( (*cmp
)(parent
, label
, id
) )
1065 return (wxWindow
*)parent
;
1067 // It wasn't, so check all its children
1068 for ( wxWindowList::Node
* node
= parent
->GetChildren().GetFirst();
1070 node
= node
->GetNext() )
1072 // recursively check each child
1073 wxWindow
*win
= (wxWindow
*)node
->GetData();
1074 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1084 // helper for FindWindowByXXX()
1086 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1087 const wxString
& label
,
1089 wxFindWindowCmp cmp
)
1093 // just check parent and all its children
1094 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1097 // start at very top of wx's windows
1098 for ( wxWindowList::Node
* node
= wxTopLevelWindows
.GetFirst();
1100 node
= node
->GetNext() )
1102 // recursively check each window & its children
1103 wxWindow
*win
= node
->GetData();
1104 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1114 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1116 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1121 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1123 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1127 // fall back to the label
1128 win
= FindWindowByLabel(title
, parent
);
1136 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1138 return wxFindWindowHelper(parent
, _T(""), id
, wxFindWindowCmpIds
);
1141 // ----------------------------------------------------------------------------
1142 // dialog oriented functions
1143 // ----------------------------------------------------------------------------
1145 void wxWindowBase::MakeModal(bool modal
)
1147 // Disable all other windows
1150 wxWindowList::Node
*node
= wxTopLevelWindows
.GetFirst();
1153 wxWindow
*win
= node
->GetData();
1155 win
->Enable(!modal
);
1157 node
= node
->GetNext();
1162 bool wxWindowBase::Validate()
1164 #if wxUSE_VALIDATORS
1165 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1167 wxWindowList::Node
*node
;
1168 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1170 wxWindowBase
*child
= node
->GetData();
1171 wxValidator
*validator
= child
->GetValidator();
1172 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1177 if ( recurse
&& !child
->Validate() )
1182 #endif // wxUSE_VALIDATORS
1187 bool wxWindowBase::TransferDataToWindow()
1189 #if wxUSE_VALIDATORS
1190 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1192 wxWindowList::Node
*node
;
1193 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1195 wxWindowBase
*child
= node
->GetData();
1196 wxValidator
*validator
= child
->GetValidator();
1197 if ( validator
&& !validator
->TransferToWindow() )
1199 wxLogWarning(_("Could not transfer data to window"));
1201 wxLog::FlushActive();
1209 if ( !child
->TransferDataToWindow() )
1211 // warning already given
1216 #endif // wxUSE_VALIDATORS
1221 bool wxWindowBase::TransferDataFromWindow()
1223 #if wxUSE_VALIDATORS
1224 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1226 wxWindowList::Node
*node
;
1227 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1229 wxWindow
*child
= node
->GetData();
1230 wxValidator
*validator
= child
->GetValidator();
1231 if ( validator
&& !validator
->TransferFromWindow() )
1233 // nop warning here because the application is supposed to give
1234 // one itself - we don't know here what might have gone wrongly
1241 if ( !child
->TransferDataFromWindow() )
1243 // warning already given
1248 #endif // wxUSE_VALIDATORS
1253 void wxWindowBase::InitDialog()
1255 wxInitDialogEvent
event(GetId());
1256 event
.SetEventObject( this );
1257 GetEventHandler()->ProcessEvent(event
);
1260 // ----------------------------------------------------------------------------
1261 // context-sensitive help support
1262 // ----------------------------------------------------------------------------
1266 // associate this help text with this window
1267 void wxWindowBase::SetHelpText(const wxString
& text
)
1269 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1272 helpProvider
->AddHelp(this, text
);
1276 // associate this help text with all windows with the same id as this
1278 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1280 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1283 helpProvider
->AddHelp(GetId(), text
);
1287 // get the help string associated with this window (may be empty)
1288 wxString
wxWindowBase::GetHelpText() const
1291 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1294 text
= helpProvider
->GetHelp(this);
1300 // show help for this window
1301 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1303 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1306 if ( helpProvider
->ShowHelp(this) )
1308 // skip the event.Skip() below
1316 #endif // wxUSE_HELP
1318 // ----------------------------------------------------------------------------
1319 // tooltipsroot.Replace("\\", "/");
1320 // ----------------------------------------------------------------------------
1324 void wxWindowBase::SetToolTip( const wxString
&tip
)
1326 // don't create the new tooltip if we already have one
1329 m_tooltip
->SetTip( tip
);
1333 SetToolTip( new wxToolTip( tip
) );
1336 // setting empty tooltip text does not remove the tooltip any more - use
1337 // SetToolTip((wxToolTip *)NULL) for this
1340 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1345 m_tooltip
= tooltip
;
1348 #endif // wxUSE_TOOLTIPS
1350 // ----------------------------------------------------------------------------
1351 // constraints and sizers
1352 // ----------------------------------------------------------------------------
1354 #if wxUSE_CONSTRAINTS
1356 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1358 if ( m_constraints
)
1360 UnsetConstraints(m_constraints
);
1361 delete m_constraints
;
1363 m_constraints
= constraints
;
1364 if ( m_constraints
)
1366 // Make sure other windows know they're part of a 'meaningful relationship'
1367 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1368 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1369 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1370 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1371 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1372 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1373 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1374 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1375 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1376 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1377 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1378 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1379 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1380 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1381 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1382 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1386 // This removes any dangling pointers to this window in other windows'
1387 // constraintsInvolvedIn lists.
1388 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1392 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1393 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1394 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1395 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1396 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1397 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1398 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1399 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1400 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1401 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1402 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1403 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1404 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1405 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1406 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1407 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1411 // Back-pointer to other windows we're involved with, so if we delete this
1412 // window, we must delete any constraints we're involved with.
1413 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1415 if ( !m_constraintsInvolvedIn
)
1416 m_constraintsInvolvedIn
= new wxWindowList
;
1417 if ( !m_constraintsInvolvedIn
->Find(otherWin
) )
1418 m_constraintsInvolvedIn
->Append(otherWin
);
1421 // REMOVE back-pointer to other windows we're involved with.
1422 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1424 if ( m_constraintsInvolvedIn
)
1425 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
1428 // Reset any constraints that mention this window
1429 void wxWindowBase::DeleteRelatedConstraints()
1431 if ( m_constraintsInvolvedIn
)
1433 wxWindowList::Node
*node
= m_constraintsInvolvedIn
->GetFirst();
1436 wxWindow
*win
= node
->GetData();
1437 wxLayoutConstraints
*constr
= win
->GetConstraints();
1439 // Reset any constraints involving this window
1442 constr
->left
.ResetIfWin(this);
1443 constr
->top
.ResetIfWin(this);
1444 constr
->right
.ResetIfWin(this);
1445 constr
->bottom
.ResetIfWin(this);
1446 constr
->width
.ResetIfWin(this);
1447 constr
->height
.ResetIfWin(this);
1448 constr
->centreX
.ResetIfWin(this);
1449 constr
->centreY
.ResetIfWin(this);
1452 wxWindowList::Node
*next
= node
->GetNext();
1457 delete m_constraintsInvolvedIn
;
1458 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1462 #endif // wxUSE_CONSTRAINTS
1464 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1467 delete m_windowSizer
;
1469 m_windowSizer
= sizer
;
1471 SetAutoLayout( sizer
!= NULL
);
1474 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1476 SetSizer( sizer
, deleteOld
);
1477 sizer
->SetSizeHints( (wxWindow
*) this );
1480 #if wxUSE_CONSTRAINTS
1482 void wxWindowBase::SatisfyConstraints()
1484 wxLayoutConstraints
*constr
= GetConstraints();
1485 bool wasOk
= constr
&& constr
->AreSatisfied();
1487 ResetConstraints(); // Mark all constraints as unevaluated
1491 // if we're a top level panel (i.e. our parent is frame/dialog), our
1492 // own constraints will never be satisfied any more unless we do it
1496 while ( noChanges
> 0 )
1498 LayoutPhase1(&noChanges
);
1502 LayoutPhase2(&noChanges
);
1505 #endif // wxUSE_CONSTRAINTS
1507 bool wxWindowBase::Layout()
1509 // If there is a sizer, use it instead of the constraints
1513 GetVirtualSize(&w
, &h
);
1514 GetSizer()->SetDimension( 0, 0, w
, h
);
1516 #if wxUSE_CONSTRAINTS
1519 SatisfyConstraints(); // Find the right constraints values
1520 SetConstraintSizes(); // Recursively set the real window sizes
1527 #if wxUSE_CONSTRAINTS
1529 // first phase of the constraints evaluation: set our own constraints
1530 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1532 wxLayoutConstraints
*constr
= GetConstraints();
1534 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1537 // second phase: set the constraints for our children
1538 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1545 // Layout grand children
1551 // Do a phase of evaluating child constraints
1552 bool wxWindowBase::DoPhase(int phase
)
1554 // the list containing the children for which the constraints are already
1556 wxWindowList succeeded
;
1558 // the max number of iterations we loop before concluding that we can't set
1560 static const int maxIterations
= 500;
1562 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1566 // loop over all children setting their constraints
1567 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
1569 node
= node
->GetNext() )
1571 wxWindow
*child
= node
->GetData();
1572 if ( child
->IsTopLevel() )
1574 // top level children are not inside our client area
1578 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1580 // this one is either already ok or nothing we can do about it
1584 int tempNoChanges
= 0;
1585 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1586 : child
->LayoutPhase2(&tempNoChanges
);
1587 noChanges
+= tempNoChanges
;
1591 succeeded
.Append(child
);
1597 // constraints are set
1605 void wxWindowBase::ResetConstraints()
1607 wxLayoutConstraints
*constr
= GetConstraints();
1610 constr
->left
.SetDone(FALSE
);
1611 constr
->top
.SetDone(FALSE
);
1612 constr
->right
.SetDone(FALSE
);
1613 constr
->bottom
.SetDone(FALSE
);
1614 constr
->width
.SetDone(FALSE
);
1615 constr
->height
.SetDone(FALSE
);
1616 constr
->centreX
.SetDone(FALSE
);
1617 constr
->centreY
.SetDone(FALSE
);
1620 wxWindowList::Node
*node
= GetChildren().GetFirst();
1623 wxWindow
*win
= node
->GetData();
1624 if ( !win
->IsTopLevel() )
1625 win
->ResetConstraints();
1626 node
= node
->GetNext();
1630 // Need to distinguish between setting the 'fake' size for windows and sizers,
1631 // and setting the real values.
1632 void wxWindowBase::SetConstraintSizes(bool recurse
)
1634 wxLayoutConstraints
*constr
= GetConstraints();
1635 if ( constr
&& constr
->AreSatisfied() )
1637 int x
= constr
->left
.GetValue();
1638 int y
= constr
->top
.GetValue();
1639 int w
= constr
->width
.GetValue();
1640 int h
= constr
->height
.GetValue();
1642 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1643 (constr
->height
.GetRelationship() != wxAsIs
) )
1645 SetSize(x
, y
, w
, h
);
1649 // If we don't want to resize this window, just move it...
1655 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1656 GetClassInfo()->GetClassName(),
1662 wxWindowList::Node
*node
= GetChildren().GetFirst();
1665 wxWindow
*win
= node
->GetData();
1666 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1667 win
->SetConstraintSizes();
1668 node
= node
->GetNext();
1673 // Only set the size/position of the constraint (if any)
1674 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1676 wxLayoutConstraints
*constr
= GetConstraints();
1681 constr
->left
.SetValue(x
);
1682 constr
->left
.SetDone(TRUE
);
1686 constr
->top
.SetValue(y
);
1687 constr
->top
.SetDone(TRUE
);
1691 constr
->width
.SetValue(w
);
1692 constr
->width
.SetDone(TRUE
);
1696 constr
->height
.SetValue(h
);
1697 constr
->height
.SetDone(TRUE
);
1702 void wxWindowBase::MoveConstraint(int x
, int y
)
1704 wxLayoutConstraints
*constr
= GetConstraints();
1709 constr
->left
.SetValue(x
);
1710 constr
->left
.SetDone(TRUE
);
1714 constr
->top
.SetValue(y
);
1715 constr
->top
.SetDone(TRUE
);
1720 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1722 wxLayoutConstraints
*constr
= GetConstraints();
1725 *w
= constr
->width
.GetValue();
1726 *h
= constr
->height
.GetValue();
1732 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1734 wxLayoutConstraints
*constr
= GetConstraints();
1737 *w
= constr
->width
.GetValue();
1738 *h
= constr
->height
.GetValue();
1741 GetClientSize(w
, h
);
1744 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1746 wxLayoutConstraints
*constr
= GetConstraints();
1749 *x
= constr
->left
.GetValue();
1750 *y
= constr
->top
.GetValue();
1756 #endif // wxUSE_CONSTRAINTS
1758 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
1760 // don't do it for the dialogs/frames - they float independently of their
1762 if ( !IsTopLevel() )
1764 wxWindow
*parent
= GetParent();
1765 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
1767 wxPoint
pt(parent
->GetClientAreaOrigin());
1774 // ----------------------------------------------------------------------------
1775 // do Update UI processing for child controls
1776 // ----------------------------------------------------------------------------
1778 // TODO: should this be implemented for the child window rather
1779 // than the parent? Then you can override it e.g. for wxCheckBox
1780 // to do the Right Thing rather than having to assume a fixed number
1781 // of control classes.
1782 void wxWindowBase::UpdateWindowUI()
1785 wxUpdateUIEvent
event(GetId());
1786 event
.m_eventObject
= this;
1788 if ( GetEventHandler()->ProcessEvent(event
) )
1790 if ( event
.GetSetEnabled() )
1791 Enable(event
.GetEnabled());
1793 if ( event
.GetSetText() )
1795 wxControl
*control
= wxDynamicCastThis(wxControl
);
1799 wxTextCtrl
*text
= wxDynamicCast(control
, wxTextCtrl
);
1802 if ( event
.GetText() != text
->GetValue() )
1803 text
->SetValue(event
.GetText());
1806 #endif // wxUSE_TEXTCTRL
1808 if ( event
.GetText() != control
->GetLabel() )
1809 control
->SetLabel(event
.GetText());
1815 wxCheckBox
*checkbox
= wxDynamicCastThis(wxCheckBox
);
1818 if ( event
.GetSetChecked() )
1819 checkbox
->SetValue(event
.GetChecked());
1821 #endif // wxUSE_CHECKBOX
1824 wxRadioButton
*radiobtn
= wxDynamicCastThis(wxRadioButton
);
1827 if ( event
.GetSetChecked() )
1828 radiobtn
->SetValue(event
.GetChecked());
1830 #endif // wxUSE_RADIOBTN
1832 #endif // wxUSE_CONTROLS
1835 // ----------------------------------------------------------------------------
1836 // dialog units translations
1837 // ----------------------------------------------------------------------------
1839 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1841 int charWidth
= GetCharWidth();
1842 int charHeight
= GetCharHeight();
1843 wxPoint
pt2(-1, -1);
1845 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1847 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1852 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1854 int charWidth
= GetCharWidth();
1855 int charHeight
= GetCharHeight();
1856 wxPoint
pt2(-1, -1);
1858 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1860 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1865 // ----------------------------------------------------------------------------
1867 // ----------------------------------------------------------------------------
1869 // propagate the colour change event to the subwindows
1870 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1872 wxWindowList::Node
*node
= GetChildren().GetFirst();
1875 // Only propagate to non-top-level windows
1876 wxWindow
*win
= node
->GetData();
1877 if ( !win
->IsTopLevel() )
1879 wxSysColourChangedEvent event2
;
1880 event
.m_eventObject
= win
;
1881 win
->GetEventHandler()->ProcessEvent(event2
);
1884 node
= node
->GetNext();
1888 // the default action is to populate dialog with data when it's created
1889 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1891 TransferDataToWindow();
1894 // process Ctrl-Alt-mclick
1895 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
1898 if ( event
.ControlDown() && event
.AltDown() )
1900 // don't translate these strings
1903 #ifdef __WXUNIVERSAL__
1905 #endif // __WXUNIVERSAL__
1907 switch ( wxGetOsVersion() )
1909 case wxMOTIF_X
: port
+= _T("Motif"); break;
1911 case wxMAC_DARWIN
: port
+= _T("Mac"); break;
1912 case wxBEOS
: port
+= _T("BeOS"); break;
1916 case wxGTK_BEOS
: port
+= _T("GTK"); break;
1922 case wxWIN386
: port
+= _T("MS Windows"); break;
1926 case wxMGL_OS2
: port
+= _T("MGL"); break;
1928 case wxOS2_PM
: port
+= _T("OS/2"); break;
1929 default: port
+= _T("unknown"); break;
1932 wxMessageBox(wxString::Format(
1934 " wxWindows Library (%s port)\nVersion %u.%u.%u%s, compiled at %s %s\n Copyright (c) 1995-2002 wxWindows team"
1948 _T("wxWindows information"),
1949 wxICON_INFORMATION
| wxOK
,
1953 #endif // wxUSE_MSGDLG
1959 // ----------------------------------------------------------------------------
1961 // ----------------------------------------------------------------------------
1963 #if wxUSE_ACCESSIBILITY
1964 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
1966 if (m_accessible
&& (accessible
!= m_accessible
))
1967 delete m_accessible
;
1968 m_accessible
= accessible
;
1970 m_accessible
->SetWindow((wxWindow
*) this);
1973 // Returns the accessible object, creating if necessary.
1974 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
1977 m_accessible
= CreateAccessible();
1978 return m_accessible
;
1981 // Override to create a specific accessible object.
1982 wxAccessible
* wxWindowBase::CreateAccessible()
1984 return new wxWindowAccessible((wxWindow
*) this);
1989 // ----------------------------------------------------------------------------
1990 // list classes implementation
1991 // ----------------------------------------------------------------------------
1993 void wxWindowListNode::DeleteData()
1995 delete (wxWindow
*)GetData();
1998 // ----------------------------------------------------------------------------
2000 // ----------------------------------------------------------------------------
2002 wxBorder
wxWindowBase::GetBorder() const
2004 wxBorder border
= (wxBorder
)(m_windowStyle
& wxBORDER_MASK
);
2005 if ( border
== wxBORDER_DEFAULT
)
2007 border
= GetDefaultBorder();
2013 wxBorder
wxWindowBase::GetDefaultBorder() const
2015 return wxBORDER_NONE
;
2018 // ----------------------------------------------------------------------------
2020 // ----------------------------------------------------------------------------
2022 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2024 // here we just check if the point is inside the window or not
2026 // check the top and left border first
2027 bool outside
= x
< 0 || y
< 0;
2030 // check the right and bottom borders too
2031 wxSize size
= GetSize();
2032 outside
= x
>= size
.x
|| y
>= size
.y
;
2035 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2038 // ----------------------------------------------------------------------------
2040 // ----------------------------------------------------------------------------
2042 struct WXDLLEXPORT wxWindowNext
2046 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2048 void wxWindowBase::CaptureMouse()
2050 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this);
2052 wxWindow
*winOld
= GetCapture();
2055 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2058 wxWindowNext
*item
= new wxWindowNext
;
2060 item
->next
= ms_winCaptureNext
;
2061 ms_winCaptureNext
= item
;
2063 //else: no mouse capture to save
2068 void wxWindowBase::ReleaseMouse()
2070 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this);
2072 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2076 if ( ms_winCaptureNext
)
2078 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2080 wxWindowNext
*item
= ms_winCaptureNext
;
2081 ms_winCaptureNext
= item
->next
;
2084 //else: stack is empty, no previous capture
2086 wxLogTrace(_T("mousecapture"),
2087 _T("After ReleaseMouse() mouse is captured by %p"),
2092 void wxWindowBase::SendDestroyEvent()
2094 wxWindowDestroyEvent event
;
2095 event
.SetEventObject(this);
2096 event
.SetId(GetId());
2097 GetEventHandler()->ProcessEvent(event
);
2100 // ----------------------------------------------------------------------------
2102 // ----------------------------------------------------------------------------
2104 #if wxUSE_VALIDATORS
2106 bool wxWindowBase::TryValidator(wxEvent
& event
)
2108 // Can only use the validator of the window which
2109 // is receiving the event
2110 if ( event
.GetEventObject() == this )
2112 wxValidator
*validator
= GetValidator();
2113 if ( validator
&& validator
->ProcessEvent(event
) )
2122 #endif // wxUSE_VALIDATORS
2124 bool wxWindowBase::TryParent(wxEvent
& event
)
2126 // Carry on up the parent-child hierarchy, but only if event is a command
2127 // event: it wouldn't make sense for a parent to receive a child's size
2128 // event, for example
2129 if ( event
.IsCommandEvent() )
2131 // honour the requests to stop propagation at this window: this is
2132 // used by the dialogs, for example, to prevent processing the events
2133 // from the dialog controls in the parent frame which rarely, if ever,
2135 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2137 wxWindow
*parent
= GetParent();
2138 if ( parent
&& !parent
->IsBeingDeleted() )
2139 return parent
->GetEventHandler()->ProcessEvent(event
);
2143 return wxEvtHandler::TryParent(event
);
2146 // ----------------------------------------------------------------------------
2148 // ----------------------------------------------------------------------------
2150 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2152 while ( win
&& !win
->IsTopLevel() )
2153 win
= win
->GetParent();
2158 #if wxUSE_ACCESSIBILITY
2159 // ----------------------------------------------------------------------------
2160 // accessible object for windows
2161 // ----------------------------------------------------------------------------
2163 // Can return either a child object, or an integer
2164 // representing the child element, starting from 1.
2165 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& pt
, int* childId
, wxAccessible
** childObject
)
2167 wxASSERT( GetWindow() != NULL
);
2171 return wxACC_NOT_IMPLEMENTED
;
2174 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2175 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2177 wxASSERT( GetWindow() != NULL
);
2181 wxWindow
* win
= NULL
;
2188 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2190 win
= (wxWindow
*) GetWindow()->GetChildren().Nth(elementId
-1)->GetData();
2197 rect
= win
->GetRect();
2198 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2199 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2203 return wxACC_NOT_IMPLEMENTED
;
2206 // Navigates from fromId to toId/toObject.
2207 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2208 int* toId
, wxAccessible
** toObject
)
2210 wxASSERT( GetWindow() != NULL
);
2216 case wxNAVDIR_FIRSTCHILD
:
2218 if (GetWindow()->GetChildren().GetCount() == 0)
2220 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2221 *toObject
= childWindow
->GetOrCreateAccessible();
2225 case wxNAVDIR_LASTCHILD
:
2227 if (GetWindow()->GetChildren().GetCount() == 0)
2229 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2230 *toObject
= childWindow
->GetOrCreateAccessible();
2234 case wxNAVDIR_RIGHT
:
2238 wxWindowList::Node
*node
= NULL
;
2241 // Can't navigate to sibling of this window
2242 // if we're a top-level window.
2243 if (!GetWindow()->GetParent())
2244 return wxACC_NOT_IMPLEMENTED
;
2246 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2250 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2251 node
= (wxWindowList::Node
*) GetWindow()->GetChildren().Nth(fromId
-1);
2254 if (node
&& node
->GetNext())
2256 wxWindow
* nextWindow
= (wxWindow
*) node
->GetNext()->Data();
2257 *toObject
= nextWindow
->GetOrCreateAccessible();
2265 case wxNAVDIR_PREVIOUS
:
2267 wxWindowList::Node
*node
= NULL
;
2270 // Can't navigate to sibling of this window
2271 // if we're a top-level window.
2272 if (!GetWindow()->GetParent())
2273 return wxACC_NOT_IMPLEMENTED
;
2275 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2279 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2280 node
= (wxWindowList::Node
*) GetWindow()->GetChildren().Nth(fromId
-1);
2283 if (node
&& node
->GetPrevious())
2285 wxWindow
* previousWindow
= (wxWindow
*) node
->GetPrevious()->Data();
2286 *toObject
= previousWindow
->GetOrCreateAccessible();
2294 return wxACC_NOT_IMPLEMENTED
;
2297 // Gets the name of the specified object.
2298 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2300 wxASSERT( GetWindow() != NULL
);
2306 // If a child, leave wxWindows to call the function on the actual
2309 return wxACC_NOT_IMPLEMENTED
;
2311 // This will eventually be replaced by specialised
2312 // accessible classes, one for each kind of wxWindows
2313 // control or window.
2314 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2315 title
= ((wxButton
*) GetWindow())->GetLabel();
2317 title
= GetWindow()->GetName();
2319 if (!title
.IsEmpty())
2325 return wxACC_NOT_IMPLEMENTED
;
2328 // Gets the number of children.
2329 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2331 wxASSERT( GetWindow() != NULL
);
2335 *childId
= (int) GetWindow()->GetChildren().GetCount();
2339 // Gets the specified child (starting from 1).
2340 // If *child is NULL and return value is wxACC_OK,
2341 // this means that the child is a simple element and
2342 // not an accessible object.
2343 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2345 wxASSERT( GetWindow() != NULL
);
2355 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2358 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().Nth(childId
-1)->GetData();
2359 *child
= childWindow
->GetOrCreateAccessible();
2366 // Gets the parent, or NULL.
2367 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2369 wxASSERT( GetWindow() != NULL
);
2373 wxWindow
* parentWindow
= GetWindow()->GetParent();
2381 *parent
= parentWindow
->GetOrCreateAccessible();
2389 // Performs the default action. childId is 0 (the action for this object)
2390 // or > 0 (the action for a child).
2391 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2392 // window (e.g. an edit control).
2393 wxAccStatus
wxWindowAccessible::DoDefaultAction(int childId
)
2395 wxASSERT( GetWindow() != NULL
);
2399 return wxACC_NOT_IMPLEMENTED
;
2402 // Gets the default action for this object (0) or > 0 (the action for a child).
2403 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2404 // string if there is no action.
2405 // The retrieved string describes the action that is performed on an object,
2406 // not what the object does as a result. For example, a toolbar button that prints
2407 // a document has a default action of "Press" rather than "Prints the current document."
2408 wxAccStatus
wxWindowAccessible::GetDefaultAction(int childId
, wxString
* actionName
)
2410 wxASSERT( GetWindow() != NULL
);
2414 return wxACC_NOT_IMPLEMENTED
;
2417 // Returns the description for this object or a child.
2418 wxAccStatus
wxWindowAccessible::GetDescription(int childId
, wxString
* description
)
2420 wxASSERT( GetWindow() != NULL
);
2424 wxString
ht(GetWindow()->GetHelpText());
2430 return wxACC_NOT_IMPLEMENTED
;
2433 // Returns help text for this object or a child, similar to tooltip text.
2434 wxAccStatus
wxWindowAccessible::GetHelpText(int childId
, wxString
* helpText
)
2436 wxASSERT( GetWindow() != NULL
);
2440 wxString
ht(GetWindow()->GetHelpText());
2446 return wxACC_NOT_IMPLEMENTED
;
2449 // Returns the keyboard shortcut for this object or child.
2450 // Return e.g. ALT+K
2451 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int childId
, wxString
* shortcut
)
2453 wxASSERT( GetWindow() != NULL
);
2457 return wxACC_NOT_IMPLEMENTED
;
2460 // Returns a role constant.
2461 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
2463 wxASSERT( GetWindow() != NULL
);
2467 // If a child, leave wxWindows to call the function on the actual
2470 return wxACC_NOT_IMPLEMENTED
;
2472 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2473 return wxACC_NOT_IMPLEMENTED
;
2475 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2476 return wxACC_NOT_IMPLEMENTED
;
2479 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2480 return wxACC_NOT_IMPLEMENTED
;
2483 //*role = wxROLE_SYSTEM_CLIENT;
2484 *role
= wxROLE_SYSTEM_CLIENT
;
2487 return wxACC_NOT_IMPLEMENTED
;
2490 // Returns a state constant.
2491 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
2493 wxASSERT( GetWindow() != NULL
);
2497 // If a child, leave wxWindows to call the function on the actual
2500 return wxACC_NOT_IMPLEMENTED
;
2502 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2503 return wxACC_NOT_IMPLEMENTED
;
2506 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2507 return wxACC_NOT_IMPLEMENTED
;
2510 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2511 return wxACC_NOT_IMPLEMENTED
;
2517 return wxACC_NOT_IMPLEMENTED
;
2520 // Returns a localized string representing the value for the object
2522 wxAccStatus
wxWindowAccessible::GetValue(int childId
, wxString
* strValue
)
2524 wxASSERT( GetWindow() != NULL
);
2528 return wxACC_NOT_IMPLEMENTED
;
2531 // Selects the object or child.
2532 wxAccStatus
wxWindowAccessible::Select(int childId
, wxAccSelectionFlags selectFlags
)
2534 wxASSERT( GetWindow() != NULL
);
2538 return wxACC_NOT_IMPLEMENTED
;
2541 // Gets the window with the keyboard focus.
2542 // If childId is 0 and child is NULL, no object in
2543 // this subhierarchy has the focus.
2544 // If this object has the focus, child should be 'this'.
2545 wxAccStatus
wxWindowAccessible::GetFocus(int* childId
, wxAccessible
** child
)
2547 wxASSERT( GetWindow() != NULL
);
2551 return wxACC_NOT_IMPLEMENTED
;
2554 // Gets a variant representing the selected children
2556 // Acceptable values:
2557 // - a null variant (IsNull() returns TRUE)
2558 // - a list variant (GetType() == wxT("list")
2559 // - an integer representing the selected child element,
2560 // or 0 if this object is selected (GetType() == wxT("long")
2561 // - a "void*" pointer to a wxAccessible child object
2562 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* selections
)
2564 wxASSERT( GetWindow() != NULL
);
2568 return wxACC_NOT_IMPLEMENTED
;
2571 #endif // wxUSE_ACCESSIBILITY