]> git.saurik.com Git - wxWidgets.git/blame - src/generic/splash.cpp
showing a bevel button for a multiline label (is not multline on the OS level, but...
[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
04dbb646 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
3f4fc796 25#ifndef WX_PRECOMP
d84d25dd 26#include "wx/dcmemory.h"
aeb500e6 27#include "wx/dcclient.h"
3f4fc796
JS
28#endif
29
30#include "wx/splash.h"
31
32/*
33 * wxSplashScreen
34 */
35
36#define wxSPLASH_TIMER_ID 9999
37
d1d2cd38
MB
38IMPLEMENT_DYNAMIC_CLASS(wxSplashScreen, wxFrame);
39
3f4fc796
JS
40BEGIN_EVENT_TABLE(wxSplashScreen, wxFrame)
41 EVT_TIMER(wxSPLASH_TIMER_ID, wxSplashScreen::OnNotify)
42 EVT_CLOSE(wxSplashScreen::OnCloseWindow)
43END_EVENT_TABLE()
44
97f1fb19
JS
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
3f4fc796 50wxSplashScreen::wxSplashScreen(const wxBitmap& bitmap, long splashStyle, int milliseconds, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style):
97f1fb19 51 wxFrame(parent, id, wxEmptyString, wxPoint(0, 0), wxSize(100, 100), style)
3f4fc796
JS
52{
53 m_window = NULL;
54 m_splashStyle = splashStyle;
55 m_milliseconds = milliseconds;
56
57 m_window = new wxSplashScreenWindow(bitmap, this, -1, pos, size, wxNO_BORDER);
58
97f1fb19 59 SetClientSize(bitmap.GetWidth(), bitmap.GetHeight());
3f4fc796
JS
60
61 if (m_splashStyle & wxSPLASH_CENTRE_ON_PARENT)
62 CentreOnParent();
63 else if (m_splashStyle & wxSPLASH_CENTRE_ON_SCREEN)
64 CentreOnScreen();
65
66 if (m_splashStyle & wxSPLASH_TIMEOUT)
67 {
68 m_timer.SetOwner(this, wxSPLASH_TIMER_ID);
69 m_timer.Start(milliseconds, TRUE);
70 }
71
72 Show(TRUE);
73 m_window->SetFocus();
913ff1a7 74#if defined( __WXMSW__ ) || defined(__WXMAC__)
8d079279
JS
75 Update(); // Without this, you see a blank screen for an instant
76#else
77 wxYieldIfNeeded(); // Should eliminate this
78#endif
3f4fc796
JS
79}
80
81wxSplashScreen::~wxSplashScreen()
82{
83 m_timer.Stop();
84}
85
33ac7e6f 86void wxSplashScreen::OnNotify(wxTimerEvent& WXUNUSED(event))
3f4fc796 87{
e1437298 88 Close(TRUE);
3f4fc796
JS
89}
90
33ac7e6f 91void wxSplashScreen::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
3f4fc796
JS
92{
93 m_timer.Stop();
94 this->Destroy();
95}
96
97/*
98 * wxSplashScreenWindow
99 */
100
101BEGIN_EVENT_TABLE(wxSplashScreenWindow, wxWindow)
c2d516f2
RD
102#ifdef __WXGTK__
103 EVT_PAINT(wxSplashScreenWindow::OnPaint)
104#endif
3f4fc796
JS
105 EVT_ERASE_BACKGROUND(wxSplashScreenWindow::OnEraseBackground)
106 EVT_CHAR(wxSplashScreenWindow::OnChar)
107 EVT_MOUSE_EVENTS(wxSplashScreenWindow::OnMouseEvent)
108END_EVENT_TABLE()
109
110wxSplashScreenWindow::wxSplashScreenWindow(const wxBitmap& bitmap, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style):
111 wxWindow(parent, id, pos, size, style)
112{
113 m_bitmap = bitmap;
574c939e 114
e3b7670b 115#if !defined(__WXGTK__) && wxUSE_PALETTE
574c939e
KB
116 bool hiColour = (wxDisplayDepth() >= 16) ;
117
118 if (bitmap.GetPalette() && !hiColour)
119 {
120 SetPalette(* bitmap.GetPalette());
121 }
122#endif
123
3f4fc796
JS
124}
125
e22c13fe
VZ
126// VZ: why don't we do it under wxGTK?
127#if !defined(__WXGTK__) && wxUSE_PALETTE
128 #define USE_PALETTE_IN_SPLASH
129#endif
130
33ac7e6f 131static void wxDrawSplashBitmap(wxDC& dc, const wxBitmap& bitmap, int WXUNUSED(x), int WXUNUSED(y))
3f4fc796
JS
132{
133 wxMemoryDC dcMem;
134
e22c13fe 135#ifdef USE_PALETTE_IN_SPLASH
3f4fc796 136 bool hiColour = (wxDisplayDepth() >= 16) ;
33ac7e6f 137
3f4fc796
JS
138 if (bitmap.GetPalette() && !hiColour)
139 {
3f4fc796
JS
140 dcMem.SetPalette(* bitmap.GetPalette());
141 }
e22c13fe 142#endif // USE_PALETTE_IN_SPLASH
25093cf3 143
3f4fc796
JS
144 dcMem.SelectObject(bitmap);
145 dc.Blit(0, 0, bitmap.GetWidth(), bitmap.GetHeight(), & dcMem, 0, 0);
146 dcMem.SelectObject(wxNullBitmap);
25093cf3 147
e22c13fe 148#ifdef USE_PALETTE_IN_SPLASH
3f4fc796
JS
149 if (bitmap.GetPalette() && !hiColour)
150 {
3f4fc796
JS
151 dcMem.SetPalette(wxNullPalette);
152 }
e22c13fe 153#endif // USE_PALETTE_IN_SPLASH
3f4fc796
JS
154}
155
c2d516f2
RD
156void wxSplashScreenWindow::OnPaint(wxPaintEvent& WXUNUSED(event))
157{
158 wxPaintDC dc(this);
159 if (m_bitmap.Ok())
160 wxDrawSplashBitmap(dc, m_bitmap, 0, 0);
161}
162
3f4fc796
JS
163void wxSplashScreenWindow::OnEraseBackground(wxEraseEvent& event)
164{
165 if (event.GetDC())
166 {
167 if (m_bitmap.Ok())
168 {
169 wxDrawSplashBitmap(* event.GetDC(), m_bitmap, 0, 0);
170 }
171 }
172 else
173 {
174 wxClientDC dc(this);
175 if (m_bitmap.Ok())
176 {
177 wxDrawSplashBitmap(dc, m_bitmap, 0, 0);
178 }
179 }
180}
181
182void wxSplashScreenWindow::OnMouseEvent(wxMouseEvent& event)
183{
184 if (event.LeftDown() || event.RightDown())
185 GetParent()->Close(TRUE);
186}
187
33ac7e6f 188void wxSplashScreenWindow::OnChar(wxKeyEvent& WXUNUSED(event))
3f4fc796
JS
189{
190 GetParent()->Close(TRUE);
191}
192
1e6feb95 193#endif // wxUSE_SPLASH