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

📄 eik_key.cpp

📁 在手机操作系统symbina上使用的一个脚本扩展语言的代码实现,可以参考用于自己的开发
💻 CPP
📖 第 1 页 / 共 4 页
字号:
					User::Leave(KErrArgument);
				dialog->AddFolderSelectorL(p1,p2,flags,ptr);
				}
			}
		else
			{
			if (flags&KFileSelectorFlagEditor) //editor
				dialog->AddFileEditorL(p1,p2,p3,flags,ptr);
			else //selector
				dialog->AddFileSelectorL(p1,p2,p3,flags,uidType,ptr);
			}
		break;
		}
	case 10:
		{
		// Can't call dBUTTONs more than once in the same dialog
		if (dialog->HasButtons())
			User::Leave(KOplStructure);
		const TInt butCount=aRuntime.IP8();// Number of buttons in container
		if (butCount>KMaxSupportedButtons)
			User::Leave(KOplStructure);

		// Create the empty container.
#if !defined(__UIQ__)
		CEikButtonGroupContainer* buttonPanel=
			CEikButtonGroupContainer::NewL(CEikButtonGroupContainer::EDialog,
				CEikButtonGroupContainer::EVertical, dialog->ButtonCommandObserver(), 
				NULL, *dialog);
#else
//!!TODOUIQ Where are the uiq classes here?
		CEikButtonGroupContainer* buttonPanel=
			CEikButtonGroupContainer::NewL(CEikButtonGroupContainer::EDialog,
				CEikButtonGroupContainer::EHorizontal, dialog->ButtonCommandObserver(), 
				NULL, *dialog);
#endif
		CleanupStack::PushL(buttonPanel);

		// Create some buttons
		CArrayFixSeg<SOplButton>* buttons=new(ELeave) CArrayFixSeg<SOplButton>(KMaxSupportedButtons);
		CleanupStack::PushL(buttons);
		SOplButton buttonAndId;
		SOplButton unusedButton;
		unusedButton.iId=0;

		for (TInt ii=butCount;--ii>=0;)
			{
			TInt id=aStack.PopInt16();
			TBool isCancel=EFalse;
			if (id<0)
				{
				id=(-id);
				isCancel=ETrue;
				}
			CEikButtonGroupContainer::THotKeyFlags hotKeyFlags=CEikButtonGroupContainer::EShowHotKey;
			if (id&EOplDialogButtonPlainHotKey)
				hotKeyFlags=STATIC_CAST(CEikButtonGroupContainer::THotKeyFlags,hotKeyFlags|CEikButtonGroupContainer::EPlainHotKey);
			if (id&EOplDialogButtonHideHotKey)
				hotKeyFlags=STATIC_CAST(CEikButtonGroupContainer::THotKeyFlags,hotKeyFlags&~CEikButtonGroupContainer::EShowHotKey);
			id&=~(EOplDialogButtonHideHotKey|EOplDialogButtonPlainHotKey); // Remove flags
			switch(id)
				{
			case 0:
				id=EEikBidBlank;
				break;
			case EKeyBackspace:
				id=EEikBidDelete;
				break;
			case EKeyTab:
				id=EEikBidTab;
				break;
			case EKeyEnter:
				id=EEikBidOk;
				break;
			case EKeyEscape:
				id=EEikBidCancel;
				break;
			case EKeySpace:
				id=EEikBidSpace;
				break;
			default:
				id=User::LowerCase(id);
				if (!(id>='a' && id<='z'))
					User::Leave(KErrArgument);
				break;
				}
			buttonAndId.iDefaultCommand=(id==EEikBidOk);
			buttonAndId.iId=(isCancel)?EEikBidCancel:id;
			if (id==EEikBidBlank)
				{
				aStack.PopString(); // Is this needed anyway just to keep stack in order?
				buttonAndId.iButtonText.Set(KNullDesC); // Ensure text is blank
				}
			else
				buttonAndId.iButtonText.Set(aStack.PopString());
			buttonAndId.iHotkeyFlags=hotKeyFlags;

// By default, populate the buttons array according to the Series 80 style guide.
// For a single button OR a button of value EEikBidOk, move it to the last CBA button
// for cancel (Close in the latter case). Otherwise it stays at the top (BUT note it may get
// 'hijacked' by the current control if this is a dCHOICE - this is Series 80 style)

			switch(butCount)
				{
			case 1:
				if (buttonAndId.iId==EEikBidCancel || buttonAndId.iId==EEikBidOk)
					{
					buttons->AppendL(buttonAndId); // Cancel or Close on CBA4.
					buttons->AppendL(unusedButton);
					buttons->AppendL(unusedButton);
					buttons->AppendL(unusedButton);
					}
				else
					{
					buttons->AppendL(unusedButton);
					buttons->AppendL(unusedButton);
					buttons->AppendL(unusedButton);
					buttons->AppendL(buttonAndId); // CBA1
					}
				break;
			case 2:
				buttons->AppendL(buttonAndId);
				if (ii==1)
					{
					buttons->AppendL(unusedButton);
					buttons->AppendL(unusedButton);
					}
				break;
			case 3:
				buttons->AppendL(buttonAndId);
				if (ii==2)
					{
					buttons->AppendL(unusedButton);
					}
				break;
			default:
				buttons->AppendL(buttonAndId);
				break;
				}
			}

		TInt buttonPosition=0;
		for (TInt i=KMaxSupportedButtons;--i>=0;)
			{
			if ((*buttons)[i].iId) // only a real button has an id.
				{
#if !defined(__UIQ__)
				buttonPanel->SetCommandL(buttonPosition,(*buttons)[i].iId,(*buttons)[i].iButtonText);
#else
				buttonPanel->AddCommandL(buttonPosition,(*buttons)[i].iId,(*buttons)[i].iButtonText);
				buttonPosition++;
#endif
				if ((*buttons)[i].iDefaultCommand)
					buttonPanel->SetDefaultCommand((*buttons)[i].iId);
				}
			else
				{
#if !defined(__UIQ__)
				buttonPanel->DimCommand(buttonPosition,ETrue);
#endif
				}
#if !defined(__UIQ__)
			buttonPosition++;
#endif
			}

		// HotKey only supported for dialogs.
		// buttonPanel->UpdateHotKey(but.iId,but.iHotkeyFlags,User::UpperCase(but.iId));

#if !defined(__UIQ__)
		// Mark any remaining CBAs as dimmed so they can't be pressed.
		const TInt max=buttonPanel->MaxCommands();
		while(buttonPosition<max)
			{
			buttonPanel->DimCommand(buttonPosition++,ETrue);
			}
#endif

		// Finally, having built the new buttonGroupContainer, swap it in.
		CEikButtonGroupContainer* oldButtons=dialog->SwapButtonGroupContainer(buttonPanel);
		dialog->HasButtons(ETrue);
		delete oldButtons;
		CleanupStack::PopAndDestroy(); // buttons
		CleanupStack::Pop(); // buttonPanel
		break;
		}
	case 11:
		{
		// dPOSITION
		TInt yPos=aStack.PopInt16();
		TInt xPos=aStack.PopInt16();
		if (Abs(xPos)>1||Abs(yPos)>1)
			User::Leave(KErrArgument);
		dialog->SetCorner(xPos,yPos);
		break;
		}
	default:
		User::Leave(KErrGeneral);
		}

	aRuntime.SetDialog(dialog);
	CleanupStack::Pop(); // runtime owns the dialog again
	}

