idlehomescreen/xmluirendering/uiengine/src/xnutils.cpp
changeset 0 f72a12da539e
equal deleted inserted replaced
-1:000000000000 0:f72a12da539e
       
     1 /*
       
     2 * Copyright (c) 2008 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 "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:  Utility functions of Xuikon.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // System includes
       
    20 #include <AknUtils.h>
       
    21 #include <AknFontAccess.h>
       
    22 #include <uri16.h>
       
    23 
       
    24 // User includes
       
    25 #include "c_xnutils.h"
       
    26 #include "xnproperty.h"
       
    27 #include "xnnodepluginif.h"
       
    28 #include "xnuienginepluginif.h"
       
    29 #include "xndomlist.h"
       
    30 #include "xnresource.h"
       
    31 #include "xnnodebreadthfirstiterator.h"
       
    32 #include "xncontroladapter.h"
       
    33 #include "xncontroladapterimpl.h"
       
    34 #include "xncomponent.h"
       
    35 #include "xncomponentnodeimpl.h"
       
    36 
       
    37 // Constants
       
    38 _LIT( KNormal, "normal" );
       
    39 _LIT( KPrimaryFont , "EAknLogicalFontPrimaryFont" );
       
    40 _LIT( KSecondaryFont , "EAknLogicalFontSecondaryFont" );
       
    41 _LIT( KTitleFont, "EAknLogicalFontTitleFont" );
       
    42 _LIT( KPrimarySmallFont , "EAknLogicalFontPrimarySmallFont" );
       
    43 _LIT( KDigitalFont , "EAknLogicalFontDigitalFont" );
       
    44 
       
    45 _LIT( KXnCommonWhiteSpaceCharacters, " \n\t\r" );
       
    46 _LIT( KXnLineFeedTabCharacters, "\n\t\r" );
       
    47 _LIT( KXnTabCharacters, "\t\r" );
       
    48 
       
    49 _LIT( KSkin, "skin(" );
       
    50  
       
    51 namespace XnColorNames
       
    52     {
       
    53     _LIT8( Kaliceblue, "aliceblue" );
       
    54     _LIT8( Kantiquewhite, "antiquewhite" );
       
    55     _LIT8( Kaqua, "aqua" );
       
    56     _LIT8( Kaquamarine, "aquamarine" );
       
    57     _LIT8( Kazure, "azure" );
       
    58     _LIT8( Kbeige, "beige" );
       
    59     _LIT8( Kbisque, "bisque" );
       
    60     _LIT8( Kblack, "black" );
       
    61     _LIT8( Kblanchedalmond, "blanchedalmond" );
       
    62     _LIT8( Kblue, "blue" );
       
    63     _LIT8( Kblueviolet, "blueviolet" );
       
    64     _LIT8( Kbrown, "brown" );
       
    65     _LIT8( Kburlywood, "burlywood" );
       
    66     _LIT8( Kcadetblue, "cadetblue" );
       
    67     _LIT8( Kchartreuse, "chartreuse" );
       
    68     _LIT8( Kchocolate, "chocolate" );
       
    69     _LIT8( Kcoral, "coral" );
       
    70     _LIT8( Kcornflowerblue, "cornflowerblue" );
       
    71     _LIT8( Kcornsilk, "cornsilk" );
       
    72     _LIT8( Kcrimson, "crimson" );
       
    73     _LIT8( Kcyan, "cyan" );
       
    74     _LIT8( Kdarkblue, "darkblue" );
       
    75     _LIT8( Kdarkcyan, "darkcyan" );
       
    76     _LIT8( Kdarkgoldenrod, "darkgoldenrod" );
       
    77     _LIT8( Kdarkgray, "darkgray" );
       
    78     _LIT8( Kdarkgreen, "darkgreen" );
       
    79     _LIT8( Kdarkgrey, "darkgrey" );
       
    80     _LIT8( Kdarkkhaki, "darkkhaki" );
       
    81     _LIT8( Kdarkmagenta, "darkmagenta" );
       
    82     _LIT8( Kdarkolivegreen, "darkolivegreen" );
       
    83     _LIT8( Kdarkorange, "darkorange" );
       
    84     _LIT8( Kdarkorchid, "darkorchid" );
       
    85     _LIT8( Kdarkred, "darkred" );
       
    86     _LIT8( Kdarksalmon, "darksalmon" );
       
    87     _LIT8( Kdarkseagreen, "darkseagreen" );
       
    88     _LIT8( Kdarkslateblue, "darkslateblue" );
       
    89     _LIT8( Kdarkslategray, "darkslategray" );
       
    90     _LIT8( Kdarkslategrey, "darkslategrey" );
       
    91     _LIT8( Kdarkturquoise, "darkturquoise" );
       
    92     _LIT8( Kdarkviolet, "darkviolet" );
       
    93     _LIT8( Kdeeppink, "deeppink" );
       
    94     _LIT8( Kdeepskyblue, "deepskyblue" );
       
    95     _LIT8( Kdimgray, "dimgray" );
       
    96     _LIT8( Kdimgrey, "dimgrey" );
       
    97     _LIT8( Kdodgerblue, "dodgerblue" );
       
    98     _LIT8( Kfirebrick, "firebrick" );
       
    99     _LIT8( Kfloralwhite, "floralwhite" );
       
   100     _LIT8( Kforestgreen, "forestgreen" );
       
   101     _LIT8( Kfuchsia, "fuchsia" );
       
   102     _LIT8( Kgainsboro, "gainsboro" );
       
   103     _LIT8( Kghostwhite, "ghostwhite" );
       
   104     _LIT8( Kgold, "gold" );
       
   105     _LIT8( Kgoldenrod, "goldenrod" );
       
   106     _LIT8( Kgray, "gray" );
       
   107     _LIT8( Kgreen, "green" );
       
   108     _LIT8( Kgreenyellow, "greenyellow" );
       
   109     _LIT8( Kgrey, "grey" );
       
   110     _LIT8( Khoneydew, "honeydew" );
       
   111     _LIT8( Khotpink, "hotpink" );
       
   112     _LIT8( Kindianred, "indianred" );
       
   113     _LIT8( Kindigo, "indigo" );
       
   114     _LIT8( Kivory, "ivory" );
       
   115     _LIT8( Kkhaki, "khaki" );
       
   116     _LIT8( Klavender, "lavender" );
       
   117     _LIT8( Klavenderblush, "lavenderblush" );
       
   118     _LIT8( Klawngreen, "lawngreen" );
       
   119     _LIT8( Klemonchiffon, "lemonchiffon" );
       
   120     _LIT8( Klightblue, "lightblue" );
       
   121     _LIT8( Klightcoral, "lightcoral" );
       
   122     _LIT8( Klightcyan, "lightcyan" );
       
   123     _LIT8( Klightgoldenrodyellow, "lightgoldenrodyellow" );
       
   124     _LIT8( Klightgray, "lightgray" );
       
   125     _LIT8( Klightgreen, "lightgreen" );
       
   126     _LIT8( Klightgrey, "lightgrey" );
       
   127     _LIT8( Klightpink, "lightpink" );
       
   128     _LIT8( Klightsalmon, "lightsalmon" );
       
   129     _LIT8( Klightseagreen, "lightseagreen" );
       
   130     _LIT8( Klightskyblue, "lightskyblue" );
       
   131     _LIT8( Klightslategray, "lightslategray" );
       
   132     _LIT8( Klightslategrey, "lightslategrey" );
       
   133     _LIT8( Klightsteelblue, "lightsteelblue" );
       
   134     _LIT8( Klightyellow, "lightyellow" );
       
   135     _LIT8( Klime, "lime" );
       
   136     _LIT8( Klimegreen, "limegreen" );
       
   137     _LIT8( Klinen, "linen" );
       
   138     _LIT8( Kmagenta, "magenta" );
       
   139     _LIT8( Kmaroon, "maroon" );
       
   140     _LIT8( Kmediumaquamarine, "mediumaquamarine" );
       
   141     _LIT8( Kmediumblue, "mediumblue" );
       
   142     _LIT8( Kmediumorchid, "mediumorchid" );
       
   143     _LIT8( Kmediumpurple, "mediumpurple" );
       
   144     _LIT8( Kmediumseagreen, "mediumseagreen" );
       
   145     _LIT8( Kmediumslateblue, "mediumslateblue" );
       
   146     _LIT8( Kmediumspringgreen, "mediumspringgreen" );
       
   147     _LIT8( Kmediumturquoise, "mediumturquoise" );
       
   148     _LIT8( Kmediumvioletred, "mediumvioletred" );
       
   149     _LIT8( Kmidnightblue, "midnightblue" );
       
   150     _LIT8( Kmintcream, "mintcream" );
       
   151     _LIT8( Kmistyrose, "mistyrose" );
       
   152     _LIT8( Kmoccasin, "moccasin" );
       
   153     _LIT8( Knavajowhite, "navajowhite" );
       
   154     _LIT8( Knavy, "navy" );
       
   155     _LIT8( Koldlace, "oldlace" );
       
   156     _LIT8( Kolive, "olive" );
       
   157     _LIT8( Kolivedrab, "olivedrab" );
       
   158     _LIT8( Korange, "orange" );
       
   159     _LIT8( Korangered, "orangered" );
       
   160     _LIT8( Korchid, "orchid" );
       
   161     _LIT8( Kpalegoldenrod, "palegoldenrod" );
       
   162     _LIT8( Kpalegreen, "palegreen" );
       
   163     _LIT8( Kpaleturquoise, "paleturquoise" );
       
   164     _LIT8( Kpalevioletred, "palevioletred" );
       
   165     _LIT8( Kpapayawhip, "papayawhip" );
       
   166     _LIT8( Kpeachpuff, "peachpuff" );
       
   167     _LIT8( Kperu, "peru" );
       
   168     _LIT8( Kpink, "pink" );
       
   169     _LIT8( Kplum, "plum" );
       
   170     _LIT8( Kpowderblue, "powderblue" );
       
   171     _LIT8( Kpurple, "purple" );
       
   172     _LIT8( Kred, "red" );
       
   173     _LIT8( Krosybrown, "rosybrown" );
       
   174     _LIT8( Kroyalblue, "royalblue" );
       
   175     _LIT8( Ksaddlebrown, "saddlebrown" );
       
   176     _LIT8( Ksalmon, "salmon" );
       
   177     _LIT8( Ksandybrown, "sandybrown" );
       
   178     _LIT8( Kseagreen, "seagreen" );
       
   179     _LIT8( Kseashell, "seashell" );
       
   180     _LIT8( Ksienna, "sienna" );
       
   181     _LIT8( Ksilver, "silver" );
       
   182     _LIT8( Kskyblue, "skyblue" );
       
   183     _LIT8( Kslateblue, "slateblue" );
       
   184     _LIT8( Kslategray, "slategray" );
       
   185     _LIT8( Kslategrey, "slategrey" );
       
   186     _LIT8( Ksnow, "snow" );
       
   187     _LIT8( Kspringgreen, "springgreen" );
       
   188     _LIT8( Ksteelblue, "steelblue" );
       
   189     _LIT8( Ktan, "tan" );
       
   190     _LIT8( Kteal, "teal" );
       
   191     _LIT8( Kthistle, "thistle" );
       
   192     _LIT8( Ktomato, "tomato" );
       
   193     _LIT8( Kturquoise, "turquoise" );
       
   194     _LIT8( Kviolet, "violet" );
       
   195     _LIT8( Kwheat, "wheat" );
       
   196     _LIT8( Kwhite, "white" );
       
   197     _LIT8( Kwhitesmoke, "whitesmoke" );
       
   198     _LIT8( Kyellow, "yellow" );
       
   199     _LIT8( Kyellowgreen, "yellowgreen" );
       
   200     }
       
   201 
       
   202 namespace XnColorValues
       
   203     {
       
   204     const TInt Kaliceblue = 0xfff8f0;
       
   205     const TInt Kantiquewhite = 0xd7ebfa;
       
   206     const TInt Kaqua = 0xffff00;
       
   207     const TInt Kaquamarine = 0xd4ff7f;
       
   208     const TInt Kazure = 0xfffff0;
       
   209     const TInt Kbeige = 0xdcf5f5;
       
   210     const TInt Kbisque = 0xc4e4ff;
       
   211     const TInt Kblack = 0x000000;
       
   212     const TInt Kblanchedalmond = 0xcdebff;
       
   213     const TInt Kblue = 0xff0000;
       
   214     const TInt Kblueviolet = 0xe22b8a;
       
   215     const TInt Kbrown = 0x2a2aa5;
       
   216     const TInt Kburlywood = 0x87b8de;
       
   217     const TInt Kcadetblue = 0xa09e5f;
       
   218     const TInt Kchartreuse = 0x00ff7f;
       
   219     const TInt Kchocolate = 0x1e69d2;
       
   220     const TInt Kcoral = 0x507fff;
       
   221     const TInt Kcornflowerblue = 0xed9564;
       
   222     const TInt Kcornsilk = 0xdcf8ff;
       
   223     const TInt Kcrimson = 0x3c14dc;
       
   224     const TInt Kcyan = 0xffff00;
       
   225     const TInt Kdarkblue = 0x8b0000;
       
   226     const TInt Kdarkcyan = 0x8b8b00;
       
   227     const TInt Kdarkgoldenrod = 0x0b86b8;
       
   228     const TInt Kdarkgray = 0xa9a9a9;
       
   229     const TInt Kdarkgreen = 0x006400;
       
   230     const TInt Kdarkgrey = 0xa9a9a9;
       
   231     const TInt Kdarkkhaki = 0x6bb7bd;
       
   232     const TInt Kdarkmagenta = 0x8b008b;
       
   233     const TInt Kdarkolivegreen = 0x2f6b55;
       
   234     const TInt Kdarkorange = 0x008cff;
       
   235     const TInt Kdarkorchid = 0xcc3299;
       
   236     const TInt Kdarkred = 0x00008b;
       
   237     const TInt Kdarksalmon = 0x7a96e9;
       
   238     const TInt Kdarkseagreen = 0x8fbc8f;
       
   239     const TInt Kdarkslateblue = 0x8b3d48;
       
   240     const TInt Kdarkslategray = 0x4f4f2f;
       
   241     const TInt Kdarkslategrey = 0x4f4f2f;
       
   242     const TInt Kdarkturquoise = 0xd1ce00;
       
   243     const TInt Kdarkviolet = 0xd30094;
       
   244     const TInt Kdeeppink = 0x9314ff;
       
   245     const TInt Kdeepskyblue = 0xffbf00;
       
   246     const TInt Kdimgray = 0x696969;
       
   247     const TInt Kdimgrey = 0x696969;
       
   248     const TInt Kdodgerblue = 0xff901e;
       
   249     const TInt Kfirebrick = 0x2222b2;
       
   250     const TInt Kfloralwhite = 0xf0faff;
       
   251     const TInt Kforestgreen = 0x228b22;
       
   252     const TInt Kfuchsia = 0xff00ff;
       
   253     const TInt Kgainsboro = 0xdcdcdc;
       
   254     const TInt Kghostwhite = 0xfff8f8;
       
   255     const TInt Kgold = 0x00d7ff;
       
   256     const TInt Kgoldenrod = 0x20a5da;
       
   257     const TInt Kgray = 0x808080;
       
   258     const TInt Kgreen = 0x008000;
       
   259     const TInt Kgreenyellow = 0x2fffad;
       
   260     const TInt Kgrey = 0x808080;
       
   261     const TInt Khoneydew = 0xf0fff0;
       
   262     const TInt Khotpink = 0xb469ff;
       
   263     const TInt Kindianred = 0x5c5ccd;
       
   264     const TInt Kindigo = 0x82004b;
       
   265     const TInt Kivory = 0xf0ffff;
       
   266     const TInt Kkhaki = 0x8ce6f0;
       
   267     const TInt Klavender = 0xfae6e6;
       
   268     const TInt Klavenderblush = 0xf5f0ff;
       
   269     const TInt Klawngreen = 0x00fc7c;
       
   270     const TInt Klemonchiffon = 0xcdfaff;
       
   271     const TInt Klightblue = 0xe6d8ad;
       
   272     const TInt Klightcoral = 0x8080f0;
       
   273     const TInt Klightcyan = 0xffffe0;
       
   274     const TInt Klightgoldenrodyellow = 0xd2fafa;
       
   275     const TInt Klightgray = 0xd3d3d3;
       
   276     const TInt Klightgreen = 0x90ee90;
       
   277     const TInt Klightgrey = 0xd3d3d3;
       
   278     const TInt Klightpink = 0xc1b6ff;
       
   279     const TInt Klightsalmon = 0x7aa0ff;
       
   280     const TInt Klightseagreen = 0xaab220;
       
   281     const TInt Klightskyblue = 0xface87;
       
   282     const TInt Klightslategray = 0x998877;
       
   283     const TInt Klightslategrey = 0x998877;
       
   284     const TInt Klightsteelblue = 0xdec4b0;
       
   285     const TInt Klightyellow = 0xe0ffff;
       
   286     const TInt Klime = 0x00ff00;
       
   287     const TInt Klimegreen = 0x32cd32;
       
   288     const TInt Klinen = 0xe6f0fa;
       
   289     const TInt Kmagenta = 0xff00ff;
       
   290     const TInt Kmaroon = 0x000080;
       
   291     const TInt Kmediumaquamarine = 0xaacd66;
       
   292     const TInt Kmediumblue = 0xcd0000;
       
   293     const TInt Kmediumorchid = 0xd355ba;
       
   294     const TInt Kmediumpurple = 0xdb7093;
       
   295     const TInt Kmediumseagreen = 0x71b33c;
       
   296     const TInt Kmediumslateblue = 0xee687b;
       
   297     const TInt Kmediumspringgreen = 0x9afa00;
       
   298     const TInt Kmediumturquoise = 0xccd148;
       
   299     const TInt Kmediumvioletred = 0x8515c7;
       
   300     const TInt Kmidnightblue = 0x701919;
       
   301     const TInt Kmintcream = 0xfafff5;
       
   302     const TInt Kmistyrose = 0xe1e4ff;
       
   303     const TInt Kmoccasin = 0xb5e4ff;
       
   304     const TInt Knavajowhite = 0xaddeff;
       
   305     const TInt Knavy = 0x800000;
       
   306     const TInt Koldlace = 0xe6f5fd;
       
   307     const TInt Kolive = 0x008080;
       
   308     const TInt Kolivedrab = 0x238e6b;
       
   309     const TInt Korange = 0x00a5ff;
       
   310     const TInt Korangered = 0x0045ff;
       
   311     const TInt Korchid = 0xd670da;
       
   312     const TInt Kpalegoldenrod = 0xaae8ee;
       
   313     const TInt Kpalegreen = 0x98fb98;
       
   314     const TInt Kpaleturquoise = 0xeeeeaf;
       
   315     const TInt Kpalevioletred = 0x9370db;
       
   316     const TInt Kpapayawhip = 0xd5efff;
       
   317     const TInt Kpeachpuff = 0xb9daff;
       
   318     const TInt Kperu = 0x3f85cd;
       
   319     const TInt Kpink = 0xcbc0ff;
       
   320     const TInt Kplum = 0xdda0dd;
       
   321     const TInt Kpowderblue = 0xe6e0b0;
       
   322     const TInt Kpurple = 0x800080;
       
   323     const TInt Kred = 0x0000ff;
       
   324     const TInt Krosybrown = 0x8f8fbc;
       
   325     const TInt Kroyalblue = 0xe16941;
       
   326     const TInt Ksaddlebrown = 0x13458b;
       
   327     const TInt Ksalmon = 0x7280fa;
       
   328     const TInt Ksandybrown = 0x60a4f4;
       
   329     const TInt Kseagreen = 0x578b2e;
       
   330     const TInt Kseashell = 0xeef5ff;
       
   331     const TInt Ksienna = 0x2d52a0;
       
   332     const TInt Ksilver = 0xc0c0c0;
       
   333     const TInt Kskyblue = 0xebce87;
       
   334     const TInt Kslateblue = 0xcd5a6a;
       
   335     const TInt Kslategray = 0x908070;
       
   336     const TInt Kslategrey = 0x908070;
       
   337     const TInt Ksnow = 0xfafaff;
       
   338     const TInt Kspringgreen = 0x7fff00;
       
   339     const TInt Ksteelblue = 0xb48246;
       
   340     const TInt Ktan = 0x8cb4d2;
       
   341     const TInt Kteal = 0x808000;
       
   342     const TInt Kthistle = 0xd8bfd8;
       
   343     const TInt Ktomato = 0x4763ff;
       
   344     const TInt Kturquoise = 0xd0e040;
       
   345     const TInt Kviolet = 0xee82ee;
       
   346     const TInt Kwheat = 0xb3def5;
       
   347     const TInt Kwhite = 0xffffff;
       
   348     const TInt Kwhitesmoke = 0xf5f5f5;
       
   349     const TInt Kyellow = 0x00ffff;
       
   350     const TInt Kyellowgreen = 0x32cd9a;
       
   351     }
       
   352 
       
   353 // ======== LOCAL FUNCTIONS ========
       
   354 
       
   355 // -----------------------------------------------------------------------------
       
   356 // MatchColor
       
   357 // -----------------------------------------------------------------------------
       
   358 //
       
   359 static TBool MatchColor( const TDesC8& aColorName, TRgb& aValue )
       
   360     {
       
   361     // Following local macro is used to generate large if-table.
       
   362     #define E( name ) else if ( aColorName == XnColorNames::name ) \
       
   363         { \
       
   364         aValue = TRgb( XnColorValues::name ); \
       
   365         return ETrue; \
       
   366         }
       
   367 
       
   368     if ( EFalse )
       
   369         {
       
   370         }
       
   371     E( Kaliceblue )
       
   372     E( Kantiquewhite )
       
   373     E( Kaqua )
       
   374     E( Kaquamarine )
       
   375     E( Kazure )
       
   376     E( Kbeige )
       
   377     E( Kbisque )
       
   378     E( Kblack )
       
   379     E( Kblanchedalmond )
       
   380     E( Kblue )
       
   381     E( Kblueviolet )
       
   382     E( Kbrown )
       
   383     E( Kburlywood )
       
   384     E( Kcadetblue )
       
   385     E( Kchartreuse )
       
   386     E( Kchocolate )
       
   387     E( Kcoral )
       
   388     E( Kcornflowerblue )
       
   389     E( Kcornsilk )
       
   390     E( Kcrimson )
       
   391     E( Kcyan )
       
   392     E( Kdarkblue )
       
   393     E( Kdarkcyan )
       
   394     E( Kdarkgoldenrod )
       
   395     E( Kdarkgray )
       
   396     E( Kdarkgreen )
       
   397     E( Kdarkgrey )
       
   398     E( Kdarkkhaki )
       
   399     E( Kdarkmagenta )
       
   400     E( Kdarkolivegreen )
       
   401     E( Kdarkorange )
       
   402     E( Kdarkorchid )
       
   403     E( Kdarkred )
       
   404     E( Kdarksalmon )
       
   405     E( Kdarkseagreen )
       
   406     E( Kdarkslateblue )
       
   407     E( Kdarkslategray )
       
   408     E( Kdarkslategrey )
       
   409     E( Kdarkturquoise )
       
   410     E( Kdarkviolet )
       
   411     E( Kdeeppink )
       
   412     E( Kdeepskyblue )
       
   413     E( Kdimgray )
       
   414     E( Kdimgrey )
       
   415     E( Kdodgerblue )
       
   416     E( Kfirebrick )
       
   417     E( Kfloralwhite )
       
   418     E( Kforestgreen )
       
   419     E( Kfuchsia )
       
   420     E( Kgainsboro )
       
   421     E( Kghostwhite )
       
   422     E( Kgold )
       
   423     E( Kgoldenrod )
       
   424     E( Kgray )
       
   425     E( Kgreen )
       
   426     E( Kgreenyellow )
       
   427     E( Kgrey )
       
   428     E( Khoneydew )
       
   429     E( Khotpink )
       
   430     E( Kindianred )
       
   431     E( Kindigo )
       
   432     E( Kivory )
       
   433     E( Kkhaki )
       
   434     E( Klavender )
       
   435     E( Klavenderblush )
       
   436     E( Klawngreen )
       
   437     E( Klemonchiffon )
       
   438     E( Klightblue )
       
   439     E( Klightcoral )
       
   440     E( Klightcyan )
       
   441     E( Klightgoldenrodyellow )
       
   442     E( Klightgray )
       
   443     E( Klightgreen )
       
   444     E( Klightgrey )
       
   445     E( Klightpink )
       
   446     E( Klightsalmon )
       
   447     E( Klightseagreen )
       
   448     E( Klightskyblue )
       
   449     E( Klightslategray )
       
   450     E( Klightslategrey )
       
   451     E( Klightsteelblue )
       
   452     E( Klightyellow )
       
   453     E( Klime )
       
   454     E( Klimegreen )
       
   455     E( Klinen )
       
   456     E( Kmagenta )
       
   457     E( Kmaroon )
       
   458     E( Kmediumaquamarine )
       
   459     E( Kmediumblue )
       
   460     E( Kmediumorchid )
       
   461     E( Kmediumpurple )
       
   462     E( Kmediumseagreen )
       
   463     E( Kmediumslateblue )
       
   464     E( Kmediumspringgreen )
       
   465     E( Kmediumturquoise )
       
   466     E( Kmediumvioletred )
       
   467     E( Kmidnightblue )
       
   468     E( Kmintcream )
       
   469     E( Kmistyrose )
       
   470     E( Kmoccasin )
       
   471     E( Knavajowhite )
       
   472     E( Knavy )
       
   473     E( Koldlace )
       
   474     E( Kolive )
       
   475     E( Kolivedrab )
       
   476     E( Korange )
       
   477     E( Korangered )
       
   478     E( Korchid )
       
   479     E( Kpalegoldenrod )
       
   480     E( Kpalegreen )
       
   481     E( Kpaleturquoise )
       
   482     E( Kpalevioletred )
       
   483     E( Kpapayawhip )
       
   484     E( Kpeachpuff )
       
   485     E( Kperu )
       
   486     E( Kpink )
       
   487     E( Kplum )
       
   488     E( Kpowderblue )
       
   489     E( Kpurple )
       
   490     E( Kred )
       
   491     E( Krosybrown )
       
   492     E( Kroyalblue )
       
   493     E( Ksaddlebrown )
       
   494     E( Ksalmon )
       
   495     E( Ksandybrown )
       
   496     E( Kseagreen )
       
   497     E( Kseashell )
       
   498     E( Ksienna )
       
   499     E( Ksilver )
       
   500     E( Kskyblue )
       
   501     E( Kslateblue )
       
   502     E( Kslategray )
       
   503     E( Kslategrey )
       
   504     E( Ksnow )
       
   505     E( Kspringgreen )
       
   506     E( Ksteelblue )
       
   507     E( Ktan )
       
   508     E( Kteal )
       
   509     E( Kthistle )
       
   510     E( Ktomato )
       
   511     E( Kturquoise )
       
   512     E( Kviolet )
       
   513     E( Kwheat )
       
   514     E( Kwhite )
       
   515     E( Kwhitesmoke )
       
   516     E( Kyellow )
       
   517     E( Kyellowgreen )
       
   518     else
       
   519         {
       
   520         return EFalse;
       
   521         }
       
   522     #undef E
       
   523     return EFalse;
       
   524     }
       
   525 
       
   526 // -----------------------------------------------------------------------------
       
   527 // FindResource
       
   528 // Locates a resource from the resource list
       
   529 // -----------------------------------------------------------------------------
       
   530 //
       
   531 EXPORT_C CXnResource* CXnUtils::FindResource(
       
   532     CArrayPtrSeg< CXnResource >& aArray,
       
   533     const TDesC& aResourceFileName,
       
   534     TInt& aBitmapIndex )
       
   535     {
       
   536     if ( aResourceFileName == KNullDesC )
       
   537         {
       
   538         return NULL;
       
   539         }
       
   540 
       
   541     TUriParser parser;
       
   542     parser.Parse( aResourceFileName );
       
   543 
       
   544     TPtrC uriWithoutFragment;
       
   545     parser.UriWithoutFragment( uriWithoutFragment );
       
   546 
       
   547     const TDesC& fragment( parser.Extract( EUriFragment ) );
       
   548 
       
   549     TLex lex( fragment );
       
   550     lex.Val( aBitmapIndex );
       
   551 
       
   552     for ( TInt i = aArray.Count() - 1; i >= 0; --i )
       
   553         {
       
   554         CXnResource* res( aArray.At( i ) );
       
   555 
       
   556         const TDesC& resId( res->ResourceId() );
       
   557 
       
   558         if ( resId.FindF( uriWithoutFragment ) != KErrNotFound )
       
   559             {
       
   560             return res;
       
   561             }
       
   562         }
       
   563 
       
   564     return NULL;
       
   565     }
       
   566 
       
   567 // -----------------------------------------------------------------------------
       
   568 // DecimalFromHexChar
       
   569 // -----------------------------------------------------------------------------
       
   570 //
       
   571 static TBool DecimalFromHexChar( TChar aChar, TInt& aValue )
       
   572     {
       
   573     switch ( aChar )
       
   574         {
       
   575         case 'a':
       
   576         case 'A':
       
   577             aValue = 10;
       
   578             return ETrue;
       
   579         case 'b':
       
   580         case 'B':
       
   581             aValue = 11;
       
   582             return ETrue;
       
   583         case 'c':
       
   584         case 'C':
       
   585             aValue = 12;
       
   586             return ETrue;
       
   587         case 'd':
       
   588         case 'D':
       
   589             aValue = 13;
       
   590             return ETrue;
       
   591         case 'e':
       
   592         case 'E':
       
   593             aValue = 14;
       
   594             return ETrue;
       
   595         case 'f':
       
   596         case 'F':
       
   597             aValue = 15;
       
   598             return ETrue;
       
   599         case '0':
       
   600             aValue = 0;
       
   601             return ETrue;
       
   602         case '1':
       
   603             aValue = 1;
       
   604             return ETrue;
       
   605         case '2':
       
   606             aValue = 2;
       
   607             return ETrue;
       
   608         case '3':
       
   609             aValue = 3;
       
   610             return ETrue;
       
   611         case '4':
       
   612             aValue = 4;
       
   613             return ETrue;
       
   614         case '5':
       
   615             aValue = 5;
       
   616             return ETrue;
       
   617         case '6':
       
   618             aValue = 6;
       
   619             return ETrue;
       
   620         case '7':
       
   621             aValue = 7;
       
   622             return ETrue;
       
   623         case '8':
       
   624             aValue = 8;
       
   625             return ETrue;
       
   626         case '9':
       
   627             aValue = 9;
       
   628             return ETrue;
       
   629         }
       
   630     return EFalse;
       
   631     }
       
   632 
       
   633 // -----------------------------------------------------------------------------
       
   634 // NumericOrHexValue
       
   635 // -----------------------------------------------------------------------------
       
   636 //
       
   637 static TInt NumericOrHexValue( TReal& aValue, TLex8& aData )
       
   638     {
       
   639     TBool isHex = EFalse;
       
   640     TInt hexIndex = 0;
       
   641     TPtrC8 data = aData.Remainder();
       
   642     TInt separatorIndex = 0;
       
   643     if ( ( hexIndex = data.LocateF( '#' ) ) != KErrNotFound &&
       
   644          ( ( separatorIndex = data.LocateF( ',' ) ) != KErrNotFound ||
       
   645            ( separatorIndex = data.LocateF( ')' ) ) != KErrNotFound ) &&
       
   646          ( separatorIndex > hexIndex ) )
       
   647         {
       
   648         isHex = ETrue;
       
   649         }
       
   650     if ( !isHex )
       
   651         {
       
   652         return aData.Val( aValue );
       
   653         }
       
   654     else
       
   655         {
       
   656         TChar character = aData.Get();
       
   657         if ( character == 0 )
       
   658             {
       
   659             return KErrGeneral;
       
   660             }
       
   661         character = aData.Get();
       
   662         if ( character == 0 )
       
   663             {
       
   664             return KErrGeneral;
       
   665             }
       
   666         TChar secondCharacter = aData.Get();
       
   667         if ( secondCharacter == 0 )
       
   668             {
       
   669             return KErrGeneral;
       
   670             }
       
   671         TInt val;
       
   672         TInt secondVal;
       
   673         if ( DecimalFromHexChar( character, val ) &&
       
   674              DecimalFromHexChar( secondCharacter, secondVal ) )
       
   675             {
       
   676             aValue = 16 * val + secondVal;
       
   677             return KErrNone;
       
   678             }
       
   679         }
       
   680     return KErrGeneral;
       
   681     }
       
   682 
       
   683 // -----------------------------------------------------------------------------
       
   684 // DecimalValueOrPercentage
       
   685 // -----------------------------------------------------------------------------
       
   686 //
       
   687 static TInt DecimalValueOrPercentage( TInt& aValue, TLex8& aData )
       
   688     {
       
   689     TBool isPercentage = EFalse;
       
   690     TInt separatorIndex = 0;
       
   691     TInt percentageIndex = 0;
       
   692     TPtrC8 data = aData.Remainder();
       
   693     if ( ( percentageIndex = data.LocateF( '%' ) ) != KErrNotFound &&
       
   694          ( ( separatorIndex = data.LocateF( ',' ) ) != KErrNotFound ||
       
   695            ( separatorIndex = data.LocateF( ')' ) ) != KErrNotFound ) &&
       
   696          ( separatorIndex > percentageIndex ) )
       
   697         {
       
   698         isPercentage = ETrue;
       
   699         }
       
   700     TReal tmp;
       
   701     TInt error = NumericOrHexValue( tmp, aData );
       
   702     if ( error != KErrNone )
       
   703         {
       
   704         return error;
       
   705         }
       
   706     if ( !isPercentage )
       
   707         {
       
   708         aValue = static_cast< TInt >( tmp );
       
   709         }
       
   710     else
       
   711         {
       
   712         aValue = static_cast< TInt >( ( tmp / 100.0 ) * 255.0 );
       
   713         }
       
   714     return KErrNone;
       
   715     }
       
   716 
       
   717 // -----------------------------------------------------------------------------
       
   718 // GetRgbValueFromColorName
       
   719 // -----------------------------------------------------------------------------
       
   720 //
       
   721 static TBool GetRgbValueFromColorName( TRgb& aValue, const TDesC8& aData )
       
   722     {
       
   723     return MatchColor( aData, aValue );
       
   724     }
       
   725 
       
   726 // -----------------------------------------------------------------------------
       
   727 // GetRgbValueFromDecimalValues
       
   728 // -----------------------------------------------------------------------------
       
   729 //
       
   730 static TBool GetRgbValueFromDecimalValues( TRgb& aValue, const TDesC8& aData )
       
   731     {
       
   732     TLex8 lex( aData );
       
   733     TInt red;
       
   734     TInt green;
       
   735     TInt blue;
       
   736     lex.SkipSpace();
       
   737     TInt error = DecimalValueOrPercentage( red, lex );
       
   738     if ( error != KErrNone )
       
   739         {
       
   740         return EFalse;
       
   741         }
       
   742     lex.SkipSpace();
       
   743     while ( lex.Peek() == ',' || lex.Peek() == '%' )
       
   744         {
       
   745         lex.Get();
       
   746         lex.SkipSpace();
       
   747         }
       
   748     error = DecimalValueOrPercentage( green, lex );
       
   749     if ( error != KErrNone )
       
   750         {
       
   751         return EFalse;
       
   752         }
       
   753     lex.SkipSpace();
       
   754     while ( lex.Peek() == ',' || lex.Peek() == '%' )
       
   755         {
       
   756         lex.Get();
       
   757         lex.SkipSpace();
       
   758         }
       
   759     error = DecimalValueOrPercentage( blue, lex );
       
   760     if ( error != KErrNone )
       
   761         {
       
   762         return EFalse;
       
   763         }
       
   764     aValue.SetRed( red );
       
   765     aValue.SetGreen( green );
       
   766     aValue.SetBlue( blue );
       
   767     return ETrue;
       
   768     }
       
   769 
       
   770 // -----------------------------------------------------------------------------
       
   771 // GetRgbValueFromRgbFunction
       
   772 // -----------------------------------------------------------------------------
       
   773 //
       
   774 static TBool GetRgbValueFromRgbFunction( TRgb& aValue, const TDesC8& aData )
       
   775     {
       
   776     TInt functionNameIndex = 0;
       
   777     TInt openingParenthesisIndex = 0;
       
   778     TInt closingParenthesisIndex = 0;
       
   779     if ( ( functionNameIndex = aData.FindF( _L8( "rgb" ) ) ) != KErrNotFound &&
       
   780          ( openingParenthesisIndex = aData.FindF( _L8( "(" ) ) ) != KErrNotFound &&
       
   781          ( openingParenthesisIndex > functionNameIndex ) &&
       
   782          ( closingParenthesisIndex = aData.FindF( _L8( ")" ) ) ) != KErrNotFound &&
       
   783          ( closingParenthesisIndex > openingParenthesisIndex ) )
       
   784         {
       
   785         TPtrC8 functionString = aData.Mid(
       
   786             openingParenthesisIndex + 1,
       
   787             closingParenthesisIndex - openingParenthesisIndex );
       
   788         return GetRgbValueFromDecimalValues( aValue, functionString );
       
   789         }
       
   790     return EFalse;
       
   791     }
       
   792 
       
   793 // -----------------------------------------------------------------------------
       
   794 // GetRgbValueFromHslFunction
       
   795 // -----------------------------------------------------------------------------
       
   796 //
       
   797 static TBool GetRgbValueFromHslFunction( TRgb& aValue, const TDesC8& aData )
       
   798     {
       
   799     TInt functionNameIndex = 0;
       
   800     TInt openingParenthesisIndex = 0;
       
   801     TInt closingParenthesisIndex = 0;
       
   802     if ( ( functionNameIndex = aData.FindF( _L8( "hsl" ) ) ) != KErrNotFound &&
       
   803          ( openingParenthesisIndex = aData.FindF( _L8( "(" ) ) ) != KErrNotFound &&
       
   804          ( openingParenthesisIndex > functionNameIndex ) &&
       
   805          ( closingParenthesisIndex = aData.FindF( _L8( ")" ) ) ) != KErrNotFound &&
       
   806          ( closingParenthesisIndex > openingParenthesisIndex ) )
       
   807         {
       
   808         TPtrC8 functionString = aData.Mid(
       
   809             openingParenthesisIndex + 1,
       
   810             closingParenthesisIndex - openingParenthesisIndex );
       
   811         TRgb rgb;
       
   812         TBool success = GetRgbValueFromDecimalValues( rgb, functionString );
       
   813 
       
   814         TLex8 lex( functionString );
       
   815         TInt red;
       
   816         TInt green;
       
   817         TInt blue;
       
   818         lex.SkipSpace();
       
   819         TReal tmp;
       
   820 
       
   821         TInt error = NumericOrHexValue( tmp, lex );
       
   822         if ( error != KErrNone )
       
   823             {
       
   824             return EFalse;
       
   825             }
       
   826         red = static_cast< TInt >( tmp );
       
   827         lex.SkipSpace();
       
   828         while ( lex.Peek() == ',' || lex.Peek() == '%' )
       
   829             {
       
   830             lex.Get();
       
   831             lex.SkipSpace();
       
   832             }
       
   833         error = NumericOrHexValue( tmp, lex );
       
   834         if ( error != KErrNone )
       
   835             {
       
   836             return EFalse;
       
   837             }
       
   838         green = static_cast< TInt >( tmp );
       
   839         lex.SkipSpace();
       
   840         while ( lex.Peek() == ',' || lex.Peek() == '%' )
       
   841             {
       
   842             lex.Get();
       
   843             lex.SkipSpace();
       
   844             }
       
   845         error = NumericOrHexValue( tmp, lex );
       
   846         if ( error != KErrNone )
       
   847             {
       
   848             return EFalse;
       
   849             }
       
   850         blue = static_cast< TInt >( tmp );
       
   851 
       
   852         if ( success )
       
   853             {
       
   854             aValue = CXnUtils::ConvertHslToRgb( red, green, blue );
       
   855             }
       
   856         return success;
       
   857         }
       
   858     return EFalse;
       
   859     }
       
   860 
       
   861 // -----------------------------------------------------------------------------
       
   862 // GetRgbValueFromHexValue
       
   863 // -----------------------------------------------------------------------------
       
   864 //
       
   865 static TBool GetRgbValueFromHexValue( TRgb& aValue, const TDesC8& aData )
       
   866     {
       
   867     TBool isHex = EFalse;
       
   868     if ( aData.LocateF( '#' ) != KErrNotFound )
       
   869         {
       
   870         isHex = ETrue;
       
   871         }
       
   872     if ( !isHex )
       
   873         {
       
   874         return EFalse;
       
   875         }
       
   876     else
       
   877         {
       
   878         TInt length = aData.Length();
       
   879         TLex8 lex( aData );
       
   880         lex.SkipSpace();
       
   881         if ( lex.Get() == 0 )
       
   882             {
       
   883             return EFalse;
       
   884             }
       
   885         TInt values[3];
       
   886         TBool flags[3] = { EFalse, EFalse, EFalse };
       
   887         TChar chars[6] = { 0, 0, 0, 0, 0, 0 };
       
   888         for ( TInt i = 5; i >= 0; --i )
       
   889             {
       
   890             TChar character = lex.Get();
       
   891             if ( character == 0 )
       
   892                 {
       
   893                 break;
       
   894                 }
       
   895             chars[i] = character;
       
   896             if ( length == 4 )
       
   897                 {
       
   898                 i--;
       
   899                 chars[i] = character;
       
   900                 }
       
   901             }
       
   902 
       
   903         for ( TInt i = 5, j = 0; ( i >= 0 ) && ( j < 3 ); --i )
       
   904             {
       
   905             if ( chars[i] == 0 )
       
   906                 {
       
   907                 continue;
       
   908                 }
       
   909             if ( i % 2 )
       
   910                 {
       
   911                 TInt secondVal = 0;
       
   912                 TInt val = 0;
       
   913                 TChar secondCharacter = chars[i];
       
   914                 --i;
       
   915                 TChar character = chars[i];
       
   916                 if ( DecimalFromHexChar( character, val ) &&
       
   917                      DecimalFromHexChar( secondCharacter, secondVal ) )
       
   918                     {
       
   919                     values[j] = val + 16 * secondVal;
       
   920                     flags[j] = ETrue;
       
   921                     ++j;
       
   922                     }
       
   923                 else
       
   924                     {
       
   925                     break;
       
   926                     }
       
   927                 }
       
   928             else
       
   929                 {
       
   930                 TInt val = 0;
       
   931                 TChar character = chars[i];
       
   932                 if ( DecimalFromHexChar( character, val ) )
       
   933                     {
       
   934                     values[j] = val;
       
   935                     flags[j] = ETrue;
       
   936                     ++j;
       
   937                     }
       
   938                 else
       
   939                     {
       
   940                     break;
       
   941                     }
       
   942                 }
       
   943             }
       
   944         if ( flags[2] && flags[1] && flags[0] )
       
   945             {
       
   946             aValue.SetRed( values[0] );
       
   947             aValue.SetGreen( values[1] );
       
   948             aValue.SetBlue( values[2] );
       
   949             return ETrue;
       
   950             }
       
   951         else if ( flags[1] && flags[0] )
       
   952             {
       
   953             aValue.SetRed( 0 );
       
   954             aValue.SetGreen( values[0] );
       
   955             aValue.SetBlue( values[1] );
       
   956             return ETrue;
       
   957             }
       
   958         else if ( flags[0] )
       
   959             {
       
   960             aValue.SetRed( 0 );
       
   961             aValue.SetGreen( 0 );
       
   962             aValue.SetBlue( values[0] );
       
   963             return ETrue;
       
   964             }
       
   965         }
       
   966     return EFalse;
       
   967     }
       
   968 
       
   969 // -----------------------------------------------------------------------------
       
   970 // Finds out AVKON font ID from fontname
       
   971 // -----------------------------------------------------------------------------
       
   972 //
       
   973 static TInt AvkonFontId( const TDesC& aFontName )
       
   974     {
       
   975     TInt fontId( KErrNotFound );
       
   976     if ( aFontName == KPrimaryFont )
       
   977         {
       
   978         fontId = KAknFontCategoryPrimary;
       
   979         }
       
   980     else if ( aFontName == KSecondaryFont )
       
   981         {
       
   982         fontId = KAknFontCategorySecondary;
       
   983         }
       
   984     else if ( aFontName == KTitleFont )
       
   985         {
       
   986         fontId = KAknFontCategoryTitle;
       
   987         }
       
   988     else if ( aFontName == KPrimarySmallFont )
       
   989         {
       
   990         fontId = KAknFontCategoryPrimarySmall;
       
   991         }
       
   992     else if ( aFontName == KDigitalFont )
       
   993         {
       
   994         fontId = KAknFontCategoryDigital;
       
   995         }
       
   996     return fontId;
       
   997     }
       
   998 
       
   999 // -----------------------------------------------------------------------------
       
  1000 // TRgb CXnUtils::ConvertHslToRgb( TInt aHue, TInt aSaturation,
       
  1001 // TInt aLightness )
       
  1002 // Perform the HSL to RGB conversion according to
       
  1003 // the rules defined in the CSS3 color module specification:
       
  1004 // http://www.w3.org/TR/2003/CR-css3-color-20030514/#hsl-color
       
  1005 // -----------------------------------------------------------------------------
       
  1006 //
       
  1007 EXPORT_C TRgb CXnUtils::ConvertHslToRgb(
       
  1008     TInt aHue, TInt aSaturation, TInt aLightness )
       
  1009     {
       
  1010     TRgb rgb( 0, 0, 0 );
       
  1011     TReal h( aHue );
       
  1012     h /= 360;
       
  1013     TReal s( aSaturation );
       
  1014     s /= 100;
       
  1015     TReal l( aLightness );
       
  1016     l /= 100;
       
  1017 
       
  1018     if ( 0 == aSaturation )
       
  1019         {
       
  1020         rgb.SetRed( TInt( l * 255 ) );
       
  1021         rgb.SetGreen( TInt( l * 255 ) );
       
  1022         rgb.SetBlue( TInt( l * 255 ) );
       
  1023         }
       
  1024     else
       
  1025         {
       
  1026         TReal m1( 0 );
       
  1027         TReal m2( 0 );
       
  1028 
       
  1029         // l<=0.5: PUT l*(s+1) IN m2
       
  1030         if ( aLightness < 0.5 )
       
  1031             {
       
  1032             m2 = l * ( s + 1.0 );
       
  1033             }
       
  1034         // PUT l+s-l*s IN m2
       
  1035         else
       
  1036             {
       
  1037             m2 = l + s - ( l * s );
       
  1038             }
       
  1039 
       
  1040         // PUT l*2-m2 IN m1
       
  1041         m1 = l * 2.0 - m2;
       
  1042 
       
  1043         TReal helperH( h );
       
  1044         TReal helperM1( m1 );
       
  1045         TReal helperM2( m2 );
       
  1046 
       
  1047         // calculate Red
       
  1048         helperH = h + ( 1.0 / 3.0 );
       
  1049 
       
  1050         // IF h<0: PUT h+1 IN h
       
  1051         if ( helperH < 0 )
       
  1052             {
       
  1053             helperH += 1.0;
       
  1054             }
       
  1055 
       
  1056         // IF h>1: PUT h-1 IN h
       
  1057         else if ( helperH > 1 )
       
  1058             {
       
  1059             helperH -= 1.0;
       
  1060             }
       
  1061         else
       
  1062             {
       
  1063             }
       
  1064 
       
  1065         TReal val( 0 );
       
  1066 
       
  1067         // IF h*6<1: RETURN m1+(m2-m1)*h*6
       
  1068         if ( ( helperH * 6 ) < 1 )
       
  1069             {
       
  1070             val = ( 255 * ( helperM1 + ( helperM2 - helperM1 ) * helperH * 6.0 ) );
       
  1071             }
       
  1072 
       
  1073         // IF h*2<1: RETURN m2 )
       
  1074         else if ( ( helperH * 2.0 ) < 1.0 )
       
  1075             {
       
  1076             val = ( 255.0 * helperM2 );
       
  1077             }
       
  1078 
       
  1079         // IF h*3<2: RETURN m1+(m2-m1)*(2/3-h)*6
       
  1080         else if ( ( helperH * 3.0 ) < 2.0 )
       
  1081             {
       
  1082             val = ( 255.0 * ( helperM1 + ( helperM2 - helperM1 ) *
       
  1083                             ( 2.0 / 3.0 - helperH ) * 6.0 ) );
       
  1084             }
       
  1085         else
       
  1086             {
       
  1087             val = 255.0 * helperM1;
       
  1088             }
       
  1089         TInt tmpVal = TInt( val + 0.5 );
       
  1090         rgb.SetRed( ( tmpVal >= 0 ) ? tmpVal : -tmpVal );
       
  1091 
       
  1092         // calculate Green
       
  1093         // PUT hue.to.rgb(m1, m2, h    ) IN g
       
  1094         helperH = h;
       
  1095         helperM1 = m1;
       
  1096         helperM2 = m2;
       
  1097 
       
  1098         // IF h<0: PUT h+1 IN h
       
  1099         if ( helperH < 0 )
       
  1100             {
       
  1101             helperH += 1.0;
       
  1102             }
       
  1103 
       
  1104         // IF h>1: PUT h-1 IN h
       
  1105         else if ( helperH > 1 )
       
  1106             {
       
  1107             helperH -= 1.0;
       
  1108             }
       
  1109         else
       
  1110             {
       
  1111             }
       
  1112 
       
  1113         // IF h*6<1: RETURN m1+(m2-m1)*h*6
       
  1114         if ( ( helperH * 6 ) < 1 )
       
  1115             {
       
  1116             val = ( 255.0 * ( helperM1 + ( helperM2 - helperM1 ) * helperH * 6.0 ) );
       
  1117             }
       
  1118 
       
  1119         // IF h*2<1: RETURN m2
       
  1120         else if ( ( helperH * 2 ) < 1 )
       
  1121             {
       
  1122             val = ( 255.0 * helperM2 );
       
  1123             }
       
  1124 
       
  1125         // IF h*3<2: RETURN m1+(m2-m1)*(2/3-h)*6
       
  1126         else if ( ( helperH * 3 ) < 2 )
       
  1127             {
       
  1128             val = ( 255.0 * ( helperM1 + ( helperM2 - helperM1 ) *
       
  1129                             ( 2.0 / 3.0 - helperH ) * 6.0 ) );
       
  1130             }
       
  1131         else
       
  1132             {
       
  1133             val = 255.0 * helperM1;
       
  1134             }
       
  1135 
       
  1136         tmpVal = TInt( val + 0.5 );
       
  1137         rgb.SetGreen( ( tmpVal >= 0 ) ? tmpVal : tmpVal );
       
  1138 
       
  1139         // calculate Blue
       
  1140         // PUT hue.to.rgb(m1, m2, h-1/3) IN b
       
  1141         helperH = h - ( 1.0 / 3.0 );
       
  1142         helperM1 = m1;
       
  1143         helperM2 = m2;
       
  1144 
       
  1145         // IF h<0: PUT h+1 IN h
       
  1146         if ( helperH < 0 )
       
  1147             {
       
  1148             helperH += 1.0;
       
  1149             }
       
  1150 
       
  1151         // IF h>1: PUT h-1 IN h
       
  1152         else if ( helperH > 1 )
       
  1153             {
       
  1154             helperH -= 1.0;
       
  1155             }
       
  1156         else
       
  1157             {
       
  1158             }
       
  1159 
       
  1160         // IF h*6<1: RETURN m1+(m2-m1)*h*6
       
  1161         if ( ( helperH * 6 ) < 1 )
       
  1162             {
       
  1163             val = ( 255.0 * ( helperM1 + ( helperM2 - helperM1 ) * helperH * 6.0 ) );
       
  1164             }
       
  1165 
       
  1166         // IF h*2<1: RETURN m2
       
  1167         else if ( ( helperH * 2 ) < 1 )
       
  1168             {
       
  1169             val = ( 255.0 * helperM2 );
       
  1170             }
       
  1171 
       
  1172         // IF h*3<2: RETURN m1+(m2-m1)*(2/3-h)*6
       
  1173         else if ( ( helperH * 3 ) < 2 )
       
  1174             {
       
  1175             val = ( 255.0 * ( helperM1 + ( helperM2 - helperM1 ) *
       
  1176                             ( 2.0 / 3.0 - helperH ) * 6.0 ) );
       
  1177             }
       
  1178         else
       
  1179             {
       
  1180             val = 255.0 * helperM1;
       
  1181             }
       
  1182 
       
  1183         tmpVal = TInt( val + 0.5 );
       
  1184         rgb.SetBlue( ( tmpVal >= 0 ) ? tmpVal : -tmpVal );
       
  1185         }
       
  1186     return rgb;
       
  1187     }
       
  1188 
       
  1189 // -----------------------------------------------------------------------------
       
  1190 // GetRgbValue
       
  1191 // -----------------------------------------------------------------------------
       
  1192 //
       
  1193 EXPORT_C TBool CXnUtils::GetRgbValue( TRgb& aValue, const TDesC8& aData )
       
  1194     {
       
  1195     return GetRgbValueFromRgbFunction( aValue, aData ) ||
       
  1196            GetRgbValueFromHslFunction( aValue, aData ) ||
       
  1197            GetRgbValueFromHexValue( aValue, aData ) ||
       
  1198            GetRgbValueFromColorName( aValue, aData );
       
  1199     }
       
  1200 
       
  1201 // -----------------------------------------------------------------------------
       
  1202 // Retrieves the string property of the node.
       
  1203 // -----------------------------------------------------------------------------
       
  1204 //
       
  1205 const TDesC8& GetStringProperty(
       
  1206     CXnNodePluginIf& aNode,
       
  1207     const TDesC8& aProperty )
       
  1208     {
       
  1209     CXnProperty* prop( NULL );
       
  1210     TRAP_IGNORE( prop = aNode.GetPropertyL( aProperty ) );
       
  1211     if ( prop )
       
  1212         {
       
  1213         CXnDomPropertyValue* value = static_cast< CXnDomPropertyValue* >(
       
  1214             prop->Property()->PropertyValueList().Item( 0 ) );
       
  1215         if ( CXnDomPropertyValue::EIdent == value->PrimitiveValueType() ||
       
  1216              CXnDomPropertyValue::EString == value->PrimitiveValueType() )
       
  1217             {
       
  1218             return prop->StringValue();
       
  1219             }
       
  1220         }
       
  1221     return KNullDesC8;
       
  1222     }
       
  1223 
       
  1224 // ======== MEMBER FUNCTIONS ========
       
  1225 
       
  1226 // -----------------------------------------------------------------------------
       
  1227 // Creates the font according to node information.
       
  1228 // -----------------------------------------------------------------------------
       
  1229 //
       
  1230 EXPORT_C void CXnUtils::CreateFontL(
       
  1231     CXnNodePluginIf& aNode,
       
  1232     CFont*& aFont,
       
  1233     TInt& aReleaseFont )
       
  1234     {
       
  1235     // Get the font properties from node
       
  1236     TFontSpec fontspec;
       
  1237 
       
  1238     //Font name
       
  1239     const TDesC8& fontNameS = GetStringProperty(
       
  1240         aNode, XnPropertyNames::appearance::common::KFontFamily );
       
  1241     HBufC* fontName = HBufC::NewLC( fontNameS.Length() );
       
  1242     TPtr namePtr = fontName->Des();
       
  1243     namePtr.Copy( fontNameS ); // 8-bit to 16-bit
       
  1244     StripQuotes( fontName );
       
  1245     TInt fLenght = fontName->Length();
       
  1246     TInt avkonFId = AvkonFontId( *fontName );
       
  1247 
       
  1248     //let's see if normal font needed
       
  1249     CCoeEnv* coeEnv = CEikonEnv::Static();
       
  1250     if ( *fontName == KNormal ||
       
  1251          !fLenght ||
       
  1252          ( KErrNotFound == avkonFId && fLenght > 24 ) )
       
  1253         {
       
  1254         aFont = const_cast< CFont* >( coeEnv->NormalFont() );
       
  1255         aReleaseFont = EFalse;
       
  1256         CleanupStack::PopAndDestroy( fontName );
       
  1257         return;
       
  1258         }
       
  1259 
       
  1260     //Font size in pixels
       
  1261     CXnProperty* fontSizeProp = aNode.GetPropertyL(
       
  1262         XnPropertyNames::appearance::common::KFontSize );
       
  1263     TInt fontSizeInPixels( aNode.Rect().Height() );//default font size
       
  1264 
       
  1265     if ( fontSizeProp )
       
  1266         { //font size from node if needed. If leaves uses default.
       
  1267         TRAP_IGNORE( fontSizeInPixels = aNode.UiEngineL()->VerticalPixelValueL(
       
  1268             fontSizeProp, aNode.Rect().Height()) );
       
  1269         }
       
  1270 
       
  1271     //Font stroke
       
  1272     const TDesC8& fontStroke = GetStringProperty(
       
  1273         aNode, XnPropertyNames::appearance::common::KFontWeight );
       
  1274     if ( fontStroke == XnPropertyNames::appearance::common::fontweight::KBold )
       
  1275         {
       
  1276         fontspec.iFontStyle.SetStrokeWeight( EStrokeWeightBold );
       
  1277         }
       
  1278 
       
  1279     //Font posture
       
  1280     const TDesC8& fontPosture = GetStringProperty(
       
  1281         aNode, XnPropertyNames::appearance::common::KFontStyle );
       
  1282     if ( fontPosture == XnPropertyNames::appearance::common::fontstyle::KItalic )
       
  1283         {
       
  1284         fontspec.iFontStyle.SetPosture( EPostureItalic );
       
  1285         }
       
  1286 
       
  1287     //Font effects
       
  1288     CXnProperty* textEffectsProp = aNode.GetPropertyL(
       
  1289         XnPropertyNames::appearance::common::KTextEffects );
       
  1290     if ( textEffectsProp )
       
  1291         {
       
  1292         CBitmapDevice* dev = coeEnv->ScreenDevice();
       
  1293         fontspec.iHeight = fontSizeInPixels;
       
  1294 
       
  1295         CXnDomList& propertyValueList =
       
  1296             textEffectsProp->Property()->PropertyValueList();
       
  1297         TInt valueCount = propertyValueList.Length();
       
  1298         TUint32 effectsFlag( 0 );
       
  1299 
       
  1300         for ( TInt i = 0; i < valueCount; ++i )
       
  1301             {
       
  1302             CXnDomPropertyValue* value = static_cast< CXnDomPropertyValue* >(
       
  1303                 propertyValueList.Item( i ) );
       
  1304 
       
  1305             if ( value->StringValueL() ==
       
  1306                  XnPropertyNames::appearance::common::fonteffects::KEffectsAlgorithmicbold )
       
  1307                 {
       
  1308                 effectsFlag |= FontEffect::EAlgorithmicBold;
       
  1309                 }
       
  1310             if ( value->StringValueL() ==
       
  1311                  XnPropertyNames::appearance::common::fonteffects::KEffectsDropshadow )
       
  1312                 {
       
  1313                 effectsFlag |= FontEffect::EDropShadow;
       
  1314                 }
       
  1315             if ( value->StringValueL() ==
       
  1316                  XnPropertyNames::appearance::common::fonteffects::KEffectsOutline )
       
  1317                 {
       
  1318                 effectsFlag |= FontEffect::EOutline;
       
  1319                 }
       
  1320             if ( value->StringValueL() == 
       
  1321                  XnPropertyNames::appearance::common::fonteffects::KEffectsEmbossed )
       
  1322                 {
       
  1323                 effectsFlag |= FontEffect::EEmbossed;
       
  1324                 }
       
  1325             if ( value->StringValueL() ==
       
  1326                  XnPropertyNames::appearance::common::fonteffects::KEffectsEngraved )
       
  1327                 {
       
  1328                 effectsFlag |= FontEffect::EEngraved;
       
  1329                 }
       
  1330             if ( value->StringValueL() == 
       
  1331                  XnPropertyNames::appearance::common::fonteffects::KEffectsSoftedge )
       
  1332                 {
       
  1333                 effectsFlag |= FontEffect::ESoftEdge;
       
  1334                 }
       
  1335             }
       
  1336         // Must be antialiased for effects to work
       
  1337         fontspec.iFontStyle.SetBitmapType( EAntiAliasedGlyphBitmap );
       
  1338         fontspec.iFontStyle.SetEffects( effectsFlag );
       
  1339         User::LeaveIfError( dev->GetNearestFontToDesignHeightInPixels(
       
  1340             aFont, fontspec ) );
       
  1341         aReleaseFont = ETrue;
       
  1342         }
       
  1343     else
       
  1344         {
       
  1345         CreateFontL( *fontName, fontSizeInPixels,
       
  1346                      fontspec.iFontStyle, aFont, aReleaseFont );
       
  1347         }
       
  1348 
       
  1349     CleanupStack::PopAndDestroy( fontName );
       
  1350     }
       
  1351 
       
  1352 // -----------------------------------------------------------------------------
       
  1353 // Creates the font according to given information.
       
  1354 // -----------------------------------------------------------------------------
       
  1355 //
       
  1356 EXPORT_C void CXnUtils::CreateFontL(
       
  1357     const TDesC& aFontName,
       
  1358     TInt aFontSizeInPixels,
       
  1359     TFontStyle aFontStyle,
       
  1360     CFont*& aFont,
       
  1361     TInt& aReleaseFont )
       
  1362     {
       
  1363     CCoeEnv* coeEnv = CEikonEnv::Static();
       
  1364     if ( aFontName == KNormal || !aFontName.Length() )
       
  1365         {
       
  1366         aFont = const_cast< CFont* >( coeEnv->NormalFont() );
       
  1367         aReleaseFont = EFalse;
       
  1368         }
       
  1369     else
       
  1370         {
       
  1371         //Avkon font id used
       
  1372         TInt fontId = AvkonFontId( aFontName );
       
  1373         if ( fontId != KErrNotFound )
       
  1374             {
       
  1375             fontId += ( ( aFontSizeInPixels & 0x3ff ) << 21 ) +
       
  1376                       ( ( aFontStyle.StrokeWeight() & 0x1 ) << 4 ) +
       
  1377                       ( ( aFontStyle.Posture() & 0x1 ) << 5 ) + 0x80000000;
       
  1378             aFont = const_cast< CFont* >( AknLayoutUtils::FontFromId( fontId ));
       
  1379             aReleaseFont = EFalse;
       
  1380             }
       
  1381         else
       
  1382             {
       
  1383             //Get font
       
  1384             CBitmapDevice* dev = coeEnv->ScreenDevice();
       
  1385             TInt fontSizeInTwips = dev->VerticalPixelsToTwips( aFontSizeInPixels );
       
  1386             aFont =  AknFontAccess::GetFont(
       
  1387                 *dev, aFontStyle, fontSizeInTwips, aFontName );
       
  1388             if ( !aFont )
       
  1389                 {
       
  1390                 aFont = AknFontAccess::GetClosestFont( *dev, aFontStyle,
       
  1391                     fontSizeInTwips, aFontName );
       
  1392                 }
       
  1393             aReleaseFont = ETrue;
       
  1394             }
       
  1395         }
       
  1396     }
       
  1397 
       
  1398 // -----------------------------------------------------------------------------
       
  1399 // Collapses white spaces from the string.
       
  1400 // -----------------------------------------------------------------------------
       
  1401 //
       
  1402 EXPORT_C void CXnUtils::CollapseWhiteSpace(
       
  1403     CXnNodePluginIf& aNode,
       
  1404     TDes &aDes )
       
  1405     {
       
  1406     const TDesC8& value = GetStringProperty( aNode,
       
  1407         XnPropertyNames::appearance::common::KWhiteSpaceCollapse );
       
  1408 
       
  1409     //Collapse -default
       
  1410     if ( value == XnPropertyNames::appearance::common::whitespace::KCollapse ||
       
  1411          !value.Length() )
       
  1412         {
       
  1413         TInt src = 0;
       
  1414         TInt srclength = aDes.Length();
       
  1415         while ( src < srclength )
       
  1416             {
       
  1417             TChar c = aDes[src];
       
  1418             if ( KXnLineFeedTabCharacters().LocateF( c ) != KErrNotFound )
       
  1419                 {
       
  1420                 aDes[src] = KSpaceChar;
       
  1421                 }
       
  1422             ++src;
       
  1423             }
       
  1424         aDes.TrimAll();
       
  1425         }
       
  1426     //Preserve breaks
       
  1427     else if ( value ==
       
  1428               XnPropertyNames::appearance::common::whitespace::KPreserveBreaks )
       
  1429         {
       
  1430         TInt src = 0;
       
  1431         TInt srclength = aDes.Length();
       
  1432         while ( src < srclength )
       
  1433             {
       
  1434             TChar c = aDes[src];
       
  1435             if ( KXnTabCharacters().LocateF( c ) != KErrNotFound )
       
  1436                 {
       
  1437                 aDes[src] = KSpaceChar;
       
  1438                 }
       
  1439             ++src;
       
  1440             }
       
  1441         aDes.TrimAll();
       
  1442         }
       
  1443     //discard
       
  1444     else if ( value == XnPropertyNames::appearance::common::whitespace::KDiscard )
       
  1445         {
       
  1446         TInt target = 0;
       
  1447         TInt src = 0;
       
  1448         TInt srclength = aDes.Length();
       
  1449         while ( src < srclength )
       
  1450             {
       
  1451             aDes[target] = aDes[src];
       
  1452             TChar c = aDes[src];
       
  1453             if ( KXnCommonWhiteSpaceCharacters().LocateF( c ) == KErrNotFound )
       
  1454                 {
       
  1455                 ++target;
       
  1456                 }
       
  1457             ++src;
       
  1458             }
       
  1459         aDes.SetLength( target );
       
  1460         }
       
  1461     //Preserve
       
  1462     //Do nothing.
       
  1463     }
       
  1464 
       
  1465 // -----------------------------------------------------------------------------
       
  1466 // Resolve TextAlignment property.
       
  1467 // -----------------------------------------------------------------------------
       
  1468 //
       
  1469 EXPORT_C TGulAlignmentValue CXnUtils::TextAlignment( CXnNodePluginIf& aNode )
       
  1470     {
       
  1471     TInt value;
       
  1472 
       
  1473     const TDesC8& alignment = GetStringProperty( aNode,
       
  1474                   XnPropertyNames::appearance::common::KTextAlign );
       
  1475 
       
  1476     if ( alignment ==
       
  1477          XnPropertyNames::appearance::common::textalign::KAlignLeft )
       
  1478         {
       
  1479         value = EHLeft;
       
  1480         }
       
  1481     else if ( alignment ==
       
  1482               XnPropertyNames::appearance::common::textalign::KAlignRight )
       
  1483         {
       
  1484         value = EHRight;
       
  1485         }
       
  1486     else if ( alignment ==
       
  1487               XnPropertyNames::appearance::common::textalign::KAlignCenter )
       
  1488         {
       
  1489         value = EHCenter;
       
  1490         }
       
  1491     else if ( alignment ==
       
  1492               XnPropertyNames::appearance::common::textalign::KAlignJustify )
       
  1493         {
       
  1494         //We don't have EJustify
       
  1495         value = EHCenter;
       
  1496         }
       
  1497     else
       
  1498         {
       
  1499         if ( AknLayoutUtils::LayoutMirrored() )
       
  1500             {
       
  1501             value = EHRight;
       
  1502             }
       
  1503         else
       
  1504             {
       
  1505             value = EHLeft;
       
  1506             }
       
  1507         }
       
  1508 
       
  1509     const TDesC8& valignment = GetStringProperty( aNode,
       
  1510         XnPropertyNames::appearance::common::KS60TextVAlign );
       
  1511 
       
  1512     if ( valignment ==
       
  1513          XnPropertyNames::appearance::common::textvalign::KAlignTop )
       
  1514         {
       
  1515         value |= EVTop;
       
  1516         }
       
  1517     else if ( valignment ==
       
  1518               XnPropertyNames::appearance::common::textvalign::KAlignBottom )
       
  1519         {
       
  1520         value |= EVBottom;
       
  1521         }
       
  1522     else
       
  1523         {
       
  1524         value |= EVCenter;
       
  1525         }
       
  1526 
       
  1527     return ( TGulAlignmentValue )value;
       
  1528     }
       
  1529 
       
  1530 // -----------------------------------------------------------------------------
       
  1531 // ScaleBitmapL
       
  1532 // -----------------------------------------------------------------------------
       
  1533 //
       
  1534 EXPORT_C void CXnUtils::ScaleBitmapL(
       
  1535     const TRect& aTrgRect,
       
  1536     CFbsBitmap* aTrgBitmap,
       
  1537     CFbsBitmap* aSrcBitmap )
       
  1538     {
       
  1539     CXnUtils::ScaleBitmapExtL( aTrgRect, aTrgBitmap, aSrcBitmap, EFalse );
       
  1540     }
       
  1541 
       
  1542 // -----------------------------------------------------------------------------
       
  1543 // Strips the " and ' quotes from the string.
       
  1544 // -----------------------------------------------------------------------------
       
  1545 //
       
  1546 EXPORT_C void CXnUtils::StripQuotes( HBufC*& aString )
       
  1547     {
       
  1548     TInt pos1 = aString->Locate( '\"' );
       
  1549     TInt pos2 = aString->Locate( '\'' );
       
  1550     // check, if the first character is " or '
       
  1551     if ( pos1 == 0 || pos2 == 0 )
       
  1552         {
       
  1553         TInt len = aString->Length() - 2;
       
  1554         TPtr ptr = aString->Des();
       
  1555         TPtrC16 newString( aString->Mid( 1, len ).Ptr(), len );
       
  1556         ptr = newString;
       
  1557         }
       
  1558     }
       
  1559 
       
  1560 // -----------------------------------------------------------------------------
       
  1561 // Resolves skin id (major+minor) and index from SKIN() declaration.
       
  1562 // -----------------------------------------------------------------------------
       
  1563 //
       
  1564 EXPORT_C TBool CXnUtils::ResolveSkinItemIDL(
       
  1565     const TDesC& aSkinId,
       
  1566     TAknsItemID& aItemID,
       
  1567     TInt& aIndex )
       
  1568     {
       
  1569     HBufC* str = aSkinId.AllocL();
       
  1570     TPtr ptrSkin = str->Des();
       
  1571     ptrSkin.TrimAll();
       
  1572     TInt pos( ptrSkin.FindF( KSkin ) );
       
  1573     if ( KErrNotFound != pos )
       
  1574         {
       
  1575         TInt majorID( 0 );
       
  1576         TInt minorID( 0 );
       
  1577         pos += KSkin().Length();
       
  1578         TPtr ptr = ptrSkin.MidTPtr( pos, ( ptrSkin.Length() - pos - 1 ) );
       
  1579         ptr.TrimAll();
       
  1580         TInt offset( ptr.Locate( KSpaceChar ) );
       
  1581         if ( KErrNotFound != offset )
       
  1582             {
       
  1583             TLex lex( ptr.Left( offset ) );
       
  1584             lex.SkipSpace();
       
  1585             lex.Val( majorID ); // ok until this.
       
  1586 
       
  1587             TInt offset2( ptr.LocateReverse( KSpaceChar ) );
       
  1588             if ( offset2 == 0 || offset2 == offset )
       
  1589                 {
       
  1590                 lex.Assign( ptr.Mid( offset ) );
       
  1591                 lex.SkipSpace();
       
  1592                 lex.Val( minorID );
       
  1593                 }
       
  1594             else
       
  1595                 {
       
  1596                 TPtrC ptrDebug = ptr.Mid( offset + 1, offset2 - offset - 1 );
       
  1597                 lex.Assign( ptr.Mid( offset + 1, offset2 - offset -1 ) );
       
  1598                 lex.Val( minorID );
       
  1599 
       
  1600                 TPtrC ptrDebug2 = ptr.Mid( offset2 + 1, ptr.Length() - offset2 - 1 );
       
  1601                 lex.Assign( ptr.Mid( offset2 + 1, ptr.Length() - offset2 - 1 ) );
       
  1602                 lex.Val( aIndex );
       
  1603                 }
       
  1604             aItemID.Set( majorID, minorID );
       
  1605             delete str;
       
  1606             return ETrue;
       
  1607             }
       
  1608         }
       
  1609     delete str;
       
  1610     return EFalse;
       
  1611     }
       
  1612 
       
  1613 // -----------------------------------------------------------------------------
       
  1614 // Propagates powersave mode to adapters
       
  1615 // -----------------------------------------------------------------------------
       
  1616 //
       
  1617 EXPORT_C TBool CXnUtils::HandlePowerSaveModeL(
       
  1618     CXnNode* aNode,
       
  1619     TBool aEnter,
       
  1620     TInt aEvent )
       
  1621     {
       
  1622 
       
  1623     CXnNodeBreadthFirstIterator< CXnNode >* iterator = 
       
  1624             CXnNodeBreadthFirstIterator< CXnNode >::NewL( *aNode );
       
  1625 
       
  1626     CleanupStack::PushL( iterator );
       
  1627 
       
  1628     for ( CXnNode* currentNode = iterator->Value(); currentNode; currentNode = iterator->NextL() )
       
  1629         {
       
  1630         if ( !currentNode->ComponentNodeImpl() )
       
  1631             {
       
  1632             continue;
       
  1633             }
       
  1634 
       
  1635         CXnComponent* component = currentNode->ComponentNodeImpl()->Component();
       
  1636 
       
  1637         if ( !component )
       
  1638             {
       
  1639             continue;
       
  1640             }
       
  1641 
       
  1642         CXnControlAdapter* adapter = component->ControlAdapter();
       
  1643 
       
  1644         if ( !adapter )
       
  1645             {
       
  1646             continue;
       
  1647             }
       
  1648 
       
  1649         if ( aEnter )
       
  1650             {
       
  1651             adapter->EnterPowerSaveModeL(
       
  1652                 ( CXnControlAdapter::TModeEvent ) aEvent );
       
  1653             }
       
  1654         else
       
  1655             {
       
  1656             adapter->ExitPowerSaveModeL(
       
  1657                 ( CXnControlAdapter::TModeEvent ) aEvent );
       
  1658             }
       
  1659         }
       
  1660 
       
  1661     CleanupStack::PopAndDestroy( iterator );
       
  1662 
       
  1663     return aEnter;
       
  1664     }
       
  1665 
       
  1666 // -----------------------------------------------------------------------------
       
  1667 // Resolves skin id (major+minor) from SKIN() declaration.
       
  1668 // -----------------------------------------------------------------------------
       
  1669 //
       
  1670 TBool CXnUtils::ResolveSkinItemIDL( const TDesC& aSkinId, TAknsItemID& aItemID )
       
  1671     {
       
  1672     HBufC* str = aSkinId.AllocL();
       
  1673     TPtr ptrSkin = str->Des();
       
  1674     ptrSkin.TrimAll();
       
  1675     TInt pos( ptrSkin.FindF( KSkin ));
       
  1676     if ( KErrNotFound != pos )
       
  1677         {
       
  1678         TInt majorID( 0 );
       
  1679         TInt minorID( 0 );
       
  1680         pos += KSkin().Length();
       
  1681         TPtr ptr = ptrSkin.MidTPtr( pos, ( ptrSkin.Length() - pos - 1 ) );
       
  1682         ptr.TrimAll();
       
  1683         TInt offset( ptr.Locate( KSpaceChar ) );
       
  1684         if ( KErrNotFound != offset )
       
  1685             {
       
  1686             TLex lex( ptr.Left( offset ) );
       
  1687             lex.SkipSpace();
       
  1688             lex.Val( majorID );
       
  1689             lex.Assign( ptr.Mid( offset ) );
       
  1690             lex.SkipSpace();
       
  1691             lex.Val( minorID );
       
  1692             aItemID.Set( majorID, minorID );
       
  1693             delete str;
       
  1694             return ETrue;
       
  1695             }
       
  1696         }
       
  1697     delete str;
       
  1698     return EFalse;
       
  1699     }
       
  1700 
       
  1701 // -----------------------------------------------------------------------------
       
  1702 // -----------------------------------------------------------------------------
       
  1703 //
       
  1704 TBool CXnUtils::DoesScaleBitmapUseFallBack( CFbsBitmap* aSrcBitmap )
       
  1705     {
       
  1706     if ( !aSrcBitmap )
       
  1707         {
       
  1708         return EFalse;
       
  1709         }
       
  1710 
       
  1711     TDisplayMode displayMode = aSrcBitmap->DisplayMode();
       
  1712     TBool fallbackOnly = EFalse;
       
  1713 
       
  1714     switch ( displayMode )
       
  1715         {
       
  1716         case EGray2:
       
  1717         case EGray4:
       
  1718         case EGray16:
       
  1719         case EColor16:
       
  1720         case EColor16M:
       
  1721         case ERgb:
       
  1722         case EColor16MA:
       
  1723             fallbackOnly = ETrue;
       
  1724             break;
       
  1725         case EGray256:
       
  1726         case EColor4K:
       
  1727         case EColor64K:
       
  1728         case EColor256:
       
  1729         case EColor16MU:
       
  1730             // These are the supported modes
       
  1731             break;
       
  1732         default:
       
  1733             fallbackOnly = ETrue;
       
  1734         }
       
  1735 
       
  1736     return fallbackOnly;
       
  1737     }
       
  1738 
       
  1739 // -----------------------------------------------------------------------------
       
  1740 // -----------------------------------------------------------------------------
       
  1741 //
       
  1742 void CXnUtils::ScaleBitmapExtL( const TRect& aTrgRect, CFbsBitmap* aTrgBitmap,
       
  1743         CFbsBitmap* aSrcBitmap, TBool aForceFallBack )
       
  1744     {
       
  1745     if ( !aSrcBitmap ) User::Leave( KErrArgument );
       
  1746     if ( !aTrgBitmap ) User::Leave( KErrArgument );
       
  1747     if ( aSrcBitmap->DisplayMode() != aTrgBitmap->DisplayMode() )
       
  1748         {
       
  1749         User::Leave( KErrArgument );
       
  1750         }
       
  1751 
       
  1752     TSize trgBitmapSize = aTrgBitmap->SizeInPixels();
       
  1753 
       
  1754     // calculate the valid drawing area
       
  1755     TRect drawRect = aTrgRect;
       
  1756     drawRect.Intersection( TRect( TPoint( 0, 0 ), trgBitmapSize ) );
       
  1757 
       
  1758     if( drawRect.IsEmpty() || aSrcBitmap->SizeInPixels().iHeight <= 0 || 
       
  1759             aSrcBitmap->SizeInPixels().iWidth <= 0 )
       
  1760         {
       
  1761         return;
       
  1762         }
       
  1763 
       
  1764     TSize srcSize = aSrcBitmap->SizeInPixels();
       
  1765 
       
  1766     TBool srcTemporary = EFalse;
       
  1767     if ( aSrcBitmap->IsRomBitmap() )
       
  1768         {
       
  1769         srcTemporary = ETrue;
       
  1770         }
       
  1771 
       
  1772     TDisplayMode displayMode = aSrcBitmap->DisplayMode();
       
  1773     TBool fallbackOnly =
       
  1774         aForceFallBack ||
       
  1775         DoesScaleBitmapUseFallBack( aSrcBitmap );
       
  1776 
       
  1777     if ( fallbackOnly )
       
  1778         {
       
  1779         CFbsBitmapDevice* dev = CFbsBitmapDevice::NewL( aTrgBitmap );
       
  1780         CleanupStack::PushL( dev );
       
  1781         CFbsBitGc* gc = NULL;
       
  1782         User::LeaveIfError( dev->CreateContext( gc ) );
       
  1783         CleanupStack::PushL( gc );
       
  1784 
       
  1785         // write alpha information if it exists
       
  1786         if ( aSrcBitmap->DisplayMode() == EColor16MA )
       
  1787             {
       
  1788             gc->SetDrawMode( CGraphicsContext::EDrawModeWriteAlpha );
       
  1789             }
       
  1790 
       
  1791         // aTrgRect is used because DrawBitmap handles clipping automatically
       
  1792         gc->DrawBitmap( aTrgRect, aSrcBitmap );
       
  1793         CleanupStack::PopAndDestroy( 2 ); // dev, gc
       
  1794         return;
       
  1795         }
       
  1796 
       
  1797     // Heap lock for FBServ large chunk to prevent background
       
  1798     // compression of aSrcBitmap after if IsCompressedInRAM returns EFalse
       
  1799     aSrcBitmap->LockHeapLC( ETrue ); // fbsheaplock
       
  1800     TBool fbsHeapLock = ETrue;
       
  1801     if ( aSrcBitmap->IsCompressedInRAM() )
       
  1802         {
       
  1803         srcTemporary = ETrue;
       
  1804         }
       
  1805 
       
  1806     CFbsBitmap* realSource = aSrcBitmap;
       
  1807     if ( srcTemporary )
       
  1808         {
       
  1809         CleanupStack::PopAndDestroy(); // fbsheaplock
       
  1810         fbsHeapLock = EFalse;
       
  1811 
       
  1812         realSource = new ( ELeave ) CFbsBitmap();
       
  1813         CleanupStack::PushL( realSource );
       
  1814         User::LeaveIfError(
       
  1815             realSource->Create( srcSize, aSrcBitmap->DisplayMode() ) );
       
  1816         CFbsBitmapDevice* dev = CFbsBitmapDevice::NewL( realSource );
       
  1817         CleanupStack::PushL( dev );
       
  1818         CFbsBitGc* gc = NULL;
       
  1819         User::LeaveIfError( dev->CreateContext( gc ) );
       
  1820         CleanupStack::PushL( gc );
       
  1821         gc->BitBlt( TPoint( 0, 0 ), aSrcBitmap );
       
  1822         CleanupStack::PopAndDestroy( 2 ); // dev, gc
       
  1823         }
       
  1824 
       
  1825     if ( !fbsHeapLock )
       
  1826         {
       
  1827         // Heap lock for FBServ large chunk is only needed with large bitmaps.
       
  1828         if ( realSource->IsLargeBitmap() || aTrgBitmap->IsLargeBitmap() )
       
  1829             {
       
  1830             aTrgBitmap->LockHeapLC( ETrue ); // fbsheaplock
       
  1831             }
       
  1832         else
       
  1833             {
       
  1834             CleanupStack::PushL( ( TAny* )NULL );
       
  1835             }
       
  1836         }
       
  1837 
       
  1838     TUint32* srcAddress = realSource->DataAddress();
       
  1839     TUint32* trgAddress = aTrgBitmap->DataAddress();
       
  1840 
       
  1841     const TInt xSkip = ( srcSize.iWidth << 8 ) / aTrgRect.Width();
       
  1842     const TInt ySkip = ( srcSize.iHeight << 8 ) / aTrgRect.Height();
       
  1843 
       
  1844     const TInt drawWidth  = drawRect.Width();
       
  1845     const TInt drawHeight = drawRect.Height();
       
  1846 
       
  1847     TRect offsetRect( aTrgRect.iTl, drawRect.iTl );
       
  1848     const TInt yPosOffset = ySkip * offsetRect.Height();
       
  1849     const TInt xPosOffset = xSkip * offsetRect.Width();
       
  1850 
       
  1851     if ( ( displayMode == EGray256 ) || ( displayMode == EColor256 ) )
       
  1852         {
       
  1853         TInt srcScanLen8 = CFbsBitmap::ScanLineLength(
       
  1854             srcSize.iWidth, displayMode );
       
  1855         TInt trgScanLen8 = CFbsBitmap::ScanLineLength(
       
  1856             trgBitmapSize.iWidth, displayMode );
       
  1857 
       
  1858         TUint8* trgAddress8 = reinterpret_cast< TUint8* >( trgAddress );
       
  1859 
       
  1860         TInt yPos = yPosOffset;
       
  1861         // skip left and top margins in the beginning
       
  1862         trgAddress8 += trgScanLen8 * drawRect.iTl.iY + drawRect.iTl.iX;
       
  1863 
       
  1864         for ( TInt y = 0; y < drawHeight; y++ )
       
  1865             {
       
  1866             TUint8* srcAddress8 = reinterpret_cast< TUint8* >( srcAddress ) +
       
  1867                 ( srcScanLen8 * ( yPos >> 8 ) );
       
  1868 
       
  1869             TInt xPos = xPosOffset;
       
  1870             for ( TInt x = 0; x < drawWidth; x++ )
       
  1871                 {
       
  1872                 *( trgAddress8++ ) = srcAddress8[xPos >> 8];
       
  1873                 xPos += xSkip;
       
  1874                 }
       
  1875 
       
  1876             yPos += ySkip;
       
  1877 
       
  1878             trgAddress8 += trgScanLen8 - drawWidth;
       
  1879             }
       
  1880         }
       
  1881     else if ( displayMode == EColor4K || displayMode == EColor64K )
       
  1882         {
       
  1883         TInt srcScanLen16 = CFbsBitmap::ScanLineLength(
       
  1884             srcSize.iWidth, displayMode ) /2;
       
  1885         TInt trgScanLen16 = CFbsBitmap::ScanLineLength(
       
  1886             trgBitmapSize.iWidth, displayMode ) /2;
       
  1887 
       
  1888         TUint16* trgAddress16 = reinterpret_cast< TUint16* >( trgAddress );
       
  1889 
       
  1890         TInt yPos = yPosOffset;
       
  1891         // skip left and top margins in the beginning
       
  1892         trgAddress16 += trgScanLen16 * drawRect.iTl.iY + drawRect.iTl.iX;
       
  1893 
       
  1894         for ( TInt y = 0; y < drawHeight; y++ )
       
  1895             {
       
  1896             TUint16* srcAddress16 = reinterpret_cast< TUint16* >( srcAddress ) +
       
  1897                 ( srcScanLen16 * ( yPos >> 8 ) );
       
  1898 
       
  1899             TInt xPos = xPosOffset;
       
  1900             for ( TInt x = 0; x < drawWidth; x++ )
       
  1901                 {
       
  1902                 *( trgAddress16++ ) = srcAddress16[xPos >> 8];
       
  1903                 xPos += xSkip;
       
  1904                 }
       
  1905 
       
  1906             yPos += ySkip;
       
  1907 
       
  1908             trgAddress16 += trgScanLen16 - drawWidth;
       
  1909             }
       
  1910         }
       
  1911     else if ( displayMode == EColor16MU )
       
  1912         {
       
  1913         TInt srcScanLen32 = CFbsBitmap::ScanLineLength(
       
  1914             srcSize.iWidth, displayMode ) /4;
       
  1915         TInt trgScanLen32 = CFbsBitmap::ScanLineLength(
       
  1916             trgBitmapSize.iWidth, displayMode ) /4;
       
  1917 
       
  1918         TUint32* trgAddress32 = reinterpret_cast< TUint32* >( trgAddress );
       
  1919 
       
  1920         TInt yPos = yPosOffset;
       
  1921         // skip left and top margins in the beginning
       
  1922         trgAddress32 += trgScanLen32 * drawRect.iTl.iY + drawRect.iTl.iX;
       
  1923 
       
  1924         for ( TInt y = 0; y < drawHeight; y++ )
       
  1925             {
       
  1926             TUint32* srcAddress32 = reinterpret_cast< TUint32* >( srcAddress ) +
       
  1927                 ( srcScanLen32 * ( yPos >> 8 ) );
       
  1928 
       
  1929             TInt xPos = xPosOffset;
       
  1930             for ( TInt x = 0; x < drawWidth; x++ )
       
  1931                 {
       
  1932                 *( trgAddress32++ ) = srcAddress32[xPos >> 8];
       
  1933                 xPos += xSkip;
       
  1934                 }
       
  1935 
       
  1936             yPos += ySkip;
       
  1937 
       
  1938             trgAddress32 += trgScanLen32 - drawWidth;
       
  1939             }
       
  1940         }
       
  1941     else
       
  1942         {
       
  1943         User::Leave( KErrUnknown );
       
  1944         }
       
  1945 
       
  1946     CleanupStack::PopAndDestroy(); // fbsheaplock
       
  1947 
       
  1948     if ( srcTemporary )
       
  1949         {
       
  1950         CleanupStack::PopAndDestroy(); // realSource
       
  1951         }
       
  1952     }