⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 iomain.cpp

📁 在手机操作系统symbina上使用的一个脚本扩展语言的代码实现,可以参考用于自己的开发
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	TInt highestPriority=KMinTInt;
	for (TInt i=iRequestArray.Count()-1; i>=0; --i)
		{
		TIORequest* const request=iRequestArray[i];
		__ASSERT_DEBUG(request!=NULL,User::Panic(KOplIOSystem,100));
		if (request->Status()!=KRequestPending)
			{
			request->HandleCompletionIfNecessary();
			const TInt priority=request->Priority();
			if (highestPriority<=priority)	// <= rather than < just in case there actually
											// is a request with priority "KMinTInt"
				{
				completedRequestWithHighestPriority=request;
				highestPriority=priority;
				}
			}
		}
	return completedRequestWithHighestPriority;
	}

void CIOCollection::RemoveCompletedOplAsynchronousRequest(const TIORequest* aRequest)
	// Can only be passed a pointer that was returned by
	// HandleAnyCompletedOplAsynchronousRequests, and it must *not* be NULL
	{
	__ASSERT_DEBUG(aRequest!=NULL, User::Panic(KOplIOSystem, 12));
	iRequestArray.Remove(iRequestArray.Find(aRequest));
	delete (TIORequest*)aRequest;
	}

#include "consIO.h"

LOCAL_C void TPointFromP_POINT(TPoint& aPoint,P_POINT* aP_Point)
	{
	aPoint.iX=OplUtil::GetWord(&aP_Point->x+1);
	aPoint.iY=OplUtil::GetWord(&aP_Point->y+1);
	}

LOCAL_C void TRectFromP_RECT(TRect& aRect,P_RECT* aP_Rect)
	{
	TPointFromP_POINT(aRect.iTl,&(aP_Rect->tl));
	TPointFromP_POINT(aRect.iBr,&(aP_Rect->br));
	}

void CIOCollection::HandleConsoleRequest(TInt16 aFuncNo,TRequestStatus& aRequestStatus,TAny* aParam1,TAny* aParam2)
	// eb205: I've replaced calls to "User::Leave(KOplErrInvalidIO)" with calls to
	// "User::RequestComplete(requestStatus,KErrArgument)"
	{
	TRequestStatus* requestStatus=&aRequestStatus;
	COplConsole& console=iRuntime->Console();
	switch (aFuncNo)
		{
	case (FSENSE):
		{
		P_RECTP* rectp=(P_RECTP*) aParam1;
		TPoint curPos=console.CurrentPos();

		OplUtil::PutWord(&(rectp->p.x),(TInt16)(curPos.iX-1));
		OplUtil::PutWord(&(rectp->p.y),(TInt16)(curPos.iY-1));
		TRect rect;
		console.ScreenRectInChars(rect);
		OplUtil::PutWord(&(rectp->r.tl.x),(TInt16)(rect.iTl.iX-1));
		OplUtil::PutWord(&(rectp->r.tl.y),(TInt16)(rect.iTl.iY-1));
		OplUtil::PutWord(&(rectp->r.br.x),(TInt16)(rect.iBr.iX-1));
		OplUtil::PutWord(&(rectp->r.br.y),(TInt16)(rect.iBr.iY-1));
		break;
		}
	case (FINQ):
		{
		TSize charSize=console.CharSize();
		CONSOLE_INFO* info=(CONSOLE_INFO*)aParam1;
		OplUtil::PutWord(&info->window_handle,1);
		OplUtil::PutWord(&info->font_handle,0);
		OplUtil::PutWord(&info->line_height,(TUint16)charSize.iHeight);
		OplUtil::PutWord(&info->char_width,(TUint16)charSize.iWidth);
		break;
		}
	case (FSET):
		{
		switch (OplUtil::GetWord(aParam1))
			{
			case P_SCR_CLR:
				{
				P_RECT* rect=(P_RECT*)aParam2;
				TRect clearRect;
				TRectFromP_RECT(clearRect,rect);
				console.ClearRect(clearRect);
				break;
				}
			case P_SCR_SCROLL:
				{
				P_RECTP* rectp=(P_RECTP*)aParam2;
				TRect area;
				TRectFromP_RECT(area,&(rectp->r));
				// don't use local function as it is an offset
				TPoint offset(OplUtil::GetWord(&rectp->p.x),OplUtil::GetWord(&rectp->p.y));
				console.ScrollRect(offset,area);
				break;
				}
			case P_SCR_NEL:
				console.Cr();
				console.Lf();
				break;
			case P_SCR_CURSOR:
				if (*(TUint8*)aParam2)
					console.DrawCursorIfOn(console.CurrentPos());
				else
					console.HideCursor();
				break;
			case P_SCR_SLOCK:
				console.SetScrollLock(*(TUint8*)aParam2);
				break;
			case P_SCR_WLOCK:
				console.SetWrapLock(!(*(TUint8*)aParam2));
				break;
			case P_SCR_LAST_LINE_WRAP:
				console.SetLastLineWrap(*(TUint8*)aParam2);
				break;
			// !!! Any more??
			default:
				User::RequestComplete(requestStatus,KErrArgument);
				return; // return here as there's been an error
			}
		break;
		}
	default:
		User::RequestComplete(requestStatus,KErrArgument);
		return; // return here as there's been an error
		}
	User::RequestComplete(requestStatus,KErrNone);
	}

