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