uidesigner/com.nokia.sdt.series60.componentlibrary/components/containers/CCoeControl.js
author dan.podwall@nokia.com
Mon, 06 Apr 2009 14:00:50 -0500
changeset 50 9107fae37cee
parent 2 d760517a8095
permissions -rw-r--r--
merge on RCL_2_0
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
include("containerLibrary.js")
cawthron
parents:
diff changeset
    21
cawthron
parents:
diff changeset
    22
function CCoeControlLayout() {
cawthron
parents:
diff changeset
    23
}
cawthron
parents:
diff changeset
    24
cawthron
parents:
diff changeset
    25
CCoeControlLayout.prototype.layout = function(instance, laf) {
cawthron
parents:
diff changeset
    26
	var thisWidth = instance.properties.size.width;
cawthron
parents:
diff changeset
    27
	var thisHeight = instance.properties.size.height;
cawthron
parents:
diff changeset
    28
		
cawthron
parents:
diff changeset
    29
	var exclusiveChild = getExclusiveChild(instance.children);
cawthron
parents:
diff changeset
    30
	if (exclusiveChild != null) {
cawthron
parents:
diff changeset
    31
		setBounds(exclusiveChild, new Rectangle(0, 0, thisWidth, thisHeight));
cawthron
parents:
diff changeset
    32
	}
cawthron
parents:
diff changeset
    33
}
cawthron
parents:
diff changeset
    34
cawthron
parents:
diff changeset
    35
CCoeControlLayout.prototype.getPreferredSize = function(instance, laf, wHint, hHint) {
cawthron
parents:
diff changeset
    36
	return null;
cawthron
parents:
diff changeset
    37
}
cawthron
parents:
diff changeset
    38
cawthron
parents:
diff changeset
    39
function getExclusiveChild(children) {
cawthron
parents:
diff changeset
    40
	var result = null;
cawthron
parents:
diff changeset
    41
	for (var i = 0; i < children.length; i++) {
cawthron
parents:
diff changeset
    42
		var child = children[i];
cawthron
parents:
diff changeset
    43
		if (child.component != null && child.component.attributes["is-exclusive-child-layout-object"] == "true") {
cawthron
parents:
diff changeset
    44
			return children[i];
cawthron
parents:
diff changeset
    45
		}
cawthron
parents:
diff changeset
    46
	}
cawthron
parents:
diff changeset
    47
	return null;
cawthron
parents:
diff changeset
    48
}
cawthron
parents:
diff changeset
    49
cawthron
parents:
diff changeset
    50
///////////////////
cawthron
parents:
diff changeset
    51
cawthron
parents:
diff changeset
    52
cawthron
parents:
diff changeset
    53
cawthron
parents:
diff changeset
    54
function CCoeControlVisual() {
cawthron
parents:
diff changeset
    55
}
cawthron
parents:
diff changeset
    56
cawthron
parents:
diff changeset
    57
CCoeControlVisual.prototype.draw = function(instance, laf, graphics) {
cawthron
parents:
diff changeset
    58
	var properties = instance.properties;
cawthron
parents:
diff changeset
    59
	var color = colorFromString(laf, properties.backColor);
cawthron
parents:
diff changeset
    60
	if (color != null) {
cawthron
parents:
diff changeset
    61
		graphics.setBackground(color);
cawthron
parents:
diff changeset
    62
		graphics.fillRectangle(0, 0, properties.size.width, properties.size.height);
cawthron
parents:
diff changeset
    63
	}
cawthron
parents:
diff changeset
    64
	else {
cawthron
parents:
diff changeset
    65
		var properties = instance.properties;	
cawthron
parents:
diff changeset
    66
		var width = properties.size.width;
cawthron
parents:
diff changeset
    67
		var height = properties.size.height;
cawthron
parents:
diff changeset
    68
		graphics.setBackground(getBackgroundColor(instance, laf));
cawthron
parents:
diff changeset
    69
		graphics.fillRectangle(new Rectangle(0, 0, width, height));
cawthron
parents:
diff changeset
    70
	}
cawthron
parents:
diff changeset
    71
}
cawthron
parents:
diff changeset
    72
cawthron
parents:
diff changeset
    73
CCoeControlVisual.prototype.getPreferredSize = function(instance, laf, wHint, hHint) {
cawthron
parents:
diff changeset
    74
	return null; // not needed	
cawthron
parents:
diff changeset
    75
}
cawthron
parents:
diff changeset
    76
cawthron
parents:
diff changeset
    77
/////////////////////
cawthron
parents:
diff changeset
    78
cawthron
parents:
diff changeset
    79
function CCoeControlPropertyExtenders() {
cawthron
parents:
diff changeset
    80
}
cawthron
parents:
diff changeset
    81
cawthron
parents:
diff changeset
    82
	// Return instances that may provide extension properties
cawthron
parents:
diff changeset
    83
	// The target instance parameter is the instance to receive the
cawthron
parents:
diff changeset
    84
	// additional properties
cawthron
parents:
diff changeset
    85
CCoeControlPropertyExtenders.prototype.getPropertyExtenders = function(instance, targetInstance) {
cawthron
parents:
diff changeset
    86
	if (isAvkonView(targetInstance.parent) && !isPreviewPopUp(instance)) {
cawthron
parents:
diff changeset
    87
		return [instance];
cawthron
parents:
diff changeset
    88
	}
cawthron
parents:
diff changeset
    89
	
cawthron
parents:
diff changeset
    90
	return null;
cawthron
parents:
diff changeset
    91
}
cawthron
parents:
diff changeset
    92
	
