]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/generic/splash.cpp
rtti api mods added
[wxWidgets.git] / src / generic / splash.cpp
... / ...
CommitLineData
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
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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
23#if wxUSE_SPLASH
24
25#ifndef WX_PRECOMP
26#include "wx/dcmemory.h"
27#include "wx/dcclient.h"
28#endif
29
30#include "wx/splash.h"
31
32/*
33 * wxSplashScreen
34 */
35
36#define wxSPLASH_TIMER_ID 9999
37
38IMPLEMENT_DYNAMIC_CLASS(wxSplashScreen, wxFrame);
39
40BEGIN_EVENT_TABLE(wxSplashScreen, wxFrame)
41 EVT_TIMER(wxSPLASH_TIMER_ID, wxSplashScreen::OnNotify)
42 EVT_CLOSE(wxSplashScreen::OnCloseWindow)
43END_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
50wxSplashScreen::wxSplashScreen(const wxBitmap& bitmap, long splashStyle, int milliseconds, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style):
51 wxFrame(parent, id, wxEmptyString, wxPoint(0, 0), wxSize(100, 100), style)
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
59 SetClientSize(bitmap.GetWidth(), bitmap.GetHeight());
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();
74#if defined( __WXMSW__ ) || defined(__WXMAC__)
75 Update(); // Without this, you see a blank screen for an instant
76#else
77 wxYieldIfNeeded(); // Should eliminate this
78#endif
79}
80
81wxSplashScreen::~wxSplashScreen()
82{
83 m_timer.Stop();
84}
85
86void wxSplashScreen::OnNotify(wxTimerEvent& WXUNUSED(event))
87{
88 Close(TRUE);
89}
90
91void wxSplashScreen::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
92{
93 m_timer.Stop();
94 this->Destroy();
95}
96
97/*
98 * wxSplashScreenWindow
99 */
100
101BEGIN_EVENT_TABLE(wxSplashScreenWindow, wxWindow)
102#ifdef __WXGTK__
103 EVT_PAINT(wxSplashScreenWindow::OnPaint)
104#endif
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;
114
115#if !defined(__WXGTK__) && wxUSE_PALETTE
116 bool hiColour = (wxDisplayDepth() >= 16) ;
117
118 if (bitmap.GetPalette() && !hiColour)
119 {
120 SetPalette(* bitmap.GetPalette());
121 }
122#endif
123
124}
125
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
131static void wxDrawSplashBitmap(wxDC& dc, const wxBitmap& bitmap, int WXUNUSED(x), int WXUNUSED(y))
132{
133 wxMemoryDC dcMem;
134
135#ifdef USE_PALETTE_IN_SPLASH
136 bool hiColour = (wxDisplayDepth() >= 16) ;
137
138 if (bitmap.GetPalette() && !hiColour)
139 {
140 dcMem.SetPalette(* bitmap.GetPalette());
141 }
142#endif // USE_PALETTE_IN_SPLASH
143
144 dcMem.SelectObject(bitmap);
145 dc.Blit(0, 0, bitmap.GetWidth(), bitmap.GetHeight(), & dcMem, 0, 0);
146 dcMem.SelectObject(wxNullBitmap);
147
148#ifdef USE_PALETTE_IN_SPLASH
149 if (bitmap.GetPalette() && !hiColour)
150 {
151 dcMem.SetPalette(wxNullPalette);
152 }
153#endif // USE_PALETTE_IN_SPLASH
154}
155
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
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
188void wxSplashScreenWindow::OnChar(wxKeyEvent& WXUNUSED(event))
189{
190 GetParent()->Close(TRUE);
191}
192
193#endif // wxUSE_SPLASH