imstutils/imconversationview/imcvuiapp/src/cimcvapptextviewcontrol.cpp
branchRCL_3
changeset 23 9a48e301e94b
equal deleted inserted replaced
22:3104fc151679 23:9a48e301e94b
       
     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 
       
    21 // INCLUDE FILES
       
    22 #include    "cimcvapptextviewcontrol.h"
       
    23 
       
    24 #include 	"cimcvappcustomdraw.h"
       
    25 #include    <frmtview.h>    // CTextView
       
    26 #include    <AknUtils.h>
       
    27 #include    <avkon.mbg>
       
    28 #include    <aknappui.h>
       
    29 #include 	"mimcvapptextview.h"
       
    30 #include    <aknlayoutscalable_apps.cdl.h>
       
    31 #include    <AknsBasicBackgroundControlContext.h>
       
    32 #include    <AknsDrawUtils.h>
       
    33 #include 	"imcvlogger.h"
       
    34 #include 	"imcvuiapputils.h"
       
    35 
       
    36 // ============================ MEMBER FUNCTIONS ===============================
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // CIMCVAppTextViewControl::CIMCVAppTextViewControl
       
    40 // C++ default constructor can NOT contain any code, that
       
    41 // might leave.
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 CIMCVAppTextViewControl::CIMCVAppTextViewControl() 
       
    45     {
       
    46     }
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CIMCVAppTextViewControl::ConstructL
       
    50 // Symbian 2nd phase constructor can leave.
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 void CIMCVAppTextViewControl::ConstructL( const TRect& aRect, 
       
    54                                      const CCoeControl& aParent,
       
    55                                      MLayDoc* aTextLayout )
       
    56     {
       
    57     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::ConstructL()	start") ); 
       
    58     CreateWindowL( &aParent );
       
    59     
       
    60     // get the drawing device
       
    61     CWindowGc& gc = SystemGc();
       
    62     CBitmapDevice* device = static_cast<CBitmapDevice*>( gc.Device() );    
       
    63     
       
    64     // create text layout and text view
       
    65 
       
    66     iViewRect = aRect;
       
    67     iClipping = new ( ELeave ) RRegion( aRect );
       
    68     
       
    69     iLayout = CTextLayout::NewL( aTextLayout, iViewRect.Width() );
       
    70     iTextView = CTextView::NewL( iLayout, iViewRect,
       
    71                 device, device, &Window(), NULL, &iCoeEnv->WsSession() );
       
    72 
       
    73     iTextView->EnableFlickerFreeRedraw();
       
    74     iTextView->SetOpaque( ETrue );    
       
    75     
       
    76     // create our background drawer
       
    77     iCustomDraw = new( ELeave )CIMCVAppCustomDraw( iViewRect );
       
    78     iLayout->SetCustomDraw( iCustomDraw );
       
    79 
       
    80     // and scrollbar
       
    81     if( IMCVUiAppUtils::PenEnabled() )
       
    82         {
       
    83         // Observer
       
    84         iScrollBar = new( ELeave )CEikScrollBarFrame( this, this );
       
    85         }
       
    86     else
       
    87         {
       
    88         // No observer
       
    89         iScrollBar = new( ELeave )CEikScrollBarFrame( this, NULL );
       
    90         }
       
    91       
       
    92    
       
    93     if (AknLayoutUtils::DefaultScrollBarType(iAvkonAppUi) == CEikScrollBarFrame::EDoubleSpan)
       
    94         { 
       
    95         
       
    96         // For EDoubleSpan type scrollbar
       
    97         // If pen is supported, SB needs to own a window
       
    98         iScrollBar->CreateDoubleSpanScrollBarsL( IMCVUiAppUtils::PenEnabled(), 
       
    99                                                  EFalse, ETrue, EFalse );
       
   100         iScrollBar->SetTypeOfVScrollBar(CEikScrollBarFrame::EDoubleSpan);
       
   101         
       
   102         }
       
   103     else
       
   104         {
       
   105         // For EArrowHead type scrollbar
       
   106         iScrollBar->SetTypeOfVScrollBar(CEikScrollBarFrame::EArrowHead);
       
   107         }
       
   108     iScrollBar->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff, 
       
   109                                          CEikScrollBarFrame::EOn );
       
   110     TEikScrollBarModel vSbarModel;
       
   111     vSbarModel.iThumbPosition = 0; // current position
       
   112     vSbarModel.iScrollSpan = 0; // how many items
       
   113     vSbarModel.iThumbSpan = 0; // ignored
       
   114 
       
   115     iScrollBar->Tile( &vSbarModel );
       
   116     iScrollBar->SetVFocusPosToThumbPos( vSbarModel.iThumbPosition );
       
   117     
       
   118     iBgContext = CAknsBasicBackgroundControlContext::NewL( 
       
   119         KAknsIIDQsnBgAreaMain, Rect(), ETrue );
       
   120     iCustomDraw->SetBackgroundContext( iBgContext, this );
       
   121     
       
   122     // set extensions
       
   123     ActivateL();    
       
   124     
       
   125     // we're ready
       
   126     static_cast<CCoeAppUi*>( iEikonEnv->AppUi() )->AddToStackL( this );
       
   127     iAddedToStack = ETrue;
       
   128     
       
   129     // Enable draging
       
   130     if ( DrawableWindow() && IMCVUiAppUtils::PenEnabled() )
       
   131         {
       
   132         EnableDragEvents();       
       
   133         Window().SetPointerGrab( ETrue );
       
   134         }
       
   135         
       
   136     // Enable draging
       
   137     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::ConstructL()	end") ); 
       
   138     }
       
   139 
       
   140 
       
   141 // Destructor
       
   142 CIMCVAppTextViewControl::~CIMCVAppTextViewControl()
       
   143     {
       
   144     if( iAddedToStack )
       
   145         {
       
   146         static_cast<CCoeAppUi*>( iEikonEnv->AppUi() )->RemoveFromStack( this );
       
   147         }
       
   148 
       
   149     delete iScrollBar;
       
   150     delete iCustomDraw;
       
   151     delete iTextView;
       
   152     delete iLayout;
       
   153     
       
   154     delete iBgContext;
       
   155     if( iClipping )
       
   156         {
       
   157         iClipping->Destroy();
       
   158         iClipping  = NULL;
       
   159         }
       
   160     }
       
   161 
       
   162 // -----------------------------------------------------------------------------
       
   163 // CIMCVAppTextViewControl::UpdateScrollBarsL
       
   164 // (other items were commented in a header).
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 void CIMCVAppTextViewControl::UpdateScrollBarsL( TBool aScrollDraw /*ETrue*/ )
       
   168     {
       
   169     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::UpdateScrollBarsL()	start") ); 
       
   170     TInt height = iLayout->FormattedHeightInPixels();
       
   171     TInt span = iViewRect.Height();
       
   172     TInt pos = iLayout->PixelsAboveBand();
       
   173     
       
   174     if( span < 0 )
       
   175         {
       
   176         span = 0;
       
   177         }
       
   178         
       
   179     if( pos < 0 )
       
   180         {
       
   181         pos = 0;
       
   182         }
       
   183 
       
   184     TEikScrollBarModel vSbarModel;
       
   185     vSbarModel.iThumbPosition = pos; // current position
       
   186     vSbarModel.iScrollSpan = height; // total length
       
   187     vSbarModel.iThumbSpan = span; // bar length
       
   188 
       
   189     // Double span
       
   190     if( iScrollBar )
       
   191         {
       
   192         if ( iScrollBar->TypeOfVScrollBar() == CEikScrollBarFrame::EDoubleSpan )
       
   193             {
       
   194             TAknDoubleSpanScrollBarModel vDsModel( vSbarModel );
       
   195             iScrollBar->Tile( &vDsModel );
       
   196             iScrollBar->SetVFocusPosToThumbPos( vDsModel.FocusPosition());
       
   197             }
       
   198         // ArrowHead
       
   199         else
       
   200             {
       
   201             iScrollBar->Tile( &vSbarModel );
       
   202             iScrollBar->SetVFocusPosToThumbPos( vSbarModel.iThumbPosition );
       
   203             }
       
   204        if( aScrollDraw )
       
   205             {
       
   206             iScrollBar->DrawScrollBarsNow();
       
   207             }
       
   208         }
       
   209     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::UpdateScrollBarsL()	end") ); 
       
   210     }
       
   211     
       
   212 void CIMCVAppTextViewControl::UpdateChatViewL ()
       
   213 {
       
   214 	UpdateViewL ();
       
   215 }
       
   216 
       
   217 
       
   218 void CIMCVAppTextViewControl:: SmileyDialogLaunched (TBool aLaunched)
       
   219 {
       
   220 	iSmileyDialogLaunched = aLaunched;
       
   221 }
       
   222     
       
   223 // -----------------------------------------------------------------------------
       
   224 // CIMCVAppTextViewControl::UpdateViewL
       
   225 // (other items were commented in a header).
       
   226 // -----------------------------------------------------------------------------
       
   227 //
       
   228 void CIMCVAppTextViewControl::UpdateViewL()
       
   229     {
       
   230 	// do not refresh if smiley dialog is launched.
       
   231 	if (iSmileyDialogLaunched)
       
   232 		return;
       
   233     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::UpdateViewL()	start") ); 
       
   234     iTextView->FormatTextL();
       
   235     iTextView->SetSelectionVisibilityL( EFalse );
       
   236     TCursorSelection sel;
       
   237     // Don't scroll if some item is highlighted
       
   238     if ( !iIsHighlighted )
       
   239         {
       
   240         sel = TCursorSelection( iLayout->DocumentLength(), 0 );
       
   241         ScrollVisibleL( sel, ETrue );
       
   242          }
       
   243     else
       
   244         {
       
   245         sel = iTextView->Selection();
       
   246         ScrollVisibleL( sel, ETrue );
       
   247          }
       
   248         
       
   249     DrawDeferred();
       
   250     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::UpdateViewL()	end") ); 
       
   251     }
       
   252 
       
   253 // -----------------------------------------------------------------------------
       
   254 // CIMCVAppTextViewControl::SetHighlighted
       
   255 // (other items were commented in a header).
       
   256 // -----------------------------------------------------------------------------
       
   257 //
       
   258 void CIMCVAppTextViewControl::SetHighlighted( TBool aIsHighlighted )
       
   259     {
       
   260     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::SetHighlighted()	start") ); 
       
   261     iIsHighlighted = aIsHighlighted;
       
   262     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::SetHighlighted()	end") ); 
       
   263     }
       
   264 
       
   265 // -----------------------------------------------------------------------------
       
   266 // CIMCVAppTextViewControl::ScrollBarFrame
       
   267 // (other items were commented in a header).
       
   268 // -----------------------------------------------------------------------------
       
   269 //
       
   270 const CEikScrollBarFrame* CIMCVAppTextViewControl::ScrollBarFrame()
       
   271     {
       
   272     return iScrollBar;
       
   273     }
       
   274 
       
   275 // -----------------------------------------------------------------------------
       
   276 // CIMCVAppTextViewControl::ScrollBarFrame
       
   277 // (other items were commented in a header).
       
   278 // -----------------------------------------------------------------------------
       
   279 //
       
   280 TInt CIMCVAppTextViewControl::FindDocPos( TPoint aPoint )
       
   281     {
       
   282     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::FindDocPos()	start") ); 
       
   283     TTmPosInfo2 posInfo;
       
   284     TBool found = EFalse;
       
   285     
       
   286     TRAPD( err, found = iTextView->FindXyPosL( aPoint, posInfo ) );
       
   287     if ( err )
       
   288         {
       
   289         CActiveScheduler::Current()->Error( err );
       
   290         // Return not found
       
   291         return KErrNotFound;
       
   292         }
       
   293         
       
   294     if ( found )
       
   295         {
       
   296   	         
       
   297         return posInfo.iDocPos.iPos;
       
   298         }
       
   299     // not found
       
   300     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::FindDocPos()	end") );
       
   301     return KErrNotFound;
       
   302     }
       
   303     
       
   304 // ---------------------------------------------------------
       
   305 // CIMCVAppTextViewControl::MopSupplyObject
       
   306 //
       
   307 // ---------------------------------------------------------
       
   308 //
       
   309 TTypeUid::Ptr CIMCVAppTextViewControl::MopSupplyObject( TTypeUid aId )
       
   310     {   
       
   311     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::MopSupplyObject()	start") ); 
       
   312     if ( aId.iUid == MAknsControlContext::ETypeId )
       
   313         {
       
   314         return MAknsControlContext::SupplyMopObject( aId, iBgContext );
       
   315         }
       
   316     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::MopSupplyObject()	end") );
       
   317     return CCoeControl::MopSupplyObject( aId );
       
   318     }
       
   319 
       
   320 // ---------------------------------------------------------
       
   321 // CIMCVAppTextViewControl::HandleScrollEventL
       
   322 //
       
   323 // ---------------------------------------------------------
       
   324 //
       
   325 void CIMCVAppTextViewControl::HandleScrollEventL( CEikScrollBar* /*aScrollBar*/,
       
   326                                              TEikScrollEvent aEventType )
       
   327     {
       
   328     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::HandleScrollEventL()	start") ); 
       
   329     switch( aEventType )
       
   330         {
       
   331         case EEikScrollUp:
       
   332             {
       
   333             ScrollLinesL( 1 );
       
   334             break;
       
   335             }
       
   336     	case EEikScrollDown:
       
   337     	    {
       
   338             ScrollLinesL( -1 );
       
   339     	    break;
       
   340     	    }
       
   341     	case EEikScrollPageUp:
       
   342     	    {
       
   343             iTextView->ScrollDisplayL( TCursorPosition::EFPageUp );
       
   344             UpdateScrollBarsL();
       
   345             DrawDeferred();
       
   346     	    break;
       
   347     	    }
       
   348     	case EEikScrollPageDown:
       
   349     	    {
       
   350             iTextView->ScrollDisplayL( TCursorPosition::EFPageDown );
       
   351             UpdateScrollBarsL();
       
   352             DrawDeferred();
       
   353     	    break;
       
   354     	    }
       
   355     	case EEikScrollThumbDragVert:
       
   356     	    {
       
   357     	    // Get position values from scrollbar
       
   358     	    const TEikScrollBarModel* model = 
       
   359     	        iScrollBar->VerticalScrollBar()->Model();
       
   360     	    TInt thumb = model->iThumbPosition;
       
   361             if( CEikScrollBarFrame::EDoubleSpan == 
       
   362                 iScrollBar->TypeOfVScrollBar() )
       
   363                 {
       
   364                 const TAknDoubleSpanScrollBarModel* dsModel = 
       
   365                     static_cast <const TAknDoubleSpanScrollBarModel*>( model );
       
   366                 thumb = dsModel->FocusPosition();
       
   367                 }
       
   368     	    
       
   369     	    // Scroll the textview according to scrollbar
       
   370     	    TViewYPosQualifier yPosQua;
       
   371     	    yPosQua.SetHotSpot( TViewYPosQualifier::EFViewTopOfLine );
       
   372     	    TInt topPos = -thumb;
       
   373     	    iTextView->SetViewL( 0, topPos, yPosQua );
       
   374     	    break;
       
   375     	    }
       
   376     	case EEikScrollThumbReleaseVert:
       
   377     	    {
       
   378     	    // Nothing to do here because EEikScrollThumbDragVert gets 
       
   379     	    // the scrollbar in correct state
       
   380     	    break;
       
   381     	    }
       
   382     	default:
       
   383     	    {
       
   384     	    break;
       
   385     	    }
       
   386         }
       
   387     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::HandleScrollEventL()	end") );
       
   388     }
       
   389 
       
   390 // -----------------------------------------------------------------------------
       
   391 // CIMCVAppTextViewControl::OfferKeyEventL
       
   392 // (other items were commented in a header).
       
   393 // -----------------------------------------------------------------------------
       
   394 //
       
   395 TKeyResponse CIMCVAppTextViewControl::OfferKeyEventL( const TKeyEvent& aKeyEvent, 
       
   396                                                  TEventCode aType )
       
   397     {
       
   398     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::OfferKeyEventL()	start") ); 
       
   399     // Commented because it generates so much log
       
   400     // CHAT_DP( D_CHAT_LIT("CIMCVAppTextViewControl::OfferKeyEventL %d, type %d"), 
       
   401     //          aKeyEvent, aType )
       
   402     
       
   403     if( aType != EEventKey )
       
   404         {
       
   405         return EKeyWasNotConsumed;
       
   406         }
       
   407 
       
   408     switch( aKeyEvent.iCode )
       
   409         {
       
   410         case EKeyDownArrow:
       
   411             {
       
   412 			//scroll lines one line down
       
   413             ScrollLinesL( -1 );
       
   414             return EKeyWasConsumed;
       
   415       
       
   416             }
       
   417         case EKeyUpArrow:
       
   418             {
       
   419 			//scroll lines one line up
       
   420             ScrollLinesL( 1 );
       
   421             return EKeyWasConsumed;
       
   422 
       
   423             }
       
   424         default:
       
   425             {
       
   426             // No handling for other events
       
   427             break;
       
   428             }
       
   429         }
       
   430     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::OfferKeyEventL()	end") );
       
   431     return EKeyWasNotConsumed;
       
   432     }
       
   433 
       
   434 // -----------------------------------------------------------------------------
       
   435 // CIMCVAppTextViewControl::HandlePointerEventL
       
   436 // (other items were commented in a header).
       
   437 // -----------------------------------------------------------------------------
       
   438 //
       
   439 void CIMCVAppTextViewControl::HandlePointerEventL( 
       
   440     const TPointerEvent& aPointerEvent )
       
   441     {
       
   442     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::HandlePointerEventL()	start") ); 
       
   443     
       
   444     if( !IMCVUiAppUtils::PenEnabled() )
       
   445         {
       
   446         return;
       
   447         }
       
   448 
       
   449     switch( iPenType )
       
   450         {
       
   451         case EPenForwardToChild:
       
   452             {
       
   453             // normal (CCoeControl) behaviour
       
   454             CCoeControl::HandlePointerEventL( aPointerEvent );
       
   455             break;
       
   456             }
       
   457         case EPenForwardToParent:
       
   458             {
       
   459             // forward all to parent
       
   460             if( Parent() )
       
   461                 {
       
   462                 Parent()->HandlePointerEventL( aPointerEvent );
       
   463                 }
       
   464             break;
       
   465             }
       
   466         // Process event ourself
       
   467         case EPenProcessEvent:
       
   468             {
       
   469             ProcessStylusEventL( aPointerEvent );
       
   470             break;
       
   471             }
       
   472         case EPenIgnoreEvent:
       
   473             {
       
   474             // Ignore all
       
   475             break;
       
   476             }
       
   477         default:
       
   478             {
       
   479             // Can't be
       
   480             break;
       
   481             }
       
   482         }
       
   483     
       
   484     
       
   485 	IM_CV_LOGS(TXT("CIMCVAppTextViewControl::HandlePointerEventL()	end") );
       
   486     }
       
   487 
       
   488 // -----------------------------------------------------------------------------
       
   489 // CIMCVAppTextViewControl::Draw
       
   490 // (other items were commented in a header).
       
   491 // -----------------------------------------------------------------------------
       
   492 //
       
   493 void CIMCVAppTextViewControl::Draw( const TRect& aRect ) const
       
   494     {
       
   495     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::Draw()	start") ); 
       
   496     CWindowGc& gc = SystemGc();    
       
   497           
       
   498     // Clip text control and scrollbar to prevent flickering
       
   499     gc.SetClippingRegion( *iClipping );
       
   500     
       
   501 	MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   502 	if (iBgContext)
       
   503 		{
       
   504 		// Draw the skin background
       
   505 		AknsDrawUtils::Background(
       
   506 			skin, iBgContext, this, gc, aRect);
       
   507 		}
       
   508 	else
       
   509 		{
       
   510 		// clear the area
       
   511 		gc.SetBrushColor( iEikonEnv->ControlColor( EColorWindowBackground, *this ) );
       
   512 		gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   513 		gc.Clear( aRect );
       
   514 		}		
       
   515     
       
   516     TRAP_IGNORE( iTextView->DrawL( aRect ) );
       
   517     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::Draw()	end") );
       
   518     }
       
   519     
       
   520 // -----------------------------------------------------------------------------
       
   521 // CIMCVAppTextViewControl::SizeChanged
       
   522 // (other items were commented in a header).
       
   523 // -----------------------------------------------------------------------------
       
   524 //
       
   525 void CIMCVAppTextViewControl::SizeChanged()
       
   526     {
       
   527     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::SizeChanged()	start") ); 
       
   528     TAknWindowLineLayout rpLayout( AknLayoutScalable_Apps::list_im_pane( 3 ) );
       
   529     TAknLayoutRect rpLayoutRect;
       
   530     rpLayoutRect.LayoutRect( Rect(), rpLayout );    
       
   531     
       
   532     // update rects
       
   533     iViewRect = rpLayoutRect.Rect();
       
   534     
       
   535     iCustomDraw->SetRect( iViewRect );    
       
   536     iTextView->SetViewRect( iViewRect );
       
   537     iLayout->SetWrapWidth( iViewRect.Width() );
       
   538     
       
   539     if (AknLayoutUtils::DefaultScrollBarType(iAvkonAppUi) == CEikScrollBarFrame::EDoubleSpan)
       
   540         {
       
   541         // For EDoubleSpan type scrollbar
       
   542         TAknWindowLineLayout sbLayout( AknLayoutScalable_Apps::scroll_pane_cp07( 3 ) );
       
   543         AknLayoutUtils::LayoutVerticalScrollBar( iScrollBar, Rect(), sbLayout );
       
   544         TAknLayoutRect sbLayoutRect;
       
   545         sbLayoutRect.LayoutRect( Rect(), sbLayout );
       
   546         }
       
   547     if ( iBgContext )
       
   548         {
       
   549         iBgContext->SetRect( Parent()->Rect() );
       
   550         iBgContext->SetParentPos( Parent()->PositionRelativeToScreen() );
       
   551         }        
       
   552 
       
   553     // Setup clipping region
       
   554     iClipping->Clear();
       
   555     iClipping->AddRect( Rect() );
       
   556     
       
   557     // clip text control
       
   558     iClipping->SubRect( iTextView->ViewRect() );
       
   559  
       
   560     // clip scrollbar
       
   561     if ( iScrollBar->TypeOfVScrollBar() == CEikScrollBarFrame::EDoubleSpan)
       
   562         {    
       
   563 		//fix for the tsw bug id:EKYT-7B68G9 //start.
       
   564         TAknWindowLineLayout sbLayout( AknLayoutScalable_Apps::scroll_pane_cp07( 3 ) );
       
   565         AknLayoutUtils::LayoutVerticalScrollBar( iScrollBar, Rect(), sbLayout );
       
   566         TAknLayoutRect sbLayoutRect;
       
   567         sbLayoutRect.LayoutRect( Rect(), sbLayout );
       
   568         iClipping->SubRect( sbLayoutRect.Rect() );
       
   569 		//fix for the tsw bug id:EKYT-7B68G9 //end.
       
   570         }
       
   571     
       
   572     // and update view
       
   573     TRAPD( err, ScrollLinesL( 0 );
       
   574                 UpdateViewL() );
       
   575     if( err != KErrNone )
       
   576         {
       
   577         CActiveScheduler::Current()->Error( err );
       
   578         }
       
   579 
       
   580     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::SizeChanged()	end") );
       
   581     }
       
   582     
       
   583 // -----------------------------------------------------------------------------
       
   584 // CIMCVAppTextViewControl::HandleFormatChangedL
       
   585 // (other items were commented in a header).
       
   586 // -----------------------------------------------------------------------------
       
   587 //
       
   588 void CIMCVAppTextViewControl::HandleFormatChangedL( TCursorSelection& aChanged, 
       
   589                                                TBool aPreserveFocus /* = EFalse */ )
       
   590     {
       
   591 	if (iSmileyDialogLaunched)
       
   592 		return;
       
   593 
       
   594     // rich text has changed, inform viewer
       
   595     iTextView->SetSelectionVisibilityL( EFalse );
       
   596     
       
   597     if( aPreserveFocus )
       
   598         {
       
   599         // Preserve focus
       
   600         TCursorSelection sel = iTextView->Selection();
       
   601         // This seems to be the only method which doesn't change focus.
       
   602         // --> so it's possible to preserve focus without flicker
       
   603         iTextView->HandleGlobalChangeNoRedrawL();
       
   604         ScrollVisibleL( sel, EFalse );
       
   605         DrawDeferred();
       
   606 
       
   607         }
       
   608     else
       
   609         {
       
   610         // Move focus along with changes
       
   611         iTextView->HandleRangeFormatChangeL( aChanged, ETrue );
       
   612 		//ScrollVisibleL( aChanged, ETrue );
       
   613 		UpdateViewL ();
       
   614         }
       
   615     }
       
   616     
       
   617 // -----------------------------------------------------------------------------
       
   618 // CIMCVAppTextViewControl::HandleInsertDeleteL
       
   619 // (other items were commented in a header).
       
   620 // -----------------------------------------------------------------------------
       
   621 //
       
   622 void CIMCVAppTextViewControl::HandleInsertDeleteL( TCursorSelection& aChanged, 
       
   623                                               TInt aDeletedChars )
       
   624     {
       
   625 	if (iSmileyDialogLaunched)
       
   626 		return;
       
   627 
       
   628     // inform about insertion or deletion
       
   629     iTextView->SetSelectionVisibilityL( EFalse );
       
   630     iTextView->HandleInsertDeleteL( aChanged, aDeletedChars );
       
   631     }
       
   632 
       
   633 // -----------------------------------------------------------------------------
       
   634 // CIMCVAppTextViewControl::HandleAdditionL
       
   635 // (other items were commented in a header).
       
   636 // -----------------------------------------------------------------------------
       
   637 //
       
   638 void CIMCVAppTextViewControl::HandleAdditionL( TBool aFirst, 
       
   639                                           TCursorSelection& aSelection, 
       
   640                                           TBool aTop )
       
   641     {
       
   642     // inform about addition
       
   643     if( aFirst )
       
   644         {
       
   645         iTextView->FormatTextL();
       
   646         }
       
   647     else
       
   648         {
       
   649         iTextView->HandleAdditionalCharactersAtEndL();    
       
   650         } 
       
   651 
       
   652 		// if smiley dialog is launched, then dont draw.
       
   653 		if (iSmileyDialogLaunched)
       
   654 			return;
       
   655 
       
   656 	    ScrollVisibleL( aSelection, aTop );
       
   657 	    DrawDeferred();   
       
   658 		
       
   659     }    
       
   660 
       
   661 // -----------------------------------------------------------------------------
       
   662 // CIMCVAppTextViewControl::ScrollVisibleL
       
   663 // (other items were commented in a header).
       
   664 // -----------------------------------------------------------------------------
       
   665 //
       
   666 void CIMCVAppTextViewControl::ScrollVisibleL( TCursorSelection& aSelection, TBool aTop )
       
   667     {
       
   668     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::ScrollVisibleL()	start") ); 
       
   669 	// if smiley dialog is launched, then dont draw.
       
   670 	if (iSmileyDialogLaunched)
       
   671 		return;
       
   672 		
       
   673 
       
   674 	TCursorSelection sel( aSelection );
       
   675     if( !ParagraphFits( sel.LowerPos() ) )
       
   676         {
       
   677         // selection doesn't fit to screen
       
   678         TInt pos( aTop ? aSelection.LowerPos() : aSelection.HigherPos() );
       
   679         sel.SetSelection( pos, pos );
       
   680         }
       
   681 
       
   682     // scroll selection to screen
       
   683     iTextView->SetSelectionVisibilityL( EFalse );
       
   684     iTextView->SetSelectionL( sel );
       
   685     
       
   686     // and update scroll bars
       
   687     UpdateScrollBarsL();    
       
   688     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::ScrollVisibleL()	end") );
       
   689     }
       
   690     
       
   691 // -----------------------------------------------------------------------------
       
   692 // CIMCVAppTextViewControl::ScrollSelectionL
       
   693 // (other items were commented in a header).
       
   694 // -----------------------------------------------------------------------------
       
   695 //
       
   696 TCursorSelection CIMCVAppTextViewControl::ScrollSelection()
       
   697     {
       
   698     return iTextView->Selection();    
       
   699     }
       
   700     
       
   701     
       
   702 // -----------------------------------------------------------------------------
       
   703 // CIMCVAppTextViewControl::ScrollLinesL
       
   704 // (other items were commented in a header).
       
   705 // -----------------------------------------------------------------------------
       
   706 //
       
   707 void CIMCVAppTextViewControl::ScrollLinesL( TInt aAmount )
       
   708     {
       
   709     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::ScrollLinesL()	start")); 
       
   710     iLayout->ScrollLinesL( aAmount );
       
   711     UpdateScrollBarsL(); 
       
   712     DrawDeferred();
       
   713     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::ScrollLinesL()	end") );
       
   714     }
       
   715 
       
   716 // -----------------------------------------------------------------------------
       
   717 // CIMCVAppTextViewControl::IsVisible
       
   718 // (other items were commented in a header).
       
   719 // -----------------------------------------------------------------------------
       
   720 //
       
   721 TBool CIMCVAppTextViewControl::IsVisible( TInt aPos )
       
   722     {
       
   723     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::IsVisible()		start") ); 
       
   724     TTmDocPos pos( aPos, ETrue );
       
   725     TTmLineInfo lineInfo;
       
   726 
       
   727     if( !iLayout->PosInBand( pos, &lineInfo ) )
       
   728         {
       
   729         // current position outside
       
   730         return EFalse;
       
   731         }
       
   732     
       
   733     if( !ParagraphFits( aPos ) )
       
   734         {
       
   735         // paragraph doesn't fit to screen
       
   736         // extend scrolling one line up and down
       
   737                 
       
   738         // iLineNumber starts from 0 and FirstCharOnLine assumes first line to be 1
       
   739         TInt lineNo( lineInfo.iLineNumber + 1 );
       
   740         
       
   741         // check previous line (if it exists)
       
   742         if( lineNo > 1 )
       
   743             {
       
   744             pos.iPos = iLayout->FirstCharOnLine( lineNo - 1 );
       
   745             
       
   746             if( !iLayout->PosInBand( pos ) )
       
   747                 {
       
   748                 // previous line outside
       
   749                 return EFalse;
       
   750                 }    
       
   751             }
       
   752 
       
   753         // check next line
       
   754         pos.iPos = iLayout->FirstCharOnLine( lineNo + 1 );
       
   755         
       
   756         return iLayout->PosInBand( pos );
       
   757         }
       
   758     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::IsVisible()	end") );
       
   759     return ETrue;
       
   760     }
       
   761     
       
   762 // -----------------------------------------------------------------------------
       
   763 // CIMCVAppTextViewControl::ParagraphFits
       
   764 // (other items were commented in a header).
       
   765 // -----------------------------------------------------------------------------
       
   766 //
       
   767 TBool CIMCVAppTextViewControl::ParagraphFits( TInt aPos )
       
   768     {
       
   769     return iLayout->ParagraphHeight( aPos ) <= iViewRect.Height();
       
   770     }
       
   771 
       
   772 // -----------------------------------------------------------------------------
       
   773 // CIMCVAppTextViewControl::RedrawL
       
   774 // (other items were commented in a header).
       
   775 // -----------------------------------------------------------------------------
       
   776 //
       
   777 void CIMCVAppTextViewControl::Redraw()
       
   778     {
       
   779     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::Redraw()	start" )); 
       
   780     DrawDeferred();
       
   781     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::Redraw()	end" ));
       
   782     }
       
   783 
       
   784 // -----------------------------------------------------------------------------
       
   785 // CIMCVAppTextViewControl::CountComponentControls
       
   786 // -----------------------------------------------------------------------------
       
   787 //
       
   788 TInt CIMCVAppTextViewControl::CountComponentControls() const
       
   789     {
       
   790     if (iScrollBar && iScrollBar->TypeOfVScrollBar() == CEikScrollBarFrame::EDoubleSpan)
       
   791         {    
       
   792         return 1;
       
   793         }
       
   794     else
       
   795         {
       
   796         return 0;
       
   797         }
       
   798     }
       
   799 
       
   800 // -----------------------------------------------------------------------------
       
   801 // CIMCVAppTextViewControl::ComponentControl
       
   802 // -----------------------------------------------------------------------------
       
   803 //
       
   804 CCoeControl* CIMCVAppTextViewControl::ComponentControl(TInt aIndex) const
       
   805     {
       
   806     if (aIndex == 0 && iScrollBar && 
       
   807     	iScrollBar->TypeOfVScrollBar() == CEikScrollBarFrame::EDoubleSpan)
       
   808         {    
       
   809         return iScrollBar->VerticalScrollBar();
       
   810         }
       
   811     else
       
   812         {
       
   813         return NULL;
       
   814         }    
       
   815     }
       
   816 
       
   817 // -----------------------------------------------------------------------------
       
   818 // CIMCVAppTextViewControl::SetPenBehaviour
       
   819 // (other items were commented in a header).
       
   820 // -----------------------------------------------------------------------------
       
   821 //
       
   822 void CIMCVAppTextViewControl::SetPenBehaviour( TPenBehaviour aPen )
       
   823     {
       
   824     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::SetPenBehaviour()	start" )); 
       
   825     iPenType = aPen;
       
   826 	IM_CV_LOGS(TXT("CIMCVAppTextViewControl::SetPenBehaviour()	end" ));
       
   827     }
       
   828 
       
   829 // -----------------------------------------------------------------------------
       
   830 // CIMCVAppTextViewControl::PenBehaviour
       
   831 // (other items were commented in a header).
       
   832 // -----------------------------------------------------------------------------
       
   833 //
       
   834 MIMCVAppTextView::TPenBehaviour CIMCVAppTextViewControl::PenBehaviour()
       
   835     {
       
   836     return iPenType;
       
   837     }
       
   838 
       
   839 // -----------------------------------------------------------------------------
       
   840 // CIMCVAppTextViewControl::ProcessStylusEventL
       
   841 // (other items were commented in a header).
       
   842 // -----------------------------------------------------------------------------
       
   843 //
       
   844 void CIMCVAppTextViewControl::ProcessStylusEventL( 
       
   845     const TPointerEvent& /*aPointerEvent*/ )
       
   846     {
       
   847     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::ProcessStylusEventL()	start" )); 
       
   848     // nothing to do. Let derived classes to handle text selection.
       
   849     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::ProcessStylusEventL()	end" ));
       
   850     }
       
   851 
       
   852 // -----------------------------------------------------------------------------
       
   853 // CIMCVAppTextViewControl::HandleGlobalChangeNoRedrawL
       
   854 // (other items were commented in a header).
       
   855 // -----------------------------------------------------------------------------
       
   856 //
       
   857 void CIMCVAppTextViewControl::HandleGlobalChangeNoRedrawL(
       
   858     TViewYPosQualifier aYPosQualifier /*= TViewYPosQualifier()*/ )
       
   859     {
       
   860     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::HandleGlobalChangeNoRedrawL()	start" )); 
       
   861     iTextView->HandleGlobalChangeNoRedrawL( aYPosQualifier );
       
   862     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::HandleGlobalChangeNoRedrawL()	end" ));
       
   863     }
       
   864     
       
   865 
       
   866 //  End of File