|
1 /* |
|
2 * Copyright (c) 1999 - 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 "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 "MIDUtils.h" |
|
20 #include "CMIDToolkit.h" |
|
21 #include "javax_microedition_lcdui_TextField.h" |
|
22 |
|
23 |
|
24 LOCAL_C void CreateL(CMIDToolkit* aToolkit,TInt* aHandle,jobject aTextComponent,const TDesC* aLabel,const TDesC* aText,TInt aConstraints,TInt aMaxSize) |
|
25 { |
|
26 MMIDTextField* textComponent = aToolkit->ComponentFactory()->CreateTextFieldL(*aLabel,*aText,aConstraints,aMaxSize); |
|
27 CleanupDisposePushL(textComponent); |
|
28 *aHandle = aToolkit->RegisterComponentL(textComponent, aTextComponent); |
|
29 CleanupPopComponent(textComponent); |
|
30 } |
|
31 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_TextField__1create |
|
32 (JNIEnv* aJni,jobject,jint aToolkit,jobject aTextComponent,jstring aLabel,jstring aText,jint aConstraints,jint aMaxSize) |
|
33 { |
|
34 jobject textComponent = aJni->NewWeakGlobalRef(aTextComponent); |
|
35 if (textComponent == 0) |
|
36 return KErrNoMemory; |
|
37 // |
|
38 RJString label(*aJni,aLabel); |
|
39 RJString text(*aJni,aText); |
|
40 CMIDToolkit* toolkit =JavaUnhand<CMIDToolkit>(aToolkit); |
|
41 TInt h=0; |
|
42 TInt err = toolkit->ExecuteTrap(&CreateL,toolkit,&h,textComponent,(const TDesC*)&label,(const TDesC*)&text,(TInt)aConstraints,(TInt)aMaxSize); |
|
43 if (err!=KErrNone) |
|
44 { |
|
45 aJni->DeleteWeakGlobalRef((jweak)textComponent); |
|
46 return err; |
|
47 } |
|
48 return h; |
|
49 } |
|
50 |
|
51 |
|
52 LOCAL_C TInt GetCaretPosition(MMIDTextField* aTextComponent) |
|
53 { |
|
54 return aTextComponent->GetCaretPosition(); |
|
55 } |
|
56 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_TextField__1getCaretPosition |
|
57 (JNIEnv*,jobject,jint aTextComponent,jint aToolkit) |
|
58 { |
|
59 MMIDTextField* textComponent = MIDUnhandObject<MMIDTextField>(aTextComponent); |
|
60 CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit); |
|
61 return toolkit->Execute(&GetCaretPosition,textComponent); |
|
62 } |
|
63 |
|
64 |
|
65 LOCAL_C void GetTextL(MMIDTextField* aTextComponent, HBufC** aString) |
|
66 { |
|
67 *aString = aTextComponent->GetTextL(); |
|
68 } |
|
69 JNIEXPORT jstring JNICALL Java_javax_microedition_lcdui_TextField__1getString |
|
70 (JNIEnv* aJni,jobject,jint aTextComponent,jint aToolkit) |
|
71 { |
|
72 MMIDTextField* textComponent = MIDUnhandObject<MMIDTextField>(aTextComponent); |
|
73 CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit); |
|
74 HBufC* text=NULL; |
|
75 TInt error = toolkit->ExecuteTrap(&GetTextL, textComponent, &text); |
|
76 jstring str = (text!=NULL && error==KErrNone) ? CreateJavaString(*aJni,*text):NULL; |
|
77 delete text; |
|
78 return str; |
|
79 } |
|
80 |
|
81 |
|
82 LOCAL_C void SetTextL(MMIDTextField* aTextComponent,const TDesC* aText) |
|
83 { |
|
84 aTextComponent->SetTextL(*aText); |
|
85 } |
|
86 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_TextField__1setString |
|
87 (JNIEnv* aJni,jobject,jint aTextComponent,jint aToolkit,jstring aText) |
|
88 { |
|
89 MMIDTextField* textComponent = MIDUnhandObject<MMIDTextField>(aTextComponent); |
|
90 CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit); |
|
91 RJString text(*aJni,aText); |
|
92 return toolkit->ExecuteTrap(&SetTextL,textComponent,(const TDesC*)&text); |
|
93 } |
|
94 |
|
95 |
|
96 LOCAL_C void InsertTextL(MMIDTextField* aTextComponent,const TDesC* aText,TInt aPosition) |
|
97 { |
|
98 aTextComponent->InsertTextL(*aText,aPosition); |
|
99 } |
|
100 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_TextField__1insertString |
|
101 (JNIEnv* aJni,jobject,jint aTextComponent,jint aToolkit,jstring aText,jint aPosition) |
|
102 { |
|
103 MMIDTextField* textComponent = MIDUnhandObject<MMIDTextField>(aTextComponent); |
|
104 CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit); |
|
105 RJString text(*aJni,aText); |
|
106 return toolkit->ExecuteTrap(&InsertTextL,textComponent,(const TDesC*)&text,(TInt)aPosition); |
|
107 } |
|
108 |
|
109 |
|
110 LOCAL_C void DeleteTextL(MMIDTextField* aTextComponent,TInt aOffset,TInt aLength) |
|
111 { |
|
112 aTextComponent->DeleteTextL(aOffset,aLength); |
|
113 } |
|
114 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_TextField__1delete |
|
115 (JNIEnv*,jobject,jint aTextComponent,jint aToolkit,jint aOffset,jint aLength) |
|
116 { |
|
117 MMIDTextField* textComponent = MIDUnhandObject<MMIDTextField>(aTextComponent); |
|
118 CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit); |
|
119 return toolkit->ExecuteTrap(&DeleteTextL,textComponent,(TInt)aOffset,(TInt)aLength); |
|
120 } |
|
121 |
|
122 |
|
123 LOCAL_C void SetMaxSizeL(MMIDTextField* aTextComponent,TInt aSize, TInt* aMaxSize) |
|
124 { |
|
125 *aMaxSize = aTextComponent->SetMaxSizeL(aSize); |
|
126 } |
|
127 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_TextField__1setMaxSize |
|
128 (JNIEnv*,jobject,jint aTextComponent,jint aToolkit,jint aSize) |
|
129 { |
|
130 MMIDTextField* textComponent = MIDUnhandObject<MMIDTextField>(aTextComponent); |
|
131 CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit); |
|
132 // Do server side as if the current contents of the TextField are larger than |
|
133 // maxSize,the contents are truncated to fit. |
|
134 TInt maxSize = 0; |
|
135 TInt err = toolkit->ExecuteTrap(&SetMaxSizeL,textComponent,(TInt)aSize, &maxSize); |
|
136 return err == KErrNone ? maxSize : err; |
|
137 } |
|
138 |
|
139 |
|
140 LOCAL_C TInt GetMaxSize(MMIDTextField* aTextComponent) |
|
141 { |
|
142 return aTextComponent->GetMaxSize(); |
|
143 } |
|
144 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_TextField__1getMaxSize |
|
145 (JNIEnv*,jobject,jint aTextComponent,jint aToolkit) |
|
146 { |
|
147 MMIDTextField* textComponent = MIDUnhandObject<MMIDTextField>(aTextComponent); |
|
148 CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit); |
|
149 return toolkit->Execute(&GetMaxSize,textComponent); |
|
150 } |
|
151 |
|
152 |
|
153 LOCAL_C TInt Size(MMIDTextField* aTextComponent) |
|
154 { |
|
155 return aTextComponent->Size(); |
|
156 } |
|
157 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_TextField__1size(JNIEnv*,jobject,jint aTextComponent,jint aToolkit) |
|
158 { |
|
159 MMIDTextField* textComponent = MIDUnhandObject<MMIDTextField>(aTextComponent); |
|
160 CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit); |
|
161 return toolkit->Execute(&Size,textComponent); |
|
162 } |
|
163 |
|
164 |
|
165 LOCAL_C void SetConstraintsL(MMIDTextField* aTextComponent,TUint aConstraints) |
|
166 { |
|
167 aTextComponent->SetConstraintsL(aConstraints); |
|
168 } |
|
169 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_TextField__1setConstraints |
|
170 (JNIEnv*,jobject,jint aTextComponent,jint aToolkit,jint aConstraints) |
|
171 { |
|
172 MMIDTextField* textComponent = MIDUnhandObject<MMIDTextField>(aTextComponent); |
|
173 CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit); |
|
174 return toolkit->ExecuteTrap(&SetConstraintsL,textComponent,(TUint)aConstraints); |
|
175 } |
|
176 |
|
177 |
|
178 LOCAL_C void SetInitialInputModeL(MMIDTextField* aTextComponent,const TDesC* aCharacterSubset) |
|
179 { |
|
180 aTextComponent->SetInitialInputModeL(*aCharacterSubset); |
|
181 } |
|
182 JNIEXPORT jint JNICALL Java_javax_microedition_lcdui_TextField__1setInitialInputMode |
|
183 (JNIEnv* aJni,jobject,jint aTextComponent,jint aToolkit,jstring aCharacterSubset) |
|
184 { |
|
185 MMIDTextField* textComponent = MIDUnhandObject<MMIDTextField>(aTextComponent); |
|
186 CMIDToolkit* toolkit = JavaUnhand<CMIDToolkit>(aToolkit); |
|
187 RJString charSubset(*aJni,aCharacterSubset); |
|
188 return toolkit->ExecuteTrap(&SetInitialInputModeL,textComponent,(const TDesC*)&charSubset); |
|
189 } |