26 #include <AknUtils.h> |
26 #include <AknUtils.h> |
27 #include <AknLayoutFont.h> |
27 #include <AknLayoutFont.h> |
28 #include <AknSettingCache.h> |
28 #include <AknSettingCache.h> |
29 #include <AknsUtils.h> |
29 #include <AknsUtils.h> |
30 #include <AknPanic.h> |
30 #include <AknPanic.h> |
31 |
31 #include <txtglobl.h> // CGlobalText |
|
32 #include <aknextendedinputcapabilities.h> // CAknExtendedInputCapabilities |
|
33 |
|
34 const TInt KAlignFlagsOfferset( 3 ); |
|
35 const TInt KNeedFormat( 2000 ); // If text length < 2000 then format it. |
32 LOCAL_C TBool IsEmpty(TInt aValue) |
36 LOCAL_C TBool IsEmpty(TInt aValue) |
33 { |
37 { |
34 return aValue == ELayoutEmpty; |
38 return aValue == ELayoutEmpty; |
35 } |
39 } |
36 |
40 |
37 |
41 |
38 // ================= MEMBER FUNCTIONS ======================= |
42 // ================= MEMBER FUNCTIONS ======================= |
39 |
43 |
40 |
44 |
41 TInt AknLayoutUtilsHelpers::CorrectBaseline( TInt aParentHeight, TInt aBaseline, TInt aFontId ) |
45 TInt AknLayoutUtilsHelpers::CorrectBaseline( TInt aParentHeight, TInt aBaseline, TInt aFontId ) |
50 if (IsParentRelative(b)) { b = aParentHeight - ELayoutP + b; } |
54 if (IsParentRelative(b)) { b = aParentHeight - ELayoutP + b; } |
51 |
55 |
52 const CAknLayoutFont *font = AknLayoutUtils::LayoutFontFromId(aFontId); |
56 const CAknLayoutFont *font = AknLayoutUtils::LayoutFontFromId(aFontId); |
53 TInt descent = font->BaselineToTextPaneBottom(); |
57 TInt descent = font->BaselineToTextPaneBottom(); |
54 |
58 |
55 // calculate distance down from top of parent to bottom of maximal glyph |
59 // calculate distance down from top of parent to bottom of maximal glyph |
56 TInt top2bog = aParentHeight - b; |
60 TInt top2bog = aParentHeight - b; |
57 |
61 |
58 // distance down to baseline is distance down to bottom of glyph minus descent |
62 // 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 |
63 // A further 1 is subtracted to account for the definition of baseline in the |
60 // Series 60 pre-2.8 layout specifications. |
64 // Series 60 pre-2.8 layout specifications. |
61 B = top2bog - descent - 1; |
65 B = top2bog - descent - 1; |
62 } |
66 } |
63 |
67 |
90 aVerticalPositionOfEdwin = |
94 aVerticalPositionOfEdwin = |
91 EditorVerticalPositionWithinParent( font, newBaseline, topMargin ); |
95 EditorVerticalPositionWithinParent( font, newBaseline, topMargin ); |
92 |
96 |
93 return EdwinHeightFromLines( |
97 return EdwinHeightFromLines( |
94 font->TextPaneHeight(), decorationMetrics, |
98 font->TextPaneHeight(), decorationMetrics, |
95 aBaselineSeparationOverRide, aNumberOfLinesToShowOverRide); |
99 aBaselineSeparationOverRide, aNumberOfLinesToShowOverRide); |
96 } |
100 } |
97 |
101 |
98 TInt AknLayoutUtilsHelpers::EdwinHeightFromLines ( |
102 TInt AknLayoutUtilsHelpers::EdwinHeightFromLines ( |
99 TInt aTextPaneHeight, |
103 TInt aTextPaneHeight, |
100 TAknTextDecorationMetrics& aDecorationMetrics, |
104 TAknTextDecorationMetrics& aDecorationMetrics, |
258 paraFormat.iLineSpacingControl = CParaFormat::ELineSpacingExactlyInPixels; |
262 paraFormat.iLineSpacingControl = CParaFormat::ELineSpacingExactlyInPixels; |
259 paraFormatMask.SetAttrib(EAttLineSpacingControl); // Switches mode to "Exact line spacing" |
263 paraFormatMask.SetAttrib(EAttLineSpacingControl); // Switches mode to "Exact line spacing" |
260 paraFormat.iLineSpacingInTwips = baselineDelta; |
264 paraFormat.iLineSpacingInTwips = baselineDelta; |
261 paraFormatMask.SetAttrib(EAttLineSpacing); |
265 paraFormatMask.SetAttrib(EAttLineSpacing); |
262 |
266 |
263 CAknSettingCache& cache = CAknEnv::Static()->SettingCache(); |
267 CAknSettingCache& cache = CAknEnv::Static()->SettingCache(); |
264 paraFormat.iLanguage = cache.InputLanguage(); // Default paragraph language (in case there is no text yet) |
268 paraFormat.iLanguage = cache.InputLanguage(); // Default paragraph language (in case there is no text yet) |
265 paraFormatMask.SetAttrib(EAttParaLanguage); |
269 paraFormatMask.SetAttrib(EAttParaLanguage); |
266 |
270 |
267 TCharFormat charFormat; |
271 TCharFormat charFormat; |
268 TCharFormatMask charFormatMask; |
272 TCharFormatMask charFormatMask; |
269 charFormat.iFontSpec = aFont->FontSpecInTwips(); |
273 charFormat.iFontSpec = aFont->FontSpecInTwips(); |
270 charFormatMask.SetAttrib(EAttFontTypeface); |
274 charFormatMask.SetAttrib(EAttFontTypeface); |
271 charFormatMask.SetAttrib(EAttFontHeight); |
275 charFormatMask.SetAttrib(EAttFontHeight); |
272 charFormatMask.SetAttrib(EAttFontStrokeWeight); |
276 charFormatMask.SetAttrib(EAttFontStrokeWeight); |
273 charFormatMask.SetAttrib(EAttFontPosture); |
277 charFormatMask.SetAttrib(EAttFontPosture); |
274 |
278 |
275 charFormat.iFontPresentation.iTextColor = AKN_LAF_COLOR_STATIC(aColor); |
279 charFormat.iFontPresentation.iTextColor = AKN_LAF_COLOR_STATIC(aColor); |
276 charFormatMask.SetAttrib(EAttColor); |
280 charFormatMask.SetAttrib(EAttColor); |
277 |
281 |
278 if ( AknsUtils::AvkonSkinEnabled() ) |
282 if ( AknsUtils::AvkonSkinEnabled() ) |
313 LOGTEXT(_L("Error in applying formatting\n")); |
318 LOGTEXT(_L("Error in applying formatting\n")); |
314 #endif // AKNUTILS_ENABLE_TRACES |
319 #endif // AKNUTILS_ENABLE_TRACES |
315 } |
320 } |
316 else |
321 else |
317 { |
322 { |
|
323 // Get paragraph format of current editor |
|
324 CGlobalText* globleText = static_cast<CGlobalText*>( aEdwin->Text() ); |
|
325 if ( globleText ) |
|
326 { |
|
327 TCursorSelection selection = aEdwin->Selection(); |
|
328 TInt selectionLength = selection.Length(); |
|
329 CParaFormat oldParaFormat; |
|
330 TParaFormatMask oldParaMask; |
|
331 TRAPD( error, globleText->GetParaFormatL( &oldParaFormat, |
|
332 paraFormatMask, |
|
333 selection.LowerPos(), |
|
334 selectionLength ) ); |
|
335 if ( error == KErrNone ) |
|
336 { |
|
337 // Get char format of current editor |
|
338 TCharFormat oldCharFormat; |
|
339 TCharFormatMask oldCharMask; |
|
340 TCharFormatMask charUndeterminedMask; |
|
341 globleText->GetCharFormat( oldCharFormat, |
|
342 charFormatMask, |
|
343 selection.LowerPos(), |
|
344 selectionLength); |
|
345 |
|
346 // If paragraph format and char format are not changed no need to do global format. |
|
347 needFormat = !( oldParaFormat.IsEqual( paraFormat, paraFormatMask ) && |
|
348 oldCharFormat.IsEqual( charFormat, charFormatMask ) ); |
|
349 } |
|
350 } |
318 aEdwin->SetParaFormatLayer(paraFormatLayer); |
351 aEdwin->SetParaFormatLayer(paraFormatLayer); |
319 aEdwin->SetCharFormatLayer(charFormatLayer); |
352 aEdwin->SetCharFormatLayer(charFormatLayer); |
320 } |
353 } |
321 aEdwin->SetSuppressFormatting(ETrue); |
354 aEdwin->SetSuppressFormatting( ETrue ); |
322 // Setting editor alignment must be done after |
355 // Setting editor alignment must be done after |
323 // other editor paragraph formatting |
356 // other editor paragraph formatting |
324 aEdwin->SetAlignment(aJustification); |
357 if ( !needFormat ) |
|
358 { |
|
359 CAknExtendedInputCapabilities* extendedInputCapabilities = |
|
360 aEdwin->MopGetObject( extendedInputCapabilities ); |
|
361 if ( extendedInputCapabilities ) |
|
362 { |
|
363 /* |
|
364 * We need to map LayoutAlign to InputEditorAlign, then check if the alignment |
|
365 * is changed. The algorithm is follow: |
|
366 * ELayoutAlignCenter = 1 -> EInputEditorAlignCenter = 0x00000010 |
|
367 * ELayoutAlignLeft = 2 -> EInputEditorAlignLeft = 0x00000020 |
|
368 * ELayoutAlignRight = 3 -> EInputEditorAlignRight = 0x00000040 |
|
369 * ELayoutAlignBidi = 4 -> EInputEditorAlignBidi = 0x00000080 |
|
370 */ |
|
371 TUint capabilities = extendedInputCapabilities->Capabilities(); |
|
372 capabilities &= CAknExtendedInputCapabilities::KAknEditorAlignMask; |
|
373 capabilities >>= ( KAlignFlagsOfferset + aJustification ); |
|
374 needFormat = ( capabilities != 1 ); |
|
375 } |
|
376 } |
|
377 aEdwin->SetAlignment(aJustification); |
325 aEdwin->SetSuppressFormatting(EFalse); |
378 aEdwin->SetSuppressFormatting(EFalse); |
326 |
379 |
327 aEdwin->SetBorder(ENone); |
380 aEdwin->SetBorder(ENone); |
328 |
381 |
329 // Edwin control`s rectangle starts out as the parent rectangle |
382 // Edwin control`s rectangle starts out as the parent rectangle |
478 view->SetCursorExtensions( firstExtension, secondExtension ); |
531 view->SetCursorExtensions( firstExtension, secondExtension ); |
479 view->SetCursorWeight( decorationMetrics.CursorWidth() ); |
532 view->SetCursorWeight( decorationMetrics.CursorWidth() ); |
480 } |
533 } |
481 |
534 |
482 // The order of SetRect(), AlterViewRect and NotifyNewFormat is important. |
535 // The order of SetRect(), AlterViewRect and NotifyNewFormat is important. |
483 aEdwin->SetSuppressFormatting(ETrue); |
536 aEdwin->SetSuppressFormatting( ETrue ); |
|
537 // If width is changed or text length is more then 2000 we will format |
|
538 // it by calling aEdwin->NotifyNewFormatL() at the end of this function. |
|
539 needFormat = ( needFormat || |
|
540 ( aEdwin->Rect().Width() != edwinRect.Width() ) || |
|
541 aEdwin->TextLength() < KNeedFormat ); |
484 aEdwin->SetRect(edwinRect); |
542 aEdwin->SetRect(edwinRect); |
485 aEdwin->SetSuppressFormatting(EFalse); |
543 aEdwin->SetSuppressFormatting(EFalse); |
486 |
544 |
487 aEdwin->SetSuppressNotifyDraw( ETrue ); |
545 aEdwin->SetSuppressNotifyDraw( ETrue ); |
488 TRAP_IGNORE(aEdwin->NotifyNewFormatL()); |
546 aEdwin->SetSuppressFormatting( !needFormat ); |
489 aEdwin->SetSuppressNotifyDraw( EFalse ); |
547 TRAP_IGNORE( aEdwin->NotifyNewFormatL() ); |
|
548 aEdwin->SetSuppressFormatting( EFalse ); |
|
549 aEdwin->SetSuppressNotifyDraw( EFalse ); |
490 } |
550 } |
491 |
551 |
492 void AknLayoutUtilsHelpers::LayoutEdwinScalable(CEikEdwin *aEdwin, |
552 void AknLayoutUtilsHelpers::LayoutEdwinScalable(CEikEdwin *aEdwin, |
493 const TRect &aEdwinParent, |
553 const TRect &aEdwinParent, |
494 TInt aFontId, |
554 TInt aFontId, |
504 const CAknLayoutFont *aCustomFont, |
564 const CAknLayoutFont *aCustomFont, |
505 TBool aMinimizeEdwinView) |
565 TBool aMinimizeEdwinView) |
506 { |
566 { |
507 __ASSERT_DEBUG(aEdwin,Panic(EAknPanicNullPointer)); |
567 __ASSERT_DEBUG(aEdwin,Panic(EAknPanicNullPointer)); |
508 __ASSERT_DEBUG(!(aEdwin->MaximumHeightInLines())||aNumberOfLinesShown<=aEdwin->MaximumHeightInLines(),Panic(EAknPanicOutOfRange)); |
568 __ASSERT_DEBUG(!(aEdwin->MaximumHeightInLines())||aNumberOfLinesShown<=aEdwin->MaximumHeightInLines(),Panic(EAknPanicOutOfRange)); |
509 |
569 |
510 const CAknLayoutFont *font = AknLayoutUtils::LayoutFontFromId(aFontId, aCustomFont); |
570 const CAknLayoutFont *font = AknLayoutUtils::LayoutFontFromId(aFontId, aCustomFont); |
511 |
571 |
512 aBaseline = CorrectBaseline( aEdwinParent.Height(), aBaseline, aFontId); |
572 aBaseline = CorrectBaseline( aEdwinParent.Height(), aBaseline, aFontId); |
513 |
573 |
514 // This puts baseline into a more natural definition where the baselins is an infinitely |
574 // This puts baseline into a more natural definition where the baselins is an infinitely |
515 // thin imaginary line underneath the glyphs' baseline pixels: |
575 // thin imaginary line underneath the glyphs' baseline pixels: |
516 aBaseline += 1; |
576 aBaseline += 1; |
517 |
577 |
518 if (aSecondLineBaseline != 0) |
578 if (aSecondLineBaseline != 0) |
519 { |
579 { |
520 aSecondLineBaseline = CorrectBaseline( aEdwinParent.Height(),aSecondLineBaseline, aFontId); |
580 aSecondLineBaseline = CorrectBaseline( aEdwinParent.Height(),aSecondLineBaseline, aFontId); |
521 aSecondLineBaseline += 1; // This puts baseline into a more natural definition |
581 aSecondLineBaseline += 1; // This puts baseline into a more natural definition |
522 } |
582 } |
523 |
583 |
524 if (IsParentRelative(aLeftMargin)) { aLeftMargin = aEdwinParent.Width() - ELayoutP + aLeftMargin; } |
584 if (IsParentRelative(aLeftMargin)) { aLeftMargin = aEdwinParent.Width() - ELayoutP + aLeftMargin; } |
525 if (IsParentRelative(aRightMargin)) { aRightMargin = aEdwinParent.Width() - ELayoutP + aRightMargin; } |
585 if (IsParentRelative(aRightMargin)) { aRightMargin = aEdwinParent.Width() - ELayoutP + aRightMargin; } |
526 if (IsParentRelative(aWidth)) { aWidth = aEdwinParent.Width() - ELayoutP + aWidth; } |
586 if (IsParentRelative(aWidth)) { aWidth = aEdwinParent.Width() - ELayoutP + aWidth; } |
527 |
587 |
528 if (IsEmpty(aLeftMargin)) { aLeftMargin = aEdwinParent.Width() - aRightMargin - aWidth; } |
588 if (IsEmpty(aLeftMargin)) { aLeftMargin = aEdwinParent.Width() - aRightMargin - aWidth; } |
529 if (IsEmpty(aRightMargin)) { aRightMargin = aEdwinParent.Width() - aLeftMargin - aWidth; } |
589 if (IsEmpty(aRightMargin)) { aRightMargin = aEdwinParent.Width() - aLeftMargin - aWidth; } |
530 if (IsEmpty(aWidth)) { aWidth = aEdwinParent.Width() - aLeftMargin - aRightMargin; } |
590 if (IsEmpty(aWidth)) { aWidth = aEdwinParent.Width() - aLeftMargin - aRightMargin; } |
531 |
591 |
532 TAknTextDecorationMetrics metrics( aFontId ); |
592 TAknTextDecorationMetrics metrics( aFontId ); |
533 LayoutEdwinScalableWithCorrectedParametersAndDecorationMetrics( |
593 LayoutEdwinScalableWithCorrectedParametersAndDecorationMetrics( |
534 aEdwin, |
594 aEdwin, |
535 aEdwinParent, |
595 aEdwinParent, |