]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/generic/splash.cpp
corrected CodeWarrior project target names and generated application names
[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#ifdef __GNUG__
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#endif
28
29#include "wx/splash.h"
30
31/*
32 * wxSplashScreen
33 */
34
35#define wxSPLASH_TIMER_ID 9999
36
37BEGIN_EVENT_TABLE(wxSplashScreen, wxFrame)
38 EVT_TIMER(wxSPLASH_TIMER_ID, wxSplashScreen::OnNotify)
39 EVT_CLOSE(wxSplashScreen::OnCloseWindow)
40END_EVENT_TABLE()
41
42wxSplashScreen::wxSplashScreen(const wxBitmap& bitmap, long splashStyle, int milliseconds, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style):
43 wxFrame(parent, id, wxEmptyString, pos, size, style)
44{
45 m_window = NULL;
46 m_splashStyle = splashStyle;
47 m_milliseconds = milliseconds;
48
49 m_window = new wxSplashScreenWindow(bitmap, this, -1, pos, size, wxNO_BORDER);
50
51 // For some reason, we need to make the client size a couple of pixels
52 // bigger for all of the bitmap to show.
53 // Or do we?
54#ifdef __WXMSW__
55 int fudge = 0;
56#else
57 int fudge = 0;
58#endif
59 SetClientSize(bitmap.GetWidth()+fudge, bitmap.GetHeight()+fudge);
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 wxYield(); // Without this, you see a blank screen for an instant
75}
76
77wxSplashScreen::~wxSplashScreen()
78{
79 m_timer.Stop();
80}
81
82void wxSplashScreen::OnNotify(wxTimerEvent& WXUNUSED(event))
83{
84 Close(TRUE);
85}
86
87void wxSplashScreen::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
88{
89 m_timer.Stop();
90 this->Destroy();
91}
92
93/*
94 * wxSplashScreenWindow
95 */
96
97BEGIN_EVENT_TABLE(wxSplashScreenWindow, wxWindow)
98 //EVT_PAINT(wxSplashScreenWindow::OnPaint)
99 EVT_ERASE_BACKGROUND(wxSplashScreenWindow::OnEraseBackground)
100 EVT_CHAR(wxSplashScreenWindow::OnChar)
101 EVT_MOUSE_EVENTS(wxSplashScreenWindow::OnMouseEvent)
102END_EVENT_TABLE()
103
104wxSplashScreenWindow::wxSplashScreenWindow(const wxBitmap& bitmap, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style):
105 wxWindow(parent, id, pos, size, style)
106{
107 m_bitmap = bitmap;
108}
109
110void wxSplashScreenWindow::OnPaint(wxPaintEvent& WXUNUSED(event))
111{
112 wxPaintDC dc(this);
113 if (m_bitmap.Ok())
114 dc.DrawBitmap(m_bitmap, 0, 0);
115}
116
117static void wxDrawSplashBitmap(wxDC& dc, const wxBitmap& bitmap, int WXUNUSED(x), int WXUNUSED(y))
118{
119 wxMemoryDC dcMem;
120
121#ifndef __WXGTK__
122 bool hiColour = (wxDisplayDepth() >= 16) ;
123
124 if (bitmap.GetPalette() && !hiColour)
125 {
126 dc.SetPalette(* bitmap.GetPalette());
127 dcMem.SetPalette(* bitmap.GetPalette());
128 }
129#endif
130
131 dcMem.SelectObject(bitmap);
132 dc.Blit(0, 0, bitmap.GetWidth(), bitmap.GetHeight(), & dcMem, 0, 0);
133 dcMem.SelectObject(wxNullBitmap);
134
135#ifndef __WXGTK__
136 if (bitmap.GetPalette() && !hiColour)
137 {
138 dc.SetPalette(wxNullPalette);
139 dcMem.SetPalette(wxNullPalette);
140 }
141#endif
142}
143
144void wxSplashScreenWindow::OnEraseBackground(wxEraseEvent& event)
145{
146 if (event.GetDC())
147 {
148 if (m_bitmap.Ok())
149 {
150 wxDrawSplashBitmap(* event.GetDC(), m_bitmap, 0, 0);
151 }
152 }
153 else
154 {
155 wxClientDC dc(this);
156 if (m_bitmap.Ok())
157 {
158 wxDrawSplashBitmap(dc, m_bitmap, 0, 0);
159 }
160 }
161}
162
163void wxSplashScreenWindow::OnMouseEvent(wxMouseEvent& event)
164{
165 if (event.LeftDown() || event.RightDown())
166 GetParent()->Close(TRUE);
167}
168
169void wxSplashScreenWindow::OnChar(wxKeyEvent& WXUNUSED(event))
170{
171 GetParent()->Close(TRUE);
172}
173
174#endif // wxUSE_SPLASH