uidesigner/com.nokia.carbide.cpp.uiq.components/components/textFormattingSrcgenLibrary.js
author tzelaw
Tue, 14 Apr 2009 15:03:19 -0500
changeset 94 d74b720418db
parent 2 d760517a8095
permissions -rw-r--r--
Test framework support: Ask debugger to remember DebugTarget so test framework can use it to setup test framework related utility. With this we can use the DebugUI way of launching while keeping test framework functionality
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
cawthron
parents:
diff changeset
     1
/*
cawthron
parents:
diff changeset
     2
* Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
cawthron
parents:
diff changeset
     3
* All rights reserved.
cawthron
parents:
diff changeset
     4
* This component and the accompanying materials are made available
cawthron
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
cawthron
parents:
diff changeset
     6
* which accompanies this distribution, and is available
cawthron
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
cawthron
parents:
diff changeset
     8
*
cawthron
parents:
diff changeset
     9
* Initial Contributors:
cawthron
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
cawthron
parents:
diff changeset
    11
*
cawthron
parents:
diff changeset
    12
* Contributors:
cawthron
parents:
diff changeset
    13
*
cawthron
parents:
diff changeset
    14
* Description: 
cawthron
parents:
diff changeset
    15
*
cawthron
parents:
diff changeset
    16
*/
cawthron
parents:
diff changeset
    17
cawthron
parents:
diff changeset
    18
cawthron
parents:
diff changeset
    19
/**
cawthron
parents:
diff changeset
    20
 *	Create a contribution that sets up a CharFormat and CharFormatMask for use
cawthron
parents:
diff changeset
    21
 *  by CEikGlobalText and subcomponents (CEikRichText).
cawthron
parents:
diff changeset
    22
 *	@param contribs the contributions to append to
cawthron
parents:
diff changeset
    23
 *	@param instance instance of the component assumed to have the correct properties.
cawthron
parents:
diff changeset
    24
 *	@param location location to write to
cawthron
parents:
diff changeset
    25
 *  @param phase phase to write to
cawthron
parents:
diff changeset
    26
 *	@return true iff generated the contribution (if some property not default).
cawthron
parents:
diff changeset
    27
 */
cawthron
parents:
diff changeset
    28
