]>
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" wxWidgets headers
28 #include "wx/deprecated/setup.h"
29 #include "wx/deprecated/resource.h"
36 IMPLEMENT_APP(wxConvertApp
)
37 //////////////////////////////////////////////////////////////////////
38 // Construction/Destruction
39 //////////////////////////////////////////////////////////////////////
41 wxConvertApp::wxConvertApp()
48 wxConvertApp::~wxConvertApp()
54 bool wxConvertApp::OnInit()
56 //Initialize all image loaders(JPEG,BMP,PNG,and etc)
57 wxInitAllImageHandlers();
58 SetAppName(_T("wxConvertApp"));
60 if (HandleCommandLine())
64 // Create the main frame window
65 m_pFrame
= new wxMainFrame(NULL
, -1, _T("wxConvertApp"), wxPoint(0, 0), wxSize(500, 400),
66 wxDEFAULT_FRAME_STYLE
| wxHSCROLL
| wxVSCROLL
);
70 SetTopWindow(m_pFrame
);
74 void wxConvertApp::InitMenu()
76 m_pMenuBar
=new wxMenuBar
;
79 wxMenu
*filemenu
=new wxMenu
;
80 filemenu
->Append(ID_RC2WXR
,_T("Convert RC file to WXR file"));
81 filemenu
->Append(ID_WXR2XML
,_T("Convert WXR file to XML file"));
82 filemenu
->Append(ID_RC2XML
,_T("Convert RC file to XML file"));
84 filemenu
->Append(ID_QUIT
, _T("E&xit"));
85 m_pMenuBar
->Append(filemenu
,_T("&File"));
87 m_pFrame
->SetMenuBar(m_pMenuBar
);
92 // MainFrame.cpp: implementation of the wxMainFrame class.
94 //////////////////////////////////////////////////////////////////////
96 BEGIN_EVENT_TABLE(wxMainFrame
, wxFrame
)
97 EVT_MENU(ID_QUIT
,wxMainFrame::OnQuit
)
98 EVT_MENU(ID_RC2WXR
,wxMainFrame::OnRc2Wxr
)
99 EVT_MENU(ID_WXR2XML
,wxMainFrame::OnWXR2XML
)
100 EVT_MENU(ID_RC2XML
,wxMainFrame::OnRC2XML
)
105 //////////////////////////////////////////////////////////////////////
106 // Construction/Destruction
107 //////////////////////////////////////////////////////////////////////
109 wxMainFrame::wxMainFrame(wxWindow
* parent
,wxWindowID id
,
110 const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
,
111 long style
, const wxString
& name
)
112 :wxFrame(parent
,id
,title
,pos
,size
,style
,name
)
117 wxMainFrame::~wxMainFrame()
123 void wxMainFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
129 void wxMainFrame::OnRc2Wxr(wxCommandEvent
& WXUNUSED(event
))
131 wxFileDialog
filed(this);
132 filed
.SetWildcard(_T("*.rc"));
133 filed
.SetStyle(wxOPEN
);
135 if (filed
.ShowModal()!=wxID_OK
)
138 wxFileDialog
wxrfile(this,_T("Enter Desired WXR file name"));
139 wxrfile
.SetWildcard(_T("*.wxr"));
140 wxrfile
.SetStyle(wxOPEN
);
141 wxrfile
.SetFilename(_T("resource.wxr"));
143 if (wxrfile
.ShowModal()!=wxID_OK
)
147 convert
.Convert(wxrfile
.GetPath(),filed
.GetPath());
150 void wxMainFrame::OnWXR2XML(wxCommandEvent
& WXUNUSED(event
))
152 wxFileDialog
f(this);
153 f
.SetWildcard(_T("*.wxr"));
154 if (f
.ShowModal()!=wxID_OK
)
158 wxFileDialog
xmlfile(this,_T("Enter Desired XML file name"));
159 xmlfile
.SetWildcard(_T("*.xml"));
160 xmlfile
.SetStyle(wxOPEN
);
161 xmlfile
.SetFilename(_T("resource.xml"));
163 if (xmlfile
.ShowModal()!=wxID_OK
)
167 XMLCon
.Convert(f
.GetPath(),xmlfile
.GetPath());
171 void wxMainFrame::OnRC2XML(wxCommandEvent
& WXUNUSED(event
))
173 wxFileDialog
f(this);
174 f
.SetWildcard(_T("*.rc"));
175 if (f
.ShowModal()!=wxID_OK
)
178 wxFileDialog
xmlfile(this,_T("Enter Desired XML file name"));
179 xmlfile
.SetWildcard(_T("*.xml"));
180 xmlfile
.SetStyle(wxOPEN
);
181 xmlfile
.SetFilename(_T("resource.xml"));
183 if (xmlfile
.ShowModal()!=wxID_OK
)
187 XMLCon
.Convert(f
.GetPath(),xmlfile
.GetPath());
191 bool wxConvertApp::HandleCommandLine()
197 //Figure out kind of conversion
198 wxString source
,target
;
200 wxr2xml trans_wxr2xml
;
208 if ((source
.Find(_T(".wxr"))>0)&&(target
.Find(_T(".xml"))>0))
210 trans_wxr2xml
.Convert(source
,target
);
213 else if ((source
.Find(_T(".rc"))!=-1)&(target
.Find(_T(".wxr"))!=-1))
215 trans_rc2wxr
.Convert(source
,target
);
218 else if ((source
.Find(_T(".rc"))!=-1)&(target
.Find(_T(".xml"))!=-1))
220 trans_rc2xml
.Convert(source
,target
);