inc/alf/alfattribute.h
branchRCL_3
changeset 19 4ea6f81c838a
parent 17 514d98f21c43
child 20 0e9bb658ef58
equal deleted inserted replaced
17:514d98f21c43 19:4ea6f81c838a
     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:  A class for attribute.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef ALFATTRIBUTE_H
       
    20 #define ALFATTRIBUTE_H
       
    21 
       
    22 //INCLUDES
       
    23 #include <osn/osndefines.h>
       
    24 #include <memory>
       
    25 #include <osn/osntypes.h>
       
    26 #include <alf/alfmetric.h>
       
    27 #include <alf/alftimedvalue.h>
       
    28 #include "alf/alfattributevaluetype.h"
       
    29 
       
    30 using namespace osncore;
       
    31 
       
    32 // FORWARD DECLARATIONS
       
    33 
       
    34 namespace osncore
       
    35     {
       
    36 class UString;
       
    37     }
       
    38 using std::auto_ptr;
       
    39 
       
    40 namespace Alf
       
    41     {
       
    42 
       
    43 class AlfAttributeImpl;
       
    44 class AlfAttributeValueType;
       
    45 
       
    46 /**
       
    47  *  @class AlfAttribute alfattribute.h "alf/alfattribute.h"
       
    48  *  Class for holding attributes. 
       
    49  *  AlfAttribute is a receptacle for holding data that can be applied to  
       
    50  *  visuals/visual templates via the attribute setters. 
       
    51  *  They can also be used hold data for properties of widgets or widget parts
       
    52  *  implement the IAlfAttributeOwner interface. 
       
    53  *  An attribute can have one or more attribute value types. 
       
    54  *  Attributes can be bunched together in attribute containers.
       
    55  *  @see IAlfAttributeSetter
       
    56  *  @see IAlfAttributeOwner
       
    57  *  @see AlfAttributeValueType
       
    58  *  @see AlfAtributeContainer
       
    59  *  @lib alfwidgetmodel.lib
       
    60  *  @since S60 ?S60_version
       
    61  *  @status Draft
       
    62  */ 
       
    63 class AlfAttribute
       
    64     {
       
    65 public:
       
    66 
       
    67     /* See Declarative Hitchcock language specification
       
    68        for more detail of attribute categories */
       
    69     enum attributecategory
       
    70         {
       
    71         EStatic,     /* static attribute */
       
    72         EDynamic,    /* dynamic attribute */
       
    73         EStaticData, /* static dataattribute  */
       
    74         EDynamicData /* dynamic dataattribute */
       
    75         };
       
    76 
       
    77     /**
       
    78      * Constructor.
       
    79      * @exception std::bad_alloc
       
    80      *
       
    81      * @since S60 ?S60_version
       
    82      */
       
    83     OSN_IMPORT AlfAttribute();
       
    84 
       
    85     /**
       
    86      * Constructor.
       
    87      * @exception std::bad_alloc
       
    88      *
       
    89      * @param aName Attribute name. Makes a copy of the name.
       
    90      * @param aCategory Attribute category.
       
    91      * @return New object.
       
    92      * @since S60 ?S60_version
       
    93      */
       
    94     OSN_IMPORT AlfAttribute(const char* aName, attributecategory aCategory);
       
    95 
       
    96     /**
       
    97      * Constructor.
       
    98      * @exception std::bad_alloc
       
    99      *
       
   100      * @param aName Attribute name. Makes a copy of the name.
       
   101      * @param aTargetValue The target value of the child attribute.
       
   102      * @param aUnit Unit of the value.
       
   103      * @param aCategory Attribute category.
       
   104      * @return New object.
       
   105      * @since S60 ?S60_version
       
   106      */
       
   107     OSN_IMPORT AlfAttribute(const char* aName, int aTargetValue,
       
   108                             TAlfUnit aUnit = EAlfUnitPixel,
       
   109                             attributecategory aCategory = EStatic);
       
   110 
       
   111     /**
       
   112      * Constructor.
       
   113      * @exception std::bad_alloc
       
   114      *
       
   115      * @param aName Attribute name. Makes a copy of the name.
       
   116      * @param aTargetValue The target value of the child attribute.
       
   117      * @param aUnit Unit of the value.
       
   118      * @param aCategory Attribute category.
       
   119      * @return New object.
       
   120      * @since S60 ?S60_version
       
   121      */
       
   122     OSN_IMPORT AlfAttribute(const char* aName, float aTargetValue,
       
   123                             TAlfUnit aUnit = EAlfUnitNormalized,
       
   124                             attributecategory aCategory = EStatic);
       
   125 
       
   126     /**
       
   127      * Constructor.
       
   128      * @exception std::bad_alloc
       
   129      *
       
   130      * @param aName Attribute name. Makes a copy of the name.
       
   131      * @param aTargetValue The target value of the child attribute. Makes a copy of the value.
       
   132      * @param aCategory Attribute category.
       
   133      * @return New object.
       
   134      * @since S60 ?S60_version
       
   135      */
       
   136     OSN_IMPORT AlfAttribute(const char* aName, const UString& aTargetValue,
       
   137                             attributecategory aCategory = EStatic);
       
   138 
       
   139     /**
       
   140      * Destructor.
       
   141      */
       
   142     OSN_IMPORT virtual ~AlfAttribute();
       
   143 
       
   144     /**
       
   145      * Assignment operation. Assigns all the member variables
       
   146      * to the values in the reference attribute.
       
   147      * @exception std::bad_alloc
       
   148      *
       
   149      * @param aAttribute The source attribute.
       
   150      * @return Reference to the attribute.
       
   151      * @since S60 ?S60_version
       
   152      */
       
   153     OSN_IMPORT AlfAttribute& operator=(const AlfAttribute& aAttribute);
       
   154 
       
   155     /**
       
   156      * Clones the attribute.
       
   157      * @exception std::bad_alloc
       
   158      *
       
   159      * @return The cloned attribute. Ownership is transferred to the caller.
       
   160      * @since S60 ?S60_version
       
   161      */
       
   162     OSN_IMPORT AlfAttribute* clone();
       
   163 
       
   164     /**
       
   165      * Gets the name of the attribute.
       
   166      *
       
   167      * @return The name of the attribute.
       
   168      * @since S60 ?S60_version
       
   169      */
       
   170     OSN_IMPORT const char* name() const;
       
   171 
       
   172     /**
       
   173      * Gets the category of the attribute.
       
   174      *
       
   175      * @return The category of the attribute.
       
   176      * @since S60 ?S60_version
       
   177      */
       
   178     OSN_IMPORT attributecategory category() const;
       
   179 
       
   180     /**
       
   181      * Gets the type of the attribute.
       
   182      * @exception osncore::AlfAttributeException Thrown with error code osncore::EInvalidAttribute if aIndex is invalid. 
       
   183      *
       
   184      * @return The type of the attribute target value.
       
   185      * @since S60 ?S60_version
       
   186      */
       
   187     OSN_IMPORT AlfAttributeValueType::Type type(unsigned int aIndex = 0) const;
       
   188 
       
   189     /**
       
   190      * Gets the int target value. Use this method only if the attribute type is EInt.
       
   191      * @exception osncore::AlfAttributeException Thrown with error code osncore::EInvalidAttribute if aIndex is invalid. 
       
   192      * @param aIndex The index of the attribute value.
       
   193      * @return The integer value of the attribute.
       
   194      * @since S60 ?S60_version
       
   195      */
       
   196     OSN_IMPORT int intValue(unsigned int aIndex = 0) const;
       
   197 
       
   198     /**
       
   199      * Gets the real target value. Use this method only if the attribute type is EFloat.
       
   200      * @exception osncore::AlfAttributeException Thrown with error code osncore::EInvalidAttribute if aIndex is invalid. 
       
   201      *
       
   202      * @param aIndex The index of the attribute value.
       
   203      * @return The float value of the attribute.
       
   204      * @since S60 ?S60_version
       
   205      */
       
   206     OSN_IMPORT float realValue(unsigned int aIndex = 0) const;
       
   207 
       
   208     /**
       
   209      * Gets the string target value. Use this method only if the attribute type is EString.
       
   210      * @exception osncore::AlfAttributeException Thrown with error code osncore::EInvalidAttribute if aIndex is invalid. 
       
   211      *
       
   212      * @param aIndex The index of the attribute value.
       
   213      * @return The string value of the attribute.
       
   214      * @since S60 ?S60_version
       
   215      */
       
   216     OSN_IMPORT const UString& stringValue(unsigned int aIndex = 0) const;
       
   217 
       
   218     /**
       
   219      * Returns true if the attribute value is set.
       
   220      *
       
   221      * @return The value state.
       
   222      * @since S60 ?S60_version
       
   223      */
       
   224     OSN_IMPORT bool isValueSet() const;
       
   225 
       
   226     /**
       
   227      * Gets the unit of the value.
       
   228      * @exception osncore::AlfAttributeException Thrown with error code osncore::EInvalidAttribute if aIndex is invalid. 
       
   229      *
       
   230      * @param aIndex The index of the attribute value.
       
   231      * @return The unit.
       
   232      * @since S60 ?S60_version
       
   233      */
       
   234     OSN_IMPORT virtual TAlfUnit unit(unsigned int aIndex = 0) const;
       
   235 
       
   236     /**
       
   237      * Adds a new target value to the attribute.
       
   238      *
       
   239      * @param aValue New value to be added.
       
   240      * @since S60 ?S60_version
       
   241      */
       
   242     OSN_IMPORT void addTargetValue(AlfAttributeValueType* aValue);
       
   243 
       
   244     /**
       
   245      * Gets target value count.
       
   246      * @exception osncore::AlfAttributeException Thrown with error code osncore::EInvalidAttribute if aIndex is invalid. 
       
   247      *
       
   248      * @return Value count.
       
   249      * @since S60 ?S60_version
       
   250      */
       
   251     OSN_IMPORT unsigned int getTargetValueCount() const;
       
   252 
       
   253     /**
       
   254      * Sets the target value of the attribute.
       
   255      *
       
   256      * @param aIndex The index of the attribute value.
       
   257      * @param aValue The target value of the attribute.
       
   258      * @since S60 ?S60_version
       
   259      */
       
   260     OSN_IMPORT void setTargetValue(AlfAttributeValueType* aValue,
       
   261                                    unsigned int aIndex = 0);
       
   262 
       
   263     /**
       
   264      * Gets the target value of the attribute.
       
   265      *
       
   266      * @param aIndex The index of the attribute value.
       
   267      * @return The target value of the attribute.
       
   268      * @since S60 ?S60_version
       
   269      */
       
   270     OSN_IMPORT AlfAttributeValueType* getTargetValue(
       
   271         unsigned int aIndex = 0) const;
       
   272 
       
   273     /**
       
   274      * Removes the target value of the attribute.
       
   275      * @exception osncore::AlfAttributeException Thrown with error code osncore::EInvalidAttribute if aIndex is invalid. 
       
   276      *
       
   277      * @param aIndex The index of the attribute value.
       
   278      * @since S60 ?S60_version
       
   279      */
       
   280     OSN_IMPORT void removeTargetValue(unsigned int aIndex = 0);
       
   281 
       
   282     /**
       
   283      * Adds a new source value to the attribute.
       
   284      *
       
   285      * @param aValue New value to be added.
       
   286      * @since S60 ?S60_version
       
   287      */
       
   288     OSN_IMPORT void addSourceValue(AlfAttributeValueType* aValue);
       
   289 
       
   290     /**
       
   291      * Gets source value count.
       
   292      * @exception osncore::AlfAttributeException Thrown with error code osncore::EInvalidAttribute if aIndex is invalid. 
       
   293      *
       
   294      * @return The source value count.
       
   295      * @since S60 ?S60_version
       
   296      */
       
   297     OSN_IMPORT unsigned int getSourceValueCount() const;
       
   298 
       
   299     /**
       
   300      * Sets the source value of the attribute.
       
   301      *
       
   302      * @param aIndex The index of the attribute value.
       
   303      * @param aValue The source value of the attribute.
       
   304      * @since S60 ?S60_version
       
   305      */
       
   306     OSN_IMPORT void setSourceValue(AlfAttributeValueType* aValue,
       
   307                                    unsigned int aIndex = 0);
       
   308 
       
   309     /**
       
   310      * Gets the source value of the attribute.
       
   311      *
       
   312      * @param aIndex The index of the attribute value.
       
   313      * @return The source value of the attribute.
       
   314      * @since S60 ?S60_version
       
   315      */
       
   316     OSN_IMPORT AlfAttributeValueType* getSourceValue(
       
   317         unsigned int aIndex = 0) const;
       
   318 
       
   319     /**
       
   320      * Removes the source value of the attribute.
       
   321      * @exception osncore::AlfAttributeException Thrown with error code osncore::EInvalidAttribute if aIndex is invalid. 
       
   322      *
       
   323      * @param aIndex The index of the attribute value.
       
   324      * @since S60 ?S60_version
       
   325      */
       
   326     OSN_IMPORT void removeSourceValue(unsigned int aIndex = 0);
       
   327 
       
   328     /**
       
   329      * Sets the interpolation style of the attribute.
       
   330      *
       
   331      * @param aInterpolationStyle The interpolation style.
       
   332      * @since S60 ?S60_version
       
   333      */
       
   334     OSN_IMPORT void setInterpolationStyle(TAlfInterpolationStyle aInterpolationStyle);
       
   335 
       
   336     /**
       
   337      * Gets the interpolation style of the attribute.
       
   338      *
       
   339      * @return The interpolation style of the attribute.
       
   340      * @since S60 ?S60_version
       
   341      */
       
   342     OSN_IMPORT TAlfInterpolationStyle getInterpolationStyle() const;
       
   343 
       
   344     /**
       
   345      * Sets the transition time for the attribute.
       
   346      *
       
   347      * @param aTime The transition time for the attribute.
       
   348      * @since S60 ?S60_version
       
   349      */
       
   350     OSN_IMPORT void setTime(int aTime);
       
   351 
       
   352     /**
       
   353      * Gets the transition time for the attribute.
       
   354      *
       
   355      * @return The transition time for the attribute.
       
   356      */
       
   357     OSN_IMPORT int getTime() const;
       
   358 
       
   359     /**
       
   360      * Sets the mapping function id for the attribute.
       
   361      *
       
   362      * @param aId The mapping function id for the attribute.
       
   363      * @since S60 ?S60_version
       
   364      */
       
   365     OSN_IMPORT void setMappingFunctionId(int aId);
       
   366 
       
   367     /**
       
   368      * Gets the mapping function id for the attribute.
       
   369      *
       
   370      * @return The mapping function id for the attribute.
       
   371      * @since S60 ?S60_version
       
   372      */
       
   373     OSN_IMPORT int getMappingFunctionId() const;
       
   374 
       
   375     /**
       
   376      * Sets the datafield for the attribute.
       
   377      *
       
   378      * @param aDataField The datafield for the attribute.
       
   379      * @since S60 ?S60_version
       
   380      */
       
   381     OSN_IMPORT void setDataField(const char* aDataField);
       
   382 
       
   383     /**
       
   384      * Gets the datafield for the attribute.
       
   385      *
       
   386      * @return The datafield for the attribute.
       
   387      * @since S60 ?S60_version
       
   388      */
       
   389     OSN_IMPORT const char* getDataField() const;
       
   390 
       
   391     /**
       
   392      * Sets the delay before the transition.
       
   393      *
       
   394      * @param aDelay The delay before the transition.
       
   395      * @since S60 ?S60_version
       
   396      */
       
   397     OSN_IMPORT void setDelay(int aDelay);
       
   398 
       
   399     /**
       
   400      * Gets the delay before the transition.
       
   401      *
       
   402      * @return The delay before the transition.
       
   403      * @since S60 ?S60_version
       
   404      */
       
   405     OSN_IMPORT int getDelay() const;
       
   406 
       
   407     /**
       
   408      * Gets the dirty information
       
   409      *
       
   410      * @return whether dirty or not
       
   411      * @since S60 ?S60_version
       
   412      */
       
   413     OSN_IMPORT bool isDirty( ) const;
       
   414 
       
   415     /**
       
   416      * Sets the dirty information
       
   417      *
       
   418      * @param flag indicates whether remove or set dirtiness
       
   419      * @since S60 ?S60_version
       
   420      */
       
   421     OSN_IMPORT void setDirty(bool aFlag );
       
   422 
       
   423 private:
       
   424 
       
   425     /**
       
   426     * Resets the data.
       
   427     *
       
   428      * @param aName Attribute name.
       
   429      * @param aValue The value of the attribute.
       
   430      * @param aCategory Attribute category.
       
   431      * @since S60 ?S60_version
       
   432     */
       
   433     void reset(const char* aName, AlfAttributeValueType* aValue,
       
   434                attributecategory aCategory);
       
   435 
       
   436     /**
       
   437      * Declaring private copy construction to prevent usage.
       
   438      *
       
   439      * @param aAttribute The attribute.
       
   440      * @since S60 ?S60_version
       
   441      */
       
   442     AlfAttribute(const AlfAttribute& attribute);
       
   443 
       
   444     /**
       
   445      * Helper function for cloning value type.
       
   446      * @exception std::bad_alloc
       
   447      *
       
   448      * @param aValue The source attribute value.
       
   449      * @since S60 ?S60_version
       
   450      */
       
   451     AlfAttributeValueType* cloneValueType(AlfAttributeValueType* aValue) const;
       
   452 
       
   453 private:    // data
       
   454 
       
   455     // Implementation data
       
   456     auto_ptr<AlfAttributeImpl> mData;
       
   457     };
       
   458 
       
   459     } // namespace Alf
       
   460 
       
   461 #endif //ALFATTRIBUTE_H