]>
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.h"
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
19 // for all others, include the necessary headers (this file is usually all you
20 // need because it includes almost all "standard" wxWidgets headers
27 #include "wx/deprecated/setup.h"
28 #include "wx/deprecated/resource.h"
35 IMPLEMENT_APP(wxConvertApp
)
36 //////////////////////////////////////////////////////////////////////
37 // Construction/Destruction
38 //////////////////////////////////////////////////////////////////////
40 wxConvertApp::wxConvertApp()
47 wxConvertApp::~wxConvertApp()
53 bool wxConvertApp::OnInit()
55 //Initialize all image loaders(JPEG,BMP,PNG,and etc)
56 wxInitAllImageHandlers();
57 SetAppName(_T("wxConvertApp"));
59 if (HandleCommandLine())
63 // Create the main frame window
64 m_pFrame
= new wxMainFrame(NULL
, wxID_ANY
, _T("wxConvertApp"), wxPoint(0, 0), wxSize(500, 400),
65 wxDEFAULT_FRAME_STYLE
| wxHSCROLL
| wxVSCROLL
);
69 SetTopWindow(m_pFrame
);
73 void wxConvertApp::InitMenu()
75 m_pMenuBar
=new wxMenuBar
;
78 wxMenu
*filemenu
=new wxMenu
;
79 filemenu
->Append(ID_RC2WXR
,_T("Convert RC file to WXR file"));
80 filemenu
->Append(ID_WXR2XML
,_T("Convert WXR file to XML file"));
81 filemenu
->Append(ID_RC2XML
,_T("Convert RC file to XML file"));
83 filemenu
->Append(ID_QUIT
, _T("E&xit"));
84 m_pMenuBar
->Append(filemenu
,_T("&File"));
86 m_pFrame
->SetMenuBar(m_pMenuBar
);
91 // MainFrame.cpp: implementation of the wxMainFrame class.
93 //////////////////////////////////////////////////////////////////////
95 BEGIN_EVENT_TABLE(wxMainFrame
, wxFrame
)
96 EVT_MENU(ID_QUIT
,wxMainFrame::OnQuit
)
97 EVT_MENU(ID_RC2WXR
,wxMainFrame::OnRc2Wxr
)
98 EVT_MENU(ID_WXR2XML
,wxMainFrame::OnWXR2XML
)
99 EVT_MENU(ID_RC2XML
,wxMainFrame::OnRC2XML
)
104 //////////////////////////////////////////////////////////////////////
105 // Construction/Destruction
106 //////////////////////////////////////////////////////////////////////
108 wxMainFrame::wxMainFrame(wxWindow
* parent
,wxWindowID id
,
109 const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
,
110 long style
, const wxString
& name
)
111 :wxFrame(parent
,id
,title
,pos
,size
,style
,name
)
116 wxMainFrame::~wxMainFrame()
122 void wxMainFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
128 void wxMainFrame::OnRc2Wxr(wxCommandEvent
& WXUNUSED(event
))
130 wxFileDialog
filed(this);
131 filed
.SetWildcard(_T("*.rc"));
132 filed
.SetStyle(wxOPEN
);
134 if (filed
.ShowModal()!=wxID_OK
)
137 wxFileDialog
wxrfile(this,_T("Enter Desired WXR file name"));
138 wxrfile
.SetWildcard(_T("*.wxr"));
139 wxrfile
.SetStyle(wxOPEN
);
140 wxrfile
.SetFilename(_T("resource.wxr"));
142 if (wxrfile
.ShowModal()!=wxID_OK
)
146 convert
.Convert(wxrfile
.GetPath(),filed
.GetPath());
149 void wxMainFrame::OnWXR2XML(wxCommandEvent
& WXUNUSED(event
))
151 wxFileDialog
f(this);
152 f
.SetWildcard(_T("*.wxr"));
153 if (f
.ShowModal()!=wxID_OK
)
157 wxFileDialog
xmlfile(this,_T("Enter Desired XML file name"));
158 xmlfile
.SetWildcard(_T("*.xml"));
159 xmlfile
.SetStyle(wxOPEN
);
160 xmlfile
.SetFilename(_T("resource.xml"));
162 if (xmlfile
.ShowModal()!=wxID_OK
)
166 XMLCon
.Convert(f
.GetPath(),xmlfile
.GetPath());
170 void wxMainFrame::OnRC2XML(wxCommandEvent
& WXUNUSED(event
))
172 wxFileDialog
f(this);
173 f
.SetWildcard(_T("*.rc"));
174 if (f
.ShowModal()!=wxID_OK
)
177 wxFileDialog
xmlfile(this,_T("Enter Desired XML file name"));
178 xmlfile
.SetWildcard(_T("*.xml"));
179 xmlfile
.SetStyle(wxOPEN
);
180 xmlfile
.SetFilename(_T("resource.xml"));
182 if (xmlfile
.ShowModal()!=wxID_OK
)
186 XMLCon
.Convert(f
.GetPath(),xmlfile
.GetPath());
190 bool wxConvertApp::HandleCommandLine()
196 //Figure out kind of conversion
197 wxString source
,target
;
199 wxr2xml trans_wxr2xml
;
207 if ((source
.Find(_T(".wxr"))>0)&&(target
.Find(_T(".xml"))>0))
209 trans_wxr2xml
.Convert(source
,target
);
212 else if ((source
.Find(_T(".rc"))!=wxNOT_FOUND
)&(target
.Find(_T(".wxr"))!=wxNOT_FOUND
))
214 trans_rc2wxr
.Convert(source
,target
);
217 else if ((source
.Find(_T(".rc"))!=wxNOT_FOUND
)&(target
.Find(_T(".xml"))!=wxNOT_FOUND
))
219 trans_rc2xml
.Convert(source
,target
);