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
157 // an optimization for the event processing: checking this flag is much
158 // faster than using IsKindOf(CLASSINFO(wxWindow))
161 #if wxUSE_CONSTRAINTS
162 // no constraints whatsoever
163 m_constraints
= (wxLayoutConstraints
*) NULL
;
164 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
165 #endif // wxUSE_CONSTRAINTS
167 m_windowSizer
= (wxSizer
*) NULL
;
168 m_containingSizer
= (wxSizer
*) NULL
;
169 m_autoLayout
= FALSE
;
171 #if wxUSE_DRAG_AND_DROP
172 m_dropTarget
= (wxDropTarget
*)NULL
;
173 #endif // wxUSE_DRAG_AND_DROP
176 m_tooltip
= (wxToolTip
*)NULL
;
177 #endif // wxUSE_TOOLTIPS
180 m_caret
= (wxCaret
*)NULL
;
181 #endif // wxUSE_CARET
184 m_hasCustomPalette
= FALSE
;
185 #endif // wxUSE_PALETTE
187 #if wxUSE_ACCESSIBILITY
191 m_virtualSize
= wxDefaultSize
;
196 m_maxVirtualHeight
= -1;
198 // Whether we're using the current theme for this window (wxGTK only for now)
199 m_themeEnabled
= FALSE
;
202 // common part of window creation process
203 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
205 const wxPoint
& WXUNUSED(pos
),
206 const wxSize
& WXUNUSED(size
),
208 const wxValidator
& validator
,
209 const wxString
& name
)
211 // m_isWindow is set to TRUE in wxWindowBase::Init() as well as many other
212 // member variables - check that it has been called (will catch the case
213 // when a new ctor is added which doesn't call InitWindow)
214 wxASSERT_MSG( m_isWindow
, wxT("Init() must have been called before!") );
217 // wxGTK doesn't allow to create controls with static box as the parent so
218 // this will result in a crash when the program is ported to wxGTK so warn
221 // if you get this assert, the correct solution is to create the controls
222 // as siblings of the static box
223 wxASSERT_MSG( !parent
|| !wxDynamicCast(parent
, wxStaticBox
),
224 _T("wxStaticBox can't be used as a window parent!") );
225 #endif // wxUSE_STATBOX
227 // ids are limited to 16 bits under MSW so if you care about portability,
228 // it's not a good idea to use ids out of this range (and negative ids are
229 // reserved for wxWindows own usage)
230 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767),
231 _T("invalid id value") );
233 // generate a new id if the user doesn't care about it
234 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
237 SetWindowStyleFlag(style
);
241 SetValidator(validator
);
242 #endif // wxUSE_VALIDATORS
244 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
245 // have it too - like this it's possible to set it only in the top level
246 // dialog/frame and all children will inherit it by defult
247 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
249 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
255 // ----------------------------------------------------------------------------
257 // ----------------------------------------------------------------------------
260 wxWindowBase::~wxWindowBase()
262 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
264 // FIXME if these 2 cases result from programming errors in the user code
265 // we should probably assert here instead of silently fixing them
267 // Just in case the window has been Closed, but we're then deleting
268 // immediately: don't leave dangling pointers.
269 wxPendingDelete
.DeleteObject(this);
271 // Just in case we've loaded a top-level window via LoadNativeDialog but
272 // we weren't a dialog class
273 wxTopLevelWindows
.DeleteObject(this);
275 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
280 #endif // wxUSE_CARET
283 if ( m_windowValidator
)
284 delete m_windowValidator
;
285 #endif // wxUSE_VALIDATORS
287 #if wxUSE_CONSTRAINTS
288 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
289 // at deleted windows as they delete themselves.
290 DeleteRelatedConstraints();
294 // This removes any dangling pointers to this window in other windows'
295 // constraintsInvolvedIn lists.
296 UnsetConstraints(m_constraints
);
297 delete m_constraints
;
298 m_constraints
= NULL
;
301 #endif // wxUSE_CONSTRAINTS
303 if ( m_containingSizer
)
304 m_containingSizer
->Detach( (wxWindow
*)this );
307 delete m_windowSizer
;
309 #if wxUSE_DRAG_AND_DROP
312 #endif // wxUSE_DRAG_AND_DROP
317 #endif // wxUSE_TOOLTIPS
319 #if wxUSE_ACCESSIBILITY
324 // reset the dangling pointer our parent window may keep to us
325 if ( m_parent
&& m_parent
->GetDefaultItem() == this )
327 m_parent
->SetDefaultItem(NULL
);
331 bool wxWindowBase::Destroy()
338 bool wxWindowBase::Close(bool force
)
340 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
341 event
.SetEventObject(this);
342 #if WXWIN_COMPATIBILITY
343 event
.SetForce(force
);
344 #endif // WXWIN_COMPATIBILITY
345 event
.SetCanVeto(!force
);
347 // return FALSE if window wasn't closed because the application vetoed the
349 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
352 bool wxWindowBase::DestroyChildren()
354 wxWindowList::Node
*node
;
357 // we iterate until the list becomes empty
358 node
= GetChildren().GetFirst();
362 wxWindow
*child
= node
->GetData();
364 wxASSERT_MSG( child
, wxT("children list contains empty nodes") );
369 wxASSERT_MSG( !GetChildren().Find(child
),
370 wxT("child didn't remove itself using RemoveChild()") );
376 // ----------------------------------------------------------------------------
377 // size/position related methods
378 // ----------------------------------------------------------------------------
380 // centre the window with respect to its parent in either (or both) directions
381 void wxWindowBase::Centre(int direction
)
383 // the position/size of the parent window or of the entire screen
385 int widthParent
, heightParent
;
387 wxWindow
*parent
= NULL
;
389 if ( !(direction
& wxCENTRE_ON_SCREEN
) )
391 // find the parent to centre this window on: it should be the
392 // immediate parent for the controls but the top level parent for the
393 // top level windows (like dialogs)
394 parent
= GetParent();
397 while ( parent
&& !parent
->IsTopLevel() )
399 parent
= parent
->GetParent();
403 // there is no wxTopLevelWindow under wxMotif yet
405 // we shouldn't center the dialog on the iconized window: under
406 // Windows, for example, this places it completely off the screen
409 wxTopLevelWindow
*winTop
= wxDynamicCast(parent
, wxTopLevelWindow
);
410 if ( winTop
&& winTop
->IsIconized() )
415 #endif // __WXMOTIF__
417 // did we find the parent?
421 direction
|= wxCENTRE_ON_SCREEN
;
425 if ( direction
& wxCENTRE_ON_SCREEN
)
427 // centre with respect to the whole screen
428 wxDisplaySize(&widthParent
, &heightParent
);
434 // centre on the parent
435 parent
->GetSize(&widthParent
, &heightParent
);
437 // adjust to the parents position
438 posParent
= parent
->GetPosition();
442 // centre inside the parents client rectangle
443 parent
->GetClientSize(&widthParent
, &heightParent
);
448 GetSize(&width
, &height
);
453 if ( direction
& wxHORIZONTAL
)
454 xNew
= (widthParent
- width
)/2;
456 if ( direction
& wxVERTICAL
)
457 yNew
= (heightParent
- height
)/2;
462 // Base size of the visible dimensions of the display
463 // to take into account the taskbar
464 wxRect rect
= wxGetClientDisplayRect();
465 wxSize
size (rect
.width
,rect
.height
);
467 // NB: in wxMSW, negative position may not neccessary mean "out of screen",
468 // but it may mean that the window is placed on other than the main
469 // display. Therefore we only make sure centered window is on the main display
470 // if the parent is at least partially present here.
471 if (posParent
.x
+ widthParent
>= 0) // if parent is (partially) on the main display
475 else if (xNew
+width
> size
.x
)
476 xNew
= size
.x
-width
-1;
478 if (posParent
.y
+ heightParent
>= 0) // if parent is (partially) on the main display
480 if (yNew
+height
> size
.y
)
481 yNew
= size
.y
-height
-1;
483 // Make certain that the title bar is initially visible
484 // always, even if this would push the bottom of the
485 // dialog of the visible area of the display
490 // move the window to this position (keeping the old size but using
491 // SetSize() and not Move() to allow xNew and/or yNew to be -1)
492 SetSize(xNew
, yNew
, width
, height
, wxSIZE_ALLOW_MINUS_ONE
);
495 // fits the window around the children
496 void wxWindowBase::Fit()
498 if ( GetChildren().GetCount() > 0 )
500 SetClientSize(DoGetBestSize());
502 //else: do nothing if we have no children
505 // fits virtual size (ie. scrolled area etc.) around children
506 void wxWindowBase::FitInside()
508 if ( GetChildren().GetCount() > 0 )
510 SetVirtualSize( GetBestVirtualSize() );
514 // return the size best suited for the current window
515 wxSize
wxWindowBase::DoGetBestSize() const
519 return m_windowSizer
->GetMinSize();
521 #if wxUSE_CONSTRAINTS
522 else if ( m_constraints
)
524 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
526 // our minimal acceptable size is such that all our windows fit inside
530 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
532 node
= node
->GetNext() )
534 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
537 // it's not normal that we have an unconstrained child, but
538 // what can we do about it?
542 int x
= c
->right
.GetValue(),
543 y
= c
->bottom
.GetValue();
551 // TODO: we must calculate the overlaps somehow, otherwise we
552 // will never return a size bigger than the current one :-(
555 return wxSize(maxX
, maxY
);
557 #endif // wxUSE_CONSTRAINTS
558 else if ( GetChildren().GetCount() > 0 )
560 // our minimal acceptable size is such that all our windows fit inside
564 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
566 node
= node
->GetNext() )
568 wxWindow
*win
= node
->GetData();
569 if ( win
->IsTopLevel()
571 || wxDynamicCast(win
, wxStatusBar
)
572 #endif // wxUSE_STATUSBAR
575 // dialogs and frames lie in different top level windows -
576 // don't deal with them here; as for the status bars, they
577 // don't lie in the client area at all
582 win
->GetPosition(&wx
, &wy
);
584 // if the window hadn't been positioned yet, assume that it is in
591 win
->GetSize(&ww
, &wh
);
592 if ( wx
+ ww
> maxX
)
594 if ( wy
+ wh
> maxY
)
598 // for compatibility with the old versions and because it really looks
599 // slightly more pretty like this, add a pad
603 return wxSize(maxX
, maxY
);
607 // for a generic window there is no natural best size - just use the
613 // by default the origin is not shifted
614 wxPoint
wxWindowBase::GetClientAreaOrigin() const
616 return wxPoint(0, 0);
619 // set the min/max size of the window
620 void wxWindowBase::SetSizeHints(int minW
, int minH
,
622 int WXUNUSED(incW
), int WXUNUSED(incH
))
624 // setting min width greater than max width leads to infinite loops under
625 // X11 and generally doesn't make any sense, so don't allow it
626 wxCHECK_RET( (minW
== -1 || maxW
== -1 || minW
<= maxW
) &&
627 (minH
== -1 || maxH
== -1 || minH
<= maxH
),
628 _T("min width/height must be less than max width/height!") );
636 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
639 m_minVirtualWidth
= minW
;
640 m_maxVirtualWidth
= maxW
;
641 m_minVirtualHeight
= minH
;
642 m_maxVirtualHeight
= maxH
;
645 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
647 if ( m_minVirtualWidth
!= -1 && m_minVirtualWidth
> x
)
648 x
= m_minVirtualWidth
;
649 if ( m_maxVirtualWidth
!= -1 && m_maxVirtualWidth
< x
)
650 x
= m_maxVirtualWidth
;
651 if ( m_minVirtualHeight
!= -1 && m_minVirtualHeight
> y
)
652 y
= m_minVirtualHeight
;
653 if ( m_maxVirtualHeight
!= -1 && m_maxVirtualHeight
< y
)
654 y
= m_maxVirtualHeight
;
656 m_virtualSize
= wxSize(x
, y
);
659 wxSize
wxWindowBase::DoGetVirtualSize() const
661 wxSize
s( GetClientSize() );
663 return wxSize( wxMax( m_virtualSize
.GetWidth(), s
.GetWidth() ),
664 wxMax( m_virtualSize
.GetHeight(), s
.GetHeight() ) );
667 // ----------------------------------------------------------------------------
668 // show/hide/enable/disable the window
669 // ----------------------------------------------------------------------------
671 bool wxWindowBase::Show(bool show
)
673 if ( show
!= m_isShown
)
685 bool wxWindowBase::Enable(bool enable
)
687 if ( enable
!= m_isEnabled
)
689 m_isEnabled
= enable
;
698 // ----------------------------------------------------------------------------
700 // ----------------------------------------------------------------------------
702 bool wxWindowBase::IsTopLevel() const
707 // ----------------------------------------------------------------------------
708 // reparenting the window
709 // ----------------------------------------------------------------------------
711 void wxWindowBase::AddChild(wxWindowBase
*child
)
713 wxCHECK_RET( child
, wxT("can't add a NULL child") );
715 // this should never happen and it will lead to a crash later if it does
716 // because RemoveChild() will remove only one node from the children list
717 // and the other(s) one(s) will be left with dangling pointers in them
718 wxASSERT_MSG( !GetChildren().Find(child
), _T("AddChild() called twice") );
720 GetChildren().Append(child
);
721 child
->SetParent(this);
724 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
726 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
728 GetChildren().DeleteObject(child
);
729 child
->SetParent((wxWindow
*)NULL
);
732 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
734 wxWindow
*oldParent
= GetParent();
735 if ( newParent
== oldParent
)
741 // unlink this window from the existing parent.
744 oldParent
->RemoveChild(this);
748 wxTopLevelWindows
.DeleteObject(this);
751 // add it to the new one
754 newParent
->AddChild(this);
758 wxTopLevelWindows
.Append(this);
764 // ----------------------------------------------------------------------------
765 // event handler stuff
766 // ----------------------------------------------------------------------------
768 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
770 wxEvtHandler
*handlerOld
= GetEventHandler();
772 handler
->SetNextHandler(handlerOld
);
775 GetEventHandler()->SetPreviousHandler(handler
);
777 SetEventHandler(handler
);
780 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
782 wxEvtHandler
*handlerA
= GetEventHandler();
785 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
786 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
789 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
790 SetEventHandler(handlerB
);
795 handlerA
= (wxEvtHandler
*)NULL
;
802 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
804 wxCHECK_MSG( handler
, FALSE
, _T("RemoveEventHandler(NULL) called") );
806 wxEvtHandler
*handlerPrev
= NULL
,
807 *handlerCur
= GetEventHandler();
810 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
812 if ( handlerCur
== handler
)
816 handlerPrev
->SetNextHandler(handlerNext
);
820 SetEventHandler(handlerNext
);
825 handlerNext
->SetPreviousHandler ( handlerPrev
);
827 handler
->SetNextHandler(NULL
);
832 handlerPrev
= handlerCur
;
833 handlerCur
= handlerNext
;
836 wxFAIL_MSG( _T("where has the event handler gone?") );
841 // ----------------------------------------------------------------------------
843 // ----------------------------------------------------------------------------
845 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
847 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
850 m_backgroundColour
= colour
;
857 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
859 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
862 m_foregroundColour
= colour
;
869 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
871 // setting an invalid cursor is ok, it means that we don't have any special
873 if ( m_cursor
== cursor
)
884 bool wxWindowBase::SetFont(const wxFont
& font
)
886 // don't try to set invalid font, always fall back to the default
887 const wxFont
& fontOk
= font
.Ok() ? font
: *wxSWISS_FONT
;
889 if ( fontOk
== m_font
)
904 void wxWindowBase::SetPalette(const wxPalette
& pal
)
906 m_hasCustomPalette
= TRUE
;
909 // VZ: can anyone explain me what do we do here?
910 wxWindowDC
d((wxWindow
*) this);
914 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
916 wxWindow
*win
= (wxWindow
*)this;
917 while ( win
&& !win
->HasCustomPalette() )
919 win
= win
->GetParent();
925 #endif // wxUSE_PALETTE
928 void wxWindowBase::SetCaret(wxCaret
*caret
)
939 wxASSERT_MSG( m_caret
->GetWindow() == this,
940 wxT("caret should be created associated to this window") );
943 #endif // wxUSE_CARET
946 // ----------------------------------------------------------------------------
948 // ----------------------------------------------------------------------------
950 void wxWindowBase::SetValidator(const wxValidator
& validator
)
952 if ( m_windowValidator
)
953 delete m_windowValidator
;
955 m_windowValidator
= (wxValidator
*)validator
.Clone();
957 if ( m_windowValidator
)
958 m_windowValidator
->SetWindow(this) ;
960 #endif // wxUSE_VALIDATORS
962 // ----------------------------------------------------------------------------
963 // update region stuff
964 // ----------------------------------------------------------------------------
966 wxRect
wxWindowBase::GetUpdateClientRect() const
968 wxRegion rgnUpdate
= GetUpdateRegion();
969 rgnUpdate
.Intersect(GetClientRect());
970 wxRect rectUpdate
= rgnUpdate
.GetBox();
971 wxPoint ptOrigin
= GetClientAreaOrigin();
972 rectUpdate
.x
-= ptOrigin
.x
;
973 rectUpdate
.y
-= ptOrigin
.y
;
978 bool wxWindowBase::IsExposed(int x
, int y
) const
980 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
983 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
985 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
988 // ----------------------------------------------------------------------------
989 // find child window by id or name
990 // ----------------------------------------------------------------------------
992 wxWindow
*wxWindowBase::FindWindow( long id
)
994 if ( id
== m_windowId
)
995 return (wxWindow
*)this;
997 wxWindowBase
*res
= (wxWindow
*)NULL
;
998 wxWindowList::Node
*node
;
999 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1001 wxWindowBase
*child
= node
->GetData();
1002 res
= child
->FindWindow( id
);
1005 return (wxWindow
*)res
;
1008 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
1010 if ( name
== m_windowName
)
1011 return (wxWindow
*)this;
1013 wxWindowBase
*res
= (wxWindow
*)NULL
;
1014 wxWindowList::Node
*node
;
1015 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1017 wxWindow
*child
= node
->GetData();
1018 res
= child
->FindWindow(name
);
1021 return (wxWindow
*)res
;
1025 // find any window by id or name or label: If parent is non-NULL, look through
1026 // children for a label or title matching the specified string. If NULL, look
1027 // through all top-level windows.
1029 // to avoid duplicating code we reuse the same helper function but with
1030 // different comparators
1032 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1033 const wxString
& label
, long id
);
1036 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1039 return win
->GetLabel() == label
;
1043 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1046 return win
->GetName() == label
;
1050 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1053 return win
->GetId() == id
;
1056 // recursive helper for the FindWindowByXXX() functions
1058 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1059 const wxString
& label
,
1061 wxFindWindowCmp cmp
)
1065 // see if this is the one we're looking for
1066 if ( (*cmp
)(parent
, label
, id
) )
1067 return (wxWindow
*)parent
;
1069 // It wasn't, so check all its children
1070 for ( wxWindowList::Node
* node
= parent
->GetChildren().GetFirst();
1072 node
= node
->GetNext() )
1074 // recursively check each child
1075 wxWindow
*win
= (wxWindow
*)node
->GetData();
1076 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1086 // helper for FindWindowByXXX()
1088 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1089 const wxString
& label
,
1091 wxFindWindowCmp cmp
)
1095 // just check parent and all its children
1096 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1099 // start at very top of wx's windows
1100 for ( wxWindowList::Node
* node
= wxTopLevelWindows
.GetFirst();
1102 node
= node
->GetNext() )
1104 // recursively check each window & its children
1105 wxWindow
*win
= node
->GetData();
1106 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1116 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1118 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1123 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1125 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1129 // fall back to the label
1130 win
= FindWindowByLabel(title
, parent
);
1138 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1140 return wxFindWindowHelper(parent
, _T(""), id
, wxFindWindowCmpIds
);
1143 // ----------------------------------------------------------------------------
1144 // dialog oriented functions
1145 // ----------------------------------------------------------------------------
1147 void wxWindowBase::MakeModal(bool modal
)
1149 // Disable all other windows
1152 wxWindowList::Node
*node
= wxTopLevelWindows
.GetFirst();
1155 wxWindow
*win
= node
->GetData();
1157 win
->Enable(!modal
);
1159 node
= node
->GetNext();
1164 bool wxWindowBase::Validate()
1166 #if wxUSE_VALIDATORS
1167 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1169 wxWindowList::Node
*node
;
1170 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1172 wxWindowBase
*child
= node
->GetData();
1173 wxValidator
*validator
= child
->GetValidator();
1174 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1179 if ( recurse
&& !child
->Validate() )
1184 #endif // wxUSE_VALIDATORS
1189 bool wxWindowBase::TransferDataToWindow()
1191 #if wxUSE_VALIDATORS
1192 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1194 wxWindowList::Node
*node
;
1195 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1197 wxWindowBase
*child
= node
->GetData();
1198 wxValidator
*validator
= child
->GetValidator();
1199 if ( validator
&& !validator
->TransferToWindow() )
1201 wxLogWarning(_("Could not transfer data to window"));
1203 wxLog::FlushActive();
1211 if ( !child
->TransferDataToWindow() )
1213 // warning already given
1218 #endif // wxUSE_VALIDATORS
1223 bool wxWindowBase::TransferDataFromWindow()
1225 #if wxUSE_VALIDATORS
1226 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1228 wxWindowList::Node
*node
;
1229 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1231 wxWindow
*child
= node
->GetData();
1232 wxValidator
*validator
= child
->GetValidator();
1233 if ( validator
&& !validator
->TransferFromWindow() )
1235 // nop warning here because the application is supposed to give
1236 // one itself - we don't know here what might have gone wrongly
1243 if ( !child
->TransferDataFromWindow() )
1245 // warning already given
1250 #endif // wxUSE_VALIDATORS
1255 void wxWindowBase::InitDialog()
1257 wxInitDialogEvent
event(GetId());
1258 event
.SetEventObject( this );
1259 GetEventHandler()->ProcessEvent(event
);
1262 // ----------------------------------------------------------------------------
1263 // context-sensitive help support
1264 // ----------------------------------------------------------------------------
1268 // associate this help text with this window
1269 void wxWindowBase::SetHelpText(const wxString
& text
)
1271 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1274 helpProvider
->AddHelp(this, text
);
1278 // associate this help text with all windows with the same id as this
1280 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1282 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1285 helpProvider
->AddHelp(GetId(), text
);
1289 // get the help string associated with this window (may be empty)
1290 wxString
wxWindowBase::GetHelpText() const
1293 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1296 text
= helpProvider
->GetHelp(this);
1302 // show help for this window
1303 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1305 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1308 if ( helpProvider
->ShowHelp(this) )
1310 // skip the event.Skip() below
1318 #endif // wxUSE_HELP
1320 // ----------------------------------------------------------------------------
1321 // tooltipsroot.Replace("\\", "/");
1322 // ----------------------------------------------------------------------------
1326 void wxWindowBase::SetToolTip( const wxString
&tip
)
1328 // don't create the new tooltip if we already have one
1331 m_tooltip
->SetTip( tip
);
1335 SetToolTip( new wxToolTip( tip
) );
1338 // setting empty tooltip text does not remove the tooltip any more - use
1339 // SetToolTip((wxToolTip *)NULL) for this
1342 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1347 m_tooltip
= tooltip
;
1350 #endif // wxUSE_TOOLTIPS
1352 // ----------------------------------------------------------------------------
1353 // constraints and sizers
1354 // ----------------------------------------------------------------------------
1356 #if wxUSE_CONSTRAINTS
1358 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1360 if ( m_constraints
)
1362 UnsetConstraints(m_constraints
);
1363 delete m_constraints
;
1365 m_constraints
= constraints
;
1366 if ( m_constraints
)
1368 // Make sure other windows know they're part of a 'meaningful relationship'
1369 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1370 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1371 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1372 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1373 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1374 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1375 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1376 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1377 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1378 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1379 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1380 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1381 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1382 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1383 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1384 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1388 // This removes any dangling pointers to this window in other windows'
1389 // constraintsInvolvedIn lists.
1390 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1394 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1395 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1396 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1397 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1398 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1399 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1400 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1401 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1402 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1403 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1404 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1405 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1406 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1407 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1408 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1409 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1413 // Back-pointer to other windows we're involved with, so if we delete this
1414 // window, we must delete any constraints we're involved with.
1415 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1417 if ( !m_constraintsInvolvedIn
)
1418 m_constraintsInvolvedIn
= new wxWindowList
;
1419 if ( !m_constraintsInvolvedIn
->Find(otherWin
) )
1420 m_constraintsInvolvedIn
->Append(otherWin
);
1423 // REMOVE back-pointer to other windows we're involved with.
1424 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1426 if ( m_constraintsInvolvedIn
)
1427 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
1430 // Reset any constraints that mention this window
1431 void wxWindowBase::DeleteRelatedConstraints()
1433 if ( m_constraintsInvolvedIn
)
1435 wxWindowList::Node
*node
= m_constraintsInvolvedIn
->GetFirst();
1438 wxWindow
*win
= node
->GetData();
1439 wxLayoutConstraints
*constr
= win
->GetConstraints();
1441 // Reset any constraints involving this window
1444 constr
->left
.ResetIfWin(this);
1445 constr
->top
.ResetIfWin(this);
1446 constr
->right
.ResetIfWin(this);
1447 constr
->bottom
.ResetIfWin(this);
1448 constr
->width
.ResetIfWin(this);
1449 constr
->height
.ResetIfWin(this);
1450 constr
->centreX
.ResetIfWin(this);
1451 constr
->centreY
.ResetIfWin(this);
1454 wxWindowList::Node
*next
= node
->GetNext();
1459 delete m_constraintsInvolvedIn
;
1460 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1464 #endif // wxUSE_CONSTRAINTS
1466 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1469 delete m_windowSizer
;
1471 m_windowSizer
= sizer
;
1473 SetAutoLayout( sizer
!= NULL
);
1476 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1478 SetSizer( sizer
, deleteOld
);
1479 sizer
->SetSizeHints( (wxWindow
*) this );
1482 #if wxUSE_CONSTRAINTS
1484 void wxWindowBase::SatisfyConstraints()
1486 wxLayoutConstraints
*constr
= GetConstraints();
1487 bool wasOk
= constr
&& constr
->AreSatisfied();
1489 ResetConstraints(); // Mark all constraints as unevaluated
1493 // if we're a top level panel (i.e. our parent is frame/dialog), our
1494 // own constraints will never be satisfied any more unless we do it
1498 while ( noChanges
> 0 )
1500 LayoutPhase1(&noChanges
);
1504 LayoutPhase2(&noChanges
);
1507 #endif // wxUSE_CONSTRAINTS
1509 bool wxWindowBase::Layout()
1511 // If there is a sizer, use it instead of the constraints
1515 GetVirtualSize(&w
, &h
);
1516 GetSizer()->SetDimension( 0, 0, w
, h
);
1518 #if wxUSE_CONSTRAINTS
1521 SatisfyConstraints(); // Find the right constraints values
1522 SetConstraintSizes(); // Recursively set the real window sizes
1529 #if wxUSE_CONSTRAINTS
1531 // first phase of the constraints evaluation: set our own constraints
1532 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1534 wxLayoutConstraints
*constr
= GetConstraints();
1536 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1539 // second phase: set the constraints for our children
1540 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1547 // Layout grand children
1553 // Do a phase of evaluating child constraints
1554 bool wxWindowBase::DoPhase(int phase
)
1556 // the list containing the children for which the constraints are already
1558 wxWindowList succeeded
;
1560 // the max number of iterations we loop before concluding that we can't set
1562 static const int maxIterations
= 500;
1564 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1568 // loop over all children setting their constraints
1569 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
1571 node
= node
->GetNext() )
1573 wxWindow
*child
= node
->GetData();
1574 if ( child
->IsTopLevel() )
1576 // top level children are not inside our client area
1580 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1582 // this one is either already ok or nothing we can do about it
1586 int tempNoChanges
= 0;
1587 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1588 : child
->LayoutPhase2(&tempNoChanges
);
1589 noChanges
+= tempNoChanges
;
1593 succeeded
.Append(child
);
1599 // constraints are set
1607 void wxWindowBase::ResetConstraints()
1609 wxLayoutConstraints
*constr
= GetConstraints();
1612 constr
->left
.SetDone(FALSE
);
1613 constr
->top
.SetDone(FALSE
);
1614 constr
->right
.SetDone(FALSE
);
1615 constr
->bottom
.SetDone(FALSE
);
1616 constr
->width
.SetDone(FALSE
);
1617 constr
->height
.SetDone(FALSE
);
1618 constr
->centreX
.SetDone(FALSE
);
1619 constr
->centreY
.SetDone(FALSE
);
1622 wxWindowList::Node
*node
= GetChildren().GetFirst();
1625 wxWindow
*win
= node
->GetData();
1626 if ( !win
->IsTopLevel() )
1627 win
->ResetConstraints();
1628 node
= node
->GetNext();
1632 // Need to distinguish between setting the 'fake' size for windows and sizers,
1633 // and setting the real values.
1634 void wxWindowBase::SetConstraintSizes(bool recurse
)
1636 wxLayoutConstraints
*constr
= GetConstraints();
1637 if ( constr
&& constr
->AreSatisfied() )
1639 int x
= constr
->left
.GetValue();
1640 int y
= constr
->top
.GetValue();
1641 int w
= constr
->width
.GetValue();
1642 int h
= constr
->height
.GetValue();
1644 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1645 (constr
->height
.GetRelationship() != wxAsIs
) )
1647 SetSize(x
, y
, w
, h
);
1651 // If we don't want to resize this window, just move it...
1657 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1658 GetClassInfo()->GetClassName(),
1664 wxWindowList::Node
*node
= GetChildren().GetFirst();
1667 wxWindow
*win
= node
->GetData();
1668 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1669 win
->SetConstraintSizes();
1670 node
= node
->GetNext();
1675 // Only set the size/position of the constraint (if any)
1676 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1678 wxLayoutConstraints
*constr
= GetConstraints();
1683 constr
->left
.SetValue(x
);
1684 constr
->left
.SetDone(TRUE
);
1688 constr
->top
.SetValue(y
);
1689 constr
->top
.SetDone(TRUE
);
1693 constr
->width
.SetValue(w
);
1694 constr
->width
.SetDone(TRUE
);
1698 constr
->height
.SetValue(h
);
1699 constr
->height
.SetDone(TRUE
);
1704 void wxWindowBase::MoveConstraint(int x
, int y
)
1706 wxLayoutConstraints
*constr
= GetConstraints();
1711 constr
->left
.SetValue(x
);
1712 constr
->left
.SetDone(TRUE
);
1716 constr
->top
.SetValue(y
);
1717 constr
->top
.SetDone(TRUE
);
1722 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1724 wxLayoutConstraints
*constr
= GetConstraints();
1727 *w
= constr
->width
.GetValue();
1728 *h
= constr
->height
.GetValue();
1734 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1736 wxLayoutConstraints
*constr
= GetConstraints();
1739 *w
= constr
->width
.GetValue();
1740 *h
= constr
->height
.GetValue();
1743 GetClientSize(w
, h
);
1746 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1748 wxLayoutConstraints
*constr
= GetConstraints();
1751 *x
= constr
->left
.GetValue();
1752 *y
= constr
->top
.GetValue();
1758 #endif // wxUSE_CONSTRAINTS
1760 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
1762 // don't do it for the dialogs/frames - they float independently of their
1764 if ( !IsTopLevel() )
1766 wxWindow
*parent
= GetParent();
1767 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
1769 wxPoint
pt(parent
->GetClientAreaOrigin());
1776 // ----------------------------------------------------------------------------
1777 // do Update UI processing for child controls
1778 // ----------------------------------------------------------------------------
1780 // TODO: should this be implemented for the child window rather
1781 // than the parent? Then you can override it e.g. for wxCheckBox
1782 // to do the Right Thing rather than having to assume a fixed number
1783 // of control classes.
1784 void wxWindowBase::UpdateWindowUI()
1787 wxUpdateUIEvent
event(GetId());
1788 event
.m_eventObject
= this;
1790 if ( GetEventHandler()->ProcessEvent(event
) )
1792 if ( event
.GetSetEnabled() )
1793 Enable(event
.GetEnabled());
1795 if ( event
.GetSetText() )
1797 wxControl
*control
= wxDynamicCastThis(wxControl
);
1801 wxTextCtrl
*text
= wxDynamicCast(control
, wxTextCtrl
);
1804 if ( event
.GetText() != text
->GetValue() )
1805 text
->SetValue(event
.GetText());
1808 #endif // wxUSE_TEXTCTRL
1810 if ( event
.GetText() != control
->GetLabel() )
1811 control
->SetLabel(event
.GetText());
1817 wxCheckBox
*checkbox
= wxDynamicCastThis(wxCheckBox
);
1820 if ( event
.GetSetChecked() )
1821 checkbox
->SetValue(event
.GetChecked());
1823 #endif // wxUSE_CHECKBOX
1826 wxRadioButton
*radiobtn
= wxDynamicCastThis(wxRadioButton
);
1829 if ( event
.GetSetChecked() )
1830 radiobtn
->SetValue(event
.GetChecked());
1832 #endif // wxUSE_RADIOBTN
1834 #endif // wxUSE_CONTROLS
1837 // ----------------------------------------------------------------------------
1838 // dialog units translations
1839 // ----------------------------------------------------------------------------
1841 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1843 int charWidth
= GetCharWidth();
1844 int charHeight
= GetCharHeight();
1845 wxPoint
pt2(-1, -1);
1847 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1849 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1854 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1856 int charWidth
= GetCharWidth();
1857 int charHeight
= GetCharHeight();
1858 wxPoint
pt2(-1, -1);
1860 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1862 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1867 // ----------------------------------------------------------------------------
1869 // ----------------------------------------------------------------------------
1871 // propagate the colour change event to the subwindows
1872 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1874 wxWindowList::Node
*node
= GetChildren().GetFirst();
1877 // Only propagate to non-top-level windows
1878 wxWindow
*win
= node
->GetData();
1879 if ( !win
->IsTopLevel() )
1881 wxSysColourChangedEvent event2
;
1882 event
.m_eventObject
= win
;
1883 win
->GetEventHandler()->ProcessEvent(event2
);
1886 node
= node
->GetNext();
1890 // the default action is to populate dialog with data when it's created
1891 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1893 TransferDataToWindow();
1896 // process Ctrl-Alt-mclick
1897 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
1900 if ( event
.ControlDown() && event
.AltDown() )
1902 // don't translate these strings
1905 #ifdef __WXUNIVERSAL__
1907 #endif // __WXUNIVERSAL__
1909 switch ( wxGetOsVersion() )
1911 case wxMOTIF_X
: port
+= _T("Motif"); break;
1913 case wxMAC_DARWIN
: port
+= _T("Mac"); break;
1914 case wxBEOS
: port
+= _T("BeOS"); break;
1918 case wxGTK_BEOS
: port
+= _T("GTK"); break;
1924 case wxWIN386
: port
+= _T("MS Windows"); break;
1928 case wxMGL_OS2
: port
+= _T("MGL"); break;
1930 case wxOS2_PM
: port
+= _T("OS/2"); break;
1931 default: port
+= _T("unknown"); break;
1934 wxMessageBox(wxString::Format(
1936 " wxWindows Library (%s port)\nVersion %u.%u.%u%s, compiled at %s %s\n Copyright (c) 1995-2002 wxWindows team"
1950 _T("wxWindows information"),
1951 wxICON_INFORMATION
| wxOK
,
1955 #endif // wxUSE_MSGDLG
1961 // ----------------------------------------------------------------------------
1963 // ----------------------------------------------------------------------------
1965 #if wxUSE_ACCESSIBILITY
1966 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
1968 if (m_accessible
&& (accessible
!= m_accessible
))
1969 delete m_accessible
;
1970 m_accessible
= accessible
;
1972 m_accessible
->SetWindow((wxWindow
*) this);
1975 // Returns the accessible object, creating if necessary.
1976 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
1979 m_accessible
= CreateAccessible();
1980 return m_accessible
;
1983 // Override to create a specific accessible object.
1984 wxAccessible
* wxWindowBase::CreateAccessible()
1986 return new wxWindowAccessible((wxWindow
*) this);
1991 // ----------------------------------------------------------------------------
1992 // list classes implementation
1993 // ----------------------------------------------------------------------------
1995 void wxWindowListNode::DeleteData()
1997 delete (wxWindow
*)GetData();
2000 // ----------------------------------------------------------------------------
2002 // ----------------------------------------------------------------------------
2004 wxBorder
wxWindowBase::GetBorder() const
2006 wxBorder border
= (wxBorder
)(m_windowStyle
& wxBORDER_MASK
);
2007 if ( border
== wxBORDER_DEFAULT
)
2009 border
= GetDefaultBorder();
2015 wxBorder
wxWindowBase::GetDefaultBorder() const
2017 return wxBORDER_NONE
;
2020 // ----------------------------------------------------------------------------
2022 // ----------------------------------------------------------------------------
2024 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2026 // here we just check if the point is inside the window or not
2028 // check the top and left border first
2029 bool outside
= x
< 0 || y
< 0;
2032 // check the right and bottom borders too
2033 wxSize size
= GetSize();
2034 outside
= x
>= size
.x
|| y
>= size
.y
;
2037 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2040 // ----------------------------------------------------------------------------
2042 // ----------------------------------------------------------------------------
2044 struct WXDLLEXPORT wxWindowNext
2048 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2050 void wxWindowBase::CaptureMouse()
2052 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this);
2054 wxWindow
*winOld
= GetCapture();
2057 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2060 wxWindowNext
*item
= new wxWindowNext
;
2062 item
->next
= ms_winCaptureNext
;
2063 ms_winCaptureNext
= item
;
2065 //else: no mouse capture to save
2070 void wxWindowBase::ReleaseMouse()
2072 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this);
2074 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2078 if ( ms_winCaptureNext
)
2080 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2082 wxWindowNext
*item
= ms_winCaptureNext
;
2083 ms_winCaptureNext
= item
->next
;
2086 //else: stack is empty, no previous capture
2088 wxLogTrace(_T("mousecapture"),
2089 _T("After ReleaseMouse() mouse is captured by %p"),
2094 void wxWindowBase::SendDestroyEvent()
2096 wxWindowDestroyEvent event
;
2097 event
.SetEventObject(this);
2098 event
.SetId(GetId());
2099 GetEventHandler()->ProcessEvent(event
);
2102 // ----------------------------------------------------------------------------
2104 // ----------------------------------------------------------------------------
2106 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2108 while ( win
&& !win
->IsTopLevel() )
2109 win
= win
->GetParent();
2114 #if wxUSE_ACCESSIBILITY
2115 // ----------------------------------------------------------------------------
2116 // accessible object for windows
2117 // ----------------------------------------------------------------------------
2119 // Can return either a child object, or an integer
2120 // representing the child element, starting from 1.
2121 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& pt
, int* childId
, wxAccessible
** childObject
)
2123 wxASSERT( GetWindow() != NULL
);
2127 return wxACC_NOT_IMPLEMENTED
;
2130 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2131 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2133 wxASSERT( GetWindow() != NULL
);
2137 wxWindow
* win
= NULL
;
2144 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2146 win
= (wxWindow
*) GetWindow()->GetChildren().Nth(elementId
-1)->GetData();
2153 rect
= win
->GetRect();
2154 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2155 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2159 return wxACC_NOT_IMPLEMENTED
;
2162 // Navigates from fromId to toId/toObject.
2163 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2164 int* toId
, wxAccessible
** toObject
)
2166 wxASSERT( GetWindow() != NULL
);
2172 case wxNAVDIR_FIRSTCHILD
:
2174 if (GetWindow()->GetChildren().GetCount() == 0)
2176 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2177 *toObject
= childWindow
->GetOrCreateAccessible();
2181 case wxNAVDIR_LASTCHILD
:
2183 if (GetWindow()->GetChildren().GetCount() == 0)
2185 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2186 *toObject
= childWindow
->GetOrCreateAccessible();
2190 case wxNAVDIR_RIGHT
:
2194 wxWindowList::Node
*node
= NULL
;
2197 // Can't navigate to sibling of this window
2198 // if we're a top-level window.
2199 if (!GetWindow()->GetParent())
2200 return wxACC_NOT_IMPLEMENTED
;
2202 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2206 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2207 node
= (wxWindowList::Node
*) GetWindow()->GetChildren().Nth(fromId
-1);
2210 if (node
&& node
->GetNext())
2212 wxWindow
* nextWindow
= (wxWindow
*) node
->GetNext()->Data();
2213 *toObject
= nextWindow
->GetOrCreateAccessible();
2221 case wxNAVDIR_PREVIOUS
:
2223 wxWindowList::Node
*node
= NULL
;
2226 // Can't navigate to sibling of this window
2227 // if we're a top-level window.
2228 if (!GetWindow()->GetParent())
2229 return wxACC_NOT_IMPLEMENTED
;
2231 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2235 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2236 node
= (wxWindowList::Node
*) GetWindow()->GetChildren().Nth(fromId
-1);
2239 if (node
&& node
->GetPrevious())
2241 wxWindow
* previousWindow
= (wxWindow
*) node
->GetPrevious()->Data();
2242 *toObject
= previousWindow
->GetOrCreateAccessible();
2250 return wxACC_NOT_IMPLEMENTED
;
2253 // Gets the name of the specified object.
2254 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2256 wxASSERT( GetWindow() != NULL
);
2262 // If a child, leave wxWindows to call the function on the actual
2265 return wxACC_NOT_IMPLEMENTED
;
2267 // This will eventually be replaced by specialised
2268 // accessible classes, one for each kind of wxWindows
2269 // control or window.
2270 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2271 title
= ((wxButton
*) GetWindow())->GetLabel();
2273 title
= GetWindow()->GetName();
2275 if (!title
.IsEmpty())
2281 return wxACC_NOT_IMPLEMENTED
;
2284 // Gets the number of children.
2285 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2287 wxASSERT( GetWindow() != NULL
);
2291 *childId
= (int) GetWindow()->GetChildren().GetCount();
2295 // Gets the specified child (starting from 1).
2296 // If *child is NULL and return value is wxACC_OK,
2297 // this means that the child is a simple element and
2298 // not an accessible object.
2299 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2301 wxASSERT( GetWindow() != NULL
);
2311 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2314 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().Nth(childId
-1)->GetData();
2315 *child
= childWindow
->GetOrCreateAccessible();
2322 // Gets the parent, or NULL.
2323 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2325 wxASSERT( GetWindow() != NULL
);
2329 wxWindow
* parentWindow
= GetWindow()->GetParent();
2337 *parent
= parentWindow
->GetOrCreateAccessible();
2345 // Performs the default action. childId is 0 (the action for this object)
2346 // or > 0 (the action for a child).
2347 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2348 // window (e.g. an edit control).
2349 wxAccStatus
wxWindowAccessible::DoDefaultAction(int childId
)
2351 wxASSERT( GetWindow() != NULL
);
2355 return wxACC_NOT_IMPLEMENTED
;
2358 // Gets the default action for this object (0) or > 0 (the action for a child).
2359 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2360 // string if there is no action.
2361 // The retrieved string describes the action that is performed on an object,
2362 // not what the object does as a result. For example, a toolbar button that prints
2363 // a document has a default action of "Press" rather than "Prints the current document."
2364 wxAccStatus
wxWindowAccessible::GetDefaultAction(int childId
, wxString
* actionName
)
2366 wxASSERT( GetWindow() != NULL
);
2370 return wxACC_NOT_IMPLEMENTED
;
2373 // Returns the description for this object or a child.
2374 wxAccStatus
wxWindowAccessible::GetDescription(int childId
, wxString
* description
)
2376 wxASSERT( GetWindow() != NULL
);
2380 wxString
ht(GetWindow()->GetHelpText());
2386 return wxACC_NOT_IMPLEMENTED
;
2389 // Returns help text for this object or a child, similar to tooltip text.
2390 wxAccStatus
wxWindowAccessible::GetHelpText(int childId
, wxString
* helpText
)
2392 wxASSERT( GetWindow() != NULL
);
2396 wxString
ht(GetWindow()->GetHelpText());
2402 return wxACC_NOT_IMPLEMENTED
;
2405 // Returns the keyboard shortcut for this object or child.
2406 // Return e.g. ALT+K
2407 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int childId
, wxString
* shortcut
)
2409 wxASSERT( GetWindow() != NULL
);
2413 return wxACC_NOT_IMPLEMENTED
;
2416 // Returns a role constant.
2417 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
2419 wxASSERT( GetWindow() != NULL
);
2423 // If a child, leave wxWindows to call the function on the actual
2426 return wxACC_NOT_IMPLEMENTED
;
2428 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2429 return wxACC_NOT_IMPLEMENTED
;
2431 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2432 return wxACC_NOT_IMPLEMENTED
;
2435 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2436 return wxACC_NOT_IMPLEMENTED
;
2439 //*role = wxROLE_SYSTEM_CLIENT;
2440 *role
= wxROLE_SYSTEM_CLIENT
;
2443 return wxACC_NOT_IMPLEMENTED
;
2446 // Returns a state constant.
2447 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
2449 wxASSERT( GetWindow() != NULL
);
2453 // If a child, leave wxWindows to call the function on the actual
2456 return wxACC_NOT_IMPLEMENTED
;
2458 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2459 return wxACC_NOT_IMPLEMENTED
;
2462 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2463 return wxACC_NOT_IMPLEMENTED
;
2466 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2467 return wxACC_NOT_IMPLEMENTED
;
2473 return wxACC_NOT_IMPLEMENTED
;
2476 // Returns a localized string representing the value for the object
2478 wxAccStatus
wxWindowAccessible::GetValue(int childId
, wxString
* strValue
)
2480 wxASSERT( GetWindow() != NULL
);
2484 return wxACC_NOT_IMPLEMENTED
;
2487 // Selects the object or child.
2488 wxAccStatus
wxWindowAccessible::Select(int childId
, wxAccSelectionFlags selectFlags
)
2490 wxASSERT( GetWindow() != NULL
);
2494 return wxACC_NOT_IMPLEMENTED
;
2497 // Gets the window with the keyboard focus.
2498 // If childId is 0 and child is NULL, no object in
2499 // this subhierarchy has the focus.
2500 // If this object has the focus, child should be 'this'.
2501 wxAccStatus
wxWindowAccessible::GetFocus(int* childId
, wxAccessible
** child
)
2503 wxASSERT( GetWindow() != NULL
);
2507 return wxACC_NOT_IMPLEMENTED
;
2510 // Gets a variant representing the selected children
2512 // Acceptable values:
2513 // - a null variant (IsNull() returns TRUE)
2514 // - a list variant (GetType() == wxT("list")
2515 // - an integer representing the selected child element,
2516 // or 0 if this object is selected (GetType() == wxT("long")
2517 // - a "void*" pointer to a wxAccessible child object
2518 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* selections
)
2520 wxASSERT( GetWindow() != NULL
);
2524 return wxACC_NOT_IMPLEMENTED
;
2527 #endif // wxUSE_ACCESSIBILITY