imstutils/imconversationview/imcvuiapp/src/cimcvappviewcontainer.cpp
branchRCL_3
changeset 22 3104fc151679
parent 21 2b7283837edb
child 23 9a48e301e94b
equal deleted inserted replaced
21:2b7283837edb 22:3104fc151679
     1 /*
       
     2 * Copyright (c) 2009 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 * 
       
    15 * Description:
       
    16 * Export help related files.
       
    17 *
       
    18 */
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include	"cimcvappviewcontainer.h"
       
    22 
       
    23 #include    "cimcvengine.h"
       
    24 #include 	"mimcvenginemessagesreadinterface.h"
       
    25 #include 	"mimcvenginemessageswriteinterface.h"
       
    26 #include    "cimcvappviewcontrol.h"
       
    27 #include 	"cimcvenginemessagecreator.h"
       
    28 #include    "mimcvenginemessage.h"
       
    29 #include	"cimcvappui.h"
       
    30 #include 	"imcvuiappnotemapper.h"
       
    31 #include 	"mimcvapplayoutinfo.h"
       
    32 #include 	"imcvlogger.h"
       
    33 #include 	"cimcvappbitmapmapping.h"
       
    34 #include 	"mimcvuiappskinvariant.h"
       
    35 #include 	"imcvuiapputils.h"
       
    36 #include 	"cimcvappmessageextensionshandler.h"
       
    37 #include 	"mimcvenginemessagecontainerinfo.h"
       
    38 #include 	"mimcvenginemessagehandler.h"
       
    39 #include 	"mimcvrecipientobserver.h"
       
    40 #include    "imcvuiapp.hrh"
       
    41 //consts
       
    42 #include 	"imcvuiliterals.h"
       
    43 #include    "imcvuiapp.h"
       
    44 #include    <StringLoader.h>
       
    45 #include 	<txtrich.h>
       
    46 #include    <aknlayout.cdl.h> //cdl 
       
    47 #include    <applayout.cdl.h> //cdl 
       
    48 #include    <AknsUtils.h>
       
    49 #include    <aknlayoutscalable_apps.cdl.h>
       
    50 #include    <aknnotewrappers.h>
       
    51 #include    <AknFepGlobalEnums.h> // for EAknFepSoftkeySpell
       
    52 #include    <AknIconUtils.h>
       
    53 
       
    54 #include 	<imcvuiapp.rsg>
       
    55 #include 	<imerrors.hrh>
       
    56 
       
    57 #include "conversations.h"
       
    58 
       
    59 #include "cimcvapplogineventlistener.h"
       
    60 #include "cimcvappwaitnote.h"
       
    61 #include <aknEditStateIndicator.h>
       
    62 #include <AknIndicatorContainer.h>
       
    63 
       
    64 #include "mimcvenginecchhandler.h"
       
    65 #include "mimcvenginemessageswriteinterface.h"
       
    66 #include "mimcvenginechatinterface.h"
       
    67 
       
    68 #include <finditemengine.h>
       
    69 
       
    70 #include <e32property.h>
       
    71 #include "cimcvappview.h"
       
    72 
       
    73 
       
    74 
       
    75 // ============================ MEMBER FUNCTIONS ===============================
       
    76 
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CIMCVAppViewContainer::NewL
       
    80 // Symbian constructor can leave.
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 CIMCVAppViewContainer* CIMCVAppViewContainer::NewL( 
       
    84             const TRect& aRect,
       
    85             CIMCVEngine* aEngine,
       
    86             MIMCVEngineMessageReadInterface* aReadInterface,
       
    87 		    MIMCVEngineMessageWriteInterface* aWriteInterface,
       
    88 		    CIMCVAppView* aParent,
       
    89             CIMCVAppMessageExtensionsHandler& aMessageHandler,
       
    90 			CEikButtonGroupContainer* aCba,
       
    91 			const TDesC& aRecipientId,			
       
    92 			MIMCVRecipientObserver* aRecipientObserver,
       
    93             CIMCVAppRichTextContainerCache* aRTContainerCache,
       
    94             CGulIcon* aFromMe, CGulIcon* aToMe)
       
    95 	{
       
    96 	IM_CV_LOGS(TXT("CIMCVAppViewContainer::NewL()  start") );
       
    97 	CIMCVAppViewContainer* self = new ( ELeave )
       
    98 			 CIMCVAppViewContainer(aEngine,aReadInterface,aWriteInterface,
       
    99 			aMessageHandler, aCba, aRecipientObserver,*aParent, aRTContainerCache );
       
   100 
       
   101 	CleanupStack::PushL( self );
       
   102 	self->ConstructL( aRect, aParent, aFromMe, aToMe,aRecipientId);
       
   103 	CleanupStack::Pop( self );
       
   104 	IM_CV_LOGS(TXT("CIMCVAppViewContainer::NewL()  end") );
       
   105 	return self;
       
   106 	}
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // CIMCVAppViewContainer::CIMCVAppViewContainer
       
   110 // Default constructor must not leave
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 CIMCVAppViewContainer::CIMCVAppViewContainer(CIMCVEngine* aEngine,
       
   114 			MIMCVEngineMessageReadInterface* aReadInterface,
       
   115 		    MIMCVEngineMessageWriteInterface* aWriteInterface, 
       
   116             CIMCVAppMessageExtensionsHandler& aMessageHandler,
       
   117 			CEikButtonGroupContainer* aCba,
       
   118 			MIMCVRecipientObserver* aRecipientObserver,
       
   119 			CIMCVAppView& aAppView,
       
   120             CIMCVAppRichTextContainerCache* aRTContainerCache):
       
   121             iActiveEngine(aEngine),
       
   122   iReadInterface(aReadInterface),
       
   123   iWriteInterface(aWriteInterface),
       
   124   iMessageExtensionsHandler( aMessageHandler ),
       
   125   iCba( aCba ),
       
   126   iRecipientObserver( aRecipientObserver ),  
       
   127   iAppView(aAppView),
       
   128   iRTContainerCache(aRTContainerCache)
       
   129     {
       
   130     IM_CV_LOGS(TXT("CIMCVAppViewContainer::CIMCVAppViewContainer() start") );
       
   131     // take virtual ownership of interfaces, so that they are not deleted
       
   132     IM_CV_LOGS(TXT("CIMCVAppViewContainer::CIMCVAppViewContainer() end") );
       
   133    	}
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 // CIMCVAppViewContainer::ConstructL
       
   137 // Symbian 2nd phase constructor can leave.
       
   138 // -----------------------------------------------------------------------------
       
   139 //
       
   140 void CIMCVAppViewContainer::ConstructL( const TRect& aRect, 
       
   141                                             MObjectProvider* aParent,                                            
       
   142                                             CGulIcon* aFromMe, CGulIcon* aToMe,
       
   143                                             const TDesC& aRecipientId )
       
   144 	{	
       
   145 	IM_CV_LOGS(TXT("CIMCVAppViewContainer::ConstructL() start") );
       
   146 	// for getting mbm path from CIMCVAPPAppUi
       
   147 	iRecipientId = aRecipientId.AllocL();
       
   148 	
       
   149 	iAppUi = static_cast<CIMCVAppUi*>( CEikonEnv::Static()->AppUi() );
       
   150 	iAppUi->AddLayoutChangeObserver( this );
       
   151 
       
   152 	// This must be done first.
       
   153 	SetMopParent( aParent );
       
   154 	CreateWindowL();
       
   155 
       
   156 	iSkinVaiant = iAppUi->SkinVariantL();
       
   157 
       
   158 	iFromMe = aFromMe;
       
   159 	iToMe = aToMe;
       
   160 	//Load from-me and to-me icons
       
   161 	if(!iFromMe)
       
   162 	    {
       
   163 	    iFromMe = LoadBitmapL(KEMbmImcvuiappQgnpropimfrom,EMbmImcvuiappQgn_prop_im_from,EMbmImcvuiappQgn_prop_im_from_mask);
       
   164 	    }
       
   165 	if(!iToMe)
       
   166 	    {
       
   167 	    iToMe = LoadBitmapL(KEMbmImcvuiappQgnpropimtome,EMbmImcvuiappQgn_prop_im_tome,EMbmImcvuiappQgn_prop_im_tome_mask );
       
   168 	    }
       
   169 
       
   170 
       
   171 	iMsgEditor = CIMCVAppMessageEditor::NewL(this, iAppUi->MbmFullPath(), iAppView,
       
   172 	        iMessageExtensionsHandler );
       
   173 	iMsgEditor->SetMessageEditorObserver(this);
       
   174 	//Sets the previously typed message in the editor
       
   175 	iMsgEditor->SetTextL( iReadInterface->GetEditerMessage() );
       
   176 	iChatView = CIMCVAppViewControl::NewL( aRect,
       
   177                             	        *this,
       
   178                             	        *iReadInterface,
       
   179                             	        iMessageExtensionsHandler,
       
   180                             	        iFromMe, 
       
   181                             	        iToMe,
       
   182                             	        *iRTContainerCache,
       
   183                             	        *iActiveEngine );
       
   184 	iChatView->SetObserver( this );
       
   185 	iMsgEditor->SetObserver( this );
       
   186 
       
   187 	iAppUi->LayoutInfo()->SetLayoutID( TChatListBoxLayout::EWithEditor );
       
   188 	iAppUi->LayoutInfo()->SetEditorVisibility( ETrue );
       
   189 
       
   190 	SetRect( aRect );
       
   191 	
       
   192 	iMsgEditor->Editor().SetCursorPosL(0, EFalse);
       
   193 	iChatView->SetFocus( EFalse );
       
   194 	iMsgEditor->SetFocus(EFalse);
       
   195 
       
   196 	ActivateL();
       
   197 
       
   198 	iChatView->SetTapObserver( this, EMessageList );
       
   199 	iMsgEditor->SetTapObserver( this, EMessageEditor );
       
   200 
       
   201 	IM_CV_LOGS(TXT("CIMCVAppViewContainer::ConstructL() end") );
       
   202 	}
       
   203 
       
   204 
       
   205 // ---------------------------------------------------------
       
   206 // CIMCVAppViewContainer::~CIMCVAppViewContainer()
       
   207 // ---------------------------------------------------------
       
   208 //
       
   209 CIMCVAppViewContainer::~CIMCVAppViewContainer()
       
   210     {
       
   211 	IM_CV_LOGS(TXT("CIMCVAppViewContainer::DESTRUCTING() DESTRUCTER GETTING CALLED end") );    
       
   212     if(iChatView)
       
   213         {
       
   214         delete iChatView;
       
   215         }
       
   216     if(iEditorMessage)
       
   217         {
       
   218         delete iEditorMessage;
       
   219         }
       
   220     delete iMsgEditor;
       
   221     if( iAppUi )
       
   222         {
       
   223         if( !iAppUi->IsUnderDestruction() )
       
   224             {
       
   225             iAppUi->LayoutInfo()->SetEditorVisibility( EFalse );
       
   226             iAppUi->RemoveLayoutChangeObserver( this );
       
   227             }
       
   228         }	
       
   229     }
       
   230 // ---------------------------------------------------------
       
   231 // CIMCVAppViewContainer::SetServiceParametersL()
       
   232 // This method is called when scrolling is started again
       
   233 // ---------------------------------------------------------
       
   234 //          
       
   235 void CIMCVAppViewContainer::SetServiceParametersL( 
       
   236                                 CIMCVEngine* aNewEngine )
       
   237     {
       
   238     iActiveEngine = aNewEngine;
       
   239     }
       
   240 // ---------------------------------------------------------
       
   241 // CIMCVAppViewContainer::StartScrollingL()
       
   242 // This method is called when scrolling is started again
       
   243 // ---------------------------------------------------------
       
   244 //
       
   245 void CIMCVAppViewContainer::StartScrollingL()
       
   246 	{
       
   247 	IM_CV_LOGS(TXT("CIMCVAppViewContainer::StartScrollingL() start") );
       
   248 	// disable highlight and set focus to editor
       
   249     if( iChatView->Highlighted() )
       
   250         {
       
   251         iChatView->DisableHighlightL();
       
   252         }       
       
   253     iMsgEditor->SetFocus( ETrue, EDrawNow );
       
   254     iMsgEditor->DrawDeferred();
       
   255     UpdateCbaL();
       
   256     iAppView.UpdateToolbarButtonsStateL();
       
   257     IM_CV_LOGS(TXT("CIMCVAppViewContainer::StartScrollingL() end") );
       
   258 	}
       
   259 
       
   260 // ---------------------------------------------------------
       
   261 // CIMCVAppViewContainer::StopScrollingL()
       
   262 // (other items were commented in a header).
       
   263 // ---------------------------------------------------------
       
   264 //
       
   265 void CIMCVAppViewContainer::StopScrollingL()
       
   266 	{
       
   267 	IM_CV_LOGS(TXT("CIMCVAppViewContainer::StopScrollingL() start") );
       
   268 	// unfocus editor (highlighting is enabled 
       
   269 	// automatically in OfferKeyEvent of ChatView)
       
   270 	iMsgEditor->SetFocus( EFalse, EDrawNow );
       
   271 	iMsgEditor->DrawDeferred();
       
   272     // Set editor cursor pos to end of text
       
   273 	iMsgEditor->Editor().SetCursorPosL( iMsgEditor->TextLength(), EFalse );
       
   274     UpdateCbaL();
       
   275     iAppView.UpdateToolbarButtonsStateL();
       
   276     IM_CV_LOGS(TXT("CIMCVAppViewContainer::StopScrollingL() end") );
       
   277 	}
       
   278 
       
   279 void CIMCVAppViewContainer :: SmileyDialogLaunched (TBool aLaunched)
       
   280     {
       
   281     iChatView->SmileyDialogLaunched (aLaunched);
       
   282     }
       
   283 void CIMCVAppViewContainer :: UpdateChatViewL ()
       
   284     {
       
   285     iChatView->UpdateChatViewL ();
       
   286     }
       
   287 	
       
   288 // ---------------------------------------------------------
       
   289 // CIMCVAppViewContainer::UpdateCbaL()
       
   290 // ---------------------------------------------------------
       
   291 //
       
   292 void CIMCVAppViewContainer::UpdateCbaL()
       
   293     {
       
   294     IM_CV_LOGS(TXT("CIMCVAppViewContainer::UpdateCbaL() start") );
       
   295     if( iChatView->Highlighted() )
       
   296         {
       
   297         // focus on chatview
       
   298         HBufC* item = iChatView->SelectedItemL();
       
   299         CleanupStack::PushL( item );
       
   300         if( item && item->Length() > 0 )
       
   301             {
       
   302             // automatic find item selected
       
   303             TInt cbaRes = R_CV_SOFTKEYS_OPTIONS_BACK__CONTEXTOPTIONS;
       
   304             iCba->SetCommandSetL( cbaRes );
       
   305             iCba->DrawNow();
       
   306             }
       
   307         CleanupStack::PopAndDestroy( item );        
       
   308         }
       
   309     
       
   310     IM_CV_LOGS(TXT("CIMCVAppViewContainer::UpdateCbaL() end") );    
       
   311     }
       
   312 
       
   313 // ---------------------------------------------------------
       
   314 // CIMCVAppViewContainer::HandleMessageEditorEventL()
       
   315 // ---------------------------------------------------------
       
   316 //
       
   317 void CIMCVAppViewContainer::HandleMessageEditorEventL( TEditorEvent aEvent )
       
   318 	{
       
   319 	IM_CV_LOGS(TXT("CIMCVAppViewContainer::HandleMessageEditorEventL() start") );
       
   320 	
       
   321 	switch( aEvent )
       
   322         {
       
   323 	    case EEditorContentCleared: 
       
   324 	        {	        
       
   325 	        // Call StartScrollingL to update CBA if needed
       
   326 	        StartScrollingL();
       
   327 	        break;	
       
   328 	        }
       
   329 	    case EEditorContentChanged:
       
   330 	        {            
       
   331 	        // Call StartScrollingL to update CBA if needed
       
   332 	        if(!iMsgEditor->IsFocused())//!iEditor->IsFocused())
       
   333 	            {
       
   334 	            StartScrollingL();	
       
   335 	            }
       
   336 	        break;
       
   337 	        }
       
   338 	    default:
       
   339 	        {
       
   340 	        break;
       
   341 	        }
       
   342         }    
       
   343     // need to implements	
       
   344 	IM_CV_LOGS(TXT("CIMCVAppViewContainer::HandleMessageEditorEventL() end") );	
       
   345 	}
       
   346 
       
   347 
       
   348 void CIMCVAppViewContainer::StartConversationL()
       
   349 	{
       
   350 	IM_CV_LOGS(TXT("CIMCVAppViewContainer::StartConversationL() start") );
       
   351 	// start a conversation with selected user id,
       
   352 	// exist cache info fetch that
       
   353 	
       
   354 	iActiveEngine->MessageHandler().StartNewConversationL( *iRecipientId );
       
   355 	
       
   356 	IM_CV_LOGS(TXT("CIMCVAppViewContainer::StartConversationL() end") );
       
   357 	}
       
   358 
       
   359 // ---------------------------------------------------------
       
   360 // CIMCVAppViewContainer::CloseConversationL()
       
   361 // This method handles message sending to engine
       
   362 // ---------------------------------------------------------
       
   363 //
       
   364 TInt CIMCVAppViewContainer::CloseConversationL(const TDesC& aBuddyId )
       
   365 	{
       
   366 	IM_CV_LOGS(TXT("CIMCVAppViewContainer::CloseConversationL()") );
       
   367 	// close the conversation with selected user id,
       
   368 	// exist cache info fetch that
       
   369 	iRTContainerCache->DeleteContainer(iReadInterface->Name() ,iActiveEngine->GetServiceId()  );
       
   370 	return iActiveEngine->MessageHandler().CloseConversationL( aBuddyId );
       
   371 	}
       
   372 // ---------------------------------------------------------
       
   373 // CIMCVAppViewContainer::DeactivateConversationL()
       
   374 // This method handles message sending to engine
       
   375 // ---------------------------------------------------------
       
   376 //
       
   377 TInt CIMCVAppViewContainer::DeactivateConversationL()
       
   378 	{
       
   379 	IM_CV_LOGS(TXT("CIMCVAppViewContainer::DeactivateConversationL()") );
       
   380 	// start a conversation with selected user id,
       
   381 	// exist cache info fetch that
       
   382 	return iActiveEngine->MessageHandler().DeactivateConversationL();
       
   383 	}	
       
   384 // ---------------------------------------------------------
       
   385 // CIMCVAppViewContainer::SendMessageL()
       
   386 // This method handles message sending to engine
       
   387 // ---------------------------------------------------------
       
   388 //
       
   389 void CIMCVAppViewContainer::SendMessageL()
       
   390 	{
       
   391 	IM_CV_LOGS(TXT("CIMCVAppViewContainer::SendMessageL() start") );
       
   392 	
       
   393 	TBool loggedIn = IsLoggedIn();
       
   394 	if( !loggedIn )
       
   395 		{
       
   396 		// load the promp from lOC file + server name
       
   397 		HBufC* prompt = StringLoader::LoadLC( R_SERVTAB_CONNECTION_NEEDED_TO, 
       
   398 		        iActiveEngine->ServiceName() );
       
   399 
       
   400 	    TInt ret = IMCVUiAppNoteMapper::DisplayQueryDialogL( R_GENERIC_YES_NO_CONFIRMATION_QUERY,
       
   401 	    												 *prompt );
       
   402 	    												 
       
   403 	    CleanupStack::PopAndDestroy( prompt );
       
   404 	    
       
   405 
       
   406     	if( ( ret == EAknSoftkeyOk ) || ( ret == EAknSoftkeyYes ) )
       
   407 	    	{
       
   408 			// load the promp from lOC file + server name
       
   409 			HBufC* prompt = StringLoader::LoadLC( R_SERVTAB_LOGIN_ONGOING, 
       
   410 			        iActiveEngine->ServiceName() );
       
   411 
       
   412 			CIMCVAppWaitNote* waitDialog = CIMCVAppWaitNote::ShowWaitNoteL( 
       
   413 			        *prompt, 
       
   414 			        ETrue );         
       
   415 						        
       
   416 			CleanupStack::PushL(waitDialog);
       
   417 			
       
   418 			// start capturing the events
       
   419 			iAppUi->CaptureEventsL();
       
   420 			
       
   421 			IM_CV_LOGS(TXT("CIMCVAppViewContainer::SendMessageL() BEFORE CALLING LOGIN") );
       
   422 			TRAPD(error, iActiveEngine->LoginL());
       
   423 			IM_CV_LOGS(TXT("CIMCVAppViewContainer::SendMessageL() AFTER CALLING LOGIN") );					
       
   424 			// stop capturing the events
       
   425     		iAppUi->ReleaseCapturingL(); 
       
   426 			
       
   427 			IM_CV_LOGS(TXT("CIMCVAppViewContainer::SendMessageL() start") );
       
   428 			loggedIn = IsLoggedIn();
       
   429 			if (KErrNone != error)
       
   430 				{
       
   431 				IMCVUiAppNoteMapper::ShowNoteL( KImErrServiceGeneralError , KNullDesC );				
       
   432 				}
       
   433 			else
       
   434 			    {
       
   435 			    // subscribe for presence notification
       
   436 			    iActiveEngine->MessageHandler().SubscribePresenceL( *iRecipientId );
       
   437 			    }
       
   438 						
       
   439 			CleanupStack::PopAndDestroy(); //waitDialog
       
   440 			CleanupStack::PopAndDestroy(); //prompt
       
   441 	    	}		    	
       
   442 		}
       
   443 	
       
   444 	if( loggedIn )
       
   445 		{
       
   446 		if(iEditorMessage)
       
   447 			{
       
   448 			delete iEditorMessage;
       
   449 			iEditorMessage = NULL;	
       
   450 			}
       
   451 		iEditorMessage = iMessageExtensionsHandler.ProcessMessageLC( iMsgEditor->Editor(),
       
   452 		        iActiveEngine->GetServiceId() );
       
   453 		
       
   454 	    TPtr msgPtr( iEditorMessage->Des() );
       
   455 	    CleanupStack::Pop();//iEditorMessage   
       
   456 		
       
   457 		if( msgPtr.Length() == 0 )
       
   458 			{
       
   459 			return;	
       
   460 			}
       
   461 		
       
   462 		TPtrC ownUserId = iActiveEngine->GetLoggedInUserId() ;
       
   463 		
       
   464 		MIMCVEngineMessageCreator::SMessageData data =
       
   465 											{
       
   466 											KMessageDataVersion,
       
   467 											ownUserId,
       
   468 											*iRecipientId, // Recipient
       
   469 											msgPtr,
       
   470 											MIMCVEngineMessage::EContentText,
       
   471 											MIMCVEngineMessage::EMessageSent            
       
   472 											};
       
   473 	    MIMCVEngineMessage* message = iActiveEngine->MessageHandler().MessageCreator().CreateMessageL( data );
       
   474 	    
       
   475 	    iWriteInterface->AppendL(message );
       
   476 	   		
       
   477 	    iActiveEngine->MessageHandler().SendMessageL( *message );
       
   478 		
       
   479 		ResetAfterSendL();
       
   480 		StopScrollingL();
       
   481 		}
       
   482 	IM_CV_LOGS(TXT("CIMCVAppViewContainer::SendMessageL() end") );
       
   483 	}
       
   484 
       
   485 
       
   486 // ---------------------------------------------------------
       
   487 // CIMCVAppViewContainer::InsertStatusChangedMessageL()
       
   488 // This method handles message sending to engine
       
   489 // ---------------------------------------------------------
       
   490 //
       
   491 void CIMCVAppViewContainer::InsertStatusChangedMessageL(CIMCVEngine& aEngine ,
       
   492                                                         TInt aServiceId, 
       
   493                                                         const TDesC& aBuddyId )
       
   494 	{
       
   495 	IM_CV_LOGS(TXT("CIMCVAppViewContainer::InsertStatusChangedMessageL() start") );
       
   496 	
       
   497 	TIMCVOnlineStatus status = 	aEngine.MessageHandler().GetPresenceStatus();
       
   498 	TInt resourceId(0);
       
   499 	switch( status ) 
       
   500 		{
       
   501 		case EOnline:
       
   502 			{
       
   503 			resourceId = R_SERVTAB_STATUS_CHANGE_ONLINE;
       
   504 			break;	
       
   505 			}
       
   506 		case EInvisible:
       
   507 			{
       
   508 			resourceId = R_SERVTAB_STATUS_CHANGE_ONTHEPHONE;
       
   509 			break;	
       
   510 			}
       
   511 		case EAway:
       
   512 			{
       
   513 			resourceId = R_SERVTAB_STATUS_CHANGE_AWAY;	
       
   514 			break;	
       
   515 			}
       
   516 		case EBusy:
       
   517 			{
       
   518 			resourceId = R_SERVTAB_STATUS_CHANGE_DND;
       
   519 			break;	
       
   520 			}
       
   521 		case EOnPhone:
       
   522 			{
       
   523 			resourceId = R_SERVTAB_STATUS_CHANGE_ONTHEPHONE;
       
   524 			break;	
       
   525 			}
       
   526 		case EDoNotDisturb:
       
   527 			{
       
   528 			resourceId = R_SERVTAB_STATUS_CHANGE_DND;
       
   529 			break;	
       
   530 			}
       
   531 		case EBlock:
       
   532 		    {
       
   533 		    resourceId = R_SERVTAB_STATUS_CHANGE_BLOCKED;
       
   534 		    break;
       
   535 		    }
       
   536 		case EOffline :
       
   537 		default:
       
   538 			{
       
   539 			resourceId = R_SERVTAB_STATUS_CHANGE_OFFLINE;
       
   540 			// default offline always
       
   541 			}
       
   542 		}
       
   543 	// not owned , chat interface
       
   544 	MIMCVEngineChatInterface* chatInterface = &(aEngine.ChatInterface() );
       
   545 	MIMCVEngineMessageReadInterface& readInterface =  chatInterface->MessageReadInterfaceL( aServiceId, aBuddyId ); 
       
   546 	
       
   547 	// cleanup stack
       
   548 	HBufC* textmessage = StringLoader::LoadLC( resourceId, readInterface.Name()  );
       
   549 	TPtrC textmessagePtr( textmessage->Des() );
       
   550 	
       
   551 	TPtrC ownUserId = aEngine.GetLoggedInUserId() ;
       
   552 	MIMCVEngineMessageCreator::SMessageData data =
       
   553 										{
       
   554 										KMessageDataVersion,
       
   555 										ownUserId,
       
   556 										aBuddyId, // Recipient
       
   557 										textmessagePtr,
       
   558 										MIMCVEngineMessage::EContentText,
       
   559 										MIMCVEngineMessage::EMessageOther            
       
   560 										};
       
   561     MIMCVEngineMessage* message = aEngine.MessageHandler().MessageCreator().CreateMessageL( data );
       
   562     
       
   563     MIMCVEngineMessageWriteInterface& writeInterface =  chatInterface->MessageWriteInterfaceL( aServiceId, aBuddyId );
       
   564     writeInterface.AppendL( message );
       
   565   	
       
   566    	// append message to cache , this is not sent/recieve message
       
   567    	// based on status change message is automatically created
       
   568   	aEngine.MessageHandler().AppendToCacheL( aBuddyId, textmessagePtr );
       
   569    		
       
   570 	CleanupStack::PopAndDestroy();// textmessage
       
   571 		
       
   572 	IM_CV_LOGS(TXT("CIMCVAppViewContainer::InsertStatusChangedMessageL() end") );
       
   573 	}
       
   574 
       
   575 // ---------------------------------------------------------
       
   576 // CIMCVAppViewContainer::ResetAfterSendL()
       
   577 // Resets arrays, lines and nick length after send
       
   578 // (other items were commented in a header).
       
   579 // ---------------------------------------------------------
       
   580 //
       
   581 void CIMCVAppViewContainer::ResetAfterSendL()
       
   582 	{
       
   583 	IM_CV_LOGS(TXT("CIMCVAppViewContainer::ResetAfterSendL() start") );	
       
   584 	iMsgEditor->SetTextL(KNullDesC());
       
   585 	StartScrollingL();  // Call to update CBA
       
   586 	IM_CV_LOGS(TXT("CIMCVAppViewContainer::ResetAfterSendL() end") );
       
   587 	}
       
   588 
       
   589 // ---------------------------------------------------------
       
   590 // CIMCVAppViewContainer::IsLoggedIn()
       
   591 // (other items were commented in a header).
       
   592 // ---------------------------------------------------------
       
   593 //
       
   594 TBool CIMCVAppViewContainer::IsLoggedIn() const
       
   595 	{
       
   596 	IM_CV_LOGS(TXT("CIMCVAppViewContainer::IsLoggedIn() ") );
       
   597 	
       
   598 	if (!iActiveEngine->IsLoggedIn()) 
       
   599 		{
       
   600 		return EFalse;
       
   601 		}
       
   602 
       
   603 	return ETrue;
       
   604 	}
       
   605 // ---------------------------------------------------------
       
   606 // CIMCVAppViewContainer::IsStopped()
       
   607 // This method checks if scroll mode is on or off
       
   608 // ---------------------------------------------------------
       
   609 //
       
   610 TBool CIMCVAppViewContainer::IsStopped() const
       
   611 	{
       
   612 	return iChatView->Highlighted();
       
   613 	}
       
   614 
       
   615 // ---------------------------------------------------------
       
   616 // CIMCVAppViewContainer::DisplayInfoNoteL()
       
   617 // Displays info note for corresponding resource id
       
   618 // (other items were commented in a header).
       
   619 // ---------------------------------------------------------
       
   620 //
       
   621 void CIMCVAppViewContainer::DisplayInfoNoteL( const TInt aResourceId )
       
   622 	{
       
   623 	IM_CV_LOGS(TXT("CIMCVAppViewContainer::DisplayInfoNoteL() start") );
       
   624 	CAknNoteDialog* infoNote = new (ELeave) CAknNoteDialog( CAknNoteDialog::
       
   625 			EConfirmationTone,CAknNoteDialog::EShortTimeout );
       
   626 
       
   627 	infoNote->ExecuteLD( aResourceId );
       
   628 	IM_CV_LOGS(TXT("CIMCVAppViewContainer::DisplayInfoNoteL() end") );
       
   629 	}
       
   630 
       
   631 // ---------------------------------------------------------
       
   632 // CIMCVAppViewContainer::LayoutChangedL
       
   633 // (other items were commented in a header).
       
   634 // ---------------------------------------------------------
       
   635 //
       
   636 void CIMCVAppViewContainer::LayoutChangedL( TInt aType )
       
   637 	{
       
   638 	IM_CV_LOGS(TXT("CIMCVAppViewContainer::LayoutChangedL() start") );
       
   639     TRect mainPaneRect;
       
   640     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, mainPaneRect );
       
   641     SetRect( mainPaneRect );    
       
   642     // Update skin context of editor
       
   643     if ( iMsgEditor )
       
   644         {
       
   645         iMsgEditor->HandleFindSizeChanged();
       
   646         }        
       
   647 	if (iRTContainerCache && aType == KAknsMessageSkinChange)
       
   648 		{
       
   649 		iRTContainerCache->UpdateSkinTextColorL ();
       
   650 		}
       
   651     CCoeControl::HandleResourceChange( aType );
       
   652     IM_CV_LOGS(TXT("CIMCVAppViewContainer::LayoutChangedL() end") );
       
   653 	}
       
   654 
       
   655     
       
   656 // ---------------------------------------------------------
       
   657 // CIMCVAppViewContainer::SelectedItem()
       
   658 // ---------------------------------------------------------
       
   659 //
       
   660 HBufC* CIMCVAppViewContainer::SelectedItemL()
       
   661     {
       
   662     return iChatView->SelectedItemL();
       
   663     }
       
   664 
       
   665 // -----------------------------------------------------------------------------
       
   666 // CIMCVAppViewContainer::SelectedItemType
       
   667 // (other items were commented in a header).
       
   668 // -----------------------------------------------------------------------------
       
   669 //
       
   670 TInt CIMCVAppViewContainer::SelectedItemType()
       
   671     {
       
   672     return iChatView->SelectedItemType();
       
   673     }
       
   674 // -----------------------------------------------------------------------------
       
   675 // CIMCVAppViewContainer::SetItemHighlightL
       
   676 // (other items were commented in a header).
       
   677 // -----------------------------------------------------------------------------
       
   678 //
       
   679 void CIMCVAppViewContainer::SetItemHighlightL( TBool aHighlight )
       
   680     {
       
   681     iChatView->SetHighlight( aHighlight );
       
   682 	DrawNow ();
       
   683     }
       
   684 
       
   685 // ---------------------------------------------------------
       
   686 // CIMCVAppViewContainer::HandleEdwinSizeEventL( CEikEdwin* aEdwin,
       
   687 // TEdwinSizeEvent aEventType, TSize aDesirableEdwinSize )
       
   688 // This method is called when editor is extended to two lines
       
   689 // ---------------------------------------------------------
       
   690 //
       
   691 TBool CIMCVAppViewContainer::HandleEdwinSizeEventL( CEikEdwin* /*aEdwin*/,
       
   692 			TEdwinSizeEvent aEventType, TSize /*aDesirableEdwinSize*/ )
       
   693 	{
       
   694 	IM_CV_LOGS(TXT("CIMCVAppViewContainer::HandleEdwinSizeEventL() start") );
       
   695 	if (aEventType == EEventSizeChanging )
       
   696 		{		
       
   697 		iMsgEditor->HandleFindSizeChanged();
       
   698 		DrawNow();
       
   699 		return ETrue;
       
   700 		}
       
   701 	IM_CV_LOGS(TXT("CIMCVAppViewContainer::HandleEdwinSizeEventL() end") );
       
   702 	return EFalse;
       
   703 	}
       
   704 
       
   705 // ---------------------------------------------------------
       
   706 // CIMCVAppViewContainer::HandleControlEventL
       
   707 // ---------------------------------------------------------
       
   708 //    
       
   709 void CIMCVAppViewContainer::HandleControlEventL( CCoeControl* aControl,
       
   710                                                      TCoeEvent aEventType )
       
   711     {
       
   712    
       
   713     IM_CV_LOGS(TXT("CIMCVAppViewContainer::HandleControlEventL() start") );
       
   714     if( EEventRequestFocus == aEventType )
       
   715         {
       
   716         if( aControl == static_cast<CCoeControl*>(iMsgEditor) )
       
   717             {
       
   718             // Focus to editor
       
   719             StartScrollingL();
       
   720             }
       
   721         else // aControl == iChatView
       
   722             {
       
   723             // Focus to messagelist
       
   724             StopScrollingL();
       
   725             }
       
   726         }
       
   727 
       
   728     if( IMCVUiAppUtils::PenEnabled() )
       
   729         {
       
   730         if( EEventStateChanged == aEventType )
       
   731             {
       
   732             if( aControl == (CCoeControl*)iMsgEditor )
       
   733                 {
       
   734                 // Update MSK - When using virtual keyboard
       
   735                 // on touch enabled devices, one is bound to receive
       
   736                 // EEventStateChanged. Hence handle the same
       
   737                 UpdateCbaL();
       
   738                 }        
       
   739             }
       
   740         }
       
   741 
       
   742     IM_CV_LOGS(TXT("CIMCVAppViewContainer::HandleControlEventL() end") );
       
   743     }
       
   744 
       
   745 // ---------------------------------------------------------
       
   746 // CIMCVAppViewContainer::SizeChanged()
       
   747 // Called by framework when the view size is changed
       
   748 // ---------------------------------------------------------
       
   749 //
       
   750 void CIMCVAppViewContainer::SizeChanged()
       
   751     {
       
   752     IM_CV_LOGS(TXT("CIMCVAppViewContainer::SizeChanged() start") );
       
   753 
       
   754     TAknLayoutRect rp;
       
   755 
       
   756     rp.LayoutRect( Rect(), AknLayoutScalable_Apps::im_reading_pane(
       
   757                    TChatListBoxLayout::EWithEditor2Lines) );	
       
   758     // Set icon sizes, do this before setting the rect for 
       
   759     // chat view to prevent icon sizes from changing after chat
       
   760 	
       
   761     // view rect is set.
       
   762 	ResizeIcons( TextRect() );
       
   763 	
       
   764 	// set rect for chat view
       
   765 	iChatView->SetRect( rp.Rect() );	
       
   766     // and editor	
       
   767 	iMsgEditor->HandleFindSizeChanged();
       
   768     DrawNow();
       
   769     IM_CV_LOGS(TXT("CIMCVAppViewContainer::SizeChanged() end") );
       
   770 	}
       
   771 
       
   772 // ---------------------------------------------------------
       
   773 // CIMCVAppViewContainer::CountComponentControls() const
       
   774 // ---------------------------------------------------------
       
   775 //
       
   776 TInt CIMCVAppViewContainer::CountComponentControls() const
       
   777     {
       
   778 	// We have 2 controls
       
   779 	return 2;
       
   780     }
       
   781 
       
   782 // ---------------------------------------------------------
       
   783 // CIMCVAppViewContainer::ComponentControl(TInt aIndex) const
       
   784 // ---------------------------------------------------------
       
   785 //
       
   786 CCoeControl* CIMCVAppViewContainer::ComponentControl( TInt aIndex ) const
       
   787     {
       
   788 	//returns control with aIndex
       
   789 	switch ( aIndex )
       
   790 		{
       
   791 		case 0:
       
   792 			{
       
   793 			return iChatView;
       
   794 			}
       
   795 		case 1:
       
   796 			{
       
   797 			return iMsgEditor;
       
   798 			}
       
   799 		default:
       
   800 			{
       
   801 			return NULL;
       
   802 			}
       
   803 		}
       
   804     }
       
   805 
       
   806 // ---------------------------------------------------------
       
   807 // CIMCVAppViewContainer::Draw(const TRect& aRect) const
       
   808 // ---------------------------------------------------------
       
   809 //
       
   810 void CIMCVAppViewContainer::Draw( const TRect& aRect ) const
       
   811     {
       
   812     IM_CV_LOGS(TXT("CIMCVAppViewContainer::Draw() const start") );
       
   813   	CWindowGc& gc = SystemGc();  	  	 	
       
   814     
       
   815     iSkinVaiant->ClearChatListBoxBackGround( 
       
   816                                     gc, aRect, 
       
   817                                     iSkinVaiant->MainPaneBackgroundContext() );
       
   818 	
       
   819 	IM_CV_LOGS(TXT("CIMCVAppViewContainer::Draw() const end") );
       
   820 	}
       
   821 
       
   822 // ---------------------------------------------------------
       
   823 // CIMCVAppViewContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent,
       
   824 //												  TEventCode aType )
       
   825 // Handles keyevents
       
   826 // ---------------------------------------------------------
       
   827 //
       
   828 TKeyResponse CIMCVAppViewContainer::OfferKeyEventL( 
       
   829             const TKeyEvent& aKeyEvent,
       
   830 			TEventCode aType )
       
   831     {
       
   832     IM_CV_LOGS(TXT("CIMCVAppViewContainer::OfferKeyEventL() start") );   
       
   833     IM_CV_LOGS(TXT("CIMCVAppViewContainer::OfferKeyEventL() is EKeyPhoneSend Event = %d") , aKeyEvent.iCode );
       
   834 
       
   835     //Consume the EEventKeyUp event for send key so that it will not launch the dialler before sending the actual message.
       
   836     if ( aKeyEvent.iScanCode == EStdKeyYes && aType != EEventKey )
       
   837         {
       
   838         return EKeyWasConsumed;
       
   839         }
       
   840    
       
   841     if( (iChatView->Highlighted() ) || ( !iMsgEditor->IsFocused()) )
       
   842         {
       
   843         if( (aKeyEvent.iScanCode >= '0' && aKeyEvent.iScanCode <= '9') ||
       
   844             (aKeyEvent.iScanCode >= 'a' && aKeyEvent.iScanCode <= 'z') ||
       
   845             (aKeyEvent.iScanCode >= 'A' && aKeyEvent.iScanCode <= 'Z') ||
       
   846             (aKeyEvent.iScanCode >= EStdKeyComma && aKeyEvent.iScanCode <= EStdKeyNkpPlus) ||
       
   847             aKeyEvent.iScanCode == EStdKeySpace || aKeyEvent.iScanCode == EStdKeyLeftShift )
       
   848             {
       
   849             // stop the automatic scrolling and start manual 
       
   850             // if user presses any of the number keys (0-9)
       
   851 			// or user presses any key on the QWERT - key pad
       
   852             StartScrollingL();
       
   853             return EKeyWasConsumed;
       
   854             }
       
   855         }
       
   856     
       
   857     
       
   858     switch( aKeyEvent.iCode )
       
   859         {
       
   860         // flowthrough
       
   861         case EKeyEnter:
       
   862         case EKeyOK:
       
   863         case EKeyPhoneSend:
       
   864             {
       
   865             if( iMsgEditor->IsFocused() )
       
   866 			    {
       
   867 			    IM_CV_LOGS(TXT("CIMCVAppViewContainer::OfferKeyEventL() message editor Focused ") );   
       
   868                 // trapping error so that focus can be returned to editor
       
   869                 SendMessageL() ;
       
   870                 IM_CV_LOGS(TXT("CIMCVAppViewContainer::OfferKeyEventL() message Sent ") ); 
       
   871                 iMsgEditor->SetFocus( ETrue );
       
   872 			    }
       
   873             else if( aKeyEvent.iCode == EKeyEnter || aKeyEvent.iCode == EKeyOK                    
       
   874                      && iChatView->Highlighted() && iChatView->SelectedItemType()
       
   875                      != CFindItemEngine::EFindItemSearchPhoneNumberBin )
       
   876                 {
       
   877                 StopScrollingL();
       
   878                 iRecipientObserver->ShowPopUpMenuL();
       
   879                 }
       
   880             else if ( aKeyEvent.iCode == EKeyPhoneSend
       
   881                                 && iChatView->Highlighted()
       
   882                                 && (iChatView->SelectedItemType()
       
   883                                     == (CFindItemEngine::EFindItemSearchPhoneNumberBin)
       
   884                                     ||(CFindItemEngine::EFindItemSearchMailAddressBin)) )
       
   885                 {
       
   886                  // Phone number highlighted, send key pressed -> call
       
   887                  iAppUi->ProcessCommandL( EIMCVCmdCall );
       
   888                 }
       
   889             //iAppView.UpdateToolbarButtonsStateL();
       
   890             StopScrollingL();
       
   891 		    return EKeyWasConsumed;
       
   892             }
       
   893 
       
   894         case EKeyBackspace:
       
   895             {
       
   896 			// if bitmap is selected, it is deleted "normally" in
       
   897 			// iEditor's OfferKeyEvent
       
   898             if( iMsgEditor->Editor().SelectionLength() > 0 )
       
   899 				{
       
   900 				break;
       
   901 				}
       
   902 
       
   903             TInt cursorPos( iMsgEditor->Editor().CursorPos() );
       
   904 			if( cursorPos > 0 ) // at least one char in editor
       
   905 				{
       
   906                 TPtrC ptr = iMsgEditor->Editor().RichText()->Read( ( cursorPos - 1 ), 1 );
       
   907     			// if a char to be "backspaced" is a picture
       
   908     			if( ptr[ 0 ] == CEditableText::EPictureCharacter )
       
   909     				{
       
   910                     iMessageExtensionsHandler.DeleteExtensionL( iMsgEditor->Editor(), iActiveEngine->GetServiceId(),
       
   911                             EMessageExtensionSmiley, cursorPos - 1 );
       
   912                     iAppView.UpdateToolbarButtonsStateL();
       
   913 					return EKeyWasConsumed;
       
   914 					}
       
   915 				}
       
   916 
       
   917 			if( cursorPos < 2 )
       
   918 				{
       
   919 				cursorPos = 2;
       
   920 				}
       
   921 		
       
   922             break;
       
   923             }
       
   924 
       
   925         // flowthrough
       
   926         case EKeyLeftArrow:
       
   927         case EKeyRightArrow:
       
   928             {
       
   929             if( !iMsgEditor->IsFocused() )
       
   930                 {
       
   931                 iAppView.UpdateToolbarButtonsStateL();
       
   932                 return iAppView.OfferTabEventL(aKeyEvent, aType);
       
   933                 }
       
   934             break;
       
   935             }
       
   936 
       
   937         case EKeyDownArrow: // flowthrough
       
   938         case EKeyUpArrow:
       
   939             {
       
   940             if( iMsgEditor->IsFocused() )
       
   941                 {
       
   942                 iAppView.UpdateToolbarButtonsStateL();
       
   943                 // editor is focused, try to offer the key
       
   944                 if( iMsgEditor->OfferKeyEventL( aKeyEvent, aType ) 
       
   945                         == EKeyWasConsumed )
       
   946                     {
       
   947                     // editor took it
       
   948                     return EKeyWasConsumed;
       
   949                     }
       
   950                 }
       
   951                 
       
   952             // offer the key to our chat control
       
   953             TKeyResponse res = static_cast<CCoeControl*>(iChatView)
       
   954                                         ->OfferKeyEventL( aKeyEvent, aType );
       
   955             
       
   956             if( iChatView->Highlighted() )
       
   957                 {
       
   958                 // change the cba
       
   959                 StopScrollingL();
       
   960                 }
       
   961             else
       
   962                 {
       
   963                 // change the cba
       
   964                 StartScrollingL();
       
   965                 }
       
   966             iAppView.UpdateToolbarButtonsStateL();
       
   967             return res;
       
   968             }
       
   969 
       
   970         default:
       
   971             {
       
   972             break;
       
   973             }
       
   974         }
       
   975     if ( iMsgEditor->IsFocused() )
       
   976         {           
       
   977 
       
   978         TKeyResponse res = iMsgEditor->OfferKeyEventL( aKeyEvent, aType );
       
   979         iAppView.UpdateToolbarButtonsStateL();        
       
   980         // Update CBA only when there is not a shift held down        
       
   981         if ( !( aKeyEvent.iModifiers & EModifierShift ) )
       
   982             {
       
   983             UpdateCbaL();
       
   984             }
       
   985         //If focus is on editer and its empty, and if user presses left arrow or right arrow keys. 
       
   986         //Move the focus to Message list to switch the tabs
       
   987         if((res == EKeyWasNotConsumed)&& (iMsgEditor->TextLength() == 0) && (aType == EEventKeyDown) &&
       
   988                 ((aKeyEvent.iScanCode == EStdKeyLeftArrow) || (aKeyEvent.iScanCode == EStdKeyRightArrow)))
       
   989             {
       
   990             StopScrollingL();       //Move the focus to Message list 
       
   991             }              
       
   992         iAppView.UpdateToolbarButtonsStateL();
       
   993         return res;
       
   994         }
       
   995     return EKeyWasNotConsumed;
       
   996     }
       
   997 
       
   998 // ---------------------------------------------------------
       
   999 // CIMCVAppViewContainer::Editor
       
  1000 // Handles operation completion
       
  1001 //	
       
  1002 CIMCVAppMessageEditor& CIMCVAppViewContainer::Editor()	const
       
  1003 	{
       
  1004 	return *iMsgEditor;
       
  1005 	}
       
  1006 // ---------------------------------------------------------
       
  1007 // CIMCVAppViewContainer::RefreshEditorL
       
  1008 // Handles operation completion
       
  1009 //
       
  1010 void CIMCVAppViewContainer::RefreshEditorL()
       
  1011     {
       
  1012     //iMsgEditor->Editor().TextView()->HandleCharEditL(CTextLayout::EFCharacterInsert) ;
       
  1013     iMsgEditor->Editor().DrawDeferred();
       
  1014     iAppView.UpdateToolbarButtonsStateL();
       
  1015     }
       
  1016 
       
  1017 // -----------------------------------------------------------------------------
       
  1018 // CIMCVAppSmileIconUtility::LoadBitmapL
       
  1019 // (other items were commented in a header).
       
  1020 // -----------------------------------------------------------------------------
       
  1021 //
       
  1022 CGulIcon* CIMCVAppViewContainer::LoadBitmapL(const TDesC8& /*aId*/,const TInt aBitmapId,const TInt aMaskId)
       
  1023 	{
       
  1024     
       
  1025     IM_CV_LOGS(TXT("CIMCVAppSmileIconUtility::LoadBitmapL() start") );
       
  1026     CFbsBitmap* bitmap = NULL;
       
  1027     CFbsBitmap* mask = NULL;
       
  1028     CGulIcon* gulIcon;
       
  1029     
       
  1030     if(0)
       
  1031         {
       
  1032         /* PPARTH
       
  1033     	TRAPD(err_bitmap, iBrandingAccess->GetBitmapL( aId, bitmap, mask ));
       
  1034 		if(KErrNone != err_bitmap)
       
  1035 			{
       
  1036 			User::Leave( err_bitmap );
       
  1037 			}
       
  1038 		gulIcon = CGulIcon::NewL(bitmap,mask);
       
  1039          */
       
  1040         }
       
  1041     else
       
  1042     	{
       
  1043 		TRgb* aCustomColor = NULL;
       
  1044 
       
  1045 		MAknsSkinInstance* skin = AknsUtils::SkinInstance();	
       
  1046 
       
  1047 		TAknsItemID itemId( KAknsIIDNone );
       
  1048 		TInt colorGroupId( 0 );
       
  1049 
       
  1050 		MapFromBitmapIdToAknsItemId( aBitmapId, itemId, colorGroupId );
       
  1051 
       
  1052 		if( colorGroupId == 0 )
       
  1053 			{
       
  1054 
       
  1055 			// Special case, these icons are using the same color 
       
  1056 			// and color group as text
       
  1057 			if ( aCustomColor )
       
  1058 				{
       
  1059 				// If user has set a special color for text
       
  1060 				AknIconUtils::CreateIconLC( bitmap, mask,  iAppUi->MbmFullPath() , 
       
  1061 				        aBitmapId, aMaskId );                
       
  1062 				AknIconUtils::SetIconColor( bitmap, *aCustomColor );		                                    
       
  1063 				}
       
  1064 			else
       
  1065 				{
       
  1066 				AknsUtils::CreateColorIconLC( skin, 
       
  1067 								itemId, KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG6, 
       
  1068 								bitmap, mask,  iAppUi->MbmFullPath() , 
       
  1069 								aBitmapId, 
       
  1070 								aMaskId, 
       
  1071 								KRgbBlack );		        
       
  1072 				}
       
  1073 		
       
  1074 			}
       
  1075 		else
       
  1076 			{
       
  1077 			AknsUtils::CreateIconLC( skin, 
       
  1078 							itemId, 
       
  1079 							bitmap, mask, iAppUi->MbmFullPath(), 
       
  1080 							aBitmapId,
       
  1081 							aMaskId );    
       
  1082 			}
       
  1083        	gulIcon = CGulIcon::NewL( bitmap, mask );
       
  1084         CleanupStack::Pop( 2 ); // bitmap, mask
       
  1085     	}
       
  1086 
       
  1087        IM_CV_LOGS(TXT("CIMCVAppSmileIconUtility::LoadBitmapL() End") );
       
  1088     return gulIcon;
       
  1089     
       
  1090     }
       
  1091 
       
  1092 
       
  1093 // -----------------------------------------------------------------------------
       
  1094 // CIMCVAppViewContainer::MapFromBitmapIdToAknsItemId
       
  1095 // (other items were commented in a header).
       
  1096 // -----------------------------------------------------------------------------
       
  1097 //
       
  1098 void CIMCVAppViewContainer::MapFromBitmapIdToAknsItemId( TInt aBitmapId, 
       
  1099                                 TAknsItemID& aItemId, TInt& aColorGroupId )
       
  1100 	{
       
  1101     for( TInt i( 0 ); KCABitmaps[i].iBitmapId != KErrNotFound; i++ )
       
  1102         {
       
  1103         if( KCABitmaps[ i ].iBitmapId == aBitmapId )
       
  1104             {
       
  1105             // found it
       
  1106             
       
  1107             aItemId = *(KCABitmaps[ i ].iItemId);
       
  1108             aColorGroupId = KCABitmaps[ i ].iColorGroupId;
       
  1109             return;
       
  1110             }
       
  1111         }
       
  1112     
       
  1113     // not found
       
  1114     
       
  1115     IM_CV_LOGS(TXT("!!!!!!!! every bitmap enumeration should be found from \
       
  1116                   CABitmapMapping.h !!!!!!!! ") );  
       
  1117     
       
  1118     }
       
  1119     
       
  1120 
       
  1121 // ---------------------------------------------------------
       
  1122 // CIMCVAppViewContainer::ResizeIcons
       
  1123 // ---------------------------------------------------------
       
  1124 //
       
  1125 void CIMCVAppViewContainer::ResizeIcons( TRect aParentRect )   
       
  1126     {
       
  1127 	TSize size( aParentRect.Height(), aParentRect.Height() );
       
  1128 	AknIconUtils::SetSize( iFromMe->Bitmap(), size );
       
  1129 	AknIconUtils::SetSize( iToMe->Bitmap(), size );
       
  1130 	
       
  1131 	iMessageExtensionsHandler.SizeChanged( size, iActiveEngine->GetServiceId() );	    
       
  1132     }
       
  1133 
       
  1134 
       
  1135 // ---------------------------------------------------------
       
  1136 // CIMCVAppViewContainer::TextRect
       
  1137 // ---------------------------------------------------------
       
  1138 //    
       
  1139 const TRect CIMCVAppViewContainer::TextRect() const
       
  1140     
       
  1141     {
       
  1142     TAknLayoutRect rp;    
       
  1143     rp.LayoutRect( Rect(), AknLayoutScalable_Apps::im_reading_pane(
       
  1144             TChatListBoxLayout::EWithEditor2Lines ) );
       
  1145     TAknLayoutText text;
       
  1146     text.LayoutText( rp.Rect(),
       
  1147             AknLayoutScalable_Apps::im_reading_pane_t1( 1 ).LayoutLine() );
       
  1148     
       
  1149     return text.TextRect();
       
  1150     }    
       
  1151 
       
  1152 // ---------------------------------------------------------
       
  1153 // CIMCVAppViewContainer::HandleTapEventL()
       
  1154 // (other items were commented in a header).
       
  1155 // ---------------------------------------------------------
       
  1156 //
       
  1157 void CIMCVAppViewContainer::HandleTapEventL( TTapEvent aEvent, 
       
  1158                                                  TUint aControlId )
       
  1159     {
       
  1160     // Handle the tap events which occur in our child controls:
       
  1161     // Message list and Message editor.
       
  1162     switch( aControlId )
       
  1163         {
       
  1164         case EMessageList:
       
  1165             {
       
  1166             // Focused message was double tapped
       
  1167             if( aEvent == MIMCVTapEventObserver::EDoubleTap )
       
  1168                 {
       
  1169                 // To be implemented later
       
  1170                 }
       
  1171             // Message or item was tapped
       
  1172             else if( aEvent == MIMCVTapEventObserver::ESingleTap 
       
  1173                     || aEvent == MIMCVTapEventObserver::EStartTap)
       
  1174                 {
       
  1175                 StopScrollingL();
       
  1176                 // Find objects activate with single tap
       
  1177                 iRecipientObserver->ShowPopUpMenuL();
       
  1178                 }
       
  1179             break;
       
  1180             }
       
  1181         case EMessageEditor:
       
  1182             {
       
  1183             // Nothing to do here ATM.
       
  1184             // Focus transition is handled in HandleControlEventL
       
  1185             iMsgEditor->SetFocus(ETrue, EDrawNow);
       
  1186             iAppView.UpdateToolbarButtonsStateL();
       
  1187             break;
       
  1188             }
       
  1189         default:
       
  1190             {
       
  1191 			break;
       
  1192             }
       
  1193         }
       
  1194     }
       
  1195 
       
  1196 //added for multitab support
       
  1197 
       
  1198 // ---------------------------------------------------------
       
  1199 // CIMCVAppViewContainer::SwitchViewL
       
  1200 // ---------------------------------------------------------
       
  1201 // 
       
  1202 void CIMCVAppViewContainer::SwitchViewL( MIMCVEngineMessageReadInterface* aReadInterface,
       
  1203 											MIMCVEngineMessageWriteInterface*  aWriteInterface,
       
  1204 											const TDesC& aRecipientId )
       
  1205 	{
       
  1206 	if(iEditorMessage)
       
  1207         {
       
  1208         delete iEditorMessage;
       
  1209         iEditorMessage = NULL;  
       
  1210         }
       
  1211     iEditorMessage = iMessageExtensionsHandler.ProcessMessageLC( iMsgEditor->Editor(),iActiveEngine->GetServiceId() );
       
  1212     CleanupStack::Pop();  //  iEditorMessage
       
  1213     iReadInterface->StoreEditerMessageL( *iEditorMessage );
       
  1214     
       
  1215 	//Clears any highlght from the chat before switching away from it
       
  1216     if( iChatView->Highlighted() )
       
  1217         {
       
  1218         iChatView->DisableHighlightL();
       
  1219         } 
       
  1220     
       
  1221 	delete iChatView;
       
  1222 	//iChatView is assigned NULL as NewL may leave
       
  1223 	iChatView = NULL;
       
  1224 	
       
  1225 	iReadInterface = aReadInterface;
       
  1226 	iWriteInterface = aWriteInterface;
       
  1227 	
       
  1228 	delete iRecipientId;
       
  1229 	iRecipientId = NULL;
       
  1230 	iRecipientId = aRecipientId.AllocL();
       
  1231 	
       
  1232 	iChatView = CIMCVAppViewControl::NewL( Rect(),
       
  1233 									*this,
       
  1234 									*iReadInterface,
       
  1235 									iMessageExtensionsHandler,
       
  1236 									iFromMe, 
       
  1237 									iToMe,
       
  1238 									*iRTContainerCache,
       
  1239 									*iActiveEngine );
       
  1240 		                
       
  1241     iChatView->SetObserver( this );        
       
  1242     
       
  1243     // Fix of TSW Bug Id - EJWU-72CB2C
       
  1244     UpdateCbaL(); 
       
  1245     
       
  1246     SizeChanged();
       
  1247     
       
  1248     // Observe tap events
       
  1249     iChatView->SetTapObserver( this, EMessageList );
       
  1250         
       
  1251     iAppUi->LayoutInfo()->SetLayoutID( TChatListBoxLayout::EWithEditor );
       
  1252 	iAppUi->LayoutInfo()->SetEditorVisibility( ETrue );
       
  1253 		
       
  1254 	iActiveEngine->MessageHandler().StartNewConversationL( *iRecipientId );
       
  1255 
       
  1256 	const TDesC& message = iReadInterface->GetEditerMessage();
       
  1257 
       
  1258 	iMsgEditor->SetTextL( message);
       
  1259 
       
  1260 	iAppView.UpdateToolbarButtonsStateL();
       
  1261 	}
       
  1262 
       
  1263 // ---------------------------------------------------------
       
  1264 // CIMCVAppViewContainer::FetchMessages
       
  1265 // ---------------------------------------------------------
       
  1266 //
       
  1267 void CIMCVAppViewContainer::FetchMessages( TBool aFetch )
       
  1268     {
       
  1269     if(iActiveEngine->IsLoggedIn())
       
  1270 	    {
       
  1271     	iChatView->FetchMessages( aFetch );
       
  1272 	    }
       
  1273     }
       
  1274 
       
  1275 // -----------------------------------------------------------------------------
       
  1276 // CIMCVAppViewContainer: StoreEditorMessage
       
  1277 // -----------------------------------------------------------------------------
       
  1278 //TODO: move this function to cimcvappviewcontainer
       
  1279 void CIMCVAppViewContainer::StoreEditorMessageL()
       
  1280     {
       
  1281     // save message typed in the editor.
       
  1282 /*    HBufC* EditorMessage = NULL;
       
  1283     CIMCVAppMessageEditor& MsgEditor = iContainer->Editor();
       
  1284     EditorMessage = iExtensionHandler->ProcessMessageLC( MsgEditor.Editor(), iActiveEngine->GetServiceId() );
       
  1285     
       
  1286     // Getting the readInterface
       
  1287     MIMCVEngineMessageReadInterface& readInterface = 
       
  1288                 iActiveChatInterface->MessageReadInterfaceL( iServiceId, *iRecipientUserId );
       
  1289     readInterface.StoreEditerMessageL( *EditorMessage );
       
  1290     
       
  1291     CleanupStack::PopAndDestroy();// EditorMessage*/
       
  1292     
       
  1293     if(iEditorMessage)
       
  1294         {
       
  1295         delete iEditorMessage;
       
  1296         iEditorMessage = NULL;  
       
  1297         }
       
  1298     iEditorMessage = iMessageExtensionsHandler.ProcessMessageLC( iMsgEditor->Editor(),iActiveEngine->GetServiceId() );
       
  1299     CleanupStack::Pop();  //  iEditorMessage
       
  1300     iReadInterface->StoreEditerMessageL( *iEditorMessage );
       
  1301     }
       
  1302 
       
  1303 
       
  1304 
       
  1305 //  End of File
       
  1306