📄 g_keywrd.cpp
字号:
// G_KEYWRD.CPP
//
// Copyright (c) 1997-1999 Symbian Ltd. All rights reserved.
//
#include <e32std.h>
#include <eikmsg.h>
#include <eikimage.h>
#include <eiklabel.h>
#include "graphics.h"
#include <opcodes.h>
#include "oplutil.h"
#define KGInfo32ArraySize 36
#define KGColorInfoArraySize 8
//const TInt KCursorObloid = 1;
const TInt KCursorNotFlashing = 2;
const TInt KCursorGray = 4;
// Partial solution for bug [ 910981 ] gFONT doesn't work on UIQ,
// the gFONT problem in beta release of OPL for UIQ.
// 0x017B4B0D is a random value, but outside the valid uid range, so guaranteed
// not to be a valid font id.
const TInt KFontUiqSwissABeta=0x017B4B0D;
void OpCode::gAt(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
{
COplDrawable* currentDrawable = aRuntime.DrawablesCollection().CurrentDrawable();
currentDrawable->SetCursorPosition(COplDrawable::PopPoint(aStack));
}
void OpCode::gMove(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
{
COplDrawable* currentDrawable = aRuntime.DrawablesCollection().CurrentDrawable();
TPoint cursorPos = currentDrawable->CursorPosition();
currentDrawable->SetCursorPosition(cursorPos + COplDrawable::PopPoint(aStack));
}
void OpCode::gBox(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
{
TInt height = aStack.PopInt16();
TInt width = aStack.PopInt16();
CDrawablesCollection& coll=aRuntime.DrawablesCollection();
COplDrawable* currentDrawable = coll.CurrentDrawable();
currentDrawable->SetGcMode(currentDrawable->CurrentDrawMode());
TPoint cursorPos = currentDrawable->CursorPosition();
TPoint heightDiff(0,height);
TPoint widthDiff(width,0);
TRect rect;
if ((width < 0) && (height < 0))
rect.SetRect(cursorPos+widthDiff+heightDiff,cursorPos);
else if (width < 0)
rect.SetRect(cursorPos+widthDiff,cursorPos+heightDiff);
else if (height < 0)
rect.SetRect(cursorPos+heightDiff,cursorPos+widthDiff);
else
rect.SetRect(cursorPos,cursorPos+widthDiff+heightDiff);
currentDrawable->DrawableGc().DrawRect(rect);
coll.FlushIfOn();
}
void OpCode::gLineBy(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
{
TPoint endPoint=COplDrawable::PopPoint(aStack);
CDrawablesCollection& coll=aRuntime.DrawablesCollection();
coll.CurrentDrawable()->DrawLine(endPoint,ETrue);
coll.FlushIfOn();
}
void OpCode::gLineTo(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
{
TPoint endPoint=COplDrawable::PopPoint(aStack);
CDrawablesCollection& coll=aRuntime.DrawablesCollection();
coll.CurrentDrawable()->DrawLine(endPoint,EFalse);
coll.FlushIfOn();
}
void OpCode::gBorder(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
{
TInt numOfArgs = aRuntime.IP8();
CDrawablesCollection& coll=aRuntime.DrawablesCollection();
COplDrawable* currentDrawable = coll.CurrentDrawable();
TSize size = currentDrawable->Size();
TPoint origin(0,0);
if (numOfArgs == 3)
{
size = COplDrawable::PopSize(aStack);
origin=currentDrawable->CursorPosition();
}
TInt flag = aStack.PopInt16();
if ((flag&0xff)>4)
User::Leave(KErrArgument);
currentDrawable->DrawS3Border(flag,TRect(origin,size));
coll.FlushIfOn();
}
void OpCode::gUse(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
{
TInt drawableId = aStack.PopInt16();
aRuntime.DrawablesCollection().SetCurrentDrawableL(drawableId);
aRuntime.ClearTrap();
}
void OpCode::gCls(CStack& /*aStack*/, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
{
CDrawablesCollection& coll=aRuntime.DrawablesCollection();
COplDrawable* currentDrawable = coll.CurrentDrawable();
if (currentDrawable->DrawableFlag() == EIsOplBitmap)
((COplBitmap*)currentDrawable)->ClearBitmap();
else
((COplWindow*)currentDrawable)->ClearWindow();
currentDrawable->SetCursorPosition(KScreenOrigin);
coll.DrawAllClocks();
coll.FlushIfOn();
}
LOCAL_C void DoEllipse(COplRuntime& aRuntime,TInt aDx,TInt aDy,TBool aFill)
{
CDrawablesCollection& coll=aRuntime.DrawablesCollection();
COplDrawable* currentDrawable = coll.CurrentDrawable();
currentDrawable->SetGcMode(currentDrawable->CurrentDrawMode());
TPoint center = currentDrawable->CursorPosition();
CBitmapContext& gc=currentDrawable->DrawableGc();
if (aFill)
{
currentDrawable->SetGcModeInvalid();
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
if (currentDrawable->CurrentDrawMode()!=EModeClear)
gc.SetBrushColor(currentDrawable->ForegroundColor());
}
gc.DrawEllipse(TRect(TPoint(center.iX-aDx,center.iY-aDy),TSize(2*aDx,2*aDy)));
coll.FlushIfOn();
}
void OpCode::gEllipse(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
{
TBool fill=(aRuntime.IP8()==0)?EFalse:(aStack.PopInt16()!=0);
TInt dY = aStack.PopInt16();
TInt dX = aStack.PopInt16();
DoEllipse(aRuntime,dX,dY,fill);
}
void OpCode::gCircle(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
{
TBool fill=(aRuntime.IP8()==0)?EFalse:(aStack.PopInt16()!=0);
TInt16 radius = aStack.PopInt16();
DoEllipse(aRuntime,radius,radius,fill);
}
void OpCode::gSetPenWidth(CStack& aStack,COplRuntime& aRuntime,CFrame* /*aFramePtr*/)
{
TInt size=aStack.PopInt16();
aRuntime.DrawablesCollection().CurrentDrawable()->DrawableGc().SetPenSize(TSize(size,size));
}
void OpCode::gVisible(CStack& /*aStack*/, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
{
CDrawablesCollection& coll=aRuntime.DrawablesCollection();
COplDrawable* currentDrawable = coll.CurrentDrawable();
if (currentDrawable->DrawableFlag() == EIsOplBitmap)
User::Leave(KOplErrInvalidWindow);
TInt visibleArg = aRuntime.IP8();
TBool visible = EFalse; // not visible
if (visibleArg == 1)
visible = ETrue;
((COplWindow*)currentDrawable)->Window().SetVisible(visible);
coll.FlushIfOn();
}
void OpCode::gSetWin(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
{
CDrawablesCollection& coll=aRuntime.DrawablesCollection();
COplDrawable* currentDrawable = coll.CurrentDrawable();
if (currentDrawable->DrawableFlag() == EIsOplBitmap)
User::Leave(KOplErrInvalidWindow);
TInt numOfArgs = aRuntime.IP8();
if (numOfArgs == 4)
currentDrawable->SetSizeL(COplDrawable::PopSize(aStack));
((COplWindow*)currentDrawable)->SetWinPosition(COplDrawable::PopPoint(aStack));
coll.FlushIfOn();
}
void OpCode::gOrder(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
{
TInt ordinalPos = aStack.PopInt16();
TInt drawableId = aStack.PopInt16();
CDrawablesCollection& coll=aRuntime.DrawablesCollection();
COplDrawable* drawable = coll.DrawableL(drawableId);
if (drawable->DrawableFlag() == EIsOplBitmap)
User::Leave(KOplErrInvalidWindow);
((COplWindow*)drawable)->Window().SetOrdinalPosition((ordinalPos)?ordinalPos-1:0);
coll.FlushIfOn();
}
void OpCode::gClose(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
{
TInt drawableId = aStack.PopInt16();
if (drawableId==1) // can not close the console
User::Leave(KErrArgument);
CDrawablesCollection& coll=aRuntime.DrawablesCollection();
coll.CloseDrawableL(drawableId);
aRuntime.ClearTrap();
coll.FlushIfOn();
}
_LIT(KFormatDecimal,"%d");
void OpCode::gPrintWord(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
{
TBuf<16> buf;
buf.Format(KFormatDecimal,aStack.PopInt16());
CDrawablesCollection& coll=aRuntime.DrawablesCollection();
coll.CurrentDrawable()->PrintAndMoveCursor(buf);
coll.FlushIfOn();
}
void OpCode::gPrintLong(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
{
TBuf<16> buf;
buf.Format(KFormatDecimal,aStack.PopInt32());
CDrawablesCollection& coll=aRuntime.DrawablesCollection();
coll.CurrentDrawable()->PrintAndMoveCursor(buf);
coll.FlushIfOn();
}
void OpCode::gPrintDbl(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
{
TReal value = aStack.PopReal64();
TReal* pValue;
pValue = &value;
TBuf<16> buf;
TInt flags=aRuntime.UserFlags();
TOplRealFormat format(flags,16);
buf.Num(*pValue,format);
CDrawablesCollection& coll=aRuntime.DrawablesCollection();
coll.CurrentDrawable()->PrintAndMoveCursor(buf);
coll.FlushIfOn();
}
void OpCode::gPrintStr(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
{
TPtrC buf = aStack.PopString();
CDrawablesCollection& coll=aRuntime.DrawablesCollection();
coll.CurrentDrawable()->PrintAndMoveCursor(buf);
coll.FlushIfOn();
}
void OpCode::gPrintSpace(CStack& /*aStack*/, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
{
_LIT(KCharSpace," ");
TPtrC buf=KCharSpace();
CDrawablesCollection& coll=aRuntime.DrawablesCollection();
coll.CurrentDrawable()->PrintAndMoveCursor(buf);
coll.FlushIfOn();
}
void OpCode::gSaveBit(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
{
TInt numOfArgs = aRuntime.IP8();
CDrawablesCollection& coll=aRuntime.DrawablesCollection();
COplDrawable* currentDrawable = coll.CurrentDrawable();
TSize size(0,0);
if (numOfArgs == 1)
size = COplDrawable::PopSize(aStack);
TPtrC fileName = aStack.PopString();
currentDrawable->StoreBitmapL(aRuntime,fileName,size);
aRuntime.ClearTrap();
coll.FlushIfOn();
}
void OpCode::gGMode(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
{
TInt mode = aStack.PopInt16();
TOplDrawMode drawMode = COplDrawable::GetOplDrawMode(mode);
COplDrawable* currentDrawable = aRuntime.DrawablesCollection().CurrentDrawable();
currentDrawable->SetDrawMode(drawMode);
// flushed before next drawing
}
void OpCode::gTMode(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
{
TInt mode = aStack.PopInt16();
TOplDrawMode textMode = COplDrawable::GetOplDrawMode(mode);
COplDrawable* currentDrawable = aRuntime.DrawablesCollection().CurrentDrawable();
currentDrawable->SetTextMode(textMode);
// flushed before drawing
}
void OpCode::gFill(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
{
TInt mode = aStack.PopInt16();
if ((mode < NULL) || (mode > 2))
User::Leave(KOplErrInvalidArgs);
CGraphicsContext::TDrawMode drawMode = CGraphicsContext::EDrawModePEN; // if mode =0 or mode=1
if (mode == 2)
drawMode = CGraphicsContext::EDrawModeNOTSCREEN;
CDrawablesCollection& coll=aRuntime.DrawablesCollection();
COplDrawable* currentDrawable = coll.CurrentDrawable();
TRect rect(currentDrawable->CursorPosition(),COplDrawable::PopSize(aStack));
TRgb color = currentDrawable->ForegroundColor();
if (mode == 1)
color = currentDrawable->BackgroundColor();
currentDrawable->SetGcModeInvalid(); // setting drawable GC directly below
CBitmapContext& gc = currentDrawable->DrawableGc();
gc.SetBrushColor(color);
gc.SetPenColor(color);
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.SetDrawMode(drawMode);
gc.DrawRect(rect);
coll.FlushIfOn();
}
void OpCode::gPoly(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
{
TInt16* p = (TInt16*)OplUtil::PopOffsetAsAddrL(aStack,aRuntime.Heap64(),sizeof(TInt)+sizeof(TPoint));
// needed to restore cursor pos on completion
TInt xStart=OplUtil::GetWord(p++);
TInt yStart=OplUtil::GetWord(p++);
TInt pairs=OplUtil::GetWord(p++);
TPoint point1(xStart,yStart);
const RHeap& heap=aRuntime.Heap64();
if (pairs<0 || ((TUint8*)p)+(pairs*2*sizeof(TInt16))-heap.Base()>heap.Size())
User::Leave(KOplErrInvalidArgs); // accessing beyond the heap
CDrawablesCollection& coll=aRuntime.DrawablesCollection();
COplDrawable* currentDrawable = coll.CurrentDrawable();
currentDrawable->SetGcMode(currentDrawable->CurrentDrawMode());
CBitmapContext& gc = currentDrawable->DrawableGc();
while (pairs--)
{
// dy accessed next line
TInt dx=OplUtil::GetWord(p++);
TPoint point2=point1+TPoint(dx>>1,OplUtil::GetWord(p++));
if (!(dx&1)) // bit clear to draw
gc.DrawLine(point1,point2);
point1=point2;
}
currentDrawable->SetCursorPosition(TPoint(xStart,yStart));
coll.FlushIfOn();
}
void OpCode::gStyle(CStack& aStack, COplRuntime& aRuntime, CFrame* /*aFramePtr*/)
{
TInt style = aStack.PopInt16();
CDrawablesCollection& collection = aRuntime.DrawablesCollection();
COplDrawable* currentDrawable = collection.CurrentDrawable();
if (style!=currentDrawable->CurrentStyle())
{
TAlgStyle algStyle;
algStyle.SetWidthFactor(1);
algStyle.SetHeightFactor(1);
CBitmapContext& drawableGc = currentDrawable->DrawableGc();
if (style & KStyleBold) // bold
algStyle.SetIsBold(ETrue);
if (style & KStyleUnderlined) // underline
drawableGc.SetUnderlineStyle(EUnderlineOn);
else
drawableGc.SetUnderlineStyle(EUnderlineOff);
/* if (style & KStyleInverse) // inverse
currentDrawable->SetInverseStyle(ETrue);
else
currentDrawable->SetInverseStyle(EFalse);*/
if (style & KStyleDblHeight) // double height
algStyle.SetHeightFactor(2);
if (style & KStyleMonoSpaced) // mono-spaced characters
algStyle.SetIsMono(ETrue);
if (style & KStyleItalics) // italic
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -