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