1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/window.cpp
3 // Purpose: common (to all ports) wxWindow functions
4 // Author: Julian Smart, Vadim Zeitlin
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
28 #include "wx/string.h"
32 #include "wx/window.h"
33 #include "wx/control.h"
34 #include "wx/checkbox.h"
35 #include "wx/radiobut.h"
36 #include "wx/statbox.h"
37 #include "wx/textctrl.h"
38 #include "wx/settings.h"
39 #include "wx/dialog.h"
40 #include "wx/msgdlg.h"
41 #include "wx/statusbr.h"
42 #include "wx/toolbar.h"
43 #include "wx/dcclient.h"
44 #include "wx/scrolbar.h"
45 #include "wx/layout.h"
49 #if wxUSE_DRAG_AND_DROP
51 #endif // wxUSE_DRAG_AND_DROP
53 #if wxUSE_ACCESSIBILITY
54 #include "wx/access.h"
58 #include "wx/cshelp.h"
62 #include "wx/tooltip.h"
63 #endif // wxUSE_TOOLTIPS
69 #if wxUSE_SYSTEM_OPTIONS
70 #include "wx/sysopt.h"
73 // For reporting compile- and runtime version of GTK+ in the ctrl+alt+mclick dialog.
74 // The gtk includes don't pull any other headers in, at least not on my system - MR
77 #include <gtk/gtkversion.h>
79 #include <gtk/gtkfeatures.h>
81 extern const unsigned int gtk_major_version
;
82 extern const unsigned int gtk_minor_version
;
83 extern const unsigned int gtk_micro_version
;
86 #include "wx/platinfo.h"
89 WXDLLIMPEXP_DATA_CORE(wxWindowList
) wxTopLevelWindows
;
91 // ----------------------------------------------------------------------------
93 // ----------------------------------------------------------------------------
95 #if defined(__WXPALMOS__)
96 int wxWindowBase
::ms_lastControlId
= 32767;
97 #elif defined(__WXPM__)
98 int wxWindowBase
::ms_lastControlId
= 2000;
100 int wxWindowBase
::ms_lastControlId
= -200;
103 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
105 // ----------------------------------------------------------------------------
107 // ----------------------------------------------------------------------------
109 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
110 EVT_SYS_COLOUR_CHANGED(wxWindowBase
::OnSysColourChanged
)
111 EVT_INIT_DIALOG(wxWindowBase
::OnInitDialog
)
112 EVT_MIDDLE_DOWN(wxWindowBase
::OnMiddleClick
)
115 EVT_HELP(wxID_ANY
, wxWindowBase
::OnHelp
)
120 // ============================================================================
121 // implementation of the common functionality of the wxWindow class
122 // ============================================================================
124 // ----------------------------------------------------------------------------
126 // ----------------------------------------------------------------------------
128 // the default initialization
129 wxWindowBase
::wxWindowBase()
131 // no window yet, no parent nor children
132 m_parent
= (wxWindow
*)NULL
;
133 m_windowId
= wxID_ANY
;
135 // no constraints on the minimal window size
137 m_maxWidth
= wxDefaultCoord
;
139 m_maxHeight
= wxDefaultCoord
;
141 // invalidiated cache value
142 m_bestSizeCache
= wxDefaultSize
;
144 // window are created enabled and visible by default
148 // the default event handler is just this window
149 m_eventHandler
= this;
153 m_windowValidator
= (wxValidator
*) NULL
;
154 #endif // wxUSE_VALIDATORS
156 // the colours/fonts are default for now, so leave m_font,
157 // m_backgroundColour and m_foregroundColour uninitialized and set those
163 m_inheritFont
= false;
169 m_backgroundStyle
= wxBG_STYLE_SYSTEM
;
171 #if wxUSE_CONSTRAINTS
172 // no constraints whatsoever
173 m_constraints
= (wxLayoutConstraints
*) NULL
;
174 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
175 #endif // wxUSE_CONSTRAINTS
177 m_windowSizer
= (wxSizer
*) NULL
;
178 m_containingSizer
= (wxSizer
*) NULL
;
179 m_autoLayout
= false;
181 #if wxUSE_DRAG_AND_DROP
182 m_dropTarget
= (wxDropTarget
*)NULL
;
183 #endif // wxUSE_DRAG_AND_DROP
186 m_tooltip
= (wxToolTip
*)NULL
;
187 #endif // wxUSE_TOOLTIPS
190 m_caret
= (wxCaret
*)NULL
;
191 #endif // wxUSE_CARET
194 m_hasCustomPalette
= false;
195 #endif // wxUSE_PALETTE
197 #if wxUSE_ACCESSIBILITY
201 m_virtualSize
= wxDefaultSize
;
203 m_scrollHelper
= (wxScrollHelper
*) NULL
;
206 m_maxVirtualWidth
= wxDefaultCoord
;
208 m_maxVirtualHeight
= wxDefaultCoord
;
210 m_windowVariant
= wxWINDOW_VARIANT_NORMAL
;
211 #if wxUSE_SYSTEM_OPTIONS
212 if ( wxSystemOptions
::HasOption(wxWINDOW_DEFAULT_VARIANT
) )
214 m_windowVariant
= (wxWindowVariant
) wxSystemOptions
::GetOptionInt( wxWINDOW_DEFAULT_VARIANT
) ;
218 // Whether we're using the current theme for this window (wxGTK only for now)
219 m_themeEnabled
= false;
221 // VZ: this one shouldn't exist...
222 m_isBeingDeleted
= false;
225 // common part of window creation process
226 bool wxWindowBase
::CreateBase(wxWindowBase
*parent
,
228 const wxPoint
& WXUNUSED(pos
),
229 const wxSize
& WXUNUSED(size
),
231 const wxValidator
& wxVALIDATOR_PARAM(validator
),
232 const wxString
& name
)
235 // wxGTK doesn't allow to create controls with static box as the parent so
236 // this will result in a crash when the program is ported to wxGTK so warn
239 // if you get this assert, the correct solution is to create the controls
240 // as siblings of the static box
241 wxASSERT_MSG( !parent
|| !wxDynamicCast(parent
, wxStaticBox
),
242 _T("wxStaticBox can't be used as a window parent!") );
243 #endif // wxUSE_STATBOX
245 // ids are limited to 16 bits under MSW so if you care about portability,
246 // it's not a good idea to use ids out of this range (and negative ids are
247 // reserved for wxWidgets own usage)
248 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767),
249 _T("invalid id value") );
251 // generate a new id if the user doesn't care about it
252 m_windowId
= id
== wxID_ANY ?
NewControlId() : id
;
254 // don't use SetWindowStyleFlag() here, this function should only be called
255 // to change the flag after creation as it tries to reflect the changes in
256 // flags by updating the window dynamically and we don't need this here
257 m_windowStyle
= style
;
263 SetValidator(validator
);
264 #endif // wxUSE_VALIDATORS
266 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
267 // have it too - like this it's possible to set it only in the top level
268 // dialog/frame and all children will inherit it by defult
269 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
271 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
277 // ----------------------------------------------------------------------------
279 // ----------------------------------------------------------------------------
282 wxWindowBase
::~wxWindowBase()
284 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
286 // FIXME if these 2 cases result from programming errors in the user code
287 // we should probably assert here instead of silently fixing them
289 // Just in case the window has been Closed, but we're then deleting
290 // immediately: don't leave dangling pointers.
291 wxPendingDelete
.DeleteObject(this);
293 // Just in case we've loaded a top-level window via LoadNativeDialog but
294 // we weren't a dialog class
295 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
297 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
299 // reset the top-level parent's default item if it is this widget
302 wxTopLevelWindow
*tlw
= wxDynamicCast(wxGetTopLevelParent((wxWindow
*)this),
305 if ( tlw
&& tlw
->GetDefaultItem() == this )
306 tlw
->SetDefaultItem(NULL
);
307 if ( tlw
&& tlw
->GetTmpDefaultItem() == this )
308 tlw
->SetTmpDefaultItem(NULL
);
311 // reset the dangling pointer our parent window may keep to us
314 m_parent
->RemoveChild(this);
319 #endif // wxUSE_CARET
322 delete m_windowValidator
;
323 #endif // wxUSE_VALIDATORS
325 #if wxUSE_CONSTRAINTS
326 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
327 // at deleted windows as they delete themselves.
328 DeleteRelatedConstraints();
332 // This removes any dangling pointers to this window in other windows'
333 // constraintsInvolvedIn lists.
334 UnsetConstraints(m_constraints
);
335 delete m_constraints
;
336 m_constraints
= NULL
;
338 #endif // wxUSE_CONSTRAINTS
340 if ( m_containingSizer
)
341 m_containingSizer
->Detach( (wxWindow
*)this );
343 delete m_windowSizer
;
345 #if wxUSE_DRAG_AND_DROP
347 #endif // wxUSE_DRAG_AND_DROP
351 #endif // wxUSE_TOOLTIPS
353 #if wxUSE_ACCESSIBILITY
358 void wxWindowBase
::SendDestroyEvent()
360 wxWindowDestroyEvent event
;
361 event
.SetEventObject(this);
362 event
.SetId(GetId());
363 GetEventHandler()->ProcessEvent(event
);
366 bool wxWindowBase
::Destroy()
373 bool wxWindowBase
::Close(bool force
)
375 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
376 event
.SetEventObject(this);
377 event
.SetCanVeto(!force
);
379 // return false if window wasn't closed because the application vetoed the
381 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
384 bool wxWindowBase
::DestroyChildren()
386 wxWindowList
::compatibility_iterator node
;
389 // we iterate until the list becomes empty
390 node
= GetChildren().GetFirst();
394 wxWindow
*child
= node
->GetData();
396 // note that we really want to call delete and not ->Destroy() here
397 // because we want to delete the child immediately, before we are
398 // deleted, and delayed deletion would result in problems as our (top
399 // level) child could outlive its parent
402 wxASSERT_MSG( !GetChildren().Find(child
),
403 wxT("child didn't remove itself using RemoveChild()") );
409 // ----------------------------------------------------------------------------
410 // size/position related methods
411 // ----------------------------------------------------------------------------
413 // centre the window with respect to its parent in either (or both) directions
414 void wxWindowBase
::DoCentre(int dir
)
416 wxCHECK_RET( !(dir
& wxCENTRE_ON_SCREEN
) && GetParent(),
417 _T("this method only implements centering child windows") );
419 SetSize(GetRect().CentreIn(GetParent()->GetClientSize(), dir
));
422 // fits the window around the children
423 void wxWindowBase
::Fit()
425 if ( !GetChildren().empty() )
427 SetSize(GetBestSize());
429 //else: do nothing if we have no children
432 // fits virtual size (ie. scrolled area etc.) around children
433 void wxWindowBase
::FitInside()
435 if ( GetChildren().GetCount() > 0 )
437 SetVirtualSize( GetBestVirtualSize() );
441 // On Mac, scrollbars are explicitly children.
443 static bool wxHasRealChildren(const wxWindowBase
* win
)
445 int realChildCount
= 0;
447 for ( wxWindowList
::compatibility_iterator node
= win
->GetChildren().GetFirst();
449 node
= node
->GetNext() )
451 wxWindow
*win
= node
->GetData();
452 if ( !win
->IsTopLevel() && win
->IsShown() && !win
->IsKindOf(CLASSINFO(wxScrollBar
)))
455 return (realChildCount
> 0);
459 void wxWindowBase
::InvalidateBestSize()
461 m_bestSizeCache
= wxDefaultSize
;
463 // parent's best size calculation may depend on its children's
464 // as long as child window we are in is not top level window itself
465 // (because the TLW size is never resized automatically)
466 // so let's invalidate it as well to be safe:
467 if (m_parent
&& !IsTopLevel())
468 m_parent
->InvalidateBestSize();
471 // return the size best suited for the current window
472 wxSize wxWindowBase
::DoGetBestSize() const
478 best
= GetWindowSizeForVirtualSize(m_windowSizer
->GetMinSize());
480 #if wxUSE_CONSTRAINTS
481 else if ( m_constraints
)
483 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
485 // our minimal acceptable size is such that all our windows fit inside
489 for ( wxWindowList
::compatibility_iterator node
= GetChildren().GetFirst();
491 node
= node
->GetNext() )
493 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
496 // it's not normal that we have an unconstrained child, but
497 // what can we do about it?
501 int x
= c
->right
.GetValue(),
502 y
= c
->bottom
.GetValue();
510 // TODO: we must calculate the overlaps somehow, otherwise we
511 // will never return a size bigger than the current one :-(
514 best
= wxSize(maxX
, maxY
);
516 #endif // wxUSE_CONSTRAINTS
517 else if ( !GetChildren().empty()
519 && wxHasRealChildren(this)
523 // our minimal acceptable size is such that all our visible child
524 // windows fit inside
528 for ( wxWindowList
::compatibility_iterator node
= GetChildren().GetFirst();
530 node
= node
->GetNext() )
532 wxWindow
*win
= node
->GetData();
533 if ( win
->IsTopLevel()
536 || wxDynamicCast(win
, wxStatusBar
)
537 #endif // wxUSE_STATUSBAR
540 // dialogs and frames lie in different top level windows -
541 // don't deal with them here; as for the status bars, they
542 // don't lie in the client area at all
547 win
->GetPosition(&wx
, &wy
);
549 // if the window hadn't been positioned yet, assume that it is in
551 if ( wx
== wxDefaultCoord
)
553 if ( wy
== wxDefaultCoord
)
556 win
->GetSize(&ww
, &wh
);
557 if ( wx
+ ww
> maxX
)
559 if ( wy
+ wh
> maxY
)
563 best
= wxSize(maxX
, maxY
);
565 else // ! has children
567 // for a generic window there is no natural best size so, if the
568 // minimal size is not set, use the current size but take care to
569 // remember it as minimal size for the next time because our best size
570 // should be constant: otherwise we could get into a situation when the
571 // window is initially at some size, then expanded to a larger size and
572 // then, when the containing window is shrunk back (because our initial
573 // best size had been used for computing the parent min size), we can't
574 // be shrunk back any more because our best size is now bigger
575 wxSize size
= GetMinSize();
576 if ( !size
.IsFullySpecified() )
578 size
.SetDefaults(GetSize());
579 wxConstCast(this, wxWindowBase
)->SetMinSize(size
);
582 // return as-is, unadjusted by the client size difference.
586 // Add any difference between size and client size
587 wxSize diff
= GetSize() - GetClientSize();
588 best
.x
+= wxMax(0, diff
.x
);
589 best
.y
+= wxMax(0, diff
.y
);
594 // helper of GetWindowBorderSize(): as many ports don't implement support for
595 // wxSYS_BORDER/EDGE_X/Y metrics in their wxSystemSettings, use hard coded
596 // fallbacks in this case
597 static int wxGetMetricOrDefault(wxSystemMetric what
)
599 int rc
= wxSystemSettings
::GetMetric(what
);
606 // 2D border is by default 1 pixel wide
612 // 3D borders are by default 2 pixels
617 wxFAIL_MSG( _T("unexpected wxGetMetricOrDefault() argument") );
625 wxSize wxWindowBase
::GetWindowBorderSize() const
629 switch ( GetBorder() )
632 // nothing to do, size is already (0, 0)
635 case wxBORDER_SIMPLE
:
636 case wxBORDER_STATIC
:
637 size
.x
= wxGetMetricOrDefault(wxSYS_BORDER_X
);
638 size
.y
= wxGetMetricOrDefault(wxSYS_BORDER_Y
);
641 case wxBORDER_SUNKEN
:
642 case wxBORDER_RAISED
:
643 size
.x
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_X
),
644 wxGetMetricOrDefault(wxSYS_BORDER_X
));
645 size
.y
= wxMax(wxGetMetricOrDefault(wxSYS_EDGE_Y
),
646 wxGetMetricOrDefault(wxSYS_BORDER_Y
));
649 case wxBORDER_DOUBLE
:
650 size
.x
= wxGetMetricOrDefault(wxSYS_EDGE_X
) +
651 wxGetMetricOrDefault(wxSYS_BORDER_X
);
652 size
.y
= wxGetMetricOrDefault(wxSYS_EDGE_Y
) +
653 wxGetMetricOrDefault(wxSYS_BORDER_Y
);
657 wxFAIL_MSG(_T("Unknown border style."));
661 // we have borders on both sides
665 wxSize wxWindowBase
::GetEffectiveMinSize() const
667 // merge the best size with the min size, giving priority to the min size
668 wxSize min
= GetMinSize();
669 if (min
.x
== wxDefaultCoord
|| min
.y
== wxDefaultCoord
)
671 wxSize best
= GetBestSize();
672 if (min
.x
== wxDefaultCoord
) min
.x
= best
.x
;
673 if (min
.y
== wxDefaultCoord
) min
.y
= best
.y
;
679 void wxWindowBase
::SetInitialSize(const wxSize
& size
)
681 // Set the min size to the size passed in. This will usually either be
682 // wxDefaultSize or the size passed to this window's ctor/Create function.
685 // Merge the size with the best size if needed
686 wxSize best
= GetEffectiveMinSize();
688 // If the current size doesn't match then change it
689 if (GetSize() != best
)
694 // by default the origin is not shifted
695 wxPoint wxWindowBase
::GetClientAreaOrigin() const
700 void wxWindowBase
::SetWindowVariant( wxWindowVariant variant
)
702 if ( m_windowVariant
!= variant
)
704 m_windowVariant
= variant
;
706 DoSetWindowVariant(variant
);
710 void wxWindowBase
::DoSetWindowVariant( wxWindowVariant variant
)
712 // adjust the font height to correspond to our new variant (notice that
713 // we're only called if something really changed)
714 wxFont font
= GetFont();
715 int size
= font
.GetPointSize();
718 case wxWINDOW_VARIANT_NORMAL
:
721 case wxWINDOW_VARIANT_SMALL
:
726 case wxWINDOW_VARIANT_MINI
:
731 case wxWINDOW_VARIANT_LARGE
:
737 wxFAIL_MSG(_T("unexpected window variant"));
741 font
.SetPointSize(size
);
745 void wxWindowBase
::DoSetSizeHints( int minW
, int minH
,
747 int WXUNUSED(incW
), int WXUNUSED(incH
) )
749 wxCHECK_RET( (minW
== wxDefaultCoord
|| maxW
== wxDefaultCoord
|| minW
<= maxW
) &&
750 (minH
== wxDefaultCoord
|| maxH
== wxDefaultCoord
|| minH
<= maxH
),
751 _T("min width/height must be less than max width/height!") );
760 void wxWindowBase
::SetVirtualSizeHints( int minW
, int minH
,
763 m_minVirtualWidth
= minW
;
764 m_maxVirtualWidth
= maxW
;
765 m_minVirtualHeight
= minH
;
766 m_maxVirtualHeight
= maxH
;
769 void wxWindowBase
::DoSetVirtualSize( int x
, int y
)
771 if ( m_minVirtualWidth
!= wxDefaultCoord
&& m_minVirtualWidth
> x
)
772 x
= m_minVirtualWidth
;
773 if ( m_maxVirtualWidth
!= wxDefaultCoord
&& m_maxVirtualWidth
< x
)
774 x
= m_maxVirtualWidth
;
775 if ( m_minVirtualHeight
!= wxDefaultCoord
&& m_minVirtualHeight
> y
)
776 y
= m_minVirtualHeight
;
777 if ( m_maxVirtualHeight
!= wxDefaultCoord
&& m_maxVirtualHeight
< y
)
778 y
= m_maxVirtualHeight
;
780 m_virtualSize
= wxSize(x
, y
);
783 wxSize wxWindowBase
::DoGetVirtualSize() const
785 // we should use the entire client area so if it is greater than our
786 // virtual size, expand it to fit (otherwise if the window is big enough we
787 // wouldn't be using parts of it)
788 wxSize size
= GetClientSize();
789 if ( m_virtualSize
.x
> size
.x
)
790 size
.x
= m_virtualSize
.x
;
792 if ( m_virtualSize
.y
>= size
.y
)
793 size
.y
= m_virtualSize
.y
;
798 void wxWindowBase
::DoGetScreenPosition(int *x
, int *y
) const
800 // screen position is the same as (0, 0) in client coords for non TLWs (and
801 // TLWs override this method)
807 ClientToScreen(x
, y
);
810 // ----------------------------------------------------------------------------
811 // show/hide/enable/disable the window
812 // ----------------------------------------------------------------------------
814 bool wxWindowBase
::Show(bool show
)
816 if ( show
!= m_isShown
)
828 bool wxWindowBase
::Enable(bool enable
)
830 if ( enable
!= m_isEnabled
)
832 m_isEnabled
= enable
;
842 bool wxWindowBase
::IsShownOnScreen() const
845 (GetParent() == NULL
|| GetParent()->IsShownOnScreen());
848 // ----------------------------------------------------------------------------
850 // ----------------------------------------------------------------------------
852 bool wxWindowBase
::IsTopLevel() const
857 // ----------------------------------------------------------------------------
858 // reparenting the window
859 // ----------------------------------------------------------------------------
861 void wxWindowBase
::AddChild(wxWindowBase
*child
)
863 wxCHECK_RET( child
, wxT("can't add a NULL child") );
865 // this should never happen and it will lead to a crash later if it does
866 // because RemoveChild() will remove only one node from the children list
867 // and the other(s) one(s) will be left with dangling pointers in them
868 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
870 GetChildren().Append((wxWindow
*)child
);
871 child
->SetParent(this);
874 void wxWindowBase
::RemoveChild(wxWindowBase
*child
)
876 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
878 GetChildren().DeleteObject((wxWindow
*)child
);
879 child
->SetParent(NULL
);
882 bool wxWindowBase
::Reparent(wxWindowBase
*newParent
)
884 wxWindow
*oldParent
= GetParent();
885 if ( newParent
== oldParent
)
891 // unlink this window from the existing parent.
894 oldParent
->RemoveChild(this);
898 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
901 // add it to the new one
904 newParent
->AddChild(this);
908 wxTopLevelWindows
.Append((wxWindow
*)this);
914 // ----------------------------------------------------------------------------
915 // event handler stuff
916 // ----------------------------------------------------------------------------
918 void wxWindowBase
::PushEventHandler(wxEvtHandler
*handler
)
920 wxEvtHandler
*handlerOld
= GetEventHandler();
922 handler
->SetNextHandler(handlerOld
);
925 GetEventHandler()->SetPreviousHandler(handler
);
927 SetEventHandler(handler
);
930 wxEvtHandler
*wxWindowBase
::PopEventHandler(bool deleteHandler
)
932 wxEvtHandler
*handlerA
= GetEventHandler();
935 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
936 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
939 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
940 SetEventHandler(handlerB
);
945 handlerA
= (wxEvtHandler
*)NULL
;
952 bool wxWindowBase
::RemoveEventHandler(wxEvtHandler
*handler
)
954 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
956 wxEvtHandler
*handlerPrev
= NULL
,
957 *handlerCur
= GetEventHandler();
960 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
962 if ( handlerCur
== handler
)
966 handlerPrev
->SetNextHandler(handlerNext
);
970 SetEventHandler(handlerNext
);
975 handlerNext
->SetPreviousHandler ( handlerPrev
);
978 handler
->SetNextHandler(NULL
);
979 handler
->SetPreviousHandler(NULL
);
984 handlerPrev
= handlerCur
;
985 handlerCur
= handlerNext
;
988 wxFAIL_MSG( _T("where has the event handler gone?") );
993 // ----------------------------------------------------------------------------
995 // ----------------------------------------------------------------------------
997 void wxWindowBase
::InheritAttributes()
999 const wxWindowBase
* const parent
= GetParent();
1003 // we only inherit attributes which had been explicitly set for the parent
1004 // which ensures that this only happens if the user really wants it and
1005 // not by default which wouldn't make any sense in modern GUIs where the
1006 // controls don't all use the same fonts (nor colours)
1007 if ( parent
->m_inheritFont
&& !m_hasFont
)
1008 SetFont(parent
->GetFont());
1010 // in addition, there is a possibility to explicitly forbid inheriting
1011 // colours at each class level by overriding ShouldInheritColours()
1012 if ( ShouldInheritColours() )
1014 if ( parent
->m_inheritFgCol
&& !m_hasFgCol
)
1015 SetForegroundColour(parent
->GetForegroundColour());
1017 // inheriting (solid) background colour is wrong as it totally breaks
1018 // any kind of themed backgrounds
1020 // instead, the controls should use the same background as their parent
1021 // (ideally by not drawing it at all)
1023 if ( parent
->m_inheritBgCol
&& !m_hasBgCol
)
1024 SetBackgroundColour(parent
->GetBackgroundColour());
1029 /* static */ wxVisualAttributes
1030 wxWindowBase
::GetClassDefaultAttributes(wxWindowVariant
WXUNUSED(variant
))
1032 // it is important to return valid values for all attributes from here,
1033 // GetXXX() below rely on this
1034 wxVisualAttributes attrs
;
1035 attrs
.font
= wxSystemSettings
::GetFont(wxSYS_DEFAULT_GUI_FONT
);
1036 attrs
.colFg
= wxSystemSettings
::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
1038 // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
1039 // the usual background colour than wxSYS_COLOUR_BTNFACE.
1040 // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
1041 // colour on other platforms.
1043 #if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
1044 attrs
.colBg
= wxSystemSettings
::GetColour(wxSYS_COLOUR_WINDOW
);
1046 attrs
.colBg
= wxSystemSettings
::GetColour(wxSYS_COLOUR_BTNFACE
);
1051 wxColour wxWindowBase
::GetBackgroundColour() const
1053 if ( !m_backgroundColour
.Ok() )
1055 wxASSERT_MSG( !m_hasBgCol
, _T("we have invalid explicit bg colour?") );
1057 // get our default background colour
1058 wxColour colBg
= GetDefaultAttributes().colBg
;
1060 // we must return some valid colour to avoid redoing this every time
1061 // and also to avoid surprizing the applications written for older
1062 // wxWidgets versions where GetBackgroundColour() always returned
1063 // something -- so give them something even if it doesn't make sense
1064 // for this window (e.g. it has a themed background)
1066 colBg
= GetClassDefaultAttributes().colBg
;
1071 return m_backgroundColour
;
1074 wxColour wxWindowBase
::GetForegroundColour() const
1076 // logic is the same as above
1077 if ( !m_hasFgCol
&& !m_foregroundColour
.Ok() )
1079 wxASSERT_MSG( !m_hasFgCol
, _T("we have invalid explicit fg colour?") );
1081 wxColour colFg
= GetDefaultAttributes().colFg
;
1084 colFg
= GetClassDefaultAttributes().colFg
;
1089 return m_foregroundColour
;
1092 bool wxWindowBase
::SetBackgroundColour( const wxColour
&colour
)
1094 if ( colour
== m_backgroundColour
)
1097 m_hasBgCol
= colour
.Ok();
1098 if ( m_backgroundStyle
!= wxBG_STYLE_CUSTOM
)
1099 m_backgroundStyle
= m_hasBgCol ? wxBG_STYLE_COLOUR
: wxBG_STYLE_SYSTEM
;
1101 m_inheritBgCol
= m_hasBgCol
;
1102 m_backgroundColour
= colour
;
1103 SetThemeEnabled( !m_hasBgCol
&& !m_foregroundColour
.Ok() );
1107 bool wxWindowBase
::SetForegroundColour( const wxColour
&colour
)
1109 if (colour
== m_foregroundColour
)
1112 m_hasFgCol
= colour
.Ok();
1113 m_inheritFgCol
= m_hasFgCol
;
1114 m_foregroundColour
= colour
;
1115 SetThemeEnabled( !m_hasFgCol
&& !m_backgroundColour
.Ok() );
1119 bool wxWindowBase
::SetCursor(const wxCursor
& cursor
)
1121 // setting an invalid cursor is ok, it means that we don't have any special
1123 if ( m_cursor
.IsSameAs(cursor
) )
1134 wxFont wxWindowBase
::GetFont() const
1136 // logic is the same as in GetBackgroundColour()
1139 wxASSERT_MSG( !m_hasFont
, _T("we have invalid explicit font?") );
1141 wxFont font
= GetDefaultAttributes().font
;
1143 font
= GetClassDefaultAttributes().font
;
1151 bool wxWindowBase
::SetFont(const wxFont
& font
)
1153 if ( font
== m_font
)
1160 m_hasFont
= font
.Ok();
1161 m_inheritFont
= m_hasFont
;
1163 InvalidateBestSize();
1170 void wxWindowBase
::SetPalette(const wxPalette
& pal
)
1172 m_hasCustomPalette
= true;
1175 // VZ: can anyone explain me what do we do here?
1176 wxWindowDC
d((wxWindow
*) this);
1180 wxWindow
*wxWindowBase
::GetAncestorWithCustomPalette() const
1182 wxWindow
*win
= (wxWindow
*)this;
1183 while ( win
&& !win
->HasCustomPalette() )
1185 win
= win
->GetParent();
1191 #endif // wxUSE_PALETTE
1194 void wxWindowBase
::SetCaret(wxCaret
*caret
)
1205 wxASSERT_MSG( m_caret
->GetWindow() == this,
1206 wxT("caret should be created associated to this window") );
1209 #endif // wxUSE_CARET
1211 #if wxUSE_VALIDATORS
1212 // ----------------------------------------------------------------------------
1214 // ----------------------------------------------------------------------------
1216 void wxWindowBase
::SetValidator(const wxValidator
& validator
)
1218 if ( m_windowValidator
)
1219 delete m_windowValidator
;
1221 m_windowValidator
= (wxValidator
*)validator
.Clone();
1223 if ( m_windowValidator
)
1224 m_windowValidator
->SetWindow(this);
1226 #endif // wxUSE_VALIDATORS
1228 // ----------------------------------------------------------------------------
1229 // update region stuff
1230 // ----------------------------------------------------------------------------
1232 wxRect wxWindowBase
::GetUpdateClientRect() const
1234 wxRegion rgnUpdate
= GetUpdateRegion();
1235 rgnUpdate
.Intersect(GetClientRect());
1236 wxRect rectUpdate
= rgnUpdate
.GetBox();
1237 wxPoint ptOrigin
= GetClientAreaOrigin();
1238 rectUpdate
.x
-= ptOrigin
.x
;
1239 rectUpdate
.y
-= ptOrigin
.y
;
1244 bool wxWindowBase
::DoIsExposed(int x
, int y
) const
1246 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1249 bool wxWindowBase
::DoIsExposed(int x
, int y
, int w
, int h
) const
1251 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1254 void wxWindowBase
::ClearBackground()
1256 // wxGTK uses its own version, no need to add never used code
1258 wxClientDC
dc((wxWindow
*)this);
1259 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1260 dc
.SetBackground(brush
);
1265 // ----------------------------------------------------------------------------
1266 // find child window by id or name
1267 // ----------------------------------------------------------------------------
1269 wxWindow
*wxWindowBase
::FindWindow(long id
) const
1271 if ( id
== m_windowId
)
1272 return (wxWindow
*)this;
1274 wxWindowBase
*res
= (wxWindow
*)NULL
;
1275 wxWindowList
::compatibility_iterator node
;
1276 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1278 wxWindowBase
*child
= node
->GetData();
1279 res
= child
->FindWindow( id
);
1282 return (wxWindow
*)res
;
1285 wxWindow
*wxWindowBase
::FindWindow(const wxString
& name
) const
1287 if ( name
== m_windowName
)
1288 return (wxWindow
*)this;
1290 wxWindowBase
*res
= (wxWindow
*)NULL
;
1291 wxWindowList
::compatibility_iterator node
;
1292 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1294 wxWindow
*child
= node
->GetData();
1295 res
= child
->FindWindow(name
);
1298 return (wxWindow
*)res
;
1302 // find any window by id or name or label: If parent is non-NULL, look through
1303 // children for a label or title matching the specified string. If NULL, look
1304 // through all top-level windows.
1306 // to avoid duplicating code we reuse the same helper function but with
1307 // different comparators
1309 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1310 const wxString
& label
, long id
);
1313 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1316 return win
->GetLabel() == label
;
1320 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1323 return win
->GetName() == label
;
1327 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1330 return win
->GetId() == id
;
1333 // recursive helper for the FindWindowByXXX() functions
1335 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1336 const wxString
& label
,
1338 wxFindWindowCmp cmp
)
1342 // see if this is the one we're looking for
1343 if ( (*cmp
)(parent
, label
, id
) )
1344 return (wxWindow
*)parent
;
1346 // It wasn't, so check all its children
1347 for ( wxWindowList
::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1349 node
= node
->GetNext() )
1351 // recursively check each child
1352 wxWindow
*win
= (wxWindow
*)node
->GetData();
1353 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1363 // helper for FindWindowByXXX()
1365 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1366 const wxString
& label
,
1368 wxFindWindowCmp cmp
)
1372 // just check parent and all its children
1373 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1376 // start at very top of wx's windows
1377 for ( wxWindowList
::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1379 node
= node
->GetNext() )
1381 // recursively check each window & its children
1382 wxWindow
*win
= node
->GetData();
1383 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1393 wxWindowBase
::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1395 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1400 wxWindowBase
::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1402 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1406 // fall back to the label
1407 win
= FindWindowByLabel(title
, parent
);
1415 wxWindowBase
::FindWindowById( long id
, const wxWindow
* parent
)
1417 return wxFindWindowHelper(parent
, wxEmptyString
, id
, wxFindWindowCmpIds
);
1420 // ----------------------------------------------------------------------------
1421 // dialog oriented functions
1422 // ----------------------------------------------------------------------------
1424 void wxWindowBase
::MakeModal(bool modal
)
1426 // Disable all other windows
1429 wxWindowList
::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1432 wxWindow
*win
= node
->GetData();
1434 win
->Enable(!modal
);
1436 node
= node
->GetNext();
1441 bool wxWindowBase
::Validate()
1443 #if wxUSE_VALIDATORS
1444 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1446 wxWindowList
::compatibility_iterator node
;
1447 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1449 wxWindowBase
*child
= node
->GetData();
1450 wxValidator
*validator
= child
->GetValidator();
1451 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1456 if ( recurse
&& !child
->Validate() )
1461 #endif // wxUSE_VALIDATORS
1466 bool wxWindowBase
::TransferDataToWindow()
1468 #if wxUSE_VALIDATORS
1469 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1471 wxWindowList
::compatibility_iterator node
;
1472 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1474 wxWindowBase
*child
= node
->GetData();
1475 wxValidator
*validator
= child
->GetValidator();
1476 if ( validator
&& !validator
->TransferToWindow() )
1478 wxLogWarning(_("Could not transfer data to window"));
1480 wxLog
::FlushActive();
1488 if ( !child
->TransferDataToWindow() )
1490 // warning already given
1495 #endif // wxUSE_VALIDATORS
1500 bool wxWindowBase
::TransferDataFromWindow()
1502 #if wxUSE_VALIDATORS
1503 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1505 wxWindowList
::compatibility_iterator node
;
1506 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1508 wxWindow
*child
= node
->GetData();
1509 wxValidator
*validator
= child
->GetValidator();
1510 if ( validator
&& !validator
->TransferFromWindow() )
1512 // nop warning here because the application is supposed to give
1513 // one itself - we don't know here what might have gone wrongly
1520 if ( !child
->TransferDataFromWindow() )
1522 // warning already given
1527 #endif // wxUSE_VALIDATORS
1532 void wxWindowBase
::InitDialog()
1534 wxInitDialogEvent
event(GetId());
1535 event
.SetEventObject( this );
1536 GetEventHandler()->ProcessEvent(event
);
1539 // ----------------------------------------------------------------------------
1540 // context-sensitive help support
1541 // ----------------------------------------------------------------------------
1545 // associate this help text with this window
1546 void wxWindowBase
::SetHelpText(const wxString
& text
)
1548 wxHelpProvider
*helpProvider
= wxHelpProvider
::Get();
1551 helpProvider
->AddHelp(this, text
);
1555 // associate this help text with all windows with the same id as this
1557 void wxWindowBase
::SetHelpTextForId(const wxString
& text
)
1559 wxHelpProvider
*helpProvider
= wxHelpProvider
::Get();
1562 helpProvider
->AddHelp(GetId(), text
);
1566 // get the help string associated with this window (may be empty)
1567 // default implementation forwards calls to the help provider
1569 wxWindowBase
::GetHelpTextAtPoint(const wxPoint
& WXUNUSED(pt
),
1570 wxHelpEvent
::Origin
WXUNUSED(origin
)) const
1573 wxHelpProvider
*helpProvider
= wxHelpProvider
::Get();
1576 text
= helpProvider
->GetHelp(this);
1582 // show help for this window
1583 void wxWindowBase
::OnHelp(wxHelpEvent
& event
)
1585 wxHelpProvider
*helpProvider
= wxHelpProvider
::Get();
1588 if ( helpProvider
->ShowHelpAtPoint(this, event
.GetPosition(), event
.GetOrigin()) )
1590 // skip the event.Skip() below
1598 #endif // wxUSE_HELP
1600 // ----------------------------------------------------------------------------
1602 // ----------------------------------------------------------------------------
1606 void wxWindowBase
::SetToolTip( const wxString
&tip
)
1608 // don't create the new tooltip if we already have one
1611 m_tooltip
->SetTip( tip
);
1615 SetToolTip( new wxToolTip( tip
) );
1618 // setting empty tooltip text does not remove the tooltip any more - use
1619 // SetToolTip((wxToolTip *)NULL) for this
1622 void wxWindowBase
::DoSetToolTip(wxToolTip
*tooltip
)
1624 if ( m_tooltip
!= tooltip
)
1629 m_tooltip
= tooltip
;
1633 #endif // wxUSE_TOOLTIPS
1635 // ----------------------------------------------------------------------------
1636 // constraints and sizers
1637 // ----------------------------------------------------------------------------
1639 #if wxUSE_CONSTRAINTS
1641 void wxWindowBase
::SetConstraints( wxLayoutConstraints
*constraints
)
1643 if ( m_constraints
)
1645 UnsetConstraints(m_constraints
);
1646 delete m_constraints
;
1648 m_constraints
= constraints
;
1649 if ( m_constraints
)
1651 // Make sure other windows know they're part of a 'meaningful relationship'
1652 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1653 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1654 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1655 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1656 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1657 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1658 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1659 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1660 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1661 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1662 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1663 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1664 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1665 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1666 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1667 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1671 // This removes any dangling pointers to this window in other windows'
1672 // constraintsInvolvedIn lists.
1673 void wxWindowBase
::UnsetConstraints(wxLayoutConstraints
*c
)
1677 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1678 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1679 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1680 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1681 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1682 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1683 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1684 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1685 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1686 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1687 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1688 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1689 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1690 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1691 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1692 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1696 // Back-pointer to other windows we're involved with, so if we delete this
1697 // window, we must delete any constraints we're involved with.
1698 void wxWindowBase
::AddConstraintReference(wxWindowBase
*otherWin
)
1700 if ( !m_constraintsInvolvedIn
)
1701 m_constraintsInvolvedIn
= new wxWindowList
;
1702 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1703 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1706 // REMOVE back-pointer to other windows we're involved with.
1707 void wxWindowBase
::RemoveConstraintReference(wxWindowBase
*otherWin
)
1709 if ( m_constraintsInvolvedIn
)
1710 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1713 // Reset any constraints that mention this window
1714 void wxWindowBase
::DeleteRelatedConstraints()
1716 if ( m_constraintsInvolvedIn
)
1718 wxWindowList
::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1721 wxWindow
*win
= node
->GetData();
1722 wxLayoutConstraints
*constr
= win
->GetConstraints();
1724 // Reset any constraints involving this window
1727 constr
->left
.ResetIfWin(this);
1728 constr
->top
.ResetIfWin(this);
1729 constr
->right
.ResetIfWin(this);
1730 constr
->bottom
.ResetIfWin(this);
1731 constr
->width
.ResetIfWin(this);
1732 constr
->height
.ResetIfWin(this);
1733 constr
->centreX
.ResetIfWin(this);
1734 constr
->centreY
.ResetIfWin(this);
1737 wxWindowList
::compatibility_iterator next
= node
->GetNext();
1738 m_constraintsInvolvedIn
->Erase(node
);
1742 delete m_constraintsInvolvedIn
;
1743 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1747 #endif // wxUSE_CONSTRAINTS
1749 void wxWindowBase
::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1751 if ( sizer
== m_windowSizer
)
1754 if ( m_windowSizer
)
1756 m_windowSizer
->SetContainingWindow(NULL
);
1759 delete m_windowSizer
;
1762 m_windowSizer
= sizer
;
1763 if ( m_windowSizer
)
1765 m_windowSizer
->SetContainingWindow((wxWindow
*)this);
1768 SetAutoLayout(m_windowSizer
!= NULL
);
1771 void wxWindowBase
::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1773 SetSizer( sizer
, deleteOld
);
1774 sizer
->SetSizeHints( (wxWindow
*) this );
1778 void wxWindowBase
::SetContainingSizer(wxSizer
* sizer
)
1780 // adding a window to a sizer twice is going to result in fatal and
1781 // hard to debug problems later because when deleting the second
1782 // associated wxSizerItem we're going to dereference a dangling
1783 // pointer; so try to detect this as early as possible
1784 wxASSERT_MSG( !sizer
|| m_containingSizer
!= sizer
,
1785 _T("Adding a window to the same sizer twice?") );
1787 m_containingSizer
= sizer
;
1790 #if wxUSE_CONSTRAINTS
1792 void wxWindowBase
::SatisfyConstraints()
1794 wxLayoutConstraints
*constr
= GetConstraints();
1795 bool wasOk
= constr
&& constr
->AreSatisfied();
1797 ResetConstraints(); // Mark all constraints as unevaluated
1801 // if we're a top level panel (i.e. our parent is frame/dialog), our
1802 // own constraints will never be satisfied any more unless we do it
1806 while ( noChanges
> 0 )
1808 LayoutPhase1(&noChanges
);
1812 LayoutPhase2(&noChanges
);
1815 #endif // wxUSE_CONSTRAINTS
1817 bool wxWindowBase
::Layout()
1819 // If there is a sizer, use it instead of the constraints
1823 GetVirtualSize(&w
, &h
);
1824 GetSizer()->SetDimension( 0, 0, w
, h
);
1826 #if wxUSE_CONSTRAINTS
1829 SatisfyConstraints(); // Find the right constraints values
1830 SetConstraintSizes(); // Recursively set the real window sizes
1837 #if wxUSE_CONSTRAINTS
1839 // first phase of the constraints evaluation: set our own constraints
1840 bool wxWindowBase
::LayoutPhase1(int *noChanges
)
1842 wxLayoutConstraints
*constr
= GetConstraints();
1844 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1847 // second phase: set the constraints for our children
1848 bool wxWindowBase
::LayoutPhase2(int *noChanges
)
1855 // Layout grand children
1861 // Do a phase of evaluating child constraints
1862 bool wxWindowBase
::DoPhase(int phase
)
1864 // the list containing the children for which the constraints are already
1866 wxWindowList succeeded
;
1868 // the max number of iterations we loop before concluding that we can't set
1870 static const int maxIterations
= 500;
1872 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1876 // loop over all children setting their constraints
1877 for ( wxWindowList
::compatibility_iterator node
= GetChildren().GetFirst();
1879 node
= node
->GetNext() )
1881 wxWindow
*child
= node
->GetData();
1882 if ( child
->IsTopLevel() )
1884 // top level children are not inside our client area
1888 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1890 // this one is either already ok or nothing we can do about it
1894 int tempNoChanges
= 0;
1895 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1896 : child
->LayoutPhase2(&tempNoChanges
);
1897 noChanges
+= tempNoChanges
;
1901 succeeded
.Append(child
);
1907 // constraints are set
1915 void wxWindowBase
::ResetConstraints()
1917 wxLayoutConstraints
*constr
= GetConstraints();
1920 constr
->left
.SetDone(false);
1921 constr
->top
.SetDone(false);
1922 constr
->right
.SetDone(false);
1923 constr
->bottom
.SetDone(false);
1924 constr
->width
.SetDone(false);
1925 constr
->height
.SetDone(false);
1926 constr
->centreX
.SetDone(false);
1927 constr
->centreY
.SetDone(false);
1930 wxWindowList
::compatibility_iterator node
= GetChildren().GetFirst();
1933 wxWindow
*win
= node
->GetData();
1934 if ( !win
->IsTopLevel() )
1935 win
->ResetConstraints();
1936 node
= node
->GetNext();
1940 // Need to distinguish between setting the 'fake' size for windows and sizers,
1941 // and setting the real values.
1942 void wxWindowBase
::SetConstraintSizes(bool recurse
)
1944 wxLayoutConstraints
*constr
= GetConstraints();
1945 if ( constr
&& constr
->AreSatisfied() )
1947 int x
= constr
->left
.GetValue();
1948 int y
= constr
->top
.GetValue();
1949 int w
= constr
->width
.GetValue();
1950 int h
= constr
->height
.GetValue();
1952 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1953 (constr
->height
.GetRelationship() != wxAsIs
) )
1955 SetSize(x
, y
, w
, h
);
1959 // If we don't want to resize this window, just move it...
1965 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1966 GetClassInfo()->GetClassName(),
1972 wxWindowList
::compatibility_iterator node
= GetChildren().GetFirst();
1975 wxWindow
*win
= node
->GetData();
1976 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1977 win
->SetConstraintSizes();
1978 node
= node
->GetNext();
1983 // Only set the size/position of the constraint (if any)
1984 void wxWindowBase
::SetSizeConstraint(int x
, int y
, int w
, int h
)
1986 wxLayoutConstraints
*constr
= GetConstraints();
1989 if ( x
!= wxDefaultCoord
)
1991 constr
->left
.SetValue(x
);
1992 constr
->left
.SetDone(true);
1994 if ( y
!= wxDefaultCoord
)
1996 constr
->top
.SetValue(y
);
1997 constr
->top
.SetDone(true);
1999 if ( w
!= wxDefaultCoord
)
2001 constr
->width
.SetValue(w
);
2002 constr
->width
.SetDone(true);
2004 if ( h
!= wxDefaultCoord
)
2006 constr
->height
.SetValue(h
);
2007 constr
->height
.SetDone(true);
2012 void wxWindowBase
::MoveConstraint(int x
, int y
)
2014 wxLayoutConstraints
*constr
= GetConstraints();
2017 if ( x
!= wxDefaultCoord
)
2019 constr
->left
.SetValue(x
);
2020 constr
->left
.SetDone(true);
2022 if ( y
!= wxDefaultCoord
)
2024 constr
->top
.SetValue(y
);
2025 constr
->top
.SetDone(true);
2030 void wxWindowBase
::GetSizeConstraint(int *w
, int *h
) const
2032 wxLayoutConstraints
*constr
= GetConstraints();
2035 *w
= constr
->width
.GetValue();
2036 *h
= constr
->height
.GetValue();
2042 void wxWindowBase
::GetClientSizeConstraint(int *w
, int *h
) const
2044 wxLayoutConstraints
*constr
= GetConstraints();
2047 *w
= constr
->width
.GetValue();
2048 *h
= constr
->height
.GetValue();
2051 GetClientSize(w
, h
);
2054 void wxWindowBase
::GetPositionConstraint(int *x
, int *y
) const
2056 wxLayoutConstraints
*constr
= GetConstraints();
2059 *x
= constr
->left
.GetValue();
2060 *y
= constr
->top
.GetValue();
2066 #endif // wxUSE_CONSTRAINTS
2068 void wxWindowBase
::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
2070 // don't do it for the dialogs/frames - they float independently of their
2072 if ( !IsTopLevel() )
2074 wxWindow
*parent
= GetParent();
2075 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
2077 wxPoint
pt(parent
->GetClientAreaOrigin());
2084 // ----------------------------------------------------------------------------
2085 // Update UI processing
2086 // ----------------------------------------------------------------------------
2088 void wxWindowBase
::UpdateWindowUI(long flags
)
2090 wxUpdateUIEvent
event(GetId());
2091 event
.SetEventObject(this);
2093 if ( GetEventHandler()->ProcessEvent(event
) )
2095 DoUpdateWindowUI(event
);
2098 if (flags
& wxUPDATE_UI_RECURSE
)
2100 wxWindowList
::compatibility_iterator node
= GetChildren().GetFirst();
2103 wxWindow
* child
= (wxWindow
*) node
->GetData();
2104 child
->UpdateWindowUI(flags
);
2105 node
= node
->GetNext();
2110 // do the window-specific processing after processing the update event
2111 void wxWindowBase
::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
2113 if ( event
.GetSetEnabled() )
2114 Enable(event
.GetEnabled());
2116 if ( event
.GetSetShown() )
2117 Show(event
.GetShown());
2120 // ----------------------------------------------------------------------------
2121 // dialog units translations
2122 // ----------------------------------------------------------------------------
2124 wxPoint wxWindowBase
::ConvertPixelsToDialog(const wxPoint
& pt
)
2126 int charWidth
= GetCharWidth();
2127 int charHeight
= GetCharHeight();
2128 wxPoint pt2
= wxDefaultPosition
;
2129 if (pt
.x
!= wxDefaultCoord
)
2130 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
);
2131 if (pt
.y
!= wxDefaultCoord
)
2132 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
);
2137 wxPoint wxWindowBase
::ConvertDialogToPixels(const wxPoint
& pt
)
2139 int charWidth
= GetCharWidth();
2140 int charHeight
= GetCharHeight();
2141 wxPoint pt2
= wxDefaultPosition
;
2142 if (pt
.x
!= wxDefaultCoord
)
2143 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4);
2144 if (pt
.y
!= wxDefaultCoord
)
2145 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8);
2150 // ----------------------------------------------------------------------------
2152 // ----------------------------------------------------------------------------
2154 // propagate the colour change event to the subwindows
2155 void wxWindowBase
::OnSysColourChanged(wxSysColourChangedEvent
& event
)
2157 wxWindowList
::compatibility_iterator node
= GetChildren().GetFirst();
2160 // Only propagate to non-top-level windows
2161 wxWindow
*win
= node
->GetData();
2162 if ( !win
->IsTopLevel() )
2164 wxSysColourChangedEvent event2
;
2165 event
.SetEventObject(win
);
2166 win
->GetEventHandler()->ProcessEvent(event2
);
2169 node
= node
->GetNext();
2175 // the default action is to populate dialog with data when it's created,
2176 // and nudge the UI into displaying itself correctly in case
2177 // we've turned the wxUpdateUIEvents frequency down low.
2178 void wxWindowBase
::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
2180 TransferDataToWindow();
2182 // Update the UI at this point
2183 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
2186 // methods for drawing the sizers in a visible way
2189 static void DrawSizers(wxWindowBase
*win
);
2191 static void DrawBorder(wxWindowBase
*win
, const wxRect
& rect
, bool fill
= false)
2193 wxClientDC
dc((wxWindow
*)win
);
2194 dc
.SetPen(*wxRED_PEN
);
2195 dc
.SetBrush(fill ?
wxBrush(*wxRED
, wxCROSSDIAG_HATCH
): *wxTRANSPARENT_BRUSH
);
2196 dc
.DrawRectangle(rect
.Deflate(1, 1));
2199 static void DrawSizer(wxWindowBase
*win
, wxSizer
*sizer
)
2201 const wxSizerItemList
& items
= sizer
->GetChildren();
2202 for ( wxSizerItemList
::const_iterator i
= items
.begin(),
2207 wxSizerItem
*item
= *i
;
2208 if ( item
->IsSizer() )
2210 DrawBorder(win
, item
->GetRect().Deflate(2));
2211 DrawSizer(win
, item
->GetSizer());
2213 else if ( item
->IsSpacer() )
2215 DrawBorder(win
, item
->GetRect().Deflate(2), true);
2217 else if ( item
->IsWindow() )
2219 DrawSizers(item
->GetWindow());
2224 static void DrawSizers(wxWindowBase
*win
)
2226 wxSizer
*sizer
= win
->GetSizer();
2229 DrawBorder(win
, win
->GetClientSize());
2230 DrawSizer(win
, sizer
);
2232 else // no sizer, still recurse into the children
2234 const wxWindowList
& children
= win
->GetChildren();
2235 for ( wxWindowList
::const_iterator i
= children
.begin(),
2236 end
= children
.end();
2245 #endif // __WXDEBUG__
2247 // process special middle clicks
2248 void wxWindowBase
::OnMiddleClick( wxMouseEvent
& event
)
2250 if ( event
.ControlDown() && event
.AltDown() )
2253 // Ctrl-Alt-Shift-mclick makes the sizers visible in debug builds
2254 if ( event
.ShiftDown() )
2259 #endif // __WXDEBUG__
2262 // don't translate these strings, they're for diagnostics purposes only
2264 msg
.Printf(_T("wxWidgets Library (%s port)\n")
2265 _T("Version %d.%d.%d%s%s, compiled at %s %s\n")
2266 _T("Runtime version of toolkit used is %d.%d.%s\n")
2267 _T("Copyright (c) 1995-2006 wxWidgets team"),
2268 wxPlatformInfo
::Get().GetPortIdName().c_str(),
2284 wxPlatformInfo
::Get().GetToolkitMajorVersion(),
2285 wxPlatformInfo
::Get().GetToolkitMinorVersion(),
2287 wxString
::Format(_T("\nThe compile-time GTK+ version is %d.%d.%d."), GTK_MAJOR_VERSION
, GTK_MINOR_VERSION
, GTK_MICRO_VERSION
).c_str()
2293 wxMessageBox(msg
, _T("wxWidgets information"),
2294 wxICON_INFORMATION
| wxOK
,
2298 #endif // wxUSE_MSGDLG
2304 // ----------------------------------------------------------------------------
2306 // ----------------------------------------------------------------------------
2308 #if wxUSE_ACCESSIBILITY
2309 void wxWindowBase
::SetAccessible(wxAccessible
* accessible
)
2311 if (m_accessible
&& (accessible
!= m_accessible
))
2312 delete m_accessible
;
2313 m_accessible
= accessible
;
2315 m_accessible
->SetWindow((wxWindow
*) this);
2318 // Returns the accessible object, creating if necessary.
2319 wxAccessible
* wxWindowBase
::GetOrCreateAccessible()
2322 m_accessible
= CreateAccessible();
2323 return m_accessible
;
2326 // Override to create a specific accessible object.
2327 wxAccessible
* wxWindowBase
::CreateAccessible()
2329 return new wxWindowAccessible((wxWindow
*) this);
2334 // ----------------------------------------------------------------------------
2335 // list classes implementation
2336 // ----------------------------------------------------------------------------
2340 #include "wx/listimpl.cpp"
2341 WX_DEFINE_LIST(wxWindowList
)
2345 void wxWindowListNode
::DeleteData()
2347 delete (wxWindow
*)GetData();
2350 #endif // wxUSE_STL/!wxUSE_STL
2352 // ----------------------------------------------------------------------------
2354 // ----------------------------------------------------------------------------
2356 wxBorder wxWindowBase
::GetBorder(long flags
) const
2358 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2359 if ( border
== wxBORDER_DEFAULT
)
2361 border
= GetDefaultBorder();
2367 wxBorder wxWindowBase
::GetDefaultBorder() const
2369 return wxBORDER_NONE
;
2372 // ----------------------------------------------------------------------------
2374 // ----------------------------------------------------------------------------
2376 wxHitTest wxWindowBase
::DoHitTest(wxCoord x
, wxCoord y
) const
2378 // here we just check if the point is inside the window or not
2380 // check the top and left border first
2381 bool outside
= x
< 0 || y
< 0;
2384 // check the right and bottom borders too
2385 wxSize size
= GetSize();
2386 outside
= x
>= size
.x
|| y
>= size
.y
;
2389 return outside ? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2392 // ----------------------------------------------------------------------------
2394 // ----------------------------------------------------------------------------
2396 struct WXDLLEXPORT wxWindowNext
2400 } *wxWindowBase
::ms_winCaptureNext
= NULL
;
2401 wxWindow
*wxWindowBase
::ms_winCaptureCurrent
= NULL
;
2402 bool wxWindowBase
::ms_winCaptureChanging
= false;
2404 void wxWindowBase
::CaptureMouse()
2406 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), wx_static_cast(void*, this));
2408 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive CaptureMouse call?") );
2410 ms_winCaptureChanging
= true;
2412 wxWindow
*winOld
= GetCapture();
2415 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2418 wxWindowNext
*item
= new wxWindowNext
;
2420 item
->next
= ms_winCaptureNext
;
2421 ms_winCaptureNext
= item
;
2423 //else: no mouse capture to save
2426 ms_winCaptureCurrent
= (wxWindow
*)this;
2428 ms_winCaptureChanging
= false;
2431 void wxWindowBase
::ReleaseMouse()
2433 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), wx_static_cast(void*, this));
2435 wxASSERT_MSG( !ms_winCaptureChanging
, _T("recursive ReleaseMouse call?") );
2437 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2439 ms_winCaptureChanging
= true;
2442 ms_winCaptureCurrent
= NULL
;
2444 if ( ms_winCaptureNext
)
2446 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2447 ms_winCaptureCurrent
= ms_winCaptureNext
->win
;
2449 wxWindowNext
*item
= ms_winCaptureNext
;
2450 ms_winCaptureNext
= item
->next
;
2453 //else: stack is empty, no previous capture
2455 ms_winCaptureChanging
= false;
2457 wxLogTrace(_T("mousecapture"),
2458 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2459 wx_static_cast(void*, GetCapture()));
2462 static void DoNotifyWindowAboutCaptureLost(wxWindow
*win
)
2464 wxMouseCaptureLostEvent
event(win
->GetId());
2465 event
.SetEventObject(win
);
2466 if ( !win
->GetEventHandler()->ProcessEvent(event
) )
2468 wxFAIL_MSG( _T("window that captured the mouse didn't process wxEVT_MOUSE_CAPTURE_LOST") );
2473 void wxWindowBase
::NotifyCaptureLost()
2475 // don't do anything if capture lost was expected, i.e. resulted from
2476 // a wx call to ReleaseMouse or CaptureMouse:
2477 if ( ms_winCaptureChanging
)
2480 // if the capture was lost unexpectedly, notify every window that has
2481 // capture (on stack or current) about it and clear the stack:
2483 if ( ms_winCaptureCurrent
)
2485 DoNotifyWindowAboutCaptureLost(ms_winCaptureCurrent
);
2486 ms_winCaptureCurrent
= NULL
;
2489 while ( ms_winCaptureNext
)
2491 wxWindowNext
*item
= ms_winCaptureNext
;
2492 ms_winCaptureNext
= item
->next
;
2494 DoNotifyWindowAboutCaptureLost(item
->win
);
2503 wxWindowBase
::RegisterHotKey(int WXUNUSED(hotkeyId
),
2504 int WXUNUSED(modifiers
),
2505 int WXUNUSED(keycode
))
2511 bool wxWindowBase
::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2517 #endif // wxUSE_HOTKEY
2519 // ----------------------------------------------------------------------------
2521 // ----------------------------------------------------------------------------
2523 bool wxWindowBase
::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2525 #if wxUSE_VALIDATORS
2526 // Can only use the validator of the window which
2527 // is receiving the event
2528 if ( event
.GetEventObject() == this )
2530 wxValidator
*validator
= GetValidator();
2531 if ( validator
&& validator
->ProcessEvent(event
) )
2536 #endif // wxUSE_VALIDATORS
2541 bool wxWindowBase
::TryParent(wxEvent
& event
)
2543 // carry on up the parent-child hierarchy if the propagation count hasn't
2545 if ( event
.ShouldPropagate() )
2547 // honour the requests to stop propagation at this window: this is
2548 // used by the dialogs, for example, to prevent processing the events
2549 // from the dialog controls in the parent frame which rarely, if ever,
2551 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2553 wxWindow
*parent
= GetParent();
2554 if ( parent
&& !parent
->IsBeingDeleted() )
2556 wxPropagateOnce
propagateOnce(event
);
2558 return parent
->GetEventHandler()->ProcessEvent(event
);
2563 return wxEvtHandler
::TryParent(event
);
2566 // ----------------------------------------------------------------------------
2567 // keyboard navigation
2568 // ----------------------------------------------------------------------------
2570 // Navigates in the specified direction.
2571 bool wxWindowBase
::Navigate(int flags
)
2573 wxNavigationKeyEvent eventNav
;
2574 eventNav
.SetFlags(flags
);
2575 eventNav
.SetEventObject(this);
2576 if ( GetParent()->GetEventHandler()->ProcessEvent(eventNav
) )
2583 void wxWindowBase
::DoMoveInTabOrder(wxWindow
*win
, MoveKind move
)
2585 // check that we're not a top level window
2586 wxCHECK_RET( GetParent(),
2587 _T("MoveBefore/AfterInTabOrder() don't work for TLWs!") );
2589 // detect the special case when we have nothing to do anyhow and when the
2590 // code below wouldn't work
2594 // find the target window in the siblings list
2595 wxWindowList
& siblings
= GetParent()->GetChildren();
2596 wxWindowList
::compatibility_iterator i
= siblings
.Find(win
);
2597 wxCHECK_RET( i
, _T("MoveBefore/AfterInTabOrder(): win is not a sibling") );
2599 // unfortunately, when wxUSE_STL == 1 DetachNode() is not implemented so we
2600 // can't just move the node around
2601 wxWindow
*self
= (wxWindow
*)this;
2602 siblings
.DeleteObject(self
);
2603 if ( move
== MoveAfter
)
2610 siblings
.Insert(i
, self
);
2612 else // MoveAfter and win was the last sibling
2614 siblings
.Append(self
);
2618 // ----------------------------------------------------------------------------
2620 // ----------------------------------------------------------------------------
2622 /*static*/ wxWindow
* wxWindowBase
::FindFocus()
2624 wxWindowBase
*win
= DoFindFocus();
2625 return win ? win
->GetMainWindowOfCompositeControl() : NULL
;
2628 // ----------------------------------------------------------------------------
2630 // ----------------------------------------------------------------------------
2632 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2634 while ( win
&& !win
->IsTopLevel() )
2635 win
= win
->GetParent();
2640 #if wxUSE_ACCESSIBILITY
2641 // ----------------------------------------------------------------------------
2642 // accessible object for windows
2643 // ----------------------------------------------------------------------------
2645 // Can return either a child object, or an integer
2646 // representing the child element, starting from 1.
2647 wxAccStatus wxWindowAccessible
::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2649 wxASSERT( GetWindow() != NULL
);
2653 return wxACC_NOT_IMPLEMENTED
;
2656 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2657 wxAccStatus wxWindowAccessible
::GetLocation(wxRect
& rect
, int elementId
)
2659 wxASSERT( GetWindow() != NULL
);
2663 wxWindow
* win
= NULL
;
2670 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2672 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2679 rect
= win
->GetRect();
2680 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2681 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2685 return wxACC_NOT_IMPLEMENTED
;
2688 // Navigates from fromId to toId/toObject.
2689 wxAccStatus wxWindowAccessible
::Navigate(wxNavDir navDir
, int fromId
,
2690 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2692 wxASSERT( GetWindow() != NULL
);
2698 case wxNAVDIR_FIRSTCHILD
:
2700 if (GetWindow()->GetChildren().GetCount() == 0)
2702 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2703 *toObject
= childWindow
->GetOrCreateAccessible();
2707 case wxNAVDIR_LASTCHILD
:
2709 if (GetWindow()->GetChildren().GetCount() == 0)
2711 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2712 *toObject
= childWindow
->GetOrCreateAccessible();
2716 case wxNAVDIR_RIGHT
:
2720 wxWindowList
::compatibility_iterator node
=
2721 wxWindowList
::compatibility_iterator();
2724 // Can't navigate to sibling of this window
2725 // if we're a top-level window.
2726 if (!GetWindow()->GetParent())
2727 return wxACC_NOT_IMPLEMENTED
;
2729 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2733 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2734 node
= GetWindow()->GetChildren().Item(fromId
-1);
2737 if (node
&& node
->GetNext())
2739 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2740 *toObject
= nextWindow
->GetOrCreateAccessible();
2748 case wxNAVDIR_PREVIOUS
:
2750 wxWindowList
::compatibility_iterator node
=
2751 wxWindowList
::compatibility_iterator();
2754 // Can't navigate to sibling of this window
2755 // if we're a top-level window.
2756 if (!GetWindow()->GetParent())
2757 return wxACC_NOT_IMPLEMENTED
;
2759 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2763 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2764 node
= GetWindow()->GetChildren().Item(fromId
-1);
2767 if (node
&& node
->GetPrevious())
2769 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2770 *toObject
= previousWindow
->GetOrCreateAccessible();
2778 return wxACC_NOT_IMPLEMENTED
;
2781 // Gets the name of the specified object.
2782 wxAccStatus wxWindowAccessible
::GetName(int childId
, wxString
* name
)
2784 wxASSERT( GetWindow() != NULL
);
2790 // If a child, leave wxWidgets to call the function on the actual
2793 return wxACC_NOT_IMPLEMENTED
;
2795 // This will eventually be replaced by specialised
2796 // accessible classes, one for each kind of wxWidgets
2797 // control or window.
2799 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2800 title
= ((wxButton
*) GetWindow())->GetLabel();
2803 title
= GetWindow()->GetName();
2811 return wxACC_NOT_IMPLEMENTED
;
2814 // Gets the number of children.
2815 wxAccStatus wxWindowAccessible
::GetChildCount(int* childId
)
2817 wxASSERT( GetWindow() != NULL
);
2821 *childId
= (int) GetWindow()->GetChildren().GetCount();
2825 // Gets the specified child (starting from 1).
2826 // If *child is NULL and return value is wxACC_OK,
2827 // this means that the child is a simple element and
2828 // not an accessible object.
2829 wxAccStatus wxWindowAccessible
::GetChild(int childId
, wxAccessible
** child
)
2831 wxASSERT( GetWindow() != NULL
);
2841 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2844 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2845 *child
= childWindow
->GetOrCreateAccessible();
2852 // Gets the parent, or NULL.
2853 wxAccStatus wxWindowAccessible
::GetParent(wxAccessible
** parent
)
2855 wxASSERT( GetWindow() != NULL
);
2859 wxWindow
* parentWindow
= GetWindow()->GetParent();
2867 *parent
= parentWindow
->GetOrCreateAccessible();
2875 // Performs the default action. childId is 0 (the action for this object)
2876 // or > 0 (the action for a child).
2877 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2878 // window (e.g. an edit control).
2879 wxAccStatus wxWindowAccessible
::DoDefaultAction(int WXUNUSED(childId
))
2881 wxASSERT( GetWindow() != NULL
);
2885 return wxACC_NOT_IMPLEMENTED
;
2888 // Gets the default action for this object (0) or > 0 (the action for a child).
2889 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2890 // string if there is no action.
2891 // The retrieved string describes the action that is performed on an object,
2892 // not what the object does as a result. For example, a toolbar button that prints
2893 // a document has a default action of "Press" rather than "Prints the current document."
2894 wxAccStatus wxWindowAccessible
::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
2896 wxASSERT( GetWindow() != NULL
);
2900 return wxACC_NOT_IMPLEMENTED
;
2903 // Returns the description for this object or a child.
2904 wxAccStatus wxWindowAccessible
::GetDescription(int WXUNUSED(childId
), wxString
* description
)
2906 wxASSERT( GetWindow() != NULL
);
2910 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent
::Origin_Keyboard
));
2916 return wxACC_NOT_IMPLEMENTED
;
2919 // Returns help text for this object or a child, similar to tooltip text.
2920 wxAccStatus wxWindowAccessible
::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
2922 wxASSERT( GetWindow() != NULL
);
2926 wxString
ht(GetWindow()->GetHelpTextAtPoint(wxDefaultPosition
, wxHelpEvent
::Origin_Keyboard
));
2932 return wxACC_NOT_IMPLEMENTED
;
2935 // Returns the keyboard shortcut for this object or child.
2936 // Return e.g. ALT+K
2937 wxAccStatus wxWindowAccessible
::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
2939 wxASSERT( GetWindow() != NULL
);
2943 return wxACC_NOT_IMPLEMENTED
;
2946 // Returns a role constant.
2947 wxAccStatus wxWindowAccessible
::GetRole(int childId
, wxAccRole
* role
)
2949 wxASSERT( GetWindow() != NULL
);
2953 // If a child, leave wxWidgets to call the function on the actual
2956 return wxACC_NOT_IMPLEMENTED
;
2958 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2959 return wxACC_NOT_IMPLEMENTED
;
2961 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2962 return wxACC_NOT_IMPLEMENTED
;
2965 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2966 return wxACC_NOT_IMPLEMENTED
;
2969 //*role = wxROLE_SYSTEM_CLIENT;
2970 *role
= wxROLE_SYSTEM_CLIENT
;
2974 return wxACC_NOT_IMPLEMENTED
;
2978 // Returns a state constant.
2979 wxAccStatus wxWindowAccessible
::GetState(int childId
, long* state
)
2981 wxASSERT( GetWindow() != NULL
);
2985 // If a child, leave wxWidgets to call the function on the actual
2988 return wxACC_NOT_IMPLEMENTED
;
2990 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2991 return wxACC_NOT_IMPLEMENTED
;
2994 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2995 return wxACC_NOT_IMPLEMENTED
;
2998 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2999 return wxACC_NOT_IMPLEMENTED
;
3006 return wxACC_NOT_IMPLEMENTED
;
3010 // Returns a localized string representing the value for the object
3012 wxAccStatus wxWindowAccessible
::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
3014 wxASSERT( GetWindow() != NULL
);
3018 return wxACC_NOT_IMPLEMENTED
;
3021 // Selects the object or child.
3022 wxAccStatus wxWindowAccessible
::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
3024 wxASSERT( GetWindow() != NULL
);
3028 return wxACC_NOT_IMPLEMENTED
;
3031 // Gets the window with the keyboard focus.
3032 // If childId is 0 and child is NULL, no object in
3033 // this subhierarchy has the focus.
3034 // If this object has the focus, child should be 'this'.
3035 wxAccStatus wxWindowAccessible
::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
3037 wxASSERT( GetWindow() != NULL
);
3041 return wxACC_NOT_IMPLEMENTED
;
3045 // Gets a variant representing the selected children
3047 // Acceptable values:
3048 // - a null variant (IsNull() returns true)
3049 // - a list variant (GetType() == wxT("list")
3050 // - an integer representing the selected child element,
3051 // or 0 if this object is selected (GetType() == wxT("long")
3052 // - a "void*" pointer to a wxAccessible child object
3053 wxAccStatus wxWindowAccessible
::GetSelections(wxVariant
* WXUNUSED(selections
))
3055 wxASSERT( GetWindow() != NULL
);
3059 return wxACC_NOT_IMPLEMENTED
;
3061 #endif // wxUSE_VARIANT
3063 #endif // wxUSE_ACCESSIBILITY
3065 // ----------------------------------------------------------------------------
3067 // ----------------------------------------------------------------------------
3070 wxWindowBase
::AdjustForLayoutDirection(wxCoord x
,
3072 wxCoord widthTotal
) const
3074 if ( GetLayoutDirection() == wxLayout_RightToLeft
)
3076 x
= widthTotal
- x
- width
;