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

📄 richtexteditorcontainer.cpp

📁 在syambian s60 3rd上开发的超级计算器 可实现大浮点数的计算
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*
* ============================================================================
*  Name     : CRTEContainer from RichTextEditorContainer.cpp
*  Part of  : RichTextEditor
*  Created  : 05/08/2006 by Forum Nokia 
*  Version  : 2.0
*
*  Copyright (c) 2006 - 2007 Nokia Corporation.
*  This material, including documentation and any related
*  computer programs, is protected by copyright controlled by
*  Nokia Corporation.
* ============================================================================
*/

// INCLUDE FILES
#include "RichTextEditorContainer.h"
#include <txtrich.h>	//Richtext
#include <eikrted.h>  	//RichText Editor
#include <avkon.mbg> 	// Image Ids 
#include <eikenv.h> 	// ReadResource() 
#include <RichTextEditor.rsg> // Demo Text Buffer
#include "mypicture.h"   // CMyPicture 
#include <AknUtils.h>	
#include <uikon.hrh>
#include <e32std.h> 
#include <FRMTVIEW.h> 
#ifdef __SERIES60_3X__
#include <eikapp.h>
#include <uikon.hrh>
#include <lafpublc.hrh>
#include <eikcolor.hrh>
#endif

#if defined(__WINS__) || defined(__WINSCW__)
#define EKeyStar EStdKeyNkpAsterisk
#else
#define EKeyStar 42 // This is the key for the star "*"
#endif


const TInt KBufSize = 256;

// ---------------------------------------------------------
// CRTEContainer::Prepare()
// Set the Editor flags
// ---------------------------------------------------------
//
void CRTEContainer::Prepare()
{

	// Lower Case 
	iRtEd->SetAknEditorCase(EAknEditorLowerCase);
	// Fixed case

	iRtEd->SetAknEditorFlags
		(
		EAknEditorFlagFixedCase| //Set up the Allowed Cases
		EAknEditorFlagEnableScrollBars  // Set up the scroller
		);

}

// ---------------------------------------------------------
//  CRTEContainer::PreparePicture()
//  Append Bitmap to iBitmap Array
// ---------------------------------------------------------
//
/*void CRTEContainer::PrepareBitmapL()
	{
	#ifndef __SERIES60_3X__
	TFileName name(KImageBitmapFile);
	CompleteWithAppPath( name );
	// windows build wants to install apps on rom drive ( "z:\" )
	// but we want the data from "c:\" instead
	#ifdef __WINS__
	name[ 0 ] = 'C';
	#endif

    #else // 3rd ed

    RFs fsSession;
    User::LeaveIfError(fsSession.Connect());
    CleanupClosePushL( fsSession );
    TFileName name;
    fsSession.PrivatePath( name );
    name.Append( KImageBitmapFile );

	#ifndef __WINS__
    // insert the drive to the private path
    TParsePtrC parse(
        (CEikonEnv::Static()->EikAppUi()->Application())->AppFullName() );
    name.Insert( 0, parse.Drive() );
    #endif

	#endif

	// Create and Load the Bitmap
	CFbsBitmap* bitmap = new( ELeave )CFbsBitmap;
	CleanupStack::PushL(bitmap);
	User::LeaveIfError(bitmap->Load(name));
	//we have to free the memory at the Destructor() -> store the bitmap memory address
	iBitmap->AppendL(bitmap);

	CleanupStack::Pop(); //bitmap - container free bitmap at the destructor
	#ifdef __SERIES60_3X__
    CleanupStack::PopAndDestroy(1, &fsSession);
    #endif
	// last item in iBitmap array is ready to Insert
	}*/

// ---------------------------------------------------------
//  CRTEContainer::InsertMyPictureL()
//  Call Richtext's InsertL() with the CPicture
// ---------------------------------------------------------
//
/*void CRTEContainer::InsertMyPictureL(TInt aPos)
	{
	CMyPicture* picture;
	// Create a CPicture derived class which will draw our image, depending this Size
	picture = new( ELeave )CMyPicture(TSize(KKImageWidth,KImageHeight),
		*(iBitmap->At(iBitmap->Count()-1)/*process the last item of iBitmap));
	CleanupStack::PushL(picture);
	// Prepare the Picture header, which will be instered into the Richtext
	TPictureHeader header;
	header.iPicture =TSwizzle<CPicture>(picture);
	iRtEd->RichText()->InsertL( aPos,header); 
	CleanupStack::Pop(); // picture - Richtext take the ownership 
	}*/

// ---------------------------------------------------------
//  CRTEContainer::Demo()
//  Create Demo Text Content 
//
//  Selecting text as holding the 'ABC'+ joystick 
//  Copy/Paste working through longpress 'ABC' and selecting the 
//  softkey which labelled as our need
// 
//  Clipboard content remain even when example closed
// ---------------------------------------------------------
//
void CRTEContainer::SetBKColor( TRgb aColor )
{
	CParaFormat* pf = new (ELeave) CParaFormat();
	TParaFormatMask mask;
	CleanupStack::PushL(pf);
	pf->iFillColor = aColor;
	mask.SetAttrib(EAttFillColor);
	iRtEd->ApplyParaFormatL(pf, mask);
	CleanupStack::Pop();  
	delete pf;
}

void CRTEContainer::UpdateText()
{
	iRtEd->GetText( iCurrentBuf ); 
}



TBool operator >=( const TBuf<100> aOp1, const TBuf<100> aOp2)
{
	TBuf<100> a(aOp1);
	TBuf<100> b(aOp2);
	
	TInt pos1 = a.Locate('.') ;
	TInt pos2 = b.Locate('.') ;

	if( pos1 == KErrNotFound ) pos1 = aOp1.Length() ;
    if( pos2 == KErrNotFound ) pos2 = aOp2.Length() ;
    
    TInt maxIntegerLen=(pos1>pos2) ? pos1 : pos2;
    TInt i;
    if( pos1 > pos2 ) return ETrue;
    else if( pos1 < pos2 ) return EFalse;
    else
    {
    	for( i = 0; i < maxIntegerLen; i++ )
    	{
    		if( a[i] > b[i] )
    			return ETrue;
    		else if( a[i] < b[i] )
    			return EFalse;
		
    	}
    }
    
	if( pos1 == aOp1.Length())
		a.Delete(0, pos1);
	else a.Delete(0, pos1 + 1);
	if( pos2 == aOp2.Length())
		b.Delete(0, pos2);
	else b.Delete(0, pos2 + 1);
	
	TInt minDecimalLen = 
		( a.Length() < b.Length() ) ? a.Length() : b.Length();
    for( i = 0; i < minDecimalLen; i++ )
   	{
    	if( a[i] > b[i] )
    		return ETrue;
    	else if( a[i] < b[i] )
    		return EFalse;
    }
    
    if( a.Length() < b.Length() ) return EFalse;
    else return ETrue;
}

template <class T>
T operator +( const T aOp1, const T aOp2 )
{

	T a(aOp1);
	T b(aOp2);
	
	T bufTmp;
	T bufZero( KZero );
	T bufOne( KOne );
	T bufBit;
	T bufInteger;	
	T bufDecimal;
	
    TInt lenA=a.Length();
    TInt lenB=b.Length();
    TInt i;
    
	TInt pos1 = a.Locate('.') ;
	TInt pos2 = b.Locate('.') ;
    
	if( pos1 == KErrNotFound ) pos1 = aOp1.Length() ;
    if( pos2 == KErrNotFound ) pos2 = aOp2.Length() ;	
	
    TInt maxIntegerLen=(pos1>pos2) ? pos1 : pos2;
    TInt minIntegerLen=(pos1<pos2) ? pos1 : pos2;
	
    for( i = maxIntegerLen - minIntegerLen; i>0; i--)
    {
    	bufTmp += bufZero;
    }
    

   //把整数部分长度调整到相同
    if( maxIntegerLen == pos1 )
    	bufTmp.Append( b ), b.Copy( bufTmp );
    else
    	bufTmp.Append( a ), a.Copy( bufTmp );
    
    TInt JW = 0;//进位
   //整数部分相加
    for(i=maxIntegerLen-1;i>=0;i--)
    {          
	   TInt tempA = a[i] - 48;
	   TInt tempB = b[i] - 48;
	   TInt temp;

	   if( tempA + tempB + JW >= 10 )
       {
		   temp = tempA + tempB + JW - 10;
		   JW = 1;
       }
       else
       {
           temp = tempA + tempB + JW;
           JW = 0;
       }

	   bufBit.Num( temp );
	   bufBit.Append( bufInteger );
	   bufInteger.Copy( bufBit );
   }//整数部分逐位相加
   if( JW == 1)
   {
	   bufOne.Append( bufInteger );
	   bufInteger.Copy( bufOne );
   }

   
   //保留两个加数的小数部分
   if( pos1 == aOp1.Length())
	   a.Delete(0,maxIntegerLen);
   else a.Delete(0,maxIntegerLen + 1);
   if( pos2 == aOp2.Length())
	   b.Delete(0,maxIntegerLen);
   else b.Delete(0,maxIntegerLen + 1);
   

   
   TInt maxDecimalLen=( a.Length() > b.Length() ) ? a.Length() : b.Length();
   TInt minDecimalLen=( a.Length() < b.Length() ) ? a.Length() : b.Length();
   if( maxDecimalLen == 0 ) 
   {
	   bufResult = bufInteger ; 
	   return bufResult;
   }
     
   bufTmp.Copy(KNull);
   for( i = maxDecimalLen - minDecimalLen; i>0; i--)
   {
	   bufTmp += bufZero;
   }
   //buftest.Num( minDecimalLen);
 
   
   if( maxDecimalLen == a.Length())
    	b.Append( bufTmp );
   else
    	a.Append( bufTmp );
   
   JW=0;//进位
   bufOne.Num(1);
   //小数部分相加
   for(int i=maxDecimalLen-1;i>=0;i--)
   {          
	   TInt tempA = a[i] - 48;
   	   TInt tempB = b[i] - 48;
   	   TInt temp;
   	   if( tempA + tempB + JW >= 10 )
       {
   		   temp = tempA + tempB + JW - 10;
   		   JW = 1;
       }
       else
       {
    	   temp = tempA + tempB + JW;
           JW = 0;
       }          
   	   bufBit.Num( temp );
   	   bufBit.Append( bufDecimal );
   	   bufDecimal.Copy( bufBit );
   }//小数部分逐位相加
   
   if( JW == 1 )
   {
	   //TBufC<100> bufIntegerC(bufInteger);
	   //TPtr p = bufIntegerC.Des();

	   for(i = bufInteger.Length() - 1; i >= 0; i--)
	   {
		   TInt temp = bufInteger[i] - 48;
		   if( temp + JW >= 10 )
		   {
			   bufInteger[i] = '0';
			   JW = 1;
		   }
		   else
		   {
			   bufInteger[i] = (char)(bufInteger[i] + 1) ;
			   JW = 0;
			   break;
		   }
	   }//处理小数部分进位
	   
	   if( JW == 1)
	   {
		   bufOne.Append( bufInteger );
		   bufInteger.Copy( bufOne );
	   }
	   
   }
  
   bufInteger.Append( KPoint );
   bufInteger.Append( bufDecimal );
   bufResult = bufInteger ; 
   return bufResult;
}

