|
1 /* |
|
2 * Copyright (c) 2005-2007 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: Phonebook 2 names list ready state. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CPbk2NamesListReadyState.h" |
|
21 |
|
22 // Phonebook 2 |
|
23 #include "CPbk2AdaptiveSearchGridFiller.h" |
|
24 #include "CPbk2ThumbnailLoader.h" |
|
25 #include "CPbk2ContactViewListBox.h" |
|
26 #include "CPbk2ContactViewIterator.h" |
|
27 #include "MPbk2UiControlEventSender.h" |
|
28 #include "CPbk2FindDelay.h" |
|
29 #include "CPbk2NamesListControl.h" |
|
30 #include "CPbk2FindStringSplitter.h" |
|
31 #include <CPbk2ViewState.h> |
|
32 #include <MPbk2ControlObserver.h> |
|
33 #include <Pbk2MenuFilteringFlags.hrh> |
|
34 #include <MPbk2ApplicationServices.h> |
|
35 #include <MPbk2AppUi.h> |
|
36 #include "TPbk2FindTextUtil.h" |
|
37 #include <CPbk2AppViewBase.h> |
|
38 |
|
39 #include "PmuCommands.hrh" // For accessing EPmuCmdCascadingBackup |
|
40 #include "Pbk2USimUI.hrh" // For accessing EPsu2CmdCascadingSimMemory |
|
41 #include <Pbk2InternalUID.h> |
|
42 #include <pbk2doublelistboxcmditemextension.h> |
|
43 |
|
44 // Virtual Phonebook |
|
45 #include <MVPbkContactViewBase.h> |
|
46 #include <MVPbkViewContact.h> |
|
47 #include <MVPbkContactLink.h> |
|
48 #include <MVPbkContactBookmark.h> |
|
49 #include <CVPbkContactLinkArray.h> |
|
50 #include <CVPbkContactFindPolicy.h> |
|
51 #include <CVPbkContactManager.h> |
|
52 |
|
53 // System includes |
|
54 #include <akntoolbar.h> |
|
55 #include <AknsDrawUtils.h> |
|
56 #include <barsread.h> |
|
57 #include <aknsfld.h> |
|
58 #include <badesca.h> |
|
59 #include <aknViewAppUi.h> |
|
60 #include <aknappui.h> |
|
61 #include <eikmenub.h> |
|
62 #include <eikdialg.h> |
|
63 |
|
64 // Debugging headers |
|
65 #include <Pbk2Debug.h> |
|
66 #include "CPbk2PredictiveSearchFilter.h" |
|
67 #include "cpbk2predictiveviewstack.h" |
|
68 |
|
69 |
|
70 /// Unnamed namespace for local definitions |
|
71 namespace { |
|
72 |
|
73 // LOCAL CONSTANTS AND MACROS |
|
74 const TInt KNumberOfControls = 2; // listbox and findbox |
|
75 const TInt KFindDelayTime = 700000; // microseconds |
|
76 const TInt KFindDelayThresholdContacts = 1000; // amount of contacts to |
|
77 // activate find delay |
|
78 |
|
79 #ifdef _DEBUG |
|
80 enum TPanicCode |
|
81 { |
|
82 EPanicLogic_ComponentControl = 1, |
|
83 EPanicLogic_FindTextL, |
|
84 EPanicLogic_PreConds_SetCurrentItemIndexAndDraw, |
|
85 EPanicLogic_Command_index_out_of_bounds |
|
86 }; |
|
87 |
|
88 void Panic(TPanicCode aReason) |
|
89 { |
|
90 _LIT(KPanicText, "CPbk2NamesListReadyState"); |
|
91 User::Panic(KPanicText, aReason); |
|
92 } |
|
93 #endif // _DEBUG |
|
94 |
|
95 |
|
96 NONSHARABLE_CLASS(TCleanupEnableListBoxViewRedraw) |
|
97 { |
|
98 public: // Interface |
|
99 |
|
100 /** |
|
101 * Constructor. |
|
102 * |
|
103 * @param aListBoxView The list box view |
|
104 */ |
|
105 inline TCleanupEnableListBoxViewRedraw( CListBoxView& aListBoxView ) |
|
106 : iCleanupItem( CleanupOp, &aListBoxView ) |
|
107 { |
|
108 } |
|
109 |
|
110 /** |
|
111 * Returns the cleanup item. |
|
112 */ |
|
113 inline operator TCleanupItem() const |
|
114 { |
|
115 return iCleanupItem; |
|
116 } |
|
117 |
|
118 private: // Implementation |
|
119 static void CleanupOp( |
|
120 TAny* aPtr ); |
|
121 |
|
122 private: // Data |
|
123 /// Own: Cleanup item |
|
124 TCleanupItem iCleanupItem; |
|
125 }; |
|
126 |
|
127 // -------------------------------------------------------------------------- |
|
128 // TCleanupEnableListBoxViewRedraw::CleanupOp |
|
129 // -------------------------------------------------------------------------- |
|
130 // |
|
131 void TCleanupEnableListBoxViewRedraw::CleanupOp( TAny* aPtr ) |
|
132 { |
|
133 static_cast<CListBoxView*>(aPtr)->SetDisableRedraw(EFalse); |
|
134 } |
|
135 |
|
136 |
|
137 /** |
|
138 * Resolves the next index of the listbox according the key event. |
|
139 * If key event is UP, the index is decreased from current index. |
|
140 * If key event is DOWN, the index is increased from current index. |
|
141 * If current index is last & event is DOWN, the new index is set to first. |
|
142 * If current index is first & event is UP, the new index is set to last. |
|
143 * |
|
144 * @param aKeyEvent Key event. |
|
145 * @param aListBox List box. |
|
146 * @return Next index of the list item. |
|
147 */ |
|
148 TInt NextFocusIndex |
|
149 ( const TKeyEvent& aKeyEvent, CEikListBox& aListBox ) |
|
150 { |
|
151 TInt result( KErrNotFound ); |
|
152 const TInt KFirstItemIndex( 0 ); |
|
153 TInt itemCount( aListBox.Model()->NumberOfItems() ); |
|
154 const TInt KLastItemIndex( itemCount - 1 ); |
|
155 TInt currentItemIndex( aListBox.CurrentItemIndex() ); |
|
156 if ( aKeyEvent.iCode == EKeyDownArrow ) |
|
157 { |
|
158 result = currentItemIndex + 1; |
|
159 if ( result > KLastItemIndex ) |
|
160 { |
|
161 // Set to first |
|
162 result = KFirstItemIndex; |
|
163 } |
|
164 } |
|
165 else if ( aKeyEvent.iCode == EKeyUpArrow ) |
|
166 { |
|
167 result = currentItemIndex - 1; |
|
168 if ( result < KFirstItemIndex ) |
|
169 { |
|
170 // Set to last |
|
171 result = KLastItemIndex; |
|
172 } |
|
173 } |
|
174 else |
|
175 { |
|
176 result = currentItemIndex; |
|
177 } |
|
178 return result; |
|
179 } |
|
180 |
|
181 } /// namespace |
|
182 |
|
183 // -------------------------------------------------------------------------- |
|
184 // CPbk2NamesListReadyState::CPbk2NamesListReadyState |
|
185 // -------------------------------------------------------------------------- |
|
186 // |
|
187 inline CPbk2NamesListReadyState::CPbk2NamesListReadyState( |
|
188 const CCoeControl& aParent, |
|
189 CPbk2ContactViewListBox& aListBox, |
|
190 MPbk2FilteredViewStack& aViewStack, |
|
191 CAknSearchField* aFindBox, |
|
192 CPbk2ThumbnailLoader& aThumbnailLoader, |
|
193 MPbk2UiControlEventSender& aEventSender, |
|
194 MPbk2ContactNameFormatter& aNameFormatter, |
|
195 RPointerArray<MPbk2UiControlCmdItem>& aCommandItems, |
|
196 CPbk2PredictiveSearchFilter& aSearchFilter ) : |
|
197 iParent( aParent ), |
|
198 iListBox( aListBox ), |
|
199 iViewStack( aViewStack ), |
|
200 iFindBox( aFindBox ), |
|
201 iThumbnailLoader( aThumbnailLoader ), |
|
202 iEventSender( aEventSender ), |
|
203 iNameFormatter( aNameFormatter ), |
|
204 iCommandItems( aCommandItems ), |
|
205 iSearchFilter(aSearchFilter) |
|
206 { |
|
207 } |
|
208 |
|
209 // -------------------------------------------------------------------------- |
|
210 // CPbk2NamesListReadyState::~CPbk2NamesListReadyState |
|
211 // -------------------------------------------------------------------------- |
|
212 // |
|
213 CPbk2NamesListReadyState::~CPbk2NamesListReadyState() |
|
214 { |
|
215 UnsubscribeCmdItemsVisibility(); |
|
216 iListBox.SetListCommands( NULL ); |
|
217 |
|
218 delete iAdaptiveSearchGridFiller; |
|
219 delete iFindPolicy; |
|
220 delete iFindDelay; |
|
221 delete iFindTextBuf; |
|
222 iSelectedItems.Close(); |
|
223 delete iStringArray; |
|
224 delete iStringSplitter; |
|
225 iIteratorIndexes.Close(); |
|
226 } |
|
227 |
|
228 // -------------------------------------------------------------------------- |
|
229 // CPbk2NamesListReadyState::NewL |
|
230 // -------------------------------------------------------------------------- |
|
231 // |
|
232 CPbk2NamesListReadyState* CPbk2NamesListReadyState::NewLC |
|
233 ( const CCoeControl* aParent, CPbk2ContactViewListBox& aListBox, |
|
234 MPbk2FilteredViewStack& aViewStack, CAknSearchField* aFindBox, |
|
235 CPbk2ThumbnailLoader& aThumbnailLoader, |
|
236 MPbk2UiControlEventSender& aEventSender, |
|
237 MPbk2ContactNameFormatter& aNameFormatter, |
|
238 RPointerArray<MPbk2UiControlCmdItem>& aCommandItems, |
|
239 CPbk2PredictiveSearchFilter& aSearchFilter ) |
|
240 { |
|
241 CPbk2NamesListReadyState* self = new (ELeave) CPbk2NamesListReadyState( |
|
242 *aParent, aListBox, aViewStack, aFindBox, aThumbnailLoader, |
|
243 aEventSender, aNameFormatter, aCommandItems, aSearchFilter ); |
|
244 CleanupStack::PushL(self); |
|
245 self->ConstructL(); |
|
246 return self; |
|
247 } |
|
248 |
|
249 // -------------------------------------------------------------------------- |
|
250 // CPbk2NamesListReadyState::ConstructL |
|
251 // -------------------------------------------------------------------------- |
|
252 // |
|
253 inline void CPbk2NamesListReadyState::ConstructL() |
|
254 { |
|
255 if ( iFindBox ) |
|
256 { |
|
257 if (!iFindBox->IsFocused() && iParent.IsFocused() ) |
|
258 { |
|
259 iFindBox->SetFocus(ETrue); |
|
260 } |
|
261 iFindBox->ResetL(); |
|
262 } |
|
263 |
|
264 iFindDelay = CPbk2FindDelay::NewL( *this ); |
|
265 |
|
266 // Create contact find policy |
|
267 CVPbkContactManager& manager = |
|
268 Phonebook2::Pbk2AppUi()->ApplicationServices().ContactManager(); |
|
269 CVPbkContactFindPolicy::TParam param = |
|
270 CVPbkContactFindPolicy::TParam( |
|
271 manager.FieldTypes(), |
|
272 manager.FsSession() ); |
|
273 iFindPolicy = CVPbkContactFindPolicy::NewL( param ); |
|
274 |
|
275 if( iFindBox ) |
|
276 { |
|
277 iFindBox->AddAdaptiveSearchTextObserverL( this ); |
|
278 iAdaptiveSearchGridFiller = CPbk2AdaptiveSearchGridFiller::NewL( *iFindBox, iNameFormatter ); |
|
279 } |
|
280 } |
|
281 |
|
282 void CPbk2NamesListReadyState::UnsubscribeCmdItemsVisibility() const |
|
283 { |
|
284 for ( TInt i = 0; i < iCommandItems.Count(); ++i ) |
|
285 { |
|
286 iCommandItems[i]->SetVisibilityObserver( NULL ); |
|
287 } |
|
288 } |
|
289 |
|
290 void CPbk2NamesListReadyState::SubscribeCmdItemsVisibility() |
|
291 { |
|
292 for ( TInt i = 0; i < iCommandItems.Count(); ++i ) |
|
293 { |
|
294 iCommandItems[i]->SetVisibilityObserver( this ); |
|
295 } |
|
296 } |
|
297 |
|
298 // -------------------------------------------------------------------------- |
|
299 // CPbk2NamesListReadyState::ActivateStateL |
|
300 // -------------------------------------------------------------------------- |
|
301 // |
|
302 void CPbk2NamesListReadyState::ActivateStateL() |
|
303 { |
|
304 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
305 ("CPbk2NamesListReadyState::ActivateStateL(0x%x)"), this ); |
|
306 |
|
307 AllowCommandsToShowThemselves( ETrue ); |
|
308 UpdateAdaptiveSearchGridL( EFalse ); |
|
309 } |
|
310 |
|
311 // -------------------------------------------------------------------------- |
|
312 // CPbk2NamesListReadyState::DeactivateState |
|
313 // -------------------------------------------------------------------------- |
|
314 // |
|
315 void CPbk2NamesListReadyState::DeactivateState() |
|
316 { |
|
317 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
318 ("CPbk2NamesListReadyState::DeactivateState(0x%x)"), this ); |
|
319 |
|
320 AllowCommandsToShowThemselves( EFalse ); |
|
321 HideThumbnail(); |
|
322 } |
|
323 |
|
324 // -------------------------------------------------------------------------- |
|
325 // CPbk2NamesListReadyState::CountComponentControls |
|
326 // -------------------------------------------------------------------------- |
|
327 // |
|
328 TInt CPbk2NamesListReadyState::CountComponentControls() const |
|
329 { |
|
330 TInt numberOfControls( KNumberOfControls ); |
|
331 if ( !iFindBox ) |
|
332 { |
|
333 --numberOfControls; |
|
334 } |
|
335 return numberOfControls; |
|
336 } |
|
337 |
|
338 // -------------------------------------------------------------------------- |
|
339 // CPbk2NamesListReadyState::ComponentControl |
|
340 // -------------------------------------------------------------------------- |
|
341 // |
|
342 CCoeControl* CPbk2NamesListReadyState::ComponentControl(TInt aIndex) const |
|
343 { |
|
344 switch (aIndex) |
|
345 { |
|
346 case 0: |
|
347 { |
|
348 return &iListBox; |
|
349 } |
|
350 case 1: |
|
351 { |
|
352 return iFindBox; |
|
353 } |
|
354 default: |
|
355 { |
|
356 // Illegal state |
|
357 __ASSERT_DEBUG(EFalse, Panic(EPanicLogic_ComponentControl)); |
|
358 return NULL; |
|
359 } |
|
360 } |
|
361 } |
|
362 |
|
363 // -------------------------------------------------------------------------- |
|
364 // CPbk2NamesListReadyState::SizeChanged |
|
365 // -------------------------------------------------------------------------- |
|
366 // |
|
367 void CPbk2NamesListReadyState::SizeChanged() |
|
368 { |
|
369 const TRect rect(iParent.Rect()); |
|
370 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
371 ("CPbk2NamesListReadyState::SizeChanged(0x%x), rect=(%d,%d,%d,%d)"), |
|
372 this, rect.iTl.iX, rect.iTl.iY, rect.iBr.iX, rect.iBr.iY); |
|
373 |
|
374 if ( iFindBox ) |
|
375 { |
|
376 AknLayoutUtils::LayoutControl(&iListBox, rect, |
|
377 AKN_LAYOUT_WINDOW_list_gen_pane(1)); |
|
378 |
|
379 AknLayoutUtils::LayoutControl( iFindBox, rect, |
|
380 AKN_LAYOUT_WINDOW_find_pane ); |
|
381 if (iFindBox->IsVisible() && iListBox.IsVisible()) |
|
382 { |
|
383 iFindBox->SetLinePos(EABColumn); |
|
384 } |
|
385 } |
|
386 else |
|
387 { |
|
388 AknLayoutUtils::LayoutControl(&iListBox, rect, |
|
389 AKN_LAYOUT_WINDOW_list_gen_pane(0)); |
|
390 } |
|
391 } |
|
392 |
|
393 // -------------------------------------------------------------------------- |
|
394 // CPbk2NamesListReadyState::MakeComponentsVisible |
|
395 // -------------------------------------------------------------------------- |
|
396 // |
|
397 void CPbk2NamesListReadyState::MakeComponentsVisible(TBool aVisible) |
|
398 { |
|
399 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
400 ("CPbk2NamesListReadyState::MakeComponentsVisible(0x%x,%d)"), |
|
401 this, aVisible); |
|
402 |
|
403 iListBox.MakeVisible(aVisible); |
|
404 |
|
405 CEikScrollBar *scrollBar = iListBox.ScrollBarFrame()->GetScrollBarHandle |
|
406 (CEikScrollBar::EVertical); |
|
407 if ( scrollBar ) |
|
408 { |
|
409 scrollBar->MakeVisible(aVisible); |
|
410 } |
|
411 |
|
412 if ( iFindBox ) |
|
413 { |
|
414 if ( (iFindBox->IsVisible()&&!aVisible) || (!iFindBox->IsVisible()&&aVisible) ) |
|
415 { |
|
416 iFindBox->MakeVisible(aVisible); |
|
417 } |
|
418 } |
|
419 |
|
420 // Have to call to make sure that scrollbar is updated when state of |
|
421 // control is changing. |
|
422 TRAP_IGNORE( iListBox.UpdateScrollBarsL() ); |
|
423 |
|
424 // Change visible state |
|
425 iVisible = aVisible; |
|
426 } |
|
427 |
|
428 // -------------------------------------------------------------------------- |
|
429 // CPbk2NamesListReadyState::ActivateL |
|
430 // -------------------------------------------------------------------------- |
|
431 // |
|
432 void CPbk2NamesListReadyState::ActivateL() |
|
433 { |
|
434 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
435 ("CPbk2NamesListReadyState::ActivateL(0x%x)"), this ); |
|
436 |
|
437 if ( iFindBox ) |
|
438 { |
|
439 // Adjust find box cursor |
|
440 CEikEdwin& findEditor = iFindBox->Editor(); |
|
441 findEditor.SetCursorPosL(findEditor.TextLength(), EFalse); |
|
442 } |
|
443 } |
|
444 |
|
445 // -------------------------------------------------------------------------- |
|
446 // CPbk2NamesListReadyState::Draw |
|
447 // -------------------------------------------------------------------------- |
|
448 // |
|
449 void CPbk2NamesListReadyState::Draw |
|
450 ( const TRect& aRect, CWindowGc& aGc ) const |
|
451 { |
|
452 PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING( |
|
453 "CPbk2NamesListReadyState::Draw(0x%x, TRect(%d,%d,%d,%d))" ), |
|
454 this, aRect.iTl.iX, aRect.iTl.iY, aRect.iBr.iX, aRect.iBr.iY ); |
|
455 |
|
456 if ( !iVisible ) |
|
457 { |
|
458 // If control is not visible (blanked) draw a blank background |
|
459 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
460 MAknsControlContext* cc = |
|
461 AknsDrawUtils::ControlContext( &iListBox ); |
|
462 |
|
463 if ( !AknsDrawUtils::Background( skin, cc, &iListBox, aGc, aRect ) ) |
|
464 { |
|
465 // Blank background if no skin present |
|
466 aGc.SetPenStyle( CGraphicsContext::ENullPen ); |
|
467 aGc.SetBrushStyle( CGraphicsContext::ESolidBrush ); |
|
468 aGc.DrawRect( aRect ); |
|
469 } |
|
470 } |
|
471 } |
|
472 |
|
473 // -------------------------------------------------------------------------- |
|
474 // CPbk2NamesListReadyState::DialogMenuBar |
|
475 // -------------------------------------------------------------------------- |
|
476 // |
|
477 CEikMenuBar* CPbk2NamesListReadyState::DialogMenuBar(CAknAppUi* aAppUi) |
|
478 { |
|
479 CEikMenuBar* menuBar = NULL; |
|
480 |
|
481 // Check for an active dialog and fetch its menu bar |
|
482 if (aAppUi->IsDisplayingMenuOrDialog()) |
|
483 { |
|
484 CCoeControl* ctrl = aAppUi->TopFocusedControl(); |
|
485 if (ctrl) |
|
486 { |
|
487 CEikDialog* dialog = ctrl->MopGetObjectNoChaining(dialog); |
|
488 if (dialog) |
|
489 { |
|
490 dialog->MopGetObject(menuBar); |
|
491 } |
|
492 } |
|
493 } |
|
494 return menuBar; |
|
495 } |
|
496 |
|
497 // -------------------------------------------------------------------------- |
|
498 // CPbk2NamesListReadyState::ViewMenuBar |
|
499 // -------------------------------------------------------------------------- |
|
500 // |
|
501 CEikMenuBar* CPbk2NamesListReadyState::ViewMenuBar(CAknAppUi* aAppUi) |
|
502 { |
|
503 CEikMenuBar* menuBar = NULL; |
|
504 |
|
505 // Check for an active view |
|
506 TVwsViewId uid; |
|
507 if (aAppUi->GetActiveViewId(uid) == KErrNone) |
|
508 { |
|
509 if ( uid.iAppUid != uid.iViewUid ) |
|
510 { |
|
511 CAknView* view = |
|
512 static_cast<CAknViewAppUi*> (aAppUi)->View(uid.iViewUid); |
|
513 if ( view ) |
|
514 { |
|
515 menuBar = view->MenuBar(); |
|
516 } |
|
517 } |
|
518 } |
|
519 return menuBar; |
|
520 } |
|
521 |
|
522 // -------------------------------------------------------------------------- |
|
523 // CPbk2NamesListReadyState::MenuBar |
|
524 // -------------------------------------------------------------------------- |
|
525 // |
|
526 CEikMenuBar* CPbk2NamesListReadyState::MenuBar(CAknAppUi* aAppUi) |
|
527 { |
|
528 // Try fetching a menu bar from currently displayed dialog |
|
529 CEikMenuBar* menuBar = DialogMenuBar( aAppUi ); |
|
530 |
|
531 if ( !menuBar ) // Menu bar was not dialog based |
|
532 { |
|
533 // Try fetching a menu bar from an active view |
|
534 menuBar = ViewMenuBar(aAppUi); |
|
535 } |
|
536 |
|
537 if ( !menuBar ) // Menu bar was not view based |
|
538 { |
|
539 // Finally, try fetching a menu bar from AppUi |
|
540 menuBar = CEikonEnv::Static()->AppUiFactory()->MenuBar(); |
|
541 } |
|
542 return menuBar; |
|
543 } |
|
544 |
|
545 // -------------------------------------------------------------------------- |
|
546 // CPbk2NamesListReadyState::OfferKeyEventL |
|
547 // -------------------------------------------------------------------------- |
|
548 // |
|
549 TKeyResponse CPbk2NamesListReadyState::OfferKeyEventL |
|
550 (const TKeyEvent& aKeyEvent, TEventCode aType) |
|
551 { |
|
552 // Remember current index and selection before |
|
553 // listbox has handled the event. |
|
554 TInt oldItemIndex( iListBox.CurrentItemIndex() ); |
|
555 TBool oldItemMarkedBefore |
|
556 ( iListBox.View()->ItemIsSelected( oldItemIndex ) ); |
|
557 |
|
558 // Remember next index based on key event (UP, DOWN) |
|
559 // and selection before listbox has handled the event. |
|
560 TInt newItemIndex( NextFocusIndex( aKeyEvent, iListBox ) ); |
|
561 TBool newItemMarkedBefore |
|
562 ( iListBox.View()->ItemIsSelected( newItemIndex ) ); |
|
563 |
|
564 TKeyResponse result( EKeyWasNotConsumed ); |
|
565 if ( iFindBox ) |
|
566 { |
|
567 //If the FindBox is locked then dont offer the event to the findbox |
|
568 if (!iSearchFilter.IsLocked()) |
|
569 { |
|
570 // use the "C" key to delete the Adaptive search character must |
|
571 // change the focus to Adaptive search pane |
|
572 if ( aKeyEvent.iCode == EKeyBackspace && iAdaptiveSearchGridFiller ) |
|
573 { |
|
574 iAdaptiveSearchGridFiller->SetFocusToAdaptiveSearchGrid(); |
|
575 } |
|
576 |
|
577 // Offer the key event first to findbox |
|
578 result = iFindBox->OfferKeyEventL( aKeyEvent, aType ); |
|
579 |
|
580 CPbk2PredictiveViewStack& predictiveViewStack = static_cast<CPbk2PredictiveViewStack&>( iViewStack ); |
|
581 |
|
582 TInt contactItemIndex = newItemIndex - CommandItemCount(); |
|
583 |
|
584 if ( contactItemIndex >= 0 && oldItemIndex != newItemIndex && iSearchFilter.IsPredictiveActivated() && iViewStack.Level() && |
|
585 !predictiveViewStack.IsNonMatchingMarkedContact( contactItemIndex ) ) |
|
586 { |
|
587 iSearchFilter.CommitFindPaneTextL( iViewStack, iNameFormatter, contactItemIndex ); |
|
588 } |
|
589 |
|
590 } |
|
591 else |
|
592 { |
|
593 //If FindPane is locked, then forward only the backspace key. |
|
594 if ( aKeyEvent.iCode == EKeyBackspace ) |
|
595 { |
|
596 // Offer the key event first to findbox |
|
597 result = iFindBox->OfferKeyEventL( aKeyEvent, aType ); |
|
598 } |
|
599 } |
|
600 } |
|
601 |
|
602 // And then offer the event to listbox if necessary |
|
603 if ( result == EKeyWasNotConsumed ) |
|
604 { |
|
605 // Use hash key to mark and unmark list item |
|
606 if ( (aKeyEvent.iScanCode == EStdKeyHash) |
|
607 && MenuBar( iAvkonAppUi )->ItemSpecificCommandsEnabled() ) |
|
608 { |
|
609 if ( aType == EEventKeyUp ) |
|
610 { |
|
611 if ( newItemMarkedBefore ) |
|
612 { |
|
613 iListBox.View()->DeselectItem( newItemIndex ); |
|
614 } |
|
615 else |
|
616 { |
|
617 iListBox.View()->SelectItemL( newItemIndex ); |
|
618 } |
|
619 } |
|
620 result = EKeyWasConsumed; |
|
621 } |
|
622 else |
|
623 { |
|
624 result = iListBox.OfferKeyEventL( aKeyEvent, aType ); |
|
625 } |
|
626 } |
|
627 else |
|
628 { |
|
629 // Find box consumed the key event, abort abort |
|
630 return result; |
|
631 } |
|
632 |
|
633 // If listbox handles the event, test if the selections have changed. |
|
634 if ( result == EKeyWasConsumed ) |
|
635 { |
|
636 // If newItemIndex is found (it is not KErrNotFound) and |
|
637 // if newItemIndex is not the same as oldItemIndex |
|
638 if ( newItemIndex != KErrNotFound |
|
639 && newItemIndex != oldItemIndex ) |
|
640 { |
|
641 // Check if the new item index has marked afterwards. |
|
642 TBool newItemMarkedAfter |
|
643 ( iListBox.View()->ItemIsSelected( newItemIndex ) ); |
|
644 |
|
645 // If new item selection has changed, send event. |
|
646 if ( newItemMarkedBefore != newItemMarkedAfter ) |
|
647 { |
|
648 // Send event about changed state |
|
649 TPbk2ControlEvent |
|
650 event( TPbk2ControlEvent::EContactSelected ); |
|
651 event.iInt = newItemIndex; |
|
652 if ( !newItemMarkedAfter ) |
|
653 { |
|
654 event.iEventType = |
|
655 TPbk2ControlEvent::EContactUnselected; |
|
656 } |
|
657 iEventSender.SendEventToObserversL( event ); |
|
658 |
|
659 //if commands marked, unmark it back |
|
660 if ( !IsContactAtListboxIndex( newItemIndex ) && newItemMarkedAfter ) |
|
661 { |
|
662 UnmarkCommands(); |
|
663 event.iEventType = TPbk2ControlEvent::EContactUnselected; |
|
664 iEventSender.SendEventToObserversL( event ); |
|
665 } |
|
666 } |
|
667 } |
|
668 |
|
669 // Check if old item's selection has changed and send event. |
|
670 TBool oldItemMarkedAfter |
|
671 ( iListBox.View()->ItemIsSelected( oldItemIndex ) ); |
|
672 if ( oldItemMarkedBefore != oldItemMarkedAfter ) |
|
673 { |
|
674 // Send event about changed state |
|
675 TPbk2ControlEvent |
|
676 event( TPbk2ControlEvent::EContactSelected ); |
|
677 event.iInt = oldItemIndex; |
|
678 if ( !oldItemMarkedAfter ) |
|
679 { |
|
680 event.iEventType = |
|
681 TPbk2ControlEvent::EContactUnselected; |
|
682 } |
|
683 iEventSender.SendEventToObserversL( event ); |
|
684 |
|
685 //if commands marked, unmark it back |
|
686 if ( !IsContactAtListboxIndex( oldItemIndex ) && oldItemMarkedAfter ) |
|
687 { |
|
688 UnmarkCommands(); |
|
689 event.iEventType = TPbk2ControlEvent::EContactUnselected; |
|
690 iEventSender.SendEventToObserversL( event ); |
|
691 } |
|
692 } |
|
693 } |
|
694 |
|
695 return result; |
|
696 } |
|
697 |
|
698 // -------------------------------------------------------------------------- |
|
699 // CPbk2NamesListReadyState::HandlePointerEventL |
|
700 // Event sending differs from OfferKeyEventL's solution on purpose. |
|
701 // -------------------------------------------------------------------------- |
|
702 // |
|
703 void CPbk2NamesListReadyState::HandlePointerEventL |
|
704 ( const TPointerEvent& aPointerEvent ) |
|
705 { |
|
706 iSearchFieldPointed = EFalse; |
|
707 if ( iFindBox ) |
|
708 { |
|
709 if ( iFindBox->Rect().Contains( aPointerEvent.iPosition ) ) |
|
710 { |
|
711 iFindBox->HandlePointerEventL( aPointerEvent ); |
|
712 iSearchFieldPointed = ETrue; |
|
713 } |
|
714 } |
|
715 |
|
716 TInt previousItemIndex = iListBox.CurrentItemIndex(); |
|
717 iListBox.HandlePointerEventL( aPointerEvent ); |
|
718 |
|
719 // Handle focus change when dragging |
|
720 if ( previousItemIndex != iListBox.CurrentItemIndex() && |
|
721 aPointerEvent.iType == TPointerEvent::EDrag ) |
|
722 { |
|
723 HandleFocusChangeL(); |
|
724 } |
|
725 |
|
726 if ( !iSearchFieldPointed && FocusableItemPointed() && |
|
727 aPointerEvent.iType == TPointerEvent::EButton1Up ) |
|
728 { |
|
729 // Send selection events based on marking |
|
730 TInt focusIndex = iListBox.CurrentItemIndex(); |
|
731 const TBool markedAfter = iListBox.View()->ItemIsSelected( focusIndex ); |
|
732 |
|
733 TPbk2ControlEvent event( TPbk2ControlEvent::EContactSelected ); |
|
734 event.iInt = focusIndex; |
|
735 if ( !markedAfter ) |
|
736 { |
|
737 event.iEventType = TPbk2ControlEvent::EContactUnselected; |
|
738 } |
|
739 iEventSender.SendEventToObserversL( event ); |
|
740 |
|
741 } |
|
742 |
|
743 TInt currentIndex = iListBox.CurrentItemIndex(); |
|
744 CPbk2PredictiveViewStack& predictiveViewStack = static_cast<CPbk2PredictiveViewStack&>( iViewStack ); |
|
745 |
|
746 TInt contactItemIndex = currentIndex - CommandItemCount(); |
|
747 if ( contactItemIndex >= 0 && iFindBox && iSearchFilter.IsPredictiveActivated() && iViewStack.Level() && |
|
748 !predictiveViewStack.IsNonMatchingMarkedContact( contactItemIndex ) ) |
|
749 { |
|
750 iSearchFilter.CommitFindPaneTextL( iViewStack, iNameFormatter, contactItemIndex ); |
|
751 } |
|
752 |
|
753 } |
|
754 |
|
755 // -------------------------------------------------------------------------- |
|
756 // CPbk2NamesListReadyState::NamesListState |
|
757 // -------------------------------------------------------------------------- |
|
758 // |
|
759 TInt CPbk2NamesListReadyState::NamesListState() const |
|
760 { |
|
761 return CPbk2NamesListControl::EStateReady; |
|
762 } |
|
763 |
|
764 // -------------------------------------------------------------------------- |
|
765 // CPbk2NamesListReadyState::HandleContactViewEventL |
|
766 // -------------------------------------------------------------------------- |
|
767 // |
|
768 void CPbk2NamesListReadyState::HandleContactViewEventL |
|
769 (TInt aEvent, TInt aIndex) |
|
770 { |
|
771 // need to calculate list index from contact |
|
772 // view index |
|
773 TInt listIndex = CommandItemCount() + aIndex; |
|
774 HandleListboxEventL(aEvent, listIndex, EFalse ); |
|
775 |
|
776 TInt currentFocusIndex = iListBox.CurrentItemIndex(); |
|
777 TBool marked = iListBox.View()->ItemIsSelected( currentFocusIndex ); |
|
778 |
|
779 //update findpane according to the new focused contact after delete operation. |
|
780 //Do nothing if the next focused contact is marked because it would not be found. |
|
781 if ( aEvent == MPbk2NamesListState::EItemRemoved |
|
782 && iSearchFilter.IsPredictiveActivated() |
|
783 && iViewStack.Level() |
|
784 && iFindBox |
|
785 && iFindBox->TextLength() != 0 |
|
786 && !marked) |
|
787 { |
|
788 iSearchFilter.CommitFindPaneTextL( iViewStack, iNameFormatter, currentFocusIndex ); |
|
789 } |
|
790 } |
|
791 |
|
792 // -------------------------------------------------------------------------- |
|
793 // CPbk2NamesListReadyState::HandleCommandEventL |
|
794 // -------------------------------------------------------------------------- |
|
795 // |
|
796 void CPbk2NamesListReadyState::HandleCommandEventL |
|
797 (TInt aEvent, TInt /* aCommandIndex*/ ) |
|
798 { |
|
799 HandleListboxEventL(aEvent, 0, ETrue ); |
|
800 } |
|
801 |
|
802 // -------------------------------------------------------------------------- |
|
803 // CPbk2NamesListReadyState::HandleListboxEventL |
|
804 // -------------------------------------------------------------------------- |
|
805 // |
|
806 void CPbk2NamesListReadyState::HandleListboxEventL |
|
807 (TInt aEvent, TInt aListboxIndex, TBool aMantainFocus ) |
|
808 { |
|
809 switch (aEvent) |
|
810 { |
|
811 case EItemAdded: |
|
812 { |
|
813 //contact added, grid might not have all necessary characters. |
|
814 //this could be optimized, we could just check the added contact and |
|
815 //update map if the performance is not enough |
|
816 UpdateAdaptiveSearchGridL( ETrue ); |
|
817 |
|
818 // Inform find box and list box |
|
819 UpdateFindBoxL(); |
|
820 |
|
821 TInt topIndex = iListBox.TopItemIndex(); |
|
822 iListBox.HandleEventL(aEvent, aListboxIndex); |
|
823 |
|
824 // Maintain focus |
|
825 // TODO: similar focus handling code in case item delete in iListBox.HandleEventL |
|
826 // to consider to move this focus code there as well |
|
827 if (aListboxIndex >= 0 && aListboxIndex < iListBox.NumberOfItems() ) |
|
828 { |
|
829 if ( aMantainFocus ) |
|
830 { |
|
831 //keep focused item and top item if its not 0 |
|
832 if ( aListboxIndex <= iListBox.CurrentItemIndex() && |
|
833 ( iListBox.CurrentItemIndex() + 1 ) < iListBox.NumberOfItems() ) |
|
834 { |
|
835 iListBox.SetCurrentItemIndex( |
|
836 iListBox.CurrentItemIndex() + 1 ); |
|
837 if ( topIndex > 0 && ( topIndex + 1 ) < iListBox.NumberOfItems() ) |
|
838 { |
|
839 iListBox.SetTopItemIndex( topIndex + 1 ); |
|
840 } |
|
841 } |
|
842 } |
|
843 else |
|
844 { |
|
845 //change focus to the added item |
|
846 if ( aListboxIndex != iListBox.CurrentItemIndex() ) |
|
847 { |
|
848 iListBox.SetCurrentItemIndex( aListboxIndex ); |
|
849 } |
|
850 } |
|
851 } |
|
852 |
|
853 iParent.DrawDeferred(); |
|
854 HandleFocusChangeL(); |
|
855 break; |
|
856 } |
|
857 case EItemRemoved: |
|
858 { |
|
859 //contact removed, grids might have unecessary characters |
|
860 UpdateAdaptiveSearchGridL( ETrue ); |
|
861 |
|
862 // Inform find box and list box |
|
863 UpdateFindBoxL(); |
|
864 iListBox.HandleEventL(aEvent, aListboxIndex); |
|
865 |
|
866 // Maintain focus |
|
867 if (aListboxIndex >= 0 && aListboxIndex < iListBox.NumberOfItems() ) |
|
868 { |
|
869 if ( aMantainFocus ) |
|
870 { |
|
871 //no op |
|
872 } |
|
873 else |
|
874 { |
|
875 //change focus |
|
876 if ( aListboxIndex != iListBox.CurrentItemIndex() ) |
|
877 { |
|
878 iListBox.SetCurrentItemIndex( aListboxIndex ); |
|
879 } |
|
880 } |
|
881 } |
|
882 |
|
883 iParent.DrawDeferred(); |
|
884 HandleFocusChangeL(); |
|
885 break; |
|
886 } |
|
887 case EContactViewUpdated: |
|
888 { |
|
889 UpdateAdaptiveSearchGridL( ETrue ); |
|
890 break; |
|
891 } |
|
892 default: |
|
893 { |
|
894 // Do nothing |
|
895 break; |
|
896 } |
|
897 } |
|
898 } |
|
899 |
|
900 // -------------------------------------------------------------------------- |
|
901 // CPbk2NamesListReadyState::CoeControl |
|
902 // -------------------------------------------------------------------------- |
|
903 // |
|
904 CCoeControl& CPbk2NamesListReadyState::CoeControl() |
|
905 { |
|
906 CCoeControl* tmp = NULL; |
|
907 return *static_cast<CCoeControl*>(tmp); |
|
908 } |
|
909 |
|
910 // -------------------------------------------------------------------------- |
|
911 // CPbk2NamesListReadyState::HandleControlEventL |
|
912 // -------------------------------------------------------------------------- |
|
913 // |
|
914 void CPbk2NamesListReadyState::HandleControlEventL( CCoeControl* aControl, |
|
915 MCoeControlObserver::TCoeEvent aEventType, TInt aParam ) |
|
916 { |
|
917 if ( aEventType == MCoeControlObserver::EEventStateChanged ) |
|
918 { |
|
919 // Find box |
|
920 if ( aControl == iFindBox ) |
|
921 { |
|
922 if( aParam ) |
|
923 { |
|
924 //means the search came from adaptive search grid |
|
925 if( iAdaptiveSearchGridFiller ) |
|
926 { |
|
927 iAdaptiveSearchGridFiller->InvalidateAdaptiveSearchGrid(); |
|
928 } |
|
929 } |
|
930 //if aParam is ETrue, it means that event came from adaptive search, which means |
|
931 //we do not want to delay filtering |
|
932 if ( ( !aParam ) && |
|
933 ( iFindDelay ) && |
|
934 ( NumberOfContacts() >= KFindDelayThresholdContacts ) ) |
|
935 { |
|
936 if ( iFindDelay->IsActive() ) |
|
937 { |
|
938 iFindDelay->Cancel(); |
|
939 } |
|
940 iFindDelay->After( TTimeIntervalMicroSeconds32( KFindDelayTime ) ); |
|
941 } |
|
942 else |
|
943 { |
|
944 UpdateFindResultL(); |
|
945 } |
|
946 } |
|
947 // List |
|
948 else if ( aControl == &iListBox ) |
|
949 { |
|
950 HandleFocusChangeL(); |
|
951 } |
|
952 } |
|
953 } |
|
954 |
|
955 // -------------------------------------------------------------------------- |
|
956 // CPbk2NamesListReadyState::TopContactL |
|
957 // -------------------------------------------------------------------------- |
|
958 // |
|
959 const MVPbkViewContact* CPbk2NamesListReadyState::TopContactL() |
|
960 { |
|
961 const MVPbkViewContact* contact = NULL; |
|
962 |
|
963 // There is an offset between listbox indexes and view indexes. |
|
964 const TInt topListboxIndex = iListBox.TopItemIndex(); |
|
965 const TInt enabledCommandCount = CommandItemCount(); |
|
966 // Check whether the index is valid. Also check whether the top |
|
967 // really is a contact. |
|
968 if ( topListboxIndex >= 0 && topListboxIndex >= enabledCommandCount ) |
|
969 { |
|
970 // Map from listbox index to view index |
|
971 contact = &iViewStack.ContactAtL( |
|
972 topListboxIndex - enabledCommandCount ); |
|
973 } |
|
974 return contact; |
|
975 } |
|
976 |
|
977 // -------------------------------------------------------------------------- |
|
978 // CPbk2NamesListReadyState::ParentControl |
|
979 // -------------------------------------------------------------------------- |
|
980 // |
|
981 MPbk2ContactUiControl* CPbk2NamesListReadyState::ParentControl() const |
|
982 { |
|
983 // Names list control does not have a parent control |
|
984 return NULL; |
|
985 } |
|
986 |
|
987 // -------------------------------------------------------------------------- |
|
988 // CPbk2NamesListReadyState::NumberOfContacts |
|
989 // -------------------------------------------------------------------------- |
|
990 // |
|
991 TInt CPbk2NamesListReadyState::NumberOfContacts() const |
|
992 { |
|
993 // The listbox can also have command items. |
|
994 TInt result = iListBox.NumberOfItems() - CommandItemCount(); |
|
995 if ( result < 0 ) |
|
996 { |
|
997 result = 0; // No contacts |
|
998 } |
|
999 return result; |
|
1000 } |
|
1001 |
|
1002 // -------------------------------------------------------------------------- |
|
1003 // CPbk2NamesListReadyState::FocusedContactL |
|
1004 // -------------------------------------------------------------------------- |
|
1005 // |
|
1006 const MVPbkBaseContact* CPbk2NamesListReadyState::FocusedContactL() const |
|
1007 { |
|
1008 return FocusedViewContactL(); |
|
1009 } |
|
1010 |
|
1011 // -------------------------------------------------------------------------- |
|
1012 // CPbk2NamesListReadyState::FocusedViewContactL |
|
1013 // -------------------------------------------------------------------------- |
|
1014 // |
|
1015 const MVPbkViewContact* CPbk2NamesListReadyState::FocusedViewContactL() const |
|
1016 { |
|
1017 const MVPbkViewContact* contact = NULL; |
|
1018 |
|
1019 // There is an offset between listbox indexes and view indexes. |
|
1020 const TInt focusListboxIndex = iListBox.CurrentItemIndex(); |
|
1021 const TInt enabledCommandCount = CommandItemCount(); |
|
1022 // Is the focus on a contact. Check... |
|
1023 if (focusListboxIndex >= 0 && focusListboxIndex >= enabledCommandCount ) |
|
1024 { |
|
1025 // Yes, the focus is on a contact. |
|
1026 // Map from listbox index to view index |
|
1027 contact = &iViewStack.ContactAtL( |
|
1028 focusListboxIndex - enabledCommandCount ); |
|
1029 } |
|
1030 return contact; |
|
1031 } |
|
1032 |
|
1033 // -------------------------------------------------------------------------- |
|
1034 // CPbk2NamesListReadyState::FocusedStoreContact |
|
1035 // -------------------------------------------------------------------------- |
|
1036 // |
|
1037 const MVPbkStoreContact* CPbk2NamesListReadyState::FocusedStoreContact() const |
|
1038 { |
|
1039 return NULL; |
|
1040 } |
|
1041 |
|
1042 // -------------------------------------------------------------------------- |
|
1043 // CPbk2NamesListReadyState::SetFocusedContactL |
|
1044 // -------------------------------------------------------------------------- |
|
1045 // |
|
1046 void CPbk2NamesListReadyState::SetFocusedContactL |
|
1047 ( const MVPbkBaseContact& aContact ) |
|
1048 { |
|
1049 SetFocusedContactL( KErrNotSupported, &aContact ); |
|
1050 } |
|
1051 |
|
1052 // -------------------------------------------------------------------------- |
|
1053 // CPbk2NamesListReadyState::SetFocusedContactL |
|
1054 // -------------------------------------------------------------------------- |
|
1055 // |
|
1056 void CPbk2NamesListReadyState::SetFocusedContactL |
|
1057 ( const MVPbkContactBookmark& aContactBookmark ) |
|
1058 { |
|
1059 TInt viewIndex = iViewStack.IndexOfBookmarkL( aContactBookmark ); |
|
1060 SetFocusedContactL( viewIndex, NULL ); |
|
1061 } |
|
1062 |
|
1063 // -------------------------------------------------------------------------- |
|
1064 // CPbk2NamesListReadyState::SetFocusedContactL |
|
1065 // -------------------------------------------------------------------------- |
|
1066 // |
|
1067 void CPbk2NamesListReadyState::SetFocusedContactL |
|
1068 ( const MVPbkContactLink& aContactLink ) |
|
1069 { |
|
1070 TInt viewIndex = iViewStack.IndexOfLinkL( aContactLink ); |
|
1071 SetFocusedContactL( viewIndex, NULL ); |
|
1072 } |
|
1073 |
|
1074 // -------------------------------------------------------------------------- |
|
1075 // CPbk2NamesListReadyState::FocusedContactIndex |
|
1076 // -------------------------------------------------------------------------- |
|
1077 // |
|
1078 TInt CPbk2NamesListReadyState::FocusedContactIndex() const |
|
1079 { |
|
1080 // The result is a view index. There is an offset between listbox indexes |
|
1081 // and view indexes. |
|
1082 |
|
1083 TInt viewIndex = KErrNotFound; |
|
1084 const TInt currentListboxIndex = iListBox.CurrentItemIndex(); |
|
1085 const TInt commandCount = CommandItemCount(); |
|
1086 // Is the focus on a contact or on a command item? Check: |
|
1087 if ( currentListboxIndex >= commandCount ) |
|
1088 { |
|
1089 // Yes, the focus is on a contact. |
|
1090 // Need to map from listbox indexes to view indexes. |
|
1091 viewIndex = currentListboxIndex - commandCount; |
|
1092 } |
|
1093 return viewIndex; |
|
1094 } |
|
1095 |
|
1096 // -------------------------------------------------------------------------- |
|
1097 // CPbk2NamesListReadyState::SetFocusedContactIndex |
|
1098 // -------------------------------------------------------------------------- |
|
1099 // |
|
1100 void CPbk2NamesListReadyState::SetFocusedContactIndexL( TInt aIndex ) |
|
1101 { |
|
1102 // The aIndex is a view index. There is an offset between listbox indexes |
|
1103 // and view indexes. |
|
1104 |
|
1105 if ( aIndex < 0 ) |
|
1106 { |
|
1107 aIndex = 0; |
|
1108 } |
|
1109 const TInt enabledCommandCount = CommandItemCount(); |
|
1110 if ( aIndex > iListBox.BottomItemIndex() - enabledCommandCount ) |
|
1111 { |
|
1112 aIndex = iListBox.BottomItemIndex() - enabledCommandCount; |
|
1113 } |
|
1114 |
|
1115 SetFocusedContactL( aIndex, NULL ); |
|
1116 } |
|
1117 |
|
1118 // -------------------------------------------------------------------------- |
|
1119 // CPbk2NamesListReadyState::NumberOfContactFields |
|
1120 // -------------------------------------------------------------------------- |
|
1121 // |
|
1122 TInt CPbk2NamesListReadyState::NumberOfContactFields() const |
|
1123 { |
|
1124 return KErrNotSupported; |
|
1125 } |
|
1126 |
|
1127 // -------------------------------------------------------------------------- |
|
1128 // CPbk2NamesListReadyState::FocusedField |
|
1129 // -------------------------------------------------------------------------- |
|
1130 // |
|
1131 const MVPbkBaseContactField* CPbk2NamesListReadyState::FocusedField() const |
|
1132 { |
|
1133 // There is no field level focus |
|
1134 return NULL; |
|
1135 } |
|
1136 |
|
1137 // -------------------------------------------------------------------------- |
|
1138 // CPbk2NamesListReadyState::FocusedFieldIndex |
|
1139 // -------------------------------------------------------------------------- |
|
1140 // |
|
1141 TInt CPbk2NamesListReadyState::FocusedFieldIndex() const |
|
1142 { |
|
1143 // There is no field level focus |
|
1144 return KErrNotFound; |
|
1145 } |
|
1146 |
|
1147 // -------------------------------------------------------------------------- |
|
1148 // CPbk2NamesListReadyState::SetFocusedFieldIndex |
|
1149 // -------------------------------------------------------------------------- |
|
1150 // |
|
1151 void CPbk2NamesListReadyState::SetFocusedFieldIndex( TInt /*aIndex*/ ) |
|
1152 { |
|
1153 // Do nothing |
|
1154 } |
|
1155 |
|
1156 // -------------------------------------------------------------------------- |
|
1157 // CPbk2NamesListReadyState::ContactsMarked |
|
1158 // -------------------------------------------------------------------------- |
|
1159 // |
|
1160 TBool CPbk2NamesListReadyState::ContactsMarked() const |
|
1161 { |
|
1162 return iListBox.ContactsMarked(); |
|
1163 } |
|
1164 |
|
1165 // -------------------------------------------------------------------------- |
|
1166 // CPbk2NamesListReadyState::SelectedContactsL |
|
1167 // -------------------------------------------------------------------------- |
|
1168 // |
|
1169 MVPbkContactLinkArray* |
|
1170 CPbk2NamesListReadyState::SelectedContactsL() const |
|
1171 { |
|
1172 // Get listbox selection indexes, a reference only |
|
1173 const CListBoxView::CSelectionIndexArray* selArray = |
|
1174 iListBox.SelectionIndexes(); |
|
1175 |
|
1176 |
|
1177 TInt count = 1; // initialize to one, because if there are |
|
1178 // no selections we operate with one focused contact |
|
1179 if (selArray) |
|
1180 { |
|
1181 count = selArray->Count(); |
|
1182 } |
|
1183 |
|
1184 CVPbkContactLinkArray* linkArray = NULL; |
|
1185 |
|
1186 if (count > 0) |
|
1187 { |
|
1188 linkArray = CVPbkContactLinkArray::NewLC(); |
|
1189 |
|
1190 // Loop through the selections and construct a link for |
|
1191 // each of the contacts |
|
1192 const TInt commandItemCount = CommandItemCount(); |
|
1193 for (TInt i=0; i<count; ++i) |
|
1194 { |
|
1195 const TInt singleSelection = selArray->At(i); |
|
1196 if ( IsContactAtListboxIndex( singleSelection ) ) |
|
1197 { |
|
1198 // Take the view contact from the view, the ownership |
|
1199 // stays at the view |
|
1200 const MVPbkViewContact* contact = |
|
1201 &iViewStack.ContactAtL( singleSelection - commandItemCount ); |
|
1202 MVPbkContactLink* link = contact->CreateLinkLC(); |
|
1203 if (link) |
|
1204 { |
|
1205 linkArray->AppendL(link); |
|
1206 CleanupStack::Pop(); // the array takes ownership of the link |
|
1207 } |
|
1208 } |
|
1209 } |
|
1210 |
|
1211 CleanupStack::Pop(linkArray); |
|
1212 } |
|
1213 |
|
1214 return linkArray; |
|
1215 } |
|
1216 |
|
1217 // -------------------------------------------------------------------------- |
|
1218 // CPbk2NamesListReadyState::SelectedContactsOrFocusedContactL |
|
1219 // -------------------------------------------------------------------------- |
|
1220 // |
|
1221 MVPbkContactLinkArray* |
|
1222 CPbk2NamesListReadyState::SelectedContactsOrFocusedContactL() const |
|
1223 { |
|
1224 MVPbkContactLinkArray* result = NULL; |
|
1225 result = SelectedContactsL(); |
|
1226 |
|
1227 if ( !result ) |
|
1228 { |
|
1229 CVPbkContactLinkArray* array = CVPbkContactLinkArray::NewLC(); |
|
1230 const MVPbkBaseContact* focusedContact = FocusedContactL(); |
|
1231 if ( focusedContact ) |
|
1232 { |
|
1233 MVPbkContactLink* link = focusedContact->CreateLinkLC(); |
|
1234 CleanupStack::Pop(); // link |
|
1235 array->AppendL( link ); |
|
1236 } |
|
1237 else |
|
1238 { |
|
1239 // there was no focused contact, check if this is the my card |
|
1240 AppendMyCardLinkIfExistL( *array ); |
|
1241 } |
|
1242 CleanupStack::Pop(); // array |
|
1243 result = array; |
|
1244 } |
|
1245 |
|
1246 return result; |
|
1247 } |
|
1248 |
|
1249 // -------------------------------------------------------------------------- |
|
1250 // CPbk2NamesListReadyState::AppendMyCardLinkIfExistL |
|
1251 // -------------------------------------------------------------------------- |
|
1252 // |
|
1253 void CPbk2NamesListReadyState::AppendMyCardLinkIfExistL( CVPbkContactLinkArray& aArray ) const |
|
1254 { |
|
1255 TInt currentItem = iListBox.CurrentItemIndex(); |
|
1256 // if focused index is command item |
|
1257 if( currentItem < CommandItemCount() ) |
|
1258 { |
|
1259 // check if the command is my card ( this search is copied from CommandItemAt - function to avoid const cast) |
|
1260 // Some of the commands might be disabled. Skip those. |
|
1261 TInt enabledCount = 0; |
|
1262 TInt indexOfResult = KErrNotFound; |
|
1263 for ( TInt n = 0; n < iCommandItems.Count() && indexOfResult == KErrNotFound; ++n ) |
|
1264 { |
|
1265 if ( iCommandItems[ n ]->IsEnabled() ) |
|
1266 { |
|
1267 enabledCount++; |
|
1268 if ( enabledCount-1 == currentItem ) |
|
1269 { |
|
1270 indexOfResult = n; |
|
1271 } |
|
1272 } |
|
1273 } |
|
1274 MPbk2UiControlCmdItem* item = iCommandItems[ indexOfResult ]; |
|
1275 // check if the command item was a my card |
|
1276 if( item->CommandId() == EPbk2CmdOpenMyCard ) |
|
1277 { |
|
1278 // get extension point and my card link |
|
1279 TAny* object = item->ControlCmdItemExtension( TUid::Uid( KPbk2ControlCmdItemExtensionUID ) ); |
|
1280 if( object ) |
|
1281 { |
|
1282 MPbk2DoubleListboxCmdItemExtension* extension = |
|
1283 static_cast<MPbk2DoubleListboxCmdItemExtension*>( object ); |
|
1284 // if extension exists |
|
1285 if( extension ) |
|
1286 { |
|
1287 const MVPbkContactLink* link = extension->Link(); |
|
1288 // if link exists, add it to the array |
|
1289 if( link ) |
|
1290 { |
|
1291 aArray.AppendL( link->CloneLC() ); |
|
1292 CleanupStack::Pop(); |
|
1293 } |
|
1294 } |
|
1295 } |
|
1296 } |
|
1297 } |
|
1298 } |
|
1299 |
|
1300 |
|
1301 // -------------------------------------------------------------------------- |
|
1302 // CPbk2NamesListReadyState::SelectedContactsIteratorL |
|
1303 // -------------------------------------------------------------------------- |
|
1304 // |
|
1305 MPbk2ContactLinkIterator* |
|
1306 CPbk2NamesListReadyState::SelectedContactsIteratorL() const |
|
1307 { |
|
1308 // Get listbox selection indexes, a reference only |
|
1309 const CListBoxView::CSelectionIndexArray* selArray = |
|
1310 iListBox.SelectionIndexes(); |
|
1311 |
|
1312 TInt count = 0; |
|
1313 if ( selArray ) |
|
1314 { |
|
1315 count = selArray->Count(); |
|
1316 } |
|
1317 |
|
1318 MPbk2ContactLinkIterator* iterator = NULL; |
|
1319 |
|
1320 if ( count > 0 ) |
|
1321 { |
|
1322 // Need to map the listbox indexes to view indexes. |
|
1323 // Also need to filter out cmd items. |
|
1324 iIteratorIndexes.Reset(); |
|
1325 const TInt commandItemCount = CommandItemCount(); |
|
1326 const TInt selectionCount = selArray->Count(); |
|
1327 for ( TInt n = 0; n < selectionCount; ++n ) |
|
1328 { |
|
1329 const TInt listboxIndex = selArray->At( n ); |
|
1330 if ( listboxIndex >= commandItemCount) |
|
1331 { |
|
1332 // It is a contact. |
|
1333 // Do a mapping from listbox index to view index |
|
1334 iIteratorIndexes.AppendL( listboxIndex - commandItemCount ); |
|
1335 } |
|
1336 } |
|
1337 iterator = CPbk2ContactViewIterator::NewLC |
|
1338 ( iViewStack, iIteratorIndexes.Array() ); |
|
1339 CleanupStack::Pop(); // iterator |
|
1340 } |
|
1341 |
|
1342 return iterator; |
|
1343 } |
|
1344 |
|
1345 // -------------------------------------------------------------------------- |
|
1346 // CPbk2NamesListReadyState::SelectedContactStoresL |
|
1347 // -------------------------------------------------------------------------- |
|
1348 // |
|
1349 CArrayPtr<MVPbkContactStore>* |
|
1350 CPbk2NamesListReadyState::SelectedContactStoresL() const |
|
1351 { |
|
1352 // This is not a state of the contact store control |
|
1353 return NULL; |
|
1354 } |
|
1355 |
|
1356 // -------------------------------------------------------------------------- |
|
1357 // CPbk2NamesListReadyState::ClearMarks |
|
1358 // -------------------------------------------------------------------------- |
|
1359 // |
|
1360 void CPbk2NamesListReadyState::ClearMarks() |
|
1361 { |
|
1362 iListBox.View()->ClearSelection(); |
|
1363 } |
|
1364 |
|
1365 // -------------------------------------------------------------------------- |
|
1366 // CPbk2NamesListReadyState::SetSelectedContactL |
|
1367 // -------------------------------------------------------------------------- |
|
1368 // |
|
1369 void CPbk2NamesListReadyState::SetSelectedContactL |
|
1370 ( TInt aIndex, TBool aSelected ) |
|
1371 { |
|
1372 if ( aSelected ) |
|
1373 { |
|
1374 iListBox.View()->SelectItemL( aIndex ); |
|
1375 } |
|
1376 else |
|
1377 { |
|
1378 iListBox.View()->DeselectItem( aIndex ); |
|
1379 } |
|
1380 } |
|
1381 |
|
1382 // -------------------------------------------------------------------------- |
|
1383 // CPbk2NamesListReadyState::SetSelectedContactL |
|
1384 // -------------------------------------------------------------------------- |
|
1385 // |
|
1386 void CPbk2NamesListReadyState::SetSelectedContactL( |
|
1387 const MVPbkContactBookmark& aContactBookmark, |
|
1388 TBool aSelected ) |
|
1389 { |
|
1390 TInt index = iViewStack.IndexOfBookmarkL( aContactBookmark ); |
|
1391 if ( index != KErrNotFound ) |
|
1392 { |
|
1393 SetSelectedContactL( index, aSelected ); |
|
1394 } |
|
1395 } |
|
1396 |
|
1397 // -------------------------------------------------------------------------- |
|
1398 // CPbk2NamesListReadyState::SetSelectedContactL |
|
1399 // -------------------------------------------------------------------------- |
|
1400 // |
|
1401 void CPbk2NamesListReadyState::SetSelectedContactL( |
|
1402 const MVPbkContactLink& aContactLink, |
|
1403 TBool aSelected ) |
|
1404 { |
|
1405 TInt index = iViewStack.IndexOfLinkL( aContactLink ); |
|
1406 if ( index != KErrNotFound ) |
|
1407 { |
|
1408 SetSelectedContactL( index, aSelected ); |
|
1409 } |
|
1410 } |
|
1411 |
|
1412 |
|
1413 TInt CPbk2NamesListReadyState::CommandItemCount() const |
|
1414 { |
|
1415 // Some of the commands might be disabled. Don't count those. |
|
1416 TInt enabledCommandCount = 0; |
|
1417 for ( TInt n = 0; n < iCommandItems.Count(); ++n ) |
|
1418 { |
|
1419 if ( iCommandItems[ n ]->IsEnabled() ) |
|
1420 { |
|
1421 enabledCommandCount++; |
|
1422 } |
|
1423 } |
|
1424 return enabledCommandCount; |
|
1425 } |
|
1426 |
|
1427 const MPbk2UiControlCmdItem& |
|
1428 CPbk2NamesListReadyState::CommandItemAt( TInt aIndex ) const |
|
1429 { |
|
1430 // Some of the commands might be disabled. Skip those. |
|
1431 TInt enabledCount = 0; |
|
1432 TInt indexOfResult = KErrNotFound; |
|
1433 |
|
1434 for ( TInt n = 0; n < iCommandItems.Count()&& indexOfResult == KErrNotFound; ++n ) |
|
1435 { |
|
1436 if ( iCommandItems[ n ]->IsEnabled() ) |
|
1437 { |
|
1438 enabledCount++; |
|
1439 if ( enabledCount-1 == aIndex ) |
|
1440 { |
|
1441 indexOfResult = n; |
|
1442 } |
|
1443 } |
|
1444 } |
|
1445 |
|
1446 return *iCommandItems[ indexOfResult ]; |
|
1447 } |
|
1448 |
|
1449 const MPbk2UiControlCmdItem* |
|
1450 CPbk2NamesListReadyState::FocusedCommandItem() const |
|
1451 { |
|
1452 const MPbk2UiControlCmdItem* cmdItem = NULL; |
|
1453 // Is the focus on a command item: |
|
1454 TInt focusListIndex = iListBox.CurrentItemIndex(); |
|
1455 const TInt commandItemCount = CommandItemCount(); |
|
1456 if ( focusListIndex != KErrNotFound && focusListIndex < commandItemCount ) |
|
1457 { |
|
1458 // Yes it's a command item. |
|
1459 cmdItem = &CommandItemAt(focusListIndex); |
|
1460 } |
|
1461 return cmdItem; |
|
1462 } |
|
1463 |
|
1464 void CPbk2NamesListReadyState::DeleteCommandItemL( TInt /*aIndex*/ ) |
|
1465 { |
|
1466 // ownership & management of iCommandItems is wasted in names list |
|
1467 // control. Do nothing here |
|
1468 } |
|
1469 |
|
1470 void CPbk2NamesListReadyState::AddCommandItemL(MPbk2UiControlCmdItem* /*aCommand*/, TInt /*aIndex*/) |
|
1471 { |
|
1472 // ownership & management of iCommandItems is wasted in names list |
|
1473 // control. Do nothing here |
|
1474 } |
|
1475 |
|
1476 // -------------------------------------------------------------------------- |
|
1477 // CPbk2NamesListReadyState::DynInitMenuPaneL |
|
1478 // -------------------------------------------------------------------------- |
|
1479 // |
|
1480 void CPbk2NamesListReadyState::DynInitMenuPaneL( |
|
1481 TInt aResourceId, CEikMenuPane* aMenuPane) const |
|
1482 { |
|
1483 AknSelectionService::HandleMarkableListDynInitMenuPane |
|
1484 (aResourceId, aMenuPane, &iListBox); |
|
1485 |
|
1486 TInt focusedItem = iListBox.View()->CurrentItemIndex(); |
|
1487 TBool markHidden = iListBox.View()->ItemIsSelected( focusedItem ); |
|
1488 TBool unmarkHidden = !iListBox.View()->ItemIsSelected( focusedItem ); |
|
1489 TBool markAllHidden = ( iListBox.Model()->NumberOfItems() == 0 ) || |
|
1490 ( iListBox.SelectionIndexes()->Count() == iListBox.Model()->NumberOfItems() ); |
|
1491 TBool unmarkAllHidden = ( iListBox.Model()->NumberOfItems() == 0 ) || |
|
1492 ( iListBox.SelectionIndexes()->Count() == 0 ); |
|
1493 |
|
1494 TInt position; |
|
1495 if (aMenuPane->MenuItemExists(EAknCmdMark, position)) |
|
1496 { |
|
1497 aMenuPane->SetItemDimmed(EAknCmdMark, markHidden); |
|
1498 } |
|
1499 if (aMenuPane->MenuItemExists(EAknCmdUnmark, position)) |
|
1500 { |
|
1501 aMenuPane->SetItemDimmed(EAknCmdUnmark, unmarkHidden); |
|
1502 } |
|
1503 if (aMenuPane->MenuItemExists(EAknMarkAll, position)) |
|
1504 { |
|
1505 aMenuPane->SetItemDimmed(EAknMarkAll, markAllHidden); |
|
1506 } |
|
1507 if (aMenuPane->MenuItemExists(EAknUnmarkAll, position)) |
|
1508 { |
|
1509 aMenuPane->SetItemDimmed(EAknUnmarkAll, unmarkAllHidden); |
|
1510 } |
|
1511 |
|
1512 // When all contacts are marked in the listbox, the command items are not marked. |
|
1513 // This code snippet dims out the Mark All menu item which is shown since the |
|
1514 // list box cannot differentiate a command and a contact item |
|
1515 |
|
1516 TInt commandItemCount = CommandItemCount(); |
|
1517 |
|
1518 |
|
1519 if ((iListBox.SelectionIndexes()->Count() + commandItemCount ) == iListBox.Model()->NumberOfItems()) |
|
1520 { |
|
1521 TInt i; // Stores the position of the searched menu item. |
|
1522 // This position is not needed or used anywhere |
|
1523 if (aMenuPane->MenuItemExists(EAknMarkAll, i)) |
|
1524 { |
|
1525 aMenuPane->SetItemDimmed(EAknMarkAll, ETrue); |
|
1526 } |
|
1527 } |
|
1528 |
|
1529 // If there's any, command items are always placed at the top of the list box. |
|
1530 // By comparing the list box current item index with the command item count, we are trying to find out |
|
1531 // if the current focused item is command item or not. |
|
1532 |
|
1533 } |
|
1534 |
|
1535 // -------------------------------------------------------------------------- |
|
1536 // CPbk2NamesListReadyState::ProcessCommandL |
|
1537 // -------------------------------------------------------------------------- |
|
1538 // |
|
1539 void CPbk2NamesListReadyState::ProcessCommandL |
|
1540 (TInt aCommandId) const |
|
1541 { |
|
1542 AknSelectionService::HandleMarkableListProcessCommandL |
|
1543 (aCommandId, &iListBox); |
|
1544 |
|
1545 // Send event |
|
1546 TPbk2ControlEvent event( TPbk2ControlEvent::EContactSelected ); |
|
1547 event.iInt = iListBox.CurrentItemIndex(); |
|
1548 |
|
1549 switch( aCommandId ) |
|
1550 { |
|
1551 case EAknCmdMark: |
|
1552 case EAknMarkAll: |
|
1553 { |
|
1554 // Send event about changed state |
|
1555 iEventSender.SendEventToObserversL( event ); |
|
1556 // commands should stay unmarked |
|
1557 UnmarkCommands(); |
|
1558 break; |
|
1559 } |
|
1560 |
|
1561 case EAknCmdUnmark: |
|
1562 { |
|
1563 event.iEventType = TPbk2ControlEvent::EContactUnselected; |
|
1564 iEventSender.SendEventToObserversL( event ); |
|
1565 break; |
|
1566 } |
|
1567 |
|
1568 case EAknUnmarkAll: |
|
1569 { |
|
1570 // Send event about changed state |
|
1571 event.iEventType = TPbk2ControlEvent::EContactUnselectedAll; |
|
1572 iEventSender.SendEventToObserversL( event ); |
|
1573 break; |
|
1574 } |
|
1575 |
|
1576 default:; |
|
1577 } |
|
1578 } |
|
1579 |
|
1580 // -------------------------------------------------------------------------- |
|
1581 // CPbk2NamesListReadyState::UpdateAfterCommandExecution |
|
1582 // -------------------------------------------------------------------------- |
|
1583 // |
|
1584 void CPbk2NamesListReadyState::UpdateAfterCommandExecution() |
|
1585 { |
|
1586 // Do nothing |
|
1587 } |
|
1588 |
|
1589 // -------------------------------------------------------------------------- |
|
1590 // CPbk2NamesListReadyState::GetMenuFilteringFlagsL |
|
1591 // -------------------------------------------------------------------------- |
|
1592 // |
|
1593 TInt CPbk2NamesListReadyState::GetMenuFilteringFlagsL() const |
|
1594 { |
|
1595 TInt ret = KPbk2ListContainsItems; |
|
1596 if (ContactsMarked()) |
|
1597 { |
|
1598 ret |= KPbk2ListContainsMarkedItems; |
|
1599 } |
|
1600 else |
|
1601 { |
|
1602 ret |= KPbk2ListContainsNoMarkedItems; |
|
1603 } |
|
1604 |
|
1605 TInt focusIndex = iListBox.CurrentItemIndex(); |
|
1606 // Non-contact items are not expandable. |
|
1607 const TInt commandItemCount = CommandItemCount(); |
|
1608 if ( focusIndex < commandItemCount ) |
|
1609 { |
|
1610 // It is not a contact. |
|
1611 focusIndex = KErrNotFound; |
|
1612 } |
|
1613 |
|
1614 // There is an offset between view indexes and listbox indexes. |
|
1615 if (focusIndex >= 0 && |
|
1616 iViewStack.ContactAtL(focusIndex - commandItemCount).Expandable()) |
|
1617 { |
|
1618 ret |= KPbk2FocusedItemIsExpandable; |
|
1619 } |
|
1620 |
|
1621 return ret; |
|
1622 } |
|
1623 |
|
1624 // -------------------------------------------------------------------------- |
|
1625 // CPbk2NamesListReadyState::ControlStateL |
|
1626 // -------------------------------------------------------------------------- |
|
1627 // |
|
1628 CPbk2ViewState* CPbk2NamesListReadyState::ControlStateL() const |
|
1629 { |
|
1630 // State objects do not handle control state changes |
|
1631 return NULL; |
|
1632 } |
|
1633 |
|
1634 // -------------------------------------------------------------------------- |
|
1635 // CPbk2NamesListReadyState::SetFocusedContactL |
|
1636 // -------------------------------------------------------------------------- |
|
1637 // |
|
1638 void CPbk2NamesListReadyState::SetFocusedContactL( TInt aIndex, |
|
1639 const MVPbkBaseContact* aContact ) |
|
1640 { |
|
1641 // The aIndex is a view index. There is an offset between listbox indexes |
|
1642 // and view indexes. |
|
1643 |
|
1644 TInt viewIndex = KErrNotReady; |
|
1645 |
|
1646 if ( aContact ) |
|
1647 { |
|
1648 MVPbkContactBookmark* bookmark = aContact->CreateBookmarkLC(); |
|
1649 TInt contactIndex = iViewStack.IndexOfBookmarkL( *bookmark ); |
|
1650 CleanupStack::PopAndDestroy(); // bookmark |
|
1651 |
|
1652 if ( contactIndex >= 0 && |
|
1653 contactIndex < iViewStack.ContactCountL() ) |
|
1654 { |
|
1655 viewIndex = contactIndex; |
|
1656 } |
|
1657 } |
|
1658 |
|
1659 if ( viewIndex == KErrNotReady ) |
|
1660 { |
|
1661 if ( aIndex >= 0 && |
|
1662 aIndex < iViewStack.ContactCountL() ) |
|
1663 { |
|
1664 viewIndex = aIndex; |
|
1665 } |
|
1666 } |
|
1667 |
|
1668 // Need to map current listbox index to view indexes. |
|
1669 // But at the same time check whether the current item is a contact. |
|
1670 const TInt enabledCommandCount = CommandItemCount(); |
|
1671 TInt currentContactAsViewIndex = KErrNotReady; |
|
1672 if ( iListBox.CurrentItemIndex() >= enabledCommandCount ) |
|
1673 { |
|
1674 // Yes, the current item is a contact. |
|
1675 currentContactAsViewIndex = |
|
1676 iListBox.CurrentItemIndex() - enabledCommandCount; |
|
1677 } |
|
1678 |
|
1679 // If index is valid, and not already the current one, then use it to set |
|
1680 // the current item. |
|
1681 if ( viewIndex != KErrNotReady && viewIndex != currentContactAsViewIndex ) |
|
1682 { |
|
1683 iListBox.SetCurrentItemIndex( viewIndex + enabledCommandCount ); |
|
1684 // Force hiding of thumbnail from previously focused contact |
|
1685 HideThumbnail(); |
|
1686 HandleFocusChangeL(); |
|
1687 } |
|
1688 |
|
1689 // Should be drawn always to be sure that UI is updated |
|
1690 iParent.DrawDeferred(); |
|
1691 } |
|
1692 |
|
1693 // -------------------------------------------------------------------------- |
|
1694 // CPbk2NamesListReadyState::RestoreControlStateL |
|
1695 // -------------------------------------------------------------------------- |
|
1696 // |
|
1697 void CPbk2NamesListReadyState::RestoreControlStateL |
|
1698 (CPbk2ViewState* aState) |
|
1699 { |
|
1700 TBool redraw = EFalse; |
|
1701 if (aState->Flags() & CPbk2ViewState::EInitialized) |
|
1702 { |
|
1703 iListBox.Reset(); |
|
1704 redraw = ETrue; |
|
1705 } |
|
1706 else |
|
1707 { |
|
1708 if (iViewStack.ContactCountL() > 0) |
|
1709 { |
|
1710 if (aState->Flags() & CPbk2ViewState::EFocusFirst) |
|
1711 { |
|
1712 iListBox.SetCurrentItemIndex(0); |
|
1713 } |
|
1714 else if (aState->Flags() & CPbk2ViewState::EFocusLast) |
|
1715 { |
|
1716 iListBox.SetCurrentItemIndex(iListBox.Model()->NumberOfItems()-1); |
|
1717 } |
|
1718 else |
|
1719 { |
|
1720 // Restore top contact |
|
1721 const MVPbkContactLink* topContact = aState->TopContact(); |
|
1722 if (topContact) |
|
1723 { |
|
1724 const TInt viewIndex = iViewStack.IndexOfLinkL(*topContact); |
|
1725 if (viewIndex >= 0) |
|
1726 { |
|
1727 const TInt prevListboxIndex = iListBox.TopItemIndex(); |
|
1728 // There is an offset between listbox indexes |
|
1729 // and view indexes. |
|
1730 const TInt listboxIndex = viewIndex + CommandItemCount(); |
|
1731 iListBox.SetTopItemIndex(listboxIndex); |
|
1732 iListBox.FixTopItemIndex(); |
|
1733 if (listboxIndex != prevListboxIndex) |
|
1734 { |
|
1735 redraw = ETrue; |
|
1736 } |
|
1737 } |
|
1738 } |
|
1739 |
|
1740 const MVPbkContactLink* focusedContact = aState->FocusedContact(); |
|
1741 if (focusedContact) |
|
1742 { |
|
1743 const TInt viewIndex = |
|
1744 iViewStack.IndexOfLinkL(*focusedContact); |
|
1745 if (viewIndex >= 0) |
|
1746 { |
|
1747 const TInt prevListboxIndex = iListBox.CurrentItemIndex(); |
|
1748 // There is an offset between listbox indexes |
|
1749 // and view indexes. |
|
1750 const TInt listboxIndex = viewIndex + CommandItemCount(); |
|
1751 iListBox.SetCurrentItemIndex(listboxIndex); |
|
1752 if (listboxIndex != prevListboxIndex) |
|
1753 { |
|
1754 redraw = ETrue; |
|
1755 } |
|
1756 } |
|
1757 } |
|
1758 } |
|
1759 // Restore selections |
|
1760 const MVPbkContactLinkArray* markedContacts = |
|
1761 aState->MarkedContacts(); |
|
1762 if (RestoreMarkedContactsL(markedContacts)) |
|
1763 { |
|
1764 redraw = ETrue; |
|
1765 } |
|
1766 } |
|
1767 } |
|
1768 if (redraw) |
|
1769 { |
|
1770 iParent.DrawDeferred(); |
|
1771 iListBox.UpdateScrollBarsL(); |
|
1772 HandleFocusChangeL(); |
|
1773 } |
|
1774 } |
|
1775 |
|
1776 // -------------------------------------------------------------------------- |
|
1777 // CPbk2NamesListReadyState::FindTextL |
|
1778 // -------------------------------------------------------------------------- |
|
1779 // |
|
1780 const TDesC& CPbk2NamesListReadyState::FindTextL() |
|
1781 { |
|
1782 if ( iFindBox ) |
|
1783 { |
|
1784 TPbk2FindTextUtil::EnsureFindTextBufSizeL( |
|
1785 *iFindBox, |
|
1786 &iFindTextBuf ); |
|
1787 TPtr bufPtr = iFindTextBuf->Des(); |
|
1788 iFindBox->GetSearchText(bufPtr); |
|
1789 return *iFindTextBuf; |
|
1790 } |
|
1791 |
|
1792 return KNullDesC; |
|
1793 } |
|
1794 |
|
1795 |
|
1796 // -------------------------------------------------------------------------- |
|
1797 // CPbk2NamesListReadyState::ResetFindL |
|
1798 // -------------------------------------------------------------------------- |
|
1799 // |
|
1800 void CPbk2NamesListReadyState::ResetFindL() |
|
1801 { |
|
1802 if ( iFindBox && iFindBox->TextLength() > 0 ) |
|
1803 { |
|
1804 iSearchFilter.ResetL(); |
|
1805 iFindBox->ResetL(); |
|
1806 iViewStack.Reset(); |
|
1807 iFindBox->DrawDeferred(); |
|
1808 } |
|
1809 } |
|
1810 |
|
1811 // -------------------------------------------------------------------------- |
|
1812 // CPbk2NamesListReadyState::HideThumbnail |
|
1813 // -------------------------------------------------------------------------- |
|
1814 // |
|
1815 void CPbk2NamesListReadyState::HideThumbnail() |
|
1816 { |
|
1817 } |
|
1818 |
|
1819 // -------------------------------------------------------------------------- |
|
1820 // CPbk2NamesListReadyState::ShowThumbnail |
|
1821 // -------------------------------------------------------------------------- |
|
1822 // |
|
1823 void CPbk2NamesListReadyState::ShowThumbnail() |
|
1824 { |
|
1825 } |
|
1826 |
|
1827 // -------------------------------------------------------------------------- |
|
1828 // CPbk2NamesListReadyState::SetBlank |
|
1829 // -------------------------------------------------------------------------- |
|
1830 // |
|
1831 void CPbk2NamesListReadyState::SetBlank(TBool aBlank) |
|
1832 { |
|
1833 if (!aBlank) |
|
1834 { |
|
1835 // Redraw |
|
1836 iParent.DrawDeferred(); |
|
1837 TRAPD( error, |
|
1838 iListBox.UpdateScrollBarsL(); |
|
1839 HandleFocusChangeL(); |
|
1840 ); |
|
1841 if ( error != KErrNone ) |
|
1842 { |
|
1843 CCoeEnv::Static()->HandleError( error ); |
|
1844 } |
|
1845 } |
|
1846 } |
|
1847 |
|
1848 // -------------------------------------------------------------------------- |
|
1849 // CPbk2NamesListReadyState::RegisterCommand |
|
1850 // -------------------------------------------------------------------------- |
|
1851 // |
|
1852 void CPbk2NamesListReadyState::RegisterCommand( |
|
1853 MPbk2Command* /*aCommand*/ ) |
|
1854 { |
|
1855 // Do nothing |
|
1856 } |
|
1857 |
|
1858 // -------------------------------------------------------------------------- |
|
1859 // CPbk2NamesListReadyState::SetTextL |
|
1860 // -------------------------------------------------------------------------- |
|
1861 // |
|
1862 void CPbk2NamesListReadyState::SetTextL( const TDesC& aText ) |
|
1863 { |
|
1864 iListBox.View()->SetListEmptyTextL( aText ); |
|
1865 } |
|
1866 |
|
1867 // -------------------------------------------------------------------------- |
|
1868 // CPbk2NamesListReadyState::ContactUiControlExtension |
|
1869 // -------------------------------------------------------------------------- |
|
1870 // |
|
1871 TAny* CPbk2NamesListReadyState::ContactUiControlExtension(TUid aExtensionUid ) |
|
1872 { |
|
1873 if( aExtensionUid == KMPbk2ContactUiControlExtension2Uid ) |
|
1874 { |
|
1875 return static_cast<MPbk2ContactUiControl2*>( this ); |
|
1876 } |
|
1877 |
|
1878 return NULL; |
|
1879 } |
|
1880 |
|
1881 // -------------------------------------------------------------------------- |
|
1882 // CPbk2NamesListReadyState::FocusedItemPointed |
|
1883 // -------------------------------------------------------------------------- |
|
1884 // |
|
1885 TBool CPbk2NamesListReadyState::FocusedItemPointed() |
|
1886 { |
|
1887 return iListBox.FocusedItemPointed(); |
|
1888 } |
|
1889 |
|
1890 // -------------------------------------------------------------------------- |
|
1891 // CPbk2NamesListReadyState::FocusableItemPointed |
|
1892 // -------------------------------------------------------------------------- |
|
1893 // |
|
1894 TBool CPbk2NamesListReadyState::FocusableItemPointed() |
|
1895 { |
|
1896 return iListBox.FocusableItemPointed(); |
|
1897 } |
|
1898 |
|
1899 // -------------------------------------------------------------------------- |
|
1900 // CPbk2NamesListReadyState::SearchFieldPointed |
|
1901 // -------------------------------------------------------------------------- |
|
1902 // |
|
1903 TBool CPbk2NamesListReadyState::SearchFieldPointed() |
|
1904 { |
|
1905 return iSearchFieldPointed; |
|
1906 } |
|
1907 |
|
1908 // -------------------------------------------------------------------------- |
|
1909 // CPbk2NamesListReadyState::TopViewChangedL |
|
1910 // |
|
1911 // This is called when top view is changed. However this happens before .e.g |
|
1912 // the view containing top contacts is ready and therefore in this point of |
|
1913 // execution we don't know whether there will be e.g. "Add to favorites" |
|
1914 // command item visible or not |
|
1915 // -------------------------------------------------------------------------- |
|
1916 // |
|
1917 void CPbk2NamesListReadyState::TopViewChangedL( |
|
1918 MVPbkContactViewBase& aOldView ) |
|
1919 { |
|
1920 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
1921 ("CPbk2NamesListReadyState::TopViewChangedL begin") ); |
|
1922 |
|
1923 // Switch view |
|
1924 TInt countBefore = aOldView.ContactCountL(); |
|
1925 TInt countAfter = iViewStack.ContactCountL(); |
|
1926 |
|
1927 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
1928 ("CPbk2NamesListReadyState::TopViewChangedL:before=%d,now=%d"), |
|
1929 countBefore, countAfter ); |
|
1930 |
|
1931 // Markings must be checked before HandleItemAdditionL or |
|
1932 // HandleItemRemovalL because they reset markings |
|
1933 TBool marked = ContactsMarked(); |
|
1934 |
|
1935 // Handle list box changes |
|
1936 // Promotion item "Add to favourites" should not be visible if top view is |
|
1937 // not base view (iViewStack.Level() !== 0). Remote search may be shown when there |
|
1938 // is text entered in find box. MyCard enabled similarly as add favorites. |
|
1939 TBool addFavoOk = iViewStack.Level() == 0 && !(iFindBox && iFindBox->TextLength()); |
|
1940 UpdateCommandEnabled( EPbk2CmdAddFavourites, addFavoOk ); |
|
1941 UpdateCommandEnabled( EPbk2CmdRcl, !addFavoOk ); |
|
1942 UpdateCommandEnabled( EPbk2CmdOpenMyCard, addFavoOk ); |
|
1943 |
|
1944 if ( countAfter > countBefore ) //count does not contain command items |
|
1945 { |
|
1946 iListBox.HandleItemAdditionL(); |
|
1947 } |
|
1948 if ( countAfter < countBefore ) |
|
1949 { |
|
1950 iListBox.HandleItemRemovalL(); |
|
1951 } |
|
1952 |
|
1953 UpdateAdaptiveSearchGridL( EFalse ); |
|
1954 |
|
1955 if ( marked ) |
|
1956 { |
|
1957 // update markings to the new view |
|
1958 RestoreMarkedItemsL( iSelectedItems ); |
|
1959 } |
|
1960 |
|
1961 if ( iSearchFilter.IsPredictiveActivated() ) |
|
1962 { |
|
1963 TInt indexOfMatchedItem = iSearchFilter.CommitFindPaneTextL( iViewStack, iNameFormatter ); |
|
1964 if ( indexOfMatchedItem == KErrNotFound ) |
|
1965 { |
|
1966 indexOfMatchedItem = 0; |
|
1967 } |
|
1968 iListBox.SetCurrentItemIndexAndDraw(indexOfMatchedItem); |
|
1969 } |
|
1970 else |
|
1971 { |
|
1972 SetCurrentItemIndexAndDrawL(); |
|
1973 } |
|
1974 |
|
1975 HandleFocusChangeL(); |
|
1976 |
|
1977 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
1978 ("CPbk2NamesListReadyState::TopViewChangedL end") ); |
|
1979 } |
|
1980 |
|
1981 // -------------------------------------------------------------------------- |
|
1982 // CPbk2NamesListReadyState::TopViewUpdatedL |
|
1983 // -------------------------------------------------------------------------- |
|
1984 // |
|
1985 void CPbk2NamesListReadyState::TopViewUpdatedL() |
|
1986 { |
|
1987 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
1988 ("CPbk2NamesListReadyState::TopViewUpdatedL begin") ); |
|
1989 |
|
1990 // Promotion item "Add to favourites" should not be visible if top view is |
|
1991 // not base view (iViewStack.Level() !== 0). Remote search may be shown when there |
|
1992 // is text entered in find box. MyCard enabled similarly as add favorites. |
|
1993 TBool addFavoOk = iViewStack.Level() == 0 && !(iFindBox && iFindBox->TextLength()); |
|
1994 |
|
1995 UpdateCommandEnabled( EPbk2CmdAddFavourites, addFavoOk ); |
|
1996 UpdateCommandEnabled( EPbk2CmdRcl, !addFavoOk ); |
|
1997 UpdateCommandEnabled( EPbk2CmdOpenMyCard, addFavoOk ); |
|
1998 UpdateAdaptiveSearchGridL( ETrue ); |
|
1999 |
|
2000 if ( ContactsMarked() ) |
|
2001 { |
|
2002 // The view didn't change so we have to restore the items that |
|
2003 // were saved last time the find box was updated. |
|
2004 RestoreMarkedItemsL( iSelectedItems ); |
|
2005 SetCurrentItemIndexAndDrawL(); |
|
2006 } |
|
2007 HandleFocusChangeL(); |
|
2008 } |
|
2009 |
|
2010 // -------------------------------------------------------------------------- |
|
2011 // CPbk2NamesListReadyState::BaseViewChangedL |
|
2012 // -------------------------------------------------------------------------- |
|
2013 // |
|
2014 void CPbk2NamesListReadyState::BaseViewChangedL() |
|
2015 { |
|
2016 HandleFocusChangeL(); |
|
2017 } |
|
2018 |
|
2019 // -------------------------------------------------------------------------- |
|
2020 // CPbk2NamesListReadyState::ViewStackError |
|
2021 // -------------------------------------------------------------------------- |
|
2022 // |
|
2023 void CPbk2NamesListReadyState::ViewStackError( TInt /*aError*/ ) |
|
2024 { |
|
2025 // CPbk2NameListControl is listening to view stack errors and handles |
|
2026 // them. This is UI control's internal design and the state can |
|
2027 // ignore the error |
|
2028 } |
|
2029 |
|
2030 // -------------------------------------------------------------------------- |
|
2031 // CPbk2NamesListReadyState::ContactAddedToBaseView |
|
2032 // -------------------------------------------------------------------------- |
|
2033 // |
|
2034 void CPbk2NamesListReadyState::ContactAddedToBaseView( |
|
2035 MVPbkContactViewBase& /*aBaseView*/, TInt /*aIndex*/, |
|
2036 const MVPbkContactLink& /*aContactLink*/ ) |
|
2037 { |
|
2038 // CPbk2NameListControl handles this. |
|
2039 } |
|
2040 |
|
2041 // -------------------------------------------------------------------------- |
|
2042 // CPbk2NamesListReadyState::FindDelayComplete |
|
2043 // -------------------------------------------------------------------------- |
|
2044 // |
|
2045 void CPbk2NamesListReadyState::FindDelayComplete() |
|
2046 { |
|
2047 TRAPD( error, UpdateFindResultL() ); |
|
2048 if ( error != KErrNone ) |
|
2049 { |
|
2050 CCoeEnv::Static()->HandleError( error ); |
|
2051 iViewStack.Reset(); |
|
2052 } |
|
2053 } |
|
2054 |
|
2055 // -------------------------------------------------------------------------- |
|
2056 // CPbk2NamesListReadyState::AdaptiveSearchTextChanged |
|
2057 // -------------------------------------------------------------------------- |
|
2058 // |
|
2059 void CPbk2NamesListReadyState::AdaptiveSearchTextChanged( CAknSearchField* aSearchField ) |
|
2060 { |
|
2061 //Add this line to call CPbk2AdaptiveSearchGridFiller::InvalidateAdaptiveSearchGrid() |
|
2062 //to control GRID must be updated always after user has pressed a key, even if the keymap does not changed |
|
2063 HandleControlEventL( aSearchField, MCoeControlObserver::EEventStateChanged, ETrue ); |
|
2064 |
|
2065 //this callback method is only used to notice when language has changed and |
|
2066 //to update adaptive search grid. |
|
2067 |
|
2068 if( aSearchField->LanguageChanged() ) |
|
2069 { |
|
2070 UpdateAdaptiveSearchGridL( ETrue ); |
|
2071 } |
|
2072 } |
|
2073 |
|
2074 |
|
2075 void CPbk2NamesListReadyState::CmdItemVisibilityChanged( TInt aCmdItemId, TBool aVisible ) |
|
2076 { |
|
2077 TInt cmdItemIndex = FindCommand(aCmdItemId); |
|
2078 TRAP_IGNORE( HandleCommandEventL( |
|
2079 (aVisible ? EItemAdded : EItemRemoved), |
|
2080 cmdItemIndex) ); |
|
2081 } |
|
2082 |
|
2083 // -------------------------------------------------------------------------- |
|
2084 // CPbk2NamesListReadyState::RestoreMarkedContactsL |
|
2085 // Marks specified contacts in the listbox. |
|
2086 // |
|
2087 // @param aMarkedContacts Contacts to mark. |
|
2088 // @return True if any contacts were marked in the list. |
|
2089 // -------------------------------------------------------------------------- |
|
2090 // |
|
2091 TBool CPbk2NamesListReadyState::RestoreMarkedContactsL |
|
2092 (const MVPbkContactLinkArray* aMarkedContacts) |
|
2093 { |
|
2094 TBool result = EFalse; |
|
2095 DisableRedrawEnablePushL(); |
|
2096 iListBox.ClearSelection(); |
|
2097 if (aMarkedContacts) |
|
2098 { |
|
2099 const TInt count = aMarkedContacts->Count(); |
|
2100 for (TInt i=0; i < count; ++i) |
|
2101 { |
|
2102 const MVPbkContactLink& contact = aMarkedContacts->At(i); |
|
2103 const TInt viewIndex = iViewStack.IndexOfLinkL(contact); |
|
2104 if (viewIndex >= 0) |
|
2105 { |
|
2106 const TInt listboxIndex = viewIndex + CommandItemCount(); |
|
2107 iListBox.View()->SelectItemL(listboxIndex); |
|
2108 result = ETrue; |
|
2109 } |
|
2110 } |
|
2111 } |
|
2112 CleanupStack::PopAndDestroy(); // DisableRedrawEnablePushL |
|
2113 return result; |
|
2114 } |
|
2115 |
|
2116 // -------------------------------------------------------------------------- |
|
2117 // CPbk2NamesListReadyState::RestoreMarkedItemsL |
|
2118 // -------------------------------------------------------------------------- |
|
2119 // |
|
2120 void CPbk2NamesListReadyState::RestoreMarkedItemsL( |
|
2121 const MVPbkContactBookmarkCollection& aSelectedItems ) |
|
2122 { |
|
2123 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
2124 ("CPbk2NamesListReadyState::RestoreMarkedItemsL: %d items"), |
|
2125 aSelectedItems.Count() ); |
|
2126 |
|
2127 DisableRedrawEnablePushL(); |
|
2128 iListBox.ClearSelection(); |
|
2129 const TInt count = aSelectedItems.Count(); |
|
2130 for ( TInt i = 0; i < count; ++i ) |
|
2131 { |
|
2132 TInt index = iViewStack.IndexOfBookmarkL( aSelectedItems.At( i ) ) + CommandItemCount(); |
|
2133 if ( index >= 0 ) |
|
2134 { |
|
2135 iListBox.View()->SelectItemL( index ); |
|
2136 } |
|
2137 } |
|
2138 CleanupStack::PopAndDestroy(); // DisableRedrawEnablePushL |
|
2139 } |
|
2140 |
|
2141 // -------------------------------------------------------------------------- |
|
2142 // CPbk2NamesListReadyState::DisableRedrawEnablePushL |
|
2143 // -------------------------------------------------------------------------- |
|
2144 // |
|
2145 void CPbk2NamesListReadyState::DisableRedrawEnablePushL() |
|
2146 { |
|
2147 CListBoxView& listBoxView = *iListBox.View(); |
|
2148 listBoxView.SetDisableRedraw(ETrue); |
|
2149 CleanupStack::PushL(TCleanupEnableListBoxViewRedraw(listBoxView)); |
|
2150 } |
|
2151 |
|
2152 // -------------------------------------------------------------------------- |
|
2153 // CPbk2NamesListReadyState::HandleFocusChangeL |
|
2154 // -------------------------------------------------------------------------- |
|
2155 // |
|
2156 void CPbk2NamesListReadyState::HandleFocusChangeL() |
|
2157 { |
|
2158 iEventSender.SendEventToObserversL( |
|
2159 TPbk2ControlEvent::TPbk2ControlEvent::EControlFocusChanged ); |
|
2160 } |
|
2161 |
|
2162 // -------------------------------------------------------------------------- |
|
2163 // CPbk2NamesListReadyState::UpdateFindResultL |
|
2164 // -------------------------------------------------------------------------- |
|
2165 // |
|
2166 void CPbk2NamesListReadyState::UpdateFindResultL() |
|
2167 { |
|
2168 TBuf <KSearchFieldLength> findPaneTxt( FindTextL() ); |
|
2169 |
|
2170 if ( iSearchFilter.StartFindPaneInlineEditL( findPaneTxt ) ) |
|
2171 { |
|
2172 TBool selectionChanged = HasSelectedItemsChangedL(); |
|
2173 |
|
2174 MVPbkContactBookmarkCollection* marked = NULL; |
|
2175 if ( ContactsMarked() ) |
|
2176 { |
|
2177 marked = &SelectedItemsL( iViewStack ); |
|
2178 } |
|
2179 else |
|
2180 { |
|
2181 // User has removed all the marks so update also bookmarks. |
|
2182 iSelectedItems.RemoveAndDeleteAll(); |
|
2183 } |
|
2184 |
|
2185 // Extract the find text into array |
|
2186 if ( !iStringSplitter ) |
|
2187 { |
|
2188 iStringSplitter = CPbk2FindStringSplitter::NewL( iNameFormatter ); |
|
2189 } |
|
2190 MDesCArray* temp = iStringSplitter->SplitTextIntoArrayL( findPaneTxt ); |
|
2191 delete iStringArray; |
|
2192 iStringArray = temp; |
|
2193 |
|
2194 iViewStack.UpdateFilterL( *iStringArray, marked, selectionChanged ); |
|
2195 |
|
2196 UpdateAdaptiveSearchGridL( EFalse ); |
|
2197 } |
|
2198 } |
|
2199 |
|
2200 // -------------------------------------------------------------------------- |
|
2201 // CPbk2NamesListReadyState::UpdateFindBoxL |
|
2202 // -------------------------------------------------------------------------- |
|
2203 // |
|
2204 void CPbk2NamesListReadyState::UpdateFindBoxL() |
|
2205 { |
|
2206 if ( iFindBox ) |
|
2207 { |
|
2208 if ( iViewStack.ContactCountL() > 0 && iParent.IsFocused() ) |
|
2209 { |
|
2210 iFindBox->SetFocusing( ETrue ); |
|
2211 // If findbox is focusing, SetFocus would clear some flag of Fep, |
|
2212 // and it will cause 'b','c',''e',...could not be entered for the |
|
2213 // first character by V-ITUT. |
|
2214 if ( !iFindBox->IsFocused() ) |
|
2215 { |
|
2216 iFindBox->SetFocus( ETrue, EDrawNow ); |
|
2217 } |
|
2218 } |
|
2219 else |
|
2220 { |
|
2221 iFindBox->SetNonFocusing(); |
|
2222 iFindBox->SetFocus( EFalse, EDrawNow ); |
|
2223 } |
|
2224 } |
|
2225 } |
|
2226 |
|
2227 // -------------------------------------------------------------------------- |
|
2228 // CPbk2NamesListReadyState::SelectedItemsL |
|
2229 // -------------------------------------------------------------------------- |
|
2230 // |
|
2231 MVPbkContactBookmarkCollection& CPbk2NamesListReadyState::SelectedItemsL( |
|
2232 MVPbkContactViewBase& aCurrentView ) |
|
2233 { |
|
2234 // Get listbox selection indexes, a reference only |
|
2235 const CListBoxView::CSelectionIndexArray* selArray = |
|
2236 iListBox.SelectionIndexes(); |
|
2237 |
|
2238 if ( selArray ) |
|
2239 { |
|
2240 iSelectedItems.RemoveAndDeleteAll(); |
|
2241 const TInt count = selArray->Count(); |
|
2242 for ( TInt i = 0; i < count; ++i ) |
|
2243 { |
|
2244 |
|
2245 iSelectedItems.AppendL( |
|
2246 aCurrentView.CreateBookmarkLC( selArray->At(i) - CommandItemCount() ) ); |
|
2247 CleanupStack::Pop(); |
|
2248 } |
|
2249 } |
|
2250 |
|
2251 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
2252 ("CPbk2NamesListReadyState::SelectedItemsL:%d marked"), |
|
2253 iSelectedItems.Count() ); |
|
2254 |
|
2255 return iSelectedItems; |
|
2256 } |
|
2257 |
|
2258 // -------------------------------------------------------------------------- |
|
2259 // CPbk2NamesListReadyState::HasSelectedItemsChangedL |
|
2260 // -------------------------------------------------------------------------- |
|
2261 // |
|
2262 TBool CPbk2NamesListReadyState::HasSelectedItemsChangedL() |
|
2263 { |
|
2264 TBool result = EFalse; |
|
2265 |
|
2266 // Get listbox selection indexes, a reference only |
|
2267 const CListBoxView::CSelectionIndexArray* selArray = |
|
2268 iListBox.SelectionIndexes(); |
|
2269 |
|
2270 if ( selArray ) |
|
2271 { |
|
2272 TInt bookmarkCount = iSelectedItems.Count(); |
|
2273 TInt markedCount = selArray->Count(); |
|
2274 // Changed if number of items are different |
|
2275 result = bookmarkCount != markedCount; |
|
2276 if ( !result ) |
|
2277 { |
|
2278 // There are equeal amount of items. Compare as long |
|
2279 // as the difference is found |
|
2280 for ( TInt i = 0; i < bookmarkCount && !result; ++i ) |
|
2281 { |
|
2282 result = selArray->At(i) != |
|
2283 iViewStack.IndexOfBookmarkL( iSelectedItems.At(i) ); |
|
2284 } |
|
2285 } |
|
2286 } |
|
2287 else if ( iSelectedItems.Count() > 0 ) |
|
2288 { |
|
2289 result = ETrue; |
|
2290 } |
|
2291 |
|
2292 PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING |
|
2293 ("CPbk2NamesListReadyState::HasSelectedItemsChangedL: %d "), |
|
2294 result ); |
|
2295 |
|
2296 return result; |
|
2297 } |
|
2298 |
|
2299 // -------------------------------------------------------------------------- |
|
2300 // CPbk2NamesListReadyState::SetCurrentItemIndexAndDrawL |
|
2301 // -------------------------------------------------------------------------- |
|
2302 // |
|
2303 void CPbk2NamesListReadyState::SetCurrentItemIndexAndDrawL() |
|
2304 { |
|
2305 __ASSERT_DEBUG( &iListBox && iFindPolicy, |
|
2306 Panic(EPanicLogic_PreConds_SetCurrentItemIndexAndDraw) ); |
|
2307 |
|
2308 if ( iStringArray && iStringArray->MdcaCount() > 0 ) |
|
2309 { |
|
2310 TBool isCurrentItemSet( EFalse ); |
|
2311 const TInt count( iViewStack.ContactCountL() ); |
|
2312 for ( TInt i(0); i < count; ++i ) |
|
2313 { |
|
2314 const MVPbkViewContact& contact = iViewStack.ContactAtL( i ); |
|
2315 if ( iFindPolicy->MatchContactNameL( *iStringArray, contact ) ) |
|
2316 { |
|
2317 isCurrentItemSet = ETrue; |
|
2318 iListBox.SetCurrentItemIndexAndDraw(i); |
|
2319 break; |
|
2320 } |
|
2321 } |
|
2322 if ( !isCurrentItemSet ) |
|
2323 { |
|
2324 iListBox.SetCurrentItemIndexAndDraw(0); |
|
2325 } |
|
2326 } |
|
2327 else |
|
2328 { |
|
2329 iListBox.SetCurrentItemIndexAndDraw(0); |
|
2330 } |
|
2331 } |
|
2332 |
|
2333 void CPbk2NamesListReadyState::UpdateAdaptiveSearchGridL( TBool aClearCache ) |
|
2334 { |
|
2335 if( ( !iAdaptiveSearchGridFiller ) || ( !iFindBox ) ) |
|
2336 { |
|
2337 return; |
|
2338 } |
|
2339 |
|
2340 CAknSearchField::TSearchFieldStyle searchStyle = iFindBox->SearchFieldStyle(); |
|
2341 |
|
2342 if ( searchStyle != CAknSearchField::EAdaptiveSearch ) |
|
2343 { |
|
2344 delete iAdaptiveSearchGridFiller; |
|
2345 iAdaptiveSearchGridFiller = NULL; |
|
2346 return; |
|
2347 } |
|
2348 |
|
2349 iAdaptiveSearchGridFiller->StopFilling(); |
|
2350 |
|
2351 if( aClearCache ) |
|
2352 { |
|
2353 iAdaptiveSearchGridFiller->ClearCache(); |
|
2354 } |
|
2355 |
|
2356 |
|
2357 iAdaptiveSearchGridFiller->StartFilling( iViewStack, FindTextL() ); |
|
2358 } |
|
2359 |
|
2360 /** |
|
2361 * Tells whether the listbox line contains a contact or not. |
|
2362 * Does not check that the aListboxIndex is within range of listbox. |
|
2363 * @param aListboxIndex The position in the listbox to be checked. |
|
2364 */ |
|
2365 TBool CPbk2NamesListReadyState::IsContactAtListboxIndex( TInt aListboxIndex ) const |
|
2366 { |
|
2367 // There can be command items at the top of the list. |
|
2368 // The command items are not contacts. |
|
2369 const TInt enabledCommandCount = CommandItemCount(); |
|
2370 return aListboxIndex >= enabledCommandCount; |
|
2371 } |
|
2372 |
|
2373 void CPbk2NamesListReadyState::AllowCommandsToShowThemselves( TBool aVisible ) |
|
2374 { |
|
2375 if ( aVisible ) |
|
2376 { |
|
2377 // ownership not transferred |
|
2378 iListBox.SetListCommands( &iCommandItems ); |
|
2379 SubscribeCmdItemsVisibility(); |
|
2380 UpdateCommandEnabled( EPbk2CmdAddFavourites, ETrue ); //By default add favorites may be shown |
|
2381 UpdateCommandEnabled( EPbk2CmdOpenMyCard, ETrue ); |
|
2382 } |
|
2383 else |
|
2384 { |
|
2385 UpdateCommandEnabled( EPbk2CmdRcl, EFalse ); |
|
2386 UpdateCommandEnabled( EPbk2CmdAddFavourites, EFalse ); |
|
2387 UpdateCommandEnabled( EPbk2CmdOpenMyCard, EFalse ); |
|
2388 UnsubscribeCmdItemsVisibility(); |
|
2389 iListBox.SetListCommands( NULL ); |
|
2390 } |
|
2391 } |
|
2392 |
|
2393 void CPbk2NamesListReadyState::UpdateCommandEnabled( TInt aCommandId, TBool aEnabled ) |
|
2394 { |
|
2395 for ( TInt i = 0; i < iCommandItems.Count(); i++ ) |
|
2396 { |
|
2397 if ( iCommandItems[i]->CommandId() == aCommandId ) |
|
2398 { |
|
2399 iCommandItems[i]->SetEnabled( aEnabled ); |
|
2400 break; |
|
2401 } |
|
2402 } |
|
2403 } |
|
2404 |
|
2405 TBool CPbk2NamesListReadyState::IsCommandEnabled(TInt aCommandId) const |
|
2406 { |
|
2407 TBool res = EFalse; |
|
2408 for ( TInt i = 0; i < iCommandItems.Count(); i++ ) |
|
2409 { |
|
2410 if ( iCommandItems[i]->CommandId() == aCommandId ) |
|
2411 { |
|
2412 res = iCommandItems[i]->IsEnabled(); |
|
2413 break; |
|
2414 } |
|
2415 } |
|
2416 return res; |
|
2417 } |
|
2418 |
|
2419 // |
|
2420 // Search for a command in iCommandItems and returns its index |
|
2421 // |
|
2422 TInt CPbk2NamesListReadyState::FindCommand(TInt aCommandId) const |
|
2423 { |
|
2424 TInt result = KErrNotFound; |
|
2425 for ( TInt i = 0; i < iCommandItems.Count(); ++i ) |
|
2426 { |
|
2427 if ( iCommandItems[i]->CommandId() == aCommandId ) |
|
2428 { |
|
2429 result = i; |
|
2430 break; |
|
2431 } |
|
2432 |
|
2433 } |
|
2434 return result; |
|
2435 } |
|
2436 |
|
2437 TInt CPbk2NamesListReadyState::CalculateListboxIndex(TInt aCommandIndex) const |
|
2438 { |
|
2439 //TInt num = 0; |
|
2440 TInt num(KErrNotFound); |
|
2441 for ( TInt i = 0; i <= aCommandIndex; ++i ) |
|
2442 { |
|
2443 if(iCommandItems[i]->IsEnabled()) |
|
2444 { |
|
2445 ++num; |
|
2446 } |
|
2447 } |
|
2448 return num; |
|
2449 } |
|
2450 |
|
2451 |
|
2452 void CPbk2NamesListReadyState::UnmarkCommands() const |
|
2453 { |
|
2454 for ( TInt i = 0; i < CommandItemCount(); i++ ) |
|
2455 { |
|
2456 iListBox.View()->DeselectItem( i ); |
|
2457 } |
|
2458 } |
|
2459 |
|
2460 TInt CPbk2NamesListReadyState::EnabledCommandCount() const |
|
2461 { |
|
2462 TInt result = 0; |
|
2463 for ( TInt i = 0; i < iCommandItems.Count(); ++i ) |
|
2464 { |
|
2465 if(iCommandItems[i]->IsEnabled()) |
|
2466 { |
|
2467 result++; |
|
2468 } |
|
2469 } |
|
2470 return result; |
|
2471 } |
|
2472 |
|
2473 // End of File |