XRC fixes for <object_ref> and relative file names

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@20068 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2003-04-07 22:16:27 +00:00
parent dc5003c6f3
commit 3d20fa7032
4 changed files with 126 additions and 40 deletions

View File

@@ -240,8 +240,18 @@ protected:
wxXmlNode *DoFindResource(wxXmlNode *parent, const wxString& name, const wxString& classname, bool recursive); wxXmlNode *DoFindResource(wxXmlNode *parent, const wxString& name, const wxString& classname, bool recursive);
// Creates a resource from information in the given node. // Creates a resource from information in the given node.
wxObject *CreateResFromNode(wxXmlNode *node, wxObject *parent, wxObject *instance = NULL); wxObject *CreateResFromNode(wxXmlNode *node, wxObject *parent,
wxObject *instance = NULL);
// Creates a resource from information in the given node
// (Uses only 'handlerToUse' if != NULL)
//
// ATTENTION: Do *NOT* use this function, it will disappear in
// wxWindows 2.5.0! It exists *only* as a hack to preserve
// binary compatibility in 2.4.x branch.
wxObject *CreateResFromNode2(wxXmlNode *node, wxObject *parent,
wxObject *instance = NULL,
wxXmlResourceHandler *handlerToUse = NULL);
private: private:
long m_version; long m_version;

View File

