os/textandloc/textrendering/textformatting/tbox/FRMDRAW.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/textandloc/textrendering/textformatting/tbox/FRMDRAW.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,356 @@
     1.4 +/*
     1.5 +* Copyright (c) 1996-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 "FRMTLAY.H"
    1.23 +#include "FRMCONST.H"
    1.24 +
    1.25 +/** Default C++ constructor.
    1.26 +
    1.27 +This constructs a fully initialized TDrawTextLayoutContext object. Its view
    1.28 +rectangle, iLabelMarginWidth and iGutterMarginWidth and iTextStartX are all
    1.29 +initialized to zero, the background colour is initialized to the default system
    1.30 +background colour, text and graphics are set to be drawn and clipping is set.
    1.31 +The graphics context is initialised to null. */
    1.32 +EXPORT_C TDrawTextLayoutContext::TDrawTextLayoutContext():
    1.33 +	iLabelMarginWidth(0),
    1.34 +	iGutterMarginWidth(0),
    1.35 +	iTextStartX(0),
    1.36 +	iBackgroundColor(TLogicalRgb::ESystemBackgroundColor),
    1.37 +	iGc(NULL),
    1.38 +	iPictureGc(NULL),
    1.39 +	iOverrideTextColor(TLogicalRgb::ESystemForegroundColor),
    1.40 +	iDrawMode(EFDrawText | EFDrawGraphics | EFUseClippingRect)
    1.41 +	{
    1.42 +	}
    1.43 +
    1.44 +/** Sets the graphics context for drawing text and pictures.
    1.45 +@param aGc Pointer to the graphics context for drawing text and pictures.
    1.46 +@param aPictureGc This argument is not used - all drawing is done using aGc. */
    1.47 +EXPORT_C void TDrawTextLayoutContext::SetGc(CGraphicsContext* aGc,CGraphicsContext* aPictureGc/*=NULL*/)
    1.48 +	{
    1.49 +	iGc=aGc;
    1.50 +	iPictureGc=aPictureGc;
    1.51 +	iDrawMode&=EFAllFlags-EFUseGcClear;
    1.52 +	iDrawMode&=EFAllFlags-EFUseWindowGc;
    1.53 +	};
    1.54 +
    1.55 +EXPORT_C void TDrawTextLayoutContext::SetBitmapGc(CBitmapContext* aGc,CBitmapContext* aPictureGc/*=NULL*/)
    1.56 +	{
    1.57 +	iGc=aGc;
    1.58 +	iPictureGc=aPictureGc;
    1.59 +	iDrawMode|=EFUseGcClear;
    1.60 +	iDrawMode&=EFAllFlags-EFUseWindowGc;
    1.61 +	};
    1.62 +
    1.63 +EXPORT_C void TDrawTextLayoutContext::SetWindowGc(CWindowGc* aGc,CWindowGc* aPictureGc/*=NULL*/)
    1.64 +	{
    1.65 +	iGc=aGc;
    1.66 +	iPictureGc=aPictureGc;
    1.67 +	iDrawMode|=EFUseGcClear;
    1.68 +	iDrawMode|=EFUseWindowGc;
    1.69 +	iDrawMode|=EFUseClippingRect;
    1.70 +	};
    1.71 +
    1.72 +/** Sets whether the background colour as specified by iBackgroundColor should
    1.73 +be drawn.
    1.74 +@param aDrawToEveryPixel Specify ETrue to draw the background colour, EFalse to
    1.75 +draw no background colour. */
    1.76 +EXPORT_C void TDrawTextLayoutContext::SetDrawToEveryPixel(TBool aDrawToEveryPixel)
    1.77 +	{
    1.78 +	if (aDrawToEveryPixel)
    1.79 +		iDrawMode|=EFUseBackgroundColor;
    1.80 +	else
    1.81 +		iDrawMode&=EFAllFlags-EFUseBackgroundColor;
    1.82 +	}
    1.83 +
    1.84 +/** Overrides the existing text colour, so that when redrawn, all text has the
    1.85 +colour specified, rather than the colour which is set in the text object. To
    1.86 +return the text to its original colour, call this function again with an
    1.87 +argument of null.
    1.88 +@param aOverrideColor If not NULL, overrides the text colour. */
    1.89 +EXPORT_C void TDrawTextLayoutContext::SetTextColorOverride(const TRgb *aOverrideColor)
    1.90 +	{
    1.91 +	if (aOverrideColor)
    1.92 +		{
    1.93 +		iDrawMode|=EFUseOverrideTextColor;
    1.94 +		iOverrideTextColor=*aOverrideColor;
    1.95 +		}
    1.96 +	else
    1.97 +		iDrawMode&=EFAllFlags-EFUseOverrideTextColor;
    1.98 +	}
    1.99 +
   1.100 +/** This function is obsolete. When a text object is drawn, all parts of it are
   1.101 +drawn. */
   1.102 +EXPORT_C void TDrawTextLayoutContext::SetDrawTextOnly()
   1.103 +	{
   1.104 +	iDrawMode|=EFDrawText;
   1.105 +	iDrawMode&=EFAllFlags-EFDrawGraphics;
   1.106 +	}
   1.107 +
   1.108 +/** This function is obsolete. When a text object is drawn, all parts of it are
   1.109 +drawn. */
   1.110 +EXPORT_C void TDrawTextLayoutContext::SetDrawGraphicsOnly()
   1.111 +	{
   1.112 +	iDrawMode|=EFDrawGraphics;
   1.113 +	iDrawMode&=EFAllFlags-EFDrawText;
   1.114 +	}
   1.115 +
   1.116 +/** This function is obsolete. When a text object is drawn, all parts of it are
   1.117 +drawn. */
   1.118 +EXPORT_C void TDrawTextLayoutContext::SetDrawTextAndGraphics()
   1.119 +	{
   1.120 +	iDrawMode|=EFDrawGraphics;
   1.121 +	iDrawMode|=EFDrawText;
   1.122 +	}
   1.123 +
   1.124 +/** Sets whether drawing should be clipped to the intersection of the draw
   1.125 +rectangle (the aDrawRect parameter passed to CTextLayout::DrawL() or
   1.126 +InvertRangeL()) and the text area.
   1.127 +@param aClipping True to clip drawing to the clip rectangle. False to ignore
   1.128 +the clip rectangle. */
   1.129 +EXPORT_C void TDrawTextLayoutContext::SetClipping(TBool aClipping)
   1.130 +	{
   1.131 +	if (aClipping)
   1.132 +		iDrawMode|=EFUseClippingRect;
   1.133 +	else
   1.134 +		{
   1.135 +		iDrawMode&=EFAllFlags-EFUseClippingRect;
   1.136 +		}
   1.137 +	}
   1.138 +	
   1.139 +/** Sets the horizontal extent of a paragraph to be filled with paragraph fill
   1.140 +colour.
   1.141 +@deprecated 7.0
   1.142 +@param aFillTextOnly If true, the region filled with paragraph fill colour is
   1.143 +the area within the paragraph only. If false, the left text margin, if present,
   1.144 +is also filled. */
   1.145 +EXPORT_C void TDrawTextLayoutContext::SetParagraphFillTextOnly(TBool aFillTextOnly)
   1.146 +	{
   1.147 +	if (aFillTextOnly)
   1.148 +		iDrawMode|=EFParagraphFillTextOnly;
   1.149 +	else
   1.150 + 		iDrawMode&=EFAllFlags-EFParagraphFillTextOnly;
   1.151 +	}
   1.152 +
   1.153 +/** If the text colour is overridden, this function gets the text override
   1.154 +colour, as set by SetTextColorOverride().
   1.155 +@return Text override colour. NULL if no text override colour is in use. */
   1.156 +EXPORT_C const TRgb* TDrawTextLayoutContext::TextOverrideColor() const 
   1.157 +	{
   1.158 +	return (iDrawMode&EFUseOverrideTextColor) ? &iOverrideTextColor : NULL;
   1.159 +	}
   1.160 +
   1.161 +/** Gets the graphics context for drawing the text and pictures.
   1.162 +@return The graphics context. */
   1.163 +EXPORT_C CGraphicsContext* TDrawTextLayoutContext::PrimaryGc() const
   1.164 +	{
   1.165 +	return iGc;
   1.166 +	}
   1.167 +
   1.168 +EXPORT_C CGraphicsContext* TDrawTextLayoutContext::PictureGc() const 
   1.169 +	{
   1.170 +	return iPictureGc;
   1.171 +	}
   1.172 +
   1.173 +/** Tests whether clipping is set to the intersection of the draw rectangle,
   1.174 +(the aDrawRect parameter passed to CTextLayout::DrawL() or InvertRangeL()) and
   1.175 +the text area.
   1.176 +@return True if clipping set to clip rectangle, false if not. */
   1.177 +EXPORT_C TBool TDrawTextLayoutContext::UseClippingRect() const 
   1.178 +	{
   1.179 +	return iDrawMode&EFUseClippingRect;
   1.180 +	}
   1.181 +
   1.182 +/** Tests if the graphics context for drawing is either CWindowGc
   1.183 +or CBitmapContext.
   1.184 +
   1.185 +@return True if the graphics context is either CWindowGc or CBitmapContext.
   1.186 +        False otherwise. */
   1.187 +EXPORT_C TBool TDrawTextLayoutContext::UseGcClear() const
   1.188 +	{
   1.189 +	return iDrawMode&EFUseGcClear;
   1.190 +	}
   1.191 +
   1.192 +/** Obsolete function. When a text object is drawn, all parts of it are drawn. */
   1.193 +EXPORT_C TBool TDrawTextLayoutContext::DrawText() const
   1.194 +	{
   1.195 +	return iDrawMode&EFDrawText;
   1.196 +	}
   1.197 +
   1.198 +/** Obsolete function. When a text object is drawn, all parts of it are drawn.
   1.199 +*/
   1.200 +EXPORT_C TBool TDrawTextLayoutContext::DrawGraphics() const
   1.201 +	{
   1.202 +	return iDrawMode&EFDrawGraphics;
   1.203 +	}
   1.204 +
   1.205 +/** Tests whether the background colour is used, as set by
   1.206 +SetDrawToEveryPixel().
   1.207 +@return True if the background colour is used. False if not. */
   1.208 +EXPORT_C TBool TDrawTextLayoutContext::UseBackgroundColor() const
   1.209 +	{
   1.210 +	return iDrawMode&EFUseBackgroundColor;
   1.211 +	}
   1.212 +
   1.213 +/** Tests whether the region filled with paragraph fill colour is the area
   1.214 +within the paragraph only, or also the area within the left text margin.
   1.215 +@deprecated 7.0
   1.216 +@return If true, the region filled with paragraph fill colour is the area
   1.217 +within the paragraph only. If false, the left text margin, if present, is also
   1.218 +filled. */
   1.219 +EXPORT_C TBool TDrawTextLayoutContext::ParagraphFillTextOnly() const
   1.220 +	{
   1.221 +	return iDrawMode&EFParagraphFillTextOnly;
   1.222 +	}
   1.223 +
   1.224 +/** Gets the text area. The text area is the view rectangle minus the label and
   1.225 +gutter margins.
   1.226 +@return The text area. */
   1.227 +EXPORT_C TRect TDrawTextLayoutContext::TextArea() const
   1.228 +	{
   1.229 +	TRect area(iViewRect);
   1.230 +	area.iTl.iX+=iLabelMarginWidth+iGutterMarginWidth;
   1.231 +	return area;
   1.232 +	}
   1.233 +
   1.234 +/** Gets the display height in pixels. The display height is the same as the
   1.235 +view rectangle height.
   1.236 +@return The display height. */
   1.237 +EXPORT_C TInt TDrawTextLayoutContext::DisplayHeight() const
   1.238 +	{
   1.239 +	return iViewRect.Height();
   1.240 +	}
   1.241 +
   1.242 +/** Gets the (window) coordinates of the top left hand corner of the text area.
   1.243 +@return The top left hand corner of the text area. */
   1.244 +EXPORT_C TPoint TDrawTextLayoutContext::TopLeftTextArea() const
   1.245 +	{
   1.246 +	return TextArea().iTl;
   1.247 +	}
   1.248 +
   1.249 +/** Gets the area occupied by the label and gutter margins.
   1.250 +@return Rectangle representing the label and gutter margins. */
   1.251 +EXPORT_C TRect TDrawTextLayoutContext::TotalMargin() const
   1.252 +	{
   1.253 +	TRect area(iViewRect);
   1.254 +	area.iBr.iX=area.iTl.iX+iLabelMarginWidth+iGutterMarginWidth;
   1.255 +	return area;
   1.256 +	}
   1.257 +
   1.258 +/** Gets the area occupied by the label margin.
   1.259 +@return Rectangle representing the label margin. */
   1.260 +EXPORT_C TRect TDrawTextLayoutContext::LabelMargin() const
   1.261 +	{
   1.262 +	TRect margin(iViewRect);
   1.263 +	margin.iBr.iX=margin.iTl.iX+iLabelMarginWidth;
   1.264 +	return margin;
   1.265 +	}
   1.266 +
   1.267 +/** Tests whether a label margin has been set.
   1.268 +@return True if a label margin has been set. False if not. */
   1.269 +EXPORT_C TBool TDrawTextLayoutContext::IsLabelMargin() const
   1.270 +	{
   1.271 +	return iGutterMarginWidth > 0;
   1.272 +	}
   1.273 +
   1.274 +/** Gets the area occupied by the gutter margin.
   1.275 +@return Rectangle representing the gutter margin. */
   1.276 +EXPORT_C TRect TDrawTextLayoutContext::GutterMargin() const
   1.277 +	{
   1.278 +	TRect margin(iViewRect);
   1.279 +	margin.iTl.iX+=iLabelMarginWidth;
   1.280 +	margin.iBr.iX=margin.iTl.iX+iGutterMarginWidth;
   1.281 +	return margin;
   1.282 +	}
   1.283 +
   1.284 +/** This function is identical to IsLabelMargin().
   1.285 +@return True if a label margin has been set, false if not. */
   1.286 +EXPORT_C TBool TDrawTextLayoutContext::IsGutterMargin() const
   1.287 +	{
   1.288 +	return iGutterMarginWidth > 0; 
   1.289 +	}
   1.290 +
   1.291 +/** Gets the window coordinates of the top left hand corner at which text may
   1.292 +be drawn. This point has the same vertical coordinate as the top of the text
   1.293 +area, but its horizontal coordinate is increased by the left text margin width
   1.294 +(iTextStartX). This point is the origin for layout coordinates.
   1.295 +
   1.296 +@return The coordinates of the top left hand point at which text can be drawn.
   1.297 +*/
   1.298 +EXPORT_C TPoint TDrawTextLayoutContext::TopLeftText() const
   1.299 +	{
   1.300 +	return TopLeftTextArea()+TPoint(iTextStartX,0);
   1.301 +	}
   1.302 +
   1.303 +/** Converts a point in window coordinates to layout coordinates. Window
   1.304 +coordinates have their origin at the top left corner of the view window. Layout
   1.305 +coordinates have their origin at the top left corner of the area within the
   1.306 +view rectangle in which text can appear, (this value is returned by
   1.307 +TopLeftText()).
   1.308 +@param aWinPos Point in window coordinates. On return, set to layout
   1.309 +coordinates. */
   1.310 +EXPORT_C void TDrawTextLayoutContext::WindowToText(TPoint& aWinPos) const
   1.311 +	{
   1.312 +	aWinPos-=TopLeftText();
   1.313 +	}
   1.314 +
   1.315 +/** Converts a rectangle in window coordinates to layout coordinates. Window
   1.316 +coordinates have their origin at the top left corner of the view window. Layout
   1.317 +coordinates have their origin at the top left corner of the area within the
   1.318 +view rectangle in which text can appear, (this value is returned by
   1.319 +TopLeftText()).
   1.320 +@param aRect Rectangle in window coordinates. On return, set to layout
   1.321 +coordinates. */
   1.322 +EXPORT_C void TDrawTextLayoutContext::WindowToText(TRect& aRect) const
   1.323 +	{
   1.324 +	aRect.Move(TPoint(0,0)-TopLeftText());
   1.325 +	}
   1.326 +
   1.327 +/** Converts a point in layout coordinates to window coordinates.
   1.328 +@param aTextAreaPos A point in layout coordinates. On return, set to window
   1.329 +coordinates. */
   1.330 +EXPORT_C void TDrawTextLayoutContext::TextToWindow(TPoint& aTextAreaPos) const
   1.331 +	{
   1.332 +	aTextAreaPos+=TopLeftText();
   1.333 +	}
   1.334 +
   1.335 +/** Converts a rectangle in layout coordinates to window coordinates.
   1.336 +@param aRect Rectangle in layout coordinates. On return, set to window
   1.337 +coordinates. */
   1.338 +EXPORT_C void TDrawTextLayoutContext::TextToWindow(TRect& aRect) const
   1.339 +	{
   1.340 +	aRect.Move(TopLeftText());
   1.341 +	}
   1.342 +
   1.343 +/** Tests if a CWindowGc is being used. */
   1.344 +TBool TDrawTextLayoutContext::UseWindowGc() const
   1.345 +	{
   1.346 +	return iDrawMode & EFUseWindowGc;
   1.347 +	}
   1.348 +
   1.349 +/** Returns the current drawing mode flags. */
   1.350 +void TDrawTextLayoutContext::SetDrawMode(TUint aDrawMode)
   1.351 +	{
   1.352 +	iDrawMode = aDrawMode;
   1.353 +	}
   1.354 +
   1.355 +/** Returns the flags that identify the current drawing mode. */
   1.356 +TUint TDrawTextLayoutContext::DrawMode() const
   1.357 +	{
   1.358 +	return iDrawMode;
   1.359 +	}