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 // ----------------------------------------------------------------------------
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(-1, wxWindowBase::OnHelp
)
103 // ============================================================================
104 // implementation of the common functionality of the wxWindow class
105 // ============================================================================
107 // ----------------------------------------------------------------------------
109 // ----------------------------------------------------------------------------
111 // the default initialization
112 void wxWindowBase::InitBase()
114 // no window yet, no parent nor children
115 m_parent
= (wxWindow
*)NULL
;
117 m_children
.DeleteContents( FALSE
); // don't auto delete node data
119 // no constraints on the minimal window size
125 // window is created enabled but it's not visible yet
129 // the default event handler is just this window
130 m_eventHandler
= this;
134 m_windowValidator
= (wxValidator
*) NULL
;
135 #endif // wxUSE_VALIDATORS
137 // use the system default colours
138 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
139 m_foregroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
141 // don't set the font here for wxMSW as we don't call WM_SETFONT here and
142 // so the font is *not* really set - but calls to SetFont() later won't do
143 // anything because m_font appears to be already set!
145 m_font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
148 // the colours/fonts are default for now
153 m_isBeingDeleted
= FALSE
;
159 #if wxUSE_CONSTRAINTS
160 // no constraints whatsoever
161 m_constraints
= (wxLayoutConstraints
*) NULL
;
162 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
163 #endif // wxUSE_CONSTRAINTS
165 m_windowSizer
= (wxSizer
*) NULL
;
166 m_containingSizer
= (wxSizer
*) NULL
;
167 m_autoLayout
= FALSE
;
169 #if wxUSE_DRAG_AND_DROP
170 m_dropTarget
= (wxDropTarget
*)NULL
;
171 #endif // wxUSE_DRAG_AND_DROP
174 m_tooltip
= (wxToolTip
*)NULL
;
175 #endif // wxUSE_TOOLTIPS
178 m_caret
= (wxCaret
*)NULL
;
179 #endif // wxUSE_CARET
182 m_hasCustomPalette
= FALSE
;
183 #endif // wxUSE_PALETTE
185 #if wxUSE_ACCESSIBILITY
189 m_virtualSize
= wxDefaultSize
;
194 m_maxVirtualHeight
= -1;
196 // Whether we're using the current theme for this window (wxGTK only for now)
197 m_themeEnabled
= FALSE
;
200 // common part of window creation process
201 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
203 const wxPoint
& WXUNUSED(pos
),
204 const wxSize
& WXUNUSED(size
),
206 const wxValidator
& validator
,
207 const wxString
& name
)
210 // wxGTK doesn't allow to create controls with static box as the parent so
211 // this will result in a crash when the program is ported to wxGTK so warn
214 // if you get this assert, the correct solution is to create the controls
215 // as siblings of the static box
216 wxASSERT_MSG( !parent
|| !wxDynamicCast(parent
, wxStaticBox
),
217 _T("wxStaticBox can't be used as a window parent!") );
218 #endif // wxUSE_STATBOX
220 // ids are limited to 16 bits under MSW so if you care about portability,
221 // it's not a good idea to use ids out of this range (and negative ids are
222 // reserved for wxWindows own usage)
223 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767),
224 _T("invalid id value") );
226 // generate a new id if the user doesn't care about it
227 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
230 SetWindowStyleFlag(style
);
234 SetValidator(validator
);
235 #endif // wxUSE_VALIDATORS
237 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
238 // have it too - like this it's possible to set it only in the top level
239 // dialog/frame and all children will inherit it by defult
240 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
242 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
248 // ----------------------------------------------------------------------------
250 // ----------------------------------------------------------------------------
253 wxWindowBase::~wxWindowBase()
255 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
257 // FIXME if these 2 cases result from programming errors in the user code
258 // we should probably assert here instead of silently fixing them
260 // Just in case the window has been Closed, but we're then deleting
261 // immediately: don't leave dangling pointers.
262 wxPendingDelete
.DeleteObject(this);
264 // Just in case we've loaded a top-level window via LoadNativeDialog but
265 // we weren't a dialog class
266 wxTopLevelWindows
.DeleteObject(this);
268 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
273 #endif // wxUSE_CARET
276 if ( m_windowValidator
)
277 delete m_windowValidator
;
278 #endif // wxUSE_VALIDATORS
280 #if wxUSE_CONSTRAINTS
281 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
282 // at deleted windows as they delete themselves.
283 DeleteRelatedConstraints();
287 // This removes any dangling pointers to this window in other windows'
288 // constraintsInvolvedIn lists.
289 UnsetConstraints(m_constraints
);
290 delete m_constraints
;
291 m_constraints
= NULL
;
294 #endif // wxUSE_CONSTRAINTS
296 if ( m_containingSizer
)
297 m_containingSizer
->Detach( (wxWindow
*)this );
300 delete m_windowSizer
;
302 #if wxUSE_DRAG_AND_DROP
305 #endif // wxUSE_DRAG_AND_DROP
310 #endif // wxUSE_TOOLTIPS
312 #if wxUSE_ACCESSIBILITY
317 // reset the dangling pointer our parent window may keep to us
318 if ( m_parent
&& m_parent
->GetDefaultItem() == this )
320 m_parent
->SetDefaultItem(NULL
);
324 bool wxWindowBase::Destroy()
331 bool wxWindowBase::Close(bool force
)
333 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
334 event
.SetEventObject(this);
335 #if WXWIN_COMPATIBILITY
336 event
.SetForce(force
);
337 #endif // WXWIN_COMPATIBILITY
338 event
.SetCanVeto(!force
);
340 // return FALSE if window wasn't closed because the application vetoed the
342 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
345 bool wxWindowBase::DestroyChildren()
347 wxWindowList::Node
*node
;
350 // we iterate until the list becomes empty
351 node
= GetChildren().GetFirst();
355 wxWindow
*child
= node
->GetData();
357 wxASSERT_MSG( child
, wxT("children list contains empty nodes") );
362 wxASSERT_MSG( !GetChildren().Find(child
),
363 wxT("child didn't remove itself using RemoveChild()") );
369 // ----------------------------------------------------------------------------
370 // size/position related methods
371 // ----------------------------------------------------------------------------
373 // centre the window with respect to its parent in either (or both) directions
374 void wxWindowBase::Centre(int direction
)
376 // the position/size of the parent window or of the entire screen
378 int widthParent
, heightParent
;
380 wxWindow
*parent
= NULL
;
382 if ( !(direction
& wxCENTRE_ON_SCREEN
) )
384 // find the parent to centre this window on: it should be the
385 // immediate parent for the controls but the top level parent for the
386 // top level windows (like dialogs)
387 parent
= GetParent();
390 while ( parent
&& !parent
->IsTopLevel() )
392 parent
= parent
->GetParent();
396 // there is no wxTopLevelWindow under wxMotif yet
398 // we shouldn't center the dialog on the iconized window: under
399 // Windows, for example, this places it completely off the screen
402 wxTopLevelWindow
*winTop
= wxDynamicCast(parent
, wxTopLevelWindow
);
403 if ( winTop
&& winTop
->IsIconized() )
408 #endif // __WXMOTIF__
410 // did we find the parent?
414 direction
|= wxCENTRE_ON_SCREEN
;
418 if ( direction
& wxCENTRE_ON_SCREEN
)
420 // centre with respect to the whole screen
421 wxDisplaySize(&widthParent
, &heightParent
);
427 // centre on the parent
428 parent
->GetSize(&widthParent
, &heightParent
);
430 // adjust to the parents position
431 posParent
= parent
->GetPosition();
435 // centre inside the parents client rectangle
436 parent
->GetClientSize(&widthParent
, &heightParent
);
441 GetSize(&width
, &height
);
446 if ( direction
& wxHORIZONTAL
)
447 xNew
= (widthParent
- width
)/2;
449 if ( direction
& wxVERTICAL
)
450 yNew
= (heightParent
- height
)/2;
455 // Base size of the visible dimensions of the display
456 // to take into account the taskbar
457 wxRect rect
= wxGetClientDisplayRect();
458 wxSize
size (rect
.width
,rect
.height
);
460 // NB: in wxMSW, negative position may not neccessary mean "out of screen",
461 // but it may mean that the window is placed on other than the main
462 // display. Therefore we only make sure centered window is on the main display
463 // if the parent is at least partially present here.
464 if (posParent
.x
+ widthParent
>= 0) // if parent is (partially) on the main display
468 else if (xNew
+width
> size
.x
)
469 xNew
= size
.x
-width
-1;
471 if (posParent
.y
+ heightParent
>= 0) // if parent is (partially) on the main display
473 if (yNew
+height
> size
.y
)
474 yNew
= size
.y
-height
-1;
476 // Make certain that the title bar is initially visible
477 // always, even if this would push the bottom of the
478 // dialog of the visible area of the display
483 // move the window to this position (keeping the old size but using
484 // SetSize() and not Move() to allow xNew and/or yNew to be -1)
485 SetSize(xNew
, yNew
, width
, height
, wxSIZE_ALLOW_MINUS_ONE
);
488 // fits the window around the children
489 void wxWindowBase::Fit()
491 if ( GetChildren().GetCount() > 0 )
493 SetClientSize(DoGetBestSize());
495 //else: do nothing if we have no children
498 // fits virtual size (ie. scrolled area etc.) around children
499 void wxWindowBase::FitInside()
501 if ( GetChildren().GetCount() > 0 )
503 SetVirtualSize( GetBestVirtualSize() );
507 // return the size best suited for the current window
508 wxSize
wxWindowBase::DoGetBestSize() const
512 return m_windowSizer
->GetMinSize();
514 #if wxUSE_CONSTRAINTS
515 else if ( m_constraints
)
517 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
519 // our minimal acceptable size is such that all our windows fit inside
523 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
525 node
= node
->GetNext() )
527 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
530 // it's not normal that we have an unconstrained child, but
531 // what can we do about it?
535 int x
= c
->right
.GetValue(),
536 y
= c
->bottom
.GetValue();
544 // TODO: we must calculate the overlaps somehow, otherwise we
545 // will never return a size bigger than the current one :-(
548 return wxSize(maxX
, maxY
);
550 #endif // wxUSE_CONSTRAINTS
551 else if ( GetChildren().GetCount() > 0 )
553 // our minimal acceptable size is such that all our windows fit inside
557 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
559 node
= node
->GetNext() )
561 wxWindow
*win
= node
->GetData();
562 if ( win
->IsTopLevel()
564 || wxDynamicCast(win
, wxStatusBar
)
565 #endif // wxUSE_STATUSBAR
568 // dialogs and frames lie in different top level windows -
569 // don't deal with them here; as for the status bars, they
570 // don't lie in the client area at all
575 win
->GetPosition(&wx
, &wy
);
577 // if the window hadn't been positioned yet, assume that it is in
584 win
->GetSize(&ww
, &wh
);
585 if ( wx
+ ww
> maxX
)
587 if ( wy
+ wh
> maxY
)
591 // for compatibility with the old versions and because it really looks
592 // slightly more pretty like this, add a pad
596 return wxSize(maxX
, maxY
);
600 // for a generic window there is no natural best size - just use the
606 // by default the origin is not shifted
607 wxPoint
wxWindowBase::GetClientAreaOrigin() const
609 return wxPoint(0, 0);
612 // set the min/max size of the window
613 void wxWindowBase::SetSizeHints(int minW
, int minH
,
615 int WXUNUSED(incW
), int WXUNUSED(incH
))
617 // setting min width greater than max width leads to infinite loops under
618 // X11 and generally doesn't make any sense, so don't allow it
619 wxCHECK_RET( (minW
== -1 || maxW
== -1 || minW
<= maxW
) &&
620 (minH
== -1 || maxH
== -1 || minH
<= maxH
),
621 _T("min width/height must be less than max width/height!") );
629 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
632 m_minVirtualWidth
= minW
;
633 m_maxVirtualWidth
= maxW
;
634 m_minVirtualHeight
= minH
;
635 m_maxVirtualHeight
= maxH
;
638 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
640 if ( m_minVirtualWidth
!= -1 && m_minVirtualWidth
> x
)
641 x
= m_minVirtualWidth
;
642 if ( m_maxVirtualWidth
!= -1 && m_maxVirtualWidth
< x
)
643 x
= m_maxVirtualWidth
;
644 if ( m_minVirtualHeight
!= -1 && m_minVirtualHeight
> y
)
645 y
= m_minVirtualHeight
;
646 if ( m_maxVirtualHeight
!= -1 && m_maxVirtualHeight
< y
)
647 y
= m_maxVirtualHeight
;
649 m_virtualSize
= wxSize(x
, y
);
652 wxSize
wxWindowBase::DoGetVirtualSize() const
654 wxSize
s( GetClientSize() );
656 return wxSize( wxMax( m_virtualSize
.GetWidth(), s
.GetWidth() ),
657 wxMax( m_virtualSize
.GetHeight(), s
.GetHeight() ) );
660 // ----------------------------------------------------------------------------
661 // show/hide/enable/disable the window
662 // ----------------------------------------------------------------------------
664 bool wxWindowBase::Show(bool show
)
666 if ( show
!= m_isShown
)
678 bool wxWindowBase::Enable(bool enable
)
680 if ( enable
!= m_isEnabled
)
682 m_isEnabled
= enable
;
691 // ----------------------------------------------------------------------------
693 // ----------------------------------------------------------------------------
695 bool wxWindowBase::IsTopLevel() const
700 // ----------------------------------------------------------------------------
701 // reparenting the window
702 // ----------------------------------------------------------------------------
704 void wxWindowBase::AddChild(wxWindowBase
*child
)
706 wxCHECK_RET( child
, wxT("can't add a NULL child") );
708 // this should never happen and it will lead to a crash later if it does
709 // because RemoveChild() will remove only one node from the children list
710 // and the other(s) one(s) will be left with dangling pointers in them
711 wxASSERT_MSG( !GetChildren().Find(child
), _T("AddChild() called twice") );
713 GetChildren().Append(child
);
714 child
->SetParent(this);
717 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
719 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
721 GetChildren().DeleteObject(child
);
722 child
->SetParent((wxWindow
*)NULL
);
725 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
727 wxWindow
*oldParent
= GetParent();
728 if ( newParent
== oldParent
)
734 // unlink this window from the existing parent.
737 oldParent
->RemoveChild(this);
741 wxTopLevelWindows
.DeleteObject(this);
744 // add it to the new one
747 newParent
->AddChild(this);
751 wxTopLevelWindows
.Append(this);
757 // ----------------------------------------------------------------------------
758 // event handler stuff
759 // ----------------------------------------------------------------------------
761 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
763 wxEvtHandler
*handlerOld
= GetEventHandler();
765 handler
->SetNextHandler(handlerOld
);
768 GetEventHandler()->SetPreviousHandler(handler
);
770 SetEventHandler(handler
);
773 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
775 wxEvtHandler
*handlerA
= GetEventHandler();
778 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
779 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
782 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
783 SetEventHandler(handlerB
);
788 handlerA
= (wxEvtHandler
*)NULL
;
795 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
797 wxCHECK_MSG( handler
, FALSE
, _T("RemoveEventHandler(NULL) called") );
799 wxEvtHandler
*handlerPrev
= NULL
,
800 *handlerCur
= GetEventHandler();
803 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
805 if ( handlerCur
== handler
)
809 handlerPrev
->SetNextHandler(handlerNext
);
813 SetEventHandler(handlerNext
);
818 handlerNext
->SetPreviousHandler ( handlerPrev
);
820 handler
->SetNextHandler(NULL
);
825 handlerPrev
= handlerCur
;
826 handlerCur
= handlerNext
;
829 wxFAIL_MSG( _T("where has the event handler gone?") );
834 // ----------------------------------------------------------------------------
836 // ----------------------------------------------------------------------------
838 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
840 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
843 m_backgroundColour
= colour
;
850 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
852 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
855 m_foregroundColour
= colour
;
862 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
864 // setting an invalid cursor is ok, it means that we don't have any special
866 if ( m_cursor
== cursor
)
877 bool wxWindowBase::SetFont(const wxFont
& font
)
879 // don't try to set invalid font, always fall back to the default
880 const wxFont
& fontOk
= font
.Ok() ? font
: *wxSWISS_FONT
;
882 if ( fontOk
== m_font
)
897 void wxWindowBase::SetPalette(const wxPalette
& pal
)
899 m_hasCustomPalette
= TRUE
;
902 // VZ: can anyone explain me what do we do here?
903 wxWindowDC
d((wxWindow
*) this);
907 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
909 wxWindow
*win
= (wxWindow
*)this;
910 while ( win
&& !win
->HasCustomPalette() )
912 win
= win
->GetParent();
918 #endif // wxUSE_PALETTE
921 void wxWindowBase::SetCaret(wxCaret
*caret
)
932 wxASSERT_MSG( m_caret
->GetWindow() == this,
933 wxT("caret should be created associated to this window") );
936 #endif // wxUSE_CARET
939 // ----------------------------------------------------------------------------
941 // ----------------------------------------------------------------------------
943 void wxWindowBase::SetValidator(const wxValidator
& validator
)
945 if ( m_windowValidator
)
946 delete m_windowValidator
;
948 m_windowValidator
= (wxValidator
*)validator
.Clone();
950 if ( m_windowValidator
)
951 m_windowValidator
->SetWindow(this) ;
953 #endif // wxUSE_VALIDATORS
955 // ----------------------------------------------------------------------------
956 // update region stuff
957 // ----------------------------------------------------------------------------
959 wxRect
wxWindowBase::GetUpdateClientRect() const
961 wxRegion rgnUpdate
= GetUpdateRegion();
962 rgnUpdate
.Intersect(GetClientRect());
963 wxRect rectUpdate
= rgnUpdate
.GetBox();
964 wxPoint ptOrigin
= GetClientAreaOrigin();
965 rectUpdate
.x
-= ptOrigin
.x
;
966 rectUpdate
.y
-= ptOrigin
.y
;
971 bool wxWindowBase::IsExposed(int x
, int y
) const
973 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
976 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
978 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
981 // ----------------------------------------------------------------------------
982 // find child window by id or name
983 // ----------------------------------------------------------------------------
985 wxWindow
*wxWindowBase::FindWindow( long id
)
987 if ( id
== m_windowId
)
988 return (wxWindow
*)this;
990 wxWindowBase
*res
= (wxWindow
*)NULL
;
991 wxWindowList::Node
*node
;
992 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
994 wxWindowBase
*child
= node
->GetData();
995 res
= child
->FindWindow( id
);
998 return (wxWindow
*)res
;
1001 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
1003 if ( name
== m_windowName
)
1004 return (wxWindow
*)this;
1006 wxWindowBase
*res
= (wxWindow
*)NULL
;
1007 wxWindowList::Node
*node
;
1008 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1010 wxWindow
*child
= node
->GetData();
1011 res
= child
->FindWindow(name
);
1014 return (wxWindow
*)res
;
1018 // find any window by id or name or label: If parent is non-NULL, look through
1019 // children for a label or title matching the specified string. If NULL, look
1020 // through all top-level windows.
1022 // to avoid duplicating code we reuse the same helper function but with
1023 // different comparators
1025 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1026 const wxString
& label
, long id
);
1029 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1032 return win
->GetLabel() == label
;
1036 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1039 return win
->GetName() == label
;
1043 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1046 return win
->GetId() == id
;
1049 // recursive helper for the FindWindowByXXX() functions
1051 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1052 const wxString
& label
,
1054 wxFindWindowCmp cmp
)
1058 // see if this is the one we're looking for
1059 if ( (*cmp
)(parent
, label
, id
) )
1060 return (wxWindow
*)parent
;
1062 // It wasn't, so check all its children
1063 for ( wxWindowList::Node
* node
= parent
->GetChildren().GetFirst();
1065 node
= node
->GetNext() )
1067 // recursively check each child
1068 wxWindow
*win
= (wxWindow
*)node
->GetData();
1069 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1079 // helper for FindWindowByXXX()
1081 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1082 const wxString
& label
,
1084 wxFindWindowCmp cmp
)
1088 // just check parent and all its children
1089 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1092 // start at very top of wx's windows
1093 for ( wxWindowList::Node
* node
= wxTopLevelWindows
.GetFirst();
1095 node
= node
->GetNext() )
1097 // recursively check each window & its children
1098 wxWindow
*win
= node
->GetData();
1099 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1109 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1111 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1116 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1118 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1122 // fall back to the label
1123 win
= FindWindowByLabel(title
, parent
);
1131 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1133 return wxFindWindowHelper(parent
, _T(""), id
, wxFindWindowCmpIds
);
1136 // ----------------------------------------------------------------------------
1137 // dialog oriented functions
1138 // ----------------------------------------------------------------------------
1140 void wxWindowBase::MakeModal(bool modal
)
1142 // Disable all other windows
1145 wxWindowList::Node
*node
= wxTopLevelWindows
.GetFirst();
1148 wxWindow
*win
= node
->GetData();
1150 win
->Enable(!modal
);
1152 node
= node
->GetNext();
1157 bool wxWindowBase::Validate()
1159 #if wxUSE_VALIDATORS
1160 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1162 wxWindowList::Node
*node
;
1163 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1165 wxWindowBase
*child
= node
->GetData();
1166 wxValidator
*validator
= child
->GetValidator();
1167 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1172 if ( recurse
&& !child
->Validate() )
1177 #endif // wxUSE_VALIDATORS
1182 bool wxWindowBase::TransferDataToWindow()
1184 #if wxUSE_VALIDATORS
1185 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1187 wxWindowList::Node
*node
;
1188 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1190 wxWindowBase
*child
= node
->GetData();
1191 wxValidator
*validator
= child
->GetValidator();
1192 if ( validator
&& !validator
->TransferToWindow() )
1194 wxLogWarning(_("Could not transfer data to window"));
1196 wxLog::FlushActive();
1204 if ( !child
->TransferDataToWindow() )
1206 // warning already given
1211 #endif // wxUSE_VALIDATORS
1216 bool wxWindowBase::TransferDataFromWindow()
1218 #if wxUSE_VALIDATORS
1219 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1221 wxWindowList::Node
*node
;
1222 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1224 wxWindow
*child
= node
->GetData();
1225 wxValidator
*validator
= child
->GetValidator();
1226 if ( validator
&& !validator
->TransferFromWindow() )
1228 // nop warning here because the application is supposed to give
1229 // one itself - we don't know here what might have gone wrongly
1236 if ( !child
->TransferDataFromWindow() )
1238 // warning already given
1243 #endif // wxUSE_VALIDATORS
1248 void wxWindowBase::InitDialog()
1250 wxInitDialogEvent
event(GetId());
1251 event
.SetEventObject( this );
1252 GetEventHandler()->ProcessEvent(event
);
1255 // ----------------------------------------------------------------------------
1256 // context-sensitive help support
1257 // ----------------------------------------------------------------------------
1261 // associate this help text with this window
1262 void wxWindowBase::SetHelpText(const wxString
& text
)
1264 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1267 helpProvider
->AddHelp(this, text
);
1271 // associate this help text with all windows with the same id as this
1273 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1275 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1278 helpProvider
->AddHelp(GetId(), text
);
1282 // get the help string associated with this window (may be empty)
1283 wxString
wxWindowBase::GetHelpText() const
1286 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1289 text
= helpProvider
->GetHelp(this);
1295 // show help for this window
1296 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1298 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1301 if ( helpProvider
->ShowHelp(this) )
1303 // skip the event.Skip() below
1311 #endif // wxUSE_HELP
1313 // ----------------------------------------------------------------------------
1314 // tooltipsroot.Replace("\\", "/");
1315 // ----------------------------------------------------------------------------
1319 void wxWindowBase::SetToolTip( const wxString
&tip
)
1321 // don't create the new tooltip if we already have one
1324 m_tooltip
->SetTip( tip
);
1328 SetToolTip( new wxToolTip( tip
) );
1331 // setting empty tooltip text does not remove the tooltip any more - use
1332 // SetToolTip((wxToolTip *)NULL) for this
1335 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1340 m_tooltip
= tooltip
;
1343 #endif // wxUSE_TOOLTIPS
1345 // ----------------------------------------------------------------------------
1346 // constraints and sizers
1347 // ----------------------------------------------------------------------------
1349 #if wxUSE_CONSTRAINTS
1351 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1353 if ( m_constraints
)
1355 UnsetConstraints(m_constraints
);
1356 delete m_constraints
;
1358 m_constraints
= constraints
;
1359 if ( m_constraints
)
1361 // Make sure other windows know they're part of a 'meaningful relationship'
1362 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1363 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1364 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1365 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1366 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1367 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1368 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1369 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1370 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1371 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1372 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1373 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1374 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1375 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1376 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1377 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1381 // This removes any dangling pointers to this window in other windows'
1382 // constraintsInvolvedIn lists.
1383 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1387 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1388 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1389 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1390 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1391 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1392 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1393 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1394 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1395 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1396 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1397 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1398 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1399 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1400 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1401 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1402 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1406 // Back-pointer to other windows we're involved with, so if we delete this
1407 // window, we must delete any constraints we're involved with.
1408 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1410 if ( !m_constraintsInvolvedIn
)
1411 m_constraintsInvolvedIn
= new wxWindowList
;
1412 if ( !m_constraintsInvolvedIn
->Find(otherWin
) )
1413 m_constraintsInvolvedIn
->Append(otherWin
);
1416 // REMOVE back-pointer to other windows we're involved with.
1417 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1419 if ( m_constraintsInvolvedIn
)
1420 m_constraintsInvolvedIn
->DeleteObject(otherWin
);
1423 // Reset any constraints that mention this window
1424 void wxWindowBase::DeleteRelatedConstraints()
1426 if ( m_constraintsInvolvedIn
)
1428 wxWindowList::Node
*node
= m_constraintsInvolvedIn
->GetFirst();
1431 wxWindow
*win
= node
->GetData();
1432 wxLayoutConstraints
*constr
= win
->GetConstraints();
1434 // Reset any constraints involving this window
1437 constr
->left
.ResetIfWin(this);
1438 constr
->top
.ResetIfWin(this);
1439 constr
->right
.ResetIfWin(this);
1440 constr
->bottom
.ResetIfWin(this);
1441 constr
->width
.ResetIfWin(this);
1442 constr
->height
.ResetIfWin(this);
1443 constr
->centreX
.ResetIfWin(this);
1444 constr
->centreY
.ResetIfWin(this);
1447 wxWindowList::Node
*next
= node
->GetNext();
1452 delete m_constraintsInvolvedIn
;
1453 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1457 #endif // wxUSE_CONSTRAINTS
1459 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1462 delete m_windowSizer
;
1464 m_windowSizer
= sizer
;
1466 SetAutoLayout( sizer
!= NULL
);
1469 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1471 SetSizer( sizer
, deleteOld
);
1472 sizer
->SetSizeHints( (wxWindow
*) this );
1475 #if wxUSE_CONSTRAINTS
1477 void wxWindowBase::SatisfyConstraints()
1479 wxLayoutConstraints
*constr
= GetConstraints();
1480 bool wasOk
= constr
&& constr
->AreSatisfied();
1482 ResetConstraints(); // Mark all constraints as unevaluated
1486 // if we're a top level panel (i.e. our parent is frame/dialog), our
1487 // own constraints will never be satisfied any more unless we do it
1491 while ( noChanges
> 0 )
1493 LayoutPhase1(&noChanges
);
1497 LayoutPhase2(&noChanges
);
1500 #endif // wxUSE_CONSTRAINTS
1502 bool wxWindowBase::Layout()
1504 // If there is a sizer, use it instead of the constraints
1508 GetVirtualSize(&w
, &h
);
1509 GetSizer()->SetDimension( 0, 0, w
, h
);
1511 #if wxUSE_CONSTRAINTS
1514 SatisfyConstraints(); // Find the right constraints values
1515 SetConstraintSizes(); // Recursively set the real window sizes
1522 #if wxUSE_CONSTRAINTS
1524 // first phase of the constraints evaluation: set our own constraints
1525 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1527 wxLayoutConstraints
*constr
= GetConstraints();
1529 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1532 // second phase: set the constraints for our children
1533 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1540 // Layout grand children
1546 // Do a phase of evaluating child constraints
1547 bool wxWindowBase::DoPhase(int phase
)
1549 // the list containing the children for which the constraints are already
1551 wxWindowList succeeded
;
1553 // the max number of iterations we loop before concluding that we can't set
1555 static const int maxIterations
= 500;
1557 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1561 // loop over all children setting their constraints
1562 for ( wxWindowList::Node
*node
= GetChildren().GetFirst();
1564 node
= node
->GetNext() )
1566 wxWindow
*child
= node
->GetData();
1567 if ( child
->IsTopLevel() )
1569 // top level children are not inside our client area
1573 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1575 // this one is either already ok or nothing we can do about it
1579 int tempNoChanges
= 0;
1580 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1581 : child
->LayoutPhase2(&tempNoChanges
);
1582 noChanges
+= tempNoChanges
;
1586 succeeded
.Append(child
);
1592 // constraints are set
1600 void wxWindowBase::ResetConstraints()
1602 wxLayoutConstraints
*constr
= GetConstraints();
1605 constr
->left
.SetDone(FALSE
);
1606 constr
->top
.SetDone(FALSE
);
1607 constr
->right
.SetDone(FALSE
);
1608 constr
->bottom
.SetDone(FALSE
);
1609 constr
->width
.SetDone(FALSE
);
1610 constr
->height
.SetDone(FALSE
);
1611 constr
->centreX
.SetDone(FALSE
);
1612 constr
->centreY
.SetDone(FALSE
);
1615 wxWindowList::Node
*node
= GetChildren().GetFirst();
1618 wxWindow
*win
= node
->GetData();
1619 if ( !win
->IsTopLevel() )
1620 win
->ResetConstraints();
1621 node
= node
->GetNext();
1625 // Need to distinguish between setting the 'fake' size for windows and sizers,
1626 // and setting the real values.
1627 void wxWindowBase::SetConstraintSizes(bool recurse
)
1629 wxLayoutConstraints
*constr
= GetConstraints();
1630 if ( constr
&& constr
->AreSatisfied() )
1632 int x
= constr
->left
.GetValue();
1633 int y
= constr
->top
.GetValue();
1634 int w
= constr
->width
.GetValue();
1635 int h
= constr
->height
.GetValue();
1637 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1638 (constr
->height
.GetRelationship() != wxAsIs
) )
1640 SetSize(x
, y
, w
, h
);
1644 // If we don't want to resize this window, just move it...
1650 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1651 GetClassInfo()->GetClassName(),
1657 wxWindowList::Node
*node
= GetChildren().GetFirst();
1660 wxWindow
*win
= node
->GetData();
1661 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1662 win
->SetConstraintSizes();
1663 node
= node
->GetNext();
1668 // Only set the size/position of the constraint (if any)
1669 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1671 wxLayoutConstraints
*constr
= GetConstraints();
1676 constr
->left
.SetValue(x
);
1677 constr
->left
.SetDone(TRUE
);
1681 constr
->top
.SetValue(y
);
1682 constr
->top
.SetDone(TRUE
);
1686 constr
->width
.SetValue(w
);
1687 constr
->width
.SetDone(TRUE
);
1691 constr
->height
.SetValue(h
);
1692 constr
->height
.SetDone(TRUE
);
1697 void wxWindowBase::MoveConstraint(int x
, int y
)
1699 wxLayoutConstraints
*constr
= GetConstraints();
1704 constr
->left
.SetValue(x
);
1705 constr
->left
.SetDone(TRUE
);
1709 constr
->top
.SetValue(y
);
1710 constr
->top
.SetDone(TRUE
);
1715 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1717 wxLayoutConstraints
*constr
= GetConstraints();
1720 *w
= constr
->width
.GetValue();
1721 *h
= constr
->height
.GetValue();
1727 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1729 wxLayoutConstraints
*constr
= GetConstraints();
1732 *w
= constr
->width
.GetValue();
1733 *h
= constr
->height
.GetValue();
1736 GetClientSize(w
, h
);
1739 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1741 wxLayoutConstraints
*constr
= GetConstraints();
1744 *x
= constr
->left
.GetValue();
1745 *y
= constr
->top
.GetValue();
1751 #endif // wxUSE_CONSTRAINTS
1753 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
1755 // don't do it for the dialogs/frames - they float independently of their
1757 if ( !IsTopLevel() )
1759 wxWindow
*parent
= GetParent();
1760 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
1762 wxPoint
pt(parent
->GetClientAreaOrigin());
1769 // ----------------------------------------------------------------------------
1770 // do Update UI processing for child controls
1771 // ----------------------------------------------------------------------------
1773 void wxWindowBase::UpdateWindowUI(long flags
)
1775 wxUpdateUIEvent
event(GetId());
1776 event
.m_eventObject
= this;
1778 if ( GetEventHandler()->ProcessEvent(event
) )
1780 DoUpdateWindowUI(event
);
1783 if (flags
& wxUPDATE_UI_RECURSE
)
1785 wxWindowList::Node
* node
= GetChildren().GetFirst();
1788 wxWindow
* child
= (wxWindow
*) node
->GetData();
1789 child
->UpdateWindowUI(flags
);
1790 node
= node
->GetNext();
1795 // do the window-specific processing after processing the update event
1796 // TODO: take specific knowledge out of this function and
1797 // put in each control's base class. Unfortunately we don't
1798 // yet have base implementation files for wxCheckBox and wxRadioButton.
1799 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
1801 if ( event
.GetSetEnabled() )
1802 Enable(event
.GetEnabled());
1805 if ( event
.GetSetText() )
1807 wxControl
*control
= wxDynamicCastThis(wxControl
);
1810 if ( event
.GetText() != control
->GetLabel() )
1811 control
->SetLabel(event
.GetText());
1814 wxCheckBox
*checkbox
= wxDynamicCastThis(wxCheckBox
);
1817 if ( event
.GetSetChecked() )
1818 checkbox
->SetValue(event
.GetChecked());
1820 #endif // wxUSE_CHECKBOX
1823 wxRadioButton
*radiobtn
= wxDynamicCastThis(wxRadioButton
);
1826 if ( event
.GetSetChecked() )
1827 radiobtn
->SetValue(event
.GetChecked());
1829 #endif // wxUSE_RADIOBTN
1834 // call internal idle recursively
1835 void wxWindowBase::ProcessInternalIdle()
1839 wxWindowList::Node
*node
= GetChildren().GetFirst();
1842 wxWindow
*child
= node
->GetData();
1843 child
->ProcessInternalIdle();
1844 node
= node
->GetNext();
1848 // ----------------------------------------------------------------------------
1849 // dialog units translations
1850 // ----------------------------------------------------------------------------
1852 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1854 int charWidth
= GetCharWidth();
1855 int charHeight
= GetCharHeight();
1856 wxPoint
pt2(-1, -1);
1858 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1860 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1865 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1867 int charWidth
= GetCharWidth();
1868 int charHeight
= GetCharHeight();
1869 wxPoint
pt2(-1, -1);
1871 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1873 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1878 // ----------------------------------------------------------------------------
1880 // ----------------------------------------------------------------------------
1882 // propagate the colour change event to the subwindows
1883 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1885 wxWindowList::Node
*node
= GetChildren().GetFirst();
1888 // Only propagate to non-top-level windows
1889 wxWindow
*win
= node
->GetData();
1890 if ( !win
->IsTopLevel() )
1892 wxSysColourChangedEvent event2
;
1893 event
.m_eventObject
= win
;
1894 win
->GetEventHandler()->ProcessEvent(event2
);
1897 node
= node
->GetNext();
1901 // the default action is to populate dialog with data when it's created,
1902 // and nudge the UI into displaying itself correctly in case
1903 // we've turned the wxUpdateUIEvents frequency down low.
1904 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1906 TransferDataToWindow();
1908 // Update the UI at this point
1909 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
1912 // process Ctrl-Alt-mclick
1913 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
1916 if ( event
.ControlDown() && event
.AltDown() )
1918 // don't translate these strings
1921 #ifdef __WXUNIVERSAL__
1923 #endif // __WXUNIVERSAL__
1925 switch ( wxGetOsVersion() )
1927 case wxMOTIF_X
: port
+= _T("Motif"); break;
1929 case wxMAC_DARWIN
: port
+= _T("Mac"); break;
1930 case wxBEOS
: port
+= _T("BeOS"); break;
1934 case wxGTK_BEOS
: port
+= _T("GTK"); break;
1940 case wxWIN386
: port
+= _T("MS Windows"); break;
1944 case wxMGL_OS2
: port
+= _T("MGL"); break;
1946 case wxOS2_PM
: port
+= _T("OS/2"); break;
1947 default: port
+= _T("unknown"); break;
1950 wxMessageBox(wxString::Format(
1952 " wxWindows Library (%s port)\nVersion %u.%u.%u%s, compiled at %s %s\n Copyright (c) 1995-2002 wxWindows team"
1966 _T("wxWindows information"),
1967 wxICON_INFORMATION
| wxOK
,
1971 #endif // wxUSE_MSGDLG
1977 // ----------------------------------------------------------------------------
1979 // ----------------------------------------------------------------------------
1981 #if wxUSE_ACCESSIBILITY
1982 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
1984 if (m_accessible
&& (accessible
!= m_accessible
))
1985 delete m_accessible
;
1986 m_accessible
= accessible
;
1988 m_accessible
->SetWindow((wxWindow
*) this);
1991 // Returns the accessible object, creating if necessary.
1992 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
1995 m_accessible
= CreateAccessible();
1996 return m_accessible
;
1999 // Override to create a specific accessible object.
2000 wxAccessible
* wxWindowBase::CreateAccessible()
2002 return new wxWindowAccessible((wxWindow
*) this);
2007 // ----------------------------------------------------------------------------
2008 // list classes implementation
2009 // ----------------------------------------------------------------------------
2011 void wxWindowListNode::DeleteData()
2013 delete (wxWindow
*)GetData();
2016 // ----------------------------------------------------------------------------
2018 // ----------------------------------------------------------------------------
2020 wxBorder
wxWindowBase::GetBorder(long flags
) const
2022 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2023 if ( border
== wxBORDER_DEFAULT
)
2025 border
= GetDefaultBorder();
2031 wxBorder
wxWindowBase::GetDefaultBorder() const
2033 return wxBORDER_NONE
;
2036 // ----------------------------------------------------------------------------
2038 // ----------------------------------------------------------------------------
2040 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2042 // here we just check if the point is inside the window or not
2044 // check the top and left border first
2045 bool outside
= x
< 0 || y
< 0;
2048 // check the right and bottom borders too
2049 wxSize size
= GetSize();
2050 outside
= x
>= size
.x
|| y
>= size
.y
;
2053 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2056 // ----------------------------------------------------------------------------
2058 // ----------------------------------------------------------------------------
2060 struct WXDLLEXPORT wxWindowNext
2064 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2066 void wxWindowBase::CaptureMouse()
2068 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this);
2070 wxWindow
*winOld
= GetCapture();
2073 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2076 wxWindowNext
*item
= new wxWindowNext
;
2078 item
->next
= ms_winCaptureNext
;
2079 ms_winCaptureNext
= item
;
2081 //else: no mouse capture to save
2086 void wxWindowBase::ReleaseMouse()
2088 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this);
2090 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2094 if ( ms_winCaptureNext
)
2096 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2098 wxWindowNext
*item
= ms_winCaptureNext
;
2099 ms_winCaptureNext
= item
->next
;
2102 //else: stack is empty, no previous capture
2104 wxLogTrace(_T("mousecapture"),
2105 _T("After ReleaseMouse() mouse is captured by %p"),
2110 void wxWindowBase::SendDestroyEvent()
2112 wxWindowDestroyEvent event
;
2113 event
.SetEventObject(this);
2114 event
.SetId(GetId());
2115 GetEventHandler()->ProcessEvent(event
);
2118 // ----------------------------------------------------------------------------
2120 // ----------------------------------------------------------------------------
2122 #if wxUSE_VALIDATORS
2124 bool wxWindowBase::TryValidator(wxEvent
& event
)
2126 // Can only use the validator of the window which
2127 // is receiving the event
2128 if ( event
.GetEventObject() == this )
2130 wxValidator
*validator
= GetValidator();
2131 if ( validator
&& validator
->ProcessEvent(event
) )
2140 #endif // wxUSE_VALIDATORS
2142 bool wxWindowBase::TryParent(wxEvent
& event
)
2144 // Carry on up the parent-child hierarchy, but only if event is a command
2145 // event: it wouldn't make sense for a parent to receive a child's size
2146 // event, for example
2147 if ( event
.IsCommandEvent() )
2149 // honour the requests to stop propagation at this window: this is
2150 // used by the dialogs, for example, to prevent processing the events
2151 // from the dialog controls in the parent frame which rarely, if ever,
2153 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2155 wxWindow
*parent
= GetParent();
2156 if ( parent
&& !parent
->IsBeingDeleted() )
2157 return parent
->GetEventHandler()->ProcessEvent(event
);
2161 return wxEvtHandler::TryParent(event
);
2164 // ----------------------------------------------------------------------------
2166 // ----------------------------------------------------------------------------
2168 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2170 while ( win
&& !win
->IsTopLevel() )
2171 win
= win
->GetParent();
2176 #if wxUSE_ACCESSIBILITY
2177 // ----------------------------------------------------------------------------
2178 // accessible object for windows
2179 // ----------------------------------------------------------------------------
2181 // Can return either a child object, or an integer
2182 // representing the child element, starting from 1.
2183 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& pt
, int* childId
, wxAccessible
** childObject
)
2185 wxASSERT( GetWindow() != NULL
);
2189 return wxACC_NOT_IMPLEMENTED
;
2192 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2193 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2195 wxASSERT( GetWindow() != NULL
);
2199 wxWindow
* win
= NULL
;
2206 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2208 win
= (wxWindow
*) GetWindow()->GetChildren().Nth(elementId
-1)->GetData();
2215 rect
= win
->GetRect();
2216 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2217 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2221 return wxACC_NOT_IMPLEMENTED
;
2224 // Navigates from fromId to toId/toObject.
2225 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2226 int* toId
, wxAccessible
** toObject
)
2228 wxASSERT( GetWindow() != NULL
);
2234 case wxNAVDIR_FIRSTCHILD
:
2236 if (GetWindow()->GetChildren().GetCount() == 0)
2238 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2239 *toObject
= childWindow
->GetOrCreateAccessible();
2243 case wxNAVDIR_LASTCHILD
:
2245 if (GetWindow()->GetChildren().GetCount() == 0)
2247 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2248 *toObject
= childWindow
->GetOrCreateAccessible();
2252 case wxNAVDIR_RIGHT
:
2256 wxWindowList::Node
*node
= NULL
;
2259 // Can't navigate to sibling of this window
2260 // if we're a top-level window.
2261 if (!GetWindow()->GetParent())
2262 return wxACC_NOT_IMPLEMENTED
;
2264 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2268 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2269 node
= (wxWindowList::Node
*) GetWindow()->GetChildren().Nth(fromId
-1);
2272 if (node
&& node
->GetNext())
2274 wxWindow
* nextWindow
= (wxWindow
*) node
->GetNext()->Data();
2275 *toObject
= nextWindow
->GetOrCreateAccessible();
2283 case wxNAVDIR_PREVIOUS
:
2285 wxWindowList::Node
*node
= NULL
;
2288 // Can't navigate to sibling of this window
2289 // if we're a top-level window.
2290 if (!GetWindow()->GetParent())
2291 return wxACC_NOT_IMPLEMENTED
;
2293 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2297 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2298 node
= (wxWindowList::Node
*) GetWindow()->GetChildren().Nth(fromId
-1);
2301 if (node
&& node
->GetPrevious())
2303 wxWindow
* previousWindow
= (wxWindow
*) node
->GetPrevious()->Data();
2304 *toObject
= previousWindow
->GetOrCreateAccessible();
2312 return wxACC_NOT_IMPLEMENTED
;
2315 // Gets the name of the specified object.
2316 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2318 wxASSERT( GetWindow() != NULL
);
2324 // If a child, leave wxWindows to call the function on the actual
2327 return wxACC_NOT_IMPLEMENTED
;
2329 // This will eventually be replaced by specialised
2330 // accessible classes, one for each kind of wxWindows
2331 // control or window.
2332 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2333 title
= ((wxButton
*) GetWindow())->GetLabel();
2335 title
= GetWindow()->GetName();
2337 if (!title
.IsEmpty())
2343 return wxACC_NOT_IMPLEMENTED
;
2346 // Gets the number of children.
2347 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2349 wxASSERT( GetWindow() != NULL
);
2353 *childId
= (int) GetWindow()->GetChildren().GetCount();
2357 // Gets the specified child (starting from 1).
2358 // If *child is NULL and return value is wxACC_OK,
2359 // this means that the child is a simple element and
2360 // not an accessible object.
2361 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2363 wxASSERT( GetWindow() != NULL
);
2373 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2376 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().Nth(childId
-1)->GetData();
2377 *child
= childWindow
->GetOrCreateAccessible();
2384 // Gets the parent, or NULL.
2385 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2387 wxASSERT( GetWindow() != NULL
);
2391 wxWindow
* parentWindow
= GetWindow()->GetParent();
2399 *parent
= parentWindow
->GetOrCreateAccessible();
2407 // Performs the default action. childId is 0 (the action for this object)
2408 // or > 0 (the action for a child).
2409 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2410 // window (e.g. an edit control).
2411 wxAccStatus
wxWindowAccessible::DoDefaultAction(int childId
)
2413 wxASSERT( GetWindow() != NULL
);
2417 return wxACC_NOT_IMPLEMENTED
;
2420 // Gets the default action for this object (0) or > 0 (the action for a child).
2421 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2422 // string if there is no action.
2423 // The retrieved string describes the action that is performed on an object,
2424 // not what the object does as a result. For example, a toolbar button that prints
2425 // a document has a default action of "Press" rather than "Prints the current document."
2426 wxAccStatus
wxWindowAccessible::GetDefaultAction(int childId
, wxString
* actionName
)
2428 wxASSERT( GetWindow() != NULL
);
2432 return wxACC_NOT_IMPLEMENTED
;
2435 // Returns the description for this object or a child.
2436 wxAccStatus
wxWindowAccessible::GetDescription(int childId
, wxString
* description
)
2438 wxASSERT( GetWindow() != NULL
);
2442 wxString
ht(GetWindow()->GetHelpText());
2448 return wxACC_NOT_IMPLEMENTED
;
2451 // Returns help text for this object or a child, similar to tooltip text.
2452 wxAccStatus
wxWindowAccessible::GetHelpText(int childId
, wxString
* helpText
)
2454 wxASSERT( GetWindow() != NULL
);
2458 wxString
ht(GetWindow()->GetHelpText());
2464 return wxACC_NOT_IMPLEMENTED
;
2467 // Returns the keyboard shortcut for this object or child.
2468 // Return e.g. ALT+K
2469 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int childId
, wxString
* shortcut
)
2471 wxASSERT( GetWindow() != NULL
);
2475 return wxACC_NOT_IMPLEMENTED
;
2478 // Returns a role constant.
2479 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
2481 wxASSERT( GetWindow() != NULL
);
2485 // If a child, leave wxWindows to call the function on the actual
2488 return wxACC_NOT_IMPLEMENTED
;
2490 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2491 return wxACC_NOT_IMPLEMENTED
;
2493 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2494 return wxACC_NOT_IMPLEMENTED
;
2497 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2498 return wxACC_NOT_IMPLEMENTED
;
2501 //*role = wxROLE_SYSTEM_CLIENT;
2502 *role
= wxROLE_SYSTEM_CLIENT
;
2505 return wxACC_NOT_IMPLEMENTED
;
2508 // Returns a state constant.
2509 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
2511 wxASSERT( GetWindow() != NULL
);
2515 // If a child, leave wxWindows to call the function on the actual
2518 return wxACC_NOT_IMPLEMENTED
;
2520 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2521 return wxACC_NOT_IMPLEMENTED
;
2524 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2525 return wxACC_NOT_IMPLEMENTED
;
2528 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2529 return wxACC_NOT_IMPLEMENTED
;
2535 return wxACC_NOT_IMPLEMENTED
;
2538 // Returns a localized string representing the value for the object
2540 wxAccStatus
wxWindowAccessible::GetValue(int childId
, wxString
* strValue
)
2542 wxASSERT( GetWindow() != NULL
);
2546 return wxACC_NOT_IMPLEMENTED
;
2549 // Selects the object or child.
2550 wxAccStatus
wxWindowAccessible::Select(int childId
, wxAccSelectionFlags selectFlags
)
2552 wxASSERT( GetWindow() != NULL
);
2556 return wxACC_NOT_IMPLEMENTED
;
2559 // Gets the window with the keyboard focus.
2560 // If childId is 0 and child is NULL, no object in
2561 // this subhierarchy has the focus.
2562 // If this object has the focus, child should be 'this'.
2563 wxAccStatus
wxWindowAccessible::GetFocus(int* childId
, wxAccessible
** child
)
2565 wxASSERT( GetWindow() != NULL
);
2569 return wxACC_NOT_IMPLEMENTED
;
2572 // Gets a variant representing the selected children
2574 // Acceptable values:
2575 // - a null variant (IsNull() returns TRUE)
2576 // - a list variant (GetType() == wxT("list")
2577 // - an integer representing the selected child element,
2578 // or 0 if this object is selected (GetType() == wxT("long")
2579 // - a "void*" pointer to a wxAccessible child object
2580 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* selections
)
2582 wxASSERT( GetWindow() != NULL
);
2586 return wxACC_NOT_IMPLEMENTED
;
2589 #endif // wxUSE_ACCESSIBILITY