📄 iomain.cpp
字号:
switch (type)
{
// Not yet dealt with/ignored:
// EEventModifiersChanged, EEventDragDrop, EEventPassword
case EEventKeyDown:
eventBuf.iCode=0x406;
eventBuf.iScanOrWinId=key.iScanCode;
eventBuf.iModifiers=mod;
#if defined(__UIQ__)
if(key.iScanCode==EStdQuartzKeyConfirm)
eventBuf.iScanOrWinId=EStdKeyMenu;
#endif
break;
case EEventKeyUp:
eventBuf.iCode=0x407;
eventBuf.iScanOrWinId=key.iScanCode;
eventBuf.iModifiers=mod;
#if defined(__UIQ__)
if(key.iScanCode==EStdQuartzKeyConfirm)
eventBuf.iScanOrWinId=EStdKeyMenu;
#endif
break;
case EEventKey:
eventBuf.iCode=key.iCode;
eventBuf.iScanOrWinId=key.iScanCode;
eventBuf.iModifiers=mod;
eventBuf.iRepeat=key.iRepeats;
#if defined(__UIQ__)
if(key.iCode==EQuartzKeyConfirm)
{
eventBuf.iCode=EKeyMenu;
eventBuf.iScanOrWinId=EStdKeyMenu;
}
#endif
break;
case EEventPointerEnter:
eventBuf.iCode=0x409;
eventBuf.iScanOrWinId=id;
break;
case EEventPointerExit:
eventBuf.iCode=0x40A;
eventBuf.iScanOrWinId=id;
break;
case EEventFocusGained:
eventBuf.iCode=0x401;
break;
case EEventFocusLost:
eventBuf.iCode=0x402;
break;
case EEventSwitchOn:
eventBuf.iCode=0x403;
break;
// case EEventSwitchOff:
// eventBuf.iCode=0x40B;
// break;
case EEventMessageReady:
// same as EEventUser
if (IsCreateOrOpenMessage(aCoeEnv, aEvent))
{
eventBuf.iCode=0x404;
}
else
{
return EFalse;
}
break;
case EEventUser:
// same as EEventMessageReady
eventBuf.iCode=0x404;
SetCommand(aEvent);
break;
case EEventPointer:
pointerEventBuf.iCode=0x408;
default:
if (type!=EEventPointer)
pointerEventBuf.iCode=type | EOplEventUnknown; // unknown event type (EEventUser), pass it on
pointerEventBuf.iTimeStamp=time64.GetTInt();
pointerEventBuf.iWinId=id;
pointerEventBuf.iPointer=*aEvent.Pointer();
Mem::Copy(aArray,&pointerEventBuf,sizeof(TOplPointerEventBuf));
return ETrue;
}
Mem::Copy(aArray,&eventBuf,sizeof(TOplEventBuf));
return ETrue;
}
void CWsEventHandler::SetCommand(const TWsEvent& aEvent)
{
switch (*(TInt*)aEvent.EventData())
{
case EApaSystemEventShutdown:
*iCommand=KLitX;
break;
case EApaSystemEventBackupStarting:
*iCommand=KLitS;
break;
case EApaSystemEventBackupComplete:
*iCommand=KLitR;
break;
case EApaSystemEventBroughtToForeground:
*iCommand=KLitF;
break;
default:
*iCommand=KLitU;
}
}
TBool CWsEventHandler::IsCreateOrOpenMessage(CCoeEnv& aCoeEnv, const TWsEvent& aEvent)
{
TBool returnValue=EFalse;
TRAPD(error, returnValue=IsCreateOrOpenMessageL(aCoeEnv, aEvent));
HandleError(error);
return returnValue;
}
TBool CWsEventHandler::IsCreateOrOpenMessageL(CCoeEnv& aCoeEnv, const TWsEvent& aEvent)
{
TUid messageUid=KNullUid;
TPtr8 messageParameters(NULL, 0, 0);
aCoeEnv.GetMessageNotifyingObserversLC(aEvent.Handle(), messageUid, messageParameters, aEvent);
const TPtrC commandParameters((TText*)messageParameters.Ptr(), messageParameters.Length()/sizeof(TText));
const TInt commandLength=1+commandParameters.Length();
if (iCommand->Des().MaxLength()<commandLength)
{
iCommand=iCommand->ReAllocL(commandLength);
}
TPtr command(iCommand->Des());
TBool returnValue=EFalse;
switch (messageUid.iUid)
{
case KUidApaMessageSwitchCreateFileValue:
command=KLitC;
command.Append(commandParameters);
returnValue=ETrue;
break;
case KUidApaMessageSwitchOpenFileValue:
command=KLitO;
command.Append(commandParameters);
returnValue=ETrue;
break;
}
CleanupStack::PopAndDestroy(); // stuff left on cleanup-stack
// by GetMessageNotifyingObserversLC
return returnValue;
}
TInt16 CWsEventHandler::DoKey(CCoeEnv& aCoeEnv)
{
iKMod=0;
TInt16 code=0;
TWsEvent event;
if (IsEventReady(aCoeEnv, &event, EUserEventsKeysOnly))
{
__ASSERT_DEBUG(event.Type()==EEventKey, User::Panic(KOplIOSystem, 13));
const TKeyEvent& key=*event.Key();
iKMod=key.iModifiers;
code=MapKeys(key.iCode);
}
return code;
}
TInt16 CWsEventHandler::DoKmod()
{
return MapToOplMod(iKMod);
}
#pragma warning ( disable: 4310) // cast truncates constant
void CWsEventHandler::DoCancelOplAsynchronousWservRequest(TInt16* aStatPtr)
{
DoCancelOplAsynchronousWservRequestWithoutConsumingSignal(aStatPtr);
User::WaitForAnyRequest(); // returns straightaway as we're consuming the signal
// associated with the canceled event (however, if
// aStatPtr!=iStatPtr and both are non-NULL, this may hang
// indefinitely - this is the same behaviour as EPOC16 OPL,
// it basically means there's a bug in the OPL program)
}
void CWsEventHandler::DoCancelOplAsynchronousWservRequestWithoutConsumingSignal(TInt16* aStatPtr)
{
if ((iStatPtr!=NULL) && (iStatPtr==aStatPtr))
{
OplUtil::PutWord(iStatPtr,(TInt16)KOplErrIOCancelled);
iStatPtr=NULL;
iArrayPtr=NULL;
Signal(1);
}
}
void CWsEventHandler::DoKeyA(CCoeEnv& aCoeEnv,TInt16* aStatPtr,TInt16* aArrayPtr)
{
if (iStatPtr!=NULL)
{
DoCancelOplAsynchronousWservRequest(iStatPtr);
}
iKeysOnly=ETrue;
iStatPtr=aStatPtr;
OplUtil::PutWord(iStatPtr,(TInt16)KOplErrFilePending);
iArrayPtr=aArrayPtr;
IsEventReady(aCoeEnv, NULL, EUserEventsAny); // this completes the request immediately
// if possible
}
void CWsEventHandler::DoGetEventA(CCoeEnv& aCoeEnv,TInt16* aStatPtr,TInt32* aArrayPtr)
{
if (iStatPtr!=NULL)
{
DoCancelOplAsynchronousWservRequest(iStatPtr);
}
iKeysOnly=EFalse;
iStatPtr=aStatPtr;
OplUtil::PutWord(iStatPtr,(TInt16)KOplErrFilePending);
iArrayPtr=aArrayPtr;
IsEventReady(aCoeEnv, NULL, EUserEventsAny); // this completes the request immediately
// if possible
}
#pragma warning (default: 4310)
TBool CWsEventHandler::DoTestEvent(CCoeEnv& aCoeEnv)
{
return IsEventReady(aCoeEnv, NULL, EUserEventsAny);
}
void CWsEventHandler::DoConsumeEvent(CCoeEnv& aCoeEnv)
{
TWsEvent ignoredEvent;
IsEventReady(aCoeEnv, &ignoredEvent, EUserEventsKeysOnly);
}
TBool CWsEventHandler::IsEventReady(CCoeEnv& aCoeEnv, TWsEvent* aEvent, TUserEventsRequired aUserEventsRequired)
// Consumes the event (and its signal) if there is one *and* if aEvent!=NULL
// KEY/TESTEVENT (both of which call this function) have lower priority than
// KEYA (which is handled by the EventCompletesAnyOplAsynchronousWservRequest calls
// in this function)
//
// For Crystal we need to acknowledge focus changes because application views
// get dimmed in the background. This method was altered by PhilS on
// 24/10/2001 to include the HandleSpecialWsEvent() check below to
// allow for this. Doing this check here ensures KEY/TESTEVENT still get
// Focus gained/lost events actioned. GET/GETEVENT functions are taken care of
// with an identical check in CWsEventHandler::OfferEventToUserEventHandler()
{
__ASSERT_DEBUG(iEventQueue->BackupIsEmpty(), User::Panic(KOplIOSystem, 20));
if ((aUserEventsRequired==EUserEventsKeysOnly) && (aEvent!=NULL))
{
iEventQueue->PurgeAllNonKeyEvents();
}
iIOCollection->HandleAnyCompletedOplAsynchronousRequests(); // a good opportunity to call this
for (TInt i=0; i<10; ++i) // only allow a finite number of iterations of this loop to
// prevent this function from taking too long to execute
{
__ASSERT_DEBUG(iEventQueue->BackupIsEmpty(), User::Panic(KOplIOSystem, 23));
while (iEventQueue->IsNotEmpty())
{
TWsEvent event;
iEventQueue->PeekNextEvent(event);
if (EventCompletesAnyOplAsynchronousWservRequest(aCoeEnv, event))
{
iEventQueue->ConsumeNextEvent();
User::WaitForAnyRequest(); // returns straightaway as we're consuming the signal
// associated with the event that has just been taken
// out of iEventQueue
}
else if ((aUserEventsRequired==EUserEventsAny) ||
((aUserEventsRequired==EUserEventsKeysOnly) && (event.Type()==EEventKey)))
{
if (aEvent!=NULL)
{
iEventQueue->ConsumeNextEvent();
User::WaitForAnyRequest(); // returns straightaway as we're consuming the
// signal associated with the event that has just
// been taken out of iEventQueue
*aEvent=event;
}
iEventQueue->RestoreAllEventsFromBackup();
return ETrue;
}
else
{
iEventQueue->PutNextEventInBackup();
User::WaitForAnyRequest(); // returns straightaway as we're consuming the signal
// associated with the event that has just been put
// in iEventQueue's backup
}
}
iEventQueue->RestoreAllEventsFromBackup();
if (iStatus==KRequestPending)
{
return EFalse;
}
User::WaitForRequest(iStatus); // returns straightaway as iStatus has already completed
TWsEvent event;
iWs.GetEvent(event);
iWs.EventReady(&iStatus);
// get this inside the loop in case it changes between iterations
CCoeFep* const fep=aCoeEnv.Fep();
if ((fep==NULL) || (OfferEventToFep(*fep, event)==CCoeFep::EEventWasNotConsumed))
{
// Here we can do checks for special events/keys, calling HandleSpecialWsEvent()
// if appropriate. Currently we check for:
//
// 1) EEventFocusGained
// 2) EEventFocusLost
// 3) The EKeyIncBrightness key
const TEventCode type=(TEventCode)event.Type();
const TKeyEvent* key=(TKeyEvent*)event.Key();
if (type==EEventFocusGained || type==EEventFocusLost || key->iCode==EKeyIncBrightness)
HandleSpecialWsEvent(event);
// Now continue with the rest of the processing as normal
if (!EventCompletesAnyOplAsynchronousWservRequest(aCoeEnv, event))
{
if ((aUserEventsRequired==EUserEventsAny) ||
((aUserEventsRequired==EUserEventsKeysOnly) && (type==EEventKey)))
{
if (aEvent!=NULL)
{
*aEvent=event;
return ETrue;
}
const TInt error=iEventQueue->AppendEvent(event);
HandleError(error);
return (error==KErrNone);
}
const TInt error=iEventQueue->AppendEvent(event);
HandleError(error);
if (error!=KErrNone)
{
return EFalse;
}
}
}
}
iWs.Flush();
return EFalse;
}
#pragma warning ( disable: 4310) // cast truncates constant
void CWsEventHandler::DoPauseL(CCoeEnv& aCoeEnv, TInt16 aDelay)
{
TWsEvent event;
const TInt KDummyEventType=-1;
event.SetType(KDummyEventType);
if (aDelay==0)
{
WaitForEvent(aCoeEnv, event, EUserEventsKeysOnly);
}
else
{
RTimer timer;
CleanupClosePushL(timer);
User::LeaveIfError(timer.CreateLocal());
TRequestStatus timStat;
timer.After(timStat, Abs(aDelay*(1000000/20)));
TTimerEventSource timerEventSource(timer, timStat, EActivePriorityWsEvents-1);
TFixedArray<MEventSource*, 1> timerEventSourceArray;
timerEventSourceArray[0]=&timerEventSource;
WaitForEvent(aCoeEnv, event, (aDelay>0)? EUserEventsNone: EUserEventsKeysOnly, timerEventSourceArray.Array());
CleanupStack::PopAndDestroy(); // timer
}
if (event.Type()!=KDummyEventType)
{
User::LeaveIfError(iEventQueue->AppendEvent(event));
}
}
#pragma warning (default: 4310)
void CWsEventHandler::Signal(TInt aNumberOfSignals)
{
__ASSERT_DEBUG(aNumberOfSignals>=0, User::Panic(KOplIOSystem, 10));
TRequestStatus requestStatus;
for (TInt i=0; i<aNumberOfSignals; ++i)
{
TRequestStatus* requestStatusPointer=&requestStatus;
User::RequestComplete(requestStatusPointer, KErrNone);
}
}
TBool CWsEventHandler::EventCompletesAnyOplAsynchronousWservRequest(CCoeEnv& aCoeEnv, const TWsEvent& aEvent)
{
if (iStatPtr==NULL)
{
return EFalse;
}
if (!iKeysOnly)
{
if (!DoGetEventArrayWrite(aCoeEnv, aEvent,(TInt32*)iArrayPtr))
{
return EFalse;
}
}
else
{
if (aEvent.Type()!=EEventKey)
{
return EFalse;
}
const TKeyEvent& key=*aEvent.Key();
OplUtil::PutWord(iArrayPtr,MapKeys(key.iCode));
OplUtil::PutWord((TInt16*)iArrayPtr+1,(TInt16)(256*(key.iRepeats)+(TUint8)MapToOplMod(key.iModifiers)));
}
OplUtil::PutWord(iStatPtr,0);
iStatPtr=NULL;
iArrayPtr=NULL;
Signal(1);
return ETrue;
}
LOCAL_C TInt ZeroReturner(const CBase*)
{
return 0;
}
void CWsEventHandler::HandleAnyCompletedEvents(CCoeEnv& aCoeEnv, TInt aMaximumNumberOfCompletedEventsToHandle)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -