applicationinterworkingfw/ServiceHandler/src/AiwMenu.cpp
changeset 0 2f259fa3e83a
child 9 0aa5fbdfbc30
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2003-2005 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:     Implements AIW Menu utilities for providers to access consumer menu.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include <barsread.h> 
       
    22 #include <barsc.h> 
       
    23 #include <bautils.h>
       
    24 #include "AiwMenu.h"
       
    25 #include "AiwCommon.hrh"
       
    26 
       
    27 // This is needed for resource reading.
       
    28 const TInt KCCMask(0x00000fff);
       
    29 
       
    30 
       
    31 EXPORT_C CAiwMenuPane::CAiwMenuPane(CEikMenuPane& aMenuPane, TInt aBaseCmdId) 
       
    32 : iMenuPane(&aMenuPane), iBaseCmdId(aBaseCmdId)
       
    33     {
       
    34     iNextCmdId = aBaseCmdId;
       
    35     }
       
    36 
       
    37 
       
    38 EXPORT_C CAiwMenuPane::~CAiwMenuPane()
       
    39     {   
       
    40     delete iMenuPane;
       
    41     
       
    42     for(TInt i = 0; i < iIdMap.Count(); i++)
       
    43         {
       
    44         iIdMap[i].extraText.Close();
       
    45         }
       
    46     
       
    47     iIdMap.Reset();
       
    48     }
       
    49 
       
    50 
       
    51 EXPORT_C void CAiwMenuPane::AddMenuItemL(
       
    52     TInt aServiceCmd,
       
    53     CEikMenuPaneItem::SData& aMenuItem, 
       
    54     TInt aIndex)
       
    55     {
       
    56     AddMenuItemL(aServiceCmd, aMenuItem, aIndex, KNullDesC());
       
    57     }
       
    58     
       
    59     
       
    60 EXPORT_C void CAiwMenuPane::AddMenuItemL(
       
    61     TInt aServiceCmd,
       
    62     CEikMenuPaneItem::SData& aMenuItem, 
       
    63     TInt aIndex,
       
    64     const TDesC& aExtraText)
       
    65     {
       
    66     SMenuIdMap map;
       
    67 
       
    68     map.dynMenuCmdId = iNextCmdId + iPaneOffset;
       
    69     map.serviceCmdId = aServiceCmd;
       
    70     map.origCmdId = aMenuItem.iCommandId;
       
    71     map.owner = iInitializingOwner;
       
    72     map.extraText.Assign(aExtraText.AllocL());
       
    73     CleanupClosePushL(map.extraText);
       
    74 
       
    75     aMenuItem.iCommandId = iNextCmdId + iPaneOffset;
       
    76     iNextCmdId++;
       
    77 
       
    78     iMenuPane->InsertMenuItemL(aMenuItem, aIndex); 
       
    79     User::LeaveIfError(iIdMap.Append( map ));
       
    80     CleanupStack::Pop(); // map.extraText
       
    81     }    
       
    82 
       
    83 
       
    84     
       
    85 EXPORT_C void CAiwMenuPane::AddMenuItemsL(
       
    86     TResourceReader& aReader,
       
    87     TInt aServiceCmd,
       
    88     TInt aIndex,
       
    89     TBool /*aAddSeperator*/)
       
    90     {
       
    91     CEikMenuPaneItem::SData data;
       
    92 
       
    93     TInt index = aIndex;
       
    94    
       
    95     TInt count = aReader.ReadInt16();
       
    96     for (TInt i = 0; i < count; i++)
       
    97         {
       
    98         data.iCommandId = aReader.ReadInt32();
       
    99         data.iCascadeId = aReader.ReadInt32();  
       
   100         data.iFlags = aReader.ReadInt32();
       
   101         data.iText.Copy(aReader.ReadTPtrC());
       
   102         
       
   103         // Extra text (additional submenu text) must be handled separately
       
   104         // because SData doesn't offer space for it.
       
   105         TPtrC extraText = aReader.ReadTPtrC();
       
   106         
       
   107         aReader.ReadTPtrC(); // Skip bmpfile.
       
   108         aReader.ReadInt16(); // Skip bmpid.
       
   109         aReader.ReadInt16(); // Skip bmpmask. 
       
   110         aReader.ReadInt32(); // Skip extension.   
       
   111 
       
   112         if (data.iCommandId == AIW_SUBMENU_TITLE)
       
   113             {
       
   114             AddTitleItemL(data.iText, index);
       
   115             }
       
   116         else
       
   117             {
       
   118             AddMenuItemL(aServiceCmd, data, index++, extraText);
       
   119             }
       
   120         } 
       
   121     }
       
   122 
       
   123 
       
   124   
       
   125 EXPORT_C void CAiwMenuPane::AddMenuItemsL(
       
   126     TFileName& aFileName,
       
   127     TInt aResId,
       
   128     TInt aServiceCmd,
       
   129     TInt aIndex,
       
   130     TBool aAddSeparator)
       
   131     {
       
   132     TResourceReader reader; 
       
   133 
       
   134     RFs fsSession;
       
   135     User::LeaveIfError( fsSession.Connect() );
       
   136     CleanupClosePushL( fsSession );
       
   137 
       
   138     BaflUtils::NearestLanguageFile(fsSession, aFileName);
       
   139 
       
   140     RResourceFile rsFile;
       
   141     rsFile.OpenL( fsSession, aFileName );
       
   142     CleanupClosePushL( rsFile );
       
   143 
       
   144     // Read multitapping resource.
       
   145     HBufC8* rBuffer = rsFile.AllocReadLC(aResId & KCCMask); // Remove offset from id
       
   146     reader.SetBuffer( rBuffer );
       
   147 
       
   148     AddMenuItemsL(reader, aServiceCmd, aIndex, aAddSeparator);
       
   149 
       
   150     CleanupStack::PopAndDestroy(3);  // rBuffer, rsFile, fsSession
       
   151     }
       
   152 
       
   153 
       
   154 
       
   155 EXPORT_C TInt CAiwMenuPane::MenuCmdId(TInt aDynCmdId) const
       
   156     {
       
   157     for (TInt i = 0; i < iIdMap.Count(); i++)
       
   158         {
       
   159         if (iIdMap[i].dynMenuCmdId == aDynCmdId)
       
   160             {
       
   161             return iIdMap[i].origCmdId;
       
   162             }
       
   163         }
       
   164 
       
   165     return 0;
       
   166     }
       
   167 
       
   168     
       
   169 
       
   170 EXPORT_C TInt CAiwMenuPane::DynCmdId(TInt aMenuCmdId) const
       
   171     {
       
   172     for (TInt i = 0; i < iIdMap.Count(); i++)
       
   173         {
       
   174         if (iIdMap[i].origCmdId == aMenuCmdId)
       
   175             {
       
   176             return iIdMap[i].dynMenuCmdId;
       
   177             }
       
   178         }
       
   179 
       
   180     return 0;
       
   181     }
       
   182 
       
   183 
       
   184 
       
   185 EXPORT_C TInt CAiwMenuPane::ServiceCmdId(TInt aDynCmdId) const
       
   186     {
       
   187     for (TInt i = 0; i < iIdMap.Count(); i++)
       
   188         {
       
   189         if (iIdMap[i].dynMenuCmdId == aDynCmdId)
       
   190             {
       
   191             return iIdMap[i].serviceCmdId;
       
   192             }
       
   193         }
       
   194 
       
   195     return 0; 
       
   196     }
       
   197 
       
   198 
       
   199 
       
   200 TInt CAiwMenuPane::FindCmdId(TInt aIndex)
       
   201     {
       
   202     TInt index;
       
   203 
       
   204     for (TInt i = 0; i < iIdMap.Count(); i++)
       
   205         {
       
   206         if (iMenuPane->MenuItemExists(iIdMap[i].dynMenuCmdId, index))   
       
   207             {
       
   208             if (aIndex == index)
       
   209                 {
       
   210                 return iIdMap[i].dynMenuCmdId;
       
   211                 }
       
   212             }
       
   213         }
       
   214 
       
   215     return -1;
       
   216     }
       
   217 
       
   218 
       
   219 
       
   220 EXPORT_C void CAiwMenuPane::AddTitleItemL(const TDesC& aTitle, TInt aIndex) 
       
   221     {
       
   222     CEikMenuPaneItem::SData data;
       
   223     
       
   224     data.iCommandId = AIW_SUBMENU_TITLE;
       
   225     data.iCascadeId = 0;  
       
   226     data.iFlags = 0;
       
   227     data.iText.Copy(aTitle);
       
   228 
       
   229     iMenuPane->InsertMenuItemL(data, aIndex);       
       
   230     }
       
   231 
       
   232 
       
   233 TBool CAiwMenuPane::IsCmdInRange(TInt aCmdSpaceSize, TInt aCmd)
       
   234     {
       
   235     if ((aCmd >= iPaneOffset + iBaseCmdId) &&
       
   236         (aCmd < iPaneOffset + iBaseCmdId + aCmdSpaceSize))
       
   237         {
       
   238         return ETrue;
       
   239         }
       
   240 
       
   241     return EFalse;
       
   242     }
       
   243 
       
   244 
       
   245 CAiwServiceIfBase* CAiwMenuPane::CommandOwner(TInt aDynCmd) const
       
   246     {
       
   247     for (TInt i = 0; i < iIdMap.Count(); i++)
       
   248         {
       
   249         if (iIdMap[i].dynMenuCmdId == aDynCmd)
       
   250             {
       
   251             return iIdMap[i].owner;
       
   252             }
       
   253         }   
       
   254 
       
   255     return NULL;
       
   256     }
       
   257     
       
   258     
       
   259 const TDesC& CAiwMenuPane::ExtraText(TInt aDynMenuCmdId)
       
   260     {
       
   261     TInt count = iIdMap.Count();
       
   262     for(TInt i = 0; i < count; i++)
       
   263         {
       
   264         if(iIdMap[i].dynMenuCmdId == aDynMenuCmdId)
       
   265             {
       
   266             return iIdMap[i].extraText;
       
   267             }
       
   268         }
       
   269     return KNullDesC;        
       
   270     }
       
   271 
       
   272 // End of file