1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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/toolbar.h"
48 #include "wx/dcclient.h"
51 #if defined(__WXMAC__) && wxUSE_SCROLLBAR
52 #include "wx/scrolbar.h"
56 #include "wx/layout.h"
57 #endif // wxUSE_CONSTRAINTS
61 #if wxUSE_DRAG_AND_DROP
63 #endif // wxUSE_DRAG_AND_DROP
65 #if wxUSE_ACCESSIBILITY
66 #include "wx/access.h"
70 #include "wx/cshelp.h"
74 #include "wx/tooltip.h"
75 #endif // wxUSE_TOOLTIPS
82 #include "wx/display.h"
85 #if wxUSE_SYSTEM_OPTIONS
86 #include "wx/sysopt.h"
89 // ----------------------------------------------------------------------------
91 // ----------------------------------------------------------------------------
93 #if defined(__WXPALMOS__)
94 int wxWindowBase::ms_lastControlId
= 32767;
95 #elif defined(__WXPM__)
96 int wxWindowBase::ms_lastControlId
= 2000;
98 int wxWindowBase::ms_lastControlId
= -200;
101 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
103 // ----------------------------------------------------------------------------
105 // ----------------------------------------------------------------------------
107 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
108 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
109 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
110 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick
)
113 EVT_HELP(wxID_ANY
, wxWindowBase::OnHelp
)
118 // ============================================================================
119 // implementation of the common functionality of the wxWindow class
120 // ============================================================================
122 // ----------------------------------------------------------------------------
124 // ----------------------------------------------------------------------------
126 // the default initialization
127 wxWindowBase::wxWindowBase()
129 // no window yet, no parent nor children
130 m_parent
= (wxWindow
*)NULL
;
131 m_windowId
= wxID_ANY
;
133 // no constraints on the minimal window size
135 m_maxWidth
= wxDefaultCoord
;
137 m_maxHeight
= wxDefaultCoord
;
139 // invalidiated cache value
140 m_bestSizeCache
= wxDefaultSize
;
142 // window are created enabled and visible by default
146 // the default event handler is just this window
147 m_eventHandler
= this;
151 m_windowValidator
= (wxValidator
*) NULL
;
152 #endif // wxUSE_VALIDATORS
154 // the colours/fonts are default for now, so leave m_font,
155 // m_backgroundColour and m_foregroundColour uninitialized and set those
161 m_inheritFont
= false;
167 m_backgroundStyle
= wxBG_STYLE_SYSTEM
;
169 #if wxUSE_CONSTRAINTS
170 // no constraints whatsoever
171 m_constraints
= (wxLayoutConstraints
*) NULL
;
172 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
173 #endif // wxUSE_CONSTRAINTS
175 m_windowSizer
= (wxSizer
*) NULL
;
176 m_containingSizer
= (wxSizer
*) NULL
;
177 m_autoLayout
= false;
179 #if wxUSE_DRAG_AND_DROP
180 m_dropTarget
= (wxDropTarget
*)NULL
;
181 #endif // wxUSE_DRAG_AND_DROP
184 m_tooltip
= (wxToolTip
*)NULL
;
185 #endif // wxUSE_TOOLTIPS
188 m_caret
= (wxCaret
*)NULL
;
189 #endif // wxUSE_CARET
192 m_hasCustomPalette
= false;
193 #endif // wxUSE_PALETTE
195 #if wxUSE_ACCESSIBILITY
199 m_virtualSize
= wxDefaultSize
;
202 m_maxVirtualWidth
= wxDefaultCoord
;
204 m_maxVirtualHeight
= wxDefaultCoord
;
206 m_windowVariant
= wxWINDOW_VARIANT_NORMAL
;
207 #if wxUSE_SYSTEM_OPTIONS
208 if ( wxSystemOptions::HasOption(wxWINDOW_DEFAULT_VARIANT
) )
210 m_windowVariant
= (wxWindowVariant
) wxSystemOptions::GetOptionInt( wxWINDOW_DEFAULT_VARIANT
) ;
214 // Whether we're using the current theme for this window (wxGTK only for now)
215 m_themeEnabled
= false;
217 // VZ: this one shouldn't exist...
218 m_isBeingDeleted
= false;
220 // Reserved for future use
221 m_windowReserved
= NULL
;
224 // common part of window creation process
225 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
227 const wxPoint
& WXUNUSED(pos
),
228 const wxSize
& WXUNUSED(size
),
230 const wxValidator
& wxVALIDATOR_PARAM(validator
),
231 const wxString
& name
)
234 // wxGTK doesn't allow to create controls with static box as the parent so
235 // this will result in a crash when the program is ported to wxGTK so warn
238 // if you get this assert, the correct solution is to create the controls
239 // as siblings of the static box
240 wxASSERT_MSG( !parent
|| !wxDynamicCast(parent
, wxStaticBox
),
241 _T("wxStaticBox can't be used as a window parent!") );
242 #endif // wxUSE_STATBOX
244 // ids are limited to 16 bits under MSW so if you care about portability,
245 // it's not a good idea to use ids out of this range (and negative ids are
246 // reserved for wxWidgets own usage)
247 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767),
248 _T("invalid id value") );
250 // generate a new id if the user doesn't care about it
251 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
254 SetWindowStyleFlag(style
);
258 SetValidator(validator
);
259 #endif // wxUSE_VALIDATORS
261 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
262 // have it too - like this it's possible to set it only in the top level
263 // dialog/frame and all children will inherit it by defult
264 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
266 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
272 // ----------------------------------------------------------------------------
274 // ----------------------------------------------------------------------------
277 wxWindowBase::~wxWindowBase()
279 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
281 // FIXME if these 2 cases result from programming errors in the user code
282 // we should probably assert here instead of silently fixing them
284 // Just in case the window has been Closed, but we're then deleting
285 // immediately: don't leave dangling pointers.
286 wxPendingDelete
.DeleteObject(this);
288 // Just in case we've loaded a top-level window via LoadNativeDialog but
289 // we weren't a dialog class
290 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
292 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
294 // reset the dangling pointer our parent window may keep to us
297 if ( m_parent
->GetDefaultItem() == this )
299 m_parent
->SetDefaultItem(NULL
);
302 m_parent
->RemoveChild(this);
307 #endif // wxUSE_CARET
310 delete m_windowValidator
;
311 #endif // wxUSE_VALIDATORS
313 #if wxUSE_CONSTRAINTS
314 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
315 // at deleted windows as they delete themselves.
316 DeleteRelatedConstraints();
320 // This removes any dangling pointers to this window in other windows'
321 // constraintsInvolvedIn lists.
322 UnsetConstraints(m_constraints
);
323 delete m_constraints
;
324 m_constraints
= NULL
;
326 #endif // wxUSE_CONSTRAINTS
328 if ( m_containingSizer
)
329 m_containingSizer
->Detach( (wxWindow
*)this );
331 delete m_windowSizer
;
333 #if wxUSE_DRAG_AND_DROP
335 #endif // wxUSE_DRAG_AND_DROP
339 #endif // wxUSE_TOOLTIPS
341 #if wxUSE_ACCESSIBILITY
346 bool wxWindowBase::Destroy()
353 bool wxWindowBase::Close(bool force
)
355 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
356 event
.SetEventObject(this);
357 event
.SetCanVeto(!force
);
359 // return false if window wasn't closed because the application vetoed the
361 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
364 bool wxWindowBase::DestroyChildren()
366 wxWindowList::compatibility_iterator node
;
369 // we iterate until the list becomes empty
370 node
= GetChildren().GetFirst();
374 wxWindow
*child
= node
->GetData();
376 // note that we really want to call delete and not ->Destroy() here
377 // because we want to delete the child immediately, before we are
378 // deleted, and delayed deletion would result in problems as our (top
379 // level) child could outlive its parent
382 wxASSERT_MSG( !GetChildren().Find(child
),
383 wxT("child didn't remove itself using RemoveChild()") );
389 // ----------------------------------------------------------------------------
390 // size/position related methods
391 // ----------------------------------------------------------------------------
393 // centre the window with respect to its parent in either (or both) directions
394 void wxWindowBase::Centre(int direction
)
396 // the position/size of the parent window or of the entire screen
398 int widthParent
, heightParent
;
400 wxWindow
*parent
= NULL
;
401 wxTopLevelWindow
*winTop
= NULL
;
403 if ( !(direction
& wxCENTRE_ON_SCREEN
) )
405 // find the parent to centre this window on: it should be the
406 // immediate parent for the controls but the top level parent for the
407 // top level windows (like dialogs)
408 parent
= GetParent();
411 while ( parent
&& !parent
->IsTopLevel() )
413 parent
= parent
->GetParent();
417 // there is no wxTopLevelWindow under wxMotif yet
419 // we shouldn't center the dialog on the iconized window: under
420 // Windows, for example, this places it completely off the screen
423 winTop
= wxDynamicCast(parent
, wxTopLevelWindow
);
424 if ( winTop
&& winTop
->IsIconized() )
430 #endif // __WXMOTIF__
432 // did we find the parent?
436 direction
|= wxCENTRE_ON_SCREEN
;
440 if ( direction
& wxCENTRE_ON_SCREEN
)
442 //RN: If we are using wxDisplay we get
443 //the dimensions of the monitor the window is on,
444 //otherwise we get the dimensions of the primary monitor
445 //FIXME: wxDisplay::GetFromWindow only implemented on MSW
446 #if wxUSE_DISPLAY && defined(__WXMSW__)
447 int nDisplay
= wxDisplay::GetFromWindow((wxWindow
*)this);
448 if(nDisplay
!= wxNOT_FOUND
)
450 wxDisplay
windowDisplay(nDisplay
);
451 wxRect displayRect
= windowDisplay
.GetGeometry();
452 widthParent
= displayRect
.width
;
453 heightParent
= displayRect
.height
;
457 // centre with respect to the whole screen
458 wxDisplaySize(&widthParent
, &heightParent
);
465 winTop
->GetRectForTopLevelChildren(&posParent
.x
, &posParent
.y
, &widthParent
, &heightParent
);
468 // centre on the parent
469 parent
->GetSize(&widthParent
, &heightParent
);
471 // adjust to the parents position
472 posParent
= parent
->GetPosition();
477 // centre inside the parents client rectangle
478 parent
->GetClientSize(&widthParent
, &heightParent
);
483 GetSize(&width
, &height
);
485 int xNew
= wxDefaultCoord
,
486 yNew
= wxDefaultCoord
;
488 if ( direction
& wxHORIZONTAL
)
489 xNew
= (widthParent
- width
)/2;
491 if ( direction
& wxVERTICAL
)
492 yNew
= (heightParent
- height
)/2;
497 // FIXME: This needs to get the client display rect of the display
498 // the window is (via wxDisplay::GetFromWindow).
500 // Base size of the visible dimensions of the display
501 // to take into account the taskbar. And the Mac menu bar at top.
502 wxRect clientrect
= wxGetClientDisplayRect();
504 // NB: in wxMSW, negative position may not necessarily mean "out of screen",
505 // but it may mean that the window is placed on other than the main
506 // display. Therefore we only make sure centered window is on the main display
507 // if the parent is at least partially present here.
508 if (posParent
.x
+ widthParent
>= 0) // if parent is (partially) on the main display
510 if (xNew
< clientrect
.GetLeft())
511 xNew
= clientrect
.GetLeft();
512 else if (xNew
+ width
> clientrect
.GetRight())
513 xNew
= clientrect
.GetRight() - width
;
515 if (posParent
.y
+ heightParent
>= 0) // if parent is (partially) on the main display
517 if (yNew
+ height
> clientrect
.GetBottom())
518 yNew
= clientrect
.GetBottom() - height
;
520 // Make certain that the title bar is initially visible
521 // always, even if this would push the bottom of the
522 // dialog off the visible area of the display
523 if (yNew
< clientrect
.GetTop())
524 yNew
= clientrect
.GetTop();
527 // move the window to this position (keeping the old size but using
528 // SetSize() and not Move() to allow xNew and/or yNew to be wxDefaultCoord)
529 SetSize(xNew
, yNew
, width
, height
, wxSIZE_ALLOW_MINUS_ONE
);
532 // fits the window around the children
533 void wxWindowBase::Fit()
535 if ( GetChildren().GetCount() > 0 )
537 SetSize(GetBestSize());
539 //else: do nothing if we have no children
542 // fits virtual size (ie. scrolled area etc.) around children
543 void wxWindowBase::FitInside()
545 if ( GetChildren().GetCount() > 0 )
547 SetVirtualSize( GetBestVirtualSize() );
551 // On Mac, scrollbars are explicitly children.
553 static bool wxHasRealChildren(const wxWindowBase
* win
)
555 int realChildCount
= 0;
557 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
559 node
= node
->GetNext() )
561 wxWindow
*win
= node
->GetData();
562 if ( !win
->IsTopLevel() && win
->IsShown() && !win
->IsKindOf(CLASSINFO(wxScrollBar
)))
565 return (realChildCount
> 0);
569 void wxWindowBase::InvalidateBestSize()
571 m_bestSizeCache
= wxDefaultSize
;
573 // parent's best size calculation may depend on its children's
574 // best sizes, so let's invalidate it as well to be safe:
576 m_parent
->InvalidateBestSize();
579 // return the size best suited for the current window
580 wxSize
wxWindowBase::DoGetBestSize() const
586 best
= m_windowSizer
->GetMinSize();
588 #if wxUSE_CONSTRAINTS
589 else if ( m_constraints
)
591 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
593 // our minimal acceptable size is such that all our windows fit inside
597 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
599 node
= node
->GetNext() )
601 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
604 // it's not normal that we have an unconstrained child, but
605 // what can we do about it?
609 int x
= c
->right
.GetValue(),
610 y
= c
->bottom
.GetValue();
618 // TODO: we must calculate the overlaps somehow, otherwise we
619 // will never return a size bigger than the current one :-(
622 best
= wxSize(maxX
, maxY
);
624 #endif // wxUSE_CONSTRAINTS
625 else if ( !GetChildren().empty()
627 && wxHasRealChildren(this)
631 // our minimal acceptable size is such that all our visible child windows fit inside
635 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
637 node
= node
->GetNext() )
639 wxWindow
*win
= node
->GetData();
640 if ( win
->IsTopLevel() || ( ! win
->IsShown() )
642 || wxDynamicCast(win
, wxStatusBar
)
643 #endif // wxUSE_STATUSBAR
646 // dialogs and frames lie in different top level windows -
647 // don't deal with them here; as for the status bars, they
648 // don't lie in the client area at all
653 win
->GetPosition(&wx
, &wy
);
655 // if the window hadn't been positioned yet, assume that it is in
657 if ( wx
== wxDefaultCoord
)
659 if ( wy
== wxDefaultCoord
)
662 win
->GetSize(&ww
, &wh
);
663 if ( wx
+ ww
> maxX
)
665 if ( wy
+ wh
> maxY
)
669 // for compatibility with the old versions and because it really looks
670 // slightly more pretty like this, add a pad
674 best
= wxSize(maxX
, maxY
);
676 else // ! has children
678 // for a generic window there is no natural best size so, if the
679 // minimal size is not set, use the current size but take care to
680 // remember it as minimal size for the next time because our best size
681 // should be constant: otherwise we could get into a situation when the
682 // window is initially at some size, then expanded to a larger size and
683 // then, when the containing window is shrunk back (because our initial
684 // best size had been used for computing the parent min size), we can't
685 // be shrunk back any more because our best size is now bigger
686 wxSize size
= GetMinSize();
687 if ( !size
.IsFullySpecified() )
689 size
.SetDefaults(GetSize());
690 wxConstCast(this, wxWindowBase
)->SetMinSize(size
);
693 // return as-is, unadjusted by the client size difference.
697 // Add any difference between size and client size
698 wxSize diff
= GetSize() - GetClientSize();
699 best
.x
+= wxMax(0, diff
.x
);
700 best
.y
+= wxMax(0, diff
.y
);
706 wxSize
wxWindowBase::GetBestFittingSize() const
708 // merge the best size with the min size, giving priority to the min size
709 wxSize min
= GetMinSize();
710 if (min
.x
== wxDefaultCoord
|| min
.y
== wxDefaultCoord
)
712 wxSize best
= GetBestSize();
713 if (min
.x
== wxDefaultCoord
) min
.x
= best
.x
;
714 if (min
.y
== wxDefaultCoord
) min
.y
= best
.y
;
720 void wxWindowBase::SetBestFittingSize(const wxSize
& size
)
722 // Set the min size to the size passed in. This will usually either be
723 // wxDefaultSize or the size passed to this window's ctor/Create function.
726 // Merge the size with the best size if needed
727 wxSize best
= GetBestFittingSize();
729 // If the current size doesn't match then change it
730 if (GetSize() != best
)
735 // by default the origin is not shifted
736 wxPoint
wxWindowBase::GetClientAreaOrigin() const
741 // set the min/max size of the window
742 void wxWindowBase::DoSetSizeHints(int minW
, int minH
,
744 int WXUNUSED(incW
), int WXUNUSED(incH
))
746 // setting min width greater than max width leads to infinite loops under
747 // X11 and generally doesn't make any sense, so don't allow it
748 wxCHECK_RET( (minW
== wxDefaultCoord
|| maxW
== wxDefaultCoord
|| minW
<= maxW
) &&
749 (minH
== wxDefaultCoord
|| maxH
== wxDefaultCoord
|| minH
<= maxH
),
750 _T("min width/height must be less than max width/height!") );
758 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
760 if ( m_windowVariant
!= variant
)
762 m_windowVariant
= variant
;
764 DoSetWindowVariant(variant
);
768 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
770 // adjust the font height to correspond to our new variant (notice that
771 // we're only called if something really changed)
772 wxFont font
= GetFont();
773 int size
= font
.GetPointSize();
776 case wxWINDOW_VARIANT_NORMAL
:
779 case wxWINDOW_VARIANT_SMALL
:
784 case wxWINDOW_VARIANT_MINI
:
789 case wxWINDOW_VARIANT_LARGE
:
795 wxFAIL_MSG(_T("unexpected window variant"));
799 font
.SetPointSize(size
);
803 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
806 m_minVirtualWidth
= minW
;
807 m_maxVirtualWidth
= maxW
;
808 m_minVirtualHeight
= minH
;
809 m_maxVirtualHeight
= maxH
;
812 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
814 if ( m_minVirtualWidth
!= wxDefaultCoord
&& m_minVirtualWidth
> x
)
815 x
= m_minVirtualWidth
;
816 if ( m_maxVirtualWidth
!= wxDefaultCoord
&& m_maxVirtualWidth
< x
)
817 x
= m_maxVirtualWidth
;
818 if ( m_minVirtualHeight
!= wxDefaultCoord
&& m_minVirtualHeight
> y
)
819 y
= m_minVirtualHeight
;
820 if ( m_maxVirtualHeight
!= wxDefaultCoord
&& m_maxVirtualHeight
< y
)
821 y
= m_maxVirtualHeight
;
823 m_virtualSize
= wxSize(x
, y
);
826 wxSize
wxWindowBase::DoGetVirtualSize() const
828 if ( m_virtualSize
.IsFullySpecified() )
829 return m_virtualSize
;
831 wxSize size
= GetClientSize();
832 if ( m_virtualSize
.x
!= wxDefaultCoord
)
833 size
.x
= m_virtualSize
.x
;
835 if ( m_virtualSize
.y
!= wxDefaultCoord
)
836 size
.y
= m_virtualSize
.y
;
841 // ----------------------------------------------------------------------------
842 // show/hide/enable/disable the window
843 // ----------------------------------------------------------------------------
845 bool wxWindowBase::Show(bool show
)
847 if ( show
!= m_isShown
)
859 bool wxWindowBase::Enable(bool enable
)
861 if ( enable
!= m_isEnabled
)
863 m_isEnabled
= enable
;
872 // ----------------------------------------------------------------------------
874 // ----------------------------------------------------------------------------
876 bool wxWindowBase::IsTopLevel() const
881 // ----------------------------------------------------------------------------
882 // reparenting the window
883 // ----------------------------------------------------------------------------
885 void wxWindowBase::AddChild(wxWindowBase
*child
)
887 wxCHECK_RET( child
, wxT("can't add a NULL child") );
889 // this should never happen and it will lead to a crash later if it does
890 // because RemoveChild() will remove only one node from the children list
891 // and the other(s) one(s) will be left with dangling pointers in them
892 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
894 GetChildren().Append((wxWindow
*)child
);
895 child
->SetParent(this);
898 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
900 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
902 GetChildren().DeleteObject((wxWindow
*)child
);
903 child
->SetParent(NULL
);
906 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
908 wxWindow
*oldParent
= GetParent();
909 if ( newParent
== oldParent
)
915 // unlink this window from the existing parent.
918 oldParent
->RemoveChild(this);
922 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
925 // add it to the new one
928 newParent
->AddChild(this);
932 wxTopLevelWindows
.Append((wxWindow
*)this);
938 // ----------------------------------------------------------------------------
939 // event handler stuff
940 // ----------------------------------------------------------------------------
942 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
944 wxEvtHandler
*handlerOld
= GetEventHandler();
946 handler
->SetNextHandler(handlerOld
);
949 GetEventHandler()->SetPreviousHandler(handler
);
951 SetEventHandler(handler
);
954 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
956 wxEvtHandler
*handlerA
= GetEventHandler();
959 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
960 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
963 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
964 SetEventHandler(handlerB
);
969 handlerA
= (wxEvtHandler
*)NULL
;
976 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
978 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
980 wxEvtHandler
*handlerPrev
= NULL
,
981 *handlerCur
= GetEventHandler();
984 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
986 if ( handlerCur
== handler
)
990 handlerPrev
->SetNextHandler(handlerNext
);
994 SetEventHandler(handlerNext
);
999 handlerNext
->SetPreviousHandler ( handlerPrev
);
1002 handler
->SetNextHandler(NULL
);
1003 handler
->SetPreviousHandler(NULL
);
1008 handlerPrev
= handlerCur
;
1009 handlerCur
= handlerNext
;
1012 wxFAIL_MSG( _T("where has the event handler gone?") );
1017 // ----------------------------------------------------------------------------
1018 // colours, fonts &c
1019 // ----------------------------------------------------------------------------
1021 void wxWindowBase::InheritAttributes()
1023 const wxWindowBase
* const parent
= GetParent();
1027 // we only inherit attributes which had been explicitly set for the parent
1028 // which ensures that this only happens if the user really wants it and
1029 // not by default which wouldn't make any sense in modern GUIs where the
1030 // controls don't all use the same fonts (nor colours)
1031 if ( parent
->m_inheritFont
&& !m_hasFont
)
1032 SetFont(parent
->GetFont());
1034 // in addition, there is a possibility to explicitly forbid inheriting
1035 // colours at each class level by overriding ShouldInheritColours()
1036 if ( ShouldInheritColours() )
1038 if ( parent
->m_inheritFgCol
&& !m_hasFgCol
)
1039 SetForegroundColour(parent
->GetForegroundColour());
1041 // inheriting (solid) background colour is wrong as it totally breaks
1042 // any kind of themed backgrounds
1044 // instead, the controls should use the same background as their parent
1045 // (ideally by not drawing it at all)
1047 if ( parent
->m_inheritBgCol
&& !m_hasBgCol
)
1048 SetBackgroundColour(parent
->GetBackgroundColour());
1053 /* static */ wxVisualAttributes
1054 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
1056 // it is important to return valid values for all attributes from here,
1057 // GetXXX() below rely on this
1058 wxVisualAttributes attrs
;
1059 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
1060 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1062 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
1063 // the usual background colour than wxSYS_COLOUR_BTNFACE.
1064 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
1065 // colour on other platforms.
1067 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
1068 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1070 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
1075 wxColour
wxWindowBase::GetBackgroundColour() const
1077 if ( !m_backgroundColour
.Ok() )
1079 wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") );
1081 // get our default background colour
1082 wxColour colBg
= GetDefaultAttributes().colBg
;
1084 // we must return some valid colour to avoid redoing this every time
1085 // and also to avoid surprizing the applications written for older
1086 // wxWidgets versions where GetBackgroundColour() always returned
1087 // something -- so give them something even if it doesn't make sense
1088 // for this window (e.g. it has a themed background)
1090 colBg
= GetClassDefaultAttributes().colBg
;
1095 return m_backgroundColour
;
1098 wxColour
wxWindowBase::GetForegroundColour() const
1100 // logic is the same as above
1101 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
1103 wxASSERT_MSG( !m_hasFgCol
, _T("we have invalid explicit fg colour?") );
1105 wxColour colFg
= GetDefaultAttributes().colFg
;
1108 colFg
= GetClassDefaultAttributes().colFg
;
1113 return m_foregroundColour
;
1116 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
1118 if ( colour
== m_backgroundColour
)
1121 m_hasBgCol
= colour
.Ok();
1122 if ( m_backgroundStyle
!= wxBG_STYLE_CUSTOM
)
1123 m_backgroundStyle
= m_hasBgCol
? wxBG_STYLE_COLOUR
: wxBG_STYLE_SYSTEM
;
1125 m_inheritBgCol
= m_hasBgCol
;
1126 m_backgroundColour
= colour
;
1127 SetThemeEnabled( !m_hasBgCol
&& !m_foregroundColour
.Ok() );
1131 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
1133 if (colour
== m_foregroundColour
)
1136 m_hasFgCol
= colour
.Ok();
1137 m_inheritFgCol
= m_hasFgCol
;
1138 m_foregroundColour
= colour
;
1139 SetThemeEnabled( !m_hasFgCol
&& !m_backgroundColour
.Ok() );
1143 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
1145 // setting an invalid cursor is ok, it means that we don't have any special
1147 if ( m_cursor
== cursor
)
1158 wxFont
wxWindowBase::GetFont() const
1160 // logic is the same as in GetBackgroundColour()
1163 wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") );
1165 wxFont font
= GetDefaultAttributes().font
;
1167 font
= GetClassDefaultAttributes().font
;
1175 bool wxWindowBase::SetFont(const wxFont
& font
)
1177 if ( font
== m_font
)
1184 m_hasFont
= font
.Ok();
1185 m_inheritFont
= m_hasFont
;
1187 InvalidateBestSize();
1194 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1196 m_hasCustomPalette
= true;
1199 // VZ: can anyone explain me what do we do here?
1200 wxWindowDC
d((wxWindow
*) this);
1204 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1206 wxWindow
*win
= (wxWindow
*)this;
1207 while ( win
&& !win
->HasCustomPalette() )
1209 win
= win
->GetParent();
1215 #endif // wxUSE_PALETTE
1218 void wxWindowBase::SetCaret(wxCaret
*caret
)
1229 wxASSERT_MSG( m_caret
->GetWindow() == this,
1230 wxT("caret should be created associated to this window") );
1233 #endif // wxUSE_CARET
1235 #if wxUSE_VALIDATORS
1236 // ----------------------------------------------------------------------------
1238 // ----------------------------------------------------------------------------
1240 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1242 if ( m_windowValidator
)
1243 delete m_windowValidator
;
1245 m_windowValidator
= (wxValidator
*)validator
.Clone();
1247 if ( m_windowValidator
)
1248 m_windowValidator
->SetWindow(this);
1250 #endif // wxUSE_VALIDATORS
1252 // ----------------------------------------------------------------------------
1253 // update region stuff
1254 // ----------------------------------------------------------------------------
1256 wxRect
wxWindowBase::GetUpdateClientRect() const
1258 wxRegion rgnUpdate
= GetUpdateRegion();
1259 rgnUpdate
.Intersect(GetClientRect());
1260 wxRect rectUpdate
= rgnUpdate
.GetBox();
1261 wxPoint ptOrigin
= GetClientAreaOrigin();
1262 rectUpdate
.x
-= ptOrigin
.x
;
1263 rectUpdate
.y
-= ptOrigin
.y
;
1268 bool wxWindowBase::IsExposed(int x
, int y
) const
1270 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1273 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
1275 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1278 void wxWindowBase::ClearBackground()
1280 // wxGTK uses its own version, no need to add never used code
1282 wxClientDC
dc((wxWindow
*)this);
1283 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1284 dc
.SetBackground(brush
);
1289 // ----------------------------------------------------------------------------
1290 // find child window by id or name
1291 // ----------------------------------------------------------------------------
1293 wxWindow
*wxWindowBase::FindWindow(long id
) const
1295 if ( id
== m_windowId
)
1296 return (wxWindow
*)this;
1298 wxWindowBase
*res
= (wxWindow
*)NULL
;
1299 wxWindowList::compatibility_iterator node
;
1300 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1302 wxWindowBase
*child
= node
->GetData();
1303 res
= child
->FindWindow( id
);
1306 return (wxWindow
*)res
;
1309 wxWindow
*wxWindowBase::FindWindow(const wxString
& name
) const
1311 if ( name
== m_windowName
)
1312 return (wxWindow
*)this;
1314 wxWindowBase
*res
= (wxWindow
*)NULL
;
1315 wxWindowList::compatibility_iterator node
;
1316 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1318 wxWindow
*child
= node
->GetData();
1319 res
= child
->FindWindow(name
);
1322 return (wxWindow
*)res
;
1326 // find any window by id or name or label: If parent is non-NULL, look through
1327 // children for a label or title matching the specified string. If NULL, look
1328 // through all top-level windows.
1330 // to avoid duplicating code we reuse the same helper function but with
1331 // different comparators
1333 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1334 const wxString
& label
, long id
);
1337 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1340 return win
->GetLabel() == label
;
1344 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1347 return win
->GetName() == label
;
1351 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1354 return win
->GetId() == id
;
1357 // recursive helper for the FindWindowByXXX() functions
1359 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1360 const wxString
& label
,
1362 wxFindWindowCmp cmp
)
1366 // see if this is the one we're looking for
1367 if ( (*cmp
)(parent
, label
, id
) )
1368 return (wxWindow
*)parent
;
1370 // It wasn't, so check all its children
1371 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1373 node
= node
->GetNext() )
1375 // recursively check each child
1376 wxWindow
*win
= (wxWindow
*)node
->GetData();
1377 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1387 // helper for FindWindowByXXX()
1389 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1390 const wxString
& label
,
1392 wxFindWindowCmp cmp
)
1396 // just check parent and all its children
1397 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1400 // start at very top of wx's windows
1401 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1403 node
= node
->GetNext() )
1405 // recursively check each window & its children
1406 wxWindow
*win
= node
->GetData();
1407 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1417 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1419 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1424 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1426 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1430 // fall back to the label
1431 win
= FindWindowByLabel(title
, parent
);
1439 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1441 return wxFindWindowHelper(parent
, wxEmptyString
, id
, wxFindWindowCmpIds
);
1444 // ----------------------------------------------------------------------------
1445 // dialog oriented functions
1446 // ----------------------------------------------------------------------------
1448 void wxWindowBase::MakeModal(bool modal
)
1450 // Disable all other windows
1453 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1456 wxWindow
*win
= node
->GetData();
1458 win
->Enable(!modal
);
1460 node
= node
->GetNext();
1465 bool wxWindowBase::Validate()
1467 #if wxUSE_VALIDATORS
1468 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1470 wxWindowList::compatibility_iterator node
;
1471 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1473 wxWindowBase
*child
= node
->GetData();
1474 wxValidator
*validator
= child
->GetValidator();
1475 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1480 if ( recurse
&& !child
->Validate() )
1485 #endif // wxUSE_VALIDATORS
1490 bool wxWindowBase::TransferDataToWindow()
1492 #if wxUSE_VALIDATORS
1493 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1495 wxWindowList::compatibility_iterator node
;
1496 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1498 wxWindowBase
*child
= node
->GetData();
1499 wxValidator
*validator
= child
->GetValidator();
1500 if ( validator
&& !validator
->TransferToWindow() )
1502 wxLogWarning(_("Could not transfer data to window"));
1504 wxLog::FlushActive();
1512 if ( !child
->TransferDataToWindow() )
1514 // warning already given
1519 #endif // wxUSE_VALIDATORS
1524 bool wxWindowBase::TransferDataFromWindow()
1526 #if wxUSE_VALIDATORS
1527 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1529 wxWindowList::compatibility_iterator node
;
1530 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1532 wxWindow
*child
= node
->GetData();
1533 wxValidator
*validator
= child
->GetValidator();
1534 if ( validator
&& !validator
->TransferFromWindow() )
1536 // nop warning here because the application is supposed to give
1537 // one itself - we don't know here what might have gone wrongly
1544 if ( !child
->TransferDataFromWindow() )
1546 // warning already given
1551 #endif // wxUSE_VALIDATORS
1556 void wxWindowBase::InitDialog()
1558 wxInitDialogEvent
event(GetId());
1559 event
.SetEventObject( this );
1560 GetEventHandler()->ProcessEvent(event
);
1563 // ----------------------------------------------------------------------------
1564 // context-sensitive help support
1565 // ----------------------------------------------------------------------------
1569 // associate this help text with this window
1570 void wxWindowBase::SetHelpText(const wxString
& text
)
1572 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1575 helpProvider
->AddHelp(this, text
);
1579 // associate this help text with all windows with the same id as this
1581 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1583 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1586 helpProvider
->AddHelp(GetId(), text
);
1590 // get the help string associated with this window (may be empty)
1591 wxString
wxWindowBase::GetHelpText() const
1594 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1597 text
= helpProvider
->GetHelp(this);
1603 // show help for this window
1604 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1606 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1609 if ( helpProvider
->ShowHelp(this) )
1611 // skip the event.Skip() below
1619 #endif // wxUSE_HELP
1621 // ----------------------------------------------------------------------------
1622 // tooltipsroot.Replace("\\", "/");
1623 // ----------------------------------------------------------------------------
1627 void wxWindowBase::SetToolTip( const wxString
&tip
)
1629 // don't create the new tooltip if we already have one
1632 m_tooltip
->SetTip( tip
);
1636 SetToolTip( new wxToolTip( tip
) );
1639 // setting empty tooltip text does not remove the tooltip any more - use
1640 // SetToolTip((wxToolTip *)NULL) for this
1643 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1648 m_tooltip
= tooltip
;
1651 #endif // wxUSE_TOOLTIPS
1653 // ----------------------------------------------------------------------------
1654 // constraints and sizers
1655 // ----------------------------------------------------------------------------
1657 #if wxUSE_CONSTRAINTS
1659 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1661 if ( m_constraints
)
1663 UnsetConstraints(m_constraints
);
1664 delete m_constraints
;
1666 m_constraints
= constraints
;
1667 if ( m_constraints
)
1669 // Make sure other windows know they're part of a 'meaningful relationship'
1670 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1671 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1672 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1673 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1674 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1675 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1676 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1677 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1678 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1679 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1680 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1681 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1682 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1683 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1684 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1685 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1689 // This removes any dangling pointers to this window in other windows'
1690 // constraintsInvolvedIn lists.
1691 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1695 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1696 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1697 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1698 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1699 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1700 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1701 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1702 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1703 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1704 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1705 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1706 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1707 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1708 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1709 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1710 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1714 // Back-pointer to other windows we're involved with, so if we delete this
1715 // window, we must delete any constraints we're involved with.
1716 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1718 if ( !m_constraintsInvolvedIn
)
1719 m_constraintsInvolvedIn
= new wxWindowList
;
1720 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1721 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1724 // REMOVE back-pointer to other windows we're involved with.
1725 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1727 if ( m_constraintsInvolvedIn
)
1728 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1731 // Reset any constraints that mention this window
1732 void wxWindowBase::DeleteRelatedConstraints()
1734 if ( m_constraintsInvolvedIn
)
1736 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1739 wxWindow
*win
= node
->GetData();
1740 wxLayoutConstraints
*constr
= win
->GetConstraints();
1742 // Reset any constraints involving this window
1745 constr
->left
.ResetIfWin(this);
1746 constr
->top
.ResetIfWin(this);
1747 constr
->right
.ResetIfWin(this);
1748 constr
->bottom
.ResetIfWin(this);
1749 constr
->width
.ResetIfWin(this);
1750 constr
->height
.ResetIfWin(this);
1751 constr
->centreX
.ResetIfWin(this);
1752 constr
->centreY
.ResetIfWin(this);
1755 wxWindowList::compatibility_iterator next
= node
->GetNext();
1756 m_constraintsInvolvedIn
->Erase(node
);
1760 delete m_constraintsInvolvedIn
;
1761 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1765 #endif // wxUSE_CONSTRAINTS
1767 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1769 if ( sizer
== m_windowSizer
)
1773 delete m_windowSizer
;
1775 m_windowSizer
= sizer
;
1777 SetAutoLayout( sizer
!= NULL
);
1780 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1782 SetSizer( sizer
, deleteOld
);
1783 sizer
->SetSizeHints( (wxWindow
*) this );
1787 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
1789 // adding a window to a sizer twice is going to result in fatal and
1790 // hard to debug problems later because when deleting the second
1791 // associated wxSizerItem we're going to dereference a dangling
1792 // pointer; so try to detect this as early as possible
1793 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
1794 _T("Adding a window to the same sizer twice?") );
1796 m_containingSizer
= sizer
;
1799 #if wxUSE_CONSTRAINTS
1801 void wxWindowBase::SatisfyConstraints()
1803 wxLayoutConstraints
*constr
= GetConstraints();
1804 bool wasOk
= constr
&& constr
->AreSatisfied();
1806 ResetConstraints(); // Mark all constraints as unevaluated
1810 // if we're a top level panel (i.e. our parent is frame/dialog), our
1811 // own constraints will never be satisfied any more unless we do it
1815 while ( noChanges
> 0 )
1817 LayoutPhase1(&noChanges
);
1821 LayoutPhase2(&noChanges
);
1824 #endif // wxUSE_CONSTRAINTS
1826 bool wxWindowBase::Layout()
1828 // If there is a sizer, use it instead of the constraints
1832 GetVirtualSize(&w
, &h
);
1833 GetSizer()->SetDimension( 0, 0, w
, h
);
1835 #if wxUSE_CONSTRAINTS
1838 SatisfyConstraints(); // Find the right constraints values
1839 SetConstraintSizes(); // Recursively set the real window sizes
1846 #if wxUSE_CONSTRAINTS
1848 // first phase of the constraints evaluation: set our own constraints
1849 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1851 wxLayoutConstraints
*constr
= GetConstraints();
1853 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1856 // second phase: set the constraints for our children
1857 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1864 // Layout grand children
1870 // Do a phase of evaluating child constraints
1871 bool wxWindowBase::DoPhase(int phase
)
1873 // the list containing the children for which the constraints are already
1875 wxWindowList succeeded
;
1877 // the max number of iterations we loop before concluding that we can't set
1879 static const int maxIterations
= 500;
1881 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1885 // loop over all children setting their constraints
1886 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1888 node
= node
->GetNext() )
1890 wxWindow
*child
= node
->GetData();
1891 if ( child
->IsTopLevel() )
1893 // top level children are not inside our client area
1897 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1899 // this one is either already ok or nothing we can do about it
1903 int tempNoChanges
= 0;
1904 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1905 : child
->LayoutPhase2(&tempNoChanges
);
1906 noChanges
+= tempNoChanges
;
1910 succeeded
.Append(child
);
1916 // constraints are set
1924 void wxWindowBase::ResetConstraints()
1926 wxLayoutConstraints
*constr
= GetConstraints();
1929 constr
->left
.SetDone(false);
1930 constr
->top
.SetDone(false);
1931 constr
->right
.SetDone(false);
1932 constr
->bottom
.SetDone(false);
1933 constr
->width
.SetDone(false);
1934 constr
->height
.SetDone(false);
1935 constr
->centreX
.SetDone(false);
1936 constr
->centreY
.SetDone(false);
1939 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1942 wxWindow
*win
= node
->GetData();
1943 if ( !win
->IsTopLevel() )
1944 win
->ResetConstraints();
1945 node
= node
->GetNext();
1949 // Need to distinguish between setting the 'fake' size for windows and sizers,
1950 // and setting the real values.
1951 void wxWindowBase::SetConstraintSizes(bool recurse
)
1953 wxLayoutConstraints
*constr
= GetConstraints();
1954 if ( constr
&& constr
->AreSatisfied() )
1956 int x
= constr
->left
.GetValue();
1957 int y
= constr
->top
.GetValue();
1958 int w
= constr
->width
.GetValue();
1959 int h
= constr
->height
.GetValue();
1961 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1962 (constr
->height
.GetRelationship() != wxAsIs
) )
1964 SetSize(x
, y
, w
, h
);
1968 // If we don't want to resize this window, just move it...
1974 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1975 GetClassInfo()->GetClassName(),
1981 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1984 wxWindow
*win
= node
->GetData();
1985 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1986 win
->SetConstraintSizes();
1987 node
= node
->GetNext();
1992 // Only set the size/position of the constraint (if any)
1993 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1995 wxLayoutConstraints
*constr
= GetConstraints();
1998 if ( x
!= wxDefaultCoord
)
2000 constr
->left
.SetValue(x
);
2001 constr
->left
.SetDone(true);
2003 if ( y
!= wxDefaultCoord
)
2005 constr
->top
.SetValue(y
);
2006 constr
->top
.SetDone(true);
2008 if ( w
!= wxDefaultCoord
)
2010 constr
->width
.SetValue(w
);
2011 constr
->width
.SetDone(true);
2013 if ( h
!= wxDefaultCoord
)
2015 constr
->height
.SetValue(h
);
2016 constr
->height
.SetDone(true);
2021 void wxWindowBase::MoveConstraint(int x
, int y
)
2023 wxLayoutConstraints
*constr
= GetConstraints();
2026 if ( x
!= wxDefaultCoord
)
2028 constr
->left
.SetValue(x
);
2029 constr
->left
.SetDone(true);
2031 if ( y
!= wxDefaultCoord
)
2033 constr
->top
.SetValue(y
);
2034 constr
->top
.SetDone(true);
2039 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
2041 wxLayoutConstraints
*constr
= GetConstraints();
2044 *w
= constr
->width
.GetValue();
2045 *h
= constr
->height
.GetValue();
2051 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
2053 wxLayoutConstraints
*constr
= GetConstraints();
2056 *w
= constr
->width
.GetValue();
2057 *h
= constr
->height
.GetValue();
2060 GetClientSize(w
, h
);
2063 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
2065 wxLayoutConstraints
*constr
= GetConstraints();
2068 *x
= constr
->left
.GetValue();
2069 *y
= constr
->top
.GetValue();
2075 #endif // wxUSE_CONSTRAINTS
2077 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
2079 // don't do it for the dialogs/frames - they float independently of their
2081 if ( !IsTopLevel() )
2083 wxWindow
*parent
= GetParent();
2084 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
2086 wxPoint
pt(parent
->GetClientAreaOrigin());
2093 // ----------------------------------------------------------------------------
2094 // do Update UI processing for child controls
2095 // ----------------------------------------------------------------------------
2097 void wxWindowBase::UpdateWindowUI(long flags
)
2099 wxUpdateUIEvent
event(GetId());
2100 event
.SetEventObject(this);
2102 if ( GetEventHandler()->ProcessEvent(event
) )
2104 DoUpdateWindowUI(event
);
2107 if (flags
& wxUPDATE_UI_RECURSE
)
2109 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2112 wxWindow
* child
= (wxWindow
*) node
->GetData();
2113 child
->UpdateWindowUI(flags
);
2114 node
= node
->GetNext();
2119 // do the window-specific processing after processing the update event
2120 // TODO: take specific knowledge out of this function and
2121 // put in each control's base class. Unfortunately we don't
2122 // yet have base implementation files for wxCheckBox and wxRadioButton.
2123 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
2125 if ( event
.GetSetEnabled() )
2126 Enable(event
.GetEnabled());
2129 if ( event
.GetSetText() )
2131 wxControl
*control
= wxDynamicCastThis(wxControl
);
2134 if ( event
.GetText() != control
->GetLabel() )
2135 control
->SetLabel(event
.GetText());
2138 #endif // wxUSE_CONTROLS
2140 if ( event
.GetSetChecked() )
2143 wxCheckBox
*checkbox
= wxDynamicCastThis(wxCheckBox
);
2146 checkbox
->SetValue(event
.GetChecked());
2148 #endif // wxUSE_CHECKBOX
2151 wxRadioButton
*radiobtn
= wxDynamicCastThis(wxRadioButton
);
2154 radiobtn
->SetValue(event
.GetChecked());
2156 #endif // wxUSE_RADIOBTN
2161 // call internal idle recursively
2162 // may be obsolete (wait until OnIdle scheme stabilises)
2163 void wxWindowBase::ProcessInternalIdle()
2167 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2170 wxWindow
*child
= node
->GetData();
2171 child
->ProcessInternalIdle();
2172 node
= node
->GetNext();
2177 // ----------------------------------------------------------------------------
2178 // dialog units translations
2179 // ----------------------------------------------------------------------------
2181 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
2183 int charWidth
= GetCharWidth();
2184 int charHeight
= GetCharHeight();
2185 wxPoint pt2
= wxDefaultPosition
;
2186 if (pt
.x
!= wxDefaultCoord
)
2187 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
2188 if (pt
.y
!= wxDefaultCoord
)
2189 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2194 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
2196 int charWidth
= GetCharWidth();
2197 int charHeight
= GetCharHeight();
2198 wxPoint pt2
= wxDefaultPosition
;
2199 if (pt
.x
!= wxDefaultCoord
)
2200 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
2201 if (pt
.y
!= wxDefaultCoord
)
2202 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2207 // ----------------------------------------------------------------------------
2209 // ----------------------------------------------------------------------------
2211 // propagate the colour change event to the subwindows
2212 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2214 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2217 // Only propagate to non-top-level windows
2218 wxWindow
*win
= node
->GetData();
2219 if ( !win
->IsTopLevel() )
2221 wxSysColourChangedEvent event2
;
2222 event
.SetEventObject(win
);
2223 win
->GetEventHandler()->ProcessEvent(event2
);
2226 node
= node
->GetNext();
2232 // the default action is to populate dialog with data when it's created,
2233 // and nudge the UI into displaying itself correctly in case
2234 // we've turned the wxUpdateUIEvents frequency down low.
2235 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2237 TransferDataToWindow();
2239 // Update the UI at this point
2240 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2243 // process Ctrl-Alt-mclick
2244 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2247 if ( event
.ControlDown() && event
.AltDown() )
2249 // don't translate these strings
2252 #ifdef __WXUNIVERSAL__
2254 #endif // __WXUNIVERSAL__
2256 switch ( wxGetOsVersion() )
2258 case wxMOTIF_X
: port
+= _T("Motif"); break;
2260 case wxMAC_DARWIN
: port
+= _T("Mac"); break;
2261 case wxBEOS
: port
+= _T("BeOS"); break;
2265 case wxGTK_BEOS
: port
+= _T("GTK"); break;
2271 case wxWIN386
: port
+= _T("MS Windows"); break;
2275 case wxMGL_OS2
: port
+= _T("MGL"); break;
2277 case wxOS2_PM
: port
+= _T("OS/2"); break;
2278 case wxPALMOS
: port
+= _T("Palm OS"); break;
2279 case wxWINDOWS_CE
: port
+= _T("Windows CE (generic)"); break;
2280 case wxWINDOWS_POCKETPC
: port
+= _T("Windows CE PocketPC"); break;
2281 case wxWINDOWS_SMARTPHONE
: port
+= _T("Windows CE Smartphone"); break;
2282 default: port
+= _T("unknown"); break;
2285 wxMessageBox(wxString::Format(
2287 " wxWidgets Library (%s port)\nVersion %u.%u.%u%s%s, compiled at %s %s\n Copyright (c) 1995-2005 wxWidgets team"
2306 _T("wxWidgets information"),
2307 wxICON_INFORMATION
| wxOK
,
2311 #endif // wxUSE_MSGDLG
2317 // ----------------------------------------------------------------------------
2319 // ----------------------------------------------------------------------------
2321 #if wxUSE_ACCESSIBILITY
2322 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2324 if (m_accessible
&& (accessible
!= m_accessible
))
2325 delete m_accessible
;
2326 m_accessible
= accessible
;
2328 m_accessible
->SetWindow((wxWindow
*) this);
2331 // Returns the accessible object, creating if necessary.
2332 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2335 m_accessible
= CreateAccessible();
2336 return m_accessible
;
2339 // Override to create a specific accessible object.
2340 wxAccessible
* wxWindowBase::CreateAccessible()
2342 return new wxWindowAccessible((wxWindow
*) this);
2347 // ----------------------------------------------------------------------------
2348 // list classes implementation
2349 // ----------------------------------------------------------------------------
2353 #include <wx/listimpl.cpp>
2354 WX_DEFINE_LIST(wxWindowList
);
2358 void wxWindowListNode::DeleteData()
2360 delete (wxWindow
*)GetData();
2365 // ----------------------------------------------------------------------------
2367 // ----------------------------------------------------------------------------
2369 wxBorder
wxWindowBase::GetBorder(long flags
) const
2371 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2372 if ( border
== wxBORDER_DEFAULT
)
2374 border
= GetDefaultBorder();
2380 wxBorder
wxWindowBase::GetDefaultBorder() const
2382 return wxBORDER_NONE
;
2385 // ----------------------------------------------------------------------------
2387 // ----------------------------------------------------------------------------
2389 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2391 // here we just check if the point is inside the window or not
2393 // check the top and left border first
2394 bool outside
= x
< 0 || y
< 0;
2397 // check the right and bottom borders too
2398 wxSize size
= GetSize();
2399 outside
= x
>= size
.x
|| y
>= size
.y
;
2402 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2405 // ----------------------------------------------------------------------------
2407 // ----------------------------------------------------------------------------
2409 struct WXDLLEXPORT wxWindowNext
2413 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2415 void wxWindowBase::CaptureMouse()
2417 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this);
2419 wxWindow
*winOld
= GetCapture();
2422 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2425 wxWindowNext
*item
= new wxWindowNext
;
2427 item
->next
= ms_winCaptureNext
;
2428 ms_winCaptureNext
= item
;
2430 //else: no mouse capture to save
2435 void wxWindowBase::ReleaseMouse()
2437 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this);
2439 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2443 if ( ms_winCaptureNext
)
2445 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2447 wxWindowNext
*item
= ms_winCaptureNext
;
2448 ms_winCaptureNext
= item
->next
;
2451 //else: stack is empty, no previous capture
2453 wxLogTrace(_T("mousecapture"),
2454 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2461 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2462 int WXUNUSED(modifiers
),
2463 int WXUNUSED(keycode
))
2469 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2475 #endif // wxUSE_HOTKEY
2477 void wxWindowBase::SendDestroyEvent()
2479 wxWindowDestroyEvent event
;
2480 event
.SetEventObject(this);
2481 event
.SetId(GetId());
2482 GetEventHandler()->ProcessEvent(event
);
2485 // ----------------------------------------------------------------------------
2487 // ----------------------------------------------------------------------------
2489 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2491 #if wxUSE_VALIDATORS
2492 // Can only use the validator of the window which
2493 // is receiving the event
2494 if ( event
.GetEventObject() == this )
2496 wxValidator
*validator
= GetValidator();
2497 if ( validator
&& validator
->ProcessEvent(event
) )
2502 #endif // wxUSE_VALIDATORS
2507 bool wxWindowBase::TryParent(wxEvent
& event
)
2509 // carry on up the parent-child hierarchy if the propgation count hasn't
2511 if ( event
.ShouldPropagate() )
2513 // honour the requests to stop propagation at this window: this is
2514 // used by the dialogs, for example, to prevent processing the events
2515 // from the dialog controls in the parent frame which rarely, if ever,
2517 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2519 wxWindow
*parent
= GetParent();
2520 if ( parent
&& !parent
->IsBeingDeleted() )
2522 wxPropagateOnce
propagateOnce(event
);
2524 return parent
->GetEventHandler()->ProcessEvent(event
);
2529 return wxEvtHandler::TryParent(event
);
2532 // ----------------------------------------------------------------------------
2533 // keyboard navigation
2534 // ----------------------------------------------------------------------------
2536 // Navigates in the specified direction.
2537 bool wxWindowBase::Navigate(int flags
)
2539 wxNavigationKeyEvent eventNav
;
2540 eventNav
.SetFlags(flags
);
2541 eventNav
.SetEventObject(this);
2542 if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav
) )
2549 void wxWindowBase::DoMoveInTabOrder(wxWindow
*win
, MoveKind move
)
2551 // check that we're not a top level window
2552 wxCHECK_RET( GetParent(),
2553 _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
2555 // detect the special case when we have nothing to do anyhow and when the
2556 // code below wouldn't work
2560 // find the target window in the siblings list
2561 wxWindowList
& siblings
= GetParent()->GetChildren();
2562 wxWindowList::compatibility_iterator i
= siblings
.Find(win
);
2563 wxCHECK_RET( i
, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") );
2565 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
2566 // can't just move the node around
2567 wxWindow
*self
= (wxWindow
*)this;
2568 siblings
.DeleteObject(self
);
2569 if ( move
== MoveAfter
)
2576 siblings
.Insert(i
, self
);
2578 else // MoveAfter and win was the last sibling
2580 siblings
.Append(self
);
2584 // ----------------------------------------------------------------------------
2586 // ----------------------------------------------------------------------------
2588 /*static*/ wxWindow
* wxWindowBase::FindFocus()
2590 wxWindowBase
*win
= DoFindFocus();
2591 return win
? win
->GetMainWindowOfCompositeControl() : NULL
;
2594 // ----------------------------------------------------------------------------
2596 // ----------------------------------------------------------------------------
2598 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2600 while ( win
&& !win
->IsTopLevel() )
2601 win
= win
->GetParent();
2606 #if wxUSE_ACCESSIBILITY
2607 // ----------------------------------------------------------------------------
2608 // accessible object for windows
2609 // ----------------------------------------------------------------------------
2611 // Can return either a child object, or an integer
2612 // representing the child element, starting from 1.
2613 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2615 wxASSERT( GetWindow() != NULL
);
2619 return wxACC_NOT_IMPLEMENTED
;
2622 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2623 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2625 wxASSERT( GetWindow() != NULL
);
2629 wxWindow
* win
= NULL
;
2636 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2638 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2645 rect
= win
->GetRect();
2646 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2647 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2651 return wxACC_NOT_IMPLEMENTED
;
2654 // Navigates from fromId to toId/toObject.
2655 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2656 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2658 wxASSERT( GetWindow() != NULL
);
2664 case wxNAVDIR_FIRSTCHILD
:
2666 if (GetWindow()->GetChildren().GetCount() == 0)
2668 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2669 *toObject
= childWindow
->GetOrCreateAccessible();
2673 case wxNAVDIR_LASTCHILD
:
2675 if (GetWindow()->GetChildren().GetCount() == 0)
2677 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2678 *toObject
= childWindow
->GetOrCreateAccessible();
2682 case wxNAVDIR_RIGHT
:
2686 wxWindowList::compatibility_iterator node
=
2687 wxWindowList::compatibility_iterator();
2690 // Can't navigate to sibling of this window
2691 // if we're a top-level window.
2692 if (!GetWindow()->GetParent())
2693 return wxACC_NOT_IMPLEMENTED
;
2695 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2699 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2700 node
= GetWindow()->GetChildren().Item(fromId
-1);
2703 if (node
&& node
->GetNext())
2705 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2706 *toObject
= nextWindow
->GetOrCreateAccessible();
2714 case wxNAVDIR_PREVIOUS
:
2716 wxWindowList::compatibility_iterator node
=
2717 wxWindowList::compatibility_iterator();
2720 // Can't navigate to sibling of this window
2721 // if we're a top-level window.
2722 if (!GetWindow()->GetParent())
2723 return wxACC_NOT_IMPLEMENTED
;
2725 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2729 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2730 node
= GetWindow()->GetChildren().Item(fromId
-1);
2733 if (node
&& node
->GetPrevious())
2735 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2736 *toObject
= previousWindow
->GetOrCreateAccessible();
2744 return wxACC_NOT_IMPLEMENTED
;
2747 // Gets the name of the specified object.
2748 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2750 wxASSERT( GetWindow() != NULL
);
2756 // If a child, leave wxWidgets to call the function on the actual
2759 return wxACC_NOT_IMPLEMENTED
;
2761 // This will eventually be replaced by specialised
2762 // accessible classes, one for each kind of wxWidgets
2763 // control or window.
2765 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2766 title
= ((wxButton
*) GetWindow())->GetLabel();
2769 title
= GetWindow()->GetName();
2777 return wxACC_NOT_IMPLEMENTED
;
2780 // Gets the number of children.
2781 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2783 wxASSERT( GetWindow() != NULL
);
2787 *childId
= (int) GetWindow()->GetChildren().GetCount();
2791 // Gets the specified child (starting from 1).
2792 // If *child is NULL and return value is wxACC_OK,
2793 // this means that the child is a simple element and
2794 // not an accessible object.
2795 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2797 wxASSERT( GetWindow() != NULL
);
2807 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2810 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2811 *child
= childWindow
->GetOrCreateAccessible();
2818 // Gets the parent, or NULL.
2819 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2821 wxASSERT( GetWindow() != NULL
);
2825 wxWindow
* parentWindow
= GetWindow()->GetParent();
2833 *parent
= parentWindow
->GetOrCreateAccessible();
2841 // Performs the default action. childId is 0 (the action for this object)
2842 // or > 0 (the action for a child).
2843 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2844 // window (e.g. an edit control).
2845 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
2847 wxASSERT( GetWindow() != NULL
);
2851 return wxACC_NOT_IMPLEMENTED
;
2854 // Gets the default action for this object (0) or > 0 (the action for a child).
2855 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2856 // string if there is no action.
2857 // The retrieved string describes the action that is performed on an object,
2858 // not what the object does as a result. For example, a toolbar button that prints
2859 // a document has a default action of "Press" rather than "Prints the current document."
2860 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
2862 wxASSERT( GetWindow() != NULL
);
2866 return wxACC_NOT_IMPLEMENTED
;
2869 // Returns the description for this object or a child.
2870 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
2872 wxASSERT( GetWindow() != NULL
);
2876 wxString
ht(GetWindow()->GetHelpText());
2882 return wxACC_NOT_IMPLEMENTED
;
2885 // Returns help text for this object or a child, similar to tooltip text.
2886 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
2888 wxASSERT( GetWindow() != NULL
);
2892 wxString
ht(GetWindow()->GetHelpText());
2898 return wxACC_NOT_IMPLEMENTED
;
2901 // Returns the keyboard shortcut for this object or child.
2902 // Return e.g. ALT+K
2903 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
2905 wxASSERT( GetWindow() != NULL
);
2909 return wxACC_NOT_IMPLEMENTED
;
2912 // Returns a role constant.
2913 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
2915 wxASSERT( GetWindow() != NULL
);
2919 // If a child, leave wxWidgets to call the function on the actual
2922 return wxACC_NOT_IMPLEMENTED
;
2924 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2925 return wxACC_NOT_IMPLEMENTED
;
2927 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2928 return wxACC_NOT_IMPLEMENTED
;
2931 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2932 return wxACC_NOT_IMPLEMENTED
;
2935 //*role = wxROLE_SYSTEM_CLIENT;
2936 *role
= wxROLE_SYSTEM_CLIENT
;
2940 return wxACC_NOT_IMPLEMENTED
;
2944 // Returns a state constant.
2945 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
2947 wxASSERT( GetWindow() != NULL
);
2951 // If a child, leave wxWidgets to call the function on the actual
2954 return wxACC_NOT_IMPLEMENTED
;
2956 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2957 return wxACC_NOT_IMPLEMENTED
;
2960 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2961 return wxACC_NOT_IMPLEMENTED
;
2964 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2965 return wxACC_NOT_IMPLEMENTED
;
2972 return wxACC_NOT_IMPLEMENTED
;
2976 // Returns a localized string representing the value for the object
2978 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
2980 wxASSERT( GetWindow() != NULL
);
2984 return wxACC_NOT_IMPLEMENTED
;
2987 // Selects the object or child.
2988 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
2990 wxASSERT( GetWindow() != NULL
);
2994 return wxACC_NOT_IMPLEMENTED
;
2997 // Gets the window with the keyboard focus.
2998 // If childId is 0 and child is NULL, no object in
2999 // this subhierarchy has the focus.
3000 // If this object has the focus, child should be 'this'.
3001 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
3003 wxASSERT( GetWindow() != NULL
);
3007 return wxACC_NOT_IMPLEMENTED
;
3010 // Gets a variant representing the selected children
3012 // Acceptable values:
3013 // - a null variant (IsNull() returns true)
3014 // - a list variant (GetType() == wxT("list")
3015 // - an integer representing the selected child element,
3016 // or 0 if this object is selected (GetType() == wxT("long")
3017 // - a "void*" pointer to a wxAccessible child object
3018 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
3020 wxASSERT( GetWindow() != NULL
);
3024 return wxACC_NOT_IMPLEMENTED
;
3027 #endif // wxUSE_ACCESSIBILITY