|
1 /* |
|
2 * Copyright (c) 2002-2006 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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <eikbtgpc.h> // CEikButtonGroupContainer |
|
20 #include <eiklbv.h> |
|
21 #include <aknenv.h> |
|
22 #include <aknPopupHeadingPane.h> |
|
23 #include <eiklabel.h> |
|
24 #include <avkon.rsg> |
|
25 |
|
26 #include <AknTasHook.h> // for testability hooks |
|
27 #include "CAknCommonDialogsPopupList.h" |
|
28 #include "MAknCommonDialogsEventObserver.h" |
|
29 #include "CAknCommonDialogsBase.h" // TReturnKey |
|
30 |
|
31 #include <eiklbi.h> |
|
32 |
|
33 // ============================ MEMBER FUNCTIONS =============================== |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // CAknCommonDialogsPopupList::CAknCommonDialogsPopupList |
|
37 // |
|
38 // |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 CAknCommonDialogsPopupList::CAknCommonDialogsPopupList( |
|
42 MAknCommonDialogsEventObserver& aObserver, TBool& aIsEndKeyPress ) |
|
43 : iObserver( aObserver ), iEndKey( aIsEndKeyPress ) |
|
44 { |
|
45 } |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // CAknCommonDialogsPopupList::ConstructL |
|
49 // |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 void CAknCommonDialogsPopupList::ConstructL( |
|
53 CEikListBox* aListBox, |
|
54 AknPopupLayouts::TAknPopupLayouts aType ) |
|
55 { |
|
56 CAknPopupList::ConstructL( aListBox, R_AVKON_SOFTKEYS_OK_CANCEL__OK, aType ); |
|
57 } |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CAknCommonDialogsPopupList::NewL |
|
61 // |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 CAknCommonDialogsPopupList* CAknCommonDialogsPopupList::NewL( |
|
65 MAknCommonDialogsEventObserver& aObserver, |
|
66 CEikListBox* aListBox, |
|
67 AknPopupLayouts::TAknPopupLayouts aType, |
|
68 TBool& aIsEndKeyPress ) |
|
69 { |
|
70 CAknCommonDialogsPopupList* self = new( ELeave ) |
|
71 CAknCommonDialogsPopupList( aObserver, aIsEndKeyPress ); |
|
72 CleanupStack::PushL( self ); |
|
73 self->ConstructL( aListBox, aType ); |
|
74 CleanupStack::Pop(); |
|
75 AKNTASHOOK_ADDL( self, "CAknCommonDialogsPopupList" ); |
|
76 return self; |
|
77 } |
|
78 |
|
79 // Destructor |
|
80 CAknCommonDialogsPopupList::~CAknCommonDialogsPopupList() |
|
81 { |
|
82 AKNTASHOOK_REMOVE(); |
|
83 } |
|
84 |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CAknCommonDialogsPopupList::ProcessCommandL |
|
88 // |
|
89 // |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 void CAknCommonDialogsPopupList::ProcessCommandL( TInt aCommandId ) |
|
93 { |
|
94 switch( aCommandId ) |
|
95 { |
|
96 // Fall through: All softkeys which can be received from the popup list |
|
97 case EAknSoftkeyOk: |
|
98 case EAknSoftkeyCancel: |
|
99 case EAknSoftkeyBack: |
|
100 { |
|
101 MAknCommonDialogsEventObserver::TEvent event( |
|
102 aCommandId == EAknSoftkeyOk? |
|
103 MAknCommonDialogsEventObserver::ELeftSoftkeyPress : |
|
104 MAknCommonDialogsEventObserver::ERightSoftkeyPress ); |
|
105 |
|
106 if( !ReportPopupEventL( event ) ) |
|
107 { |
|
108 // Returned false, do not allow exit from popup, return |
|
109 return; |
|
110 } |
|
111 |
|
112 break; |
|
113 } |
|
114 |
|
115 default: |
|
116 { |
|
117 break; |
|
118 } |
|
119 |
|
120 } |
|
121 CAknPopupList::ProcessCommandL( aCommandId ); |
|
122 } |
|
123 |
|
124 // ----------------------------------------------------------------------------- |
|
125 // CAknCommonDialogsPopupList::OfferKeyEventL |
|
126 // |
|
127 // |
|
128 // ----------------------------------------------------------------------------- |
|
129 // |
|
130 TKeyResponse CAknCommonDialogsPopupList::OfferKeyEventL( |
|
131 const TKeyEvent& aKeyEvent, TEventCode aType ) |
|
132 { |
|
133 if( aType == EEventKey ) |
|
134 { |
|
135 |
|
136 switch( aKeyEvent.iCode ) |
|
137 { |
|
138 case EKeyUpArrow: |
|
139 case EKeyDownArrow: |
|
140 { |
|
141 // Get current item index |
|
142 TInt oldIndex( iListBox->CurrentItemIndex() ); |
|
143 // Call OfferKeyEventL |
|
144 TKeyResponse response( |
|
145 iListBox->OfferKeyEventL( aKeyEvent, aType ) ); |
|
146 // Get new item index |
|
147 TInt newIndex( iListBox->CurrentItemIndex() ); |
|
148 // Compare new and old index |
|
149 if( oldIndex != newIndex ) |
|
150 { |
|
151 // Notify focus change only if focus actually changes |
|
152 // Top item index value is zero because there is no need to |
|
153 // know what it is in focus change. |
|
154 oldIndex = 0; |
|
155 iObserver.HandleEventL( MAknCommonDialogsEventObserver::EFocusChange, |
|
156 newIndex, oldIndex, iPopoutCba ); |
|
157 } |
|
158 return response; |
|
159 // No break needed after return |
|
160 } |
|
161 |
|
162 case EKeyOK: |
|
163 { |
|
164 if( !ReportPopupEventL( MAknCommonDialogsEventObserver::ESelectionKeyPress ) ) |
|
165 { |
|
166 // Returned false, do not allow exit from popup. |
|
167 return EKeyWasConsumed; |
|
168 } |
|
169 break; |
|
170 } |
|
171 |
|
172 case EKeyEscape: |
|
173 { |
|
174 TInt oldFocus( 0 ); |
|
175 TInt oldTopIndex( 0 ); |
|
176 MAknCommonDialogsEventObserver::TAction action( |
|
177 iObserver.HandleEventL( MAknCommonDialogsEventObserver::ECancelAllActions, |
|
178 oldFocus, oldTopIndex, iPopoutCba ) ); |
|
179 if ( action == MAknCommonDialogsEventObserver::EDidNothing || |
|
180 action == MAknCommonDialogsEventObserver::ETryingToExit ) |
|
181 { |
|
182 iEndKey = ETrue; |
|
183 MakeVisible( EFalse ); |
|
184 AttemptExitL( EFalse ); |
|
185 } |
|
186 return EKeyWasConsumed; |
|
187 // No break needed after return |
|
188 } |
|
189 |
|
190 default: |
|
191 { |
|
192 break; |
|
193 } |
|
194 |
|
195 } |
|
196 } |
|
197 return iListBox->OfferKeyEventL( aKeyEvent, aType ); |
|
198 } |
|
199 |
|
200 // ----------------------------------------------------------------------------- |
|
201 // CAknCommonDialogsPopupList::ReportPopupEventL |
|
202 // |
|
203 // |
|
204 // ----------------------------------------------------------------------------- |
|
205 // |
|
206 TBool CAknCommonDialogsPopupList::ReportPopupEventL( |
|
207 MAknCommonDialogsEventObserver::TEvent aEvent ) |
|
208 { |
|
209 // Get current indices in listbox. |
|
210 const TInt oldFocus( iListBox->CurrentItemIndex() ); |
|
211 const TInt oldTopIndex( iListBox->View()->TopItemIndex() ); |
|
212 // Create variables for new indices. |
|
213 TInt newFocus( oldFocus ); |
|
214 TInt newTopIndex( oldTopIndex ); |
|
215 |
|
216 // Report the event to event handler |
|
217 MAknCommonDialogsEventObserver::TAction action( |
|
218 iObserver.HandleEventL( aEvent, newFocus, newTopIndex, iPopoutCba ) ); |
|
219 |
|
220 // Do what the event handler says. |
|
221 switch( action ) |
|
222 { |
|
223 case MAknCommonDialogsEventObserver::EDidNothing: |
|
224 { |
|
225 return EFalse; |
|
226 } |
|
227 case MAknCommonDialogsEventObserver::EItemsUpdated: |
|
228 { |
|
229 UpdateItemsAndRedrawPopupL( newFocus, newTopIndex ); |
|
230 return EFalse; |
|
231 } |
|
232 case MAknCommonDialogsEventObserver::ELaunchEmptyPopup: |
|
233 { |
|
234 MakeVisible( EFalse ); |
|
235 // Trap empty popup launching in order to set popup visible again. |
|
236 TPtr promptText = iTitle->PromptText(); |
|
237 TRAPD( error, |
|
238 iAvkonEnv->ExecuteEmptyPopupListL( |
|
239 NULL, &promptText, R_AVKON_SOFTKEYS_OK_BACK ) ); |
|
240 MakeVisible( ETrue ); |
|
241 User::LeaveIfError( error ); |
|
242 return EFalse; |
|
243 } |
|
244 case MAknCommonDialogsEventObserver::ECanceled: |
|
245 { |
|
246 AttemptExitL(EFalse); |
|
247 return EFalse; |
|
248 } |
|
249 default: |
|
250 { |
|
251 break; |
|
252 } |
|
253 } |
|
254 return ETrue; |
|
255 } |
|
256 |
|
257 // ----------------------------------------------------------------------------- |
|
258 // CAknCommonDialogsPopupList::UpdateItemsAndRedrawPopupL |
|
259 // |
|
260 // |
|
261 // ----------------------------------------------------------------------------- |
|
262 // |
|
263 void CAknCommonDialogsPopupList::UpdateItemsAndRedrawPopupL( TInt aFocus, TInt aTopIndex ) |
|
264 { |
|
265 iListBox->Reset(); |
|
266 iListBox->HandleItemRemovalL(); |
|
267 |
|
268 // If indices have been defined, set then after reset |
|
269 CListBoxView* view = iListBox->View(); |
|
270 if( aFocus >= 0 ) |
|
271 { |
|
272 view->SetCurrentItemIndex( aFocus ); |
|
273 |
|
274 if( aTopIndex >= 0 ) |
|
275 { |
|
276 view->SetTopItemIndex( aTopIndex ); |
|
277 } |
|
278 } |
|
279 // Report focus change event |
|
280 iObserver.HandleEventL( |
|
281 MAknCommonDialogsEventObserver::EFocusChange, aFocus, aTopIndex, iPopoutCba ); |
|
282 |
|
283 // Change window size and update screen |
|
284 MakeVisible( EFalse ); |
|
285 SetupWindowLayout( iWindowType ); |
|
286 ( (RWindow*)DrawableWindow() )->ClearRedrawStore(); |
|
287 MakeVisible( ETrue ); |
|
288 DrawNow(); |
|
289 } |
|
290 |
|
291 // ----------------------------------------------------------------------------- |
|
292 // CAknCommonDialogsPopupList::HandleListBoxEventL |
|
293 // Override CAknPopupList's HandleListBoxEventL function |
|
294 // Processes key & point (for S60 4.0) events from the listbox. |
|
295 // ----------------------------------------------------------------------------- |
|
296 // |
|
297 void CAknCommonDialogsPopupList::HandleListBoxEventL(CEikListBox* aListBox, |
|
298 TListBoxEvent aEventType) |
|
299 { |
|
300 // Respond to events from listbox |
|
301 if (aListBox == iListBox) |
|
302 { |
|
303 // if left softkey is empty, we do not handle enter key either. |
|
304 if (iPopoutCba && iPopoutCba->ButtonGroup()) |
|
305 if (iPopoutCba->ButtonGroup()->CommandId( 0 ) != 0) // CommandId(0) is left softkey. |
|
306 { |
|
307 if ( ( aEventType == MEikListBoxObserver::EEventEnterKeyPressed ) |
|
308 || ( aEventType == MEikListBoxObserver::EEventItemDoubleClicked ) |
|
309 || ( aEventType == MEikListBoxObserver::EEventItemClicked ) |
|
310 || ( aEventType == MEikListBoxObserver::EEventPanningStopped) |
|
311 || ( aEventType == MEikListBoxObserver::EEventFlickStopped ) |
|
312 || ( aEventType == MEikListBoxObserver::EEventItemSingleClicked ) |
|
313 && AknLayoutUtils::PenEnabled() ) |
|
314 { |
|
315 MAknCommonDialogsEventObserver::TEvent event; |
|
316 |
|
317 if( aEventType == MEikListBoxObserver::EEventItemDoubleClicked |
|
318 || aEventType == MEikListBoxObserver::EEventItemSingleClicked |
|
319 ) |
|
320 { |
|
321 event = MAknCommonDialogsEventObserver::EEventClicked; |
|
322 iListBox->View()->ItemDrawer()->ClearFlags( CListItemDrawer::EPressedDownState ); |
|
323 } |
|
324 else if ( aEventType == MEikListBoxObserver::EEventItemClicked |
|
325 || aEventType == MEikListBoxObserver::EEventPanningStopped |
|
326 || aEventType == MEikListBoxObserver::EEventFlickStopped ) |
|
327 { |
|
328 event = MAknCommonDialogsEventObserver::EFocusChange; |
|
329 } |
|
330 else |
|
331 event = MAknCommonDialogsEventObserver::ESelectionKeyPress; |
|
332 |
|
333 if ( !ReportPopupEventL( event ) ) |
|
334 { |
|
335 return; |
|
336 } |
|
337 AttemptExitL(ETrue); |
|
338 } |
|
339 } |
|
340 } |
|
341 } |
|
342 |
|
343 // ----------------------------------------------------------------------------- |
|
344 // CAknCommonDialogsPopupList::HandlePointerEventL |
|
345 // ----------------------------------------------------------------------------- |
|
346 // |
|
347 |
|
348 void CAknCommonDialogsPopupList::HandlePointerEventL( const TPointerEvent& aPointerEvent ) |
|
349 { |
|
350 if( AknLayoutUtils::PenEnabled() ) |
|
351 { |
|
352 TInt oldHighlight = iListBox->CurrentItemIndex(); |
|
353 |
|
354 CCoeControl::HandlePointerEventL( aPointerEvent ); |
|
355 |
|
356 if ( oldHighlight != iListBox->CurrentItemIndex() ) |
|
357 { |
|
358 HandleListBoxHighlightChangedL( iListBox ); |
|
359 } |
|
360 } |
|
361 } |
|
362 |
|
363 |
|
364 // ----------------------------------------------------------------------------- |
|
365 // CAknCommonDialogsPopupList::NotifyDrivesChangedL |
|
366 // |
|
367 // |
|
368 // ----------------------------------------------------------------------------- |
|
369 // |
|
370 void CAknCommonDialogsPopupList::NotifyDrivesChangedL( |
|
371 const MDesCArray* aItemArray ) |
|
372 { |
|
373 TInt focus = iListBox->CurrentItemIndex(); |
|
374 TInt topIndex = iListBox->View()->TopItemIndex(); |
|
375 if ( focus < 0 ) |
|
376 { |
|
377 focus = aItemArray->MdcaCount() - 1; |
|
378 } |
|
379 UpdateItemsAndRedrawPopupL( focus, topIndex ); |
|
380 } |
|
381 |
|
382 // ----------------------------------------------------------------------------- |
|
383 // CAknCommonDialogsPopupList::HandleListBoxHighlightChangedL |
|
384 // |
|
385 // |
|
386 // ----------------------------------------------------------------------------- |
|
387 // |
|
388 void CAknCommonDialogsPopupList::HandleListBoxHighlightChangedL( CEikListBox* aListBox ) |
|
389 { |
|
390 TInt oldFocus( aListBox->CurrentItemIndex() ); |
|
391 TInt oldTopIndex( aListBox->View()->TopItemIndex() ); |
|
392 // Report focus change event |
|
393 iObserver.HandleEventL( |
|
394 MAknCommonDialogsEventObserver::EFocusChange, oldFocus, oldTopIndex, iPopoutCba ); |
|
395 } |
|
396 |
|
397 // End of File |