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

📄 eik_key.cpp

📁 在手机操作系统symbina上使用的一个脚本扩展语言的代码实现,可以参考用于自己的开发
💻 CPP
📖 第 1 页 / 共 4 页
字号:
// EIK_KEY.CPP
//
// Copyright (c) 1997-2001 Symbian Ltd. All rights reserved.

#include "debug.h"
#include <opcodes.h>
#include "oplutil.h"
#include "opldialg.h"
#include <eikfctry.h>
#include <eikon.hrh>
#include <eikon.rsg>
#include <eikdialg.h>
#include <eiklabel.h>
#include <eikseced.h>
#if !defined(__SERIES60__)
#include <eikchlst.h>
#include <eikfsel.h>
#endif
#if !defined(__UIQ__)
#include <eikfpne.h>
#include <eikmfne.h>
#elif defined(__UIQ__)
#include <qikon.hrh>
#include <QikDurationEditor.h>
#include <qiktimeeditor.h>
#include <QikTimeAndDateEditor.h>
#include <QikDateEditor.h>
#include <QIKNUMBEREDITOR.H>
#include <QIKFLOATINGPOINTEDITOR.H>
#endif
#include <coeutils.h>
#include <eikfutil.h>
#include <eikbtpan.h>
#include <eikbtgpc.h>
#include <eikcmbut.h>
#include <eiklbbut.h>
#include <barsread.h>
#if defined(__SERIES60__)

#elif defined(__UIQ__)
#include <eikchkbx.h>

#else
#include <eikchkbx.h>
#include <ckndgsve.h>
#include <ckndgtrg.h>
#endif
#include <eikcapc.h>
#include <oplr.rsg>
#include <oplr.hrh>
#include "graphics.h"
#include "oplr.h"
#include "oplapi.h"
#if defined(__SERIES60__)
#include <aknenv.h>
#elif defined(__UIQ__)
#else
#include <ckndgtrg.h>	// Needed on Crystal 6.0 to workaround the fact that folder selectors
						// provide no ROM access flags by default. This allows us to hack
						// things ourselves and use CCknTargetFolderDialog directly
#endif
#if defined(__S80_DP2_0__)
#include <eikmover.h>	// For 9500 dDATE fix.
#endif

LOCAL_C void doProcessItemsL(CStack& aStack, COplRuntime& aRuntime,TInt aNumOfItems)
	{
	TInt hotKeyCode;
	for(TInt index=0; index<aNumOfItems; index++)
		{
		hotKeyCode = aStack.PopInt16();
		TBuf<256> str=aStack.PopString();
		if (str.Length()>CEikMenuPaneItem::SData::ENominalTextLength)
			User::Leave(KOplErrTooWide);
		if (hotKeyCode) // Skip optional items whose hotkeycode is zero.
			aRuntime.AddMenuItemL(&str,hotKeyCode);
		}
	}

LOCAL_C void CloseMenu(TAny* aRuntime)
	{
	STATIC_CAST(COplRuntime*,aRuntime)->CloseMenu();
	}

void FuncOpCode::mPopup(CStack& aStack,COplRuntime& aRuntime,CFrame* /*aFrame*/)
	{
	aRuntime.CloseMenu();
	
	TCleanupItem menu(CloseMenu,&aRuntime);
	CleanupStack::PushL(menu);

	TInt numOfArgs=aRuntime.IP8();
	doProcessItemsL(aStack,aRuntime,(numOfArgs-3)/2);
	TInt targetType=aStack.PopInt16();
	if (targetType<0 || targetType>3)
		User::Leave(KErrArgument);
	TInt ypos=aStack.PopInt16();
	TInt xpos=aStack.PopInt16();
	CEikHotKeyTable* hotKeyTable=aRuntime.CreateHotKeyTableLC();
	aRuntime.LaunchPopupMenuL(KMenuPopup,TPoint(xpos,ypos),(TPopupTargetPosType)targetType,hotKeyTable);
	CActiveScheduler::Start();
	CleanupStack::PopAndDestroy(2); // hotKeyTable and menu
	}

LOCAL_C void doCardOrCascL(CStack& aStack, COplRuntime& aRuntime, TBool aIsCasc)
	{
	TCleanupItem menu(CloseMenu,&aRuntime);
	CleanupStack::PushL(menu);
	doProcessItemsL(aStack,aRuntime,aRuntime.IP8());
	TBuf<256> str;
	str=aStack.PopString();
	_LIT(KCascChar,">");
	if (aIsCasc)
		str.Append(KCascChar);
	if (str.Length()>CEikMenuBarTitle::SData::ENominalTextLength)
		User::Leave(KOplErrTooWide);
	aRuntime.AddMenuTitleL(&str,aIsCasc);
	CleanupStack::Pop(); // menu
	}

