uifw/AvKon/animdllinc/AknKeyEventMap.h
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2005 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 configurable key translation table class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef AKNKEYEVENTMAP_H
       
    21 #define AKNKEYEVENTMAP_H
       
    22 
       
    23 // INCLUDES
       
    24 #include <e32base.h>
       
    25 #include <w32adll.h>
       
    26 #include "AknAnimKeySound.h"
       
    27 #include "aknkeyeventmapinternal.hrh"
       
    28 #include "AknKefSubscriber.h"
       
    29 
       
    30 // DATA TYPES
       
    31 
       
    32 enum TAknPost
       
    33     {
       
    34     EAknPostRaw = 0,
       
    35     EAknPostKey = 1
       
    36     };
       
    37 
       
    38 /**
       
    39 * Flag for short key event.
       
    40 * @since Series 60 3.0
       
    41 */
       
    42 #define KAknIsShortKey 0x01
       
    43 
       
    44 /**
       
    45 * Flag for long key event.
       
    46 * @since Series 60 3.0
       
    47 */
       
    48 #define KAknIsLongKey 0x02
       
    49 
       
    50 /**
       
    51 * Flag for long key press.
       
    52 * @since Series 60 3.0
       
    53 */
       
    54 #define KAknIsLongPress 0x04
       
    55 
       
    56 /**
       
    57 * Flag for long key event only.
       
    58 * @since Series 60 3.0
       
    59 */
       
    60 #define KAknIsLongOnly 0x08
       
    61 
       
    62 /**
       
    63 * Structure encapsulating key event type.
       
    64 * @since Series 60 3.0
       
    65 */
       
    66 struct TAknKeyEvent
       
    67     {
       
    68     TUint16 iShortPress;
       
    69     TUint16 iLongPress;
       
    70     TUint8  iEventType;
       
    71     //
       
    72     // iEventType does not contain the KAknType-flags directly.  Instead
       
    73     // the necessary information is bitflagged using the KAknIs* flags, 
       
    74     // as follows:
       
    75     //
       
    76     // bit 0: 0 when Short keypress is sent as raw, 
       
    77     //        1 when it is sent as key (KAknIsShortKey)
       
    78     // bit 1: 0 when Long keypress is sent as raw, 
       
    79     //        1 when it is sent as key  (KAknIsLongKey)
       
    80     // bit 2: 0 when the scancode has no long keypresses defined 
       
    81     //        (required for combos to work) (KAknIsLongPress)
       
    82     // bit 3: 0 when the short keypress before a long one can be generated,
       
    83     //        1 when it must be delayed until press is long (KAknIsLongOnly)
       
    84     // bit 4: reserved
       
    85     // bit 5: reserved
       
    86     // bit 6: reserved
       
    87     // bit 7: reserved
       
    88     //
       
    89     // This means that the default event type (=0) is 
       
    90     // KAknTypeShort | KAknTypeRaw, with successful mappings sent out 
       
    91     // immediately on the down event.
       
    92     };
       
    93 
       
    94 /**
       
    95 * Encapsulates key event data during initialization of the key table.
       
    96 * @since Series 60 3.0
       
    97 */
       
    98 struct TAknKeyDefinition
       
    99     {
       
   100     CArrayFixFlat<TUint16>* iScanCodes;
       
   101     TUint16 iKeyCode;
       
   102     TUint16 iDeviceMode;
       
   103     TUint8 iEventType;
       
   104     };
       
   105 
       
   106 /**
       
   107 * Key Beacon contains the on-time information necessary for posting
       
   108 * out correct kind of events.
       
   109 * @since Series 60 3.0
       
   110 */
       
   111 struct TAknKeyBeacon
       
   112     {
       
   113     TUint16 iKeyCode;
       
   114     TUint8  iEventType;
       
   115     };
       
   116 
       
   117 /**
       
   118 * Structure containing repeat rate definition.
       
   119 */
       
   120 struct TAknKeyRepeatRate
       
   121     {
       
   122     TUint16 iMode;
       
   123     TUint16 iModeMask;
       
   124     TUint8 iRate;
       
   125     };
       
   126         
       
   127 // CLASS DECLARATION
       
   128 
       
   129 /**
       
   130 * CAknKeyEventMap is the main class of the Key Event Framework.
       
   131 *
       
   132 * It is responsible for configuring the keyboard mapping table(s) from
       
   133 * resource files; listening to raw events from the device; performing
       
   134 * the key translation and subsequently passing the resolved event for 
       
   135 * Window Server, which further passes it to interested clients.
       
   136 *
       
   137 * @lib AknAnimDll.lib
       
   138 * @since Series 60 3.0
       
   139 */
       
   140 NONSHARABLE_CLASS( CAknKeyEventMap )
       
   141     : public CBase,
       
   142       public MAknKefPropertyResponder
       
   143     {
       
   144     public: // Construction and destruction
       
   145 
       
   146         /**
       
   147         * Constructor.
       
   148         */
       
   149         CAknKeyEventMap(CAknAsynchTonePlayer& aAsyncTonePlayer);
       
   150 
       
   151         /**
       
   152         * 2nd phase constructor.
       
   153         * @param aFunctions pointer to interface providing general functions.
       
   154         */
       
   155         void ConstructL( MAnimGeneralFunctions* aFunctions );
       
   156 
       
   157         /**
       
   158         * Destructor.
       
   159         */
       
   160         ~CAknKeyEventMap();
       
   161 
       
   162     public: // New functions
       
   163 
       
   164         /**
       
   165         * Checks if key event map is enabled.
       
   166         * @return ETrue if enabled, EFalse otherwise.
       
   167         */
       
   168         TBool IsKeyEventMapEnabled() const;
       
   169 
       
   170         /**
       
   171         * Handles raw events.
       
   172         * @param aRawEvent the raw event from the kernel    .
       
   173         * @return ETrue if the event is consumed, EFalse otherwise.
       
   174         */
       
   175         TBool OfferRawEvent( const TRawEvent& aRawEvent );
       
   176         
       
   177         /**
       
   178         * Handles raw events.
       
   179         * @param aRawEvent the raw event from the kernel 
       
   180         * @param aSilentEvent If set, the event will not generate keysound.
       
   181         * @return ETrue if the event is consumed, EFalse otherwise.
       
   182         */
       
   183         TBool OfferRawEvent( const TRawEvent& aRawEvent, TBool aSilentEvent );        
       
   184 
       
   185     public: // Functions from base classes
       
   186     
       
   187         /**
       
   188         * From MAknKefPropertyResponder, handles changes in monitored 
       
   189         * Publish & Subscribe variables.
       
   190         *
       
   191         * @param aCategory Category of the variable that was modified.
       
   192         * @param aKey Key of the variable that was modified.
       
   193         */
       
   194         virtual void HandlePropertyChangedL( 
       
   195             const TUid& aCategory, 
       
   196             const TUint aKey );   
       
   197 
       
   198     private:
       
   199 
       
   200         /**
       
   201         * Loads a resource file and sets up the translation table.
       
   202         * @param aConfigFile Name of the configuration resource file
       
   203         */
       
   204         void InitializeKeyTableFromResourceL( 
       
   205             const TDesC& aConfigFile );
       
   206 
       
   207         /**
       
   208         * Sets the repeat rate for long key presses.
       
   209         * @param aRepeatRate repeat rate.
       
   210         */
       
   211         void SetRepeatRate( TUint8 aRepeatRate );
       
   212 
       
   213         /**
       
   214         * Sets a key mapping for scan code(s) in a given devicemode. 
       
   215         * @param aKey A struct containing all information to set up 
       
   216         *        the mapping.    
       
   217         */
       
   218         void SetKeyMappingL( const TAknKeyDefinition& aKey );
       
   219 
       
   220         /**
       
   221         * This method creates an array containing indices of all device 
       
   222         * modes (iKeyMap rows) that are affected by the processed mapping.
       
   223         * @param aModes it will contain array of modes.
       
   224         * @param aMode device mode identifier (from the resource file).
       
   225         */
       
   226         void ResolveDeviceModeL( RArray<TUint>& aModes, TUint16 aMode );
       
   227 
       
   228         /**
       
   229         * This method converts the eventtype-flags (KAknType*) used in the resource file
       
   230         * into TAknKeyEvent::iEventType.  Notice that the resource file
       
   231         * definitions are translated into KAknIs* flags.
       
   232         *
       
   233         * @param aEventType Event type indentifier (from the resource file).
       
   234         * @return event type data in a format that can be put in TAknKeyEvent.
       
   235         */
       
   236         TUint8 ResolveEventType( TUint8 aEventType );
       
   237     
       
   238         /**
       
   239         * Performs a lookup on key map to find out the correct
       
   240         * mapping for a (single) scan code in a given device mode
       
   241         * @param aScanCode The scan code that is to be looked up.
       
   242         * @param aDeviceMode The device mode for which the mapping is done.
       
   243         * @returns result of the mapping
       
   244         */
       
   245         TAknKeyBeacon GetKeyMapping( TUint16 aScanCode, TUint16 aDeviceMode );
       
   246 
       
   247         /**
       
   248         * Performs a search on combination key mapping to find out the correct
       
   249         * mapping for a combination of scan codes, if any.
       
   250         * @param aComboCandidate reference to iDownEvents.
       
   251         * @returns result of the mapping
       
   252         */
       
   253         TAknKeyBeacon GetComboMapping( RArray<TUint32>& aComboCandidate );
       
   254 
       
   255         /**
       
   256         * Resolves correct keycode for the last keypress / combo that 
       
   257         * came in / is coming in.
       
   258         * @return result of the mapping.
       
   259         */
       
   260         TAknKeyBeacon ResolveMapping();
       
   261 
       
   262         /**
       
   263         * A callback for the CPeriodic timer that tracks the length of the
       
   264         * keypress,and subsequently the amount of repeats (if any).
       
   265         *
       
   266         * @param aMyPtr a pointer to an instance of this class.
       
   267         * @return 1 if the callback should be called again, 0 otherwise.
       
   268         */
       
   269         static TInt KeyPressDuration( TAny *aMyPtr );
       
   270         
       
   271         /**
       
   272         * Helper function for posting the re-mapped event.
       
   273         *
       
   274         * @param aType type of event to send;
       
   275         *         default is TAknPost::ERaw for a raw event
       
   276         *         TAknPost::Ekey posts a key event
       
   277         */
       
   278         
       
   279         void PostEvent(TUint aType = 0);
       
   280 
       
   281         /**
       
   282         * A macro that stops the timer and resets all variables.
       
   283         */
       
   284         void CancelProcessingKeyPress();
       
   285     
       
   286     private:
       
   287     
       
   288         /**
       
   289         * This is the 'main' translation table that corresponds to a 
       
   290         * M x N matrix, where M is the number of scan codes, and N is 
       
   291         * the number of device modes.
       
   292         *
       
   293         * Each device mode is identified by a bit-encoded integer, and each
       
   294         * device mode's key mapping can be found from a separate row in 
       
   295         * iKeyMap.
       
   296         *
       
   297         * The first row, ie. iKeyMap[i][0] contains the 'Default' mode mapping.
       
   298         * If this mapping is not EKeyNull (the initial value), then it is 
       
   299         * returned regardless of what the actual device mode is, IF non-EKeyNull
       
   300         * mapping for that mode is not found.  If it is EKeyDisabled, then the 
       
   301         * raw event is consumed but nothing is passed on.
       
   302         */
       
   303         TAknKeyEvent iKeyMap[ KAknKeyMapColumns ][ KAknKeyMapRows ];
       
   304     
       
   305         /**
       
   306         * This array of arrays of integers stores combined keypresses. For 
       
   307         * each combo,  *(*iCombos)[i], there's an array whose first two
       
   308         * elements contain the key code AND the device mode this 
       
   309         * combo is active in, AND the event type (long or short keypress). 
       
   310         * Subsequent elements contain the participating scan codes.
       
   311         *
       
   312         * Information about the device mode and the event type is encoded into
       
   313         * the higher 16 bits of the keycode value.
       
   314         */
       
   315         RArray<RArray<TUint32>*>* iCombos;
       
   316     
       
   317         /**
       
   318         * Support for combined keypresses, this array accumulates down events 
       
   319         * until an up event comes and resets the array. The contents of this 
       
   320         * array are matched against each element of iCombos.
       
   321         */
       
   322         RArray<TUint32> iDownEvents;
       
   323 
       
   324         /**
       
   325         * Support for sending out raw events, this array accumulates the
       
   326         * results for mapped DOWN raw events.  Then when an UP raw event
       
   327         * is got from the keyb driver, this array is used to make sure that 
       
   328         * for every event that was sent out as raw DOWN there will 
       
   329         * also be the raw UP.
       
   330         */
       
   331         RArray<TUint32> iUpEvents;
       
   332 
       
   333         /**
       
   334         * Repeat rate definitions.
       
   335         */
       
   336         RArray< TAknKeyRepeatRate > iRepeatRates;
       
   337         
       
   338         /**
       
   339         * Contains the character value to be sent in PostKeyEvent, if any.
       
   340         * Possible values:
       
   341         *  EKeyNull: default, disables PostEvent.
       
   342         *  KAknKeyDisabled: disables PostEvent, and indicates that 
       
   343         *  the current raw event should be consumed.
       
   344         *  any other value: the key code to be sent in PostEvent().
       
   345         */
       
   346         TAknKeyBeacon iKeyBeacon;
       
   347     
       
   348         /**
       
   349         * EFalse = key, ETrue = raw
       
   350         *
       
   351         * This variable is currently OBSOLETE; i'm leaving it in nonetheless,
       
   352         * so someone remembers to add KAknTypeRepeatable and associated functionality.
       
   353         *
       
   354         */
       
   355         TBool iSendRepeats; 
       
   356 
       
   357         /**
       
   358         * Scan code of the last incoming down or up type raw event, 
       
   359         * excluding raw events generated by this class.
       
   360         */
       
   361         TUint32 iCurrentScanCode;
       
   362 
       
   363         /**
       
   364         * The device mode.  This is updated via a P&S key.
       
   365         */ 
       
   366         TUint16 iCurrentDeviceMode;
       
   367 
       
   368         /**
       
   369         * Timer for the latest incoming down type raw event    
       
   370         */
       
   371         CPeriodic* iDownTimer;
       
   372 
       
   373         /**
       
   374         * Interval to poll.
       
   375         */
       
   376         TTimeIntervalMicroSeconds32 iKeyPollInterval;
       
   377 
       
   378         /**
       
   379         * Key press duration.
       
   380         */
       
   381         TReal32 iKeyPressDuration;
       
   382         
       
   383         /**
       
   384         * Support for key presses that must not generate
       
   385         * any event until the key press type is fully resolved.
       
   386         * Currently this is used for KAknTypeLongOnly.
       
   387         */
       
   388         TAknKeyBeacon iPostMeOnUp;
       
   389 
       
   390         /**
       
   391         * Safeguard against active scheduler problems.
       
   392         */
       
   393         TBool iIsCanceled; 
       
   394 
       
   395         /**
       
   396         * ETrue when iDownTimer > KLongPressThreshold.
       
   397         */
       
   398         TBool iIsLongKeyPress;
       
   399 
       
   400         /**
       
   401         * For ignoring self-generated raw events.
       
   402         */
       
   403         TInt iScanCodeIJustGenerated;
       
   404 
       
   405         /**
       
   406         * Key repeat rate.
       
   407         */
       
   408         TUint8 iRepeatRate;
       
   409         
       
   410         /**
       
   411         * Amount of repeats.
       
   412         */
       
   413         TInt32 iRepeats;
       
   414 
       
   415         /**
       
   416         * Boolean flag indicating whether the processed event 
       
   417         * should be consumed
       
   418         */
       
   419         TBool iConsume;
       
   420     
       
   421         /**
       
   422         * Owned array of Publish & Subscribe variable monitors.
       
   423         */
       
   424         RPointerArray< CAknKefSubscriber > iKefSubscribers;
       
   425     
       
   426         /**
       
   427         * Not owned key sound session.
       
   428         */
       
   429         CAknAsynchTonePlayer& iSoundSession;
       
   430         
       
   431         // ETrue if key event map is enabled.
       
   432         TBool iKeyEventMapEnabled;
       
   433 
       
   434         // General functions for plug-ins.
       
   435         MAnimGeneralFunctions* iFunctions;
       
   436         
       
   437     };
       
   438 
       
   439 #endif // AKNKEYEVENTMAP_H
       
   440 
       
   441 // End of File