欢迎来到虫虫下载站 | 资源下载 资源专辑 关于我们
虫虫下载站

system.cpp

在手机操作系统symbina上使用的一个脚本扩展语言的代码实现,可以参考用于自己的开发
CPP
第 1 页 / 共 3 页
字号:
	{
	TUid id3;
	id3.iUid=aOplAPI.PopInt32();
	TUid id2;
	id2.iUid=aOplAPI.PopInt32();
	TUid id1;
	id1.iUid=aOplAPI.PopInt32();
	TUidType uidType(id1,id2,id3);
	TCheckedUid check(uidType);
	TPtrC16 check16bit((TUint16*)check.Des().Ptr(),16);
	aOplAPI.PushL(check16bit);
	}

void CSystemOpx::SetPointerGrabOn(OplAPI& aOplAPI) const
	{
	TInt32 state=aOplAPI.PopInt32();
	TInt32 winId=aOplAPI.PopInt32();
	RBackedUpWindow win=aOplAPI.WindowFromIdL(winId);
	win.SetPointerGrab(TBool(state));
	aOplAPI.Push(TReal64(0.0));
	}

void CSystemOpx::ClaimPointerGrab(OplAPI& aOplAPI) const
	{
	TInt32 state=aOplAPI.PopInt32();
	TInt32 winId=aOplAPI.PopInt32();
	RBackedUpWindow win=aOplAPI.WindowFromIdL(winId);
	win.ClaimPointerGrab(TBool(state));
	aOplAPI.Push(TReal64(0.0));
	}

void CSystemOpx::SetPointerCapture(OplAPI& aOplAPI) const
//#pragma warning (disable:4710) // function not expanded.
	{
	TInt32 flags=aOplAPI.PopInt32();
	TInt32 winId=aOplAPI.PopInt32();
	RBackedUpWindow win=aOplAPI.WindowFromIdL(winId);
	win.SetPointerCapture(flags);
	aOplAPI.Push(TReal64(0.0));
	}

void CSystemOpx::EndTask(OplAPI& aOplAPI) const
// Send Shut-down message. 
	{
	TInt prev =aOplAPI.PopInt32();
	TInt tempId =aOplAPI.PopInt32();
	TThreadId id= *((TThreadId*)&tempId);
	RWsSession& ws=aOplAPI.WsSession();
	TInt winGid=ws.FindWindowGroupIdentifier(prev,id);
	TApaTask tApatsk(ws);
	tApatsk.SetWgId(winGid);
	if (!tApatsk.Exists())
		User::Leave(KErrNotFound);
	CApaWindowGroupName* wgName=CApaWindowGroupName::NewLC(ws,winGid);
	if (wgName->IsSystem() || wgName->IsBusy() || !wgName->RespondsToShutdownEvent())
		User::Leave(KErrAccessDenied);
	CleanupStack::PopAndDestroy(); // wgName
	tApatsk.SendSystemEvent(EApaSystemEventShutdown);
	aOplAPI.Push(TInt32(winGid));
	}

void CSystemOpx::KillTask(OplAPI& aOplAPI) const
// Send Shut-down message Ignore apps.
	{
	TInt prev =aOplAPI.PopInt32();
	TInt tempId =aOplAPI.PopInt32();
	TThreadId id= *((TThreadId*)&tempId);
	RWsSession& ws=aOplAPI.WsSession();
	TInt winGid=ws.FindWindowGroupIdentifier(prev,id);
	TApaTask tApatsk(ws);
	tApatsk.SetWgId(winGid);
	if (!tApatsk.Exists())
		User::Leave(KErrNotFound);
	tApatsk.KillTask();
	aOplAPI.Push(TInt32(winGid));
	}

