classicui_plat/volume_popup_api/inc/AknVolumePopup.h
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2004-2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     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".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Popup Volume Indicator
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef AKN_VOLUME_POPUP_H
       
    20 #define AKN_VOLUME_POPUP_H
       
    21 
       
    22 //  INCLUDES
       
    23 #include <coecntrl.h>
       
    24 #include <avkon.rsg>
       
    25 
       
    26 // CONSTANTS
       
    27 const TInt KTextLen        = 64;
       
    28 const TInt KWindowPosition = 10;           // window group's priority
       
    29 const TInt KInactivityTime = 2000000;      // 2 seconds - close window after this
       
    30 _LIT( KVolumePopupWgName, "VolumePopup" ); // window groups name
       
    31 
       
    32 /**
       
    33 * AknVolume is showed, press speaker icon with the pen, speaker
       
    34 * icon will be replaced to the mute icon. Value() should reurn 
       
    35 * KVolumePopupMutedValue, but volume level before muted should
       
    36 * be saved. After press the  mute icon again, speaker icon  
       
    37 * should display again and Value()should return the saved value.
       
    38 */
       
    39 const TInt KVolumePopupMutedValue = 0;  
       
    40 const TInt KVolumePopupLevelNotFound = 0;
       
    41 // FORWARD DECLARATIONS
       
    42 class CAknVolumeControl;
       
    43 class CEikLabel;
       
    44 class CFbsBitmap;
       
    45 class CAknsBasicBackgroundControlContext;
       
    46 class CAknButton;
       
    47 class CAknSlider;
       
    48 class CAknControl;
       
    49 class CAknVolumePopupExtension;
       
    50 // CLASS DECLARATION
       
    51 
       
    52 /**
       
    53 * Sidekey Popup volume indicator
       
    54 * 
       
    55 * @lib avkon.lib
       
    56 * @since 2.8
       
    57 *
       
    58 * How to use: <br>
       
    59 * ----------- <br>
       
    60 * // create control <br>
       
    61 * iVolumePopup = CAknVolumePopup::NewL();
       
    62 *
       
    63 * // set title text <br>
       
    64 * iVolumePopup->SetTitleText( _L("Ringer / Profile") );
       
    65 *
       
    66 * // set range <br>
       
    67 * iVolumePopup->SetRange( iMinimumValue, iMaximumValue ); //iMinimumValue<=iVolume && iVolume<=iMaximumValue <br>
       
    68 *
       
    69 * // set value <br>
       
    70 * iVolumePopup->SetValue( iVolume );
       
    71 *
       
    72 * // display it  <br>
       
    73 * iVolumePopup->ShowVolumePopupL(); // will close itself after 1s unless another call to ShowVolumePopupL() is made <br>
       
    74 *
       
    75 * // if non volume key is pressed <br>
       
    76 * iVolumePopup->CloseVolumePopup();
       
    77 *
       
    78 */
       
    79 
       
    80 NONSHARABLE_CLASS(CAknVolumePopup) : public CCoeControl, 
       
    81                                      public MCoeControlObserver,
       
    82                                      public MCoeControlBackground
       
    83     {
       
    84 public: // Enumerations
       
    85     /**
       
    86     * Elements that currently support custom graphics.
       
    87     *
       
    88     * @since 5.0
       
    89     */
       
    90     enum TVolumeGfxElements
       
    91         {
       
    92 
       
    93         /**
       
    94         * Speaker component of the volume when unmute.
       
    95         */
       
    96         EElemSpeaker = 100,
       
    97 
       
    98         /**
       
    99         * Mute component of the volume when mute.
       
   100         */
       
   101         EElemMute,
       
   102 
       
   103         /**
       
   104         * Plus Button component of the volume when button active.
       
   105         */ 
       
   106         EElemPlusButtonActive,
       
   107 
       
   108         /**
       
   109         * Plus Button component of the volume when button dimmed.
       
   110         */
       
   111         EElemPlusButtonInActive,
       
   112 
       
   113         /**
       
   114         * Plus Button component of the volume when button pressed.
       
   115         */
       
   116         EElemPlusButtonSelected,
       
   117 
       
   118         /**
       
   119         * Minus Button component of the volume when button active.
       
   120         */
       
   121         EElemMinusButtonActive,
       
   122 
       
   123         /**
       
   124         * Minus Button component of the volume when button dimmed.
       
   125         */
       
   126         EElemMinusButtonInActive,
       
   127 
       
   128         /**
       
   129         * Minus Button component of the volume when button pressed.
       
   130         */
       
   131         EElemMinusButtonSelected      
       
   132         };
       
   133 // Constructors and destructor    
       
   134     public:  
       
   135         /** deprecated */
       
   136         IMPORT_C static CAknVolumePopup* NewL( const TUid aSharedDataVolumeUid,
       
   137                                                const TDesC& aKey, 
       
   138                                                TInt aMinimumValue = 0 );
       
   139 
       
   140         /** 
       
   141         * deprecated.
       
   142         * Two-phased constructor.
       
   143         * Use NewL() to create old volume popup control.
       
   144         * @param aMinimumValue deprecated
       
   145         */
       
   146         IMPORT_C static CAknVolumePopup* NewL( TInt aMinimumValue = 0 );
       
   147 
       
   148         /** 
       
   149         * Two-phased constructor utilizing custom resource defined by client.
       
   150         * Use either this or NewL(). 
       
   151         * ConstructFromResourceL() can create dynimic_range volume control
       
   152         * @param aResourceId Resource ID for DYNAMIC_VOLUME or VOLUME resource.
       
   153         * 
       
   154         */
       
   155         IMPORT_C static CAknVolumePopup* ConstructFromResourceL( TInt aResourceId );
       
   156 
       
   157         /**
       
   158         * Two-phased constructor utilizing custom resource defined by client.
       
   159         * if aIsVertical is ETrue, there would be a vertical slider
       
   160         * if aIsVertical is EFalse, there would be a volume control, but not
       
   161         * dynimic_range volume control 
       
   162 
       
   163         * @since 5.0
       
   164         * @param aParent Pointer to the parent control. 
       
   165         * @param aIsVertical A flag for create a vertical slider volume or not.       
       
   166         */
       
   167         IMPORT_C static CAknVolumePopup* NewL( CCoeControl* aParent,
       
   168                                                TBool aIsVertical );
       
   169                                                                 
       
   170         /**
       
   171         * Destructor
       
   172         */
       
   173         virtual ~CAknVolumePopup();
       
   174         
       
   175 // from CCoeControl
       
   176     public: 
       
   177         TInt CountComponentControls() const;
       
   178         CCoeControl* ComponentControl(TInt aIndex) const;
       
   179         void Draw(const TRect& aRect) const;        
       
   180         void HandlePointerEventL(const TPointerEvent &aPointerEvent);
       
   181         TKeyResponse OfferKeyEventL( const TKeyEvent& aKeyEvent,
       
   182                                      TEventCode aType );    
       
   183         void PositionChanged();
       
   184         
       
   185 // from MCoeControlObserver               
       
   186     public: 
       
   187         void HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType); 
       
   188         
       
   189 // from MCoeControlBackground 
       
   190     public:
       
   191         void Draw(CWindowGc &aGc, const CCoeControl &aControl, const TRect &aRect) const; 
       
   192                                                               
       
   193 // New functions
       
   194     public: 
       
   195         /** deprecated */
       
   196         IMPORT_C TKeyResponse HandleVolumeKeyEventL(const TKeyEvent& aEvent, TEventCode aType); 
       
   197 
       
   198         /**
       
   199         * Set new volume value to volume control or vertical slider control
       
   200         * will show muted icon  or text, if value is 0
       
   201         * The first call to this method will set the value to be the default value.
       
   202         * @param aValue new value 
       
   203         */
       
   204         IMPORT_C void SetValue(TInt aValue);
       
   205 
       
   206         /**
       
   207         * Sets the range of the volume control or vertical slider control. 
       
   208         * Maximum value must be greater 
       
   209         * than the minimum value, or the method will Panic.
       
   210         * Volume value should be within the range.
       
   211         * If the default value is greater than the Maximum value, it will be set to maximum value.
       
   212         * if the default value is smaller than the Minimum value, it will be set to minimum value.
       
   213         *
       
   214         * @since 3.2
       
   215         * @param aMinimumValue The minimum value of the volume/vertical slider  control
       
   216         * @param aMaximumValue The maximum value of the volume/vertical slider  control
       
   217         * @par Exceptions:
       
   218         *   Will panic with EAknPanicInvalidValue if the minimum value is greater
       
   219         *   or equal than maximum value.
       
   220         *
       
   221         */
       
   222         IMPORT_C void SetRange( TInt aMinimumValue, TInt aMaximumValue );
       
   223         
       
   224         /**
       
   225         * Gets the range of the volume control or vertical slider.
       
   226         * @since 3.2
       
   227         * @param aMinimumValue The minimum value of the volume/vertical slider control
       
   228         * @param aMaximumValue The maximum value of the volume/vertical slider control
       
   229         */
       
   230         IMPORT_C void GetRange( TInt& aMinimumValue, TInt& aMaximumValue );
       
   231 
       
   232         /**
       
   233         * get volume control or vertical slider control value
       
   234         */
       
   235         IMPORT_C TInt Value() const;
       
   236 
       
   237         /**
       
   238         * Set title part of label text
       
   239         * @param aText title part of text
       
   240         */
       
   241         IMPORT_C void SetTitleTextL( const TDesC& aText );
       
   242 
       
   243         /** deprecated */
       
   244         IMPORT_C void ShowProfileName( TBool aShowProfile );
       
   245 
       
   246         /**
       
   247         * Show the popup window - it will
       
   248         * close itself after a second of inactivity
       
   249         */
       
   250         IMPORT_C void ShowVolumePopupL();
       
   251 
       
   252         /**
       
   253         * close the popup window - actually this only hides it
       
   254         */
       
   255         IMPORT_C void CloseVolumePopup();
       
   256         
       
   257         /**
       
   258         * Set value type for vertical slider control
       
   259         *
       
   260         * @since 5.0
       
   261         * @param aValueType A type of value, should be EAknSliderValueNone,
       
   262         * EAknSliderValueBareFigure,EAknSliderValuePercentage,
       
   263         * EAknSliderValueFraction or EAknSliderValueDecimal.
       
   264         *
       
   265         * If EAknSliderValueNone is set as value type, the speaker icon will
       
   266         * be displayed instead of value text;
       
   267         * 
       
   268         * If one of other value types except EAknSliderValueNone is set as
       
   269         * value type, the speaker icon will not be shown, only the value text
       
   270         * can be seen.
       
   271         *
       
   272         * The default value type is EAknSliderValueNone.
       
   273         */
       
   274         IMPORT_C void SetValueType( TInt aValueType );
       
   275          
       
   276         /**
       
   277         * Sets the step size. The step size must divide evenly into the Range. This
       
   278         * routine should be called after SetRange if either is called.
       
   279         *
       
   280         * @since 5.0
       
   281         * @param aStepSize The value of the step size
       
   282         */
       
   283         IMPORT_C void SetStepSize( TInt aStepSize );
       
   284         
       
   285         /**
       
   286         * As default adjustment indicator is displayed.
       
   287         * this function can be used to sets switch for adjustment indicator on/off.
       
   288         *
       
   289         * @since 5.0
       
   290         * @param aFlag A bool value for switch adjustment indicator on/off.
       
   291         */
       
   292         IMPORT_C void SetAdjustmentIndicatorDisplay( TBool aFlag );
       
   293         
       
   294         /**
       
   295         * Time out for dispear the volume control can be defined.
       
   296         * Only used for floating Slider popup( no Parent defined).
       
   297         * If parent is set, Timeout doesn't take effect, the contol
       
   298         * is alway shown until user close it manually.
       
   299         *
       
   300         * @since 5.0
       
   301         * @param aSecond A time value as second.
       
   302         */
       
   303         IMPORT_C void SetTimeOutAsSecond( TInt aSecond ); 
       
   304         
       
   305         /**
       
   306         * Decimal place can be set by the user.
       
   307         * Only used for Slider popup, the value must be 0 ~ 9
       
   308         *
       
   309         * @since 5.0
       
   310         * @param aDecimalPlace A decimal place.
       
   311         */
       
   312         IMPORT_C void SetDecimalPlaces( TInt aDecimalPlaces ); 
       
   313                      
       
   314         /**
       
   315         * Allows setting custom graphics for a certain vertical volume element. 
       
   316         * Existing icons (custom or default) for the element are discarded. 
       
   317         *
       
   318         * Vertical volume takes care of scaling the given icons to the correct size,
       
   319         * provided that they have been created with @c AknIconUtils or @c AknsUtils
       
   320         * interfaces. It also handles re-scaling the icons if the volume layout
       
   321         * changes.
       
   322         *
       
   323         * If the custom icons are created by using skin items (e.g. using color
       
   324         * from skin), remember to change the icons whenever skin changes, see
       
   325         * @c CCoeControl::HandleResourceChange.
       
   326         *
       
   327         * @param aElement The element ID to which the icons are assigned, one of
       
   328         *                 @c TVolumeGfxElements and TSliderGfxElements.
       
   329         *
       
   330         * @param aBitmap The icon used for the element, must be non-NULL,
       
   331         *                ownership is transferred to volume.
       
   332         *
       
   333         * @param aMask Optional mask for the aBitmap, can be NULL, ownership
       
   334         *              is transferred to volume.
       
   335         *
       
   336         * @par Exceptions:
       
   337         *   Will panic with EAknPanicInvalidValue if the element ID is invalid or
       
   338         *   aBitmap is NULL.
       
   339         *
       
   340         * @since 5.0
       
   341         */
       
   342         IMPORT_C void SetGraphics( TInt aElement,
       
   343                                    CFbsBitmap* aBitmap,
       
   344                                    CFbsBitmap* aMask );
       
   345         /** 
       
   346         *  If muted icon is used, the speaker icon will change to mute 
       
   347         *  icon when volume value is minimized. If not, the speaker icon will 
       
   348         *  not be changed.
       
   349         *  @since 5.0
       
   350         *  @param aFlag  - A flag for changing to mute icon or not.
       
   351         */ 
       
   352         IMPORT_C void UseMutedIcon( TBool aFlag );
       
   353                                                      
       
   354         /** 
       
   355         *  If enabled, volumepopup will close itself when user touches outside,
       
   356         *  Enabled as default.
       
   357         *  @since 5.0
       
   358         *  @param aEnable  - ETrue then close volumepopup when user touches outside.
       
   359         */ 
       
   360         IMPORT_C void ClosePopupWhenTappedOutside( TBool aEnable );
       
   361         
       
   362         /**
       
   363         * Set default value for volume popup with value field.
       
   364         * Tapping the value field will set the volume value to be the default value,
       
   365         * also the first set value with SetValue call will set that value to be 
       
   366         * the default value.
       
   367         * @since 5.0
       
   368         * @param aValue new value
       
   369         */
       
   370         IMPORT_C void SetDefaultValue( TInt aValue );
       
   371         
       
   372         /**
       
   373         * If enabled, the value field displayed in volumepopup will be inactive. 
       
   374         * Enabled as default
       
   375         * @since 5.0
       
   376         * @param aEnable  - ETrue Disable the default value feature of volumepopup
       
   377         */
       
   378         IMPORT_C void EnableResetViaValueField( TBool aEnabled=ETrue );
       
   379 
       
   380 
       
   381 
       
   382     protected: // From CCoeControl
       
   383         void SizeChanged();
       
   384         
       
   385         void HandleResourceChange( TInt aType );
       
   386         
       
   387     private:
       
   388         /**
       
   389         * C++ default constructor.
       
   390         */
       
   391         CAknVolumePopup(TInt aFlags);
       
   392 
       
   393         /**
       
   394         * By default Symbian 2nd phase constructor is private.
       
   395         * @param aParent Pointer to the parent control.
       
   396         * @param aIsVertical A flag for create a vertical slider volume or not.
       
   397         * @param aResourceId Resource ID for volume.
       
   398         */
       
   399         void ConstructL( CCoeControl* aParent,
       
   400                          TBool aIsVertical,
       
   401                          TInt aResourceId = R_AVKON_POPUP_VOLUME_INDICATOR );
       
   402 
       
   403         /** Prohibit copy constructor if not deriving from CBase.*/
       
   404         CAknVolumePopup( const CAknVolumePopup& );
       
   405         
       
   406         /** Prohibit assigment operator if not deriving from CBase.*/
       
   407         CAknVolumePopup& operator=( const CAknVolumePopup& );
       
   408 
       
   409         static void CleanupShowVolumePopup(TAny* aThis);
       
   410 
       
   411         void SetSpeakerMuted(TBool aMuted);
       
   412         void MutePressed();
       
   413         void StartTimer();
       
   414         void ResetTimer();
       
   415         static TInt TimerExpired(TAny* aPtr);
       
   416 
       
   417         /**
       
   418         * Show text "Muted" instead of volume slider if volume = 0
       
   419         * @param aShowMuteAsLabel ETrue = show text
       
   420         *
       
   421         * Not exported yet
       
   422         */
       
   423         /*IMPORT_C*/ void ShowMuteAsLabel( TBool aShowMuteAsLabel );
       
   424         
       
   425         /**
       
   426         * When the volume value is minimum or mute, volume control is 
       
   427         * invisible, but the if vertical slider is used, it can be seen.
       
   428         * @param aVisibility A flag for the volume control's visiblility.
       
   429         */
       
   430         void SetVisibilityL( TBool aVisibility );
       
   431         
       
   432         void CreateControlsL();
       
   433         void CreateSpeakerL();
       
   434         void SetControlIconL(  TInt aElement,
       
   435                                CFbsBitmap* aBitmap,
       
   436                                CFbsBitmap* aMask );
       
   437         void CreateLeftRightButtonL();
       
   438         void CreateUpDownButtonL();
       
   439         void SetValueTextL();
       
   440         
       
   441         void DoSetValueTextL( TDes& aTextBuf, TInt aValue );
       
   442 
       
   443         void GetMarkerRect( TRect& aRect );
       
   444         
       
   445         /**
       
   446          * From @c CCoeControl.
       
   447          *
       
   448          * Retrieves an object of the same type as that encapsulated in aId. Other
       
   449          * than in the case where @c NULL is returned, the object returned must be 
       
   450          * of the same object type - that is, the @c ETypeId member of the object
       
   451          * pointed to by the pointer returned by this function must be equal to the
       
   452          * @c iUid member of @c aId.
       
   453          *
       
   454          * @param aId An encapsulated object type ID.
       
   455          * @return Encapsulates the pointer to the object provided. Note that the 
       
   456          *         encapsulated pointer may be @c NULL.
       
   457          */
       
   458         TTypeUid::Ptr MopSupplyObject( TTypeUid aId );       
       
   459         void SetVolumeLayout();
       
   460         void SetLabelColor();       
       
   461         /**
       
   462         * Set new volume value to volume control or vertical slider control
       
   463         * will show muted icon  or text, if value is 0
       
   464         * @param aValue new value (1-10)
       
   465         */
       
   466         void DoSetValue(TInt aValue);       
       
   467 // member data
       
   468     private:    
       
   469         RWindowGroup        iWindowGroup;
       
   470         
       
   471         /** title & profile text */
       
   472         CEikLabel*          iLabel;
       
   473         /** text to show instead of volume control */
       
   474         CEikLabel*          iMutedLabel;      
       
   475 
       
   476         /** spare */
       
   477         HBufC*              iSpare;
       
   478         /** muted label text */
       
   479         HBufC*              iMutedText;       
       
   480         
       
   481         // icons
       
   482         CAknButton*         iSpeaker;
       
   483 
       
   484         /** current volume setting */
       
   485         TInt                iVolume;          
       
   486         // show normal / muted icon */
       
   487         TBool               iMuted;           
       
   488         /** is control visible? */
       
   489         TBool               iVisible;         
       
   490         /** show "Muted" instead of volume control */
       
   491         TBool               iShowMuteAsLabel; 
       
   492         /** saved volume setting */
       
   493         TInt                iStoredLevel; 
       
   494         /** only used for vertical slider value label format */
       
   495         TInt iValueType;
       
   496         TInt iDecimalPlaces;
       
   497         
       
   498         /** controls parent rectangle */
       
   499         TRect               iParentRect;              
       
   500         
       
   501         TRect               iSpeakerRect;
       
   502         /** will close window after timeout */
       
   503         
       
   504         CPeriodic*          iTimer;           
       
   505         
       
   506         CAknsBasicBackgroundControlContext*  iBgcc;
       
   507         
       
   508         CAknButton* iDecArrow;
       
   509         CAknButton* iIncArrow;
       
   510         TInt iFlags;
       
   511         
       
   512         /** A switch for adjustment indictor icon display.*/ 
       
   513         TBool iAdjustmentIndicatorOn; 
       
   514         /** A flag for vertical or not.*/  
       
   515         TBool iVertical;
       
   516          
       
   517         /** time for inactivity time.*/
       
   518         TInt iTimeout; 
       
   519         CAknVolumePopupExtension* iExt;
       
   520         TAny* iSpareMember;             
       
   521 
       
   522     };
       
   523 
       
   524 
       
   525 #endif      // AKN_VOLUME_POPUP_H
       
   526             
       
   527 // End of File