added Get/SetItemToolTip() (and implemented them for MSW) to allow setting tooltips for the individual radiobox items
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39030 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -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,
|
||||
|
@@ -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}}}
|
||||
|
@@ -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__
|
||||
|
@@ -16,6 +16,16 @@
|
||||
|
||||
#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__)
|
||||
|
@@ -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) );
|
||||
|
@@ -30,6 +30,10 @@
|
||||
#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
|
||||
|
@@ -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)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user