2 * Copyright (c) 2005-2006 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: Slider editor class
19 #ifndef __AKNSLIDER_H__
20 #define __AKNSLIDER_H__
26 #include <avkon.hrh> // For TAknOrientation
30 // The following is max. length of the entire formatted value text including
31 // number, special characters and supplied text.
32 const TInt KValueLabelTextMaxLength = 30;
34 // Forward declarations
36 class MAknsSkinInstance;
37 class CAknSliderExtension;
42 class CAknSlider : public CEikBorderedControl
44 public: // Enumerations
46 * Elements that currently support custom graphics.
50 enum TSliderGfxElements
53 * Left cap component of the slider, without filling. Left cap equals
54 * to bottom cap in vertical layout.
59 * Right cap component of the slider, without filling. Right cap equals
60 * to top cap in vertical layout.
65 * Line component of the slider, without filling.
70 * Line component of the slider, with filling.
75 * Left cap component of the slider, with filling.
80 * Right cap component of the slider, with filling.
85 * Marker component of the slider.
90 * Tick mark component of the slider. Small evenly spaced lines,
91 * placed vertically in relation to slider itself.
96 * Marker component of the slider when dragged
102 * Supported slider position indicators.
109 * Flag for enabling/disabling line filling. With line filling different
110 * graphics will be used for the the slider line's left and right sides
111 * (the current marker position as pivot). The left side is considered
112 * filled line and the right side empty line.
114 * When line filling is enabled the graphics element @c EElemFilledLine
115 * is used for the left side and @c EElemEmptyLine for the right. If
116 * line filling is disabled @c EElemEmptyLine is used for the whole
121 * Flag for enabling/disabling line marker (the knob). While disabled
122 * marker is not visible, the marker area will still be used for touch
129 * Event for slider thumb/marker dragging.
136 * Slider thumb/marker drag start
138 EDragMarkerStart = 1000,
140 * Slider thumb/marker drag end
147 * Default Constructor.
149 IMPORT_C CAknSlider();
154 IMPORT_C ~CAknSlider();
157 * Sets the value of the slider control and also updates the iValueLabel
158 * text. There are the following constraints on the value:
159 * it must be within the current range,
160 * it must be at a value that is minimum + N * stepsize.
161 * If these are not both true, then the method will Panic
163 * @param aValue Sets the value of the slider.
165 IMPORT_C void SetValueL( TInt aValue );
168 * Returns the value of the slider control
170 * @return Slider value.
172 IMPORT_C TInt Value() const;
175 * Sets the range of the slider control. Maximum value must be greater than
176 * the minimum value, or the method will Panic.
178 * @param aMinimumValue The minimum value of the slider control
179 * @param aMaximumValue The maximum value of the slider control
181 IMPORT_C void SetRange( TInt aMinimumValue, TInt aMaximumValue );
184 * Gets the range of the slider control. Maximum value must be greater than
185 * the minimum value, or the method will Panic.
188 * @param aMinimumValue The minimum value of the slider control
189 * @param aMaximumValue The maximum value of the slider control
191 IMPORT_C void GetRange( TInt& aMinimumValue, TInt& aMaximumValue );
194 * Sets the step size. The step size must divide evenly into the Range. This
195 * routine should be called after SetRange if either is called.
197 * @param aStepSize The value of the step size
199 IMPORT_C void SetStepSize( TInt aStepSize );
202 * Sets the text to the minimum label.
204 * @param aText The text passed is set to the minimum label
206 IMPORT_C void SetMinimumTextL( const TDesC& aText );
209 * Sets the text to the maximum label.
211 * @param aText The text passed is set to the maximum label
213 IMPORT_C void SetMaximumTextL( const TDesC& aText );
216 * Sets the value of decimal places. The legal range is 0 - 9 inclusive.
218 * @param aDecimalPlaces The value of the decimal place
220 IMPORT_C void SetDecimalPlaces( TInt aDecimalPlaces );
223 * Returns the value of decimal place.
225 * @return the value of decimal place.
227 IMPORT_C TInt DecimalPlaces() const;
230 * Allows setting custom graphics for a certain slider element. Existing
231 * icons (custom or default) for the element are discarded. Note that some
232 * elements might not be visible until the corresponding functionality is
233 * enabled, see @c SetPositionIndicators and @c SetTicksEnabled.
235 * Slider takes care of scaling the given icons to the correct size,
236 * provided that they have been created with @c AknIconUtils or @c AknsUtils
237 * interfaces. It also handles re-scaling the icons if the slider layout
240 * If the custom icons are created by using skin items (e.g. using color
241 * from skin), remember to change the icons whenever skin changes, see
242 * @c CCoeControl::HandleResourceChange. In addition, note that slider can
243 * be with horizontal or vertical layout, @see Orientation
245 * @param aElement The element ID to which the icons are assigned, one of
248 * @param aBitmap The icon used for the element, must be non-NULL,
249 * ownership is transferred to slider.
251 * @param aMask Optional mask for the aBitmap, can be NULL, ownership
252 * is transferred to slider.
255 * Will panic with EAknPanicInvalidValue if the element ID is invalid or
260 IMPORT_C void SetGraphics( TInt aElement,
265 * Makes an element to use default graphics. Possible custom graphics for
266 * the element is discarded.
268 * @param aElement The element ID which should use default graphics, one of
272 * Will panic with EAknPanicInvalidValue if the element index is invalid.
276 IMPORT_C void UseDefaultGraphics( TInt aElement );
279 * Queries whether some element is using default graphics.
281 * @param aElement The element ID which should use default graphics, one of
284 * @return ETrue if default graphics is used for the element, EFalse
285 * otherwise (custom graphics used).
288 * Will panic with EAknPanicInvalidValue if the element index is invalid.
292 IMPORT_C TBool UsesDefaultGraphics( TInt aElement ) const;
295 * Configures line position indicators, which display the slider's current
296 * position. Possible indicators are defined in @c EPositionIndicator, at
297 * least one of them must be defined (to display some position information).
298 * Multiple values can be enabled by using bitwise or, e.g. @c EPosFilling |
299 * EPosMarker. The new flags will fully override the old values. The default
300 * value is @c EPosMarker.
302 * @param aFlags Bitmask containing flags from @c EPositionIndicator. At
303 * least one flag should be set.
306 * If none of the flags in @c EPositionIndicator is set, the code defaults
307 * silently to @c EPosMarker.
311 IMPORT_C void SetPositionIndicators( TUint32 aFlags );
315 * Queries the current status of position indicators.
317 * @return Bitmask containing flags as defined in @c EPositionIndicator
321 IMPORT_C TUint32 PositionIndicators() const;
324 * Queries the current orientation status.
326 * @return The current orientation, see @c TAknOrientation.
330 IMPORT_C TAknOrientation Orientation() const;
333 * Enables/disables the tick marks. Tick marks are disabled by default.
334 * Enabling tick marks affects only the visual appearance of slider. That is,
335 * enabling slider step handling is not changed.
337 * @param aStatus ETrue to enable tick marks, EFalse to disable.
341 IMPORT_C void SetTicksEnabled( TBool aStatus );
344 * Queries the current tick mark status.
346 * @return ETrue if tick marks are enabled, EFalse otherwise.
350 IMPORT_C TBool TicksEnabled() const;
353 * Sets the tick interval used for drawing the tick marks. Tick interval is
354 * in the slider range units (not in pixels). If interval value is set to 0,
355 * the slider step size is used as tick interval, see @c SetStepSize. The
356 * default interval value is 0.
358 * @param aInterval The value set as tick interval, always >= 0.
362 IMPORT_C void SetTickInterval( TUint aInterval );
365 * Queries the current tick interval value.
367 * @return Current tick interval, always >= 0.
371 IMPORT_C TUint TickInterval() const;
374 * Returns slider bitmap to "list pane for setting item" (setting option
375 * item slider graphic). Ownership of the returned bitmap is transfered to
378 * @param aValue Current value
379 * @param aResourceId Slider resource that contains minimum and maximum
381 * @return Slider bitmap. Ownership of the bitmap is transfered to the
384 IMPORT_C static CFbsBitmap* CreateBitmapL( TInt aValue,
388 * Returns slider bitmap to "list pane for setting item" (setting option
389 * item slider graphic). Ownership of the returned bitmap is transfered to
392 * @param aValue Current value
393 * @param aMinimumValue Slider minimum value
394 * @param aMaximumValue Slider maximum value
395 * @return Slider bitmap. Ownership of the bitmap is transfered to the
398 IMPORT_C static CFbsBitmap* CreateBitmapL( TInt aValue,
400 TInt aMaximumValue );
403 * Returns slider icon to "list pane for setting item" (setting option item
404 * slider graphic). Ownership of the returned icon is transfered to the
407 * @param aValue Current value
408 * @param aResourceId Slider resource that contains minimum and maximum
410 * @return Slider icon. Ownership of the icon is transfered to the caller
412 IMPORT_C static CGulIcon* CreateSetStyleListBoxIconL( TInt aValue,
416 * Returns slider icon to "list pane for setting item" (setting option item
417 * slider graphic). Ownership of the returned icon is transfered to the
420 * @param aValue Current value
421 * @param aMinimumValue Slider minimum value
422 * @param aMaximumValue Slider maximum value
423 * @return Slider bitmap. Ownership of the icon is transfered to the caller
425 IMPORT_C static CGulIcon* CreateSetStyleListBoxIconL( TInt aValue,
427 TInt aMaximumValue );
429 * Call CCoeControl::EnableDragEvents()
433 IMPORT_C void EnableDrag();
437 * From CCoeControl, returns the size of the control. And yes, this method
440 * @return size of the control
445 * From CCoeControl, Handles key event.
447 * @param aKeyEvent The key event.
448 * @param aType The type of the event.
449 * @return Indicates whether the key event was used by this control or not
451 TKeyResponse OfferKeyEventL( const TKeyEvent& aKeyEvent,
455 * From CCoeControl, essential for Dialog/Form construction.
457 * @param aReader which reads the values specified in the resource file
459 IMPORT_C void ConstructFromResourceL( TResourceReader& aReader );
462 * This function is used for constructing the control.
464 * @param aParent Pointer to the parent control.
465 * @paran aValue Current value of the slider control.
466 * @param aReader which reads the values specified in the resource file.
468 IMPORT_C void ConstructFromResourceL( CCoeControl* aParent,
470 TResourceReader& aReader );
473 * This function toggles between edit and view modes
475 * @param aType Specifies the mode.
477 IMPORT_C void HandleResourceChange( TInt aType );
480 * This function will be called when focus changed.
482 * @param aDrawNow if the control needs to call DrawNow().
484 IMPORT_C virtual void FocusChanged(TDrawNow aDrawNow);
488 * This function is used specifically in the forms. (For Forms/Dialogs to
489 * use with LAF) Returns the number of lines on the control.
491 * @return Number of lines
493 IMPORT_C TInt NumberOfLines() const;
496 * This routine can be used to combine the resource for a Slider with a
497 * value to get the same value text that you would get if you had the
498 * instantiated control
500 * @param aValue The value to format
501 * @param aResourceId AKN_SLIDER resource id
503 * @return Transfer of ownership of descriptor containing the value text
505 IMPORT_C static HBufC* CreateValueTextInHBufCL( TInt aValue,
508 void SuppressDrawing( TBool aSuppress );
512 * From CCoeControl, Called by framework when the view size is changed.
517 * From CCoeControl, Drawing function which draws the control
519 * @param aRect Specified area to be drawn
521 void Draw( const TRect& aRect ) const;
524 * From CCoeControl, Returns number of components.
526 * @return Number of component controls
528 IMPORT_C virtual TInt CountComponentControls() const;
531 * From CCoeControl, Returns pointer to particular component
533 * @param aIndex Index whose control's pointer has to returned.
534 * @return Pointer to component control
536 IMPORT_C virtual CCoeControl* ComponentControl( TInt aIndex ) const;
540 * From CCoeControl. Handles pointer event
542 * @param aPointerEvent Pointer event to be handled
544 IMPORT_C void HandlePointerEventL( const TPointerEvent& aPointerEvent );
545 TInt StepSize() const;
551 IMPORT_C void* ExtensionInterface( TUid aInterface );
555 * Sets the text to the value label
557 IMPORT_C void SetValueTextL();
562 * Report event for thumb/marker dragging via HandleControlEventL
566 void ReportMarkerDragEvent( TBool aEnable );
570 * This function creates the bitmaps and labels. Also it sets the
571 * container window for the labels.
575 void InitializeBitmapsL();
578 * static routine for setting the value text.
579 * @param valueBuf Buffer to hold the result. Must be big enough to hold
580 * value label as formatted from the resources and value provided, though
581 * it is protected from overflow. Contained text will be truncated to
582 * KValueLabelTextMaxLength
583 * @param aValue Slider value to format
584 * @param aResourceData resource Id to read from
586 static void DoSetValueTextL( TDes& valueBuf, TInt aValue,
587 const CAknSliderData& aResourceData );
590 * This method is used to trap all the accesses to the internal data. It
591 * panics with EAknPanicObjectNotFullyConstructed if iData is not
592 * constructed, that is, if 2nd stage construction has not taken place (or
595 CAknSliderData* SliderData() const;
598 * This class is a utility to protect StringLoader::Format from being
599 * called without a formatting token.
601 * StringLoader is used in current implementation. See StringLoader::Format
602 * for the semantics of the parameters.
604 * The other thing to note is that the output for descriptor must be able
605 * to accept up to KValueLabelTextMaxLength characters.
607 * @param aOutput Output of format operation
608 * @param aFormat Formatting descriptor.
609 * @param aValue Descriptor to substitute for the %U token potentially
610 * present in the formatting descriptor.
612 static void FormatWithOrWithoutTokenL( TDes& aOutput,
613 const TDesC& aFormat,
614 const TDesC& aValue );
617 void FormSliderLayout1();
618 void FormSliderLayout2();
619 void FormSliderLayout3();
620 void SettingsItemSliderLayout();
621 void VerticalSliderLayout();
622 void HorizontalSliderLayout();
623 void MIDPFormSliderLayout();
625 void SetLabelColor();
628 void CreateDecoratorImageFromResourceL( TInt aImageResourceId );
630 // Internal access methods
632 TInt MaximumValue() const;
633 TInt MinimumValue() const;
636 // Starts a timer for feedback effect visualization.
639 // Callback for feedback effect.
640 static TInt IndicationDrawCallbackL( TAny* aThis );
642 // Implementation of the feedback effect.
643 void SmallDirectionIndicationL();
645 void DrawHorizontalTickMarks( CWindowGc& aGc ) const;
646 void DrawVerticalTickMarks( CWindowGc& aGc ) const;
648 void TranslateValueL( TInt aDelta, TBool aFeedback = EFalse );
650 void GetMarkerRect( TRect& aRect ) const;
651 TSize MarkerSize() const;
652 TPoint MarkerPos() const;
654 void DrawHorizontal( TBool aDrawMarker ) const;
655 void DrawVertical( TBool aDrawMarker ) const;
657 void DrawHorizontalLine( CWindowGc& aGc ) const;
658 void DrawVerticalLine( CWindowGc& aGc ) const;
660 void FetchGfx( TAknSliderGfx& aGfx, TInt aElement, const TSize& aSize ) const;
662 // calculate the correct value according to the input point
663 TInt CalcAlignedValue( const TPoint& aPoint );
665 void StartFeedback( const TPointerEvent* aPointerEvent, TTimeIntervalMicroSeconds32 aTimeout );
667 void ModifyFeedback();
668 TInt FeedbackIntensity();
671 * Provides the touch active area for setting item slider.
673 * @return Touch active area rect.
675 TRect TouchActiveArea() const;
679 CEikLabel* iValueLabel;
680 CEikLabel* iMinLabel;
681 CEikLabel* iMaxLabel;
682 CFbsBitmap* iMarkerBmp;
683 CFbsBitmap* iMarkerMaskBmp;
690 // Not used, kept for binary compatibility. Another pointer with same name
691 // in iData is really used
692 HBufC* iSingularText;
694 CAknSliderData* iData;
695 CAknSliderExtension* iExt;
700 #endif // __AKNSLIDER_H__