148 lines
5.5 KiB
C++
148 lines
5.5 KiB
C++
#include <test/splash.hpp>
|
|
#include <common/resbmp.hpp>
|
|
#include <common/dib.hpp>
|
|
#include <common/bitmap.hpp>
|
|
|
|
char SplashScreen::szClassName[]="SplashScreen";
|
|
|
|
SplashScreen::SplashScreen(const String &strBitmap,const String &strCaption,BOOL useTimer)
|
|
: mBitmapName(strBitmap), mStrCaption(strCaption), mUseTimer(useTimer),
|
|
mTextFont("Times New Roman",12,Font::PitchVariable|Font::FamilySwiss,Font::WeightBold)
|
|
{
|
|
mResBitmap=new ResBitmap(mBitmapName);
|
|
mResBitmap.disposition(PointerDisposition::Delete);
|
|
mCreateHandler.setCallback(this,&SplashScreen::createHandler);
|
|
mPaintHandler.setCallback(this,&SplashScreen::paintHandler);
|
|
mDestroyHandler.setCallback(this,&SplashScreen::destroyHandler);
|
|
mPaletteChangedHandler.setCallback(this,&SplashScreen::paletteChangedHandler);
|
|
mSetFocusHandler.setCallback(this,&SplashScreen::setFocusHandler);
|
|
mTimerHandler.setCallback(this,&SplashScreen::timerHandler);
|
|
insertHandler(VectorHandler::CreateHandler,&mCreateHandler);
|
|
insertHandler(VectorHandler::PaintHandler,&mPaintHandler);
|
|
insertHandler(VectorHandler::DestroyHandler,&mDestroyHandler);
|
|
insertHandler(VectorHandler::PaletteChangedHandler,&mPaletteChangedHandler);
|
|
insertHandler(VectorHandler::SetFocusHandler,&mSetFocusHandler);
|
|
insertHandler(VectorHandler::TimerHandler,&mTimerHandler);
|
|
registerClass();
|
|
}
|
|
|
|
SplashScreen::SplashScreen(const SplashScreen &someSplashScreen)
|
|
{ // private implementation
|
|
}
|
|
|
|
SplashScreen::~SplashScreen()
|
|
{
|
|
removeHandler(VectorHandler::CreateHandler,&mCreateHandler);
|
|
removeHandler(VectorHandler::PaintHandler,&mPaintHandler);
|
|
removeHandler(VectorHandler::DestroyHandler,&mDestroyHandler);
|
|
removeHandler(VectorHandler::PaletteChangedHandler,&mPaletteChangedHandler);
|
|
removeHandler(VectorHandler::SetFocusHandler,&mSetFocusHandler);
|
|
removeHandler(VectorHandler::TimerHandler,&mTimerHandler);
|
|
}
|
|
|
|
void SplashScreen::registerClass(void)
|
|
{
|
|
HINSTANCE hInstance(processInstance());
|
|
WNDCLASS wndClass;
|
|
|
|
if(::GetClassInfo(hInstance,szClassName,(WNDCLASS FAR*)&wndClass))return;
|
|
wndClass.style =CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS|CS_OWNDC;
|
|
wndClass.lpfnWndProc =(WNDPROC)Window::WndProc;
|
|
wndClass.cbClsExtra =0;
|
|
wndClass.cbWndExtra =sizeof(SplashScreen*);
|
|
wndClass.hInstance =hInstance;
|
|
wndClass.hIcon =::LoadIcon(NULL,IDI_APPLICATION);
|
|
wndClass.hCursor =::LoadCursor(NULL,IDC_ARROW);
|
|
wndClass.hbrBackground =(HBRUSH)::GetStockObject(NULL_BRUSH);
|
|
wndClass.lpszMenuName =0;
|
|
wndClass.lpszClassName =szClassName;
|
|
::RegisterClass(&wndClass);
|
|
assert(0!=::GetClassInfo(hInstance,szClassName,(WNDCLASS FAR*)&wndClass));
|
|
}
|
|
|
|
SplashScreen &SplashScreen::operator=(const SplashScreen &someSplashScreen)
|
|
{ // private implementation
|
|
return *this;
|
|
}
|
|
|
|
BOOL SplashScreen::perform(Rect initRect)
|
|
{
|
|
UINT style(0);
|
|
if(CW_USEDEFAULT==initRect.right())initRect.right(mResBitmap->width());
|
|
if(CW_USEDEFAULT==initRect.bottom())initRect.bottom(mResBitmap->height());
|
|
if(useTimer())
|
|
{
|
|
PureDevice pureDevice;
|
|
pureDevice.screenDevice();
|
|
initRect.left((pureDevice.horizontalResolution()-mResBitmap->width())/2);
|
|
initRect.top((pureDevice.verticalResolution()-mResBitmap->height())/2);
|
|
style=WS_POPUP|WS_CLIPSIBLINGS|0x04|WS_DLGFRAME;
|
|
}
|
|
else style=WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_BORDER|WS_DLGFRAME|0x04|WS_CLIPSIBLINGS;
|
|
createWindow(WS_EX_CONTROLPARENT,szClassName,useTimer()?(char*)0:(char*)mStrCaption,style,initRect,NULL,NULL,processInstance(),(LPSTR)this); // WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_BORDER|WS_DLGFRAME|0x04|WS_CLIPSIBLINGS
|
|
show(SW_SHOW);
|
|
update();
|
|
return messageLoop();
|
|
}
|
|
|
|
CallbackData::ReturnType SplashScreen::destroyHandler(CallbackData &someCallbackData)
|
|
{
|
|
PureDevice pureDevice(*this);
|
|
((PurePalette&)*mDIBitmap).usePalette(pureDevice,FALSE);
|
|
postQuitMessage(onDestroy());
|
|
return (CallbackData::ReturnType)FALSE;
|
|
}
|
|
|
|
CallbackData::ReturnType SplashScreen::createHandler(CallbackData &someCallbackData)
|
|
{
|
|
mPureDevice=new PureDevice(*this);
|
|
mPureDevice.disposition(PointerDisposition::Delete);
|
|
mDIBitmap=new DIBitmap(*mPureDevice,mResBitmap->width(),mResBitmap->height(),*mResBitmap);
|
|
mDIBitmap.disposition(PointerDisposition::Delete);
|
|
if(useTimer())setTimer(TimerID,TimeOut);
|
|
return (CallbackData::ReturnType)FALSE;
|
|
}
|
|
|
|
CallbackData::ReturnType SplashScreen::timerHandler(CallbackData &someCallbackData)
|
|
{
|
|
killTimer(TimerID);
|
|
postMessage(*this,WM_CLOSE,0,0L);
|
|
return (CallbackData::ReturnType)FALSE;
|
|
}
|
|
|
|
CallbackData::ReturnType SplashScreen::paletteChangedHandler(CallbackData &someCallbackData)
|
|
{
|
|
if(!mDIBitmap.isOkay()||((HWND)*this==(HWND)someCallbackData.wParam()))return (CallbackData::ReturnType)FALSE;
|
|
PureDevice pureDevice(*this);
|
|
((PurePalette&)*mDIBitmap).usePalette(pureDevice,TRUE);
|
|
update();
|
|
return (CallbackData::ReturnType)FALSE;
|
|
}
|
|
|
|
CallbackData::ReturnType SplashScreen::setFocusHandler(CallbackData &/*someCallbackData*/)
|
|
{
|
|
if(!mDIBitmap.isOkay())return (CallbackData::ReturnType)FALSE;
|
|
PureDevice pureDevice(*this);
|
|
((PurePalette&)*mDIBitmap).usePalette(pureDevice,TRUE);
|
|
return (CallbackData::ReturnType)FALSE;
|
|
}
|
|
|
|
CallbackData::ReturnType SplashScreen::paintHandler(CallbackData &someCallbackData)
|
|
{
|
|
if(!mResBitmap.isOkay())return (CallbackData::ReturnType)FALSE;
|
|
PaintInformation *pPaintInfo=(PaintInformation*)someCallbackData.lParam();
|
|
PureDevice &pureDevice=(PureDevice&)*pPaintInfo;
|
|
mDIBitmap->copyBits(mResBitmap->ptrData(),mResBitmap->imageExtent());
|
|
mDIBitmap->stretchBlt(pureDevice,Rect(0,0,width(),height()));
|
|
return (CallbackData::ReturnType)FALSE;
|
|
}
|
|
|
|
|
|
// virtuals
|
|
int SplashScreen::onDestroy(void)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
|