#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"
}
else
{
- node->RemoveChild(c);
wxXmlNode *c2 = c->GetNext();
+ node->RemoveChild(c);
delete c;
c = c2;
}
}
-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;
// 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;
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);
return NULL;
}
-wxXmlNode *wxXmlResource::FindResource(const wxString& name,
+wxXmlNode *wxXmlResource::FindResource(const wxString& name,
const wxString& classname,
bool recursive)
{
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 )
{
wxXmlProperty *dprop;
for (dprop = dest.GetProperties(); dprop; dprop = dprop->GetNext())
{
-
+
if ( dprop->GetName() == prop->GetName() )
{
dprop->SetValue(prop->GetValue());
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;
}
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);
if (classInfo)
m_instance = classInfo->CreateObject();
-
+
if (!m_instance)
{
wxLogError(_("Subclass '%s' not found for resource '%s', not subclassing!"),
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('$');
}
else str2 << *dt;
}
-
+
if (translate && m_resource->GetFlags() & wxXRC_USE_LOCALE)
return wxGetTranslation(str2);
else
}
+
int wxXmlResourceHandler::GetID()
{
wxString sid = GetName();
}
+
wxString wxXmlResourceHandler::GetName()
{
return m_node->GetPropVal(wxT("name"), wxT("-1"));
-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)
#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);