|
1 /* |
|
2 * Copyright (c) 2002-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: EikSrv keysound map. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "eikkeysoundmap.h" |
|
19 #include <avkon.hrh> |
|
20 |
|
21 const TInt KEikKeySoundMapGranularity = 4; |
|
22 const TInt KEikSKeyGranularity = 16; |
|
23 |
|
24 // class TSkey - SKey definition |
|
25 // Keycode and Repeat are stored as a single code, to enable fast searching |
|
26 void TSKey::Set(TInt aKeyCode, TInt aRepeatType, TInt aSid) |
|
27 { |
|
28 iSid = aSid; |
|
29 iKeyCode = aKeyCode + (aRepeatType << 16); |
|
30 } |
|
31 |
|
32 // =============================== |
|
33 // CEikKeySoundMap implementation. |
|
34 // =============================== |
|
35 |
|
36 CEikKeySoundMap* CEikKeySoundMap::NewL() |
|
37 { |
|
38 CEikKeySoundMap* self = new(ELeave)CEikKeySoundMap(); |
|
39 return self; |
|
40 } |
|
41 |
|
42 CEikKeySoundMap::~CEikKeySoundMap() |
|
43 { |
|
44 } |
|
45 |
|
46 CEikKeySoundMap::CEikKeySoundMap() |
|
47 :CArrayFixFlat<TSKey>(KEikSKeyGranularity) |
|
48 { |
|
49 } |
|
50 |
|
51 void CEikKeySoundMap::InternalizeL(RReadStream& aStream, TInt aItems, TInt aUid) |
|
52 { |
|
53 for (TInt ii=0; ii<aItems; ii++) |
|
54 { |
|
55 TInt sid = aStream.ReadInt16L(); |
|
56 if (sid < 1000) |
|
57 { |
|
58 sid = (aUid << 16) + sid; |
|
59 } |
|
60 TInt key = aStream.ReadUint16L(); |
|
61 TInt type = aStream.ReadInt8L(); |
|
62 TSKey sKey; |
|
63 sKey.Set(key, type, sid); |
|
64 TKeyArrayFix sidKey(_FOFF(TSKey, iKeyCode), ECmpTInt); |
|
65 InsertIsqL(sKey, sidKey); |
|
66 } |
|
67 } |
|
68 |
|
69 TBool CEikKeySoundMap::Find(TSKey& aKey) |
|
70 { |
|
71 TKeyArrayFix sidKey(_FOFF(TSKey, iKeyCode), ECmpTInt); |
|
72 TInt index; |
|
73 if (FindIsq(aKey, sidKey, index) == 0) |
|
74 { |
|
75 aKey.iSid = At(index).iSid; |
|
76 return ETrue; |
|
77 } |
|
78 return EFalse; |
|
79 } |
|
80 |
|
81 TInt CEikKeySoundMap::ContextResourceId() |
|
82 { |
|
83 return iContextResourceId; |
|
84 } |
|
85 |
|
86 void CEikKeySoundMap::SetContextResourceId(TInt aContextResId) |
|
87 { |
|
88 iContextResourceId = aContextResId; |
|
89 } |
|
90 |
|
91 // ================================= |
|
92 // CEikKeySoundStack implementation. |
|
93 // ================================= |
|
94 |
|
95 CEikKeySoundStack* CEikKeySoundStack::NewL() |
|
96 { |
|
97 CEikKeySoundStack* self = new(ELeave)CEikKeySoundStack(); |
|
98 return self; |
|
99 } |
|
100 |
|
101 CEikKeySoundStack::~CEikKeySoundStack() |
|
102 { |
|
103 ResetAndDestroy(); |
|
104 } |
|
105 |
|
106 CEikKeySoundStack::CEikKeySoundStack() |
|
107 :CArrayPtrFlat<CEikKeySoundMap>(KEikKeySoundMapGranularity) |
|
108 { |
|
109 } |
|
110 |
|
111 TBool CEikKeySoundStack::Find(TInt aScanCode, TInt aRepeat, TInt& aSid) |
|
112 { |
|
113 TSKey key; |
|
114 // Decide on key-repeat type to check for |
|
115 if (aRepeat == 0) |
|
116 { |
|
117 key.Set(aScanCode, ESKeyTypeShort, 0); |
|
118 } |
|
119 else |
|
120 { |
|
121 if (iPreviousRepeat == 0) |
|
122 { |
|
123 key.Set(aScanCode, ESKeyTypeLong, 0); |
|
124 } |
|
125 else |
|
126 { |
|
127 key.Set(aScanCode, ESKeyTypeRepeat, 0); |
|
128 } |
|
129 } |
|
130 |
|
131 iPreviousRepeat = aRepeat; |
|
132 |
|
133 // Check in top layer |
|
134 TInt index = Count(); |
|
135 while (index) |
|
136 { |
|
137 index--; |
|
138 CEikKeySoundMap* map = At(index); |
|
139 if (map->Find(key)) |
|
140 { |
|
141 if (key.iSid == EAvkonSIDNoSound) |
|
142 return EFalse; |
|
143 else if (key.iSid == EAvkonSIDDefaultSound) |
|
144 { |
|
145 // Go direct to play default sound |
|
146 index = 1; |
|
147 continue; |
|
148 } |
|
149 else |
|
150 { |
|
151 aSid = key.iSid; |
|
152 return ETrue; |
|
153 } |
|
154 } |
|
155 } |
|
156 return EFalse; |
|
157 } |
|
158 |