1. made XRC immune against changing CWD

2. fixed object_ref handling


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@18756 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2003-01-15 23:14:07 +00:00
parent dc5e3b9ec5
commit 317a0d7361
2 changed files with 86 additions and 32 deletions

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,9 +100,26 @@ bool wxXmlResource::Load(const wxString& filemask)
fnd = filemask; fnd = filemask;
while (!!fnd) while (!!fnd)
{ {
// NB: Load() accepts both filenames and URLs (should probably be
// changed to filenames only, but embedded resources currently
// 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))
{
// Make the name absolute filename, because the app may
// 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 wxUSE_FILESYSTEM
if (filemask.Lower().Matches(wxT("*.zip")) || if (fnd.Lower().Matches(wxT("*.zip")) ||
filemask.Lower().Matches(wxT("*.xrs"))) fnd.Lower().Matches(wxT("*.xrs")))
{ {
rt = rt && Load(fnd + wxT("#zip:*.xrc")); rt = rt && Load(fnd + wxT("#zip:*.xrc"));
} }
@@ -516,7 +534,9 @@ 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,
wxXmlResourceHandler *handlerToUse)
{ {
if (node == NULL) return NULL; if (node == NULL) return NULL;
@@ -540,17 +560,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'!"),
@@ -1111,10 +1140,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->CreateResFromNode(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

@@ -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,9 +100,26 @@ bool wxXmlResource::Load(const wxString& filemask)
fnd = filemask; fnd = filemask;
while (!!fnd) while (!!fnd)
{ {
// NB: Load() accepts both filenames and URLs (should probably be
// changed to filenames only, but embedded resources currently
// 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))
{
// Make the name absolute filename, because the app may
// 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 wxUSE_FILESYSTEM
if (filemask.Lower().Matches(wxT("*.zip")) || if (fnd.Lower().Matches(wxT("*.zip")) ||
filemask.Lower().Matches(wxT("*.xrs"))) fnd.Lower().Matches(wxT("*.xrs")))
{ {
rt = rt && Load(fnd + wxT("#zip:*.xrc")); rt = rt && Load(fnd + wxT("#zip:*.xrc"));
} }
@@ -516,7 +534,9 @@ 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,
wxXmlResourceHandler *handlerToUse)
{ {
if (node == NULL) return NULL; if (node == NULL) return NULL;
@@ -540,17 +560,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'!"),
@@ -1111,10 +1140,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->CreateResFromNode(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();
} }