function createCharFormatStructs(contribs, instance, location, phase) {
cawthron
parents:
diff changeset
    29
	var generated = false;
cawthron
parents:
diff changeset
    30
	var properties = instance.properties;
cawthron
parents:
diff changeset
    31
	var contribText = "\tTCharFormatMask charFormatMask;\n\tTCharFormat charFormat;\n";
cawthron
parents:
diff changeset
    32
	
cawthron
parents:
diff changeset
    33
	if (properties.charFormat.textColor != "") {
cawthron
parents:
diff changeset
    34
		contribText += "\tcharFormatMask.SetAttrib( EAttColor );\n";
cawthron
parents:
diff changeset
    35
		contribText += "\tcharFormat.iFontPresentation.iTextColor = TLogicalRgb( ";
cawthron
parents:
diff changeset
    36
		contribText += this.getRgb(properties.charFormat.textColor);
cawthron
parents:
diff changeset
    37
		contribText += " );\n";
cawthron
parents:
diff changeset
    38
		generated = true;
cawthron
parents:
diff changeset
    39
	}
cawthron
parents:
diff changeset
    40
cawthron
parents:
diff changeset
    41
	if (properties.charFormat.highlightColor != "") {
cawthron
parents:
diff changeset
    42
		contribText += "\tcharFormatMask.SetAttrib( EAttFontHighlightColor );\n";
cawthron
parents:
diff changeset
    43
		contribText += "\tcharFormat.iFontPresentation.iHighlightColor = TLogicalRgb( ";
cawthron
parents:
diff changeset
    44
		contribText += this.getRgb(properties.charFormat.highlightColor);
cawthron
parents:
diff changeset
    45
		contribText += " );\n";
cawthron
parents:
diff changeset
    46
		generated = true;
cawthron
parents:
diff changeset
    47
	}
cawthron
parents:
diff changeset
    48
	
cawthron
parents:
diff changeset
    49
	if (properties.charFormat.highlightStyle != "EFontHighlightNone") {
cawthron
parents:
diff changeset
    50
		contribText += "\tcharFormatMask.SetAttrib( EAttFontHighlightStyle );\n";
cawthron
parents:
diff changeset
    51
		contribText += "\tcharFormat.iFontPresentation.iHighlightStyle = ";
cawthron
parents:
diff changeset
    52
		contribText += "\tTFontPresentation::";
cawthron
parents:
diff changeset
    53
		contribText += properties.charFormat.highlightStyle;
cawthron
parents:
diff changeset
    54
		contribText += ";\n";
cawthron
parents:
diff changeset
    55
		generated = true;
cawthron
parents:
diff changeset
    56
	}
cawthron
parents:
diff changeset
    57
cawthron
parents:
diff changeset
    58
	if (properties.charFormat.strikethrough) {
cawthron
parents:
diff changeset
    59
		contribText += "\tcharFormatMask.SetAttrib( EAttFontStrikethrough );\n";
cawthron
parents:
diff changeset
    60
		contribText += "\tcharFormat.iFontPresentation.iStrikethrough = EStrikethroughOn;\n";
cawthron
parents:
diff changeset
    61
		generated = true;
cawthron
parents:
diff changeset
    62
	}
cawthron
parents:
diff changeset
    63
	
cawthron
parents:
diff changeset
    64
	if (properties.charFormat.underline) {
cawthron
parents:
diff changeset
    65
		contribText += "\tcharFormatMask.SetAttrib( EAttFontUnderline );\n";
cawthron
parents:
diff changeset
    66
		contribText += "\tcharFormat.iFontPresentation.iUnderline = EUnderlineOn;\n";
cawthron
parents:
diff changeset
    67
		generated = true;
cawthron
parents:
diff changeset
    68
	}
cawthron
parents:
diff changeset
    69
	
cawthron
parents:
diff changeset
    70
	if (properties.charFormat.italics) {
cawthron
parents:
diff changeset
    71
		contribText += "\tcharFormatMask.SetAttrib( EAttFontPosture );\n";
cawthron
parents:
diff changeset
    72
		contribText += "\tcharFormat.iFontSpec.iFontStyle.SetPosture( EPostureItalic );\n";
cawthron
parents:
diff changeset
    73
		generated = true;
cawthron
parents:
diff changeset
    74
	}
cawthron
parents:
diff changeset
    75
	
cawthron
parents:
diff changeset
    76
	if (properties.charFormat.bold) {
cawthron
parents:
diff changeset
    77
		contribText += "\tcharFormatMask.SetAttrib( EAttFontStrokeWeight );\n";
cawthron
parents:
diff changeset
    78
		contribText += "\tcharFormat.iFontSpec.iFontStyle.SetStrokeWeight( EStrokeWeightBold );\n";
cawthron
parents:
diff changeset
    79
		generated = true;
cawthron
parents:
diff changeset
    80
	}
cawthron
parents:
diff changeset
    81
	
cawthron
parents:
diff changeset
    82
	if (properties.charFormat.hiddenText) {
cawthron
parents:
diff changeset
    83
		contribText += "\tcharFormatMask.SetAttrib( EAttFontHiddenText );\n";
cawthron
parents:
diff changeset
    84
		contribText += "\tcharFormat.iFontPresentation.iHiddenText = ETrue;\n";
cawthron
parents:
diff changeset
    85
		generated = true;
cawthron
parents:
diff changeset
    86
	}
cawthron
parents:
diff changeset
    87
	
cawthron
parents:
diff changeset
    88
	if (properties.charFormat.pictureAlignment != "EAlignBaseLine") {
cawthron
parents:
diff changeset
    89
		contribText += "\tcharFormatMask.SetAttrib( EAttFontPictureAlignment );\n";
cawthron
parents:
diff changeset
    90
		contribText += "\tcharFormat.iFontPresentation.iPictureAlignment = ";
cawthron
parents:
diff changeset
    91
		contribText += "\tTFontPresentation::";
cawthron
parents:
diff changeset
    92
		contribText += properties.charFormat.pictureAlignment;
cawthron
parents:
diff changeset
    93
		contribText += ";\n";
cawthron
parents:
diff changeset
    94
		generated = true;
cawthron
parents:
diff changeset
    95
	}
cawthron
parents:
diff changeset
    96
	
cawthron
parents:
diff changeset
    97
	if (generated) {
cawthron
parents:
diff changeset
    98
		if (instance.component.id == "com.nokia.carbide.uiq.CEikRichText") {
cawthron
parents:
diff changeset
    99
			contribText += "\tCRichText* richtxt = " + instance.memberName + "->RichText();\n";
cawthron
parents:
diff changeset
   100
			contribText += "\trichtxt->ApplyCharFormatL( charFormat, charFormatMask, 0, richtxt->DocumentLength() );\n";
cawthron
parents:
diff changeset
   101
		} else {
cawthron
parents:
diff changeset
   102
			contribText += "\t" + instance.memberName + "->ApplyCharFormatL( charFormat, charFormatMask );\n";
cawthron
parents:
diff changeset
   103
		}
cawthron
parents:
diff changeset
   104
	}
cawthron
parents:
diff changeset
   105
cawthron
parents:
diff changeset
   106
	if (generated) {
cawthron
parents:
diff changeset
   107
		var contrib = null; 
cawthron
parents:
diff changeset
   108
		if (location != null) {
cawthron
parents:
diff changeset
   109
			contrib = Engine.createContributionForLocation(location);
cawthron
parents:
diff changeset
   110
		} else {
cawthron
parents:
diff changeset
   111
			contrib = Engine.createContributionForPhase(phase);
cawthron
parents:
diff changeset
   112
		}
cawthron
parents:
diff changeset
   113
		var opening = "\nif ( " + instance.memberName + " != NULL )\n";
cawthron
parents:
diff changeset
   114
		opening += "\t{\n";
cawthron
parents:
diff changeset
   115
		var closing = "\t}\n"
cawthron
parents:
diff changeset
   116
		contribText = opening + contribText + closing;
cawthron
parents:
diff changeset
   117
		contrib.setText(contribText);
cawthron
parents:
diff changeset
   118
		contribs.add(contrib);
cawthron
parents:
diff changeset
   119
	}
cawthron
parents:
diff changeset
   120
	
cawthron
parents:
diff changeset
   121
	return generated;		
cawthron
parents:
diff changeset
   122
}
cawthron
parents:
diff changeset
   123
