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 "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.
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 * Closes the selection list
254 IMPORT_C void CloseSelectionListL();
256 public: // from CCoeControl
259 * From @c CCoeControl.
261 * Handles key events.
263 * @param aKeyEvent The key event.
264 * @param aType The type of key event.
265 * @return Indicates whether or not the key event was used by this control.
267 IMPORT_C TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);
270 * From @c CCoeControl.
272 * Constructs the control from a resource file.
274 * @param aReader The resource reader pointing to the popup field resource.
276 IMPORT_C void ConstructFromResourceL(TResourceReader& aReader);
279 * From @c CCoeControl.
281 * Determines the minimum size of the control.
283 * @return The minimum size required by the control.
285 IMPORT_C TSize MinimumSize();
288 * From @c CCoeControl.
290 * Handles a change to the control's resources.
292 * @param aType The type of the resource change.
294 IMPORT_C void HandleResourceChange(TInt aType);
297 * From @c CCoeControl.
299 * Handles pointer events of popup field list.
301 * @param aPointerEvent The pointer event to be handled.
303 IMPORT_C void HandlePointerEventL(const TPointerEvent& aPointerEvent);
307 * Sets the maximium number of lines that can be displayed.
309 * @param aMaxNoLines The maximum number of lines.
311 IMPORT_C void SetMaxNumberOfLinesPermitted(TInt aMaxNoLines);
315 * Sets a form field rectangle so that a popup field can correctly position
318 * @param aFormFieldRect The form field rectangle.
320 IMPORT_C void SetFormFieldRect(TRect aFormFieldRect);
322 protected: // from MCoeControlObserver
325 * From @c MCoeControlObserver.
327 * Handles an event from an observed control.
329 * @param aControl The control that sent the event.
330 * @param aEvent The event type.
332 IMPORT_C void HandleControlEventL(CCoeControl* aControl,TCoeEvent aEvent);
333 protected: // from MEikCommandObserver
336 * From @c MEikCommandObserver.
338 * Processes events from the softkeys. Responds to @c EAknSoftkeyOk and
339 * @c EAknSoftkeyCancel to accept or cancel the pop-up.
341 * @param aCommandId Event Id from the soft-key.
343 IMPORT_C void ProcessCommandL(TInt aCommandId);
344 protected: // From MEikListBoxObserver
347 * From @c MEikListBoxObserver.
349 * Processes key events from the listbox. Responds to
350 * @c EEventEnterKeyPressed to accept the pop-up.
352 * @param aListBox Listbox being observed.
353 * @param aEventType Event observed.
355 IMPORT_C void HandleListBoxEventL(CEikListBox* aListBox,
356 TListBoxEvent aEventType);
357 protected: // from CCoeControl
360 * From @c CCoeControl.
362 * Gets the number of controls contained in a compound control.
364 * @return The number of component controls contained by this control.
366 IMPORT_C TInt CountComponentControls() const;
369 * From @c CCoeControl.
371 * Gets an indexed component of a compound control.
373 * @param aIndex Control index.
374 * @return The component control with an index of @c aIndex.
376 IMPORT_C CCoeControl* ComponentControl(TInt aIndex) const;
379 * From @c CCoeControl.
381 * Responds to changes to the size and position of the contents of this
384 IMPORT_C void SizeChanged();
387 * From @c CCoeControl.
389 * Responds to a change in focus.
391 * @param aDrawNow Contains the value that was passed to it by
394 IMPORT_C void FocusChanged( TDrawNow aDrawNow );
397 * From @c CEikBorderedControl.
399 * Called by the framework to draw the control.
401 * @param aRect Rectangle in which the Cone framework believes drawing is
404 IMPORT_C void Draw(const TRect& aRect) const;
406 private: // from CCoeControl
407 IMPORT_C void Reserved_1();
408 IMPORT_C void Reserved_2();
414 IMPORT_C void* ExtensionInterface( TUid aInterface );
416 protected: // personal
419 * Construction tasks common to both a normal construction and a construction
420 * from a resource. Used from @c ConstructL() and
421 * @c ConstructFromResourceL().
423 void CommonConstructL();
424 protected: // from MObjectProvider
427 * From @c CCoeControl.
429 * Retrieves an object of the same type as that encapsulated in @c aId.
431 * @param aId An encapsulated object type ID.
432 * @return Encapsulates the pointer to the object provided.
433 * Note that the encapsulated pointer may be NULL.
435 IMPORT_C TTypeUid::Ptr MopSupplyObject(TTypeUid aId);
439 * Create the label that will show the currently selected value.
442 void ConstructLabelL();
445 * Create the command button that will be used to show the other choices indicator.
448 void ConstructCommandButtonL();
451 * Create the selection list box that will fill the expanded popup field
454 void ConstructSelectionListL();
457 * setup the scroll bar within the selection list box
460 void SetUpScrollBarL();
463 * set the scroll bar selection
466 void SetScrollBarSelectionL();
469 * Set up the bitmap array for the "not pushed" and "pushed in" states
472 void InitialiseRadioButtonBitmapsL();
475 * Handles the case where the selection list is closed. If necessary,
476 * update the value of the text label that is displayed.
478 * @return TBool ETrue always
480 TBool HandleInteractionConfirmedL();
483 * Create the popup list. Warn the user if there are no entries in the list.
486 void CreatePopoutL();
489 * Destroy the popup list and remove it from the stack
492 void DestroyPopout();
495 * Checks to see if the popupfield is empty
498 TBool IsEmpty() const;
500 * Checks to see if the popupfield is invalid
503 TBool IsInvalid() const;
505 * Handles a horizontal key event
507 * @return TKeyResponse returns either EKeyWasConsumed
508 * or EKeyWasNotConsumed
510 TKeyResponse HandleHorizontalKeyEventL(TUint aKeyEventCode);
514 * Creates the CBA for use when the selection list is active
519 * Configures the decoration according to the currently set flags.
520 * Should be called whenever the flags are changed.
523 void ConfigureDecorator();
526 * Configures the layout decoration according to the radio button flag
527 * Should be called whenever the flags are changed.
530 void ConstructLayoutDecoratorL();
533 * display a note when the selection list has no items available
536 void ShowEmptyListNoteL();
539 * Re-defined method of the base class. Gets called when the
540 * user tries to select a value. If required, an editor is created to
541 * allow the user to input the user defined value. Otherwise, the
542 * normal selection behaviour of popup list is activated.
544 * @param aAccept If ETrue, popup list was accepted;
545 * if EFalse, popup list was cancelled
548 void AttemptExitL(TBool aAccept);
551 * Changes the mode of the popupfield to one of
552 * the EAknPopupFieldSelectionMode's
554 void ChangeMode(EAknPopupFieldSelectionMode aNewMode);
557 static TInt AttemptExitCallbackL(TAny* aThis);
558 void DoAttemptExitL();
559 void DoSizeChangedL();
561 // the following members are owned
563 * Label of the popup field.
569 * Bitmap button for the popup field.
572 CAknPopupFieldBitmapButton* iButton;
575 * List box for the popup field usage.
578 CAknFormGraphicStyleListBox* iSelectionList;
581 * Contains a popup field selection array and a leading text that will be
582 * inserted before the text from the descriptor array entry.
585 CAknListBoxLayoutDecorator* iLayoutDecorator;
588 * Button group container for the popup field.
591 CEikButtonGroupContainer* iCba;
594 * Active object for calling @c AttemptExitCallbackL asynchronously.
597 CAsyncCallBack* iAttemptExitAsync;
599 // the following fields are reflected in the POPUP_FIELD resource structure
601 * Flags for the popup field.
606 * Maximum line width.
611 * Text to the bottom of the selection array.
617 * The empty list note text.
623 * The invalid text. Used in the view state when none of the elements in the
624 * list are available.
630 * Resource id for the empty note.
632 TInt iEmptyNoteResourceId;
634 // the following members are not owned
636 * Query value for the popup field.
639 MAknQueryValue* iValue;
642 * Observer for receiving events from the popup field.
645 MAknPopupFieldObserver* iObserver;
647 // the following values are member variables
649 * Enumeration representing form mode values.
651 EAknFormMode iFormMode;
654 * Timeout for the empty tone.
656 CAknNoteDialog::TTimeout iEmptyNoteTimeout;
659 * Tone for the empty note.
661 CAknNoteDialog::TTone iEmptyNoteTone;
664 * Selection array for the popup field.
666 TAknDesCArrayDecorator iDecorator;
669 * Enumeration representing selection mode values.
671 EAknPopupFieldSelectionMode iSelectionMode;
674 * Maximum number of items in selection array.
677 // NOTE: use Extension() to extend this class.
679 CAknPopupFieldExtension* iExtension;
683 #endif // AKNPOPUPFIELD_H