]> git.saurik.com Git - wxWidgets.git/blob - contrib/utils/convertrc/convert.cpp
More wxFileOffset usage and making layout of the code little more readable.
[wxWidgets.git] / 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
6 */
7
8 #ifdef __GNUG__
9 #pragma implementation "convert.cpp"
10 #pragma interface "convert.cpp"
11 #endif
12
13 // For compilers that support precompilation, includes "wx/wx.h".
14 #include "wx/wxprec.h"
15
16 #ifdef __BORLANDC__
17 #pragma hdrstop
18 #endif
19
20 // for all others, include the necessary headers (this file is usually all you
21 // need because it includes almost all "standard" wxWidgets headers
22 #ifndef WX_PRECOMP
23 #include <wx/wx.h>
24 #endif
25
26 #include <wx/image.h>
27
28 #include "wx/deprecated/setup.h"
29 #include "wx/deprecated/resource.h"
30
31 #include "convert.h"
32 #include "rc2wxr.h"
33 #include "wxr2xml.h"
34 #include "rc2xml.h"
35
36 IMPLEMENT_APP(wxConvertApp)
37 //////////////////////////////////////////////////////////////////////
38 // Construction/Destruction
39 //////////////////////////////////////////////////////////////////////
40
41 wxConvertApp::wxConvertApp()
42 {
43 m_pFrame=NULL;
44 m_pMenuBar=NULL;
45
46 }
47
48 wxConvertApp::~wxConvertApp()
49 {
50
51 }
52
53
54 bool wxConvertApp::OnInit()
55 {
56 //Initialize all image loaders(JPEG,BMP,PNG,and etc)
57 wxInitAllImageHandlers();
58 SetAppName(_T("wxConvertApp"));
59
60 if (HandleCommandLine())
61 return true;
62
63
64 // Create the main frame window
65 m_pFrame = new wxMainFrame(NULL, wxID_ANY, _T("wxConvertApp"), wxPoint(0, 0), wxSize(500, 400),
66 wxDEFAULT_FRAME_STYLE | wxHSCROLL | wxVSCROLL);
67
68 InitMenu();
69 m_pFrame->Show(true);
70 SetTopWindow(m_pFrame);
71 return true;
72 }
73
74 void wxConvertApp::InitMenu()
75 {
76 m_pMenuBar=new wxMenuBar;
77 wxASSERT(m_pMenuBar);
78
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"));
83
84 filemenu->Append(ID_QUIT, _T("E&xit"));
85 m_pMenuBar->Append(filemenu,_T("&File"));
86
87 m_pFrame->SetMenuBar(m_pMenuBar);
88 }
89
90
91
92 // MainFrame.cpp: implementation of the wxMainFrame class.
93 //
94 //////////////////////////////////////////////////////////////////////
95
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)
101 END_EVENT_TABLE()
102
103
104
105 //////////////////////////////////////////////////////////////////////
106 // Construction/Destruction
107 //////////////////////////////////////////////////////////////////////
108
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)
113 {
114
115 }
116
117 wxMainFrame::~wxMainFrame()
118 {
119 }
120
121
122
123 void wxMainFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
124 {
125 Close(true);
126 }
127
128
129 void wxMainFrame::OnRc2Wxr(wxCommandEvent& WXUNUSED(event))
130 {
131 wxFileDialog filed(this);
132 filed.SetWildcard(_T("*.rc"));
133 filed.SetStyle(wxOPEN);
134
135 if (filed.ShowModal()!=wxID_OK)
136 return;
137
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"));
142
143 if (wxrfile.ShowModal()!=wxID_OK)
144 return;
145
146 rc2wxr convert;
147 convert.Convert(wxrfile.GetPath(),filed.GetPath());
148 }
149
150 void wxMainFrame::OnWXR2XML(wxCommandEvent& WXUNUSED(event))
151 {
152 wxFileDialog f(this);
153 f.SetWildcard(_T("*.wxr"));
154 if (f.ShowModal()!=wxID_OK)
155 return;
156
157
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"));
162
163 if (xmlfile.ShowModal()!=wxID_OK)
164 return;
165
166 wxr2xml XMLCon;
167 XMLCon.Convert(f.GetPath(),xmlfile.GetPath());
168
169 }
170
171 void wxMainFrame::OnRC2XML(wxCommandEvent& WXUNUSED(event))
172 {
173 wxFileDialog f(this);
174 f.SetWildcard(_T("*.rc"));
175 if (f.ShowModal()!=wxID_OK)
176 return;
177
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"));
182
183 if (xmlfile.ShowModal()!=wxID_OK)
184 return;
185
186 rc2xml XMLCon;
187 XMLCon.Convert(f.GetPath(),xmlfile.GetPath());
188
189 }
190
191 bool wxConvertApp::HandleCommandLine()
192 {
193
194 if (argc != 2)
195 return false;
196
197 //Figure out kind of conversion
198 wxString source,target;
199
200 wxr2xml trans_wxr2xml;
201 rc2xml trans_rc2xml;
202 rc2wxr trans_rc2wxr;
203
204 source=argv[1];
205 target=argv[2];
206
207
208 if ((source.Find(_T(".wxr"))>0)&&(target.Find(_T(".xml"))>0))
209 {
210 trans_wxr2xml.Convert(source,target);
211 return true;
212 }
213 else if ((source.Find(_T(".rc"))!=wxNOT_FOUND)&(target.Find(_T(".wxr"))!=wxNOT_FOUND))
214 {
215 trans_rc2wxr.Convert(source,target);
216 return true;
217 }
218 else if ((source.Find(_T(".rc"))!=wxNOT_FOUND)&(target.Find(_T(".xml"))!=wxNOT_FOUND))
219 {
220 trans_rc2xml.Convert(source,target);
221 return true;
222 }
223
224 return false;
225 }