uidesigner/com.nokia.carbide.cpp.uiq.components/components/srcgenLibrary.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
include("renderLibrary.js")
cawthron
parents:
diff changeset
    20
cawthron
parents:
diff changeset
    21
/**
cawthron
parents:
diff changeset
    22
 * Create a contribution that sets a property if its value
cawthron
parents:
diff changeset
    23
 * is not equal to a given default.  
cawthron
parents:
diff changeset
    24
 * @param phase the phase to supply
cawthron
parents:
diff changeset
    25
 * @param indent extra indentation to add (i.e. 1 if inside an "if")
cawthron
parents:
diff changeset
    26
 * @param instanceMemberName the name of the member variable
cawthron
parents:
diff changeset
    27
 * @param propertyValue the current value of the property
cawthron
parents:
diff changeset
    28
 * @param defaultValue the value considered the default
cawthron
parents:
diff changeset
    29
 * @param format a format string for setting the property, where
cawthron
parents:
diff changeset
    30
 *		{0} is substituted with instanceMemberName and 
cawthron
parents:
diff changeset
    31
 *		{1} is substituted with the propertyValue
cawthron
parents:
diff changeset
    32
 * @return a contribution, or null
cawthron
parents:
diff changeset
    33
 */
cawthron
parents:
diff changeset
    34
function createSetPropertyForPhase(contribs, phase, indent, instanceMemberName, 
cawthron
parents:
diff changeset
    35
			propertyValue, defaultValue, format) {
cawthron
parents:
diff changeset
    36
	if (propertyValue != defaultValue) {
cawthron
parents:
diff changeset
    37
		contrib = Engine.createContributionForPhase(phase);
cawthron
parents:
diff changeset
    38
		contrib.indentAdjust(indent);
cawthron
parents:
diff changeset
    39
		contrib.setFormattedText(format, new Array( instanceMemberName, propertyValue) );
cawthron
parents:
diff changeset
    40
		return contrib;
cawthron
parents:
diff changeset
    41
	}
cawthron
parents:
diff changeset
    42
	return null;
cawthron
parents:
diff changeset
    43
}
cawthron
parents:
diff changeset
    44
cawthron
parents:
diff changeset
    45
/**
cawthron
parents:
diff changeset
    46
 * Generate a contribution that sets a property if its value
cawthron
parents:
diff changeset
    47
 * is not equal to a given default.  
cawthron
parents:
diff changeset
    48
 * @param contribs the contribution list
cawthron
parents:
diff changeset
    49
 * @param phase the phase to supply
cawthron
parents:
diff changeset
    50
 * @param indent extra indentation to add (i.e. 1 if inside an "if")
cawthron
parents:
diff changeset
    51
 * @param instanceMemberName the name of the member variable
cawthron
parents:
diff changeset
    52
 * @param propertyValue the current value of the property
cawthron
parents:
diff changeset
    53
 * @param defaultValue the value considered the default
cawthron
parents:
diff changeset
    54
 * @param format a format string for setting the property, where
cawthron
parents:
diff changeset
    55
 *		{0} is substituted with instanceMemberName and 
cawthron
parents:
diff changeset
    56
 *		{1} is substituted with the propertyValue
cawthron
parents:
diff changeset
    57
 * @param checkNull if true, insert check for null instance around sette
cawthron
parents:
diff changeset
    58
 */
cawthron
parents:
diff changeset
    59
function setPropertyForPhase(contribs, phase, indent, instanceMemberName, 
cawthron
parents:
diff changeset
    60
			propertyValue, defaultValue, format, checkNull) {
cawthron
parents:
diff changeset
    61
	contrib = createSetPropertyForPhase(contribs, phase, indent, 
cawthron
parents:
diff changeset
    62
			instanceMemberName, propertyValue, defaultValue, format);
cawthron
parents:
diff changeset
    63
	if (contrib == null)
cawthron
parents:
diff changeset
    64
		return;
cawthron
parents:
diff changeset
    65
	if (checkNull) {
cawthron
parents:
diff changeset
    66
		acontrib = Engine.createContributionForPhase(phase);
cawthron
parents:
diff changeset
    67
		acontrib.indentAdjust(indent);
cawthron
parents:
diff changeset
    68
		acontrib.setFormattedText("if ( {0} )\n", [ instanceMemberName ]);
cawthron
parents:
diff changeset
    69
		contribs.add(acontrib);
cawthron
parents:
diff changeset
    70
		
cawthron
parents:
diff changeset
    71
		acontrib = Engine.createContributionForPhase(phase);
cawthron
parents:
diff changeset
    72
		acontrib.indentAdjust(indent+1);
cawthron
parents:
diff changeset
    73
		acontrib.setText("{\n");
cawthron
parents:
diff changeset
    74
		contribs.add(acontrib);
cawthron
parents:
diff changeset
    75
		
cawthron
parents:
diff changeset
    76
		contribs.add(contrib);
cawthron
parents:
diff changeset
    77
		
cawthron
parents:
diff changeset
    78
		acontrib = Engine.createContributionForPhase(phase);
cawthron
parents:
diff changeset
    79
		acontrib.indentAdjust(indent+1);
cawthron
parents:
diff changeset
    80
		acontrib.setText("}\n");
cawthron
parents:
diff changeset
    81
		contribs.add(acontrib);
cawthron
parents:
diff changeset
    82
	} else {
cawthron
parents:
diff changeset
    83
		contribs.add(contrib);
cawthron
parents:
diff changeset
    84
	}
cawthron
parents:
diff changeset
    85
}
cawthron
parents:
diff changeset
    86
cawthron
parents:
diff changeset
    87
/**
cawthron
parents:
diff changeset
    88
 * Generate a set of contributions to set multiple possible
cawthron
parents:
diff changeset
    89
 * properties.
cawthron
parents:
diff changeset
    90
 * Like #setPropertyForPhase(), where the 5th and later arguments
cawthron
parents:
diff changeset
    91
 * are taken in groups of three as [propertyValue, defaultValue, format].
cawthron
parents:
diff changeset
    92
 */
cawthron
parents:
diff changeset
    93
function setPropertiesForPhase(contribs, phase, indent, instanceMemberName, checkNull) {
cawthron
parents:
diff changeset
    94
	var ourContribStr = "";
cawthron
parents:
diff changeset
    95
	var any = false;
cawthron
parents:
diff changeset
    96
	var innerIndent = indent + (checkNull ? 1 : 0);
cawthron
parents:
diff changeset
    97
	for (var h = 5; h < arguments.length; h += 3) {
cawthron
parents:
diff changeset
    98
		contrib = createSetPropertyForPhase(contribs, phase, innerIndent, instanceMemberName,
cawthron
parents:
diff changeset
    99
			arguments[h], arguments[h+1], arguments[h+2]);
cawthron
parents:
diff changeset
   100
		if (contrib == null)
cawthron
parents:
diff changeset
   101
			continue;
cawthron
parents:
diff changeset
   102
		if (!any && checkNull) {
cawthron
parents:
diff changeset
   103
			acontrib = Engine.createContributionForPhase(phase);
cawthron
parents:
diff changeset
   104
			acontrib.indentAdjust(indent);
cawthron
parents:
diff changeset
   105
			acontrib.setFormattedText("if ( {0} )\n", [ instanceMemberName ]);
cawthron
parents:
diff changeset
   106
			ourContribStr = acontrib.getText();
cawthron
parents:
diff changeset
   107
			
cawthron
parents:
diff changeset
   108
			acontrib = Engine.createContributionForPhase(phase);
cawthron
parents:
diff changeset
   109
			acontrib.indentAdjust(indent+1);
cawthron
parents:
diff changeset
   110
			acontrib.setText("\t" + "{\n");
cawthron
parents:
diff changeset
   111
			ourContribStr = ourContribStr + acontrib.getText();
cawthron
parents:
diff changeset
   112
			
cawthron
parents:
diff changeset
   113
			any	= true;
cawthron
parents:
diff changeset
   114
		}
cawthron
parents:
diff changeset
   115
		ourContribStr = ourContribStr + "\t" + contrib.getText();
cawthron
parents:
diff changeset
   116
	}
cawthron
parents:
diff changeset
   117
cawthron
parents:
diff changeset
   118
	if (any && checkNull) {
cawthron
parents:
diff changeset
   119
		acontrib = Engine.createContributionForPhase(phase);
cawthron
parents:
diff changeset
   120
		acontrib.indentAdjust(indent+1);
cawthron
parents:
diff changeset
   121
		acontrib.setText("\t" + "}\n");
cawthron
parents:
diff changeset
   122
		ourContribStr = ourContribStr + acontrib.getText();
cawthron
parents:
diff changeset
   123
	}
cawthron
parents:
diff changeset
   124
	acontrib = Engine.createContributionForPhase(phase);
cawthron
parents:
diff changeset
   125
	acontrib.indentAdjust(indent);
cawthron
parents:
diff changeset
   126
	acontrib.setText(ourContribStr);
cawthron
parents:
diff changeset
   127
	contribs.add(acontrib);
cawthron
parents:
diff changeset
   128
}
cawthron
parents:
diff changeset
   129
