- wxFFile file(parOutput, "wt");
- size_t i;
-
- if (flagVerbose)
- wxPrintf("creating C++ source file " + parOutput + "...\n");
-
- file.Write("\
-#include \"wx/wxprec.h\"\n\
-\n\
-#ifdef __BORLANDC__\n\
- #pragma hdrstop\n\
-#endif\n\
-\n\
-#ifndef WX_PRECOMP\n\
- #include \"wx/wx.h\"\n\
-#endif\n\
-\
-#include \"wx/filesys.h\"\n\
-#include \"wx/fs_mem.h\"\n\
-#include \"wx/xml/xmlres.h\"\n\
-#include \"wx/xml/xh_all.h\"\n\
-\n");
-
- for (i = 0; i < flist.Count(); i++)
- file.Write(FileToCppArray(flist[i], i));
-
- file.Write("\
-void " + parFuncname + "()\n\
-{\n\
-\n\
- // Check for memory FS. If not present, load the handler:\n\
- {\n\
- wxMemoryFSHandler::AddFile(\"xml_resource/dummy_file\", \"dummy one\");\n\
- wxFileSystem fsys;\n\
- wxFSFile *f = fsys.OpenFile(\"xml_resource/dummy_file\");\n\
- wxMemoryFSHandler::RemoveFile(\"xml_resource/dummy_file\");\n\
- if (f) delete f;\n\
- else wxFileSystem::AddHandler(new wxMemoryFSHandler);\n\
- }\n\
-\n");
-
- for (i = 0; i < flist.Count(); i++)
+ wxFFile file(parOutput, wxT("wt"));
+ unsigned i;
+
+ if (flagVerbose)
+ wxPrintf(wxT("creating C++ source file ") + parOutput + wxT("...\n"));
+
+ file.Write(""
+"//\n"
+"// This file was automatically generated by wxrc, do not edit by hand.\n"
+"//\n\n"
+"#include <wx/wxprec.h>\n"
+"\n"
+"#ifdef __BORLANDC__\n"
+" #pragma hdrstop\n"
+"#endif\n"
+"\n"
+""
+"#include <wx/filesys.h>\n"
+"#include <wx/fs_mem.h>\n"
+"#include <wx/xrc/xmlres.h>\n"
+"#include <wx/xrc/xh_all.h>\n"
+"\n"
+"#if wxCHECK_VERSION(2,8,5) && wxABI_VERSION >= 20805\n"
+" #define XRC_ADD_FILE(name, data, size, mime) \\\n"
+" wxMemoryFSHandler::AddFileWithMimeType(name, data, size, mime)\n"
+"#else\n"
+" #define XRC_ADD_FILE(name, data, size, mime) \\\n"
+" wxMemoryFSHandler::AddFile(name, data, size)\n"
+"#endif\n"
+"\n");
+
+ for (i = 0; i < flist.GetCount(); i++)
+ file.Write(
+ FileToCppArray(parOutputPath + wxFILE_SEP_PATH + flist[i], i));
+
+ file.Write(""
+"void " + parFuncname + "()\n"
+"{\n"
+"\n"
+" // Check for memory FS. If not present, load the handler:\n"
+" {\n"
+" wxMemoryFSHandler::AddFile(wxT(\"XRC_resource/dummy_file\"), wxT(\"dummy one\"));\n"
+" wxFileSystem fsys;\n"
+" wxFSFile *f = fsys.OpenFile(wxT(\"memory:XRC_resource/dummy_file\"));\n"
+" wxMemoryFSHandler::RemoveFile(wxT(\"XRC_resource/dummy_file\"));\n"
+" if (f) delete f;\n"
+" else wxFileSystem::AddHandler(new wxMemoryFSHandler);\n"
+" }\n"
+"\n");
+
+ for (i = 0; i < flist.GetCount(); i++)
+ {
+ wxString s;
+
+ wxString mime;
+ wxString ext = wxFileName(flist[i]).GetExt();
+ if ( ext.Lower() == wxT("xrc") )
+ mime = wxT("text/xml");
+#if wxUSE_MIMETYPE
+ else
+ {
+ wxFileType *ft = wxTheMimeTypesManager->GetFileTypeFromExtension(ext);
+ if ( ft )
+ {
+ ft->GetMimeType(&mime);
+ delete ft;
+ }
+ }
+#endif // wxUSE_MIMETYPE
+
+ s.Printf(" XRC_ADD_FILE(wxT(\"XRC_resource/" + flist[i] +
+ "\"), xml_res_file_%u, xml_res_size_%u, wxT(\"%s\"));\n",
+ i, i, mime.c_str());
+ file.Write(s);
+ }
+
+ for (i = 0; i < parFiles.GetCount(); i++)
+ {
+ file.Write(" wxXmlResource::Get()->Load(wxT(\"memory:XRC_resource/" +
+ GetInternalFileName(parFiles[i], flist) + "\"));\n");
+ }
+
+ file.Write("}\n");
+
+
+}
+
+void XmlResApp::GenCPPHeader()
+{
+ // Generate the output header in the same directory as the source file.
+ wxFileName headerName(parOutput);
+ headerName.SetExt("h");
+
+ wxFFile file(headerName.GetFullPath(), wxT("wt"));
+ file.Write(
+"//\n"
+"// This file was automatically generated by wxrc, do not edit by hand.\n"
+"//\n\n"
+"#ifndef __" + headerName.GetName() + "_h__\n"
+"#define __" + headerName.GetName() + "_h__\n"
+);
+ for(size_t i=0;i<aXRCWndClassData.GetCount();++i){
+ aXRCWndClassData.Item(i).GenerateHeaderCode(file);
+ }
+ file.Write(
+ "\nvoid \n"
+ + parFuncname
+ + "();\n#endif\n");
+}
+
+static wxString FileToPythonArray(wxString filename, int num)
+{
+ wxString output;
+ wxString tmp;
+ wxString snum;
+ wxFFile file(filename, wxT("rb"));
+ wxFileOffset offset = file.Length();
+ wxASSERT_MSG( offset >= 0 , wxT("Invalid file length") );
+
+ const size_t lng = wx_truncate_cast(size_t, offset);
+ wxASSERT_MSG( static_cast<wxFileOffset>(lng) == offset,
+ wxT("Huge file not supported") );
+
+ snum.Printf(wxT("%i"), num);
+ output = " xml_res_file_" + snum + " = '''\\\n";
+
+ unsigned char *buffer = new unsigned char[lng];
+ file.Read(buffer, lng);
+
+ for (size_t i = 0, linelng = 0; i < lng; i++)
+ {
+ unsigned char c = buffer[i];
+ if (c == '\n')
+ {
+ tmp = (wxChar)c;
+ linelng = 0;
+ }
+ else if (c < 32 || c > 127 || c == '\'')
+ tmp.Printf(wxT("\\x%02x"), c);
+ else if (c == '\\')
+ tmp = wxT("\\\\");
+ else
+ tmp = (wxChar)c;
+ if (linelng > 70)
+ {
+ linelng = 0;
+ output << wxT("\\\n");
+ }
+ output << tmp;
+ linelng += tmp.Length();
+ }
+
+ delete[] buffer;
+
+ output += wxT("'''\n\n");
+
+ return output;
+}
+
+
+void XmlResApp::MakePackagePython(const wxArrayString& flist)
+{
+ wxFFile file(parOutput, wxT("wt"));
+ unsigned i;
+
+ if (flagVerbose)
+ wxPrintf(wxT("creating Python source file ") + parOutput + wxT("...\n"));
+
+ file.Write(
+ "#\n"
+ "# This file was automatically generated by wxrc, do not edit by hand.\n"
+ "#\n\n"
+ "import wx\n"
+ "import wx.xrc\n\n"
+ );
+
+
+ file.Write("def " + parFuncname + "():\n");
+
+ for (i = 0; i < flist.GetCount(); i++)
+ file.Write(
+ FileToPythonArray(parOutputPath + wxFILE_SEP_PATH + flist[i], i));
+
+ file.Write(
+ " # check if the memory filesystem handler has been loaded yet, and load it if not\n"
+ " wx.MemoryFSHandler.AddFile('XRC_resource/dummy_file', 'dummy value')\n"
+ " fsys = wx.FileSystem()\n"
+ " f = fsys.OpenFile('memory:XRC_resource/dummy_file')\n"
+ " wx.MemoryFSHandler.RemoveFile('XRC_resource/dummy_file')\n"
+ " if f is not None:\n"
+ " f.Destroy()\n"
+ " else:\n"
+ " wx.FileSystem.AddHandler(wx.MemoryFSHandler())\n"
+ "\n"
+ " # load all the strings as memory files and load into XmlRes\n"
+ );
+
+
+ for (i = 0; i < flist.GetCount(); i++)