|
1 /* |
|
2 * Copyright (c) 2001-2005 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "CMIDToolkit.h" |
|
19 #include "MIDUtils.h" |
|
20 #include "javax_microedition_lcdui_List.h" |
|
21 #include "lcdgr.h" |
|
22 |
|
23 struct TListCreate |
|
24 { |
|
25 jweak iRef; |
|
26 jint iDisplayable; |
|
27 jint iType; |
|
28 }; |
|
29 |
|
30 struct TListAttribs |
|
31 { |
|
32 jint iHandle; |
|
33 TSize iSize; |
|
34 }; |
|
35 |
|
36 LOCAL_C void CreateListL(CMIDToolkit* aToolkit, TListCreate* aCreate, TListAttribs* aAttribs) |
|
37 { |
|
38 MMIDDisplayable& displayable = *MIDUnhand<MMIDDisplayable>(aCreate->iDisplayable); |
|
39 MMIDComponentFactory& factory = *aToolkit->ComponentFactory(); |
|
40 RArray<TPtrC> dummyTextArray; |
|
41 RArray<MMIDImage*> dummyIconArray; |
|
42 TInt type = aCreate->iType; |
|
43 MMIDList* list = factory.CreateListL(type, displayable, dummyTextArray, dummyIconArray); |
|
44 CleanupDisposePushL(list); |
|
45 aAttribs->iHandle = aToolkit->RegisterComponentL(list, aCreate->iRef); |
|
46 CleanupPopComponent(list); |
|
47 aCreate->iRef = 0; |
|
48 aAttribs->iSize = displayable.ContentSize(); |
|
49 } |
|
50 |
|
51 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_List__1create |
|
52 ( |
|
53 JNIEnv* aJni, |
|
54 jobject aList, |
|
55 jint aToolkit, |
|
56 jint aDisplayable, |
|
57 jint aType, |
|
58 jintArray aCreateListReturn |
|
59 ) |
|
60 { |
|
61 jint error = 0; |
|
62 |
|
63 TListCreate create; |
|
64 create.iRef = aJni->NewWeakGlobalRef(aList); |
|
65 create.iDisplayable=aDisplayable; |
|
66 create.iType = aType; |
|
67 |
|
68 TListAttribs attribs; |
|
69 attribs.iHandle = 0; |
|
70 |
|
71 if (create.iRef) |
|
72 { |
|
73 CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit); |
|
74 error = toolkit->ExecuteTrap(CreateListL, toolkit, &create, &attribs); |
|
75 } |
|
76 else |
|
77 { |
|
78 error = KErrNoMemory; |
|
79 } |
|
80 |
|
81 if (create.iRef) |
|
82 { |
|
83 // cleared in CreateListL if successful |
|
84 aJni->DeleteWeakGlobalRef(create.iRef); |
|
85 } |
|
86 |
|
87 ASSERT(aJni->GetArrayLength(aCreateListReturn) == 3); |
|
88 jint arrayReturn[3]; |
|
89 arrayReturn[0] = attribs.iHandle; |
|
90 arrayReturn[1] = attribs.iSize.iWidth; |
|
91 arrayReturn[2] = attribs.iSize.iHeight; |
|
92 aJni->SetIntArrayRegion(aCreateListReturn, 0, 3, arrayReturn); |
|
93 |
|
94 return error; |
|
95 } |
|
96 |
|
97 LOCAL_C void InvokeSetSelectCommand(jint aList, jint aID) |
|
98 { |
|
99 MMIDList* list = MIDUnhandObject<MMIDList>(aList); |
|
100 list->SetSelectCommand(aID); |
|
101 } |
|
102 |
|
103 JNIEXPORT void JNICALL Java_javax_microedition_lcdui_List__1setSelectCommand(JNIEnv*, jobject, jint aList, jint aToolkit, jint aID) |
|
104 { |
|
105 JavaUnhand<CMIDToolkit>(aToolkit)->ExecuteV(&InvokeSetSelectCommand, aList, aID); |
|
106 } |
|
107 |
|
108 LOCAL_C void InsertElementL(MMIDList* aChoice,TInt aIndex,const TDesC* aText,MMIDImage* aImage) |
|
109 { |
|
110 aChoice->InsertElementL(aIndex,*aText,aImage); |
|
111 } |
|
112 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_List__1insert |
|
113 ( |
|
114 JNIEnv* aEnv, |
|
115 jobject, |
|
116 jint aList, |
|
117 jint aToolkit, |
|
118 jint aIndex, |
|
119 jstring aStringItem, |
|
120 jint aImage |
|
121 ) |
|
122 { |
|
123 RJString string(*aEnv,aStringItem); |
|
124 CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit); |
|
125 MMIDList* list = MIDUnhandObject<MMIDList>(aList); |
|
126 MMIDImage* image = MIDUnhandObject<MMIDImage>(aImage); |
|
127 return toolkit->ExecuteTrap( |
|
128 &InsertElementL, |
|
129 list, |
|
130 (TInt)aIndex, |
|
131 (const TDesC*)&string, |
|
132 image |
|
133 ); |
|
134 } |
|
135 |
|
136 LOCAL_C void DeleteElementL(MMIDList* aChoice,TInt aIndex) |
|
137 { |
|
138 aChoice->DeleteElementL(aIndex); |
|
139 } |
|
140 |
|
141 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_List__1delete |
|
142 (JNIEnv *, jobject, jint aList, jint aToolkit, jint aIndex) |
|
143 { |
|
144 MMIDList* list = MIDUnhandObject<MMIDList>(aList); |
|
145 return JavaUnhand<CMIDToolkit>(aToolkit)->ExecuteTrap(&DeleteElementL,list,(TInt)aIndex); |
|
146 } |
|
147 |
|
148 LOCAL_C void DeleteAllL(MMIDList* aChoice) |
|
149 { |
|
150 aChoice->DeleteAllL(); |
|
151 } |
|
152 |
|
153 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_List__1deleteAll |
|
154 (JNIEnv *, jobject, jint aList, jint aToolkit) |
|
155 { |
|
156 MMIDList* list = MIDUnhandObject<MMIDList>(aList); |
|
157 return JavaUnhand<CMIDToolkit>(aToolkit)->ExecuteTrap(&DeleteAllL,list); |
|
158 } |
|
159 |
|
160 LOCAL_C void SetElementL(MMIDList* aChoice,TInt aIndex,const TDesC* aText,MMIDImage* aImage) |
|
161 { |
|
162 aChoice->SetElementL(aIndex,*aText,aImage); |
|
163 } |
|
164 |
|
165 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_List__1set |
|
166 (JNIEnv* aEnv,jobject,jint aList,jint aToolkit,jint aIndex,jstring aStringItem,jint aImage) |
|
167 { |
|
168 RJString string(*aEnv,aStringItem); |
|
169 CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit); |
|
170 MMIDList* list = MIDUnhandObject<MMIDList>(aList); |
|
171 MMIDImage* image = MIDUnhandObject<MMIDImage>(aImage); |
|
172 return toolkit->ExecuteTrap(&SetElementL, list,(TInt)aIndex,(const TDesC*)&string,image); |
|
173 } |
|
174 |
|
175 LOCAL_C TBool IsSelected(MMIDList* aChoice,TInt aIndex) |
|
176 { |
|
177 return aChoice->IsSelected(aIndex); |
|
178 } |
|
179 |
|
180 JNIEXPORT jboolean JNICALL Java_javax_microedition_lcdui_List__1isSelected |
|
181 (JNIEnv*,jobject,jint aList,jint aToolkit,jint aIndex) |
|
182 { |
|
183 MMIDList* list = MIDUnhandObject<MMIDList>(aList); |
|
184 return (jboolean)JavaUnhand<CMIDToolkit>(aToolkit)->Execute(&IsSelected,list,(TInt)aIndex); |
|
185 } |
|
186 |
|
187 LOCAL_C void SelectElementL(MMIDList* aChoice,TInt aIndex,TBool aSelected) |
|
188 { |
|
189 aChoice->SelectElementL(aIndex,aSelected); |
|
190 } |
|
191 |
|
192 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_List__1select |
|
193 (JNIEnv*,jobject,jint aList,jint aToolkit,jint aIndex,jboolean aSelected) |
|
194 { |
|
195 MMIDList* list = MIDUnhandObject<MMIDList>(aList); |
|
196 return JavaUnhand<CMIDToolkit>(aToolkit)->ExecuteTrap(&SelectElementL,list,(TInt)aIndex,(TBool)aSelected); |
|
197 } |
|
198 |
|
199 LOCAL_C void SetFontL(MMIDList* aChoice,TInt aIndex, MMIDFont* aFont) |
|
200 { |
|
201 aChoice->SetFontL(aIndex,aFont); |
|
202 } |
|
203 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_List__1setFont |
|
204 (JNIEnv*,jobject,jint aItem,jint aToolkit,jint aIndex,jint aFont) |
|
205 { |
|
206 MMIDList* choice = MIDUnhandObject<MMIDList>(aItem); |
|
207 MMIDFont* font = MIDUnhandObject<MMIDFont>(aFont); |
|
208 CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit); |
|
209 return toolkit->ExecuteTrap(&SetFontL,choice,(TInt)aIndex,font); |
|
210 } |
|
211 |
|
212 LOCAL_C void SetFitPolicyL(MMIDList* aChoice,TInt aFitPolicy) |
|
213 { |
|
214 aChoice->SetFitPolicyL(aFitPolicy); |
|
215 } |
|
216 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_List__1setFitPolicy |
|
217 (JNIEnv*,jobject,jint aItem,jint aToolkit,jint aFitPolicy) |
|
218 { |
|
219 MMIDList* choice = MIDUnhandObject<MMIDList>(aItem); |
|
220 return JavaUnhand<CMIDToolkit>(aToolkit)->ExecuteTrap(&SetFitPolicyL,choice,(TInt)aFitPolicy); |
|
221 } |