00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "advsplash.h"
00012 #include <wx/splash.h>
00013
00014 #if defined(__WXGTK20__)
00015 #include <gtk/gtk.h>
00016 #endif
00017
00018
00019
00020
00021
00022 #define wxSPLASH_TIMER_ID 9999
00023
00024 IMPLEMENT_DYNAMIC_CLASS(wxAdvSplashScreen, wxFrame);
00025
00026 BEGIN_EVENT_TABLE(wxAdvSplashScreen, wxFrame)
00027 EVT_TIMER(wxSPLASH_TIMER_ID, wxAdvSplashScreen::OnNotify)
00028 EVT_CLOSE(wxAdvSplashScreen::OnCloseWindow)
00029 END_EVENT_TABLE()
00030
00031
00032
00033
00034
00035
00036 wxAdvSplashScreen::wxAdvSplashScreen(const wxBitmap& bitmap, long splashStyle, int milliseconds, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style)
00037 {
00038
00039
00040 Create(parent, id, wxEmptyString, wxPoint(0,0), wxSize(100, 100), style);
00041
00042
00043 #if defined(__WXGTK20__)
00044 #if GTK_CHECK_VERSION(2,2,0)
00045 gtk_window_set_type_hint(GTK_WINDOW(m_widget),
00046 GDK_WINDOW_TYPE_HINT_SPLASHSCREEN);
00047 #endif
00048 #endif
00049
00050 m_window = NULL;
00051 m_splashStyle = splashStyle;
00052 m_milliseconds = milliseconds;
00053
00054 m_window = new wxAdvSplashScreenWindow(bitmap, this, wxID_ANY, pos, size, wxNO_BORDER);
00055
00056 SetClientSize(bitmap.GetWidth()+2, bitmap.GetHeight()+2);
00057
00058 if (m_splashStyle & wxSPLASH_CENTRE_ON_PARENT)
00059 CentreOnParent();
00060 else if (m_splashStyle & wxSPLASH_CENTRE_ON_SCREEN)
00061 CentreOnScreen();
00062
00063 if (m_splashStyle & wxSPLASH_TIMEOUT)
00064 {
00065 m_timer.SetOwner(this, wxSPLASH_TIMER_ID);
00066 m_timer.Start(milliseconds, true);
00067 }
00068
00069 Show(true);
00070 m_window->SetFocus();
00071 #if defined( __WXMSW__ ) || defined(__WXMAC__)
00072 Update();
00073 #else
00074 wxYieldIfNeeded();
00075 #endif
00076 }
00077
00078 wxAdvSplashScreen::~wxAdvSplashScreen()
00079 {
00080 m_timer.Stop();
00081 }
00082
00083 void wxAdvSplashScreen::OnNotify(wxTimerEvent& WXUNUSED(event))
00084 {
00085 Close(true);
00086 }
00087
00088 void wxAdvSplashScreen::OnCloseWindow(wxCloseEvent& WXUNUSED(event))
00089 {
00090 m_timer.Stop();
00091 this->Destroy();
00092 }
00093
00094
00095
00096
00097
00098 BEGIN_EVENT_TABLE(wxAdvSplashScreenWindow, wxWindow)
00099 #ifdef __WXGTK__
00100 EVT_PAINT(wxAdvSplashScreenWindow::OnPaint)
00101 #endif
00102 EVT_ERASE_BACKGROUND(wxAdvSplashScreenWindow::OnEraseBackground)
00103 EVT_CHAR(wxAdvSplashScreenWindow::OnChar)
00104 EVT_MOUSE_EVENTS(wxAdvSplashScreenWindow::OnMouseEvent)
00105 END_EVENT_TABLE()
00106
00107 wxAdvSplashScreenWindow::wxAdvSplashScreenWindow(const wxBitmap& bitmap, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style):
00108 wxWindow(parent, id, pos, size, style)
00109 {
00110 m_bitmap = bitmap;
00111
00112 #if !defined(__WXGTK__) && wxUSE_PALETTE
00113 bool hiColour = (wxDisplayDepth() >= 16) ;
00114
00115 if (bitmap.GetPalette() && !hiColour)
00116 {
00117 SetPalette(* bitmap.GetPalette());
00118 }
00119 #endif
00120
00121 }
00122
00123
00124 #if !defined(__WXGTK__) && wxUSE_PALETTE
00125 #define USE_PALETTE_IN_SPLASH
00126 #endif
00127
00128 static void wxDrawSplashBitmap(wxDC& dc, const wxBitmap& bitmap, int WXUNUSED(x), int WXUNUSED(y))
00129 {
00130 #if 0
00131 wxMemoryDC dcMem;
00132
00133 #ifdef USE_PALETTE_IN_SPLASH
00134 bool hiColour = (wxDisplayDepth() >= 16) ;
00135
00136 if (bitmap.GetPalette() && !hiColour)
00137 {
00138 dcMem.SetPalette(* bitmap.GetPalette());
00139 }
00140 #endif // USE_PALETTE_IN_SPLASH
00141
00142 dcMem.SelectObject(bitmap);
00143 dc.Blit(0, 0, bitmap.GetWidth(), bitmap.GetHeight(), & dcMem, 0, 0);
00144 dcMem.SelectObject(wxNullBitmap);
00145
00146 #ifdef USE_PALETTE_IN_SPLASH
00147 if (bitmap.GetPalette() && !hiColour)
00148 {
00149 dcMem.SetPalette(wxNullPalette);
00150 }
00151 #endif // USE_PALETTE_IN_SPLASH
00152 #endif
00153
00154 dc.DrawBitmap(bitmap, 0, 0);
00155
00156 }
00157
00158 void wxAdvSplashScreenWindow::OnPaint(wxPaintEvent& WXUNUSED(event))
00159 {
00160 wxPaintDC dc(this);
00161 if (m_bitmap.Ok())
00162 wxDrawSplashBitmap(dc, m_bitmap, 0, 0);
00163 }
00164
00165 void wxAdvSplashScreenWindow::OnEraseBackground(wxEraseEvent& event)
00166 {
00167 if (event.GetDC())
00168 {
00169 if (m_bitmap.Ok())
00170 {
00171 wxDrawSplashBitmap(* event.GetDC(), m_bitmap, 0, 0);
00172 }
00173 }
00174 else
00175 {
00176 wxClientDC dc(this);
00177 if (m_bitmap.Ok())
00178 {
00179 wxDrawSplashBitmap(dc, m_bitmap, 0, 0);
00180 }
00181 }
00182 }
00183
00184 void wxAdvSplashScreenWindow::OnMouseEvent(wxMouseEvent& event)
00185 {
00186 if (event.LeftDown() || event.RightDown())
00187 GetParent()->Close(true);
00188 }
00189
00190 void wxAdvSplashScreenWindow::OnChar(wxKeyEvent& WXUNUSED(event))
00191 {
00192 GetParent()->Close(true);
00193 }
00194