]> git.saurik.com Git - wxWidgets.git/blame - contrib/utils/convertrc/convert.cpp
offset version by 1 to avoid having compatibility_version of 0.0.0 under Darwin:...
[wxWidgets.git] / contrib / utils / convertrc / convert.cpp
CommitLineData
2193517f
VS
1//wxConvertApp Programming Utility
2/*This program currently offers 3 useful conversions
31. Converts most of an .RC file into a wxXml file
42. Converts most of an .wxr file into a wxXml file
53. Converts portions of an .RC file into a wxr file
6*/
7
2193517f 8// For compilers that support precompilation, includes "wx/wx.h".
92a19c2e 9#include "wx/wxprec.h"
2193517f
VS
10
11#ifdef __BORLANDC__
12#pragma hdrstop
13#endif
14
15// for all others, include the necessary headers (this file is usually all you
be5a51fb 16// need because it includes almost all "standard" wxWidgets headers
2193517f 17#ifndef WX_PRECOMP
94dadb0a 18#include "wx/wx.h"
2193517f
VS
19#endif
20
94dadb0a 21#include "wx/image.h"
7c9955d1
JS
22
23#include "wx/deprecated/setup.h"
24#include "wx/deprecated/resource.h"
2193517f
VS
25
26#include "convert.h"
27#include "rc2wxr.h"
28#include "wxr2xml.h"
29#include "rc2xml.h"
30
31IMPLEMENT_APP(wxConvertApp)
32//////////////////////////////////////////////////////////////////////
33// Construction/Destruction
34//////////////////////////////////////////////////////////////////////
35
36wxConvertApp::wxConvertApp()
37{
38 m_pFrame=NULL;
39 m_pMenuBar=NULL;
40
41}
42
43wxConvertApp::~wxConvertApp()
44{
45
46}
47
48
49bool wxConvertApp::OnInit()
50{
51//Initialize all image loaders(JPEG,BMP,PNG,and etc)
52 wxInitAllImageHandlers();
19d0f58d 53 SetAppName(_T("wxConvertApp"));
2193517f
VS
54
55 if (HandleCommandLine())
f80ea77b 56 return true;
2193517f
VS
57
58
59// Create the main frame window
f80ea77b 60 m_pFrame = new wxMainFrame(NULL, wxID_ANY, _T("wxConvertApp"), wxPoint(0, 0), wxSize(500, 400),
2193517f 61 wxDEFAULT_FRAME_STYLE | wxHSCROLL | wxVSCROLL);
7c9955d1 62
2193517f 63 InitMenu();
f80ea77b 64 m_pFrame->Show(true);
2193517f 65 SetTopWindow(m_pFrame);
f80ea77b 66 return true;
2193517f
VS
67}
68
69void wxConvertApp::InitMenu()
70{
71 m_pMenuBar=new wxMenuBar;
72 wxASSERT(m_pMenuBar);
73
74 wxMenu *filemenu=new wxMenu;
19d0f58d
JS
75 filemenu->Append(ID_RC2WXR,_T("Convert RC file to WXR file"));
76 filemenu->Append(ID_WXR2XML,_T("Convert WXR file to XML file"));
77 filemenu->Append(ID_RC2XML,_T("Convert RC file to XML file"));
2193517f 78
19d0f58d
JS
79 filemenu->Append(ID_QUIT, _T("E&xit"));
80 m_pMenuBar->Append(filemenu,_T("&File"));
2193517f
VS
81
82 m_pFrame->SetMenuBar(m_pMenuBar);
83}
84
85
86
87// MainFrame.cpp: implementation of the wxMainFrame class.
88//
89//////////////////////////////////////////////////////////////////////
90
91BEGIN_EVENT_TABLE(wxMainFrame, wxFrame)
92 EVT_MENU(ID_QUIT,wxMainFrame::OnQuit)
93 EVT_MENU(ID_RC2WXR,wxMainFrame::OnRc2Wxr)
94 EVT_MENU(ID_WXR2XML,wxMainFrame::OnWXR2XML)
95 EVT_MENU(ID_RC2XML,wxMainFrame::OnRC2XML)
96END_EVENT_TABLE()
97
98
99
100//////////////////////////////////////////////////////////////////////
101// Construction/Destruction
102//////////////////////////////////////////////////////////////////////
103
7c9955d1 104wxMainFrame::wxMainFrame(wxWindow* parent,wxWindowID id,
2193517f
VS
105const wxString& title, const wxPoint& pos, const wxSize& size,
106long style, const wxString& name)
107:wxFrame(parent,id,title,pos,size,style,name)
108{
7c9955d1 109
2193517f
VS
110}
111
112wxMainFrame::~wxMainFrame()
113{
114}
115
116
117
19d0f58d 118void wxMainFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
2193517f 119{
f80ea77b 120 Close(true);
2193517f
VS
121}
122
123
19d0f58d 124void wxMainFrame::OnRc2Wxr(wxCommandEvent& WXUNUSED(event))
2193517f 125{
c54e5eb0 126#if wxUSE_FILEDLG
2193517f 127 wxFileDialog filed(this);
19d0f58d 128 filed.SetWildcard(_T("*.rc"));
2193517f
VS
129 filed.SetStyle(wxOPEN);
130
131 if (filed.ShowModal()!=wxID_OK)
132 return;
133
19d0f58d
JS
134 wxFileDialog wxrfile(this,_T("Enter Desired WXR file name"));
135 wxrfile.SetWildcard(_T("*.wxr"));
2193517f 136 wxrfile.SetStyle(wxOPEN);
19d0f58d 137 wxrfile.SetFilename(_T("resource.wxr"));
2193517f
VS
138
139 if (wxrfile.ShowModal()!=wxID_OK)
140 return;
141
142 rc2wxr convert;
143 convert.Convert(wxrfile.GetPath(),filed.GetPath());
c54e5eb0 144#endif // wxUSE_FILEDLG
2193517f
VS
145}
146
19d0f58d 147void wxMainFrame::OnWXR2XML(wxCommandEvent& WXUNUSED(event))
2193517f 148{
c54e5eb0 149#if wxUSE_FILEDLG
2193517f 150 wxFileDialog f(this);
19d0f58d 151 f.SetWildcard(_T("*.wxr"));
2193517f
VS
152 if (f.ShowModal()!=wxID_OK)
153 return;
154
155
19d0f58d
JS
156 wxFileDialog xmlfile(this,_T("Enter Desired XML file name"));
157 xmlfile.SetWildcard(_T("*.xml"));
2193517f 158 xmlfile.SetStyle(wxOPEN);
19d0f58d 159 xmlfile.SetFilename(_T("resource.xml"));
2193517f
VS
160
161 if (xmlfile.ShowModal()!=wxID_OK)
162 return;
163
164 wxr2xml XMLCon;
165 XMLCon.Convert(f.GetPath(),xmlfile.GetPath());
c54e5eb0 166#endif // wxUSE_FILEDLG
2193517f
VS
167}
168
19d0f58d 169void wxMainFrame::OnRC2XML(wxCommandEvent& WXUNUSED(event))
2193517f 170{
c54e5eb0 171#if wxUSE_FILEDLG
2193517f 172 wxFileDialog f(this);
19d0f58d 173 f.SetWildcard(_T("*.rc"));
2193517f
VS
174 if (f.ShowModal()!=wxID_OK)
175 return;
176
19d0f58d
JS
177 wxFileDialog xmlfile(this,_T("Enter Desired XML file name"));
178 xmlfile.SetWildcard(_T("*.xml"));
2193517f 179 xmlfile.SetStyle(wxOPEN);
19d0f58d 180 xmlfile.SetFilename(_T("resource.xml"));
2193517f
VS
181
182 if (xmlfile.ShowModal()!=wxID_OK)
183 return;
184
185 rc2xml XMLCon;
186 XMLCon.Convert(f.GetPath(),xmlfile.GetPath());
c54e5eb0 187#endif // wxUSE_FILEDLG
2193517f
VS
188}
189
190bool wxConvertApp::HandleCommandLine()
191{
192
7c9955d1 193 if (argc != 2)
f80ea77b 194 return false;
2193517f
VS
195
196//Figure out kind of conversion
197 wxString source,target;
7c9955d1 198
2193517f
VS
199 wxr2xml trans_wxr2xml;
200 rc2xml trans_rc2xml;
201 rc2wxr trans_rc2wxr;
202
203 source=argv[1];
204 target=argv[2];
7c9955d1 205
2193517f 206
19d0f58d 207 if ((source.Find(_T(".wxr"))>0)&&(target.Find(_T(".xml"))>0))
2193517f
VS
208 {
209 trans_wxr2xml.Convert(source,target);
f80ea77b 210 return true;
2193517f 211 }
f80ea77b 212 else if ((source.Find(_T(".rc"))!=wxNOT_FOUND)&(target.Find(_T(".wxr"))!=wxNOT_FOUND))
2193517f
VS
213 {
214 trans_rc2wxr.Convert(source,target);
f80ea77b 215 return true;
2193517f 216 }
f80ea77b 217 else if ((source.Find(_T(".rc"))!=wxNOT_FOUND)&(target.Find(_T(".xml"))!=wxNOT_FOUND))
2193517f
VS
218 {
219 trans_rc2xml.Convert(source,target);
f80ea77b 220 return true;
2193517f 221 }
7c9955d1 222
f80ea77b 223 return false;
2193517f 224}