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

📄 eik_key.cpp

📁 在手机操作系统symbina上使用的一个脚本扩展语言的代码实现,可以参考用于自己的开发
💻 CPP
📖 第 1 页 / 共 4 页
字号:
// EEikBidCancel never gets here
//			case EEikBidCancel:
//				bid=EKeyEscape;
//				break;
			case EEikBidSpace:
				bid=EKeySpace;
				break;
			default:
				bid=aButtonId;
				break;
				}
			*iReturnPtr=(TInt16)bid;
			}
		else
			{ // Dialogs with no buttons
			TInt id=IdOfFocusControl();
			if (id)
				*iReturnPtr=(TInt16)(id-KOplDialogIdBase);
			else
				*iReturnPtr=TInt16(1);
			}
		}
#if defined(__UIQ__)
	for(TInt loop=KOplDialogIdBase;loop<iNextId;loop++) // save data in controls
	{
		CEikCaptionedControl* line=Line(loop+1);
		if(line->iReturnValue!=NULL)
			GetCustomAutoValue(line->iReturnValue,line->iControlType,line->iControl);
	}
#endif
	return ETrue;
	}

void COplDialog::AddTitleL(const TDesC& aTitle)
	{
	SetTitleL(aTitle);
//!!TODOUIQ Removed from UIQ, yet OPL needs nextId != KOplDialogIdBase to prevent structure fault.
// So this needs to be retested on UIQ and Crystal.
#if !defined(__UIQ__)
	++iNextId;
#endif
	}

void COplDialog::SetCorner(TInt aXPos,TInt aYPos)
	{
	// assume aXPos and aYPos are -1,0 or 1
	TInt corner=aXPos+1+(0x10*(aYPos+1));
	iCorner=(TGulAlignmentValue)corner;
	}

void COplDialog::SetSizeAndPosition(const TSize& aSize)
	{
	// Set dialog size and position as requested normally
	SetCornerAndSize(iCorner,aSize);

	// Get bounded size (by Status Pane and CBA) so we can prevent dialog
	// exceeding these boundaries
#if defined(__UIQ__)
	const TSize screenSize=iEikonEnv->EikAppUi()->ClientRect().Size();
#else
	const TSize screenSize=iCoeEnv->ScreenDevice()->SizeInPixels();
#endif
	TRect boundingRect(screenSize);
	CEikButtonGroupContainer& buttonGroup=ButtonGroupContainer();
	if (&buttonGroup)
		{
		// Must do this here else the cba is not sized
		buttonGroup.SetBoundingRect(boundingRect);
		buttonGroup.ReduceRect(boundingRect);
		}
	CEikStatusPaneBase* statusPane = CEikStatusPaneBase::Current();
	if(statusPane)
		statusPane->ReduceRect(boundingRect);
	
	// Compare the current dialog size to maximum bounded size. SetCornerAndSize seems
	// to correctly set the size of the dialog but the position is not reflected in the
	// value returned by Rect() so we manually fix this using Position()
	TRect currentRect=Rect();
	TPoint currentPos=Position();
	currentRect.iTl.iX=currentPos.iX;
	currentRect.iBr.iX += currentPos.iX;
	currentRect.iTl.iY=currentPos.iY;
	currentRect.iBr.iY += currentPos.iY;

	// Slight hack for dialogs dPOSITIONed right up against the CBA, this prevents
	// their width from shrinking when the other settings are made below
	//
	// Currently assumes CBA is always vertical and on right!!
	if ((iCorner&EHRight) && (&buttonGroup))
		currentRect.iTl.iX=currentPos.iX-(screenSize.iWidth-boundingRect.iBr.iX);

	if (currentRect.iBr.iX>boundingRect.iBr.iX)
		currentRect.iBr.iX=boundingRect.iBr.iX;
	if (currentRect.iTl.iX<boundingRect.iTl.iX)
		currentRect.iTl.iX=boundingRect.iTl.iX;
	if (currentRect.iBr.iY>boundingRect.iBr.iY)
		currentRect.iBr.iY=boundingRect.iBr.iY;
	if (currentRect.iTl.iY<boundingRect.iTl.iY)
		currentRect.iTl.iY=boundingRect.iTl.iY;

	// Now reset the Rect area to ensure dialog fits within appropriate bounds
	SetRect(currentRect);
	}

