sl@0: /* sl@0: * Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "FRMTLAY.H" sl@0: #include "FRMCONST.H" sl@0: sl@0: /** Default C++ constructor. sl@0: sl@0: This constructs a fully initialized TDrawTextLayoutContext object. Its view sl@0: rectangle, iLabelMarginWidth and iGutterMarginWidth and iTextStartX are all sl@0: initialized to zero, the background colour is initialized to the default system sl@0: background colour, text and graphics are set to be drawn and clipping is set. sl@0: The graphics context is initialised to null. */ sl@0: EXPORT_C TDrawTextLayoutContext::TDrawTextLayoutContext(): sl@0: iLabelMarginWidth(0), sl@0: iGutterMarginWidth(0), sl@0: iTextStartX(0), sl@0: iBackgroundColor(TLogicalRgb::ESystemBackgroundColor), sl@0: iGc(NULL), sl@0: iPictureGc(NULL), sl@0: iOverrideTextColor(TLogicalRgb::ESystemForegroundColor), sl@0: iDrawMode(EFDrawText | EFDrawGraphics | EFUseClippingRect) sl@0: { sl@0: } sl@0: sl@0: /** Sets the graphics context for drawing text and pictures. sl@0: @param aGc Pointer to the graphics context for drawing text and pictures. sl@0: @param aPictureGc This argument is not used - all drawing is done using aGc. */ sl@0: EXPORT_C void TDrawTextLayoutContext::SetGc(CGraphicsContext* aGc,CGraphicsContext* aPictureGc/*=NULL*/) sl@0: { sl@0: iGc=aGc; sl@0: iPictureGc=aPictureGc; sl@0: iDrawMode&=EFAllFlags-EFUseGcClear; sl@0: iDrawMode&=EFAllFlags-EFUseWindowGc; sl@0: }; sl@0: sl@0: EXPORT_C void TDrawTextLayoutContext::SetBitmapGc(CBitmapContext* aGc,CBitmapContext* aPictureGc/*=NULL*/) sl@0: { sl@0: iGc=aGc; sl@0: iPictureGc=aPictureGc; sl@0: iDrawMode|=EFUseGcClear; sl@0: iDrawMode&=EFAllFlags-EFUseWindowGc; sl@0: }; sl@0: sl@0: EXPORT_C void TDrawTextLayoutContext::SetWindowGc(CWindowGc* aGc,CWindowGc* aPictureGc/*=NULL*/) sl@0: { sl@0: iGc=aGc; sl@0: iPictureGc=aPictureGc; sl@0: iDrawMode|=EFUseGcClear; sl@0: iDrawMode|=EFUseWindowGc; sl@0: iDrawMode|=EFUseClippingRect; sl@0: }; sl@0: sl@0: /** Sets whether the background colour as specified by iBackgroundColor should sl@0: be drawn. sl@0: @param aDrawToEveryPixel Specify ETrue to draw the background colour, EFalse to sl@0: draw no background colour. */ sl@0: EXPORT_C void TDrawTextLayoutContext::SetDrawToEveryPixel(TBool aDrawToEveryPixel) sl@0: { sl@0: if (aDrawToEveryPixel) sl@0: iDrawMode|=EFUseBackgroundColor; sl@0: else sl@0: iDrawMode&=EFAllFlags-EFUseBackgroundColor; sl@0: } sl@0: sl@0: /** Overrides the existing text colour, so that when redrawn, all text has the sl@0: colour specified, rather than the colour which is set in the text object. To sl@0: return the text to its original colour, call this function again with an sl@0: argument of null. sl@0: @param aOverrideColor If not NULL, overrides the text colour. */ sl@0: EXPORT_C void TDrawTextLayoutContext::SetTextColorOverride(const TRgb *aOverrideColor) sl@0: { sl@0: if (aOverrideColor) sl@0: { sl@0: iDrawMode|=EFUseOverrideTextColor; sl@0: iOverrideTextColor=*aOverrideColor; sl@0: } sl@0: else sl@0: iDrawMode&=EFAllFlags-EFUseOverrideTextColor; sl@0: } sl@0: sl@0: /** This function is obsolete. When a text object is drawn, all parts of it are sl@0: drawn. */ sl@0: EXPORT_C void TDrawTextLayoutContext::SetDrawTextOnly() sl@0: { sl@0: iDrawMode|=EFDrawText; sl@0: iDrawMode&=EFAllFlags-EFDrawGraphics; sl@0: } sl@0: sl@0: /** This function is obsolete. When a text object is drawn, all parts of it are sl@0: drawn. */ sl@0: EXPORT_C void TDrawTextLayoutContext::SetDrawGraphicsOnly() sl@0: { sl@0: iDrawMode|=EFDrawGraphics; sl@0: iDrawMode&=EFAllFlags-EFDrawText; sl@0: } sl@0: sl@0: /** This function is obsolete. When a text object is drawn, all parts of it are sl@0: drawn. */ sl@0: EXPORT_C void TDrawTextLayoutContext::SetDrawTextAndGraphics() sl@0: { sl@0: iDrawMode|=EFDrawGraphics; sl@0: iDrawMode|=EFDrawText; sl@0: } sl@0: sl@0: /** Sets whether drawing should be clipped to the intersection of the draw sl@0: rectangle (the aDrawRect parameter passed to CTextLayout::DrawL() or sl@0: InvertRangeL()) and the text area. sl@0: @param aClipping True to clip drawing to the clip rectangle. False to ignore sl@0: the clip rectangle. */ sl@0: EXPORT_C void TDrawTextLayoutContext::SetClipping(TBool aClipping) sl@0: { sl@0: if (aClipping) sl@0: iDrawMode|=EFUseClippingRect; sl@0: else sl@0: { sl@0: iDrawMode&=EFAllFlags-EFUseClippingRect; sl@0: } sl@0: } sl@0: sl@0: /** Sets the horizontal extent of a paragraph to be filled with paragraph fill sl@0: colour. sl@0: @deprecated 7.0 sl@0: @param aFillTextOnly If true, the region filled with paragraph fill colour is sl@0: the area within the paragraph only. If false, the left text margin, if present, sl@0: is also filled. */ sl@0: EXPORT_C void TDrawTextLayoutContext::SetParagraphFillTextOnly(TBool aFillTextOnly) sl@0: { sl@0: if (aFillTextOnly) sl@0: iDrawMode|=EFParagraphFillTextOnly; sl@0: else sl@0: iDrawMode&=EFAllFlags-EFParagraphFillTextOnly; sl@0: } sl@0: sl@0: /** If the text colour is overridden, this function gets the text override sl@0: colour, as set by SetTextColorOverride(). sl@0: @return Text override colour. NULL if no text override colour is in use. */ sl@0: EXPORT_C const TRgb* TDrawTextLayoutContext::TextOverrideColor() const sl@0: { sl@0: return (iDrawMode&EFUseOverrideTextColor) ? &iOverrideTextColor : NULL; sl@0: } sl@0: sl@0: /** Gets the graphics context for drawing the text and pictures. sl@0: @return The graphics context. */ sl@0: EXPORT_C CGraphicsContext* TDrawTextLayoutContext::PrimaryGc() const sl@0: { sl@0: return iGc; sl@0: } sl@0: sl@0: EXPORT_C CGraphicsContext* TDrawTextLayoutContext::PictureGc() const sl@0: { sl@0: return iPictureGc; sl@0: } sl@0: sl@0: /** Tests whether clipping is set to the intersection of the draw rectangle, sl@0: (the aDrawRect parameter passed to CTextLayout::DrawL() or InvertRangeL()) and sl@0: the text area. sl@0: @return True if clipping set to clip rectangle, false if not. */ sl@0: EXPORT_C TBool TDrawTextLayoutContext::UseClippingRect() const sl@0: { sl@0: return iDrawMode&EFUseClippingRect; sl@0: } sl@0: sl@0: /** Tests if the graphics context for drawing is either CWindowGc sl@0: or CBitmapContext. sl@0: sl@0: @return True if the graphics context is either CWindowGc or CBitmapContext. sl@0: False otherwise. */ sl@0: EXPORT_C TBool TDrawTextLayoutContext::UseGcClear() const sl@0: { sl@0: return iDrawMode&EFUseGcClear; sl@0: } sl@0: sl@0: /** Obsolete function. When a text object is drawn, all parts of it are drawn. */ sl@0: EXPORT_C TBool TDrawTextLayoutContext::DrawText() const sl@0: { sl@0: return iDrawMode&EFDrawText; sl@0: } sl@0: sl@0: /** Obsolete function. When a text object is drawn, all parts of it are drawn. sl@0: */ sl@0: EXPORT_C TBool TDrawTextLayoutContext::DrawGraphics() const sl@0: { sl@0: return iDrawMode&EFDrawGraphics; sl@0: } sl@0: sl@0: /** Tests whether the background colour is used, as set by sl@0: SetDrawToEveryPixel(). sl@0: @return True if the background colour is used. False if not. */ sl@0: EXPORT_C TBool TDrawTextLayoutContext::UseBackgroundColor() const sl@0: { sl@0: return iDrawMode&EFUseBackgroundColor; sl@0: } sl@0: sl@0: /** Tests whether the region filled with paragraph fill colour is the area sl@0: within the paragraph only, or also the area within the left text margin. sl@0: @deprecated 7.0 sl@0: @return If true, the region filled with paragraph fill colour is the area sl@0: within the paragraph only. If false, the left text margin, if present, is also sl@0: filled. */ sl@0: EXPORT_C TBool TDrawTextLayoutContext::ParagraphFillTextOnly() const sl@0: { sl@0: return iDrawMode&EFParagraphFillTextOnly; sl@0: } sl@0: sl@0: /** Gets the text area. The text area is the view rectangle minus the label and sl@0: gutter margins. sl@0: @return The text area. */ sl@0: EXPORT_C TRect TDrawTextLayoutContext::TextArea() const sl@0: { sl@0: TRect area(iViewRect); sl@0: area.iTl.iX+=iLabelMarginWidth+iGutterMarginWidth; sl@0: return area; sl@0: } sl@0: sl@0: /** Gets the display height in pixels. The display height is the same as the sl@0: view rectangle height. sl@0: @return The display height. */ sl@0: EXPORT_C TInt TDrawTextLayoutContext::DisplayHeight() const sl@0: { sl@0: return iViewRect.Height(); sl@0: } sl@0: sl@0: /** Gets the (window) coordinates of the top left hand corner of the text area. sl@0: @return The top left hand corner of the text area. */ sl@0: EXPORT_C TPoint TDrawTextLayoutContext::TopLeftTextArea() const sl@0: { sl@0: return TextArea().iTl; sl@0: } sl@0: sl@0: /** Gets the area occupied by the label and gutter margins. sl@0: @return Rectangle representing the label and gutter margins. */ sl@0: EXPORT_C TRect TDrawTextLayoutContext::TotalMargin() const sl@0: { sl@0: TRect area(iViewRect); sl@0: area.iBr.iX=area.iTl.iX+iLabelMarginWidth+iGutterMarginWidth; sl@0: return area; sl@0: } sl@0: sl@0: /** Gets the area occupied by the label margin. sl@0: @return Rectangle representing the label margin. */ sl@0: EXPORT_C TRect TDrawTextLayoutContext::LabelMargin() const sl@0: { sl@0: TRect margin(iViewRect); sl@0: margin.iBr.iX=margin.iTl.iX+iLabelMarginWidth; sl@0: return margin; sl@0: } sl@0: sl@0: /** Tests whether a label margin has been set. sl@0: @return True if a label margin has been set. False if not. */ sl@0: EXPORT_C TBool TDrawTextLayoutContext::IsLabelMargin() const sl@0: { sl@0: return iGutterMarginWidth > 0; sl@0: } sl@0: sl@0: /** Gets the area occupied by the gutter margin. sl@0: @return Rectangle representing the gutter margin. */ sl@0: EXPORT_C TRect TDrawTextLayoutContext::GutterMargin() const sl@0: { sl@0: TRect margin(iViewRect); sl@0: margin.iTl.iX+=iLabelMarginWidth; sl@0: margin.iBr.iX=margin.iTl.iX+iGutterMarginWidth; sl@0: return margin; sl@0: } sl@0: sl@0: /** This function is identical to IsLabelMargin(). sl@0: @return True if a label margin has been set, false if not. */ sl@0: EXPORT_C TBool TDrawTextLayoutContext::IsGutterMargin() const sl@0: { sl@0: return iGutterMarginWidth > 0; sl@0: } sl@0: sl@0: /** Gets the window coordinates of the top left hand corner at which text may sl@0: be drawn. This point has the same vertical coordinate as the top of the text sl@0: area, but its horizontal coordinate is increased by the left text margin width sl@0: (iTextStartX). This point is the origin for layout coordinates. sl@0: sl@0: @return The coordinates of the top left hand point at which text can be drawn. sl@0: */ sl@0: EXPORT_C TPoint TDrawTextLayoutContext::TopLeftText() const sl@0: { sl@0: return TopLeftTextArea()+TPoint(iTextStartX,0); sl@0: } sl@0: sl@0: /** Converts a point in window coordinates to layout coordinates. Window sl@0: coordinates have their origin at the top left corner of the view window. Layout sl@0: coordinates have their origin at the top left corner of the area within the sl@0: view rectangle in which text can appear, (this value is returned by sl@0: TopLeftText()). sl@0: @param aWinPos Point in window coordinates. On return, set to layout sl@0: coordinates. */ sl@0: EXPORT_C void TDrawTextLayoutContext::WindowToText(TPoint& aWinPos) const sl@0: { sl@0: aWinPos-=TopLeftText(); sl@0: } sl@0: sl@0: /** Converts a rectangle in window coordinates to layout coordinates. Window sl@0: coordinates have their origin at the top left corner of the view window. Layout sl@0: coordinates have their origin at the top left corner of the area within the sl@0: view rectangle in which text can appear, (this value is returned by sl@0: TopLeftText()). sl@0: @param aRect Rectangle in window coordinates. On return, set to layout sl@0: coordinates. */ sl@0: EXPORT_C void TDrawTextLayoutContext::WindowToText(TRect& aRect) const sl@0: { sl@0: aRect.Move(TPoint(0,0)-TopLeftText()); sl@0: } sl@0: sl@0: /** Converts a point in layout coordinates to window coordinates. sl@0: @param aTextAreaPos A point in layout coordinates. On return, set to window sl@0: coordinates. */ sl@0: EXPORT_C void TDrawTextLayoutContext::TextToWindow(TPoint& aTextAreaPos) const sl@0: { sl@0: aTextAreaPos+=TopLeftText(); sl@0: } sl@0: sl@0: /** Converts a rectangle in layout coordinates to window coordinates. sl@0: @param aRect Rectangle in layout coordinates. On return, set to window sl@0: coordinates. */ sl@0: EXPORT_C void TDrawTextLayoutContext::TextToWindow(TRect& aRect) const sl@0: { sl@0: aRect.Move(TopLeftText()); sl@0: } sl@0: sl@0: /** Tests if a CWindowGc is being used. */ sl@0: TBool TDrawTextLayoutContext::UseWindowGc() const sl@0: { sl@0: return iDrawMode & EFUseWindowGc; sl@0: } sl@0: sl@0: /** Returns the current drawing mode flags. */ sl@0: void TDrawTextLayoutContext::SetDrawMode(TUint aDrawMode) sl@0: { sl@0: iDrawMode = aDrawMode; sl@0: } sl@0: sl@0: /** Returns the flags that identify the current drawing mode. */ sl@0: TUint TDrawTextLayoutContext::DrawMode() const sl@0: { sl@0: return iDrawMode; sl@0: }