]>
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
8 // For compilers that support precompilation, includes "wx/wx.h".
15 // for all others, include the necessary headers (this file is usually all you
16 // need because it includes almost all "standard" wxWidgets headers
23 #include "wx/deprecated/setup.h"
24 #include "wx/deprecated/resource.h"
31 IMPLEMENT_APP(wxConvertApp
)
32 //////////////////////////////////////////////////////////////////////
33 // Construction/Destruction
34 //////////////////////////////////////////////////////////////////////
36 wxConvertApp::wxConvertApp()
43 wxConvertApp::~wxConvertApp()
49 bool wxConvertApp::OnInit()
51 //Initialize all image loaders(JPEG,BMP,PNG,and etc)
52 wxInitAllImageHandlers();
53 SetAppName(_T("wxConvertApp"));
55 if (HandleCommandLine())
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
);
65 SetTopWindow(m_pFrame
);
69 void wxConvertApp::InitMenu()
71 m_pMenuBar
=new wxMenuBar
;
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"));
79 filemenu
->Append(ID_QUIT
, _T("E&xit"));
80 m_pMenuBar
->Append(filemenu
,_T("&File"));
82 m_pFrame
->SetMenuBar(m_pMenuBar
);
87 // MainFrame.cpp: implementation of the wxMainFrame class.
89 //////////////////////////////////////////////////////////////////////
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
)
100 //////////////////////////////////////////////////////////////////////
101 // Construction/Destruction
102 //////////////////////////////////////////////////////////////////////
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
)
112 wxMainFrame::~wxMainFrame()
118 void wxMainFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
124 void wxMainFrame::OnRc2Wxr(wxCommandEvent
& WXUNUSED(event
))
127 wxFileDialog
filed(this, wxEmptyString
,
128 wxEmptyString
, wxEmptyString
,
129 _T("*.rc"), wxFD_OPEN
);
131 if (filed
.ShowModal()!=wxID_OK
)
134 wxFileDialog
wxrfile(this, _T("Enter Desired WXR file name"),
135 wxEmptyString
, _T("resource.wxr"),
136 _T("*.wxr"), wxFD_OPEN
);
138 if (wxrfile
.ShowModal()!=wxID_OK
)
142 convert
.Convert(wxrfile
.GetPath(),filed
.GetPath());
143 #endif // wxUSE_FILEDLG
146 void wxMainFrame::OnWXR2XML(wxCommandEvent
& WXUNUSED(event
))
149 wxFileDialog
f(this);
150 f
.SetWildcard(_T("*.wxr"));
151 if (f
.ShowModal()!=wxID_OK
)
155 wxFileDialog
xmlfile(this,_T("Enter Desired XML file name"),
156 wxEmptyString
, _T("resource.xml"),
157 _T("*.xml"), wxFD_OPEN
);
159 if (xmlfile
.ShowModal()!=wxID_OK
)
163 XMLCon
.Convert(f
.GetPath(),xmlfile
.GetPath());
164 #endif // wxUSE_FILEDLG
167 void wxMainFrame::OnRC2XML(wxCommandEvent
& WXUNUSED(event
))
170 wxFileDialog
f(this);
171 f
.SetWildcard(_T("*.rc"));
172 if (f
.ShowModal()!=wxID_OK
)
175 wxFileDialog
xmlfile(this,_T("Enter Desired XML file name"),
176 wxEmptyString
, _T("resource.xml"),
177 _T("*.xml"), wxFD_OPEN
);
179 if (xmlfile
.ShowModal()!=wxID_OK
)
183 XMLCon
.Convert(f
.GetPath(),xmlfile
.GetPath());
184 #endif // wxUSE_FILEDLG
187 bool wxConvertApp::HandleCommandLine()
193 //Figure out kind of conversion
194 wxString source
,target
;
196 wxr2xml trans_wxr2xml
;
204 if ((source
.Find(_T(".wxr"))>0)&&(target
.Find(_T(".xml"))>0))
206 trans_wxr2xml
.Convert(source
,target
);
209 else if ((source
.Find(_T(".rc"))!=wxNOT_FOUND
)&(target
.Find(_T(".wxr"))!=wxNOT_FOUND
))
211 trans_rc2wxr
.Convert(source
,target
);
214 else if ((source
.Find(_T(".rc"))!=wxNOT_FOUND
)&(target
.Find(_T(".xml"))!=wxNOT_FOUND
))
216 trans_rc2xml
.Convert(source
,target
);