wvuing/wvuiave/AppSrc/CCAChatViewControl.cpp
branchRCL_3
changeset 13 a941bc465d9f
parent 0 094583676ce7
equal deleted inserted replaced
12:6ca72c0fe49a 13:a941bc465d9f
       
     1 /*
       
     2 * Copyright (c) 2006 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 viewer component
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "CCAChatViewControl.h"
       
    22 #include    "MCAMessageFlowHandlerPC.h"
       
    23 
       
    24 #include    "CCACustomDraw.h"
       
    25 #include    "CCAPicture.h"
       
    26 #include    "CCAAppUi.h"
       
    27 #include    "mcatapeventobserver.h"
       
    28 #include	"MCASettingsPC.h"
       
    29 
       
    30 #include    <AknUtils.h>
       
    31 #include    <aknsettingcache.h>
       
    32 #include    <aknenv.h>
       
    33 #include    <aknconsts.h>
       
    34 #include    <avkon.mbg>
       
    35 #include    <eikrted.h>
       
    36 
       
    37 #include	"MCAProcessManager.h"
       
    38 #include	"IMMessageUtilsPC.h"
       
    39 
       
    40 #include	"MCAMsgAddedToRichTxtCtrlObserver.h"
       
    41 
       
    42 // ============================ MEMBER FUNCTIONS ===============================
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CCAChatViewControl::CCAChatViewControl
       
    46 // C++ default constructor can NOT contain any code, that
       
    47 // might leave.
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 CCAChatViewControl::CCAChatViewControl()
       
    51     {
       
    52     }
       
    53 // -----------------------------------------------------------------------------
       
    54 // CCAChatViewControl::ConstructL
       
    55 // Symbian 2nd phase constructor can leave.
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 void CCAChatViewControl::ConstructL( const TRect& aRect,
       
    59                                      const CCoeControl& aParent,
       
    60                                      MCAGroupPC& aMsgRWInterfacePC,
       
    61                                      MCASettingsPC& aSettingsInterface,
       
    62                                      CCAMessageExtensionsHandler& aExtensionsHandler,
       
    63                                      CGulIcon*& aFromMe,
       
    64                                      CGulIcon*& aToMe,
       
    65                                      CGulIcon*& aUnsupported,
       
    66                                      CGulIcon*& aCorrupted,
       
    67                                      TBool aScrollOver,
       
    68                                      MCAMsgAddedToRichTxtCtrlObserver* aAddMsgObserver )
       
    69     {
       
    70     // get the graphics device
       
    71     CWindowGc& gc = SystemGc();
       
    72     CBitmapDevice* device = static_cast<CBitmapDevice*>( gc.Device() );
       
    73 
       
    74     // text container
       
    75     iTextContainer = CCARichTextContainer::NewL(
       
    76                          static_cast<CCAAppUi&>( *iEikonEnv->AppUi() ),
       
    77                          aSettingsInterface, *this,
       
    78                          aExtensionsHandler,
       
    79                          aFromMe, aToMe, aUnsupported,
       
    80                          aCorrupted,
       
    81                          *device, aScrollOver,
       
    82                          aAddMsgObserver );
       
    83 
       
    84     // construct base class
       
    85     CCATextViewControl::ConstructL( aRect, aParent,
       
    86                                     iTextContainer->TextLayout() );
       
    87 
       
    88     // Initialise flow handler and fetch messages
       
    89     iFlowHandlerPC = IMMessageUtilsPC::CreateInstanceL( *iTextContainer,
       
    90                                                         aMsgRWInterfacePC,
       
    91                                                         !aScrollOver ) ;
       
    92 
       
    93     // We want to handle all the events which occur inside the text area.
       
    94     // Rest is done by the base class.
       
    95     SetPenBehaviour( EPenProcessEvent );
       
    96     }
       
    97 // -----------------------------------------------------------------------------
       
    98 // CCAChatViewControl::ConstructL
       
    99 // Symbian 2nd phase constructor can leave.
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 void CCAChatViewControl::ConstructL( const TRect& aRect,
       
   103                                      const CCoeControl& aParent,
       
   104                                      MCAConversationPC& aMsgRWInterfacePC,
       
   105                                      MCASettingsPC& aSettingsInterface,
       
   106                                      CCAMessageExtensionsHandler& aExtensionsHandler,
       
   107                                      CGulIcon*& aFromMe,
       
   108                                      CGulIcon*& aToMe,
       
   109                                      CGulIcon*& aUnsupported,
       
   110                                      CGulIcon*& aCorrupted,
       
   111                                      TBool aScrollOver,
       
   112                                      MCAMsgAddedToRichTxtCtrlObserver* aAddMsgObserver )
       
   113     {
       
   114     // get the graphics device
       
   115     CWindowGc& gc = SystemGc();
       
   116     CBitmapDevice* device = static_cast<CBitmapDevice*>( gc.Device() );
       
   117 
       
   118     // text container
       
   119     iTextContainer = CCARichTextContainer::NewL(
       
   120                          static_cast<CCAAppUi&>( *iEikonEnv->AppUi() ),
       
   121                          aSettingsInterface, *this,
       
   122                          aExtensionsHandler,
       
   123                          aFromMe, aToMe, aUnsupported,
       
   124                          aCorrupted,
       
   125                          *device, aScrollOver,
       
   126                          aAddMsgObserver );
       
   127 
       
   128     // construct base class
       
   129     CCATextViewControl::ConstructL( aRect, aParent,
       
   130                                     iTextContainer->TextLayout() );
       
   131 
       
   132     // Initialise flow handler and fetch messages
       
   133     iFlowHandlerPC = IMMessageUtilsPC::CreateInstanceL( *iTextContainer,
       
   134                                                         aMsgRWInterfacePC,
       
   135                                                         !aScrollOver ) ;
       
   136 
       
   137     // We want to handle all the events which occur inside the text area.
       
   138     // Rest is done by the base class.
       
   139     SetPenBehaviour( EPenProcessEvent );
       
   140     }
       
   141 
       
   142 void CCAChatViewControl::ConstructL( const TRect& aRect,
       
   143                                      const CCoeControl& aParent,
       
   144                                      MCARecordedChatsPC& aRecordedChatsPC,
       
   145                                      MCASettingsPC& aSettingsInterface,
       
   146                                      CCAMessageExtensionsHandler& aExtensionsHandler,
       
   147                                      CGulIcon*& aFromMe,
       
   148                                      CGulIcon*& aToMe,
       
   149                                      CGulIcon*& aUnsupported,
       
   150                                      CGulIcon*& aCorrupted,
       
   151                                      TBool aScrollOver,
       
   152                                      MCAMsgAddedToRichTxtCtrlObserver* aAddMsgObserver )
       
   153     {
       
   154     // get the graphics device
       
   155     CWindowGc& gc = SystemGc();
       
   156     CBitmapDevice* device = static_cast<CBitmapDevice*>( gc.Device() );
       
   157 
       
   158     // text container
       
   159     iTextContainer = CCARichTextContainer::NewL(
       
   160                          static_cast<CCAAppUi&>( *iEikonEnv->AppUi() ),
       
   161                          aSettingsInterface, *this,
       
   162                          aExtensionsHandler,
       
   163                          aFromMe, aToMe, aUnsupported,
       
   164                          aCorrupted,
       
   165                          *device, aScrollOver, aAddMsgObserver );
       
   166 
       
   167     // construct base class
       
   168     CCATextViewControl::ConstructL( aRect, aParent,
       
   169                                     iTextContainer->TextLayout() );
       
   170 
       
   171     // Initialise flow handler and fetch messages
       
   172     iFlowHandlerPC = IMMessageUtilsPC::CreateInstanceL( *iTextContainer,
       
   173                                                         aRecordedChatsPC,
       
   174                                                         !aScrollOver ) ;
       
   175 
       
   176     // We want to handle all the events which occur inside the text area.
       
   177     // Rest is done by the base class.
       
   178     SetPenBehaviour( EPenProcessEvent );
       
   179     }
       
   180 
       
   181 // -----------------------------------------------------------------------------
       
   182 // CCAChatViewControl::NewL
       
   183 // Two-phased constructor.
       
   184 // -----------------------------------------------------------------------------
       
   185 //
       
   186 CCAChatViewControl* CCAChatViewControl::NewL( const TRect& aRect,
       
   187                                               const CCoeControl& aParent,
       
   188                                               MCAGroupPC& aMsgRWInterfacePC,
       
   189                                               MCASettingsPC& aSettingsInterface,
       
   190                                               CCAMessageExtensionsHandler& aExtensionsHandler,
       
   191                                               CGulIcon*& aFromMe,
       
   192                                               CGulIcon*& aToMe,
       
   193                                               CGulIcon*& aUnsupported,
       
   194                                               CGulIcon*& aCorrupted,
       
   195                                               TBool aScrollOver /*= ETrue*/,
       
   196                                               MCAMsgAddedToRichTxtCtrlObserver* aAddMsgObserver /*=NULL*/ )
       
   197     {
       
   198     CCAChatViewControl* self = new( ELeave ) CCAChatViewControl;
       
   199     CleanupStack::PushL( self );
       
   200     self->ConstructL( aRect, aParent, aMsgRWInterfacePC, aSettingsInterface,
       
   201                       aExtensionsHandler, aFromMe, aToMe,
       
   202                       aUnsupported, aCorrupted,
       
   203                       aScrollOver, aAddMsgObserver );
       
   204     CleanupStack::Pop( self );
       
   205     return self;
       
   206     }
       
   207 
       
   208 // -----------------------------------------------------------------------------
       
   209 // CCAChatViewControl::NewL
       
   210 // Two-phased constructor.
       
   211 // -----------------------------------------------------------------------------
       
   212 //
       
   213 CCAChatViewControl* CCAChatViewControl::NewL( const TRect& aRect,
       
   214                                               const CCoeControl& aParent,
       
   215                                               MCAConversationPC& aMsgRWInterfacePC,
       
   216                                               MCASettingsPC& aSettingsInterface,
       
   217                                               CCAMessageExtensionsHandler& aExtensionsHandler,
       
   218                                               CGulIcon*& aFromMe,
       
   219                                               CGulIcon*& aToMe,
       
   220                                               CGulIcon*& aUnsupported,
       
   221                                               CGulIcon*& aCorrupted,
       
   222                                               TBool aScrollOver /*= ETrue*/,
       
   223                                               MCAMsgAddedToRichTxtCtrlObserver* aAddMsgObserver /*=NULL*/ )
       
   224     {
       
   225     CCAChatViewControl* self = new( ELeave ) CCAChatViewControl;
       
   226     CleanupStack::PushL( self );
       
   227     self->ConstructL( aRect, aParent, aMsgRWInterfacePC, aSettingsInterface,
       
   228                       aExtensionsHandler, aFromMe, aToMe,
       
   229                       aUnsupported, aCorrupted,
       
   230                       aScrollOver, aAddMsgObserver );
       
   231     CleanupStack::Pop( self );
       
   232     return self;
       
   233     }
       
   234 
       
   235 CCAChatViewControl* CCAChatViewControl::NewL( const TRect& aRect,
       
   236                                               const CCoeControl& aParent,
       
   237                                               MCARecordedChatsPC& aRecordedChatsPC,
       
   238                                               MCASettingsPC& aSettingsInterface,
       
   239                                               CCAMessageExtensionsHandler& aExtensionsHandler,
       
   240                                               CGulIcon*& aFromMe,
       
   241                                               CGulIcon*& aToMe,
       
   242                                               CGulIcon*& aUnsupported,
       
   243                                               CGulIcon*& aCorrupted,
       
   244                                               TBool aScrollOver /*= ETrue*/,
       
   245                                               MCAMsgAddedToRichTxtCtrlObserver* aAddMsgObserver /*= NULL*/ )
       
   246     {
       
   247     CCAChatViewControl* self = new( ELeave ) CCAChatViewControl;
       
   248     CleanupStack::PushL( self );
       
   249     self->ConstructL( aRect, aParent, aRecordedChatsPC, aSettingsInterface,
       
   250                       aExtensionsHandler, aFromMe, aToMe,
       
   251                       aUnsupported, aCorrupted,
       
   252                       aScrollOver, aAddMsgObserver );
       
   253     CleanupStack::Pop( self );
       
   254     return self;
       
   255     }
       
   256 
       
   257 
       
   258 // Destructor
       
   259 CCAChatViewControl::~CCAChatViewControl()
       
   260     {
       
   261     delete iTextContainer;
       
   262     delete iFlowHandlerPC;
       
   263     }
       
   264 
       
   265 
       
   266 // -----------------------------------------------------------------------------
       
   267 // CCAChatViewControl::FetchMessages
       
   268 // (other items were commented in a header).
       
   269 // -----------------------------------------------------------------------------
       
   270 //
       
   271 void CCAChatViewControl::FetchMessages( TBool aFetch )
       
   272     {
       
   273     iFlowHandlerPC->FetchMessages( aFetch );
       
   274     }
       
   275 
       
   276 // -----------------------------------------------------------------------------
       
   277 // CCAChatViewControl::SelectedMessage
       
   278 // (other items were commented in a header).
       
   279 // -----------------------------------------------------------------------------
       
   280 //
       
   281 MCAConversationMessage* CCAChatViewControl::SelectedMessage()
       
   282     {
       
   283     return iTextContainer->SelectedMessage();
       
   284     }
       
   285 
       
   286 // -----------------------------------------------------------------------------
       
   287 // CCAChatViewControl::SelectedItem
       
   288 // (other items were commented in a header).
       
   289 // -----------------------------------------------------------------------------
       
   290 //
       
   291 HBufC* CCAChatViewControl::SelectedItemL()
       
   292     {
       
   293     return iTextContainer->SelectedItemL();
       
   294     }
       
   295 
       
   296 // -----------------------------------------------------------------------------
       
   297 // CCAChatViewControl::SelectedItemType
       
   298 // (other items were commented in a header).
       
   299 // -----------------------------------------------------------------------------
       
   300 //
       
   301 TInt CCAChatViewControl::SelectedItemType()
       
   302     {
       
   303     return iTextContainer->SelectedItemType();
       
   304     }
       
   305 
       
   306 // -----------------------------------------------------------------------------
       
   307 // CCAChatViewControl::SetHighlight
       
   308 // (other items were commented in a header).
       
   309 // -----------------------------------------------------------------------------
       
   310 //
       
   311 void CCAChatViewControl::SetHighlight( TBool aHighlight )
       
   312     {
       
   313     iTextContainer->SetItemHighlight( aHighlight );
       
   314     }
       
   315 
       
   316 // -----------------------------------------------------------------------------
       
   317 // CCAChatViewControl::DisableHighlightL
       
   318 // (other items were commented in a header).
       
   319 // -----------------------------------------------------------------------------
       
   320 //
       
   321 void CCAChatViewControl::DisableHighlightL()
       
   322     {
       
   323     iTextContainer->DisableHighlightL();
       
   324     }
       
   325 
       
   326 // -----------------------------------------------------------------------------
       
   327 // CCAChatViewControl::Highlighted
       
   328 // (other items were commented in a header).
       
   329 // -----------------------------------------------------------------------------
       
   330 //
       
   331 TBool CCAChatViewControl::Highlighted()
       
   332     {
       
   333     return iTextContainer->Highlighted();
       
   334     }
       
   335 
       
   336 
       
   337 // -----------------------------------------------------------------------------
       
   338 // CCAChatViewControl::OfferKeyEventL
       
   339 // (other items were commented in a header).
       
   340 // -----------------------------------------------------------------------------
       
   341 //
       
   342 TKeyResponse CCAChatViewControl::OfferKeyEventL( const TKeyEvent& aKeyEvent,
       
   343                                                  TEventCode aType )
       
   344     {
       
   345     if ( aType != EEventKey )
       
   346         {
       
   347         return EKeyWasNotConsumed;
       
   348         }
       
   349 
       
   350     CCARichTextContainer::THighlightMovement movement(
       
   351         CCARichTextContainer::ENext );
       
   352 
       
   353     switch ( aKeyEvent.iCode )
       
   354         {
       
   355         case EKeyUpArrow:
       
   356             {
       
   357             movement = CCARichTextContainer::EPrevious;
       
   358             // flowthrough
       
   359             }
       
   360         case EKeyDownArrow:
       
   361             {
       
   362             return iTextContainer->MoveHighlightL( movement ) == KErrNone ?
       
   363                    EKeyWasConsumed : EKeyWasNotConsumed;
       
   364             }
       
   365 
       
   366         default:
       
   367             {
       
   368             // No handling for other events
       
   369             break;
       
   370             }
       
   371         }
       
   372 
       
   373     return EKeyWasNotConsumed;
       
   374     }
       
   375 
       
   376 // -----------------------------------------------------------------------------
       
   377 // CCAChatViewControl::ProcessStylusEventL
       
   378 // (other items were commented in a header).
       
   379 // -----------------------------------------------------------------------------
       
   380 //
       
   381 void CCAChatViewControl::ProcessStylusEventL(
       
   382     const TPointerEvent& aPointerEvent )
       
   383     {
       
   384     // We end up here only if the pointer event started inside
       
   385     // the text area.
       
   386     if ( aPointerEvent.iType == TPointerEvent::EButton1Down ||
       
   387          aPointerEvent.iType == TPointerEvent::EDrag )
       
   388         {
       
   389         // Reset poiter flags
       
   390         if ( aPointerEvent.iType == TPointerEvent::EButton1Down )
       
   391             {
       
   392             iWaitForDoubleTap = iWaitForSingleTap;
       
   393             iWaitForSingleTap = ETrue;
       
   394             iStylusOutsideMessage = EFalse;
       
   395             }
       
   396 
       
   397         TInt pos = FindDocPos( aPointerEvent.iPosition );
       
   398         if ( pos != KErrNotFound )
       
   399             {
       
   400             TInt res = iTextContainer->HighlightItemAtPosL( pos );
       
   401             if ( res == KErrNone )
       
   402 
       
   403                 {
       
   404                 // New item/message was highlighted
       
   405                 if ( aPointerEvent.iType == TPointerEvent::EDrag )
       
   406                     {
       
   407                     // Single tap is not possible if highlight was changed
       
   408                     // with draging
       
   409                     iWaitForSingleTap = EFalse;
       
   410                     }
       
   411                 // doubletap is not possible for now
       
   412                 iWaitForDoubleTap = EFalse;
       
   413                 }
       
   414             }
       
   415         else
       
   416             {
       
   417             // Stylus was moved/activated outside text elements
       
   418             iStylusOutsideMessage = ETrue;
       
   419             }
       
   420         }
       
   421 
       
   422     // Notify Observers
       
   423     if ( iTapObserver )
       
   424         {
       
   425         if ( aPointerEvent.iType == TPointerEvent::EButton1Down )
       
   426             {
       
   427             // Start
       
   428             iTapObserver->HandleTapEventL(
       
   429                 MCATapEventObserver::EStartTap, iTapControlId );
       
   430             }
       
   431         else if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
       
   432             {
       
   433             // Release
       
   434             iTapObserver->HandleTapEventL(
       
   435                 MCATapEventObserver::EReleaseTap, iTapControlId );
       
   436             if ( iWaitForSingleTap && !iStylusOutsideMessage )
       
   437                 {
       
   438                 // Single tap
       
   439                 iTapObserver->HandleTapEventL(
       
   440                     MCATapEventObserver::ESingleTap, iTapControlId );
       
   441                 }
       
   442             if ( iWaitForDoubleTap && !iStylusOutsideMessage )
       
   443                 {
       
   444                 // Double Tap
       
   445                 iTapObserver->HandleTapEventL(
       
   446                     MCATapEventObserver::EDoubleTap, iTapControlId );
       
   447                 }
       
   448             }
       
   449         }
       
   450     }
       
   451 
       
   452 // -----------------------------------------------------------------------------
       
   453 // CCAChatViewControl::SizeChanged
       
   454 // (other items were commented in a header).
       
   455 // -----------------------------------------------------------------------------
       
   456 //
       
   457 void CCAChatViewControl::SizeChanged()
       
   458     {
       
   459     SetHighlighted( Highlighted() );
       
   460     CCATextViewControl::SizeChanged();
       
   461     }
       
   462 
       
   463 // -----------------------------------------------------------------------------
       
   464 // CCAChatViewControl::MoveHighlightL
       
   465 // (other items were commented in a header).
       
   466 // -----------------------------------------------------------------------------
       
   467 //
       
   468 void CCAChatViewControl::MoveHighlightL(
       
   469     CCARichTextContainer::THighlightMovement aMovement )
       
   470     {
       
   471     iWaitForSingleTap = ETrue;
       
   472     iTextContainer->MoveHighlightL( aMovement );
       
   473     }
       
   474 
       
   475 // -----------------------------------------------------------------------------
       
   476 // CCAChatViewControl::SetTapObserver
       
   477 // (other items were commented in a header).
       
   478 // -----------------------------------------------------------------------------
       
   479 //
       
   480 void CCAChatViewControl::SetTapObserver( MCATapEventObserver* aObserver, TUint aId )
       
   481     {
       
   482     iTapObserver = aObserver;
       
   483     iTapControlId = aId;
       
   484     }
       
   485 
       
   486 // -----------------------------------------------------------------------------
       
   487 // CCAChatViewControl::IsDeleted
       
   488 // (other items were commented in a header).
       
   489 // -----------------------------------------------------------------------------
       
   490 //
       
   491 TBool CCAChatViewControl::IsDeleted() const
       
   492     {
       
   493     return iTextContainer->IsDeleted();
       
   494     }
       
   495 
       
   496 
       
   497 // -----------------------------------------------------------------------------
       
   498 // CCAChatViewControl::GetMessageCount
       
   499 // (other items were commented in a header).
       
   500 // -----------------------------------------------------------------------------
       
   501 //
       
   502 TInt CCAChatViewControl::GetMessageCount()
       
   503     {
       
   504     return iTextContainer->GetMessageCount();
       
   505     }
       
   506 
       
   507 //when user navigate among tab.
       
   508 // -----------------------------------------------------------------------------
       
   509 // CCAChatViewControl::UnRegisterRichTxtCtrlObserver
       
   510 // (other items were commented in a header).
       
   511 // -----------------------------------------------------------------------------
       
   512 //
       
   513 void CCAChatViewControl::UnRegisterRichTxtCtrlObserver()
       
   514     {
       
   515     return iTextContainer->UnRegisterRichTxtCtrlObserver();
       
   516     }
       
   517 
       
   518 //  End of File