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