]> git.saurik.com Git - wxWidgets.git/blob - contrib/samples/deprecated/resource/resource.cpp
Updating bakefiles to include wxWebKit.
[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 wxWindows 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, -1,
107 wxT("wxWindows Resource Sample"),
108 wxPoint(-1, -1), wxSize(300, 250) );
109
110 // Give it a status line
111 frame->CreateStatusBar(2);
112
113 wxMenuBar *menu_bar = wxResourceCreateMenuBar(wxT("menu1"));
114
115 // Associate the menu bar with the frame
116 frame->SetMenuBar(menu_bar);
117
118 // Make a panel
119 frame->panel = new MyPanel( frame, -1, wxPoint(0, 0), wxSize(400, 400),
120 0, wxT("MyMainFrame") );
121 frame->Show(TRUE);
122
123 SetTopWindow(frame);
124
125 return TRUE;
126 }
127
128 MyApp::~MyApp()
129 {
130 #if defined(__WXMSW__) && !wxUSE_UNICODE
131 delete dialog1;
132 delete menu1;
133 #endif
134 }
135
136 BEGIN_EVENT_TABLE(MyPanel, wxPanel)
137 EVT_LEFT_DOWN( MyPanel::OnClick)
138 END_EVENT_TABLE()
139
140 MyPanel::MyPanel
141 (
142 wxWindow *parent, wxWindowID id, const wxPoint& pos,
143 const wxSize& size,
144 int style, const wxString &name
145 ) : wxPanel( parent, id, pos, size, style, name )
146 {
147 }
148
149 void MyPanel::OnClick( wxMouseEvent &WXUNUSED(event2) )
150 {
151 MyFrame *frame = (MyFrame*)(wxTheApp->GetTopWindow());
152 wxCommandEvent event;
153 frame->OnTestDialog( event );
154 }
155
156
157 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
158 EVT_MENU(RESOURCE_ABOUT, MyFrame::OnAbout)
159 EVT_MENU(RESOURCE_QUIT, MyFrame::OnQuit)
160 EVT_MENU(RESOURCE_TESTDIALOG, MyFrame::OnTestDialog)
161 END_EVENT_TABLE()
162
163 // Define my frame constructor
164 MyFrame::MyFrame
165 (
166 wxWindow *parent, const wxWindowID id,
167 const wxString& title, const wxPoint& pos, const wxSize& size
168 ) : wxFrame(parent, id, title, pos, size)
169 {
170 panel = (wxWindow *) NULL;
171 }
172
173 void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) )
174 {
175 wxMessageBox(wxT("wxWindows resource sample.\n")
176 wxT("(c) Julian Smart"), wxT("About wxWindows sample"),
177 wxICON_INFORMATION | wxOK);
178 }
179
180 void MyFrame::OnQuit( wxCommandEvent& WXUNUSED(event) )
181 {
182 Close(TRUE);
183 }
184
185 void MyFrame::OnTestDialog(wxCommandEvent& WXUNUSED(event) )
186 {
187 MyDialog *dialog = new MyDialog;
188
189 if (wxLoadFromResource(dialog, this, wxT("dialog1")))
190 {
191 wxTextCtrl *text = (wxTextCtrl *)wxFindWindowByName(wxT("multitext3"), dialog);
192 if (text)
193 {
194 text->SetValue(wxT("wxWindows resource demo"));
195 }
196
197 dialog->ShowModal();
198 }
199
200 dialog->Close(TRUE);
201 }
202
203 BEGIN_EVENT_TABLE(MyDialog, wxDialog)
204 //EVT_BUTTON(RESOURCE_OK, MyDialog::OnOk)
205 EVT_BUTTON(ID_BUTTON109, MyDialog::OnCancel)
206 END_EVENT_TABLE()
207
208
209 void MyDialog::OnOk(wxCommandEvent& WXUNUSED(event) )
210 {
211 // EndModal(RESOURCE_OK);
212 }
213
214 void MyDialog::OnCancel(wxCommandEvent& WXUNUSED(event) )
215 {
216 EndModal(ID_BUTTON109);
217 }
218
219