1 /////////////////////////////////////////////////////////////////////////////
2 // Name: common/window.cpp
3 // Purpose: common (to all ports) wxWindow functions
4 // Author: Julian Smart, Vadim Zeitlin
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
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"
51 #include "wx/layout.h"
52 #endif // wxUSE_CONSTRAINTS
56 #if wxUSE_DRAG_AND_DROP
58 #endif // wxUSE_DRAG_AND_DROP
60 #if wxUSE_ACCESSIBILITY
61 #include "wx/access.h"
65 #include "wx/cshelp.h"
69 #include "wx/tooltip.h"
70 #endif // wxUSE_TOOLTIPS
76 // ----------------------------------------------------------------------------
78 // ----------------------------------------------------------------------------
81 int wxWindowBase::ms_lastControlId
= 2000;
83 int wxWindowBase::ms_lastControlId
= -200;
86 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
88 // ----------------------------------------------------------------------------
90 // ----------------------------------------------------------------------------
92 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
93 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
94 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
95 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick
)
98 EVT_HELP(wxID_ANY
, wxWindowBase::OnHelp
)
103 // ============================================================================
104 // implementation of the common functionality of the wxWindow class
105 // ============================================================================
107 // ----------------------------------------------------------------------------
109 // ----------------------------------------------------------------------------
111 // the default initialization
112 wxWindowBase::wxWindowBase()
114 // no window yet, no parent nor children
115 m_parent
= (wxWindow
*)NULL
;
116 m_windowId
= wxID_ANY
;
118 // no constraints on the minimal window size
124 // window is created enabled but it's not visible yet
128 // the default event handler is just this window
129 m_eventHandler
= this;
133 m_windowValidator
= (wxValidator
*) NULL
;
134 #endif // wxUSE_VALIDATORS
136 // use the system default colours
137 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
138 m_foregroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
140 // don't set the font here for wxMSW as we don't call WM_SETFONT here and
141 // so the font is *not* really set - but calls to SetFont() later won't do
142 // anything because m_font appears to be already set!
144 m_font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
147 // the colours/fonts are default for now
152 m_isBeingDeleted
= false;
158 #if wxUSE_CONSTRAINTS
159 // no constraints whatsoever
160 m_constraints
= (wxLayoutConstraints
*) NULL
;
161 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
162 #endif // wxUSE_CONSTRAINTS
164 m_windowSizer
= (wxSizer
*) NULL
;
165 m_containingSizer
= (wxSizer
*) NULL
;
166 m_autoLayout
= false;
168 #if wxUSE_DRAG_AND_DROP
169 m_dropTarget
= (wxDropTarget
*)NULL
;
170 #endif // wxUSE_DRAG_AND_DROP
173 m_tooltip
= (wxToolTip
*)NULL
;
174 #endif // wxUSE_TOOLTIPS
177 m_caret
= (wxCaret
*)NULL
;
178 #endif // wxUSE_CARET
181 m_hasCustomPalette
= false;
182 #endif // wxUSE_PALETTE
184 #if wxUSE_ACCESSIBILITY
188 m_virtualSize
= wxDefaultSize
;
193 m_maxVirtualHeight
= -1;
195 // Whether we're using the current theme for this window (wxGTK only for now)
196 m_themeEnabled
= false;
199 // common part of window creation process
200 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
202 const wxPoint
& WXUNUSED(pos
),
203 const wxSize
& WXUNUSED(size
),
205 const wxValidator
& wxVALIDATOR_PARAM(validator
),
206 const wxString
& name
)
209 // wxGTK doesn't allow to create controls with static box as the parent so
210 // this will result in a crash when the program is ported to wxGTK so warn
213 // if you get this assert, the correct solution is to create the controls
214 // as siblings of the static box
215 wxASSERT_MSG( !parent
|| !wxDynamicCast(parent
, wxStaticBox
),
216 _T("wxStaticBox can't be used as a window parent!") );
217 #endif // wxUSE_STATBOX
219 // ids are limited to 16 bits under MSW so if you care about portability,
220 // it's not a good idea to use ids out of this range (and negative ids are
221 // reserved for wxWindows own usage)
222 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767),
223 _T("invalid id value") );
225 // generate a new id if the user doesn't care about it
226 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
229 SetWindowStyleFlag(style
);
233 SetValidator(validator
);
234 #endif // wxUSE_VALIDATORS
236 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
237 // have it too - like this it's possible to set it only in the top level
238 // dialog/frame and all children will inherit it by defult
239 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
241 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
247 // ----------------------------------------------------------------------------
249 // ----------------------------------------------------------------------------
252 wxWindowBase::~wxWindowBase()
254 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
256 // FIXME if these 2 cases result from programming errors in the user code
257 // we should probably assert here instead of silently fixing them
259 // Just in case the window has been Closed, but we're then deleting
260 // immediately: don't leave dangling pointers.
261 wxPendingDelete
.DeleteObject(this);
263 // Just in case we've loaded a top-level window via LoadNativeDialog but
264 // we weren't a dialog class
265 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
267 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
269 // reset the dangling pointer our parent window may keep to us
272 if ( m_parent
->GetDefaultItem() == this )
274 m_parent
->SetDefaultItem(NULL
);
277 m_parent
->RemoveChild(this);
282 #endif // wxUSE_CARET
285 delete m_windowValidator
;
286 #endif // wxUSE_VALIDATORS
288 #if wxUSE_CONSTRAINTS
289 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
290 // at deleted windows as they delete themselves.
291 DeleteRelatedConstraints();
295 // This removes any dangling pointers to this window in other windows'
296 // constraintsInvolvedIn lists.
297 UnsetConstraints(m_constraints
);
298 delete m_constraints
;
299 m_constraints
= NULL
;
301 #endif // wxUSE_CONSTRAINTS
303 if ( m_containingSizer
)
304 m_containingSizer
->Detach( (wxWindow
*)this );
306 delete m_windowSizer
;
308 #if wxUSE_DRAG_AND_DROP
310 #endif // wxUSE_DRAG_AND_DROP
314 #endif // wxUSE_TOOLTIPS
316 #if wxUSE_ACCESSIBILITY
321 bool wxWindowBase::Destroy()
328 bool wxWindowBase::Close(bool force
)
330 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
331 event
.SetEventObject(this);
332 event
.SetCanVeto(!force
);
334 // return false if window wasn't closed because the application vetoed the
336 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
339 bool wxWindowBase::DestroyChildren()
341 wxWindowList::compatibility_iterator node
;
344 // we iterate until the list becomes empty
345 node
= GetChildren().GetFirst();
349 wxWindow
*child
= node
->GetData();
351 // note that we really want to call delete and not ->Destroy() here
352 // because we want to delete the child immediately, before we are
353 // deleted, and delayed deletion would result in problems as our (top
354 // level) child could outlive its parent
357 wxASSERT_MSG( !GetChildren().Find(child
),
358 wxT("child didn't remove itself using RemoveChild()") );
364 // ----------------------------------------------------------------------------
365 // size/position related methods
366 // ----------------------------------------------------------------------------
368 // centre the window with respect to its parent in either (or both) directions
369 void wxWindowBase::Centre(int direction
)
371 // the position/size of the parent window or of the entire screen
373 int widthParent
, heightParent
;
375 wxWindow
*parent
= NULL
;
377 if ( !(direction
& wxCENTRE_ON_SCREEN
) )
379 // find the parent to centre this window on: it should be the
380 // immediate parent for the controls but the top level parent for the
381 // top level windows (like dialogs)
382 parent
= GetParent();
385 while ( parent
&& !parent
->IsTopLevel() )
387 parent
= parent
->GetParent();
391 // there is no wxTopLevelWindow under wxMotif yet
393 // we shouldn't center the dialog on the iconized window: under
394 // Windows, for example, this places it completely off the screen
397 wxTopLevelWindow
*winTop
= wxDynamicCast(parent
, wxTopLevelWindow
);
398 if ( winTop
&& winTop
->IsIconized() )
403 #endif // __WXMOTIF__
405 // did we find the parent?
409 direction
|= wxCENTRE_ON_SCREEN
;
413 if ( direction
& wxCENTRE_ON_SCREEN
)
415 // centre with respect to the whole screen
416 wxDisplaySize(&widthParent
, &heightParent
);
422 // centre on the parent
423 parent
->GetSize(&widthParent
, &heightParent
);
425 // adjust to the parents position
426 posParent
= parent
->GetPosition();
430 // centre inside the parents client rectangle
431 parent
->GetClientSize(&widthParent
, &heightParent
);
436 GetSize(&width
, &height
);
441 if ( direction
& wxHORIZONTAL
)
442 xNew
= (widthParent
- width
)/2;
444 if ( direction
& wxVERTICAL
)
445 yNew
= (heightParent
- height
)/2;
450 // Base size of the visible dimensions of the display
451 // to take into account the taskbar
452 wxRect rect
= wxGetClientDisplayRect();
453 wxSize
size (rect
.width
,rect
.height
);
455 // NB: in wxMSW, negative position may not neccessary mean "out of screen",
456 // but it may mean that the window is placed on other than the main
457 // display. Therefore we only make sure centered window is on the main display
458 // if the parent is at least partially present here.
459 if (posParent
.x
+ widthParent
>= 0) // if parent is (partially) on the main display
463 else if (xNew
+width
> size
.x
)
464 xNew
= size
.x
-width
-1;
466 if (posParent
.y
+ heightParent
>= 0) // if parent is (partially) on the main display
468 if (yNew
+height
> size
.y
)
469 yNew
= size
.y
-height
-1;
471 // Make certain that the title bar is initially visible
472 // always, even if this would push the bottom of the
473 // dialog of the visible area of the display
478 // move the window to this position (keeping the old size but using
479 // SetSize() and not Move() to allow xNew and/or yNew to be -1)
480 SetSize(xNew
, yNew
, width
, height
, wxSIZE_ALLOW_MINUS_ONE
);
483 // fits the window around the children
484 void wxWindowBase::Fit()
486 if ( GetChildren().GetCount() > 0 )
488 SetClientSize(DoGetBestSize());
490 //else: do nothing if we have no children
493 // fits virtual size (ie. scrolled area etc.) around children
494 void wxWindowBase::FitInside()
496 if ( GetChildren().GetCount() > 0 )
498 SetVirtualSize( GetBestVirtualSize() );
502 // return the size best suited for the current window
503 wxSize
wxWindowBase::DoGetBestSize() const
507 return m_windowSizer
->GetMinSize();
509 #if wxUSE_CONSTRAINTS
510 else if ( m_constraints
)
512 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
514 // our minimal acceptable size is such that all our windows fit inside
518 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
520 node
= node
->GetNext() )
522 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
525 // it's not normal that we have an unconstrained child, but
526 // what can we do about it?
530 int x
= c
->right
.GetValue(),
531 y
= c
->bottom
.GetValue();
539 // TODO: we must calculate the overlaps somehow, otherwise we
540 // will never return a size bigger than the current one :-(
543 return wxSize(maxX
, maxY
);
545 #endif // wxUSE_CONSTRAINTS
546 else if ( GetChildren().GetCount() > 0 )
548 // our minimal acceptable size is such that all our windows fit inside
552 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
554 node
= node
->GetNext() )
556 wxWindow
*win
= node
->GetData();
557 if ( win
->IsTopLevel()
559 || wxDynamicCast(win
, wxStatusBar
)
560 #endif // wxUSE_STATUSBAR
563 // dialogs and frames lie in different top level windows -
564 // don't deal with them here; as for the status bars, they
565 // don't lie in the client area at all
570 win
->GetPosition(&wx
, &wy
);
572 // if the window hadn't been positioned yet, assume that it is in
579 win
->GetSize(&ww
, &wh
);
580 if ( wx
+ ww
> maxX
)
582 if ( wy
+ wh
> maxY
)
586 // for compatibility with the old versions and because it really looks
587 // slightly more pretty like this, add a pad
591 return wxSize(maxX
, maxY
);
595 // for a generic window there is no natural best size - just use the
601 // by default the origin is not shifted
602 wxPoint
wxWindowBase::GetClientAreaOrigin() const
604 return wxPoint(0, 0);
607 // set the min/max size of the window
608 void wxWindowBase::SetSizeHints(int minW
, int minH
,
610 int WXUNUSED(incW
), int WXUNUSED(incH
))
612 // setting min width greater than max width leads to infinite loops under
613 // X11 and generally doesn't make any sense, so don't allow it
614 wxCHECK_RET( (minW
== -1 || maxW
== -1 || minW
<= maxW
) &&
615 (minH
== -1 || maxH
== -1 || minH
<= maxH
),
616 _T("min width/height must be less than max width/height!") );
624 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
627 m_minVirtualWidth
= minW
;
628 m_maxVirtualWidth
= maxW
;
629 m_minVirtualHeight
= minH
;
630 m_maxVirtualHeight
= maxH
;
633 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
635 if ( m_minVirtualWidth
!= -1 && m_minVirtualWidth
> x
)
636 x
= m_minVirtualWidth
;
637 if ( m_maxVirtualWidth
!= -1 && m_maxVirtualWidth
< x
)
638 x
= m_maxVirtualWidth
;
639 if ( m_minVirtualHeight
!= -1 && m_minVirtualHeight
> y
)
640 y
= m_minVirtualHeight
;
641 if ( m_maxVirtualHeight
!= -1 && m_maxVirtualHeight
< y
)
642 y
= m_maxVirtualHeight
;
644 m_virtualSize
= wxSize(x
, y
);
647 wxSize
wxWindowBase::DoGetVirtualSize() const
649 wxSize
s( GetClientSize() );
651 return wxSize( wxMax( m_virtualSize
.GetWidth(), s
.GetWidth() ),
652 wxMax( m_virtualSize
.GetHeight(), s
.GetHeight() ) );
655 // ----------------------------------------------------------------------------
656 // show/hide/enable/disable the window
657 // ----------------------------------------------------------------------------
659 bool wxWindowBase::Show(bool show
)
661 if ( show
!= m_isShown
)
673 bool wxWindowBase::Enable(bool enable
)
675 if ( enable
!= m_isEnabled
)
677 m_isEnabled
= enable
;
686 // ----------------------------------------------------------------------------
688 // ----------------------------------------------------------------------------
690 bool wxWindowBase::IsTopLevel() const
695 // ----------------------------------------------------------------------------
696 // reparenting the window
697 // ----------------------------------------------------------------------------
699 void wxWindowBase::AddChild(wxWindowBase
*child
)
701 wxCHECK_RET( child
, wxT("can't add a NULL child") );
703 // this should never happen and it will lead to a crash later if it does
704 // because RemoveChild() will remove only one node from the children list
705 // and the other(s) one(s) will be left with dangling pointers in them
706 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
708 GetChildren().Append((wxWindow
*)child
);
709 child
->SetParent(this);
712 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
714 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
716 GetChildren().DeleteObject((wxWindow
*)child
);
717 child
->SetParent(NULL
);
720 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
722 wxWindow
*oldParent
= GetParent();
723 if ( newParent
== oldParent
)
729 // unlink this window from the existing parent.
732 oldParent
->RemoveChild(this);
736 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
739 // add it to the new one
742 newParent
->AddChild(this);
746 wxTopLevelWindows
.Append((wxWindow
*)this);
752 // ----------------------------------------------------------------------------
753 // event handler stuff
754 // ----------------------------------------------------------------------------
756 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
758 wxEvtHandler
*handlerOld
= GetEventHandler();
760 handler
->SetNextHandler(handlerOld
);
763 GetEventHandler()->SetPreviousHandler(handler
);
765 SetEventHandler(handler
);
768 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
770 wxEvtHandler
*handlerA
= GetEventHandler();
773 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
774 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
777 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
778 SetEventHandler(handlerB
);
783 handlerA
= (wxEvtHandler
*)NULL
;
790 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
792 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
794 wxEvtHandler
*handlerPrev
= NULL
,
795 *handlerCur
= GetEventHandler();
798 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
800 if ( handlerCur
== handler
)
804 handlerPrev
->SetNextHandler(handlerNext
);
808 SetEventHandler(handlerNext
);
813 handlerNext
->SetPreviousHandler ( handlerPrev
);
816 handler
->SetNextHandler(NULL
);
817 handler
->SetPreviousHandler(NULL
);
822 handlerPrev
= handlerCur
;
823 handlerCur
= handlerNext
;
826 wxFAIL_MSG( _T("where has the event handler gone?") );
831 // ----------------------------------------------------------------------------
833 // ----------------------------------------------------------------------------
835 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
837 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
840 m_backgroundColour
= colour
;
847 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
849 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
852 m_foregroundColour
= colour
;
859 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
861 // setting an invalid cursor is ok, it means that we don't have any special
863 if ( m_cursor
== cursor
)
874 bool wxWindowBase::SetFont(const wxFont
& font
)
876 // don't try to set invalid font, always fall back to the default
877 const wxFont
& fontOk
= font
.Ok() ? font
: *wxSWISS_FONT
;
879 if ( fontOk
== m_font
)
894 void wxWindowBase::SetPalette(const wxPalette
& pal
)
896 m_hasCustomPalette
= true;
899 // VZ: can anyone explain me what do we do here?
900 wxWindowDC
d((wxWindow
*) this);
904 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
906 wxWindow
*win
= (wxWindow
*)this;
907 while ( win
&& !win
->HasCustomPalette() )
909 win
= win
->GetParent();
915 #endif // wxUSE_PALETTE
918 void wxWindowBase::SetCaret(wxCaret
*caret
)
929 wxASSERT_MSG( m_caret
->GetWindow() == this,
930 wxT("caret should be created associated to this window") );
933 #endif // wxUSE_CARET
936 // ----------------------------------------------------------------------------
938 // ----------------------------------------------------------------------------
940 void wxWindowBase::SetValidator(const wxValidator
& validator
)
942 if ( m_windowValidator
)
943 delete m_windowValidator
;
945 m_windowValidator
= (wxValidator
*)validator
.Clone();
947 if ( m_windowValidator
)
948 m_windowValidator
->SetWindow(this) ;
950 #endif // wxUSE_VALIDATORS
952 // ----------------------------------------------------------------------------
953 // update region stuff
954 // ----------------------------------------------------------------------------
956 wxRect
wxWindowBase::GetUpdateClientRect() const
958 wxRegion rgnUpdate
= GetUpdateRegion();
959 rgnUpdate
.Intersect(GetClientRect());
960 wxRect rectUpdate
= rgnUpdate
.GetBox();
961 wxPoint ptOrigin
= GetClientAreaOrigin();
962 rectUpdate
.x
-= ptOrigin
.x
;
963 rectUpdate
.y
-= ptOrigin
.y
;
968 bool wxWindowBase::IsExposed(int x
, int y
) const
970 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
973 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
975 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
978 void wxWindowBase::ClearBackground()
980 // wxGTK uses its own version, no need to add never used code
982 wxClientDC
dc((wxWindow
*)this);
983 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
984 dc
.SetBackground(brush
);
989 // ----------------------------------------------------------------------------
990 // find child window by id or name
991 // ----------------------------------------------------------------------------
993 wxWindow
*wxWindowBase::FindWindow( long id
)
995 if ( id
== m_windowId
)
996 return (wxWindow
*)this;
998 wxWindowBase
*res
= (wxWindow
*)NULL
;
999 wxWindowList::compatibility_iterator node
;
1000 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1002 wxWindowBase
*child
= node
->GetData();
1003 res
= child
->FindWindow( id
);
1006 return (wxWindow
*)res
;
1009 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
1011 if ( name
== m_windowName
)
1012 return (wxWindow
*)this;
1014 wxWindowBase
*res
= (wxWindow
*)NULL
;
1015 wxWindowList::compatibility_iterator node
;
1016 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1018 wxWindow
*child
= node
->GetData();
1019 res
= child
->FindWindow(name
);
1022 return (wxWindow
*)res
;
1026 // find any window by id or name or label: If parent is non-NULL, look through
1027 // children for a label or title matching the specified string. If NULL, look
1028 // through all top-level windows.
1030 // to avoid duplicating code we reuse the same helper function but with
1031 // different comparators
1033 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1034 const wxString
& label
, long id
);
1037 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1040 return win
->GetLabel() == label
;
1044 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1047 return win
->GetName() == label
;
1051 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1054 return win
->GetId() == id
;
1057 // recursive helper for the FindWindowByXXX() functions
1059 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1060 const wxString
& label
,
1062 wxFindWindowCmp cmp
)
1066 // see if this is the one we're looking for
1067 if ( (*cmp
)(parent
, label
, id
) )
1068 return (wxWindow
*)parent
;
1070 // It wasn't, so check all its children
1071 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1073 node
= node
->GetNext() )
1075 // recursively check each child
1076 wxWindow
*win
= (wxWindow
*)node
->GetData();
1077 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1087 // helper for FindWindowByXXX()
1089 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1090 const wxString
& label
,
1092 wxFindWindowCmp cmp
)
1096 // just check parent and all its children
1097 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1100 // start at very top of wx's windows
1101 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1103 node
= node
->GetNext() )
1105 // recursively check each window & its children
1106 wxWindow
*win
= node
->GetData();
1107 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1117 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1119 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1124 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1126 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1130 // fall back to the label
1131 win
= FindWindowByLabel(title
, parent
);
1139 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1141 return wxFindWindowHelper(parent
, _T(""), id
, wxFindWindowCmpIds
);
1144 // ----------------------------------------------------------------------------
1145 // dialog oriented functions
1146 // ----------------------------------------------------------------------------
1148 void wxWindowBase::MakeModal(bool modal
)
1150 // Disable all other windows
1153 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1156 wxWindow
*win
= node
->GetData();
1158 win
->Enable(!modal
);
1160 node
= node
->GetNext();
1165 bool wxWindowBase::Validate()
1167 #if wxUSE_VALIDATORS
1168 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1170 wxWindowList::compatibility_iterator node
;
1171 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1173 wxWindowBase
*child
= node
->GetData();
1174 wxValidator
*validator
= child
->GetValidator();
1175 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1180 if ( recurse
&& !child
->Validate() )
1185 #endif // wxUSE_VALIDATORS
1190 bool wxWindowBase::TransferDataToWindow()
1192 #if wxUSE_VALIDATORS
1193 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1195 wxWindowList::compatibility_iterator node
;
1196 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1198 wxWindowBase
*child
= node
->GetData();
1199 wxValidator
*validator
= child
->GetValidator();
1200 if ( validator
&& !validator
->TransferToWindow() )
1202 wxLogWarning(_("Could not transfer data to window"));
1204 wxLog::FlushActive();
1212 if ( !child
->TransferDataToWindow() )
1214 // warning already given
1219 #endif // wxUSE_VALIDATORS
1224 bool wxWindowBase::TransferDataFromWindow()
1226 #if wxUSE_VALIDATORS
1227 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1229 wxWindowList::compatibility_iterator node
;
1230 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1232 wxWindow
*child
= node
->GetData();
1233 wxValidator
*validator
= child
->GetValidator();
1234 if ( validator
&& !validator
->TransferFromWindow() )
1236 // nop warning here because the application is supposed to give
1237 // one itself - we don't know here what might have gone wrongly
1244 if ( !child
->TransferDataFromWindow() )
1246 // warning already given
1251 #endif // wxUSE_VALIDATORS
1256 void wxWindowBase::InitDialog()
1258 wxInitDialogEvent
event(GetId());
1259 event
.SetEventObject( this );
1260 GetEventHandler()->ProcessEvent(event
);
1263 // ----------------------------------------------------------------------------
1264 // context-sensitive help support
1265 // ----------------------------------------------------------------------------
1269 // associate this help text with this window
1270 void wxWindowBase::SetHelpText(const wxString
& text
)
1272 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1275 helpProvider
->AddHelp(this, text
);
1279 // associate this help text with all windows with the same id as this
1281 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1283 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1286 helpProvider
->AddHelp(GetId(), text
);
1290 // get the help string associated with this window (may be empty)
1291 wxString
wxWindowBase::GetHelpText() const
1294 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1297 text
= helpProvider
->GetHelp(this);
1303 // show help for this window
1304 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1306 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1309 if ( helpProvider
->ShowHelp(this) )
1311 // skip the event.Skip() below
1319 #endif // wxUSE_HELP
1321 // ----------------------------------------------------------------------------
1322 // tooltipsroot.Replace("\\", "/");
1323 // ----------------------------------------------------------------------------
1327 void wxWindowBase::SetToolTip( const wxString
&tip
)
1329 // don't create the new tooltip if we already have one
1332 m_tooltip
->SetTip( tip
);
1336 SetToolTip( new wxToolTip( tip
) );
1339 // setting empty tooltip text does not remove the tooltip any more - use
1340 // SetToolTip((wxToolTip *)NULL) for this
1343 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1348 m_tooltip
= tooltip
;
1351 #endif // wxUSE_TOOLTIPS
1353 // ----------------------------------------------------------------------------
1354 // constraints and sizers
1355 // ----------------------------------------------------------------------------
1357 #if wxUSE_CONSTRAINTS
1359 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1361 if ( m_constraints
)
1363 UnsetConstraints(m_constraints
);
1364 delete m_constraints
;
1366 m_constraints
= constraints
;
1367 if ( m_constraints
)
1369 // Make sure other windows know they're part of a 'meaningful relationship'
1370 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1371 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1372 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1373 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1374 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1375 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1376 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1377 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1378 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1379 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1380 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1381 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1382 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1383 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1384 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1385 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1389 // This removes any dangling pointers to this window in other windows'
1390 // constraintsInvolvedIn lists.
1391 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1395 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1396 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1397 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1398 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1399 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1400 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1401 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1402 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1403 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1404 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1405 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1406 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1407 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1408 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1409 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1410 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1414 // Back-pointer to other windows we're involved with, so if we delete this
1415 // window, we must delete any constraints we're involved with.
1416 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1418 if ( !m_constraintsInvolvedIn
)
1419 m_constraintsInvolvedIn
= new wxWindowList
;
1420 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1421 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1424 // REMOVE back-pointer to other windows we're involved with.
1425 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1427 if ( m_constraintsInvolvedIn
)
1428 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1431 // Reset any constraints that mention this window
1432 void wxWindowBase::DeleteRelatedConstraints()
1434 if ( m_constraintsInvolvedIn
)
1436 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1439 wxWindow
*win
= node
->GetData();
1440 wxLayoutConstraints
*constr
= win
->GetConstraints();
1442 // Reset any constraints involving this window
1445 constr
->left
.ResetIfWin(this);
1446 constr
->top
.ResetIfWin(this);
1447 constr
->right
.ResetIfWin(this);
1448 constr
->bottom
.ResetIfWin(this);
1449 constr
->width
.ResetIfWin(this);
1450 constr
->height
.ResetIfWin(this);
1451 constr
->centreX
.ResetIfWin(this);
1452 constr
->centreY
.ResetIfWin(this);
1455 wxWindowList::compatibility_iterator next
= node
->GetNext();
1456 m_constraintsInvolvedIn
->Erase(node
);
1460 delete m_constraintsInvolvedIn
;
1461 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1465 #endif // wxUSE_CONSTRAINTS
1467 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1469 if ( sizer
== m_windowSizer
)
1473 delete m_windowSizer
;
1475 m_windowSizer
= sizer
;
1477 SetAutoLayout( sizer
!= NULL
);
1480 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1482 SetSizer( sizer
, deleteOld
);
1483 sizer
->SetSizeHints( (wxWindow
*) this );
1486 #if wxUSE_CONSTRAINTS
1488 void wxWindowBase::SatisfyConstraints()
1490 wxLayoutConstraints
*constr
= GetConstraints();
1491 bool wasOk
= constr
&& constr
->AreSatisfied();
1493 ResetConstraints(); // Mark all constraints as unevaluated
1497 // if we're a top level panel (i.e. our parent is frame/dialog), our
1498 // own constraints will never be satisfied any more unless we do it
1502 while ( noChanges
> 0 )
1504 LayoutPhase1(&noChanges
);
1508 LayoutPhase2(&noChanges
);
1511 #endif // wxUSE_CONSTRAINTS
1513 bool wxWindowBase::Layout()
1515 // If there is a sizer, use it instead of the constraints
1519 GetVirtualSize(&w
, &h
);
1520 GetSizer()->SetDimension( 0, 0, w
, h
);
1522 #if wxUSE_CONSTRAINTS
1525 SatisfyConstraints(); // Find the right constraints values
1526 SetConstraintSizes(); // Recursively set the real window sizes
1533 #if wxUSE_CONSTRAINTS
1535 // first phase of the constraints evaluation: set our own constraints
1536 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1538 wxLayoutConstraints
*constr
= GetConstraints();
1540 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1543 // second phase: set the constraints for our children
1544 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1551 // Layout grand children
1557 // Do a phase of evaluating child constraints
1558 bool wxWindowBase::DoPhase(int phase
)
1560 // the list containing the children for which the constraints are already
1562 wxWindowList succeeded
;
1564 // the max number of iterations we loop before concluding that we can't set
1566 static const int maxIterations
= 500;
1568 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1572 // loop over all children setting their constraints
1573 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1575 node
= node
->GetNext() )
1577 wxWindow
*child
= node
->GetData();
1578 if ( child
->IsTopLevel() )
1580 // top level children are not inside our client area
1584 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1586 // this one is either already ok or nothing we can do about it
1590 int tempNoChanges
= 0;
1591 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1592 : child
->LayoutPhase2(&tempNoChanges
);
1593 noChanges
+= tempNoChanges
;
1597 succeeded
.Append(child
);
1603 // constraints are set
1611 void wxWindowBase::ResetConstraints()
1613 wxLayoutConstraints
*constr
= GetConstraints();
1616 constr
->left
.SetDone(false);
1617 constr
->top
.SetDone(false);
1618 constr
->right
.SetDone(false);
1619 constr
->bottom
.SetDone(false);
1620 constr
->width
.SetDone(false);
1621 constr
->height
.SetDone(false);
1622 constr
->centreX
.SetDone(false);
1623 constr
->centreY
.SetDone(false);
1626 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1629 wxWindow
*win
= node
->GetData();
1630 if ( !win
->IsTopLevel() )
1631 win
->ResetConstraints();
1632 node
= node
->GetNext();
1636 // Need to distinguish between setting the 'fake' size for windows and sizers,
1637 // and setting the real values.
1638 void wxWindowBase::SetConstraintSizes(bool recurse
)
1640 wxLayoutConstraints
*constr
= GetConstraints();
1641 if ( constr
&& constr
->AreSatisfied() )
1643 int x
= constr
->left
.GetValue();
1644 int y
= constr
->top
.GetValue();
1645 int w
= constr
->width
.GetValue();
1646 int h
= constr
->height
.GetValue();
1648 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1649 (constr
->height
.GetRelationship() != wxAsIs
) )
1651 SetSize(x
, y
, w
, h
);
1655 // If we don't want to resize this window, just move it...
1661 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1662 GetClassInfo()->GetClassName(),
1668 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1671 wxWindow
*win
= node
->GetData();
1672 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1673 win
->SetConstraintSizes();
1674 node
= node
->GetNext();
1679 // Only set the size/position of the constraint (if any)
1680 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1682 wxLayoutConstraints
*constr
= GetConstraints();
1687 constr
->left
.SetValue(x
);
1688 constr
->left
.SetDone(true);
1692 constr
->top
.SetValue(y
);
1693 constr
->top
.SetDone(true);
1697 constr
->width
.SetValue(w
);
1698 constr
->width
.SetDone(true);
1702 constr
->height
.SetValue(h
);
1703 constr
->height
.SetDone(true);
1708 void wxWindowBase::MoveConstraint(int x
, int y
)
1710 wxLayoutConstraints
*constr
= GetConstraints();
1715 constr
->left
.SetValue(x
);
1716 constr
->left
.SetDone(true);
1720 constr
->top
.SetValue(y
);
1721 constr
->top
.SetDone(true);
1726 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1728 wxLayoutConstraints
*constr
= GetConstraints();
1731 *w
= constr
->width
.GetValue();
1732 *h
= constr
->height
.GetValue();
1738 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1740 wxLayoutConstraints
*constr
= GetConstraints();
1743 *w
= constr
->width
.GetValue();
1744 *h
= constr
->height
.GetValue();
1747 GetClientSize(w
, h
);
1750 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1752 wxLayoutConstraints
*constr
= GetConstraints();
1755 *x
= constr
->left
.GetValue();
1756 *y
= constr
->top
.GetValue();
1762 #endif // wxUSE_CONSTRAINTS
1764 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
1766 // don't do it for the dialogs/frames - they float independently of their
1768 if ( !IsTopLevel() )
1770 wxWindow
*parent
= GetParent();
1771 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
1773 wxPoint
pt(parent
->GetClientAreaOrigin());
1780 // ----------------------------------------------------------------------------
1781 // do Update UI processing for child controls
1782 // ----------------------------------------------------------------------------
1784 void wxWindowBase::UpdateWindowUI(long flags
)
1786 wxUpdateUIEvent
event(GetId());
1787 event
.m_eventObject
= this;
1789 if ( GetEventHandler()->ProcessEvent(event
) )
1791 DoUpdateWindowUI(event
);
1794 if (flags
& wxUPDATE_UI_RECURSE
)
1796 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1799 wxWindow
* child
= (wxWindow
*) node
->GetData();
1800 child
->UpdateWindowUI(flags
);
1801 node
= node
->GetNext();
1806 // do the window-specific processing after processing the update event
1807 // TODO: take specific knowledge out of this function and
1808 // put in each control's base class. Unfortunately we don't
1809 // yet have base implementation files for wxCheckBox and wxRadioButton.
1810 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
1812 if ( event
.GetSetEnabled() )
1813 Enable(event
.GetEnabled());
1816 if ( event
.GetSetText() )
1818 wxControl
*control
= wxDynamicCastThis(wxControl
);
1821 if ( event
.GetText() != control
->GetLabel() )
1822 control
->SetLabel(event
.GetText());
1825 wxCheckBox
*checkbox
= wxDynamicCastThis(wxCheckBox
);
1828 if ( event
.GetSetChecked() )
1829 checkbox
->SetValue(event
.GetChecked());
1831 #endif // wxUSE_CHECKBOX
1834 wxRadioButton
*radiobtn
= wxDynamicCastThis(wxRadioButton
);
1837 if ( event
.GetSetChecked() )
1838 radiobtn
->SetValue(event
.GetChecked());
1840 #endif // wxUSE_RADIOBTN
1846 // call internal idle recursively
1847 // may be obsolete (wait until OnIdle scheme stabilises)
1848 void wxWindowBase::ProcessInternalIdle()
1852 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1855 wxWindow
*child
= node
->GetData();
1856 child
->ProcessInternalIdle();
1857 node
= node
->GetNext();
1862 // ----------------------------------------------------------------------------
1863 // dialog units translations
1864 // ----------------------------------------------------------------------------
1866 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1868 int charWidth
= GetCharWidth();
1869 int charHeight
= GetCharHeight();
1870 wxPoint
pt2(-1, -1);
1872 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1874 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1879 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1881 int charWidth
= GetCharWidth();
1882 int charHeight
= GetCharHeight();
1883 wxPoint
pt2(-1, -1);
1885 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1887 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1892 // ----------------------------------------------------------------------------
1894 // ----------------------------------------------------------------------------
1896 // propagate the colour change event to the subwindows
1897 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1899 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1902 // Only propagate to non-top-level windows
1903 wxWindow
*win
= node
->GetData();
1904 if ( !win
->IsTopLevel() )
1906 wxSysColourChangedEvent event2
;
1907 event
.m_eventObject
= win
;
1908 win
->GetEventHandler()->ProcessEvent(event2
);
1911 node
= node
->GetNext();
1915 // the default action is to populate dialog with data when it's created,
1916 // and nudge the UI into displaying itself correctly in case
1917 // we've turned the wxUpdateUIEvents frequency down low.
1918 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1920 TransferDataToWindow();
1922 // Update the UI at this point
1923 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
1926 // process Ctrl-Alt-mclick
1927 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
1930 if ( event
.ControlDown() && event
.AltDown() )
1932 // don't translate these strings
1935 #ifdef __WXUNIVERSAL__
1937 #endif // __WXUNIVERSAL__
1939 switch ( wxGetOsVersion() )
1941 case wxMOTIF_X
: port
+= _T("Motif"); break;
1943 case wxMAC_DARWIN
: port
+= _T("Mac"); break;
1944 case wxBEOS
: port
+= _T("BeOS"); break;
1948 case wxGTK_BEOS
: port
+= _T("GTK"); break;
1954 case wxWIN386
: port
+= _T("MS Windows"); break;
1958 case wxMGL_OS2
: port
+= _T("MGL"); break;
1960 case wxOS2_PM
: port
+= _T("OS/2"); break;
1961 default: port
+= _T("unknown"); break;
1964 wxMessageBox(wxString::Format(
1966 " wxWindows Library (%s port)\nVersion %u.%u.%u%s, compiled at %s %s\n Copyright (c) 1995-2002 wxWindows team"
1980 _T("wxWindows information"),
1981 wxICON_INFORMATION
| wxOK
,
1985 #endif // wxUSE_MSGDLG
1991 // ----------------------------------------------------------------------------
1993 // ----------------------------------------------------------------------------
1995 #if wxUSE_ACCESSIBILITY
1996 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
1998 if (m_accessible
&& (accessible
!= m_accessible
))
1999 delete m_accessible
;
2000 m_accessible
= accessible
;
2002 m_accessible
->SetWindow((wxWindow
*) this);
2005 // Returns the accessible object, creating if necessary.
2006 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2009 m_accessible
= CreateAccessible();
2010 return m_accessible
;
2013 // Override to create a specific accessible object.
2014 wxAccessible
* wxWindowBase::CreateAccessible()
2016 return new wxWindowAccessible((wxWindow
*) this);
2022 // ----------------------------------------------------------------------------
2023 // list classes implementation
2024 // ----------------------------------------------------------------------------
2026 void wxWindowListNode::DeleteData()
2028 delete (wxWindow
*)GetData();
2032 // ----------------------------------------------------------------------------
2034 // ----------------------------------------------------------------------------
2036 wxBorder
wxWindowBase::GetBorder(long flags
) const
2038 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2039 if ( border
== wxBORDER_DEFAULT
)
2041 border
= GetDefaultBorder();
2047 wxBorder
wxWindowBase::GetDefaultBorder() const
2049 return wxBORDER_NONE
;
2052 // ----------------------------------------------------------------------------
2054 // ----------------------------------------------------------------------------
2056 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2058 // here we just check if the point is inside the window or not
2060 // check the top and left border first
2061 bool outside
= x
< 0 || y
< 0;
2064 // check the right and bottom borders too
2065 wxSize size
= GetSize();
2066 outside
= x
>= size
.x
|| y
>= size
.y
;
2069 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2072 // ----------------------------------------------------------------------------
2074 // ----------------------------------------------------------------------------
2076 struct WXDLLEXPORT wxWindowNext
2080 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2082 void wxWindowBase::CaptureMouse()
2084 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this);
2086 wxWindow
*winOld
= GetCapture();
2089 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2092 wxWindowNext
*item
= new wxWindowNext
;
2094 item
->next
= ms_winCaptureNext
;
2095 ms_winCaptureNext
= item
;
2097 //else: no mouse capture to save
2102 void wxWindowBase::ReleaseMouse()
2104 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this);
2106 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2110 if ( ms_winCaptureNext
)
2112 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2114 wxWindowNext
*item
= ms_winCaptureNext
;
2115 ms_winCaptureNext
= item
->next
;
2118 //else: stack is empty, no previous capture
2120 wxLogTrace(_T("mousecapture"),
2121 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2128 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2129 int WXUNUSED(modifiers
),
2130 int WXUNUSED(keycode
))
2136 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2142 #endif // wxUSE_HOTKEY
2144 void wxWindowBase::SendDestroyEvent()
2146 wxWindowDestroyEvent event
;
2147 event
.SetEventObject(this);
2148 event
.SetId(GetId());
2149 GetEventHandler()->ProcessEvent(event
);
2152 // ----------------------------------------------------------------------------
2154 // ----------------------------------------------------------------------------
2156 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2158 #if wxUSE_VALIDATORS
2159 // Can only use the validator of the window which
2160 // is receiving the event
2161 if ( event
.GetEventObject() == this )
2163 wxValidator
*validator
= GetValidator();
2164 if ( validator
&& validator
->ProcessEvent(event
) )
2169 #endif // wxUSE_VALIDATORS
2174 bool wxWindowBase::TryParent(wxEvent
& event
)
2176 // carry on up the parent-child hierarchy if the propgation count hasn't
2178 if ( event
.ShouldPropagate() )
2180 // honour the requests to stop propagation at this window: this is
2181 // used by the dialogs, for example, to prevent processing the events
2182 // from the dialog controls in the parent frame which rarely, if ever,
2184 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2186 wxWindow
*parent
= GetParent();
2187 if ( parent
&& !parent
->IsBeingDeleted() )
2189 wxPropagateOnce
propagateOnce(event
);
2191 return parent
->GetEventHandler()->ProcessEvent(event
);
2196 return wxEvtHandler::TryParent(event
);
2199 // ----------------------------------------------------------------------------
2201 // ----------------------------------------------------------------------------
2203 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2205 while ( win
&& !win
->IsTopLevel() )
2206 win
= win
->GetParent();
2211 #if wxUSE_ACCESSIBILITY
2212 // ----------------------------------------------------------------------------
2213 // accessible object for windows
2214 // ----------------------------------------------------------------------------
2216 // Can return either a child object, or an integer
2217 // representing the child element, starting from 1.
2218 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2220 wxASSERT( GetWindow() != NULL
);
2224 return wxACC_NOT_IMPLEMENTED
;
2227 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2228 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2230 wxASSERT( GetWindow() != NULL
);
2234 wxWindow
* win
= NULL
;
2241 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2243 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2250 rect
= win
->GetRect();
2251 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2252 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2256 return wxACC_NOT_IMPLEMENTED
;
2259 // Navigates from fromId to toId/toObject.
2260 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2261 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2263 wxASSERT( GetWindow() != NULL
);
2269 case wxNAVDIR_FIRSTCHILD
:
2271 if (GetWindow()->GetChildren().GetCount() == 0)
2273 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2274 *toObject
= childWindow
->GetOrCreateAccessible();
2278 case wxNAVDIR_LASTCHILD
:
2280 if (GetWindow()->GetChildren().GetCount() == 0)
2282 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2283 *toObject
= childWindow
->GetOrCreateAccessible();
2287 case wxNAVDIR_RIGHT
:
2291 wxWindowList::compatibility_iterator node
=
2292 wxWindowList::compatibility_iterator();
2295 // Can't navigate to sibling of this window
2296 // if we're a top-level window.
2297 if (!GetWindow()->GetParent())
2298 return wxACC_NOT_IMPLEMENTED
;
2300 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2304 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2305 node
= GetWindow()->GetChildren().Item(fromId
-1);
2308 if (node
&& node
->GetNext())
2310 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2311 *toObject
= nextWindow
->GetOrCreateAccessible();
2319 case wxNAVDIR_PREVIOUS
:
2321 wxWindowList::compatibility_iterator node
=
2322 wxWindowList::compatibility_iterator();
2325 // Can't navigate to sibling of this window
2326 // if we're a top-level window.
2327 if (!GetWindow()->GetParent())
2328 return wxACC_NOT_IMPLEMENTED
;
2330 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2334 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2335 node
= GetWindow()->GetChildren().Item(fromId
-1);
2338 if (node
&& node
->GetPrevious())
2340 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2341 *toObject
= previousWindow
->GetOrCreateAccessible();
2349 return wxACC_NOT_IMPLEMENTED
;
2352 // Gets the name of the specified object.
2353 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2355 wxASSERT( GetWindow() != NULL
);
2361 // If a child, leave wxWindows to call the function on the actual
2364 return wxACC_NOT_IMPLEMENTED
;
2366 // This will eventually be replaced by specialised
2367 // accessible classes, one for each kind of wxWindows
2368 // control or window.
2369 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2370 title
= ((wxButton
*) GetWindow())->GetLabel();
2372 title
= GetWindow()->GetName();
2374 if (!title
.IsEmpty())
2380 return wxACC_NOT_IMPLEMENTED
;
2383 // Gets the number of children.
2384 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2386 wxASSERT( GetWindow() != NULL
);
2390 *childId
= (int) GetWindow()->GetChildren().GetCount();
2394 // Gets the specified child (starting from 1).
2395 // If *child is NULL and return value is wxACC_OK,
2396 // this means that the child is a simple element and
2397 // not an accessible object.
2398 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2400 wxASSERT( GetWindow() != NULL
);
2410 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2413 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2414 *child
= childWindow
->GetOrCreateAccessible();
2421 // Gets the parent, or NULL.
2422 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2424 wxASSERT( GetWindow() != NULL
);
2428 wxWindow
* parentWindow
= GetWindow()->GetParent();
2436 *parent
= parentWindow
->GetOrCreateAccessible();
2444 // Performs the default action. childId is 0 (the action for this object)
2445 // or > 0 (the action for a child).
2446 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2447 // window (e.g. an edit control).
2448 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
2450 wxASSERT( GetWindow() != NULL
);
2454 return wxACC_NOT_IMPLEMENTED
;
2457 // Gets the default action for this object (0) or > 0 (the action for a child).
2458 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2459 // string if there is no action.
2460 // The retrieved string describes the action that is performed on an object,
2461 // not what the object does as a result. For example, a toolbar button that prints
2462 // a document has a default action of "Press" rather than "Prints the current document."
2463 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
2465 wxASSERT( GetWindow() != NULL
);
2469 return wxACC_NOT_IMPLEMENTED
;
2472 // Returns the description for this object or a child.
2473 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
2475 wxASSERT( GetWindow() != NULL
);
2479 wxString
ht(GetWindow()->GetHelpText());
2485 return wxACC_NOT_IMPLEMENTED
;
2488 // Returns help text for this object or a child, similar to tooltip text.
2489 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
2491 wxASSERT( GetWindow() != NULL
);
2495 wxString
ht(GetWindow()->GetHelpText());
2501 return wxACC_NOT_IMPLEMENTED
;
2504 // Returns the keyboard shortcut for this object or child.
2505 // Return e.g. ALT+K
2506 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
2508 wxASSERT( GetWindow() != NULL
);
2512 return wxACC_NOT_IMPLEMENTED
;
2515 // Returns a role constant.
2516 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
2518 wxASSERT( GetWindow() != NULL
);
2522 // If a child, leave wxWindows to call the function on the actual
2525 return wxACC_NOT_IMPLEMENTED
;
2527 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2528 return wxACC_NOT_IMPLEMENTED
;
2530 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2531 return wxACC_NOT_IMPLEMENTED
;
2534 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2535 return wxACC_NOT_IMPLEMENTED
;
2538 //*role = wxROLE_SYSTEM_CLIENT;
2539 *role
= wxROLE_SYSTEM_CLIENT
;
2543 return wxACC_NOT_IMPLEMENTED
;
2547 // Returns a state constant.
2548 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
2550 wxASSERT( GetWindow() != NULL
);
2554 // If a child, leave wxWindows to call the function on the actual
2557 return wxACC_NOT_IMPLEMENTED
;
2559 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2560 return wxACC_NOT_IMPLEMENTED
;
2563 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2564 return wxACC_NOT_IMPLEMENTED
;
2567 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2568 return wxACC_NOT_IMPLEMENTED
;
2575 return wxACC_NOT_IMPLEMENTED
;
2579 // Returns a localized string representing the value for the object
2581 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
2583 wxASSERT( GetWindow() != NULL
);
2587 return wxACC_NOT_IMPLEMENTED
;
2590 // Selects the object or child.
2591 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
2593 wxASSERT( GetWindow() != NULL
);
2597 return wxACC_NOT_IMPLEMENTED
;
2600 // Gets the window with the keyboard focus.
2601 // If childId is 0 and child is NULL, no object in
2602 // this subhierarchy has the focus.
2603 // If this object has the focus, child should be 'this'.
2604 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
2606 wxASSERT( GetWindow() != NULL
);
2610 return wxACC_NOT_IMPLEMENTED
;
2613 // Gets a variant representing the selected children
2615 // Acceptable values:
2616 // - a null variant (IsNull() returns TRUE)
2617 // - a list variant (GetType() == wxT("list")
2618 // - an integer representing the selected child element,
2619 // or 0 if this object is selected (GetType() == wxT("long")
2620 // - a "void*" pointer to a wxAccessible child object
2621 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
2623 wxASSERT( GetWindow() != NULL
);
2627 return wxACC_NOT_IMPLEMENTED
;
2630 #endif // wxUSE_ACCESSIBILITY