]>
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);
128 filed
.SetWildcard(_T("*.rc"));
129 filed
.SetStyle(wxOPEN
);
131 if (filed
.ShowModal()!=wxID_OK
)
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"));
139 if (wxrfile
.ShowModal()!=wxID_OK
)
143 convert
.Convert(wxrfile
.GetPath(),filed
.GetPath());
144 #endif // wxUSE_FILEDLG
147 void wxMainFrame::OnWXR2XML(wxCommandEvent
& WXUNUSED(event
))
150 wxFileDialog
f(this);
151 f
.SetWildcard(_T("*.wxr"));
152 if (f
.ShowModal()!=wxID_OK
)
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"));
161 if (xmlfile
.ShowModal()!=wxID_OK
)
165 XMLCon
.Convert(f
.GetPath(),xmlfile
.GetPath());
166 #endif // wxUSE_FILEDLG
169 void wxMainFrame::OnRC2XML(wxCommandEvent
& WXUNUSED(event
))
172 wxFileDialog
f(this);
173 f
.SetWildcard(_T("*.rc"));
174 if (f
.ShowModal()!=wxID_OK
)
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"));
182 if (xmlfile
.ShowModal()!=wxID_OK
)
186 XMLCon
.Convert(f
.GetPath(),xmlfile
.GetPath());
187 #endif // wxUSE_FILEDLG
190 bool wxConvertApp::HandleCommandLine()
196 //Figure out kind of conversion
197 wxString source
,target
;
199 wxr2xml trans_wxr2xml
;
207 if ((source
.Find(_T(".wxr"))>0)&&(target
.Find(_T(".xml"))>0))
209 trans_wxr2xml
.Convert(source
,target
);
212 else if ((source
.Find(_T(".rc"))!=wxNOT_FOUND
)&(target
.Find(_T(".wxr"))!=wxNOT_FOUND
))
214 trans_rc2wxr
.Convert(source
,target
);
217 else if ((source
.Find(_T(".rc"))!=wxNOT_FOUND
)&(target
.Find(_T(".xml"))!=wxNOT_FOUND
))
219 trans_rc2xml
.Convert(source
,target
);