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/dcclient.h"
50 #if defined(__WXMAC__) && wxUSE_SCROLLBAR
51 #include "wx/scrolbar.h"
55 #include "wx/layout.h"
56 #endif // wxUSE_CONSTRAINTS
60 #if wxUSE_DRAG_AND_DROP
62 #endif // wxUSE_DRAG_AND_DROP
64 #if wxUSE_ACCESSIBILITY
65 #include "wx/access.h"
69 #include "wx/cshelp.h"
73 #include "wx/tooltip.h"
74 #endif // wxUSE_TOOLTIPS
81 #include "wx/display.h"
84 #if wxUSE_SYSTEM_OPTIONS
85 #include "wx/sysopt.h"
88 // ----------------------------------------------------------------------------
90 // ----------------------------------------------------------------------------
92 #if defined(__WXPALMOS__)
93 int wxWindowBase::ms_lastControlId
= 32767;
94 #elif defined(__WXPM__)
95 int wxWindowBase::ms_lastControlId
= 2000;
97 int wxWindowBase::ms_lastControlId
= -200;
100 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
102 // ----------------------------------------------------------------------------
104 // ----------------------------------------------------------------------------
106 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
107 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
108 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
109 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick
)
112 EVT_HELP(wxID_ANY
, wxWindowBase::OnHelp
)
117 // ============================================================================
118 // implementation of the common functionality of the wxWindow class
119 // ============================================================================
121 // ----------------------------------------------------------------------------
123 // ----------------------------------------------------------------------------
125 // the default initialization
126 wxWindowBase::wxWindowBase()
128 // no window yet, no parent nor children
129 m_parent
= (wxWindow
*)NULL
;
130 m_windowId
= wxID_ANY
;
132 // no constraints on the minimal window size
134 m_maxWidth
= wxDefaultCoord
;
136 m_maxHeight
= wxDefaultCoord
;
138 // invalidiated cache value
139 m_bestSizeCache
= wxDefaultSize
;
141 // window are created enabled and visible by default
145 // the default event handler is just this window
146 m_eventHandler
= this;
150 m_windowValidator
= (wxValidator
*) NULL
;
151 #endif // wxUSE_VALIDATORS
153 // the colours/fonts are default for now, so leave m_font,
154 // m_backgroundColour and m_foregroundColour uninitialized and set those
160 m_inheritFont
= false;
166 m_backgroundStyle
= wxBG_STYLE_SYSTEM
;
168 #if wxUSE_CONSTRAINTS
169 // no constraints whatsoever
170 m_constraints
= (wxLayoutConstraints
*) NULL
;
171 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
172 #endif // wxUSE_CONSTRAINTS
174 m_windowSizer
= (wxSizer
*) NULL
;
175 m_containingSizer
= (wxSizer
*) NULL
;
176 m_autoLayout
= false;
178 #if wxUSE_DRAG_AND_DROP
179 m_dropTarget
= (wxDropTarget
*)NULL
;
180 #endif // wxUSE_DRAG_AND_DROP
183 m_tooltip
= (wxToolTip
*)NULL
;
184 #endif // wxUSE_TOOLTIPS
187 m_caret
= (wxCaret
*)NULL
;
188 #endif // wxUSE_CARET
191 m_hasCustomPalette
= false;
192 #endif // wxUSE_PALETTE
194 #if wxUSE_ACCESSIBILITY
198 m_virtualSize
= wxDefaultSize
;
201 m_maxVirtualWidth
= wxDefaultCoord
;
203 m_maxVirtualHeight
= wxDefaultCoord
;
205 m_windowVariant
= wxWINDOW_VARIANT_NORMAL
;
206 #if wxUSE_SYSTEM_OPTIONS
207 if ( wxSystemOptions::HasOption(wxWINDOW_DEFAULT_VARIANT
) )
209 m_windowVariant
= (wxWindowVariant
) wxSystemOptions::GetOptionInt( wxWINDOW_DEFAULT_VARIANT
) ;
213 // Whether we're using the current theme for this window (wxGTK only for now)
214 m_themeEnabled
= false;
216 // VZ: this one shouldn't exist...
217 m_isBeingDeleted
= false;
219 // Reserved for future use
220 m_windowReserved
= NULL
;
223 // common part of window creation process
224 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
226 const wxPoint
& WXUNUSED(pos
),
227 const wxSize
& WXUNUSED(size
),
229 const wxValidator
& wxVALIDATOR_PARAM(validator
),
230 const wxString
& name
)
233 // wxGTK doesn't allow to create controls with static box as the parent so
234 // this will result in a crash when the program is ported to wxGTK so warn
237 // if you get this assert, the correct solution is to create the controls
238 // as siblings of the static box
239 wxASSERT_MSG( !parent
|| !wxDynamicCast(parent
, wxStaticBox
),
240 _T("wxStaticBox can't be used as a window parent!") );
241 #endif // wxUSE_STATBOX
243 // ids are limited to 16 bits under MSW so if you care about portability,
244 // it's not a good idea to use ids out of this range (and negative ids are
245 // reserved for wxWidgets own usage)
246 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767),
247 _T("invalid id value") );
249 // generate a new id if the user doesn't care about it
250 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
253 SetWindowStyleFlag(style
);
257 SetValidator(validator
);
258 #endif // wxUSE_VALIDATORS
260 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
261 // have it too - like this it's possible to set it only in the top level
262 // dialog/frame and all children will inherit it by defult
263 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
265 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
271 // ----------------------------------------------------------------------------
273 // ----------------------------------------------------------------------------
276 wxWindowBase::~wxWindowBase()
278 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
280 // FIXME if these 2 cases result from programming errors in the user code
281 // we should probably assert here instead of silently fixing them
283 // Just in case the window has been Closed, but we're then deleting
284 // immediately: don't leave dangling pointers.
285 wxPendingDelete
.DeleteObject(this);
287 // Just in case we've loaded a top-level window via LoadNativeDialog but
288 // we weren't a dialog class
289 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
291 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
293 // reset the dangling pointer our parent window may keep to us
296 if ( m_parent
->GetDefaultItem() == this )
298 m_parent
->SetDefaultItem(NULL
);
301 m_parent
->RemoveChild(this);
306 #endif // wxUSE_CARET
309 delete m_windowValidator
;
310 #endif // wxUSE_VALIDATORS
312 #if wxUSE_CONSTRAINTS
313 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
314 // at deleted windows as they delete themselves.
315 DeleteRelatedConstraints();
319 // This removes any dangling pointers to this window in other windows'
320 // constraintsInvolvedIn lists.
321 UnsetConstraints(m_constraints
);
322 delete m_constraints
;
323 m_constraints
= NULL
;
325 #endif // wxUSE_CONSTRAINTS
327 if ( m_containingSizer
)
328 m_containingSizer
->Detach( (wxWindow
*)this );
330 delete m_windowSizer
;
332 #if wxUSE_DRAG_AND_DROP
334 #endif // wxUSE_DRAG_AND_DROP
338 #endif // wxUSE_TOOLTIPS
340 #if wxUSE_ACCESSIBILITY
345 bool wxWindowBase::Destroy()
352 bool wxWindowBase::Close(bool force
)
354 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
355 event
.SetEventObject(this);
356 event
.SetCanVeto(!force
);
358 // return false if window wasn't closed because the application vetoed the
360 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
363 bool wxWindowBase::DestroyChildren()
365 wxWindowList::compatibility_iterator node
;
368 // we iterate until the list becomes empty
369 node
= GetChildren().GetFirst();
373 wxWindow
*child
= node
->GetData();
375 // note that we really want to call delete and not ->Destroy() here
376 // because we want to delete the child immediately, before we are
377 // deleted, and delayed deletion would result in problems as our (top
378 // level) child could outlive its parent
381 wxASSERT_MSG( !GetChildren().Find(child
),
382 wxT("child didn't remove itself using RemoveChild()") );
388 // ----------------------------------------------------------------------------
389 // size/position related methods
390 // ----------------------------------------------------------------------------
392 // centre the window with respect to its parent in either (or both) directions
393 void wxWindowBase::Centre(int direction
)
395 // the position/size of the parent window or of the entire screen
397 int widthParent
, heightParent
;
399 wxWindow
*parent
= NULL
;
400 wxTopLevelWindow
*winTop
= NULL
;
402 if ( !(direction
& wxCENTRE_ON_SCREEN
) )
404 // find the parent to centre this window on: it should be the
405 // immediate parent for the controls but the top level parent for the
406 // top level windows (like dialogs)
407 parent
= GetParent();
410 while ( parent
&& !parent
->IsTopLevel() )
412 parent
= parent
->GetParent();
416 // there is no wxTopLevelWindow under wxMotif yet
418 // we shouldn't center the dialog on the iconized window: under
419 // Windows, for example, this places it completely off the screen
422 winTop
= wxDynamicCast(parent
, wxTopLevelWindow
);
423 if ( winTop
&& winTop
->IsIconized() )
429 #endif // __WXMOTIF__
431 // did we find the parent?
435 direction
|= wxCENTRE_ON_SCREEN
;
439 if ( direction
& wxCENTRE_ON_SCREEN
)
441 //RN: If we are using wxDisplay we get
442 //the dimensions of the monitor the window is on,
443 //otherwise we get the dimensions of the primary monitor
444 //FIXME: wxDisplay::GetFromWindow only implemented on MSW
445 #if wxUSE_DISPLAY && defined(__WXMSW__)
446 int nDisplay
= wxDisplay::GetFromWindow((wxWindow
*)this);
447 if(nDisplay
!= wxNOT_FOUND
)
449 wxDisplay
windowDisplay(nDisplay
);
450 wxRect displayRect
= windowDisplay
.GetGeometry();
451 widthParent
= displayRect
.width
;
452 heightParent
= displayRect
.height
;
456 // centre with respect to the whole screen
457 wxDisplaySize(&widthParent
, &heightParent
);
464 winTop
->GetRectForTopLevelChildren(&posParent
.x
, &posParent
.y
, &widthParent
, &heightParent
);
467 // centre on the parent
468 parent
->GetSize(&widthParent
, &heightParent
);
470 // adjust to the parents position
471 posParent
= parent
->GetPosition();
476 // centre inside the parents client rectangle
477 parent
->GetClientSize(&widthParent
, &heightParent
);
482 GetSize(&width
, &height
);
484 int xNew
= wxDefaultCoord
,
485 yNew
= wxDefaultCoord
;
487 if ( direction
& wxHORIZONTAL
)
488 xNew
= (widthParent
- width
)/2;
490 if ( direction
& wxVERTICAL
)
491 yNew
= (heightParent
- height
)/2;
496 // FIXME: This needs to get the client display rect of the display
497 // the window is (via wxDisplay::GetFromWindow).
499 // Base size of the visible dimensions of the display
500 // to take into account the taskbar. And the Mac menu bar at top.
501 wxRect clientrect
= wxGetClientDisplayRect();
503 // NB: in wxMSW, negative position may not neccessary mean "out of screen",
504 // but it may mean that the window is placed on other than the main
505 // display. Therefore we only make sure centered window is on the main display
506 // if the parent is at least partially present here.
507 if (posParent
.x
+ widthParent
>= 0) // if parent is (partially) on the main display
509 if (xNew
< clientrect
.GetLeft())
510 xNew
= clientrect
.GetLeft();
511 else if (xNew
+ width
> clientrect
.GetRight())
512 xNew
= clientrect
.GetRight() - width
;
514 if (posParent
.y
+ heightParent
>= 0) // if parent is (partially) on the main display
516 if (yNew
+ height
> clientrect
.GetBottom())
517 yNew
= clientrect
.GetBottom() - height
;
519 // Make certain that the title bar is initially visible
520 // always, even if this would push the bottom of the
521 // dialog off the visible area of the display
522 if (yNew
< clientrect
.GetTop())
523 yNew
= clientrect
.GetTop();
526 // move the window to this position (keeping the old size but using
527 // SetSize() and not Move() to allow xNew and/or yNew to be wxDefaultCoord)
528 SetSize(xNew
, yNew
, width
, height
, wxSIZE_ALLOW_MINUS_ONE
);
531 // fits the window around the children
532 void wxWindowBase::Fit()
534 if ( GetChildren().GetCount() > 0 )
536 SetSize(GetBestSize());
538 //else: do nothing if we have no children
541 // fits virtual size (ie. scrolled area etc.) around children
542 void wxWindowBase::FitInside()
544 if ( GetChildren().GetCount() > 0 )
546 SetVirtualSize( GetBestVirtualSize() );
550 // On Mac, scrollbars are explicitly children.
552 static bool wxHasRealChildren(const wxWindowBase
* win
)
554 int realChildCount
= 0;
556 for ( wxWindowList::compatibility_iterator node
= win
->GetChildren().GetFirst();
558 node
= node
->GetNext() )
560 wxWindow
*win
= node
->GetData();
561 if ( !win
->IsTopLevel() && win
->IsShown() && !win
->IsKindOf(CLASSINFO(wxScrollBar
)))
564 return (realChildCount
> 0);
568 void wxWindowBase::InvalidateBestSize()
570 m_bestSizeCache
= wxDefaultSize
;
572 // parent's best size calculation may depend on its children's
573 // best sizes, so let's invalidate it as well to be safe:
575 m_parent
->InvalidateBestSize();
578 // return the size best suited for the current window
579 wxSize
wxWindowBase::DoGetBestSize() const
585 best
= m_windowSizer
->GetMinSize();
587 #if wxUSE_CONSTRAINTS
588 else if ( m_constraints
)
590 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
592 // our minimal acceptable size is such that all our windows fit inside
596 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
598 node
= node
->GetNext() )
600 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
603 // it's not normal that we have an unconstrained child, but
604 // what can we do about it?
608 int x
= c
->right
.GetValue(),
609 y
= c
->bottom
.GetValue();
617 // TODO: we must calculate the overlaps somehow, otherwise we
618 // will never return a size bigger than the current one :-(
621 best
= wxSize(maxX
, maxY
);
623 #endif // wxUSE_CONSTRAINTS
624 else if ( !GetChildren().empty()
626 && wxHasRealChildren(this)
630 // our minimal acceptable size is such that all our visible child windows fit inside
634 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
636 node
= node
->GetNext() )
638 wxWindow
*win
= node
->GetData();
639 if ( win
->IsTopLevel() || ( ! win
->IsShown() )
641 || wxDynamicCast(win
, wxStatusBar
)
642 #endif // wxUSE_STATUSBAR
645 // dialogs and frames lie in different top level windows -
646 // don't deal with them here; as for the status bars, they
647 // don't lie in the client area at all
652 win
->GetPosition(&wx
, &wy
);
654 // if the window hadn't been positioned yet, assume that it is in
656 if ( wx
== wxDefaultCoord
)
658 if ( wy
== wxDefaultCoord
)
661 win
->GetSize(&ww
, &wh
);
662 if ( wx
+ ww
> maxX
)
664 if ( wy
+ wh
> maxY
)
668 // for compatibility with the old versions and because it really looks
669 // slightly more pretty like this, add a pad
673 best
= wxSize(maxX
, maxY
);
675 else // ! has children
677 // for a generic window there is no natural best size so, if the
678 // minimal size is not set, use the current size but take care to
679 // remember it as minimal size for the next time because our best size
680 // should be constant: otherwise we could get into a situation when the
681 // window is initially at some size, then expanded to a larger size and
682 // then, when the containing window is shrunk back (because our initial
683 // best size had been used for computing the parent min size), we can't
684 // be shrunk back any more because our best size is now bigger
685 if ( !GetMinSize().IsFullySpecified() )
686 wxConstCast(this, wxWindowBase
)->SetMinSize(GetSize());
688 // return as-is, unadjusted by the client size difference.
692 // Add any difference between size and client size
693 wxSize diff
= GetSize() - GetClientSize();
694 best
.x
+= wxMax(0, diff
.x
);
695 best
.y
+= wxMax(0, diff
.y
);
701 wxSize
wxWindowBase::GetBestFittingSize() const
703 // merge the best size with the min size, giving priority to the min size
704 wxSize min
= GetMinSize();
705 if (min
.x
== wxDefaultCoord
|| min
.y
== wxDefaultCoord
)
707 wxSize best
= GetBestSize();
708 if (min
.x
== wxDefaultCoord
) min
.x
= best
.x
;
709 if (min
.y
== wxDefaultCoord
) min
.y
= best
.y
;
715 void wxWindowBase::SetBestFittingSize(const wxSize
& size
)
717 // Set the min size to the size passed in. This will usually either be
718 // wxDefaultSize or the size passed to this window's ctor/Create function.
721 // Merge the size with the best size if needed
722 wxSize best
= GetBestFittingSize();
724 // If the current size doesn't match then change it
725 if (GetSize() != best
)
730 // by default the origin is not shifted
731 wxPoint
wxWindowBase::GetClientAreaOrigin() const
736 // set the min/max size of the window
737 void wxWindowBase::DoSetSizeHints(int minW
, int minH
,
739 int WXUNUSED(incW
), int WXUNUSED(incH
))
741 // setting min width greater than max width leads to infinite loops under
742 // X11 and generally doesn't make any sense, so don't allow it
743 wxCHECK_RET( (minW
== wxDefaultCoord
|| maxW
== wxDefaultCoord
|| minW
<= maxW
) &&
744 (minH
== wxDefaultCoord
|| maxH
== wxDefaultCoord
|| minH
<= maxH
),
745 _T("min width/height must be less than max width/height!") );
753 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
755 if ( m_windowVariant
!= variant
)
757 m_windowVariant
= variant
;
759 DoSetWindowVariant(variant
);
763 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
765 // adjust the font height to correspond to our new variant (notice that
766 // we're only called if something really changed)
767 wxFont font
= GetFont();
768 int size
= font
.GetPointSize();
771 case wxWINDOW_VARIANT_NORMAL
:
774 case wxWINDOW_VARIANT_SMALL
:
779 case wxWINDOW_VARIANT_MINI
:
784 case wxWINDOW_VARIANT_LARGE
:
790 wxFAIL_MSG(_T("unexpected window variant"));
794 font
.SetPointSize(size
);
798 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
801 m_minVirtualWidth
= minW
;
802 m_maxVirtualWidth
= maxW
;
803 m_minVirtualHeight
= minH
;
804 m_maxVirtualHeight
= maxH
;
807 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
809 if ( m_minVirtualWidth
!= wxDefaultCoord
&& m_minVirtualWidth
> x
)
810 x
= m_minVirtualWidth
;
811 if ( m_maxVirtualWidth
!= wxDefaultCoord
&& m_maxVirtualWidth
< x
)
812 x
= m_maxVirtualWidth
;
813 if ( m_minVirtualHeight
!= wxDefaultCoord
&& m_minVirtualHeight
> y
)
814 y
= m_minVirtualHeight
;
815 if ( m_maxVirtualHeight
!= wxDefaultCoord
&& m_maxVirtualHeight
< y
)
816 y
= m_maxVirtualHeight
;
818 m_virtualSize
= wxSize(x
, y
);
821 wxSize
wxWindowBase::DoGetVirtualSize() const
823 if ( m_virtualSize
.IsFullySpecified() )
824 return m_virtualSize
;
826 wxSize size
= GetClientSize();
827 if ( m_virtualSize
.x
!= wxDefaultCoord
)
828 size
.x
= m_virtualSize
.x
;
830 if ( m_virtualSize
.y
!= wxDefaultCoord
)
831 size
.y
= m_virtualSize
.y
;
836 // ----------------------------------------------------------------------------
837 // show/hide/enable/disable the window
838 // ----------------------------------------------------------------------------
840 bool wxWindowBase::Show(bool show
)
842 if ( show
!= m_isShown
)
854 bool wxWindowBase::Enable(bool enable
)
856 if ( enable
!= m_isEnabled
)
858 m_isEnabled
= enable
;
867 // ----------------------------------------------------------------------------
869 // ----------------------------------------------------------------------------
871 bool wxWindowBase::IsTopLevel() const
876 // ----------------------------------------------------------------------------
877 // reparenting the window
878 // ----------------------------------------------------------------------------
880 void wxWindowBase::AddChild(wxWindowBase
*child
)
882 wxCHECK_RET( child
, wxT("can't add a NULL child") );
884 // this should never happen and it will lead to a crash later if it does
885 // because RemoveChild() will remove only one node from the children list
886 // and the other(s) one(s) will be left with dangling pointers in them
887 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
889 GetChildren().Append((wxWindow
*)child
);
890 child
->SetParent(this);
893 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
895 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
897 GetChildren().DeleteObject((wxWindow
*)child
);
898 child
->SetParent(NULL
);
901 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
903 wxWindow
*oldParent
= GetParent();
904 if ( newParent
== oldParent
)
910 // unlink this window from the existing parent.
913 oldParent
->RemoveChild(this);
917 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
920 // add it to the new one
923 newParent
->AddChild(this);
927 wxTopLevelWindows
.Append((wxWindow
*)this);
933 // ----------------------------------------------------------------------------
934 // event handler stuff
935 // ----------------------------------------------------------------------------
937 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
939 wxEvtHandler
*handlerOld
= GetEventHandler();
941 handler
->SetNextHandler(handlerOld
);
944 GetEventHandler()->SetPreviousHandler(handler
);
946 SetEventHandler(handler
);
949 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
951 wxEvtHandler
*handlerA
= GetEventHandler();
954 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
955 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
958 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
959 SetEventHandler(handlerB
);
964 handlerA
= (wxEvtHandler
*)NULL
;
971 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
973 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
975 wxEvtHandler
*handlerPrev
= NULL
,
976 *handlerCur
= GetEventHandler();
979 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
981 if ( handlerCur
== handler
)
985 handlerPrev
->SetNextHandler(handlerNext
);
989 SetEventHandler(handlerNext
);
994 handlerNext
->SetPreviousHandler ( handlerPrev
);
997 handler
->SetNextHandler(NULL
);
998 handler
->SetPreviousHandler(NULL
);
1003 handlerPrev
= handlerCur
;
1004 handlerCur
= handlerNext
;
1007 wxFAIL_MSG( _T("where has the event handler gone?") );
1012 // ----------------------------------------------------------------------------
1013 // colours, fonts &c
1014 // ----------------------------------------------------------------------------
1016 void wxWindowBase::InheritAttributes()
1018 const wxWindowBase
* const parent
= GetParent();
1022 // we only inherit attributes which had been explicitly set for the parent
1023 // which ensures that this only happens if the user really wants it and
1024 // not by default which wouldn't make any sense in modern GUIs where the
1025 // controls don't all use the same fonts (nor colours)
1026 if ( parent
->m_inheritFont
&& !m_hasFont
)
1027 SetFont(parent
->GetFont());
1029 // in addition, there is a possibility to explicitly forbid inheriting
1030 // colours at each class level by overriding ShouldInheritColours()
1031 if ( ShouldInheritColours() )
1033 if ( parent
->m_inheritFgCol
&& !m_hasFgCol
)
1034 SetForegroundColour(parent
->GetForegroundColour());
1036 // inheriting (solid) background colour is wrong as it totally breaks
1037 // any kind of themed backgrounds
1039 // instead, the controls should use the same background as their parent
1040 // (ideally by not drawing it at all)
1042 if ( parent
->m_inheritBgCol
&& !m_hasBgCol
)
1043 SetBackgroundColour(parent
->GetBackgroundColour());
1048 /* static */ wxVisualAttributes
1049 wxWindowBase::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
1051 // it is important to return valid values for all attributes from here,
1052 // GetXXX() below rely on this
1053 wxVisualAttributes attrs
;
1054 attrs
.font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
1055 attrs
.colFg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1057 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
1058 // the usual background colour than wxSYS_COLOUR_BTNFACE.
1059 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
1060 // colour on other platforms.
1062 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
1063 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
);
1065 attrs
.colBg
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
1070 wxColour
wxWindowBase::GetBackgroundColour() const
1072 if ( !m_backgroundColour
.Ok() )
1074 wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") );
1076 // get our default background colour
1077 wxColour colBg
= GetDefaultAttributes().colBg
;
1079 // we must return some valid colour to avoid redoing this every time
1080 // and also to avoid surprizing the applications written for older
1081 // wxWidgets versions where GetBackgroundColour() always returned
1082 // something -- so give them something even if it doesn't make sense
1083 // for this window (e.g. it has a themed background)
1085 colBg
= GetClassDefaultAttributes().colBg
;
1090 return m_backgroundColour
;
1093 wxColour
wxWindowBase::GetForegroundColour() const
1095 // logic is the same as above
1096 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
1098 wxASSERT_MSG( !m_hasFgCol
, _T("we have invalid explicit fg colour?") );
1100 wxColour colFg
= GetDefaultAttributes().colFg
;
1103 colFg
= GetClassDefaultAttributes().colFg
;
1108 return m_foregroundColour
;
1111 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
1113 if ( colour
== m_backgroundColour
)
1116 m_hasBgCol
= colour
.Ok();
1117 if ( m_backgroundStyle
!= wxBG_STYLE_CUSTOM
)
1118 m_backgroundStyle
= m_hasBgCol
? wxBG_STYLE_COLOUR
: wxBG_STYLE_SYSTEM
;
1120 m_inheritBgCol
= m_hasBgCol
;
1121 m_backgroundColour
= colour
;
1122 SetThemeEnabled( !m_hasBgCol
&& !m_foregroundColour
.Ok() );
1126 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
1128 if (colour
== m_foregroundColour
)
1131 m_hasFgCol
= colour
.Ok();
1132 m_inheritFgCol
= m_hasFgCol
;
1133 m_foregroundColour
= colour
;
1134 SetThemeEnabled( !m_hasFgCol
&& !m_backgroundColour
.Ok() );
1138 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
1140 // setting an invalid cursor is ok, it means that we don't have any special
1142 if ( m_cursor
== cursor
)
1153 wxFont
wxWindowBase::GetFont() const
1155 // logic is the same as in GetBackgroundColour()
1158 wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") );
1160 wxFont font
= GetDefaultAttributes().font
;
1162 font
= GetClassDefaultAttributes().font
;
1170 bool wxWindowBase::SetFont(const wxFont
& font
)
1172 if ( font
== m_font
)
1179 m_hasFont
= font
.Ok();
1180 m_inheritFont
= m_hasFont
;
1182 InvalidateBestSize();
1189 void wxWindowBase::SetPalette(const wxPalette
& pal
)
1191 m_hasCustomPalette
= true;
1194 // VZ: can anyone explain me what do we do here?
1195 wxWindowDC
d((wxWindow
*) this);
1199 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
1201 wxWindow
*win
= (wxWindow
*)this;
1202 while ( win
&& !win
->HasCustomPalette() )
1204 win
= win
->GetParent();
1210 #endif // wxUSE_PALETTE
1213 void wxWindowBase::SetCaret(wxCaret
*caret
)
1224 wxASSERT_MSG( m_caret
->GetWindow() == this,
1225 wxT("caret should be created associated to this window") );
1228 #endif // wxUSE_CARET
1230 #if wxUSE_VALIDATORS
1231 // ----------------------------------------------------------------------------
1233 // ----------------------------------------------------------------------------
1235 void wxWindowBase::SetValidator(const wxValidator
& validator
)
1237 if ( m_windowValidator
)
1238 delete m_windowValidator
;
1240 m_windowValidator
= (wxValidator
*)validator
.Clone();
1242 if ( m_windowValidator
)
1243 m_windowValidator
->SetWindow(this);
1245 #endif // wxUSE_VALIDATORS
1247 // ----------------------------------------------------------------------------
1248 // update region stuff
1249 // ----------------------------------------------------------------------------
1251 wxRect
wxWindowBase::GetUpdateClientRect() const
1253 wxRegion rgnUpdate
= GetUpdateRegion();
1254 rgnUpdate
.Intersect(GetClientRect());
1255 wxRect rectUpdate
= rgnUpdate
.GetBox();
1256 wxPoint ptOrigin
= GetClientAreaOrigin();
1257 rectUpdate
.x
-= ptOrigin
.x
;
1258 rectUpdate
.y
-= ptOrigin
.y
;
1263 bool wxWindowBase::IsExposed(int x
, int y
) const
1265 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1268 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
1270 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1273 void wxWindowBase::ClearBackground()
1275 // wxGTK uses its own version, no need to add never used code
1277 wxClientDC
dc((wxWindow
*)this);
1278 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1279 dc
.SetBackground(brush
);
1284 // ----------------------------------------------------------------------------
1285 // find child window by id or name
1286 // ----------------------------------------------------------------------------
1288 wxWindow
*wxWindowBase::FindWindow(long id
) const
1290 if ( id
== m_windowId
)
1291 return (wxWindow
*)this;
1293 wxWindowBase
*res
= (wxWindow
*)NULL
;
1294 wxWindowList::compatibility_iterator node
;
1295 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1297 wxWindowBase
*child
= node
->GetData();
1298 res
= child
->FindWindow( id
);
1301 return (wxWindow
*)res
;
1304 wxWindow
*wxWindowBase::FindWindow(const wxString
& name
) const
1306 if ( name
== m_windowName
)
1307 return (wxWindow
*)this;
1309 wxWindowBase
*res
= (wxWindow
*)NULL
;
1310 wxWindowList::compatibility_iterator node
;
1311 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1313 wxWindow
*child
= node
->GetData();
1314 res
= child
->FindWindow(name
);
1317 return (wxWindow
*)res
;
1321 // find any window by id or name or label: If parent is non-NULL, look through
1322 // children for a label or title matching the specified string. If NULL, look
1323 // through all top-level windows.
1325 // to avoid duplicating code we reuse the same helper function but with
1326 // different comparators
1328 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1329 const wxString
& label
, long id
);
1332 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1335 return win
->GetLabel() == label
;
1339 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1342 return win
->GetName() == label
;
1346 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1349 return win
->GetId() == id
;
1352 // recursive helper for the FindWindowByXXX() functions
1354 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1355 const wxString
& label
,
1357 wxFindWindowCmp cmp
)
1361 // see if this is the one we're looking for
1362 if ( (*cmp
)(parent
, label
, id
) )
1363 return (wxWindow
*)parent
;
1365 // It wasn't, so check all its children
1366 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1368 node
= node
->GetNext() )
1370 // recursively check each child
1371 wxWindow
*win
= (wxWindow
*)node
->GetData();
1372 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1382 // helper for FindWindowByXXX()
1384 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1385 const wxString
& label
,
1387 wxFindWindowCmp cmp
)
1391 // just check parent and all its children
1392 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1395 // start at very top of wx's windows
1396 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1398 node
= node
->GetNext() )
1400 // recursively check each window & its children
1401 wxWindow
*win
= node
->GetData();
1402 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1412 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1414 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1419 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1421 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1425 // fall back to the label
1426 win
= FindWindowByLabel(title
, parent
);
1434 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1436 return wxFindWindowHelper(parent
, wxEmptyString
, id
, wxFindWindowCmpIds
);
1439 // ----------------------------------------------------------------------------
1440 // dialog oriented functions
1441 // ----------------------------------------------------------------------------
1443 void wxWindowBase::MakeModal(bool modal
)
1445 // Disable all other windows
1448 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1451 wxWindow
*win
= node
->GetData();
1453 win
->Enable(!modal
);
1455 node
= node
->GetNext();
1460 bool wxWindowBase::Validate()
1462 #if wxUSE_VALIDATORS
1463 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1465 wxWindowList::compatibility_iterator node
;
1466 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1468 wxWindowBase
*child
= node
->GetData();
1469 wxValidator
*validator
= child
->GetValidator();
1470 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1475 if ( recurse
&& !child
->Validate() )
1480 #endif // wxUSE_VALIDATORS
1485 bool wxWindowBase::TransferDataToWindow()
1487 #if wxUSE_VALIDATORS
1488 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1490 wxWindowList::compatibility_iterator node
;
1491 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1493 wxWindowBase
*child
= node
->GetData();
1494 wxValidator
*validator
= child
->GetValidator();
1495 if ( validator
&& !validator
->TransferToWindow() )
1497 wxLogWarning(_("Could not transfer data to window"));
1499 wxLog::FlushActive();
1507 if ( !child
->TransferDataToWindow() )
1509 // warning already given
1514 #endif // wxUSE_VALIDATORS
1519 bool wxWindowBase::TransferDataFromWindow()
1521 #if wxUSE_VALIDATORS
1522 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1524 wxWindowList::compatibility_iterator node
;
1525 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1527 wxWindow
*child
= node
->GetData();
1528 wxValidator
*validator
= child
->GetValidator();
1529 if ( validator
&& !validator
->TransferFromWindow() )
1531 // nop warning here because the application is supposed to give
1532 // one itself - we don't know here what might have gone wrongly
1539 if ( !child
->TransferDataFromWindow() )
1541 // warning already given
1546 #endif // wxUSE_VALIDATORS
1551 void wxWindowBase::InitDialog()
1553 wxInitDialogEvent
event(GetId());
1554 event
.SetEventObject( this );
1555 GetEventHandler()->ProcessEvent(event
);
1558 // ----------------------------------------------------------------------------
1559 // context-sensitive help support
1560 // ----------------------------------------------------------------------------
1564 // associate this help text with this window
1565 void wxWindowBase::SetHelpText(const wxString
& text
)
1567 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1570 helpProvider
->AddHelp(this, text
);
1574 // associate this help text with all windows with the same id as this
1576 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1578 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1581 helpProvider
->AddHelp(GetId(), text
);
1585 // get the help string associated with this window (may be empty)
1586 wxString
wxWindowBase::GetHelpText() const
1589 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1592 text
= helpProvider
->GetHelp(this);
1598 // show help for this window
1599 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1601 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1604 if ( helpProvider
->ShowHelp(this) )
1606 // skip the event.Skip() below
1614 #endif // wxUSE_HELP
1616 // ----------------------------------------------------------------------------
1617 // tooltipsroot.Replace("\\", "/");
1618 // ----------------------------------------------------------------------------
1622 void wxWindowBase::SetToolTip( const wxString
&tip
)
1624 // don't create the new tooltip if we already have one
1627 m_tooltip
->SetTip( tip
);
1631 SetToolTip( new wxToolTip( tip
) );
1634 // setting empty tooltip text does not remove the tooltip any more - use
1635 // SetToolTip((wxToolTip *)NULL) for this
1638 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1643 m_tooltip
= tooltip
;
1646 #endif // wxUSE_TOOLTIPS
1648 // ----------------------------------------------------------------------------
1649 // constraints and sizers
1650 // ----------------------------------------------------------------------------
1652 #if wxUSE_CONSTRAINTS
1654 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1656 if ( m_constraints
)
1658 UnsetConstraints(m_constraints
);
1659 delete m_constraints
;
1661 m_constraints
= constraints
;
1662 if ( m_constraints
)
1664 // Make sure other windows know they're part of a 'meaningful relationship'
1665 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1666 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1667 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1668 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1669 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1670 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1671 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1672 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1673 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1674 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1675 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1676 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1677 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1678 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1679 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1680 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1684 // This removes any dangling pointers to this window in other windows'
1685 // constraintsInvolvedIn lists.
1686 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1690 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1691 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1692 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1693 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1694 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1695 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1696 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1697 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1698 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1699 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1700 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1701 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1702 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1703 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1704 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1705 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1709 // Back-pointer to other windows we're involved with, so if we delete this
1710 // window, we must delete any constraints we're involved with.
1711 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1713 if ( !m_constraintsInvolvedIn
)
1714 m_constraintsInvolvedIn
= new wxWindowList
;
1715 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1716 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1719 // REMOVE back-pointer to other windows we're involved with.
1720 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1722 if ( m_constraintsInvolvedIn
)
1723 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1726 // Reset any constraints that mention this window
1727 void wxWindowBase::DeleteRelatedConstraints()
1729 if ( m_constraintsInvolvedIn
)
1731 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1734 wxWindow
*win
= node
->GetData();
1735 wxLayoutConstraints
*constr
= win
->GetConstraints();
1737 // Reset any constraints involving this window
1740 constr
->left
.ResetIfWin(this);
1741 constr
->top
.ResetIfWin(this);
1742 constr
->right
.ResetIfWin(this);
1743 constr
->bottom
.ResetIfWin(this);
1744 constr
->width
.ResetIfWin(this);
1745 constr
->height
.ResetIfWin(this);
1746 constr
->centreX
.ResetIfWin(this);
1747 constr
->centreY
.ResetIfWin(this);
1750 wxWindowList::compatibility_iterator next
= node
->GetNext();
1751 m_constraintsInvolvedIn
->Erase(node
);
1755 delete m_constraintsInvolvedIn
;
1756 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1760 #endif // wxUSE_CONSTRAINTS
1762 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1764 if ( sizer
== m_windowSizer
)
1768 delete m_windowSizer
;
1770 m_windowSizer
= sizer
;
1772 SetAutoLayout( sizer
!= NULL
);
1775 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1777 SetSizer( sizer
, deleteOld
);
1778 sizer
->SetSizeHints( (wxWindow
*) this );
1782 void wxWindowBase::SetContainingSizer(wxSizer
* sizer
)
1784 // adding a window to a sizer twice is going to result in fatal and
1785 // hard to debug problems later because when deleting the second
1786 // associated wxSizerItem we're going to dereference a dangling
1787 // pointer; so try to detect this as early as possible
1788 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
1789 _T("Adding a window to the same sizer twice?") );
1791 m_containingSizer
= sizer
;
1794 #if wxUSE_CONSTRAINTS
1796 void wxWindowBase::SatisfyConstraints()
1798 wxLayoutConstraints
*constr
= GetConstraints();
1799 bool wasOk
= constr
&& constr
->AreSatisfied();
1801 ResetConstraints(); // Mark all constraints as unevaluated
1805 // if we're a top level panel (i.e. our parent is frame/dialog), our
1806 // own constraints will never be satisfied any more unless we do it
1810 while ( noChanges
> 0 )
1812 LayoutPhase1(&noChanges
);
1816 LayoutPhase2(&noChanges
);
1819 #endif // wxUSE_CONSTRAINTS
1821 bool wxWindowBase::Layout()
1823 // If there is a sizer, use it instead of the constraints
1827 GetVirtualSize(&w
, &h
);
1828 GetSizer()->SetDimension( 0, 0, w
, h
);
1830 #if wxUSE_CONSTRAINTS
1833 SatisfyConstraints(); // Find the right constraints values
1834 SetConstraintSizes(); // Recursively set the real window sizes
1841 #if wxUSE_CONSTRAINTS
1843 // first phase of the constraints evaluation: set our own constraints
1844 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1846 wxLayoutConstraints
*constr
= GetConstraints();
1848 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1851 // second phase: set the constraints for our children
1852 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1859 // Layout grand children
1865 // Do a phase of evaluating child constraints
1866 bool wxWindowBase::DoPhase(int phase
)
1868 // the list containing the children for which the constraints are already
1870 wxWindowList succeeded
;
1872 // the max number of iterations we loop before concluding that we can't set
1874 static const int maxIterations
= 500;
1876 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1880 // loop over all children setting their constraints
1881 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1883 node
= node
->GetNext() )
1885 wxWindow
*child
= node
->GetData();
1886 if ( child
->IsTopLevel() )
1888 // top level children are not inside our client area
1892 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1894 // this one is either already ok or nothing we can do about it
1898 int tempNoChanges
= 0;
1899 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1900 : child
->LayoutPhase2(&tempNoChanges
);
1901 noChanges
+= tempNoChanges
;
1905 succeeded
.Append(child
);
1911 // constraints are set
1919 void wxWindowBase::ResetConstraints()
1921 wxLayoutConstraints
*constr
= GetConstraints();
1924 constr
->left
.SetDone(false);
1925 constr
->top
.SetDone(false);
1926 constr
->right
.SetDone(false);
1927 constr
->bottom
.SetDone(false);
1928 constr
->width
.SetDone(false);
1929 constr
->height
.SetDone(false);
1930 constr
->centreX
.SetDone(false);
1931 constr
->centreY
.SetDone(false);
1934 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1937 wxWindow
*win
= node
->GetData();
1938 if ( !win
->IsTopLevel() )
1939 win
->ResetConstraints();
1940 node
= node
->GetNext();
1944 // Need to distinguish between setting the 'fake' size for windows and sizers,
1945 // and setting the real values.
1946 void wxWindowBase::SetConstraintSizes(bool recurse
)
1948 wxLayoutConstraints
*constr
= GetConstraints();
1949 if ( constr
&& constr
->AreSatisfied() )
1951 int x
= constr
->left
.GetValue();
1952 int y
= constr
->top
.GetValue();
1953 int w
= constr
->width
.GetValue();
1954 int h
= constr
->height
.GetValue();
1956 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1957 (constr
->height
.GetRelationship() != wxAsIs
) )
1959 SetSize(x
, y
, w
, h
);
1963 // If we don't want to resize this window, just move it...
1969 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1970 GetClassInfo()->GetClassName(),
1976 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1979 wxWindow
*win
= node
->GetData();
1980 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1981 win
->SetConstraintSizes();
1982 node
= node
->GetNext();
1987 // Only set the size/position of the constraint (if any)
1988 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1990 wxLayoutConstraints
*constr
= GetConstraints();
1993 if ( x
!= wxDefaultCoord
)
1995 constr
->left
.SetValue(x
);
1996 constr
->left
.SetDone(true);
1998 if ( y
!= wxDefaultCoord
)
2000 constr
->top
.SetValue(y
);
2001 constr
->top
.SetDone(true);
2003 if ( w
!= wxDefaultCoord
)
2005 constr
->width
.SetValue(w
);
2006 constr
->width
.SetDone(true);
2008 if ( h
!= wxDefaultCoord
)
2010 constr
->height
.SetValue(h
);
2011 constr
->height
.SetDone(true);
2016 void wxWindowBase::MoveConstraint(int x
, int y
)
2018 wxLayoutConstraints
*constr
= GetConstraints();
2021 if ( x
!= wxDefaultCoord
)
2023 constr
->left
.SetValue(x
);
2024 constr
->left
.SetDone(true);
2026 if ( y
!= wxDefaultCoord
)
2028 constr
->top
.SetValue(y
);
2029 constr
->top
.SetDone(true);
2034 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
2036 wxLayoutConstraints
*constr
= GetConstraints();
2039 *w
= constr
->width
.GetValue();
2040 *h
= constr
->height
.GetValue();
2046 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
2048 wxLayoutConstraints
*constr
= GetConstraints();
2051 *w
= constr
->width
.GetValue();
2052 *h
= constr
->height
.GetValue();
2055 GetClientSize(w
, h
);
2058 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
2060 wxLayoutConstraints
*constr
= GetConstraints();
2063 *x
= constr
->left
.GetValue();
2064 *y
= constr
->top
.GetValue();
2070 #endif // wxUSE_CONSTRAINTS
2072 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
2074 // don't do it for the dialogs/frames - they float independently of their
2076 if ( !IsTopLevel() )
2078 wxWindow
*parent
= GetParent();
2079 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
2081 wxPoint
pt(parent
->GetClientAreaOrigin());
2088 // ----------------------------------------------------------------------------
2089 // do Update UI processing for child controls
2090 // ----------------------------------------------------------------------------
2092 void wxWindowBase::UpdateWindowUI(long flags
)
2094 wxUpdateUIEvent
event(GetId());
2095 event
.SetEventObject(this);
2097 if ( GetEventHandler()->ProcessEvent(event
) )
2099 DoUpdateWindowUI(event
);
2102 if (flags
& wxUPDATE_UI_RECURSE
)
2104 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2107 wxWindow
* child
= (wxWindow
*) node
->GetData();
2108 child
->UpdateWindowUI(flags
);
2109 node
= node
->GetNext();
2114 // do the window-specific processing after processing the update event
2115 // TODO: take specific knowledge out of this function and
2116 // put in each control's base class. Unfortunately we don't
2117 // yet have base implementation files for wxCheckBox and wxRadioButton.
2118 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
2120 if ( event
.GetSetEnabled() )
2121 Enable(event
.GetEnabled());
2124 if ( event
.GetSetText() )
2126 wxControl
*control
= wxDynamicCastThis(wxControl
);
2129 if ( event
.GetText() != control
->GetLabel() )
2130 control
->SetLabel(event
.GetText());
2133 #endif // wxUSE_CONTROLS
2135 if ( event
.GetSetChecked() )
2138 wxCheckBox
*checkbox
= wxDynamicCastThis(wxCheckBox
);
2141 checkbox
->SetValue(event
.GetChecked());
2143 #endif // wxUSE_CHECKBOX
2146 wxRadioButton
*radiobtn
= wxDynamicCastThis(wxRadioButton
);
2149 radiobtn
->SetValue(event
.GetChecked());
2151 #endif // wxUSE_RADIOBTN
2156 // call internal idle recursively
2157 // may be obsolete (wait until OnIdle scheme stabilises)
2158 void wxWindowBase::ProcessInternalIdle()
2162 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2165 wxWindow
*child
= node
->GetData();
2166 child
->ProcessInternalIdle();
2167 node
= node
->GetNext();
2172 // ----------------------------------------------------------------------------
2173 // dialog units translations
2174 // ----------------------------------------------------------------------------
2176 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
2178 int charWidth
= GetCharWidth();
2179 int charHeight
= GetCharHeight();
2180 wxPoint pt2
= wxDefaultPosition
;
2181 if (pt
.x
!= wxDefaultCoord
)
2182 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
2183 if (pt
.y
!= wxDefaultCoord
)
2184 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2189 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
2191 int charWidth
= GetCharWidth();
2192 int charHeight
= GetCharHeight();
2193 wxPoint pt2
= wxDefaultPosition
;
2194 if (pt
.x
!= wxDefaultCoord
)
2195 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
2196 if (pt
.y
!= wxDefaultCoord
)
2197 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2202 // ----------------------------------------------------------------------------
2204 // ----------------------------------------------------------------------------
2206 // propagate the colour change event to the subwindows
2207 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2209 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
2212 // Only propagate to non-top-level windows
2213 wxWindow
*win
= node
->GetData();
2214 if ( !win
->IsTopLevel() )
2216 wxSysColourChangedEvent event2
;
2217 event
.SetEventObject(win
);
2218 win
->GetEventHandler()->ProcessEvent(event2
);
2221 node
= node
->GetNext();
2227 // the default action is to populate dialog with data when it's created,
2228 // and nudge the UI into displaying itself correctly in case
2229 // we've turned the wxUpdateUIEvents frequency down low.
2230 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2232 TransferDataToWindow();
2234 // Update the UI at this point
2235 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2238 // process Ctrl-Alt-mclick
2239 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
2242 if ( event
.ControlDown() && event
.AltDown() )
2244 // don't translate these strings
2247 #ifdef __WXUNIVERSAL__
2249 #endif // __WXUNIVERSAL__
2251 switch ( wxGetOsVersion() )
2253 case wxMOTIF_X
: port
+= _T("Motif"); break;
2255 case wxMAC_DARWIN
: port
+= _T("Mac"); break;
2256 case wxBEOS
: port
+= _T("BeOS"); break;
2260 case wxGTK_BEOS
: port
+= _T("GTK"); break;
2266 case wxWIN386
: port
+= _T("MS Windows"); break;
2270 case wxMGL_OS2
: port
+= _T("MGL"); break;
2272 case wxOS2_PM
: port
+= _T("OS/2"); break;
2273 default: port
+= _T("unknown"); break;
2276 wxMessageBox(wxString::Format(
2278 " wxWidgets Library (%s port)\nVersion %u.%u.%u%s%s, compiled at %s %s\n Copyright (c) 1995-2005 wxWidgets team"
2297 _T("wxWidgets information"),
2298 wxICON_INFORMATION
| wxOK
,
2302 #endif // wxUSE_MSGDLG
2308 // ----------------------------------------------------------------------------
2310 // ----------------------------------------------------------------------------
2312 #if wxUSE_ACCESSIBILITY
2313 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2315 if (m_accessible
&& (accessible
!= m_accessible
))
2316 delete m_accessible
;
2317 m_accessible
= accessible
;
2319 m_accessible
->SetWindow((wxWindow
*) this);
2322 // Returns the accessible object, creating if necessary.
2323 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2326 m_accessible
= CreateAccessible();
2327 return m_accessible
;
2330 // Override to create a specific accessible object.
2331 wxAccessible
* wxWindowBase::CreateAccessible()
2333 return new wxWindowAccessible((wxWindow
*) this);
2338 // ----------------------------------------------------------------------------
2339 // list classes implementation
2340 // ----------------------------------------------------------------------------
2344 #include <wx/listimpl.cpp>
2345 WX_DEFINE_LIST(wxWindowList
);
2349 void wxWindowListNode::DeleteData()
2351 delete (wxWindow
*)GetData();
2356 // ----------------------------------------------------------------------------
2358 // ----------------------------------------------------------------------------
2360 wxBorder
wxWindowBase::GetBorder(long flags
) const
2362 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2363 if ( border
== wxBORDER_DEFAULT
)
2365 border
= GetDefaultBorder();
2371 wxBorder
wxWindowBase::GetDefaultBorder() const
2373 return wxBORDER_NONE
;
2376 // ----------------------------------------------------------------------------
2378 // ----------------------------------------------------------------------------
2380 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2382 // here we just check if the point is inside the window or not
2384 // check the top and left border first
2385 bool outside
= x
< 0 || y
< 0;
2388 // check the right and bottom borders too
2389 wxSize size
= GetSize();
2390 outside
= x
>= size
.x
|| y
>= size
.y
;
2393 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2396 // ----------------------------------------------------------------------------
2398 // ----------------------------------------------------------------------------
2400 struct WXDLLEXPORT wxWindowNext
2404 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2406 void wxWindowBase::CaptureMouse()
2408 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this);
2410 wxWindow
*winOld
= GetCapture();
2413 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2416 wxWindowNext
*item
= new wxWindowNext
;
2418 item
->next
= ms_winCaptureNext
;
2419 ms_winCaptureNext
= item
;
2421 //else: no mouse capture to save
2426 void wxWindowBase::ReleaseMouse()
2428 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this);
2430 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2434 if ( ms_winCaptureNext
)
2436 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2438 wxWindowNext
*item
= ms_winCaptureNext
;
2439 ms_winCaptureNext
= item
->next
;
2442 //else: stack is empty, no previous capture
2444 wxLogTrace(_T("mousecapture"),
2445 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2452 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2453 int WXUNUSED(modifiers
),
2454 int WXUNUSED(keycode
))
2460 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2466 #endif // wxUSE_HOTKEY
2468 void wxWindowBase::SendDestroyEvent()
2470 wxWindowDestroyEvent event
;
2471 event
.SetEventObject(this);
2472 event
.SetId(GetId());
2473 GetEventHandler()->ProcessEvent(event
);
2476 // ----------------------------------------------------------------------------
2478 // ----------------------------------------------------------------------------
2480 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2482 #if wxUSE_VALIDATORS
2483 // Can only use the validator of the window which
2484 // is receiving the event
2485 if ( event
.GetEventObject() == this )
2487 wxValidator
*validator
= GetValidator();
2488 if ( validator
&& validator
->ProcessEvent(event
) )
2493 #endif // wxUSE_VALIDATORS
2498 bool wxWindowBase::TryParent(wxEvent
& event
)
2500 // carry on up the parent-child hierarchy if the propgation count hasn't
2502 if ( event
.ShouldPropagate() )
2504 // honour the requests to stop propagation at this window: this is
2505 // used by the dialogs, for example, to prevent processing the events
2506 // from the dialog controls in the parent frame which rarely, if ever,
2508 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2510 wxWindow
*parent
= GetParent();
2511 if ( parent
&& !parent
->IsBeingDeleted() )
2513 wxPropagateOnce
propagateOnce(event
);
2515 return parent
->GetEventHandler()->ProcessEvent(event
);
2520 return wxEvtHandler::TryParent(event
);
2523 // ----------------------------------------------------------------------------
2524 // keyboard navigation
2525 // ----------------------------------------------------------------------------
2527 // Navigates in the specified direction.
2528 bool wxWindowBase::Navigate(int flags
)
2530 wxNavigationKeyEvent eventNav
;
2531 eventNav
.SetFlags(flags
);
2532 eventNav
.SetEventObject(this);
2533 if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav
) )
2540 void wxWindowBase::DoMoveInTabOrder(wxWindow
*win
, MoveKind move
)
2542 // check that we're not a top level window
2543 wxCHECK_RET( GetParent(),
2544 _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
2546 // detect the special case when we have nothing to do anyhow and when the
2547 // code below wouldn't work
2551 // find the target window in the siblings list
2552 wxWindowList
& siblings
= GetParent()->GetChildren();
2553 wxWindowList::compatibility_iterator i
= siblings
.Find(win
);
2554 wxCHECK_RET( i
, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") );
2556 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
2557 // can't just move the node around
2558 wxWindow
*self
= (wxWindow
*)this;
2559 siblings
.DeleteObject(self
);
2560 if ( move
== MoveAfter
)
2567 siblings
.Insert(i
, self
);
2569 else // MoveAfter and win was the last sibling
2571 siblings
.Append(self
);
2575 // ----------------------------------------------------------------------------
2577 // ----------------------------------------------------------------------------
2579 /*static*/ wxWindow
* wxWindowBase::FindFocus()
2581 wxWindowBase
*win
= DoFindFocus();
2582 return win
? win
->GetMainWindowOfCompositeControl() : NULL
;
2585 // ----------------------------------------------------------------------------
2587 // ----------------------------------------------------------------------------
2589 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2591 while ( win
&& !win
->IsTopLevel() )
2592 win
= win
->GetParent();
2597 #if wxUSE_ACCESSIBILITY
2598 // ----------------------------------------------------------------------------
2599 // accessible object for windows
2600 // ----------------------------------------------------------------------------
2602 // Can return either a child object, or an integer
2603 // representing the child element, starting from 1.
2604 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2606 wxASSERT( GetWindow() != NULL
);
2610 return wxACC_NOT_IMPLEMENTED
;
2613 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2614 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2616 wxASSERT( GetWindow() != NULL
);
2620 wxWindow
* win
= NULL
;
2627 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2629 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2636 rect
= win
->GetRect();
2637 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2638 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2642 return wxACC_NOT_IMPLEMENTED
;
2645 // Navigates from fromId to toId/toObject.
2646 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2647 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2649 wxASSERT( GetWindow() != NULL
);
2655 case wxNAVDIR_FIRSTCHILD
:
2657 if (GetWindow()->GetChildren().GetCount() == 0)
2659 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2660 *toObject
= childWindow
->GetOrCreateAccessible();
2664 case wxNAVDIR_LASTCHILD
:
2666 if (GetWindow()->GetChildren().GetCount() == 0)
2668 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2669 *toObject
= childWindow
->GetOrCreateAccessible();
2673 case wxNAVDIR_RIGHT
:
2677 wxWindowList::compatibility_iterator node
=
2678 wxWindowList::compatibility_iterator();
2681 // Can't navigate to sibling of this window
2682 // if we're a top-level window.
2683 if (!GetWindow()->GetParent())
2684 return wxACC_NOT_IMPLEMENTED
;
2686 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2690 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2691 node
= GetWindow()->GetChildren().Item(fromId
-1);
2694 if (node
&& node
->GetNext())
2696 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2697 *toObject
= nextWindow
->GetOrCreateAccessible();
2705 case wxNAVDIR_PREVIOUS
:
2707 wxWindowList::compatibility_iterator node
=
2708 wxWindowList::compatibility_iterator();
2711 // Can't navigate to sibling of this window
2712 // if we're a top-level window.
2713 if (!GetWindow()->GetParent())
2714 return wxACC_NOT_IMPLEMENTED
;
2716 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2720 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2721 node
= GetWindow()->GetChildren().Item(fromId
-1);
2724 if (node
&& node
->GetPrevious())
2726 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2727 *toObject
= previousWindow
->GetOrCreateAccessible();
2735 return wxACC_NOT_IMPLEMENTED
;
2738 // Gets the name of the specified object.
2739 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2741 wxASSERT( GetWindow() != NULL
);
2747 // If a child, leave wxWidgets to call the function on the actual
2750 return wxACC_NOT_IMPLEMENTED
;
2752 // This will eventually be replaced by specialised
2753 // accessible classes, one for each kind of wxWidgets
2754 // control or window.
2756 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2757 title
= ((wxButton
*) GetWindow())->GetLabel();
2760 title
= GetWindow()->GetName();
2768 return wxACC_NOT_IMPLEMENTED
;
2771 // Gets the number of children.
2772 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2774 wxASSERT( GetWindow() != NULL
);
2778 *childId
= (int) GetWindow()->GetChildren().GetCount();
2782 // Gets the specified child (starting from 1).
2783 // If *child is NULL and return value is wxACC_OK,
2784 // this means that the child is a simple element and
2785 // not an accessible object.
2786 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2788 wxASSERT( GetWindow() != NULL
);
2798 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2801 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2802 *child
= childWindow
->GetOrCreateAccessible();
2809 // Gets the parent, or NULL.
2810 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2812 wxASSERT( GetWindow() != NULL
);
2816 wxWindow
* parentWindow
= GetWindow()->GetParent();
2824 *parent
= parentWindow
->GetOrCreateAccessible();
2832 // Performs the default action. childId is 0 (the action for this object)
2833 // or > 0 (the action for a child).
2834 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2835 // window (e.g. an edit control).
2836 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
2838 wxASSERT( GetWindow() != NULL
);
2842 return wxACC_NOT_IMPLEMENTED
;
2845 // Gets the default action for this object (0) or > 0 (the action for a child).
2846 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2847 // string if there is no action.
2848 // The retrieved string describes the action that is performed on an object,
2849 // not what the object does as a result. For example, a toolbar button that prints
2850 // a document has a default action of "Press" rather than "Prints the current document."
2851 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
2853 wxASSERT( GetWindow() != NULL
);
2857 return wxACC_NOT_IMPLEMENTED
;
2860 // Returns the description for this object or a child.
2861 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
2863 wxASSERT( GetWindow() != NULL
);
2867 wxString
ht(GetWindow()->GetHelpText());
2873 return wxACC_NOT_IMPLEMENTED
;
2876 // Returns help text for this object or a child, similar to tooltip text.
2877 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
2879 wxASSERT( GetWindow() != NULL
);
2883 wxString
ht(GetWindow()->GetHelpText());
2889 return wxACC_NOT_IMPLEMENTED
;
2892 // Returns the keyboard shortcut for this object or child.
2893 // Return e.g. ALT+K
2894 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
2896 wxASSERT( GetWindow() != NULL
);
2900 return wxACC_NOT_IMPLEMENTED
;
2903 // Returns a role constant.
2904 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
2906 wxASSERT( GetWindow() != NULL
);
2910 // If a child, leave wxWidgets to call the function on the actual
2913 return wxACC_NOT_IMPLEMENTED
;
2915 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2916 return wxACC_NOT_IMPLEMENTED
;
2918 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2919 return wxACC_NOT_IMPLEMENTED
;
2922 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2923 return wxACC_NOT_IMPLEMENTED
;
2926 //*role = wxROLE_SYSTEM_CLIENT;
2927 *role
= wxROLE_SYSTEM_CLIENT
;
2931 return wxACC_NOT_IMPLEMENTED
;
2935 // Returns a state constant.
2936 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
2938 wxASSERT( GetWindow() != NULL
);
2942 // If a child, leave wxWidgets to call the function on the actual
2945 return wxACC_NOT_IMPLEMENTED
;
2947 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2948 return wxACC_NOT_IMPLEMENTED
;
2951 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2952 return wxACC_NOT_IMPLEMENTED
;
2955 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2956 return wxACC_NOT_IMPLEMENTED
;
2963 return wxACC_NOT_IMPLEMENTED
;
2967 // Returns a localized string representing the value for the object
2969 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
2971 wxASSERT( GetWindow() != NULL
);
2975 return wxACC_NOT_IMPLEMENTED
;
2978 // Selects the object or child.
2979 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
2981 wxASSERT( GetWindow() != NULL
);
2985 return wxACC_NOT_IMPLEMENTED
;
2988 // Gets the window with the keyboard focus.
2989 // If childId is 0 and child is NULL, no object in
2990 // this subhierarchy has the focus.
2991 // If this object has the focus, child should be 'this'.
2992 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
2994 wxASSERT( GetWindow() != NULL
);
2998 return wxACC_NOT_IMPLEMENTED
;
3001 // Gets a variant representing the selected children
3003 // Acceptable values:
3004 // - a null variant (IsNull() returns true)
3005 // - a list variant (GetType() == wxT("list")
3006 // - an integer representing the selected child element,
3007 // or 0 if this object is selected (GetType() == wxT("long")
3008 // - a "void*" pointer to a wxAccessible child object
3009 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
3011 wxASSERT( GetWindow() != NULL
);
3015 return wxACC_NOT_IMPLEMENTED
;
3018 #endif // wxUSE_ACCESSIBILITY