os/textandloc/textrendering/textformatting/tbox/FRMFRAME.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) 1996-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 "FRMFRAME.H"
sl@0
    20
sl@0
    21
const TInt KBorderThicknessInPixels=2;
sl@0
    22
sl@0
    23
/** This constructs a TFrameOverlay, clearing all flags and initializing both 
sl@0
    24
blob widths to zero. */
sl@0
    25
EXPORT_C TFrameOverlay::TFrameOverlay()
sl@0
    26
	:iFlags(0),iVisibleBlobWidth(0),iActiveBlobWidth(0)
sl@0
    27
	{
sl@0
    28
    }
sl@0
    29
sl@0
    30
/** Sets the visible and active blob widths to the same value in pixels.
sl@0
    31
@param aWidth The visible and active blob width in pixels. */
sl@0
    32
EXPORT_C void TFrameOverlay::SetBlobWidthInPixels(const TInt aWidth)
sl@0
    33
    {
sl@0
    34
	SetVisibleBlobWidthInPixels(aWidth);
sl@0
    35
	SetActiveBlobWidthInPixels(aWidth);
sl@0
    36
    }
sl@0
    37
sl@0
    38
/** Sets the visible blob width in pixels.
sl@0
    39
@param aWidth The visible blob width in pixels. */
sl@0
    40
EXPORT_C void TFrameOverlay::SetVisibleBlobWidthInPixels(const TInt aWidth)
sl@0
    41
    {
sl@0
    42
	iVisibleBlobWidth=aWidth;
sl@0
    43
    }
sl@0
    44
sl@0
    45
/** Sets the active blob width in pixels. The active blob width should normally
sl@0
    46
be at least as large as the visible blob width.
sl@0
    47
@param aWidth The active blob width in pixels. */
sl@0
    48
EXPORT_C void TFrameOverlay::SetActiveBlobWidthInPixels(const TInt aWidth)
sl@0
    49
	{
sl@0
    50
	iActiveBlobWidth=aWidth;
sl@0
    51
	}
sl@0
    52
sl@0
    53
/** Sets the flags which control how the frame is drawn. Adds the flags
sl@0
    54
specified to the existing flag settings, which are preserved. For a description
sl@0
    55
of the available flags, see the TFrameOverlayFlags enum.
sl@0
    56
@param aFlag Flags to add to the existing settings. */
sl@0
    57
EXPORT_C void TFrameOverlay::SetFlags(TInt aFlag)
sl@0
    58
    {
sl@0
    59
	iFlags|=aFlag;
sl@0
    60
    }
sl@0
    61
sl@0
    62
/** Clears the flags specified from the frame's flag settings. For a description 
sl@0
    63
of the available flags, see the TFrameOverlayFlags enum.
sl@0
    64
@param aFlag Flags to clear from the existing flag settings. */
sl@0
    65
EXPORT_C void TFrameOverlay::ClearFlags(TInt aFlag)
sl@0
    66
    {
sl@0
    67
	iFlags&=(~aFlag);
sl@0
    68
    }
sl@0
    69
sl@0
    70
 
sl@0
    71
sl@0
    72
EXPORT_C void TFrameOverlay::SetRect(const TRect& aRect)
sl@0
    73
/** Sets the picture frame rectangle.
sl@0
    74
sl@0
    75
@param aRect The picture frame rectangle. */
sl@0
    76
    {
sl@0
    77
	iRect=aRect;
sl@0
    78
    }
sl@0
    79
sl@0
    80
/** Draws the picture frame and blobs to a graphics context using the frame's
sl@0
    81
flag settings. If drawn, the frame is represented by a dotted line. The
sl@0
    82
operation uses a draw mode of CGraphicsContext::EDrawModeNOTSCREEN so that the
sl@0
    83
colour of each pixel which is drawn over is inverted. The frame's coordinates
sl@0
    84
are set using SetRect().
sl@0
    85
@param aGc The graphics context to draw to. */
sl@0
    86
