X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/718cf16095911aff708013e3615ee56f6b730313..cdb105516c7934613e22c4ae2b0936ea77ad17ca:/src/xrc/xmlres.cpp?ds=sidebyside diff --git a/src/xrc/xmlres.cpp b/src/xrc/xmlres.cpp index dda368212b..b0376ee851 100644 --- a/src/xrc/xmlres.cpp +++ b/src/xrc/xmlres.cpp @@ -32,6 +32,7 @@ #include "wx/bitmap.h" #include "wx/image.h" #include "wx/fontmap.h" +#include "wx/artprov.h" #include "wx/xrc/xml.h" #include "wx/xrc/xmlres.h" @@ -268,8 +269,8 @@ static void ProcessPlatformProperty(wxXmlNode *node) } else { - node->RemoveChild(c); wxXmlNode *c2 = c->GetNext(); + node->RemoveChild(c); delete c; c = c2; } @@ -372,9 +373,9 @@ void wxXmlResource::UpdateResources() } -wxXmlNode *wxXmlResource::DoFindResource(wxXmlNode *parent, - const wxString& name, - const wxString& classname, +wxXmlNode *wxXmlResource::DoFindResource(wxXmlNode *parent, + const wxString& name, + const wxString& classname, bool recursive) { wxString dummy; @@ -384,10 +385,10 @@ wxXmlNode *wxXmlResource::DoFindResource(wxXmlNode *parent, // where the resource is most commonly looked for): for (node = parent->GetChildren(); node; node = node->GetNext()) { - if ( node->GetType() == wxXML_ELEMENT_NODE && - (node->GetName() == wxT("object") || + if ( node->GetType() == wxXML_ELEMENT_NODE && + (node->GetName() == wxT("object") || node->GetName() == wxT("object_ref")) && - (!classname || + (!classname || node->GetPropVal(wxT("class"), wxEmptyString) == classname) && node->GetPropVal(wxT("name"), &dummy) && dummy == name ) return node; @@ -396,8 +397,8 @@ wxXmlNode *wxXmlResource::DoFindResource(wxXmlNode *parent, if ( recursive ) for (node = parent->GetChildren(); node; node = node->GetNext()) { - if ( node->GetType() == wxXML_ELEMENT_NODE && - (node->GetName() == wxT("object") || + if ( node->GetType() == wxXML_ELEMENT_NODE && + (node->GetName() == wxT("object") || node->GetName() == wxT("object_ref")) ) { wxXmlNode* found = DoFindResource(node, name, classname, TRUE); @@ -409,7 +410,7 @@ wxXmlNode *wxXmlResource::DoFindResource(wxXmlNode *parent, return NULL; } -wxXmlNode *wxXmlResource::FindResource(const wxString& name, +wxXmlNode *wxXmlResource::FindResource(const wxString& name, const wxString& classname, bool recursive) { @@ -421,7 +422,7 @@ wxXmlNode *wxXmlResource::FindResource(const wxString& name, if ( m_data[f].Doc == NULL || m_data[f].Doc->GetRoot() == NULL ) continue; - wxXmlNode* found = DoFindResource(m_data[f].Doc->GetRoot(), + wxXmlNode* found = DoFindResource(m_data[f].Doc->GetRoot(), name, classname, recursive); if ( found ) { @@ -445,7 +446,7 @@ static void MergeNodes(wxXmlNode& dest, wxXmlNode& with) wxXmlProperty *dprop; for (dprop = dest.GetProperties(); dprop; dprop = dprop->GetNext()) { - + if ( dprop->GetName() == prop->GetName() ) { dprop->SetValue(prop->GetValue()); @@ -494,7 +495,7 @@ wxObject *wxXmlResource::CreateResFromNode(wxXmlNode *node, wxObject *parent, wx if ( !refNode ) { - wxLogError(_("Referenced object node with ref=\"%s\" not found!"), + wxLogError(_("Referenced object node with ref=\"%s\" not found!"), refName.c_str()); return NULL; } @@ -543,7 +544,7 @@ wxObject *wxXmlResourceHandler::CreateResource(wxXmlNode *node, wxObject *parent wxWindow *myParentAW = m_parentAsWindow, *myInstanceAW = m_instanceAsWindow; m_instance = instance; - if (!m_instance && node->HasProp(wxT("subclass")) && + if (!m_instance && node->HasProp(wxT("subclass")) && !(m_resource->GetFlags() & wxXRC_NO_SUBCLASSING)) { wxString subclass = node->GetPropVal(wxT("subclass"), wxEmptyString); @@ -551,7 +552,7 @@ wxObject *wxXmlResourceHandler::CreateResource(wxXmlNode *node, wxObject *parent if (classInfo) m_instance = classInfo->CreateObject(); - + if (!m_instance) { wxLogError(_("Subclass '%s' not found for resource '%s', not subclassing!"), @@ -638,8 +639,8 @@ wxString wxXmlResourceHandler::GetText(const wxString& param, bool translate) const wxChar *dt; wxChar amp_char; - // VS: First version of XRC resources used $ instead of & (which is - // illegal in XML), but later I realized that '_' fits this purpose + // VS: First version of XRC resources used $ instead of & (which is + // illegal in XML), but later I realized that '_' fits this purpose // much better (because &File means "File with F underlined"). if (m_resource->CompareVersion(2,3,0,1) < 0) amp_char = wxT('$'); @@ -668,7 +669,7 @@ wxString wxXmlResourceHandler::GetText(const wxString& param, bool translate) } else str2 << *dt; } - + if (translate && m_resource->GetFlags() & wxXRC_USE_LOCALE) return wxGetTranslation(str2); else @@ -690,6 +691,7 @@ long wxXmlResourceHandler::GetLong(const wxString& param, long defaultv) } + int wxXmlResourceHandler::GetID() { wxString sid = GetName(); @@ -716,6 +718,7 @@ int wxXmlResourceHandler::GetID() } + wxString wxXmlResourceHandler::GetName() { return m_node->GetPropVal(wxT("name"), wxT("-1")); @@ -753,10 +756,30 @@ wxColour wxXmlResourceHandler::GetColour(const wxString& param) -wxBitmap wxXmlResourceHandler::GetBitmap(const wxString& param, wxSize size) +wxBitmap wxXmlResourceHandler::GetBitmap(const wxString& param, + const wxArtClient& defaultArtClient, + wxSize size) { + /* If the bitmap is specified as stock item, query wxArtProvider for it: */ + wxXmlNode *bmpNode = GetParamNode(param); + if ( bmpNode ) + { + wxString sid = bmpNode->GetPropVal(wxT("stock_id"), wxEmptyString); + if ( !sid.empty() ) + { + wxString scl = bmpNode->GetPropVal(wxT("stock_client"), defaultArtClient); + wxBitmap stockArt = + wxArtProvider::GetBitmap(wxART_MAKE_ART_ID_FROM_STR(sid), + wxART_MAKE_CLIENT_ID_FROM_STR(scl), + size); + if ( stockArt.Ok() ) + return stockArt; + } + } + + /* ...or load the bitmap from file: */ wxString name = GetParamValue(param); - if (name.IsEmpty()) return wxNullBitmap; + if (name.IsEmpty()) return wxNullBitmap; #if wxUSE_FILESYSTEM wxFSFile *fsfile = GetCurFileSystem().OpenFile(name); if (fsfile == NULL) @@ -769,22 +792,26 @@ wxBitmap wxXmlResourceHandler::GetBitmap(const wxString& param, wxSize size) #else wxImage img(GetParamValue(wxT("bitmap"))); #endif + if (!img.Ok()) { wxLogError(_("XRC resource: Cannot create bitmap from '%s'."), param.c_str()); return wxNullBitmap; } if (!(size == wxDefaultSize)) img.Rescale(size.x, size.y); - return img.ConvertToBitmap(); + return wxBitmap(img); + } -wxIcon wxXmlResourceHandler::GetIcon(const wxString& param, wxSize size) +wxIcon wxXmlResourceHandler::GetIcon(const wxString& param, + const wxArtClient& defaultArtClient, + wxSize size) { #if wxCHECK_VERSION(2,3,0) || defined(__WXMSW__) wxIcon icon; - icon.CopyFromBitmap(GetBitmap(param, size)); + icon.CopyFromBitmap(GetBitmap(param, defaultArtClient, size)); #else wxIcon *iconpt; wxBitmap bmppt = GetBitmap(param, size);