template <class T>
T operator -( const T aOp1, const T aOp2)
{
	TBool minus = EFalse;
	
	T a(aOp1);
	T b(aOp2);
	
	T bufTmp;
	T bufZero( KZero );
	T bufOne( KOne );
	T bufBit;
	T bufInteger;	
	T bufDecimal;
		
	if( !(a >= b) )
	{
		a.Swap( b );
		minus = ETrue;
	}   
			
    TInt lenA=a.Length();
	TInt lenB=b.Length();
	TInt i;
	    
	TInt pos1 = a.Locate('.') ;
	TInt pos2 = b.Locate('.') ;

		 
	if( pos1 == KErrNotFound ) pos1 = a.Length();
	if( pos2 == KErrNotFound ) pos2 = b.Length();	
		
	TInt maxIntegerLen=( pos1 > pos2 ) ? pos1 : pos2;
	TInt minIntegerLen=( pos1 < pos2 ) ? pos1 : pos2;
		
	for( i = maxIntegerLen - minIntegerLen; i>0; i-- )
	{
	  	bufTmp += bufZero;
	}

	//把整数部分长度调整到相同
	if( maxIntegerLen == pos1 )
	 	bufTmp.Append( b ), b.Copy( bufTmp );
	else
	  	bufTmp.Append( a ), a.Copy( bufTmp );
	   
	
	
	TInt JW = 0;//借位
	//整数部分相减
	for(i=maxIntegerLen-1;i>=0;i--)
	{          
	   TInt tempA = a[i] - 48;
	   TInt tempB = b[i] - 48;
	   TInt temp;
	   if( tempA - tempB - JW < 0 )
	   {
		   temp = tempA - tempB - JW + 10;
		   JW = 1;
	   }
	   else
	   {
	       temp = tempA - tempB - JW;
	       JW = 0;
	   }
	   bufBit.Num( temp );
	 //	    note->ExecuteLD( test );
	   bufBit.Append( bufInteger );
	   bufInteger.Copy( bufBit );
	}//整数部分逐位减加
	  
	if( JW ==  1) //处理最高位借位
	    bufInteger[0] = (char)(bufInteger[0] - 1);

	
	   
	//保留两减加数的小数部分
	if( pos1 == a.Length())
		a.Delete(0,maxIntegerLen);
	else a.Delete(0,maxIntegerLen + 1);
	if( pos2 == b.Length())
		b.Delete(0,maxIntegerLen);
	else b.Delete(0,maxIntegerLen + 1);
	  
	 
	TInt maxDecimalLen=( a.Length() > b.Length() ) ? a.Length() : b.Length();
	TInt minDecimalLen=( a.Length() < b.Length() ) ? a.Length() : b.Length();
	 
	if( maxDecimalLen == 0 ) 
	{
		if( minus ) bufInteger.Insert( 0, KSub );
		bufResult = bufInteger ; 
		return bufResult;

	}
	     
	bufTmp.Copy(KNull);
	for( i = maxDecimalLen - minDecimalLen; i>0; i--)
	{
		bufTmp += bufZero;
	}
	   
	if( maxDecimalLen == a.Length())
		b.Append( bufTmp );
	else
		a.Append( bufTmp );
	  
	JW=0;//进位
	bufOne.Num(1);
	   //小数部减相加
	for(int i=maxDecimalLen-1;i>=0;i--)
	{          
		TInt tempA = a[i] - 48;
		TInt tempB = b[i] - 48;
		TInt temp;
		if( tempA - tempB - JW < 0 )
		{
			temp = tempA - tempB - JW + 10;
			JW = 1;
		}
		else
		{
			temp = tempA - tempB - JW;
			JW = 0;
		}          
		bufBit.Num( temp );
		bufBit.Append( bufDecimal );
		bufDecimal.Copy( bufBit );
	}//小数部分逐位相减
	   
	if( JW == 1 )
	{
		for(i = bufInteger.Length() - 1; i >= 0; i--)
		{
			TInt temp = bufInteger[i] - 48;
			if( temp - 1 < 0 )
			{
				bufInteger[i] = '9';
				JW = 1;
			}
			else

⌨️ 快捷键说明

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