javauis/lcdui_akn/lcdui/src/CMIDCommand.cpp
changeset 21 2a9601315dfc
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     1 /*
       
     2 * Copyright (c) 2006 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:  ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // macros definitions for resources
       
    20 #include <lcdui.rsg>
       
    21 
       
    22 #include "CMIDCommand.h"
       
    23 //using CEikonEnv API for loading resources to label
       
    24 #include "eikenv.h"
       
    25 
       
    26 
       
    27 MMIDCommand* CMIDCommand::NewL(const TDesC& aShortLabel,const TDesC& aLongLabel,
       
    28                                TCommandType aType,TInt aPriority,TInt aCommandID)
       
    29 {
       
    30     CMIDCommand* command = new(ELeave) CMIDCommand(aType,aPriority,aCommandID);
       
    31     CleanupStack::PushL(command);
       
    32     command->ConstructL(aShortLabel,aLongLabel);
       
    33     CleanupStack::Pop(command);
       
    34     return command;
       
    35 }
       
    36 
       
    37 CMIDCommand* CMIDCommand::NewBuiltInCommandL(const TDesC& aLabel, TCommandType aType, TInt aId)
       
    38 {
       
    39     return static_cast<CMIDCommand*>(CMIDCommand::NewL(aLabel, aLabel, aType, 0, aId));
       
    40 }
       
    41 
       
    42 HBufC* CMIDCommand::AlertDismissLabelL()
       
    43 {
       
    44     // This method is static - that's why member variable iEikEnv cannot be used
       
    45     return CEikonEnv::Static()->AllocReadResourceL(R_DISMISS_COMMAND_NAME);
       
    46 }
       
    47 
       
    48 HBufC* CMIDCommand::ListSelectLabelL()
       
    49 {
       
    50     // This method is static - that's why member variable iEikEnv cannot be used
       
    51     return CEikonEnv::Static()->AllocReadResourceL(R_SELECT_COMMAND_NAME);
       
    52 }
       
    53 
       
    54 CMIDCommand::CMIDCommand(TCommandType aType,TInt aPriority, TInt aId)
       
    55         :iType(aType)
       
    56         ,iPriority(aPriority)
       
    57         ,iId(aId)
       
    58         ,iEikEnv(*(CEikonEnv::Static()))
       
    59 {
       
    60 }
       
    61 
       
    62 CMIDCommand::~CMIDCommand()
       
    63 {
       
    64     delete iShortLabel;
       
    65     delete iLongLabel;
       
    66 }
       
    67 
       
    68 void CMIDCommand::ConstructL(const TDesC& aShortLabel,const TDesC& aLongLabel)
       
    69 {
       
    70     switch (iId)
       
    71     {
       
    72     case MMIDCommand::EAlertDismissCommand:
       
    73         iShortLabel = AlertDismissLabelL();
       
    74         iLongLabel = AlertDismissLabelL();
       
    75         break;
       
    76 
       
    77     case MMIDCommand::EListSelectCommand:
       
    78         iShortLabel = ListSelectLabelL();
       
    79         iLongLabel = ListSelectLabelL();
       
    80         break;
       
    81 
       
    82     case MMIDCommand::ENullCommand:
       
    83     default:
       
    84         if (aShortLabel.Length())
       
    85         {
       
    86             iShortLabel = aShortLabel.AllocL();
       
    87         }
       
    88         else
       
    89         {
       
    90             // Use default label only if both short and long labels are empt
       
    91             if (aLongLabel.Length())
       
    92             {
       
    93                 iShortLabel= aLongLabel.AllocL();
       
    94             }
       
    95             else
       
    96             {
       
    97                 iShortLabel = DefaultLabelL();
       
    98             }
       
    99         }
       
   100         iLongLabel = aLongLabel.AllocL();
       
   101         break;
       
   102     }
       
   103 
       
   104     // Finally, in all cases make sure that the long label is not left empty.
       
   105     // If it would be, replace it with the short label.
       
   106     if (!iLongLabel->Length())
       
   107     {
       
   108         delete iLongLabel;
       
   109         iLongLabel = NULL;
       
   110         iLongLabel = iShortLabel->AllocL();
       
   111     }
       
   112 }
       
   113 
       
   114 const TDesC& CMIDCommand::Label() const
       
   115 {
       
   116     return iLongLabel->Length() ? *iLongLabel : *iShortLabel;
       
   117 }
       
   118 
       
   119 MMIDCommand::TCommandType CMIDCommand::CommandType() const
       
   120 {
       
   121     return iType;
       
   122 }
       
   123 
       
   124 TInt CMIDCommand::Priority() const
       
   125 {
       
   126     return iPriority;
       
   127 }
       
   128 
       
   129 TInt CMIDCommand::Id() const
       
   130 {
       
   131     return iId;
       
   132 }
       
   133 
       
   134 void CMIDCommand::Dispose()
       
   135 {
       
   136     delete this;
       
   137 }
       
   138 
       
   139 const TDesC& CMIDCommand::ShortLabel() const
       
   140 {
       
   141     return *iShortLabel;
       
   142 }
       
   143 
       
   144 void CMIDCommand::SetMappedToSoftKey(TBool aMapped) const
       
   145 {
       
   146     iIsMappedToSoftKey = aMapped;
       
   147 }
       
   148 
       
   149 TBool CMIDCommand::IsMappedToSoftKey() const
       
   150 {
       
   151     return iIsMappedToSoftKey;
       
   152 }
       
   153 
       
   154 HBufC* CMIDCommand::DefaultLabelL()
       
   155 {
       
   156     HBufC* label = NULL;
       
   157     switch (iType)
       
   158     {
       
   159     case EScreen:
       
   160         label = iEikEnv.AllocReadResourceL(R_MIDP_SCREEN_COMMAND_TEXT);
       
   161         break;
       
   162     case EBack:
       
   163         label = iEikEnv.AllocReadResourceL(R_MIDP_BACK_COMMAND_TEXT);
       
   164         break;
       
   165     case ECancel:
       
   166         label = iEikEnv.AllocReadResourceL(R_MIDP_CANCEL_COMMAND_TEXT);
       
   167         break;
       
   168     case EOk:
       
   169         label = iEikEnv.AllocReadResourceL(R_MIDP_OK_COMMAND_TEXT);
       
   170         break;
       
   171     case EHelp:
       
   172         label = iEikEnv.AllocReadResourceL(R_MIDP_HELP_COMMAND_TEXT);
       
   173         break;
       
   174     case EStop:
       
   175         label = iEikEnv.AllocReadResourceL(R_MIDP_STOP_COMMAND_TEXT);
       
   176         break;
       
   177     case EItem:
       
   178         label = iEikEnv.AllocReadResourceL(R_MIDP_ITEM_COMMAND_TEXT);
       
   179         break;
       
   180     case EExit:
       
   181         label = iEikEnv.AllocReadResourceL(R_MIDP_EXIT_COMMAND_TEXT);
       
   182         break;
       
   183     }
       
   184     return label;
       
   185 }
       
   186 
       
   187 /** Set the current cmd observer, see MMIDCommandObserver. This can be a NULL
       
   188 pointer. Any previous observer is overwritten.*/
       
   189 void CMIDCommand::SetObserver(MMIDCommandObserver* aObserver)
       
   190 {
       
   191     iObserver = aObserver;
       
   192 }
       
   193 
       
   194 MMIDCommandObserver* CMIDCommand::Observer() const
       
   195 {
       
   196     return iObserver;
       
   197 }
       
   198 
       
   199 // End of File