mulwidgets/common/inc/mulvisualutility.h
changeset 0 e83bab7cf002
equal deleted inserted replaced
-1:000000000000 0:e83bab7cf002
       
     1 /*
       
     2 * Copyright (c) 2007-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 class for widgets visualization in terms of LCT data
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef MULVISUALUTILITY_H_
       
    20 #define MULVISUALUTILITY_H_
       
    21 
       
    22 #include <alf/alflayout.h>
       
    23 #include <osn/ustring.h>
       
    24 
       
    25 // Avkon Includes
       
    26 #include <aknlayout2hierarchy.h>
       
    27 #include <AknUtils.h>
       
    28 #include <AknsConstants.h>
       
    29 
       
    30 // OpenC Includes
       
    31 #include <libc/string.h>
       
    32 #include <libc/stdlib.h>
       
    33 
       
    34 #include <vector>
       
    35 using namespace osncore;
       
    36 
       
    37 namespace Alf
       
    38 	{
       
    39 	    
       
    40 enum TMulCurrentOrientation
       
    41     {
       
    42     EMulPortrait,
       
    43     EMulLandScape
       
    44     };	
       
    45 /**
       
    46  * Different visual types
       
    47  */
       
    48 enum TMulLCTVisualType
       
    49     {
       
    50     EVisualImage = 0,
       
    51     EVisualText
       
    52     };
       
    53 
       
    54 /**
       
    55  * Different attribute types
       
    56  */    
       
    57 enum TMulCustomAttributeType
       
    58     {
       
    59     EAttributeNone,
       
    60     EAttributeCategory,
       
    61     EAttributeOpacity,
       
    62     EAttributeStyle,
       
    63     EAttributeFontthemecolor,
       
    64     EAttributeHAlign,
       
    65     EAttributeVAlign
       
    66     };
       
    67 
       
    68 /**
       
    69  * Different Category types
       
    70  */    
       
    71 enum TMulAttributeCategoryType
       
    72     {
       
    73     ECategoryInvalid,
       
    74     ECategoryData,
       
    75     ECategoryStaticData
       
    76     };
       
    77     
       
    78 /**
       
    79  * Co-ordinate data
       
    80  */    
       
    81 struct LCTData
       
    82 	{
       
    83 	    int mPosX;
       
    84 	    int mPosY;
       
    85 	    int mWidth;
       
    86 	    int mHeight;
       
    87 	    int mFontId;
       
    88 	};
       
    89 
       
    90 /**
       
    91  * LCT Id and variety
       
    92  */	
       
    93 struct LCTPair
       
    94     {
       
    95     UString mLctId;
       
    96     int mVariety;
       
    97     };
       
    98 
       
    99 // ---------------------------------------------------------------------------
       
   100 // Class to hold  attributes name and value
       
   101 // ---------------------------------------------------------------------------
       
   102 //
       
   103 class CustomAttributeStructure 
       
   104     {
       
   105 public:
       
   106 
       
   107    /**
       
   108 	* Constructor
       
   109 	*
       
   110 	* @param aName				Name of the Attribute
       
   111 	* @param aTargetVal			Value the Attribute
       
   112 	* @param aAttributeType		Name of the Attribute
       
   113 	* @param aCategoryType		Name of the Attribute
       
   114 	*
       
   115 	*
       
   116 	*/
       
   117     CustomAttributeStructure(const UString& aName, const UString& aTargetVal,
       
   118         TMulCustomAttributeType aAttributeType = EAttributeNone, 
       
   119         TMulAttributeCategoryType aCategoryType = ECategoryInvalid): 
       
   120             mName(aName),
       
   121             mTargetVal(aTargetVal),
       
   122             mAttributeType(aAttributeType), 
       
   123             mCategoryType(aCategoryType)
       
   124             
       
   125              {
       
   126              mLctPair.mLctId = UString("");
       
   127              mLctPair.mVariety = -1;
       
   128              } 
       
   129     
       
   130    /**
       
   131 	* Constructor
       
   132 	*
       
   133 	* @param aName				Name of the Attribute
       
   134 	* @param aLctInfo			LCT information of the custom attribute
       
   135 	* @param aAttributeType		Name of the Attribute
       
   136 	* @param aCategoryType		Name of the Attribute
       
   137 	*
       
   138 	*
       
   139 	*/
       
   140     CustomAttributeStructure(const UString& aName, const LCTPair& aLctInfo,
       
   141         TMulCustomAttributeType aAttributeType = EAttributeNone, 
       
   142         TMulAttributeCategoryType aCategoryType = ECategoryInvalid): 
       
   143             mName(aName),
       
   144             mTargetVal(""),
       
   145             mAttributeType(aAttributeType), 
       
   146             mCategoryType(aCategoryType)
       
   147             
       
   148              {
       
   149              mLctPair.mLctId = aLctInfo.mLctId;
       
   150              mLctPair.mVariety = aLctInfo.mVariety;
       
   151              }   
       
   152     
       
   153    /**
       
   154 	* Sets the name of the custom attribute
       
   155 	*
       
   156 	* @param aName	Name of the custom attribute
       
   157 	* @return nothing
       
   158 	*
       
   159 	*/         
       
   160     void SetName(const UString& aName) {mName = aName;}
       
   161     
       
   162    /**
       
   163 	* Sets the value the custom attribute
       
   164 	*
       
   165 	* @param aTarget	Value of the custom attribute
       
   166 	* @return nothing
       
   167 	*
       
   168 	*/ 
       
   169     void SetTargetValue(const UString& aTarget) {mTargetVal = aTarget; }
       
   170     
       
   171    /**
       
   172 	* Get the name of attribute
       
   173 	*
       
   174 	* 
       
   175 	* @return Name of the attribute
       
   176 	*
       
   177 	*/
       
   178     const UString GetName() const {return mName; } 
       
   179     
       
   180    /**
       
   181 	* Get the value of the attribute
       
   182 	*
       
   183 	* 
       
   184 	* @return Value of the attribute
       
   185 	*
       
   186 	*/
       
   187     const UString GetTargetvalue() const {return mTargetVal;} 
       
   188      
       
   189    /**
       
   190 	* Sets the attribute type the custom attribute
       
   191 	*
       
   192 	* @param aAttributeType		Attribute type of the custom attribute
       
   193 	* @return nothing
       
   194 	*
       
   195 	*/ 
       
   196     void SetAttributeType(TMulCustomAttributeType aAttributeType) {mAttributeType = aAttributeType;}
       
   197     
       
   198    /**
       
   199 	* Sets the Category type the custom attribute
       
   200 	*
       
   201 	* @param aCategoryType		Category type of the custom attribute
       
   202 	* @return nothing
       
   203 	*
       
   204 	*/
       
   205     void SetCategoryType(TMulAttributeCategoryType aCategoryType) {mCategoryType = aCategoryType;} 
       
   206        
       
   207    /**
       
   208 	* Get the attribute type of the attribute
       
   209 	*
       
   210 	* 
       
   211 	* @return TMulCustomAttributeType
       
   212 	*
       
   213 	*/  
       
   214     TMulCustomAttributeType AttributeType() const {return mAttributeType;}
       
   215     
       
   216    /**
       
   217 	* Get the category type of the attribute
       
   218 	*
       
   219 	* 
       
   220 	* @return TMulAttributeCategoryType
       
   221 	*
       
   222 	*/ 
       
   223     TMulAttributeCategoryType CategoryType()const {return mCategoryType;}
       
   224     
       
   225    /**
       
   226 	* Get the LCT information of attribute
       
   227 	*
       
   228 	* 
       
   229 	* @return LCTPair
       
   230 	*
       
   231 	*/ 
       
   232     const LCTPair& GetLctPair() 
       
   233     {
       
   234     return mLctPair;
       
   235     }
       
   236 
       
   237 private: 
       
   238  
       
   239    /**
       
   240 	* Attribute name
       
   241 	*/
       
   242     UString mName;
       
   243     
       
   244    /**
       
   245 	* Attribute value
       
   246 	*/
       
   247     UString mTargetVal;
       
   248     
       
   249    /**
       
   250 	* Attribute type
       
   251 	*/
       
   252     TMulCustomAttributeType mAttributeType;
       
   253     
       
   254    /**
       
   255 	* Attribute  Category type
       
   256 	*/
       
   257     TMulAttributeCategoryType mCategoryType;    
       
   258     
       
   259    /**
       
   260 	* LCT Id and variety
       
   261 	*/
       
   262     LCTPair mLctPair;
       
   263     };
       
   264     
       
   265 
       
   266 // ---------------------------------------------------------------------------
       
   267 // Class to hold a visual's attributes
       
   268 // ---------------------------------------------------------------------------
       
   269 //
       
   270 class LCTVisualStructure
       
   271     {
       
   272 public:
       
   273 	
       
   274    /**
       
   275 	* Default Constructor
       
   276 	*
       
   277 	*/
       
   278     LCTVisualStructure()
       
   279     {
       
   280     	
       
   281     }    
       
   282         
       
   283    /**
       
   284 	* Destructor
       
   285 	*
       
   286 	*/
       
   287     ~LCTVisualStructure()
       
   288     {
       
   289     for(int i =0; i < mAttributeStructure.size(); i++)
       
   290         {
       
   291         delete mAttributeStructure[i];
       
   292         }
       
   293     mAttributeStructure.clear();
       
   294     } 
       
   295         
       
   296    /**
       
   297 	* Sets the LCT Id of the visual Structure (part of LCT information of Visual Structure)
       
   298 	*
       
   299 	* @param aId	LCT Id of Visual Structure
       
   300 	* @return nothing
       
   301 	*
       
   302 	*/
       
   303     void SetLCTId(const UString& aId) {mLctPair.mLctId = aId;}
       
   304     
       
   305    /**
       
   306 	* Sets the Variety Id of the visual Structure (part of LCT information of Visual Structure)
       
   307 	*
       
   308 	* @param aId	Variety Id of Visual Structure
       
   309 	* @return nothing
       
   310 	*
       
   311 	*/
       
   312     void SetVarietyId(int aId) {mLctPair.mVariety = aId;}
       
   313     
       
   314    /**
       
   315 	* Gets the LCT Id of the visual Structure (part of LCT information of Visual Structure)
       
   316 	*
       
   317 	* @return nothing
       
   318 	*
       
   319 	*/
       
   320     const UString GetLCTId() const {return mLctPair.mLctId; } 
       
   321     
       
   322    /**
       
   323 	* Gets the Variety Id of the visual Structure (part of LCT information of Visual Structure)
       
   324 	*
       
   325 	* @return nothing
       
   326 	*
       
   327 	*/
       
   328     const int GetVarietyId() const {return mLctPair.mVariety;}
       
   329      
       
   330    /**
       
   331 	* Sets the type of visual this structure contains (can be either image/text)
       
   332 	*
       
   333 	* @param aVisualType	EVisualImage/EVisualText
       
   334 	* @return nothing
       
   335 	*
       
   336 	*/
       
   337     void SetVisualType(const TMulLCTVisualType aVisualType) {mVisualType = aVisualType; }
       
   338     
       
   339    /**
       
   340 	* Gets the visual type of the visual Structure 
       
   341 	*
       
   342 	* @return TMulLCTVisualType
       
   343 	*
       
   344 	*/
       
   345     TMulLCTVisualType VisualType()const { return mVisualType;} 
       
   346     
       
   347    /**
       
   348 	* Adds a Custom attribute structure to this visual structure
       
   349 	*
       
   350 	* @param	aAttr	Custom Attribute structure to be added
       
   351 	*					
       
   352 	*
       
   353 	*/    
       
   354     void AddAttribute(CustomAttributeStructure* aAttr)
       
   355     {
       
   356     if(aAttr)
       
   357         mAttributeStructure.push_back(aAttr);
       
   358     }
       
   359     
       
   360    /**
       
   361 	* Gets a Custom attribute structure at a specified index in this visual structure
       
   362 	*
       
   363 	* @param	aIndex	Index at which the attribute struct desired
       
   364 	* @return   CustomAttributeStructure, NULL if no attribute is found
       
   365 	*
       
   366 	*/ 
       
   367     const CustomAttributeStructure* GetAttribute(int aIndex) const
       
   368     {
       
   369     if(aIndex >=0 && aIndex < mAttributeStructure.size())
       
   370         return mAttributeStructure[aIndex];
       
   371     else
       
   372         return NULL;
       
   373     }
       
   374         
       
   375    /**
       
   376 	* Gets a Custom attribute structure by name in this visual structure
       
   377 	*
       
   378 	* @param	aAttrName	Name of the attribute struct desired
       
   379 	* @return   CustomAttributeStructure, NULL if no attribute is found
       
   380 	*					
       
   381 	*
       
   382 	*/  
       
   383     const CustomAttributeStructure* GetAttributeByName(const UString& aAttrName) const
       
   384     {
       
   385     for (vector<CustomAttributeStructure*>::const_iterator it = mAttributeStructure.begin(); 
       
   386             it!=mAttributeStructure.end(); ++it) 
       
   387     	{
       
   388     	if(!strcmp(((*it)->GetName()).getUtf8(),aAttrName.getUtf8()))
       
   389     		return *it;
       
   390     	} 
       
   391     return NULL;        
       
   392     } 
       
   393     
       
   394    /**
       
   395 	* Gets the current attribute count
       
   396 	*
       
   397 	* @return total number of attributes
       
   398 	*
       
   399 	*/
       
   400     int AttributeCount() const
       
   401     {
       
   402     return mAttributeStructure.size();
       
   403     }
       
   404 
       
   405    /**
       
   406 	* Sets the Id of the visual Structure 
       
   407 	*
       
   408 	* @param aId	Identifier of Visual Structure
       
   409 	* @return nothing
       
   410 	*
       
   411 	*/
       
   412     void SetId(const UString& aId) {mId = aId;}
       
   413     
       
   414    /**
       
   415 	* Gets the Id of the visual Structure 
       
   416 	*
       
   417 	* @return Identifier of the visual structure
       
   418 	*
       
   419 	*/   
       
   420     UString GetId() const { return mId; }
       
   421     
       
   422     void SetPositions(int x,int y)
       
   423 	    {
       
   424 	    mX = x;
       
   425 	    mY = y;
       
   426 	    }
       
   427     void SetDimensions(int width,int height)
       
   428 	    {
       
   429 	    mW = width;
       
   430 	    mH = height;
       
   431 	    }  
       
   432     int PositionX() const {return mX;}
       
   433     int PositionY() const {return mY;}
       
   434     int Width() const {return mW;}
       
   435     int Height() const {return mH;}
       
   436    /**
       
   437 	* Gets the LCT Information of the visual Structure 
       
   438 	*
       
   439 	* @return LCTPair 
       
   440 	*
       
   441 	*/   
       
   442     const LCTPair& GetLctPair() 
       
   443     {
       
   444     return mLctPair;
       
   445     }
       
   446 
       
   447         
       
   448 private:
       
   449 
       
   450    /**
       
   451 	* Class to hold  attributes name and value
       
   452 	*
       
   453 	*/
       
   454     UString mId;
       
   455      
       
   456 	/**
       
   457 	 * LCT Id and variety
       
   458 	 */ 
       
   459     LCTPair mLctPair;   
       
   460     
       
   461 	/**
       
   462  	 * Type of Visual
       
   463      */
       
   464     TMulLCTVisualType mVisualType;
       
   465     
       
   466     /**
       
   467 	* Array of attribute structures (owned)
       
   468 	*
       
   469 	*/
       
   470     std::vector<CustomAttributeStructure*> mAttributeStructure;
       
   471     int mX,mY,mW,mH;
       
   472     };
       
   473 
       
   474 // ---------------------------------------------------------------------------
       
   475 // Custom data type to hold information about different visuals
       
   476 // ---------------------------------------------------------------------------
       
   477 //
       
   478 class LCTElementStructure
       
   479     {
       
   480 public:
       
   481     
       
   482    /**
       
   483 	* Destructor
       
   484 	*
       
   485 	*/
       
   486     ~LCTElementStructure()
       
   487     {
       
   488     for(int i =0; i < mVS.size(); ++i)
       
   489         {
       
   490         delete mVS[i];            
       
   491         }
       
   492     mVS.clear(); 
       
   493     }
       
   494        
       
   495    /**
       
   496 	* Adds a Visual structure to this Element structure
       
   497 	*
       
   498 	* @param	aVStructure		VisualStructure to be added
       
   499 	* @return 	nothing				
       
   500 	*
       
   501 	*/  
       
   502     void AddVisualStructure(LCTVisualStructure* aVStructure)
       
   503     {
       
   504     if(aVStructure)
       
   505     mVS.push_back(aVStructure);
       
   506     }   
       
   507     
       
   508    /**
       
   509 	* Gets a Visual structure at a specified index in this visual structure
       
   510 	*
       
   511 	* @param	aIndex	Index at which the attribute struct desired
       
   512 	* @return   LCTVisualStructure, NULL if no structure is found
       
   513 	*
       
   514 	*/    
       
   515     const LCTVisualStructure* GetVisualStruture(int aIndex)
       
   516     {
       
   517     if(aIndex >=0 && aIndex < mVS.size())
       
   518         return mVS[aIndex];
       
   519     else
       
   520         return NULL;
       
   521     }
       
   522     
       
   523     /**
       
   524 	* Gets a Visual structure with specified name
       
   525 	*
       
   526 	* @param	aVisualName	name of the  visual structure
       
   527 	* @return   LCTVisualStructure, NULL if no structure is found
       
   528 	*
       
   529 	*/    
       
   530     const LCTVisualStructure* GetVisualStrutureByName(const UString& aVisualName) const
       
   531     {
       
   532     for (vector<LCTVisualStructure*>::const_iterator it = mVS.begin(); 
       
   533             it!=mVS.end(); ++it) 
       
   534     	{
       
   535     	if(!strcmp(((*it)->GetId()).getUtf8(),aVisualName.getUtf8()))
       
   536     		return *it;
       
   537     	} 
       
   538     //if attribute by this name is not found
       
   539     return NULL;        
       
   540     }
       
   541         
       
   542     /**
       
   543 	* Gets a Visual structure count
       
   544 	*
       
   545 	* @param	nothing
       
   546 	* @return   int visual structure count
       
   547 	*
       
   548 	*/ 
       
   549     int VisualCount()
       
   550     {
       
   551     return mVS.size();
       
   552     }
       
   553         
       
   554     /**
       
   555 	* Sets the visual structure Id
       
   556 	*
       
   557 	* @param	aId
       
   558 	* @return   nothing
       
   559 	*
       
   560 	*/ 
       
   561     void SetId(const UString& aId) {mId = aId;}
       
   562     
       
   563     /**
       
   564 	* Gets the visual structure Id
       
   565 	*
       
   566 	* @param	nothing
       
   567 	* @return   UString 
       
   568 	*
       
   569 	*/ 
       
   570     UString GetId() const { return mId; }
       
   571     
       
   572     void SetPositions(int x,int y)
       
   573 	    {
       
   574 	    mX = x;
       
   575 	    mY = y;
       
   576 	    }
       
   577     void SetDimensions(int width,int height)
       
   578 	    {
       
   579 	    mW = width;
       
   580 	    mH = height;
       
   581 	    }  
       
   582     int PositionX() const {return mX;}
       
   583     int PositionY() const {return mY;}
       
   584     int Width() const {return mW;}
       
   585     int Height() const {return mH;}
       
   586    /**
       
   587 	* Sets the LCT Id
       
   588 	*
       
   589 	* @param	aId
       
   590 	* @return   nothing
       
   591 	*
       
   592 	*/ 
       
   593     void SetLCTId(const UString& aId) {mLctPair.mLctId = aId;}
       
   594     
       
   595     /**
       
   596 	* Sets the Variety Id
       
   597 	*
       
   598 	* @param	aId
       
   599 	* @return   nothing
       
   600 	*
       
   601 	*/ 
       
   602     void SetVarietyId(int aId) {mLctPair.mVariety = aId;}
       
   603     
       
   604    /**
       
   605 	* Returns the LCT Id
       
   606 	*
       
   607 	* @param	nothing
       
   608 	* @return   UString 
       
   609 	*
       
   610 	*/ 
       
   611     const UString GetLCTId() const {return mLctPair.mLctId; }
       
   612     
       
   613     /**
       
   614 	* Returns the Variety Id
       
   615 	*
       
   616 	* @param	nothing
       
   617 	* @return   int
       
   618 	*
       
   619 	*/  
       
   620     const int GetVarietyId() const {return mLctPair.mVariety;} 
       
   621     
       
   622     /**
       
   623 	* Returns the LCT Pair structure
       
   624 	*
       
   625 	* @param	nothing
       
   626 	* @return   LCTPair
       
   627 	*
       
   628 	*/  
       
   629     const LCTPair& GetLctPair() 
       
   630     {
       
   631     return mLctPair;
       
   632     }
       
   633 
       
   634 private:
       
   635 	/**
       
   636 	 * Identifier for the element structure
       
   637 	 */
       
   638     UString mId;
       
   639     
       
   640     /**
       
   641 	 * LCT information of element
       
   642 	 */
       
   643     LCTPair mLctPair;
       
   644     
       
   645     /**
       
   646      * Array of children visual structure (owned)
       
   647      */
       
   648     vector<LCTVisualStructure*> mVS;    
       
   649     
       
   650     int mX,mY,mW,mH;
       
   651     };
       
   652 
       
   653 
       
   654 
       
   655 class MulVisualUtility
       
   656 	{
       
   657 	public:
       
   658 	    /**
       
   659 	     *  Default Constructor
       
   660 	     */
       
   661 	    OSN_IMPORT MulVisualUtility();
       
   662 	    
       
   663 	    /**
       
   664 	     * Destructor
       
   665 	     */
       
   666 	    OSN_IMPORT ~MulVisualUtility();
       
   667 	   
       
   668 	   /**
       
   669 	    * Accessor function for the LCT data
       
   670 	    * 
       
   671 	    * @return	LCTData		internal data that contains the coordinate information
       
   672 	    */
       
   673 	    OSN_IMPORT const LCTData& data() const ;
       
   674 	    
       
   675 	    /**
       
   676 	     *  Uses the passed LCTPair and populates the LCT related information
       
   677 	     *  as its internal Data.
       
   678 	     *
       
   679 	     *  @param	aPair			LCTPair to be parsed
       
   680 	     *  @param  aParentLayout	ParentLayout wit respect to which the 
       
   681 	     *							coordinate calculation has to be made
       
   682 	     *  @return nothing
       
   683 	     */
       
   684 	    OSN_IMPORT void parseLCTInfo(const LCTPair& aPair, CAlfLayout* aParentLayout= NULL);
       
   685 	     
       
   686 	    /**
       
   687 	     *  Uses the passed LCTPair and populates the LCT related information
       
   688 	     *  as its internal Data.
       
   689 	     *
       
   690 	     *  @ :: yet to implement
       
   691 	     *  @return nothing
       
   692 	     */
       
   693 	    OSN_IMPORT void parseLCTTextInfo();
       
   694 	     
       
   695 	private:
       
   696 	    /**
       
   697 	     * Internal function to concert LCT IDs into absolute data 
       
   698 	     */	
       
   699 	     void readLCTData();
       
   700 	     
       
   701 	    /**
       
   702 	     * Internal function to concert LCT IDs into absolute data for text 
       
   703 	     */	
       
   704 	     void readLCTTextData();
       
   705 	     
       
   706 	     bool isParentRelative(int aVal) const;
       
   707 	
       
   708 	private:
       
   709 	    /**
       
   710 	     * LCT data, Owned
       
   711 	     */
       
   712 	    auto_ptr <LCTData> mData;
       
   713 	    
       
   714 	    /**
       
   715 	     * LCT id
       
   716 	     */
       
   717 	     UString mLCTId;
       
   718 	     
       
   719 	    /**
       
   720 	     * Variety id
       
   721 	     */
       
   722 	     int mVarietyId;
       
   723 	};
       
   724 
       
   725 	}
       
   726  //namespace Alf
       
   727 
       
   728 #endif /*MULVISUALUTILITY_H_*/