|
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 <eikamnt.h> |
|
22 #include <eikcba.h> |
|
23 |
|
24 |
|
25 #include "Menu.h" |
|
26 #include "MenuItem.h" |
|
27 #include "MenuFuncs.h" |
|
28 #include "MenuCallbacks.h" |
|
29 |
|
30 using namespace KJS; |
|
31 |
|
32 // ---------------------------------------------------------------------------- |
|
33 // JSMenuFunc::JSMenuFunc |
|
34 // Default constructor |
|
35 // |
|
36 // |
|
37 // ---------------------------------------------------------------------------- |
|
38 JSMenuFunc::JSMenuFunc( ExecState* exec, MJSMenuCallbacks* callbacks, int functionIndex ) : |
|
39 JSObject(exec->lexicalInterpreter()->builtinObjectPrototype()), |
|
40 m_callbacks( callbacks ), |
|
41 m_functionId( abs( functionIndex ) ) |
|
42 { |
|
43 } |
|
44 |
|
45 JSMenuFunc::~JSMenuFunc() |
|
46 { |
|
47 } |
|
48 |
|
49 // ---------------------------------------------------------------------------- |
|
50 // JSMenuFunc::implementsCall |
|
51 // Whether or not the object implements the call() method |
|
52 // |
|
53 // |
|
54 // ---------------------------------------------------------------------------- |
|
55 bool JSMenuFunc::implementsCall() const |
|
56 { |
|
57 return true; |
|
58 } |
|
59 |
|
60 |
|
61 // ---------------------------------------------------------------------------- |
|
62 // JSMenuFunc::call |
|
63 // Calls this object as if it is a function |
|
64 // |
|
65 // |
|
66 // ---------------------------------------------------------------------------- |
|
67 JSValue* JSMenuFunc::callAsFunction(ExecState *exec, JSObject *thisObj, const List &args) |
|
68 { |
|
69 |
|
70 JSMenu *thisItem = static_cast<JSMenu*>(thisObj); |
|
71 |
|
72 switch ( m_functionId) |
|
73 { |
|
74 case JSMenu::Append: |
|
75 { |
|
76 if ( args.size() > 0 && !args[0]->isNull() ) { |
|
77 JSMenuItem* mitem = static_cast<JSMenuItem*>( args[0]->toObject(exec) ); |
|
78 if ( mitem->type() == ObjectType && mitem->inherits(&JSMenuItem::info) ) { |
|
79 mitem->AddOptionsMenuItem(true); |
|
80 } |
|
81 } |
|
82 } |
|
83 break; |
|
84 case JSMenu::Remove: |
|
85 { |
|
86 if ( args.size() > 0 && !args[0]->isNull() ) { |
|
87 JSMenuItem* mitem = static_cast<JSMenuItem*>( args[0]->toObject(exec) ); |
|
88 if ( mitem->type() == ObjectType && mitem->inherits(&JSMenuItem::info) ) { |
|
89 mitem->DeleteMenuItem(); |
|
90 } |
|
91 } |
|
92 |
|
93 } |
|
94 break; |
|
95 case JSMenu::GetMenuItemById: |
|
96 { |
|
97 if ( args.size() > 0 && !args[0]->isNull() ) { |
|
98 |
|
99 TInt cmdId = args[0]->toInt32( exec ); |
|
100 JSMenuItem* mi = static_cast<JSMenuItem*>(m_callbacks->getFromMenuItemCollection( cmdId )); |
|
101 |
|
102 if ( !mi ) |
|
103 return jsUndefined(); |
|
104 |
|
105 return mi; |
|
106 } |
|
107 } |
|
108 break; |
|
109 case JSMenu::GetMenuItemByName: |
|
110 { |
|
111 if ( args.size() > 0 && !args[0]->isNull() ) { |
|
112 UString str = args[0]->toString( exec ); |
|
113 TBuf<CEikAutoMenuTitle::ENominalTextLength+1> textVal; |
|
114 textVal.Copy( (const unsigned short*)( str.data() ),( str.size() > CEikAutoMenuTitle::ENominalTextLength ) ? CEikAutoMenuTitle::ENominalTextLength : str.size() ); |
|
115 |
|
116 JSMenuItem* mi = static_cast<JSMenuItem*>( m_callbacks->getFromMenuItemCollection( textVal )); |
|
117 if ( !mi ) |
|
118 return jsUndefined(); |
|
119 |
|
120 return mi; |
|
121 } |
|
122 |
|
123 } |
|
124 break; |
|
125 case JSMenu::SetRightSoftKeyLabel: |
|
126 { |
|
127 if (args.size() > 1) { |
|
128 TInt labelSize(0); |
|
129 if (!args[0]->isNull() ) { |
|
130 UString label = args[0]->toString( exec ); |
|
131 labelSize = (label.size() < KMaxCbaLabelLength) ? label.size() : KMaxCbaLabelLength; |
|
132 m_callbacks->setRightSoftKeyLabel(TPtrC((const unsigned short*)(label.data()), labelSize) ); |
|
133 } |
|
134 |
|
135 JSValue* val = (!args[1]->isNull() && labelSize) ? args[1] : 0; |
|
136 thisItem->setRightKeyCallback( exec, val ); |
|
137 } |
|
138 |
|
139 } |
|
140 break; |
|
141 case JSMenu::SetLeftSoftKeyLabel: |
|
142 { |
|
143 if (args.size() > 1) { |
|
144 TInt labelSize(0); |
|
145 if (!args[0]->isNull() ) { |
|
146 UString label = args[0]->toString( exec ); |
|
147 labelSize = (label.size() < KMaxCbaLabelLength) ? label.size() : KMaxCbaLabelLength; |
|
148 m_callbacks->setLeftSoftKeyLabel(TPtrC((const unsigned short*)(label.data()), labelSize) ); |
|
149 } |
|
150 |
|
151 JSValue* val = (!args[1]->isNull() && labelSize) ? args[1] : 0; |
|
152 thisItem->setLeftKeyCallback( exec, val ); |
|
153 } |
|
154 |
|
155 } |
|
156 break; |
|
157 case JSMenu::Clear: |
|
158 { |
|
159 m_callbacks->clearMenuItems(); |
|
160 } |
|
161 break; |
|
162 case JSMenu::ToString: |
|
163 { |
|
164 thisItem->toString( exec ); |
|
165 } |
|
166 break; |
|
167 case JSMenu::HideSoftkeys: |
|
168 { |
|
169 m_callbacks->hideSoftkeys( ); |
|
170 } |
|
171 break; |
|
172 case JSMenu::ShowSoftkeys: |
|
173 { |
|
174 m_callbacks->showSoftkeys( ); |
|
175 } |
|
176 break; |
|
177 default: |
|
178 break; |
|
179 } |
|
180 |
|
181 return jsUndefined(); |
|
182 } |
|
183 |
|
184 |
|
185 |