cawthron
parents:
diff changeset
   130
/**
cawthron
parents:
diff changeset
   131
 *	Get the base filename
cawthron
parents:
diff changeset
   132
 *	@param path a path
cawthron
parents:
diff changeset
   133
 */
cawthron
parents:
diff changeset
   134
function getBaseFileName(path) {
cawthron
parents:
diff changeset
   135
	var idx = path.lastIndexOf('/');
cawthron
parents:
diff changeset
   136
	if (idx >= 0)
cawthron
parents:
diff changeset
   137
		base = path.substring(idx+1);
cawthron
parents:
diff changeset
   138
	else {
cawthron
parents:
diff changeset
   139
		idx = path.lastIndexOf('\\');
cawthron
parents:
diff changeset
   140
		if (idx >= 0)
cawthron
parents:
diff changeset
   141
			base = path.substring(idx+1);
cawthron
parents:
diff changeset
   142
		else
cawthron
parents:
diff changeset
   143
			base = path;
cawthron
parents:
diff changeset
   144
	}
cawthron
parents:
diff changeset
   145
	idx = base.lastIndexOf('.');
cawthron
parents:
diff changeset
   146
	if (idx >= 0)
cawthron
parents:
diff changeset
   147
		base = base.substring(0, idx);
cawthron
parents:
diff changeset
   148
		
cawthron
parents:
diff changeset
   149
	return base;
cawthron
parents:
diff changeset
   150
}
cawthron
parents:
diff changeset
   151
cawthron
parents:
diff changeset
   152
/**
cawthron
parents:
diff changeset
   153
 *	Get the bitmap header file
cawthron
parents:
diff changeset
   154
 *	@param path the system MBM/MIF name from the image.bmpfile property
cawthron
parents:
diff changeset
   155
 */
cawthron
parents:
diff changeset
   156
function getBitmapHeaderName(path) {
cawthron
parents:
diff changeset
   157
	var base = getBaseFileName(path);
cawthron
parents:
diff changeset
   158
	base = base + ".mbg";	
cawthron
parents:
diff changeset
   159
	return base.toLowerCase();
cawthron
parents:
diff changeset
   160
}
cawthron
parents:
diff changeset
   161
cawthron
parents:
diff changeset
   162
function addContrib(contribs, phase, loc, indent, text) {
cawthron
parents:
diff changeset
   163
	var c;
cawthron
parents:
diff changeset
   164
	if (phase != null)
cawthron
parents:
diff changeset
   165
		c = Engine.createContributionForPhase(phase);
cawthron
parents:
diff changeset
   166
	else
cawthron
parents:
diff changeset
   167
		c = Engine.createContributionForLocation(loc);
cawthron
parents:
diff changeset
   168
	c.setText(text);
cawthron
parents:
diff changeset
   169
	c.indentAdjust(indent);
cawthron
parents:
diff changeset
   170
	contribs.add(c);
cawthron
parents:
diff changeset
   171
}
cawthron
parents:
diff changeset
   172
cawthron
parents:
diff changeset
   173
function addFormattedContrib(contribs, phase, loc, indent, format, args) {
cawthron
parents:
diff changeset
   174
	var c;
cawthron
parents:
diff changeset
   175
	if (phase != null)
cawthron
parents:
diff changeset
   176
		c = Engine.createContributionForPhase(phase);
cawthron
parents:
diff changeset
   177
	else
cawthron
parents:
diff changeset
   178
		c = Engine.createContributionForLocation(loc);
cawthron
parents:
diff changeset
   179
	c.setFormattedText(format, args);
cawthron
parents:
diff changeset
   180
	c.indentAdjust(indent);
cawthron
parents:
diff changeset
   181
	contribs.add(c);
cawthron
parents:
diff changeset
   182
}
cawthron
parents:
diff changeset
   183
cawthron
parents:
diff changeset
   184
/**
cawthron
parents:
diff changeset
   185
 *	Get the nearest enclosing instance that defines a class.
cawthron
parents:
diff changeset
   186
 */
cawthron
parents:
diff changeset
   187
function getClassHolder(instance) {
cawthron
parents:
diff changeset
   188
	while (instance != null && !instance.properties.className) {
cawthron
parents:
diff changeset
   189
		instance = instance.parent;
cawthron
parents:
diff changeset
   190
	}
cawthron
parents:
diff changeset
   191
	return instance;
cawthron
parents:
diff changeset
   192
}
cawthron
parents:
diff changeset
   193
cawthron
parents:
diff changeset
   194
/**
cawthron
parents:
diff changeset
   195
 *	Get the table of multi-image filenames to literal names
cawthron
parents:
diff changeset
   196
 */
cawthron
parents:
diff changeset
   197
function getFilenameToLiteralTable(instance) {
cawthron
parents:
diff changeset
   198
	var holder = getClassHolder(instance);
cawthron
parents:
diff changeset
   199
	var key = "ImageSupport.filenameToLiteralTable:" + holder;
cawthron
parents:
diff changeset
   200
	var table = Engine.getGlobalDictionary().get(key);
cawthron
parents:
diff changeset
   201
	if (table == null) {
cawthron
parents:
diff changeset
   202
		table = new java.util.HashMap();
cawthron
parents:
diff changeset
   203
		Engine.getGlobalDictionary().put(key, table);
cawthron
parents:
diff changeset
   204
	}
cawthron
parents:
diff changeset
   205
	return table;
cawthron
parents:
diff changeset
   206
}
cawthron
parents:
diff changeset
   207
cawthron
parents:
diff changeset
   208
/**
cawthron
parents:
diff changeset
   209
 *	Get an identifier name from a MBM/MIF filepath
cawthron
parents:
diff changeset
   210
 */
cawthron
parents:
diff changeset
   211
function makeLiteralIdentifier(map, path) {
cawthron
parents:
diff changeset
   212
	// no need to uniquify, as the base mbmdef/mifdef name must be unique as well
cawthron
parents:
diff changeset
   213
	var base = getBaseFileName(path);
cawthron
parents:
diff changeset
   214
	var litname = "K" + base + "File";
cawthron
parents:
diff changeset
   215
	return litname;
cawthron
parents:
diff changeset
   216
}
cawthron
parents:
diff changeset
   217
cawthron
parents:
diff changeset
   218
/**
cawthron
parents:
diff changeset
   219
 *	Prepare a container for sourcegen that involves generating
cawthron
parents:
diff changeset
   220
 *	image properties.  We need to ensure the MBM/MIF filename for
cawthron
parents:
diff changeset
   221
 *	an image is emitted as a constant only once.
cawthron
parents:
diff changeset
   222
 */
cawthron
parents:
diff changeset
   223
function resetImagePropertyState(instance) {
cawthron
parents:
diff changeset
   224
	var classHolder = getClassHolder(instance);
cawthron
parents:
diff changeset
   225
	classHolder.filenameToLiteralTable = new java.util.HashMap();
cawthron
parents:
diff changeset
   226
}
cawthron
parents:
diff changeset
   227
cawthron
parents:
diff changeset
   228
/**
cawthron
parents:
diff changeset
   229
 *	Tell if an image property is set.  If not, it should be ignored.
cawthron
parents:
diff changeset
   230
 */		
cawthron
parents:
diff changeset
   231
