📄 sdlexe.cpp
字号:
CExitWait::~CExitWait() { Cancel(); } void CExitWait::RunL() { if(iStatusPtr != NULL ) iWait.DoExit(iStatus.Int()); } void CExitWait::DoCancel() { if(iStatusPtr != NULL ) User::RequestComplete(iStatusPtr , KErrCancel); } //////////////////////////////////////////////////////////////////////////////////////////////CSDLDocument::CSDLDocument(CEikApplication& aApp) : CEikDocument(aApp) {} CEikAppUi* CSDLDocument::CreateAppUiL() { return new (ELeave) CSDLAppUi; } /////////////////////////////////////////////////////////////////////////// void CSDLWin:: ConstructL(const TRect& aRect) { CreateWindowL(); SetRect(aRect); ActivateL(); } RWindow& CSDLWin::GetWindow() const { return Window(); } void CSDLWin::Draw(const TRect& /*aRect*/) const { if(!iNoDraw) { CWindowGc& gc = SystemGc(); gc.SetPenStyle(CGraphicsContext::ESolidPen); gc.SetPenColor(KRgbGray); gc.SetBrushStyle(CGraphicsContext::ESolidBrush); gc.SetBrushColor(0xaaaaaa); gc.DrawRect(Rect()); } } void CSDLWin::SetNoDraw() { iNoDraw = ETrue; }///////////////////////////////////////////////////////////////////////// CSDLAppUi::~CSDLAppUi() { if(iIdle) iIdle->Cancel(); delete iIdle; if(iStarter != NULL) iStarter->Cancel(); delete iStarter; delete iWait; delete iSdl; delete iSDLWin; delete iParams; delete iCBmp; delete iAlpha; } void CSDLAppUi::ConstructL() { BaseConstructL(ENoAppResourceFile | ENoScreenFurniture); RLibrary lib; User::LeaveIfError(lib.Load(_L("sdlexe.dll"))); TFileName name = lib.FileName(); lib.Close(); name.Replace(3, name.Length() - 3, _L("resource\\apps\\sdlexe.rsc")); BaflUtils::NearestLanguageFile(iEikonEnv->FsSession(), name); iResOffset = iCoeEnv->AddResourceFileL(name); name.Replace(name.Length() - 3, 3, _L("mbm")); TEntry e; const TInt err = iEikonEnv->FsSession().Entry(name, e); iCBmp = iEikonEnv->CreateBitmapL(name, 0); iAlpha = iEikonEnv->CreateBitmapL(name, 1); iIdle = CIdle::NewL(CActive::EPriorityIdle); iSDLWin = new (ELeave) CSDLWin; iSDLWin->ConstructL(ApplicationRect()); iSdl = CSDL::NewL(gSDLClass.SdlFlags()); gSDLClass.SendEvent(MSDLMainObs::ESDLCreated, 0, iSdl); iSdl->SetObserver(this); iSdl->DisableKeyBlocking(*this); iSdl->SetContainerWindowL( iSDLWin->GetWindow(), iEikonEnv->WsSession(), *iEikonEnv->ScreenDevice()); iSdl->AppendOverlay(iCursor, 0); iCursor.Set(TRect(TPoint(0, 0), iSDLWin->Size()), iCBmp, iAlpha); iStarter = CIdle::NewL(CActive::EPriorityLow); iStarter->Start(TCallBack(StartL, this)); } TBool CSDLAppUi::StartL(TAny* aThis) { static_cast<CSDLAppUi*>(aThis)->StartL(); return EFalse; } void CSDLAppUi::PrepareToExit() { CAknAppUiBase::PrepareToExit(); //aknappu::PrepareToExit crashes iCoeEnv->DeleteResourceFile(iResOffset); } TBool CSDLAppUi::ProcessCommandParametersL(CApaCommandLine &aCommandLine) { const TPtrC8 cmdLine = aCommandLine.TailEnd(); iParams = new (ELeave) CDesC8ArrayFlat(8); MakeCCmdLineL(cmdLine, *iParams); return EFalse; } TBool CSDLAppUi::ParamEditorL(TDes& aCheat) { CAknTextQueryDialog* query = CAknTextQueryDialog::NewL(aCheat); CleanupStack::PushL(query); query->SetPromptL(_L("Enter parameters")); CleanupStack::Pop(); return query->ExecuteLD(R_PARAMEDITOR); } void CSDLAppUi::StartL() { if(gSDLClass.AppFlags() & SDLEnv::EParamQuery) { TBuf8<256> cmd; RFile file; TInt err = file.Open(iEikonEnv->FsSession(), _L("sdl_param.txt"),EFileRead); if(err == KErrNone) { file.Read(cmd); file.Close(); MakeCCmdLineL(cmd, *iParams); } if(err != KErrNone || gSDLClass.AppFlags() & (SDLEnv::EParamQueryDialog ^ SDLEnv::EParamQuery)) { TBuf<256> buffer; if(ParamEditorL(buffer)) { cmd.Copy(buffer); MakeCCmdLineL(cmd, *iParams); } } } iWait = new (ELeave) CExitWait(*this); iSdl->CallMainL(gSDLClass.Main(), &iWait->iStatus, iParams, CSDL::ENoParamFlags, 0xA000); } void CSDLAppUi::HandleCommandL(TInt aCommand) { switch(aCommand) { case EAknSoftkeyBack: case EAknSoftkeyExit: case EAknCmdExit: case EEikCmdExit: gSDLClass.AppFlags(SDLEnv::EAllowConsoleView); if(iWait == NULL || !iWait->IsActive() || iSdl == NULL) { Exit(); } else if(!iExitRequest) { iExitRequest = ETrue; //trick how SDL can be closed! iSdl->Suspend(); } break; } } TBool CSDLAppUi::HandleKeyL(const TWsEvent& aEvent) { const TInt type = aEvent.Type(); if(!(type == EEventKey || type == EEventKeyUp || type == EEventKeyDown)) { return ETrue; } const TKeyEvent& key = *aEvent.Key(); if((key.iScanCode == EStdKeyYes) && (gSDLClass.AppFlags() & SDLEnv::EVirtualMouse)) { if(type == EEventKeyUp) { iCursor.Toggle(); iSdl->RedrawRequest(); } return EFalse; } if(iCursor.IsOn()) { switch(key.iScanCode) { case EStdKeyUpArrow: iCursor.Move(0, -1); break; case EStdKeyDownArrow: iCursor.Move(0, 1); break; case EStdKeyLeftArrow: iCursor.Move(-1, 0); break; case EStdKeyRightArrow: iCursor.Move(1, 0); break; case EStdKeyDevice3: if(type == EEventKeyUp) { TWsEvent event; iCursor.MakeEvent(event, iSDLWin->Position()); iSdl->AppendWsEvent(event); } return EFalse; default: return ETrue; } iSdl->RedrawRequest(); return EFalse; } return ETrue; } void CSDLAppUi::HandleWsEventL(const TWsEvent& aEvent, CCoeControl* aDestination) { if(iSdl && iWait && HandleKeyL(aEvent)) iSdl->AppendWsEvent(aEvent); CAknAppUi::HandleWsEventL(aEvent, aDestination); } void CSDLAppUi::HandleResourceChangeL(TInt aType) { CAknAppUi::HandleResourceChangeL(aType); if(aType == KEikDynamicLayoutVariantSwitch) { iSDLWin->SetRect(ApplicationRect()); iSdl->SetContainerWindowL( iSDLWin->GetWindow(), iEikonEnv->WsSession(), *iEikonEnv->ScreenDevice()); } } void CSDLAppUi::DoExit(TInt/*Err*/) { iExitRequest = ETrue; Exit(); } TInt CSDLAppUi::SdlThreadEvent(TInt aEvent, TInt /*aParam*/) { switch(aEvent) { case MSDLObserver::EEventResume: break; case MSDLObserver::EEventSuspend: if(iExitRequest) return MSDLObserver::ESuspendNoSuspend; break; case MSDLObserver::EEventWindowReserved: break; case MSDLObserver::EEventWindowNotAvailable: break; case MSDLObserver::EEventScreenSizeChanged: break; } return MSDLObserver::EParameterNone; } TInt CSDLAppUi::SdlEvent(TInt aEvent, TInt /*aParam*/) { switch(aEvent) { case MSDLObserver::EEventResume: break; case MSDLObserver::EEventSuspend: if(iExitRequest) return MSDLObserver::ESuspendNoSuspend; break; case MSDLObserver::EEventWindowReserved: break; case MSDLObserver::EEventWindowNotAvailable: { TRAP_IGNORE(HandleConsoleWindowL()); } break; case MSDLObserver::EEventScreenSizeChanged: break; case MSDLObserver::EEventKeyMapInit: break; case MSDLObserver::EEventMainExit: if(iStdOut != 0) { gSDLClass.AppFlags(SDLEnv::EAllowConsoleView); iEikonEnv->WsSession().SetWindowGroupOrdinalPosition(iStdOut, 0); } break; } return MSDLObserver::EParameterNone; } void CSDLAppUi::HandleForegroundEventL(TBool aForeground) { CAknAppUi::HandleForegroundEventL(aForeground); if(!aForeground) HandleConsoleWindow(); } void CSDLAppUi::HandleConsoleWindow() { if(!iIdle->IsActive()) iIdle->Start(TCallBack(IdleRequestL, this)); } TBool CSDLAppUi::IdleRequestL(TAny* aThis) { static_cast<CSDLAppUi*>(aThis)->HandleConsoleWindowL(); return EFalse; }void CSDLAppUi::HandleConsoleWindowL() { if(gSDLClass.AppFlags() & SDLEnv::EAllowConsoleView) { return; } RWsSession& ses = iEikonEnv->WsSession(); const TInt focus = ses.GetFocusWindowGroup(); CApaWindowGroupName* name = CApaWindowGroupName::NewLC(ses, focus); const TPtrC caption = name->Caption(); if(0 == caption.CompareF(_L("STDOUT"))) { iStdOut = focus; ses.SetWindowGroupOrdinalPosition(iEikonEnv->RootWin().Identifier(), 0); } CleanupStack::PopAndDestroy(); //name } ////////////////////////////////////////////////////////////////////////CApaApplication* NewApplication() { return new CSDLApplication(); } EXPORT_C TInt SDLEnv::SetMain(const TMainFunc& aFunc, TInt aSdlFlags, MSDLMainObs* aObs, TInt aSdlExeFlags) { gSDLClass.SetMain(aFunc, aSdlFlags, aObs, aSdlExeFlags); return EikStart::RunApplication(NewApplication); } //////////////////////////////////////////////////////////////////////TInt SDLUiPrint(const TDesC8& /*aInfo*/) { return KErrNotFound; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -