]> git.saurik.com Git - wxWidgets.git/blame - src/generic/splash.cpp
Add wxAnyScrollHelperBase to reduce code duplication in wxVarScrollHelperBase.
[wxWidgets.git] / src / generic / splash.cpp
CommitLineData
3f4fc796 1/////////////////////////////////////////////////////////////////////////////
ed4b0fdc 2// Name: src/generic/splash.cpp
3f4fc796
JS
3// Purpose: wxSplashScreen class
4// Author: Julian Smart
5// Modified by:
6// Created: 28/6/2000
3f4fc796 7// Copyright: (c) Julian Smart
65571936 8// Licence: wxWindows licence
3f4fc796
JS
9/////////////////////////////////////////////////////////////////////////////
10
3f4fc796
JS
11// For compilers that support precompilation, includes "wx/wx.h".
12#include "wx/wxprec.h"
13
14#ifdef __BORLANDC__
ed4b0fdc 15 #pragma hdrstop
3f4fc796
JS
16#endif
17
1e6feb95
VZ
18#if wxUSE_SPLASH
19
231475bf
VS
20#ifdef __WXGTK20__
21 #include <gtk/gtk.h>
22#endif
23
3f4fc796
JS
24#include "wx/splash.h"
25
ed4b0fdc
WS
26#ifndef WX_PRECOMP
27 #include "wx/dcmemory.h"
28 #include "wx/dcclient.h"
29#endif
231475bf 30
3f4fc796 31
aac39d1d
FM
32// ----------------------------------------------------------------------------
33// wxSplashScreen
34// ----------------------------------------------------------------------------
3f4fc796 35
aac39d1d 36#define wxSPLASH_TIMER_ID 9999
d1d2cd38 37
aac39d1d 38IMPLEMENT_DYNAMIC_CLASS(wxSplashScreen, wxFrame)
3f4fc796
JS
39BEGIN_EVENT_TABLE(wxSplashScreen, wxFrame)
40 EVT_TIMER(wxSPLASH_TIMER_ID, wxSplashScreen::OnNotify)
41 EVT_CLOSE(wxSplashScreen::OnCloseWindow)
42END_EVENT_TABLE()
43
6e043ba9
VZ
44void wxSplashScreen::Init()
45{
46 m_window = NULL;
47
48 wxEvtHandler::AddFilter(this);
49}
50
97f1fb19
JS
51/* Note that unless we pass a non-default size to the frame, SetClientSize
52 * won't work properly under Windows, and the splash screen frame is sized
53 * slightly too small.
54 */
55
aac39d1d
FM
56wxSplashScreen::wxSplashScreen(const wxBitmap& bitmap, long splashStyle, int milliseconds,
57 wxWindow* parent, wxWindowID id, const wxPoint& pos,
58 const wxSize& size, long style)
7650eed4
VZ
59 : wxFrame(parent, id, wxEmptyString, wxPoint(0,0), wxSize(100, 100),
60 style | wxFRAME_TOOL_WINDOW | wxFRAME_NO_TASKBAR)
3f4fc796 61{
6e043ba9
VZ
62 Init();
63
889e7422
VZ
64 // splash screen must not be used as parent by the other windows because it
65 // is going to disappear soon, indicate it by giving it this special style
66 SetExtraStyle(GetExtraStyle() | wxWS_EX_TRANSIENT);
67
95561814 68#if defined(__WXGTK20__)
231475bf
VS
69 gtk_window_set_type_hint(GTK_WINDOW(m_widget),
70 GDK_WINDOW_TYPE_HINT_SPLASHSCREEN);
71#endif
2997ca30 72
3f4fc796
JS
73 m_splashStyle = splashStyle;
74 m_milliseconds = milliseconds;
75
ca65c044 76 m_window = new wxSplashScreenWindow(bitmap, this, wxID_ANY, pos, size, wxNO_BORDER);
3f4fc796 77
97f1fb19 78 SetClientSize(bitmap.GetWidth(), bitmap.GetHeight());
3f4fc796
JS
79
80 if (m_splashStyle & wxSPLASH_CENTRE_ON_PARENT)
81 CentreOnParent();
82 else if (m_splashStyle & wxSPLASH_CENTRE_ON_SCREEN)
83 CentreOnScreen();
84
85 if (m_splashStyle & wxSPLASH_TIMEOUT)
86 {
87 m_timer.SetOwner(this, wxSPLASH_TIMER_ID);
ca65c044 88 m_timer.Start(milliseconds, true);
3f4fc796
JS
89 }
90
ca65c044 91 Show(true);
3f4fc796 92 m_window->SetFocus();
913ff1a7 93#if defined( __WXMSW__ ) || defined(__WXMAC__)
8d079279 94 Update(); // Without this, you see a blank screen for an instant
aac39d1d
FM
95#elif defined(__WXGTK20__)
96 // we don't need to do anything at least on wxGTK with GTK+ 2.12.9
8d079279
JS
97#else
98 wxYieldIfNeeded(); // Should eliminate this
99#endif
3f4fc796
JS
100}
101
102wxSplashScreen::~wxSplashScreen()
103{
104 m_timer.Stop();
6e043ba9
VZ
105
106 wxEvtHandler::RemoveFilter(this);
107}
108
109int wxSplashScreen::FilterEvent(wxEvent& event)
110{
111 const wxEventType t = event.GetEventType();
112 if ( t == wxEVT_KEY_DOWN ||
113 t == wxEVT_LEFT_DOWN ||
114 t == wxEVT_RIGHT_DOWN ||
115 t == wxEVT_MIDDLE_DOWN )
116 Close(true);
117
118 return -1;
3f4fc796
JS
119}
120
33ac7e6f 121void wxSplashScreen::OnNotify(wxTimerEvent& WXUNUSED(event))
3f4fc796 122{
ca65c044 123 Close(true);
3f4fc796
JS
124}
125
33ac7e6f 126void wxSplashScreen::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
3f4fc796
JS
127{
128 m_timer.Stop();
129 this->Destroy();
130}
131
aac39d1d
FM
132// ----------------------------------------------------------------------------
133// wxSplashScreenWindow
134// ----------------------------------------------------------------------------
3f4fc796
JS
135
136BEGIN_EVENT_TABLE(wxSplashScreenWindow, wxWindow)
c2d516f2
RD
137#ifdef __WXGTK__
138 EVT_PAINT(wxSplashScreenWindow::OnPaint)
139#endif
3f4fc796 140 EVT_ERASE_BACKGROUND(wxSplashScreenWindow::OnEraseBackground)
3f4fc796
JS
141END_EVENT_TABLE()
142
aac39d1d
FM
143wxSplashScreenWindow::wxSplashScreenWindow(const wxBitmap& bitmap, wxWindow* parent,
144 wxWindowID id, const wxPoint& pos,
145 const wxSize& size, long style)
146 : wxWindow(parent, id, pos, size, style)
3f4fc796
JS
147{
148 m_bitmap = bitmap;
574c939e 149
e3b7670b 150#if !defined(__WXGTK__) && wxUSE_PALETTE
574c939e
KB
151 bool hiColour = (wxDisplayDepth() >= 16) ;
152
153 if (bitmap.GetPalette() && !hiColour)
154 {
155 SetPalette(* bitmap.GetPalette());
156 }
157#endif
3f4fc796
JS
158}
159
e22c13fe
VZ
160// VZ: why don't we do it under wxGTK?
161#if !defined(__WXGTK__) && wxUSE_PALETTE
162 #define USE_PALETTE_IN_SPLASH
163#endif
164
33ac7e6f 165static void wxDrawSplashBitmap(wxDC& dc, const wxBitmap& bitmap, int WXUNUSED(x), int WXUNUSED(y))
3f4fc796
JS
166{
167 wxMemoryDC dcMem;
168
e22c13fe 169#ifdef USE_PALETTE_IN_SPLASH
3f4fc796 170 bool hiColour = (wxDisplayDepth() >= 16) ;
33ac7e6f 171
3f4fc796
JS
172 if (bitmap.GetPalette() && !hiColour)
173 {
3f4fc796
JS
174 dcMem.SetPalette(* bitmap.GetPalette());
175 }
e22c13fe 176#endif // USE_PALETTE_IN_SPLASH
25093cf3 177
fea35690 178 dcMem.SelectObjectAsSource(bitmap);
deb8254e
VZ
179 dc.Blit(0, 0, bitmap.GetWidth(), bitmap.GetHeight(), &dcMem, 0, 0, wxCOPY,
180 true /* use mask */);
3f4fc796 181 dcMem.SelectObject(wxNullBitmap);
25093cf3 182
e22c13fe 183#ifdef USE_PALETTE_IN_SPLASH
3f4fc796
JS
184 if (bitmap.GetPalette() && !hiColour)
185 {
3f4fc796
JS
186 dcMem.SetPalette(wxNullPalette);
187 }
e22c13fe 188#endif // USE_PALETTE_IN_SPLASH
3f4fc796
JS
189}
190
c2d516f2
RD
191void wxSplashScreenWindow::OnPaint(wxPaintEvent& WXUNUSED(event))
192{
193 wxPaintDC dc(this);
a1b806b9 194 if (m_bitmap.IsOk())
c2d516f2
RD
195 wxDrawSplashBitmap(dc, m_bitmap, 0, 0);
196}
197
3f4fc796
JS
198void wxSplashScreenWindow::OnEraseBackground(wxEraseEvent& event)
199{
a1b806b9 200 if (event.GetDC() && m_bitmap.IsOk())
3f4fc796 201 {
aac39d1d 202 wxDrawSplashBitmap(* event.GetDC(), m_bitmap, 0, 0);
3f4fc796
JS
203 }
204 else
205 {
206 wxClientDC dc(this);
a1b806b9 207 if (m_bitmap.IsOk())
3f4fc796 208 wxDrawSplashBitmap(dc, m_bitmap, 0, 0);
3f4fc796
JS
209 }
210}
211
1e6feb95 212#endif // wxUSE_SPLASH