/*
void OpCode::dCheckBox(CStack& aStack,COplRuntime& aRuntime,CFrame* aFramePtr)
	{
	COplDialog* dialog=aRuntime.Dialog();

	aRuntime.SetDialog(NULL); // temporarily take ownership
	CleanupStack::PushL(dialog);
	
	if ((dialog==NULL)||(dialog->InitFrame()!=aFramePtr))
		User::Leave(KOplStructure);
	TPtrC prompt=aStack.PopString();
	aStack.PopInt16(); // field flag
	TInt16* pLive=&(aStack.PopRefInt16());
	dialog->AddCheckBoxL(prompt,pLive);

	aRuntime.SetDialog(dialog);
	CleanupStack::Pop(); // runtime owns the dialog again
	}
*/

void OpCode::dEditMulti(CStack& aStack,COplRuntime& aRuntime,CFrame* aFramePtr)
	{
	TInt numOptionalArgs = aRuntime.IP8();
	COplDialog* dialog=aRuntime.Dialog();

	aRuntime.SetDialog(NULL); // temporarily take ownership
	CleanupStack::PushL(dialog);
	
	if ((dialog==NULL)||(dialog->InitFrame()!=aFramePtr))
		User::Leave(KOplStructure);
	TBool readOnly=EFalse;
	if (numOptionalArgs==1)
		readOnly = (TBool)(aStack.PopInt16());
	TInt maxLen=aStack.PopInt32();
	TInt numOfLines=aStack.PopInt16();
	TInt widthInChars=aStack.PopInt16();
	TPtrC prompt=aStack.PopString();
	TInt32* pLive=(TInt32*)OplUtil::PopOffsetAsAddrL(aStack,aRuntime.Heap64(),sizeof(TInt32)*2);
	dialog->AddMultiLineEditorL(prompt,numOfLines,widthInChars,maxLen,pLive,readOnly);

	aRuntime.SetDialog(dialog);
	CleanupStack::Pop(); // runtime owns the dialog again
	}

