From d64ad2c7e18f23ae0d6458a009bf832c04dde2aa Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 4 May 2006 22:54:17 +0000 Subject: [PATCH 1/1] added support for radiobox items tooltips in XRC git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39036 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/tech/tn0014.txt | 3 +++ include/wx/xrc/xh_radbx.h | 9 +++++-- samples/xrc/rc/controls.xrc | 21 ++++++++++++--- src/xrc/xh_radbx.cpp | 52 +++++++++++++++++++++++++------------ 4 files changed, 64 insertions(+), 21 deletions(-) diff --git a/docs/tech/tn0014.txt b/docs/tech/tn0014.txt index 9001edbbfa..ad67f45742 100644 --- a/docs/tech/tn0014.txt +++ b/docs/tech/tn0014.txt @@ -408,6 +408,9 @@ wxRadioBox This control may have "dimension" (major dimension) and (initial) "selection" Integer subelements and a composite "content" element similar to wxCheckList. +The only difference is that the "item" subelements can have an optional +"tooltip=I18nString" attribute to specify the per-item tooltip. + wxScrolledWindow ---------------- diff --git a/include/wx/xrc/xh_radbx.h b/include/wx/xrc/xh_radbx.h index c68da5a3b4..ac1c14b1d7 100644 --- a/include/wx/xrc/xh_radbx.h +++ b/include/wx/xrc/xh_radbx.h @@ -24,9 +24,14 @@ public: virtual bool CanHandle(wxXmlNode *node); private: bool m_insideBox; - wxArrayString strList; + + // the items labels + wxArrayString labels; + + // the items tooltips (some or all elements may be empty) + wxArrayString tooltips; }; -#endif +#endif // wxUSE_RADIOBOX #endif // _WX_XH_RADBX_H_ diff --git a/samples/xrc/rc/controls.xrc b/samples/xrc/rc/controls.xrc index 707441abc5..59c5b35374 100644 --- a/samples/xrc/rc/controls.xrc +++ b/samples/xrc/rc/controls.xrc @@ -74,6 +74,7 @@ wxALIGN_CENTER_VERTICAL|wxALL 5 + 300,60 2,2 @@ -118,6 +119,13 @@ variable.xpm Replace variables in the XRC file at runtime + + + Just + a combobox + in the toolbar + + @@ -175,6 +183,13 @@ variable.xpm Replace variables in the XRC file at runtime + + + Just + a combobox + in the toolbar + + @@ -618,9 +633,9 @@ 1 0 - Power 108 - WMMS 100.7 - Energy 98.3 + Power 108 + WMMS 100.7 + Energy 98.3 CHUM FM 92FM diff --git a/src/xrc/xh_radbx.cpp b/src/xrc/xh_radbx.cpp index 7bc108302e..9beea7ba9d 100644 --- a/src/xrc/xh_radbx.cpp +++ b/src/xrc/xh_radbx.cpp @@ -39,7 +39,7 @@ wxRadioBoxXmlHandler::wxRadioBoxXmlHandler() wxObject *wxRadioBoxXmlHandler::DoCreateResource() { - if( m_class == wxT("wxRadioBox")) + if ( m_class == wxT("wxRadioBox")) { // find the selection long selection = GetLong( wxT("selection"), -1 ); @@ -47,13 +47,18 @@ wxObject *wxRadioBoxXmlHandler::DoCreateResource() // need to build the list of strings from children m_insideBox = true; CreateChildrenPrivately( NULL, GetParamNode(wxT("content"))); - wxString *strings = (wxString *) NULL; - if( strList.GetCount() > 0 ) + + wxString *strings; + if ( !labels.empty() ) + { + strings = new wxString[labels.size()]; + const unsigned count = labels.size(); + for( unsigned i = 0; i < count; i++ ) + strings[i] = labels[i]; + } + else { - strings = new wxString[strList.GetCount()]; - int count = strList.GetCount(); - for( int i = 0; i < count; i++ ) - strings[i]=strList[i]; + strings = NULL; } XRC_MAKE_INSTANCE(control, wxRadioBox) @@ -62,34 +67,49 @@ wxObject *wxRadioBoxXmlHandler::DoCreateResource() GetID(), GetText(wxT("label")), GetPosition(), GetSize(), - strList.GetCount(), + labels.size(), strings, GetLong(wxT("dimension"), 1), GetStyle(), wxDefaultValidator, GetName()); + delete[] strings; + if (selection != -1) control->SetSelection(selection); SetupWindow(control); - if (strings != NULL) - delete[] strings; - strList.Clear(); // dump the strings + const unsigned count = labels.size(); + for( unsigned i = 0; i < count; i++ ) + { + if ( !tooltips[i].empty() ) + control->SetItemToolTip(i, tooltips[i]); + } + + labels.clear(); // dump the strings + tooltips.clear(); // dump the tooltips return control; } - else + else // inside the radiobox element { - // on the inside now. - // handle Label + // we handle Label constructs here - // add to the list wxString str = GetNodeContent(m_node); + wxString tooltip; + m_node->GetPropVal(wxT("tooltip"), &tooltip); + if (m_resource->GetFlags() & wxXRC_USE_LOCALE) + { str = wxGetTranslation(str); - strList.Add(str); + if ( !tooltip.empty() ) + tooltip = wxGetTranslation(tooltip); + } + + labels.push_back(str); + tooltips.push_back(tooltip); return NULL; } -- 2.45.2