]>
git.saurik.com Git - wxWidgets.git/blob - contrib/utils/convertrc/convert.cpp
1 //wxConvertApp Programming Utility
2 /*This program currently offers 3 useful conversions
3 1. Converts most of an .RC file into a wxXml file
4 2. Converts most of an .wxr file into a wxXml file
5 3. Converts portions of an .RC file into a wxr file
9 #pragma implementation "convert.cpp"
10 #pragma interface "convert.cpp"
13 // For compilers that support precompilation, includes "wx/wx.h".
14 #include "wx/wxprec.h"
20 // for all others, include the necessary headers (this file is usually all you
21 // need because it includes almost all "standard" wxWindows headers
27 #include "wx/resource.h"
34 IMPLEMENT_APP(wxConvertApp
)
35 //////////////////////////////////////////////////////////////////////
36 // Construction/Destruction
37 //////////////////////////////////////////////////////////////////////
39 wxConvertApp::wxConvertApp()
46 wxConvertApp::~wxConvertApp()
52 bool wxConvertApp::OnInit()
54 //Initialize all image loaders(JPEG,BMP,PNG,and etc)
55 wxInitAllImageHandlers();
56 SetAppName("wxConvertApp");
58 if (HandleCommandLine())
62 // Create the main frame window
63 m_pFrame
= new wxMainFrame(NULL
, -1, "wxConvertApp", wxPoint(0, 0), wxSize(500, 400),
64 wxDEFAULT_FRAME_STYLE
| wxHSCROLL
| wxVSCROLL
);
68 SetTopWindow(m_pFrame
);
72 void wxConvertApp::InitMenu()
74 m_pMenuBar
=new wxMenuBar
;
77 wxMenu
*filemenu
=new wxMenu
;
78 filemenu
->Append(ID_RC2WXR
,"Convert RC file to WXR file");
79 filemenu
->Append(ID_WXR2XML
,"Convert WXR file to XML file");
80 filemenu
->Append(ID_RC2XML
,"Convert RC file to XML file");
82 filemenu
->Append(ID_QUIT
, "E&xit");
83 m_pMenuBar
->Append(filemenu
,"&File");
85 m_pFrame
->SetMenuBar(m_pMenuBar
);
90 // MainFrame.cpp: implementation of the wxMainFrame class.
92 //////////////////////////////////////////////////////////////////////
94 BEGIN_EVENT_TABLE(wxMainFrame
, wxFrame
)
95 EVT_MENU(ID_QUIT
,wxMainFrame::OnQuit
)
96 EVT_MENU(ID_RC2WXR
,wxMainFrame::OnRc2Wxr
)
97 EVT_MENU(ID_WXR2XML
,wxMainFrame::OnWXR2XML
)
98 EVT_MENU(ID_RC2XML
,wxMainFrame::OnRC2XML
)
103 //////////////////////////////////////////////////////////////////////
104 // Construction/Destruction
105 //////////////////////////////////////////////////////////////////////
107 wxMainFrame::wxMainFrame(wxWindow
* parent
,wxWindowID id
,
108 const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
,
109 long style
, const wxString
& name
)
110 :wxFrame(parent
,id
,title
,pos
,size
,style
,name
)
115 wxMainFrame::~wxMainFrame()
121 void wxMainFrame::OnQuit()
127 void wxMainFrame::OnRc2Wxr()
129 wxFileDialog
filed(this);
130 filed
.SetWildcard("*.rc");
131 filed
.SetStyle(wxOPEN
);
133 if (filed
.ShowModal()!=wxID_OK
)
136 wxFileDialog
wxrfile(this,"Enter Desired WXR file name");
137 wxrfile
.SetWildcard("*.wxr");
138 wxrfile
.SetStyle(wxOPEN
);
139 wxrfile
.SetFilename("resource.wxr");
141 if (wxrfile
.ShowModal()!=wxID_OK
)
145 convert
.Convert(wxrfile
.GetPath(),filed
.GetPath());
148 void wxMainFrame::OnWXR2XML()
150 wxFileDialog
f(this);
151 f
.SetWildcard("*.wxr");
152 if (f
.ShowModal()!=wxID_OK
)
156 wxFileDialog
xmlfile(this,"Enter Desired XML file name");
157 xmlfile
.SetWildcard("*.xml");
158 xmlfile
.SetStyle(wxOPEN
);
159 xmlfile
.SetFilename("resource.xml");
161 if (xmlfile
.ShowModal()!=wxID_OK
)
165 XMLCon
.Convert(f
.GetPath(),xmlfile
.GetPath());
169 void wxMainFrame::OnRC2XML()
171 wxFileDialog
f(this);
172 f
.SetWildcard("*.rc");
173 if (f
.ShowModal()!=wxID_OK
)
176 wxFileDialog
xmlfile(this,"Enter Desired XML file name");
177 xmlfile
.SetWildcard("*.xml");
178 xmlfile
.SetStyle(wxOPEN
);
179 xmlfile
.SetFilename("resource.xml");
181 if (xmlfile
.ShowModal()!=wxID_OK
)
185 XMLCon
.Convert(f
.GetPath(),xmlfile
.GetPath());
189 bool wxConvertApp::HandleCommandLine()
195 //Figure out kind of conversion
196 wxString source
,target
;
197 wxr2xml trans_wxr2xml
;
205 if ((source
.Find(".wxr")>0)&&(target
.Find(".xml")>0))
207 trans_wxr2xml
.Convert(source
,target
);
210 else if ((source
.Find(".rc")!=-1)&(target
.Find(".wxr")!=-1))
212 trans_rc2wxr
.Convert(source
,target
);
215 else if ((source
.Find(".rc")!=-1)&(target
.Find(".xml")!=-1))
217 trans_rc2xml
.Convert(source
,target
);