uifw/EikStd/coctlsrc/EIKHKEYT.CPP
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 1997-1999 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 #include <eikhkeyt.h>
       
    20 #include <eikpanic.h>
       
    21 #include <coemain.h>
       
    22 #include <barsread.h>
       
    23 
       
    24 EXPORT_C CEikHotKeyTable::CEikHotKeyTable()
       
    25     : CArrayFixFlat<SEikHotKey> (4) // granularity of 4
       
    26     {
       
    27     }
       
    28 
       
    29 EXPORT_C CEikHotKeyTable::~CEikHotKeyTable()
       
    30     {
       
    31     }
       
    32 
       
    33 EXPORT_C TBool CEikHotKeyTable::HotKeyFromCommandId(TInt aCommandId,TInt& aKeycode,TInt& aModifiers) const
       
    34     {
       
    35     if (Count())
       
    36         {
       
    37         TInt i=0;
       
    38         const SEikHotKey* hotKey=&(*this)[0];
       
    39         while (i++<Count())
       
    40             {
       
    41             if (hotKey->iCommandId==aCommandId)
       
    42                 {
       
    43                 if (i<=iNumberPlain)
       
    44                     {
       
    45                     aKeycode=hotKey->iKeycode;
       
    46                     aModifiers=0;
       
    47                     }
       
    48                 else
       
    49                     {
       
    50                     aKeycode=hotKey->iKeycode-('a'-1);
       
    51                     if (i>iNumberPlain+iNumberCtrl)
       
    52                         aModifiers=EModifierShift|EModifierCtrl;
       
    53                     else
       
    54                         aModifiers=EModifierCtrl;
       
    55                     }
       
    56                 return(ETrue);
       
    57                 }
       
    58             hotKey++;
       
    59             }
       
    60         }
       
    61     return(EFalse);
       
    62     }
       
    63 
       
    64 EXPORT_C TInt CEikHotKeyTable::CommandIdFromHotKey(TInt aKeycode,TInt aModifiers) const
       
    65     {
       
    66 	if (aModifiers&EModifierPureKeycode && aModifiers&EModifierCtrl)
       
    67 		return 0;
       
    68     TInt start=0;
       
    69     TInt count=0;
       
    70     if (!aModifiers || aModifiers==EModifierShift)
       
    71         count=iNumberPlain;
       
    72     else
       
    73         {
       
    74         aKeycode+='a'-1;
       
    75         if (aModifiers==EModifierCtrl)
       
    76             {
       
    77             start=iNumberPlain;
       
    78             count=iNumberCtrl;
       
    79             }
       
    80         else if (aModifiers==(EModifierShift|EModifierCtrl))
       
    81             {
       
    82             start=iNumberPlain+iNumberCtrl;
       
    83             count=iNumberShiftCtrl;
       
    84             }
       
    85         }
       
    86     if (count && Count())
       
    87         {
       
    88         const SEikHotKey* hotKey=&(*this)[start];
       
    89         while (count--)
       
    90             {
       
    91             if (hotKey->iKeycode==aKeycode)
       
    92                 return(hotKey->iCommandId);
       
    93             hotKey++;
       
    94             }
       
    95         }
       
    96     return(0);
       
    97     }
       
    98 
       
    99 EXPORT_C void CEikHotKeyTable::AddItemL(TInt aCommandId,TInt aKeycode,TInt aModifiers)
       
   100     {
       
   101     TInt pos=0;
       
   102     TInt* pNumber=&iNumberPlain;
       
   103     switch (aModifiers)
       
   104         {
       
   105     case 0:
       
   106         break;
       
   107     case EModifierCtrl:
       
   108         pos=iNumberPlain;
       
   109         pNumber=&iNumberCtrl;
       
   110         break;
       
   111     case (EModifierShift|EModifierCtrl):
       
   112         pos=iNumberPlain+iNumberCtrl;
       
   113         pNumber=&iNumberShiftCtrl;
       
   114         break;
       
   115     default:
       
   116         User::Leave(KErrNotSupported);
       
   117         }
       
   118     SEikHotKey hotKey;
       
   119     hotKey.iCommandId=aCommandId;
       
   120     hotKey.iKeycode=aKeycode;
       
   121     InsertL(pos+*pNumber,hotKey);
       
   122     (*pNumber)++; // after the InsertL succeeds
       
   123     }
       
   124 
       
   125 EXPORT_C void CEikHotKeyTable::RemoveItem(TInt aCommandId)
       
   126     {
       
   127     TInt i=0;
       
   128     FOREVER
       
   129         {
       
   130         if (i==Count())
       
   131             Panic(EEikPanicNoHotKeyToRemove);
       
   132         SEikHotKey& hotKey=(*this)[i];
       
   133         if (hotKey.iCommandId==aCommandId)
       
   134             {
       
   135             if (i<iNumberPlain)
       
   136                 iNumberPlain--;
       
   137             else if (i<iNumberPlain+iNumberCtrl)
       
   138                 iNumberCtrl--;
       
   139             else
       
   140                 iNumberShiftCtrl--;
       
   141             break;
       
   142             }
       
   143         i++;
       
   144         }
       
   145     Delete(i);
       
   146     }
       
   147 
       
   148 EXPORT_C void CEikHotKeyTable::ConstructFromResourceL(TInt aResourceId)
       
   149     {
       
   150     TResourceReader reader;
       
   151     CCoeEnv::Static()->CreateResourceReaderLC(reader,aResourceId);
       
   152     iNumberPlain=reader.ReadInt16();
       
   153     if (iNumberPlain)
       
   154         {
       
   155 	    const SEikHotKey* ptr=(const SEikHotKey*)reader.Ptr();
       
   156 	    reader.Advance(iNumberPlain*sizeof(SEikHotKey));
       
   157 	    AppendL(ptr,iNumberPlain);
       
   158         }
       
   159     iNumberCtrl=reader.ReadInt16();
       
   160     if (iNumberCtrl)
       
   161         {
       
   162 	    const SEikHotKey* ptr=(const SEikHotKey*)reader.Ptr();
       
   163 	    reader.Advance(iNumberCtrl*sizeof(SEikHotKey));
       
   164 	    AppendL(ptr,iNumberCtrl);
       
   165         }
       
   166     iNumberShiftCtrl=reader.ReadInt16();
       
   167     if (iNumberShiftCtrl)
       
   168         {
       
   169 	    const SEikHotKey* ptr=(const SEikHotKey*)reader.Ptr();
       
   170 	    reader.Advance(iNumberShiftCtrl*sizeof(SEikHotKey));
       
   171 	    AppendL(ptr,iNumberShiftCtrl);
       
   172         }
       
   173     CleanupStack::PopAndDestroy();
       
   174     }
       
   175 
       
   176 EXPORT_C void CEikHotKeyTable::Reset()
       
   177     {
       
   178 	iNumberPlain=iNumberCtrl=iNumberShiftCtrl=0;
       
   179     CArrayFixFlat<SEikHotKey>::Reset();
       
   180     }