]> git.saurik.com Git - wxWidgets.git/commitdiff
added Get/SetItemToolTip() (and implemented them for MSW) to allow setting tooltips...
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 4 May 2006 16:08:56 +0000 (16:08 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 4 May 2006 16:08:56 +0000 (16:08 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39030 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
docs/latex/wx/radiobox.tex
include/wx/msw/radiobox.h
include/wx/radiobox.h
samples/controls/controls.cpp
src/common/radiocmn.cpp
src/msw/radiobox.cpp

index d83e47d4cea5440af2cc5536d593cedd9db8acb9..62cd9e56d764bdba260ba7fb6f6eaf8f8f5cb8a7 100644 (file)
@@ -78,6 +78,7 @@ All (GUI):
 
 - Added wxTreebook (uses a wxTreeCtrl to control pages).
 - Added wxDC::GradientFillLinear/Concentric()
+- Added wxRadioBox::SetItemToolTip()
 - Added wxKeyEvent::GetModifiers()
 - Added wxDialog::SetEscapeId().
 - wxItemContainerImmutable::FindString unified (affects wxRadioBox, wxListBox,
index 6dd954b8a330f4c3dbfd7c282ada93b997a3b1ad..c322e7932986da961a017343015c604a32089126 100644 (file)
@@ -193,6 +193,18 @@ Finds a button matching the given string, returning the position if found, or
 Returns the number of columns in the radiobox.
 
 
+\membersection{wxRadioBox::GetItemToolTip}\label{wxradioboxgetitemtooltip}
+
+\constfunc{wxToolTip *}{GetItemToolTip}{\param{unsigned int}{ item}}
+
+Returns the tooltip associated with the specified \arg{item} if any or \NULL.
+
+\wxheading{See also}
+
+\helpref{SetItemToolTip}{wxradioboxsetitemtooltip},\\
+\helpref{wxWindow::GetToolTip}{wxwindowgettooltip}
+
+
 \membersection{wxRadioBox::GetLabel}\label{wxradioboxgetlabel}
 
 \constfunc{wxString}{GetLabel}{\void}
@@ -327,6 +339,24 @@ a wxEVT\_COMMAND\_RADIOBOX\_SELECTED event to get emitted.
 \docparam{string}{The label of the button to select.}
 
 
+\membersection{wxRadioBox::SetItemToolTip}\label{wxradioboxsetitemtooltip}
+
+\func{void}{SetItemToolTip}{\param{unsigned int}{ item}, \param{const wxString\& }{text}}
+
+Sets the tooltip text for the specified item in the radio group.
+
+\wxheading{Parameters}
+
+\docparam{item}{Index of the item the tooltip will be shown for.}
+
+\docparam{text}{Tooltip text for the item, the tooltip is removed if empty.}
+
+\wxheading{See also}
+
+\helpref{GetItemToolTip}{wxradioboxgetitemtooltip},\\
+\helpref{wxWindow::SetToolTip}{wxwindowsettooltip}
+
+
 \membersection{wxRadioBox::Show}\label{wxradioboxshow}
 
 \func{virtual bool}{Show}{\param{const bool}{ show = {\tt true}}}
index c02598fa6ca3e5ca393f9c8e3cbd62c4ac35c0ff..f3cd4d83317fc9211a83f6914b54ff306921b33a 100644 (file)
@@ -99,6 +99,9 @@ public:
     virtual void SetFocus();
     virtual bool SetFont(const wxFont& font);
     virtual bool ContainsHWND(WXHWND hWnd) const;
+#if wxUSE_TOOLTIPS
+    virtual bool HasToolTips() const;
+#endif // wxUSE_TOOLTIPS
 
     // we inherit a version always returning false from wxStaticBox, override
     // it to behave normally
@@ -137,6 +140,10 @@ protected:
                            int sizeFlags = wxSIZE_AUTO);
     virtual wxSize DoGetBestSize() const;
 
+#if wxUSE_TOOLTIPS
+    virtual void DoSetItemToolTip(unsigned int n, wxToolTip * tooltip);
+#endif
+
 #ifndef __WXWINCE__
     virtual WXHRGN MSWGetRegionWithoutChildren();
 #endif // __WXWINCE__
index 655f73b2bacba85a12ab9e97927f76f7ba07e038..dc9ab4be18c662bbf02565af3b9485d8a2cd90d1 100644 (file)
 
 #include "wx/ctrlsub.h"
 
+#if wxUSE_TOOLTIPS
+
+#include "wx/dynarray.h"
+
+class WXDLLEXPORT wxToolTip;
+
+WX_DEFINE_EXPORTED_ARRAY_PTR(wxToolTip *, wxToolTipArray);
+
+#endif // wxUSE_TOOLTIPS
+
 extern WXDLLEXPORT_DATA(const wxChar) wxRadioBoxNameStr[];
 
 // ----------------------------------------------------------------------------
@@ -27,6 +37,8 @@ extern WXDLLEXPORT_DATA(const wxChar) wxRadioBoxNameStr[];
 class WXDLLEXPORT wxRadioBoxBase : public wxItemContainerImmutable
 {
 public:
+    virtual ~wxRadioBoxBase();
+
     // change/query the individual radio button state
     virtual bool Enable(unsigned int n, bool enable = true) = 0;
     virtual bool Show(unsigned int n, bool show = true) = 0;
@@ -40,6 +52,14 @@ public:
     // return the item above/below/to the left/right of the given one
     int GetNextItem(int item, wxDirection dir, long style) const;
 
+#if wxUSE_TOOLTIPS
+    // set the tooltip text for a radio item, empty string unsets any tooltip
+    void SetItemToolTip(unsigned int item, const wxString& text);
+
+    // get the individual items tooltip; returns NULL if none
+    wxToolTip *GetItemToolTip(unsigned int item) const
+        { return m_itemsTooltips ? (*m_itemsTooltips)[item] : NULL; }
+#endif // wxUSE_TOOLTIPS
 
     // deprecated functions
     // --------------------
@@ -53,6 +73,10 @@ protected:
     wxRadioBoxBase()
     {
         m_majorDim = 0;
+
+#if wxUSE_TOOLTIPS
+        m_itemsTooltips = NULL;
+#endif // wxUSE_TOOLTIPS
     }
 
     // return the number of items in major direction (which depends on whether
@@ -64,6 +88,18 @@ protected:
     // the style parameter should be the style of the radiobox itself
     void SetMajorDim(unsigned int majorDim, long style);
 
+#if wxUSE_TOOLTIPS
+    // called from SetItemToolTip() to really set the tooltip for the specified
+    // item in the box (or, if tooltip is NULL, to remove any existing one).
+    //
+    // NB: this function should really be pure virtual but to avoid breaking
+    //     the build of the ports for which it's not implemented yet we provide
+    //     an empty stub in the base class for now
+    virtual void DoSetItemToolTip(unsigned int item, wxToolTip *tooltip);
+
+    // returns true if we have any item tooltips
+    bool HasItemToolTips() const { return m_itemsTooltips != NULL; }
+#endif // wxUSE_TOOLTIPS
 
 private:
     // the number of elements in major dimension (i.e. number of columns if
@@ -72,6 +108,13 @@ private:
     unsigned int m_majorDim,
                  m_numCols,
                  m_numRows;
+
+#if wxUSE_TOOLTIPS
+    // array of tooltips for the individual items
+    //
+    // this array is initially NULL and initialized on first use
+    wxToolTipArray *m_itemsTooltips;
+#endif
 };
 
 #if defined(__WXUNIVERSAL__)
index 0a0cdb04ef642261193e169af77b6a9e5dd31cb7..9275dc8041ee2dd8c403646d75e40b2a59faad63 100644 (file)
@@ -808,12 +808,21 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h )
     };
 
     panel = new wxPanel(m_book);
