]>
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); | |
128 | filed.SetWildcard(_T("*.rc")); | |
129 | filed.SetStyle(wxOPEN); | |
130 | ||
131 | if (filed.ShowModal()!=wxID_OK) | |
132 | return; | |
133 | ||
134 | wxFileDialog wxrfile(this,_T("Enter Desired WXR file name")); | |
135 | wxrfile.SetWildcard(_T("*.wxr")); | |
136 | wxrfile.SetStyle(wxOPEN); | |
137 | wxrfile.SetFilename(_T("resource.wxr")); | |
138 | ||
139 | if (wxrfile.ShowModal()!=wxID_OK) | |
140 | return; | |
141 | ||
142 | rc2wxr convert; | |
143 | convert.Convert(wxrfile.GetPath(),filed.GetPath()); | |
144 | #endif // wxUSE_FILEDLG | |
145 | } | |
146 | ||
147 | void wxMainFrame::OnWXR2XML(wxCommandEvent& WXUNUSED(event)) | |
148 | { | |
149 | #if wxUSE_FILEDLG | |
150 | wxFileDialog f(this); | |
151 | f.SetWildcard(_T("*.wxr")); | |
152 | if (f.ShowModal()!=wxID_OK) | |
153 | return; | |
154 | ||
155 | ||
156 | wxFileDialog xmlfile(this,_T("Enter Desired XML file name")); | |
157 | xmlfile.SetWildcard(_T("*.xml")); | |
158 | xmlfile.SetStyle(wxOPEN); | |
159 | xmlfile.SetFilename(_T("resource.xml")); | |
160 | ||
161 | if (xmlfile.ShowModal()!=wxID_OK) | |
162 | return; | |
163 | ||
164 | wxr2xml XMLCon; | |
165 | XMLCon.Convert(f.GetPath(),xmlfile.GetPath()); | |
166 | #endif // wxUSE_FILEDLG | |
167 | } | |
168 | ||
169 | void wxMainFrame::OnRC2XML(wxCommandEvent& WXUNUSED(event)) | |
170 | { | |
171 | #if wxUSE_FILEDLG | |
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 | #endif // wxUSE_FILEDLG | |
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 | } |