From: Vadim Zeitlin Date: Sat, 2 Aug 2008 18:21:38 +0000 (+0000) Subject: added enabled and hidden attributes to radio box items in XRC X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/8758875e0b001444cb677906e68912cb455ab275?ds=inline 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 --- diff --git a/docs/changes.txt b/docs/changes.txt index 41c0899b87..13f9c16e4b 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -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: diff --git a/docs/tech/tn0014.txt b/docs/tech/tn0014.txt index 75b492fda0..136a8c043d 100644 --- a/docs/tech/tn0014.txt +++ b/docs/tech/tn0014.txt @@ -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 subelements can have additional attributes: + +tooltip I18nString "" +helptext I18nString "" +enabled Boolean 1 +hidden Boolean 0 wxScrolledWindow diff --git a/include/wx/xrc/xh_radbx.h b/include/wx/xrc/xh_radbx.h index 94ee62498d..53638089f4 100644 --- a/include/wx/xrc/xh_radbx.h +++ b/include/wx/xrc/xh_radbx.h @@ -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 diff --git a/include/wx/xrc/xmlres.h b/include/wx/xrc/xmlres.h index 9321e4c186..2f941d9f00 100644 --- a/include/wx/xrc/xmlres.h +++ b/include/wx/xrc/xmlres.h @@ -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); diff --git a/samples/xrc/rc/controls.xrc b/samples/xrc/rc/controls.xrc index d9cf1813b8..909bbef433 100644 --- a/samples/xrc/rc/controls.xrc +++ b/samples/xrc/rc/controls.xrc @@ -704,10 +704,12 @@ 0 Power 108 + Power 0 WMMS 100.7 Energy 98.3 CHUM FM 92FM + diff --git a/src/common/filename.cpp b/src/common/filename.cpp index ee7e4d412a..1e3444bc87 100644 --- a/src/common/filename.cpp +++ b/src/common/filename.cpp @@ -1026,55 +1026,55 @@ wxFileName::CreateTempFileName(const wxString& prefix, wxFFile *fileTemp) // directory operations // ---------------------------------------------------------------------------- -wxString wxFileName::GetTempDir() +// helper of GetTempDir(): check if the given directory exists and return it if +// it does or an empty string otherwise +namespace { - wxString dir; - dir = wxGetenv(_T("TMPDIR")); - if (dir.empty()) - { - dir = wxGetenv(_T("TMP")); - if (dir.empty()) - { - dir = wxGetenv(_T("TEMP")); - } - } -#if defined(__WXWINCE__) - if (dir.empty()) +wxString CheckIfDirExists(const wxString& dir) +{ + return wxFileName::DirExists(dir) ? dir : wxString(); +} + +} // anonymous namespace + +wxString wxFileName::GetTempDir() +{ + // 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() ) { - // FIXME. Create \temp dir? - if (DirExists(wxT("\\temp"))) - dir = wxT("\\temp"); + dir = CheckIfDirExists(wxGetenv("TMP")); + if ( dir.empty() ) + dir = CheckIfDirExists(wxGetenv("TEMP")); } -#elif defined(__WINDOWS__) && !defined(__WXMICROWIN__) + // if no environment variables are set, use the system default if ( dir.empty() ) { +#if defined(__WXWINCE__) + dir = CheckIfDirExists(wxT("\\temp")); +#elif defined(__WINDOWS__) && !defined(__WXMICROWIN__) 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('.'); - } +#elif defined(__WXMAC__) && wxOSX_USE_CARBON + dir = wxMacFindFolder(short(kOnSystemDisk), kTemporaryFolderType, kCreateFolder); +#endif // systems with native way } -#else // !Windows + // fall back to hard coded value 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 +#ifdef __UNIX_LIKE__ + dir = CheckIfDirExists("/tmp"); + if ( dir.empty() ) +#endif // __UNIX_LIKE__ + dir = "."; } -#endif return dir; } diff --git a/src/xrc/xh_radbx.cpp b/src/xrc/xh_radbx.cpp index dbbf54b5e4..c6ee9307a6 100644 --- a/src/xrc/xh_radbx.cpp +++ b/src/xrc/xh_radbx.cpp @@ -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 Label constructs here + // we handle handle Label 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; } diff --git a/src/xrc/xmlres.cpp b/src/xrc/xmlres.cpp index dd6447b9fa..3a6cbefc6b 100644 --- a/src/xrc/xmlres.cpp +++ b/src/xrc/xmlres.cpp @@ -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'); }