added enabled and hidden attributes to radio box items in XRC

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@54929 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2008-08-02 18:21:38 +00:00
parent 8a18ea3f03
commit 8758875e0b
8 changed files with 110 additions and 83 deletions

View File

@@ -377,6 +377,7 @@ All (GUI):
- Added wxVListBox::GetItemRect() (Javier Urien).
- Show busy cursor in wxLaunchDefaultBrowser and add wxBROWSER_NOBUSYCURSOR.
- Added wxFlexGridSizer::Is{Row,Col}Growable() (Marcin Wojdyr).
- Added "enabled" and "hidden" attributes to radio box items in XRC.
wxGTK:

View File

@@ -421,10 +421,13 @@ 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" and "helptext=I18nString" attributes to specify
the per-item tooltip and helptext.
Integer subelements and a composite "content" element similar to wxCheckList
except that <item> subelements can have additional attributes:
tooltip I18nString ""
helptext I18nString ""
enabled Boolean 1
hidden Boolean 0
wxScrolledWindow

View File

@@ -28,14 +28,21 @@ private:
bool m_insideBox;
// the items labels
wxArrayString labels;
wxArrayString m_labels;
#if wxUSE_TOOLTIPS
// the items tooltips
wxArrayString tooltips;
wxArrayString m_tooltips;
#endif // wxUSE_TOOLTIPS
// the item help text
wxArrayString helptexts;
wxArrayInt helptextSpecified;
wxArrayString m_helptexts;
wxArrayInt m_helptextSpecified;
// if the corresponding array element is 1, the radiobox item is
// disabled/hidden
wxArrayInt m_isEnabled,
m_isShown;
};
#endif // wxUSE_XRC && wxUSE_RADIOBOX

View File

@@ -462,6 +462,10 @@ protected:
// Gets a font.
wxFont GetFont(const wxString& param = wxT("font"));
// Gets the value of a boolean attribute (only "0" and "1" are valid values)
bool GetBoolAttr(const wxString& attr, bool defaultv);
// Sets common window options.
void SetupWindow(wxWindow *wnd);

View File

@@ -704,10 +704,12 @@
<selection>0</selection>
<content>
<item tooltip="Powerful radio station" helptext="This station is for amateurs of hard rock and heavy metal">Power 108</item>
<item tooltip="Disabled radio station" enabled="0">Power 0</item>
<item tooltip="">WMMS 100.7</item>
<item tooltip="E=mc^2">Energy 98.3</item>
<item helptext="Favourite chukcha's radio">CHUM FM</item>
<item>92FM</item>
<item hidden="1">Very quite station</item>
</content>
</object>
</object>

View File