function isImagePropertySet(imageProperty) {
cawthron
parents:
diff changeset
   232
	return imageProperty.bmpfile != "" 
cawthron
parents:
diff changeset
   233
		&& imageProperty.bmpid != "";
cawthron
parents:
diff changeset
   234
}
cawthron
parents:
diff changeset
   235
cawthron
parents:
diff changeset
   236
/** 
cawthron
parents:
diff changeset
   237
 *	Tell if we support scaling at all
cawthron
parents:
diff changeset
   238
 */
cawthron
parents:
diff changeset
   239
function isScalingIcons() {
cawthron
parents:
diff changeset
   240
	var version = getComponentVersions();
cawthron
parents:
diff changeset
   241
	if (version.getMajor() >= 3)
cawthron
parents:
diff changeset
   242
		return true;
cawthron
parents:
diff changeset
   243
	if (version.getMajor() == 2 && version.getMinor() >= 8) {
cawthron
parents:
diff changeset
   244
		appUi = getRootModelInstanceOfType("com.nokia.sdt.series60.CAknAppUi");
cawthron
parents:
diff changeset
   245
		if (appUi != null)
cawthron
parents:
diff changeset
   246
			return appUi.properties.layoutAware;
cawthron
parents:
diff changeset
   247
	}
cawthron
parents:
diff changeset
   248
	return false;
cawthron
parents:
diff changeset
   249
}
cawthron
parents:
diff changeset
   250
cawthron
parents:
diff changeset
   251
/**
cawthron
parents:
diff changeset
   252
 *	Set up contributions that set up an image property given
cawthron
parents:
diff changeset
   253
 *	its compound property.  This uses CFbsBitmap* objects and
cawthron
parents:
diff changeset
   254
 *	thus allows for resizing behavior.  Use a separate routine if
cawthron
parents:
diff changeset
   255
 *	setting up multiple images, since the repeated code for SVG setup
cawthron
parents:
diff changeset
   256
 *	can get quite long.
cawthron
parents:
diff changeset
   257
 *	@param contribs the contributions to append to
cawthron
parents:
diff changeset
   258
 *	@param instance instance the image is for (used to find the class)
cawthron
parents:
diff changeset
   259
 *	@param phase primary phase to write to (or null, loc must be set)
cawthron
parents:
diff changeset
   260
 *	@param loc primary location to write to (or null, phase must be set)
cawthron
parents:
diff changeset
   261
 *	@param indent indentation adjust
cawthron
parents:
diff changeset
   262
 *	@param imageProperty the property value
cawthron
parents:
diff changeset
   263
 *	@param aspectOption the appropriate enumeration for aspect ratio handling (or null)
cawthron
parents:
diff changeset
   264
 *	@param bitmapPattern when only a bitmap is set,
cawthron
parents:
diff changeset
   265
 *		a MessageFormat string to be substituted with arguments ([ CFbsBitmap* ])
cawthron
parents:
diff changeset
   266
 *	@param bitmapAndMaskPattern when a bitmap and mask is set,
cawthron
parents:
diff changeset
   267
 *		a MessageFormat string to be substituted with arguments (or null)
cawthron
parents:
diff changeset
   268
 *		([ CFbsBitmap*, CFbsBitmap* ])
cawthron
parents:
diff changeset
   269
 *	@param theSize text representing the TSize argument (e.g. "control->Size()" or "TSize(45, 66)")
cawthron
parents:
diff changeset
   270
 *			or null to use the image's real size
cawthron
parents:
diff changeset
   271
 */
cawthron
parents:
diff changeset
   272
