]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: splash.cpp | |
3 | // Purpose: wxSplashScreen sample | |
4 | // Author: Wlodzimierz ABX Skiba | |
5 | // Modified by: | |
6 | // Created: 04/08/2004 | |
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" | |
34 | #include "wx/mediactrl.h" | |
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) | |
42 | #ifndef wxHAS_IMAGES_IN_RESOURCES | |
43 | #include "../sample.xpm" | |
44 | #endif | |
45 | ||
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 | ||
50 | // ---------------------------------------------------------------------------- | |
51 | // private classes | |
52 | // ---------------------------------------------------------------------------- | |
53 | ||
54 | // Define a new application type, each program should derive a class from wxApp | |
55 | class MyApp : public wxApp | |
56 | { | |
57 | public: | |
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 | |
68 | class MyFrame : public wxFrame | |
69 | { | |
70 | public: | |
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 | ||
78 | bool m_isPda; | |
79 | ||
80 | private: | |
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 | |
90 | enum | |
91 | { | |
92 | Minimal_Run = wxID_HIGHEST + 1 | |
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. | |
102 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
103 | EVT_MENU(wxID_EXIT, MyFrame::OnQuit) | |
104 | EVT_MENU(wxID_ABOUT, MyFrame::OnAbout) | |
105 | END_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) | |
112 | IMPLEMENT_APP(MyApp) | |
113 | ||
114 | // ============================================================================ | |
115 | // implementation | |
116 | // ============================================================================ | |
117 | ||
118 | // ---------------------------------------------------------------------------- | |
119 | // the application class | |
120 | // ---------------------------------------------------------------------------- | |
121 | ||
122 | // 'Main program' equivalent: the program execution "starts" here | |
123 | bool MyApp::OnInit() | |
124 | { | |
125 | if ( !wxApp::OnInit() ) | |
126 | return false; | |
127 | ||
128 | wxImage::AddHandler(new wxPNGHandler); | |
129 | ||
130 | // create the main application window | |
131 | MyFrame *frame = new MyFrame(wxT("wxSplashScreen sample application")); | |
132 | ||
133 | wxBitmap bitmap; | |
134 | ||
135 | if (frame->m_isPda) | |
136 | bitmap = wxBitmap(mobile_xpm); | |
137 | ||
138 | bool ok = frame->m_isPda | |
139 | ? bitmap.IsOk() | |
140 | : bitmap.LoadFile(wxT("splash.png"), wxBITMAP_TYPE_PNG); | |
141 | ||
142 | if (ok) | |
143 | { | |
144 | new wxSplashScreen(bitmap, | |
145 | wxSPLASH_CENTRE_ON_SCREEN|wxSPLASH_TIMEOUT, | |
146 | 6000, frame, wxID_ANY, wxDefaultPosition, wxDefaultSize, | |
147 | wxSIMPLE_BORDER|wxSTAY_ON_TOP); | |
148 | } | |
149 | ||
150 | #if !defined(__WXGTK20__) | |
151 | // we don't need it at least on wxGTK with GTK+ 2.12.9 | |
152 | wxYield(); | |
153 | #endif | |
154 | ||
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 | |
170 | MyFrame::MyFrame(const wxString& title) | |
171 | : wxFrame(NULL, wxID_ANY, title) | |
172 | { | |
173 | m_isPda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA); | |
174 | ||
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; | |
184 | helpMenu->Append(wxID_ABOUT, wxT("&About\tF1"), wxT("Show about frame")); | |
185 | ||
186 | menuFile->Append(wxID_EXIT, wxT("E&xit\tAlt-X"), wxT("Quit this program")); | |
187 | ||
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")); | |
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); | |
200 | SetStatusText(wxT("Welcome to wxWidgets!")); | |
201 | #endif // wxUSE_STATUSBAR | |
202 | } | |
203 | ||
204 | ||
205 | // event handlers | |
206 | ||
207 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) | |
208 | { | |
209 | // true is to force the frame to close | |
210 | Close(true); | |
211 | } | |
212 | ||
213 | void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) | |
214 | { | |
215 | wxBitmap bitmap; | |
216 | ||
217 | if (m_isPda) bitmap = wxBitmap(mobile_xpm); | |
218 | ||
219 | bool ok = m_isPda | |
220 | ? bitmap.IsOk() | |
221 | : bitmap.LoadFile(wxT("splash.png"), wxBITMAP_TYPE_PNG); | |
222 | ||
223 | if (ok) | |
224 | { | |
225 | wxImage image = bitmap.ConvertToImage(); | |
226 | ||
227 | // do not scale on already small screens | |
228 | if (!m_isPda) | |
229 | image.Rescale( bitmap.GetWidth()/2, bitmap.GetHeight()/2 ); | |
230 | ||
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); | |
236 | ||
237 | wxWindow *win = splash->GetSplashWindow(); | |
238 | #if wxUSE_MEDIACTRL | |
239 | wxMediaCtrl *media = new wxMediaCtrl( win, wxID_EXIT, wxT("press.mpg"), wxPoint(2,2)); | |
240 | media->Play(); | |
241 | #else | |
242 | wxStaticText *text = new wxStaticText( win, | |
243 | wxID_EXIT, | |
244 | wxT("click somewhere\non this image"), | |
245 | wxPoint(m_isPda ? 0 : 13, | |
246 | m_isPda ? 0 : 11) | |
247 | ); | |
248 | text->SetBackgroundColour(*wxWHITE); | |
249 | text->SetForegroundColour(*wxBLACK); | |
250 | wxFont font = text->GetFont(); | |
251 | font.SetPointSize(2*font.GetPointSize()/3); | |
252 | text->SetFont(font); | |
253 | #endif | |
254 | } | |
255 | } |