uifw/EikStd/coctlsrc/AknButton.cpp
branchRCL_3
changeset 56 d48ab3b357f1
parent 55 aecbbf00d063
child 59 978afdc0236f
equal deleted inserted replaced
55:aecbbf00d063 56:d48ab3b357f1
     1 /*
     1 /*
     2 * Copyright (c) 2005-2008 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
   262     // Fetches bitmaps from resource provider (if one exists)
   262     // Fetches bitmaps from resource provider (if one exists)
   263     TBool FetchProviderPressedBmpsL();
   263     TBool FetchProviderPressedBmpsL();
   264 
   264 
   265     // Sets bitmaps to resource provider (if one exists)
   265     // Sets bitmaps to resource provider (if one exists)
   266     void SetProviderPressedBmpsL();
   266     void SetProviderPressedBmpsL();
   267 
   267     
       
   268     //Verify new rectagle size equals to the original
       
   269     TBool TextRectSizeChanged( TRect aNewRect );
       
   270    
   268 private: // Data
   271 private: // Data
   269 
   272 
   270     CAknButton& iButton;
   273     CAknButton& iButton;
   271     CAknButton::TTooltipPosition iTooltipPosition;
   274     CAknButton::TTooltipPosition iTooltipPosition;
   272     CAknPictographInterface* iPictographInterface; // not owned
   275     CAknPictographInterface* iPictographInterface; // not owned
   282     TBitFlags iFlags;
   285     TBitFlags iFlags;
   283     MTouchFeedback* iFeedback;
   286     MTouchFeedback* iFeedback;
   284     CFbsBitmap* iPressedDownBmp;
   287     CFbsBitmap* iPressedDownBmp;
   285     CFbsBitmap* iPressedDownBmpMask;
   288     CFbsBitmap* iPressedDownBmpMask;
   286     CAknResourceProvider* iResourceProvider;
   289     CAknResourceProvider* iResourceProvider;
       
   290     
       
   291     //Previous touch down or drag position, valid only with pressed state. 
       
   292     TPoint iPrePointerPos;
       
   293     CAknsFrameBackgroundControlContext* iHighlightContext;  
       
   294     // buffer for visually ordered text
       
   295     TBuf<255 + KAknBidiExtraSpacePerLine> iVisualText; 
       
   296     TBool iFeedbackEnabled;
       
   297     TAknsItemID iBackgroundSkinIID;
       
   298     TRect iBgFrameRect;
       
   299     TRect iTextRect;
   287     };
   300     };
   288 
   301 
   289 // ============================ MEMBER FUNCTIONS ===============================
   302 // ============================ MEMBER FUNCTIONS ===============================
   290 
   303 
   291 // -----------------------------------------------------------------------------
   304 // -----------------------------------------------------------------------------
   301       iUnderlineStyle( EUnderlineOff ),
   314       iUnderlineStyle( EUnderlineOff ),
   302       iFrameAndCenterIds( 2 ),
   315       iFrameAndCenterIds( 2 ),
   303       iVerticalIconAlignment( CAknButton::ECenter ),
   316       iVerticalIconAlignment( CAknButton::ECenter ),
   304       iHorizontalIconAlignment( CAknButton::ECenter ),
   317       iHorizontalIconAlignment( CAknButton::ECenter ),
   305       iTextAndIconAlignment( CAknButton::EIconBeforeText ),
   318       iTextAndIconAlignment( CAknButton::EIconBeforeText ),
   306       iResourceProvider( 0 )
   319       iResourceProvider( 0 ),
       
   320       iFeedbackEnabled( ETrue )
   307     {
   321     {
   308     // default margins, these are applied to both text and icon
   322     // default margins, these are applied to both text and icon
   309     iMargins.SetAllValuesTo( 
   323     iMargins.SetAllValuesTo( 
   310         AknLayoutScalable_Avkon::aid_value_unit2().LayoutLine().iW / 10 );
   324         AknLayoutScalable_Avkon::aid_value_unit2().LayoutLine().iW / 10 );
   311         
   325         
   315     layoutRect.LayoutRect( rect, 
   329     layoutRect.LayoutRect( rect, 
   316         AknLayoutScalable_Avkon::toolbar_button_pane_g10().LayoutLine() );
   330         AknLayoutScalable_Avkon::toolbar_button_pane_g10().LayoutLine() );
   317     iIconSize = layoutRect.Rect().Size();
   331     iIconSize = layoutRect.Rect().Size();
   318     iFlags.Set( EUseDefaultIconSize );
   332     iFlags.Set( EUseDefaultIconSize );
   319     iFlags.Set( EUseDefaultMargins );
   333     iFlags.Set( EUseDefaultMargins );
       
   334     iTextRect = TRect::EUninitialized;
   320     }
   335     }
   321 
   336 
   322 // -----------------------------------------------------------------------------
   337 // -----------------------------------------------------------------------------
   323 // CAknButtonExtension::~CAknButtonExtension
   338 // CAknButtonExtension::~CAknButtonExtension
   324 // Destructor.
   339 // Destructor.
   328     {
   343     {
   329     delete iLongPressTimer;
   344     delete iLongPressTimer;
   330     iPictographInterface = NULL; // not owned
   345     iPictographInterface = NULL; // not owned
   331     iFrameAndCenterIds.Close();
   346     iFrameAndCenterIds.Close();
   332     DeletePressedBmps();
   347     DeletePressedBmps();
       
   348     delete iHighlightContext; 
   333     }
   349     }
   334 
   350 
   335 // -----------------------------------------------------------------------------
   351 // -----------------------------------------------------------------------------
   336 // CAknButtonExtension::NewL
   352 // CAknButtonExtension::NewL
   337 // Symbian two-phased constructor.
   353 // Symbian two-phased constructor.
   366     iFrameAndCenterIds.AppendL( KAknsIIDQsnFrButtonPressed );
   382     iFrameAndCenterIds.AppendL( KAknsIIDQsnFrButtonPressed );
   367     iFrameAndCenterIds.AppendL( KAknsIIDQsnFrButtonCenterPressed );
   383     iFrameAndCenterIds.AppendL( KAknsIIDQsnFrButtonCenterPressed );
   368     // Latched dimmed frame and center
   384     // Latched dimmed frame and center
   369     iFrameAndCenterIds.AppendL( KAknsIIDQsnFrButtonInactive );
   385     iFrameAndCenterIds.AppendL( KAknsIIDQsnFrButtonInactive );
   370     iFrameAndCenterIds.AppendL( KAknsIIDQsnFrButtonCenterInactive );
   386     iFrameAndCenterIds.AppendL( KAknsIIDQsnFrButtonCenterInactive );
       
   387     if ( !iHighlightContext )
       
   388         {
       
   389         iHighlightContext = CAknsFrameBackgroundControlContext::NewL(
       
   390             KAknsIIDNone, TRect(), TRect(), EFalse );
       
   391         iHighlightContext->SetFrame( KAknsIIDQsnFrButtonHighlight ); 
       
   392         iHighlightContext->SetCenter( KAknsIIDQsnFrButtonHighlightCenter ); 
       
   393         }
   371     }
   394     }
   372 
   395 
   373 // -----------------------------------------------------------------------------
   396 // -----------------------------------------------------------------------------
   374 // CAknButtonExtension::StartLongPressTimerL
   397 // CAknButtonExtension::StartLongPressTimerL
   375 // Starts the long press timer. The timer is constructed when used for the
   398 // Starts the long press timer. The timer is constructed when used for the
   497             KPressedFrameId, 
   520             KPressedFrameId, 
   498             static_cast<MAknResourceItem*>( resourceItem ) );
   521             static_cast<MAknResourceItem*>( resourceItem ) );
   499         }
   522         }
   500     }
   523     }
   501     
   524     
       
   525 //Verify new rectangle size equals to the original
       
   526 TBool CAknButtonExtension::TextRectSizeChanged( TRect aNewRect )
       
   527     {
       
   528     TBool result( ETrue );
       
   529     if ( !iTextRect.IsEmpty() && !aNewRect.IsEmpty() )
       
   530         {
       
   531         if ( iTextRect.Width() == aNewRect.Width() 
       
   532                 && iTextRect.Height() == aNewRect.Height() )
       
   533             {
       
   534             result = EFalse;
       
   535             }
       
   536         }
       
   537     return result;
       
   538     }
   502     
   539     
   503 
   540 
   504 //
   541 //
   505 TBool CAknButtonExtension::HitRegionContains( const TPoint &aPoint, 
   542 TBool CAknButtonExtension::HitRegionContains( const TPoint &aPoint, 
   506     const CCoeControl& /*aControl*/ ) const
   543     const CCoeControl& /*aControl*/ ) const
   512     return retval;
   549     return retval;
   513     }
   550     }
   514 
   551 
   515 void CAknButtonExtension::HandleFeedbackAreaChange()
   552 void CAknButtonExtension::HandleFeedbackAreaChange()
   516     {
   553     {
       
   554     if ( !iFeedbackEnabled )
       
   555         {
       
   556         return; 
       
   557         }
   517     // it is possible that feedback does not exist, eg. while booting.
   558     // it is possible that feedback does not exist, eg. while booting.
   518     // try getting one, and give up if that fails.
   559     // try getting one, and give up if that fails.
   519     if ( !iFeedback )
   560     if ( !iFeedback )
   520         {
   561         {
   521         iFeedback = MTouchFeedback::Instance();
   562         iFeedback = MTouchFeedback::Instance();
   577     TAknsItemID iId;
   618     TAknsItemID iId;
   578     TAknsItemID iDimmedId;
   619     TAknsItemID iDimmedId;
   579     TAknsItemID iPressedId;
   620     TAknsItemID iPressedId;
   580     TAknsItemID iHoverId;
   621     TAknsItemID iHoverId;
   581     TScaleMode iScaleMode;
   622     TScaleMode iScaleMode;
       
   623     TBool iFlagsChanged; 
       
   624     TBool iTextChanged; 
   582     };
   625     };
   583 
   626 
   584 // ============================ MEMBER FUNCTIONS ===============================
   627 // ============================ MEMBER FUNCTIONS ===============================
   585 
   628 
   586 // -----------------------------------------------------------------------------
   629 // -----------------------------------------------------------------------------
   989     {
  1032     {
   990     delete iText;
  1033     delete iText;
   991     iText = NULL;
  1034     iText = NULL;
   992 
  1035 
   993     iText = aText.AllocL();
  1036     iText = aText.AllocL();
       
  1037     iExtension->iTextChanged = ETrue; 
   994     }
  1038     }
   995 
  1039 
   996 // -----------------------------------------------------------------------------
  1040 // -----------------------------------------------------------------------------
   997 // CAknButtonState::SetHelpTextL
  1041 // CAknButtonState::SetHelpTextL
   998 // Sets the text inside the help note
  1042 // Sets the text inside the help note
  1011 // Sets state flags.
  1055 // Sets state flags.
  1012 // -----------------------------------------------------------------------------
  1056 // -----------------------------------------------------------------------------
  1013 //
  1057 //
  1014 EXPORT_C void CAknButtonState::SetFlags( const TInt aFlags )
  1058 EXPORT_C void CAknButtonState::SetFlags( const TInt aFlags )
  1015     {
  1059     {
       
  1060     if ( ( iFlags & KAknButtonStateHasLatchedFrame ) != 
       
  1061         ( aFlags & KAknButtonStateHasLatchedFrame ) )
       
  1062         {
       
  1063         iExtension->iFlagsChanged = ETrue; 
       
  1064         }
  1016     iFlags = aFlags;
  1065     iFlags = aFlags;
  1017     }
  1066     }
  1018 
  1067 
  1019 // -----------------------------------------------------------------------------
  1068 // -----------------------------------------------------------------------------
  1020 // CAknButtonState::UpdateIconL
  1069 // CAknButtonState::UpdateIconL
  1068     LoadButtonIcon( iIcon );
  1117     LoadButtonIcon( iIcon );
  1069     LoadButtonIcon( iDimmedIcon );
  1118     LoadButtonIcon( iDimmedIcon );
  1070     LoadButtonIcon( iPressedIcon );
  1119     LoadButtonIcon( iPressedIcon );
  1071     LoadButtonIcon( iHoverIcon );
  1120     LoadButtonIcon( iHoverIcon );
  1072     }
  1121     }
  1073 
  1122 // -----------------------------------------------------------------------------
       
  1123 // CAknButtonState::UpdateExtensionInfoL
       
  1124 // Updates extension information. 
       
  1125 // -----------------------------------------------------------------------------
       
  1126 void CAknButtonState::UpdateExtensionInfoL( TInt aResource )
       
  1127 	{
       
  1128 	if ( iExtension )
       
  1129 		{
       
  1130 		iExtension->ConfigureExtensionFromResourceL( aResource );
       
  1131 		LoadButtonIcon( iIcon );
       
  1132 	    LoadButtonIcon( iDimmedIcon );
       
  1133 	    LoadButtonIcon( iPressedIcon );
       
  1134 	    LoadButtonIcon( iHoverIcon );
       
  1135 		}
       
  1136 	}
  1074 // -----------------------------------------------------------------------------
  1137 // -----------------------------------------------------------------------------
  1075 // CAknButtonState::SizeChanged
  1138 // CAknButtonState::SizeChanged
  1076 // Scales function graphics to the given size
  1139 // Scales function graphics to the given size
  1077 // -----------------------------------------------------------------------------
  1140 // -----------------------------------------------------------------------------
  1078 //
  1141 //
  1319 // -----------------------------------------------------------------------------    
  1382 // -----------------------------------------------------------------------------    
  1320 void CAknButtonState::SetGeneratedDimmedIcon( TBool aDimmedIconCreatedByButton )
  1383 void CAknButtonState::SetGeneratedDimmedIcon( TBool aDimmedIconCreatedByButton )
  1321     {
  1384     {
  1322     iExtension->iGeneratedDimmedIcon = aDimmedIconCreatedByButton;
  1385     iExtension->iGeneratedDimmedIcon = aDimmedIconCreatedByButton;
  1323     }
  1386     }
       
  1387 // -----------------------------------------------------------------------------
       
  1388 // CAknButtonState::FlagsChanged
       
  1389 // Returns ETrue if button state flags are changed so that 
       
  1390 // KAknStateHasLatchedDownFrame is setted or cleared
       
  1391 // -----------------------------------------------------------------------------    
       
  1392 TBool CAknButtonState::FlagsChanged()
       
  1393     {
       
  1394     return iExtension->iFlagsChanged;
       
  1395     }
       
  1396 
       
  1397 // -----------------------------------------------------------------------------
       
  1398 // CAknButtonState::ResetFlagsChanged
       
  1399 // Frame has been updated so boolean iFlagsChanged can be set to EFalse
       
  1400 // -----------------------------------------------------------------------------
       
  1401 void CAknButtonState::ResetFlagsChanged()
       
  1402     {
       
  1403     iExtension->iFlagsChanged = EFalse;
       
  1404     }
       
  1405 
       
  1406 // -----------------------------------------------------------------------------
       
  1407 // CAknButtonState::TextChanged
       
  1408 // Returns ETrue if text is changed and button's visual text has 
       
  1409 // not been updated. 
       
  1410 // -----------------------------------------------------------------------------    
       
  1411 TBool CAknButtonState::TextChanged()
       
  1412     {
       
  1413     return iExtension->iTextChanged;
       
  1414     }
       
  1415 
       
  1416 // -----------------------------------------------------------------------------
       
  1417 // CAknButtonState::ResetTextChanged
       
  1418 // Visual text has been updated so boolean iTextChanged can be set to EFalse
       
  1419 // -----------------------------------------------------------------------------
       
  1420 void CAknButtonState::ResetTextChanged()
       
  1421     {
       
  1422     iExtension->iTextChanged = EFalse;
       
  1423     }
       
  1424 
  1324 
  1425 
  1325 // -----------------------------------------------------------------------------
  1426 // -----------------------------------------------------------------------------
  1326 // CAknButtonState::Extension
  1427 // CAknButtonState::Extension
  1327 // -----------------------------------------------------------------------------
  1428 // -----------------------------------------------------------------------------
  1328 //
  1429 //
  1560     if ( AknsUtils::GetCachedColor( AknsUtils::SkinInstance(), textColor, 
  1661     if ( AknsUtils::GetCachedColor( AknsUtils::SkinInstance(), textColor, 
  1561         iTextColorTableId, iTextColorIndex ) == KErrNone )
  1662         iTextColorTableId, iTextColorIndex ) == KErrNone )
  1562         {
  1663         {
  1563         OverrideColorL( EColorButtonText, textColor );
  1664         OverrideColorL( EColorButtonText, textColor );
  1564         }
  1665         }
  1565 
  1666     
       
  1667     if ( AknsUtils::GetCachedColor( AknsUtils::SkinInstance(), textColor, 
       
  1668             iTextColorTableId, EAknsCIQsnTextColorsCG84 ) == KErrNone )
       
  1669         {
       
  1670         OverrideColorL( EColorButtonTextPressed, textColor );
       
  1671         }
  1566     if ( !iStates )
  1672     if ( !iStates )
  1567         {
  1673         {
  1568         iStates = new ( ELeave ) CArrayPtrFlat<CAknButtonState>( 2 );
  1674         iStates = new ( ELeave ) CArrayPtrFlat<CAknButtonState>( 2 );
  1569         }
  1675         }
  1570 
  1676 
  1592     if ( iFlags & KAknButtonTextLeft )
  1698     if ( iFlags & KAknButtonTextLeft )
  1593         {
  1699         {
  1594         iHorizontalAlignment = CGraphicsContext::ELeft;
  1700         iHorizontalAlignment = CGraphicsContext::ELeft;
  1595         }
  1701         }
  1596     iExtension->HandleFeedbackAreaChange();
  1702     iExtension->HandleFeedbackAreaChange();
       
  1703     SetFrameIDs(); 
  1597     }
  1704     }
  1598 
  1705 
  1599 // -----------------------------------------------------------------------------
  1706 // -----------------------------------------------------------------------------
  1600 // CAknButton::ConstructL
  1707 // CAknButton::ConstructL
  1601 // Symbian 2nd phase constructor for 1 state button.
  1708 // Symbian 2nd phase constructor for 1 state button.
  1794                 iTextColorTableId, iTextColorIndex ) == KErrNone )
  1901                 iTextColorTableId, iTextColorIndex ) == KErrNone )
  1795             {
  1902             {
  1796             TRAP_IGNORE( OverrideColorL( EColorButtonText, textColor ) );
  1903             TRAP_IGNORE( OverrideColorL( EColorButtonText, textColor ) );
  1797             }
  1904             }
  1798     
  1905     
       
  1906         if ( AknsUtils::GetCachedColor( AknsUtils::SkinInstance(), textColor, 
       
  1907                     iTextColorTableId, EAknsCIQsnTextColorsCG84 ) == KErrNone )
       
  1908             {
       
  1909             TRAP_IGNORE( OverrideColorL( EColorButtonTextPressed, textColor ) );
       
  1910             }
  1799         // generated pressed frame has to be regenerated
  1911         // generated pressed frame has to be regenerated
  1800         if ( iFlags & KAknButtonNoFrame && iFlags & KAknButtonPressedDownFrame )
  1912         if ( iFlags & KAknButtonNoFrame && iFlags & KAknButtonPressedDownFrame )
  1801             {
  1913             {
  1802             iExtension->DeletePressedBmps();
  1914             iExtension->DeletePressedBmps();
  1803             TRAP_IGNORE( CreatePressedDownFrameL() );
  1915             TRAP_IGNORE( CreatePressedDownFrameL() );
  1887         StopKeyRepeatTimer();
  1999         StopKeyRepeatTimer();
  1888         StopLongPressTimer();
  2000         StopLongPressTimer();
  1889         HideHelp();
  2001         HideHelp();
  1890         iButtonPressed = EFalse;
  2002         iButtonPressed = EFalse;
  1891         }
  2003         }
  1892     
       
  1893     if ( aDimmed )
  2004     if ( aDimmed )
  1894         {
  2005         {
  1895         iExtension->iFlags.Set( CAknButtonExtension::EDimmed );
  2006         iExtension->iFlags.Set( CAknButtonExtension::EDimmed );
  1896         }
  2007         }
  1897     else
  2008     else
  1898         {
  2009         {
  1899         iExtension->iFlags.Clear( CAknButtonExtension::EDimmed );
  2010         iExtension->iFlags.Clear( CAknButtonExtension::EDimmed );
  1900         }
  2011         }
  1901     if ( iExtension->iFeedback )
  2012     if ( iExtension->iFeedbackEnabled && iExtension->iFeedback )
  1902         {
  2013         {
  1903         if ( aDimmed )
  2014         if ( aDimmed )
  1904             {
  2015             {
  1905             iExtension->iFeedback->MoveFeedbackAreaToFirstPriority( this, 0 );
  2016             iExtension->iFeedback->MoveFeedbackAreaToFirstPriority( this, 0 );
  1906             }        
  2017             }        
  1931     // None of states has help text, CCoeControl::SetDimmed can be used        
  2042     // None of states has help text, CCoeControl::SetDimmed can be used        
  1932     if ( !hasHelp )
  2043     if ( !hasHelp )
  1933         {
  2044         {
  1934         CCoeControl::SetDimmed( aDimmed );
  2045         CCoeControl::SetDimmed( aDimmed );
  1935         }
  2046         }
       
  2047     SetFrameIDs(); 
  1936     }
  2048     }
  1937 
  2049 
  1938 // -----------------------------------------------------------------------------
  2050 // -----------------------------------------------------------------------------
  1939 // CAknButton::OfferKeyEventL
  2051 // CAknButton::OfferKeyEventL
  1940 // Handles key events.
  2052 // Handles key events.
  1960 
  2072 
  1961             if ( !iButtonPressed )
  2073             if ( !iButtonPressed )
  1962                 {
  2074                 {
  1963                 // show press changes
  2075                 // show press changes
  1964                 iButtonPressed = ETrue;
  2076                 iButtonPressed = ETrue;
       
  2077                 iExtension->iPrePointerPos.SetXY( -1, -1 );
       
  2078                 
       
  2079                 SetFrameIDs(); 
  1965                 if ( NeedsRedrawWhenPressed() )
  2080                 if ( NeedsRedrawWhenPressed() )
  1966                     {
  2081                     {
  1967                     DrawNow();
  2082                     DrawNow();
  1968                     }
  2083                     }
  1969                 }
  2084                 }
  1994         else if ( aType == EEventKeyUp )
  2109         else if ( aType == EEventKeyUp )
  1995             {
  2110             {
  1996             if ( iButtonPressed )
  2111             if ( iButtonPressed )
  1997                 {
  2112                 {
  1998                 iButtonPressed = EFalse;
  2113                 iButtonPressed = EFalse;
       
  2114                 SetFrameIDs(); 
  1999 
  2115 
  2000                 if ( NeedsRedrawWhenPressed() )
  2116                 if ( NeedsRedrawWhenPressed() )
  2001                     {
  2117                     {
  2002                     DrawNow();
  2118                     DrawNow();
  2003                     }
  2119                     }
  2030                         CAknButton::ELongPressEndedEvent ) );
  2146                         CAknButton::ELongPressEndedEvent ) );
  2031                     }
  2147                     }
  2032                 iExtension->iFlags.Clear( CAknButtonExtension::ELongPressReported );
  2148                 iExtension->iFlags.Clear( CAknButtonExtension::ELongPressReported );
  2033                 iExtension->iFlags.Clear( CAknButtonExtension::EKeyRepeatEventReported );
  2149                 iExtension->iFlags.Clear( CAknButtonExtension::EKeyRepeatEventReported );
  2034                 }
  2150                 }
  2035 
  2151             
  2036             if ( iKeyDownReported && RequestExit() && Observer() )
  2152             TInt reported = iKeyDownReported;
       
  2153             iKeyDownReported = EFalse;            
       
  2154             if ( reported && RequestExit() && Observer() )
  2037                 {
  2155                 {
  2038                 Observer()->HandleControlEventL( this,
  2156                 Observer()->HandleControlEventL( this,
  2039                     MCoeControlObserver::EEventRequestExit );
  2157                     MCoeControlObserver::EEventRequestExit );
  2040                 }
  2158                 }            
  2041 
       
  2042             iKeyDownReported = EFalse;
       
  2043             }
  2159             }
  2044         // we don't want aKeyEvent to go somewhere else :)
  2160         // we don't want aKeyEvent to go somewhere else :)
  2045         return EKeyWasConsumed;
  2161         return EKeyWasConsumed;
  2046         }
  2162         }
  2047 
  2163 
  2056 EXPORT_C void CAknButton::MakeVisible( TBool aVisible )
  2172 EXPORT_C void CAknButton::MakeVisible( TBool aVisible )
  2057     {
  2173     {
  2058     if ( aVisible != IsVisible() )
  2174     if ( aVisible != IsVisible() )
  2059         {
  2175         {
  2060         CAknControl::MakeVisible( aVisible );
  2176         CAknControl::MakeVisible( aVisible );
  2061         if ( iExtension->iFeedback )
  2177         if ( iExtension->iFeedbackEnabled && iExtension->iFeedback )
  2062             {
  2178             {
  2063             if ( aVisible )
  2179             if ( aVisible )
  2064                 {
  2180                 {
  2065                 iExtension->iFeedback->MoveFeedbackAreaToFirstPriority( this, 
  2181                 iExtension->iFeedback->MoveFeedbackAreaToFirstPriority( this, 
  2066                                                                         0 );
  2182                                                                         0 );
  2069                     this, 
  2185                     this, 
  2070                     aVisible && !IsDimmed() );
  2186                     aVisible && !IsDimmed() );
  2071             }
  2187             }
  2072 
  2188 
  2073         CAknButtonState* state = State();
  2189         CAknButtonState* state = State();
  2074         if ( !aVisible && state && state->HasHelp() )
  2190         if ( !aVisible && iButtonPressed )
       
  2191             {
       
  2192             ResetState();
       
  2193             }
       
  2194         else if ( !aVisible && state && state->HasHelp() )
  2075             {
  2195             {
  2076             HideHelp();
  2196             HideHelp();
  2077             }
  2197             }
  2078         }
  2198         }
  2079     }
  2199     }
  2118 // this control.
  2238 // this control.
  2119 // -----------------------------------------------------------------------------
  2239 // -----------------------------------------------------------------------------
  2120 //
  2240 //
  2121 EXPORT_C void CAknButton::SizeChanged()
  2241 EXPORT_C void CAknButton::SizeChanged()
  2122     {
  2242     {
       
  2243     //Reset state if observer modified the rectangel.
       
  2244     if ( iButtonPressed && !Rect().Contains( iExtension->iPrePointerPos ) )
       
  2245         {
       
  2246         ResetState();               
       
  2247         }
  2123     // If default icon size from LAF is used re-request that, otherwise trust
  2248     // If default icon size from LAF is used re-request that, otherwise trust
  2124     // that size will be updated by the utilising application.
  2249     // that size will be updated by the utilising application.
  2125     if ( iExtension->iFlags.IsSet( CAknButtonExtension::EUseDefaultIconSize ) )
  2250     if ( iExtension->iFlags.IsSet( CAknButtonExtension::EUseDefaultIconSize ) )
  2126         {
  2251         {
  2127         if ( iFlags & KAknButtonNoFrame && !State()->HasText() )
  2252         if ( iFlags & KAknButtonNoFrame && !State()->HasText() )
  2147     // Pressed down frame has to be regenerated
  2272     // Pressed down frame has to be regenerated
  2148     if ( iFlags & KAknButtonNoFrame && iFlags & KAknButtonPressedDownFrame ) 
  2273     if ( iFlags & KAknButtonNoFrame && iFlags & KAknButtonPressedDownFrame ) 
  2149        {
  2274        {
  2150         TRAP_IGNORE( CreatePressedDownFrameL() );
  2275         TRAP_IGNORE( CreatePressedDownFrameL() );
  2151         }
  2276         }
       
  2277     SetFrameRects(); 
  2152 
  2278 
  2153     iExtension->HandleFeedbackAreaChange();
  2279     iExtension->HandleFeedbackAreaChange();
  2154     }
  2280     }
  2155 
  2281 
  2156 // -----------------------------------------------------------------------------
  2282 // -----------------------------------------------------------------------------
  2168             if ( iButtonPressed )
  2294             if ( iButtonPressed )
  2169                 {
  2295                 {
  2170                 ResetState();               
  2296                 ResetState();               
  2171                 }
  2297                 }
  2172             return;
  2298             return;
       
  2299             }
       
  2300         if ( iExtension )
       
  2301             {
       
  2302             iExtension->iPrePointerPos = aPointerEvent.iPosition;
  2173             }
  2303             }
  2174         TBool buttonEvent( TouchArea().Contains( aPointerEvent.iPosition ) );
  2304         TBool buttonEvent( TouchArea().Contains( aPointerEvent.iPosition ) );
  2175         CAknButtonState* state = State();
  2305         CAknButtonState* state = State();
  2176         if ( !state )
  2306         if ( !state )
  2177             {
  2307             {
  2196                 else if ( buttonEvent )
  2326                 else if ( buttonEvent )
  2197                     {
  2327                     {
  2198                     if ( !iButtonPressed )
  2328                     if ( !iButtonPressed )
  2199                         {
  2329                         {
  2200                         iButtonPressed = ETrue;
  2330                         iButtonPressed = ETrue;
       
  2331                         SetFrameIDs(); 
  2201                         // feedback/basic on down event, if hit test is
  2332                         // feedback/basic on down event, if hit test is
  2202                         // used. Area registry is used for rectangular
  2333                         // used. Area registry is used for rectangular
  2203                         // buttons
  2334                         // buttons
  2204                         if ( ( iFlags & KAknButtonHitTest ) 
  2335                         if ( ( iFlags & KAknButtonHitTest ) 
  2205                            && !IsDimmed() 
  2336                            && !IsDimmed() 
  2225 
  2356 
  2226                     if ( iFlags & KAknButtonReportOnKeyDown )
  2357                     if ( iFlags & KAknButtonReportOnKeyDown )
  2227                         {
  2358                         {
  2228                         // State is changed on button down event
  2359                         // State is changed on button down event
  2229                         ChangeState( EFalse );
  2360                         ChangeState( EFalse );
  2230                         redrawNeeded = ETrue;
  2361                         redrawNeeded = EFalse;
       
  2362                         DrawNow();  //Redraw before noticing the observer for observer might open dialog                        
  2231                         if ( Observer() )
  2363                         if ( Observer() )
  2232                             {
  2364                             {
  2233                             Observer()->HandleControlEventL( this,
  2365                             Observer()->HandleControlEventL( this,
  2234                                 MCoeControlObserver::EEventStateChanged );
  2366                                 MCoeControlObserver::EEventStateChanged );
  2235                             }
  2367                             }
  2262                     if ( !buttonEvent && iButtonPressed )
  2394                     if ( !buttonEvent && iButtonPressed )
  2263                         {
  2395                         {
  2264                         // Redraw button, if needed
  2396                         // Redraw button, if needed
  2265                         if ( NeedsRedrawWhenPressed() )
  2397                         if ( NeedsRedrawWhenPressed() )
  2266                             {
  2398                             {
  2267                             iButtonPressed = EFalse;
       
  2268                             redrawNeeded = ETrue;
  2399                             redrawNeeded = ETrue;
  2269                             }
  2400                             }
  2270                         iButtonPressed = EFalse;
  2401                         iButtonPressed = EFalse;
       
  2402                         SetFrameIDs(); 
  2271 
  2403 
  2272                         StopKeyRepeatTimer();
  2404                         StopKeyRepeatTimer();
  2273                         StopLongPressTimer();
  2405                         StopLongPressTimer();
  2274 
  2406 
  2275                         if ( !IsFocused() )
  2407                         if ( !IsFocused() )
  2287 
  2419 
  2288                     // Pointer is dragged back into button area
  2420                     // Pointer is dragged back into button area
  2289                     else if ( buttonEvent && !iButtonPressed && !IsDimmed() )
  2421                     else if ( buttonEvent && !iButtonPressed && !IsDimmed() )
  2290                         {
  2422                         {
  2291                         iButtonPressed = ETrue;
  2423                         iButtonPressed = ETrue;
       
  2424                         SetFrameIDs(); 
  2292 
  2425 
  2293                         // Redraw button, if needed
  2426                         // Redraw button, if needed
  2294                         if ( NeedsRedrawWhenPressed() )
  2427                         if ( NeedsRedrawWhenPressed() )
  2295                             {
  2428                             {
  2296                             redrawNeeded = ETrue;
  2429                             redrawNeeded = ETrue;
  2313                 break;
  2446                 break;
  2314                 }
  2447                 }
  2315 
  2448 
  2316             case TPointerEvent::EButton1Up:
  2449             case TPointerEvent::EButton1Up:
  2317                 {
  2450                 {
       
  2451                 if ( iExtension )
       
  2452                     {
       
  2453                     iExtension->iPrePointerPos.SetXY( -1, -1 );
       
  2454                     }
  2318                 iNumberOfDragEvents = 0;
  2455                 iNumberOfDragEvents = 0;
  2319                 HideHelp();
  2456                 HideHelp();
  2320 
  2457 
  2321                 StopKeyRepeatTimer();
  2458                 StopKeyRepeatTimer();
  2322                 StopLongPressTimer();
  2459                 StopLongPressTimer();
  2331                             {
  2468                             {
  2332                             redrawNeeded = ETrue;
  2469                             redrawNeeded = ETrue;
  2333                             }
  2470                             }
  2334                         }
  2471                         }
  2335                     iButtonPressed = EFalse;
  2472                     iButtonPressed = EFalse;
       
  2473                     SetFrameIDs(); 
  2336                     }
  2474                     }
  2337 
  2475 
       
  2476                 TBool hasDrawn( EFalse );
  2338                 if ( buttonEvent && !IsDimmed() )
  2477                 if ( buttonEvent && !IsDimmed() )
  2339                     {
  2478                     {
  2340                         // feedback/BasicButton on up event, if hit test is
  2479                         // feedback/BasicButton on up event, if hit test is
  2341                         // used. Area registry is used for rectangular
  2480                         // used. Area registry is used for rectangular
  2342                         // buttons
  2481                         // buttons
  2355                     if ( !( iFlags & KAknButtonReportOnKeyDown ) &&
  2494                     if ( !( iFlags & KAknButtonReportOnKeyDown ) &&
  2356                          !( iExtension->iFlags.IsSet( CAknButtonExtension::ELongPressReported ) ) &&
  2495                          !( iExtension->iFlags.IsSet( CAknButtonExtension::ELongPressReported ) ) &&
  2357                          !( iExtension->iFlags.IsSet( CAknButtonExtension::EKeyRepeatEventReported ) ) )
  2496                          !( iExtension->iFlags.IsSet( CAknButtonExtension::EKeyRepeatEventReported ) ) )
  2358                         {
  2497                         {
  2359                         ChangeState( EFalse );
  2498                         ChangeState( EFalse );
  2360                         redrawNeeded = ETrue;
  2499                         if ( !hasDrawn )
       
  2500                         	{
       
  2501 	                        DrawNow();
       
  2502 	                        hasDrawn = ETrue;
       
  2503                         	}
       
  2504                         
  2361                         if ( Observer() )
  2505                         if ( Observer() )
  2362                             {
  2506                             {
  2363                             Observer()->HandleControlEventL( this,
  2507                             Observer()->HandleControlEventL( this,
  2364                                 MCoeControlObserver::EEventStateChanged );
  2508                                 MCoeControlObserver::EEventStateChanged );
  2365                             }
  2509                             }
  2366                         }
  2510                         }
  2367                    else
  2511                    else
  2368                         {
  2512                         {
  2369                         if ( iExtension->iFlags.IsSet( CAknButtonExtension::ELongPressReported ) && Observer() )
  2513                         if ( iExtension->iFlags.IsSet( CAknButtonExtension::ELongPressReported ) && Observer() )
  2370                             {
  2514                             {
       
  2515                             if ( redrawNeeded && !hasDrawn )
       
  2516                             	{
       
  2517                             	DrawNow();
       
  2518                             	hasDrawn = ETrue;
       
  2519                             	}
  2371                             Observer()->HandleControlEventL( this, 
  2520                             Observer()->HandleControlEventL( this, 
  2372                                 static_cast<MCoeControlObserver::TCoeEvent>( 
  2521                                 static_cast<MCoeControlObserver::TCoeEvent>( 
  2373                                 CAknButton::ELongPressEndedEvent ) );
  2522                                 CAknButton::ELongPressEndedEvent ) );
  2374                             }
  2523                             }
  2375                         iExtension->iFlags.Clear( CAknButtonExtension::ELongPressReported );
  2524                         iExtension->iFlags.Clear( CAknButtonExtension::ELongPressReported );
  2376                         iExtension->iFlags.Clear( CAknButtonExtension::EKeyRepeatEventReported );
  2525                         iExtension->iFlags.Clear( CAknButtonExtension::EKeyRepeatEventReported );
  2377                         }
  2526                         }
  2378 
  2527 
  2379                     if ( RequestExit() && Observer() )
  2528                     if ( RequestExit() && Observer() )
  2380                         {
  2529                         {
       
  2530                         if ( redrawNeeded && !hasDrawn )
       
  2531                         	{
       
  2532                         	DrawNow();
       
  2533                         	hasDrawn = ETrue;
       
  2534                         	}
  2381                         Observer()->HandleControlEventL( this,
  2535                         Observer()->HandleControlEventL( this,
  2382                             MCoeControlObserver::EEventRequestExit );
  2536                             MCoeControlObserver::EEventRequestExit );
  2383                         }
  2537                         }
  2384                     }
  2538                     }
  2385                         
  2539                         
  2386                 if ( !buttonEvent && !IsDimmed() && Observer() )
  2540                 if ( !buttonEvent && !IsDimmed() && Observer() )
  2387                    {
  2541                    {
       
  2542                    if ( redrawNeeded && !hasDrawn )
       
  2543                 	   {
       
  2544                 	   DrawNow();
       
  2545                 	   hasDrawn = ETrue;
       
  2546                 	   }
  2388                    Observer()->HandleControlEventL( this,
  2547                    Observer()->HandleControlEventL( this,
  2389                         MCoeControlObserver::EEventRequestCancel );
  2548                         MCoeControlObserver::EEventRequestCancel );
  2390                         
  2549                         
  2391                     if ( iExtension->iFlags.IsSet( CAknButtonExtension::ELongPressReported ) )
  2550                     if ( iExtension->iFlags.IsSet( CAknButtonExtension::ELongPressReported ) )
  2392                         {
  2551                         {
  2395                             CAknButton::ELongPressEndedEvent ) );
  2554                             CAknButton::ELongPressEndedEvent ) );
  2396                         iExtension->iFlags.Clear( CAknButtonExtension::ELongPressReported );
  2555                         iExtension->iFlags.Clear( CAknButtonExtension::ELongPressReported );
  2397                         iExtension->iFlags.Clear( CAknButtonExtension::EKeyRepeatEventReported );
  2556                         iExtension->iFlags.Clear( CAknButtonExtension::EKeyRepeatEventReported );
  2398                         }                        
  2557                         }                        
  2399                    }
  2558                    }
  2400 
  2559                 if ( hasDrawn )
       
  2560                 	{
       
  2561                 	redrawNeeded = EFalse;
       
  2562                 	}
  2401                 break;
  2563                 break;
  2402                 }
  2564                 }
  2403 
  2565 
  2404             default:
  2566             default:
  2405                 break;
  2567                 break;
  2418 //
  2580 //
  2419 EXPORT_C void CAknButton::PositionChanged()
  2581 EXPORT_C void CAknButton::PositionChanged()
  2420     {
  2582     {
  2421     if ( iExtension ) iExtension->HandleFeedbackAreaChange();
  2583     if ( iExtension ) iExtension->HandleFeedbackAreaChange();
  2422     CAknControl::PositionChanged();
  2584     CAknControl::PositionChanged();
       
  2585     
       
  2586     //Reset state if observer moved button position.
       
  2587     if ( iButtonPressed && iExtension && !Rect().Contains( iExtension->iPrePointerPos ) )
       
  2588     	{
       
  2589     	ResetState();
       
  2590     	}
       
  2591     SetFrameRects(); 
  2423     }
  2592     }
  2424     
  2593     
  2425 // -----------------------------------------------------------------------------
  2594 // -----------------------------------------------------------------------------
  2426 // CAknButton::FocusChanged
  2595 // CAknButton::FocusChanged
  2427 // This function is called whenever a control gains or loses focus.
  2596 // This function is called whenever a control gains or loses focus.
  2430 EXPORT_C void CAknButton::FocusChanged( TDrawNow aDrawNow )
  2599 EXPORT_C void CAknButton::FocusChanged( TDrawNow aDrawNow )
  2431     {
  2600     {
  2432     if ( !IsFocused() && iButtonPressed )
  2601     if ( !IsFocused() && iButtonPressed )
  2433         {
  2602         {
  2434         iButtonPressed = EFalse; 
  2603         iButtonPressed = EFalse; 
       
  2604         SetFrameIDs(); 
  2435         iKeyDownReported = EFalse; 
  2605         iKeyDownReported = EFalse; 
  2436         }
  2606         }
  2437     if ( IsVisible() )
  2607     if ( IsVisible() )
  2438         {
  2608         {
  2439         
  2609         
  2474 // -----------------------------------------------------------------------------
  2644 // -----------------------------------------------------------------------------
  2475 //
  2645 //
  2476 EXPORT_C void CAknButton::Draw( const TRect& /*aRect*/ ) const
  2646 EXPORT_C void CAknButton::Draw( const TRect& /*aRect*/ ) const
  2477     {
  2647     {
  2478     TRect rect( Rect() );
  2648     TRect rect( Rect() );
  2479     TAknLayoutRect centerLayout;
       
  2480     centerLayout.LayoutRect( rect,
       
  2481         AknLayoutScalable_Avkon::toolbar_button_pane_g1().LayoutLine() );
       
  2482     TRect innerRect( centerLayout.Rect() );
       
  2483     TRect highlightRect( HighlightRect() );
  2649     TRect highlightRect( HighlightRect() );
  2484     CWindowGc& gc = SystemGc();
  2650     CWindowGc& gc = SystemGc();
  2485     CAknButtonState* state = State();
  2651     CAknButtonState* state = State();
  2486 
  2652 
  2487     // Skin ids are determined here (a bit too early than necessary) so that 
  2653     if ( !( iFlags & KAknButtonNoFrame ) && !iButtonPressed && state && 
  2488     // we can avoid doing the same thing in DrawMaskedL.
  2654             state->FlagsChanged() )
  2489     if ( !( iFlags & KAknButtonNoFrame ) )
  2655         {
  2490         {
  2656         SetFrameIDs(); 
  2491         TInt frameIdIndex = KFrameId;
       
  2492 
       
  2493         if ( iButtonPressed )
       
  2494             {
       
  2495             frameIdIndex = KPressedFrameId;
       
  2496             }
       
  2497         else if ( state && state->Flags() & KAknButtonStateHasLatchedFrame )
       
  2498             {
       
  2499             if ( IsDimmed() )
       
  2500                 {
       
  2501                 // dimmed latched frame
       
  2502                 frameIdIndex = KLatchedDimmedFrameId;
       
  2503                 }
       
  2504             else
       
  2505                 {
       
  2506                 // latched down
       
  2507                 frameIdIndex = KLatchedFrameId;
       
  2508                 }
       
  2509             }
       
  2510         else if ( IsDimmed())
       
  2511             {
       
  2512             // dimmed frame
       
  2513             frameIdIndex = KDimmedFrameId;
       
  2514             }
       
  2515 
       
  2516         if ( SkinIID( frameIdIndex ) != KAknsIIDNone )
       
  2517             {
       
  2518             iBgContext->SetFrame( SkinIID( frameIdIndex ) );
       
  2519             iBgContext->SetCenter( SkinIID( ++frameIdIndex ) );
       
  2520             iBgContext->SetFrameRects( rect, innerRect );
       
  2521             }
       
  2522         }
  2657         }
  2523 
  2658 
  2524     if ( !iExtension->iFlags.IsSet( CAknButtonExtension::EUseAdditionalMask ) )
  2659     if ( !iExtension->iFlags.IsSet( CAknButtonExtension::EUseAdditionalMask ) )
  2525         {
  2660         {
  2526         MAknsSkinInstance* skin = AknsUtils::SkinInstance();
  2661         MAknsSkinInstance* skin = AknsUtils::SkinInstance();
  2538                 }
  2673                 }
  2539                 
  2674                 
  2540 
  2675 
  2541             if ( IsFocused() && !highlightRect.IsEmpty() )
  2676             if ( IsFocused() && !highlightRect.IsEmpty() )
  2542                 {
  2677                 {
  2543                 iBgContext->SetFrame( KAknsIIDQsnFrButtonHighlight ); 
       
  2544                 iBgContext->SetCenter( KAknsIIDQsnFrButtonHighlightCenter ); 
       
  2545                 iBgContext->SetFrameRects( rect, innerRect );
       
  2546 
       
  2547                 // frame graphics
  2678                 // frame graphics
  2548                 if ( !AknsDrawUtils::Background( skin, iBgContext, NULL, gc,
  2679                 if ( !AknsDrawUtils::Background( skin, 
  2549                       rect, KAknsDrawParamNoClearUnderImage ) )
  2680                       iExtension->iHighlightContext, NULL, gc, rect, 
       
  2681                       KAknsDrawParamNoClearUnderImage ) )
  2550                     {
  2682                     {
  2551                     gc.SetBrushColor( KRgbRed );
  2683                     gc.SetBrushColor( KRgbRed );
  2552                     gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
  2684                     gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
  2553                     gc.DrawRect( rect );
  2685                     gc.DrawRect( rect );
  2554                     }
  2686                     }
  2622         {
  2754         {
  2623         newIndex = aStateIndex % iStates->Count();
  2755         newIndex = aStateIndex % iStates->Count();
  2624         }
  2756         }
  2625 
  2757 
  2626     TRAP_IGNORE( SetStateIndexL( newIndex ) );
  2758     TRAP_IGNORE( SetStateIndexL( newIndex ) );
       
  2759     SetFrameIDs(); 
  2627     if ( aDrawNow )
  2760     if ( aDrawNow )
  2628         {
  2761         {
  2629         DrawNow();
  2762         DrawNow();
  2630         }
  2763         }
  2631     }
  2764     }
  2711 // CAknButton::SetFlags
  2844 // CAknButton::SetFlags
  2712 // Sets the button flags
  2845 // Sets the button flags
  2713 // -----------------------------------------------------------------------------
  2846 // -----------------------------------------------------------------------------
  2714 //
  2847 //
  2715 EXPORT_C void CAknButton::SetButtonFlags( const TInt aFlags )
  2848 EXPORT_C void CAknButton::SetButtonFlags( const TInt aFlags )
  2716     {
  2849     {    
  2717     if ( !(iFlags & KAknButtonNoFrame ) && aFlags & KAknButtonNoFrame )
  2850     if ( !( iFlags & KAknButtonNoFrame ) )
  2718         {
  2851         {
  2719         iExtension->iMargins.SetAllValuesTo( 0 );
  2852         if ( aFlags & KAknButtonNoFrame ) 
       
  2853             {
       
  2854             iExtension->iMargins.SetAllValuesTo( 0 );         
       
  2855             }
  2720         }
  2856         }
  2721     if ( aFlags & KAknButtonHitTest )
  2857     if ( aFlags & KAknButtonHitTest )
  2722         {
  2858         {
  2723         SetHitTest( iExtension );
  2859         SetHitTest( iExtension );
  2724         iExtension->HandleFeedbackAreaChange();
  2860         iExtension->HandleFeedbackAreaChange();
  2789         }
  2925         }
  2790     if ( aLatchedDimmedCenterId != KAknsIIDDefault )
  2926     if ( aLatchedDimmedCenterId != KAknsIIDDefault )
  2791         {
  2927         {
  2792         skinIds[KLatchedDimmedCenterId] = aLatchedDimmedCenterId;
  2928         skinIds[KLatchedDimmedCenterId] = aLatchedDimmedCenterId;
  2793         }
  2929         }
       
  2930     SetFrameIDs(); 
  2794     }
  2931     }
  2795 
  2932 
  2796 // -----------------------------------------------------------------------------
  2933 // -----------------------------------------------------------------------------
  2797 // CAknButton::SetBackgroundIds
  2934 // CAknButton::SetBackgroundIds
  2798 // -----------------------------------------------------------------------------
  2935 // -----------------------------------------------------------------------------
  2820 // -----------------------------------------------------------------------------
  2957 // -----------------------------------------------------------------------------
  2821 //
  2958 //
  2822 EXPORT_C void CAknButton::SetTextFont( const CFont* aFont )
  2959 EXPORT_C void CAknButton::SetTextFont( const CFont* aFont )
  2823     {
  2960     {
  2824     iFont = aFont;
  2961     iFont = aFont;
       
  2962     ConvertTextToVisualAndClip( iExtension->iTextRect ); 
  2825     }
  2963     }
  2826 
  2964 
  2827 // -----------------------------------------------------------------------------
  2965 // -----------------------------------------------------------------------------
  2828 // CAknButton::SetTextColorIds
  2966 // CAknButton::SetTextColorIds
  2829 // Sets the color table and color index for the button text.
  2967 // Sets the color table and color index for the button text.
  3114         {
  3252         {
  3115         newIndex = 0;
  3253         newIndex = 0;
  3116         }
  3254         }
  3117     
  3255     
  3118     TRAP_IGNORE( SetStateIndexL( newIndex ) );
  3256     TRAP_IGNORE( SetStateIndexL( newIndex ) );
       
  3257     // Updating background context might be needed if states flags differ
       
  3258     SetFrameIDs(); 
  3119     
  3259     
  3120     if ( aDrawNow )
  3260     if ( aDrawNow )
  3121         {
  3261         {
  3122         DrawNow();
  3262         DrawNow();
  3123         }
  3263         }
  3292 EXPORT_C void CAknButton::ResetState( )
  3432 EXPORT_C void CAknButton::ResetState( )
  3293     {
  3433     {
  3294     StopKeyRepeatTimer();
  3434     StopKeyRepeatTimer();
  3295     StopLongPressTimer();
  3435     StopLongPressTimer();
  3296     iButtonPressed = EFalse;
  3436     iButtonPressed = EFalse;
       
  3437     SetFrameIDs(); 
  3297     HideHelp();
  3438     HideHelp();
  3298     if ( iExtension )
  3439     if ( iExtension )
  3299         {
  3440         {
  3300         if ( iExtension->iFlags.IsSet( CAknButtonExtension::ELongPressReported ) && Observer() )
  3441         if ( iExtension->iFlags.IsSet( CAknButtonExtension::ELongPressReported ) && Observer() )
  3301             {
  3442             {
  3381 // Continues drawing of the button which has only text
  3522 // Continues drawing of the button which has only text
  3382 // -----------------------------------------------------------------------------
  3523 // -----------------------------------------------------------------------------
  3383 //
  3524 //
  3384 void CAknButton::DrawTextButton( CWindowGc& aGc ) const
  3525 void CAknButton::DrawTextButton( CWindowGc& aGc ) const
  3385     {
  3526     {
       
  3527     TRect textRect;
       
  3528     
       
  3529     TRect iconRect; //this is no use
       
  3530     GetCurrentStateTextAndIconRect( iconRect, textRect );
       
  3531       
  3386     CAknButtonState* state = State();
  3532     CAknButtonState* state = State();
  3387     if ( !state || !state->HasText() )
  3533     if ( state->TextChanged() || iExtension->TextRectSizeChanged( textRect ) )
  3388         return;
  3534         {
  3389 
  3535         ConvertTextToVisualAndClip( textRect ); 
       
  3536         }
       
  3537     DrawText( aGc, textRect ); 
       
  3538     }
       
  3539 
       
  3540 // -----------------------------------------------------------------------------
       
  3541 // CAknButton::DrawText
       
  3542 // Continues drawing of the button which has text
       
  3543 // -----------------------------------------------------------------------------
       
  3544 //
       
  3545 void CAknButton::DrawText( CWindowGc& aGc, TRect& aTextRect ) const
       
  3546     {
  3390     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
  3547     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
  3391 
       
  3392     TRect textRect = iExtension->iMargins.InnerRect( Rect() );
       
  3393 
       
  3394     if ( !( iFlags & KAknButtonNoFrame ) && 
       
  3395          ( iFlags & KAknButtonTextInsideFrame ) )
       
  3396         {
       
  3397         TAknLayoutRect center;
       
  3398         center.LayoutRect( Rect(), 
       
  3399             AknLayoutScalable_Avkon::toolbar_button_pane_g1().LayoutLine() );
       
  3400 
       
  3401         textRect = center.Rect();
       
  3402         }
       
  3403 
  3548 
  3404     aGc.SetBrushStyle( CGraphicsContext::ENullBrush );
  3549     aGc.SetBrushStyle( CGraphicsContext::ENullBrush );
  3405 
  3550 
  3406     TRgb penColor;
  3551     TRgb penColor;
  3407     TRgb brushColor;
  3552     TRgb brushColor;
  3416         }
  3561         }
  3417     aGc.UseFont( font );
  3562     aGc.UseFont( font );
  3418 
  3563 
  3419     aGc.SetUnderlineStyle( iExtension->iUnderlineStyle );
  3564     aGc.SetUnderlineStyle( iExtension->iUnderlineStyle );
  3420 
  3565 
  3421     // buffer for visually ordered text
       
  3422     TBuf<255 + KAknBidiExtraSpacePerLine> visualText; 
       
  3423     TInt clipWidth = textRect.Width();
       
  3424 
       
  3425     // bidi processing - using AknBidiTextUtils.
       
  3426     AknBidiTextUtils::ConvertToVisualAndClip(
       
  3427         state->Text(),
       
  3428         visualText,
       
  3429         *font,
       
  3430         clipWidth,
       
  3431         clipWidth );
       
  3432 
  3566 
  3433     TInt baselineOffset = 0;
  3567     TInt baselineOffset = 0;
  3434     switch ( iVerticalAlignment )
  3568     switch ( iVerticalAlignment )
  3435         {
  3569         {
  3436         case ETop:
  3570         case ETop:
  3437             baselineOffset = font->AscentInPixels();
  3571             baselineOffset = font->AscentInPixels();
  3438             break;
  3572             break;
  3439 
  3573 
  3440         case EBottom:
  3574         case EBottom:
  3441             baselineOffset = textRect.Height();
  3575             baselineOffset = aTextRect.Height();
  3442             break;
  3576             break;
  3443 
  3577 
  3444         default:  // centered
  3578         default:  // centered
  3445             baselineOffset = font->AscentInPixels() +
  3579             baselineOffset = font->AscentInPixels() +
  3446                            ( textRect.Height() - font->AscentInPixels() ) / 2;
  3580                            ( aTextRect.Height() - font->AscentInPixels() ) / 2;
  3447         }
  3581         }
  3448 
  3582 
  3449     CGraphicsContext::TTextAlign horAlignment = iHorizontalAlignment;
  3583     CGraphicsContext::TTextAlign horAlignment = iHorizontalAlignment;
  3450 
  3584 
  3451     aGc.DrawText( visualText, textRect, baselineOffset, horAlignment );
  3585     aGc.DrawText( iExtension->iVisualText, aTextRect, baselineOffset, 
       
  3586             horAlignment );
  3452     if ( iExtension->iPictographInterface )
  3587     if ( iExtension->iPictographInterface )
  3453         {
  3588         {
  3454         // For Japanese variant only
  3589         // For Japanese variant only
  3455         iExtension->iPictographInterface->Interface()->DrawPictographsInText(
  3590         iExtension->iPictographInterface->Interface()->DrawPictographsInText(
  3456             aGc, *font, visualText, textRect, baselineOffset, horAlignment );
  3591             aGc, *font, iExtension->iVisualText, aTextRect, baselineOffset, 
       
  3592             horAlignment );
  3457         }
  3593         }
  3458     }
  3594     }
  3459 
  3595 
  3460 // -----------------------------------------------------------------------------
  3596 // -----------------------------------------------------------------------------
  3461 // CAknButton::DrawIconButton
  3597 // CAknButton::DrawIconButton
  3462 // Continues drawing of the button which has only an icon in it
  3598 // Continues drawing of the button which has only an icon in it
  3463 // -----------------------------------------------------------------------------
  3599 // -----------------------------------------------------------------------------
  3464 //
  3600 //
  3465 void CAknButton::DrawIconButton( CWindowGc& aGc ) const
  3601 void CAknButton::DrawIconButton( CWindowGc& aGc ) const
  3466     {
  3602     {
  3467     TRect iconRect( iExtension->iMargins.InnerRect( Rect() ) );
  3603     TRect iconRect;
       
  3604     TRect textRect; 
       
  3605     GetCurrentStateTextAndIconRect( iconRect, textRect );
  3468     
  3606     
  3469     aGc.SetBrushStyle( CGraphicsContext::ENullBrush );
  3607     aGc.SetBrushStyle( CGraphicsContext::ENullBrush );
  3470 
  3608 
  3471     const CGulIcon* icon = GetCurrentIcon();
  3609     const CGulIcon* icon = GetCurrentIcon();
  3472     if ( !icon )
       
  3473         return;
       
  3474 
  3610 
  3475     CFbsBitmap* buttonBmp = icon->Bitmap();
  3611     CFbsBitmap* buttonBmp = icon->Bitmap();
  3476     CFbsBitmap* buttonMask = icon->Mask();
  3612     CFbsBitmap* buttonMask = icon->Mask();
  3477 
  3613 
  3478     TPoint iconPoint;
  3614     TPoint iconPoint;
  3550     {
  3686     {
  3551     CAknButtonState* state = State();
  3687     CAknButtonState* state = State();
  3552     if ( !state  || !state->HasText() )
  3688     if ( !state  || !state->HasText() )
  3553         {
  3689         {
  3554         return;
  3690         return;
  3555         }
  3691         }   
  3556     
  3692     
  3557     const CGulIcon* icon = GetCurrentIcon();
  3693     const CGulIcon* icon = GetCurrentIcon();
  3558     if ( !icon )
  3694 
  3559         {
  3695    
  3560         return;
       
  3561         }
       
  3562 
       
  3563     TRect rect = iExtension->iMargins.InnerRect( Rect() );
       
  3564     TRect iconRect;
  3696     TRect iconRect;
  3565     TRect textRect;
  3697     TRect textRect;
  3566     
  3698     GetCurrentStateTextAndIconRect( iconRect, textRect );
  3567     if ( !( iFlags & KAknButtonNoFrame ) &&
  3699     
  3568           ( iFlags & KAknButtonTextInsideFrame ))
       
  3569         {
       
  3570         TAknLayoutRect centerLayout;
       
  3571         centerLayout.LayoutRect( rect,
       
  3572         AknLayoutScalable_Avkon::toolbar_button_pane_g1().LayoutLine() );
       
  3573         rect = centerLayout.Rect();
       
  3574         }
       
  3575 
       
  3576     CFbsBitmap* buttonBmp = icon->Bitmap();
  3700     CFbsBitmap* buttonBmp = icon->Bitmap();
  3577     CFbsBitmap* buttonMask = icon->Mask();
  3701     CFbsBitmap* buttonMask = icon->Mask();
  3578     TSize iconSize ( buttonBmp->SizeInPixels());
  3702     TSize iconSize ( buttonBmp->SizeInPixels());
  3579     
  3703     
  3580     // Set rects for icon and text according to their positioning
  3704    
  3581     // First icon rect according to icon size - rest is for text
  3705     if ( state->TextChanged() || iExtension->TextRectSizeChanged( textRect ) )
  3582     
  3706         {
  3583     switch ( iExtension->iTextAndIconAlignment )        
  3707         ConvertTextToVisualAndClip( textRect ); 
  3584         {
  3708         }
  3585         case EIconBeforeText:
       
  3586             if ( AknLayoutUtils::LayoutMirrored() ) 
       
  3587                 {
       
  3588                 textRect.SetRect( rect.iTl.iX, rect.iTl.iY,
       
  3589                 rect.iBr.iX - iconSize.iWidth, rect.iBr.iY);
       
  3590                 iconRect.SetRect( rect.iTl.iX + 
       
  3591                     rect.Width() -iconSize.iWidth,
       
  3592                 rect.iTl.iY, rect.iBr.iX, rect.iBr.iY );    
       
  3593                 }
       
  3594             else
       
  3595                 {
       
  3596                 iconRect.SetRect( rect.iTl.iX, rect.iTl.iY,
       
  3597                 rect.iTl.iX + iconSize.iWidth, rect.iBr.iY);
       
  3598                 textRect.SetRect( rect.iTl.iX + iconSize.iWidth,
       
  3599                 rect.iTl.iY, rect.iBr.iX, rect.iBr.iY );    
       
  3600                 }
       
  3601             
       
  3602             break;
       
  3603             
       
  3604         case EIconAfterText:
       
  3605             if ( AknLayoutUtils::LayoutMirrored() ) 
       
  3606                 {
       
  3607                 iconRect.SetRect( rect.iTl.iX, rect.iTl.iY,
       
  3608                 rect.iTl.iX + iconSize.iWidth, rect.iBr.iY);
       
  3609                 textRect.SetRect( rect.iTl.iX + iconSize.iWidth,
       
  3610                 rect.iTl.iY, rect.iBr.iX, rect.iBr.iY );    
       
  3611                 }
       
  3612             else
       
  3613                 {
       
  3614                 textRect.SetRect( rect.iTl.iX, rect.iTl.iY,
       
  3615                 rect.iBr.iX - iconSize.iWidth, rect.iBr.iY);
       
  3616                 iconRect.SetRect( rect.iTl.iX + 
       
  3617                     rect.Width() -iconSize.iWidth,
       
  3618                 rect.iTl.iY, rect.iBr.iX, rect.iBr.iY );
       
  3619                 }
       
  3620             break;
       
  3621         
       
  3622         case EIconOverText:
       
  3623             iconRect.SetRect( rect.iTl.iX, rect.iTl.iY,
       
  3624             rect.iBr.iX, rect.iTl.iY + iconSize.iHeight );
       
  3625             textRect.SetRect( rect.iTl.iX, rect.iTl.iY + iconSize.iHeight,
       
  3626             rect.iBr.iX, rect.iBr.iY );
       
  3627             break;
       
  3628             
       
  3629         case EIconUnderText:
       
  3630             textRect.SetRect( rect.iTl.iX, rect.iTl.iY,
       
  3631             rect.iBr.iX, rect.iBr.iY - iconSize.iHeight );
       
  3632             iconRect.SetRect( rect.iTl.iX, rect.iBr.iY - iconSize.iHeight,
       
  3633             rect.iBr.iX, rect.iBr.iY );
       
  3634             break;
       
  3635 
       
  3636         case EOverlay:
       
  3637             {
       
  3638             textRect = rect;
       
  3639             iconRect = rect;
       
  3640             }
       
  3641             break;
       
  3642             
       
  3643         default:
       
  3644             return;
       
  3645         }
       
  3646 
       
  3647     // Draw icon
  3709     // Draw icon
  3648     TPoint iconPoint;
  3710     TPoint iconPoint;
  3649     switch ( iExtension->iHorizontalIconAlignment )
  3711     switch ( iExtension->iHorizontalIconAlignment )
  3650         {
  3712         {
  3651         case ERight:
  3713         case ERight:
  3706     else if ( buttonBmp )
  3768     else if ( buttonBmp )
  3707         {
  3769         {
  3708         aGc.BitBlt( iconPoint, buttonBmp, iconRect.Size() );
  3770         aGc.BitBlt( iconPoint, buttonBmp, iconRect.Size() );
  3709         }
  3771         }
  3710 
  3772 
  3711     const CFont* font = iFont;
  3773     DrawText( aGc, textRect ); 
  3712     if ( !font )
       
  3713         {
       
  3714         font = iCoeEnv->NormalFont();
       
  3715         }
       
  3716     aGc.UseFont( font );
       
  3717         
       
  3718     TRgb penColor;
       
  3719     TRgb brushColor;
       
  3720     GetTextColors( penColor, brushColor ); 
       
  3721     aGc.SetPenColor( penColor ); 
       
  3722     aGc.SetBrushColor( brushColor ); 
       
  3723 
       
  3724     aGc.SetUnderlineStyle( iExtension->iUnderlineStyle );
       
  3725 
       
  3726     TBuf<255 + KAknBidiExtraSpacePerLine> visualText; // buffer for visually ordered text
       
  3727     TInt clipWidth = textRect.Width();
       
  3728 
       
  3729     // bidi processing - using AknBidiTextUtils.
       
  3730     AknBidiTextUtils::ConvertToVisualAndClip(
       
  3731         state->Text(),
       
  3732         visualText,
       
  3733         *font,
       
  3734         clipWidth,
       
  3735         clipWidth );
       
  3736 
       
  3737     TInt baselineOffset = 0;
       
  3738     switch ( iVerticalAlignment )
       
  3739         {
       
  3740         case ETop:
       
  3741             baselineOffset = font->AscentInPixels();
       
  3742             break;
       
  3743 
       
  3744         case EBottom:
       
  3745             baselineOffset = textRect.Height();
       
  3746             break;
       
  3747 
       
  3748         default:  // centered
       
  3749             baselineOffset = font->AscentInPixels() +
       
  3750                            ( textRect.Height() - font->AscentInPixels() ) / 2;
       
  3751         }
       
  3752 
       
  3753     CGraphicsContext::TTextAlign horAlignment = iHorizontalAlignment;
       
  3754 
       
  3755     aGc.DrawText( visualText, textRect, baselineOffset, horAlignment );
       
  3756     if ( iExtension->iPictographInterface )
       
  3757         {
       
  3758         // For Japanese variant only
       
  3759         iExtension->iPictographInterface->Interface()->DrawPictographsInText(
       
  3760             aGc, *font, visualText, textRect, baselineOffset, horAlignment );
       
  3761         }
       
  3762     }
  3774     }
  3763 
  3775 
  3764 // -----------------------------------------------------------------------------
  3776 // -----------------------------------------------------------------------------
  3765 // Starts the long press timer.
  3777 // Starts the long press timer.
  3766 // -----------------------------------------------------------------------------
  3778 // -----------------------------------------------------------------------------
  4343         delete state;
  4355         delete state;
  4344         state = NULL;
  4356         state = NULL;
  4345         iStates->Delete( iStateIndex );
  4357         iStates->Delete( iStateIndex );
  4346         
  4358         
  4347         iStateIndex <= 0 ? iStateIndex = 0 : iStateIndex--;
  4359         iStateIndex <= 0 ? iStateIndex = 0 : iStateIndex--;
       
  4360         SetFrameIDs(); 
  4348         DrawNow();
  4361         DrawNow();
  4349         }
  4362         }
  4350     }
  4363     }
  4351 
  4364 
  4352 
  4365 
  4440             }
  4453             }
  4441         iHelpNote = CAknInfoPopupNoteController::NewL();
  4454         iHelpNote = CAknInfoPopupNoteController::NewL();
  4442         iHelpNote->SetTimeDelayBeforeShow( iHelpNoteWaitInterval );
  4455         iHelpNote->SetTimeDelayBeforeShow( iHelpNoteWaitInterval );
  4443         iHelpNote->SetTimePopupInView( iHelpNoteInViewInterval );
  4456         iHelpNote->SetTimePopupInView( iHelpNoteInViewInterval );
  4444         iHelpNote->SetTooltipModeL( ETrue );
  4457         iHelpNote->SetTooltipModeL( ETrue );
  4445         }
  4458         
  4446     }
  4459         //When state changed, empty rect to enable recalculate the 
  4447 
  4460         //visual text if text exists in current state.
       
  4461         if ( !(iExtension->iTextRect.IsEmpty()) )
       
  4462             {
       
  4463             iExtension->iTextRect = TRect::EUninitialized;
       
  4464             }
       
  4465         }
       
  4466     }
       
  4467 
       
  4468 // -----------------------------------------------------------------------------
       
  4469 // CAknButton::SetFrameIDs
       
  4470 // Sets frame ids for background context
       
  4471 // -----------------------------------------------------------------------------
       
  4472 //
       
  4473 void CAknButton::SetFrameIDs() const
       
  4474     {
       
  4475     // Skin ids are determined here (a bit too early than necessary) so that 
       
  4476     // we can avoid doing the same thing in DrawMaskedL.
       
  4477     CAknButtonState* state = State();
       
  4478     if ( !( iFlags & KAknButtonNoFrame ) )
       
  4479         {
       
  4480         TInt frameIdIndex = KFrameId;
       
  4481 
       
  4482         if ( iButtonPressed )
       
  4483             {
       
  4484             frameIdIndex = KPressedFrameId;
       
  4485             }
       
  4486         else if ( state && state->Flags() & KAknButtonStateHasLatchedFrame )
       
  4487             {
       
  4488             if ( IsDimmed() )
       
  4489                 {
       
  4490                 // dimmed latched frame
       
  4491                 frameIdIndex = KLatchedDimmedFrameId;
       
  4492                 }
       
  4493             else
       
  4494                 {
       
  4495                 // latched down
       
  4496                 frameIdIndex = KLatchedFrameId;
       
  4497                 }
       
  4498             }
       
  4499         else if ( IsDimmed() )
       
  4500             {
       
  4501             // dimmed frame
       
  4502             frameIdIndex = KDimmedFrameId;
       
  4503             }
       
  4504 
       
  4505         TAknsItemID skinIID( SkinIID( frameIdIndex ) );
       
  4506 
       
  4507         // Only change the background frame graphics if necessary.
       
  4508         if ( skinIID != KAknsIIDNone &&
       
  4509              skinIID != iExtension->iBackgroundSkinIID )
       
  4510             {
       
  4511             iBgContext->SetFrame( skinIID );
       
  4512             iBgContext->SetCenter( SkinIID( ++frameIdIndex) );
       
  4513             iExtension->iBackgroundSkinIID = skinIID;
       
  4514             }
       
  4515         }
       
  4516     if ( state )
       
  4517         {
       
  4518         state->ResetFlagsChanged(); 
       
  4519         }
       
  4520     }
       
  4521 
       
  4522 // -----------------------------------------------------------------------------
       
  4523 // CAknButton::SetFrameRects
       
  4524 // -----------------------------------------------------------------------------
       
  4525 //
       
  4526 void CAknButton::SetFrameRects()
       
  4527     {
       
  4528     TRect rect( Rect() );
       
  4529 
       
  4530     // Only change the frame rects is the button rectangle is valid and the
       
  4531     // button size has changed.
       
  4532     if ( !rect.IsEmpty() && iExtension->iBgFrameRect != rect )
       
  4533         {
       
  4534         TAknLayoutRect centerLayout;
       
  4535         centerLayout.LayoutRect( rect,
       
  4536             AknLayoutScalable_Avkon::toolbar_button_pane_g1().LayoutLine() );
       
  4537         TRect innerRect( centerLayout.Rect() );
       
  4538 
       
  4539         iBgContext->SetFrameRects( rect, innerRect );
       
  4540         iExtension->iHighlightContext->SetFrameRects( rect, innerRect );
       
  4541         iExtension->iBgFrameRect = rect;
       
  4542         }
       
  4543     }
       
  4544 
       
  4545 // -----------------------------------------------------------------------------
       
  4546 // CAknButton::ConvertTextToVisualAndClip
       
  4547 // -----------------------------------------------------------------------------
       
  4548 //
       
  4549 void CAknButton::ConvertTextToVisualAndClip( const TRect& aRect ) const
       
  4550     {
       
  4551     CAknButtonState* state = State();
       
  4552     if ( !state || !state->HasText() )
       
  4553         {
       
  4554         if ( state ) 
       
  4555             {
       
  4556             state->ResetTextChanged();
       
  4557             } 
       
  4558         return;
       
  4559         }
       
  4560 
       
  4561     TRect textRect( aRect );
       
  4562     //Using given rect to calculate the visual text if it's not empty.
       
  4563     if ( !textRect.IsEmpty() )
       
  4564         {
       
  4565         iExtension->iTextRect = textRect;
       
  4566         }
       
  4567     //Calculate text area.
       
  4568     //This branch means that it's the first calling after the state changed
       
  4569     //or client using new font before this is shown. 
       
  4570     else 
       
  4571         {
       
  4572         TRect iconRect;
       
  4573         GetCurrentStateTextAndIconRect( iconRect, textRect );
       
  4574         iExtension->iTextRect = textRect;
       
  4575         }
       
  4576    
       
  4577     TInt clipWidth = textRect.Width();
       
  4578 
       
  4579     const CFont* font = iFont;
       
  4580     if ( !font )
       
  4581         {
       
  4582         font = iCoeEnv->NormalFont();
       
  4583         }
       
  4584 
       
  4585     // bidi processing - using AknBidiTextUtils.
       
  4586     AknBidiTextUtils::ConvertToVisualAndClip(
       
  4587         state->Text(),
       
  4588         iExtension->iVisualText,
       
  4589         *font,
       
  4590         clipWidth,
       
  4591         clipWidth );
       
  4592     }
       
  4593       
       
  4594 // -----------------------------------------------------------------------------
       
  4595 // CAknButton::GetCurrentStateTextAndIconRect()
       
  4596 // Get rect for icon and text of the current button state .
       
  4597 // -----------------------------------------------------------------------------
       
  4598 //
       
  4599 void CAknButton::GetCurrentStateTextAndIconRect( TRect& aIconRect, 
       
  4600         TRect& aTextRect ) const
       
  4601     {
       
  4602     TRect iconRect( TRect::EUninitialized ) ;
       
  4603     TRect textRect( TRect::EUninitialized );
       
  4604     
       
  4605     CAknButtonState* state = State();
       
  4606     
       
  4607     //Return directly if no state
       
  4608     if ( !state )
       
  4609         {
       
  4610         aIconRect = iconRect;
       
  4611         aTextRect = textRect;
       
  4612         return;
       
  4613         }
       
  4614     
       
  4615     TBool hasText( state->HasText() );
       
  4616     TBool hasIcon( EFalse );  
       
  4617 
       
  4618     const CGulIcon* icon = GetCurrentIcon();
       
  4619     if ( icon )
       
  4620         {
       
  4621         hasIcon = ETrue;
       
  4622         }  
       
  4623     
       
  4624     TRect rect = iExtension->iMargins.InnerRect( Rect() );    
       
  4625     
       
  4626     //Icon area is not effected by the frame flags.
       
  4627     if ( hasIcon )
       
  4628         {
       
  4629         iconRect = rect;
       
  4630         }
       
  4631     
       
  4632     if ( !( iFlags & KAknButtonNoFrame ) &&
       
  4633           ( iFlags & KAknButtonTextInsideFrame ))
       
  4634         {
       
  4635         TAknLayoutRect centerLayout;
       
  4636         centerLayout.LayoutRect( rect,
       
  4637         AknLayoutScalable_Avkon::toolbar_button_pane_g1().LayoutLine() );
       
  4638         rect = centerLayout.Rect();
       
  4639         }
       
  4640     
       
  4641     if ( hasText )
       
  4642         {
       
  4643         textRect = rect;
       
  4644         }
       
  4645  
       
  4646 
       
  4647     if ( hasText && hasIcon )
       
  4648         {
       
  4649         CFbsBitmap* buttonBmp = icon->Bitmap();
       
  4650         CFbsBitmap* buttonMask = icon->Mask();
       
  4651         TSize iconSize ( buttonBmp->SizeInPixels());
       
  4652             
       
  4653             // Set rects for icon and text according to their positioning
       
  4654             // First icon rect according to icon size - rest is for text
       
  4655             
       
  4656         switch ( iExtension->iTextAndIconAlignment )        
       
  4657             {
       
  4658             case CAknButton::EIconBeforeText:
       
  4659                 if ( AknLayoutUtils::LayoutMirrored() ) 
       
  4660                     {
       
  4661                     textRect.SetRect( rect.iTl.iX, rect.iTl.iY,
       
  4662                     rect.iBr.iX - iconSize.iWidth, rect.iBr.iY);
       
  4663                     iconRect.SetRect( rect.iTl.iX + 
       
  4664                         rect.Width() -iconSize.iWidth,
       
  4665                     rect.iTl.iY, rect.iBr.iX, rect.iBr.iY );    
       
  4666                     }
       
  4667                 else
       
  4668                     {
       
  4669                     iconRect.SetRect( rect.iTl.iX, rect.iTl.iY,
       
  4670                     rect.iTl.iX + iconSize.iWidth, rect.iBr.iY);
       
  4671                     textRect.SetRect( rect.iTl.iX + iconSize.iWidth,
       
  4672                     rect.iTl.iY, rect.iBr.iX, rect.iBr.iY );    
       
  4673                     }
       
  4674                 
       
  4675                 break;
       
  4676                 
       
  4677             case CAknButton::EIconAfterText:
       
  4678                 if ( AknLayoutUtils::LayoutMirrored() ) 
       
  4679                     {
       
  4680                     iconRect.SetRect( rect.iTl.iX, rect.iTl.iY,
       
  4681                     rect.iTl.iX + iconSize.iWidth, rect.iBr.iY);
       
  4682                     textRect.SetRect( rect.iTl.iX + iconSize.iWidth,
       
  4683                     rect.iTl.iY, rect.iBr.iX, rect.iBr.iY );    
       
  4684                     }
       
  4685                 else
       
  4686                     {
       
  4687                     textRect.SetRect( rect.iTl.iX, rect.iTl.iY,
       
  4688                     rect.iBr.iX - iconSize.iWidth, rect.iBr.iY);
       
  4689                     iconRect.SetRect( rect.iTl.iX + 
       
  4690                         rect.Width() -iconSize.iWidth,
       
  4691                     rect.iTl.iY, rect.iBr.iX, rect.iBr.iY );
       
  4692                     }
       
  4693                 break;
       
  4694             
       
  4695             case CAknButton::EIconOverText:
       
  4696                 iconRect.SetRect( rect.iTl.iX, rect.iTl.iY,
       
  4697                 rect.iBr.iX, rect.iTl.iY + iconSize.iHeight );
       
  4698                 textRect.SetRect( rect.iTl.iX, rect.iTl.iY + iconSize.iHeight,
       
  4699                 rect.iBr.iX, rect.iBr.iY );
       
  4700                 break;
       
  4701                 
       
  4702             case CAknButton::EIconUnderText:
       
  4703                 textRect.SetRect( rect.iTl.iX, rect.iTl.iY,
       
  4704                 rect.iBr.iX, rect.iBr.iY - iconSize.iHeight );
       
  4705                 iconRect.SetRect( rect.iTl.iX, rect.iBr.iY - iconSize.iHeight,
       
  4706                 rect.iBr.iX, rect.iBr.iY );
       
  4707                 break;
       
  4708 
       
  4709             case CAknButton::EOverlay:
       
  4710                 {
       
  4711                 textRect = rect;
       
  4712                 iconRect = rect;
       
  4713                 }
       
  4714                 break;
       
  4715             default:
       
  4716                 break; //Do nothing.
       
  4717             }            
       
  4718         }
       
  4719     aTextRect = textRect;
       
  4720     aIconRect = iconRect;
       
  4721     }
  4448 // -----------------------------------------------------------------------------
  4722 // -----------------------------------------------------------------------------
  4449 // CAknButton::TouchArea
  4723 // CAknButton::TouchArea
  4450 // Returns the button touchable area.
  4724 // Returns the button touchable area.
  4451 // -----------------------------------------------------------------------------
  4725 // -----------------------------------------------------------------------------
  4452 //
  4726 //
  4461             !Layout_Meta_Data::IsLandscapeOrientation() ).LayoutLine() );
  4735             !Layout_Meta_Data::IsLandscapeOrientation() ).LayoutLine() );
  4462         touchRect = layoutRect.Rect();
  4736         touchRect = layoutRect.Rect();
  4463         }
  4737         }
  4464     return touchRect;
  4738     return touchRect;
  4465     }
  4739     }
       
  4740 
       
  4741 // -----------------------------------------------------------------------------
       
  4742 // CAknButton::EnableFeedback
       
  4743 // Enables or disables tactile feedback
       
  4744 // -----------------------------------------------------------------------------
       
  4745 //
       
  4746 EXPORT_C void CAknButton::EnableFeedback( TBool aEnable )
       
  4747     {
       
  4748     if ( iExtension->iFeedbackEnabled == aEnable )
       
  4749         {
       
  4750         return; 
       
  4751         }
       
  4752     iExtension->iFeedbackEnabled = aEnable; 
       
  4753     if ( aEnable )
       
  4754         {
       
  4755         if ( !iExtension->iFeedback )
       
  4756             {
       
  4757             iExtension->iFeedback = MTouchFeedback::Instance();
       
  4758             }
       
  4759         if ( !iExtension->iFeedback )
       
  4760             {
       
  4761             return;
       
  4762             }
       
  4763         if ( IsVisible() )
       
  4764             {
       
  4765             iExtension->iFeedback->MoveFeedbackAreaToFirstPriority( this, 
       
  4766                                                                         0 );
       
  4767             iExtension->iFeedback->EnableFeedbackForControl( 
       
  4768                     this, 
       
  4769                    !IsDimmed() );
       
  4770             }
       
  4771         iExtension->HandleFeedbackAreaChange(); 
       
  4772         }
       
  4773     else 
       
  4774         {
       
  4775         // MTouchFeedback instance lives in AknAppUi. If there is no
       
  4776         // MTouchFeedback instance there is no need to remove any areas
       
  4777         // either.
       
  4778         MTouchFeedback* fb = MTouchFeedback::Instance();
       
  4779         if ( fb )
       
  4780             {
       
  4781             fb->RemoveFeedbackForControl( this );
       
  4782             }
       
  4783         }
       
  4784     }
  4466 // end of file
  4785 // end of file