function setupImageFromPropertyViaCFbsBitmap(contribs, instance, phase, loc, indent,
cawthron
parents:
diff changeset
   273
		imageProperty, aspectOption, 
cawthron
parents:
diff changeset
   274
		bitmapPattern, bitmapAndMaskPattern, theSize) {
cawthron
parents:
diff changeset
   275
cawthron
parents:
diff changeset
   276
	var version = getComponentVersions();
cawthron
parents:
diff changeset
   277
	var contrib;
cawthron
parents:
diff changeset
   278
cawthron
parents:
diff changeset
   279
	// moved here to precede system includes of .mbg files	
cawthron
parents:
diff changeset
   280
	var isSVG = imageProperty.editableValue.isSVG();
cawthron
parents:
diff changeset
   281
cawthron
parents:
diff changeset
   282
	if (isScalingIcons() || isSVG) {
cawthron
parents:
diff changeset
   283
		// get icon utilities header
cawthron
parents:
diff changeset
   284
		addContrib(contribs, "MainSystemIncludes", loc, 0,
cawthron
parents:
diff changeset
   285
			"#include <akniconutils.h>\n");
cawthron
parents:
diff changeset
   286
	}
cawthron
parents:
diff changeset
   287
	
cawthron
parents:
diff changeset
   288
	if (imageProperty.bmpfile != "") {
cawthron
parents:
diff changeset
   289
		// make the literal string for the filename
cawthron
parents:
diff changeset
   290
		var table = getFilenameToLiteralTable(instance);
cawthron
parents:
diff changeset
   291
		var litname = table.get(imageProperty.bmpfile);
cawthron
parents:
diff changeset
   292
		if (!litname) {
cawthron
parents:
diff changeset
   293
			litname = makeLiteralIdentifier(table, imageProperty.bmpfile);
cawthron
parents:
diff changeset
   294
			addContrib(contribs, "MainConstants", null, 0,
cawthron
parents:
diff changeset
   295
				"_LIT( " + litname +", \"" + 
cawthron
parents:
diff changeset
   296
					TextUtils.escape(imageProperty.bmpfile, '"') + "\" );\n");
cawthron
parents:
diff changeset
   297
	
cawthron
parents:
diff changeset
   298
			// get the mbg header
cawthron
parents:
diff changeset
   299
			addContrib(contribs, "MainSystemIncludes", null, 0,
cawthron
parents:
diff changeset
   300
				"#include <" + getBitmapHeaderName(imageProperty.bmpfile) + ">\n");
cawthron
parents:
diff changeset
   301
	
cawthron
parents:
diff changeset
   302
			table.put(imageProperty.bmpfile, litname);
cawthron
parents:
diff changeset
   303
		}
cawthron
parents:
diff changeset
   304
	}
cawthron
parents:
diff changeset
   305
cawthron
parents:
diff changeset
   306
	if (!isScalingIcons() && !isSVG) {
cawthron
parents:
diff changeset
   307
		// only unscalable bitmaps allowed, and initialized via CFbsBitmap
cawthron
parents:
diff changeset
   308
		indent++;
cawthron
parents:
diff changeset
   309
		addContrib(contribs, phase, loc, indent,
cawthron
parents:
diff changeset
   310
			"{\n");
cawthron
parents:
diff changeset
   311
		if (bitmapAndMaskPattern != null 
cawthron
parents:
diff changeset
   312
				&& imageProperty.bmpfile != ""
cawthron
parents:
diff changeset
   313
				&& imageProperty.bmpmask != "" 
cawthron
parents:
diff changeset
   314
				&& imageProperty.bmpid != "") {
cawthron
parents:
diff changeset
   315
			addContrib(contribs, phase, loc, indent,
cawthron
parents:
diff changeset
   316
				"CFbsBitmap* bitmap = iEikonEnv->CreateBitmapL( " + litname + ", " + imageProperty.bmpid + " );\n"
cawthron
parents:
diff changeset
   317
				);
cawthron
parents:
diff changeset
   318
			addContrib(contribs, phase, loc, indent,
cawthron
parents:
diff changeset
   319
				"CFbsBitmap* mask = iEikonEnv->CreateBitmapL( " + litname + ", " + imageProperty.bmpmask + " );\n"
cawthron
parents:
diff changeset
   320
				);
cawthron
parents:
diff changeset
   321
			
cawthron
parents:
diff changeset
   322
			addFormattedContrib(contribs, phase, loc, indent,
cawthron
parents:
diff changeset
   323
				bitmapAndMaskPattern, [ "bitmap", "mask" ]);
cawthron
parents:
diff changeset
   324
		}
cawthron
parents:
diff changeset
   325
		else if (bitmapPattern != null) {
cawthron
parents:
diff changeset
   326
			if (imageProperty.bmpfile != "" && imageProperty.bmpid != "") {
cawthron
parents:
diff changeset
   327
				addContrib(contribs, phase, loc, indent,
cawthron
parents:
diff changeset
   328
					"CFbsBitmap* bitmap = iEikonEnv->CreateBitmapL( " + litname + ", " + imageProperty.bmpid + " );\n"
cawthron
parents:
diff changeset
   329
					);
cawthron
parents:
diff changeset
   330
			} else {
cawthron
parents:
diff changeset
   331
				// no image, but at least a bitmap is required
cawthron
parents:
diff changeset
   332
				addContrib(contribs, phase, loc, indent,
cawthron
parents:
diff changeset
   333
					"CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;\n"
cawthron
parents:
diff changeset
   334
					);
cawthron
parents:
diff changeset
   335
			}						
cawthron
parents:
diff changeset
   336
			addFormattedContrib(contribs, phase, loc, indent,
cawthron
parents:
diff changeset
   337
				bitmapPattern, [ "bitmap" ]);
cawthron
parents:
diff changeset
   338
		}
cawthron
parents:
diff changeset
   339
cawthron
parents:
diff changeset
   340
		addContrib(contribs, phase, loc, indent,
cawthron
parents:
diff changeset
   341
			"}\n");
cawthron
parents:
diff changeset
   342
		indent--;
cawthron
parents:
diff changeset
   343
		
cawthron
parents:
diff changeset
   344
	} else {
cawthron
parents:
diff changeset
   345
		// S60 >= 3.0
cawthron
parents:
diff changeset
   346
		
cawthron
parents:
diff changeset
   347
		indent++;
cawthron
parents:
diff changeset
   348
cawthron
parents:
diff changeset
   349
		addContrib(contribs, phase, loc, indent,
cawthron
parents:
diff changeset
   350
			"{\n");
cawthron
parents:
diff changeset
   351
cawthron
parents:
diff changeset
   352
		var sizeArg = theSize;
cawthron
parents:
diff changeset
   353
		if (sizeArg == null)
cawthron
parents:
diff changeset
   354
			sizeArg = "size"; 	// for SVG 
cawthron
parents:
diff changeset
   355
cawthron
parents:
diff changeset
   356
		if (imageProperty.bmpfile != "") {		
cawthron
parents:
diff changeset
   357
			// load the bitmap and/or mask
cawthron
parents:
diff changeset
   358
			addContrib(contribs, phase, loc, indent,
cawthron
parents:
diff changeset
   359
				"CFbsBitmap *bitmap, *mask;\n");
cawthron
parents:
diff changeset
   360
				
cawthron
parents:
diff changeset
   361
			addContrib(contribs, phase, loc, indent,
cawthron
parents:
diff changeset
   362
				"AknIconUtils::CreateIconL( bitmap, mask,\n"+
cawthron
parents:
diff changeset
   363
				"\t\t" + litname + ", " + 
cawthron
parents:
diff changeset
   364
				((bitmapPattern != null && imageProperty.bmpid != "") ?
cawthron
parents:
diff changeset
   365
					imageProperty.bmpid : "-1") + 
cawthron
parents:
diff changeset
   366
					", " +
cawthron
parents:
diff changeset
   367
				((bitmapAndMaskPattern != null && imageProperty.bmpmask != "") ?
cawthron
parents:
diff changeset
   368
					imageProperty.bmpmask : "-1") +
cawthron
parents:
diff changeset
   369
					" );\n");
cawthron
parents:
diff changeset
   370
					
cawthron
parents:
diff changeset
   371
			// prepare to issue two calls needing SVG info
cawthron
parents:
diff changeset
   372
			if (isSVG && theSize == null) {
cawthron
parents:
diff changeset
   373
				addContrib(contribs, phase, loc, indent,
cawthron
parents:
diff changeset
   374
					"TSize size;\n"+
cawthron
parents:
diff changeset
   375
					"AknIconUtils::PreserveIconData( bitmap );\n"+
cawthron
parents:
diff changeset
   376
					//"AknIconUtils::PreserveIconData( mask );\n"+
cawthron
parents:
diff changeset
   377
					"");
cawthron
parents:
diff changeset
   378
			}
cawthron
parents:
diff changeset
   379
cawthron
parents:
diff changeset
   380
		} else {
cawthron
parents:
diff changeset
   381
			// no image, but at least a bitmap WITH CONTENT is required
cawthron
parents:
diff changeset
   382
			addContrib(contribs, phase, loc, indent,
cawthron
parents:
diff changeset
   383
				"CFbsBitmap *bitmap = new (ELeave) CFbsBitmap;\n"+
cawthron
parents:
diff changeset
   384
				"bitmap->Create( TSize( 1, 1), EGray2 );\n");
cawthron
parents:
diff changeset
   385
		}
cawthron
parents:
diff changeset
   386
		
cawthron
parents:
diff changeset
   387
		// set the size
cawthron
parents:
diff changeset
   388
		var aspectText;
cawthron
parents:
diff changeset
   389
		if (aspectOption != null && aspectOption != "")
cawthron
parents:
diff changeset
   390
			aspectText = ", " + aspectOption;
cawthron
parents:
diff changeset
   391
		else
cawthron
parents:
diff changeset
   392
			aspectText = ", EAspectRatioNotPreserved";
cawthron
parents:
diff changeset
   393
cawthron
parents:
diff changeset
   394
		if (imageProperty.bmpfile != "") {		
cawthron
parents:
diff changeset
   395
			if (isSVG && theSize == null) {
cawthron
parents:
diff changeset
   396
				// get the size
cawthron
parents:
diff changeset
   397
				addContrib(contribs, phase, loc, indent,
cawthron
parents:
diff changeset
   398
					"AknIconUtils::GetContentDimensions( bitmap, size );\n");
cawthron
parents:
diff changeset
   399
			}
cawthron
parents:
diff changeset
   400
		}
cawthron
parents:
diff changeset
   401
cawthron
parents:
diff changeset
   402
		if (bitmapAndMaskPattern != null 
cawthron
parents:
diff changeset
   403
				&& imageProperty.bmpfile != ""
cawthron
parents:
diff changeset
   404
				&& imageProperty.bmpmask != "" 
cawthron
parents:
diff changeset
   405
				&& imageProperty.bmpid != "") {
cawthron
parents:
diff changeset
   406
cawthron
parents:
diff changeset
   407
			addContrib(contribs, phase, loc, indent,
cawthron
parents:
diff changeset
   408
				"AknIconUtils::SetSize( bitmap, " + sizeArg + aspectText + " );\n");
cawthron
parents:
diff changeset
   409
			addContrib(contribs, phase, loc, indent,
cawthron
parents:
diff changeset
   410
				"AknIconUtils::SetSize( mask, " + sizeArg + aspectText + " );\n");
cawthron
parents:
diff changeset
   411
cawthron
parents:
diff changeset
   412
			addFormattedContrib(contribs, phase, loc, indent,
cawthron
parents:
diff changeset
   413
				bitmapAndMaskPattern, [ "bitmap", "mask" ]);
cawthron
parents:
diff changeset
   414
					
cawthron
parents:
diff changeset
   415
		} else if (bitmapPattern != null) {
cawthron
parents:
diff changeset
   416
			addContrib(contribs, phase, loc, indent,
cawthron
parents:
diff changeset
   417
				"AknIconUtils::SetSize( bitmap, " + theSize + aspectText + " );\n");
cawthron
parents:
diff changeset
   418
cawthron
parents:
diff changeset
   419
			addFormattedContrib(contribs, phase, loc, indent,
cawthron
parents:
diff changeset
   420
				bitmapPattern, [ "bitmap" ]);
cawthron
parents:
diff changeset
   421
		}
cawthron
parents:
diff changeset
   422
cawthron
parents:
diff changeset
   423
		if (isSVG && theSize == null) {
cawthron
parents:
diff changeset
   424
			addContrib(contribs, phase, loc, indent,
cawthron
parents:
diff changeset
   425
				"AknIconUtils::DestroyIconData( bitmap );\n");
cawthron
parents:
diff changeset
   426
		}
cawthron
parents:
diff changeset
   427
		
cawthron
parents:
diff changeset
   428
		addContrib(contribs, phase, loc, indent,
cawthron
parents:
diff changeset
   429
			"}\n");
cawthron
parents:
diff changeset
   430
		
cawthron
parents:
diff changeset
   431
		indent--;
cawthron
parents:
diff changeset
   432
	}
cawthron
parents:
diff changeset
   433
}
cawthron
parents:
diff changeset
   434
