webengine/widgetengine/src/Menu.cpp
changeset 0 dd21522fd290
child 5 10e98eab6f85
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 
       
    22 #include "config.h"
       
    23 #include <e32std.h>
       
    24 #include <kjs/object.h>
       
    25 #include <AknUtils.h>
       
    26 
       
    27 #include "Menu.h"
       
    28 #include "MenuFuncs.h"
       
    29 #include "MenuCallbacks.h"
       
    30 
       
    31 
       
    32 using namespace KJS;
       
    33 
       
    34 // ------------------------------ JSMenu -----------------------------
       
    35 
       
    36 const ClassInfo JSMenu::info = { "JSMenu", 0, &MenuTable, 0 };
       
    37 
       
    38 
       
    39 /*
       
    40 @begin MenuTable 11
       
    41   append            JSMenu::Append              DontDelete|Function 1
       
    42   remove            JSMenu::Remove              DontDelete|Function 1
       
    43   getMenuItemById   JSMenu::GetMenuItemById     DontDelete|Function 1
       
    44   getMenuItemByName JSMenu::GetMenuItemByName   DontDelete|Function 1
       
    45   setRightSoftkeyLabel JSMenu::SetRightSoftKeyLabel DontDelete|Function 2
       
    46   onShow            JSMenu::OnShow              DontDelete|ReadOnly
       
    47   clear             JSMenu::Clear               DontDelete|Function 0
       
    48   toString          JSMenu::ToString            DontDelete|Function 0
       
    49   hideSoftkeys      JSMenu::HideSoftkeys        DontDelete|Function 0
       
    50   showSoftkeys      JSMenu::ShowSoftkeys        DontDelete|Function 0
       
    51   setLeftSoftkeyLabel JSMenu::SetLeftSoftKeyLabel DontDelete|Function 2
       
    52   location          JSMenu::Location            DontDelete|ReadOnly
       
    53 @end
       
    54 */
       
    55 
       
    56 
       
    57 // ----------------------------------------------------------------------------
       
    58 // JSMenu::JSMenu
       
    59 // Default contructor
       
    60 //
       
    61 //
       
    62 // ----------------------------------------------------------------------------
       
    63 JSMenu::JSMenu(MJSMenuCallbacks* aMenuCallbacks)
       
    64         : JSObject(), 
       
    65         d(new MenuPrivate(aMenuCallbacks,0,0))
       
    66 {  
       
    67 }
       
    68 
       
    69 
       
    70 // ----------------------------------------------------------------------------
       
    71 // JSMenu::~JSMenu
       
    72 // Destructor
       
    73 //
       
    74 //
       
    75 // ----------------------------------------------------------------------------
       
    76 JSMenu::~JSMenu()
       
    77 {    
       
    78     delete d;
       
    79 }
       
    80 
       
    81 
       
    82 // ----------------------------------------------------------------------------
       
    83 // JSMenu::type
       
    84 //
       
    85 //
       
    86 // ----------------------------------------------------------------------------
       
    87 JSType JSMenu::type() const 
       
    88 { 
       
    89     return ObjectType; 
       
    90 }
       
    91 
       
    92 // ----------------------------------------------------------------------------
       
    93 // JSMenu::toString
       
    94 // Returns string representation of the object
       
    95 //
       
    96 //
       
    97 // ----------------------------------------------------------------------------
       
    98 UString JSMenu::toString( ExecState *exec ) const
       
    99 {
       
   100     return "[object JSMenu]";
       
   101 }
       
   102 
       
   103 
       
   104 // ----------------------------------------------------------------------------
       
   105 // JSMenu::setRightKeyObserver
       
   106 // Sets the callback fuction for right softkey press
       
   107 //
       
   108 //
       
   109 // ----------------------------------------------------------------------------
       
   110 void JSMenu::setRightKeyCallback( ExecState *exec, JSValue *value )
       
   111 {
       
   112     if (d->m_rightKeyCallback)
       
   113         d->m_rightKeyCallback->Delete();
       
   114     
       
   115     d->m_rightKeyCallback = NULL;
       
   116     if ( value && !value->isNull() ) {        
       
   117         d->m_rightKeyCallback = new WidgetEventHandler(value, exec->lexicalInterpreter()->globalExec());
       
   118     }
       
   119 }
       
   120 
       
   121 // ----------------------------------------------------------------------------
       
   122 // JSMenu::setRightKeyObserver
       
   123 // Sets the callback fuction for right softkey press
       
   124 //
       
   125 //
       
   126 // ----------------------------------------------------------------------------
       
   127 void JSMenu::setLeftKeyCallback( ExecState *exec, JSValue *value )
       
   128 {
       
   129     if (d->m_leftKeyCallback)
       
   130         d->m_leftKeyCallback->Delete();
       
   131     
       
   132     d->m_leftKeyCallback = NULL;
       
   133     if ( value && !value->isNull() ) {        
       
   134         d->m_leftKeyCallback = new WidgetEventHandler(value, exec->lexicalInterpreter()->globalExec());
       
   135     }
       
   136 }
       
   137 
       
   138 
       
   139 // ----------------------------------------------------------------------------
       
   140 // JSMenu::getOwnPropertySlot
       
   141 //
       
   142 //
       
   143 //
       
   144 // ----------------------------------------------------------------------------
       
   145 bool JSMenu::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
       
   146 {
       
   147     
       
   148     const HashEntry* entry = Lookup::findEntry(&MenuTable, propertyName);
       
   149     if (entry) {
       
   150         slot.setStaticEntry(this, entry, staticValueGetter<JSMenu>);
       
   151         return true;
       
   152     }   
       
   153 
       
   154     return JSObject::getOwnPropertySlot(exec, propertyName, slot);
       
   155 }
       
   156 
       
   157 
       
   158 // ----------------------------------------------------------------------------
       
   159 // JSMenu::get
       
   160 // Retrieves the specified property from the object. If neither the object
       
   161 // or any other object in it's prototype chain have the property, this function
       
   162 // will return Undefined
       
   163 //
       
   164 //
       
   165 // ----------------------------------------------------------------------------
       
   166 JSValue* JSMenu::getValueProperty(KJS::ExecState* exec, int token) const
       
   167 {
       
   168     
       
   169     switch( token )
       
   170     {
       
   171         case Append:
       
   172         case Remove:
       
   173         case GetMenuItemById:
       
   174         case GetMenuItemByName:
       
   175         case SetRightSoftKeyLabel:
       
   176         case Clear:
       
   177         case ToString:
       
   178         case HideSoftkeys:
       
   179         case ShowSoftkeys:  
       
   180         case SetLeftSoftKeyLabel: {
       
   181             JSMenuFunc *mf = new JSMenuFunc(exec, d->m_callbacks, token);
       
   182             return mf;
       
   183         }
       
   184             
       
   185         case Location: {
       
   186             // The return values are based on the document that describes softkey location
       
   187             // -1 The command is not supported on this system
       
   188             // 0  The softkeys are located on the top of the device screen
       
   189             // 1  The softkeys are located on the left of the device screen
       
   190             // 2  The softkeys are located on the bottom of the device screen
       
   191             // 3  The softkeys are located on the right of the device screen
       
   192         
       
   193             int ret = -1; 
       
   194             AknLayoutUtils::TAknCbaLocation loc = AknLayoutUtils::CbaLocation();
       
   195             if ( loc == AknLayoutUtils::EAknCbaLocationBottom )
       
   196             {
       
   197                 ret = 2;
       
   198             }
       
   199             else if ( loc == AknLayoutUtils::EAknCbaLocationRight )
       
   200             {
       
   201                 ret = 3;
       
   202             }
       
   203             else if ( loc == AknLayoutUtils::EAknCbaLocationLeft )
       
   204             {
       
   205                 ret = 1;
       
   206             }    
       
   207             return jsNumber(ret);
       
   208         }
       
   209         
       
   210     }
       
   211 
       
   212     return throwError(exec, GeneralError);
       
   213 }
       
   214 
       
   215 
       
   216 // ----------------------------------------------------------------------------
       
   217 // JSMenu::canPut
       
   218 //
       
   219 //
       
   220 //
       
   221 // ----------------------------------------------------------------------------
       
   222 bool JSMenu::canPut(ExecState *exec, const Identifier &propertyName) const
       
   223 {    
       
   224     return true;
       
   225 }
       
   226 
       
   227 // ----------------------------------------------------------------------------
       
   228 // JSMenu::put
       
   229 // Sets the specified property
       
   230 //
       
   231 //
       
   232 // ----------------------------------------------------------------------------
       
   233 
       
   234 void JSMenu::put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr)
       
   235 {
       
   236     const HashEntry * entry = Lookup::findEntry( &MenuTable, propertyName );
       
   237 
       
   238     // if the property exists in the table
       
   239     if ( entry ){
       
   240     
       
   241         // changes the properties of the JSMenu element
       
   242         switch ( entry->value )
       
   243         {
       
   244             case OnShow: {
       
   245                 delete d->m_onShowCallback;
       
   246                 d->m_onShowCallback = NULL;
       
   247                 d->m_onShowCallback = new WidgetEventHandler(value, exec->lexicalInterpreter()->globalExec());
       
   248                 break;
       
   249             }
       
   250             default:
       
   251                 break;
       
   252         }
       
   253     }
       
   254 }
       
   255 
       
   256 
       
   257 
       
   258 
       
   259