-    (void)new MyRadioBox( panel, ID_RADIOBOX, _T("&That"), wxPoint(10,160), wxDefaultSize, WXSIZEOF(choices2), choices2, 1, wxRA_SPECIFY_ROWS );
+    wxRadioBox *radio2 = new MyRadioBox( panel, ID_RADIOBOX, _T("&That"), wxPoint(10,160), wxDefaultSize, WXSIZEOF(choices2), choices2, 1, wxRA_SPECIFY_ROWS );
     m_radio = new wxRadioBox( panel, ID_RADIOBOX, _T("T&his"), wxPoint(10,10), wxDefaultSize, WXSIZEOF(choices), choices, 1, wxRA_SPECIFY_COLS );
 
 #if wxUSE_TOOLTIPS
     m_combo->SetToolTip(_T("This is a natural\ncombobox - can you believe me?"));
-    m_radio->SetToolTip(_T("Ever seen a radiobox?"));
+    radio2->SetToolTip(_T("Ever seen a radiobox?"));
+
+    //m_radio->SetToolTip(_T("Tooltip for the entire radiobox"));
+    for ( unsigned int nb = 0; nb < WXSIZEOF(choices); nb++ )
+    {
+        m_radio->SetItemToolTip(nb, _T("tooltip for\n") + choices[nb]);
+    }
+
+    // remove the tooltip for one of the items
+    m_radio->SetItemToolTip(2, _T(""));
 #endif // wxUSE_TOOLTIPS
 
     (void)new wxButton( panel, ID_RADIOBOX_SEL_NUM, _T("Select #&2"), wxPoint(180,30), wxSize(140,30) );
