webengine/widgetengine/src/MenuItemFuncs.cpp
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 /*
       
     2 * Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDES
       
    21 #include "config.h"
       
    22 #include <kjs/object.h>
       
    23 #include <e32std.h>
       
    24 #include <lookup.h>
       
    25 #include <eikamnt.h>
       
    26 
       
    27 #include "MenuItem.h"
       
    28 #include "MenuItemFuncs.h"
       
    29 #include "MenuItemCallbacks.h"
       
    30 
       
    31 using namespace KJS;
       
    32 
       
    33 // ----------------------------------------------------------------------------
       
    34 // JSMenuItemFunc::JSMenuItemFunc
       
    35 // Default constructor
       
    36 //
       
    37 //
       
    38 // ----------------------------------------------------------------------------
       
    39 JSMenuItemFunc::JSMenuItemFunc(  
       
    40     ExecState *exec,  
       
    41     MJSMenuItemCallbacks* callbacks,
       
    42     int functionIndex )
       
    43     : JSObject(exec->lexicalInterpreter()->builtinObjectPrototype()),
       
    44     m_functionId( abs( functionIndex ) ),
       
    45     m_callbacks( callbacks )    
       
    46     {
       
    47     }
       
    48 
       
    49 
       
    50 // ----------------------------------------------------------------------------
       
    51 // JSMenuItemFunc::implementsCall
       
    52 // Whether or not the object implements the call() method
       
    53 //
       
    54 //
       
    55 // ----------------------------------------------------------------------------
       
    56 bool JSMenuItemFunc::implementsCall() const
       
    57     {
       
    58     return true;
       
    59     }
       
    60 
       
    61 
       
    62 // ----------------------------------------------------------------------------
       
    63 // JSMenuItemFunc::call
       
    64 // Calls this object as if it is a function
       
    65 //
       
    66 //
       
    67 // ----------------------------------------------------------------------------
       
    68 JSValue* JSMenuItemFunc::callAsFunction(ExecState *exec, JSObject *thisObj, const List &args)
       
    69     {
       
    70 
       
    71     JSMenuItem *thisItem = static_cast<JSMenuItem*>(thisObj);
       
    72 
       
    73     switch ( m_functionId )
       
    74     {
       
    75         case JSMenuItem::Append:
       
    76         {
       
    77             if ( args.size() > 0 && !args[0]->isNull() ) {
       
    78                 
       
    79                 JSMenuItem* mitem = static_cast<JSMenuItem*>(args[0]->toObject(exec));
       
    80                 
       
    81                 if ( mitem->type() == ObjectType &&  mitem->inherits(&JSMenuItem::info) && 
       
    82                      thisItem->type() == ObjectType && thisItem->inherits(&JSMenuItem::info)) {                                        
       
    83                     
       
    84                     int itemId = mitem->InternalId();
       
    85                     int pitemId = thisItem->InternalId();
       
    86                     if (m_callbacks->addOptionsMenuItem(itemId, pitemId, thisItem->Show()) == KErrNone) {                        
       
    87                         mitem->SetShow( thisItem->Show() );
       
    88                         if ( mitem->callback() )
       
    89                             m_callbacks->setMenuItemObserver(itemId, mitem->callback());                        
       
    90                     }
       
    91                     
       
    92                 }
       
    93             }
       
    94         }
       
    95         break;
       
    96         case JSMenuItem::Remove:
       
    97         {
       
    98             if ( args.size() > 0 && !(args[0]->isNull()) ) {
       
    99             
       
   100                 JSMenuItem* mitem = static_cast<JSMenuItem*>(args[0]->toObject(exec));
       
   101                 
       
   102                 if (mitem->type() == ObjectType && 
       
   103                     mitem->inherits(&JSMenuItem::info) && 
       
   104                     thisItem->type() == ObjectType && 
       
   105                     thisItem->inherits(&JSMenuItem::info)) {
       
   106                         m_callbacks->deleteMenuItem(mitem->InternalId());
       
   107                 }
       
   108             }
       
   109         }       
       
   110         break;
       
   111         case JSMenuItem::SetDim:
       
   112         {
       
   113             if ( args.size() > 0 && 
       
   114                 args[0]->type() == BooleanType && 
       
   115                 thisItem->type() == ObjectType && 
       
   116                 thisItem->inherits(&JSMenuItem::info)) {
       
   117                 thisItem->SetDimmed( args[0]->toBoolean( exec ) );
       
   118             }
       
   119             
       
   120         }
       
   121         break;
       
   122         case JSMenuItem::ToString:
       
   123         {
       
   124             thisItem->toString( exec );
       
   125         }
       
   126         break;
       
   127         default:
       
   128           break;
       
   129     }
       
   130     
       
   131     return jsUndefined();
       
   132 }
       
   133 
       
   134 
       
   135