EXPORT_C void TFrameOverlay::XorDraw(CGraphicsContext& aGc) const
sl@0
    87
    {
sl@0
    88
	TRect rect=iRect;
sl@0
    89
	TInt blobWidth=VisibleBlobWidth();
sl@0
    90
	if (iFlags&EFrameOverlayFlagBlobsInternal)
sl@0
    91
		rect.Shrink(blobWidth,blobWidth);
sl@0
    92
	TPoint tl=rect.iTl;
sl@0
    93
	TPoint br=rect.iBr;
sl@0
    94
	aGc.SetDrawMode(CGraphicsContext::EDrawModeNOTSCREEN);
sl@0
    95
	aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
sl@0
    96
sl@0
    97
	if (iFlags&EFrameOverlayFlagShowBorder)
sl@0
    98
		{
sl@0
    99
		rect.Grow(blobWidth,blobWidth);
sl@0
   100
		DrawDottedRectangle(aGc, rect);
sl@0
   101
		}
sl@0
   102
sl@0
   103
	if (blobWidth > 0)
sl@0
   104
		{
sl@0
   105
		TInt width=br.iX-tl.iX;
sl@0
   106
		TInt height=br.iY-tl.iY;
sl@0
   107
sl@0
   108
		aGc.SetPenStyle(CGraphicsContext::ESolidPen);
sl@0
   109
		if (!(iFlags&EFrameOverlayFlagTopBlobsDimmed) && !(iFlags&EFrameOverlayFlagLeftBlobsDimmed))
sl@0
   110
			aGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0
   111
		aGc.DrawRect(TRect(tl-TPoint(blobWidth,blobWidth),tl));
sl@0
   112
		aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
sl@0
   113
sl@0
   114
		if (DrawTopAndBottom())
sl@0
   115
			{
sl@0
   116
			if (!(iFlags&EFrameOverlayFlagTopBlobsDimmed))
sl@0
   117
				aGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0
   118
    		aGc.DrawRect(TRect(tl+TPoint((width-blobWidth)/2,-blobWidth),tl+TPoint((width+blobWidth)/2,0)));
sl@0
   119
			aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
sl@0
   120
			}
sl@0
   121
sl@0
   122
		if (!(iFlags&EFrameOverlayFlagTopBlobsDimmed) && !(iFlags&EFrameOverlayFlagRightBlobsDimmed))
sl@0
   123
			aGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0
   124
sl@0
   125
		aGc.DrawRect(TRect(TPoint(br.iX,tl.iY-blobWidth),TPoint(br.iX+blobWidth,tl.iY)));
sl@0
   126
		aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
sl@0
   127
sl@0
   128
		if (DrawLeftAndRight())
sl@0
   129
			{
sl@0
   130
 			if (!(iFlags&EFrameOverlayFlagRightBlobsDimmed))
sl@0
   131
				aGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0
   132
   			aGc.DrawRect(TRect(br-TPoint(0,(height+blobWidth)/2),br+TPoint(blobWidth,-(height-blobWidth)/2)));
sl@0
   133
			aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
sl@0
   134
			}
sl@0
   135
sl@0
   136
		if (!(iFlags&EFrameOverlayFlagRightBlobsDimmed) && !(iFlags&EFrameOverlayFlagBottomBlobsDimmed))
sl@0
   137
			aGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0
   138
		aGc.DrawRect(TRect(br,br+TPoint(blobWidth,blobWidth)));
sl@0
   139
		aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
sl@0
   140
sl@0
   141
		if (DrawTopAndBottom())
sl@0
   142
			{
sl@0
   143
 			if (!(iFlags&EFrameOverlayFlagBottomBlobsDimmed))
sl@0
   144
				aGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0
   145
    		aGc.DrawRect(TRect(br-TPoint((width+blobWidth)/2,0),br-TPoint((width-blobWidth)/2,-blobWidth)));
sl@0
   146
			aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
sl@0
   147
			}
sl@0
   148
sl@0
   149
		if (!(iFlags&EFrameOverlayFlagBottomBlobsDimmed) && !(iFlags&EFrameOverlayFlagLeftBlobsDimmed))
sl@0
   150
			aGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0
   151
		aGc.DrawRect(TRect(TPoint(tl.iX-blobWidth,br.iY),TPoint(tl.iX,br.iY+blobWidth)));
sl@0
   152
		aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
sl@0
   153
sl@0
   154
		if (DrawLeftAndRight())
sl@0
   155
			{
sl@0
   156
  			if (!(iFlags&EFrameOverlayFlagLeftBlobsDimmed))
sl@0
   157
				aGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0
   158
   			aGc.DrawRect(TRect(tl+TPoint(-blobWidth,(height-blobWidth)/2),tl+TPoint(0,(height+blobWidth)/2)));
sl@0
   159
			aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
sl@0
   160
			}
sl@0
   161
		}
sl@0
   162
sl@0
   163
	aGc.SetDrawMode(CGraphicsContext::EDrawModePEN);
sl@0
   164
    }
