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