cawthron
parents:
diff changeset
   435
/**
cawthron
parents:
diff changeset
   436
 *	Set up contributions that set up an image property given
cawthron
parents:
diff changeset
   437
 *	its compound property.  This passes arguments to a function
cawthron
parents:
diff changeset
   438
 *	which takes the (TDesc aFileName, TInt bmpid, TInt maskid)
cawthron
parents:
diff changeset
   439
 *	arguments.  Image resizing is not allowed.
cawthron
parents:
diff changeset
   440
 *	@param contribs the contributions to append to
cawthron
parents:
diff changeset
   441
 *	@param instance instance the image is for (used to find the class)
cawthron
parents:
diff changeset
   442
 *	@param phase primary phase to write to (or null, loc must be set)
cawthron
parents:
diff changeset
   443
 *	@param loc primary location to write to (or null, phase must be set)
cawthron
parents:
diff changeset
   444
 *	@param indent indentation adjust
cawthron
parents:
diff changeset
   445
 *	@param imageProperty the compound property providing bmpfile, bmpid, bmpmask
cawthron
parents:
diff changeset
   446
 *	@param bitmapPattern when only a bitmap is set,
cawthron
parents:
diff changeset
   447
 *		a MessageFormat string to be substituted with arguments
cawthron
parents:
diff changeset
   448
 *		([ filename, id ])
cawthron
parents:
diff changeset
   449
 *	@param bitmapAndMaskPattern when a bitmap and mask is set,
cawthron
parents:
diff changeset
   450
 *		a MessageFormat string to be substituted with arguments (or null)
cawthron
parents:
diff changeset
   451
 *		([ filename, id, maskid ])
cawthron
parents:
diff changeset
   452
 */
cawthron
parents:
diff changeset
   453
function setupImageFromPropertyViaTuple(contribs, instance, phase, loc, indent,
cawthron
parents:
diff changeset
   454
		imageProperty,
cawthron
parents:
diff changeset
   455
		bitmapPattern, bitmapAndMaskPattern) {
cawthron
parents:
diff changeset
   456
cawthron
parents:
diff changeset
   457
	if (!isImagePropertySet(imageProperty))
cawthron
parents:
diff changeset
   458
		return;
cawthron
parents:
diff changeset
   459
		
cawthron
parents:
diff changeset
   460
	var version = getComponentVersions();
cawthron
parents:
diff changeset
   461
	var contrib;
cawthron
parents:
diff changeset
   462
	
cawthron
parents:
diff changeset
   463
	// make the literal string for the filename
cawthron
parents:
diff changeset
   464
	var table = getFilenameToLiteralTable(instance);
cawthron
parents:
diff changeset
   465
	var litname = table.get(imageProperty.bmpfile);
cawthron
parents:
diff changeset
   466
	if (!litname) {
cawthron
parents:
diff changeset
   467
		litname = makeLiteralIdentifier(table, imageProperty.bmpfile);
cawthron
parents:
diff changeset
   468
		addContrib(contribs, "MainConstants", null, 0,
cawthron
parents:
diff changeset
   469
			"_LIT( " + litname +", \"" + 
cawthron
parents:
diff changeset
   470
				TextUtils.escape(imageProperty.bmpfile, '"') + "\" );\n");
cawthron
parents:
diff changeset
   471
cawthron
parents:
diff changeset
   472
		// get the mbg header
cawthron
parents:
diff changeset
   473
		addContrib(contribs, "MainSystemIncludes", null, 0,
cawthron
parents:
diff changeset
   474
			"#include <" + getBitmapHeaderName(imageProperty.bmpfile) + ">\n");
cawthron
parents:
diff changeset
   475
cawthron
parents:
diff changeset
   476
		table.put(imageProperty.bmpfile, litname);
cawthron
parents:
diff changeset
   477
	}
cawthron
parents:
diff changeset
   478
		
cawthron
parents:
diff changeset
   479
	if (bitmapAndMaskPattern != null 
cawthron
parents:
diff changeset
   480
			&& imageProperty.bmpmask != "") {
cawthron
parents:
diff changeset
   481
		
cawthron
parents:
diff changeset
   482
		addFormattedContrib(contribs, phase, loc, indent,
cawthron
parents:
diff changeset
   483
			bitmapAndMaskPattern, [ litname, imageProperty.bmpid, imageProperty.bmpmask ]);
cawthron
parents:
diff changeset
   484
	}
cawthron
parents:
diff changeset
   485
	else if (bitmapPattern != null) {
cawthron
parents:
diff changeset
   486
		addFormattedContrib(contribs, phase, loc, indent,
cawthron
parents:
diff changeset
   487
			bitmapPattern, [ litname, imageProperty.bmpid ]);
cawthron
parents:
diff changeset
   488
	}
cawthron
parents:
diff changeset
   489
	
cawthron
parents:
diff changeset
   490
}
cawthron
parents:
diff changeset
   491
cawthron
parents:
diff changeset
   492
/**
cawthron
parents:
diff changeset
   493
 *	Create a method that loads and scales SVG or BMP icons, for use when
cawthron
parents:
diff changeset
   494
 *	multiple icons are loaded at once.  This assumes the function defined in
cawthron
parents:
diff changeset
   495
 *	LoadAndScaleIconL.inc.  For S60 2.8 or newer.
cawthron
parents:
diff changeset
   496
 */
cawthron
parents:
diff changeset
   497
function defineIconLoadingRoutines(contribs, location, className) { 
cawthron
parents:
diff changeset
   498
	// get icon utilities headers.  
cawthron
parents:
diff changeset
   499
	addContrib(contribs, "HeaderIncludes", null, 0,
cawthron
parents:
diff changeset
   500
		"#include <akniconutils.h>\n");
cawthron
parents:
diff changeset
   501
	addContrib(contribs, "HeaderIncludes", null, 0,
cawthron
parents:
diff changeset
   502
		"#include <gulicon.h>\n");
cawthron
parents:
diff changeset
   503
		
cawthron
parents:
diff changeset
   504
	//// needs to be permanent or else it's duplicated
cawthron
parents:
diff changeset
   505
	//addContrib(contribs, "UserHandlers", null, 0,
cawthron
parents:
diff changeset
   506
	addContrib(contribs, "ClassMethods", null, 0,
cawthron
parents:
diff changeset
   507
		"static CGulIcon* LoadAndScaleIconL(\n"+
cawthron
parents:
diff changeset
   508
		"\t\tconst TDesC& aFileName,\n"+
cawthron
parents:
diff changeset
   509
		"\t\tTInt aBitmapId,\n"+
cawthron
parents:
diff changeset
   510
		"\t\tTInt aMaskId,\n"+
cawthron
parents:
diff changeset
   511
		"\t\tTSize* aSize,\n"+
cawthron
parents:
diff changeset
   512
		"\t\tTScaleMode aScaleMode );\n"
cawthron
parents:
diff changeset
   513
	);
cawthron
parents:
diff changeset
   514
	
cawthron
parents:
diff changeset
   515
	// force the location to be instantiated
cawthron
parents:
diff changeset
   516
	addContrib(contribs, null, location, 0, "");
cawthron
parents:
diff changeset
   517
	return;
cawthron
parents:
diff changeset
   518
}
cawthron
parents:
diff changeset
   519
cawthron
parents:
diff changeset
   520
var alignmentMap = {
cawthron
parents:
diff changeset
   521
	"EHLeft+EVTop" : "EHLeftVTop",
cawthron
parents:
diff changeset
   522
	"EHLeft+EVCenter" : "EHLeftVCenter",
cawthron
parents:
diff changeset
   523
	"EHLeft+EVBottom" : "EHLeftVBottom",
cawthron
parents:
diff changeset
   524
	"EHCenter+EVTop" : "EHCenterVTop",
cawthron
parents:
diff changeset
   525
	"EHCenter+EVCenter" : "EHCenterVCenter",
cawthron
parents:
diff changeset
   526
	"EHCenter+EVBottom" : "EHCenterVBottom",
cawthron
parents:
diff changeset
   527
	"EHRight+EVTop" : "EHRightVTop",
cawthron
parents:
diff changeset
   528
	"EHRight+EVCenter" : "EHRightVCenter",
cawthron
parents:
diff changeset
   529
	"EHRight+EVBottom" : "EHRightVBottom"
cawthron
parents:
diff changeset
   530
};
cawthron
parents:
diff changeset
   531
