|
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: Sound Map |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // AKNSOUNDMAP.CPP |
|
20 // |
|
21 // Copyright (c) 1997-2000 Symbian Ltd. All rights reserved. |
|
22 // |
|
23 |
|
24 // AknSoundMap - maps a set of keys to SID's |
|
25 |
|
26 |
|
27 #include "AknSoundMap.h" |
|
28 #include <avkon.hrh> |
|
29 |
|
30 |
|
31 const TInt KAknKeySoundMapGranularity = 4; |
|
32 const TInt KAknSKeyGranularity = 16; |
|
33 |
|
34 // class TSkey - SKey definition |
|
35 // Keycode and Repeat are stored as a single code, to enable fast searching |
|
36 void TSKey::Set(TInt aKeyCode, TInt aRepeatType, TInt aSid) |
|
37 { |
|
38 iSid = aSid; |
|
39 iKeyCode = aKeyCode + (aRepeatType << 16); |
|
40 } |
|
41 |
|
42 |
|
43 CAknKeySoundMap* CAknKeySoundMap::NewL() |
|
44 { |
|
45 CAknKeySoundMap* self = new(ELeave)CAknKeySoundMap(); |
|
46 return self; |
|
47 } |
|
48 |
|
49 CAknKeySoundMap::~CAknKeySoundMap() |
|
50 { |
|
51 } |
|
52 |
|
53 CAknKeySoundMap::CAknKeySoundMap() |
|
54 :CArrayFixFlat<TSKey>(KAknSKeyGranularity) |
|
55 { |
|
56 } |
|
57 |
|
58 |
|
59 void CAknKeySoundMap::ConstructFromResourceL(TResourceReader& aReader) |
|
60 { |
|
61 TInt count = aReader.ReadInt16(); |
|
62 for (TInt ii=0; ii<count; ii++) |
|
63 { |
|
64 TInt sid = aReader.ReadInt16(); |
|
65 TInt key = aReader.ReadUint16(); |
|
66 TInt type = aReader.ReadInt8(); |
|
67 TSKey sKey; |
|
68 sKey.Set(key, type, sid); |
|
69 TKeyArrayFix sidKey(_FOFF(TSKey, iKeyCode), ECmpTInt); |
|
70 InsertIsqL(sKey, sidKey); |
|
71 } |
|
72 } |
|
73 |
|
74 TBool CAknKeySoundMap::Find(TSKey& aKey) |
|
75 { |
|
76 TKeyArrayFix sidKey(_FOFF(TSKey, iKeyCode), ECmpTInt); |
|
77 TInt index; |
|
78 if (FindIsq(aKey, sidKey, index) == 0) |
|
79 { |
|
80 aKey.iSid = At(index).iSid; |
|
81 return ETrue; |
|
82 } |
|
83 return EFalse; |
|
84 } |
|
85 |
|
86 |
|
87 // CAknKeySoundStack |
|
88 |
|
89 |
|
90 CAknKeySoundStack* CAknKeySoundStack::NewL() |
|
91 { |
|
92 CAknKeySoundStack* self = new(ELeave)CAknKeySoundStack(); |
|
93 return self; |
|
94 } |
|
95 |
|
96 CAknKeySoundStack::~CAknKeySoundStack() |
|
97 { |
|
98 ResetAndDestroy(); |
|
99 } |
|
100 |
|
101 |
|
102 CAknKeySoundStack::CAknKeySoundStack() |
|
103 :CArrayPtrFlat<CAknKeySoundMap>(KAknKeySoundMapGranularity) |
|
104 { |
|
105 } |
|
106 |
|
107 TBool CAknKeySoundStack::Find(const TKeyEvent& aKeyEvent, TInt& aSid) |
|
108 { |
|
109 TSKey key; |
|
110 // Decide on key-repeat type to check for |
|
111 if (aKeyEvent.iRepeats == 0) |
|
112 { |
|
113 key.Set(aKeyEvent.iCode, ESKeyTypeShort, 0); |
|
114 } |
|
115 else |
|
116 { |
|
117 if (iPreviousEvent.iRepeats == 0) |
|
118 { |
|
119 key.Set(aKeyEvent.iCode, ESKeyTypeLong, 0); |
|
120 } |
|
121 else |
|
122 { |
|
123 key.Set(aKeyEvent.iCode, ESKeyTypeRepeat, 0); |
|
124 } |
|
125 } |
|
126 |
|
127 iPreviousEvent = aKeyEvent; |
|
128 |
|
129 // Check in top layer |
|
130 TInt index = Count(); |
|
131 while (index) |
|
132 { |
|
133 index--; |
|
134 CAknKeySoundMap* map = At(index); |
|
135 if (map->Find(key)) |
|
136 { |
|
137 if (key.iSid == EAvkonSIDNoSound) |
|
138 return EFalse; |
|
139 else if (key.iSid == EAvkonSIDDefaultSound) |
|
140 { |
|
141 // Go direct to play default sound |
|
142 index = 1; |
|
143 continue; |
|
144 } |
|
145 else |
|
146 { |
|
147 aSid = key.iSid; |
|
148 return ETrue; |
|
149 } |
|
150 } |
|
151 } |
|
152 return EFalse; |
|
153 } |
|
154 |
|
155 // End of File |