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