bool wxXmlResource::Load(const wxString& filemask)
{
- wxString fnd;
- bool iswild = wxIsWild(filemask);
- bool rt = true;
-
#if wxUSE_FILESYSTEM
wxFileSystem fsys;
# define wxXmlFindFirst fsys.FindFirst(filemask, wxFILE)
# define wxXmlFindFirst wxFindFirstFile(filemask, wxFILE)
# define wxXmlFindNext wxFindNextFile()
#endif
- if (iswild)
- fnd = wxXmlFindFirst;
- else
- fnd = filemask;
+ wxString fnd = wxXmlFindFirst;
+ if ( fnd.empty() )
+ {
+ wxLogError(_("Cannot load resources from '%s'."), filemask);
+ return false;
+ }
+
while (!fnd.empty())
{
fnd = ConvertFileNameToURL(fnd);
#if wxUSE_FILESYSTEM
if ( IsArchive(fnd) )
{
- rt = rt && Load(fnd + wxT("#zip:*.xrc"));
+ if ( !Load(fnd + wxT("#zip:*.xrc")) )
+ return false;
}
else // a single resource URL
#endif // wxUSE_FILESYSTEM
Data().push_back(drec);
}
- if (iswild)
- fnd = wxXmlFindNext;
- else
- fnd = wxEmptyString;
+ fnd = wxXmlFindNext;
}
# undef wxXmlFindFirst
# undef wxXmlFindNext
- return rt && UpdateResources();
+
+ return UpdateResources();
}
bool wxXmlResource::Unload(const wxString& filename)
delete rec->Doc;
rec->Doc = new wxXmlDocument;
}
- if (!stream || !rec->Doc->Load(*stream, encoding))
+ if (!stream || !stream->IsOk() || !rec->Doc->Load(*stream, encoding))
{
wxLogError(_("Cannot load resources from file '%s'."),
rec->File);
+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');
}
while (n)
{
if (n->GetType() == wxXML_ELEMENT_NODE && n->GetName() == param)
+ {
+ // TODO: check that there are no other properties/parameters with
+ // the same name and log an error if there are (can't do this
+ // right now as I'm not sure if it's not going to break code
+ // using this function in unintentional way (i.e. for
+ // accessing other things than properties), for example
+ // wxBitmapComboBoxXmlHandler almost surely does
return n;
+ }
n = n->GetNext();
}
return NULL;
}
-
-
bool wxXmlResourceHandler::IsOfClass(wxXmlNode *node, const wxString& classname)
{
return node->GetAttribute(wxT("class"), wxEmptyString) == classname;
return XRCID_Lookup(str_id, value_if_not_found);
}
+/* static */
+wxString wxXmlResource::FindXRCIDById(int numId)
+{
+ for ( int i = 0; i < XRCID_TABLE_SIZE; i++ )
+ {
+ for ( XRCID_record *rec = XRCID_Records[i]; rec; rec = rec->next )
+ {
+ if ( rec->id == numId )
+ return wxString(rec->key);
+ }
+ }
+
+ return wxString();
+}
static void CleanXRCID_Record(XRCID_record *rec)
{