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);
|
|
169 |
|
|
170 |
public: // from MEikListBoxObserver
|
|
171 |
virtual void HandleListBoxEventL(CEikListBox* aControl, TListBoxEvent aEventType);
|
|
172 |
|
|
173 |
public: // from CCoeControl
|
|
174 |
TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType);
|
|
175 |
|
|
176 |
#ifdef RD_SCALABLE_UI_V2
|
|
177 |
void HandlePointerEventL(const TPointerEvent& aPointerEvent);
|
|
178 |
#endif //RD_SCALABLE_UI_V2
|
|
179 |
|
|
180 |
// void SetContainerWindowL(const CCoeControl& aContainer);
|
|
181 |
TInt CountComponentControls() const;
|
|
182 |
CCoeControl* ComponentControl(TInt aIndex) const;
|
|
183 |
|
|
184 |
void SizeChanged();
|
|
185 |
void PositionChanged();
|
|
186 |
// Calculates and returns the minimum size required by the control
|
|
187 |
TSize MinimumSize() const;
|
|
188 |
|
|
189 |
// Draws the control (only used in popup mode)
|
|
190 |
virtual void Draw(const TRect& aRect) const;
|
|
191 |
|
|
192 |
// Responds to focus change.
|
|
193 |
void FocusChanged(TDrawNow aDrawNow);
|
|
194 |
|
|
195 |
// Handles a change to control's resources.
|
|
196 |
void HandleResourceChange(TInt aType);
|
|
197 |
|
|
198 |
TTypeUid::Ptr MopSupplyObject(TTypeUid aId);
|
|
199 |
|
|
200 |
public:
|
|
201 |
inline MMIDChoiceGroup::TChoiceType ChoiceType() const;
|
|
202 |
void ClosePopup();
|
|
203 |
|
|
204 |
// Sets up the columndata columns
|
|
205 |
void SetupColumnsL(CColumnListBoxData* aColumnData);
|
|
206 |
|
|
207 |
/**
|
|
208 |
* Shows info popup for the current item if text does not fit and was ellipsed
|
|
209 |
*/
|
|
210 |
void ShowInfoPopup();
|
|
211 |
|
|
212 |
/**
|
|
213 |
* Scrolls the form in order to get the focused sub-item on screen
|
|
214 |
*/
|
|
215 |
void RestoreFocus();
|
|
216 |
|
|
217 |
#ifdef RD_SCALABLE_UI_V2
|
|
218 |
/**
|
|
219 |
* In timed scrolling calculates the needed scroll amount and
|
|
220 |
* requests (via CMIDChoiceGroupItem) the form to scroll.
|
|
221 |
*
|
|
222 |
* @param aDirection The direction of the scroll
|
|
223 |
*/
|
|
224 |
void TimedScroll(CMIDForm::TDirection aDirection);
|
|
225 |
#endif
|
|
226 |
|
|
227 |
#ifdef RD_JAVA_S60_RELEASE_9_2
|
|
228 |
CMIDForm* Form() const;
|
|
229 |
|
|
230 |
/**
|
|
231 |
* Fuction sets ESingleClickDisabledHighlight - item drawer flags
|
|
232 |
* and reports current highlight element change event
|
|
233 |
*/
|
|
234 |
void SingleClickDisableHighlightL(TBool aDisable);
|
|
235 |
|
|
236 |
#endif // RD_JAVA_S60_RELEASE_9_2
|
|
237 |
|
|
238 |
#ifdef RD_TACTILE_FEEDBACK
|
|
239 |
private:
|
|
240 |
MTouchFeedback* iFeedback;
|
|
241 |
#endif
|
|
242 |
|
|
243 |
|
|
244 |
|
|
245 |
protected:
|
|
246 |
|
|
247 |
private:
|
|
248 |
void DrawIcon(CGulIcon* aIcon) const;
|
|
249 |
void DrawText(const TDesC& aText) const;
|
|
250 |
|
|
251 |
// Fill listbox model with items given at construct time
|
|
252 |
void PopulateModelL(RArray<TPtrC>& aStringArray,RArray<MMIDImage*>& aImageArray);
|
|
253 |
|
|
254 |
// Creates a new element with text and image
|
|
255 |
CMIDChoiceGroupElement* NewElementLC(const TDesC& aString, MMIDImage* aImage);
|
|
256 |
|
|
257 |
// Report control event to observer
|
|
258 |
void ReportEventL(MMIDChoiceGroupControlObserver::TChoiceGroupControlEvent aEvent,
|
|
259 |
TAny* aParam = NULL);
|
|
260 |
|
|
261 |
// Calculates, whether the current item in the choice is visible,
|
|
262 |
// and requests a form scroll, if necessary
|
|
263 |
void RequestScrollIfNeededL();
|
|
264 |
|
|
265 |
// Functions for creating the choice listbox. Create() uses Allocate()
|
|
266 |
// and Construct(). Split to enable using LB pointer as parameter to
|
|
267 |
// AknPopup, and AknPopup in turn as parent to LB construction
|
|
268 |
CMIDChoiceGroupListBox* CreateListBoxL(const CCoeControl* aParent = NULL);
|
|
269 |
CMIDChoiceGroupListBox* AllocateListBoxL();
|
|
270 |
void ConstructListBoxL(
|
|
271 |
CMIDChoiceGroupListBox* aListBox,
|
|
272 |
const CCoeControl* aParent = NULL);
|
|
273 |
|
|
274 |
// Deletes the choice listbox (taking care not to destroy the icon array)
|
|
275 |
void DeleteListBox(CMIDChoiceGroupListBox* aListBox);
|
|
276 |
|
|
277 |
// Returns whether this is a popup
|
|
278 |
inline TBool IsPopup() const;
|
|
279 |
|
|
280 |
TRect ListBoxRect(const TRect& aRect) const;
|
|
281 |
|
|
282 |
/**
|
|
283 |
* Sets selection state of element at <aIndex> and posts a java event
|
|
284 |
* if needed
|
|
285 |
*
|
|
286 |
* @param aIndex The index of the element
|
|
287 |
* @param aSelected The new selection state of the element
|
|
288 |
* @param aPostEvent If true, itemStateChanged event is sent to the midlet
|
|
289 |
*/
|
|
290 |
void SelectElementL(TInt aIndex, TBool aSelected, TBool aPostEvent);
|
|
291 |
|
|
292 |
void UpdateMargins();
|
|
293 |
void UpdatePopupListAppearanceL(TChoiceGroupModelEvent aEvent);
|
|
294 |
|
|
295 |
#ifdef RD_SCALABLE_UI_V2
|
|
296 |
/**
|
|
297 |
* Finds the index of the first choicegroup element of which more than half is outside the
|
|
298 |
* visible form area. aScrollDirection indicates if the element is searched on the top or
|
|
299 |
* bottom of the form. The choicegroup listbox must be partially on visible form area in order
|
|
300 |
* this function to return a valid index. If the listbox is fully invisible, KErrNotFound is returned.
|
|
301 |
*
|
|
302 |
* @param aScrollDireection The direction to which the form is being scrolled
|
|
303 |
* @return Index of the element if element is found in wanted direction, KErrNotFound otherwise
|
|
304 |
*/
|
|
305 |
TInt FirstInvisibleElement(CMIDForm::TDirection aScrollDirection) const;
|
|
306 |
#endif
|
|
307 |
|
|
308 |
private:
|
|
309 |
// Type of the choicegroup (list, popup)
|
|
310 |
MMIDChoiceGroup::TChoiceType iType;
|
|
311 |
|
|
312 |
// The parent item
|
|
313 |
CMIDChoiceGroupItem* iItem;
|
|
314 |
|
|
315 |
// Observer (usually the form item)
|
|
316 |
MMIDChoiceGroupControlObserver* iObserver;
|
|
317 |
|
|
318 |
// Element container model (owned outside of the listbox, because
|
|
319 |
// elements may be added before the control is added to a form, ie
|
|
320 |
// before the listbox has a parent window and can be created)
|
|
321 |
CMIDChoiceGroupModel* iModel;
|
|
322 |
|
|
323 |
// The actual listbox control
|
|
324 |
CMIDChoiceGroupListBox* iListBox;
|
|
325 |
|
|
326 |
/** The rect for placing the icon of the popup choice group, see SizeChanged() */
|
|
327 |
TRect iPopupIconRect;
|
|
328 |
|
|
329 |
/** The layout object for drawing the popup choice group text, see SizeChanged() */
|
|
330 |
TAknLayoutText iPopupTextLayout;
|
|
331 |
|
|
332 |
// Margins for choicegroup content. This includes also the margin between the label and listbox.
|
|
333 |
TMargins8 iContentMargins;
|
|
334 |
|
|
335 |
// Pointer to the popup list. This is needed in order that popup can be properly updated
|
|
336 |
// if the list box model is modified while the popup is open. No need to delete
|
|
337 |
// iPopupList in destructor because popup list is created and deleted in DoPopupL().
|
|
338 |
// iPopupList is valid only while popup list is open, otherwise it is NULL.
|
|
339 |
CMIDChoiceGroupPopupList* iPopupList;
|
|
340 |
#ifdef RD_SCALABLE_UI_V2
|
|
341 |
TBool iPointerDragHasStarted; //True if drag has started
|
|
342 |
|
|
343 |
// True if focus has changed between TPointerEvent::EButton1Down and
|
|
344 |
// TPointerEvent::EButton1Up events.
|
|
345 |
TBool iFocusChangingWithPen;
|
|
346 |
|
|
347 |
#endif //RD_SCALABLE_UI_V2
|
|
348 |
};
|
|
349 |
|
|
350 |
// --- Inlines
|
|
351 |
|
|
352 |
// Return choice group type
|
|
353 |
inline MMIDChoiceGroup::TChoiceType CMIDChoiceGroupControl::ChoiceType() const
|
|
354 |
{
|
|
355 |
return iType;
|
|
356 |
}
|
|
357 |
|
|
358 |
// Returns whether this is a popup
|
|
359 |
inline TBool CMIDChoiceGroupControl::IsPopup() const
|
|
360 |
{
|
|
361 |
return (iType == MMIDChoiceGroup::EPopup);
|
|
362 |
}
|
|
363 |
|
|
364 |
#endif // CMIDCHOICEGROUPCONTROL_H
|