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