1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxSplashScreen sample
4 // Author: Wlodzimierz ABX Skiba
7 // Copyright: (c) Wlodzimierz Skiba
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx/wx.h".
20 #include "wx/wxprec.h"
26 // for all others, include the necessary headers (this file is usually all you
27 // need because it includes almost all "standard" wxWidgets headers)
33 #include "wx/splash.h"
34 #include "wx/mediactrl.h"
36 // ----------------------------------------------------------------------------
38 // ----------------------------------------------------------------------------
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)
42 #ifndef wxHAS_IMAGES_IN_RESOURCES
43 #include "../sample.xpm"
46 // for smartphone, pda and other small screens use resized embedded image
47 // instead of full colour png dedicated to desktops
50 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
54 // Define a new application type, each program should derive a class from wxApp
55 class MyApp
: public wxApp
58 // override base class virtuals
59 // ----------------------------
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();
67 // Define a new frame type: this is going to be our main frame
68 class MyFrame
: public wxFrame
72 MyFrame(const wxString
& title
);
74 // event handlers (these functions should _not_ be virtual)
75 void OnQuit(wxCommandEvent
& event
);
76 void OnAbout(wxCommandEvent
& event
);
81 // any class wishing to process wxWidgets events must use this macro
85 // ----------------------------------------------------------------------------
87 // ----------------------------------------------------------------------------
89 // IDs for the controls and the menu commands
92 Minimal_Run
= wxID_HIGHEST
+ 1
95 // ----------------------------------------------------------------------------
96 // event tables and other macros for wxWidgets
97 // ----------------------------------------------------------------------------
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.
102 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
103 EVT_MENU(wxID_EXIT
, MyFrame::OnQuit
)
104 EVT_MENU(wxID_ABOUT
, MyFrame::OnAbout
)
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
114 // ============================================================================
116 // ============================================================================
118 // ----------------------------------------------------------------------------
119 // the application class
120 // ----------------------------------------------------------------------------
122 // 'Main program' equivalent: the program execution "starts" here
125 if ( !wxApp::OnInit() )
128 wxImage::AddHandler(new wxPNGHandler
);
130 // create the main application window
131 MyFrame
*frame
= new MyFrame(wxT("wxSplashScreen sample application"));
136 bitmap
= wxBitmap(mobile_xpm
);
138 bool ok
= frame
->m_isPda
140 : bitmap
.LoadFile(wxT("splash.png"), wxBITMAP_TYPE_PNG
);
144 new wxSplashScreen(bitmap
,
145 wxSPLASH_CENTRE_ON_SCREEN
|wxSPLASH_TIMEOUT
,
146 6000, frame
, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
,
147 wxSIMPLE_BORDER
|wxSTAY_ON_TOP
);
150 #if !defined(__WXGTK20__)
151 // we don't need it at least on wxGTK with GTK+ 2.12.9
155 // and show it (the frames, unlike simple controls, are not shown when
156 // created initially)
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.
165 // ----------------------------------------------------------------------------
167 // ----------------------------------------------------------------------------
170 MyFrame::MyFrame(const wxString
& title
)
171 : wxFrame(NULL
, wxID_ANY
, title
)
173 m_isPda
= (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
);
175 // set the frame icon
176 SetIcon(wxICON(sample
));
180 wxMenu
*menuFile
= new wxMenu
;
182 // the "About" item should be in the help menu
183 wxMenu
*helpMenu
= new wxMenu
;
184 helpMenu
->Append(wxID_ABOUT
, wxT("&About\tF1"), wxT("Show about frame"));
186 menuFile
->Append(wxID_EXIT
, wxT("E&xit\tAlt-X"), wxT("Quit this program"));
188 // now append the freshly created menu to the menu bar...
189 wxMenuBar
*menuBar
= new wxMenuBar();
190 menuBar
->Append(menuFile
, wxT("&File"));
191 menuBar
->Append(helpMenu
, wxT("&Help"));
193 // ... and attach this menu bar to the frame
195 #endif // wxUSE_MENUS
198 // create a status bar just for fun (by default with 1 pane only)
200 SetStatusText(wxT("Welcome to wxWidgets!"));
201 #endif // wxUSE_STATUSBAR
207 void MyFrame::OnQuit(wxCommandEvent
& WXUNUSED(event
))
209 // true is to force the frame to close
213 void MyFrame::OnAbout(wxCommandEvent
& WXUNUSED(event
))
217 if (m_isPda
) bitmap
= wxBitmap(mobile_xpm
);
221 : bitmap
.LoadFile(wxT("splash.png"), wxBITMAP_TYPE_PNG
);
225 wxImage image
= bitmap
.ConvertToImage();
227 // do not scale on already small screens
229 image
.Rescale( bitmap
.GetWidth()/2, bitmap
.GetHeight()/2 );
231 bitmap
= wxBitmap(image
);
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
);
237 wxWindow
*win
= splash
->GetSplashWindow();
239 wxMediaCtrl
*media
= new wxMediaCtrl( win
, wxID_EXIT
, wxT("press.mpg"), wxPoint(2,2));
242 wxStaticText
*text
= new wxStaticText( win
,
244 wxT("click somewhere\non this image"),
245 wxPoint(m_isPda
? 0 : 13,
248 text
->SetBackgroundColour(*wxWHITE
);
249 text
->SetForegroundColour(*wxBLACK
);
250 wxFont font
= text
->GetFont();
251 font
.SetPointSize(2*font
.GetPointSize()/3);