added ability to read resources directly from wxXmlDocument to wxXmlResource
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8425 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -45,6 +45,7 @@ class WXDLLEXPORT wxXmlResourceDataRecord
|
|||||||
|
|
||||||
wxString File;
|
wxString File;
|
||||||
wxXmlDocument *Doc;
|
wxXmlDocument *Doc;
|
||||||
|
bool DocOwned;
|
||||||
wxDateTime Time;
|
wxDateTime Time;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -30,6 +30,7 @@
|
|||||||
#include "wx/module.h"
|
#include "wx/module.h"
|
||||||
#include "wx/bitmap.h"
|
#include "wx/bitmap.h"
|
||||||
#include "wx/image.h"
|
#include "wx/image.h"
|
||||||
|
#include "wx/fontmap.h"
|
||||||
|
|
||||||
#include "wx/xml/xml.h"
|
#include "wx/xml/xml.h"
|
||||||
#include "wx/xml/xmlres.h"
|
#include "wx/xml/xmlres.h"
|
||||||
@@ -53,6 +54,12 @@ wxXmlResource::wxXmlResource(const wxString& filemask, bool use_locale = TRUE)
|
|||||||
|
|
||||||
wxXmlResource::~wxXmlResource()
|
wxXmlResource::~wxXmlResource()
|
||||||
{
|
{
|
||||||
|
for (size_t i = 0; i < m_Data.GetCount(); i++)
|
||||||
|
{
|
||||||
|
if (!m_Data[i].DocOwned) m_Data[i].Doc = NULL;
|
||||||
|
// we don't want it to be deleted
|
||||||
|
}
|
||||||
|
|
||||||
ClearHandlers();
|
ClearHandlers();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,6 +97,7 @@ bool wxXmlResource::Load(const wxString& filemask)
|
|||||||
drec = new wxXmlResourceDataRecord;
|
drec = new wxXmlResourceDataRecord;
|
||||||
drec->File = fnd2;
|
drec->File = fnd2;
|
||||||
m_Data.Add(drec);
|
m_Data.Add(drec);
|
||||||
|
drec->DocOwned = TRUE;
|
||||||
fnd2 = fs2.FindNext();
|
fnd2 = fs2.FindNext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -98,6 +106,7 @@ bool wxXmlResource::Load(const wxString& filemask)
|
|||||||
{
|
{
|
||||||
drec = new wxXmlResourceDataRecord;
|
drec = new wxXmlResourceDataRecord;
|
||||||
drec->File = fnd;
|
drec->File = fnd;
|
||||||
|
drec->DocOwned = TRUE;
|
||||||
m_Data.Add(drec);
|
m_Data.Add(drec);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,6 +268,8 @@ void wxXmlResource::UpdateResources()
|
|||||||
|
|
||||||
for (size_t i = 0; i < m_Data.GetCount(); i++)
|
for (size_t i = 0; i < m_Data.GetCount(); i++)
|
||||||
{
|
{
|
||||||
|
if (!m_Data[i].DocOwned) continue;
|
||||||
|
|
||||||
modif = (m_Data[i].Doc == NULL);
|
modif = (m_Data[i].Doc == NULL);
|
||||||
|
|
||||||
if (!modif)
|
if (!modif)
|
||||||
@@ -732,33 +743,44 @@ wxFont wxXmlResourceHandler::GetFont(const wxString& param)
|
|||||||
wxXmlNode *font_node = GetParamNode(param);
|
wxXmlNode *font_node = GetParamNode(param);
|
||||||
if (font_node == NULL)
|
if (font_node == NULL)
|
||||||
{
|
{
|
||||||
wxLogError("Cannot find font node '%s'.", param.mb_str());
|
wxLogError(_("Cannot find font node '%s'."), param.mb_str());
|
||||||
return wxNullFont;
|
return wxNullFont;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxXmlNode *oldnode = m_Node;
|
wxXmlNode *oldnode = m_Node;
|
||||||
m_Node = font_node;
|
m_Node = font_node;
|
||||||
|
|
||||||
long size = GetLong(_("size"), 12);
|
long size = GetLong(_T("size"), 12);
|
||||||
|
|
||||||
wxString style = GetParamValue(_("style"));
|
wxString style = GetParamValue(_T("style"));
|
||||||
wxString weight = GetParamValue(_("weight"));
|
wxString weight = GetParamValue(_T("weight"));
|
||||||
int istyle = wxNORMAL, iweight = wxNORMAL;
|
int istyle = wxNORMAL, iweight = wxNORMAL;
|
||||||
if (style == _("italic")) istyle = wxITALIC;
|
if (style == _T("italic")) istyle = wxITALIC;
|
||||||
else if (style == _("slant")) istyle = wxSLANT;
|
else if (style == _T("slant")) istyle = wxSLANT;
|
||||||
if (weight == _("bold")) iweight = wxBOLD;
|
if (weight == _T("bold")) iweight = wxBOLD;
|
||||||
else if (weight == _("light")) iweight = wxLIGHT;
|
else if (weight == _T("light")) iweight = wxLIGHT;
|
||||||
|
|
||||||
bool underlined = GetBool(_("underlined"), FALSE);
|
wxString family = GetParamValue(_T("family"));
|
||||||
|
int ifamily = wxDEFAULT;
|
||||||
|
if (family == _T("decorative")) ifamily = wxDECORATIVE;
|
||||||
|
else if (family == _T("roman")) ifamily = wxROMAN;
|
||||||
|
else if (family == _T("script")) ifamily = wxSCRIPT;
|
||||||
|
else if (family == _T("swiss")) ifamily = wxSWISS;
|
||||||
|
else if (family == _T("modern")) ifamily = wxMODERN;
|
||||||
|
|
||||||
wxString encoding = GetParamValue(_("encoding"));
|
bool underlined = GetBool(_T("underlined"), FALSE);
|
||||||
// FIXME - handle encoding
|
|
||||||
|
|
||||||
wxString faces = GetParamValue(_("face"));
|
wxString encoding = GetParamValue(_T("encoding"));
|
||||||
|
wxFontMapper mapper;
|
||||||
|
wxFontEncoding enc = wxFONTENCODING_DEFAULT;
|
||||||
|
if (!encoding.IsEmpty()) enc = mapper.CharsetToEncoding(encoding);
|
||||||
|
if (enc == wxFONTENCODING_SYSTEM) enc = wxFONTENCODING_SYSTEM;
|
||||||
|
|
||||||
|
wxString faces = GetParamValue(_T("face"));
|
||||||
wxString facename = wxEmptyString;
|
wxString facename = wxEmptyString;
|
||||||
wxFontEnumerator enu;
|
wxFontEnumerator enu;
|
||||||
enu.EnumerateFacenames();
|
enu.EnumerateFacenames();
|
||||||
wxStringTokenizer tk(faces, ",");
|
wxStringTokenizer tk(faces, _T(","));
|
||||||
while (tk.HasMoreTokens())
|
while (tk.HasMoreTokens())
|
||||||
{
|
{
|
||||||
int index = enu.GetFacenames()->Index(tk.GetNextToken(), FALSE);
|
int index = enu.GetFacenames()->Index(tk.GetNextToken(), FALSE);
|
||||||
@@ -771,8 +793,7 @@ wxFont wxXmlResourceHandler::GetFont(const wxString& param)
|
|||||||
|
|
||||||
m_Node = oldnode;
|
m_Node = oldnode;
|
||||||
|
|
||||||
wxFont font(size, wxDEFAULT, istyle, iweight, underlined,
|
wxFont font(size, ifamily, istyle, iweight, underlined, facename, enc);
|
||||||
facename, wxFONTENCODING_DEFAULT);
|
|
||||||
return font;
|
return font;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user