]> git.saurik.com Git - wxWidgets.git/blame - samples/splash/splash.cpp
leave i386 compiler to default
[wxWidgets.git] / samples / splash / splash.cpp
CommitLineData
8b9d7133
WS
1/////////////////////////////////////////////////////////////////////////////
2// Name: splash.cpp
3// Purpose: wxSplashScreen sample
4// Author: Wlodzimierz ABX Skiba
5// Modified by:
6// Created: 04/08/2004
8b9d7133
WS
7// Copyright: (c) Wlodzimierz Skiba
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11// ============================================================================
12// declarations
13// ============================================================================
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
19// For compilers that support precompilation, includes "wx/wx.h".
20#include "wx/wxprec.h"
21
22#ifdef __BORLANDC__
23 #pragma hdrstop
24#endif
25
26// for all others, include the necessary headers (this file is usually all you
27// need because it includes almost all "standard" wxWidgets headers)
28#ifndef WX_PRECOMP
29 #include "wx/wx.h"
30#endif
31
32#include "wx/image.h"
33#include "wx/splash.h"
b1096e45 34#include "wx/mediactrl.h"
8b9d7133
WS
35
36// ----------------------------------------------------------------------------
37// resources
38// ----------------------------------------------------------------------------
39
40// the application icon (under Windows and OS/2 it is in resources and even
41// though we could still include the XPM here it would be unused)
e7092398 42#ifndef wxHAS_IMAGES_IN_RESOURCES
8b9d7133
WS
43 #include "../sample.xpm"
44#endif
45
58ed4361
WS
46// for smartphone, pda and other small screens use resized embedded image
47// instead of full colour png dedicated to desktops
48#include "mobile.xpm"
49
8b9d7133
WS
50// ----------------------------------------------------------------------------
51// private classes
52// ----------------------------------------------------------------------------
53
54// Define a new application type, each program should derive a class from wxApp
55class MyApp : public wxApp
56{
57public:
58 // override base class virtuals
59 // ----------------------------
60
61 // this one is called on application startup and is a good place for the app
62 // initialization (doing it here and not in the ctor allows to have an error
63 // return: if OnInit() returns false, the application terminates)
64 virtual bool OnInit();
65};
66
67// Define a new frame type: this is going to be our main frame
68class MyFrame : public wxFrame
69{
70public:
71 // ctor(s)
72 MyFrame(const wxString& title);
73
74 // event handlers (these functions should _not_ be virtual)
75 void OnQuit(wxCommandEvent& event);
76 void OnAbout(wxCommandEvent& event);
77
58ed4361
WS
78 bool m_isPda;
79
8b9d7133
WS
80private:
81 // any class wishing to process wxWidgets events must use this macro
82 DECLARE_EVENT_TABLE()
83};
84
85// ----------------------------------------------------------------------------
86// constants
87// ----------------------------------------------------------------------------
88
89// IDs for the controls and the menu commands
90enum
91{
004f4002 92 Minimal_Run = wxID_HIGHEST + 1
8b9d7133
WS
93};
94
95// ----------------------------------------------------------------------------
96// event tables and other macros for wxWidgets
97// ----------------------------------------------------------------------------
98
99// the event tables connect the wxWidgets events with the functions (event
100// handlers) which process them. It can be also done at run-time, but for the
101// simple menu events like this the static method is much simpler.
102BEGIN_EVENT_TABLE(MyFrame, wxFrame)
103 EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
104 EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
105END_EVENT_TABLE()
106
107// Create a new application object: this macro will allow wxWidgets to create
108// the application object during program execution (it's better than using a
109// static object for many reasons) and also implements the accessor function
110// wxGetApp() which will return the reference of the right type (i.e. MyApp and
111// not wxApp)
112IMPLEMENT_APP(MyApp)
113
114// ============================================================================
115// implementation
116// ============================================================================
117
118// ----------------------------------------------------------------------------
119// the application class
120// ----------------------------------------------------------------------------
121
122// 'Main program' equivalent: the program execution "starts" here
123bool MyApp::OnInit()
124{
45e6e6f8
VZ
125 if ( !wxApp::OnInit() )
126 return false;
127
8b9d7133
WS
128 wxImage::AddHandler(new wxPNGHandler);
129
77f5549a 130 // create the main application window
9a83f860 131 MyFrame *frame = new MyFrame(wxT("wxSplashScreen sample application"));
77f5549a 132
8b9d7133 133 wxBitmap bitmap;
58ed4361
WS
134
135 if (frame->m_isPda)
136 bitmap = wxBitmap(mobile_xpm);
137
138 bool ok = frame->m_isPda
a1b806b9 139 ? bitmap.IsOk()
9a83f860 140 : bitmap.LoadFile(wxT("splash.png"), wxBITMAP_TYPE_PNG);
58ed4361
WS
141
142 if (ok)
8b9d7133 143 {
78ee2a28 144 new wxSplashScreen(bitmap,
8b9d7133 145 wxSPLASH_CENTRE_ON_SCREEN|wxSPLASH_TIMEOUT,
77f5549a 146 6000, frame, wxID_ANY, wxDefaultPosition, wxDefaultSize,
8b9d7133
WS
147 wxSIMPLE_BORDER|wxSTAY_ON_TOP);
148 }
aac39d1d
FM
149
150#if !defined(__WXGTK20__)
151 // we don't need it at least on wxGTK with GTK+ 2.12.9
8b9d7133 152 wxYield();
aac39d1d 153#endif
8b9d7133 154
8b9d7133
WS
155 // and show it (the frames, unlike simple controls, are not shown when
156 // created initially)
157 frame->Show(true);
158
159 // success: wxApp::OnRun() will be called which will enter the main message
160 // loop and the application will run. If we returned false here, the
161 // application would exit immediately.
162 return true;
163}
164
165// ----------------------------------------------------------------------------
166// main frame
167// ----------------------------------------------------------------------------
168
169// frame constructor
170MyFrame::MyFrame(const wxString& title)
171 : wxFrame(NULL, wxID_ANY, title)
172{
58ed4361
WS
173 m_isPda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA);
174
8b9d7133
WS
175 // set the frame icon
176 SetIcon(wxICON(sample));
177
178#if wxUSE_MENUS
179 // create a menu bar
180 wxMenu *menuFile = new wxMenu;
181
182 // the "About" item should be in the help menu
183 wxMenu *helpMenu = new wxMenu;
2d143b66 184 helpMenu->Append(wxID_ABOUT, wxT("&About\tF1"), wxT("Show about frame"));
8b9d7133 185
9a83f860 186 menuFile->Append(wxID_EXIT, wxT("E&xit\tAlt-X"), wxT("Quit this program"));
8b9d7133
WS
187
188 // now append the freshly created menu to the menu bar...
189 wxMenuBar *menuBar = new wxMenuBar();
9a83f860
VZ
190 menuBar->Append(menuFile, wxT("&File"));
191 menuBar->Append(helpMenu, wxT("&Help"));
8b9d7133
WS
192
193 // ... and attach this menu bar to the frame
194 SetMenuBar(menuBar);
195#endif // wxUSE_MENUS
196
197#if wxUSE_STATUSBAR
198 // create a status bar just for fun (by default with 1 pane only)
199 CreateStatusBar(2);
9a83f860 200 SetStatusText(wxT("Welcome to wxWidgets!"));
8b9d7133
WS
201#endif // wxUSE_STATUSBAR
202}
203
204
205// event handlers
206
207void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
208{
209 // true is to force the frame to close
210 Close(true);
211}
212
213void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
214{
78ee2a28 215 wxBitmap bitmap;
58ed4361
WS
216
217 if (m_isPda) bitmap = wxBitmap(mobile_xpm);
218
219 bool ok = m_isPda
a1b806b9 220 ? bitmap.IsOk()
9a83f860 221 : bitmap.LoadFile(wxT("splash.png"), wxBITMAP_TYPE_PNG);
58ed4361
WS
222
223 if (ok)
78ee2a28
WS
224 {
225 wxImage image = bitmap.ConvertToImage();
aac39d1d 226
58ed4361
WS
227 // do not scale on already small screens
228 if (!m_isPda)
229 image.Rescale( bitmap.GetWidth()/2, bitmap.GetHeight()/2 );
aac39d1d 230
b1096e45 231 bitmap = wxBitmap(image);
78ee2a28
WS
232 wxSplashScreen *splash = new wxSplashScreen(bitmap,
233 wxSPLASH_CENTRE_ON_PARENT | wxSPLASH_NO_TIMEOUT,
234 0, this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
235 wxSIMPLE_BORDER|wxSTAY_ON_TOP);
aac39d1d 236
b1096e45
WS
237 wxWindow *win = splash->GetSplashWindow();
238#if wxUSE_MEDIACTRL
9a83f860 239 wxMediaCtrl *media = new wxMediaCtrl( win, wxID_EXIT, wxT("press.mpg"), wxPoint(2,2));
b1096e45
WS
240 media->Play();
241#else
58ed4361
WS
242 wxStaticText *text = new wxStaticText( win,
243 wxID_EXIT,
9a83f860 244 wxT("click somewhere\non this image"),
58ed4361
WS
245 wxPoint(m_isPda ? 0 : 13,
246 m_isPda ? 0 : 11)
247 );
78ee2a28
WS
248 text->SetBackgroundColour(*wxWHITE);
249 text->SetForegroundColour(*wxBLACK);
250 wxFont font = text->GetFont();
251 font.SetPointSize(2*font.GetPointSize()/3);
252 text->SetFont(font);
b1096e45 253#endif
78ee2a28 254 }
8b9d7133 255}