listeners.c

Go to the documentation of this file.
00001 
00015 #include "listeners.h"
00016 
00017 #ifdef __cplusplus
00018 extern "C" {
00019 #endif
00020 
00022 #define CLS_CBWINDOWLISTENER "at/fhv/sgr/guilib/listeners/CBWindowListener"
00023 
00025 #define CLS_CBMOUSELISTENER "at/fhv/sgr/guilib/listeners/CBMouseListener"
00026 
00028 #define CLS_CBCOMPONENTLISTENER "at/fhv/sgr/guilib/listeners/CBComponentListener"
00029 
00031 #define CLS_CBACTIONLISTENER "at/fhv/sgr/guilib/listeners/CBActionListener"
00032 
00034 #define CLS_CBITEMLISTENER "at/fhv/sgr/guilib/listeners/CBItemListener"
00035 
00046 void cbWindowListener(JNIEnv* env, jobject jobj, jlong ptr, jint event, jobject window) {
00047    void (*func)(jint, jobject) = (void (*)(jint, jobject))ptr;
00048    func(event, window);
00049 }
00050 
00066 WindowListener addWindowListener(jobject obj, void (*func)(jint, Window)) {
00067    static jclass cbwinlist = NULL;
00068    jobject wl = NULL;
00069 
00070    if (cbwinlist == NULL) {
00071       JNINativeMethod nm;
00072 
00073       nm.name = "cbWindowListener"; /* method name */
00074       nm.signature = "(JILjava/awt/Window;)V"; /* method signature */
00075       nm.fnPtr = (void*)&cbWindowListener; /* pointer of function to register */
00076 
00077       cbwinlist = findClass(CLS_CBWINDOWLISTENER);
00078       registerNatives(cbwinlist, &nm, 1);
00079    }
00080    
00081    wl = newObjectBySignature(cbwinlist, "(J)V", (jlong) func);
00082    
00083    callVoidMethodByName(obj, "addWindowListener", "(Ljava/awt/event/WindowListener;)V", wl);
00084 
00085    exception();
00086 
00087    return wl;
00088 }
00089 
00099 void removeWindowListener(jobject obj, WindowListener wl) {
00100    callVoidMethodByName(obj, "removeWindowListener", "(Ljava/awt/event/WindowListener;)V", wl);
00101 
00102    deleteGlobalReference(wl);
00103 
00104    exception();
00105 }
00106 
00117 void cbComponentListener(JNIEnv *env, jobject jobj, jlong ptr, jint event, jobject source) {
00118    void (*func)(jint, jobject) = (void (*)(jint, jobject))ptr;
00119    func(event, source);
00120 }
00121 
00137 ComponentListener addComponentListener(jobject obj, void (*func)(jint, Component)) {
00138    static jclass cbcomplist = NULL;
00139    jobject cl = NULL;
00140 
00141    if (cbcomplist == NULL) {
00142       JNINativeMethod nm;
00143 
00144       nm.name = "cbComponentListener"; /* method name */
00145       nm.signature = "(JILjava/lang/Object;)V"; /* method signature */
00146       nm.fnPtr = (void*)&cbComponentListener; /* pointer of function to register */
00147 
00148       cbcomplist = findClass(CLS_CBCOMPONENTLISTENER);
00149       registerNatives(cbcomplist, &nm, 1);
00150    }
00151    
00152    cl = newObjectBySignature(cbcomplist, "(J)V", (jlong) func);
00153    
00154    callVoidMethodByName(obj, "addComponentListener", "(Ljava/awt/event/ComponentListener;)V", cl);
00155 
00156    exception();
00157 
00158    return cl;
00159 }
00160 
00170 void removeComponentListener(jobject obj, ComponentListener cl) {
00171    callVoidMethodByName(obj, "removeComponentListener", "(Ljava/awt/event/ComponentListener;)V", cl);
00172 
00173    deleteGlobalReference(cl);
00174 
00175    exception();
00176 }
00177 
00192 void cbMouseListener(JNIEnv* env, jobject jobj, jlong ptr, jint event, jobject window, jint x, jint y, jint button, jint clickCount) {
00193    void (*func)(jint, jobject, jint, jint, jint, jint) = (void (*)(jint, jobject, jint, jint, jint, jint))ptr;
00194    func(event, window, x, y, button, clickCount);
00195 }
00196 
00216 MouseListener addMouseListener(jobject obj, void (*func)(jint, Component, jint, jint, jint, jint)) {
00217    static jclass cbmouselist = NULL;
00218    jobject ml = NULL;
00219 
00220    if (cbmouselist == NULL) {
00221       JNINativeMethod nm;
00222 
00223       nm.name = "cbMouseListener"; /* method name */
00224       nm.signature = "(JILjava/lang/Object;IIII)V"; /* method signature */
00225       nm.fnPtr = (void*)&cbMouseListener; /* pointer of function to register */
00226 
00227       cbmouselist = findClass(CLS_CBMOUSELISTENER);
00228       registerNatives(cbmouselist, &nm, 1);
00229    }
00230    
00231    ml = newObjectBySignature(cbmouselist, "(J)V", (jlong) func);
00232 
00233    callVoidMethodByName(obj, "addMouseListener", "(Ljava/awt/event/MouseListener;)V", ml);
00234 
00235    exception();
00236 
00237    return ml;
00238 }
00239 
00249 void removeMouseListener(jobject obj, MouseListener ml) {
00250    callVoidMethodByName(obj, "removeMouseListener", "(Ljava/awt/event/MouseListener;)V", ml);
00251 
00252    deleteGlobalReference(ml);
00253 
00254    exception();
00255 }
00256 
00266 void cbActionListener(JNIEnv* env, jobject jobj, jlong ptr, jobject source) {
00267    void (*func)(jobject) = (void (*)(jobject))ptr;
00268    func(source);
00269 }
00270 
00285 ActionListener addActionListener(jobject obj, void (*func)(Component)) {
00286    static jclass cbactlist = NULL;
00287    jobject al = NULL;
00288 
00289    if (cbactlist == NULL) {
00290       JNINativeMethod nm;
00291 
00292       nm.name = "cbActionListener"; /* method name */
00293       nm.signature = "(JLjava/lang/Object;)V"; /* method signature */
00294       nm.fnPtr = (void*)&cbActionListener; /* pointer of function to register */
00295 
00296       cbactlist = findClass(CLS_CBACTIONLISTENER);
00297       registerNatives(cbactlist, &nm, 1);
00298    }
00299    
00300    al = newObjectBySignature(cbactlist, "(J)V", (jlong) func);
00301    
00302    callVoidMethodByName(obj, "addActionListener", "(Ljava/awt/event/ActionListener;)V", al);
00303 
00304    exception();
00305 
00306    return al;
00307 }
00308 
00318 void removeActionListener(jobject obj, ActionListener al) {
00319    callVoidMethodByName(obj, "removeActionListener", "(Ljava/awt/event/ActionListener;)V", al);
00320 
00321    deleteGlobalReference(al);
00322 
00323    exception();
00324 }
00325 
00337 void cbItemListener(JNIEnv* env, jobject jobj, jlong ptr, jobject source, jboolean selected, jobject item) {
00338    void (*func)(jobject, jboolean, const char*) = (void (*)(jobject, jboolean, const char*))ptr;
00339    char* itemtext = convertJString((jstring) callObjectMethodByName(item, "toString", "()Ljava/lang/String;"));
00340    func(source, selected, itemtext);
00341 }
00342 
00359 ItemListener addItemListener(jobject obj, void (*func)(Component, jboolean, const char*)) {
00360    static jclass cbitemlist = NULL;
00361    jobject il = NULL;
00362 
00363    if (cbitemlist == NULL) {
00364       JNINativeMethod nm;
00365 
00366       nm.name = "cbItemListener"; /* method name */
00367       nm.signature = "(JLjava/lang/Object;ZLjava/lang/Object;)V"; /* method signature */
00368       nm.fnPtr = (void*)&cbItemListener; /* pointer of function to register */
00369 
00370       cbitemlist = findClass(CLS_CBITEMLISTENER);
00371       registerNatives(cbitemlist, &nm, 1);
00372    }
00373    
00374    il = newObjectBySignature(cbitemlist, "(J)V", (jlong) func);
00375 
00376    callVoidMethodByName(obj, "addItemListener", "(Ljava/awt/event/ItemListener;)V", il);
00377 
00378    exception();
00379 
00380    return il;
00381 }
00382 
00392 void removeItemListener(jobject obj, ItemListener il) {
00393    callVoidMethodByName(obj, "removeItemListener", "(Ljava/awt/event/ItemListener;)V", il);
00394 
00395    deleteGlobalReference(il);
00396 
00397    exception();
00398 }
00399 
00400 #ifdef __cplusplus
00401 } /* extern "C" */
00402 #endif
00403 
00404 /* end of file listeners.c */

Generated on Sat Nov 19 14:11:11 2005 for GrubC by  doxygen 1.4.4