add support for creating drop down toolbar buttons from XRC
[wxWidgets.git] / samples / xrc / xrcdemo.cpp
1 //-----------------------------------------------------------------------------
2 // Name: xrcdemo.cpp
3 // Purpose: XML resources sample: Main application file
4 // Author: Robert O'Connor (rob@medicalmnemonics.com), Vaclav Slavik
5 // RCS-ID: $Id$
6 // Copyright: (c) Robert O'Connor and Vaclav Slavik
7 // Licence: wxWindows licence
8 //-----------------------------------------------------------------------------
9
10 //-----------------------------------------------------------------------------
11 // Standard wxWidgets headers
12 //-----------------------------------------------------------------------------
13
14 // For compilers that support precompilation, includes "wx/wx.h".
15 #include "wx/wxprec.h"
16
17 #ifdef __BORLANDC__
18 #pragma hdrstop
19 #endif
20
21 // For all others, include the necessary headers (this file is usually all you
22 // need because it includes almost all "standard" wxWidgets headers)
23 #ifndef WX_PRECOMP
24 #include "wx/wx.h"
25 #endif
26
27 //-----------------------------------------------------------------------------
28 // Header of this .cpp file
29 //-----------------------------------------------------------------------------
30
31 #include "xrcdemo.h"
32
33 //-----------------------------------------------------------------------------
34 // Remaining headers: Needed wx headers, then wx/contrib headers, then app one
35 //-----------------------------------------------------------------------------
36
37 #include "wx/image.h" // wxImage
38
39 #include "wx/xrc/xmlres.h" // XRC XML resources
40
41 #include "wx/cshelp.h" // wxSimpleHelpProvider for helptext
42
43 #include "myframe.h"
44
45 //-----------------------------------------------------------------------------
46 // wxWidgets macro: Declare the application.
47 //-----------------------------------------------------------------------------
48
49 // Create a new application object: this macro will allow wxWidgets to create
50 // the application object during program execution (it's better than using a
51 // static object for many reasons) and also declares the accessor function
52 // wxGetApp() which will return the reference of the right type (i.e. the_app and
53 // not wxApp).
54 IMPLEMENT_APP(MyApp)
55
56 //-----------------------------------------------------------------------------
57 // Public methods
58 //-----------------------------------------------------------------------------
59
60 // 'Main program' equivalent: the program execution "starts" here
61 bool MyApp::OnInit()
62 {
63 if ( !wxApp::OnInit() )
64 return false;
65
66 // If there is any of a certain format of image in the xrcs, then first
67 // load a handler for that image type. This example uses XPMs, but if
68 // you want PNGs, then add a PNG handler, etc. See wxImage::AddHandler()
69 // documentation for the types of image handlers available.
70 wxImage::AddHandler(new wxXPMHandler);
71
72 // Initialize all the XRC handlers. Always required (unless you feel like
73 // going through and initializing a handler of each control type you will
74 // be using (ie initialize the spinctrl handler, initialize the textctrl
75 // handler). However, if you are only using a few control types, it will
76 // save some space to only initialize the ones you will be using. See
77 // wxXRC docs for details.
78 wxXmlResource::Get()->InitAllHandlers();
79
80 // Load all of the XRC files that will be used. You can put everything
81 // into one giant XRC file if you wanted, but then they become more
82 // diffcult to manage, and harder to reuse in later projects.
83 // The menubar
84 if (!wxXmlResource::Get()->Load(wxT("rc/menu.xrc")))
85 return false;
86
87 // The toolbar
88 if (!wxXmlResource::Get()->Load(wxT("rc/toolbar.xrc")))
89 return false;
90
91 // Non-derived dialog example
92 if (!wxXmlResource::Get()->Load(wxT("rc/basicdlg.xrc")))
93 return false;
94
95 // Derived dialog example
96 if (!wxXmlResource::Get()->Load(wxT("rc/derivdlg.xrc")))
97 return false;
98
99 // Controls property example
100 if (!wxXmlResource::Get()->Load(wxT("rc/controls.xrc")))
101 return false;
102
103 // Frame example
104 if (!wxXmlResource::Get()->Load(wxT("rc/frame.xrc")))
105 return false;
106
107 // Uncentered example
108 if (!wxXmlResource::Get()->Load(wxT("rc/uncenter.xrc")))
109 return false;
110
111 // Custom class example
112 if (!wxXmlResource::Get()->Load(wxT("rc/custclas.xrc")))
113 return false;
114
115 // wxArtProvider example
116 if (!wxXmlResource::Get()->Load(wxT("rc/artprov.xrc")))
117 return false;
118
119 // Platform property example
120 if (!wxXmlResource::Get()->Load(wxT("rc/platform.xrc")))
121 return false;
122
123 // Variable expansion example
124 if (!wxXmlResource::Get()->Load(wxT("rc/variable.xrc")))
125 return false;
126
127
128 #if wxUSE_HELP
129 // Use the simple help provider to show the context-sensitive help
130 wxHelpProvider::Set( new wxSimpleHelpProvider );
131 #endif // wxUSE_HELP
132
133 // Make an instance of your derived frame. Passing NULL (the default value
134 // of MyFrame's constructor is NULL) as the frame doesn't have a parent
135 // since it is the main application window.
136 MyFrame *frame = new MyFrame();
137
138 // Show the frame as it's created initially hidden.
139 frame->Show(true);
140
141 // Return true to tell program to continue (false would terminate).
142 return true;
143 }
144