author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 15 Sep 2010 12:05:25 +0300 | |
branch | RCL_3 |
changeset 77 | 7cee158cb8cd |
parent 66 | 2455ef1f5bbc |
child 83 | 26b2b12093af |
permissions | -rw-r--r-- |
66 | 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 control container. Owns and manipulates |
|
15 |
* the choicegroup model and creates / deletes the actual |
|
16 |
* control as needed. |
|
17 |
* |
|
18 |
*/ |
|
19 |
||
20 |
#ifndef CMIDCHOICEGROUPCONTROL_H |
|
21 |
#define CMIDCHOICEGROUPCONTROL_H |
|
22 |
||
23 |
#include <eiklbo.h> |
|
24 |
#include <lcdui.h> |
|
25 |
||
26 |
#include <AknUtils.h> |
|
27 |
// CAknPopupList inheritance in CMIDChoiceGroupPopupList declaration |
|
28 |
#include <aknPopup.h> |
|
29 |
||
30 |
#include "CMIDChoiceGroupListBox.h" |
|
31 |
#include "CMIDChoiceGroupModel.h" |
|
32 |
||
33 |
#ifdef RD_SCALABLE_UI_V2 |
|
34 |
#include "CMIDForm.h" |
|
35 |
#endif |
|
36 |
||
37 |
||
38 |
#ifdef RD_TACTILE_FEEDBACK |
|
39 |
#include <touchfeedback.h> |
|
40 |
#endif |
|
41 |
||
42 |
||
43 |
class CMIDChoiceGroupItem; |
|
44 |
||
45 |
// Forward declaration for the observer interface |
|
46 |
class CMIDChoiceGroupControl; |
|
47 |
||
48 |
// Choicegroup control observer interface. The observer |
|
49 |
// is notified when the control size changes, so that it can adjust |
|
50 |
// its size accordingly |
|
51 |
class MMIDChoiceGroupControlObserver |
|
52 |
{ |
|
53 |
public: |
|
54 |
enum TChoiceGroupControlEvent |
|
55 |
{ |
|
56 |
ESizeChanged, |
|
57 |
EScrollRequest |
|
58 |
}; |
|
59 |
public: |
|
60 |
virtual void HandleChoiceGroupControlEventL( |
|
61 |
CMIDChoiceGroupControl* aControl, |
|
62 |
TChoiceGroupControlEvent aEvent, |
|
63 |
TAny* aParam) = 0; |
|
64 |
}; |
|
65 |
||
66 |
// Popup list that shows the contents of the popup choice group. |
|
67 |
// This derived class is needed in order that opened popup can be |
|
68 |
// properly resized if its content changes. |
|
69 |
NONSHARABLE_CLASS(CMIDChoiceGroupPopupList) : public CAknPopupList |
|
70 |
{ |
|
71 |
public: |
|
72 |
static CMIDChoiceGroupPopupList* NewL(CEikListBox* aListBox, TInt aCbaResource, |
|
73 |
AknPopupLayouts::TAknPopupLayouts aType); |
|
74 |
virtual ~CMIDChoiceGroupPopupList(); |
|
75 |
||
76 |
// Resizes the popup list |
|
77 |
void ResizeList(); |
|
78 |
||
79 |
#ifdef RD_SCALABLE_UI_V2 |
|
80 |
public: // from CCoeControl |
|
81 |
void HandlePointerEventL(const TPointerEvent& aPointerEvent); |
|
82 |
#endif //RD_SCALABLE_UI_V2 |
|
83 |
||
84 |
private: |
|
85 |
CMIDChoiceGroupPopupList(); |
|
86 |
}; |
|
87 |
||
88 |
// Choice group control. Encapsulates the actual control and popup |
|
89 |
NONSHARABLE_CLASS(CMIDChoiceGroupControl) : |
|
90 |
public CCoeControl, |
|
91 |
public MEikListBoxObserver, |
|
92 |
public MMIDChoiceGroupModelObserver |
|
93 |
{ |
|
94 |
public: |
|
95 |
// Constants identifying columns of column listobox data used |
|
96 |
// when choice group is created and layouted |
|
97 |
enum TColumnDataIndexes |
|
98 |
{ |
|
99 |
ERadioButtonOrCheckBoxColumn, |
|
100 |
EUserDefinedImagesColumn, |
|
101 |
ETextColumn |
|
102 |
}; |
|
103 |
||
104 |
CMIDChoiceGroupControl( |
|
105 |
MMIDChoiceGroup::TChoiceType aType, |
|
106 |
CMIDChoiceGroupItem* aItem); |
|
107 |
||
108 |
virtual ~CMIDChoiceGroupControl(); |
|
109 |
||
110 |
// Constructs the ChoiceGroup control and the choicegroup model, |
|
111 |
// but does not yet create the actual listbox. The listbox is created |
|
112 |
// by a call to CreateActualControlL(), when the parent window |
|
113 |
// is known (ie when the CMIDChoiceGroupItem is added to a CMIDForm |
|
114 |
void ConstructL( |
|
115 |
RArray<TPtrC>& aStringArray, |
|
116 |
RArray<MMIDImage*>& aImageArray); |
|
117 |
||
118 |
// Creates the listbox control according to choice type and |
|
119 |
// fills it with elements, if the model already contains any |
|
120 |
void CreateControlL(const CCoeControl* aParent, const TRect& aRect); |
|
121 |
||
122 |
// Deletes the listbox control (when removed from a form). Does |
|
123 |
// not empty the model, however |
|
124 |
void DeleteControl(); |
|
125 |
||
126 |
// Set coitrol observer associated with this control |
|
127 |
void SetObserver(MMIDChoiceGroupControlObserver* aObserver) |
|
128 |
{ |
|
129 |
iObserver = aObserver; |
|
130 |
} |
|
131 |
||
132 |
// Get observer associated with this control |
|
133 |
MMIDChoiceGroupControlObserver* Observer() |
|
134 |
{ |
|
135 |
return iObserver; |
|
136 |
} |
|
137 |
||
138 |
void HiliteFirstElement(TBool aEnableHighlight); |
|
139 |
void HiliteLastElement(TBool aEnableHighlight); |
|
140 |
void EnableListHighlight(TBool aEnable); |
|
141 |
TBool IsCurrentItemSelected(); |
|
142 |
void ToggleCurrentItemSelectionL(); |
|
143 |
||
144 |
// Nofication method to inform that the curent item has changed in the list |
|
145 |
void CurrentItemChanged(); |
|
146 |
||
147 |
// Pops up the popup choice |
|
148 |
void DoPopupL(); |
|
149 |
||
150 |
/** |
|
151 |
* Returns the number of elements in the choice group |
|
152 |
**/ |
|
153 |
TInt NumberOfElements() const; |
|
154 |
||
155 |
public: // delegated from MMIDChoiceGroup |
|
156 |
void InsertElementL(TInt aIndex, const TDesC& aText, MMIDImage* aImage); |
|
157 |
void DeleteElementL(TInt aIndex); |
|
158 |
void DeleteAllL(); |
|
159 |
void SetElementL(TInt aIndex, const TDesC& aText, MMIDImage* aImage); |
|
160 |
void SelectElementL(TInt aIndex, TBool aSelected); |
|
161 |
TBool IsSelected(TInt aIndex); |
|
162 |
void SetFontL(TInt aIndex, MMIDFont* aFont); |
|
163 |
void SetFitPolicyL(TInt aFitPolicy); |
|
164 |
||
165 |
public: // from MMIDChoiceGroupModelObserver |
|
166 |
virtual void HandleChoiceGroupModelEventL( |
|
167 |
CMIDChoiceGroupModel* aModel, |
|
168 |
TChoiceGroupModelEvent aEvent); |
|
77
7cee158cb8cd
Revision: v2.2.13
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
169 |
#ifdef RD_JAVA_S60_RELEASE_9_2 |
7cee158cb8cd
Revision: v2.2.13
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
170 |
virtual TBool IsControlOnFormHighlighted(); |
7cee158cb8cd
Revision: v2.2.13
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
171 |
#endif // RD_JAVA_S60_RELEASE_9_2 |
66 | 172 |
|
173 |
public: // from MEikListBoxObserver |
|
174 |
virtual void HandleListBoxEventL(CEikListBox* aControl, TListBoxEvent aEventType); |
|
175 |
||
176 |
public: // from CCoeControl |
|
177 |
TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType); |
|
178 |
||
179 |
#ifdef RD_SCALABLE_UI_V2 |
|
180 |
void HandlePointerEventL(const TPointerEvent& aPointerEvent); |
|
181 |
#endif //RD_SCALABLE_UI_V2 |
|
182 |
||
183 |
// void SetContainerWindowL(const CCoeControl& aContainer); |
|
184 |
TInt CountComponentControls() const; |
|
185 |
CCoeControl* ComponentControl(TInt aIndex) const; |
|
186 |
||
187 |
void SizeChanged(); |
|
188 |
void PositionChanged(); |
|
189 |
// Calculates and returns the minimum size required by the control |
|
190 |
TSize MinimumSize() const; |
|
191 |
||
192 |
// Draws the control (only used in popup mode) |
|
193 |
virtual void Draw(const TRect& aRect) const; |
|
194 |
||
195 |
// Responds to focus change. |
|
196 |
void FocusChanged(TDrawNow aDrawNow); |
|
197 |
||
198 |
// Handles a change to control's resources. |
|
199 |
void HandleResourceChange(TInt aType); |
|
200 |
||
201 |
TTypeUid::Ptr MopSupplyObject(TTypeUid aId); |
|
202 |
||
203 |
public: |
|
204 |
inline MMIDChoiceGroup::TChoiceType ChoiceType() const; |
|
205 |
void ClosePopup(); |
|
206 |
||
207 |
// Sets up the columndata columns |
|
208 |
void SetupColumnsL(CColumnListBoxData* aColumnData); |
|
209 |
||
210 |
/** |
|
211 |
* Shows info popup for the current item if text does not fit and was ellipsed |
|
212 |
*/ |
|
213 |
void ShowInfoPopup(); |
|
214 |
||
215 |
/** |
|
216 |
* Scrolls the form in order to get the focused sub-item on screen |
|
217 |
*/ |
|
218 |
void RestoreFocus(); |
|
219 |
||
220 |
#ifdef RD_SCALABLE_UI_V2 |
|
221 |
/** |
|
222 |
* In timed scrolling calculates the needed scroll amount and |
|
223 |
* requests (via CMIDChoiceGroupItem) the form to scroll. |
|
224 |
* |
|
225 |
* @param aDirection The direction of the scroll |
|
226 |
*/ |
|
227 |
void TimedScroll(CMIDForm::TDirection aDirection); |
|
228 |
#endif |
|
229 |
||
230 |
#ifdef RD_JAVA_S60_RELEASE_9_2 |
|
231 |
CMIDForm* Form() const; |
|
232 |
||
233 |
/** |
|
234 |
* Fuction sets ESingleClickDisabledHighlight - item drawer flags |
|
235 |
* and reports current highlight element change event |
|
236 |
*/ |
|
237 |
void SingleClickDisableHighlightL(TBool aDisable); |
|
238 |
||
77
7cee158cb8cd
Revision: v2.2.13
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
239 |
CMIDControlItem* ControlItem() const; |
7cee158cb8cd
Revision: v2.2.13
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
240 |
CMIDChoiceGroupListBox* InnerListBoxControl() const; |
7cee158cb8cd
Revision: v2.2.13
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
66
diff
changeset
|
241 |
CMIDChoiceGroupModel* InnerListBoxModel() const; |
66 | 242 |
#endif // RD_JAVA_S60_RELEASE_9_2 |
243 |
||
244 |
#ifdef RD_TACTILE_FEEDBACK |
|
245 |
private: |
|
246 |
MTouchFeedback* iFeedback; |
|
247 |
#endif |
|
248 |
||
249 |
||
250 |
||
251 |
protected: |
|
252 |
||
253 |
private: |
|
254 |
void DrawIcon(CGulIcon* aIcon) const; |
|
255 |
void DrawText(const TDesC& aText) const; |
|
256 |
||
257 |
// Fill listbox model with items given at construct time |
|
258 |
void PopulateModelL(RArray<TPtrC>& aStringArray,RArray<MMIDImage*>& aImageArray); |
|
259 |
||
260 |
// Creates a new element with text and image |
|
261 |
CMIDChoiceGroupElement* NewElementLC(const TDesC& aString, MMIDImage* aImage); |
|
262 |
||
263 |
// Report control event to observer |
|
264 |
void ReportEventL(MMIDChoiceGroupControlObserver::TChoiceGroupControlEvent aEvent, |
|
265 |
TAny* aParam = NULL); |
|
266 |
||
267 |
// Calculates, whether the current item in the choice is visible, |
|
268 |
// and requests a form scroll, if necessary |
|
269 |
void RequestScrollIfNeededL(); |
|
270 |
||
271 |
// Functions for creating the choice listbox. Create() uses Allocate() |
|
272 |
// and Construct(). Split to enable using LB pointer as parameter to |
|
273 |
// AknPopup, and AknPopup in turn as parent to LB construction |
|
274 |
CMIDChoiceGroupListBox* CreateListBoxL(const CCoeControl* aParent = NULL); |
|
275 |
CMIDChoiceGroupListBox* AllocateListBoxL(); |
|
276 |
void ConstructListBoxL( |
|
277 |
CMIDChoiceGroupListBox* aListBox, |
|
278 |
const CCoeControl* aParent = NULL); |
|
279 |
||
280 |
// Deletes the choice listbox (taking care not to destroy the icon array) |
|
281 |
void DeleteListBox(CMIDChoiceGroupListBox* aListBox); |
|
282 |
||
283 |
// Returns whether this is a popup |
|
284 |
inline TBool IsPopup() const; |
|
285 |
||
286 |
TRect ListBoxRect(const TRect& aRect) const; |
|
287 |
||
288 |
/** |
|
289 |
* Sets selection state of element at <aIndex> and posts a java event |
|
290 |
* if needed |
|
291 |
* |
|
292 |
* @param aIndex The index of the element |
|
293 |
* @param aSelected The new selection state of the element |
|
294 |
* @param aPostEvent If true, itemStateChanged event is sent to the midlet |
|
295 |
*/ |
|
296 |
void SelectElementL(TInt aIndex, TBool aSelected, TBool aPostEvent); |
|
297 |
||
298 |
void UpdateMargins(); |
|
299 |
void UpdatePopupListAppearanceL(TChoiceGroupModelEvent aEvent); |
|
300 |
||
301 |
#ifdef RD_SCALABLE_UI_V2 |
|
302 |
/** |
|
303 |
* Finds the index of the first choicegroup element of which more than half is outside the |
|
304 |
* visible form area. aScrollDirection indicates if the element is searched on the top or |
|
305 |
* bottom of the form. The choicegroup listbox must be partially on visible form area in order |
|
306 |
* this function to return a valid index. If the listbox is fully invisible, KErrNotFound is returned. |
|
307 |
* |
|
308 |
* @param aScrollDireection The direction to which the form is being scrolled |
|
309 |
* @return Index of the element if element is found in wanted direction, KErrNotFound otherwise |
|
310 |
*/ |
|
311 |
TInt FirstInvisibleElement(CMIDForm::TDirection aScrollDirection) const; |
|
312 |
#endif |
|
313 |
||
314 |
private: |
|
315 |
// Type of the choicegroup (list, popup) |
|
316 |
MMIDChoiceGroup::TChoiceType iType; |
|
317 |
||
318 |
// The parent item |
|
319 |
CMIDChoiceGroupItem* iItem; |
|
320 |
||
321 |
// Observer (usually the form item) |
|
322 |
MMIDChoiceGroupControlObserver* iObserver; |
|
323 |
||
324 |
// Element container model (owned outside of the listbox, because |
|
325 |
// elements may be added before the control is added to a form, ie |
|
326 |
// before the listbox has a parent window and can be created) |
|
327 |
CMIDChoiceGroupModel* iModel; |
|
328 |
||
329 |
// The actual listbox control |
|
330 |
CMIDChoiceGroupListBox* iListBox; |
|
331 |
||
332 |
/** The rect for placing the icon of the popup choice group, see SizeChanged() */ |
|
333 |
TRect iPopupIconRect; |
|
334 |
||
335 |
/** The layout object for drawing the popup choice group text, see SizeChanged() */ |
|
336 |
TAknLayoutText iPopupTextLayout; |
|
337 |
||
338 |
// Margins for choicegroup content. This includes also the margin between the label and listbox. |
|
339 |
TMargins8 iContentMargins; |
|
340 |
||
341 |
// Pointer to the popup list. This is needed in order that popup can be properly updated |
|
342 |
// if the list box model is modified while the popup is open. No need to delete |
|
343 |
// iPopupList in destructor because popup list is created and deleted in DoPopupL(). |
|
344 |
// iPopupList is valid only while popup list is open, otherwise it is NULL. |
|
345 |
CMIDChoiceGroupPopupList* iPopupList; |
|
346 |
#ifdef RD_SCALABLE_UI_V2 |
|
347 |
TBool iPointerDragHasStarted; //True if drag has started |
|
348 |
||
349 |
// True if focus has changed between TPointerEvent::EButton1Down and |
|
350 |
// TPointerEvent::EButton1Up events. |
|
351 |
TBool iFocusChangingWithPen; |
|
352 |
||
353 |
#endif //RD_SCALABLE_UI_V2 |
|
354 |
}; |
|
355 |
||
356 |
// --- Inlines |
|
357 |
||
358 |
// Return choice group type |
|
359 |
inline MMIDChoiceGroup::TChoiceType CMIDChoiceGroupControl::ChoiceType() const |
|
360 |
{ |
|
361 |
return iType; |
|
362 |
} |
|
363 |
||
364 |
// Returns whether this is a popup |
|
365 |
inline TBool CMIDChoiceGroupControl::IsPopup() const |
|
366 |
{ |
|
367 |
return (iType == MMIDChoiceGroup::EPopup); |
|
368 |
} |
|
369 |
||
370 |
#endif // CMIDCHOICEGROUPCONTROL_H |