📄 richtexteditorcontainer.cpp
字号:
{
bufInteger[i] = (char)(bufInteger[i] - 1) ;
JW = 0;
break;
}
}//处理小数借位进位
if( JW == 1)
bufInteger[0] = (char)(bufInteger[0] - 1);
}
bufInteger.Append( KPoint );
bufInteger.Append( bufDecimal );
~ bufInteger;
if( minus ) bufInteger.Insert( 0, KSub );
bufResult = bufInteger ;
return bufResult;
}
template <class T>
T operator *( const T aOp1, const T aOp2)
{
T a(aOp1);
T b(aOp2);
T bufZero;
T bufOne( KOne );
T bufBit;
T bufR1( KZero );
T bufR2;
T bufJW;
TInt pos1 = a.Locate('.') ;
TInt pos2 = b.Locate('.') ;
TInt offset = 0;
TInt i,j,k = 0,kk,JW;
if( pos1 == KErrNotFound )
pos1 = a.Length() ;
else
{
offset += (a.Length() - pos1 - 1);
a.Delete( pos1, 1);
}
if( pos2 == KErrNotFound )
pos2 = b.Length() ;
else
{
offset += (b.Length() - pos2 - 1);
b.Delete( pos2, 1);
}
TInt aLen = a.Length();
TInt bLen = b.Length();
for( j = bLen - 1, k = 0; j >= 0; j--, k++ )
{
TInt tempB = b[j] - 48;
TInt temp;
bufR2.Copy(KNull);
if( tempB == 0 ) continue;
for( i = aLen - 1, JW = 0; i >= 0 ;i-- )
{
TInt tempA = a[i] - 48;
temp = (tempA * tempB + JW) % 10;
JW = (tempA * tempB + JW) / 10;
bufBit.Num( temp );
bufBit.Append( bufR2 );
bufR2.Copy( bufBit );
}
if( JW )
{
bufJW.Num( JW );
bufJW.Append( bufR2 );
bufR2.Copy( bufJW );
}
for( kk = 0 ;kk < k; kk++ )
bufR2.Append( KZero );
bufR1 = bufR1 + bufR2;
}
while( bufR1.Length() - offset <= 0 )
bufR1.Insert( 0,KZero );
bufR1.Insert( bufR1.Length() - offset, KPoint );
bufResult = bufR1 ;
return bufResult;
}
template <class T>
T operator /( const T aOp1, const T aOp2)
{
T a(aOp1);
T b(aOp2);
T bufZero;
T bufOne( KOne );
T bufBit;
T bufR1( KZero );
T bufR2;
T bufJW;
TBuf<20> buftest;
TInt pos = a.Locate('.') ;
TInt offset = 0, i;
if( b == bufR1 )
User::Leave(-1);
if( pos == KErrNotFound )
pos = a.Length() ;
else
{
offset += (a.Length() - pos - 1);
a.Delete( pos, 1 );
}
!b ;
bufResult = a * b;
if( offset > 0)
{
for( i = 0; i < offset; i++ )
bufResult.Insert( 0,KZero );
pos = bufResult.Locate('.');
bufResult.Delete( pos, 1);
bufResult.Insert( pos - offset , KPoint );
}
~ bufResult;
return bufResult;
}
template <class T>
void operator ~( T & aBuf )
{
_LIT( KZero , "0");
_LIT( KPoint, ".");
TBool flag = EFalse;
if( aBuf[0] == '+' ) aBuf.Delete( 0, 1 );
else if( aBuf[0] == '-' )
aBuf.Delete( 0, 1 ), flag = ETrue;
TInt pos = aBuf.Locate('.');
while( aBuf.Length() > 0 && aBuf[0] == '0')
aBuf.Delete(0,1);
if( aBuf.Length() == 0 )
aBuf.Insert( 0, KZero );
if( pos != KErrNotFound )
while( aBuf[ aBuf.Length() - 1 ] == '0' )
aBuf.Delete( aBuf.Length() - 1, 1);
if( aBuf.Locate('.') == 0 ) aBuf.Insert( 0 , KZero );
if( aBuf.Locate('.') == aBuf.Length() - 1) aBuf.Delete( aBuf.Length() - 1, 1 );
if( flag && ( aBuf.Length() > 1 || aBuf.Length() == 1 && aBuf[0] != '0' ) )
aBuf.Insert( 0, KSub );
}
template <class T>
void operator !( T & aBuf )
{
_LIT( KZero , "0");
_LIT( KOne, "1");
_LIT( KTwo, "2");
_LIT( KPoint, ".");
TInt i;
TInt pos = aBuf.Locate('.'), offset = 0;
TBuf<200> bufTemp( aBuf ), bufInit, bufTwo( KTwo );
if( pos == KErrNotFound )
pos = bufTemp.Length() ;
else
{
offset += (bufTemp.Length() - pos - 1);
bufTemp.Delete( pos, 1);
~ bufTemp;
}
TInt aLen = bufTemp.Length();
if( bufTemp[0] == '1')
aLen--;
for( i = 0; i < aLen; i++)
bufInit.Append( KZero );
bufInit.Append( KOne );
bufInit.Insert( 1, KPoint );
TBuf<200> x0, x1;
x1 = bufInit;
i=0;
do
{
x0 = x1;
bufResult = bufTemp * x0 ;
//
bufResult = bufTwo - bufResult;
bufResult = bufResult * x0;
x1 = bufResult;
if( x1.Length() > 100 )
x1.Delete( 100,x1.Length() - 101 );
i++;
}//x1 = ( bufTwo - aBuf * x0 ) * x0;
while( i < 9 );
if( pos != KErrNotFound )
{
for( i = 0; i < offset; i++ )
x1.Append( KZero);
pos = x1.Locate('.');
x1.Delete( pos, 1);
x1.Insert( pos + offset, KPoint );
}
Limit( x1 );
~ x1;
if( x1.Length() > 50 )
x1.Delete( 50,x1.Length() - 51 );
aBuf = x1;
}
TBool CRTEContainer::GetOperand( TBuf<100> & aBuf, TBool &aFlag )
{
UpdateText();
iPosEnd = iRtEd->RichText()->DocumentLength();
CAknInformationNote* note = new ( ELeave ) CAknInformationNote;
if(iPosEnd == iPosStart)
{
TBuf<100> KError;
iEikonEnv->ReadResource(KError,ERROR1);
note->ExecuteLD( KError );
return EFalse;
}
else if(iPosEnd - iPosStart > 24)
{
TBuf<100> KError;
iEikonEnv->ReadResource(KError,ERROR2);
note->ExecuteLD( KError );
return EFalse;
}
aBuf.Copy( iCurrentBuf );
aBuf.Delete( 0, iPosStart );
if( aBuf.LocateReverse('.') != aBuf.Locate('.')
|| aBuf[aBuf.Length() - 1] == '-'
|| aBuf.LocateReverse('+') != KErrNotFound && aBuf.LocateReverse('+') > 0
|| aBuf.LocateReverse('-') != KErrNotFound && aBuf.LocateReverse('-') > 0
|| aBuf.LocateReverse('E') != KErrNotFound)
{
TBuf<100> KError;
iEikonEnv->ReadResource(KError,ERROR3);
note->ExecuteLD( KError );
return EFalse;
}
if( aBuf[0] == '-' )
aFlag = ETrue;
else aFlag = EFalse;
~ aBuf;
delete note;
return ETrue;
}
void CRTEContainer::InsertTab()
{
iRtEd->RichText()->InsertL(iRtEd->RichText()->DocumentLength(), KTab);
}
void CRTEContainer::Equal( TBool aIsTemp )
{
TBool flag = EFalse;
CAknInformationNote* note = new ( ELeave ) CAknInformationNote;;
if( iIsOperand1 ) return;
//获取第二个操作数
if( !iIsComplete )
{
if( !GetOperand( iOperand2, iIsMinor2 ) ) return ;
//获取两个操作数的绝对值
if( iIsMinor1 ) iOperand1.Delete( 0, 1 );
if( iIsMinor2 ) iOperand2.Delete( 0, 1 );
//根据当前操作符进行相应的运算
switch( CurOp )
{
case EOpAdd:
if( !iIsMinor1 && !iIsMinor2 ) iResult = iOperand1 + iOperand2 ;
else if( !iIsMinor1 ) iResult = iOperand1 - iOperand2;
else if( !iIsMinor2 ) iResult = iOperand2 - iOperand1;
else flag = ETrue, iResult = iOperand1 + iOperand2;
break;
case EOpSub:
if( !iIsMinor1 && !iIsMinor2 ) iResult = iOperand1 - iOperand2 ;
else if( !iIsMinor1 ) iResult = iOperand1 + iOperand2;
else if( !iIsMinor2 ) flag = ETrue, iResult = iOperand1 + iOperand2;
else iResult = iOperand2 - iOperand1;
break;
case EOpMult:
iResult = iOperand1 * iOperand2 ;
if( !iIsMinor1 && iIsMinor2 || iIsMinor1 && !iIsMinor2) flag = ETrue;
break;
case EOpDiv:
TRAPD(err,iResult = iOperand1 / iOperand2)
if( err < 0 )
{
TBuf<50> KError;
iEikonEnv->ReadResource(KError,ERROR4);
note->ExecuteLD( KError4 );
return;
}
if( !iIsMinor1 && iIsMinor2 || iIsMinor1 && !iIsMinor2) flag = ETrue;
break;
}
if( flag && iResult[0] != '-')
iResult.Insert( 0, KSub);
else if( flag && iResult[0] == '-')
iResult.Delete( 0, 1);
Limit( iResult );
~ iResult;
}
if( !aIsTemp )
{
//最终结果方式,显示’=‘号和结果
SetColor( KRgbDarkCyan );
iRtEd->SetCursorPosL(iRtEd->RichText()->DocumentLength(), false);
iRtEd->RichText()->InsertL(iRtEd->RichText()->
DocumentLength(), CEditableText::EParagraphDelimiter);
SetRightTab();
SetFont(EAknLogicalFontPrimaryFont);
iRtEd->RichText()->InsertL( iRtEd->RichText()->DocumentLength(), KEqual);
SetColor( KRgbBlack );
InsertTab();
iRtEd->SetCursorPosL( iRtEd->RichText()->DocumentLength(), false);
SetFont(EAknLogicalFontPrimarySmallFont);
//恢复下一段落格式
SetColor( KRgbBlack );
iRtEd->RichText()->InsertL( iRtEd->RichText()->DocumentLength(), iResult);
iRtEd->SetCursorPosL( iRtEd->RichText()->DocumentLength(), false );
iIsComplete = ETrue;
}
else
{
//中间结果方式,清屏并显示中间结果
iRtEd->SetCursorPosL( 0, false );
iRtEd->RichText()->DeleteL( 1, iRtEd->RichText()->DocumentLength() - 1 );
iRtEd->HandleTextChangedL();
//iRtEd->SetCursorPosL( iRtEd->RichText()->DocumentLength(), false);
iRtEd->RichText()->InsertL( 1, iResult);
iRtEd->SetCursorPosL( iRtEd->RichText()->DocumentLength(), false );
iPosStart = 1;
GetOperand( iOperand1, iIsMinor1 );
iIsComplete = EFalse;
}
if( iIsMinor1 ) iOperand1.Insert( 0, KSub );
if( iIsMinor2 ) iOperand2.Insert( 0, KSub );
delete note;
}
template <class T>
void Limit( T & aBuf )
{
T bufTemp( aBuf );
T bufOne( KOne ), buftest, bufZero;
TBool flag = EFalse;
TInt i, pos1, pos2, offset;
_LIT( KLimit1, "999999999999999999999");
_LIT( KLimit2, "000000000000000000000");
~ aBuf;
if( aBuf[0] == '-' )
{
aBuf.Delete( 0, 1 );
flag = ETrue;
}
pos1 = aBuf.Locate( '.' );
if( pos1 != KErrNotFound )
aBuf.Delete( pos1, 1 );
else
{
if( flag )
aBuf.Insert( 0, KSub );
return ;
}
pos2 = aBuf.Find( KLimit1 );
if( pos2!= KErrNotFound )
{
offset = pos2 - pos1 + 1;
if( offset <= 0 )
aBuf.Delete( pos1 , aBuf.Length() - pos1 );
else
{
for( i = 0; i < offset - 1; i++ )
bufOne.Insert( 0, KZero );
bufOne.Insert( 1, KPoint );
aBuf.Delete( pos2 , aBuf.Length() - pos2 );
aBuf.Insert( pos1, KPoint );
}
~ bufOne;
aBuf = aBuf + bufOne;
}
else if( (pos2 = aBuf.Find( KLimit2 )) != KErrNotFound )
{
//note->ExecuteLD( aBuf );
offset = pos2 - pos1 + 1;
if( offset > 0 )
aBuf.Delete( pos2, aBuf.Length() - pos2 );
else
aBuf.Delete( pos1, aBuf.Length() - pos1 );
aBuf.Insert( pos1, KPoint );
}
else aBuf.Insert( pos1, KPoint );
if( flag )
aBuf.Insert( 0, KSub );
}
void CRTEContainer::Operate( TInt aOperator )
{
TInt pos = 0;
TBool flag;
//if( !iIsOperand1 )
if( iIsOperand1 && !iIsComplete)
flag = GetOperand( iOperand1, iIsMinor1 );
else
Equal( ETrue );
//flag = GetOperand( iOperand2, iIsMinor2 );
if( !flag ) return ;
CurOp = ( TOperator )aOperator;
iRtEd->SetCursorPosL(iRtEd->RichText()->DocumentLength(), false);
SetFont(EAknLogicalFontPrimaryFont);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -