// 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(), "w+t");
    wxASSERT_MSG(result, "Couldn't create XML file");
    if (!result)
        return FALSE;
    result = m_table.ParseResourceFile(wxrfile);
    wxASSERT_MSG(result, "Couldn't Load WXR file");
    if (!result)
        return FALSE;
    // Write basic xml header
    m_xmlfile.Write("\n");
    m_xmlfile.Write("\n");
    result = ParseResources();
    m_xmlfile.Write("\n");
    m_xmlfile.Close();
    return result;
}
bool wxr2xml::ParseResources()
{
    m_table.BeginFind();
    wxNode *node;
    while ((node = m_table.Next())) 
        {
        wxItemResource *res = (wxItemResource *) node->Data();
        wxString resType(res->GetType());
        if (resType == "wxDialog")
            ParseDialog(res);
        else if (resType == "wxPanel")
            ParsePanel(res);
        else if (resType == "wxPanel")
            ParsePanel(res);
        else if (resType == "wxMenu")
            ParseMenuBar(res);
        else if (resType == "wxBitmap")
            ParseBitmap(res);
        else
            wxLogError("Found unsupported resource " + resType);
    }
    return TRUE;
}
void wxr2xml::ParsePanel(wxItemResource * res)
{
    m_xmlfile.Write("\t