|
1 /* |
|
2 * Copyright (c) 2007-2009 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: Local area registry management in client's process. |
|
15 * Part of: Tactile Feedback. |
|
16 * |
|
17 */ |
|
18 |
|
19 #include <eikenv.h> |
|
20 |
|
21 #include "touchfeedbackregistry.h" |
|
22 |
|
23 // ======== MEMBER FUNCTIONS ======== |
|
24 |
|
25 // --------------------------------------------------------------------------- |
|
26 // Constructor. |
|
27 // --------------------------------------------------------------------------- |
|
28 // |
|
29 CTouchFeedbackRegistry::CTouchFeedbackRegistry( TUint aWindowHandle ): |
|
30 iWindowHandle( aWindowHandle ) |
|
31 { |
|
32 } |
|
33 |
|
34 // --------------------------------------------------------------------------- |
|
35 // 2-phased constructor. |
|
36 // --------------------------------------------------------------------------- |
|
37 // |
|
38 CTouchFeedbackRegistry* CTouchFeedbackRegistry::NewL( |
|
39 TUint aWindowHandle ) |
|
40 { |
|
41 CTouchFeedbackRegistry* self = |
|
42 new( ELeave ) CTouchFeedbackRegistry ( aWindowHandle ); |
|
43 |
|
44 // ConstructL not needed on the moment |
|
45 // --> Just return created instance right away |
|
46 return self; |
|
47 } |
|
48 |
|
49 // --------------------------------------------------------------------------- |
|
50 // Destructor. |
|
51 // --------------------------------------------------------------------------- |
|
52 // |
|
53 CTouchFeedbackRegistry::~CTouchFeedbackRegistry() |
|
54 { |
|
55 iAreaArray.Close(); |
|
56 } |
|
57 |
|
58 // --------------------------------------------------------------------------- |
|
59 // |
|
60 // #1 If area exists already, then update it |
|
61 // #2 Otherwise add it to the beginning of registry |
|
62 // |
|
63 // --------------------------------------------------------------------------- |
|
64 // |
|
65 void CTouchFeedbackRegistry::AddFeedbackAreaL( |
|
66 TRect aRect, |
|
67 TTouchLogicalFeedback aFeedbackTypeDown, |
|
68 TTouchFeedbackType aFeedbackDown, |
|
69 TTouchLogicalFeedback aFeedbackTypeUp, |
|
70 TTouchFeedbackType aFeedbackUp, |
|
71 TTouchEventType aEventType, |
|
72 TUint aId, |
|
73 TBool aVibraEnabled, |
|
74 TBool aAudioEnabled, |
|
75 TBool aVisible ) |
|
76 { |
|
77 TBool update = EFalse; |
|
78 |
|
79 // #1 |
|
80 for ( TInt i = 0; i < iAreaArray.Count() && !update; i++ ) |
|
81 { |
|
82 if ( iAreaArray[i].iId == aId ) |
|
83 { |
|
84 iAreaArray[i].iRect = aRect; |
|
85 iAreaArray[i].iFeedbackTypeDown = aFeedbackTypeDown; |
|
86 iAreaArray[i].iFeedbackDown = aFeedbackDown; |
|
87 iAreaArray[i].iFeedbackTypeUp = aFeedbackTypeUp; |
|
88 iAreaArray[i].iFeedbackUp = aFeedbackUp; |
|
89 iAreaArray[i].iEventType = aEventType; |
|
90 iAreaArray[i].iVibraEnabled = aVibraEnabled; |
|
91 iAreaArray[i].iAudioEnabled = aAudioEnabled; |
|
92 iAreaArray[i].iVisible = aVisible; |
|
93 |
|
94 update = ETrue; |
|
95 } |
|
96 } |
|
97 |
|
98 // #2 |
|
99 if ( !update ) |
|
100 { |
|
101 TFeedbackEntry newEntry; |
|
102 |
|
103 newEntry.iRect = aRect; |
|
104 newEntry.iFeedbackTypeDown = aFeedbackTypeDown; |
|
105 newEntry.iFeedbackDown = aFeedbackDown; |
|
106 newEntry.iFeedbackTypeUp = aFeedbackTypeUp; |
|
107 newEntry.iFeedbackUp = aFeedbackUp; |
|
108 newEntry.iEventType = aEventType; |
|
109 newEntry.iId = aId; |
|
110 newEntry.iVibraEnabled = aVibraEnabled; |
|
111 newEntry.iAudioEnabled = aAudioEnabled; |
|
112 newEntry.iVisible = aVisible; |
|
113 |
|
114 iAreaArray.AppendL( newEntry ); |
|
115 } |
|
116 } |
|
117 |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 // --------------------------------------------------------------------------- |
|
121 // |
|
122 void CTouchFeedbackRegistry::RemoveFeedbackArea( TUint aId ) |
|
123 { |
|
124 for ( TInt i = 0; i < iAreaArray.Count(); i++ ) |
|
125 { |
|
126 if ( iAreaArray[i].iId == aId ) |
|
127 { |
|
128 iAreaArray.Remove( i ); |
|
129 break; |
|
130 } |
|
131 } |
|
132 } |
|
133 |
|
134 // --------------------------------------------------------------------------- |
|
135 // |
|
136 // --------------------------------------------------------------------------- |
|
137 // |
|
138 TBool CTouchFeedbackRegistry::ChangeFeedbackArea( |
|
139 TUint aId, |
|
140 TRect aNewRect ) |
|
141 { |
|
142 TBool changed = EFalse; |
|
143 |
|
144 for ( TInt i = 0; i < iAreaArray.Count(); i++ ) |
|
145 { |
|
146 if ( iAreaArray[i].iId == aId ) |
|
147 { |
|
148 // Check if we really have to change something |
|
149 if ( iAreaArray[i].iRect != aNewRect ) |
|
150 { |
|
151 iAreaArray[i].iRect = aNewRect; |
|
152 |
|
153 changed = ETrue; |
|
154 } |
|
155 |
|
156 // Anyway break out from the loop, as we found the area |
|
157 // already |
|
158 break; |
|
159 } |
|
160 } |
|
161 |
|
162 return changed; |
|
163 } |
|
164 |
|
165 // --------------------------------------------------------------------------- |
|
166 // |
|
167 // --------------------------------------------------------------------------- |
|
168 // |
|
169 TBool CTouchFeedbackRegistry::ChangeFeedbackType( |
|
170 TUint aId, |
|
171 TTouchLogicalFeedback aNewFeedbackTypeDown, |
|
172 TTouchLogicalFeedback aNewFeedbackTypeUp ) |
|
173 { |
|
174 TBool changed = EFalse; |
|
175 |
|
176 for ( TInt i = 0; i < iAreaArray.Count(); i++ ) |
|
177 { |
|
178 if ( iAreaArray[i].iId == aId ) |
|
179 { |
|
180 // Check if we really have to change something |
|
181 if ( iAreaArray[i].iFeedbackTypeDown != aNewFeedbackTypeDown ) |
|
182 { |
|
183 iAreaArray[i].iFeedbackTypeDown = aNewFeedbackTypeDown; |
|
184 changed = ETrue; |
|
185 } |
|
186 if ( aNewFeedbackTypeUp != 0xFFFFFFFF && |
|
187 iAreaArray[i].iFeedbackTypeUp != aNewFeedbackTypeUp ) |
|
188 { |
|
189 iAreaArray[i].iFeedbackTypeUp = aNewFeedbackTypeUp; |
|
190 changed = ETrue; |
|
191 } |
|
192 |
|
193 // Anyway break out from the loop, as we found the area |
|
194 // already |
|
195 break; |
|
196 } |
|
197 } |
|
198 |
|
199 return changed; |
|
200 } |
|
201 |
|
202 // --------------------------------------------------------------------------- |
|
203 // Areas are moved to server side starting from last position |
|
204 // --> We need to make the desired area the last one in the array. |
|
205 // --------------------------------------------------------------------------- |
|
206 // |
|
207 TInt CTouchFeedbackRegistry::MoveFeedbackAreaToFirstPriority( TUint aId ) |
|
208 { |
|
209 TInt ret = KErrNotFound; |
|
210 |
|
211 for ( TInt i = 0; i < iAreaArray.Count(); i++ ) |
|
212 { |
|
213 if ( iAreaArray[i].iId == aId ) |
|
214 { |
|
215 TFeedbackEntry tmpEntry = iAreaArray[i]; |
|
216 |
|
217 TInt lastPosition = iAreaArray.Count()-1; |
|
218 |
|
219 iAreaArray[i] = iAreaArray[lastPosition]; |
|
220 iAreaArray[lastPosition] = tmpEntry; |
|
221 |
|
222 ret = KErrNone; |
|
223 |
|
224 break; |
|
225 } |
|
226 } |
|
227 |
|
228 return ret; |
|
229 } |
|
230 |
|
231 // --------------------------------------------------------------------------- |
|
232 // Here we set the new enabled / disabled state for this area. |
|
233 // |
|
234 // We also return ETrue if the status really changed. This way caller of this |
|
235 // function can know if any updates to server side have to be done or not. |
|
236 // --------------------------------------------------------------------------- |
|
237 // |
|
238 TBool CTouchFeedbackRegistry::SetFeedbackEnabled( TUint aId, |
|
239 TBool aVibraEnabled, |
|
240 TBool aAudioEnabled, |
|
241 TBool aVisible ) |
|
242 { |
|
243 TInt changed = EFalse; |
|
244 |
|
245 for ( TInt i = 0; i < iAreaArray.Count(); i++ ) |
|
246 { |
|
247 if ( iAreaArray[i].iId == aId ) |
|
248 { |
|
249 // Check if the status really changes |
|
250 if ( ( iAreaArray[i].iVibraEnabled != aVibraEnabled ) || |
|
251 (iAreaArray[i].iAudioEnabled != aAudioEnabled ) || |
|
252 (iAreaArray[i].iVisible != aVisible )) |
|
253 { |
|
254 changed = ETrue; |
|
255 |
|
256 iAreaArray[i].iVibraEnabled = aVibraEnabled; |
|
257 iAreaArray[i].iAudioEnabled = aAudioEnabled; |
|
258 iAreaArray[i].iVisible = aVisible; |
|
259 } |
|
260 |
|
261 break; |
|
262 } |
|
263 } |
|
264 |
|
265 return changed; |
|
266 } |
|
267 |
|
268 // --------------------------------------------------------------------------- |
|
269 // |
|
270 // --------------------------------------------------------------------------- |
|
271 // |
|
272 TUint CTouchFeedbackRegistry::WindowHandle() const |
|
273 { |
|
274 return iWindowHandle; |
|
275 } |
|
276 |
|
277 // --------------------------------------------------------------------------- |
|
278 // |
|
279 // --------------------------------------------------------------------------- |
|
280 // |
|
281 TInt CTouchFeedbackRegistry::CTouchFeedbackRegistry::AreaCount() |
|
282 { |
|
283 return iAreaArray.Count(); |
|
284 } |
|
285 |
|
286 |
|
287 // --------------------------------------------------------------------------- |
|
288 // |
|
289 // --------------------------------------------------------------------------- |
|
290 // |
|
291 RArray<TFeedbackEntry>* CTouchFeedbackRegistry::WindowRegistry() |
|
292 { |
|
293 return &iAreaArray; |
|
294 } |