browserui/browser/BrowserAppSrc/BrowserShortcutKeyMap.cpp
changeset 0 84ad3b177aa3
child 10 4530440261a8
equal deleted inserted replaced
-1:000000000000 0:84ad3b177aa3
       
     1 /*
       
     2 * Copyright (c) 2007 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 the License "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:  Browser View
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <aknutils.h>
       
    20 #include <gulicon.h>
       
    21 #include <StringLoader.h>
       
    22 #include <data_caging_path_literals.hrh>
       
    23 #include <eikbtgpc.h>
       
    24 #include <eikapp.h>
       
    25 #include <AknsUtils.h>
       
    26 #include <e32math.h>
       
    27 #include <browser.mbg>
       
    28 #include "BrowserShortcutKeyMap.h"
       
    29 #include "BrowserContentViewContainer.h"
       
    30 #include "BrowserPreferences.h"
       
    31 #include "BrowserWindowManager.h"
       
    32 #include "BrowserWindow.h"
       
    33 #include "ApiProvider.h"
       
    34 #include "BrowserUIVariant.hrh"
       
    35 #include "BrowserAppUi.h"
       
    36 
       
    37 // CONSTANTS
       
    38 _LIT( KKeyMapSvgFile, "browser.mif" );
       
    39 
       
    40 // Value table for 70% Transparency
       
    41 const TInt KTransparency[256] =
       
    42     {
       
    43     0, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 7, 7, 7,
       
    44     8, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 13, 13, 13,
       
    45     14, 14, 14, 14, 15, 15, 15, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 19,
       
    46     19, 19, 20, 20, 20, 20, 21, 21, 21, 22, 22, 22, 23, 23, 23, 23, 24, 24,
       
    47     24, 25, 25, 25, 26, 26, 26, 26, 27, 27, 27, 28, 28, 28, 29, 29, 29, 29,
       
    48     30, 30, 30, 31, 31, 31, 32, 32, 32, 32, 33, 33, 33, 34, 34, 34, 35, 35,
       
    49     35, 35, 36, 36, 36, 37, 37, 37, 38, 38, 38, 38, 39, 39, 39, 40, 40, 40,
       
    50     41, 41, 41, 41, 42, 42, 42, 43, 43, 43, 44, 44, 44, 44, 45, 45, 45, 46,
       
    51     46, 46, 47, 47, 47, 47, 48, 48, 48, 49, 49, 49, 50, 50, 50, 50, 51, 51,
       
    52     51, 52, 52, 52, 53, 53, 53, 53, 54, 54, 54, 55, 55, 55, 56, 56, 56, 56,
       
    53     57, 57, 57, 58, 58, 58, 59, 59, 59, 59, 60, 60, 60, 61, 61, 61, 62, 62,
       
    54     62, 62, 63, 63, 63, 64, 64, 64, 65, 65, 65, 65, 66, 66, 66, 67, 67, 67,
       
    55     68, 68, 68, 68, 69, 69, 69, 70, 70, 70, 71, 71, 71, 71, 72, 72, 72, 73,
       
    56     73, 73, 74, 74, 74, 74, 75, 75, 75, 76, 76, 76, 77, 77
       
    57     };
       
    58 
       
    59 
       
    60 // keymap is 3x4
       
    61 #define KNumCellsX 3
       
    62 #define KNumCellsY 4
       
    63 #define KNumCells  12
       
    64 
       
    65 // spacing in pixels for scroll bars
       
    66 #define KKeymapHScrollbarSize 4
       
    67 #define KKeymapVScrollbarSize 4
       
    68 
       
    69 // sizing for entire keymap (not counting scrollbar)
       
    70 // as a percentage of vertical screen size, and an aspect ratio width/height
       
    71 #define KKeymapVSize 0.90
       
    72 #define KKeymapHVAspectRatio 0.88
       
    73 #define KKeymapHSize 0.90
       
    74 
       
    75 // margins for each cell
       
    76 #define KCellTopMargin    2
       
    77 #define KCellRightMargin  5
       
    78 #define KCellBotMargin    2
       
    79 #define KCellLeftMargin   5
       
    80 
       
    81 // Create constant icon assignments for each command
       
    82 // note that this follows TShortcutsCommandDecodeEntry in BrowserPreferences.h
       
    83 
       
    84 typedef const TInt TShortcutsIconAndTextDecodeEntry[2];
       
    85 
       
    86 #define KShortcutsIconAndTextAssignmentSize 22
       
    87 #define KShortcutsIconAndTextDecodeMatrixText  0  // First entry is the Text
       
    88 #define KShortcutsIconAndTextDecodeMatrixIcon  1  // Second entry is the Icon
       
    89 
       
    90 static const TShortcutsIconAndTextDecodeEntry KShortcutsIconAndTextAssignmentMatrix[] =
       
    91 {
       
    92     /* 0   EWmlNoCmd,                       */  { R_BROWSER_KEYMAP_TEXT_NONE,               EMbmBrowserQgn_indi_browser_tb_key_map      },
       
    93     /* 1   EWmlCmdHelp,                     */  { R_BROWSER_KEYMAP_TEXT_SHOW_HELP,          EMbmBrowserQgn_indi_browser_tb_help         },
       
    94     /* 2   EWmlCmdSwitchWindow,             */  { R_BROWSER_KEYMAP_TEXT_SWITCH_WINDOW,      EMbmBrowserQgn_indi_browser_tb_switch_win   },
       
    95     /* 3   EWmlCmdSavePage,                 */  { R_BROWSER_KEYMAP_TEXT_SAVE_PAGE,          EMbmBrowserQgn_indi_browser_tb_save_page    },
       
    96     /* 4   EWmlCmdShowImages,               */  { R_BROWSER_KEYMAP_TEXT_VIEW_IMAGES,        EMbmBrowserQgn_indi_browser_tb_view_images  },
       
    97     /* 5   EWmlCmdHistory,                  */  { R_BROWSER_KEYMAP_TEXT_VISUAL_HISTORY,     EMbmBrowserQgn_indi_browser_tb_view_pages   },
       
    98     /* 6   EWmlCmdFavourites,               */  { R_BROWSER_KEYMAP_TEXT_MANAGE_BOOKMARKS,   EMbmBrowserQgn_indi_browser_tb_bm           },
       
    99     /* 7   EWmlCmdShowSubscribeList,        */  { R_BROWSER_KEYMAP_TEXT_SUBSCRIBE_TO_FEEDS, EMbmBrowserQgn_indi_browser_tb_rss          },
       
   100     /* 8   EWmlCmdRotateDisplay,            */  { R_BROWSER_KEYMAP_TEXT_ROTATE_SCREEN,      EMbmBrowserQgn_indi_browser_tb_rotate       },
       
   101     /* 9   EWmlCmdPreferences,              */  { R_BROWSER_KEYMAP_TEXT_SETTINGS,           EMbmBrowserQgn_indi_browser_tb_settings     },
       
   102     /* 10  EWmlCmdZoomOut,                  */  { R_BROWSER_KEYMAP_TEXT_ZOOM_OUT,           EMbmBrowserQgn_indi_browser_tb_zoom_out     },
       
   103     /* 11  EWmlCmdZoomIn,                   */  { R_BROWSER_KEYMAP_TEXT_ZOOM_IN,            EMbmBrowserQgn_indi_browser_tb_zoom_in      },
       
   104     /* 12  EWmlCmdLaunchHomePage,           */  { R_BROWSER_KEYMAP_TEXT_GO_TO_HOMEPAGE,     EMbmBrowserQgn_indi_browser_tb_home         },
       
   105     /* 13  EWmlCmdOneStepBack,              */  { R_BROWSER_KEYMAP_TEXT_PREVIOUS_PAGE,      EMbmBrowserQgn_indi_browser_tb_back         },
       
   106     /* 14  EWmlCmdShowMiniature,            */  { R_BROWSER_KEYMAP_TEXT_MINIATURE_SHOW,     EMbmBrowserQgn_indi_browser_tb_page         },
       
   107     /* 15  EWmlCmdReload,                   */  { R_BROWSER_KEYMAP_TEXT_RELOAD,             EMbmBrowserQgn_indi_browser_tb_reload       },
       
   108     /* 16  EWmlCmdFindKeyword,              */  { R_BROWSER_KEYMAP_TEXT_FIND_KEYWORD,       EMbmBrowserQgn_indi_browser_tb_find_kw      },
       
   109     /* 17  EWmlCmdSaveAsBookmark,           */  { R_BROWSER_KEYMAP_TEXT_SAVE_AS_BOOKMARK,   EMbmBrowserQgn_indi_browser_tb_save_bm      },
       
   110     /* 18  EWmlCmdGoToAddress,              */  { R_BROWSER_KEYMAP_TEXT_GO_TO_WEB_ADDRESS,  EMbmBrowserQgn_indi_browser_tb_goto         },
       
   111     /* 19  EWmlCmdShowToolBar,              */  { R_BROWSER_KEYMAP_TEXT_SHOW_TOOLBAR,       EMbmBrowserQgn_indi_browser_tb_tb           },
       
   112     /* 20  EWmlCmdShowShortcutKeymap,       */  { R_BROWSER_KEYMAP_TEXT_SHOW_KEYMAP,        EMbmBrowserQgn_indi_browser_tb_key_map      },
       
   113     /* 21  EWmlCmdEnterFullScreenBrowsing,  */  { R_BROWSER_KEYMAP_TEXT_FULL_SCREEN,        EMbmBrowserQgn_indi_button_exit_fs          },
       
   114 };
       
   115 
       
   116 // key assignments
       
   117 static const TInt KDialpadAssignments[] =
       
   118 {
       
   119     /*  0  */ R_BROWSER_KEYMAP_KEY0,
       
   120     /*  1  */ R_BROWSER_KEYMAP_KEY1,
       
   121     /*  2  */ R_BROWSER_KEYMAP_KEY2,
       
   122     /*  3  */ R_BROWSER_KEYMAP_KEY3,
       
   123     /*  4  */ R_BROWSER_KEYMAP_KEY4,
       
   124     /*  5  */ R_BROWSER_KEYMAP_KEY5,
       
   125     /*  6  */ R_BROWSER_KEYMAP_KEY6,
       
   126     /*  7  */ R_BROWSER_KEYMAP_KEY7,
       
   127     /*  8  */ R_BROWSER_KEYMAP_KEY8,
       
   128     /*  9  */ R_BROWSER_KEYMAP_KEY9,
       
   129     /* 10  */ R_BROWSER_KEYMAP_KEY10,
       
   130     /* 11  */ R_BROWSER_KEYMAP_KEY11
       
   131 };
       
   132 
       
   133 // ============================= LOCAL FUNCTIONS ===============================
       
   134 
       
   135 // ============================ MEMBER FUNCTIONS ===============================
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 // TKeymapCellData::TKeymapCellData
       
   139 // TKeymapCellData Utility Class constructor
       
   140 // -----------------------------------------------------------------------------
       
   141 
       
   142 TKeymapCellData::TKeymapCellData() :
       
   143     keyText(NULL),
       
   144     lineText(NULL),
       
   145     cmdRscId(NULL),
       
   146     keyBitmapImage(NULL),
       
   147     keyBitmapMask(NULL)
       
   148     {
       
   149     }
       
   150 
       
   151 
       
   152 // -----------------------------------------------------------------------------
       
   153 // TKeymapCellData::TKeymapCellData
       
   154 // TKeymapCellData Utility Class destructor
       
   155 // -----------------------------------------------------------------------------
       
   156 TKeymapCellData::~TKeymapCellData()
       
   157     {
       
   158     if(keyText) delete keyText;
       
   159     if(lineText) delete lineText;
       
   160     if(keyBitmapImage) delete keyBitmapImage;
       
   161     if(keyBitmapMask) delete keyBitmapMask;
       
   162     }
       
   163 
       
   164 // -----------------------------------------------------------------------------
       
   165 // CBrowserShortcutKeyMap::NewL
       
   166 // The two-phase Symbian constructor
       
   167 // -----------------------------------------------------------------------------
       
   168 //
       
   169 CBrowserShortcutKeyMap* CBrowserShortcutKeyMap::NewL( CBrowserContentViewContainer* aContentViewContainer, MApiProvider& aApiProvider )
       
   170     {
       
   171     CBrowserShortcutKeyMap* self = new (ELeave) CBrowserShortcutKeyMap( aContentViewContainer, aApiProvider );
       
   172     CleanupStack::PushL(self);
       
   173     self->ConstructL();
       
   174     CleanupStack::Pop(); //self
       
   175     return self;
       
   176     }
       
   177 
       
   178 
       
   179 
       
   180 // -----------------------------------------------------------------------------
       
   181 // Destructor
       
   182 // -----------------------------------------------------------------------------
       
   183 CBrowserShortcutKeyMap::~CBrowserShortcutKeyMap()
       
   184     {
       
   185     // Close out array and delete data members
       
   186     iCellData.Close();
       
   187 
       
   188     // cleanup svg mbm file name
       
   189     if(iSvgMbmFile)
       
   190         {
       
   191         delete iSvgMbmFile;
       
   192         iSvgMbmFile = NULL;
       
   193         }
       
   194 
       
   195     // Cleanup Sprite data
       
   196     iSprite.Close();
       
   197     if(iSpriteBitmapDevice)
       
   198         {
       
   199         delete iSpriteBitmapDevice;
       
   200         iSpriteBitmapDevice = NULL;
       
   201         }
       
   202     if(iSpriteBitmapContext)
       
   203         {
       
   204         delete iSpriteBitmapContext;
       
   205         iSpriteBitmapContext = NULL;
       
   206         }
       
   207     if(iSpriteBitmap)
       
   208         {
       
   209         delete iSpriteBitmap;
       
   210         iSpriteBitmap = NULL;
       
   211         }
       
   212 
       
   213     if(iSpriteMaskBitmapDevice)
       
   214         {
       
   215         delete iSpriteMaskBitmapDevice;
       
   216         iSpriteMaskBitmapDevice = NULL;
       
   217         }
       
   218     if(iSpriteMaskBitmapContext)
       
   219         {
       
   220         delete iSpriteMaskBitmapContext;
       
   221         iSpriteMaskBitmapContext = NULL;
       
   222         }
       
   223     if(iSpriteMaskBitmap)
       
   224         {
       
   225         delete iSpriteMaskBitmap;
       
   226         iSpriteMaskBitmap = NULL;
       
   227         }
       
   228 
       
   229     }
       
   230 
       
   231 
       
   232 
       
   233 // -----------------------------------------------------------------------------
       
   234 // CBrowserShortcutKeyMap::CBrowserShortcutKeyMap
       
   235 // C++ default constructor can NOT contain any code, that
       
   236 // might leave.
       
   237 // -----------------------------------------------------------------------------
       
   238 //
       
   239 CBrowserShortcutKeyMap::CBrowserShortcutKeyMap( CBrowserContentViewContainer* aContentViewContainer, MApiProvider& aApiProvider )
       
   240     : iContentViewContainer( aContentViewContainer ), iApiProvider( aApiProvider )
       
   241     {
       
   242     }
       
   243 
       
   244 
       
   245 
       
   246 // -----------------------------------------------------------------------------
       
   247 // CBrowserShortcutKeyMap::ConstructL
       
   248 // The constructor that can contain code that might leave.
       
   249 // -----------------------------------------------------------------------------
       
   250 //
       
   251 void CBrowserShortcutKeyMap::ConstructL()
       
   252     {
       
   253     //LoadResourceFileL();
       
   254     iSvgMbmFile = GetCannedImageDirL();
       
   255     iSvgMbmFile->Des().Append( KKeyMapSvgFile );
       
   256 
       
   257     InitKeymap();
       
   258     CreateBitmapAndContextL();
       
   259     ConstructSprite();
       
   260     }
       
   261 
       
   262 
       
   263 
       
   264 // -----------------------------------------------------------------------------
       
   265 // CBrowserShortcutKeyMap::InitKeymap
       
   266 // Initialize Keymap properties
       
   267 // -----------------------------------------------------------------------------
       
   268 //
       
   269 void CBrowserShortcutKeyMap::InitKeymap()
       
   270     {
       
   271     // derive keymap's size from the container's size
       
   272     iTargetRect = iContentViewContainer->Rect();
       
   273 
       
   274     // resize it to account for scrollbar width/height
       
   275     iTargetRect.Resize(-TSize(KKeymapHScrollbarSize,KKeymapVScrollbarSize));
       
   276 
       
   277     //
       
   278     // derive shrink amounts based on keymap size constants and shrink the rect
       
   279     //
       
   280     TInt newHeight = (KKeymapVSize * iTargetRect.Size().iHeight);
       
   281     //TInt newWidth = (KKeymapHSize * iTargetRect.Size().iWidth);
       
   282     TInt newWidth = newHeight * KKeymapHVAspectRatio;
       
   283 
       
   284     if(newWidth > KKeymapHSize * iTargetRect.Size().iWidth)
       
   285         {
       
   286         newWidth = (KKeymapHSize * iTargetRect.Size().iWidth);
       
   287         }
       
   288 
       
   289     // shrink the height and width slightly
       
   290     // as necessary to be evenly divisible by the rows/cols later on
       
   291     TReal remainder;
       
   292     TInt result;
       
   293     result = Math::Mod(remainder,newWidth,KNumCellsX);
       
   294     if((result == KErrNone) && (remainder != 0))
       
   295         {
       
   296         newWidth -= remainder;
       
   297         }
       
   298     result = Math::Mod(remainder,newHeight,KNumCellsY);
       
   299     if((result == KErrNone) && (remainder != 0))
       
   300         {
       
   301         newHeight -= remainder;
       
   302         }
       
   303     TInt hShrink = (iTargetRect.Size().iWidth - newWidth)/2;
       
   304     TInt vShrink = (iTargetRect.Size().iHeight - newHeight)/2;
       
   305     iTargetRect.Shrink(TSize(hShrink,vShrink));
       
   306 
       
   307     // Set font types
       
   308     iLineFont = LatinPlain12();
       
   309     iKeyFont = LatinBold16();
       
   310 
       
   311     // init cell data
       
   312     InitCellDataL();
       
   313     }
       
   314 
       
   315 
       
   316 
       
   317 // -----------------------------------------------------------------------------
       
   318 // CBrowserShortcutKeyMap::InitCellDataL
       
   319 // Initialize Keymap data kept for each cell of the map
       
   320 // -----------------------------------------------------------------------------
       
   321 
       
   322 void CBrowserShortcutKeyMap::InitCellDataL()
       
   323     {
       
   324     for(TInt i = 0; i < KNumCells; i++)
       
   325         {
       
   326         TKeymapCellData* cellData = new (ELeave) TKeymapCellData();
       
   327 
       
   328         TInt shortcutAssign;
       
   329 
       
   330         // get the shortcut assignment from Browser Prefs
       
   331         switch(i)
       
   332             {
       
   333             case 0:
       
   334                 shortcutAssign = iApiProvider.Preferences().ShortcutKey1Cmd();
       
   335                 break;
       
   336             case 1:
       
   337                 shortcutAssign = iApiProvider.Preferences().ShortcutKey2Cmd();
       
   338                 break;
       
   339             case 2:
       
   340                 shortcutAssign = iApiProvider.Preferences().ShortcutKey3Cmd();
       
   341                 break;
       
   342             case 3:
       
   343                 shortcutAssign = iApiProvider.Preferences().ShortcutKey4Cmd();
       
   344                 break;
       
   345             case 4:
       
   346                 shortcutAssign = iApiProvider.Preferences().ShortcutKey5Cmd();
       
   347                 break;
       
   348             case 5:
       
   349                 shortcutAssign = iApiProvider.Preferences().ShortcutKey6Cmd();
       
   350                 break;
       
   351             case 6:
       
   352                 shortcutAssign = iApiProvider.Preferences().ShortcutKey7Cmd();
       
   353                 break;
       
   354             case 7:
       
   355                 shortcutAssign = iApiProvider.Preferences().ShortcutKey8Cmd();
       
   356                 break;
       
   357             case 8:
       
   358                 shortcutAssign = iApiProvider.Preferences().ShortcutKey9Cmd();
       
   359                 break;
       
   360             case 9:
       
   361                 shortcutAssign = iApiProvider.Preferences().ShortcutKeyStarCmd();
       
   362                 break;
       
   363             case 10:
       
   364                 shortcutAssign = iApiProvider.Preferences().ShortcutKey0Cmd();
       
   365                 break;
       
   366             case 11:
       
   367                 shortcutAssign = iApiProvider.Preferences().ShortcutKeyHashCmd();
       
   368                 break;
       
   369             default:
       
   370                 shortcutAssign = iApiProvider.Preferences().ShortcutKey1Cmd();
       
   371                 break;
       
   372             }
       
   373 
       
   374         cellData->cmdRscId = KShortcutsIconAndTextAssignmentMatrix[shortcutAssign][KShortcutsIconAndTextDecodeMatrixText];
       
   375         cellData->lineText = StringLoader::LoadLC(cellData->cmdRscId);
       
   376 
       
   377         // get shortcut key assignments and set dialpad assignments
       
   378         cellData->keyText = StringLoader::LoadLC(KDialpadAssignments[i]);
       
   379 
       
   380         // load the icon its mask (use a default if we're out of range)
       
   381         TInt iconId = EMbmBrowserQgn_indi_browser_tb_key_map;
       
   382         if(shortcutAssign < KShortcutsIconAndTextAssignmentSize)
       
   383             {
       
   384             iconId = KShortcutsIconAndTextAssignmentMatrix[shortcutAssign][KShortcutsIconAndTextDecodeMatrixIcon];
       
   385             }
       
   386 
       
   387         if(shortcutAssign == NULL)
       
   388             {
       
   389             cellData->keyBitmapImage = NULL;
       
   390             cellData->keyBitmapMask = NULL;
       
   391             }
       
   392         else
       
   393             {
       
   394             LoadSvg(iconId,
       
   395                     *iSvgMbmFile,
       
   396                     cellData->keyBitmapImage,
       
   397                     cellData->keyBitmapMask);
       
   398             }
       
   399 
       
   400         // add to the data array
       
   401         iCellData.Append(cellData);
       
   402 
       
   403         // remove keytext, linetext from stack
       
   404         CleanupStack::Pop(2);
       
   405         }
       
   406     }
       
   407 
       
   408 
       
   409 
       
   410 // -----------------------------------------------------------------------------
       
   411 // CBrowserShortcutKeyMap::CreateBitmapAndContextL
       
   412 // Create the bitmap and context that will be used for the sprite
       
   413 // -----------------------------------------------------------------------------
       
   414 //
       
   415 void CBrowserShortcutKeyMap::CreateBitmapAndContextL()
       
   416     {
       
   417     // Create Sprite Bitmap
       
   418     iSpriteBitmap = new (ELeave) CFbsBitmap;
       
   419     User::LeaveIfError( iSpriteBitmap->Create( iTargetRect.Size(), EColor16MA ) );
       
   420 
       
   421     iSpriteBitmapDevice = CFbsBitmapDevice::NewL( iSpriteBitmap );
       
   422     User::LeaveIfError( iSpriteBitmapDevice->CreateContext( iSpriteBitmapContext ) );
       
   423 
       
   424     // Create Mask Bitmap
       
   425     iSpriteMaskBitmap = new (ELeave) CFbsBitmap;
       
   426     User::LeaveIfError( iSpriteMaskBitmap->Create( iTargetRect.Size(), EColor16MA ) );
       
   427     iSpriteMaskBitmapDevice = CFbsBitmapDevice::NewL( iSpriteMaskBitmap );
       
   428     User::LeaveIfError( iSpriteMaskBitmapDevice->CreateContext( iSpriteMaskBitmapContext ) );
       
   429 
       
   430     TRect r( TPoint( 0, 0 ), iSpriteMaskBitmap->SizeInPixels());
       
   431 
       
   432     iSpriteMaskBitmapContext->SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   433     iSpriteMaskBitmapContext->SetPenStyle( CGraphicsContext::ESolidPen );
       
   434     iSpriteMaskBitmapContext->SetBrushColor( TRgb( 0, 0, 0) );
       
   435     iSpriteMaskBitmapContext->SetPenColor( TRgb( 0, 0, 0) );
       
   436     iSpriteMaskBitmapContext->DrawRect(r);
       
   437 
       
   438     // Draw the rectangular outline
       
   439     iSpriteBitmapContext->SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   440     iSpriteBitmapContext->SetPenStyle( CGraphicsContext::ESolidPen );
       
   441     iSpriteBitmapContext->SetBrushColor( TRgb( 242, 244, 242) );
       
   442     iSpriteBitmapContext->SetPenColor( TRgb( 100, 100, 0) );
       
   443     iSpriteBitmapContext->SetPenSize( TSize(2,2) );
       
   444     iSpriteBitmapContext->DrawRect(r);
       
   445 
       
   446     TSize cellSize(r.Width()/KNumCellsX,r.Height()/KNumCellsY);
       
   447 
       
   448     for(TInt i = 0; i < KNumCellsY; i++)
       
   449         {
       
   450         for(TInt j = 0; j < KNumCellsX; j++)
       
   451             {
       
   452             TInt cellIndex(i*KNumCellsX + j);
       
   453             CreateCellLayout( cellIndex, TPoint(j*cellSize.iWidth,i*cellSize.iHeight),cellSize);
       
   454             CreateSpriteCellL( cellIndex );
       
   455             }
       
   456         }
       
   457     }
       
   458 
       
   459 
       
   460 
       
   461 // -----------------------------------------------------------------------------
       
   462 // CBrowserShortcutKeyMap::CreateCellLayout
       
   463 // Calculate the layout of the sprite rects for a given cell
       
   464 // -----------------------------------------------------------------------------
       
   465 
       
   466 void CBrowserShortcutKeyMap::CreateCellLayout(const TInt& aCellIndex, const TPoint& aUpperL, const TSize& aSize)
       
   467     {
       
   468     // Create pointer for easy access curr Cell
       
   469     TKeymapCellData* pCurrCell = iCellData[aCellIndex];
       
   470 
       
   471     // Create rect for Cell
       
   472     pCurrCell->r.SetRect(aUpperL, aSize);
       
   473 
       
   474     // Internally, Our Cell is sized accounting for margin
       
   475     // Setup this
       
   476     TPoint marginOffset(KCellLeftMargin, KCellTopMargin);
       
   477     TSize marginSize(KCellLeftMargin + KCellRightMargin, KCellTopMargin + KCellBotMargin);
       
   478     pCurrCell->rCell.SetRect( aUpperL + marginOffset, aSize - marginSize );
       
   479 
       
   480     // Upper LH key indicator
       
   481     TInt keyFontHeight = iKeyFont->HeightInPixels() + iKeyFont->DescentInPixels();
       
   482     pCurrCell->rKey.SetRect( pCurrCell->rCell.iTl, TSize(keyFontHeight, iKeyFont->MaxCharWidthInPixels()) );
       
   483 
       
   484     // Prep the line rects, calculating the position based upon the font size
       
   485     TInt lineFontHeight = iLineFont->HeightInPixels() + iLineFont->DescentInPixels();
       
   486     TSize lineSize(pCurrCell->rCell.Width(),lineFontHeight);
       
   487     TPoint lineAreaUpperLH(pCurrCell->rCell.iTl.iX, pCurrCell->rCell.iBr.iY - (2*lineSize.iHeight));
       
   488 
       
   489     // Set this point to be the upper left of the line(s) of text.
       
   490     // If we have two lines, this will be the upperLH of Line1
       
   491     // If we have one line, this will be the upperLH of Line2
       
   492     // This, we will use to set the rect size of the icon later
       
   493     pCurrCell->rLine1.SetRect(lineAreaUpperLH,lineSize);
       
   494     pCurrCell->rLine2.SetRect(lineAreaUpperLH + TPoint(0,lineSize.iHeight),lineSize);
       
   495     TPoint linesUpperLH = pCurrCell->rLine1.iTl;
       
   496 
       
   497     // CREATE the icon area from what is left over
       
   498     TPoint iconUpperLH(pCurrCell->rCell.iTl + TPoint(pCurrCell->rKey.Size().iWidth,0));
       
   499     TPoint iconLowerRH(pCurrCell->rCell.iBr.iX,linesUpperLH.iY);
       
   500     pCurrCell->rIcon.SetRect(iconUpperLH,iconLowerRH);
       
   501 
       
   502     // resize the icon rect to be square if its not already... according to its smallest dimension
       
   503     if(pCurrCell->rIcon.Height() > pCurrCell->rIcon.Width())
       
   504         {
       
   505         TSize sizeChange(0,pCurrCell->rIcon.Width() - pCurrCell->rIcon.Height());
       
   506         pCurrCell->rIcon.Resize(sizeChange);
       
   507         pCurrCell->rIcon.Move(TPoint(0,-sizeChange.iHeight/2));
       
   508         }
       
   509     else if(pCurrCell->rIcon.Width() > pCurrCell->rIcon.Height())
       
   510         {
       
   511         TSize sizeChange(pCurrCell->rIcon.Height() - pCurrCell->rIcon.Width(),0);
       
   512         pCurrCell->rIcon.Resize(sizeChange);
       
   513         pCurrCell->rIcon.Move(TPoint(-sizeChange.iWidth/2,0));
       
   514         }
       
   515     }
       
   516 
       
   517 
       
   518 
       
   519 // -----------------------------------------------------------------------------
       
   520 // CBrowserShortcutKeyMap::CreateSpriteCellL
       
   521 // Draw the sprite rects to the sprite bitmap
       
   522 // ----------------------------------------------------------------------------
       
   523 
       
   524 void CBrowserShortcutKeyMap::CreateSpriteCellL(const TInt& aCellIndex)
       
   525     {
       
   526     // Create pointer for easy access curr Cell
       
   527     TKeymapCellData* pCurrCell = iCellData[aCellIndex];
       
   528 
       
   529     TBool ShowDim = EFalse;
       
   530 
       
   531 
       
   532     // Draw rect for Cell
       
   533     iSpriteBitmapContext->SetPenSize( TSize(1,1) );
       
   534     iSpriteBitmapContext->SetPenStyle( CGraphicsContext::ESolidPen );
       
   535     iSpriteBitmapContext->SetPenColor( TRgb( 0, 0, 0) );
       
   536     iSpriteBitmapContext->DrawRect(pCurrCell->r);
       
   537 
       
   538 
       
   539 
       
   540     // DRAW TEXT
       
   541     iSpriteBitmapContext->SetPenColor( TRgb( 0, 0, 0) );
       
   542 
       
   543     // Draw key text
       
   544     if(pCurrCell->keyText)
       
   545     {
       
   546         iSpriteBitmapContext->UseFont( iKeyFont );
       
   547         iSpriteBitmapContext->DrawText(pCurrCell->keyText->Des(),
       
   548             pCurrCell->rKey, iKeyFont->FontMaxHeight(), CGraphicsContext::ECenter, 0);
       
   549     }
       
   550 
       
   551     // For line1, line2 text, we need to first wrap them
       
   552     // based upon the width of their enclosing rectangles
       
   553     if(pCurrCell->lineText)
       
   554         {
       
   555         CArrayFixFlat<TInt> *lineWidthArray = new( ELeave ) CArrayFixFlat<TInt>(2);
       
   556         lineWidthArray->AppendL(pCurrCell->rLine1.Width());
       
   557         lineWidthArray->AppendL(pCurrCell->rLine2.Width());
       
   558 
       
   559         CArrayFixFlat<TPtrC> *WrappedArray = new( ELeave ) CArrayFixFlat<TPtrC>(3);
       
   560         AknTextUtils::WrapToArrayL( *(pCurrCell->lineText), *lineWidthArray, *iLineFont, *WrappedArray );
       
   561 
       
   562         iSpriteBitmapContext->UseFont( iLineFont );
       
   563         iSpriteBitmapContext->DrawText(WrappedArray->At(0),
       
   564             pCurrCell->rLine2, iLineFont->FontMaxHeight(), CGraphicsContext::ECenter, 0);
       
   565 
       
   566         if(WrappedArray->Count() >= 2)
       
   567             {
       
   568             iSpriteBitmapContext->DrawText(WrappedArray->At(0),
       
   569                 pCurrCell->rLine1, iLineFont->FontMaxHeight(), CGraphicsContext::ECenter, 0);
       
   570             iSpriteBitmapContext->DrawText(WrappedArray->At(1),
       
   571                 pCurrCell->rLine2, iLineFont->FontMaxHeight(), CGraphicsContext::ECenter, 0);
       
   572             }
       
   573 
       
   574 
       
   575         // Set dim flag if needed
       
   576         switch (pCurrCell->cmdRscId)
       
   577             {
       
   578             case R_BROWSER_KEYMAP_TEXT_SWITCH_WINDOW:
       
   579                 { //EWmlCmdSwitchWindow;
       
   580                 ShowDim = ( !iApiProvider.Preferences().UiLocalFeatureSupported( KBrowserMultipleWindows ) ||
       
   581                             iApiProvider.IsEmbeddedModeOn() ||
       
   582                             iApiProvider.WindowMgr().WindowCount() < 2);
       
   583                 break;
       
   584                 }
       
   585 
       
   586             case R_BROWSER_KEYMAP_TEXT_VIEW_IMAGES:
       
   587                 { //EWmlCmdShowImages;
       
   588                 ShowDim = ( !iApiProvider.BrCtlInterface().ImageCountL() );
       
   589                 break;
       
   590                 }
       
   591 
       
   592             case R_BROWSER_KEYMAP_TEXT_SUBSCRIBE_TO_FEEDS:
       
   593                 { // EWmlCmdShowSubscribeList
       
   594                 CBrCtlInterface& brctl = iApiProvider.BrCtlInterface();
       
   595                 TBool subscribeToItems(EFalse);
       
   596                 TRAPD(err, const RPointerArray<TBrCtlSubscribeTo>& items = brctl.SubscribeToMenuItemsL();
       
   597                 subscribeToItems = (err == KErrNone && items.Count() > 0));
       
   598                 ShowDim = !subscribeToItems;
       
   599                 break;
       
   600                 }
       
   601 
       
   602             case R_BROWSER_KEYMAP_TEXT_GO_TO_HOMEPAGE:
       
   603                 { // EWmlCmdLaunchHomePage
       
   604                 ShowDim = iApiProvider.IsLaunchHomePageDimmedL();
       
   605                 break;
       
   606                 }
       
   607 
       
   608             case R_BROWSER_KEYMAP_TEXT_PREVIOUS_PAGE:
       
   609                 { // EWmlCmdOneStepBack
       
   610                 ShowDim = (!iApiProvider.BrCtlInterface().NavigationAvailable(TBrCtlDefs::ENavigationBack ) );
       
   611                 break;
       
   612                 }
       
   613 
       
   614             case R_BROWSER_KEYMAP_TEXT_MINIATURE_SHOW:
       
   615                 { //EWmlCmdShowMiniature;
       
   616                 ShowDim = ( !iApiProvider.Preferences().UiLocalFeatureSupported( KBrowserGraphicalPage ) ||
       
   617                             iApiProvider.WindowMgr().CurrentWindow()->HasWMLContent(ETrue) );
       
   618                 break;
       
   619                 }
       
   620 
       
   621             case R_BROWSER_KEYMAP_TEXT_SHOW_TOOLBAR:
       
   622                 { //EWmlCmdShowToolBar;
       
   623                 if ( !AknLayoutUtils::PenEnabled() && iApiProvider.Preferences().ShowToolbarOnOff() )
       
   624                     {
       
   625                     ShowDim = iApiProvider.WindowMgr().CurrentWindow()->WMLMode();
       
   626                     }
       
   627                 else
       
   628                     {
       
   629                     ShowDim = ETrue;
       
   630                     }
       
   631                 break;
       
   632                 }
       
   633 
       
   634             case R_BROWSER_KEYMAP_TEXT_SAVE_AS_BOOKMARK:
       
   635                 { //EWmlCmdSaveAsBookmark;
       
   636                 if ( iApiProvider.IsEmbeddedModeOn() && CBrowserAppUi::Static()->IsEmbeddedInOperatorMenu() )
       
   637                     {
       
   638                     ShowDim = ETrue;
       
   639                     }
       
   640                 else
       
   641                     {
       
   642                     HBufC *pageUrl = iApiProvider.BrCtlInterface().PageInfoLC( TBrCtlDefs::EPageInfoUrl );
       
   643                     if( ( pageUrl == NULL ) || ( pageUrl->Length() == 0 ) )
       
   644                         {
       
   645                         ShowDim = ETrue;
       
   646                         }
       
   647                     CleanupStack::PopAndDestroy( pageUrl );
       
   648                     }
       
   649                 break;
       
   650                 }
       
   651 
       
   652             /* Zoom Mode currently disabled
       
   653             case R_BROWSER_KEYMAP_TEXT_ZOOM_MODE:
       
   654                 { //EWmlCmdZoomMode;
       
   655 
       
   656                 ShowDim = ( iApiProvider.WindowMgr().CurrentWindow()->WMLMode() ||
       
   657                             !iApiProvider.ContentDisplayed() ||
       
   658                             AknLayoutUtils::PenEnabled() );
       
   659                 break;
       
   660                 }
       
   661             */
       
   662 
       
   663             default:
       
   664             break;
       
   665             }
       
   666         }
       
   667 
       
   668     // DRAW the icon,
       
   669     // setting the icon size according to iconRect
       
   670     if(pCurrCell->keyBitmapImage != NULL && pCurrCell->keyBitmapMask != NULL)
       
   671         {
       
   672         AknIconUtils::SetSize(pCurrCell->keyBitmapImage, pCurrCell->rIcon.Size() );
       
   673         AknIconUtils::SetSize(pCurrCell->keyBitmapMask, pCurrCell->rIcon.Size() );
       
   674 
       
   675         if (ShowDim)
       
   676             {
       
   677             CFbsBitmap* keyBitmapDimImage;
       
   678             CFbsBitmap* keyBitmapDimMask;
       
   679 
       
   680             CreateDimBitmapL(pCurrCell->keyBitmapImage,
       
   681                              pCurrCell->keyBitmapMask,
       
   682                              keyBitmapDimImage,
       
   683                              keyBitmapDimMask);
       
   684 
       
   685             iSpriteBitmapContext->BitBltMasked(pCurrCell->rIcon.iTl,
       
   686                 keyBitmapDimImage,
       
   687                 TRect(TPoint(0, 0),pCurrCell->rIcon.Size() ),
       
   688                 keyBitmapDimMask,
       
   689                 ETrue);
       
   690 
       
   691             delete keyBitmapDimImage;
       
   692             delete keyBitmapDimMask;
       
   693             }
       
   694         else
       
   695             {
       
   696             iSpriteBitmapContext->BitBltMasked(pCurrCell->rIcon.iTl,
       
   697                 pCurrCell->keyBitmapImage,
       
   698                 TRect(TPoint(0, 0),pCurrCell->rIcon.Size() ),
       
   699                 pCurrCell->keyBitmapMask,
       
   700                 ETrue);
       
   701             }
       
   702         }
       
   703     }
       
   704 
       
   705 
       
   706 
       
   707 // -----------------------------------------------------------------------------
       
   708 // CBrowserShortcutKeyMap::ConstructSprite
       
   709 // Construct the Sprite from the bitmap and context
       
   710 // -----------------------------------------------------------------------------
       
   711 //
       
   712 void CBrowserShortcutKeyMap::ConstructSprite()
       
   713     {
       
   714     iSprite = RWsSprite( CEikonEnv::Static()->WsSession() );
       
   715     RWindowTreeNode *window = iContentViewContainer->DrawableWindow();
       
   716     iSprite.Construct(*window,iTargetRect.iTl,ESpriteNoChildClip);
       
   717 
       
   718     TSpriteMember spriteMem;
       
   719     spriteMem.iBitmap = iSpriteBitmap;
       
   720     spriteMem.iMaskBitmap = iSpriteMaskBitmap;
       
   721     spriteMem.iInvertMask = ETrue;
       
   722     iSprite.AppendMember(spriteMem);
       
   723 
       
   724     iSprite.SetPosition(iTargetRect.iTl);
       
   725     iSprite.Activate();
       
   726     }
       
   727 
       
   728 
       
   729 
       
   730 // -----------------------------------------------------------------------------
       
   731 // CBrowserShortcutKeyMap::GetCannedImageDirL
       
   732 // Utility: Get the folder where the canned image is located
       
   733 // -----------------------------------------------------------------------------
       
   734 //
       
   735 HBufC* CBrowserShortcutKeyMap::GetCannedImageDirL( )
       
   736     {
       
   737     HBufC* mbmFile = NULL;
       
   738     TParse parse;
       
   739 
       
   740     // Get the drive letter where mbm resides.. it will be the same
       
   741     // as this AppUi (browser ng)
       
   742     CEikAppUi* pAppUI = (CEikAppUi*)(CCoeEnv::Static()->AppUi());
       
   743     TFileName mbmDrive = pAppUI->Application()->DllName();
       
   744 
       
   745     parse.Set( mbmDrive, NULL, NULL );
       
   746     mbmDrive = parse.Drive();
       
   747 
       
   748     // allocate memory for MBM file name
       
   749     mbmFile = HBufC::NewL( KMaxFileName );
       
   750 
       
   751     // assemble the MBM file name
       
   752     TPtr ptr( mbmFile->Des() );
       
   753     ptr.SetLength( 0 );
       
   754     ptr.Append( mbmDrive );
       
   755     ptr.Append( KDC_APP_BITMAP_DIR );
       
   756     return mbmFile;
       
   757     }
       
   758 
       
   759 
       
   760 
       
   761 // -----------------------------------------------------------------------------
       
   762 // CBrowserShortcutKeyMap::LoadSvg
       
   763 // Utility: get the SVG bitmaps, etc, given its filename
       
   764 // -----------------------------------------------------------------------------
       
   765 //
       
   766 void CBrowserShortcutKeyMap::LoadSvg(
       
   767     TInt aImageId,
       
   768     const TDesC& aFileName,
       
   769     CFbsBitmap*& aImage ,
       
   770     CFbsBitmap*& aImageMask )
       
   771     {
       
   772     // Don't skin icons--at least for now.
       
   773     TRAPD(error, AknIconUtils::CreateIconL( aImage,
       
   774                                             aImageMask,
       
   775                                             aFileName,
       
   776                                             aImageId,
       
   777                                             aImageId+1));
       
   778 
       
   779     if (error!=KErrNone)
       
   780         {
       
   781         return;
       
   782         }
       
   783     }
       
   784 
       
   785 // -----------------------------------------------------------------------------
       
   786 // CBrowserShortcutKeyMap::CreateDimBitmap
       
   787 // Utility: Create Dimmed version of Bitmap
       
   788 // -----------------------------------------------------------------------------
       
   789 //
       
   790 void CBrowserShortcutKeyMap::CreateDimBitmapL(
       
   791     CFbsBitmap* aImage,
       
   792     CFbsBitmap* aImageMask,
       
   793     CFbsBitmap*& aDimImage,
       
   794     CFbsBitmap*& aDimImageMask)
       
   795     {
       
   796 
       
   797     aDimImage = new ( ELeave ) CFbsBitmap;
       
   798     CleanupStack::PushL( aDimImage );
       
   799 
       
   800     aDimImage->Duplicate( aImage->Handle() );
       
   801 
       
   802     aDimImageMask = new ( ELeave ) CFbsBitmap;
       
   803 
       
   804     User::LeaveIfError( aDimImageMask->Create(aDimImage->SizeInPixels(),
       
   805                                         EGray256 ) );
       
   806 
       
   807     CleanupStack::PushL( aDimImageMask );
       
   808 
       
   809     CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL( aDimImageMask );
       
   810     CleanupStack::PushL( bitmapDevice );
       
   811 
       
   812     CFbsBitGc* bitGc( NULL );
       
   813     User::LeaveIfError( bitmapDevice->CreateContext( bitGc ) );
       
   814     CleanupStack::PushL( bitGc );
       
   815 
       
   816     bitGc->SetPenStyle( CGraphicsContext::ESolidPen );
       
   817     bitGc->BitBlt( TPoint( 0, 0 ), aImageMask );
       
   818 
       
   819 
       
   820     aDimImageMask->LockHeap();
       
   821     TInt w = aImageMask->SizeInPixels().iWidth;
       
   822     TInt h = aImageMask->SizeInPixels().iHeight;
       
   823     TInt dataStride = aImageMask->DataStride() - w;
       
   824     unsigned char* address = (unsigned char *)aDimImageMask->DataAddress();
       
   825 
       
   826     for ( TInt i = 0; i < h; ++i )
       
   827         {
       
   828         for ( TInt j = 0; j < w; ++j )
       
   829             {
       
   830             *address = KTransparency[*address];
       
   831             ++address;
       
   832             }
       
   833         address += dataStride;
       
   834         }
       
   835 
       
   836     aDimImageMask->UnlockHeap();
       
   837 
       
   838     CleanupStack::PopAndDestroy( 2 ); // bitmapDevice, bitGc
       
   839     CleanupStack::Pop( 2 ); // aDimImage, aDimImageMask
       
   840 
       
   841 
       
   842     }
       
   843 
       
   844 //  End of File