|
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 |
|
22 #include <gdi.h> |
|
23 #include "TXTFRMAT.H" |
|
24 |
|
25 #include "TXTSTD.H" |
|
26 |
|
27 |
|
28 const TInt KParaDefaultLanguage=0; |
|
29 const TInt KParaDefaultLeftMargin=0; |
|
30 const TInt KParaDefaultRightMargin=0; |
|
31 const TInt KParaDefaultIndent=0; |
|
32 const CParaFormat::TAlignment KParaDefaultHorizAlign=CParaFormat::ELeftAlign; |
|
33 const CParaFormat::TAlignment KParaDefaultVertAlign=CParaFormat::EUnspecifiedAlign; |
|
34 const TInt KParaDefaultLineSpacing=200; // 200 twips = 10pt |
|
35 const CParaFormat::TLineSpacingControl KParaDefaultLineSpacingControl=CParaFormat::ELineSpacingAtLeastInTwips; |
|
36 const TInt KParaDefaultSpaceBefore=0; |
|
37 const TInt KParaDefaultSpaceAfter=0; |
|
38 const TBool KParaDefaultKeepTogether=EFalse; |
|
39 const TBool KParaDefaultKeepWithNext=EFalse; |
|
40 const TBool KParaDefaultStartNewPage=EFalse; |
|
41 const TBool KParaDefaultWidowOrphan=EFalse; |
|
42 const TBool KParaDefaultWrap=ETrue; |
|
43 const TInt KParaDefaultBorderMargin=0; |
|
44 const TInt KParaDefaultTabWidth=360; // 360 twips = 0.25" |
|
45 const TUint KParFormatBits = (2 << EAttTabStop) - 1; |
|
46 const TUint KCharFormatBits = (2 << (EAttFontHiddenText - EAttCharLanguage)) - 1; |
|
47 |
|
48 |
|
49 EXPORT_C TTabStop::TTabStop(): |
|
50 iTwipsPosition(0), |
|
51 iType(ELeftTab) |
|
52 /** The default C++ constructor constructs a TTabStop. The twips position is |
|
53 initialised to zero and the alignment to ELeftTab. */ |
|
54 { |
|
55 } |
|
56 |
|
57 EXPORT_C TTabStop::TTabStop(const TTabStop& aTabStop): |
|
58 iTwipsPosition(aTabStop.iTwipsPosition), |
|
59 iType(aTabStop.iType) |
|
60 { |
|
61 } |
|
62 |
|
63 EXPORT_C TTabStop& TTabStop::operator=(const TTabStop& aTabStop) |
|
64 /** Assigns the twips position and alignment of aTabStop to the current TTabStop. |
|
65 |
|
66 @param aTabStop The tab stop to assign to the current tab stop. |
|
67 @return The current tab stop. */ |
|
68 { |
|
69 iTwipsPosition=aTabStop.iTwipsPosition; |
|
70 iType=aTabStop.iType; |
|
71 return *this; |
|
72 } |
|
73 |
|
74 EXPORT_C TBool TTabStop::operator==(const TTabStop& aTabStop)const |
|
75 /** Compares two tab stops for equality. To be equal, they must have the same |
|
76 twips position and alignment. |
|
77 |
|
78 @param aTabStop The tab stop to compare with the current tab stop. |
|
79 @return ETrue if both tab stops have the same twips position and alignment. |
|
80 EFalse if not. */ |
|
81 { |
|
82 if (iTwipsPosition!=aTabStop.iTwipsPosition) |
|
83 return EFalse; |
|
84 if (iType!=aTabStop.iType) |
|
85 return EFalse; |
|
86 return ETrue; |
|
87 } |
|
88 |
|
89 EXPORT_C TParaBorder::TParaBorder(): |
|
90 iLineStyle(ENullLineStyle), |
|
91 iThickness(0), |
|
92 iColor(TLogicalRgb::ESystemForegroundColor), |
|
93 iAutoColor(ETrue) |
|
94 /** The default C++ constructor constructs a TParaBorder, initializing its line |
|
95 style to ENullLineStyle, its line thickness to zero, its colour to KRgbBlack |
|
96 and iAutocolor to ETrue. */ |
|
97 { |
|
98 } |
|
99 |
|
100 EXPORT_C TBool TParaBorder::operator==(const TParaBorder& aParaBorder)const |
|
101 /** Compares two paragraph border sides for equality. For two paragraph border |
|
102 sides to be equal, all data members must be equal. |
|
103 |
|
104 @param aBorder The paragraph border to compare with the current border. |
|
105 @return ETrue if the two paragraph border sides are equal, EFalse if not. */ |
|
106 { |
|
107 if (iLineStyle!=aParaBorder.iLineStyle) |
|
108 return EFalse; |
|
109 if (iThickness!=aParaBorder.iThickness) |
|
110 return EFalse; |
|
111 if (iColor!=aParaBorder.iColor) |
|
112 return EFalse; |
|
113 if (iAutoColor!=aParaBorder.iAutoColor) |
|
114 return EFalse; |
|
115 return ETrue; |
|
116 } |
|
117 |
|
118 EXPORT_C TBullet::TBullet(): |
|
119 iCharacterCode(0x2022), |
|
120 iHeightInTwips(0), |
|
121 iHangingIndent(TRUE), |
|
122 iColor(TLogicalRgb::ESystemForegroundColor), |
|
123 iStyle(EBulletStyle), |
|
124 iStartNumber(1), |
|
125 iAlignment(ELeftAlign) |
|
126 /** The default C++ constructor constructs a TBullet, initializing the |
|
127 character code to 0x2022, the height to zero, the colour to the system's |
|
128 default foreground colour and the hanging indent to ETrue. The typeface |
|
129 is not initialised. */ |
|
130 { |
|
131 } |
|
132 |
|
133 EXPORT_C TBool TBullet::operator==(const TBullet& aBullet)const |
|
134 /** Compares two bullet points for equality. For two bullet points to be equal, |
|
135 all data members must be equal. |
|
136 |
|
137 @param aBullet The bullet point to compare. |
|
138 @return ETrue if the two bullet points are equal, EFalse if not. */ |
|
139 { |
|
140 return iCharacterCode == aBullet.iCharacterCode && |
|
141 iHeightInTwips == aBullet.iHeightInTwips && |
|
142 iHangingIndent == aBullet.iHangingIndent && |
|
143 iColor == aBullet.iColor && |
|
144 iStyle == aBullet.iStyle && |
|
145 iStartNumber == aBullet.iStartNumber && |
|
146 iAlignment == aBullet.iAlignment && |
|
147 iTypeface == aBullet.iTypeface; |
|
148 } |
|
149 |
|
150 EXPORT_C CParaFormat* CParaFormat::NewL() |
|
151 /** Allocates and constructs a CParaFormat object. All attributes are |
|
152 initialised with default values. |
|
153 |
|
154 @return The new CParaFormat object. */ |
|
155 { |
|
156 return new(ELeave) CParaFormat; |
|
157 } |
|
158 |
|
159 EXPORT_C CParaFormat* CParaFormat::NewLC() |
|
160 /** Allocates and constructs a CParaFormat object. All attributes are |
|
161 initialised with default values. Leaves the object on the cleanup stack. |
|
162 |
|
163 @return The new CParaFormat object. */ |
|
164 { |
|
165 CParaFormat* self=new(ELeave) CParaFormat; |
|
166 CleanupStack::PushL(self); |
|
167 return self; |
|
168 } |
|
169 |
|
170 EXPORT_C CParaFormat* CParaFormat::NewL(const CParaFormat& aFormat) |
|
171 /** Allocates and constructs a new CParaFormat. All attributes are initialised |
|
172 to the values contained in the aFormat argument. |
|
173 |
|
174 @param aFormat Paragraph format container whose values are used to initialise |
|
175 the new CParaFormat. |
|
176 @return The new CParaFormat object. */ |
|
177 { |
|
178 CParaFormat* self = new(ELeave) CParaFormat(aFormat); |
|
179 CleanupStack::PushL(self); |
|
180 self->CopyL(aFormat); |
|
181 CleanupStack::Pop(); |
|
182 return self; |
|
183 } |
|
184 |
|
185 EXPORT_C CParaFormat::CParaFormat(): |
|
186 iTabList(NULL), |
|
187 iParaBorderArray(NULL), |
|
188 iFillColor(TLogicalRgb::ESystemBackgroundColor), |
|
189 iLanguage(KParaDefaultLanguage), |
|
190 iLeftMarginInTwips(KParaDefaultLeftMargin), |
|
191 iRightMarginInTwips(KParaDefaultRightMargin), |
|
192 iIndentInTwips(KParaDefaultIndent), |
|
193 iHorizontalAlignment(KParaDefaultHorizAlign), |
|
194 iVerticalAlignment(KParaDefaultVertAlign), |
|
195 iLineSpacingInTwips(KParaDefaultLineSpacing), |
|
196 iLineSpacingControl(KParaDefaultLineSpacingControl), |
|
197 iSpaceBeforeInTwips(KParaDefaultSpaceBefore), |
|
198 iSpaceAfterInTwips(KParaDefaultSpaceAfter), |
|
199 iKeepTogether(KParaDefaultKeepTogether), |
|
200 iKeepWithNext(KParaDefaultKeepWithNext), |
|
201 iStartNewPage(KParaDefaultStartNewPage), |
|
202 iWidowOrphan(KParaDefaultWidowOrphan), |
|
203 iWrap(KParaDefaultWrap), |
|
204 iBorderMarginInTwips(KParaDefaultBorderMargin), |
|
205 iBullet(NULL), |
|
206 iDefaultTabWidthInTwips(KParaDefaultTabWidth) |
|
207 /** The default C++ constructor constructs a new CParaFormat initialising all |
|
208 attributes to the default settings. |
|
209 |
|
210 Note: This function allows a CParaFormat object to be created on the stack. This |
|
211 should only be done if it is known in advance that the object will not be |
|
212 used to store tab stops, bullets or borders. */ |
|
213 { |
|
214 } |
|
215 |
|
216 |
|
217 CParaFormat::CParaFormat(const CParaFormat& aFormat): |
|
218 iFillColor(aFormat.iFillColor), |
|
219 iLanguage(aFormat.iLanguage), |
|
220 iLeftMarginInTwips(aFormat.iLeftMarginInTwips), |
|
221 iRightMarginInTwips(aFormat.iRightMarginInTwips), |
|
222 iIndentInTwips(aFormat.iIndentInTwips), |
|
223 iHorizontalAlignment(aFormat.iHorizontalAlignment), |
|
224 iVerticalAlignment(aFormat.iVerticalAlignment), |
|
225 iLineSpacingInTwips(aFormat.iLineSpacingInTwips), |
|
226 iLineSpacingControl(aFormat.iLineSpacingControl), |
|
227 iSpaceBeforeInTwips(aFormat.iSpaceBeforeInTwips), |
|
228 iSpaceAfterInTwips(aFormat.iSpaceAfterInTwips), |
|
229 iKeepTogether(aFormat.iKeepTogether), |
|
230 iKeepWithNext(aFormat.iKeepWithNext), |
|
231 iStartNewPage(aFormat.iStartNewPage), |
|
232 iWidowOrphan(aFormat.iWidowOrphan), |
|
233 iWrap(aFormat.iWrap), |
|
234 iBorderMarginInTwips(aFormat.iBorderMarginInTwips), |
|
235 iDefaultTabWidthInTwips(aFormat.iDefaultTabWidthInTwips) |
|
236 { |
|
237 } |
|
238 |
|
239 void CParaFormat::CreateTabListL() |
|
240 { |
|
241 if (!iTabList) |
|
242 iTabList = new(ELeave) CArrayFixFlat<TTabStop>(ETabStoreGranularity); |
|
243 } |
|
244 |
|
245 EXPORT_C CParaFormat::~CParaFormat() |
|
246 /** The destructor frees all resources owned by the paragraph format container |
|
247 (tabs, borders and bullets), prior to its destruction. |
|
248 |
|
249 Note that Strip() also sets the resource pointers to NULL. This is important |
|
250 in case CParaFormat is on the stack and gets deleted twice: once by the cleanup |
|
251 stack and once by exceptions being unwound. */ |
|
252 { |
|
253 Strip(); |
|
254 } |
|
255 |
|
256 EXPORT_C void CParaFormat::CopyL(const CParaFormat& aFormat) |
|
257 /** Copies all attribute values from another paragraph format container. |
|
258 |
|
259 @param aFormat Contains the attribute values to copy. */ |
|
260 { |
|
261 TParaFormatMask mask; |
|
262 mask.SetAll(); |
|
263 CopyL(aFormat,mask); |
|
264 } |
|
265 |
|
266 EXPORT_C void CParaFormat::CopyL(const CParaFormat& aFormat,const TParaFormatMask& aMask) |
|
267 /** Copies selected attribute values from another paragraph format container. |
|
268 Only the attributes which are set in the mask are copied. |
|
269 |
|
270 @param aFormat Contains the attribute values to copy. |
|
271 @param aMask Bitmask specifying the attributes to copy. */ |
|
272 { |
|
273 if (aMask.AttribIsSet(EAttParaLanguage)) |
|
274 iLanguage=aFormat.iLanguage; |
|
275 if (aMask.AttribIsSet(EAttFillColor)) |
|
276 iFillColor=aFormat.iFillColor; |
|
277 if (aMask.AttribIsSet(EAttLeftMargin)) |
|
278 iLeftMarginInTwips=aFormat.iLeftMarginInTwips; |
|
279 if (aMask.AttribIsSet(EAttRightMargin)) |
|
280 iRightMarginInTwips=aFormat.iRightMarginInTwips; |
|
281 if (aMask.AttribIsSet(EAttIndent)) |
|
282 iIndentInTwips=aFormat.iIndentInTwips; |
|
283 if (aMask.AttribIsSet(EAttAlignment)) |
|
284 iHorizontalAlignment=aFormat.iHorizontalAlignment; |
|
285 if (aMask.AttribIsSet(EAttVerticalAlignment)) |
|
286 iVerticalAlignment=aFormat.iVerticalAlignment; |
|
287 if (aMask.AttribIsSet(EAttLineSpacing)) |
|
288 iLineSpacingInTwips=aFormat.iLineSpacingInTwips; |
|
289 if (aMask.AttribIsSet(EAttLineSpacingControl)) |
|
290 iLineSpacingControl=aFormat.iLineSpacingControl; |
|
291 if (aMask.AttribIsSet(EAttSpaceBefore)) |
|
292 iSpaceBeforeInTwips=aFormat.iSpaceBeforeInTwips; |
|
293 if (aMask.AttribIsSet(EAttSpaceAfter)) |
|
294 iSpaceAfterInTwips=aFormat.iSpaceAfterInTwips; |
|
295 if (aMask.AttribIsSet(EAttKeepTogether)) |
|
296 iKeepTogether=aFormat.iKeepTogether; |
|
297 if (aMask.AttribIsSet(EAttKeepWithNext)) |
|
298 iKeepWithNext=aFormat.iKeepWithNext; |
|
299 if (aMask.AttribIsSet(EAttStartNewPage)) |
|
300 iStartNewPage=aFormat.iStartNewPage; |
|
301 if (aMask.AttribIsSet(EAttWidowOrphan)) |
|
302 iWidowOrphan=aFormat.iWidowOrphan; |
|
303 if (aMask.AttribIsSet(EAttWrap)) |
|
304 iWrap=aFormat.iWrap; |
|
305 |
|
306 // Copy borders; create a border array only if necessary. |
|
307 if (iParaBorderArray || aFormat.iParaBorderArray) |
|
308 { |
|
309 if (!iParaBorderArray) |
|
310 iParaBorderArray = new(ELeave) TParaBorderArray; |
|
311 if (aMask.AttribIsSet(EAttTopBorder)) |
|
312 iParaBorderArray->iBorder[EParaBorderTop] = aFormat.ParaBorder(EParaBorderTop); |
|
313 if (aMask.AttribIsSet(EAttBottomBorder)) |
|
314 iParaBorderArray->iBorder[EParaBorderBottom] = aFormat.ParaBorder(EParaBorderBottom); |
|
315 if (aMask.AttribIsSet(EAttLeftBorder)) |
|
316 iParaBorderArray->iBorder[EParaBorderLeft] = aFormat.ParaBorder(EParaBorderLeft); |
|
317 if (aMask.AttribIsSet(EAttRightBorder)) |
|
318 iParaBorderArray->iBorder[EParaBorderRight] = aFormat.ParaBorder(EParaBorderRight); |
|
319 TParaBorder default_border; |
|
320 TBool borders_are_default = TRUE; |
|
321 for (int i = 0; i < 4; i++) |
|
322 if (iParaBorderArray->iBorder[i] != default_border) |
|
323 { |
|
324 borders_are_default = FALSE; |
|
325 break; |
|
326 } |
|
327 if (borders_are_default) |
|
328 RemoveAllBorders(); |
|
329 } |
|
330 |
|
331 if (iBullet || aFormat.iBullet) |
|
332 { |
|
333 if (aMask.AttribIsSet(EAttBullet)) |
|
334 { |
|
335 if (aFormat.iBullet && aFormat.iBullet->iStyle != TBullet::ENullStyle) |
|
336 { |
|
337 if (!iBullet) |
|
338 iBullet = new(ELeave) TBullet; |
|
339 *iBullet = *aFormat.iBullet; |
|
340 } |
|
341 else |
|
342 { |
|
343 delete iBullet; |
|
344 iBullet = NULL; |
|
345 } |
|
346 } |
|
347 } |
|
348 |
|
349 if (aMask.AttribIsSet(EAttDefaultTabWidth)) |
|
350 iDefaultTabWidthInTwips = aFormat.iDefaultTabWidthInTwips; |
|
351 |
|
352 if (iTabList || aFormat.iTabList) |
|
353 { |
|
354 if (aMask.AttribIsSet(EAttTabStop)) |
|
355 { |
|
356 RemoveAllTabs(); |
|
357 if (aFormat.iTabList && aFormat.iTabList->Count()) |
|
358 { |
|
359 CreateTabListL(); |
|
360 iTabList->InsertL(0,&(aFormat.iTabList->At(0)),aFormat.iTabList->Count()); |
|
361 } |
|
362 } |
|
363 } |
|
364 } |
|
365 |
|
366 EXPORT_C TBool CParaFormat::IsEqual(const CParaFormat& aFormat,const TParaFormatMask& aMask) const |
|
367 /** Compares selected attribute values for equality. Only the attributes |
|
368 specified in the mask are involved in the comparison. |
|
369 |
|
370 @param aFormat Contains the attribute values to compare. |
|
371 @param aMask Bitmask specifying the attributes to compare. |
|
372 @return ETrue if the two format containers have the same values for the |
|
373 attributes specified in the mask, EFalse if not. */ |
|
374 { |
|
375 if (aMask.AttribIsSet(EAttParaLanguage)) |
|
376 { |
|
377 if (iLanguage!=aFormat.iLanguage) |
|
378 return EFalse; |
|
379 } |
|
380 if (aMask.AttribIsSet(EAttFillColor)) |
|
381 { |
|
382 if (iFillColor!=aFormat.iFillColor) |
|
383 return EFalse; |
|
384 } |
|
385 if (aMask.AttribIsSet(EAttLeftMargin)) |
|
386 { |
|
387 if (iLeftMarginInTwips!=aFormat.iLeftMarginInTwips) |
|
388 return EFalse; |
|
389 } |
|
390 if (aMask.AttribIsSet(EAttRightMargin)) |
|
391 { |
|
392 if (iRightMarginInTwips!=aFormat.iRightMarginInTwips) |
|
393 return EFalse; |
|
394 } |
|
395 if (aMask.AttribIsSet(EAttIndent)) |
|
396 { |
|
397 if (iIndentInTwips!=aFormat.iIndentInTwips) |
|
398 return EFalse; |
|
399 } |
|
400 if (aMask.AttribIsSet(EAttAlignment)) |
|
401 { |
|
402 if (iHorizontalAlignment!=aFormat.iHorizontalAlignment) |
|
403 return EFalse; |
|
404 } |
|
405 if (aMask.AttribIsSet(EAttVerticalAlignment)) |
|
406 { |
|
407 if (iVerticalAlignment!=aFormat.iVerticalAlignment) |
|
408 return EFalse; |
|
409 } |
|
410 if (aMask.AttribIsSet(EAttLineSpacing)) |
|
411 { |
|
412 if (iLineSpacingInTwips!=aFormat.iLineSpacingInTwips) |
|
413 return EFalse; |
|
414 } |
|
415 if (aMask.AttribIsSet(EAttLineSpacingControl)) |
|
416 { |
|
417 if (iLineSpacingControl!=aFormat.iLineSpacingControl) |
|
418 return EFalse; |
|
419 } |
|
420 if (aMask.AttribIsSet(EAttSpaceBefore)) |
|
421 { |
|
422 if (iSpaceBeforeInTwips!=aFormat.iSpaceBeforeInTwips) |
|
423 return EFalse; |
|
424 } |
|
425 if (aMask.AttribIsSet(EAttSpaceAfter)) |
|
426 { |
|
427 if (iSpaceAfterInTwips!=aFormat.iSpaceAfterInTwips) |
|
428 return EFalse; |
|
429 } |
|
430 if (aMask.AttribIsSet(EAttKeepTogether)) |
|
431 { |
|
432 if (iKeepTogether!=aFormat.iKeepTogether) |
|
433 return EFalse; |
|
434 } |
|
435 if (aMask.AttribIsSet(EAttKeepWithNext)) |
|
436 { |
|
437 if (iKeepWithNext!=aFormat.iKeepWithNext) |
|
438 return EFalse; |
|
439 } |
|
440 if (aMask.AttribIsSet(EAttStartNewPage)) |
|
441 { |
|
442 if (iStartNewPage!=aFormat.iStartNewPage) |
|
443 return EFalse; |
|
444 } |
|
445 if (aMask.AttribIsSet(EAttWidowOrphan)) |
|
446 { |
|
447 if (iWidowOrphan!=aFormat.iWidowOrphan) |
|
448 return EFalse; |
|
449 } |
|
450 if (aMask.AttribIsSet(EAttWrap)) |
|
451 { |
|
452 if (iWrap!=aFormat.iWrap) |
|
453 return EFalse; |
|
454 } |
|
455 if (aMask.AttribIsSet(EAttBorderMargin)) |
|
456 { |
|
457 if (iBorderMarginInTwips!=aFormat.iBorderMarginInTwips) |
|
458 return EFalse; |
|
459 } |
|
460 if (aMask.AttribIsSet(EAttTopBorder)) |
|
461 { |
|
462 if (iParaBorderArray) |
|
463 { |
|
464 if (ParaBorder(EParaBorderTop)!=aFormat.ParaBorder(EParaBorderTop)) |
|
465 return EFalse; |
|
466 } |
|
467 else |
|
468 { |
|
469 if (aFormat.ParaBorder(EParaBorderTop).iLineStyle!=TParaBorder::ENullLineStyle) |
|
470 return EFalse; |
|
471 } |
|
472 } |
|
473 if (aMask.AttribIsSet(EAttBottomBorder)) |
|
474 { |
|
475 if (iParaBorderArray) |
|
476 { |
|
477 if (ParaBorder(EParaBorderBottom)!=aFormat.ParaBorder(EParaBorderBottom)) |
|
478 return EFalse; |
|
479 } |
|
480 else |
|
481 { |
|
482 if (aFormat.ParaBorder(EParaBorderBottom).iLineStyle!=TParaBorder::ENullLineStyle) |
|
483 return EFalse; |
|
484 } |
|
485 } |
|
486 if (aMask.AttribIsSet(EAttLeftBorder)) |
|
487 { |
|
488 if (iParaBorderArray) |
|
489 { |
|
490 if (ParaBorder(EParaBorderLeft)!=aFormat.ParaBorder(EParaBorderLeft)) |
|
491 return EFalse; |
|
492 } |
|
493 else |
|
494 { |
|
495 if (aFormat.ParaBorder(EParaBorderLeft).iLineStyle!=TParaBorder::ENullLineStyle) |
|
496 return EFalse; |
|
497 } |
|
498 } |
|
499 if (aMask.AttribIsSet(EAttRightBorder)) |
|
500 { |
|
501 if (iParaBorderArray) |
|
502 { |
|
503 if (ParaBorder(EParaBorderRight)!=aFormat.ParaBorder(EParaBorderRight)) |
|
504 return EFalse; |
|
505 } |
|
506 else |
|
507 { |
|
508 if (aFormat.ParaBorder(EParaBorderRight).iLineStyle!=TParaBorder::ENullLineStyle) |
|
509 return EFalse; |
|
510 } |
|
511 } |
|
512 if (aMask.AttribIsSet(EAttBullet)) |
|
513 { |
|
514 if (iBullet) |
|
515 { |
|
516 if (!aFormat.iBullet) |
|
517 return EFalse; |
|
518 if (*iBullet!=*aFormat.iBullet) |
|
519 return EFalse; |
|
520 } |
|
521 else |
|
522 { |
|
523 if (aFormat.iBullet) |
|
524 return EFalse; |
|
525 } |
|
526 } |
|
527 if (aMask.AttribIsSet(EAttDefaultTabWidth)) |
|
528 { |
|
529 if (iDefaultTabWidthInTwips!=aFormat.iDefaultTabWidthInTwips) |
|
530 return EFalse; |
|
531 } |
|
532 if (aMask.AttribIsSet(EAttTabStop)) |
|
533 { |
|
534 if (TabCount()>0) |
|
535 {// Check the tablists are the same. |
|
536 if (TabCount()!=aFormat.TabCount()) |
|
537 return EFalse; |
|
538 TInt tabCount=TabCount(); |
|
539 for (TInt index=0;index<tabCount;index++) |
|
540 {// Check each stored tab is the same |
|
541 if (TabStop(index)!=aFormat.TabStop(index)) |
|
542 return EFalse; |
|
543 } |
|
544 } |
|
545 else if (aFormat.TabCount()>0) |
|
546 return EFalse; |
|
547 } |
|
548 return ETrue; |
|
549 } |
|
550 |
|
551 EXPORT_C TBool CParaFormat::IsEqual(const CParaFormat& aFormat) const |
|
552 /** Compares all attribute values for equality. |
|
553 |
|
554 @param aFormat Contains the attribute values to compare. |
|
555 @return ETrue if the two format containers have the same values for all |
|
556 attributes, EFalse if not. */ |
|
557 { |
|
558 TParaFormatMask mask; |
|
559 mask.SetAll(); |
|
560 return IsEqual(aFormat,mask); |
|
561 } |
|
562 |
|
563 EXPORT_C void CParaFormat::Strip() |
|
564 /** Deletes all paragraph borders, bullets and tab stops. No other |
|
565 attributes are affected. */ |
|
566 { |
|
567 RemoveAllTabs(); |
|
568 RemoveAllBorders(); |
|
569 delete iBullet; |
|
570 iBullet = NULL; |
|
571 } |
|
572 |
|
573 EXPORT_C void CParaFormat::Reset() |
|
574 /** Resets all paragraph format attributes to their default values. All tab |
|
575 stops, paragraph borders and bullet points which have been allocated are |
|
576 deleted and set to NULL. */ |
|
577 { |
|
578 ResetNonDestructive(); |
|
579 Strip(); |
|
580 } |
|
581 |
|
582 EXPORT_C void CParaFormat::ResetNonDestructive() |
|
583 /** Resets all paragraph format attributes to their default values, but any |
|
584 allocated tab stops, bullet points and paragraph borders are preserved. */ |
|
585 { |
|
586 iLanguage=KParaDefaultLanguage; |
|
587 iFillColor=TLogicalRgb::ESystemBackgroundColor; |
|
588 iLeftMarginInTwips=KParaDefaultLeftMargin; |
|
589 iRightMarginInTwips=KParaDefaultRightMargin; |
|
590 iIndentInTwips=KParaDefaultIndent; |
|
591 iHorizontalAlignment=KParaDefaultHorizAlign; |
|
592 iVerticalAlignment=KParaDefaultVertAlign; |
|
593 iLineSpacingInTwips=KParaDefaultLineSpacing; |
|
594 iLineSpacingControl=KParaDefaultLineSpacingControl; |
|
595 iSpaceBeforeInTwips=KParaDefaultSpaceBefore; |
|
596 iSpaceAfterInTwips=KParaDefaultSpaceAfter; |
|
597 iKeepTogether=KParaDefaultKeepTogether; |
|
598 iKeepWithNext=KParaDefaultKeepWithNext; |
|
599 iStartNewPage=KParaDefaultStartNewPage; |
|
600 iWidowOrphan=KParaDefaultWidowOrphan; |
|
601 iWrap=KParaDefaultWrap; |
|
602 iBorderMarginInTwips=KParaDefaultBorderMargin; |
|
603 iDefaultTabWidthInTwips=KParaDefaultTabWidth; |
|
604 } |
|
605 |
|
606 EXPORT_C void CParaFormat::StoreTabL(const TTabStop& aTabStop) |
|
607 /** Adds a tab stop to the list of tab stops, maintaining the ordering of the |
|
608 list, (ascending order of twips position). Multiple tabs with the same twips |
|
609 position are not allowed, so that if aTabStop shares the same twips position |
|
610 as an existing tab stop, regardless of its alignment, the existing tab stop is |
|
611 replaced by aTabStop. |
|
612 |
|
613 @param aTabStop The tab stop to be stored. */ |
|
614 { |
|
615 CreateTabListL(); |
|
616 TKeyArrayFix tabKey(_FOFF(TTabStop,iTwipsPosition),ECmpTUint32); |
|
617 TInt tabNumber; |
|
618 CArrayFixFlat<TTabStop>& tabs=*iTabList; |
|
619 if (tabs.FindIsq(aTabStop,tabKey,tabNumber)==0) |
|
620 tabs[tabNumber]=aTabStop; // found one at this position |
|
621 else |
|
622 tabs.InsertL(tabNumber,aTabStop); // add the new one |
|
623 } |
|
624 |
|
625 EXPORT_C void CParaFormat::RemoveTab(TInt aTabPosition) |
|
626 /** Deletes a tab stop identified by its twips position. If the specified |
|
627 tab stop does not exist, the function has no effect. |
|
628 |
|
629 @param aTabTwipsPosition The twips position of the tab stop to remove. */ |
|
630 |
|
631 { |
|
632 TInt tabNumber=LocateTab(aTabPosition); // will return KTabNotFound if no tab list present |
|
633 if (tabNumber!=KTabNotFound) |
|
634 { |
|
635 iTabList->Delete(tabNumber); |
|
636 iTabList->Compress(); |
|
637 } |
|
638 } |
|
639 |
|
640 EXPORT_C const TTabStop CParaFormat::TabStop(TInt aTabIndex) const |
|
641 /** Gets the tab stop located at the specified index within the tab list |
|
642 (counting from zero). Tab stops are ordered in ascending order of twips |
|
643 position. If the object has no tab list, then a default tab stop is returned. |
|
644 |
|
645 @param aTabIndex The offset of the tab stop in the tab list. Must be less |
|
646 than the total number of tab stops, or a panic occurs. To find the total number |
|
647 of tab stops, use TabCount(). |
|
648 @return The tab stop located at the specified index. */ |
|
649 { |
|
650 __ASSERT_ALWAYS(aTabIndex<TabCount(),Panic(ETabNotFound)); |
|
651 |
|
652 return (iTabList) |
|
653 ? TTabStop((*iTabList)[aTabIndex]) |
|
654 : TTabStop(); |
|
655 } |
|
656 |
|
657 EXPORT_C TInt CParaFormat::LocateTab(TInt aTabPosition) const |
|
658 /** Locates the tab stop specified by its twips position, and returns its |
|
659 offset in the tab list. |
|
660 |
|
661 @param aTabPosition The twips position of the tab stop. |
|
662 @return The tab stop's index within the tab list (counting from zero). |
|
663 KTabNotFound indicates that no tab stop has the specified twips |
|
664 position, or that no tab list has been allocated. */ |
|
665 { |
|
666 if (!iTabList) |
|
667 return KTabNotFound; |
|
668 TKeyArrayFix tabKey(_FOFF(TTabStop,iTwipsPosition),ECmpTUint32); |
|
669 TInt tabNumber=0; |
|
670 TTabStop tab; |
|
671 tab.iTwipsPosition=aTabPosition; |
|
672 TInt error=iTabList->FindIsq(tab,tabKey,tabNumber); |
|
673 return error ?KTabNotFound :tabNumber; |
|
674 } |
|
675 |
|
676 EXPORT_C void CParaFormat::SetParaBorderL(TParaBorderSide aSide,const TParaBorder& aBorder) |
|
677 /** Sets one side of the object's paragraph border. If a border on the specified |
|
678 side already exists, it is replaced. |
|
679 |
|
680 Note: Setting a single side of the object's paragraph border incurs the overhead |
|
681 of allocating storage for the three other sides, which are assigned default |
|
682 values. |
|
683 |
|
684 @param aSide The side for the paragraph border. |
|
685 @param aBorder Specification for the paragraph border. */ |
|
686 { |
|
687 TParaBorderArray* borders=iParaBorderArray; |
|
688 if (!borders) |
|
689 iParaBorderArray=borders=new(ELeave) TParaBorderArray; |
|
690 borders->iBorder[aSide]=aBorder; |
|
691 } |
|
692 |
|
693 EXPORT_C const TParaBorder CParaFormat::ParaBorder(TParaBorderSide aSide)const |
|
694 /** Gets the paragraph border on the side specified. If no paragraph border |
|
695 array has been allocated, returns a default paragraph border. |
|
696 |
|
697 @param aSide The side for the paragraph border. |
|
698 @return The paragraph border on the specified side. */ |
|
699 { |
|
700 if (iParaBorderArray) |
|
701 return iParaBorderArray->iBorder[aSide]; |
|
702 return TParaBorder(); |
|
703 } |
|
704 |
|
705 EXPORT_C void CParaFormat::RemoveAllBorders() |
|
706 /** Deletes all paragraph borders. */ |
|
707 { |
|
708 delete iParaBorderArray; |
|
709 iParaBorderArray = NULL; |
|
710 } |
|
711 |
|
712 EXPORT_C TBool CParaFormat::AllBordersEqual(const CParaFormat& aFormat)const |
|
713 /** Tests whether all paragraph borders in the specified paragraph format |
|
714 container are identical to the paragraph borders of this paragraph format |
|
715 container. |
|
716 |
|
717 @param aFormat Contains the set of paragraph borders to compare. |
|
718 @return ETrue if both objects have exactly the same set of paragraph borders. |
|
719 EFalse if not. */ |
|
720 { |
|
721 if (aFormat.ParaBorder(EParaBorderTop)!=ParaBorder(EParaBorderTop)) |
|
722 return EFalse; |
|
723 if (aFormat.ParaBorder(EParaBorderBottom)!=ParaBorder(EParaBorderBottom)) |
|
724 return EFalse; |
|
725 if (aFormat.ParaBorder(EParaBorderLeft)!=ParaBorder(EParaBorderLeft)) |
|
726 return EFalse; |
|
727 if (aFormat.ParaBorder(EParaBorderRight)!=ParaBorder(EParaBorderRight)) |
|
728 return EFalse; |
|
729 return ETrue; |
|
730 } |
|
731 |
|
732 EXPORT_C TBool CParaFormat::IsBorderEqual(TParaBorderSide aSide,const CParaFormat& aFormat)const |
|
733 /** Tests whether the paragraph border located on the specified side is the same |
|
734 as the border on the corresponding side in this object. For two borders to |
|
735 be equal, they must both either be set or unset, and if set, they must have |
|
736 the same characteristics. |
|
737 |
|
738 @param aSide Indicates which side should be compared. |
|
739 @param aFormat Contains the paragraph border to compare. |
|
740 @return ETrue if the border sides are identical. EFalse if not. */ |
|
741 { |
|
742 return aFormat.ParaBorder(aSide)==ParaBorder(aSide); |
|
743 } |
|
744 |
|
745 EXPORT_C void TParaFormatMask::SetAll() |
|
746 /** Sets all attribute flags in the paragraph format mask. */ |
|
747 { |
|
748 iGuard = KMaxTUint; |
|
749 } |
|
750 |
|
751 EXPORT_C void TParaFormatMask::ClearAll() |
|
752 /** Clears all attribute flags in the paragraph format mask. */ |
|
753 { |
|
754 iGuard=0; |
|
755 } |
|
756 |
|
757 EXPORT_C TBool TParaFormatMask::operator==(const TParaFormatMask& aMask)const |
|
758 /** Compares two paragraph format masks for equality. |
|
759 |
|
760 @param aMask The mask to compare. |
|
761 @return ETrue if all flags are the same in both masks. EFalse if any differ. */ |
|
762 { |
|
763 return (iGuard & KParFormatBits) == (aMask.iGuard & KParFormatBits); |
|
764 } |
|
765 |
|
766 EXPORT_C TFontPresentation::TFontPresentation(): |
|
767 iTextColor(TLogicalRgb::ESystemForegroundColor), |
|
768 iHighlightColor(TLogicalRgb::ESystemForegroundColor), |
|
769 iHighlightStyle(EFontHighlightNone), |
|
770 iStrikethrough(EStrikethroughOff), |
|
771 iUnderline(EUnderlineOff), |
|
772 iHiddenText(EFalse), |
|
773 iPictureAlignment(EAlignBaseLine) |
|
774 /** The default C++ constructor constructs a TFontPresentation object, |
|
775 initializing all member data to default values. For details of these values, |
|
776 see the table below. */ |
|
777 { |
|
778 } |
|
779 |
|
780 EXPORT_C TBool TFontPresentation::IsEqual(const TFontPresentation& aFontPresentation,const TCharFormatMask& aMask) const |
|
781 /** Compares selected attribute values for equality. Only the attributes |
|
782 specified in the mask are involved in the comparison. |
|
783 |
|
784 @param aFontPresentation Contains the attribute values to compare. |
|
785 @param aMask Bitmask specifying the attributes involved in the comparison. |
|
786 @return ETrue if the two objects have the same values for the attributes |
|
787 specified in the mask, EFalse if not. */ |
|
788 { |
|
789 // Compare two font presentations, comparing only the attributes selected by the mask. |
|
790 if (aMask.AttribIsSet(EAttColor)) |
|
791 { |
|
792 if (iTextColor!=aFontPresentation.iTextColor) |
|
793 return EFalse; |
|
794 } |
|
795 if (aMask.AttribIsSet(EAttFontHighlightColor)) |
|
796 { |
|
797 if (iHighlightColor!=aFontPresentation.iHighlightColor) |
|
798 return EFalse; |
|
799 } |
|
800 if (aMask.AttribIsSet(EAttFontHighlightStyle)) |
|
801 { |
|
802 if (iHighlightStyle!=aFontPresentation.iHighlightStyle) |
|
803 return EFalse; |
|
804 } |
|
805 if (aMask.AttribIsSet(EAttFontStrikethrough)) |
|
806 { |
|
807 if (iStrikethrough!=aFontPresentation.iStrikethrough) |
|
808 return EFalse; |
|
809 } |
|
810 if (aMask.AttribIsSet(EAttFontUnderline)) |
|
811 { |
|
812 if (iUnderline!=aFontPresentation.iUnderline) |
|
813 return EFalse; |
|
814 } |
|
815 if (aMask.AttribIsSet(EAttFontHiddenText)) |
|
816 { |
|
817 if (iHiddenText!=aFontPresentation.iHiddenText) |
|
818 return EFalse; |
|
819 } |
|
820 if (aMask.AttribIsSet(EAttFontPictureAlignment)) |
|
821 { |
|
822 if (iPictureAlignment!=aFontPresentation.iPictureAlignment) |
|
823 return EFalse; |
|
824 } |
|
825 return ETrue; |
|
826 } |
|
827 |
|
828 EXPORT_C TCharFormat::TCharFormat(): |
|
829 iLanguage(0) |
|
830 /** Allocates and constructs a TCharFormat object. The font-independent |
|
831 attributes are initialised with default values. The language is initialised |
|
832 to zero. The font (iFontSpec) is set to be proportional and serif and to have |
|
833 a height of 200 twips. The typeface name is not initialised. */ |
|
834 { |
|
835 iFontSpec.iTypeface.SetAttributes(TTypeface::EProportional | TTypeface::ESerif); |
|
836 iFontSpec.iHeight = 200; |
|
837 } |
|
838 |
|
839 EXPORT_C TCharFormat::TCharFormat(const TDesC &aTypefaceName,TInt aHeight): |
|
840 iLanguage(0), |
|
841 iFontSpec(aTypefaceName,aHeight) |
|
842 /** The C++ constructor is used to construct the TCharFormat object with a font |
|
843 (typeface name and font height). The font-independent attributes are initialised |
|
844 to default values; for details, see class TFontPresentation. The language |
|
845 is initialised to zero. |
|
846 |
|
847 @param aTypefaceName Specifies the typeface name. |
|
848 @param aHeight Specifies the font height in twips. */ |
|
849 { |
|
850 } |
|
851 |
|
852 EXPORT_C TBool TCharFormat::IsEqual(const TCharFormat& aFormat,const TCharFormatMask& aMask) const |
|
853 /** Compares selected attribute values for equality. Only the attributes |
|
854 specified in the mask are involved in the comparison. |
|
855 |
|
856 @param aFormat Contains the attribute values to compare. |
|
857 @param aMask Bitmask specifying the attributes to compare. |
|
858 @return ETrue if the two format containers have the same values for the |
|
859 attributes specified in the mask, EFalse if not. */ |
|
860 { |
|
861 if (aMask.AttribIsSet(EAttCharLanguage)) |
|
862 { |
|
863 if (iLanguage!=aFormat.iLanguage) |
|
864 return EFalse; |
|
865 } |
|
866 if (!iFontPresentation.IsEqual(aFormat.iFontPresentation,aMask)) |
|
867 return EFalse; |
|
868 if (aMask.AttribIsSet(EAttFontHeight)) |
|
869 { |
|
870 if (iFontSpec.iHeight!=aFormat.iFontSpec.iHeight) |
|
871 return EFalse; |
|
872 } |
|
873 if (aMask.AttribIsSet(EAttFontTypeface)) |
|
874 { |
|
875 if (!(iFontSpec.iTypeface==aFormat.iFontSpec.iTypeface)) |
|
876 return EFalse; |
|
877 } |
|
878 if (aMask.AttribIsSet(EAttFontPosture)) |
|
879 { |
|
880 if (iFontSpec.iFontStyle.Posture()!=aFormat.iFontSpec.iFontStyle.Posture()) |
|
881 return EFalse; |
|
882 } |
|
883 if (aMask.AttribIsSet(EAttFontStrokeWeight)) |
|
884 { |
|
885 if (iFontSpec.iFontStyle.StrokeWeight()!=aFormat.iFontSpec.iFontStyle.StrokeWeight()) |
|
886 return EFalse; |
|
887 } |
|
888 if (aMask.AttribIsSet(EAttFontPrintPos)) |
|
889 { |
|
890 if (iFontSpec.iFontStyle.PrintPosition()!=aFormat.iFontSpec.iFontStyle.PrintPosition()) |
|
891 return EFalse; |
|
892 } |
|
893 return ETrue; |
|
894 } |
|
895 |
|
896 |
|
897 EXPORT_C TBool TCharFormat::IsEqual(const TCharFormat& aFormat) const |
|
898 /** Compares all attribute values for equality. |
|
899 |
|
900 @param aFormat Contains the attribute values to compare. |
|
901 @return ETrue if the two format containers have the same values for all |
|
902 attributes, EFalse if not. */ |
|
903 { |
|
904 TCharFormatMask mask; |
|
905 mask.SetAll(); |
|
906 return IsEqual(aFormat,mask); |
|
907 } |
|
908 |
|
909 EXPORT_C void TCharFormatMask::SetAll() |
|
910 /** Sets all attribute flags in the character format mask. */ |
|
911 { |
|
912 iGuard = KMaxTUint; |
|
913 } |
|
914 |
|
915 EXPORT_C void TCharFormatMask::ClearAll() |
|
916 /** Clears all attribute flags in the character format mask. */ |
|
917 { |
|
918 iGuard = 0; |
|
919 } |
|
920 |
|
921 EXPORT_C TBool TCharFormatMask::operator==(const TCharFormatMask& aMask)const |
|
922 /** Compares two character format masks for equality. |
|
923 |
|
924 @param aMask The mask to compare. |
|
925 @return ETrue if all flags are the same in both masks. EFalse if any differ. */ |
|
926 { |
|
927 return (iGuard & KCharFormatBits) == (aMask.iGuard & KCharFormatBits); |
|
928 } |