]> git.saurik.com Git - wxWidgets.git/blob - src/generic/splash.cpp
wxInputConsumer
[wxWidgets.git] / src / generic / splash.cpp
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
37 BEGIN_EVENT_TABLE(wxSplashScreen, wxFrame)
38 EVT_TIMER(wxSPLASH_TIMER_ID, wxSplashScreen::OnNotify)
39 EVT_CLOSE(wxSplashScreen::OnCloseWindow)
40 END_EVENT_TABLE()
41
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
47 wxSplashScreen::wxSplashScreen(const wxBitmap& bitmap, long splashStyle, int milliseconds, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style):
48 wxFrame(parent, id, wxEmptyString, wxPoint(0, 0), wxSize(100, 100), style)
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
56 SetClientSize(bitmap.GetWidth(), bitmap.GetHeight());
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();
71 #ifdef __WXMSW__
72 Update(); // Without this, you see a blank screen for an instant
73 #else
74 wxYieldIfNeeded(); // Should eliminate this
75 #endif
76 }
77
78 wxSplashScreen::~wxSplashScreen()
79 {
80 m_timer.Stop();
81 }
82
83 void wxSplashScreen::OnNotify(wxTimerEvent& WXUNUSED(event))
84 {
85 Close(TRUE);
86 }
87
88 void wxSplashScreen::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
89 {
90 m_timer.Stop();
91 this->Destroy();
92 }
93
94 /*
95 * wxSplashScreenWindow
96 */
97
98 BEGIN_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)
103 END_EVENT_TABLE()
104
105 wxSplashScreenWindow::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
111 void wxSplashScreenWindow::OnPaint(wxPaintEvent& WXUNUSED(event))
112 {
113 wxPaintDC dc(this);
114 if (m_bitmap.Ok())
115 dc.DrawBitmap(m_bitmap, 0, 0);
116 }
117
118 static void wxDrawSplashBitmap(wxDC& dc, const wxBitmap& bitmap, int WXUNUSED(x), int WXUNUSED(y))
119 {
120 wxMemoryDC dcMem;
121
122 #ifndef __WXGTK__
123 bool hiColour = (wxDisplayDepth() >= 16) ;
124
125 if (bitmap.GetPalette() && !hiColour)
126 {
127 dc.SetPalette(* bitmap.GetPalette());
128 dcMem.SetPalette(* bitmap.GetPalette());
129 }
130 #endif
131
132 dcMem.SelectObject(bitmap);
133 dc.Blit(0, 0, bitmap.GetWidth(), bitmap.GetHeight(), & dcMem, 0, 0);
134 dcMem.SelectObject(wxNullBitmap);
135
136 #ifndef __WXGTK__
137 if (bitmap.GetPalette() && !hiColour)
138 {
139 dc.SetPalette(wxNullPalette);
140 dcMem.SetPalette(wxNullPalette);
141 }
142 #endif
143 }
144
145 void 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
164 void wxSplashScreenWindow::OnMouseEvent(wxMouseEvent& event)
165 {
166 if (event.LeftDown() || event.RightDown())
167 GetParent()->Close(TRUE);
168 }
169
170 void wxSplashScreenWindow::OnChar(wxKeyEvent& WXUNUSED(event))
171 {
172 GetParent()->Close(TRUE);
173 }
174
175 #endif // wxUSE_SPLASH