cawthron
parents:
diff changeset
   532
function getTGulAlignmentValue(horiz, vert) {
cawthron
parents:
diff changeset
   533
	return alignmentMap[horiz+"+"+vert];	
cawthron
parents:
diff changeset
   534
}
cawthron
parents:
diff changeset
   535
cawthron
parents:
diff changeset
   536
//////////////////////////
cawthron
parents:
diff changeset
   537
cawthron
parents:
diff changeset
   538
/**
cawthron
parents:
diff changeset
   539
 *	Get the table of unique images in an icon array
cawthron
parents:
diff changeset
   540
 *	@return an ImageList
cawthron
parents:
diff changeset
   541
 */
cawthron
parents:
diff changeset
   542
function getImageList(instance) {
cawthron
parents:
diff changeset
   543
	var key = "srcgenLibrary.ImageList:" + instance.name;
cawthron
parents:
diff changeset
   544
	var table = Engine.getGlobalDictionary().get(key);
cawthron
parents:
diff changeset
   545
	if (table == null) {
cawthron
parents:
diff changeset
   546
		table = new ImageList(instance);
cawthron
parents:
diff changeset
   547
		Engine.getGlobalDictionary().put(key, table);
cawthron
parents:
diff changeset
   548
	}
cawthron
parents:
diff changeset
   549
	return table;
cawthron
parents:
diff changeset
   550
}
cawthron
parents:
diff changeset
   551
cawthron
parents:
diff changeset
   552
cawthron
parents:
diff changeset
   553
/**
cawthron
parents:
diff changeset
   554
 *	This is a prototype used to track arrays of icons.  
cawthron
parents:
diff changeset
   555
 *	Create an instance of the class and populate it with image
cawthron
parents:
diff changeset
   556
 *	properties, then generate contributions that create a
cawthron
parents:
diff changeset
   557
 *	CArrayPtr<CGulIcon> array, then look up indices of image
cawthron
parents:
diff changeset
   558
 *	properties either by index or generated enum.
cawthron
parents:
diff changeset
   559
 *
cawthron
parents:
diff changeset
   560
 *	@param ownerInstance the instance that owns all the images
cawthron
parents:
diff changeset
   561
 */
cawthron
parents:
diff changeset
   562
function ImageList(ownerInstance) {
cawthron
parents:
diff changeset
   563
	this.ownerInstance = ownerInstance;
cawthron
parents:
diff changeset
   564
	this.imageMap = new java.util.LinkedHashMap();
cawthron
parents:
diff changeset
   565
	this.enumSet = new java.util.LinkedHashSet();
cawthron
parents:
diff changeset
   566
	this.imageIdx = 0;
cawthron
parents:
diff changeset
   567
	this.lastEnum = "0";
cawthron
parents:
diff changeset
   568
}
cawthron
parents:
diff changeset
   569
cawthron
parents:
diff changeset
   570
ImageList.prototype.getImagePropertyKey = function(imageProperty) {
cawthron
parents:
diff changeset
   571
	if (isImagePropertySet(imageProperty)) {
cawthron
parents:
diff changeset
   572
		return imageProperty.bmpfile + "|" + imageProperty.bmpid + "|" + imageProperty.bmpmask;
cawthron
parents:
diff changeset
   573
	} else {
cawthron
parents:
diff changeset
   574
		return null;
cawthron
parents:
diff changeset
   575
	}
cawthron
parents:
diff changeset
   576
}
cawthron
parents:
diff changeset
   577
cawthron
parents:
diff changeset
   578
ImageList.prototype.uniquifyEnum = function(enm) {
cawthron
parents:
diff changeset
   579
	var idx = 1;
cawthron
parents:
diff changeset
   580
	var base = enm;
cawthron
parents:
diff changeset
   581
	while (this.enumSet.contains(enm)) {
cawthron
parents:
diff changeset
   582
		enm = base + (++idx);
cawthron
parents:
diff changeset
   583
	}
cawthron
parents:
diff changeset
   584
	return enm;
cawthron
parents:
diff changeset
   585
}
cawthron
parents:
diff changeset
   586
cawthron
parents:
diff changeset
   587
IL_PROPERTY_INDEX = 0;
cawthron
parents:
diff changeset
   588
IL_INDEX_INDEX = 1;
cawthron
parents:
diff changeset
   589
IL_ENUM_INDEX = 2;
cawthron
parents:
diff changeset
   590
cawthron
parents:
diff changeset
   591
/**
cawthron
parents:
diff changeset
   592
 *	Register an image property.  Only adds if unique.
cawthron
parents:
diff changeset
   593
 *	@param instance the instance containing the property
cawthron
parents:
diff changeset
   594
 *	@param property the property ID
cawthron
parents:
diff changeset
   595
 */
cawthron
parents:
diff changeset
   596
ImageList.prototype.registerImageProperty = function(imageProperty) {
cawthron
parents:
diff changeset
   597
	var key = this.getImagePropertyKey(imageProperty);
cawthron
parents:
diff changeset
   598
	if (key != null && !this.imageMap.containsKey(key)) {
cawthron
parents:
diff changeset
   599
		var base = imageProperty.bmpid;
cawthron
parents:
diff changeset
   600
		if (base == "")
cawthron
parents:
diff changeset
   601
			base = imageProperty.bmpmask;
cawthron
parents:
diff changeset
   602
		if (base.substring(0, 4) == "EMbm")
cawthron
parents:
diff changeset
   603
			base = base.substring(4);
cawthron
parents:
diff changeset
   604
		
cawthron
parents:
diff changeset
   605
		var enm = "E" + titleCase(this.ownerInstance.name) + base + "Index";
cawthron
parents:
diff changeset
   606
		enm = this.uniquifyEnum(enm);
cawthron
parents:
diff changeset
   607
		this.enumSet.add(enm);
cawthron
parents:
diff changeset
   608
		this.lastEnum = enm;
cawthron
parents:
diff changeset
   609
			
cawthron
parents:
diff changeset
   610
		this.imageMap.put(key, [imageProperty, this.imageIdx++, enm]);
cawthron
parents:
diff changeset
   611
	}
cawthron
parents:
diff changeset
   612
}
cawthron
parents:
diff changeset
   613
cawthron
parents:
diff changeset
   614
ImageList.prototype.getSystemImageKey = function(bitmap, mask) {
cawthron
parents:
diff changeset
   615
	if (bitmap == null || bitmap.length == 0)
cawthron
parents:
diff changeset
   616
		return null;
cawthron
parents:
diff changeset
   617
cawthron
parents:
diff changeset
   618
	var file = "KAvkonBitmapFile";	// constant in aknconsts.h
cawthron
parents:
diff changeset
   619
	var prefix = "EMbmAvkon";
cawthron
parents:
diff changeset
   620
	var key = file 
cawthron
parents:
diff changeset
   621
		+ "|" 
cawthron
parents:
diff changeset
   622
		+ (bitmap.length > 0 ? prefix + titleCase(bitmap) : "") 
cawthron
parents:
diff changeset
   623
		+ "|" 
cawthron
parents:
diff changeset
   624
		+ (mask.length > 0 ? prefix + titleCase(mask) : "");
cawthron
parents:
diff changeset
   625
	return key;
cawthron
parents:
diff changeset
   626
}
cawthron
parents:
diff changeset
   627
cawthron
parents:
diff changeset
   628
/**
cawthron
parents:
diff changeset
   629
 *	Register an Avkon system image (only added if unique).  
cawthron
parents:
diff changeset
   630
 */
cawthron
parents:
diff changeset
   631
