texted.cpp

来自「在手机操作系统symbina上使用的一个脚本扩展语言的代码实现,可以参考用于自己」· C++ 代码 · 共 1,978 行 · 第 1/5 页

CPP
1,978
字号
// TEXTED.CPP
//
// Copyright (c) 1997-2002 Symbian Ltd. All rights reserved.

#include <txtrich.h>
#include <txtglobl.h>
#include <txtfmlyr.h>

#if defined(__UIQ__) 
#include <qiknumbereditor.h> 
#include <eikchlst.h> 
#include <eikcfdlg.h> 
#include <eikcore.rsg> 
#define  R_EIK_TBUF_SAVED R_EIK_TBUF_FILE_SAVED 
#else 
#include <sendui.h>
#include <sendnorm.rsg>
#include <eikfontd.h>
#include <eikprtpv.h>
#include <eikprtdg.h>
#include <indicato.rsg>
#include <ckntitle.h>
#include <cknconf.h>
#include <ckndgopn.h>
#include <ckndgsve.h>
#if defined(USE_ADDTODESK)
#include <linkbase.h>
#include <linkdocument.h>
#endif
#include <linkutils.h>
#include <eikfard.h>

#endif

#include <coeutils.h>

#include <s32file.h>
#include <e32uid.h>
#include <eikon.hrh>

#include <eikenv.h>
#include <eikproc.h>
#include <eikdll.h>
#include <gulutil.h>

#include <prnsetup.h>
#include <frmprint.h>
#include <eiktbar.h>
#include <eikbtgpc.h>
#include <eiklabel.h>
#include <eikmenub.h>
#include <eikmenup.h>
#include <eikfnlab.h>
#include <eikbtpan.h>
#include <eikcmbut.h>
#include <eikfutil.h>
#include <eikmsg.h>
#include <eiktxlbm.h>
#include <eiktxlbx.h>

#include <eikspane.h>

#include <bautils.h>




#include <apgicnfl.h>

#include <eikon.rsg>
#include <texted.rsg>
#include <eikon.mbg>
#include "texted.hrh"

#include "txtedsrc.h"
#include "txtedpan.h"

#include <apadef.h>
#include <apacmdln.h>
#include <apfdef.h>
#include <bafindf.h>

#include <oplapi.h>

#include "opl.hlp.hrh" 
#include "texted.h"

//#define _USE_FILELOGGING
#include "debug.h"

// Comment this out to lose the app close panic due to messaging's open RHandle assert
// This should no longer be a problem, however: COAKL07, 09/09/2001

GLDEF_C void Panic(TTextedPanic aPanic)
	{
	_LIT(KAppName,"Program"); // external name is Program
	User::Panic(KAppName,aPanic);
	}

#define KTextedFontControlFlags EGulFontControlItalic|EGulFontControlUnderline|EGulFontControlStrikethrough|EGulFontControlPrintPos

_LIT(KOplExtension,".opl");
_LIT(KOpoExtension,".opo");
_LIT(KAppExtension,".app");
_LIT(KDefaultTranslatorName,"OPLT");
_LIT(KOplRuntimeLibraryName,"Opl.app");
_LIT(KDefaultAppPath,"\\System\\Apps\\.app");
_LIT(KDefaultOplIncludePath,"\\System\\OPL\\");
_LIT(KOplDefaultFilePath,"C:\\");

// For import/export of text
const TInt KFullFormattingUpperThreshold=2000; // from EIKEDWIN.CPP
_LIT(KTextExtension,".txt");
_LIT(KCarriageReturnLineFeed, "\x0d\x0a"); // the DOS/Windows line-terminating character-sequence
_LIT(KLineFeed, "\x0a"); // the Unix line-terminating character

const TInt KUidOplTranslatorProviderValue=0x100001D3;
const TUid KUidOplTranslatorProvider={KUidOplTranslatorProviderValue};

const TInt KUidOplDebuggerValue=0x10000269;
const TUid KUidOplDebugger={KUidOplDebuggerValue};

const TUid KUidInterpreterObj={0x100055C0}; 
const TUid KUidOplInterpreter={0x10005D2E};

// Restrictions on suitable MTMs for SendUi
const TInt KSendAsMaxBodySizeNotUsed=0;
const TInt KSendAsMaxMessageSizeNotUsed=0;

