|
1 /* |
|
2 * Copyright (c) 2003-2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: The CMIDChoiceGroup listbox model |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef CMIDCHOICEGROUPMODEL_H |
|
19 #define CMIDCHOICEGROUPMODEL_H |
|
20 |
|
21 #include <lcdui.h> |
|
22 |
|
23 #include <coecntrl.h> |
|
24 |
|
25 #include <eikenv.h> |
|
26 // CAknFilteredTextListBoxModel inheritance in declaration |
|
27 #include <AknUtils.h> |
|
28 |
|
29 // using CMIDChoiceGroupElement for array of elements |
|
30 #include "CMIDChoiceGroupElement.h" |
|
31 |
|
32 // 3 seems like a reasonable default amount of elements in a choice |
|
33 const TInt KCGElementArrayGranularity = 3; |
|
34 |
|
35 // Forward declaration for the observer interface |
|
36 class CMIDChoiceGroupModel; |
|
37 |
|
38 // Choicegroup listbox model observer interface. The observer |
|
39 // is notified about element addition, removal and modification |
|
40 class MMIDChoiceGroupModelObserver |
|
41 { |
|
42 public: |
|
43 enum TChoiceGroupModelEvent |
|
44 { |
|
45 EElementAdded, |
|
46 EElementDeleted, |
|
47 EElementModified, |
|
48 EElementSelected, |
|
49 EUpdateStarted, |
|
50 EUpdateEnded |
|
51 }; |
|
52 public: |
|
53 virtual void HandleChoiceGroupModelEventL( |
|
54 CMIDChoiceGroupModel* aModel, |
|
55 TChoiceGroupModelEvent aEvent) = 0; |
|
56 }; |
|
57 |
|
58 |
|
59 /** |
|
60 * ChoiceGroup listbox model. Contains ChoiceGroup elements. |
|
61 * Figures out and provides strings with correct indices to the |
|
62 * listbox, and creates an image array for the column listbox data |
|
63 */ |
|
64 NONSHARABLE_CLASS(CMIDChoiceGroupModel) : public CAknFilteredTextListBoxModel |
|
65 { |
|
66 public: |
|
67 // Default constructor & destructor |
|
68 CMIDChoiceGroupModel(MMIDChoiceGroup::TChoiceType aType); |
|
69 virtual ~CMIDChoiceGroupModel(); |
|
70 |
|
71 public: |
|
72 // Two-phase constructor, initialises member arrays and stuff |
|
73 virtual void ConstructL(CEikonEnv* aEikonEnv); |
|
74 |
|
75 public: // Base class overrides |
|
76 // The model contains more than just the strings - need to override |
|
77 // number of items query |
|
78 virtual TInt NumberOfItems() const; |
|
79 |
|
80 // Provides a string with correct indices to images |
|
81 virtual TPtrC ItemText(TInt aItemIndex) const; |
|
82 |
|
83 // Initialises the element array with given strings |
|
84 void SetItemTextArray(MDesCArray* aItemTextArray); |
|
85 |
|
86 // Returns a pointer to the item text array (needs to create one |
|
87 // first, really. Actually this is not needed, and should be |
|
88 // overridden, if only to return NULL. |
|
89 MDesCArray* ItemTextArray() const; |
|
90 |
|
91 public: // New functions |
|
92 // Add an element to the end of the array |
|
93 void AppendElementL(CMIDChoiceGroupElement* aElement); |
|
94 |
|
95 // Insert an element at <aIndex>. Space must be reserved. |
|
96 void InsertElementL(TInt aIndex, CMIDChoiceGroupElement* aElement); |
|
97 |
|
98 // Delete element at <anIndex>. |
|
99 void DeleteElementL(TInt aIndex); |
|
100 |
|
101 // Delete all elements |
|
102 void DeleteAllL(); |
|
103 |
|
104 // Set properties of element at <aIndex> |
|
105 void SetElementL( |
|
106 TInt aIndex, |
|
107 const TDesC& aText, |
|
108 CFbsBitmap* aBitmap, |
|
109 CFbsBitmap* aMask); |
|
110 |
|
111 // Get element at position <aIndex> |
|
112 CMIDChoiceGroupElement* ElementAt(TInt aIndex) const; |
|
113 |
|
114 // Reserve space for <aCount> elements |
|
115 void SetReserveL(TInt aCount); |
|
116 |
|
117 // Get icon array, recreate if requested |
|
118 CArrayPtr<CGulIcon>* IconArray(TBool aReCreate = EFalse); |
|
119 |
|
120 // Set model observer associated with this model |
|
121 void SetObserver(MMIDChoiceGroupModelObserver* aObserver) |
|
122 { |
|
123 iObserver = aObserver; |
|
124 } |
|
125 |
|
126 // Get control associated with this model |
|
127 MMIDChoiceGroupModelObserver* Observer() |
|
128 { |
|
129 return iObserver; |
|
130 } |
|
131 |
|
132 // Set selection state of item at <index>. |
|
133 // If an item is set selected in an exclusive type choice, also |
|
134 // deselects other items. |
|
135 // Deselection of an item in an exlusive choice has no effect. |
|
136 // NOTE: Currently does not leave, but the name was 'L' in Choice interface |
|
137 void SelectElementL(TInt aIndex, TBool aSelected); |
|
138 |
|
139 // Begin model update. During the update the icon array will not be |
|
140 // updated nor the observer notified of element actions. |
|
141 // Once EndUpdate() is called, icon array is rebuilt and notification |
|
142 // will occur. |
|
143 void BeginUpdate(); |
|
144 |
|
145 // End a model update. At the end the icon array will be |
|
146 // recreated, and the associated observer notified. |
|
147 void EndUpdate(); |
|
148 |
|
149 // Returns the index of the selected element in an exclusive |
|
150 // choice, or -1 |
|
151 TInt SelectedElement(); |
|
152 |
|
153 //Constructs radio or checkbox on and off icons |
|
154 void ReConstructSelectionIconsL(); |
|
155 |
|
156 // Create an icon array to be given to the lbox column data |
|
157 // This should be done every time the contents of the model are changed, |
|
158 // or icon array is retrieved with create flag set. |
|
159 // NOTE that the indices in the array and the item strings should |
|
160 // be synchronised. The selection icon is always at index |
|
161 // 0 (selected) and 1 (not selected) |
|
162 void UpdateIconArrayL(); |
|
163 |
|
164 // Returns true if there is at least one item that has icon |
|
165 TBool HasIcons() const; |
|
166 |
|
167 private: // Utility functions |
|
168 |
|
169 // Clears all selections |
|
170 void ClearSelection(); |
|
171 |
|
172 // Report choicegroup event to observer |
|
173 void ReportEventL( |
|
174 MMIDChoiceGroupModelObserver::TChoiceGroupModelEvent aEvent); |
|
175 |
|
176 private: |
|
177 // Type of the choicegroup |
|
178 // (model is only really interested in selection type) |
|
179 MMIDChoiceGroup::TChoiceType iType; |
|
180 |
|
181 // Icon to display the selection state. Depending on the |
|
182 // choice type this is either a radiobutton or a checkbox |
|
183 CGulIcon* iIconSelected; |
|
184 CGulIcon* iIconNotSelected; |
|
185 |
|
186 // Dummy icon for elements that have no icon |
|
187 CGulIcon* iIconDummy; |
|
188 |
|
189 // Element array |
|
190 CArrayPtrFlat<CMIDChoiceGroupElement>* iElements; |
|
191 |
|
192 // Indicates that the model is being "bulk-updated", ie |
|
193 // BeginUpdate() has been called. Icon array and control updates |
|
194 // are supressed during an update operation, until EndUpdate(). |
|
195 TBool iUpdating; |
|
196 |
|
197 // Icon array, recreated when elements are added or |
|
198 // removed. Owned by the model, not listbox column data. |
|
199 CArrayPtrFlat<CGulIcon>* iIconArray; |
|
200 |
|
201 // Observer associated with this model. Observer is |
|
202 // reported about changes in the model, if set |
|
203 MMIDChoiceGroupModelObserver* iObserver; |
|
204 }; |
|
205 |
|
206 |
|
207 #endif // CMIDCHOICEGROUPMODEL_H |