]>
git.saurik.com Git - wxWidgets.git/blob - contrib/samples/xml/xmldemo.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: XML resources sample
4 // Author: Vaclav Slavik
6 // Copyright: (c) Vaclav Slavik
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // ============================================================================
12 // ============================================================================
14 // ----------------------------------------------------------------------------
16 // ----------------------------------------------------------------------------
18 #pragma implementation "xmldemo.cpp"
19 #pragma interface "xmldemo.cpp"
22 // For compilers that support precompilation, includes "wx/wx.h".
23 #include "wx/wxprec.h"
29 // for all others, include the necessary headers (this file is usually all you
30 // need because it includes almost all "standard" wxWindows headers)
36 #include "wx/xml/xmlres.h"
38 // ----------------------------------------------------------------------------
40 // ----------------------------------------------------------------------------
41 // the application icon
42 #if defined(__WXGTK__) || defined(__WXMOTIF__)
43 #include "rc/appicon.xpm"
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 // Define a new application type, each program should derive a class from wxApp
51 class MyApp
: public wxApp
54 // override base class virtuals
55 // ----------------------------
57 // this one is called on application startup and is a good place for the app
58 // initialization (doing it here and not in the ctor allows to have an error
59 // return: if OnInit() returns false, the application terminates)
60 virtual bool OnInit();
63 // Define a new frame type: this is going to be our main frame
64 class MyFrame
: public wxFrame
68 MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
);
70 // event handlers (these functions should _not_ be virtual)
71 void OnQuit(wxCommandEvent
& event
);
72 void OnAbout(wxCommandEvent
& event
);
73 void OnDlg1(wxCommandEvent
& event
);
74 void OnDlg2(wxCommandEvent
& event
);
77 // any class wishing to process wxWindows events must use this macro
81 // ----------------------------------------------------------------------------
82 // event tables and other macros for wxWindows
83 // ----------------------------------------------------------------------------
85 // the event tables connect the wxWindows events with the functions (event
86 // handlers) which process them. It can be also done at run-time, but for the
87 // simple menu events like this the static method is much simpler.
88 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
89 EVT_MENU(XMLID("menu_quit"), MyFrame::OnQuit
)
90 EVT_MENU(XMLID("menu_about"), MyFrame::OnAbout
)
91 EVT_MENU(XMLID("menu_dlg1"), MyFrame::OnDlg1
)
92 EVT_MENU(XMLID("menu_dlg2"), MyFrame::OnDlg2
)
95 // Create a new application object: this macro will allow wxWindows to create
96 // the application object during program execution (it's better than using a
97 // static object for many reasons) and also declares the accessor function
98 // wxGetApp() which will return the reference of the right type (i.e. MyApp and
102 // ============================================================================
104 // ============================================================================
106 // ----------------------------------------------------------------------------
107 // the application class
108 // ----------------------------------------------------------------------------
110 // 'Main program' equivalent: the program execution "starts" here
113 wxImage::AddHandler(new wxGIFHandler
);
114 wxTheXmlResource
->InitAllHandlers();
115 wxTheXmlResource
->Load("rc/resource.xml");
117 MyFrame
*frame
= new MyFrame("XML resources demo",
118 wxPoint(50, 50), wxSize(450, 340));
123 // ----------------------------------------------------------------------------
125 // ----------------------------------------------------------------------------
128 MyFrame::MyFrame(const wxString
& title
, const wxPoint
& pos
, const wxSize
& size
)
129 : wxFrame((wxFrame
*)NULL
, -1, title
, pos
, size
)
131 SetIcon(wxICON(appicon
));
133 SetMenuBar(wxTheXmlResource
->LoadMenuBar("mainmenu"));
134 SetToolBar(wxTheXmlResource
->LoadToolBar(this, "toolbar"));
140 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
142 // TRUE is to force the frame to close
146 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
149 msg
.Printf( _T("This is the about dialog of XML resources demo.\n")
150 _T("Welcome to %s"), wxVERSION_STRING
);
152 wxMessageBox(msg
, "About XML resources demo", wxOK
| wxICON_INFORMATION
, this);
155 void MyFrame::OnDlg1(wxCommandEvent
& WXUNUSED(event
))
158 wxTheXmlResource
->LoadDialog(&dlg
, this, "dlg1");
163 void MyFrame::OnDlg2(wxCommandEvent
& WXUNUSED(event
))
166 wxTheXmlResource
->LoadDialog(&dlg
, this, "dlg2");