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