]>
Commit | Line | Data |
---|---|---|
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 | ||
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 | ||
7c9955d1 JS |
27 | #include "wx/deprecated/setup.h" |
28 | ||
592cae95 VS |
29 | #if !wxUSE_WX_RESOURCES |
30 | #error "You should set wxUSE_WX_RESOURCES to 1 to compile this sample" | |
820893d0 JS |
31 | #endif |
32 | ||
33 | #if wxUSE_UNICODE | |
34 | // #error "This sample can't be compiled in Unicode mode." | |
35 | #endif // wxUSE_UNICODE | |
36 | ||
7c9955d1 | 37 | #include "wx/deprecated/resource.h" |
820893d0 JS |
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. | |
be5a51fb | 44 | // But this shows how to embed the wxWidgets resources |
820893d0 JS |
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 | |
c7f8ebf8 | 106 | frame = new MyFrame( (wxFrame *) NULL, wxID_ANY, |
be5a51fb | 107 | wxT("wxWidgets Resource Sample"), |
c7f8ebf8 | 108 | wxDefaultPosition, wxSize(300, 250) ); |
820893d0 | 109 | |
d96cdd4a | 110 | #if wxUSE_STATUSBAR |
820893d0 JS |
111 | // Give it a status line |
112 | frame->CreateStatusBar(2); | |
d96cdd4a | 113 | #endif // wxUSE_STATUSBAR |
820893d0 JS |
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 | |
c7f8ebf8 | 121 | frame->panel = new MyPanel( frame, wxID_ANY, wxPoint(0, 0), wxSize(400, 400), |
820893d0 | 122 | 0, wxT("MyMainFrame") ); |
c7f8ebf8 | 123 | frame->Show(true); |
820893d0 JS |
124 | |
125 | SetTopWindow(frame); | |
126 | ||
c7f8ebf8 | 127 | return true; |
820893d0 JS |
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 | { | |
be5a51fb JS |
177 | wxMessageBox(wxT("wxWidgets resource sample.\n") |
178 | wxT("(c) Julian Smart"), wxT("About wxWidgets sample"), | |
820893d0 JS |
179 | wxICON_INFORMATION | wxOK); |
180 | } | |
181 | ||
182 | void MyFrame::OnQuit( wxCommandEvent& WXUNUSED(event) ) | |
183 | { | |
c7f8ebf8 | 184 | Close(true); |
820893d0 JS |
185 | } |
186 | ||
187 | void MyFrame::OnTestDialog(wxCommandEvent& WXUNUSED(event) ) | |
188 | { | |
189 | MyDialog *dialog = new MyDialog; | |
190 | ||
7c9955d1 | 191 | if (wxLoadFromResource(dialog, this, wxT("dialog1"))) |
820893d0 JS |
192 | { |
193 | wxTextCtrl *text = (wxTextCtrl *)wxFindWindowByName(wxT("multitext3"), dialog); | |
194 | if (text) | |
195 | { | |
be5a51fb | 196 | text->SetValue(wxT("wxWidgets resource demo")); |
820893d0 JS |
197 | } |
198 | ||
199 | dialog->ShowModal(); | |
200 | } | |
201 | ||
c7f8ebf8 | 202 | dialog->Close(true); |
820893d0 JS |
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 |