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