// wxr2xml.cpp: implementation of the wxWxr2Xml class.
// 8/30/00 Brian Gavin
// only tested on wxMSW so far
//////////////////////////////////////////////////////////////////////
/* TODO
port to wxGTK should be very easy
support fonts
add unsupported controls when XML format adds them
*/
#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
//////////////////////////////////////////////////////////////////////
wxWxr2Xml::wxWxr2Xml()
{
}
wxWxr2Xml::~wxWxr2Xml()
{
}
bool wxWxr2Xml::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 wxWxr2Xml::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 wxWxr2Xml::ParsePanel(wxItemResource *res)
{
m_xmlfile.Write(" \n");
ParseControls(res);
m_xmlfile.Write(" \n");
m_xmlfile.Write(" \n");
}
void wxWxr2Xml::ParseDialog(wxItemResource *res)
{
PanelStuff(res);
m_xmlfile.Write(" \n");
}
void wxWxr2Xml::ParseControls(wxItemResource *res)
{
wxNode *node = res->GetChildren().First();
while (node)
{
wxItemResource *res = (wxItemResource *)node->Data();
wxString resType(res->GetType());
if (resType=="wxButton")
ParseButton(res);
else if ((resType=="wxTextCtrl")|(resType=="wxText")
|(resType=="wxMultiText"))
ParseTextCtrl(res);
else if (resType=="wxCheckBox")
ParseCheckBox(res);
else if (resType=="wxRadioBox")
ParseRadioBox(res);
else if (resType=="wxListBox")
ParseListBox(res);
else if ((resType=="wxStaticText")|(resType=="wxMessage"))
ParseStaticText(res);
else if (resType=="wxChoice")
ParseChoice(res);
else if (resType=="wxGauge")
ParseGauge(res);
else if (resType=="wxSlider")
ParseSlider(res);
else if (resType=="wxComboBox")
ParseComboBox(res);
else if (resType=="wxRadioButton")
ParseRadioButton(res);
else if (resType=="wxStaticBitmap")
ParseStaticBitmap(res);
else if (resType=="wxScrollBar")
wxLogError("wxScrollBar unsupported");
else if ((resType=="wxStaticBox")|(resType=="wxGroupBox"))
wxLogError("wxStaticBox unsupported");
else if (resType=="wxBitmapButton")
wxLogError("wxBitmapButton unsupported");
else
wxLogError("Found unsupported resource "+resType);
node = node->Next();
}
}
//Write out basic stuff every control has
// name,position,size,bg,fg
void wxWxr2Xml::WriteControlInfo(wxItemResource *res)
{
m_xmlfile.Write(GenerateName(res));
m_xmlfile.Write(">\n");
m_xmlfile.Write(GetPosition(res));
m_xmlfile.Write(GetSize(res));
m_xmlfile.Write(GetStyles(res));
}
wxString wxWxr2Xml::GetSize(wxItemResource *res)
{
wxString msg;
if (m_dlgunits)
msg<<" "<GetWidth()<<","<GetHeight()<<"d";
else
msg<<" "<GetWidth()<<","<GetHeight()<<"";
return msg;
}
wxString wxWxr2Xml::GetPosition(wxItemResource *res)
{
wxString msg;
if (m_dlgunits)
msg<<" "<GetX()<<","<GetY()<<"d";
else
msg<<" "<GetX()<<","<GetY()<<"";
return msg;
}
void wxWxr2Xml::ParseButton(wxItemResource *res)
{
m_xmlfile.Write("