cawthron
parents:
diff changeset
   124
/**
cawthron
parents:
diff changeset
   125
 *	Create a contribution that sets up a CharFormat and CharFormatMask for use
cawthron
parents:
diff changeset
   126
 *  by CEikGlobalText and subcomponents (CEikRichText).
cawthron
parents:
diff changeset
   127
 *	@param contribs the contributions to append to
cawthron
parents:
diff changeset
   128
 *	@param instance instance of the component assumed to have the correct properties.
cawthron
parents:
diff changeset
   129
 *  @param phase phase to write to
cawthron
parents:
diff changeset
   130
 *	@return true if generated the contribution (if some property not default).
cawthron
parents:
diff changeset
   131
 */
cawthron
parents:
diff changeset
   132
function createCharFormatStructsForPhase(contribs, instance, phase) {
cawthron
parents:
diff changeset
   133
	var generated = createCharFormatStructs(contribs, instance, null, phase);
cawthron
parents:
diff changeset
   134
	return generated;
cawthron
parents:
diff changeset
   135
}
cawthron
parents:
diff changeset
   136
cawthron
parents:
diff changeset
   137
cawthron
parents:
diff changeset
   138
function getRgb(colorProperty) {
cawthron
parents:
diff changeset
   139
	if (colorProperty.indexOf(',') > 0)
cawthron
parents:
diff changeset
   140
		return "TRgb( " + colorProperty + " )";
cawthron
parents:
diff changeset
   141
	else
cawthron
parents:
diff changeset
   142
		return "iEikonEnv->Color( ( TLogicalColor ) " + colorProperty + " )";
cawthron
parents:
diff changeset
   143
}