uidesigner/com.nokia.sdt.series60.componentlibrary/components/transient/SingleLineDataQuery.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 include("../renderLibrary.js")
       
    20 include("../messageLibrary.js")
       
    21 include("../cba/cbaLibrary.js")
       
    22 include("../containers/containerLibrary.js")
       
    23 include("popupDialogLibrary.js")
       
    24 
       
    25 function SingleLineDataQueryVisual() {
       
    26 	setupPopupVisualHelper(SingleLineDataQueryVisual.prototype);
       
    27 }
       
    28 
       
    29 
       
    30 SingleLineDataQueryVisual.prototype.draw = function(instance, laf, graphics) {
       
    31 	var properties = instance.properties;
       
    32 
       
    33 	// first draw the CBA
       
    34 	var leftText = lookupString("Ok");
       
    35 	var rightText = lookupString("Cancel");
       
    36 	var middleText = "";
       
    37 	var r = laf.getRectangle("control.pane.bounds");
       
    38 	var rect = new Rectangle(r.x, r.y, r.width, r.height);
       
    39 	rect.x -= properties.location.x;
       
    40 	rect.y -= properties.location.y;
       
    41 	drawCBA(leftText, rightText, middleText, new Point(rect.x, rect.y), new Point(rect.width, rect.height), laf, graphics);
       
    42 
       
    43 	// then draw the query dialog
       
    44 	var flags = Font.ALIGN_LEFT | Font.WRAPPING_ENABLED;
       
    45 	var font = laf.getFont("message.font");
       
    46 	var textr = this.calculateTextBounds(properties, laf, "text", font, flags, 1, 3);
       
    47 	var editDims = laf.getRectangle("query.editor");
       
    48 	var editRect = new Rectangle(editDims.x, editDims.y, editDims.width, editDims.height);
       
    49 	var bounds = this.calculateDialogBounds(properties, laf, new Point(textr.width, textr.height), editRect);
       
    50 	//println("textr="+textr);
       
    51 	//println("bounds="+bounds);
       
    52 	var font = this.getLabelFont(instance, "text", laf);
       
    53 	this.drawPopupDialog(instance, laf, graphics, font, flags, textr, bounds);
       
    54 }
       
    55 
       
    56 SingleLineDataQueryVisual.prototype.getPreferredSize = function(instance, laf, wHint, hHint) {
       
    57 	return null;
       
    58 }
       
    59 
       
    60 // IDirectLabelEdit
       
    61 SingleLineDataQueryVisual.prototype.getPropertyPaths = function(instance) {
       
    62 	return new Array("text");
       
    63 }
       
    64 
       
    65 SingleLineDataQueryVisual.prototype.getLabelBounds = function(instance, propertyPath, laf) {
       
    66 	var properties = instance.properties;
       
    67 	var flags = Font.ALIGN_LEFT | Font.WRAPPING_ENABLED;
       
    68 	var font = laf.getFont("message.font");
       
    69 	rect = this.calculateTextBounds(properties, laf, "text", font, flags, 1, 3);
       
    70 	
       
    71 	return rect;
       
    72 }
       
    73 
       
    74 SingleLineDataQueryVisual.prototype.getLabelFont = function(instance, propertyPath, laf) {
       
    75 	return laf.getFont("message.font");
       
    76 }
       
    77 
       
    78 SingleLineDataQueryVisual.prototype.getIconRect = function() {
       
    79 	return new Rectangle(0,0,0,0);
       
    80 }
       
    81 
       
    82 SingleLineDataQueryVisual.prototype.layout = function(instance, laf) {
       
    83 	var properties = instance.properties;
       
    84 	var portrait = laf.getBoolean("is.portrait", true);
       
    85 
       
    86 	var flags = Font.ALIGN_LEFT | Font.WRAPPING_ENABLED;
       
    87 	var font = laf.getFont("message.font");
       
    88 	var textr = this.calculateTextBounds(properties, laf, "text", font, flags, 1, 3);
       
    89 	var editDims = laf.getRectangle("query.editor");
       
    90 	var editRect = new Rectangle(editDims.x, editDims.y, editDims.width, editDims.height);
       
    91 	editRect.y += textr.height;
       
    92 	var rect = this.calculateDialogBounds(properties, laf, new Point(textr.width, textr.height), editRect);
       
    93 	var d = laf.getDimension("screen.size");
       
    94 	var cbaR = laf.getRectangle("control.pane.bounds");
       
    95 	
       
    96 	// position dialog
       
    97 	if (portrait) {
       
    98 		rect.y = (d.y - cbaR.height) - rect.height - rect.y;
       
    99 	}
       
   100 	else {
       
   101 	
       
   102 	}
       
   103 	
       
   104 	// set our bounds
       
   105 	setBounds(instance, rect);
       
   106 
       
   107 	// set child bounds
       
   108 	var child = instance.children[0];
       
   109 	var bounds = new Rectangle(0,0,0,0);
       
   110 	if (child != null) {
       
   111 		if (portrait) {
       
   112 			bounds.x = rect.x + editRect.x;
       
   113 			bounds.y = editRect.y;
       
   114 		}
       
   115 		else {
       
   116 			bounds.x = editRect.x;
       
   117 			bounds.y = rect.y + editRect.y;
       
   118 		}
       
   119 		bounds.width = editRect.width;
       
   120 		bounds.height = editRect.height;
       
   121 		setBounds(child, bounds);
       
   122 	}
       
   123 }
       
   124 
       
   125 /////////////////////
       
   126 
       
   127 
       
   128 function SingleLineDataQueryContainment() {
       
   129 }
       
   130 
       
   131 function hasChild(instance) {
       
   132 	return (instance.children != null) && (instance.children.length > 0);
       
   133 }
       
   134 
       
   135 SingleLineDataQueryContainment.prototype.canContainComponent = function(instance, otherComponent) {
       
   136 	if (hasChild(instance)) {
       
   137 		return buildSimpleContainmentErrorStatus(
       
   138 			lookupString("singleChildContainmentError"), null);
       
   139 	}
       
   140 	
       
   141 	return null;
       
   142 }
       
   143  
       
   144 SingleLineDataQueryContainment.prototype.canContainChild = function(instance, child) {
       
   145 	if (hasChild(instance)) {
       
   146 		return buildSimpleContainmentErrorStatus(
       
   147 			lookupString("singleChildContainmentError"), null);
       
   148 	}
       
   149 	
       
   150 	return null;
       
   151 }
       
   152  
       
   153 SingleLineDataQueryContainment.prototype.canRemoveChild = function(instance, child) {
       
   154 	return false;
       
   155 }
       
   156  
       
   157 SingleLineDataQueryContainment.prototype.isValidComponentInPalette = function(instance, otherComponent) {
       
   158 	return true;
       
   159 }
       
   160 
       
   161 SingleLineDataQueryContainment.prototype.getAllowedAttribute = function() {
       
   162 	return "is-dataquery-content";
       
   163 }
       
   164 
       
   165 setupAttributeBasedQueryContainment(SingleLineDataQueryContainment.prototype);
       
   166 
       
   167 SingleLineDataQueryContainment.prototype.propertyChanged = function(instance, property) {
       
   168 	if (property == "text") {
       
   169 		instance.forceLayout();
       
   170 	}
       
   171 }
       
   172 
       
   173