#pragma warning ( disable: 4310) // cast truncates constant
#pragma warning ( disable: 4706) // assignment withing conditional expression
TInt16 CIOCollection::DoIOA(TInt16 aHandle,TInt16 aFuncNo,TOplReqStatus* aOplStatPtr, TAny* aParam1, TAny* aParam2)
	{
	TInt err=iRequestArray.Append(NULL);
	if (err==KErrNone)
		{
		const TInt indexOfRequest=iRequestArray.Count()-1;
		TIORequest*& request=iRequestArray[indexOfRequest];
		__ASSERT_DEBUG(request==NULL, User::Panic(KOplIOSystem, 14));
		if (aHandle==-2)
			{
			request=new TOplIORequest(aOplStatPtr,EActivePriorityWsEvents);
			if (request==NULL)
				{
				err=KErrNoMemory;
				}
			else
				{
				HandleConsoleRequest(aFuncNo,request->Status(),aParam1,aParam2);
				}
			}
		else if (aHandle==-1 && !(aHandle=iLHandle)) // trying Lxxx without calling LOPEN
			{
			err=KOplErrClosed;
			}
		else
			{
			TRAP(err,FindObjectL(aHandle)->RunFunctionL(aFuncNo,request,aOplStatPtr,aParam1,aParam2));
			}
		if (err)
			{
			__ASSERT_DEBUG(request==NULL, User::Panic(KOplIOSystem, 15));
			iRequestArray.Remove(indexOfRequest);
			}
		}
	return OplUtil::MapError(err);
	}
#pragma warning (default: 4706)

TInt16 CIOCollection::DoIow(CCoeEnv& aCoeEnv,TInt16 aHandle,TInt16 aFuncNo, TAny* aParam1, TAny* aParam2)
	{
	TOplReqStatus status=(TInt8)KOplErrFilePending;
	TInt16 err=DoIOA(aHandle,aFuncNo,&status,aParam1,aParam2);
	if (err)
		return err;
	iWsEventHandler->WaitForOplAsynchronousRequestCompletion16(aCoeEnv,&status);
	return status;
	}
#pragma warning (default: 4310)

TRequestStatus& CIOCollection::NewRequestL(TOplReqStatus* aStatusPtr,TInt aPriority,TCallBack aCallBack)
	{
	TOplIOCallBackRequest* request=(TOplIOCallBackRequest*)User::AllocLC(sizeof(TOplIOCallBackRequest));
	User::LeaveIfError(iRequestArray.Append(request));
	CleanupStack::Pop(); // request
	new(request) TOplIOCallBackRequest(aStatusPtr,aPriority,aCallBack);
	return request->Status();
	}

