|
1 /* |
|
2 * Copyright (c) 2006-2008 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: Base container for multiselection containers |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "gssenbasecontainer.h" |
|
21 #include "gssensorpluginmodel.h" |
|
22 #include "gssensorplugin.hrh" |
|
23 #include "gssensorplugin_debug.h" |
|
24 #include "gssensormskobserver.h" |
|
25 |
|
26 #include <aknlists.h> |
|
27 #include <gslistbox.h> |
|
28 #include <gssensorpluginrsc.rsg> |
|
29 #include <akncheckboxsettingpage.h> |
|
30 #include <AknIconArray.h> |
|
31 #include <aknconsts.h> |
|
32 #include <avkon.mbg> |
|
33 #include <gulicon.h> |
|
34 #include <eiklbv.h> |
|
35 |
|
36 // ========================= MEMBER FUNCTIONS ================================ |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 // CGSSenBaseContainer::CGSSenBaseContainer |
|
40 // Default constructor |
|
41 // --------------------------------------------------------------------------- |
|
42 // |
|
43 CGSSenBaseContainer::CGSSenBaseContainer( MGSSensorMskObserver& aMskObserver ) : |
|
44 iMskObserver( aMskObserver ) |
|
45 { |
|
46 TRACE_( "[GSSensorPlugin] CGSSenBaseContainer::CGSSenBaseContainer()" ); |
|
47 } |
|
48 |
|
49 // --------------------------------------------------------------------------- |
|
50 // CGSSenBaseContainer::~CGSSenBaseContainer |
|
51 // Destructor |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 CGSSenBaseContainer::~CGSSenBaseContainer() |
|
55 { |
|
56 TRACE_( "[GSSensorPlugin] CGSSenBaseContainer::~CGSSenBaseContainer()" ); |
|
57 if ( iSelectionItems ) |
|
58 { |
|
59 delete iSelectionItems; |
|
60 } |
|
61 if ( iListboxItemArray ) |
|
62 { |
|
63 delete iListboxItemArray; |
|
64 } |
|
65 |
|
66 iModel = NULL; |
|
67 TRACE_( "[GSSensorPlugin] CGSSenBaseContainer::~CGSSenBaseContainer() - return" ); |
|
68 } |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // CGSSenBaseContainer::ConstructListBoxL |
|
72 // --------------------------------------------------------------------------- |
|
73 // |
|
74 void CGSSenBaseContainer::ConstructListBoxL( TInt aResLbxId, TInt aResMsId ) |
|
75 { |
|
76 TRACE_( "[GSSensorPlugin] CGSSenBaseContainer::ConstructListBoxL()" ); |
|
77 iListBox->ConstructL( this, EAknListBoxMultiselectionList ); |
|
78 iListboxItemArray = CGSListBoxItemTextArray::NewL( |
|
79 aResLbxId, *iListBox, *iCoeEnv ); |
|
80 iListBox->Model()->SetItemTextArray( iListboxItemArray ); |
|
81 iListBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray ); |
|
82 |
|
83 iSelectionItems = iCoeEnv->ReadDesC16ArrayResourceL( |
|
84 aResMsId ); |
|
85 |
|
86 |
|
87 const TInt interactionId = InteractionId(); |
|
88 |
|
89 // Get current selections from CenRep |
|
90 iSelections = iModel->SelectionListL( interactionId ); |
|
91 const TUint32 variation = iModel->VariationListL( interactionId ); |
|
92 |
|
93 TUint bitmaskpos = 0; |
|
94 |
|
95 // Loop selections and delete disabled items |
|
96 for ( TInt i = 0; i < iSelectionItems->Count(); i++ ) |
|
97 { |
|
98 TUint status( 0 ); |
|
99 TUint mask( 0x01 << bitmaskpos++ ); |
|
100 |
|
101 // Get value from member variable bitmask. It is updated when this view is launched |
|
102 // and will be stored when view is closed |
|
103 status = variation & mask; |
|
104 |
|
105 if (!status) |
|
106 { |
|
107 // Remove disabled item from iSelectionItems |
|
108 iSelectionItems->Delete( i ); |
|
109 i--; // Decrease index |
|
110 } |
|
111 } |
|
112 |
|
113 // Add items to list box |
|
114 iListBox->Model()->SetItemTextArray( iSelectionItems ); |
|
115 iListBox->HandleItemAdditionL(); |
|
116 |
|
117 // Create checkbox icons |
|
118 AddCheckboxIconsL(); |
|
119 |
|
120 // Update checkbox icons according to previous settings |
|
121 UpdateCheckboxIconsL(); |
|
122 TRACE_( "[GSSensorPlugin] CGSSenBaseContainer::ConstructListBoxL() - return" ); |
|
123 } |
|
124 |
|
125 // --------------------------------------------------------------------------- |
|
126 // CGSSenBaseContainer::AddCheckboxIconsL |
|
127 // --------------------------------------------------------------------------- |
|
128 // |
|
129 void CGSSenBaseContainer::AddCheckboxIconsL() |
|
130 { |
|
131 TRACE_( "[GSSensorPlugin] CGSSenBaseContainer::AddCheckboxIconsL()" ); |
|
132 CAknIconArray* iconArray = new( ELeave ) CAknIconArray( 1 ); |
|
133 CleanupStack::PushL( iconArray ); |
|
134 CFbsBitmap* checkboxOnBitmap = NULL; |
|
135 CFbsBitmap* checkboxOnBitmapMask = NULL; |
|
136 CFbsBitmap* checkboxOffBitmap = NULL; |
|
137 CFbsBitmap* checkboxOffBitmapMask = NULL; |
|
138 |
|
139 //CListItemDrawer is using this logical color as default for its marked icons |
|
140 TRgb defaultColor; |
|
141 defaultColor = ( ( CEikonEnv* )iCoeEnv )->Color( EColorControlText ); |
|
142 |
|
143 // Create 'ON' checkbox icon |
|
144 AknsUtils::CreateColorIconLC( AknsUtils::SkinInstance(), |
|
145 KAknsIIDQgnIndiCheckboxOn, |
|
146 KAknsIIDQsnIconColors, |
|
147 EAknsCIQsnIconColorsCG13, |
|
148 checkboxOnBitmap, |
|
149 checkboxOnBitmapMask, |
|
150 KAvkonBitmapFile, |
|
151 EMbmAvkonQgn_indi_checkbox_on, |
|
152 EMbmAvkonQgn_indi_checkbox_on_mask, |
|
153 defaultColor |
|
154 ); |
|
155 |
|
156 CGulIcon* checkboxOnIcon = CGulIcon::NewL( checkboxOnBitmap, checkboxOnBitmapMask ); |
|
157 // cleanup checkboxOnBitmap, checkboxOnBitmapMask |
|
158 CleanupStack::Pop( checkboxOnBitmapMask ); |
|
159 CleanupStack::Pop( checkboxOnBitmap ); |
|
160 |
|
161 CleanupStack::PushL( checkboxOnIcon ); |
|
162 iconArray->AppendL( checkboxOnIcon ); |
|
163 |
|
164 // Create 'OFF' checkbox icon |
|
165 AknsUtils::CreateColorIconLC( AknsUtils::SkinInstance(), |
|
166 KAknsIIDQgnIndiCheckboxOff, |
|
167 KAknsIIDQsnIconColors, |
|
168 EAknsCIQsnIconColorsCG13, |
|
169 checkboxOffBitmap, |
|
170 checkboxOffBitmapMask, |
|
171 KAvkonBitmapFile, |
|
172 EMbmAvkonQgn_indi_checkbox_off, |
|
173 EMbmAvkonQgn_indi_checkbox_off_mask, |
|
174 defaultColor |
|
175 ); |
|
176 |
|
177 CGulIcon* checkboxOffIcon = CGulIcon::NewL( checkboxOffBitmap, checkboxOffBitmapMask ); |
|
178 // cleanup checkboxOffBitmap, checkboxOffBitmapMask |
|
179 CleanupStack::Pop( checkboxOffBitmapMask ); |
|
180 CleanupStack::Pop( checkboxOffBitmap ); |
|
181 |
|
182 |
|
183 CleanupStack::PushL( checkboxOffIcon ); |
|
184 iconArray->AppendL( checkboxOffIcon ); |
|
185 |
|
186 CAknColumnListBox* castedListbox = static_cast<CAknColumnListBox*>( iListBox ); |
|
187 castedListbox->ItemDrawer()->ColumnData()->SetIconArray( iconArray ); |
|
188 |
|
189 // cleanup checkboxOnIcon, checkboxOffIcon, iconArray |
|
190 CleanupStack::Pop( checkboxOffIcon ); |
|
191 CleanupStack::Pop( checkboxOnIcon ); |
|
192 CleanupStack::Pop( iconArray ); |
|
193 |
|
194 TRACE_( "[GSSensorPlugin] CGSSenBaseContainer::AddCheckboxIconsL() - return" ); |
|
195 } |
|
196 |
|
197 // --------------------------------------------------------------------------- |
|
198 // CGSSenBaseContainer::OfferKeyEventL |
|
199 // --------------------------------------------------------------------------- |
|
200 // |
|
201 TKeyResponse CGSSenBaseContainer::OfferKeyEventL( |
|
202 const TKeyEvent& aKeyEvent, TEventCode aType ) |
|
203 { |
|
204 TRACE_( "[GSSensorPlugin] CGSSenBaseContainer::OfferKeyEventL()" ); |
|
205 |
|
206 TKeyResponse returnValue( EKeyWasNotConsumed ); |
|
207 |
|
208 switch ( aKeyEvent.iCode ) |
|
209 { |
|
210 case EKeyUpArrow: |
|
211 case EKeyDownArrow: |
|
212 { |
|
213 // Send key event to Listbox |
|
214 returnValue = iListBox->OfferKeyEventL( aKeyEvent, aType ); |
|
215 // Change MSK label if needs to changed |
|
216 iMskObserver.CheckMiddleSoftkeyLabelL(); |
|
217 break; |
|
218 } |
|
219 case EKeyLeftArrow: |
|
220 case EKeyRightArrow: |
|
221 { |
|
222 // Listbox takes all events even if it doesn't use them. |
|
223 // Stick with the default return value |
|
224 break; |
|
225 } |
|
226 default: |
|
227 { |
|
228 // Forward key event to listbox |
|
229 returnValue = iListBox->OfferKeyEventL( aKeyEvent, aType ); |
|
230 break; |
|
231 } |
|
232 } |
|
233 |
|
234 TRACE_( "[GSSensorPlugin] CGSSenBaseContainer::OfferKeyEventL() - return" ); |
|
235 return returnValue; |
|
236 } |
|
237 |
|
238 // --------------------------------------------------------------------------- |
|
239 // CGSSenBaseContainer::UpdateCheckboxIconL |
|
240 // --------------------------------------------------------------------------- |
|
241 // |
|
242 void CGSSenBaseContainer::UpdateCheckboxIconL( TInt aSelectedItem ) |
|
243 { |
|
244 TRACE_1( "[GSSensorPlugin] CGSSenBaseContainer::UpdateCheckboxIconL() - Item: %i", aSelectedItem ); |
|
245 // Range of selected item is already checked by caller of this function |
|
246 if ( SelectionStatus( aSelectedItem ) ) |
|
247 { |
|
248 iListBox->View()->SelectItemL( aSelectedItem ); |
|
249 } |
|
250 else |
|
251 { |
|
252 iListBox->View()->DeselectItem( aSelectedItem ); |
|
253 } |
|
254 TRACE_( "[GSSensorPlugin] CGSSenBaseContainer::UpdateCheckboxIconL() - return" ); |
|
255 } |
|
256 |
|
257 // --------------------------------------------------------------------------- |
|
258 // CGSSenBaseContainer::StoreSelectionsL |
|
259 // Store current selection list to CenRep |
|
260 // --------------------------------------------------------------------------- |
|
261 // |
|
262 void CGSSenBaseContainer::StoreSelectionsL() |
|
263 { |
|
264 TRACE_( "[GSSensorPlugin] CGSSenBaseContainer::StoreSelectionsL()" ); |
|
265 // Send current selection list to be stored by model |
|
266 iModel->SetSelectionListL( InteractionId(), iSelections ); |
|
267 TRACE_( "[GSSensorPlugin] CGSSenBaseContainer::StoreSelectionsL() - return" ); |
|
268 } |
|
269 |
|
270 // --------------------------------------------------------------------------- |
|
271 // CGSSenBaseContainer::CurrentFeatureId |
|
272 // --------------------------------------------------------------------------- |
|
273 // |
|
274 TInt CGSSenBaseContainer::CurrentFeatureId( ) const |
|
275 { |
|
276 TRACE_1( "[GSSensorPlugin] CGSSenBaseContainer::CurrentFeatureId() - %i", |
|
277 iListboxItemArray->CurrentFeature() ); |
|
278 return iListboxItemArray->CurrentFeature(); |
|
279 } |
|
280 |
|
281 // ---------------------------------------------------------------------------- |
|
282 // CGSSenBaseContainer::SelectionStatus |
|
283 // ---------------------------------------------------------------------------- |
|
284 // |
|
285 TInt CGSSenBaseContainer::SelectionStatus( TInt aPosition ) |
|
286 { |
|
287 TRACE_1( "[GSSensorPlugin] CGSSenBaseContainer::SelectionStatus() - Position: %i", aPosition ); |
|
288 TUint status( 0 ); |
|
289 TUint mask( 0x01 << aPosition ); |
|
290 |
|
291 // Get value from member variable bitmask. It is updated when this view is launched |
|
292 // and will be stored when view is closed |
|
293 status = iSelections & mask; |
|
294 TRACE_1( "[GSSensorPlugin] CGSSenBaseContainer::SelectionStatus() - return: %i", status ); |
|
295 return status; |
|
296 } |
|
297 |
|
298 // ---------------------------------------------------------------------------- |
|
299 // CGSSenBaseContainer::ChangeSelectionStatus |
|
300 // ---------------------------------------------------------------------------- |
|
301 // |
|
302 void CGSSenBaseContainer::ChangeSelectionStatus( TInt aPosition) |
|
303 { |
|
304 TRACE_1( "[GSSensorPlugin] CGSSenBaseContainer::ChangeSelectionStatus() - Position: %i", |
|
305 aPosition ); |
|
306 // Set position bit to 1 |
|
307 TUint bit( 0x01 << aPosition ); |
|
308 // Get current status |
|
309 const TBool status( SelectionStatus( aPosition ) ); |
|
310 |
|
311 // Set value only to member variable bitmask. Bitmask is updated to CenRep when all |
|
312 // selections are approved by user |
|
313 |
|
314 if ( !status ) |
|
315 { |
|
316 // Set selected bit on |
|
317 iSelections = iSelections | bit; |
|
318 } |
|
319 else |
|
320 { |
|
321 // Set selected bit off. In example, second and fourth are selected. Second needs to set off |
|
322 // First take bitwice from selections, for example 0000 1010 -> 1111 0101 |
|
323 // Make OR operand to bitwise with selected bit (second) 1111 0101 -> 1111 0111 |
|
324 // Make bitwise again to set selections to original form 1111 0111 -> 0000 1000 |
|
325 TUint bitwise( ~iSelections ); |
|
326 iSelections = ~( bitwise | bit ); |
|
327 } |
|
328 TRACE_( "[GSSensorPlugin] CGSSenBaseContainer::ChangeSelectionStatus() - return" ); |
|
329 } |
|
330 |
|
331 // ---------------------------------------------------------------------------- |
|
332 // CGSSenBaseContainer::CheckSelections |
|
333 // ---------------------------------------------------------------------------- |
|
334 // |
|
335 void CGSSenBaseContainer::CheckSelections() |
|
336 { |
|
337 TRACE_( "[GSSensorPlugin] CGSSenBaseContainer::CheckSelections()"); |
|
338 |
|
339 // This function is needed purely for this component to work in S60 3.1 as it does not support MSK |
|
340 // as well as S60 3.2 and onwards. The reason for this function is that in S60 3.1 MSK presses does |
|
341 // not end up for this component, but the checking / unchecking is done in AVKON side and hence |
|
342 // this component does not know the changes other way than with this function |
|
343 |
|
344 TUint status( 0 ); |
|
345 CArrayFix<TInt>* selections = const_cast<CArrayFix<TInt>*> ( iListBox->View()->SelectionIndexes() ); |
|
346 |
|
347 if ( selections ) |
|
348 { |
|
349 for ( TInt i = 0; i < selections->Count(); i++ ) |
|
350 { |
|
351 // Set selected bit to 1 |
|
352 TUint bit( 0x01 << selections->At( i ) ); |
|
353 // Set selected bit on |
|
354 status = status | bit; |
|
355 } |
|
356 } |
|
357 #ifdef _DEBUG |
|
358 TRACE_2( "[GSSensorPlugin] CGSSenBaseContainer::CheckSelections() - iSelections: %i listbox selections: %i", |
|
359 iSelections, status ); |
|
360 #endif |
|
361 iSelections = status; |
|
362 TRACE_( "[GSSensorPlugin] CGSSenBaseContainer::CheckSelections() - return" ); |
|
363 } |