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