]> git.saurik.com Git - wxWidgets.git/blame - contrib/samples/xrc/xrcdemo.cpp
added missing -univ package control files.
[wxWidgets.git] / contrib / samples / xrc / xrcdemo.cpp
CommitLineData
64d452a8
VS
1/////////////////////////////////////////////////////////////////////////////
2// Name: xmldemo.cpp
3// Purpose: XML resources sample
4// Author: Vaclav Slavik
5// RCS-ID: $Id$
6// Copyright: (c) Vaclav Slavik
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10// ============================================================================
11// declarations
12// ============================================================================
13
14// ----------------------------------------------------------------------------
15// headers
16// ----------------------------------------------------------------------------
17#ifdef __GNUG__
999d9a9f
VS
18 #pragma implementation "xrcdemo.cpp"
19 #pragma interface "xrcdemo.cpp"
64d452a8
VS
20#endif
21
22// For compilers that support precompilation, includes "wx/wx.h".
23#include "wx/wxprec.h"
24
25#ifdef __BORLANDC__
26 #pragma hdrstop
27#endif
28
29// for all others, include the necessary headers (this file is usually all you
30// need because it includes almost all "standard" wxWindows headers)
31#ifndef WX_PRECOMP
32 #include "wx/wx.h"
64d452a8
VS
33#endif
34
d9300df9 35#include "wx/image.h"
999d9a9f 36#include "wx/xrc/xmlres.h"
64d452a8
VS
37
38// ----------------------------------------------------------------------------
39// resources
40// ----------------------------------------------------------------------------
41// the application icon
42#if defined(__WXGTK__) || defined(__WXMOTIF__)
43 #include "rc/appicon.xpm"
44#endif
45
46// ----------------------------------------------------------------------------
47// private classes
48// ----------------------------------------------------------------------------
49
50// Define a new application type, each program should derive a class from wxApp
51class MyApp : public wxApp
52{
53public:
54 // override base class virtuals
55 // ----------------------------
56
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();
61};
62
63// Define a new frame type: this is going to be our main frame
64class MyFrame : public wxFrame
65{
66public:
67 // ctor(s)
68 MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
69
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);
75
76private:
77 // any class wishing to process wxWindows events must use this macro
78 DECLARE_EVENT_TABLE()
79};
80
81// ----------------------------------------------------------------------------
82// event tables and other macros for wxWindows
83// ----------------------------------------------------------------------------
84
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.
88BEGIN_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)
93END_EVENT_TABLE()
94
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
99// not wxApp)
100IMPLEMENT_APP(MyApp)
101
102// ============================================================================
103// implementation
104// ============================================================================
105
106// ----------------------------------------------------------------------------
107// the application class
108// ----------------------------------------------------------------------------
109
110// 'Main program' equivalent: the program execution "starts" here
111bool MyApp::OnInit()
112{
113 wxImage::AddHandler(new wxGIFHandler);
114 wxTheXmlResource->InitAllHandlers();
d9300df9 115 wxTheXmlResource->Load("rc/resource.xrc");
64d452a8
VS
116
117 MyFrame *frame = new MyFrame("XML resources demo",
118 wxPoint(50, 50), wxSize(450, 340));
119 frame->Show(TRUE);
120 return TRUE;
121}
122
123// ----------------------------------------------------------------------------
124// main frame
125// ----------------------------------------------------------------------------
126
127// frame constructor
128MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
129 : wxFrame((wxFrame *)NULL, -1, title, pos, size)
130{
131 SetIcon(wxICON(appicon));
132
133 SetMenuBar(wxTheXmlResource->LoadMenuBar("mainmenu"));
134 SetToolBar(wxTheXmlResource->LoadToolBar(this, "toolbar"));
135}
136
137
138// event handlers
139
140void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
141{
142 // TRUE is to force the frame to close
143 Close(TRUE);
144}
145
146void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
147{
148 wxString msg;
149 msg.Printf( _T("This is the about dialog of XML resources demo.\n")
150 _T("Welcome to %s"), wxVERSION_STRING);
151
152 wxMessageBox(msg, "About XML resources demo", wxOK | wxICON_INFORMATION, this);
153}
154
155void MyFrame::OnDlg1(wxCommandEvent& WXUNUSED(event))
156{
157 wxDialog dlg;
158 wxTheXmlResource->LoadDialog(&dlg, this, "dlg1");
159 dlg.ShowModal();
160}
161
162
163void MyFrame::OnDlg2(wxCommandEvent& WXUNUSED(event))
164{
165 wxDialog dlg;
166 wxTheXmlResource->LoadDialog(&dlg, this, "dlg2");
167 dlg.ShowModal();
168}