cawthron
parents:
diff changeset
    93
CCoeControlPropertyExtenders.prototype.getExtensionSetNames = function(instance, targetInstance) {
cawthron
parents:
diff changeset
    94
	if (instance == targetInstance)
cawthron
parents:
diff changeset
    95
		return [ "default" ];
cawthron
parents:
diff changeset
    96
		
cawthron
parents:
diff changeset
    97
	return null;
cawthron
parents:
diff changeset
    98
}
cawthron
parents:
diff changeset
    99
cawthron
parents:
diff changeset
   100
/////////////////////
cawthron
parents:
diff changeset
   101
cawthron
parents:
diff changeset
   102
cawthron
parents:
diff changeset
   103
function CCoeControlQueryContainment() {
cawthron
parents:
diff changeset
   104
}
cawthron
parents:
diff changeset
   105
cawthron
parents:
diff changeset
   106
CCoeControlQueryContainment.prototype.getAllowedAttribute = function() {
cawthron
parents:
diff changeset
   107
	return "is-ccoecontrol-content";
cawthron
parents:
diff changeset
   108
}
cawthron
parents:
diff changeset
   109
cawthron
parents:
diff changeset
   110
setupAttributeBasedQueryContainment(CCoeControlQueryContainment.prototype);
cawthron
parents:
diff changeset
   111
cawthron
parents:
diff changeset
   112
/////////////////////////
cawthron
parents:
diff changeset
   113
cawthron
parents:
diff changeset
   114
function CCoeControlPropertyListener() {
cawthron
parents:
diff changeset
   115
}
cawthron
parents:
diff changeset
   116
cawthron
parents:
diff changeset
   117
CCoeControlPropertyListener.prototype.propertyChanged = function(instance, propertyId) {
cawthron
parents:
diff changeset
   118
	if (propertyId == "backColor") {
cawthron
parents:
diff changeset
   119
		// anything hosted on top may depend on the color
cawthron
parents:
diff changeset
   120
		for (var c in instance.children) {
cawthron
parents:
diff changeset
   121
			instance.children[c].forceRedraw();
cawthron
parents:
diff changeset
   122
		}
cawthron
parents:
diff changeset
   123
	}
cawthron
parents:
diff changeset
   124
}
cawthron
parents:
diff changeset
   125
cawthron
parents:
diff changeset
   126
/////////////////////////
cawthron
parents:
diff changeset
   127
cawthron
parents:
diff changeset
   128
function CCoeControlChildListener() {
cawthron
parents:
diff changeset
   129
}
cawthron
parents:
diff changeset
   130
cawthron
parents:
diff changeset
   131
CCoeControlChildListener.prototype.childAdded = function(instance, child, laf) {
cawthron
parents:
diff changeset
   132
	var properties = instance.properties;
cawthron
parents:
diff changeset
   133
	var childWantsFocus = hasAttributeValue(child.attributes, "wants-initial-focus", "true");
cawthron
parents:
diff changeset
   134
	var numFocusableChildren = 
cawthron
parents:
diff changeset
   135
		countImmediateChildrenWithAttributeValue(instance.children, "wants-initial-focus", "true");
cawthron
parents:
diff changeset
   136
		
cawthron
parents:
diff changeset
   137
	// if has no initial focus, but the child just added is the only one that wants it
cawthron
parents:
diff changeset
   138
	if ((properties.initialFocus == "") && childWantsFocus && (numFocusableChildren == 1))
cawthron
parents:
diff changeset
   139
		properties.initialFocus = child.name;
cawthron
parents:
diff changeset
   140
}
cawthron
parents:
diff changeset
   141
cawthron
parents:
diff changeset
   142
CCoeControlChildListener.prototype.childRemoved = function(instance, child, laf) {
cawthron
parents:
diff changeset
   143
	// nothing to do
cawthron
parents:
diff changeset
   144
}
cawthron
parents:
diff changeset
   145
cawthron
parents:
diff changeset
   146
CCoeControlChildListener.prototype.childrenReordered = function(instance, laf) {
cawthron
parents:
diff changeset
   147
	// nothing to do
cawthron
parents:
diff changeset
   148
}
cawthron
parents:
diff changeset
   149
cawthron
parents:
diff changeset
   150
//////////////////////////////////////////
cawthron
parents:
diff changeset
   151
// IComponentEventInfo
cawthron
parents:
diff changeset
   152
//////////////////////////////////////////
cawthron
parents:
diff changeset
   153
function CCoeControlEventInfo(){}
cawthron
parents:
diff changeset
   154
cawthron
parents:
diff changeset
   155
CCoeControlEventInfo.prototype.getEventGroups = function(instance) {
cawthron
parents:
diff changeset
   156
	// Get the proper events depending on the SDK.
cawthron
parents:
diff changeset
   157
	version = getComponentVersions();
cawthron
parents:
diff changeset
   158
	if (version.major >= 5) {
cawthron
parents:
diff changeset
   159
		// Add touch events
cawthron
parents:
diff changeset
   160
		return ["TouchUIEvent", "CustomCCoeControl", "CCoeControl"];
cawthron
parents:
diff changeset
   161
	}
cawthron
parents:
diff changeset
   162
	else {
cawthron
parents:
diff changeset
   163
		// sdks prior to touch
cawthron
parents:
diff changeset
   164
		return ["CustomCCoeControl", "CCoeControl"];
cawthron
parents:
diff changeset
   165
	}
cawthron
parents:
diff changeset
   166
}