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
This commit is contained in:
Vadim Zeitlin
2006-05-04 22:54:17 +00:00
parent ab0c98223a
commit d64ad2c7e1
4 changed files with 64 additions and 21 deletions

View File

@@ -408,6 +408,9 @@ wxRadioBox
This control may have "dimension" (major dimension) and (initial) "selection" This control may have "dimension" (major dimension) and (initial) "selection"
Integer subelements and a composite "content" element similar to wxCheckList. 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 wxScrolledWindow
---------------- ----------------

View File

@@ -24,9 +24,14 @@ public:
virtual bool CanHandle(wxXmlNode *node); virtual bool CanHandle(wxXmlNode *node);
private: private:
bool m_insideBox; 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_ #endif // _WX_XH_RADBX_H_

View File

@@ -74,6 +74,7 @@
<object class="sizeritem"> <object class="sizeritem">
<flag>wxALIGN_CENTER_VERTICAL|wxALL</flag> <flag>wxALIGN_CENTER_VERTICAL|wxALL</flag>
<border>5</border> <border>5</border>
<size>300,60</size>
<object class="wxToolBar"> <object class="wxToolBar">
<style>wxTB_FLAT|wxTB_NODIVIDER</style> <style>wxTB_FLAT|wxTB_NODIVIDER</style>
<margins>2,2</margins> <margins>2,2</margins>
@@ -118,6 +119,13 @@
<bitmap>variable.xpm</bitmap> <bitmap>variable.xpm</bitmap>
<longhelp>Replace variables in the XRC file at runtime</longhelp> <longhelp>Replace variables in the XRC file at runtime</longhelp>
</object> </object>
<object class="wxComboBox">
<content>
<item>Just</item>
<item>a combobox</item>
<item>in the toolbar</item>
</content>
</object>
</object> </object>
</object> </object>
<object class="sizeritem"> <object class="sizeritem">
@@ -175,6 +183,13 @@
<bitmap>variable.xpm</bitmap> <bitmap>variable.xpm</bitmap>
<longhelp>Replace variables in the XRC file at runtime</longhelp> <longhelp>Replace variables in the XRC file at runtime</longhelp>
</object> </object>
<object class="wxComboBox">
<content>
<item>Just</item>
<item>a combobox</item>
<item>in the toolbar</item>
</content>
</object>
</object> </object>
</object> </object>
</object> </object>
@@ -618,9 +633,9 @@
<dimension>1</dimension> <dimension>1</dimension>
<selection>0</selection> <selection>0</selection>
<content> <content>
<item>Power 108</item> <item tooltip="Powerful radio station">Power 108</item>
<item>WMMS 100.7</item> <item tooltip="">WMMS 100.7</item>
<item>Energy 98.3</item> <item tooltip="E=mc^2">Energy 98.3</item>
<item>CHUM FM</item> <item>CHUM FM</item>
<item>92FM</item> <item>92FM</item>
</content> </content>

View File

@@ -39,7 +39,7 @@ wxRadioBoxXmlHandler::wxRadioBoxXmlHandler()
wxObject *wxRadioBoxXmlHandler::DoCreateResource() wxObject *wxRadioBoxXmlHandler::DoCreateResource()
{ {
if( m_class == wxT("wxRadioBox")) if ( m_class == wxT("wxRadioBox"))
{ {
// find the selection // find the selection
long selection = GetLong( wxT("selection"), -1 ); long selection = GetLong( wxT("selection"), -1 );
@@ -47,13 +47,18 @@ wxObject *wxRadioBoxXmlHandler::DoCreateResource()
// need to build the list of strings from children // need to build the list of strings from children
m_insideBox = true; m_insideBox = true;
CreateChildrenPrivately( NULL, GetParamNode(wxT("content"))); CreateChildrenPrivately( NULL, GetParamNode(wxT("content")));
wxString *strings = (wxString *) NULL;
if( strList.GetCount() > 0 ) wxString *strings;
if ( !labels.empty() )
{ {
strings = new wxString[strList.GetCount()]; strings = new wxString[labels.size()];
int count = strList.GetCount(); const unsigned count = labels.size();
for( int i = 0; i < count; i++ ) for( unsigned i = 0; i < count; i++ )
strings[i]=strList[i]; strings[i] = labels[i];
}
else
{
strings = NULL;
} }
XRC_MAKE_INSTANCE(control, wxRadioBox) XRC_MAKE_INSTANCE(control, wxRadioBox)
@@ -62,34 +67,49 @@ wxObject *wxRadioBoxXmlHandler::DoCreateResource()
GetID(), GetID(),
GetText(wxT("label")), GetText(wxT("label")),
GetPosition(), GetSize(), GetPosition(), GetSize(),
strList.GetCount(), labels.size(),
strings, strings,
GetLong(wxT("dimension"), 1), GetLong(wxT("dimension"), 1),
GetStyle(), GetStyle(),
wxDefaultValidator, wxDefaultValidator,
GetName()); GetName());
delete[] strings;
if (selection != -1) if (selection != -1)
control->SetSelection(selection); control->SetSelection(selection);
SetupWindow(control); SetupWindow(control);
if (strings != NULL) const unsigned count = labels.size();
delete[] strings; for( unsigned i = 0; i < count; i++ )
strList.Clear(); // dump the strings {
if ( !tooltips[i].empty() )
control->SetItemToolTip(i, tooltips[i]);
}
labels.clear(); // dump the strings
tooltips.clear(); // dump the tooltips
return control; return control;
} }
else else // inside the radiobox element
{ {
// on the inside now. // we handle <item tooltip="...">Label</item> constructs here
// handle <item selected="boolean">Label</item>
// add to the list
wxString str = GetNodeContent(m_node); wxString str = GetNodeContent(m_node);
wxString tooltip;
m_node->GetPropVal(wxT("tooltip"), &tooltip);
if (m_resource->GetFlags() & wxXRC_USE_LOCALE) if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
{
str = wxGetTranslation(str); str = wxGetTranslation(str);
strList.Add(str); if ( !tooltip.empty() )
tooltip = wxGetTranslation(tooltip);
}
labels.push_back(str);
tooltips.push_back(tooltip);
return NULL; return NULL;
} }