]> git.saurik.com Git - wxWidgets.git/blame - src/generic/splash.cpp
Patch from Jed Burgess that optionally allows the grid to notify when
[wxWidgets.git] / src / generic / splash.cpp
CommitLineData
3f4fc796
JS
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
65571936 9// Licence: wxWindows licence
3f4fc796
JS
10/////////////////////////////////////////////////////////////////////////////
11
14f355c2 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
3f4fc796
JS
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
1e6feb95
VZ
23#if wxUSE_SPLASH
24
231475bf
VS
25#ifdef __WXGTK20__
26 #include <gtk/gtk.h>
27#endif
28
3f4fc796 29#ifndef WX_PRECOMP
d84d25dd 30#include "wx/dcmemory.h"
aeb500e6 31#include "wx/dcclient.h"
3f4fc796
JS
32#endif
33
34#include "wx/splash.h"
35
231475bf 36
3f4fc796
JS
37/*
38 * wxSplashScreen
39 */
40
41#define wxSPLASH_TIMER_ID 9999
42
d1d2cd38
MB
43IMPLEMENT_DYNAMIC_CLASS(wxSplashScreen, wxFrame);
44
3f4fc796
JS
45BEGIN_EVENT_TABLE(wxSplashScreen, wxFrame)
46 EVT_TIMER(wxSPLASH_TIMER_ID, wxSplashScreen::OnNotify)
47 EVT_CLOSE(wxSplashScreen::OnCloseWindow)
48END_EVENT_TABLE()
49
97f1fb19
JS
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
3f4fc796 55wxSplashScreen::wxSplashScreen(const wxBitmap& bitmap, long splashStyle, int milliseconds, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style):
97f1fb19 56 wxFrame(parent, id, wxEmptyString, wxPoint(0, 0), wxSize(100, 100), style)
3f4fc796 57{
231475bf
VS
58#ifdef __WXGTK20__
59 gtk_window_set_type_hint(GTK_WINDOW(m_widget),
60 GDK_WINDOW_TYPE_HINT_SPLASHSCREEN);
61#endif
62
3f4fc796
JS
63 m_window = NULL;
64 m_splashStyle = splashStyle;
65 m_milliseconds = milliseconds;
66
ca65c044 67 m_window = new wxSplashScreenWindow(bitmap, this, wxID_ANY, pos, size, wxNO_BORDER);
3f4fc796 68
97f1fb19 69 SetClientSize(bitmap.GetWidth(), bitmap.GetHeight());
3f4fc796
JS
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);
ca65c044 79 m_timer.Start(milliseconds, true);
3f4fc796
JS
80 }
81
ca65c044 82 Show(true);
3f4fc796 83 m_window->SetFocus();
913ff1a7 84#if defined( __WXMSW__ ) || defined(__WXMAC__)
8d079279
JS
85 Update(); // Without this, you see a blank screen for an instant
86#else
87 wxYieldIfNeeded(); // Should eliminate this
88#endif
3f4fc796
JS
89}
90
91wxSplashScreen::~wxSplashScreen()
92{
93 m_timer.Stop();
94}
95
33ac7e6f 96void wxSplashScreen::OnNotify(wxTimerEvent& WXUNUSED(event))
3f4fc796 97{
ca65c044 98 Close(true);
3f4fc796
JS
99}
100
33ac7e6f 101void wxSplashScreen::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
3f4fc796
JS
102{
103 m_timer.Stop();
104 this->Destroy();
105}
106
107/*
108 * wxSplashScreenWindow
109 */
110
111BEGIN_EVENT_TABLE(wxSplashScreenWindow, wxWindow)
c2d516f2
RD
112#ifdef __WXGTK__
113 EVT_PAINT(wxSplashScreenWindow::OnPaint)
114#endif
3f4fc796
JS
115 EVT_ERASE_BACKGROUND(wxSplashScreenWindow::OnEraseBackground)
116 EVT_CHAR(wxSplashScreenWindow::OnChar)
117 EVT_MOUSE_EVENTS(wxSplashScreenWindow::OnMouseEvent)
118END_EVENT_TABLE()
119
120wxSplashScreenWindow::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;
574c939e 124
e3b7670b 125#if !defined(__WXGTK__) && wxUSE_PALETTE
574c939e
KB
126 bool hiColour = (wxDisplayDepth() >= 16) ;
127
128 if (bitmap.GetPalette() && !hiColour)
129 {
130 SetPalette(* bitmap.GetPalette());
131 }
132#endif
133
3f4fc796
JS
134}
135
e22c13fe
VZ
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
33ac7e6f 141static void wxDrawSplashBitmap(wxDC& dc, const wxBitmap& bitmap, int WXUNUSED(x), int WXUNUSED(y))
3f4fc796
JS
142{
143 wxMemoryDC dcMem;
144
e22c13fe 145#ifdef USE_PALETTE_IN_SPLASH
3f4fc796 146 bool hiColour = (wxDisplayDepth() >= 16) ;
33ac7e6f 147
3f4fc796
JS
148 if (bitmap.GetPalette() && !hiColour)
149 {
3f4fc796
JS
150 dcMem.SetPalette(* bitmap.GetPalette());
151 }
e22c13fe 152#endif // USE_PALETTE_IN_SPLASH
25093cf3 153
3f4fc796
JS
154 dcMem.SelectObject(bitmap);
155 dc.Blit(0, 0, bitmap.GetWidth(), bitmap.GetHeight(), & dcMem, 0, 0);
156 dcMem.SelectObject(wxNullBitmap);
25093cf3 157
e22c13fe 158#ifdef USE_PALETTE_IN_SPLASH
3f4fc796
JS
159 if (bitmap.GetPalette() && !hiColour)
160 {
3f4fc796
JS
161 dcMem.SetPalette(wxNullPalette);
162 }
e22c13fe 163#endif // USE_PALETTE_IN_SPLASH
3f4fc796
JS
164}
165
c2d516f2
RD
166void wxSplashScreenWindow::OnPaint(wxPaintEvent& WXUNUSED(event))
167{
168 wxPaintDC dc(this);
169 if (m_bitmap.Ok())
170 wxDrawSplashBitmap(dc, m_bitmap, 0, 0);
171}
172
3f4fc796
JS
173void 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
192void wxSplashScreenWindow::OnMouseEvent(wxMouseEvent& event)
193{
194 if (event.LeftDown() || event.RightDown())
ca65c044 195 GetParent()->Close(true);
3f4fc796
JS
196}
197
33ac7e6f 198void wxSplashScreenWindow::OnChar(wxKeyEvent& WXUNUSED(event))
3f4fc796 199{
ca65c044 200 GetParent()->Close(true);
3f4fc796
JS
201}
202
1e6feb95 203#endif // wxUSE_SPLASH