]>
git.saurik.com Git - wxWidgets.git/blob - 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
9 #pragma implementation "convert.h"
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
19 // for all others, include the necessary headers (this file is usually all you
20 // need because it includes almost all "standard" wxWidgets headers
27 #include "wx/deprecated/setup.h"
28 #include "wx/deprecated/resource.h"
35 IMPLEMENT_APP(wxConvertApp
)
36 //////////////////////////////////////////////////////////////////////
37 // Construction/Destruction
38 //////////////////////////////////////////////////////////////////////
40 wxConvertApp::wxConvertApp()
47 wxConvertApp::~wxConvertApp()
53 bool wxConvertApp::OnInit()
55 //Initialize all image loaders(JPEG,BMP,PNG,and etc)
56 wxInitAllImageHandlers();
57 SetAppName(_T("wxConvertApp"));
59 if (HandleCommandLine())
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
);
69 SetTopWindow(m_pFrame
);
73 void wxConvertApp::InitMenu()
75 m_pMenuBar
=new wxMenuBar
;
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"));
83 filemenu
->Append(ID_QUIT
, _T("E&xit"));
84 m_pMenuBar
->Append(filemenu
,_T("&File"));
86 m_pFrame
->SetMenuBar(m_pMenuBar
);
91 // MainFrame.cpp: implementation of the wxMainFrame class.
93 //////////////////////////////////////////////////////////////////////
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
)
104 //////////////////////////////////////////////////////////////////////
105 // Construction/Destruction
106 //////////////////////////////////////////////////////////////////////
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
)
116 wxMainFrame::~wxMainFrame()
122 void wxMainFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
128 void wxMainFrame::OnRc2Wxr(wxCommandEvent
& WXUNUSED(event
))
131 wxFileDialog
filed(this);
132 filed
.SetWildcard(_T("*.rc"));
133 filed
.SetStyle(wxOPEN
);
135 if (filed
.ShowModal()!=wxID_OK
)
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"));
143 if (wxrfile
.ShowModal()!=wxID_OK
)
147 convert
.Convert(wxrfile
.GetPath(),filed
.GetPath());
148 #endif // wxUSE_FILEDLG
151 void wxMainFrame::OnWXR2XML(wxCommandEvent
& WXUNUSED(event
))
154 wxFileDialog
f(this);
155 f
.SetWildcard(_T("*.wxr"));
156 if (f
.ShowModal()!=wxID_OK
)
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"));
165 if (xmlfile
.ShowModal()!=wxID_OK
)
169 XMLCon
.Convert(f
.GetPath(),xmlfile
.GetPath());
170 #endif // wxUSE_FILEDLG
173 void wxMainFrame::OnRC2XML(wxCommandEvent
& WXUNUSED(event
))
176 wxFileDialog
f(this);
177 f
.SetWildcard(_T("*.rc"));
178 if (f
.ShowModal()!=wxID_OK
)
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"));
186 if (xmlfile
.ShowModal()!=wxID_OK
)
190 XMLCon
.Convert(f
.GetPath(),xmlfile
.GetPath());
191 #endif // wxUSE_FILEDLG
194 bool wxConvertApp::HandleCommandLine()
200 //Figure out kind of conversion
201 wxString source
,target
;
203 wxr2xml trans_wxr2xml
;
211 if ((source
.Find(_T(".wxr"))>0)&&(target
.Find(_T(".xml"))>0))
213 trans_wxr2xml
.Convert(source
,target
);
216 else if ((source
.Find(_T(".rc"))!=wxNOT_FOUND
)&(target
.Find(_T(".wxr"))!=wxNOT_FOUND
))
218 trans_rc2wxr
.Convert(source
,target
);
221 else if ((source
.Find(_T(".rc"))!=wxNOT_FOUND
)&(target
.Find(_T(".xml"))!=wxNOT_FOUND
))
223 trans_rc2xml
.Convert(source
,target
);