]>
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 | #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 | wxFileDialog filed(this); | |
131 | filed.SetWildcard(_T("*.rc")); | |
132 | filed.SetStyle(wxOPEN); | |
133 | ||
134 | if (filed.ShowModal()!=wxID_OK) | |
135 | return; | |
136 | ||
137 | wxFileDialog wxrfile(this,_T("Enter Desired WXR file name")); | |
138 | wxrfile.SetWildcard(_T("*.wxr")); | |
139 | wxrfile.SetStyle(wxOPEN); | |
140 | wxrfile.SetFilename(_T("resource.wxr")); | |
141 | ||
142 | if (wxrfile.ShowModal()!=wxID_OK) | |
143 | return; | |
144 | ||
145 | rc2wxr convert; | |
146 | convert.Convert(wxrfile.GetPath(),filed.GetPath()); | |
147 | } | |
148 | ||
149 | void wxMainFrame::OnWXR2XML(wxCommandEvent& WXUNUSED(event)) | |
150 | { | |
151 | wxFileDialog f(this); | |
152 | f.SetWildcard(_T("*.wxr")); | |
153 | if (f.ShowModal()!=wxID_OK) | |
154 | return; | |
155 | ||
156 | ||
157 | wxFileDialog xmlfile(this,_T("Enter Desired XML file name")); | |
158 | xmlfile.SetWildcard(_T("*.xml")); | |
159 | xmlfile.SetStyle(wxOPEN); | |
160 | xmlfile.SetFilename(_T("resource.xml")); | |
161 | ||
162 | if (xmlfile.ShowModal()!=wxID_OK) | |
163 | return; | |
164 | ||
165 | wxr2xml XMLCon; | |
166 | XMLCon.Convert(f.GetPath(),xmlfile.GetPath()); | |
167 | ||
168 | } | |
169 | ||
170 | void wxMainFrame::OnRC2XML(wxCommandEvent& WXUNUSED(event)) | |
171 | { | |
172 | wxFileDialog f(this); | |
173 | f.SetWildcard(_T("*.rc")); | |
174 | if (f.ShowModal()!=wxID_OK) | |
175 | return; | |
176 | ||
177 | wxFileDialog xmlfile(this,_T("Enter Desired XML file name")); | |
178 | xmlfile.SetWildcard(_T("*.xml")); | |
179 | xmlfile.SetStyle(wxOPEN); | |
180 | xmlfile.SetFilename(_T("resource.xml")); | |
181 | ||
182 | if (xmlfile.ShowModal()!=wxID_OK) | |
183 | return; | |
184 | ||
185 | rc2xml XMLCon; | |
186 | XMLCon.Convert(f.GetPath(),xmlfile.GetPath()); | |
187 | ||
188 | } | |
189 | ||
190 | bool wxConvertApp::HandleCommandLine() | |
191 | { | |
192 | ||
193 | if (argc != 2) | |
194 | return false; | |
195 | ||
196 | //Figure out kind of conversion | |
197 | wxString source,target; | |
198 | ||
199 | wxr2xml trans_wxr2xml; | |
200 | rc2xml trans_rc2xml; | |
201 | rc2wxr trans_rc2wxr; | |
202 | ||
203 | source=argv[1]; | |
204 | target=argv[2]; | |
205 | ||
206 | ||
207 | if ((source.Find(_T(".wxr"))>0)&&(target.Find(_T(".xml"))>0)) | |
208 | { | |
209 | trans_wxr2xml.Convert(source,target); | |
210 | return true; | |
211 | } | |
212 | else if ((source.Find(_T(".rc"))!=wxNOT_FOUND)&(target.Find(_T(".wxr"))!=wxNOT_FOUND)) | |
213 | { | |
214 | trans_rc2wxr.Convert(source,target); | |
215 | return true; | |
216 | } | |
217 | else if ((source.Find(_T(".rc"))!=wxNOT_FOUND)&(target.Find(_T(".xml"))!=wxNOT_FOUND)) | |
218 | { | |
219 | trans_rc2xml.Convert(source,target); | |
220 | return true; | |
221 | } | |
222 | ||
223 | return false; | |
224 | } |