os/textandloc/textrendering/textformatting/tbox/FRMSCRND.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/textandloc/textrendering/textformatting/tbox/FRMSCRND.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,382 @@
     1.4 +/*
     1.5 +* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +#include "FRMTVIEW.H"
    1.23 +#include "FRMCONST.H"
    1.24 +#include "FORMUTIL.H"
    1.25 +
    1.26 +#include "OstTraceDefinitions.h"
    1.27 +#ifdef OST_TRACE_COMPILER_IN_USE
    1.28 +#include "FRMSCRNDTraces.h"
    1.29 +#endif
    1.30 +
    1.31 +#ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
    1.32 +#include "FRMCONST_INTERNAL.H"
    1.33 +#include "FRMCONST_PARTNER.H"
    1.34 +#include "TAGMA_INTERNAL.H"
    1.35 +#endif
    1.36 +
    1.37 +RScreenDisplay::RScreenDisplay(TDrawTextLayoutContext* const aDrawTextLayoutContext):
    1.38 +	iSession(NULL),
    1.39 +	iGroupWin(NULL),
    1.40 +	iWin(NULL),
    1.41 +	iGc(NULL),
    1.42 +	iDrawTextLayoutContext(aDrawTextLayoutContext),
    1.43 +	iBackground(KRgbWhite)
    1.44 +	{
    1.45 +	}
    1.46 +
    1.47 +void RScreenDisplay::Close()
    1.48 +	//
    1.49 +	{
    1.50 +
    1.51 +	DestroyContexts();
    1.52 +	}
    1.53 +
    1.54 +void RScreenDisplay::Destroy()
    1.55 +	//
    1.56 +	{
    1.57 +
    1.58 +	Close();
    1.59 +	delete this;
    1.60 +	}
    1.61 +
    1.62 +void RScreenDisplay::DestroyContexts()
    1.63 +	//
    1.64 +	//Destroy the graphics contexts
    1.65 +	//
    1.66 +	{
    1.67 +
    1.68 +	if (iGc)
    1.69 +		delete iGc;
    1.70 +	iGc=NULL;
    1.71 +	}
    1.72 +
    1.73 +void RScreenDisplay::ActivateContext()
    1.74 +	//
    1.75 +	{
    1.76 +	ActivateContext(iGc);
    1.77 +	iBackground = iDrawTextLayoutContext->iBackgroundColor;
    1.78 +	const MFormParam* p = MFormParam::Get();
    1.79 +	FormUtil::LogicalToActualColor(p,iBackground);
    1.80 +	}
    1.81 +
    1.82 +void RScreenDisplay::ActivateContext(CGraphicsContext *aGc)
    1.83 +	//
    1.84 +	//Activate a gc on the current window
    1.85 +	//
    1.86 +	{
    1.87 +	
    1.88 +	//__ASSERT_DEBUG(aGc!=NULL,FormPanic());
    1.89 +	if (iWin)
    1.90 +		((CWindowGc *) aGc)->Activate(*iWin);
    1.91 +	}
    1.92 +
    1.93 +void RScreenDisplay::DeactivateContext()
    1.94 +	//
    1.95 +	{
    1.96 +	DeactivateContext(iGc);
    1.97 +	}
    1.98 +
    1.99 +void RScreenDisplay::DeactivateContext(CGraphicsContext *aGc)
   1.100 +	//
   1.101 +	//Deactivate a gc on the current window
   1.102 +	//
   1.103 +	{
   1.104 +	
   1.105 +	//__ASSERT_DEBUG(aGc!=NULL,FormPanic());
   1.106 +	if (iWin)
   1.107 +		((CWindowGc *) aGc)->Deactivate();
   1.108 +	}
   1.109 +
   1.110 +void RScreenDisplay::CreateContextL()
   1.111 +	//
   1.112 +	//Create and activate the main Graphics Context
   1.113 +	//
   1.114 +	{
   1.115 +	if (iGc)
   1.116 +	    {
   1.117 +	    OstTrace0( TRACE_DUMP, RSCREENDISPLAY_CREATECONTEXTL, "EFGcNotSet" );
   1.118 +	    }
   1.119 +	__ASSERT_DEBUG(iGc==NULL,FormPanic(EFGcNotSet));
   1.120 +	User::LeaveIfError(iGd->CreateBitmapContext(iGc));
   1.121 +	if (iWin)
   1.122 +		iDrawTextLayoutContext->SetWindowGc((CWindowGc *)iGc);
   1.123 +	else
   1.124 +		iDrawTextLayoutContext->SetBitmapGc(iGc);
   1.125 +	}
   1.126 +
   1.127 +void RScreenDisplay::CreateContextL(CBitmapDevice *aGd)
   1.128 +	//
   1.129 +	//Create and activate the main Graphics Context
   1.130 +	//
   1.131 +	{
   1.132 +	CBitmapContext* localGc;
   1.133 +	localGc=NULL;
   1.134 +	//__ASSERT_DEBUG(iGc==NULL,FormPanic(EFGcNotSet));
   1.135 +	User::LeaveIfError(aGd->CreateBitmapContext(localGc));
   1.136 +	delete iGc;
   1.137 +	iGc=NULL;
   1.138 +	iGc=localGc;
   1.139 +	iGd=aGd;
   1.140 +	if (iWin)
   1.141 +		iDrawTextLayoutContext->SetWindowGc((CWindowGc *)iGc);
   1.142 +	else
   1.143 +		iDrawTextLayoutContext->SetBitmapGc(iGc);
   1.144 +	}
   1.145 +
   1.146 +void RScreenDisplay::SetWindow(RWindow *aWin)
   1.147 +	//
   1.148 +	{
   1.149 +
   1.150 +	iWin=aWin;
   1.151 +	}
   1.152 +
   1.153 +void RScreenDisplay::SetGraphicsDeviceL(CBitmapDevice *aGd)
   1.154 +	//
   1.155 +	{
   1.156 +
   1.157 +	//DestroyContexts();
   1.158 +	//iGd=aGd;
   1.159 +	CreateContextL(aGd);
   1.160 +	}
   1.161 +
   1.162 +void RScreenDisplay::SetInvalidRect(const TRect& aRect)
   1.163 +	//
   1.164 +	{
   1.165 +
   1.166 +	iInvalidRect=aRect;
   1.167 +	}
   1.168 +
   1.169 +void RScreenDisplay::SetInvalidRect(TInt aHeight)
   1.170 +	//
   1.171 +	//Set the clipping region to the top or bottom abs(aHeight) pixels of the screen
   1.172 +	//aHeight<0 ==> bottom of the screen
   1.173 +	//
   1.174 +	{
   1.175 +
   1.176 +	iInvalidRect=iDrawTextLayoutContext->iViewRect;
   1.177 +	if (aHeight<0)
   1.178 +		iInvalidRect.iTl.iY=iInvalidRect.iBr.iY+aHeight;
   1.179 +	else
   1.180 +		iInvalidRect.iBr.iY=iInvalidRect.iTl.iY+aHeight;
   1.181 +	}
   1.182 +
   1.183 +void RScreenDisplay::SetInvalidRectHorizontal(TInt aWidth)
   1.184 +	//
   1.185 +	//Set the clipping region to the left or right abs(aHeight) pixels of the screen
   1.186 +	//aWidth<0 ==> right of the screen
   1.187 +	//
   1.188 +	{
   1.189 +
   1.190 +	iInvalidRect=iDrawTextLayoutContext->TextArea(); 
   1.191 +	if (aWidth<0)
   1.192 +		iInvalidRect.iTl.iX=iInvalidRect.iBr.iX+aWidth;
   1.193 +	else
   1.194 +		iInvalidRect.iBr.iX=iInvalidRect.iTl.iX+aWidth;
   1.195 +	}
   1.196 +
   1.197 +void RScreenDisplay::SetRects(TUint aRects)
   1.198 +	//
   1.199 +	//Set the clipping region to the union of rectangles specified in the enum
   1.200 +	//
   1.201 +	{
   1.202 +
   1.203 +	iRects=aRects;
   1.204 +	}
   1.205 +
   1.206 +void RScreenDisplay::AddRects(TUint aRects)
   1.207 +	//
   1.208 +	{
   1.209 +
   1.210 +	iRects|=aRects;
   1.211 +	}
   1.212 +
   1.213 +void RScreenDisplay::SubRects(TUint aRects)
   1.214 +	//
   1.215 +	{
   1.216 +	
   1.217 +	iRects&=EFClipAllFlags-aRects;
   1.218 +	}
   1.219 +
   1.220 +
   1.221 +TRect RScreenDisplay::ClippingRect()
   1.222 +	//
   1.223 +	{
   1.224 +
   1.225 +	TRect clipRect(iDrawTextLayoutContext->iViewRect);
   1.226 +
   1.227 +	if (!(iRects&EFClipViewRect))
   1.228 +		{
   1.229 +		if (iRects&EFClipTextArea)
   1.230 +			clipRect=iDrawTextLayoutContext->TextArea();
   1.231 +		else if (iRects&EFClipLineCursor)
   1.232 +			clipRect=LineCursorMargin();
   1.233 +		if (iRects&EFClipExtendedViewRect && iTextLayout)
   1.234 +			iTextLayout->HighlightExtensions().ExtendRect(clipRect);
   1.235 +		if (iRects&EFClipExtendedTextArea)
   1.236 +			{
   1.237 +			clipRect=iDrawTextLayoutContext->TextArea();
   1.238 +			if (iTextLayout)
   1.239 +				iTextLayout->HighlightExtensions().ExtendRect(clipRect);
   1.240 +			}
   1.241 +		}
   1.242 +	if (iRects&EFClipInvalid)
   1.243 +		clipRect.Intersection(iInvalidRect);
   1.244 +	return clipRect;
   1.245 +	}
   1.246 +
   1.247 +
   1.248 +void RScreenDisplay::ResetClippingRect()
   1.249 +	{
   1.250 +	TRect clipRect=ClippingRect();
   1.251 +	iGc->SetClippingRect(clipRect);
   1.252 +	}
   1.253 +
   1.254 +void RScreenDisplay::BlastBitmap(const TPoint& aPoint,const CFbsBitmap* aBitmap,const TRect& aRect)
   1.255 +	//
   1.256 +	// Blast bitmap to screen
   1.257 +	//
   1.258 +	{
   1.259 +	iGc->BitBlt(aPoint,aBitmap,aRect);
   1.260 +	}
   1.261 +
   1.262 +void RScreenDisplay::DrawPictureFrame(TFrameOverlay* aPictureFrame,const TRect& aLineRect)
   1.263 +	//
   1.264 +	// Draw a frame overlay, using XOR brush. Therefore if frame visible, the frame will disappear,
   1.265 +	// and vice versa.
   1.266 +	//
   1.267 +	{
   1.268 +	TRect clipRect=ClippingRect();
   1.269 +	clipRect.Intersection(aLineRect);
   1.270 +	iGc->SetClippingRect(clipRect);
   1.271 +	iGc->SetPenSize(TSize(1,1));
   1.272 +	aPictureFrame->XorDraw(*iGc);
   1.273 +	ResetClippingRect();
   1.274 +    }
   1.275 +
   1.276 +void RScreenDisplay::Invalidate(TRect aRect)
   1.277 +	//
   1.278 +    //Invalidate the view rect
   1.279 +    //
   1.280 +    {
   1.281 +	if (iWin)
   1.282 +		iWin->Invalidate(aRect);
   1.283 +    }
   1.284 +
   1.285 +void RScreenDisplay::SetTextCursor(TPoint aPos, const TTextCursor &aCursor)
   1.286 +	//
   1.287 +	//Display a cursor at position aPos
   1.288 +	//
   1.289 +	{
   1.290 +	if (iWin && iGroupWin)
   1.291 +		{
   1.292 +		aPos.iX+=iDrawTextLayoutContext->iTextStartX;
   1.293 +		iGroupWin->SetTextCursor(*iWin,aPos,aCursor,iDrawTextLayoutContext->TextArea());
   1.294 +		}
   1.295 +	}
   1.296 +
   1.297 +void RScreenDisplay::RemoveTextCursor()
   1.298 +	//
   1.299 +	//Remove cursor from window
   1.300 +	//
   1.301 +	{
   1.302 +
   1.303 +	if (iGroupWin)
   1.304 +		iGroupWin->CancelTextCursor();
   1.305 +	}
   1.306 +
   1.307 +void RScreenDisplay::ClearRect(const TRect& aRect)
   1.308 +	//
   1.309 +	//Clear a rectangle on the screen
   1.310 +	//
   1.311 +	{
   1.312 +	if (iTextLayout)
   1.313 +		{
   1.314 +		TPoint top_left = iDrawTextLayoutContext->TopLeftText();
   1.315 +		iTextLayout->DrawBackground(*iGc,top_left,aRect,iBackground);
   1.316 +		ResetClippingRect();
   1.317 +		}
   1.318 +	else
   1.319 +		{
   1.320 +		iGc->SetBrushColor(iBackground);
   1.321 +		iGc->Clear(aRect);
   1.322 +		}
   1.323 +	}
   1.324 +
   1.325 +void RScreenDisplay::InvertRect(TRect aRect,const TRgb aInvertColor)
   1.326 +	{
   1.327 +	aRect.Move(iDrawTextLayoutContext->iTextStartX,0);
   1.328 +	iGc->SetDrawMode(CGraphicsContext::EDrawModeXOR);
   1.329 +	iGc->SetBrushColor(aInvertColor);
   1.330 +	iGc->Clear(aRect);
   1.331 +	iGc->SetBrushColor(iBackground);
   1.332 +	iGc->SetDrawMode(CGraphicsContext::EDrawModePEN);
   1.333 +	}
   1.334 +
   1.335 +void RScreenDisplay::Scroll(TRect aRect,const TPoint& aBy,TBool aScrollBackground)
   1.336 +	{
   1.337 +	if (iWin)
   1.338 +		{
   1.339 +		if (!aScrollBackground || (iTextLayout && iTextLayout->CustomDraw()))
   1.340 +			{
   1.341 +			aRect.Move(aBy);
   1.342 +			iWin->Invalidate(aRect);
   1.343 +			}
   1.344 +		else
   1.345 +   			iWin->Scroll(aBy,aRect);
   1.346 +		}
   1.347 +	return;
   1.348 +	}
   1.349 +
   1.350 +void RScreenDisplay::Flush()
   1.351 +	{
   1.352 +	if (iSession)
   1.353 +		iSession->Flush();
   1.354 +	}
   1.355 +
   1.356 +TBool RScreenDisplay::IsLineCursor() const
   1.357 +	{
   1.358 +	return iDrawTextLayoutContext->IsGutterMargin();
   1.359 +	}
   1.360 +
   1.361 +TRect RScreenDisplay::LineCursorMargin() const
   1.362 +	{
   1.363 +	return iDrawTextLayoutContext->GutterMargin();
   1.364 +	}
   1.365 +
   1.366 +TPoint RScreenDisplay::TopLeftTextArea() const
   1.367 +	{
   1.368 +	return iDrawTextLayoutContext->TopLeftTextArea();
   1.369 +	}
   1.370 +
   1.371 +void RScreenDisplay::SetLayout(CTextLayout* aLayout)
   1.372 +	{
   1.373 +	iTextLayout = aLayout;
   1.374 +	iTextLayout->SetWindow(iWin);
   1.375 +	}
   1.376 +
   1.377 +CTextLayout* RScreenDisplay::Layout()
   1.378 +	{
   1.379 +	return iTextLayout;
   1.380 +	}
   1.381 +
   1.382 +TBool RScreenDisplay::UseWindowGc() const
   1.383 +	{
   1.384 +	return iDrawTextLayoutContext->UseWindowGc();
   1.385 +	}