1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/splash.cpp
3 // Purpose: wxSplashScreen class
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx/wx.h".
12 #include "wx/wxprec.h"
24 #include "wx/splash.h"
27 #include "wx/dcmemory.h"
28 #include "wx/dcclient.h"
32 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
36 #define wxSPLASH_TIMER_ID 9999
38 IMPLEMENT_DYNAMIC_CLASS(wxSplashScreen
, wxFrame
)
39 BEGIN_EVENT_TABLE(wxSplashScreen
, wxFrame
)
40 EVT_TIMER(wxSPLASH_TIMER_ID
, wxSplashScreen::OnNotify
)
41 EVT_CLOSE(wxSplashScreen::OnCloseWindow
)
44 void wxSplashScreen::Init()
48 wxEvtHandler::AddFilter(this);
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
56 wxSplashScreen::wxSplashScreen(const wxBitmap
& bitmap
, long splashStyle
, int milliseconds
,
57 wxWindow
* parent
, wxWindowID id
, const wxPoint
& pos
,
58 const wxSize
& size
, long style
)
59 : wxFrame(parent
, id
, wxEmptyString
, wxPoint(0,0), wxSize(100, 100),
60 style
| wxFRAME_TOOL_WINDOW
| wxFRAME_NO_TASKBAR
)
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
);
68 #if defined(__WXGTK20__)
69 gtk_window_set_type_hint(GTK_WINDOW(m_widget
),
70 GDK_WINDOW_TYPE_HINT_SPLASHSCREEN
);
73 m_splashStyle
= splashStyle
;
74 m_milliseconds
= milliseconds
;
76 m_window
= new wxSplashScreenWindow(bitmap
, this, wxID_ANY
, pos
, size
, wxNO_BORDER
);
78 SetClientSize(bitmap
.GetWidth(), bitmap
.GetHeight());
80 if (m_splashStyle
& wxSPLASH_CENTRE_ON_PARENT
)
82 else if (m_splashStyle
& wxSPLASH_CENTRE_ON_SCREEN
)
85 if (m_splashStyle
& wxSPLASH_TIMEOUT
)
87 m_timer
.SetOwner(this, wxSPLASH_TIMER_ID
);
88 m_timer
.Start(milliseconds
, true);
93 #if defined( __WXMSW__ ) || defined(__WXMAC__)
94 Update(); // Without this, you see a blank screen for an instant
95 #elif defined(__WXGTK20__)
96 // we don't need to do anything at least on wxGTK with GTK+ 2.12.9
98 wxYieldIfNeeded(); // Should eliminate this
102 wxSplashScreen::~wxSplashScreen()
106 wxEvtHandler::RemoveFilter(this);
109 int wxSplashScreen::FilterEvent(wxEvent
& event
)
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
)
121 void wxSplashScreen::OnNotify(wxTimerEvent
& WXUNUSED(event
))
126 void wxSplashScreen::OnCloseWindow(wxCloseEvent
& WXUNUSED(event
))
132 // ----------------------------------------------------------------------------
133 // wxSplashScreenWindow
134 // ----------------------------------------------------------------------------
136 BEGIN_EVENT_TABLE(wxSplashScreenWindow
, wxWindow
)
138 EVT_PAINT(wxSplashScreenWindow::OnPaint
)
140 EVT_ERASE_BACKGROUND(wxSplashScreenWindow::OnEraseBackground
)
143 wxSplashScreenWindow::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
)
150 #if !defined(__WXGTK__) && wxUSE_PALETTE
151 bool hiColour
= (wxDisplayDepth() >= 16) ;
153 if (bitmap
.GetPalette() && !hiColour
)
155 SetPalette(* bitmap
.GetPalette());
160 // VZ: why don't we do it under wxGTK?
161 #if !defined(__WXGTK__) && wxUSE_PALETTE
162 #define USE_PALETTE_IN_SPLASH
165 static void wxDrawSplashBitmap(wxDC
& dc
, const wxBitmap
& bitmap
, int WXUNUSED(x
), int WXUNUSED(y
))
169 #ifdef USE_PALETTE_IN_SPLASH
170 bool hiColour
= (wxDisplayDepth() >= 16) ;
172 if (bitmap
.GetPalette() && !hiColour
)
174 dcMem
.SetPalette(* bitmap
.GetPalette());
176 #endif // USE_PALETTE_IN_SPLASH
178 dcMem
.SelectObjectAsSource(bitmap
);
179 dc
.Blit(0, 0, bitmap
.GetWidth(), bitmap
.GetHeight(), &dcMem
, 0, 0, wxCOPY
,
180 true /* use mask */);
181 dcMem
.SelectObject(wxNullBitmap
);
183 #ifdef USE_PALETTE_IN_SPLASH
184 if (bitmap
.GetPalette() && !hiColour
)
186 dcMem
.SetPalette(wxNullPalette
);
188 #endif // USE_PALETTE_IN_SPLASH
191 void wxSplashScreenWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
195 wxDrawSplashBitmap(dc
, m_bitmap
, 0, 0);
198 void wxSplashScreenWindow::OnEraseBackground(wxEraseEvent
& event
)
200 if (event
.GetDC() && m_bitmap
.IsOk())
202 wxDrawSplashBitmap(* event
.GetDC(), m_bitmap
, 0, 0);
208 wxDrawSplashBitmap(dc
, m_bitmap
, 0, 0);
212 #endif // wxUSE_SPLASH