From dfc0e3fb9a38ac231b12d207654afcf3de9582c2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Wed, 26 Jul 2000 21:32:47 +0000 Subject: [PATCH] xmlres: added support for wxMSW git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@7854 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- contrib/include/wx/xml/xml.h | 10 +- contrib/include/wx/xml/xmlio.h | 6 +- contrib/include/wx/xml/xmlres.h | 6 +- contrib/src/xml/wxxmlVC.dsp | 286 ++++++++++++++++++++++++++++++++ contrib/src/xml/wxxmlVC.dsw | 29 ++++ contrib/src/xml/xmlpars.cpp | 36 +++- 6 files changed, 357 insertions(+), 16 deletions(-) create mode 100644 contrib/src/xml/wxxmlVC.dsp create mode 100644 contrib/src/xml/wxxmlVC.dsw diff --git a/contrib/include/wx/xml/xml.h b/contrib/include/wx/xml/xml.h index 45aedba49f..f6cdbd5a85 100644 --- a/contrib/include/wx/xml/xml.h +++ b/contrib/include/wx/xml/xml.h @@ -64,7 +64,7 @@ enum wxXmlIOType // Example: in "src" is property with value // "hello.gif" and "id" is prop. with value "3". -class WXDLLEXPORT wxXmlProperty +class wxXmlProperty { public: wxXmlProperty() : m_Next(NULL) {} @@ -94,7 +94,7 @@ class WXDLLEXPORT wxXmlProperty // element with name="title", irrelevant content and one child (wxXML_TEXT_NODE // with content="hi"). -class WXDLLEXPORT wxXmlNode +class wxXmlNode { public: wxXmlNode() : m_Properties(NULL), m_Parent(NULL), @@ -165,7 +165,7 @@ class WXDLLEXPORT wxXmlNode // internal representation is independant on libxml and you can use // it without libxml (see Load/SaveBinary). -class WXDLLEXPORT wxXmlDocument : public wxObject +class wxXmlDocument : public wxObject { public: wxXmlDocument() : wxObject(), m_Version(_T("1.0")), m_Root(NULL) {} @@ -184,8 +184,6 @@ class WXDLLEXPORT wxXmlDocument : public wxObject bool Load(wxInputStream& stream, wxXmlIOType io_type = wxXML_IO_AUTO); // Saves document as .xml file. - // NOTE: Any call to this method will result into linking against libxml - // and app's binary size will grow by ca. 250kB bool Save(const wxString& filename, wxXmlIOType io_type) const; bool Save(wxOutputStream& stream, wxXmlIOType io_type) const; @@ -221,7 +219,7 @@ class WXDLLEXPORT wxXmlDocument : public wxObject // wxXmlIOHandler takes care of loading and/or saving XML data. // see xmlio.h for available handlers -class WXDLLEXPORT wxXmlIOHandler : public wxObject +class wxXmlIOHandler : public wxObject { public: wxXmlIOHandler() {} diff --git a/contrib/include/wx/xml/xmlio.h b/contrib/include/wx/xml/xmlio.h index 3e336b46c9..788f1f8023 100644 --- a/contrib/include/wx/xml/xmlio.h +++ b/contrib/include/wx/xml/xmlio.h @@ -20,7 +20,7 @@ #include "wx/xml/xml.h" -class WXDLLEXPORT wxXmlIOHandlerBin : public wxXmlIOHandler +class wxXmlIOHandlerBin : public wxXmlIOHandler { public: wxXmlIOHandlerBin() {} @@ -41,7 +41,7 @@ class WXDLLEXPORT wxXmlIOHandlerBin : public wxXmlIOHandler #if wxUSE_ZLIB -class WXDLLEXPORT wxXmlIOHandlerBinZ : public wxXmlIOHandlerBin +class wxXmlIOHandlerBinZ : public wxXmlIOHandlerBin { public: wxXmlIOHandlerBinZ() {} @@ -57,7 +57,7 @@ class WXDLLEXPORT wxXmlIOHandlerBinZ : public wxXmlIOHandlerBin -class WXDLLEXPORT wxXmlIOHandlerLibxml : public wxXmlIOHandler +class wxXmlIOHandlerLibxml : public wxXmlIOHandler { public: virtual wxXmlIOType GetType() { return wxXML_IO_LIBXML; } diff --git a/contrib/include/wx/xml/xmlres.h b/contrib/include/wx/xml/xmlres.h index 118561b7ba..bc8090ad37 100644 --- a/contrib/include/wx/xml/xmlres.h +++ b/contrib/include/wx/xml/xmlres.h @@ -40,7 +40,7 @@ enum -class WXDLLEXPORT wxXmlResourceDataRecord +class wxXmlResourceDataRecord { public: wxXmlResourceDataRecord() : Doc(NULL), Time(wxDateTime::Now()) {} @@ -57,7 +57,7 @@ WX_DECLARE_OBJARRAY(wxXmlResourceDataRecord, wxXmlResourceDataRecords); // (or derived forms, either binary or zipped -- see manual for // details). -class WXDLLEXPORT wxXmlResource : public wxObject +class wxXmlResource : public wxObject { public: wxXmlResource(); @@ -152,7 +152,7 @@ extern wxXmlResource *wxTheXmlResource; #define XMLID(str_id) wxXmlResource::GetXMLID(str_id) -class WXDLLEXPORT wxXmlResourceHandler : public wxObject +class wxXmlResourceHandler : public wxObject { public: wxXmlResourceHandler(); diff --git a/contrib/src/xml/wxxmlVC.dsp b/contrib/src/xml/wxxmlVC.dsp new file mode 100644 index 0000000000..fb8c4f26ad --- /dev/null +++ b/contrib/src/xml/wxxmlVC.dsp @@ -0,0 +1,286 @@ +# Microsoft Developer Studio Project File - Name="wxxmlVC" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Static Library" 0x0104 + +CFG=wxxmlVC - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "wxxmlVC.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "wxxmlVC.mak" CFG="wxxmlVC - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "wxxmlVC - Win32 Release" (based on "Win32 (x86) Static Library") +!MESSAGE "wxxmlVC - Win32 Debug" (based on "Win32 (x86) Static Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "wxxmlVC - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /O1 /Ob2 /I "../../../include" /I "../../include" /D "WIN32" /D "_WINDOWS" /D "__WINDOWS__" /D "__WXMSW__" /D "__WIN95__" /D "__WIN32__" /D WINVER=0x0400 /D "STRICT" /FD /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x809 +# ADD RSC /l 0x809 +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo /out:"..\..\lib\wxxml.lib" + +!ELSEIF "$(CFG)" == "wxxmlVC - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /Z7 /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /FD /c +# ADD CPP /nologo /MDd /W3 /GX /Z7 /Od /I "../../../include" /I "../../include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "__WINDOWS__" /D "__WXMSW__" /D DEBUG=1 /D "__WXDEBUG__" /D "__WIN95__" /D "__WIN32__" /D WINVER=0x0400 /D "STRICT" /FD /c +# SUBTRACT CPP /YX +# ADD BASE RSC /l 0x809 +# ADD RSC /l 0x809 +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo /out:"..\..\lib\wxxmld.lib" + +!ENDIF + +# Begin Target + +# Name "wxxmlVC - Win32 Release" +# Name "wxxmlVC - Win32 Debug" +# Begin Group "Source files" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=.\xh_bttn.cpp +# End Source File +# Begin Source File + +SOURCE=.\xh_chckb.cpp +# End Source File +# Begin Source File + +SOURCE=.\xh_chckl.cpp +# End Source File +# Begin Source File + +SOURCE=.\xh_choic.cpp +# End Source File +# Begin Source File + +SOURCE=.\xh_combo.cpp +# End Source File +# Begin Source File + +SOURCE=.\xh_dlg.cpp +# End Source File +# Begin Source File + +SOURCE=.\xh_gauge.cpp +# End Source File +# Begin Source File + +SOURCE=.\xh_html.cpp +# End Source File +# Begin Source File + +SOURCE=.\xh_menu.cpp +# End Source File +# Begin Source File + +SOURCE=.\xh_notbk.cpp +# End Source File +# Begin Source File + +SOURCE=.\xh_panel.cpp +# End Source File +# Begin Source File + +SOURCE=.\xh_radbt.cpp +# End Source File +# Begin Source File + +SOURCE=.\xh_radbx.cpp +# End Source File +# Begin Source File + +SOURCE=.\xh_sizer.cpp +# End Source File +# Begin Source File + +SOURCE=.\xh_slidr.cpp +# End Source File +# Begin Source File + +SOURCE=.\xh_spin.cpp +# End Source File +# Begin Source File + +SOURCE=.\xh_stbmp.cpp +# End Source File +# Begin Source File + +SOURCE=.\xh_sttxt.cpp +# End Source File +# Begin Source File + +SOURCE=.\xh_text.cpp +# End Source File +# Begin Source File + +SOURCE=.\xml.cpp +# End Source File +# Begin Source File + +SOURCE=.\xmlbin.cpp +# End Source File +# Begin Source File + +SOURCE=.\xmlbinz.cpp +# End Source File +# Begin Source File + +SOURCE=.\xmlpars.cpp +# End Source File +# Begin Source File + +SOURCE=.\xmlres.cpp +# End Source File +# Begin Source File + +SOURCE=.\xmlrsall.cpp +# End Source File +# End Group +# Begin Group "Header files" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=..\..\include\wx\xml\xh_all.h +# End Source File +# Begin Source File + +SOURCE=..\..\include\wx\xml\xh_bttn.h +# End Source File +# Begin Source File + +SOURCE=..\..\include\wx\xml\xh_chckb.h +# End Source File +# Begin Source File + +SOURCE=..\..\include\wx\xml\xh_chckl.h +# End Source File +# Begin Source File + +SOURCE=..\..\include\wx\xml\xh_choic.h +# End Source File +# Begin Source File + +SOURCE=..\..\include\wx\xml\xh_combo.h +# End Source File +# Begin Source File + +SOURCE=..\..\include\wx\xml\xh_dlg.h +# End Source File +# Begin Source File + +SOURCE=..\..\include\wx\xml\xh_gauge.h +# End Source File +# Begin Source File + +SOURCE=..\..\include\wx\xml\xh_html.h +# End Source File +# Begin Source File + +SOURCE=..\..\include\wx\xml\xh_menu.h +# End Source File +# Begin Source File + +SOURCE=..\..\include\wx\xml\xh_notbk.h +# End Source File +# Begin Source File + +SOURCE=..\..\include\wx\xml\xh_panel.h +# End Source File +# Begin Source File + +SOURCE=..\..\include\wx\xml\xh_radbt.h +# End Source File +# Begin Source File + +SOURCE=..\..\include\wx\xml\xh_radbx.h +# End Source File +# Begin Source File + +SOURCE=..\..\include\wx\xml\xh_sizer.h +# End Source File +# Begin Source File + +SOURCE=..\..\include\wx\xml\xh_slidr.h +# End Source File +# Begin Source File + +SOURCE=..\..\include\wx\xml\xh_spin.h +# End Source File +# Begin Source File + +SOURCE=..\..\include\wx\xml\xh_stbmp.h +# End Source File +# Begin Source File + +SOURCE=..\..\include\wx\xml\xh_sttxt.h +# End Source File +# Begin Source File + +SOURCE=..\..\include\wx\xml\xh_text.h +# End Source File +# Begin Source File + +SOURCE=..\..\include\wx\xml\xml.h +# End Source File +# Begin Source File + +SOURCE=..\..\include\wx\xml\xmlio.h +# End Source File +# Begin Source File + +SOURCE=..\..\include\wx\xml\xmlres.h +# End Source File +# End Group +# End Target +# End Project diff --git a/contrib/src/xml/wxxmlVC.dsw b/contrib/src/xml/wxxmlVC.dsw new file mode 100644 index 0000000000..44f60625ca --- /dev/null +++ b/contrib/src/xml/wxxmlVC.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "wxxmlVC"=.\wxxmlVC.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/contrib/src/xml/xmlpars.cpp b/contrib/src/xml/xmlpars.cpp index 797c76d0a9..d35cd3722b 100644 --- a/contrib/src/xml/xmlpars.cpp +++ b/contrib/src/xml/xmlpars.cpp @@ -43,6 +43,8 @@ typedef xmlNodePtr (*type_xmlNewChild)(xmlNodePtr, xmlNsPtr, const xmlChar *, co typedef xmlChar * (*type_xmlNodeListGetString)(xmlDocPtr, xmlNodePtr, int); typedef xmlNodePtr (*type_xmlDocGetRootElement)(xmlDocPtr); typedef xmlNodePtr (*type_xmlDocSetRootElement)(xmlDocPtr doc, xmlNodePtr root); +typedef void (*(*type_xmlFree))(void *); +typedef int (*type_xmlKeepBlanksDefault)(int); static struct { @@ -62,6 +64,8 @@ static struct type_xmlNodeListGetString xmlNodeListGetString; type_xmlDocGetRootElement xmlDocGetRootElement; type_xmlDocSetRootElement xmlDocSetRootElement; + type_xmlFree xmlFree; + type_xmlKeepBlanksDefault xmlKeepBlanksDefault; } gs_libxmlDLL; static bool gs_libxmlLoaded = FALSE; @@ -88,17 +92,37 @@ static bool LoadLibxml() gs_libxmlLoadFailed = TRUE; wxLogDebug("Loading libxml.so.2..."); + { + wxLogNull lg; #ifdef __UNIX__ gs_libxmlDLL.Handle = + wxDllLoader::LoadLibrary(_T("wxlibxml.so.2"), &gs_libxmlLoaded); + if (!gs_libxmlLoaded) gs_libxmlDLL.Handle = wxDllLoader::LoadLibrary(_T("libxml.so.2"), &gs_libxmlLoaded); #endif +#ifdef __WXMSW__ + gs_libxmlDLL.Handle = + wxDllLoader::LoadLibrary(_T("wxlibxml2.dll"), &gs_libxmlLoaded); + if (!gs_libxmlLoaded) gs_libxmlDLL.Handle = + wxDllLoader::LoadLibrary(_T("libxml2.dll"), &gs_libxmlLoaded); +#endif + } - if (!gs_libxmlLoaded) return FALSE; + if (!gs_libxmlLoaded) + { + wxLogError(_("Failed to load libxml shared library.")); + return FALSE; + } #define LOAD_SYMBOL(sym) \ gs_libxmlDLL.sym = \ (type_##sym)wxDllLoader::GetSymbol(gs_libxmlDLL.Handle, _T(#sym)); \ - if (!gs_libxmlDLL.sym) { ReleaseLibxml(); return FALSE; } + if (!gs_libxmlDLL.sym) \ + { \ + ReleaseLibxml(); \ + wxLogError(_("Failed to load libxml shared library.")); \ + return FALSE; \ + } LOAD_SYMBOL(xmlCreatePushParserCtxt) LOAD_SYMBOL(xmlNewText) @@ -114,6 +138,8 @@ static bool LoadLibxml() LOAD_SYMBOL(xmlNodeListGetString) LOAD_SYMBOL(xmlDocGetRootElement) LOAD_SYMBOL(xmlDocSetRootElement) + LOAD_SYMBOL(xmlFree) + LOAD_SYMBOL(xmlKeepBlanksDefault) #undef LOAD_SYMBOL @@ -153,7 +179,7 @@ static wxXmlProperty *CreateWXProperty(xmlDocPtr doc, xmlAttrPtr attr) gs_libxmlDLL.xmlNodeListGetString(doc, attr->children, 1); wxXmlProperty *prop = new wxXmlProperty(attr->name, val, CreateWXProperty(doc, attr->next)); - free(val); + (*gs_libxmlDLL.xmlFree)(val); return prop; } @@ -187,6 +213,7 @@ bool wxXmlIOHandlerLibxml::Load(wxInputStream& stream, wxXmlDocument& doc) if (res > 0) { bool okay = TRUE; + gs_libxmlDLL.xmlKeepBlanksDefault(0); ctxt = gs_libxmlDLL.xmlCreatePushParserCtxt(NULL, NULL, buffer, res, ""/*docname*/); while ((res = stream.Read(buffer, 1024).LastRead()) > 0) @@ -249,6 +276,7 @@ bool wxXmlIOHandlerLibxml::Save(wxOutputStream& stream, const wxXmlDocument& doc wxASSERT_MSG(doc.GetRoot() != NULL, _("Trying to save empty document!")); + gs_libxmlDLL.xmlKeepBlanksDefault(0); dc = gs_libxmlDLL.xmlNewDoc((xmlChar*)doc.GetVersion().mb_str()); gs_libxmlDLL.xmlDocSetRootElement(dc, @@ -262,7 +290,7 @@ bool wxXmlIOHandlerLibxml::Save(wxOutputStream& stream, const wxXmlDocument& doc gs_libxmlDLL.xmlDocDumpMemory(dc, &buffer, &size); gs_libxmlDLL.xmlFreeDoc(dc); stream.Write(buffer, size); - free(buffer); + (*gs_libxmlDLL.xmlFree)(buffer); return stream.LastWrite() == (unsigned)size; } -- 2.45.2