uidesigner/com.nokia.sdt.series60.componentlibrary/components/toolbar/toolbar_utils.js
author fturovic <frank.turovich@nokia.com>
Fri, 03 Apr 2009 10:36:00 -0500
changeset 36 131ddbe8aee4
parent 2 d760517a8095
permissions -rw-r--r--
added IAD rules to CS manual
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
// Get the width and height of the toolbar in a Point.
cawthron
parents:
diff changeset
    20
// instance - the toolbar instance to get the width and height of
cawthron
parents:
diff changeset
    21
// laf - local laf
cawthron
parents:
diff changeset
    22
function getToolBarSize(instance, laf){
cawthron
parents:
diff changeset
    23
	
cawthron
parents:
diff changeset
    24
	props = instance.properties;
cawthron
parents:
diff changeset
    25
	var isSmallBar =   props.smallToolbar == true ? true : false;
cawthron
parents:
diff changeset
    26
	var toolBarMarginPadding = laf.getInteger("control.toolbar.margin", 0);
cawthron
parents:
diff changeset
    27
	var toolBarWidth = laf.getInteger("control.toolbar.height", 0);
cawthron
parents:
diff changeset
    28
	var toolBarHeight = toolBarWidth;
cawthron
parents:
diff changeset
    29
	var isHorizontal = props.orientation == "Horizontal" ? true : false;
cawthron
parents:
diff changeset
    30
	
cawthron
parents:
diff changeset
    31
	if (isSmallBar){
cawthron
parents:
diff changeset
    32
		toolBarMarginPadding = 0;
cawthron
parents:
diff changeset
    33
		toolBarHeight /= 2;
cawthron
parents:
diff changeset
    34
		toolBarWidth /= 2;
cawthron
parents:
diff changeset
    35
	}
cawthron
parents:
diff changeset
    36
	
cawthron
parents:
diff changeset
    37
	var numChillens = instance.children.length;
cawthron
parents:
diff changeset
    38
	var childWidth = 0;
cawthron
parents:
diff changeset
    39
	
cawthron
parents:
diff changeset
    40
	if (isHorizontal) {
cawthron
parents:
diff changeset
    41
		var lastChildWasNull = false;  // for some reason the width is zero after dragging an item in from the main pane
cawthron
parents:
diff changeset
    42
		for (var i in instance.children) {
cawthron
parents:
diff changeset
    43
			var child = instance.children[i];
cawthron
parents:
diff changeset
    44
			var childProperties = child.properties;
cawthron
parents:
diff changeset
    45
			childWidth += childProperties.size.width;
cawthron
parents:
diff changeset
    46
			if (lastChildWasNull == true) {
cawthron
parents:
diff changeset
    47
				lastChildWasNull = false;
cawthron
parents:
diff changeset
    48
				childWidth += childWidth;
cawthron
parents:
diff changeset
    49
			}
cawthron
parents:
diff changeset
    50
			if (childProperties.size.width == 0) {
cawthron
parents:
diff changeset
    51
				lastChildWasNull = true;
cawthron
parents:
diff changeset
    52
			}
cawthron
parents:
diff changeset
    53
		}
cawthron
parents:
diff changeset
    54
		
cawthron
parents:
diff changeset
    55
		childWidth += toolBarMarginPadding * (numChillens + 1);
cawthron
parents:
diff changeset
    56
		
cawthron
parents:
diff changeset
    57
		if (numChillens == 0) {
cawthron
parents:
diff changeset
    58
			// no items, set to default width
cawthron
parents:
diff changeset
    59
			childWidth = laf.getInteger("control.toolbar.height", 0);
cawthron
parents:
diff changeset
    60
		}
cawthron
parents:
diff changeset
    61
		
cawthron
parents:
diff changeset
    62
	} else {
cawthron
parents:
diff changeset
    63
		var lastChildWasNull = false;  // for some reason the height is zero after dragging an item in from the main pane
cawthron
parents:
diff changeset
    64
		childWidth = toolBarHeight;
cawthron
parents:
diff changeset
    65
		toolBarHeight = 0;
cawthron
parents:
diff changeset
    66
		for (var i in instance.children) {
cawthron
parents:
diff changeset
    67
			var child = instance.children[i];
cawthron
parents:
diff changeset
    68
			var childProperties = child.properties;
cawthron
parents:
diff changeset
    69
			toolBarHeight += childProperties.size.height;
cawthron
parents:
diff changeset
    70
			if (lastChildWasNull == true) {
cawthron
parents:
diff changeset
    71
				lastChildWasNull = false;
cawthron
parents:
diff changeset
    72
				toolBarHeight += toolBarHeight;
cawthron
parents:
diff changeset
    73
			}
cawthron
parents:
diff changeset
    74
			if (childProperties.size.height == 0) {
cawthron
parents:
diff changeset
    75
				lastChildWasNull = true;
cawthron
parents:
diff changeset
    76
			}
cawthron
parents:
diff changeset
    77
		}
cawthron
parents:
diff changeset
    78
		// Get default height of items
cawthron
parents:
diff changeset
    79
		
cawthron
parents:
diff changeset
    80
		toolBarHeight += toolBarMarginPadding * (numChillens + 1)
cawthron
parents:
diff changeset
    81
		
cawthron
parents:
diff changeset
    82
		if (numChillens == 0) {
cawthron
parents:
diff changeset
    83
			// no items, set to default width
cawthron
parents:
diff changeset
    84
			toolBarHeight = laf.getInteger("control.toolbar.height", 0);
cawthron
parents:
diff changeset
    85
		}
cawthron
parents:
diff changeset
    86
	}
cawthron
parents:
diff changeset
    87
	
cawthron
parents:
diff changeset
    88
	return new Point(childWidth, toolBarHeight);
cawthron
parents:
diff changeset
    89
}
cawthron
parents:
diff changeset
    90