TRequestStatus& CIOCollection::NewRequestL(TInt32* aStatusPtr,TInt aPriority,TCallBack aCallBack)
	{
	TEraIOCallBackRequest* request=(TEraIOCallBackRequest*)User::AllocLC(sizeof(TEraIOCallBackRequest));
	User::LeaveIfError(iRequestArray.Append(request));
	CleanupStack::Pop(); // request
	new(request) TEraIOCallBackRequest(aStatusPtr,aPriority,aCallBack);
	return request->Status();
	}

CIOCollection::~CIOCollection()
	{
	TInt count;
	for (count=0;count<KMaxIOObjects;++count)
		{
		delete iObjArray[count];
		}
	iRequestArray.ResetAndDestroy();
	iRequestArray.Close();
	delete iWsEventHandler;
	}

//
// Class CWsEventHandler
//
CWsEventHandler::CWsEventHandler(RWsSession& aWsSession,CIOCollection* aIOCollection)
	:iWs(aWsSession),
	 iIOCollection(aIOCollection),
	 iIsSuspended(EFalse)
	{
	}

void CWsEventHandler::ConstructL(CCoeEnv& aCoeEnv)
	{
	iPriorityKeyHandler=CPriorityKeyHandler::NewL(iWs, *this);
	iOplActiveScheduler=COplActiveScheduler::NewL(aCoeEnv, *TheRuntime());
	iEventQueue=CEventQueue::NewL();
	iSignalBuffer=CSignalBuffer::NewL();
	iCommand=HBufC::NewL(1);
	iFepControl=NULL;
	}

CWsEventHandler::~CWsEventHandler()
	{
	delete iPriorityKeyHandler;
	delete iEventQueue;
	delete iSignalBuffer;
	delete iCommand;
	delete iOplActiveScheduler;
	}

void CWsEventHandler::Start()
	{
	iOplActiveScheduler->InstallOverConeActiveScheduler();
	iWs.EventReady(&iStatus);
	}

void CWsEventHandler::Stop()
	{
	iOplActiveScheduler->ReinstallConeActiveScheduler();
	iWs.EventReadyCancel();
	User::WaitForRequest(iStatus);	// returns straightaway as the iWs.EventReady request
									// has been canceled
	}

#if defined(_DEBUG)
TBool CWsEventHandler::IsStarted() const
	{
	return iOplActiveScheduler->IsInstalledOverConeActiveScheduler();
	}
#endif

TInt CWsEventHandler::HandleSpecialWsEvent(const TWsEvent& aWsEvent)
	{
	// Since this method cannot leave, TRAP the HandleWsEventL() call and return any error
	TInt error=KErrNone;
	const TEventCode type=(TEventCode)aWsEvent.Type();
	const TKeyEvent* key=(TKeyEvent*)aWsEvent.Key();
	if (type==EEventFocusGained || type==EEventFocusLost || key->iCode==EKeyIncBrightness)
		{
		// For Focus Gained/Lost events this ensures we handle both the application
		// screen fading and also notifications to foreground observers (e.g. Status Panes)
		//
		// For the Brightness key it ensures OPL apps properly let CKON cycle the screen
		// brightness with, for example, Chr+Space on Crystal.
		TRAP(error,TheRuntime()->HandleWsEventL(aWsEvent,NULL));
		}
	return error;
	}

void CWsEventHandler::PrepareToStartActiveScheduler(CCoeEnv&)
	{
	if (iOplActiveScheduler->IncConemodeNestCount()==KNoNestedDialogs) //just starting
		{
		COplActiveScheduler::SetMode(COplActiveScheduler::EModeCone);
		iEventQueue->PrepareToStartActiveScheduler();
		iWs.EventReadyCancel();
		User::WaitForRequest(iStatus);	// returns straightaway as the iWs.EventReady request
										// has been canceled
		iSignalBuffer->StartBufferingAnyUnhandledSignals();
		}
	}

