|
1 /* |
|
2 * Copyright (c) 2002 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: LandmarksUi Content File - |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 // INCLUDE FILES |
|
27 #include "TLmkDeletionHelper.h" |
|
28 #include <eiklbx.h> |
|
29 #include <aknlists.h> |
|
30 #include <lmkerrors.h> |
|
31 |
|
32 |
|
33 #if defined(_DEBUG) |
|
34 |
|
35 // CONSTANTS |
|
36 /// Unnamed namespace for local definitions |
|
37 namespace { |
|
38 _LIT( KPanicMsg, "TLmkDeletionHelper" ); |
|
39 |
|
40 void Panic( TPanicCode aReason ) |
|
41 { |
|
42 User::Panic( KPanicMsg, aReason ); |
|
43 } |
|
44 } // namespace |
|
45 #endif |
|
46 |
|
47 |
|
48 // ============================ MEMBER FUNCTIONS =============================== |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // TLmkDeletionHelper::TLmkDeletionHelper |
|
52 // C++ default constructor can NOT contain any code, that |
|
53 // might leave. |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 TLmkDeletionHelper::TLmkDeletionHelper() |
|
57 : iUserRequestedDelete( EFalse ), |
|
58 iCurrentItemIndexBeforeRemoval( -1 ), |
|
59 iCurrentItemWasRemoved( EFalse ), |
|
60 iIndexesToRemovedItems( NULL ), |
|
61 iListBox( NULL ) |
|
62 { |
|
63 } |
|
64 |
|
65 // ---------------------------------------------------- |
|
66 // TLmkDeletionHelper::~TLmkDeletionHelper |
|
67 // ---------------------------------------------------- |
|
68 // |
|
69 TLmkDeletionHelper::~TLmkDeletionHelper() |
|
70 { |
|
71 } |
|
72 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // TLmkDeletionHelper::StoreListInformation |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 void TLmkDeletionHelper::StoreListInformation( |
|
78 CEikListBox& aListBox, |
|
79 TBool aMultipleItems ) |
|
80 { |
|
81 iListBox = &aListBox; |
|
82 iUserRequestedDelete = ETrue; |
|
83 /* |
|
84 * After deletion, the focus must go to the first item, |
|
85 * commenting re-assigning the iCurrentItemIndexBeforeRemoval |
|
86 * with zero. |
|
87 */ |
|
88 iCurrentItemIndexBeforeRemoval = iListBox->CurrentItemIndex(); |
|
89 //iCurrentItemIndexBeforeRemoval = KTopListIndex; |
|
90 if ( aMultipleItems ) |
|
91 { |
|
92 iIndexesToRemovedItems = iListBox->SelectionIndexes(); |
|
93 // This parameter is not important in this case: |
|
94 iCurrentItemWasRemoved = EFalse; |
|
95 } |
|
96 else |
|
97 { |
|
98 iCurrentItemWasRemoved = ETrue; |
|
99 // This parameter is not important in this case: |
|
100 iIndexesToRemovedItems = NULL; |
|
101 } |
|
102 } |
|
103 |
|
104 // ----------------------------------------------------------------------------- |
|
105 // TLmkDeletionHelper::UpdateListIfDeleteHappenedL |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 TBool TLmkDeletionHelper::UpdateListIfDeleteHappenedL() |
|
109 { |
|
110 // Avkon's utility seems to work nicely even if operation was cancelled |
|
111 // and some items were not deleted. |
|
112 |
|
113 if ( iUserRequestedDelete ) |
|
114 { |
|
115 if( iIndexesToRemovedItems ) |
|
116 { |
|
117 // We need to make a copy of the index array since AknListBoxUtils |
|
118 // requires a non-const parameter: |
|
119 TInt count = iIndexesToRemovedItems->Count(); |
|
120 // If index array exists it always contains some items: |
|
121 __ASSERT_DEBUG( count > 0, Panic( KLmkPanicDeletionInfo ) ); |
|
122 CArrayFix<TInt>* removedItems = |
|
123 new( ELeave ) CArrayFixFlat<TInt>( count ); |
|
124 CleanupStack::PushL( removedItems ); |
|
125 for ( TInt i( 0 ); i < count; ++i ) |
|
126 { |
|
127 removedItems->AppendL( iIndexesToRemovedItems->At( i ) ); |
|
128 } |
|
129 |
|
130 AknListBoxUtils::HandleItemRemovalAndPositionHighlightL( |
|
131 iListBox, |
|
132 iCurrentItemIndexBeforeRemoval, |
|
133 *removedItems ); |
|
134 CleanupStack::PopAndDestroy( removedItems ); |
|
135 } |
|
136 else |
|
137 { |
|
138 AknListBoxUtils::HandleItemRemovalAndPositionHighlightL( |
|
139 iListBox, |
|
140 iCurrentItemIndexBeforeRemoval, |
|
141 iCurrentItemWasRemoved ); |
|
142 } |
|
143 // List update now done, set indicator to EFalse: |
|
144 iUserRequestedDelete = EFalse; |
|
145 return ETrue; |
|
146 } |
|
147 else |
|
148 { // Delete hasn't been performed by the user, |
|
149 // i.e. StoreListInformation() hasn't been called |
|
150 return EFalse; |
|
151 } |
|
152 } |
|
153 |
|
154 // End of File |