1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/window.cpp
3 // Purpose: common (to all ports) wxWindow functions
4 // Author: Julian Smart, Vadim Zeitlin
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
28 #include "wx/string.h"
33 #include "wx/window.h"
34 #include "wx/control.h"
35 #include "wx/checkbox.h"
36 #include "wx/radiobut.h"
37 #include "wx/statbox.h"
38 #include "wx/textctrl.h"
39 #include "wx/settings.h"
40 #include "wx/dialog.h"
41 #include "wx/msgdlg.h"
42 #include "wx/statusbr.h"
43 #include "wx/toolbar.h"
44 #include "wx/dcclient.h"
47 #if defined(__WXMAC__) && wxUSE_SCROLLBAR
48 #include "wx/scrolbar.h"
52 #include "wx/layout.h"
53 #endif // wxUSE_CONSTRAINTS
57 #if wxUSE_DRAG_AND_DROP
59 #endif // wxUSE_DRAG_AND_DROP
61 #if wxUSE_ACCESSIBILITY
62 #include "wx/access.h"
66 #include "wx/cshelp.h"
70 #include "wx/tooltip.h"
71 #endif // wxUSE_TOOLTIPS
78 #include "wx/display.h"
81 #if wxUSE_SYSTEM_OPTIONS
82 #include "wx/sysopt.h"
85 // For reporting compile- and runtime version of GTK+ in the ctrl+alt+mclick dialog.
86 // The gtk includes don't pull any other headers in, at least not on my system - MR
89 #include <gtk/gtkversion.h>
91 #include <gtk/gtkfeatures.h>
93 extern const unsigned int gtk_major_version
;
94 extern const unsigned int gtk_minor_version
;
95 extern const unsigned int gtk_micro_version
;
98 // ----------------------------------------------------------------------------
100 // ----------------------------------------------------------------------------
102 #if defined(__WXPALMOS__)
103 int wxWindowBase::ms_lastControlId
= 32767;
104 #elif defined(__WXPM__)
105 int wxWindowBase::ms_lastControlId
= 2000;
107 int wxWindowBase::ms_lastControlId
= -200;
110 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
112 // ----------------------------------------------------------------------------
114 // ----------------------------------------------------------------------------
116 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
117 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
118 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
119 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick
)
122 EVT_HELP(wxID_ANY
, wxWindowBase::OnHelp
)
127 // ============================================================================
128 // implementation of the common functionality of the wxWindow class
129 // ============================================================================
131 // ----------------------------------------------------------------------------
133 // ----------------------------------------------------------------------------
135 // the default initialization
136 wxWindowBase::wxWindowBase()
138 // no window yet, no parent nor children
139 m_parent
= (wxWindow
*)NULL
;
140 m_windowId
= wxID_ANY
;
142 // no constraints on the minimal window size
144 m_maxWidth
= wxDefaultCoord
;
146 m_maxHeight
= wxDefaultCoord
;
148 // invalidiated cache value
149 m_bestSizeCache
= wxDefaultSize
;
151 // window are created enabled and visible by default
155 // the default event handler is just this window
156 m_eventHandler
= this;
160 m_windowValidator
= (wxValidator
*) NULL
;
161 #endif // wxUSE_VALIDATORS
163 // the colours/fonts are default for now, so leave m_font,
164 // m_backgroundColour and m_foregroundColour uninitialized and set those
170 m_inheritFont
= false;
176 m_backgroundStyle
= wxBG_STYLE_SYSTEM
;
178 #if wxUSE_CONSTRAINTS
179 // no constraints whatsoever
180 m_constraints
= (wxLayoutConstraints
*) NULL
;
181 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
182 #endif // wxUSE_CONSTRAINTS
184 m_windowSizer
= (wxSizer
*) NULL
;
185 m_containingSizer
= (wxSizer
*) NULL
;
186 m_autoLayout
= false;
188 #if wxUSE_DRAG_AND_DROP
189 m_dropTarget
= (wxDropTarget
*)NULL
;
190 #endif // wxUSE_DRAG_AND_DROP
193 m_tooltip
= (wxToolTip
*)NULL
;
194 #endif // wxUSE_TOOLTIPS
197 m_caret
= (wxCaret
*)NULL
;
198 #endif // wxUSE_CARET
201 m_hasCustomPalette
= false;
202 #endif // wxUSE_PALETTE
204 #if wxUSE_ACCESSIBILITY
208 m_virtualSize
= wxDefaultSize
;
211 m_maxVirtualWidth
= wxDefaultCoord
;
213 m_maxVirtualHeight
= wxDefaultCoord
;
215 m_windowVariant
= wxWINDOW_VARIANT_NORMAL
;
216 #if wxUSE_SYSTEM_OPTIONS
217 if ( wxSystemOptions::HasOption(wxWINDOW_DEFAULT_VARIANT
) )
219 m_windowVariant
= (wxWindowVariant
) wxSystemOptions::GetOptionInt( wxWINDOW_DEFAULT_VARIANT
) ;
223 // Whether we're using the current theme for this window (wxGTK only for now)
224 m_themeEnabled
= false;
226 // VZ: this one shouldn't exist...
227 m_isBeingDeleted
= false;
229 // Reserved for future use
230 m_windowReserved
= NULL
;
233 // common part of window creation process
234 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
236 const wxPoint
& WXUNUSED(pos
),
237 const wxSize
& WXUNUSED(size
),
239 const wxValidator
& wxVALIDATOR_PARAM(validator
),
240 const wxString
& name
)
243 // wxGTK doesn't allow to create controls with static box as the parent so
244 // this will result in a crash when the program is ported to wxGTK so warn
247 // if you get this assert, the correct solution is to create the controls
248 // as siblings of the static box
249 wxASSERT_MSG( !parent
|| !wxDynamicCast(parent
, wxStaticBox
),
250 _T("wxStaticBox can't be used as a window parent!") );
251 #endif // wxUSE_STATBOX
253 // ids are limited to 16 bits under MSW so if you care about portability,
254 // it's not a good idea to use ids out of this range (and negative ids are
255 // reserved for wxWidgets own usage)
256 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767),
257 _T("invalid id value") );
259 // generate a new id if the user doesn't care about it
260 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
263 SetWindowStyleFlag(style
);
267 SetValidator(validator
);
268 #endif // wxUSE_VALIDATORS
270 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
271 // have it too - like this it's possible to set it only in the top level
272 // dialog/frame and all children will inherit it by defult
273 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
275 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
281 // ----------------------------------------------------------------------------
283 // ----------------------------------------------------------------------------
286 wxWindowBase::~wxWindowBase()
288 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
290 // FIXME if these 2 cases result from programming errors in the user code
291 // we should probably assert here instead of silently fixing them
293 // Just in case the window has been Closed, but we're then deleting
294 // immediately: don't leave dangling pointers.
295 wxPendingDelete
.DeleteObject(this);
297 // Just in case we've loaded a top-level window via LoadNativeDialog but
298 // we weren't a dialog class
299 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
301 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
303 // reset the dangling pointer our parent window may keep to us
306 if ( m_parent
->GetDefaultItem() == this )
308 m_parent
->SetDefaultItem(NULL
);
311 m_parent
->RemoveChild(this);
316 #endif // wxUSE_CARET
319 delete m_windowValidator
;
320 #endif // wxUSE_VALIDATORS
322 #if wxUSE_CONSTRAINTS
323 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
324 // at deleted windows as they delete themselves.
325 DeleteRelatedConstraints();
329 // This removes any dangling pointers to this window in other windows'
330 // constraintsInvolvedIn lists.
331 UnsetConstraints(m_constraints
);
332 delete m_constraints
;
333 m_constraints
= NULL
;
335 #endif // wxUSE_CONSTRAINTS
337 if ( m_containingSizer
)
338 m_containingSizer
->Detach( (wxWindow
*)this );
340 delete m_windowSizer
;
342 #if wxUSE_DRAG_AND_DROP
344 #endif // wxUSE_DRAG_AND_DROP
348 #endif // wxUSE_TOOLTIPS
350 #if wxUSE_ACCESSIBILITY
355 bool wxWindowBase::Destroy()
362 bool wxWindowBase::Close(bool force
)
364 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
365 event
.SetEventObject(this);
366 event
.SetCanVeto(!force
);
368 // return false if window wasn't closed because the application vetoed the
370 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
373 bool wxWindowBase::DestroyChildren()
375 wxWindowList::compatibility_iterator node
;
378 // we iterate until the list becomes empty
379 node
= GetChildren().GetFirst();
383 wxWindow
*child
= node
->GetData();
385 // note that we really want to call delete and not ->Destroy() here
386 // because we want to delete the child immediately, before we are
387 // deleted, and delayed deletion would result in problems as our (top
388 // level) child could outlive its parent
391 wxASSERT_MSG( !GetChildren().Find(child
),
392 wxT("child didn't remove itself using RemoveChild()") );
398 // ----------------------------------------------------------------------------
399 // size/position related methods
400 // ----------------------------------------------------------------------------
402 // centre the window with respect to its parent in either (or both) directions
403 void wxWindowBase::Centre(int direction
)
405 // the position/size of the parent window or of the entire screen
407 int widthParent
, heightParent
;
409 wxWindow
*parent
= NULL
;
410 wxTopLevelWindow
*winTop
= NULL
;
412 if ( !(direction
& wxCENTRE_ON_SCREEN
) )
414 // find the parent to centre this window on: it should be the
415 // immediate parent for the controls but the top level parent for the
416 // top level windows (like dialogs)
417 parent
= GetParent();
420 while ( parent
&& !parent
->IsTopLevel() )
422 parent
= parent
->GetParent();
426 // there is no wxTopLevelWindow under wxMotif yet
428 // we shouldn't center the dialog on the iconized window: under
429 // Windows, for example, this places it completely off the screen
432 winTop
= wxDynamicCast(parent
, wxTopLevelWindow
);
433 if ( winTop
&& winTop
->IsIconized() )
439 #endif // __WXMOTIF__
441 // did we find the parent?
445 direction
|= wxCENTRE_ON_SCREEN
;
449 if ( direction
& wxCENTRE_ON_SCREEN
)
451 //RN: If we are using wxDisplay we get
452 //the dimensions of the monitor the window is on,
453 //otherwise we get the dimensions of the primary monitor
454 //FIXME: wxDisplay::GetFromWindow only implemented on MSW
455 #if wxUSE_DISPLAY && defined(__WXMSW__)
456 int nDisplay
= wxDisplay::GetFromWindow((wxWindow
*)this);
457 if(nDisplay
!= wxNOT_FOUND
)
459 wxDisplay
windowDisplay(nDisplay
);
460 wxRect displayRect
= windowDisplay
.GetGeometry();
461 widthParent
= displayRect
.width
;
462 heightParent
= displayRect
.height
;
466 // centre with respect to the whole screen
467 wxDisplaySize(&widthParent
, &heightParent
);
474 winTop
->GetRectForTopLevelChildren(&posParent
.x
, &posParent
.y
, &widthParent
, &heightParent
);
477 // centre on the parent
478 parent
->GetSize(&widthParent
, &heightParent
);
480 // adjust to the parents position
481 posParent
= parent
->GetPosition();
486 // centre inside the parents client rectangle
487 parent
->GetClientSize(&widthParent
, &heightParent
);
492 GetSize(&width
, &height
);
494 int xNew
= wxDefaultCoord
,
495 yNew
= wxDefaultCoord
;
497 if ( direction
& wxHORIZONTAL
)
498 xNew
= (widthParent
- width
)/2;
500 if ( direction
& wxVERTICAL
)
501 yNew
= (heightParent
- height
)/2;
506 // FIXME: This needs to get the client display rect of the display
507 // the window is (via wxDisplay::GetFromWindow).
509 // Base size of the visible dimensions of the display
510 // to take into account the taskbar. And the Mac menu bar at top.
511 wxRect clientrect
= wxGetClientDisplayRect();
513 // NB: in wxMSW, negative position may not necessarily mean "out of screen",
514 // but it may mean that the window is placed on other than the main
515 // display. Therefore we only make sure centered window is on the main display
516 // if the parent is at least partially present here.
517 if (posParent
.x
+ widthParent
>= 0) // if parent is (partially) on the main display
519 if (xNew
< clientrect
.GetLeft())
520 xNew
= clientrect
.GetLeft();
521 else if (xNew
+ width
> clientrect
.GetRight())
522 xNew
= clientrect
.GetRight() - width
;
524 if (posParent
.y
+ heightParent
>= 0) // if parent is (partially) on the main display
526 if (yNew
+ height
> clientrect
.GetBottom())
527 yNew
= clientrect
.GetBottom() - height
;
529 // Make certain that the title bar is initially visible
530 // always, even if this would push the bottom of the
531 // dialog off the visible area of the display
532 if (yNew
< clientrect
.GetTop())
533 yNew
= clientrect
.GetTop();
536 // move the window to this position (keeping the old size but using
537 // SetSize() and not Move() to allow xNew and/or yNew to be wxDefaultCoord)
538 SetSize(xNew
, yNew
, width
, height
, wxSIZE_ALLOW_MINUS_ONE
);
541 // fits the window around the children
542 void wxWindowBase::Fit()
544 if ( !GetChildren().empty() )
546 SetClientSize(GetBestSize());
548 //else: do nothing if we have no children
551 // fits virtual size (ie. scrolled area etc.) around children
552 void wxWindowBase::FitInside()
554 if ( GetChildren().GetCount() > 0 )
556 SetVirtualSize( GetBestVirtualSize() );
560 // On Mac, scrollbars are explicitly children.
562 static bool wxHasRealChildren(const wxWindowBase
* win
)
564 int realChildCount
= 0;
566 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
568 node
= node
->GetNext() )
570 wxWindow
*win
= node
->GetData();
571 if ( !win
->IsTopLevel() && win
->IsShown() && !win
->IsKindOf(CLASSINFO(wxScrollBar
)))
574 return (realChildCount
> 0);
578 void wxWindowBase::InvalidateBestSize()
580 m_bestSizeCache
= wxDefaultSize
;
582 // parent's best size calculation may depend on its children's
583 // best sizes, so let's invalidate it as well to be safe:
585 m_parent
->InvalidateBestSize();
588 // return the size best suited for the current window
589 wxSize
wxWindowBase::DoGetBestSize() const
595 best
= GetWindowSizeForVirtualSize(m_windowSizer
->GetMinSize());
597 #if wxUSE_CONSTRAINTS
598 else if ( m_constraints
)
600 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
602 // our minimal acceptable size is such that all our windows fit inside
606 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
608 node
= node
->GetNext() )
610 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
613 // it's not normal that we have an unconstrained child, but
614 // what can we do about it?
618 int x
= c
->right
.GetValue(),
619 y
= c
->bottom
.GetValue();
627 // TODO: we must calculate the overlaps somehow, otherwise we
628 // will never return a size bigger than the current one :-(
631 best
= wxSize(maxX
, maxY
);
633 #endif // wxUSE_CONSTRAINTS
634 else if ( !GetChildren().empty()
636 && wxHasRealChildren(this)
640 // our minimal acceptable size is such that all our visible child windows fit inside
644 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
646 node
= node
->GetNext() )
648 wxWindow
*win
= node
->GetData();
649 if ( win
->IsTopLevel() || ( ! win
->IsShown() )
651 || wxDynamicCast(win
, wxStatusBar
)
652 #endif // wxUSE_STATUSBAR
655 // dialogs and frames lie in different top level windows -
656 // don't deal with them here; as for the status bars, they
657 // don't lie in the client area at all
662 win
->GetPosition(&wx
, &wy
);
664 // if the window hadn't been positioned yet, assume that it is in
666 if ( wx
== wxDefaultCoord
)
668 if ( wy
== wxDefaultCoord
)
671 win
->GetSize(&ww
, &wh
);
672 if ( wx
+ ww
> maxX
)
674 if ( wy
+ wh
> maxY
)
678 // for compatibility with the old versions and because it really looks
679 // slightly more pretty like this, add a pad
683 best
= wxSize(maxX
, maxY
);
685 else // ! has children
687 // for a generic window there is no natural best size so, if the
688 // minimal size is not set, use the current size but take care to
689 // remember it as minimal size for the next time because our best size
690 // should be constant: otherwise we could get into a situation when the
691 // window is initially at some size, then expanded to a larger size and
692 // then, when the containing window is shrunk back (because our initial
693 // best size had been used for computing the parent min size), we can't
694 // be shrunk back any more because our best size is now bigger
695 wxSize size
= GetMinSize();
696 if ( !size
.IsFullySpecified() )
698 size
.SetDefaults(GetSize());
699 wxConstCast(this, wxWindowBase
)->SetMinSize(size
);
702 // return as-is, unadjusted by the client size difference.
706 // Add any difference between size and client size
707 wxSize diff
= GetSize() - GetClientSize();
708 best
.x
+= wxMax(0, diff
.x
);
709 best
.y
+= wxMax(0, diff
.y
);
715 wxSize
wxWindowBase::GetBestFittingSize() const
717 // merge the best size with the min size, giving priority to the min size
718 wxSize min
= GetMinSize();
719 if (min
.x
== wxDefaultCoord
|| min
.y
== wxDefaultCoord
)
721 wxSize best
= GetBestSize();
722 if (min
.x
== wxDefaultCoord
) min
.x
= best
.x
;
723 if (min
.y
== wxDefaultCoord
) min
.y
= best
.y
;
729 void wxWindowBase::SetBestFittingSize(const wxSize
& size
)
731 // Set the min size to the size passed in. This will usually either be
732 // wxDefaultSize or the size passed to this window's ctor/Create function.
735 // Merge the size with the best size if needed
736 wxSize best
= GetBestFittingSize();
738 // If the current size doesn't match then change it
739 if (GetSize() != best
)
744 // by default the origin is not shifted
745 wxPoint
wxWindowBase::GetClientAreaOrigin() const
750 // set the min/max size of the window
751 void wxWindowBase::DoSetSizeHints(int minW
, int minH
,
753 int WXUNUSED(incW
), int WXUNUSED(incH
))
755 // setting min width greater than max width leads to infinite loops under
756 // X11 and generally doesn't make any sense, so don't allow it
757 wxCHECK_RET( (minW
== wxDefaultCoord
|| maxW
== wxDefaultCoord
|| minW
<= maxW
) &&
758 (minH
== wxDefaultCoord
|| maxH
== wxDefaultCoord
|| minH
<= maxH
),
759 _T("min width/height must be less than max width/height!") );
767 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
769 if ( m_windowVariant
!= variant
)
771 m_windowVariant
= variant
;
773 DoSetWindowVariant(variant
);
777 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
779 // adjust the font height to correspond to our new variant (notice that
780 // we're only called if something really changed)
781 wxFont font
= GetFont();
782 int size
= font
.GetPointSize();
785 case wxWINDOW_VARIANT_NORMAL
:
788 case wxWINDOW_VARIANT_SMALL
:
793 case wxWINDOW_VARIANT_MINI
:
798 case wxWINDOW_VARIANT_LARGE
:
804 wxFAIL_MSG(_T("unexpected window variant"));
808 font
.SetPointSize(size
);
812 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
815 m_minVirtualWidth
= minW
;
816 m_maxVirtualWidth
= maxW
;
817 m_minVirtualHeight
= minH
;
818 m_maxVirtualHeight
= maxH
;
821 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
823 if ( m_minVirtualWidth
!= wxDefaultCoord
&& m_minVirtualWidth
> x
)
824 x
= m_minVirtualWidth
;
825 if ( m_maxVirtualWidth
!= wxDefaultCoord
&& m_maxVirtualWidth
< x
)
826 x
= m_maxVirtualWidth
;
827 if ( m_minVirtualHeight
!= wxDefaultCoord
&& m_minVirtualHeight
> y
)
828 y
= m_minVirtualHeight
;
829 if ( m_maxVirtualHeight
!= wxDefaultCoord
&& m_maxVirtualHeight
< y
)
830 y
= m_maxVirtualHeight
;
832 m_virtualSize
= wxSize(x
, y
);
835 wxSize
wxWindowBase::DoGetVirtualSize() const
837 if ( m_virtualSize
.IsFullySpecified() )
838 return m_virtualSize
;
840 wxSize size
= GetClientSize();
841 if ( m_virtualSize
.x
!= wxDefaultCoord
)
842 size
.x
= m_virtualSize
.x
;
844 if ( m_virtualSize
.y
!= wxDefaultCoord
)
845 size
.y
= m_virtualSize
.y
;
850 // ----------------------------------------------------------------------------
851 // show/hide/enable/disable the window
852 // ----------------------------------------------------------------------------
854 bool wxWindowBase::Show(bool show
)
856 if ( show
!= m_isShown
)
868 bool wxWindowBase::Enable(bool enable
)
870 if ( enable
!= m_isEnabled
)
872 m_isEnabled
= enable
;
881 // ----------------------------------------------------------------------------
883 // ----------------------------------------------------------------------------
885 bool wxWindowBase::IsTopLevel() const
890 // ----------------------------------------------------------------------------
891 // reparenting the window
892 // ----------------------------------------------------------------------------
894 void wxWindowBase::AddChild(wxWindowBase
*child
)
896 wxCHECK_RET( child
, wxT("can't add a NULL child") );
898 // this should never happen and it will lead to a crash later if it does
899 // because RemoveChild() will remove only one node from the children list
900 // and the other(s) one(s) will be left with dangling pointers in them
901 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
903 GetChildren().Append((wxWindow
*)child
);
904 child
->SetParent(this);
907 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
909 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
911 GetChildren().DeleteObject((wxWindow
*)child
);
912 child
->SetParent(NULL
);
915 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
917 wxWindow
*oldParent
= GetParent();
918 if ( newParent
== oldParent
)
924 // unlink this window from the existing parent.
927 oldParent
->RemoveChild(this);
931 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
934 // add it to the new one
937 newParent
->AddChild(this);
941 wxTopLevelWindows
.Append((wxWindow
*)this);
947 // ----------------------------------------------------------------------------
948 // event handler stuff
949 // ----------------------------------------------------------------------------
951 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
953 wxEvtHandler
*handlerOld
= GetEventHandler();
955 handler
->SetNextHandler(handlerOld
);
958 GetEventHandler()->SetPreviousHandler(handler
);
960 SetEventHandler(handler
);
963 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
965 wxEvtHandler
*handlerA
= GetEventHandler();
968 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
969 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
972 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
973 SetEventHandler(handlerB
);
978 handlerA
= (wxEvtHandler
*)NULL
;
985 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
987 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
989 wxEvtHandler
*handlerPrev
= NULL
,
990 *handlerCur
= GetEventHandler();
993 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
995 if ( handlerCur
== handler
)
999 handlerPrev
->SetNextHandler(handlerNext
);
1003 SetEventHandler(handlerNext
);
1008 handlerNext
->SetPreviousHandler ( handlerPrev
);
1011 handler
->SetNextHandler(NULL
);
1012 handler
->SetPreviousHandler(NULL
);
1017 handlerPrev
= handlerCur
;
1018 handlerCur
= handlerNext
;
1021 wxFAIL_MSG( _T("where has the event handler gone?") );
1026 // ----------------------------------------------------------------------------
1027 // colours, fonts &c
1028 // ----------------------------------------------------------------------------
1030 void wxWindowBase::InheritAttributes()
1032 const wxWindowBase
* const parent
= GetParent();
1036 // we only inherit attributes which had been explicitly set for the parent
1037 // which ensures that this only happens if the user really wants it and
1038 // not by default which wouldn't make any sense in modern GUIs where the
1039 // controls don't all use the same fonts (nor colours)
1040 if ( parent
->m_inheritFont
&& !m_hasFont
)
1041 SetFont(parent
->GetFont());
1043 // in addition, there is a possibility to explicitly forbid inheriting
1044 // colours at each class level by overriding ShouldInheritColours()
1045 if ( ShouldInheritColours() )
1047 if ( parent
->m_inheritFgCol
&& !m_hasFgCol
)
1048 SetForegroundColour(parent
->GetForegroundColour());
1050 // inheriting (solid) background colour is wrong as it totally breaks
1051 // any kind of themed backgrounds
1053 // instead, the controls should use the same background as their parent
1054 // (ideally by not drawing it at all)
1056 if ( parent
->m_inheritBgCol
&& !m_hasBgCol
)
1057 SetBackgroundColour(parent
->GetBackgroundColour());
1062 /* static */ wxVisualAttributes
1063 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
1065 // it is important to return valid values for all attributes from here,
1066 // GetXXX() below rely on this
1067 wxVisualAttributes attrs
;
1068 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
1069 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1071 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
1072 // the usual background colour than wxSYS_COLOUR_BTNFACE.
1073 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
1074 // colour on other platforms.
1076 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
1077 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1079 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
1084 wxColour
wxWindowBase::GetBackgroundColour() const
1086 if ( !m_backgroundColour
.Ok() )
1088 wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") );
1090 // get our default background colour
1091 wxColour colBg
= GetDefaultAttributes().colBg
;
1093 // we must return some valid colour to avoid redoing this every time
1094 // and also to avoid surprizing the applications written for older
1095 // wxWidgets versions where GetBackgroundColour() always returned
1096 // something -- so give them something even if it doesn't make sense
1097 // for this window (e.g. it has a themed background)
1099 colBg
= GetClassDefaultAttributes().colBg
;
1104 return m_backgroundColour
;
1107 wxColour
wxWindowBase::GetForegroundColour() const
1109 // logic is the same as above
1110 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
1112 wxASSERT_MSG( !m_hasFgCol
, _T("we have invalid explicit fg colour?") );
1114 wxColour colFg
= GetDefaultAttributes().colFg
;
1117 colFg
= GetClassDefaultAttributes().colFg
;
1122 return m_foregroundColour
;
1125 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
1127 if ( colour
== m_backgroundColour
)
1130 m_hasBgCol
= colour
.Ok();
1131 if ( m_backgroundStyle
!= wxBG_STYLE_CUSTOM
)
1132 m_backgroundStyle
= m_hasBgCol
? wxBG_STYLE_COLOUR
: wxBG_STYLE_SYSTEM
;
1134 m_inheritBgCol
= m_hasBgCol
;
1135 m_backgroundColour
= colour
;
1136 SetThemeEnabled( !m_hasBgCol
&& !m_foregroundColour
.Ok() );
1140 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
1142 if (colour
== m_foregroundColour
)
1145 m_hasFgCol
= colour
.Ok();
1146 m_inheritFgCol
= m_hasFgCol
;
1147 m_foregroundColour
= colour
;
1148 SetThemeEnabled( !m_hasFgCol
&& !m_backgroundColour
.Ok() );
1152 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
1154 // setting an invalid cursor is ok, it means that we don't have any special
1156 if ( m_cursor
== cursor
)
1167 wxFont
wxWindowBase::GetFont() const
1169 // logic is the same as in GetBackgroundColour()
1172 wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") );
1174 wxFont font
= GetDefaultAttributes().font
;
1176 font
= GetClassDefaultAttributes().font
;
1184 bool wxWindowBase::SetFont(const wxFont
& font
)
1186 if ( font
== m_font
)
1193 m_hasFont
= font
.Ok();
1194 m_inheritFont
= m_hasFont
;
1196 InvalidateBestSize();
1203 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1205 m_hasCustomPalette
= true;
1208 // VZ: can anyone explain me what do we do here?
1209 wxWindowDC
d((wxWindow
*) this);
1213 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1215 wxWindow
*win
= (wxWindow
*)this;
1216 while ( win
&& !win
->HasCustomPalette() )
1218 win
= win
->GetParent();
1224 #endif // wxUSE_PALETTE
1227 void wxWindowBase::SetCaret(wxCaret
*caret
)
1238 wxASSERT_MSG( m_caret
->GetWindow() == this,
1239 wxT("caret should be created associated to this window") );
1242 #endif // wxUSE_CARET
1244 #if wxUSE_VALIDATORS
1245 // ----------------------------------------------------------------------------
1247 // ----------------------------------------------------------------------------
1249 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1251 if ( m_windowValidator
)
1252 delete m_windowValidator
;
1254 m_windowValidator
= (wxValidator
*)validator
.Clone();
1256 if ( m_windowValidator
)
1257 m_windowValidator
->SetWindow(this);
1259 #endif // wxUSE_VALIDATORS
1261 // ----------------------------------------------------------------------------
1262 // update region stuff
1263 // ----------------------------------------------------------------------------
1265 wxRect
wxWindowBase::GetUpdateClientRect() const
1267 wxRegion rgnUpdate
= GetUpdateRegion();
1268 rgnUpdate
.Intersect(GetClientRect());
1269 wxRect rectUpdate
= rgnUpdate
.GetBox();
1270 wxPoint ptOrigin
= GetClientAreaOrigin();
1271 rectUpdate
.x
-= ptOrigin
.x
;
1272 rectUpdate
.y
-= ptOrigin
.y
;
1277 bool wxWindowBase::IsExposed(int x
, int y
) const
1279 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1282 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
1284 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1287 void wxWindowBase::ClearBackground()
1289 // wxGTK uses its own version, no need to add never used code
1291 wxClientDC
dc((wxWindow
*)this);
1292 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1293 dc
.SetBackground(brush
);
1298 // ----------------------------------------------------------------------------
1299 // find child window by id or name
1300 // ----------------------------------------------------------------------------
1302 wxWindow
*wxWindowBase::FindWindow(long id
) const
1304 if ( id
== m_windowId
)
1305 return (wxWindow
*)this;
1307 wxWindowBase
*res
= (wxWindow
*)NULL
;
1308 wxWindowList::compatibility_iterator node
;
1309 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1311 wxWindowBase
*child
= node
->GetData();
1312 res
= child
->FindWindow( id
);
1315 return (wxWindow
*)res
;
1318 wxWindow
*wxWindowBase::FindWindow(const wxString
& name
) const
1320 if ( name
== m_windowName
)
1321 return (wxWindow
*)this;
1323 wxWindowBase
*res
= (wxWindow
*)NULL
;
1324 wxWindowList::compatibility_iterator node
;
1325 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1327 wxWindow
*child
= node
->GetData();
1328 res
= child
->FindWindow(name
);
1331 return (wxWindow
*)res
;
1335 // find any window by id or name or label: If parent is non-NULL, look through
1336 // children for a label or title matching the specified string. If NULL, look
1337 // through all top-level windows.
1339 // to avoid duplicating code we reuse the same helper function but with
1340 // different comparators
1342 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1343 const wxString
& label
, long id
);
1346 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1349 return win
->GetLabel() == label
;
1353 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1356 return win
->GetName() == label
;
1360 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1363 return win
->GetId() == id
;
1366 // recursive helper for the FindWindowByXXX() functions
1368 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1369 const wxString
& label
,
1371 wxFindWindowCmp cmp
)
1375 // see if this is the one we're looking for
1376 if ( (*cmp
)(parent
, label
, id
) )
1377 return (wxWindow
*)parent
;
1379 // It wasn't, so check all its children
1380 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1382 node
= node
->GetNext() )
1384 // recursively check each child
1385 wxWindow
*win
= (wxWindow
*)node
->GetData();
1386 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1396 // helper for FindWindowByXXX()
1398 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1399 const wxString
& label
,
1401 wxFindWindowCmp cmp
)
1405 // just check parent and all its children
1406 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1409 // start at very top of wx's windows
1410 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1412 node
= node
->GetNext() )
1414 // recursively check each window & its children
1415 wxWindow
*win
= node
->GetData();
1416 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1426 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1428 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1433 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1435 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1439 // fall back to the label
1440 win
= FindWindowByLabel(title
, parent
);
1448 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1450 return wxFindWindowHelper(parent
, wxEmptyString
, id
, wxFindWindowCmpIds
);
1453 // ----------------------------------------------------------------------------
1454 // dialog oriented functions
1455 // ----------------------------------------------------------------------------
1457 void wxWindowBase::MakeModal(bool modal
)
1459 // Disable all other windows
1462 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1465 wxWindow
*win
= node
->GetData();
1467 win
->Enable(!modal
);
1469 node
= node
->GetNext();
1474 bool wxWindowBase::Validate()
1476 #if wxUSE_VALIDATORS
1477 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1479 wxWindowList::compatibility_iterator node
;
1480 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1482 wxWindowBase
*child
= node
->GetData();
1483 wxValidator
*validator
= child
->GetValidator();
1484 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1489 if ( recurse
&& !child
->Validate() )
1494 #endif // wxUSE_VALIDATORS
1499 bool wxWindowBase::TransferDataToWindow()
1501 #if wxUSE_VALIDATORS
1502 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1504 wxWindowList::compatibility_iterator node
;
1505 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1507 wxWindowBase
*child
= node
->GetData();
1508 wxValidator
*validator
= child
->GetValidator();
1509 if ( validator
&& !validator
->TransferToWindow() )
1511 wxLogWarning(_("Could not transfer data to window"));
1513 wxLog::FlushActive();
1521 if ( !child
->TransferDataToWindow() )
1523 // warning already given
1528 #endif // wxUSE_VALIDATORS
1533 bool wxWindowBase::TransferDataFromWindow()
1535 #if wxUSE_VALIDATORS
1536 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1538 wxWindowList::compatibility_iterator node
;
1539 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1541 wxWindow
*child
= node
->GetData();
1542 wxValidator
*validator
= child
->GetValidator();
1543 if ( validator
&& !validator
->TransferFromWindow() )
1545 // nop warning here because the application is supposed to give
1546 // one itself - we don't know here what might have gone wrongly
1553 if ( !child
->TransferDataFromWindow() )
1555 // warning already given
1560 #endif // wxUSE_VALIDATORS
1565 void wxWindowBase::InitDialog()
1567 wxInitDialogEvent
event(GetId());
1568 event
.SetEventObject( this );
1569 GetEventHandler()->ProcessEvent(event
);
1572 // ----------------------------------------------------------------------------
1573 // context-sensitive help support
1574 // ----------------------------------------------------------------------------
1578 // associate this help text with this window
1579 void wxWindowBase::SetHelpText(const wxString
& text
)
1581 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1584 helpProvider
->AddHelp(this, text
);
1588 // associate this help text with all windows with the same id as this
1590 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1592 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1595 helpProvider
->AddHelp(GetId(), text
);
1599 // get the help string associated with this window (may be empty)
1600 wxString
wxWindowBase::GetHelpText() const
1603 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1606 text
= helpProvider
->GetHelp(this);
1612 // show help for this window
1613 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1615 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1618 if ( helpProvider
->ShowHelp(this) )
1620 // skip the event.Skip() below
1628 #endif // wxUSE_HELP
1630 // ----------------------------------------------------------------------------
1631 // tooltipsroot.Replace("\\", "/");
1632 // ----------------------------------------------------------------------------
1636 void wxWindowBase::SetToolTip( const wxString
&tip
)
1638 // don't create the new tooltip if we already have one
1641 m_tooltip
->SetTip( tip
);
1645 SetToolTip( new wxToolTip( tip
) );
1648 // setting empty tooltip text does not remove the tooltip any more - use
1649 // SetToolTip((wxToolTip *)NULL) for this
1652 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1657 m_tooltip
= tooltip
;
1660 #endif // wxUSE_TOOLTIPS
1662 // ----------------------------------------------------------------------------
1663 // constraints and sizers
1664 // ----------------------------------------------------------------------------
1666 #if wxUSE_CONSTRAINTS
1668 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1670 if ( m_constraints
)
1672 UnsetConstraints(m_constraints
);
1673 delete m_constraints
;
1675 m_constraints
= constraints
;
1676 if ( m_constraints
)
1678 // Make sure other windows know they're part of a 'meaningful relationship'
1679 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1680 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1681 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1682 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1683 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1684 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1685 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1686 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1687 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1688 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1689 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1690 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1691 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1692 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1693 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1694 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1698 // This removes any dangling pointers to this window in other windows'
1699 // constraintsInvolvedIn lists.
1700 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1704 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1705 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1706 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1707 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1708 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1709 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1710 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1711 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1712 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1713 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1714 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1715 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1716 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1717 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1718 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1719 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1723 // Back-pointer to other windows we're involved with, so if we delete this
1724 // window, we must delete any constraints we're involved with.
1725 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1727 if ( !m_constraintsInvolvedIn
)
1728 m_constraintsInvolvedIn
= new wxWindowList
;
1729 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1730 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1733 // REMOVE back-pointer to other windows we're involved with.
1734 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1736 if ( m_constraintsInvolvedIn
)
1737 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1740 // Reset any constraints that mention this window
1741 void wxWindowBase::DeleteRelatedConstraints()
1743 if ( m_constraintsInvolvedIn
)
1745 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1748 wxWindow
*win
= node
->GetData();
1749 wxLayoutConstraints
*constr
= win
->GetConstraints();
1751 // Reset any constraints involving this window
1754 constr
->left
.ResetIfWin(this);
1755 constr
->top
.ResetIfWin(this);
1756 constr
->right
.ResetIfWin(this);
1757 constr
->bottom
.ResetIfWin(this);
1758 constr
->width
.ResetIfWin(this);
1759 constr
->height
.ResetIfWin(this);
1760 constr
->centreX
.ResetIfWin(this);
1761 constr
->centreY
.ResetIfWin(this);
1764 wxWindowList::compatibility_iterator next
= node
->GetNext();
1765 m_constraintsInvolvedIn
->Erase(node
);
1769 delete m_constraintsInvolvedIn
;
1770 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1774 #endif // wxUSE_CONSTRAINTS
1776 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1778 if ( sizer
== m_windowSizer
)
1782 delete m_windowSizer
;
1784 m_windowSizer
= sizer
;
1786 SetAutoLayout( sizer
!= NULL
);
1789 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1791 SetSizer( sizer
, deleteOld
);
1792 sizer
->SetSizeHints( (wxWindow
*) this );
1796 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
1798 // adding a window to a sizer twice is going to result in fatal and
1799 // hard to debug problems later because when deleting the second
1800 // associated wxSizerItem we're going to dereference a dangling
1801 // pointer; so try to detect this as early as possible
1802 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
1803 _T("Adding a window to the same sizer twice?") );
1805 m_containingSizer
= sizer
;
1808 #if wxUSE_CONSTRAINTS
1810 void wxWindowBase::SatisfyConstraints()
1812 wxLayoutConstraints
*constr
= GetConstraints();
1813 bool wasOk
= constr
&& constr
->AreSatisfied();
1815 ResetConstraints(); // Mark all constraints as unevaluated
1819 // if we're a top level panel (i.e. our parent is frame/dialog), our
1820 // own constraints will never be satisfied any more unless we do it
1824 while ( noChanges
> 0 )
1826 LayoutPhase1(&noChanges
);
1830 LayoutPhase2(&noChanges
);
1833 #endif // wxUSE_CONSTRAINTS
1835 bool wxWindowBase::Layout()
1837 // If there is a sizer, use it instead of the constraints
1841 GetVirtualSize(&w
, &h
);
1842 GetSizer()->SetDimension( 0, 0, w
, h
);
1844 #if wxUSE_CONSTRAINTS
1847 SatisfyConstraints(); // Find the right constraints values
1848 SetConstraintSizes(); // Recursively set the real window sizes
1855 #if wxUSE_CONSTRAINTS
1857 // first phase of the constraints evaluation: set our own constraints
1858 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1860 wxLayoutConstraints
*constr
= GetConstraints();
1862 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1865 // second phase: set the constraints for our children
1866 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1873 // Layout grand children
1879 // Do a phase of evaluating child constraints
1880 bool wxWindowBase::DoPhase(int phase
)
1882 // the list containing the children for which the constraints are already
1884 wxWindowList succeeded
;
1886 // the max number of iterations we loop before concluding that we can't set
1888 static const int maxIterations
= 500;
1890 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1894 // loop over all children setting their constraints
1895 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1897 node
= node
->GetNext() )
1899 wxWindow
*child
= node
->GetData();
1900 if ( child
->IsTopLevel() )
1902 // top level children are not inside our client area
1906 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1908 // this one is either already ok or nothing we can do about it
1912 int tempNoChanges
= 0;
1913 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1914 : child
->LayoutPhase2(&tempNoChanges
);
1915 noChanges
+= tempNoChanges
;
1919 succeeded
.Append(child
);
1925 // constraints are set
1933 void wxWindowBase::ResetConstraints()
1935 wxLayoutConstraints
*constr
= GetConstraints();
1938 constr
->left
.SetDone(false);
1939 constr
->top
.SetDone(false);
1940 constr
->right
.SetDone(false);
1941 constr
->bottom
.SetDone(false);
1942 constr
->width
.SetDone(false);
1943 constr
->height
.SetDone(false);
1944 constr
->centreX
.SetDone(false);
1945 constr
->centreY
.SetDone(false);
1948 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1951 wxWindow
*win
= node
->GetData();
1952 if ( !win
->IsTopLevel() )
1953 win
->ResetConstraints();
1954 node
= node
->GetNext();
1958 // Need to distinguish between setting the 'fake' size for windows and sizers,
1959 // and setting the real values.
1960 void wxWindowBase::SetConstraintSizes(bool recurse
)
1962 wxLayoutConstraints
*constr
= GetConstraints();
1963 if ( constr
&& constr
->AreSatisfied() )
1965 int x
= constr
->left
.GetValue();
1966 int y
= constr
->top
.GetValue();
1967 int w
= constr
->width
.GetValue();
1968 int h
= constr
->height
.GetValue();
1970 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1971 (constr
->height
.GetRelationship() != wxAsIs
) )
1973 SetSize(x
, y
, w
, h
);
1977 // If we don't want to resize this window, just move it...
1983 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1984 GetClassInfo()->GetClassName(),
1990 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1993 wxWindow
*win
= node
->GetData();
1994 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1995 win
->SetConstraintSizes();
1996 node
= node
->GetNext();
2001 // Only set the size/position of the constraint (if any)
2002 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
2004 wxLayoutConstraints
*constr
= GetConstraints();
2007 if ( x
!= wxDefaultCoord
)
2009 constr
->left
.SetValue(x
);
2010 constr
->left
.SetDone(true);
2012 if ( y
!= wxDefaultCoord
)
2014 constr
->top
.SetValue(y
);
2015 constr
->top
.SetDone(true);
2017 if ( w
!= wxDefaultCoord
)
2019 constr
->width
.SetValue(w
);
2020 constr
->width
.SetDone(true);
2022 if ( h
!= wxDefaultCoord
)
2024 constr
->height
.SetValue(h
);
2025 constr
->height
.SetDone(true);
2030 void wxWindowBase::MoveConstraint(int x
, int y
)
2032 wxLayoutConstraints
*constr
= GetConstraints();
2035 if ( x
!= wxDefaultCoord
)
2037 constr
->left
.SetValue(x
);
2038 constr
->left
.SetDone(true);
2040 if ( y
!= wxDefaultCoord
)
2042 constr
->top
.SetValue(y
);
2043 constr
->top
.SetDone(true);
2048 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
2050 wxLayoutConstraints
*constr
= GetConstraints();
2053 *w
= constr
->width
.GetValue();
2054 *h
= constr
->height
.GetValue();
2060 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
2062 wxLayoutConstraints
*constr
= GetConstraints();
2065 *w
= constr
->width
.GetValue();
2066 *h
= constr
->height
.GetValue();
2069 GetClientSize(w
, h
);
2072 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
2074 wxLayoutConstraints
*constr
= GetConstraints();
2077 *x
= constr
->left
.GetValue();
2078 *y
= constr
->top
.GetValue();
2084 #endif // wxUSE_CONSTRAINTS
2086 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
2088 // don't do it for the dialogs/frames - they float independently of their
2090 if ( !IsTopLevel() )
2092 wxWindow
*parent
= GetParent();
2093 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
2095 wxPoint
pt(parent
->GetClientAreaOrigin());
2102 // ----------------------------------------------------------------------------
2103 // do Update UI processing for child controls
2104 // ----------------------------------------------------------------------------
2106 void wxWindowBase::UpdateWindowUI(long flags
)
2108 wxUpdateUIEvent
event(GetId());
2109 event
.SetEventObject(this);
2111 if ( GetEventHandler()->ProcessEvent(event
) )
2113 DoUpdateWindowUI(event
);
2116 if (flags
& wxUPDATE_UI_RECURSE
)
2118 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2121 wxWindow
* child
= (wxWindow
*) node
->GetData();
2122 child
->UpdateWindowUI(flags
);
2123 node
= node
->GetNext();
2128 // do the window-specific processing after processing the update event
2129 // TODO: take specific knowledge out of this function and
2130 // put in each control's base class. Unfortunately we don't
2131 // yet have base implementation files for wxCheckBox and wxRadioButton.
2132 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
2134 if ( event
.GetSetEnabled() )
2135 Enable(event
.GetEnabled());
2138 if ( event
.GetSetText() )
2140 wxControl
*control
= wxDynamicCastThis(wxControl
);
2143 if ( event
.GetText() != control
->GetLabel() )
2144 control
->SetLabel(event
.GetText());
2147 #endif // wxUSE_CONTROLS
2149 if ( event
.GetSetChecked() )
2152 wxCheckBox
*checkbox
= wxDynamicCastThis(wxCheckBox
);
2155 checkbox
->SetValue(event
.GetChecked());
2157 #endif // wxUSE_CHECKBOX
2160 wxRadioButton
*radiobtn
= wxDynamicCastThis(wxRadioButton
);
2163 radiobtn
->SetValue(event
.GetChecked());
2165 #endif // wxUSE_RADIOBTN
2170 // call internal idle recursively
2171 // may be obsolete (wait until OnIdle scheme stabilises)
2172 void wxWindowBase::ProcessInternalIdle()
2176 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2179 wxWindow
*child
= node
->GetData();
2180 child
->ProcessInternalIdle();
2181 node
= node
->GetNext();
2186 // ----------------------------------------------------------------------------
2187 // dialog units translations
2188 // ----------------------------------------------------------------------------
2190 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
2192 int charWidth
= GetCharWidth();
2193 int charHeight
= GetCharHeight();
2194 wxPoint pt2
= wxDefaultPosition
;
2195 if (pt
.x
!= wxDefaultCoord
)
2196 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
2197 if (pt
.y
!= wxDefaultCoord
)
2198 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2203 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
2205 int charWidth
= GetCharWidth();
2206 int charHeight
= GetCharHeight();
2207 wxPoint pt2
= wxDefaultPosition
;
2208 if (pt
.x
!= wxDefaultCoord
)
2209 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
2210 if (pt
.y
!= wxDefaultCoord
)
2211 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2216 // ----------------------------------------------------------------------------
2218 // ----------------------------------------------------------------------------
2220 // propagate the colour change event to the subwindows
2221 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2223 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2226 // Only propagate to non-top-level windows
2227 wxWindow
*win
= node
->GetData();
2228 if ( !win
->IsTopLevel() )
2230 wxSysColourChangedEvent event2
;
2231 event
.SetEventObject(win
);
2232 win
->GetEventHandler()->ProcessEvent(event2
);
2235 node
= node
->GetNext();
2241 // the default action is to populate dialog with data when it's created,
2242 // and nudge the UI into displaying itself correctly in case
2243 // we've turned the wxUpdateUIEvents frequency down low.
2244 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2246 TransferDataToWindow();
2248 // Update the UI at this point
2249 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2252 // process Ctrl-Alt-mclick
2253 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2256 if ( event
.ControlDown() && event
.AltDown() )
2258 // don't translate these strings
2261 #ifdef __WXUNIVERSAL__
2263 #endif // __WXUNIVERSAL__
2265 switch ( wxGetOsVersion() )
2267 case wxMOTIF_X
: port
+= _T("Motif"); break;
2269 case wxMAC_DARWIN
: port
+= _T("Mac"); break;
2270 case wxBEOS
: port
+= _T("BeOS"); break;
2274 case wxGTK_BEOS
: port
+= _T("GTK"); break;
2280 case wxWIN386
: port
+= _T("MS Windows"); break;
2284 case wxMGL_OS2
: port
+= _T("MGL"); break;
2286 case wxOS2_PM
: port
+= _T("OS/2"); break;
2287 case wxPALMOS
: port
+= _T("Palm OS"); break;
2288 case wxWINDOWS_CE
: port
+= _T("Windows CE (generic)"); break;
2289 case wxWINDOWS_POCKETPC
: port
+= _T("Windows CE PocketPC"); break;
2290 case wxWINDOWS_SMARTPHONE
: port
+= _T("Windows CE Smartphone"); break;
2291 default: port
+= _T("unknown"); break;
2294 wxMessageBox(wxString::Format(
2296 " wxWidgets Library (%s port)\nVersion %d.%d.%d%s%s, compiled at %s %s%s\n Copyright (c) 1995-2005 wxWidgets team"
2315 wxString::Format(_T("\nagainst GTK+ %d.%d.%d. Runtime GTK+ version: %d.%d.%d"), GTK_MAJOR_VERSION
, GTK_MINOR_VERSION
, GTK_MICRO_VERSION
, gtk_major_version
, gtk_minor_version
, gtk_micro_version
).c_str()
2320 _T("wxWidgets information"),
2321 wxICON_INFORMATION
| wxOK
,
2325 #endif // wxUSE_MSGDLG
2331 // ----------------------------------------------------------------------------
2333 // ----------------------------------------------------------------------------
2335 #if wxUSE_ACCESSIBILITY
2336 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2338 if (m_accessible
&& (accessible
!= m_accessible
))
2339 delete m_accessible
;
2340 m_accessible
= accessible
;
2342 m_accessible
->SetWindow((wxWindow
*) this);
2345 // Returns the accessible object, creating if necessary.
2346 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2349 m_accessible
= CreateAccessible();
2350 return m_accessible
;
2353 // Override to create a specific accessible object.
2354 wxAccessible
* wxWindowBase::CreateAccessible()
2356 return new wxWindowAccessible((wxWindow
*) this);
2361 // ----------------------------------------------------------------------------
2362 // list classes implementation
2363 // ----------------------------------------------------------------------------
2367 #include "wx/listimpl.cpp"
2368 WX_DEFINE_LIST(wxWindowList
)
2372 void wxWindowListNode::DeleteData()
2374 delete (wxWindow
*)GetData();
2379 // ----------------------------------------------------------------------------
2381 // ----------------------------------------------------------------------------
2383 wxBorder
wxWindowBase::GetBorder(long flags
) const
2385 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2386 if ( border
== wxBORDER_DEFAULT
)
2388 border
= GetDefaultBorder();
2394 wxBorder
wxWindowBase::GetDefaultBorder() const
2396 return wxBORDER_NONE
;
2399 // ----------------------------------------------------------------------------
2401 // ----------------------------------------------------------------------------
2403 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2405 // here we just check if the point is inside the window or not
2407 // check the top and left border first
2408 bool outside
= x
< 0 || y
< 0;
2411 // check the right and bottom borders too
2412 wxSize size
= GetSize();
2413 outside
= x
>= size
.x
|| y
>= size
.y
;
2416 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2419 // ----------------------------------------------------------------------------
2421 // ----------------------------------------------------------------------------
2423 struct WXDLLEXPORT wxWindowNext
2427 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2429 void wxWindowBase::CaptureMouse()
2431 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this);
2433 wxWindow
*winOld
= GetCapture();
2436 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2439 wxWindowNext
*item
= new wxWindowNext
;
2441 item
->next
= ms_winCaptureNext
;
2442 ms_winCaptureNext
= item
;
2444 //else: no mouse capture to save
2449 void wxWindowBase::ReleaseMouse()
2451 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this);
2453 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2457 if ( ms_winCaptureNext
)
2459 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2461 wxWindowNext
*item
= ms_winCaptureNext
;
2462 ms_winCaptureNext
= item
->next
;
2465 //else: stack is empty, no previous capture
2467 wxLogTrace(_T("mousecapture"),
2468 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2475 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2476 int WXUNUSED(modifiers
),
2477 int WXUNUSED(keycode
))
2483 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2489 #endif // wxUSE_HOTKEY
2491 void wxWindowBase::SendDestroyEvent()
2493 wxWindowDestroyEvent event
;
2494 event
.SetEventObject(this);
2495 event
.SetId(GetId());
2496 GetEventHandler()->ProcessEvent(event
);
2499 // ----------------------------------------------------------------------------
2501 // ----------------------------------------------------------------------------
2503 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2505 #if wxUSE_VALIDATORS
2506 // Can only use the validator of the window which
2507 // is receiving the event
2508 if ( event
.GetEventObject() == this )
2510 wxValidator
*validator
= GetValidator();
2511 if ( validator
&& validator
->ProcessEvent(event
) )
2516 #endif // wxUSE_VALIDATORS
2521 bool wxWindowBase::TryParent(wxEvent
& event
)
2523 // carry on up the parent-child hierarchy if the propagation count hasn't
2525 if ( event
.ShouldPropagate() )
2527 // honour the requests to stop propagation at this window: this is
2528 // used by the dialogs, for example, to prevent processing the events
2529 // from the dialog controls in the parent frame which rarely, if ever,
2531 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2533 wxWindow
*parent
= GetParent();
2534 if ( parent
&& !parent
->IsBeingDeleted() )
2536 wxPropagateOnce
propagateOnce(event
);
2538 return parent
->GetEventHandler()->ProcessEvent(event
);
2543 return wxEvtHandler::TryParent(event
);
2546 // ----------------------------------------------------------------------------
2547 // keyboard navigation
2548 // ----------------------------------------------------------------------------
2550 // Navigates in the specified direction.
2551 bool wxWindowBase::Navigate(int flags
)
2553 wxNavigationKeyEvent eventNav
;
2554 eventNav
.SetFlags(flags
);
2555 eventNav
.SetEventObject(this);
2556 if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav
) )
2563 void wxWindowBase::DoMoveInTabOrder(wxWindow
*win
, MoveKind move
)
2565 // check that we're not a top level window
2566 wxCHECK_RET( GetParent(),
2567 _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
2569 // detect the special case when we have nothing to do anyhow and when the
2570 // code below wouldn't work
2574 // find the target window in the siblings list
2575 wxWindowList
& siblings
= GetParent()->GetChildren();
2576 wxWindowList::compatibility_iterator i
= siblings
.Find(win
);
2577 wxCHECK_RET( i
, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") );
2579 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
2580 // can't just move the node around
2581 wxWindow
*self
= (wxWindow
*)this;
2582 siblings
.DeleteObject(self
);
2583 if ( move
== MoveAfter
)
2590 siblings
.Insert(i
, self
);
2592 else // MoveAfter and win was the last sibling
2594 siblings
.Append(self
);
2598 // ----------------------------------------------------------------------------
2600 // ----------------------------------------------------------------------------
2602 /*static*/ wxWindow
* wxWindowBase::FindFocus()
2604 wxWindowBase
*win
= DoFindFocus();
2605 return win
? win
->GetMainWindowOfCompositeControl() : NULL
;
2608 // ----------------------------------------------------------------------------
2610 // ----------------------------------------------------------------------------
2612 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2614 while ( win
&& !win
->IsTopLevel() )
2615 win
= win
->GetParent();
2620 #if wxUSE_ACCESSIBILITY
2621 // ----------------------------------------------------------------------------
2622 // accessible object for windows
2623 // ----------------------------------------------------------------------------
2625 // Can return either a child object, or an integer
2626 // representing the child element, starting from 1.
2627 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2629 wxASSERT( GetWindow() != NULL
);
2633 return wxACC_NOT_IMPLEMENTED
;
2636 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2637 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2639 wxASSERT( GetWindow() != NULL
);
2643 wxWindow
* win
= NULL
;
2650 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2652 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2659 rect
= win
->GetRect();
2660 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2661 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2665 return wxACC_NOT_IMPLEMENTED
;
2668 // Navigates from fromId to toId/toObject.
2669 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2670 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2672 wxASSERT( GetWindow() != NULL
);
2678 case wxNAVDIR_FIRSTCHILD
:
2680 if (GetWindow()->GetChildren().GetCount() == 0)
2682 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2683 *toObject
= childWindow
->GetOrCreateAccessible();
2687 case wxNAVDIR_LASTCHILD
:
2689 if (GetWindow()->GetChildren().GetCount() == 0)
2691 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2692 *toObject
= childWindow
->GetOrCreateAccessible();
2696 case wxNAVDIR_RIGHT
:
2700 wxWindowList::compatibility_iterator node
=
2701 wxWindowList::compatibility_iterator();
2704 // Can't navigate to sibling of this window
2705 // if we're a top-level window.
2706 if (!GetWindow()->GetParent())
2707 return wxACC_NOT_IMPLEMENTED
;
2709 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2713 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2714 node
= GetWindow()->GetChildren().Item(fromId
-1);
2717 if (node
&& node
->GetNext())
2719 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2720 *toObject
= nextWindow
->GetOrCreateAccessible();
2728 case wxNAVDIR_PREVIOUS
:
2730 wxWindowList::compatibility_iterator node
=
2731 wxWindowList::compatibility_iterator();
2734 // Can't navigate to sibling of this window
2735 // if we're a top-level window.
2736 if (!GetWindow()->GetParent())
2737 return wxACC_NOT_IMPLEMENTED
;
2739 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2743 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2744 node
= GetWindow()->GetChildren().Item(fromId
-1);
2747 if (node
&& node
->GetPrevious())
2749 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2750 *toObject
= previousWindow
->GetOrCreateAccessible();
2758 return wxACC_NOT_IMPLEMENTED
;
2761 // Gets the name of the specified object.
2762 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2764 wxASSERT( GetWindow() != NULL
);
2770 // If a child, leave wxWidgets to call the function on the actual
2773 return wxACC_NOT_IMPLEMENTED
;
2775 // This will eventually be replaced by specialised
2776 // accessible classes, one for each kind of wxWidgets
2777 // control or window.
2779 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2780 title
= ((wxButton
*) GetWindow())->GetLabel();
2783 title
= GetWindow()->GetName();
2791 return wxACC_NOT_IMPLEMENTED
;
2794 // Gets the number of children.
2795 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2797 wxASSERT( GetWindow() != NULL
);
2801 *childId
= (int) GetWindow()->GetChildren().GetCount();
2805 // Gets the specified child (starting from 1).
2806 // If *child is NULL and return value is wxACC_OK,
2807 // this means that the child is a simple element and
2808 // not an accessible object.
2809 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2811 wxASSERT( GetWindow() != NULL
);
2821 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2824 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2825 *child
= childWindow
->GetOrCreateAccessible();
2832 // Gets the parent, or NULL.
2833 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2835 wxASSERT( GetWindow() != NULL
);
2839 wxWindow
* parentWindow
= GetWindow()->GetParent();
2847 *parent
= parentWindow
->GetOrCreateAccessible();
2855 // Performs the default action. childId is 0 (the action for this object)
2856 // or > 0 (the action for a child).
2857 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2858 // window (e.g. an edit control).
2859 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
2861 wxASSERT( GetWindow() != NULL
);
2865 return wxACC_NOT_IMPLEMENTED
;
2868 // Gets the default action for this object (0) or > 0 (the action for a child).
2869 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2870 // string if there is no action.
2871 // The retrieved string describes the action that is performed on an object,
2872 // not what the object does as a result. For example, a toolbar button that prints
2873 // a document has a default action of "Press" rather than "Prints the current document."
2874 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
2876 wxASSERT( GetWindow() != NULL
);
2880 return wxACC_NOT_IMPLEMENTED
;
2883 // Returns the description for this object or a child.
2884 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
2886 wxASSERT( GetWindow() != NULL
);
2890 wxString
ht(GetWindow()->GetHelpText());
2896 return wxACC_NOT_IMPLEMENTED
;
2899 // Returns help text for this object or a child, similar to tooltip text.
2900 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
2902 wxASSERT( GetWindow() != NULL
);
2906 wxString
ht(GetWindow()->GetHelpText());
2912 return wxACC_NOT_IMPLEMENTED
;
2915 // Returns the keyboard shortcut for this object or child.
2916 // Return e.g. ALT+K
2917 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
2919 wxASSERT( GetWindow() != NULL
);
2923 return wxACC_NOT_IMPLEMENTED
;
2926 // Returns a role constant.
2927 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
2929 wxASSERT( GetWindow() != NULL
);
2933 // If a child, leave wxWidgets to call the function on the actual
2936 return wxACC_NOT_IMPLEMENTED
;
2938 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2939 return wxACC_NOT_IMPLEMENTED
;
2941 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2942 return wxACC_NOT_IMPLEMENTED
;
2945 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2946 return wxACC_NOT_IMPLEMENTED
;
2949 //*role = wxROLE_SYSTEM_CLIENT;
2950 *role
= wxROLE_SYSTEM_CLIENT
;
2954 return wxACC_NOT_IMPLEMENTED
;
2958 // Returns a state constant.
2959 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
2961 wxASSERT( GetWindow() != NULL
);
2965 // If a child, leave wxWidgets to call the function on the actual
2968 return wxACC_NOT_IMPLEMENTED
;
2970 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2971 return wxACC_NOT_IMPLEMENTED
;
2974 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2975 return wxACC_NOT_IMPLEMENTED
;
2978 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2979 return wxACC_NOT_IMPLEMENTED
;
2986 return wxACC_NOT_IMPLEMENTED
;
2990 // Returns a localized string representing the value for the object
2992 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
2994 wxASSERT( GetWindow() != NULL
);
2998 return wxACC_NOT_IMPLEMENTED
;
3001 // Selects the object or child.
3002 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
3004 wxASSERT( GetWindow() != NULL
);
3008 return wxACC_NOT_IMPLEMENTED
;
3011 // Gets the window with the keyboard focus.
3012 // If childId is 0 and child is NULL, no object in
3013 // this subhierarchy has the focus.
3014 // If this object has the focus, child should be 'this'.
3015 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
3017 wxASSERT( GetWindow() != NULL
);
3021 return wxACC_NOT_IMPLEMENTED
;
3024 // Gets a variant representing the selected children
3026 // Acceptable values:
3027 // - a null variant (IsNull() returns true)
3028 // - a list variant (GetType() == wxT("list")
3029 // - an integer representing the selected child element,
3030 // or 0 if this object is selected (GetType() == wxT("long")
3031 // - a "void*" pointer to a wxAccessible child object
3032 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
3034 wxASSERT( GetWindow() != NULL
);
3038 return wxACC_NOT_IMPLEMENTED
;
3041 #endif // wxUSE_ACCESSIBILITY