]>
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 JS |
10 | //----------------------------------------------------------------------------- |
11 | // GCC implementation | |
12 | //----------------------------------------------------------------------------- | |
64d452a8 | 13 | |
64d452a8 | 14 | #ifdef __GNUG__ |
af1337b0 | 15 | #pragma implementation "xrcdemo.h" |
64d452a8 VS |
16 | #endif |
17 | ||
af1337b0 | 18 | //----------------------------------------------------------------------------- |
be5a51fb | 19 | // Standard wxWidgets headers |
af1337b0 JS |
20 | //----------------------------------------------------------------------------- |
21 | ||
64d452a8 VS |
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 | ||
af1337b0 | 29 | // For all others, include the necessary headers (this file is usually all you |
be5a51fb | 30 | // need because it includes almost all "standard" wxWidgets headers) |
64d452a8 VS |
31 | #ifndef WX_PRECOMP |
32 | #include "wx/wx.h" | |
64d452a8 VS |
33 | #endif |
34 | ||
af1337b0 JS |
35 | //----------------------------------------------------------------------------- |
36 | // Header of this .cpp file | |
37 | //----------------------------------------------------------------------------- | |
64d452a8 | 38 | |
af1337b0 | 39 | #include "xrcdemo.h" |
64d452a8 | 40 | |
af1337b0 JS |
41 | //----------------------------------------------------------------------------- |
42 | // Remaining headers: Needed wx headers, then wx/contrib headers, then application headers | |
43 | //----------------------------------------------------------------------------- | |
64d452a8 | 44 | |
af1337b0 JS |
45 | #include "wx/image.h" // wxImage |
46 | ||
47 | //----------------------------------------------------------------------------- | |
48 | ||
49 | #include "wx/xrc/xmlres.h" // XRC XML resouces | |
50 | ||
51 | //----------------------------------------------------------------------------- | |
52 | ||
53 | #include "myframe.h" | |
54 | ||
55 | //----------------------------------------------------------------------------- | |
be5a51fb | 56 | // wxWidgets macro: Declare the application. |
af1337b0 | 57 | //----------------------------------------------------------------------------- |
64d452a8 | 58 | |
be5a51fb | 59 | // Create a new application object: this macro will allow wxWidgets to create |
64d452a8 VS |
60 | // the application object during program execution (it's better than using a |
61 | // static object for many reasons) and also declares the accessor function | |
af1337b0 JS |
62 | // wxGetApp() which will return the reference of the right type (i.e. the_app and |
63 | // not wxApp). | |
64d452a8 VS |
64 | IMPLEMENT_APP(MyApp) |
65 | ||
af1337b0 JS |
66 | //----------------------------------------------------------------------------- |
67 | // Public methods | |
68 | //----------------------------------------------------------------------------- | |
64d452a8 VS |
69 | |
70 | // 'Main program' equivalent: the program execution "starts" here | |
71 | bool MyApp::OnInit() | |
72 | { | |
af1337b0 JS |
73 | // If there is any of a certain format of image in the xrcs, then first |
74 | // load a handler for that image type. This example uses XPMs, but if | |
75 | // you want PNGs, then add a PNG handler, etc. See wxImage::AddHandler() | |
76 | // documentation for the types of image handlers available. | |
77 | wxImage::AddHandler(new wxXPMHandler); | |
f80ea77b | 78 | |
af1337b0 JS |
79 | // Initialize all the XRC handlers. Always required (unless you feel like |
80 | // going through and initializing a handler of each control type you will | |
81 | // be using (ie initialize the spinctrl handler, initialize the textctrl | |
82 | // handler). However, if you are only using a few control types, it will | |
83 | // save some space to only initialize the ones you will be using. See | |
84 | // wxXRC docs for details. | |
f80ea77b WS |
85 | wxXmlResource::Get()->InitAllHandlers(); |
86 | ||
af1337b0 | 87 | // Load all of the XRC files that will be used. You can put everything |
f80ea77b WS |
88 | // into one giant XRC file if you wanted, but then they become more |
89 | // diffcult to manage, and harder to reuse in later projects. | |
af1337b0 | 90 | // The menubar |
2b5f62a0 | 91 | wxXmlResource::Get()->Load(wxT("rc/menu.xrc")); |
af1337b0 | 92 | // The toolbar |
2b5f62a0 | 93 | wxXmlResource::Get()->Load(wxT("rc/toolbar.xrc")); |
af1337b0 | 94 | // Non-derived dialog example |
2b5f62a0 | 95 | wxXmlResource::Get()->Load(wxT("rc/basicdlg.xrc")); |
af1337b0 | 96 | // Derived dialog example |
2b5f62a0 | 97 | wxXmlResource::Get()->Load(wxT("rc/derivdlg.xrc")); |
af1337b0 | 98 | // Controls property example |
2b5f62a0 | 99 | wxXmlResource::Get()->Load(wxT("rc/controls.xrc")); |
af1337b0 | 100 | // Frame example |
2b5f62a0 | 101 | wxXmlResource::Get()->Load(wxT("rc/frame.xrc")); |
af1337b0 | 102 | // Uncentered example |
f80ea77b | 103 | wxXmlResource::Get()->Load(wxT("rc/uncenter.xrc")); |
af1337b0 | 104 | // Custom class example |
2b5f62a0 | 105 | wxXmlResource::Get()->Load(wxT("rc/custclas.xrc")); |
af1337b0 | 106 | // wxArtProvider example |
2b5f62a0 | 107 | wxXmlResource::Get()->Load(wxT("rc/artprov.xrc")); |
af1337b0 | 108 | // Platform property example |
2b5f62a0 | 109 | wxXmlResource::Get()->Load(wxT("rc/platform.xrc")); |
af1337b0 | 110 | // Variable expansion example |
2b5f62a0 | 111 | wxXmlResource::Get()->Load(wxT("rc/variable.xrc")); |
af1337b0 | 112 | |
f80ea77b | 113 | // Make an instance of your derived frame. Passing NULL (the default value |
2148dc99 VZ |
114 | // of MyFrame's constructor is NULL) as the frame doesn't have a parent |
115 | // since it is the main application window. | |
af1337b0 | 116 | MyFrame *frame = new MyFrame(); |
f80ea77b | 117 | |
2148dc99 | 118 | // Show the frame as it's created initially hidden. |
f80ea77b WS |
119 | frame->Show(true); |
120 | ||
121 | // Return true to tell program to continue (false would terminate). | |
122 | return true; | |
64d452a8 VS |
123 | } |
124 |