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
)
210 // wxGTK doesn't allow to create controls with static box as the parent so
211 // this will result in a crash when the program is ported to wxGTK so warn
214 // if you get this assert, the correct solution is to create the controls
215 // as siblings of the static box
216 wxASSERT_MSG( !parent
|| !wxDynamicCast(parent
, wxStaticBox
),
217 _T("wxStaticBox can't be used as a window parent!") );
218 #endif // wxUSE_STATBOX
220 // ids are limited to 16 bits under MSW so if you care about portability,
221 // it's not a good idea to use ids out of this range (and negative ids are
222 // reserved for wxWindows own usage)
223 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767),
224 _T("invalid id value") );
226 // generate a new id if the user doesn't care about it
227 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
230 SetWindowStyleFlag(style
);
234 SetValidator(validator
);
235 #endif // wxUSE_VALIDATORS
237 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
238 // have it too - like this it's possible to set it only in the top level
239 // dialog/frame and all children will inherit it by defult
240 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
242 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
248 // ----------------------------------------------------------------------------
250 // ----------------------------------------------------------------------------
253 wxWindowBase::~wxWindowBase()
255 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
257 // FIXME if these 2 cases result from programming errors in the user code
258 // we should probably assert here instead of silently fixing them
260 // Just in case the window has been Closed, but we're then deleting
261 // immediately: don't leave dangling pointers.
262 wxPendingDelete
.DeleteObject(this);
264 // Just in case we've loaded a top-level window via LoadNativeDialog but
265 // we weren't a dialog class
266 wxTopLevelWindows
.DeleteObject(this);
268 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
273 #endif // wxUSE_CARET
276 if ( m_windowValidator
)
277 delete m_windowValidator
;
278 #endif // wxUSE_VALIDATORS
280 #if wxUSE_CONSTRAINTS
281 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
282 // at deleted windows as they delete themselves.
283 DeleteRelatedConstraints();
287 // This removes any dangling pointers to this window in other windows'
288 // constraintsInvolvedIn lists.
289 UnsetConstraints(m_constraints
);
290 delete m_constraints
;
291 m_constraints
= NULL
;
294 #endif // wxUSE_CONSTRAINTS
296 if ( m_containingSizer
)
297 m_containingSizer
->Detach( (wxWindow
*)this );
300 delete m_windowSizer
;
302 #if wxUSE_DRAG_AND_DROP
305 #endif // wxUSE_DRAG_AND_DROP
310 #endif // wxUSE_TOOLTIPS
312 #if wxUSE_ACCESSIBILITY
317 // reset the dangling pointer our parent window may keep to us
318 if ( m_parent
&& m_parent
->GetDefaultItem() == this )
320 m_parent
->SetDefaultItem(NULL
);
324 bool wxWindowBase::Destroy()
331 bool wxWindowBase::Close(bool force
)
333 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
334 event
.SetEventObject(this);
335 #if WXWIN_COMPATIBILITY
336 event
.SetForce(force
);
337 #endif // WXWIN_COMPATIBILITY
338 event
.SetCanVeto(!force
);
340 // return FALSE if window wasn't closed because the application vetoed the
342 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
345 bool wxWindowBase::DestroyChildren()
347 wxWindowList::Node
*node
;
350 // we iterate until the list becomes empty
351 node
= GetChildren().GetFirst();
355 wxWindow
*child
= node
->GetData();
357 wxASSERT_MSG( child
, wxT("children list contains empty nodes") );
362 wxASSERT_MSG( !GetChildren().Find(child
),
363 wxT("child didn't remove itself using RemoveChild()") );
369 // ----------------------------------------------------------------------------
370 // size/position related methods
371 // ----------------------------------------------------------------------------
373 // centre the window with respect to its parent in either (or both) directions
374 void wxWindowBase::Centre(int direction
)
376 // the position/size of the parent window or of the entire screen
378 int widthParent
, heightParent
;
380 wxWindow
*parent
= NULL
;
382 if ( !(direction
& wxCENTRE_ON_SCREEN
) )
384 // find the parent to centre this window on: it should be the
385 // immediate parent for the controls but the top level parent for the
386 // top level windows (like dialogs)
387 parent
= GetParent();
390 while ( parent
&& !parent
->IsTopLevel() )
392 parent
= parent
->GetParent();
396 // there is no wxTopLevelWindow under wxMotif yet
398 // we shouldn't center the dialog on the iconized window: under
399 // Windows, for example, this places it completely off the screen
402 wxTopLevelWindow
*winTop
= wxDynamicCast(parent
, wxTopLevelWindow
);
403 if ( winTop
&& winTop
->IsIconized() )
408 #endif // __WXMOTIF__
410 // did we find the parent?
414 direction
|= wxCENTRE_ON_SCREEN
;
418 if ( direction
& wxCENTRE_ON_SCREEN
)
420 // centre with respect to the whole screen
421 wxDisplaySize(&widthParent
, &heightParent
);
427 // centre on the parent
428 parent
->GetSize(&widthParent
, &heightParent
);
430 // adjust to the parents position
431 posParent
= parent
->GetPosition();
435 // centre inside the parents client rectangle
436 parent
->GetClientSize(&widthParent
, &heightParent
);
441 GetSize(&width
, &height
);
446 if ( direction
& wxHORIZONTAL
)
447 xNew
= (widthParent
- width
)/2;
449 if ( direction
& wxVERTICAL
)
450 yNew
= (heightParent
- height
)/2;
455 // Base size of the visible dimensions of the display
456 // to take into account the taskbar
457 wxRect rect
= wxGetClientDisplayRect();
458 wxSize
size (rect
.width
,rect
.height
);
460 // NB: in wxMSW, negative position may not neccessary mean "out of screen",
461 // but it may mean that the window is placed on other than the main
462 // display. Therefore we only make sure centered window is on the main display
463 // if the parent is at least partially present here.
464 if (posParent
.x
+ widthParent
>= 0) // if parent is (partially) on the main display
468 else if (xNew
+width
> size
.x
)
469 xNew
= size
.x
-width
-1;
471 if (posParent
.y
+ heightParent
>= 0) // if parent is (partially) on the main display
473 if (yNew
+height
> size
.y
)
474 yNew
= size
.y
-height
-1;
476 // Make certain that the title bar is initially visible
477 // always, even if this would push the bottom of the
478 // dialog of the visible area of the display
483 // move the window to this position (keeping the old size but using
484 // SetSize() and not Move() to allow xNew and/or yNew to be -1)
485 SetSize(xNew
, yNew
, width
, height
, wxSIZE_ALLOW_MINUS_ONE
);
488 // fits the window around the children
489 void wxWindowBase::Fit()
491 if ( GetChildren().GetCount() > 0 )
493 SetClientSize(DoGetBestSize());
495 //else: do nothing if we have no children
498 // fits virtual size (ie. scrolled area etc.) around children
499 void wxWindowBase::FitInside()
501 if ( GetChildren().GetCount() > 0 )
503 SetVirtualSize( GetBestVirtualSize() );
507 // return the size best suited for the current window
508 wxSize
wxWindowBase::DoGetBestSize() const
512 return m_windowSizer
->GetMinSize();
514 #if wxUSE_CONSTRAINTS
515 else if ( m_constraints
)
517 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
519 // our minimal acceptable size is such that all our windows fit inside
523 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
525 node
= node
->GetNext() )
527 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
530 // it's not normal that we have an unconstrained child, but
531 // what can we do about it?
535 int x
= c
->right
.GetValue(),
536 y
= c
->bottom
.GetValue();
544 // TODO: we must calculate the overlaps somehow, otherwise we
545 // will never return a size bigger than the current one :-(
548 return wxSize(maxX
, maxY
);
550 #endif // wxUSE_CONSTRAINTS
551 else if ( GetChildren().GetCount() > 0 )
553 // our minimal acceptable size is such that all our windows fit inside
557 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
559 node
= node
->GetNext() )
561 wxWindow
*win
= node
->GetData();
562 if ( win
->IsTopLevel()
564 || wxDynamicCast(win
, wxStatusBar
)
565 #endif // wxUSE_STATUSBAR
568 // dialogs and frames lie in different top level windows -
569 // don't deal with them here; as for the status bars, they
570 // don't lie in the client area at all
575 win
->GetPosition(&wx
, &wy
);
577 // if the window hadn't been positioned yet, assume that it is in
584 win
->GetSize(&ww
, &wh
);
585 if ( wx
+ ww
> maxX
)
587 if ( wy
+ wh
> maxY
)
591 // for compatibility with the old versions and because it really looks
592 // slightly more pretty like this, add a pad
596 return wxSize(maxX
, maxY
);
600 // for a generic window there is no natural best size - just use the
606 // by default the origin is not shifted
607 wxPoint
wxWindowBase::GetClientAreaOrigin() const
609 return wxPoint(0, 0);
612 // set the min/max size of the window
613 void wxWindowBase::SetSizeHints(int minW
, int minH
,
615 int WXUNUSED(incW
), int WXUNUSED(incH
))
617 // setting min width greater than max width leads to infinite loops under
618 // X11 and generally doesn't make any sense, so don't allow it
619 wxCHECK_RET( (minW
== -1 || maxW
== -1 || minW
<= maxW
) &&
620 (minH
== -1 || maxH
== -1 || minH
<= maxH
),
621 _T("min width/height must be less than max width/height!") );
629 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
632 m_minVirtualWidth
= minW
;
633 m_maxVirtualWidth
= maxW
;
634 m_minVirtualHeight
= minH
;
635 m_maxVirtualHeight
= maxH
;
638 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
640 if ( m_minVirtualWidth
!= -1 && m_minVirtualWidth
> x
)
641 x
= m_minVirtualWidth
;
642 if ( m_maxVirtualWidth
!= -1 && m_maxVirtualWidth
< x
)
643 x
= m_maxVirtualWidth
;
644 if ( m_minVirtualHeight
!= -1 && m_minVirtualHeight
> y
)
645 y
= m_minVirtualHeight
;
646 if ( m_maxVirtualHeight
!= -1 && m_maxVirtualHeight
< y
)
647 y
= m_maxVirtualHeight
;
649 m_virtualSize
= wxSize(x
, y
);
652 wxSize
wxWindowBase::DoGetVirtualSize() const
654 wxSize
s( GetClientSize() );
656 return wxSize( wxMax( m_virtualSize
.GetWidth(), s
.GetWidth() ),
657 wxMax( m_virtualSize
.GetHeight(), s
.GetHeight() ) );
660 // ----------------------------------------------------------------------------
661 // show/hide/enable/disable the window
662 // ----------------------------------------------------------------------------
664 bool wxWindowBase::Show(bool show
)
666 if ( show
!= m_isShown
)
678 bool wxWindowBase::Enable(bool enable
)
680 if ( enable
!= m_isEnabled
)
682 m_isEnabled
= enable
;
691 // ----------------------------------------------------------------------------
693 // ----------------------------------------------------------------------------
695 bool wxWindowBase::IsTopLevel() const
700 // ----------------------------------------------------------------------------
701 // reparenting the window
702 // ----------------------------------------------------------------------------
704 void wxWindowBase::AddChild(wxWindowBase
*child
)
706 wxCHECK_RET( child
, wxT("can't add a NULL child") );
708 // this should never happen and it will lead to a crash later if it does
709 // because RemoveChild() will remove only one node from the children list
710 // and the other(s) one(s) will be left with dangling pointers in them
711 wxASSERT_MSG( !GetChildren().Find(child
), _T("AddChild() called twice") );
713 GetChildren().Append(child
);
714 child
->SetParent(this);
717 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
719 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
721 GetChildren().DeleteObject(child
);
722 child
->SetParent((wxWindow
*)NULL
);
725 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
727 wxWindow
*oldParent
= GetParent();
728 if ( newParent
== oldParent
)
734 // unlink this window from the existing parent.
737 oldParent
->RemoveChild(this);
741 wxTopLevelWindows
.DeleteObject(this);
744 // add it to the new one
747 newParent
->AddChild(this);
751 wxTopLevelWindows
.Append(this);
757 // ----------------------------------------------------------------------------
758 // event handler stuff
759 // ----------------------------------------------------------------------------
761 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
763 wxEvtHandler
*handlerOld
= GetEventHandler();
765 handler
->SetNextHandler(handlerOld
);
768 GetEventHandler()->SetPreviousHandler(handler
);
770 SetEventHandler(handler
);
773 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
775 wxEvtHandler
*handlerA
= GetEventHandler();
778 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
779 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
782 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
783 SetEventHandler(handlerB
);
788 handlerA
= (wxEvtHandler
*)NULL
;
795 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
797 wxCHECK_MSG( handler
, FALSE
, _T("RemoveEventHandler(NULL) called") );
799 wxEvtHandler
*handlerPrev
= NULL
,
800 *handlerCur
= GetEventHandler();
803 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
805 if ( handlerCur
== handler
)
809 handlerPrev
->SetNextHandler(handlerNext
);
813 SetEventHandler(handlerNext
);
818 handlerNext
->SetPreviousHandler ( handlerPrev
);
820 handler
->SetNextHandler(NULL
);
825 handlerPrev
= handlerCur
;
826 handlerCur
= handlerNext
;
829 wxFAIL_MSG( _T("where has the event handler gone?") );
834 // ----------------------------------------------------------------------------
836 // ----------------------------------------------------------------------------
838 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
840 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
843 m_backgroundColour
= colour
;
850 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
852 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
855 m_foregroundColour
= colour
;
862 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
864 // setting an invalid cursor is ok, it means that we don't have any special
866 if ( m_cursor
== cursor
)
877 bool wxWindowBase::SetFont(const wxFont
& font
)
879 // don't try to set invalid font, always fall back to the default
880 const wxFont
& fontOk
= font
.Ok() ? font
: *wxSWISS_FONT
;
882 if ( fontOk
== m_font
)
897 void wxWindowBase::SetPalette(const wxPalette
& pal
)
899 m_hasCustomPalette
= TRUE
;
902 // VZ: can anyone explain me what do we do here?
903 wxWindowDC
d((wxWindow
*) this);
907 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
909 wxWindow
*win
= (wxWindow
*)this;
910 while ( win
&& !win
->HasCustomPalette() )
912 win
= win
->GetParent();
918 #endif // wxUSE_PALETTE
921 void wxWindowBase::SetCaret(wxCaret
*caret
)
932 wxASSERT_MSG( m_caret
->GetWindow() == this,
933 wxT("caret should be created associated to this window") );
936 #endif // wxUSE_CARET
939 // ----------------------------------------------------------------------------
941 // ----------------------------------------------------------------------------
943 void wxWindowBase::SetValidator(const wxValidator
& validator
)
945 if ( m_windowValidator
)
946 delete m_windowValidator
;
948 m_windowValidator
= (wxValidator
*)validator
.Clone();
950 if ( m_windowValidator
)
951 m_windowValidator
->SetWindow(this) ;
953 #endif // wxUSE_VALIDATORS
955 // ----------------------------------------------------------------------------
956 // update region stuff
957 // ----------------------------------------------------------------------------
959 wxRect
wxWindowBase::GetUpdateClientRect() const
961 wxRegion rgnUpdate
= GetUpdateRegion();
962 rgnUpdate
.Intersect(GetClientRect());
963 wxRect rectUpdate
= rgnUpdate
.GetBox();
964 wxPoint ptOrigin
= GetClientAreaOrigin();
965 rectUpdate
.x
-= ptOrigin
.x
;
966 rectUpdate
.y
-= ptOrigin
.y
;
971 bool wxWindowBase::IsExposed(int x
, int y
) const
973 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
976 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
978 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
981 // ----------------------------------------------------------------------------
982 // find child window by id or name
983 // ----------------------------------------------------------------------------
985 wxWindow
*wxWindowBase::FindWindow( long id
)
987 if ( id
== m_windowId
)
988 return (wxWindow
*)this;
990 wxWindowBase
*res
= (wxWindow
*)NULL
;
991 wxWindowList::Node
*node
;
992 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
994 wxWindowBase
*child
= node
->GetData();
995 res
= child
->FindWindow( id
);
998 return (wxWindow
*)res
;
1001 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
1003 if ( name
== m_windowName
)
1004 return (wxWindow
*)this;
1006 wxWindowBase
*res
= (wxWindow
*)NULL
;
1007 wxWindowList::Node
*node
;
1008 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1010 wxWindow
*child
= node
->GetData();
1011 res
= child
->FindWindow(name
);
1014 return (wxWindow
*)res
;
1018 // find any window by id or name or label: If parent is non-NULL, look through
1019 // children for a label or title matching the specified string. If NULL, look
1020 // through all top-level windows.
1022 // to avoid duplicating code we reuse the same helper function but with
1023 // different comparators
1025 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1026 const wxString
& label
, long id
);
1029 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1032 return win
->GetLabel() == label
;
1036 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1039 return win
->GetName() == label
;
1043 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1046 return win
->GetId() == id
;
1049 // recursive helper for the FindWindowByXXX() functions
1051 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1052 const wxString
& label
,
1054 wxFindWindowCmp cmp
)
1058 // see if this is the one we're looking for
1059 if ( (*cmp
)(parent
, label
, id
) )
1060 return (wxWindow
*)parent
;
1062 // It wasn't, so check all its children
1063 for ( wxWindowList::Node
* node
= parent
->GetChildren().GetFirst();
1065 node
= node
->GetNext() )
1067 // recursively check each child
1068 wxWindow
*win
= (wxWindow
*)node
->GetData();
1069 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1079 // helper for FindWindowByXXX()
1081 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1082 const wxString
& label
,
1084 wxFindWindowCmp cmp
)
1088 // just check parent and all its children
1089 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1092 // start at very top of wx's windows
1093 for ( wxWindowList::Node
* node
= wxTopLevelWindows
.GetFirst();
1095 node
= node
->GetNext() )
1097 // recursively check each window & its children
1098 wxWindow
*win
= node
->GetData();
1099 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1109 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1111 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1116 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1118 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1122 // fall back to the label
1123 win
= FindWindowByLabel(title
, parent
);
1131 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1133 return wxFindWindowHelper(parent
, _T(""), id
, wxFindWindowCmpIds
);
1136 // ----------------------------------------------------------------------------
1137 // dialog oriented functions
1138 // ----------------------------------------------------------------------------
1140 void wxWindowBase::MakeModal(bool modal
)
1142 // Disable all other windows
1145 wxWindowList::Node
*node
= wxTopLevelWindows
.GetFirst();
1148 wxWindow
*win
= node
->GetData();
1150 win
->Enable(!modal
);
1152 node
= node
->GetNext();
1157 bool wxWindowBase::Validate()
1159 #if wxUSE_VALIDATORS
1160 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1162 wxWindowList::Node
*node
;
1163 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1165 wxWindowBase
*child
= node
->GetData();
1166 wxValidator
*validator
= child
->GetValidator();
1167 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1172 if ( recurse
&& !child
->Validate() )
1177 #endif // wxUSE_VALIDATORS
1182 bool wxWindowBase::TransferDataToWindow()
1184 #if wxUSE_VALIDATORS
1185 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1187 wxWindowList::Node
*node
;
1188 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1190 wxWindowBase
*child
= node
->GetData();
1191 wxValidator
*validator
= child
->GetValidator();
1192 if ( validator
&& !validator
->TransferToWindow() )
1194 wxLogWarning(_("Could not transfer data to window"));
1196 wxLog::FlushActive();
1204 if ( !child
->TransferDataToWindow() )
1206 // warning already given
1211 #endif // wxUSE_VALIDATORS
1216 bool wxWindowBase::TransferDataFromWindow()
1218 #if wxUSE_VALIDATORS
1219 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1221 wxWindowList::Node
*node
;
1222 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1224 wxWindow
*child
= node
->GetData();
1225 wxValidator
*validator
= child
->GetValidator();
1226 if ( validator
&& !validator
->TransferFromWindow() )
1228 // nop warning here because the application is supposed to give
1229 // one itself - we don't know here what might have gone wrongly
1236 if ( !child
->TransferDataFromWindow() )
1238 // warning already given
1243 #endif // wxUSE_VALIDATORS
1248 void wxWindowBase::InitDialog()
1250 wxInitDialogEvent
event(GetId());
1251 event
.SetEventObject( this );
1252 GetEventHandler()->ProcessEvent(event
);
1255 // ----------------------------------------------------------------------------
1256 // context-sensitive help support
1257 // ----------------------------------------------------------------------------
1261 // associate this help text with this window
1262 void wxWindowBase::SetHelpText(const wxString
& text
)
1264 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1267 helpProvider
->AddHelp(this, text
);
1271 // associate this help text with all windows with the same id as this
1273 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1275 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1278 helpProvider
->AddHelp(GetId(), text
);
1282 // get the help string associated with this window (may be empty)
1283 wxString
wxWindowBase::GetHelpText() const
1286 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1289 text
= helpProvider
->GetHelp(this);
1295 // show help for this window
1296 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1298 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1301 if ( helpProvider
->ShowHelp(this) )
1303 // skip the event.Skip() below
1311 #endif // wxUSE_HELP
1313 // ----------------------------------------------------------------------------
1314 // tooltipsroot.Replace("\\", "/");
1315 // ----------------------------------------------------------------------------
1319 void wxWindowBase::SetToolTip( const wxString
&tip
)
1321 // don't create the new tooltip if we already have one
1324 m_tooltip
->SetTip( tip
);
1328 SetToolTip( new wxToolTip( tip
) );
1331 // setting empty tooltip text does not remove the tooltip any more - use
1332 // SetToolTip((wxToolTip *)NULL) for this
1335 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1340 m_tooltip
= tooltip
;
1343 #endif // wxUSE_TOOLTIPS
1345 // ----------------------------------------------------------------------------
1346 // constraints and sizers
1347 // ----------------------------------------------------------------------------
1349 #if wxUSE_CONSTRAINTS
1351 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1353 if ( m_constraints
)
1355 UnsetConstraints(m_constraints
);
1356 delete m_constraints
;
1358 m_constraints
= constraints
;
1359 if ( m_constraints
)
1361 // Make sure other windows know they're part of a 'meaningful relationship'
1362 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1363 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1364 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1365 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1366 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1367 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1368 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1369 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1370 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1371 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1372 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1373 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1374 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1375 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1376 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1377 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1381 // This removes any dangling pointers to this window in other windows'
1382 // constraintsInvolvedIn lists.
1383 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1387 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1388 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1389 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1390 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1391 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1392 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1393 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1394 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1395 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1396 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1397 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1398 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1399 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1400 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1401 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1402 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1406 // Back-pointer to other windows we're involved with, so if we delete this
1407 // window, we must delete any constraints we're involved with.
1408 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1410 if ( !m_constraintsInvolvedIn
)
1411 m_constraintsInvolvedIn
= new wxWindowList
;
1412 if ( !m_constraintsInvolvedIn
->Find(otherWin
) )
1413 m_constraintsInvolvedIn
->Append(otherWin
);
1416 // REMOVE back-pointer to other windows we're involved with.
1417 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1419 if ( m_constraintsInvolvedIn
)
1420 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
1423 // Reset any constraints that mention this window
1424 void wxWindowBase::DeleteRelatedConstraints()
1426 if ( m_constraintsInvolvedIn
)
1428 wxWindowList::Node
*node
= m_constraintsInvolvedIn
->GetFirst();
1431 wxWindow
*win
= node
->GetData();
1432 wxLayoutConstraints
*constr
= win
->GetConstraints();
1434 // Reset any constraints involving this window
1437 constr
->left
.ResetIfWin(this);
1438 constr
->top
.ResetIfWin(this);
1439 constr
->right
.ResetIfWin(this);
1440 constr
->bottom
.ResetIfWin(this);
1441 constr
->width
.ResetIfWin(this);
1442 constr
->height
.ResetIfWin(this);
1443 constr
->centreX
.ResetIfWin(this);
1444 constr
->centreY
.ResetIfWin(this);
1447 wxWindowList::Node
*next
= node
->GetNext();
1452 delete m_constraintsInvolvedIn
;
1453 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1457 #endif // wxUSE_CONSTRAINTS
1459 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1462 delete m_windowSizer
;
1464 m_windowSizer
= sizer
;
1466 SetAutoLayout( sizer
!= NULL
);
1469 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1471 SetSizer( sizer
, deleteOld
);
1472 sizer
->SetSizeHints( (wxWindow
*) this );
1475 #if wxUSE_CONSTRAINTS
1477 void wxWindowBase::SatisfyConstraints()
1479 wxLayoutConstraints
*constr
= GetConstraints();
1480 bool wasOk
= constr
&& constr
->AreSatisfied();
1482 ResetConstraints(); // Mark all constraints as unevaluated
1486 // if we're a top level panel (i.e. our parent is frame/dialog), our
1487 // own constraints will never be satisfied any more unless we do it
1491 while ( noChanges
> 0 )
1493 LayoutPhase1(&noChanges
);
1497 LayoutPhase2(&noChanges
);
1500 #endif // wxUSE_CONSTRAINTS
1502 bool wxWindowBase::Layout()
1504 // If there is a sizer, use it instead of the constraints
1508 GetVirtualSize(&w
, &h
);
1509 GetSizer()->SetDimension( 0, 0, w
, h
);
1511 #if wxUSE_CONSTRAINTS
1514 SatisfyConstraints(); // Find the right constraints values
1515 SetConstraintSizes(); // Recursively set the real window sizes
1522 #if wxUSE_CONSTRAINTS
1524 // first phase of the constraints evaluation: set our own constraints
1525 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1527 wxLayoutConstraints
*constr
= GetConstraints();
1529 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1532 // second phase: set the constraints for our children
1533 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1540 // Layout grand children
1546 // Do a phase of evaluating child constraints
1547 bool wxWindowBase::DoPhase(int phase
)
1549 // the list containing the children for which the constraints are already
1551 wxWindowList succeeded
;
1553 // the max number of iterations we loop before concluding that we can't set
1555 static const int maxIterations
= 500;
1557 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1561 // loop over all children setting their constraints
1562 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
1564 node
= node
->GetNext() )
1566 wxWindow
*child
= node
->GetData();
1567 if ( child
->IsTopLevel() )
1569 // top level children are not inside our client area
1573 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1575 // this one is either already ok or nothing we can do about it
1579 int tempNoChanges
= 0;
1580 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1581 : child
->LayoutPhase2(&tempNoChanges
);
1582 noChanges
+= tempNoChanges
;
1586 succeeded
.Append(child
);
1592 // constraints are set
1600 void wxWindowBase::ResetConstraints()
1602 wxLayoutConstraints
*constr
= GetConstraints();
1605 constr
->left
.SetDone(FALSE
);
1606 constr
->top
.SetDone(FALSE
);
1607 constr
->right
.SetDone(FALSE
);
1608 constr
->bottom
.SetDone(FALSE
);
1609 constr
->width
.SetDone(FALSE
);
1610 constr
->height
.SetDone(FALSE
);
1611 constr
->centreX
.SetDone(FALSE
);
1612 constr
->centreY
.SetDone(FALSE
);
1615 wxWindowList::Node
*node
= GetChildren().GetFirst();
1618 wxWindow
*win
= node
->GetData();
1619 if ( !win
->IsTopLevel() )
1620 win
->ResetConstraints();
1621 node
= node
->GetNext();
1625 // Need to distinguish between setting the 'fake' size for windows and sizers,
1626 // and setting the real values.
1627 void wxWindowBase::SetConstraintSizes(bool recurse
)
1629 wxLayoutConstraints
*constr
= GetConstraints();
1630 if ( constr
&& constr
->AreSatisfied() )
1632 int x
= constr
->left
.GetValue();
1633 int y
= constr
->top
.GetValue();
1634 int w
= constr
->width
.GetValue();
1635 int h
= constr
->height
.GetValue();
1637 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1638 (constr
->height
.GetRelationship() != wxAsIs
) )
1640 SetSize(x
, y
, w
, h
);
1644 // If we don't want to resize this window, just move it...
1650 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1651 GetClassInfo()->GetClassName(),
1657 wxWindowList::Node
*node
= GetChildren().GetFirst();
1660 wxWindow
*win
= node
->GetData();
1661 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1662 win
->SetConstraintSizes();
1663 node
= node
->GetNext();
1668 // Only set the size/position of the constraint (if any)
1669 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1671 wxLayoutConstraints
*constr
= GetConstraints();
1676 constr
->left
.SetValue(x
);
1677 constr
->left
.SetDone(TRUE
);
1681 constr
->top
.SetValue(y
);
1682 constr
->top
.SetDone(TRUE
);
1686 constr
->width
.SetValue(w
);
1687 constr
->width
.SetDone(TRUE
);
1691 constr
->height
.SetValue(h
);
1692 constr
->height
.SetDone(TRUE
);
1697 void wxWindowBase::MoveConstraint(int x
, int y
)
1699 wxLayoutConstraints
*constr
= GetConstraints();
1704 constr
->left
.SetValue(x
);
1705 constr
->left
.SetDone(TRUE
);
1709 constr
->top
.SetValue(y
);
1710 constr
->top
.SetDone(TRUE
);
1715 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1717 wxLayoutConstraints
*constr
= GetConstraints();
1720 *w
= constr
->width
.GetValue();
1721 *h
= constr
->height
.GetValue();
1727 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1729 wxLayoutConstraints
*constr
= GetConstraints();
1732 *w
= constr
->width
.GetValue();
1733 *h
= constr
->height
.GetValue();
1736 GetClientSize(w
, h
);
1739 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1741 wxLayoutConstraints
*constr
= GetConstraints();
1744 *x
= constr
->left
.GetValue();
1745 *y
= constr
->top
.GetValue();
1751 #endif // wxUSE_CONSTRAINTS
1753 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
1755 // don't do it for the dialogs/frames - they float independently of their
1757 if ( !IsTopLevel() )
1759 wxWindow
*parent
= GetParent();
1760 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
1762 wxPoint
pt(parent
->GetClientAreaOrigin());
1769 // ----------------------------------------------------------------------------
1770 // do Update UI processing for child controls
1771 // ----------------------------------------------------------------------------
1773 // TODO: should this be implemented for the child window rather
1774 // than the parent? Then you can override it e.g. for wxCheckBox
1775 // to do the Right Thing rather than having to assume a fixed number
1776 // of control classes.
1777 void wxWindowBase::UpdateWindowUI()
1780 wxUpdateUIEvent
event(GetId());
1781 event
.m_eventObject
= this;
1783 if ( GetEventHandler()->ProcessEvent(event
) )
1785 if ( event
.GetSetEnabled() )
1786 Enable(event
.GetEnabled());
1788 if ( event
.GetSetText() )
1790 wxControl
*control
= wxDynamicCastThis(wxControl
);
1794 wxTextCtrl
*text
= wxDynamicCast(control
, wxTextCtrl
);
1797 if ( event
.GetText() != text
->GetValue() )
1798 text
->SetValue(event
.GetText());
1801 #endif // wxUSE_TEXTCTRL
1803 if ( event
.GetText() != control
->GetLabel() )
1804 control
->SetLabel(event
.GetText());
1810 wxCheckBox
*checkbox
= wxDynamicCastThis(wxCheckBox
);
1813 if ( event
.GetSetChecked() )
1814 checkbox
->SetValue(event
.GetChecked());
1816 #endif // wxUSE_CHECKBOX
1819 wxRadioButton
*radiobtn
= wxDynamicCastThis(wxRadioButton
);
1822 if ( event
.GetSetChecked() )
1823 radiobtn
->SetValue(event
.GetChecked());
1825 #endif // wxUSE_RADIOBTN
1827 #endif // wxUSE_CONTROLS
1830 // ----------------------------------------------------------------------------
1831 // dialog units translations
1832 // ----------------------------------------------------------------------------
1834 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1836 int charWidth
= GetCharWidth();
1837 int charHeight
= GetCharHeight();
1838 wxPoint
pt2(-1, -1);
1840 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1842 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1847 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1849 int charWidth
= GetCharWidth();
1850 int charHeight
= GetCharHeight();
1851 wxPoint
pt2(-1, -1);
1853 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1855 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1860 // ----------------------------------------------------------------------------
1862 // ----------------------------------------------------------------------------
1864 // propagate the colour change event to the subwindows
1865 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1867 wxWindowList::Node
*node
= GetChildren().GetFirst();
1870 // Only propagate to non-top-level windows
1871 wxWindow
*win
= node
->GetData();
1872 if ( !win
->IsTopLevel() )
1874 wxSysColourChangedEvent event2
;
1875 event
.m_eventObject
= win
;
1876 win
->GetEventHandler()->ProcessEvent(event2
);
1879 node
= node
->GetNext();
1883 // the default action is to populate dialog with data when it's created
1884 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1886 TransferDataToWindow();
1889 // process Ctrl-Alt-mclick
1890 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
1893 if ( event
.ControlDown() && event
.AltDown() )
1895 // don't translate these strings
1898 #ifdef __WXUNIVERSAL__
1900 #endif // __WXUNIVERSAL__
1902 switch ( wxGetOsVersion() )
1904 case wxMOTIF_X
: port
+= _T("Motif"); break;
1906 case wxMAC_DARWIN
: port
+= _T("Mac"); break;
1907 case wxBEOS
: port
+= _T("BeOS"); break;
1911 case wxGTK_BEOS
: port
+= _T("GTK"); break;
1917 case wxWIN386
: port
+= _T("MS Windows"); break;
1921 case wxMGL_OS2
: port
+= _T("MGL"); break;
1923 case wxOS2_PM
: port
+= _T("OS/2"); break;
1924 default: port
+= _T("unknown"); break;
1927 wxMessageBox(wxString::Format(
1929 " wxWindows Library (%s port)\nVersion %u.%u.%u%s, compiled at %s %s\n Copyright (c) 1995-2002 wxWindows team"
1943 _T("wxWindows information"),
1944 wxICON_INFORMATION
| wxOK
,
1948 #endif // wxUSE_MSGDLG
1954 // ----------------------------------------------------------------------------
1956 // ----------------------------------------------------------------------------
1958 #if wxUSE_ACCESSIBILITY
1959 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
1961 if (m_accessible
&& (accessible
!= m_accessible
))
1962 delete m_accessible
;
1963 m_accessible
= accessible
;
1965 m_accessible
->SetWindow((wxWindow
*) this);
1968 // Returns the accessible object, creating if necessary.
1969 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
1972 m_accessible
= CreateAccessible();
1973 return m_accessible
;
1976 // Override to create a specific accessible object.
1977 wxAccessible
* wxWindowBase::CreateAccessible()
1979 return new wxWindowAccessible((wxWindow
*) this);
1984 // ----------------------------------------------------------------------------
1985 // list classes implementation
1986 // ----------------------------------------------------------------------------
1988 void wxWindowListNode::DeleteData()
1990 delete (wxWindow
*)GetData();
1993 // ----------------------------------------------------------------------------
1995 // ----------------------------------------------------------------------------
1997 wxBorder
wxWindowBase::GetBorder() const
1999 wxBorder border
= (wxBorder
)(m_windowStyle
& wxBORDER_MASK
);
2000 if ( border
== wxBORDER_DEFAULT
)
2002 border
= GetDefaultBorder();
2008 wxBorder
wxWindowBase::GetDefaultBorder() const
2010 return wxBORDER_NONE
;
2013 // ----------------------------------------------------------------------------
2015 // ----------------------------------------------------------------------------
2017 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2019 // here we just check if the point is inside the window or not
2021 // check the top and left border first
2022 bool outside
= x
< 0 || y
< 0;
2025 // check the right and bottom borders too
2026 wxSize size
= GetSize();
2027 outside
= x
>= size
.x
|| y
>= size
.y
;
2030 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2033 // ----------------------------------------------------------------------------
2035 // ----------------------------------------------------------------------------
2037 struct WXDLLEXPORT wxWindowNext
2041 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2043 void wxWindowBase::CaptureMouse()
2045 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this);
2047 wxWindow
*winOld
= GetCapture();
2050 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2053 wxWindowNext
*item
= new wxWindowNext
;
2055 item
->next
= ms_winCaptureNext
;
2056 ms_winCaptureNext
= item
;
2058 //else: no mouse capture to save
2063 void wxWindowBase::ReleaseMouse()
2065 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this);
2067 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2071 if ( ms_winCaptureNext
)
2073 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2075 wxWindowNext
*item
= ms_winCaptureNext
;
2076 ms_winCaptureNext
= item
->next
;
2079 //else: stack is empty, no previous capture
2081 wxLogTrace(_T("mousecapture"),
2082 _T("After ReleaseMouse() mouse is captured by %p"),
2087 void wxWindowBase::SendDestroyEvent()
2089 wxWindowDestroyEvent event
;
2090 event
.SetEventObject(this);
2091 event
.SetId(GetId());
2092 GetEventHandler()->ProcessEvent(event
);
2095 // ----------------------------------------------------------------------------
2097 // ----------------------------------------------------------------------------
2099 #if wxUSE_VALIDATORS
2101 bool wxWindowBase::TryValidator(wxEvent
& event
)
2103 // Can only use the validator of the window which
2104 // is receiving the event
2105 if ( event
.GetEventObject() == this )
2107 wxValidator
*validator
= GetValidator();
2108 if ( validator
&& validator
->ProcessEvent(event
) )
2117 #endif // wxUSE_VALIDATORS
2119 bool wxWindowBase::TryParent(wxEvent
& event
)
2121 // Carry on up the parent-child hierarchy, but only if event is a command
2122 // event: it wouldn't make sense for a parent to receive a child's size
2123 // event, for example
2124 if ( event
.IsCommandEvent() )
2126 // honour the requests to stop propagation at this window: this is
2127 // used by the dialogs, for example, to prevent processing the events
2128 // from the dialog controls in the parent frame which rarely, if ever,
2130 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2132 wxWindow
*parent
= GetParent();
2133 if ( parent
&& !parent
->IsBeingDeleted() )
2134 return parent
->GetEventHandler()->ProcessEvent(event
);
2138 return wxEvtHandler::TryParent(event
);
2141 // ----------------------------------------------------------------------------
2143 // ----------------------------------------------------------------------------
2145 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2147 while ( win
&& !win
->IsTopLevel() )
2148 win
= win
->GetParent();
2153 #if wxUSE_ACCESSIBILITY
2154 // ----------------------------------------------------------------------------
2155 // accessible object for windows
2156 // ----------------------------------------------------------------------------
2158 // Can return either a child object, or an integer
2159 // representing the child element, starting from 1.
2160 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& pt
, int* childId
, wxAccessible
** childObject
)
2162 wxASSERT( GetWindow() != NULL
);
2166 return wxACC_NOT_IMPLEMENTED
;
2169 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2170 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2172 wxASSERT( GetWindow() != NULL
);
2176 wxWindow
* win
= NULL
;
2183 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2185 win
= (wxWindow
*) GetWindow()->GetChildren().Nth(elementId
-1)->GetData();
2192 rect
= win
->GetRect();
2193 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2194 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2198 return wxACC_NOT_IMPLEMENTED
;
2201 // Navigates from fromId to toId/toObject.
2202 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2203 int* toId
, wxAccessible
** toObject
)
2205 wxASSERT( GetWindow() != NULL
);
2211 case wxNAVDIR_FIRSTCHILD
:
2213 if (GetWindow()->GetChildren().GetCount() == 0)
2215 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2216 *toObject
= childWindow
->GetOrCreateAccessible();
2220 case wxNAVDIR_LASTCHILD
:
2222 if (GetWindow()->GetChildren().GetCount() == 0)
2224 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2225 *toObject
= childWindow
->GetOrCreateAccessible();
2229 case wxNAVDIR_RIGHT
:
2233 wxWindowList::Node
*node
= NULL
;
2236 // Can't navigate to sibling of this window
2237 // if we're a top-level window.
2238 if (!GetWindow()->GetParent())
2239 return wxACC_NOT_IMPLEMENTED
;
2241 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2245 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2246 node
= (wxWindowList::Node
*) GetWindow()->GetChildren().Nth(fromId
-1);
2249 if (node
&& node
->GetNext())
2251 wxWindow
* nextWindow
= (wxWindow
*) node
->GetNext()->Data();
2252 *toObject
= nextWindow
->GetOrCreateAccessible();
2260 case wxNAVDIR_PREVIOUS
:
2262 wxWindowList::Node
*node
= NULL
;
2265 // Can't navigate to sibling of this window
2266 // if we're a top-level window.
2267 if (!GetWindow()->GetParent())
2268 return wxACC_NOT_IMPLEMENTED
;
2270 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2274 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2275 node
= (wxWindowList::Node
*) GetWindow()->GetChildren().Nth(fromId
-1);
2278 if (node
&& node
->GetPrevious())
2280 wxWindow
* previousWindow
= (wxWindow
*) node
->GetPrevious()->Data();
2281 *toObject
= previousWindow
->GetOrCreateAccessible();
2289 return wxACC_NOT_IMPLEMENTED
;
2292 // Gets the name of the specified object.
2293 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2295 wxASSERT( GetWindow() != NULL
);
2301 // If a child, leave wxWindows to call the function on the actual
2304 return wxACC_NOT_IMPLEMENTED
;
2306 // This will eventually be replaced by specialised
2307 // accessible classes, one for each kind of wxWindows
2308 // control or window.
2309 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2310 title
= ((wxButton
*) GetWindow())->GetLabel();
2312 title
= GetWindow()->GetName();
2314 if (!title
.IsEmpty())
2320 return wxACC_NOT_IMPLEMENTED
;
2323 // Gets the number of children.
2324 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2326 wxASSERT( GetWindow() != NULL
);
2330 *childId
= (int) GetWindow()->GetChildren().GetCount();
2334 // Gets the specified child (starting from 1).
2335 // If *child is NULL and return value is wxACC_OK,
2336 // this means that the child is a simple element and
2337 // not an accessible object.
2338 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2340 wxASSERT( GetWindow() != NULL
);
2350 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2353 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().Nth(childId
-1)->GetData();
2354 *child
= childWindow
->GetOrCreateAccessible();
2361 // Gets the parent, or NULL.
2362 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2364 wxASSERT( GetWindow() != NULL
);
2368 wxWindow
* parentWindow
= GetWindow()->GetParent();
2376 *parent
= parentWindow
->GetOrCreateAccessible();
2384 // Performs the default action. childId is 0 (the action for this object)
2385 // or > 0 (the action for a child).
2386 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2387 // window (e.g. an edit control).
2388 wxAccStatus
wxWindowAccessible::DoDefaultAction(int childId
)
2390 wxASSERT( GetWindow() != NULL
);
2394 return wxACC_NOT_IMPLEMENTED
;
2397 // Gets the default action for this object (0) or > 0 (the action for a child).
2398 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2399 // string if there is no action.
2400 // The retrieved string describes the action that is performed on an object,
2401 // not what the object does as a result. For example, a toolbar button that prints
2402 // a document has a default action of "Press" rather than "Prints the current document."
2403 wxAccStatus
wxWindowAccessible::GetDefaultAction(int childId
, wxString
* actionName
)
2405 wxASSERT( GetWindow() != NULL
);
2409 return wxACC_NOT_IMPLEMENTED
;
2412 // Returns the description for this object or a child.
2413 wxAccStatus
wxWindowAccessible::GetDescription(int childId
, wxString
* description
)
2415 wxASSERT( GetWindow() != NULL
);
2419 wxString
ht(GetWindow()->GetHelpText());
2425 return wxACC_NOT_IMPLEMENTED
;
2428 // Returns help text for this object or a child, similar to tooltip text.
2429 wxAccStatus
wxWindowAccessible::GetHelpText(int childId
, wxString
* helpText
)
2431 wxASSERT( GetWindow() != NULL
);
2435 wxString
ht(GetWindow()->GetHelpText());
2441 return wxACC_NOT_IMPLEMENTED
;
2444 // Returns the keyboard shortcut for this object or child.
2445 // Return e.g. ALT+K
2446 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int childId
, wxString
* shortcut
)
2448 wxASSERT( GetWindow() != NULL
);
2452 return wxACC_NOT_IMPLEMENTED
;
2455 // Returns a role constant.
2456 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
2458 wxASSERT( GetWindow() != NULL
);
2462 // If a child, leave wxWindows to call the function on the actual
2465 return wxACC_NOT_IMPLEMENTED
;
2467 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2468 return wxACC_NOT_IMPLEMENTED
;
2470 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2471 return wxACC_NOT_IMPLEMENTED
;
2474 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2475 return wxACC_NOT_IMPLEMENTED
;
2478 //*role = wxROLE_SYSTEM_CLIENT;
2479 *role
= wxROLE_SYSTEM_CLIENT
;
2482 return wxACC_NOT_IMPLEMENTED
;
2485 // Returns a state constant.
2486 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
2488 wxASSERT( GetWindow() != NULL
);
2492 // If a child, leave wxWindows to call the function on the actual
2495 return wxACC_NOT_IMPLEMENTED
;
2497 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2498 return wxACC_NOT_IMPLEMENTED
;
2501 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2502 return wxACC_NOT_IMPLEMENTED
;
2505 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2506 return wxACC_NOT_IMPLEMENTED
;
2512 return wxACC_NOT_IMPLEMENTED
;
2515 // Returns a localized string representing the value for the object
2517 wxAccStatus
wxWindowAccessible::GetValue(int childId
, wxString
* strValue
)
2519 wxASSERT( GetWindow() != NULL
);
2523 return wxACC_NOT_IMPLEMENTED
;
2526 // Selects the object or child.
2527 wxAccStatus
wxWindowAccessible::Select(int childId
, wxAccSelectionFlags selectFlags
)
2529 wxASSERT( GetWindow() != NULL
);
2533 return wxACC_NOT_IMPLEMENTED
;
2536 // Gets the window with the keyboard focus.
2537 // If childId is 0 and child is NULL, no object in
2538 // this subhierarchy has the focus.
2539 // If this object has the focus, child should be 'this'.
2540 wxAccStatus
wxWindowAccessible::GetFocus(int* childId
, wxAccessible
** child
)
2542 wxASSERT( GetWindow() != NULL
);
2546 return wxACC_NOT_IMPLEMENTED
;
2549 // Gets a variant representing the selected children
2551 // Acceptable values:
2552 // - a null variant (IsNull() returns TRUE)
2553 // - a list variant (GetType() == wxT("list")
2554 // - an integer representing the selected child element,
2555 // or 0 if this object is selected (GetType() == wxT("long")
2556 // - a "void*" pointer to a wxAccessible child object
2557 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* selections
)
2559 wxASSERT( GetWindow() != NULL
);
2563 return wxACC_NOT_IMPLEMENTED
;
2566 #endif // wxUSE_ACCESSIBILITY