comparison lib/Canna.c @ 17:688ac5040e7d

imported patch 20_kinput2-v3.1-canna-keybind2.patch
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Mon, 08 Mar 2010 20:38:17 +0900
parents 1f1719e33c62
children
comparison
equal deleted inserted replaced
16:598fcbe482b5 17:688ac5040e7d
57 #include <X11/keysym.h> 57 #include <X11/keysym.h>
58 #if XtSpecificationRelease > 4 58 #if XtSpecificationRelease > 4
59 #include <X11/Xfuncs.h> 59 #include <X11/Xfuncs.h>
60 #endif 60 #endif
61 #include "CannaP.h" 61 #include "CannaP.h"
62 #include "ParseKey.h"
62 #include "DebugPrint.h" 63 #include "DebugPrint.h"
63 64
64 /* Canna 3.7$B0J9_$O$3$N$h$&$KDj5A$9$k(B */ 65 /* Canna 3.7$B0J9_$O$3$N$h$&$KDj5A$9$k(B */
65 #define CANNA_WCHAR16 66 #define CANNA_WCHAR16
66 #define CANNA_NEW_WCHAR_AWARE 67 #define CANNA_NEW_WCHAR_AWARE
77 { XtNcannafile, XtCCannafile, XtRString, sizeof(String), 78 { XtNcannafile, XtCCannafile, XtRString, sizeof(String),
78 offset(cannafile), XtRString, NULL }, 79 offset(cannafile), XtRString, NULL },
79 { XtNsendReturnByString, XtCSendReturnByString, 80 { XtNsendReturnByString, XtCSendReturnByString,
80 XtRBoolean, sizeof(Boolean), 81 XtRBoolean, sizeof(Boolean),
81 offset(sendReturnByString), XtRBoolean, False }, 82 offset(sendReturnByString), XtRBoolean, False },
83 { XtNkeyBackslashAlwaysShifted, XtCKeyBackslashAlwaysShifted,
84 XtRBoolean, sizeof(Boolean),
85 offset(keyBackslashAlwaysShifted), XtRBoolean, False },
86 { XtNconversionEndKeys, XtCConversionEndKeys, XtRString, sizeof(String),
87 offset(conversion_end_keys), XtRImmediate, NULL }
82 #undef offset 88 #undef offset
83 }; 89 };
84 90
85 static void ClassInitialize(); 91 static void ClassInitialize();
86 static void Initialize(), Destroy(); 92 static void Initialize(), Destroy();
209 /* $B2?$b$7$J$$(B */ 215 /* $B2?$b$7$J$$(B */
210 } 216 }
211 217
212 static int 218 static int
213 XKanaLookup(event_struct, buffer_return, bytes_buffer, 219 XKanaLookup(event_struct, buffer_return, bytes_buffer,
214 keysym, status_return) 220 keysym, status_return, bs_flag)
215 XKeyEvent *event_struct; 221 XKeyEvent *event_struct;
216 char *buffer_return; 222 char *buffer_return;
217 int bytes_buffer; 223 int bytes_buffer;
218 KeySym *keysym; 224 KeySym *keysym;
219 XComposeStatus *status_return; 225 XComposeStatus *status_return;
226 int bs_flag;
220 { 227 {
221 int res; 228 int res;
222 res = XLookupString(event_struct, buffer_return, bytes_buffer, 229 res = XLookupString(event_struct, buffer_return, bytes_buffer,
223 keysym, status_return); 230 keysym, status_return);
231 if ( res == 1 && bs_flag ) {
232 /* $B$+$JF~NO$G!V!<!W$,F~NO$G$-$k$h$&$K(B */
233 if ( *keysym == XK_backslash && event_struct->keycode == 123 ) {
234 buffer_return[0] = '_';
235 }
236 }
224 if (!res && XK_overline <= *keysym && *keysym <= XK_semivoicedsound) { 237 if (!res && XK_overline <= *keysym && *keysym <= XK_semivoicedsound) {
225 buffer_return[0] = (unsigned long)(*keysym) & 0xff; 238 buffer_return[0] = (unsigned long)(*keysym) & 0xff;
226 res = 1; 239 res = 1;
227 } 240 }
228 return res; 241 return res;
246 259
247 obj->canna.textchanged = False; 260 obj->canna.textchanged = False;
248 261
249 /* $B<h$j$"$($:J8;z$KD>$7$F$7$^$&(B */ 262 /* $B<h$j$"$($:J8;z$KD>$7$F$7$^$&(B */
250 kanabuf[0] = '\0'; 263 kanabuf[0] = '\0';
251 nbytes = XKanaLookup(event, kanabuf, 20, &ks, &compose_status); 264 nbytes = XKanaLookup(event, kanabuf, 20, &ks, &compose_status,
265 obj->canna.keyBackslashAlwaysShifted);
252 266
253 buf[0] = (wchar)kanabuf[0]; /* $B$-$?$J$$(B */ 267 buf[0] = (wchar)kanabuf[0]; /* $B$-$?$J$$(B */
254 268
255 if (ks == XK_space && (event->xkey.state & ShiftMask)) { 269 if ( obj->canna.conv_end_key_list != NULL ) {
270 cKeyList *listelem;
271 for ( listelem=obj->canna.conv_end_key_list; listelem!=NULL; listelem=listelem->next ) {
272 if (ks == listelem->ksym && event->xkey.state == listelem->mods) {
273 void convend();
274
275 convend(obj);
276 return 0;
277 }
278 }
279 } else if (ks == XK_space && (event->xkey.state & ShiftMask)) {
256 void convend(); 280 void convend();
257 281
258 convend(obj); 282 convend(obj);
259 return 0; 283 return 0;
260 } 284 }
619 obj->canna.cursymbol = 0; 643 obj->canna.cursymbol = 0;
620 obj->canna.candlist = NULL; 644 obj->canna.candlist = NULL;
621 obj->canna.candlistsize = 0; 645 obj->canna.candlistsize = 0;
622 obj->canna.numcand = 0; 646 obj->canna.numcand = 0;
623 obj->canna.lastTextLengthIsZero = False; 647 obj->canna.lastTextLengthIsZero = False;
648 obj->canna.conv_end_key_list = NULL;
649
650 if ( obj->canna.conversion_end_keys != NULL ) {
651 char *p = obj->canna.conversion_end_keys;
652 char *buf = NULL;
653 size_t buf_size = 0;
654 cKeyList *prev_key_listelem = NULL, *new_key_listelem;
655
656 while ( *p != '\0' ) {
657 KeySym ksym;
658 long mods, chk_mods;
659 unsigned int comp_len;
660
661 comp_len = strcspn( p, "\n" ) + 1;
662 if ( buf_size < comp_len ) {
663 buf = XtRealloc( buf, comp_len * sizeof(char) );
664 buf_size = comp_len;
665 }
666 memcpy( buf, p, comp_len );
667 buf[comp_len - 1] = '\0';
668
669 if ( ParseKeyEvent( buf, &ksym, &mods, &chk_mods ) ) {
670 new_key_listelem = (cKeyList *)XtMalloc( sizeof(cKeyList) );
671 new_key_listelem->ksym = ksym;
672 new_key_listelem->mods = mods;
673 new_key_listelem->chk_mods = chk_mods;
674 new_key_listelem->next = NULL;
675 if ( prev_key_listelem == NULL ) {
676 obj->canna.conv_end_key_list = new_key_listelem;
677 } else {
678 prev_key_listelem->next = new_key_listelem;
679 }
680 prev_key_listelem = new_key_listelem;
681 }
682 p += comp_len;
683 }
684 if ( buf != NULL ) XtFree( (char *)buf );
685 }
624 686
625 ibufInitialize(obj); 687 ibufInitialize(obj);
626 688
627 /* $BJQ49$N=i4|2=(B */ 689 /* $BJQ49$N=i4|2=(B */
628 initializeCannaConnection(obj); 690 initializeCannaConnection(obj);
715 wcKanjiStatus ks; 777 wcKanjiStatus ks;
716 wchar buf[512]; 778 wchar buf[512];
717 int i; 779 int i;
718 780
719 /* $B%P%C%U%!$N2rJ|(B */ 781 /* $B%P%C%U%!$N2rJ|(B */
782 if ( obj->canna.conv_end_key_list != NULL ) {
783 cKeyList *listelem = obj->canna.conv_end_key_list;
784 while ( listelem != NULL) {
785 cKeyList *next_elem = listelem->next;
786 XtFree( (char*)listelem );
787 listelem = next_elem;
788 }
789 }
720 790
721 freeIBuf(obj->canna.ibuf); 791 freeIBuf(obj->canna.ibuf);
722 792
723 if (obj->canna.candlist) { 793 if (obj->canna.candlist) {
724 for (i = 0 ; i < obj->canna.candlistsize ; i++) { 794 for (i = 0 ; i < obj->canna.candlistsize ; i++) {