void CSystemOpx::ThreadIdFromOpenDoc(OplAPI& aOplAPI) const
	{
	TInt32* prev=aOplAPI.PopPtrInt32();
	TPtrC doc=aOplAPI.PopString();
	RWsSession& ws=aOplAPI.WsSession();
	TInt prevLive=aOplAPI.GetLong(prev);
	CApaWindowGroupName::FindByDocName(doc,ws,prevLive);
	TApaTask tApatsk(ws);
	tApatsk.SetWgId(prevLive);
	aOplAPI.PutLong(prev,prevLive);
	if (!tApatsk.Exists())
		User::Leave(KErrNotFound);
	TThreadId tId= tApatsk.ThreadId();
	aOplAPI.Push(*((TInt32*)&tId));
	}

void CSystemOpx::ThreadIdFromAppUid(OplAPI& aOplAPI) const
	{
	TInt32* prev=aOplAPI.PopPtrInt32();
	TUid uid;
	uid.iUid=(aOplAPI.PopInt32());
	RWsSession& ws=aOplAPI.WsSession();
	TInt prevLive=aOplAPI.GetLong(prev);
	CApaWindowGroupName::FindByAppUid(uid,ws,prevLive); 
	TApaTask tApatsk(ws);
	tApatsk.SetWgId(prevLive);
	aOplAPI.PutLong(prev,prevLive);
	if (!tApatsk.Exists())
		User::Leave(KErrNotFound);
	TThreadId tId= tApatsk.ThreadId();
	aOplAPI.Push(*((TInt32*)&tId));
	}

void CSystemOpx::SetForeground(OplAPI& aOplAPI) const
	{
	RWsSession& ws=aOplAPI.WsSession();
	RWindowGroup& rw = aOplAPI.RootWindow();
	TInt winId = rw.Identifier();
	TApaTask tApatsk(ws);
	tApatsk.SetWgId(winId);
	tApatsk.BringToForeground();
	aOplAPI.Push(TReal64(0.0));
	}

void CSystemOpx::SetBackground(OplAPI& aOplAPI) const
	{
	RWsSession& ws=aOplAPI.WsSession();
	RWindowGroup& rw = aOplAPI.RootWindow();
	TInt winId = rw.Identifier();
	TApaTask tApatsk(ws);
	tApatsk.SetWgId(winId);
	tApatsk.SendToBackground();
	aOplAPI.Push(TReal64(0.0));
	}

void CSystemOpx::SetBackgroundByThread(OplAPI& aOplAPI) const
	{
	TInt prev =aOplAPI.PopInt32();
	TInt tempId =aOplAPI.PopInt32();
	TThreadId id= *((TThreadId*)&tempId);
	RWsSession& ws=aOplAPI.WsSession();
	TInt winGid=ws.FindWindowGroupIdentifier(prev,id);
	TApaTask tApatsk(ws);
	tApatsk.SetWgId(winGid);
	if (!tApatsk.Exists())
		User::Leave(KErrNotFound);
	tApatsk.SendToBackground();
	aOplAPI.Push(TInt32(winGid));
	}

void CSystemOpx::SetForegroundByThread(OplAPI& aOplAPI) const
	{
	TInt prev =aOplAPI.PopInt32();
	TInt tempId =aOplAPI.PopInt32();
	TThreadId id= *((TThreadId*)&tempId);
	RWsSession& ws=aOplAPI.WsSession();
	TInt winGid=ws.FindWindowGroupIdentifier(prev,id);
	TApaTask tApatsk(ws);
	tApatsk.SetWgId(winGid);
	if (!tApatsk.Exists())
		User::Leave(KErrNotFound);
	tApatsk.BringToForeground();
	aOplAPI.Push(TInt32(winGid));
	}