ImageList.prototype.registerAvkonSystemImage = function(bitmap, mask) {
cawthron
parents:
diff changeset
   632
	var key = this.getSystemImageKey(bitmap, mask);
cawthron
parents:
diff changeset
   633
	if (key != null && !this.imageMap.containsKey(key)) {
cawthron
parents:
diff changeset
   634
		var enm = "E" + titleCase(this.ownerInstance.name) 
cawthron
parents:
diff changeset
   635
			+ "Avkon" + titleCase(bitmap != null ? bitmap : mask) 
cawthron
parents:
diff changeset
   636
			+ "Index";
cawthron
parents:
diff changeset
   637
		enm = this.uniquifyEnum(enm);
cawthron
parents:
diff changeset
   638
		this.lastEnum = enm;
cawthron
parents:
diff changeset
   639
cawthron
parents:
diff changeset
   640
		this.imageMap.put(key, [null, this.imageIdx++, enm]);
cawthron
parents:
diff changeset
   641
	}
cawthron
parents:
diff changeset
   642
}
cawthron
parents:
diff changeset
   643
cawthron
parents:
diff changeset
   644
/**
cawthron
parents:
diff changeset
   645
 *	Get the icon index for the given image.
cawthron
parents:
diff changeset
   646
 */
cawthron
parents:
diff changeset
   647
ImageList.prototype.getListIconIndexForProperty = function(imageProperty) {
cawthron
parents:
diff changeset
   648
	var key = this.getImagePropertyKey(imageProperty);
cawthron
parents:
diff changeset
   649
	var value = this.imageMap.get(key);
cawthron
parents:
diff changeset
   650
	if (value != null)
cawthron
parents:
diff changeset
   651
		return value[IL_INDEX_INDEX];
cawthron
parents:
diff changeset
   652
	else
cawthron
parents:
diff changeset
   653
		return -1;
cawthron
parents:
diff changeset
   654
}
cawthron
parents:
diff changeset
   655
cawthron
parents:
diff changeset
   656
/**
cawthron
parents:
diff changeset
   657
 *	Get the enumerator for the given image.
cawthron
parents:
diff changeset
   658
 */
cawthron
parents:
diff changeset
   659
ImageList.prototype.getListIconEnumForProperty = function(imageProperty, getEnum) {
cawthron
parents:
diff changeset
   660
	var key = this.getImagePropertyKey(imageProperty);
cawthron
parents:
diff changeset
   661
	var value = this.imageMap.get(key);
cawthron
parents:
diff changeset
   662
	if (value != null)
cawthron
parents:
diff changeset
   663
		return value[IL_ENUM_INDEX];
cawthron
parents:
diff changeset
   664
	else
cawthron
parents:
diff changeset
   665
		return null;
cawthron
parents:
diff changeset
   666
}
cawthron
parents:
diff changeset
   667
cawthron
parents:
diff changeset
   668
/**
cawthron
parents:
diff changeset
   669
 *	Get the number of images, also the upper bound of the indices
cawthron
parents:
diff changeset
   670
 */
cawthron
parents:
diff changeset
   671
ImageList.prototype.getImageCount = function() {
cawthron
parents:
diff changeset
   672
	return this.imageIdx;
cawthron
parents:
diff changeset
   673
}
cawthron
parents:
diff changeset
   674
cawthron
parents:
diff changeset
   675
ImageList.prototype.getLastEnumerator = function() {
cawthron
parents:
diff changeset
   676
	return this.lastEnum;
cawthron
parents:
diff changeset
   677
}
cawthron
parents:
diff changeset
   678
cawthron
parents:
diff changeset
   679
/**
cawthron
parents:
diff changeset
   680
 *	Generate code to set up a CGulIcon icon array.  Since S60 doesn't
cawthron
parents:
diff changeset
   681
 *	tolerate empty arrays, the generated code allocates the array only if needed,
cawthron
parents:
diff changeset
   682
 *	leaving it on the cleanup stack.  The caller of this code/routine
cawthron
parents:
diff changeset
   683
 *	needs to examine the return value and handle cleaning up appropriately.
cawthron
parents:
diff changeset
   684
 *	@param contribs
cawthron
parents:
diff changeset
   685
 *	@param iconsVar name of array variable to create (must be declared)
cawthron
parents:
diff changeset
   686
 *	@param location the function to add code to
cawthron
parents:
diff changeset
   687
 *	@param mainLocation preferably owned section in main file to add function to if needed
cawthron
parents:
diff changeset
   688
 *	@param instance instance to search upwards for owning class
cawthron
parents:
diff changeset
   689
 *	@param isScaling true if scaling bitmaps and icons, false otherwise
cawthron
parents:
diff changeset
   690
 *  @return true if icon array allocated
cawthron
parents:
diff changeset
   691
 */
cawthron
parents:
diff changeset
   692
