javauis/lcdui_akn/lcdui/src/CMIDDisplayable.cpp
branchRCL_3
changeset 66 2455ef1f5bbc
child 77 7cee158cb8cd
equal deleted inserted replaced
65:ae942d28ec0e 66:2455ef1f5bbc
       
     1 /*
       
     2 * Copyright (c) 2003-2009 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:  Implementation of the CMIDDisplayable class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <bldvariant.hrh>
       
    20 
       
    21 #include <memory>
       
    22 #include <apgwgnam.h>
       
    23 #include <eikenv.h>
       
    24 #include <coecntrl.h>
       
    25 #include <uikon.hrh>
       
    26 // using BaflUtils::CopyWithTruncation in PopulateMenuItemsWithListL function
       
    27 #include <bautils.h>
       
    28 // using MMIDImage and MMIDBitmapImage
       
    29 #include <lcdgr.h>
       
    30 // macros definitions for resources
       
    31 #include <lcdui.rsg>
       
    32 // using TMifLcdui enumeration
       
    33 #include <lcdui.mbg>
       
    34 // Used for Avkon toolbar disabling
       
    35 #include <akntoolbar.h>
       
    36 // Layout data
       
    37 #include <layoutmetadata.cdl.h>
       
    38 #include <aknlayoutscalable_avkon.cdl.h>
       
    39 #include <e32property.h>
       
    40 //#include <SysStartup.h>
       
    41 #include <aknappui.h>
       
    42 // using CAknTitlePane in ShowTitleL() function
       
    43 #include <akntitle.h>
       
    44 // using CAknContextPane in SetMIDletIconL() function to show midlet icon
       
    45 #include <akncontext.h>
       
    46 // used for label converting for commands (in PopulateMenuItemsWithListL function)
       
    47 #include <AknBidiTextUtils.h>
       
    48 #include <avkon.hrh>
       
    49 #include <avkon.rsg>
       
    50 #include <AvkonInternalCRKeys.h>
       
    51 #include <aknstyluspopupmenu.h>
       
    52 #include <eiklabel.h>
       
    53 #ifdef RD_SCALABLE_UI_V2
       
    54 // For requiring available keyboards in the device
       
    55 #include <PtiEngine.h>
       
    56 #include <PtiDefs.h>
       
    57 #endif // RD_SCALABLE_UI_V2
       
    58 
       
    59 // OMJ storage
       
    60 #include <applicationinfo.h>
       
    61 #include <javastorageentry.h>
       
    62 #include <javastorage.h>
       
    63 #include <javastoragenames.h>
       
    64 #include <javauid.h>
       
    65 #include <javasymbianoslayer.h>
       
    66 
       
    67 #include "CMIDDisplayable.h"
       
    68 // API used in several places (iAppUi is member)
       
    69 #include "CMIDAppUi.h"
       
    70 #include "CMIDCanvas.h"
       
    71 // used in SetComponentL function
       
    72 #include "CMIDDefaultBackground.h"
       
    73 // API for ticker on displayable
       
    74 #include "CMIDTicker.h"
       
    75 #include "CMIDComponentFactory.h"
       
    76 // used for setting iMenuHandler from iUIManager (MenuHandler)
       
    77 #include "CMIDUIManager.h"
       
    78 #include "CMIDCommand.h"
       
    79 #include "CMIDForm.h"
       
    80 // using CMIDUtils::CopyBitmapL in SetMIDletIconL() function
       
    81 #include "CMIDUtils.h"
       
    82 // used in SetComponentL function
       
    83 // and used in several place for actions specific for Alert (SetTitleL, ContentSize, HandleCurrentL)
       
    84 #include "CMIDAlert.h"
       
    85 #include "CMIDAlertDialog.h"
       
    86 #include "CMIDEdwin.h"
       
    87 // used in SetComponentL function
       
    88 // used in HandleCurrentL function
       
    89 #include "CMIDTextBoxControl.h"
       
    90 #include "CMIDTextBoxDialogControl.h"
       
    91 // used in SetComponentL function
       
    92 #include "CMIDList.h"
       
    93 // using API for softkeys and their commands
       
    94 #include "CMIDSoftKey.h"
       
    95 #include "CMIDCanvasKeypad.h"
       
    96 #include "CMIDTicker.h"
       
    97 
       
    98 #include "coreuiavkonlcdui.h"
       
    99 #include "coreuiappui.h"
       
   100 
       
   101 #include <j2me/jdebug.h>
       
   102 
       
   103 /** This macro is executed each time a trapped call returns an error code different than KErrNone */
       
   104 #undef  TRAP_INSTRUMENTATION_LEAVE
       
   105 #define TRAP_INSTRUMENTATION_LEAVE(aResult) DEBUG_INT2("In CMIDDisplayable.cpp, trapped method was called at line %D and got exception %D", __LINE__, aResult);
       
   106 
       
   107 const TGulBorder::TBorderType KMIDLetBorder = TGulBorder::EThickDeepRaisedWithOutline;
       
   108 
       
   109 const TInt KCommandIdNotFound = -10000;
       
   110 const TInt KCommandIdBase = 7000;
       
   111 const TInt KItemCommandIdBase = 8000; // must be greater than KCommandIdBase
       
   112 // Special ID for built-in MSK commands. Handling of them is different because
       
   113 // built-in commands are not visible in menus, only in MSK. Built-in MSK commands
       
   114 // are commands that are set using SetMSKCommand method, but are not found in
       
   115 // command lists.
       
   116 const TInt KBuiltInMSKCommandId = 9000;
       
   117 
       
   118 // Index of the MSK in CBA, to be used when adding MSK command to CBA
       
   119 const TInt KMSKPositionInCBA = 3;
       
   120 
       
   121 /** The maximum number of softkeys on the device.
       
   122 */
       
   123 const TInt KMaxNumberOfSoftKeys = 2;
       
   124 const TInt KListLongTapAnimationDelay = 400000;
       
   125 const TInt KListLongTapDelay = 800000;
       
   126 
       
   127 
       
   128 /*
       
   129  * The allowed command types for softkeys,
       
   130  *   -1 means we have run out of allowed types.
       
   131  * More restrictive sks, eg the right sk, should come
       
   132  * before more permissive sks. This array is used to
       
   133  * initialise iSoftkeys.
       
   134  */
       
   135 const TInt KAllowedCommandTypesForSoftkeys[KMaxNumberOfSoftKeys][9] =
       
   136 {
       
   137     // Right softkey
       
   138     {
       
   139         MMIDCommand::EStop,
       
   140         MMIDCommand::ECancel,
       
   141         MMIDCommand::EBack,
       
   142         MMIDCommand::EExit,
       
   143         -1,
       
   144         -1,
       
   145         -1,
       
   146         -1,
       
   147         -1
       
   148     },
       
   149 
       
   150     // Left softkey
       
   151     {
       
   152         MMIDCommand::EStop,
       
   153         MMIDCommand::EOk,
       
   154         MMIDCommand::ECancel,
       
   155         MMIDCommand::EItem,
       
   156         MMIDCommand::EScreen,
       
   157         MMIDCommand::EBack,
       
   158         MMIDCommand::EHelp,
       
   159         MMIDCommand::EExit,
       
   160         -1
       
   161     }
       
   162 };
       
   163 
       
   164 /**
       
   165   The CBA that can have an options menu if commands are available.
       
   166   This is used as a zero-based index in iSoftkeys and must be
       
   167   less than KMaxNumberOfSoftKeys.
       
   168 */
       
   169 const TInt KOptionsMenuCBAIndex = 1; //left sk
       
   170 
       
   171 /**
       
   172   The sk position in the CBA. Must use the same ordering as
       
   173   KAllowedCommandTypesForSoftkeys and is used to initialise
       
   174   iSoftkeys.
       
   175 */
       
   176 const TInt KPositionsInCBAForSoftkeys[KMaxNumberOfSoftKeys] =
       
   177 {
       
   178     2, //Right softkey
       
   179     0 //Left softkey
       
   180 };
       
   181 
       
   182 // One ticker can be added more than one displayable. So keep track of all of them
       
   183 const TInt KAddDisplayable = 1; // add the displable to the list in ticker
       
   184 const TInt KRemoveDisplayable = 0; // Remove the displable from the list in ticker
       
   185 
       
   186 const TInt KSoftKeyLabelPropertyPositionsMSKIndex = 2;
       
   187 const TInt KSoftKeyLabelPropertyPositionsInCBA[ KSoftKeyLabelPropertyNumberOfSoftKeys ] =
       
   188 {
       
   189     0,  //LSK
       
   190     2,  //RSK
       
   191     3   //MSK
       
   192 };
       
   193 
       
   194 // class CMIDDisplayable
       
   195 
       
   196 CMIDDisplayable* CMIDDisplayable::NewL(MMIDEnv& aEnv,CMIDUIManager& aUIManager)
       
   197 {
       
   198     CMIDDisplayable* displayable = new(ELeave)CMIDDisplayable(aEnv,aUIManager);
       
   199     CleanupStack::PushL(displayable);
       
   200     displayable->ConstructL();
       
   201     CleanupStack::Pop(displayable);
       
   202     return displayable;
       
   203 }
       
   204 
       
   205 // ---------------------------------------------------------------------------
       
   206 //
       
   207 // ---------------------------------------------------------------------------
       
   208 //
       
   209 void CMIDDisplayable::ConstructL()
       
   210 {
       
   211     DEBUG("+ CMIDDisplayable::ConstructL");
       
   212 
       
   213     // Menu/commands
       
   214     // NOTE: Menu handler member variable has to be valid before
       
   215     // the <code>CCoeContol::MakeVisible</code> method is called
       
   216     // because the <code>CMIDDisplayable::MopSupplyObject</code> method
       
   217     // might be called because of that.
       
   218     iMenuHandler = iUIManager->OpenMenuHandlerL();
       
   219     iCommandList = new(ELeave) CMIDCommandList();
       
   220     iCommandList->SetCommandOffset(KCommandIdBase);
       
   221     iMSKCommand = NULL;
       
   222     iDisplayableBehindPopup = NULL;
       
   223 
       
   224     iEnv.AddObserverL(*this);
       
   225     CreateWindowL(&iEikonEnv->RootWin());
       
   226     SetMopParent(java::ui::CoreUiAvkonLcdui::getInstance().getJavaAknAppUi());
       
   227 
       
   228     //All windows are created invisible and then made visible
       
   229     //in SetComponentL(), except for Alerts (dialogs)
       
   230     MakeVisible(EFalse);
       
   231     Window().SetOrdinalPosition(-1);
       
   232 
       
   233     Window().EnableOnEvents(EEventControlOnlyWhenVisible);
       
   234     EnableDragEvents();
       
   235 
       
   236     // Long tap detection
       
   237     iLongTapDetector = CAknLongTapDetector::NewL(this);
       
   238 
       
   239     // SoftKeys
       
   240     for (TInt i = 0; i < KMaxNumberOfSoftKeys; i++)
       
   241     {
       
   242         CMIDSoftKey* softKey = CMIDSoftKey::NewLC(i, &(KAllowedCommandTypesForSoftkeys[i][0]),
       
   243                                KPositionsInCBAForSoftkeys[i]);
       
   244         User::LeaveIfError(iSoftKeys.Append(softKey));
       
   245         CleanupStack::Pop(softKey);
       
   246     }
       
   247 
       
   248     // CBA
       
   249     iCba = iMenuHandler->Cba();
       
   250 
       
   251     UpdateDisplayableRect();
       
   252     SetRect(iDisplayableRect);
       
   253 
       
   254     iBorder = TGulBorder::ENone;
       
   255 
       
   256     SetComponentsToInheritVisibility();
       
   257     // for Skin Support, Create background control context:
       
   258     iBackGroundControlContext = CAknsBasicBackgroundControlContext::NewL(
       
   259                                     KAknsIIDQsnBgAreaMain,  // Default mainpane skinning
       
   260                                     Rect(),                 // Layout to the entire client rect
       
   261                                     EFalse);
       
   262 
       
   263     iAppUi->Displayables().AppendL(this);
       
   264     iAppUi->SetEnv(iEnv);
       
   265     ActivateL();
       
   266 
       
   267     //Read JAD attribute value for On-Screen Keypad softkeys visual appearence with HW QWERTY keypad
       
   268     if (iEnv.MidletAttributeIsSetToVal(
       
   269                 LcduiMidletAttributes::KAttribOskSoftkeysInQwerty,
       
   270                 LcduiMidletAttributeValues::KPositionBottom))
       
   271     {
       
   272         iSKPositionWithQwerty = ESoftkeysBottom;
       
   273     }
       
   274     else
       
   275     {
       
   276         //default value
       
   277         iSKPositionWithQwerty = ESoftkeysRight;
       
   278     }
       
   279 
       
   280     // initialization of keypad information
       
   281     ReadOnScreenKeypadTypeFromSuiteSettings();
       
   282 
       
   283     DEBUG("- CMIDDisplayable::ConstructL");
       
   284 }
       
   285 
       
   286 CMIDDisplayable::CMIDDisplayable(MMIDEnv& aEnv,CMIDUIManager& aUIManager)
       
   287         :CEikBorderedControl(TGulBorder(KMIDLetBorder)),
       
   288         iUIManager(&aUIManager),iEnv(aEnv),
       
   289         iIsFullScreenMode(EFalse),iActive(EFalse), iSelectCommand(NULL), iSelectCommandEnabled(ETrue),
       
   290         iFullscreenCanvasLabelCacheIsValid(EFalse)
       
   291 #ifdef RD_TACTILE_FEEDBACK
       
   292         ,iPenInputServerConnected(EFalse)
       
   293 #endif //RD_TACTILE_FEEDBACK
       
   294         ,iIdOfMSKCommand(KErrNotFound)
       
   295         ,iRestoreOrientation(EFalse)
       
   296         ,iReleaseCnt(0)
       
   297 {
       
   298 #ifdef RD_JAVA_S60_RELEASE_9_2
       
   299     iSplitScreenKeyboard = EFalse;
       
   300 #endif // RD_JAVA_S60_RELEASE_9_2
       
   301     iAppUi = (CMIDAppUi*)java::ui::CoreUiAvkonLcdui::getInstance().getJavaUiAppUi()->getLcduiChild();
       
   302 }
       
   303 
       
   304 CMIDDisplayable::~CMIDDisplayable()
       
   305 {
       
   306     DEBUG("+ CMIDDisplayable::CMIDDisplayable");
       
   307 
       
   308     // iPropertyWatch is CPropertyWatch object,
       
   309     // delete member call desctructor of CPropertyWatch
       
   310     // and remove active object form active scheduler
       
   311     if (iPropertyWatch)
       
   312     {
       
   313         delete iPropertyWatch;
       
   314         iPropertyWatch = NULL;
       
   315     }
       
   316 
       
   317     // Informing iEnv about deleting this
       
   318     iEnv.DisplayableIsDestructed(this);
       
   319 
       
   320     // Remove this from iEnv observer
       
   321     iEnv.RemoveObserver(*this);
       
   322 
       
   323     if (iAppUi)
       
   324     {
       
   325         iAppUi->RemoveFromStack(iContentControl);
       
   326         TInt index = iAppUi->Displayables().Find(this);
       
   327         if (index != KErrNotFound)
       
   328         {
       
   329             iAppUi->Displayables().Remove(index);
       
   330         }
       
   331     }
       
   332 
       
   333     delete iLongTapDetector;
       
   334     delete iStylusPopupMenu;
       
   335     delete iTitle;
       
   336 
       
   337 #ifdef RD_SCALABLE_UI_V2
       
   338     iUIManager->CloseCanvasKeypad(iCanvasKeypad);
       
   339     iCanvasKeypad = NULL;
       
   340 #endif //RD_SCALABLE_UI_V2
       
   341 
       
   342 #ifdef RD_TACTILE_FEEDBACK
       
   343     if (iPenInputServerConnected)
       
   344     {
       
   345         iPenInputServer.Close();
       
   346         iPenInputServerConnected = EFalse;
       
   347     }
       
   348 #endif //RD_TACTILE_FEEDBACK
       
   349 
       
   350     // if ticker is present in this displayable and displayable is
       
   351     // deleted but ticker is not, tell the ticker that displayable is
       
   352     // garbage collected.
       
   353     if (iTicker)
       
   354     {
       
   355         TRAP_IGNORE(iTicker->SetDisplayableL(this, KRemoveDisplayable));
       
   356     }
       
   357 
       
   358     delete iBackGroundControlContext;
       
   359     iBackGroundControlContext = NULL;
       
   360 
       
   361     iSoftKeys.ResetAndDestroy();
       
   362     delete iCommandList;
       
   363 
       
   364     if (iMenuHandler->GetDisplayable() == this)
       
   365     {
       
   366         //this may happen when the application is exiting
       
   367         iMenuHandler->SetDisplayable(NULL);
       
   368     }
       
   369 
       
   370     DEBUG("- CMIDDisplayable::CMIDDisplayable");
       
   371 }
       
   372 
       
   373 /**
       
   374  * This means we are being deleted java side. We delete ourselves.
       
   375  * However before doing this we call ReplaceBehindAlertIfNeeded().
       
   376  **/
       
   377 void CMIDDisplayable::Dispose()
       
   378 {
       
   379     ReplaceBehindAlertIfNeeded();
       
   380 
       
   381     delete this;
       
   382 }
       
   383 
       
   384 /**
       
   385  * This method is called when we are deleted java side, from Dispose().
       
   386  * This code should only execute when java side they decide to delete the
       
   387  * displayable immeditately behind a showing alert. We check if we are a
       
   388  * displayable behind an alert. If so we find another displayable (the
       
   389  * one with lowest ordinal position, ie the top most displayable except us
       
   390  * and the alert). If we find one we make it visible so that the alert will
       
   391  * not end up with a white background.
       
   392  **/
       
   393 void CMIDDisplayable::ReplaceBehindAlertIfNeeded()
       
   394 {
       
   395     if ((this != iUIManager->GetDefaultDisplayable())
       
   396             && IsVisible()
       
   397             && (iMenuHandler->GetDisplayable())
       
   398             && (iMenuHandler->GetDisplayable()->Component()->Type() == EAlert))
       
   399     {
       
   400         // In this case we are a faded displayable behind a dialog
       
   401         TInt numDisplayables = iAppUi->Displayables().Count();
       
   402         TInt index = -1;
       
   403         TInt currentPosition = 999;
       
   404         for (TInt i = 0; i < numDisplayables; i++)
       
   405         {
       
   406             CMIDDisplayable* disp = iAppUi->Displayables()[i];
       
   407             if ((disp != this) && (disp->DrawableWindow()->OrdinalPosition() < currentPosition)
       
   408                     && (disp->Component()->Type() != EAlert))
       
   409             {
       
   410                 currentPosition = disp->DrawableWindow()->OrdinalPosition();
       
   411                 index = i;
       
   412             }
       
   413         }
       
   414 
       
   415         if (index != -1)
       
   416         {
       
   417             CMIDDisplayable* disp = iAppUi->Displayables()[index];
       
   418             disp->MakeVisible(ETrue);
       
   419         }
       
   420     }
       
   421 }
       
   422 
       
   423 void CMIDDisplayable::Draw(const TRect& aRect) const
       
   424 {
       
   425     CWindowGc& gc = SystemGc();
       
   426 
       
   427     // Set up update region - preventing DSA to be destroyed by redrawing
       
   428     if (!iDirectContentsRegion.IsEmpty())
       
   429     {
       
   430         gc.CancelClippingRect();
       
   431         iUpdateRegion.Clear();
       
   432         iUpdateRegion.AddRect(aRect);
       
   433         // Remove occupied areas out from update region
       
   434         iUpdateRegion.SubRegion(iDirectContentsRegion);
       
   435         // Set the update region for the context
       
   436         gc.SetClippingRegion(iUpdateRegion);
       
   437     }
       
   438 
       
   439     if (iContent->Type() != ECanvas)
       
   440     {
       
   441         // Draw background
       
   442         MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   443         AknsDrawUtils::Background(skin, iBackGroundControlContext, this, gc, aRect);
       
   444     }
       
   445     iBorder.Draw(gc, Rect());
       
   446 }
       
   447 
       
   448 TInt CMIDDisplayable::CountComponentControls() const
       
   449 {
       
   450     TInt count=0;
       
   451     if (iContentControl)
       
   452     {
       
   453         ++count;
       
   454     }
       
   455     return count;
       
   456 }
       
   457 
       
   458 CCoeControl* CMIDDisplayable::ComponentControl(TInt aIndex) const
       
   459 {
       
   460     switch (aIndex)
       
   461     {
       
   462     case 0:
       
   463         return iContentControl ? iContentControl: 0;
       
   464     default:
       
   465         return 0;
       
   466     }
       
   467 }
       
   468 
       
   469 void CMIDDisplayable::SizeChanged()
       
   470 {
       
   471     if (iBackGroundControlContext)
       
   472     {
       
   473         iBackGroundControlContext->SetRect(Rect());
       
   474     }
       
   475     Layout();
       
   476 }
       
   477 
       
   478 /**
       
   479  * Use the commands in aCommandList to create menu items and add them to aItems.
       
   480  */
       
   481 void CMIDDisplayable::PopulateMenuItemsWithListL
       
   482 (
       
   483     const CMIDMenuHandler::TMenuType& aMenuType, //The type of menu
       
   484     RArray<CEikMenuPaneItem::SData>& aItems, //The items that will be added to the menu
       
   485     CMIDCommandList* aCommandList, //The list of commands to be examined
       
   486     TBool aSeparator
       
   487 )
       
   488 {
       
   489     if (!aCommandList)
       
   490     {
       
   491         return;
       
   492     }
       
   493     const TBool isItemCommands = (aCommandList == iItemCommandList);
       
   494 
       
   495     CMIDCommandList* list = aCommandList;
       
   496     CEikMenuPaneItem::SData item;
       
   497 
       
   498 #ifdef RD_JAVA_S60_RELEASE_9_2
       
   499     // implicitList is used when creating options menu content.
       
   500     TBool implicitList = EFalse;
       
   501     if (iContent && iContent->Type() == EList && iContentControl)
       
   502     {
       
   503         CMIDList* list = static_cast<CMIDList*>(iContentControl);
       
   504         implicitList = list->ListChoiceType() == MMIDChoiceGroup::EImplicit;
       
   505     }
       
   506 #endif // RD_JAVA_S60_RELEASE_9_2
       
   507 
       
   508     const TInt count = list->Count();
       
   509     for (TInt ii=0; ii<count; ii++)
       
   510     {
       
   511         const CMIDCommand* command = (list->At(ii).iCommand);
       
   512 #ifdef RD_JAVA_S60_RELEASE_9_2
       
   513         // If command is mapped to any sk, do not add it to menu (pop-up menu is an exception).
       
   514         if (!iIsFullScreenMode && CommandIsMappedToSk(command) && aMenuType != CMIDMenuHandler::EPopUpMenu)
       
   515 #else
       
   516         // If command is mapped to any sk, do not add it to menu.
       
   517         if (!iIsFullScreenMode && CommandIsMappedToSk(command))
       
   518 #endif // RD_JAVA_S60_RELEASE_9_2               
       
   519         {
       
   520             continue;
       
   521         }
       
   522         // Only commands of type OK and ITEM are visible in context menu.
       
   523         // TextBox/TextField device-provided commands:
       
   524         // - "Fetch number"
       
   525         // - "Call"
       
   526         // - "Fetch e-mail address"
       
   527         // are exception. Those are visible ONLY in Options menu so here
       
   528         // they are not added to context menu.
       
   529 #ifdef RD_JAVA_S60_RELEASE_9_2
       
   530         if (aMenuType == CMIDMenuHandler::EOkMenu || aMenuType == CMIDMenuHandler::EPopUpMenu)
       
   531 #else
       
   532         if (aMenuType == CMIDMenuHandler::EOkMenu)
       
   533 #endif // RD_JAVA_S60_RELEASE_9_2            
       
   534         {
       
   535             if ((!isItemCommands &&
       
   536             (command->CommandType() != MMIDCommand::EOk) &&
       
   537             (command->CommandType() != MMIDCommand::EItem)) ||
       
   538             (command->Id() == CMIDEdwinUtils::EMenuCommandFetchPhoneNumber) ||
       
   539             (command->Id() == CMIDEdwinUtils::EMenuCommandFetchEmailAddress) ||
       
   540             (command->Id() == CMIDEdwinUtils::EMenuCommandCreatePhoneCall))
       
   541             {
       
   542                 continue;
       
   543             }
       
   544         }
       
   545 
       
   546         if (aMenuType == CMIDMenuHandler::EHelpMenu)
       
   547         {
       
   548             if (command->CommandType() != MMIDCommand::EHelp)
       
   549             {
       
   550                 continue;
       
   551             }
       
   552         }
       
   553 
       
   554         TPtrC shortLabel = const_cast<CMIDCommand*>(command)->ShortLabel();
       
   555         TPtrC longLabel  = const_cast<CMIDCommand*>(command)->Label();
       
   556 
       
   557         item.iCommandId = ii + list->CommandOffset();
       
   558         item.iCascadeId = 0;
       
   559 
       
   560         if (ii == (count-1) && aSeparator)
       
   561         {
       
   562             item.iFlags = EEikMenuItemSeparatorAfter;
       
   563         }
       
   564         else
       
   565         {
       
   566             item.iFlags = 0;
       
   567         }
       
   568 
       
   569         // Find out whether the long label fits into the menu without clipping,
       
   570         // and use the long label if it fits; otherwise use short label.
       
   571         //
       
   572         // In some scripts the visual presentation may differ from the logical text,
       
   573         // so we need to convert the text to visual presentation first.
       
   574         // The clipped clipped string is not used, only the return value is.
       
   575         //
       
   576         const CFont& font =
       
   577             *AknLayoutUtils::FontFromId(AKN_LAYOUT_TEXT_List_pane_texts__menu_single__Line_1(0).iFont);
       
   578         TInt maxMenuItemLength = CEikMenuPaneItem::SData::ENominalTextLength;
       
   579 
       
   580         TRect parentRect = Rect();
       
   581         TAknLayoutText prompt1;
       
   582         prompt1.LayoutText(parentRect, AKN_LAYOUT_TEXT_Data_query_pop_up_window_texts_Line_1(0));
       
   583         TInt layoutWidth = prompt1.TextRect().Width();
       
   584 
       
   585         HBufC* visual = HBufC::NewMaxLC(maxMenuItemLength + KAknBidiExtraSpacePerLine);
       
   586         TPtr visualPtr = visual->Des();
       
   587         TBool clip = AknBidiTextUtils::ConvertToVisualAndClip(
       
   588                          longLabel,
       
   589                          visualPtr,
       
   590                          font,
       
   591                          layoutWidth,
       
   592                          layoutWidth,
       
   593                          AknBidiTextUtils::EImplicit,
       
   594                          0xFFFF);
       
   595         CleanupStack::PopAndDestroy(visual);
       
   596 
       
   597         if (clip)
       
   598         {
       
   599             BaflUtils::CopyWithTruncation(item.iText, shortLabel);
       
   600         }
       
   601         else
       
   602         {
       
   603             BaflUtils::CopyWithTruncation(item.iText, longLabel);
       
   604         }
       
   605 
       
   606         if ((iMSKCommand) && (iMSKCommand == list->At(ii).iCommand))
       
   607         {
       
   608             User::LeaveIfError(aItems.Insert(item, 0));
       
   609         }
       
   610         else
       
   611         {
       
   612 #ifdef RD_JAVA_S60_RELEASE_9_2
       
   613             if (aMenuType == CMIDMenuHandler::EOptionsMenu)
       
   614             {
       
   615                 TBool implicitCmd = (implicitList && (command->CommandType() == MMIDCommand::EOk ||
       
   616                                                       command->CommandType() == MMIDCommand::EItem));
       
   617 
       
   618                 if (!implicitCmd)
       
   619                 {
       
   620                     User::LeaveIfError(aItems.Append(item));
       
   621                 }
       
   622                 else if (implicitCmd && iContentControl &&
       
   623                          static_cast<CMIDList*>(iContentControl)->IsHighlighted())
       
   624                 {
       
   625                     // If highlight in implicit list is False then there is no focus
       
   626                     // Item/Ok should be visible in options menu only when there is focus on item
       
   627                     User::LeaveIfError(aItems.Append(item));
       
   628                 }
       
   629             }
       
   630             else
       
   631             {
       
   632                 User::LeaveIfError(aItems.Append(item));
       
   633             }
       
   634 #else
       
   635             User::LeaveIfError(aItems.Append(item));
       
   636 #endif // RD_JAVA_S60_RELEASE_9_2
       
   637         }
       
   638     }
       
   639 }
       
   640 
       
   641 
       
   642 /**
       
   643  * Create a list of menu items based on the type of menu and the
       
   644  * existing command lists.
       
   645  *
       
   646  * This method is executed each time the menu is displayed to the user.
       
   647  * There are two types of menus that can be displayed: context sensitive
       
   648  * - activated by the select key also known as ok-options menu -
       
   649  * or standard options menu - activated by the LSK. In the standard options
       
   650  * menu we display item and standard commands.In the context menu we display
       
   651  * item commands (if there are any) and standard commands if they are
       
   652  * of type OK or ITEM, this is taken care of by PopulateMenuItemsWithListL().
       
   653  *
       
   654  * @see PopulateMenuItemsWithListL(), CMIDMenuHandler::ShowMenuL()
       
   655  **/
       
   656 void CMIDDisplayable::CreateMenuItemsL
       
   657 (
       
   658     const CMIDMenuHandler::TMenuType& aMenuType, // the type of menu
       
   659     RArray<CEikMenuPaneItem::SData>& aMenuItems // the list of menu items
       
   660 )
       
   661 {
       
   662     aMenuItems.Reset();
       
   663 
       
   664     if (aMenuType == CMIDMenuHandler::EOkMenu)
       
   665     {
       
   666         if (iItemCommandList && iItemCommandList->Count() > 0)
       
   667         {
       
   668             PopulateMenuItemsWithListL(aMenuType, aMenuItems, iItemCommandList, EFalse);
       
   669         }
       
   670 
       
   671         // Add form commands always
       
   672         PopulateMenuItemsWithListL(aMenuType, aMenuItems, iCommandList, EFalse);
       
   673     }
       
   674     else if (aMenuType == CMIDMenuHandler::EHelpMenu)
       
   675     {
       
   676         // Add the Help commands only
       
   677         PopulateMenuItemsWithListL(aMenuType, aMenuItems, iCommandList, EFalse);
       
   678     }
       
   679     else if (aMenuType == CMIDMenuHandler::EOptionsMenu)
       
   680     {
       
   681         PopulateMenuItemsWithListL(aMenuType, aMenuItems, iItemCommandList, EFalse);
       
   682         PopulateMenuItemsWithListL(aMenuType, aMenuItems, iCommandList, ETrue);
       
   683     }
       
   684 }
       
   685 
       
   686 /**
       
   687  * iMenuHandler gets the commands first and handles the default ones (exit, options...).
       
   688  * The rest of the commands are passed here.
       
   689  **/
       
   690 void CMIDDisplayable::ProcessCommandL(TInt aCommandId)
       
   691 {
       
   692     if (!iActive)
       
   693     {
       
   694         return;
       
   695     }
       
   696 
       
   697     if (aCommandId == EAknSoftkeyContextOptions)
       
   698     {
       
   699         // MSK command to show context sensitive menu -> open it
       
   700         ShowOkOptionsMenuL();
       
   701     }
       
   702     else if (aCommandId == KBuiltInMSKCommandId)
       
   703     {
       
   704         // Handle built-in command that is not accessible from menus, only in MSK.
       
   705         // Send a notification to the observer; there always should be one in built-in
       
   706         // commands, if not it is considered to be an error.
       
   707         ASSERT(iMSKCommand->Observer());
       
   708         iMSKCommand->Observer()->ProcessCommandL(iMSKCommand);
       
   709     }
       
   710     else if (aCommandId >= KItemCommandIdBase
       
   711              && iItemCommandList->IsValidIndex(aCommandId-KItemCommandIdBase))
       
   712     {
       
   713         HandleItemCommandL(iItemCommandList->At(aCommandId-KItemCommandIdBase));
       
   714     }
       
   715     else if (aCommandId >= KCommandIdBase
       
   716              && iCommandList->IsValidIndex(aCommandId-KCommandIdBase))
       
   717     {
       
   718         HandleStandardCommandL(iCommandList->At(aCommandId-KCommandIdBase));
       
   719     }
       
   720 #ifdef RD_JAVA_S60_RELEASE_9_2
       
   721     // If command has come from pop-up menu, ensure that
       
   722     // possible pending up event is forwarded to the UI component.
       
   723     if (iContent && iContentControl)
       
   724     {
       
   725         if (iContent->Type() == EList)
       
   726         {
       
   727             CMIDList* list = static_cast<CMIDList*>(iContentControl);
       
   728             list->PostPendingUpEventL();
       
   729         }
       
   730         else if (iContent->Type() == EForm)
       
   731         {
       
   732             CMIDForm* form = static_cast<CMIDForm*>(iContentControl);
       
   733             form->PostPendingUpEventL();
       
   734         }
       
   735     }
       
   736 #endif // RD_JAVA_S60_RELEASE_9_2
       
   737 }
       
   738 
       
   739 #ifdef RD_SCALABLE_UI_V2
       
   740 /** */
       
   741 // This function can be moved out from RD_SCALABLE_UI_V2 flag if needed.
       
   742 // It is behind this flag because currently it is used only by Touch.
       
   743 void CMIDDisplayable::ProcessCommandL(CMIDCommand* aCommand)
       
   744 {
       
   745     TInt internalID = GetInternalCommandIdFor(aCommand);
       
   746     if (internalID != KCommandIdNotFound)
       
   747     {
       
   748         ProcessCommandL(internalID);
       
   749     }
       
   750 }
       
   751 #endif //RD_SCALABLE_UI_V2
       
   752 
       
   753 /** */
       
   754 void CMIDDisplayable::HandleStandardCommandL(const TCommandEntry& aCmdEntry)
       
   755 {
       
   756     TBool postJavaEvent = ETrue;
       
   757     if (aCmdEntry.iCommand->Id() < 0)
       
   758     {
       
   759         //non-midlet command, see if there is an observer
       
   760         if (aCmdEntry.iCommand->Observer())
       
   761         {
       
   762             postJavaEvent = !(aCmdEntry.iCommand->Observer()->ProcessCommandL(aCmdEntry.iCommand));
       
   763         }
       
   764     }
       
   765 
       
   766     if (postJavaEvent)
       
   767     {
       
   768         iEnv.PostJavaEvent(*this, EDisplayable, ECommand, aCmdEntry.iKey);
       
   769     }
       
   770 }
       
   771 
       
   772 /** */
       
   773 void CMIDDisplayable::HandleItemCommandL(const TCommandEntry& aCmdEntry)
       
   774 {
       
   775     TBool postJavaEvent = ETrue;
       
   776     if (aCmdEntry.iCommand->Id() < 0)
       
   777     {
       
   778         //non-midlet command, see if there is an observer
       
   779         if (aCmdEntry.iCommand->Observer())
       
   780         {
       
   781             postJavaEvent = !(aCmdEntry.iCommand->Observer()->ProcessCommandL(aCmdEntry.iCommand));
       
   782         }
       
   783     }
       
   784 
       
   785     if (postJavaEvent && iContent->Type() == EForm)
       
   786     {
       
   787         CMIDForm* form = static_cast<CMIDForm*>(iContentControl);
       
   788         ASSERT(form);
       
   789 
       
   790         MMIDItem* item = form->CurrentItem();
       
   791         if (item)
       
   792         {
       
   793             iEnv.PostJavaEvent(*item, EItem, ECommand, aCmdEntry.iKey);
       
   794         }
       
   795     }
       
   796 }
       
   797 
       
   798 void CMIDDisplayable::HandleHelpCommandL()
       
   799 {
       
   800     // Get how many java help commands is registered
       
   801     TInt numCommands = NumCommandsForHelpOptionsMenu();
       
   802 
       
   803     // If there is only one help command, invoke the Java help event directly
       
   804     if (numCommands == 1)
       
   805     {
       
   806         TCommandEntry cmdEntry;
       
   807         cmdEntry.iCommand = NULL;
       
   808 
       
   809         if (iCommandList)
       
   810         {
       
   811             TInt index = iCommandList->HighestPriorityCommand(MMIDCommand::EHelp);
       
   812             if (index != KErrNotFound)
       
   813             {
       
   814                 cmdEntry = iCommandList->At(index);
       
   815                 iEnv.PostJavaEvent(*this, EDisplayable, ECommand, cmdEntry.iKey);
       
   816             }
       
   817         }
       
   818     }
       
   819     // If there is two or more help commands, let display the menu with these commands
       
   820     else if (numCommands > 0)
       
   821     {
       
   822         iMenuHandler->ShowMenuL(CMIDMenuHandler::EHelpMenu);
       
   823     }
       
   824 }
       
   825 
       
   826 TInt CMIDDisplayable::NumCommandsForHelpOptionsMenu() const
       
   827 {
       
   828     TInt ret = 0;
       
   829 
       
   830     // Add always HELP commands from form
       
   831     TInt numCommands = iCommandList->Count();
       
   832     for (TInt i = 0; i < numCommands; i++)
       
   833     {
       
   834         const CMIDCommand& command = *(iCommandList->At(i).iCommand);
       
   835         if (command.CommandType() == MMIDCommand::EHelp)
       
   836         {
       
   837             ret++;
       
   838         }
       
   839     }
       
   840     return ret;
       
   841 }
       
   842 
       
   843 /**
       
   844  * Find the screen or help command with highest priority
       
   845  * and if exists invokes it
       
   846  **/
       
   847 void CMIDDisplayable::HandleHighestPriorityScreenOrHelpCommandL()
       
   848 {
       
   849     // Find the highest priority screen or help command
       
   850     TInt screenOrHelpCmdIndex = GetHighestPriorityScreenOrHelpCommand();
       
   851     if (screenOrHelpCmdIndex != KErrNotFound)
       
   852     {
       
   853         HandleStandardCommandL(iCommandList->At(screenOrHelpCmdIndex));
       
   854     }
       
   855 }
       
   856 
       
   857 //
       
   858 // From MMIDDisplayable
       
   859 //
       
   860 void CMIDDisplayable::SetTitleL(const TDesC* aTitle)
       
   861 {
       
   862     delete iTitle;
       
   863     iTitle = NULL;
       
   864 
       
   865     if (aTitle)
       
   866     {
       
   867         iTitle = aTitle->AllocL();
       
   868     }
       
   869 
       
   870     if (iTitle)
       
   871     {
       
   872         iHasTitle = ETrue;
       
   873     }
       
   874     else
       
   875     {
       
   876         iHasTitle = EFalse;
       
   877     }
       
   878 
       
   879     if (iActive)
       
   880     {
       
   881         ShowTitleL();
       
   882     }
       
   883 
       
   884     if (iContent && iContent->Type() == EAlert)
       
   885     {
       
   886         CMIDAlert* alert = (CMIDAlert*) iContent;
       
   887         alert->SetTitleL(iTitle);
       
   888     }
       
   889     // Title must be forwarded to Pop-up TextBox
       
   890     else if (iContent && iContent->Type() == ETextBox && iIsPopupTextBox)
       
   891     {
       
   892         CMIDTextBoxDialogControl* textbox = (CMIDTextBoxDialogControl*) iContent;
       
   893         textbox->SetTitleL(iTitle);
       
   894     }
       
   895 }
       
   896 
       
   897 /**
       
   898  * Sets the Ticker
       
   899  *
       
   900  * StartL is called on the current displayable's ticker in these circumstances:
       
   901  * - When the MIDlet is brought to the foreground (in HandleForegroundL(ETrue))
       
   902  * - When the device is switched on (in HandleSwitchOnL(ETrue))
       
   903  * - If the MIDlet has been paused due to a CSaveNotifier event, StartL is
       
   904  *   called when the MIDlet is next brought to the foreground.(in HandleSwitchOnL(ETrue))
       
   905  * - When the displayable is made current (StartL called by framework)
       
   906  *
       
   907  * Stop is called on the current displayable's ticker in these circumstances:
       
   908  * - When the MIDlet is placed in the background.(in HandleForegroundL(EFalse) )
       
   909  * - The implementation uses the CSaveNotifier framework to provide MIDLet state changes.
       
   910  *   When the following events are received ESaveAll,ESaveQuick,ESaveData,EReleaseRAM
       
   911  *   the MIDlet is paused and the ticker is stopped.(in HandleSwitchOnL(EFalse))
       
   912  * - When the Displayable is no longer current. (Stop is called by framework)
       
   913  **/
       
   914 void CMIDDisplayable::SetTickerL(MMIDTicker* aTicker)
       
   915 {
       
   916     CMIDTicker* newTicker = static_cast< CMIDTicker* >(aTicker);
       
   917     // if it is the same do nothing
       
   918     if (iTicker == aTicker)
       
   919     {
       
   920         return;
       
   921     }
       
   922 
       
   923     if (iTicker)
       
   924     {
       
   925         // Tell the current Ticker that it has no displayable
       
   926         iTicker->SetDisplayableL(this, KRemoveDisplayable);
       
   927     }
       
   928 
       
   929     iTicker = newTicker;
       
   930     if (iTicker)
       
   931     {
       
   932         iTicker->SetDisplayableL(this, KAddDisplayable);
       
   933     }
       
   934 
       
   935     // Request ticker timer if a valid ticker has been set and
       
   936     // this is the current displayable.
       
   937     UpdateTickerL();
       
   938 }
       
   939 
       
   940 // ---------------------------------------------------------------------------
       
   941 //
       
   942 // ---------------------------------------------------------------------------
       
   943 //
       
   944 MMIDTicker* CMIDDisplayable::Ticker() const
       
   945 {
       
   946     return iTicker;
       
   947 }
       
   948 
       
   949 // ---------------------------------------------------------------------------
       
   950 // Ensures that ticker update events are generated when appropriate
       
   951 // (e.g. when active) and that this displayables ticker control is notified
       
   952 // whenever it needs to redraw.
       
   953 //
       
   954 // ResumeTicker() and SuspendTicker() deal with the ticker timer whereas
       
   955 // PauseTicker() is actually sending the ticker to the background makeing it
       
   956 // disappear.
       
   957 // ---------------------------------------------------------------------------
       
   958 void CMIDDisplayable::UpdateTickerL()
       
   959 {
       
   960     if (iActive)
       
   961     {
       
   962         iUIManager->OpenNaviPaneControllerL()->SetTickerL(iTicker);
       
   963         if (iIsFullScreenMode || iIsPopupTextBox)
       
   964         {
       
   965             iUIManager->OpenNaviPaneControllerL()->ShowTickerL(EFalse);
       
   966         }
       
   967         else
       
   968         {
       
   969             iUIManager->OpenNaviPaneControllerL()->ShowTickerL(ETrue);
       
   970         }
       
   971     }
       
   972 }
       
   973 
       
   974 // ---------------------------------------------------------------------------
       
   975 //
       
   976 // ---------------------------------------------------------------------------
       
   977 //
       
   978 void CMIDDisplayable::HandleSwitchOnL(TBool /*aSwitchOn*/)
       
   979 {
       
   980 }
       
   981 
       
   982 // ---------------------------------------------------------------------------
       
   983 //
       
   984 // ---------------------------------------------------------------------------
       
   985 //
       
   986 void CMIDDisplayable::HandleForegroundL(TBool aForeground)
       
   987 {
       
   988     DEBUG("+ CMIDDisplayable::HandleForegroundL");
       
   989 
       
   990     // send HandleForegroundL notification to Form
       
   991     if (iContent && (iContent->Type() == MMIDComponent::EForm) && iContentControl)
       
   992     {
       
   993         CMIDForm* form = static_cast<CMIDForm*>(iContentControl);
       
   994         ASSERT(form);
       
   995         form->HandleForegroundL(aForeground);
       
   996     }
       
   997 
       
   998     // Notify canvas about gained foreground only if it is the current displayable
       
   999     if (!aForeground || iActive)
       
  1000     {
       
  1001         HandleCanvasForeground(aForeground);
       
  1002     }
       
  1003 
       
  1004     if (aForeground)
       
  1005     {
       
  1006         // If MIDlet is sent to foreground and JAD-attribute BackgroundEvent=Pause,
       
  1007         // then call startApp() method for the MIDlet.
       
  1008 
       
  1009         if (iEnv.MidletAttributeIsSetToVal(LcduiMidletAttributes::KAttribBackgroundEvent,
       
  1010                                            LcduiMidletAttributeValues::KPauseValue))
       
  1011 
       
  1012         {
       
  1013             iEnv.PostMidletEvent(EStart);
       
  1014             iAppUi->SetPauseAppState(EFalse);
       
  1015         }
       
  1016     }
       
  1017     else //to background
       
  1018     {
       
  1019 
       
  1020         // If MIDlet is sent to background and JAD-attribute BackgroundEvent=Pause,
       
  1021         // and window is not faded yet or window is already faded but pauseApp was not called yet,
       
  1022         // then call pauseApp() method for the MIDlet.
       
  1023         TBool isfaded = this->DrawableWindow()->IsFaded();
       
  1024 
       
  1025         if (iEnv.MidletAttributeIsSetToVal(LcduiMidletAttributes::KAttribBackgroundEvent,
       
  1026                                            LcduiMidletAttributeValues::KPauseValue) && (!isfaded ||
       
  1027                                                    (isfaded && !iAppUi->GetPauseAppState())))
       
  1028 
       
  1029         {
       
  1030             iEnv.PostMidletEvent(EPause);
       
  1031             iAppUi->SetPauseAppState(ETrue);
       
  1032         }
       
  1033     }
       
  1034     DEBUG("- CMIDDisplayable::HandleForegroundL");
       
  1035 }
       
  1036 
       
  1037 // ---------------------------------------------------------------------------
       
  1038 //
       
  1039 // ---------------------------------------------------------------------------
       
  1040 //
       
  1041 void CMIDDisplayable::HandleResourceChangeL(TInt aType)
       
  1042 {
       
  1043     DEBUG("+ CMIDDisplayable::HandleResourceChangeL");
       
  1044 
       
  1045     if (aType == KEikDynamicLayoutVariantSwitch)
       
  1046     {
       
  1047         // dynamic orientation change
       
  1048 
       
  1049         // Correct rect is set for displayable
       
  1050         if (iActive && iCanvasKeypad)
       
  1051         {
       
  1052             //Update correct On-Screen Keypad type
       
  1053             UpdateOnScreenKeypadSettings();
       
  1054         }
       
  1055         UpdateDisplayableRect();
       
  1056         SetRect(iDisplayableRect);
       
  1057 
       
  1058         // MIDlet icon is resized in cpane SizeChanged()
       
  1059         if (!iActive && iContentControl)
       
  1060         {
       
  1061             //The active displayable already gets this call by the CONE framework but
       
  1062             //background displayables don't, so for example a background form won't be
       
  1063             //re-laid-out if we don't call this here
       
  1064             iContentControl->HandleResourceChange(aType);
       
  1065         }
       
  1066 #ifdef RD_SCALABLE_UI_V2
       
  1067         // When current Displayble is Canvas or popup Displayable and the last
       
  1068         // Displayble was Canvas, then OSK visual appearance is needed
       
  1069         //  to be change.
       
  1070         if (iUseOnScreenKeypad && iCanvasKeypad && (iActive || this->DrawableWindow()->IsFaded()))
       
  1071         {
       
  1072             if (iActive)
       
  1073             {
       
  1074                 // Current is Canvas.
       
  1075                 iCanvasKeypad->UpdateVisualAppearanceL(*iCanvas, iOnScreenKeyboardType, *this);
       
  1076             }
       
  1077             else
       
  1078             {
       
  1079                 // Get current Displayable and the last fullscreen Displayble.
       
  1080                 MMIDDisplayable* current = iEnv.Current();
       
  1081                 const MMIDDisplayable* last = iEnv.LastFullscreenDisplayable();
       
  1082                 if (current && last && current->Component()
       
  1083                         && last->Component())
       
  1084                 {
       
  1085                     // Get types of Displayables.
       
  1086                     MMIDComponent::TType lastType = last->Component()->Type();
       
  1087                     MMIDComponent::TType currentType = current->Component()->Type();
       
  1088                     if (lastType == ECanvas)
       
  1089                     {
       
  1090                         if (currentType == EAlert)
       
  1091                         {
       
  1092                             // Current is Alert and the last fullscreen
       
  1093                             // Displayable was Canvas.
       
  1094                             iCanvasKeypad->UpdateVisualAppearanceL(
       
  1095                                 *iCanvas, iOnScreenKeyboardType, *this);
       
  1096                         }
       
  1097                         else if (currentType == ETextBox && current->IsPopupTextBox())
       
  1098                         {
       
  1099                             // Current is popup TextBox and the last fullscreen
       
  1100                             // Displayable was Canvas.
       
  1101                             iCanvasKeypad->UpdateVisualAppearanceL(
       
  1102                                 *iCanvas, iOnScreenKeyboardType, *this);
       
  1103                         }
       
  1104                     }
       
  1105                 }
       
  1106             }
       
  1107         }
       
  1108 #endif // RD_SCALABLE_UI_V2
       
  1109         iFullscreenCanvasLabelCacheIsValid = EFalse;
       
  1110     }
       
  1111     else if (aType == KEikColorResourceChange ||
       
  1112              aType == KAknsMessageSkinChange  ||
       
  1113              aType == KUidValueCoeColorSchemeChangeEvent)
       
  1114     {
       
  1115         //skin or color change, may need to recreate ctx icon
       
  1116         // send skin change event to non-active controls so they can also
       
  1117         // reload graphics
       
  1118         if (!iActive && iContentControl)
       
  1119         {
       
  1120             iContentControl->HandleResourceChange(aType);
       
  1121         }
       
  1122 #ifdef RD_SCALABLE_UI_V2
       
  1123         if (iUseOnScreenKeypad && iCanvasKeypad && iActive)
       
  1124         {
       
  1125             iCanvasKeypad->UpdateVisualAppearanceL(*iCanvas, iOnScreenKeyboardType, *this);
       
  1126         }
       
  1127 #endif // RD_SCALABLE_UI_V2
       
  1128         iFullscreenCanvasLabelCacheIsValid = EFalse;
       
  1129     }
       
  1130 
       
  1131     DEBUG("- CMIDDisplayable::HandleResourceChangeL");
       
  1132 
       
  1133     // Language input change, needed by TextEditor.
       
  1134     if ((aType == KEikInputLanguageChange) && iContentControl)
       
  1135     {
       
  1136         iContentControl->HandleResourceChange(aType);
       
  1137     }
       
  1138 }
       
  1139 
       
  1140 #ifdef RD_JAVA_NGA_ENABLED
       
  1141 void CMIDDisplayable::HandleFullOrPartialForegroundL(TBool aFullOrPartialFg)
       
  1142 {
       
  1143     CMIDCanvas* canvas = GetContentCanvas();
       
  1144     if (canvas)
       
  1145     {
       
  1146         canvas->HandleFullOrPartialForegroundL(aFullOrPartialFg, iActive);
       
  1147     }
       
  1148 }
       
  1149 
       
  1150 void CMIDDisplayable::HandleFreeGraphicsMemory()
       
  1151 {
       
  1152     CMIDCanvas* canvas = GetContentCanvas();
       
  1153     if (canvas)
       
  1154     {
       
  1155         canvas->FreeGraphicsMemory(ETrue);
       
  1156     }
       
  1157 }
       
  1158 #endif // RD_JAVA_NGA_ENABLED
       
  1159 
       
  1160 /**
       
  1161  * The container has changed it available drawing space, so resize
       
  1162  * the displayable to fit and post a size changed event.
       
  1163  **/
       
  1164 void CMIDDisplayable::Layout()
       
  1165 {
       
  1166     TBool changed(EFalse);
       
  1167 
       
  1168     //
       
  1169     // Get client area of window (within border).
       
  1170     //
       
  1171     TRect rect(iBorder.InnerRect(Rect()));
       
  1172 
       
  1173     if (iContentControl)
       
  1174     {
       
  1175         if (iContentControl->Rect() != rect)
       
  1176         {
       
  1177             // Anything left in rect is space for the content.
       
  1178             // It is arguable that the content should post the resize event as
       
  1179             // it knows its true size. Certainly that is required for Canvas.
       
  1180             iContentControl->SetRect(rect);
       
  1181             changed = ETrue;
       
  1182             TRAP_IGNORE(iUIManager->OpenNaviPaneControllerL()->LayoutTickerL());
       
  1183         }
       
  1184 
       
  1185         MMIDComponent::TType type = iContent->Type();
       
  1186         //
       
  1187         // We assume that the content width/height == control width height
       
  1188         // arguably not a valid assumption for any content - but especially
       
  1189         // invalid for Canvas when the JAD specifies an assumed size.
       
  1190         //
       
  1191         // Let Canvas's post their own size, but
       
  1192         // use the content rect size for all other displayables.
       
  1193         //
       
  1194         if (type != ECanvas && type != EGameCanvas)
       
  1195         {
       
  1196             //
       
  1197             // Only post this event for non-canvas components.
       
  1198             //
       
  1199             TSize size(rect.Size());
       
  1200             iEnv.PostJavaEvent(*this, EDisplayable, ESizeChanged, size.iWidth, size.iHeight, 0);
       
  1201         }
       
  1202     }
       
  1203 
       
  1204     if (changed)
       
  1205     {
       
  1206         DrawDeferred();
       
  1207     }
       
  1208 }
       
  1209 
       
  1210 // ---------------------------------------------------------------------------
       
  1211 //
       
  1212 // ---------------------------------------------------------------------------
       
  1213 //
       
  1214 TInt CMIDDisplayable::GetSKPositionForOSK()
       
  1215 {
       
  1216     return iSKPositionWithQwerty;
       
  1217 }
       
  1218 
       
  1219 // ---------------------------------------------------------------------------
       
  1220 //
       
  1221 // ---------------------------------------------------------------------------
       
  1222 //
       
  1223 TRect CMIDDisplayable::GetCanvasRectFromLaf()
       
  1224 {
       
  1225     DEBUG("+ CMIDDisplayable::GetCanvasRectFromLaf");
       
  1226 
       
  1227     TRect resultRect = TRect(0,0,0,0);
       
  1228     AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EScreen, resultRect);
       
  1229     TAknLayoutRect canvasRect;
       
  1230     TAknLayoutRect mainPane;
       
  1231     TAknLayoutRect mainMidpPane;
       
  1232 
       
  1233 #ifdef RD_JAVA_S60_RELEASE_9_2
       
  1234     // If split screen is open, then it is needed return current size of Canvas.
       
  1235     if (iSplitScreenKeyboard)
       
  1236     {
       
  1237         CMIDCanvas* canvas = GetContentCanvas();
       
  1238         if (canvas)
       
  1239         {
       
  1240             resultRect = canvas->ViewRect();
       
  1241         }
       
  1242     }
       
  1243     else
       
  1244     {
       
  1245 #endif // RD_JAVA_S60_RELEASE_9_2    
       
  1246         //Read canvasRect from LAF depending on keyboard type
       
  1247         switch (iOnScreenKeyboardType)
       
  1248         {
       
  1249         case EOnScreenKeypadValueNo:
       
  1250             break;
       
  1251         case EOnScreenKeypadValueNavigationKeys:
       
  1252         {
       
  1253             if (iIsFullScreenMode)
       
  1254             {
       
  1255                 if (!Layout_Meta_Data::IsLandscapeOrientation())  //portrait
       
  1256                 {
       
  1257                     canvasRect.LayoutRect(resultRect, AknLayoutScalable_Avkon::midp_canvas_pane(1).LayoutLine());
       
  1258                 }
       
  1259                 else //landscape
       
  1260                 {
       
  1261                     canvasRect.LayoutRect(resultRect, AknLayoutScalable_Avkon::midp_canvas_pane(8).LayoutLine());
       
  1262                 }
       
  1263             }
       
  1264             else //normal mode
       
  1265             {
       
  1266                 if (!Layout_Meta_Data::IsLandscapeOrientation())  //portrait
       
  1267                 {
       
  1268                     mainPane.LayoutRect(resultRect, AknLayoutScalable_Avkon::main_pane(3).LayoutLine());
       
  1269                     mainMidpPane.LayoutRect(mainPane.Rect(), AknLayoutScalable_Avkon::main_midp_pane(0).LayoutLine());
       
  1270                     canvasRect.LayoutRect(mainMidpPane.Rect(), AknLayoutScalable_Avkon::midp_canvas_pane(4).LayoutLine());
       
  1271                 }
       
  1272                 else //landscape
       
  1273                 {
       
  1274                     mainPane.LayoutRect(resultRect, AknLayoutScalable_Avkon::main_pane(4).LayoutLine());
       
  1275                     mainMidpPane.LayoutRect(mainPane.Rect(), AknLayoutScalable_Avkon::main_midp_pane(1).LayoutLine());
       
  1276                     canvasRect.LayoutRect(mainMidpPane.Rect(), AknLayoutScalable_Avkon::midp_canvas_pane(7).LayoutLine());
       
  1277                 }
       
  1278             }
       
  1279             resultRect = canvasRect.Rect();
       
  1280             break;
       
  1281         }
       
  1282         case EOnScreenKeypadValueGameActions:
       
  1283         {
       
  1284             if (iIsFullScreenMode)
       
  1285             {
       
  1286                 if (!Layout_Meta_Data::IsLandscapeOrientation())  //portrait
       
  1287                 {
       
  1288                     canvasRect.LayoutRect(resultRect, AknLayoutScalable_Avkon::midp_canvas_pane(2).LayoutLine());
       
  1289                 }
       
  1290                 else //landscape
       
  1291                 {
       
  1292                     canvasRect.LayoutRect(resultRect, AknLayoutScalable_Avkon::midp_canvas_pane(3).LayoutLine());
       
  1293                 }
       
  1294             }
       
  1295             else //normal mode
       
  1296             {
       
  1297                 if (!Layout_Meta_Data::IsLandscapeOrientation())  //portrait
       
  1298                 {
       
  1299                     mainPane.LayoutRect(resultRect, AknLayoutScalable_Avkon::main_pane(3).LayoutLine());
       
  1300                     mainMidpPane.LayoutRect(mainPane.Rect(), AknLayoutScalable_Avkon::main_midp_pane(0).LayoutLine());
       
  1301                     canvasRect.LayoutRect(mainMidpPane.Rect(), AknLayoutScalable_Avkon::midp_canvas_pane(5).LayoutLine());
       
  1302                 }
       
  1303                 else//landscape
       
  1304                 {
       
  1305                     mainPane.LayoutRect(resultRect, AknLayoutScalable_Avkon::main_pane(4).LayoutLine());
       
  1306                     mainMidpPane.LayoutRect(mainPane.Rect(), AknLayoutScalable_Avkon::main_midp_pane(1).LayoutLine());
       
  1307                     canvasRect.LayoutRect(mainMidpPane.Rect(), AknLayoutScalable_Avkon::midp_canvas_pane(6).LayoutLine());
       
  1308                 }
       
  1309             }
       
  1310             resultRect = canvasRect.Rect();
       
  1311             break;
       
  1312         }
       
  1313         case EOnScreenKeypadValueLskRsk:
       
  1314         {
       
  1315             if (iIsFullScreenMode)
       
  1316             {
       
  1317                 if (!Layout_Meta_Data::IsLandscapeOrientation())  //portrait
       
  1318                 {
       
  1319                     canvasRect.LayoutRect(resultRect, AknLayoutScalable_Avkon::midp_canvas_pane(11).LayoutLine());
       
  1320                 }
       
  1321                 else //landscape
       
  1322                 {
       
  1323                     if (iSKPositionWithQwerty == ESoftkeysRight)
       
  1324                     {
       
  1325                         canvasRect.LayoutRect(resultRect, AknLayoutScalable_Avkon::midp_canvas_pane(10).LayoutLine());
       
  1326                     }
       
  1327                     else
       
  1328                     {
       
  1329 #ifdef RD_JAVA_S60_RELEASE_9_2
       
  1330                         canvasRect.LayoutRect(resultRect, AknLayoutScalable_Avkon::midp_canvas_pane(9).LayoutLine());
       
  1331 #else
       
  1332                         resultRect = TRect(80,0,560,360); // Layout data not defined in older releases.
       
  1333                         DEBUG("- CMIDDisplayable::GetCanvasRectFromLaf");
       
  1334                         return resultRect;
       
  1335 #endif // RD_JAVA_S60_RELEASE_9_2
       
  1336                     }
       
  1337                 }
       
  1338             }
       
  1339             else//normal mode
       
  1340             {
       
  1341                 //no need to present LSK&RSK in OSK when in normal mode Canvas
       
  1342                 resultRect = TRect(0,0,0,0);
       
  1343 
       
  1344                 DEBUG("- CMIDDisplayable::GetCanvasRectFromLaf");
       
  1345                 return resultRect;
       
  1346             }
       
  1347             resultRect = canvasRect.Rect();
       
  1348             break;
       
  1349         }
       
  1350         }
       
  1351 #ifdef RD_JAVA_S60_RELEASE_9_2
       
  1352     }
       
  1353 #endif // RD_JAVA_S60_RELEASE_9_2
       
  1354 
       
  1355     DEBUG("- CMIDDisplayable::GetCanvasRectFromLaf");
       
  1356     return resultRect;
       
  1357 }
       
  1358 
       
  1359 // ---------------------------------------------------------------------------
       
  1360 //
       
  1361 // ---------------------------------------------------------------------------
       
  1362 //
       
  1363 void CMIDDisplayable::AddCommandL(MMIDCommand* aCommand)
       
  1364 {
       
  1365     iCommandList->AddL(aCommand);
       
  1366     InitializeCbasL();
       
  1367     iMenuHandler->UpdateMenuIfVisibleL();
       
  1368 }
       
  1369 
       
  1370 // ---------------------------------------------------------------------------
       
  1371 //
       
  1372 // ---------------------------------------------------------------------------
       
  1373 //
       
  1374 void CMIDDisplayable::RemoveCommand(MMIDCommand* aCommand)
       
  1375 {
       
  1376     iCommandList->Remove(aCommand);
       
  1377     TRAP_IGNORE(InitializeCbasL());
       
  1378     TRAP_IGNORE(iMenuHandler->UpdateMenuIfVisibleL());
       
  1379 }
       
  1380 
       
  1381 // ---------------------------------------------------------------------------
       
  1382 // This method reports the total space available to the
       
  1383 // content class. Displayable subclasses may report a
       
  1384 // different value as the width/height in which case they
       
  1385 // will use a differnt mechanism.
       
  1386 // @see MMIDCanvas::ContentSize
       
  1387 // @see MMIDForm::Width
       
  1388 // @see MMIDForm::Height
       
  1389 // ---------------------------------------------------------------------------
       
  1390 TSize CMIDDisplayable::ContentSize() const
       
  1391 {
       
  1392     if (iContent->Type() == MMIDComponent::EAlert)
       
  1393     {
       
  1394         return static_cast<CMIDAlert*>(iContent)->Dialog()->Size();
       
  1395     }
       
  1396     else if (iContent->Type() == MMIDComponent::ETextBox && iIsPopupTextBox)
       
  1397     {
       
  1398         return static_cast<CMIDTextBoxDialogControl*>(iContent)->Dialog()->ContentSize();
       
  1399     }
       
  1400     else if (iContent->Type() == MMIDComponent::EForm)
       
  1401     {
       
  1402         // return the size that is available for the form items
       
  1403         // as stated in MIDP specification. This is smaller size than would be
       
  1404         // returned by the iContentControl->Size().
       
  1405         CMIDForm* form = static_cast<CMIDForm*>(iContent);
       
  1406         return TSize(form->Width(), form->Height());
       
  1407     }
       
  1408     /**
       
  1409     Size really depends on the content class, however
       
  1410     javax.microedition.lcdui.Form and javax.microedition.lcdui.Canvas
       
  1411     contain overrides to return the correct size - so polymorphism is
       
  1412     only required here for List,TextBox and Alert.
       
  1413 
       
  1414     We return the size of the content control, so as long as the content
       
  1415     control keeps its size up to date (eg alerts must have the same size as the dialog)
       
  1416     the correct size will be returned even if there is no polymorphism
       
  1417     provided by the framework. Now, for alerts UpdateSizeL() must have
       
  1418     been called, in fact when the dialog is not yet displaying they need
       
  1419     to create one, set the size and then delete the dialog immediately.
       
  1420     */
       
  1421     if (iContentControl)
       
  1422     {
       
  1423         return iContentControl->Size();
       
  1424     }
       
  1425 
       
  1426     //If there is no content then we shouldn't really exist
       
  1427     //because java side Displayable is abstract
       
  1428     return TSize(0,0);
       
  1429 }
       
  1430 
       
  1431 // ---------------------------------------------------------------------------
       
  1432 // Called by the framework when current displayable was changed
       
  1433 // in case that old and new displayable type is canvas to change osk state
       
  1434 // ---------------------------------------------------------------------------
       
  1435 void CMIDDisplayable::ChangeOSKBackgroundState(TBool aOSKBackgroundState)
       
  1436 {
       
  1437     if (iContent && iContent->Type() == ECanvas)
       
  1438     {
       
  1439         if (iCanvasKeypad)
       
  1440         {
       
  1441             iCanvasKeypad->OSKInBackground(aOSKBackgroundState);
       
  1442         }
       
  1443     }
       
  1444 }
       
  1445 
       
  1446 // ---------------------------------------------------------------------------
       
  1447 // Called by the framework when we become or stop being the active displayable.
       
  1448 // See HandleActivated(), HandleDeactivated().
       
  1449 // ---------------------------------------------------------------------------
       
  1450 void CMIDDisplayable::HandleCurrentL(TBool aCurrent)
       
  1451 {
       
  1452     DEBUG("+ CMIDDisplayable::HandleCurrentL");
       
  1453     ASSERT(iContentControl);
       
  1454     ASSERT(iContent);
       
  1455 
       
  1456     iActive = aCurrent;
       
  1457     const TType type = iContent->Type();
       
  1458 
       
  1459     if (aCurrent)
       
  1460     {
       
  1461         HandleCanvasForeground(aCurrent);
       
  1462 
       
  1463         // when setting displayable as current remember to deactivate
       
  1464         // the default displayable if it has not been done yet
       
  1465         CMIDDisplayable* defaultDisplayable =
       
  1466             iUIManager->GetDefaultDisplayable();
       
  1467         if (defaultDisplayable &&
       
  1468                 (this != defaultDisplayable) &&
       
  1469                 defaultDisplayable->IsActive())
       
  1470         {
       
  1471             defaultDisplayable->HandleCurrentL(EFalse);
       
  1472         }
       
  1473         // "Whole screen size"-displayable behind popup type displayable is stored.
       
  1474         if (type == EAlert || (type == ETextBox && iIsPopupTextBox))
       
  1475         {
       
  1476             if (!(iMenuHandler->GetDisplayable() && (iMenuHandler->GetDisplayable()->IsPopupTextBox() ||
       
  1477                     iMenuHandler->GetDisplayable()->Component()->Type() == EAlert)))
       
  1478             {
       
  1479                 iDisplayableBehindPopup    = iMenuHandler->GetDisplayable();
       
  1480             }
       
  1481         }
       
  1482 
       
  1483         iMenuHandler->SetDisplayable(this);
       
  1484         // Tell the iAppUi about setting this as active
       
  1485         iAppUi->SetCurrentDisplayable(this);
       
  1486         HandleActivatedL();
       
  1487     }
       
  1488     else
       
  1489     {
       
  1490         HandleDeactivated();
       
  1491     }
       
  1492 
       
  1493     if (type == EAlert)
       
  1494     {
       
  1495         // alerts do their on thing, they rely on sleeping dialogs in fact
       
  1496         CMIDAlert* alert = static_cast<CMIDAlert*>(iContentControl);
       
  1497         TRAP_IGNORE(alert->HandleCurrentL(aCurrent));
       
  1498 
       
  1499         UpdateTickerL();
       
  1500     }
       
  1501     else if (type == ETextBox && iIsPopupTextBox)
       
  1502     {
       
  1503         // Pop-up TextBox do their on thing, they rely on sleeping dialogs in fact
       
  1504         CMIDTextBoxDialogControl* textBoxDialogControl =
       
  1505             static_cast<CMIDTextBoxDialogControl*>(iContentControl);
       
  1506         TRAP_IGNORE(textBoxDialogControl->HandleCurrentL(aCurrent));
       
  1507     }
       
  1508     else
       
  1509     {
       
  1510         if (aCurrent)
       
  1511         {
       
  1512             UpdateVisualAppearanceL();
       
  1513         }
       
  1514         else
       
  1515         {
       
  1516             // Hide the displayable except the current displayable is Alert
       
  1517             // or pop-up TextBox.
       
  1518             if ((this != iUIManager->GetDefaultDisplayable()) &&
       
  1519                     (iMenuHandler->GetDisplayable()) &&
       
  1520                     (iMenuHandler->GetDisplayable()->Component()->Type() != EAlert)  &&
       
  1521                     !(iMenuHandler->GetDisplayable()->Component()->Type() == ETextBox &&
       
  1522                       iMenuHandler->GetDisplayable()->IsPopupTextBox()))
       
  1523             {
       
  1524                 MakeVisible(EFalse);
       
  1525             }
       
  1526 
       
  1527             // Notify canvas after changing the visibility
       
  1528             HandleCanvasForeground(aCurrent);
       
  1529         }
       
  1530 
       
  1531         iContentControl->SetFocus(aCurrent);
       
  1532 
       
  1533         switch (type)
       
  1534         {
       
  1535         case EForm:
       
  1536         {
       
  1537             CMIDForm* form = static_cast<CMIDForm*>(iContentControl);
       
  1538             TRAP_IGNORE(form->HandleCurrentL(aCurrent));
       
  1539             break;
       
  1540         }
       
  1541         case ETextBox:
       
  1542         {
       
  1543             CMIDTextBoxControl* textBoxControl =
       
  1544                 static_cast<CMIDTextBoxControl*>(iContentControl);
       
  1545             TRAP_IGNORE(textBoxControl->HandleCurrentL(aCurrent));
       
  1546             break;
       
  1547         }
       
  1548         }
       
  1549     }
       
  1550 
       
  1551     DEBUG("- CMIDDisplayable::HandleCurrentL");
       
  1552 }
       
  1553 
       
  1554 /**
       
  1555  * Called when we become the active displayable, see HandleCurrent().
       
  1556  * Put icontentControl on the app UI stack and update the title.
       
  1557  **/
       
  1558 void CMIDDisplayable::HandleActivatedL()
       
  1559 {
       
  1560     DEBUG("+ CMIDDisplayable::HandleActivatedL");
       
  1561     ASSERT(iContentControl);
       
  1562 
       
  1563     if (iContentControl->IsNonFocusing()) // i.e it's a Form
       
  1564     {
       
  1565         iAppUi->AddToStackL(
       
  1566             iContentControl,
       
  1567             (ECoeStackPriorityDefault - 1),
       
  1568             ECoeStackFlagRefusesFocus);
       
  1569     }
       
  1570     else
       
  1571     {
       
  1572         iAppUi->AddToStackL(iContentControl);
       
  1573     }
       
  1574 
       
  1575     ShowTitleL();
       
  1576 
       
  1577     /* In case Canvas is in fullcsreen mode iDisplaybleRect needs to be updated.
       
  1578      * The Canvas rect has been reduced if Casvas has been displayed before (See HandleDeactivated).
       
  1579      */
       
  1580     if (iContent && iContent->Type() == ECanvas)
       
  1581     {
       
  1582         if (iCanvasKeypad)
       
  1583         {
       
  1584             UpdateOnScreenKeypadSettings();
       
  1585         }
       
  1586         UpdateDisplayableRect();
       
  1587         SetRect(iDisplayableRect);
       
  1588     }
       
  1589 
       
  1590 #ifdef RD_SCALABLE_UI_V2
       
  1591     // Hide CanvasKeypad if the current displayable is not Alert nor pop-up TextBox.
       
  1592     if (iUIManager->GetCanvasKeypad() && !iCanvasKeypad &&
       
  1593             (iContent->Type() != EAlert &&
       
  1594              !(iContent->Type() == ETextBox && iIsPopupTextBox)))
       
  1595     {
       
  1596         iUIManager->GetCanvasKeypad()->MakeVisible(EFalse);
       
  1597     }
       
  1598 #endif //RD_SCALABLE_UI_V2
       
  1599 
       
  1600     DEBUG("- CMIDDisplayable::HandleActivatedL");
       
  1601 }
       
  1602 
       
  1603 // ---------------------------------------------------------------------------
       
  1604 // Called when we stop being the active displayable, see HandleCurrent().
       
  1605 // Remove iContentControl from the app UI stack. If a menu was showing then
       
  1606 // hide it.
       
  1607 // ---------------------------------------------------------------------------
       
  1608 void CMIDDisplayable::HandleDeactivated()
       
  1609 {
       
  1610     DEBUG("+ CMIDDisplayable::HandleDeactivated");
       
  1611     ASSERT(iContentControl);
       
  1612 
       
  1613     // Make displayable behind popup/Alert non-visible if displayable behind
       
  1614     // popup/Alert is changed to Canvas when dismissing the popup/Alert.
       
  1615     // Use case: Canvas on-screen keypad visibility after displayable changes.
       
  1616     if (iDisplayableBehindPopup && iContent && (iContent->Type() == EAlert || (iContent->Type() == ETextBox && iIsPopupTextBox))
       
  1617             && iDisplayableBehindPopup != iMenuHandler->GetDisplayable())
       
  1618     {
       
  1619         if (iMenuHandler->GetDisplayable()->Component()->Type() == ECanvas ||
       
  1620                 iMenuHandler->GetDisplayable()->Component()->Type() == EGameCanvas)
       
  1621         {
       
  1622             iDisplayableBehindPopup->MakeVisible(EFalse);
       
  1623         }
       
  1624     }
       
  1625 
       
  1626     // Stop displaying commands of old displayable
       
  1627     iMenuHandler->HideMenuIfVisible();
       
  1628 
       
  1629     // Stop repeat timer if OSK set to background
       
  1630     if (iContent && iContent->Type() == ECanvas && iCanvasKeypad)
       
  1631     {
       
  1632         iCanvasKeypad->OSKInBackground(ETrue);
       
  1633     }
       
  1634 
       
  1635     iAppUi->RemoveFromStack(iContentControl);
       
  1636 
       
  1637     /* Enable status pane when Canvas in fullscreen mode is deactivated.
       
  1638      * In case there is Canvas in fullscreen mode and then setCurrent(Alert,normal mode displayable)
       
  1639      * is called, status pane stays behind the Canvas window.
       
  1640      * First we make status pane and cbas visible according to whether we
       
  1641      * are full screen or not. This determines the rect returned by iAppUi->ClientRect()
       
  1642      */
       
  1643     if (iContent && iContent->Type() == ECanvas && iIsFullScreenMode)
       
  1644     {
       
  1645         CEikStatusPane* pane = iAppUi->StatusPane();
       
  1646         pane->MakeVisible(ETrue);
       
  1647         // set right Width from APPUI client rect
       
  1648         TRect displayableRectT = iDisplayableRect;
       
  1649         TRect iDisplayableRect = iAppUi->ClientRect();
       
  1650         iDisplayableRect.iBr.iY = displayableRectT.iBr.iY;
       
  1651 
       
  1652         TRAPD(err, SetFullScreenModeL(ETrue));
       
  1653         if (err != KErrNone)
       
  1654         {
       
  1655             DEBUG_INT("CMIDDisplayable::HandleDeactivated - SetFullScreenModeL error %d", err);
       
  1656         }
       
  1657     }
       
  1658 
       
  1659     DEBUG("- CMIDDisplayable::HandleDeactivated");
       
  1660 }
       
  1661 
       
  1662 // ---------------------------------------------------------------------------
       
  1663 //
       
  1664 // ---------------------------------------------------------------------------
       
  1665 //
       
  1666 void CMIDDisplayable::UpdateVisualAppearanceL()
       
  1667 {
       
  1668     DEBUG("+ CMIDDisplayable::UpdateVisualAppearanceL");
       
  1669 
       
  1670     Window().SetOrdinalPosition(0);
       
  1671     MakeVisible(ETrue);
       
  1672 
       
  1673     // First we make status pane and cbas visible according to whether we
       
  1674     // are full screen or not. This determines the rect returned by
       
  1675     // iAppUi->ClientRect()
       
  1676     CEikStatusPane* pane = iAppUi->StatusPane();
       
  1677     pane->MakeVisible(!iIsFullScreenMode);
       
  1678 
       
  1679     java::ui::CoreUiAvkonAppUi* appUi =
       
  1680         java::ui::CoreUiAvkonLcdui::getInstance().getJavaUiAppUi();
       
  1681     if (!iIsFullScreenMode && appUi && appUi->hidesIndicators())
       
  1682     {
       
  1683         HideIndicators();
       
  1684     }
       
  1685 
       
  1686     if (iCba)
       
  1687     {
       
  1688         iCba->MakeVisible(!iIsFullScreenMode);
       
  1689 
       
  1690 #ifdef RD_JAVA_S60_RELEASE_9_2
       
  1691         // To enable clock pane in landscape after MIDlet was started
       
  1692         iCba->SetBoundingRect(TRect(0, 0, 0, 0));
       
  1693 #endif // RD_JAVA_S60_RELEASE_9_2
       
  1694     }
       
  1695 
       
  1696     // Close fixed toolbar for full screen Canvas.
       
  1697     CAknToolbar* toolbar = iAppUi->CurrentFixedToolbar();
       
  1698     if (toolbar)
       
  1699     {
       
  1700         toolbar->SetToolbarVisibility(!iIsFullScreenMode);
       
  1701     }
       
  1702 
       
  1703 #ifdef RD_SCALABLE_UI_V2
       
  1704     if ((iActive && iCanvasKeypad)
       
  1705             || (!iActive && this->DrawableWindow()->IsFaded()
       
  1706                 && iCanvasKeypad))
       
  1707     {
       
  1708         if (iUseOnScreenKeypad)
       
  1709         {
       
  1710             iCanvasKeypad->UpdateVisualAppearanceL(
       
  1711                 *iCanvas, iOnScreenKeyboardType, *this);
       
  1712 
       
  1713             // Because keypad changed its appearance we have to assure that
       
  1714             // values for soft key label locations are updated.
       
  1715             iFullscreenCanvasLabelCacheIsValid = EFalse;
       
  1716         }
       
  1717         else
       
  1718         {
       
  1719             // Canvas keypad has to be set invisible if On-Screen keypad is
       
  1720             // not to be used. Otherwise, if the visibility not handled here,
       
  1721             // status pane and CBA area's visual appearance can be corrupted.
       
  1722             if (!iIsFullScreenMode)
       
  1723             {
       
  1724                 iCanvasKeypad->MakeVisible(EFalse);
       
  1725             }
       
  1726         }
       
  1727     }
       
  1728 #endif //RD_SCALABLE_UI_V2
       
  1729 
       
  1730     // At this point we can set the rect.
       
  1731     if (!iIsFullScreenMode && iCba)
       
  1732     {
       
  1733         InitializeCbasL();
       
  1734         iCba->DrawableWindow()->SetOrdinalPosition(0);
       
  1735     }
       
  1736 
       
  1737     UpdateTickerL();
       
  1738     DrawDeferred();
       
  1739     DEBUG("- CMIDDisplayable::UpdateVisualAppearanceL");
       
  1740 }
       
  1741 
       
  1742 // ---------------------------------------------------------------------------
       
  1743 //
       
  1744 // ---------------------------------------------------------------------------
       
  1745 //
       
  1746 void CMIDDisplayable::SetComponentL(MMIDComponent& aComponent)
       
  1747 {
       
  1748     ASSERT(!iContentControl);
       
  1749 
       
  1750     iContent = &aComponent;
       
  1751     iContentControl = NULL;
       
  1752 
       
  1753     MMIDComponent::TType type = aComponent.Type();
       
  1754     switch (type)
       
  1755     {
       
  1756     case MMIDComponent::EForm:
       
  1757         iContentControl = static_cast<CMIDForm*>(iContent);
       
  1758         break;
       
  1759     case MMIDComponent::EAlert:
       
  1760         iContentControl = static_cast<CMIDAlert*>(iContent);
       
  1761         break;
       
  1762     case MMIDComponent::ECanvas:
       
  1763     case MMIDComponent::EGameCanvas:
       
  1764     {
       
  1765         iContentControl = &(static_cast<MMIDCanvas*>(iContent)->Control());
       
  1766 #ifdef RD_SCALABLE_UI_V2
       
  1767         iCanvas = static_cast<CMIDCanvas*>(iContentControl);
       
  1768         if (AknLayoutUtils::PenEnabled())
       
  1769         {
       
  1770             iUseOnScreenKeypad = ETrue;
       
  1771             iCanvasKeypad = iUIManager->OpenCanvasKeypadL(this);
       
  1772 
       
  1773             // initialize iPropertyWatch as CPropertyWatch
       
  1774             iPropertyWatch = CPropertyWatch::NewL(this);//Property observer
       
  1775             UpdateOnScreenKeypadSettings();
       
  1776         }
       
  1777         UpdateDisplayableRect();
       
  1778         SetRect(iDisplayableRect);
       
  1779 #endif //RD_SCALABLE_UI_V2
       
  1780     }
       
  1781     break;
       
  1782     case MMIDComponent::ETextBox:
       
  1783         if (iIsPopupTextBox) // pop-up TextBox
       
  1784         {
       
  1785             iContentControl = static_cast<CMIDTextBoxDialogControl*>(iContent);
       
  1786         }
       
  1787         else                // normal TextBox
       
  1788         {
       
  1789             iContentControl = static_cast<CMIDTextBoxControl*>(iContent);
       
  1790         }
       
  1791         break;
       
  1792     case MMIDComponent::EList:
       
  1793         iContentControl = static_cast<CMIDList*>(iContent);
       
  1794         // Lengthen long tap delay to get better usability.
       
  1795         iLongTapDetector->SetTimeDelayBeforeAnimation(KListLongTapAnimationDelay);
       
  1796         iLongTapDetector->SetLongTapDelay(KListLongTapAnimationDelay + KListLongTapDelay);
       
  1797         break;
       
  1798     case MMIDComponent::EDefaultBackground:
       
  1799         iContentControl = static_cast<CMIDDefaultBackground*>(iContent);
       
  1800         break;
       
  1801     default:
       
  1802         ASSERT(iContentControl);
       
  1803     }
       
  1804     Layout();
       
  1805 
       
  1806     ASSERT(iContentControl);
       
  1807     iContentControl->ActivateL();
       
  1808 
       
  1809     DEBUG("- CMIDDisplayable::SetComponentL");
       
  1810 }
       
  1811 
       
  1812 
       
  1813 void CMIDDisplayable::UpdateOnScreenKeypadSettings()
       
  1814 {
       
  1815     DEBUG("+ CMIDDisplayable::UpdateOnScreenKeypadSettings");
       
  1816     if (iCanvasKeypad)
       
  1817     {
       
  1818         TInt hwKeyboardLayout = 0;
       
  1819 
       
  1820         if (AknLayoutUtils::PenEnabled())
       
  1821         {
       
  1822             // touch screen
       
  1823             ReadOnScreenKeypadTypeFromSuiteSettings();
       
  1824 
       
  1825             if (iOnScreenKeyboardType == EOnScreenKeypadValueNo)
       
  1826             {
       
  1827                 iUseOnScreenKeypad = EFalse;
       
  1828 
       
  1829                 DEBUG("- CMIDDisplayable::UpdateOnScreenKeypadSettings");
       
  1830                 return;
       
  1831             }
       
  1832 
       
  1833             RProperty::Get(
       
  1834                 KCRUidAvkon, KAknKeyBoardLayout, hwKeyboardLayout);
       
  1835 
       
  1836             // Avoid display of on-screen keypad on screen
       
  1837             // in landscape mode for QWERTY layout 3x11 (4) and 4x10 (3)
       
  1838             if (hwKeyboardLayout == EPtiKeyboardQwerty4x10 ||
       
  1839                     hwKeyboardLayout == EPtiKeyboardQwerty3x11)
       
  1840             {
       
  1841                 // HW keyboard is opened
       
  1842                 if (iIsFullScreenMode)
       
  1843                 {
       
  1844                     iOnScreenKeyboardType = EOnScreenKeypadValueLskRsk;
       
  1845                     iUseOnScreenKeypad = ETrue;
       
  1846                 }
       
  1847                 else
       
  1848                 {
       
  1849                     // normal mode
       
  1850                     iOnScreenKeyboardType = EOnScreenKeypadValueNo;
       
  1851                     iUseOnScreenKeypad = EFalse;
       
  1852                 }
       
  1853             }
       
  1854             else
       
  1855             {
       
  1856                 // Keypadless device or HW keyboard is closed
       
  1857                 iUseOnScreenKeypad = ETrue;
       
  1858             }
       
  1859         }
       
  1860         else
       
  1861         {
       
  1862             // no touch screen
       
  1863             iUseOnScreenKeypad = EFalse;
       
  1864             iOnScreenKeyboardType = EOnScreenKeypadValueNo;
       
  1865         }
       
  1866     }
       
  1867 
       
  1868     DEBUG("- CMIDDisplayable::UpdateOnScreenKeypadSettings");
       
  1869 }
       
  1870 
       
  1871 void CMIDDisplayable::ReadOnScreenKeypadTypeFromSuiteSettings()
       
  1872 {
       
  1873     DEBUG("+ CMIDDisplayable::ReadOnScreenKeypadTypeFromSuiteSettings");
       
  1874 
       
  1875     // Read required keyboard type
       
  1876     // 0=not defined,  1=no, 2=navigationkeys, 3=gameactions(default)
       
  1877     TRAP_IGNORE(iOnScreenKeyboardType = OnScreenKeypadL());
       
  1878     if (iOnScreenKeyboardType == EOnScreenKeypadValueUndefined)
       
  1879     {
       
  1880         // if keypad value cannot be read correctly
       
  1881         // set gameactions keypad active (ignore error silently)
       
  1882         iOnScreenKeyboardType = EOnScreenKeypadValueGameActions;
       
  1883     }
       
  1884 
       
  1885     DEBUG("- CMIDDisplayable::ReadOnScreenKeypadTypeFromSuiteSettings");
       
  1886 }
       
  1887 
       
  1888 void CMIDDisplayable::HandleOnScreenKeypadVisual()
       
  1889 {
       
  1890     DEBUG("+ CMIDDisplayable::HandleOnScreenKeypadVisual");
       
  1891 #ifdef RD_JAVA_S60_RELEASE_9_2
       
  1892     if (iActive && !iSplitScreenKeyboard)
       
  1893 #else
       
  1894     if (iActive)
       
  1895 #endif // RD_JAVA_S60_RELEASE_9_2
       
  1896     {
       
  1897         UpdateOnScreenKeypadSettings();
       
  1898         UpdateDisplayableRect();
       
  1899         SetRect(iDisplayableRect);
       
  1900         TRAP_IGNORE(UpdateVisualAppearanceL());
       
  1901     }
       
  1902     DEBUG("- CMIDDisplayable::HandleOnScreenKeypadVisual");
       
  1903 }
       
  1904 
       
  1905 
       
  1906 // ---------------------------------------------------------------------------
       
  1907 //
       
  1908 // ---------------------------------------------------------------------------
       
  1909 //
       
  1910 CCoeControl& CMIDDisplayable::ContentWindow()
       
  1911 {
       
  1912     return *this;
       
  1913 }
       
  1914 
       
  1915 // ---------------------------------------------------------------------------
       
  1916 //
       
  1917 // ---------------------------------------------------------------------------
       
  1918 //
       
  1919 void CMIDDisplayable::SetCommandListenerExistence(TBool aExistence)
       
  1920 {
       
  1921     iCommandListenerExistence = aExistence;
       
  1922 }
       
  1923 
       
  1924 // ---------------------------------------------------------------------------
       
  1925 //
       
  1926 // ---------------------------------------------------------------------------
       
  1927 //
       
  1928 TBool CMIDDisplayable::IsCommandListenerSet() const
       
  1929 {
       
  1930     return iCommandListenerExistence;
       
  1931 }
       
  1932 
       
  1933 // ---------------------------------------------------------------------------
       
  1934 // Gets a softkey label location
       
  1935 // This can be got fot fullscreen canvas only
       
  1936 // ---------------------------------------------------------------------------
       
  1937 //
       
  1938 TBool CMIDDisplayable::SoftKeyLabelLocation(TInt aSoftKeyId, TPoint& aPosition, TSize& aSize)
       
  1939 {
       
  1940     if ((iContent->Type() == ECanvas && iIsFullScreenMode) &&
       
  1941             (aSoftKeyId > 0) &&
       
  1942             (aSoftKeyId <= KSoftKeyLabelPropertyNumberOfSoftKeys))
       
  1943     {
       
  1944         // Refresh the properties cache
       
  1945         // (can be trapped - checked by iFullscreenCanvasLabelCacheIsValid)
       
  1946         TRAPD(result, RenewFullscreenCanvasLabelCacheL());
       
  1947         if (result != KErrNone)
       
  1948         {
       
  1949             DEBUG_INT("CMIDDisplayable::SoftKeyLabelLocation - Exception from CMIDDisplayable::RenewFullscreenCanvasLabelCacheL. Error = %d", result);
       
  1950         }
       
  1951         else
       
  1952         {
       
  1953             TInt skIndex = aSoftKeyId - 1;
       
  1954             if (iFullscreenCanvasLabelCacheIsValid &&
       
  1955                     iFullscreenCanvasLabelCache[ skIndex ].iIsOn)
       
  1956             {
       
  1957 
       
  1958                 aPosition = iFullscreenCanvasLabelCache[ skIndex ].iPosition;
       
  1959                 aSize = iFullscreenCanvasLabelCache[ skIndex ].iSize;
       
  1960                 return ETrue;
       
  1961             }
       
  1962         }
       
  1963     }
       
  1964     return EFalse;
       
  1965 }
       
  1966 
       
  1967 // ---------------------------------------------------------------------------
       
  1968 // Force sync draw.
       
  1969 // ---------------------------------------------------------------------------
       
  1970 //
       
  1971 void CMIDDisplayable::DrawNow()
       
  1972 {
       
  1973     CEikBorderedControl::DrawNow();
       
  1974     if (iCba)
       
  1975         iCba->DrawNow();
       
  1976     iAppUi->StatusPane()->DrawNow();
       
  1977 }
       
  1978 
       
  1979 // ---------------------------------------------------------------------------
       
  1980 // Gets a softkey label anchor
       
  1981 // This can be got fot fullscreen canvas only
       
  1982 // ---------------------------------------------------------------------------
       
  1983 //
       
  1984 TInt CMIDDisplayable::SoftKeyLabelAnchor(TInt aSoftKeyId)
       
  1985 {
       
  1986     if ((iContent->Type() == ECanvas && iIsFullScreenMode) &&
       
  1987             (aSoftKeyId > 0) &&
       
  1988             (aSoftKeyId <= KSoftKeyLabelPropertyNumberOfSoftKeys))
       
  1989     {
       
  1990         // Refresh the properties cache
       
  1991         // (can be trapped - checked by iFullscreenCanvasLabelCacheIsValid)
       
  1992         TRAPD(result, RenewFullscreenCanvasLabelCacheL());
       
  1993         if (result != KErrNone)
       
  1994         {
       
  1995             DEBUG_INT("CMIDDisplayable::SoftKeyLabelAnchor - Exception from CMIDDisplayable::RenewFullscreenCanvasLabelCacheL. Error = %d", result);
       
  1996         }
       
  1997         else
       
  1998         {
       
  1999             TInt skIndex = aSoftKeyId - 1;
       
  2000             if (iFullscreenCanvasLabelCacheIsValid &&
       
  2001                     iFullscreenCanvasLabelCache[ skIndex ].iIsOn)
       
  2002             {
       
  2003                 return iFullscreenCanvasLabelCache[ skIndex ].iAnchor;
       
  2004             }
       
  2005         }
       
  2006     }
       
  2007     return 0;
       
  2008 }
       
  2009 
       
  2010 void CMIDDisplayable::SetS60SelectionKeyCompatibility(TBool aS60SelectionKeyCompatibility)
       
  2011 {
       
  2012     iS60SelectionKeyCompatibility = aS60SelectionKeyCompatibility;
       
  2013 }
       
  2014 
       
  2015 // ---------------------------------------------------------------------------
       
  2016 //
       
  2017 // ---------------------------------------------------------------------------
       
  2018 //
       
  2019 CMIDUIManager* CMIDDisplayable::GetUIManager() const
       
  2020 {
       
  2021     return iUIManager;
       
  2022 }
       
  2023 
       
  2024 // ---------------------------------------------------------------------------
       
  2025 //
       
  2026 // ---------------------------------------------------------------------------
       
  2027 //
       
  2028 void CMIDDisplayable::UpdateDisplayableRect()
       
  2029 {
       
  2030     DEBUG("+ CMIDDisplayable::UpdateDisplayableRect");
       
  2031 
       
  2032 #ifdef RD_SCALABLE_UI_V2
       
  2033     TRect canvasRect;
       
  2034     if (iContent)
       
  2035     {
       
  2036         if (iUseOnScreenKeypad)
       
  2037         {
       
  2038             MMIDComponent::TType type = iContent->Type();
       
  2039             if (type == ECanvas || type == EGameCanvas)
       
  2040             {
       
  2041                 canvasRect = GetCanvasRectFromLaf();
       
  2042             }
       
  2043         }
       
  2044     }
       
  2045 #endif //RD_SCALABLE_UI_V2
       
  2046     if (iIsFullScreenMode)
       
  2047     {
       
  2048         iDisplayableRect = iAppUi->ApplicationRect();
       
  2049 
       
  2050         // Update Cba because of softkey location properties
       
  2051         // (see RenewFullscreenCanvasLabelCacheL())
       
  2052         if (iCba && iActive)
       
  2053         {
       
  2054             // enable cba so that the layout is performed correctly
       
  2055             iCba->MakeVisible(ETrue);
       
  2056             iCba->SetBoundingRect(iDisplayableRect);
       
  2057             // iCba is always invisible in fullscreen
       
  2058             iCba->MakeVisible(EFalse);
       
  2059         }
       
  2060 
       
  2061 #ifdef RD_SCALABLE_UI_V2
       
  2062         if (iUseOnScreenKeypad && (canvasRect != TRect(0,0,0,0)))
       
  2063         {
       
  2064             iDisplayableRect = canvasRect;
       
  2065         }
       
  2066 #endif //RD_SCALABLE_UI_V2
       
  2067     }
       
  2068     else
       
  2069     {
       
  2070         // In case we are changing from FullScreen mode to Normal mode
       
  2071         // the status pane has to be enabled before quering client area rect.
       
  2072         CEikStatusPane* pane = iAppUi->StatusPane();
       
  2073         // Store pane visibility
       
  2074         TBool paneVisible = pane->IsVisible();
       
  2075         pane->MakeVisible(ETrue);
       
  2076 
       
  2077         iDisplayableRect = iAppUi->ClientRect();
       
  2078 
       
  2079 #ifdef RD_SCALABLE_UI_V2
       
  2080         if (iUseOnScreenKeypad && (canvasRect != TRect(0,0,0,0)))
       
  2081         {
       
  2082             iDisplayableRect = canvasRect;
       
  2083         }
       
  2084 #endif //RD_SCALABLE_UI_V2
       
  2085         if (!iActive)
       
  2086         {
       
  2087             // Restore pane visibility. There is one pane for all displayables.
       
  2088             // Only active displayable can decide about the pane visibility.
       
  2089             // Others should not change it.
       
  2090             pane->MakeVisible(paneVisible);
       
  2091         }
       
  2092 
       
  2093         if (iCba)
       
  2094         {
       
  2095             // Store cba visibility
       
  2096             TBool cbaVisible = iCba->IsVisible();
       
  2097 
       
  2098             // enable cba so that the layout is performed correctly
       
  2099             iCba->MakeVisible(ETrue);
       
  2100 
       
  2101             iCba->SetBoundingRect(iDisplayableRect);
       
  2102             // Control pane area has to be reduced
       
  2103             iCba->ReduceRect(iDisplayableRect);
       
  2104 
       
  2105             if (!iActive)
       
  2106             {
       
  2107                 // Restore cba visibility. There is one cba for all displayables.
       
  2108                 // Only active displayable can decide about the cba visibility.
       
  2109                 // Others should not change it.
       
  2110                 iCba->MakeVisible(cbaVisible);
       
  2111             }
       
  2112         }
       
  2113     }
       
  2114 
       
  2115     DEBUG("- CMIDDisplayable::UpdateDisplayableRect");
       
  2116 }
       
  2117 
       
  2118 // ---------------------------------------------------------------------------
       
  2119 // When we are full screen (currently only Canvas supports this) we need to
       
  2120 // get rid of status pane and CBAs. We do this by calling SetRect() to the full
       
  2121 // screen rect. We also set a flag in canvas, which determines its behaviour.
       
  2122 // See CMIDCanvas::FullScreen(). We store the full screen status in iIsFullScreenMode.
       
  2123 // Note that this method is called by java side.
       
  2124 // ---------------------------------------------------------------------------
       
  2125 void CMIDDisplayable::SetFullScreenModeL(TBool aFullScreen)
       
  2126 {
       
  2127     DEBUG("+ CMIDDisplayable::SetFullScreenModeL");
       
  2128 
       
  2129     iIsFullScreenMode = aFullScreen;
       
  2130 
       
  2131     if (iContent->Type() == MMIDComponent::ECanvas)
       
  2132     {
       
  2133         static_cast<CMIDCanvas*>(iContent)->FullScreen(iIsFullScreenMode);
       
  2134     }
       
  2135     if (iCanvasKeypad)
       
  2136     {
       
  2137         UpdateOnScreenKeypadSettings();
       
  2138     }
       
  2139 
       
  2140     // Displayable rect is updated and set
       
  2141     UpdateDisplayableRect();
       
  2142     SetRect(iDisplayableRect);
       
  2143 
       
  2144     if (iActive)
       
  2145     {
       
  2146         //this means we are the active displayable
       
  2147         UpdateVisualAppearanceL();
       
  2148     }
       
  2149 
       
  2150     if (aFullScreen)
       
  2151     {
       
  2152         iFullscreenCanvasLabelCacheIsValid = EFalse;
       
  2153     }
       
  2154 
       
  2155     DEBUG("- CMIDDisplayable::SetFullScreenModeL");
       
  2156 }
       
  2157 
       
  2158 #ifdef RD_JAVA_S60_RELEASE_9_2
       
  2159 // ---------------------------------------------------------------------------
       
  2160 // When partial screen keyboard is opened we need to
       
  2161 // get rid of status pane and resize Displayable.
       
  2162 // ---------------------------------------------------------------------------
       
  2163 void CMIDDisplayable::HandleSplitScreenKeyboard(TBool aOpened)
       
  2164 {
       
  2165     iSplitScreenKeyboard = aOpened;
       
  2166     if (aOpened)
       
  2167     {
       
  2168         iAppUi->StatusPane()->MakeVisible(EFalse);
       
  2169         TRect clientRect = iAppUi->ClientRect();
       
  2170         SetRect(clientRect);
       
  2171         if (iActive)
       
  2172         {
       
  2173             DrawDeferred();
       
  2174         }
       
  2175     }
       
  2176     else
       
  2177     {
       
  2178         if (iActive)
       
  2179         {
       
  2180             UpdateOnScreenKeypadSettings();
       
  2181             UpdateDisplayableRect();
       
  2182             SetRect(iDisplayableRect);
       
  2183             // Ignoring leave
       
  2184             // The method was already called at least once
       
  2185             // and must be called here.
       
  2186             TRAP_IGNORE(UpdateVisualAppearanceL());
       
  2187         }
       
  2188     }
       
  2189 }
       
  2190 #endif // RD_JAVA_S60_RELEASE_9_2
       
  2191 
       
  2192 // ---------------------------------------------------------------------------
       
  2193 // Return true if we are in full screen mode (cavas), false otherwise.
       
  2194 // @see iIsFullScreenMode
       
  2195 // @see SetFullScreenModeL().
       
  2196 // ---------------------------------------------------------------------------
       
  2197 TBool CMIDDisplayable::IsFullScreenMode() const
       
  2198 {
       
  2199     return iIsFullScreenMode;
       
  2200 }
       
  2201 
       
  2202 // ---------------------------------------------------------------------------
       
  2203 // Sets a new command to the middle soft key (MSK). This can be used e.g. by
       
  2204 // ListBox to set the selection command to the MSK. Context sensitive menu
       
  2205 // opening command is handled automatically by displayable, there is no need
       
  2206 // to set a command for that. Setting MSK via this method, overrides
       
  2207 // automatic behavior of displayable e.g. to open context menu. To unset the
       
  2208 // MSK command, set it to NULL, then the automatic behavior is effective again.
       
  2209 // ---------------------------------------------------------------------------
       
  2210 void CMIDDisplayable::SetMSKCommand(CMIDCommand* aMSKCommand)
       
  2211 {
       
  2212     CMIDCommand* oldMSKCommand = iMSKCommand;
       
  2213     iMSKCommand = aMSKCommand;
       
  2214     if (oldMSKCommand != iMSKCommand)
       
  2215     {
       
  2216         // avoid unnecessary updating to avoid flickering
       
  2217         TRAP_IGNORE(InitializeCbasL());
       
  2218     }
       
  2219 }
       
  2220 
       
  2221 void CMIDDisplayable::SetSelectCommand(CMIDCommand* aSelectCommand)
       
  2222 {
       
  2223     if (aSelectCommand != iSelectCommand)
       
  2224     {
       
  2225         // avoid unnecessary updating to avoid flickering
       
  2226         iSelectCommand = aSelectCommand;
       
  2227         TRAP_IGNORE(InitializeCbasL());
       
  2228     }
       
  2229 }
       
  2230 
       
  2231 void CMIDDisplayable::SetSelectCommandState(TBool aEnableSelectCommand)
       
  2232 {
       
  2233     iSelectCommandEnabled = aEnableSelectCommand;
       
  2234 }
       
  2235 
       
  2236 // ---------------------------------------------------------------------------
       
  2237 // Sets the list of form item commands associated with this Displayable on a
       
  2238 // given moment. Calling this will cause the CBA to be updated accordingly and
       
  2239 // usually it is called when focus has moved to a new Item.
       
  2240 //
       
  2241 // If the MSK command is not NULL, it will be presented in the middle soft key
       
  2242 // (MSK). Setting the MSK command here is basically equivalent to setting it with
       
  2243 // SetMSKCommand. The parameter is added here to remind the programmer and to
       
  2244 // gain a small performance benefit of not updating the CBA twice.
       
  2245 // ---------------------------------------------------------------------------
       
  2246 void CMIDDisplayable::SetItemCommandList(CMIDCommandList* aList, CMIDCommand* aMSKCommand)
       
  2247 {
       
  2248     iItemCommandList = aList;
       
  2249     if (iItemCommandList)
       
  2250     {
       
  2251         iItemCommandList->SetCommandOffset(KItemCommandIdBase);
       
  2252     }
       
  2253     CMIDCommand* oldMSKCommand = iMSKCommand;
       
  2254     iMSKCommand = aMSKCommand;
       
  2255 
       
  2256     TInt newCount = iItemCommandList ? iItemCommandList->Count() : 0;
       
  2257 
       
  2258     // To avoid flicker don't update the CBA if the old and the new command list
       
  2259     // both have 0 items (very likely).
       
  2260     if (!(iItemCommandsCount==0 && newCount==0) ||
       
  2261             oldMSKCommand != iMSKCommand
       
  2262             || iS60SelectionKeyCompatibility
       
  2263        )
       
  2264     {
       
  2265         TRAP_IGNORE(InitializeCbasL());
       
  2266     }
       
  2267 
       
  2268     // set current items commands count
       
  2269     iItemCommandsCount = newCount;
       
  2270 }
       
  2271 
       
  2272 // ---------------------------------------------------------------------------
       
  2273 // Called to show the MIDlet title in the Status Pane.
       
  2274 // ---------------------------------------------------------------------------
       
  2275 void CMIDDisplayable::ShowTitleL()
       
  2276 {
       
  2277     CEikStatusPane* pane = iAppUi->StatusPane();
       
  2278     CAknTitlePane* titlePane = (CAknTitlePane*)pane->ControlL(TUid::Uid(EEikStatusPaneUidTitle));
       
  2279 
       
  2280 
       
  2281     if ((iContent && iContent->Type() == ETextBox) && iIsPopupTextBox)
       
  2282     {
       
  2283         // No need to update status pane for pop-up TextBox, because it is not using it.
       
  2284     }
       
  2285     else if ((iContent && iContent->Type() == EAlert) || !(this->iTitle) ||
       
  2286              (this->iTitle->Length() < 1))
       
  2287     {
       
  2288         const TDesC& titleText = iEnv.MidletName();
       
  2289         titlePane->SetTextL(titleText);
       
  2290     }
       
  2291     else
       
  2292     {
       
  2293         titlePane->SetTextL(*iTitle);
       
  2294     }
       
  2295 }
       
  2296 // ---------------------------------------------------------------------------
       
  2297 // Get Tilte to
       
  2298 // ---------------------------------------------------------------------------
       
  2299 HBufC* CMIDDisplayable::Title()
       
  2300 {
       
  2301     return iTitle;
       
  2302 }
       
  2303 
       
  2304 // ---------------------------------------------------------------------------
       
  2305 // First map the first eligible command to every sk. Then for the
       
  2306 // sk that accepts the options menu, change the mapped command to
       
  2307 // the options menu if there are still commands that have not been
       
  2308 // mapped. ASSUMPTION 1: Only one sk accepts a menu and this menu is
       
  2309 // always the options menu. ASSUMPTION 2: sks are ordered so that
       
  2310 // sks that are more restrictive in the type of commands they accept
       
  2311 // come before less restrictive sks, eg the right sk comes before the
       
  2312 // left sk.
       
  2313 // Some components, for example, List, do not want MSK set if list is empty,
       
  2314 // decision is done based on enableDefaultMSK parameter value
       
  2315 //
       
  2316 // Finally draw the CBA.
       
  2317 // ---------------------------------------------------------------------------
       
  2318 void CMIDDisplayable::InitializeCbasL()
       
  2319 {
       
  2320     if (!iActive)
       
  2321     {
       
  2322         return;
       
  2323     }
       
  2324 
       
  2325     iCba->SetCommandSetL(R_AVKON_SOFTKEYS_EMPTY);
       
  2326 
       
  2327     // Initialize command lists
       
  2328     RArray<CMIDCommandList*> lists;
       
  2329     CleanupClosePushL(lists);
       
  2330     User::LeaveIfError(lists.Append(iCommandList));
       
  2331     User::LeaveIfError(lists.Append(iItemCommandList));
       
  2332 
       
  2333 #ifdef RD_JAVA_S60_RELEASE_9_2
       
  2334     if (iSelectCommand)
       
  2335 #else
       
  2336     if (!iSelectCommandEnabled && iSelectCommand)
       
  2337 #endif // RD_JAVA_S60_RELEASE_9_2
       
  2338     {
       
  2339         // remove the select command
       
  2340         for (TInt j = 0; j < lists.Count(); j++)
       
  2341         {
       
  2342             if (lists[j])
       
  2343             {
       
  2344                 CMIDCommandList* itemCommandList = lists[j];
       
  2345                 if (itemCommandList)
       
  2346                 {
       
  2347                     TInt index = itemCommandList->FindCommandIndex(iSelectCommand);
       
  2348                     if (index != KErrNotFound)
       
  2349                     {
       
  2350                         itemCommandList->Remove(iSelectCommand);
       
  2351                     }
       
  2352                 }
       
  2353             }
       
  2354         }
       
  2355     }
       
  2356 
       
  2357     TInt numLists = lists.Count();
       
  2358     TInt numSoftKeys = iSoftKeys.Count();
       
  2359     ResetSoftKeysAndCommands(lists);
       
  2360 
       
  2361     // Variable implicitList is used when mapping commands to soft keys
       
  2362     // In case of IMPLICIT List with only OK or ITEM commands,
       
  2363     // no command is mapped to soft key and these commands are not
       
  2364     // populated to Options menu
       
  2365     TBool implicitList = EFalse;
       
  2366 #ifdef RD_JAVA_S60_RELEASE_9_2
       
  2367     if (iContent && iContent->Type() == EList && iContentControl)
       
  2368     {
       
  2369         CMIDList* list = static_cast<CMIDList*>(iContentControl);
       
  2370         // Important: Set to ETrue only if List is IMPLICIT and there is no highlight
       
  2371         implicitList = (list->ListChoiceType() == MMIDChoiceGroup::EImplicit) &&
       
  2372                        !list->IsHighlighted();
       
  2373     }
       
  2374 #endif // RD_JAVA_S60_RELEASE_9_2
       
  2375 
       
  2376     // First map one command to every softkey if possible,
       
  2377     // sks must have been ordered correctly, ie right key before
       
  2378     // left key or else left key might get BACK cmd if not other
       
  2379     // cmds are available.
       
  2380     for (TInt i = 0; i < numSoftKeys; i++)
       
  2381     {
       
  2382         for (TInt j = 0; j < numLists && !iSoftKeys[i]->HasAMappedCommand(); j++)
       
  2383         {
       
  2384             if (lists[j])
       
  2385             {
       
  2386                 TInt index = lists[j]->FindCommandForSoftKey(*iSoftKeys[i], implicitList);
       
  2387                 if (index != KErrNotFound)
       
  2388                 {
       
  2389                     TInt commandId = lists[j]->CommandOffset() + index;
       
  2390                     CMIDCommand* cmd = lists[j]->At(index).iCommand;
       
  2391                     iSoftKeys[i]->Map(cmd);
       
  2392                     iCba->SetCommandL(iSoftKeys[i]->PositionInCBA(),
       
  2393                                       commandId,
       
  2394                                       lists[j]->ShortLabel(index));
       
  2395                 }
       
  2396             }
       
  2397         }
       
  2398     }
       
  2399 
       
  2400     // Then for the sk that can potentially accept an options menu,
       
  2401     // see if the mapped command must be replaced by the options menu
       
  2402     // when there is at least one command that has not been mapped to any sk.
       
  2403     // Important: Do not set Options menu in case of IMPLICIT List
       
  2404     // with only OK or ITEM commands
       
  2405     TBool needToDisplayMenu = EFalse;
       
  2406     for (TInt j = 0; j < numLists && !needToDisplayMenu; j++)
       
  2407     {
       
  2408         if (lists[j])
       
  2409         {
       
  2410             // Looping trough all commands
       
  2411             for (TInt i = 0; i < lists[j]->Count() && !needToDisplayMenu; i++)
       
  2412             {
       
  2413                 CMIDCommand* cmd = lists[j]->At(i).iCommand;
       
  2414                 // In case that displayable is IMPLICIT List, we need to know,
       
  2415                 // if it has only OK or ITEM commands
       
  2416                 if (!(implicitList && (cmd->CommandType() == MMIDCommand::EOk ||
       
  2417                                        cmd->CommandType() == MMIDCommand::EItem)))
       
  2418                 {
       
  2419                     // There is at least one command, which is not mapped yet,
       
  2420                     // so it will be populated to Options menu.
       
  2421                     needToDisplayMenu = !CommandIsMappedToSk(cmd);
       
  2422                 }
       
  2423             }
       
  2424         }
       
  2425     }
       
  2426     if (needToDisplayMenu)
       
  2427     {
       
  2428         iSoftKeys[KOptionsMenuCBAIndex]->MappedCommand()->SetMappedToSoftKey(EFalse);
       
  2429         iSoftKeys[KOptionsMenuCBAIndex]->Map(NULL);
       
  2430         iCba->SetCommandL(iSoftKeys[KOptionsMenuCBAIndex]->PositionInCBA(),R_MIDP_SOFTKEY_OPTIONS);
       
  2431     }
       
  2432 
       
  2433     // Setup the MSK command
       
  2434     TInt contextMenuSize = NumCommandsForOkOptionsMenu();
       
  2435     // first reset stored id of command mapped to MSK
       
  2436     iIdOfMSKCommand = KErrNotFound;
       
  2437     if (!iS60SelectionKeyCompatibility)
       
  2438     {
       
  2439         if (iMSKCommand)
       
  2440         {
       
  2441             // There is a explicitly set MSK command -> it takes the precedence and gets MSK
       
  2442             TInt commandId = GetInternalCommandIdFor(iMSKCommand);
       
  2443             if (commandId == KCommandIdNotFound)
       
  2444             {
       
  2445                 // it must be a built-in command, it is the only command not contained in the command lists
       
  2446                 commandId = KBuiltInMSKCommandId;
       
  2447             }
       
  2448             iCba->SetCommandL(KMSKPositionInCBA, commandId, iMSKCommand->ShortLabel());
       
  2449             iIdOfMSKCommand = commandId;
       
  2450         }
       
  2451         else if (!iMSKCommand && (contextMenuSize == 1))
       
  2452         {
       
  2453             // There is no explicitly set MSK command and just one for the context menu.
       
  2454             // Instead of a menu, put the command to MSK directly.
       
  2455             RPointerArray<CMIDCommand> commands;
       
  2456             GetOkOptionsMenuCommandsL(commands);
       
  2457             ASSERT(commands.Count() == 1);
       
  2458             CMIDCommand* command = commands[0];
       
  2459             commands.Close();
       
  2460             iCba->SetCommandL(KMSKPositionInCBA,
       
  2461                               GetInternalCommandIdFor(command),
       
  2462                               command->ShortLabel());
       
  2463             iIdOfMSKCommand = GetInternalCommandIdFor(command);
       
  2464         }
       
  2465         else if (!iMSKCommand && (contextMenuSize > 1))
       
  2466         {
       
  2467             // There is no explicitly set MSK command, but there is a
       
  2468             // context sensitive menu -> display MSK command & icon for opening the menu
       
  2469             _LIT(KEmptyLabel, ""); // the label is never shown in MSK, but an icon is
       
  2470             iCba->SetCommandL(KMSKPositionInCBA, EAknSoftkeyContextOptions, KEmptyLabel);
       
  2471             iIdOfMSKCommand = EAknSoftkeyContextOptions;
       
  2472         }
       
  2473         else if (!iMSKCommand && (contextMenuSize == 0))
       
  2474         {
       
  2475             // There is no explicitly set MSK command and no OK or ITEM command defined
       
  2476             // Try to map SCREEN or HELP command with the highest priority
       
  2477             TInt screenOrHelpCmdIndex = GetHighestPriorityScreenOrHelpCommand();
       
  2478             if (screenOrHelpCmdIndex != KErrNotFound)
       
  2479             {
       
  2480                 CMIDCommand *command = iCommandList->At(screenOrHelpCmdIndex).iCommand;
       
  2481                 if (command)
       
  2482                 {
       
  2483                     // At least one SCREEN or HELP command is set, map to MSK
       
  2484                     iCba->SetCommandL(KMSKPositionInCBA,
       
  2485                                       GetInternalCommandIdFor(command),
       
  2486                                       command->ShortLabel());
       
  2487                     iIdOfMSKCommand = GetInternalCommandIdFor(command);
       
  2488                 }
       
  2489             }
       
  2490         }
       
  2491     }
       
  2492 
       
  2493     CleanupStack::PopAndDestroy(&lists);
       
  2494     iCba->DrawDeferred();
       
  2495 }
       
  2496 
       
  2497 // ---------------------------------------------------------------------------
       
  2498 // Returns an internal command id for a command. Assumes that
       
  2499 // command is not NULL.
       
  2500 // ---------------------------------------------------------------------------
       
  2501 TInt CMIDDisplayable::GetInternalCommandIdFor(CMIDCommand* aCommand) const
       
  2502 {
       
  2503     ASSERT(aCommand);
       
  2504     // See if command is part on command list, if the list exists
       
  2505     if (iCommandList)
       
  2506     {
       
  2507         // To identify the command, first find it from the list, this is based on
       
  2508         // command ids. However, commands in iCommandList and iItemCommandList may
       
  2509         // have same ids (because of Java side implementation) and thus we compare
       
  2510         // the pointer of the command in the second phase.
       
  2511         TInt index = iCommandList->FindCommandIndex(aCommand);
       
  2512         if (index != KErrNotFound && iCommandList->At(index).iCommand == aCommand)
       
  2513         {
       
  2514             return iCommandList->CommandOffset() + index;
       
  2515         }
       
  2516     }
       
  2517     // See if command is part of item command list, if the list exists
       
  2518     if (iItemCommandList)
       
  2519     {
       
  2520         // To identify the command, first find it from the list, this is based on
       
  2521         // command ids. However, commands in iCommandList and iItemCommandList may
       
  2522         // have same ids (because of Java side implementation) and thus we compare
       
  2523         // the pointer of the command in the second phase.
       
  2524         TInt index = iItemCommandList->FindCommandIndex(aCommand);
       
  2525         if (index != KErrNotFound && iItemCommandList->At(index).iCommand == aCommand)
       
  2526         {
       
  2527             return iItemCommandList->CommandOffset() + index;
       
  2528         }
       
  2529     }
       
  2530     // Did not find the requested command
       
  2531     return KCommandIdNotFound;
       
  2532 }
       
  2533 
       
  2534 // ---------------------------------------------------------------------------
       
  2535 // Return true if the command is mapped to any softkey. The same java side command seem
       
  2536 // to exist on more than one list so we use the command Id to make sure the command is not
       
  2537 // a repeatition of an existing command.
       
  2538 // ---------------------------------------------------------------------------
       
  2539 TBool CMIDDisplayable::CommandIsMappedToSk(const CMIDCommand* aCommand) const
       
  2540 {
       
  2541     DEBUG("+ CMIDDisplayable::CommandIsMappedToSk");
       
  2542 
       
  2543     TBool commandIsMapped = aCommand->IsMappedToSoftKey();
       
  2544     for (TInt k = 0; k < iSoftKeys.Count() && !commandIsMapped; k++)
       
  2545     {
       
  2546         const CMIDCommand* skCmd = iSoftKeys[k]->MappedCommand();
       
  2547         if (skCmd && skCmd == aCommand && skCmd->Id() == aCommand->Id())
       
  2548         {
       
  2549             commandIsMapped = ETrue;
       
  2550         }
       
  2551     }
       
  2552 
       
  2553     DEBUG("- CMIDDisplayable::CommandIsMappedToSk");
       
  2554     return commandIsMapped;
       
  2555 }
       
  2556 
       
  2557 // ---------------------------------------------------------------------------
       
  2558 // See how many commands eligible for the ok-optins menu we have. If we
       
  2559 // have only one command then post java event directly. Otherwise show
       
  2560 // ok-options menu. In these two cases return ETrue. If zero or negative
       
  2561 // commands do nothing and return EFalse. See also NumCommandsForOkOptionsMenu()
       
  2562 // and CMIDMenuHandler::ShowMenuL().
       
  2563 // ---------------------------------------------------------------------------
       
  2564 TBool CMIDDisplayable::ShowOkOptionsMenuL()
       
  2565 {
       
  2566     TInt numCommands = NumCommandsForOkOptionsMenu();
       
  2567 
       
  2568     if (numCommands == 1)
       
  2569     {
       
  2570         TCommandEntry cmd;
       
  2571         cmd.iCommand = NULL;
       
  2572 
       
  2573         if (iItemCommandList && iItemCommandList->Count() > 0)
       
  2574         {
       
  2575             // there can only be one so pick the first one
       
  2576             cmd = iItemCommandList->At(0);
       
  2577 
       
  2578             if (cmd.iCommand->IsMappedToSoftKey())
       
  2579             {
       
  2580                 HandleItemCommandL(cmd);
       
  2581                 return ETrue;
       
  2582             }
       
  2583         }
       
  2584         else if (iCommandList && iCommandList->Count() > 0)
       
  2585         {
       
  2586             TInt index = iCommandList->HighestPriorityCommand(MMIDCommand::EOk);
       
  2587             if (index == KErrNotFound)
       
  2588             {
       
  2589                 // there can only be one so if the other one was KErrNotFound, this must be it
       
  2590                 index = iCommandList->HighestPriorityCommand(MMIDCommand::EItem);
       
  2591             }
       
  2592             cmd = iCommandList->At(index);
       
  2593 
       
  2594             if (cmd.iCommand->IsMappedToSoftKey())
       
  2595             {
       
  2596                 HandleStandardCommandL(cmd);
       
  2597                 return ETrue;
       
  2598             }
       
  2599         }
       
  2600     }
       
  2601 
       
  2602     if (numCommands > 0)
       
  2603     {
       
  2604         iMenuHandler->ShowMenuL(CMIDMenuHandler::EOkMenu);
       
  2605         return ETrue;
       
  2606     }
       
  2607 
       
  2608     return EFalse;
       
  2609 }
       
  2610 
       
  2611 // ---------------------------------------------------------------------------
       
  2612 // See how many commands eligible for the screen or help - optins menu we have.
       
  2613 // If we have only one command call ProcessCommandL. Otherwise show
       
  2614 // options menu. In these two cases return ETrue. If zero or negative
       
  2615 // commands do nothing and return EFalse.
       
  2616 // ---------------------------------------------------------------------------
       
  2617 TBool CMIDDisplayable::ShowScreenOrHelpOptionsMenuL()
       
  2618 {
       
  2619     TBool ret = EFalse;
       
  2620     TInt numOkCommands = NumCommandsForOkOptionsMenu();
       
  2621     TInt numScreenOrHelpCommands = NumCommandsForScreenOrHelpOptionsMenu();
       
  2622     TInt screenOrHelpCmdIndex = GetHighestPriorityScreenOrHelpCommand();
       
  2623 
       
  2624     // There is no OK or ITEM command defined on form
       
  2625     // There are SCREEN or HELP commands
       
  2626     if (iCommandList && screenOrHelpCmdIndex != KErrNotFound && numOkCommands == 0)
       
  2627     {
       
  2628         CMIDCommand *command = NULL;
       
  2629         if (iCommandList->IsValidIndex(screenOrHelpCmdIndex))
       
  2630         {
       
  2631             command = iCommandList->At(screenOrHelpCmdIndex).iCommand;
       
  2632         }
       
  2633 
       
  2634         if (command && (command->CommandType() == MMIDCommand::EScreen ||
       
  2635                         command->CommandType() == MMIDCommand::EHelp) && iMenuHandler)
       
  2636         {
       
  2637             if (numScreenOrHelpCommands > 1)
       
  2638             {
       
  2639                 iMenuHandler->ShowMenuL(CMIDMenuHandler::EOptionsMenu);
       
  2640                 ret = ETrue;
       
  2641             }
       
  2642             else if (numScreenOrHelpCommands == 1)
       
  2643             {
       
  2644                 ProcessCommandL(iCommandList->CommandOffset());
       
  2645                 ret = ETrue;
       
  2646             }
       
  2647         }
       
  2648     }
       
  2649 
       
  2650     return ret;
       
  2651 }
       
  2652 
       
  2653 // ---------------------------------------------------------------------------
       
  2654 // Return the number of commands that can be displayed in the ok-options menu.
       
  2655 // If form has set any item commands in iItemCommandList this means that there is
       
  2656 // a form item focused and the commands for this item should be displayed in
       
  2657 // the ok-options menu along with form OK and ITEM commands.
       
  2658 //
       
  2659 // If we have no item cmds we analyse the standard command list and
       
  2660 // select only the commands of type OK or ITEM.
       
  2661 //
       
  2662 // TextBox/TextField device-provided commands:
       
  2663 // - "Fetch number"
       
  2664 // - "Call"
       
  2665 // - "Fetch e-mail address"
       
  2666 // are exception. Those are visible ONLY in Options menu so here they are
       
  2667 // removed from context menu commands count.
       
  2668 // ---------------------------------------------------------------------------
       
  2669 TInt CMIDDisplayable::NumCommandsForOkOptionsMenu() const
       
  2670 {
       
  2671     TInt ret = 0;
       
  2672 
       
  2673     if (iItemCommandList && iItemCommandList->Count() > 0)
       
  2674     {
       
  2675         TInt numItemCommands = iItemCommandList->Count();
       
  2676         for (TInt i = 0; i < numItemCommands; i++)
       
  2677         {
       
  2678             const CMIDCommand& command = *(iItemCommandList->At(i).iCommand);
       
  2679 
       
  2680             if ((command.Id() != CMIDEdwinUtils::EMenuCommandFetchPhoneNumber) &&
       
  2681                     (command.Id() != CMIDEdwinUtils::EMenuCommandFetchEmailAddress) &&
       
  2682                     (command.Id() != CMIDEdwinUtils::EMenuCommandCreatePhoneCall))
       
  2683             {
       
  2684                 ret++;
       
  2685             }
       
  2686         }
       
  2687     }
       
  2688 
       
  2689     // Add always OK and ITEM commands from form
       
  2690     TInt numCommands = iCommandList->Count();
       
  2691     for (TInt i = 0; i < numCommands; i++)
       
  2692     {
       
  2693         const CMIDCommand& command = *(iCommandList->At(i).iCommand);
       
  2694 
       
  2695         if (((command.CommandType() == MMIDCommand::EOk) ||
       
  2696                 (command.CommandType() == MMIDCommand::EItem)) &&
       
  2697                 (command.Id() != CMIDEdwinUtils::EMenuCommandFetchPhoneNumber) &&
       
  2698                 (command.Id() != CMIDEdwinUtils::EMenuCommandFetchEmailAddress) &&
       
  2699                 (command.Id() != CMIDEdwinUtils::EMenuCommandCreatePhoneCall))
       
  2700         {
       
  2701             TBool selectCommand = (&command == iSelectCommand);
       
  2702             if (selectCommand && !iSelectCommandEnabled)
       
  2703             {
       
  2704                 continue;
       
  2705             }
       
  2706             ret++;
       
  2707         }
       
  2708     }
       
  2709 
       
  2710     return ret;
       
  2711 }
       
  2712 
       
  2713 // ---------------------------------------------------------------------------
       
  2714 // Return the number of commands that can be displayed in the screen or help - options menu.
       
  2715 // Form item screen or help commands are ignored
       
  2716 //
       
  2717 // TextBox/TextField device-provided commands:
       
  2718 // - "Fetch number"
       
  2719 // - "Call"
       
  2720 // - "Fetch e-mail address"
       
  2721 // are exception. Those are visible ONLY in Options menu so here they are
       
  2722 // removed from context menu commands count.
       
  2723 // ---------------------------------------------------------------------------
       
  2724 TInt CMIDDisplayable::NumCommandsForScreenOrHelpOptionsMenu() const
       
  2725 {
       
  2726     TInt ret = 0;
       
  2727 
       
  2728     // Add SCREEN and HELP commands from form
       
  2729     if (iCommandList)
       
  2730     {
       
  2731         TInt numCommands = iCommandList->Count();
       
  2732         for (TInt i = 0; i < numCommands; i++)
       
  2733         {
       
  2734             const CMIDCommand& command = *(iCommandList->At(i).iCommand);
       
  2735 
       
  2736             if (((command.CommandType() == MMIDCommand::EScreen) ||
       
  2737                     (command.CommandType() == MMIDCommand::EHelp)) &&
       
  2738                     (command.Id() != CMIDEdwinUtils::EMenuCommandFetchPhoneNumber) &&
       
  2739                     (command.Id() != CMIDEdwinUtils::EMenuCommandFetchEmailAddress) &&
       
  2740                     (command.Id() != CMIDEdwinUtils::EMenuCommandCreatePhoneCall))
       
  2741             {
       
  2742                 TBool selectCommand = (&command == iSelectCommand);
       
  2743                 if (selectCommand && !iSelectCommandEnabled)
       
  2744                 {
       
  2745                     continue;
       
  2746                 }
       
  2747                 ret++;
       
  2748             }
       
  2749         }
       
  2750     }
       
  2751     return ret;
       
  2752 }
       
  2753 
       
  2754 // ---------------------------------------------------------------------------
       
  2755 // Returns a pointer to the command in the iCommandList with the specified
       
  2756 // ID number. If such command is not found, returns NULL.
       
  2757 // ---------------------------------------------------------------------------
       
  2758 CMIDCommand* CMIDDisplayable::FindCommandWithId(TInt aCommandId) const
       
  2759 {
       
  2760     TInt numCommands = iCommandList->Count();
       
  2761     for (TInt i = 0; i < numCommands; i++)
       
  2762     {
       
  2763         CMIDCommand* command = iCommandList->At(i).iCommand;
       
  2764         if (command->Id() == aCommandId)
       
  2765             return command;
       
  2766     }
       
  2767     return NULL;
       
  2768 }
       
  2769 
       
  2770 // ---------------------------------------------------------------------------
       
  2771 // Retrieves the commands to be placed in the context (ok-options) menu.
       
  2772 // The commands are returned in the array, provided by the calling code.
       
  2773 // This function will empty the commands array before filling it.
       
  2774 //
       
  2775 // Only commands of type OK and ITEM are visible in context menu.
       
  2776 // TextBox/TextField device-provided commands:
       
  2777 // - "Fetch number"
       
  2778 // - "Call"
       
  2779 // - "Fetch e-mail address"
       
  2780 // are exception. Those are visible ONLY in Options menu so here
       
  2781 // they are not added to context menu commands array.
       
  2782 //
       
  2783 // If there are item commands, there are placed first. Form commands of ITEM
       
  2784 // and OK type are then included always.
       
  2785 // ---------------------------------------------------------------------------
       
  2786 void CMIDDisplayable::GetOkOptionsMenuCommandsL(RPointerArray<CMIDCommand>& aCommands) const
       
  2787 {
       
  2788     aCommands.Reset();
       
  2789     if (iItemCommandList && iItemCommandList->Count() > 0)
       
  2790     {
       
  2791         for (TInt i = 0; i < iItemCommandList->Count(); i++)
       
  2792         {
       
  2793             const CMIDCommand* command = iItemCommandList->At(i).iCommand;
       
  2794             if ((command->Id() != CMIDEdwinUtils::EMenuCommandFetchPhoneNumber) &&
       
  2795                     (command->Id() != CMIDEdwinUtils::EMenuCommandFetchEmailAddress) &&
       
  2796                     (command->Id() != CMIDEdwinUtils::EMenuCommandCreatePhoneCall))
       
  2797             {
       
  2798                 aCommands.AppendL(command);
       
  2799             }
       
  2800         }
       
  2801     }
       
  2802 
       
  2803     // add Form commands always
       
  2804     TInt numCommands = iCommandList->Count();
       
  2805     for (TInt i = 0; i < numCommands; i++)
       
  2806     {
       
  2807         const CMIDCommand* command = iCommandList->At(i).iCommand;
       
  2808         if (((command->CommandType() == MMIDCommand::EOk) ||
       
  2809                 (command->CommandType() == MMIDCommand::EItem)) &&
       
  2810                 (command->Id() != CMIDEdwinUtils::EMenuCommandFetchPhoneNumber) &&
       
  2811                 (command->Id() != CMIDEdwinUtils::EMenuCommandFetchEmailAddress) &&
       
  2812                 (command->Id() != CMIDEdwinUtils::EMenuCommandCreatePhoneCall))
       
  2813         {
       
  2814             if (!iSelectCommandEnabled && command == iSelectCommand)
       
  2815             {
       
  2816                 continue;
       
  2817             }
       
  2818             aCommands.AppendL(command);
       
  2819         }
       
  2820     }
       
  2821 }
       
  2822 
       
  2823 /**
       
  2824  * Retrieves index of the highest priority SCREEN command
       
  2825  * where there is no SCREEN command it retreives index
       
  2826  * of the highest priority HELP command number.
       
  2827  *
       
  2828  * When there is no such command type, it returns KErrNotFound
       
  2829  **/
       
  2830 TInt CMIDDisplayable::GetHighestPriorityScreenOrHelpCommand() const
       
  2831 {
       
  2832     TInt cmdNum = iCommandList->HighestPriorityCommand(MMIDCommand::EScreen);
       
  2833     if (cmdNum == KErrNotFound)
       
  2834         cmdNum = iCommandList->HighestPriorityCommand(MMIDCommand::EHelp);
       
  2835     return cmdNum;
       
  2836 }
       
  2837 
       
  2838 
       
  2839 // ---------------------------------------------------------------------------
       
  2840 // Removes the title, effectively showing the midlet name as the title.
       
  2841 // Used by popup-style TextBox which maintains its own title.
       
  2842 // ---------------------------------------------------------------------------
       
  2843 void CMIDDisplayable::ClearTitleL()
       
  2844 {
       
  2845     delete iTitle;
       
  2846     iTitle = NULL;
       
  2847     if (this->iActive)
       
  2848     {
       
  2849         this->ShowTitleL();
       
  2850     }
       
  2851     iHasTitle = EFalse;
       
  2852 }
       
  2853 
       
  2854 // ---------------------------------------------------------------------------
       
  2855 // Replaces the CEikButtonGroupContainer.
       
  2856 // ---------------------------------------------------------------------------
       
  2857 void CMIDDisplayable::SetCba(CEikButtonGroupContainer* aCba)
       
  2858 {
       
  2859     DEBUG("+ CMIDDisplayable::SetCba");
       
  2860 
       
  2861     ASSERT(aCba);
       
  2862     iCba = aCba;
       
  2863     iCba->DrawDeferred();
       
  2864 
       
  2865     DEBUG("- CMIDDisplayable::SetCba");
       
  2866 }
       
  2867 
       
  2868 // ---------------------------------------------------------------------------
       
  2869 // Reset the status of all sks and commands so that no command is mapped to any sk
       
  2870 // ---------------------------------------------------------------------------
       
  2871 void CMIDDisplayable::ResetSoftKeysAndCommands(const RArray<CMIDCommandList*>& aLists)
       
  2872 {
       
  2873     TInt numSoftKeys = iSoftKeys.Count();
       
  2874     for (TInt i = 0; i < numSoftKeys; i++)
       
  2875     {
       
  2876         iSoftKeys[i]->Map(NULL);
       
  2877     }
       
  2878 
       
  2879     TInt numLists = aLists.Count();
       
  2880     for (TInt j = 0; j < numLists; j++)
       
  2881     {
       
  2882         if (aLists[j])
       
  2883         {
       
  2884             aLists[j]->UnMapCommands();
       
  2885         }
       
  2886     }
       
  2887 }
       
  2888 
       
  2889 // ---------------------------------------------------------------------------
       
  2890 //
       
  2891 // ---------------------------------------------------------------------------
       
  2892 TBool CMIDDisplayable::TryDetectLongTapL(const TPointerEvent& aPointerEvent)
       
  2893 {
       
  2894     //Following code disables the cancelling of long tap to be determined as a normal tap.
       
  2895     //Cancelling of long tap (up event during long tap animation) shouldn't do anything
       
  2896     //else than cancel the animation.
       
  2897     if (iLongTapDetector->IsAnimationRunning() &&
       
  2898             aPointerEvent.iType == TPointerEvent::EButton1Up)
       
  2899     {
       
  2900         iLongTapDetector->PointerEventL(aPointerEvent);
       
  2901         return ETrue;
       
  2902     }
       
  2903     // If there is a context menu available, forward events to long tap detector
       
  2904 #ifdef RD_JAVA_S60_RELEASE_9_2
       
  2905     if (NumCommandsForOkOptionsMenu() > 0)
       
  2906 #else
       
  2907     if (NumCommandsForOkOptionsMenu() > 1)
       
  2908 #endif // RD_JAVA_S60_RELEASE_9_2
       
  2909     {
       
  2910         iLongTapDetector->PointerEventL(aPointerEvent);
       
  2911     }
       
  2912     if (aPointerEvent.iType == TPointerEvent::EButton1Up && iLongTapDetected)
       
  2913     {
       
  2914         iLongTapDetected = EFalse;
       
  2915         return ETrue;
       
  2916     }
       
  2917     else
       
  2918     {
       
  2919         return EFalse;
       
  2920     }
       
  2921 }
       
  2922 
       
  2923 // ---------------------------------------------------------------------------
       
  2924 //
       
  2925 // ---------------------------------------------------------------------------
       
  2926 void CMIDDisplayable::HandleLongTapEventL(const TPoint& /*aPenEventLocation*/,
       
  2927         const TPoint& aPenEventScreenLocation)
       
  2928 {
       
  2929     // Long tap was detected -> show context menu. However, make sure that the
       
  2930     // context sensitive menu is still there; it could be that the menu items
       
  2931     // have been changed while waiting for the long tap event
       
  2932     RArray<CEikMenuPaneItem::SData> menuItems; // the list of menu items
       
  2933     menuItems.Reset();
       
  2934 
       
  2935     if (iItemCommandList && iItemCommandList->Count() > 0)
       
  2936     {
       
  2937 #ifdef RD_JAVA_S60_RELEASE_9_2
       
  2938         PopulateMenuItemsWithListL(CMIDMenuHandler::EPopUpMenu, menuItems, iItemCommandList, EFalse);
       
  2939 #else
       
  2940         PopulateMenuItemsWithListL(CMIDMenuHandler::EOkMenu, menuItems, iItemCommandList, EFalse);
       
  2941 #endif // RD_JAVA_S60_RELEASE_9_2
       
  2942     }
       
  2943 
       
  2944     // Add form commands always
       
  2945 #ifdef RD_JAVA_S60_RELEASE_9_2
       
  2946     PopulateMenuItemsWithListL(CMIDMenuHandler::EPopUpMenu, menuItems, iCommandList, EFalse);
       
  2947 #else
       
  2948     PopulateMenuItemsWithListL(CMIDMenuHandler::EOkMenu, menuItems, iCommandList, EFalse);
       
  2949 #endif // RD_JAVA_S60_RELEASE_9_2
       
  2950 #ifdef RD_JAVA_S60_RELEASE_9_2
       
  2951     if (menuItems.Count() > 0)
       
  2952 #else
       
  2953     if (menuItems.Count() > 1)
       
  2954 #endif // RD_JAVA_S60_RELEASE_9_2
       
  2955     {
       
  2956         // recreate stylus popup menu because it does not have method
       
  2957         // for clearing the menu items
       
  2958         delete iStylusPopupMenu;
       
  2959         iStylusPopupMenu = NULL;
       
  2960         iStylusPopupMenu = CAknStylusPopUpMenu::NewL(this, aPenEventScreenLocation);
       
  2961         for (TInt i = 0; i < menuItems.Count(); i++)
       
  2962         {
       
  2963             iStylusPopupMenu->AddMenuItemL(menuItems[i].iText, menuItems[i].iCommandId);
       
  2964         }
       
  2965 
       
  2966         iStylusPopupMenu->SetPosition(aPenEventScreenLocation);
       
  2967         iStylusPopupMenu->ShowMenu();
       
  2968     }
       
  2969 
       
  2970     iLongTapDetected = ETrue;
       
  2971 }
       
  2972 
       
  2973 // ---------------------------------------------------------------------------
       
  2974 //
       
  2975 // ---------------------------------------------------------------------------
       
  2976 MAknsControlContext* CMIDDisplayable::BackGroundControlContext()
       
  2977 {
       
  2978     return iBackGroundControlContext;
       
  2979 }
       
  2980 
       
  2981 // ---------------------------------------------------------------------------
       
  2982 //
       
  2983 // ---------------------------------------------------------------------------
       
  2984 CMIDCommandList* CMIDDisplayable::MainCommandList() const
       
  2985 {
       
  2986     return iCommandList;
       
  2987 }
       
  2988 
       
  2989 // ---------------------------------------------------------------------------
       
  2990 //
       
  2991 // ---------------------------------------------------------------------------
       
  2992 MMIDComponent* CMIDDisplayable::Component() const
       
  2993 {
       
  2994     return iContent;
       
  2995 }
       
  2996 
       
  2997 // ---------------------------------------------------------------------------
       
  2998 //
       
  2999 // ---------------------------------------------------------------------------
       
  3000 TInt CMIDDisplayable::CommandCount()
       
  3001 {
       
  3002     return iCommandList->Count();
       
  3003 }
       
  3004 
       
  3005 // ---------------------------------------------------------------------------
       
  3006 // Returns a boolean indicating whether a non-null title has been set by
       
  3007 // calling the Displayable's SetTitle method.
       
  3008 // ---------------------------------------------------------------------------
       
  3009 TBool CMIDDisplayable::HasTitle() const
       
  3010 {
       
  3011     return iHasTitle;
       
  3012 }
       
  3013 
       
  3014 // ---------------------------------------------------------------------------
       
  3015 //
       
  3016 // ---------------------------------------------------------------------------
       
  3017 CMIDMenuHandler* CMIDDisplayable::MenuHandler() const
       
  3018 {
       
  3019     return iMenuHandler;
       
  3020 }
       
  3021 
       
  3022 // ---------------------------------------------------------------------------
       
  3023 //
       
  3024 // ---------------------------------------------------------------------------
       
  3025 TBool CMIDDisplayable::IsActive() const
       
  3026 {
       
  3027     return iActive;
       
  3028 }
       
  3029 
       
  3030 // ---------------------------------------------------------------------------
       
  3031 //
       
  3032 // ---------------------------------------------------------------------------
       
  3033 TTypeUid::Ptr CMIDDisplayable::MopSupplyObject(TTypeUid aId)
       
  3034 {
       
  3035     if (aId.iUid == MAknsControlContext::ETypeId && iBackGroundControlContext)
       
  3036     {
       
  3037         return MAknsControlContext::SupplyMopObject(aId, iBackGroundControlContext);
       
  3038     }
       
  3039     ASSERT(iMenuHandler);
       
  3040     return SupplyMopObject(aId, iMenuHandler->Cba(), iMenuHandler->MenuBar());
       
  3041 }
       
  3042 
       
  3043 // ---------------------------------------------------------------------------
       
  3044 //
       
  3045 // ---------------------------------------------------------------------------
       
  3046 void CMIDDisplayable::NotifyContentDestroyed()
       
  3047 {
       
  3048     iContent = NULL;
       
  3049     iContentControl = NULL;
       
  3050 
       
  3051     iEnv.RemoveObserver(*this);
       
  3052 }
       
  3053 
       
  3054 /** Check virtual keyboard status. Only for touchscreen.
       
  3055   *  Returns a boolean variable:
       
  3056   *  ETrue  - VKB is opened,
       
  3057   *  EFalse - VKB is hidden.
       
  3058  **/
       
  3059 #ifdef RD_TACTILE_FEEDBACK
       
  3060 TBool CMIDDisplayable::IsVKBOnScreen()
       
  3061 {
       
  3062     TBool vkbOpen = EFalse;
       
  3063 
       
  3064     if (!iPenInputServerConnected && AknLayoutUtils::PenEnabled())
       
  3065     {
       
  3066         TInt err = iPenInputServer.Connect();
       
  3067         iPenInputServerConnected = (err == KErrNone);
       
  3068     }
       
  3069 
       
  3070     if (iPenInputServerConnected)
       
  3071     {
       
  3072         if (iPenInputServer.IsVisible())
       
  3073         {
       
  3074             vkbOpen = ETrue;
       
  3075         }
       
  3076     }
       
  3077 
       
  3078     return vkbOpen;
       
  3079 }
       
  3080 #endif //RD_TACTILE_FEEDBACK
       
  3081 
       
  3082 
       
  3083 #ifdef RD_SCALABLE_UI_V2
       
  3084 TUint CMIDDisplayable::OnScreenKeypadL()
       
  3085 {
       
  3086     DEBUG("+ CMIDDisplayable::OnScreenKeypadL");
       
  3087 
       
  3088     if (RProcess().SecureId().iId != 0x102033E6)
       
  3089     {
       
  3090         // For standalone type apps we don't show keypad.
       
  3091         return EOnScreenKeypadValueNo;
       
  3092     }
       
  3093     TUint onScreenKeypadValue = EOnScreenKeypadValueUndefined;
       
  3094 
       
  3095     std::auto_ptr<java::storage::JavaStorage> js(java::storage::JavaStorage::createInstance());
       
  3096     java::storage::JavaStorageApplicationEntry_t entries;
       
  3097     try
       
  3098     {
       
  3099         js->open();
       
  3100         java::util::Uid uid;
       
  3101         TUidToUid(iEnv.MidletSuiteUid(), uid);
       
  3102         js->read(java::storage::MIDP_PACKAGE_TABLE, uid, entries);
       
  3103         js->close();
       
  3104     }
       
  3105     catch (java::storage::JavaStorageException& ex)
       
  3106     {
       
  3107         DEBUG_INT("CMIDCanvas::IsNetworkIndicatorEnabledL: JavaStorage error: \
       
  3108             reading MIDP_PACKAGE_TABLE failed, error code = %D", ex.mStatus);
       
  3109     }
       
  3110     java::storage::JavaStorageEntry attribute;
       
  3111     attribute.setEntry(java::storage::ON_SCREEN_KEYPAD, L"");
       
  3112     java::storage::JavaStorageApplicationEntry_t::const_iterator findIterator = entries.find(attribute);
       
  3113     std::wstring res = L"";
       
  3114     if (findIterator != entries.end())
       
  3115     {
       
  3116         res = (*findIterator).entryValue();
       
  3117     }
       
  3118     entries.clear();
       
  3119 
       
  3120     if (res == L"0")
       
  3121     {
       
  3122         onScreenKeypadValue = EOnScreenKeypadValueNo;
       
  3123     }
       
  3124     else if (res == L"1")
       
  3125     {
       
  3126         onScreenKeypadValue = EOnScreenKeypadValueGameActions;
       
  3127     }
       
  3128     else if (res == L"2")
       
  3129     {
       
  3130         onScreenKeypadValue = EOnScreenKeypadValueNavigationKeys;
       
  3131     }
       
  3132 
       
  3133     DEBUG("- CMIDDisplayable::OnScreenKeypadL");
       
  3134 
       
  3135     return onScreenKeypadValue;
       
  3136 }
       
  3137 #endif // RD_SCALABLE_UI_V2
       
  3138 
       
  3139 // ---------------------------------------------------------------------------
       
  3140 //
       
  3141 // ---------------------------------------------------------------------------
       
  3142 void CMIDDisplayable::SetEmphasis(CCoeControl* /*aMenuControl*/,TBool /*aEmphasis*/)
       
  3143 {
       
  3144 
       
  3145 }
       
  3146 
       
  3147 // ---------------------------------------------------------------------------
       
  3148 // Adds a rectangle to be excluded from redrawing (for DSA)
       
  3149 // ---------------------------------------------------------------------------
       
  3150 //
       
  3151 void CMIDDisplayable::AddDirectContentArea(const TRect& aRect)
       
  3152 {
       
  3153     TDirectContentsRect rect(aRect);
       
  3154     TInt index = iDirectContentsRects.Find(
       
  3155                      rect, TIdentityRelation< TDirectContentsRect >(CMIDDisplayable::MatchDirectContentsRects));
       
  3156     if (index == KErrNotFound)
       
  3157     {
       
  3158         TInt err = iDirectContentsRects.Append(rect);
       
  3159         if (KErrNone == err)
       
  3160         {
       
  3161             UpdateDirectContentsRegion();
       
  3162         }
       
  3163         else
       
  3164         {
       
  3165             DEBUG_INT("CMIDDisplayable::AddDirectContentArea - RArray append error %d", err);
       
  3166         }
       
  3167     }
       
  3168     else
       
  3169     {
       
  3170         iDirectContentsRects[ index ].iRefCount++;
       
  3171     }
       
  3172 }
       
  3173 
       
  3174 // ---------------------------------------------------------------------------
       
  3175 // Removes a rectangle to be excluded from redrawing (for DSA)
       
  3176 // ---------------------------------------------------------------------------
       
  3177 //
       
  3178 void CMIDDisplayable::RemoveDirectContentArea(const TRect& aRect)
       
  3179 {
       
  3180     TDirectContentsRect rect(aRect);
       
  3181     TInt index = iDirectContentsRects.Find(
       
  3182                      rect, TIdentityRelation< TDirectContentsRect >(CMIDDisplayable::MatchDirectContentsRects));
       
  3183     if (index != KErrNotFound)
       
  3184     {
       
  3185         iDirectContentsRects[ index ].iRefCount--;
       
  3186         if (iDirectContentsRects[ index ].iRefCount <= 0)
       
  3187         {
       
  3188             iDirectContentsRects.Remove(index);
       
  3189             UpdateDirectContentsRegion();
       
  3190         }
       
  3191     }
       
  3192 }
       
  3193 
       
  3194 
       
  3195 // ---------------------------------------------------------------------------
       
  3196 // Matches two direct content rectangles and returns the result
       
  3197 // ---------------------------------------------------------------------------
       
  3198 //
       
  3199 TBool CMIDDisplayable::MatchDirectContentsRects
       
  3200 (
       
  3201     const TDirectContentsRect& aLhs,
       
  3202     const TDirectContentsRect& aRhs
       
  3203 )
       
  3204 {
       
  3205     return (aLhs.iRect == aRhs.iRect);
       
  3206 }
       
  3207 
       
  3208 // ---------------------------------------------------------------------------
       
  3209 // Update the direct content regions
       
  3210 // This should be called just after addition or removal of dc rectangle
       
  3211 // ---------------------------------------------------------------------------
       
  3212 //
       
  3213 void CMIDDisplayable::UpdateDirectContentsRegion()
       
  3214 {
       
  3215     iDirectContentsRegion.Clear();
       
  3216     TInt count = iDirectContentsRects.Count();
       
  3217     for (int index = 0; index < count; index++)
       
  3218     {
       
  3219         iDirectContentsRegion.AddRect(iDirectContentsRects[ index ].iRect);
       
  3220     }
       
  3221 }
       
  3222 
       
  3223 
       
  3224 TBool CMIDDisplayable::NoDirectContentAreaDefined()
       
  3225 {
       
  3226     return iDirectContentsRegion.IsEmpty();
       
  3227 }
       
  3228 
       
  3229 void CMIDDisplayable::SetPopupTextBox(TBool aPopup)
       
  3230 {
       
  3231     iIsPopupTextBox = aPopup;
       
  3232 }
       
  3233 
       
  3234 TBool CMIDDisplayable::IsPopupTextBox()
       
  3235 {
       
  3236     return iIsPopupTextBox;
       
  3237 }
       
  3238 
       
  3239 // ---------------------------------------------------------------------------
       
  3240 // Gets the location and anchor for all the softkey buttons
       
  3241 // for fullscreen canvas and stores it for later usage.
       
  3242 // The data have to marked as invalid in iFullscreenCanvasLabelCacheIsValid
       
  3243 // if any resolution / skin change is proceeding.
       
  3244 // ---------------------------------------------------------------------------
       
  3245 //
       
  3246 void CMIDDisplayable::RenewFullscreenCanvasLabelCacheL()
       
  3247 {
       
  3248     DEBUG("+ CMIDDisplayable::RenewFullscreenCanvasLabelCacheL");
       
  3249 
       
  3250     if ((iCba)   &&
       
  3251             (!iFullscreenCanvasLabelCacheIsValid) &&
       
  3252             (iCommandList))
       
  3253     {
       
  3254         TPoint move(0, 0);
       
  3255         if (iUseOnScreenKeypad)
       
  3256         {
       
  3257             // SK location have to be moved when OnScreenKeypad is active
       
  3258             TSize diff(iDisplayableRect.Size() -
       
  3259                        iAppUi->ApplicationRect().Size());
       
  3260             move = diff.AsPoint();
       
  3261         }
       
  3262 
       
  3263         for (TInt softKeyId = 0; softKeyId < KSoftKeyLabelPropertyNumberOfSoftKeys; softKeyId++)
       
  3264         {
       
  3265             iFullscreenCanvasLabelCache[softKeyId].iIsOn = EFalse;
       
  3266             TBool SKVisibility = true;
       
  3267 
       
  3268             // Check if the MSK is used in Avkon
       
  3269             if (softKeyId == KSoftKeyLabelPropertyPositionsMSKIndex)
       
  3270             {
       
  3271                 TBool MSKEnabledInPlatform;
       
  3272                 CRepository* cenRep = NULL;
       
  3273                 TRAPD(err, cenRep = CRepository::NewL(KCRUidAvkon));
       
  3274                 if (!err)
       
  3275                 {
       
  3276                     err = cenRep->Get(KAknMiddleSoftkeyEnabled, MSKEnabledInPlatform);
       
  3277                     delete cenRep;
       
  3278                 }
       
  3279 
       
  3280                 // Check the cases, in which the MSK is off
       
  3281                 if (!AknLayoutUtils::MSKEnabled() || !MSKEnabledInPlatform ||
       
  3282                         !Layout_Meta_Data::IsMSKEnabled() ||
       
  3283                         Layout_Meta_Data::IsLandscapeOrientation())
       
  3284                 {
       
  3285                     SKVisibility = false;
       
  3286                 }
       
  3287 
       
  3288             }
       
  3289 
       
  3290             if (SKVisibility)
       
  3291             {
       
  3292                 iCba->SetCommandSetL(R_AVKON_SOFTKEYS_EMPTY);
       
  3293                 TInt softKeyCbaPosition = KSoftKeyLabelPropertyPositionsInCBA[ softKeyId ];
       
  3294                 iCba->SetCommandL(softKeyCbaPosition, R_MIDP_SOFTKEY_OPTIONS);
       
  3295                 TInt cmdId = EAknSoftkeyOptions;
       
  3296                 TInt position = iCba->PositionById(cmdId);
       
  3297                 if ((position == softKeyCbaPosition) && iCba->IsCommandVisible(cmdId))
       
  3298                 {
       
  3299                     CEikCommandButton *cmdButton = (CEikCommandButton*)iCba->ControlOrNull(cmdId);
       
  3300                     if (cmdButton && cmdButton->IsVisible()  && !iCba->IsCommandDimmed(cmdId))
       
  3301                     {
       
  3302                         CEikLabel *label = (CEikLabel*)cmdButton->ComponentControl(0);
       
  3303                         if (label && label->IsVisible())
       
  3304                         {
       
  3305                             iFullscreenCanvasLabelCache[softKeyId].iPosition
       
  3306                             = label->PositionRelativeToScreen() + move;
       
  3307 
       
  3308                             iFullscreenCanvasLabelCache[softKeyId].iSize = label->Size();
       
  3309                             TGulAlignment align = label->iAlignment;
       
  3310                             TGulHAlignment hAlign = align.HAlignment();
       
  3311                             switch (hAlign)
       
  3312                             {
       
  3313                             case EHLeft:
       
  3314                                 iFullscreenCanvasLabelCache[softKeyId].iAnchor = TSoftkeyLabel::EJavaLeft;
       
  3315                                 break;
       
  3316                             case EHCenter:
       
  3317                                 iFullscreenCanvasLabelCache[softKeyId].iAnchor = TSoftkeyLabel::EJavaHCenter;
       
  3318                                 break;
       
  3319                             case EHRight:
       
  3320                                 iFullscreenCanvasLabelCache[softKeyId].iAnchor = TSoftkeyLabel::EJavaRight;
       
  3321                                 break;
       
  3322                             }
       
  3323                             TGulVAlignment vAlign = align.VAlignment();
       
  3324                             switch (vAlign)
       
  3325                             {
       
  3326                             case EVTop:
       
  3327                                 iFullscreenCanvasLabelCache[softKeyId].iAnchor |= TSoftkeyLabel::EJavaTop;
       
  3328                                 break;
       
  3329                             case EVCenter:
       
  3330                                 iFullscreenCanvasLabelCache[softKeyId].iAnchor |= TSoftkeyLabel::EJavaVCenter;
       
  3331                                 break;
       
  3332                             case EVBottom:
       
  3333                                 iFullscreenCanvasLabelCache[softKeyId].iAnchor |= TSoftkeyLabel::EJavaBottom;
       
  3334                                 break;
       
  3335                             }
       
  3336                             iFullscreenCanvasLabelCache[softKeyId].iIsOn = ETrue;
       
  3337                         }
       
  3338                     }
       
  3339                 }
       
  3340             }
       
  3341         }
       
  3342     }
       
  3343 
       
  3344     iFullscreenCanvasLabelCacheIsValid = ETrue;
       
  3345 
       
  3346     DEBUG("- CMIDDisplayable::RenewFullscreenCanvasLabelCacheL");
       
  3347 }
       
  3348 
       
  3349 void CMIDDisplayable::HandleCanvasForeground(TBool aForeground)
       
  3350 {
       
  3351     CMIDCanvas* canvas = GetContentCanvas();
       
  3352     if (canvas)
       
  3353     {
       
  3354         canvas->HandleForeground(aForeground);
       
  3355     }
       
  3356 }
       
  3357 
       
  3358 void CMIDDisplayable::HandleApplicationBackground()
       
  3359 {
       
  3360     // If iCanvasKeypad exists, it notifies On-Screen Keypad
       
  3361     // about current application focus lost.
       
  3362     if (iCanvasKeypad)
       
  3363     {
       
  3364         iCanvasKeypad->HandleApplicationBackground();
       
  3365     }
       
  3366 
       
  3367     HandleCanvasForeground(EFalse);
       
  3368 }
       
  3369 
       
  3370 void CMIDDisplayable::ProcessMSKCommandL()
       
  3371 {
       
  3372     if (iIdOfMSKCommand != KErrNotFound)
       
  3373     {
       
  3374         ProcessCommandL(iIdOfMSKCommand);
       
  3375     }
       
  3376 }
       
  3377 
       
  3378 void CMIDDisplayable::DisplayableBehindPopupIsDestroyed()
       
  3379 {
       
  3380     // Old fullscreen Displayable is destroyed.
       
  3381     iDisplayableBehindPopup = NULL;
       
  3382 }
       
  3383 
       
  3384 void CMIDDisplayable::HideIndicator(CEikStatusPane* aSp, TInt aId)
       
  3385 {
       
  3386     TUid uid = TUid::Uid(aId);
       
  3387     CEikStatusPaneBase::TPaneCapabilities subPane = aSp->PaneCapabilities(uid);
       
  3388     if (subPane.IsPresent() && subPane.IsAppOwned())
       
  3389     {
       
  3390         CCoeControl* ctrl = NULL;
       
  3391         TRAP_IGNORE(ctrl = aSp->ControlL(uid));
       
  3392         if (ctrl)
       
  3393         {
       
  3394             ctrl->MakeVisible(EFalse);
       
  3395         }
       
  3396     }
       
  3397 }
       
  3398 
       
  3399 void CMIDDisplayable::HideIndicators()
       
  3400 {
       
  3401     CEikStatusPane* pane = iAppUi->StatusPane();
       
  3402     if (!pane)
       
  3403         return;
       
  3404 
       
  3405     HideIndicator(pane, EEikStatusPaneUidSignal);
       
  3406     HideIndicator(pane, EEikStatusPaneUidBattery);
       
  3407     HideIndicator(pane, EEikStatusPaneUidIndic);
       
  3408     HideIndicator(pane, EEikStatusPaneUidMessage);
       
  3409     HideIndicator(pane, EEikStatusPaneUidClock);
       
  3410     HideIndicator(pane, EEikStatusPaneUidDigitalClock);
       
  3411 }
       
  3412 
       
  3413 CMIDCanvas* CMIDDisplayable::GetContentCanvas()
       
  3414 {
       
  3415     CMIDCanvas* ret = NULL;
       
  3416     if (iContent && iContentControl &&
       
  3417             (iContent->Type() == MMIDComponent::ECanvas ||
       
  3418              iContent->Type() == MMIDComponent::EGameCanvas))
       
  3419     {
       
  3420         ret = static_cast<CMIDCanvas*>(iContentControl);
       
  3421     }
       
  3422     return ret;
       
  3423 }
       
  3424 
       
  3425 CPropertyWatch* CPropertyWatch::NewL(MMIDDisplayable* aDisplayable)
       
  3426 {
       
  3427     DEBUG("+ CPropertyWatch::NewL");
       
  3428 
       
  3429     CPropertyWatch* self = new(ELeave) CPropertyWatch;
       
  3430     CleanupStack::PushL(self);
       
  3431     self->ConstructL(aDisplayable);
       
  3432     CleanupStack::Pop(self);
       
  3433 
       
  3434     DEBUG("- CPropertyWatch::NewL");
       
  3435 
       
  3436     return self;
       
  3437 }
       
  3438 
       
  3439 void CMIDDisplayable::FixOrientation()
       
  3440 {
       
  3441     TBool tmpRestoreOrientation;
       
  3442 
       
  3443     if (!iAvkonAppUi)
       
  3444     {
       
  3445         return;
       
  3446     }
       
  3447 
       
  3448     iOldUiOrientation = iAvkonAppUi->Orientation();
       
  3449     tmpRestoreOrientation = (iOldUiOrientation == CAknAppUiBase::EAppUiOrientationUnspecified) ? ETrue : EFalse;
       
  3450 
       
  3451     // Fix the orientation when was set to unspecified only
       
  3452     if (tmpRestoreOrientation)
       
  3453     {
       
  3454         TRAP_IGNORE(iAvkonAppUi->SetOrientationL(CAknAppUiBase::EAppUiOrientationLandscape));
       
  3455 
       
  3456         iRestoreOrientation = ETrue;
       
  3457         ++iReleaseCnt;
       
  3458     }
       
  3459 
       
  3460 }
       
  3461 
       
  3462 void CMIDDisplayable::ReleaseOrientation()
       
  3463 {
       
  3464     if (!iAvkonAppUi)
       
  3465     {
       
  3466         return;
       
  3467     }
       
  3468 
       
  3469     if (iReleaseCnt > 0)
       
  3470     {
       
  3471         --iReleaseCnt;
       
  3472         if (iReleaseCnt == 0 && iRestoreOrientation)
       
  3473         {
       
  3474             TRAP_IGNORE(iAvkonAppUi->SetOrientationL(iOldUiOrientation));
       
  3475             iRestoreOrientation = EFalse;
       
  3476         }
       
  3477 
       
  3478     }
       
  3479 }
       
  3480 
       
  3481 CPropertyWatch::CPropertyWatch()
       
  3482         : CActive(0)
       
  3483 {
       
  3484 }
       
  3485 
       
  3486 void CPropertyWatch::ConstructL(MMIDDisplayable* aDisplayable)
       
  3487 {
       
  3488     DEBUG("+ CPropertyWatch::ConstructL");
       
  3489 
       
  3490     iDisplayable = static_cast< CMIDDisplayable* >(aDisplayable);
       
  3491     User::LeaveIfError(iProperty.Attach(KCRUidAvkon, KAknKeyBoardLayout));
       
  3492     CActiveScheduler::Add(this);
       
  3493     iDelayTimer = CPeriodic::NewL(CActive::EPriorityStandard);
       
  3494     RunL();
       
  3495 
       
  3496     DEBUG("- CPropertyWatch::ConstructL");
       
  3497 }
       
  3498 
       
  3499 CPropertyWatch::~CPropertyWatch()
       
  3500 {
       
  3501     DEBUG("+ CPropertyWatch::~CPropertyWatch");
       
  3502 
       
  3503     Cancel();
       
  3504     iProperty.Close();
       
  3505 
       
  3506     if (iDelayTimer)
       
  3507     {
       
  3508         iDelayTimer->Cancel();
       
  3509         delete iDelayTimer;
       
  3510     }
       
  3511 
       
  3512     DEBUG("- CPropertyWatch::~CPropertyWatch");
       
  3513 }
       
  3514 
       
  3515 void CPropertyWatch::DoCancel()
       
  3516 {
       
  3517     iProperty.Cancel();
       
  3518 }
       
  3519 
       
  3520 void CPropertyWatch::HandleDelayTimerEventL()
       
  3521 {
       
  3522     iDelayTimer->Cancel();
       
  3523     if (Layout_Meta_Data::IsLandscapeOrientation())
       
  3524     {
       
  3525         iDisplayable->HandleOnScreenKeypadVisual();
       
  3526     }
       
  3527 }
       
  3528 
       
  3529 TInt CPropertyWatch::DelayTimerCallbackL(TAny* aThis)
       
  3530 {
       
  3531     CPropertyWatch* observer = static_cast<CPropertyWatch*>(aThis);
       
  3532     observer->HandleDelayTimerEventL();
       
  3533     return 0;
       
  3534 }
       
  3535 
       
  3536 void CPropertyWatch::RunL()
       
  3537 {
       
  3538     DEBUG("+ CPropertyWatch::RunL");
       
  3539 
       
  3540     //Resubscribe before processing new value to prevent missing updates
       
  3541     iProperty.Subscribe(iStatus);
       
  3542     SetActive();
       
  3543 
       
  3544     if (Layout_Meta_Data::IsLandscapeOrientation())
       
  3545     {
       
  3546         iDelayTimer->Cancel();
       
  3547         iDelayTimer->Start(KTimerDelayValue, KTimerDelayValue,
       
  3548                            TCallBack(DelayTimerCallbackL, this));
       
  3549     }
       
  3550 
       
  3551     DEBUG("- CPropertyWatch::RunL");
       
  3552 }
       
  3553 
       
  3554 
       
  3555 // End of File