//
// Class CTextEdGlobalTextEditor
//
CTextEdGlobalTextEditor::CTextEdGlobalTextEditor(const TBool aFindHack)
	:iFindHack(aFindHack)
	{
	}

void CTextEdGlobalTextEditor::SetAutoIndent(TBool aAutoIndent)
	{
	iAutoIndent=aAutoIndent;
	}

TKeyResponse CTextEdGlobalTextEditor::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
	{
	TKeyEvent keyEvent=aKeyEvent;
	if (keyEvent.iCode==EKeyEnter || keyEvent.iCode==EKeySpace)	// remove shift to stop forced
																// line breaks and non-breaking
																// spaces
		keyEvent.iModifiers&=~(EModifierShift|EModifierLeftShift|EModifierRightShift);
	if ((keyEvent.iCode==EKeyTab || keyEvent.iCode==EKeyEnter) && SelectionLength())
		ClearSelectionL(); // is this needed when undo is added !!!!
	CEikGlobalTextEditor::OfferKeyEventL(keyEvent,aType);
	if (keyEvent.iCode==EKeyEnter&&!(keyEvent.iModifiers&EModifierCtrl)&&IsAutoIndenting())
		{
		CGlobalText* globalText=GlobalText();
		TInt curPos=CursorPos();
		__ASSERT_DEBUG(curPos>0,Panic(ETextedPanicInvalidCursorPosition));
		TInt pos=curPos-1;
		TInt maxLen=globalText->ToParagraphStart(pos);
		TBuf<256> buf;
		globalText->Extract(buf,pos,(maxLen<256)?maxLen:256);
		TInt len=0;
		const TText* ptr=buf.Ptr();
		for (;len<buf.Length();len++,ptr++)
			{
			if ((*ptr!=0x20)&&(*ptr!=CEditableText::ETabCharacter))
				break;
			}
		if (len>0)
			{
			buf.SetLength(len);
			const TInt oldLength=iText->DocumentLength();
			globalText->InsertL(curPos,buf);
			TCursorSelection sel(curPos,curPos + len);
			TextView()->HandleInsertDeleteL(sel,0);
			SetCursorPosL(curPos+len,EFalse);
			const TInt length=iText->DocumentLength();
			if (length>UpperFullFormattingLength() && oldLength<=UpperFullFormattingLength())
				SetAmountToFormatL();
			UpdateScrollBarsL();
			}
		}
	return EKeyWasConsumed;
	}

void CTextEdGlobalTextEditor::ResetWindow()
	{
	ActivateGc();
	SystemGc().Clear();
	DeactivateGc();
	}

#if defined(__UIQ__)
TBool CTextEdGlobalTextEditor::CallBackFindL(SEdwinFindModel& /*aModel*/, TBool /*aResetStart*/)
	{
	// Never restart from the beginning like on ER5 (always pass EFalse)
//!!TODOUIQ	iFindHack=CEikGlobalTextEditor::CallBackFindL(aModel,EFalse);
	return iFindHack;
	}

TBool CTextEdGlobalTextEditor::CallBackReplaceL(SEdwinFindModel& aModel, TBool /*aResetStart*/)
	{
	// Never restart from the beginning like on ER5 (always pass EFalse to callback). In
	// addition if we are in the replace callback but ENoReplace it set, we need to hack
	// things by setting it to EReplaceOnce, but only if something has already been found
	// (iFindHack==ETrue). If nothing has been found, do a find first and THEN change the
	// iReplaceOption for future callbacks. If we leave it set to EReplaceOnce when
	// nothing is found, the replace text is inserted immediately when the user presses
	// the Replace CBA button. On the other hand if we don't do EReplaceOnce if a valid find
	// has happened then the user has to bring up the Replace options dialog and then confirm
	// it before any replace settings take effect!
	if (aModel.iReplaceOption==ENoReplace || (!iFindHack && aModel.iReplaceOption!=EReplaceAll))
		{
//		iFindHack=CEikGlobalTextEditor::CallBackFindL(aModel,EFalse);
		if (iFindHack && aModel.iReplaceOption==ENoReplace)
			aModel.iReplaceOption=EReplaceOnce;
		}
	else
		{
//		iFindHack=CEikGlobalTextEditor::CallBackReplaceL(aModel,EFalse);
		}
	return iFindHack;
	}
