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
& wxVALIDATOR_PARAM(validator
),
206 const wxString
& name
)
209 // wxGTK doesn't allow to create controls with static box as the parent so
210 // this will result in a crash when the program is ported to wxGTK so warn
213 // if you get this assert, the correct solution is to create the controls
214 // as siblings of the static box
215 wxASSERT_MSG( !parent
|| !wxDynamicCast(parent
, wxStaticBox
),
216 _T("wxStaticBox can't be used as a window parent!") );
217 #endif // wxUSE_STATBOX
219 // ids are limited to 16 bits under MSW so if you care about portability,
220 // it's not a good idea to use ids out of this range (and negative ids are
221 // reserved for wxWindows own usage)
222 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767),
223 _T("invalid id value") );
225 // generate a new id if the user doesn't care about it
226 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
229 SetWindowStyleFlag(style
);
233 SetValidator(validator
);
234 #endif // wxUSE_VALIDATORS
236 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
237 // have it too - like this it's possible to set it only in the top level
238 // dialog/frame and all children will inherit it by defult
239 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
241 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
247 // ----------------------------------------------------------------------------
249 // ----------------------------------------------------------------------------
252 wxWindowBase::~wxWindowBase()
254 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
256 // FIXME if these 2 cases result from programming errors in the user code
257 // we should probably assert here instead of silently fixing them
259 // Just in case the window has been Closed, but we're then deleting
260 // immediately: don't leave dangling pointers.
261 wxPendingDelete
.DeleteObject(this);
263 // Just in case we've loaded a top-level window via LoadNativeDialog but
264 // we weren't a dialog class
265 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
267 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
269 // reset the dangling pointer our parent window may keep to us
272 if ( m_parent
->GetDefaultItem() == this )
274 m_parent
->SetDefaultItem(NULL
);
277 m_parent
->RemoveChild(this);
282 #endif // wxUSE_CARET
285 delete m_windowValidator
;
286 #endif // wxUSE_VALIDATORS
288 #if wxUSE_CONSTRAINTS
289 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
290 // at deleted windows as they delete themselves.
291 DeleteRelatedConstraints();
295 // This removes any dangling pointers to this window in other windows'
296 // constraintsInvolvedIn lists.
297 UnsetConstraints(m_constraints
);
298 delete m_constraints
;
299 m_constraints
= NULL
;
301 #endif // wxUSE_CONSTRAINTS
303 if ( m_containingSizer
)
304 m_containingSizer
->Detach( (wxWindow
*)this );
306 delete m_windowSizer
;
308 #if wxUSE_DRAG_AND_DROP
310 #endif // wxUSE_DRAG_AND_DROP
314 #endif // wxUSE_TOOLTIPS
316 #if wxUSE_ACCESSIBILITY
321 bool wxWindowBase::Destroy()
328 bool wxWindowBase::Close(bool force
)
330 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
331 event
.SetEventObject(this);
332 event
.SetCanVeto(!force
);
334 // return FALSE if window wasn't closed because the application vetoed the
336 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
339 bool wxWindowBase::DestroyChildren()
341 wxWindowList::compatibility_iterator node
;
344 // we iterate until the list becomes empty
345 node
= GetChildren().GetFirst();
349 wxWindow
*child
= node
->GetData();
353 wxASSERT_MSG( !GetChildren().Find(child
),
354 wxT("child didn't remove itself using RemoveChild()") );
360 // ----------------------------------------------------------------------------
361 // size/position related methods
362 // ----------------------------------------------------------------------------
364 // centre the window with respect to its parent in either (or both) directions
365 void wxWindowBase::Centre(int direction
)
367 // the position/size of the parent window or of the entire screen
369 int widthParent
, heightParent
;
371 wxWindow
*parent
= NULL
;
373 if ( !(direction
& wxCENTRE_ON_SCREEN
) )
375 // find the parent to centre this window on: it should be the
376 // immediate parent for the controls but the top level parent for the
377 // top level windows (like dialogs)
378 parent
= GetParent();
381 while ( parent
&& !parent
->IsTopLevel() )
383 parent
= parent
->GetParent();
387 // there is no wxTopLevelWindow under wxMotif yet
389 // we shouldn't center the dialog on the iconized window: under
390 // Windows, for example, this places it completely off the screen
393 wxTopLevelWindow
*winTop
= wxDynamicCast(parent
, wxTopLevelWindow
);
394 if ( winTop
&& winTop
->IsIconized() )
399 #endif // __WXMOTIF__
401 // did we find the parent?
405 direction
|= wxCENTRE_ON_SCREEN
;
409 if ( direction
& wxCENTRE_ON_SCREEN
)
411 // centre with respect to the whole screen
412 wxDisplaySize(&widthParent
, &heightParent
);
418 // centre on the parent
419 parent
->GetSize(&widthParent
, &heightParent
);
421 // adjust to the parents position
422 posParent
= parent
->GetPosition();
426 // centre inside the parents client rectangle
427 parent
->GetClientSize(&widthParent
, &heightParent
);
432 GetSize(&width
, &height
);
437 if ( direction
& wxHORIZONTAL
)
438 xNew
= (widthParent
- width
)/2;
440 if ( direction
& wxVERTICAL
)
441 yNew
= (heightParent
- height
)/2;
446 // Base size of the visible dimensions of the display
447 // to take into account the taskbar
448 wxRect rect
= wxGetClientDisplayRect();
449 wxSize
size (rect
.width
,rect
.height
);
451 // NB: in wxMSW, negative position may not neccessary mean "out of screen",
452 // but it may mean that the window is placed on other than the main
453 // display. Therefore we only make sure centered window is on the main display
454 // if the parent is at least partially present here.
455 if (posParent
.x
+ widthParent
>= 0) // if parent is (partially) on the main display
459 else if (xNew
+width
> size
.x
)
460 xNew
= size
.x
-width
-1;
462 if (posParent
.y
+ heightParent
>= 0) // if parent is (partially) on the main display
464 if (yNew
+height
> size
.y
)
465 yNew
= size
.y
-height
-1;
467 // Make certain that the title bar is initially visible
468 // always, even if this would push the bottom of the
469 // dialog of the visible area of the display
474 // move the window to this position (keeping the old size but using
475 // SetSize() and not Move() to allow xNew and/or yNew to be -1)
476 SetSize(xNew
, yNew
, width
, height
, wxSIZE_ALLOW_MINUS_ONE
);
479 // fits the window around the children
480 void wxWindowBase::Fit()
482 if ( GetChildren().GetCount() > 0 )
484 SetClientSize(DoGetBestSize());
486 //else: do nothing if we have no children
489 // fits virtual size (ie. scrolled area etc.) around children
490 void wxWindowBase::FitInside()
492 if ( GetChildren().GetCount() > 0 )
494 SetVirtualSize( GetBestVirtualSize() );
498 // return the size best suited for the current window
499 wxSize
wxWindowBase::DoGetBestSize() const
503 return m_windowSizer
->GetMinSize();
505 #if wxUSE_CONSTRAINTS
506 else if ( m_constraints
)
508 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
510 // our minimal acceptable size is such that all our windows fit inside
514 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
516 node
= node
->GetNext() )
518 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
521 // it's not normal that we have an unconstrained child, but
522 // what can we do about it?
526 int x
= c
->right
.GetValue(),
527 y
= c
->bottom
.GetValue();
535 // TODO: we must calculate the overlaps somehow, otherwise we
536 // will never return a size bigger than the current one :-(
539 return wxSize(maxX
, maxY
);
541 #endif // wxUSE_CONSTRAINTS
542 else if ( GetChildren().GetCount() > 0 )
544 // our minimal acceptable size is such that all our windows fit inside
548 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
550 node
= node
->GetNext() )
552 wxWindow
*win
= node
->GetData();
553 if ( win
->IsTopLevel()
555 || wxDynamicCast(win
, wxStatusBar
)
556 #endif // wxUSE_STATUSBAR
559 // dialogs and frames lie in different top level windows -
560 // don't deal with them here; as for the status bars, they
561 // don't lie in the client area at all
566 win
->GetPosition(&wx
, &wy
);
568 // if the window hadn't been positioned yet, assume that it is in
575 win
->GetSize(&ww
, &wh
);
576 if ( wx
+ ww
> maxX
)
578 if ( wy
+ wh
> maxY
)
582 // for compatibility with the old versions and because it really looks
583 // slightly more pretty like this, add a pad
587 return wxSize(maxX
, maxY
);
591 // for a generic window there is no natural best size - just use the
597 // by default the origin is not shifted
598 wxPoint
wxWindowBase::GetClientAreaOrigin() const
600 return wxPoint(0, 0);
603 // set the min/max size of the window
604 void wxWindowBase::SetSizeHints(int minW
, int minH
,
606 int WXUNUSED(incW
), int WXUNUSED(incH
))
608 // setting min width greater than max width leads to infinite loops under
609 // X11 and generally doesn't make any sense, so don't allow it
610 wxCHECK_RET( (minW
== -1 || maxW
== -1 || minW
<= maxW
) &&
611 (minH
== -1 || maxH
== -1 || minH
<= maxH
),
612 _T("min width/height must be less than max width/height!") );
620 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
623 m_minVirtualWidth
= minW
;
624 m_maxVirtualWidth
= maxW
;
625 m_minVirtualHeight
= minH
;
626 m_maxVirtualHeight
= maxH
;
629 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
631 if ( m_minVirtualWidth
!= -1 && m_minVirtualWidth
> x
)
632 x
= m_minVirtualWidth
;
633 if ( m_maxVirtualWidth
!= -1 && m_maxVirtualWidth
< x
)
634 x
= m_maxVirtualWidth
;
635 if ( m_minVirtualHeight
!= -1 && m_minVirtualHeight
> y
)
636 y
= m_minVirtualHeight
;
637 if ( m_maxVirtualHeight
!= -1 && m_maxVirtualHeight
< y
)
638 y
= m_maxVirtualHeight
;
640 m_virtualSize
= wxSize(x
, y
);
643 wxSize
wxWindowBase::DoGetVirtualSize() const
645 wxSize
s( GetClientSize() );
647 return wxSize( wxMax( m_virtualSize
.GetWidth(), s
.GetWidth() ),
648 wxMax( m_virtualSize
.GetHeight(), s
.GetHeight() ) );
651 // ----------------------------------------------------------------------------
652 // show/hide/enable/disable the window
653 // ----------------------------------------------------------------------------
655 bool wxWindowBase::Show(bool show
)
657 if ( show
!= m_isShown
)
669 bool wxWindowBase::Enable(bool enable
)
671 if ( enable
!= m_isEnabled
)
673 m_isEnabled
= enable
;
682 // ----------------------------------------------------------------------------
684 // ----------------------------------------------------------------------------
686 bool wxWindowBase::IsTopLevel() const
691 // ----------------------------------------------------------------------------
692 // reparenting the window
693 // ----------------------------------------------------------------------------
695 void wxWindowBase::AddChild(wxWindowBase
*child
)
697 wxCHECK_RET( child
, wxT("can't add a NULL child") );
699 // this should never happen and it will lead to a crash later if it does
700 // because RemoveChild() will remove only one node from the children list
701 // and the other(s) one(s) will be left with dangling pointers in them
702 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
704 GetChildren().Append((wxWindow
*)child
);
705 child
->SetParent(this);
708 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
710 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
712 GetChildren().DeleteObject((wxWindow
*)child
);
713 child
->SetParent(NULL
);
716 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
718 wxWindow
*oldParent
= GetParent();
719 if ( newParent
== oldParent
)
725 // unlink this window from the existing parent.
728 oldParent
->RemoveChild(this);
732 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
735 // add it to the new one
738 newParent
->AddChild(this);
742 wxTopLevelWindows
.Append((wxWindow
*)this);
748 // ----------------------------------------------------------------------------
749 // event handler stuff
750 // ----------------------------------------------------------------------------
752 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
754 wxEvtHandler
*handlerOld
= GetEventHandler();
756 handler
->SetNextHandler(handlerOld
);
759 GetEventHandler()->SetPreviousHandler(handler
);
761 SetEventHandler(handler
);
764 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
766 wxEvtHandler
*handlerA
= GetEventHandler();
769 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
770 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
773 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
774 SetEventHandler(handlerB
);
779 handlerA
= (wxEvtHandler
*)NULL
;
786 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
788 wxCHECK_MSG( handler
, FALSE
, _T("RemoveEventHandler(NULL) called") );
790 wxEvtHandler
*handlerPrev
= NULL
,
791 *handlerCur
= GetEventHandler();
794 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
796 if ( handlerCur
== handler
)
800 handlerPrev
->SetNextHandler(handlerNext
);
804 SetEventHandler(handlerNext
);
809 handlerNext
->SetPreviousHandler ( handlerPrev
);
811 handler
->SetNextHandler(NULL
);
816 handlerPrev
= handlerCur
;
817 handlerCur
= handlerNext
;
820 wxFAIL_MSG( _T("where has the event handler gone?") );
825 // ----------------------------------------------------------------------------
827 // ----------------------------------------------------------------------------
829 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
831 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
834 m_backgroundColour
= colour
;
841 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
843 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
846 m_foregroundColour
= colour
;
853 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
855 // setting an invalid cursor is ok, it means that we don't have any special
857 if ( m_cursor
== cursor
)
868 bool wxWindowBase::SetFont(const wxFont
& font
)
870 // don't try to set invalid font, always fall back to the default
871 const wxFont
& fontOk
= font
.Ok() ? font
: *wxSWISS_FONT
;
873 if ( fontOk
== m_font
)
888 void wxWindowBase::SetPalette(const wxPalette
& pal
)
890 m_hasCustomPalette
= TRUE
;
893 // VZ: can anyone explain me what do we do here?
894 wxWindowDC
d((wxWindow
*) this);
898 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
900 wxWindow
*win
= (wxWindow
*)this;
901 while ( win
&& !win
->HasCustomPalette() )
903 win
= win
->GetParent();
909 #endif // wxUSE_PALETTE
912 void wxWindowBase::SetCaret(wxCaret
*caret
)
923 wxASSERT_MSG( m_caret
->GetWindow() == this,
924 wxT("caret should be created associated to this window") );
927 #endif // wxUSE_CARET
930 // ----------------------------------------------------------------------------
932 // ----------------------------------------------------------------------------
934 void wxWindowBase::SetValidator(const wxValidator
& validator
)
936 if ( m_windowValidator
)
937 delete m_windowValidator
;
939 m_windowValidator
= (wxValidator
*)validator
.Clone();
941 if ( m_windowValidator
)
942 m_windowValidator
->SetWindow(this) ;
944 #endif // wxUSE_VALIDATORS
946 // ----------------------------------------------------------------------------
947 // update region stuff
948 // ----------------------------------------------------------------------------
950 wxRect
wxWindowBase::GetUpdateClientRect() const
952 wxRegion rgnUpdate
= GetUpdateRegion();
953 rgnUpdate
.Intersect(GetClientRect());
954 wxRect rectUpdate
= rgnUpdate
.GetBox();
955 wxPoint ptOrigin
= GetClientAreaOrigin();
956 rectUpdate
.x
-= ptOrigin
.x
;
957 rectUpdate
.y
-= ptOrigin
.y
;
962 bool wxWindowBase::IsExposed(int x
, int y
) const
964 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
967 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
969 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
972 void wxWindowBase::ClearBackground()
974 // wxGTK uses its own version, no need to add never used code
976 wxClientDC
dc((wxWindow
*)this);
977 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
978 dc
.SetBackground(brush
);
983 // ----------------------------------------------------------------------------
984 // find child window by id or name
985 // ----------------------------------------------------------------------------
987 wxWindow
*wxWindowBase::FindWindow( long id
)
989 if ( id
== m_windowId
)
990 return (wxWindow
*)this;
992 wxWindowBase
*res
= (wxWindow
*)NULL
;
993 wxWindowList::compatibility_iterator node
;
994 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
996 wxWindowBase
*child
= node
->GetData();
997 res
= child
->FindWindow( id
);
1000 return (wxWindow
*)res
;
1003 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
1005 if ( name
== m_windowName
)
1006 return (wxWindow
*)this;
1008 wxWindowBase
*res
= (wxWindow
*)NULL
;
1009 wxWindowList::compatibility_iterator node
;
1010 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1012 wxWindow
*child
= node
->GetData();
1013 res
= child
->FindWindow(name
);
1016 return (wxWindow
*)res
;
1020 // find any window by id or name or label: If parent is non-NULL, look through
1021 // children for a label or title matching the specified string. If NULL, look
1022 // through all top-level windows.
1024 // to avoid duplicating code we reuse the same helper function but with
1025 // different comparators
1027 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1028 const wxString
& label
, long id
);
1031 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1034 return win
->GetLabel() == label
;
1038 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1041 return win
->GetName() == label
;
1045 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1048 return win
->GetId() == id
;
1051 // recursive helper for the FindWindowByXXX() functions
1053 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1054 const wxString
& label
,
1056 wxFindWindowCmp cmp
)
1060 // see if this is the one we're looking for
1061 if ( (*cmp
)(parent
, label
, id
) )
1062 return (wxWindow
*)parent
;
1064 // It wasn't, so check all its children
1065 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1067 node
= node
->GetNext() )
1069 // recursively check each child
1070 wxWindow
*win
= (wxWindow
*)node
->GetData();
1071 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1081 // helper for FindWindowByXXX()
1083 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1084 const wxString
& label
,
1086 wxFindWindowCmp cmp
)
1090 // just check parent and all its children
1091 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1094 // start at very top of wx's windows
1095 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1097 node
= node
->GetNext() )
1099 // recursively check each window & its children
1100 wxWindow
*win
= node
->GetData();
1101 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1111 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1113 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1118 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1120 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1124 // fall back to the label
1125 win
= FindWindowByLabel(title
, parent
);
1133 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1135 return wxFindWindowHelper(parent
, _T(""), id
, wxFindWindowCmpIds
);
1138 // ----------------------------------------------------------------------------
1139 // dialog oriented functions
1140 // ----------------------------------------------------------------------------
1142 void wxWindowBase::MakeModal(bool modal
)
1144 // Disable all other windows
1147 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1150 wxWindow
*win
= node
->GetData();
1152 win
->Enable(!modal
);
1154 node
= node
->GetNext();
1159 bool wxWindowBase::Validate()
1161 #if wxUSE_VALIDATORS
1162 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1164 wxWindowList::compatibility_iterator node
;
1165 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1167 wxWindowBase
*child
= node
->GetData();
1168 wxValidator
*validator
= child
->GetValidator();
1169 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1174 if ( recurse
&& !child
->Validate() )
1179 #endif // wxUSE_VALIDATORS
1184 bool wxWindowBase::TransferDataToWindow()
1186 #if wxUSE_VALIDATORS
1187 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1189 wxWindowList::compatibility_iterator node
;
1190 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1192 wxWindowBase
*child
= node
->GetData();
1193 wxValidator
*validator
= child
->GetValidator();
1194 if ( validator
&& !validator
->TransferToWindow() )
1196 wxLogWarning(_("Could not transfer data to window"));
1198 wxLog::FlushActive();
1206 if ( !child
->TransferDataToWindow() )
1208 // warning already given
1213 #endif // wxUSE_VALIDATORS
1218 bool wxWindowBase::TransferDataFromWindow()
1220 #if wxUSE_VALIDATORS
1221 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1223 wxWindowList::compatibility_iterator node
;
1224 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1226 wxWindow
*child
= node
->GetData();
1227 wxValidator
*validator
= child
->GetValidator();
1228 if ( validator
&& !validator
->TransferFromWindow() )
1230 // nop warning here because the application is supposed to give
1231 // one itself - we don't know here what might have gone wrongly
1238 if ( !child
->TransferDataFromWindow() )
1240 // warning already given
1245 #endif // wxUSE_VALIDATORS
1250 void wxWindowBase::InitDialog()
1252 wxInitDialogEvent
event(GetId());
1253 event
.SetEventObject( this );
1254 GetEventHandler()->ProcessEvent(event
);
1257 // ----------------------------------------------------------------------------
1258 // context-sensitive help support
1259 // ----------------------------------------------------------------------------
1263 // associate this help text with this window
1264 void wxWindowBase::SetHelpText(const wxString
& text
)
1266 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1269 helpProvider
->AddHelp(this, text
);
1273 // associate this help text with all windows with the same id as this
1275 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1277 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1280 helpProvider
->AddHelp(GetId(), text
);
1284 // get the help string associated with this window (may be empty)
1285 wxString
wxWindowBase::GetHelpText() const
1288 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1291 text
= helpProvider
->GetHelp(this);
1297 // show help for this window
1298 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1300 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1303 if ( helpProvider
->ShowHelp(this) )
1305 // skip the event.Skip() below
1313 #endif // wxUSE_HELP
1315 // ----------------------------------------------------------------------------
1316 // tooltipsroot.Replace("\\", "/");
1317 // ----------------------------------------------------------------------------
1321 void wxWindowBase::SetToolTip( const wxString
&tip
)
1323 // don't create the new tooltip if we already have one
1326 m_tooltip
->SetTip( tip
);
1330 SetToolTip( new wxToolTip( tip
) );
1333 // setting empty tooltip text does not remove the tooltip any more - use
1334 // SetToolTip((wxToolTip *)NULL) for this
1337 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1342 m_tooltip
= tooltip
;
1345 #endif // wxUSE_TOOLTIPS
1347 // ----------------------------------------------------------------------------
1348 // constraints and sizers
1349 // ----------------------------------------------------------------------------
1351 #if wxUSE_CONSTRAINTS
1353 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1355 if ( m_constraints
)
1357 UnsetConstraints(m_constraints
);
1358 delete m_constraints
;
1360 m_constraints
= constraints
;
1361 if ( m_constraints
)
1363 // Make sure other windows know they're part of a 'meaningful relationship'
1364 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1365 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1366 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1367 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1368 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1369 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1370 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1371 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1372 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1373 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1374 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1375 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1376 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1377 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1378 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1379 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1383 // This removes any dangling pointers to this window in other windows'
1384 // constraintsInvolvedIn lists.
1385 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1389 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1390 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1391 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1392 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1393 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1394 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1395 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1396 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1397 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1398 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1399 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1400 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1401 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1402 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1403 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1404 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1408 // Back-pointer to other windows we're involved with, so if we delete this
1409 // window, we must delete any constraints we're involved with.
1410 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1412 if ( !m_constraintsInvolvedIn
)
1413 m_constraintsInvolvedIn
= new wxWindowList
;
1414 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1415 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1418 // REMOVE back-pointer to other windows we're involved with.
1419 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1421 if ( m_constraintsInvolvedIn
)
1422 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1425 // Reset any constraints that mention this window
1426 void wxWindowBase::DeleteRelatedConstraints()
1428 if ( m_constraintsInvolvedIn
)
1430 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1433 wxWindow
*win
= node
->GetData();
1434 wxLayoutConstraints
*constr
= win
->GetConstraints();
1436 // Reset any constraints involving this window
1439 constr
->left
.ResetIfWin(this);
1440 constr
->top
.ResetIfWin(this);
1441 constr
->right
.ResetIfWin(this);
1442 constr
->bottom
.ResetIfWin(this);
1443 constr
->width
.ResetIfWin(this);
1444 constr
->height
.ResetIfWin(this);
1445 constr
->centreX
.ResetIfWin(this);
1446 constr
->centreY
.ResetIfWin(this);
1449 wxWindowList::compatibility_iterator next
= node
->GetNext();
1450 m_constraintsInvolvedIn
->Erase(node
);
1454 delete m_constraintsInvolvedIn
;
1455 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1459 #endif // wxUSE_CONSTRAINTS
1461 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1464 delete m_windowSizer
;
1466 m_windowSizer
= sizer
;
1468 SetAutoLayout( sizer
!= NULL
);
1471 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1473 SetSizer( sizer
, deleteOld
);
1474 sizer
->SetSizeHints( (wxWindow
*) this );
1477 #if wxUSE_CONSTRAINTS
1479 void wxWindowBase::SatisfyConstraints()
1481 wxLayoutConstraints
*constr
= GetConstraints();
1482 bool wasOk
= constr
&& constr
->AreSatisfied();
1484 ResetConstraints(); // Mark all constraints as unevaluated
1488 // if we're a top level panel (i.e. our parent is frame/dialog), our
1489 // own constraints will never be satisfied any more unless we do it
1493 while ( noChanges
> 0 )
1495 LayoutPhase1(&noChanges
);
1499 LayoutPhase2(&noChanges
);
1502 #endif // wxUSE_CONSTRAINTS
1504 bool wxWindowBase::Layout()
1506 // If there is a sizer, use it instead of the constraints
1510 GetVirtualSize(&w
, &h
);
1511 GetSizer()->SetDimension( 0, 0, w
, h
);
1513 #if wxUSE_CONSTRAINTS
1516 SatisfyConstraints(); // Find the right constraints values
1517 SetConstraintSizes(); // Recursively set the real window sizes
1524 #if wxUSE_CONSTRAINTS
1526 // first phase of the constraints evaluation: set our own constraints
1527 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1529 wxLayoutConstraints
*constr
= GetConstraints();
1531 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1534 // second phase: set the constraints for our children
1535 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1542 // Layout grand children
1548 // Do a phase of evaluating child constraints
1549 bool wxWindowBase::DoPhase(int phase
)
1551 // the list containing the children for which the constraints are already
1553 wxWindowList succeeded
;
1555 // the max number of iterations we loop before concluding that we can't set
1557 static const int maxIterations
= 500;
1559 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1563 // loop over all children setting their constraints
1564 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1566 node
= node
->GetNext() )
1568 wxWindow
*child
= node
->GetData();
1569 if ( child
->IsTopLevel() )
1571 // top level children are not inside our client area
1575 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1577 // this one is either already ok or nothing we can do about it
1581 int tempNoChanges
= 0;
1582 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1583 : child
->LayoutPhase2(&tempNoChanges
);
1584 noChanges
+= tempNoChanges
;
1588 succeeded
.Append(child
);
1594 // constraints are set
1602 void wxWindowBase::ResetConstraints()
1604 wxLayoutConstraints
*constr
= GetConstraints();
1607 constr
->left
.SetDone(FALSE
);
1608 constr
->top
.SetDone(FALSE
);
1609 constr
->right
.SetDone(FALSE
);
1610 constr
->bottom
.SetDone(FALSE
);
1611 constr
->width
.SetDone(FALSE
);
1612 constr
->height
.SetDone(FALSE
);
1613 constr
->centreX
.SetDone(FALSE
);
1614 constr
->centreY
.SetDone(FALSE
);
1617 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1620 wxWindow
*win
= node
->GetData();
1621 if ( !win
->IsTopLevel() )
1622 win
->ResetConstraints();
1623 node
= node
->GetNext();
1627 // Need to distinguish between setting the 'fake' size for windows and sizers,
1628 // and setting the real values.
1629 void wxWindowBase::SetConstraintSizes(bool recurse
)
1631 wxLayoutConstraints
*constr
= GetConstraints();
1632 if ( constr
&& constr
->AreSatisfied() )
1634 int x
= constr
->left
.GetValue();
1635 int y
= constr
->top
.GetValue();
1636 int w
= constr
->width
.GetValue();
1637 int h
= constr
->height
.GetValue();
1639 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1640 (constr
->height
.GetRelationship() != wxAsIs
) )
1642 SetSize(x
, y
, w
, h
);
1646 // If we don't want to resize this window, just move it...
1652 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1653 GetClassInfo()->GetClassName(),
1659 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1662 wxWindow
*win
= node
->GetData();
1663 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1664 win
->SetConstraintSizes();
1665 node
= node
->GetNext();
1670 // Only set the size/position of the constraint (if any)
1671 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1673 wxLayoutConstraints
*constr
= GetConstraints();
1678 constr
->left
.SetValue(x
);
1679 constr
->left
.SetDone(TRUE
);
1683 constr
->top
.SetValue(y
);
1684 constr
->top
.SetDone(TRUE
);
1688 constr
->width
.SetValue(w
);
1689 constr
->width
.SetDone(TRUE
);
1693 constr
->height
.SetValue(h
);
1694 constr
->height
.SetDone(TRUE
);
1699 void wxWindowBase::MoveConstraint(int x
, int y
)
1701 wxLayoutConstraints
*constr
= GetConstraints();
1706 constr
->left
.SetValue(x
);
1707 constr
->left
.SetDone(TRUE
);
1711 constr
->top
.SetValue(y
);
1712 constr
->top
.SetDone(TRUE
);
1717 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1719 wxLayoutConstraints
*constr
= GetConstraints();
1722 *w
= constr
->width
.GetValue();
1723 *h
= constr
->height
.GetValue();
1729 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1731 wxLayoutConstraints
*constr
= GetConstraints();
1734 *w
= constr
->width
.GetValue();
1735 *h
= constr
->height
.GetValue();
1738 GetClientSize(w
, h
);
1741 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1743 wxLayoutConstraints
*constr
= GetConstraints();
1746 *x
= constr
->left
.GetValue();
1747 *y
= constr
->top
.GetValue();
1753 #endif // wxUSE_CONSTRAINTS
1755 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
1757 // don't do it for the dialogs/frames - they float independently of their
1759 if ( !IsTopLevel() )
1761 wxWindow
*parent
= GetParent();
1762 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
1764 wxPoint
pt(parent
->GetClientAreaOrigin());
1771 // ----------------------------------------------------------------------------
1772 // do Update UI processing for child controls
1773 // ----------------------------------------------------------------------------
1775 void wxWindowBase::UpdateWindowUI(long flags
)
1777 wxUpdateUIEvent
event(GetId());
1778 event
.m_eventObject
= this;
1780 if ( GetEventHandler()->ProcessEvent(event
) )
1782 DoUpdateWindowUI(event
);
1785 if (flags
& wxUPDATE_UI_RECURSE
)
1787 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1790 wxWindow
* child
= (wxWindow
*) node
->GetData();
1791 child
->UpdateWindowUI(flags
);
1792 node
= node
->GetNext();
1797 // do the window-specific processing after processing the update event
1798 // TODO: take specific knowledge out of this function and
1799 // put in each control's base class. Unfortunately we don't
1800 // yet have base implementation files for wxCheckBox and wxRadioButton.
1801 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
1803 if ( event
.GetSetEnabled() )
1804 Enable(event
.GetEnabled());
1807 if ( event
.GetSetText() )
1809 wxControl
*control
= wxDynamicCastThis(wxControl
);
1812 if ( event
.GetText() != control
->GetLabel() )
1813 control
->SetLabel(event
.GetText());
1816 wxCheckBox
*checkbox
= wxDynamicCastThis(wxCheckBox
);
1819 if ( event
.GetSetChecked() )
1820 checkbox
->SetValue(event
.GetChecked());
1822 #endif // wxUSE_CHECKBOX
1825 wxRadioButton
*radiobtn
= wxDynamicCastThis(wxRadioButton
);
1828 if ( event
.GetSetChecked() )
1829 radiobtn
->SetValue(event
.GetChecked());
1831 #endif // wxUSE_RADIOBTN
1837 // call internal idle recursively
1838 // may be obsolete (wait until OnIdle scheme stabilises)
1839 void wxWindowBase::ProcessInternalIdle()
1843 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1846 wxWindow
*child
= node
->GetData();
1847 child
->ProcessInternalIdle();
1848 node
= node
->GetNext();
1853 // ----------------------------------------------------------------------------
1854 // dialog units translations
1855 // ----------------------------------------------------------------------------
1857 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1859 int charWidth
= GetCharWidth();
1860 int charHeight
= GetCharHeight();
1861 wxPoint
pt2(-1, -1);
1863 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1865 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1870 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1872 int charWidth
= GetCharWidth();
1873 int charHeight
= GetCharHeight();
1874 wxPoint
pt2(-1, -1);
1876 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1878 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1883 // ----------------------------------------------------------------------------
1885 // ----------------------------------------------------------------------------
1887 // propagate the colour change event to the subwindows
1888 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1890 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1893 // Only propagate to non-top-level windows
1894 wxWindow
*win
= node
->GetData();
1895 if ( !win
->IsTopLevel() )
1897 wxSysColourChangedEvent event2
;
1898 event
.m_eventObject
= win
;
1899 win
->GetEventHandler()->ProcessEvent(event2
);
1902 node
= node
->GetNext();
1906 // the default action is to populate dialog with data when it's created,
1907 // and nudge the UI into displaying itself correctly in case
1908 // we've turned the wxUpdateUIEvents frequency down low.
1909 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1911 TransferDataToWindow();
1913 // Update the UI at this point
1914 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
1917 // process Ctrl-Alt-mclick
1918 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
1921 if ( event
.ControlDown() && event
.AltDown() )
1923 // don't translate these strings
1926 #ifdef __WXUNIVERSAL__
1928 #endif // __WXUNIVERSAL__
1930 switch ( wxGetOsVersion() )
1932 case wxMOTIF_X
: port
+= _T("Motif"); break;
1934 case wxMAC_DARWIN
: port
+= _T("Mac"); break;
1935 case wxBEOS
: port
+= _T("BeOS"); break;
1939 case wxGTK_BEOS
: port
+= _T("GTK"); break;
1945 case wxWIN386
: port
+= _T("MS Windows"); break;
1949 case wxMGL_OS2
: port
+= _T("MGL"); break;
1951 case wxOS2_PM
: port
+= _T("OS/2"); break;
1952 default: port
+= _T("unknown"); break;
1955 wxMessageBox(wxString::Format(
1957 " wxWindows Library (%s port)\nVersion %u.%u.%u%s, compiled at %s %s\n Copyright (c) 1995-2002 wxWindows team"
1971 _T("wxWindows information"),
1972 wxICON_INFORMATION
| wxOK
,
1976 #endif // wxUSE_MSGDLG
1982 // ----------------------------------------------------------------------------
1984 // ----------------------------------------------------------------------------
1986 #if wxUSE_ACCESSIBILITY
1987 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
1989 if (m_accessible
&& (accessible
!= m_accessible
))
1990 delete m_accessible
;
1991 m_accessible
= accessible
;
1993 m_accessible
->SetWindow((wxWindow
*) this);
1996 // Returns the accessible object, creating if necessary.
1997 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2000 m_accessible
= CreateAccessible();
2001 return m_accessible
;
2004 // Override to create a specific accessible object.
2005 wxAccessible
* wxWindowBase::CreateAccessible()
2007 return new wxWindowAccessible((wxWindow
*) this);
2013 // ----------------------------------------------------------------------------
2014 // list classes implementation
2015 // ----------------------------------------------------------------------------
2017 void wxWindowListNode::DeleteData()
2019 delete (wxWindow
*)GetData();
2023 // ----------------------------------------------------------------------------
2025 // ----------------------------------------------------------------------------
2027 wxBorder
wxWindowBase::GetBorder(long flags
) const
2029 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2030 if ( border
== wxBORDER_DEFAULT
)
2032 border
= GetDefaultBorder();
2038 wxBorder
wxWindowBase::GetDefaultBorder() const
2040 return wxBORDER_NONE
;
2043 // ----------------------------------------------------------------------------
2045 // ----------------------------------------------------------------------------
2047 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2049 // here we just check if the point is inside the window or not
2051 // check the top and left border first
2052 bool outside
= x
< 0 || y
< 0;
2055 // check the right and bottom borders too
2056 wxSize size
= GetSize();
2057 outside
= x
>= size
.x
|| y
>= size
.y
;
2060 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2063 // ----------------------------------------------------------------------------
2065 // ----------------------------------------------------------------------------
2067 struct WXDLLEXPORT wxWindowNext
2071 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2073 void wxWindowBase::CaptureMouse()
2075 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this);
2077 wxWindow
*winOld
= GetCapture();
2080 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2083 wxWindowNext
*item
= new wxWindowNext
;
2085 item
->next
= ms_winCaptureNext
;
2086 ms_winCaptureNext
= item
;
2088 //else: no mouse capture to save
2093 void wxWindowBase::ReleaseMouse()
2095 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this);
2097 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2101 if ( ms_winCaptureNext
)
2103 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2105 wxWindowNext
*item
= ms_winCaptureNext
;
2106 ms_winCaptureNext
= item
->next
;
2109 //else: stack is empty, no previous capture
2111 wxLogTrace(_T("mousecapture"),
2112 _T("After ReleaseMouse() mouse is captured by %p"),
2119 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2120 int WXUNUSED(modifiers
),
2121 int WXUNUSED(keycode
))
2127 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2133 #endif // wxUSE_HOTKEY
2135 void wxWindowBase::SendDestroyEvent()
2137 wxWindowDestroyEvent event
;
2138 event
.SetEventObject(this);
2139 event
.SetId(GetId());
2140 GetEventHandler()->ProcessEvent(event
);
2143 // ----------------------------------------------------------------------------
2145 // ----------------------------------------------------------------------------
2147 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2149 #if wxUSE_VALIDATORS
2150 // Can only use the validator of the window which
2151 // is receiving the event
2152 if ( event
.GetEventObject() == this )
2154 wxValidator
*validator
= GetValidator();
2155 if ( validator
&& validator
->ProcessEvent(event
) )
2160 #endif // wxUSE_VALIDATORS
2165 bool wxWindowBase::TryParent(wxEvent
& event
)
2167 // carry on up the parent-child hierarchy if the propgation count hasn't
2169 if ( event
.ShouldPropagate() )
2171 // honour the requests to stop propagation at this window: this is
2172 // used by the dialogs, for example, to prevent processing the events
2173 // from the dialog controls in the parent frame which rarely, if ever,
2175 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2177 wxWindow
*parent
= GetParent();
2178 if ( parent
&& !parent
->IsBeingDeleted() )
2180 wxPropagateOnce
propagateOnce(event
);
2182 return parent
->GetEventHandler()->ProcessEvent(event
);
2187 return wxEvtHandler::TryParent(event
);
2190 // ----------------------------------------------------------------------------
2192 // ----------------------------------------------------------------------------
2194 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2196 while ( win
&& !win
->IsTopLevel() )
2197 win
= win
->GetParent();
2202 #if wxUSE_ACCESSIBILITY
2203 // ----------------------------------------------------------------------------
2204 // accessible object for windows
2205 // ----------------------------------------------------------------------------
2207 // Can return either a child object, or an integer
2208 // representing the child element, starting from 1.
2209 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& pt
, int* childId
, wxAccessible
** childObject
)
2211 wxASSERT( GetWindow() != NULL
);
2215 return wxACC_NOT_IMPLEMENTED
;
2218 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2219 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2221 wxASSERT( GetWindow() != NULL
);
2225 wxWindow
* win
= NULL
;
2232 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2234 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2241 rect
= win
->GetRect();
2242 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2243 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2247 return wxACC_NOT_IMPLEMENTED
;
2250 // Navigates from fromId to toId/toObject.
2251 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2252 int* toId
, wxAccessible
** toObject
)
2254 wxASSERT( GetWindow() != NULL
);
2260 case wxNAVDIR_FIRSTCHILD
:
2262 if (GetWindow()->GetChildren().GetCount() == 0)
2264 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2265 *toObject
= childWindow
->GetOrCreateAccessible();
2269 case wxNAVDIR_LASTCHILD
:
2271 if (GetWindow()->GetChildren().GetCount() == 0)
2273 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2274 *toObject
= childWindow
->GetOrCreateAccessible();
2278 case wxNAVDIR_RIGHT
:
2282 wxWindowList::compatibility_iterator node
=
2283 wxWindowList::compatibility_iterator();
2286 // Can't navigate to sibling of this window
2287 // if we're a top-level window.
2288 if (!GetWindow()->GetParent())
2289 return wxACC_NOT_IMPLEMENTED
;
2291 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2295 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2296 node
= GetWindow()->GetChildren().Item(fromId
-1);
2299 if (node
&& node
->GetNext())
2301 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2302 *toObject
= nextWindow
->GetOrCreateAccessible();
2310 case wxNAVDIR_PREVIOUS
:
2312 wxWindowList::compatibility_iterator node
=
2313 wxWindowList::compatibility_iterator();
2316 // Can't navigate to sibling of this window
2317 // if we're a top-level window.
2318 if (!GetWindow()->GetParent())
2319 return wxACC_NOT_IMPLEMENTED
;
2321 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2325 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2326 node
= GetWindow()->GetChildren().Item(fromId
-1);
2329 if (node
&& node
->GetPrevious())
2331 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2332 *toObject
= previousWindow
->GetOrCreateAccessible();
2340 return wxACC_NOT_IMPLEMENTED
;
2343 // Gets the name of the specified object.
2344 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2346 wxASSERT( GetWindow() != NULL
);
2352 // If a child, leave wxWindows to call the function on the actual
2355 return wxACC_NOT_IMPLEMENTED
;
2357 // This will eventually be replaced by specialised
2358 // accessible classes, one for each kind of wxWindows
2359 // control or window.
2360 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2361 title
= ((wxButton
*) GetWindow())->GetLabel();
2363 title
= GetWindow()->GetName();
2365 if (!title
.IsEmpty())
2371 return wxACC_NOT_IMPLEMENTED
;
2374 // Gets the number of children.
2375 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2377 wxASSERT( GetWindow() != NULL
);
2381 *childId
= (int) GetWindow()->GetChildren().GetCount();
2385 // Gets the specified child (starting from 1).
2386 // If *child is NULL and return value is wxACC_OK,
2387 // this means that the child is a simple element and
2388 // not an accessible object.
2389 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2391 wxASSERT( GetWindow() != NULL
);
2401 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2404 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2405 *child
= childWindow
->GetOrCreateAccessible();
2412 // Gets the parent, or NULL.
2413 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2415 wxASSERT( GetWindow() != NULL
);
2419 wxWindow
* parentWindow
= GetWindow()->GetParent();
2427 *parent
= parentWindow
->GetOrCreateAccessible();
2435 // Performs the default action. childId is 0 (the action for this object)
2436 // or > 0 (the action for a child).
2437 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2438 // window (e.g. an edit control).
2439 wxAccStatus
wxWindowAccessible::DoDefaultAction(int childId
)
2441 wxASSERT( GetWindow() != NULL
);
2445 return wxACC_NOT_IMPLEMENTED
;
2448 // Gets the default action for this object (0) or > 0 (the action for a child).
2449 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2450 // string if there is no action.
2451 // The retrieved string describes the action that is performed on an object,
2452 // not what the object does as a result. For example, a toolbar button that prints
2453 // a document has a default action of "Press" rather than "Prints the current document."
2454 wxAccStatus
wxWindowAccessible::GetDefaultAction(int childId
, wxString
* actionName
)
2456 wxASSERT( GetWindow() != NULL
);
2460 return wxACC_NOT_IMPLEMENTED
;
2463 // Returns the description for this object or a child.
2464 wxAccStatus
wxWindowAccessible::GetDescription(int childId
, wxString
* description
)
2466 wxASSERT( GetWindow() != NULL
);
2470 wxString
ht(GetWindow()->GetHelpText());
2476 return wxACC_NOT_IMPLEMENTED
;
2479 // Returns help text for this object or a child, similar to tooltip text.
2480 wxAccStatus
wxWindowAccessible::GetHelpText(int childId
, wxString
* helpText
)
2482 wxASSERT( GetWindow() != NULL
);
2486 wxString
ht(GetWindow()->GetHelpText());
2492 return wxACC_NOT_IMPLEMENTED
;
2495 // Returns the keyboard shortcut for this object or child.
2496 // Return e.g. ALT+K
2497 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int childId
, wxString
* shortcut
)
2499 wxASSERT( GetWindow() != NULL
);
2503 return wxACC_NOT_IMPLEMENTED
;
2506 // Returns a role constant.
2507 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
2509 wxASSERT( GetWindow() != NULL
);
2513 // If a child, leave wxWindows to call the function on the actual
2516 return wxACC_NOT_IMPLEMENTED
;
2518 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2519 return wxACC_NOT_IMPLEMENTED
;
2521 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2522 return wxACC_NOT_IMPLEMENTED
;
2525 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2526 return wxACC_NOT_IMPLEMENTED
;
2529 //*role = wxROLE_SYSTEM_CLIENT;
2530 *role
= wxROLE_SYSTEM_CLIENT
;
2533 return wxACC_NOT_IMPLEMENTED
;
2536 // Returns a state constant.
2537 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
2539 wxASSERT( GetWindow() != NULL
);
2543 // If a child, leave wxWindows to call the function on the actual
2546 return wxACC_NOT_IMPLEMENTED
;
2548 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2549 return wxACC_NOT_IMPLEMENTED
;
2552 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2553 return wxACC_NOT_IMPLEMENTED
;
2556 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2557 return wxACC_NOT_IMPLEMENTED
;
2563 return wxACC_NOT_IMPLEMENTED
;
2566 // Returns a localized string representing the value for the object
2568 wxAccStatus
wxWindowAccessible::GetValue(int childId
, wxString
* strValue
)
2570 wxASSERT( GetWindow() != NULL
);
2574 return wxACC_NOT_IMPLEMENTED
;
2577 // Selects the object or child.
2578 wxAccStatus
wxWindowAccessible::Select(int childId
, wxAccSelectionFlags selectFlags
)
2580 wxASSERT( GetWindow() != NULL
);
2584 return wxACC_NOT_IMPLEMENTED
;
2587 // Gets the window with the keyboard focus.
2588 // If childId is 0 and child is NULL, no object in
2589 // this subhierarchy has the focus.
2590 // If this object has the focus, child should be 'this'.
2591 wxAccStatus
wxWindowAccessible::GetFocus(int* childId
, wxAccessible
** child
)
2593 wxASSERT( GetWindow() != NULL
);
2597 return wxACC_NOT_IMPLEMENTED
;
2600 // Gets a variant representing the selected children
2602 // Acceptable values:
2603 // - a null variant (IsNull() returns TRUE)
2604 // - a list variant (GetType() == wxT("list")
2605 // - an integer representing the selected child element,
2606 // or 0 if this object is selected (GetType() == wxT("long")
2607 // - a "void*" pointer to a wxAccessible child object
2608 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* selections
)
2610 wxASSERT( GetWindow() != NULL
);
2614 return wxACC_NOT_IMPLEMENTED
;
2617 #endif // wxUSE_ACCESSIBILITY