SEikControlInfo COplDialog::CreateCustomControlL(TInt aType)
	{
	if (aType==KOplMultiLineTextEditor)
		aType=EEikCtEdwin;
	SEikControlInfo ret;
	ret.iControl = NULL;
	ret.iTrailerTextId = 0;
	ret.iFlags = 0;
#if !defined(__SERIES60__)
	switch (aType)
		{
	case KOplDriveNameSel:
		ret.iControl=new(ELeave) COplDriveNameSelector();
		ret.iFlags|=EEikControlHasEars;
		break;
	case KOplFileSelector:
		ret.iControl=new(ELeave) COplFileNameSelector();
		ret.iFlags|=EEikControlHasEars;
		break;
	case KOplFileEditor:
		ret.iControl=new(ELeave) COplFileNameEditor();
		break;
	case KOplFolderNameEd:
		ret.iControl=new(ELeave) COplFolderNameEditor();
		break;
	case KOplFolderNameSel:
		ret.iControl=new(ELeave) COplFolderNameSelector();
		break;
	default:
		ret=EikControlFactory::CreateByTypeL(aType&~KOplDialogItem);
		break;
		}
#else
	ret=EikControlFactory::CreateByTypeL(aType&~KOplDialogItem);
#endif
	if (aType==KOplTextLabel)
		ret.iFlags&=~EEikControlIsNonFocusing;
	return ret;
	}

void COplDialog::GetCustomAutoValue(TAny* aReturn,TInt aType,const CCoeControl* aControl)
	{
	switch (aType)
		{
	case (KOplLongEditor):
		{
#if defined(__UIQ__)
		OplUtil::PutLong(aReturn,((CQikNumberEditor*)aControl)->Value());
#else
		OplUtil::PutLong(aReturn,((CEikNumberEditor*)aControl)->Number());
#endif
		break;
		}
	case (KOplFloatEditor):
		{
#if defined(__UIQ__)
		OplUtil::PutFloat(aReturn,((CQikFloatingPointEditor*)aControl)->Value());
#else
		OplUtil::PutFloat(aReturn,((CEikFloatingPointEditor*)aControl)->Value());
#endif
		break;
		}
	case (KOplTextEditor):
		{
		TPtr ptr((TText*)((TUint8*)aReturn+1+KOplAlignment),255);
		((CEikEdwin*)aControl)->GetText(ptr);
		*(TUint8*)aReturn=(TUint8)ptr.Length();
		break;
		}
	case (KOplMultiLineTextEditor):
		{
		TPtr ptr((TText*)((TInt32*)aReturn+1),KMaxTInt); // KOplAlignment NOT needed (or last 2 chars get lost)
		((CEikEdwin*)aControl)->GetText(ptr);
		OplUtil::PutLong((TInt32*)aReturn,ptr.Length());
		break;
		}
#if !defined(__SERIES60__)
	case (KOplChoiceList):
		{
		OplUtil::PutWord(aReturn,(TInt16)(((CEikChoiceList*)aControl)->CurrentItem()+1));
		break;
		}
#endif
	case (KOplSecretEditor):
		{
		TPtr ptr((TText*)((TUint8*)aReturn+1+KOplAlignment),255);
		((CEikSecretEditor*)aControl)->GetText(ptr);
		*(TUint8*)aReturn=(TUint8)ptr.Length();
		break;
		}
	case (KOplTimeEditor):
		{
#if defined(__UIQ__)
		TTime time=((CQikTimeEditor*)aControl)->Time();
#else
		TTime time=((CEikTimeEditor*)aControl)->Time();
#endif
		TInt64 timeInt=time.Int64();
		timeInt/=1000000;
		OplUtil::PutLong(aReturn,timeInt.Low());
		break;
		}
	case (KOplDurationEditor):
		{
#if defined(__UIQ__)
		TTimeIntervalSeconds duration=((CQikDurationEditor*)aControl)->Duration();
#else
		TTimeIntervalSeconds duration=((CEikDurationEditor*)aControl)->Duration();
#endif
		OplUtil::PutLong(aReturn,duration.Int());
		break;
		}
	case (KOplDateEditor):
		{
#if defined(__UIQ__)
		TTime time=((CQikDateEditor*)aControl)->Time();
#else
		TTime time=((CEikDateEditor*)aControl)->Date();
#endif
		TDateTime startDate(1900,TMonth(0),0,0,0,0,0);
		TTime sTime(startDate);
		OplUtil::PutLong(aReturn,time.DaysFrom(sTime).Int());
		break;
		}
#if !defined(__SERIES60__)
	case (KOplFileSelector):
		{
		TPtr ptr((TText*)((TUint8*)aReturn+1+KOplAlignment),255);
		ptr=((COplFileNameSelector*)aControl)->FullName();
		*(TUint8*)aReturn=(TUint8)ptr.Length();
		break;
		}
	case (KOplFileEditor):
		{
		TPtr ptr((TText*)((TUint8*)aReturn+1+KOplAlignment),255);
		ptr=((COplFileNameEditor*)aControl)->FullName();
		*(TUint8*)aReturn=(TUint8)ptr.Length();
		break;
		}
	case (KOplFolderNameSel):
		{
		TPtr ptr((TText*)((TUint8*)aReturn+1+KOplAlignment),255);
		ptr=((COplFolderNameSelector*)aControl)->FullName();
		*(TUint8*)aReturn=(TUint8)ptr.Length();
		break;
		}
	case (KOplFolderNameEd):
		{
		TPtr ptr((TText*)((TUint8*)aReturn+KOplAlignment),255);
		ptr=((COplFolderNameEditor*)aControl)->Name();
		*(TUint8*)aReturn=(TUint8)ptr.Length();
		break;
		}
#endif
/*	case (KOplCheckBox):
		{
		OplUtil::PutWord(aReturn,(TInt16)((((CEikCheckBox*)aControl)->State()==CEikButtonBase::ESet)?KOplTrue:KOplFalse));
		break;
		}
*/	default:
		_LIT(KOplDialogs,"Opl Dialogs");
		User::Panic(KOplDialogs,1);
		}
	}

