commonuis/CommonUi/src/FindItemDialog.cpp
changeset 0 2f259fa3e83a
child 3 8ca85d2f0db7
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2002-2007 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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include <avkon.hrh>
       
    22 #include <aknappui.h>
       
    23 #include <eikrted.h> // for CRichTextEditor
       
    24 #include <txtrich.h> // for CRichText
       
    25 #include <AknUtils.h> // for AknUtils
       
    26 #include <eikmenup.h> // for CEikMenuPane
       
    27 #include <eikmenub.h> // for CEikMenuBar
       
    28 #include <e32keys.h> // for TKeyCode
       
    29 #include <akntitle.h> // for CAknTitlePane
       
    30 #include <aknnavi.h> // for NaviPane
       
    31 #include <aknnavide.h> // for CAknNavigationDecorator
       
    32 #include <aknnotedialog.h> // for CAknNoteDialog
       
    33 #include <akncontext.h> // for AknContextPane
       
    34 #include <bautils.h> // BaflUtils
       
    35 #include <eikbtgpc.h> // for ButtonGroupContainer
       
    36 #include <uikon.hrh> // for EKeyOk
       
    37 
       
    38 #include <FavouritesLimits.h> // KFavouritesMaxUrl
       
    39 #include <FavouritesItem.h> // for CBookmarkItem
       
    40 
       
    41 #include <FavouritesDb.h>
       
    42 
       
    43 #include <apgcli.h> // RApaLsSession for WMLBrowser launch
       
    44 
       
    45 #ifndef RD_VIRTUAL_PHONEBOOK
       
    46 #include <CPbkContactEngine.h> // Phonebook Engine
       
    47 #include <RPbkViewResourceFile.h> // Phonebook view dll resource loader
       
    48 #include <cpbkdatasaveappui.h> // for PbkDataSaveAppUi
       
    49 #include <CPbkFieldsInfo.h> // Phonebook field types
       
    50 #else // RD_VIRTUAL_PHONEBOOK
       
    51 #include <AiwServiceHandler.h> // CAiwServiceHandler
       
    52 #include <AiwContactAssignDataTypes.h> // AiwContactAssign
       
    53 #endif // !RD_VIRTUAL_PHONEBOOK
       
    54 
       
    55 #include <sendui.h> // for CSendAppUi
       
    56 #include <CMessageData.h> // for CMessageData
       
    57 #include <SendUiConsts.h> // Mtm uids
       
    58 
       
    59 #include <commonphoneparser.h> // Phonenumber parser
       
    60 
       
    61 #include <baclipb.h> // For CClipboard
       
    62 
       
    63 #include <SchemeHandler.h> // For CSchemeHandler
       
    64 
       
    65 #include <aknnotewrappers.h>
       
    66 
       
    67 #include <finditemui.rsg>
       
    68 
       
    69 #include <featmgr.h>
       
    70 
       
    71 #include "finditemdialogpanic.h"
       
    72 #include "finditemdialog.h"
       
    73 #include "finditem.hrh"
       
    74 #include "finditemcontroller.h"
       
    75 
       
    76 #include <bldvariant.hrh>
       
    77 #include <find.hlp.hrh> // for help context
       
    78 #include <hlplch.h> // For HlpLauncher
       
    79 
       
    80 #include <aknlayout.cdl.h>
       
    81 #include <applayout.cdl.h>
       
    82 #include <AiwCommon.hrh>
       
    83 
       
    84 #include "FindItemVoIPExtension.h"
       
    85 #include "FindItemMenuWrapper.h"
       
    86 
       
    87 #include <AknDef.h> // KEikDynamicLayoutVariantSwitch
       
    88 #include <AknsBasicBackgroundControlContext.h>
       
    89 #include <AknsUtils.h> // MAknsSkinInstance
       
    90 #include <AknsDrawUtils.h> // AknsDrawUtils
       
    91 #include <aknlayoutscalable_apps.cdl.h>
       
    92 
       
    93 #include <txtfrmat.h>  // for TCharFormat
       
    94 
       
    95 #include <aknnavilabel.h> // for changing the lable of navipane
       
    96 
       
    97 #include <AknTasHook.h> // for testability hooks
       
    98 _LIT( KResFileName, "z:\\resource\\finditemui.rsc" );
       
    99 
       
   100 // Panic
       
   101 _LIT( KFindItemPanic, "FindItemDialog" );
       
   102 // Space for WML Browser's parameter
       
   103 _LIT( KSpace, " " );
       
   104 // Position indicator in navipane
       
   105 _LIT( KPosIndicator, "%d/%d" );
       
   106 // Period and space constant for inserting paragraphs
       
   107 _LIT( KPeriodAndSpace, ". " );
       
   108 
       
   109 // Point where edwin changes from full to band formatting
       
   110 const TInt KFullFormattingUpperThreshold = 2000;
       
   111 // If edwin is using band formatting, there should be enough
       
   112 // paragraphs to make it faster.
       
   113 const TInt KLengthOfRecommendedParagraph = 500;
       
   114 // Maximum length of Browser bookmark
       
   115 const TInt KMaxBookmarkNameLength = 50;
       
   116 
       
   117 // Wap Browser's constants UId
       
   118 const TUid KWapUid = { 0x10008D39 };
       
   119 
       
   120 // magic number for Wml browser to open the URL
       
   121 _LIT( KWmlBrowserParameter, "4");
       
   122 
       
   123 _LIT( KRtspUrlAddress, "rtsp://" );
       
   124 _LIT( KHhttpAddress, "http://" );
       
   125 
       
   126 const TInt KCommonUiEdwinLines = 7;
       
   127 
       
   128 const TUid KCommonUIUid = { 0x100058FD };
       
   129 
       
   130 /**
       
   131 * Class to
       
   132 */
       
   133 class CRichTextEditorContainer
       
   134     : public CEikBorderedControl
       
   135     {
       
   136     public: // Constructors and destructors
       
   137 
       
   138         /**
       
   139         * Constructor.
       
   140         */
       
   141         CRichTextEditorContainer();
       
   142 
       
   143         /**
       
   144         * Destructor.
       
   145         */
       
   146         ~CRichTextEditorContainer();
       
   147 
       
   148     public: // Functions from base classes
       
   149 
       
   150         /**
       
   151         * From CCoeControl
       
   152         */
       
   153         void ConstructFromResourceL( TResourceReader& aReader );
       
   154 
       
   155         /**
       
   156         * From CCoeControl
       
   157         */
       
   158         void SizeChanged();
       
   159 
       
   160         /**
       
   161         * From CCoeControl.
       
   162         */
       
   163         void Draw( const TRect& aRect ) const;
       
   164 
       
   165         /**
       
   166         * From CCoeControl
       
   167         */
       
   168         TInt CountComponentControls() const;
       
   169 
       
   170         /**
       
   171         * From CCoeControl
       
   172         */
       
   173         CCoeControl* ComponentControl( TInt aIndex ) const;
       
   174 
       
   175         /**
       
   176         * From CCoeControl
       
   177         */
       
   178         void HandleResourceChange( TInt aType );
       
   179 
       
   180         /**
       
   181         * From CCoeControl
       
   182         */
       
   183         TSize MinimumSize();
       
   184 
       
   185     public: // data
       
   186 
       
   187         // Rich text editor.
       
   188         CEikRichTextEditor* iEditor;
       
   189 
       
   190         TInt iRows;
       
   191 
       
   192         // Background context.
       
   193         CAknsBasicBackgroundControlContext* iBgContext;
       
   194     };
       
   195 
       
   196 const CFindItemEngine::TFindItemSearchCase KSearchTelInternetNumber =
       
   197     static_cast<CFindItemEngine::TFindItemSearchCase>
       
   198         ( CFindItemEngine::EFindItemSearchPhoneNumberBin |
       
   199         CFindItemEngine::EFindItemSearchMailAddressBin );
       
   200 
       
   201 // -----------------------------------------------------------------------------
       
   202 // Panic
       
   203 //
       
   204 // -----------------------------------------------------------------------------
       
   205 GLDEF_C void Panic( TFindItemDialogPanic aPanic )
       
   206     {
       
   207     User::Panic( KFindItemPanic, aPanic );
       
   208     }
       
   209 
       
   210 NONSHARABLE_CLASS(PBAiwNotify): public MAiwNotifyCallback
       
   211     {
       
   212 public:
       
   213     // aiw call back funtion
       
   214     // Fix for ESLM-7XH9UM: we must return true for the   
       
   215     // phonebook to know it can exit    
       
   216     TInt HandleNotifyL(TInt aCmdId, TInt aEventId,
       
   217             CAiwGenericParamList& aEventParamList,
       
   218             const CAiwGenericParamList& aInParamList);
       
   219     };
       
   220 
       
   221 TInt PBAiwNotify::HandleNotifyL(TInt /*aCmdId*/, TInt aEventId,
       
   222         CAiwGenericParamList& aEventParamList,
       
   223         const CAiwGenericParamList& /*aInParamList*/)
       
   224     {
       
   225     if (aEventId == KAiwEventError)
       
   226         {
       
   227         if (aEventParamList.Count() > 0)
       
   228             {
       
   229             TInt32 err = aEventParamList[0].Value().AsTInt32();
       
   230             User::Leave(err);                
       
   231             }
       
   232         }
       
   233     // Fix for ESLM-7XH9UM: we must return true for the   
       
   234     // phonebook to know it can exit    
       
   235     return ETrue;
       
   236     }    
       
   237 
       
   238 NONSHARABLE_CLASS(CItemFinderExtension) : public CBase
       
   239 	{
       
   240 public: 
       
   241 	~CItemFinderExtension(); 
       
   242 	static CItemFinderExtension* NewL(); 
       
   243 	
       
   244 	//new function
       
   245 public:
       
   246 	PBAiwNotify* CallBack();
       
   247 	
       
   248 private: 
       
   249 	CItemFinderExtension(); 
       
   250 	void ConstructL();	
       
   251 	
       
   252 public:
       
   253 	PBAiwNotify iCallBack;
       
   254 	};
       
   255 
       
   256 CItemFinderExtension::~CItemFinderExtension()
       
   257 	{
       
   258 	
       
   259 	}
       
   260 
       
   261 CItemFinderExtension* CItemFinderExtension::NewL()
       
   262 	{
       
   263 	CItemFinderExtension* self = new ( ELeave )CItemFinderExtension;
       
   264 	CleanupStack::PushL(self);
       
   265 	self->ConstructL();
       
   266 	CleanupStack::Pop();
       
   267 	return self;
       
   268 	}
       
   269 
       
   270 PBAiwNotify* CItemFinderExtension::CallBack()
       
   271 	{
       
   272 	return &iCallBack;
       
   273 	}
       
   274 
       
   275 CItemFinderExtension::CItemFinderExtension()
       
   276 	{
       
   277 	
       
   278 	}
       
   279 
       
   280 void CItemFinderExtension::ConstructL()
       
   281 	{
       
   282 	
       
   283 	}
       
   284 
       
   285 
       
   286 
       
   287 // ================= MEMBER FUNCTIONS =======================
       
   288 
       
   289 // -----------------------------------------------------------------------------
       
   290 // CFindItemDialog::~CFindItemDialog
       
   291 //  Default destructor
       
   292 // -----------------------------------------------------------------------------
       
   293 //
       
   294 EXPORT_C CFindItemDialog::~CFindItemDialog()
       
   295     {
       
   296     AKNTASHOOK_REMOVE();
       
   297     // Remove from stack
       
   298     iEikonEnv->RemoveFromStack( this );
       
   299     // Unload the resourcefile
       
   300     iResLoader.Close();
       
   301     delete iController;
       
   302     // Put the application's title back
       
   303     if ( iTitlePane && iOldTitle )
       
   304         {
       
   305         iTitlePane->SetText( iOldTitle ); // takes ownership of iOldTitle
       
   306         }
       
   307     delete iNaviDecorator;
       
   308     delete iSBFrame;
       
   309     delete iItemArrayForScrollBar;
       
   310 
       
   311     delete iSendUi;
       
   312 #ifndef RD_VIRTUAL_PHONEBOOK
       
   313     delete iPbkDataSave;
       
   314     delete iPbkEngine;
       
   315     iPbkResourceFile.Close();
       
   316 #endif //RD_VIRTUAL_PHONEBOOK
       
   317     delete iIdle;
       
   318 
       
   319     delete iServiceHandler;
       
   320     delete iFindItemVoIPExtension;
       
   321 
       
   322     delete iSchemeHandler;
       
   323 
       
   324     delete iBgContext;
       
   325 
       
   326     delete iTitleText;
       
   327 
       
   328     delete iDialData;
       
   329     
       
   330     delete iExtension;
       
   331     }
       
   332 
       
   333 // -----------------------------------------------------------------------------
       
   334 // CFindItemDialog::CFindItemDialog
       
   335 //  Default constructor
       
   336 // -----------------------------------------------------------------------------
       
   337 //
       
   338 CFindItemDialog::CFindItemDialog(
       
   339     const TDesC& aPlainText,
       
   340     const CFindItemEngine::TFindItemSearchCase aSearchCase )
       
   341     : iPlainText( aPlainText ),
       
   342     iSearchCase( aSearchCase ),
       
   343 #ifndef RD_VIRTUAL_PHONEBOOK
       
   344     iPbkResourceFile( *iCoeEnv ),
       
   345 #endif // !RD_VIRTUAL_PHONEBOOK
       
   346     iResLoader( *iCoeEnv )
       
   347     {
       
   348     }
       
   349 
       
   350 // -----------------------------------------------------------------------------
       
   351 // CFindItemDialog::NewL
       
   352 //  Two-phased constructor
       
   353 // -----------------------------------------------------------------------------
       
   354 //
       
   355 EXPORT_C CFindItemDialog* CFindItemDialog::NewL(
       
   356     const TDesC& aPlainText,
       
   357     const CFindItemEngine::TFindItemSearchCase aSearchCase )
       
   358     {
       
   359     CFindItemDialog* self =
       
   360         new(ELeave) CFindItemDialog( aPlainText, aSearchCase );
       
   361     CleanupStack::PushL( self );
       
   362     self->ConstructL();
       
   363     CleanupStack::Pop();
       
   364     AKNTASHOOK_ADDL( self, "CFindItemDialog" );
       
   365     return self;
       
   366     }
       
   367 
       
   368 // -----------------------------------------------------------------------------
       
   369 // CFindItemDialog::ConstructL
       
   370 //  EPOC constructor
       
   371 // -----------------------------------------------------------------------------
       
   372 //
       
   373 void CFindItemDialog::ConstructL()
       
   374     {
       
   375     // Must tell CONE where to find dialog resource
       
   376     TFileName fileName( KResFileName );
       
   377     iResLoader.OpenL( fileName );
       
   378 
       
   379     // Call the base class' two-phased constructor
       
   380     CAknDialog::ConstructL( R_AVKON_FORM_MENUBAR );
       
   381 
       
   382 #ifndef RD_VIRTUAL_PHONEBOOK
       
   383     iPbkEngine = CPbkContactEngine::NewL();
       
   384     iPbkResourceFile.OpenL();
       
   385     iPbkDataSave = CPbkDataSaveAppUi::NewL( *iPbkEngine );
       
   386 #endif // RD_VIRTUAL_PHONEBOOK
       
   387 
       
   388     // Set up the StatusPane
       
   389     CEikStatusPane *sp =
       
   390          ( (CAknAppUi*)iEikonEnv->EikAppUi() )->StatusPane();
       
   391     // Fetch pointer to the default title pane control
       
   392     iTitlePane =
       
   393         (CAknTitlePane *)sp->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) );
       
   394     // save the old Title
       
   395     const TDesC* title = iTitlePane->Text();
       
   396     iOldTitle = title->AllocL();
       
   397 
       
   398     // Fetch pointer to the default navi pane control
       
   399     iNaviPane =
       
   400         ( CAknNavigationControlContainer *)sp->ControlL(
       
   401             TUid::Uid( EEikStatusPaneUidNavi ) );
       
   402 
       
   403     // AIW
       
   404     iServiceHandler = CAiwServiceHandler::NewL();
       
   405 
       
   406     // CallUi
       
   407     iServiceHandler->AttachMenuL(
       
   408         R_FINDITEM_CALLUI_AIW_SUBMENU,
       
   409         R_FINDITEM_CALLUI_AIW_INTEREST );
       
   410 
       
   411     CMyMenuPane* callUiMenu = new (ELeave)CMyMenuPane( this );
       
   412     CleanupStack::PushL( callUiMenu );
       
   413     TResourceReader callUiReader;
       
   414     iEikonEnv->CreateResourceReaderLC(
       
   415         callUiReader, R_FINDITEM_CALLUI_AIW_SUBMENU );
       
   416     callUiMenu->ConstructFromResourceL( callUiReader );
       
   417     CleanupStack::PopAndDestroy(); // callUiReader
       
   418 
       
   419     iServiceHandler->InitializeMenuPaneL(
       
   420         *(CEikMenuPane*)callUiMenu,
       
   421         R_FINDITEM_CALLUI_AIW_SUBMENU,
       
   422         EFindMenuPlaceHolderCallUI,
       
   423         iServiceHandler->InParamListL() );
       
   424 
       
   425     if ( callUiMenu->NumberOfItemsInPane() < 2 )
       
   426         {
       
   427         iHideCallMenu = ETrue;
       
   428         }
       
   429 
       
   430     iServiceHandler->AttachL( R_FINDITEM_CALLUI_AIW_INTEREST );
       
   431     CleanupStack::PopAndDestroy(); // callUiMenu
       
   432 
       
   433 #ifdef RD_VIRTUAL_PHONEBOOK
       
   434     // Contacts
       
   435     iServiceHandler->AttachMenuL(
       
   436         R_FINDITEM_CONTACTS_AIW_SUBMENU,
       
   437         R_FINDITEM_CONTACTS_AIW_INTEREST );
       
   438 #endif // RD_VIRTUAL_PHONEBOOK
       
   439 
       
   440     iDialData = CAiwDialDataExt::NewL();
       
   441 
       
   442     iHelpFeatureSupported =
       
   443         FeatureManager::FeatureSupported( KFeatureIdHelp );
       
   444 
       
   445     iAudioMessagingFeatureSupported =
       
   446         FeatureManager::FeatureSupported( KFeatureIdAudioMessaging );
       
   447 
       
   448     iMMSFeatureSupported =
       
   449         FeatureManager::FeatureSupported( KFeatureIdMMS );
       
   450 
       
   451     iEmailOverSmsFeatureSupported =
       
   452         FeatureManager::FeatureSupported( KFeatureIdEmailOverSms );
       
   453 
       
   454     iEmailUiFeatureSupported =
       
   455         FeatureManager::FeatureSupported( KFeatureIdEmailUi );
       
   456 
       
   457     iFindItemVoIPExtension = CFindItemVoIPExtension::NewL();
       
   458     
       
   459     iExtension = CItemFinderExtension::NewL();
       
   460     }
       
   461 
       
   462 
       
   463 // -----------------------------------------------------------------------------
       
   464 // CFindItemDialog::DoCopyToClipboardL
       
   465 //  Copies the selected item to EPOC clipboard
       
   466 // -----------------------------------------------------------------------------
       
   467 //
       
   468 void CFindItemDialog::CopyToClipboardL()
       
   469     {
       
   470     __ASSERT_DEBUG( iEdwin->SelectionLength() > 0, Panic( ENoItemSelected ) );
       
   471 
       
   472     // CEikEdwin::ClipboardL cannot be used due to the underlining.
       
   473     TCursorSelection selection = iEdwin->Selection();
       
   474     TInt length = selection.Length();
       
   475     HBufC* number = HBufC::NewLC( length );
       
   476     TPtr numberPtr = number->Des();
       
   477     numberPtr.Append( iPlainText.Mid( selection.LowerPos(), length ) );
       
   478     CPlainText* plainText =
       
   479         CPlainText::NewL( CPlainText::ESegmentedStorage, length );
       
   480     CleanupStack::PushL( plainText );
       
   481     plainText->InsertL( 0, *number );
       
   482 
       
   483     CClipboard* cb = CClipboard::NewForWritingLC( iCoeEnv->FsSession() );
       
   484     plainText->CopyToStoreL( cb->Store(),cb->StreamDictionary(), 0, length );
       
   485     cb->CommitL();
       
   486     CleanupStack::PopAndDestroy(3); // number, plainText, cb
       
   487 
       
   488     CAknNoteDialog* dlg = new (ELeave) CAknNoteDialog();
       
   489     dlg->SetTimeout(CAknNoteDialog::EShortTimeout);
       
   490     dlg->SetTone(CAknNoteDialog::ENoTone);
       
   491     dlg->ExecuteLD( R_AVKON_NOTE_CONF_COPIED );
       
   492     }
       
   493 
       
   494 // -----------------------------------------------------------------------------
       
   495 // CFindItemDialog::CreateContactCardL
       
   496 //  Creates a contact card from selected item
       
   497 // -----------------------------------------------------------------------------
       
   498 //
       
   499 void CFindItemDialog::CreateContactCardL( TInt aCommandId )
       
   500     {
       
   501     __ASSERT_DEBUG( iEdwin->SelectionLength() > 0, Panic( ENoItemSelected ) );
       
   502 
       
   503     // Hide options menu if showing
       
   504     if ( CAknDialog::MenuShowing() )
       
   505         {
       
   506         CAknDialog::HideMenu();
       
   507         }
       
   508 
       
   509     CFindItemEngine::SFoundItem selecteditem;
       
   510     TBool founditem = iController->Item( selecteditem );
       
   511 
       
   512 #ifndef RD_VIRTUAL_PHONEBOOK
       
   513     CArrayPtrFlat<CPbkFieldInfo> *fieldArray =
       
   514         new(ELeave)CArrayPtrFlat<CPbkFieldInfo>( 1 );
       
   515     CleanupStack::PushL( fieldArray );
       
   516     for ( TInt i = 0; i < iPbkEngine->FieldsInfo().Count(); i++ )
       
   517         {
       
   518         CPbkFieldInfo* fieldInfo = iPbkEngine->FieldsInfo()[ i ];
       
   519         // Only interested in text storage fields
       
   520         if ( !( fieldInfo->FieldStorageType() == KStorageTypeText ) )
       
   521             {
       
   522             continue;
       
   523             }
       
   524         if ( iFindItemVoIPExtension->IsVoIPSupported() &&
       
   525             iSearchCase == KSearchTelInternetNumber )
       
   526             {
       
   527             if ( fieldInfo->FieldId() == EPbkFieldIdVOIP ||
       
   528                 ( fieldInfo->FieldId() == EPbkFieldIdEmailAddress &&
       
   529                 founditem && selecteditem.iItemType ==
       
   530                     CFindItemEngine::EFindItemSearchMailAddressBin ) ||
       
   531                 ( fieldInfo->IsPhoneNumberField() &&
       
   532                 founditem && selecteditem.iItemType ==
       
   533                     CFindItemEngine::EFindItemSearchPhoneNumberBin ) )
       
   534                 {
       
   535                 fieldArray->AppendL( fieldInfo );
       
   536                 }
       
   537             }
       
   538         else if ( iSearchCase & CFindItemEngine::EFindItemSearchPhoneNumberBin &&
       
   539             ( fieldInfo->IsPhoneNumberField() ||
       
   540                 iFindItemVoIPExtension->IsVoIPSupported() &&
       
   541                 fieldInfo->FieldId() == EPbkFieldIdVOIP ) )
       
   542             {
       
   543             fieldArray->AppendL( fieldInfo );
       
   544             }
       
   545         else if ( iSearchCase & CFindItemEngine::EFindItemSearchMailAddressBin &&
       
   546             ( fieldInfo->FieldId() ==  EPbkFieldIdEmailAddress ||
       
   547                 iFindItemVoIPExtension->IsVoIPSupported() &&
       
   548                 fieldInfo->FieldId() == EPbkFieldIdVOIP ) )
       
   549             {
       
   550             fieldArray->AppendL( fieldInfo );
       
   551             }
       
   552         else if ( iSearchCase & CFindItemEngine::EFindItemSearchURLBin &&
       
   553             fieldInfo->FieldId() == EPbkFieldIdURL )
       
   554             {
       
   555             fieldArray->AppendL( fieldInfo );
       
   556             }
       
   557         }
       
   558 #endif // !RD_VIRTUAL_PHONEBOOK
       
   559 
       
   560     // Get the selected item
       
   561     TCursorSelection selection = iEdwin->Selection();
       
   562     HBufC* item = HBufC::NewLC( selection.Length() );
       
   563     TPtr itemDes = item->Des();
       
   564     itemDes.Append(
       
   565         iPlainText.Mid( selection.LowerPos(), selection.Length() ) );
       
   566 
       
   567     // Handle command
       
   568 #ifndef RD_VIRTUAL_PHONEBOOK
       
   569     iPbkDataSave->HandleCommandL( aCommandId, *fieldArray, *item );
       
   570     CleanupStack::PopAndDestroy( 2 ); // fieldArray, item
       
   571 #else // RD_VIRTUAL_PHONEBOOK
       
   572     using namespace AiwContactAssign;
       
   573 
       
   574     CAiwGenericParamList& inList = iServiceHandler->InParamListL();
       
   575 
       
   576     // Contact Assign Data.
       
   577     TAiwGenericParam param( EGenericParamContactAssignData );
       
   578     TAiwSingleContactAssignDataV1 assignData;
       
   579     assignData.SetFlags( 0 );
       
   580     param.Value().Set( TAiwSingleContactAssignDataV1Pckg( assignData ) );
       
   581     inList.AppendL( param );
       
   582 
       
   583     // Contact Data Type.
       
   584     param.Reset();
       
   585     switch( selecteditem.iItemType ) // Resolve type.
       
   586         {
       
   587         case CFindItemEngine::EFindItemSearchPhoneNumberBin:    // Phone number
       
   588             param.SetSemanticId( EGenericParamPhoneNumber );
       
   589             // convert phone number.
       
   590             CommonPhoneParser::ParsePhoneNumber(
       
   591                 itemDes, CommonPhoneParser::EPhoneClientNumber );
       
   592             break;
       
   593         case CFindItemEngine::EFindItemSearchMailAddressBin:    // E-mail
       
   594             param.SetSemanticId( EGenericParamEmailAddress );
       
   595             break;
       
   596         case CFindItemEngine::EFindItemSearchURLBin:            // URL
       
   597         case CFindItemEngine::EFindItemSearchScheme:            // URI
       
   598             param.SetSemanticId( EGenericParamURL );
       
   599             break;
       
   600         default:
       
   601             CleanupStack::PopAndDestroy( 1 ); // item
       
   602             return; // unknown item type.
       
   603         }
       
   604     param.Value().Set( itemDes );
       
   605     inList.AppendL( param );
       
   606 
       
   607     iServiceHandler->ExecuteMenuCmdL(
       
   608         aCommandId,
       
   609         inList,
       
   610         iServiceHandler->OutParamListL(),
       
   611         0,
       
   612         iExtension->CallBack() );
       
   613     CleanupStack::PopAndDestroy( 1 ); // item
       
   614 #endif // !RD_VIRTUAL_PHONEBOOK
       
   615     }
       
   616 
       
   617 // -----------------------------------------------------------------------------
       
   618 // CFindItemDialog::SendMessageL
       
   619 //  Sends message (SMS, MMS or E-mail) to selected item
       
   620 // -----------------------------------------------------------------------------
       
   621 //
       
   622 void CFindItemDialog::SendMessageL( const TUid aMtmUid )
       
   623     {
       
   624     __ASSERT_DEBUG( iEdwin->SelectionLength() > 0, Panic( ENoItemSelected ) );
       
   625 
       
   626     if ( !iSendUi )
       
   627         {
       
   628         return;
       
   629         }
       
   630 
       
   631     // Hide options menu if showing
       
   632     if ( CAknDialog::MenuShowing() )
       
   633         {
       
   634         CAknDialog::HideMenu();
       
   635         }
       
   636 
       
   637     TCursorSelection selection = iEdwin->Selection();
       
   638     HBufC* number = HBufC::NewLC( selection.Length() );
       
   639     TPtr numberPtr = number->Des();
       
   640     numberPtr.Append(
       
   641         iPlainText.Mid(
       
   642             selection.LowerPos(), selection.Length() ) );
       
   643     if ( iSearchCase & CFindItemEngine::EFindItemSearchPhoneNumberBin )
       
   644         {
       
   645         CommonPhoneParser::ParsePhoneNumber(
       
   646             numberPtr, CommonPhoneParser::EPlainPhoneNumber );
       
   647         AknTextUtils::ConvertDigitsTo( numberPtr, EDigitTypeWestern );            
       
   648         }
       
   649 
       
   650     CMessageData* messageData = CMessageData::NewL();
       
   651     CleanupStack::PushL( messageData );
       
   652     messageData->AppendToAddressL( *number );
       
   653 
       
   654     iSendUi->CreateAndSendMessageL( aMtmUid, messageData );
       
   655     CleanupStack::PopAndDestroy(2); // messageData, number
       
   656 
       
   657     }
       
   658 
       
   659 // -----------------------------------------------------------------------------
       
   660 // CFindItemDialog::LaunchGenericUriL
       
   661 //  Handles URIs launching. If parent application is Browser,
       
   662 //  launches URLs to same Browser window. On other cases passes
       
   663 //  URI to Schemehandler.
       
   664 // -----------------------------------------------------------------------------
       
   665 //
       
   666 TBool CFindItemDialog::LaunchGenericUriL()
       
   667     {
       
   668     HideMenu();
       
   669     __ASSERT_DEBUG( iEdwin->SelectionLength() > 0, Panic( ENoItemSelected ) );
       
   670 
       
   671     TCursorSelection selection = iEdwin->Selection();
       
   672 
       
   673     HBufC* itemtext =
       
   674         HBufC::NewLC( selection.Length() + KHhttpAddress().Length() );
       
   675     TPtr itemtextPtr = itemtext->Des();
       
   676     itemtextPtr.Append(
       
   677         iPlainText.Mid( selection.LowerPos(), selection.Length() ) );
       
   678 
       
   679     TBool isUrl = EFalse;
       
   680 
       
   681     // Link is url, if it starts with "http"
       
   682     const TDesC& pref = itemtextPtr.Left( 4 );
       
   683     if ( pref.CompareF( KHhttpAddress().Left( 4 ) ) == 0 )
       
   684         {
       
   685         isUrl = ETrue;
       
   686         }
       
   687 
       
   688     // old url types need prefix in order to work w/ schemehandler
       
   689     if ( !( isUrl || pref.CompareF( KRtspUrlAddress().Left( 4 ) ) == 0 ) )
       
   690         {
       
   691         itemtextPtr.Insert( 0, KHhttpAddress );
       
   692         isUrl = ETrue;
       
   693         }
       
   694 
       
   695     TInt length = itemtextPtr.Length();
       
   696 
       
   697     // Get the current app's UID
       
   698     TUid appUid = iEikonEnv->EikAppUi()->Application()->AppDllUid();
       
   699 
       
   700     // If current app is Browser and we have URL, we open it to this same
       
   701     // Browser window
       
   702     if ( appUid == KWapUid && isUrl )
       
   703         {
       
   704         GoToUrlL( itemtextPtr );
       
   705         CleanupStack::PopAndDestroy(); // itemtext
       
   706         return ETrue;
       
   707         }
       
   708     // If current app is other than Browser, use schemehandler for launching
       
   709     // file
       
   710     else
       
   711         {
       
   712         if ( iSchemeHandler )
       
   713             {
       
   714             delete iSchemeHandler;
       
   715             iSchemeHandler = 0;
       
   716             }
       
   717         iSchemeHandler = CSchemeHandler::NewL( itemtextPtr );
       
   718         if ( itemtext->FindF( KRtspUrlAddress ) != KErrNotFound )
       
   719             {
       
   720             iSchemeHandler->HandleUrlEmbeddedL();
       
   721             }
       
   722         else
       
   723             {
       
   724             iSchemeHandler->HandleUrlStandaloneL();
       
   725             }
       
   726         }
       
   727 
       
   728     CleanupStack::PopAndDestroy(); // itemtext
       
   729     return EFalse;
       
   730     }
       
   731 
       
   732 
       
   733 // -----------------------------------------------------------------------------
       
   734 // CCFindItemDialog::GoToUrlL
       
   735 //  Goes to URL (selected item) using Browser
       
   736 // -----------------------------------------------------------------------------
       
   737 //
       
   738 void CFindItemDialog::GoToUrlL( const TPtr& aItemtextPtr )
       
   739     {
       
   740     TInt paramLength = aItemtextPtr.Length();
       
   741     paramLength += 2; // 2 = length of the first parameter + space
       
   742 
       
   743     HBufC *parameters = HBufC::NewLC( paramLength );
       
   744     TPtr paramPtr = parameters->Des();
       
   745     paramPtr.Copy( KWmlBrowserParameter );
       
   746     paramPtr.Append( KSpace );
       
   747     paramPtr.Append(
       
   748         aItemtextPtr.Mid(
       
   749             0, Min( aItemtextPtr.Length(), KFavouritesMaxUrl ) ) );
       
   750 
       
   751     TApaTaskList taskList( iEikonEnv->WsSession() );
       
   752     TApaTask task = taskList.FindApp( KWapUid );
       
   753     if ( task.Exists() )
       
   754         {
       
   755         HBufC8* param8 = HBufC8::NewLC( parameters->Length() );
       
   756         param8->Des().Append( *parameters );
       
   757         task.SendMessage( TUid::Uid( 0 ), *param8 ); // Uid is not used
       
   758         CleanupStack::PopAndDestroy(); // param8
       
   759         }
       
   760     else
       
   761         {
       
   762         // should not happen
       
   763         }
       
   764 
       
   765     CleanupStack::PopAndDestroy(); // parameters
       
   766 
       
   767     // Close Find Item dialog as it was launched from Browser
       
   768     TryExitL( EAknSoftkeyBack );
       
   769     }
       
   770 
       
   771 
       
   772 // -----------------------------------------------------------------------------
       
   773 // CFindItemDialog::AddToBookmarkL
       
   774 //  Adds the selected item to bookmarks
       
   775 // -----------------------------------------------------------------------------
       
   776 //
       
   777 void CFindItemDialog::AddToBookmarkL()
       
   778     {
       
   779     __ASSERT_DEBUG( iEdwin->SelectionLength() > 0, Panic( ENoItemSelected ) );
       
   780 
       
   781     // Create an item and fill with meaningful data.
       
   782     CFavouritesItem* item = CFavouritesItem::NewLC();
       
   783     item->SetParentFolder( KFavouritesRootUid );
       
   784     item->SetType( CFavouritesItem::EItem );
       
   785     // Read default name from resources
       
   786     HBufC* defaultName =
       
   787         iEikonEnv->AllocReadResourceLC( R_FINDITEM_DEFAULT_BOOKMARK_NAME );
       
   788 
       
   789     TBuf<KMaxBookmarkNameLength> retName;
       
   790     retName.Copy ( defaultName->Des() );
       
   791     CleanupStack::PopAndDestroy( ); //defaultName
       
   792 
       
   793     // Query bookmark name from user
       
   794     CAknTextQueryDialog* dlg = CAknTextQueryDialog::NewL( retName );
       
   795     dlg->SetMaxLength( KMaxBookmarkNameLength );
       
   796     if ( !dlg->ExecuteLD( R_FINDITEM_BOOKMARK_QUERY_DIALOG ) )
       
   797         {
       
   798         // User press cancel - do not add bookmark
       
   799         CleanupStack::PopAndDestroy( ); // item
       
   800         return;
       
   801         }
       
   802 
       
   803     item->SetNameL( retName );
       
   804     TCursorSelection selection = iEdwin->Selection();
       
   805     item->SetUrlL( iPlainText.Mid( selection.LowerPos(), selection.Length() ) );
       
   806 
       
   807     RFavouritesSession sess;
       
   808     RFavouritesDb db;
       
   809 
       
   810     User::LeaveIfError( sess.Connect() );
       
   811     CleanupClosePushL<RFavouritesSession>( sess );
       
   812     User::LeaveIfError( db.Open( sess, KBrowserBookmarks ) );
       
   813     CleanupClosePushL<RFavouritesDb>( db );
       
   814 
       
   815     // Add item.
       
   816     db.Add( *item, ETrue );
       
   817     // Close the database.
       
   818     db.Close();
       
   819 
       
   820     HBufC* msgBuffer =
       
   821         iCoeEnv->AllocReadResourceLC( R_FINDITEM_BOOKMARK_SAVED );
       
   822     CAknConfirmationNote* note = new (ELeave)CAknConfirmationNote( ETrue );
       
   823     note->ExecuteLD( *msgBuffer );
       
   824 
       
   825     CleanupStack::PopAndDestroy( 4 );   // magBuffer, db, sess, item
       
   826     }
       
   827 
       
   828 // -----------------------------------------------------------------------------
       
   829 // CFindItemDialog::ProcessCommandL
       
   830 //  Prosesses menu commands
       
   831 // -----------------------------------------------------------------------------
       
   832 //
       
   833 EXPORT_C void CFindItemDialog::ProcessCommandL( TInt aCommandId )
       
   834     {
       
   835     CAknDialog::ProcessCommandL( aCommandId );
       
   836     switch (aCommandId)
       
   837         {
       
   838         // General cmds
       
   839         case EFindItemCmdNextItem:
       
   840             {
       
   841             iController->NextItemL();
       
   842             break;
       
   843             }
       
   844         case EFindItemCmdPrevItem:
       
   845             {
       
   846             iController->PrevItemL();
       
   847             break;
       
   848             }
       
   849         case EFindItemCmdExit:
       
   850             {
       
   851             HideMenu();
       
   852             STATIC_CAST( MEikCommandObserver*,
       
   853                 iEikonEnv->EikAppUi())->ProcessCommandL( EAknCmdExit );
       
   854             return;
       
   855             }
       
   856         case EFindItemCmdCreateContactCardSub1:
       
   857         case EFindItemCmdCreateContactCardSub2:
       
   858         case EFindItemCmdCreateContactCardSub3:
       
   859             {
       
   860             CreateContactCardL( aCommandId );
       
   861             // Restore original client application icon back to context pane.
       
   862             CEikStatusPane* statusPane =
       
   863                 ( (CAknAppUi*)CEikonEnv::Static()->EikAppUi() )->StatusPane();
       
   864             CCoeControl* contextControl =
       
   865                 statusPane->ControlL( TUid::Uid( EEikStatusPaneUidContext ) );
       
   866             CAknContextPane* contextPane =
       
   867                 static_cast<CAknContextPane*>( contextControl );
       
   868             contextPane->SetPictureToDefaultL();
       
   869             break;
       
   870             }
       
   871         // Phone number cmds
       
   872         case EFindItemCmdCall:
       
   873             { // bit awkward but correct functionality provided.
       
   874             TKeyEvent keyEvent;
       
   875             keyEvent.iCode = EKeyPhoneSend;
       
   876             OfferKeyEventL( keyEvent, EEventKey );
       
   877             break;
       
   878             }
       
   879         // fix for FAMZ-7JVQ4Y
       
   880         case EFindItemSubMenuSend:
       
   881            {
       
   882            CFindItemEngine::SFoundItem item;
       
   883            TBool founditem = iController->Item( item );
       
   884            TSendingCapabilities sendingCapabilities;
       
   885            sendingCapabilities.iFlags = TSendingCapabilities::ESupportsEditor;
       
   886            CArrayFixFlat<TUid>* mtmFilter = new(ELeave) CArrayFixFlat<TUid>( 1 );
       
   887            CleanupStack::PushL(mtmFilter);
       
   888            mtmFilter->AppendL(KSenduiMtmPostcardUid);// hide postcard
       
   889            // Hide MMs
       
   890            #ifndef RD_UNIFIED_EDITOR
       
   891            if( !iMMSFeatureSupported )
       
   892                {
       
   893            	   mtmFilter->AppendL(KSenduiMtmMmsUid);
       
   894                }
       
   895            #endif
       
   896            
       
   897            // Hide Sms
       
   898            if ( iSearchCase == CFindItemEngine::EFindItemSearchMailAddressBin ||
       
   899               ( iFindItemVoIPExtension->IsVoIPSupported() &&
       
   900                   founditem && item.iItemType == CFindItemEngine::EFindItemSearchMailAddressBin &&
       
   901                   iSearchCase == KSearchTelInternetNumber ) )
       
   902               {
       
   903               #ifndef RD_UNIFIED_EDITOR
       
   904               if ( !iEmailOverSmsFeatureSupported )
       
   905                   {
       
   906                   mtmFilter->AppendL(KSenduiMtmSmsUid);
       
   907                   }
       
   908               #endif
       
   909               }
       
   910               
       
   911            // Hide Mail
       
   912            else if ( !iEmailUiFeatureSupported ||
       
   913                ( iSearchCase == CFindItemEngine::EFindItemSearchPhoneNumberBin ||
       
   914                ( iFindItemVoIPExtension->IsVoIPSupported() && founditem &&
       
   915                    item.iItemType == CFindItemEngine::EFindItemSearchPhoneNumberBin &&
       
   916                    iSearchCase == KSearchTelInternetNumber ) ) )
       
   917                {
       
   918        	       mtmFilter->AppendL(KSenduiMtmSmtpUid);
       
   919                mtmFilter->AppendL(KSenduiMtmImap4Uid);
       
   920                mtmFilter->AppendL(KSenduiMtmPop3Uid);
       
   921                mtmFilter->AppendL(KSenduiMtmSyncMLEmailUid);
       
   922                }
       
   923            // Hide Audio
       
   924            if ( iSearchCase != CFindItemEngine::EFindItemSearchPhoneNumberBin ||
       
   925                !iAudioMessagingFeatureSupported )
       
   926                {
       
   927                mtmFilter->AppendL(KSenduiMtmAudioMessageUid);
       
   928                }
       
   929                
       
   930            TUid uid = iSendUi->ShowTypedQueryL( CSendUi::EWriteMenu, NULL, sendingCapabilities, mtmFilter );
       
   931           
       
   932            CleanupStack::PopAndDestroy();
       
   933            
       
   934            if ( uid == KNullUid )
       
   935               {
       
   936               break;
       
   937               }
       
   938            SendMessageL(uid);  
       
   939            
       
   940            break;
       
   941            }
       
   942         case EFindItemCmdGoToUrl:
       
   943             {
       
   944             if ( LaunchGenericUriL() )
       
   945                 {
       
   946                 return;
       
   947                 }
       
   948             break;
       
   949             }
       
   950         case EFindItemCmdAddToBookmark:
       
   951             {
       
   952             AddToBookmarkL();
       
   953             break;
       
   954             }
       
   955         case EAknCmdHelp:
       
   956             {
       
   957             if( iHelpFeatureSupported )
       
   958                 {
       
   959                 CArrayFixFlat<TCoeHelpContext>* helps = new ( ELeave ) CArrayFixFlat<TCoeHelpContext>( 1 );
       
   960                 CleanupStack::PushL( helps );
       
   961                 TCoeHelpContext helpContext;
       
   962                 GetHelpContext( helpContext );
       
   963                 helps->AppendL( helpContext );
       
   964                 HlpLauncher::LaunchHelpApplicationL(
       
   965                     iEikonEnv->WsSession(),
       
   966                     helps );
       
   967                 CleanupStack::Pop(helps);
       
   968                 }
       
   969             break;
       
   970             }
       
   971         case EFindItemCmdCopy:
       
   972             {
       
   973             CopyToClipboardL();
       
   974             break;
       
   975             }
       
   976         // The command was not known, so lets offer it to AIWFW
       
   977         default:
       
   978             {
       
   979             if ( !iDialData )
       
   980                 {
       
   981                 break;
       
   982                 }
       
   983 
       
   984             TInt aiwCmd = iServiceHandler->ServiceCmdByMenuCmd( aCommandId );
       
   985 
       
   986             // Calls via AIW
       
   987             if ( aiwCmd == KAiwCmdCall &&(
       
   988                 iSearchCase & CFindItemEngine::EFindItemSearchPhoneNumberBin ||
       
   989                 iFindItemVoIPExtension->VoIPProfilesExistL() &&
       
   990                 ( iSearchCase & CFindItemEngine::EFindItemSearchMailAddressBin ||
       
   991                 iSearchCase == KSearchTelInternetNumber ) ) )
       
   992                 {
       
   993                 FormatDialDataL( aCommandId );
       
   994 
       
   995                 CAiwGenericParamList& paramList =
       
   996                     iServiceHandler->InParamListL();
       
   997 
       
   998                 iDialData->FillInParamListL( paramList );
       
   999 
       
  1000                 iServiceHandler->ExecuteMenuCmdL(
       
  1001                     aCommandId,
       
  1002                     paramList,
       
  1003                     iServiceHandler->OutParamListL(),
       
  1004                     0, // No options used.
       
  1005                     0 ); // no dial results are wanted.
       
  1006                 }
       
  1007 #ifdef RD_VIRTUAL_PHONEBOOK
       
  1008             // Contacts via AIW
       
  1009             else if ( aiwCmd == KAiwCmdAssign )
       
  1010                 {
       
  1011                 CreateContactCardL( aCommandId );
       
  1012                 }
       
  1013 #endif // RD_VIRTUAL_PHONEBOOK
       
  1014             break;
       
  1015             }
       
  1016         }
       
  1017     }
       
  1018 
       
  1019 // -----------------------------------------------------------------------------
       
  1020 // CFindItemDialog::DynInitMenuPaneL
       
  1021 //  Initializes items on the menu
       
  1022 // -----------------------------------------------------------------------------
       
  1023 //
       
  1024 EXPORT_C void CFindItemDialog::DynInitMenuPaneL(
       
  1025     TInt aMenuId,
       
  1026     CEikMenuPane* aMenuPane )
       
  1027     {
       
  1028     if ( iServiceHandler->HandleSubmenuL( *aMenuPane ) )
       
  1029         {
       
  1030         return;
       
  1031         }
       
  1032 
       
  1033     CFindItemEngine::SFoundItem item;
       
  1034     TBool founditem = iController->Item( item );
       
  1035 
       
  1036     if ( aMenuId == R_FINDITEM_CALLUI_AIW_SUBMENU )
       
  1037         {
       
  1038         if ( iFindItemVoIPExtension->IsVoIPSupported() &&
       
  1039             ( iSearchCase ==
       
  1040                 CFindItemEngine::EFindItemSearchMailAddressBin ||
       
  1041             ( iSearchCase == KSearchTelInternetNumber &&
       
  1042             founditem && item.iItemType ==
       
  1043                 CFindItemEngine::EFindItemSearchMailAddressBin ) ) )
       
  1044             {
       
  1045             CAiwGenericParamList* inList = CAiwGenericParamList::NewLC();
       
  1046 
       
  1047             // SIP Address
       
  1048             TAiwGenericParam param( EGenericParamSIPAddress );
       
  1049             inList->AppendL( param );
       
  1050 
       
  1051             iServiceHandler->InitializeMenuPaneL(
       
  1052                 *aMenuPane,
       
  1053                 aMenuId,
       
  1054                 EFindMenuPlaceHolderCallUI,
       
  1055                 *inList );
       
  1056 
       
  1057             CleanupStack::PopAndDestroy(); // genericParamList
       
  1058             }
       
  1059         else
       
  1060             {
       
  1061             iServiceHandler->InitializeMenuPaneL(
       
  1062                 *aMenuPane,
       
  1063                 aMenuId,
       
  1064                 EFindMenuPlaceHolderCallUI,
       
  1065                 iServiceHandler->InParamListL() );
       
  1066             }
       
  1067         return;
       
  1068         }
       
  1069 
       
  1070 #ifdef RD_VIRTUAL_PHONEBOOK
       
  1071     if ( aMenuId == R_FINDITEM_CONTACTS_AIW_SUBMENU )
       
  1072         {
       
  1073         using namespace AiwContactAssign;
       
  1074 
       
  1075         CAiwGenericParamList& inList = iServiceHandler->InParamListL();
       
  1076 
       
  1077         // Contact Assign Data
       
  1078         TAiwGenericParam param( EGenericParamContactAssignData );
       
  1079         TAiwSingleContactAssignDataV1 assignData;
       
  1080         assignData.SetFlags( 0 ); // Reset
       
  1081         param.Value().Set( TAiwSingleContactAssignDataV1Pckg( assignData ) );
       
  1082         inList.AppendL( param );
       
  1083 
       
  1084         // Type Phone Number
       
  1085         param.Reset();
       
  1086         param.SetSemanticId( EGenericParamPhoneNumber );
       
  1087         inList.AppendL( param );
       
  1088 
       
  1089         iServiceHandler->InitializeMenuPaneL(
       
  1090             *aMenuPane,
       
  1091             aMenuId,
       
  1092             EFindMenuCmdLast,
       
  1093             inList );
       
  1094 
       
  1095         return;
       
  1096         }
       
  1097 #endif  // RD_VIRTUAL_PHONEBOOK
       
  1098 
       
  1099     if (aMenuId == R_AVKON_FORM_MENUPANE)
       
  1100         {
       
  1101         TInt resource = 0;
       
  1102 
       
  1103         if ( iSearchCase == KSearchTelInternetNumber )
       
  1104             {
       
  1105             resource = R_FINDITEM_TELINTERNETNUMBER_MENU;
       
  1106             }
       
  1107         else if ( iSearchCase & CFindItemEngine::EFindItemSearchURLBin )
       
  1108             {
       
  1109             resource = R_FINDITEM_URL_ADDRESS_MENU;
       
  1110             }
       
  1111         else if ( iSearchCase & CFindItemEngine::EFindItemSearchMailAddressBin )
       
  1112             {
       
  1113             resource = R_FINDITEM_MAIL_ADDRESS_MENU;
       
  1114             }
       
  1115         else if ( iSearchCase & CFindItemEngine::EFindItemSearchPhoneNumberBin )
       
  1116             {
       
  1117             resource = R_FINDITEM_PHONENUMBER_MENU;
       
  1118             }
       
  1119         else
       
  1120            {
       
  1121            ;
       
  1122            }
       
  1123 
       
  1124         aMenuPane->AddMenuItemsL( resource, EAknFormMaxDefault - 1, ETrue );
       
  1125 
       
  1126         if ( iSearchCase == KSearchTelInternetNumber &&
       
  1127             iFindItemVoIPExtension->VoIPProfilesExistL() ||
       
  1128             iSearchCase == KSearchTelInternetNumber &&
       
  1129             !iFindItemVoIPExtension->VoIPProfilesExistL() &&
       
  1130             founditem &&
       
  1131             item.iItemType ==
       
  1132                 CFindItemEngine::EFindItemSearchPhoneNumberBin ||
       
  1133             iSearchCase & CFindItemEngine::EFindItemSearchMailAddressBin &&
       
  1134             iFindItemVoIPExtension->VoIPProfilesExistL() )
       
  1135             {
       
  1136             aMenuPane->SetItemDimmed( EFindItemCmdCall, ETrue );
       
  1137             aMenuPane->AddMenuItemsL(
       
  1138                 R_FINDITEM_CALLUI_AIW_ITEM,
       
  1139                 EFindItemCmdCall);
       
  1140             }
       
  1141         else if ( iSearchCase == KSearchTelInternetNumber &&
       
  1142             !iFindItemVoIPExtension->VoIPProfilesExistL() ||
       
  1143             iSearchCase & CFindItemEngine::EFindItemSearchMailAddressBin &&
       
  1144             !iFindItemVoIPExtension->VoIPProfilesExistL() )
       
  1145             {
       
  1146             aMenuPane->DeleteMenuItem(EFindItemCmdCall);
       
  1147             }
       
  1148         else if (
       
  1149             iSearchCase & CFindItemEngine::EFindItemSearchPhoneNumberBin &&
       
  1150             !iHideCallMenu )
       
  1151             {
       
  1152             aMenuPane->SetItemDimmed( EFindItemCmdCall, ETrue );
       
  1153             aMenuPane->AddMenuItemsL(
       
  1154                 R_FINDITEM_CALLUI_AIW_ITEM,
       
  1155                 EFindItemCmdCall );
       
  1156             }
       
  1157 
       
  1158         aMenuPane->DeleteMenuItem( EAknFormCmdEdit );
       
  1159         aMenuPane->DeleteMenuItem( EAknFormCmdAdd );
       
  1160         aMenuPane->DeleteMenuItem( EAknFormCmdSave );
       
  1161         aMenuPane->DeleteMenuItem( EAknFormCmdLabel );
       
  1162         aMenuPane->DeleteMenuItem( EAknFormCmdDelete );
       
  1163 
       
  1164 #ifndef RD_VIRTUAL_PHONEBOOK
       
  1165         iPbkDataSave->AddMenuItemsL(
       
  1166             aMenuPane,
       
  1167             EFindItemCmdCreateContactCard );
       
  1168 #else
       
  1169         aMenuPane->SetItemDimmed( EFindItemCmdCreateContactCard, ETrue );
       
  1170         aMenuPane->AddMenuItemsL(
       
  1171             R_FINDITEM_CONTACTS_AIW_ITEM,
       
  1172             EFindItemCmdCreateContactCard );
       
  1173 #endif // !RD_VIRTUAL_PHONEBOOK
       
  1174 
       
  1175         // Delete next/prev item items from menu if a last/next
       
  1176         // item is currently selected (or if sensitive menu)
       
  1177         if ( iController->FirstItem() || iIsSensitiveMenu )
       
  1178             {
       
  1179             aMenuPane->DeleteMenuItem( EFindItemCmdPrevItem );
       
  1180             }
       
  1181         if ( iController->LastItem() || iIsSensitiveMenu )
       
  1182             {
       
  1183             aMenuPane->DeleteMenuItem( EFindItemCmdNextItem );
       
  1184             }
       
  1185 
       
  1186         if ( iIsSensitiveMenu )
       
  1187             {
       
  1188             aMenuPane->DeleteMenuItem( EFindItemCmdExit );
       
  1189             if( iHelpFeatureSupported )
       
  1190                 {
       
  1191                 aMenuPane->DeleteMenuItem( EAknCmdHelp );
       
  1192                 }
       
  1193             iIsSensitiveMenu = EFalse;
       
  1194             }
       
  1195 
       
  1196         // No send message submenu for e-mail.
       
  1197         if ( iSearchCase == CFindItemEngine::EFindItemSearchMailAddressBin &&
       
  1198             !iEmailOverSmsFeatureSupported && !iEmailUiFeatureSupported &&
       
  1199             !iMMSFeatureSupported )
       
  1200             {
       
  1201             aMenuPane->SetItemDimmed( EFindItemSubMenuSend, ETrue );
       
  1202             }
       
  1203         }
       
  1204     else
       
  1205         {
       
  1206         // we are in Create contact submenu
       
  1207         // this does nothing if we're not, so this is safe
       
  1208 #ifndef RD_VIRTUAL_PHONEBOOK
       
  1209         iPbkDataSave->DynInitMenuPaneL( aMenuId, aMenuPane );
       
  1210 #endif // !RD_VIRTUAL_PHONEBOOK
       
  1211         }
       
  1212     }
       
  1213 
       
  1214 // -----------------------------------------------------------------------------
       
  1215 // CFindItemDialog::OfferKeyEventL
       
  1216 //  Handles key events
       
  1217 // -----------------------------------------------------------------------------
       
  1218 //
       
  1219 EXPORT_C TKeyResponse CFindItemDialog::OfferKeyEventL(
       
  1220     const TKeyEvent& aKeyEvent,
       
  1221     TEventCode aType )
       
  1222     {
       
  1223     // Only interested in standard key events
       
  1224     if ( aType != EEventKey )
       
  1225         {
       
  1226         return EKeyWasNotConsumed;
       
  1227         }
       
  1228 
       
  1229     // If a menu is showing offer key events to it.
       
  1230     if ( CAknDialog::MenuShowing() )
       
  1231         {
       
  1232         return CAknDialog::OfferKeyEventL( aKeyEvent, aType );
       
  1233         }
       
  1234 
       
  1235     TInt code = aKeyEvent.iCode;
       
  1236     TBool founditem = EFalse;
       
  1237 
       
  1238     switch ( code )
       
  1239         {
       
  1240         case EKeyRightArrow:
       
  1241             iController->NextItemL();
       
  1242             break;
       
  1243         case EKeyDownArrow:
       
  1244             iController->MoveDownL();
       
  1245             break;
       
  1246         case EKeyLeftArrow:
       
  1247             iController->PrevItemL();
       
  1248             break;
       
  1249         case EKeyUpArrow:
       
  1250             iController->MoveUpL();
       
  1251             break;
       
  1252         case EKeyOK:
       
  1253         case EKeyEnter:
       
  1254             iIsSensitiveMenu = ETrue;
       
  1255             iMenuBar->SetMenuType(CEikMenuBar::EMenuContext);
       
  1256             CAknDialog::DisplayMenuL();
       
  1257             break;
       
  1258         case EKeyPhoneSend:
       
  1259             if ( !iDialData )
       
  1260                 {
       
  1261                 break;
       
  1262                 }
       
  1263 
       
  1264             CFindItemEngine::SFoundItem item;
       
  1265             founditem = iController->Item( item );
       
  1266 
       
  1267             if ( iSearchCase ==
       
  1268                     CFindItemEngine::EFindItemSearchPhoneNumberBin ||
       
  1269                 iFindItemVoIPExtension->VoIPProfilesExistL() &&
       
  1270                 ( iSearchCase ==
       
  1271                     CFindItemEngine::EFindItemSearchMailAddressBin ||
       
  1272                 iSearchCase == KSearchTelInternetNumber ) ||
       
  1273                 iSearchCase == KSearchTelInternetNumber && founditem &&
       
  1274                 item.iItemType ==
       
  1275                     CFindItemEngine::EFindItemSearchPhoneNumberBin )
       
  1276                 {
       
  1277                 FormatDialDataL( code );
       
  1278 
       
  1279                 // Create Call W/O Menu
       
  1280                 CAiwGenericParamList& paramList =
       
  1281                     iServiceHandler->InParamListL();
       
  1282                 
       
  1283                 if ( iFindItemVoIPExtension->VoIPProfilesExistL() &&
       
  1284                     ( iSearchCase ==
       
  1285                     CFindItemEngine::EFindItemSearchMailAddressBin ||
       
  1286                     iSearchCase == KSearchTelInternetNumber ) )
       
  1287                     {
       
  1288                     //voip
       
  1289                     iDialData->SetCallType( CAiwDialData::EAIWVoiP );    
       
  1290                     }
       
  1291 
       
  1292                 iDialData->FillInParamListL( paramList );
       
  1293 
       
  1294                 iServiceHandler->ExecuteServiceCmdL(
       
  1295                     KAiwCmdCall,
       
  1296                     paramList,
       
  1297                     iServiceHandler->OutParamListL(),
       
  1298                     0, // No options used.
       
  1299                     NULL ); // Dial results are not wanted.
       
  1300                 }
       
  1301             break;
       
  1302         default:
       
  1303             return CAknDialog::OfferKeyEventL( aKeyEvent, aType );
       
  1304         }
       
  1305     return EKeyWasConsumed;
       
  1306     }
       
  1307 
       
  1308 
       
  1309 // -----------------------------------------------------------------------------
       
  1310 // CFindItemDialog::OkToExitL
       
  1311 // called by framework when the OK button is pressed
       
  1312 // -----------------------------------------------------------------------------
       
  1313 //
       
  1314 TBool CFindItemDialog::OkToExitL( TInt aButtonId )
       
  1315 {
       
  1316     if ( aButtonId == EAknSoftkeyOptions )
       
  1317         {
       
  1318         // Show the options menu
       
  1319         iIsSensitiveMenu = EFalse;
       
  1320         iMenuBar->SetMenuType(CEikMenuBar::EMenuOptions);
       
  1321         return CAknDialog::OkToExitL( aButtonId );
       
  1322         }
       
  1323     if ( aButtonId == EAknSoftkeyContextOptions )
       
  1324         {
       
  1325         // Show context sensitive menu. In this case it would
       
  1326         // be normal menu with some items removed
       
  1327         iIsSensitiveMenu = ETrue;
       
  1328         iMenuBar->SetMenuType(CEikMenuBar::EMenuContext);
       
  1329         return CAknDialog::OkToExitL( EAknSoftkeyOptions );
       
  1330         }
       
  1331     if ( aButtonId == EAknSoftkeyBack || aButtonId == EAknSoftkeyExit )
       
  1332         {
       
  1333         // Close Find Item
       
  1334         return ETrue;
       
  1335         }
       
  1336     return EFalse;
       
  1337 }
       
  1338 
       
  1339 // -----------------------------------------------------------------------------
       
  1340 // CFindItemDialog::PreLayoutDynInitL
       
  1341 // called by framework before dialog is shown
       
  1342 // -----------------------------------------------------------------------------
       
  1343 //
       
  1344 void CFindItemDialog::PreLayoutDynInitL()
       
  1345     {
       
  1346     // Fetch a pointer to richtext editor
       
  1347     iEdwinContainer = STATIC_CAST(
       
  1348         CRichTextEditorContainer*, Control( EFindItemRichTxtEditorContainer ) );
       
  1349     iEdwin = iEdwinContainer->iEditor;
       
  1350 
       
  1351     // Create a controller, and thus create an engine and
       
  1352     // execute the search algorithm
       
  1353     iController =
       
  1354         CFindItemController::NewL(
       
  1355             this, iEdwin->RichText(), iPlainText, iSearchCase );
       
  1356 
       
  1357     iItemArrayForScrollBar = new (ELeave) CArrayFixFlat<TInt>( 2 );
       
  1358     iController->FillScrollBarItemsArrayL( iItemArrayForScrollBar );
       
  1359     CreateScrollBarFrameL();
       
  1360     }
       
  1361 
       
  1362 // -----------------------------------------------------------------------------
       
  1363 // CFindItemDialog::PostLayoutDynInitL
       
  1364 //  called by framework before dialog is shown (don't affect layout)
       
  1365 // -----------------------------------------------------------------------------
       
  1366 //
       
  1367 void CFindItemDialog::PostLayoutDynInitL()
       
  1368     {
       
  1369     if ( !( iEdwin->TextView() ) )
       
  1370         {
       
  1371         // There was no memory to create a text view.
       
  1372         // CRichTextEditor doesn't leave if that happens? so let's leave here.
       
  1373         User::Leave( KErrNoMemory );
       
  1374         }
       
  1375 
       
  1376     CFindItemEngine::SFoundItem item;
       
  1377     TBool anyFound = iController->Item( item );
       
  1378 
       
  1379     // Skin Support
       
  1380     iBgContext =
       
  1381         CAknsBasicBackgroundControlContext::NewL(
       
  1382             KAknsIIDQsnBgAreaMain, Rect(), EFalse );
       
  1383 
       
  1384     // Editor
       
  1385     iEdwin->SetTextL( &iPlainText );
       
  1386     
       
  1387     // change the color of the text according to the skin color
       
  1388     TRgb color;
       
  1389     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
  1390     TInt error = AknsUtils::GetCachedColor(skin, color, KAknsIIDQsnTextColors, 
       
  1391     												EAknsCIQsnTextColorsCG6 );
       
  1392     if(error==KErrNone)
       
  1393     	{
       
  1394       	TCharFormat charFormat;
       
  1395     	TCharFormatMask charFormatMask;
       
  1396     	charFormatMask.SetAttrib(EAttColor);
       
  1397     	charFormat.iFontPresentation.iTextColor = color; 
       
  1398     
       
  1399     	CRichText * richText = NULL;
       
  1400     	richText = iEdwin->RichText();
       
  1401     	if( NULL!=richText )
       
  1402     		{
       
  1403     		TInt length = richText->DocumentLength();
       
  1404     		length++;
       
  1405     		// apply the color to text
       
  1406     		TRAP_IGNORE(richText->ApplyCharFormatL( charFormat, charFormatMask, 0, length ));
       
  1407     		}
       
  1408        	}
       
  1409     if ( anyFound )
       
  1410         {
       
  1411         // Insert paragraphs inside the text if needed, i.e. if text is
       
  1412         // bandformatted and there's not enough paragraphs already. The
       
  1413         // paragraphs needs to be inserted so that the length of the document
       
  1414         // won't change, i.e. replace ". " with "." + paragraph
       
  1415         TInt docLength = iEdwin->RichText()->DocumentLength();
       
  1416         if ( docLength >= KFullFormattingUpperThreshold &&
       
  1417              iEdwin->RichText()->ParagraphCount() <=
       
  1418                 ( docLength / KLengthOfRecommendedParagraph ) )
       
  1419             {
       
  1420             TInt i = 1;
       
  1421             while ( ( KLengthOfRecommendedParagraph * i ) <
       
  1422                     iPlainText.Length() )
       
  1423                 {
       
  1424                 TInt endOfSentence =
       
  1425                     iPlainText.Right(
       
  1426                         iPlainText.Length() -
       
  1427                             KLengthOfRecommendedParagraph * i ).FindF(
       
  1428                                 KPeriodAndSpace );
       
  1429                 if ( endOfSentence != KErrNotFound )
       
  1430                     {
       
  1431                     iEdwin->RichText()->DeleteL(
       
  1432                         endOfSentence + 1 +
       
  1433                             ( KLengthOfRecommendedParagraph * i ), 1 );
       
  1434                     iEdwin->RichText()->InsertL(
       
  1435                         endOfSentence + 1 +
       
  1436                             ( KLengthOfRecommendedParagraph * i ),
       
  1437                         CEditableText::EParagraphDelimiter );
       
  1438                     }
       
  1439                 i++;
       
  1440                 }
       
  1441             }
       
  1442 
       
  1443         iController->MarkFoundItemsL();
       
  1444         iEdwin->NotifyNewFormatL();
       
  1445 
       
  1446         // 'Cheating' - AllowBlankSpace flag doesn't work when scrolling pages,
       
  1447         // so insert paragraph delimiters
       
  1448         for ( TInt i = 0; i < iRows; i++ )
       
  1449             {
       
  1450             TRAP_IGNORE( iEdwin->RichText()->InsertL(
       
  1451                 iEdwin->RichText()->DocumentLength(),
       
  1452                 CEditableText::EParagraphDelimiter ) );
       
  1453             }
       
  1454 
       
  1455         }
       
  1456 
       
  1457     iEikonEnv->EikAppUi()->AddToStackL( this, ECoeStackPriorityDialog );
       
  1458 
       
  1459     // Observe pointer events
       
  1460     CEikCaptionedControl* capCC = Line( EFindItemRichTxtEditorContainer );
       
  1461     capCC->SetPointerEventObserver( this );
       
  1462 
       
  1463     iTappingOffset = iEdwin->Rect().iTl - Rect().iTl;
       
  1464     }
       
  1465 
       
  1466 // -----------------------------------------------------------------------------
       
  1467 // CFindItemDialog::SelectionChangedL
       
  1468 //  Selects the given item.
       
  1469 //  Gets called by controller via CFindItemDialogCallBack.
       
  1470 // -----------------------------------------------------------------------------
       
  1471 //
       
  1472 void CFindItemDialog::SelectionChangedL(
       
  1473     const CFindItemEngine::SFoundItem& aItem )
       
  1474     {
       
  1475     iEdwin->SetSelectionL( aItem.iStartPos, aItem.iLength + aItem.iStartPos );
       
  1476     UpdateScrollIndicatorL();
       
  1477     }
       
  1478 
       
  1479 // -----------------------------------------------------------------------------
       
  1480 // CFindItemDialog::SelectionChangedL
       
  1481 //  Selects the given item and scrolls the edit window.
       
  1482 //  Gets called by controller via CFindItemDialogCallBack.
       
  1483 // -----------------------------------------------------------------------------
       
  1484 //
       
  1485 void CFindItemDialog::SelectionChangedL(
       
  1486     const CFindItemEngine::SFoundItem& aItem,
       
  1487     const TBool aNext )
       
  1488     {
       
  1489     const TInt startPos = aItem.iStartPos;
       
  1490     const TInt endPos = aItem.iStartPos + aItem.iLength;
       
  1491     TPoint dummy;
       
  1492     __ASSERT_DEBUG(
       
  1493         endPos <= iEdwin->TextLength(), Panic( EItemOutOfDocumentRange ) );
       
  1494 
       
  1495     // Scroll the display if needed
       
  1496     if ( aNext )
       
  1497         {
       
  1498         while ( !( iEdwin->TextLayout()->PosInBand( startPos, dummy ) ) )
       
  1499             {
       
  1500             // Unselect text if display needs to be scrolled
       
  1501             iEdwin->ClearSelectionL();
       
  1502             // Scroll page down
       
  1503             iEdwin->MoveDisplayL( TCursorPosition::EFPageDown );
       
  1504             }
       
  1505         }
       
  1506     else
       
  1507         {
       
  1508         while ( !( iEdwin->TextLayout()->PosInBand( startPos, dummy ) ) )
       
  1509             {
       
  1510             // Unselect text if display needs to be scrolled
       
  1511             iEdwin->ClearSelectionL();
       
  1512             // Scroll page down
       
  1513             iEdwin->MoveDisplayL( TCursorPosition::EFPageUp );
       
  1514             }
       
  1515         }
       
  1516 
       
  1517     // First see if the string fits to the band and then make the selection
       
  1518     if( iEdwin->TextLayout()->PosInBand( startPos, dummy ) &&
       
  1519        !iEdwin->TextLayout()->PosInBand( endPos, dummy ) )
       
  1520         iEdwin->SetSelectionL( startPos, endPos ); // startPos first so that we
       
  1521                                                    // can see the start of the
       
  1522                                                    // string
       
  1523     else
       
  1524         iEdwin->SetSelectionL( endPos, startPos ); // endPos first because
       
  1525                                                    // otherwise selection will
       
  1526                                                    // change the first
       
  1527                                                    // visible line.
       
  1528 
       
  1529     // Set up the navipane
       
  1530     // To avoid flickering a new label has to be
       
  1531     // pushed before deleting the old one
       
  1532     //CAknNavigationDecorator* oldDecorator = iNaviDecorator;
       
  1533     //CleanupStack::PushL( oldDecorator );
       
  1534     //iNaviDecorator = NULL;
       
  1535     UpdateNaviPaneL();
       
  1536     //CleanupStack::PopAndDestroy(); // oldDecorator
       
  1537     //oldDecorator = NULL;
       
  1538     UpdateScrollIndicatorL();
       
  1539     }
       
  1540 
       
  1541 // -----------------------------------------------------------------------------
       
  1542 // CFindItemDialog::AtSameLine
       
  1543 //  Returns whether items are at the same line
       
  1544 // -----------------------------------------------------------------------------
       
  1545 //
       
  1546 TBool CFindItemDialog::AtSameLine( const TInt& aItem1, const TInt& aItem2 )
       
  1547     {
       
  1548     TInt error = KErrNone;    
       
  1549     // DocPosToXyPosL can't leave, because of the flag EFWholeTBoxesOnly see SDK!    
       
  1550     TBool pos1 = EFalse;
       
  1551     TPoint point1;
       
  1552     TRAP( error, pos1 = iEdwin->TextLayout()->DocPosToXyPosL( 
       
  1553         aItem1, point1, CLayoutData::EFWholeTBoxesOnly ) );
       
  1554     if ( error != KErrNone )
       
  1555         {
       
  1556         return EFalse;
       
  1557         }
       
  1558     TBool pos2 = EFalse;        
       
  1559     TPoint point2;
       
  1560     TRAP( error, pos2 = iEdwin->TextLayout()->DocPosToXyPosL( 
       
  1561         aItem2, point2, CLayoutData::EFWholeTBoxesOnly ) );
       
  1562     if ( error != KErrNone )
       
  1563         {
       
  1564         return EFalse;
       
  1565         }    
       
  1566     if ( !pos1 || !pos2 || point1.iY != point2.iY )
       
  1567         {
       
  1568         return EFalse;
       
  1569         }
       
  1570     return ETrue;
       
  1571     }
       
  1572 
       
  1573 // -----------------------------------------------------------------------------
       
  1574 // CFindItemDialog::ExecuteLD
       
  1575 //  Calls CAknDialog's  ExecuteLD() with correct resourceId
       
  1576 // -----------------------------------------------------------------------------
       
  1577 //
       
  1578 
       
  1579 EXPORT_C TInt CFindItemDialog::ExecuteLD()
       
  1580     {
       
  1581     return CAknDialog::ExecuteLD( R_FINDITEM_DIALOG );
       
  1582     }
       
  1583 
       
  1584 
       
  1585 // -----------------------------------------------------------------------------
       
  1586 // CFindItemDialog::CreateScrollBarFrameL
       
  1587 //  Creates the scrollbarframe
       
  1588 // -----------------------------------------------------------------------------
       
  1589 //
       
  1590 void CFindItemDialog::CreateScrollBarFrameL()
       
  1591     {
       
  1592     iSBFrame = new(ELeave) CEikScrollBarFrame( this, NULL, ETrue );
       
  1593 
       
  1594     // Check which type of scrollbar is to be shown
       
  1595     if ( AknLayoutUtils::DefaultScrollBarType( iAvkonAppUi ) ==
       
  1596             CEikScrollBarFrame::EDoubleSpan )
       
  1597         {
       
  1598         // For EDoubleSpan type scrollbar
       
  1599 
       
  1600          // window owning scrollbar
       
  1601         iSBFrame->CreateDoubleSpanScrollBarsL( ETrue, EFalse, ETrue, EFalse );
       
  1602 
       
  1603         iSBFrame->SetTypeOfVScrollBar( CEikScrollBarFrame::EDoubleSpan );
       
  1604         }
       
  1605     else
       
  1606         {
       
  1607         // For EArrowHead type scrollbar
       
  1608         iSBFrame->SetTypeOfVScrollBar( CEikScrollBarFrame::EArrowHead );
       
  1609         }
       
  1610 
       
  1611     iSBFrame->SetScrollBarVisibilityL(
       
  1612         CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
  1613 
       
  1614     iSBFrame->SetScrollBarFrameObserver( this );
       
  1615 
       
  1616     iThumbPos = 0;
       
  1617     }
       
  1618 
       
  1619 // -----------------------------------------------------------------------------
       
  1620 // CFindItemDialog::ActivateL
       
  1621 //  Initializes and activates the dialog.
       
  1622 // -----------------------------------------------------------------------------
       
  1623 //
       
  1624 void CFindItemDialog::ActivateL()
       
  1625     {
       
  1626     CFindItemEngine::SFoundItem item;
       
  1627     TBool anyFound = iController->Item( item );
       
  1628 
       
  1629     if ( anyFound )
       
  1630         {
       
  1631         // These has to be done after the CAknDialog::ExecuteLD is called
       
  1632         CAknDialog::ActivateL();
       
  1633 
       
  1634         // set up a new title
       
  1635         TInt resource = 0;
       
  1636 
       
  1637         if ( iSearchCase == KSearchTelInternetNumber )
       
  1638             {
       
  1639             resource = R_FINDITEM_TITLE_TELINTERNET;
       
  1640             iSendUi = CSendUi::NewL();
       
  1641             }
       
  1642         else if ( iSearchCase & CFindItemEngine::EFindItemSearchURLBin )
       
  1643             {
       
  1644             resource = R_FINDITEM_TITLE_URL;
       
  1645             }
       
  1646         else if ( iSearchCase & CFindItemEngine::EFindItemSearchMailAddressBin )
       
  1647             {
       
  1648             resource = R_FINDITEM_TITLE_MAIL;
       
  1649             iSendUi = CSendUi::NewL();
       
  1650             }
       
  1651         else if ( iSearchCase & CFindItemEngine::EFindItemSearchPhoneNumberBin )
       
  1652             {
       
  1653             resource = R_FINDITEM_TITLE_PHONE;
       
  1654             iSendUi = CSendUi::NewL();
       
  1655             }
       
  1656         else
       
  1657           {
       
  1658           __ASSERT_ALWAYS( 0, Panic( ENoSearchCase ) );
       
  1659           return;
       
  1660           }
       
  1661 
       
  1662         iTitleText = iEikonEnv->AllocReadResourceL( resource );
       
  1663 
       
  1664         // Set the correct titlepane text
       
  1665         if ( iTitleText )
       
  1666             {
       
  1667             iTitlePane->SetTextL( iTitleText->Des() );
       
  1668             }
       
  1669 
       
  1670         // Set up NaviPane ( if items were found )
       
  1671         if ( iController->ItemCount() >= 1 )
       
  1672             {
       
  1673             if ( iNaviDecorator )
       
  1674                 {
       
  1675                 delete iNaviDecorator;
       
  1676                 iNaviDecorator = NULL;
       
  1677                 }
       
  1678             UpdateNaviPaneL();
       
  1679             }
       
  1680 
       
  1681         UpdateScrollIndicatorL();
       
  1682 
       
  1683         iEdwin->TextView()->SetSelectionVisibilityL( ETrue );
       
  1684         iEdwin->SetSelectionL( item.iStartPos, item.iLength + item.iStartPos );
       
  1685         }
       
  1686     else
       
  1687         {// Let's show a information note if no items were found
       
  1688         HBufC* infoNote =
       
  1689             iEikonEnv->AllocReadResourceLC(
       
  1690                 R_FINDITEM_NO_ITEMS_FOUND_NOTE_MSG );
       
  1691         CAknInformationNote* note = new (ELeave) CAknInformationNote( ETrue );
       
  1692         note->ExecuteLD( *infoNote );
       
  1693         CleanupStack::PopAndDestroy(); // infoNote
       
  1694 
       
  1695         MakeVisible( EFalse );
       
  1696         CEikButtonGroupContainer* cba = CEikButtonGroupContainer::Current();
       
  1697         if( cba )
       
  1698             {
       
  1699             // To avoid user press "option" while dialog is closing
       
  1700             // TSW error: EBYU-7QWC37
       
  1701             cba->SetCommandSetL( R_AVKON_SOFTKEYS_EMPTY );  
       
  1702             }
       
  1703         
       
  1704         delete iIdle;
       
  1705         iIdle = 0;
       
  1706         iIdle = CIdle::NewL( CActive::EPriorityIdle );
       
  1707         iIdle->Start( TCallBack( DeleteMe, this ) );
       
  1708         }
       
  1709 
       
  1710     }
       
  1711 
       
  1712 void CFindItemDialog::DeleteMeL()
       
  1713     {
       
  1714     TryExitL( EAknSoftkeyBack );
       
  1715     }
       
  1716 
       
  1717 TInt CFindItemDialog::DeleteMe( TAny* aThis )
       
  1718     {
       
  1719     TRAPD( err, ( (CFindItemDialog*)aThis )->DeleteMeL() );
       
  1720     return err;
       
  1721     }
       
  1722 
       
  1723 // -----------------------------------------------------------------------------
       
  1724 // CFindItemDialog::UpdateScrollIndicatorL
       
  1725 //  Updates the scrollindicator
       
  1726 // -----------------------------------------------------------------------------
       
  1727 //
       
  1728 void CFindItemDialog::UpdateScrollIndicatorL()
       
  1729     {
       
  1730     if ( !iSBFrame )
       
  1731         {
       
  1732         return;
       
  1733         }
       
  1734 
       
  1735     TEikScrollBarModel hSbarModel;
       
  1736     TEikScrollBarModel vSbarModel;
       
  1737 
       
  1738     // Count scrollbar position
       
  1739     TInt position = iController->Position();
       
  1740 
       
  1741     TInt i = 0;
       
  1742     while ( i < iItemArrayForScrollBar->Count() &&
       
  1743         position >= iItemArrayForScrollBar->At( i ) )
       
  1744         {
       
  1745         i++;
       
  1746         }
       
  1747 
       
  1748     // If text is longer than KFullFormattingUpperThreshold (=2000) chars
       
  1749     // it's impossible to count lines instead of items. That's why
       
  1750     // for the first and last item, thumbposition needs to be added "manually".
       
  1751     if ( iPlainText.Length() >= KFullFormattingUpperThreshold )
       
  1752         {
       
  1753         if ( iController->IsAtSameLineAsFirstItem() )
       
  1754             {
       
  1755             i = 0;
       
  1756             }
       
  1757         else if ( iController->IsAtSameLineAsLastItem() )
       
  1758             {
       
  1759             i = iItemArrayForScrollBar->Count() + 1;
       
  1760             }
       
  1761         }
       
  1762 
       
  1763     vSbarModel.iThumbPosition = i;
       
  1764     vSbarModel.iScrollSpan= iItemArrayForScrollBar->Count() + 1;
       
  1765     vSbarModel.iThumbSpan = 1;
       
  1766 
       
  1767     TEikScrollBarFrameLayout layout;
       
  1768     if ( iSBFrame->TypeOfVScrollBar() == CEikScrollBarFrame::EDoubleSpan )
       
  1769         {
       
  1770         // For EDoubleSpan type scrollbar
       
  1771         if ( vSbarModel.iThumbPosition + vSbarModel.iThumbSpan >
       
  1772                 vSbarModel.iScrollSpan )
       
  1773             {
       
  1774             // Not let scrollbar values overflow
       
  1775             vSbarModel.iThumbPosition =
       
  1776                 vSbarModel.iScrollSpan - vSbarModel.iThumbSpan;
       
  1777             }
       
  1778         TAknDoubleSpanScrollBarModel hDsSbarModel( hSbarModel );
       
  1779         TAknDoubleSpanScrollBarModel vDsSbarModel( vSbarModel );
       
  1780         TRect rect( Position(), Rect().Size() );        
       
  1781         ButtonGroupContainer().ReduceRect( rect );        
       
  1782         rect.Move( -Position() );
       
  1783         layout.iTilingMode = TEikScrollBarFrameLayout::EInclusiveRectConstant;
       
  1784         iSBFrame->TileL( &hDsSbarModel, &vDsSbarModel, rect, rect, layout );
       
  1785         iSBFrame->SetVFocusPosToThumbPos( vDsSbarModel.FocusPosition() );
       
  1786         }
       
  1787     else
       
  1788         {
       
  1789         // For EArrowHead type scrollbar
       
  1790         TRect rect( Rect() );
       
  1791         iSBFrame->TileL( &hSbarModel, &vSbarModel, rect, rect, layout );
       
  1792         iSBFrame->SetVFocusPosToThumbPos( vSbarModel.iThumbPosition );
       
  1793         }
       
  1794 
       
  1795     iThumbPos = iSBFrame->VerticalScrollBar()->ThumbPosition();
       
  1796     }
       
  1797 
       
  1798 // -----------------------------------------------------------------------------
       
  1799 // CFindItemDialog::UpdateNaviPaneL
       
  1800 //  Updates the Navipane
       
  1801 // -----------------------------------------------------------------------------
       
  1802 //
       
  1803 void CFindItemDialog::UpdateNaviPaneL()
       
  1804     {
       
  1805     TBuf<16> naviText;
       
  1806     naviText.Format(
       
  1807         KPosIndicator, iController->Position() + 1, iController->ItemCount() );
       
  1808 
       
  1809     if(NULL == iNaviDecorator)
       
  1810     	{
       
  1811     	iNaviDecorator = iNaviPane->CreateNavigationLabelL( naviText );
       
  1812        	iNaviDecorator->SetNaviDecoratorObserver( this );  
       
  1813        	iNaviDecorator->MakeScrollButtonVisible( ETrue );
       
  1814        	}
       
  1815     else
       
  1816     	{
       
  1817     	// Change the label on Nave pane control...
       
  1818     	CAknNaviLabel * label =( CAknNaviLabel* )iNaviDecorator->DecoratedControl();
       
  1819     	label->SetTextL(naviText);
       
  1820     	}
       
  1821 
       
  1822     // Dimm arrows if needed
       
  1823     if ( iController->LastItem() )
       
  1824         {
       
  1825         iNaviDecorator->SetScrollButtonDimmed(
       
  1826             CAknNavigationDecorator::ERightButton, ETrue);
       
  1827         }
       
  1828     else
       
  1829         {
       
  1830         iNaviDecorator->SetScrollButtonDimmed(
       
  1831             CAknNavigationDecorator::ERightButton, EFalse );
       
  1832         }
       
  1833     if ( iController->FirstItem() )
       
  1834         {
       
  1835         iNaviDecorator->SetScrollButtonDimmed(
       
  1836             CAknNavigationDecorator::ELeftButton, ETrue );
       
  1837         }
       
  1838     else
       
  1839         {
       
  1840         iNaviDecorator->SetScrollButtonDimmed(
       
  1841             CAknNavigationDecorator::ELeftButton, EFalse );
       
  1842         }
       
  1843     iNaviPane->PushL( *iNaviDecorator );
       
  1844     }
       
  1845 
       
  1846 // -----------------------------------------------------------------------------
       
  1847 // CFindItemDialog::GetHelpContext
       
  1848 // This function is called when Help application is launched.
       
  1849 // (other items were commented in a header).
       
  1850 // -----------------------------------------------------------------------------
       
  1851 //
       
  1852 void CFindItemDialog::GetHelpContext(
       
  1853     TCoeHelpContext& aContext ) const
       
  1854     {
       
  1855     if( iHelpFeatureSupported )
       
  1856         {
       
  1857         aContext.iMajor = KCommonUIUid;
       
  1858         aContext.iContext = KFIND_HLP;
       
  1859         }
       
  1860     }
       
  1861 
       
  1862 void CFindItemDialog::FormatDialDataL( TInt aCommandId )
       
  1863     {
       
  1864     if ( !iDialData )
       
  1865         {
       
  1866         return;
       
  1867         }
       
  1868 
       
  1869     __ASSERT_DEBUG( iEdwin->SelectionLength() > 0, Panic( ENoItemSelected ) );
       
  1870 
       
  1871     (void)aCommandId;
       
  1872     
       
  1873     TCursorSelection selection = iEdwin->Selection();
       
  1874     HBufC* number = HBufC::NewLC( selection.Length() );
       
  1875     TPtr numberPtr = number->Des();
       
  1876     numberPtr.Append(
       
  1877         iPlainText.Mid( selection.LowerPos(), selection.Length() ) );
       
  1878 
       
  1879     using namespace AIWDialDataExt;
       
  1880     __ASSERT_ALWAYS(
       
  1881         number->Length() <= KMaximumPhoneNumberLength, Panic( ETooLongItem ) );
       
  1882     AknTextUtils::ConvertDigitsTo( numberPtr, EDigitTypeWestern );
       
  1883     iDialData->SetPhoneNumberL( numberPtr );
       
  1884 
       
  1885     CleanupStack::PopAndDestroy(); // number;
       
  1886     }
       
  1887 
       
  1888 // -----------------------------------------------------------------------------
       
  1889 // CFindItemDialog::CreateInternetCallL
       
  1890 // This function is called when Internet call command is pressed.
       
  1891 // (other items were commented in a header).
       
  1892 // -----------------------------------------------------------------------------
       
  1893 //
       
  1894 void CFindItemDialog::CreateInternetCallL()
       
  1895     {
       
  1896     if ( iFindItemVoIPExtension->VoIPProfilesExistL() &&
       
  1897        ( iSearchCase & CFindItemEngine::EFindItemSearchPhoneNumberBin ||
       
  1898        iSearchCase & CFindItemEngine::EFindItemSearchMailAddressBin ||
       
  1899        iSearchCase == KSearchTelInternetNumber ) )
       
  1900         {
       
  1901         if ( !iDialData )
       
  1902             {
       
  1903             return;
       
  1904             }
       
  1905 
       
  1906         FormatDialDataL( EKeyPhoneSend ); //That number is formated correctly
       
  1907 
       
  1908         // Create Call W/O Menu
       
  1909         CAiwGenericParamList& paramList = iServiceHandler->InParamListL();
       
  1910 
       
  1911         iDialData->FillInParamListL( paramList );
       
  1912 
       
  1913         iServiceHandler->ExecuteServiceCmdL(
       
  1914             KAiwCmdCall,
       
  1915             paramList,
       
  1916             iServiceHandler->OutParamListL(),
       
  1917             0, // No options used.
       
  1918             NULL ); // Dial results are not wanted.
       
  1919         }
       
  1920     }
       
  1921 
       
  1922 // -----------------------------------------------------------------------------
       
  1923 // CFindItemDialog::IsSendKeyCallVoIP
       
  1924 // -----------------------------------------------------------------------------
       
  1925 //
       
  1926 TBool CFindItemDialog::IsSendKeyCallVoIP() const
       
  1927     {
       
  1928     return iFindItemVoIPExtension->IsPreferredTelephonyVoIP();
       
  1929     }
       
  1930 
       
  1931 // -----------------------------------------------------------------------------
       
  1932 // CFindItemDialog::HandleResourceChange
       
  1933 //
       
  1934 // -----------------------------------------------------------------------------
       
  1935 void CFindItemDialog::HandleResourceChange( TInt aType )
       
  1936     {
       
  1937 	//Update Horizantal Scroll bar color if skin changes
       
  1938     if( aType == KAknsMessageSkinChange)
       
  1939     	{
       
  1940     	CAknScrollBar *scrollBar = iSBFrame->VerticalScrollBar();
       
  1941     	scrollBar->HandleResourceChange(aType);
       
  1942     	}
       
  1943     CAknDialog::HandleResourceChange( aType );
       
  1944     }
       
  1945 
       
  1946 // -----------------------------------------------------------------------------
       
  1947 // CFindItemDialog::SizeChanged
       
  1948 // -----------------------------------------------------------------------------
       
  1949 //
       
  1950 void CFindItemDialog::SizeChanged()
       
  1951     {
       
  1952     CAknDialog::SizeChanged();
       
  1953 
       
  1954     if ( AknLayoutUtils::ScalableLayoutInterfaceAvailable() )
       
  1955         {
       
  1956         using namespace AknLayoutScalable_Apps;
       
  1957         iRows = list_single_mce_message_pane_ParamLimits().LastRow();
       
  1958         }
       
  1959     else
       
  1960         {
       
  1961         iRows = KCommonUiEdwinLines;
       
  1962         }
       
  1963 
       
  1964     if ( iBgContext )
       
  1965         {
       
  1966         iBgContext->SetRect( Rect() );
       
  1967         }
       
  1968 
       
  1969     iTappingOffset = iEdwin->Rect().iTl - Rect().iTl;
       
  1970 
       
  1971     TRAP_IGNORE( UpdateScrollIndicatorL() );
       
  1972     }
       
  1973 
       
  1974 // ----------------------------------------------------------------------------
       
  1975 // CFindItemDialog::CreateCustomControlL
       
  1976 // from MEikDialogPageObserver
       
  1977 // ----------------------------------------------------------------------------
       
  1978 //
       
  1979 SEikControlInfo CFindItemDialog::CreateCustomControlL( TInt aControlType )
       
  1980     {
       
  1981     SEikControlInfo info = { 0, 0, 0 };
       
  1982     if ( aControlType == EFindItemCtRichTxtEditorContainer )
       
  1983         {
       
  1984         iEdwinContainer = new(ELeave)CRichTextEditorContainer;
       
  1985         info.iControl = iEdwinContainer;
       
  1986         }
       
  1987     return info;
       
  1988     }
       
  1989 
       
  1990 // ----------------------------------------------------------------------------
       
  1991 // CFindItemDialog::SupplyMopObject
       
  1992 // ----------------------------------------------------------------------------
       
  1993 //
       
  1994 TTypeUid::Ptr CFindItemDialog::MopSupplyObject( TTypeUid aId )
       
  1995     {
       
  1996     if ( aId.iUid == MAknsControlContext::ETypeId )
       
  1997         {
       
  1998         return MAknsControlContext::SupplyMopObject( aId, iBgContext );
       
  1999         }
       
  2000     return CAknDialog::MopSupplyObject( aId );
       
  2001     }
       
  2002 
       
  2003 // ----------------------------------------------------------------------------
       
  2004 // CFindItemDialog::FocusChanged
       
  2005 // ----------------------------------------------------------------------------
       
  2006 //
       
  2007 void CFindItemDialog::FocusChanged( TDrawNow /*aDrawNow*/ )
       
  2008     {
       
  2009     if ( IsFocused() && iTitleText )
       
  2010         {
       
  2011         TRAP_IGNORE( iTitlePane->SetTextL( iTitleText->Des() ) );
       
  2012         }
       
  2013     }
       
  2014 
       
  2015 // -----------------------------------------------------------------------------
       
  2016 // CFindItemDialog::PointerEvent
       
  2017 // -----------------------------------------------------------------------------
       
  2018 //
       
  2019  bool CFindItemDialog::PointerEvent(
       
  2020     CEikCaptionedControl* /*aControl*/,
       
  2021     const TPointerEvent& aPointerEvent )
       
  2022     {
       
  2023     if ( AknLayoutUtils::PenEnabled() &&
       
  2024         aPointerEvent.iType == TPointerEvent::EButton1Down )
       
  2025         {
       
  2026         TPoint tapPoint( aPointerEvent.iPosition - iTappingOffset );        
       
  2027         TInt pos = 0;
       
  2028         TInt len = iEdwin->TextLayout()->PosRangeInBand( pos );
       
  2029         CFindItemEngine::SFoundItem item;
       
  2030         TRect rect;
       
  2031         TInt i = 0;
       
  2032         while ( i < iController->ItemCount() ) // Check visible rects
       
  2033             {
       
  2034             if ( !iController->Item( i, item ) ) // Get item.
       
  2035                 {
       
  2036                 break; // Error: invalid item.
       
  2037                 };
       
  2038             TInt end = item.iStartPos + item.iLength - 1;                            
       
  2039             if ( end < pos )
       
  2040                 {
       
  2041                 i++;
       
  2042                 continue; // item not visible.                
       
  2043                 };                                            
       
  2044             TInt start = item.iStartPos;
       
  2045             if ( start >= ( pos + len ) )
       
  2046                 {
       
  2047                 break; // item not visible.
       
  2048                 }
       
  2049             TInt lastLine = iEdwin->TextLayout()->GetLineNumber( end );
       
  2050             TInt nextLine = 0;
       
  2051             TInt lastPos = start;
       
  2052             do // Check all rects of one item.
       
  2053                 {     
       
  2054                 TInt error = KErrNone;                   
       
  2055                 TRAP( error, rect = iEdwin->TextLayout()->GetLineRectL( start, end ) );
       
  2056                 if ( error == KErrNone )
       
  2057                     {
       
  2058                     if ( rect.Contains( tapPoint ) ) // Item rect tapped.
       
  2059                         {                                    
       
  2060                         TRAP( error, iController->TappedItemL( i ) ); // Change selection
       
  2061                         if ( error != KErrNone )
       
  2062                             {
       
  2063                             return false; // Error: no selection made.
       
  2064                             }
       
  2065                         iIsSensitiveMenu = ETrue;
       
  2066                         iMenuBar->SetMenuType( CEikMenuBar::EMenuContext );
       
  2067                         TRAP_IGNORE( CAknDialog::DisplayMenuL() );
       
  2068                         return false; // Hit, no further handling.
       
  2069                         }
       
  2070                     }                 
       
  2071                 else
       
  2072                     {
       
  2073                     return false; // Error: no rect.
       
  2074                     }                                                    
       
  2075                 TPoint midPoint( rect.iBr.iX, ( rect.iBr.iY + rect.iTl.iY) / 2 );
       
  2076                 TRAP( error, lastPos = iEdwin->TextLayout()->XyPosToDocPosL( midPoint ) );            
       
  2077                 if ( error != KErrNone )
       
  2078                     {
       
  2079                     return false; // Error: no last pos.
       
  2080                     }
       
  2081                 start = lastPos + 1;
       
  2082                 nextLine = iEdwin->TextLayout()->GetLineNumber( lastPos );                       
       
  2083                 } while ( nextLine != lastLine ); 
       
  2084             i++;
       
  2085             }
       
  2086         }
       
  2087     return false;   // No hit, no further handling.
       
  2088     }
       
  2089 
       
  2090 // -----------------------------------------------------------------------------
       
  2091 // CFindItemDialog::HandleScrollEventL
       
  2092 // -----------------------------------------------------------------------------
       
  2093 //
       
  2094 void CFindItemDialog::HandleScrollEventL(
       
  2095     CEikScrollBar* aScrollBar,
       
  2096     TEikScrollEvent aEventType )
       
  2097     {
       
  2098     TInt oldPos = iThumbPos;
       
  2099     iThumbPos = aScrollBar->ThumbPosition();
       
  2100     if ( iThumbPos == oldPos )
       
  2101         {
       
  2102         return; // not moved.
       
  2103         }
       
  2104 
       
  2105     switch( aEventType )
       
  2106         {
       
  2107         case EEikScrollUp:
       
  2108         case EEikScrollPageUp:
       
  2109             iController->PrevItemL();
       
  2110             break;
       
  2111         case EEikScrollDown:
       
  2112         case EEikScrollPageDown:
       
  2113             iController->NextItemL();
       
  2114             break;
       
  2115         case EEikScrollThumbDragVert:
       
  2116             if ( iThumbPos < oldPos )
       
  2117                 {
       
  2118                 iController->PrevItemL();
       
  2119                 }
       
  2120             else
       
  2121                 {
       
  2122                 iController->NextItemL();
       
  2123                 }
       
  2124             break;
       
  2125         default:
       
  2126             break;
       
  2127         }
       
  2128     }
       
  2129 
       
  2130 // ----------------------------------------------------------------------------
       
  2131 // CFindItemDialog::HandleNaviDecoratorEventL
       
  2132 // ----------------------------------------------------------------------------
       
  2133 //
       
  2134 void CFindItemDialog::HandleNaviDecoratorEventL( TInt aEventID )
       
  2135     {
       
  2136     switch( aEventID )
       
  2137         {
       
  2138         case MAknNaviDecoratorObserver::EAknNaviDecoratorEventLeftTabArrow:
       
  2139             iController->PrevItemL();    
       
  2140             break;
       
  2141         case MAknNaviDecoratorObserver::EAknNaviDecoratorEventRightTabArrow:
       
  2142             iController->NextItemL();
       
  2143             break;
       
  2144         default:
       
  2145             break;
       
  2146         }    
       
  2147     }   
       
  2148 
       
  2149 //
       
  2150 // CONTAINER CLASS
       
  2151 //
       
  2152 
       
  2153 // -----------------------------------------------------------------------------
       
  2154 // CRichTextEditorContainer:CRichTextEditorContainer
       
  2155 // -----------------------------------------------------------------------------
       
  2156 //
       
  2157 CRichTextEditorContainer::CRichTextEditorContainer()
       
  2158     {
       
  2159     }
       
  2160 
       
  2161 // -----------------------------------------------------------------------------
       
  2162 // CRichTextEditorContainer:ConstructFromResourceL
       
  2163 // -----------------------------------------------------------------------------
       
  2164 //
       
  2165 void CRichTextEditorContainer::ConstructFromResourceL(
       
  2166     TResourceReader& aReader )
       
  2167     {
       
  2168     iEditor = new (ELeave)CEikRichTextEditor;
       
  2169     iEditor->SetContainerWindowL( *this );
       
  2170 
       
  2171     iEditor->ConstructFromResourceL( aReader );
       
  2172 
       
  2173     iBgContext =
       
  2174         CAknsBasicBackgroundControlContext::NewL(
       
  2175             KAknsIIDQsnBgAreaMain, Rect(), EFalse );
       
  2176     if ( iBgContext )
       
  2177         {
       
  2178         iEditor->SetSkinBackgroundControlContextL( iBgContext );
       
  2179         }
       
  2180     }
       
  2181 
       
  2182 // -----------------------------------------------------------------------------
       
  2183 // CRichTextEditorContainer::MinimumSize
       
  2184 // -----------------------------------------------------------------------------
       
  2185 //
       
  2186 TSize CRichTextEditorContainer::MinimumSize()
       
  2187     {
       
  2188     return iAvkonAppUi->ClientRect().Size();
       
  2189     }
       
  2190 
       
  2191 //------------------------------------------------------------------------------
       
  2192 // CRichTextEditorContainer::~CRichTextEditorContainer
       
  2193 // -----------------------------------------------------------------------------
       
  2194 //
       
  2195 CRichTextEditorContainer::~CRichTextEditorContainer()
       
  2196     {
       
  2197     delete iEditor;
       
  2198     delete iBgContext;
       
  2199     }
       
  2200 
       
  2201 // -----------------------------------------------------------------------------
       
  2202 // CRichTextEditorContainer::SizeChanged
       
  2203 // -----------------------------------------------------------------------------
       
  2204 //
       
  2205 void CRichTextEditorContainer::SizeChanged()
       
  2206     {
       
  2207     if ( iEditor )
       
  2208         {
       
  2209         if ( AknLayoutUtils::ScalableLayoutInterfaceAvailable() )
       
  2210             {
       
  2211             using namespace AknLayoutScalable_Apps;
       
  2212             iRows = list_single_mce_message_pane_ParamLimits().LastRow();
       
  2213             }
       
  2214         else
       
  2215             {
       
  2216             iRows = KCommonUiEdwinLines;
       
  2217             }
       
  2218         AknLayoutUtils::LayoutEdwin(
       
  2219             iEditor,
       
  2220             Rect(),
       
  2221             AppLayout::Multiline_Message_writing_texts_Line_3( iRows ) );
       
  2222 
       
  2223         if ( iBgContext )
       
  2224             {
       
  2225             iBgContext->SetRect( Rect() );
       
  2226             TRAP_IGNORE( iEditor->SetSkinBackgroundControlContextL( iBgContext ) );
       
  2227             }
       
  2228         // change the color of the text according to the skin color
       
  2229         // this is needed if finditemdialog is active and theme is changed.
       
  2230         TRgb color;
       
  2231         MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
  2232         TInt error = AknsUtils::GetCachedColor(skin, color, KAknsIIDQsnTextColors, 
       
  2233         												EAknsCIQsnTextColorsCG6 );
       
  2234         if(error==KErrNone)
       
  2235         	{
       
  2236            	TCharFormat charFormat;
       
  2237         	TCharFormatMask charFormatMask;
       
  2238         	charFormatMask.SetAttrib(EAttColor);
       
  2239         	charFormat.iFontPresentation.iTextColor = color; 
       
  2240      
       
  2241         	CRichText * richText = NULL;
       
  2242         	richText = iEditor->RichText();
       
  2243         	if( NULL!=richText )
       
  2244         		{
       
  2245         		TInt length = richText->DocumentLength();
       
  2246         		length++;
       
  2247         		// apply the color to the text
       
  2248         		TRAP_IGNORE(richText->ApplyCharFormatL( charFormat, charFormatMask, 0, length ));
       
  2249         		}
       
  2250            	}
       
  2251         }
       
  2252     }
       
  2253 
       
  2254 // -----------------------------------------------------------------------------
       
  2255 // CRichTextEditorContainer::HandleResourceChange
       
  2256 //
       
  2257 // -----------------------------------------------------------------------------
       
  2258 void CRichTextEditorContainer::HandleResourceChange( TInt aType )
       
  2259     {
       
  2260     CCoeControl::HandleResourceChange( aType );
       
  2261     if ( aType == KAknsMessageSkinChange ||
       
  2262         aType == KEikDynamicLayoutVariantSwitch )
       
  2263         {
       
  2264         SizeChanged();
       
  2265         }
       
  2266     }
       
  2267 
       
  2268 // -----------------------------------------------------------------------------
       
  2269 // CRichTextEditorContainer::CountComponentControls
       
  2270 // -----------------------------------------------------------------------------
       
  2271 //
       
  2272 TInt CRichTextEditorContainer::CountComponentControls() const
       
  2273     {
       
  2274     return iEditor ? 1 : 0;
       
  2275     }
       
  2276 
       
  2277 // -----------------------------------------------------------------------------
       
  2278 // CRichTextEditorContainer::ComponentControl
       
  2279 // -----------------------------------------------------------------------------
       
  2280 //
       
  2281 CCoeControl* CRichTextEditorContainer::ComponentControl(
       
  2282     TInt /*aIndex*/ ) const
       
  2283     {
       
  2284     return iEditor;
       
  2285     }
       
  2286 
       
  2287 // -----------------------------------------------------------------------------
       
  2288 // CRichTextEditorContainer::Draw
       
  2289 // -----------------------------------------------------------------------------
       
  2290 //
       
  2291 void CRichTextEditorContainer::Draw( const TRect& /*aRect*/ ) const
       
  2292     {
       
  2293     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
  2294     MAknsControlContext* cc = AknsDrawUtils::ControlContext( this );
       
  2295     CWindowGc& gc = SystemGc();
       
  2296     if ( !AknsDrawUtils::Background( skin, cc, this, gc, Rect() ) )
       
  2297         {
       
  2298         gc.SetPenStyle( CGraphicsContext::ENullPen );
       
  2299         gc.SetBrushColor( AKN_LAF_COLOR( 0 ) );
       
  2300         gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
       
  2301         gc.DrawRect( Rect() );
       
  2302         }
       
  2303     }
       
  2304 
       
  2305 // End of File