uifw/EikStd/coctlsrc/AknToolbar.cpp
branchRCL_3
changeset 56 d48ab3b357f1
parent 55 aecbbf00d063
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".
   249     {
   249     {
   250     aReader.ReadInt8(); //version, not used currently
   250     aReader.ReadInt8(); //version, not used currently
   251     aReader.ReadInt8();  //lines, not used currently
   251     aReader.ReadInt8();  //lines, not used currently
   252     iFlags = aReader.ReadInt32();
   252     iFlags = aReader.ReadInt32();
   253 
   253 
   254     TBool enableTransparency = CAknEnv::Static()->TransparencyEnabled() && 
   254     TBool enableTransparency = 
   255         ( ( !( iFlags & KAknToolbarFixed ) && 
   255         ( ( !( iFlags & KAknToolbarFixed ) && 
   256                 !( iFlags & KAknToolbarFloatingUnTransparent ) ) || 
   256                 !( iFlags & KAknToolbarFloatingUnTransparent ) ) || 
   257         ( iFlags & KAknToolbarTransparent && iFlags & KAknToolbarFixed ) ); 
   257         ( iFlags & KAknToolbarTransparent && iFlags & KAknToolbarFixed ) ); 
   258 
   258 
   259 
   259     if ( enableTransparency ) 
   260     if( enableTransparency ) 
       
   261         {
   260         {
   262         Window().SetRequiredDisplayMode( EColor16MA ); // Without this, ACT does not work in all cases in HW
   261         Window().SetRequiredDisplayMode( EColor16MA ); // Without this, ACT does not work in all cases in HW
   263         TInt err = Window().SetTransparencyAlphaChannel();
   262         EnableWindowTransparency();
   264 
   263         }
   265         if ( err == KErrNone ) // it should all ways be true in NGA
   264 
   266             {
   265     TRect dummyRect( 0, 0, 0, 0 );
   267             // Set the window initially completely transparent. This needs to be called only once.
   266     iFrameContext = CAknsFrameBackgroundControlContext::NewL(
   268             Window().SetBackgroundColor(~0);
   267         KAknsIIDQsnFrPopupSub, 
   269             }
   268         dummyRect,
   270         }
   269         dummyRect,
   271 
   270         ( iFlags & KAknToolbarFixed ) ? ETrue : EFalse );  
   272 
       
   273 
       
   274     iFrameContext = CAknsFrameBackgroundControlContext::NewL( KAknsIIDQsnFrPopupSub, 
       
   275             TRect(), TRect(), ( iFlags & KAknToolbarFixed )? ETrue : EFalse );  
       
   276 
   271 
   277     iBgContext = CAknsBasicBackgroundControlContext::NewL(
   272     iBgContext = CAknsBasicBackgroundControlContext::NewL(
   278         KAknsIIDQsnBgScreen, TRect(), ETrue );
   273         KAknsIIDQsnBgScreen, dummyRect, ETrue );
   279 
   274 
   280     SetWithSliding( ETrue ); 
   275     SetWithSliding( ETrue ); 
   281 
   276 
   282     TInt softkeyResource = aReader.ReadUint32(); //softkeys
   277     TInt softkeyResource = aReader.ReadUint32(); //softkeys
   283 
   278 
   312     
   307     
   313     // If toolbar is fixed need to set size for toolbar so that it can reduce 
   308     // If toolbar is fixed need to set size for toolbar so that it can reduce 
   314     // the rects correctly. 
   309     // the rects correctly. 
   315     if ( iFlags & KAknToolbarFixed )
   310     if ( iFlags & KAknToolbarFixed )
   316         {
   311         {
   317         if ( iFlags & KAknToolbarDefault )
   312         SetFocusing( EFalse );
   318             {
   313         
   319             SetDimmed( ETrue ); 
   314         // Don't set the size and position for default toolbar (never shown).
   320             }
   315         if ( !( iFlags & KAknToolbarDefault ) )
   321         SetFocusing( EFalse ); 
   316             {
   322         SetRect( CalculateSizeAndPosition() ); 
   317             SetRect( CalculateSizeAndPosition() );
   323         }
   318             }
   324 
   319         }
   325     AdjustAllButtons();
   320 
       
   321     // Unnecessary for default toolbar (never shown).
       
   322     if ( !( iFlags & KAknToolbarDefault ) )
       
   323         {
       
   324         AdjustAllButtons();
       
   325         }
   326     }
   326     }
   327 
   327 
   328 // -----------------------------------------------------------------------------
   328 // -----------------------------------------------------------------------------
   329 // CAknToolbar::ConstructFromResourceL
   329 // CAknToolbar::ConstructFromResourceL
   330 // Constructs controls from a resource file.
   330 // Constructs controls from a resource file.
   411         else
   411         else
   412             {
   412             {
   413             iInternalFlags.Clear( EFixedShown );
   413             iInternalFlags.Clear( EFixedShown );
   414             }
   414             }
   415 
   415 
   416         if ( visible && ( !AknLayoutUtils::PenEnabled() || 
   416         if ( visible &&
   417             ( !Layout_Meta_Data::IsLandscapeOrientation() && iFlags & KAknToolbarDefault ) ) )
   417              !Layout_Meta_Data::IsLandscapeOrientation() &&
       
   418              iFlags & KAknToolbarDefault )
   418             {
   419             {
   419             return; 
   420             return; 
   420             }
   421             }
   421 
   422 
   422         }
   423         }
   545 // The position of the top left corner should be set in advance.
   546 // The position of the top left corner should be set in advance.
   546 // -----------------------------------------------------------------------------
   547 // -----------------------------------------------------------------------------
   547 //
   548 //
   548 void CAknToolbar::ShowToolbarL()
   549 void CAknToolbar::ShowToolbarL()
   549     {
   550     {
   550     if ( iFlags & KAknToolbarFixed &&
   551     if ( iFlags & KAknToolbarFixed && iFlags & KAknToolbarDefault )
   551          ( !AknLayoutUtils::PenEnabled() ||
       
   552            iFlags & KAknToolbarDefault ) )
       
   553         {
   552         {
   554         if ( IsVisible() )
   553         if ( IsVisible() )
   555             {
   554             {
   556             MakeVisible( EFalse );
   555             MakeVisible( EFalse );
   557             }
   556             }
   590             startPos.iX = -rect.Size().iWidth;
   589             startPos.iX = -rect.Size().iWidth;
   591             }
   590             }
   592         SetExtent( startPos, rect.Size() );
   591         SetExtent( startPos, rect.Size() );
   593         UpdateControlPositions(); 
   592         UpdateControlPositions(); 
   594 
   593 
   595         TBool redrawStoreEnabled(EFalse);
       
   596         if( !CAknEnv::Static()->TransparencyEnabled() )
       
   597             {
       
   598             redrawStoreEnabled = Window().IsRedrawStoreEnabled();
       
   599             }
       
   600 
       
   601         CTouchToolbarData* data = CheckRegistration( this );      
   594         CTouchToolbarData* data = CheckRegistration( this );      
   602         if ( data && !(iFlags & KAknToolbarFixed) && iAvkonAppUi->IsForeground() )
   595         if ( data && !(iFlags & KAknToolbarFixed) && iAvkonAppUi->IsForeground() )
   603             {
   596             {
   604             data->SetBetweenRegisterAndBegin( EFalse );
   597             data->SetBetweenRegisterAndBegin( EFalse );
   605             
   598             
   633             else
   626             else
   634                 {
   627                 {
   635                 CAknTransitionUtils::RemoveData( reinterpret_cast<TInt>( this ) );
   628                 CAknTransitionUtils::RemoveData( reinterpret_cast<TInt>( this ) );
   636                 delete data;
   629                 delete data;
   637                 GfxTransEffect::Deregister( this );
   630                 GfxTransEffect::Deregister( this );
   638                 }
       
   639 
       
   640             if ( !CAknEnv::Static()->TransparencyEnabled() && redrawStoreEnabled )
       
   641                 {
       
   642                 Window().EnableRedrawStore( ETrue );
       
   643                 }
   631                 }
   644             }
   632             }
   645 
   633 
   646         // notify observer, for example touch pane, that toolbar was shown
   634         // notify observer, for example touch pane, that toolbar was shown
   647         if ( Observer() )
   635         if ( Observer() )
   743 //
   731 //
   744 void CAknToolbar::HideToolbarL()
   732 void CAknToolbar::HideToolbarL()
   745     {
   733     {
   746     if ( !iInternalFlags.IsSet( EShown ) ) // nothing to hide
   734     if ( !iInternalFlags.IsSet( EShown ) ) // nothing to hide
   747         {
   735         {
   748         if ( iFlags & KAknToolbarDefault && !AknLayoutUtils::PenEnabled()
       
   749               && IsVisible() )
       
   750             {
       
   751             MakeVisible( EFalse );
       
   752             }
       
   753         return;
   736         return;
   754         }
   737         }
   755 
   738 
   756    if ( iIdle && iIdle->IsActive() ) 
   739    if ( iIdle && iIdle->IsActive() ) 
   757         {
   740         {
   904 //    
   887 //    
   905 EXPORT_C void CAknToolbar::SetItemDimmed( const TInt aCommandId, 
   888 EXPORT_C void CAknToolbar::SetItemDimmed( const TInt aCommandId, 
   906                                           const TBool aDimmed, 
   889                                           const TBool aDimmed, 
   907                                           const TBool aDrawNow ) 
   890                                           const TBool aDrawNow ) 
   908     {
   891     {
       
   892     if( IsDimmed() )
       
   893     	return;
   909     CAknToolbarItem* item = ToolbarItemById( aCommandId );
   894     CAknToolbarItem* item = ToolbarItemById( aCommandId );
   910     if ( item && item->Control() ) 
   895     if ( item && item->Control() ) 
   911         {
   896         {
   912         item->Control()->SetDimmed( aDimmed );
   897         item->Control()->SetDimmed( aDimmed );
   913         if ( aDimmed && IsFocused() && item->Control()->IsFocused() )
   898         if ( aDimmed && IsFocused() && item->Control()->IsFocused() )
  1132                         if ( ii != iDownItem && !button->IsDimmed() )
  1117                         if ( ii != iDownItem && !button->IsDimmed() )
  1133                             {
  1118                             {
  1134                             MTouchFeedback* feedback = MTouchFeedback::Instance();
  1119                             MTouchFeedback* feedback = MTouchFeedback::Instance();
  1135                             if ( feedback )
  1120                             if ( feedback )
  1136                                 {
  1121                                 {
  1137                                 feedback->InstantFeedback( ETouchFeedbackBasicButton );
  1122                                 feedback->InstantFeedback( button,
       
  1123                                                            ETouchFeedbackBasicButton,
       
  1124                                                            ETouchFeedbackVibra,
       
  1125                                                            aPointerEvent );
  1138                                 }
  1126                                 }
  1139                             }
  1127                             }
  1140                 
  1128                 
  1141                         button->HandlePointerEventL( aPointerEvent );
  1129                         button->HandlePointerEventL( aPointerEvent );
  1142                         override = ETrue;
  1130                         override = ETrue;
  1193                 iInternalFlags.Clear( EFixedShown );
  1181                 iInternalFlags.Clear( EFixedShown );
  1194                 }
  1182                 }
  1195             return;
  1183             return;
  1196             }
  1184             }
  1197         }
  1185         }
  1198         
  1186 
  1199     if ( aType == KAknToolbarSetVisible && iFlags & KAknToolbarDefault 
  1187     if ( aType == KAknToolbarSetVisible && !IsShown() )
  1200             && !AknLayoutUtils::PenEnabled() )
       
  1201         {
       
  1202         return; 
       
  1203         }
       
  1204     else if ( aType == KAknToolbarSetVisible && !IsShown() )
       
  1205         {
  1188         {
  1206         iInternalFlags.Set( ECalledFromFW );
  1189         iInternalFlags.Set( ECalledFromFW );
  1207         iInternalFlags.Clear( EDrawBackground ); 
  1190         iInternalFlags.Clear( EDrawBackground ); 
  1208         SetToolbarVisibility(ETrue, EFalse);
  1191         SetToolbarVisibility(ETrue, EFalse);
  1209         iInternalFlags.Clear( ECalledFromFW );
  1192         iInternalFlags.Clear( ECalledFromFW );
  1225         {
  1208         {
  1226         iPreviousItem = KSelectedNone;
  1209         iPreviousItem = KSelectedNone;
  1227         for(TInt i = 0; i < iVisibleItems.Count(); i++)
  1210         for(TInt i = 0; i < iVisibleItems.Count(); i++)
  1228             {
  1211             {
  1229             CAknToolbarItem* item = iVisibleItems[ i ];
  1212             CAknToolbarItem* item = iVisibleItems[ i ];
  1230             CAknButton* button = static_cast<CAknButton*>( item->Control() ); 
  1213             if( item->ControlType() == EAknCtButton 
  1231             button->ResetState();
  1214                 || item->ControlType() == EAknCtToolbarExtension )
  1232             }
  1215                 {
  1233         if ( iFlags & KAknToolbarDefault && !AknLayoutUtils::PenEnabled() && IsVisible() )
  1216                 CAknButton* button = static_cast<CAknButton*>( item->Control() ); 
  1234             {
  1217                 button->ResetState();
  1235             TRAP_IGNORE( HideToolbarL() ); 
  1218                 }
  1236             return; 
  1219             }
  1237             }
  1220 
  1238         else if ( iFlags & KAknToolbarFixed )
  1221         if ( iFlags & KAknToolbarFixed )
  1239             {
  1222             {
  1240             if ( Layout_Meta_Data::IsLandscapeOrientation() && AknLayoutUtils::PenEnabled() )
  1223             if ( Layout_Meta_Data::IsLandscapeOrientation() )
  1241                 {
  1224                 {
  1242                 iOrientation = EAknOrientationVertical; 
  1225                 iOrientation = EAknOrientationVertical; 
  1243                 if ( ( iInternalFlags.IsSet( EFixedShown ) 
  1226                 if ( ( iInternalFlags.IsSet( EFixedShown ) 
  1244                     || ( iInternalFlags.IsSet( EItemsHidden )
  1227                     || ( iInternalFlags.IsSet( EItemsHidden )
  1245                     && iInternalFlags.IsSet( EAppOverrideVisibility ) ) )
  1228                     && iInternalFlags.IsSet( EAppOverrideVisibility ) ) )
  1255                         {
  1238                         {
  1256                         ShowViaIdle();                          
  1239                         ShowViaIdle();                          
  1257                         }
  1240                         }
  1258                     }
  1241                     }
  1259                 }
  1242                 }
  1260             else if ( !( iFlags & KAknToolbarDefault ) && AknLayoutUtils::PenEnabled() )
  1243             else if ( !( iFlags & KAknToolbarDefault ) )
  1261                 {
  1244                 {
  1262                 iOrientation = EAknOrientationHorizontal; 
  1245                 iOrientation = EAknOrientationHorizontal; 
  1263                 if ( iInternalFlags.IsSet( EFixedShown ) && !iInternalFlags.IsSet( EShown ) )
  1246                 if ( iInternalFlags.IsSet( EFixedShown ) && !iInternalFlags.IsSet( EShown ) )
  1264                     {
  1247                     {
  1265                     // If showing toolbar because HideItemsAndDrawOnlyBackground( EFalse )
  1248                     // If showing toolbar because HideItemsAndDrawOnlyBackground( EFalse )
  1273                         {
  1256                         {
  1274                         ShowViaIdle();
  1257                         ShowViaIdle();
  1275                         }
  1258                         }
  1276                     }
  1259                     }
  1277                 }
  1260                 }
  1278             else if ( ( !AknLayoutUtils::PenEnabled() || iFlags & KAknToolbarDefault ) && iInternalFlags.IsSet( EShown ) )
  1261             else if ( iFlags & KAknToolbarDefault && iInternalFlags.IsSet( EShown ) )
  1279                 {
  1262                 {
  1280                 TRAP_IGNORE( HideToolbarL() ); 
  1263                 TRAP_IGNORE( HideToolbarL() ); 
  1281                 return; 
  1264                 return; 
  1282                 }
  1265                 }
  1283             else
  1266             else
  2040         SetOrdinalPositions();
  2023         SetOrdinalPositions();
  2041         }
  2024         }
  2042 
  2025 
  2043     CWindowGc& gc = SystemGc();
  2026     CWindowGc& gc = SystemGc();
  2044     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
  2027     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
  2045     // Draw background         
  2028     
  2046     if ( iFlags & KAknToolbarFixed && 
  2029     //
       
  2030     // Draw background
       
  2031     //
       
  2032     if ( iFlags & KAknToolbarFixed && !( iFlags & KAknToolbarNoBackground ) &&
  2047          iBgRect.Height() > 0 &&
  2033          iBgRect.Height() > 0 &&
  2048          iBgRect.Width() > 0 )
  2034          iBgRect.Width() > 0 )
  2049         {
  2035         {
  2050         if ( aRect.Intersects( iBgRect ) )
  2036         if ( aRect.Intersects( iBgRect ) )
  2051             {
  2037             {
  2373             {
  2359             {
  2374             iFrameContext->SetCenter( KAknsIIDQgnGrafPopupTransCenter ); 
  2360             iFrameContext->SetCenter( KAknsIIDQgnGrafPopupTransCenter ); 
  2375             }
  2361             }
  2376         } 
  2362         } 
  2377 
  2363 
  2378     TRect rect = CalculateSizeAndPosition();
  2364     // Don't set the size and position for default toolbar (never shown).
  2379     // Set focused item again to avoid panic in a case when toolbar has more 
  2365     if ( !( iFlags & KAknToolbarDefault ) )
  2380     // items in previous orientation and some of the items that do not 
  2366         {
  2381     // fit to toolbar in this orientation was focused. 
  2367         TRect rect = CalculateSizeAndPosition();
  2382     if ( IsFocused() )
  2368         // Set focused item again to avoid panic in a case when toolbar has
  2383         {
  2369         // more items in previous orientation and some of the items that do
  2384         TRAP_IGNORE( MoveHighlightL( iFocusedItem, EFalse ) ); 
  2370         // not  fit to toolbar in this orientation was focused. 
  2385         }
  2371         if ( IsFocused() )
  2386 
  2372             {
  2387     if ( iInternalFlags.IsSet( EShown ) )
  2373             TRAP_IGNORE( MoveHighlightL( iFocusedItem, EFalse ) ); 
  2388         {
  2374             }
  2389         if ( !( iFlags & KAknToolbarFlexiblePosition ) )
  2375     
  2390             {
  2376         if ( iInternalFlags.IsSet( EShown ) )
  2391             SetPosition( rect.iTl );
  2377             {
  2392             }
  2378             if ( !( iFlags & KAknToolbarFlexiblePosition ) )
  2393         else 
  2379                 {
  2394             {
  2380                 SetPosition( rect.iTl );
  2395             UpdateControlPositions(); 
  2381                 }
  2396             }
  2382             else 
  2397         SetSize( rect.Size() );
  2383                 {
  2398         DrawDeferred();
  2384                 UpdateControlPositions(); 
       
  2385                 }
       
  2386             SetSize( rect.Size() );
       
  2387             DrawDeferred();
       
  2388             }
  2399         }
  2389         }
  2400     }
  2390     }
  2401 
  2391 
  2402 // -----------------------------------------------------------------------------
  2392 // -----------------------------------------------------------------------------
  2403 // CAknToolbar::NotifyBackgroundChange
  2393 // CAknToolbar::NotifyBackgroundChange
  2629 //    
  2619 //    
  2630 void CAknToolbar::ReduceRect( TRect& aBoundingRect ) const
  2620 void CAknToolbar::ReduceRect( TRect& aBoundingRect ) const
  2631     {
  2621     {
  2632     TBool toolbarNotVisible( !IsShown() && !( iFlags & KAknToolbarDefault ) );
  2622     TBool toolbarNotVisible( !IsShown() && !( iFlags & KAknToolbarDefault ) );
  2633     TBool fixedToolbar( iFlags & KAknToolbarFixed );
  2623     TBool fixedToolbar( iFlags & KAknToolbarFixed );
  2634     TBool landscapeOrientation( Layout_Meta_Data::IsLandscapeOrientation() );
       
  2635     TBool touchEnabled( AknLayoutUtils::PenEnabled() );
       
  2636     TBool defaultContent( iFlags & KAknToolbarDefault );
  2624     TBool defaultContent( iFlags & KAknToolbarDefault );
  2637 
  2625 
  2638     if ( toolbarNotVisible || 
  2626     if ( toolbarNotVisible || 
  2639          !fixedToolbar ||
  2627          !fixedToolbar ||
  2640          ( defaultContent && !landscapeOrientation ) ||
       
  2641          !touchEnabled ||
       
  2642          ( fixedToolbar && defaultContent ) )
  2628          ( fixedToolbar && defaultContent ) )
  2643         {
  2629         {
  2644         return;
  2630         return;
  2645         }
  2631         }
  2646     TRect appRect, toolbarRect; 
  2632     TRect appRect, toolbarRect; 
  3112 
  3098 
  3113             aCellPaneRect = RectFromLayout( aGridPaneRect,     
  3099             aCellPaneRect = RectFromLayout( aGridPaneRect,     
  3114                 AknLayoutScalable_Avkon::cell_sctrl_middle_pane( 0, 0, 0 ) );
  3100                 AknLayoutScalable_Avkon::cell_sctrl_middle_pane( 0, 0, 0 ) );
  3115             }
  3101             }
  3116         }
  3102         }
  3117     else    
  3103     else
  3118         {
  3104         {
  3119         if ( iOrientation == EAknOrientationHorizontal )
  3105         if ( iOrientation == EAknOrientationHorizontal )
  3120             {        
  3106             {
  3121             variety = 4;    
  3107             variety = 4;
  3122             aToolbarRect = RectFromLayout( aMainPaneRect,
  3108             aToolbarRect = RectFromLayout( aMainPaneRect,
  3123                 AknLayoutScalable_Avkon::popup_toolbar_window( variety ) );
  3109                 AknLayoutScalable_Avkon::popup_toolbar_window( variety ) );
  3124 
  3110 
  3125             aGridPaneRect = RectFromLayout( TRect( TPoint(), aToolbarRect.Size() ),
  3111             aGridPaneRect = RectFromLayout( TRect( TPoint(), aToolbarRect.Size() ),
  3126                 AknLayoutScalable_Avkon::grid_toobar_pane() );
  3112                 AknLayoutScalable_Avkon::grid_toobar_pane() );