|
1 /* |
|
2 * Copyright (c) 1999-2002 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 |
|
19 #include "CMIDToolkit.h" |
|
20 #include "MIDUtils.h" |
|
21 #include "javax_microedition_lcdui_Form.h" |
|
22 |
|
23 struct TFormCreate |
|
24 { |
|
25 jweak iRef; |
|
26 jint iDisplayable; |
|
27 }; |
|
28 |
|
29 struct TFormAttribs |
|
30 { |
|
31 jint iHandle; |
|
32 TSize iSize; |
|
33 }; |
|
34 |
|
35 LOCAL_C void CreateFormL(CMIDToolkit* aToolkit, TFormCreate* aCreate, TFormAttribs* aAttribs) |
|
36 { |
|
37 MMIDDisplayable* displayable = MIDUnhand<MMIDDisplayable>(aCreate->iDisplayable); |
|
38 MMIDForm* form = aToolkit->ComponentFactory()->CreateFormL(*displayable); |
|
39 CleanupDisposePushL(form); |
|
40 aAttribs->iHandle = aToolkit->RegisterComponentL(form, aCreate->iRef); |
|
41 CleanupPopComponent(form); |
|
42 aCreate->iRef = 0; |
|
43 aAttribs->iSize.iWidth = form->Width(); |
|
44 aAttribs->iSize.iHeight = form->Height(); |
|
45 } |
|
46 |
|
47 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_Form__1create |
|
48 ( |
|
49 JNIEnv* aJni, |
|
50 jobject aForm, |
|
51 jint aToolkit, |
|
52 jint aDisplayable, |
|
53 jintArray aFormAttribReturn |
|
54 ) |
|
55 { |
|
56 TFormCreate create; |
|
57 TFormAttribs attribs; |
|
58 |
|
59 create.iDisplayable = aDisplayable; |
|
60 create.iRef = aJni->NewWeakGlobalRef(aForm); |
|
61 attribs.iHandle = 0; |
|
62 |
|
63 jint error; |
|
64 if (create.iRef) |
|
65 { |
|
66 CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit); |
|
67 error = toolkit->ExecuteTrap(&CreateFormL, toolkit, &create, &attribs); |
|
68 } |
|
69 else |
|
70 { |
|
71 error = KErrNoMemory; |
|
72 } |
|
73 |
|
74 if (create.iRef) |
|
75 { |
|
76 // CreateFormL clears if successful |
|
77 aJni->DeleteWeakGlobalRef(create.iRef); |
|
78 } |
|
79 |
|
80 jint attribArray[3]; |
|
81 attribArray[0]=attribs.iHandle; |
|
82 attribArray[1]=attribs.iSize.iWidth; |
|
83 attribArray[2]=attribs.iSize.iHeight; |
|
84 aJni->SetIntArrayRegion(aFormAttribReturn, 0, 3, attribArray); |
|
85 |
|
86 return error; |
|
87 } |
|
88 |
|
89 LOCAL_C void RefreshItemL(MMIDForm* aForm,TInt aIndex) |
|
90 { |
|
91 aForm->RefreshItemL(aIndex); |
|
92 } |
|
93 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_Form__1refresh |
|
94 (JNIEnv*,jobject,jint aForm,jint aToolkit,jint aIndex) |
|
95 { |
|
96 CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit); |
|
97 MMIDForm* form = MIDUnhandObject<MMIDForm>(aForm); |
|
98 return toolkit->ExecuteTrap(&RefreshItemL,form,(TInt)aIndex); |
|
99 } |
|
100 |
|
101 LOCAL_C TBool IsVisible(MMIDForm* aForm,TInt aIndex) |
|
102 { |
|
103 return aForm->IsItemVisible(aIndex); |
|
104 } |
|
105 JNIEXPORT jboolean JNICALL Java_javax_microedition_lcdui_Form__1isVisible |
|
106 (JNIEnv*,jobject,jint aForm,jint aToolkit,jint aIndex) |
|
107 { |
|
108 CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit); |
|
109 MMIDForm* form = MIDUnhandObject<MMIDForm>(aForm); |
|
110 return (jboolean)toolkit->Execute(&IsVisible,form,(TInt)aIndex); |
|
111 } |
|
112 |
|
113 LOCAL_C void InsertItemL(MMIDForm* aForm,MMIDItem* aItem,TInt aIndex) |
|
114 { |
|
115 aForm->InsertItemL(*aItem,aIndex); |
|
116 } |
|
117 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_Form__1insert |
|
118 (JNIEnv*,jobject,jint aForm,jint aToolkit,jint aIndex,jint aItem) |
|
119 { |
|
120 CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit); |
|
121 MMIDForm* form = MIDUnhandObject<MMIDForm>(aForm); |
|
122 MMIDItem* item = MIDUnhandObject<MMIDItem>(aItem); |
|
123 return toolkit->ExecuteTrap(&InsertItemL,form,item,(TInt)aIndex); |
|
124 } |
|
125 |
|
126 LOCAL_C void SetItemL(MMIDForm* aForm,MMIDItem* aItem,TInt aIndex) |
|
127 { |
|
128 aForm->SetItemL(*aItem,aIndex); |
|
129 } |
|
130 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_Form__1set |
|
131 (JNIEnv*,jobject,jint aForm,jint aToolkit,jint aIndex,jint aItem) |
|
132 { |
|
133 CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit); |
|
134 MMIDForm* form = MIDUnhandObject<MMIDForm>(aForm); |
|
135 MMIDItem* item = MIDUnhandObject<MMIDItem>(aItem); |
|
136 return toolkit->ExecuteTrap(&SetItemL,form,item,(TInt)aIndex); |
|
137 } |
|
138 |
|
139 LOCAL_C void SetAllItemsL(MMIDForm* aForm,RArray<MMIDItem*>* aItems) |
|
140 { |
|
141 aForm->SetAllItemsL(*aItems); |
|
142 } |
|
143 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_Form__1setAll |
|
144 (JNIEnv* aJni,jobject,jint aForm,jint aToolkit,jintArray aItems) |
|
145 { |
|
146 jint* items = aJni->GetIntArrayElements(aItems,0); |
|
147 TInt count = aJni->GetArrayLength(aItems); |
|
148 RArray<MMIDItem*> MIDItems(count); |
|
149 TInt ret = KErrNone; |
|
150 for (TInt i=0; i<count; i++) |
|
151 ret = MIDItems.Append(MIDUnhandObject<MMIDItem>(items[i])); |
|
152 aJni->ReleaseIntArrayElements(aItems,items,JNI_ABORT); |
|
153 if (ret == KErrNone) |
|
154 { |
|
155 CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit); |
|
156 MMIDForm* form = MIDUnhandObject<MMIDForm>(aForm); |
|
157 ret = toolkit->ExecuteTrap(&SetAllItemsL,form,&MIDItems); |
|
158 } |
|
159 MIDItems.Close(); |
|
160 return ret; |
|
161 } |
|
162 |
|
163 LOCAL_C void DeleteItemL(MMIDForm* aForm,TInt aIndex) |
|
164 { |
|
165 aForm->DeleteItemL(aIndex); |
|
166 } |
|
167 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_Form__1delete |
|
168 (JNIEnv*,jobject,jint aForm,jint aToolkit,jint aIndex) |
|
169 { |
|
170 CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit); |
|
171 MMIDForm* form = MIDUnhandObject<MMIDForm>(aForm); |
|
172 return toolkit->ExecuteTrap(&DeleteItemL,form,(TInt)aIndex); |
|
173 } |
|
174 |
|
175 LOCAL_C void DeleteAllItemsL(MMIDForm* aForm) |
|
176 { |
|
177 aForm->DeleteAllItemsL(); |
|
178 } |
|
179 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_Form__1deleteAll |
|
180 (JNIEnv*,jobject,jint aForm,jint aToolkit) |
|
181 { |
|
182 CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit); |
|
183 MMIDForm* form = MIDUnhandObject<MMIDForm>(aForm); |
|
184 return toolkit->ExecuteTrap(&DeleteAllItemsL,form); |
|
185 } |
|
186 |
|
187 LOCAL_C void NotifyStateChanged(MMIDEnv* aEnv,MMIDForm* aForm,TInt aIndex) |
|
188 { |
|
189 aEnv->PostJavaEvent(*aForm,EDisplayable,aIndex); |
|
190 } |
|
191 JNIEXPORT void JNICALL Java_javax_microedition_lcdui_Form__1notifyStateChanged |
|
192 (JNIEnv*,jobject,jint aForm,jint aToolkit,jint aIndex) |
|
193 { |
|
194 CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit); |
|
195 MMIDForm* form = MIDUnhandObject<MMIDForm>(aForm); |
|
196 toolkit->ExecuteV(&NotifyStateChanged,toolkit->Env(),form,(TInt)aIndex); |
|
197 } |
|
198 |
|
199 LOCAL_C void SetCurrentItemL(MMIDForm* aForm,TInt aIndex) |
|
200 { |
|
201 aForm->SetCurrentItemL(aIndex); |
|
202 } |
|
203 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_Form__1setCurrentItem |
|
204 (JNIEnv*,jobject,jint aForm,jint aToolkit,jint aIndex) |
|
205 { |
|
206 CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit); |
|
207 MMIDForm* form = MIDUnhandObject<MMIDForm>(aForm); |
|
208 return toolkit->ExecuteTrap(&SetCurrentItemL,form,(TInt)aIndex); |
|
209 } |
|
210 |
|
211 LOCAL_C void GetFormSize(MMIDForm* aForm, TSize* aSize) |
|
212 { |
|
213 aSize->iWidth = aForm->Width(); |
|
214 aSize->iHeight = aForm->Height(); |
|
215 } |
|
216 |
|
217 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_Form__1getFormSize |
|
218 (JNIEnv*,jobject,jint aForm,jint aToolkit) |
|
219 { |
|
220 CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit); |
|
221 if (!toolkit) |
|
222 { |
|
223 return KErrGeneral; |
|
224 } |
|
225 |
|
226 MMIDForm* form = MIDUnhandObject<MMIDForm>(aForm); |
|
227 TSize size; |
|
228 toolkit->ExecuteV(&GetFormSize, form, &size); |
|
229 return (size.iWidth << 16) | (size.iHeight & 0x0000ffff); |
|
230 } |