1 |
/******************************************************************************* |
= |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2005 IBM Corporation and others. |
|
2 |
* Copyright (c) 2000, 2005 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
|
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
|
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
|
5 |
* which accompanies this distribution, and is available at |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
|
6 |
* http://www.eclipse.org/legal/epl-v10.html |
7 |
* |
|
7 |
* |
8 |
* Contributors: |
|
8 |
* Contributors: |
9 |
* IBM Corporation - initial API and implementation |
|
9 |
* IBM Corporation - initial API and implementation |
10 |
*******************************************************************************/ |
|
10 |
*******************************************************************************/ |
11 |
|
|
11 |
|
|
|
<> |
12 |
/******************************************************************************* |
|
|
|
13 |
* Additions/modifications to this source file by Oracle America, Inc. 2011 |
|
|
|
14 |
*******************************************************************************/ |
|
|
|
15 |
|
12 |
#include "UGL_ErrorImpl.h" |
= |
16 |
#include "UGL_ErrorImpl.h" |
13 |
#include "Button.h" |
|
17 |
#include "Button.h" |
14 |
#include "UGL_Error.h" |
|
18 |
#include "UGL_Error.h" |
15 |
#include "TypeConverter.h" |
|
19 |
#include "TypeConverter.h" |
16 |
#include <jni.h> |
|
20 |
#include <jni.h> |
17 |
#include "JNIHelpers.h" |
|
21 |
#include "JNIHelpers.h" |
18 |
#include "UGLTypes.h" |
|
22 |
#include "UGLTypes.h" |
19 |
|
|
23 |
|
20 |
#ifdef __cplusplus |
|
24 |
#ifdef __cplusplus |
21 |
#define UNUSED(var) |
|
25 |
#define UNUSED(var) |
22 |
#else |
|
26 |
#else |
23 |
#define UNUSED(var) var |
|
27 |
#define UNUSED(var) var |
24 |
#endif |
|
28 |
#endif |
25 |
|
|
29 |
|
26 |
#ifdef __cplusplus |
|
30 |
#ifdef __cplusplus |
27 |
extern "C" { |
|
31 |
extern "C" { |
28 |
#endif |
|
32 |
#endif |
29 |
|
|
33 |
|
30 |
|
|
34 |
|
31 |
/** |
|
35 |
/** |
32 |
* Sets the label of a button. Please note that a button may not display |
|
36 |
* Sets the label of a button. Please note that a button may not display |
33 |
* its image and its label simultaneously. |
|
37 |
* its image and its label simultaneously. |
34 |
*/ |
|
38 |
*/ |
35 |
JNIEXPORT void JNICALL Java_com_ibm_ugl_eswt_OS_Button_1SetLabel(JNIEnv* env, jclass UNUSED(clazz), jint handle, jstring string) |
|
39 |
JNIEXPORT void JNICALL Java_com_ibm_ugl_eswt_OS_Button_1SetLabel(JNIEnv* env, jclass UNUSED(clazz), jint handle, jstring string) |
36 |
{ |
|
40 |
{ |
37 |
UGL_ErrorStruct error; |
|
41 |
UGL_ErrorStruct error; |
38 |
const jchar* stringCharData; |
|
42 |
const jchar* stringCharData; |
39 |
jint stringLength; |
|
43 |
jint stringLength; |
40 |
UGL_Boolean stringShouldFree; |
|
44 |
UGL_Boolean stringShouldFree; |
41 |
UGL_String uglstring; |
|
45 |
UGL_String uglstring; |
42 |
|
|
46 |
|
43 |
stringCharData = GetStringChars(env, string); |
|
47 |
stringCharData = GetStringChars(env, string); |
44 |
if (ExceptionCheck(env)) return ; |
|
48 |
if (ExceptionCheck(env)) return ; |
45 |
stringLength = GetStringLength(env, string); |
|
49 |
stringLength = GetStringLength(env, string); |
46 |
uglstring = convertToNativeString(stringCharData, stringLength, &stringShouldFree); |
|
50 |
uglstring = convertToNativeString(stringCharData, stringLength, &stringShouldFree); |
47 |
error.error_code = 0; |
|
51 |
error.error_code = 0; |
48 |
|
|
52 |
|
49 |
#ifdef debug_print |
|
53 |
#ifdef debug_print |
50 |
APITRACE(env, "Entering - Button_SetLabel\n"); |
|
54 |
APITRACE(env, "Entering - Button_SetLabel\n"); |
51 |
APIARGTRACE(env, "\thandle=%d\n" , handle); |
|
55 |
APIARGTRACE(env, "\thandle=%d\n" , handle); |
52 |
APITRACE(env, "\tstringCharData="); |
|
56 |
APITRACE(env, "\tstringCharData="); |
53 |
{ |
|
57 |
{ |
54 |
int i; |
|
58 |
int i; |
55 |
for (i=0; i<stringLength; i++) APIARGTRACE(env, "%c" , stringCharData[i]); |
|
59 |
for (i=0; i<stringLength; i++) APIARGTRACE(env, "%c" , stringCharData[i]); |
56 |
} |
|
60 |
} |
57 |
APITRACE(env, "\n"); |
|
61 |
APITRACE(env, "\n"); |
58 |
#endif |
|
62 |
#endif |
59 |
|
|
63 |
|
60 |
Button_SetLabel(handle, uglstring, &error); |
|
64 |
Button_SetLabel(handle, uglstring, &error); |
61 |
if (stringShouldFree) freeNativeString(uglstring); |
|
65 |
if (stringShouldFree) freeNativeString(uglstring); |
62 |
ReleaseStringChars(env, string, stringCharData); |
|
66 |
ReleaseStringChars(env, string, stringCharData); |
63 |
if (error.error_code == 0) { |
|
67 |
if (error.error_code == 0) { |
64 |
return; |
|
68 |
return; |
65 |
} else { |
|
69 |
} else { |
66 |
UGL_ErrorHandler(env, "Button_SetLabel", &error); |
|
70 |
UGL_ErrorHandler(env, "Button_SetLabel", &error); |
67 |
} |
|
71 |
} |
68 |
} |
|
72 |
} |
69 |
|
|
73 |
|
70 |
/** |
|
74 |
/** |
71 |
* Set the selection state of a button. |
|
75 |
* Set the selection state of a button. |
72 |
*/ |
|
76 |
*/ |
73 |
JNIEXPORT void JNICALL Java_com_ibm_ugl_eswt_OS_Button_1SetSelection(JNIEnv* env, jclass UNUSED(clazz), jint handle, jboolean selection) |
|
77 |
JNIEXPORT void JNICALL Java_com_ibm_ugl_eswt_OS_Button_1SetSelection(JNIEnv* env, jclass UNUSED(clazz), jint handle, jboolean selection) |
74 |
{ |
|
78 |
{ |
75 |
UGL_ErrorStruct error; |
|
79 |
UGL_ErrorStruct error; |
76 |
UGL_Boolean nativeselection; |
|
80 |
UGL_Boolean nativeselection; |
77 |
|
|
81 |
|
78 |
nativeselection = convertToNativeBoolean(env, selection); |
|
82 |
nativeselection = convertToNativeBoolean(env, selection); |
79 |
error.error_code = 0; |
|
83 |
error.error_code = 0; |
80 |
|
|
84 |
|
81 |
#ifdef debug_print |
|
85 |
#ifdef debug_print |
82 |
APITRACE(env, "Entering - Button_SetSelection\n"); |
|
86 |
APITRACE(env, "Entering - Button_SetSelection\n"); |
83 |
APIARGTRACE(env, "\thandle=%d\n" , handle); |
|
87 |
APIARGTRACE(env, "\thandle=%d\n" , handle); |
84 |
APIARGTRACE(env, "\tnativeselection=%d\n" , nativeselection); |
|
88 |
APIARGTRACE(env, "\tnativeselection=%d\n" , nativeselection); |
85 |
#endif |
|
89 |
#endif |
86 |
|
|
90 |
|
87 |
Button_SetSelection(handle, nativeselection, &error); |
|
91 |
Button_SetSelection(handle, nativeselection, &error); |
88 |
if (error.error_code == 0) { |
|
92 |
if (error.error_code == 0) { |
89 |
return; |
|
93 |
return; |
90 |
} else { |
|
94 |
} else { |
91 |
UGL_ErrorHandler(env, "Button_SetSelection", &error); |
|
95 |
UGL_ErrorHandler(env, "Button_SetSelection", &error); |
92 |
} |
|
96 |
} |
93 |
} |
|
97 |
} |
94 |
|
|
98 |
|
95 |
/** |
|
99 |
/** |
|
|
<> |
100 |
* Get the selection state of a button. |
|
|
|
101 |
*/ |
|
|
|
102 |
JNIEXPORT jboolean JNICALL Java_com_ibm_ugl_eswt_OS_Button_1GetSelection(JNIEnv* env, jclass UNUSED(clazz), jint handle) |
|
|
|
103 |
{ |
|
|
|
104 |
UGL_ErrorStruct error; |
|
|
|
105 |
UGL_Boolean nativeselection; |
|
|
|
106 |
|
|
|
|
107 |
error.error_code = 0; |
|
|
|
108 |
|
|
|
|
109 |
#ifdef debug_print |
|
|
|
110 |
APITRACE(env, "Entering - Button_GetSelection\n"); |
|
|
|
111 |
APIARGTRACE(env, "\thandle=%d\n" , handle); |
|
|
|
112 |
#endif |
|
|
|
113 |
|
|
|
|
114 |
nativeselection = Button_GetSelection(handle, &error); |
|
|
|
115 |
|
|
|
|
116 |
if (error.error_code == 0) { |
|
|
|
117 |
return convertToJavaBoolean(env, nativeselection); |
|
|
|
118 |
} else { |
|
|
|
119 |
UGL_ErrorHandler(env, "Button_GetSelection", &error); |
|
|
|
120 |
return JNI_FALSE; |
|
|
|
121 |
} |
|
|
|
122 |
} |
|
|
|
123 |
|
|
|
|
124 |
/** |
96 |
* Creates a new Checkbox widget |
= |
125 |
* Creates a new Checkbox widget |
97 |
*/ |
|
126 |
*/ |
98 |
JNIEXPORT jint JNICALL Java_com_ibm_ugl_eswt_OS_Checkbox_1New(JNIEnv* env, jclass UNUSED(clazz), jint parentHandle, jint style) |
|
127 |
JNIEXPORT jint JNICALL Java_com_ibm_ugl_eswt_OS_Checkbox_1New(JNIEnv* env, jclass UNUSED(clazz), jint parentHandle, jint style) |
99 |
{ |
|
128 |
{ |
100 |
UGL_ErrorStruct error; |
|
129 |
UGL_ErrorStruct error; |
101 |
UGL_Int returnValue; |
|
130 |
UGL_Int returnValue; |
102 |
|
|
131 |
|
103 |
error.error_code = 0; |
|
132 |
error.error_code = 0; |
104 |
|
|
133 |
|
105 |
#ifdef debug_print |
|
134 |
#ifdef debug_print |
106 |
APITRACE(env, "Entering - Checkbox_New\n"); |
|
135 |
APITRACE(env, "Entering - Checkbox_New\n"); |
107 |
APIARGTRACE(env, "\tparentHandle=%d\n" , parentHandle); |
|
136 |
APIARGTRACE(env, "\tparentHandle=%d\n" , parentHandle); |
108 |
APIARGTRACE(env, "\tstyle=%d\n" , style); |
|
137 |
APIARGTRACE(env, "\tstyle=%d\n" , style); |
109 |
#endif |
|
138 |
#endif |
110 |
|
|
139 |
|
111 |
returnValue = Checkbox_New(parentHandle, style, &error); |
|
140 |
returnValue = Checkbox_New(parentHandle, style, &error); |
112 |
if (error.error_code == 0) { |
|
141 |
if (error.error_code == 0) { |
113 |
return returnValue; |
|
142 |
return returnValue; |
114 |
} else { |
|
143 |
} else { |
115 |
UGL_ErrorHandler(env, "Checkbox_New", &error); |
|
144 |
UGL_ErrorHandler(env, "Checkbox_New", &error); |
116 |
return 0; |
|
145 |
return 0; |
117 |
} |
|
146 |
} |
118 |
} |
|
147 |
} |
119 |
|
|
148 |
|
120 |
/** |
|
149 |
/** |
121 |
* Create a new PushButton widget |
|
150 |
* Create a new PushButton widget |
122 |
*/ |
|
151 |
*/ |
123 |
JNIEXPORT jint JNICALL Java_com_ibm_ugl_eswt_OS_PushButton_1New(JNIEnv* env, jclass UNUSED(clazz), jint parentHandle, jint style) |
|
152 |
JNIEXPORT jint JNICALL Java_com_ibm_ugl_eswt_OS_PushButton_1New(JNIEnv* env, jclass UNUSED(clazz), jint parentHandle, jint style) |
124 |
{ |
|
153 |
{ |
125 |
UGL_ErrorStruct error; |
|
154 |
UGL_ErrorStruct error; |
126 |
UGL_Int returnValue; |
|
155 |
UGL_Int returnValue; |
127 |
|
|
156 |
|
128 |
error.error_code = 0; |
|
157 |
error.error_code = 0; |
129 |
|
|
158 |
|
130 |
#ifdef debug_print |
|
159 |
#ifdef debug_print |
131 |
APITRACE(env, "Entering - PushButton_New\n"); |
|
160 |
APITRACE(env, "Entering - PushButton_New\n"); |
132 |
APIARGTRACE(env, "\tparentHandle=%d\n" , parentHandle); |
|
161 |
APIARGTRACE(env, "\tparentHandle=%d\n" , parentHandle); |
133 |
APIARGTRACE(env, "\tstyle=%d\n" , style); |
|
162 |
APIARGTRACE(env, "\tstyle=%d\n" , style); |
134 |
#endif |
|
163 |
#endif |
135 |
|
|
164 |
|
136 |
returnValue = PushButton_New(parentHandle, style, &error); |
|
165 |
returnValue = PushButton_New(parentHandle, style, &error); |
137 |
if (error.error_code == 0) { |
|
166 |
if (error.error_code == 0) { |
138 |
return returnValue; |
|
167 |
return returnValue; |
139 |
} else { |
|
168 |
} else { |
140 |
UGL_ErrorHandler(env, "PushButton_New", &error); |
|
169 |
UGL_ErrorHandler(env, "PushButton_New", &error); |
141 |
return 0; |
|
170 |
return 0; |
142 |
} |
|
171 |
} |
143 |
} |
|
172 |
} |
144 |
|
|
173 |
|
145 |
/** |
|
174 |
/** |
146 |
* Create a new RadioButton widget |
|
175 |
* Create a new RadioButton widget |
147 |
*/ |
|
176 |
*/ |
148 |
JNIEXPORT jint JNICALL Java_com_ibm_ugl_eswt_OS_RadioButton_1New(JNIEnv* env, jclass UNUSED(clazz), jint parentHandle, jint style) |
|
177 |
JNIEXPORT jint JNICALL Java_com_ibm_ugl_eswt_OS_RadioButton_1New(JNIEnv* env, jclass UNUSED(clazz), jint parentHandle, jint style) |
149 |
{ |
|
178 |
{ |
150 |
UGL_ErrorStruct error; |
|
179 |
UGL_ErrorStruct error; |
151 |
UGL_Int returnValue; |
|
180 |
UGL_Int returnValue; |
152 |
|
|
181 |
|
153 |
error.error_code = 0; |
|
182 |
error.error_code = 0; |
154 |
|
|
183 |
|
155 |
#ifdef debug_print |
|
184 |
#ifdef debug_print |
156 |
APITRACE(env, "Entering - RadioButton_New\n"); |
|
185 |
APITRACE(env, "Entering - RadioButton_New\n"); |
157 |
APIARGTRACE(env, "\tparentHandle=%d\n" , parentHandle); |
|
186 |
APIARGTRACE(env, "\tparentHandle=%d\n" , parentHandle); |
158 |
APIARGTRACE(env, "\tstyle=%d\n" , style); |
|
187 |
APIARGTRACE(env, "\tstyle=%d\n" , style); |
159 |
#endif |
|
188 |
#endif |
160 |
|
|
189 |
|
161 |
returnValue = RadioButton_New(parentHandle, style, &error); |
|
190 |
returnValue = RadioButton_New(parentHandle, style, &error); |
162 |
if (error.error_code == 0) { |
|
191 |
if (error.error_code == 0) { |
163 |
return returnValue; |
|
192 |
return returnValue; |
164 |
} else { |
|
193 |
} else { |
165 |
UGL_ErrorHandler(env, "RadioButton_New", &error); |
|
194 |
UGL_ErrorHandler(env, "RadioButton_New", &error); |
166 |
return 0; |
|
195 |
return 0; |
167 |
} |
|
196 |
} |
168 |
} |
|
197 |
} |
169 |
|
|
198 |
|
170 |
|
|
199 |
|
171 |
|
|
200 |
|
172 |
/** |
|
201 |
/** |
173 |
* Sets the position of the label or image on the button. |
|
202 |
* Sets the position of the label or image on the button. |
174 |
* On left to right locales, STYLE_LEAD is left, and STYLE_TRAIL |
|
203 |
* On left to right locales, STYLE_LEAD is left, and STYLE_TRAIL |
175 |
* is right. Right to left locales reverse this notation. |
|
204 |
* is right. Right to left locales reverse this notation. |
176 |
*/ |
|
205 |
*/ |
177 |
JNIEXPORT void JNICALL Java_com_ibm_ugl_eswt_OS_Button_1SetAlignment(JNIEnv* env, jclass UNUSED(clazz), jint handle, jint alignment) |
|
206 |
JNIEXPORT void JNICALL Java_com_ibm_ugl_eswt_OS_Button_1SetAlignment(JNIEnv* env, jclass UNUSED(clazz), jint handle, jint alignment) |
178 |
{ |
|
207 |
{ |
179 |
UGL_ErrorStruct error; |
|
208 |
UGL_ErrorStruct error; |
180 |
|
|
209 |
|
181 |
error.error_code = 0; |
|
210 |
error.error_code = 0; |
182 |
|
|
211 |
|
183 |
#ifdef debug_print |
|
212 |
#ifdef debug_print |
184 |
APITRACE(env, "Entering - Button_SetAlignment\n"); |
|
213 |
APITRACE(env, "Entering - Button_SetAlignment\n"); |
185 |
APIARGTRACE(env, "\thandle=%d\n" , handle); |
|
214 |
APIARGTRACE(env, "\thandle=%d\n" , handle); |
186 |
APIARGTRACE(env, "\talignment=%d\n" , alignment); |
|
215 |
APIARGTRACE(env, "\talignment=%d\n" , alignment); |
187 |
#endif |
|
216 |
#endif |
188 |
|
|
217 |
|
189 |
Button_SetAlignment(handle, alignment, &error); |
|
218 |
Button_SetAlignment(handle, alignment, &error); |
190 |
if (error.error_code == 0) { |
|
219 |
if (error.error_code == 0) { |
191 |
return; |
|
220 |
return; |
192 |
} else { |
|
221 |
} else { |
193 |
UGL_ErrorHandler(env, "Button_SetAlignment", &error); |
|
222 |
UGL_ErrorHandler(env, "Button_SetAlignment", &error); |
194 |
} |
|
223 |
} |
195 |
} |
|
224 |
} |
196 |
|
|
225 |
|
197 |
/** |
|
226 |
/** |
198 |
* Sets the image of a button. Please note that a button may not display |
|
227 |
* Sets the image of a button. Please note that a button may not display |
199 |
* its image and its label simultaneously. |
|
228 |
* its image and its label simultaneously. |
200 |
*/ |
|
229 |
*/ |
201 |
JNIEXPORT void JNICALL Java_com_ibm_ugl_eswt_OS_Button_1SetImage(JNIEnv* env, jclass UNUSED(clazz), jint handle, jint imageHandle) |
|
230 |
JNIEXPORT void JNICALL Java_com_ibm_ugl_eswt_OS_Button_1SetImage(JNIEnv* env, jclass UNUSED(clazz), jint handle, jint imageHandle) |
202 |
{ |
|
231 |
{ |
203 |
UGL_ErrorStruct error; |
|
232 |
UGL_ErrorStruct error; |
204 |
|
|
233 |
|
205 |
error.error_code = 0; |
|
234 |
error.error_code = 0; |
206 |
|
|
235 |
|
207 |
#ifdef debug_print |
|
236 |
#ifdef debug_print |
208 |
APITRACE(env, "Entering - Button_SetImage\n"); |
|
237 |
APITRACE(env, "Entering - Button_SetImage\n"); |
209 |
APIARGTRACE(env, "\thandle=%d\n" , handle); |
|
238 |
APIARGTRACE(env, "\thandle=%d\n" , handle); |
210 |
APIARGTRACE(env, "\timageHandle=%d\n" , imageHandle); |
|
239 |
APIARGTRACE(env, "\timageHandle=%d\n" , imageHandle); |
211 |
#endif |
|
240 |
#endif |
212 |
|
|
241 |
|
213 |
Button_SetImage(handle, imageHandle, &error); |
|
242 |
Button_SetImage(handle, imageHandle, &error); |
214 |
if (error.error_code == 0) { |
|
243 |
if (error.error_code == 0) { |
215 |
return; |
|
244 |
return; |
216 |
} else { |
|
245 |
} else { |
217 |
UGL_ErrorHandler(env, "Button_SetImage", &error); |
|
246 |
UGL_ErrorHandler(env, "Button_SetImage", &error); |
218 |
} |
|
247 |
} |
219 |
} |
|
248 |
} |
220 |
|
|
249 |
|
221 |
/** |
|
250 |
/** |
222 |
* Create a new ToggleButton widget |
|
251 |
* Create a new ToggleButton widget |
223 |
*/ |
|
252 |
*/ |
224 |
JNIEXPORT jint JNICALL Java_com_ibm_ugl_eswt_OS_ToggleButton_1New(JNIEnv* env, jclass UNUSED(clazz), jint parentHandle, jint style) |
|
253 |
JNIEXPORT jint JNICALL Java_com_ibm_ugl_eswt_OS_ToggleButton_1New(JNIEnv* env, jclass UNUSED(clazz), jint parentHandle, jint style) |
225 |
{ |
|
254 |
{ |
226 |
UGL_ErrorStruct error; |
|
255 |
UGL_ErrorStruct error; |
227 |
UGL_Int returnValue; |
|
256 |
UGL_Int returnValue; |
228 |
|
|
257 |
|
229 |
error.error_code = 0; |
|
258 |
error.error_code = 0; |
230 |
|
|
259 |
|
231 |
#ifdef debug_print |
|
260 |
#ifdef debug_print |
232 |
APITRACE(env, "Entering - ToggleButton_New\n"); |
|
261 |
APITRACE(env, "Entering - ToggleButton_New\n"); |
233 |
APIARGTRACE(env, "\tparentHandle=%d\n" , parentHandle); |
|
262 |
APIARGTRACE(env, "\tparentHandle=%d\n" , parentHandle); |
234 |
APIARGTRACE(env, "\tstyle=%d\n" , style); |
|
263 |
APIARGTRACE(env, "\tstyle=%d\n" , style); |
235 |
#endif |
|
264 |
#endif |
236 |
|
|
265 |
|
237 |
returnValue = ToggleButton_New(parentHandle, style, &error); |
|
266 |
returnValue = ToggleButton_New(parentHandle, style, &error); |
238 |
if (error.error_code == 0) { |
|
267 |
if (error.error_code == 0) { |
239 |
return returnValue; |
|
268 |
return returnValue; |
240 |
} else { |
|
269 |
} else { |
241 |
UGL_ErrorHandler(env, "ToggleButton_New", &error); |
|
270 |
UGL_ErrorHandler(env, "ToggleButton_New", &error); |
242 |
return 0; |
|
271 |
return 0; |
243 |
} |
|
272 |
} |
244 |
} |
|
273 |
} |
245 |
|
|
274 |
|
246 |
|
|
275 |
|
247 |
#ifdef __cplusplus |
|
276 |
#ifdef __cplusplus |
248 |
} |
|
277 |
} |
249 |
#endif |
|
278 |
#endif |
250 |
|
|
279 |
|