]>
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 | // 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" | |
35 | #include "wx/mediactrl.h" | |
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) | |
43 | #if !defined(__WXMSW__) && !defined(__WXPM__) | |
44 | #include "../sample.xpm" | |
45 | #endif | |
46 | ||
47 | // ---------------------------------------------------------------------------- | |
48 | // private classes | |
49 | // ---------------------------------------------------------------------------- | |
50 | ||
51 | // Define a new application type, each program should derive a class from wxApp | |
52 | class MyApp : public wxApp | |
53 | { | |
54 | public: | |
55 | // override base class virtuals | |
56 | // ---------------------------- | |
57 | ||
58 | // this one is called on application startup and is a good place for the app | |
59 | // initialization (doing it here and not in the ctor allows to have an error | |
60 | // return: if OnInit() returns false, the application terminates) | |
61 | virtual bool OnInit(); | |
62 | }; | |
63 | ||
64 | // Define a new frame type: this is going to be our main frame | |
65 | class MyFrame : public wxFrame | |
66 | { | |
67 | public: | |
68 | // ctor(s) | |
69 | MyFrame(const wxString& title); | |
70 | ||
71 | // event handlers (these functions should _not_ be virtual) | |
72 | void OnQuit(wxCommandEvent& event); | |
73 | void OnAbout(wxCommandEvent& event); | |
74 | ||
75 | private: | |
76 | // any class wishing to process wxWidgets events must use this macro | |
77 | DECLARE_EVENT_TABLE() | |
78 | }; | |
79 | ||
80 | // ---------------------------------------------------------------------------- | |
81 | // constants | |
82 | // ---------------------------------------------------------------------------- | |
83 | ||
84 | // IDs for the controls and the menu commands | |
85 | enum | |
86 | { | |
87 | Minimal_Run = wxID_HIGHEST + 1, | |
88 | }; | |
89 | ||
90 | // ---------------------------------------------------------------------------- | |
91 | // event tables and other macros for wxWidgets | |
92 | // ---------------------------------------------------------------------------- | |
93 | ||
94 | // the event tables connect the wxWidgets events with the functions (event | |
95 | // handlers) which process them. It can be also done at run-time, but for the | |
96 | // simple menu events like this the static method is much simpler. | |
97 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
98 | EVT_MENU(wxID_EXIT, MyFrame::OnQuit) | |
99 | EVT_MENU(wxID_ABOUT, MyFrame::OnAbout) | |
100 | END_EVENT_TABLE() | |
101 | ||
102 | // Create a new application object: this macro will allow wxWidgets to create | |
103 | // the application object during program execution (it's better than using a | |
104 | // static object for many reasons) and also implements the accessor function | |
105 | // wxGetApp() which will return the reference of the right type (i.e. MyApp and | |
106 | // not wxApp) | |
107 | IMPLEMENT_APP(MyApp) | |
108 | ||
109 | // ============================================================================ | |
110 | // implementation | |
111 | // ============================================================================ | |
112 | ||
113 | // ---------------------------------------------------------------------------- | |
114 | // the application class | |
115 | // ---------------------------------------------------------------------------- | |
116 | ||
117 | // 'Main program' equivalent: the program execution "starts" here | |
118 | bool MyApp::OnInit() | |
119 | { | |
120 | wxImage::AddHandler(new wxPNGHandler); | |
121 | ||
122 | // create the main application window | |
123 | MyFrame *frame = new MyFrame(_T("wxSplashScreen sample application")); | |
124 | ||
125 | wxBitmap bitmap; | |
126 | if (bitmap.LoadFile(_T("splash.png"), wxBITMAP_TYPE_PNG)) | |
127 | { | |
128 | new wxSplashScreen(bitmap, | |
129 | wxSPLASH_CENTRE_ON_SCREEN|wxSPLASH_TIMEOUT, | |
130 | 6000, frame, wxID_ANY, wxDefaultPosition, wxDefaultSize, | |
131 | wxSIMPLE_BORDER|wxSTAY_ON_TOP); | |
132 | } | |
133 | wxYield(); | |
134 | ||
135 | // and show it (the frames, unlike simple controls, are not shown when | |
136 | // created initially) | |
137 | frame->Show(true); | |
138 | ||
139 | // success: wxApp::OnRun() will be called which will enter the main message | |
140 | // loop and the application will run. If we returned false here, the | |
141 | // application would exit immediately. | |
142 | return true; | |
143 | } | |
144 | ||
145 | // ---------------------------------------------------------------------------- | |
146 | // main frame | |
147 | // ---------------------------------------------------------------------------- | |
148 | ||
149 | // frame constructor | |
150 | MyFrame::MyFrame(const wxString& title) | |
151 | : wxFrame(NULL, wxID_ANY, title) | |
152 | { | |
153 | // set the frame icon | |
154 | SetIcon(wxICON(sample)); | |
155 | ||
156 | #if wxUSE_MENUS | |
157 | // create a menu bar | |
158 | wxMenu *menuFile = new wxMenu; | |
159 | ||
160 | // the "About" item should be in the help menu | |
161 | wxMenu *helpMenu = new wxMenu; | |
162 | helpMenu->Append(wxID_ABOUT, _T("&About...\tF1"), _T("Show about frame")); | |
163 | ||
164 | menuFile->Append(wxID_EXIT, _T("E&xit\tAlt-X"), _T("Quit this program")); | |
165 | ||
166 | // now append the freshly created menu to the menu bar... | |
167 | wxMenuBar *menuBar = new wxMenuBar(); | |
168 | menuBar->Append(menuFile, _T("&File")); | |
169 | menuBar->Append(helpMenu, _T("&Help")); | |
170 | ||
171 | // ... and attach this menu bar to the frame | |
172 | SetMenuBar(menuBar); | |
173 | #endif // wxUSE_MENUS | |
174 | ||
175 | #if wxUSE_STATUSBAR | |
176 | // create a status bar just for fun (by default with 1 pane only) | |
177 | CreateStatusBar(2); | |
178 | SetStatusText(_T("Welcome to wxWidgets!")); | |
179 | #endif // wxUSE_STATUSBAR | |
180 | } | |
181 | ||
182 | ||
183 | // event handlers | |
184 | ||
185 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) | |
186 | { | |
187 | // true is to force the frame to close | |
188 | Close(true); | |
189 | } | |
190 | ||
191 | void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) | |
192 | { | |
193 | wxBitmap bitmap; | |
194 | if (bitmap.LoadFile(_T("splash.png"), wxBITMAP_TYPE_PNG)) | |
195 | { | |
196 | wxImage image = bitmap.ConvertToImage(); | |
197 | image.Rescale( bitmap.GetWidth()/2, bitmap.GetHeight()/2 ); | |
198 | bitmap = wxBitmap(image); | |
199 | wxSplashScreen *splash = new wxSplashScreen(bitmap, | |
200 | wxSPLASH_CENTRE_ON_PARENT | wxSPLASH_NO_TIMEOUT, | |
201 | 0, this, wxID_ANY, wxDefaultPosition, wxDefaultSize, | |
202 | wxSIMPLE_BORDER|wxSTAY_ON_TOP); | |
203 | wxWindow *win = splash->GetSplashWindow(); | |
204 | #if wxUSE_MEDIACTRL | |
205 | wxMediaCtrl *media = new wxMediaCtrl( win, wxID_EXIT, _T("press.mpg"), wxPoint(2,2)); | |
206 | media->Play(); | |
207 | #else | |
208 | wxStaticText *text = new wxStaticText( win, wxID_EXIT, _T("click somewhere\non image"), wxPoint(13,11) ); | |
209 | text->SetBackgroundColour(*wxWHITE); | |
210 | text->SetForegroundColour(*wxBLACK); | |
211 | wxFont font = text->GetFont(); | |
212 | font.SetPointSize(2*font.GetPointSize()/3); | |
213 | text->SetFont(font); | |
214 | #endif | |
215 | } | |
216 | } |