mmuifw_plat/alf_widgetmodel_api/inc/alf/ialfwidgetcontrol.h
changeset 17 3eca7e70b1b8
parent 3 4526337fb576
equal deleted inserted replaced
3:4526337fb576 17:3eca7e70b1b8
     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:  The base class for all widgets.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef I_ALFWIDGETCONTROL_H
       
    20 #define I_ALFWIDGETCONTROL_H
       
    21 
       
    22 #include <osn/osntypes.h>
       
    23 #include <alf/ialfinterfacebase.h>
       
    24 #include <alf/alftypes.h>
       
    25 
       
    26 //FORWARD DECLARATION
       
    27 class TAlfEvent;
       
    28 class CAlfDisplay;
       
    29 
       
    30 namespace osncore
       
    31     {
       
    32     class UString;
       
    33     }
       
    34 using namespace osncore;
       
    35 
       
    36 namespace Alf
       
    37     {
       
    38 //FORWARD DECLARATIONS    
       
    39 class IAlfWidgetEventHandler;
       
    40 class IAlfElement;
       
    41 class AlfWidget;
       
    42 class IAlfVariantType;
       
    43 class AlfCustomInitDataBase;
       
    44  
       
    45 
       
    46 namespace alfwidgetcontrol
       
    47     {
       
    48 static const IfId ident=
       
    49     {
       
    50     0,"alfwidgetcontrol"
       
    51     };
       
    52     }
       
    53 
       
    54 /**
       
    55  *  The interface for widget controls.
       
    56  *  Widget controls are derived from Alfred controls. This is
       
    57  *  the primary interface to access the widget control functionality.
       
    58  *  Alfred control interface can be queried, but direct access should not
       
    59  *  be needed. Widget controls are responsible for the widget logic, i.e.,
       
    60  *  storing and controlling the state of the widget. This usually includes
       
    61  *  input event handling, updating the presentation, and communication with
       
    62  *  the model, the application, and other controls. Event handlers can be
       
    63  *  used to implement parts of the widget logic.
       
    64  *
       
    65  *  @lib alfwidgetmodel.lib
       
    66  *  @since S60 ?S60_version
       
    67  *  @status Draft
       
    68  */
       
    69 class IAlfWidgetControl : public IAlfInterfaceBase
       
    70     {
       
    71 public:
       
    72 
       
    73     /**
       
    74      * Defines the bitflags used with the state interfaces.
       
    75      */
       
    76 
       
    77     // Visible is set if the widget control is currently intended to be visible
       
    78     static const uint Visible = 0x0001;
       
    79 
       
    80     // Enabled is set if the widget control is to be responsive to user input
       
    81     // Note: Presentation may render this control in some way to indicate that
       
    82     // it is disabled
       
    83     static const uint Enabled = 0x0002;
       
    84     
       
    85     // Focused is set if the control is to be currently attracting key events 
       
    86     static const uint Focused = 0x0004;
       
    87     
       
    88     // Focusable is set iff the widget control is to allow focus to be put
       
    89     // on it
       
    90     static const uint Focusable = 0x0008;
       
    91 
       
    92 public:
       
    93     static inline const IfId& type()
       
    94         {
       
    95         return alfwidgetcontrol::ident;
       
    96         }
       
    97     /**
       
    98      * Virtual destructor.
       
    99      *
       
   100      * @since S60 ?S60_version
       
   101      */
       
   102     virtual ~IAlfWidgetControl() {}
       
   103 
       
   104     /**
       
   105      * Get the state of the control.
       
   106      * The state is a combination of binary state flags.
       
   107      *
       
   108      * The individual aspects of the state can be queried by testing 
       
   109      * for the bits in the return value.
       
   110      *
       
   111      * @since S60 ?S60_version
       
   112      * @return The bit-pattern encoding the state
       
   113      */
       
   114     virtual uint state() const = 0;
       
   115 
       
   116     /**
       
   117      * Sets the widget control's state.
       
   118      *
       
   119      * The entire state of the widget is set to the passed-in value. 
       
   120      * 
       
   121      * The new state must conform to the following invariants:
       
   122      *
       
   123      * If IAlfWidgetControl::Focus is set, then IAlfWidgetControl::Focusable must also be set
       
   124      * If IAlfWidgetControl::Focusable is set, then IAlfWidgetControl::Enabled must also be set
       
   125      *
       
   126      * If these invariants are violated, then this method will throw AlfException::EInvalidArgument
       
   127      *
       
   128      * @since S60 ?S60_version
       
   129      * @param aState The new state of the control.
       
   130      */
       
   131     virtual void setState( uint aState ) = 0;
       
   132 
       
   133     /**
       
   134      * Enable given states.
       
   135      *
       
   136      * This method modifies a state by enabling bits. No bits are disabled.
       
   137      * This is equal to <code>SetState( State() | aState )</code>.
       
   138      *
       
   139      * The resulting state is tested for the invariants documented with setState() 
       
   140      * and throws the same exceptions.
       
   141      *
       
   142      * @since S60 ?S60_version
       
   143      * @param aState The states to be enabled.
       
   144      */
       
   145     virtual void enableState( uint aState ) = 0;
       
   146 
       
   147     /**
       
   148      * Disable given states.
       
   149      *
       
   150      * This method modifies a state by clearing bits. No bits are set.
       
   151      * This is equal to <code>SetState( State() & ( 0xFFFFFFFF ^ aState ) )</code>.
       
   152      *
       
   153      * The resulting state is tested for the invariants documented with setState() 
       
   154      * and throws the same exceptions.
       
   155      *
       
   156      * @since S60 ?S60_version
       
   157      * @param aState The states to be disabled.
       
   158      */
       
   159     virtual void disableState( uint aState ) = 0;
       
   160 
       
   161     /**
       
   162      * Checks the current state of the widget control for a single aspect.
       
   163      * This is equal to <code>enabled = State() & aState</code>
       
   164      * 
       
   165      * The parameter passed in should usually be a single bit state aspect 
       
   166      * e.g. <code>IAlfWidgetControl::Focusable</code>
       
   167      * If a pattern with more than one bit set is passed in, the result
       
   168      * is not easily usable.
       
   169      *
       
   170      * @since S60 ?S60_version
       
   171      * @param aState a state bit pattern to test
       
   172      * @return true if and only one of the passed-in bits is set in the state
       
   173      */
       
   174     virtual bool checkState( uint aState ) const = 0;
       
   175 
       
   176     /**
       
   177      * Get the number of event handlers in the control.
       
   178      *
       
   179      * @since S60 ?S60_version
       
   180      * @return The number of event handlers.
       
   181      */
       
   182     virtual int numEventHandlers() const = 0;
       
   183 
       
   184     /**
       
   185      * Get an event handler by index.
       
   186      *
       
   187      * @since S60 ?S60_version
       
   188      * @param aIndex The index of the event handler to get.
       
   189      *
       
   190      * @return The event handler at the given index.
       
   191      */
       
   192     virtual IAlfWidgetEventHandler& eventHandler( int aIndex ) = 0;
       
   193 
       
   194     /**
       
   195      * Get the index of the given event handler.
       
   196      * The index specifies the order in which
       
   197      * the event handlers are processed.
       
   198      *
       
   199      * @since S60 ?S60_version
       
   200      * @param aEventHandler The event handler.
       
   201      *
       
   202      * @return The index of the event handler, or -1 if the event handler 
       
   203      *         does not exist.
       
   204      */
       
   205     virtual int eventHandlerIndex( 
       
   206                     IAlfWidgetEventHandler& aEventHandler ) const = 0;
       
   207 
       
   208 
       
   209     /**
       
   210      * Find an event handler responsible for the given event.
       
   211      *
       
   212      * @since S60 ?S60_version
       
   213      * @param aEvent The event.
       
   214      *
       
   215      * @return The first event handler to handle the given event, or NULL 
       
   216      *         if not found.
       
   217      */
       
   218     virtual IAlfWidgetEventHandler* findEventHandler(
       
   219                                         const TAlfEvent& aEvent ) = 0;
       
   220 
       
   221     /**
       
   222      * Add a new event handler.
       
   223      * The control takes the ownership of the event handler.
       
   224      *
       
   225      * @since S60 ?S60_version
       
   226      * @param aEventHandler The event handler to be added.
       
   227      * @param aIndex The index of the new event handler,
       
   228      *               or -1 to append the event handler after the existing
       
   229      *               event handlers.
       
   230      */
       
   231     virtual void addEventHandler(
       
   232                      IAlfWidgetEventHandler* aEventHandler,
       
   233                      int aIndex = -1 ) = 0;
       
   234 
       
   235     /**
       
   236      * Remove and destroy an event handler.
       
   237      *
       
   238      * @since S60 ?S60_version
       
   239      * @param aEventHandler The event handler to be removed and destroyed.
       
   240      */
       
   241     virtual void removeAndDestroyEventHandler(
       
   242                      IAlfWidgetEventHandler& aEventHandler ) = 0;
       
   243 
       
   244     /**
       
   245      * Remove and destroy an event handler from the control bases on its name.
       
   246      *
       
   247      * @since S60 ?S60_version
       
   248      * @param aHandlerId The name/Id of the event handler to be removed
       
   249      *                   and destroyed.
       
   250      */
       
   251     virtual void removeAndDestroyEventHandler( const UString& aHandlerId ) = 0;
       
   252    
       
   253   
       
   254     /**
       
   255      * Remove and destroy an event handler.
       
   256      *
       
   257      * @since S60 ?S60_version
       
   258      * @param aEventHandler The event handler to be removed and destroyed.
       
   259      */
       
   260     virtual void removeEventHandler(
       
   261                      IAlfWidgetEventHandler& aEventHandler ) = 0;
       
   262     
       
   263     
       
   264     /**
       
   265      * Remove and destroy all event handlers associated with presentation.
       
   266      *
       
   267      * @since S60 ?S60_version
       
   268      */
       
   269     virtual void removeAndDestroyPresentationEventHandlers() = 0;
       
   270     
       
   271     /**
       
   272      * Removes all event handlers associated with presentation from 
       
   273      * this control.
       
   274      *
       
   275      * @since S60 ?S60_version
       
   276      */ 
       
   277     virtual void removePresentationEventHandlers() = 0;
       
   278     
       
   279     /**
       
   280      * Get the number of elements in the control.
       
   281      *
       
   282      * @since S60 ?S60_version
       
   283      * @return The number of elements.
       
   284      */
       
   285     virtual int numElements() const = 0;
       
   286 
       
   287     /**
       
   288      * Get an element by index.
       
   289      *
       
   290      * @since S60 ?S60_version
       
   291      * @param aIndex The index of the element to get.
       
   292      *
       
   293      * @return The element at the given index.
       
   294      */
       
   295     virtual IAlfElement& element( int aIndex ) = 0;
       
   296 
       
   297     /**
       
   298      * Find an element by name.
       
   299      *
       
   300      * @since S60 ?S60_version
       
   301      * @param aName The name of the element to find.
       
   302      *
       
   303      * @return The found element, or NULL if not found.
       
   304      */
       
   305     virtual IAlfElement* findElement( const char* aName ) = 0;
       
   306 
       
   307     /**
       
   308      * Add a new element.
       
   309      * The control takes the ownership of the element.
       
   310      *
       
   311      * @since S60 ?S60_version
       
   312      * @param aElement The element to be added.
       
   313      */
       
   314     virtual void addElement( IAlfElement* aElement ) = 0;
       
   315 
       
   316     /**
       
   317      * Remove and destroy an element. All visuals created by the
       
   318      * element are destroyed.
       
   319      *
       
   320      * @since S60 ?S60_version
       
   321      * @param aElement The element to be removed and destroyed.
       
   322      */
       
   323     virtual void removeAndDestroyElement( const IAlfElement& aElement ) = 0;
       
   324     
       
   325     /**
       
   326      * Remove an element.
       
   327      *
       
   328      * @since S60 ?S60_version
       
   329      * @param aElement The element to be removed.
       
   330      */
       
   331     virtual void removeElement( const IAlfElement& aElement ) = 0; 
       
   332 
       
   333     /**
       
   334      * Get an id for mapping data to a visual tree created by an element.
       
   335      * The data id is required to be unique withing the scope of the element.
       
   336      * The parent data id and data id ranges specified by SetDataIdRange can
       
   337      * be used to calculate data ids in hierarchical element structures.
       
   338      * In the default implementation, the data id is calculated as follows:
       
   339      * \f[
       
   340      * data id = aParentDataId * DataIdRange( aElement ) + aIndex
       
   341      * \f]
       
   342      *
       
   343      * @since S60 ?S60_version
       
   344      * @param aElement      The element to associate the data id with.
       
   345      * @param aIndex        The index of the data field.
       
   346      * @param aParentDataId The parent data id in the data hierarchy.
       
   347      * @return A unique data id for mapping data to a visual tree.
       
   348      */
       
   349     virtual uint elementDataId(
       
   350                      const IAlfElement& aElement,
       
   351                      uint aIndex,
       
   352                      uint aParentDataId ) = 0;
       
   353 
       
   354     /**
       
   355      * Get the parent data id from the given data id.
       
   356      * In the default implementation, the parent data id is calculated 
       
   357      * as follows:
       
   358      * \f[
       
   359      * parent data id = aDataId / DataIdRange( aElement )
       
   360      * \f]
       
   361      * The implementation should match the functionality of ElementDataId().
       
   362      *
       
   363      * @since S60 ?S60_version
       
   364      * @param aElement  The element associated with the given data id.
       
   365      * @param aDataId   The data id.
       
   366      * @return The parent data id.
       
   367      */
       
   368     virtual uint parentElementDataId(
       
   369                      const IAlfElement& aElement,
       
   370                      uint aDataId ) = 0;
       
   371 
       
   372     /**
       
   373      * Get the index of the given child data id in the parent data container.
       
   374      * In the default implementation, the parent data id is calculated
       
   375      * as follows:
       
   376      * \f[
       
   377      * index = aDataId % DataIdRange( aElement )
       
   378      * \f]
       
   379      * The implementation should match the functionality of ElementDataId().
       
   380      *
       
   381      * @since S60 ?S60_version
       
   382      * @param aElement  The element associated with the given data id.
       
   383      * @param aDataId   The data id.
       
   384      * @return The parent data id.
       
   385      */
       
   386     virtual uint dataIdToIndex(
       
   387                      const IAlfElement& aElement,
       
   388                      uint aDataId ) = 0;
       
   389                      
       
   390     /**
       
   391      * Get data for a visual tree created by the given element.
       
   392      *
       
   393      * @since S60 ?S60_version
       
   394      * @param aElement  The element containing the visual tree.
       
   395      * @param aDataId   The data id of the visual tree.
       
   396      * @return Data for the visual tree.
       
   397      */
       
   398     virtual IAlfVariantType* elementData(
       
   399                                  const IAlfElement& aElement,
       
   400                                  uint aDataId ) = 0;
       
   401 
       
   402     /**
       
   403      * Set the range of data ids for an element.
       
   404      * The range is used for data mapping in ElementDataId() and ElementData().
       
   405      * The default range for all elements is 0xFFFFFFFF. The ranges need to be
       
   406      * adjusted for child elements in hierarchical element structures.
       
   407      * Otherwise,the data ids will overflow and not remain unique.
       
   408      * @see ElementDataId().
       
   409      *
       
   410      * @since S60 ?S60_version
       
   411      * @param aElement  The element.
       
   412      * @param aRange    The range of data ids.
       
   413      */
       
   414     virtual void setDataIdRange(
       
   415                      const IAlfElement& aElement,
       
   416                      uint aRange ) = 0;
       
   417 
       
   418     /**
       
   419      * Get the range of data ids for the given element.
       
   420      * The range is used for data mapping in ElementDataId() and ElementData().
       
   421      * @see SetDataIdRange().
       
   422      *
       
   423      * @since S60 ?S60_version
       
   424      * @param aElement  The element.
       
   425      * @return The range of data ids for the element.
       
   426      */
       
   427     virtual uint dataIdRange( const IAlfElement& aElement ) = 0;
       
   428 
       
   429     /**
       
   430      * Create or update the presentation for the widget.
       
   431      *
       
   432      * @since S60 ?S60_version
       
   433      */
       
   434     virtual void updatePresentation() = 0;
       
   435 
       
   436     /**
       
   437      * Remove visuals from all elements. The visuals are destroyed
       
   438      * after the given delay. This allows executing an animation
       
   439      * sequence before the actual destruction of visuals.
       
   440      *
       
   441      * @since S60 ?S60_version
       
   442      * @param aTimeMilliseconds The remaining time to destruction of 
       
   443      *                          all visuals.
       
   444      */
       
   445     virtual void destroyPresentation( int aTimeMilliseconds ) = 0;
       
   446     
       
   447     /**
       
   448      * Remove visuals from all elements and destroy all elements.
       
   449      * The visuals and elements are destroyed after the given delay.
       
   450      * This allows executing an animation sequence before the actual
       
   451      * destruction of visuals.
       
   452      *
       
   453      * @since S60 ?S60_version
       
   454      * @param aTimeMilliseconds The remaining time to destruction of 
       
   455      *                          all visuals.
       
   456      */    
       
   457     virtual void destroyVisualsAndElements( int aTimeMilliseconds = 0 ) = 0;
       
   458 
       
   459     /**
       
   460      * Get the owner widget of this control.
       
   461      *
       
   462      * @since S60 ?S60_version
       
   463      * @return The owner widget, or NULL if this control does not belong to
       
   464      *         any widget.
       
   465      */
       
   466     virtual AlfWidget* widget() = 0;
       
   467     
       
   468     /**
       
   469      * Handles events sent to widget control.
       
   470      *
       
   471      * @since S60 ?S60_version
       
   472      * @param aEvent The event to be handled.
       
   473      * @return Result of event processing. See AlfEventStatus.
       
   474      */
       
   475     virtual AlfEventStatus handleEvent( const TAlfEvent& aEvent ) = 0;
       
   476     
       
   477     };
       
   478 
       
   479 /**
       
   480  *  Placeholder for information required to instantiate a widgetcontrol
       
   481  *  via the widget factory mechanism.
       
   482  *  A pointer to this structure is casted to a void pointer and sent to the
       
   483  *  factory plugin.
       
   484  *  @lib alfwidgetmodel.lib
       
   485  *  @since S60 ?S60_version
       
   486  */
       
   487 struct AlfWidgetControlInitData
       
   488     {
       
   489 
       
   490     /**
       
   491      * Display pointer
       
   492      */
       
   493     CAlfDisplay* mDisplay;
       
   494     
       
   495     /**
       
   496      * Pointer to custom data passed via factory mechanism
       
   497      * Not Owned.
       
   498      */
       
   499     AlfCustomInitDataBase* mCustomData;  
       
   500     };
       
   501 
       
   502     } // namespace Alf
       
   503 
       
   504 #endif // I_ALFWIDGETCONTROL_H
       
   505 
       
   506 // End of File