void CSystemOpx::NextWindowGroupName(OplAPI& aOplAPI) const
	{
	TInt32* prev=aOplAPI.PopPtrInt32();
	TInt32 prevLive=aOplAPI.GetLong(prev);
	TInt tempId =aOplAPI.PopInt32();
	TThreadId id= *((TThreadId*)&tempId);
	RWsSession& ws=aOplAPI.WsSession();
	TInt winGid=ws.FindWindowGroupIdentifier(prevLive,id);
	CApaWindowGroupName* wgName=CApaWindowGroupName::NewLC(ws,winGid);
	TBuf<255> name=wgName->WindowGroupName();
	CleanupStack::PopAndDestroy(); // wgName
	aOplAPI.PutLong(prev,winGid);
	aOplAPI.PushL(name);
	}

void CSystemOpx::NextWindowId(OplAPI& aOplAPI) const
	{
	TInt prev=aOplAPI.PopInt32();
	TInt tempId =aOplAPI.PopInt32();
	TThreadId id= *((TThreadId*)&tempId);
	RWsSession& ws=aOplAPI.WsSession();
	TInt winGid=ws.FindWindowGroupIdentifier(prev,id);
	aOplAPI.Push(TInt32(winGid));
	}

void CSystemOpx::SendSwitchFilesMessageToApp(OplAPI& aOplAPI) const
	{
	TBool aCreateRatherThanOpen=aOplAPI.PopInt16();
	TPtrC aFileName = aOplAPI.PopString();
	TInt aPrevious = aOplAPI.PopInt32();
	TInt aTempId = aOplAPI.PopInt32();

	// Find our task
	TThreadId threadId= *((TThreadId*)&aTempId);
	RWsSession& ws=aOplAPI.WsSession();
	TInt winGid=ws.FindWindowGroupIdentifier(aPrevious,threadId);
	TApaTask tApatsk(ws);
	tApatsk.SetWgId(winGid);
	if (!tApatsk.Exists())
		User::Leave(KErrNotFound);
	// Now switch the file
	if (aCreateRatherThanOpen)
		tApatsk.SwitchCreateFile(aFileName);
	else
		tApatsk.SwitchOpenFile(aFileName);
	aOplAPI.Push(TInt32(winGid));
	}

void CSystemOpx::SendKeyEventToApp(OplAPI& aOplAPI) const
	{
	TKeyEvent event;
	event.iRepeats=aOplAPI.PopInt32();
	event.iModifiers=aOplAPI.PopInt32();
	event.iScanCode=aOplAPI.PopInt32();
	event.iCode=aOplAPI.PopInt32();
	TInt prev =aOplAPI.PopInt32();
	TInt tempId =aOplAPI.PopInt32();

	TThreadId id= *((TThreadId*)&tempId);
	RWsSession& ws=aOplAPI.WsSession();
	TInt winGid=ws.FindWindowGroupIdentifier(prev,id);
	TApaTask tApatsk(ws);
	tApatsk.SetWgId(winGid);
	if (!tApatsk.Exists())
		User::Leave(KErrNotFound);
	tApatsk.SendKey(event);
	aOplAPI.Push(TInt32(winGid));
	}

void CSystemOpx::CaptureKey(OplAPI& aOplAPI) const
	{
	TUint32 mod=aOplAPI.PopInt32();
	TUint32 msk=aOplAPI.PopInt32();
	TUint32 key=aOplAPI.PopInt32();
	RWindowGroup& rw = aOplAPI.RootWindow();
	TInt32 ret=rw.CaptureKey(key,msk,mod);
	User::LeaveIfError(ret);
	aOplAPI.Push(ret);
	}

void CSystemOpx::CancelCaptureKey(OplAPI& aOplAPI) const
	{
	TInt32 canc=aOplAPI.PopInt32();
	RWindowGroup& rw = aOplAPI.RootWindow();
	rw.CancelCaptureKey(canc);
	aOplAPI.Push(0.0);
	}

LOCAL_C void ParseNameL(RFs& aFs,TFileName& aName)
	{
	TParse parse;
	User::LeaveIfError(aFs.Parse(aName,parse));
	aName=parse.FullName();
	}