@@ -24,6 +24,7 @@
#include "wx/frame.h" #include "wx/frame.h"
#include "wx/wfstream.h" #include "wx/wfstream.h"
#include "wx/filesys.h" #include "wx/filesys.h"
#include "wx/filename.h"
#include "wx/log.h" #include "wx/log.h"
#include "wx/intl.h" #include "wx/intl.h"
#include "wx/tokenzr.h" #include "wx/tokenzr.h"
@@ -99,12 +100,29 @@ bool wxXmlResource::Load(const wxString& filemask)
fnd = filemask; fnd = filemask;
while (!!fnd) while (!!fnd)
{ {
#if wxUSE_FILESYSTEM // NB: Load() accepts both filenames and URLs (should probably be
if (filemask.Lower().Matches(wxT("*.zip")) || // changed to filenames only, but embedded resources currently
filemask.Lower().Matches(wxT("*.xrs"))) // rely on its ability to handle URLs - FIXME). This check
// serves as a quick way to determine whether found name is
// filename and not URL:
if (wxFileName::FileExists(fnd))
{ {
rt = rt && Load(fnd + wxT("#zip:*.xmlbin")); // Make the name absolute filename, because the app may
rt = rt && Load(fnd + wxT("#zip:*.xrc")); // change working directory later:
wxFileName fn(fnd);
if (fn.IsRelative())
{
fn.Normalize(wxPATH_NORM_DOTS | wxPATH_NORM_ABSOLUTE);
fnd = fn.GetFullPath();
}
}
#if wxUSE_FILESYSTEM
if (fnd.Lower().Matches(wxT("*.zip")) ||
fnd.Lower().Matches(wxT("*.xrs")))
{
wxString url(wxFileSystem::FileNameToURL(fnd));
rt = rt && Load(url + wxT("#zip:*.xrc"));
} }
else else
#endif #endif
@@ -517,7 +535,15 @@ static void MergeNodes(wxXmlNode& dest, wxXmlNode& with)
dest.SetContent(with.GetContent()); dest.SetContent(with.GetContent());
} }
wxObject *wxXmlResource::CreateResFromNode(wxXmlNode *node, wxObject *parent, wxObject *instance) wxObject *wxXmlResource::CreateResFromNode(wxXmlNode *node, wxObject *parent,
wxObject *instance)
{
return CreateResFromNode2(node, parent, instance);
}
wxObject *wxXmlResource::CreateResFromNode2(wxXmlNode *node, wxObject *parent,
wxObject *instance,
wxXmlResourceHandler *handlerToUse)
{ {
if (node == NULL) return NULL; if (node == NULL) return NULL;
@@ -541,17 +567,26 @@ wxObject *wxXmlResource::CreateResFromNode(wxXmlNode *node, wxObject *parent, wx
} }
wxXmlResourceHandler *handler; wxXmlResourceHandler *handler;
wxObject *ret;
wxNode * ND = m_handlers.GetFirst(); if (handlerToUse)
while (ND) {
{ if (handlerToUse->CanHandle(node))
handler = (wxXmlResourceHandler*)ND->GetData();
if (node->GetName() == wxT("object") && handler->CanHandle(node))
{ {
ret = handler->CreateResource(node, parent, instance); return handlerToUse->CreateResource(node, parent, instance);
if (ret) return ret; }
}
else if (node->GetName() == wxT("object"))
{
wxNode *ND = m_handlers.GetFirst();
while (ND)
{
handler = (wxXmlResourceHandler*)ND->GetData();
if (handler->CanHandle(node))
{
return handler->CreateResource(node, parent, instance);
}
ND = ND->GetNext();
} }
ND = ND->GetNext();
} }
wxLogError(_("No handler found for XML node '%s', class '%s'!"), wxLogError(_("No handler found for XML node '%s', class '%s'!"),
@@ -1084,10 +1119,8 @@ void wxXmlResourceHandler::CreateChildren(wxObject *parent, bool this_hnd_only)
if (n->GetType() == wxXML_ELEMENT_NODE && if (n->GetType() == wxXML_ELEMENT_NODE &&
(n->GetName() == wxT("object") || n->GetName() == wxT("object_ref"))) (n->GetName() == wxT("object") || n->GetName() == wxT("object_ref")))
{ {
if (this_hnd_only && CanHandle(n)) m_resource->CreateResFromNode2(n, parent, NULL,
CreateResource(n, parent, NULL); this_hnd_only ? this : NULL);
else
m_resource->CreateResFromNode(n, parent, NULL);
} }
n = n->GetNext(); n = n->GetNext();
} }

View File

@@ -240,8 +240,18 @@ protected:
wxXmlNode *DoFindResource(wxXmlNode *parent, const wxString& name, const wxString& classname, bool recursive); wxXmlNode *DoFindResource(wxXmlNode *parent, const wxString& name, const wxString& classname, bool recursive);
// Creates a resource from information in the given node. // Creates a resource from information in the given node.
wxObject *CreateResFromNode(wxXmlNode *node, wxObject *parent, wxObject *instance = NULL); wxObject *CreateResFromNode(wxXmlNode *node, wxObject *parent,
wxObject *instance = NULL);
// Creates a resource from information in the given node
// (Uses only 'handlerToUse' if != NULL)
//
// ATTENTION: Do *NOT* use this function, it will disappear in
// wxWindows 2.5.0! It exists *only* as a hack to preserve
// binary compatibility in 2.4.x branch.
wxObject *CreateResFromNode2(wxXmlNode *node, wxObject *parent,
wxObject *instance = NULL,
wxXmlResourceHandler *handlerToUse = NULL);
private: private:
long m_version; long m_version;

View File

@@ -24,6 +24,7 @@
#include "wx/frame.h" #include "wx/frame.h"
#include "wx/wfstream.h" #include "wx/wfstream.h"
#include "wx/filesys.h" #include "wx/filesys.h"
#include "wx/filename.h"
#include "wx/log.h" #include "wx/log.h"
#include "wx/intl.h" #include "wx/intl.h"
#include "wx/tokenzr.h" #include "wx/tokenzr.h"
@@ -99,12 +100,29 @@ bool wxXmlResource::Load(const wxString& filemask)
fnd = filemask; fnd = filemask;
while (!!fnd) while (!!fnd)
{ {
#if wxUSE_FILESYSTEM // NB: Load() accepts both filenames and URLs (should probably be
if (filemask.Lower().Matches(wxT("*.zip")) || // changed to filenames only, but embedded resources currently
filemask.Lower().Matches(wxT("*.xrs"))) // rely on its ability to handle URLs - FIXME). This check
// serves as a quick way to determine whether found name is
// filename and not URL:
if (wxFileName::FileExists(fnd))
{ {
rt = rt && Load(fnd + wxT("#zip:*.xmlbin")); // Make the name absolute filename, because the app may
rt = rt && Load(fnd + wxT("#zip:*.xrc")); // change working directory later:
wxFileName fn(fnd);
if (fn.IsRelative())
{
fn.Normalize(wxPATH_NORM_DOTS | wxPATH_NORM_ABSOLUTE);
fnd = fn.GetFullPath();
}
}
#if wxUSE_FILESYSTEM
if (fnd.Lower().Matches(wxT("*.zip")) ||
fnd.Lower().Matches(wxT("*.xrs")))
{
wxString url(wxFileSystem::FileNameToURL(fnd));
rt = rt && Load(url + wxT("#zip:*.xrc"));
} }
else else
#endif #endif
@@ -517,7 +535,15 @@ static void MergeNodes(wxXmlNode& dest, wxXmlNode& with)
dest.SetContent(with.GetContent()); dest.SetContent(with.GetContent());
} }
wxObject *wxXmlResource::CreateResFromNode(wxXmlNode *node, wxObject *parent, wxObject *instance) wxObject *wxXmlResource::CreateResFromNode(wxXmlNode *node, wxObject *parent,
wxObject *instance)
{
return CreateResFromNode2(node, parent, instance);
}
wxObject *wxXmlResource::CreateResFromNode2(wxXmlNode *node, wxObject *parent,
wxObject *instance,
wxXmlResourceHandler *handlerToUse)
{ {
if (node == NULL) return NULL; if (node == NULL) return NULL;
@@ -541,17 +567,26 @@ wxObject *wxXmlResource::CreateResFromNode(wxXmlNode *node, wxObject *parent, wx
} }
wxXmlResourceHandler *handler; wxXmlResourceHandler *handler;
wxObject *ret;
wxNode * ND = m_handlers.GetFirst(); if (handlerToUse)
while (ND) {
{ if (handlerToUse->CanHandle(node))
handler = (wxXmlResourceHandler*)ND->GetData();
if (node->GetName() == wxT("object") && handler->CanHandle(node))
{ {
ret = handler->CreateResource(node, parent, instance); return handlerToUse->CreateResource(node, parent, instance);
if (ret) return ret; }
}
else if (node->GetName() == wxT("object"))
{
wxNode *ND = m_handlers.GetFirst();
while (ND)
{
handler = (wxXmlResourceHandler*)ND->GetData();
if (handler->CanHandle(node))
{
return handler->CreateResource(node, parent, instance);
}
ND = ND->GetNext();
} }
ND = ND->GetNext();
} }
wxLogError(_("No handler found for XML node '%s', class '%s'!"), wxLogError(_("No handler found for XML node '%s', class '%s'!"),
@@ -1084,10 +1119,8 @@ void wxXmlResourceHandler::CreateChildren(wxObject *parent, bool this_hnd_only)
if (n->GetType() == wxXML_ELEMENT_NODE && if (n->GetType() == wxXML_ELEMENT_NODE &&
(n->GetName() == wxT("object") || n->GetName() == wxT("object_ref"))) (n->GetName() == wxT("object") || n->GetName() == wxT("object_ref")))
{ {
if (this_hnd_only && CanHandle(n)) m_resource->CreateResFromNode2(n, parent, NULL,
CreateResource(n, parent, NULL); this_hnd_only ? this : NULL);
else
m_resource->CreateResFromNode(n, parent, NULL);
} }
n = n->GetNext(); n = n->GetNext();
} }