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:
parent
dc5e3b9ec5
commit
317a0d7361
@ -24,6 +24,7 @@
|
||||
#include "wx/frame.h"
|
||||
#include "wx/wfstream.h"
|
||||
#include "wx/filesys.h"
|
||||
#include "wx/filename.h"
|
||||
#include "wx/log.h"
|
||||
#include "wx/intl.h"
|
||||
#include "wx/tokenzr.h"
|
||||
@ -99,9 +100,26 @@ bool wxXmlResource::Load(const wxString& filemask)
|
||||
fnd = filemask;
|
||||
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 (filemask.Lower().Matches(wxT("*.zip")) ||
|
||||
filemask.Lower().Matches(wxT("*.xrs")))
|
||||
if (fnd.Lower().Matches(wxT("*.zip")) ||
|
||||
fnd.Lower().Matches(wxT("*.xrs")))
|
||||
{
|
||||
rt = rt && Load(fnd + wxT("#zip:*.xrc"));
|
||||
}
|
||||
@ -516,7 +534,9 @@ static void MergeNodes(wxXmlNode& dest, wxXmlNode& with)
|
||||
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;
|
||||
|
||||
@ -540,17 +560,26 @@ wxObject *wxXmlResource::CreateResFromNode(wxXmlNode *node, wxObject *parent, wx
|
||||
}
|
||||
|
||||
wxXmlResourceHandler *handler;
|
||||
wxObject *ret;
|
||||
wxNode * ND = m_handlers.GetFirst();
|
||||
while (ND)
|
||||
{
|
||||
handler = (wxXmlResourceHandler*)ND->GetData();
|
||||
if (node->GetName() == wxT("object") && handler->CanHandle(node))
|
||||
|
||||
if (handlerToUse)
|
||||
{
|
||||
if (handlerToUse->CanHandle(node))
|
||||
{
|
||||
ret = handler->CreateResource(node, parent, instance);
|
||||
if (ret) return ret;
|
||||
return handlerToUse->CreateResource(node, parent, instance);
|
||||
}
|
||||
}
|
||||
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'!"),
|
||||
@ -1111,10 +1140,8 @@ void wxXmlResourceHandler::CreateChildren(wxObject *parent, bool this_hnd_only)
|
||||
if (n->GetType() == wxXML_ELEMENT_NODE &&
|
||||
(n->GetName() == wxT("object") || n->GetName() == wxT("object_ref")))
|
||||
{
|
||||
if (this_hnd_only && CanHandle(n))
|
||||
CreateResource(n, parent, NULL);
|
||||
else
|
||||
m_resource->CreateResFromNode(n, parent, NULL);
|
||||
m_resource->CreateResFromNode(n, parent, NULL,
|
||||
this_hnd_only ? this : NULL);
|
||||
}
|
||||
n = n->GetNext();
|
||||
}
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "wx/frame.h"
|
||||
#include "wx/wfstream.h"
|
||||
#include "wx/filesys.h"
|
||||
#include "wx/filename.h"
|
||||
#include "wx/log.h"
|
||||
#include "wx/intl.h"
|
||||
#include "wx/tokenzr.h"
|
||||
@ -99,9 +100,26 @@ bool wxXmlResource::Load(const wxString& filemask)
|
||||
fnd = filemask;
|
||||
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 (filemask.Lower().Matches(wxT("*.zip")) ||
|
||||
filemask.Lower().Matches(wxT("*.xrs")))
|
||||
if (fnd.Lower().Matches(wxT("*.zip")) ||
|
||||
fnd.Lower().Matches(wxT("*.xrs")))
|
||||
{
|
||||
rt = rt && Load(fnd + wxT("#zip:*.xrc"));
|
||||
}
|
||||
@ -516,7 +534,9 @@ static void MergeNodes(wxXmlNode& dest, wxXmlNode& with)
|
||||
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;
|
||||
|
||||
@ -540,17 +560,26 @@ wxObject *wxXmlResource::CreateResFromNode(wxXmlNode *node, wxObject *parent, wx
|
||||
}
|
||||
|
||||
wxXmlResourceHandler *handler;
|
||||
wxObject *ret;
|
||||
wxNode * ND = m_handlers.GetFirst();
|
||||
while (ND)
|
||||
{
|
||||
handler = (wxXmlResourceHandler*)ND->GetData();
|
||||
if (node->GetName() == wxT("object") && handler->CanHandle(node))
|
||||
|
||||
if (handlerToUse)
|
||||
{
|
||||
if (handlerToUse->CanHandle(node))
|
||||
{
|
||||
ret = handler->CreateResource(node, parent, instance);
|
||||
if (ret) return ret;
|
||||
return handlerToUse->CreateResource(node, parent, instance);
|
||||
}
|
||||
}
|
||||
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'!"),
|
||||
@ -1111,10 +1140,8 @@ void wxXmlResourceHandler::CreateChildren(wxObject *parent, bool this_hnd_only)
|
||||
if (n->GetType() == wxXML_ELEMENT_NODE &&
|
||||
(n->GetName() == wxT("object") || n->GetName() == wxT("object_ref")))
|
||||
{
|
||||
if (this_hnd_only && CanHandle(n))
|
||||
CreateResource(n, parent, NULL);
|
||||
else
|
||||
m_resource->CreateResFromNode(n, parent, NULL);
|
||||
m_resource->CreateResFromNode(n, parent, NULL,
|
||||
this_hnd_only ? this : NULL);
|
||||
}
|
||||
n = n->GetNext();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user