uifw/EikStd/coctlsrc/aknstyluspopupmenucontent.cpp
branchRCL_3
changeset 4 8ca85d2f0db7
parent 0 2f259fa3e83a
child 9 aabf2c525e0f
equal deleted inserted replaced
0:2f259fa3e83a 4:8ca85d2f0db7
     1 /*
     1 /*
     2 * Copyright (c) 2005-2009 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".
    25 #include <AknsConstants.h>
    25 #include <AknsConstants.h>
    26 #include <eikapp.h>
    26 #include <eikapp.h>
    27 #include <aknappui.h>
    27 #include <aknappui.h>
    28 #include <AknDef.h>
    28 #include <AknDef.h>
    29 #include <touchfeedback.h>
    29 #include <touchfeedback.h>
       
    30 #include <layoutmetadata.cdl.h>
    30 
    31 
    31 #include "aknstyluspopupmenuphysicshandler.h"
    32 #include "aknstyluspopupmenuphysicshandler.h"
    32 #include "aknstyluspopupmenucontent.h"
    33 #include "aknstyluspopupmenucontent.h"
    33 
    34 
    34 const TInt KItemArrayGranularity = 4;
    35 const TInt KItemArrayGranularity = 4;
   543         aCommandId );
   544         aCommandId );
   544     CleanupStack::PushL( item ); 
   545     CleanupStack::PushL( item ); 
   545     item->ConstructL( aItem );  
   546     item->ConstructL( aItem );  
   546     iItems.AppendL( item );
   547     iItems.AppendL( item );
   547     CleanupStack::Pop( item ); 
   548     CleanupStack::Pop( item ); 
   548 
       
   549     }
   549     }
   550 
   550 
   551 // ---------------------------------------------------------------------------
   551 // ---------------------------------------------------------------------------
   552 // Removes the menu item based on the given command id and frees the 
   552 // Removes the menu item based on the given command id and frees the 
   553 // memory occupied by it.
   553 // memory occupied by it.
   693     TInt height = 0; // height of all menu items combined.
   693     TInt height = 0; // height of all menu items combined.
   694     TInt width = 0; // Width of menu
   694     TInt width = 0; // Width of menu
   695     TInt visibleItems = 0; // Number of visible items
   695     TInt visibleItems = 0; // Number of visible items
   696     
   696     
   697     // Find the widest visible item and count visible items
   697     // Find the widest visible item and count visible items
       
   698     TRect screenRect;
       
   699     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EScreen,
       
   700                                        screenRect );
       
   701     TInt screenHeight( screenRect.Height() );
       
   702     TInt screenWidth( screenRect.Width() );
       
   703     
       
   704     const CFont* usedFont = AknLayoutUtils::FontFromId(
       
   705         AknLayoutScalable_Avkon::list_single_popup_submenu_pane_t1( 0 ).Font() );
   698     for ( TInt i = 0; i < iItems.Count(); i++ )
   706     for ( TInt i = 0; i < iItems.Count(); i++ )
   699         {
   707         {
   700         if ( iItems[i]->iVisibility == KShown )
   708         if ( iItems[i]->iVisibility == KShown )
   701             {
   709             {
   702             visibleItems++;
   710             visibleItems++;
   703             textWidth = AknLayoutUtils::FontFromId( AknLayoutScalable_Avkon::
   711             textWidth = usedFont->TextWidthInPixels( *( iItems[i]->iText ) );
   704             list_single_popup_submenu_pane_t1( 0 ).LayoutLine().FontId() )->TextWidthInPixels( *( iItems[i]->iText ) );
       
   705             width = Max( width, textWidth );
   712             width = Max( width, textWidth );
   706             }
   713             }
   707         }
   714         }
   708         
   715 
   709     if ( visibleItems == 0 )
   716     if ( visibleItems == 0 )
   710         {
   717         {
   711         return TSize( 0, 0 );
   718         return TSize( 0, 0 );
   712         }
   719         }
   713             
   720 
   714     TRect mainPaneRect;
   721     // Check the minimum width from the layout data and adjust the width
   715     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane,
   722     // if the text would take less space than that.
   716                                        mainPaneRect );
   723     TInt minWidth =
       
   724         TAknWindowComponentLayout::Compose(
       
   725             AknLayoutScalable_Avkon::popup_touch_menu_window( 0 ),
       
   726             TAknWindowComponentLayout::Compose(
       
   727                 AknLayoutScalable_Avkon::list_touch_menu_pane( 0 ),
       
   728                 AknLayoutScalable_Avkon::list_single_touch_menu_pane( 0 ) ) ).LayoutLine().iW;
       
   729     width = Max( width, minWidth );
       
   730 
   717     TAknWindowLineLayout listLayout = 
   731     TAknWindowLineLayout listLayout = 
   718        AknLayoutScalable_Avkon::list_single_touch_menu_pane(0).LayoutLine();
   732        AknLayoutScalable_Avkon::list_single_touch_menu_pane(0).LayoutLine();
   719  
   733  
   720     TAknTextLineLayout textLayout = 
   734     TAknTextLineLayout textLayout = 
   721        AknLayoutScalable_Avkon::list_single_touch_menu_pane_t1().LayoutLine();
   735        AknLayoutScalable_Avkon::list_single_touch_menu_pane_t1().LayoutLine();
   724        AknLayoutScalable_Avkon::aid_value_unit2().LayoutLine();
   738        AknLayoutScalable_Avkon::aid_value_unit2().LayoutLine();
   725     
   739     
   726     TInt singleItemHeight = listLayout.iH; 
   740     TInt singleItemHeight = listLayout.iH; 
   727     height = singleItemHeight * visibleItems;
   741     height = singleItemHeight * visibleItems;
   728     
   742     
   729     if ( height > mainPaneRect.Height() )
   743     if ( height > screenHeight )
   730         {
   744         {
   731         TInt fitsToMenu = mainPaneRect.Height() / singleItemHeight;
   745         // Amount of items that fit in the popup.
       
   746         TInt fitsToMenu = visibleItems;
       
   747 
       
   748         if ( Layout_Meta_Data::IsLandscapeOrientation() )
       
   749             {
       
   750             // In landscape orientation the max amount of items comes from
       
   751             // the layout data.
       
   752             TAknLayoutScalableParameterLimits paramLimits(
       
   753                 AknLayoutScalable_Avkon::list_single_touch_menu_pane_ParamLimits() );
       
   754             
       
   755             // Add one to the last row as it's row index starting from zero.
       
   756             fitsToMenu = paramLimits.LastRow() + 1;
       
   757             }
       
   758         else
       
   759             {
       
   760             // In potrait orientation the menu can show as many items as fit
       
   761             // on the screen.
       
   762             fitsToMenu = screenHeight / singleItemHeight;
       
   763             }
       
   764 
   732         height = fitsToMenu * singleItemHeight;
   765         height = fitsToMenu * singleItemHeight;
   733         TAknWindowLineLayout scrollBar = 
   766         TAknWindowLineLayout scrollBar = 
   734             AknLayoutScalable_Avkon::scroll_pane( 0 );
   767             AknLayoutScalable_Avkon::scroll_pane( 0 );
   735         width += scrollBar.iW;
   768         width += scrollBar.iW;
   736         }
   769         }
   737 
   770 
   738     width += textLayout.ir + textLayout.il;
   771     width += textLayout.ir + textLayout.il;
   739 
   772 
   740     if ( width > ( mainPaneRect.Width() - unit.iW ) )
   773     if ( width > ( screenWidth - unit.iW ) )
   741         {
   774         {
   742         width = mainPaneRect.Width() - ( unit.iW );
   775         width = screenWidth - ( unit.iW );
   743         }
   776         }
   744 
   777 
   745     return TSize( width, height );
   778     return TSize( width, height );
   746     }
   779     }
   747 
   780 
   823     else
   856     else
   824         {
   857         {
   825         if ( iExtension && iExtension->iInformObserver && !iExtension->iObserverInformed )
   858         if ( iExtension && iExtension->iInformObserver && !iExtension->iObserverInformed )
   826             {
   859             {
   827             iExtension->iInformObserver = EFalse; 
   860             iExtension->iInformObserver = EFalse; 
   828             TRAP_IGNORE(Observer()->HandleControlEventL( this,
   861             if ( Observer() )
   829                 MCoeControlObserver::EEventRequestCancel )); 
   862                 {
       
   863                 TRAP_IGNORE(Observer()->HandleControlEventL( this,
       
   864                     MCoeControlObserver::EEventRequestCancel )); 
       
   865                 }
   830             }
   866             }
   831         if ( iSBFrame )
   867         if ( iSBFrame )
   832             {
   868             {
   833             delete iSBFrame;
   869             delete iSBFrame;
   834             iSBFrame = NULL;
   870             iSBFrame = NULL;
   910 void CAknStylusPopUpMenuContent::DrawItem(
   946 void CAknStylusPopUpMenuContent::DrawItem(
   911     CWindowGc& aGc,TInt aItem,THighlightType aHighlight) const
   947     CWindowGc& aGc,TInt aItem,THighlightType aHighlight) const
   912     {
   948     {
   913     TRect rect( iItems[aItem]->iRect );
   949     TRect rect( iItems[aItem]->iRect );
   914     
   950     
   915     // Use offset to move items smoothly.
   951     if ( !rect.IsEmpty() )
   916     // If physics not in use, offset is always 0.
   952         {
   917     rect.Move( TPoint( 0, -Offset() ) ); 
   953         // Use offset to move items smoothly.
   918 
   954         // If physics not in use, offset is always 0.
   919     if ( aHighlight == EDrawHighlight )
   955         rect.Move( TPoint( 0, -Offset() ) ); 
   920         {
   956     
   921         TBool drawOk = EFalse; 
   957         if ( aHighlight == EDrawHighlight )
   922         if( iExtension->iAnimation ) // Draw animated highlight
   958             {
   923             {
   959             TBool drawOk = EFalse; 
   924             drawOk = iExtension->iAnimation->Render( aGc, rect );
   960             if( iExtension->iAnimation ) // Draw animated highlight
   925             }
       
   926         if ( !drawOk )
       
   927             {
       
   928             // Animated highlight was not available, use normal skinned
       
   929             // rendering.
       
   930             TAknLayoutRect listRect; 
       
   931             TAknLayoutRect innerRect;
       
   932 
       
   933             listRect.LayoutRect( rect, 
       
   934                 AknLayoutScalable_Avkon::list_highlight_pane_cp1().LayoutLine() );
       
   935             innerRect.LayoutRect( listRect.Rect(),
       
   936                 AknLayoutScalable_Avkon::list_highlight_pane_g1_cp1().LayoutLine() );
       
   937             
       
   938             MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   939             aGc.SetBrushStyle( CGraphicsContext::ESolidBrush ); 
       
   940             // if we have transparent highlight, draw also background under highlight
       
   941             if ( Background() )
       
   942                 {
   961                 {
   943                 Background()->Draw( aGc, *this, rect );
   962                 drawOk = iExtension->iAnimation->Render( aGc, rect );
   944                 }
   963                 }
   945             
       
   946             drawOk = AknsDrawUtils::DrawFrame( skin, aGc, rect, innerRect.Rect(), 
       
   947                 KAknsIIDQsnFrList, KAknsIIDDefault );
       
   948 
       
   949             //Both highlight animation and frame drawing failed. 
       
   950             if ( !drawOk )
   964             if ( !drawOk )
   951                 {
   965                 {
   952                 listRect.DrawRect( aGc ); 
   966                 // Animated highlight was not available, use normal skinned
   953                 innerRect.DrawRect( aGc ); 
   967                 // rendering.
       
   968                 TAknLayoutRect listRect; 
       
   969                 TAknLayoutRect innerRect;
       
   970     
       
   971                 listRect.LayoutRect( rect, 
       
   972                     AknLayoutScalable_Avkon::list_highlight_pane_cp1().LayoutLine() );
       
   973                 innerRect.LayoutRect( listRect.Rect(),
       
   974                     AknLayoutScalable_Avkon::list_highlight_pane_g1_cp1().LayoutLine() );
       
   975                 
       
   976                 MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   977                 aGc.SetBrushStyle( CGraphicsContext::ESolidBrush ); 
       
   978                 // if we have transparent highlight, draw also background under highlight
       
   979                 if ( Background() )
       
   980                     {
       
   981                     Background()->Draw( aGc, *this, rect );
       
   982                     }
       
   983                 
       
   984                 drawOk = AknsDrawUtils::DrawFrame( skin, aGc, rect, innerRect.Rect(), 
       
   985                     KAknsIIDQsnFrList, KAknsIIDDefault );
       
   986     
       
   987                 //Both highlight animation and frame drawing failed. 
       
   988                 if ( !drawOk )
       
   989                     {
       
   990                     listRect.DrawRect( aGc ); 
       
   991                     innerRect.DrawRect( aGc ); 
       
   992                     }
   954                 }
   993                 }
   955             }
   994             }
   956         }
   995     
   957 
   996         if ( aHighlight == ERemoveHighlight && Background() )
   958     if ( aHighlight == ERemoveHighlight && Background() )
   997             {
   959         {
   998             Background()->Draw( aGc, *this, rect );
   960         Background()->Draw( aGc, *this, rect );
   999             }
   961         }
  1000     
   962 
  1001         TAknLayoutText layoutText; 
   963     TAknLayoutText layoutText; 
  1002         layoutText.LayoutText( rect, 
   964     layoutText.LayoutText( rect, 
  1003             AknLayoutScalable_Avkon::list_single_touch_menu_pane_t1().LayoutLine()); 
   965         AknLayoutScalable_Avkon::list_single_touch_menu_pane_t1().LayoutLine()); 
  1004     
   966 
  1005         MAknsSkinInstance* skin = AknsUtils::SkinInstance();
   967     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
  1006     
   968 
  1007         TRgb textColor(layoutText.Color()); 
   969     TRgb textColor(layoutText.Color()); 
  1008         AknsUtils::GetCachedColor( skin, textColor, KAknsIIDQsnTextColors,
   970     AknsUtils::GetCachedColor( skin, textColor, KAknsIIDQsnTextColors,
  1009                                        EAknsCIQsnTextColorsCG20 );
   971                                    EAknsCIQsnTextColorsCG20 );
  1010     
   972 
  1011         layoutText.DrawText( aGc, *(iItems[aItem]->iText), ETrue, textColor ); 
   973     layoutText.DrawText( aGc, *(iItems[aItem]->iText), ETrue, textColor ); 
  1012 
       
  1013         if ( aItem < iLastVisibleItem )
       
  1014             {
       
  1015             AknListUtils::DrawSeparator( aGc, rect, textColor );
       
  1016             }
       
  1017 		}
   974     }
  1018     }
   975 
  1019 
   976 // -----------------------------------------------------------------------------
  1020 // -----------------------------------------------------------------------------
   977 // CAknStylusPopUpMenuContent::StartAnimation
  1021 // CAknStylusPopUpMenuContent::StartAnimation
   978 // -----------------------------------------------------------------------------
  1022 // -----------------------------------------------------------------------------
  1039                                 CEikScrollBarFrame::EOff ) );
  1083                                 CEikScrollBarFrame::EOff ) );
  1040         return;
  1084         return;
  1041         }
  1085         }
  1042         
  1086         
  1043     TAknDoubleSpanScrollBarModel vsbarModel;
  1087     TAknDoubleSpanScrollBarModel vsbarModel;
  1044     TAknDoubleSpanScrollBarModel hsbarModel;
       
  1045     
  1088     
  1046     if ( iSBFrame->VScrollBarVisibility() != CEikScrollBarFrame::EOff )
  1089     if ( iSBFrame->VScrollBarVisibility() != CEikScrollBarFrame::EOff )
  1047         {
  1090         {
  1048         vsbarModel.iThumbPosition = thumbPos * singleItemHeight + Offset();
  1091         vsbarModel.iThumbPosition = thumbPos * singleItemHeight + Offset();
  1049         vsbarModel.iScrollSpan = visibleItems * singleItemHeight;
  1092         vsbarModel.iScrollSpan = visibleItems * singleItemHeight;
  1050         vsbarModel.iThumbSpan = fitsToMenu * singleItemHeight;
  1093         vsbarModel.iThumbSpan = fitsToMenu * singleItemHeight;
  1051             
  1094 
  1052         TEikScrollBarFrameLayout layout;
  1095         TAknLayoutRect scrollBarLayout;
  1053         layout.iTilingMode=TEikScrollBarFrameLayout::EInclusiveRectConstant;
  1096         scrollBarLayout.LayoutRect( listRect,
  1054         layout.SetClientMargin(0);
  1097                                     AknLayoutScalable_Avkon::scroll_pane() );
  1055         layout.SetInclusiveMargin(0);
  1098         TRect scrollBarRect( scrollBarLayout.Rect() );
  1056         
  1099         
  1057         TBool changed ( EFalse );
  1100         iSBFrame->Tile( &vsbarModel, scrollBarRect );
  1058         TRect clientRect( listRect );
  1101         
  1059         TRect inclusiveRect( listRect );
  1102         iSBFrame->DrawScrollBarsDeferred();
  1060         TRAP_IGNORE ( changed = iSBFrame->TileL( &hsbarModel, 
       
  1061                                                  &vsbarModel,
       
  1062                                                  clientRect, 
       
  1063                                                  inclusiveRect, 
       
  1064                                                  layout ) );
       
  1065         if ( changed )
       
  1066             {
       
  1067             iSBFrame->DrawScrollBarsDeferred();
       
  1068             }
       
  1069         }
  1103         }
  1070     }
  1104     }
  1071 
  1105 
  1072 // -----------------------------------------------------------------------------
  1106 // -----------------------------------------------------------------------------
  1073 // CAknStylusPopUpMenuContent::CalculateShownItems
  1107 // CAknStylusPopUpMenuContent::CalculateShownItems
  1243             itemRect.SetRect( TPoint( 0,0 ), TPoint( 0,0 ) );
  1277             itemRect.SetRect( TPoint( 0,0 ), TPoint( 0,0 ) );
  1244             }
  1278             }
  1245         iItems[i]->iRect = itemRect;
  1279         iItems[i]->iRect = itemRect;
  1246         }
  1280         }
  1247 
  1281 
  1248     return lastItem;    
  1282     if ( lastItem == iItems.Count() )
       
  1283         {
       
  1284         // substract the partially visible item
       
  1285         --lastItem;
       
  1286         }
       
  1287     
       
  1288     return lastItem; 
  1249     }
  1289     }
  1250 
  1290 
  1251 // ---------------------------------------------------------------------------
  1291 // ---------------------------------------------------------------------------
  1252 // From class CCoeControl
  1292 // From class CCoeControl
  1253 // CAknStylusPopUpMenuContent::SizeChanged
  1293 // CAknStylusPopUpMenuContent::SizeChanged
  1262     iPhysicsHandler->SetWorldHeight( WorldHeight() );
  1302     iPhysicsHandler->SetWorldHeight( WorldHeight() );
  1263     iPhysicsHandler->SetViewRect( Rect() );
  1303     iPhysicsHandler->SetViewRect( Rect() );
  1264 
  1304 
  1265     TRAP_IGNORE( InitPhysicsL() );
  1305     TRAP_IGNORE( InitPhysicsL() );
  1266         
  1306         
  1267     if ( CalculateShownItems( ENoScroll ) != KNoItemSelected )
  1307     if ( ( iLastVisibleItem = CalculateShownItems( ENoScroll ) ) != KNoItemSelected )
  1268         {
  1308         {
  1269         UpdateScrollBar();
  1309         UpdateScrollBar();
  1270         DrawNow();
  1310         DrawNow();
  1271         }
  1311         }
  1272     }
  1312     }
  1280     {
  1320     {
  1281     if ( AknLayoutUtils::PenEnabled() )
  1321     if ( AknLayoutUtils::PenEnabled() )
  1282         {
  1322         {
  1283         CWindowGc& gc = SystemGc();
  1323         CWindowGc& gc = SystemGc();
  1284 
  1324 
       
  1325         gc.SetClippingRect( Rect() );
       
  1326         
  1285         for ( TInt i=iFirstItem; i < iItems.Count(); i++ )
  1327         for ( TInt i=iFirstItem; i < iItems.Count(); i++ )
  1286             {
  1328             {
  1287             if ( iItems[i]->iVisibility != KHidden )
  1329             if ( iItems[i]->iVisibility != KHidden )
  1288                 {
  1330                 {
  1289                 DrawItem( gc, i, ( i == iCurrentItem ) ? EDrawHighlight : 
  1331                 DrawItem( gc, i, ( i == iCurrentItem ) ? EDrawHighlight : 
  1290                     ENoHighlight );
  1332                     ENoHighlight );
  1291                 }
  1333                 }
  1292             }
  1334             }
       
  1335         gc.CancelClippingRect();
  1293         }
  1336         }
  1294     }
  1337     }
  1295 
  1338 
  1296 
  1339 
  1297 // -----------------------------------------------------------------------------
  1340 // -----------------------------------------------------------------------------
  1400     if ( visibleItems == 0 )
  1443     if ( visibleItems == 0 )
  1401         {
  1444         {
  1402         return 0;
  1445         return 0;
  1403         }
  1446         }
  1404             
  1447             
  1405     TRect mainPaneRect;
       
  1406     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane,
       
  1407                                        mainPaneRect );
       
  1408     TAknWindowLineLayout listLayout = 
  1448     TAknWindowLineLayout listLayout = 
  1409        AknLayoutScalable_Avkon::list_single_touch_menu_pane(0).LayoutLine();
  1449        AknLayoutScalable_Avkon::list_single_touch_menu_pane(0).LayoutLine();
  1410  
       
  1411     TAknTextLineLayout textLayout = 
       
  1412        AknLayoutScalable_Avkon::list_single_touch_menu_pane_t1().LayoutLine();
       
  1413 
       
  1414     TAknWindowLineLayout unit = 
       
  1415        AknLayoutScalable_Avkon::aid_value_unit2().LayoutLine();
       
  1416     
  1450     
  1417     TInt singleItemHeight = listLayout.iH; 
  1451     TInt singleItemHeight = listLayout.iH; 
  1418     TInt height = singleItemHeight * visibleItems;
  1452     TInt height = singleItemHeight * visibleItems;
  1419     return height;
  1453     return height;
  1420     }
  1454     }