// wxr2xml.cpp: implementation of the wxr2xml class.
// 8/30/00 Brian Gavin
// only tested on wxMSW so far
//License: wxWindows Liscense
// ////////////////////////////////////////////////////////////////////
/*
How to use class:
#include "wxr2xml.h"
...
wxr2xml trans;
trans->Convert("Myfile.wxr","Myfile.xml");
*/
#ifdef __GNUG__
#pragma implementation "wxr2xml.h"
#endif
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include "wxr2xml.h"
// ////////////////////////////////////////////////////////////////////
// Construction/Destruction
// ////////////////////////////////////////////////////////////////////
wxr2xml::wxr2xml()
{
}
wxr2xml::~wxr2xml()
{
}
bool wxr2xml::Convert(wxString wxrfile, wxString xmlfile)
{
bool result;
result = m_xmlfile.Open(xmlfile.c_str(), _T("w+t"));
wxASSERT_MSG(result, _T("Couldn't create XML file"));
if (!result)
return false;
result = m_table.ParseResourceFile(wxrfile);
wxASSERT_MSG(result, _T("Couldn't Load WXR file"));
if (!result)
return false;
// Write basic xml header
m_xmlfile.Write(_T("\n"));
m_xmlfile.Write(_T("\n"));
result = ParseResources();
m_xmlfile.Write(_T("\n"));
m_xmlfile.Close();
return result;
}
bool wxr2xml::ParseResources()
{
m_table.BeginFind();
wxHashTable::Node *node;
node = m_table.Next();
while (node)
{
wxItemResource *res = (wxItemResource *) node->GetData();
wxString resType(res->GetType());
if (resType == _T("wxDialog"))
ParseDialog(res);
else if (resType == _T("wxPanel"))
ParsePanel(res);
else if (resType == _T("wxPanel"))
ParsePanel(res);
else if (resType == _T("wxMenu"))
ParseMenuBar(res);
else if (resType == _T("wxBitmap"))
ParseBitmap(res);
else
wxLogError(_T("Found unsupported resource ") + resType);
node = m_table.Next();
}
return true;
}
void wxr2xml::ParsePanel(wxItemResource * res)
{
m_xmlfile.Write(_T("\t