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