index 32adee107ad468dddbe0ede761182327cbaf13f4..1703e168a17ece2732b67e3937b286c96a627aac 100644 (file)
     #include "wx/radiobox.h"
 #endif //WX_PRECOMP
 
+#if wxUSE_TOOLTIPS
+    #include "wx/tooltip.h"
+#endif // wxUSE_TOOLTIPS
+
 // ============================================================================
 // implementation
 // ============================================================================
@@ -150,6 +154,78 @@ int wxRadioBoxBase::GetNextItem(int item, wxDirection dir, long style) const
     return item;
 }
 
+#if wxUSE_TOOLTIPS
+
+void wxRadioBoxBase::SetItemToolTip(unsigned int item, const wxString& text)
+{
+    wxASSERT_MSG( item < GetCount(), _T("Invalid item index") );
+
+    // extend the array to have entries for all our items on first use
+    if ( !m_itemsTooltips )
+    {
+        m_itemsTooltips = new wxToolTipArray;
+        m_itemsTooltips->resize(GetCount());
+    }
+
+    wxToolTip *tooltip = (*m_itemsTooltips)[item];
+
+    bool changed = true;
+    if ( text.empty() )
+    {
+        if ( tooltip )
+        {
+            // delete the tooltip
+            delete tooltip;
+            tooltip = NULL;
+        }
+        else // nothing to do
+        {
+            changed = false;
+        }
+    }
+    else // non empty tooltip text
+    {
+        if ( tooltip )
+        {
+            // just change the existing tooltip text, don't change the tooltip
+            tooltip->SetTip(text);
+            changed = false;
+        }
+        else // no tooltip yet
+        {
+            // create the new one
+            tooltip = new wxToolTip(text);
+        }
+    }
+
+    if ( changed )
+    {
+        (*m_itemsTooltips)[item] = tooltip;
+        DoSetItemToolTip(item, tooltip);
+    }
+}
+
+void
+wxRadioBoxBase::DoSetItemToolTip(unsigned int WXUNUSED(item),
+                                 wxToolTip * WXUNUSED(tooltip))
+{
+    // per-item tooltips not implemented by default
+}
+
+wxRadioBoxBase::~wxRadioBoxBase()
+{
+    if ( m_itemsTooltips )
+    {
+        const size_t n = m_itemsTooltips->size();
+        for ( size_t i = 0; i < n; i++ )
+            delete (*m_itemsTooltips)[i];
+
+        delete m_itemsTooltips;
+    }
+}
+
+#endif // wxUSE_TOOLTIPS
+
 #if WXWIN_COMPATIBILITY_2_4
 
 // these functions are deprecated and don't do anything
index b3a6b7f03db39982639c43a8fef2c93d81865c5d..9f0c6b131eb9638071897203c9c2541c46e4b3dc 100644 (file)
@@ -37,9 +37,6 @@
 #include "wx/msw/subwin.h"
 
 #if wxUSE_TOOLTIPS
-    #if !defined(__GNUWIN32_OLD__) || defined(__CYGWIN10__)
-        #include <commctrl.h>
-    #endif
     #include "wx/tooltip.h"
 #endif // wxUSE_TOOLTIPS
 
@@ -421,6 +418,25 @@ bool wxRadioBox::IsItemShown(unsigned int item) const
                             GWL_STYLE) & WS_VISIBLE) != 0;
 }
 
+#if wxUSE_TOOLTIPS
+
+bool wxRadioBox::HasToolTips() const
+{
+    return wxStaticBox::HasToolTips() || wxRadioBoxBase::HasItemToolTips();
+}
+
+void wxRadioBox::DoSetItemToolTip(unsigned int item, wxToolTip *tooltip)
+{
+    // we have already checked for the item to be valid in wxRadioBoxBase
+    const HWND hwndRbtn = (*m_radioButtons)[item];
+    if ( tooltip != NULL )
+        tooltip->Add(hwndRbtn);
+    else // unset the tooltip
+        wxToolTip::Remove(hwndRbtn);
+}
+
+#endif // wxUSE_TOOLTIPS
+
 WX_FORWARD_STD_METHODS_TO_SUBWINDOWS(wxRadioBox, wxStaticBox, m_radioButtons)
 
 // ----------------------------------------------------------------------------