2000-07-25 14:47:21 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wxrc.cpp
|
|
|
|
// Purpose: XML resource compiler
|
2004-02-05 16:58:29 -05:00
|
|
|
// Author: Vaclav Slavik, Eduardo Marques <edrdo@netcabo.pt>
|
2000-07-25 14:47:21 -04:00
|
|
|
// Created: 2000/03/05
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 2000 Vaclav Slavik
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2002-09-07 08:28:46 -04:00
|
|
|
#if defined(__GNUG__) && !defined(__APPLE__)
|
2000-07-25 14:47:21 -04:00
|
|
|
#pragma implementation
|
|
|
|
#pragma interface
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
2003-09-19 11:44:28 -04:00
|
|
|
// for all others, include the necessary headers
|
2000-07-25 14:47:21 -04:00
|
|
|
#ifndef WX_PRECOMP
|
2003-09-19 11:44:28 -04:00
|
|
|
#include "wx/app.h"
|
|
|
|
#include "wx/log.h"
|
2000-07-25 14:47:21 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "wx/cmdline.h"
|
2003-07-20 18:15:32 -04:00
|
|
|
#include "wx/xml/xml.h"
|
2000-07-25 14:47:21 -04:00
|
|
|
#include "wx/ffile.h"
|
2002-12-25 10:23:44 -05:00
|
|
|
#include "wx/filename.h"
|
2000-08-11 15:07:43 -04:00
|
|
|
#include "wx/wfstream.h"
|
2005-01-21 07:40:19 -05:00
|
|
|
#include "wx/utils.h"
|
2000-08-11 15:07:43 -04:00
|
|
|
|
|
|
|
|
2004-02-05 16:58:29 -05:00
|
|
|
class XRCWidgetData
|
|
|
|
{
|
|
|
|
public:
|
2004-06-11 09:14:23 -04:00
|
|
|
XRCWidgetData(const wxString& vname,const wxString& vclass)
|
2004-02-05 16:58:29 -05:00
|
|
|
: 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;
|
|
|
|
};
|
2005-01-13 14:57:24 -05:00
|
|
|
|
2004-02-05 16:58:29 -05:00
|
|
|
#include "wx/arrimpl.cpp"
|
|
|
|
WX_DECLARE_OBJARRAY(XRCWidgetData,ArrayOfXRCWidgetData);
|
|
|
|
WX_DEFINE_OBJARRAY(ArrayOfXRCWidgetData);
|
|
|
|
|
|
|
|
class XRCWndClassData
|
|
|
|
{
|
2004-06-11 09:14:23 -04:00
|
|
|
private:
|
2004-02-05 16:58:29 -05:00
|
|
|
wxString m_className;
|
|
|
|
wxString m_parentClassName;
|
|
|
|
ArrayOfXRCWidgetData m_wdata;
|
2004-06-11 09:14:23 -04:00
|
|
|
|
2004-02-05 16:58:29 -05:00
|
|
|
void BrowseXmlNode(wxXmlNode* node)
|
|
|
|
{
|
|
|
|
wxString classValue;
|
|
|
|
wxString nameValue;
|
2004-06-11 09:14:23 -04:00
|
|
|
wxXmlNode* children;
|
2004-02-05 16:58:29 -05:00
|
|
|
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)
|
2004-06-11 09:14:23 -04:00
|
|
|
BrowseXmlNode(children);
|
2004-02-05 16:58:29 -05:00
|
|
|
node = node->GetNext();
|
|
|
|
}
|
|
|
|
}
|
2004-06-11 09:14:23 -04:00
|
|
|
|
2004-02-05 16:58:29 -05:00
|
|
|
public:
|
2004-03-18 12:23:31 -05:00
|
|
|
XRCWndClassData(const wxString& className,const wxString& parentClassName, const wxXmlNode* node) :
|
2005-01-13 14:57:24 -05:00
|
|
|
m_className(className) , m_parentClassName(parentClassName)
|
|
|
|
{
|
2004-03-18 12:23:31 -05:00
|
|
|
BrowseXmlNode(node->GetChildren());
|
|
|
|
}
|
2004-06-11 09:14:23 -04:00
|
|
|
|
2005-01-13 14:57:24 -05:00
|
|
|
const ArrayOfXRCWidgetData& GetWidgetData()
|
|
|
|
{
|
2004-03-18 12:23:31 -05:00
|
|
|
return m_wdata;
|
|
|
|
}
|
2004-08-23 08:55:16 -04:00
|
|
|
|
|
|
|
bool IsRealClass(const wxString& name)
|
|
|
|
{
|
2005-01-13 14:57:24 -05:00
|
|
|
if (name == _T("tool") ||
|
|
|
|
name == _T("unknown") ||
|
|
|
|
name == _T("notebookpage") ||
|
|
|
|
name == _T("separator") ||
|
2004-08-23 08:55:16 -04:00
|
|
|
name == _T("sizeritem") ||
|
|
|
|
name == _T("wxMenuItem"))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2005-01-13 14:57:24 -05:00
|
|
|
|
2004-08-23 08:55:16 -04:00
|
|
|
void GenerateHeaderCode(wxFFile& file)
|
|
|
|
{
|
2004-03-18 12:23:31 -05:00
|
|
|
|
|
|
|
file.Write(_T("class ") + m_className + _T(" : public ") + m_parentClassName
|
|
|
|
+ _T(" {\nprotected:\n"));
|
|
|
|
size_t i;
|
2004-08-23 08:55:16 -04:00
|
|
|
for(i=0;i<m_wdata.Count();++i)
|
|
|
|
{
|
2004-03-18 12:23:31 -05:00
|
|
|
const XRCWidgetData& w = m_wdata.Item(i);
|
2005-01-13 14:57:24 -05:00
|
|
|
if( !IsRealClass(w.GetClass()) ) continue;
|
|
|
|
if( w.GetName().Length() == 0 ) continue;
|
2004-03-18 12:23:31 -05:00
|
|
|
file.Write(
|
|
|
|
_T(" ") + w.GetClass() + _T("* ") + w.GetName()
|
|
|
|
+ _T(";\n"));
|
|
|
|
}
|
|
|
|
file.Write(_T("\nprivate:\n void InitWidgetsFromXRC(){\n")
|
2004-11-16 15:49:58 -05:00
|
|
|
_T(" wxXmlResource::Get()->LoadObject(this,NULL,_T(\"")
|
2004-06-11 09:14:23 -04:00
|
|
|
+ m_className
|
2004-11-16 15:49:58 -05:00
|
|
|
+ _T("\"), _T(\"")
|
2004-06-11 09:14:23 -04:00
|
|
|
+ m_parentClassName
|
2004-11-16 15:49:58 -05:00
|
|
|
+ _T("\"));\n"));
|
2004-08-23 08:55:16 -04:00
|
|
|
for(i=0;i<m_wdata.Count();++i)
|
|
|
|
{
|
2004-03-18 12:23:31 -05:00
|
|
|
const XRCWidgetData& w = m_wdata.Item(i);
|
2005-01-13 14:57:24 -05:00
|
|
|
if( !IsRealClass(w.GetClass()) ) continue;
|
|
|
|
if( w.GetName().Length() == 0 ) continue;
|
2004-06-11 09:14:23 -04:00
|
|
|
file.Write( _T(" ")
|
|
|
|
+ w.GetName()
|
2004-03-18 12:23:31 -05:00
|
|
|
+ _T(" = XRCCTRL(*this,\"")
|
2004-06-11 09:14:23 -04:00
|
|
|
+ w.GetName()
|
2004-03-18 12:23:31 -05:00
|
|
|
+ _T("\",")
|
|
|
|
+ w.GetClass()
|
|
|
|
+ _T(");\n")
|
|
|
|
);
|
|
|
|
}
|
2005-01-13 14:57:24 -05:00
|
|
|
file.Write(_T(" }\n"));
|
|
|
|
|
|
|
|
file.Write(
|
|
|
|
_T("public:\n")
|
|
|
|
+ m_className
|
|
|
|
+ _T("::")
|
|
|
|
+ m_className
|
|
|
|
+ _T("(){\n")
|
|
|
|
+ _T(" InitWidgetsFromXRC();\n")
|
|
|
|
_T(" }\n")
|
|
|
|
_T("};\n")
|
|
|
|
);
|
|
|
|
};
|
2004-02-05 16:58:29 -05:00
|
|
|
};
|
|
|
|
WX_DECLARE_OBJARRAY(XRCWndClassData,ArrayOfXRCWndClassData);
|
|
|
|
WX_DEFINE_OBJARRAY(ArrayOfXRCWndClassData);
|
|
|
|
|
|
|
|
|
2003-07-20 18:15:32 -04:00
|
|
|
class XmlResApp : public wxAppConsole
|
2000-07-25 14:47:21 -04:00
|
|
|
{
|
|
|
|
public:
|
2003-08-09 16:09:02 -04:00
|
|
|
// don't use builtin cmd line parsing:
|
2004-06-11 09:14:23 -04:00
|
|
|
virtual bool OnInit() { return true; }
|
2000-07-25 14:47:21 -04:00
|
|
|
virtual int OnRun();
|
2004-06-11 09:14:23 -04:00
|
|
|
|
|
|
|
private:
|
2000-07-25 14:47:21 -04:00
|
|
|
void ParseParams(const wxCmdLineParser& cmdline);
|
|
|
|
void CompileRes();
|
|
|
|
wxArrayString PrepareTempFiles();
|
2000-08-11 15:07:43 -04:00
|
|
|
void FindFilesInXML(wxXmlNode *node, wxArrayString& flist, const wxString& inputPath);
|
|
|
|
|
2002-06-22 19:33:12 -04:00
|
|
|
wxString GetInternalFileName(const wxString& name, const wxArrayString& flist);
|
2000-07-25 14:47:21 -04:00
|
|
|
void DeleteTempFiles(const wxArrayString& flist);
|
|
|
|
void MakePackageZIP(const wxArrayString& flist);
|
|
|
|
void MakePackageCPP(const wxArrayString& flist);
|
2002-08-14 07:02:39 -04:00
|
|
|
void MakePackagePython(const wxArrayString& flist);
|
2000-11-24 12:20:20 -05:00
|
|
|
|
|
|
|
void OutputGettext();
|
|
|
|
wxArrayString FindStrings();
|
|
|
|
wxArrayString FindStrings(wxXmlNode *node);
|
2004-06-11 09:14:23 -04:00
|
|
|
|
2002-08-14 07:02:39 -04:00
|
|
|
bool flagVerbose, flagCPP, flagPython, flagGettext;
|
2000-07-25 14:47:21 -04:00
|
|
|
wxString parOutput, parFuncname, parOutputPath;
|
|
|
|
wxArrayString parFiles;
|
|
|
|
int retCode;
|
2004-02-05 16:58:29 -05:00
|
|
|
|
|
|
|
ArrayOfXRCWndClassData aXRCWndClassData;
|
2004-03-18 12:23:31 -05:00
|
|
|
bool flagH;
|
|
|
|
void GenCPPHeader();
|
2000-07-25 14:47:21 -04:00
|
|
|
};
|
|
|
|
|
2003-08-25 16:48:47 -04:00
|
|
|
IMPLEMENT_APP_CONSOLE(XmlResApp)
|
2000-07-25 14:47:21 -04:00
|
|
|
|
|
|
|
int XmlResApp::OnRun()
|
|
|
|
{
|
|
|
|
static const wxCmdLineEntryDesc cmdLineDesc[] =
|
|
|
|
{
|
2004-06-11 09:14:23 -04:00
|
|
|
{ wxCMD_LINE_SWITCH, _T("h"), _T("help"), _T("show help message"),
|
2002-07-02 18:06:00 -04:00
|
|
|
wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
|
2005-02-01 15:34:39 -05:00
|
|
|
{ wxCMD_LINE_SWITCH, _T("v"), _T("verbose"), _T("be verbose"), (wxCmdLineParamType)0, 0 },
|
|
|
|
{ wxCMD_LINE_SWITCH, _T("e"), _T("extra-cpp-code"), _T("output C++ header file with XRC derived classes"), (wxCmdLineParamType)0, 0 },
|
|
|
|
{ wxCMD_LINE_SWITCH, _T("c"), _T("cpp-code"), _T("output C++ source rather than .rsc file"), (wxCmdLineParamType)0, 0 },
|
|
|
|
{ wxCMD_LINE_SWITCH, _T("p"), _T("python-code"), _T("output wxPython source rather than .rsc file"), (wxCmdLineParamType)0, 0 },
|
|
|
|
{ wxCMD_LINE_SWITCH, _T("g"), _T("gettext"), _T("output list of translatable strings (to stdout or file if -o used)"), (wxCmdLineParamType)0, 0 },
|
|
|
|
{ wxCMD_LINE_OPTION, _T("n"), _T("function"), _T("C++/Python function name (with -c or -p) [InitXmlResource]"), (wxCmdLineParamType)0, 0 },
|
|
|
|
{ wxCMD_LINE_OPTION, _T("o"), _T("output"), _T("output file [resource.xrs/cpp]"), (wxCmdLineParamType)0, 0 },
|
2002-07-02 18:06:00 -04:00
|
|
|
#if 0 // not yet implemented
|
2005-05-31 05:29:22 -04:00
|
|
|
{ wxCMD_LINE_OPTION, _T("l"), _T("list-of-handlers"), _T("output list of necessary handlers to this file"), (wxCmdLineParamType)0, 0 },
|
2002-07-02 18:06:00 -04:00
|
|
|
#endif
|
2002-12-04 09:11:26 -05:00
|
|
|
{ wxCMD_LINE_PARAM, NULL, NULL, _T("input file(s)"),
|
2004-06-11 09:14:23 -04:00
|
|
|
wxCMD_LINE_VAL_STRING,
|
2002-07-02 18:06:00 -04:00
|
|
|
wxCMD_LINE_PARAM_MULTIPLE | wxCMD_LINE_OPTION_MANDATORY },
|
2000-07-25 14:47:21 -04:00
|
|
|
|
2005-02-01 15:34:39 -05:00
|
|
|
{ wxCMD_LINE_NONE, NULL, NULL, NULL, (wxCmdLineParamType)0, 0 }
|
2000-07-25 14:47:21 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
wxCmdLineParser parser(cmdLineDesc, argc, argv);
|
|
|
|
|
|
|
|
switch (parser.Parse())
|
|
|
|
{
|
|
|
|
case -1:
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
retCode = 0;
|
|
|
|
ParseParams(parser);
|
2000-11-24 12:20:20 -05:00
|
|
|
if (flagGettext)
|
|
|
|
OutputGettext();
|
|
|
|
else
|
|
|
|
CompileRes();
|
2000-07-25 14:47:21 -04:00
|
|
|
return retCode;
|
|
|
|
}
|
2003-09-11 05:30:59 -04:00
|
|
|
return 1;
|
2000-07-25 14:47:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void XmlResApp::ParseParams(const wxCmdLineParser& cmdline)
|
|
|
|
{
|
2002-12-04 09:11:26 -05:00
|
|
|
flagGettext = cmdline.Found(_T("g"));
|
|
|
|
flagVerbose = cmdline.Found(_T("v"));
|
|
|
|
flagCPP = cmdline.Found(_T("c"));
|
|
|
|
flagPython = cmdline.Found(_T("p"));
|
2004-02-05 16:58:29 -05:00
|
|
|
flagH = flagCPP && cmdline.Found(_T("e"));
|
|
|
|
|
2000-07-25 14:47:21 -04:00
|
|
|
|
2004-06-11 09:14:23 -04:00
|
|
|
if (!cmdline.Found(_T("o"), &parOutput))
|
2000-11-24 12:20:20 -05:00
|
|
|
{
|
|
|
|
if (flagGettext)
|
|
|
|
parOutput = wxEmptyString;
|
|
|
|
else
|
2002-08-14 07:02:39 -04:00
|
|
|
{
|
|
|
|
if (flagCPP)
|
2002-12-04 09:11:26 -05:00
|
|
|
parOutput = _T("resource.cpp");
|
2002-08-14 07:02:39 -04:00
|
|
|
else if (flagPython)
|
2002-12-04 09:11:26 -05:00
|
|
|
parOutput = _T("resource.py");
|
2002-08-14 07:02:39 -04:00
|
|
|
else
|
2002-12-04 09:11:26 -05:00
|
|
|
parOutput = _T("resource.xrs");
|
2002-08-14 07:02:39 -04:00
|
|
|
}
|
2000-11-24 12:20:20 -05:00
|
|
|
}
|
2004-02-05 16:58:29 -05:00
|
|
|
if (!parOutput.empty())
|
|
|
|
{
|
|
|
|
wxFileName fn(parOutput);
|
|
|
|
fn.Normalize();
|
|
|
|
parOutput = fn.GetFullPath();
|
|
|
|
parOutputPath = wxPathOnly(parOutput);
|
|
|
|
}
|
2002-12-04 09:11:26 -05:00
|
|
|
if (!parOutputPath) parOutputPath = _T(".");
|
2000-07-25 14:47:21 -04:00
|
|
|
|
2004-06-11 09:14:23 -04:00
|
|
|
if (!cmdline.Found(_T("n"), &parFuncname))
|
2002-12-04 09:11:26 -05:00
|
|
|
parFuncname = _T("InitXmlResource");
|
2000-07-25 14:47:21 -04:00
|
|
|
|
|
|
|
for (size_t i = 0; i < cmdline.GetParamCount(); i++)
|
2003-07-21 18:23:09 -04:00
|
|
|
{
|
|
|
|
#ifdef __WINDOWS__
|
|
|
|
wxString fn=wxFindFirstFile(cmdline.GetParam(i), wxFILE);
|
2005-01-13 14:57:24 -05:00
|
|
|
while (!fn.empty())
|
2003-07-21 18:23:09 -04:00
|
|
|
{
|
|
|
|
parFiles.Add(fn);
|
|
|
|
fn=wxFindNextFile();
|
|
|
|
}
|
|
|
|
#else
|
2000-07-25 14:47:21 -04:00
|
|
|
parFiles.Add(cmdline.GetParam(i));
|
2003-07-21 18:23:09 -04:00
|
|
|
#endif
|
|
|
|
}
|
2000-07-25 14:47:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void XmlResApp::CompileRes()
|
|
|
|
{
|
|
|
|
wxArrayString files = PrepareTempFiles();
|
|
|
|
|
|
|
|
wxRemoveFile(parOutput);
|
|
|
|
|
|
|
|
if (!retCode)
|
2004-06-11 09:14:23 -04:00
|
|
|
{
|
2004-02-05 16:58:29 -05:00
|
|
|
if (flagCPP){
|
2000-07-25 14:47:21 -04:00
|
|
|
MakePackageCPP(files);
|
2004-02-05 16:58:29 -05:00
|
|
|
if (flagH)
|
|
|
|
GenCPPHeader();
|
|
|
|
}
|
2002-08-14 07:02:39 -04:00
|
|
|
else if (flagPython)
|
|
|
|
MakePackagePython(files);
|
2000-07-25 14:47:21 -04:00
|
|
|
else
|
|
|
|
MakePackageZIP(files);
|
|
|
|
}
|
2004-06-11 09:14:23 -04:00
|
|
|
|
2000-07-25 14:47:21 -04:00
|
|
|
DeleteTempFiles(files);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-06-22 19:33:12 -04:00
|
|
|
wxString XmlResApp::GetInternalFileName(const wxString& name, const wxArrayString& flist)
|
|
|
|
{
|
|
|
|
wxString name2 = name;
|
2002-12-04 09:11:26 -05:00
|
|
|
name2.Replace(_T(":"), _T("_"));
|
|
|
|
name2.Replace(_T("/"), _T("_"));
|
|
|
|
name2.Replace(_T("\\"), _T("_"));
|
|
|
|
name2.Replace(_T("*"), _T("_"));
|
|
|
|
name2.Replace(_T("?"), _T("_"));
|
2004-06-11 09:14:23 -04:00
|
|
|
|
2002-12-04 09:11:26 -05:00
|
|
|
wxString s = wxFileNameFromPath(parOutput) + _T("$") + name2;
|
2002-06-22 19:33:12 -04:00
|
|
|
|
|
|
|
if (wxFileExists(s) && flist.Index(s) == wxNOT_FOUND)
|
2004-06-11 09:14:23 -04:00
|
|
|
{
|
2002-06-22 19:33:12 -04:00
|
|
|
for (int i = 0;; i++)
|
|
|
|
{
|
2002-12-04 09:11:26 -05:00
|
|
|
s.Printf(wxFileNameFromPath(parOutput) + _T("$%03i-") + name2, i);
|
2002-06-22 19:33:12 -04:00
|
|
|
if (!wxFileExists(s) || flist.Index(s) != wxNOT_FOUND)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
2000-07-25 14:47:21 -04:00
|
|
|
|
|
|
|
wxArrayString XmlResApp::PrepareTempFiles()
|
|
|
|
{
|
|
|
|
wxArrayString flist;
|
2004-06-11 09:14:23 -04:00
|
|
|
|
2000-07-25 14:47:21 -04:00
|
|
|
for (size_t i = 0; i < parFiles.Count(); i++)
|
|
|
|
{
|
2004-06-11 09:14:23 -04:00
|
|
|
if (flagVerbose)
|
2002-12-04 09:11:26 -05:00
|
|
|
wxPrintf(_T("processing ") + parFiles[i] + _T("...\n"));
|
2000-07-25 14:47:21 -04:00
|
|
|
|
|
|
|
wxXmlDocument doc;
|
2004-06-11 09:14:23 -04:00
|
|
|
|
2000-07-25 14:47:21 -04:00
|
|
|
if (!doc.Load(parFiles[i]))
|
|
|
|
{
|
2002-12-04 09:11:26 -05:00
|
|
|
wxLogError(_T("Error parsing file ") + parFiles[i]);
|
2000-07-25 14:47:21 -04:00
|
|
|
retCode = 1;
|
|
|
|
continue;
|
|
|
|
}
|
2004-06-11 09:14:23 -04:00
|
|
|
|
2000-08-11 15:07:43 -04:00
|
|
|
wxString name, ext, path;
|
|
|
|
wxSplitPath(parFiles[i], &path, &name, &ext);
|
|
|
|
|
|
|
|
FindFilesInXML(doc.GetRoot(), flist, path);
|
2004-02-05 16:58:29 -05:00
|
|
|
if (flagH)
|
|
|
|
{
|
|
|
|
wxXmlNode* node = (doc.GetRoot())->GetChildren();
|
2004-03-18 12:23:31 -05:00
|
|
|
wxString classValue,nameValue;
|
|
|
|
while(node){
|
2004-02-05 16:58:29 -05:00
|
|
|
if(node->GetName() == _T("object")
|
2004-03-18 12:23:31 -05:00
|
|
|
&& node->GetPropVal(_T("class"),&classValue)
|
|
|
|
&& node->GetPropVal(_T("name"),&nameValue)){
|
2004-02-05 16:58:29 -05:00
|
|
|
|
|
|
|
aXRCWndClassData.Add(
|
2004-03-18 12:23:31 -05:00
|
|
|
XRCWndClassData(nameValue,classValue,node)
|
2004-02-05 16:58:29 -05:00
|
|
|
);
|
|
|
|
}
|
2004-03-18 12:23:31 -05:00
|
|
|
node = node -> GetNext();
|
2004-02-05 16:58:29 -05:00
|
|
|
}
|
|
|
|
}
|
2002-06-22 19:33:12 -04:00
|
|
|
wxString internalName = GetInternalFileName(parFiles[i], flist);
|
2004-06-11 09:14:23 -04:00
|
|
|
|
2002-12-25 10:23:44 -05:00
|
|
|
doc.Save(parOutputPath + wxFILE_SEP_PATH + internalName);
|
2002-06-22 19:33:12 -04:00
|
|
|
flist.Add(internalName);
|
2000-07-25 14:47:21 -04:00
|
|
|
}
|
2004-06-11 09:14:23 -04:00
|
|
|
|
2000-07-25 14:47:21 -04:00
|
|
|
return flist;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-25 10:23:44 -05:00
|
|
|
// Does 'node' contain filename information at all?
|
|
|
|
static bool NodeContainsFilename(wxXmlNode *node)
|
|
|
|
{
|
|
|
|
// Any bitmaps:
|
|
|
|
if (node->GetName() == _T("bitmap"))
|
2004-06-11 09:14:23 -04:00
|
|
|
return true;
|
2005-01-13 14:57:24 -05:00
|
|
|
|
2004-10-31 06:42:27 -05:00
|
|
|
if (node->GetName() == _T("icon"))
|
|
|
|
return true;
|
2002-12-25 10:23:44 -05:00
|
|
|
|
|
|
|
// URLs in wxHtmlWindow:
|
|
|
|
if (node->GetName() == _T("url"))
|
2004-06-11 09:14:23 -04:00
|
|
|
return true;
|
|
|
|
|
2002-12-25 10:23:44 -05:00
|
|
|
// wxBitmapButton:
|
|
|
|
wxXmlNode *parent = node->GetParent();
|
2004-06-11 09:14:23 -04:00
|
|
|
if (parent != NULL &&
|
2002-12-25 10:23:44 -05:00
|
|
|
parent->GetPropVal(_T("class"), _T("")) == _T("wxBitmapButton") &&
|
2004-06-11 09:14:23 -04:00
|
|
|
(node->GetName() == _T("focus") ||
|
2002-12-25 10:23:44 -05:00
|
|
|
node->GetName() == _T("disabled") ||
|
|
|
|
node->GetName() == _T("selected")))
|
2004-06-11 09:14:23 -04:00
|
|
|
return true;
|
|
|
|
|
2002-12-25 10:23:44 -05:00
|
|
|
// wxBitmap or wxIcon toplevel resources:
|
|
|
|
if (node->GetName() == _T("object"))
|
|
|
|
{
|
|
|
|
wxString klass = node->GetPropVal(_T("class"), wxEmptyString);
|
|
|
|
if (klass == _T("wxBitmap") || klass == _T("wxIcon"))
|
2004-06-11 09:14:23 -04:00
|
|
|
return true;
|
2002-12-25 10:23:44 -05:00
|
|
|
}
|
2004-06-11 09:14:23 -04:00
|
|
|
|
|
|
|
return false;
|
2002-12-25 10:23:44 -05:00
|
|
|
}
|
2000-07-25 14:47:21 -04:00
|
|
|
|
2000-08-11 15:07:43 -04:00
|
|
|
// find all files mentioned in structure, e.g. <bitmap>filename</bitmap>
|
|
|
|
void XmlResApp::FindFilesInXML(wxXmlNode *node, wxArrayString& flist, const wxString& inputPath)
|
|
|
|
{
|
2002-12-04 09:11:26 -05:00
|
|
|
// Is 'node' XML node element?
|
|
|
|
if (node == NULL) return;
|
|
|
|
if (node->GetType() != wxXML_ELEMENT_NODE) return;
|
|
|
|
|
2002-12-25 10:23:44 -05:00
|
|
|
bool containsFilename = NodeContainsFilename(node);
|
2002-12-04 09:11:26 -05:00
|
|
|
|
|
|
|
wxXmlNode *n = node->GetChildren();
|
2000-08-11 15:07:43 -04:00
|
|
|
while (n)
|
|
|
|
{
|
2002-12-04 09:11:26 -05:00
|
|
|
if (containsFilename &&
|
2004-06-11 09:14:23 -04:00
|
|
|
(n->GetType() == wxXML_TEXT_NODE ||
|
2002-12-04 09:11:26 -05:00
|
|
|
n->GetType() == wxXML_CDATA_SECTION_NODE))
|
2000-08-11 15:07:43 -04:00
|
|
|
{
|
|
|
|
wxString fullname;
|
2002-12-04 09:11:26 -05:00
|
|
|
if (wxIsAbsolutePath(n->GetContent()) || inputPath.empty())
|
|
|
|
fullname = n->GetContent();
|
|
|
|
else
|
2002-12-25 10:23:44 -05:00
|
|
|
fullname = inputPath + wxFILE_SEP_PATH + n->GetContent();
|
2002-06-22 19:33:12 -04:00
|
|
|
|
2004-06-11 09:14:23 -04:00
|
|
|
if (flagVerbose)
|
2002-12-04 09:11:26 -05:00
|
|
|
wxPrintf(_T("adding ") + fullname + _T("...\n"));
|
|
|
|
|
2002-06-22 19:33:12 -04:00
|
|
|
wxString filename = GetInternalFileName(n->GetContent(), flist);
|
2000-08-11 15:07:43 -04:00
|
|
|
n->SetContent(filename);
|
|
|
|
|
2002-12-04 09:11:26 -05:00
|
|
|
if (flist.Index(filename) == wxNOT_FOUND)
|
|
|
|
flist.Add(filename);
|
2000-08-11 15:07:43 -04:00
|
|
|
|
|
|
|
wxFileInputStream sin(fullname);
|
2002-12-25 10:23:44 -05:00
|
|
|
wxFileOutputStream sout(parOutputPath + wxFILE_SEP_PATH + filename);
|
2000-08-11 15:07:43 -04:00
|
|
|
sin.Read(sout); // copy the stream
|
|
|
|
}
|
2002-12-04 09:11:26 -05:00
|
|
|
|
2000-08-11 15:07:43 -04:00
|
|
|
// subnodes:
|
|
|
|
if (n->GetType() == wxXML_ELEMENT_NODE)
|
|
|
|
FindFilesInXML(n, flist, inputPath);
|
2002-12-04 09:11:26 -05:00
|
|
|
|
2000-08-11 15:07:43 -04:00
|
|
|
n = n->GetNext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-07-25 14:47:21 -04:00
|
|
|
void XmlResApp::DeleteTempFiles(const wxArrayString& flist)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < flist.Count(); i++)
|
2002-12-25 10:23:44 -05:00
|
|
|
wxRemoveFile(parOutputPath + wxFILE_SEP_PATH + flist[i]);
|
2000-07-25 14:47:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void XmlResApp::MakePackageZIP(const wxArrayString& flist)
|
|
|
|
{
|
|
|
|
wxString files;
|
2004-06-11 09:14:23 -04:00
|
|
|
|
2000-07-25 14:47:21 -04:00
|
|
|
for (size_t i = 0; i < flist.Count(); i++)
|
2002-12-04 09:11:26 -05:00
|
|
|
files += flist[i] + _T(" ");
|
2000-07-25 14:47:21 -04:00
|
|
|
files.RemoveLast();
|
2004-06-11 09:14:23 -04:00
|
|
|
|
|
|
|
if (flagVerbose)
|
2002-12-04 09:11:26 -05:00
|
|
|
wxPrintf(_T("compressing ") + parOutput + _T("...\n"));
|
2004-06-11 09:14:23 -04:00
|
|
|
|
2002-12-25 10:23:44 -05:00
|
|
|
wxString cwd = wxGetCwd();
|
|
|
|
wxSetWorkingDirectory(parOutputPath);
|
2004-06-11 09:14:23 -04:00
|
|
|
int execres = wxExecute(_T("zip -9 -j ") +
|
2005-01-31 17:17:18 -05:00
|
|
|
wxString(flagVerbose ? _T("\"") : _T("-q \"")) +
|
|
|
|
parOutput + _T("\" ") + files, true);
|
2002-12-25 10:23:44 -05:00
|
|
|
wxSetWorkingDirectory(cwd);
|
|
|
|
if (execres == -1)
|
2000-07-25 14:47:21 -04:00
|
|
|
{
|
2002-12-04 09:11:26 -05:00
|
|
|
wxLogError(_T("Unable to execute zip program. Make sure it is in the path."));
|
|
|
|
wxLogError(_T("You can download it at http://www.cdrom.com/pub/infozip/"));
|
2000-07-25 14:47:21 -04:00
|
|
|
retCode = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static wxString FileToCppArray(wxString filename, int num)
|
|
|
|
{
|
|
|
|
wxString output;
|
|
|
|
wxString tmp;
|
2000-08-11 15:07:43 -04:00
|
|
|
wxString snum;
|
2003-03-16 15:27:15 -05:00
|
|
|
wxFFile file(filename, wxT("rb"));
|
2005-01-13 14:57:24 -05:00
|
|
|
wxFileOffset offset = file.Length();
|
|
|
|
wxASSERT_MSG( offset >= 0 , wxT("Invalid file length") );
|
|
|
|
wxASSERT_MSG( offset == wxFileOffset(size_t(offset)) , wxT("Huge file not supported") );
|
|
|
|
size_t lng = (size_t)offset;
|
2004-06-11 09:14:23 -04:00
|
|
|
|
2002-12-04 09:11:26 -05:00
|
|
|
snum.Printf(_T("%i"), num);
|
|
|
|
output.Printf(_T("static size_t xml_res_size_") + snum + _T(" = %i;\n"), lng);
|
|
|
|
output += _T("static unsigned char xml_res_file_") + snum + _T("[] = {\n");
|
2000-10-07 17:56:37 -04:00
|
|
|
// we cannot use string literals because MSVC is dumb wannabe compiler
|
|
|
|
// with arbitrary limitation to 2048 strings :(
|
2004-06-11 09:14:23 -04:00
|
|
|
|
2000-07-25 14:47:21 -04:00
|
|
|
unsigned char *buffer = new unsigned char[lng];
|
|
|
|
file.Read(buffer, lng);
|
2004-06-11 09:14:23 -04:00
|
|
|
|
2000-08-11 15:07:43 -04:00
|
|
|
for (size_t i = 0, linelng = 0; i < lng; i++)
|
2000-07-25 14:47:21 -04:00
|
|
|
{
|
2002-12-04 09:11:26 -05:00
|
|
|
tmp.Printf(_T("%i"), buffer[i]);
|
|
|
|
if (i != 0) output << _T(',');
|
2000-10-07 17:56:37 -04:00
|
|
|
if (linelng > 70)
|
2000-08-11 15:07:43 -04:00
|
|
|
{
|
|
|
|
linelng = 0;
|
2002-12-04 09:11:26 -05:00
|
|
|
output << _T("\n");
|
2000-08-11 15:07:43 -04:00
|
|
|
}
|
2000-10-07 17:56:37 -04:00
|
|
|
output << tmp;
|
|
|
|
linelng += tmp.Length()+1;
|
2000-07-25 14:47:21 -04:00
|
|
|
}
|
2004-06-11 09:14:23 -04:00
|
|
|
|
2000-07-25 14:47:21 -04:00
|
|
|
delete[] buffer;
|
2004-06-11 09:14:23 -04:00
|
|
|
|
2002-12-04 09:11:26 -05:00
|
|
|
output += _T("};\n\n");
|
2004-06-11 09:14:23 -04:00
|
|
|
|
2000-07-25 14:47:21 -04:00
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void XmlResApp::MakePackageCPP(const wxArrayString& flist)
|
|
|
|
{
|
2003-03-16 15:27:15 -05:00
|
|
|
wxFFile file(parOutput, wxT("wt"));
|
2000-07-25 14:47:21 -04:00
|
|
|
size_t i;
|
|
|
|
|
2004-06-11 09:14:23 -04:00
|
|
|
if (flagVerbose)
|
2002-12-04 09:11:26 -05:00
|
|
|
wxPrintf(_T("creating C++ source file ") + parOutput + _T("...\n"));
|
2004-06-11 09:14:23 -04:00
|
|
|
|
2002-12-04 09:11:26 -05:00
|
|
|
file.Write(_T("")
|
|
|
|
_T("//\n")
|
|
|
|
_T("// This file was automatically generated by wxrc, do not edit by hand.\n")
|
|
|
|
_T("//\n\n")
|
|
|
|
_T("#include <wx/wxprec.h>\n")
|
|
|
|
_T("\n")
|
|
|
|
_T("#ifdef __BORLANDC__\n")
|
|
|
|
_T(" #pragma hdrstop\n")
|
|
|
|
_T("#endif\n")
|
|
|
|
_T("\n")
|
|
|
|
_T("")
|
|
|
|
_T("#include <wx/filesys.h>\n")
|
|
|
|
_T("#include <wx/fs_mem.h>\n")
|
|
|
|
_T("#include <wx/xrc/xmlres.h>\n")
|
|
|
|
_T("#include <wx/xrc/xh_all.h>\n")
|
|
|
|
_T("\n"));
|
2000-07-25 14:47:21 -04:00
|
|
|
|
|
|
|
for (i = 0; i < flist.Count(); i++)
|
2002-12-25 10:23:44 -05:00
|
|
|
file.Write(
|
|
|
|
FileToCppArray(parOutputPath + wxFILE_SEP_PATH + flist[i], i));
|
2004-06-11 09:14:23 -04:00
|
|
|
|
2002-12-04 09:11:26 -05:00
|
|
|
file.Write(_T("")
|
2003-03-16 15:27:15 -05:00
|
|
|
_T("void ") + parFuncname + wxT("()\n")
|
2002-12-04 09:11:26 -05:00
|
|
|
_T("{\n")
|
|
|
|
_T("\n")
|
|
|
|
_T(" // Check for memory FS. If not present, load the handler:\n")
|
|
|
|
_T(" {\n")
|
2003-03-16 15:27:15 -05:00
|
|
|
_T(" wxMemoryFSHandler::AddFile(wxT(\"XRC_resource/dummy_file\"), wxT(\"dummy one\"));\n")
|
2002-12-04 09:11:26 -05:00
|
|
|
_T(" wxFileSystem fsys;\n")
|
2003-03-16 15:27:15 -05:00
|
|
|
_T(" wxFSFile *f = fsys.OpenFile(wxT(\"memory:XRC_resource/dummy_file\"));\n")
|
|
|
|
_T(" wxMemoryFSHandler::RemoveFile(wxT(\"XRC_resource/dummy_file\"));\n")
|
2002-12-04 09:11:26 -05:00
|
|
|
_T(" if (f) delete f;\n")
|
|
|
|
_T(" else wxFileSystem::AddHandler(new wxMemoryFSHandler);\n")
|
|
|
|
_T(" }\n")
|
|
|
|
_T("\n"));
|
2000-07-25 14:47:21 -04:00
|
|
|
|
|
|
|
for (i = 0; i < flist.Count(); i++)
|
|
|
|
{
|
|
|
|
wxString s;
|
2003-03-16 15:27:15 -05:00
|
|
|
s.Printf(_T(" wxMemoryFSHandler::AddFile(wxT(\"XRC_resource/") + flist[i] +
|
|
|
|
_T("\"), xml_res_file_%i, xml_res_size_%i);\n"), i, i);
|
2000-07-25 14:47:21 -04:00
|
|
|
file.Write(s);
|
|
|
|
}
|
2000-08-11 15:07:43 -04:00
|
|
|
|
|
|
|
for (i = 0; i < parFiles.Count(); i++)
|
|
|
|
{
|
2003-03-16 15:27:15 -05:00
|
|
|
file.Write(_T(" wxXmlResource::Get()->Load(wxT(\"memory:XRC_resource/") +
|
|
|
|
GetInternalFileName(parFiles[i], flist) + _T("\"));\n"));
|
2000-08-11 15:07:43 -04:00
|
|
|
}
|
2004-06-11 09:14:23 -04:00
|
|
|
|
2002-12-04 09:11:26 -05:00
|
|
|
file.Write(_T("}\n"));
|
2000-07-25 14:47:21 -04:00
|
|
|
|
2000-08-11 15:07:43 -04:00
|
|
|
|
2000-07-25 14:47:21 -04:00
|
|
|
}
|
2000-11-24 12:20:20 -05:00
|
|
|
|
2004-02-05 16:58:29 -05:00
|
|
|
void XmlResApp::GenCPPHeader()
|
|
|
|
{
|
2004-08-23 08:55:16 -04:00
|
|
|
wxString fileSpec = ((parOutput.BeforeLast('.')).AfterLast('/')).AfterLast('\\');
|
2004-02-05 16:58:29 -05:00
|
|
|
wxString heaFileName = fileSpec + _T(".h");
|
2004-06-11 09:14:23 -04:00
|
|
|
|
2004-02-05 16:58:29 -05:00
|
|
|
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")
|
2004-06-11 09:14:23 -04:00
|
|
|
);
|
2004-02-05 16:58:29 -05:00
|
|
|
for(size_t i=0;i<aXRCWndClassData.Count();++i){
|
2004-06-11 09:14:23 -04:00
|
|
|
aXRCWndClassData.Item(i).GenerateHeaderCode(file);
|
|
|
|
}
|
2004-02-05 16:58:29 -05:00
|
|
|
file.Write(
|
2004-03-18 12:23:31 -05:00
|
|
|
_T("\nvoid \n")
|
|
|
|
+ parFuncname
|
|
|
|
+ _T("();\n#endif\n"));
|
2004-02-05 16:58:29 -05:00
|
|
|
}
|
|
|
|
|
2002-08-14 07:02:39 -04:00
|
|
|
static wxString FileToPythonArray(wxString filename, int num)
|
|
|
|
{
|
|
|
|
wxString output;
|
|
|
|
wxString tmp;
|
|
|
|
wxString snum;
|
2003-03-16 15:27:15 -05:00
|
|
|
wxFFile file(filename, wxT("rb"));
|
2005-01-13 14:57:24 -05:00
|
|
|
wxFileOffset offset = file.Length();
|
|
|
|
wxASSERT_MSG( offset >= 0 , wxT("Invalid file length") );
|
|
|
|
wxASSERT_MSG( offset == wxFileOffset(size_t(offset)) , wxT("Huge file not supported") );
|
|
|
|
size_t lng = (size_t)offset;
|
2004-06-11 09:14:23 -04:00
|
|
|
|
2002-12-04 09:11:26 -05:00
|
|
|
snum.Printf(_T("%i"), num);
|
2004-09-28 20:20:27 -04:00
|
|
|
output = _T(" xml_res_file_") + snum + _T(" = '''\\\n");
|
2004-06-11 09:14:23 -04:00
|
|
|
|
2002-08-14 07:02:39 -04:00
|
|
|
unsigned char *buffer = new unsigned char[lng];
|
|
|
|
file.Read(buffer, lng);
|
2004-06-11 09:14:23 -04:00
|
|
|
|
2002-08-14 07:02:39 -04:00
|
|
|
for (size_t i = 0, linelng = 0; i < lng; i++)
|
|
|
|
{
|
|
|
|
unsigned char c = buffer[i];
|
|
|
|
if (c == '\n')
|
|
|
|
{
|
|
|
|
tmp = (wxChar)c;
|
|
|
|
linelng = 0;
|
|
|
|
}
|
2004-09-28 20:20:27 -04:00
|
|
|
else if (c < 32 || c > 127 || c == '\'')
|
2002-12-04 09:11:26 -05:00
|
|
|
tmp.Printf(_T("\\x%02x"), c);
|
2002-08-14 07:02:39 -04:00
|
|
|
else if (c == '\\')
|
2002-12-04 09:11:26 -05:00
|
|
|
tmp = _T("\\\\");
|
2002-08-14 07:02:39 -04:00
|
|
|
else
|
|
|
|
tmp = (wxChar)c;
|
|
|
|
if (linelng > 70)
|
|
|
|
{
|
|
|
|
linelng = 0;
|
2002-12-04 09:11:26 -05:00
|
|
|
output << _T("\\\n");
|
2002-08-14 07:02:39 -04:00
|
|
|
}
|
|
|
|
output << tmp;
|
|
|
|
linelng += tmp.Length();
|
|
|
|
}
|
2004-06-11 09:14:23 -04:00
|
|
|
|
2002-08-14 07:02:39 -04:00
|
|
|
delete[] buffer;
|
2004-06-11 09:14:23 -04:00
|
|
|
|
2004-09-28 20:20:27 -04:00
|
|
|
output += _T("'''\n\n");
|
2004-06-11 09:14:23 -04:00
|
|
|
|
2002-08-14 07:02:39 -04:00
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void XmlResApp::MakePackagePython(const wxArrayString& flist)
|
|
|
|
{
|
2003-03-16 15:27:15 -05:00
|
|
|
wxFFile file(parOutput, wxT("wt"));
|
2002-08-14 07:02:39 -04:00
|
|
|
size_t i;
|
|
|
|
|
2004-06-11 09:14:23 -04:00
|
|
|
if (flagVerbose)
|
2002-12-04 09:11:26 -05:00
|
|
|
wxPrintf(_T("creating Python source file ") + parOutput + _T("...\n"));
|
2004-06-11 09:14:23 -04:00
|
|
|
|
2002-08-14 07:02:39 -04:00
|
|
|
file.Write(
|
2002-12-04 09:11:26 -05:00
|
|
|
_T("#\n")
|
|
|
|
_T("# This file was automatically generated by wxrc, do not edit by hand.\n")
|
|
|
|
_T("#\n\n")
|
2004-09-28 20:15:21 -04:00
|
|
|
_T("import wx\n")
|
|
|
|
_T("import wx.xrc\n\n")
|
2002-08-14 07:02:39 -04:00
|
|
|
);
|
|
|
|
|
2004-06-11 09:14:23 -04:00
|
|
|
|
2002-12-04 09:11:26 -05:00
|
|
|
file.Write(_T("def ") + parFuncname + _T("():\n"));
|
2002-08-14 07:02:39 -04:00
|
|
|
|
|
|
|
for (i = 0; i < flist.Count(); i++)
|
2002-12-25 10:23:44 -05:00
|
|
|
file.Write(
|
|
|
|
FileToPythonArray(parOutputPath + wxFILE_SEP_PATH + flist[i], i));
|
2002-08-14 07:02:39 -04:00
|
|
|
|
2005-01-13 14:57:24 -05:00
|
|
|
file.Write(
|
2004-09-28 20:15:21 -04:00
|
|
|
_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")
|
|
|
|
);
|
|
|
|
|
2005-01-13 14:57:24 -05:00
|
|
|
|
2002-08-14 07:02:39 -04:00
|
|
|
for (i = 0; i < flist.Count(); i++)
|
|
|
|
{
|
|
|
|
wxString s;
|
2004-09-28 20:15:21 -04:00
|
|
|
s.Printf(_T(" wx.MemoryFSHandler.AddFile('XRC_resource/") + flist[i] +
|
|
|
|
_T("', xml_res_file_%i)\n"), i);
|
2002-08-14 07:02:39 -04:00
|
|
|
file.Write(s);
|
|
|
|
}
|
2004-09-28 20:15:21 -04:00
|
|
|
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"));
|
2002-08-14 07:02:39 -04:00
|
|
|
}
|
|
|
|
|
2000-11-24 12:20:20 -05:00
|
|
|
|
|
|
|
|
|
|
|
void XmlResApp::OutputGettext()
|
|
|
|
{
|
|
|
|
wxArrayString str = FindStrings();
|
2004-06-11 09:14:23 -04:00
|
|
|
|
2000-11-24 12:20:20 -05:00
|
|
|
wxFFile fout;
|
2004-02-05 16:58:29 -05:00
|
|
|
if (parOutput.empty())
|
|
|
|
fout.Attach(stdout);
|
|
|
|
else
|
|
|
|
fout.Open(parOutput, wxT("wt"));
|
2004-06-11 09:14:23 -04:00
|
|
|
|
2000-11-24 12:20:20 -05:00
|
|
|
for (size_t i = 0; i < str.GetCount(); i++)
|
2002-08-31 11:37:20 -04:00
|
|
|
fout.Write(_T("_(\"") + str[i] + _T("\");\n"));
|
2004-06-11 09:14:23 -04:00
|
|
|
|
2000-11-24 12:20:20 -05:00
|
|
|
if (!parOutput) fout.Detach();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wxArrayString XmlResApp::FindStrings()
|
|
|
|
{
|
|
|
|
wxArrayString arr, a2;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < parFiles.Count(); i++)
|
|
|
|
{
|
2004-06-11 09:14:23 -04:00
|
|
|
if (flagVerbose)
|
2002-12-04 09:11:26 -05:00
|
|
|
wxPrintf(_T("processing ") + parFiles[i] + _T("...\n"));
|
2000-11-24 12:20:20 -05:00
|
|
|
|
2004-06-11 09:14:23 -04:00
|
|
|
wxXmlDocument doc;
|
2000-11-24 12:20:20 -05:00
|
|
|
if (!doc.Load(parFiles[i]))
|
|
|
|
{
|
2002-12-04 09:11:26 -05:00
|
|
|
wxLogError(_T("Error parsing file ") + parFiles[i]);
|
2000-11-24 12:20:20 -05:00
|
|
|
retCode = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
a2 = FindStrings(doc.GetRoot());
|
|
|
|
WX_APPEND_ARRAY(arr, a2);
|
|
|
|
}
|
2004-06-11 09:14:23 -04:00
|
|
|
|
2000-11-24 12:20:20 -05:00
|
|
|
return arr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-03-09 11:35:00 -05:00
|
|
|
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;
|
|
|
|
}
|
2004-06-11 09:14:23 -04:00
|
|
|
else
|
2002-03-09 11:35:00 -05:00
|
|
|
{
|
|
|
|
switch (*dt)
|
|
|
|
{
|
|
|
|
case wxT('\n') : str2 << wxT("\\n"); break;
|
|
|
|
case wxT('\t') : str2 << wxT("\\t"); break;
|
|
|
|
case wxT('\r') : str2 << wxT("\\r"); break;
|
2002-12-04 09:11:26 -05:00
|
|
|
case wxT('\\') : if ((*(dt+1) != 'n') &&
|
|
|
|
(*(dt+1) != 't') &&
|
|
|
|
(*(dt+1) != 'r'))
|
|
|
|
str2 << wxT("\\\\");
|
|
|
|
else
|
2004-06-11 09:14:23 -04:00
|
|
|
str2 << wxT("\\");
|
2002-12-04 09:11:26 -05:00
|
|
|
break;
|
2002-08-23 14:52:31 -04:00
|
|
|
case wxT('"') : str2 << wxT("\\\""); break;
|
2002-03-09 11:35:00 -05:00
|
|
|
default : str2 << *dt; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return str2;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-24 12:20:20 -05:00
|
|
|
wxArrayString XmlResApp::FindStrings(wxXmlNode *node)
|
|
|
|
{
|
|
|
|
wxArrayString arr;
|
|
|
|
|
|
|
|
wxXmlNode *n = node;
|
|
|
|
if (n == NULL) return arr;
|
|
|
|
n = n->GetChildren();
|
2004-06-11 09:14:23 -04:00
|
|
|
|
2000-11-24 12:20:20 -05:00
|
|
|
while (n)
|
|
|
|
{
|
|
|
|
if ((node->GetType() == wxXML_ELEMENT_NODE) &&
|
|
|
|
// parent is an element, i.e. has subnodes...
|
2004-06-11 09:14:23 -04:00
|
|
|
(n->GetType() == wxXML_TEXT_NODE ||
|
2000-11-24 12:20:20 -05:00
|
|
|
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") ||
|
2002-08-31 11:37:20 -04:00
|
|
|
node/*not n!*/->GetName() == _T("title") ||
|
|
|
|
node/*not n!*/->GetName() == _T("item")
|
2000-11-24 12:20:20 -05:00
|
|
|
))
|
2002-03-09 11:35:00 -05:00
|
|
|
// ...and known to contain translatable string
|
2000-11-24 12:20:20 -05:00
|
|
|
{
|
2004-08-29 14:27:51 -04:00
|
|
|
if (!flagGettext ||
|
|
|
|
node->GetPropVal(_T("translate"), _T("1")) != _T("0"))
|
|
|
|
{
|
|
|
|
arr.Add(ConvertText(n->GetContent()));
|
|
|
|
}
|
2000-11-24 12:20:20 -05:00
|
|
|
}
|
2004-06-11 09:14:23 -04:00
|
|
|
|
2000-11-24 12:20:20 -05:00
|
|
|
// subnodes:
|
|
|
|
if (n->GetType() == wxXML_ELEMENT_NODE)
|
|
|
|
{
|
|
|
|
wxArrayString a2 = FindStrings(n);
|
|
|
|
WX_APPEND_ARRAY(arr, a2);
|
|
|
|
}
|
2004-06-11 09:14:23 -04:00
|
|
|
|
2000-11-24 12:20:20 -05:00
|
|
|
n = n->GetNext();
|
|
|
|
}
|
|
|
|
return arr;
|
|
|
|
}
|