]> git.saurik.com Git - wxWidgets.git/blame - samples/resource/resource.cpp
wxDIB::Create(wxBitmap) shouldn't do any conversions if the bitmap is already a DIB...
[wxWidgets.git] / samples / resource / resource.cpp
CommitLineData
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$
6aa89a22 8// Copyright: (c) Julian Smart
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 31#if wxUSE_UNICODE
bf604268 32// #error "This sample can't be compiled in Unicode mode."
f565a6c2
VZ
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
bf604268 59#if defined(__WXMSW__) && !wxUSE_UNICODE
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
63static wxChar *dialog1 = NULL;
64static 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 73MyFrame *frame = (MyFrame *) NULL;
457814b5
JS
74
75IMPLEMENT_APP(MyApp)
76
77// Testing of ressources
78MyApp::MyApp()
79{
80}
81
82// The `main program' equivalent, creating the windows and returning the
83// main frame
84bool MyApp::OnInit(void)
85{
bf604268 86#if defined(__WXMSW__) && !wxUSE_UNICODE
f565a6c2 87 // Load the .wxr 'file' from a .rc resource, under Windows.
bf604268 88 // note that the resource really is a char*, not a wxChar*!
f565a6c2
VZ
89 dialog1 = wxLoadUserResource(wxT("dialog1"), wxT("WXRDATA"));
90 menu1 = wxLoadUserResource(wxT("menu1"), wxT("WXRDATA"));
91 // All resources in the file (only one in this case) get parsed
92 // by this call.
93 wxResourceParseString(dialog1);
94 wxResourceParseString(menu1);
457814b5 95#else
f565a6c2
VZ
96 // Simply parse the data pointed to by the variable dialog1.
97 // If there were several resources, there would be several
98 // variables, and this would need to be called several times.
99 wxResourceParseData(dialog1);
100 wxResourceParseData(menu1);
457814b5
JS
101#endif
102
f565a6c2
VZ
103 // Create the main frame window
104 frame = new MyFrame( (wxFrame *) NULL, -1,
bf604268 105 wxT("wxWindows Resource Sample"),
f565a6c2
VZ
106 wxPoint(-1, -1), wxSize(300, 250) );
107
108 // Give it a status line
109 frame->CreateStatusBar(2);
457814b5 110
bf604268 111 wxMenuBar *menu_bar = wxResourceCreateMenuBar(wxT("menu1"));
457814b5 112
f565a6c2
VZ
113 // Associate the menu bar with the frame
114 frame->SetMenuBar(menu_bar);
457814b5 115
f565a6c2
VZ
116 // Make a panel
117 frame->panel = new MyPanel( frame, -1, wxPoint(0, 0), wxSize(400, 400),
bf604268 118 0, wxT("MyMainFrame") );
f565a6c2 119 frame->Show(TRUE);
457814b5 120
f565a6c2 121 SetTopWindow(frame);
457814b5 122
f565a6c2 123 return TRUE;
457814b5
JS
124}
125
1d5b7a0b
VZ
126MyApp::~MyApp()
127{
bf604268 128#if defined(__WXMSW__) && !wxUSE_UNICODE
1d5b7a0b
VZ
129 delete dialog1;
130 delete menu1;
f6bcfd97 131#endif
1d5b7a0b
VZ
132}
133
8d71b555 134BEGIN_EVENT_TABLE(MyPanel, wxPanel)
2f6c54eb 135 EVT_LEFT_DOWN( MyPanel::OnClick)
8d71b555
RR
136END_EVENT_TABLE()
137
f565a6c2
VZ
138MyPanel::MyPanel
139(
140 wxWindow *parent, wxWindowID id, const wxPoint& pos,
141 const wxSize& size,
142 int style, const wxString &name
143) : wxPanel( parent, id, pos, size, style, name )
8d71b555
RR
144{
145}
146
1d5b7a0b 147void MyPanel::OnClick( wxMouseEvent &WXUNUSED(event2) )
8d71b555 148{
f565a6c2
VZ
149 MyFrame *frame = (MyFrame*)(wxTheApp->GetTopWindow());
150 wxCommandEvent event;
151 frame->OnTestDialog( event );
8d71b555
RR
152}
153
154
457814b5 155BEGIN_EVENT_TABLE(MyFrame, wxFrame)
2f6c54eb
VZ
156 EVT_MENU(RESOURCE_ABOUT, MyFrame::OnAbout)
157 EVT_MENU(RESOURCE_QUIT, MyFrame::OnQuit)
158 EVT_MENU(RESOURCE_TESTDIALOG, MyFrame::OnTestDialog)
457814b5
JS
159END_EVENT_TABLE()
160
161// Define my frame constructor
f565a6c2
VZ
162MyFrame::MyFrame
163(
164 wxWindow *parent, const wxWindowID id,
165 const wxString& title, const wxPoint& pos, const wxSize& size
166) : wxFrame(parent, id, title, pos, size)
457814b5 167{
f565a6c2 168 panel = (wxWindow *) NULL;
457814b5
JS
169}
170
1d5b7a0b
VZ
171void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) )
172{
bf604268
MB
173 wxMessageBox(wxT("wxWindows resource sample.\n")
174 wxT("(c) Julian Smart"), wxT("About wxWindows sample"),
1d5b7a0b
VZ
175 wxICON_INFORMATION | wxOK);
176}
177
8d71b555 178void MyFrame::OnQuit( wxCommandEvent& WXUNUSED(event) )
457814b5 179{
2f6c54eb 180 Close(TRUE);
457814b5
JS
181}
182
1d5b7a0b 183void MyFrame::OnTestDialog(wxCommandEvent& WXUNUSED(event) )
457814b5 184{
f565a6c2
VZ
185 MyDialog *dialog = new MyDialog;
186
bf604268 187 if (dialog->LoadFromResource(this, wxT("dialog1")))
f565a6c2 188 {
bf604268 189 wxTextCtrl *text = (wxTextCtrl *)wxFindWindowByName(wxT("multitext3"), dialog);
457814b5 190 if (text)
f565a6c2 191 {
bf604268 192 text->SetValue(wxT("wxWindows resource demo"));
f565a6c2
VZ
193 }
194
457814b5 195 dialog->ShowModal();
f565a6c2
VZ
196 }
197
198 dialog->Close(TRUE);
457814b5
JS
199}
200
457814b5 201BEGIN_EVENT_TABLE(MyDialog, wxDialog)
2f6c54eb
VZ
202 //EVT_BUTTON(RESOURCE_OK, MyDialog::OnOk)
203 EVT_BUTTON(ID_BUTTON109, MyDialog::OnCancel)
457814b5
JS
204END_EVENT_TABLE()
205
206
8d71b555 207void MyDialog::OnOk(wxCommandEvent& WXUNUSED(event) )
457814b5 208{
f565a6c2 209 // EndModal(RESOURCE_OK);
457814b5
JS
210}
211
8d71b555 212void MyDialog::OnCancel(wxCommandEvent& WXUNUSED(event) )
457814b5 213{
f565a6c2 214 EndModal(ID_BUTTON109);
457814b5
JS
215}
216
217