#elif defined(__S80_DP2_0__)
TBool CTextEdGlobalTextEditor::CallBackFindL(SEdwinFindModel& aModel, TBool /*aResetStart*/)
	{
	// Never restart from the beginning like on ER5 (always pass EFalse)
//	aModel.iReplaceOption=EReplaceOnce;
	return CEikGlobalTextEditor::CallBackFindL(aModel,EFalse);
	}

TBool CTextEdGlobalTextEditor::CallBackReplaceL(SEdwinFindModel& aModel, TBool /*aResetStart*/)
	{
	return CEikGlobalTextEditor::CallBackReplaceL(aModel,EFalse);
	}
#else
TBool CTextEdGlobalTextEditor::CallBackFindL(SEdwinFindModel& aModel, TBool /*aResetStart*/)
	{
	// Never restart from the beginning like on ER5 (always pass EFalse)
	iFindHack=CEikGlobalTextEditor::CallBackFindL(aModel,EFalse);
	return iFindHack;
	}

TBool CTextEdGlobalTextEditor::CallBackReplaceL(SEdwinFindModel& aModel, TBool /*aResetStart*/)
	{
	// Never restart from the beginning like on ER5 (always pass EFalse to callback). In
	// addition if we are in the replace callback but ENoReplace it set, we need to hack
	// things by setting it to EReplaceOnce, but only if something has already been found
	// (iFindHack==ETrue). If nothing has been found, do a find first and THEN change the
	// iReplaceOption for future callbacks. If we leave it set to EReplaceOnce when
	// nothing is found, the replace text is inserted immediately when the user presses
	// the Replace CBA button. On the other hand if we don't do EReplaceOnce if a valid find
	// has happened then the user has to bring up the Replace options dialog and then confirm
	// it before any replace settings take effect!
	if (aModel.iReplaceOption==ENoReplace || (!iFindHack && aModel.iReplaceOption!=EReplaceAll))
		{
		iFindHack=CEikGlobalTextEditor::CallBackFindL(aModel,EFalse);
		if (iFindHack && aModel.iReplaceOption==ENoReplace)
			aModel.iReplaceOption=EReplaceOnce;
		}
	else
		{
		iFindHack=CEikGlobalTextEditor::CallBackReplaceL(aModel,EFalse);
		}
	return iFindHack;
	}
#endif


//
// Class CTxtedAppUi
//
CTxtedAppUi::~CTxtedAppUi()
	{
	iCoeEnv->DeleteResourceFile(iOplrResourceFile);
	iTranslatorDll.Close();
	delete iFindFile;
#if defined(USE_PRINTING)
	delete iPageTable;
	delete iPrint;
#endif
	// Take the global text off the stack, to stop that CONE 44 panic.
	RemoveFromStack(iGlobalEd);
	delete iGlobalEd;
	delete iTranFileName;
	delete iOplRtLogon;
#ifdef USE_SENDAS
	delete iSendAppUi;
#endif
#ifdef USE_IRLISTEN
	delete iIrListenAppUi;
#endif
	}

TBool CTxtedAppUi::ProcessCommandParametersL(TApaCommand aCommand,TFileName& aDocumentName,const TDesC8& /*aTail*/)
	{
	TBool ret=CEikAppUi::ProcessCommandParametersL(aCommand,aDocumentName);
	if (!ret) // create 
		ConeUtils::EnsurePathExistsL(aDocumentName); //!!!! Eikon should do this !!!!
	return ret;
	}

void CTxtedAppUi::HandleModelChangeL()
	{
	ResetViewL();
	}

