notepad/notepad1/LibSrc/NpdViewerDialog.cpp
changeset 0 f979ecb2b13e
child 14 21239b3bcd78
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 NotepadViewer mode.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <aknappui.h>
       
    21 #include <avkon.hrh>
       
    22 #include <eikmenup.h>
       
    23 #include <txtetext.h>
       
    24 #include <AknForm.h>
       
    25 #include <aknnotedialog.h>
       
    26 #include <eikapp.h>
       
    27 #include <aknnotewrappers.h>
       
    28 #include <sendui.h>
       
    29 #include <SenduiMtmUids.h>
       
    30 #include <Sendnorm.rsg>
       
    31 #include <barsread.h>
       
    32 #include <featmgr.h>
       
    33 #include <hlplch.h>
       
    34 #include <finditemmenu.h>
       
    35 #include <ItemFinder.h> 
       
    36 #include <CommonContentPolicy.h>
       
    37 #include <StringLoader.h>
       
    38 #include <centralrepository.h>
       
    39 #include <CommonUiInternalCRKeys.h>
       
    40 #include <akntitle.h>
       
    41 
       
    42 #include <NpdLib.rsg>
       
    43 #include "NpdLib.hrh"
       
    44 #include <finditem.hrh>
       
    45 #include <CMessageData.h>
       
    46 #include "NpdViewerDialog.h"
       
    47 #include "NpdApi.h"
       
    48 #include "NpdLib.h"
       
    49 #include "NpdUtil.h"
       
    50 #include "NpdRichTextEditor.h"
       
    51 #include "NpdLibPanic.h"
       
    52 
       
    53 #include <csxhelp/nmake.hlp.hrh>
       
    54 
       
    55 // ============================ MEMBER FUNCTIONS ===============================
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CNotepadViewerDialog::NewL
       
    59 // constructor.
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 EXPORT_C CNotepadViewerDialog* CNotepadViewerDialog::NewL(
       
    63     const TInt aResId, 
       
    64     CEikDialog** aSelfPtr )
       
    65     {
       
    66     CNotepadViewerDialog* self = new(ELeave) CNotepadViewerDialog;
       
    67     self->iSelfPtr = aSelfPtr;
       
    68     CleanupStack::PushL(self);
       
    69 
       
    70     TResourceReader rr;
       
    71     self->iCoeEnv->CreateResourceReaderLC(rr, aResId); // Push rr
       
    72     self->ConstructL( rr );
       
    73     CleanupStack::PopAndDestroy(); // rr
       
    74     CleanupStack::Pop(); // self
       
    75     return self;
       
    76     }
       
    77 
       
    78 void CNotepadViewerDialog::ConstructL(TResourceReader &rr)
       
    79     {
       
    80     CNotepadDialogBase::ConstructL(rr);
       
    81     iAutoFinder = CItemFinder::NewL();
       
    82     iFindMenu = CFindItemMenu::NewL( EFindItemMenuPlaceHolder );
       
    83     iFindMenu->AttachItemFinderMenuL(0);
       
    84     iForwardLocked = EFalse;
       
    85     iReturnValue = KErrNone;
       
    86     iFileExist = EFalse;
       
    87     iAutomaticHlValue = ETrue;
       
    88     iAutomaticHlInitialized = EFalse;
       
    89     iTaskSwapperFlag = EFalse;
       
    90     ReadAutoHlCenRepValueAndSetNotifyL();
       
    91     SetAutomaticHighlightL(iAutomaticHlValue);
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CNotepadViewerDialog::~CNotepadViewerDialog
       
    96 // Destructor
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 EXPORT_C CNotepadViewerDialog::~CNotepadViewerDialog()
       
   100     {
       
   101     if( iPeriodicTimer )
       
   102         {
       
   103         iPeriodicTimer->Cancel();
       
   104         delete iPeriodicTimer;
       
   105         iPeriodicTimer = NULL;
       
   106         }
       
   107     delete iFilename;
       
   108     delete iSendUi;
       
   109     delete iAutoFinder;
       
   110     delete iFindMenu;
       
   111     if( iNotifier )
       
   112         {
       
   113         iNotifier->StopListening();
       
   114         delete iNotifier;        
       
   115         }
       
   116     delete iCenRepSession;
       
   117     iCenRepSession = NULL;
       
   118     }
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // CNotepadViewerDialog::SetFileL
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 EXPORT_C void CNotepadViewerDialog::SetFileL(
       
   125     const TDesC& aFilename, 
       
   126     const TDesC* aTitle,
       
   127     TBool aGuessEncoding,
       
   128     TUint aEncoding )
       
   129     {
       
   130     HBufC* filename = aFilename.AllocL();
       
   131     delete iFilename;
       
   132     iFilename = filename;
       
   133     if ( aTitle )
       
   134         {
       
   135         CNotepadDialogBase::SetTitleL(aTitle);
       
   136         }
       
   137     else
       
   138         {
       
   139         TPtr ptr = filename->Des();
       
   140         TParsePtr parse(ptr);
       
   141         TPtrC name = parse.NameAndExt();
       
   142         CNotepadDialogBase::SetTitleL(&name); // SetTitleL copies the name.
       
   143         }
       
   144 
       
   145     // Check whether the file is forward locked.
       
   146     CCommonContentPolicy *ccp = CCommonContentPolicy::NewLC();
       
   147     if(ccp->IsClosedFileL(aFilename))
       
   148         {
       
   149         iForwardLocked = ETrue;
       
   150         }
       
   151     CleanupStack::PopAndDestroy(ccp);
       
   152 
       
   153     iGuessEncoding = aGuessEncoding;
       
   154     iEncoding = aEncoding;
       
   155     iDescriptorViewer = EFalse;
       
   156     iEditable = EFalse;
       
   157     }
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CNotepadViewerDialog::SetFileL file handle
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 EXPORT_C void CNotepadViewerDialog::SetFileL(
       
   164     RFile& aFile, 
       
   165     const TDesC* aTitle,
       
   166     TBool aGuessEncoding,
       
   167     TUint aEncoding )
       
   168     {
       
   169     iFile = &aFile;
       
   170     CNotepadDialogBase::SetFileHandleL(aFile);
       
   171     if ( aTitle )
       
   172         {
       
   173         CNotepadDialogBase::SetTitleL(aTitle);
       
   174         }
       
   175     else
       
   176         {
       
   177         TBuf<256> name;
       
   178         aFile.Name(name);
       
   179         CNotepadDialogBase::SetTitleL(&name); // SetTitleL copies the name.
       
   180         }
       
   181 
       
   182     // Check whether the file is forward locked.
       
   183     CCommonContentPolicy *ccp = CCommonContentPolicy::NewLC();
       
   184     if(ccp->IsClosedFileL(aFile))
       
   185         {
       
   186         iForwardLocked = ETrue;
       
   187         }
       
   188     CleanupStack::PopAndDestroy(ccp);
       
   189 
       
   190     iGuessEncoding = aGuessEncoding;
       
   191     iEncoding = aEncoding;
       
   192     iDescriptorViewer = EFalse;
       
   193     iEditable = EFalse;
       
   194     iFileExist = ETrue;
       
   195     }
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // CNotepadViewerDialog::InitDescriptorViewerL
       
   199 // -----------------------------------------------------------------------------
       
   200 //
       
   201 void CNotepadViewerDialog::InitDescriptorViewerL
       
   202     (HBufC** aContentPointer,
       
   203     TInt& aReturnStatus,
       
   204     TBool aReadOnly,
       
   205     const TDesC& aText,
       
   206     const TDesC& aTitle, 
       
   207     const TDesC& aDelConfirmation 
       
   208     )
       
   209     {
       
   210     if ( aTitle.Length() != 0 )
       
   211         {
       
   212         CNotepadDialogBase::SetTitleL(&aTitle);
       
   213         }
       
   214     iContent.Set(aText);
       
   215     iContentPointer = aContentPointer;
       
   216     iDescriptorViewer = ETrue;
       
   217     iEditable = !aReadOnly;
       
   218     iTitle.Set(aTitle);
       
   219     iDelConfirmation.Set(aDelConfirmation);
       
   220     iReturnValue = &aReturnStatus;
       
   221     }
       
   222 
       
   223 // -----------------------------------------------------------------------------
       
   224 // CNotepadViewerDialog::LoadFileL
       
   225 // -----------------------------------------------------------------------------
       
   226 //
       
   227 EXPORT_C void CNotepadViewerDialog::LoadFileL()
       
   228     {
       
   229     __ASSERT_DEBUG( iEditor, Panic(ENotepadLibraryPanicNoEdwin) );
       
   230     __ASSERT_DEBUG( iFilename, Panic(ENotepadLibraryPanicNoFileSpecified) );
       
   231     iEditor->SetTextL(NULL);
       
   232     NotepadUtil::LoadFileL( *iCoeEnv, *iFilename, iGuessEncoding,
       
   233         iEncoding, *(iEditor->Text()) );
       
   234     iEditor->SetAmountToFormat(iEditor->Text()->DocumentLength());
       
   235     iEditor->HandleTextChangedL();
       
   236     iAutoFinder->SetEditor((CEikRichTextEditor**)&iEditor);
       
   237 
       
   238     RefreshTitleL();
       
   239     }
       
   240 
       
   241 // -----------------------------------------------------------------------------
       
   242 // CNotepadViewerDialog::LoadFileL file handle
       
   243 // -----------------------------------------------------------------------------
       
   244 //
       
   245 EXPORT_C void CNotepadViewerDialog::LoadFileL(RFile& aFile)
       
   246     {
       
   247     __ASSERT_DEBUG( iEditor, Panic(ENotepadLibraryPanicNoEdwin) );
       
   248     //__ASSERT_DEBUG( iFilename, Panic(ENotepadLibraryPanicNoFileSpecified) );
       
   249     iEditor->SetTextL(NULL);
       
   250    TBool error = NotepadUtil::LoadFileL( *iCoeEnv, aFile, iGuessEncoding,
       
   251         iEncoding, *(iEditor->Text()) );
       
   252     iEditor->SetAmountToFormat(iEditor->Text()->DocumentLength()); 
       
   253     iEditor->HandleTextChangedL();
       
   254     iAutoFinder->SetEditor((CEikRichTextEditor**)&iEditor);
       
   255 
       
   256     RefreshTitleL();
       
   257     if( error != KErrNone)
       
   258         {
       
   259         
       
   260         HBufC* text = StringLoader::LoadLC(R_NOTEPAD_QTN_FILE_CORRUPTED);
       
   261         CAknErrorNote* mErrorNote;
       
   262         mErrorNote = new (ELeave) CAknErrorNote( ETrue );
       
   263         mErrorNote->ExecuteLD(*text);
       
   264         CleanupStack::PopAndDestroy( text );
       
   265          
       
   266         iPeriodicTimer = CPeriodic::NewL( CActive::EPriorityStandard );    
       
   267         if( !iPeriodicTimer->IsActive() )
       
   268             {
       
   269               iPeriodicTimer->Start( 1, 1000000/2, 
       
   270                                TCallBack( CNotepadViewerDialog::TimerCallbackL, this ) );
       
   271 	        }
       
   272         }
       
   273     }
       
   274 
       
   275 // -----------------------------------------------------------------------------
       
   276 // CNotepadViewerDialog::OpenFileL
       
   277 // -----------------------------------------------------------------------------
       
   278 //
       
   279 EXPORT_C void CNotepadViewerDialog::OpenFileL(
       
   280     const TDesC& aFilename, 
       
   281     const TDesC* aTitle,
       
   282     TBool aGuessEncoding,
       
   283     TUint aEncoding )
       
   284     {
       
   285     SetFileL(aFilename, aTitle, aGuessEncoding, aEncoding);
       
   286     LoadFileL();
       
   287     }
       
   288 
       
   289 // -----------------------------------------------------------------------------
       
   290 // CNotepadViewerDialog::OpenFileL file handle
       
   291 // -----------------------------------------------------------------------------
       
   292 //
       
   293 EXPORT_C void CNotepadViewerDialog::OpenFileL(
       
   294     RFile& aFile, 
       
   295     const TDesC* aTitle,
       
   296     TBool aGuessEncoding,
       
   297     TUint aEncoding )
       
   298     {
       
   299     SetFileL(aFile, aTitle, aGuessEncoding, aEncoding);
       
   300     LoadFileL(aFile);
       
   301     }
       
   302 
       
   303 // ----------------------------------------------------
       
   304 // CNotepadViewerDialog::SetAutomaticHighlightL
       
   305 // 
       
   306 // ----------------------------------------------------
       
   307 void CNotepadViewerDialog::SetAutomaticHighlightL( const TBool aSwitchON )
       
   308     {
       
   309     if ( iAutoFinder )
       
   310         {
       
   311         // content highlight
       
   312         if ( aSwitchON )
       
   313             { // switch ON
       
   314             iAutoFinder->SetFindModeL( 
       
   315                 CItemFinder::EPhoneNumber |
       
   316                 CItemFinder::EUrlAddress |
       
   317                 CItemFinder::EEmailAddress );
       
   318             }
       
   319         else
       
   320             { // switch OFF
       
   321             iAutoFinder->SetFindModeL( 
       
   322                 CItemFinder::ENoneSelected );
       
   323             }
       
   324         }
       
   325     }
       
   326 
       
   327 // ----------------------------------------------------
       
   328 // CNotepadViewerDialog::ReadAutoHlCenRepValueAndSetNotifyL
       
   329 // 
       
   330 // ----------------------------------------------------
       
   331 void CNotepadViewerDialog::ReadAutoHlCenRepValueAndSetNotifyL()
       
   332     {
       
   333     if ( iAutomaticHlInitialized )
       
   334         return;
       
   335     // Create the session
       
   336     iCenRepSession = CRepository::NewL( KCRUidCommonUi );
       
   337     if( iCenRepSession )
       
   338         {
       
   339         // Get the value of AutomaticHighlight key
       
   340         iCenRepSession->Get( KCuiAutomaticHighlight, iAutomaticHlValue );
       
   341         // Create the notifer
       
   342         iNotifier = 
       
   343             CCenRepNotifyHandler::NewL( 
       
   344                 *this, *iCenRepSession, CCenRepNotifyHandler::EIntKey,
       
   345                 KCuiAutomaticHighlight );
       
   346         // Start listening
       
   347         iNotifier->StartListeningL();       
       
   348         }
       
   349     iAutomaticHlInitialized = ETrue; // Done once per viewer
       
   350     }
       
   351 
       
   352 // -----------------------------------------------------------------------------
       
   353 // CNotepadViewerDialog::OkToExitL
       
   354 // -----------------------------------------------------------------------------
       
   355 //
       
   356 TBool CNotepadViewerDialog::OkToExitL( TInt aButtonId )
       
   357     {
       
   358     iFlags &= ~ENotepadMenuByOkKey;
       
   359     TBool isOk(ETrue);
       
   360     switch ( aButtonId )
       
   361         {
       
   362 		//MSK        
       
   363         case EAknSoftkeyContextOptions:
       
   364 	   		{
       
   365 	   		iFlags |= ENotepadMenuByOkKey;
       
   366 	   		DisplayMenuL();
       
   367 	   		isOk= EFalse;
       
   368 	   		}
       
   369 	   		break;
       
   370         case EAknSoftkeyBack:
       
   371             if ( !IsWaiting() ) // not API, but viewer application
       
   372                 {
       
   373                 iAvkonAppUi->HandleCommandL(EEikCmdExit);
       
   374                 isOk = EFalse ;
       
   375                 }
       
   376             break;
       
   377         case EAknSoftkeyOptions:
       
   378              iTaskSwapperFlag = ETrue;
       
   379         default:
       
   380             isOk = CAknDialog::OkToExitL(aButtonId);
       
   381             break;
       
   382         }
       
   383     return isOk;
       
   384     }
       
   385 
       
   386 // ----------------------------------------------------------------------------
       
   387 // CNotepadViewerDialog::HandleNotifyInt
       
   388 // ----------------------------------------------------------------------------    
       
   389 //
       
   390 void CNotepadViewerDialog::HandleNotifyInt( 
       
   391     TUint32  /*aId*/, 
       
   392     TInt aNewValue )
       
   393     {   
       
   394     // Notifies changes on KCuiAutomaticHighlight
       
   395     TRAPD(error,SetAutomaticHighlightL( aNewValue ));
       
   396 	if ( error != KErrNone )
       
   397 		{
       
   398 		_LIT(KNpdViewerNotifierPanicType,"CNotepadViewerDialog::SetAutomaticHighlightL");
       
   399 		User::Panic( KNpdViewerNotifierPanicType, error );
       
   400 		}
       
   401     }
       
   402 
       
   403 // ----------------------------------------------------------------------------
       
   404 // CMsgSmsViewerAppUi::HandleNotifyError
       
   405 // ----------------------------------------------------------------------------    
       
   406 //
       
   407 void CNotepadViewerDialog::HandleNotifyError( 
       
   408     TUint32 /*aId*/, 
       
   409     TInt /* aError */, 
       
   410     CCenRepNotifyHandler* /* aHandler */ )
       
   411     {
       
   412     // Remove session and notifier
       
   413     if( iNotifier )
       
   414         {
       
   415         iNotifier->StopListening();       
       
   416         delete iNotifier;
       
   417         iNotifier = NULL;
       
   418         }
       
   419     delete iCenRepSession;    
       
   420     iCenRepSession = NULL;
       
   421     }
       
   422 
       
   423 // ---------------------------------------------------------
       
   424 // CNotepadViewerDialog::HandleResourceChange
       
   425 // from CCoeControl
       
   426 // ---------------------------------------------------------
       
   427 //
       
   428 void CNotepadViewerDialog::HandleResourceChange(TInt aType)
       
   429     {
       
   430     
       
   431     if(aType == KAknsMessageSkinChange)
       
   432     	{
       
   433     	if(iEditor && IsActivated())
       
   434     		{
       
   435     		iEditor->HandleResourceChange(aType);
       
   436     		}
       
   437     	}
       
   438     if (aType == KEikDynamicLayoutVariantSwitch)
       
   439         {
       
   440         CAknDialog::HandleResourceChange(aType);
       
   441 		CEikDialog::Layout();
       
   442 		if (iEditor && IsActivated())
       
   443 			{
       
   444 			iEditor->HandleResourceChange(aType);
       
   445 			}
       
   446 		iEditor->DrawDeferred();
       
   447 		}
       
   448     }
       
   449 
       
   450 // ---------------------------------------------------------
       
   451 // CNotepadViewerDialog::SizeChanged
       
   452 // from CCoeControl
       
   453 // ---------------------------------------------------------
       
   454 //
       
   455 void CNotepadViewerDialog::SizeChanged()
       
   456     {
       
   457     CNotepadDialogBase::SizeChanged();
       
   458     if (iEditor && IsActivated())
       
   459         {
       
   460         TRAP_IGNORE(iEditor->DoEditorLayoutL());
       
   461         }
       
   462     }
       
   463 
       
   464 // -----------------------------------------------------------------------------
       
   465 // CNotepadViewerDialog::ShowConfirmationNoteL
       
   466 // -----------------------------------------------------------------------------
       
   467 //
       
   468 void CNotepadViewerDialog::ShowConfirmationNoteL()
       
   469     {
       
   470     HBufC* text = StringLoader::LoadLC(R_NOTEPAD_MEMO_ATTA_SAVED); //<NOTEPAD_SAVE_NOTE_MAXLENGTH> text;
       
   471     CAknConfirmationNote* note = new(ELeave) CAknConfirmationNote();
       
   472     note->SetMopParent(this);
       
   473     note->ExecuteLD(*text);
       
   474     CleanupStack::PopAndDestroy(text);
       
   475     }
       
   476 
       
   477 // -----------------------------------------------------------------------------
       
   478 // CNotepadViewerDialog::PostLayoutDynInitL
       
   479 // -----------------------------------------------------------------------------
       
   480 //
       
   481 void CNotepadViewerDialog::PostLayoutDynInitL()
       
   482     {
       
   483     iEditor = STATIC_CAST(CNotepadRichTextEditor*, Control(ENotepadIdRichTextEditor));
       
   484     iEditor->ConstructBaseL(this);
       
   485     __ASSERT_DEBUG( iEditor, Panic(ENotepadLibraryPanicNoEdwin) );
       
   486     iEditor->EnableCcpuSupportL(EFalse);
       
   487     iEditor->CreatePreAllocatedScrollBarFrameL()->SetScrollBarVisibilityL(
       
   488         CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
       
   489      
       
   490      CEikAppUi* container = iAvkonAppUi->ContainerAppUi();
       
   491     //cannot find UIDs in SenduiMtmUids.h
       
   492     TUid appuid = KNullUid;
       
   493     if ( container )
       
   494         {
       
   495         appuid = container->Application()->AppDllUid();
       
   496         }
       
   497     if ( appuid != KSenduiMMSEditorUid && appuid != KSenduiMailEditorUid )
       
   498         {
       
   499         iSendUi = CSendUi::NewL();
       
   500         }
       
   501 
       
   502     TRect rect(iEikonEnv->EikAppUi()->ClientRect());
       
   503     iEditor->SetRect(rect);
       
   504 	
       
   505     DrawNow();
       
   506     }
       
   507 
       
   508 // -----------------------------------------------------------------------------
       
   509 // CNotepadViewerDialog::ActivateL
       
   510 // -----------------------------------------------------------------------------
       
   511 //
       
   512 void CNotepadViewerDialog::ActivateL()
       
   513     {
       
   514     __ASSERT_DEBUG( iEditor, Panic(ENotepadLibraryPanicNoEdwin) );
       
   515     CNotepadDialogBase::ActivateL();
       
   516     CAknTitlePane*    TitlePane = 
       
   517         STATIC_CAST(CAknTitlePane*, 
       
   518             (((CAknAppUi*)iEikonEnv->EikAppUi())->StatusPane())
       
   519                 ->ControlL(TUid::Uid(EEikStatusPaneUidTitle)));
       
   520  	TitlePane->SetTextL (_L(""));  
       
   521     iEditor->InitNotepadEditorL(this);
       
   522     if (iFileExist) // when SetFileL before execute
       
   523         {
       
   524         LoadFileL(*iFile);
       
   525         }
       
   526     else if (iContent.Length() != 0)
       
   527         {
       
   528         iEditor->SetTextL(NULL);
       
   529         iEditor->SetTextL(&iContent);
       
   530         iEditor->SetAmountToFormat(iContent.Length()); // Will ensure first Format in SetTextL is in correct mode
       
   531         iEditor->HandleTextChangedL();
       
   532         iAutoFinder->SetEditor((CEikRichTextEditor**)&iEditor);
       
   533         RefreshTitleL();
       
   534         }
       
   535     }
       
   536 
       
   537 // -----------------------------------------------------------------------------
       
   538 // CNotepadViewerDialog::OfferKeyEventL
       
   539 // from CoeControl
       
   540 // -----------------------------------------------------------------------------
       
   541 //
       
   542 TKeyResponse CNotepadViewerDialog::OfferKeyEventL(
       
   543     const TKeyEvent& aKeyEvent, 
       
   544     TEventCode aType )
       
   545     {
       
   546     if ( MenuShowing() || aType != EEventKey )
       
   547         {
       
   548         return CAknDialog::OfferKeyEventL(aKeyEvent, aType);
       
   549         }
       
   550     TKeyResponse keyResponse(EKeyWasConsumed);
       
   551     switch (aKeyEvent.iCode)
       
   552         {
       
   553         case EKeyOK: // into next case
       
   554         case EKeyEnter:
       
   555             if ( aKeyEvent.iRepeats == 0 &&
       
   556                 !(aKeyEvent.iModifiers & (EAllStdModifiers|EModifierSpecial)) )
       
   557                 {
       
   558                 iFlags |= ENotepadMenuByOkKey;
       
   559                 DisplayMenuL();
       
   560                 }
       
   561             break;
       
   562         case EKeyRightArrow: // into next case
       
   563         case EKeyLeftArrow:
       
   564             break;
       
   565         case EKeyUpArrow:
       
   566    	        iAutoFinder->NextItemOrScrollL( CItemFinder::ENextUp );
       
   567             break;
       
   568         case EKeyDownArrow:
       
   569    	        iAutoFinder->NextItemOrScrollL( CItemFinder::ENextDown );
       
   570             break;
       
   571         case EKeyPhoneSend:
       
   572              HandleNumberCallL();
       
   573             break;
       
   574         default:
       
   575             keyResponse = CAknDialog::OfferKeyEventL(aKeyEvent, aType);
       
   576         }
       
   577  
       
   578     return keyResponse;
       
   579     }
       
   580 // -----------------------------------------------------------------------------
       
   581 // CNotepadViewerDialog::HandleDialogPointerEventL
       
   582 // from CoeControl
       
   583 // -----------------------------------------------------------------------------
       
   584 //
       
   585 void CNotepadViewerDialog::HandleDialogPointerEventL( const TPointerEvent& aPointerEvent )
       
   586 {
       
   587 	
       
   588 	 if(!AknLayoutUtils::PenEnabled())
       
   589 	 {
       
   590 	 	return;
       
   591 	 }
       
   592 	 
       
   593     if(aPointerEvent.iType == TPointerEvent::EButton1Up ) 
       
   594     {
       
   595    
       
   596        TInt curPos = iEditor->CursorPos();	
       
   597        TRect rect = iEditor->Rect();  
       
   598        if ( !iAutoFinder->ItemWasTappedL( aPointerEvent.iPosition - rect.iTl ) )
       
   599          {
       
   600 		 	return;
       
   601 		 } 
       
   602 		 
       
   603        TInt curPos1 = iEditor->CursorPos();
       
   604        if (curPos == curPos1) 
       
   605        {
       
   606    			iFlags |= ENotepadMenuByOkKey;
       
   607    	    	DisplayMenuL();	       	
       
   608        }
       
   609    
       
   610     
       
   611     }
       
   612 }
       
   613 
       
   614 // -----------------------------------------------------------------------------
       
   615 // CNotepadViewerDialog::HandleNumberCallL
       
   616 // -----------------------------------------------------------------------------
       
   617 //
       
   618 void CNotepadViewerDialog::HandleNumberCallL()
       
   619     {
       
   620      const CItemFinder::CFindItemExt& findItem = iAutoFinder->CurrentItemExt(); 
       
   621      
       
   622      if (findItem.iItemType == CItemFinder::EEmailAddress)
       
   623     	 {
       
   624     	 iFindMenu->HandleVoIPCallL(findItem.iItemDescriptor->Des());
       
   625     	 }
       
   626      else if(findItem.iItemType == CItemFinder::EPhoneNumber )
       
   627         {
       
   628         iFindMenu->HandleCallL( findItem.iItemDescriptor->Des() );
       
   629         }         
       
   630     }
       
   631 
       
   632 // -----------------------------------------------------------------------------
       
   633 // CNotepadViewerDialog::GetHelpContext
       
   634 // -----------------------------------------------------------------------------
       
   635 //
       
   636 void CNotepadViewerDialog::GetHelpContext(TCoeHelpContext& aContext) const
       
   637     {
       
   638     aContext.iMajor = KUidNotepad;
       
   639     if(iEditable)
       
   640     	{
       
   641     	aContext.iContext = KNMAKE_HLP_MEMO_VIEWER_EDIT;
       
   642     	}
       
   643     else
       
   644       	{
       
   645     	aContext.iContext = KNMAKE_HLP_MEMO_VIEWER;
       
   646     	}
       
   647     
       
   648     }
       
   649 
       
   650 // -----------------------------------------------------------------------------
       
   651 // CNotepadViewerDialog::ProcessCommandL
       
   652 // from MEikCommandObserver
       
   653 // -----------------------------------------------------------------------------
       
   654 //
       
   655 void CNotepadViewerDialog::ProcessCommandL(TInt aCommandId)
       
   656     {
       
   657     HideMenu();
       
   658     switch (aCommandId)
       
   659         {
       
   660         case ENotepadCmdViewerSave:
       
   661             {
       
   662             TInt length(iEditor->TextLength());
       
   663             if ( length > 0 )
       
   664                 {
       
   665                 CNotepadApi::AddContentL(
       
   666                     iEditor->Text()->Read(0, length) );
       
   667                 ShowConfirmationNoteL();
       
   668                 }
       
   669             }
       
   670             break;
       
   671         case ENotepadCmdViewerEdit:
       
   672             {
       
   673             (*iContentPointer) = CNotepadApi::ExecTextEditorL(*iReturnValue, iContent , iTitle, iDelConfirmation);
       
   674             TryExitL(0);
       
   675             }
       
   676             break;
       
   677          case ENotepadCmdViewerDelete:
       
   678             {
       
   679             TBool deleted;
       
   680             if(iDelConfirmation.Length() != 0)
       
   681                 {
       
   682                 deleted = CNotepadDialogBase::ExecuteConfirmationQueryL( &iDelConfirmation );
       
   683                 }
       
   684             else
       
   685                 {
       
   686                 deleted = CNotepadDialogBase::ExecuteConfirmationQueryL( R_NOTEPAD_QUERY_DELETE_MEMO );
       
   687                 }
       
   688             if(deleted)
       
   689                 {
       
   690                 *iReturnValue = CNotepadApi::ENpdDataDeleted;
       
   691                 TryExitL(0);
       
   692                 }
       
   693             }
       
   694             break;
       
   695         case ENotepadCmdSend:
       
   696        		SendAsL( *iSendUi, aCommandId, iFileExist, NULL, iEditor->Text() );
       
   697             break;
       
   698         default:
       
   699             {
       
   700             if ( iFindMenu->CommandIsValidL(aCommandId) ) // can't really leave
       
   701                 {
       
   702                 iFindMenu->HandleItemFinderCommandL(aCommandId);
       
   703                 return;
       
   704                 }
       
   705             CNotepadDialogBase::ProcessCommandL(aCommandId);
       
   706             break;
       
   707             }
       
   708         }
       
   709     }
       
   710 
       
   711 // -----------------------------------------------------------------------------
       
   712 // CNotepadViewerDialog::DynInitMenuPaneL
       
   713 // from MEikMenuObserver
       
   714 // -----------------------------------------------------------------------------
       
   715 //
       
   716 void CNotepadViewerDialog::DynInitMenuPaneL(
       
   717     TInt aResourceId,
       
   718     CEikMenuPane* aMenuPane )
       
   719     {
       
   720     __ASSERT_DEBUG(aResourceId > 0, Panic(ENotepadLibraryPanicNoMenuResource));
       
   721     __ASSERT_DEBUG(aMenuPane, Panic(ENotepadLibraryPanicNullMenuPane));
       
   722     __ASSERT_DEBUG(iEditor, Panic(ENotepadLibraryPanicNoEdwin));
       
   723     TInt index;
       
   724     switch ( aResourceId )
       
   725         {
       
   726         case R_SENDUI_MENU:
       
   727             index = 2;
       
   728 			iSendUi->AddSendMenuItemL(*aMenuPane, index, ENotepadCmdSend );
       
   729             break;
       
   730         case R_NOTEPAD_VIEWER_MENU:
       
   731 
       
   732             if(iEditable)
       
   733                 {
       
   734                 aMenuPane->DeleteMenuItem(ENotepadCmdViewerSave);
       
   735 
       
   736                 if ( iFlags & ENotepadMenuByOkKey )
       
   737                     {
       
   738     				aMenuPane->DeleteMenuItem(EAknCmdExit);
       
   739     				if(FeatureManager::FeatureSupported(KFeatureIdHelp))
       
   740 						{
       
   741     				aMenuPane->DeleteMenuItem(EAknCmdHelp);
       
   742 						}
       
   743                     }
       
   744                 }
       
   745             else 
       
   746                 {
       
   747                 aMenuPane->DeleteMenuItem(ENotepadCmdViewerEdit);
       
   748                 aMenuPane->DeleteMenuItem(ENotepadCmdViewerDelete);
       
   749 
       
   750                 if (iForwardLocked || iDescriptorViewer)
       
   751                     {
       
   752                     aMenuPane->SetItemDimmed(ENotepadCmdViewerSave, ETrue);
       
   753                     }
       
   754 
       
   755                 if ( iSendUi && // not called from MMS/Mail editor
       
   756                     !NotepadUtil::IsEmpty(iEditor->Text()->Read(0)) 
       
   757                     && !iForwardLocked)
       
   758                     {
       
   759                     InsertSendMenuItemAfterL( *iSendUi, *aMenuPane, 
       
   760                         EFindItemMenuPlaceHolder);
       
   761                     }
       
   762 
       
   763                 if ( iFlags & ENotepadMenuByOkKey )
       
   764                     {
       
   765                     aMenuPane->DeleteMenuItem(EAknCmdExit);
       
   766                     if(FeatureManager::FeatureSupported(KFeatureIdHelp))
       
   767 						{
       
   768                     aMenuPane->DeleteMenuItem(EAknCmdHelp);
       
   769 						}
       
   770                     if(!iForwardLocked)
       
   771                         {
       
   772                         CEikMenuPaneItem::SData item = aMenuPane->ItemData(ENotepadCmdViewerSave);
       
   773                         aMenuPane->DeleteMenuItem(ENotepadCmdViewerSave);
       
   774                 	    aMenuPane->AddMenuItemL(item, EFindItemMenuPlaceHolder);
       
   775                         }
       
   776                     }
       
   777 
       
   778                 }
       
   779 
       
   780             iFindMenu->AddItemFindMenuL(iAutoFinder,aMenuPane,EFindItemMenuPlaceHolder,KNullDesC);
       
   781 
       
   782    			if(!FeatureManager::FeatureSupported(KFeatureIdHelp))
       
   783 				{
       
   784 				aMenuPane->DeleteMenuItem(EAknCmdHelp);
       
   785 				}
       
   786 
       
   787             break;
       
   788         default:
       
   789        		iFindMenu->UpdateItemFinderMenuL(aResourceId,aMenuPane);
       
   790             break;
       
   791         }
       
   792     }
       
   793 // -----------------------------------------------------------------------------
       
   794 // CNotepadViewerDialog::DynInitMenuBarL
       
   795 // from MEikMenuObserver
       
   796 // -----------------------------------------------------------------------------
       
   797 //    
       
   798 void CNotepadViewerDialog::DynInitMenuBarL(TInt aResourceId,CEikMenuBar* aMenuBar)
       
   799     {
       
   800     __ASSERT_DEBUG(aResourceId > 0, Panic(ENotepadLibraryPanicNoMenuResource));
       
   801     __ASSERT_DEBUG(aMenuBar, Panic(ENotepadLibraryPanicNoMenuResource));
       
   802     
       
   803     if(!iTaskSwapperFlag)
       
   804         {
       
   805         aMenuBar->SetMenuType(CEikMenuBar::EMenuOptionsNoTaskSwapper);
       
   806         }
       
   807     else
       
   808         {
       
   809         aMenuBar->SetMenuType(CEikMenuBar::EMenuOptions);
       
   810         iTaskSwapperFlag=EFalse;
       
   811         }
       
   812     }
       
   813 // -----------------------------------------------------------------------------
       
   814 // CNotepadViewerDialog::ExitDialogOnTimerExpireL
       
   815 // -----------------------------------------------------------------------------
       
   816 //    
       
   817 void CNotepadViewerDialog::ExitDialogOnTimerExpireL()
       
   818     {
       
   819        if ( !IsWaiting() ) // not API, but viewer application
       
   820         {
       
   821          iAvkonAppUi->HandleCommandL(EEikCmdExit);
       
   822         }
       
   823        else
       
   824         {
       
   825          TryExitL(0);    
       
   826         }    
       
   827     }
       
   828     
       
   829 // -----------------------------------------------------------------------------
       
   830 // CNotepadViewerDialog::TimerCallbackL
       
   831 // -----------------------------------------------------------------------------
       
   832 //
       
   833 TInt CNotepadViewerDialog::TimerCallbackL(TAny* aPtr)
       
   834     {
       
   835        static_cast<CNotepadViewerDialog*>( aPtr )->ExitDialogOnTimerExpireL(); 
       
   836        return ETrue;
       
   837     }
       
   838 
       
   839 // -----------------------------------------------------------------------------
       
   840 // CNotepadViewerDialog::CNotepadViewerDialog_Reserved
       
   841 // -----------------------------------------------------------------------------
       
   842 //
       
   843 EXPORT_C void CNotepadViewerDialog::CNotepadViewerDialog_Reserved()
       
   844     {
       
   845     }
       
   846 
       
   847 // End of File