imstutils/imconversationview/imcvuiapp/src/cimcvapptextviewcontrol.cpp
changeset 0 5e5d6b214f4f
child 10 78867dafe7eb
equal deleted inserted replaced
-1:000000000000 0:5e5d6b214f4f
       
     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         iScrollBar->TypeOfVScrollBar() == CEikScrollBarFrame::EDoubleSpan )
       
   192         {
       
   193         TAknDoubleSpanScrollBarModel vDsModel( vSbarModel );
       
   194         iScrollBar->Tile( &vDsModel );
       
   195         iScrollBar->SetVFocusPosToThumbPos( vDsModel.FocusPosition());
       
   196         }
       
   197     // ArrowHead
       
   198     else
       
   199         {
       
   200         iScrollBar->Tile( &vSbarModel );
       
   201         iScrollBar->SetVFocusPosToThumbPos( vSbarModel.iThumbPosition );
       
   202         }
       
   203 
       
   204    if( aScrollDraw )
       
   205 		{
       
   206 	    iScrollBar->DrawScrollBarsNow();
       
   207 	   	}
       
   208     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::UpdateScrollBarsL()	end") ); 
       
   209     }
       
   210     
       
   211 void CIMCVAppTextViewControl::UpdateChatViewL ()
       
   212 {
       
   213 	UpdateViewL ();
       
   214 }
       
   215 
       
   216 
       
   217 void CIMCVAppTextViewControl:: SmileyDialogLaunched (TBool aLaunched)
       
   218 {
       
   219 	iSmileyDialogLaunched = aLaunched;
       
   220 }
       
   221     
       
   222 // -----------------------------------------------------------------------------
       
   223 // CIMCVAppTextViewControl::UpdateViewL
       
   224 // (other items were commented in a header).
       
   225 // -----------------------------------------------------------------------------
       
   226 //
       
   227 void CIMCVAppTextViewControl::UpdateViewL()
       
   228     {
       
   229 	// do not refresh if smiley dialog is launched.
       
   230 	if (iSmileyDialogLaunched)
       
   231 		return;
       
   232     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::UpdateViewL()	start") ); 
       
   233     iTextView->FormatTextL();
       
   234     iTextView->SetSelectionVisibilityL( EFalse );
       
   235     TCursorSelection sel;
       
   236     // Don't scroll if some item is highlighted
       
   237     if ( !iIsHighlighted )
       
   238         {
       
   239         sel = TCursorSelection( iLayout->DocumentLength(), 0 );
       
   240         ScrollVisibleL( sel, ETrue );
       
   241          }
       
   242     else
       
   243         {
       
   244         sel = iTextView->Selection();
       
   245         ScrollVisibleL( sel, ETrue );
       
   246          }
       
   247         
       
   248     DrawDeferred();
       
   249     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::UpdateViewL()	end") ); 
       
   250     }
       
   251 
       
   252 // -----------------------------------------------------------------------------
       
   253 // CIMCVAppTextViewControl::SetHighlighted
       
   254 // (other items were commented in a header).
       
   255 // -----------------------------------------------------------------------------
       
   256 //
       
   257 void CIMCVAppTextViewControl::SetHighlighted( TBool aIsHighlighted )
       
   258     {
       
   259     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::SetHighlighted()	start") ); 
       
   260     iIsHighlighted = aIsHighlighted;
       
   261     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::SetHighlighted()	end") ); 
       
   262     }
       
   263 
       
   264 // -----------------------------------------------------------------------------
       
   265 // CIMCVAppTextViewControl::ScrollBarFrame
       
   266 // (other items were commented in a header).
       
   267 // -----------------------------------------------------------------------------
       
   268 //
       
   269 const CEikScrollBarFrame* CIMCVAppTextViewControl::ScrollBarFrame()
       
   270     {
       
   271     return iScrollBar;
       
   272     }
       
   273 
       
   274 // -----------------------------------------------------------------------------
       
   275 // CIMCVAppTextViewControl::ScrollBarFrame
       
   276 // (other items were commented in a header).
       
   277 // -----------------------------------------------------------------------------
       
   278 //
       
   279 TInt CIMCVAppTextViewControl::FindDocPos( TPoint aPoint )
       
   280     {
       
   281     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::FindDocPos()	start") ); 
       
   282     TTmPosInfo2 posInfo;
       
   283     TBool found = EFalse;
       
   284     
       
   285     TRAPD( err, found = iTextView->FindXyPosL( aPoint, posInfo ) );
       
   286     if ( err )
       
   287         {
       
   288         CActiveScheduler::Current()->Error( err );
       
   289         // Return not found
       
   290         return KErrNotFound;
       
   291         }
       
   292         
       
   293     if ( found )
       
   294         {
       
   295   	         
       
   296         return posInfo.iDocPos.iPos;
       
   297         }
       
   298     // not found
       
   299     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::FindDocPos()	end") );
       
   300     return KErrNotFound;
       
   301     }
       
   302     
       
   303 // ---------------------------------------------------------
       
   304 // CIMCVAppTextViewControl::MopSupplyObject
       
   305 //
       
   306 // ---------------------------------------------------------
       
   307 //
       
   308 TTypeUid::Ptr CIMCVAppTextViewControl::MopSupplyObject( TTypeUid aId )
       
   309     {   
       
   310     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::MopSupplyObject()	start") ); 
       
   311     if ( aId.iUid == MAknsControlContext::ETypeId )
       
   312         {
       
   313         return MAknsControlContext::SupplyMopObject( aId, iBgContext );
       
   314         }
       
   315     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::MopSupplyObject()	end") );
       
   316     return CCoeControl::MopSupplyObject( aId );
       
   317     }
       
   318 
       
   319 // ---------------------------------------------------------
       
   320 // CIMCVAppTextViewControl::HandleScrollEventL
       
   321 //
       
   322 // ---------------------------------------------------------
       
   323 //
       
   324 void CIMCVAppTextViewControl::HandleScrollEventL( CEikScrollBar* /*aScrollBar*/,
       
   325                                              TEikScrollEvent aEventType )
       
   326     {
       
   327     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::HandleScrollEventL()	start") ); 
       
   328     switch( aEventType )
       
   329         {
       
   330         case EEikScrollUp:
       
   331             {
       
   332             ScrollLinesL( 1 );
       
   333             break;
       
   334             }
       
   335     	case EEikScrollDown:
       
   336     	    {
       
   337             ScrollLinesL( -1 );
       
   338     	    break;
       
   339     	    }
       
   340     	case EEikScrollPageUp:
       
   341     	    {
       
   342             iTextView->ScrollDisplayL( TCursorPosition::EFPageUp );
       
   343             UpdateScrollBarsL();
       
   344             DrawDeferred();
       
   345     	    break;
       
   346     	    }
       
   347     	case EEikScrollPageDown:
       
   348     	    {
       
   349             iTextView->ScrollDisplayL( TCursorPosition::EFPageDown );
       
   350             UpdateScrollBarsL();
       
   351             DrawDeferred();
       
   352     	    break;
       
   353     	    }
       
   354     	case EEikScrollThumbDragVert:
       
   355     	    {
       
   356     	    // Get position values from scrollbar
       
   357     	    const TEikScrollBarModel* model = 
       
   358     	        iScrollBar->VerticalScrollBar()->Model();
       
   359     	    TInt thumb = model->iThumbPosition;
       
   360             if( CEikScrollBarFrame::EDoubleSpan == 
       
   361                 iScrollBar->TypeOfVScrollBar() )
       
   362                 {
       
   363                 const TAknDoubleSpanScrollBarModel* dsModel = 
       
   364                     static_cast <const TAknDoubleSpanScrollBarModel*>( model );
       
   365                 thumb = dsModel->FocusPosition();
       
   366                 }
       
   367     	    
       
   368     	    // Scroll the textview according to scrollbar
       
   369     	    TViewYPosQualifier yPosQua;
       
   370     	    yPosQua.SetHotSpot( TViewYPosQualifier::EFViewTopOfLine );
       
   371     	    TInt topPos = -thumb;
       
   372     	    iTextView->SetViewL( 0, topPos, yPosQua );
       
   373     	    break;
       
   374     	    }
       
   375     	case EEikScrollThumbReleaseVert:
       
   376     	    {
       
   377     	    // Nothing to do here because EEikScrollThumbDragVert gets 
       
   378     	    // the scrollbar in correct state
       
   379     	    break;
       
   380     	    }
       
   381     	default:
       
   382     	    {
       
   383     	    break;
       
   384     	    }
       
   385         }
       
   386     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::HandleScrollEventL()	end") );
       
   387     }
       
   388 
       
   389 // -----------------------------------------------------------------------------
       
   390 // CIMCVAppTextViewControl::OfferKeyEventL
       
   391 // (other items were commented in a header).
       
   392 // -----------------------------------------------------------------------------
       
   393 //
       
   394 TKeyResponse CIMCVAppTextViewControl::OfferKeyEventL( const TKeyEvent& aKeyEvent, 
       
   395                                                  TEventCode aType )
       
   396     {
       
   397     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::OfferKeyEventL()	start") ); 
       
   398     // Commented because it generates so much log
       
   399     // CHAT_DP( D_CHAT_LIT("CIMCVAppTextViewControl::OfferKeyEventL %d, type %d"), 
       
   400     //          aKeyEvent, aType )
       
   401     
       
   402     if( aType != EEventKey )
       
   403         {
       
   404         return EKeyWasNotConsumed;
       
   405         }
       
   406 
       
   407     switch( aKeyEvent.iCode )
       
   408         {
       
   409         case EKeyDownArrow:
       
   410             {
       
   411 			//scroll lines one line down
       
   412             ScrollLinesL( -1 );
       
   413             return EKeyWasConsumed;
       
   414       
       
   415             }
       
   416         case EKeyUpArrow:
       
   417             {
       
   418 			//scroll lines one line up
       
   419             ScrollLinesL( 1 );
       
   420             return EKeyWasConsumed;
       
   421 
       
   422             }
       
   423         default:
       
   424             {
       
   425             // No handling for other events
       
   426             break;
       
   427             }
       
   428         }
       
   429     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::OfferKeyEventL()	end") );
       
   430     return EKeyWasNotConsumed;
       
   431     }
       
   432 
       
   433 // -----------------------------------------------------------------------------
       
   434 // CIMCVAppTextViewControl::HandlePointerEventL
       
   435 // (other items were commented in a header).
       
   436 // -----------------------------------------------------------------------------
       
   437 //
       
   438 void CIMCVAppTextViewControl::HandlePointerEventL( 
       
   439     const TPointerEvent& aPointerEvent )
       
   440     {
       
   441     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::HandlePointerEventL()	start") ); 
       
   442     
       
   443     if( !IMCVUiAppUtils::PenEnabled() )
       
   444         {
       
   445         return;
       
   446         }
       
   447 
       
   448     switch( iPenType )
       
   449         {
       
   450         case EPenForwardToChild:
       
   451             {
       
   452             // normal (CCoeControl) behaviour
       
   453             CCoeControl::HandlePointerEventL( aPointerEvent );
       
   454             break;
       
   455             }
       
   456         case EPenForwardToParent:
       
   457             {
       
   458             // forward all to parent
       
   459             if( Parent() )
       
   460                 {
       
   461                 Parent()->HandlePointerEventL( aPointerEvent );
       
   462                 }
       
   463             break;
       
   464             }
       
   465         // Process event ourself
       
   466         case EPenProcessEvent:
       
   467             {
       
   468             ProcessStylusEventL( aPointerEvent );
       
   469             break;
       
   470             }
       
   471         case EPenIgnoreEvent:
       
   472             {
       
   473             // Ignore all
       
   474             break;
       
   475             }
       
   476         default:
       
   477             {
       
   478             // Can't be
       
   479             break;
       
   480             }
       
   481         }
       
   482     
       
   483     
       
   484 	IM_CV_LOGS(TXT("CIMCVAppTextViewControl::HandlePointerEventL()	end") );
       
   485     }
       
   486 
       
   487 // -----------------------------------------------------------------------------
       
   488 // CIMCVAppTextViewControl::Draw
       
   489 // (other items were commented in a header).
       
   490 // -----------------------------------------------------------------------------
       
   491 //
       
   492 void CIMCVAppTextViewControl::Draw( const TRect& aRect ) const
       
   493     {
       
   494     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::Draw()	start") ); 
       
   495     CWindowGc& gc = SystemGc();    
       
   496           
       
   497     // Clip text control and scrollbar to prevent flickering
       
   498     gc.SetClippingRegion( *iClipping );
       
   499     
       
   500 	MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   501 	if (iBgContext)
       
   502 		{
       
   503 		// Draw the skin background
       
   504 		AknsDrawUtils::Background(
       
   505 			skin, iBgContext, this, gc, aRect);
       
   506 		}
       
   507 	else
       
   508 		{
       
   509 		// clear the area
       
   510 		gc.SetBrushColor( iEikonEnv->ControlColor( EColorWindowBackground, *this ) );
       
   511 		gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   512 		gc.Clear( aRect );
       
   513 		}		
       
   514     
       
   515     TRAP_IGNORE( iTextView->DrawL( aRect ) );
       
   516     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::Draw()	end") );
       
   517     }
       
   518     
       
   519 // -----------------------------------------------------------------------------
       
   520 // CIMCVAppTextViewControl::SizeChanged
       
   521 // (other items were commented in a header).
       
   522 // -----------------------------------------------------------------------------
       
   523 //
       
   524 void CIMCVAppTextViewControl::SizeChanged()
       
   525     {
       
   526     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::SizeChanged()	start") ); 
       
   527     TAknWindowLineLayout rpLayout( AknLayoutScalable_Apps::list_im_pane( 3 ) );
       
   528     TAknLayoutRect rpLayoutRect;
       
   529     rpLayoutRect.LayoutRect( Rect(), rpLayout );    
       
   530     
       
   531     // update rects
       
   532     iViewRect = rpLayoutRect.Rect();
       
   533     
       
   534     iCustomDraw->SetRect( iViewRect );    
       
   535     iTextView->SetViewRect( iViewRect );
       
   536     iLayout->SetWrapWidth( iViewRect.Width() );
       
   537     
       
   538     if (AknLayoutUtils::DefaultScrollBarType(iAvkonAppUi) == CEikScrollBarFrame::EDoubleSpan)
       
   539         {
       
   540         // For EDoubleSpan type scrollbar
       
   541         TAknWindowLineLayout sbLayout( AknLayoutScalable_Apps::scroll_pane_cp07( 3 ) );
       
   542         AknLayoutUtils::LayoutVerticalScrollBar( iScrollBar, Rect(), sbLayout );
       
   543         TAknLayoutRect sbLayoutRect;
       
   544         sbLayoutRect.LayoutRect( Rect(), sbLayout );
       
   545         }
       
   546     if ( iBgContext )
       
   547         {
       
   548         iBgContext->SetRect( Parent()->Rect() );
       
   549         iBgContext->SetParentPos( Parent()->PositionRelativeToScreen() );
       
   550         }        
       
   551 
       
   552     // Setup clipping region
       
   553     iClipping->Clear();
       
   554     iClipping->AddRect( Rect() );
       
   555     
       
   556     // clip text control
       
   557     iClipping->SubRect( iTextView->ViewRect() );
       
   558  
       
   559     // clip scrollbar
       
   560     if ( iScrollBar->TypeOfVScrollBar() == CEikScrollBarFrame::EDoubleSpan)
       
   561         {    
       
   562 		//fix for the tsw bug id:EKYT-7B68G9 //start.
       
   563         TAknWindowLineLayout sbLayout( AknLayoutScalable_Apps::scroll_pane_cp07( 3 ) );
       
   564         AknLayoutUtils::LayoutVerticalScrollBar( iScrollBar, Rect(), sbLayout );
       
   565         TAknLayoutRect sbLayoutRect;
       
   566         sbLayoutRect.LayoutRect( Rect(), sbLayout );
       
   567         iClipping->SubRect( sbLayoutRect.Rect() );
       
   568 		//fix for the tsw bug id:EKYT-7B68G9 //end.
       
   569         }
       
   570     
       
   571     // and update view
       
   572     TRAPD( err, ScrollLinesL( 0 );
       
   573                 UpdateViewL() );
       
   574     if( err != KErrNone )
       
   575         {
       
   576         CActiveScheduler::Current()->Error( err );
       
   577         }
       
   578 
       
   579     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::SizeChanged()	end") );
       
   580     }
       
   581     
       
   582 // -----------------------------------------------------------------------------
       
   583 // CIMCVAppTextViewControl::HandleFormatChangedL
       
   584 // (other items were commented in a header).
       
   585 // -----------------------------------------------------------------------------
       
   586 //
       
   587 void CIMCVAppTextViewControl::HandleFormatChangedL( TCursorSelection& aChanged, 
       
   588                                                TBool aPreserveFocus /* = EFalse */ )
       
   589     {
       
   590 	if (iSmileyDialogLaunched)
       
   591 		return;
       
   592 
       
   593     // rich text has changed, inform viewer
       
   594     iTextView->SetSelectionVisibilityL( EFalse );
       
   595     
       
   596     if( aPreserveFocus )
       
   597         {
       
   598         // Preserve focus
       
   599         TCursorSelection sel = iTextView->Selection();
       
   600         // This seems to be the only method which doesn't change focus.
       
   601         // --> so it's possible to preserve focus without flicker
       
   602         iTextView->HandleGlobalChangeNoRedrawL();
       
   603         ScrollVisibleL( sel, EFalse );
       
   604         DrawDeferred();
       
   605 
       
   606         }
       
   607     else
       
   608         {
       
   609         // Move focus along with changes
       
   610         iTextView->HandleRangeFormatChangeL( aChanged, ETrue );
       
   611 		//ScrollVisibleL( aChanged, ETrue );
       
   612 		UpdateViewL ();
       
   613         }
       
   614     }
       
   615     
       
   616 // -----------------------------------------------------------------------------
       
   617 // CIMCVAppTextViewControl::HandleInsertDeleteL
       
   618 // (other items were commented in a header).
       
   619 // -----------------------------------------------------------------------------
       
   620 //
       
   621 void CIMCVAppTextViewControl::HandleInsertDeleteL( TCursorSelection& aChanged, 
       
   622                                               TInt aDeletedChars )
       
   623     {
       
   624 	if (iSmileyDialogLaunched)
       
   625 		return;
       
   626 
       
   627     // inform about insertion or deletion
       
   628     iTextView->SetSelectionVisibilityL( EFalse );
       
   629     iTextView->HandleInsertDeleteL( aChanged, aDeletedChars );
       
   630     }
       
   631 
       
   632 // -----------------------------------------------------------------------------
       
   633 // CIMCVAppTextViewControl::HandleAdditionL
       
   634 // (other items were commented in a header).
       
   635 // -----------------------------------------------------------------------------
       
   636 //
       
   637 void CIMCVAppTextViewControl::HandleAdditionL( TBool aFirst, 
       
   638                                           TCursorSelection& aSelection, 
       
   639                                           TBool aTop )
       
   640     {
       
   641     // inform about addition
       
   642     if( aFirst )
       
   643         {
       
   644         iTextView->FormatTextL();
       
   645         }
       
   646     else
       
   647         {
       
   648         iTextView->HandleAdditionalCharactersAtEndL();    
       
   649         } 
       
   650 
       
   651 		// if smiley dialog is launched, then dont draw.
       
   652 		if (iSmileyDialogLaunched)
       
   653 			return;
       
   654 
       
   655 	    ScrollVisibleL( aSelection, aTop );
       
   656 	    DrawDeferred();   
       
   657 		
       
   658     }    
       
   659 
       
   660 // -----------------------------------------------------------------------------
       
   661 // CIMCVAppTextViewControl::ScrollVisibleL
       
   662 // (other items were commented in a header).
       
   663 // -----------------------------------------------------------------------------
       
   664 //
       
   665 void CIMCVAppTextViewControl::ScrollVisibleL( TCursorSelection& aSelection, TBool aTop )
       
   666     {
       
   667     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::ScrollVisibleL()	start") ); 
       
   668 	// if smiley dialog is launched, then dont draw.
       
   669 	if (iSmileyDialogLaunched)
       
   670 		return;
       
   671 		
       
   672 
       
   673 	TCursorSelection sel( aSelection );
       
   674     if( !ParagraphFits( sel.LowerPos() ) )
       
   675         {
       
   676         // selection doesn't fit to screen
       
   677         TInt pos( aTop ? aSelection.LowerPos() : aSelection.HigherPos() );
       
   678         sel.SetSelection( pos, pos );
       
   679         }
       
   680 
       
   681     // scroll selection to screen
       
   682     iTextView->SetSelectionVisibilityL( EFalse );
       
   683     iTextView->SetSelectionL( sel );
       
   684     
       
   685     // and update scroll bars
       
   686     UpdateScrollBarsL();    
       
   687     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::ScrollVisibleL()	end") );
       
   688     }
       
   689     
       
   690 // -----------------------------------------------------------------------------
       
   691 // CIMCVAppTextViewControl::ScrollSelectionL
       
   692 // (other items were commented in a header).
       
   693 // -----------------------------------------------------------------------------
       
   694 //
       
   695 TCursorSelection CIMCVAppTextViewControl::ScrollSelection()
       
   696     {
       
   697     return iTextView->Selection();    
       
   698     }
       
   699     
       
   700     
       
   701 // -----------------------------------------------------------------------------
       
   702 // CIMCVAppTextViewControl::ScrollLinesL
       
   703 // (other items were commented in a header).
       
   704 // -----------------------------------------------------------------------------
       
   705 //
       
   706 void CIMCVAppTextViewControl::ScrollLinesL( TInt aAmount )
       
   707     {
       
   708     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::ScrollLinesL()	start")); 
       
   709     iLayout->ScrollLinesL( aAmount );
       
   710     UpdateScrollBarsL(); 
       
   711     DrawDeferred();
       
   712     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::ScrollLinesL()	end") );
       
   713     }
       
   714 
       
   715 // -----------------------------------------------------------------------------
       
   716 // CIMCVAppTextViewControl::IsVisible
       
   717 // (other items were commented in a header).
       
   718 // -----------------------------------------------------------------------------
       
   719 //
       
   720 TBool CIMCVAppTextViewControl::IsVisible( TInt aPos )
       
   721     {
       
   722     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::IsVisible()		start") ); 
       
   723     TTmDocPos pos( aPos, ETrue );
       
   724     TTmLineInfo lineInfo;
       
   725 
       
   726     if( !iLayout->PosInBand( pos, &lineInfo ) )
       
   727         {
       
   728         // current position outside
       
   729         return EFalse;
       
   730         }
       
   731     
       
   732     if( !ParagraphFits( aPos ) )
       
   733         {
       
   734         // paragraph doesn't fit to screen
       
   735         // extend scrolling one line up and down
       
   736                 
       
   737         // iLineNumber starts from 0 and FirstCharOnLine assumes first line to be 1
       
   738         TInt lineNo( lineInfo.iLineNumber + 1 );
       
   739         
       
   740         // check previous line (if it exists)
       
   741         if( lineNo > 1 )
       
   742             {
       
   743             pos.iPos = iLayout->FirstCharOnLine( lineNo - 1 );
       
   744             
       
   745             if( !iLayout->PosInBand( pos ) )
       
   746                 {
       
   747                 // previous line outside
       
   748                 return EFalse;
       
   749                 }    
       
   750             }
       
   751 
       
   752         // check next line
       
   753         pos.iPos = iLayout->FirstCharOnLine( lineNo + 1 );
       
   754         
       
   755         return iLayout->PosInBand( pos );
       
   756         }
       
   757     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::IsVisible()	end") );
       
   758     return ETrue;
       
   759     }
       
   760     
       
   761 // -----------------------------------------------------------------------------
       
   762 // CIMCVAppTextViewControl::ParagraphFits
       
   763 // (other items were commented in a header).
       
   764 // -----------------------------------------------------------------------------
       
   765 //
       
   766 TBool CIMCVAppTextViewControl::ParagraphFits( TInt aPos )
       
   767     {
       
   768     return iLayout->ParagraphHeight( aPos ) <= iViewRect.Height();
       
   769     }
       
   770 
       
   771 // -----------------------------------------------------------------------------
       
   772 // CIMCVAppTextViewControl::RedrawL
       
   773 // (other items were commented in a header).
       
   774 // -----------------------------------------------------------------------------
       
   775 //
       
   776 void CIMCVAppTextViewControl::Redraw()
       
   777     {
       
   778     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::Redraw()	start" )); 
       
   779     DrawDeferred();
       
   780     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::Redraw()	end" ));
       
   781     }
       
   782 
       
   783 // -----------------------------------------------------------------------------
       
   784 // CIMCVAppTextViewControl::CountComponentControls
       
   785 // -----------------------------------------------------------------------------
       
   786 //
       
   787 TInt CIMCVAppTextViewControl::CountComponentControls() const
       
   788     {
       
   789     if (iScrollBar && iScrollBar->TypeOfVScrollBar() == CEikScrollBarFrame::EDoubleSpan)
       
   790         {    
       
   791         return 1;
       
   792         }
       
   793     else
       
   794         {
       
   795         return 0;
       
   796         }
       
   797     }
       
   798 
       
   799 // -----------------------------------------------------------------------------
       
   800 // CIMCVAppTextViewControl::ComponentControl
       
   801 // -----------------------------------------------------------------------------
       
   802 //
       
   803 CCoeControl* CIMCVAppTextViewControl::ComponentControl(TInt aIndex) const
       
   804     {
       
   805     if (aIndex == 0 && iScrollBar && 
       
   806     	iScrollBar->TypeOfVScrollBar() == CEikScrollBarFrame::EDoubleSpan)
       
   807         {    
       
   808         return iScrollBar->VerticalScrollBar();
       
   809         }
       
   810     else
       
   811         {
       
   812         return NULL;
       
   813         }    
       
   814     }
       
   815 
       
   816 // -----------------------------------------------------------------------------
       
   817 // CIMCVAppTextViewControl::SetPenBehaviour
       
   818 // (other items were commented in a header).
       
   819 // -----------------------------------------------------------------------------
       
   820 //
       
   821 void CIMCVAppTextViewControl::SetPenBehaviour( TPenBehaviour aPen )
       
   822     {
       
   823     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::SetPenBehaviour()	start" )); 
       
   824     iPenType = aPen;
       
   825 	IM_CV_LOGS(TXT("CIMCVAppTextViewControl::SetPenBehaviour()	end" ));
       
   826     }
       
   827 
       
   828 // -----------------------------------------------------------------------------
       
   829 // CIMCVAppTextViewControl::PenBehaviour
       
   830 // (other items were commented in a header).
       
   831 // -----------------------------------------------------------------------------
       
   832 //
       
   833 MIMCVAppTextView::TPenBehaviour CIMCVAppTextViewControl::PenBehaviour()
       
   834     {
       
   835     return iPenType;
       
   836     }
       
   837 
       
   838 // -----------------------------------------------------------------------------
       
   839 // CIMCVAppTextViewControl::ProcessStylusEventL
       
   840 // (other items were commented in a header).
       
   841 // -----------------------------------------------------------------------------
       
   842 //
       
   843 void CIMCVAppTextViewControl::ProcessStylusEventL( 
       
   844     const TPointerEvent& /*aPointerEvent*/ )
       
   845     {
       
   846     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::ProcessStylusEventL()	start" )); 
       
   847     // nothing to do. Let derived classes to handle text selection.
       
   848     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::ProcessStylusEventL()	end" ));
       
   849     }
       
   850 
       
   851 // -----------------------------------------------------------------------------
       
   852 // CIMCVAppTextViewControl::HandleGlobalChangeNoRedrawL
       
   853 // (other items were commented in a header).
       
   854 // -----------------------------------------------------------------------------
       
   855 //
       
   856 void CIMCVAppTextViewControl::HandleGlobalChangeNoRedrawL(
       
   857     TViewYPosQualifier aYPosQualifier /*= TViewYPosQualifier()*/ )
       
   858     {
       
   859     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::HandleGlobalChangeNoRedrawL()	start" )); 
       
   860     iTextView->HandleGlobalChangeNoRedrawL( aYPosQualifier );
       
   861     IM_CV_LOGS(TXT("CIMCVAppTextViewControl::HandleGlobalChangeNoRedrawL()	end" ));
       
   862     }
       
   863     
       
   864 
       
   865 //  End of File