//
// Alert Support
//
void FuncOpCode::Alert(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
	{
	TInt numArgs = aRuntime.IP8();
	TPtrC txt1(KNullDesC);
	TPtrC txt2(KNullDesC);

	TPtrC but1(KNullDesC);
	TPtrC but2(KNullDesC);
	TPtrC but3(KNullDesC);

	switch (numArgs)
		{
	case 5:
		but3.Set(aStack.PopString());
	case 4:
		but2.Set(aStack.PopString());
	case 3:
		but1.Set(aStack.PopString());
	case 2:
		txt2.Set(aStack.PopString());
	case 1:
		txt1.Set(aStack.PopString());
		}
	aStack.Push((TInt16)(aRuntime.AlertWin(txt1,txt2,but1,but2,but3)+1));
	}

TInt COplRuntime::AlertWin(const TDesC& aLine1,const TDesC& aLine2,const TDesC& aBut1,const TDesC& aBut2,const TDesC& aBut3)
	{
	TInt ret=0;
	__ASSERT_DEBUG(iOplAlertWin,User::Invariant());
	iOplAlertWin->RunAlert(aLine1,aLine2,aBut1,aBut2,aBut3,ret);
	return ret;
	}

//
// Class COplAlertWin
//
COplAlertWin::COplAlertWin()
	{
	iExitOnEnter=EFalse;
	iButtonGroupContainerFocus=ENoButtonGroupContainer;
	}

void COplAlertWin::ConstructL(CCoeEnv* aCoeEnv)
	{
	ConstructSleepingDialogL(R_OPL_DIALOG_ALERT); // includes three button panel
	Window().SetOrdinalPosition(0,ECoeWinPriorityAlwaysAtFront-1);
#if !defined(__UIQ__)
	SetLabelReserveLengthL(EOplCidAlertText1,KMaxLineLength);
	SetLabelReserveLengthL(EOplCidAlertText2,KMaxLineLength);
#endif
	iTwoButtonGroupContainer=
		CEikButtonGroupContainer::NewL(CEikButtonGroupContainer::EDialog,
			CEikButtonGroupContainer::EVertical,
			this->ButtonCommandObserver(), R_OPL_BUTTONS_CANCEL_OK, *this);
	iTwoButtonGroupContainer->MakeVisible(EFalse);

	iThreeButtonGroupContainer=SwapButtonGroupContainer(iTwoButtonGroupContainer);
	iButtonGroupContainerFocus=ETwoButtonGroupContainer;

	iOneButtonGroupContainer=
		CEikButtonGroupContainer::NewL(CEikButtonGroupContainer::EDialog,
			CEikButtonGroupContainer::EVertical,
			this->ButtonCommandObserver(), R_OPL_BUTTONS_CANCEL, *this);
	iOneButtonGroupContainer->MakeVisible(EFalse);
	iTwoButtonGroupContainer=SwapButtonGroupContainer(iOneButtonGroupContainer);
	iButtonGroupContainerFocus=EOneButtonGroupContainer;

	SetButtonTextReserveLengthL(iThreeButtonGroupContainer,EEikBidCancel,KMaxButLength);
	SetButtonTextReserveLengthL(iThreeButtonGroupContainer,EEikBidSpace,KMaxButLength);
	SetButtonTextReserveLengthL(iThreeButtonGroupContainer,EEikBidOk,KMaxButLength);
	SetButtonTextReserveLengthL(iTwoButtonGroupContainer,EEikBidCancel,KMaxButLength);
	SetButtonTextReserveLengthL(iTwoButtonGroupContainer,EEikBidOk,KMaxButLength);
	SetButtonTextReserveLengthL(iOneButtonGroupContainer,EEikBidCancel,KMaxButLength);
	iContinueText=aCoeEnv->AllocReadResourceL(R_OPLR_TBUF_CONTINUE_TEXT);
	}

void COplAlertWin::SetButtonTextReserveLengthL(const CEikButtonGroupContainer* aButtonPanel,const TInt aButtonId,const TInt aReserveLength)
	{
	aButtonPanel->ButtonById(aButtonId)->Label()->SetBufferReserveLengthL(aReserveLength);
	}

void COplAlertWin::RunAlert(const TDesC& aLine1,const TDesC& aLine2,const TDesC& aBut1,const TDesC& aBut2,const TDesC& aBut3,TInt& aReturn)
	{
	iReturnPtr=&aReturn;
	Set(iLine1,aLine1,KMaxLineLength);
	Set(iLine2,aLine2,KMaxLineLength);
	Set(iBut1,aBut1,KMaxButLength);
	Set(iBut2,aBut2,KMaxButLength);
	Set(iBut3,aBut3,KMaxButLength);
	RouseSleepingDialog();
	}

void COplAlertWin::Set(TPtrC& aTrg,const TDesC& aSrc,TInt aMaxLen)
	{
	TInt len=aSrc.Length();
	aTrg.Set(aSrc.Ptr(),(len>aMaxLen)?aMaxLen:len);
	}

void COplAlertWin::ExchangeButtonGroupContainer(TButtonGroupContainerFocus aNewFocus) 
	{
	if (aNewFocus==iButtonGroupContainerFocus)
		return;
	switch(iButtonGroupContainerFocus)
		{
	case EOneButtonGroupContainer:
		if (aNewFocus==ETwoButtonGroupContainer)
			iOneButtonGroupContainer=SwapButtonGroupContainer(iTwoButtonGroupContainer);
		else
			iOneButtonGroupContainer=SwapButtonGroupContainer(iThreeButtonGroupContainer);
		break;
	case ETwoButtonGroupContainer:
		if (aNewFocus==EOneButtonGroupContainer)
			iTwoButtonGroupContainer=SwapButtonGroupContainer(iOneButtonGroupContainer);
		else
			iTwoButtonGroupContainer=SwapButtonGroupContainer(iThreeButtonGroupContainer);
		break;
	case EThreeButtonGroupContainer:
	default:
		if (aNewFocus==EOneButtonGroupContainer)
			iThreeButtonGroupContainer=SwapButtonGroupContainer(iOneButtonGroupContainer);
		else
			iThreeButtonGroupContainer=SwapButtonGroupContainer(iTwoButtonGroupContainer);
		break;
		}
	iButtonGroupContainerFocus=aNewFocus;
	}

void COplAlertWin::PreLayoutDynInitL()
	{
	TInt butCount=1;
#if defined(__UIQ__)
	CEikLabel* label = static_cast<CEikLabel*>(Control(EOplCidAlertText1));
	label->SetTextL(iLine1);
	label = static_cast<CEikLabel*>(Control(EOplCidAlertText2));
	label->SetTextL(iLine2);
#else
	SetLabelL(EOplCidAlertText1,iLine1);
	SetLabelL(EOplCidAlertText2,iLine2);
#endif
	if (iBut1.Length() && iBut2.Length())
		{
		if (iBut3.Length())
			{
			ExchangeButtonGroupContainer(EThreeButtonGroupContainer);
			butCount=3;
			}
		else
			{
			ExchangeButtonGroupContainer(ETwoButtonGroupContainer);
			butCount=2;
			}
		}
	else
		ExchangeButtonGroupContainer(EOneButtonGroupContainer);

//	CEikButtonGroupContainer* butPanel=ButtonPanel();
//	butPanel->ResetMinimumSize();
	CEikButtonGroupContainer& btGrp=ButtonGroupContainer();
	iExitOnEnter=EFalse;
	if (iBut1.Length())
		{
		btGrp.SetCommandL(EEikBidCancel,iBut1);
		if (butCount>=2)
			{
			btGrp.SetCommandL(EEikBidOk,iBut2);
			iExitOnEnter=ETrue;
			if (butCount==3)
				{
				btGrp.SetCommandL(EEikBidSpace,iBut3);
				}
			}
		}
	else
		{
		btGrp.SetCommandL(EEikBidCancel,*iContinueText);
		}
	}

TBool COplAlertWin::OkToExitL(TInt aButtonId)
	{
	switch (aButtonId)
		{
	case EEikBidSpace:
		*iReturnPtr=2;
		break;
	case EEikBidOk:
		if (!iExitOnEnter)
			return EFalse;
		*iReturnPtr=1;
		break;
		}	
	return ETrue;
	}

COplAlertWin::~COplAlertWin()
	{
	ExchangeButtonGroupContainer(EOneButtonGroupContainer); // dialog deletes this
	delete iTwoButtonGroupContainer;
	delete iThreeButtonGroupContainer;
	delete iContinueText;
	}

⌨️ 快捷键说明

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