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(-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
;
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
& 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") );
271 #endif // wxUSE_CARET
274 delete m_windowValidator
;
275 #endif // wxUSE_VALIDATORS
277 #if wxUSE_CONSTRAINTS
278 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
279 // at deleted windows as they delete themselves.
280 DeleteRelatedConstraints();
284 // This removes any dangling pointers to this window in other windows'
285 // constraintsInvolvedIn lists.
286 UnsetConstraints(m_constraints
);
287 delete m_constraints
;
288 m_constraints
= NULL
;
290 #endif // wxUSE_CONSTRAINTS
292 if ( m_containingSizer
)
293 m_containingSizer
->Detach( (wxWindow
*)this );
295 delete m_windowSizer
;
297 #if wxUSE_DRAG_AND_DROP
299 #endif // wxUSE_DRAG_AND_DROP
303 #endif // wxUSE_TOOLTIPS
305 #if wxUSE_ACCESSIBILITY
309 // reset the dangling pointer our parent window may keep to us
310 if ( m_parent
&& m_parent
->GetDefaultItem() == this )
312 m_parent
->SetDefaultItem(NULL
);
316 bool wxWindowBase::Destroy()
323 bool wxWindowBase::Close(bool force
)
325 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
326 event
.SetEventObject(this);
327 event
.SetCanVeto(!force
);
329 // return FALSE if window wasn't closed because the application vetoed the
331 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
334 bool wxWindowBase::DestroyChildren()
336 wxWindowList::compatibility_iterator node
;
339 // we iterate until the list becomes empty
340 node
= GetChildren().GetFirst();
344 wxWindow
*child
= node
->GetData();
346 wxASSERT_MSG( child
, wxT("children list contains empty nodes") );
352 wxASSERT_MSG( !GetChildren().Find(child
),
353 wxT("child didn't remove itself using RemoveChild()") );
359 // ----------------------------------------------------------------------------
360 // size/position related methods
361 // ----------------------------------------------------------------------------
363 // centre the window with respect to its parent in either (or both) directions
364 void wxWindowBase::Centre(int direction
)
366 // the position/size of the parent window or of the entire screen
368 int widthParent
, heightParent
;
370 wxWindow
*parent
= NULL
;
372 if ( !(direction
& wxCENTRE_ON_SCREEN
) )
374 // find the parent to centre this window on: it should be the
375 // immediate parent for the controls but the top level parent for the
376 // top level windows (like dialogs)
377 parent
= GetParent();
380 while ( parent
&& !parent
->IsTopLevel() )
382 parent
= parent
->GetParent();
386 // there is no wxTopLevelWindow under wxMotif yet
388 // we shouldn't center the dialog on the iconized window: under
389 // Windows, for example, this places it completely off the screen
392 wxTopLevelWindow
*winTop
= wxDynamicCast(parent
, wxTopLevelWindow
);
393 if ( winTop
&& winTop
->IsIconized() )
398 #endif // __WXMOTIF__
400 // did we find the parent?
404 direction
|= wxCENTRE_ON_SCREEN
;
408 if ( direction
& wxCENTRE_ON_SCREEN
)
410 // centre with respect to the whole screen
411 wxDisplaySize(&widthParent
, &heightParent
);
417 // centre on the parent
418 parent
->GetSize(&widthParent
, &heightParent
);
420 // adjust to the parents position
421 posParent
= parent
->GetPosition();
425 // centre inside the parents client rectangle
426 parent
->GetClientSize(&widthParent
, &heightParent
);
431 GetSize(&width
, &height
);
436 if ( direction
& wxHORIZONTAL
)
437 xNew
= (widthParent
- width
)/2;
439 if ( direction
& wxVERTICAL
)
440 yNew
= (heightParent
- height
)/2;
445 // Base size of the visible dimensions of the display
446 // to take into account the taskbar
447 wxRect rect
= wxGetClientDisplayRect();
448 wxSize
size (rect
.width
,rect
.height
);
450 // NB: in wxMSW, negative position may not neccessary mean "out of screen",
451 // but it may mean that the window is placed on other than the main
452 // display. Therefore we only make sure centered window is on the main display
453 // if the parent is at least partially present here.
454 if (posParent
.x
+ widthParent
>= 0) // if parent is (partially) on the main display
458 else if (xNew
+width
> size
.x
)
459 xNew
= size
.x
-width
-1;
461 if (posParent
.y
+ heightParent
>= 0) // if parent is (partially) on the main display
463 if (yNew
+height
> size
.y
)
464 yNew
= size
.y
-height
-1;
466 // Make certain that the title bar is initially visible
467 // always, even if this would push the bottom of the
468 // dialog of the visible area of the display
473 // move the window to this position (keeping the old size but using
474 // SetSize() and not Move() to allow xNew and/or yNew to be -1)
475 SetSize(xNew
, yNew
, width
, height
, wxSIZE_ALLOW_MINUS_ONE
);
478 // fits the window around the children
479 void wxWindowBase::Fit()
481 if ( GetChildren().GetCount() > 0 )
483 SetClientSize(DoGetBestSize());
485 //else: do nothing if we have no children
488 // fits virtual size (ie. scrolled area etc.) around children
489 void wxWindowBase::FitInside()
491 if ( GetChildren().GetCount() > 0 )
493 SetVirtualSize( GetBestVirtualSize() );
497 // return the size best suited for the current window
498 wxSize
wxWindowBase::DoGetBestSize() const
502 return m_windowSizer
->GetMinSize();
504 #if wxUSE_CONSTRAINTS
505 else if ( m_constraints
)
507 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
509 // our minimal acceptable size is such that all our windows fit inside
513 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
515 node
= node
->GetNext() )
517 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
520 // it's not normal that we have an unconstrained child, but
521 // what can we do about it?
525 int x
= c
->right
.GetValue(),
526 y
= c
->bottom
.GetValue();
534 // TODO: we must calculate the overlaps somehow, otherwise we
535 // will never return a size bigger than the current one :-(
538 return wxSize(maxX
, maxY
);
540 #endif // wxUSE_CONSTRAINTS
541 else if ( GetChildren().GetCount() > 0 )
543 // our minimal acceptable size is such that all our windows fit inside
547 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
549 node
= node
->GetNext() )
551 wxWindow
*win
= node
->GetData();
552 if ( win
->IsTopLevel()
554 || wxDynamicCast(win
, wxStatusBar
)
555 #endif // wxUSE_STATUSBAR
558 // dialogs and frames lie in different top level windows -
559 // don't deal with them here; as for the status bars, they
560 // don't lie in the client area at all
565 win
->GetPosition(&wx
, &wy
);
567 // if the window hadn't been positioned yet, assume that it is in
574 win
->GetSize(&ww
, &wh
);
575 if ( wx
+ ww
> maxX
)
577 if ( wy
+ wh
> maxY
)
581 // for compatibility with the old versions and because it really looks
582 // slightly more pretty like this, add a pad
586 return wxSize(maxX
, maxY
);
590 // for a generic window there is no natural best size - just use the
596 // by default the origin is not shifted
597 wxPoint
wxWindowBase::GetClientAreaOrigin() const
599 return wxPoint(0, 0);
602 // set the min/max size of the window
603 void wxWindowBase::SetSizeHints(int minW
, int minH
,
605 int WXUNUSED(incW
), int WXUNUSED(incH
))
607 // setting min width greater than max width leads to infinite loops under
608 // X11 and generally doesn't make any sense, so don't allow it
609 wxCHECK_RET( (minW
== -1 || maxW
== -1 || minW
<= maxW
) &&
610 (minH
== -1 || maxH
== -1 || minH
<= maxH
),
611 _T("min width/height must be less than max width/height!") );
619 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
622 m_minVirtualWidth
= minW
;
623 m_maxVirtualWidth
= maxW
;
624 m_minVirtualHeight
= minH
;
625 m_maxVirtualHeight
= maxH
;
628 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
630 if ( m_minVirtualWidth
!= -1 && m_minVirtualWidth
> x
)
631 x
= m_minVirtualWidth
;
632 if ( m_maxVirtualWidth
!= -1 && m_maxVirtualWidth
< x
)
633 x
= m_maxVirtualWidth
;
634 if ( m_minVirtualHeight
!= -1 && m_minVirtualHeight
> y
)
635 y
= m_minVirtualHeight
;
636 if ( m_maxVirtualHeight
!= -1 && m_maxVirtualHeight
< y
)
637 y
= m_maxVirtualHeight
;
639 m_virtualSize
= wxSize(x
, y
);
642 wxSize
wxWindowBase::DoGetVirtualSize() const
644 wxSize
s( GetClientSize() );
646 return wxSize( wxMax( m_virtualSize
.GetWidth(), s
.GetWidth() ),
647 wxMax( m_virtualSize
.GetHeight(), s
.GetHeight() ) );
650 // ----------------------------------------------------------------------------
651 // show/hide/enable/disable the window
652 // ----------------------------------------------------------------------------
654 bool wxWindowBase::Show(bool show
)
656 if ( show
!= m_isShown
)
668 bool wxWindowBase::Enable(bool enable
)
670 if ( enable
!= m_isEnabled
)
672 m_isEnabled
= enable
;
681 // ----------------------------------------------------------------------------
683 // ----------------------------------------------------------------------------
685 bool wxWindowBase::IsTopLevel() const
690 // ----------------------------------------------------------------------------
691 // reparenting the window
692 // ----------------------------------------------------------------------------
694 void wxWindowBase::AddChild(wxWindowBase
*child
)
696 wxCHECK_RET( child
, wxT("can't add a NULL child") );
698 // this should never happen and it will lead to a crash later if it does
699 // because RemoveChild() will remove only one node from the children list
700 // and the other(s) one(s) will be left with dangling pointers in them
701 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
703 GetChildren().Append((wxWindow
*)child
);
704 child
->SetParent(this);
707 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
709 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
711 GetChildren().DeleteObject((wxWindow
*)child
);
712 child
->SetParent(NULL
);
715 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
717 wxWindow
*oldParent
= GetParent();
718 if ( newParent
== oldParent
)
724 // unlink this window from the existing parent.
727 oldParent
->RemoveChild(this);
731 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
734 // add it to the new one
737 newParent
->AddChild(this);
741 wxTopLevelWindows
.Append((wxWindow
*)this);
747 // ----------------------------------------------------------------------------
748 // event handler stuff
749 // ----------------------------------------------------------------------------
751 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
753 wxEvtHandler
*handlerOld
= GetEventHandler();
755 handler
->SetNextHandler(handlerOld
);
758 GetEventHandler()->SetPreviousHandler(handler
);
760 SetEventHandler(handler
);
763 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
765 wxEvtHandler
*handlerA
= GetEventHandler();
768 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
769 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
772 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
773 SetEventHandler(handlerB
);
778 handlerA
= (wxEvtHandler
*)NULL
;
785 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
787 wxCHECK_MSG( handler
, FALSE
, _T("RemoveEventHandler(NULL) called") );
789 wxEvtHandler
*handlerPrev
= NULL
,
790 *handlerCur
= GetEventHandler();
793 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
795 if ( handlerCur
== handler
)
799 handlerPrev
->SetNextHandler(handlerNext
);
803 SetEventHandler(handlerNext
);
808 handlerNext
->SetPreviousHandler ( handlerPrev
);
810 handler
->SetNextHandler(NULL
);
815 handlerPrev
= handlerCur
;
816 handlerCur
= handlerNext
;
819 wxFAIL_MSG( _T("where has the event handler gone?") );
824 // ----------------------------------------------------------------------------
826 // ----------------------------------------------------------------------------
828 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
830 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
833 m_backgroundColour
= colour
;
840 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
842 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
845 m_foregroundColour
= colour
;
852 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
854 // setting an invalid cursor is ok, it means that we don't have any special
856 if ( m_cursor
== cursor
)
867 bool wxWindowBase::SetFont(const wxFont
& font
)
869 // don't try to set invalid font, always fall back to the default
870 const wxFont
& fontOk
= font
.Ok() ? font
: *wxSWISS_FONT
;
872 if ( fontOk
== m_font
)
887 void wxWindowBase::SetPalette(const wxPalette
& pal
)
889 m_hasCustomPalette
= TRUE
;
892 // VZ: can anyone explain me what do we do here?
893 wxWindowDC
d((wxWindow
*) this);
897 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
899 wxWindow
*win
= (wxWindow
*)this;
900 while ( win
&& !win
->HasCustomPalette() )
902 win
= win
->GetParent();
908 #endif // wxUSE_PALETTE
911 void wxWindowBase::SetCaret(wxCaret
*caret
)
922 wxASSERT_MSG( m_caret
->GetWindow() == this,
923 wxT("caret should be created associated to this window") );
926 #endif // wxUSE_CARET
929 // ----------------------------------------------------------------------------
931 // ----------------------------------------------------------------------------
933 void wxWindowBase::SetValidator(const wxValidator
& validator
)
935 if ( m_windowValidator
)
936 delete m_windowValidator
;
938 m_windowValidator
= (wxValidator
*)validator
.Clone();
940 if ( m_windowValidator
)
941 m_windowValidator
->SetWindow(this) ;
943 #endif // wxUSE_VALIDATORS
945 // ----------------------------------------------------------------------------
946 // update region stuff
947 // ----------------------------------------------------------------------------
949 wxRect
wxWindowBase::GetUpdateClientRect() const
951 wxRegion rgnUpdate
= GetUpdateRegion();
952 rgnUpdate
.Intersect(GetClientRect());
953 wxRect rectUpdate
= rgnUpdate
.GetBox();
954 wxPoint ptOrigin
= GetClientAreaOrigin();
955 rectUpdate
.x
-= ptOrigin
.x
;
956 rectUpdate
.y
-= ptOrigin
.y
;
961 bool wxWindowBase::IsExposed(int x
, int y
) const
963 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
966 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
968 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
971 void wxWindowBase::ClearBackground()
973 // wxGTK uses its own version, no need to add never used code
975 wxClientDC
dc((wxWindow
*)this);
976 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
977 dc
.SetBackground(brush
);
982 // ----------------------------------------------------------------------------
983 // find child window by id or name
984 // ----------------------------------------------------------------------------
986 wxWindow
*wxWindowBase::FindWindow( long id
)
988 if ( id
== m_windowId
)
989 return (wxWindow
*)this;
991 wxWindowBase
*res
= (wxWindow
*)NULL
;
992 wxWindowList::compatibility_iterator node
;
993 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
995 wxWindowBase
*child
= node
->GetData();
996 res
= child
->FindWindow( id
);
999 return (wxWindow
*)res
;
1002 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
1004 if ( name
== m_windowName
)
1005 return (wxWindow
*)this;
1007 wxWindowBase
*res
= (wxWindow
*)NULL
;
1008 wxWindowList::compatibility_iterator node
;
1009 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1011 wxWindow
*child
= node
->GetData();
1012 res
= child
->FindWindow(name
);
1015 return (wxWindow
*)res
;
1019 // find any window by id or name or label: If parent is non-NULL, look through
1020 // children for a label or title matching the specified string. If NULL, look
1021 // through all top-level windows.
1023 // to avoid duplicating code we reuse the same helper function but with
1024 // different comparators
1026 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1027 const wxString
& label
, long id
);
1030 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1033 return win
->GetLabel() == label
;
1037 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1040 return win
->GetName() == label
;
1044 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1047 return win
->GetId() == id
;
1050 // recursive helper for the FindWindowByXXX() functions
1052 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1053 const wxString
& label
,
1055 wxFindWindowCmp cmp
)
1059 // see if this is the one we're looking for
1060 if ( (*cmp
)(parent
, label
, id
) )
1061 return (wxWindow
*)parent
;
1063 // It wasn't, so check all its children
1064 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1066 node
= node
->GetNext() )
1068 // recursively check each child
1069 wxWindow
*win
= (wxWindow
*)node
->GetData();
1070 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1080 // helper for FindWindowByXXX()
1082 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1083 const wxString
& label
,
1085 wxFindWindowCmp cmp
)
1089 // just check parent and all its children
1090 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1093 // start at very top of wx's windows
1094 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1096 node
= node
->GetNext() )
1098 // recursively check each window & its children
1099 wxWindow
*win
= node
->GetData();
1100 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1110 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1112 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1117 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1119 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1123 // fall back to the label
1124 win
= FindWindowByLabel(title
, parent
);
1132 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1134 return wxFindWindowHelper(parent
, _T(""), id
, wxFindWindowCmpIds
);
1137 // ----------------------------------------------------------------------------
1138 // dialog oriented functions
1139 // ----------------------------------------------------------------------------
1141 void wxWindowBase::MakeModal(bool modal
)
1143 // Disable all other windows
1146 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1149 wxWindow
*win
= node
->GetData();
1151 win
->Enable(!modal
);
1153 node
= node
->GetNext();
1158 bool wxWindowBase::Validate()
1160 #if wxUSE_VALIDATORS
1161 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1163 wxWindowList::compatibility_iterator node
;
1164 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1166 wxWindowBase
*child
= node
->GetData();
1167 wxValidator
*validator
= child
->GetValidator();
1168 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1173 if ( recurse
&& !child
->Validate() )
1178 #endif // wxUSE_VALIDATORS
1183 bool wxWindowBase::TransferDataToWindow()
1185 #if wxUSE_VALIDATORS
1186 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1188 wxWindowList::compatibility_iterator node
;
1189 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1191 wxWindowBase
*child
= node
->GetData();
1192 wxValidator
*validator
= child
->GetValidator();
1193 if ( validator
&& !validator
->TransferToWindow() )
1195 wxLogWarning(_("Could not transfer data to window"));
1197 wxLog::FlushActive();
1205 if ( !child
->TransferDataToWindow() )
1207 // warning already given
1212 #endif // wxUSE_VALIDATORS
1217 bool wxWindowBase::TransferDataFromWindow()
1219 #if wxUSE_VALIDATORS
1220 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1222 wxWindowList::compatibility_iterator node
;
1223 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1225 wxWindow
*child
= node
->GetData();
1226 wxValidator
*validator
= child
->GetValidator();
1227 if ( validator
&& !validator
->TransferFromWindow() )
1229 // nop warning here because the application is supposed to give
1230 // one itself - we don't know here what might have gone wrongly
1237 if ( !child
->TransferDataFromWindow() )
1239 // warning already given
1244 #endif // wxUSE_VALIDATORS
1249 void wxWindowBase::InitDialog()
1251 wxInitDialogEvent
event(GetId());
1252 event
.SetEventObject( this );
1253 GetEventHandler()->ProcessEvent(event
);
1256 // ----------------------------------------------------------------------------
1257 // context-sensitive help support
1258 // ----------------------------------------------------------------------------
1262 // associate this help text with this window
1263 void wxWindowBase::SetHelpText(const wxString
& text
)
1265 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1268 helpProvider
->AddHelp(this, text
);
1272 // associate this help text with all windows with the same id as this
1274 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1276 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1279 helpProvider
->AddHelp(GetId(), text
);
1283 // get the help string associated with this window (may be empty)
1284 wxString
wxWindowBase::GetHelpText() const
1287 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1290 text
= helpProvider
->GetHelp(this);
1296 // show help for this window
1297 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1299 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1302 if ( helpProvider
->ShowHelp(this) )
1304 // skip the event.Skip() below
1312 #endif // wxUSE_HELP
1314 // ----------------------------------------------------------------------------
1315 // tooltipsroot.Replace("\\", "/");
1316 // ----------------------------------------------------------------------------
1320 void wxWindowBase::SetToolTip( const wxString
&tip
)
1322 // don't create the new tooltip if we already have one
1325 m_tooltip
->SetTip( tip
);
1329 SetToolTip( new wxToolTip( tip
) );
1332 // setting empty tooltip text does not remove the tooltip any more - use
1333 // SetToolTip((wxToolTip *)NULL) for this
1336 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1341 m_tooltip
= tooltip
;
1344 #endif // wxUSE_TOOLTIPS
1346 // ----------------------------------------------------------------------------
1347 // constraints and sizers
1348 // ----------------------------------------------------------------------------
1350 #if wxUSE_CONSTRAINTS
1352 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1354 if ( m_constraints
)
1356 UnsetConstraints(m_constraints
);
1357 delete m_constraints
;
1359 m_constraints
= constraints
;
1360 if ( m_constraints
)
1362 // Make sure other windows know they're part of a 'meaningful relationship'
1363 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1364 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1365 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1366 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1367 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1368 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1369 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1370 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1371 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1372 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1373 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1374 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1375 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1376 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1377 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1378 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1382 // This removes any dangling pointers to this window in other windows'
1383 // constraintsInvolvedIn lists.
1384 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1388 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1389 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1390 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1391 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1392 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1393 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1394 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1395 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1396 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1397 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1398 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1399 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1400 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1401 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1402 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1403 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1407 // Back-pointer to other windows we're involved with, so if we delete this
1408 // window, we must delete any constraints we're involved with.
1409 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1411 if ( !m_constraintsInvolvedIn
)
1412 m_constraintsInvolvedIn
= new wxWindowList
;
1413 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1414 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1417 // REMOVE back-pointer to other windows we're involved with.
1418 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1420 if ( m_constraintsInvolvedIn
)
1421 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1424 // Reset any constraints that mention this window
1425 void wxWindowBase::DeleteRelatedConstraints()
1427 if ( m_constraintsInvolvedIn
)
1429 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1432 wxWindow
*win
= node
->GetData();
1433 wxLayoutConstraints
*constr
= win
->GetConstraints();
1435 // Reset any constraints involving this window
1438 constr
->left
.ResetIfWin(this);
1439 constr
->top
.ResetIfWin(this);
1440 constr
->right
.ResetIfWin(this);
1441 constr
->bottom
.ResetIfWin(this);
1442 constr
->width
.ResetIfWin(this);
1443 constr
->height
.ResetIfWin(this);
1444 constr
->centreX
.ResetIfWin(this);
1445 constr
->centreY
.ResetIfWin(this);
1448 wxWindowList::compatibility_iterator next
= node
->GetNext();
1449 m_constraintsInvolvedIn
->Erase(node
);
1453 delete m_constraintsInvolvedIn
;
1454 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1458 #endif // wxUSE_CONSTRAINTS
1460 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1463 delete m_windowSizer
;
1465 m_windowSizer
= sizer
;
1467 SetAutoLayout( sizer
!= NULL
);
1470 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1472 SetSizer( sizer
, deleteOld
);
1473 sizer
->SetSizeHints( (wxWindow
*) this );
1476 #if wxUSE_CONSTRAINTS
1478 void wxWindowBase::SatisfyConstraints()
1480 wxLayoutConstraints
*constr
= GetConstraints();
1481 bool wasOk
= constr
&& constr
->AreSatisfied();
1483 ResetConstraints(); // Mark all constraints as unevaluated
1487 // if we're a top level panel (i.e. our parent is frame/dialog), our
1488 // own constraints will never be satisfied any more unless we do it
1492 while ( noChanges
> 0 )
1494 LayoutPhase1(&noChanges
);
1498 LayoutPhase2(&noChanges
);
1501 #endif // wxUSE_CONSTRAINTS
1503 bool wxWindowBase::Layout()
1505 // If there is a sizer, use it instead of the constraints
1509 GetVirtualSize(&w
, &h
);
1510 GetSizer()->SetDimension( 0, 0, w
, h
);
1512 #if wxUSE_CONSTRAINTS
1515 SatisfyConstraints(); // Find the right constraints values
1516 SetConstraintSizes(); // Recursively set the real window sizes
1523 #if wxUSE_CONSTRAINTS
1525 // first phase of the constraints evaluation: set our own constraints
1526 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1528 wxLayoutConstraints
*constr
= GetConstraints();
1530 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1533 // second phase: set the constraints for our children
1534 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1541 // Layout grand children
1547 // Do a phase of evaluating child constraints
1548 bool wxWindowBase::DoPhase(int phase
)
1550 // the list containing the children for which the constraints are already
1552 wxWindowList succeeded
;
1554 // the max number of iterations we loop before concluding that we can't set
1556 static const int maxIterations
= 500;
1558 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1562 // loop over all children setting their constraints
1563 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1565 node
= node
->GetNext() )
1567 wxWindow
*child
= node
->GetData();
1568 if ( child
->IsTopLevel() )
1570 // top level children are not inside our client area
1574 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1576 // this one is either already ok or nothing we can do about it
1580 int tempNoChanges
= 0;
1581 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1582 : child
->LayoutPhase2(&tempNoChanges
);
1583 noChanges
+= tempNoChanges
;
1587 succeeded
.Append(child
);
1593 // constraints are set
1601 void wxWindowBase::ResetConstraints()
1603 wxLayoutConstraints
*constr
= GetConstraints();
1606 constr
->left
.SetDone(FALSE
);
1607 constr
->top
.SetDone(FALSE
);
1608 constr
->right
.SetDone(FALSE
);
1609 constr
->bottom
.SetDone(FALSE
);
1610 constr
->width
.SetDone(FALSE
);
1611 constr
->height
.SetDone(FALSE
);
1612 constr
->centreX
.SetDone(FALSE
);
1613 constr
->centreY
.SetDone(FALSE
);
1616 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1619 wxWindow
*win
= node
->GetData();
1620 if ( !win
->IsTopLevel() )
1621 win
->ResetConstraints();
1622 node
= node
->GetNext();
1626 // Need to distinguish between setting the 'fake' size for windows and sizers,
1627 // and setting the real values.
1628 void wxWindowBase::SetConstraintSizes(bool recurse
)
1630 wxLayoutConstraints
*constr
= GetConstraints();
1631 if ( constr
&& constr
->AreSatisfied() )
1633 int x
= constr
->left
.GetValue();
1634 int y
= constr
->top
.GetValue();
1635 int w
= constr
->width
.GetValue();
1636 int h
= constr
->height
.GetValue();
1638 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1639 (constr
->height
.GetRelationship() != wxAsIs
) )
1641 SetSize(x
, y
, w
, h
);
1645 // If we don't want to resize this window, just move it...
1651 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1652 GetClassInfo()->GetClassName(),
1658 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1661 wxWindow
*win
= node
->GetData();
1662 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1663 win
->SetConstraintSizes();
1664 node
= node
->GetNext();
1669 // Only set the size/position of the constraint (if any)
1670 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1672 wxLayoutConstraints
*constr
= GetConstraints();
1677 constr
->left
.SetValue(x
);
1678 constr
->left
.SetDone(TRUE
);
1682 constr
->top
.SetValue(y
);
1683 constr
->top
.SetDone(TRUE
);
1687 constr
->width
.SetValue(w
);
1688 constr
->width
.SetDone(TRUE
);
1692 constr
->height
.SetValue(h
);
1693 constr
->height
.SetDone(TRUE
);
1698 void wxWindowBase::MoveConstraint(int x
, int y
)
1700 wxLayoutConstraints
*constr
= GetConstraints();
1705 constr
->left
.SetValue(x
);
1706 constr
->left
.SetDone(TRUE
);
1710 constr
->top
.SetValue(y
);
1711 constr
->top
.SetDone(TRUE
);
1716 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1718 wxLayoutConstraints
*constr
= GetConstraints();
1721 *w
= constr
->width
.GetValue();
1722 *h
= constr
->height
.GetValue();
1728 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1730 wxLayoutConstraints
*constr
= GetConstraints();
1733 *w
= constr
->width
.GetValue();
1734 *h
= constr
->height
.GetValue();
1737 GetClientSize(w
, h
);
1740 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1742 wxLayoutConstraints
*constr
= GetConstraints();
1745 *x
= constr
->left
.GetValue();
1746 *y
= constr
->top
.GetValue();
1752 #endif // wxUSE_CONSTRAINTS
1754 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
1756 // don't do it for the dialogs/frames - they float independently of their
1758 if ( !IsTopLevel() )
1760 wxWindow
*parent
= GetParent();
1761 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
1763 wxPoint
pt(parent
->GetClientAreaOrigin());
1770 // ----------------------------------------------------------------------------
1771 // do Update UI processing for child controls
1772 // ----------------------------------------------------------------------------
1774 void wxWindowBase::UpdateWindowUI(long flags
)
1776 wxUpdateUIEvent
event(GetId());
1777 event
.m_eventObject
= this;
1779 if ( GetEventHandler()->ProcessEvent(event
) )
1781 DoUpdateWindowUI(event
);
1784 if (flags
& wxUPDATE_UI_RECURSE
)
1786 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1789 wxWindow
* child
= (wxWindow
*) node
->GetData();
1790 child
->UpdateWindowUI(flags
);
1791 node
= node
->GetNext();
1796 // do the window-specific processing after processing the update event
1797 // TODO: take specific knowledge out of this function and
1798 // put in each control's base class. Unfortunately we don't
1799 // yet have base implementation files for wxCheckBox and wxRadioButton.
1800 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
1802 if ( event
.GetSetEnabled() )
1803 Enable(event
.GetEnabled());
1806 if ( event
.GetSetText() )
1808 wxControl
*control
= wxDynamicCastThis(wxControl
);
1811 if ( event
.GetText() != control
->GetLabel() )
1812 control
->SetLabel(event
.GetText());
1815 wxCheckBox
*checkbox
= wxDynamicCastThis(wxCheckBox
);
1818 if ( event
.GetSetChecked() )
1819 checkbox
->SetValue(event
.GetChecked());
1821 #endif // wxUSE_CHECKBOX
1824 wxRadioButton
*radiobtn
= wxDynamicCastThis(wxRadioButton
);
1827 if ( event
.GetSetChecked() )
1828 radiobtn
->SetValue(event
.GetChecked());
1830 #endif // wxUSE_RADIOBTN
1836 // call internal idle recursively
1837 // may be obsolete (wait until OnIdle scheme stabilises)
1838 void wxWindowBase::ProcessInternalIdle()
1842 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1845 wxWindow
*child
= node
->GetData();
1846 child
->ProcessInternalIdle();
1847 node
= node
->GetNext();
1852 // ----------------------------------------------------------------------------
1853 // dialog units translations
1854 // ----------------------------------------------------------------------------
1856 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1858 int charWidth
= GetCharWidth();
1859 int charHeight
= GetCharHeight();
1860 wxPoint
pt2(-1, -1);
1862 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1864 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1869 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1871 int charWidth
= GetCharWidth();
1872 int charHeight
= GetCharHeight();
1873 wxPoint
pt2(-1, -1);
1875 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1877 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1882 // ----------------------------------------------------------------------------
1884 // ----------------------------------------------------------------------------
1886 // propagate the colour change event to the subwindows
1887 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1889 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1892 // Only propagate to non-top-level windows
1893 wxWindow
*win
= node
->GetData();
1894 if ( !win
->IsTopLevel() )
1896 wxSysColourChangedEvent event2
;
1897 event
.m_eventObject
= win
;
1898 win
->GetEventHandler()->ProcessEvent(event2
);
1901 node
= node
->GetNext();
1905 // the default action is to populate dialog with data when it's created,
1906 // and nudge the UI into displaying itself correctly in case
1907 // we've turned the wxUpdateUIEvents frequency down low.
1908 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1910 TransferDataToWindow();
1912 // Update the UI at this point
1913 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
1916 // process Ctrl-Alt-mclick
1917 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
1920 if ( event
.ControlDown() && event
.AltDown() )
1922 // don't translate these strings
1925 #ifdef __WXUNIVERSAL__
1927 #endif // __WXUNIVERSAL__
1929 switch ( wxGetOsVersion() )
1931 case wxMOTIF_X
: port
+= _T("Motif"); break;
1933 case wxMAC_DARWIN
: port
+= _T("Mac"); break;
1934 case wxBEOS
: port
+= _T("BeOS"); break;
1938 case wxGTK_BEOS
: port
+= _T("GTK"); break;
1944 case wxWIN386
: port
+= _T("MS Windows"); break;
1948 case wxMGL_OS2
: port
+= _T("MGL"); break;
1950 case wxOS2_PM
: port
+= _T("OS/2"); break;
1951 default: port
+= _T("unknown"); break;
1954 wxMessageBox(wxString::Format(
1956 " wxWindows Library (%s port)\nVersion %u.%u.%u%s, compiled at %s %s\n Copyright (c) 1995-2002 wxWindows team"
1970 _T("wxWindows information"),
1971 wxICON_INFORMATION
| wxOK
,
1975 #endif // wxUSE_MSGDLG
1981 // ----------------------------------------------------------------------------
1983 // ----------------------------------------------------------------------------
1985 #if wxUSE_ACCESSIBILITY
1986 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
1988 if (m_accessible
&& (accessible
!= m_accessible
))
1989 delete m_accessible
;
1990 m_accessible
= accessible
;
1992 m_accessible
->SetWindow((wxWindow
*) this);
1995 // Returns the accessible object, creating if necessary.
1996 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
1999 m_accessible
= CreateAccessible();
2000 return m_accessible
;
2003 // Override to create a specific accessible object.
2004 wxAccessible
* wxWindowBase::CreateAccessible()
2006 return new wxWindowAccessible((wxWindow
*) this);
2012 // ----------------------------------------------------------------------------
2013 // list classes implementation
2014 // ----------------------------------------------------------------------------
2016 void wxWindowListNode::DeleteData()
2018 delete (wxWindow
*)GetData();
2022 // ----------------------------------------------------------------------------
2024 // ----------------------------------------------------------------------------
2026 wxBorder
wxWindowBase::GetBorder(long flags
) const
2028 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2029 if ( border
== wxBORDER_DEFAULT
)
2031 border
= GetDefaultBorder();
2037 wxBorder
wxWindowBase::GetDefaultBorder() const
2039 return wxBORDER_NONE
;
2042 // ----------------------------------------------------------------------------
2044 // ----------------------------------------------------------------------------
2046 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2048 // here we just check if the point is inside the window or not
2050 // check the top and left border first
2051 bool outside
= x
< 0 || y
< 0;
2054 // check the right and bottom borders too
2055 wxSize size
= GetSize();
2056 outside
= x
>= size
.x
|| y
>= size
.y
;
2059 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2062 // ----------------------------------------------------------------------------
2064 // ----------------------------------------------------------------------------
2066 struct WXDLLEXPORT wxWindowNext
2070 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2072 void wxWindowBase::CaptureMouse()
2074 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this);
2076 wxWindow
*winOld
= GetCapture();
2079 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2082 wxWindowNext
*item
= new wxWindowNext
;
2084 item
->next
= ms_winCaptureNext
;
2085 ms_winCaptureNext
= item
;
2087 //else: no mouse capture to save
2092 void wxWindowBase::ReleaseMouse()
2094 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this);
2096 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2100 if ( ms_winCaptureNext
)
2102 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2104 wxWindowNext
*item
= ms_winCaptureNext
;
2105 ms_winCaptureNext
= item
->next
;
2108 //else: stack is empty, no previous capture
2110 wxLogTrace(_T("mousecapture"),
2111 _T("After ReleaseMouse() mouse is captured by %p"),
2118 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2119 int WXUNUSED(modifiers
),
2120 int WXUNUSED(keycode
))
2126 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2132 #endif // wxUSE_HOTKEY
2134 void wxWindowBase::SendDestroyEvent()
2136 wxWindowDestroyEvent event
;
2137 event
.SetEventObject(this);
2138 event
.SetId(GetId());
2139 GetEventHandler()->ProcessEvent(event
);
2142 // ----------------------------------------------------------------------------
2144 // ----------------------------------------------------------------------------
2146 bool wxWindowBase::TryValidator(wxEvent
& event
)
2148 #if wxUSE_VALIDATORS
2149 // Can only use the validator of the window which
2150 // is receiving the event
2151 if ( event
.GetEventObject() == this )
2153 wxValidator
*validator
= GetValidator();
2154 if ( validator
&& validator
->ProcessEvent(event
) )
2159 #endif // wxUSE_VALIDATORS
2164 bool wxWindowBase::TryParent(wxEvent
& event
)
2166 // carry on up the parent-child hierarchy if the propgation count hasn't
2168 if ( event
.ShouldPropagate() )
2170 // honour the requests to stop propagation at this window: this is
2171 // used by the dialogs, for example, to prevent processing the events
2172 // from the dialog controls in the parent frame which rarely, if ever,
2174 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2176 wxWindow
*parent
= GetParent();
2177 if ( parent
&& !parent
->IsBeingDeleted() )
2179 wxPropagateOnce
propagateOnce(event
);
2181 return parent
->GetEventHandler()->ProcessEvent(event
);
2186 return wxEvtHandler::TryParent(event
);
2189 // ----------------------------------------------------------------------------
2191 // ----------------------------------------------------------------------------
2193 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2195 while ( win
&& !win
->IsTopLevel() )
2196 win
= win
->GetParent();
2201 #if wxUSE_ACCESSIBILITY
2202 // ----------------------------------------------------------------------------
2203 // accessible object for windows
2204 // ----------------------------------------------------------------------------
2206 // Can return either a child object, or an integer
2207 // representing the child element, starting from 1.
2208 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& pt
, int* childId
, wxAccessible
** childObject
)
2210 wxASSERT( GetWindow() != NULL
);
2214 return wxACC_NOT_IMPLEMENTED
;
2217 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2218 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2220 wxASSERT( GetWindow() != NULL
);
2224 wxWindow
* win
= NULL
;
2231 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2233 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2240 rect
= win
->GetRect();
2241 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2242 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2246 return wxACC_NOT_IMPLEMENTED
;
2249 // Navigates from fromId to toId/toObject.
2250 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2251 int* toId
, wxAccessible
** toObject
)
2253 wxASSERT( GetWindow() != NULL
);
2259 case wxNAVDIR_FIRSTCHILD
:
2261 if (GetWindow()->GetChildren().GetCount() == 0)
2263 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2264 *toObject
= childWindow
->GetOrCreateAccessible();
2268 case wxNAVDIR_LASTCHILD
:
2270 if (GetWindow()->GetChildren().GetCount() == 0)
2272 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2273 *toObject
= childWindow
->GetOrCreateAccessible();
2277 case wxNAVDIR_RIGHT
:
2281 wxWindowList::compatibility_iterator node
=
2282 wxWindowList::compatibility_iterator();
2285 // Can't navigate to sibling of this window
2286 // if we're a top-level window.
2287 if (!GetWindow()->GetParent())
2288 return wxACC_NOT_IMPLEMENTED
;
2290 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2294 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2295 node
= GetWindow()->GetChildren().Item(fromId
-1);
2298 if (node
&& node
->GetNext())
2300 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2301 *toObject
= nextWindow
->GetOrCreateAccessible();
2309 case wxNAVDIR_PREVIOUS
:
2311 wxWindowList::compatibility_iterator node
=
2312 wxWindowList::compatibility_iterator();
2315 // Can't navigate to sibling of this window
2316 // if we're a top-level window.
2317 if (!GetWindow()->GetParent())
2318 return wxACC_NOT_IMPLEMENTED
;
2320 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2324 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2325 node
= GetWindow()->GetChildren().Item(fromId
-1);
2328 if (node
&& node
->GetPrevious())
2330 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2331 *toObject
= previousWindow
->GetOrCreateAccessible();
2339 return wxACC_NOT_IMPLEMENTED
;
2342 // Gets the name of the specified object.
2343 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2345 wxASSERT( GetWindow() != NULL
);
2351 // If a child, leave wxWindows to call the function on the actual
2354 return wxACC_NOT_IMPLEMENTED
;
2356 // This will eventually be replaced by specialised
2357 // accessible classes, one for each kind of wxWindows
2358 // control or window.
2359 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2360 title
= ((wxButton
*) GetWindow())->GetLabel();
2362 title
= GetWindow()->GetName();
2364 if (!title
.IsEmpty())
2370 return wxACC_NOT_IMPLEMENTED
;
2373 // Gets the number of children.
2374 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2376 wxASSERT( GetWindow() != NULL
);
2380 *childId
= (int) GetWindow()->GetChildren().GetCount();
2384 // Gets the specified child (starting from 1).
2385 // If *child is NULL and return value is wxACC_OK,
2386 // this means that the child is a simple element and
2387 // not an accessible object.
2388 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2390 wxASSERT( GetWindow() != NULL
);
2400 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2403 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2404 *child
= childWindow
->GetOrCreateAccessible();
2411 // Gets the parent, or NULL.
2412 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2414 wxASSERT( GetWindow() != NULL
);
2418 wxWindow
* parentWindow
= GetWindow()->GetParent();
2426 *parent
= parentWindow
->GetOrCreateAccessible();
2434 // Performs the default action. childId is 0 (the action for this object)
2435 // or > 0 (the action for a child).
2436 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2437 // window (e.g. an edit control).
2438 wxAccStatus
wxWindowAccessible::DoDefaultAction(int childId
)
2440 wxASSERT( GetWindow() != NULL
);
2444 return wxACC_NOT_IMPLEMENTED
;
2447 // Gets the default action for this object (0) or > 0 (the action for a child).
2448 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2449 // string if there is no action.
2450 // The retrieved string describes the action that is performed on an object,
2451 // not what the object does as a result. For example, a toolbar button that prints
2452 // a document has a default action of "Press" rather than "Prints the current document."
2453 wxAccStatus
wxWindowAccessible::GetDefaultAction(int childId
, wxString
* actionName
)
2455 wxASSERT( GetWindow() != NULL
);
2459 return wxACC_NOT_IMPLEMENTED
;
2462 // Returns the description for this object or a child.
2463 wxAccStatus
wxWindowAccessible::GetDescription(int childId
, wxString
* description
)
2465 wxASSERT( GetWindow() != NULL
);
2469 wxString
ht(GetWindow()->GetHelpText());
2475 return wxACC_NOT_IMPLEMENTED
;
2478 // Returns help text for this object or a child, similar to tooltip text.
2479 wxAccStatus
wxWindowAccessible::GetHelpText(int childId
, wxString
* helpText
)
2481 wxASSERT( GetWindow() != NULL
);
2485 wxString
ht(GetWindow()->GetHelpText());
2491 return wxACC_NOT_IMPLEMENTED
;
2494 // Returns the keyboard shortcut for this object or child.
2495 // Return e.g. ALT+K
2496 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int childId
, wxString
* shortcut
)
2498 wxASSERT( GetWindow() != NULL
);
2502 return wxACC_NOT_IMPLEMENTED
;
2505 // Returns a role constant.
2506 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
2508 wxASSERT( GetWindow() != NULL
);
2512 // If a child, leave wxWindows to call the function on the actual
2515 return wxACC_NOT_IMPLEMENTED
;
2517 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2518 return wxACC_NOT_IMPLEMENTED
;
2520 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2521 return wxACC_NOT_IMPLEMENTED
;
2524 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2525 return wxACC_NOT_IMPLEMENTED
;
2528 //*role = wxROLE_SYSTEM_CLIENT;
2529 *role
= wxROLE_SYSTEM_CLIENT
;
2532 return wxACC_NOT_IMPLEMENTED
;
2535 // Returns a state constant.
2536 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
2538 wxASSERT( GetWindow() != NULL
);
2542 // If a child, leave wxWindows to call the function on the actual
2545 return wxACC_NOT_IMPLEMENTED
;
2547 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2548 return wxACC_NOT_IMPLEMENTED
;
2551 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2552 return wxACC_NOT_IMPLEMENTED
;
2555 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2556 return wxACC_NOT_IMPLEMENTED
;
2562 return wxACC_NOT_IMPLEMENTED
;
2565 // Returns a localized string representing the value for the object
2567 wxAccStatus
wxWindowAccessible::GetValue(int childId
, wxString
* strValue
)
2569 wxASSERT( GetWindow() != NULL
);
2573 return wxACC_NOT_IMPLEMENTED
;
2576 // Selects the object or child.
2577 wxAccStatus
wxWindowAccessible::Select(int childId
, wxAccSelectionFlags selectFlags
)
2579 wxASSERT( GetWindow() != NULL
);
2583 return wxACC_NOT_IMPLEMENTED
;
2586 // Gets the window with the keyboard focus.
2587 // If childId is 0 and child is NULL, no object in
2588 // this subhierarchy has the focus.
2589 // If this object has the focus, child should be 'this'.
2590 wxAccStatus
wxWindowAccessible::GetFocus(int* childId
, wxAccessible
** child
)
2592 wxASSERT( GetWindow() != NULL
);
2596 return wxACC_NOT_IMPLEMENTED
;
2599 // Gets a variant representing the selected children
2601 // Acceptable values:
2602 // - a null variant (IsNull() returns TRUE)
2603 // - a list variant (GetType() == wxT("list")
2604 // - an integer representing the selected child element,
2605 // or 0 if this object is selected (GetType() == wxT("long")
2606 // - a "void*" pointer to a wxAccessible child object
2607 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* selections
)
2609 wxASSERT( GetWindow() != NULL
);
2613 return wxACC_NOT_IMPLEMENTED
;
2616 #endif // wxUSE_ACCESSIBILITY