]> git.saurik.com Git - wxWidgets.git/blob - samples/resource/resource.cpp
fixed typo
[wxWidgets.git] / samples / 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 and Markus Holzem
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 #if wxUSE_UNICODE
28 #error "This sample can't be compiled in Unicode mode."
29 #endif // wxUSE_UNICODE
30
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
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
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
55 #if defined(__WXMSW__)
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'.
59 static wxChar *dialog1 = NULL;
60 static wxChar *menu1 = NULL;
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
69 MyFrame *frame = (MyFrame *) NULL;
70
71 IMPLEMENT_APP(MyApp)
72
73 // Testing of ressources
74 MyApp::MyApp()
75 {
76 }
77
78 // The `main program' equivalent, creating the windows and returning the
79 // main frame
80 bool MyApp::OnInit(void)
81 {
82 #if defined(__WXMSW__)
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);
90 #else
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);
96 #endif
97
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);
105
106 wxMenuBar *menu_bar = wxResourceCreateMenuBar("menu1");
107
108 // Associate the menu bar with the frame
109 frame->SetMenuBar(menu_bar);
110
111 // Make a panel
112 frame->panel = new MyPanel( frame, -1, wxPoint(0, 0), wxSize(400, 400),
113 0, "MyMainFrame" );
114 frame->Show(TRUE);
115
116 SetTopWindow(frame);
117
118 return TRUE;
119 }
120
121 MyApp::~MyApp()
122 {
123 #if defined(__WXMSW__)
124 delete dialog1;
125 delete menu1;
126 #endif
127 }
128
129 BEGIN_EVENT_TABLE(MyPanel, wxPanel)
130 EVT_LEFT_DOWN( MyPanel::OnClick)
131 END_EVENT_TABLE()
132
133 MyPanel::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 )
139 {
140 }
141
142 void MyPanel::OnClick( wxMouseEvent &WXUNUSED(event2) )
143 {
144 MyFrame *frame = (MyFrame*)(wxTheApp->GetTopWindow());
145 wxCommandEvent event;
146 frame->OnTestDialog( event );
147 }
148
149
150 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
151 EVT_MENU(RESOURCE_ABOUT, MyFrame::OnAbout)
152 EVT_MENU(RESOURCE_QUIT, MyFrame::OnQuit)
153 EVT_MENU(RESOURCE_TESTDIALOG, MyFrame::OnTestDialog)
154 END_EVENT_TABLE()
155
156 // Define my frame constructor
157 MyFrame::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)
162 {
163 panel = (wxWindow *) NULL;
164 }
165
166 void 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
173 void MyFrame::OnQuit( wxCommandEvent& WXUNUSED(event) )
174 {
175 Close(TRUE);
176 }
177
178 void MyFrame::OnTestDialog(wxCommandEvent& WXUNUSED(event) )
179 {
180 MyDialog *dialog = new MyDialog;
181
182 if (dialog->LoadFromResource(this, "dialog1"))
183 {
184 wxTextCtrl *text = (wxTextCtrl *)wxFindWindowByName("multitext3", dialog);
185 if (text)
186 {
187 text->SetValue("wxWindows resource demo");
188 }
189
190 dialog->ShowModal();
191 }
192
193 dialog->Close(TRUE);
194 }
195
196 BEGIN_EVENT_TABLE(MyDialog, wxDialog)
197 //EVT_BUTTON(RESOURCE_OK, MyDialog::OnOk)
198 EVT_BUTTON(ID_BUTTON109, MyDialog::OnCancel)
199 END_EVENT_TABLE()
200
201
202 void MyDialog::OnOk(wxCommandEvent& WXUNUSED(event) )
203 {
204 // EndModal(RESOURCE_OK);
205 }
206
207 void MyDialog::OnCancel(wxCommandEvent& WXUNUSED(event) )
208 {
209 EndModal(ID_BUTTON109);
210 }
211
212