Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
2 * Copyright (c) 2005-2008 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: Button component.
20 #ifndef __AKNBUTTON_H__
21 #define __AKNBUTTON_H__
24 #include <akncontrol.h>
25 #include <akniconutils.h>
28 // FORWARD DECLARATIONS
31 class CAknButtonExtension;
32 class CAknInfoPopupNoteController;
33 class CAknButtonStateExtension;
34 class CAknPictographInterface;
35 class CAknsFrameBackgroundControlContext;
36 class CAknResourceProvider;
41 * Class which represents one of the button states.
44 * @since Series 60 3.1
46 class CAknButtonState : public CBase
48 public: // Constructors and destructors
53 IMPORT_C ~CAknButtonState();
55 protected: // Constructors and destructors
60 * @param aFlags The flags for the button state
62 IMPORT_C CAknButtonState( const TInt aFlags );
65 * Symbian 2nd phase constructor.
67 * @param aIcon The icon for the normal state. Takes ownership.
68 * @param aDimmedIcon The icon for the dimmed state. Takes ownership.
69 * @param aPressedIcon The icon for the pressed down. Takes ownership.
70 * @param aHoverIcon The icon for the hover state. Takes ownership.
71 * @param aText The text inside the button.
72 * @param aHelpText The text for the tooltip.
74 IMPORT_C void ConstructL( CGulIcon* aIcon,
75 CGulIcon* aDimmedIcon,
76 CGulIcon* aPressedIcon,
79 const TDesC& aHelpText );
82 * Symbian 2nd phase constructor.
84 * @param aFilePath The path to the file which contains icons.
85 * @param aBmpId The bitmap ID for the normal state icon.
86 * @param aMaskId The mask ID for the normal state icon.
87 * @param aDimmedBmpId The bitmap ID for the dimmed state icon.
88 * @param aDimmedMaskId The mask ID for the dimmed state icon.
89 * @param aPressedBmpId The bitmap ID for the pressed down state.
90 * @param aPressedMaskId The mask ID for the pressed down state.
91 * @param aHoverBmpId The bitmap ID for the hover state icon.
92 * @param aHoverMaskId The mask ID for the hover state icon.
93 * @param aText The text inside the button.
94 * @param aHelpText The text for the tooltip.
95 * @param aId Item ID of the masked bitmap to be created for skin
97 * @param aDimmedId Item ID of the dimmed masked bitmap to be created
98 * for skin specific icon.
99 * @param aPressedId Item ID of the pressed masked bitmap to be created
100 * for skin specific icon.
101 * @param aHoverId Item ID of the masked hover bitmap to be created
102 * for skin specific icon.
104 IMPORT_C void ConstructL( const TDesC& aFilePath,
107 const TInt aDimmedBmpId,
108 const TInt aDimmedMaskId,
109 const TInt aPressedBmpId,
110 const TInt aPressedMaskId,
111 const TInt aHoverBmpId,
112 const TInt aHoverMaskId,
114 const TDesC& aHelpText,
115 const TAknsItemID& aId = KAknsIIDNone,
116 const TAknsItemID& aDimmedId = KAknsIIDNone,
117 const TAknsItemID& aPressedId = KAknsIIDNone,
118 const TAknsItemID& aHoverId = KAknsIIDNone );
120 public: // New functions
123 * Provides the icon for the normal state.
125 * @return The icon for the normal state.
127 IMPORT_C const CGulIcon* Icon() const;
130 * Provides the icon for the dimmed state.
132 * @return The icon for the dimmed state.
134 IMPORT_C const CGulIcon* DimmedIcon() const;
137 * Provides the icon for the pressed down (not released) state.
139 * @return The icon for the pressed down (not released) state.
141 IMPORT_C const CGulIcon* PressedIcon() const;
144 * Provides the icon for the hover state.
146 * @return The icon for the hover state.
148 IMPORT_C const CGulIcon* HoverIcon() const;
151 * Provides the text inside the button.
153 * @return The button text.
155 IMPORT_C const TDesC& Text() const;
158 * Provides the text inside the help note.
160 * @return The tooltip text.
162 IMPORT_C const TDesC& HelpText() const;
165 * Provides the flags for the state.
167 * @return The state flags.
169 IMPORT_C TInt Flags() const;
172 * Sets the icon for the normal state. Takes ownership.
174 * @param aIcon The icon for the normal state.
176 IMPORT_C void SetIcon( CGulIcon* aIcon );
179 * Sets the icon for the dimmed state. Takes ownership.
181 * @param aDimmedIcon The icon for the dimmed state.
183 IMPORT_C void SetDimmedIcon( CGulIcon* aDimmedIcon );
186 * Sets the icon for the pressed down state. Takes ownership.
188 * @param aPressedIcon The icon for the pressed down state.
190 IMPORT_C void SetPressedIcon( CGulIcon* aPressedIcon );
193 * Sets the icon for the hover state. Takes ownership.
195 * @param aHoverIcon The icon for the hover state.
197 IMPORT_C void SetHoverIcon( CGulIcon* aHoverIcon );
200 * Sets the text inside the button.
202 * @param aText The text inside the button.
204 IMPORT_C void SetTextL( const TDesC& aText );
207 * Sets the text inside the help note.
209 * @param aHelpText The text inside the tooltip.
211 IMPORT_C void SetHelpTextL( const TDesC& aHelpText );
214 * Sets the flags for the state.
216 * @param aFlags The flags for the state.
218 IMPORT_C void SetFlags( const TInt aFlags );
221 * Sets the icon for the normal state
223 * @param aFlags The flags for the state.
225 void UpdateIconL( const TDesC& aFilePath,
228 const TInt aDimmedBmpId,
229 const TInt aDimmedMaskId,
230 const TInt aPressedBmpId,
231 const TInt aPressedMaskId,
232 const TInt aHoverBmpId,
233 const TInt aHoverMaskId,
234 const TAknsItemID& aId = KAknsIIDNone,
235 const TAknsItemID& aDimmedId = KAknsIIDNone,
236 const TAknsItemID& aPressedId = KAknsIIDNone,
237 const TAknsItemID& aHoverId = KAknsIIDNone );
241 protected: // New functions
244 * Constructs controls from a resource file.
245 * @param aReader The resource reader with which to access the
246 * control's resource values.
248 IMPORT_C virtual void ConstructFromResourceL( TResourceReader& aReader );
251 * Updates the size of icons. Called from CAknButton::SizeChanged()
254 * @param aRect The new rectangle for the icons.
255 * @param aScaleMode The scale mode which was set for the button.
257 IMPORT_C virtual void SizeChanged( const TRect& aRect,
258 TScaleMode aScaleMode );
261 * @return ETrue if the button has valid text (not empty and not space).
263 IMPORT_C TBool HasText() const;
266 * @return ETrue if the button has valid tooltip text (not empty and
269 IMPORT_C TBool HasHelp() const;
272 * Handles changes in state's environment.
275 * @param aType Resource change's type.
277 void HandleResourceChange( TInt aType );
280 * Sets default scaling mode.
283 * @param aScaleMode Scaling mode.
285 void SetIconScaleMode( const TScaleMode aScaleMode );
287 private: // new functions
290 * Creates one icon based on the specified file path and IDs.
292 * @param aIcon The icon object which is created and returned.
293 * Will be deleted if it is not NULL on entry.
294 * @param aFilePath The path to the file which contains icons.
295 * @param aBmpId The bitmap ID for the icon.
296 * @param aMaskId The mask ID for the icon.
297 * @param aId Item ID of the masked bitmap to be created for skin
300 void CreateButtonIconL( CGulIcon*& aIcon, const TDesC& aFilePath,
301 TInt aBmpId, TInt aMaskId,
302 const TAknsItemID& aId = KAknsIIDNone ) const;
305 * Loads one icon based on the specified file path and IDs. If the icon
306 * is already loaded it is deleted and replaced with a reloaded copy.
309 * @param aIcon The icon object which is created and returned.
310 * Will be deleted if it is not NULL on entry.
311 * @param aFilePath The path to the file which contains icons.
312 * @param aBmpId The bitmap ID for the icon.
313 * @param aMaskId The mask ID for the icon.
314 * @param aId Item ID of the masked bitmap to be created for skin
317 void LoadButtonIcon( CGulIcon*& aIcon ) const;
320 * Replaces the given icon with a new one. If the original icon had its
321 * size set then the new icon is scaled to that size.
325 void ReplaceIcon( CGulIcon*& aIcon, CGulIcon* aNewIcon );
331 * @param aSize New icon size.
332 * @param aScaleMode Scaling mode.
333 * @return KErrNone or an error code.
335 TInt ScaleIcons( const TSize& aSize, TScaleMode aScaleMode );
338 * @return The extension object.
340 CAknButtonStateExtension* Extension() const;
343 * @return The scalemode of the ButtonState
345 TScaleMode ScaleMode() const;
348 * @param aDimmedIconCreatedByButton ETrue, if the dimmed icon of the state is
349 * created by owning Button
351 void SetGeneratedDimmedIcon( TBool aDimmedIconCreatedByButton );
353 friend class CAknButton;
356 CGulIcon* iIcon; // bitmaps for normal state
357 CGulIcon* iDimmedIcon; // bitmaps for dimmed icon
358 CGulIcon* iPressedIcon; // bitmaps for pressed but not activated state
359 CGulIcon* iHoverIcon; // bitmaps for hover icon
360 HBufC* iText; // text for normal state
361 HBufC* iHelpText; // text which is shown as a help
362 TInt iFlags; // flags for the state
363 CAknButtonStateExtension* iExtension; // for future extensions
370 * Generic button class.
373 * @since Series 60 3.1
375 class CAknButton : public CAknControl
377 public: // Enumerations
381 ECenter, /* align center vertically or horizontally */
382 ETop, /* align to top vertically */
383 EBottom, /* align to bottom vertically */
384 ERight, /* align to right horizontally */
385 ELeft /* align to left horixontally */
388 enum TTooltipPosition
390 EPositionTop = 1, /* Tool tip alignment vertically to top */
391 EPositionBottom, /* Tool tip alignment vertically to bottom */
392 EPositionLeft, /* Tool tip alignment horizontally to left */
393 EPositionRight /* Tool tip alignment horizontally to right */
396 enum TTextAndIconAlignment
398 EIconBeforeText, /* Icon and text side by side Icon first */
399 EIconAfterText, /* Icon and text side by side Text first */
400 EIconUnderText, /* Icon and text one upon the other Icon under the text */
401 EIconOverText, /* Icon and text one upon the other Icon over the text */
402 EOverlay /* Icon and text overlaid */
407 ELongPressEvent = 100, /* Observer event for long press event */
408 ELongPressEndedEvent /* Observer event for long press ended event */
411 public: // Constructors and destructors
414 * Two-phased constructor.
415 * Constructs an empty button.
417 IMPORT_C static CAknButton* NewL();
420 * Two-phased constructor. Constructs an empty button.
422 IMPORT_C static CAknButton* NewLC();
425 * Two-phased constructor. Constructs the button from resources.
427 * @param aReader is the resource reader with which to access
428 * the control's resource values.
430 IMPORT_C static CAknButton* NewL( TResourceReader& aReader );
433 * Two-phased constructor. Constructs the button from resources.
435 * @param aReader is the resource reader with which to access
436 * the control's resource values.
438 IMPORT_C static CAknButton* NewLC( TResourceReader& aReader );
441 * Two-phased constructor. Constructs the button from resources.
443 * @param aResourceId is the ID for this component's resource.
445 IMPORT_C static CAknButton* NewL( const TInt aResourceId );
448 * Two-phased constructor. Constructs the button from resources.
450 * @param aResourceId is the ID for this component's resource.
452 IMPORT_C static CAknButton* NewLC( const TInt aResourceId );
455 * Two-phased constructor. Constructs one state button.
457 * @param aIcon The icon for the normal state. Takes ownership.
458 * @param aDimmedIcon The icon for the dimmed state. Takes ownership.
459 * @param aPressedIcon The icon for the pressed down. Takes ownership.
460 * @param aHoverIcon The icon for the hover state. Takes ownership.
461 * @param aText The text inside the button.
462 * @param aHelpText The text for the tooltip.
463 * @param aButtonFlags The flags for the button.
464 * @param aStateFlags The flags for the first state.
466 IMPORT_C static CAknButton* NewL( CGulIcon* aIcon,
467 CGulIcon* aDimmedIcon,
468 CGulIcon* aPressedIcon,
469 CGulIcon* aHoverIcon,
471 const TDesC& aHelpText,
472 const TInt aButtonFlags,
473 const TInt aStateFlags );
476 * Two-phased constructor. Constructs one state button.
478 * @param aIcon The icon for the normal state. Takes ownership.
479 * @param aDimmedIcon The icon for the dimmed state. Takes ownership.
480 * @param aPressedIcon The icon for the pressed down. Takes ownership.
481 * @param aHoverIcon The icon for the hover state. Takes ownership.
482 * @param aText The text inside the button.
483 * @param aHelpText The text for the tooltip.
484 * @param aButtonFlags The flags for the button.
485 * @param aStateFlags The flags for the first state.
487 IMPORT_C static CAknButton* NewLC( CGulIcon* aIcon,
488 CGulIcon* aDimmedIcon,
489 CGulIcon* aPressedIcon,
490 CGulIcon* aHoverIcon,
492 const TDesC& aHelpText,
494 const TInt aStateFlags );
497 * Two-phased constructor. Constructs one state button.
499 * @param aFilePath The path to the file which contains icons.
500 * @param aBmpId The bitmap ID for the normal state icon.
501 * @param aMaskId The mask ID for the normal state icon.
502 * @param aDimmedBmpId The bitmap ID for the dimmed state icon.
503 * @param aDimmedMaskId The mask ID for the dimmed state icon.
504 * @param aPressedBmpId The bitmap ID for the pressed down state.
505 * @param aPressedMaskId The mask ID for the pressed down state.
506 * @param aHoverBmpId The bitmap ID for the hover state.
507 * @param aHoverMaskId The mask ID for the hover state.
508 * @param aText The text inside the button.
509 * @param aHelpText The text for the tooltip.
510 * @param aButtonFlags The flags for the button.
511 * @param aStateFlags The flags for the first state.
512 * @param aId Item ID of the masked bitmap to be created for skin
514 * @param aDimmedId Item ID of the dimmed masked bitmap to be created
515 * for skin specific icon.
516 * @param aPressedId Item ID of the pressed masked bitmap to be created
517 * for skin specific icon.
518 * @param aHoverId Item ID of the masked hover bitmap to be created
519 * for skin specific icon.
521 IMPORT_C static CAknButton* NewL( const TDesC& aFilePath,
524 const TInt aDimmedBmpId,
525 const TInt aDimmedMaskId,
526 const TInt aPressedBmpId,
527 const TInt aPressedMaskId,
528 const TInt aHoverBmpId,
529 const TInt aHoverMaskId,
531 const TDesC& aHelpText,
532 const TInt aButtonFlags,
533 const TInt aStateFlags,
534 const TAknsItemID& aId = KAknsIIDNone,
535 const TAknsItemID& aDimmedId = KAknsIIDNone,
536 const TAknsItemID& aPressedId = KAknsIIDNone,
537 const TAknsItemID& aHoverId = KAknsIIDNone );
540 * Two-phased constructor. Constructs one state button.
542 * @param aFilePath The path to the file which contains icons.
543 * @param aBmpId The bitmap ID for the normal state icon.
544 * @param aMaskId The mask ID for the normal state icon.
545 * @param aDimmedBmpId The bitmap ID for the dimmed state icon.
546 * @param aDimmedMaskId The mask ID for the dimmed state icon.
547 * @param aPressedBmpId The bitmap ID for the pressed down state.
548 * @param aPressedMaskId The mask ID for the pressed down state.
549 * @param aHoverBmpId The bitmap ID for the hover state.
550 * @param aHoverMaskId The mask ID for the hover state.
551 * @param aText The text inside the button.
552 * @param aHelpText The text for the tooltip.
553 * @param aButtonFlags The flags for the button.
554 * @param aStateFlags The flags for the first state.
555 * @param aId Item ID of the masked bitmap to be created for skin
557 * @param aDimmedId Item ID of the dimmed masked bitmap to be created
558 * for skin specific icon.
559 * @param aPressedId Item ID of the pressed masked bitmap to be created
560 * for skin specific icon.
561 * @param aHoverId Item ID of the hover state masked bitmap to be
562 * created for skin specific icon.
564 IMPORT_C static CAknButton* NewLC( const TDesC& aFilePath,
567 const TInt aDimmedBmpId,
568 const TInt aDimmedMaskId,
569 const TInt aPressedBmpId,
570 const TInt aPressedMaskId,
571 const TInt aHoverBmpId,
572 const TInt aHoverMaskId,
574 const TDesC& aHelpText,
575 const TInt aButtonFlags,
576 const TInt aStateFlags,
577 const TAknsItemID& aId = KAknsIIDNone,
578 const TAknsItemID& aDimmedId = KAknsIIDNone,
579 const TAknsItemID& aPressedId = KAknsIIDNone,
580 const TAknsItemID& aHoverId = KAknsIIDNone );
585 IMPORT_C virtual ~CAknButton();
587 public: // Functions from base class
590 * Sets control as ready to be drawn.
592 IMPORT_C void ActivateL();
595 * Constructs controls from a resource file.
597 * @param aReader The resource reader, with which to access the
598 * control's resource values.
600 IMPORT_C void ConstructFromResourceL( TResourceReader& aReader );
603 * Handles a change to the control's resources.
605 * @param aType is a message UID value.
607 IMPORT_C void HandleResourceChange( TInt aType );
610 * Returns the control's minimum required size. It does not include the
611 * size of the highlight. However, it includes current margins.
612 * Use HighlightRect() function to get highlight rectangle for the
615 * @return The minimum size required by the control.
617 IMPORT_C TSize MinimumSize();
620 * Sets button dimmed. Does not redraw the button. Note: This function
621 * does not affect the flag set with function CCoeControl::SetDimmed(),
622 * since button needs to get pointer events, even if it is dimmed.
623 * The value of the flag can be enquired using CAknButotn::IsDimmed().
625 * @param aDimmed is ETrue to dim the button, EFalse to set the button
628 IMPORT_C void SetDimmed( TBool aDimmed );
631 * Handles key events.
633 * @param aKeyEvent The key event.
634 * @param aType The type of key event: EEventKey, EEventKeyUp or
637 IMPORT_C TKeyResponse OfferKeyEventL( const TKeyEvent& aKeyEvent,
641 * Sets this control as visible or invisible.
643 * @param aVisible ETrue to make the control visible, EFalse to make
646 IMPORT_C void MakeVisible( TBool aVisible );
649 * This function is called by the dialog framework immediately before
650 * it removes keyboard focus from a control within a dialog.
651 * Currently has empty implementation.
653 IMPORT_C void PrepareForFocusLossL();
656 * Prepares the control for gaining focus.
657 * Must be used before calling SetFocus() function in case when help
658 * note should be shown.
660 IMPORT_C void PrepareForFocusGainL();
663 * Handles pointer events.
665 * @param aPointerEvent The pointer event.
667 IMPORT_C void HandlePointerEventL( const TPointerEvent& aPointerEvent );
670 * Responds to changes in the position of a control.
672 IMPORT_C virtual void PositionChanged();
674 public: // New functions
677 * Constructs controls from a resource file.
679 * @param aResourceId The ID for this component's resource.
681 IMPORT_C void ConstructFromResourceL( const TInt aResourceId );
686 * @param aStateIndex The index for the state, starts from 0.
687 * @param aDrawNow ETrue to redraw the button.
689 IMPORT_C virtual void SetCurrentState( const TInt aStateIndex,
690 const TBool aDrawNow );
693 * Adds one more state for the button to the end of state array.
695 * @param aIcon The icon object containing a bitmap and a mask (if
696 * there is one) for the button.
697 * @param aDimmedIcon The icon object containing a bitmap and a mask
698 * (if there is one) for the dimmed case.
699 * @param aPressedIcon The icon object containing a bitmap and a mask
700 * (if there is one) for the case when button is pressed.
701 * @param aHoverIcon The icon object containingg a bitmap and a mask
702 * for the case when the pointer is hovering over the button.
703 * @param aText is the text.
704 * @param aHelpText is the text for the tooltip.
705 * @param aStateFlags The flags for the state.
707 IMPORT_C virtual void AddStateL( CGulIcon* aIcon,
708 CGulIcon* aDimmedIcon,
709 CGulIcon* aPressedIcon,
710 CGulIcon* aHoverIcon,
712 const TDesC& aHelpText,
713 const TInt aStateFlags );
716 * Adds one more state for the button.
718 * @param aFilePath The path to the file which contains icons.
719 * @param aBmpId The bitmap ID for the normal state icon.
720 * @param aMaskId The mask ID for the normal state icon.
721 * @param aDimmedBmpId The bitmap ID for the dimmed state icon.
722 * @param aDimmedMaskId The mask ID for the dimmed state icon.
723 * @param aPressedBmpId The bitmap ID for the pressed down state.
724 * @param aPressedMaskId The mask ID for the pressed down state.
725 * @param aHoverBmpId The bitmap ID for the hover state.
726 * @param aHoverMaskId The mask ID for the hover state.
727 * @param aHoverId Item ID of the hover state masked bitmap to be
728 * created for skin specific icon.
729 * @param aText is the text.
730 * @param aHelpText is the text for the tooltip.
731 * @param aStateFlags The flags for the state.
732 * @param aId Item ID of the masked bitmap to be created for skin
733 * specific icon. Use KAknsIIDNone when it is not needed.
734 * @param aDimmedId Item ID of the dimmed masked bitmap to be created
735 * for skin specific icon. Use KAknsIIDNone when it is not needed.
736 * @param aPressedId Item ID of the pressed masked bitmap to be created
737 * for skin specific icon. Use KAknsIIDNone when it is not needed.
738 * @param aHoverId Item ID of the hover state masked bitmap to be
739 * created for skin specific icon.
741 IMPORT_C virtual void AddStateL( const TDesC& aFilePath,
744 const TInt aDimmedBmpId,
745 const TInt aDimmedMaskId,
746 const TInt aPressedBmpId,
747 const TInt aPressedMaskId,
748 const TInt aHoverBmpId,
749 const TInt aHoverMaskId,
751 const TDesC& aHelpText,
752 const TInt aStateFlags,
753 const TAknsItemID& aId,
754 const TAknsItemID& aDimmedId,
755 const TAknsItemID& aPressedId,
756 const TAknsItemID& aHoverId );
759 * Adds one more state for the button to the end of state array.
761 * @param aIcon The icon object containing a bitmap and
762 * a mask (if there is one) for the button.
763 * @param aDimmedIcon The icon object containing a bitmap and a mask
764 * (if there is one) for the dimmed case.
765 * @param aPressedIcon The icon object containing a bitmap and a mask
766 * (if there is one) for the case when
768 * @param aHoverIcon The icon object containingg a bitmap and
769 * a mask for the case when the pointer is
770 * hovering over the button.
771 * @param aText is the text.
772 * @param aHelpText is the text for the tooltip.
773 * @param aStateFlags The flags for the state.
774 * @param aCommandId Command to be attached with the state.
776 void AddStateL( CGulIcon* aIcon,
777 CGulIcon* aDimmedIcon,
778 CGulIcon* aPressedIcon,
779 CGulIcon* aHoverIcon,
781 const TDesC& aHelpText,
782 const TInt aStateFlags,
783 const TInt aCommandId );
786 * Sets the button flags.
788 * @param aFlags which can be combination of: KAknButtonTextLeft,
789 * KAknButtonSizeFitText, KAknButtonNoFrame, KAknButtonKeyRepeat,
790 * KAknButtonReportOnKeyDown, KAknButtonNoFramePressEvent,
791 * KAknButtonRequestExitOnButtonUpEvent, KAknButtonReportOnLongPress.
793 IMPORT_C void SetButtonFlags( const TInt aFlags );
796 * Sets specified frame IDs. Can be used when default frame is not
797 * suitable. Use KAknsIIDNone value in case when some frame or center
798 * drawing is not needed or KAknsIIDDefault when the default button
799 * frame should be used.
801 * @param aFrameId The item ID of the entire frame.
802 * @param aCenterId The item ID of the center part of the frame.
803 * @param aLatchedFrameId The item ID of the entire frame for button
805 * @param aLatchedCenterId The item ID of the center part of the
806 * frame for button in latched state.
807 * @param aDimmedFrameId The item ID of the entire frame for a button
809 * @param aDimmedCenterId The item ID of the center part of the frame
810 * for a button in dimmed state.
811 * @param aPressedFrameId The item ID of the entire frame for a
812 * button in pressed state.
813 * @param aPressedCenterId is the item ID of the center part of the
814 * frame for a button in pressed state.
815 * @param aLatchedDimmedFrameId The item ID of the entire frame for
816 * a button in latched and dimmed state.
817 * @param aLatchedDimmedCenterId The item ID of the center part of
818 * the frame for a button in latched and dimmed state.
820 IMPORT_C void SetFrameAndCenterIds( const TAknsItemID& aFrameId,
821 const TAknsItemID& aCenterId,
822 const TAknsItemID& aLatchedFrameId,
823 const TAknsItemID& aLatchedCenterId,
824 const TAknsItemID& aDimmedFrameId,
825 const TAknsItemID& aDimmedCenterId,
826 const TAknsItemID& aPressedFrameId,
827 const TAknsItemID& aPressedCenterId,
828 const TAknsItemID& aLatchedDimmedFrameId,
829 const TAknsItemID& aLatchedDimmedCenterId );
832 * Sets specified background IDs. Can be used when default frame is not
833 * suitable and the backgound is composed of only single image instead
834 * of frame and center. SetFrameAndCenterIds() function can also be used
835 * for this purpose by giving the same backround ID for both frame and
836 * center. This allows also some of the states to be composed of frames
837 * and the others from single backgound images. Use KAknsIIDNone value
838 * in case when some backgound drawing is not needed or KAknsIIDDefault
839 * when the default button frame should be used.
841 * @param aBackgroundId The item ID of the entire frame.
842 * @param aLatchedBackgroundId The item ID of the background for the
843 * button in latched state.
844 * @param aDimmedBackgroundId The item ID of the background for the
845 * button in dimmed state.
846 * @param aPressedBackgroundId The item ID of the background for the
847 * button in pressed state.
848 * @param aLatchedDimmedBackgroundId The item ID of the background for
849 * the button in latched and dimmed state.
851 IMPORT_C void SetBackgroundIds( const TAknsItemID& aBackgroundId,
852 const TAknsItemID& aLatchedBackgroundId,
853 const TAknsItemID& aDimmedBackgroundId,
854 const TAknsItemID& aPressedBackgroundId,
855 const TAknsItemID& aLatchedDimmedBackgroundId );
858 * Sets some specific text font.
860 * @param aFont The font, which should be used for the text inside the
863 IMPORT_C void SetTextFont( const CFont* aFont );
866 * Sets the color table and color index for the button text. It will be
867 * used on button drawing, if color of the text shouldn't be taken from
870 * @param aTextColorTableId Id for the color table
871 * @param aTextColorIndex Index of the color inside color table.
873 IMPORT_C void SetTextColorIds( const TAknsItemID& aTextColorTableId,
874 const TInt aTextColorIndex );
877 * Sets the horizontal alignment for the text inside the button. It
878 * will be used, if alignment shouldn't be taken from text layout. By
879 * default it will be centered.
881 * @param aHorizontalAlignment The horizontal alignment for the text.
883 IMPORT_C void SetTextHorizontalAlignment(
884 const CGraphicsContext::TTextAlign aHorizontalAlignment );
887 * Sets the vertical alignment for the text inside the button. It will
888 * be used if alignment shouldn't be taken from text layout. By default
889 * it will be centered.
891 * @param aVerticalAlignment The vertical alignment for the text.
893 IMPORT_C void SetTextVerticalAlignment(
894 const CAknButton::TAlignment aVerticalAlignment );
897 * Sets the icon and text alignment for a button having both
899 * @param aAlignment. TTextAndIconAlignment
901 IMPORT_C void SetTextAndIconAlignment(
902 const CAknButton::TTextAndIconAlignment aAlignment );
905 * Sets the text underline style for the text inside the button. By
906 * default no underline is used.
908 * @param aUnderlineStyle The style of underline.
910 IMPORT_C void SetTextUnderlineStyle( TFontUnderline aUnderlineStyle );
913 * Sets the scale mode for the icon inside the button.
914 * The default is EAspectRatioNotPreserved.
916 * @param aScaleMode The scale mode.
918 IMPORT_C void SetIconScaleMode( const TScaleMode aScaleMode );
921 * Sets the horizontal alignment for the icon inside the button.
922 * By default it will be centered.
924 * @param aHorizontalAlignment The horizontal alignment for the icon.
926 IMPORT_C void SetIconHorizontalAlignment(
927 const CAknButton::TAlignment aHorizontalAlignment );
930 * Sets the vertical alignment for the icon inside the button.
931 * By default it will be centered.
933 * @param aVerticalAlignment The vertical alignment for the icon.
935 IMPORT_C void SetIconVerticalAlignment(
936 const CAknButton::TAlignment aVerticalAlignment );
939 * Sets the delay before the help text is shown and also specifies the
940 * time for how long help text is visible.
942 * @param aBeforeTimeout The delay in milliseconds before text help note
943 * is shown. The default is 150 milliseconds.
944 * @param aInViewTimeout The interval in milliseconds during which help
945 * text note is shown. The default is 3000 milliseconds.
947 IMPORT_C void SetHelpNoteTimeouts( const TInt aBeforeTimeout,
948 const TInt aInViewTimeout );
951 * Sets the interval for key repeat.
953 * @param aKeyRepeatDelay The initial delay, after which the key repeat is
954 started. The default is 500 milliseconds.
955 * @param aKeyRepeatInterval The interval in milliseconds, in which key
956 * repeat events should be reported. The default is 500 milliseconds.
958 IMPORT_C void SetKeyRepeatInterval( const TInt aKeyRepeatDelay,
959 const TInt aKeyRepeatInterval );
962 * Sets the interval for long press. When KAknButtonReportOnLongPress
963 * flag is set for the button, button will notify observer with
964 * KAknButtonLongPressEvent as the event type, after button has been
965 * pressed for the specified time.
967 * @param aLongPressInterval The time interval in milliseconds, after
968 * which the long press event should be reported. The default
969 * value is 800 milliseconds.
971 IMPORT_C void SetLongPressInterval( const TInt aLongPressInterval );
974 * Returns the index of the button state.
976 IMPORT_C TInt StateIndex() const;
979 * Enables pictograph drawing in the button text.
980 * Only effective in Japanese variant.
981 * By default, it is disabled.
983 * @param aInterface Used pictograph interface owned by the caller.
985 IMPORT_C void EnablePictographsL( CAknPictographInterface& aInterface );
988 * Disables pictograph drawing in the button text.
989 * Only effective in Japanese variant.
990 * By default, it is disabled.
992 IMPORT_C void DisablePictographs();
995 * It will change the default highlight rectangle around
996 * the focused button.
998 * @param aRect The highlight rectangle.
1000 IMPORT_C void SetHighlightRect( const TRect& aRect );
1003 * Gets the highlight rectangle around the button.
1005 * @return The higlight rectangle around the button.
1007 IMPORT_C TRect HighlightRect() const;
1010 * Sets the tooltip position.
1012 * @param aPosition The position of the tooltip.
1014 IMPORT_C void SetTooltipPosition( const TTooltipPosition aPosition );
1017 * Sets whether button should send an EEventRequestExit event to command
1018 * observer on button up event.
1020 * @param aRequestExit ETrue if button should request exit.
1022 IMPORT_C void SetRequestExit( const TBool aRequestExit );
1025 * Tests if the control is dimmed. This function overrides the function
1026 * declared in CCoeControl, and returns the value which is set and unset
1027 * using CAknButton::SetDimmed().
1029 * @return ETrue if the control is dimmed, EFalse if it is not dimmed.
1031 IMPORT_C TBool IsDimmed() const;
1034 * Sets the help text for dimmed button.
1036 * @param aHelpText The text inside the tooltip.
1038 IMPORT_C void SetDimmedHelpTextL( const TDesC& aHelpText );
1041 * Check if point is within buttons visible area, when
1042 * KAknButtonHitTest flag is enabled
1044 * @param aPoint Location to check.
1045 * @param aCheckHitArea if need to check the hit area for fixed
1048 TBool HitAreaContainsL( const TPoint& aPoint, TBool aCheckHitArea ) const;
1051 * Returns the current state of the button.
1053 * @return the current state of the button
1055 IMPORT_C CAknButtonState* State() const;
1058 * Returns the state of the button under specified index.
1060 * @param aStateIndex The index for the state.
1061 * @return the state of the button.
1063 IMPORT_C CAknButtonState* State( const TInt aStateIndex ) const;
1066 * Returns the flags of button. The flags are defined in eikon.hrh.
1067 * @return Button flags.
1070 IMPORT_C TInt ButtonFlags() const;
1073 * Sets button's margins. These define the free area inside the button
1074 * where content is placed. Note that calling this function overrides
1075 * default margins that are scaled automatically depending on the
1076 * current screen layout. If this function is called then the caller
1077 * is responsible for updating margins whenever the layout changes.
1080 * @param aMargins New marginals.
1082 IMPORT_C void SetMargins( const TMargins8& aMargins );
1085 * Sets icon size for the button. Calling this function overrides the
1086 * default size that is scaled automatically depending on the current
1087 * screen layout. If this function is called then the caller is
1088 * responsible for updating icon size whenever the layout changes.
1091 * @param aSize New icon size.
1092 * @return KErrNone if the operation succeeded, otherwise an error code.
1094 IMPORT_C TInt SetIconSize( const TSize& aSize );
1097 * Checks if the button uses default margins.
1101 * @return ETrue if default margins are used.
1103 TBool UsesDefaultMargins() const;
1106 * Sets tooltip to hide or show itself when background faded.
1109 * @param aHide should be ETrue if hiding, EFalse if showing
1111 void HideTooltipWhenAppFaded( TBool aHide );
1116 void CheckHitArea();
1119 * Resets button to unpressed state.
1123 IMPORT_C void ResetState();
1126 * Sets button to use additional masks during drawing. Calling this
1127 * method forces button to bypass the normal drawing routine i.e.
1128 * method DrawMaskedL is executed instead of Draw.
1131 * @param aMaskedDraw ETrue to use additional mask.
1133 void UseMaskedDraw( TBool aMaskedDraw );
1136 * Registers resource provider.
1137 * @param aProvider New resource provider.
1139 void RegisterResourceProvider( CAknResourceProvider* aProvider );
1142 * Unregisters resource provider.
1144 void UnregisterResourceProvider();
1146 CAknsFrameBackgroundControlContext* BgContext();
1149 * Removes the currently active state from the button,
1150 * and sets the current state to the previous one.
1152 void RemoveCurrentState();
1155 * Returns the button touchable area.
1158 * @return Button touch area
1160 TRect TouchArea() const;
1162 protected: // Constructors
1165 * C++ constructor for the one state button.
1167 * @param aFlags The flags for the button
1169 IMPORT_C CAknButton( const TInt aFlags );
1172 * Symbian 2nd phase constructor.
1174 IMPORT_C void ConstructL();
1177 * Symbian 2nd phase constructor.
1179 * @param aIcon The icon for the normal state. Takes ownership.
1180 * @param aDimmedIcon The icon for the dimmed state. Takes ownership.
1181 * @param aPressedIcon The icon for the pressed down. Takes ownership.
1182 * @param aHoverIcon The icon for the hover state.
1183 * @param aText The text inside the button.
1184 * @param aHelpText The text for the tooltip.
1185 * @param aStateFlags The flags for the first state.
1187 IMPORT_C void ConstructL( CGulIcon* aIcon,
1188 CGulIcon* aDimmedIcon,
1189 CGulIcon* aPressedIcon,
1190 CGulIcon* aHoverIcon,
1192 const TDesC& aHelpText,
1193 const TInt aStateFlags );
1196 * Symbian 2nd phase constructor.
1198 * @param aFilePath The path to the file which contains icons.
1199 * @param aBmpId The bitmap ID for the normal state icon.
1200 * @param aMaskId The mask ID for the normal state icon.
1201 * @param aDimmedBmpId The bitmap ID for the dimmed state icon.
1202 * @param aDimmedMaskId The mask ID for the dimmed state icon.
1203 * @param aPressedBmpId The bitmap ID for the pressed down state.
1204 * @param aPressedMaskId The mask ID for the pressed down state.
1205 * @param aHoverBmpId The bitmap ID for the hover state icon.
1206 * @param aHoverMaskId The mask ID for the hover state icon.
1207 * @param aText The text inside the button.
1208 * @param aHelpText The text for the tooltip.
1209 * @param aStateFlags The flags for the first state.
1210 * @param aId Item ID of the masked bitmap to be created for skin
1212 * @param aDimmedId Item ID of the dimmed masked bitmap to be created
1213 * for skin specific icon.
1214 * @param aPressedId Item ID of the pressed masked bitmap to be created
1215 * for skin specific icon.
1216 * @param aHoverId Item ID of the masked hover bitmap to be created
1217 * for skin specific icon.
1219 IMPORT_C void ConstructL( const TDesC& aFilePath,
1222 const TInt aDimmedBmpId,
1223 const TInt aDimmedMaskId,
1224 const TInt aPressedBmpId,
1225 const TInt aPressedMaskId,
1226 const TInt aHoverBmpId,
1227 const TInt aHoverMaskId,
1229 const TDesC& aHelpText,
1230 const TInt aStateFlags,
1231 const TAknsItemID& aId = KAknsIIDNone,
1232 const TAknsItemID& aDimmedId = KAknsIIDNone,
1233 const TAknsItemID& aPressedId = KAknsIIDNone,
1234 const TAknsItemID& aHoverId = KAknsIIDNone );
1236 protected: // Functions from base class
1239 * Responds to size changes to sets the size and position of the
1240 * contents of this control.
1242 IMPORT_C void SizeChanged();
1245 * This function is called whenever a control gains or loses focus.
1247 * @param aDrawNow Contains the value that was passed to it by SetFocus().
1249 IMPORT_C void FocusChanged( TDrawNow aDrawNow );
1252 * For future extensions
1254 * @param aInterface The ID for the extension interface.
1256 IMPORT_C void* ExtensionInterface( TUid aInterface );
1258 protected: // New functions
1261 * Changes the state of the button to the next one.
1263 * @return the current state index
1265 IMPORT_C TInt ChangeState( TBool aDrawNow );
1268 * Returns the text, which will be displayed inside the button
1269 * for the current state.
1271 IMPORT_C const TDesC& GetCurrentText() const;
1274 * Returns icon for the current state.
1276 IMPORT_C const CGulIcon* GetCurrentIcon() const;
1279 * Shows help text for a certain period of time.
1281 IMPORT_C void ShowHelpL();
1284 * Hides help text after certain interval.
1286 IMPORT_C void HideHelp();
1289 private: // Functions from base class
1292 * From CCoeControl. Draws the control. Called by window server.
1294 IMPORT_C void Draw( const TRect& aRect ) const;
1296 private: // New functions
1299 * Continues drawing of the button which has only text.
1301 void DrawTextButton( CWindowGc& aGc ) const;
1304 * Continues drawing of the button which has only an icon in it.
1306 void DrawIconButton( CWindowGc& aGc ) const;
1309 * Continues drawing of the button which has both text and icon.
1311 void DrawTextAndIconButton( CWindowGc& aGc ) const;
1314 * Draws a button with additional mask.
1316 void DrawMaskedL( CWindowGc& aGc ) const;
1319 * Starts the long press timer.
1321 void StartLongPressTimerL();
1324 * Stops the long press timer.
1326 void StopLongPressTimer();
1329 * Starts the timer for the key repeat.
1331 void StartKeyRepeatTimerL();
1334 * Stops the key repeat timer.
1336 void StopKeyRepeatTimer();
1339 * Called after timeout is over.
1341 static TInt ReportKeyRepeatL( TAny* aThis );
1344 * Asserts that extension class object exists.
1346 * @return Extension object.
1348 CAknButtonExtension* Extension() const;
1351 * Updates tooltip position.
1353 void UpdateTooltipPosition();
1356 * Checks whether toolbar should send an EEventRequestExit event to
1357 * command observe on button up event.
1359 * @return ETrue if event should be sent, EFalse otherwise.
1361 TBool RequestExit() const;
1364 * Gets the rectangele reserved for button content excluding frame.
1366 * @return Content rectangle.
1368 TRect ContentRect() const;
1371 * Checks whether button needs redrawing when it is pressed or released.
1373 * @return ETrue, if redraw is needed, othewise EFalse.
1375 TBool NeedsRedrawWhenPressed() const;
1378 * Returns the ID of specified skin item.
1380 TAknsItemID SkinIID( const TInt aIndex ) const;
1383 * Calculates default margins.
1385 void CalculateDefaultMargins();
1390 * @return KErrNone or an error code.
1395 * Gets the correct text color.
1397 * @return Text color.
1399 TRgb TextColor() const;
1402 * Generates the pressed down bitmaps
1403 * if flag KAknButtonPressedDownFrame is set and button has no frame
1405 void CreatePressedDownFrameL();
1408 * Calculates color's luminance.
1410 TInt CalculateLuminance( const TRgb& aColor ) const;
1413 * Converts outline color, if fill color is too similar to outline color
1415 * @aFillColor fill color
1416 * @aOutlineColor outline color
1418 void ConvertColorsForOutlineEffect( TRgb& aFillColor, TRgb& aOutlineColor ) const;
1423 * @aPenColor pen color
1424 * @aBrushColor brush color
1426 void GetTextColors( TRgb& aPenColor, TRgb& aBrushColor ) const;
1429 * Sets new state index
1431 * @param aNewIndex New state index
1433 void SetStateIndexL( TInt aNewIndex );
1437 // array to keep states
1438 CArrayPtrFlat<CAknButtonState>* iStates;
1443 // current button state index
1446 // flag to define whether the button is pressed
1447 TBool iButtonPressed;
1449 // number of drag events, needed to distinguish when it is outside
1451 TInt iNumberOfDragEvents;
1453 // Flag which shows whether key down event was reported before key up
1454 // event was sent to the button, because some controls consume key down
1455 // but don't consume key up events which might cause of button state
1456 // when it is not expected
1457 TBool iKeyDownReported;
1459 // Background control context for button's frame
1460 CAknsFrameBackgroundControlContext* iBgContext;
1462 // Customized highlight rectangular around the button if the default one
1464 TRect iHighlightRect;
1466 // text button specific data
1467 const CFont* iFont; // font for the text inside the button
1468 TAlignment iVerticalAlignment; // vertical alignment for the text. Centered by default
1469 CGraphicsContext::TTextAlign iHorizontalAlignment; // horizontal alignment for the text. Centered by default
1470 TAknsItemID iTextColorTableId; // id for the color table
1471 TInt iTextColorIndex; // index of the color in color table
1473 // icon button specific data
1474 TScaleMode iScaleMode; // scale mode for the icon, by default it is EAspectRatioNotPreserved
1476 // tooltip specific data
1477 TInt iHelpNoteWaitInterval; // interval in milliseconds between the time when the button got focused and the help text is shown
1478 TInt iHelpNoteInViewInterval; // interval during which help text is shown in milliseconds
1479 CAknInfoPopupNoteController* iHelpNote; // component to show help text
1480 HBufC* iDimmedHelpText; // help text in case if the button is dimmed, not used currently
1481 TBool iShowHelp; // flag which specifies whether help note should be shown
1483 // Key repeat handling
1484 CPeriodic* iKeyRepeatTimer; // timer to report key repeats
1485 TInt iKeyRepeatDelay; // initial delay for key repeats
1486 TInt iKeyRepeatInterval; // time interval for key repeats
1489 CAknButtonExtension* iExtension;
1494 #endif // __AKNBUTTON_H__