menufw/menufwui/mmwidgets/inc/mmtemplatelibrary.h
branchv5backport
changeset 14 1abc632eb502
parent 13 6205fd287e8a
child 20 636d517f67e6
equal deleted inserted replaced
13:6205fd287e8a 14:1abc632eb502
     1 /*
       
     2 * Copyright (c) 2007 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:
       
    15 *  Version     : %version: MM_24.1.9 % << Don't touch! Updated by Synergy at check-out.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #ifndef MMTEMPLATELIBRARY_H
       
    21 #define MMTEMPLATELIBRARY_H
       
    22 
       
    23 // INCLUDES
       
    24 #include <e32std.h>
       
    25 #include <e32base.h>
       
    26 #include <e32hashtab.h> //RHashMap
       
    27 #include <avkon.hrh>
       
    28 #include <xmlengdom.h>
       
    29 #include <gdi.h>
       
    30 #include <eiksbfrm.h>
       
    31 #include <AknLayout2Def.h>
       
    32 #include "mmwidgetsconstants.h"
       
    33 #include <AknDef.hrh>
       
    34 
       
    35 // default templates
       
    36 // grid
       
    37 _LIT8( KDefaultGridLogicalTemplate, "logical_template_3" );
       
    38 // list
       
    39 _LIT8( KDefaultListLogicalTemplate, "list_single_hc_apps_pane" );
       
    40 
       
    41 
       
    42 // STRUCT DECLARATION
       
    43 
       
    44 /**
       
    45  *  Struct used to store template child data
       
    46  *
       
    47  * @since S60 v5.0
       
    48  * @ingroup group_mmwidgets
       
    49  */
       
    50 class TTemplateChild
       
    51     {
       
    52 
       
    53 public:
       
    54 
       
    55     /**
       
    56      * Rectangle of subcell according to position in item.
       
    57      */
       
    58     TRect iRectAccordingToParent;
       
    59 
       
    60     /**
       
    61      * Data type represented by the subcell.
       
    62      */
       
    63     TBufC8<64> iData;
       
    64 
       
    65     /**
       
    66      * The LCT template used to calculate the subcell position.
       
    67      */
       
    68     TBufC8<64> iLct;
       
    69 
       
    70     /**
       
    71      * The variety for the lct template.
       
    72      */
       
    73     TInt iVariety;
       
    74 
       
    75     /**
       
    76      * Depicts if the subcell is an image or text.
       
    77      */
       
    78     TBool iIsImage;
       
    79 
       
    80     /**
       
    81      * The font id used for displaying text.
       
    82      */
       
    83     TAknLogicalFontId iFontId;
       
    84 
       
    85     /**
       
    86      * The type of align for the text.
       
    87      */
       
    88     CGraphicsContext::TTextAlign  iTextAlign;
       
    89 
       
    90     /**
       
    91      * The additional Id for a subcell element used to differentiate it
       
    92      * from others. e.g the backdrop image has a different visual id
       
    93      * since it is displayed only in edit mode.
       
    94      */
       
    95     TImageVisualId iImageVisualId;
       
    96 
       
    97     /**
       
    98      * The type of horizontal align for the icon.
       
    99      */
       
   100     TManualAlign iHAlign;
       
   101 
       
   102     };
       
   103 
       
   104 // CLASS DECLARATION
       
   105 
       
   106 /**
       
   107  *  Used by Multimedia Menu to load template data.
       
   108  *
       
   109  *  @code
       
   110  *  @endcode
       
   111  *  @lib mmwidgets
       
   112  *  @since S60 v3.0
       
   113  *  @ingroup group_mmwidgets
       
   114  */
       
   115 NONSHARABLE_CLASS( CMmTemplateLibrary ) : public CBase
       
   116 	{
       
   117 public:
       
   118 	// Constructors and destructor
       
   119 
       
   120     /**
       
   121      * Destructor.
       
   122      */
       
   123     ~CMmTemplateLibrary();
       
   124 
       
   125 	/**
       
   126 	 * Two-phased constructor.
       
   127 	 */
       
   128 	IMPORT_C static CMmTemplateLibrary* NewL();
       
   129 
       
   130 	/**
       
   131      * Two-phased constructor.
       
   132      */
       
   133 	IMPORT_C static CMmTemplateLibrary* NewLC();
       
   134 
       
   135 private:
       
   136 
       
   137 	/**
       
   138 	 * Constructor for performing 1st stage construction.
       
   139 	 */
       
   140 	CMmTemplateLibrary();
       
   141 
       
   142 	/**
       
   143 	 * Default symbian 2nd stage constructor.
       
   144 	 */
       
   145 	void ConstructL();
       
   146 
       
   147 public:
       
   148 
       
   149 	/**
       
   150 	 * Gets the size of template item according to highlight and orientation.
       
   151 	 *
       
   152 	 * @since S60 v3.0
       
   153 	 * @param aWidgetType The widget type.
       
   154 	 * @param aTemplate The current template for the item.
       
   155 	 * @param aLandscapeOrientation Is view in landscape orientation.
       
   156 	 * @param aHighlighted Is item highlighted.
       
   157 	 * @param aParentRect The bounding rect in which the item is drawn.
       
   158 	 *
       
   159 	 * @return size of item
       
   160 	 */
       
   161 	TSize GetSize( TMmWidgetType aWidgetType, const TDesC8& aTemplate,
       
   162 			TBool aLandscapeOrientation = 0, TBool aHighlighted = 0,
       
   163 			TRect aParentRect = TRect() );
       
   164 
       
   165     /**
       
   166      * Gets the size of template.
       
   167      *
       
   168      * @since S60 v3.0
       
   169      * @param aItemSize Item size to be set.
       
   170      * @param aWidgetType The widget type.
       
   171 	 * @param aTemplate The current template for the item.
       
   172 	 * @param aLandscapeOrientation Is view in landscape orientation.
       
   173 	 * @param aHighlighted Is item highlighted.
       
   174 	 * @param aParentRect The bounding rect in which the item is drawn.
       
   175 	 *
       
   176      * @return error code
       
   177      */
       
   178 	TInt GetSize(  TSize& aItemSize, TMmWidgetType aWidgetType,
       
   179 	        const TDesC8& aTemplate, TBool aLandscapeOrientation,
       
   180 	        TBool aHighlighted , TRect aParentRect = TRect() );
       
   181 
       
   182     /**
       
   183      * Get array of templates for subcells ( item children ).
       
   184      *
       
   185      * @since S60 v3.0
       
   186      * @param aWidgetType The widget type.
       
   187      * @param aArray The array of subcell children to be set.
       
   188      * @param aTemplate The current template for the item.
       
   189      * @param aLandscapeOrientation Is view in landscape orientation.
       
   190      * @param aHighlighted Is item highlighted.
       
   191      * @param aIsEditMode Is in edit mode.
       
   192      *
       
   193      */
       
   194 	void GetChildrenL( TMmWidgetType aWidgetType,
       
   195 			RArray< TTemplateChild >& aArray, const TDesC8& aTemplate,
       
   196 			TBool aLandscapeOrientation = 0, TBool aHighlighted = 0, TBool aIsEditMode = 0 );
       
   197 
       
   198     /**
       
   199      * Get the layout size ( Grid ) e.g. 3x4
       
   200      *
       
   201      * @since S60 v3.0
       
   202      * @param aWidgetType The widget type.
       
   203      * @param aTemplate The current template for the item.
       
   204      * @param aLandscapeOrientation Is view in landscape orientation.
       
   205      *
       
   206      * @return the size of the layout.
       
   207      */
       
   208 	TSize GetLayoutSizeL( TMmWidgetType aWidgetType, const TDesC8& aTemplate,
       
   209 			TBool aLandscapeOrientation );
       
   210 
       
   211     /**
       
   212      * Get rect of move indicator according to item (as reference position).
       
   213      * The rect is relevant to the item in point (0,0).
       
   214      * e.g for item size 20x360 the rect can be (-5,-5):(365,25).
       
   215      *
       
   216      * @since S60 v3.0
       
   217      * @param aWidgetType The widget type.
       
   218      * @param aTemplate The current template for the item.
       
   219      * @param aLandscapeOrientation Is view in landscape orientation.
       
   220      * @param aHighlighted Is item highlighted.
       
   221      *
       
   222      * @return rect of move indicator area.
       
   223      */
       
   224 	TRect GetMoveIndicatorRect( TMmWidgetType aWidgetType, const TDesC8& aTemplate,
       
   225 			TBool aLandscapeOrientation, TBool aHighlighted );
       
   226 
       
   227     /**
       
   228      * Get children templates for move indicator.
       
   229      *
       
   230      * @since S60 v3.0
       
   231      * @param aWidgetType The widget type.
       
   232      * @param aArray Array of children templates.
       
   233      * @param aTemplate The current template for the item.
       
   234      * @param aLandscapeOrientation Is view in landscape orientation.
       
   235      * @param aHighlighted Is item highlighted.
       
   236      *
       
   237      */
       
   238 	void GetMoveIndicatorChildrenL( TMmWidgetType aWidgetType,
       
   239 			RArray< TTemplateChild >& aArray, const TDesC8& aTemplate, TBool aLandscapeOrientation, TBool aHighlighted );
       
   240 
       
   241     /**
       
   242      * Get size of item for LCT template.
       
   243      *
       
   244      * @since S60 v3.0
       
   245      * @param aLCTTemplate The LCT template name.
       
   246      * @param aVariety The variety for aLCTTemplate.
       
   247      * @param aWindowLayout The window layout to be used to calculet the size.
       
   248      * @param aLandscapeOrientation ETrue if view in landscape orientation otherwise EFalse.
       
   249      *
       
   250      * @return item size
       
   251      */
       
   252 	TSize GetLCTSize( const TDesC8& aLCTTemplate, TInt aVariety, TAknWindowLineLayout& aWindowLayout, TBool aLandscapeOrientation );
       
   253 
       
   254     /**
       
   255      * Clean the cache
       
   256      *
       
   257      * @since S60 v3.0
       
   258      */
       
   259 	void CleanAndClearCache( );
       
   260 
       
   261     /**
       
   262      * The template content is loaded. LCT templates have highest priority.
       
   263      * If there is no LCT template, a custom template is loaded.
       
   264      *
       
   265      * @since S60 v3.0
       
   266      * @param aTemplate The current template for the item.
       
   267      * @param aWidgetType The widget type.
       
   268      * @param aMmTemplateType Type of template (LCT/custom).
       
   269      *
       
   270      * @return Template content.
       
   271      */
       
   272 	HBufC8* GetTemplateContentL( const TDesC8& aTemplate, TMmWidgetType aWidgetType, TMmTemplateType& aMmTemplateType );
       
   273 
       
   274     /**
       
   275      * Sets scrollbar visibility so template library is aware.
       
   276      *
       
   277      * @since S60 v3.0
       
   278      * @param aIsScrollbarVisible Is scrollbar visible.
       
   279      */
       
   280     void SetScrollbarVisibilityL( TBool aIsScrollbarVisible );
       
   281 
       
   282     /**
       
   283      * Gets scrollbar visibility.
       
   284      *
       
   285      * @since S60 v3.0
       
   286      * @return Is scrollbar visible.
       
   287      */
       
   288     TBool GetScrollbarVisibility();
       
   289 
       
   290 	/**
       
   291      * Sets the scrollbar width so template library can calculate the width of the item correctly.
       
   292      *
       
   293      * @since S60 v3.0
       
   294      * @param aScrollbarWidth The current width of the scrollbar.
       
   295      */
       
   296 	void SetScrollbarWidthL( TInt aScrollbarWidth );
       
   297 
       
   298 	/**
       
   299 	 * Gets scrollbar width.
       
   300 	 *
       
   301 	 * @since S60 v3.0
       
   302 	 * @return scrollbar width
       
   303 	 */
       
   304 	TInt ScrollbarWidth();
       
   305 
       
   306 	/**
       
   307      * Gets the parent rect for given orientation from which templates were calculated.
       
   308      *
       
   309      * @since S60 v3.0
       
   310      * @param aLandscapeOrientation The current landscape orientation.
       
   311      * @return Parent rect for given orientation.
       
   312      */
       
   313 	TRect GetParentRect( TBool aLandscapeOrientation );
       
   314 
       
   315 private:
       
   316 	/**
       
   317 	 * Get the lookup text.
       
   318 	 *
       
   319 	 * @since S60 v3.0
       
   320 	 * @param aTemplate The current template for the item.
       
   321 	 * @param aWidgetType The widget type.
       
   322 	 * @param aLandscapeOrientation Is view in landscape orientation.
       
   323 	 * @param aHighlighted Is item highlighted.
       
   324 	 *
       
   325 	 * @return Lookup text.
       
   326 	 */
       
   327 	HBufC8* LookupText( const TDesC8& aTemplate, TMmWidgetType aWidgetType,
       
   328                         TBool aLandscapeOrientation = EFalse,
       
   329                         TBool aHighlighted = EFalse );
       
   330 
       
   331     /**
       
   332      * Get the lookup text for layout size.
       
   333      *
       
   334      * @since S60 v3.0
       
   335      * @param aWidgetType The widget type.
       
   336      * @param aTemplate The current template for the item.
       
   337      * @param aLandscapeOrientation Is view in landscape orientation.
       
   338      *
       
   339      * @return lookup layout text.
       
   340      */
       
   341 	HBufC8* LookupLayoutText( TMmWidgetType aWidgetType,
       
   342                               const TDesC8& aTemplate,
       
   343                               TBool aLandscapeOrientation );
       
   344 
       
   345 	/**
       
   346      * Get the lookup text for move indicator.
       
   347      *
       
   348      * @since S60 v3.0
       
   349      * @param aLookupText The lookup text to be used to create the lookup indicator text.
       
   350      * @return lookup Indicator text.
       
   351      */
       
   352 	HBufC8* LookupIndicatorText( const TDesC8& aLookupText );
       
   353 
       
   354     /**
       
   355      * Load the template to cache.
       
   356      *
       
   357      * @since S60 v3.0
       
   358      * @param aWidgetType The widget type.
       
   359      * @param aTemplate The current template for the item.
       
   360 	 * @param aLandscapeOrientation The current orientation.
       
   361      */
       
   362 	void LoadTemplateL( TMmWidgetType aWidgetType, const TDesC8& aTemplate,
       
   363 			TBool aLandscapeOrientation );
       
   364 
       
   365     /**
       
   366      * Get template file content.
       
   367      *
       
   368      * @since S60 v3.0
       
   369      * @param aContent Descriptor to which the file content should be set.
       
   370      * @param aTemplate The current template for the item.
       
   371      * @param aWidgetType The widget type.
       
   372      * @param aMmTemplateType Type of template (LCT/custom).
       
   373      * @param aLoadCustomTemplate Value to be set depending on template type loaded (LCT/custom).
       
   374      */
       
   375 	void GetTemplateFileContentL (HBufC8*& aContent, const TDesC8& aTemplate,
       
   376 		TMmWidgetType aWidgetType, TMmTemplateType& aMmTemplateType,
       
   377 		TBool aLoadCustomTemplate = EFalse);
       
   378 
       
   379     /**
       
   380      * Process xml element.
       
   381      *
       
   382      * @since S60 v3.0
       
   383      * @param aMmTemplateType Type of template (LCT/custom).
       
   384      * @param aElement Element ( xml ).
       
   385      * @param aTemplate The current template for the item.
       
   386      * @param aLandscapeOrientation Is view in landscape orientation.
       
   387      * @param aHighlighted Is item highlighted.
       
   388      *
       
   389      */
       
   390 	void ProcessElementL (TMmTemplateType aMmTemplateType,
       
   391 		TXmlEngElement aElement, const TDesC8& aTemplate,
       
   392 		TBool aLandscapeOrientation, TBool aHighlighted);
       
   393 
       
   394 	/**
       
   395      * Process the LCT template.
       
   396      *
       
   397      * @since S60 v3.0
       
   398      * @param aElement Element (xml).
       
   399      * @param aTemplate The current template for the item.
       
   400      * @param aLandscapeOrientation Is view in landscape orientation.
       
   401      * @param aHighlighted Is item highlighted.
       
   402      */
       
   403 	void ProcessLCTTemplateElementL( TXmlEngElement aElement,
       
   404 	                                         const TDesC8& aTemplate,
       
   405 	                                         TBool aLandscapeOrientation,
       
   406 	                                         TBool aHighlighted );
       
   407 
       
   408     /**
       
   409      * Process the custom template.
       
   410      *
       
   411      * @since S60 v3.0
       
   412      * @param aElement Element (xml)
       
   413      * @param aTemplate The current template for the item.
       
   414      * @param aLandscapeOrientation Is view in landscape orientation.
       
   415      * @param aHighlighted Is item highlighted.
       
   416      */
       
   417 	void ProcessCustomTemplateElementL( TXmlEngElement aElement,
       
   418 	                                         const TDesC8& aTemplate,
       
   419 	                                         TBool aLandscapeOrientation,
       
   420 	                                         TBool aHighlighted );
       
   421 
       
   422     /**
       
   423      * Setup LCT template data.
       
   424      *
       
   425      * @since S60 v3.0
       
   426      * @param aChildTemplate Template where the data should be set up.
       
   427      * @param aChildElement Element (xml).
       
   428      * @param aItemSize Item size.
       
   429      */
       
   430 	void SetupLCTTemplateL(TTemplateChild& aChildTemplate, TXmlEngElement& aChildElement, TSize aItemSize );
       
   431 
       
   432 	/**
       
   433      * Setup custom template.
       
   434      *
       
   435      * @since S60 v3.0
       
   436      * @param aChildTemplate Template where the data should be set up.
       
   437      * @param aChildElement Element (xml).
       
   438      */
       
   439 	void SetupCustomTemplateL(TTemplateChild& aChildTemplate, TXmlEngElement& aChildElement );
       
   440 
       
   441 	/**
       
   442      * Set the template visual id.
       
   443      *
       
   444      * @since S60 v3.0
       
   445      * @param aChildTemplate Template data.
       
   446      */
       
   447 	void SetupTemplateVisualId(TTemplateChild& aChildTemplate );
       
   448 
       
   449 	/**
       
   450      * Setup the item children template data for move indicator and cache the data.
       
   451      *
       
   452      * @since S60 v3.0
       
   453      * @param aLookupString Lookup string.
       
   454      * @param aItemSize Item size.
       
   455      */
       
   456 	void SetupMoveIndicatorTemplateChildrenL( const TDesC8& aLookupString, TSize aItemSize );
       
   457 
       
   458 	/**
       
   459      * Adjusts the item size loaded to template cache according to layout size and orientation.
       
   460      * This method adjusts the item width so that items occupy the view correctly.
       
   461      *
       
   462      * @since S60 v3.0
       
   463      * @param aSize The size of the item to be adjusted.
       
   464      * @param aLayoutSize The layout of the widget e.g 3x4
       
   465      * @param aLandscapeOrientation The orientation of the template being processed.
       
   466      */
       
   467 	void AdjustItemWidth( TSize& aSize, TSize aLayoutSize, TBool aLandscapeOrientation );
       
   468 
       
   469 	/**
       
   470      * Updates the parent rect according to orientation.
       
   471      *
       
   472      * @since S60 v3.0
       
   473      * @param aParentRect The current parent rectangle.
       
   474      * @param aLandscapeOrientation The current orientation.
       
   475      */
       
   476 	void UpdateParentRect( TRect aParentRect, TBool aLandscapeOrientation );
       
   477 
       
   478 	/**
       
   479      * Sets the parent rect for given orientation.
       
   480      *
       
   481      * @since S60 v3.0
       
   482      * @param aLandscapeOrientation Orientation for which parent rect shoul be set.
       
   483      * @param aParentRect The parent rect of current orientation.
       
   484      */
       
   485 	void SetParentRect( TBool aLandscapeOrientation, TRect aParentRect);
       
   486 
       
   487 	/**
       
   488      * Appends the edit mode template (backdrop icon) to the array of template children passed to the item drawer for drawing.
       
   489      *
       
   490      * @since S60 v3.0
       
   491      * @param aTemplateArray The template array to which the edit mode template is appended.
       
   492      * @param aSize The size of the item for which the edit mode template should be calculated.
       
   493      */
       
   494 	void AppendEditModeTemplateL( RArray< TTemplateChild >& aTemplateArray, TSize aSize );
       
   495 
       
   496 	/**
       
   497      * Adjusts the item size according to layout, LCT item size and orientation.
       
   498      *
       
   499      * @since S60 v3.0
       
   500      * @param aItemSize The LCT item size.
       
   501      * @param aLayoutSize The layout size to be used to calculate item size.
       
   502      * @param aLandscapeOrientation The orientation for which the template is loaded.
       
   503      */
       
   504 	void AdjustItemSize(TSize& aItemSize,  TSize aLayoutSize, TBool aLandscapeOrientation );
       
   505 
       
   506 	/**
       
   507      * Caches the layout size
       
   508      *
       
   509      * @since S60 v3.0
       
   510      * @param aLayoutSize The layout size to ba cached.
       
   511      * @param aTemplate The template for the cached layout size.
       
   512      * @param aLandscapeOrientation The orientation for which the template is loaded.
       
   513      */
       
   514 	void CacheLayoutSizeL( TSize aLayoutSize, const TDesC8& aTemplate, TBool aLandscapeOrientation );
       
   515 
       
   516 	/**
       
   517      * Adjusts icon's align to layout (left, center, right).
       
   518      *
       
   519      * @since S60 v5.0
       
   520      * @param aParentSize The LCT parent item size.
       
   521      * @param aTemplateChild Template data.
       
   522      */
       
   523     void AdjustIconPosition(TSize aParentSize,
       
   524                     TTemplateChild& aTemplateChild);
       
   525 
       
   526 private: //Members
       
   527 
       
   528 	/**
       
   529 	 * Widget type of template being loaded.
       
   530 	 */
       
   531     TMmWidgetType iWidgetType;
       
   532 
       
   533     /**
       
   534      * Template type which is being loaded (LCT/custom).
       
   535      */
       
   536     TMmTemplateType iMmTemplateType;
       
   537 
       
   538     /**
       
   539      * Template sizes map.
       
   540      */
       
   541     RHashMap< HBufC8*, TSize> iTemplateSizesMap;
       
   542 
       
   543     /**
       
   544      * Item children template map.
       
   545      */
       
   546     RHashMap< HBufC8*, RArray<TTemplateChild> > iTemplateChildrenMap;
       
   547 
       
   548     /**
       
   549      * Move indicator rects map.
       
   550      */
       
   551     RHashMap< HBufC8*, TRect> iMoveIndicatorRectsMap;
       
   552 
       
   553     /**
       
   554      * Parent bounding rect.
       
   555      */
       
   556     TRect iParentRectPortrait;
       
   557 
       
   558     /**
       
   559      * Parent bounding rect.
       
   560      */
       
   561     TRect iParentRectLandscape;
       
   562 
       
   563     /**
       
   564      * Scrollbar is visible.
       
   565      */
       
   566     TBool iIsScrollbarVisible;
       
   567 
       
   568     /**
       
   569      * Scrollbar width.
       
   570      */
       
   571     TInt iScrollbarWidth;
       
   572 
       
   573 	};
       
   574 #endif // MMTEMPLATELIBRARY_H