|
1 /* |
|
2 * Copyright (c) 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "HgKeyUtils.h" |
|
19 #include "HgConstants.h" |
|
20 #include <ganes/HgScroller.h> |
|
21 #include <ganes/HgItem.h> |
|
22 |
|
23 #include <w32std.h> |
|
24 #include <eikbtgpc.h> |
|
25 #include <eikcba.h> |
|
26 #include <avkon.rsg> |
|
27 #include <avkon.hrh> |
|
28 #include <AknUtils.h> |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // CHgKeyUtils::NewL() |
|
32 // ----------------------------------------------------------------------------- |
|
33 // |
|
34 CHgKeyUtils* CHgKeyUtils::NewL( CHgScroller& aScroller ) |
|
35 { |
|
36 CHgKeyUtils* self = new (ELeave) CHgKeyUtils( aScroller ); |
|
37 CleanupStack::PushL( self ); |
|
38 self->ConstructL(); |
|
39 CleanupStack::Pop( self ); |
|
40 return self; |
|
41 } |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // CHgKeyUtils::CHgKeyUtils() |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 CHgKeyUtils::~CHgKeyUtils() |
|
48 { |
|
49 RemoveMSKObserver(); |
|
50 // Stop listening CenRep. |
|
51 if (iCenRepNotifyHandler) |
|
52 { |
|
53 iCenRepNotifyHandler->StopListening(); |
|
54 } |
|
55 delete iCenRepNotifyHandler; |
|
56 delete iCenRep; |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CHgKeyUtils::HandleNotifyInt() |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 void CHgKeyUtils::HandleNotifyInt(TUint32 aId, TInt aNewValue) |
|
64 { |
|
65 if (aId == KAknFepHashKeySelection) |
|
66 { |
|
67 iAknFepHashKeySelection = (TBool)aNewValue; |
|
68 } |
|
69 } |
|
70 |
|
71 // ----------------------------------------------------------------------------- |
|
72 // CHgKeyUtils::CHgKeyUtils() |
|
73 // ----------------------------------------------------------------------------- |
|
74 // |
|
75 CHgKeyUtils::CHgKeyUtils( CHgScroller& aScroller ): |
|
76 iScroller( aScroller ) |
|
77 { |
|
78 |
|
79 } |
|
80 |
|
81 // ----------------------------------------------------------------------------- |
|
82 // CHgKeyUtils::ConstructL() |
|
83 // ----------------------------------------------------------------------------- |
|
84 // |
|
85 void CHgKeyUtils::ConstructL() |
|
86 { |
|
87 iMskEnabledInPlatform = AknLayoutUtils::MSKEnabled(); |
|
88 |
|
89 // Start listening a CenRep key indicating whether hash key selection is active. |
|
90 TRAPD(err, iCenRep = CRepository::NewL(KCRUidAknFep)); |
|
91 if (err == KErrNone) |
|
92 { |
|
93 iCenRepNotifyHandler = CCenRepNotifyHandler::NewL(*this, |
|
94 *iCenRep, |
|
95 CCenRepNotifyHandler::EIntKey, |
|
96 KAknFepHashKeySelection); |
|
97 |
|
98 iCenRepNotifyHandler->StartListeningL(); |
|
99 iCenRep->Get(KAknFepHashKeySelection, iAknFepHashKeySelection); |
|
100 } |
|
101 } |
|
102 |
|
103 // ----------------------------------------------------------------------------- |
|
104 // CHgKeyUtils::SelectionMode() |
|
105 // ----------------------------------------------------------------------------- |
|
106 // |
|
107 TBool CHgKeyUtils::SelectionMode( const TKeyEvent& aKeyEvent ) |
|
108 { |
|
109 return (iAknFepHashKeySelection && aKeyEvent.iScanCode == EStdKeyHash) || |
|
110 aKeyEvent.iScanCode == EStdKeyLeftShift || |
|
111 aKeyEvent.iScanCode == EStdKeyRightShift || |
|
112 aKeyEvent.iScanCode == EStdKeyLeftCtrl || |
|
113 aKeyEvent.iScanCode == EStdKeyRightCtrl; |
|
114 } |
|
115 |
|
116 // ----------------------------------------------------------------------------- |
|
117 // CHgKeyUtils::ProcessCommandL() |
|
118 // ----------------------------------------------------------------------------- |
|
119 // |
|
120 void CHgKeyUtils::ProcessCommandL(TInt aCommandId) |
|
121 { |
|
122 if( !iMskEnabledInPlatform ) |
|
123 return; |
|
124 |
|
125 switch ( aCommandId ) |
|
126 { |
|
127 case EAknSoftkeyShiftMSK: |
|
128 { |
|
129 const TInt selectedIndex = iScroller.SelectedIndex(); |
|
130 if ( selectedIndex != KErrNotFound ) |
|
131 { |
|
132 if( iScroller.ItemL( selectedIndex ).Flags() & CHgItem::EHgItemFlagMarked ) |
|
133 { |
|
134 iScroller.UnMark(selectedIndex); |
|
135 iScroller.SetSelectionMode( CHgScroller::ESelectionUnMark ); |
|
136 } |
|
137 else |
|
138 { |
|
139 iScroller.Mark(selectedIndex); |
|
140 iScroller.SetSelectionMode( CHgScroller::ESelectionMark ); |
|
141 } |
|
142 } |
|
143 } |
|
144 break; |
|
145 default: |
|
146 break; |
|
147 } |
|
148 } |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // CHgKeyUtils::CreateMSKObserverL() |
|
152 // ----------------------------------------------------------------------------- |
|
153 // |
|
154 void CHgKeyUtils::CreateMSKObserver() |
|
155 { |
|
156 if( !iMskEnabledInPlatform ) |
|
157 return; |
|
158 |
|
159 RemoveMSKObserver(); |
|
160 |
|
161 UpdateMSKVars(); |
|
162 |
|
163 if( !iCba ) |
|
164 return; |
|
165 |
|
166 iCba->SetMSKCommandObserver(this); |
|
167 iMSKButtonGroupAlive = ETrue; |
|
168 } |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // CHgKeyUtils::RemoveMSKObserver() |
|
172 // ----------------------------------------------------------------------------- |
|
173 // |
|
174 void CHgKeyUtils::RemoveMSKObserver() |
|
175 { |
|
176 if( !iMSKButtonGroupAlive || !iMskEnabledInPlatform ) |
|
177 return; |
|
178 |
|
179 UpdateMSKVars(); |
|
180 |
|
181 if( !iCba ) |
|
182 return; |
|
183 |
|
184 iCba->SetMSKCommandObserver(NULL); |
|
185 iMSKButtonGroupAlive = EFalse; |
|
186 } |
|
187 |
|
188 // ----------------------------------------------------------------------------- |
|
189 // CHgKeyUtils::UpdateMSKVars() |
|
190 // ----------------------------------------------------------------------------- |
|
191 // |
|
192 void CHgKeyUtils::UpdateMSKVars() |
|
193 { |
|
194 if( !iMskEnabledInPlatform ) |
|
195 return; |
|
196 |
|
197 CEikButtonGroupContainer* bgc; |
|
198 iCba = NULL; |
|
199 |
|
200 iScroller.MopGetObject( bgc ); |
|
201 if ( bgc ) |
|
202 { |
|
203 iCba = ( static_cast<CEikCba*>( bgc->ButtonGroup() ) ); // downcast from MEikButtonGroup |
|
204 } |
|
205 } |
|
206 |
|
207 // ----------------------------------------------------------------------------- |
|
208 // CHgKeyUtils::OfferKeyEventL() |
|
209 // ----------------------------------------------------------------------------- |
|
210 // |
|
211 TKeyResponse CHgKeyUtils::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType ) |
|
212 { |
|
213 TKeyResponse response = EKeyWasNotConsumed; |
|
214 |
|
215 // if we have markable list and either shift, ctrl or hash is long pressed |
|
216 // down, we will enter selection (marking) mode, where MSK is Mark/Unmark |
|
217 if( SelectionMode( aKeyEvent ) ) |
|
218 { |
|
219 if( aType == EEventKeyDown ) |
|
220 { |
|
221 iShiftKeyPressed = ETrue; |
|
222 iScroller.SetSelectionMode( CHgScroller::ESelectionPossible ); |
|
223 } |
|
224 else if( aType == EEventKeyUp ) |
|
225 { |
|
226 iShiftKeyPressed = EFalse; |
|
227 iScroller.SetSelectionMode( CHgScroller::ENoSelection ); |
|
228 } |
|
229 response = EKeyWasConsumed; |
|
230 } |
|
231 |
|
232 const TInt selectedIndex = iScroller.SelectedIndex(); |
|
233 if( iShiftKeyPressed |
|
234 && aType == EEventKey |
|
235 && selectedIndex != KErrNotFound |
|
236 && iScroller.SelectionMode() == CHgScroller::ESelectionPossible ) |
|
237 { |
|
238 TBool itemMarked = iScroller.ItemL( selectedIndex ).Flags() & CHgItem::EHgItemFlagMarked; |
|
239 if(itemMarked) |
|
240 { |
|
241 iScroller.SetSelectionMode( CHgScroller::ESelectionUnMark ); |
|
242 } |
|
243 else |
|
244 { |
|
245 iScroller.SetSelectionMode( CHgScroller::ESelectionMark ); |
|
246 } |
|
247 |
|
248 if( ( iAknFepHashKeySelection && aKeyEvent.iScanCode == EStdKeyHash ) ) |
|
249 { |
|
250 if( itemMarked ) |
|
251 { |
|
252 iScroller.UnMark(selectedIndex); |
|
253 } |
|
254 else |
|
255 { |
|
256 iScroller.Mark(selectedIndex); |
|
257 } |
|
258 iScroller.RefreshScreen(selectedIndex); |
|
259 } |
|
260 |
|
261 } |
|
262 |
|
263 return response; |
|
264 } |
|
265 |
|
266 // ----------------------------------------------------------------------------- |
|
267 // CHgKeyUtils::HandleLosingForeground() |
|
268 // ----------------------------------------------------------------------------- |
|
269 // |
|
270 void CHgKeyUtils::HandleLosingFocus() |
|
271 { |
|
272 // switch off selection (marking) mode when we lose focus |
|
273 iShiftKeyPressed = EFalse; |
|
274 iSelectionModeEnabled = EFalse; |
|
275 iScroller.SetSelectionMode( CHgScroller::ENoSelection ); |
|
276 RemoveMSKObserver(); |
|
277 } |
|
278 |
|
279 // ----------------------------------------------------------------------------- |
|
280 // CHgKeyUtils::HandleGainingForeground() |
|
281 // ----------------------------------------------------------------------------- |
|
282 // |
|
283 void CHgKeyUtils::HandleGainingFocus() |
|
284 { |
|
285 CreateMSKObserver(); |
|
286 } |
|
287 |
|
288 // End of file |