uidesigner/com.nokia.sdt.series60.componentlibrary/components/textFormattingSrcgenLibrary.js
changeset 2 d760517a8095
equal deleted inserted replaced
-1:000000000000 2:d760517a8095
       
     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 the License "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 /**
       
    20  *	Create a contribution that sets up a CharFormat and CharFormatMask for use
       
    21  *  by CEikGlobalText and subcomponents (CEikRichText).
       
    22  *	@param contribs the contributions to append to
       
    23  *	@param instance instance of the component assumed to have the correct properties.
       
    24  *	@param location location to write to
       
    25  *	@return true iff generated the contribution (if some property not default).
       
    26  */
       
    27 function createCharFormatStructs(contribs, instance, location) {
       
    28 	var generated = false;
       
    29 	var properties = instance.properties;
       
    30 	var contribText = "TCharFormatMask charFormatMask;\nTCharFormat charFormat;\n";
       
    31 	
       
    32 	if (properties.charFormat.textColor != "") {
       
    33 		contribText += "charFormatMask.SetAttrib( EAttColor );\n";
       
    34 		contribText += "charFormat.iFontPresentation.iTextColor = TLogicalRgb( ";
       
    35 		contribText += this.getRgb(properties.charFormat.textColor);
       
    36 		contribText += " );\n";
       
    37 		generated = true;
       
    38 	}
       
    39 
       
    40 	if (properties.charFormat.highlightColor != "") {
       
    41 		contribText += "charFormatMask.SetAttrib( EAttFontHighlightColor );\n";
       
    42 		contribText += "charFormat.iFontPresentation.iHighlightColor = TLogicalRgb( ";
       
    43 		contribText += this.getRgb(properties.charFormat.highlightColor);
       
    44 		contribText += " );\n";
       
    45 		generated = true;
       
    46 	}
       
    47 	
       
    48 	if (properties.charFormat.highlightStyle != "EFontHighlightNone") {
       
    49 		contribText += "charFormatMask.SetAttrib( EAttFontHighlightStyle );\n";
       
    50 		contribText += "charFormat.iFontPresentation.iHighlightStyle = ";
       
    51 		contribText += "TFontPresentation::";
       
    52 		contribText += properties.charFormat.highlightStyle;
       
    53 		contribText += ";\n";
       
    54 		generated = true;
       
    55 	}
       
    56 
       
    57 	if (properties.charFormat.strikethrough) {
       
    58 		contribText += "charFormatMask.SetAttrib( EAttFontStrikethrough );\n";
       
    59 		contribText += "charFormat.iFontPresentation.iStrikethrough = EStrikethroughOn;\n";
       
    60 		generated = true;
       
    61 	}
       
    62 	
       
    63 	if (properties.charFormat.underline) {
       
    64 		contribText += "charFormatMask.SetAttrib( EAttFontUnderline );\n";
       
    65 		contribText += "charFormat.iFontPresentation.iUnderline = EUnderlineOn;\n";
       
    66 		generated = true;
       
    67 	}
       
    68 	
       
    69 	if (properties.charFormat.italics) {
       
    70 		contribText += "charFormatMask.SetAttrib( EAttFontPosture );\n";
       
    71 		contribText += "charFormat.iFontSpec.iFontStyle.SetPosture( EPostureItalic );\n";
       
    72 		generated = true;
       
    73 	}
       
    74 	
       
    75 	if (properties.charFormat.bold) {
       
    76 		contribText += "charFormatMask.SetAttrib( EAttFontStrokeWeight );\n";
       
    77 		contribText += "charFormat.iFontSpec.iFontStyle.SetStrokeWeight( EStrokeWeightBold );\n";
       
    78 		generated = true;
       
    79 	}
       
    80 	
       
    81 	if (properties.charFormat.hiddenText) {
       
    82 		contribText += "charFormatMask.SetAttrib( EAttFontHiddenText );\n";
       
    83 		contribText += "charFormat.iFontPresentation.iHiddenText = ETrue;\n";
       
    84 		generated = true;
       
    85 	}
       
    86 	
       
    87 	if (properties.charFormat.pictureAlignment != "EAlignBaseLine") {
       
    88 		contribText += "charFormatMask.SetAttrib( EAttFontPictureAlignment );\n";
       
    89 		contribText += "charFormat.iFontPresentation.iPictureAlignment = ";
       
    90 		contribText += "TFontPresentation::";
       
    91 		contribText += properties.charFormat.pictureAlignment;
       
    92 		contribText += ";\n";
       
    93 		generated = true;
       
    94 	}
       
    95 
       
    96 	if (generated) {
       
    97 		var contrib = Engine.createContributionForLocation(location);
       
    98 		contrib.setText(contribText);
       
    99 		contribs.add(contrib);
       
   100 	}
       
   101 	
       
   102 	return generated;		
       
   103 }
       
   104 
       
   105 function getRgb(colorProperty) {
       
   106 	if (colorProperty.indexOf(',') > 0)
       
   107 		return "TRgb( " + colorProperty + " )";
       
   108 	else
       
   109 		return "iEikonEnv->Color( ( TLogicalColor ) " + colorProperty + " )";
       
   110 }