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