void OpCode::mInit(CStack& /*aStack*/, COplRuntime& aRuntime, CFrame* /*aFrame*/)
	{
	aRuntime.CloseMenu();
	aRuntime.PrepareForMenuL();
	}

void OpCode::mCard(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFrame*/)
	{
	doCardOrCascL(aStack,aRuntime,EFalse);
	}

void OpCode::mCardX(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFrame*/)
	{ // mCARDX bitmapId%,maskId%,item$,key%,
	TCleanupItem menu(CloseMenu,&aRuntime);
	CleanupStack::PushL(menu);
	doProcessItemsL(aStack,aRuntime,aRuntime.IP8());
	CDrawablesCollection& collection=aRuntime.DrawablesCollection();
	COplDrawable* maskDrawable=collection.DrawableL(aStack.PopInt16());
	COplDrawable* bitmapDrawable=collection.DrawableL(aStack.PopInt16());
	CFbsBitmap* mask=new(ELeave) CFbsBitmap();
	CleanupStack::PushL(mask);
	mask->Duplicate(((COplBitmap*)maskDrawable)->FbsBitmap().Handle());
	CFbsBitmap* bitmap=new(ELeave) CFbsBitmap();
	CleanupStack::PushL(bitmap);
	bitmap->Duplicate(((COplBitmap*)bitmapDrawable)->FbsBitmap().Handle());
	aRuntime.AddMenuBitmapL(bitmap,mask);
	CleanupStack::Pop(3); // two bitmaps and a menu
	}

void OpCode::mCasc(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFrame*/)
	{
	doCardOrCascL(aStack,aRuntime,ETrue);
	}

void FuncOpCode::Menu(CStack& /*aStack*/, COplRuntime& aRuntime, CFrame* /*aFrame*/)
	{ // MENU
	TCleanupItem menu(CloseMenu,&aRuntime);
	CleanupStack::PushL(menu);
#if defined(__SERIES60__)
	aRuntime.DisplayMenuL(0,0); // No task list pane on Series60
#else
	aRuntime.DisplayMenuL(1,0); // Skip the zero'th task list pane by default
#endif
	CActiveScheduler::Start();
	CleanupStack::PopAndDestroy(); // menu
	}

void FuncOpCode::MenuWithMemory(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFrame*/)
	{
	TUint8* pInit=OplUtil::PopOffsetAsAddrL(aStack,aRuntime.Heap64(),sizeof(TInt16));
	aRuntime.DisplayMenuL(*(pInit+1),*pInit,(TInt16*)pInit);
	CActiveScheduler::Start();
	aRuntime.CloseMenu();
	}

//
// End of menu stuff
//

//
// COplFileNameSelector
//
#if !defined(__SERIES60__)
void COplFileNameSelector::ConstructL(CCoeControl* aParent,TInt aFlags)
	{
	CEikFileNameSelector::ConstructL(aParent,EEikChlistIncrementalMatching,KOplFileSelectorsMaxDisplayChars);
	iFlags=aFlags;
	}

TBool COplFileNameSelector::IsStateValid()
	{
	if ((iFileSelectorFlags&ESpecifiedFolderIsEmpty)&&!(iFlags&KFileSelectorFlagAllowNulls))
		{
		iEikonEnv->InfoMsg(R_EIK_TBUF_NO_FILENAME_SPECIFIED);
		return EFalse;
		}
	return ETrue;
	}
	
//
// COplFileNameEditor
//
void COplFileNameEditor::ConstructL(TInt aFlags)
	{
	CEikFileNameEditor::ConstructL(0,KOplFileSelectorsMaxDisplayChars,255,1); // check these values!!!!!
	iOplFlags=aFlags;
	}

