1 /////////////////////////////////////////////////////////////////////////////
2 // Name: common/window.cpp
3 // Purpose: common (to all ports) wxWindow functions
4 // Author: Julian Smart, Vadim Zeitlin
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "windowbase.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
32 #include "wx/string.h"
37 #include "wx/window.h"
38 #include "wx/control.h"
39 #include "wx/checkbox.h"
40 #include "wx/radiobut.h"
41 #include "wx/statbox.h"
42 #include "wx/textctrl.h"
43 #include "wx/settings.h"
44 #include "wx/dialog.h"
45 #include "wx/msgdlg.h"
46 #include "wx/statusbr.h"
47 #include "wx/dcclient.h"
51 #include "wx/layout.h"
52 #endif // wxUSE_CONSTRAINTS
56 #if wxUSE_DRAG_AND_DROP
58 #endif // wxUSE_DRAG_AND_DROP
60 #if wxUSE_ACCESSIBILITY
61 #include "wx/access.h"
65 #include "wx/cshelp.h"
69 #include "wx/tooltip.h"
70 #endif // wxUSE_TOOLTIPS
76 // ----------------------------------------------------------------------------
78 // ----------------------------------------------------------------------------
81 int wxWindowBase::ms_lastControlId
= 2000;
83 int wxWindowBase::ms_lastControlId
= -200;
86 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
88 // ----------------------------------------------------------------------------
90 // ----------------------------------------------------------------------------
92 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
93 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
94 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
95 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick
)
98 EVT_HELP(wxID_ANY
, wxWindowBase::OnHelp
)
103 // ============================================================================
104 // implementation of the common functionality of the wxWindow class
105 // ============================================================================
107 // ----------------------------------------------------------------------------
109 // ----------------------------------------------------------------------------
111 // the default initialization
112 wxWindowBase::wxWindowBase()
114 // no window yet, no parent nor children
115 m_parent
= (wxWindow
*)NULL
;
116 m_windowId
= wxID_ANY
;
118 // no constraints on the minimal window size
124 // window are created enabled and visible by default
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 m_windowVariant
= wxWINDOW_VARIANT_NORMAL
;
197 // Whether we're using the current theme for this window (wxGTK only for now)
198 m_themeEnabled
= false;
201 // common part of window creation process
202 bool wxWindowBase::CreateBase(wxWindowBase
*parent
,
204 const wxPoint
& WXUNUSED(pos
),
205 const wxSize
& WXUNUSED(size
),
207 const wxValidator
& wxVALIDATOR_PARAM(validator
),
208 const wxString
& name
)
211 // wxGTK doesn't allow to create controls with static box as the parent so
212 // this will result in a crash when the program is ported to wxGTK so warn
215 // if you get this assert, the correct solution is to create the controls
216 // as siblings of the static box
217 wxASSERT_MSG( !parent
|| !wxDynamicCast(parent
, wxStaticBox
),
218 _T("wxStaticBox can't be used as a window parent!") );
219 #endif // wxUSE_STATBOX
221 // ids are limited to 16 bits under MSW so if you care about portability,
222 // it's not a good idea to use ids out of this range (and negative ids are
223 // reserved for wxWindows own usage)
224 wxASSERT_MSG( id
== wxID_ANY
|| (id
>= 0 && id
< 32767),
225 _T("invalid id value") );
227 // generate a new id if the user doesn't care about it
228 m_windowId
= id
== wxID_ANY
? NewControlId() : id
;
231 SetWindowStyleFlag(style
);
235 SetValidator(validator
);
236 #endif // wxUSE_VALIDATORS
238 // if the parent window has wxWS_EX_VALIDATE_RECURSIVELY set, we want to
239 // have it too - like this it's possible to set it only in the top level
240 // dialog/frame and all children will inherit it by defult
241 if ( parent
&& (parent
->GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) )
243 SetExtraStyle(GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY
);
249 // ----------------------------------------------------------------------------
251 // ----------------------------------------------------------------------------
254 wxWindowBase::~wxWindowBase()
256 wxASSERT_MSG( GetCapture() != this, wxT("attempt to destroy window with mouse capture") );
258 // FIXME if these 2 cases result from programming errors in the user code
259 // we should probably assert here instead of silently fixing them
261 // Just in case the window has been Closed, but we're then deleting
262 // immediately: don't leave dangling pointers.
263 wxPendingDelete
.DeleteObject(this);
265 // Just in case we've loaded a top-level window via LoadNativeDialog but
266 // we weren't a dialog class
267 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
269 wxASSERT_MSG( GetChildren().GetCount() == 0, wxT("children not destroyed") );
271 // reset the dangling pointer our parent window may keep to us
274 if ( m_parent
->GetDefaultItem() == this )
276 m_parent
->SetDefaultItem(NULL
);
279 m_parent
->RemoveChild(this);
284 #endif // wxUSE_CARET
287 delete m_windowValidator
;
288 #endif // wxUSE_VALIDATORS
290 #if wxUSE_CONSTRAINTS
291 // Have to delete constraints/sizer FIRST otherwise sizers may try to look
292 // at deleted windows as they delete themselves.
293 DeleteRelatedConstraints();
297 // This removes any dangling pointers to this window in other windows'
298 // constraintsInvolvedIn lists.
299 UnsetConstraints(m_constraints
);
300 delete m_constraints
;
301 m_constraints
= NULL
;
303 #endif // wxUSE_CONSTRAINTS
305 if ( m_containingSizer
)
306 m_containingSizer
->Detach( (wxWindow
*)this );
308 delete m_windowSizer
;
310 #if wxUSE_DRAG_AND_DROP
312 #endif // wxUSE_DRAG_AND_DROP
316 #endif // wxUSE_TOOLTIPS
318 #if wxUSE_ACCESSIBILITY
323 bool wxWindowBase::Destroy()
330 bool wxWindowBase::Close(bool force
)
332 wxCloseEvent
event(wxEVT_CLOSE_WINDOW
, m_windowId
);
333 event
.SetEventObject(this);
334 event
.SetCanVeto(!force
);
336 // return false if window wasn't closed because the application vetoed the
338 return GetEventHandler()->ProcessEvent(event
) && !event
.GetVeto();
341 bool wxWindowBase::DestroyChildren()
343 wxWindowList::compatibility_iterator node
;
346 // we iterate until the list becomes empty
347 node
= GetChildren().GetFirst();
351 wxWindow
*child
= node
->GetData();
353 // note that we really want to call delete and not ->Destroy() here
354 // because we want to delete the child immediately, before we are
355 // deleted, and delayed deletion would result in problems as our (top
356 // level) child could outlive its parent
359 wxASSERT_MSG( !GetChildren().Find(child
),
360 wxT("child didn't remove itself using RemoveChild()") );
366 // ----------------------------------------------------------------------------
367 // size/position related methods
368 // ----------------------------------------------------------------------------
370 // centre the window with respect to its parent in either (or both) directions
371 void wxWindowBase::Centre(int direction
)
373 // the position/size of the parent window or of the entire screen
375 int widthParent
, heightParent
;
377 wxWindow
*parent
= NULL
;
379 if ( !(direction
& wxCENTRE_ON_SCREEN
) )
381 // find the parent to centre this window on: it should be the
382 // immediate parent for the controls but the top level parent for the
383 // top level windows (like dialogs)
384 parent
= GetParent();
387 while ( parent
&& !parent
->IsTopLevel() )
389 parent
= parent
->GetParent();
393 // there is no wxTopLevelWindow under wxMotif yet
395 // we shouldn't center the dialog on the iconized window: under
396 // Windows, for example, this places it completely off the screen
399 wxTopLevelWindow
*winTop
= wxDynamicCast(parent
, wxTopLevelWindow
);
400 if ( winTop
&& winTop
->IsIconized() )
405 #endif // __WXMOTIF__
407 // did we find the parent?
411 direction
|= wxCENTRE_ON_SCREEN
;
415 if ( direction
& wxCENTRE_ON_SCREEN
)
417 // centre with respect to the whole screen
418 wxDisplaySize(&widthParent
, &heightParent
);
424 // centre on the parent
425 parent
->GetSize(&widthParent
, &heightParent
);
427 // adjust to the parents position
428 posParent
= parent
->GetPosition();
432 // centre inside the parents client rectangle
433 parent
->GetClientSize(&widthParent
, &heightParent
);
438 GetSize(&width
, &height
);
443 if ( direction
& wxHORIZONTAL
)
444 xNew
= (widthParent
- width
)/2;
446 if ( direction
& wxVERTICAL
)
447 yNew
= (heightParent
- height
)/2;
452 // Base size of the visible dimensions of the display
453 // to take into account the taskbar
454 wxRect rect
= wxGetClientDisplayRect();
455 wxSize
size (rect
.width
,rect
.height
);
457 // NB: in wxMSW, negative position may not neccessary mean "out of screen",
458 // but it may mean that the window is placed on other than the main
459 // display. Therefore we only make sure centered window is on the main display
460 // if the parent is at least partially present here.
461 if (posParent
.x
+ widthParent
>= 0) // if parent is (partially) on the main display
465 else if (xNew
+width
> size
.x
)
466 xNew
= size
.x
-width
-1;
468 if (posParent
.y
+ heightParent
>= 0) // if parent is (partially) on the main display
470 if (yNew
+height
> size
.y
)
471 yNew
= size
.y
-height
-1;
473 // Make certain that the title bar is initially visible
474 // always, even if this would push the bottom of the
475 // dialog of the visible area of the display
480 // move the window to this position (keeping the old size but using
481 // SetSize() and not Move() to allow xNew and/or yNew to be -1)
482 SetSize(xNew
, yNew
, width
, height
, wxSIZE_ALLOW_MINUS_ONE
);
485 // fits the window around the children
486 void wxWindowBase::Fit()
488 if ( GetChildren().GetCount() > 0 )
490 SetClientSize(DoGetBestSize());
492 //else: do nothing if we have no children
495 // fits virtual size (ie. scrolled area etc.) around children
496 void wxWindowBase::FitInside()
498 if ( GetChildren().GetCount() > 0 )
500 SetVirtualSize( GetBestVirtualSize() );
504 // return the size best suited for the current window
505 wxSize
wxWindowBase::DoGetBestSize() const
509 return m_windowSizer
->GetMinSize();
511 #if wxUSE_CONSTRAINTS
512 else if ( m_constraints
)
514 wxConstCast(this, wxWindowBase
)->SatisfyConstraints();
516 // our minimal acceptable size is such that all our windows fit inside
520 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
522 node
= node
->GetNext() )
524 wxLayoutConstraints
*c
= node
->GetData()->GetConstraints();
527 // it's not normal that we have an unconstrained child, but
528 // what can we do about it?
532 int x
= c
->right
.GetValue(),
533 y
= c
->bottom
.GetValue();
541 // TODO: we must calculate the overlaps somehow, otherwise we
542 // will never return a size bigger than the current one :-(
545 return wxSize(maxX
, maxY
);
547 #endif // wxUSE_CONSTRAINTS
548 else if ( GetChildren().GetCount() > 0 )
550 // our minimal acceptable size is such that all our windows fit inside
554 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
556 node
= node
->GetNext() )
558 wxWindow
*win
= node
->GetData();
559 if ( win
->IsTopLevel()
561 || wxDynamicCast(win
, wxStatusBar
)
562 #endif // wxUSE_STATUSBAR
565 // dialogs and frames lie in different top level windows -
566 // don't deal with them here; as for the status bars, they
567 // don't lie in the client area at all
572 win
->GetPosition(&wx
, &wy
);
574 // if the window hadn't been positioned yet, assume that it is in
581 win
->GetSize(&ww
, &wh
);
582 if ( wx
+ ww
> maxX
)
584 if ( wy
+ wh
> maxY
)
588 // for compatibility with the old versions and because it really looks
589 // slightly more pretty like this, add a pad
593 return wxSize(maxX
, maxY
);
597 // for a generic window there is no natural best size - just use the
603 // by default the origin is not shifted
604 wxPoint
wxWindowBase::GetClientAreaOrigin() const
606 return wxPoint(0, 0);
609 // set the min/max size of the window
610 void wxWindowBase::SetSizeHints(int minW
, int minH
,
612 int WXUNUSED(incW
), int WXUNUSED(incH
))
614 // setting min width greater than max width leads to infinite loops under
615 // X11 and generally doesn't make any sense, so don't allow it
616 wxCHECK_RET( (minW
== -1 || maxW
== -1 || minW
<= maxW
) &&
617 (minH
== -1 || maxH
== -1 || minH
<= maxH
),
618 _T("min width/height must be less than max width/height!") );
626 void wxWindowBase::SetWindowVariant( wxWindowVariant variant
)
628 if ( m_windowVariant
== variant
)
631 m_windowVariant
= variant
;
633 DoSetWindowVariant( variant
) ;
637 void wxWindowBase::DoSetWindowVariant( wxWindowVariant variant
)
639 wxFont font
= wxSystemSettings::GetSystemFont( wxSYS_DEFAULT_GUI_FONT
) ;
640 int size
= font
.GetPointSize() ;
643 case wxWINDOW_VARIANT_NORMAL
:
645 case wxWINDOW_VARIANT_SMALL
:
646 font
.SetPointSize( size
* 3 / 4 ) ;
648 case wxWINDOW_VARIANT_MINI
:
649 font
.SetPointSize( size
* 2 / 3 ) ;
651 case wxWINDOW_VARIANT_LARGE
:
652 font
.SetPointSize( size
* 5 / 4 ) ;
655 wxFAIL_MSG(_T("unexpected window variant"));
661 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
664 m_minVirtualWidth
= minW
;
665 m_maxVirtualWidth
= maxW
;
666 m_minVirtualHeight
= minH
;
667 m_maxVirtualHeight
= maxH
;
670 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
672 if ( m_minVirtualWidth
!= -1 && m_minVirtualWidth
> x
)
673 x
= m_minVirtualWidth
;
674 if ( m_maxVirtualWidth
!= -1 && m_maxVirtualWidth
< x
)
675 x
= m_maxVirtualWidth
;
676 if ( m_minVirtualHeight
!= -1 && m_minVirtualHeight
> y
)
677 y
= m_minVirtualHeight
;
678 if ( m_maxVirtualHeight
!= -1 && m_maxVirtualHeight
< y
)
679 y
= m_maxVirtualHeight
;
681 m_virtualSize
= wxSize(x
, y
);
684 wxSize
wxWindowBase::DoGetVirtualSize() const
686 wxSize
s( GetClientSize() );
688 return wxSize( wxMax( m_virtualSize
.GetWidth(), s
.GetWidth() ),
689 wxMax( m_virtualSize
.GetHeight(), s
.GetHeight() ) );
692 // ----------------------------------------------------------------------------
693 // show/hide/enable/disable the window
694 // ----------------------------------------------------------------------------
696 bool wxWindowBase::Show(bool show
)
698 if ( show
!= m_isShown
)
710 bool wxWindowBase::Enable(bool enable
)
712 if ( enable
!= m_isEnabled
)
714 m_isEnabled
= enable
;
723 // ----------------------------------------------------------------------------
725 // ----------------------------------------------------------------------------
727 bool wxWindowBase::IsTopLevel() const
732 // ----------------------------------------------------------------------------
733 // reparenting the window
734 // ----------------------------------------------------------------------------
736 void wxWindowBase::AddChild(wxWindowBase
*child
)
738 wxCHECK_RET( child
, wxT("can't add a NULL child") );
740 // this should never happen and it will lead to a crash later if it does
741 // because RemoveChild() will remove only one node from the children list
742 // and the other(s) one(s) will be left with dangling pointers in them
743 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
745 GetChildren().Append((wxWindow
*)child
);
746 child
->SetParent(this);
749 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
751 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
753 GetChildren().DeleteObject((wxWindow
*)child
);
754 child
->SetParent(NULL
);
757 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
759 wxWindow
*oldParent
= GetParent();
760 if ( newParent
== oldParent
)
766 // unlink this window from the existing parent.
769 oldParent
->RemoveChild(this);
773 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
776 // add it to the new one
779 newParent
->AddChild(this);
783 wxTopLevelWindows
.Append((wxWindow
*)this);
789 // ----------------------------------------------------------------------------
790 // event handler stuff
791 // ----------------------------------------------------------------------------
793 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
795 wxEvtHandler
*handlerOld
= GetEventHandler();
797 handler
->SetNextHandler(handlerOld
);
800 GetEventHandler()->SetPreviousHandler(handler
);
802 SetEventHandler(handler
);
805 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
807 wxEvtHandler
*handlerA
= GetEventHandler();
810 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
811 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
814 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
815 SetEventHandler(handlerB
);
820 handlerA
= (wxEvtHandler
*)NULL
;
827 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
829 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
831 wxEvtHandler
*handlerPrev
= NULL
,
832 *handlerCur
= GetEventHandler();
835 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
837 if ( handlerCur
== handler
)
841 handlerPrev
->SetNextHandler(handlerNext
);
845 SetEventHandler(handlerNext
);
850 handlerNext
->SetPreviousHandler ( handlerPrev
);
853 handler
->SetNextHandler(NULL
);
854 handler
->SetPreviousHandler(NULL
);
859 handlerPrev
= handlerCur
;
860 handlerCur
= handlerNext
;
863 wxFAIL_MSG( _T("where has the event handler gone?") );
868 // ----------------------------------------------------------------------------
870 // ----------------------------------------------------------------------------
872 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
874 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
877 m_backgroundColour
= colour
;
884 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
886 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
889 m_foregroundColour
= colour
;
896 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
898 // setting an invalid cursor is ok, it means that we don't have any special
900 if ( m_cursor
== cursor
)
911 bool wxWindowBase::SetFont(const wxFont
& font
)
913 // don't try to set invalid font, always fall back to the default
914 const wxFont
& fontOk
= font
.Ok() ? font
: *wxSWISS_FONT
;
916 if ( fontOk
== m_font
)
931 void wxWindowBase::SetPalette(const wxPalette
& pal
)
933 m_hasCustomPalette
= true;
936 // VZ: can anyone explain me what do we do here?
937 wxWindowDC
d((wxWindow
*) this);
941 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
943 wxWindow
*win
= (wxWindow
*)this;
944 while ( win
&& !win
->HasCustomPalette() )
946 win
= win
->GetParent();
952 #endif // wxUSE_PALETTE
955 void wxWindowBase::SetCaret(wxCaret
*caret
)
966 wxASSERT_MSG( m_caret
->GetWindow() == this,
967 wxT("caret should be created associated to this window") );
970 #endif // wxUSE_CARET
973 // ----------------------------------------------------------------------------
975 // ----------------------------------------------------------------------------
977 void wxWindowBase::SetValidator(const wxValidator
& validator
)
979 if ( m_windowValidator
)
980 delete m_windowValidator
;
982 m_windowValidator
= (wxValidator
*)validator
.Clone();
984 if ( m_windowValidator
)
985 m_windowValidator
->SetWindow(this) ;
987 #endif // wxUSE_VALIDATORS
989 // ----------------------------------------------------------------------------
990 // update region stuff
991 // ----------------------------------------------------------------------------
993 wxRect
wxWindowBase::GetUpdateClientRect() const
995 wxRegion rgnUpdate
= GetUpdateRegion();
996 rgnUpdate
.Intersect(GetClientRect());
997 wxRect rectUpdate
= rgnUpdate
.GetBox();
998 wxPoint ptOrigin
= GetClientAreaOrigin();
999 rectUpdate
.x
-= ptOrigin
.x
;
1000 rectUpdate
.y
-= ptOrigin
.y
;
1005 bool wxWindowBase::IsExposed(int x
, int y
) const
1007 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1010 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
1012 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1015 void wxWindowBase::ClearBackground()
1017 // wxGTK uses its own version, no need to add never used code
1019 wxClientDC
dc((wxWindow
*)this);
1020 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1021 dc
.SetBackground(brush
);
1026 // ----------------------------------------------------------------------------
1027 // find child window by id or name
1028 // ----------------------------------------------------------------------------
1030 wxWindow
*wxWindowBase::FindWindow( long id
)
1032 if ( id
== m_windowId
)
1033 return (wxWindow
*)this;
1035 wxWindowBase
*res
= (wxWindow
*)NULL
;
1036 wxWindowList::compatibility_iterator node
;
1037 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1039 wxWindowBase
*child
= node
->GetData();
1040 res
= child
->FindWindow( id
);
1043 return (wxWindow
*)res
;
1046 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
1048 if ( name
== m_windowName
)
1049 return (wxWindow
*)this;
1051 wxWindowBase
*res
= (wxWindow
*)NULL
;
1052 wxWindowList::compatibility_iterator node
;
1053 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1055 wxWindow
*child
= node
->GetData();
1056 res
= child
->FindWindow(name
);
1059 return (wxWindow
*)res
;
1063 // find any window by id or name or label: If parent is non-NULL, look through
1064 // children for a label or title matching the specified string. If NULL, look
1065 // through all top-level windows.
1067 // to avoid duplicating code we reuse the same helper function but with
1068 // different comparators
1070 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1071 const wxString
& label
, long id
);
1074 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1077 return win
->GetLabel() == label
;
1081 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1084 return win
->GetName() == label
;
1088 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1091 return win
->GetId() == id
;
1094 // recursive helper for the FindWindowByXXX() functions
1096 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1097 const wxString
& label
,
1099 wxFindWindowCmp cmp
)
1103 // see if this is the one we're looking for
1104 if ( (*cmp
)(parent
, label
, id
) )
1105 return (wxWindow
*)parent
;
1107 // It wasn't, so check all its children
1108 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1110 node
= node
->GetNext() )
1112 // recursively check each child
1113 wxWindow
*win
= (wxWindow
*)node
->GetData();
1114 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1124 // helper for FindWindowByXXX()
1126 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1127 const wxString
& label
,
1129 wxFindWindowCmp cmp
)
1133 // just check parent and all its children
1134 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1137 // start at very top of wx's windows
1138 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1140 node
= node
->GetNext() )
1142 // recursively check each window & its children
1143 wxWindow
*win
= node
->GetData();
1144 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1154 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1156 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1161 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1163 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1167 // fall back to the label
1168 win
= FindWindowByLabel(title
, parent
);
1176 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1178 return wxFindWindowHelper(parent
, _T(""), id
, wxFindWindowCmpIds
);
1181 // ----------------------------------------------------------------------------
1182 // dialog oriented functions
1183 // ----------------------------------------------------------------------------
1185 void wxWindowBase::MakeModal(bool modal
)
1187 // Disable all other windows
1190 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1193 wxWindow
*win
= node
->GetData();
1195 win
->Enable(!modal
);
1197 node
= node
->GetNext();
1202 bool wxWindowBase::Validate()
1204 #if wxUSE_VALIDATORS
1205 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1207 wxWindowList::compatibility_iterator node
;
1208 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1210 wxWindowBase
*child
= node
->GetData();
1211 wxValidator
*validator
= child
->GetValidator();
1212 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1217 if ( recurse
&& !child
->Validate() )
1222 #endif // wxUSE_VALIDATORS
1227 bool wxWindowBase::TransferDataToWindow()
1229 #if wxUSE_VALIDATORS
1230 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1232 wxWindowList::compatibility_iterator node
;
1233 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1235 wxWindowBase
*child
= node
->GetData();
1236 wxValidator
*validator
= child
->GetValidator();
1237 if ( validator
&& !validator
->TransferToWindow() )
1239 wxLogWarning(_("Could not transfer data to window"));
1241 wxLog::FlushActive();
1249 if ( !child
->TransferDataToWindow() )
1251 // warning already given
1256 #endif // wxUSE_VALIDATORS
1261 bool wxWindowBase::TransferDataFromWindow()
1263 #if wxUSE_VALIDATORS
1264 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1266 wxWindowList::compatibility_iterator node
;
1267 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1269 wxWindow
*child
= node
->GetData();
1270 wxValidator
*validator
= child
->GetValidator();
1271 if ( validator
&& !validator
->TransferFromWindow() )
1273 // nop warning here because the application is supposed to give
1274 // one itself - we don't know here what might have gone wrongly
1281 if ( !child
->TransferDataFromWindow() )
1283 // warning already given
1288 #endif // wxUSE_VALIDATORS
1293 void wxWindowBase::InitDialog()
1295 wxInitDialogEvent
event(GetId());
1296 event
.SetEventObject( this );
1297 GetEventHandler()->ProcessEvent(event
);
1300 // ----------------------------------------------------------------------------
1301 // context-sensitive help support
1302 // ----------------------------------------------------------------------------
1306 // associate this help text with this window
1307 void wxWindowBase::SetHelpText(const wxString
& text
)
1309 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1312 helpProvider
->AddHelp(this, text
);
1316 // associate this help text with all windows with the same id as this
1318 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1320 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1323 helpProvider
->AddHelp(GetId(), text
);
1327 // get the help string associated with this window (may be empty)
1328 wxString
wxWindowBase::GetHelpText() const
1331 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1334 text
= helpProvider
->GetHelp(this);
1340 // show help for this window
1341 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1343 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1346 if ( helpProvider
->ShowHelp(this) )
1348 // skip the event.Skip() below
1356 #endif // wxUSE_HELP
1358 // ----------------------------------------------------------------------------
1359 // tooltipsroot.Replace("\\", "/");
1360 // ----------------------------------------------------------------------------
1364 void wxWindowBase::SetToolTip( const wxString
&tip
)
1366 // don't create the new tooltip if we already have one
1369 m_tooltip
->SetTip( tip
);
1373 SetToolTip( new wxToolTip( tip
) );
1376 // setting empty tooltip text does not remove the tooltip any more - use
1377 // SetToolTip((wxToolTip *)NULL) for this
1380 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1385 m_tooltip
= tooltip
;
1388 #endif // wxUSE_TOOLTIPS
1390 // ----------------------------------------------------------------------------
1391 // constraints and sizers
1392 // ----------------------------------------------------------------------------
1394 #if wxUSE_CONSTRAINTS
1396 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1398 if ( m_constraints
)
1400 UnsetConstraints(m_constraints
);
1401 delete m_constraints
;
1403 m_constraints
= constraints
;
1404 if ( m_constraints
)
1406 // Make sure other windows know they're part of a 'meaningful relationship'
1407 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1408 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1409 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1410 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1411 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1412 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1413 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1414 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1415 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1416 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1417 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1418 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1419 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1420 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1421 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1422 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1426 // This removes any dangling pointers to this window in other windows'
1427 // constraintsInvolvedIn lists.
1428 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1432 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1433 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1434 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1435 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1436 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1437 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1438 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1439 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1440 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1441 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1442 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1443 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1444 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1445 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1446 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1447 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1451 // Back-pointer to other windows we're involved with, so if we delete this
1452 // window, we must delete any constraints we're involved with.
1453 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1455 if ( !m_constraintsInvolvedIn
)
1456 m_constraintsInvolvedIn
= new wxWindowList
;
1457 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1458 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1461 // REMOVE back-pointer to other windows we're involved with.
1462 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1464 if ( m_constraintsInvolvedIn
)
1465 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1468 // Reset any constraints that mention this window
1469 void wxWindowBase::DeleteRelatedConstraints()
1471 if ( m_constraintsInvolvedIn
)
1473 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1476 wxWindow
*win
= node
->GetData();
1477 wxLayoutConstraints
*constr
= win
->GetConstraints();
1479 // Reset any constraints involving this window
1482 constr
->left
.ResetIfWin(this);
1483 constr
->top
.ResetIfWin(this);
1484 constr
->right
.ResetIfWin(this);
1485 constr
->bottom
.ResetIfWin(this);
1486 constr
->width
.ResetIfWin(this);
1487 constr
->height
.ResetIfWin(this);
1488 constr
->centreX
.ResetIfWin(this);
1489 constr
->centreY
.ResetIfWin(this);
1492 wxWindowList::compatibility_iterator next
= node
->GetNext();
1493 m_constraintsInvolvedIn
->Erase(node
);
1497 delete m_constraintsInvolvedIn
;
1498 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1502 #endif // wxUSE_CONSTRAINTS
1504 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1506 if ( sizer
== m_windowSizer
)
1510 delete m_windowSizer
;
1512 m_windowSizer
= sizer
;
1514 SetAutoLayout( sizer
!= NULL
);
1517 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1519 SetSizer( sizer
, deleteOld
);
1520 sizer
->SetSizeHints( (wxWindow
*) this );
1523 #if wxUSE_CONSTRAINTS
1525 void wxWindowBase::SatisfyConstraints()
1527 wxLayoutConstraints
*constr
= GetConstraints();
1528 bool wasOk
= constr
&& constr
->AreSatisfied();
1530 ResetConstraints(); // Mark all constraints as unevaluated
1534 // if we're a top level panel (i.e. our parent is frame/dialog), our
1535 // own constraints will never be satisfied any more unless we do it
1539 while ( noChanges
> 0 )
1541 LayoutPhase1(&noChanges
);
1545 LayoutPhase2(&noChanges
);
1548 #endif // wxUSE_CONSTRAINTS
1550 bool wxWindowBase::Layout()
1552 // If there is a sizer, use it instead of the constraints
1556 GetVirtualSize(&w
, &h
);
1557 GetSizer()->SetDimension( 0, 0, w
, h
);
1559 #if wxUSE_CONSTRAINTS
1562 SatisfyConstraints(); // Find the right constraints values
1563 SetConstraintSizes(); // Recursively set the real window sizes
1570 #if wxUSE_CONSTRAINTS
1572 // first phase of the constraints evaluation: set our own constraints
1573 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1575 wxLayoutConstraints
*constr
= GetConstraints();
1577 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1580 // second phase: set the constraints for our children
1581 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1588 // Layout grand children
1594 // Do a phase of evaluating child constraints
1595 bool wxWindowBase::DoPhase(int phase
)
1597 // the list containing the children for which the constraints are already
1599 wxWindowList succeeded
;
1601 // the max number of iterations we loop before concluding that we can't set
1603 static const int maxIterations
= 500;
1605 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1609 // loop over all children setting their constraints
1610 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1612 node
= node
->GetNext() )
1614 wxWindow
*child
= node
->GetData();
1615 if ( child
->IsTopLevel() )
1617 // top level children are not inside our client area
1621 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1623 // this one is either already ok or nothing we can do about it
1627 int tempNoChanges
= 0;
1628 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1629 : child
->LayoutPhase2(&tempNoChanges
);
1630 noChanges
+= tempNoChanges
;
1634 succeeded
.Append(child
);
1640 // constraints are set
1648 void wxWindowBase::ResetConstraints()
1650 wxLayoutConstraints
*constr
= GetConstraints();
1653 constr
->left
.SetDone(false);
1654 constr
->top
.SetDone(false);
1655 constr
->right
.SetDone(false);
1656 constr
->bottom
.SetDone(false);
1657 constr
->width
.SetDone(false);
1658 constr
->height
.SetDone(false);
1659 constr
->centreX
.SetDone(false);
1660 constr
->centreY
.SetDone(false);
1663 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1666 wxWindow
*win
= node
->GetData();
1667 if ( !win
->IsTopLevel() )
1668 win
->ResetConstraints();
1669 node
= node
->GetNext();
1673 // Need to distinguish between setting the 'fake' size for windows and sizers,
1674 // and setting the real values.
1675 void wxWindowBase::SetConstraintSizes(bool recurse
)
1677 wxLayoutConstraints
*constr
= GetConstraints();
1678 if ( constr
&& constr
->AreSatisfied() )
1680 int x
= constr
->left
.GetValue();
1681 int y
= constr
->top
.GetValue();
1682 int w
= constr
->width
.GetValue();
1683 int h
= constr
->height
.GetValue();
1685 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1686 (constr
->height
.GetRelationship() != wxAsIs
) )
1688 SetSize(x
, y
, w
, h
);
1692 // If we don't want to resize this window, just move it...
1698 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1699 GetClassInfo()->GetClassName(),
1705 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1708 wxWindow
*win
= node
->GetData();
1709 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1710 win
->SetConstraintSizes();
1711 node
= node
->GetNext();
1716 // Only set the size/position of the constraint (if any)
1717 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1719 wxLayoutConstraints
*constr
= GetConstraints();
1724 constr
->left
.SetValue(x
);
1725 constr
->left
.SetDone(true);
1729 constr
->top
.SetValue(y
);
1730 constr
->top
.SetDone(true);
1734 constr
->width
.SetValue(w
);
1735 constr
->width
.SetDone(true);
1739 constr
->height
.SetValue(h
);
1740 constr
->height
.SetDone(true);
1745 void wxWindowBase::MoveConstraint(int x
, int y
)
1747 wxLayoutConstraints
*constr
= GetConstraints();
1752 constr
->left
.SetValue(x
);
1753 constr
->left
.SetDone(true);
1757 constr
->top
.SetValue(y
);
1758 constr
->top
.SetDone(true);
1763 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1765 wxLayoutConstraints
*constr
= GetConstraints();
1768 *w
= constr
->width
.GetValue();
1769 *h
= constr
->height
.GetValue();
1775 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1777 wxLayoutConstraints
*constr
= GetConstraints();
1780 *w
= constr
->width
.GetValue();
1781 *h
= constr
->height
.GetValue();
1784 GetClientSize(w
, h
);
1787 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1789 wxLayoutConstraints
*constr
= GetConstraints();
1792 *x
= constr
->left
.GetValue();
1793 *y
= constr
->top
.GetValue();
1799 #endif // wxUSE_CONSTRAINTS
1801 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
1803 // don't do it for the dialogs/frames - they float independently of their
1805 if ( !IsTopLevel() )
1807 wxWindow
*parent
= GetParent();
1808 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
1810 wxPoint
pt(parent
->GetClientAreaOrigin());
1817 // ----------------------------------------------------------------------------
1818 // do Update UI processing for child controls
1819 // ----------------------------------------------------------------------------
1821 void wxWindowBase::UpdateWindowUI(long flags
)
1823 wxUpdateUIEvent
event(GetId());
1824 event
.m_eventObject
= this;
1826 if ( GetEventHandler()->ProcessEvent(event
) )
1828 DoUpdateWindowUI(event
);
1831 if (flags
& wxUPDATE_UI_RECURSE
)
1833 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1836 wxWindow
* child
= (wxWindow
*) node
->GetData();
1837 child
->UpdateWindowUI(flags
);
1838 node
= node
->GetNext();
1843 // do the window-specific processing after processing the update event
1844 // TODO: take specific knowledge out of this function and
1845 // put in each control's base class. Unfortunately we don't
1846 // yet have base implementation files for wxCheckBox and wxRadioButton.
1847 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
1849 if ( event
.GetSetEnabled() )
1850 Enable(event
.GetEnabled());
1853 if ( event
.GetSetText() )
1855 wxControl
*control
= wxDynamicCastThis(wxControl
);
1858 if ( event
.GetText() != control
->GetLabel() )
1859 control
->SetLabel(event
.GetText());
1862 wxCheckBox
*checkbox
= wxDynamicCastThis(wxCheckBox
);
1865 if ( event
.GetSetChecked() )
1866 checkbox
->SetValue(event
.GetChecked());
1868 #endif // wxUSE_CHECKBOX
1871 wxRadioButton
*radiobtn
= wxDynamicCastThis(wxRadioButton
);
1874 if ( event
.GetSetChecked() )
1875 radiobtn
->SetValue(event
.GetChecked());
1877 #endif // wxUSE_RADIOBTN
1883 // call internal idle recursively
1884 // may be obsolete (wait until OnIdle scheme stabilises)
1885 void wxWindowBase::ProcessInternalIdle()
1889 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1892 wxWindow
*child
= node
->GetData();
1893 child
->ProcessInternalIdle();
1894 node
= node
->GetNext();
1899 // ----------------------------------------------------------------------------
1900 // dialog units translations
1901 // ----------------------------------------------------------------------------
1903 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1905 int charWidth
= GetCharWidth();
1906 int charHeight
= GetCharHeight();
1907 wxPoint
pt2(-1, -1);
1909 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1911 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1916 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1918 int charWidth
= GetCharWidth();
1919 int charHeight
= GetCharHeight();
1920 wxPoint
pt2(-1, -1);
1922 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1924 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1929 // ----------------------------------------------------------------------------
1931 // ----------------------------------------------------------------------------
1933 // propagate the colour change event to the subwindows
1934 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1936 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1939 // Only propagate to non-top-level windows
1940 wxWindow
*win
= node
->GetData();
1941 if ( !win
->IsTopLevel() )
1943 wxSysColourChangedEvent event2
;
1944 event
.m_eventObject
= win
;
1945 win
->GetEventHandler()->ProcessEvent(event2
);
1948 node
= node
->GetNext();
1952 // the default action is to populate dialog with data when it's created,
1953 // and nudge the UI into displaying itself correctly in case
1954 // we've turned the wxUpdateUIEvents frequency down low.
1955 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1957 TransferDataToWindow();
1959 // Update the UI at this point
1960 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
1963 // process Ctrl-Alt-mclick
1964 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
1967 if ( event
.ControlDown() && event
.AltDown() )
1969 // don't translate these strings
1972 #ifdef __WXUNIVERSAL__
1974 #endif // __WXUNIVERSAL__
1976 switch ( wxGetOsVersion() )
1978 case wxMOTIF_X
: port
+= _T("Motif"); break;
1980 case wxMAC_DARWIN
: port
+= _T("Mac"); break;
1981 case wxBEOS
: port
+= _T("BeOS"); break;
1985 case wxGTK_BEOS
: port
+= _T("GTK"); break;
1991 case wxWIN386
: port
+= _T("MS Windows"); break;
1995 case wxMGL_OS2
: port
+= _T("MGL"); break;
1997 case wxOS2_PM
: port
+= _T("OS/2"); break;
1998 default: port
+= _T("unknown"); break;
2001 wxMessageBox(wxString::Format(
2003 " wxWindows Library (%s port)\nVersion %u.%u.%u%s, compiled at %s %s\n Copyright (c) 1995-2002 wxWindows team"
2017 _T("wxWindows information"),
2018 wxICON_INFORMATION
| wxOK
,
2022 #endif // wxUSE_MSGDLG
2028 // ----------------------------------------------------------------------------
2030 // ----------------------------------------------------------------------------
2032 #if wxUSE_ACCESSIBILITY
2033 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2035 if (m_accessible
&& (accessible
!= m_accessible
))
2036 delete m_accessible
;
2037 m_accessible
= accessible
;
2039 m_accessible
->SetWindow((wxWindow
*) this);
2042 // Returns the accessible object, creating if necessary.
2043 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2046 m_accessible
= CreateAccessible();
2047 return m_accessible
;
2050 // Override to create a specific accessible object.
2051 wxAccessible
* wxWindowBase::CreateAccessible()
2053 return new wxWindowAccessible((wxWindow
*) this);
2059 // ----------------------------------------------------------------------------
2060 // list classes implementation
2061 // ----------------------------------------------------------------------------
2063 void wxWindowListNode::DeleteData()
2065 delete (wxWindow
*)GetData();
2069 // ----------------------------------------------------------------------------
2071 // ----------------------------------------------------------------------------
2073 wxBorder
wxWindowBase::GetBorder(long flags
) const
2075 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2076 if ( border
== wxBORDER_DEFAULT
)
2078 border
= GetDefaultBorder();
2084 wxBorder
wxWindowBase::GetDefaultBorder() const
2086 return wxBORDER_NONE
;
2089 // ----------------------------------------------------------------------------
2091 // ----------------------------------------------------------------------------
2093 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2095 // here we just check if the point is inside the window or not
2097 // check the top and left border first
2098 bool outside
= x
< 0 || y
< 0;
2101 // check the right and bottom borders too
2102 wxSize size
= GetSize();
2103 outside
= x
>= size
.x
|| y
>= size
.y
;
2106 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2109 // ----------------------------------------------------------------------------
2111 // ----------------------------------------------------------------------------
2113 struct WXDLLEXPORT wxWindowNext
2117 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2119 void wxWindowBase::CaptureMouse()
2121 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this);
2123 wxWindow
*winOld
= GetCapture();
2126 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2129 wxWindowNext
*item
= new wxWindowNext
;
2131 item
->next
= ms_winCaptureNext
;
2132 ms_winCaptureNext
= item
;
2134 //else: no mouse capture to save
2139 void wxWindowBase::ReleaseMouse()
2141 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this);
2143 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2147 if ( ms_winCaptureNext
)
2149 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2151 wxWindowNext
*item
= ms_winCaptureNext
;
2152 ms_winCaptureNext
= item
->next
;
2155 //else: stack is empty, no previous capture
2157 wxLogTrace(_T("mousecapture"),
2158 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2165 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2166 int WXUNUSED(modifiers
),
2167 int WXUNUSED(keycode
))
2173 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2179 #endif // wxUSE_HOTKEY
2181 void wxWindowBase::SendDestroyEvent()
2183 wxWindowDestroyEvent event
;
2184 event
.SetEventObject(this);
2185 event
.SetId(GetId());
2186 GetEventHandler()->ProcessEvent(event
);
2189 // ----------------------------------------------------------------------------
2191 // ----------------------------------------------------------------------------
2193 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2195 #if wxUSE_VALIDATORS
2196 // Can only use the validator of the window which
2197 // is receiving the event
2198 if ( event
.GetEventObject() == this )
2200 wxValidator
*validator
= GetValidator();
2201 if ( validator
&& validator
->ProcessEvent(event
) )
2206 #endif // wxUSE_VALIDATORS
2211 bool wxWindowBase::TryParent(wxEvent
& event
)
2213 // carry on up the parent-child hierarchy if the propgation count hasn't
2215 if ( event
.ShouldPropagate() )
2217 // honour the requests to stop propagation at this window: this is
2218 // used by the dialogs, for example, to prevent processing the events
2219 // from the dialog controls in the parent frame which rarely, if ever,
2221 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2223 wxWindow
*parent
= GetParent();
2224 if ( parent
&& !parent
->IsBeingDeleted() )
2226 wxPropagateOnce
propagateOnce(event
);
2228 return parent
->GetEventHandler()->ProcessEvent(event
);
2233 return wxEvtHandler::TryParent(event
);
2236 // ----------------------------------------------------------------------------
2238 // ----------------------------------------------------------------------------
2240 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2242 while ( win
&& !win
->IsTopLevel() )
2243 win
= win
->GetParent();
2248 #if wxUSE_ACCESSIBILITY
2249 // ----------------------------------------------------------------------------
2250 // accessible object for windows
2251 // ----------------------------------------------------------------------------
2253 // Can return either a child object, or an integer
2254 // representing the child element, starting from 1.
2255 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2257 wxASSERT( GetWindow() != NULL
);
2261 return wxACC_NOT_IMPLEMENTED
;
2264 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2265 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2267 wxASSERT( GetWindow() != NULL
);
2271 wxWindow
* win
= NULL
;
2278 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2280 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2287 rect
= win
->GetRect();
2288 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2289 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2293 return wxACC_NOT_IMPLEMENTED
;
2296 // Navigates from fromId to toId/toObject.
2297 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2298 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2300 wxASSERT( GetWindow() != NULL
);
2306 case wxNAVDIR_FIRSTCHILD
:
2308 if (GetWindow()->GetChildren().GetCount() == 0)
2310 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2311 *toObject
= childWindow
->GetOrCreateAccessible();
2315 case wxNAVDIR_LASTCHILD
:
2317 if (GetWindow()->GetChildren().GetCount() == 0)
2319 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2320 *toObject
= childWindow
->GetOrCreateAccessible();
2324 case wxNAVDIR_RIGHT
:
2328 wxWindowList::compatibility_iterator node
=
2329 wxWindowList::compatibility_iterator();
2332 // Can't navigate to sibling of this window
2333 // if we're a top-level window.
2334 if (!GetWindow()->GetParent())
2335 return wxACC_NOT_IMPLEMENTED
;
2337 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2341 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2342 node
= GetWindow()->GetChildren().Item(fromId
-1);
2345 if (node
&& node
->GetNext())
2347 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2348 *toObject
= nextWindow
->GetOrCreateAccessible();
2356 case wxNAVDIR_PREVIOUS
:
2358 wxWindowList::compatibility_iterator node
=
2359 wxWindowList::compatibility_iterator();
2362 // Can't navigate to sibling of this window
2363 // if we're a top-level window.
2364 if (!GetWindow()->GetParent())
2365 return wxACC_NOT_IMPLEMENTED
;
2367 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2371 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2372 node
= GetWindow()->GetChildren().Item(fromId
-1);
2375 if (node
&& node
->GetPrevious())
2377 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2378 *toObject
= previousWindow
->GetOrCreateAccessible();
2386 return wxACC_NOT_IMPLEMENTED
;
2389 // Gets the name of the specified object.
2390 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2392 wxASSERT( GetWindow() != NULL
);
2398 // If a child, leave wxWindows to call the function on the actual
2401 return wxACC_NOT_IMPLEMENTED
;
2403 // This will eventually be replaced by specialised
2404 // accessible classes, one for each kind of wxWindows
2405 // control or window.
2406 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2407 title
= ((wxButton
*) GetWindow())->GetLabel();
2409 title
= GetWindow()->GetName();
2411 if (!title
.IsEmpty())
2417 return wxACC_NOT_IMPLEMENTED
;
2420 // Gets the number of children.
2421 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2423 wxASSERT( GetWindow() != NULL
);
2427 *childId
= (int) GetWindow()->GetChildren().GetCount();
2431 // Gets the specified child (starting from 1).
2432 // If *child is NULL and return value is wxACC_OK,
2433 // this means that the child is a simple element and
2434 // not an accessible object.
2435 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2437 wxASSERT( GetWindow() != NULL
);
2447 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2450 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2451 *child
= childWindow
->GetOrCreateAccessible();
2458 // Gets the parent, or NULL.
2459 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2461 wxASSERT( GetWindow() != NULL
);
2465 wxWindow
* parentWindow
= GetWindow()->GetParent();
2473 *parent
= parentWindow
->GetOrCreateAccessible();
2481 // Performs the default action. childId is 0 (the action for this object)
2482 // or > 0 (the action for a child).
2483 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2484 // window (e.g. an edit control).
2485 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
2487 wxASSERT( GetWindow() != NULL
);
2491 return wxACC_NOT_IMPLEMENTED
;
2494 // Gets the default action for this object (0) or > 0 (the action for a child).
2495 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2496 // string if there is no action.
2497 // The retrieved string describes the action that is performed on an object,
2498 // not what the object does as a result. For example, a toolbar button that prints
2499 // a document has a default action of "Press" rather than "Prints the current document."
2500 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
2502 wxASSERT( GetWindow() != NULL
);
2506 return wxACC_NOT_IMPLEMENTED
;
2509 // Returns the description for this object or a child.
2510 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
2512 wxASSERT( GetWindow() != NULL
);
2516 wxString
ht(GetWindow()->GetHelpText());
2522 return wxACC_NOT_IMPLEMENTED
;
2525 // Returns help text for this object or a child, similar to tooltip text.
2526 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
2528 wxASSERT( GetWindow() != NULL
);
2532 wxString
ht(GetWindow()->GetHelpText());
2538 return wxACC_NOT_IMPLEMENTED
;
2541 // Returns the keyboard shortcut for this object or child.
2542 // Return e.g. ALT+K
2543 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
2545 wxASSERT( GetWindow() != NULL
);
2549 return wxACC_NOT_IMPLEMENTED
;
2552 // Returns a role constant.
2553 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
2555 wxASSERT( GetWindow() != NULL
);
2559 // If a child, leave wxWindows to call the function on the actual
2562 return wxACC_NOT_IMPLEMENTED
;
2564 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2565 return wxACC_NOT_IMPLEMENTED
;
2567 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2568 return wxACC_NOT_IMPLEMENTED
;
2571 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2572 return wxACC_NOT_IMPLEMENTED
;
2575 //*role = wxROLE_SYSTEM_CLIENT;
2576 *role
= wxROLE_SYSTEM_CLIENT
;
2580 return wxACC_NOT_IMPLEMENTED
;
2584 // Returns a state constant.
2585 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
2587 wxASSERT( GetWindow() != NULL
);
2591 // If a child, leave wxWindows to call the function on the actual
2594 return wxACC_NOT_IMPLEMENTED
;
2596 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2597 return wxACC_NOT_IMPLEMENTED
;
2600 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2601 return wxACC_NOT_IMPLEMENTED
;
2604 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2605 return wxACC_NOT_IMPLEMENTED
;
2612 return wxACC_NOT_IMPLEMENTED
;
2616 // Returns a localized string representing the value for the object
2618 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
2620 wxASSERT( GetWindow() != NULL
);
2624 return wxACC_NOT_IMPLEMENTED
;
2627 // Selects the object or child.
2628 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
2630 wxASSERT( GetWindow() != NULL
);
2634 return wxACC_NOT_IMPLEMENTED
;
2637 // Gets the window with the keyboard focus.
2638 // If childId is 0 and child is NULL, no object in
2639 // this subhierarchy has the focus.
2640 // If this object has the focus, child should be 'this'.
2641 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
2643 wxASSERT( GetWindow() != NULL
);
2647 return wxACC_NOT_IMPLEMENTED
;
2650 // Gets a variant representing the selected children
2652 // Acceptable values:
2653 // - a null variant (IsNull() returns TRUE)
2654 // - a list variant (GetType() == wxT("list")
2655 // - an integer representing the selected child element,
2656 // or 0 if this object is selected (GetType() == wxT("long")
2657 // - a "void*" pointer to a wxAccessible child object
2658 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
2660 wxASSERT( GetWindow() != NULL
);
2664 return wxACC_NOT_IMPLEMENTED
;
2667 #endif // wxUSE_ACCESSIBILITY