2 * Copyright (c) 1997-2009 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.
14 * Description: Base class for an on-screen list box control from
15 * which one or more items can be selected.
34 // FORWARD DECLARATIONS
36 class RIncrMatcherBase;
37 class CListItemDrawer;
38 class CEikScrollBarFrame;
47 * Item change observer will be notified when list box items have been added or
48 * removed or the list box has been reset. Observers can be added and removed by
49 * using @c CEikListBox methods @c AddItemChangeObserverL() and
50 * @c RemoveItemChangeObserver().
54 class MListBoxItemChangeObserver
58 * Notification and handling of a list box item change.
60 * @param aListBox The source list box of this message.
62 virtual void ListBoxItemsChanged(CEikListBox* aListBox) = 0;
67 * Item selection (marking) observer is used to let application control item marking
68 * (in markable lists). Observers can be added and removed by using
69 * @c CEikListBox methods @c AddSelectionObserverL() and
70 * @c RemoveSelectionObserver().
74 class MListBoxSelectionObserver
78 * Notification of entering and leaving marking mode. Marking mode
79 * is enabled by long pressing shift, ctrl or hash keys (when hash key marking is enabled).
81 * @param aListBox The source list box of this message.
82 * @param aSelectionModeEnabled ETrue, when entering selection (marking) mode.
84 virtual void SelectionModeChanged(CEikListBox* aListBox, TBool aSelectionModeEnabled) = 0;
91 * Base class for an on-screen list box control from which one or more items
94 * @c CEikListBox implements the basics of a list box. It has a scroll bar
95 * frame, an item drawer, and a model, and reports events to a list box
98 * List boxes display a number of items within a scrolling frame; the items
99 * in a list box which are visible at one time are represented by a list
102 * Writing derived classes:
104 * This class may be derived from to provide specialisations of the basic
105 * list box behaviour. It is usual when subclassing CEikListBox to also
106 * provide specialisations of CListItemDrawer and CListBoxView for
107 * representing the data of such a list box effectively
109 class CEikListBox : public CEikBorderedControl, public MEikScrollBarObserver
114 friend class CListBoxExt;
119 * Construction flags.
125 * Construction flag for a list box from which the user can
126 * select multiple items.
128 EMultipleSelection = SLafListBox::EMultipleSelection,
131 * Construction flag for disabling extended selection.
132 * If this is set the user cannot select multiple items by
133 * using @c SHIFT button.
135 ENoExtendedSelection = SLafListBox::ENoExtendedSelection,
138 * Construction flag that sets the list box to match user’s keystrokes
141 EIncrementalMatching = SLafListBox::EIncrementalMatching,
144 * Construction flag for setting the list box as a pop-out list box.
145 * Pop-out list boxes handle certain keystrokes and events differently.
147 EPopout = SLafListBox::EPopout,
150 * Construction flag that enables the indication of pointer press
151 * inside the view of the list box.
153 ELeftDownInViewRect = SLafListBox::ELeftDownInViewRect,
156 * Construction flag for enabling @c CEiklist box item double click
159 EItemDoubleClicked = SLafListBox::EItemDoubleClicked,
162 * Construction flag for removing the ownership of the supplied list box
163 * model from the @c CEikListBox so that the list box model will not be
164 * deleted with the @c CEikListBoxes destruction.
166 EKeepModel = SLafListBox::EKeepModel,
169 * Construction flag for excluding the scroll bar.
170 * If the flag is set the scroll bas is drawn ouside the window that
171 * describes the scroll bars extent.
173 EScrollBarSizeExcluded = SLafListBox::EScrollBarSizeExcluded,
176 * Construction flag for enabling @c CEikListBox change indication.
178 EStateChanged = SLafListBox::EStateChanged,
181 * Construction flag that indicates that the list box should be created
184 ECreateOwnWindow = SLafListBox::ECreateOwnWindow,
187 * Construction flag for disabling key matching.
189 ENoFirstLetterMatching = SLafListBox::ENoFirstLetterMatching,
192 * Construction flag for enabling painting of selected items.
194 EPaintedSelection = SLafListBox::EPaintedSelection ,
197 * Construction flag for enabling loop scrolling in which the list box
198 * jumps from the last item to the first item.
200 ELoopScrolling = 0x1000,
203 * Construction flag for enabling @c Avkon multiselection list.
205 EEnterMarks = 0x2000, // Avkon multiselection list
208 * Construction flag for enabling Avkon markable list which enables the
209 * marking of several items from the list.
211 EShiftEnterMarks = 0x4000, // Avkon markable list
214 * Construction flag that combines @c EPageAtOnceScrolling and
215 * @c EDisableHighlight flags
217 EViewerFlag = 0x8000, // combined the two flags to fit to WORD.
220 * Construction flag for enabling scrolling at a page per time so that
221 * the whole list box page is scrolled to the next.
223 EPageAtOnceScrolling = 0x8000, // Avkon viewers
226 * Construction flag for disabling the highlighting of the selected item.
228 EDisableHighlight = 0x8000, // Avkon viewers
231 * Construction flag for enabling S60 style selection of multiple items
234 ES60StyleMultiselection = SLafListBox::ES60StyleMultiselection,
237 * Construction flag for enabling S60 style markable items.
239 ES60StyleMarkable = SLafListBox::ES60StyleMarkable
241 enum {KEikMaxMatchingBufferLength = 2};
244 * Indicates who owns the scroll bar.
246 enum TScrollBarOwnerShip
249 * Indicates that the scrollbar is not owned by an external class.
251 ENotOwnedExternally=0x0000,
253 * Indicates that the scrollbar is owned by an external class.
255 EOwnedExternally =0x0001
261 * Used for indicating the reason why the item lost focus.
263 enum TReasonForFocusLost
266 * Focus has been lost from the list box to an external control.
268 EFocusLostToExternalControl,
270 * Focus has been moved from the list box to an internal editor.
272 EFocusLostToInternalEditor
279 IMPORT_C ~CEikListBox();
282 * C++ default constructor.
284 IMPORT_C CEikListBox();
286 * Handles 2nd phase construction.
288 * Sets list box model and list item drawer. Request another @c ConstructL
289 * to handle @c aParent and @c aFlags.
291 * @param aListBoxModel List box model that is to be used with the list box.
292 * @param aListItemDrawer List item drawer that is to be used with the
294 * @param aParent Host @c CoeControl for the list box.
295 * @param aFlags Construction flags (@c TFlags) for the list box.
297 IMPORT_C void ConstructL(MListBoxModel* aListBoxModel,
298 CListItemDrawer* aListItemDrawer,
299 const CCoeControl* aParent,
303 * Handles 2nd phase construction.
306 * Sets the border that is to be drawn outside the list box. Request another
307 * @c ConstructL to handle list box model, list item drawer, @c aParent
310 * @param aListBoxModel List box model that is to be used with the list box.
311 * @param aListItemDrawer List item drawer that is to be used with the
313 * @param aParent Host @c CoeControl for the list box.
314 * @param aBorder Border to be drawn outside the list box.
315 * @param aFlags Construction flags (@c TFlags) for the list box.
317 IMPORT_C void ConstructL(MListBoxModel* aListBoxModel,
318 CListItemDrawer* aListItemDrawer,
319 const CCoeControl* aParent,
323 * Informs the @c CEikListbox of a key press.
325 * @param aKeyEvent Details of the key event that is being handled.
326 * @param aType Defines what kind of key event is being handled e.g.
328 * @return @c EKeyWasConsumed if the key was handled by the method.
329 * @c EKeyWasNotConsumed if the key was not handled.
331 IMPORT_C virtual TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,
335 * Handling of pointer event within the @c CEikListBox.
336 * Used for e.g. selecting an item from the list box.
338 * @param aPointerEvent Details of the pointer event that is being handled.
340 IMPORT_C virtual void HandlePointerEventL(
341 const TPointerEvent& aPointerEvent);
344 * Creates an own window for the list box or draws the list box to an old
345 * window defined by the @c aContainer.
347 * @param aContainer Defines the container where the list box will be drawn.
349 IMPORT_C virtual void SetContainerWindowL(const CCoeControl& aContainer);
352 * Checks the minimum size needed for the list box.
354 * @return The two dimensional minimum size for the list box.
356 IMPORT_C virtual TSize MinimumSize();
359 * This function sets a flag within the control which indicates
360 * whether or not the control is dimmed (greyed out).
362 * @param aDimmed @c ETrue dimmed. @c EFalse not dimmed.
364 IMPORT_C virtual void SetDimmed(TBool aDimmed);
367 * Used for scrolling through the items in the list box.
369 * @param aScrollBar Scroll bar for the list box.
370 * @param aEventType Type of the event that occured.
372 IMPORT_C virtual void HandleScrollEventL(CEikScrollBar* aScrollBar,
373 TEikScrollEvent aEventType);
375 // model/view access functions
377 * Gets the list box data model.
379 * @return Interface to the list box data model.
381 IMPORT_C MListBoxModel* Model() const;
384 * Gets the list box view.
386 * @return Interface to the list box view.
388 IMPORT_C CListBoxView* View() const;
390 // functions for accessing top/current/bottom item index
392 * Gets the index number of the top item.
394 * @return Index number for the top item.
396 IMPORT_C TInt TopItemIndex() const;
399 * Sets the selected item to be the top item.
401 * @param aItemIndex Index for the item to be set as the top item.
403 IMPORT_C virtual void SetTopItemIndex(TInt aItemIndex) const;
406 * Gets for the bottom items index.
408 * @return Index for the bottom item.
410 IMPORT_C TInt BottomItemIndex() const;
413 * Gets the index number of the selected item.
415 * @return Index of the selected item.
417 IMPORT_C TInt CurrentItemIndex() const;
420 * Changes the current item index to the selected item index. Does not
421 * redraw the list. If the item was not previously visible it is set to the
422 * top item in the view.
424 * @param aItemIndex Defines the index of the selected item.
426 IMPORT_C void SetCurrentItemIndex(TInt aItemIndex) const;
429 * Changes the current item index to the selected item index and
432 * @param aItemIndex Defines the index of the selected item.
434 IMPORT_C void SetCurrentItemIndexAndDraw(TInt aItemIndex) const;
436 // functions for dealing with the selection state
438 * Gets for list boxes selection indexes.
440 * @return Pointer to the list boxes in array of selection indexes.
442 IMPORT_C const CListBoxView::CSelectionIndexArray* SelectionIndexes() const;
445 * Assigns a array of selection indexes for the list box.
447 * @param aArrayOfSelectionIndexes The index array that is to be assigned
450 IMPORT_C void SetSelectionIndexesL(
451 CListBoxView::CSelectionIndexArray* aArrayOfSelectionIndexes);
454 * Clears the selection from the view.
456 IMPORT_C void ClearSelection();
458 // Functions for updating a list box's internal state after its model has
459 // been updated, all of them will emit item change event to item change
462 * Handles the addition of item to the list box.
464 IMPORT_C void HandleItemAdditionL();
467 * Handles the removal of an item from the list box.
469 IMPORT_C void HandleItemRemovalL();
472 * Handles the addition of new items to the list box and updates
473 * selection indexes array.
475 * NOTE. This algorithm can not handle position of the list highlight
476 * nor can it update the top item index correctly.
478 * @param aArrayOfNewIndexesAfterAddition Array of new indexes to be added.
480 IMPORT_C void HandleItemAdditionL(
481 CArrayFix<TInt> &aArrayOfNewIndexesAfterAddition);
484 * Handles the removal of items to the list box and updates
485 * selection indexes array.
487 * NOTE. This algorithm cannot handle position of the list highlight
488 * nor can it update the top item index correctly.
490 * @param aArrayOfOldIndexesBeforeRemoval Array of indexes to be removed.
492 IMPORT_C void HandleItemRemovalL(
493 CArrayFix<TInt> &aArrayOfOldIndexesBeforeRemoval);
496 * Deletes the item editor
498 IMPORT_C void Reset();
501 * Adds an item change observer to the listbox. Duplicates are not checked
502 * (i.e. adding the same observer multiple times is not prevented).
505 * @param aObserver Must be non-NULL.
507 IMPORT_C void AddItemChangeObserverL( MListBoxItemChangeObserver* aObserver );
509 * Removes an item change observer from the listbox.
512 * @param aObserver The observer to be removed.
513 * @return ETrue if removal ok, EFalse if observer was not removed (not
514 * found from the list of observers).
516 IMPORT_C TBool RemoveItemChangeObserver( MListBoxItemChangeObserver* aObserver );
518 // functions for accessing the item height
520 * Sets the height of the item to the selected value.
522 * @param aHeight New height for the item.
524 IMPORT_C virtual void SetItemHeightL(TInt aHeight);
527 * Gets height of the item.
529 * @return Height of the item.
531 IMPORT_C TInt ItemHeight() const;
533 // functions for scrollbars
535 * Creates a scrollbar frame.
537 * @param aPreAlloc Boolean defining if there should be initial
538 * memory allocations.
539 * @return The new scroll bar frame.
541 IMPORT_C CEikScrollBarFrame* CreateScrollBarFrameL(TBool aPreAlloc=EFalse);
544 * Sets the given scroll bar frame for the list box with the given
547 * @param aScrollBarFrame The new frame that is going to be used.
548 * @param aOwnerShip Ownership level of the scroll bar frame.
550 IMPORT_C void SetScrollBarFrame(CEikScrollBarFrame* aScrollBarFrame, TScrollBarOwnerShip aOwnerShip);
553 * Gets pointer for the scroll bar frame.
555 * @return Pointer to the scroll bar frame.
557 IMPORT_C CEikScrollBarFrame* const ScrollBarFrame();
560 * Updates all scroll bars.
562 IMPORT_C virtual void UpdateScrollBarsL();
564 // construction support functions
566 * Gets the size of the rectangle required to display a pop out.
568 * @param aTargetItemIndex The item from which the popout originates.
569 * @param aTargetYPos Vertical position of the item from which the popout
571 * @param aListBoxRect The list box rectangle.
572 * @param aMinHeightInNumOfItems The minimum number of items for the popout.
574 IMPORT_C void CalculatePopoutRect( TInt aTargetItemIndex,
577 TInt aMinHeightInNumOfItems = 1 );
579 * Gets the size of the list box in pixels based on the height of
580 * the list box in items and the length of the items in characters.
582 * Returns @c TSize element consisting of two elements, the height
583 * and the width. Height is the number of items times the height
584 * of the font in pixels. Width is the number of characters in a
585 * single line times the width of the font in pixels.
587 * @param aWidthAsNumOfChars Width of list box in characters.
588 * @param aHeightAsNumOfItems Height of list box in characters.
589 * @return The size of the list box in pixels as TSize.
591 IMPORT_C TSize CalcSizeInPixels(TInt aWidthAsNumOfChars,
592 TInt aHeightAsNumOfItems) const;
595 * Gets the width of the list box in pixels based on the width of the list
598 * Returns the number of characters times the width of a character
601 * @param aNumOfChars The number of characters.
602 * @return The width of the list box in pixels.
604 IMPORT_C TInt CalcWidthBasedOnNumOfChars(TInt aNumOfChars) const;
607 * Gets the height of the list box in pixels based on the width of the
608 * list box in characters.
610 * Returns the number of items times the height of the font in pixels.
612 * @param aNumOfItems The number of items.
613 * @return The height of the list box in pixels.
615 IMPORT_C TInt CalcHeightBasedOnNumOfItems(TInt aNumOfItems) const;
618 * Gets the width of the list box in pixels based on the width of the
619 * list box text in pixels.
621 * returns the width of the whole list box in pixels, which includes
622 * the text width and the width of elements in the list box that have
623 * an effect on the overall width.
625 * @param aTextWidthInPixels Width of list box text in pixels.
626 * @return Required width of whole list box in pixels.
628 IMPORT_C TInt CalcWidthBasedOnRequiredItemWidth(
629 TInt aTextWidthInPixels) const;
631 // drawing/scrolling functions
633 * Draws a list box item, first scrolling the list to make it visible
634 * if it is not already.
636 * @c DrawItem() panics if there is no list box view currently set.
637 * @param aItemIndex Index of the item to reveal.
639 IMPORT_C void DrawItem(TInt aItemIndex) const;
642 * Makes an item visible in the list, scrolling it if necessary.
644 * @param aItemIndex Index of the item to reveal.
646 IMPORT_C void ScrollToMakeItemVisible(TInt aItemIndex) const;
650 * @param aItemIndex index of item to be redrawn.
653 IMPORT_C void RedrawItem( TInt aItemIndex );
657 * Sets the observer for the list box.
659 * @param aObserver Wanted observer for the list box.
661 IMPORT_C void SetListBoxObserver(MEikListBoxObserver* aObserver);
665 * Gets the size of the vertical gap between items. This space is used
666 * by the view to allow a box to be drawn around each item.
668 * @return Size of the vertical gap in pixels.
670 IMPORT_C TInt VerticalInterItemGap() const;
674 * Provides a call back mechanism to the button which just launched a
677 * @param aButton The button which just launched a popout menu.
679 IMPORT_C void SetLaunchingButton(CEikButtonBase* aButton);
683 * Selects an item editor for the list box.
685 * @param aEditor The editor that has been selected for usage.
687 IMPORT_C void SetItemEditor(MEikListBoxEditor* aEditor);
690 * Resets the list boxes item editor.
692 IMPORT_C void ResetItemEditor();
694 * Gets item editor for the current class.
696 * @return The item editor used by the list box class.
698 IMPORT_C MEikListBoxEditor* ItemEditor();
701 * Creates an item editor and starts editing the current item.
703 * The editor can edit the current item up to a maximum length of
704 * @c aMaxLength characters. Also reports an @c EEventEditingStarted event
705 * to any list box observer by default.
707 * The function only creates a new editor if one does not already exist.
709 * @param aMaxLength Maximum length of characters to edit.
711 IMPORT_C virtual void EditItemL(TInt aMaxLength);
714 * Stops editing and deletes the item editor.
716 * The function reports an @c EEventEditingStopped event to any list box
717 * observer, and updates the list box model if @c aUpdateModel is @c ETrue.
719 * @param aUpdateModel If @c ETrue the list box model is updated.
721 IMPORT_C void StopEditingL(TBool aUpdateModel);
723 // functions needed for Avkon shortcuts,
724 // passing information from one list to another
729 * @return Always returns 0.
731 IMPORT_C virtual TInt ShortcutValueForNextList();
736 * @param aValue Not Used.
738 IMPORT_C virtual void SetShortcutValueFromPrevList(TInt aValue);
740 // pop-up positioning support
742 * Gets the position and the size of the list box.
744 * @return A rectangle with the correct position data as
745 * well as size data for the list box.
747 IMPORT_C TRect HighlightRect() const;
750 * Checks whether background drawing is suppressed on item level i.e. each
751 * list item doesn't draw its background.
754 * @return ETrue if background drawing is suppressed.
756 IMPORT_C TBool BackgroundDrawingSuppressed() const;
758 public: // from CCoeControl
761 * From @c CCoeControl
763 * Gets the list of logical colours employed in the drawing of the control,
764 * paired with an explanation of how they are used. Appends the list to
767 * @param aColorUseList List of logical colours.
769 IMPORT_C virtual void GetColorUseListL(
770 CArrayFix<TCoeColorUse>& aColorUseList) const;
771 // not available before Release 005u
774 * From @c CCoeControl
776 * Handles a change to the list box’s resources of type @c aType which are
777 * shared across the environment, colours or fonts for example.
779 * @param aType The type of resources that have changed.
781 IMPORT_C virtual void HandleResourceChange(TInt aType);
782 // not available before Release 005u
785 * From @c CCoeControl
787 * Sets the control as ready to be drawn.
789 * The application should call this function on all controls that are not
790 * components in a compound control.
792 * The purpose of this function is that controls are not always ready to
793 * be drawn as soon as they have been constructed. For example, it may
794 * not be possible to set the control's extent during construction, but
795 * its extent should always be set before it is drawn. Similarly, if a
796 * control is to be made invisible, this should be done before it is
799 * The default implementation sets a flag in the control to indicate it is
800 * ready to be drawn. If the control is a compound control, the default
801 * implementation also calls @c ActivateL() for all the control's components.
802 * To get the control's components it uses @c CountComponentControls() and
803 * @c ComponentControl(), which should be implemented by the compound control.
805 * @c ActivateL() is typically called from the control's @c ConstructL()
810 * This function can be overridden. This is useful for doing late
811 * initialisation of the control, using information that was not available
812 * at the time the control was created. For example, a text editor might
813 * override @c ActivateL() and use it to enquire whether it is focused: if
814 * it is, it makes the cursor and any highlighting visible. At the time when
815 * the editor is created, it doesn't know whether or not it has keyboard
818 * If overriding @c ActivateL(), the implementation must include a base
819 * call to @c CCoeControl's @c ActivateL().
821 IMPORT_C virtual void ActivateL();
824 * From @c CCoeControl.
826 * Gets the input capabilities of the control and all its components.
828 * @return The input capabilities of the control.
830 IMPORT_C TCoeInputCapabilities InputCapabilities() const;
836 IMPORT_C void* ExtensionInterface( TUid aInterface );
839 // Shortcuts need access to Incremental matching
840 // The shortcuts will be used inside OfferkeyEventL().
841 friend class AknListBoxShortCutsImplementation;
842 // Avkon layout uses SetVerticalMargin, which is protected.
843 friend class AknListBoxLayouts;
846 * Responds to a change in focus.
848 * This is called whenever the control gains or loses focus,
849 * as a result of a call to @c SetFocus(). A typical use of
850 * @c FocusChanged() is to change the appearance of the control,
851 * for example by drawing a focus rectangle around it.
853 * The default implementation is empty, and should be
854 * overridden by the @c CCoeControl-derived class.
856 * @param aDrawNow Contains the value that was passed to it
859 IMPORT_C virtual void FocusChanged(TDrawNow aDrawNow);
862 * Responds to changes to the size and position of the contents
865 * For a simple control this might include text or graphics.
866 * For a compound control it sets the size and position of the
867 * components. It has an empty default implementation and should
868 * be implemented by the CCoeControl-derived class.
870 * The function is called whenever @c SetExtent(), @c SetSize(),
871 * @c SetRect(), @c SetCornerAndSize(), or @c SetExtentToWholeScreen()
872 * are called on the control. Note that the window server does not
873 * generate size-changed events: @c SizeChanged() gets called only as
874 * a result of calling the functions listed above. Therefore, if a
875 * resize of one control affects the size of other controls, it is
876 * up to the application to ensure that it handles the re-sizing
877 * of all affected controls.
879 IMPORT_C virtual void SizeChanged();
882 * Handles the change in case that the size of the view rectangle
883 * for the list box changes.
885 IMPORT_C virtual void HandleViewRectSizeChangeL();
888 * Gets the number of controls contained in a compound control.
890 * There are two ways to implement a compound control. One way is to
891 * override this function. The other way is to use the @c CCoeControlArray
892 * functionality (see the @c InitComponentArrayL method).
894 * @return The number of component controls contained by this control.
896 IMPORT_C virtual TInt CountComponentControls() const;
899 * Gets an indexed component of a compound control.
901 * There are two ways to implement a compound control. One way is to
902 * override this function. The other way is to use the @c CCoeControlArray
903 * functionality (see the @c InitComponentArrayL method).
905 * Note: Within a compound control each component control is identified
906 * by an index, where the index depends on the order the controls were
907 * added: the first is given an index of 0, the next an index of 1, and
910 * @param aIndex The index of the control.
911 * @return The component control with an index of aIndex.
913 IMPORT_C virtual CCoeControl* ComponentControl(TInt aIndex) const;
915 // functions that implement first letter and incremental matching
917 * Creates a buffer for checking how well two strings match up.
919 IMPORT_C void CreateMatchBufferL();
922 * Empties the match buffer .
924 IMPORT_C void ClearMatchBuffer() const;
927 * Checks matching for the given character.
929 * @param aCode Character code.
931 IMPORT_C void MatchTypedCharL(TUint aCode);
934 * Undoes changes from the match buffer that have been caused
935 * by the last match with a character.
937 IMPORT_C void UndoLastChar();
939 * Checks if the last character matched with the string.
941 * @return @c ETrue if a match was found from the buffer with the character.
943 IMPORT_C TBool LastCharMatched() const;
945 // functions needed for supporting scrollbars
947 * Updates the position of this list box’s scroll bars’ thumbs to reflect
948 * the horizontal and vertical position of the list view within the list.
950 IMPORT_C virtual void UpdateScrollBarThumbs() const;
953 * Get horizontal scroll granularity in pixels.
954 * The granularity is the minimum size of a horizontal move of the client
957 * @return Grain size for horizontal scrolling in pixels.
959 IMPORT_C virtual TInt HorizScrollGranularityInPixels() const;
962 * Gets the number of grains to move horizontally when a nudge button is
964 * For simple list boxes, this value is a fraction of the width of the
967 * @return Number of grains to move left or right on each nudge
969 IMPORT_C virtual TInt HorizontalNudgeValue() const;
972 * Called by various functions of this class to ensure that the top
973 * item index is always a sane value. The implementation in @c CEikListBox
974 * tries to ensure the minimum amount of white space at the bottom of
975 * the list box. Note that this function does not affect the
976 * current item index.
978 IMPORT_C virtual void AdjustTopItemIndex() const;
980 // navigation support functions
982 * Simulates an arrow key event.
984 * If the list box flags include @c EMultipleSelection, this has the effect
985 * of pressing @c SHIFT with the arrow key represented by @c aKeyCode.
986 * Calls @c CEikListBox::OfferKeyEventL() with aKeyCode translated into a
989 * @param aKeyCode A key code.
991 IMPORT_C void SimulateArrowKeyEventL(TKeyCode aKeyCode);
994 * Handles a left arrow key event.
996 * The method used to handle the event depends on the selection mode, e.g.
997 * whether the user has pressed the @c SHIFT or @c CONTROL key.
999 * @param aSelectionMode Not used
1001 IMPORT_C virtual void HandleLeftArrowKeyL(CListBoxView::TSelectionMode aSelectionMode);
1004 * Handles a right arrow key event.
1006 * The method used to handle the event depends on the selection mode,
1007 * e.g. whether the user has pressed the @c SHIFT or @c CONTROL key.
1009 * @param aSelectionMode Not used.
1011 IMPORT_C virtual void HandleRightArrowKeyL(CListBoxView::TSelectionMode aSelectionMode);
1013 // construction support functions
1015 * Restores the list box properties shared by all subclasses from a resource
1016 * reader. This function is not called within @c CEikListBox itself, but is
1017 * used by subclasses which support construction from resources.
1019 * @param aReader A resource reader.
1021 IMPORT_C void RestoreCommonListBoxPropertiesL(TResourceReader& aReader);
1024 * Second-phase constructor.
1026 * This protected form is overridden non-virtually by the second-phase
1027 * constructors of each subclass, and should be invoked by them using
1028 * @c CEikListBox::ConstructL().
1030 * @param aParent The parent control. May be NULL.
1031 * @param aFlags Construction flags.
1033 IMPORT_C virtual void ConstructL(const CCoeControl* aParent, TInt aFlags = 0);
1036 * Completes the list box view’s construction.
1038 * This function is called by @c ConstructL() to complete construction
1039 * of the resource view, calling its @c ConstructL() with appropriate
1040 * arguments and assigning it to @c iView. Also prepares the view for use.
1042 IMPORT_C virtual void CreateViewL();
1045 * Creates the list box view.
1047 * The function is called by @c ConstructL() to create an instance of
1048 * the appropriate list box view class for this list box. The returned
1049 * instance is owned by this object, and does not have to have its
1050 * second-phase constructor run. This function is called by @c CreateViewL().
1052 * @return Pointer to a newly constructed list box view for this object.
1054 IMPORT_C virtual CListBoxView* MakeViewClassInstanceL();
1057 * Sets the view rectangle from the client rectangle making sure a whole
1058 * number of items is displayed.
1060 * @param aClientRect The client rectangle
1062 IMPORT_C void SetViewRectFromClientRect(const TRect& aClientRect);
1065 * Calculates the client area.
1067 * This method is called by various functions of this class to
1068 * recalculate the extent of the client area from @c iViewRect. This
1069 * implementation takes into account any rounding of the viewing
1070 * rectangle made to fit a whole number of items.
1072 * @param aClientRect On return contains a size for the client area
1075 IMPORT_C virtual void RestoreClientRectFromViewRect( TRect& aClientRect) const;
1078 * Rounds down the height of the rectangle (if necessary) so that
1079 * only a whole number of items can be displayed inside the list box.
1081 * @param aRect The rectangle to be modified.
1082 * @return The number of pixels reduced.
1084 IMPORT_C virtual TInt AdjustRectHeightToWholeNumberOfItems( TRect& aRect) const;
1086 // accessor for Laf members
1088 * Gets list box margins.
1090 * @return The list box margins in pixels.
1092 IMPORT_C TMargins8 ListBoxMargins() const;
1094 // various accessors for private data members
1096 * This function gets the horizontal margin. Use
1097 * @c CEikListBox::ListBoxMargins() instead, as this
1098 * provides a more accurate value due to the bit shifting involved.
1100 * @deprecated Use @c CEikListBox::ListBoxMargins()
1101 * @return The horizontal margin in pixels.
1103 IMPORT_C TInt HorizontalMargin() const;
1106 * This function gets the vertical margin. This function
1107 * is deprecated, use @c CEikListBox::ListBoxMargins() instead,
1108 * this provides a more accurate value due to the bit
1109 * shifting involved.
1111 * @deprecated Use @c CEikListBox::ListBoxMargins()
1112 * @return The vertical margin in pixels.
1114 IMPORT_C TInt VerticalMargin() const;
1117 * Sets the horizontal margin.
1119 * @param aMargin The required horizontal margin.
1121 IMPORT_C void SetHorizontalMargin(TInt aMargin);
1124 * Sets the vertical margin.
1126 * @param aMargin The required vertical margin.
1128 IMPORT_C void SetVerticalMargin(TInt aMargin);
1131 * Gets a pointer to the match buffer. Returns
1132 * NULL if the match buffer does not exist.
1134 * @return Pointer to the match buffer.
1136 IMPORT_C RIncrMatcherBase* MatchBuffer() const;
1139 * Gets the view rectangle height adjustment.
1141 * These are the adjustments that were made to the
1142 * view rectangle when the @c SetViewRectFromClientRect()
1143 * function was called.
1145 * @return Height adjustment.
1147 IMPORT_C TInt ViewRectHeightAdjustment() const;
1150 * Gets the background colour.
1152 * @return The background colour.
1154 IMPORT_C TRgb BackColor() const;
1157 * Sets the view rectangle height adjustment.
1159 * @param aAdjustment New adjustment.
1161 IMPORT_C void SetViewRectHeightAdjustment(TInt aAdjustment);
1166 * Reports a list box event to any observer of this list box.
1167 * This function returns immediately if no observer is set.
1169 * @param aEvent The event to report.
1171 IMPORT_C virtual void ReportListBoxEventL( MEikListBoxObserver::TListBoxEvent aEvent );
1174 * Redraws the specified area of this list box into the specified rectangle.
1176 * @param aRect Rectangle to be redrawn. Specified relative to the
1177 * origin of this control.
1179 IMPORT_C virtual void Draw(const TRect& aRect) const;
1182 * Clears the list box margins. The list box is redrawn only if redraws
1183 * are enabled for the list box view.
1185 IMPORT_C void ClearMargins() const;
1188 * Sets an item as the current item, even if it is not currently
1189 * visible. Redraws the list box to reflect the change. This
1190 * should not be called from within another Draw function.
1192 * @param aItemIndex The index of the list box item to update.
1194 IMPORT_C virtual void UpdateCurrentItem(TInt aItemIndex) const;
1197 * Handles drag events.
1199 * This function is called by @c HandlePointerEventL() to handle pointer
1200 * drag events appropriately.
1202 * @param aPointerPos The position of the @c TPointerEvent for which this
1203 * handler is invoked.
1205 IMPORT_C virtual void HandleDragEventL(TPoint aPointerPos);
1208 * Tests whether an item exists.
1210 * @param aItemIndex Index to test.
1211 * @return @c ETrue if the specified item exists, EFalse otherwise.
1213 IMPORT_C TBool ItemExists(TInt aItemIndex) const;
1216 * Draws the matcher cursor in the correct location for the current match.
1217 * If there is no match buffer, this function returns immediately;
1218 * otherwise the cursor is drawn on the current item using
1219 * @c CListBoxView::DrawMatcherCursor() after scrolling to make the current
1222 * A list box control’s matcher cursor is an on-screen cursor which is
1223 * drawn to indicate to the user the location of the current text. Whether
1224 * the cursor is drawn is dependent on the
1225 * @c CListBoxView::TFlags::EHasMatcherCursor flag, which may be set on the
1228 * Note, that CListBoxView::DrawMatcherCursor() is not implemented in S60.
1230 IMPORT_C void DrawMatcherCursor() const;
1233 * Gets the vertical gap between elements in the list box.
1235 * @return The vertical gap between elements in the list box.
1237 IMPORT_C static TInt InterItemGap();
1240 * Updates the view colours in line with the colours in effect for the
1241 * Uikon environment. Has no effect if there is no view.
1243 IMPORT_C void UpdateViewColors();
1246 * Updates the item drawer colours in line with the colours in effect
1247 * for the Uikon environment. Has no effect if there is no item drawer.
1249 IMPORT_C void UpdateItemDrawerColors();
1252 * Notifies item change observers about item change. Subclasses must call
1253 * this method if they have implemented item handling functions (e.g.
1254 * @c HandleItemAdditionL or @c HandleItemRemovalL).
1258 IMPORT_C void FireItemChange();
1261 protected: // functions which deal with extension
1263 * Sets the reason for the list box’s loss of focus.
1265 * This is required so the list box can determine whether
1266 * loss of focus is due to an external control or an internal component.
1268 * @param aReasonForFocusLost The reason for the loss of focus.
1270 IMPORT_C void SetReasonForFocusLostL( TReasonForFocusLost aReasonForFocusLost );
1273 * Gets the reason for the list box’s loss of focus.
1275 * @return The reason for the loss of focus.
1277 IMPORT_C TReasonForFocusLost ReasonForFocusLostL();
1280 * Tests whether the list box match buffer exists.
1282 * @return @c ETrue if the list box match buffer exists.
1283 @c EFalse if the list box match buffer does not exist.
1285 IMPORT_C TBool IsMatchBuffer() const;
1288 * Checks for a list box extension. Attempts to create one if not present.
1290 * This function leaves if an extension cannot be created.
1292 void CheckCreateExtensionL();
1295 * Checks for a list box extension. Creates one if not present.
1297 * @return @c ETrue if a list box extension already existed or
1298 * if there was no previous extension and a new extension
1299 * class was created successfully.
1300 * @c EFalse if there was no previous extension and a new one
1301 * could not be constructed.
1303 TBool CheckCreateExtension();
1306 * Checks the list box match buffer exists. If a buffer does not
1307 * exist, one is created.
1309 void CheckCreateBufferL();
1312 * Gets the list box match buffer.
1314 * @return The list box match buffer.
1316 CMatchBuffer* Buffer() const;
1320 * Creates a scroll bar frame layout according to @c aLayout.
1322 * @param aLayout Defines the layout.
1324 IMPORT_C void CreateScrollBarFrameLayout(TEikScrollBarFrameLayout& aLayout) const;
1327 * If MiddleSoftKey is either Mark or Unmark, this method sets MSK
1328 * according to the current item selection state.
1330 void UpdateMarkUnmarkMSKL() const;
1334 * @return Event modifiers for the @c CEikListBox.
1336 IMPORT_C TInt EventModifiers();
1339 * Returns ETrue if list has ES60StyleMultiselection flag.
1341 IMPORT_C TBool IsMultiselection();
1344 * Creates a scrollbar for the listbox. The caller may choose if the scrollbar is requested
1345 * remotely via the mop chain from parent control
1347 * @param aPreAlloc Is the scrollbar created immediately or when taking in to use
1348 * @param aRemote If True, the scrollbar is obtained via mop-chain from
1349 * parent control. If used, the listbox only sets the scrollbar
1350 * values. The scrollbar position and size must set in the parent
1353 * @return CEikScrollBarFrame* pointer to scrollbar frame object
1355 IMPORT_C CEikScrollBarFrame* CreateScrollBarFrameL(TBool aPreAlloc, TBool aRemote);
1358 * Creates a scrollbar for the listbox. The caller may choose if the scrollbar is requested
1359 * remotely via the mop chain from parent control
1361 * @param aPreAlloc Is the scrollbar created immediately or when taking in to use
1362 * @param aRemote If True, the scrollbar is obtained via mop-chain from
1363 * parent control. If used, the listbox only sets the scrollbar
1364 * values. The scrollbar position and size must set in the parent
1366 * @param aWindowOwning Does the created scrollbar create own window or
1367 * is it compound control. The listbox uses a window owning
1368 * scrollbar by default.
1370 * @return CEikScrollBarFrame* pointer to scrollbar frame object
1372 IMPORT_C CEikScrollBarFrame* CreateScrollBarFrameL(TBool aPreAlloc, TBool aRemote, TBool aWindowOwning);
1375 * By default markable listbox has middle softkey observer, which handles
1376 * Mark / Unmark functionality. By this method, the caller may disable default
1381 * @param aEnable If EFalse, disables default middle softkey observer
1382 * for markable lists. ETrue enables observer again.
1384 IMPORT_C void EnableMSKObserver(TBool aEnable);
1387 * Called from MSK observer when shift+MSK have been pressed
1391 void DoShiftMSKMarkingL();
1394 * This method is only called by CEikButtonGroupContainer when MSK observer
1395 * is enabled and CEikButtonGroupContainer is deleted.
1399 void InformMSKButtonGroupDeletion();
1402 * Adds a selection (item marking) observer to the listbox. Duplicates are not checked
1403 * (i.e. adding the same observer multiple times is not prevented).
1406 * @param aObserver Must be non-NULL.
1408 IMPORT_C void AddSelectionObserverL( MListBoxSelectionObserver* aObserver );
1411 * Removes a selection (item marking) observer from the listbox.
1414 * @param aObserver The observer to be removed.
1416 IMPORT_C void RemoveSelectionObserver( MListBoxSelectionObserver* aObserver );
1419 * This switches listbox into selection mode. Basicly only changes MSK and
1420 * informs selection observers about the change.
1423 * @param aEnable ETrue when entering into selection mode, EFalse when leaving
1425 void ChangeSelectionMode(TBool aEnable);
1428 * Sets the number of list items that form one grid line.
1431 * @param aItems Number of items in one grid line.
1433 IMPORT_C void SetItemsInSingleLine(TInt aItems);
1436 * Removes pointer event filtering for list items.
1438 * When there are two pointer up events on the same item at short interval,
1439 * listbox will only get the first one and drop the second one. This method forces listbox to handle all pointer up events.
1443 * @param aItemIndexes Array of item indexes to be added.
1445 IMPORT_C void SetPointerEventFilterDisabledL( const CArrayFix<TInt>& aItemIndexes );
1448 * Scrolls the view by the given amount of pixels while keeping the
1449 * physics parameters up-to-date.
1450 * This should be called when scrolling the list box view except for
1451 * when it is done by list dragging (e.g. scrolling with scroll bar).
1453 * @param aDeltaPixels Amount of pixels to scroll the view.
1457 IMPORT_C void HandlePhysicsScrollEventL( TInt aDeltaPixels );
1460 * Disables the kinetic scrolling functionality in the list.
1461 * By default the feature is enabled.
1463 * @param aDisabled @c ETrue to disable kinetic scrolling,
1464 * @c EFalse otherwise.
1468 IMPORT_C void DisableScrolling( TBool aDisabled );
1471 * Checks if the kinetic scrolling is currently enabled in the list.
1473 * @return @c ETrue if kinetic scrolling is enabled, @c EFalse otherwise.
1477 IMPORT_C TBool ScrollingDisabled();
1480 * Suspends transitions effects.
1484 * @param aSuspend ETrue to suspend effects, EFalse to re-enable them.
1486 IMPORT_C void SuspendEffects( TBool aSuspend );
1489 IMPORT_C virtual void CEikListBox_Reserved(); // listbox use only
1490 void HorizontalScroll(TInt aScrollAmountInPixels);
1491 void DrawItemInView(TInt aItemIndex) const;
1492 void ClearMargins(CWindowGc& aGc) const;
1493 TKeyResponse DoOfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);
1494 void UpdateScrollBarColors(CEikScrollBar* aScrollBar);
1495 void UpdateScrollBarsColors();
1497 void HandleItemRemovalWithoutSelectionsL();
1500 * Scrolls the view by the given amount of pixels.
1502 * @param aOffset Amount of offset in pixels.
1503 * @param aDrawNow Whether or not the view is be drawn.
1504 * If @c EFalse then only the logical state is updated.
1509 void ScrollView( const TInt aOffset, TBool aDrawNow );
1512 * Handles pointer events if physics are enabled.
1514 * @return @c ETrue if the event was consumed by kinetic scrolling.
1519 TBool HandlePhysicsPointerEventL( const TPointerEvent& aPointerEvent );
1522 * Selects an item and draws highlight to it.
1524 * @param aItemIndex Index of the highlighted item.
1529 void UpdateHighlightL( TInt aItemIndex );
1532 /** Flags for this list box */
1535 /** This List box's view */
1536 CListBoxView* iView;
1538 /** Item drawer for this list box */
1539 CListItemDrawer* iItemDrawer;
1541 /** Data model for this list box */
1542 MListBoxModel* iModel;
1544 /** Height of each item in the list */
1547 /** The scroll bar used by this control */
1548 CEikScrollBarFrame* iSBFrame;
1550 /** Identifies if the scroll bar is owned by this list */
1551 TScrollBarOwnerShip iSBFrameOwned;
1553 /** The required height of this list box expressed in
1554 * terms of a number of items.
1556 TInt iRequiredHeightInNumOfItems;
1559 * Defines which button launched the popout.
1561 CEikButtonBase* iLaunchingButton; // only used by popouts
1563 /** The button which just launched a popout menu. */
1564 MEikListBoxObserver* iListBoxObserver;
1569 // TInt iHorizontalMargin;
1570 // TInt iVerticalMargin;
1571 TMargins8 iMargins ;
1572 CListBoxExt* iListBoxExt;
1573 TInt iViewRectHeightAdjustment;
1574 MEikListBoxEditor* iItemEditor;
1575 TBool* iLbxDestroyed;
1576 TBool iLastCharMatched;
1583 * This is a list box that scrolls horizontally, displaying its items
1584 * in as many vertical columns as needed. Columns are arranged across
1585 * the control from left to right; within columns, items are arranged
1586 * from top to bottom. The flow of items or text ‘snakes’ across the
1587 * face of the control.
1589 * This is a flexible control class that makes good use of short, wide
1590 * display areas; for instance, subclasses of @c CEikSnakingListBox could
1591 * be used for file lists or for a control panel. A standard user
1592 * subclass, @c CEikSnakingTextListBox, also exists.
1594 * @since Symbian 5.0
1596 class CEikSnakingListBox : public CEikListBox
1600 * C++ standard constructor
1602 IMPORT_C CEikSnakingListBox();
1607 IMPORT_C ~CEikSnakingListBox();
1610 * Creates an instance of the view class.
1612 * This function is called during construction to create
1613 * (but not second-phase construct) an instance of the correct view
1614 * class for this list box control. In the case of the snaking list
1615 * box, a @c CSnakingListBoxView is returned.
1617 * This function overrides @c CEikListBox::MakeViewClassInstanceL().
1619 * @return The view which will be used by the list box being created
1621 IMPORT_C virtual CListBoxView* MakeViewClassInstanceL();
1624 * Sets the top item’s index.
1626 * @param aItemIndex Index of the item to set as the top item.
1628 IMPORT_C virtual void SetTopItemIndex(TInt aItemIndex) const;
1631 * Gets the width of this list box’s columns.
1633 * @return Width of each column.
1635 IMPORT_C TInt ColumnWidth() const;
1638 * Sets the width of all columns in the list box.
1640 * @param aColumnWidth New column width.
1642 IMPORT_C void SetColumnWidth(TInt aColumnWidth);
1644 public: //from CCoeControl
1647 * From @c CCoeControl.
1649 * Handles pointer events.
1651 * @param aPointerEvent The pointer event.
1653 IMPORT_C void HandlePointerEventL(const TPointerEvent& aPointerEvent);
1658 * Handles a change in size of the viewing rectangle.
1660 * This function is called by framework functions to update the content,
1661 * view, and scroll bars of this list box after the viewing rectangle has
1662 * changed size. This implementation ensures that the current item is
1663 * visible after a resize.
1665 IMPORT_C virtual void HandleViewRectSizeChangeL();
1668 * Handles a left arrow key event.
1670 * Moves the cursor into the correct column and clears any matcher buffer
1671 * that may have been built up.
1673 * @param aSelectionMode Not used.
1675 IMPORT_C virtual void HandleLeftArrowKeyL(
1676 CListBoxView::TSelectionMode aSelectionMode);
1679 * Handles a right arrow key event.
1681 * Moves the cursor into the correct column and clears any matcher buffer
1682 * that may have been built up.
1684 * @param aSelectionMode Not used.
1686 IMPORT_C virtual void HandleRightArrowKeyL(
1687 CListBoxView::TSelectionMode aSelectionMode);
1690 * Gets the number of grains to move horizontally when a nudge button
1693 * For simple list boxes, this value is a fraction of the width of the
1696 * @return Number of grains to move left or right on each nudge.
1698 IMPORT_C virtual TInt HorizontalNudgeValue() const;
1701 * Gets the granularity for horizontal scrolls.
1703 * The granularity is the minimum size of a horizontal move of the
1706 * @return Grain size for horizontal scrolling in pixels.
1708 IMPORT_C virtual TInt HorizScrollGranularityInPixels() const;
1711 * Called by various functions of this class to ensure that the top
1712 * item index is always a sane value. The implementation in @c CEikListBox
1713 * tries to ensure the minimum amount of white space at the bottom of
1714 * the list box. Note that this function does not affect the current
1717 IMPORT_C virtual void AdjustTopItemIndex() const;
1720 * Handles drag events.
1722 * This function is called by @c HandlePointerEventL() to handle
1723 * pointer drag events appropriately.
1725 * @param aPointerPos The position of the @c TPointerEvent for which this
1726 * handler is invoked.
1728 IMPORT_C virtual void HandleDragEventL(TPoint aPointerPos);
1731 * Calculates the client area.
1733 * This method is called by various functions of this class to recalculate
1734 * the extent of the client area from @c iViewRect. This implementation
1735 * takes into account any rounding of the viewing rectangle made to fit a
1736 * whole number of items.
1738 * @param aClientRect On return contains a size for the client area in
1741 IMPORT_C virtual void RestoreClientRectFromViewRect(
1742 TRect& aClientRect) const;
1745 * Rounds down the height of the rectangle (if necessary) so that only a
1746 * whole number of items can be displayed inside the list box.
1748 * @param aRect The rectangle to be modified.
1749 * @return The number of pixels reduced.
1751 IMPORT_C virtual TInt AdjustRectHeightToWholeNumberOfItems(
1752 TRect& aRect) const;
1755 * Move to next or previous item according to the given parameter.
1757 * @param aPoint Position which defines the moving direction.
1759 IMPORT_C void MoveToNextOrPreviousItemL(TPoint aPoint);
1761 protected: //from CCoeControl
1764 * From @c CCoeControl
1766 * Updates the viewing rectangle of this control appropriately. The function
1767 * updates the viewing rectangle, and invokes @c HandleViewRectSizeChangeL().
1769 IMPORT_C virtual void SizeChanged();
1772 * From @c CCoeControl
1774 * Gets the list of logical colours employed in the drawing of the control,
1775 * paired with an explanation of how they are used. Appends the list to
1778 * @param aColorUseList List of logical colours.
1780 IMPORT_C virtual void GetColorUseListL(
1781 CArrayFix<TCoeColorUse>& aColorUseList) const;
1782 // not available before Release 005u
1784 * From @c CCoeControl.
1786 * Handles a change to the list box’s resources of type @c aType which are
1787 * shared across the environment, colours or fonts for example.
1789 * @param aType The type of resources that have changed.
1791 IMPORT_C virtual void HandleResourceChange(TInt aType);
1792 // not available before Release 005u
1794 private: // from CCoeControl
1795 IMPORT_C void Reserved_1();
1797 IMPORT_C void Reserved_2();
1803 IMPORT_C void* ExtensionInterface( TUid aInterface );
1806 IMPORT_C virtual void CEikListBox_Reserved(); // listbox use only
1809 #endif // __EIKLBX_H__