+ // this should never happen and it will lead to a crash later if it does
+ // because RemoveChild() will remove only one node from the children list
+ // and the other(s) one(s) will be left with dangling pointers in them
+ wxASSERT_MSG( !GetChildren().Find((wxWindow*)child), wxT("AddChild() called twice") );
+
+ GetChildren().Append((wxWindow*)child);
+ child->SetParent(this);
+
+ // adding a child while frozen will assert when thawed, so freeze it as if
+ // it had been already present when we were frozen
+ if ( IsFrozen() && !child->IsTopLevel() )
+ child->Freeze();
+}
+
+void wxWindowBase::RemoveChild(wxWindowBase *child)
+{
+ wxCHECK_RET( child, wxT("can't remove a NULL child") );
+
+ // removing a child while frozen may result in permanently frozen window
+ // if used e.g. from Reparent(), so thaw it
+ //
+ // NB: IsTopLevel() doesn't return true any more when a TLW child is being
+ // removed from its ~wxWindowBase, so check for IsBeingDeleted() too
+ if ( IsFrozen() && !child->IsBeingDeleted() && !child->IsTopLevel() )
+ child->Thaw();
+
+ GetChildren().DeleteObject((wxWindow *)child);
+ child->SetParent(NULL);
+}
+
+bool wxWindowBase::Reparent(wxWindowBase *newParent)
+{
+ wxWindow *oldParent = GetParent();
+ if ( newParent == oldParent )
+ {
+ // nothing done
+ return false;
+ }
+
+ const bool oldEnabledState = IsEnabled();
+
+ // unlink this window from the existing parent.
+ if ( oldParent )
+ {
+ oldParent->RemoveChild(this);
+ }
+ else
+ {
+ wxTopLevelWindows.DeleteObject((wxWindow *)this);
+ }
+
+ // add it to the new one
+ if ( newParent )
+ {
+ newParent->AddChild(this);
+ }
+ else
+ {
+ wxTopLevelWindows.Append((wxWindow *)this);
+ }
+
+ // We need to notify window (and its subwindows) if by changing the parent
+ // we also change our enabled/disabled status.
+ const bool newEnabledState = IsEnabled();
+ if ( newEnabledState != oldEnabledState )
+ {
+ NotifyWindowOnEnableChange(newEnabledState);
+ }
+
+ return true;
+}
+
+// ----------------------------------------------------------------------------
+// event handler stuff
+// ----------------------------------------------------------------------------
+
+void wxWindowBase::SetEventHandler(wxEvtHandler *handler)
+{
+ wxCHECK_RET(handler != NULL, "SetEventHandler(NULL) called");
+
+ m_eventHandler = handler;
+}
+
+void wxWindowBase::SetNextHandler(wxEvtHandler *WXUNUSED(handler))
+{
+ // disable wxEvtHandler chain mechanism for wxWindows:
+ // wxWindow uses its own stack mechanism which doesn't mix well with wxEvtHandler's one
+
+ wxFAIL_MSG("wxWindow cannot be part of a wxEvtHandler chain");
+}
+void wxWindowBase::SetPreviousHandler(wxEvtHandler *WXUNUSED(handler))
+{
+ // we can't simply wxFAIL here as in SetNextHandler: in fact the last
+ // handler of our stack when is destroyed will be Unlink()ed and thus
+ // will call this function to update the pointer of this window...
+
+ //wxFAIL_MSG("wxWindow cannot be part of a wxEvtHandler chain");
+}
+
+void wxWindowBase::PushEventHandler(wxEvtHandler *handlerToPush)
+{
+ wxCHECK_RET( handlerToPush != NULL, "PushEventHandler(NULL) called" );
+
+ // the new handler is going to be part of the wxWindow stack of event handlers:
+ // it can't be part also of an event handler double-linked chain:
+ wxASSERT_MSG(handlerToPush->IsUnlinked(),
+ "The handler being pushed in the wxWindow stack shouldn't be part of "
+ "a wxEvtHandler chain; call Unlink() on it first");
+
+ wxEvtHandler *handlerOld = GetEventHandler();
+ wxCHECK_RET( handlerOld, "an old event handler is NULL?" );
+
+ // now use wxEvtHandler double-linked list to implement a stack:
+ handlerToPush->SetNextHandler(handlerOld);
+
+ if (handlerOld != this)
+ handlerOld->SetPreviousHandler(handlerToPush);
+
+ SetEventHandler(handlerToPush);
+
+#if wxDEBUG_LEVEL
+ // final checks of the operations done above:
+ wxASSERT_MSG( handlerToPush->GetPreviousHandler() == NULL,
+ "the first handler of the wxWindow stack should "
+ "have no previous handlers set" );
+ wxASSERT_MSG( handlerToPush->GetNextHandler() != NULL,
+ "the first handler of the wxWindow stack should "
+ "have non-NULL next handler" );
+
+ wxEvtHandler* pLast = handlerToPush;
+ while ( pLast && pLast != this )
+ pLast = pLast->GetNextHandler();
+ wxASSERT_MSG( pLast->GetNextHandler() == NULL,
+ "the last handler of the wxWindow stack should "
+ "have this window as next handler" );
+#endif // wxDEBUG_LEVEL
+}
+
+wxEvtHandler *wxWindowBase::PopEventHandler(bool deleteHandler)
+{
+ // we need to pop the wxWindow stack, i.e. we need to remove the first handler
+
+ wxEvtHandler *firstHandler = GetEventHandler();
+ wxCHECK_MSG( firstHandler != NULL, NULL, "wxWindow cannot have a NULL event handler" );
+ wxCHECK_MSG( firstHandler != this, NULL, "cannot pop the wxWindow itself" );
+ wxCHECK_MSG( firstHandler->GetPreviousHandler() == NULL, NULL,
+ "the first handler of the wxWindow stack should have no previous handlers set" );
+
+ wxEvtHandler *secondHandler = firstHandler->GetNextHandler();
+ wxCHECK_MSG( secondHandler != NULL, NULL,
+ "the first handler of the wxWindow stack should have non-NULL next handler" );
+
+ firstHandler->SetNextHandler(NULL);
+ secondHandler->SetPreviousHandler(NULL);
+
+ // now firstHandler is completely unlinked; set secondHandler as the new window event handler
+ SetEventHandler(secondHandler);
+
+ if ( deleteHandler )
+ {
+ delete firstHandler;
+ firstHandler = NULL;
+ }
+
+ return firstHandler;
+}
+
+bool wxWindowBase::RemoveEventHandler(wxEvtHandler *handlerToRemove)
+{
+ wxCHECK_MSG( handlerToRemove != NULL, false, "RemoveEventHandler(NULL) called" );
+ wxCHECK_MSG( handlerToRemove != this, false, "Cannot remove the window itself" );
+
+ if (handlerToRemove == GetEventHandler())
+ {
+ // removing the first event handler is equivalent to "popping" the stack
+ PopEventHandler(false);
+ return true;
+ }
+
+ // NOTE: the wxWindow event handler list is always terminated with "this" handler
+ wxEvtHandler *handlerCur = GetEventHandler()->GetNextHandler();
+ while ( handlerCur != this && handlerCur )
+ {
+ wxEvtHandler *handlerNext = handlerCur->GetNextHandler();
+
+ if ( handlerCur == handlerToRemove )
+ {
+ handlerCur->Unlink();
+
+ wxASSERT_MSG( handlerCur != GetEventHandler(),
+ "the case Remove == Pop should was already handled" );
+ return true;
+ }
+
+ handlerCur = handlerNext;
+ }
+
+ wxFAIL_MSG( wxT("where has the event handler gone?") );
+
+ return false;
+}
+
+bool wxWindowBase::HandleWindowEvent(wxEvent& event) const
+{
+ // SafelyProcessEvent() will handle exceptions nicely
+ return GetEventHandler()->SafelyProcessEvent(event);
+}
+
+// ----------------------------------------------------------------------------
+// colours, fonts &c
+// ----------------------------------------------------------------------------
+
+void wxWindowBase::InheritAttributes()
+{
+ const wxWindowBase * const parent = GetParent();
+ if ( !parent )
+ return;
+
+ // we only inherit attributes which had been explicitly set for the parent
+ // which ensures that this only happens if the user really wants it and
+ // not by default which wouldn't make any sense in modern GUIs where the
+ // controls don't all use the same fonts (nor colours)
+ if ( parent->m_inheritFont && !m_hasFont )
+ SetFont(parent->GetFont());
+
+ // in addition, there is a possibility to explicitly forbid inheriting
+ // colours at each class level by overriding ShouldInheritColours()
+ if ( ShouldInheritColours() )
+ {
+ if ( parent->m_inheritFgCol && !m_hasFgCol )
+ SetForegroundColour(parent->GetForegroundColour());
+
+ // inheriting (solid) background colour is wrong as it totally breaks
+ // any kind of themed backgrounds
+ //
+ // instead, the controls should use the same background as their parent
+ // (ideally by not drawing it at all)
+#if 0
+ if ( parent->m_inheritBgCol && !m_hasBgCol )
+ SetBackgroundColour(parent->GetBackgroundColour());
+#endif // 0
+ }
+}
+
+/* static */ wxVisualAttributes
+wxWindowBase::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
+{
+ // it is important to return valid values for all attributes from here,
+ // GetXXX() below rely on this
+ wxVisualAttributes attrs;
+ attrs.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
+ attrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
+
+ // On Smartphone/PocketPC, wxSYS_COLOUR_WINDOW is a better reflection of
+ // the usual background colour than wxSYS_COLOUR_BTNFACE.
+ // It's a pity that wxSYS_COLOUR_WINDOW isn't always a suitable background
+ // colour on other platforms.
+
+#if defined(__WXWINCE__) && (defined(__SMARTPHONE__) || defined(__POCKETPC__))
+ attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
+#else
+ attrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
+#endif
+ return attrs;
+}
+
+wxColour wxWindowBase::GetBackgroundColour() const
+{
+ if ( !m_backgroundColour.IsOk() )
+ {
+ wxASSERT_MSG( !m_hasBgCol, wxT("we have invalid explicit bg colour?") );
+
+ // get our default background colour
+ wxColour colBg = GetDefaultAttributes().colBg;
+
+ // we must return some valid colour to avoid redoing this every time
+ // and also to avoid surprising the applications written for older
+ // wxWidgets versions where GetBackgroundColour() always returned
+ // something -- so give them something even if it doesn't make sense
+ // for this window (e.g. it has a themed background)
+ if ( !colBg.Ok() )
+ colBg = GetClassDefaultAttributes().colBg;
+
+ return colBg;
+ }
+ else
+ return m_backgroundColour;
+}
+
+wxColour wxWindowBase::GetForegroundColour() const
+{
+ // logic is the same as above
+ if ( !m_hasFgCol && !m_foregroundColour.Ok() )
+ {
+ wxColour colFg = GetDefaultAttributes().colFg;
+
+ if ( !colFg.IsOk() )
+ colFg = GetClassDefaultAttributes().colFg;
+
+ return colFg;
+ }
+ else
+ return m_foregroundColour;
+}
+
+bool wxWindowBase::SetBackgroundColour( const wxColour &colour )
+{
+ if ( colour == m_backgroundColour )
+ return false;
+
+ m_hasBgCol = colour.IsOk();
+
+ m_inheritBgCol = m_hasBgCol;
+ m_backgroundColour = colour;
+ SetThemeEnabled( !m_hasBgCol && !m_foregroundColour.Ok() );
+ return true;
+}
+
+bool wxWindowBase::SetForegroundColour( const wxColour &colour )
+{
+ if (colour == m_foregroundColour )
+ return false;
+
+ m_hasFgCol = colour.IsOk();
+ m_inheritFgCol = m_hasFgCol;
+ m_foregroundColour = colour;
+ SetThemeEnabled( !m_hasFgCol && !m_backgroundColour.Ok() );
+ return true;
+}
+
+bool wxWindowBase::SetCursor(const wxCursor& cursor)
+{
+ // setting an invalid cursor is ok, it means that we don't have any special
+ // cursor
+ if ( m_cursor.IsSameAs(cursor) )
+ {
+ // no change
+ return false;
+ }
+
+ m_cursor = cursor;
+
+ return true;
+}
+
+wxFont wxWindowBase::GetFont() const
+{
+ // logic is the same as in GetBackgroundColour()
+ if ( !m_font.IsOk() )
+ {
+ wxASSERT_MSG( !m_hasFont, wxT("we have invalid explicit font?") );
+
+ wxFont font = GetDefaultAttributes().font;
+ if ( !font.IsOk() )
+ font = GetClassDefaultAttributes().font;
+
+ return font;
+ }
+ else
+ return m_font;
+}
+
+bool wxWindowBase::SetFont(const wxFont& font)
+{
+ if ( font == m_font )
+ {
+ // no change
+ return false;
+ }
+
+ m_font = font;
+ m_hasFont = font.IsOk();
+ m_inheritFont = m_hasFont;
+
+ InvalidateBestSize();
+
+ return true;
+}
+
+#if wxUSE_PALETTE
+
+void wxWindowBase::SetPalette(const wxPalette& pal)
+{
+ m_hasCustomPalette = true;
+ m_palette = pal;
+
+ // VZ: can anyone explain me what do we do here?
+ wxWindowDC d((wxWindow *) this);
+ d.SetPalette(pal);
+}
+
+wxWindow *wxWindowBase::GetAncestorWithCustomPalette() const
+{
+ wxWindow *win = (wxWindow *)this;
+ while ( win && !win->HasCustomPalette() )
+ {
+ win = win->GetParent();
+ }
+
+ return win;
+}
+
+#endif // wxUSE_PALETTE
+
+#if wxUSE_CARET
+void wxWindowBase::SetCaret(wxCaret *caret)
+{
+ if ( m_caret )
+ {
+ delete m_caret;
+ }
+
+ m_caret = caret;
+
+ if ( m_caret )
+ {
+ wxASSERT_MSG( m_caret->GetWindow() == this,
+ wxT("caret should be created associated to this window") );
+ }
+}
+#endif // wxUSE_CARET
+
+#if wxUSE_VALIDATORS
+// ----------------------------------------------------------------------------
+// validators
+// ----------------------------------------------------------------------------
+
+void wxWindowBase::SetValidator(const wxValidator& validator)
+{
+ if ( m_windowValidator )
+ delete m_windowValidator;
+
+ m_windowValidator = (wxValidator *)validator.Clone();
+
+ if ( m_windowValidator )
+ m_windowValidator->SetWindow(this);
+}
+#endif // wxUSE_VALIDATORS
+
+// ----------------------------------------------------------------------------
+// update region stuff
+// ----------------------------------------------------------------------------
+
+wxRect wxWindowBase::GetUpdateClientRect() const
+{
+ wxRegion rgnUpdate = GetUpdateRegion();
+ rgnUpdate.Intersect(GetClientRect());
+ wxRect rectUpdate = rgnUpdate.GetBox();
+ wxPoint ptOrigin = GetClientAreaOrigin();
+ rectUpdate.x -= ptOrigin.x;
+ rectUpdate.y -= ptOrigin.y;
+
+ return rectUpdate;
+}
+
+bool wxWindowBase::DoIsExposed(int x, int y) const
+{
+ return m_updateRegion.Contains(x, y) != wxOutRegion;
+}
+
+bool wxWindowBase::DoIsExposed(int x, int y, int w, int h) const
+{
+ return m_updateRegion.Contains(x, y, w, h) != wxOutRegion;
+}
+
+void wxWindowBase::ClearBackground()
+{
+ // wxGTK uses its own version, no need to add never used code
+#ifndef __WXGTK__
+ wxClientDC dc((wxWindow *)this);
+ wxBrush brush(GetBackgroundColour(), wxBRUSHSTYLE_SOLID);
+ dc.SetBackground(brush);
+ dc.Clear();
+#endif // __WXGTK__
+}
+
+// ----------------------------------------------------------------------------
+// find child window by id or name
+// ----------------------------------------------------------------------------
+
+wxWindow *wxWindowBase::FindWindow(long id) const
+{
+ if ( id == m_windowId )
+ return (wxWindow *)this;
+
+ wxWindowBase *res = NULL;
+ wxWindowList::compatibility_iterator node;
+ for ( node = m_children.GetFirst(); node && !res; node = node->GetNext() )
+ {
+ wxWindowBase *child = node->GetData();
+ res = child->FindWindow( id );
+ }
+
+ return (wxWindow *)res;
+}
+
+wxWindow *wxWindowBase::FindWindow(const wxString& name) const
+{
+ if ( name == m_windowName )
+ return (wxWindow *)this;
+
+ wxWindowBase *res = NULL;
+ wxWindowList::compatibility_iterator node;
+ for ( node = m_children.GetFirst(); node && !res; node = node->GetNext() )
+ {
+ wxWindow *child = node->GetData();
+ res = child->FindWindow(name);
+ }
+
+ return (wxWindow *)res;
+}
+
+
+// find any window by id or name or label: If parent is non-NULL, look through
+// children for a label or title matching the specified string. If NULL, look
+// through all top-level windows.
+//
+// to avoid duplicating code we reuse the same helper function but with
+// different comparators
+
+typedef bool (*wxFindWindowCmp)(const wxWindow *win,
+ const wxString& label, long id);
+
+static
+bool wxFindWindowCmpLabels(const wxWindow *win, const wxString& label,
+ long WXUNUSED(id))
+{
+ return win->GetLabel() == label;
+}
+
+static
+bool wxFindWindowCmpNames(const wxWindow *win, const wxString& label,
+ long WXUNUSED(id))
+{
+ return win->GetName() == label;
+}
+
+static
+bool wxFindWindowCmpIds(const wxWindow *win, const wxString& WXUNUSED(label),
+ long id)
+{
+ return win->GetId() == id;
+}
+
+// recursive helper for the FindWindowByXXX() functions
+static
+wxWindow *wxFindWindowRecursively(const wxWindow *parent,
+ const wxString& label,
+ long id,
+ wxFindWindowCmp cmp)
+{
+ if ( parent )
+ {
+ // see if this is the one we're looking for
+ if ( (*cmp)(parent, label, id) )
+ return (wxWindow *)parent;
+
+ // It wasn't, so check all its children
+ for ( wxWindowList::compatibility_iterator node = parent->GetChildren().GetFirst();
+ node;
+ node = node->GetNext() )
+ {
+ // recursively check each child
+ wxWindow *win = (wxWindow *)node->GetData();
+ wxWindow *retwin = wxFindWindowRecursively(win, label, id, cmp);
+ if (retwin)
+ return retwin;
+ }
+ }
+
+ // Not found
+ return NULL;
+}
+
+// helper for FindWindowByXXX()
+static
+wxWindow *wxFindWindowHelper(const wxWindow *parent,
+ const wxString& label,
+ long id,
+ wxFindWindowCmp cmp)
+{
+ if ( parent )
+ {
+ // just check parent and all its children
+ return wxFindWindowRecursively(parent, label, id, cmp);
+ }
+
+ // start at very top of wx's windows
+ for ( wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst();
+ node;
+ node = node->GetNext() )
+ {
+ // recursively check each window & its children
+ wxWindow *win = node->GetData();
+ wxWindow *retwin = wxFindWindowRecursively(win, label, id, cmp);
+ if (retwin)
+ return retwin;
+ }
+
+ return NULL;
+}
+
+/* static */
+wxWindow *
+wxWindowBase::FindWindowByLabel(const wxString& title, const wxWindow *parent)
+{
+ return wxFindWindowHelper(parent, title, 0, wxFindWindowCmpLabels);
+}
+
+/* static */
+wxWindow *
+wxWindowBase::FindWindowByName(const wxString& title, const wxWindow *parent)
+{
+ wxWindow *win = wxFindWindowHelper(parent, title, 0, wxFindWindowCmpNames);
+
+ if ( !win )
+ {
+ // fall back to the label
+ win = FindWindowByLabel(title, parent);
+ }
+
+ return win;
+}
+
+/* static */
+wxWindow *
+wxWindowBase::FindWindowById( long id, const wxWindow* parent )
+{
+ return wxFindWindowHelper(parent, wxEmptyString, id, wxFindWindowCmpIds);
+}
+
+// ----------------------------------------------------------------------------
+// dialog oriented functions
+// ----------------------------------------------------------------------------
+
+void wxWindowBase::MakeModal(bool modal)
+{
+ // Disable all other windows
+ if ( IsTopLevel() )
+ {
+ wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst();
+ while (node)
+ {
+ wxWindow *win = node->GetData();
+ if (win != this)
+ win->Enable(!modal);
+
+ node = node->GetNext();
+ }
+ }
+}
+
+bool wxWindowBase::Validate()
+{
+#if wxUSE_VALIDATORS
+ bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0;
+
+ wxWindowList::compatibility_iterator node;
+ for ( node = m_children.GetFirst(); node; node = node->GetNext() )
+ {
+ wxWindowBase *child = node->GetData();
+ wxValidator *validator = child->GetValidator();
+ if ( validator && !validator->Validate((wxWindow *)this) )
+ {
+ return false;
+ }
+
+ if ( recurse && !child->Validate() )
+ {
+ return false;
+ }
+ }
+#endif // wxUSE_VALIDATORS
+
+ return true;
+}
+
+bool wxWindowBase::TransferDataToWindow()
+{
+#if wxUSE_VALIDATORS
+ bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0;
+
+ wxWindowList::compatibility_iterator node;
+ for ( node = m_children.GetFirst(); node; node = node->GetNext() )
+ {
+ wxWindowBase *child = node->GetData();
+ wxValidator *validator = child->GetValidator();
+ if ( validator && !validator->TransferToWindow() )
+ {
+ wxLogWarning(_("Could not transfer data to window"));
+#if wxUSE_LOG
+ wxLog::FlushActive();
+#endif // wxUSE_LOG
+
+ return false;
+ }
+
+ if ( recurse )
+ {
+ if ( !child->TransferDataToWindow() )
+ {
+ // warning already given
+ return false;
+ }
+ }
+ }
+#endif // wxUSE_VALIDATORS
+
+ return true;
+}
+
+bool wxWindowBase::TransferDataFromWindow()
+{
+#if wxUSE_VALIDATORS
+ bool recurse = (GetExtraStyle() & wxWS_EX_VALIDATE_RECURSIVELY) != 0;
+
+ wxWindowList::compatibility_iterator node;
+ for ( node = m_children.GetFirst(); node; node = node->GetNext() )
+ {
+ wxWindow *child = node->GetData();
+ wxValidator *validator = child->GetValidator();
+ if ( validator && !validator->TransferFromWindow() )
+ {
+ // nop warning here because the application is supposed to give
+ // one itself - we don't know here what might have gone wrongly
+
+ return false;
+ }
+
+ if ( recurse )
+ {
+ if ( !child->TransferDataFromWindow() )
+ {
+ // warning already given
+ return false;
+ }
+ }
+ }
+#endif // wxUSE_VALIDATORS
+
+ return true;
+}
+
+void wxWindowBase::InitDialog()
+{
+ wxInitDialogEvent event(GetId());
+ event.SetEventObject( this );
+ GetEventHandler()->ProcessEvent(event);
+}
+
+// ----------------------------------------------------------------------------
+// context-sensitive help support
+// ----------------------------------------------------------------------------
+
+#if wxUSE_HELP
+
+// associate this help text with this window
+void wxWindowBase::SetHelpText(const wxString& text)
+{
+ wxHelpProvider *helpProvider = wxHelpProvider::Get();
+ if ( helpProvider )
+ {
+ helpProvider->AddHelp(this, text);
+ }
+}
+
+#if WXWIN_COMPATIBILITY_2_8
+// associate this help text with all windows with the same id as this
+// one
+void wxWindowBase::SetHelpTextForId(const wxString& text)
+{
+ wxHelpProvider *helpProvider = wxHelpProvider::Get();
+ if ( helpProvider )
+ {
+ helpProvider->AddHelp(GetId(), text);
+ }
+}
+#endif // WXWIN_COMPATIBILITY_2_8
+
+// get the help string associated with this window (may be empty)
+// default implementation forwards calls to the help provider
+wxString
+wxWindowBase::GetHelpTextAtPoint(const wxPoint & WXUNUSED(pt),
+ wxHelpEvent::Origin WXUNUSED(origin)) const
+{
+ wxString text;
+ wxHelpProvider *helpProvider = wxHelpProvider::Get();
+ if ( helpProvider )
+ {
+ text = helpProvider->GetHelp(this);
+ }
+
+ return text;
+}
+
+// show help for this window
+void wxWindowBase::OnHelp(wxHelpEvent& event)
+{
+ wxHelpProvider *helpProvider = wxHelpProvider::Get();
+ if ( helpProvider )
+ {
+ wxPoint pos = event.GetPosition();
+ const wxHelpEvent::Origin origin = event.GetOrigin();
+ if ( origin == wxHelpEvent::Origin_Keyboard )
+ {
+ // if the help event was generated from keyboard it shouldn't
+ // appear at the mouse position (which is still the only position
+ // associated with help event) if the mouse is far away, although
+ // we still do use the mouse position if it's over the window
+ // because we suppose the user looks approximately at the mouse
+ // already and so it would be more convenient than showing tooltip
+ // at some arbitrary position which can be quite far from it
+ const wxRect rectClient = GetClientRect();
+ if ( !rectClient.Contains(ScreenToClient(pos)) )
+ {
+ // position help slightly under and to the right of this window
+ pos = ClientToScreen(wxPoint(
+ 2*GetCharWidth(),
+ rectClient.height + GetCharHeight()
+ ));
+ }
+ }
+
+ if ( helpProvider->ShowHelpAtPoint(this, pos, origin) )
+ {
+ // skip the event.Skip() below
+ return;
+ }
+ }
+
+ event.Skip();
+}
+
+#endif // wxUSE_HELP
+
+// ----------------------------------------------------------------------------
+// tooltips
+// ----------------------------------------------------------------------------
+
+#if wxUSE_TOOLTIPS
+
+wxString wxWindowBase::GetToolTipText() const
+{
+ return m_tooltip ? m_tooltip->GetTip() : wxString();
+}
+
+void wxWindowBase::SetToolTip( const wxString &tip )
+{
+ // don't create the new tooltip if we already have one
+ if ( m_tooltip )
+ {
+ m_tooltip->SetTip( tip );
+ }
+ else
+ {
+ SetToolTip( new wxToolTip( tip ) );
+ }
+
+ // setting empty tooltip text does not remove the tooltip any more - use
+ // SetToolTip(NULL) for this
+}