void CSystemOpx::FileOpenDialog(OplAPI& aOplAPI) const
	{ // SyOpenFileDialog$:(seedFile$,uid1&,uid2&,uid3&)
#if !defined(__SERIES60__)
	TInt uid3=aOplAPI.PopInt32();
	TInt uid2=aOplAPI.PopInt32();
	TUidType uidType(TUid::Uid(aOplAPI.PopInt32()),TUid::Uid(uid2),TUid::Uid(uid3));
	TFileName fName=aOplAPI.PopString();
	ParseNameL(aOplAPI.EikonEnv().FsSession(),fName);
	CEikFileOpenDialog* dialog=new(ELeave) CEikFileOpenDialog(&fName);
	dialog->SetRequiredUid(uidType);
	if (dialog->ExecuteLD(R_EIK_DIALOG_FILE_OPEN))
		{
		if (fName.Length()>KOplMaxStringLength)
			User::Leave(KOplErrStrTooLong);
		}
	else
		fName.Zero();
#else
	aOplAPI.PopInt32();
	aOplAPI.PopInt32();
	aOplAPI.PopInt32();
	TFileName fName=aOplAPI.PopString();
	User::Leave(KOplErrNotSupported);
#endif
	aOplAPI.PushL(fName);
	}

void CSystemOpx::FileCreateDialog(OplAPI& aOplAPI) const
	{ // SyCreateFileDialog$:(seedPath$)
	TFileName fName=aOplAPI.PopString();
	ParseNameL(aOplAPI.EikonEnv().FsSession(),fName);
#if !defined(__SERIES60__)
	if (CEikFileSaveAsDialog::RunDlgLD(&fName,NULL,R_EIK_TBUF_CREATE_NEW_FILE))
		{
		if (fName.Length()>KOplMaxStringLength)
			User::Leave(KOplErrStrTooLong);
		}
	else
		fName.Zero();
#else
	User::Leave(KOplErrNotSupported);
#endif
	aOplAPI.PushL(fName);
	}

void CSystemOpx::FileSaveAsDialog(OplAPI& aOplAPI) const
	{ // SySaveAsFileDialog$:(seedPath$,BYREF useNewFile%)
#if !defined(__SERIES60__)
	TInt16* useNewPtr=aOplAPI.PopPtrInt16();
	TFileName fName=aOplAPI.PopString();
	ParseNameL(aOplAPI.EikonEnv().FsSession(),fName);
	TBool useNewFile=(useNewPtr!=NULL)?(*useNewPtr!=0):EFalse;
	if (CEikFileSaveAsDialog::RunDlgLD(&fName,(useNewPtr!=NULL)?&useNewFile:NULL))
		{
		if (fName.Length()>KOplMaxStringLength)
			User::Leave(KOplErrStrTooLong);
		if (useNewPtr!=NULL)
			*useNewPtr = OpxUtil::OplBool16(useNewFile);
		}
	else
		fName.Zero();
#else
	aOplAPI.PopPtrInt16();
	TFileName fName=aOplAPI.PopString();
	User::Leave(KOplErrNotSupported);
#endif
	aOplAPI.PushL(fName);
	}

TInt CSystemOpx::CheckThreadPointerL(RThreadHolder* aKeyPtr)
	{
	TInt count=iThreadArray.Count();
	TInt ii;
	for(ii=0;ii<count;ii++)
		{
		if (iThreadArray[ii]==aKeyPtr)
			return ii;
		}
	User::Leave(KOplErrInvalidArgs);
	return ii;
	}

void CSystemOpx::ThreadIdFromCaption(OplAPI& aOplAPI) const
	{
	TInt32* prev=aOplAPI.PopPtrInt32();
	TPtrC doc=aOplAPI.PopString();
	RWsSession& ws=aOplAPI.WsSession();
	TInt prevLive=aOplAPI.GetLong(prev);
	CApaWindowGroupName::FindByCaption(doc,ws,prevLive); 
	TApaTask tApatsk(ws);
	tApatsk.SetWgId(prevLive);
	aOplAPI.PutLong(prev,prevLive);
	if (!tApatsk.Exists())
		User::Leave(KErrNotFound);
	TThreadId tId= tApatsk.ThreadId();
	aOplAPI.Push(*((TInt32*)&tId));
	}

