]> git.saurik.com Git - wxWidgets.git/blame - src/generic/splash.cpp
better learn the operators...
[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
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
1e6feb95
VZ
23#if wxUSE_SPLASH
24
3f4fc796 25#ifndef WX_PRECOMP
d84d25dd 26#include "wx/dcmemory.h"
3f4fc796
JS
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
97f1fb19
JS
42/* Note that unless we pass a non-default size to the frame, SetClientSize
43 * won't work properly under Windows, and the splash screen frame is sized
44 * slightly too small.
45 */
46
3f4fc796 47wxSplashScreen::wxSplashScreen(const wxBitmap& bitmap, long splashStyle, int milliseconds, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style):
97f1fb19 48 wxFrame(parent, id, wxEmptyString, wxPoint(0, 0), wxSize(100, 100), style)
3f4fc796
JS
49{
50 m_window = NULL;
51 m_splashStyle = splashStyle;
52 m_milliseconds = milliseconds;
53
54 m_window = new wxSplashScreenWindow(bitmap, this, -1, pos, size, wxNO_BORDER);
55
97f1fb19 56 SetClientSize(bitmap.GetWidth(), bitmap.GetHeight());
3f4fc796
JS
57
58 if (m_splashStyle & wxSPLASH_CENTRE_ON_PARENT)
59 CentreOnParent();
60 else if (m_splashStyle & wxSPLASH_CENTRE_ON_SCREEN)
61 CentreOnScreen();
62
63 if (m_splashStyle & wxSPLASH_TIMEOUT)
64 {
65 m_timer.SetOwner(this, wxSPLASH_TIMER_ID);
66 m_timer.Start(milliseconds, TRUE);
67 }
68
69 Show(TRUE);
70 m_window->SetFocus();
8d079279
JS
71#ifdef __WXMSW__
72 Update(); // Without this, you see a blank screen for an instant
73#else
74 wxYieldIfNeeded(); // Should eliminate this
75#endif
3f4fc796
JS
76}
77
78wxSplashScreen::~wxSplashScreen()
79{
80 m_timer.Stop();
81}
82
33ac7e6f 83void wxSplashScreen::OnNotify(wxTimerEvent& WXUNUSED(event))
3f4fc796 84{
e1437298 85 Close(TRUE);
3f4fc796
JS
86}
87
33ac7e6f 88void wxSplashScreen::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
3f4fc796
JS
89{
90 m_timer.Stop();
91 this->Destroy();
92}
93
94/*
95 * wxSplashScreenWindow
96 */
97
98BEGIN_EVENT_TABLE(wxSplashScreenWindow, wxWindow)
99 //EVT_PAINT(wxSplashScreenWindow::OnPaint)
100 EVT_ERASE_BACKGROUND(wxSplashScreenWindow::OnEraseBackground)
101 EVT_CHAR(wxSplashScreenWindow::OnChar)
102 EVT_MOUSE_EVENTS(wxSplashScreenWindow::OnMouseEvent)
103END_EVENT_TABLE()
104
105wxSplashScreenWindow::wxSplashScreenWindow(const wxBitmap& bitmap, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style):
106 wxWindow(parent, id, pos, size, style)
107{
108 m_bitmap = bitmap;
109}
110
33ac7e6f 111void wxSplashScreenWindow::OnPaint(wxPaintEvent& WXUNUSED(event))
3f4fc796
JS
112{
113 wxPaintDC dc(this);
114 if (m_bitmap.Ok())
115 dc.DrawBitmap(m_bitmap, 0, 0);
116}
117
33ac7e6f 118static void wxDrawSplashBitmap(wxDC& dc, const wxBitmap& bitmap, int WXUNUSED(x), int WXUNUSED(y))
3f4fc796
JS
119{
120 wxMemoryDC dcMem;
121
c0f09a2e 122#ifndef __WXGTK__
3f4fc796 123 bool hiColour = (wxDisplayDepth() >= 16) ;
33ac7e6f 124
3f4fc796
JS
125 if (bitmap.GetPalette() && !hiColour)
126 {
127 dc.SetPalette(* bitmap.GetPalette());
128 dcMem.SetPalette(* bitmap.GetPalette());
129 }
25093cf3
JS
130#endif
131
3f4fc796
JS
132 dcMem.SelectObject(bitmap);
133 dc.Blit(0, 0, bitmap.GetWidth(), bitmap.GetHeight(), & dcMem, 0, 0);
134 dcMem.SelectObject(wxNullBitmap);
25093cf3
JS
135
136#ifndef __WXGTK__
3f4fc796
JS
137 if (bitmap.GetPalette() && !hiColour)
138 {
139 dc.SetPalette(wxNullPalette);
140 dcMem.SetPalette(wxNullPalette);
141 }
25093cf3 142#endif
3f4fc796
JS
143}
144
145void wxSplashScreenWindow::OnEraseBackground(wxEraseEvent& event)
146{
147 if (event.GetDC())
148 {
149 if (m_bitmap.Ok())
150 {
151 wxDrawSplashBitmap(* event.GetDC(), m_bitmap, 0, 0);
152 }
153 }
154 else
155 {
156 wxClientDC dc(this);
157 if (m_bitmap.Ok())
158 {
159 wxDrawSplashBitmap(dc, m_bitmap, 0, 0);
160 }
161 }
162}
163
164void wxSplashScreenWindow::OnMouseEvent(wxMouseEvent& event)
165{
166 if (event.LeftDown() || event.RightDown())
167 GetParent()->Close(TRUE);
168}
169
33ac7e6f 170void wxSplashScreenWindow::OnChar(wxKeyEvent& WXUNUSED(event))
3f4fc796
JS
171{
172 GetParent()->Close(TRUE);
173}
174
1e6feb95 175#endif // wxUSE_SPLASH