void CTxtedAppUi::ResetViewL()
	{
	iGlobalEd->SetReadOnly(!(iDocument->AppFileMode()&EFileWrite));
	if (!(iDocument->AppFileMode()&EFileWrite))
		iEikonEnv->InfoMsg(R_TXED_FILE_IS_READ_ONLY);
#if defined(__S80_DP2_0__)
	else
		{
		iFindModel.iReplaceOption=EReplaceSkip;
		}
#endif
	iGlobalEd->ClearUndo();
#if defined(USE_PRINTING)
	iPrintSetup=STATIC_CAST(CTextEdDocument*,iDocument)->PrintSetup();

	iPrintSetup->Header()->SetFileNameInfo(*this);
	iPrintSetup->Header()->SetNumPagesInfo(*this);
	iPrintSetup->Footer()->SetFileNameInfo(*this);
	iPrintSetup->Footer()->SetNumPagesInfo(*this); 

	iPrint->SetFirstPageOfDoc(0);
	iPrint->SetDocument((STATIC_CAST(CTextEdDocument*,iDocument)->iGlobalText));
	iPrint->SetPageList(iPageTable);
	iPrint->SetPrinterDevice(iPrintSetup->PrinterDevice());
	iPrint->SetPageMarginsInTwips(iPrintSetup->iPageMarginsInTwips.iMargins);
	iPrint->SetPageSpecInTwips(iPrintSetup->PrinterDevice()->CurrentPageSpecInTwips());
	iPaginateDocumentChanged=ETrue;
#endif

	iGlobalEd->SetDocumentContentL(*(STATIC_CAST(CTextEdDocument*,iDocument)->iGlobalText),CEikEdwin::EUseText);

	iGlobalEd->NotifyNewFormatL(); // doesn't cause the same flicker as NotifyNewDocumentL
	TInt pos=(STATIC_CAST(CTextEdDocument*,iDocument)->iIsNewDoc)?5:0;
	iGlobalEd->SetCursorPosL(pos,EFalse);

	SetTitleBarFileNameL(iEikonEnv->Process()->MainDocFileName());
	delete iTranFileName;
	iTranFileName=NULL;
	}

void CTxtedAppUi::CreateEdwinL()
	{
	CGraphicsDevice* device=iCoeEnv->ScreenDevice();
	iAppZoom.SetGraphicsDeviceMap(device);

	iGlobalEd=new(ELeave) CTextEdGlobalTextEditor();

	iGlobalEd->ConstructL(NULL,0,0,EEikEdwinAllowUndo|EEikEdwinUserSuppliedText|EEikEdwinInclusiveSizeFixed|EEikEdwinKeepDocument|EEikEdwinNoWrap|EEikEdwinLineCursor|EEikEdwinOwnsWindow|EEikEdwinAlwaysShowSelection,KTextedFontControlFlags,EGulNoSymbolFonts);
	iGlobalEd->SetObserver(this);
	iGlobalEd->SetZoomFactorL(&iAppZoom);
	iGlobalEd->CreateScrollBarFrameL();
	iGlobalEd->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff/*EAuto*/, CEikScrollBarFrame::EAuto);
	iGlobalEd->SetDocumentContentL(*(STATIC_CAST(CTextEdDocument*,iDocument)->iGlobalText),CEikEdwin::EUseText);
#if defined(USE_PRINTING)
	iPaginateDocumentChanged=ETrue;
#endif
	iGlobalEd->SetRect(ClientRect());
	iGlobalEd->ActivateL();

	iGlobalEd->SetWordDelimiters(EFalse,ETrue);
	iGlobalEd->SetCursorPosL(0,EFalse);
	iGlobalEd->SetFocus(ETrue);
	}

void CTxtedAppUi::ConstructL()
	{
	FLOGWRITE(_L("CTxtedAppUi::ConstructL() starts."));
	CEikAppUi::ConstructL();

	FLOGWRITE(_L("edwin."));
	CreateEdwinL();
	AddToStackL(iGlobalEd);

	FLOGWRITE(_L("Title bar."));
	InitTitleBar();
	InitFullScreenL();

	FLOGWRITE(_L("Translator."));
	iFindFile=new(ELeave) CFindFileByType(iEikonEnv->FsSession());
	// iFindFile is used by LoadTranslatorL()
	LoadTranslatorL();

	FLOGWRITE(_L("Prefs."));
	RestorePrefsL();
	SetTabWidthL(iTabWidthInChars);
	iGlobalEd->TextLayout()->SetNonPrintingCharsVisibility(iNonPrintingCharVisibility);
	iGlobalEd->NotifyNewFormatL();
#if defined(USE_PRINTING)
	iPrintSetup=STATIC_CAST(CTextEdDocument*,iDocument)->PrintSetup();

⌨️ 快捷键说明

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