void CSystemOpx::OSVersionMajor(OplAPI& aOplAPI) const
	{
	aOplAPI.Push(TInt32(User::Version().iMajor));
	}

void CSystemOpx::OSVersionMinor(OplAPI& aOplAPI) const
	{
	aOplAPI.Push(TInt32(User::Version().iMinor));
	}

void CSystemOpx::OSVersionBuild(OplAPI& aOplAPI) const
	{
	aOplAPI.Push(TInt32(User::Version().iBuild));
	}

void CSystemOpx::ROMVersionMajor(OplAPI& aOplAPI) const
	{
	TMachineInfoV1Buf buf;
	UserHal::MachineInfo(buf);
	TMachineInfoV1& t=buf();
	aOplAPI.Push(TInt32(t.iRomVersion.iMajor));
	}

void CSystemOpx::ROMVersionMinor(OplAPI& aOplAPI) const
	{
	TMachineInfoV1Buf buf;
	UserHal::MachineInfo(buf);
	TMachineInfoV1& t=buf();
	aOplAPI.Push(TInt32(t.iRomVersion.iMinor));
	}

void CSystemOpx::ROMVersionBuild(OplAPI& aOplAPI) const
	{
	TMachineInfoV1Buf buf;
	UserHal::MachineInfo(buf);
	TMachineInfoV1& t=buf();
	aOplAPI.Push(TInt32(t.iRomVersion.iBuild));
	}

void CSystemOpx::FileSize(OplAPI& aOplAPI) const
	{
	TFileName FileName(aOplAPI.PopString());
	RFs& TheFs=aOplAPI.DbManager()->FsSession();
	TEntry entry;
	User::LeaveIfError(TheFs.Entry(FileName,entry));
	aOplAPI.Push(TInt32(entry.iSize));
	}

// From SystInfo
void CSystemOpx::IsDirectory(OplAPI& aOplAPI) const
	{
	TPtrC fname = aOplAPI.PopString();
	TUint attValue;
	User::LeaveIfError(aOplAPI.EikonEnv().FsSession().Att(fname, attValue));
	aOplAPI.Push(TInt32((attValue & KEntryAttDir) ? 1 : 0));
	}

void CSystemOpx::IsPathVisible(OplAPI& aOplAPI) const
	{
	TPtrC fname = aOplAPI.PopString();
	TUint attValue;
	RFs &aFs = aOplAPI.EikonEnv().FsSession();
	TParse aParse;
	aParse.Set(fname, NULL, NULL);
	while (!aParse.IsRoot())
		{
		User::LeaveIfError(aFs.Att(aParse.DriveAndPath(), attValue));
		if (attValue & (KEntryAttHidden | KEntryAttSystem))
			{
			aOplAPI.Push(TInt32(0));
			return;
			}
		aParse.PopDir();
		}
	aOplAPI.Push(TInt32(1));
	}

void CSystemOpx::VolumeName(OplAPI& aOplAPI) const
	{
	TVolumeInfo vol;
	TInt32 drive= aOplAPI.PopInt32();
	if (drive<0 || drive>25)
		User::Leave(KOplErrInvalidArgs);
	aOplAPI.DbManager()->FsSession().Volume(vol, drive);
	aOplAPI.PushL(vol.iName);
	}

void CSystemOpx::UniqueFilename(OplAPI& aOplAPI) const
	{
	TBuf<256> fname = aOplAPI.PopString();
	User::LeaveIfError(CEikApplication::GenerateFileName(aOplAPI.EikonEnv().FsSession(), fname));
	aOplAPI.PushL(fname);
	}

