|
1 /* |
|
2 * Copyright (c) 2006 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 * Internal implementations for Avkon Layout Utilities. Related public interfaces are to be |
|
16 * found in AknUtils.h. |
|
17 * Implementations that use these internal routines are to be found in AknUtils.cpp |
|
18 * |
|
19 * |
|
20 */ |
|
21 |
|
22 |
|
23 #include "AknLayoutUtilsHelpers.h" |
|
24 #include <eikedwin.h> |
|
25 #include <AknFontId.h> |
|
26 #include <AknUtils.h> |
|
27 #include <AknLayoutFont.h> |
|
28 #include <AknSettingCache.h> |
|
29 #include <AknsUtils.h> |
|
30 #include <AknPanic.h> |
|
31 |
|
32 LOCAL_C TBool IsEmpty(TInt aValue) |
|
33 { |
|
34 return aValue == ELayoutEmpty; |
|
35 } |
|
36 |
|
37 |
|
38 // ================= MEMBER FUNCTIONS ======================= |
|
39 |
|
40 |
|
41 TInt AknLayoutUtilsHelpers::CorrectBaseline( TInt aParentHeight, TInt aBaseline, TInt aFontId ) |
|
42 { |
|
43 TInt B = aBaseline; |
|
44 if( TAknFontId::IsEncodedFont(aFontId) ) // This tells us that the font id has come from scalable layout API |
|
45 { |
|
46 // From scalable layout, the iB member is the distance from the bottom of the |
|
47 // parent to the bottom of the text pane. |
|
48 // |
|
49 TInt b = aBaseline; |
|
50 if (IsParentRelative(b)) { b = aParentHeight - ELayoutP + b; } |
|
51 |
|
52 const CAknLayoutFont *font = AknLayoutUtils::LayoutFontFromId(aFontId); |
|
53 TInt descent = font->BaselineToTextPaneBottom(); |
|
54 |
|
55 // calculate distance down from top of parent to bottom of maximal glyph |
|
56 TInt top2bog = aParentHeight - b; |
|
57 |
|
58 // distance down to baseline is distance down to bottom of glyph minus descent |
|
59 // A further 1 is subtracted to account for the definition of baseline in the |
|
60 // Series 60 pre-2.8 layout specifications. |
|
61 B = top2bog - descent - 1; |
|
62 } |
|
63 |
|
64 return B; |
|
65 } |
|
66 |
|
67 TInt AknLayoutUtilsHelpers::EdwinHeightFromLines ( |
|
68 TInt aParentHeight, |
|
69 const TAknTextLineLayout& aLayout, |
|
70 TInt aBaselineSeparationOverRide, |
|
71 TInt aNumberOfLinesToShowOverRide, |
|
72 TInt& aVerticalPositionOfEdwin |
|
73 ) |
|
74 { |
|
75 TInt fontId = aLayout.FontId(); |
|
76 const CAknLayoutFont* font = AknLayoutUtils::LayoutFontFromId( fontId, NULL ); |
|
77 |
|
78 // Take on the overrides |
|
79 if ( aBaselineSeparationOverRide <= 0 ) |
|
80 aBaselineSeparationOverRide = aLayout.BaselineSkip(); |
|
81 if ( aNumberOfLinesToShowOverRide <= 0) |
|
82 aNumberOfLinesToShowOverRide = aLayout.NumberOfLinesShown(); |
|
83 |
|
84 TAknTextDecorationMetrics decorationMetrics( fontId ); |
|
85 TInt topMargin, bottomMargin; |
|
86 decorationMetrics.GetTopAndBottomMargins( topMargin, bottomMargin ); |
|
87 |
|
88 TInt newBaseline = CorrectBaseline( aParentHeight, aLayout.iB, fontId ); |
|
89 |
|
90 aVerticalPositionOfEdwin = |
|
91 EditorVerticalPositionWithinParent( font, newBaseline, topMargin ); |
|
92 |
|
93 return EdwinHeightFromLines( |
|
94 font->TextPaneHeight(), decorationMetrics, |
|
95 aBaselineSeparationOverRide, aNumberOfLinesToShowOverRide); |
|
96 } |
|
97 |
|
98 TInt AknLayoutUtilsHelpers::EdwinHeightFromLines ( |
|
99 TInt aTextPaneHeight, |
|
100 TAknTextDecorationMetrics& aDecorationMetrics, |
|
101 TInt aBaselineSeparation, |
|
102 TInt aNumberOfLinesToShow |
|
103 ) |
|
104 { |
|
105 // This space around the glyph areas is for cursor and highlight extensions |
|
106 TInt topMargin, bottomMargin; |
|
107 aDecorationMetrics.GetTopAndBottomMargins( topMargin, bottomMargin ); |
|
108 |
|
109 TInt height = (aNumberOfLinesToShow-1)*aBaselineSeparation |
|
110 + aTextPaneHeight // includes top and bottom text pane parts |
|
111 + topMargin + bottomMargin; |
|
112 return height; |
|
113 } |
|
114 |
|
115 TInt AknLayoutUtilsHelpers::EdwinLinesWithinHeight ( |
|
116 const TAknTextLineLayout& aLayout, |
|
117 TInt aBaselineSeparationOverride, |
|
118 TInt aMaxHeight, |
|
119 TInt& aUsedHeight |
|
120 ) |
|
121 { |
|
122 |
|
123 TInt fontId = aLayout.FontId(); |
|
124 TInt textPaneHeight; |
|
125 if ( TAknFontId::IsEncodedFont( fontId )) |
|
126 { |
|
127 TAknFontSpecification spec( fontId ); |
|
128 textPaneHeight = spec.TextPaneHeight(); |
|
129 } |
|
130 else |
|
131 { |
|
132 const CAknLayoutFont* font = AknLayoutUtils::LayoutFontFromId( fontId, NULL ); |
|
133 textPaneHeight = font->TextPaneHeight(); |
|
134 } |
|
135 |
|
136 // Deal with the override |
|
137 if ( aBaselineSeparationOverride <= 0 ) |
|
138 aBaselineSeparationOverride = aLayout.BaselineSkip(); |
|
139 TAknTextDecorationMetrics decorationMetrics( fontId ); |
|
140 return AknLayoutUtilsHelpers::EdwinLinesWithinHeight( |
|
141 textPaneHeight, |
|
142 decorationMetrics, |
|
143 aBaselineSeparationOverride, |
|
144 aMaxHeight, |
|
145 aUsedHeight ); |
|
146 } |
|
147 |
|
148 /** |
|
149 * This implemenation is protected against aBaseline <=0 baseline, but that is all, and the math |
|
150 * will just to its stuff. |
|
151 */ |
|
152 TInt AknLayoutUtilsHelpers::EdwinLinesWithinHeight ( |
|
153 TInt aTextPaneHeight, |
|
154 TAknTextDecorationMetrics& aDecorationMetrics, |
|
155 TInt aBaselineSeparation, |
|
156 TInt aMaxHeight, |
|
157 TInt& aUsedHeight |
|
158 ) |
|
159 { |
|
160 TInt numberOfLinesThatFit(0); |
|
161 |
|
162 // This space around the glyph areas is for cursor and highlight extensions |
|
163 TInt topMargin, bottomMargin; |
|
164 aDecorationMetrics.GetTopAndBottomMargins( topMargin, bottomMargin ); |
|
165 |
|
166 if ( aBaselineSeparation > 0 ) |
|
167 { |
|
168 // This variable precalculates how much bigger the baseline separation is than the |
|
169 // text and highlights. Adding it to aHeight lets us pretend that all lines, whether they |
|
170 // are at top bottom or middle, are the same. Then we can just divide to see how many lines |
|
171 // there are. |
|
172 TInt savedSpaceAtTopAndBottom = |
|
173 aBaselineSeparation - aTextPaneHeight - topMargin - bottomMargin; |
|
174 TInt virtualMaxHeight = aMaxHeight + savedSpaceAtTopAndBottom; |
|
175 numberOfLinesThatFit = virtualMaxHeight/aBaselineSeparation; // Integer diviion |
|
176 aUsedHeight = (numberOfLinesThatFit-1)*aBaselineSeparation |
|
177 + aTextPaneHeight + topMargin + bottomMargin; |
|
178 } |
|
179 else |
|
180 { |
|
181 // The question is, does even one line fit? |
|
182 TInt lineHeight = aTextPaneHeight + topMargin + bottomMargin; |
|
183 if ( lineHeight >= aMaxHeight ) |
|
184 { |
|
185 numberOfLinesThatFit = 1; |
|
186 aUsedHeight = lineHeight; |
|
187 } |
|
188 else |
|
189 { |
|
190 numberOfLinesThatFit = 0; |
|
191 aUsedHeight = 0; |
|
192 } |
|
193 } |
|
194 |
|
195 return numberOfLinesThatFit; |
|
196 } |
|
197 |
|
198 /** |
|
199 * This routine emulates what Form is doing internally to get font height and depth. |
|
200 */ |
|
201 void AknLayoutUtilsHelpers::GetFontMaxHeightAndDepth( const CFont* aFont, TInt& aMaxHeight, TInt& aMaxDepth) |
|
202 { |
|
203 const CFbsFont* fbsFont = NULL; |
|
204 |
|
205 if ( aFont->TypeUid() == KCFbsFontUid) |
|
206 { |
|
207 fbsFont = (CFbsFont*)aFont; |
|
208 } |
|
209 |
|
210 if ( fbsFont && fbsFont->IsOpenFont() ) |
|
211 { |
|
212 TOpenFontMetrics metrics; |
|
213 fbsFont->GetFontMetrics(metrics); |
|
214 aMaxHeight = metrics.MaxHeight(); |
|
215 aMaxDepth = metrics.MaxDepth(); |
|
216 } |
|
217 else |
|
218 { |
|
219 aMaxHeight = aFont->AscentInPixels(); |
|
220 aMaxDepth = aFont->DescentInPixels(); |
|
221 } |
|
222 } |
|
223 |
|
224 |
|
225 void AknLayoutUtilsHelpers::LayoutEdwinScalableWithCorrectedParametersAndDecorationMetrics( |
|
226 CEikEdwin *aEdwin, |
|
227 const TRect &aEdwinParent, |
|
228 const CAknLayoutFont *aFont, |
|
229 TInt aColor, |
|
230 TInt aLeftMargin, |
|
231 TInt aRightMargin, |
|
232 TInt aBaseline, // naturally defined |
|
233 TInt /*aWidth*/, // Used with some printing diagnostics |
|
234 TInt aJustification, |
|
235 TInt aNumberOfLinesShown, |
|
236 TInt aSecondLineBaseline, //naturally defined |
|
237 TAknsQsnTextColorsIndex aOverrideColor, |
|
238 TAknTextDecorationMetrics& decorationMetrics, |
|
239 TBool aEnsureEditorIsContainedByParent, |
|
240 TInt& aNumberOfVisibleLines) |
|
241 { |
|
242 |
|
243 // Get editor margin information |
|
244 // This space around the glyph areas is for cursor and highlight extensions |
|
245 TInt topMargin, bottomMargin, leftMargin, rightMargin; |
|
246 decorationMetrics.GetTopAndBottomMargins( topMargin, bottomMargin ); |
|
247 decorationMetrics.GetLeftAndRightMargins( leftMargin, rightMargin ); |
|
248 |
|
249 /* |
|
250 If there is a second baseline, set the baselineDelta to second - first |
|
251 */ |
|
252 TInt baselineDelta = (aSecondLineBaseline) |
|
253 ?(aSecondLineBaseline - aBaseline) |
|
254 :aFont->TextPaneHeight()+topMargin+bottomMargin; |
|
255 |
|
256 CParaFormat paraFormat; |
|
257 TParaFormatMask paraFormatMask; |
|
258 paraFormat.iLineSpacingControl = CParaFormat::ELineSpacingExactlyInPixels; |
|
259 paraFormatMask.SetAttrib(EAttLineSpacingControl); // Switches mode to "Exact line spacing" |
|
260 paraFormat.iLineSpacingInTwips = baselineDelta; |
|
261 paraFormatMask.SetAttrib(EAttLineSpacing); |
|
262 |
|
263 CAknSettingCache& cache = CAknEnv::Static()->SettingCache(); |
|
264 paraFormat.iLanguage = cache.InputLanguage(); // Default paragraph language (in case there is no text yet) |
|
265 paraFormatMask.SetAttrib(EAttParaLanguage); |
|
266 |
|
267 TCharFormat charFormat; |
|
268 TCharFormatMask charFormatMask; |
|
269 charFormat.iFontSpec = aFont->FontSpecInTwips(); |
|
270 charFormatMask.SetAttrib(EAttFontTypeface); |
|
271 charFormatMask.SetAttrib(EAttFontHeight); |
|
272 charFormatMask.SetAttrib(EAttFontStrokeWeight); |
|
273 charFormatMask.SetAttrib(EAttFontPosture); |
|
274 |
|
275 charFormat.iFontPresentation.iTextColor = AKN_LAF_COLOR_STATIC(aColor); |
|
276 charFormatMask.SetAttrib(EAttColor); |
|
277 |
|
278 if ( AknsUtils::AvkonSkinEnabled() ) |
|
279 { |
|
280 // This is not needed actually anymore, left here to ensure backward compatibility |
|
281 AknsUtils::GetCachedColor( AknsUtils::SkinInstance(), |
|
282 charFormat.iFontPresentation.iTextColor, |
|
283 KAknsIIDQsnTextColors, |
|
284 aOverrideColor ); |
|
285 |
|
286 } |
|
287 TRAP_IGNORE(aEdwin->SetTextSkinColorIdL(aOverrideColor)); // this can leave only if there is no extension before |
|
288 // and allocating new one fails |
|
289 |
|
290 // ensure that logical index is being set correctly, so we can override color afterwards in SystemColor() |
|
291 charFormat.iFontPresentation.iTextColor.SetSystemColorIndex(TLogicalRgb::ESystemForegroundIndex); |
|
292 |
|
293 // this is needed because edwin in noneditable flags on draws with EColorControlText and not charformat layer. |
|
294 TRAP_IGNORE( AknLayoutUtils::OverrideControlColorL(*aEdwin, EColorControlText, charFormat.iFontPresentation.iTextColor)); |
|
295 |
|
296 |
|
297 CParaFormatLayer* paraFormatLayer = NULL; |
|
298 CCharFormatLayer* charFormatLayer = NULL; |
|
299 |
|
300 TRAPD( |
|
301 error, |
|
302 { |
|
303 paraFormatLayer = CParaFormatLayer::NewL(¶Format,paraFormatMask); |
|
304 CleanupStack::PushL(paraFormatLayer); |
|
305 charFormatLayer = CCharFormatLayer::NewL(charFormat,charFormatMask); |
|
306 CleanupStack::Pop(); // paraFormatLayer |
|
307 } |
|
308 ); |
|
309 |
|
310 if (error) |
|
311 { |
|
312 #ifdef AKNUTILS_ENABLE_TRACES |
|
313 LOGTEXT(_L("Error in applying formatting\n")); |
|
314 #endif // AKNUTILS_ENABLE_TRACES |
|
315 } |
|
316 else |
|
317 { |
|
318 aEdwin->SetParaFormatLayer(paraFormatLayer); |
|
319 aEdwin->SetCharFormatLayer(charFormatLayer); |
|
320 } |
|
321 aEdwin->SetSuppressFormatting(ETrue); |
|
322 // Setting editor alignment must be done after |
|
323 // other editor paragraph formatting |
|
324 aEdwin->SetAlignment(aJustification); |
|
325 aEdwin->SetSuppressFormatting(EFalse); |
|
326 |
|
327 aEdwin->SetBorder(ENone); |
|
328 |
|
329 // Edwin control`s rectangle starts out as the parent rectangle |
|
330 TRect edwinRect = aEdwinParent; |
|
331 |
|
332 // Editor margin" is used to position the TextView inside the editor |
|
333 // May have to modify top and bottom margins for font characteristics |
|
334 // "fontAscent" variable stands for total (+ve) distance from the baseline to the top of the Scalable layout textpane. |
|
335 TInt fontAscent = aFont->TextPaneTopToBaseline(); |
|
336 // Form itself uses an OpenFont MaxHeight it if can get it. Account for this |
|
337 TInt maxHeight; |
|
338 TInt maxDepth; |
|
339 GetFontMaxHeightAndDepth( aFont, maxHeight, maxDepth ); |
|
340 // This is now excess as measured in S60 relative to what TOpenFontMetrics reports |
|
341 // Should be zero in optimal situations. |
|
342 TInt roomForHighGlyphs = fontAscent - maxHeight; |
|
343 |
|
344 TMargins8 editorMargins; |
|
345 editorMargins.iBottom = 0; // allow the viewrect to extend into the bottom margin |
|
346 editorMargins.iTop = 0; |
|
347 editorMargins.iRight = (TUint8)rightMargin; |
|
348 editorMargins.iLeft = (TUint8)leftMargin; |
|
349 |
|
350 // Use left and right layout information (from parameters) and additional margins |
|
351 // (for highlights). Top and bottom corrections are not done here. |
|
352 edwinRect.iTl.iX += aLeftMargin; |
|
353 edwinRect.iTl.iX -=editorMargins.iLeft; // subtract left highlight margin |
|
354 edwinRect.iBr.iX -= aRightMargin; |
|
355 edwinRect.iBr.iX += editorMargins.iRight; // add right highlight margin |
|
356 #ifdef AKNUTILS_ENABLE_TRACES |
|
357 __ASSERT_DEBUG(edwinRect.Size().iWidth == aWidth, LOGTEXT(_L("AknLayoutUtils:LayoutEdwin: edwinRect.Size().iWidth differs from parameter value aWidth"))); |
|
358 #endif // AKNUTILS_ENABLE_TRACES |
|
359 |
|
360 // because of right alignment, cursor width added |
|
361 TInt cursorWidth = decorationMetrics.CursorWidth(); |
|
362 edwinRect.iBr.iX += cursorWidth; |
|
363 edwinRect.iTl.iX += cursorWidth; |
|
364 |
|
365 // Scaleable layout uses convention where topMargin (space for highlights) is positive. |
|
366 TInt posOfFirstBaselineInsideTextView( fontAscent + topMargin); |
|
367 TInt heightBetweenTextViewAndTopOfEditor( editorMargins.iTop ); |
|
368 TInt editorTopFromParentTop = |
|
369 aBaseline - (posOfFirstBaselineInsideTextView + heightBetweenTextViewAndTopOfEditor); |
|
370 |
|
371 #ifdef AKNUTILS_ENABLE_TRACES |
|
372 // There is a problem with layout or the font if the editor has had to be positioned higher than its parent |
|
373 if ( editorTopFromParentTop < 0 ) |
|
374 { |
|
375 LOGTEXT( _L("WARNING:LayoutEdwinScalable: Editor top has been placed higher than parent top") ); |
|
376 } |
|
377 #endif // AKNUTILS_ENABLE_TRACES |
|
378 |
|
379 aEdwin->SetBorderViewMargins(editorMargins); |
|
380 |
|
381 TInt madeATextView=KErrNone; |
|
382 if (!aEdwin->TextView()) |
|
383 TRAP(madeATextView,aEdwin->CreateTextViewL()); |
|
384 if (KErrNone==madeATextView) |
|
385 { |
|
386 |
|
387 /* |
|
388 The left and right values passed to SetHighlighExtensions are unambiguous. |
|
389 The top value is measured up from the top of the textview. Note that that the top of the textview |
|
390 includes all of the following: |
|
391 Font ascent; |
|
392 + Any excess height as reported by OpenFont's MaxHeight; |
|
393 + excess height above that requested by SetExcessHeightRequired |
|
394 Since we already pass in the top margin + any excess over and above OpenFont's maxheight into |
|
395 SetExcessHeightRequired (see below), then the top highlight needs no extension. |
|
396 |
|
397 The bottomMargin returned by HighlightExtensionsFromFont is measured down from the bottom of the Series 60 |
|
398 text pane. But the value to be passed in to SetHighlightExtension is measured down from the default bottom |
|
399 of Form's Text Band. Now, the bottom of the Text Band is by default the top of the text on the |
|
400 next line (or where the next line would be). However, the placement of the Text Band is modified |
|
401 by the call to SetExcessHeightRequired, raising it up by the value passed in. |
|
402 */ |
|
403 |
|
404 // First we can group together all the distances from the top of the highlight to the baseline |
|
405 TInt topOfHighlightToBaseline = maxHeight + roomForHighGlyphs + topMargin; |
|
406 // Position ourselves at the top of the CURRENT line by subtracting baselineDelta. |
|
407 TInt bottomWrtBandedHeight = -baselineDelta; |
|
408 // Then we can measure down to the bottom of the highlight: |
|
409 bottomWrtBandedHeight += topOfHighlightToBaseline + aFont->BaselineToTextPaneBottom() + bottomMargin; |
|
410 |
|
411 aEdwin->TextView()->SetHighlightExtensions( |
|
412 leftMargin, rightMargin, 0, bottomWrtBandedHeight ); |
|
413 } |
|
414 /* |
|
415 Added to restrict the height of the edwin in pixels to the max height in lines. |
|
416 This is because MaximumHeightInLines is simply a number held by Edwin and the editor |
|
417 height is only enforced for MaximumHeight. |
|
418 */ |
|
419 TInt maxHeightInLinesForEdwin=aEdwin->MaximumHeightInLines(); |
|
420 if (maxHeightInLinesForEdwin) |
|
421 { |
|
422 |
|
423 TInt edwinMaxHeight = EdwinHeightFromLines( |
|
424 aFont->TextPaneHeight(), |
|
425 decorationMetrics, |
|
426 baselineDelta, |
|
427 maxHeightInLinesForEdwin ); |
|
428 aEdwin->SetMaximumHeight( edwinMaxHeight ); |
|
429 |
|
430 // Also restrict the number of lines to set up now |
|
431 if ( maxHeightInLinesForEdwin < aNumberOfLinesShown) |
|
432 { |
|
433 aNumberOfLinesShown = maxHeightInLinesForEdwin; |
|
434 } |
|
435 |
|
436 } |
|
437 |
|
438 /* |
|
439 Make the edwin height big enough to eliminate scrolling... |
|
440 If !aMinimizeEdwinView then this is fine. |
|
441 If aMinimizeEdwinView, the printing region will be altered anyway. |
|
442 */ |
|
443 TInt edwinHeight = EdwinHeightFromLines( |
|
444 aFont->TextPaneHeight(), |
|
445 decorationMetrics, |
|
446 baselineDelta, |
|
447 aNumberOfLinesShown ); |
|
448 |
|
449 edwinRect.iTl.iY += editorTopFromParentTop; |
|
450 TInt availableHeight = aEdwinParent.Height()-editorTopFromParentTop; |
|
451 if ( aEnsureEditorIsContainedByParent && (edwinHeight > availableHeight)) |
|
452 { |
|
453 aNumberOfVisibleLines = EdwinLinesWithinHeight( |
|
454 aFont->TextPaneHeight(), decorationMetrics, baselineDelta, availableHeight, edwinHeight ); |
|
455 } |
|
456 else |
|
457 { |
|
458 aNumberOfVisibleLines = aNumberOfLinesShown; |
|
459 } |
|
460 |
|
461 edwinRect.iBr.iY = edwinRect.iTl.iY + edwinHeight; |
|
462 |
|
463 if (aEdwin->TextLayout()) |
|
464 { |
|
465 // Do not automatically inflate the ascents inside Form |
|
466 aEdwin->TextLayout()->SetFontHeightIncreaseFactor(0); |
|
467 // Allow minimum descent of 0 |
|
468 aEdwin->TextLayout()->SetMinimumLineDescent(0); |
|
469 } |
|
470 |
|
471 CTextView* view = aEdwin->TextView(); |
|
472 if ( view ) |
|
473 { |
|
474 view->SetExcessHeightRequired( roomForHighGlyphs + topMargin ); |
|
475 // Cursor extensions and width |
|
476 TInt firstExtension = topMargin + aFont->TextPaneTopToBaseline() - aFont->AscentInPixels(); |
|
477 TInt secondExtension = bottomMargin + aFont->BaselineToTextPaneBottom() - aFont->DescentInPixels(); |
|
478 view->SetCursorExtensions( firstExtension, secondExtension ); |
|
479 view->SetCursorWeight( decorationMetrics.CursorWidth() ); |
|
480 } |
|
481 |
|
482 // The order of SetRect(), AlterViewRect and NotifyNewFormat is important. |
|
483 aEdwin->SetSuppressFormatting(ETrue); |
|
484 aEdwin->SetRect(edwinRect); |
|
485 aEdwin->SetSuppressFormatting(EFalse); |
|
486 |
|
487 aEdwin->SetSuppressNotifyDraw( ETrue ); |
|
488 TRAP_IGNORE(aEdwin->NotifyNewFormatL()); |
|
489 aEdwin->SetSuppressNotifyDraw( EFalse ); |
|
490 } |
|
491 |
|
492 void AknLayoutUtilsHelpers::LayoutEdwinScalable(CEikEdwin *aEdwin, |
|
493 const TRect &aEdwinParent, |
|
494 TInt aFontId, |
|
495 TInt aColor, |
|
496 TInt aLeftMargin, |
|
497 TInt aRightMargin, |
|
498 TInt aBaseline, |
|
499 TInt aWidth, |
|
500 TInt aJustification, |
|
501 TInt aNumberOfLinesShown, |
|
502 TInt aSecondLineBaseline, |
|
503 TAknsQsnTextColorsIndex aOverrideColor, |
|
504 const CAknLayoutFont *aCustomFont, |
|
505 TBool aMinimizeEdwinView) |
|
506 { |
|
507 __ASSERT_DEBUG(aEdwin,Panic(EAknPanicNullPointer)); |
|
508 __ASSERT_DEBUG(!(aEdwin->MaximumHeightInLines())||aNumberOfLinesShown<=aEdwin->MaximumHeightInLines(),Panic(EAknPanicOutOfRange)); |
|
509 |
|
510 const CAknLayoutFont *font = AknLayoutUtils::LayoutFontFromId(aFontId, aCustomFont); |
|
511 |
|
512 aBaseline = CorrectBaseline( aEdwinParent.Height(), aBaseline, aFontId); |
|
513 |
|
514 // This puts baseline into a more natural definition where the baselins is an infinitely |
|
515 // thin imaginary line underneath the glyphs' baseline pixels: |
|
516 aBaseline += 1; |
|
517 |
|
518 if (aSecondLineBaseline != 0) |
|
519 { |
|
520 aSecondLineBaseline = CorrectBaseline( aEdwinParent.Height(),aSecondLineBaseline, aFontId); |
|
521 aSecondLineBaseline += 1; // This puts baseline into a more natural definition |
|
522 } |
|
523 |
|
524 if (IsParentRelative(aLeftMargin)) { aLeftMargin = aEdwinParent.Width() - ELayoutP + aLeftMargin; } |
|
525 if (IsParentRelative(aRightMargin)) { aRightMargin = aEdwinParent.Width() - ELayoutP + aRightMargin; } |
|
526 if (IsParentRelative(aWidth)) { aWidth = aEdwinParent.Width() - ELayoutP + aWidth; } |
|
527 |
|
528 if (IsEmpty(aLeftMargin)) { aLeftMargin = aEdwinParent.Width() - aRightMargin - aWidth; } |
|
529 if (IsEmpty(aRightMargin)) { aRightMargin = aEdwinParent.Width() - aLeftMargin - aWidth; } |
|
530 if (IsEmpty(aWidth)) { aWidth = aEdwinParent.Width() - aLeftMargin - aRightMargin; } |
|
531 |
|
532 TAknTextDecorationMetrics metrics( aFontId ); |
|
533 LayoutEdwinScalableWithCorrectedParametersAndDecorationMetrics( |
|
534 aEdwin, |
|
535 aEdwinParent, |
|
536 font, |
|
537 aColor, |
|
538 aLeftMargin, |
|
539 aRightMargin, |
|
540 aBaseline, |
|
541 aWidth, |
|
542 aJustification, |
|
543 aNumberOfLinesShown, |
|
544 aSecondLineBaseline, |
|
545 aOverrideColor, |
|
546 metrics, |
|
547 EFalse, // Legacy behaviour is not to constrain editor to stay inside parent |
|
548 aMinimizeEdwinView); |
|
549 } |
|
550 |
|
551 void AknLayoutUtilsHelpers::GetEditorVerticalPositionWithinParent( |
|
552 TInt aParentHeight, |
|
553 const TAknTextLineLayout& aLayout, |
|
554 TInt& aVerticalPosOfEditor ) |
|
555 { |
|
556 |
|
557 TInt newBaseline = CorrectBaseline( aParentHeight, aLayout.iB, aLayout.FontId()); |
|
558 |
|
559 // This puts baseline into a more natural definition where the baselins is an infinitely |
|
560 // thin imaginary line underneath the glyphs' baseline pixels: |
|
561 newBaseline += 1; |
|
562 |
|
563 TInt fontId = aLayout.FontId(); |
|
564 const CAknLayoutFont* font = AknLayoutUtils::LayoutFontFromId( fontId, NULL ); |
|
565 |
|
566 TAknTextDecorationMetrics decorationMetrics( aLayout.FontId() ); |
|
567 |
|
568 // Editor margin" is used to position the TextView inside the editor |
|
569 // May have to modify top and bottom margins for font characteristics |
|
570 // "fontAscent" variable stands for total (+ve) distance from the baseline to the top of the Scalable layout textpane. |
|
571 TInt topMargin; |
|
572 TInt bottomMargin; |
|
573 decorationMetrics.GetTopAndBottomMargins( topMargin, bottomMargin); |
|
574 aVerticalPosOfEditor = |
|
575 EditorVerticalPositionWithinParent( font, newBaseline, topMargin ); |
|
576 } |
|
577 |
|
578 TInt AknLayoutUtilsHelpers::EditorVerticalPositionWithinParent( |
|
579 const CAknLayoutFont* aLayoutFont, |
|
580 TInt aFirstBaseline, |
|
581 TInt aTopMargin ) |
|
582 { |
|
583 return aFirstBaseline - (aLayoutFont->TextPaneTopToBaseline() + aTopMargin ); |
|
584 } |
|
585 |
|
586 |
|
587 |
|
588 // End of file |
|
589 |