uidesigner/com.nokia.sdt.series60.componentlibrary/components/statuspane/titleLibrary.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 
       
    20 function drawTitleText(instance, laf, graphics, titleText) {
       
    21 	var properties = instance.properties;
       
    22 
       
    23 	var textColor = laf.getColor("status.title.color");
       
    24    if (textColor != null)
       
    25         graphics.setForeground(textColor);
       
    26 	var titleBounds = new Rectangle(0, 0, properties.size.width, properties.size.height)
       
    27 		
       
    28 	if (laf.getBoolean("is.portrait", true)) {
       
    29         var bgColor = laf.getColor("screen.background");
       
    30         if (bgColor != null)
       
    31             graphics.setBackground(bgColor);
       
    32 
       
    33 		var font = laf.getFont("status.TitleFont");
       
    34 		titleText = chooseScalableText(titleText, font, titleBounds.width);
       
    35 	
       
    36 		var oneLineExtent = font.stringExtent(titleText);
       
    37 		if (oneLineExtent.x <= titleBounds.width) {
       
    38 			graphics.setFont(font);
       
    39             titleBounds.y += (titleBounds.height - oneLineExtent.y) / 2;
       
    40 			graphics.drawFormattedString(titleText, titleBounds, 
       
    41 					Font.OVERFLOW_IGNORE|Font.DRAW_TRANSPARENT);
       
    42 		}
       
    43 		else {
       
    44 			font = laf.getFont("HalfTitleFont");
       
    45 			oneLineExtent = font.stringExtent(titleText);
       
    46 			graphics.setFont(font);
       
    47 			graphics.drawFormattedString(titleText, titleBounds, 
       
    48 					Font.OVERFLOW_IGNORE|Font.DRAW_TRANSPARENT|Font.WRAPPING_ENABLED);
       
    49 		}
       
    50 	}
       
    51 	else { // landscape, title is always one line
       
    52         var bgColor = laf.getColor("status.bar.color");
       
    53         if (bgColor != null)
       
    54             graphics.setBackground(bgColor);
       
    55 
       
    56         var font = laf.getFont("status.TitleFont");
       
    57         titleText = chooseScalableText(titleText, font, titleBounds.width);
       
    58         	
       
    59 		var oneLineExtent = font.stringExtent(titleText);
       
    60 		graphics.setFont(font);
       
    61         var y = (titleBounds.height - oneLineExtent.y) / 2;
       
    62 		graphics.drawFormattedString(titleText, 
       
    63 				new Rectangle(0, y, titleBounds.width, titleBounds.height), 
       
    64 				Font.OVERFLOW_ELLIPSIS|Font.DRAW_TRANSPARENT);
       
    65 	}
       
    66 
       
    67 }