TBool COplFileNameEditor::IsStateValid()
	{
	TInt infoMsg=0;
	TParse parse;
	GetText(iReturnName);
	if (parse.Set(iReturnName,NULL,NULL)!=KErrNone)
		{
		infoMsg=R_EIK_TBUF_INVALID_FILE_NAME;
		goto exit;
		}
	if (parse.DrivePresent())
		{
		TBuf<2> driveName = parse.Drive();
		driveName.UpperCase();
		TInt driveId = driveName[0] - 'A';
		TVolumeInfo volInfo;
		TInt retcode = iEikonEnv->FsSession().Volume(volInfo, driveId);
		if (retcode != KErrNone)
			{
			infoMsg=R_EIK_TBUF_DISK_NOT_PRESENT;
			goto exit;
			}
		}
	if (!parse.NamePresent())
		{
		if (parse.ExtPresent())
			infoMsg=R_EIK_TBUF_INVALID_FILE_NAME;
		else
			{
			if (parse.PathPresent()&&(iOplFlags&KFileSelectorFlagAllowDirs)) // allow dirs
				{
				parse.Set(iReturnName,&iRef,NULL);
				iReturnName=parse.DriveAndPath();
				if ((iOplFlags&KFileSelectorFlagDisallowExisting)&&EikFileUtils::PathExists(iReturnName)) // disallow existing
					infoMsg=R_EIK_TBUF_EXISTING_FOLDER_SPECIFIED;
				}
			else if (iOplFlags&KFileSelectorFlagAllowNulls) // allow null
				{// ensure drive and path in iReturnName
				parse.Set(iReturnName,&iRef,NULL);
				iReturnName=parse.DriveAndPath();
				}
			else
				infoMsg=R_EIK_TBUF_NO_FILENAME_SPECIFIED;
			}
		goto exit;
		}
	if (parse.Set(iReturnName,&iRef,NULL)!=KErrNone || !(iEikonEnv->FsSession().IsValidName(parse.FullName())))
		{
		infoMsg=R_EIK_TBUF_INVALID_FILE_NAME;
		goto exit;
		}
	if (ConeUtils::FileExists(parse.FullName()))
		{
		if (iOplFlags&KFileSelectorFlagDisallowExisting) // disallow existing
			{
			infoMsg=R_EIK_TBUF_EXISTING_FILE_SPECIFIED;
			goto exit;
			}
		else if (iOplFlags&KFileSelectorFlagQueryExisting) // query existing
			{
			TBuf<50> title;
			TBuf<35> displayFileName;
			TBuf<128> message;
			iEikonEnv->ReadResource(title,R_EIK_TBUF_DIALOG_TITLE_CONFIRM_FILE_REPLACE);
			EikFileUtils::AbbreviateFileName(parse.NameAndExt(),displayFileName);
			iEikonEnv->Format128(message,R_EIK_TBUF_FILE_REPLACE_CONFIRM1,&displayFileName);
			if (!iEikonEnv->QueryWinL(title,message))
				return EFalse;
			}
		}
	iReturnName=parse.FullName();
exit:
	if (infoMsg!=0)
		{
		iEikonEnv->InfoMsg(infoMsg);
		return EFalse;
		}
	return ETrue;
	}

//
// COplFolderNameEditor
//
void COplFolderNameEditor::ConstructL(TInt aFlags)
	{
	CEikFileNameEditor::ConstructL(0,KOplFileSelectorsMaxDisplayChars,253,1); // check these values !!!!!!!
	iOplFlags=aFlags;
	}

TFileName COplFolderNameEditor::Name()
	{
	return iReturnName;
	}

TBool COplFolderNameEditor::IsStateValid()
	{
	GetText(iReturnName);
	TParse parse;
	if (parse.Set(iReturnName,&iRef,NULL)!=KErrNone || !(iEikonEnv->FsSession().IsValidName(parse.FullName())))
		{
		iEikonEnv->InfoMsg(R_EIK_TBUF_INVALID_FOLDER_NAME);
		return EFalse;
		}
	iReturnName=parse.FullName();
	if (parse.NameOrExtPresent() && iReturnName.Length()<iReturnName.MaxLength())
		iReturnName.Append(KPathDelimiter); 
	if ((iOplFlags&KFileSelectorFlagDisallowExisting)&&EikFileUtils::PathExists(iReturnName)) // disallow existing
		{
		iEikonEnv->InfoMsg(R_EIK_TBUF_EXISTING_FOLDER_SPECIFIED);
		return EFalse;
		}
	return ETrue;
	}

