+ for (i = 0; i < parFiles.Count(); i++)
+ {
+ file.Write(_T(" wxXmlResource::Get()->Load(wxT(\"memory:XRC_resource/") +
+ GetInternalFileName(parFiles[i], flist) + _T("\"));\n"));
+ }
+
+ file.Write(_T("}\n"));
+
+
+}
+
+void XmlResApp::GenCPPHeader()
+{
+ wxString fileSpec = ((parOutput.BeforeLast('.')).AfterLast('/')).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<aXRCWndClassData.Count();++i){
+ aXRCWndClassData.Item(i).GenerateHeaderCode(file);
+ }
+ file.Write(
+ _T("\nvoid \n")
+ + parFuncname
+ + _T("();\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( offset == lng, wxT("Huge file not supported") );
+
+ snum.Printf(_T("%i"), num);
+ output = _T(" xml_res_file_") + snum + _T(" = '''\\\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(_T("\\x%02x"), c);
+ else if (c == '\\')
+ tmp = _T("\\\\");
+ else
+ tmp = (wxChar)c;
+ if (linelng > 70)
+ {
+ linelng = 0;
+ output << _T("\\\n");
+ }
+ output << tmp;
+ linelng += tmp.Length();
+ }
+
+ delete[] buffer;
+
+ output += _T("'''\n\n");
+
+ return output;
+}
+
+
+void XmlResApp::MakePackagePython(const wxArrayString& flist)
+{
+ wxFFile file(parOutput, wxT("wt"));
+ size_t i;
+
+ if (flagVerbose)
+ wxPrintf(_T("creating Python source file ") + parOutput + _T("...\n"));
+
+ file.Write(
+ _T("#\n")
+ _T("# This file was automatically generated by wxrc, do not edit by hand.\n")
+ _T("#\n\n")
+ _T("import wx\n")
+ _T("import wx.xrc\n\n")
+ );
+
+
+ file.Write(_T("def ") + parFuncname + _T("():\n"));
+
+ for (i = 0; i < flist.Count(); i++)
+ file.Write(
+ FileToPythonArray(parOutputPath + wxFILE_SEP_PATH + flist[i], i));
+
+ file.Write(
+ _T(" # check if the memory filesystem handler has been loaded yet, and load it if not\n")
+ _T(" wx.MemoryFSHandler.AddFile('XRC_resource/dummy_file', 'dummy value')\n")
+ _T(" fsys = wx.FileSystem()\n")
+ _T(" f = fsys.OpenFile('memory:XRC_resource/dummy_file')\n")
+ _T(" wx.MemoryFSHandler.RemoveFile('XRC_resource/dummy_file')\n")
+ _T(" if f is not None:\n")
+ _T(" f.Destroy()\n")
+ _T(" else:\n")
+ _T(" wx.FileSystem.AddHandler(wx.MemoryFSHandler())\n")
+ _T("\n")
+ _T(" # load all the strings as memory files and load into XmlRes\n")
+ );
+
+
+ for (i = 0; i < flist.Count(); i++)
+ {
+ wxString s;
+ s.Printf(_T(" wx.MemoryFSHandler.AddFile('XRC_resource/") + flist[i] +
+ _T("', xml_res_file_%i)\n"), i);
+ file.Write(s);
+ }
+ for (i = 0; i < parFiles.Count(); i++)
+ {
+ file.Write(_T(" wx.xrc.XmlResource.Get().Load('memory:XRC_resource/") +
+ GetInternalFileName(parFiles[i], flist) + _T("')\n"));
+ }
+
+ file.Write(_T("\n"));
+}
+
+
+
+void XmlResApp::OutputGettext()
+{
+ wxArrayString str = FindStrings();
+
+ wxFFile fout;
+ if (parOutput.empty())
+ fout.Attach(stdout);
+ else
+ fout.Open(parOutput, wxT("wt"));
+
+ for (size_t i = 0; i < str.GetCount(); i++)
+ fout.Write(_T("_(\"") + str[i] + _T("\");\n"));
+
+ if (!parOutput) fout.Detach();
+}
+
+
+
+wxArrayString XmlResApp::FindStrings()
+{
+ wxArrayString arr, a2;
+
+ for (size_t i = 0; i < parFiles.Count(); i++)
+ {
+ if (flagVerbose)
+ wxPrintf(_T("processing ") + parFiles[i] + _T("...\n"));
+
+ wxXmlDocument doc;
+ if (!doc.Load(parFiles[i]))
+ {
+ wxLogError(_T("Error parsing file ") + parFiles[i]);
+ retCode = 1;
+ continue;
+ }
+ a2 = FindStrings(doc.GetRoot());
+ WX_APPEND_ARRAY(arr, a2);
+ }
+
+ return arr;
+}
+
+
+
+static wxString ConvertText(const wxString& str)
+{
+ wxString str2;
+ const wxChar *dt;
+
+ for (dt = str.c_str(); *dt; dt++)
+ {
+ if (*dt == wxT('_'))
+ {
+ if ( *(++dt) == wxT('_') )
+ str2 << wxT('_');
+ else
+ str2 << wxT('&') << *dt;
+ }
+ else
+ {
+ switch (*dt)
+ {
+ case wxT('\n') : str2 << wxT("\\n"); break;
+ case wxT('\t') : str2 << wxT("\\t"); break;
+ case wxT('\r') : str2 << wxT("\\r"); break;
+ case wxT('\\') : if ((*(dt+1) != 'n') &&
+ (*(dt+1) != 't') &&
+ (*(dt+1) != 'r'))
+ str2 << wxT("\\\\");
+ else
+ str2 << wxT("\\");
+ break;
+ case wxT('"') : str2 << wxT("\\\""); break;
+ default : str2 << *dt; break;
+ }
+ }
+ }
+
+ return str2;
+}
+
+
+wxArrayString XmlResApp::FindStrings(wxXmlNode *node)
+{
+ wxArrayString arr;
+
+ wxXmlNode *n = node;
+ if (n == NULL) return arr;
+ n = n->GetChildren();
+
+ while (n)
+ {
+ if ((node->GetType() == wxXML_ELEMENT_NODE) &&
+ // parent is an element, i.e. has subnodes...
+ (n->GetType() == wxXML_TEXT_NODE ||
+ n->GetType() == wxXML_CDATA_SECTION_NODE) &&
+ // ...it is textnode...
+ (
+ node/*not n!*/->GetName() == _T("label") ||
+ (node/*not n!*/->GetName() == _T("value") &&
+ !n->GetContent().IsNumber()) ||
+ node/*not n!*/->GetName() == _T("help") ||
+ node/*not n!*/->GetName() == _T("longhelp") ||
+ node/*not n!*/->GetName() == _T("tooltip") ||
+ node/*not n!*/->GetName() == _T("htmlcode") ||
+ node/*not n!*/->GetName() == _T("title") ||
+ node/*not n!*/->GetName() == _T("item")
+ ))
+ // ...and known to contain translatable string
+ {
+ if (!flagGettext ||
+ node->GetPropVal(_T("translate"), _T("1")) != _T("0"))
+ {
+ arr.Add(ConvertText(n->GetContent()));
+ }
+ }
+
+ // subnodes:
+ if (n->GetType() == wxXML_ELEMENT_NODE)
+ {
+ wxArrayString a2 = FindStrings(n);
+ WX_APPEND_ARRAY(arr, a2);
+ }
+
+ n = n->GetNext();
+ }
+ return arr;