2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
14 * Description: CAknChoiceList - Choice list for S60
20 #ifndef AKNCHOICELIST_H
21 #define AKNCHOICELIST_H
24 #include <AknControl.h>
27 // forward declarations
30 class CAknChoiceListPopup;
31 class CAknChoiceListPopupList;
32 class CAknsFrameBackgroundControlContext;
33 class CAknInfoPopupNoteController;
39 * Choice list is new component, which allows selection from vertical list of choices.
40 * By default choice list shows currently selected item and a arrow for opening the
41 * the choice list. Choice list can be used also without showing current selection.
45 class CAknChoiceList : public CAknControl, public MCoeControlObserver
49 /* Flags for choice list types and positioning */
50 enum TAknChoiceListFlags
52 /* Using default choice list with popup list */
53 EAknChoiceListWithCurrentSelection = 0x01,
54 /* Using user defined button to open choice list */
55 EAknChoiceListWithoutCurrentSelection = 0x02,
56 /* Popup positioning flags */
57 EAknChoiceListPositionLeft = 0x04,
58 EAknChoiceListPositionRight = 0x08,
59 EAknChoiceListPositionBottom = 0x10
62 /* Tooltip positioning */
65 EPositionTop = 1, /* Tooltip alignment vertically to top */
66 EPositionBottom, /* Tooltip alignment vertically to bottom */
67 EPositionLeft, /* Tooltip alignment horizontally to left */
68 EPositionRight /* Tooltip alignment horizontally to right */
73 * Two-phased constructor.
74 * If the default flag is used then choice list shows an opening arrow and selected item on its
75 * left side. If flag EAknChoiceListUsesButton is and user has defined own button then choice list
76 * open with items in the given array. Selected item is not show when choice list is closed.
77 * @param aParent the parent control for choice list
78 * @param aItemArray Array of items to be shown in the choicelist. Transfers ownership.
79 * @param aFlags Flags for choice list type and positioning
80 * @param aButton user defined button for choicelist. Button replaces the typical choice list.
81 * Transfers ownership.
83 IMPORT_C static CAknChoiceList* NewL( CCoeControl* aParent, CDesCArray* aItemArray, TInt aFlags = EAknChoiceListWithCurrentSelection, CAknButton* aButton = NULL );
86 * Two-phased constructor.
87 * If the default flag is used then choice list shows an opening arrow and selected item on its
88 * left side. If flag EAknChoiceListUsesButton is and user has defined own button then choice list
89 * open with items in the given array. Selected item is not show when choice list is closed.
90 * @param aParent the parent control for choice list
91 * @param aItemArray Array of items to be shown in the choicelist. Transfers ownership.
92 * @param aFlags Flags for choice list type and positioning
93 * @param aButton user defined button for choicelist. Button replaces the typical choice list.
94 * Transfers ownership.
96 IMPORT_C static CAknChoiceList* NewLC( CCoeControl* aParent, CDesCArray* aItemArray, TInt aFlags = EAknChoiceListWithCurrentSelection, CAknButton* aButton = NULL );
105 * Choicelist can be opened with this function. If the choicelist is already
106 * open nothing will happen.
107 * @return KErrNone if succeeded
109 IMPORT_C TInt ShowChoiceListL();
112 * Set certain index of the choice list array to selected
113 * @param aIndex Index of the array to be selected as default
115 IMPORT_C void SetSelectedIndex( const TInt aIndex );
118 * Returns selected index from the choice list array
119 * @return TInt selected index
121 IMPORT_C TInt SelectedIndex() const;
124 * Set certain array as the contents of the choice list.
125 * It's recommended to use CDesCArrayFlat. The ownership of the array is transferred
127 * @param aArray Array of text items to be inserted as the content for choice list
129 IMPORT_C void SetItems( CDesCArray* aArray );
132 * Set certain array as the contents of the choice list.
133 * It's recommended to use CDesCArrayFlat.
134 * @param aResourceId Resource id for an array.
136 IMPORT_C void SetItemsL( TInt aResourceId );
139 * Add a text as a new item in the end of the choice list array.
140 * @param aDesC Pointer to a descriptor item that should be appended to the array.
141 * Transfers ownership.
142 * @return index in the choicelist array for newly added item.
144 IMPORT_C TInt AddItemL( const TDesC* aDesC );
147 * Removes an item from the choice list array with the given index.
148 * @param aIndex index for the item that should be removed from the choice list array
150 IMPORT_C void RemoveItem( const TInt aIndex );
153 * Sets flags for choice list.
154 * Choice lists position can be changed in runtime with right flags.
155 * @param aFlags The flags to be set for choice list
157 IMPORT_C void SetFlags( const TInt aFlags );
160 * Return choice list specific flags.
161 * @return choice list flags
163 IMPORT_C TInt Flags() const;
166 * Set the button that launches choice list opening.
167 * @param aButton The Button for opening choice list control
169 IMPORT_C void SetButtonL( CAknButton* aButton );
172 * Hide choice list popup. Current selection is not selected.
174 IMPORT_C void HideChoiceList();
177 * Set text for tooltip
178 * @param aText The text shown as tooltip
180 IMPORT_C void SetTooltipTextL( const TDesC& aText );
183 * Set the delays for tooltip
184 * @param aBeforeTimeout The delay in milliseconds before tooltip
185 * is shown. The default is 150 milliseconds
186 * @param aInViewTiemout The interval in milliseconds how long the
187 * tooltip is displayed. The default is 3000 milliseconds.
189 IMPORT_C void SetTooltipTimeouts( const TInt aBeforeTimeout,
190 const TInt aInViewTimeout );
192 * Set the postion of tooltip
193 * @param aPosition The position expressed with TTooltipPosition
194 * The default is EPositionTop
196 IMPORT_C void SetTooltipPosition( const TTooltipPosition aPosition );
201 * From CCoeControl. Returns the control inside control with given index.
202 * @param aIndex Index of a control be returned
203 * @return A Pointer to control.
205 IMPORT_C CCoeControl* ComponentControl( TInt aIndex ) const;
208 * From CCoeControl. Returns number of controls inside the control.
209 * @return Number of component controls.
211 IMPORT_C TInt CountComponentControls() const;
214 * From CCoeControl. Returns the Minimum size needed by the control.
215 * @return TSize minimum size.
217 IMPORT_C TSize MinimumSize();
220 * From CCoeControl. Handles a change to the control's resources.
221 * @param aType A message UID value.
223 IMPORT_C void HandleResourceChange( TInt aType );
226 * From CCoeControl. Handles key events.
227 * @param aKeyEvent the key event
228 * @param aType The type of key event
229 * @return Indicates whether or not the keyevent was used by this control
231 IMPORT_C TKeyResponse OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType );
234 * From CCoeControl. Draws control to given area
235 * @param aRect The rectangle that should be drawn by the control.
237 IMPORT_C void Draw( const TRect& aRect ) const;
243 * Responds to changes in the position of a control.
246 IMPORT_C virtual void PositionChanged();
249 // From MCoeControlObserver
252 * From MCoeControlObserver. Handles an event from an observed control.
253 * If this component has observer, then a EEventStateChanged is sent to it
254 * when a item is selected from choice list
255 * @param aControl The control that sent the event.
256 * @param aEventType The event type.
258 IMPORT_C void HandleControlEventL( CCoeControl* aControl, TCoeEvent aEventType );
263 * Insert new item to a certain index. The rest of the array will be reindexed.
264 * If given index is beyond current array then it's just appended to the end of the array.
265 * @param aIndex The array index where new item is going to be inserted.
266 * @param aText Items text
267 * @return The index of newly inserted item. Index can be other than passed if given index
268 * is out of array bounds
270 IMPORT_C TInt InsertItemL( const TInt aIndex, const TDesC& aText );
277 * From CCoeControl. Sets the size and position of the component.
282 * From CCoeControl. Handles pointer events
283 * @param aPointerEvent the pointer event be be handled.
285 void HandlePointerEventL( const TPointerEvent& aPointerEvent );
290 * C++ Default Constructor
295 * 2nd phase constructor
296 * @param aParent the parent control for choice list
297 * @param aItemArray Array of items to be shown in the choicelist
298 * @param aFlags Flags for choice list type and positioning
299 * @param aButton user defined button for choicelist. Button replaces the typical choice list
301 void ConstructL( CCoeControl* aParent, CDesCArray* aItemArray, TInt aFlags, CAknButton* aButton );
304 * Construct the typical choice list that open with arrow and show current selection
305 * even in the closed state.
307 void ConstructTypicalChoiceListL();
310 * Calculate positioning for the opened choice list popup by the given position flag.
328 * Flags for choice list
333 * Currently selected index of an item that is stored in choice list array.
338 * Used to store if the choice list is closed mode or not.
343 * Button for opening the choicelist. If choice lists type is
344 * EAknChoiceListWithCurrentSelection this is the arrow button.
345 * Otherwise this is user defined.
351 * Label that shows the currently selected item if choice list type is
352 * EAknChoiceListWithCurrentSelection. Otherwise this will not be used.
358 * Array that stores all the items in the choice list.
364 * Pointer to current choice list popup window. Popup window is
365 * used only internally and it cannot be accessed from outside.
368 CAknChoiceListPopup* iPopup;
371 * Component used to show tooltip
374 CAknInfoPopupNoteController* iTooltip;
377 * Stores the text for tooltip
383 * Stores the delay in milliseconds when the tooltip is shown
386 TInt iTooltipWaitInterval;
389 * Stores the time interval in milliseconds how long the tooltip is shown
392 TInt iTooltipInViewInterval;
395 * Stores the tool tip positioning
398 TTooltipPosition iTooltipPosition;
403 #endif // AKNCHOICELIST_H