commands/fed/src/textview.cpp
changeset 0 7f656887cf89
child 78 b3ffff030d5c
equal deleted inserted replaced
-1:000000000000 0:7f656887cf89
       
     1 // textview.cpp
       
     2 // 
       
     3 // Copyright (c) 2009 - 2010 Accenture. All rights reserved.
       
     4 // This component and the accompanying materials are made available
       
     5 // under the terms of the "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 // Accenture - Initial contribution
       
    11 //
       
    12 
       
    13 #include <e32cmn.h>
       
    14 #include <e32cons.h>
       
    15 
       
    16 #include "textview.h"
       
    17 #include "filebuffer.h"
       
    18 
       
    19 CTextView::CTextView(MConsoleProvider& aConsoleProvider, CFedBufferBase& aBuffer, TInt aPriority)
       
    20 	: CFedViewBase(aConsoleProvider, aPriority), iBuffer(aBuffer)
       
    21 	{
       
    22 	iBuffer.IncRef();
       
    23 	CActiveScheduler::Add(this);
       
    24 	}
       
    25 
       
    26 void CTextView::ConstructL()
       
    27 	{
       
    28 	User::LeaveIfError(iBuffer.RegisterClient(*this, iDes, iRange, iRangeStartLineNumber));
       
    29 	// Make iLine as big as it will ever need to be
       
    30 	TSize size = iConsole.ScreenSize();
       
    31 	iLine.CreateL(size.iWidth);
       
    32 	}
       
    33 
       
    34 CTextView::~CTextView()
       
    35 	{
       
    36 	Cancel();
       
    37 	iLine.Close();
       
    38 	iBuffer.DecRef();
       
    39 	}
       
    40 
       
    41 void CTextView::DoCancel()
       
    42 	{
       
    43 	ASSERT(EFalse);
       
    44 	}
       
    45 
       
    46 void CTextView::RunL()
       
    47 {
       
    48 	ASSERT(EFalse);
       
    49 /*
       
    50 	if(iStatus.Int() != KErrNone)
       
    51 		return;
       
    52 
       
    53 	//redraw by calling DoDrawL if iDrawPoint is within iWindow and iActive is ETrue
       
    54 	switch(iState)
       
    55 		{
       
    56 		case EStateGetData:
       
    57 			iState = EStateNone;
       
    58 			if(iActive)
       
    59 				DoDrawL();
       
    60 			break;
       
    61 		default:;
       
    62 		}
       
    63 */
       
    64 }
       
    65 
       
    66 TInt CTextView::RunError(TInt aError)
       
    67 {
       
    68 	return aError;
       
    69 }
       
    70 
       
    71 //MViewController
       
    72 void CTextView::ShowCursor()
       
    73 	{
       
    74 	if (iBuffer.Editable())
       
    75 		{
       
    76 		// Don't show a cursor if the file isn't editable
       
    77 		iConsole.SetCursorHeight(20);
       
    78 		}
       
    79 	}
       
    80 
       
    81 void CTextView::HideCursor()
       
    82 	{
       
    83 	iConsole.SetCursorHeight(0);
       
    84 	}
       
    85 
       
    86 void CTextView::ResizeL(const TWindow& aWindow)
       
    87 {
       
    88 	iActive = ETrue;
       
    89 	TWindow oldWindow = iWindow;
       
    90 	StoreWindow(aWindow);
       
    91 	DoResizeL(oldWindow);
       
    92 }
       
    93 
       
    94 void CTextView::RedrawL(const TWindow& aWindow)
       
    95 {
       
    96 	iActive = ETrue;
       
    97 	StoreWindow(aWindow);
       
    98 	DoRedrawL();
       
    99 }
       
   100 
       
   101 void CTextView::DeactivateL()
       
   102 {
       
   103 	iActive = EFalse;
       
   104 }
       
   105 
       
   106 //MSharedCacheClient
       
   107 void CTextView::InvalidateBuffer(TRequestStatus& aStatus)
       
   108 {
       
   109 	aStatus = KRequestPending;
       
   110 	iDes.Set(NULL, 0);
       
   111 	TRequestStatus* stat = &aStatus;
       
   112 	User::RequestComplete(stat, KErrNone);
       
   113 }
       
   114 
       
   115 void CTextView::RequestData(TBool aFromTheTop, TInt aOffset)
       
   116 	{
       
   117 	if (aFromTheTop) iDrawPoint.SetXY(iWindow.iX, iWindow.iY);
       
   118 	TInt err = iBuffer.GetData(*this, aOffset);
       
   119 	if (err)
       
   120 		{
       
   121 		HandleDataLoadError(err);
       
   122 		}
       
   123 	else
       
   124 		{
       
   125 		DoDrawL();
       
   126 		}
       
   127 	}
       
   128 
       
   129 void CTextView::SeekData(TInt aDocumentPosition, TInt aNumLines)
       
   130 	{
       
   131 	if (aDocumentPosition == 0 && aNumLines <= 0)
       
   132 		{
       
   133 		// Nothing to do
       
   134 		return;
       
   135 		}
       
   136 
       
   137 	iDrawPoint.SetXY(iWindow.iX, iWindow.iY); // Seeks always cause a redraw from the top
       
   138 	TInt err = iBuffer.SeekFromOffset(*this, aDocumentPosition, aNumLines, iWindow.iWidth-1); // minus one because we can't use the last char
       
   139 	if (err)
       
   140 		{
       
   141 		HandleDataLoadError(err);
       
   142 		}
       
   143 	else
       
   144 		{
       
   145 		DoDrawL();
       
   146 		}
       
   147 	}
       
   148 
       
   149 void CTextView::UpdateCursor(const TPoint& aNewPos)
       
   150 	{
       
   151 	ASSERT(aNewPos.iX >= 0);
       
   152 	ASSERT(aNewPos.iY >= 0);
       
   153 	iCursor = aNewPos;
       
   154 	ValidateCursor();
       
   155 	if (iActive)
       
   156 		{
       
   157 		ShowCursor();
       
   158 		iConsole.SetCursorPosAbs(iCursor + iWindow.Origin());
       
   159 		}
       
   160 	}
       
   161 
       
   162 void CTextView::ValidateCursor()
       
   163 	{
       
   164 	// Subclasses can override for additional validation
       
   165 	if(iCursor.iX < 0)
       
   166 		iCursor.iX = 0;
       
   167 	if(iCursor.iX >= iWindow.iWidth)
       
   168 		iCursor.iX = iWindow.iWidth - 1;
       
   169 	if(iCursor.iY < 0)
       
   170 		iCursor.iY = 0;
       
   171 	if(iCursor.iY >= iWindow.iHeight)
       
   172 		iCursor.iY = iWindow.iHeight -1;
       
   173 	}
       
   174 
       
   175 CFedBufferBase& CTextView::Buffer()
       
   176 	{
       
   177 	return iBuffer;
       
   178 	}
       
   179 
       
   180 void CTextView::HandleDataLoadError(TInt aError)
       
   181 	{
       
   182 	iConsoleProvider.InfoPrint(_L("Error loading data: %d"), aError);
       
   183 	}