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