uidesigner/com.nokia.sdt.symbian.tests/data/images/components/testImplLibrary.js
changeset 0 fb279309251b
equal deleted inserted replaced
-1:000000000000 0:fb279309251b
       
     1 /*
       
     2 * Copyright (c) 2009 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 // This file has routines which initialize component implementations
       
    18 // according to patterns.
       
    19 
       
    20 include ("testMessageLibrary.js")
       
    21 
       
    22 strings = getLocalizedStrings("testImplLibrary");
       
    23 
       
    24 //	Set up direct label editing implementation for a component with
       
    25 //	one editable label
       
    26 //	@param prototype the impl prototype to update
       
    27 //	@param property the name of the edited property
       
    28 //	@param areafunction a function, taking an instance and laf, which returns the
       
    29 //		editable area of the label (or null).  If null, the default behavior is
       
    30 //		to use the entire rendered area.
       
    31 //	@param fontfunction a function, taking an instance and laf, which returns the
       
    32 //		IFont to edit with (or null).  If null, the default behavior is to return
       
    33 //		null, indicating a default system font.
       
    34 function setupCommonDirectLabelEditing(prototype, property, areafunction, fontfunction) {
       
    35 
       
    36 	prototype.getPropertyPaths = function(instance) {
       
    37 		return [ property ];
       
    38 	}
       
    39 
       
    40 	prototype.getLabelBounds = function(instance, propertyPath, laf) {
       
    41 		if (areafunction)
       
    42 			return areafunction(instance, laf);
       
    43 		var size = instance.properties.size;
       
    44 	    return new Rectangle(0, 0, size.width, size.height);
       
    45 	}
       
    46 
       
    47 	prototype.getLabelFont = function(instance, propertyPath, laf) {
       
    48 		if (fontfunction)
       
    49 			return fontfunction(instance, laf)
       
    50 		return null;
       
    51 	}
       
    52 }
       
    53 
       
    54 //	Set up direct image editing implementation for a component
       
    55 //	with one image property.  This sets up a standard validation
       
    56 //	check (images must be BMP or SVG if scalable UI enabled), and
       
    57 //	warns about scaled images if the image is a bitmap and its size 
       
    58 //	doesn't match the rendered area.
       
    59 //	<p>
       
    60 //	The validation logic is added to the prototype as "commonValidateImage" --
       
    61 //	you may override this behavior in your "validateImage" call.
       
    62 //
       
    63 //	@param prototype the impl prototype to update
       
    64 //	@param property the name of the edited property
       
    65 //	@param areafunction a function, taking an instance and laf, or null.
       
    66 //		If not null, the function which returns a rectangle for the clickable area 
       
    67 //		of the rendered area to respond to as well as the preferred size of the image.
       
    68 //		If null, the default behavior is to use the entire rendered area.
       
    69 function setupCommonDirectImageEditing(prototype, property, areafunction) {
       
    70 
       
    71 	prototype.getImagePropertyPaths = function(instance) {
       
    72 		return [ property ];
       
    73 	}
       
    74 
       
    75 	prototype.getImageBounds = function(instance, propertyPath, laf) {
       
    76 		println( "image: " + instance.properties[propertyPath].bmpfile + "/" 
       
    77 				+instance.properties[propertyPath].bmpid + "/" 
       
    78 				+instance.properties[propertyPath].bmpmask );
       
    79 				
       
    80 		if (areafunction) 
       
    81 			return areafunction(instance, laf);
       
    82 		var size = instance.properties.size;
       
    83 	    return new Rectangle(0, 0, size.width, size.height);
       
    84 	}
       
    85 
       
    86 	function isBMPFile(file) {
       
    87 		var lower = file.toLowerCase();
       
    88 		return lower.endsWith(".bmp");
       
    89 	}
       
    90 
       
    91 	function isSVGFile(file) {
       
    92 		var lower = file.toLowerCase();
       
    93 		println ("SVG check: lower="+lower);
       
    94 		return lower.endsWith(".svg") || lower.endsWith(".svgt");
       
    95 	}
       
    96 
       
    97 	prototype.commonValidateImage = function(instance, propertyId, laf, file, size) {
       
    98 	
       
    99 		var bounds = this.getImageBounds(instance, propertyId.substring(propertyId.lastIndexOf('.')+1), laf)
       
   100 		
       
   101 		//println("validating " + file + " @" + size +" for " + propertyId + " in " + bounds);
       
   102 	
       
   103 		var lower = file.toLowerCase();
       
   104 		if (!isBMPFile(file) && !isSVGFile(file)) {
       
   105 			return buildSimpleErrorStatus(
       
   106 				strings.getString("imageTypeOnlyBmpOrSvgError"), [ file ]);
       
   107 		}
       
   108 	
       
   109 	 	// unknown size --> ignore
       
   110 		if (size == null)
       
   111 			return null;
       
   112 		
       
   113 		if (!isSVGFile(file)) {
       
   114 			if (size.x != bounds.width || size.y != bounds.height)
       
   115 				return buildSimpleWarningStatus(
       
   116 					strings.getString("scaledOrCroppedImageSizeMsg"), 
       
   117 					new Array( bounds.width, bounds.height ));
       
   118 		}
       
   119 		
       
   120 		return null;
       
   121 	}
       
   122 
       
   123 	prototype.validateImage = prototype.commonValidateImage;
       
   124 }