Back to index

im-sdk  12.3.91
sampleja2.cpp
Go to the documentation of this file.
00001 /*
00002 Copyright 1990-2001 Sun Microsystems, Inc. All Rights Reserved.
00003 
00004 Permission is hereby granted, free of charge, to any person obtaining a
00005 copy of this software and associated documentation files (the
00006 "Software"), to deal in the Software without restriction, including
00007 without limitation the rights to use, copy, modify, merge, publish,
00008 distribute, sublicense, and/or sell copies of the Software, and to
00009 permit persons to whom the Software is furnished to do so, subject to
00010 the following conditions: The above copyright notice and this
00011 permission notice shall be included in all copies or substantial
00012 portions of the Software.
00013 
00014 
00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00016 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00017 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00018 IN NO EVENT SHALL THE OPEN GROUP OR SUN MICROSYSTEMS, INC. BE LIABLE
00019 FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
00020 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
00021 THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE EVEN IF
00022 ADVISED IN ADVANCE OF THE POSSIBILITY OF SUCH DAMAGES.
00023 
00024 
00025 Except as contained in this notice, the names of The Open Group and/or
00026 Sun Microsystems, Inc. shall not be used in advertising or otherwise to
00027 promote the sale, use or other dealings in this Software without prior
00028 written authorization from The Open Group and/or Sun Microsystems,
00029 Inc., as applicable.
00030 
00031 
00032 X Window System is a trademark of The Open Group
00033 
00034 OSF/1, OSF/Motif and Motif are registered trademarks, and OSF, the OSF
00035 logo, LBX, X Window System, and Xinerama are trademarks of the Open
00036 Group. All other trademarks and registered trademarks mentioned herein
00037 are the property of their respective owners. No right, title or
00038 interest in or to any trademark, service mark, logo or trade name of
00039 Sun Microsystems, Inc. or its licensors is granted.
00040 
00041 */
00042 #ifdef WIN32
00043 #include <windows.h>
00044 #endif
00045 
00046 #include <stdio.h>
00047 #include <stdlib.h>
00048 #include <string.h>
00049 #include <sys/types.h>
00050 
00051 #include "SunIM.h"
00052 
00053 Bool if_sampleja2_OpenIF(iml_if_t *);
00054 Bool if_sampleja2_CloseIF(iml_if_t *);
00055 Bool if_sampleja2_GetIFValue(iml_if_t *, IMArgList, int);
00056 Bool if_sampleja2_SetIFValue(iml_if_t *, IMArgList, int);
00057 Bool if_sampleja2_OpenDesktop(iml_desktop_t *, IMArgList, int);
00058 Bool if_sampleja2_CloseDesktop(iml_desktop_t *);
00059 Bool if_sampleja2_CreateSC(iml_session_t *, IMArgList, int);
00060 Bool if_sampleja2_DestroySC(iml_session_t *);
00061 Bool if_sampleja2_GetSCValue(iml_session_t *, IMArgList, int);
00062 Bool if_sampleja2_SetSCValue(iml_session_t *, IMArgList, int);
00063 IMText *if_sampleja2_ResetSC(iml_session_t *);
00064 void if_sampleja2_SetSCFocus(iml_session_t *);
00065 void if_sampleja2_UnsetSCFocus(iml_session_t *);
00066 void if_sampleja2_SendEvent(iml_session_t *, IMInputEvent * ev);
00067 
00068 /* IF Method */
00069 if_methods_t sampleja_methods = {
00070     if_sampleja2_OpenIF,
00071     if_sampleja2_CloseIF,
00072     if_sampleja2_GetIFValue,
00073     if_sampleja2_SetIFValue,
00074     if_sampleja2_OpenDesktop,
00075     if_sampleja2_CloseDesktop,
00076     if_sampleja2_CreateSC,
00077     if_sampleja2_DestroySC,
00078     if_sampleja2_GetSCValue,
00079     if_sampleja2_SetSCValue,
00080     if_sampleja2_ResetSC,
00081     if_sampleja2_SetSCFocus,
00082     if_sampleja2_UnsetSCFocus,
00083     if_sampleja2_SendEvent
00084 };
00085 
00086 UTFCHAR lename_string[] = {0x30b5, 0x30f3, 0x30d7, 0x30eb, 0x65e5, 0x672c, 0x8a9e, 0x30a8, 0x30f3, 0x30b8, 0x30f3, 0x0};
00087 UTFCHAR jahrn_string[] = {0x65e5, 0x672c, 0x8a9e, 0x0};
00088 
00089 static IMLEName lename = {
00090     "sampleja2", lename_string     /* LE id, HRN */
00091 };
00092 
00093 static IMLocale locales[] = {
00094     {"ja", jahrn_string},   /* locale id, HRN */
00095     NULL
00096 };
00097 
00098 
00099 extern "C" {
00100 
00101 #ifdef WIN32
00102 #define EXPORT extern __declspec(dllexport)
00103 
00104 EXPORT
00105 #endif
00106 
00107 void
00108 if_GetIfInfo(
00109     IMArgList args,
00110     int num_args
00111 )
00112 {
00113     int i;
00114     for (i = 0; i < num_args; i++, args++) {
00115         switch (args->id) {
00116             case IF_VERSION:
00117                 args->value = (IMArgVal) "1.2";
00118                 break;
00119             case IF_METHOD_TABLE:
00120                 args->value = (IMArgVal) & sampleja_methods;
00121                 break;
00122             case IF_LE_NAME:
00123                 args->value = (IMArgVal) & lename;
00124                 break;
00125             case IF_SUPPORTED_LOCALES:
00126                 args->value = (IMArgVal) & locales;
00127                 break;
00128             case IF_NEED_THREAD_LOCK:
00129                 args->value = (IMArgVal) False;
00130                 break;
00131             default:
00132                 break;
00133             }
00134     }
00135 }
00136 
00137 }
00138 
00139 static int UTFCHARCpy(UTFCHAR *, UTFCHAR *);
00140 static int UTFCHARLen(UTFCHAR *);
00141 static IMFeedbackList *create_feedback(iml_session_t * s, int size);
00142 static void my_conversion_on(iml_session_t *);
00143 static void my_conversion_off(iml_session_t *);
00144 
00145 #define       DEBUG
00146 
00147 Bool
00148 if_sampleja2_OpenIF(
00149     iml_if_t * If
00150 )
00151 {
00152 #ifdef DEBUG
00153     printf("if_sampleja2_OpenIF()\n");
00154     printf("  If=[%x]\n", If);
00155     printf("  locale=[%s]\n", If->locale);
00156     printf("  if_name=[%s]\n", If->if_name);
00157 #endif
00158     return True;
00159 }
00160 
00161 Bool
00162 if_sampleja2_CloseIF(
00163     iml_if_t * If
00164 )
00165 {
00166 #ifdef DEBUG
00167     printf("if_sampleja2_CloseIF()\n");
00168     printf("  If=[%x]\n", If);
00169     printf("  locale=[%s]\n", If->locale);
00170     printf("  if_name=[%s]\n", If->if_name);
00171 #endif
00172     return True;
00173 }
00174 
00175 Bool
00176 if_sampleja2_GetIFValue(
00177     iml_if_t * If,
00178     IMArgList args,
00179     int num_args
00180 )
00181 {
00182 #ifdef DEBUG
00183     printf("if_sampleja2_GetIFValue()\n");
00184     printf("  If=[%x]\n", If);
00185     printf("  locale=[%s]\n", If->locale);
00186     printf("  if_name=[%s]\n", If->if_name);
00187 #endif
00188     return True;
00189 }
00190 
00191 Bool
00192 if_sampleja2_SetIFValue(
00193     iml_if_t * If,
00194     IMArgList args,
00195     int num_args
00196 )
00197 {
00198     int i;
00199 #ifdef DEBUG
00200     printf("if_sampleja2_SetIFValue()\n");
00201     printf("  If=[%x]\n", If);
00202     printf("  locale=[%s]\n", If->locale);
00203     printf("  if_name=[%s]\n", If->if_name);
00204 #endif
00205     return True;
00206 }
00207 
00208 Bool
00209 if_sampleja2_OpenDesktop(
00210     iml_desktop_t * desktop,
00211     IMArgList args,
00212     int num_args
00213 )
00214 {
00215 #ifdef DEBUG
00216     printf("if_sampleja2_OpenDesktop()\n");
00217     printf("  If=[%x]\n", desktop->If);
00218     printf("  desktop=[%x]\n", desktop);
00219     printf("  locale=[%s]\n", desktop->If->locale);
00220     printf("  if_name=[%s]\n", desktop->If->if_name);
00221     printf("  USER:%s\n", desktop->user_name);
00222     printf("  HOST:%s\n", desktop->host_name);
00223     printf("  DISPLAY:%s\n", desktop->display_id);
00224 #endif
00225     return True;
00226 }
00227 
00228 Bool
00229 if_sampleja2_CloseDesktop(
00230     iml_desktop_t * desktop
00231 )
00232 {
00233 #ifdef DEBUG
00234     printf("if_sampleja2_CloseDesktop()\n");
00235     printf("  If=[%x]\n", desktop->If);
00236     printf("  desktop=[%x]\n", desktop);
00237     printf("  locale=[%s]\n", desktop->If->locale);
00238     printf("  if_name=[%s]\n", desktop->If->if_name);
00239     printf("  USER:%s\n", desktop->user_name);
00240     printf("  HOST:%s\n", desktop->host_name);
00241     printf("  DISPLAY:%s\n", desktop->display_id);
00242 #endif
00243     return True;
00244 }
00245 
00246 Bool
00247 if_sampleja2_CreateSC(
00248     iml_session_t *s,
00249     IMArgList args,
00250     int num_args
00251 )
00252 {
00253     iml_desktop_t *desktop = s->desktop;
00254 #ifdef DEBUG
00255     printf("if_sampleja2_CreateSC()\n");
00256     printf("  If=[%x]\n", desktop->If);
00257     printf("  desktop=[%x]\n", desktop);
00258     printf("  locale=[%s]\n", desktop->If->locale);
00259     printf("  if_name=[%s]\n", desktop->If->if_name);
00260     printf("  USER:%s\n", desktop->user_name);
00261     printf("  HOST:%s\n", desktop->host_name);
00262     printf("  DISPLAY:%s\n", desktop->display_id);
00263 #endif
00264     return True;
00265 }
00266 
00267 Bool
00268 if_sampleja2_DestroySC(
00269     iml_session_t * s
00270 )
00271 {
00272 #ifdef DEBUG
00273     printf("if_sampleja2_DestroySC(s=%x)\n", s);
00274     printf("  s=[%x]\n", s);
00275     printf("  If=[%x]\n", s->desktop->If);
00276     printf("  desktop=[%x]\n", s->desktop);
00277     printf("  locale=[%s]\n", s->desktop->If->locale);
00278     printf("  if_name=[%s]\n", s->desktop->If->if_name);
00279     printf("  USER:%s\n", s->desktop->user_name);
00280     printf("  HOST:%s\n", s->desktop->host_name);
00281 #endif
00282     return True;
00283 }
00284 
00285 Bool
00286 if_sampleja2_GetSCValue(
00287     iml_session_t * s,
00288     IMArgList args,
00289     int num_args
00290 )
00291 {
00292     int i;
00293     IMArg *p = args;
00294     
00295     static int charsubset[] = {
00296         67,                 /* LATIN */
00297         47,                 /* HIRAGANA */
00298         48,                 /* KATAKANA */
00299         71,                 /* KANJI */
00300         0
00301     };
00302     
00303 #ifdef DEBUG
00304     printf("if_sampleja2_GetSCValue(s=%x)\n", s);
00305     printf("  s=[%x]\n", s);
00306     printf("  If=[%x]\n", s->desktop->If);
00307     printf("  desktop=[%x]\n", s->desktop);
00308     printf("  locale=[%s]\n", s->desktop->If->locale);
00309     printf("  if_name=[%s]\n", s->desktop->If->if_name);
00310     printf("  USER:%s\n", s->desktop->user_name);
00311     printf("  HOST:%s\n", s->desktop->host_name);
00312 #endif
00313     for (i = 0; i < num_args; i++, p++) {
00314         switch (p->id) {
00315             case SC_SUPPORTED_CHARACTER_SUBSETS:
00316                 /* specify CHARACTER_SUBSETS */
00317                 p->value = (IMArgVal) charsubset;
00318                 break;
00319             default:
00320                 break;
00321             }
00322     }
00323     return True;
00324 }
00325 
00326 UTFCHAR on_string[] = {0x65e5, 0x672c, 0x8a9e, 0x30aa, 0x30f3, 0};
00327 UTFCHAR off_string[] = {0x65e5, 0x672c, 0x8a9e, 0x30aa, 0x30d5, 0};
00328 
00329 static void
00330 my_conversion_on(
00331     iml_session_t * s
00332 )
00333 {
00334     iml_inst *lp;
00335     iml_inst *rrv = NULL;
00336     
00337     lp = s->If->m->iml_make_start_conversion_inst(s);
00338     s->If->m->iml_link_inst_tail(&rrv, lp);
00339 
00340     IMText *p = (IMText *) s->If->m->iml_new(s, sizeof(IMText));
00341     p->encoding = UTF16_CODESET;
00342     p->char_length = UTFCHARLen(on_string);
00343     p->text.utf_chars = (UTFCHAR *) s->If->m->iml_new(s, sizeof(UTFCHAR) * (p->char_length + 1));
00344     UTFCHARCpy(p->text.utf_chars, on_string);
00345     p->feedback = create_feedback(s, p->char_length);
00346 
00347     lp = s->If->m->iml_make_status_draw_inst(s, p);
00348     s->If->m->iml_link_inst_tail(&rrv, lp);
00349 
00350     s->If->m->iml_execute(s, &rrv);
00351 }
00352 
00353 static void
00354 my_conversion_off(
00355     iml_session_t * s
00356 )
00357 {
00358     iml_inst *lp;
00359     iml_inst *rrv = NULL;
00360     
00361     lp = s->If->m->iml_make_end_conversion_inst(s);
00362 
00363     s->If->m->iml_link_inst_tail(&rrv, lp);
00364 
00365     IMText *p = (IMText *) s->If->m->iml_new(s, sizeof(IMText));
00366     p->encoding = UTF16_CODESET; 
00367     p->char_length = UTFCHARLen(off_string);
00368     p->text.utf_chars = (UTFCHAR *) s->If->m->iml_new(s, sizeof(UTFCHAR) * (p->char_length + 1));
00369     UTFCHARCpy(p->text.utf_chars, off_string);
00370     p->feedback = create_feedback(s, p->char_length);
00371 
00372     lp = s->If->m->iml_make_status_draw_inst(s, p);
00373     s->If->m->iml_link_inst_tail(&rrv, lp);
00374 
00375     s->If->m->iml_execute(s, &rrv);
00376 }
00377 
00378 Bool
00379 if_sampleja2_SetSCValue(
00380     iml_session_t * s,
00381     IMArgList args,
00382     int num_args
00383 )
00384 {
00385     int i;
00386     IMArg *p = args;
00387 #ifdef DEBUG
00388     printf("if_sampleja2_SetSCValue()\n");
00389     printf("  s=[%x]\n", s);
00390     printf("  If=[%x]\n", s->desktop->If);
00391     printf("  desktop=[%x]\n", s->desktop);
00392     printf("  locale=[%s]\n", s->desktop->If->locale);
00393     printf("  if_name=[%s]\n", s->desktop->If->if_name);
00394     printf("  USER:%s\n", s->desktop->user_name);
00395     printf("  HOST:%s\n", s->desktop->host_name);
00396 #endif
00397     for (i = 0; i < num_args; i++, p++) {
00398         switch (p->id) {
00399             case SC_TRIGGER_ON_NOTIFY:
00400                 printf("conversion on\n");
00401                 my_conversion_on(s);
00402                 break;
00403                 
00404             case SC_TRIGGER_OFF_NOTIFY:
00405                 printf("conversion off\n");
00406                 my_conversion_off(s);
00407                 break;
00408                 
00409             case SC_REALIZE:
00410                 break;
00411             default:
00412                 break;
00413             }
00414     }
00415     return True;
00416 }
00417 
00418 IMText *
00419 if_sampleja2_ResetSC(
00420     iml_session_t * s
00421 )
00422 {
00423 #ifdef DEBUG
00424     printf("if_sampleja2_ResetSC(s=%x)\n", s);
00425     printf("  s=[%x]\n", s);
00426     printf("  If=[%x]\n", s->desktop->If);
00427     printf("  desktop=[%x]\n", s->desktop);
00428     printf("  locale=[%s]\n", s->desktop->If->locale);
00429     printf("  if_name=[%s]\n", s->desktop->If->if_name);
00430     printf("  USER:%s\n", s->desktop->user_name);
00431     printf("  HOST:%s\n", s->desktop->host_name);
00432     printf("  DISPLAY:%s\n", s->desktop->display_id);
00433 #endif
00434     return (IMText *) NULL;
00435 }
00436 
00437 void
00438 if_sampleja2_SetSCFocus(
00439     iml_session_t * s
00440 )
00441 {
00442 #ifdef DEBUG
00443     printf("if_sampleja2_SetSCFocus()\n");
00444     printf("  s=[%x]\n", s);
00445     printf("  If=[%x]\n", s->desktop->If);
00446     printf("  desktop=[%x]\n", s->desktop);
00447     printf("  locale=[%s]\n", s->desktop->If->locale);
00448     printf("  if_name=[%s]\n", s->desktop->If->if_name);
00449     printf("  USER:%s\n", s->desktop->user_name);
00450     printf("  HOST:%s\n", s->desktop->host_name);
00451     printf("  DISPLAY:%s\n", s->desktop->display_id);
00452 #endif
00453 }
00454 
00455 void
00456 if_sampleja2_UnsetSCFocus(
00457     iml_session_t * s
00458 )
00459 {
00460 #ifdef DEBUG
00461     printf("if_sampleja2_UnsetSCFocus()\n");
00462     printf("  s=[%x]\n", s);
00463     printf("  If=[%x]\n", s->desktop->If);
00464     printf("  desktop=[%x]\n", s->desktop);
00465     printf("  locale=[%s]\n", s->desktop->If->locale);
00466     printf("  if_name=[%s]\n", s->desktop->If->if_name);
00467     printf("  USER:%s\n", s->desktop->user_name);
00468     printf("  HOST:%s\n", s->desktop->host_name);
00469     printf("  DISPLAY:%s\n", s->desktop->display_id);
00470 #endif
00471 }
00472 
00473 void
00474 if_sampleja2_SendEvent(
00475     iml_session_t * s,
00476     IMInputEvent * ev
00477 )
00478 {
00479 #ifdef DEBUG
00480     printf("if_sampleja2_SendEvent s=%x ev=%x\n", s, ev);
00481 #endif
00482     if (ev) {
00483         if (ev->type == IM_EventKeyList) {
00484         } else if (ev->type == IM_EventString) {
00485               /* receive operation list */
00486               IMStringEvent *stringev=(IMStringEvent*)ev;
00487         } else if (ev->type == IM_EventAux) {
00488         } else if (ev->type == IM_EventString) {
00489         } else if (ev->type == IM_EventText) {
00490         }
00491     }
00492 }
00493 
00494 int
00495 UTFCHARCpy(
00496     UTFCHAR * dest,
00497     UTFCHAR * original
00498 )
00499 {
00500     int i;
00501     for (i = 0; *original; i++) {
00502         *dest++ = *original++;
00503     }
00504     *dest = 0;
00505     return i;
00506 }
00507 
00508 int
00509 UTFCHARLen(
00510     UTFCHAR * p
00511 )
00512 {
00513     int i;
00514     for (i = 0; *p; i++)
00515     p++;
00516     return i;
00517 }
00518 
00519 static IMFeedbackList *
00520 create_feedback(
00521     iml_session_t * s,
00522     int size
00523 )
00524 {
00525     int i;
00526     IMFeedbackList *feedback, *fbl;
00527     IMFeedback *fb;
00528 
00529     if (s) {
00530         feedback = (IMFeedbackList *) s->If->m->iml_new(s, sizeof(IMFeedbackList) * size);
00531     } else {
00532         feedback = (IMFeedbackList *) calloc(1, sizeof(IMFeedbackList) * size);
00533     }
00534     for (i = 0; i < size; i++) {
00535         IMFeedbackList *fbl = &feedback[i];
00536         fbl->count_feedbacks = 1;
00537         if (s) {
00538             fb = fbl->feedbacks = (IMFeedback *) s->If->m->iml_new(s, sizeof(IMFeedback));
00539         } else {
00540             fb = fbl->feedbacks = (IMFeedback *) calloc(1, sizeof(IMFeedback));
00541         }
00542         memset(fbl->feedbacks, 0, sizeof(IMFeedback));
00543     }
00544     return feedback;
00545 }