@@ -1026,55 +1026,55 @@ wxFileName::CreateTempFileName(const wxString& prefix, wxFFile *fileTemp)
// directory operations
// ----------------------------------------------------------------------------
// helper of GetTempDir(): check if the given directory exists and return it if
// it does or an empty string otherwise
namespace
{
wxString CheckIfDirExists(const wxString& dir)
{
return wxFileName::DirExists(dir) ? dir : wxString();
}
} // anonymous namespace
wxString wxFileName::GetTempDir()
{
wxString dir;
dir = wxGetenv(_T("TMPDIR"));
// first try getting it from environment: this allows overriding the values
// used by default if the user wants to create temporary files in another
// directory
wxString dir = CheckIfDirExists(wxGetenv("TMPDIR"));
if ( dir.empty() )
{
dir = wxGetenv(_T("TMP"));
dir = CheckIfDirExists(wxGetenv("TMP"));
if ( dir.empty() )
{
dir = wxGetenv(_T("TEMP"));
}
dir = CheckIfDirExists(wxGetenv("TEMP"));
}
// if no environment variables are set, use the system default
if ( dir.empty() )
{
#if defined(__WXWINCE__)
if (dir.empty())
{
// FIXME. Create \temp dir?
if (DirExists(wxT("\\temp")))
dir = wxT("\\temp");
}
dir = CheckIfDirExists(wxT("\\temp"));
#elif defined(__WINDOWS__) && !defined(__WXMICROWIN__)
if ( dir.empty() )
{
if ( !::GetTempPath(MAX_PATH, wxStringBuffer(dir, MAX_PATH + 1)) )
{
wxLogLastError(_T("GetTempPath"));
}
if ( dir.empty() )
{
// GetTempFileName() fails if we pass it an empty string
dir = _T('.');
}
}
#else // !Windows
if ( dir.empty() )
{
// default
#if defined(__DOS__) || defined(__OS2__)
dir = _T(".");
#elif defined(__WXMAC__) && wxOSX_USE_CARBON
dir = wxMacFindFolder(short(kOnSystemDisk), kTemporaryFolderType, kCreateFolder);
#else
dir = _T("/tmp");
#endif
#endif // systems with native way
}
// fall back to hard coded value
if ( dir.empty() )
{
#ifdef __UNIX_LIKE__
dir = CheckIfDirExists("/tmp");
if ( dir.empty() )
#endif // __UNIX_LIKE__
dir = ".";
}
#endif
return dir;
}

View File

@@ -47,66 +47,66 @@ wxObject *wxRadioBoxXmlHandler::DoCreateResource()
m_insideBox = true;
CreateChildrenPrivately( NULL, GetParamNode(wxT("content")));
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 = NULL;
}
XRC_MAKE_INSTANCE(control, wxRadioBox)
control->Create(m_parentAsWindow,
GetID(),
GetText(wxT("label")),
GetPosition(), GetSize(),
labels.size(),
strings,
m_labels,
GetLong(wxT("dimension"), 1),
GetStyle(),
wxDefaultValidator,
GetName());
delete[] strings;
if (selection != -1)
control->SetSelection(selection);
SetupWindow(control);
const unsigned count = labels.size();
const unsigned count = m_labels.size();
for( unsigned i = 0; i < count; i++ )
{
#if wxUSE_TOOLTIPS
if ( !tooltips[i].empty() )
control->SetItemToolTip(i, tooltips[i]);
if ( !m_tooltips[i].empty() )
control->SetItemToolTip(i, m_tooltips[i]);
#endif // wxUSE_TOOLTIPS
#if wxUSE_HELP
if ( helptextSpecified[i] )
control->SetItemHelpText(i, helptexts[i]);
if ( m_helptextSpecified[i] )
control->SetItemHelpText(i, m_helptexts[i]);
#endif // wxUSE_HELP
if ( !m_isShown[i] )
control->Show(i, false);
if ( !m_isEnabled[i] )
control->Enable(i, false);
}
labels.clear(); // dump the strings
tooltips.clear(); // dump the tooltips
// forget information about the items of this radiobox, we should start
// afresh for the next one
m_labels.clear();
helptexts.clear(); // dump the helptexts
helptextSpecified.clear();
#if wxUSE_TOOLTIPS
m_tooltips.clear();
#endif // wxUSE_TOOLTIPS
#if wxUSE_HELP
m_helptexts.clear();
m_helptextSpecified.clear();
#endif // wxUSE_HELP
m_isShown.clear();
m_isEnabled.clear();
return control;
}
else // inside the radiobox element
{
// we handle handle <item tooltip="..." helptext="...">Label</item> constructs here
// we handle handle <item>Label</item> constructs here, and the item
// tag can have tooltip, helptext, enabled and hidden attributes
wxString str = GetNodeContent(m_node);
wxString label = GetNodeContent(m_node);
wxString tooltip;
m_node->GetAttribute(wxT("tooltip"), &tooltip);
@@ -116,17 +116,23 @@ wxObject *wxRadioBoxXmlHandler::DoCreateResource()
if (m_resource->GetFlags() & wxXRC_USE_LOCALE)
{
str = wxGetTranslation(str, m_resource->GetDomain());
label = wxGetTranslation(label, m_resource->GetDomain());
if ( !tooltip.empty() )
tooltip = wxGetTranslation(tooltip, m_resource->GetDomain());
if ( hasHelptext )
helptext = wxGetTranslation(helptext, m_resource->GetDomain());
}
labels.push_back(str);
tooltips.push_back(tooltip);
helptexts.push_back(helptext);
helptextSpecified.push_back(hasHelptext);
m_labels.push_back(label);
#if wxUSE_TOOLTIPS
m_tooltips.push_back(tooltip);
#endif // wxUSE_TOOLTIPS
#if wxUSE_HELP
m_helptexts.push_back(helptext);
m_helptextSpecified.push_back(hasHelptext);
#endif // wxUSE_HELP
m_isEnabled.push_back(GetBoolAttr("enabled", 1));
m_isShown.push_back(!GetBoolAttr("hidden", 0));
return NULL;
}

View File

@@ -1031,13 +1031,17 @@ wxString wxXmlResourceHandler::GetName()
bool wxXmlResourceHandler::GetBoolAttr(const wxString& attr, bool defaultv)
{
wxString v;
return m_node->GetAttribute(attr, &v) ? v == '1' : defaultv;
}
bool wxXmlResourceHandler::GetBool(const wxString& param, bool defaultv)
{
wxString v = GetParamValue(param);
v.MakeLower();
if (!v) return defaultv;
const wxString v = GetParamValue(param);
return (v == wxT("1"));
return v.empty() ? defaultv : (v == '1');
}