1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/epoc32/include/mw/eiklabel.h Wed Mar 31 12:33:34 2010 +0100
1.3 @@ -0,0 +1,422 @@
1.4 +/*
1.5 +* Copyright (c) 1997-1999 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 +#if !defined(__EIKLABEL_H__)
1.23 +#define __EIKLABEL_H__
1.24 +
1.25 +
1.26 +#if !defined(__EIKALIGN_H__)
1.27 +#include <eikalign.h>
1.28 +#endif
1.29 +
1.30 +#if !defined(__COECCNTX_H__)
1.31 +#include <coeccntx.h>
1.32 +#endif
1.33 +
1.34 +#include <bidi.h>
1.35 +
1.36 +class CEikLabelExtension;
1.37 +class CAknPictographInterface;
1.38 +
1.39 +/**
1.40 + * Enables one or more lines of text to be displayed.
1.41 + */
1.42 +class CEikLabel : public CEikAlignedControl, public MCoeControlContext
1.43 + {
1.44 +public: // new functions
1.45 + /**
1.46 + * Destructor.
1.47 + */
1.48 + IMPORT_C ~CEikLabel();
1.49 + /**
1.50 + * C++ default constructor.
1.51 + */
1.52 + IMPORT_C CEikLabel();
1.53 + /**
1.54 + * Sets the labels alignment. Overwrites alignment set
1.55 + * via @c CEikAlignedControl.
1.56 + *
1.57 + * @param aAlignment Should be one of { @c ELayoutAlignNone,
1.58 + * @c ELayoutAlignCenter, @c ELayoutAlignLeft, @c ELayoutAlignRight,
1.59 + * @c ELayoutAlignBidi } defined in @c Avkon.hrh.
1.60 + */
1.61 + IMPORT_C void SetLabelAlignment(TInt aAlignment);
1.62 +
1.63 + /**
1.64 + * Sets the brush style to be used from @c aBrushStyle,
1.65 + * this overwrites the brush style set via the Control Context.
1.66 + *
1.67 + * @param aBrushStyle A brush style.
1.68 + */
1.69 + IMPORT_C void SetBrushStyle(CWindowGc::TBrushStyle aBrushStyle);
1.70 +
1.71 + /**
1.72 + * Sets the brush style to be used from the Control Context,
1.73 + * this overwrites the brush style set via the @c CEikLabel::SetBrushStyle().
1.74 + */
1.75 + IMPORT_C void SetBrushStyleFromContext();
1.76 +
1.77 +
1.78 +public: // from CCoeControl
1.79 + /**
1.80 + * From @c CCoeControl.
1.81 + *
1.82 + * Sets the control's minimum required size.
1.83 + *
1.84 + * @return Minimum size required by the control.
1.85 + */
1.86 + IMPORT_C TSize MinimumSize();
1.87 + /**
1.88 + * From @c CCoeControl.
1.89 + *
1.90 + * Constructs the control from a resource file.
1.91 + *
1.92 + * @param aReader Interprets resource data read from a resource file.
1.93 + */
1.94 + IMPORT_C void ConstructFromResourceL(TResourceReader& aReader);
1.95 +
1.96 + /**
1.97 + * From @c CCoeControl.
1.98 + *
1.99 + * Gets the list of logical colours used to draw the control.
1.100 + *
1.101 + * @param aColorUseList The colour list.
1.102 + */
1.103 + IMPORT_C void GetColorUseListL(
1.104 + CArrayFix<TCoeColorUse>& aColorUseList) const;
1.105 + /**
1.106 + * From @c CCoeControl.
1.107 + *
1.108 + * Handles a change to the control's resources.
1.109 + *
1.110 + * @param aType A message UID value.
1.111 + */
1.112 + IMPORT_C void HandleResourceChange(TInt aType); // not available before Release 005u
1.113 + /**
1.114 + * From @c CCoeControl.
1.115 + *
1.116 + * Draw a control - called by window server. All controls, except blank
1.117 + * controls, should implement this function. The default implementation
1.118 + * draws a blank control.
1.119 + *
1.120 + * This function is used for window server-initiated redrawing of controls,
1.121 + * and for some application-initiated drawing. It should be implemented by
1.122 + * each control, but is only called from within @c CCoeControl's member
1.123 + * functions, and not from the derived class. For this reason it is a
1.124 + * private member function of @c CCoeControl.
1.125 + *
1.126 + * @param aRect The region of the control to be redrawn. Co-ordinates are
1.127 + * relative to the control's origin (top left corner).
1.128 + * @panic EEikPanicLabelNullText Panics if label text has not been defined.
1.129 + */
1.130 + IMPORT_C void Draw(const TRect& aRect) const;
1.131 +
1.132 +public:
1.133 + /**
1.134 + * Determines text emphasis.
1.135 + */
1.136 + enum TTextEmphasis
1.137 + {
1.138 + /** No emphasis. */
1.139 + ENoEmphasis =0x00,
1.140 +
1.141 + /** Partial emphasis. */
1.142 + EPartialEmphasis =0x10,
1.143 +
1.144 + /** Full emphasis. */
1.145 + EFullEmphasis =0x20
1.146 + };
1.147 +public: // new functions
1.148 +
1.149 + /**
1.150 + * Sets the label’s text.
1.151 + *
1.152 + * @param aText The label’s text.
1.153 + * @panic EEikPanicLabelNullText Panics if label text has not been defined.
1.154 + */
1.155 + IMPORT_C void SetTextL(const TDesC& aText);
1.156 +
1.157 + /**
1.158 + * Gets the label’s text.
1.159 + *
1.160 + * @return The label’s text.
1.161 + */
1.162 + inline const TDesC* Text() const;
1.163 +
1.164 + /**
1.165 + * Sets a flag to indicate that the text needs to be truncated
1.166 + * with 3 dots.
1.167 + */
1.168 + IMPORT_C void CropText();
1.169 +
1.170 + /**
1.171 + * Sets the buffer reserve length.
1.172 + *
1.173 + * @param aLength The buffer reserve length.
1.174 + */
1.175 + IMPORT_C void SetBufferReserveLengthL(TInt aLength);
1.176 +
1.177 + /**
1.178 + * Sets the label’s font.
1.179 + *
1.180 + * @param aFont The label's font.
1.181 + */
1.182 + IMPORT_C void SetFont(const CFont* aFont);
1.183 +
1.184 + /**
1.185 + * Gets the label’s font.
1.186 + *
1.187 + * @return The label’s font.
1.188 + */
1.189 + inline const CFont* Font() const;
1.190 +
1.191 + /**
1.192 + * Sets the label's text emphasis.
1.193 + *
1.194 + * @param aEmphasis The label's text emphasis.
1.195 + */
1.196 + IMPORT_C void SetEmphasis(TTextEmphasis aEmphasis);
1.197 +
1.198 + /**
1.199 + * Sets the gap between lines. Gap has a particular definition here.
1.200 + * It is defined to be: "baselines separation" - @c CFont::HeightInPixels()
1.201 + *
1.202 + * @param aGap Pixels gap to set between lines.
1.203 + */
1.204 + IMPORT_C void SetPixelGapBetweenLines(TInt aGap);
1.205 +
1.206 + /**
1.207 + * Gets the number of pixels between two lines of text.
1.208 + *
1.209 + * @return The number of pixels between two lines of text.
1.210 + */
1.211 + IMPORT_C TInt PixelGapBetweenLines() const;
1.212 +
1.213 + /**
1.214 + * Tests whether the label is underlined.
1.215 + *
1.216 + * @return @c ETrue if the label is set as underlined.
1.217 + * @return @c EFalse if the label is not set as underlined.
1.218 + */
1.219 + inline TBool IsUnderlined() const;
1.220 +
1.221 + /**
1.222 + * Sets the label underlining.
1.223 + *
1.224 + * @param aUnderLining @c ETrue to set the label as underlined.
1.225 + * @c EFalse to set the label as not underlined.
1.226 + */
1.227 + IMPORT_C void SetUnderlining(TBool aUnderLining);
1.228 +
1.229 + /**
1.230 + * Tests label strike-through.
1.231 + *
1.232 + * @return @c ETrue if the label is set to be drawn with a line through it.
1.233 + * @return @c EFalse if the label is not set to be drawn with a line
1.234 + * through it.
1.235 + */
1.236 + inline TBool IsStrikethrough() const;
1.237 +
1.238 + /**
1.239 + * Sets the label strike-through.
1.240 + *
1.241 + * @param aStrikethrough @c ETrue to set the label to be drawn with a line
1.242 + * through it. @c EFalse to set the label to not be drawn with a
1.243 + * line through it.
1.244 + */
1.245 + IMPORT_C void SetStrikethrough(TBool aStrikethrough);
1.246 +
1.247 + /**
1.248 + * Gets the minimum size required to draw the specified text.
1.249 + *
1.250 + * @param aText The text to be drawn.
1.251 + * @return The minimum size required to draw the text.
1.252 + */
1.253 + IMPORT_C TSize CalcMinimumSize(TPtrC& aText) const;
1.254 +
1.255 + /**
1.256 + * Gets the number of lines of text in the label.
1.257 + *
1.258 + * @return The number of lines of text.
1.259 + */
1.260 + inline TUint8 NumberOfLines();
1.261 +
1.262 + /**
1.263 + * Gets the buffer reserve length.
1.264 + *
1.265 + * @return The buffer reserve length.
1.266 + */
1.267 + IMPORT_C TInt BufferReserveLength() const;
1.268 +
1.269 + /**
1.270 + * Enables or disables logical to visual conversion when label text
1.271 + * is drawn. By default, it is enabled.
1.272 + * If you perform the conversion yourself and give visual text
1.273 + * (in scrictly left-to-right order) to label, you
1.274 + * should disable the conversion in label. Note that label does not perform
1.275 + * cropping if logical to visual conversion is disabled.
1.276 + *
1.277 + * @param aUseConversion Whether label should perform logical to visual
1.278 + * conversion or not.
1.279 + */
1.280 + IMPORT_C void UseLogicalToVisualConversion( TBool aUseConversion );
1.281 +
1.282 + /**
1.283 + * Gets information whether label is performing logical to visual
1.284 + * conversion or not.
1.285 + *
1.286 + * @return @c ETrue if label does logical to visual conversion.
1.287 + * @return @c EFalse if not.
1.288 + */
1.289 + IMPORT_C TBool LogicalToVisualConversionUsed() const;
1.290 +
1.291 + /**
1.292 + * Enables pictograph drawing in the label text.
1.293 + * Only effective in Japanese variant.
1.294 + * By default, it is disabled.
1.295 + *
1.296 + * @since S60 2.6
1.297 + * @param aInterface Used pictograph interface owned by the caller.
1.298 + */
1.299 + IMPORT_C void EnablePictographsL( CAknPictographInterface& aInterface );
1.300 +
1.301 + /**
1.302 + * Disables pictograph drawing in the label text.
1.303 + * Only effective in Japanese variant.
1.304 + * By default, it is disabled.
1.305 + *
1.306 + * @since S60 2.6
1.307 + */
1.308 + IMPORT_C void DisablePictographs();
1.309 +public: // From CCoeControl
1.310 +
1.311 + /**
1.312 + * From @c CCoeControl.
1.313 + *
1.314 + * Handles pointer events. This function gets called whenever a pointer
1.315 + * event occurs in the control, i.e. when the pointer is within the
1.316 + * control's extent, or when the control has grabbed the pointer.
1.317 + * The control should implement this function to handle pointer events.
1.318 + *
1.319 + * Note: events of type @c EButton1Down are processed before
1.320 + * @c HandlePointerEventL() is called, in order to transfer keyboard focus
1.321 + * to the control in which the @c EButton1Down event occurred.
1.322 + *
1.323 + * If overriding @c HandlePointerEventL(), the implementation must include
1.324 + * a base call to @c CCoeControl's @c HandlePointerEventL().
1.325 + *
1.326 + * @param aPointerEvent The pointer event.
1.327 + */
1.328 + IMPORT_C void HandlePointerEventL(const TPointerEvent& aPointerEvent);
1.329 +protected: // from CCoeControl
1.330 +
1.331 + /**
1.332 + * From @c CCoeControl.
1.333 + *
1.334 + * Writes the internal state of the control and its components to a stream.
1.335 + * Does nothing in release mode.
1.336 + * Designed to be overidden and base called by subclasses.
1.337 + *
1.338 + * @param aWriteStream The write stream.
1.339 + */
1.340 + IMPORT_C void WriteInternalStateL(RWriteStream& aWriteStream) const;
1.341 +private:
1.342 + IMPORT_C void Reserved_2();
1.343 +private:
1.344 + /**
1.345 + * From @c CAknControl.
1.346 + */
1.347 + IMPORT_C void* ExtensionInterface( TUid aInterface );
1.348 +private: // new functions
1.349 + TInt HeightInPixels() const;
1.350 + TInt WidthInPixels(TPtrC& aText) const;
1.351 + TInt HeightInPixels(const TDesC& aText) const;
1.352 + void SetupGcForEmphasis(CGraphicsContext& aGc) const;
1.353 + TBool CheckAndCreateExtension();
1.354 + void ConvertColorsForOutlineEffect(TRgb& aFillColor, TRgb& aOutlineColor) const;
1.355 +
1.356 +public:
1.357 + /**
1.358 + * @internal
1.359 + */
1.360 + void DrawToContext( CBitmapContext& aContext,
1.361 + const TRgb* aOverrideColor ) const;
1.362 +
1.363 +protected:
1.364 +
1.365 + /**
1.366 + * Determines whether text is drawn with underlining or strike-through.
1.367 + */
1.368 + enum TLabelFlags
1.369 + {
1.370 + /** Text is drawn with underlining. */
1.371 + EUnderlining = 0x02,
1.372 +
1.373 + /** Text is drawn with strike-through. */
1.374 + EStrikethrough = 0x04,
1.375 +
1.376 + /**
1.377 + * Determines that bi-directional algorithm still needs to be run
1.378 + * against the set text string. This flag allows app to do
1.379 + * logical-to-visual conversion in the application side -- since the
1.380 + * bi-directional algorithm can only be run once for every text string,
1.381 + * we need flagging like this to control whether the algorithm is run
1.382 + * inside label or whether the application has already run it and we
1.383 + * should not return the algorithm.
1.384 + */
1.385 + EUseLogicalToVisualConversion = 0x08
1.386 + // flags 0x10, 0x20, 0x40 are already used for text emphasis!
1.387 + };
1.388 +
1.389 + /** The label’s text. */
1.390 + HBufC* iText;
1.391 +
1.392 + /** The label’s font. */
1.393 + const CFont* iFont;
1.394 +
1.395 + /** The label’s number of lines of text. */
1.396 + TUint8 iNumberOfLines;
1.397 +
1.398 + /**
1.399 + * The label’s flags. These are used to set text emphasis and
1.400 + * characteristics, such as underlining, and strikethrough.
1.401 + */
1.402 + TUint8 iLabFlags;
1.403 +
1.404 + /** The number of pixels between lines of text. */
1.405 + TInt iGapBetweenLines;
1.406 +
1.407 +private:
1.408 + TInt iReserveLength;
1.409 + CEikLabelExtension* iExtension;
1.410 + TInt iSpare[2];
1.411 + };
1.412 +
1.413 +
1.414 +inline const TDesC* CEikLabel::Text() const
1.415 + { return(iText); }
1.416 +inline const CFont* CEikLabel::Font() const
1.417 + { return(iFont); }
1.418 +inline TBool CEikLabel::IsUnderlined() const
1.419 + {return iLabFlags&EUnderlining;}
1.420 +inline TBool CEikLabel::IsStrikethrough() const
1.421 + {return iLabFlags&EStrikethrough;}
1.422 +inline TUint8 CEikLabel::NumberOfLines()
1.423 + {return iNumberOfLines;}
1.424 +
1.425 +#endif // __EIKLABEL_H__