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

📄 g_keywrd.cpp

📁 在手机操作系统symbina上使用的一个脚本扩展语言的代码实现,可以参考用于自己的开发
💻 CPP
📖 第 1 页 / 共 4 页
字号:
			algStyle.SetIsItalic(ETrue);

#if defined(__SERIES60__)
		TUid fontUid=OplUtil::MapFontId(currentDrawable->FontId(),algStyle);
		const CFont* font;
		TBool standardFont=OplUtil::IsStandardFontUid(fontUid);
		if (standardFont)
			font=OplUtil::MapFontUidToStandardFontL(fontUid);
		else
			font = collection.GetFontByIdL(fontUid,algStyle);
		currentDrawable->SetStyle(style);
		currentDrawable->SetFont((CFbsFont*)font,standardFont);
#else
		TUid fontId=OplUtil::MapFontId(currentDrawable->FontId(),algStyle);
		CFbsFont* font = collection.GetFontByIdL(fontId,algStyle);
		currentDrawable->SetStyle(style);
		currentDrawable->SetFont(font);
#endif
		}
	// flushed before next draw
	}
	
void OpCode::gInvert(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
	{
	CDrawablesCollection& coll=aRuntime.DrawablesCollection();
	COplDrawable* currentDrawable = coll.CurrentDrawable();
	TPoint cursorPos = currentDrawable->CursorPosition();
	TRect rect(cursorPos,COplDrawable::PopSize(aStack));
	currentDrawable->SetGcModeInvalid();	// setting GC directly
	CBitmapContext& gc = currentDrawable->DrawableGc();
	gc.SetDrawMode(CGraphicsContext::EDrawModeNOTSCREEN);
	gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
	gc.DrawRoundRect(rect,TSize(3,3));
	coll.FlushIfOn();
	}
	
void OpCode::gScroll(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
	{
	TInt numOfArgs = aRuntime.IP8();
	TRect scrollRect;
	if (numOfArgs == 6)
		scrollRect = COplDrawable::PopRect(aStack);
	TInt dY = aStack.PopInt16();
	TInt dX = aStack.PopInt16();
/*	if (dY < NULL)
		scrollRect.iTl.iY += dY;
	else if (dY > NULL)
		scrollRect.iBr.iY += dY;
	if (dX < NULL)
		scrollRect.iTl.iX += dX;
	else if (dX > NULL)
		scrollRect.iBr.iX += dX;*/
	TPoint offset(dX,dY);
	CDrawablesCollection& coll=aRuntime.DrawablesCollection();
	COplDrawable* currentDrawable = coll.CurrentDrawable();
	if (numOfArgs != 6)
		scrollRect=currentDrawable->Size();
	currentDrawable->Scroll(offset,scrollRect);
	coll.FlushIfOn();
	}
	
void OpCode::gCopy(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
	{
	TInt mode = aStack.PopInt16();
	TRect sourceRect = COplDrawable::PopRect(aStack);
	TInt drawableId = aStack.PopInt16();
	
	CDrawablesCollection& collection = aRuntime.DrawablesCollection();
	COplDrawable* currentDrawable = collection.CurrentDrawable();
	COplDrawable* sourceDrawable = collection.DrawableL(drawableId);

	if (!sourceDrawable)
		User::Leave(KOplErrDrawNotOpen);
	CGraphicsContext::TDrawMode drawMode = CGraphicsContext::EDrawModePEN;
	switch(mode)
		{
	case 0 :
		drawMode = CGraphicsContext::EDrawModeAND;
		break;
	case 1 :
		drawMode = CGraphicsContext::EDrawModeORNOT;
		break;
	case 2 :
		drawMode = CGraphicsContext::EDrawModeNOTXOR;
		}
	currentDrawable->SetGcModeInvalid();	// setting GC directly
	currentDrawable->DrawableGc().SetDrawMode(drawMode);
	
	if (sourceDrawable->DrawableFlag() == EIsOplBitmap)
		{
		CFbsBitmap& backup = ((COplBitmap*)sourceDrawable)->FbsBitmap();
		currentDrawable->DrawableGc().BitBlt(currentDrawable->CursorPosition(),&backup,sourceRect);
		}
	else
		{
		CFbsBitmap* backup = new(ELeave) CFbsBitmap();
		CleanupStack::PushL(backup);
		((COplWindow*)sourceDrawable)->BackupBmpHandleL(*backup);
		currentDrawable->DrawableGc().BitBlt(currentDrawable->CursorPosition(),backup,sourceRect);
		CleanupStack::PopAndDestroy();
		}
    aRuntime.ClearTrap();
	collection.FlushIfOn();
    }
	
void OpCode::Cursor(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
	{									   
    TInt arg = aRuntime.IP8();
	CDrawablesCollection& collection = aRuntime.DrawablesCollection();
	TTextCursor cursor;
	TInt type = 0;	// default type - corresponds to ETypeRectangle
	TInt id = collection.DrawableWithCursor();
	switch (arg)
		{
	case 0 :
		aRuntime.Console().HideCursor();
		if (id>0)
			{
			((COplWindow*)collection.DrawableL(id))->SetCursorEnabled(EFalse);
			collection.SetDrawableWithCursor(-1);
			collection.FlushIfOn();
			}
		return;
	case 1 :
		collection.SetDrawableWithCursor(0);
		aRuntime.Console().CursorOn();
		collection.FlushIfOn();
		return;
	case 4 :
		type = aStack.PopInt16(); // fall through to case 3:
	case 3 :
		cursor.iHeight = aStack.PopInt16();
		cursor.iWidth = aStack.PopInt16();
		cursor.iAscent = aStack.PopInt16();
		break;
		}
	aRuntime.Console().HideCursor();
	TInt drawableId = aStack.PopInt16();
	COplDrawable* drawable = collection.DrawableL(drawableId);   
	// if the supplied drawable id is a drawable that is a bitmap - leave.	
	if (drawable->DrawableFlag() == EIsOplBitmap)
		User::Leave(KOplErrInvalidWindow);
	
	collection.SetDrawableWithCursor(drawableId);
	if (arg == 2)
		{
		cursor.iWidth = 2;	 // default width
		cursor.iHeight = drawable->Font()->HeightInPixels();	// default height
		cursor.iAscent = drawable->Font()->AscentInPixels();	// default ascent
		}

	cursor.iFlags = 0;
	cursor.iType = TTextCursor::ETypeRectangle;		// default cursor
	
//	if (type & KCursorObloid)
//		cursor.iType = TTextCursor::ETypeObloid;	// obloid shape

	if (type & KCursorNotFlashing)
		cursor.iFlags = TTextCursor::EFlagNoFlash;		// not flashing
	
	if (type & KCursorGray)														 
		cursor.iColor=KRgbGray; // grey color
	
	((COplWindow*)drawable)->SetCursorEnabled(ETrue);
	((COplWindow*)drawable)->DrawCursorIfOn(cursor);
	collection.FlushIfOn();
	}
	
void OpCode::gPatt(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
	{
	TInt mode = aStack.PopInt16();
	TSize size = COplDrawable::PopSize(aStack);
	TInt drawableId = aStack.PopInt16();
	CDrawablesCollection& coll=aRuntime.DrawablesCollection();
	COplDrawable* currentDrawable = coll.CurrentDrawable();
	currentDrawable->SetGcModeInvalid();	// setting GC directly
	CBitmapContext& gc = currentDrawable->DrawableGc();
	CGraphicsContext::TDrawMode drawMode=CGraphicsContext::EDrawModeAND;
	switch(COplDrawable::GetOplDrawMode(mode))
		{
	case EModeSet:
		break;
	case EModeClear:
		drawMode=CGraphicsContext::EDrawModeORNOT;
		break;
	case EModeInvert:
		drawMode=CGraphicsContext::EDrawModeNOTXOR;
		break;
	case EModeReplace:
		drawMode=CGraphicsContext::EDrawModePEN;
		break;
	default:
		User::Leave(KErrArgument);
		}
	gc.SetDrawMode(drawMode);
	gc.SetPenStyle(CGraphicsContext::ENullPen);
	if (drawableId == -1)
		{
		gc.SetBrushColor(currentDrawable->BackgroundColor());
		gc.SetPenColor(currentDrawable->ForegroundColor());
		gc.SetBrushStyle(CGraphicsContext::EDiamondCrossHatchBrush);
		gc.DrawRect(TRect(currentDrawable->CursorPosition(),size));
		}
	else
		{
		COplDrawable* sourceDrawable = aRuntime.DrawablesCollection().DrawableL(drawableId);
		if (!sourceDrawable)
			User::Leave(KOplErrDrawNotOpen);
		currentDrawable->SetPattern(sourceDrawable,size);
		}
    aRuntime.ClearTrap();
    coll.FlushIfOn();
	}
	
void OpCode::gUpdate(CStack& /*aStack*/, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
	{
	TInt flag = aRuntime.IP8();
	RWsSession& wsSession = aRuntime.ConEnv()->WsSession();
	if (flag == 255)
		{
		wsSession.Flush();
		return;
		}
	TBool fl=ETrue;
	if (flag==NULL)
		fl=EFalse;
	aRuntime.DrawablesCollection().SetFlushState(flag);
    }

void FuncOpCode::gLoadFont(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
	{
	TPtrC fileName = aStack.PopString();
	TParse parse;
	User::LeaveIfError(aRuntime.ConEnv()->FsSession().Parse(fileName,parse));
	aStack.Push(aRuntime.DrawablesCollection().AddFontFileL(parse.FullName()));
    }

	
void OpCode::gUnloadFont(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
	{
	CDrawablesCollection& coll=aRuntime.DrawablesCollection();
	coll.RemoveFontFile(aStack.PopInt16());	
    aRuntime.ClearTrap();
	// flushed before next draw
    }
	
void OpCode::gFont(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
	{
	TInt fontId = aStack.PopInt32();
	CDrawablesCollection& collection = aRuntime.DrawablesCollection();
	TAlgStyle algStyle;
	algStyle.SetWidthFactor(1);
	algStyle.SetHeightFactor(1);
	COplDrawable* currentDrawable=collection.CurrentDrawable();
	TInt style=currentDrawable->CurrentStyle();
	
	if (style & KStyleBold)		// bold
		algStyle.SetIsBold(ETrue);

	if (style & KStyleDblHeight)		// double height
		algStyle.SetHeightFactor(2);
	
	if (style & KStyleMonoSpaced)	 // mono-spaced characters
		algStyle.SetIsMono(ETrue);
	
	if (style & KStyleItalics)	  // italic
		algStyle.SetIsItalic(ETrue);
	TUid fontUid=OplUtil::MapFontId(fontId,algStyle);

//#define __FONTBYNAME
#if defined(__FONTBYNAME)||defined(__UIQ__)
#pragma message("g_keywrd.cpp: !!TODO __FONTBYNAME is defined.")
#if defined(__UIQ__)	
// Partial solution for bug [ 910981 ] gFONT doesn't work on UIQ
// Rather than implementing the FontByName keyword, use the fontId to determine 
// whether to use the old Symbian Viking, or the more generic SwissA font.
// This is for the beta release only, and must be fixed before the final v1.00 release.
	TFontSpec spec(_L(""),0);
	if (fontId==KFontUiqSwissABeta)
		{
		spec=TFontSpec(_L("SwissA"),200); //height in twips
		}
	else
		{
		spec=TFontSpec(_L("Symbian Viking"),100);
		}
#else
	TFontSpec spec(_L("Courier"),300);
#endif
//	CFbsFont* font=aRuntime.ConEnv()->CreateScreenFontL(spec);
	CFbsFont* font = collection.GetFontByNameL(spec); // ,algStyle);
	currentDrawable->SetFont(font);
#else
#if defined(__SERIES60__)
	const CFont* font;
	TBool standardFont=OplUtil::IsStandardFontUid(fontUid);
	if (standardFont)
		font=OplUtil::MapFontUidToStandardFontL(fontUid);
	else
		font=collection.GetFontByIdL(fontUid,algStyle);
	currentDrawable->SetFont((CFbsFont*)font,standardFont);
#else
	CFbsFont* font=collection.GetFontByIdL(fontUid,algStyle);
	currentDrawable->SetFont(font);
#endif
#endif
	currentDrawable->SetFontId(fontId);
    aRuntime.ClearTrap();
	// flushed before next draw
    }

void OpCode::DefaultWin(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
	{
	TDisplayMode mode = COplDrawable::DisplayMode(aStack.PopInt16());
	RBackedUpWindow win(aRuntime.ConEnv()->WsSession());
	CleanupClosePushL(win);
	User::LeaveIfError(win.Construct(aRuntime.ConEnv()->RootWin(),mode,1));
	TSize size=aRuntime.ConEnv()->ScreenDevice()->SizeInPixels();
	User::LeaveIfError(win.SetExtentErr(TPoint(0,0),size));
	win.SetOrdinalPosition(0,-1); // just less than default
	User::LeaveIfError(win.SetCornerType(EWindowCornerSquare));	// by default
	win.PointerFilter(EPointerFilterDrag|EPointerFilterMove|EPointerFilterEnterExit,0);
	win.Activate();
	STATIC_CAST(COplWindow*,aRuntime.DrawablesCollection().DrawableL(1))->UseNewWindow(win,mode); // console must exist
	CleanupStack::Pop();
	aRuntime.Console().UseNewWindow(win); // this one closes the old window
	}
	
void OpCode::gXBorder(CStack& aStack, COplRuntime& aRuntime, CFrame* /*  */)
	{
	TInt numOfArgs = aRuntime.IP8();
	CDrawablesCollection& coll=aRuntime.DrawablesCollection();
	COplDrawable* currentDrawable = coll.CurrentDrawable();
	TPoint cursorPos=currentDrawable->CursorPosition();
	currentDrawable->SetGcMode(currentDrawable->CurrentDrawMode()); //hp: otherwise gGMode 2: gXBorder has no effect
	currentDrawable->SetGcModeInvalid();	// setting GC directly below
	TPoint origin;
	TSize outerSize = currentDrawable->Size();
	if (numOfArgs == 4)
		{
		outerSize = COplDrawable::PopSize(aStack);
		origin =cursorPos;
		}
	TRect rect(origin,outerSize);
    TInt flag = aStack.PopInt16();
	TInt type = aStack.PopInt16();
	if ((type==0||type==1)&&(flag&0xff)>4)
		User::Leave(KErrArgument);
	switch (type)
		{
		case 0:
			{
			currentDrawable->DrawS3Border(flag,rect);
			break;
			}
		case 1:
			{
			TInt corner = 0;
			TSize cornerSize(4,4);
			if (flag&KMoreRoundedCorners)
				{
		//		flag -= KMoreRoundedCorners;
				corner = KMoreRoundedCorners;
				cornerSize.SetSize(6,6);
				}

			CBitmapContext& gc = currentDrawable->DrawableGc();
			if (flag&0x100)
				rect.Shrink(1,1);
		//	gc.DrawRect(rect);
  
			gc.SetPenColor(TRgb::Gray16(0));
			gc.DrawRoundRect(TRect(origin,outerSize),cornerSize);

⌨️ 快捷键说明

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