//
// COplFolderNameSelector
//
void COplFolderNameSelector::DoCreatePopoutL()
	{
#if defined(__UIQ__)
#else
	TFullName fullName(FullName());
	TParse originalParse;
	originalParse.Set(fullName,NULL,NULL);
	TUint flags=CCknTargetFolderDialog::EShowAllDrives;
	if(iFolderSelectorFlags&EShowSystem)
		flags|=CCknTargetFolderDialog::EShowSystemFolders;
	if(iOplFlags&KFileSelectorFlagShowRom)
		flags|=CCknTargetFolderDialog::EShowRomDrive;
	if(iOplFlags&KFileSelectorFlagShowHidden)
		flags|=CCknTargetFolderDialog::EShowHiddenFolders;
	if(!(iOplFlags&KFileSelectorFlagAllowNewFolders)) // Note it's if the flag is NOT specified...
		flags|=CCknTargetFolderDialog::EDisallowNewFolder;

	if (CCknTargetFolderDialog::RunSelectFolderDlgLD(fullName,flags))
		{
		// Check to see if user changed drives in Crystal folder selector too. If they did
		// we need to update the drive selector (if stored) with the new drive...
		TParse newParse;
		newParse.Set(fullName,NULL,NULL);
		if ((newParse.Drive()!=originalParse.Drive()) && (iCorrespondingDriveSelector))
			{
			if (iCorrespondingDriveSelector->FileSelectionObserver()==this)
				{
				// If this control is set as the observer for the drive selector then
				// de-register it, set the drive name and then re-register it. This will
				// prevent the drive selector control from updating this control
				// which is what we want to do ourselves with SetFullNameL() below.
				iCorrespondingDriveSelector->SetFileSelectionObserver(NULL);
				iCorrespondingDriveSelector->SetFullNameL(fullName);
				iCorrespondingDriveSelector->SetFileSelectionObserver(this);
				}
			}
		SetFullNameL(fullName);
		}
#endif
	}

void COplFolderNameSelector::ConstructL(CCoeControl* aParent,const TInt aFlags)
	{
	CEikFolderNameSelector::ConstructL(aParent,EEikChlistIncrementalMatching,KOplFileSelectorsMaxDisplayChars);
	iOplFlags=aFlags;
	}
#endif

//
// COplDialog
//
COplDialog::COplDialog()
	{
	iNextId=KOplDialogIdBase;
	iCorner=EHCenterVCenter;
	iHasButtons=EFalse;
	}

#if defined(__UIQ__)
void COplDialog::ConstructLC(CFrame* aFramePtr)
	{
	PrepareLC(R_OPL_DIALOG_BASIC);
	iValidatedItems=new(ELeave) CArrayFixSeg<SValidatedItem>(4); // more than four is unlikely
	iFramePtr=aFramePtr;
	}
#else
void COplDialog::ConstructLC(CFrame* aFramePtr,TInt aFlags)
	{
	CEikDialog::ConstructAutoDialogLC(aFlags,0);
	iValidatedItems=new(ELeave) CArrayFixSeg<SValidatedItem>(4); // more than four is unlikely
	iFramePtr=aFramePtr;
	}
#endif

COplDialog::~COplDialog()
	{
	delete iValidatedItems; // the items have already been deleted
	}

void COplDialog::RunLD(TInt16* aReturnPtr)
	{ // were on the cleanup stack!
	if (iLastCreatedChoiceListId)
		User::Leave(KOplStructure);
	iReturnPtr=aReturnPtr;
	*iReturnPtr=(TInt16)0;
	CEikDialog::RunLD();
	}

void COplDialog::AddValidatedItemL(MValidatedItem* aItem,TInt aId)
	{
	SValidatedItem item;
	item.iItem=aItem;
	item.iId=aId;
	iValidatedItems->AppendL(item);
	}

TBool COplDialog::OkToExitL(TInt aButtonId)
	{
	if (aButtonId!=EEikBidCancel)
		{
		// validate any dFiles
		for (TInt ii=iValidatedItems->Count();--ii>=0;)
			{
			if (!((*iValidatedItems)[ii].iItem->IsStateValid()))
				{
				TryChangeFocusToL((*iValidatedItems)[ii].iId);
				return EFalse;
				}
			}
		CEikButtonGroupContainer& btGrp=ButtonGroupContainer();
		if (btGrp.ButtonCount())
			{
			TInt bid;
			switch(aButtonId)
				{
			case EEikBidDelete:
				bid=EKeyBackspace;
				break;
			case EEikBidTab:
				bid=EKeyTab;
				break;

			case EEikBidOk:
				{
				if (btGrp.PositionById(aButtonId)==KErrNotFound)
					return EFalse; // in case enter pressed and no enter button specified
				bid=EKeyEnter;
				}
				break;

⌨️ 快捷键说明

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