ImageList.prototype.generateSetupIconArrayL = function(contribs, iconsVar, location, mainLocation, instance, isScaling) {
cawthron
parents:
diff changeset
   693
	// must not generate a zero-size array or set an empty icon array
cawthron
parents:
diff changeset
   694
	var anyIcons = false;
cawthron
parents:
diff changeset
   695
	
cawthron
parents:
diff changeset
   696
	var iconVar = (iconsVar.match(".*s") ? iconsVar.substring(0, iconsVar.length - 1) : iconsVar + "_instance");
cawthron
parents:
diff changeset
   697
	
cawthron
parents:
diff changeset
   698
	for (var iter = this.imageMap.entrySet().iterator(); iter.hasNext(); ) {
cawthron
parents:
diff changeset
   699
		var entry = iter.next();
cawthron
parents:
diff changeset
   700
		var key = entry.getKey();
cawthron
parents:
diff changeset
   701
		var value = entry.getValue();
cawthron
parents:
diff changeset
   702
		var property = value[IL_PROPERTY_INDEX];
cawthron
parents:
diff changeset
   703
		var index = value[IL_INDEX_INDEX];
cawthron
parents:
diff changeset
   704
		var enm = value[IL_ENUM_INDEX];
cawthron
parents:
diff changeset
   705
		var granularity = this.enumSet.size() > 0? this.enumSet.size() : 1;
cawthron
parents:
diff changeset
   706
cawthron
parents:
diff changeset
   707
		if (!anyIcons) {
cawthron
parents:
diff changeset
   708
			addFormattedContrib(contribs, null, location, 0,
cawthron
parents:
diff changeset
   709
				 "{0} = new (ELeave) CAknIconArray( {1} );\n",
cawthron
parents:
diff changeset
   710
				 [ iconsVar,
cawthron
parents:
diff changeset
   711
				 granularity
cawthron
parents:
diff changeset
   712
				 ] );
cawthron
parents:
diff changeset
   713
		
cawthron
parents:
diff changeset
   714
			addFormattedContrib(contribs, null, location,  0,
cawthron
parents:
diff changeset
   715
					"CleanupStack::PushL( {0} );\n",
cawthron
parents:
diff changeset
   716
					[ iconsVar ]);
cawthron
parents:
diff changeset
   717
cawthron
parents:
diff changeset
   718
			if (isScaling) {
cawthron
parents:
diff changeset
   719
				defineIconLoadingRoutines(contribs, mainLocation, getClassHolder(instance).properties["className"]);
cawthron
parents:
diff changeset
   720
			}
cawthron
parents:
diff changeset
   721
cawthron
parents:
diff changeset
   722
			addFormattedContrib(contribs, null, location,  0,
cawthron
parents:
diff changeset
   723
					"CGulIcon* {0};\n",
cawthron
parents:
diff changeset
   724
					[ iconVar ]);
cawthron
parents:
diff changeset
   725
cawthron
parents:
diff changeset
   726
			anyIcons = true;		
cawthron
parents:
diff changeset
   727
		}
cawthron
parents:
diff changeset
   728
		
cawthron
parents:
diff changeset
   729
		//println("querying " + instance + ", property="+property);
cawthron
parents:
diff changeset
   730
cawthron
parents:
diff changeset
   731
		// This assumes the user doesn't modify the ordering and
cawthron
parents:
diff changeset
   732
		// all enums map evenly to 0...N.
cawthron
parents:
diff changeset
   733
		// We can't use ->InsertL or ->ExtendL since they're stupid.
cawthron
parents:
diff changeset
   734
		var adder = "->AppendL";
cawthron
parents:
diff changeset
   735
		
cawthron
parents:
diff changeset
   736
		// Bug 7621: please ensure that a leave in the AppendL doesn't 
cawthron
parents:
diff changeset
   737
		// leak the allocated image.
cawthron
parents:
diff changeset
   738
		var saveIcon = "CleanupStack::PushL( " + iconVar + " );\n";
cawthron
parents:
diff changeset
   739
		var restoreIcon = "CleanupStack::Pop( " + iconVar + " );\n";
cawthron
parents:
diff changeset
   740
		var addIcon = iconsVar + adder + "( " + iconVar + " );\n";
cawthron
parents:
diff changeset
   741
		var saveAddAndRestore = saveIcon + addIcon + restoreIcon;
cawthron
parents:
diff changeset
   742
cawthron
parents:
diff changeset
   743
		contrib = Engine.createContributionForLocation(location);
cawthron
parents:
diff changeset
   744
		contrib.setText("// for " + enm + "\n");
cawthron
parents:
diff changeset
   745
		contribs.add(contrib);
cawthron
parents:
diff changeset
   746
	
cawthron
parents:
diff changeset
   747
		if (property == null) {
cawthron
parents:
diff changeset
   748
			// system image
cawthron
parents:
diff changeset
   749
			var parts = key.split("\\|");
cawthron
parents:
diff changeset
   750
			
cawthron
parents:
diff changeset
   751
			var contrib = Engine.createContributionForPhase("MainSystemIncludes");
cawthron
parents:
diff changeset
   752
			contrib.setText("#include <aknconsts.h>\n");
cawthron
parents:
diff changeset
   753
			contribs.add(contrib);
cawthron
parents:
diff changeset
   754
cawthron
parents:
diff changeset
   755
			contrib = Engine.createContributionForPhase("MainSystemIncludes");
cawthron
parents:
diff changeset
   756
			contrib.setText("#include <avkon.mbg>\n");
cawthron
parents:
diff changeset
   757
			contribs.add(contrib);
cawthron
parents:
diff changeset
   758
			
cawthron
parents:
diff changeset
   759
			var format;
cawthron
parents:
diff changeset
   760
			
cawthron
parents:
diff changeset
   761
			if (isScaling) {
cawthron
parents:
diff changeset
   762
				if (parts[2] != "") {
cawthron
parents:
diff changeset
   763
					format = iconVar + " = LoadAndScaleIconL(\n\t\t{0}, {1}, {2},\n\t\tNULL, EAspectRatioPreserved );\n"
cawthron
parents:
diff changeset
   764
						+ saveAddAndRestore;
cawthron
parents:
diff changeset
   765
				} else {
cawthron
parents:
diff changeset
   766
					format = iconVar + " = LoadAndScaleIconL(\n\t\t{0}, {1}, -1,\n\t\tNULL, EAspectRatioPreserved );\n"
cawthron
parents:
diff changeset
   767
						+ saveAddAndRestore;
cawthron
parents:
diff changeset
   768
				}
cawthron
parents:
diff changeset
   769
			} else {
cawthron
parents:
diff changeset
   770
				if (parts[2] != "") {
cawthron
parents:
diff changeset
   771
					format = iconVar + " = CEikonEnv::Static()->CreateIconL(\n\t\t{0}, {1}, {2} );\n"
cawthron
parents:
diff changeset
   772
						+ saveAddAndRestore;
cawthron
parents:
diff changeset
   773
				} else {
cawthron
parents:
diff changeset
   774
					format = iconVar + " = CEikonEnv::Static()->CreateIconL(\n\t\t{0}, {1} );\n"
cawthron
parents:
diff changeset
   775
						+ saveAddAndRestore;
cawthron
parents:
diff changeset
   776
				}
cawthron
parents:
diff changeset
   777
			}			
cawthron
parents:
diff changeset
   778
			contrib = Engine.createContributionForLocation(location);
cawthron
parents:
diff changeset
   779
			contrib.setFormattedText(format, parts);
cawthron
parents:
diff changeset
   780
			contribs.add(contrib);
cawthron
parents:
diff changeset
   781
			
cawthron
parents:
diff changeset
   782
		} else {
cawthron
parents:
diff changeset
   783
			if (isScaling) {
cawthron
parents:
diff changeset
   784
				setupImageFromPropertyViaTuple(contribs, instance, null, location, 0,
cawthron
parents:
diff changeset
   785
					property,
cawthron
parents:
diff changeset
   786
					iconVar + " = LoadAndScaleIconL(\n\t\t{0}, {1}, -1,\n\t\tNULL, EAspectRatioPreserved );\n"
cawthron
parents:
diff changeset
   787
						+ saveAddAndRestore,
cawthron
parents:
diff changeset
   788
					iconVar + " = LoadAndScaleIconL(\n\t\t{0}, {1}, {2},\n\t\tNULL, EAspectRatioPreserved );\n"
cawthron
parents:
diff changeset
   789
						+ saveAddAndRestore
cawthron
parents:
diff changeset
   790
				);
cawthron
parents:
diff changeset
   791
			} else {
cawthron
parents:
diff changeset
   792
				setupImageFromPropertyViaTuple(contribs, instance, null, location, 0,
cawthron
parents:
diff changeset
   793
					property, 
cawthron
parents:
diff changeset
   794
					iconVar + " = CEikonEnv::Static()->CreateIconL(\n\t\t{0}, {1} );\n"
cawthron
parents:
diff changeset
   795
						+ saveAddAndRestore,
cawthron
parents:
diff changeset
   796
					iconVar + " = CEikonEnv::Static()->CreateIconL(\n\t\t{0}, {1}, {2} );\n"
cawthron
parents:
diff changeset
   797
						+ saveAddAndRestore);
cawthron
parents:
diff changeset
   798
			}
cawthron
parents:
diff changeset
   799
		}
cawthron
parents:
diff changeset
   800
	}
cawthron
parents:
diff changeset
   801
		
cawthron
parents:
diff changeset
   802
	if (anyIcons) {
cawthron
parents:
diff changeset
   803
		return true;
cawthron
parents:
diff changeset
   804
	}
cawthron
parents:
diff changeset
   805
	else
cawthron
parents:
diff changeset
   806
		return false;
cawthron
parents:
diff changeset
   807
}
cawthron
parents:
diff changeset
   808
cawthron
parents:
diff changeset
   809
/**
cawthron
parents:
diff changeset
   810
 *	Generate text to be substituted into an enum{} declaration.
cawthron
parents:
diff changeset
   811
 */
cawthron
parents:
diff changeset
   812
ImageList.prototype.generateImageListEnums = function() {
cawthron
parents:
diff changeset
   813
	var text = "";
cawthron
parents:
diff changeset
   814
	for (var iter = this.imageMap.entrySet().iterator(); iter.hasNext(); ) {
cawthron
parents:
diff changeset
   815
		var entry = iter.next();
cawthron
parents:
diff changeset
   816
		var index = entry.getValue()[IL_INDEX_INDEX];
cawthron
parents:
diff changeset
   817
		var enm = entry.getValue()[IL_ENUM_INDEX];
cawthron
parents:
diff changeset
   818
		text += enm + " = " + index + ",\n";
cawthron
parents:
diff changeset
   819
	}
cawthron
parents:
diff changeset
   820
	text += "E" + titleCase(this.ownerInstance.name) + "FirstUserImageIndex\n";
cawthron
parents:
diff changeset
   821
	return text;
cawthron
parents:
diff changeset
   822
}
cawthron
parents:
diff changeset
   823
cawthron
parents:
diff changeset
   824
ImageList.prototype.dump = function() {
cawthron
parents:
diff changeset
   825
	println("dump of image list: ");
cawthron
parents:
diff changeset
   826
	for (var iter = this.imageMap.entrySet().iterator(); iter.hasNext(); ) {
cawthron
parents:
diff changeset
   827
		var entry = iter.next();
cawthron
parents:
diff changeset
   828
		var key = entry.getKey();
cawthron
parents:
diff changeset
   829
		var value = entry.getValue();
cawthron
parents:
diff changeset
   830
		var property = value[IL_PROPERTY_INDEX];
cawthron
parents:
diff changeset
   831
		var index = value[IL_INDEX_INDEX];
cawthron
parents:
diff changeset
   832
cawthron
parents:
diff changeset
   833
		println("key="+key+", property="+property+", index="+index);
cawthron
parents:
diff changeset
   834
	}
cawthron
parents:
diff changeset
   835
}