menufw/menufwui/mmwidgets/inc/mmtemplatelibrary.h
changeset 0 f72a12da539e
child 1 5315654608de
equal deleted inserted replaced
-1:000000000000 0:f72a12da539e
       
     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.8 % << 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 current zoom so template library can retrieve the appropriate templates.
       
   292      * 
       
   293      * @since S60 v3.0
       
   294      * @param aZoom Is The current zoom to be set.
       
   295      */
       
   296 	void SetZoom( TAknUiZoom aZoom =  EAknUiZoomAutomatic );
       
   297 	
       
   298 	/**
       
   299      * Sets the scrollbar width so template library can calculate the width of the item correctly.
       
   300      * 
       
   301      * @since S60 v3.0
       
   302      * @param aScrollbarWidth The current width of the scrollbar.
       
   303      */
       
   304 	void SetScrollbarWidthL( TInt aScrollbarWidth );
       
   305 	
       
   306 	/**
       
   307 	 * Gets scrollbar width.
       
   308 	 * 
       
   309 	 * @since S60 v3.0
       
   310 	 * @return scrollbar width
       
   311 	 */
       
   312 	TInt ScrollbarWidth();
       
   313 	
       
   314 	/**
       
   315      * Gets the parent rect for given orientation from which templates were calculated.
       
   316      * 
       
   317      * @since S60 v3.0
       
   318      * @param aLandscapeOrientation The current landscape orientation.
       
   319      * @return Parent rect for given orientation.
       
   320      */
       
   321 	TRect GetParentRect( TBool aLandscapeOrientation );
       
   322 	
       
   323 private:
       
   324 	/**
       
   325 	 * Get the lookup text.
       
   326 	 * 
       
   327 	 * @since S60 v3.0
       
   328 	 * @param aTemplate The current template for the item.
       
   329 	 * @param aWidgetType The widget type.
       
   330 	 * @param aLandscapeOrientation Is view in landscape orientation. 
       
   331 	 * @param aHighlighted Is item highlighted.
       
   332 	 * 
       
   333 	 * @return Lookup text. 
       
   334 	 */
       
   335 	HBufC8* LookupText( const TDesC8& aTemplate, TMmWidgetType aWidgetType,
       
   336         TAknUiZoom aZoom, TBool aLandscapeOrientation = EFalse, 
       
   337         TBool aHighlighted = EFalse );	
       
   338     
       
   339     /**
       
   340      * Get the lookup text for layout size.
       
   341      * 
       
   342      * @since S60 v3.0
       
   343      * @param aWidgetType The widget type.
       
   344      * @param aTemplate The current template for the item.
       
   345      * @param aLandscapeOrientation Is view in landscape orientation. 
       
   346      * 
       
   347      * @return lookup layout text.
       
   348      */
       
   349 	HBufC8* LookupLayoutText( TMmWidgetType aWidgetType, TAknUiZoom aZoom, 
       
   350         const TDesC8& aTemplate, TBool aLandscapeOrientation );
       
   351     
       
   352 	/**
       
   353      * Get the lookup text for move indicator.
       
   354      * 
       
   355      * @since S60 v3.0
       
   356      * @param aLookupText The lookup text to be used to create the lookup indicator text.
       
   357      * @return lookup Indicator text.
       
   358      */
       
   359 	HBufC8* LookupIndicatorText( const TDesC8& aLookupText );
       
   360 
       
   361     /**
       
   362      * Load the template to cache.
       
   363      * 
       
   364      * @since S60 v3.0
       
   365      * @param aWidgetType The widget type.
       
   366      * @param aTemplate The current template for the item.
       
   367 	 * @param aLandscapeOrientation The current orientation.
       
   368      */
       
   369 	void LoadTemplateL( TMmWidgetType aWidgetType, const TDesC8& aTemplate, 
       
   370 			TBool aLandscapeOrientation );
       
   371 	
       
   372     /**
       
   373      * Get template file content.
       
   374      * 
       
   375      * @since S60 v3.0
       
   376      * @param aContent Descriptor to which the file content should be set.
       
   377      * @param aTemplate The current template for the item.
       
   378      * @param aWidgetType The widget type.
       
   379      * @param aMmTemplateType Type of template (LCT/custom).
       
   380      * @param aLoadCustomTemplate Value to be set depending on template type loaded (LCT/custom).
       
   381      */
       
   382 	void GetTemplateFileContentL (HBufC8*& aContent, const TDesC8& aTemplate,
       
   383 		TMmWidgetType aWidgetType, TMmTemplateType& aMmTemplateType,
       
   384 		TBool aLoadCustomTemplate = EFalse);
       
   385 		
       
   386     /**
       
   387      * Process xml element.
       
   388      * 
       
   389      * @since S60 v3.0
       
   390      * @param aMmTemplateType Type of template (LCT/custom).
       
   391      * @param aElement Element ( xml ).
       
   392      * @param aTemplate The current template for the item.
       
   393      * @param aLandscapeOrientation Is view in landscape orientation. 
       
   394      * @param aHighlighted Is item highlighted.
       
   395      * 
       
   396      */
       
   397 	void ProcessElementL (TMmTemplateType aMmTemplateType,
       
   398 		TXmlEngElement aElement, const TDesC8& aTemplate,
       
   399 		TBool aLandscapeOrientation, TBool aHighlighted);	
       
   400     
       
   401 	/**
       
   402      * Process the LCT template.
       
   403      * 
       
   404      * @since S60 v3.0
       
   405      * @param aElement Element (xml).
       
   406      * @param aTemplate The current template for the item.
       
   407      * @param aLandscapeOrientation Is view in landscape orientation. 
       
   408      * @param aHighlighted Is item highlighted.
       
   409      */
       
   410 	void ProcessLCTTemplateElementL( TXmlEngElement aElement, 
       
   411 	                                         const TDesC8& aTemplate, 
       
   412 	                                         TBool aLandscapeOrientation,
       
   413 	                                         TBool aHighlighted );
       
   414 
       
   415     /**
       
   416      * Process the custom template.
       
   417      * 
       
   418      * @since S60 v3.0
       
   419      * @param aElement Element (xml)
       
   420      * @param aTemplate The current template for the item.
       
   421      * @param aLandscapeOrientation Is view in landscape orientation. 
       
   422      * @param aHighlighted Is item highlighted.
       
   423      */
       
   424 	void ProcessCustomTemplateElementL( TXmlEngElement aElement, 
       
   425 	                                         const TDesC8& aTemplate, 
       
   426 	                                         TBool aLandscapeOrientation,
       
   427 	                                         TBool aHighlighted );
       
   428 
       
   429     /**
       
   430      * Setup LCT template data.
       
   431      * 
       
   432      * @since S60 v3.0
       
   433      * @param aChildTemplate Template where the data should be set up. 
       
   434      * @param aChildElement Element (xml).
       
   435      * @param aItemSize Item size.
       
   436      */
       
   437 	void SetupLCTTemplateL(TTemplateChild& aChildTemplate, TXmlEngElement& aChildElement, TSize aItemSize );
       
   438     
       
   439 	/**
       
   440      * Setup custom template. 
       
   441      * 
       
   442      * @since S60 v3.0
       
   443      * @param aChildTemplate Template where the data should be set up. 
       
   444      * @param aChildElement Element (xml).
       
   445      */
       
   446 	void SetupCustomTemplateL(TTemplateChild& aChildTemplate, TXmlEngElement& aChildElement );
       
   447     
       
   448 	/**
       
   449      * Set the template visual id.
       
   450      * 
       
   451      * @since S60 v3.0
       
   452      * @param aChildTemplate Template data.
       
   453      */
       
   454 	void SetupTemplateVisualId(TTemplateChild& aChildTemplate );
       
   455     
       
   456 	/**
       
   457      * Setup the item children template data for move indicator and cache the data.
       
   458      * 
       
   459      * @since S60 v3.0
       
   460      * @param aLookupString Lookup string.
       
   461      * @param aItemSize Item size.
       
   462      */
       
   463 	void SetupMoveIndicatorTemplateChildrenL( const TDesC8& aLookupString, TSize aItemSize );
       
   464     
       
   465 	/**
       
   466      * Adjusts the item size loaded to template cache according to layout size and orientation.
       
   467      * This method adjusts the item width so that items occupy the view correctly.
       
   468      * 
       
   469      * @since S60 v3.0
       
   470      * @param aSize The size of the item to be adjusted. 
       
   471      * @param aLayoutSize The layout of the widget e.g 3x4 
       
   472      * @param aLandscapeOrientation The orientation of the template being processed.
       
   473      */
       
   474 	void AdjustItemWidth( TSize& aSize, TSize aLayoutSize, TBool aLandscapeOrientation );
       
   475 
       
   476 	/**
       
   477      * Updates the parent rect according to orientation.
       
   478      * 
       
   479      * @since S60 v3.0
       
   480      * @param aParentRect The current parent rectangle.
       
   481      * @param aLandscapeOrientation The current orientation.
       
   482      */
       
   483 	void UpdateParentRect( TRect aParentRect, TBool aLandscapeOrientation );
       
   484     
       
   485 	/**
       
   486      * Sets the parent rect for given orientation.
       
   487      * 
       
   488      * @since S60 v3.0
       
   489      * @param aLandscapeOrientation Orientation for which parent rect shoul be set.
       
   490      * @param aParentRect The parent rect of current orientation.
       
   491      */
       
   492 	void SetParentRect( TBool aLandscapeOrientation, TRect aParentRect);
       
   493     
       
   494 	/**
       
   495      * Appends the edit mode template (backdrop icon) to the array of template children passed to the item drawer for drawing.
       
   496      * 
       
   497      * @since S60 v3.0
       
   498      * @param aTemplateArray The template array to which the edit mode template is appended.
       
   499      * @param aSize The size of the item for which the edit mode template should be calculated.
       
   500      */
       
   501 	void AppendEditModeTemplateL( RArray< TTemplateChild >& aTemplateArray, TSize aSize );
       
   502     
       
   503 	/**
       
   504      * Adjusts the item size according to layout, LCT item size and orientation.
       
   505      * 
       
   506      * @since S60 v3.0
       
   507      * @param aItemSize The LCT item size.
       
   508      * @param aLayoutSize The layout size to be used to calculate item size.
       
   509      * @param aLandscapeOrientation The orientation for which the template is loaded.
       
   510      */
       
   511 	void AdjustItemSize(TSize& aItemSize,  TSize aLayoutSize, TBool aLandscapeOrientation );
       
   512     
       
   513 	/**
       
   514      * Get the current zoom for displaying templates.
       
   515      * 
       
   516      * @since S60 v3.0
       
   517      * @return The current zoom.
       
   518      */
       
   519 	TAknUiZoom Zoom( );
       
   520     
       
   521 	/**
       
   522      * Caches the layout size
       
   523      * 
       
   524      * @since S60 v3.0
       
   525      * @param aLayoutSize The layout size to ba cached.
       
   526      * @param aTemplate The template for the cached layout size.
       
   527      * @param aLandscapeOrientation The orientation for which the template is loaded.
       
   528      * @return The current zoom.
       
   529      */
       
   530 	void CacheLayoutSizeL( TSize aLayoutSize, const TDesC8& aTemplate, TBool aLandscapeOrientation );
       
   531 	
       
   532 	/**
       
   533      * Adjusts icon's align to layout (left, center, right).
       
   534      * 
       
   535      * @since S60 v5.0
       
   536      * @param aParentSize The LCT parent item size.
       
   537      * @param aTemplateChild Template data.
       
   538      */
       
   539     void AdjustIconPosition(TSize aParentSize,
       
   540                     TTemplateChild& aTemplateChild);
       
   541 
       
   542 private: //Members
       
   543 
       
   544 	/**
       
   545 	 * Widget type of template being loaded.
       
   546 	 */
       
   547     TMmWidgetType iWidgetType;
       
   548     
       
   549     /**
       
   550      * Template type which is being loaded (LCT/custom).
       
   551      */
       
   552     TMmTemplateType iMmTemplateType;
       
   553     
       
   554     /**
       
   555      * Template sizes map.
       
   556      */
       
   557     RHashMap< HBufC8*, TSize> iTemplateSizesMap;
       
   558     
       
   559     /**
       
   560      * Item children template map.
       
   561      */
       
   562     RHashMap< HBufC8*, RArray<TTemplateChild> > iTemplateChildrenMap;
       
   563     
       
   564     /**
       
   565      * Move indicator rects map.
       
   566      */
       
   567     RHashMap< HBufC8*, TRect> iMoveIndicatorRectsMap;
       
   568     
       
   569     /**
       
   570      * Parent bounding rect.
       
   571      */
       
   572     TRect iParentRectPortrait;
       
   573 	
       
   574     /**
       
   575      * Parent bounding rect.
       
   576      */
       
   577     TRect iParentRectLandscape;
       
   578     
       
   579     /**
       
   580      * Scrollbar is visible.
       
   581      */
       
   582     TBool iIsScrollbarVisible;
       
   583 	
       
   584     /**
       
   585      * Scrollbar width.
       
   586      */
       
   587     TInt iScrollbarWidth;
       
   588 	
       
   589     /**
       
   590      * Zoom type.
       
   591      */
       
   592     TAknUiZoom iZoom;
       
   593 
       
   594 	};
       
   595 #endif // MMTEMPLATELIBRARY_H