#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"
}
-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!"),
wxString wxXmlResourceHandler::GetText(const wxString& param, bool translate)
{
- wxString str1;
+ wxString str1(GetParamValue(param));
wxString str2;
const wxChar *dt;
wxChar amp_char;
- if (translate && m_resource->GetFlags() & wxXRC_USE_LOCALE)
- str1 = wxGetTranslation(GetParamValue(param));
- else
- str1 = GetParamValue(param);
-
- // 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").
+ // 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
}
else str2 << *dt;
}
-
- return str2;
+
+ if (translate && m_resource->GetFlags() & wxXRC_USE_LOCALE)
+ return wxGetTranslation(str2);
+ else
+ return str2;
+
}
}
+
int wxXmlResourceHandler::GetID()
{
wxString sid = GetName();
}
+
+wxArtID wxXmlResourceHandler::GetStockID(const wxString& param)
+{
+ wxXmlNode *stockIDNode = GetParamNode(param);
+ if (stockIDNode == NULL)
+ return wxEmptyString;
+
+ wxXmlNode *oldnode = m_node;
+ m_node = stockIDNode;
+
+ wxArtID sid = m_node->GetPropVal(wxT("stock_id"), wxT(""));
+
+ m_node = oldnode;
+
+ if (sid.IsEmpty()) return wxEmptyString;
+#define stdID(id) else if (sid == wxT(#id)) return id
+ stdID(wxART_ADD_BOOKMARK); stdID(wxART_DEL_BOOKMARK);
+ stdID(wxART_HELP_SIDE_PANEL); stdID(wxART_HELP_SETTINGS);
+ stdID(wxART_HELP_BOOK); stdID(wxART_HELP_FOLDER);
+ stdID(wxART_HELP_PAGE); stdID(wxART_GO_BACK);
+ stdID(wxART_GO_FORWARD); stdID(wxART_GO_UP);
+ stdID(wxART_GO_DOWN); stdID(wxART_GO_TO_PARENT);
+ stdID(wxART_GO_HOME); stdID(wxART_FILE_OPEN);
+ stdID(wxART_PRINT); stdID(wxART_HELP); stdID(wxART_TIP);
+ stdID(wxART_REPORT_VIEW); stdID(wxART_LIST_VIEW);
+ stdID(wxART_NEW_DIR); stdID(wxART_FOLDER);
+ stdID(wxART_GO_DIR_UP); stdID(wxART_EXECUTABLE_FILE);
+ stdID(wxART_NORMAL_FILE); stdID(wxART_TICK_MARK);
+ stdID(wxART_CROSS_MARK); stdID(wxART_ERROR);
+ stdID(wxART_QUESTION); stdID(wxART_WARNING);
+ stdID(wxART_INFORMATION);
+#undef stdID
+ else return sid;
+}
+
+
+
+wxArtClient wxXmlResourceHandler::GetStockClient(const wxString& param)
+{
+ wxXmlNode *stockClientNode = GetParamNode(param);
+ if (stockClientNode == NULL)
+ return wxEmptyString;
+
+ wxXmlNode *oldnode = m_node;
+ m_node = stockClientNode;
+
+ wxArtClient sid = m_node->GetPropVal(wxT("stock_client"), wxT("wxART_OTHER"));
+
+ m_node = oldnode;
+
+ if (sid.IsEmpty()) return wxEmptyString;
+#define stdID(id) else if (sid == wxT(#id)) return id
+ stdID(wxART_TOOLBAR); stdID(wxART_MENU);
+ stdID(wxART_FRAME_ICON); stdID(wxART_CMN_DIALOG);
+ stdID(wxART_HELP_BROWSER); stdID(wxART_MESSAGE_BOX);
+ stdID(wxART_OTHER);
+#undef stdID
+ else return sid;
+}
+
+
+
wxString wxXmlResourceHandler::GetName()
{
return m_node->GetPropVal(wxT("name"), wxT("-1"));
wxBitmap wxXmlResourceHandler::GetBitmap(const wxString& param, wxSize size)
{
+ wxString stk = param;
+ if (!GetStockID(stk).IsEmpty())
+ {
+ wxBitmap stockArt = wxArtProvider::GetBitmap(GetStockID(stk),
+ GetStockClient(stk), size);
+ if (stockArt != wxNullBitmap)
+ return stockArt;
+ }
+
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);
+
}