uidesigner/com.nokia.sdt.series60.componentlibrary/components/transient/StylusPopup.js
changeset 2 d760517a8095
equal deleted inserted replaced
-1:000000000000 2:d760517a8095
       
     1 /*
       
     2 * Copyright (c) 2007 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 include("../containers/containerLibrary.js")
       
    20 include("../renderLibrary.js")
       
    21 include("StylusPopupItem.js")
       
    22 
       
    23 function CAknStylusPopUpMenu() {
       
    24 	this.lafInfo = null;
       
    25 
       
    26 	// the bounds of the dialog, rel. to instance
       
    27 	this.dialogBounds = null;	
       
    28 	// the bounds of the prompt part, rel. to dialogBounds
       
    29 	this.promptBounds = null;
       
    30 	// the bounds of the list box part, rel. to dialogBounds
       
    31 	this.listBounds = null;
       
    32 }
       
    33 
       
    34 
       
    35 ///////////////////////////////////
       
    36 // IQueryContainment
       
    37 ///////////////////////////////////
       
    38 function canContainComponent(instance, component) {
       
    39 	if (isStylusPopupItemComponent(component))
       
    40 		return null;
       
    41 	
       
    42 	return buildSimpleContainmentErrorStatus(
       
    43 			lookupString("stylusPopupItemContainmentErr"), new Array( component.friendlyName ));			
       
    44 }
       
    45 
       
    46 CAknStylusPopUpMenu.prototype.canContainComponent = function(instance, otherComponent) {
       
    47 	if (instance.children.length >= 4){
       
    48 		return buildSimpleContainmentErrorStatus(
       
    49 			lookupString("maxStylusPopupItemContainmentErr"), new Array( otherComponent.friendlyName ));			
       
    50 	}
       
    51 	return canContainComponent(instance, otherComponent);
       
    52 }
       
    53 
       
    54 CAknStylusPopUpMenu.prototype.canContainChild = function(instance, child) {
       
    55 	return canContainComponent(instance, child.component);
       
    56 }
       
    57 
       
    58 CAknStylusPopUpMenu.prototype.canRemoveChild = function(instance) {
       
    59 	return true;
       
    60 }
       
    61 
       
    62 CAknStylusPopUpMenu.prototype.isValidComponentInPalette = function(instance, otherComponent) {
       
    63 	return canContainComponent(instance, otherComponent) == null;
       
    64 }
       
    65 
       
    66 function isStylusPopupItemComponent(component) {
       
    67 	return component.id == "com.nokia.sdt.series60.StylusPopupItem";
       
    68 }
       
    69 
       
    70 ///////////////////////////////////
       
    71 // IVisualAppearance
       
    72 ///////////////////////////////////
       
    73 CAknStylusPopUpMenu.prototype.draw = function(instance, laf, graphics) {
       
    74 	
       
    75 	var width = instance.properties.size.width - 3;
       
    76 	var height = instance.properties.size.height - 3;
       
    77 	var x = 0;
       
    78 	var y = 0;
       
    79 	
       
    80 	// fill 
       
    81 	graphics.setBackground(getBackgroundColor(instance, laf))
       
    82 	graphics.fillRectangle(new Rectangle(0, 0, width, height))
       
    83 	
       
    84 	// edge
       
    85 	graphics.setForeground(Colors.getColor(0, 0, 0))
       
    86 	graphics.drawRectangle(new Rectangle(0, 0, width, height))
       
    87 	
       
    88 	// shadows
       
    89 	graphics.setForeground(laf.getColor("control.shadow.inner"))
       
    90 	graphics.drawLine(x + 1, y + height + 1, x + width + 1, y + height + 1)
       
    91 	graphics.drawLine(x + width + 1, y + 1, x + width + 1, y + height + 1)
       
    92 	
       
    93 	graphics.setForeground(laf.getColor("control.shadow.outer"))
       
    94 	graphics.drawLine(x + 2, y + height + 2, x + width + 2, y + height + 2)
       
    95 	graphics.drawLine(x + width + 2, y + 2, x + width + 2, y + height + 2)
       
    96 
       
    97 	graphics.setForeground(laf.getColor("EEikColorDialogText"));
       
    98 	
       
    99 	if (instance.children.length == 0) {
       
   100 			drawTextItem(" No data ", new Point(0, 0), new Point(width + 5, height + 2), laf, graphics);
       
   101 	}
       
   102 }
       
   103 
       
   104 
       
   105 CAknStylusPopUpMenu.prototype.getPreferredSize = function(instance, laf, wHint, hHint) {
       
   106 	return null;
       
   107 }
       
   108 
       
   109 ///////////////////////////////////
       
   110 // IDirectLableEdit
       
   111 ///////////////////////////////////
       
   112 
       
   113 
       
   114 ///////////////////////////////////
       
   115 // ILayout
       
   116 ///////////////////////////////////
       
   117 CAknStylusPopUpMenu.prototype.layout = function(instance, laf) {
       
   118 	
       
   119 	//Get the rectangle for the screen, we'll put the popup menu in the middle
       
   120 	var d = laf.getDimension("screen.size");
       
   121 	var textPadding = 10;
       
   122 	var numChildren = instance.children.length;
       
   123 	if (numChildren == 0){
       
   124 		numChildren = 1; // Leave space for text to indicate no menu items present
       
   125 	}
       
   126 	
       
   127 	var font = laf.getFont("menuitem.font");
       
   128 	var extent = font.stringExtent("  No data  ");  // get default widest text length
       
   129 	var menuWidth = extent.x + textPadding;
       
   130 	var fontHeight = font.getHeight() + 8;
       
   131 	
       
   132 	for (var i in instance.children) {
       
   133 	    // figure out the max width of the text item...
       
   134 		var child = instance.children[i];
       
   135 		var childProperties = child.properties;
       
   136 		if (menuWidth < font.stringExtent(child.properties.textItem).x) {
       
   137 		    if (font.stringExtent(child.properties.textItem).x > d.x / 2) {
       
   138 		       // NOTE: I'm not sure about the termination. The popup menu doesn't seem to work
       
   139 		       // on the emulator on all the resolutions so far, so proper elipsis length is unknown.
       
   140 		       // However, currently it seems to be 1/2 of screen size.
       
   141 		    	menuWidth = d.x /2 + 10; // menu width can only be 1/2 of screen width
       
   142 		    } else {
       
   143 				menuWidth = font.stringExtent(child.properties.textItem).x + textPadding;
       
   144 			}
       
   145 		}	
       
   146 	}
       
   147 	
       
   148 	var menuLayoutHeight = fontHeight * numChildren + numChildren * 2;
       
   149 	
       
   150 	var contentRect = laf.getRectangle("content.pane.bounds");
       
   151 	var menuRect = new Rectangle(contentRect.x, contentRect.y, contentRect.width, contentRect.height);
       
   152 	menuRect.width = menuWidth + 10;
       
   153 	menuRect.height = menuLayoutHeight + 4;
       
   154 	menuRect.x = d.x / 2 - (menuRect.width / 2) + 2;
       
   155 	menuRect.y = (d.y / 2) - (menuLayoutHeight / 2) + 2;
       
   156 	
       
   157 	setBounds(instance, menuRect); // Sets the bounds of the menu itself
       
   158 	
       
   159 	var properties = instance.properties;
       
   160 	defaultX=6;
       
   161 	defaultY=2;
       
   162 	// set the layout bounds for each menu item child 
       
   163 	for (var i in instance.children) {
       
   164 		var child = instance.children[i];
       
   165 		var childProperties = child.properties;
       
   166 		// Set the offsets so that the text item shows with it's bounds inside the menu rectangle borders
       
   167 		setBounds(child, new Rectangle(defaultX, defaultY, menuWidth-4, fontHeight-2));
       
   168 		defaultY = defaultY + fontHeight + 2;
       
   169 	}
       
   170 		
       
   171 }
       
   172 
       
   173