]> git.saurik.com Git - wxWidgets.git/blob - src/generic/splash.cpp
fixed typo
[wxWidgets.git] / src / generic / splash.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: splash.cpp
3 // Purpose: wxSplashScreen class
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 28/6/2000
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "splash.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #if wxUSE_SPLASH
24
25 #ifdef __WXGTK20__
26 #include <gtk/gtk.h>
27 #endif
28
29 #ifndef WX_PRECOMP
30 #include "wx/dcmemory.h"
31 #include "wx/dcclient.h"
32 #endif
33
34 #include "wx/splash.h"
35
36
37 /*
38 * wxSplashScreen
39 */
40
41 #define wxSPLASH_TIMER_ID 9999
42
43 IMPLEMENT_DYNAMIC_CLASS(wxSplashScreen, wxFrame);
44
45 BEGIN_EVENT_TABLE(wxSplashScreen, wxFrame)
46 EVT_TIMER(wxSPLASH_TIMER_ID, wxSplashScreen::OnNotify)
47 EVT_CLOSE(wxSplashScreen::OnCloseWindow)
48 END_EVENT_TABLE()
49
50 /* Note that unless we pass a non-default size to the frame, SetClientSize
51 * won't work properly under Windows, and the splash screen frame is sized
52 * slightly too small.
53 */
54
55 wxSplashScreen::wxSplashScreen(const wxBitmap& bitmap, long splashStyle, int milliseconds, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style):
56 wxFrame(parent, id, wxEmptyString, wxPoint(0, 0), wxSize(100, 100), style)
57 {
58 #ifdef __WXGTK20__
59 gtk_window_set_type_hint(GTK_WINDOW(m_widget),
60 GDK_WINDOW_TYPE_HINT_SPLASHSCREEN);
61 #endif
62
63 m_window = NULL;
64 m_splashStyle = splashStyle;
65 m_milliseconds = milliseconds;
66
67 m_window = new wxSplashScreenWindow(bitmap, this, wxID_ANY, pos, size, wxNO_BORDER);
68
69 SetClientSize(bitmap.GetWidth(), bitmap.GetHeight());
70
71 if (m_splashStyle & wxSPLASH_CENTRE_ON_PARENT)
72 CentreOnParent();
73 else if (m_splashStyle & wxSPLASH_CENTRE_ON_SCREEN)
74 CentreOnScreen();
75
76 if (m_splashStyle & wxSPLASH_TIMEOUT)
77 {
78 m_timer.SetOwner(this, wxSPLASH_TIMER_ID);
79 m_timer.Start(milliseconds, true);
80 }
81
82 Show(true);
83 m_window->SetFocus();
84 #if defined( __WXMSW__ ) || defined(__WXMAC__)
85 Update(); // Without this, you see a blank screen for an instant
86 #else
87 wxYieldIfNeeded(); // Should eliminate this
88 #endif
89 }
90
91 wxSplashScreen::~wxSplashScreen()
92 {
93 m_timer.Stop();
94 }
95
96 void wxSplashScreen::OnNotify(wxTimerEvent& WXUNUSED(event))
97 {
98 Close(true);
99 }
100
101 void wxSplashScreen::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
102 {
103 m_timer.Stop();
104 this->Destroy();
105 }
106
107 /*
108 * wxSplashScreenWindow
109 */
110
111 BEGIN_EVENT_TABLE(wxSplashScreenWindow, wxWindow)
112 #ifdef __WXGTK__
113 EVT_PAINT(wxSplashScreenWindow::OnPaint)
114 #endif
115 EVT_ERASE_BACKGROUND(wxSplashScreenWindow::OnEraseBackground)
116 EVT_CHAR(wxSplashScreenWindow::OnChar)
117 EVT_MOUSE_EVENTS(wxSplashScreenWindow::OnMouseEvent)
118 END_EVENT_TABLE()
119
120 wxSplashScreenWindow::wxSplashScreenWindow(const wxBitmap& bitmap, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style):
121 wxWindow(parent, id, pos, size, style)
122 {
123 m_bitmap = bitmap;
124
125 #if !defined(__WXGTK__) && wxUSE_PALETTE
126 bool hiColour = (wxDisplayDepth() >= 16) ;
127
128 if (bitmap.GetPalette() && !hiColour)
129 {
130 SetPalette(* bitmap.GetPalette());
131 }
132 #endif
133
134 }
135
136 // VZ: why don't we do it under wxGTK?
137 #if !defined(__WXGTK__) && wxUSE_PALETTE
138 #define USE_PALETTE_IN_SPLASH
139 #endif
140
141 static void wxDrawSplashBitmap(wxDC& dc, const wxBitmap& bitmap, int WXUNUSED(x), int WXUNUSED(y))
142 {
143 wxMemoryDC dcMem;
144
145 #ifdef USE_PALETTE_IN_SPLASH
146 bool hiColour = (wxDisplayDepth() >= 16) ;
147
148 if (bitmap.GetPalette() && !hiColour)
149 {
150 dcMem.SetPalette(* bitmap.GetPalette());
151 }
152 #endif // USE_PALETTE_IN_SPLASH
153
154 dcMem.SelectObject(bitmap);
155 dc.Blit(0, 0, bitmap.GetWidth(), bitmap.GetHeight(), & dcMem, 0, 0);
156 dcMem.SelectObject(wxNullBitmap);
157
158 #ifdef USE_PALETTE_IN_SPLASH
159 if (bitmap.GetPalette() && !hiColour)
160 {
161 dcMem.SetPalette(wxNullPalette);
162 }
163 #endif // USE_PALETTE_IN_SPLASH
164 }
165
166 void wxSplashScreenWindow::OnPaint(wxPaintEvent& WXUNUSED(event))
167 {
168 wxPaintDC dc(this);
169 if (m_bitmap.Ok())
170 wxDrawSplashBitmap(dc, m_bitmap, 0, 0);
171 }
172
173 void wxSplashScreenWindow::OnEraseBackground(wxEraseEvent& event)
174 {
175 if (event.GetDC())
176 {
177 if (m_bitmap.Ok())
178 {
179 wxDrawSplashBitmap(* event.GetDC(), m_bitmap, 0, 0);
180 }
181 }
182 else
183 {
184 wxClientDC dc(this);
185 if (m_bitmap.Ok())
186 {
187 wxDrawSplashBitmap(dc, m_bitmap, 0, 0);
188 }
189 }
190 }
191
192 void wxSplashScreenWindow::OnMouseEvent(wxMouseEvent& event)
193 {
194 if (event.LeftDown() || event.RightDown())
195 GetParent()->Close(true);
196 }
197
198 void wxSplashScreenWindow::OnChar(wxKeyEvent& WXUNUSED(event))
199 {
200 GetParent()->Close(true);
201 }
202
203 #endif // wxUSE_SPLASH