|
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: |
|
15 * Phonebook contact view list control. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #ifndef __CPbkContactViewListControl_H__ |
|
21 #define __CPbkContactViewListControl_H__ |
|
22 |
|
23 |
|
24 // INCLUDES |
|
25 #include <cntviewbase.h> // MContactViewObserver |
|
26 #include <coecobs.h> // MCoeControlObserver |
|
27 #include <babitflags.h> // TBitFlags |
|
28 |
|
29 #include <PbkIconId.hrh> // TPbkIconId |
|
30 #include <MPbkContactDbObserver.h> |
|
31 #include <CPbkContactListControlBase.h> |
|
32 |
|
33 // FORWARD DECLARATIONS |
|
34 class CPbkContactFindView; |
|
35 class CEikColumnListBox; |
|
36 class CEikMenuPane; |
|
37 class CAknSearchField; |
|
38 class CPbkThumbnailPopup; |
|
39 class CPbkViewState; |
|
40 class MPbkContactEntryLoader; |
|
41 class MPbkContactViewListControlObserver; |
|
42 class MPbkContactViewListModel; |
|
43 class TPbkContactViewListControlEvent; |
|
44 class MPbkFindPrimitives; |
|
45 class MPbkContactUiControlExtension; |
|
46 class MPbkFetchDlgSelection; |
|
47 /// Use for testing only!!! |
|
48 class CPbkContactViewListControl_TestAccess; |
|
49 |
|
50 |
|
51 // CLASS DECLARATION |
|
52 |
|
53 /** |
|
54 * @internal Only Phonebook internal use supported! |
|
55 * |
|
56 * Phonebook contact view list control. Used in all views and dialogs which |
|
57 * display contacts in a list box. |
|
58 */ |
|
59 class CPbkContactViewListControl : |
|
60 public CPbkContactListControlBase, |
|
61 private MCoeControlObserver, |
|
62 private MContactViewObserver |
|
63 { |
|
64 public: // Constructors and destructor |
|
65 /** |
|
66 * Creates a new instance of this class. |
|
67 * @param aEngine phonebook engine instance. |
|
68 * @param aView the contact view this list control displays. |
|
69 * @param aResourceId if of a PBK_CONTACTVIEWLISTCONTROL resource to |
|
70 * use for intialisation. |
|
71 * @param aParent container for this control. If NULL this control |
|
72 * creates its own window. |
|
73 */ |
|
74 IMPORT_C static CPbkContactViewListControl* NewL |
|
75 (CPbkContactEngine& aEngine, |
|
76 CContactViewBase& aView, |
|
77 TInt aResourceId, |
|
78 const CCoeControl* aParent); |
|
79 |
|
80 /** |
|
81 * C++ default constructor. |
|
82 */ |
|
83 IMPORT_C CPbkContactViewListControl(); |
|
84 |
|
85 /** |
|
86 * Second phase constructor, from CCoeControl. Initialises this object |
|
87 * from a PBK_ENTRYLIST_CONTROL resource struct using aReader. |
|
88 * Should be called before ConstructL(). |
|
89 */ |
|
90 void ConstructFromResourceL(TResourceReader& aReader); |
|
91 |
|
92 /** |
|
93 * "Third phase" constructor. Should be called after |
|
94 * ConstructFromResourceL(). |
|
95 * @param aEngine Phonebook engine instance. |
|
96 * @param aView the contact view this list control displays. |
|
97 */ |
|
98 IMPORT_C void ConstructL |
|
99 (CPbkContactEngine& aEngine, CContactViewBase& aView); |
|
100 |
|
101 /** |
|
102 * Destructor. |
|
103 */ |
|
104 ~CPbkContactViewListControl(); |
|
105 |
|
106 public: // New functions |
|
107 |
|
108 /** |
|
109 * Returns the Contact id at listbox index aIndex. |
|
110 */ |
|
111 IMPORT_C TContactItemId ContactIdAtL(TInt aIndex) const; |
|
112 |
|
113 /** |
|
114 * Returns the listbox index of entry having contact id aId, |
|
115 * -1 if not found. |
|
116 */ |
|
117 IMPORT_C TInt FindContactIdL(TContactItemId aId) const; |
|
118 |
|
119 /** |
|
120 * Returns the currently focused item's index. |
|
121 */ |
|
122 IMPORT_C TInt CurrentItemIndex() const; |
|
123 |
|
124 /** |
|
125 * Sets the currently focused item's index to aIndex. |
|
126 */ |
|
127 IMPORT_C void SetCurrentItemIndex(TInt aIndex); |
|
128 |
|
129 /** |
|
130 * Sets the currently focused item's index to aIndex and updates |
|
131 * the control on the display. |
|
132 */ |
|
133 IMPORT_C void SetCurrentItemIndexAndDraw(TInt aIndex); |
|
134 |
|
135 /** |
|
136 * Handles aCommandId if it is a markable list box command. |
|
137 * @see AknSelectionService::HandleMarkableListProcessCommandL. |
|
138 */ |
|
139 IMPORT_C void HandleMarkableListProcessCommandL(TInt aCommandId); |
|
140 |
|
141 /** |
|
142 * Updates a menu pane containing markable list commands. |
|
143 * @see AknSelectionService::HandleMarkableListDynInitMenuPane |
|
144 */ |
|
145 IMPORT_C void HandleMarkableListDynInitMenuPane |
|
146 (TInt aResourceId, CEikMenuPane* aMenu); |
|
147 |
|
148 /** |
|
149 * Updates listbox state after command execution. |
|
150 * @see AknSelectionService::HandleMarkableListUpdateAfterCommandExecution. |
|
151 */ |
|
152 IMPORT_C void HandleMarkableListUpdateAfterCommandExecution(); |
|
153 |
|
154 /** |
|
155 * Returns the text currenlty in find box. KNullDesC if the find box |
|
156 * is not visible. |
|
157 */ |
|
158 IMPORT_C const TDesC& FindTextL() const; |
|
159 |
|
160 /** |
|
161 * Resets any string in the find box. |
|
162 */ |
|
163 IMPORT_C void ResetFindL(); |
|
164 |
|
165 /** |
|
166 * Returns ETrue if item at aIndex is currently marked. |
|
167 */ |
|
168 IMPORT_C TBool ItemMarked(TInt aIndex) const; |
|
169 |
|
170 /** |
|
171 * Returns index of next unmarked item starting from focused item. |
|
172 */ |
|
173 IMPORT_C TInt NextUnmarkedIndexFromFocus() const; |
|
174 |
|
175 /** |
|
176 * Marks or unmarks a contact item in the list. |
|
177 * |
|
178 * @param aContactId Id of Contact item to mark or unmark. |
|
179 * @param aMark ETrue: set the mark, EFalse: remove the mark. |
|
180 */ |
|
181 IMPORT_C void MarkItemL(TContactItemId aContactId, TBool aMark); |
|
182 |
|
183 /** |
|
184 * Umarks all marked items. |
|
185 */ |
|
186 IMPORT_C void ClearMarks(); |
|
187 |
|
188 /** |
|
189 * Creates a new CPbkViewState and stores this control's |
|
190 * state to it. |
|
191 * @param aSaveMarks if true saves also marked entries to returned |
|
192 * view state object. |
|
193 * @return this control's saved state. Caller is responsible for |
|
194 * deleting the returned object. |
|
195 * @see RestoreState |
|
196 */ |
|
197 IMPORT_C CPbkViewState* GetStateL(TBool aSaveMarks=ETrue) const; |
|
198 |
|
199 /** |
|
200 * Same as GetStateL, but leaves the object on the cleanup stack. |
|
201 * @see GetStateL |
|
202 */ |
|
203 IMPORT_C CPbkViewState* GetStateLC(TBool aSaveMarks=ETrue) const; |
|
204 |
|
205 /** |
|
206 * Restores this control to a previously saved state. |
|
207 * @param aState the state where to restore this control. |
|
208 * If NULL the function does nothing. |
|
209 * @see GetState |
|
210 */ |
|
211 IMPORT_C void RestoreStateL(const CPbkViewState* aState); |
|
212 |
|
213 /** |
|
214 * Shows the thumbnail image if the currently focused contact has |
|
215 * one. |
|
216 */ |
|
217 IMPORT_C void ShowThumbnailL(); |
|
218 |
|
219 /** |
|
220 * Hides thumbnail window if visible. Call UpdateL() to restore |
|
221 * thumbnail. |
|
222 */ |
|
223 IMPORT_C void HideThumbnail(); |
|
224 |
|
225 /** |
|
226 * Adds an observer aObserver to this control. |
|
227 */ |
|
228 IMPORT_C void AddObserverL |
|
229 (MPbkContactViewListControlObserver& aObserver); |
|
230 |
|
231 /** |
|
232 * Removes an observer aObserver from this control. |
|
233 */ |
|
234 IMPORT_C void RemoveObserver |
|
235 (MPbkContactViewListControlObserver& aObserver); |
|
236 |
|
237 /** |
|
238 * Returns ETrue when this control is ready to use. |
|
239 */ |
|
240 IMPORT_C TBool IsReady() const; |
|
241 |
|
242 /** |
|
243 * Disables/enables listbox control redrawing. |
|
244 * @see CListBoxView::SetDisableRedraw(TBool) |
|
245 */ |
|
246 void SetDisableRedraw(TBool aDisableRedraw); |
|
247 |
|
248 /** |
|
249 * Disables listbox redrawing and pushes a cleanup item on the cleanup |
|
250 * stack which enables redrawing again when PopAndDestroy()'ed. |
|
251 * @see SetDisableRedraw(TBool) |
|
252 */ |
|
253 void DisableRedrawEnablePushL(); |
|
254 |
|
255 /** |
|
256 * Blanks/unblanks this control. Use when there are massive updates |
|
257 * to the database to avoid flickering. |
|
258 * @param aBlank ETrue blanks the control, EFalse unblanks it |
|
259 */ |
|
260 IMPORT_C void SetBlank(TBool aBlank); |
|
261 |
|
262 /** |
|
263 * Set contact entry loader to aContactEntryLoader. |
|
264 */ |
|
265 IMPORT_C void SetEntryLoader |
|
266 (MPbkContactEntryLoader& aContactEntryLoader); |
|
267 |
|
268 /** |
|
269 * Set selection accepter. If accepter is set, all item selections |
|
270 * are first checked from accepter. It can then prevent the |
|
271 * selection from happening. |
|
272 * @param aAccepter Pointer to the accepter |
|
273 */ |
|
274 void SetSelectionAccepter(MPbkFetchDlgSelection* aAccepter); |
|
275 |
|
276 /** |
|
277 * Deletes this control thumbnail |
|
278 */ |
|
279 IMPORT_C void DeleteThumbnail(); |
|
280 |
|
281 /** |
|
282 * Calls Listbox's corresponding method. |
|
283 * @param aEnable If EFalse, removes the listbox's own observer |
|
284 */ |
|
285 void EnableMSKObserver( TBool aEnable ); |
|
286 |
|
287 /** |
|
288 * Returns the count of items on a list. |
|
289 * @return item count |
|
290 */ |
|
291 TInt ItemCount(); |
|
292 |
|
293 public: // From MPbkContactUiControl |
|
294 /** |
|
295 * Returns the number of entries in the list box. |
|
296 * NOTE: if find is active (there is text in the find box) this |
|
297 * function returns number of currently visible items only! |
|
298 */ |
|
299 TInt NumberOfItems() const; |
|
300 TBool ItemsMarked() const; |
|
301 const CContactIdArray& MarkedItemsL() const; |
|
302 TContactItemId FocusedContactIdL() const; |
|
303 const TPbkContactItemField* FocusedField() const; |
|
304 MObjectProvider* ObjectProvider(); |
|
305 |
|
306 public: // from CCoeControl |
|
307 TKeyResponse OfferKeyEventL |
|
308 (const TKeyEvent& aKeyEvent,TEventCode aType); |
|
309 void HandlePointerEventL(const TPointerEvent& aPointerEvent); |
|
310 void MakeVisible(TBool aVisible); |
|
311 |
|
312 public: // from MPbkContactUiControlUpdate |
|
313 void UpdateContact(TContactItemId aContactId); |
|
314 |
|
315 private: // from CCoeControl |
|
316 void ConstructFromResourceL(TInt aResourceId); |
|
317 TInt CountComponentControls() const; |
|
318 CCoeControl* ComponentControl(TInt aIndex) const; |
|
319 void FocusChanged(TDrawNow aDrawNow); |
|
320 void SizeChanged(); |
|
321 void Draw(const TRect& aRect) const; |
|
322 void HandleResourceChange(TInt aType); |
|
323 void DoHandleResourceChangeL(TInt aType); |
|
324 |
|
325 private: // from MCoeControlObserver |
|
326 void HandleControlEventL(CCoeControl* aControl, TCoeEvent aEventType); |
|
327 |
|
328 private: // from MContactViewObserver |
|
329 void HandleContactViewEvent |
|
330 (const CContactViewBase& aView, const TContactViewEvent& aEvent); |
|
331 |
|
332 private: // Implementation |
|
333 void ConstructL |
|
334 (CPbkContactEngine& aEngine, CContactViewBase& aView, |
|
335 TInt aResourceId, const CCoeControl* aParent); |
|
336 CEikColumnListBox& ListBox() const; |
|
337 MPbkContactViewListModel& Model() const; |
|
338 void FixTopItemIndex(); |
|
339 void Redraw(); |
|
340 void MakeComponentsVisible(TBool aVisible); |
|
341 void HandleItemAdditionL(TInt aIndex); |
|
342 void HandleItemRemovalL(TInt aIndex); |
|
343 void UpdateFindBoxL(); |
|
344 void EnableFindBoxL(); |
|
345 void DisableFindBoxL(); |
|
346 TBool UpdateFindResultL(); |
|
347 void SetFindEmptyTextL(); |
|
348 void RemoveFindEmptyTextL(); |
|
349 void DoHandleContactViewEventL |
|
350 (const CContactViewBase& aView, const TContactViewEvent& aEvent); |
|
351 static TInt NoEventsInLastPeriod(TAny* aPtr); |
|
352 void SendEventToObserversL |
|
353 (const TPbkContactViewListControlEvent& aEvent); |
|
354 void ShowThumbnail(TContactItemId aContactId); |
|
355 void HandleFocusChange(); |
|
356 void HandleFocusChangeL(); |
|
357 TBool RestoreMarkedItemsL(const CContactIdArray* aMarkedContactIds); |
|
358 TBool PostCond_Constructor(); |
|
359 TBool PostCond_ConstructFromResource(); |
|
360 void CreateControlExtensionL(CPbkContactEngine& aEngine); |
|
361 void RefreshIconArrayL(); |
|
362 |
|
363 /// State flags |
|
364 enum TStateFlags |
|
365 { |
|
366 /// Set when this control is ready to use |
|
367 EReady, |
|
368 /// Set when this control should draw only blank |
|
369 EBlank, |
|
370 }; |
|
371 |
|
372 /// Data loaded from resources |
|
373 struct TResourceData |
|
374 { |
|
375 /// Own: flags |
|
376 TUint iFlags; |
|
377 /// Own: text to use for unnamed entries |
|
378 HBufC* iUnnamedText; |
|
379 /// Own: empty icon id |
|
380 TPbkIconId iEmptyIconId; |
|
381 /// Own: default icon id |
|
382 TPbkIconId iDefaultIconId; |
|
383 /// Own: listbox empty text in find state |
|
384 HBufC* iFindEmptyText; |
|
385 }; |
|
386 |
|
387 /// Use for testing only!!! |
|
388 friend class CPbkContactViewListControl_TestAccess; |
|
389 |
|
390 private: // data |
|
391 /// Own: Listbox control |
|
392 CEikColumnListBox* iListBox; |
|
393 /// Own: find box control |
|
394 CAknSearchField* iFindBox; |
|
395 /// Own: Thumbnail popup |
|
396 CPbkThumbnailPopup* iThumbnailPopup; |
|
397 /// Own: state flags |
|
398 TBitFlags iStateFlags; |
|
399 /// Own: the contact view this list control is displaying |
|
400 CContactViewBase* iBaseView; |
|
401 /// Own: wrapper view over iBaseView implementing find functionality |
|
402 CPbkContactFindView* iView; |
|
403 /// Own: find primitives implementation for iView |
|
404 MPbkFindPrimitives* iFindPrimitives; |
|
405 /// Own: Buffer for text retrieved from iFindBox |
|
406 mutable HBufC* iFindTextBuf; |
|
407 /// Own: marked items array returned from MarkedItemsL() |
|
408 mutable CContactIdArray* iMarkedItemsArray; |
|
409 /// Own: contact item id where focus was the last time |
|
410 TContactItemId iLastFocusId; |
|
411 /// Own: observers of this object |
|
412 RPointerArray<MPbkContactViewListControlObserver> iObservers; |
|
413 /// Own: standard listbox empty text |
|
414 HBufC* iOriginalEmptyText; |
|
415 /// Own: data loaded from resources |
|
416 TResourceData iResourceData; |
|
417 /// Own: indexes of the changed list items |
|
418 CArrayFixFlat<TInt> iChangedIndexes; |
|
419 /// Own: for setting and releasing contact ui control |
|
420 MPbkContactUiControlExtension* iControlExtension; |
|
421 /// Not own: for asking wheter a contact item can be selected |
|
422 MPbkFetchDlgSelection* iSelectionAccepter; |
|
423 /// Ref: Contact Engine |
|
424 CPbkContactEngine* iEngine; |
|
425 /// Own: Contact item index preceding the latest stylus tap |
|
426 TInt iPrevIndex; |
|
427 }; |
|
428 |
|
429 |
|
430 #endif // __CPbkContactViewListControl_H__ |
|
431 |
|
432 // End of File |