void CSystemOpx::LanguageIndex(OplAPI& aOplAPI) const
	{
	TMachineInfoV2Buf buf;
	User::LeaveIfError(UserHal::MachineInfo(buf));
	TMachineInfoV2 info=buf();
	aOplAPI.Push(TInt32(info.iLanguageIndex));
	}

void CSystemOpx::GetOPXVersion(OplAPI& aOplAPI) const
	{
	TFileName aOPXName=aOplAPI.PopString();
	if (!ConeUtils::FileExists(aOPXName))
		User::Leave(KOplErrNotExists);
	TParse parse;
	_LIT(KOPXExtension,".OPX");
	parse.Set(aOPXName,NULL,NULL);
	if (parse.Ext().CompareF(KOPXExtension)!=KErrNone)
		User::Leave(KOplErrBadFileType);

	RLibrary opx;
	User::LeaveIfError(opx.Load(aOPXName));
	TLibraryFunction versionExport=opx.Lookup(2);
	if (versionExport==NULL) // Ordinal not found
		{
		opx.Close();
		User::Leave(KOplErrNotSupported);
		}
	TInt32 version=(TInt32)(*(versionExport))();
	opx.Close();
	aOplAPI.Push(version);
	}

void CSystemOpx::RemoteLinkStatus(OplAPI& aOplAPI) const
	{
#if !defined(USE_PLP)
	User::Leave(KErrNotSupported);
#else
	RRemoteLink link;
	TRemoteLinkStatus status;
	User::LeaveIfError(link.Open());
	CleanupClosePushL(link);
	User::LeaveIfError(link.Status(status));
	CleanupStack::PopAndDestroy(); // link
	aOplAPI.Push(TInt32(status.iStatus));
#endif
	}

void CSystemOpx::RemoteLinkDisable(OplAPI& aOplAPI) const
	{
#if !defined(USE_PLP)
	User::Leave(KErrNotSupported);
#else
	RRemoteLink link;
	User::LeaveIfError(link.Open());
	CleanupClosePushL(link);
	User::LeaveIfError(link.Disable());
	CleanupStack::PopAndDestroy(); // link
	aOplAPI.Push(0.0);
#endif
	}

void CSystemOpx::RemoteLinkEnable(OplAPI& aOplAPI) const
	{
#if !defined(USE_PLP)
	User::Leave(KErrNotSupported);
#else
	RRemoteLink link;
	User::LeaveIfError(link.Open());
	CleanupClosePushL(link);
	User::LeaveIfError(link.Enable(EBps115200,KNullDesC,KNullDesC));
	CleanupStack::PopAndDestroy(); // link
	aOplAPI.Push(0.0);
#endif
	}

void CSystemOpx::RemoteLinkEnableWithOptions(OplAPI& aOplAPI) const
	{
#if !defined(USE_PLP)
	User::Leave(KErrNotSupported);
#else
	// Note: In each of the below two checks the ExxxxUnknown value is invalid
	TInt16 aLinkBaud = aOplAPI.PopInt16();
	if ((aLinkBaud < ELinkBps9600) || (aLinkBaud > ELinkBps4000000))
		User::Leave(KOplErrInvalidArgs);
	TInt16 aLinkType = aOplAPI.PopInt16();
	if ((aLinkType < ELinkTypeCable) || (aLinkType > ELinkTypeIrDA)) 
		User::Leave(KOplErrInvalidArgs);

	RRemoteLink link;
	User::LeaveIfError(link.Open());
	CleanupClosePushL(link);

	TBps linkBaud;
	switch (aLinkBaud)
		{
	case ELinkBps9600:
		linkBaud = EBps9600;
		break;
	case ELinkBps19200:
		linkBaud = EBps19200;
		break;
	case ELinkBps38400:
		linkBaud = EBps38400;
		break;
	case ELinkBps57600:
		linkBaud = EBps57600;
		break;
	case ELinkBps115200:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -