os/textandloc/textrendering/textformatting/tbox/FRMSCRND.CPP
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 1997-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 * Description: 
    15 *
    16 */
    17 
    18 
    19 #include "FRMTVIEW.H"
    20 #include "FRMCONST.H"
    21 #include "FORMUTIL.H"
    22 
    23 #include "OstTraceDefinitions.h"
    24 #ifdef OST_TRACE_COMPILER_IN_USE
    25 #include "FRMSCRNDTraces.h"
    26 #endif
    27 
    28 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
    29 #include "FRMCONST_INTERNAL.H"
    30 #include "FRMCONST_PARTNER.H"
    31 #include "TAGMA_INTERNAL.H"
    32 #endif
    33 
    34 RScreenDisplay::RScreenDisplay(TDrawTextLayoutContext* const aDrawTextLayoutContext):
    35 	iSession(NULL),
    36 	iGroupWin(NULL),
    37 	iWin(NULL),
    38 	iGc(NULL),
    39 	iDrawTextLayoutContext(aDrawTextLayoutContext),
    40 	iBackground(KRgbWhite)
    41 	{
    42 	}
    43 
    44 void RScreenDisplay::Close()
    45 	//
    46 	{
    47 
    48 	DestroyContexts();
    49 	}
    50 
    51 void RScreenDisplay::Destroy()
    52 	//
    53 	{
    54 
    55 	Close();
    56 	delete this;
    57 	}
    58 
    59 void RScreenDisplay::DestroyContexts()
    60 	//
    61 	//Destroy the graphics contexts
    62 	//
    63 	{
    64 
    65 	if (iGc)
    66 		delete iGc;
    67 	iGc=NULL;
    68 	}
    69 
    70 void RScreenDisplay::ActivateContext()
    71 	//
    72 	{
    73 	ActivateContext(iGc);
    74 	iBackground = iDrawTextLayoutContext->iBackgroundColor;
    75 	const MFormParam* p = MFormParam::Get();
    76 	FormUtil::LogicalToActualColor(p,iBackground);
    77 	}
    78 
    79 void RScreenDisplay::ActivateContext(CGraphicsContext *aGc)
    80 	//
    81 	//Activate a gc on the current window
    82 	//
    83 	{
    84 	
    85 	//__ASSERT_DEBUG(aGc!=NULL,FormPanic());
    86 	if (iWin)
    87 		((CWindowGc *) aGc)->Activate(*iWin);
    88 	}
    89 
    90 void RScreenDisplay::DeactivateContext()
    91 	//
    92 	{
    93 	DeactivateContext(iGc);
    94 	}
    95 
    96 void RScreenDisplay::DeactivateContext(CGraphicsContext *aGc)
    97 	//
    98 	//Deactivate a gc on the current window
    99 	//
   100 	{
   101 	
   102 	//__ASSERT_DEBUG(aGc!=NULL,FormPanic());
   103 	if (iWin)
   104 		((CWindowGc *) aGc)->Deactivate();
   105 	}
   106 
   107 void RScreenDisplay::CreateContextL()
   108 	//
   109 	//Create and activate the main Graphics Context
   110 	//
   111 	{
   112 	if (iGc)
   113 	    {
   114 	    OstTrace0( TRACE_DUMP, RSCREENDISPLAY_CREATECONTEXTL, "EFGcNotSet" );
   115 	    }
   116 	__ASSERT_DEBUG(iGc==NULL,FormPanic(EFGcNotSet));
   117 	User::LeaveIfError(iGd->CreateBitmapContext(iGc));
   118 	if (iWin)
   119 		iDrawTextLayoutContext->SetWindowGc((CWindowGc *)iGc);
   120 	else
   121 		iDrawTextLayoutContext->SetBitmapGc(iGc);
   122 	}
   123 
   124 void RScreenDisplay::CreateContextL(CBitmapDevice *aGd)
   125 	//
   126 	//Create and activate the main Graphics Context
   127 	//
   128 	{
   129 	CBitmapContext* localGc;
   130 	localGc=NULL;
   131 	//__ASSERT_DEBUG(iGc==NULL,FormPanic(EFGcNotSet));
   132 	User::LeaveIfError(aGd->CreateBitmapContext(localGc));
   133 	delete iGc;
   134 	iGc=NULL;
   135 	iGc=localGc;
   136 	iGd=aGd;
   137 	if (iWin)
   138 		iDrawTextLayoutContext->SetWindowGc((CWindowGc *)iGc);
   139 	else
   140 		iDrawTextLayoutContext->SetBitmapGc(iGc);
   141 	}
   142 
   143 void RScreenDisplay::SetWindow(RWindow *aWin)
   144 	//
   145 	{
   146 
   147 	iWin=aWin;
   148 	}
   149 
   150 void RScreenDisplay::SetGraphicsDeviceL(CBitmapDevice *aGd)
   151 	//
   152 	{
   153 
   154 	//DestroyContexts();
   155 	//iGd=aGd;
   156 	CreateContextL(aGd);
   157 	}
   158 
   159 void RScreenDisplay::SetInvalidRect(const TRect& aRect)
   160 	//
   161 	{
   162 
   163 	iInvalidRect=aRect;
   164 	}
   165 
   166 void RScreenDisplay::SetInvalidRect(TInt aHeight)
   167 	//
   168 	//Set the clipping region to the top or bottom abs(aHeight) pixels of the screen
   169 	//aHeight<0 ==> bottom of the screen
   170 	//
   171 	{
   172 
   173 	iInvalidRect=iDrawTextLayoutContext->iViewRect;
   174 	if (aHeight<0)
   175 		iInvalidRect.iTl.iY=iInvalidRect.iBr.iY+aHeight;
   176 	else
   177 		iInvalidRect.iBr.iY=iInvalidRect.iTl.iY+aHeight;
   178 	}
   179 
   180 void RScreenDisplay::SetInvalidRectHorizontal(TInt aWidth)
   181 	//
   182 	//Set the clipping region to the left or right abs(aHeight) pixels of the screen
   183 	//aWidth<0 ==> right of the screen
   184 	//
   185 	{
   186 
   187 	iInvalidRect=iDrawTextLayoutContext->TextArea(); 
   188 	if (aWidth<0)
   189 		iInvalidRect.iTl.iX=iInvalidRect.iBr.iX+aWidth;
   190 	else
   191 		iInvalidRect.iBr.iX=iInvalidRect.iTl.iX+aWidth;
   192 	}
   193 
   194 void RScreenDisplay::SetRects(TUint aRects)
   195 	//
   196 	//Set the clipping region to the union of rectangles specified in the enum
   197 	//
   198 	{
   199 
   200 	iRects=aRects;
   201 	}
   202 
   203 void RScreenDisplay::AddRects(TUint aRects)
   204 	//
   205 	{
   206 
   207 	iRects|=aRects;
   208 	}
   209 
   210 void RScreenDisplay::SubRects(TUint aRects)
   211 	//
   212 	{
   213 	
   214 	iRects&=EFClipAllFlags-aRects;
   215 	}
   216 
   217 
   218 TRect RScreenDisplay::ClippingRect()
   219 	//
   220 	{
   221 
   222 	TRect clipRect(iDrawTextLayoutContext->iViewRect);
   223 
   224 	if (!(iRects&EFClipViewRect))
   225 		{
   226 		if (iRects&EFClipTextArea)
   227 			clipRect=iDrawTextLayoutContext->TextArea();
   228 		else if (iRects&EFClipLineCursor)
   229 			clipRect=LineCursorMargin();
   230 		if (iRects&EFClipExtendedViewRect && iTextLayout)
   231 			iTextLayout->HighlightExtensions().ExtendRect(clipRect);
   232 		if (iRects&EFClipExtendedTextArea)
   233 			{
   234 			clipRect=iDrawTextLayoutContext->TextArea();
   235 			if (iTextLayout)
   236 				iTextLayout->HighlightExtensions().ExtendRect(clipRect);
   237 			}
   238 		}
   239 	if (iRects&EFClipInvalid)
   240 		clipRect.Intersection(iInvalidRect);
   241 	return clipRect;
   242 	}
   243 
   244 
   245 void RScreenDisplay::ResetClippingRect()
   246 	{
   247 	TRect clipRect=ClippingRect();
   248 	iGc->SetClippingRect(clipRect);
   249 	}
   250 
   251 void RScreenDisplay::BlastBitmap(const TPoint& aPoint,const CFbsBitmap* aBitmap,const TRect& aRect)
   252 	//
   253 	// Blast bitmap to screen
   254 	//
   255 	{
   256 	iGc->BitBlt(aPoint,aBitmap,aRect);
   257 	}
   258 
   259 void RScreenDisplay::DrawPictureFrame(TFrameOverlay* aPictureFrame,const TRect& aLineRect)
   260 	//
   261 	// Draw a frame overlay, using XOR brush. Therefore if frame visible, the frame will disappear,
   262 	// and vice versa.
   263 	//
   264 	{
   265 	TRect clipRect=ClippingRect();
   266 	clipRect.Intersection(aLineRect);
   267 	iGc->SetClippingRect(clipRect);
   268 	iGc->SetPenSize(TSize(1,1));
   269 	aPictureFrame->XorDraw(*iGc);
   270 	ResetClippingRect();
   271     }
   272 
   273 void RScreenDisplay::Invalidate(TRect aRect)
   274 	//
   275     //Invalidate the view rect
   276     //
   277     {
   278 	if (iWin)
   279 		iWin->Invalidate(aRect);
   280     }
   281 
   282 void RScreenDisplay::SetTextCursor(TPoint aPos, const TTextCursor &aCursor)
   283 	//
   284 	//Display a cursor at position aPos
   285 	//
   286 	{
   287 	if (iWin && iGroupWin)
   288 		{
   289 		aPos.iX+=iDrawTextLayoutContext->iTextStartX;
   290 		iGroupWin->SetTextCursor(*iWin,aPos,aCursor,iDrawTextLayoutContext->TextArea());
   291 		}
   292 	}
   293 
   294 void RScreenDisplay::RemoveTextCursor()
   295 	//
   296 	//Remove cursor from window
   297 	//
   298 	{
   299 
   300 	if (iGroupWin)
   301 		iGroupWin->CancelTextCursor();
   302 	}
   303 
   304 void RScreenDisplay::ClearRect(const TRect& aRect)
   305 	//
   306 	//Clear a rectangle on the screen
   307 	//
   308 	{
   309 	if (iTextLayout)
   310 		{
   311 		TPoint top_left = iDrawTextLayoutContext->TopLeftText();
   312 		iTextLayout->DrawBackground(*iGc,top_left,aRect,iBackground);
   313 		ResetClippingRect();
   314 		}
   315 	else
   316 		{
   317 		iGc->SetBrushColor(iBackground);
   318 		iGc->Clear(aRect);
   319 		}
   320 	}
   321 
   322 void RScreenDisplay::InvertRect(TRect aRect,const TRgb aInvertColor)
   323 	{
   324 	aRect.Move(iDrawTextLayoutContext->iTextStartX,0);
   325 	iGc->SetDrawMode(CGraphicsContext::EDrawModeXOR);
   326 	iGc->SetBrushColor(aInvertColor);
   327 	iGc->Clear(aRect);
   328 	iGc->SetBrushColor(iBackground);
   329 	iGc->SetDrawMode(CGraphicsContext::EDrawModePEN);
   330 	}
   331 
   332 void RScreenDisplay::Scroll(TRect aRect,const TPoint& aBy,TBool aScrollBackground)
   333 	{
   334 	if (iWin)
   335 		{
   336 		if (!aScrollBackground || (iTextLayout && iTextLayout->CustomDraw()))
   337 			{
   338 			aRect.Move(aBy);
   339 			iWin->Invalidate(aRect);
   340 			}
   341 		else
   342    			iWin->Scroll(aBy,aRect);
   343 		}
   344 	return;
   345 	}
   346 
   347 void RScreenDisplay::Flush()
   348 	{
   349 	if (iSession)
   350 		iSession->Flush();
   351 	}
   352 
   353 TBool RScreenDisplay::IsLineCursor() const
   354 	{
   355 	return iDrawTextLayoutContext->IsGutterMargin();
   356 	}
   357 
   358 TRect RScreenDisplay::LineCursorMargin() const
   359 	{
   360 	return iDrawTextLayoutContext->GutterMargin();
   361 	}
   362 
   363 TPoint RScreenDisplay::TopLeftTextArea() const
   364 	{
   365 	return iDrawTextLayoutContext->TopLeftTextArea();
   366 	}
   367 
   368 void RScreenDisplay::SetLayout(CTextLayout* aLayout)
   369 	{
   370 	iTextLayout = aLayout;
   371 	iTextLayout->SetWindow(iWin);
   372 	}
   373 
   374 CTextLayout* RScreenDisplay::Layout()
   375 	{
   376 	return iTextLayout;
   377 	}
   378 
   379 TBool RScreenDisplay::UseWindowGc() const
   380 	{
   381 	return iDrawTextLayoutContext->UseWindowGc();
   382 	}