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