javauis/lcdui_akn/javalcdui/inc/CMIDKeyTranslator.h
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2002 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 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CMIDKEYTRANSLATOR_H
       
    20 #define CMIDKEYTRANSLATOR_H
       
    21 
       
    22 #include <coecntrl.h>
       
    23 #include "lcdui.h"
       
    24 
       
    25 class CKeyList;
       
    26 
       
    27 struct TKeyRecord
       
    28 {
       
    29     enum TState
       
    30     {
       
    31         EStateInitial = 0,
       
    32         EStateDown,
       
    33         EStateDownTranslated,
       
    34         EStateKeyTranslated,
       
    35         EStateKeyRepeated,
       
    36         EStateDownRepeated,
       
    37     };
       
    38 
       
    39     TInt iScanCode;
       
    40     TInt iKeyCode;
       
    41     TInt iState;
       
    42     TBool iIsSpecialKey;
       
    43 
       
    44     void Transition(TEventCode aEventCode, TMIDKeyEvent& aMIDPKeyEvent, TInt aRepeats, TBool aS60SelectionKeyCompatibility);
       
    45     void StateInitial(TEventCode aEventCode, TMIDKeyEvent& aMIDPKeyEvent, TInt aRepeats, TBool aS60SelectionKeyCompatibility);
       
    46     void StateDown(TEventCode aEventCode, TMIDKeyEvent& aMIDPKeyEvent, TInt aRepeats);
       
    47     void StateDownTranslated(TEventCode aEventCode, TMIDKeyEvent& aMIDPKeyEvent, TInt aRepeats);
       
    48     void StateKeyTranslated(TEventCode aEventCode, TMIDKeyEvent& aMIDPKeyEvent, TInt aRepeats);
       
    49     void StateKeyRepeated(TEventCode aEventCode, TMIDKeyEvent& aMIDPKeyEvent, TInt aRepeats);
       
    50     void StateDownRepeated(TEventCode aEventCode, TMIDKeyEvent& aMIDPKeyEvent, TInt aRepeats);
       
    51     void KeyPressed(TMIDKeyEvent& aMIDKeyEvent);
       
    52     void KeyRepeated(TMIDKeyEvent& aMIDKeyEvent,TInt aRepeats);
       
    53     void KeyReleased(TMIDKeyEvent& aMIDKeyEvent);
       
    54     void SetKeyCode(TMIDKeyEvent& aMIDPKeyEvent);
       
    55 
       
    56 };
       
    57 
       
    58 /**
       
    59  * Maps EPOC key events to MIDP key codes.
       
    60  *
       
    61  *  Translates EEventKeyDown and EEventKeyUp scancodes to
       
    62  *  key codes.
       
    63  *
       
    64  *  Maps non-unicode keys to negative codes.
       
    65  *
       
    66  *  Stores Game key mappings.
       
    67  *
       
    68  */
       
    69 class CMIDKeyTranslator : public CBase
       
    70 {
       
    71 public:
       
    72     enum { KInvalidKeyCode    = 0  };
       
    73     enum { KInvalidGameAction = 0  };
       
    74     enum { KMaxGameAction     = 12 };
       
    75     enum { KMaxUnicodeKeyCode = 65535 };    // TUint16 max value
       
    76 
       
    77 public:
       
    78     CMIDKeyTranslator(MMIDEnv& aEnv);
       
    79     void ConstructL();
       
    80     ~CMIDKeyTranslator();
       
    81 
       
    82     /**
       
    83      * Utils are not available at construction time, so
       
    84      * are set later.
       
    85      */
       
    86     void    SetUtils(MMIDUtils* aUtils);
       
    87 
       
    88     /**
       
    89      * Map EPOC Key event to MIDP key code.
       
    90      *
       
    91      *@returns ETrue if key event should be posted to Java.
       
    92      */
       
    93     TBool   TranslateL(TMIDKeyEvent& aEvent, const TKeyEvent& aWsEvent, TEventCode aType);
       
    94     TBool   PostKeyEvent(MMIDComponent& aSource, const TMIDKeyEvent& aEvent);
       
    95 
       
    96     /**
       
    97      * Forgets all currently tracked keys. Used to release some memory
       
    98      * if key events will not be sent up to java. Also resets the
       
    99      * game action key state.
       
   100      */
       
   101     void    Reset();
       
   102 
       
   103 
       
   104 private:
       
   105     TInt FindKeyRecord(TInt aScanCode) const;
       
   106     TInt Map(TInt aScanCode, TInt aCode);
       
   107     /**
       
   108      * Map an invalid (non-unicode) SymbianOS keycode to a valid MIDP unicode or
       
   109      * negative keycode.
       
   110      *@param  aScanCode SymbianOS scan code.
       
   111      *@return MIDP key code
       
   112      */
       
   113     TInt    MapNonUnicodeKeyCode(TInt aScanCode);
       
   114     void    PostKeyEvent(MMIDComponent& aComponent, TEventType aType, TInt aKeyCode, TInt aRepeats);
       
   115 
       
   116 private:
       
   117     MMIDEnv&    iEnv;
       
   118     MMIDUtils*  iUtils;
       
   119     RArray<TKeyRecord>  iKeyList;
       
   120 
       
   121     TBool iS60SelectionKeyCompatibility;
       
   122 
       
   123 };
       
   124 
       
   125 #endif // CMIDKEYTRANSLATOR_H