1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: XML resource compiler
4 // Author: Vaclav Slavik, Eduardo Marques <edrdo@netcabo.pt>
7 // Copyright: (c) 2000 Vaclav Slavik
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx/wx.h".
12 #include "wx/wxprec.h"
18 // for all others, include the necessary headers
22 #include "wx/wxcrtvararg.h"
25 #include "wx/cmdline.h"
26 #include "wx/xml/xml.h"
28 #include "wx/filename.h"
29 #include "wx/wfstream.h"
31 #include "wx/hashset.h"
32 #include "wx/mimetype.h"
33 #include "wx/vector.h"
35 WX_DECLARE_HASH_SET(wxString
, wxStringHash
, wxStringEqual
, StringSet
);
40 XRCWidgetData(const wxString
& vname
,const wxString
& vclass
)
41 : m_class(vclass
), m_name(vname
) {}
42 const wxString
& GetName() const { return m_name
; }
43 const wxString
& GetClass() const { return m_class
; }
49 #include "wx/arrimpl.cpp"
50 WX_DECLARE_OBJARRAY(XRCWidgetData
,ArrayOfXRCWidgetData
);
51 WX_DEFINE_OBJARRAY(ArrayOfXRCWidgetData
)
57 wxString m_parentClassName
;
58 StringSet m_ancestorClassNames
;
59 ArrayOfXRCWidgetData m_wdata
;
61 void BrowseXmlNode(wxXmlNode
* node
)
68 if (node
->GetName() == wxT("object")
69 && node
->GetAttribute(wxT("class"),&classValue
)
70 && node
->GetAttribute(wxT("name"),&nameValue
))
72 m_wdata
.Add(XRCWidgetData(nameValue
,classValue
));
74 children
= node
->GetChildren();
76 BrowseXmlNode(children
);
77 node
= node
->GetNext();
82 XRCWndClassData(const wxString
& className
,
83 const wxString
& parentClassName
,
84 const wxXmlNode
* node
) :
85 m_className(className
) , m_parentClassName(parentClassName
)
87 if ( className
== wxT("wxMenu") )
89 m_ancestorClassNames
.insert(wxT("wxMenu"));
90 m_ancestorClassNames
.insert(wxT("wxMenuBar"));
92 else if ( className
== wxT("wxMDIChildFrame") )
94 m_ancestorClassNames
.insert(wxT("wxMDIParentFrame"));
96 else if( className
== wxT("wxMenuBar") ||
97 className
== wxT("wxStatusBar") ||
98 className
== wxT("wxToolBar") )
100 m_ancestorClassNames
.insert(wxT("wxFrame"));
104 m_ancestorClassNames
.insert(wxT("wxWindow"));
107 BrowseXmlNode(node
->GetChildren());
110 const ArrayOfXRCWidgetData
& GetWidgetData()
115 bool CanBeUsedWithXRCCTRL(const wxString
& name
)
117 if (name
== wxT("tool") ||
118 name
== wxT("data") ||
119 name
== wxT("unknown") ||
120 name
== wxT("notebookpage") ||
121 name
== wxT("separator") ||
122 name
== wxT("sizeritem") ||
123 name
== wxT("wxMenu") ||
124 name
== wxT("wxMenuBar") ||
125 name
== wxT("wxMenuItem") ||
126 name
.EndsWith(wxT("Sizer")) )
133 void GenerateHeaderCode(wxFFile
& file
)
136 file
.Write(wxT("class ") + m_className
+ wxT(" : public ") + m_parentClassName
137 + wxT(" {\nprotected:\n"));
139 for(i
=0;i
<m_wdata
.GetCount();++i
)
141 const XRCWidgetData
& w
= m_wdata
.Item(i
);
142 if( !CanBeUsedWithXRCCTRL(w
.GetClass()) ) continue;
143 if( w
.GetName().Length() == 0 ) continue;
145 wxT(" ") + w
.GetClass() + wxT("* ") + w
.GetName()
148 file
.Write(wxT("\nprivate:\n void InitWidgetsFromXRC(wxWindow *parent){\n")
149 wxT(" wxXmlResource::Get()->LoadObject(this,parent,wxT(\"")
154 for(i
=0;i
<m_wdata
.GetCount();++i
)
156 const XRCWidgetData
& w
= m_wdata
.Item(i
);
157 if( !CanBeUsedWithXRCCTRL(w
.GetClass()) ) continue;
158 if( w
.GetName().Length() == 0 ) continue;
161 + wxT(" = XRCCTRL(*this,\"")
167 file
.Write(wxT(" }\n"));
169 file
.Write( wxT("public:\n"));
171 if ( m_ancestorClassNames
.size() == 1 )
177 *m_ancestorClassNames
.begin() +
178 wxT(" *parent=NULL){\n") +
179 wxT(" InitWidgetsFromXRC((wxWindow *)parent);\n")
186 file
.Write(m_className
+ wxT("(){\n") +
187 wxT(" InitWidgetsFromXRC(NULL);\n")
191 for ( StringSet::const_iterator it
= m_ancestorClassNames
.begin();
192 it
!= m_ancestorClassNames
.end();
195 file
.Write(m_className
+ wxT("(") + *it
+ wxT(" *parent){\n") +
196 wxT(" InitWidgetsFromXRC((wxWindow *)parent);\n")
203 WX_DECLARE_OBJARRAY(XRCWndClassData
,ArrayOfXRCWndClassData
);
204 WX_DEFINE_OBJARRAY(ArrayOfXRCWndClassData
)
206 struct ExtractedString
208 ExtractedString() : lineNo(-1) {}
209 ExtractedString(const wxString
& str_
,
210 const wxString
& filename_
, int lineNo_
)
211 : str(str_
), filename(filename_
), lineNo(lineNo_
)
220 typedef wxVector
<ExtractedString
> ExtractedStrings
;
223 class XmlResApp
: public wxAppConsole
226 // don't use builtin cmd line parsing:
227 virtual bool OnInit() { return true; }
231 void ParseParams(const wxCmdLineParser
& cmdline
);
233 wxArrayString
PrepareTempFiles();
234 void FindFilesInXML(wxXmlNode
*node
, wxArrayString
& flist
, const wxString
& inputPath
);
236 wxString
GetInternalFileName(const wxString
& name
, const wxArrayString
& flist
);
237 void DeleteTempFiles(const wxArrayString
& flist
);
238 void MakePackageZIP(const wxArrayString
& flist
);
239 void MakePackageCPP(const wxArrayString
& flist
);
240 void MakePackagePython(const wxArrayString
& flist
);
242 void OutputGettext();
243 ExtractedStrings
FindStrings();
244 ExtractedStrings
FindStrings(const wxString
& filename
, wxXmlNode
*node
);
246 bool flagVerbose
, flagCPP
, flagPython
, flagGettext
;
247 wxString parOutput
, parFuncname
, parOutputPath
;
248 wxArrayString parFiles
;
251 ArrayOfXRCWndClassData aXRCWndClassData
;
256 IMPLEMENT_APP_CONSOLE(XmlResApp
)
258 int XmlResApp::OnRun()
260 static const wxCmdLineEntryDesc cmdLineDesc
[] =
262 { wxCMD_LINE_SWITCH
, "h", "help", "show help message", wxCMD_LINE_VAL_NONE
, wxCMD_LINE_OPTION_HELP
},
263 { wxCMD_LINE_SWITCH
, "v", "verbose", "be verbose" },
264 { wxCMD_LINE_SWITCH
, "e", "extra-cpp-code", "output C++ header file with XRC derived classes" },
265 { wxCMD_LINE_SWITCH
, "c", "cpp-code", "output C++ source rather than .rsc file" },
266 { wxCMD_LINE_SWITCH
, "p", "python-code", "output wxPython source rather than .rsc file" },
267 { wxCMD_LINE_SWITCH
, "g", "gettext", "output list of translatable strings (to stdout or file if -o used)" },
268 { wxCMD_LINE_OPTION
, "n", "function", "C++/Python function name (with -c or -p) [InitXmlResource]" },
269 { wxCMD_LINE_OPTION
, "o", "output", "output file [resource.xrs/cpp]" },
270 #if 0 // not yet implemented
271 { wxCMD_LINE_OPTION
, "l", "list-of-handlers", "output list of necessary handlers to this file" },
273 { wxCMD_LINE_PARAM
, NULL
, NULL
, "input file(s)",
274 wxCMD_LINE_VAL_STRING
,
275 wxCMD_LINE_PARAM_MULTIPLE
| wxCMD_LINE_OPTION_MANDATORY
},
280 wxCmdLineParser
parser(cmdLineDesc
, argc
, argv
);
282 switch (parser
.Parse())
302 void XmlResApp::ParseParams(const wxCmdLineParser
& cmdline
)
304 flagGettext
= cmdline
.Found("g");
305 flagVerbose
= cmdline
.Found("v");
306 flagCPP
= cmdline
.Found("c");
307 flagPython
= cmdline
.Found("p");
308 flagH
= flagCPP
&& cmdline
.Found("e");
311 if (!cmdline
.Found("o", &parOutput
))
314 parOutput
= wxEmptyString
;
318 parOutput
= wxT("resource.cpp");
320 parOutput
= wxT("resource.py");
322 parOutput
= wxT("resource.xrs");
325 if (!parOutput
.empty())
327 wxFileName
fn(parOutput
);
329 parOutput
= fn
.GetFullPath();
330 parOutputPath
= wxPathOnly(parOutput
);
332 if (!parOutputPath
) parOutputPath
= wxT(".");
334 if (!cmdline
.Found("n", &parFuncname
))
335 parFuncname
= wxT("InitXmlResource");
337 for (size_t i
= 0; i
< cmdline
.GetParamCount(); i
++)
340 wxString fn
=wxFindFirstFile(cmdline
.GetParam(i
), wxFILE
);
347 parFiles
.Add(cmdline
.GetParam(i
));
355 void XmlResApp::CompileRes()
357 wxArrayString files
= PrepareTempFiles();
359 wxRemoveFile(parOutput
);
364 MakePackageCPP(files
);
369 MakePackagePython(files
);
371 MakePackageZIP(files
);
374 DeleteTempFiles(files
);
378 wxString
XmlResApp::GetInternalFileName(const wxString
& name
, const wxArrayString
& flist
)
380 wxString name2
= name
;
381 name2
.Replace(wxT(":"), wxT("_"));
382 name2
.Replace(wxT("/"), wxT("_"));
383 name2
.Replace(wxT("\\"), wxT("_"));
384 name2
.Replace(wxT("*"), wxT("_"));
385 name2
.Replace(wxT("?"), wxT("_"));
387 wxString s
= wxFileNameFromPath(parOutput
) + wxT("$") + name2
;
389 if (wxFileExists(s
) && flist
.Index(s
) == wxNOT_FOUND
)
391 for (int i
= 0;; i
++)
393 s
.Printf(wxFileNameFromPath(parOutput
) + wxT("$%03i-") + name2
, i
);
394 if (!wxFileExists(s
) || flist
.Index(s
) != wxNOT_FOUND
)
401 wxArrayString
XmlResApp::PrepareTempFiles()
405 for (size_t i
= 0; i
< parFiles
.GetCount(); i
++)
408 wxPrintf(wxT("processing ") + parFiles
[i
] + wxT("...\n"));
412 if (!doc
.Load(parFiles
[i
]))
414 wxLogError(wxT("Error parsing file ") + parFiles
[i
]);
419 wxString name
, ext
, path
;
420 wxFileName::SplitPath(parFiles
[i
], &path
, &name
, &ext
);
422 FindFilesInXML(doc
.GetRoot(), flist
, path
);
425 wxXmlNode
* node
= (doc
.GetRoot())->GetChildren();
426 wxString classValue
,nameValue
;
428 if(node
->GetName() == wxT("object")
429 && node
->GetAttribute(wxT("class"),&classValue
)
430 && node
->GetAttribute(wxT("name"),&nameValue
)){
432 aXRCWndClassData
.Add(
433 XRCWndClassData(nameValue
,classValue
,node
)
436 node
= node
-> GetNext();
439 wxString internalName
= GetInternalFileName(parFiles
[i
], flist
);
441 doc
.Save(parOutputPath
+ wxFILE_SEP_PATH
+ internalName
);
442 flist
.Add(internalName
);
449 // Does 'node' contain filename information at all?
450 static bool NodeContainsFilename(wxXmlNode
*node
)
452 const wxString name
= node
->GetName();
454 // Any bitmaps (bitmap2 is used for disabled toolbar buttons):
455 if ( name
== wxT("bitmap") || name
== wxT("bitmap2") )
458 if ( name
== wxT("icon") )
462 wxXmlNode
*parent
= node
->GetParent();
463 if (parent
!= NULL
&&
464 parent
->GetAttribute(wxT("class"), wxT("")) == wxT("wxBitmapButton") &&
465 (name
== wxT("focus") ||
466 name
== wxT("disabled") ||
467 name
== wxT("hover") ||
468 name
== wxT("selected")))
471 // wxBitmap or wxIcon toplevel resources:
472 if ( name
== wxT("object") )
474 wxString klass
= node
->GetAttribute(wxT("class"), wxEmptyString
);
475 if (klass
== wxT("wxBitmap") ||
476 klass
== wxT("wxIcon") ||
477 klass
== wxT("data") )
481 // URLs in wxHtmlWindow:
482 if ( name
== wxT("url") &&
484 parent
->GetAttribute(wxT("class"), wxT("")) == wxT("wxHtmlWindow") )
486 // FIXME: this is wrong for e.g. http:// URLs
493 // find all files mentioned in structure, e.g. <bitmap>filename</bitmap>
494 void XmlResApp::FindFilesInXML(wxXmlNode
*node
, wxArrayString
& flist
, const wxString
& inputPath
)
496 // Is 'node' XML node element?
497 if (node
== NULL
) return;
498 if (node
->GetType() != wxXML_ELEMENT_NODE
) return;
500 bool containsFilename
= NodeContainsFilename(node
);
502 wxXmlNode
*n
= node
->GetChildren();
505 if (containsFilename
&&
506 (n
->GetType() == wxXML_TEXT_NODE
||
507 n
->GetType() == wxXML_CDATA_SECTION_NODE
))
510 if (wxIsAbsolutePath(n
->GetContent()) || inputPath
.empty())
511 fullname
= n
->GetContent();
513 fullname
= inputPath
+ wxFILE_SEP_PATH
+ n
->GetContent();
516 wxPrintf(wxT("adding ") + fullname
+ wxT("...\n"));
518 wxString filename
= GetInternalFileName(n
->GetContent(), flist
);
519 n
->SetContent(filename
);
521 if (flist
.Index(filename
) == wxNOT_FOUND
)
524 wxFileInputStream
sin(fullname
);
525 wxFileOutputStream
sout(parOutputPath
+ wxFILE_SEP_PATH
+ filename
);
526 sin
.Read(sout
); // copy the stream
530 if (n
->GetType() == wxXML_ELEMENT_NODE
)
531 FindFilesInXML(n
, flist
, inputPath
);
539 void XmlResApp::DeleteTempFiles(const wxArrayString
& flist
)
541 for (size_t i
= 0; i
< flist
.GetCount(); i
++)
542 wxRemoveFile(parOutputPath
+ wxFILE_SEP_PATH
+ flist
[i
]);
547 void XmlResApp::MakePackageZIP(const wxArrayString
& flist
)
551 for (size_t i
= 0; i
< flist
.GetCount(); i
++)
552 files
+= flist
[i
] + wxT(" ");
556 wxPrintf(wxT("compressing ") + parOutput
+ wxT("...\n"));
558 wxString cwd
= wxGetCwd();
559 wxSetWorkingDirectory(parOutputPath
);
560 int execres
= wxExecute(wxT("zip -9 -j ") +
561 wxString(flagVerbose
? wxT("\"") : wxT("-q \"")) +
562 parOutput
+ wxT("\" ") + files
, true);
563 wxSetWorkingDirectory(cwd
);
566 wxLogError(wxT("Unable to execute zip program. Make sure it is in the path."));
567 wxLogError(wxT("You can download it at http://www.cdrom.com/pub/infozip/"));
575 static wxString
FileToCppArray(wxString filename
, int num
)
580 wxFFile
file(filename
, wxT("rb"));
581 wxFileOffset offset
= file
.Length();
582 wxASSERT_MSG( offset
>= 0 , wxT("Invalid file length") );
584 const size_t lng
= wx_truncate_cast(size_t, offset
);
585 wxASSERT_MSG( static_cast<wxFileOffset
>(lng
) == offset
,
586 wxT("Huge file not supported") );
588 snum
.Printf(wxT("%i"), num
);
589 output
.Printf(wxT("static size_t xml_res_size_") + snum
+ wxT(" = %zu;\n"), lng
);
590 output
+= wxT("static unsigned char xml_res_file_") + snum
+ wxT("[] = {\n");
591 // we cannot use string literals because MSVC is dumb wannabe compiler
592 // with arbitrary limitation to 2048 strings :(
594 unsigned char *buffer
= new unsigned char[lng
];
595 file
.Read(buffer
, lng
);
597 for (size_t i
= 0, linelng
= 0; i
< lng
; i
++)
599 tmp
.Printf(wxT("%i"), buffer
[i
]);
600 if (i
!= 0) output
<< wxT(',');
607 linelng
+= tmp
.Length()+1;
612 output
+= wxT("};\n\n");
618 void XmlResApp::MakePackageCPP(const wxArrayString
& flist
)
620 wxFFile
file(parOutput
, wxT("wt"));
624 wxPrintf(wxT("creating C++ source file ") + parOutput
+ wxT("...\n"));
628 "// This file was automatically generated by wxrc, do not edit by hand.\n"
630 "#include <wx/wxprec.h>\n"
632 "#ifdef __BORLANDC__\n"
637 "#include <wx/filesys.h>\n"
638 "#include <wx/fs_mem.h>\n"
639 "#include <wx/xrc/xmlres.h>\n"
640 "#include <wx/xrc/xh_all.h>\n"
642 "#if wxCHECK_VERSION(2,8,5) && wxABI_VERSION >= 20805\n"
643 " #define XRC_ADD_FILE(name, data, size, mime) \\\n"
644 " wxMemoryFSHandler::AddFileWithMimeType(name, data, size, mime)\n"
646 " #define XRC_ADD_FILE(name, data, size, mime) \\\n"
647 " wxMemoryFSHandler::AddFile(name, data, size)\n"
651 for (i
= 0; i
< flist
.GetCount(); i
++)
653 FileToCppArray(parOutputPath
+ wxFILE_SEP_PATH
+ flist
[i
], i
));
656 "void " + parFuncname
+ "()\n"
659 " // Check for memory FS. If not present, load the handler:\n"
661 " wxMemoryFSHandler::AddFile(wxT(\"XRC_resource/dummy_file\"), wxT(\"dummy one\"));\n"
662 " wxFileSystem fsys;\n"
663 " wxFSFile *f = fsys.OpenFile(wxT(\"memory:XRC_resource/dummy_file\"));\n"
664 " wxMemoryFSHandler::RemoveFile(wxT(\"XRC_resource/dummy_file\"));\n"
665 " if (f) delete f;\n"
666 " else wxFileSystem::AddHandler(new wxMemoryFSHandler);\n"
670 for (i
= 0; i
< flist
.GetCount(); i
++)
675 wxString ext
= wxFileName(flist
[i
]).GetExt();
676 if ( ext
.Lower() == wxT("xrc") )
677 mime
= wxT("text/xml");
681 wxFileType
*ft
= wxTheMimeTypesManager
->GetFileTypeFromExtension(ext
);
684 ft
->GetMimeType(&mime
);
688 #endif // wxUSE_MIMETYPE
690 s
.Printf(" XRC_ADD_FILE(wxT(\"XRC_resource/" + flist
[i
] +
691 "\"), xml_res_file_%u, xml_res_size_%u, wxT(\"%s\"));\n",
696 for (i
= 0; i
< parFiles
.GetCount(); i
++)
698 file
.Write(" wxXmlResource::Get()->Load(wxT(\"memory:XRC_resource/" +
699 GetInternalFileName(parFiles
[i
], flist
) + "\"));\n");
707 void XmlResApp::GenCPPHeader()
709 wxString fileSpec
= ((parOutput
.BeforeLast('.')).AfterLast('/')).AfterLast('\\');
710 wxString heaFileName
= fileSpec
+ wxT(".h");
712 wxFFile
file(heaFileName
, wxT("wt"));
715 "// This file was automatically generated by wxrc, do not edit by hand.\n"
717 "#ifndef __" + fileSpec
+ "_h__\n"
718 "#define __" + fileSpec
+ "_h__\n"
720 for(size_t i
=0;i
<aXRCWndClassData
.GetCount();++i
){
721 aXRCWndClassData
.Item(i
).GenerateHeaderCode(file
);
729 static wxString
FileToPythonArray(wxString filename
, int num
)
734 wxFFile
file(filename
, wxT("rb"));
735 wxFileOffset offset
= file
.Length();
736 wxASSERT_MSG( offset
>= 0 , wxT("Invalid file length") );
738 const size_t lng
= wx_truncate_cast(size_t, offset
);
739 wxASSERT_MSG( static_cast<wxFileOffset
>(lng
) == offset
,
740 wxT("Huge file not supported") );
742 snum
.Printf(wxT("%i"), num
);
743 output
= " xml_res_file_" + snum
+ " = '''\\\n";
745 unsigned char *buffer
= new unsigned char[lng
];
746 file
.Read(buffer
, lng
);
748 for (size_t i
= 0, linelng
= 0; i
< lng
; i
++)
750 unsigned char c
= buffer
[i
];
756 else if (c
< 32 || c
> 127 || c
== '\'')
757 tmp
.Printf(wxT("\\x%02x"), c
);
765 output
<< wxT("\\\n");
768 linelng
+= tmp
.Length();
773 output
+= wxT("'''\n\n");
779 void XmlResApp::MakePackagePython(const wxArrayString
& flist
)
781 wxFFile
file(parOutput
, wxT("wt"));
785 wxPrintf(wxT("creating Python source file ") + parOutput
+ wxT("...\n"));
789 "# This file was automatically generated by wxrc, do not edit by hand.\n"
796 file
.Write("def " + parFuncname
+ "():\n");
798 for (i
= 0; i
< flist
.GetCount(); i
++)
800 FileToPythonArray(parOutputPath
+ wxFILE_SEP_PATH
+ flist
[i
], i
));
803 " # check if the memory filesystem handler has been loaded yet, and load it if not\n"
804 " wx.MemoryFSHandler.AddFile('XRC_resource/dummy_file', 'dummy value')\n"
805 " fsys = wx.FileSystem()\n"
806 " f = fsys.OpenFile('memory:XRC_resource/dummy_file')\n"
807 " wx.MemoryFSHandler.RemoveFile('XRC_resource/dummy_file')\n"
808 " if f is not None:\n"
811 " wx.FileSystem.AddHandler(wx.MemoryFSHandler())\n"
813 " # load all the strings as memory files and load into XmlRes\n"
817 for (i
= 0; i
< flist
.GetCount(); i
++)
820 s
.Printf(" wx.MemoryFSHandler.AddFile('XRC_resource/" + flist
[i
] +
821 "', xml_res_file_%u)\n", i
);
824 for (i
= 0; i
< parFiles
.GetCount(); i
++)
826 file
.Write(" wx.xrc.XmlResource.Get().Load('memory:XRC_resource/" +
827 GetInternalFileName(parFiles
[i
], flist
) + "')\n");
835 void XmlResApp::OutputGettext()
837 ExtractedStrings str
= FindStrings();
840 if (parOutput
.empty())
843 fout
.Open(parOutput
, wxT("wt"));
845 for (ExtractedStrings::const_iterator i
= str
.begin(); i
!= str
.end(); ++i
)
847 const wxFileName
filename(i
->filename
);
850 s
.Printf("#line %d \"%s\"\n",
851 i
->lineNo
, filename
.GetFullPath(wxPATH_UNIX
));
854 fout
.Write("_(\"" + i
->str
+ "\");\n");
857 if (!parOutput
) fout
.Detach();
862 ExtractedStrings
XmlResApp::FindStrings()
864 ExtractedStrings arr
, a2
;
866 for (size_t i
= 0; i
< parFiles
.GetCount(); i
++)
869 wxPrintf(wxT("processing ") + parFiles
[i
] + wxT("...\n"));
872 if (!doc
.Load(parFiles
[i
]))
874 wxLogError(wxT("Error parsing file ") + parFiles
[i
]);
878 a2
= FindStrings(parFiles
[i
], doc
.GetRoot());
880 WX_APPEND_ARRAY(arr
, a2
);
888 static wxString
ConvertText(const wxString
& str
)
893 for (dt
= str
.c_str(); *dt
; dt
++)
897 if ( *(++dt
) == wxT('_') )
900 str2
<< wxT('&') << *dt
;
906 case wxT('\n') : str2
<< wxT("\\n"); break;
907 case wxT('\t') : str2
<< wxT("\\t"); break;
908 case wxT('\r') : str2
<< wxT("\\r"); break;
909 case wxT('\\') : if ((*(dt
+1) != 'n') &&
916 case wxT('"') : str2
<< wxT("\\\""); break;
917 default : str2
<< *dt
; break;
927 XmlResApp::FindStrings(const wxString
& filename
, wxXmlNode
*node
)
929 ExtractedStrings arr
;
932 if (n
== NULL
) return arr
;
933 n
= n
->GetChildren();
937 if ((node
->GetType() == wxXML_ELEMENT_NODE
) &&
938 // parent is an element, i.e. has subnodes...
939 (n
->GetType() == wxXML_TEXT_NODE
||
940 n
->GetType() == wxXML_CDATA_SECTION_NODE
) &&
941 // ...it is textnode...
943 node
/*not n!*/->GetName() == wxT("label") ||
944 (node
/*not n!*/->GetName() == wxT("value") &&
945 !n
->GetContent().IsNumber()) ||
946 node
/*not n!*/->GetName() == wxT("help") ||
947 node
/*not n!*/->GetName() == wxT("longhelp") ||
948 node
/*not n!*/->GetName() == wxT("tooltip") ||
949 node
/*not n!*/->GetName() == wxT("htmlcode") ||
950 node
/*not n!*/->GetName() == wxT("title") ||
951 node
/*not n!*/->GetName() == wxT("item")
953 // ...and known to contain translatable string
956 node
->GetAttribute(wxT("translate"), wxT("1")) != wxT("0"))
962 ConvertText(n
->GetContent()),
971 if (n
->GetType() == wxXML_ELEMENT_NODE
)
973 ExtractedStrings a2
= FindStrings(filename
, n
);
974 WX_APPEND_ARRAY(arr
, a2
);