1 /////////////////////////////////////////////////////////////////////////////
2 // Name: common/window.cpp
3 // Purpose: common (to all ports) wxWindow functions
4 // Author: Julian Smart, Vadim Zeitlin
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "windowbase.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
32 #include "wx/string.h"
37 #include "wx/window.h"
38 #include "wx/control.h"
39 #include "wx/checkbox.h"
40 #include "wx/radiobut.h"
41 #include "wx/statbox.h"
42 #include "wx/textctrl.h"
43 #include "wx/settings.h"
44 #include "wx/dialog.h"
45 #include "wx/msgdlg.h"
46 #include "wx/statusbr.h"
47 #include "wx/dcclient.h"
51 #include "wx/layout.h"
52 #endif // wxUSE_CONSTRAINTS
56 #if wxUSE_DRAG_AND_DROP
58 #endif // wxUSE_DRAG_AND_DROP
60 #if wxUSE_ACCESSIBILITY
61 #include "wx/access.h"
65 #include "wx/cshelp.h"
69 #include "wx/tooltip.h"
70 #endif // wxUSE_TOOLTIPS
76 // ----------------------------------------------------------------------------
78 // ----------------------------------------------------------------------------
81 int wxWindowBase::ms_lastControlId
= 2000;
83 int wxWindowBase::ms_lastControlId
= -200;
86 IMPLEMENT_ABSTRACT_CLASS(wxWindowBase
, wxEvtHandler
)
88 // ----------------------------------------------------------------------------
90 // ----------------------------------------------------------------------------
92 BEGIN_EVENT_TABLE(wxWindowBase
, wxEvtHandler
)
93 EVT_SYS_COLOUR_CHANGED(wxWindowBase::OnSysColourChanged
)
94 EVT_INIT_DIALOG(wxWindowBase::OnInitDialog
)
95 EVT_MIDDLE_DOWN(wxWindowBase::OnMiddleClick
)
98 EVT_HELP(wxID_ANY
, wxWindowBase::OnHelp
)
103 // ============================================================================
104 // implementation of the common functionality of the wxWindow class
105 // ============================================================================
107 // ----------------------------------------------------------------------------
109 // ----------------------------------------------------------------------------
111 // the default initialization
112 wxWindowBase::wxWindowBase()
114 // no window yet, no parent nor children
115 m_parent
= (wxWindow
*)NULL
;
116 m_windowId
= wxID_ANY
;
118 // no constraints on the minimal window size
124 // window is created enabled but it's not visible yet
128 // the default event handler is just this window
129 m_eventHandler
= this;
133 m_windowValidator
= (wxValidator
*) NULL
;
134 #endif // wxUSE_VALIDATORS
136 // use the system default colours
137 m_backgroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
);
138 m_foregroundColour
= wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT
);
140 // don't set the font here for wxMSW as we don't call WM_SETFONT here and
141 // so the font is *not* really set - but calls to SetFont() later won't do
142 // anything because m_font appears to be already set!
144 m_font
= wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
147 // the colours/fonts are default for now
152 m_isBeingDeleted
= false;
158 #if wxUSE_CONSTRAINTS
159 // no constraints whatsoever
160 m_constraints
= (wxLayoutConstraints
*) NULL
;
161 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
162 #endif // wxUSE_CONSTRAINTS
164 m_windowSizer
= (wxSizer
*) NULL
;
165 m_containingSizer
= (wxSizer
*) NULL
;
166 m_autoLayout
= false;
168 #if wxUSE_DRAG_AND_DROP
169 m_dropTarget
= (wxDropTarget
*)NULL
;
170 #endif // wxUSE_DRAG_AND_DROP
173 m_tooltip
= (wxToolTip
*)NULL
;
174 #endif // wxUSE_TOOLTIPS
177 m_caret
= (wxCaret
*)NULL
;
178 #endif // wxUSE_CARET
181 m_hasCustomPalette
= false;
182 #endif // wxUSE_PALETTE
184 #if wxUSE_ACCESSIBILITY
188 m_virtualSize
= wxDefaultSize
;
193 m_maxVirtualHeight
= -1;
195 m_windowVariant
= wxWINDOW_VARIANT_DEFAULT
;
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 ) ;
654 case wxWINDOW_VARIANT_DEFAULT
:
657 wxFAIL_MSG(_T("unexpected window variant"));
663 void wxWindowBase::SetVirtualSizeHints( int minW
, int minH
,
666 m_minVirtualWidth
= minW
;
667 m_maxVirtualWidth
= maxW
;
668 m_minVirtualHeight
= minH
;
669 m_maxVirtualHeight
= maxH
;
672 void wxWindowBase::DoSetVirtualSize( int x
, int y
)
674 if ( m_minVirtualWidth
!= -1 && m_minVirtualWidth
> x
)
675 x
= m_minVirtualWidth
;
676 if ( m_maxVirtualWidth
!= -1 && m_maxVirtualWidth
< x
)
677 x
= m_maxVirtualWidth
;
678 if ( m_minVirtualHeight
!= -1 && m_minVirtualHeight
> y
)
679 y
= m_minVirtualHeight
;
680 if ( m_maxVirtualHeight
!= -1 && m_maxVirtualHeight
< y
)
681 y
= m_maxVirtualHeight
;
683 m_virtualSize
= wxSize(x
, y
);
686 wxSize
wxWindowBase::DoGetVirtualSize() const
688 wxSize
s( GetClientSize() );
690 return wxSize( wxMax( m_virtualSize
.GetWidth(), s
.GetWidth() ),
691 wxMax( m_virtualSize
.GetHeight(), s
.GetHeight() ) );
694 // ----------------------------------------------------------------------------
695 // show/hide/enable/disable the window
696 // ----------------------------------------------------------------------------
698 bool wxWindowBase::Show(bool show
)
700 if ( show
!= m_isShown
)
712 bool wxWindowBase::Enable(bool enable
)
714 if ( enable
!= m_isEnabled
)
716 m_isEnabled
= enable
;
725 // ----------------------------------------------------------------------------
727 // ----------------------------------------------------------------------------
729 bool wxWindowBase::IsTopLevel() const
734 // ----------------------------------------------------------------------------
735 // reparenting the window
736 // ----------------------------------------------------------------------------
738 void wxWindowBase::AddChild(wxWindowBase
*child
)
740 wxCHECK_RET( child
, wxT("can't add a NULL child") );
742 // this should never happen and it will lead to a crash later if it does
743 // because RemoveChild() will remove only one node from the children list
744 // and the other(s) one(s) will be left with dangling pointers in them
745 wxASSERT_MSG( !GetChildren().Find((wxWindow
*)child
), _T("AddChild() called twice") );
747 GetChildren().Append((wxWindow
*)child
);
748 child
->SetParent(this);
751 void wxWindowBase::RemoveChild(wxWindowBase
*child
)
753 wxCHECK_RET( child
, wxT("can't remove a NULL child") );
755 GetChildren().DeleteObject((wxWindow
*)child
);
756 child
->SetParent(NULL
);
759 bool wxWindowBase::Reparent(wxWindowBase
*newParent
)
761 wxWindow
*oldParent
= GetParent();
762 if ( newParent
== oldParent
)
768 // unlink this window from the existing parent.
771 oldParent
->RemoveChild(this);
775 wxTopLevelWindows
.DeleteObject((wxWindow
*)this);
778 // add it to the new one
781 newParent
->AddChild(this);
785 wxTopLevelWindows
.Append((wxWindow
*)this);
791 // ----------------------------------------------------------------------------
792 // event handler stuff
793 // ----------------------------------------------------------------------------
795 void wxWindowBase::PushEventHandler(wxEvtHandler
*handler
)
797 wxEvtHandler
*handlerOld
= GetEventHandler();
799 handler
->SetNextHandler(handlerOld
);
802 GetEventHandler()->SetPreviousHandler(handler
);
804 SetEventHandler(handler
);
807 wxEvtHandler
*wxWindowBase::PopEventHandler(bool deleteHandler
)
809 wxEvtHandler
*handlerA
= GetEventHandler();
812 wxEvtHandler
*handlerB
= handlerA
->GetNextHandler();
813 handlerA
->SetNextHandler((wxEvtHandler
*)NULL
);
816 handlerB
->SetPreviousHandler((wxEvtHandler
*)NULL
);
817 SetEventHandler(handlerB
);
822 handlerA
= (wxEvtHandler
*)NULL
;
829 bool wxWindowBase::RemoveEventHandler(wxEvtHandler
*handler
)
831 wxCHECK_MSG( handler
, false, _T("RemoveEventHandler(NULL) called") );
833 wxEvtHandler
*handlerPrev
= NULL
,
834 *handlerCur
= GetEventHandler();
837 wxEvtHandler
*handlerNext
= handlerCur
->GetNextHandler();
839 if ( handlerCur
== handler
)
843 handlerPrev
->SetNextHandler(handlerNext
);
847 SetEventHandler(handlerNext
);
852 handlerNext
->SetPreviousHandler ( handlerPrev
);
855 handler
->SetNextHandler(NULL
);
856 handler
->SetPreviousHandler(NULL
);
861 handlerPrev
= handlerCur
;
862 handlerCur
= handlerNext
;
865 wxFAIL_MSG( _T("where has the event handler gone?") );
870 // ----------------------------------------------------------------------------
872 // ----------------------------------------------------------------------------
874 bool wxWindowBase::SetBackgroundColour( const wxColour
&colour
)
876 if ( !colour
.Ok() || (colour
== m_backgroundColour
) )
879 m_backgroundColour
= colour
;
886 bool wxWindowBase::SetForegroundColour( const wxColour
&colour
)
888 if ( !colour
.Ok() || (colour
== m_foregroundColour
) )
891 m_foregroundColour
= colour
;
898 bool wxWindowBase::SetCursor(const wxCursor
& cursor
)
900 // setting an invalid cursor is ok, it means that we don't have any special
902 if ( m_cursor
== cursor
)
913 bool wxWindowBase::SetFont(const wxFont
& font
)
915 // don't try to set invalid font, always fall back to the default
916 const wxFont
& fontOk
= font
.Ok() ? font
: *wxSWISS_FONT
;
918 if ( fontOk
== m_font
)
933 void wxWindowBase::SetPalette(const wxPalette
& pal
)
935 m_hasCustomPalette
= true;
938 // VZ: can anyone explain me what do we do here?
939 wxWindowDC
d((wxWindow
*) this);
943 wxWindow
*wxWindowBase::GetAncestorWithCustomPalette() const
945 wxWindow
*win
= (wxWindow
*)this;
946 while ( win
&& !win
->HasCustomPalette() )
948 win
= win
->GetParent();
954 #endif // wxUSE_PALETTE
957 void wxWindowBase::SetCaret(wxCaret
*caret
)
968 wxASSERT_MSG( m_caret
->GetWindow() == this,
969 wxT("caret should be created associated to this window") );
972 #endif // wxUSE_CARET
975 // ----------------------------------------------------------------------------
977 // ----------------------------------------------------------------------------
979 void wxWindowBase::SetValidator(const wxValidator
& validator
)
981 if ( m_windowValidator
)
982 delete m_windowValidator
;
984 m_windowValidator
= (wxValidator
*)validator
.Clone();
986 if ( m_windowValidator
)
987 m_windowValidator
->SetWindow(this) ;
989 #endif // wxUSE_VALIDATORS
991 // ----------------------------------------------------------------------------
992 // update region stuff
993 // ----------------------------------------------------------------------------
995 wxRect
wxWindowBase::GetUpdateClientRect() const
997 wxRegion rgnUpdate
= GetUpdateRegion();
998 rgnUpdate
.Intersect(GetClientRect());
999 wxRect rectUpdate
= rgnUpdate
.GetBox();
1000 wxPoint ptOrigin
= GetClientAreaOrigin();
1001 rectUpdate
.x
-= ptOrigin
.x
;
1002 rectUpdate
.y
-= ptOrigin
.y
;
1007 bool wxWindowBase::IsExposed(int x
, int y
) const
1009 return m_updateRegion
.Contains(x
, y
) != wxOutRegion
;
1012 bool wxWindowBase::IsExposed(int x
, int y
, int w
, int h
) const
1014 return m_updateRegion
.Contains(x
, y
, w
, h
) != wxOutRegion
;
1017 void wxWindowBase::ClearBackground()
1019 // wxGTK uses its own version, no need to add never used code
1021 wxClientDC
dc((wxWindow
*)this);
1022 wxBrush
brush(GetBackgroundColour(), wxSOLID
);
1023 dc
.SetBackground(brush
);
1028 // ----------------------------------------------------------------------------
1029 // find child window by id or name
1030 // ----------------------------------------------------------------------------
1032 wxWindow
*wxWindowBase::FindWindow( long id
)
1034 if ( id
== m_windowId
)
1035 return (wxWindow
*)this;
1037 wxWindowBase
*res
= (wxWindow
*)NULL
;
1038 wxWindowList::compatibility_iterator node
;
1039 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1041 wxWindowBase
*child
= node
->GetData();
1042 res
= child
->FindWindow( id
);
1045 return (wxWindow
*)res
;
1048 wxWindow
*wxWindowBase::FindWindow( const wxString
& name
)
1050 if ( name
== m_windowName
)
1051 return (wxWindow
*)this;
1053 wxWindowBase
*res
= (wxWindow
*)NULL
;
1054 wxWindowList::compatibility_iterator node
;
1055 for ( node
= m_children
.GetFirst(); node
&& !res
; node
= node
->GetNext() )
1057 wxWindow
*child
= node
->GetData();
1058 res
= child
->FindWindow(name
);
1061 return (wxWindow
*)res
;
1065 // find any window by id or name or label: If parent is non-NULL, look through
1066 // children for a label or title matching the specified string. If NULL, look
1067 // through all top-level windows.
1069 // to avoid duplicating code we reuse the same helper function but with
1070 // different comparators
1072 typedef bool (*wxFindWindowCmp
)(const wxWindow
*win
,
1073 const wxString
& label
, long id
);
1076 bool wxFindWindowCmpLabels(const wxWindow
*win
, const wxString
& label
,
1079 return win
->GetLabel() == label
;
1083 bool wxFindWindowCmpNames(const wxWindow
*win
, const wxString
& label
,
1086 return win
->GetName() == label
;
1090 bool wxFindWindowCmpIds(const wxWindow
*win
, const wxString
& WXUNUSED(label
),
1093 return win
->GetId() == id
;
1096 // recursive helper for the FindWindowByXXX() functions
1098 wxWindow
*wxFindWindowRecursively(const wxWindow
*parent
,
1099 const wxString
& label
,
1101 wxFindWindowCmp cmp
)
1105 // see if this is the one we're looking for
1106 if ( (*cmp
)(parent
, label
, id
) )
1107 return (wxWindow
*)parent
;
1109 // It wasn't, so check all its children
1110 for ( wxWindowList::compatibility_iterator node
= parent
->GetChildren().GetFirst();
1112 node
= node
->GetNext() )
1114 // recursively check each child
1115 wxWindow
*win
= (wxWindow
*)node
->GetData();
1116 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1126 // helper for FindWindowByXXX()
1128 wxWindow
*wxFindWindowHelper(const wxWindow
*parent
,
1129 const wxString
& label
,
1131 wxFindWindowCmp cmp
)
1135 // just check parent and all its children
1136 return wxFindWindowRecursively(parent
, label
, id
, cmp
);
1139 // start at very top of wx's windows
1140 for ( wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1142 node
= node
->GetNext() )
1144 // recursively check each window & its children
1145 wxWindow
*win
= node
->GetData();
1146 wxWindow
*retwin
= wxFindWindowRecursively(win
, label
, id
, cmp
);
1156 wxWindowBase::FindWindowByLabel(const wxString
& title
, const wxWindow
*parent
)
1158 return wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpLabels
);
1163 wxWindowBase::FindWindowByName(const wxString
& title
, const wxWindow
*parent
)
1165 wxWindow
*win
= wxFindWindowHelper(parent
, title
, 0, wxFindWindowCmpNames
);
1169 // fall back to the label
1170 win
= FindWindowByLabel(title
, parent
);
1178 wxWindowBase::FindWindowById( long id
, const wxWindow
* parent
)
1180 return wxFindWindowHelper(parent
, _T(""), id
, wxFindWindowCmpIds
);
1183 // ----------------------------------------------------------------------------
1184 // dialog oriented functions
1185 // ----------------------------------------------------------------------------
1187 void wxWindowBase::MakeModal(bool modal
)
1189 // Disable all other windows
1192 wxWindowList::compatibility_iterator node
= wxTopLevelWindows
.GetFirst();
1195 wxWindow
*win
= node
->GetData();
1197 win
->Enable(!modal
);
1199 node
= node
->GetNext();
1204 bool wxWindowBase::Validate()
1206 #if wxUSE_VALIDATORS
1207 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1209 wxWindowList::compatibility_iterator node
;
1210 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1212 wxWindowBase
*child
= node
->GetData();
1213 wxValidator
*validator
= child
->GetValidator();
1214 if ( validator
&& !validator
->Validate((wxWindow
*)this) )
1219 if ( recurse
&& !child
->Validate() )
1224 #endif // wxUSE_VALIDATORS
1229 bool wxWindowBase::TransferDataToWindow()
1231 #if wxUSE_VALIDATORS
1232 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1234 wxWindowList::compatibility_iterator node
;
1235 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1237 wxWindowBase
*child
= node
->GetData();
1238 wxValidator
*validator
= child
->GetValidator();
1239 if ( validator
&& !validator
->TransferToWindow() )
1241 wxLogWarning(_("Could not transfer data to window"));
1243 wxLog::FlushActive();
1251 if ( !child
->TransferDataToWindow() )
1253 // warning already given
1258 #endif // wxUSE_VALIDATORS
1263 bool wxWindowBase::TransferDataFromWindow()
1265 #if wxUSE_VALIDATORS
1266 bool recurse
= (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY
) != 0;
1268 wxWindowList::compatibility_iterator node
;
1269 for ( node
= m_children
.GetFirst(); node
; node
= node
->GetNext() )
1271 wxWindow
*child
= node
->GetData();
1272 wxValidator
*validator
= child
->GetValidator();
1273 if ( validator
&& !validator
->TransferFromWindow() )
1275 // nop warning here because the application is supposed to give
1276 // one itself - we don't know here what might have gone wrongly
1283 if ( !child
->TransferDataFromWindow() )
1285 // warning already given
1290 #endif // wxUSE_VALIDATORS
1295 void wxWindowBase::InitDialog()
1297 wxInitDialogEvent
event(GetId());
1298 event
.SetEventObject( this );
1299 GetEventHandler()->ProcessEvent(event
);
1302 // ----------------------------------------------------------------------------
1303 // context-sensitive help support
1304 // ----------------------------------------------------------------------------
1308 // associate this help text with this window
1309 void wxWindowBase::SetHelpText(const wxString
& text
)
1311 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1314 helpProvider
->AddHelp(this, text
);
1318 // associate this help text with all windows with the same id as this
1320 void wxWindowBase::SetHelpTextForId(const wxString
& text
)
1322 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1325 helpProvider
->AddHelp(GetId(), text
);
1329 // get the help string associated with this window (may be empty)
1330 wxString
wxWindowBase::GetHelpText() const
1333 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1336 text
= helpProvider
->GetHelp(this);
1342 // show help for this window
1343 void wxWindowBase::OnHelp(wxHelpEvent
& event
)
1345 wxHelpProvider
*helpProvider
= wxHelpProvider::Get();
1348 if ( helpProvider
->ShowHelp(this) )
1350 // skip the event.Skip() below
1358 #endif // wxUSE_HELP
1360 // ----------------------------------------------------------------------------
1361 // tooltipsroot.Replace("\\", "/");
1362 // ----------------------------------------------------------------------------
1366 void wxWindowBase::SetToolTip( const wxString
&tip
)
1368 // don't create the new tooltip if we already have one
1371 m_tooltip
->SetTip( tip
);
1375 SetToolTip( new wxToolTip( tip
) );
1378 // setting empty tooltip text does not remove the tooltip any more - use
1379 // SetToolTip((wxToolTip *)NULL) for this
1382 void wxWindowBase::DoSetToolTip(wxToolTip
*tooltip
)
1387 m_tooltip
= tooltip
;
1390 #endif // wxUSE_TOOLTIPS
1392 // ----------------------------------------------------------------------------
1393 // constraints and sizers
1394 // ----------------------------------------------------------------------------
1396 #if wxUSE_CONSTRAINTS
1398 void wxWindowBase::SetConstraints( wxLayoutConstraints
*constraints
)
1400 if ( m_constraints
)
1402 UnsetConstraints(m_constraints
);
1403 delete m_constraints
;
1405 m_constraints
= constraints
;
1406 if ( m_constraints
)
1408 // Make sure other windows know they're part of a 'meaningful relationship'
1409 if ( m_constraints
->left
.GetOtherWindow() && (m_constraints
->left
.GetOtherWindow() != this) )
1410 m_constraints
->left
.GetOtherWindow()->AddConstraintReference(this);
1411 if ( m_constraints
->top
.GetOtherWindow() && (m_constraints
->top
.GetOtherWindow() != this) )
1412 m_constraints
->top
.GetOtherWindow()->AddConstraintReference(this);
1413 if ( m_constraints
->right
.GetOtherWindow() && (m_constraints
->right
.GetOtherWindow() != this) )
1414 m_constraints
->right
.GetOtherWindow()->AddConstraintReference(this);
1415 if ( m_constraints
->bottom
.GetOtherWindow() && (m_constraints
->bottom
.GetOtherWindow() != this) )
1416 m_constraints
->bottom
.GetOtherWindow()->AddConstraintReference(this);
1417 if ( m_constraints
->width
.GetOtherWindow() && (m_constraints
->width
.GetOtherWindow() != this) )
1418 m_constraints
->width
.GetOtherWindow()->AddConstraintReference(this);
1419 if ( m_constraints
->height
.GetOtherWindow() && (m_constraints
->height
.GetOtherWindow() != this) )
1420 m_constraints
->height
.GetOtherWindow()->AddConstraintReference(this);
1421 if ( m_constraints
->centreX
.GetOtherWindow() && (m_constraints
->centreX
.GetOtherWindow() != this) )
1422 m_constraints
->centreX
.GetOtherWindow()->AddConstraintReference(this);
1423 if ( m_constraints
->centreY
.GetOtherWindow() && (m_constraints
->centreY
.GetOtherWindow() != this) )
1424 m_constraints
->centreY
.GetOtherWindow()->AddConstraintReference(this);
1428 // This removes any dangling pointers to this window in other windows'
1429 // constraintsInvolvedIn lists.
1430 void wxWindowBase::UnsetConstraints(wxLayoutConstraints
*c
)
1434 if ( c
->left
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1435 c
->left
.GetOtherWindow()->RemoveConstraintReference(this);
1436 if ( c
->top
.GetOtherWindow() && (c
->top
.GetOtherWindow() != this) )
1437 c
->top
.GetOtherWindow()->RemoveConstraintReference(this);
1438 if ( c
->right
.GetOtherWindow() && (c
->right
.GetOtherWindow() != this) )
1439 c
->right
.GetOtherWindow()->RemoveConstraintReference(this);
1440 if ( c
->bottom
.GetOtherWindow() && (c
->bottom
.GetOtherWindow() != this) )
1441 c
->bottom
.GetOtherWindow()->RemoveConstraintReference(this);
1442 if ( c
->width
.GetOtherWindow() && (c
->width
.GetOtherWindow() != this) )
1443 c
->width
.GetOtherWindow()->RemoveConstraintReference(this);
1444 if ( c
->height
.GetOtherWindow() && (c
->height
.GetOtherWindow() != this) )
1445 c
->height
.GetOtherWindow()->RemoveConstraintReference(this);
1446 if ( c
->centreX
.GetOtherWindow() && (c
->centreX
.GetOtherWindow() != this) )
1447 c
->centreX
.GetOtherWindow()->RemoveConstraintReference(this);
1448 if ( c
->centreY
.GetOtherWindow() && (c
->centreY
.GetOtherWindow() != this) )
1449 c
->centreY
.GetOtherWindow()->RemoveConstraintReference(this);
1453 // Back-pointer to other windows we're involved with, so if we delete this
1454 // window, we must delete any constraints we're involved with.
1455 void wxWindowBase::AddConstraintReference(wxWindowBase
*otherWin
)
1457 if ( !m_constraintsInvolvedIn
)
1458 m_constraintsInvolvedIn
= new wxWindowList
;
1459 if ( !m_constraintsInvolvedIn
->Find((wxWindow
*)otherWin
) )
1460 m_constraintsInvolvedIn
->Append((wxWindow
*)otherWin
);
1463 // REMOVE back-pointer to other windows we're involved with.
1464 void wxWindowBase::RemoveConstraintReference(wxWindowBase
*otherWin
)
1466 if ( m_constraintsInvolvedIn
)
1467 m_constraintsInvolvedIn
->DeleteObject((wxWindow
*)otherWin
);
1470 // Reset any constraints that mention this window
1471 void wxWindowBase::DeleteRelatedConstraints()
1473 if ( m_constraintsInvolvedIn
)
1475 wxWindowList::compatibility_iterator node
= m_constraintsInvolvedIn
->GetFirst();
1478 wxWindow
*win
= node
->GetData();
1479 wxLayoutConstraints
*constr
= win
->GetConstraints();
1481 // Reset any constraints involving this window
1484 constr
->left
.ResetIfWin(this);
1485 constr
->top
.ResetIfWin(this);
1486 constr
->right
.ResetIfWin(this);
1487 constr
->bottom
.ResetIfWin(this);
1488 constr
->width
.ResetIfWin(this);
1489 constr
->height
.ResetIfWin(this);
1490 constr
->centreX
.ResetIfWin(this);
1491 constr
->centreY
.ResetIfWin(this);
1494 wxWindowList::compatibility_iterator next
= node
->GetNext();
1495 m_constraintsInvolvedIn
->Erase(node
);
1499 delete m_constraintsInvolvedIn
;
1500 m_constraintsInvolvedIn
= (wxWindowList
*) NULL
;
1504 #endif // wxUSE_CONSTRAINTS
1506 void wxWindowBase::SetSizer(wxSizer
*sizer
, bool deleteOld
)
1508 if ( sizer
== m_windowSizer
)
1512 delete m_windowSizer
;
1514 m_windowSizer
= sizer
;
1516 SetAutoLayout( sizer
!= NULL
);
1519 void wxWindowBase::SetSizerAndFit(wxSizer
*sizer
, bool deleteOld
)
1521 SetSizer( sizer
, deleteOld
);
1522 sizer
->SetSizeHints( (wxWindow
*) this );
1525 #if wxUSE_CONSTRAINTS
1527 void wxWindowBase::SatisfyConstraints()
1529 wxLayoutConstraints
*constr
= GetConstraints();
1530 bool wasOk
= constr
&& constr
->AreSatisfied();
1532 ResetConstraints(); // Mark all constraints as unevaluated
1536 // if we're a top level panel (i.e. our parent is frame/dialog), our
1537 // own constraints will never be satisfied any more unless we do it
1541 while ( noChanges
> 0 )
1543 LayoutPhase1(&noChanges
);
1547 LayoutPhase2(&noChanges
);
1550 #endif // wxUSE_CONSTRAINTS
1552 bool wxWindowBase::Layout()
1554 // If there is a sizer, use it instead of the constraints
1558 GetVirtualSize(&w
, &h
);
1559 GetSizer()->SetDimension( 0, 0, w
, h
);
1561 #if wxUSE_CONSTRAINTS
1564 SatisfyConstraints(); // Find the right constraints values
1565 SetConstraintSizes(); // Recursively set the real window sizes
1572 #if wxUSE_CONSTRAINTS
1574 // first phase of the constraints evaluation: set our own constraints
1575 bool wxWindowBase::LayoutPhase1(int *noChanges
)
1577 wxLayoutConstraints
*constr
= GetConstraints();
1579 return !constr
|| constr
->SatisfyConstraints(this, noChanges
);
1582 // second phase: set the constraints for our children
1583 bool wxWindowBase::LayoutPhase2(int *noChanges
)
1590 // Layout grand children
1596 // Do a phase of evaluating child constraints
1597 bool wxWindowBase::DoPhase(int phase
)
1599 // the list containing the children for which the constraints are already
1601 wxWindowList succeeded
;
1603 // the max number of iterations we loop before concluding that we can't set
1605 static const int maxIterations
= 500;
1607 for ( int noIterations
= 0; noIterations
< maxIterations
; noIterations
++ )
1611 // loop over all children setting their constraints
1612 for ( wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1614 node
= node
->GetNext() )
1616 wxWindow
*child
= node
->GetData();
1617 if ( child
->IsTopLevel() )
1619 // top level children are not inside our client area
1623 if ( !child
->GetConstraints() || succeeded
.Find(child
) )
1625 // this one is either already ok or nothing we can do about it
1629 int tempNoChanges
= 0;
1630 bool success
= phase
== 1 ? child
->LayoutPhase1(&tempNoChanges
)
1631 : child
->LayoutPhase2(&tempNoChanges
);
1632 noChanges
+= tempNoChanges
;
1636 succeeded
.Append(child
);
1642 // constraints are set
1650 void wxWindowBase::ResetConstraints()
1652 wxLayoutConstraints
*constr
= GetConstraints();
1655 constr
->left
.SetDone(false);
1656 constr
->top
.SetDone(false);
1657 constr
->right
.SetDone(false);
1658 constr
->bottom
.SetDone(false);
1659 constr
->width
.SetDone(false);
1660 constr
->height
.SetDone(false);
1661 constr
->centreX
.SetDone(false);
1662 constr
->centreY
.SetDone(false);
1665 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1668 wxWindow
*win
= node
->GetData();
1669 if ( !win
->IsTopLevel() )
1670 win
->ResetConstraints();
1671 node
= node
->GetNext();
1675 // Need to distinguish between setting the 'fake' size for windows and sizers,
1676 // and setting the real values.
1677 void wxWindowBase::SetConstraintSizes(bool recurse
)
1679 wxLayoutConstraints
*constr
= GetConstraints();
1680 if ( constr
&& constr
->AreSatisfied() )
1682 int x
= constr
->left
.GetValue();
1683 int y
= constr
->top
.GetValue();
1684 int w
= constr
->width
.GetValue();
1685 int h
= constr
->height
.GetValue();
1687 if ( (constr
->width
.GetRelationship() != wxAsIs
) ||
1688 (constr
->height
.GetRelationship() != wxAsIs
) )
1690 SetSize(x
, y
, w
, h
);
1694 // If we don't want to resize this window, just move it...
1700 wxLogDebug(wxT("Constraints not satisfied for %s named '%s'."),
1701 GetClassInfo()->GetClassName(),
1707 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1710 wxWindow
*win
= node
->GetData();
1711 if ( !win
->IsTopLevel() && win
->GetConstraints() )
1712 win
->SetConstraintSizes();
1713 node
= node
->GetNext();
1718 // Only set the size/position of the constraint (if any)
1719 void wxWindowBase::SetSizeConstraint(int x
, int y
, int w
, int h
)
1721 wxLayoutConstraints
*constr
= GetConstraints();
1726 constr
->left
.SetValue(x
);
1727 constr
->left
.SetDone(true);
1731 constr
->top
.SetValue(y
);
1732 constr
->top
.SetDone(true);
1736 constr
->width
.SetValue(w
);
1737 constr
->width
.SetDone(true);
1741 constr
->height
.SetValue(h
);
1742 constr
->height
.SetDone(true);
1747 void wxWindowBase::MoveConstraint(int x
, int y
)
1749 wxLayoutConstraints
*constr
= GetConstraints();
1754 constr
->left
.SetValue(x
);
1755 constr
->left
.SetDone(true);
1759 constr
->top
.SetValue(y
);
1760 constr
->top
.SetDone(true);
1765 void wxWindowBase::GetSizeConstraint(int *w
, int *h
) const
1767 wxLayoutConstraints
*constr
= GetConstraints();
1770 *w
= constr
->width
.GetValue();
1771 *h
= constr
->height
.GetValue();
1777 void wxWindowBase::GetClientSizeConstraint(int *w
, int *h
) const
1779 wxLayoutConstraints
*constr
= GetConstraints();
1782 *w
= constr
->width
.GetValue();
1783 *h
= constr
->height
.GetValue();
1786 GetClientSize(w
, h
);
1789 void wxWindowBase::GetPositionConstraint(int *x
, int *y
) const
1791 wxLayoutConstraints
*constr
= GetConstraints();
1794 *x
= constr
->left
.GetValue();
1795 *y
= constr
->top
.GetValue();
1801 #endif // wxUSE_CONSTRAINTS
1803 void wxWindowBase::AdjustForParentClientOrigin(int& x
, int& y
, int sizeFlags
) const
1805 // don't do it for the dialogs/frames - they float independently of their
1807 if ( !IsTopLevel() )
1809 wxWindow
*parent
= GetParent();
1810 if ( !(sizeFlags
& wxSIZE_NO_ADJUSTMENTS
) && parent
)
1812 wxPoint
pt(parent
->GetClientAreaOrigin());
1819 // ----------------------------------------------------------------------------
1820 // do Update UI processing for child controls
1821 // ----------------------------------------------------------------------------
1823 void wxWindowBase::UpdateWindowUI(long flags
)
1825 wxUpdateUIEvent
event(GetId());
1826 event
.m_eventObject
= this;
1828 if ( GetEventHandler()->ProcessEvent(event
) )
1830 DoUpdateWindowUI(event
);
1833 if (flags
& wxUPDATE_UI_RECURSE
)
1835 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1838 wxWindow
* child
= (wxWindow
*) node
->GetData();
1839 child
->UpdateWindowUI(flags
);
1840 node
= node
->GetNext();
1845 // do the window-specific processing after processing the update event
1846 // TODO: take specific knowledge out of this function and
1847 // put in each control's base class. Unfortunately we don't
1848 // yet have base implementation files for wxCheckBox and wxRadioButton.
1849 void wxWindowBase::DoUpdateWindowUI(wxUpdateUIEvent
& event
)
1851 if ( event
.GetSetEnabled() )
1852 Enable(event
.GetEnabled());
1855 if ( event
.GetSetText() )
1857 wxControl
*control
= wxDynamicCastThis(wxControl
);
1860 if ( event
.GetText() != control
->GetLabel() )
1861 control
->SetLabel(event
.GetText());
1864 wxCheckBox
*checkbox
= wxDynamicCastThis(wxCheckBox
);
1867 if ( event
.GetSetChecked() )
1868 checkbox
->SetValue(event
.GetChecked());
1870 #endif // wxUSE_CHECKBOX
1873 wxRadioButton
*radiobtn
= wxDynamicCastThis(wxRadioButton
);
1876 if ( event
.GetSetChecked() )
1877 radiobtn
->SetValue(event
.GetChecked());
1879 #endif // wxUSE_RADIOBTN
1885 // call internal idle recursively
1886 // may be obsolete (wait until OnIdle scheme stabilises)
1887 void wxWindowBase::ProcessInternalIdle()
1891 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1894 wxWindow
*child
= node
->GetData();
1895 child
->ProcessInternalIdle();
1896 node
= node
->GetNext();
1901 // ----------------------------------------------------------------------------
1902 // dialog units translations
1903 // ----------------------------------------------------------------------------
1905 wxPoint
wxWindowBase::ConvertPixelsToDialog(const wxPoint
& pt
)
1907 int charWidth
= GetCharWidth();
1908 int charHeight
= GetCharHeight();
1909 wxPoint
pt2(-1, -1);
1911 pt2
.x
= (int) ((pt
.x
* 4) / charWidth
) ;
1913 pt2
.y
= (int) ((pt
.y
* 8) / charHeight
) ;
1918 wxPoint
wxWindowBase::ConvertDialogToPixels(const wxPoint
& pt
)
1920 int charWidth
= GetCharWidth();
1921 int charHeight
= GetCharHeight();
1922 wxPoint
pt2(-1, -1);
1924 pt2
.x
= (int) ((pt
.x
* charWidth
) / 4) ;
1926 pt2
.y
= (int) ((pt
.y
* charHeight
) / 8) ;
1931 // ----------------------------------------------------------------------------
1933 // ----------------------------------------------------------------------------
1935 // propagate the colour change event to the subwindows
1936 void wxWindowBase::OnSysColourChanged(wxSysColourChangedEvent
& event
)
1938 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
1941 // Only propagate to non-top-level windows
1942 wxWindow
*win
= node
->GetData();
1943 if ( !win
->IsTopLevel() )
1945 wxSysColourChangedEvent event2
;
1946 event
.m_eventObject
= win
;
1947 win
->GetEventHandler()->ProcessEvent(event2
);
1950 node
= node
->GetNext();
1954 // the default action is to populate dialog with data when it's created,
1955 // and nudge the UI into displaying itself correctly in case
1956 // we've turned the wxUpdateUIEvents frequency down low.
1957 void wxWindowBase::OnInitDialog( wxInitDialogEvent
&WXUNUSED(event
) )
1959 TransferDataToWindow();
1961 // Update the UI at this point
1962 UpdateWindowUI(wxUPDATE_UI_RECURSE
);
1965 // process Ctrl-Alt-mclick
1966 void wxWindowBase::OnMiddleClick( wxMouseEvent
& event
)
1969 if ( event
.ControlDown() && event
.AltDown() )
1971 // don't translate these strings
1974 #ifdef __WXUNIVERSAL__
1976 #endif // __WXUNIVERSAL__
1978 switch ( wxGetOsVersion() )
1980 case wxMOTIF_X
: port
+= _T("Motif"); break;
1982 case wxMAC_DARWIN
: port
+= _T("Mac"); break;
1983 case wxBEOS
: port
+= _T("BeOS"); break;
1987 case wxGTK_BEOS
: port
+= _T("GTK"); break;
1993 case wxWIN386
: port
+= _T("MS Windows"); break;
1997 case wxMGL_OS2
: port
+= _T("MGL"); break;
1999 case wxOS2_PM
: port
+= _T("OS/2"); break;
2000 default: port
+= _T("unknown"); break;
2003 wxMessageBox(wxString::Format(
2005 " wxWindows Library (%s port)\nVersion %u.%u.%u%s, compiled at %s %s\n Copyright (c) 1995-2002 wxWindows team"
2019 _T("wxWindows information"),
2020 wxICON_INFORMATION
| wxOK
,
2024 #endif // wxUSE_MSGDLG
2030 // ----------------------------------------------------------------------------
2032 // ----------------------------------------------------------------------------
2034 #if wxUSE_ACCESSIBILITY
2035 void wxWindowBase::SetAccessible(wxAccessible
* accessible
)
2037 if (m_accessible
&& (accessible
!= m_accessible
))
2038 delete m_accessible
;
2039 m_accessible
= accessible
;
2041 m_accessible
->SetWindow((wxWindow
*) this);
2044 // Returns the accessible object, creating if necessary.
2045 wxAccessible
* wxWindowBase::GetOrCreateAccessible()
2048 m_accessible
= CreateAccessible();
2049 return m_accessible
;
2052 // Override to create a specific accessible object.
2053 wxAccessible
* wxWindowBase::CreateAccessible()
2055 return new wxWindowAccessible((wxWindow
*) this);
2061 // ----------------------------------------------------------------------------
2062 // list classes implementation
2063 // ----------------------------------------------------------------------------
2065 void wxWindowListNode::DeleteData()
2067 delete (wxWindow
*)GetData();
2071 // ----------------------------------------------------------------------------
2073 // ----------------------------------------------------------------------------
2075 wxBorder
wxWindowBase::GetBorder(long flags
) const
2077 wxBorder border
= (wxBorder
)(flags
& wxBORDER_MASK
);
2078 if ( border
== wxBORDER_DEFAULT
)
2080 border
= GetDefaultBorder();
2086 wxBorder
wxWindowBase::GetDefaultBorder() const
2088 return wxBORDER_NONE
;
2091 // ----------------------------------------------------------------------------
2093 // ----------------------------------------------------------------------------
2095 wxHitTest
wxWindowBase::DoHitTest(wxCoord x
, wxCoord y
) const
2097 // here we just check if the point is inside the window or not
2099 // check the top and left border first
2100 bool outside
= x
< 0 || y
< 0;
2103 // check the right and bottom borders too
2104 wxSize size
= GetSize();
2105 outside
= x
>= size
.x
|| y
>= size
.y
;
2108 return outside
? wxHT_WINDOW_OUTSIDE
: wxHT_WINDOW_INSIDE
;
2111 // ----------------------------------------------------------------------------
2113 // ----------------------------------------------------------------------------
2115 struct WXDLLEXPORT wxWindowNext
2119 } *wxWindowBase::ms_winCaptureNext
= NULL
;
2121 void wxWindowBase::CaptureMouse()
2123 wxLogTrace(_T("mousecapture"), _T("CaptureMouse(%p)"), this);
2125 wxWindow
*winOld
= GetCapture();
2128 ((wxWindowBase
*) winOld
)->DoReleaseMouse();
2131 wxWindowNext
*item
= new wxWindowNext
;
2133 item
->next
= ms_winCaptureNext
;
2134 ms_winCaptureNext
= item
;
2136 //else: no mouse capture to save
2141 void wxWindowBase::ReleaseMouse()
2143 wxLogTrace(_T("mousecapture"), _T("ReleaseMouse(%p)"), this);
2145 wxASSERT_MSG( GetCapture() == this, wxT("attempt to release mouse, but this window hasn't captured it") );
2149 if ( ms_winCaptureNext
)
2151 ((wxWindowBase
*)ms_winCaptureNext
->win
)->DoCaptureMouse();
2153 wxWindowNext
*item
= ms_winCaptureNext
;
2154 ms_winCaptureNext
= item
->next
;
2157 //else: stack is empty, no previous capture
2159 wxLogTrace(_T("mousecapture"),
2160 (const wxChar
*) _T("After ReleaseMouse() mouse is captured by %p"),
2167 wxWindowBase::RegisterHotKey(int WXUNUSED(hotkeyId
),
2168 int WXUNUSED(modifiers
),
2169 int WXUNUSED(keycode
))
2175 bool wxWindowBase::UnregisterHotKey(int WXUNUSED(hotkeyId
))
2181 #endif // wxUSE_HOTKEY
2183 void wxWindowBase::SendDestroyEvent()
2185 wxWindowDestroyEvent event
;
2186 event
.SetEventObject(this);
2187 event
.SetId(GetId());
2188 GetEventHandler()->ProcessEvent(event
);
2191 // ----------------------------------------------------------------------------
2193 // ----------------------------------------------------------------------------
2195 bool wxWindowBase::TryValidator(wxEvent
& wxVALIDATOR_PARAM(event
))
2197 #if wxUSE_VALIDATORS
2198 // Can only use the validator of the window which
2199 // is receiving the event
2200 if ( event
.GetEventObject() == this )
2202 wxValidator
*validator
= GetValidator();
2203 if ( validator
&& validator
->ProcessEvent(event
) )
2208 #endif // wxUSE_VALIDATORS
2213 bool wxWindowBase::TryParent(wxEvent
& event
)
2215 // carry on up the parent-child hierarchy if the propgation count hasn't
2217 if ( event
.ShouldPropagate() )
2219 // honour the requests to stop propagation at this window: this is
2220 // used by the dialogs, for example, to prevent processing the events
2221 // from the dialog controls in the parent frame which rarely, if ever,
2223 if ( !(GetExtraStyle() & wxWS_EX_BLOCK_EVENTS
) )
2225 wxWindow
*parent
= GetParent();
2226 if ( parent
&& !parent
->IsBeingDeleted() )
2228 wxPropagateOnce
propagateOnce(event
);
2230 return parent
->GetEventHandler()->ProcessEvent(event
);
2235 return wxEvtHandler::TryParent(event
);
2238 // ----------------------------------------------------------------------------
2240 // ----------------------------------------------------------------------------
2242 wxWindow
* wxGetTopLevelParent(wxWindow
*win
)
2244 while ( win
&& !win
->IsTopLevel() )
2245 win
= win
->GetParent();
2250 #if wxUSE_ACCESSIBILITY
2251 // ----------------------------------------------------------------------------
2252 // accessible object for windows
2253 // ----------------------------------------------------------------------------
2255 // Can return either a child object, or an integer
2256 // representing the child element, starting from 1.
2257 wxAccStatus
wxWindowAccessible::HitTest(const wxPoint
& WXUNUSED(pt
), int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(childObject
))
2259 wxASSERT( GetWindow() != NULL
);
2263 return wxACC_NOT_IMPLEMENTED
;
2266 // Returns the rectangle for this object (id = 0) or a child element (id > 0).
2267 wxAccStatus
wxWindowAccessible::GetLocation(wxRect
& rect
, int elementId
)
2269 wxASSERT( GetWindow() != NULL
);
2273 wxWindow
* win
= NULL
;
2280 if (elementId
<= (int) GetWindow()->GetChildren().GetCount())
2282 win
= GetWindow()->GetChildren().Item(elementId
-1)->GetData();
2289 rect
= win
->GetRect();
2290 if (win
->GetParent() && !win
->IsKindOf(CLASSINFO(wxTopLevelWindow
)))
2291 rect
.SetPosition(win
->GetParent()->ClientToScreen(rect
.GetPosition()));
2295 return wxACC_NOT_IMPLEMENTED
;
2298 // Navigates from fromId to toId/toObject.
2299 wxAccStatus
wxWindowAccessible::Navigate(wxNavDir navDir
, int fromId
,
2300 int* WXUNUSED(toId
), wxAccessible
** toObject
)
2302 wxASSERT( GetWindow() != NULL
);
2308 case wxNAVDIR_FIRSTCHILD
:
2310 if (GetWindow()->GetChildren().GetCount() == 0)
2312 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetFirst()->GetData();
2313 *toObject
= childWindow
->GetOrCreateAccessible();
2317 case wxNAVDIR_LASTCHILD
:
2319 if (GetWindow()->GetChildren().GetCount() == 0)
2321 wxWindow
* childWindow
= (wxWindow
*) GetWindow()->GetChildren().GetLast()->GetData();
2322 *toObject
= childWindow
->GetOrCreateAccessible();
2326 case wxNAVDIR_RIGHT
:
2330 wxWindowList::compatibility_iterator node
=
2331 wxWindowList::compatibility_iterator();
2334 // Can't navigate to sibling of this window
2335 // if we're a top-level window.
2336 if (!GetWindow()->GetParent())
2337 return wxACC_NOT_IMPLEMENTED
;
2339 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2343 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2344 node
= GetWindow()->GetChildren().Item(fromId
-1);
2347 if (node
&& node
->GetNext())
2349 wxWindow
* nextWindow
= node
->GetNext()->GetData();
2350 *toObject
= nextWindow
->GetOrCreateAccessible();
2358 case wxNAVDIR_PREVIOUS
:
2360 wxWindowList::compatibility_iterator node
=
2361 wxWindowList::compatibility_iterator();
2364 // Can't navigate to sibling of this window
2365 // if we're a top-level window.
2366 if (!GetWindow()->GetParent())
2367 return wxACC_NOT_IMPLEMENTED
;
2369 node
= GetWindow()->GetParent()->GetChildren().Find(GetWindow());
2373 if (fromId
<= (int) GetWindow()->GetChildren().GetCount())
2374 node
= GetWindow()->GetChildren().Item(fromId
-1);
2377 if (node
&& node
->GetPrevious())
2379 wxWindow
* previousWindow
= node
->GetPrevious()->GetData();
2380 *toObject
= previousWindow
->GetOrCreateAccessible();
2388 return wxACC_NOT_IMPLEMENTED
;
2391 // Gets the name of the specified object.
2392 wxAccStatus
wxWindowAccessible::GetName(int childId
, wxString
* name
)
2394 wxASSERT( GetWindow() != NULL
);
2400 // If a child, leave wxWindows to call the function on the actual
2403 return wxACC_NOT_IMPLEMENTED
;
2405 // This will eventually be replaced by specialised
2406 // accessible classes, one for each kind of wxWindows
2407 // control or window.
2408 if (GetWindow()->IsKindOf(CLASSINFO(wxButton
)))
2409 title
= ((wxButton
*) GetWindow())->GetLabel();
2411 title
= GetWindow()->GetName();
2413 if (!title
.IsEmpty())
2419 return wxACC_NOT_IMPLEMENTED
;
2422 // Gets the number of children.
2423 wxAccStatus
wxWindowAccessible::GetChildCount(int* childId
)
2425 wxASSERT( GetWindow() != NULL
);
2429 *childId
= (int) GetWindow()->GetChildren().GetCount();
2433 // Gets the specified child (starting from 1).
2434 // If *child is NULL and return value is wxACC_OK,
2435 // this means that the child is a simple element and
2436 // not an accessible object.
2437 wxAccStatus
wxWindowAccessible::GetChild(int childId
, wxAccessible
** child
)
2439 wxASSERT( GetWindow() != NULL
);
2449 if (childId
> (int) GetWindow()->GetChildren().GetCount())
2452 wxWindow
* childWindow
= GetWindow()->GetChildren().Item(childId
-1)->GetData();
2453 *child
= childWindow
->GetOrCreateAccessible();
2460 // Gets the parent, or NULL.
2461 wxAccStatus
wxWindowAccessible::GetParent(wxAccessible
** parent
)
2463 wxASSERT( GetWindow() != NULL
);
2467 wxWindow
* parentWindow
= GetWindow()->GetParent();
2475 *parent
= parentWindow
->GetOrCreateAccessible();
2483 // Performs the default action. childId is 0 (the action for this object)
2484 // or > 0 (the action for a child).
2485 // Return wxACC_NOT_SUPPORTED if there is no default action for this
2486 // window (e.g. an edit control).
2487 wxAccStatus
wxWindowAccessible::DoDefaultAction(int WXUNUSED(childId
))
2489 wxASSERT( GetWindow() != NULL
);
2493 return wxACC_NOT_IMPLEMENTED
;
2496 // Gets the default action for this object (0) or > 0 (the action for a child).
2497 // Return wxACC_OK even if there is no action. actionName is the action, or the empty
2498 // string if there is no action.
2499 // The retrieved string describes the action that is performed on an object,
2500 // not what the object does as a result. For example, a toolbar button that prints
2501 // a document has a default action of "Press" rather than "Prints the current document."
2502 wxAccStatus
wxWindowAccessible::GetDefaultAction(int WXUNUSED(childId
), wxString
* WXUNUSED(actionName
))
2504 wxASSERT( GetWindow() != NULL
);
2508 return wxACC_NOT_IMPLEMENTED
;
2511 // Returns the description for this object or a child.
2512 wxAccStatus
wxWindowAccessible::GetDescription(int WXUNUSED(childId
), wxString
* description
)
2514 wxASSERT( GetWindow() != NULL
);
2518 wxString
ht(GetWindow()->GetHelpText());
2524 return wxACC_NOT_IMPLEMENTED
;
2527 // Returns help text for this object or a child, similar to tooltip text.
2528 wxAccStatus
wxWindowAccessible::GetHelpText(int WXUNUSED(childId
), wxString
* helpText
)
2530 wxASSERT( GetWindow() != NULL
);
2534 wxString
ht(GetWindow()->GetHelpText());
2540 return wxACC_NOT_IMPLEMENTED
;
2543 // Returns the keyboard shortcut for this object or child.
2544 // Return e.g. ALT+K
2545 wxAccStatus
wxWindowAccessible::GetKeyboardShortcut(int WXUNUSED(childId
), wxString
* WXUNUSED(shortcut
))
2547 wxASSERT( GetWindow() != NULL
);
2551 return wxACC_NOT_IMPLEMENTED
;
2554 // Returns a role constant.
2555 wxAccStatus
wxWindowAccessible::GetRole(int childId
, wxAccRole
* role
)
2557 wxASSERT( GetWindow() != NULL
);
2561 // If a child, leave wxWindows to call the function on the actual
2564 return wxACC_NOT_IMPLEMENTED
;
2566 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2567 return wxACC_NOT_IMPLEMENTED
;
2569 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2570 return wxACC_NOT_IMPLEMENTED
;
2573 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2574 return wxACC_NOT_IMPLEMENTED
;
2577 //*role = wxROLE_SYSTEM_CLIENT;
2578 *role
= wxROLE_SYSTEM_CLIENT
;
2582 return wxACC_NOT_IMPLEMENTED
;
2586 // Returns a state constant.
2587 wxAccStatus
wxWindowAccessible::GetState(int childId
, long* state
)
2589 wxASSERT( GetWindow() != NULL
);
2593 // If a child, leave wxWindows to call the function on the actual
2596 return wxACC_NOT_IMPLEMENTED
;
2598 if (GetWindow()->IsKindOf(CLASSINFO(wxControl
)))
2599 return wxACC_NOT_IMPLEMENTED
;
2602 if (GetWindow()->IsKindOf(CLASSINFO(wxStatusBar
)))
2603 return wxACC_NOT_IMPLEMENTED
;
2606 if (GetWindow()->IsKindOf(CLASSINFO(wxToolBar
)))
2607 return wxACC_NOT_IMPLEMENTED
;
2614 return wxACC_NOT_IMPLEMENTED
;
2618 // Returns a localized string representing the value for the object
2620 wxAccStatus
wxWindowAccessible::GetValue(int WXUNUSED(childId
), wxString
* WXUNUSED(strValue
))
2622 wxASSERT( GetWindow() != NULL
);
2626 return wxACC_NOT_IMPLEMENTED
;
2629 // Selects the object or child.
2630 wxAccStatus
wxWindowAccessible::Select(int WXUNUSED(childId
), wxAccSelectionFlags
WXUNUSED(selectFlags
))
2632 wxASSERT( GetWindow() != NULL
);
2636 return wxACC_NOT_IMPLEMENTED
;
2639 // Gets the window with the keyboard focus.
2640 // If childId is 0 and child is NULL, no object in
2641 // this subhierarchy has the focus.
2642 // If this object has the focus, child should be 'this'.
2643 wxAccStatus
wxWindowAccessible::GetFocus(int* WXUNUSED(childId
), wxAccessible
** WXUNUSED(child
))
2645 wxASSERT( GetWindow() != NULL
);
2649 return wxACC_NOT_IMPLEMENTED
;
2652 // Gets a variant representing the selected children
2654 // Acceptable values:
2655 // - a null variant (IsNull() returns TRUE)
2656 // - a list variant (GetType() == wxT("list")
2657 // - an integer representing the selected child element,
2658 // or 0 if this object is selected (GetType() == wxT("long")
2659 // - a "void*" pointer to a wxAccessible child object
2660 wxAccStatus
wxWindowAccessible::GetSelections(wxVariant
* WXUNUSED(selections
))
2662 wxASSERT( GetWindow() != NULL
);
2666 return wxACC_NOT_IMPLEMENTED
;
2669 #endif // wxUSE_ACCESSIBILITY