imstutils/imconversationview/imcvuiapp/src/cimcvappviewcontrol.cpp
changeset 0 5e5d6b214f4f
equal deleted inserted replaced
-1:000000000000 0:5e5d6b214f4f
       
     1 /*
       
     2 * Copyright (c) 2007-2008 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:  text view control container 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    "cimcvappviewcontrol.h"
       
    21 
       
    22 #include    "cimcvapprichtextcontainer.h"
       
    23 #include 	"cimcvappui.h"
       
    24 #include	"cimcvappmessageflowhandler.h"
       
    25 #include    <AknUtils.h>
       
    26 #include    <AknSettingCache.h>
       
    27 #include    <aknenv.h>
       
    28 #include    <aknconsts.h>
       
    29 #include    <avkon.mbg>
       
    30 #include    <eikrted.h>
       
    31 #include 	"imcvlogger.h"
       
    32 #include	"mimcvtapeventobserver.h"
       
    33 #include    "mimcvenginemessagesreadinterface.h"
       
    34 #include    "mimcvenginemessagecontainerinfo.h"
       
    35 // ============================ MEMBER FUNCTIONS ===============================
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CIMCVAppViewControl::CIMCVAppViewControl
       
    39 // C++ default constructor can NOT contain any code, that
       
    40 // might leave.
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 CIMCVAppViewControl::CIMCVAppViewControl()
       
    44     {
       
    45     }
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // CIMCVAppViewControl::ConstructL
       
    49 // Symbian 2nd phase constructor can leave.
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 void CIMCVAppViewControl::ConstructL( const TRect& aRect, 
       
    53                         const CCoeControl& aParent,
       
    54                         MIMCVEngineMessageReadInterface& aReadInterface,
       
    55                         CIMCVAppMessageExtensionsHandler& aExtensionsHandler,
       
    56                         CGulIcon* aFromMe,
       
    57                         CGulIcon* aToMe,
       
    58                         CIMCVAppRichTextContainerCache& aRTContainerCache,
       
    59                         CIMCVEngine& aActiveEngine,
       
    60                         TBool aScrollOver )
       
    61     {
       
    62 	IM_CV_LOGS(TXT("CIMCVAppViewContainer::ConstructL() start") );   
       
    63 	 
       
    64 	CWindowGc& gc = SystemGc();
       
    65 	CBitmapDevice* device = static_cast<CBitmapDevice*>( gc.Device() ); 
       
    66 
       
    67 	TInt serviceId = aActiveEngine.GetServiceId();
       
    68 	// text container
       
    69 	// Load the container from the cache
       
    70 	iTextContainer = aRTContainerCache.LoadContainer(serviceId, aReadInterface.TargetId().Target() );
       
    71 	if(NULL == iTextContainer )
       
    72 	    {
       
    73 		//If container not found in cache, create a new and add it to cache
       
    74 	    iTextContainer = CIMCVAppRichTextContainer::NewL(static_cast<CIMCVAppUi*>( iEikonEnv->AppUi() ),
       
    75 	            this, 
       
    76 	            &aExtensionsHandler,
       
    77 	            aFromMe, aToMe,device, 
       
    78 	            aReadInterface.TargetId().Target(),
       
    79 	            serviceId,
       
    80 	            aScrollOver
       
    81 	             );
       
    82 	    
       
    83 	    aRTContainerCache.StoreContainer(iTextContainer);
       
    84 	    }
       
    85 	else
       
    86 	    {
       
    87 		//If container is loaded from the cache, Then Provide it with the Parent's object address
       
    88 	    iTextContainer->Initialize( static_cast<CIMCVAppUi*>( iEikonEnv->AppUi() ),
       
    89                 this, 
       
    90                 &aExtensionsHandler,
       
    91                 aFromMe, aToMe,device, 
       
    92                 aScrollOver );
       
    93 	    }
       
    94 
       
    95 
       
    96 	// construct base class
       
    97 	CIMCVAppTextViewControl::ConstructL( aRect, aParent, 
       
    98 	                                iTextContainer->TextLayout() );
       
    99 
       
   100 	// create flow handler and fetch messages
       
   101 	// Use aScrollOver to determine is this recorded chat or not,
       
   102 	// it is EFalse only with recorded chats.
       
   103 	SetPenBehaviour( EPenProcessEvent );
       
   104 	iFlowHandler = CIMCVAppMessageFlowHandler::NewL( *iTextContainer,
       
   105 												aReadInterface,
       
   106 												aActiveEngine,
       
   107 												!aScrollOver );
       
   108 	IM_CV_LOGS(TXT("CIMCVAppViewContainer::ConstructL() end") );   
       
   109     }
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 // CIMCVAppViewControl::SetTapObserver
       
   113 // (other items were commented in a header).
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 void CIMCVAppViewControl::SetTapObserver( MIMCVTapEventObserver* aObserver, TUint aId )
       
   117     {
       
   118     iTapObserver = aObserver;
       
   119     iTapControlId = aId;
       
   120     }
       
   121 
       
   122 
       
   123 // -----------------------------------------------------------------------------
       
   124 // CIMCVAppViewControl::NewL
       
   125 // Two-phased constructor.
       
   126 // -----------------------------------------------------------------------------
       
   127 //
       
   128 CIMCVAppViewControl* CIMCVAppViewControl::NewL( const TRect& aRect, 
       
   129                         const CCoeControl& aParent,
       
   130                         MIMCVEngineMessageReadInterface& aReadInterface,
       
   131                         CIMCVAppMessageExtensionsHandler& aExtensionsHandler,
       
   132                         CGulIcon* aFromMe,
       
   133                         CGulIcon* aToMe,
       
   134                         CIMCVAppRichTextContainerCache& aRTContainerCache,
       
   135                         CIMCVEngine& aActiveEngine,
       
   136                         TBool aScrollOver /*= ETrue*/ )
       
   137     {
       
   138     IM_CV_LOGS(TXT("CIMCVAppViewContainer::NewL() start") );   
       
   139     CIMCVAppViewControl* self = new( ELeave ) CIMCVAppViewControl;
       
   140     CleanupStack::PushL( self );
       
   141     self->ConstructL( aRect, aParent, aReadInterface,  
       
   142                       aExtensionsHandler,aFromMe, aToMe,aRTContainerCache,
       
   143                       aActiveEngine,
       
   144                       aScrollOver );
       
   145     CleanupStack::Pop( self );
       
   146     IM_CV_LOGS(TXT("CIMCVAppViewContainer::NewL() end") );   
       
   147     return self;
       
   148     }
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 // CIMCVAppViewControl::~CIMCVAppViewControl
       
   152 //  Destructor
       
   153 // -----------------------------------------------------------------------------
       
   154 
       
   155 CIMCVAppViewControl::~CIMCVAppViewControl()
       
   156     {
       
   157     delete iFlowHandler;
       
   158     }
       
   159 
       
   160     
       
   161 
       
   162 // -----------------------------------------------------------------------------
       
   163 // CIMCVAppViewControl::SelectedItem
       
   164 // (other items were commented in a header).
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 HBufC* CIMCVAppViewControl::SelectedItemL()
       
   168     {
       
   169     return iTextContainer->SelectedItemL();
       
   170     }
       
   171     
       
   172 // -----------------------------------------------------------------------------
       
   173 // CIMCVAppViewControl::SelectedItemType
       
   174 // (other items were commented in a header).
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 TInt CIMCVAppViewControl::SelectedItemType()
       
   178     {
       
   179     return iTextContainer->SelectedItemType();
       
   180     }
       
   181 
       
   182 
       
   183 // -----------------------------------------------------------------------------
       
   184 // CIMCVAppViewControl::DisableHighlightL
       
   185 // (other items were commented in a header).
       
   186 // -----------------------------------------------------------------------------
       
   187 //
       
   188 void CIMCVAppViewControl::DisableHighlightL()
       
   189     {
       
   190     IM_CV_LOGS(TXT("CIMCVAppViewContainer::DisableHighlightL()	start") );   
       
   191     iTextContainer->DisableHighlightL();
       
   192     IM_CV_LOGS(TXT("CIMCVAppViewContainer::DisableHighlightL()	end") );   
       
   193     }
       
   194     
       
   195 // -----------------------------------------------------------------------------
       
   196 // CIMCVAppViewControl::Highlighted
       
   197 // (other items were commented in a header).
       
   198 // -----------------------------------------------------------------------------
       
   199 //
       
   200 TBool CIMCVAppViewControl::Highlighted()
       
   201     {
       
   202     IM_CV_LOGS(TXT("CIMCVAppViewContainer::Highlighted()	start") );
       
   203     
       
   204     IM_CV_LOGS(TXT("CIMCVAppViewContainer::Highlighted()	end") );      
       
   205     return iTextContainer->Highlighted();
       
   206     }
       
   207 
       
   208 // -----------------------------------------------------------------------------
       
   209 // CIMCVAppViewControl::SetHighlight
       
   210 // (other items were commented in a header).
       
   211 // -----------------------------------------------------------------------------
       
   212 //
       
   213 void CIMCVAppViewControl::SetHighlight( TBool aHighlight )
       
   214     {
       
   215     iTextContainer->SetItemHighlight( aHighlight );
       
   216     }
       
   217 
       
   218 // -----------------------------------------------------------------------------
       
   219 // CIMCVAppViewControl::OfferKeyEventL
       
   220 // (other items were commented in a header).
       
   221 // -----------------------------------------------------------------------------
       
   222 //
       
   223 TKeyResponse CIMCVAppViewControl::OfferKeyEventL( const TKeyEvent& aKeyEvent, 
       
   224                                                  TEventCode aType )
       
   225     {
       
   226     IM_CV_LOGS(TXT("CIMCVAppViewContainer::OfferKeyEventL()	start") );   
       
   227     if( aType != EEventKey )
       
   228         {
       
   229         return EKeyWasNotConsumed;
       
   230         }
       
   231 
       
   232     CIMCVAppRichTextContainer::THighlightMovement movement( 
       
   233                                                 CIMCVAppRichTextContainer::ENext );
       
   234     
       
   235     switch( aKeyEvent.iCode )
       
   236         {
       
   237         case EKeyUpArrow:
       
   238             {
       
   239             movement = CIMCVAppRichTextContainer::EPrevious;
       
   240             // flowthrough
       
   241 			}
       
   242         case EKeyDownArrow:
       
   243             {                        
       
   244             return iTextContainer->MoveHighlightL( movement ) == KErrNone ? 
       
   245                         EKeyWasConsumed : EKeyWasNotConsumed;
       
   246             }
       
   247 
       
   248         default:
       
   249             {
       
   250             // No handling for other events
       
   251             break;
       
   252             }
       
   253         }
       
   254     IM_CV_LOGS(TXT("CIMCVAppViewContainer::OfferKeyEventL()	end") );   
       
   255     return EKeyWasNotConsumed;
       
   256     }
       
   257 
       
   258 // -----------------------------------------------------------------------------
       
   259 // CIMCVAppViewControl::ProcessStylusEventL
       
   260 // (other items were commented in a header).
       
   261 // -----------------------------------------------------------------------------
       
   262 //
       
   263 void CIMCVAppViewControl::ProcessStylusEventL( 
       
   264     const TPointerEvent& aPointerEvent )
       
   265     {
       
   266     IM_CV_LOGS(TXT("CIMCVAppViewContainer::ProcessStylusEventL()	start") );   
       
   267     // We end up here only if the pointer event started inside
       
   268     // the text area.
       
   269     if( aPointerEvent.iType == TPointerEvent::EButton1Down ||
       
   270         aPointerEvent.iType == TPointerEvent::EDrag )
       
   271         {
       
   272         // Reset poiter flags
       
   273         if( aPointerEvent.iType == TPointerEvent::EButton1Down )
       
   274             {
       
   275             iWaitForDoubleTap = iWaitForSingleTap;
       
   276             iWaitForSingleTap = ETrue;
       
   277              }
       
   278         
       
   279         TInt pos = FindDocPos( aPointerEvent.iPosition );
       
   280         if( pos != KErrNotFound )
       
   281             {
       
   282             TInt res = iTextContainer->HighlightItemAtPosL( pos );
       
   283             if( res == KErrNone )  
       
   284                 
       
   285                 {
       
   286                 // New item/message was highlighted 
       
   287                 if( aPointerEvent.iType == TPointerEvent::EDrag )
       
   288                     {
       
   289                     // Single tap is not possible if highlight was changed
       
   290                     // with draging
       
   291                     iWaitForSingleTap = EFalse;
       
   292                     }
       
   293                 // doubletap is not possible for now
       
   294                 iWaitForDoubleTap = EFalse;
       
   295                 }
       
   296             }
       
   297          }
       
   298     
       
   299     if( iTapObserver )
       
   300         {
       
   301         if( aPointerEvent.iType == TPointerEvent::EButton1Down )
       
   302             {
       
   303             // Start
       
   304             iTapObserver->HandleTapEventL( 
       
   305                 MIMCVTapEventObserver::EStartTap, iTapControlId );
       
   306             }
       
   307         }
       
   308     
       
   309    	IM_CV_LOGS(TXT("CIMCVAppViewContainer::ProcessStylusEventL()	end") );   
       
   310     }
       
   311 
       
   312 // -----------------------------------------------------------------------------
       
   313 // CIMCVAppViewControl::SizeChanged
       
   314 // (other items were commented in a header).
       
   315 // -----------------------------------------------------------------------------
       
   316 //
       
   317 void CIMCVAppViewControl::SizeChanged()
       
   318     {
       
   319     IM_CV_LOGS(TXT("CIMCVAppViewContainer::SizeChanged()	start") );   
       
   320     SetHighlighted( Highlighted() );
       
   321     CIMCVAppTextViewControl::SizeChanged();
       
   322     IM_CV_LOGS(TXT("CIMCVAppViewContainer::SizeChanged()	end") );   
       
   323     }
       
   324 
       
   325 // -----------------------------------------------------------------------------
       
   326 // CIMCVAppViewControl::MoveHighlightL
       
   327 // (other items were commented in a header).
       
   328 // -----------------------------------------------------------------------------
       
   329 //
       
   330 void CIMCVAppViewControl::MoveHighlightL( 
       
   331                             CIMCVAppRichTextContainer::THighlightMovement aMovement)
       
   332     {
       
   333     IM_CV_LOGS(TXT("CIMCVAppViewContainer::MoveHighlightL()	start") );   
       
   334     iWaitForSingleTap = ETrue;
       
   335     iTextContainer->MoveHighlightL( aMovement );
       
   336     IM_CV_LOGS(TXT("CIMCVAppViewContainer::MoveHighlightL()	end") );   
       
   337     }
       
   338 // -----------------------------------------------------------------------------
       
   339 // CIMCVAppViewControl::GetMessageCount
       
   340 // (other items were commented in a header).
       
   341 // -----------------------------------------------------------------------------
       
   342 //
       
   343 TInt CIMCVAppViewControl::GetMessageCount()
       
   344 	{
       
   345 	return iTextContainer->GetMessageCount();	
       
   346 	}
       
   347 
       
   348 // -----------------------------------------------------------------------------
       
   349 // CIMCVAppViewControl::FetchMessages
       
   350 // (other items were commented in a header).
       
   351 // -----------------------------------------------------------------------------
       
   352 //
       
   353 void CIMCVAppViewControl::FetchMessages( TBool aFetch )
       
   354     {
       
   355     iFlowHandler->FetchMessages( aFetch );
       
   356     }
       
   357 
       
   358 //  End of File