2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * Represents a combo box type control, used to implement the Series 60
22 #ifndef AKNPOPUPFIELD_H
23 #define AKNPOPUPFIELD_H
31 #include <AknDesCArrayDecorator.h>
32 #include <AknListBoxLayoutDecorator.h>
33 #include <aknnotedialog.h>
35 class TResourceReader;
37 class CEikCommandButton;
38 class CAknFormGraphicStyleListBox;
42 class CAknPopupFieldExtension;
45 * this interface should be implemented by classes that need to know
46 * about events occurring in the popup field control
48 class MAknPopupFieldObserver
51 enum TAknPopupFieldEvent
53 EAknPopupFieldEventModeChange,
54 EAknPopupFieldEventValueChange
58 * Handles events from the popup field control, such as changes between
59 * selection list mode and label mode.
61 * @param aPopupField pointer to the popup field control that generated
63 * @param aEventType the type of event.
64 * @param aHint for possible future use.
66 virtual void HandlePopupFieldEventL(CAknPopupField* aPopupField,
67 TAknPopupFieldEvent aEventType,
72 * Represents a combo box type control, used to implement the Series 60
75 class CAknPopupField :
76 public CEikBorderedControl,
77 public MCoeControlObserver,
78 public MEikCommandObserver,
79 public MEikListBoxObserver
83 * Specialises bitmap button to make the layout correct for popup field
85 class CAknPopupFieldBitmapButton : public CEikBitmapButton
91 CAknPopupFieldBitmapButton();
95 * Selection mode of the popup field.
97 enum EAknPopupFieldSelectionMode
100 * Label mode. In Label mode popup field is minimized and popup field
101 * looks identical to a list item. When it receives the selection key
102 * press it is changed to @c EAknPopupFieldSelectionListMode and the
103 * pre-defined list is displayed.
105 EAknPopupFieldLabelMode,
108 * Selection list mode. In this selection mode pre-defined popup
109 * selection list is displayed.
111 EAknPopupFieldSelectionListMode
115 * Form mode for the popup field.
122 /** Editable mode. */
125 /** View mode with graphic. */
126 EAknFormModeViewWideWithGraphic,
128 /** View mode without graphic. */
129 EAknFormModeViewWideWithoutGraphic,
131 /** Edit mode with graphic. */
132 EAknFormModeEditWideWithGraphic,
134 /** Edit mode without graphic. */
135 EAknFormModeEditWideWithoutGraphic
138 EAknPopupFieldSelectionMode SelectionMode() const { return iSelectionMode; }
139 EAknFormMode FormMode() const { return iFormMode; }
141 * C++ default constructor.
143 IMPORT_C CAknPopupField();
148 IMPORT_C ~CAknPopupField();
151 * Handles 2nd phase construction.
153 IMPORT_C void ConstructL();
156 * Sets a flag that enables user defined entry. Note that flag can also be
157 * set from resources, but this method allows behaviour to be changed at
160 * @param aAllows if @c ETrue sets a flag.
162 IMPORT_C void SetAllowsUserDefinedEntry(TBool aAllows);
165 * Causes a list of pre-defined values to appear.
166 * Use this method to activate the pop-up field from a menu option command.
167 * Note that the desired control must be focused on before it can be
170 IMPORT_C void ActivateSelectionListL();
173 * Used by the client to set the query value. It is used to represent the
174 * user defined query value in this popup field control.
176 * @param aValue Pointer to query value, ownership is not passed.
178 IMPORT_C void SetQueryValueL(MAknQueryValue* aValue);
181 * Sets the font of the contained label.
183 * @param aFont Font definition used to set the font of the contained
186 IMPORT_C void SetFont(const CFont* aFont);
189 * Sets a flag that determines whether the indicators are shown.
190 * In practice the indicators have the appearance of radio buttons.
192 * @param aShowIndicators If @c ETrue, indicators are displayed.
194 IMPORT_C void SetShowIndicatorsL(TBool aShowIndicators);
197 * Number of lines used.
199 * @return Number of entries on the selection list. If selection list
200 * is not active, 1 is returned.
201 * NOTE that the number is limited by @c KAknMaxEditorLines.
203 IMPORT_C TInt NumLines() const;
206 * Sets an observer of this class to receive events from popup field.
208 * @param aObserver Pointer to the class that implements the observer
211 IMPORT_C void SetPopupFieldObserver(MAknPopupFieldObserver* aObserver);
214 * Sets the note to be displayed when the selection list has no items
217 * @param aResourceId Resource id for the note.
218 * @param aTimeout = CAknNoteDialog::EShortTimeout Timeout for the note.
219 * @param aTone = CAknNoteDialog::ENoTone Tone for the note.
221 IMPORT_C void SetEmptyListNoteL(TInt aResourceId,
222 CAknNoteDialog::TTimeout aTimeout = CAknNoteDialog::EShortTimeout,
223 CAknNoteDialog::TTone aTone = CAknNoteDialog::ENoTone);
226 * Sets the empty list note text. This note is displayed when the
227 * selection list has no items available.
229 * @param aEmptyText The empty list note text.
231 IMPORT_C void SetEmptyTextL(const TDesC& aEmptyText);
234 * Sets the text to be added to the bottom of the array to enter user
237 * @param aOtherText Text to the bottom of the selection array.
239 IMPORT_C void SetOtherTextL(const TDesC& aOtherText);
242 * Sets the text for view state when none of the elements in the
243 * list are available.
245 * @param aInvalidText The invalid text.
247 IMPORT_C void SetInvalidTextL(const TDesC &aInvalidText);
250 public: // from CCoeControl
253 * From @c CCoeControl.
255 * Handles key events.
257 * @param aKeyEvent The key event.
258 * @param aType The type of key event.
259 * @return Indicates whether or not the key event was used by this control.
261 IMPORT_C TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);
264 * From @c CCoeControl.
266 * Constructs the control from a resource file.
268 * @param aReader The resource reader pointing to the popup field resource.
270 IMPORT_C void ConstructFromResourceL(TResourceReader& aReader);
273 * From @c CCoeControl.
275 * Determines the minimum size of the control.
277 * @return The minimum size required by the control.
279 IMPORT_C TSize MinimumSize();
282 * From @c CCoeControl.
284 * Handles a change to the control's resources.
286 * @param aType The type of the resource change.
288 IMPORT_C void HandleResourceChange(TInt aType);
291 * From @c CCoeControl.
293 * Handles pointer events of popup field list.
295 * @param aPointerEvent The pointer event to be handled.
297 IMPORT_C void HandlePointerEventL(const TPointerEvent& aPointerEvent);
301 * Sets the maximium number of lines that can be displayed.
303 * @param aMaxNoLines The maximum number of lines.
305 IMPORT_C void SetMaxNumberOfLinesPermitted(TInt aMaxNoLines);
309 * Sets a form field rectangle so that a popup field can correctly position
312 * @param aFormFieldRect The form field rectangle.
314 IMPORT_C void SetFormFieldRect(TRect aFormFieldRect);
316 protected: // from MCoeControlObserver
319 * From @c MCoeControlObserver.
321 * Handles an event from an observed control.
323 * @param aControl The control that sent the event.
324 * @param aEvent The event type.
326 IMPORT_C void HandleControlEventL(CCoeControl* aControl,TCoeEvent aEvent);
327 protected: // from MEikCommandObserver
330 * From @c MEikCommandObserver.
332 * Processes events from the softkeys. Responds to @c EAknSoftkeyOk and
333 * @c EAknSoftkeyCancel to accept or cancel the pop-up.
335 * @param aCommandId Event Id from the soft-key.
337 IMPORT_C void ProcessCommandL(TInt aCommandId);
338 protected: // From MEikListBoxObserver
341 * From @c MEikListBoxObserver.
343 * Processes key events from the listbox. Responds to
344 * @c EEventEnterKeyPressed to accept the pop-up.
346 * @param aListBox Listbox being observed.
347 * @param aEventType Event observed.
349 IMPORT_C void HandleListBoxEventL(CEikListBox* aListBox,
350 TListBoxEvent aEventType);
351 protected: // from CCoeControl
354 * From @c CCoeControl.
356 * Gets the number of controls contained in a compound control.
358 * @return The number of component controls contained by this control.
360 IMPORT_C TInt CountComponentControls() const;
363 * From @c CCoeControl.
365 * Gets an indexed component of a compound control.
367 * @param aIndex Control index.
368 * @return The component control with an index of @c aIndex.
370 IMPORT_C CCoeControl* ComponentControl(TInt aIndex) const;
373 * From @c CCoeControl.
375 * Responds to changes to the size and position of the contents of this
378 IMPORT_C void SizeChanged();
381 * From @c CCoeControl.
383 * Responds to a change in focus.
385 * @param aDrawNow Contains the value that was passed to it by
388 IMPORT_C void FocusChanged( TDrawNow aDrawNow );
391 * From @c CEikBorderedControl.
393 * Called by the framework to draw the control.
395 * @param aRect Rectangle in which the Cone framework believes drawing is
398 IMPORT_C void Draw(const TRect& aRect) const;
400 private: // from CCoeControl
401 IMPORT_C void Reserved_1();
402 IMPORT_C void Reserved_2();
408 IMPORT_C void* ExtensionInterface( TUid aInterface );
410 protected: // personal
413 * Construction tasks common to both a normal construction and a construction
414 * from a resource. Used from @c ConstructL() and
415 * @c ConstructFromResourceL().
417 void CommonConstructL();
418 protected: // from MObjectProvider
421 * From @c CCoeControl.
423 * Retrieves an object of the same type as that encapsulated in @c aId.
425 * @param aId An encapsulated object type ID.
426 * @return Encapsulates the pointer to the object provided.
427 * Note that the encapsulated pointer may be NULL.
429 IMPORT_C TTypeUid::Ptr MopSupplyObject(TTypeUid aId);
433 * Create the label that will show the currently selected value.
436 void ConstructLabelL();
439 * Create the command button that will be used to show the other choices indicator.
442 void ConstructCommandButtonL();
445 * Create the selection list box that will fill the expanded popup field
448 void ConstructSelectionListL();
451 * setup the scroll bar within the selection list box
454 void SetUpScrollBarL();
457 * set the scroll bar selection
460 void SetScrollBarSelectionL();
463 * Set up the bitmap array for the "not pushed" and "pushed in" states
466 void InitialiseRadioButtonBitmapsL();
469 * Handles the case where the selection list is closed. If necessary,
470 * update the value of the text label that is displayed.
472 * @return TBool ETrue always
474 TBool HandleInteractionConfirmedL();
477 * Create the popup list. Warn the user if there are no entries in the list.
480 void CreatePopoutL();
483 * Destroy the popup list and remove it from the stack
486 void DestroyPopout();
489 * Checks to see if the popupfield is empty
492 TBool IsEmpty() const;
494 * Checks to see if the popupfield is invalid
497 TBool IsInvalid() const;
499 * Handles a horizontal key event
501 * @return TKeyResponse returns either EKeyWasConsumed
502 * or EKeyWasNotConsumed
504 TKeyResponse HandleHorizontalKeyEventL(TUint aKeyEventCode);
508 * Creates the CBA for use when the selection list is active
513 * Configures the decoration according to the currently set flags.
514 * Should be called whenever the flags are changed.
517 void ConfigureDecorator();
520 * Configures the layout decoration according to the radio button flag
521 * Should be called whenever the flags are changed.
524 void ConstructLayoutDecoratorL();
527 * display a note when the selection list has no items available
530 void ShowEmptyListNoteL();
533 * Re-defined method of the base class. Gets called when the
534 * user tries to select a value. If required, an editor is created to
535 * allow the user to input the user defined value. Otherwise, the
536 * normal selection behaviour of popup list is activated.
538 * @param aAccept If ETrue, popup list was accepted;
539 * if EFalse, popup list was cancelled
542 void AttemptExitL(TBool aAccept);
545 * Changes the mode of the popupfield to one of
546 * the EAknPopupFieldSelectionMode's
548 void ChangeMode(EAknPopupFieldSelectionMode aNewMode);
551 static TInt AttemptExitCallbackL(TAny* aThis);
552 void DoAttemptExitL();
553 void DoSizeChangedL();
555 // the following members are owned
557 * Label of the popup field.
563 * Bitmap button for the popup field.
566 CAknPopupFieldBitmapButton* iButton;
569 * List box for the popup field usage.
572 CAknFormGraphicStyleListBox* iSelectionList;
575 * Contains a popup field selection array and a leading text that will be
576 * inserted before the text from the descriptor array entry.
579 CAknListBoxLayoutDecorator* iLayoutDecorator;
582 * Button group container for the popup field.
585 CEikButtonGroupContainer* iCba;
588 * Active object for calling @c AttemptExitCallbackL asynchronously.
591 CAsyncCallBack* iAttemptExitAsync;
593 // the following fields are reflected in the POPUP_FIELD resource structure
595 * Flags for the popup field.
600 * Maximum line width.
605 * Text to the bottom of the selection array.
611 * The empty list note text.
617 * The invalid text. Used in the view state when none of the elements in the
618 * list are available.
624 * Resource id for the empty note.
626 TInt iEmptyNoteResourceId;
628 // the following members are not owned
630 * Query value for the popup field.
633 MAknQueryValue* iValue;
636 * Observer for receiving events from the popup field.
639 MAknPopupFieldObserver* iObserver;
641 // the following values are member variables
643 * Enumeration representing form mode values.
645 EAknFormMode iFormMode;
648 * Timeout for the empty tone.
650 CAknNoteDialog::TTimeout iEmptyNoteTimeout;
653 * Tone for the empty note.
655 CAknNoteDialog::TTone iEmptyNoteTone;
658 * Selection array for the popup field.
660 TAknDesCArrayDecorator iDecorator;
663 * Enumeration representing selection mode values.
665 EAknPopupFieldSelectionMode iSelectionMode;
668 * Maximum number of items in selection array.
671 // NOTE: use Extension() to extend this class.
673 CAknPopupFieldExtension* iExtension;
677 #endif // AKNPOPUPFIELD_H