notepad/notepad1/LibSrc/NpdEditorDialog.cpp
changeset 0 f979ecb2b13e
child 21 9711e452b5e9
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 /*
       
     2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation of Notepad/Template Editor mode.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <aknappui.h>
       
    21 #include <avkon.hrh>
       
    22 #include <eikmenub.h>
       
    23 #include <txtglobl.h>
       
    24 #include <AknForm.h>
       
    25 #include <aknnotedialog.h>
       
    26 #include <aknkeys.h>
       
    27 #include <eikapp.h>
       
    28 #include <eikedwob.h>
       
    29 #include <aknnotewrappers.h>
       
    30 #include <AknUtils.h>
       
    31 #include <barsread.h>
       
    32 #include <sendui.h>
       
    33 #include <Sendnorm.rsg>
       
    34 #include <hlplch.h>
       
    35 #include <featmgr.h>
       
    36 #include <NpdLib.rsg>
       
    37 #include "NpdLib.hrh"
       
    38 #include <txtrich.h>
       
    39 #include <StringLoader.h>
       
    40 #include <AvkonInternalCRKeys.h>
       
    41 #include <e32keys.h>
       
    42 #include <finditemengine.h>
       
    43 #include <finditemmenu.h>
       
    44 #include <finditemdialog.h>
       
    45 #include <FindItemmenu.rsg>
       
    46 
       
    47 #include <csxhelp/nmake.hlp.hrh>
       
    48 
       
    49 #include "NpdEdwin.h"
       
    50 #include "NpdEditorDialog.h"
       
    51 #include "NpdDialogBase.h"
       
    52 #include "NpdListDialog.h"
       
    53 #include "NpdModel_platsec.h"
       
    54 #include "NpdApi.h"
       
    55 #include "NpdLib.h"
       
    56 #include "NpdEdwinLines.h"
       
    57 #include "NpdLibPanic.h"
       
    58 
       
    59 // CONSTANTS
       
    60 const TInt KNotepadSequenceGranularity(10);
       
    61 const TInt KNotepadInvalidSequenceIndex(-1);
       
    62 //0x21b2 is the linefeed character
       
    63 //const TChar linefeed(0x21B2);
       
    64 // ============================ MEMBER FUNCTIONS ===============================
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CNotepadEditorDialog::NewL
       
    68 // Constructor.
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 EXPORT_C CNotepadEditorDialog* CNotepadEditorDialog::NewL(
       
    72     TInt aResId, 
       
    73     CNotepadModel* aModel,
       
    74     CNotepadListDialog* aListDialog,
       
    75     CSendUi* aSendUi
       
    76     )
       
    77     {
       
    78     __ASSERT_DEBUG(aModel, Panic(ENotepadLibraryPanicNoModel));
       
    79 
       
    80     CNotepadEditorDialog* self = 
       
    81         new(ELeave) CNotepadEditorDialog(*aModel, aListDialog);
       
    82     CleanupStack::PushL(self);
       
    83     TResourceReader rr;
       
    84     self->iCoeEnv->CreateResourceReaderLC(rr, aResId); // Push rr
       
    85     self->ConstructL( rr );
       
    86     CleanupStack::PopAndDestroy(); // rr
       
    87     CleanupStack::Pop(); // self
       
    88     self->iSendUi = aSendUi;
       
    89     return self;
       
    90     }
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // CNotepadEditorDialog::ConstructL
       
    94 // private second-phase constructor
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 void CNotepadEditorDialog::ConstructL( TResourceReader& aReader)
       
    98     {
       
    99 	CNotepadDialogBase::ConstructL( aReader ); // menubar, dialog
       
   100     TPtrC ptr = aReader.ReadTPtrC();
       
   101     if ( ptr.Length() )
       
   102         {
       
   103         SetTitleL(&ptr);               // LTEXT title
       
   104         }
       
   105     iModel.SetNotepadModelObserver(this);
       
   106 	iFindItemMenu = CFindItemMenu::NewL(ENotepadCmdFind);
       
   107 	iRedrawBackground = EFalse;
       
   108 	iTaskSwapperFlag=EFalse;
       
   109 	User::LeaveIfError(iQwertyModeStatusProperty.Attach(KCRUidAvkon, KAknQwertyInputModeActive));
       
   110     if ( FeatureManager::FeatureSupported( KFeatureIdFfEnablePrintingFramework ) )
       
   111         {
       
   112         iServiceHandler = CAiwServiceHandler::NewL();
       
   113         iServiceHandler->AttachMenuL( R_NOTEPAD_EDITOR_MENU, R_PS_AIW_INTEREST );
       
   114         }
       
   115 	}
       
   116 // -----------------------------------------------------------------------------
       
   117 // CNotepadEditorDialog::~CNotepadEditorDialog
       
   118 // Destructor
       
   119 // -----------------------------------------------------------------------------
       
   120 //
       
   121 EXPORT_C CNotepadEditorDialog::~CNotepadEditorDialog()
       
   122     {
       
   123     if ( iEditor )
       
   124         {
       
   125         iEditor->CancelFepTransaction();
       
   126         }
       
   127     if ( iListDialog )
       
   128         {
       
   129         iListDialog->EditorDeleted();
       
   130         }
       
   131     delete iSequence;
       
   132     delete iIdle;
       
   133 	delete iFindItemMenu;
       
   134     delete iServiceHandler;
       
   135     }
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 // CNotepadEditorDialog::ExecuteLD
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 EXPORT_C TInt CNotepadEditorDialog::ExecuteLD()
       
   142     {
       
   143     CleanupStack::PushL(this);
       
   144     CreateSequenceL();
       
   145     CleanupStack::Pop(); // this
       
   146     return CNotepadDialogBase::ExecuteLD();
       
   147     }
       
   148 
       
   149 // -----------------------------------------------------------------------------
       
   150 // CNotepadEditorDialog::SwitchTextL
       
   151 // -----------------------------------------------------------------------------
       
   152 //
       
   153 void CNotepadEditorDialog::SwitchTextL(TInt aKey) 
       
   154     {
       
   155     TInt err(KErrNone);
       
   156     __ASSERT_DEBUG( iEditor, Panic(ENotepadLibraryPanicNoEdwin) );
       
   157     if ( iModel.SeekKey(aKey) != 0 ) // not found
       
   158         {
       
   159         aKey = KNotepadPseudoKeyIdForNewNote;
       
   160         }
       
   161     TRAP(err,
       
   162         iEditor->ClearSelectionL();
       
   163         iEditor->Text()->Reset();
       
   164         iEditor->HandleTextChangedL();
       
   165         iEditor->SetCursorPosL(0, EFalse);
       
   166         if ( aKey != KNotepadPseudoKeyIdForNewNote )
       
   167             {
       
   168             HBufC* text = iModel.ContentByKeyL(aKey);
       
   169             CleanupStack::PushL(text);
       
   170             iEditor->SetTextL(text);
       
   171             CleanupStack::PopAndDestroy(); // text
       
   172             }
       
   173      	else
       
   174         	{
       
   175 
       
   176             iEditor->NotifyNewFormatL();
       
   177         	}
       
   178         iEditor->SetCursorPosL(0,EFalse);
       
   179         );
       
   180     if (err != KErrNone)
       
   181         {
       
   182         delete(this);
       
   183         User::Leave(err);
       
   184         }
       
   185     iKey = aKey; // set after switching is succeeded (important)
       
   186     if (iRedrawBackground)
       
   187     	{
       
   188     	iEditor->HandleResourceChange(KEikDynamicLayoutVariantSwitch);
       
   189     	iEditor->SetBackgroundColorL();
       
   190     	iRedrawBackground = EFalse;
       
   191     	}
       
   192     	iEditor->Text()->SetHasChanged(EFalse);
       
   193     	iEditor->DrawDeferred();
       
   194   }
       
   195 
       
   196 // -----------------------------------------------------------------------------
       
   197 // CNotepadEditorDialog::SaveOnExitL
       
   198 // -----------------------------------------------------------------------------
       
   199 //
       
   200 TInt CNotepadEditorDialog::SaveOnExitL(
       
   201     TBool aNeedListRefresh )
       
   202     {
       
   203     TBool doSave( ( IsModeAdding() && !IsEmpty() ) ||
       
   204         ( IsModeEditing() && iEditor->Text()->HasChanged() ) );
       
   205     TInt statOfSave(CNotepadModel::ENotepadModelRowNop);
       
   206     TInt returnKey( iKey );
       
   207     iFlags &= ~ENotepadCatchSaveOnExitCallback;
       
   208     if ( doSave )
       
   209         {
       
   210         const TInt savedNextKey( NextKeyInSequence() );
       
   211         statOfSave = SaveL();
       
   212         returnKey = ( statOfSave == CNotepadModel::ENotepadModelRowDeleted ) ?
       
   213             savedNextKey : iKey;
       
   214         }
       
   215     if ( aNeedListRefresh )
       
   216         {
       
   217         iListDialog->HandleEditorExitL( statOfSave, returnKey,
       
   218             statOfSave == CNotepadModel::ENotepadModelRowNop || 
       
   219             iFlags & ENotepadCatchSaveOnExitCallback );
       
   220         }
       
   221     return statOfSave;
       
   222     }
       
   223 
       
   224 // -----------------------------------------------------------------------------
       
   225 // CNotepadEditorDialog::EditByKeyL
       
   226 // This case is caused by Pinboard.
       
   227 // If a pinned memo is selected by Pinboard while Notepad is 
       
   228 // running in editor mode, we must change iEditorDialog's content
       
   229 // instead of creating new EditorDialog.
       
   230 //
       
   231 // we don't need to save/switchtext if required memo is
       
   232 // equivalent to the memo now being edited (ie. aKey == iKey)
       
   233 //
       
   234 // The editor did not work well after following operation:
       
   235 //     1. Launch Notepad
       
   236 //     2. Open a certain memo to switch into editor mode
       
   237 //     3. Press application key to return shell
       
   238 //     4. Launch Pinboard
       
   239 //     5. Select "Write a note"
       
   240 // then, no cursor will be displayed, numeric keys not work.
       
   241 // We can fix this by adding:
       
   242 //     iBaseAppUi->UpdateStackedControlFlags(iEditorDialog, 0, ~0);
       
   243 // to this function.
       
   244 // -----------------------------------------------------------------------------
       
   245 //
       
   246 void CNotepadEditorDialog::EditByKeyL(const TInt aKey, CAknAppUi& aAppUi)
       
   247     {
       
   248     if ( aKey == KNotepadPseudoKeyIdForNewNote // Pinboard "Write a Note"
       
   249         || aKey != iKey )
       
   250         {
       
   251         SaveL();
       
   252      	  SwitchTextL(aKey);	
       
   253         }
       
   254     aAppUi.UpdateStackedControlFlags(this, 0, ~0);
       
   255     DrawNow();
       
   256     }
       
   257 
       
   258 // -----------------------------------------------------------------------------
       
   259 // CNotepadEditorDialog::SetInitialKeyEventL
       
   260 // -----------------------------------------------------------------------------
       
   261 //
       
   262 void CNotepadEditorDialog::SetInitialKeyEventL(const TKeyEvent& aKeyEvent)
       
   263     {
       
   264     iEvent = aKeyEvent;
       
   265     delete iIdle;
       
   266     iIdle = NULL;
       
   267     iIdle = CIdle::NewL(CActive::EPriorityUserInput);
       
   268     iIdle->Start(TCallBack(NumberKeyCallBack, this));
       
   269     }
       
   270 
       
   271 // -----------------------------------------------------------------------------
       
   272 // CNotepadEditorDialog::HandleNotepadModelEventL
       
   273 // -----------------------------------------------------------------------------
       
   274 //
       
   275 void CNotepadEditorDialog::HandleNotepadModelEventL(
       
   276     TEvent aEvent, 
       
   277     TInt /*aParam*/ )
       
   278     {
       
   279     switch ( aEvent )
       
   280         {
       
   281         case EDatabaseChanged:
       
   282             iFlags |= ENotepadCatchSaveOnExitCallback;
       
   283             if ( (iModel.ItemArrayFlags()) & CNotepadModel::ENotepadItemArrayUpdateOnly )
       
   284             	{
       
   285             	iModel.SyncL(EFalse);
       
   286             	}
       
   287             if ( iStoreWait.IsStarted() )
       
   288                 {
       
   289                 iStoreWait.AsyncStop();
       
   290                 }
       
   291             break;
       
   292         case ECompleteItemArrayChange:
       
   293             SyncSequenceL(ETrue);
       
   294             break;
       
   295         default:
       
   296             break;
       
   297         }
       
   298     }
       
   299 
       
   300 // -----------------------------------------------------------------------------
       
   301 // CNotepadEditorDialog::DynInitMenuPaneL
       
   302 // from MEikMenuObserver
       
   303 // -----------------------------------------------------------------------------
       
   304 //
       
   305 void CNotepadEditorDialog::DynInitMenuPaneL(
       
   306     TInt aResourceId,
       
   307     CEikMenuPane* aMenuPane)
       
   308     {
       
   309     __ASSERT_DEBUG(aResourceId > 0, Panic(ENotepadLibraryPanicNoMenuResource));
       
   310     __ASSERT_DEBUG(aMenuPane, Panic(ENotepadLibraryPanicNullMenuPane));
       
   311     __ASSERT_DEBUG(iEditor, Panic(ENotepadLibraryPanicNoEdwin));
       
   312 
       
   313     if ( iServiceHandler && iServiceHandler->HandleSubmenuL( *aMenuPane ) )
       
   314         {
       
   315         return;
       
   316         }
       
   317 
       
   318     iModel.SyncL(EFalse);
       
   319     CNotepadDialogBase::DynInitMenuPaneL( aResourceId, aMenuPane );
       
   320     SyncSequenceL(EFalse);
       
   321     TInt index;
       
   322     switch ( aResourceId )
       
   323         {
       
   324         case R_SENDUI_MENU:
       
   325             index = 2;   
       
   326 			iSendUi->AddSendMenuItemL(*aMenuPane, index, ENotepadCmdSend /*TSendingCapabilities()*/ );
       
   327             break;
       
   328         case R_NOTEPAD_EDITOR_MENU: // when Notepad Editor
       
   329             {
       
   330             if ( FeatureManager::FeatureSupported( KFeatureIdFfEnablePrintingFramework ) )
       
   331                 {
       
   332                 // Initiliaze menu
       
   333                 if ( !IsEmpty() )
       
   334                     {
       
   335                     if ( iServiceHandler )
       
   336                         {
       
   337                         CAiwGenericParamList& inParams = iServiceHandler->InParamListL();
       
   338                         iServiceHandler->InitializeMenuPaneL( *aMenuPane, 
       
   339                                                               aResourceId,  
       
   340                                                               ENotepadCmdPrint,
       
   341                                                               inParams
       
   342                                                              );
       
   343                         }
       
   344                     }
       
   345                 else
       
   346                     {
       
   347                     aMenuPane->DeleteMenuItem( ENotepadCmdPrint );
       
   348                     }
       
   349                 }
       
   350             else
       
   351                 {
       
   352                 aMenuPane->DeleteMenuItem( ENotepadCmdPrint );
       
   353                 }
       
   354 
       
   355             const TBool empty(IsEmpty());
       
   356             if((empty && !iEditor->CcpuCanPaste()) || ( iFlags & ENotepadMenuByOkKey) || iEditor->IsReadOnly() )
       
   357                 {
       
   358                 aMenuPane->DeleteMenuItem( EAknCmdEditTextMenu ); 
       
   359                 }
       
   360            #ifdef RD_INTELLIGENT_TEXT_INPUT    
       
   361             else
       
   362             {
       
   363             	aMenuPane->DeleteMenuItem( EAknCmdEditTextMenu ); 
       
   364             } 
       
   365             #endif
       
   366             if ( empty )
       
   367                 {
       
   368                 aMenuPane->DeleteMenuItem(ENotepadCmdAdd);
       
   369                 }
       
   370             else
       
   371                 {
       
   372 				iSendUi->AddSendMenuItemL( *aMenuPane, 0, ENotepadCmdSend /*TSendingCapabilities()*/ ); // top item 
       
   373 				if ( !( iFlags & ENotepadMenuByOkKey ) )
       
   374 					{
       
   375 					iFindItemMenu->DisplayFindItemMenuItemL(*aMenuPane, ENotepadCmdPreviousMemo);
       
   376 					}
       
   377            		}
       
   378  
       
   379 			if ( iFlags & ENotepadMenuByOkKey )
       
   380                 {
       
   381                 aMenuPane->DeleteMenuItem(ENotepadCmdNextMemo);
       
   382                 aMenuPane->DeleteMenuItem(ENotepadCmdPreviousMemo);
       
   383                 aMenuPane->DeleteMenuItem(EAknCmdExit);
       
   384 				if(FeatureManager::FeatureSupported(KFeatureIdHelp))
       
   385 					{
       
   386 				aMenuPane->DeleteMenuItem(EAknCmdHelp);
       
   387 					}
       
   388 				}
       
   389             else
       
   390                 {
       
   391                 if ( IsSequenceAtLast() )
       
   392                     {
       
   393                     aMenuPane->DeleteMenuItem(ENotepadCmdNextMemo);
       
   394                     }
       
   395                 if ( IsSequenceAtFirst() )
       
   396                     {
       
   397                     aMenuPane->DeleteMenuItem(ENotepadCmdPreviousMemo);
       
   398                     }
       
   399                 }
       
   400 
       
   401 			if(!FeatureManager::FeatureSupported(KFeatureIdHelp))
       
   402 				{
       
   403 				aMenuPane->DeleteMenuItem(EAknCmdHelp);
       
   404 				}
       
   405 				
       
   406 			TLanguage language = User::Language();
       
   407 			
       
   408 			if(language == ELangJapanese || language == ELangEnglish_Japan)
       
   409 			{
       
   410 				aMenuPane->DeleteMenuItem(EAknCmdInputLanguage);	
       
   411 		    }
       
   412 		    else
       
   413 		    {
       
   414 			    if (iFlags & ENotepadMenuByOkKey)
       
   415 			    {
       
   416 			    	aMenuPane->DeleteMenuItem(EAknCmdInputLanguage);
       
   417 			    }
       
   418 			    #ifdef RD_INTELLIGENT_TEXT_INPUT   
       
   419 			    else
       
   420 			    {
       
   421 			        aMenuPane->DeleteMenuItem(EAknCmdInputLanguage);
       
   422 			    }
       
   423 			   #endif
       
   424 			}
       
   425 		    
       
   426 		   	if(language == ELangPrcChinese || language ==ELangHongKongChinese || language ==ELangTaiwanChinese)
       
   427 			{
       
   428 				TInt checkQwertyStatus;	
       
   429 				iQwertyModeStatusProperty.Get(checkQwertyStatus);
       
   430 				
       
   431 				if(!checkQwertyStatus )
       
   432 				{
       
   433 				
       
   434 				aMenuPane->DeleteMenuItem(EAknCmdInputMethod);	
       
   435 					
       
   436 				}
       
   437 			
       
   438 			}
       
   439 			else
       
   440 			{
       
   441 				aMenuPane->DeleteMenuItem(EAknCmdInputMethod);
       
   442 			}
       
   443 
       
   444             }
       
   445             break;
       
   446 				
       
   447 
       
   448            case R_NOTEPAD_TEMPLATE_EDITOR_MENU: // when Template Editor
       
   449             {
       
   450             const TBool empty(IsEmpty());
       
   451             if ( !empty )
       
   452                 {
       
   453 				iSendUi->AddSendMenuItemL( *aMenuPane, 0, ENotepadCmdSend /*TSendingCapabilities()*/ ); // top item
       
   454                 }
       
   455             if ( iFlags & ENotepadMenuByOkKey )
       
   456                 {
       
   457                 aMenuPane->DeleteMenuItem(EAknCmdExit);
       
   458                 if(FeatureManager::FeatureSupported(KFeatureIdHelp))
       
   459 					{
       
   460                 aMenuPane->DeleteMenuItem(EAknCmdHelp);
       
   461 					}
       
   462                 }
       
   463 			if(!FeatureManager::FeatureSupported(KFeatureIdHelp))
       
   464 				{
       
   465 				aMenuPane->DeleteMenuItem(EAknCmdHelp);
       
   466 				}
       
   467             }
       
   468             break;
       
   469 		case R_FINDITEMMENU_MENU :
       
   470             {
       
   471             iFindItemMenu->DisplayFindItemCascadeMenuL(*aMenuPane);
       
   472             break;
       
   473             }
       
   474             
       
   475        
       
   476         default:
       
   477             break;
       
   478         }
       
   479 
       
   480     }
       
   481     
       
   482     
       
   483 // -----------------------------------------------------------------------------
       
   484 // CNotepadEditorDialog::DynInitMenuBarL
       
   485 // from MEikMenuObserver
       
   486 // -----------------------------------------------------------------------------
       
   487 //    
       
   488 void CNotepadEditorDialog::DynInitMenuBarL(
       
   489     TInt aResourceId,
       
   490     CEikMenuBar* aMenuBar )
       
   491     
       
   492 {
       
   493 	
       
   494 	__ASSERT_DEBUG( aResourceId > 0, 
       
   495         Panic(ENotepadLibraryPanicNoMenuResource) );
       
   496     __ASSERT_DEBUG( aMenuBar, Panic(ENotepadLibraryPanicNoMenuResource) );
       
   497    
       
   498     if(!iTaskSwapperFlag )
       
   499     {
       
   500     aMenuBar->SetMenuType(CEikMenuBar::EMenuOptionsNoTaskSwapper);
       
   501     }
       
   502     else
       
   503     {
       
   504     	aMenuBar->SetMenuType(CEikMenuBar::EMenuOptions);
       
   505     	iTaskSwapperFlag=EFalse;	
       
   506 
       
   507     }
       
   508 	
       
   509 }
       
   510 
       
   511 // -----------------------------------------------------------------------------
       
   512 // CNotepadEditorDialog::ProcessCommandL
       
   513 // from MEikCommandObserver
       
   514 // -----------------------------------------------------------------------------
       
   515 //
       
   516 void CNotepadEditorDialog::ProcessCommandL(TInt aCommandId)
       
   517     {
       
   518     HideMenu();
       
   519 	if ( iFindItemMenu && iFindItemMenu->CommandIsValidL( aCommandId ) )
       
   520         {
       
   521         	iFlags |= ENotepadFindItemRuning;
       
   522            TInt ret = DoSearchL( iFindItemMenu->SearchCase(aCommandId) );
       
   523 		   if ( ret == EAknSoftkeyExit )
       
   524 			{
       
   525 				aCommandId = ret;
       
   526 			}
       
   527 			iFlags &= ~ENotepadFindItemRuning;
       
   528         }
       
   529 
       
   530 	switch (aCommandId)
       
   531         {
       
   532 		case EAknSoftkeyExit:
       
   533 		case EAknCmdExit:
       
   534             if ( iListDialog )
       
   535                 {
       
   536                 iListDialog->MakeVisible( EFalse );
       
   537                 } 
       
   538             TryExitL(EAknSoftkeyExit);
       
   539             iAvkonAppUi->ProcessCommandL(EAknCmdExit);
       
   540             break;
       
   541         case ENotepadCmdAdd:
       
   542             OnCmdAddL();
       
   543             break;
       
   544         case ENotepadCmdNextMemo:
       
   545         	iRedrawBackground = ETrue;
       
   546             OnCmdNextMemoL();
       
   547             break;
       
   548         case ENotepadCmdPreviousMemo:
       
   549         	iRedrawBackground = ETrue;
       
   550             OnCmdPreviousMemoL();
       
   551             break;
       
   552         case ENotepadCmdDelete:
       
   553             OnCmdDeleteL();
       
   554             break;
       
   555         case ENotepadCmdSend:
       
   556         	SendAsL( *iSendUi, aCommandId, EFalse, NULL, iEditor->Text() );
       
   557         	 if ( IsExitDelayedBySendUi() )
       
   558              	{
       
   559                 delete iListDialog;
       
   560                 iListDialog = NULL;
       
   561              	}
       
   562         default:
       
   563             {
       
   564             const TInt aiwServiceCmd( iServiceHandler ? iServiceHandler->ServiceCmdByMenuCmd( aCommandId ) : 0 );
       
   565             if ( aiwServiceCmd == KAiwCmdPrint )
       
   566                 {
       
   567                 CAiwGenericParamList& inParams = iServiceHandler->InParamListL();
       
   568 
       
   569                 // Just in case, save note to avoid situation when newly created
       
   570                 // note cannot be be printed
       
   571                 if ( iEditor->Text()->HasChanged() )
       
   572                     {
       
   573                     if ( SaveOnExitL( ETrue ) != CNotepadModel::ENotepadModelRowNop )
       
   574                         {
       
   575                         // Wait asynronously that memo is stored
       
   576                         if ( !iStoreWait.IsStarted() )
       
   577                             {
       
   578                             iStoreWait.Start();
       
   579                             }
       
   580                         }
       
   581                     }
       
   582 
       
   583                 // Note index
       
   584                 TAiwGenericParam noteParam( EGenericParamNoteItem );
       
   585                 const TInt32 noteKey = iKey;
       
   586                 noteParam.Value().Set( noteKey );
       
   587                 inParams.AppendL( noteParam );
       
   588 
       
   589                 // Application uid
       
   590                 const TUid uid( KUidNotepad ); // Notepad Uid3
       
   591                 TAiwGenericParam uidParam( EGenericParamApplication );
       
   592                 uidParam.Value().Set( uid );
       
   593                 inParams.AppendL( uidParam );
       
   594 
       
   595                 // Execute service command with given parameters
       
   596                 iServiceHandler->ExecuteMenuCmdL( aCommandId,
       
   597                                                   inParams,
       
   598                                                   iServiceHandler->OutParamListL(),
       
   599                                                   0,
       
   600                                                   iListDialog
       
   601                                                 );
       
   602                 break;
       
   603                 }
       
   604             
       
   605             CNotepadDialogBase::ProcessCommandL(aCommandId);
       
   606             }
       
   607             break;
       
   608         }
       
   609     }
       
   610 
       
   611 // -----------------------------------------------------------------------------
       
   612 // CNotepadEditorDialog::HandleControlStateChangeL
       
   613 // from CEikDialog
       
   614 // -----------------------------------------------------------------------------
       
   615 //
       
   616 void CNotepadEditorDialog::HandleControlStateChangeL(TInt aControlId )
       
   617     {
       
   618     CNotepadDialogBase::HandleControlStateChangeL(aControlId);
       
   619     }
       
   620 
       
   621 // -----------------------------------------------------------------------------
       
   622 // CNotepadEditorDialog::PreLayoutDynInitL
       
   623 // from CEikDialog.
       
   624 // -----------------------------------------------------------------------------
       
   625 //
       
   626 void CNotepadEditorDialog::PreLayoutDynInitL()
       
   627     {
       
   628     iEditor = STATIC_CAST(CNotepadEdwin*, Control(ENotepadIdEdwin));
       
   629     TRect rect(iEikonEnv->EikAppUi()->ClientRect());
       
   630     iEditor->SetRect(rect);
       
   631     }
       
   632 
       
   633 // -----------------------------------------------------------------------------
       
   634 // CNotepadEditorDialog::OkToExitL
       
   635 // -----------------------------------------------------------------------------
       
   636 //
       
   637 TBool CNotepadEditorDialog::OkToExitL( TInt aButtonId )
       
   638     {
       
   639     const TChar linefeed(0x21B2);
       
   640     __ASSERT_DEBUG( iEditor, Panic(ENotepadLibraryPanicNoEdwin) );
       
   641     if (IsContainLinefeedSymbol(iEditor->Text()->Read(0,
       
   642 			iEditor->Text()->DocumentLength())) && !IsEmpty())
       
   643 		{
       
   644 		return EFalse;
       
   645 		}    
       
   646     iFlags &= ~ENotepadMenuByOkKey;
       
   647     TBool isOk(ETrue);
       
   648     iTaskSwapperFlag= EFalse;
       
   649     switch ( aButtonId )
       
   650         {
       
   651 		//MSK       
       
   652 	   	case EAknSoftkeyContextOptions:
       
   653 	   		{
       
   654 	   	
       
   655 	   		iFlags |= ENotepadMenuByOkKey;
       
   656 	   		DisplayMenuL();
       
   657 	   		isOk= EFalse;
       
   658 	   		}
       
   659 	   		break;
       
   660         case EAknSoftkeyDone:
       
   661             SaveOnExitL(ETrue);
       
   662             break;
       
   663         case EEikBidCancel: // Simulated by CAknShutter
       
   664         case EAknSoftkeyExit:
       
   665             {
       
   666             TRAPD( err, SaveOnExitL( EFalse ); );
       
   667             if ( err )
       
   668                 {
       
   669                 CEikonEnv::Static()->HandleError(err);
       
   670                 }
       
   671             }
       
   672             break;
       
   673         
       
   674         case EAknSoftkeyOptions:
       
   675 				iTaskSwapperFlag= ETrue;        
       
   676 				if ( iFlags & ENotepadFindItemRuning  )
       
   677 				    {
       
   678 				    return EFalse;
       
   679 				    }        
       
   680         default:
       
   681             isOk = CAknDialog::OkToExitL( aButtonId );
       
   682             break;
       
   683         }
       
   684     return isOk;
       
   685     }
       
   686 
       
   687 // -----------------------------------------------------------------------------
       
   688 // CNotepadEditorDialog::ActivateL
       
   689 // from CoeControl.
       
   690 // -----------------------------------------------------------------------------
       
   691 //
       
   692 void CNotepadEditorDialog::ActivateL()
       
   693     {
       
   694     __ASSERT_DEBUG( iEditor, Panic(ENotepadLibraryPanicNoEdwin) );
       
   695     iEditor->ConstructBaseL();
       
   696     iEditor->InitNotepadEditorL(this, STATIC_CAST(CNotepadEdwinLines*, Control(ENotepadIdEdwinLines)));
       
   697     iEditor->SetFocus(ETrue, ENoDrawNow);
       
   698     CNotepadDialogBase::ActivateL();
       
   699     }
       
   700 
       
   701 // -----------------------------------------------------------------------------
       
   702 // CNotepadEditorDialog::OfferKeyEventL
       
   703 // from CCoeControl
       
   704 // -----------------------------------------------------------------------------
       
   705 //
       
   706 TKeyResponse CNotepadEditorDialog::OfferKeyEventL(
       
   707     const TKeyEvent& aKeyEvent,
       
   708     TEventCode aType )
       
   709     {
       
   710   	 
       
   711     
       
   712 	if ( iIdle ) 
       
   713         {
       
   714         NumberKeyCallBack(this);
       
   715         }
       
   716     TKeyResponse keyResponse(EKeyWasConsumed);
       
   717     
       
   718   	
       
   719     if ( !MenuShowing() && aType == EEventKey &&
       
   720         !( aKeyEvent.iModifiers & (EAllStdModifiers|EModifierSpecial) ) &&
       
   721         ( aKeyEvent.iCode  == EKeyOK ) )
       
   722         {
       
   723         iFlags |= ENotepadMenuByOkKey;
       
   724         DisplayMenuL();
       
   725         }
       
   726     else
       
   727         {
       
   728         if ( aKeyEvent.iCode == EKeyNo || aKeyEvent.iCode == EKeyEscape )
       
   729             {
       
   730             iExitByTerminateKey = ETrue;
       
   731             }
       
   732         keyResponse = CAknDialog::OfferKeyEventL(aKeyEvent, aType);	
       
   733         }
       
   734     return keyResponse;
       
   735 	}
       
   736 
       
   737 // -----------------------------------------------------------------------------
       
   738 // CNotepadEditorDialog::GetHelpContext
       
   739 // from CCoeControl
       
   740 // -----------------------------------------------------------------------------
       
   741 //
       
   742 void CNotepadEditorDialog::GetHelpContext(TCoeHelpContext& aContext) const
       
   743     {
       
   744     aContext.iMajor = KUidNotepad;
       
   745     switch ( iResId )
       
   746         {
       
   747         case R_NOTEPAD_EDITOR_DIALOG_ORG:
       
   748             aContext.iContext = KNMAKE_HLP_MEMO_EDITOR;
       
   749             break;
       
   750         case R_NOTEPAD_TEMPLATE_EDITOR_DIALOG_ORG:
       
   751             aContext.iContext = KNMAKE_HLP_TEMPLATE_EDITOR;
       
   752             break;
       
   753         default:
       
   754             break;
       
   755         }
       
   756     }
       
   757     
       
   758 // ---------------------------------------------------------
       
   759 // CNotepadEditorDialog::HandleResourceChange
       
   760 // from CCoeControl
       
   761 // ---------------------------------------------------------
       
   762 //
       
   763 void CNotepadEditorDialog::HandleResourceChange(TInt aType)
       
   764     {
       
   765     if ( aType == KAknsMessageSkinChange || aType ==  KEikDynamicLayoutVariantSwitch )
       
   766         {
       
   767         CAknDialog::HandleResourceChange( aType );
       
   768         CEikDialog::Layout();
       
   769         if ( iEditor && IsActivated() )
       
   770             {
       
   771             iEditor->HandleResourceChange(aType);
       
   772             }
       
   773         iEditor->DrawDeferred();
       
   774         }
       
   775     else
       
   776         {
       
   777         CAknDialog::HandleResourceChange(aType);
       
   778         }
       
   779     if(iEditor)
       
   780     	{
       
   781         iEditor->SetCursorVisible(IsFocused());
       
   782     	}
       
   783     }
       
   784 
       
   785 // ---------------------------------------------------------
       
   786 // CNotepadEditorDialog::SizeChanged
       
   787 // from CCoeControl
       
   788 // ---------------------------------------------------------
       
   789 //
       
   790 void CNotepadEditorDialog::SizeChanged()
       
   791     {
       
   792     CNotepadDialogBase::SizeChanged();
       
   793     if (iEditor && IsActivated())
       
   794         {
       
   795         TRAP_IGNORE(iEditor->DoEditorLayoutL());
       
   796         }
       
   797     }
       
   798 
       
   799 // -----------------------------------------------------------------------------
       
   800 // CNotepadEditorDialog::CNotepadEditorDialog
       
   801 // private c++ constructor
       
   802 // -----------------------------------------------------------------------------
       
   803 //
       
   804 CNotepadEditorDialog::CNotepadEditorDialog(
       
   805     CNotepadModel& aModel,
       
   806     CNotepadListDialog* aListDialog )
       
   807     :CNotepadDialogBase(), iModel(aModel), iListDialog(aListDialog), 
       
   808     iKey(KNotepadPseudoKeyIdForNewNote),
       
   809     iServiceHandler( NULL )
       
   810     {
       
   811     }
       
   812 
       
   813 
       
   814 
       
   815 // -----------------------------------------------------------------------------
       
   816 // CNotepadEditorDialog::SaveL
       
   817 //
       
   818 // Table: What shoud we do after saving?
       
   819 // mode before saving, rowResult ->  entry in iSequence 
       
   820 // 1.  adding             nop    ->         nop              
       
   821 // 2.  adding            added   ->    insert to top         
       
   822 // 3.  editing            nop    ->         nop              
       
   823 // 4.  editing          updated  ->    update the entry      
       
   824 // 5.  editing           added   ->    update the entry      
       
   825 // 6.  editing          deleted  ->    remove the entry     
       
   826 //
       
   827 // In case 6, the info note "Memo delted" should be shown.
       
   828 // -----------------------------------------------------------------------------
       
   829 //
       
   830 TInt CNotepadEditorDialog::SaveL()
       
   831     {
       
   832     __ASSERT_DEBUG(iEditor, Panic(ENotepadLibraryPanicNoEdwin));
       
   833     __ASSERT_DEBUG(iEditor->Text(), Panic(ENotepadLibraryPanicNoTextInEdwin));
       
   834     // in order to avoid leaving at *never leave* bellow
       
   835     iSequence->SetReserveL(iSequence->Count()+1); // *reserve space*
       
   836     const TBool wasModeAdding( IsModeAdding() );
       
   837     const TInt savedCurrentSequence( CurrentSequence() );
       
   838     TInt rowResult(CNotepadModel::ENotepadModelRowNop);
       
   839     if ( iEditor->Text()->HasChanged() )
       
   840         {
       
   841         if ( wasModeAdding )
       
   842             {
       
   843             rowResult = iModel.InsertL( iEditor->Text()->Read(
       
   844                 0, iEditor->Text()->DocumentLength()), iKey );
       
   845             // iKey is updated by InsertL if really added
       
   846             }
       
   847         else
       
   848             {
       
   849             rowResult = iModel.UpdateL(  iEditor->Text()->Read(
       
   850                 0, iEditor->Text()->DocumentLength()), iKey );
       
   851             // iKey is updated by InsertL if iKey doesn't exist or set as 
       
   852             // KNotepadPseudoKeyIdForNewNote if the entry was deleted
       
   853             }
       
   854         iEditor->Text()->SetHasChanged(EFalse);
       
   855         }
       
   856     if ( rowResult == CNotepadModel::ENotepadModelRowDeleted )
       
   857         {
       
   858         if ( savedCurrentSequence != KNotepadInvalidSequenceIndex )
       
   859             {
       
   860             iSequence->Delete(savedCurrentSequence);
       
   861             }
       
   862         
       
   863         if ( !iExitByTerminateKey )
       
   864             {
       
   865             TInt resid = IsNotepad() ? R_NOTEPAD_TEXT_DELETED_EMPTY_MEMO : R_NOTEPAD_TEXT_DELETED_EMPTY_TEMPLATE;
       
   866             HBufC *text= StringLoader::LoadLC(resid); //<NOTEPAD_SAVE_NOTE_MAXLENGTH> text;
       
   867             CAknInformationNote* note 
       
   868                  = new(ELeave) CAknInformationNote(ETrue);
       
   869             note->SetMopParent(this);
       
   870 
       
   871             note->ExecuteLD(*text);
       
   872             CleanupStack::PopAndDestroy(text); 
       
   873             }
       
   874         }
       
   875     else
       
   876         {
       
   877         if ( wasModeAdding && 
       
   878             rowResult == CNotepadModel::ENotepadModelRowAdded )
       
   879             {
       
   880             iSequence->InsertL(0, iKey); // *never leave* because reserved
       
   881             }
       
   882         else if ( savedCurrentSequence != KNotepadInvalidSequenceIndex &&
       
   883             ( rowResult == CNotepadModel::ENotepadModelRowAdded ||
       
   884             rowResult == CNotepadModel::ENotepadModelRowUpdated ) )
       
   885             {
       
   886             (*iSequence)[savedCurrentSequence] = iKey;
       
   887             }
       
   888         }
       
   889     return rowResult;
       
   890     }
       
   891 
       
   892 // -----------------------------------------------------------------------------
       
   893 // CNotepadEditorDialog::OnCmdAddL
       
   894 // This command will never be called
       
   895 // in template Editor.
       
   896 // -----------------------------------------------------------------------------
       
   897 //
       
   898 void CNotepadEditorDialog::OnCmdAddL()
       
   899     {
       
   900     SaveL();
       
   901     SwitchTextL(KNotepadPseudoKeyIdForNewNote);
       
   902     }
       
   903 
       
   904 // -----------------------------------------------------------------------------
       
   905 // CNotepadEditorDialog::OnCmdNextMemoL
       
   906 //
       
   907 // Ever reported;
       
   908 //   1. Notepad has memo "aaa", "bbb", "ddd" and open "aaa" in editor.
       
   909 //   2. Edit "aaa" to be "".
       
   910 //   3. Select 'Next memo' in Options menu.
       
   911 //   then, editor contents will be changed to "bbb" correctly, but 
       
   912 //   Options menu has 'Previous memo' and nothing occurs if we select it.
       
   913 //
       
   914 // Table: What is next?
       
   915 // mode before saving, rowResult ->    nextIndex
       
   916 // 1.  adding             nop    ->       0
       
   917 // 2.  adding            added   ->       1
       
   918 // 3.  editing            nop    ->    oldIndex+1
       
   919 // 4.  editing          updated  ->    oldIndex+1
       
   920 // 5.  editing           added   ->    oldIndex+1
       
   921 // 6.  editing          deleted  ->    oldIndex
       
   922 // Of course, we must check the nextIndex so as not to exceed the total count.
       
   923 // -----------------------------------------------------------------------------
       
   924 //
       
   925 void CNotepadEditorDialog::OnCmdNextMemoL()
       
   926     {
       
   927     TInt nextIndex(0);
       
   928     const TBool wasModeAdding( IsModeAdding() );
       
   929     if ( !wasModeAdding )
       
   930         {
       
   931         nextIndex = CurrentSequence(); // oldIndex
       
   932         }
       
   933     const TInt stat(SaveL()); // iKey has not changed when deleted
       
   934     if ( iSequence->Count() > 0 && 
       
   935         wasModeAdding ? 
       
   936         stat == CNotepadModel::ENotepadModelRowAdded :
       
   937         stat != CNotepadModel::ENotepadModelRowDeleted )
       
   938         {
       
   939         nextIndex++;
       
   940         if ( nextIndex >= iSequence->Count() )
       
   941             {
       
   942             nextIndex = iSequence->Count() - 1;
       
   943             }
       
   944         }
       
   945     if ( iSequence->Count() > 0 )
       
   946         {
       
   947         TInt nextKey( (*iSequence)[nextIndex] );
       
   948         if (nextKey != iKey)
       
   949             {
       
   950             SwitchTextL(nextKey);
       
   951             }
       
   952         }
       
   953     }
       
   954 
       
   955 // -----------------------------------------------------------------------------
       
   956 // CNotepadEditorDialog::OnCmdPreviousMemoL
       
   957 //
       
   958 // Table: What is previous?
       
   959 // mode before saving, rowResult ->    previousIndex
       
   960 // 1.  editing            nop    ->    oldIndex-1
       
   961 // 2.  editing          updated  ->    oldIndex-1
       
   962 // 3.  editing           added   ->    oldIndex-1
       
   963 // 4.  editing          deleted  ->    oldIndex-1
       
   964 // In adding mode, "Previous memo" is not available.
       
   965 // Of course, we must check the previousIndex so as not to be less than 0.
       
   966 // -----------------------------------------------------------------------------
       
   967 //
       
   968 void CNotepadEditorDialog::OnCmdPreviousMemoL()
       
   969     {
       
   970     __ASSERT_DEBUG( IsModeEditing(), 
       
   971         Panic(ENotepadLibraryPanicEditorInvalidMode) );
       
   972     TInt previousIndex( CurrentSequence() ); // oldIndex
       
   973     SaveL();
       
   974     if ( previousIndex > 0 )
       
   975         {
       
   976         --previousIndex;
       
   977         }
       
   978     if ( iSequence->Count() > 0 )
       
   979         {
       
   980         TInt previousKey( (*iSequence)[previousIndex] );
       
   981         if (previousKey != iKey)
       
   982             {
       
   983             SwitchTextL(previousKey);
       
   984             }
       
   985         }
       
   986     }
       
   987 
       
   988 // -----------------------------------------------------------------------------
       
   989 // CNotepadEditorDialog::OnCmdDeleteL
       
   990 // -----------------------------------------------------------------------------
       
   991 //
       
   992 void CNotepadEditorDialog::OnCmdDeleteL()
       
   993     {
       
   994     TInt deleteKey( IsModeEditing() ? iKey : KNotepadPseudoKeyIdForNewNote );
       
   995     if ( ExecuteConfirmationQueryL(QueryDeleteSingleResId()) )
       
   996         {
       
   997         TInt returnKey( iKey );
       
   998         TInt stat(CNotepadModel::ENotepadModelRowNop);
       
   999         iFlags &= ~ENotepadCatchSaveOnExitCallback;
       
  1000         if ( deleteKey >= 0 )
       
  1001             {
       
  1002             const TBool isEditingFirst(
       
  1003                 IsModeEditing() && IsSequenceAtFirst() );
       
  1004             stat = iModel.DeleteL(deleteKey);
       
  1005             if ( !isEditingFirst && 
       
  1006                 stat == CNotepadModel::ENotepadModelRowDeleted )
       
  1007                 {
       
  1008                 returnKey = NextKeyInSequence();
       
  1009                 }
       
  1010             }
       
  1011         iEditor->Text()->SetHasChanged(EFalse); // prevent saving
       
  1012 
       
  1013         iListDialog->HandleEditorExitL(stat, returnKey, 
       
  1014             stat == CNotepadModel::ENotepadModelRowNop || 
       
  1015             iFlags & ENotepadCatchSaveOnExitCallback );
       
  1016         delete(this); // this is OK
       
  1017         }
       
  1018     }
       
  1019 
       
  1020 // -----------------------------------------------------------------------------
       
  1021 // CNotepadEditorDialog::NumberKeyCallBack
       
  1022 // -----------------------------------------------------------------------------
       
  1023 //
       
  1024 TInt CNotepadEditorDialog::NumberKeyCallBack(TAny *aSelf)
       
  1025     {
       
  1026     CNotepadEditorDialog *self = STATIC_CAST(CNotepadEditorDialog*, aSelf);
       
  1027     delete self->iIdle;
       
  1028     self->iIdle = NULL;
       
  1029     // delete must preceed KeyEvent to avoid infinite loop of OfferKeyEventL
       
  1030     //
       
  1031     TRAPD(err,
       
  1032         self->iCoeEnv->SimulateKeyEventL(self->iEvent, EEventKeyDown);
       
  1033         self->iCoeEnv->SimulateKeyEventL(self->iEvent, EEventKey);
       
  1034         );
       
  1035     if ( err != KErrNone )
       
  1036         {
       
  1037         self->iEditor->CancelFepTransaction(); // indispensable to avoid crash
       
  1038         self->iCoeEnv->HandleError(err);
       
  1039         }
       
  1040     return FALSE;
       
  1041     }
       
  1042 
       
  1043 // -----------------------------------------------------------------------------
       
  1044 // CNotepadEditorDialog::CreateSequenceL
       
  1045 // -----------------------------------------------------------------------------
       
  1046 //
       
  1047 void CNotepadEditorDialog::CreateSequenceL()
       
  1048     {
       
  1049     delete iSequence;
       
  1050     iSequence = NULL;
       
  1051     iSequence = new(ELeave) CArrayFixFlat<TInt>(KNotepadSequenceGranularity);
       
  1052     const RArray<TInt>& keyArray = iModel.KeyArray();
       
  1053     const TInt count(keyArray.Count());
       
  1054     iFlags |= ENotepadRequireSequenceUpdate; // flag on
       
  1055     for (TInt i(0); i < count; i++)
       
  1056         {
       
  1057         iSequence->AppendL( keyArray[i] );
       
  1058         }
       
  1059     iFlags &= ~ENotepadRequireSequenceUpdate; // flag off
       
  1060     }
       
  1061 
       
  1062 // -----------------------------------------------------------------------------
       
  1063 // CNotepadEditorDialog::SyncSequenceL
       
  1064 // -----------------------------------------------------------------------------
       
  1065 //
       
  1066 void CNotepadEditorDialog::SyncSequenceL( const TBool aForceSync )
       
  1067     {
       
  1068     if ( !iSequence || 
       
  1069         !( aForceSync || iFlags & ENotepadRequireSequenceUpdate) )
       
  1070         {
       
  1071         iFlags &= ~ENotepadRequireSequenceUpdate; // flag off
       
  1072         return;
       
  1073         }
       
  1074     iFlags |= ENotepadRequireSequenceUpdate; // flag on
       
  1075     const RArray<TInt>& keyArray = iModel.KeyArray();
       
  1076 
       
  1077     // Delete entries which no longer exist
       
  1078     //
       
  1079     TInt i(0);
       
  1080     for ( i = iSequence->Count() - 1; i >= 0; --i )
       
  1081         {
       
  1082         if ( keyArray.Find((*iSequence)[i]) < 0 ) // not found
       
  1083             {
       
  1084             iSequence->Delete(i);
       
  1085             }
       
  1086         }
       
  1087 
       
  1088     // Add entries which is newly added after previous Create/SyncSequenceL
       
  1089     //
       
  1090     TInt index( 0 );
       
  1091     TKeyArrayFix cmpKeyArray(0, ECmpTInt);
       
  1092     for (i = keyArray.Count() - 1; i >= 0; --i)
       
  1093         {
       
  1094         if (iSequence->Find(keyArray[i], cmpKeyArray, index) != 0)
       
  1095             {
       
  1096             iSequence->InsertL(0, keyArray[i]);
       
  1097             }
       
  1098         }
       
  1099     if (iKey != KNotepadPseudoKeyIdForNewNote 
       
  1100         && iSequence->Find(iKey, cmpKeyArray, index) != 0) // not found
       
  1101         {
       
  1102         iKey = KNotepadPseudoKeyIdForNewNote;
       
  1103         }
       
  1104     iFlags &= ~ENotepadRequireSequenceUpdate; // flag off
       
  1105     }
       
  1106 
       
  1107 // -----------------------------------------------------------------------------
       
  1108 // CNotepadEditorDialog::IsSequenceAtLast
       
  1109 // -----------------------------------------------------------------------------
       
  1110 //
       
  1111 TBool CNotepadEditorDialog::IsSequenceAtLast() const
       
  1112     {
       
  1113     __ASSERT_DEBUG( iSequence, 
       
  1114         Panic(ENotepadLibraryPanicNullSequenceInEditor) );
       
  1115     return ( IsModeAdding() ? iSequence->Count() == 0 :
       
  1116         CurrentSequence() == iSequence->Count() - 1 );
       
  1117     }
       
  1118 
       
  1119 // -----------------------------------------------------------------------------
       
  1120 // CNotepadEditorDialog::IsSequenceAtFirst
       
  1121 // -----------------------------------------------------------------------------
       
  1122 //
       
  1123 TBool CNotepadEditorDialog::IsSequenceAtFirst() const
       
  1124     {
       
  1125     __ASSERT_DEBUG( iSequence, 
       
  1126         Panic(ENotepadLibraryPanicNullSequenceInEditor) );
       
  1127     return ( IsModeAdding() || CurrentSequence() == 0);
       
  1128     }
       
  1129 
       
  1130 // -----------------------------------------------------------------------------
       
  1131 // CNotepadEditorDialog::CurrentSequence
       
  1132 // -----------------------------------------------------------------------------
       
  1133 //
       
  1134 TInt CNotepadEditorDialog::CurrentSequence() const
       
  1135     {
       
  1136     __ASSERT_DEBUG( iSequence, 
       
  1137         Panic(ENotepadLibraryPanicNullSequenceInEditor) );
       
  1138     TInt index(KNotepadInvalidSequenceIndex);
       
  1139     TKeyArrayFix cmpKeyArray(0, ECmpTInt);
       
  1140     iSequence->Find(iKey, cmpKeyArray, index);
       
  1141     return index;
       
  1142     }
       
  1143 
       
  1144 // -----------------------------------------------------------------------------
       
  1145 // CNotepadEditorDialog::NextKeyInSequence
       
  1146 // -----------------------------------------------------------------------------
       
  1147 //
       
  1148 TInt CNotepadEditorDialog::NextKeyInSequence() const
       
  1149     {
       
  1150     __ASSERT_DEBUG( iSequence, 
       
  1151         Panic(ENotepadLibraryPanicNullSequenceInEditor) );
       
  1152     TInt nextKey(iKey);
       
  1153     if ( iKey == KNotepadPseudoKeyIdForNewNote ) // IsModeAdding
       
  1154         {
       
  1155         if ( iSequence->Count() > 0 )
       
  1156             {
       
  1157             nextKey = (*iSequence)[0];
       
  1158             }
       
  1159         }
       
  1160     else
       
  1161         {
       
  1162         TInt index ( CurrentSequence() );
       
  1163         if ( index < iSequence->Count() - 1 )
       
  1164             {
       
  1165             nextKey = (*iSequence)[index+1];
       
  1166             }
       
  1167         }
       
  1168     return nextKey;
       
  1169     }
       
  1170 
       
  1171 // -----------------------------------------------------------------------------
       
  1172 // CNotepadEditorDialog::PreviousKeyInSequence
       
  1173 // -----------------------------------------------------------------------------
       
  1174 //
       
  1175 TInt CNotepadEditorDialog::PreviousKeyInSequence() const
       
  1176     {
       
  1177     __ASSERT_DEBUG( iSequence, 
       
  1178         Panic(ENotepadLibraryPanicNullSequenceInEditor) );
       
  1179     __ASSERT_DEBUG( IsModeEditing(), 
       
  1180         Panic(ENotepadLibraryPanicEditorInvalidMode) );
       
  1181     TInt previousKey(iKey);
       
  1182     if ( IsModeEditing() )
       
  1183         {
       
  1184         TInt index( CurrentSequence() );
       
  1185         if ( index > 0 )
       
  1186             {
       
  1187             previousKey = (*iSequence)[index - 1];
       
  1188             }
       
  1189         }
       
  1190     return previousKey;
       
  1191     }
       
  1192 
       
  1193 // -----------------------------------------------------------------------------
       
  1194 // CNotepadEditorDialog::DoSearchL
       
  1195 // -----------------------------------------------------------------------------
       
  1196 //
       
  1197 TInt CNotepadEditorDialog::DoSearchL(CFindItemEngine::TFindItemSearchCase aCase)
       
  1198     {
       
  1199     CFindItemDialog* dialog = CFindItemDialog::NewL( iEditor->Text()->Read( 0 ), aCase );
       
  1200     TInt ret = dialog->ExecuteLD();
       
  1201     return ret;
       
  1202     }
       
  1203 
       
  1204 // -----------------------------------------------------------------------------
       
  1205 // CNotepadEditorDialog::IsContainLinefeedSymbol
       
  1206 // -----------------------------------------------------------------------------
       
  1207 //
       
  1208 TBool CNotepadEditorDialog::IsContainLinefeedSymbol(const TDesC& aDes)
       
  1209     {
       
  1210     const TChar linefeed(0x21B2);
       
  1211 	  for(TInt i = 0; i < aDes.Length(); i++)
       
  1212 		    {
       
  1213 		    TChar c(aDes[i]);
       
  1214 		    if(c == linefeed)
       
  1215 			    {
       
  1216 			    return ETrue;		
       
  1217 			    }
       
  1218 		    }
       
  1219 	   return EFalse;
       
  1220 	  }
       
  1221 
       
  1222 // CNotepadEditorDialog::FocusChanged
       
  1223 // -----------------------------------------------------------------------------
       
  1224 //	
       
  1225 #ifdef RD_INTELLIGENT_TEXT_INPUT
       
  1226 void CNotepadEditorDialog::FocusChanged(TDrawNow /*aDrawNow*/)
       
  1227     {
       
  1228     if(iEditor)
       
  1229     	{
       
  1230         iEditor->SetCursorVisible(IsFocused());
       
  1231     	}
       
  1232     }
       
  1233 #endif
       
  1234 	
       
  1235 // -----------------------------------------------------------------------------
       
  1236 // CNotepadEditorDialog::CNotepadEditorDialog_Reserved
       
  1237 // -----------------------------------------------------------------------------
       
  1238 //
       
  1239 EXPORT_C void CNotepadEditorDialog::CNotepadEditorDialog_Reserved()
       
  1240     {
       
  1241     }
       
  1242 
       
  1243 // End of File