void COplDialog::AddLongEditorL(const TDesC& aPrompt,TInt aMin,TInt aMax,TAny* aReturn)
	{
#if defined(__UIQ__)
	CQikNumberEditor* numEd=(CQikNumberEditor*)CreateLineByTypeL(aPrompt,++iNextId,KOplLongEditor,aReturn);
#else
	CEikNumberEditor* numEd=(CEikNumberEditor*)CreateLineByTypeL(aPrompt,++iNextId,KOplLongEditor,aReturn);
#endif
	TInt init=OplUtil::GetLong(aReturn);
	if (init<aMin)
		init=aMin;
	else if (init>aMax)
		init=aMax;
	numEd->ConstructL(aMin,aMax,init);
	}

void COplDialog::AddFloatEditorL(const TDesC& aPrompt,TReal64 aMin,TReal64 aMax,TAny* aReturn)
	{
#if defined(__UIQ__)
	CQikFloatingPointEditor* flPtEd=(CQikFloatingPointEditor*)CreateLineByTypeL(aPrompt,++iNextId,KOplFloatEditor,aReturn);
#else
	CEikFloatingPointEditor* flPtEd=(CEikFloatingPointEditor*)CreateLineByTypeL(aPrompt,++iNextId,KOplFloatEditor,aReturn);
#endif
	flPtEd->ConstructL(aMin,aMax,18);
	TReal64 real(OplUtil::GetFloat(aReturn));
	if (real<aMin)
		real=aMin;
	else if (real>aMax)
		real=aMax;
#if defined(__UIQ__)
	flPtEd->SetValueL(real);
#else
	flPtEd->SetValueL(&real);
#endif
	}

void COplDialog::AddTextEditorL(const TDesC& aPrompt,TInt aWidthInChars,TInt aMaxLength,TText* aReturn)
	{ // aReturn is a pointer to the length byte
	CEikEdwin* edwin=(CEikEdwin*)CreateLineByTypeL(aPrompt,++iNextId,KOplTextEditor,aReturn);
	edwin->ConstructL(0,aWidthInChars,aMaxLength,1);
	TUint8* ptr8=(TUint8*)aReturn;
	TPtr ptr((TText*)(ptr8+1+KOplAlignment),*ptr8,aMaxLength);
	// Set the edwin from the des contents.
	edwin->SetTextL(&ptr);
	}

#if !defined(__SERIES60__)
CDesCArray* COplDialog::AddChoiceListL(const TDesC& aPrompt,TAny* aReturn,TBool aIncrementalMatching)
	{
	CEikChoiceList* list;
	if (iLastCreatedChoiceListId)
		{
		CEikCaptionedControl* line=Line(iLastCreatedChoiceListId);
		if (line->iReturnValue!=aReturn)
			User::Leave(KErrArgument);
		list=(CEikChoiceList*)(line->iControl);
		}
	else
		{
		list = (CEikChoiceList*)CreateLineByTypeL(aPrompt,++iNextId,KOplChoiceList,aReturn);
		list->ConstructL(list,0,0);
		CDesCArray* array=new(ELeave) CDesCArraySeg(4);
		list->SetArrayL(array); // takes ownership BEFORE it can leave!
		list->SetIncrementalMatching(aIncrementalMatching);
		iLastCreatedChoiceListId=iNextId;
		}
	return list->DesCArray();
	}
#else
CDesCArray* COplDialog::AddChoiceListL(const TDesC&,TAny*,TBool)
	{
	return (CDesCArray*)NULL;
	}
#endif