sl@0
   165
sl@0
   166
/** Gets the active region in which a pixel position is located.
sl@0
   167
sl@0
   168
Note: Adjacent active regions overlap at the corners of the picture frame, so
sl@0
   169
that a pixel position may be located within more than one active region.
sl@0
   170
sl@0
   171
@param aPos A pixel position.
sl@0
   172
@return The active area(s) within which the position specified is located. Zero
sl@0
   173
if not located within any active area. For details, see the TEdges enumeration,
sl@0
   174
described below. */
sl@0
   175
EXPORT_C TInt TFrameOverlay::XyPosToEdges(const TPoint& aPos) const
sl@0
   176
    {
sl@0
   177
	TInt visibleBlobWidth=VisibleBlobWidth();
sl@0
   178
	TInt marginWidth=ActiveMarginWidth();
sl@0
   179
	TInt edgesTouched=ENoEdges;
sl@0
   180
	TRect frameOuterRect=iRect;
sl@0
   181
	TRect frameInnerRect=iRect;
sl@0
   182
	frameOuterRect.Grow(marginWidth,marginWidth);
sl@0
   183
	frameInnerRect.Shrink(marginWidth,marginWidth);
sl@0
   184
	if (iFlags&EFrameOverlayFlagBlobsInternal)
sl@0
   185
		frameInnerRect.Shrink(visibleBlobWidth,visibleBlobWidth);
sl@0
   186
	else
sl@0
   187
		frameOuterRect.Grow(visibleBlobWidth,visibleBlobWidth);
sl@0
   188
	TRect rightRect(TPoint(frameInnerRect.iBr.iX,frameOuterRect.iTl.iY),frameOuterRect.iBr);
sl@0
   189
	TRect leftRect(frameOuterRect.iTl,TPoint(frameInnerRect.iTl.iX,frameOuterRect.iBr.iY));
sl@0
   190
	if (rightRect.Contains(aPos))
sl@0
   191
		edgesTouched|=EEdgeRight;
sl@0
   192
	else if (leftRect.Contains(aPos))
sl@0
   193
		edgesTouched|=EEdgeLeft;
sl@0
   194
	TRect topRect(frameOuterRect.iTl,TPoint(frameOuterRect.iBr.iX,frameInnerRect.iTl.iY));
sl@0
   195
	TRect bottomRect(TPoint(frameOuterRect.iTl.iX,frameInnerRect.iBr.iY),frameOuterRect.iBr);
sl@0
   196
	if (topRect.Contains(aPos))
sl@0
   197
		edgesTouched|=EEdgeTop;
sl@0
   198
	else if (bottomRect.Contains(aPos))
sl@0
   199
		edgesTouched|=EEdgeBottom;
sl@0
   200
	return(edgesTouched);
sl@0
   201
    }
sl@0
   202
sl@0
   203
sl@0
   204
TInt TFrameOverlay::VisibleBlobWidth()	const
sl@0
   205
	{
sl@0
   206
	if (iFlags&EFrameOverlayFlagBlobsInternal)
sl@0
   207
		return Min(Min(iRect.Width(),iRect.Height())/3,(TInt) iVisibleBlobWidth);
sl@0
   208
	else
sl@0
   209
		return iVisibleBlobWidth;
sl@0
   210
	}
sl@0
   211
sl@0
   212
TInt TFrameOverlay::ActiveMarginWidth() const
sl@0
   213
	{
sl@0
   214
	TInt margin=(iActiveBlobWidth-VisibleBlobWidth())/2;
sl@0
   215
	if (iFlags&EFrameOverlayFlagBlobsInternal)
sl@0
   216
		return Min(Min(iRect.Width(),iRect.Height())/3-VisibleBlobWidth(),margin);
sl@0
   217
	else
sl@0
   218
		return Min(Min(iRect.Width(),iRect.Height())/3,margin);
sl@0
   219
sl@0
   220
	}
