1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/textandloc/textrendering/texthandling/stext/TXTGLOBL.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,350 @@
1.4 +/*
1.5 +* Copyright (c) 2003-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 <e32std.h>
1.23 +#include <e32base.h>
1.24 +#include <gdi.h>
1.25 +
1.26 +#include "TXTFMLYR.H"
1.27 +#include "TXTGLOBL.H"
1.28 +
1.29 +#include "TXTSTD.H"
1.30 +#include "OstTraceDefinitions.h"
1.31 +#ifdef OST_TRACE_COMPILER_IN_USE
1.32 +#include "TXTGLOBLTraces.h"
1.33 +#endif
1.34 +
1.35 +
1.36 +/**
1.37 +@internalAll
1.38 +*/
1.39 +EXPORT_C void MLayDoc::MLayDoc_Reserved_1() {}
1.40 +EXPORT_C void CGlobalText::__DbgTestInvariant()const
1.41 +// Class Invariants.
1.42 +//
1.43 + {
1.44 +#ifdef _DEBUG
1.45 +// ASSERT: The global format layers are never null.
1.46 + __ASSERT_DEBUG(iGlobalParaFormatLayer!=NULL,User::Invariant());
1.47 + __ASSERT_DEBUG(iGlobalCharFormatLayer!=NULL,User::Invariant());
1.48 +#endif
1.49 + }
1.50 +
1.51 +
1.52 +EXPORT_C CGlobalText* CGlobalText::NewL(const CParaFormatLayer* aGlobalParaLayer,const CCharFormatLayer* aGlobalCharLayer,
1.53 + TDocumentStorage aStorage,TInt aDefaultTextGranularity)
1.54 +/** Allocates and constructs an empty global text object with a paragraph and a
1.55 +character format layer. A single end-of-document delimiter is inserted.
1.56 +
1.57 +@param aGlobalParaLayer Pointer to the paragraph format layer referenced by
1.58 +the text object. Must not be NULL, or a panic occurs.
1.59 +@param aGlobalCharLayer Pointer to the character format layer referenced by
1.60 +the text object. Must not be NULL, or a panic occurs.
1.61 +@param aStorage The type of in-memory buffer to use. Defaults to
1.62 +ESegmentedStorage.
1.63 +@param aDefaultTextGranularity Specifies the granularity of the in-memory buffer.
1.64 +Default is EDefaultTextGranularity bytes (=256).
1.65 +@return Pointer to the global text object. */
1.66 + {
1.67 + if (aGlobalParaLayer==NULL)
1.68 + {
1.69 + OstTrace0( TRACE_FATAL, CGLOBALTEXT_NEWL, "ENullFormatLayerHandle" );
1.70 + }
1.71 + __ASSERT_ALWAYS(aGlobalParaLayer!=NULL,Panic(ENullFormatLayerHandle));
1.72 + if (aGlobalCharLayer==NULL)
1.73 + {
1.74 + OstTrace0( TRACE_FATAL, DUP1_CGLOBALTEXT_NEWL, "ENullFormatLayerHandle" );
1.75 + }
1.76 + __ASSERT_ALWAYS(aGlobalCharLayer!=NULL,Panic(ENullFormatLayerHandle));
1.77 +
1.78 + CGlobalText* self=new(ELeave) CGlobalText(aGlobalParaLayer,aGlobalCharLayer);
1.79 + CleanupStack::PushL(self);
1.80 + self->ConstructL(aStorage,aDefaultTextGranularity);
1.81 + CleanupStack::Pop();
1.82 + return self;
1.83 + }
1.84 +
1.85 +EXPORT_C CGlobalText* CGlobalText::NewL(const CStreamStore& aStore,TStreamId aStreamId,
1.86 + const CParaFormatLayer* aGlobalParaLayer,const CCharFormatLayer* aGlobalCharLayer,
1.87 + MTextFieldFactory* aFactory,
1.88 + TDocumentStorage aStorage)
1.89 +/** Returns a handle to a new instance of this class, whose textual content is
1.90 +restored from the specified read-stream. The global text object *uses* (does
1.91 +not own) the supplied global format layers.*/
1.92 + {
1.93 + if (aGlobalParaLayer==NULL)
1.94 + {
1.95 + OstTrace0( TRACE_FATAL, DUP2_CGLOBALTEXT_NEWL, "ENullFormatLayerHandle" );
1.96 + }
1.97 + __ASSERT_ALWAYS(aGlobalParaLayer!=NULL,Panic(ENullFormatLayerHandle));
1.98 + if (aGlobalCharLayer==NULL)
1.99 + {
1.100 + OstTrace0( TRACE_FATAL, DUP3_CGLOBALTEXT_NEWL, "ENullFormatLayerHandle" );
1.101 + }
1.102 + __ASSERT_ALWAYS(aGlobalCharLayer!=NULL,Panic(ENullFormatLayerHandle));
1.103 +
1.104 + CGlobalText* self=new(ELeave) CGlobalText(aGlobalParaLayer,aGlobalCharLayer);
1.105 + CleanupStack::PushL(self);
1.106 + self->ConstructL(aStore,aStreamId,aFactory,aStorage);
1.107 + CleanupStack::Pop();
1.108 + return self;
1.109 + }
1.110 +
1.111 +
1.112 +EXPORT_C CGlobalText::CGlobalText()
1.113 + {}
1.114 +
1.115 +
1.116 +EXPORT_C CGlobalText::CGlobalText(const CParaFormatLayer* aGlobalParaLayer,const CCharFormatLayer* aGlobalCharLayer):
1.117 + iGlobalParaFormatLayer(aGlobalParaLayer),
1.118 + iGlobalCharFormatLayer(aGlobalCharLayer)
1.119 + {
1.120 + __TEST_INVARIANT;
1.121 + }
1.122 +
1.123 +EXPORT_C CGlobalText::~CGlobalText()
1.124 +/** The destructor is empty, and is present only to cause the virtual function
1.125 +table to be defined in a unique module. */
1.126 + {}
1.127 +
1.128 +EXPORT_C void CGlobalText::SetGlobalParaFormat(const CParaFormatLayer* aParaFormatLayer)
1.129 +/** Replaces the paragraph format layer referenced by the global text object.
1.130 +
1.131 +@param aParaFormatLayer Pointer to the paragraph format layer to be referenced
1.132 +by the global text object. */
1.133 + {
1.134 + iGlobalParaFormatLayer=aParaFormatLayer;
1.135 + CEditableText::SetHasChanged(ETrue);
1.136 +
1.137 + __TEST_INVARIANT;
1.138 + }
1.139 +
1.140 +EXPORT_C void CGlobalText::SetGlobalCharFormat(const CCharFormatLayer* aCharFormatLayer)
1.141 +/** Replaces the character format layer referenced by the global text object.
1.142 +
1.143 +@param aCharFormatLayer Pointer to the character format layer to be referenced
1.144 +by the global text object. */
1.145 + {
1.146 + iGlobalCharFormatLayer=aCharFormatLayer;
1.147 + CEditableText::SetHasChanged(ETrue);
1.148 +
1.149 + __TEST_INVARIANT;
1.150 + }
1.151 +
1.152 +
1.153 +EXPORT_C void CGlobalText::ApplyParaFormatL(const CParaFormat* aFormat,const TParaFormatMask& aMask,
1.154 + TInt /*aPos*/,TInt /*aLength*/)
1.155 +/** Changes the text object's paragraph formatting. The attributes which are
1.156 +set in the mask are read from aFormat into the text object's paragraph format
1.157 +layer. The attributes which are not set in the mask are not changed. Note
1.158 +that the position and length arguments are only used in the rich text
1.159 +implementation of this function.
1.160 +
1.161 +@param aFormat Contains the paragraph format attribute values to apply.
1.162 +@param aMask Bitmask specifying the paragraph format attributes to change.
1.163 +@param aPos This argument is not used for global text.
1.164 +@param aLength This argument is not used for global text. */
1.165 + {
1.166 +
1.167 + __TEST_INVARIANT;
1.168 +
1.169 + TParaFormatMask applyMask=aMask;
1.170 + CParaFormat* pf=CParaFormat::NewL(*aFormat);
1.171 + CleanupStack::PushL(pf);
1.172 + iGlobalParaFormatLayer->SenseL(pf,applyMask);
1.173 + CONST_CAST(CParaFormatLayer*,iGlobalParaFormatLayer)->SetL(pf,applyMask);
1.174 + CleanupStack::PopAndDestroy(); // pf
1.175 + CEditableText::SetHasChanged(ETrue);
1.176 +
1.177 + __TEST_INVARIANT;
1.178 + }
1.179 +
1.180 +EXPORT_C void CGlobalText::ApplyCharFormatL(const TCharFormat& aFormat,const TCharFormatMask& aMask,
1.181 + TInt /*aPos*/,TInt /*aLength*/)
1.182 +/** Changes the text object's character formatting. The attributes which are
1.183 +set in the mask are read from aFormat into the text object's character format
1.184 +layer. The attributes which are not set in the mask are not changed. Note
1.185 +that the position and length arguments are only used in the rich text
1.186 +implementation of this function.
1.187 +
1.188 +@param aFormat Contains the character format attribute values to apply.
1.189 +@param aMask Bitmask specifying the character format attributes to change.
1.190 +@param aPos This argument is not used for global text.
1.191 +@param aLength This argument is not used for global text. */
1.192 + {
1.193 +
1.194 + __TEST_INVARIANT;
1.195 +
1.196 + TCharFormatMask applyMask=aMask;
1.197 + TCharFormat cf(aFormat);
1.198 + iGlobalCharFormatLayer->Sense(cf,applyMask);
1.199 + (CONST_CAST(CCharFormatLayer*,iGlobalCharFormatLayer))->SetL(cf,applyMask);
1.200 + CEditableText::SetHasChanged(ETrue);
1.201 +
1.202 + __TEST_INVARIANT;
1.203 + }
1.204 +
1.205 +EXPORT_C TInt CGlobalText::LdDocumentLength()const
1.206 +/** Gets the the number of characters in the document.
1.207 +
1.208 +Note: the count includes all non-printing characters but excludes the end
1.209 +of text paragraph delimiter, so that the smallest return value is always zero.
1.210 +
1.211 +@return The number of characters contained in the document. */
1.212 + {
1.213 + __TEST_INVARIANT;
1.214 +
1.215 + return CPlainText::DocumentLength();
1.216 + }
1.217 +
1.218 +EXPORT_C TInt CGlobalText::LdToParagraphStart(TInt& aCurrentPos)const
1.219 +/** Gets the document position of the start of the paragraph containing a
1.220 +specified document position.
1.221 +
1.222 +@param aCurrentPos Specifies a document position: must be valid or a panic
1.223 +occurs. On return, specifies the document position of the first character
1.224 +in the paragraph in which it is located.
1.225 +@return The number of characters skipped in scanning to the start of the
1.226 +paragraph. */
1.227 + {
1.228 + __TEST_INVARIANT;
1.229 +
1.230 + return CPlainText::ToParagraphStart(aCurrentPos);
1.231 + }
1.232 +
1.233 +EXPORT_C TBool CGlobalText::EnquirePageBreak(TInt aPos,TInt aLength)const
1.234 +/** Tests whether a page break occurs within a range of characters. Returns
1.235 +false if no page table has been set up: see CPlainText::SetPageTable(). The
1.236 +start and end of the range must be valid document positions, or a panic occurs.
1.237 +
1.238 +@param aPos The document position from which to begin searching for a page
1.239 +break.
1.240 +@param aLength The number of characters to search for a page break, beginning
1.241 +at aPos. The default is zero.
1.242 +@return ETrue if a page break occurs within the specified range, otherwise
1.243 +EFalse. */
1.244 + {
1.245 + __TEST_INVARIANT;
1.246 +
1.247 + return PageContainingPos(aPos+aLength)>PageContainingPos(aPos);
1.248 + }
1.249 +
1.250 +EXPORT_C void CGlobalText::GetChars(TPtrC& aView,TCharFormat& aFormat,TInt aStartPos)const
1.251 +/** Gets a constant pointer descriptor to a portion of the text object. The
1.252 +portion starts at document position aStartPos, and ends at the end of the
1.253 +document, or the end of the segment, if segmented storage is being used. Also
1.254 +fills a character format object with the text object's effective character
1.255 +formatting. The start position must be valid, or a panic occurs.
1.256 +
1.257 +@param aView On return, a constant pointer to a portion of the text.
1.258 +@param aFormat On return, contains the text object's effective character
1.259 +formatting.
1.260 +@param aStartPos The start position for the view. */
1.261 + {
1.262 + if (aStartPos<0 || aStartPos>DocumentLength())
1.263 + {
1.264 + OstTrace0( TRACE_FATAL, CGLOBALTEXT_GETCHARS, "ECharPosBeyondDocument" );
1.265 + }
1.266 + __ASSERT_ALWAYS(aStartPos>=0 && aStartPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
1.267 +
1.268 + aView.Set(Read(aStartPos));
1.269 + iGlobalCharFormatLayer->SenseEffective(aFormat);
1.270 + OverrideFormatOfInlineTextIfApplicable(aView,aFormat,aStartPos);
1.271 + }
1.272 +
1.273 +EXPORT_C void CGlobalText::GetParagraphFormatL(CParaFormat* aFormat,TInt /*aPos*/) const
1.274 +/** Gets the text object's effective paragraph formatting. The aPos value is
1.275 +only used in the rich text implementation of this function.
1.276 +
1.277 +@param aFormat On return, filled with the text object's effective paragraph
1.278 +formatting.
1.279 +@param aPos This argument is not used for global text. */
1.280 + {
1.281 + // Get the paragraph format. Global text has a single unvarying character format so aPos is ignored.
1.282 + iGlobalParaFormatLayer->SenseEffectiveL(aFormat);
1.283 + }
1.284 +
1.285 +
1.286 +EXPORT_C void CGlobalText::GetParaFormatL(CParaFormat* aFormat,TParaFormatMask& aVaries,TInt /*aPos*/,TInt /*aLength*/,
1.287 + CParaFormat::TParaFormatGetMode aMode) const
1.288 +/** Gets the the global text object's effective paragraph formatting. Note that
1.289 +the position and length arguments are only used in the rich text implementation
1.290 +of this function.
1.291 +
1.292 +@param aFormat Must not be NULL or a panic occurs. On return, contains the
1.293 +effective paragraph formatting for the global text object.
1.294 +@param aVaries On return, a bitmask indicating which paragraph format attributes
1.295 +vary over the range of characters selected. This is only relevant for rich
1.296 +text, so for global text returns a value of zero for all attributes.
1.297 +@param aPos This argument is not used for global text.
1.298 +@param aLength This argument is not used for global text.
1.299 +@param aMode The default, EAllAttributes indicates that values for all paragraph
1.300 +format attributes are written to aFormat. EFixedAttributes indicates that
1.301 +tabs, bullets and borders are not written to aFormat. */
1.302 + {
1.303 + iGlobalParaFormatLayer->SenseEffectiveL(aFormat,aMode);
1.304 + aVaries.ClearAll();
1.305 + }
1.306 +
1.307 +
1.308 +
1.309 +EXPORT_C void CGlobalText::GetCharFormat(TCharFormat& aFormat,TCharFormatMask& aVaries,
1.310 + TInt /*aPos*/,TInt /*aLength*/) const
1.311 +/** Gets the global text object's effective character formatting. Note that the
1.312 +last three arguments are not relevant to the global text implementation of
1.313 +this function.
1.314 +
1.315 +@param aFormat On return, contains the effective character formatting for
1.316 +the global text object.
1.317 +@param aVaries On return, a bitmask indicating which character format attributes
1.318 +vary over the range of characters selected. This is only relevant for rich
1.319 +text, so for global text returns a value of zero for all attributes.
1.320 +@param aPos This argument is not used for global text.
1.321 +@param aLength This argument is not used for global text. */
1.322 + {
1.323 + iGlobalCharFormatLayer->SenseEffective(aFormat);
1.324 + aVaries.ClearAll();
1.325 + }
1.326 +
1.327 +EXPORT_C CPicture* CGlobalText::PictureHandleL(TInt /*aPos*/,MLayDoc::TForcePictureLoad /*aForceLoad*/) const
1.328 +/** Global text provides no support for pictures, so this implementation
1.329 +of the function returns NULL. */
1.330 + {
1.331 + // Global text provides no support for pictures.
1.332 + return NULL;
1.333 + }
1.334 +
1.335 +EXPORT_C TInt CGlobalText::GetPictureSizeInTwips(TSize& /*aSize*/, TInt /*aPos*/) const
1.336 +/** Global text provides no support for pictures, so this implementation
1.337 +of the function returns KErrNotFound. */
1.338 + {
1.339 + // Global text provides no support for pictures.
1.340 + return KErrNotFound;
1.341 + }
1.342 +
1.343 +EXPORT_C TBool CGlobalText::SelectParagraphLabel(TInt /*aPos*/)
1.344 +/** Global text does not support paragraph labels, so this function
1.345 +returns EFalse. */
1.346 + {
1.347 + return EFalse;
1.348 + }
1.349 +
1.350 +EXPORT_C void CGlobalText::CancelSelectLabel()
1.351 +/** Not supported. */
1.352 + {
1.353 + }