X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4249ec2c526b01fc35daedfdf4290959455cc4a5..16c587ca765d00a17eb4fe83f6d94901a08801a4:/contrib/utils/wxrc/wxrc.cpp?ds=sidebyside diff --git a/contrib/utils/wxrc/wxrc.cpp b/contrib/utils/wxrc/wxrc.cpp index c2aeec7a7e..bc4a9df795 100644 --- a/contrib/utils/wxrc/wxrc.cpp +++ b/contrib/utils/wxrc/wxrc.cpp @@ -1,7 +1,7 @@ ///////////////////////////////////////////////////////////////////////////// // Name: wxrc.cpp // Purpose: XML resource compiler -// Author: Vaclav Slavik +// Author: Vaclav Slavik, Eduardo Marques // Created: 2000/03/05 // RCS-ID: $Id$ // Copyright: (c) 2000 Vaclav Slavik @@ -20,40 +20,125 @@ #pragma hdrstop #endif -// for all others, include the necessary headers (this file is usually all you -// need because it includes almost all "standard" wxWindows headers +// for all others, include the necessary headers #ifndef WX_PRECOMP - #include "wx/wx.h" + #include "wx/app.h" + #include "wx/log.h" #endif #include "wx/cmdline.h" -#include "wx/xrc/xml.h" +#include "wx/xml/xml.h" #include "wx/ffile.h" #include "wx/filename.h" #include "wx/wfstream.h" +class XRCWidgetData +{ +public: + XRCWidgetData(const wxString& vname,const wxString& vclass) + : m_class(vclass), m_name(vname) {} + const wxString& GetName() const { return m_name; } + const wxString& GetClass() const { return m_class; } +private: + wxString m_class; + wxString m_name; +}; +#include "wx/arrimpl.cpp" +WX_DECLARE_OBJARRAY(XRCWidgetData,ArrayOfXRCWidgetData); +WX_DEFINE_OBJARRAY(ArrayOfXRCWidgetData); +class XRCWndClassData +{ +private: + wxString m_className; + wxString m_parentClassName; + ArrayOfXRCWidgetData m_wdata; + + void BrowseXmlNode(wxXmlNode* node) + { + wxString classValue; + wxString nameValue; + wxXmlNode* children; + while (node) + { + if (node->GetName() == _T("object") + && node->GetPropVal(_T("class"),&classValue) + && node->GetPropVal(_T("name"),&nameValue)) + { + m_wdata.Add(XRCWidgetData(nameValue,classValue)); + } + children = node->GetChildren(); + if (children) + BrowseXmlNode(children); + node = node->GetNext(); + } + } + +public: + XRCWndClassData(const wxString& className,const wxString& parentClassName, const wxXmlNode* node) : + m_className(className) , m_parentClassName(parentClassName) { + + BrowseXmlNode(node->GetChildren()); + + } + + const ArrayOfXRCWidgetData& GetWidgetData(){ + return m_wdata; + } + void GenerateHeaderCode(wxFFile& file){ + + file.Write(_T("class ") + m_className + _T(" : public ") + m_parentClassName + + _T(" {\nprotected:\n")); + for(size_t i=0;iLoadObject(this,NULL,\"") + + m_className + + +_T("\",\"") + + m_parentClassName + + _T("\");\n")); + for(size_t i=0;iGetChildren(); + wxString classValue,nameValue; + while(node){ + if(node->GetName() == _T("object") + && node->GetPropVal(_T("class"),&classValue) + && node->GetPropVal(_T("name"),&nameValue)){ + + aXRCWndClassData.Add( + XRCWndClassData(nameValue,classValue,node) + ); + } + node = node -> GetNext(); + } + } wxString internalName = GetInternalFileName(parFiles[i], flist); doc.Save(parOutputPath + wxFILE_SEP_PATH + internalName); @@ -364,13 +486,12 @@ void XmlResApp::MakePackageZIP(const wxArrayString& flist) - static wxString FileToCppArray(wxString filename, int num) { wxString output; wxString tmp; wxString snum; - wxFFile file(filename, "rb"); + wxFFile file(filename, wxT("rb")); size_t lng = file.Length(); snum.Printf(_T("%i"), num); @@ -405,7 +526,7 @@ static wxString FileToCppArray(wxString filename, int num) void XmlResApp::MakePackageCPP(const wxArrayString& flist) { - wxFFile file(parOutput, "wt"); + wxFFile file(parOutput, wxT("wt")); size_t i; if (flagVerbose) @@ -436,15 +557,15 @@ _T("\n")); FileToCppArray(parOutputPath + wxFILE_SEP_PATH + flist[i], i)); file.Write(_T("") -_T("void " + parFuncname + "()\n") +_T("void ") + parFuncname + wxT("()\n") _T("{\n") _T("\n") _T(" // Check for memory FS. If not present, load the handler:\n") _T(" {\n") -_T(" wxMemoryFSHandler::AddFile(\"XRC_resource/dummy_file\", \"dummy one\");\n") +_T(" wxMemoryFSHandler::AddFile(wxT(\"XRC_resource/dummy_file\"), wxT(\"dummy one\"));\n") _T(" wxFileSystem fsys;\n") -_T(" wxFSFile *f = fsys.OpenFile(\"memory:XRC_resource/dummy_file\");\n") -_T(" wxMemoryFSHandler::RemoveFile(\"XRC_resource/dummy_file\");\n") +_T(" wxFSFile *f = fsys.OpenFile(wxT(\"memory:XRC_resource/dummy_file\"));\n") +_T(" wxMemoryFSHandler::RemoveFile(wxT(\"XRC_resource/dummy_file\"));\n") _T(" if (f) delete f;\n") _T(" else wxFileSystem::AddHandler(new wxMemoryFSHandler);\n") _T(" }\n") @@ -453,15 +574,15 @@ _T("\n")); for (i = 0; i < flist.Count(); i++) { wxString s; - s.Printf(_T(" wxMemoryFSHandler::AddFile(\"XRC_resource/") + flist[i] + - _T("\", xml_res_file_%i, xml_res_size_%i);\n"), i, i); + s.Printf(_T(" wxMemoryFSHandler::AddFile(wxT(\"XRC_resource/") + flist[i] + + _T("\"), xml_res_file_%i, xml_res_size_%i);\n"), i, i); file.Write(s); } for (i = 0; i < parFiles.Count(); i++) { - file.Write(_T(" wxXmlResource::Get()->Load(\"memory:XRC_resource/") + - GetInternalFileName(parFiles[i], flist) + _T("\");\n")); + file.Write(_T(" wxXmlResource::Get()->Load(wxT(\"memory:XRC_resource/") + + GetInternalFileName(parFiles[i], flist) + _T("\"));\n")); } file.Write(_T("}\n")); @@ -469,12 +590,34 @@ _T("\n")); } +void XmlResApp::GenCPPHeader() +{ + wxString fileSpec = (parOutput.BeforeLast('.')).AfterLast('/'); + wxString heaFileName = fileSpec + _T(".h"); + + wxFFile file(heaFileName, wxT("wt")); + file.Write( +_T("//\n") +_T("// This file was automatically generated by wxrc, do not edit by hand.\n") +_T("//\n\n") +_T("#ifndef __") + fileSpec + _T("_h__\n") +_T("#define __") + fileSpec + _T("_h__\n") +); + for(size_t i=0;i