sl@0
   221
sl@0
   222
TBool TFrameOverlay::DrawLeftAndRight() const
sl@0
   223
	{
sl@0
   224
	if (iFlags&EFrameOverlayFlagBlobsInternal)
sl@0
   225
		return (iRect.Height()>3*iVisibleBlobWidth);
sl@0
   226
	else
sl@0
   227
		return (iRect.Height()>iVisibleBlobWidth);
sl@0
   228
	}
sl@0
   229
sl@0
   230
TBool TFrameOverlay::DrawTopAndBottom() const
sl@0
   231
	{
sl@0
   232
	if (iFlags&EFrameOverlayFlagBlobsInternal)
sl@0
   233
		return (iRect.Width()>3*iVisibleBlobWidth);
sl@0
   234
	else
sl@0
   235
		return (iRect.Width()>iVisibleBlobWidth);
sl@0
   236
	}
sl@0
   237
sl@0
   238
void TFrameOverlay::DrawDottedRectangle(CGraphicsContext& aGc,const TRect& aRect) const
sl@0
   239
	{
sl@0
   240
	TInt dashWidth=KBorderThicknessInPixels; 
sl@0
   241
	TInt dashLength=KBorderThicknessInPixels;
sl@0
   242
	TInt horizontalDashes=(aRect.Width()+dashLength-dashWidth)/(2*dashLength);
sl@0
   243
	TInt verticalDashes=(aRect.Height()+dashLength-dashWidth)/(2*dashLength);
sl@0
   244
	aGc.SetPenStyle(CGraphicsContext::ENullPen);
sl@0
   245
	aGc.SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0
   246
	TPoint move(2*dashLength,0);
sl@0
   247
	TRect drawRect(aRect.iTl,TSize(dashLength,dashWidth));
sl@0
   248
sl@0
   249
	{for (TInt ii=0;ii<horizontalDashes;ii++)
sl@0
   250
		{
sl@0
   251
 		aGc.DrawRect(drawRect);
sl@0
   252
 		drawRect.Move(move);
sl@0
   253
		}
sl@0
   254
	}
sl@0
   255
sl@0
   256
	move.SetXY(0,2*dashLength);
sl@0
   257
	drawRect.SetRect(TPoint(aRect.iBr.iX-dashWidth,aRect.iTl.iY),TSize(dashWidth,dashLength));
sl@0
   258
sl@0
   259
	{for (TInt ii=0;ii<verticalDashes;ii++)
sl@0
   260
		{
sl@0
   261
 		aGc.DrawRect(drawRect);
sl@0
   262
 		drawRect.Move(move);
sl@0
   263
		}
sl@0
   264
	}
sl@0
   265
sl@0
   266
	move.SetXY(-2*dashLength,0);
sl@0
   267
	drawRect.SetRect(TPoint(aRect.iBr.iX-dashLength,aRect.iBr.iY-dashWidth),TSize(dashLength,dashWidth));
sl@0
   268
sl@0
   269
	{for (TInt ii=0;ii<horizontalDashes;ii++)
sl@0
   270
		{
sl@0
   271
 		aGc.DrawRect(drawRect);
sl@0
   272
 		drawRect.Move(move);
sl@0
   273
		}
sl@0
   274
	}
sl@0
   275
sl@0
   276
	move.SetXY(0,-2*dashLength);
sl@0
   277
	drawRect.SetRect(TPoint(aRect.iTl.iX,aRect.iBr.iY-dashLength),TSize(dashWidth,dashLength));
sl@0
   278
sl@0
   279
	{for (TInt ii=0;ii<verticalDashes;ii++)
sl@0
   280
		{
sl@0
   281
 		aGc.DrawRect(drawRect);
sl@0
   282
 		drawRect.Move(move);
sl@0
   283
		}
sl@0
   284
	}
sl@0
   285
sl@0
   286
	}
sl@0
   287
sl@0
   288
sl@0
   289