]> git.saurik.com Git - wxWidgets.git/blob - contrib/samples/deprecated/resource/resource.cpp
Move the WX_FLAVOUR variables to be defined generally, not just for
[wxWidgets.git] / contrib / samples / deprecated / resource / resource.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: resource.cpp
3 // Purpose: Dialog resource sample
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 // #pragma implementation
14 #endif
15
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/wx.h"
25 #endif
26
27 #include "wx/deprecated/setup.h"
28
29 #if !wxUSE_WX_RESOURCES
30 #error "You should set wxUSE_WX_RESOURCES to 1 to compile this sample"
31 #endif
32
33 #if wxUSE_UNICODE
34 // #error "This sample can't be compiled in Unicode mode."
35 #endif // wxUSE_UNICODE
36
37 #include "wx/deprecated/resource.h"
38
39 #include <ctype.h>
40 #include "resource.h"
41
42 // If we wanted to demonstrate total platform independence,
43 // then we'd use the dynamic file loading form for all platforms.
44 // But this shows how to embed the wxWidgets resources
45 // in the program code/executable for UNIX and Windows
46 // platforms.
47
48 // In order to get the ID of the controls defined in the
49 // dialog, we include the header automatically generated
50 // by DialogEd
51
52 #include "dialog1.h"
53
54 // If you have a Windows compiler that can cope with long strings,
55 // then you can always use the #include form for simplicity.
56
57 // NOTE: Borland's brc32.exe resource compiler doesn't recognize
58 // the TEXT resource, for some reason, so either run-time file loading
59 // or file inclusion should be used.
60
61 #if defined(__WXMSW__) && !wxUSE_UNICODE
62 // Under Windows, some compilers can't include
63 // a whole .wxr file. So we use a .rc user-defined resource
64 // instead. dialog1 will point to the whole .wxr 'file'.
65 static wxChar *dialog1 = NULL;
66 static wxChar *menu1 = NULL;
67 #else
68 // Other platforms should have sensible compilers that
69 // cope with long strings.
70 #include "dialog1.wxr"
71 #include "menu1.wxr"
72 #endif
73
74 // Declare two frames
75 MyFrame *frame = (MyFrame *) NULL;
76
77 IMPLEMENT_APP(MyApp)
78
79 // Testing of ressources
80 MyApp::MyApp()
81 {
82 }
83
84 // The `main program' equivalent, creating the windows and returning the
85 // main frame
86 bool MyApp::OnInit(void)
87 {
88 #if defined(__WXMSW__) && !wxUSE_UNICODE
89 // Load the .wxr 'file' from a .rc resource, under Windows.
90 // note that the resource really is a char*, not a wxChar*!
91 dialog1 = wxLoadUserResource(wxT("dialog1"), wxT("WXRDATA"));
92 menu1 = wxLoadUserResource(wxT("menu1"), wxT("WXRDATA"));
93 // All resources in the file (only one in this case) get parsed
94 // by this call.
95 wxResourceParseString(dialog1);
96 wxResourceParseString(menu1);
97 #else
98 // Simply parse the data pointed to by the variable dialog1.
99 // If there were several resources, there would be several
100 // variables, and this would need to be called several times.
101 wxResourceParseData(dialog1);
102 wxResourceParseData(menu1);
103 #endif
104
105 // Create the main frame window
106 frame = new MyFrame( (wxFrame *) NULL, wxID_ANY,
107 wxT("wxWidgets Resource Sample"),
108 wxDefaultPosition, wxSize(300, 250) );
109
110 #if wxUSE_STATUSBAR
111 // Give it a status line
112 frame->CreateStatusBar(2);
113 #endif // wxUSE_STATUSBAR
114
115 wxMenuBar *menu_bar = wxResourceCreateMenuBar(wxT("menu1"));
116
117 // Associate the menu bar with the frame
118 frame->SetMenuBar(menu_bar);
119
120 // Make a panel
121 frame->panel = new MyPanel( frame, wxID_ANY, wxPoint(0, 0), wxSize(400, 400),
122 0, wxT("MyMainFrame") );
123 frame->Show(true);
124
125 SetTopWindow(frame);
126
127 return true;
128 }
129
130 MyApp::~MyApp()
131 {
132 #if defined(__WXMSW__) && !wxUSE_UNICODE
133 delete dialog1;
134 delete menu1;
135 #endif
136 }
137
138 BEGIN_EVENT_TABLE(MyPanel, wxPanel)
139 EVT_LEFT_DOWN( MyPanel::OnClick)
140 END_EVENT_TABLE()
141
142 MyPanel::MyPanel
143 (
144 wxWindow *parent, wxWindowID id, const wxPoint& pos,
145 const wxSize& size,
146 int style, const wxString &name
147 ) : wxPanel( parent, id, pos, size, style, name )
148 {
149 }
150
151 void MyPanel::OnClick( wxMouseEvent &WXUNUSED(event2) )
152 {
153 MyFrame *frame = (MyFrame*)(wxTheApp->GetTopWindow());
154 wxCommandEvent event;
155 frame->OnTestDialog( event );
156 }
157
158
159 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
160 EVT_MENU(RESOURCE_ABOUT, MyFrame::OnAbout)
161 EVT_MENU(RESOURCE_QUIT, MyFrame::OnQuit)
162 EVT_MENU(RESOURCE_TESTDIALOG, MyFrame::OnTestDialog)
163 END_EVENT_TABLE()
164
165 // Define my frame constructor
166 MyFrame::MyFrame
167 (
168 wxWindow *parent, const wxWindowID id,
169 const wxString& title, const wxPoint& pos, const wxSize& size
170 ) : wxFrame(parent, id, title, pos, size)
171 {
172 panel = (wxWindow *) NULL;
173 }
174
175 void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) )
176 {
177 wxMessageBox(wxT("wxWidgets resource sample.\n")
178 wxT("(c) Julian Smart"), wxT("About wxWidgets sample"),
179 wxICON_INFORMATION | wxOK);
180 }
181
182 void MyFrame::OnQuit( wxCommandEvent& WXUNUSED(event) )
183 {
184 Close(true);
185 }
186
187 void MyFrame::OnTestDialog(wxCommandEvent& WXUNUSED(event) )
188 {
189 MyDialog *dialog = new MyDialog;
190
191 if (wxLoadFromResource(dialog, this, wxT("dialog1")))
192 {
193 wxTextCtrl *text = (wxTextCtrl *)wxFindWindowByName(wxT("multitext3"), dialog);
194 if (text)
195 {
196 text->SetValue(wxT("wxWidgets resource demo"));
197 }
198
199 dialog->ShowModal();
200 }
201
202 dialog->Close(true);
203 }
204
205 BEGIN_EVENT_TABLE(MyDialog, wxDialog)
206 //EVT_BUTTON(RESOURCE_OK, MyDialog::OnOk)
207 EVT_BUTTON(ID_BUTTON109, MyDialog::OnCancel)
208 END_EVENT_TABLE()
209
210
211 void MyDialog::OnOk(wxCommandEvent& WXUNUSED(event) )
212 {
213 // EndModal(RESOURCE_OK);
214 }
215
216 void MyDialog::OnCancel(wxCommandEvent& WXUNUSED(event) )
217 {
218 EndModal(ID_BUTTON109);
219 }
220
221