void CWsEventHandler::NotifyActiveSchedulerStopped()
	{
	if (iOplActiveScheduler->DecConemodeNestCount()==KNoNestedDialogs) // now ending
		{
		COplActiveScheduler::SetMode(COplActiveScheduler::EModeOpl);
		iEventQueue->NotifyActiveSchedulerStopped();
		iWs.EventReady(&iStatus);
		iSignalBuffer->StopBufferingAndReplaceAnyBufferedSignals();
		iWs.Flush();
		}
	}

TUint CWsEventHandler::DoGetUnmapped(CCoeEnv& aCoeEnv)
	{
	TWsEvent event;
	WaitForEvent(aCoeEnv, event, EUserEventsKeysOnly);
	const TKeyEvent& key=*event.Key();
	iKMod=key.iModifiers;
	return key.iCode;
	}

TInt16 CWsEventHandler::DoGet(CCoeEnv& aCoeEnv)
	{
	return MapKeys(DoGetUnmapped(aCoeEnv));
	}

void CWsEventHandler::DoGetEvent(CCoeEnv& aCoeEnv, TInt16* aArray)
	{
	TBool done=EFalse;
	while (!done)
		{
		done=ETrue;
		TWsEvent event;
		WaitForEvent(aCoeEnv, event, EUserEventsAny);

		switch (event.Type())
			{
		case EEventKey:
			{
			const TKeyEvent& key=*event.Key();
			TInt mod=MapToOplMod(key.iModifiers);
			OplUtil::PutWord(aArray,MapKeys(key.iCode));
			OplUtil::PutWord(aArray+1,(TInt16)(mod | (key.iRepeats<<8)));
			break;
			}
		case EEventFocusGained:
			OplUtil::PutWord(aArray,0x401);
			break;
		case EEventFocusLost:
			OplUtil::PutWord(aArray,0x402);
			break;
		case EEventSwitchOn:
			OplUtil::PutWord(aArray,0x403);
			break;
//		case EEventSwitchOff:
//			OplUtil::PutWord(aArray,0x40B);
//			break;
		case EEventKeyDown:
			OplUtil::PutWord(aArray,0x406);
			break;
		case EEventKeyUp:
			OplUtil::PutWord(aArray,0x407);
			break;
		case EEventPointerEnter:
			OplUtil::PutWord(aArray,0x409);
			break;
		case EEventPointerExit:
			OplUtil::PutWord(aArray,0x40A);
			break;
		case EEventMessageReady:
			// same as EEventUser
			if (IsCreateOrOpenMessage(aCoeEnv, event))
				{
				OplUtil::PutWord(aArray,0x404);
				}
			else
				{
				done=EFalse;
				}
			break;
		case EEventUser: 
			// same as EEventMessageReady
			OplUtil::PutWord(aArray,0x404);
			SetCommand(event);
			break;
		case EEventPointer:
			OplUtil::PutWord(aArray,0x408);
			break;
		default:
			// unknown event type
			OplUtil::PutWord(aArray,0x400);
			break;
			}
		}
	}

void CWsEventHandler::DoGetEvent(CCoeEnv& aCoeEnv, TInt32* aArray)
	{
	TWsEvent event;
	TBool done=EFalse;
	while (!done)
		{
		WaitForEvent(aCoeEnv, event, EUserEventsAny);
		done=DoGetEventArrayWrite(aCoeEnv, event,aArray);
		}
	}

TBool CWsEventHandler::DoGetEventArrayWrite(CCoeEnv& aCoeEnv, const TWsEvent& aEvent,TInt32* aArray)
	{
	TOplEventBuf eventBuf;
	TOplPointerEventBuf pointerEventBuf;
	TInt id=(TInt)aEvent.Handle();
	if (id==0)
		id=1;
	TInt64 time64=aEvent.Time().Int64();
	eventBuf.iTimeStamp=time64.GetTInt();
	const TKeyEvent& key=*aEvent.Key();
	TInt mod=MapToOplMod(key.iModifiers);

	const TEventCode type=(TEventCode)aEvent.Type();

⌨️ 快捷键说明

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