javauis/eswt_akn/org.eclipse.ercp.swt.s60/native/src/swtcommand.cpp
changeset 21 2a9601315dfc
child 23 98ccebc37403
equal deleted inserted replaced
18:e8e63152f320 21:2a9601315dfc
       
     1 /*******************************************************************************
       
     2  * Copyright (c) 2005, 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved. This program and the accompanying materials
       
     4  * are made available under the terms of the Eclipse Public License v1.0
       
     5  * which accompanies this distribution, and is available at
       
     6  * http://www.eclipse.org/legal/epl-v10.html
       
     7  *
       
     8  * Contributors:
       
     9  *     Nokia Corporation - S60 implementation
       
    10  *******************************************************************************/
       
    11 
       
    12 
       
    13 #include "swtcommand.h"
       
    14 
       
    15 
       
    16 // ======== MEMBER FUNCTIONS ========
       
    17 
       
    18 
       
    19 inline CSwtCommand::CSwtCommand(MSwtDisplay& aDisplay, TSwtPeer aPeer,
       
    20                                 const MSwtControl& aParentControl, const MSwtCommand* aParentCommand,
       
    21                                 TInt aType, TInt aPriority)
       
    22         : iDisplay(aDisplay)
       
    23         , iPeer(aPeer)
       
    24         , iParentControl(aParentControl)
       
    25         , iParentCommand(aParentCommand)
       
    26         , iType(aType)
       
    27         , iPriority(aPriority)
       
    28         , iEnabled(ETrue)
       
    29 {
       
    30 }
       
    31 
       
    32 CSwtCommand::~CSwtCommand()
       
    33 {
       
    34     delete iText;
       
    35     delete iLongLabel;
       
    36 
       
    37     if (iImage != NULL)
       
    38         iImage->RemoveRef();
       
    39 
       
    40 #ifdef _lint
       
    41     iParentCommand = NULL;
       
    42     iImage = NULL;
       
    43 #endif
       
    44     //lint -esym(1540, CSwtCommand::iPeer)
       
    45 }
       
    46 
       
    47 void CSwtCommand::ConstructL()
       
    48 {
       
    49     iParentControl.GetShell().InstallCba();
       
    50     
       
    51     // Notify Command arranger (must be done at the end of ConstructL,
       
    52     // when Command is created for sure)
       
    53     MSwtCommandArranger* commandArranger = iDisplay.CommandArranger();
       
    54     ASSERT(commandArranger); // Mobile Extensions must have been loaded
       
    55     commandArranger->CommandAddedL(*this);
       
    56 } //lint !e1762
       
    57 
       
    58 CSwtCommand* CSwtCommand::NewL(MSwtDisplay& aDisplay, TSwtPeer aPeer,
       
    59                                const MSwtControl& aParentControl, const MSwtCommand* aParentCommand,
       
    60                                TInt aType, TInt aPriority)
       
    61 {
       
    62     CSwtCommand* self = new(ELeave) CSwtCommand(aDisplay, aPeer,
       
    63             aParentControl, aParentCommand, aType, aPriority);
       
    64     CleanupStack::PushL(self);
       
    65     self->ConstructL();
       
    66     CleanupStack::Pop(self);
       
    67     return self;
       
    68 }
       
    69 
       
    70 TSwtPeer CSwtCommand::Dispose()
       
    71 {
       
    72     // Notify Command arranger
       
    73     // Done here rather than in destructor because command may go through
       
    74     // destruction before being added to arranger
       
    75     MSwtCommandArranger* commandArranger = iDisplay.CommandArranger();
       
    76     ASSERT(commandArranger); // Mobile Extensions must have been loaded
       
    77     commandArranger->CommandRemoved(*this);
       
    78 
       
    79     // Actual dispose
       
    80     TSwtPeer peer(JavaPeer());
       
    81     delete this;
       
    82     return peer;
       
    83 }
       
    84 
       
    85 TSwtPeer CSwtCommand::JavaPeer() const
       
    86 {
       
    87     return iPeer;
       
    88 } //lint !e1763
       
    89 
       
    90 const MSwtControl& CSwtCommand::ParentControl() const
       
    91 {
       
    92     return iParentControl;
       
    93 }
       
    94 
       
    95 const MSwtCommand* CSwtCommand::ParentCommand() const
       
    96 {
       
    97     return iParentCommand;
       
    98 }
       
    99 
       
   100 void CSwtCommand::SetAcceleratorL(TInt aAccelerator)
       
   101 {
       
   102     iAccelerator = aAccelerator;
       
   103 
       
   104     // Notify Command arranger
       
   105 //  MSwtCommandArranger* commandArranger = iDisplay.CommandArranger();
       
   106 //  ASSERT(commandArranger); // Mobile Extensions must have been loaded
       
   107 }
       
   108 
       
   109 void CSwtCommand::SetEnabled(TBool aEnabled)
       
   110 {
       
   111     iEnabled = aEnabled;
       
   112 
       
   113     // Notify Command arranger
       
   114     MSwtCommandArranger* commandArranger = iDisplay.CommandArranger();
       
   115     ASSERT(commandArranger); // Mobile Extensions must have been loaded
       
   116     commandArranger->CommandEnablingUpdated(*this);
       
   117 }
       
   118 
       
   119 void CSwtCommand::SetDefaultCommand(TBool aDefault)
       
   120 {
       
   121     iDefault = aDefault;
       
   122 
       
   123     // Notify Command arranger
       
   124     if (aDefault)
       
   125     {
       
   126         MSwtCommandArranger* commandArranger = iDisplay.CommandArranger();
       
   127         ASSERT(commandArranger); // Mobile Extensions must have been loaded
       
   128         commandArranger->CommandSetAsDefault(*this);
       
   129     }
       
   130 }
       
   131 
       
   132 void CSwtCommand::SetTextL(const TDesC& aText)
       
   133 {
       
   134     if (iText)
       
   135     {
       
   136         delete iText;
       
   137         iText = NULL;
       
   138     }
       
   139 
       
   140     iText = aText.AllocL();
       
   141 
       
   142     // Notify Command arranger
       
   143     MSwtCommandArranger* commandArranger = iDisplay.CommandArranger();
       
   144     ASSERT(commandArranger); // Mobile Extensions must have been loaded
       
   145     commandArranger->CommandContentUpdated(*this);
       
   146 }
       
   147 
       
   148 void CSwtCommand::SetImageL(const MSwtImage* aImage)
       
   149 {
       
   150     /* Here are ideas for CommandArranger
       
   151     if (aImage != NULL)
       
   152         {
       
   153         // Beware, ownership of CFbsBitmap is transferred
       
   154         // (at the end, so use cleanupstack in case it leaves)
       
   155         // => create a copy!
       
   156         aImage->Bitmap()
       
   157         aImage->MaskBitmap() // may it be null (in MSwtImage and in nativesymbiancommand)?
       
   158         }
       
   159     else
       
   160         {
       
   161         }
       
   162     */
       
   163 
       
   164     if (iImage != NULL)
       
   165         iImage->RemoveRef();
       
   166     iImage = aImage;
       
   167     if (iImage != NULL)
       
   168         iImage->AddRef();
       
   169 
       
   170     // Notify Command arranger
       
   171     MSwtCommandArranger* commandArranger = iDisplay.CommandArranger();
       
   172     ASSERT(commandArranger); // Mobile Extensions must have been loaded
       
   173     commandArranger->CommandContentUpdated(*this);
       
   174 }
       
   175 
       
   176 void CSwtCommand::SetLongLabelL(const TDesC& aText)
       
   177 {
       
   178     if (iLongLabel)
       
   179     {
       
   180         delete iLongLabel;
       
   181         iLongLabel = NULL;
       
   182     }
       
   183 
       
   184     iLongLabel = aText.AllocL();
       
   185 
       
   186     // Notify Command arranger
       
   187     MSwtCommandArranger* commandArranger = iDisplay.CommandArranger();
       
   188     ASSERT(commandArranger); // Mobile Extensions must have been loaded
       
   189     commandArranger->CommandContentUpdated(*this);
       
   190 }
       
   191 
       
   192 TInt CSwtCommand::Accelerator() const
       
   193 {
       
   194     return iAccelerator;
       
   195 }
       
   196 
       
   197 TBool CSwtCommand::IsEnabled() const
       
   198 {
       
   199     return iEnabled;
       
   200 }
       
   201 
       
   202 TBool CSwtCommand::IsDefaultCommand() const
       
   203 {
       
   204     return iDefault;
       
   205 }
       
   206 
       
   207 const TDesC& CSwtCommand::Text() const
       
   208 {
       
   209     if (iText != NULL)
       
   210     {
       
   211         return *iText;
       
   212     }
       
   213     else
       
   214     {
       
   215         return KNullDesC;
       
   216     }
       
   217 }
       
   218 
       
   219 const MSwtImage* CSwtCommand::Image() const
       
   220 {
       
   221     return iImage;
       
   222 }
       
   223 
       
   224 const TDesC& CSwtCommand::LongLabel() const
       
   225 {
       
   226     if (iLongLabel != NULL)
       
   227     {
       
   228         return *iLongLabel;
       
   229     }
       
   230     else
       
   231     {
       
   232         return KNullDesC;
       
   233     }
       
   234 }
       
   235 
       
   236 TInt CSwtCommand::Priority() const
       
   237 {
       
   238     return iPriority;
       
   239 }
       
   240 
       
   241 TInt CSwtCommand::Type() const
       
   242 {
       
   243     return iType;
       
   244 }