textrendering/texthandling/stext/TXTGLOBL.CPP
changeset 0 1fb32624e06b
child 40 91ef7621b7fc
equal deleted inserted replaced
-1:000000000000 0:1fb32624e06b
       
     1 /*
       
     2 * Copyright (c) 2003-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 <e32std.h>
       
    20 #include <e32base.h>
       
    21 #include <gdi.h>
       
    22 
       
    23 #include "TXTFMLYR.H"
       
    24 #include "TXTGLOBL.H"
       
    25 
       
    26 #include "TXTSTD.H"
       
    27 
       
    28 /**
       
    29 @internalAll
       
    30 */
       
    31 EXPORT_C void MLayDoc::MLayDoc_Reserved_1() {}
       
    32 EXPORT_C void CGlobalText::__DbgTestInvariant()const
       
    33 // Class Invariants.
       
    34 //
       
    35 	{
       
    36 #ifdef _DEBUG
       
    37 // ASSERT: The global format layers are never null.
       
    38 	__ASSERT_DEBUG(iGlobalParaFormatLayer!=NULL,User::Invariant());
       
    39 	__ASSERT_DEBUG(iGlobalCharFormatLayer!=NULL,User::Invariant());
       
    40 #endif
       
    41 	}
       
    42 
       
    43 
       
    44 EXPORT_C CGlobalText* CGlobalText::NewL(const CParaFormatLayer* aGlobalParaLayer,const CCharFormatLayer* aGlobalCharLayer,
       
    45 										TDocumentStorage aStorage,TInt aDefaultTextGranularity)
       
    46 /** Allocates and constructs an empty global text object with a paragraph and a 
       
    47 character format layer. A single end-of-document delimiter is inserted.
       
    48 
       
    49 @param aGlobalParaLayer Pointer to the paragraph format layer referenced by 
       
    50 the text object. Must not be NULL, or a panic occurs. 
       
    51 @param aGlobalCharLayer Pointer to the character format layer referenced by 
       
    52 the text object. Must not be NULL, or a panic occurs. 
       
    53 @param aStorage The type of in-memory buffer to use. Defaults to 
       
    54 ESegmentedStorage. 
       
    55 @param aDefaultTextGranularity Specifies the granularity of the in-memory buffer. 
       
    56 Default is EDefaultTextGranularity bytes (=256). 
       
    57 @return Pointer to the global text object. */
       
    58 	{
       
    59 	__ASSERT_ALWAYS(aGlobalParaLayer!=NULL,Panic(ENullFormatLayerHandle));
       
    60 	__ASSERT_ALWAYS(aGlobalCharLayer!=NULL,Panic(ENullFormatLayerHandle));
       
    61 
       
    62 	CGlobalText* self=new(ELeave) CGlobalText(aGlobalParaLayer,aGlobalCharLayer);
       
    63 	CleanupStack::PushL(self);
       
    64 	self->ConstructL(aStorage,aDefaultTextGranularity);
       
    65 	CleanupStack::Pop();
       
    66 	return self;
       
    67 	}
       
    68 
       
    69 EXPORT_C CGlobalText* CGlobalText::NewL(const CStreamStore& aStore,TStreamId aStreamId,
       
    70 										const CParaFormatLayer* aGlobalParaLayer,const CCharFormatLayer* aGlobalCharLayer,
       
    71 										MTextFieldFactory* aFactory,
       
    72 										TDocumentStorage aStorage)
       
    73 /** Returns a handle to a new instance of this class, whose textual content is 
       
    74 restored from the specified read-stream.  The global text object *uses* (does 
       
    75 not own) the supplied global format layers.*/
       
    76 	{
       
    77 	__ASSERT_ALWAYS(aGlobalParaLayer!=NULL,Panic(ENullFormatLayerHandle));
       
    78 	__ASSERT_ALWAYS(aGlobalCharLayer!=NULL,Panic(ENullFormatLayerHandle));
       
    79 
       
    80 	CGlobalText* self=new(ELeave) CGlobalText(aGlobalParaLayer,aGlobalCharLayer);
       
    81 	CleanupStack::PushL(self);
       
    82 	self->ConstructL(aStore,aStreamId,aFactory,aStorage);
       
    83 	CleanupStack::Pop();
       
    84 	return self;
       
    85 	}
       
    86 
       
    87 
       
    88 EXPORT_C CGlobalText::CGlobalText()
       
    89 	{}
       
    90 
       
    91 
       
    92 EXPORT_C CGlobalText::CGlobalText(const CParaFormatLayer* aGlobalParaLayer,const CCharFormatLayer* aGlobalCharLayer):
       
    93 	iGlobalParaFormatLayer(aGlobalParaLayer),
       
    94 	iGlobalCharFormatLayer(aGlobalCharLayer)
       
    95 	{
       
    96 	__TEST_INVARIANT;
       
    97 	}
       
    98 
       
    99 EXPORT_C CGlobalText::~CGlobalText()
       
   100 /** The destructor is empty, and is present only to cause the virtual function 
       
   101 table to be defined in a unique module. */
       
   102 	{}
       
   103 
       
   104 EXPORT_C void CGlobalText::SetGlobalParaFormat(const CParaFormatLayer* aParaFormatLayer)
       
   105 /** Replaces the paragraph format layer referenced by the global text object.
       
   106 
       
   107 @param aParaFormatLayer Pointer to the paragraph format layer to be referenced 
       
   108 by the global text object. */
       
   109 	{
       
   110 	iGlobalParaFormatLayer=aParaFormatLayer;
       
   111 	CEditableText::SetHasChanged(ETrue);
       
   112 	
       
   113 	__TEST_INVARIANT;
       
   114 	}
       
   115 
       
   116 EXPORT_C void CGlobalText::SetGlobalCharFormat(const CCharFormatLayer* aCharFormatLayer)
       
   117 /** Replaces the character format layer referenced by the global text object.
       
   118 
       
   119 @param aCharFormatLayer Pointer to the character format layer to be referenced 
       
   120 by the global text object. */
       
   121 	{
       
   122 	iGlobalCharFormatLayer=aCharFormatLayer;
       
   123 	CEditableText::SetHasChanged(ETrue);
       
   124 	
       
   125 	__TEST_INVARIANT;
       
   126 	}
       
   127 
       
   128  
       
   129 EXPORT_C void CGlobalText::ApplyParaFormatL(const CParaFormat* aFormat,const TParaFormatMask& aMask,
       
   130 											TInt /*aPos*/,TInt /*aLength*/)
       
   131 /** Changes the text object's paragraph formatting. The attributes which are 
       
   132 set in the mask are read from aFormat into the text object's paragraph format 
       
   133 layer. The attributes which are not set in the mask are not changed. Note 
       
   134 that the position and length arguments are only used in the rich text 
       
   135 implementation of this function.
       
   136 
       
   137 @param aFormat Contains the paragraph format attribute values to apply. 
       
   138 @param aMask Bitmask specifying the paragraph format attributes to change. 
       
   139 @param aPos This argument is not used for global text. 
       
   140 @param aLength This argument is not used for global text. */
       
   141 	{
       
   142  
       
   143 	__TEST_INVARIANT;
       
   144 
       
   145 	TParaFormatMask applyMask=aMask;
       
   146 	CParaFormat* pf=CParaFormat::NewL(*aFormat);
       
   147 	CleanupStack::PushL(pf);
       
   148 	iGlobalParaFormatLayer->SenseL(pf,applyMask);
       
   149 	CONST_CAST(CParaFormatLayer*,iGlobalParaFormatLayer)->SetL(pf,applyMask);
       
   150 	CleanupStack::PopAndDestroy();  // pf
       
   151 	CEditableText::SetHasChanged(ETrue);
       
   152 
       
   153 	__TEST_INVARIANT;
       
   154 	}
       
   155 
       
   156 EXPORT_C void CGlobalText::ApplyCharFormatL(const TCharFormat& aFormat,const TCharFormatMask& aMask,
       
   157 											TInt /*aPos*/,TInt /*aLength*/)
       
   158 /** Changes the text object's character formatting. The attributes which are 
       
   159 set in the mask are read from aFormat into the text object's character format 
       
   160 layer. The attributes which are not set in the mask are not changed. Note 
       
   161 that the position and length arguments are only used in the rich text 
       
   162 implementation of this function.
       
   163 
       
   164 @param aFormat Contains the character format attribute values to apply. 
       
   165 @param aMask Bitmask specifying the character format attributes to change. 
       
   166 @param aPos This argument is not used for global text. 
       
   167 @param aLength This argument is not used for global text. */
       
   168 	{
       
   169 
       
   170 	__TEST_INVARIANT;
       
   171 
       
   172 	TCharFormatMask applyMask=aMask;
       
   173 	TCharFormat cf(aFormat);
       
   174 	iGlobalCharFormatLayer->Sense(cf,applyMask);
       
   175 	(CONST_CAST(CCharFormatLayer*,iGlobalCharFormatLayer))->SetL(cf,applyMask);
       
   176 	CEditableText::SetHasChanged(ETrue);
       
   177 
       
   178 	__TEST_INVARIANT;
       
   179 	}
       
   180 
       
   181 EXPORT_C TInt CGlobalText::LdDocumentLength()const
       
   182 /** Gets the the number of characters in the document.
       
   183 
       
   184 Note: the count includes all non-printing characters but excludes the end 
       
   185 of text paragraph delimiter, so that the smallest return value is always zero.
       
   186 
       
   187 @return The number of characters contained in the document. */
       
   188    {
       
   189    __TEST_INVARIANT;
       
   190    
       
   191    return CPlainText::DocumentLength();
       
   192    }
       
   193 
       
   194 EXPORT_C TInt CGlobalText::LdToParagraphStart(TInt& aCurrentPos)const
       
   195 /** Gets the document position of the start of the paragraph containing a 
       
   196 specified document position.
       
   197 
       
   198 @param aCurrentPos Specifies a document position: must be valid or a panic 
       
   199 occurs. On return, specifies the document position of the first character 
       
   200 in the paragraph in which it is located. 
       
   201 @return The number of characters skipped in scanning to the start of the 
       
   202 paragraph. */
       
   203 	{
       
   204 	__TEST_INVARIANT;
       
   205 
       
   206 	return CPlainText::ToParagraphStart(aCurrentPos);
       
   207 	}
       
   208 
       
   209 EXPORT_C TBool CGlobalText::EnquirePageBreak(TInt aPos,TInt aLength)const
       
   210 /** Tests whether a page break occurs within a range of characters. Returns 
       
   211 false if no page table has been set up: see CPlainText::SetPageTable(). The 
       
   212 start and end of the range must be valid document positions, or a panic occurs.
       
   213 
       
   214 @param aPos The document position from which to begin searching for a page 
       
   215 break. 
       
   216 @param aLength The number of characters to search for a page break, beginning 
       
   217 at aPos. The default is zero. 
       
   218 @return ETrue if a page break occurs within the specified range, otherwise 
       
   219 EFalse. */
       
   220 	{
       
   221 	__TEST_INVARIANT;
       
   222 
       
   223 	return PageContainingPos(aPos+aLength)>PageContainingPos(aPos);
       
   224 	}
       
   225 
       
   226 EXPORT_C void CGlobalText::GetChars(TPtrC& aView,TCharFormat& aFormat,TInt aStartPos)const
       
   227 /** Gets a constant pointer descriptor to a portion of the text object. The 
       
   228 portion starts at document position aStartPos, and ends at the end of the 
       
   229 document, or the end of the segment, if segmented storage is being used. Also 
       
   230 fills a character format object with the text object's effective character 
       
   231 formatting. The start position must be valid, or a panic occurs.
       
   232 
       
   233 @param aView On return, a constant pointer to a portion of the text. 
       
   234 @param aFormat On return, contains the text object's effective character 
       
   235 formatting. 
       
   236 @param aStartPos The start position for the view. */
       
   237 	{
       
   238 	__ASSERT_ALWAYS(aStartPos>=0 && aStartPos<=DocumentLength(),Panic(ECharPosBeyondDocument));
       
   239 
       
   240 	aView.Set(Read(aStartPos));
       
   241 	iGlobalCharFormatLayer->SenseEffective(aFormat);
       
   242 	OverrideFormatOfInlineTextIfApplicable(aView,aFormat,aStartPos);
       
   243 	}
       
   244 
       
   245 EXPORT_C void CGlobalText::GetParagraphFormatL(CParaFormat* aFormat,TInt /*aPos*/) const
       
   246 /** Gets the text object's effective paragraph formatting. The aPos value is 
       
   247 only used in the rich text implementation of this function.
       
   248 
       
   249 @param aFormat On return, filled with the text object's effective paragraph 
       
   250 formatting. 
       
   251 @param aPos This argument is not used for global text. */
       
   252 	{
       
   253 	// Get the paragraph format. Global text has a single unvarying character format so aPos is ignored.
       
   254 	iGlobalParaFormatLayer->SenseEffectiveL(aFormat);
       
   255 	}
       
   256 
       
   257  
       
   258 EXPORT_C void CGlobalText::GetParaFormatL(CParaFormat* aFormat,TParaFormatMask& aVaries,TInt /*aPos*/,TInt /*aLength*/,
       
   259 										  CParaFormat::TParaFormatGetMode aMode) const
       
   260 /** Gets the the global text object's effective paragraph formatting. Note that 
       
   261 the position and length arguments are only used in the rich text implementation 
       
   262 of this function.
       
   263 
       
   264 @param aFormat Must not be NULL or a panic occurs. On return, contains the 
       
   265 effective paragraph formatting for the global text object. 
       
   266 @param aVaries On return, a bitmask indicating which paragraph format attributes 
       
   267 vary over the range of characters selected. This is only relevant for rich 
       
   268 text, so for global text returns a value of zero for all attributes. 
       
   269 @param aPos This argument is not used for global text. 
       
   270 @param aLength This argument is not used for global text. 
       
   271 @param aMode The default, EAllAttributes indicates that values for all paragraph 
       
   272 format attributes are written to aFormat. EFixedAttributes indicates that 
       
   273 tabs, bullets and borders are not written to aFormat. */
       
   274 	{
       
   275 	iGlobalParaFormatLayer->SenseEffectiveL(aFormat,aMode);
       
   276 	aVaries.ClearAll();
       
   277 	}
       
   278 
       
   279 
       
   280 
       
   281 EXPORT_C void CGlobalText::GetCharFormat(TCharFormat& aFormat,TCharFormatMask& aVaries,
       
   282 										 TInt /*aPos*/,TInt /*aLength*/) const
       
   283 /** Gets the global text object's effective character formatting. Note that the 
       
   284 last three arguments are not relevant to the global text implementation of 
       
   285 this function.
       
   286 
       
   287 @param aFormat On return, contains the effective character formatting for 
       
   288 the global text object. 
       
   289 @param aVaries On return, a bitmask indicating which character format attributes 
       
   290 vary over the range of characters selected. This is only relevant for rich 
       
   291 text, so for global text returns a value of zero for all attributes. 
       
   292 @param aPos This argument is not used for global text. 
       
   293 @param aLength This argument is not used for global text. */
       
   294 	{
       
   295 	iGlobalCharFormatLayer->SenseEffective(aFormat);
       
   296 	aVaries.ClearAll();
       
   297 	}
       
   298 
       
   299 EXPORT_C CPicture* CGlobalText::PictureHandleL(TInt /*aPos*/,MLayDoc::TForcePictureLoad /*aForceLoad*/) const
       
   300 /**  Global text provides no support for pictures, so this implementation
       
   301 of the function returns NULL. */
       
   302 	{
       
   303 	// Global text provides no support for pictures.
       
   304 	return NULL;
       
   305 	}
       
   306 
       
   307 EXPORT_C TInt CGlobalText::GetPictureSizeInTwips(TSize& /*aSize*/, TInt /*aPos*/) const
       
   308 /** Global text provides no support for pictures, so this implementation
       
   309 of the function returns KErrNotFound. */	
       
   310 	{
       
   311 	// Global text provides no support for pictures.
       
   312 	return KErrNotFound;
       
   313 	}
       
   314 
       
   315 EXPORT_C TBool CGlobalText::SelectParagraphLabel(TInt /*aPos*/)
       
   316 /** Global text does not support paragraph labels, so this function
       
   317 returns EFalse. */	
       
   318     {
       
   319 	return EFalse;
       
   320 	}
       
   321 
       
   322 EXPORT_C void CGlobalText::CancelSelectLabel()
       
   323 /** Not supported. */
       
   324 	{
       
   325 	}