#if defined(__SERIES60__)
void COplDialog::ChoiceListFinishedL() {}
#else
void COplDialog::ChoiceListFinishedL()
	{
	if (!iLastCreatedChoiceListId)
		User::Leave(KOplStructure);
	CEikCaptionedControl* line=Line(iLastCreatedChoiceListId);
	CEikChoiceList* list=(CEikChoiceList*)(line->iControl);
	TInt current=(*(TUint16*)(line->iReturnValue));
	if (current==0)
		current=1;
	else 
		{
		TInt count=list->Array()->MdcaCount();
		if (current>count)
			current=count;
		}
	list->SetCurrentItem(current-1);
	iLastCreatedChoiceListId=0;
	}
#endif

void COplDialog::AddSecretEditorL(const TDesC& aPrompt,TInt aMaxLength,TText* aReturn, TBool aSeedTextContents)
	{
	CEikSecretEditor* secEd = (CEikSecretEditor*)CreateLineByTypeL(aPrompt,++iNextId,KOplSecretEditor,aReturn);
#if defined(__SERIES60__)
	TInt actualMaxLength=(aMaxLength<CEikSecretEditor::EMaxSecEdBufLength)?aMaxLength:CEikSecretEditor::EMaxSecEdBufLength;
#else
	TInt actualMaxLength=(aMaxLength<CEikSecretEditor::EMaxSecEdLength)?aMaxLength:CEikSecretEditor::EMaxSecEdLength;
#endif
	secEd->SetMaxLength(actualMaxLength);
	if (aSeedTextContents)
		{
		TUint8* ptr8=(TUint8*)aReturn;
		TPtr ptr((TText*)(ptr8+1+KOplAlignment),*ptr8,actualMaxLength);
		secEd->SetText(ptr);
		}
	}

void COplDialog::AddTextLabelL(const TDesC& aPrompt,const TDesC& aBody,TInt aFlags)
	{
	if (aPrompt.Length()==0 && aBody.Length()==0)
		{
		if (aFlags==0x800)
			{
			if (iNextId==KOplDialogIdBase) // no items added
				User::Leave(KOplStructure);
			Line(iNextId++)->SetDividerAfter(ETrue);
			}
		else
			User::Leave(KErrArgument);
		}
	else
		{
		TGulAlignment align=EHLeftVTop;
		if ((aFlags&0x3)==1)
			align=EHRightVTop;
		else if ((aFlags&0x3)==2)
			align=EHCenterVTop;
		TInt type=EEikCtLabel;
		if (aFlags&0x400)
			type=KOplTextLabel;
		CEikLabel* label=(CEikLabel*)CreateLineByTypeL(aPrompt,++iNextId,type,NULL);
		label->SetTextL(aBody);
		label->iAlignment=align;
		if (aFlags&0x200)
			Line(iNextId)->SetDividerAfter(ETrue);
		}
	}

void COplDialog::AddTimeEditorL(const TDesC& aPrompt,TUint aMinTime,TUint aMaxTime,TInt aFlags,TAny* aReturn)
	{// assumes aFlags and times are valid
#if defined(__UIQ__)
	TInt flags=0;
	if (aFlags&0x8)
		flags|=EQikTimeForce24HourFormat;
#else
	TInt flags=(aFlags&0x1)?0:EEikTimeWithoutSecondsField;
	if (aFlags&0x4)
		flags|=EEikTimeWithoutHoursField;
	if (aFlags&0x8)
		flags|=EEikTimeForce24HourFormat;
#endif
	if (~aFlags&0x2)
		{
#if defined(__UIQ__)
		CQikTimeEditor* timeEd = (CQikTimeEditor*)CreateLineByTypeL(aPrompt,++iNextId,KOplTimeEditor,aReturn);
#else
		CEikTimeEditor* timeEd = (CEikTimeEditor*)CreateLineByTypeL(aPrompt,++iNextId,KOplTimeEditor,aReturn);
#endif
		TInt64 maxInt=aMaxTime;
		TInt64 minInt=aMinTime;
		TInt64 initInt=TUint(OplUtil::GetLong(aReturn));
		if (initInt<minInt)
			initInt=minInt;
		else if (initInt>maxInt)
			initInt=maxInt;
		TTime max(maxInt*1000000);
		TTime min(minInt*1000000);
		TTime init(initInt*1000000);
		timeEd->ConstructL(min,max,init,flags);
		}
	else
		{
#if defined(__UIQ__)
		CQikDurationEditor* timeEd = (CQikDurationEditor*)CreateLineByTypeL(aPrompt,++iNextId,KOplDurationEditor,aReturn);
#else
		CEikDurationEditor* timeEd = (CEikDurationEditor*)CreateLineByTypeL(aPrompt,++iNextId,KOplDurationEditor,aReturn);
#endif
		TUint init=OplUtil::GetLong(aReturn);

⌨️ 快捷键说明

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