1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905
|
#ifndef lint
static char *rcsid = "$Id: imconv.c,v 1.18 1999/05/18 08:53:23 ishisone Exp $";
#endif
/*
* Copyright (c) 1991, 1994 Software Research Associates, Inc.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose and without fee is hereby granted, provided
* that the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of Software Research Associates not be
* used in advertising or publicity pertaining to distribution of the
* software without specific, written prior permission. Software Research
* Associates makes no representations about the suitability of this software
* for any purpose. It is provided "as is" without express or implied
* warranty.
*
* Author: Makoto Ishisone, Software Research Associates, Inc., Japan
*/
#include "im.h"
#include "ConvMgr.h"
#include "OverConv.h"
#include "OffConv.h"
#include "OnConv.h"
#include "InputConv.h"
static void fillDefaultAttributesForStartup _Pt_((IMIC *icp));
static unsigned long makeConvAttributesForStartup _Pt_((IMIC *icp,
ConversionAttributes *attrp));
static void commitString _Pt_((IMIC *icp, char *str, int len, int sync));
static void fixCallback _Pt_((Widget w, XtPointer client_data,
XtPointer call_data));
static void detachConverter _Pt_((IMIC *icp));
static void endCallback _Pt_((Widget w, XtPointer client_data,
XtPointer call_data));
static void unusedEventCallback _Pt_((Widget w, XtPointer client_data,
XtPointer call_data));
static void preeditStartCallback _Pt_((Widget w, XtPointer client_data,
XtPointer call_data));
static void preeditDoneCallback _Pt_((Widget w, XtPointer client_data,
XtPointer call_data));
static void preeditDrawCallback _Pt_((Widget w, XtPointer client_data,
XtPointer call_data));
static void preeditCaretCallback _Pt_((Widget w, XtPointer client_data,
XtPointer call_data));
static void statusStartCallback _Pt_((Widget w, XtPointer client_data,
XtPointer call_data));
static void statusDoneCallback _Pt_((Widget w, XtPointer client_data,
XtPointer call_data));
static void statusDrawCallback _Pt_((Widget w, XtPointer client_data,
XtPointer call_data));
static void preeditStart _Pt_((IMIC *icp));
static void preeditDone _Pt_((IMIC *icp));
static void preeditDraw _Pt_((IMIC *icp, OCCPreeditDrawArg *data));
static void preeditCaret _Pt_((IMIC *icp, int caret));
static void statusStart _Pt_((IMIC *icp));
static void statusDone _Pt_((IMIC *icp));
static void statusDraw _Pt_((IMIC *icp, OCCPreeditDrawArg *data));
/*- fillDefaultAttributesForStartup: put default necessary for conv. start -*/
static void
fillDefaultAttributesForStartup(icp)
IMIC *icp;
{
unsigned long cmask, pmask, smask;
cmask = ATTR_MASK_FOCUS;
switch (icp->style) {
case IMSTYLE_OVER_THE_SPOT:
pmask = ATTR_MASK_FOREGROUND | ATTR_MASK_BACKGROUND |
ATTR_MASK_FONT_SET;
smask = 0;
break;
case IMSTYLE_OFF_THE_SPOT:
pmask = ATTR_MASK_FOREGROUND | ATTR_MASK_BACKGROUND |
ATTR_MASK_FONT_SET | ATTR_MASK_AREA;
smask = ATTR_MASK_AREA;
break;
case IMSTYLE_ON_THE_SPOT:
pmask = 0;
smask = 0;
break;
default:
pmask = 0;
smask = 0;
}
IMFillDefault(icp, cmask, pmask, smask);
}
/*- makeConvAttributesForStartup: get conv. attrs needed for startup -*/
static unsigned long
makeConvAttributesForStartup(icp, attrp)
IMIC *icp;
ConversionAttributes *attrp;
{
icp->common_attr.change_mask = icp->common_attr.set_mask;
icp->preedit_attr.change_mask = icp->preedit_attr.set_mask;
icp->status_attr.change_mask = icp->status_attr.set_mask;
return IMMakeConvAttributes(icp, attrp);
}
/*- commitString: commmit converted string to client -*/
static void
commitString(icp, str, len, sync)
IMIC *icp;
char *str;
int len;
int sync;
{
int offset;
IMConnection *conn = icp->im->connection;
unsigned int flag;
TRACE(("imlib:commitString()\n"));
if (DDEBUG_CONDITION(5)) {
unsigned char *p = (unsigned char *)str;
int i;
/*
* Dump commiting string.
*/
printf("* commit string:\n\t");
for (i = 0; i < len; i++, p++) {
if (*p == '\033') {
printf("ESC ");
} else if (*p < ' ') {
printf("^%c ", *p + '@');
} else if (*p == ' ') {
printf("sp ");
} else if (*p >= 0x7f) {
printf("%x ", *p);
} else {
printf("%c ", *p);
}
}
printf("\n");
}
flag = XIM_FLAG_X_LOOKUP_CHARS;
if (sync) flag |= XIM_FLAG_SYNCHRONOUS;
offset = IMPutHeader(conn, XIM_COMMIT, 0, 0);
IMPutC16(conn, icp->im->id);
IMPutC16(conn, icp->id);
IMPutC16(conn, flag);
IMPutC16(conn, (unsigned int)len);
IMPutString(conn, str, len);
IMFinishRequest(conn, offset);
}
/*- fixCallback: fix callback -*/
/* ARGSUSED */
static void
fixCallback(w, client_data, call_data)
Widget w;
XtPointer client_data;
XtPointer call_data;
{
IMIC *icp = (IMIC *)client_data;
IMConnection *conn = icp->im->connection;
Widget proto = conn->proto_widget;
Atom ctext = IMCtextAtom(proto);
CCTextCallbackArg *arg = (CCTextCallbackArg *)call_data;
TRACE(("imlib:fixCallback()\n"));
/* check encoding and format */
if (arg->encoding != ctext || arg->format != 8) {
/*
* since every conversion object must support COMPOUND_TEXT,
* it is a serious error.
*/
String params[2];
Cardinal num_params;
WidgetClass ioc = icp->im->converter->input_object_class;
params[0] = XtClass(proto)->core_class.class_name;
params[1] = ioc->core_class.class_name;
num_params = 2;
XtAppErrorMsg(XtWidgetToApplicationContext(proto),
"encodingError", "convertedString", "WidgetError",
"%s: encoding of the converted string is not COMPOUND_STRING. check inputObject %s",
params, &num_params);
}
/*
* Send fixed string via XIM_COMMIT message.
* Since kinput2 uses full-synchronous mode,
* synchronous flag must be turned off.
*/
commitString(icp, arg->text, arg->length, 0);
}
/*- detachConverter: detach conversion widget from specified IC -*/
static void
detachConverter(icp)
IMIC *icp;
{
Widget conv;
TRACE(("imlib:detachConverter()\n"));
conv = icp->conversion;
XtRemoveCallback(conv, XtNtextCallback, fixCallback, (XtPointer)icp);
XtRemoveCallback(conv, XtNendCallback, endCallback, (XtPointer)icp);
XtRemoveCallback(conv, XtNunusedEventCallback, unusedEventCallback, (XtPointer)icp);
if (icp->style == IMSTYLE_ON_THE_SPOT) {
XtRemoveCallback(conv, XtNpreeditStartCallback, preeditStartCallback,
(XtPointer)icp);
XtRemoveCallback(conv, XtNpreeditDoneCallback, preeditDoneCallback,
(XtPointer)icp);
XtRemoveCallback(conv, XtNpreeditDrawCallback, preeditDrawCallback,
(XtPointer)icp);
XtRemoveCallback(conv, XtNpreeditCaretCallback, preeditCaretCallback,
(XtPointer)icp);
XtRemoveCallback(conv, XtNstatusStartCallback, statusStartCallback,
(XtPointer)icp);
XtRemoveCallback(conv, XtNstatusDoneCallback, statusDoneCallback,
(XtPointer)icp);
XtRemoveCallback(conv, XtNstatusDrawCallback, statusDrawCallback,
(XtPointer)icp);
}
CMReleaseConverter(XtParent(icp->im->connection->proto_widget), conv);
icp->conversion = NULL;
}
/*- endCallback: conversion end callback -*/
/* ARGSUSED */
static void
endCallback(w, client_data, call_data)
Widget w;
XtPointer client_data;
XtPointer call_data;
{
IMIC *icp = (IMIC *)client_data;
TRACE(("imlib:endCallback()\n"));
if (icp->state & IC_CONVERTING) {
detachConverter(icp);
icp->state &= ~IC_CONVERTING;
}
}
/*- unusedEventCallback: unused key event callback -*/
/* ARGSUSED */
static void
unusedEventCallback(w, client_data, call_data)
Widget w;
XtPointer client_data;
XtPointer call_data;
{
IMIC *icp = (IMIC *)client_data;
IMConnection *conn = icp->im->connection;
XKeyEvent *ev = (XKeyEvent *)call_data;
int offset;
TRACE(("imlib:unusedEventCallback()\n"));
if (icp->im->mask & XIM_EXT_FORWARD_KEYEVENT_MASK) {
offset = IMPutHeader(conn, XIM_EXT_FORWARD_KEYEVENT, 0, 0);
IMPutC16(conn, icp->im->id);
IMPutC16(conn, icp->id);
IMPutC16(conn, 0);
IMPutC16(conn, (unsigned int)(ev->serial & 0xffff));
IMPutC8(conn, ev->type);
IMPutC8(conn, (int)ev->keycode);
IMPutC16(conn, (unsigned int)ev->state);
IMPutC32(conn, ev->time);
IMPutC32(conn, ev->window);
IMFinishRequest(conn, offset);
} else {
offset = IMPutHeader(conn, XIM_FORWARD_EVENT, 0, 0);
IMPutC16(conn, icp->im->id);
IMPutC16(conn, icp->id);
IMPutC16(conn, 0); /* ?? */
IMPutC16(conn, (unsigned int)((ev->serial >> 16) & 0xffff));
IMPutC8(conn, ev->type);
IMPutC8(conn, (int)ev->keycode);
IMPutC16(conn, (unsigned int)(ev->serial & 0xffff));
IMPutC32(conn, ev->time);
IMPutC32(conn, ev->root);
IMPutC32(conn, ev->window);
IMPutC32(conn, ev->subwindow);
IMPutI16(conn, ev->x_root);
IMPutI16(conn, ev->y_root);
IMPutI16(conn, ev->x);
IMPutI16(conn, ev->y);
IMPutC16(conn, ev->state);
IMPutC8(conn, ev->same_screen);
IMFinishRequest(conn, offset);
}
}
/*- preeditStartCallback: preedit start -*/
/* ARGSUSED */
static void
preeditStartCallback(w, client_data, call_data)
Widget w;
XtPointer client_data;
XtPointer call_data;
{
IMIC *icp = (IMIC *)client_data;
TRACE(("preeditStartCallback(icp=0x%lx)\n", icp));
if (!(icp->common_attr.input_style & XIMPreeditCallbacks))
return;
preeditStart(icp);
}
/*- preeditDoneCallback: preedit done -*/
/* ARGSUSED */
static void
preeditDoneCallback(w, client_data, call_data)
Widget w;
XtPointer client_data;
XtPointer call_data;
{
IMIC *icp = (IMIC *)client_data;
TRACE(("preeditDoneCallback(icp=0x%lx)\n", icp));
if (!(icp->common_attr.input_style & XIMPreeditCallbacks))
return;
preeditDone(icp);
}
/*- preeditDrawCallback: preedit draw -*/
/* ARGSUSED */
static void
preeditDrawCallback(w, client_data, call_data)
Widget w;
XtPointer client_data;
XtPointer call_data;
{
IMIC *icp = (IMIC *)client_data;
OCCPreeditDrawArg *arg = (OCCPreeditDrawArg *)call_data;
IMConnection *conn = icp->im->connection;
Widget proto = conn->proto_widget;
Atom ctext = IMCtextAtom(proto);
TRACE(("preeditDrawCallback(icp=0x%lx, length=%d)\n",icp,arg->text_length));
if (!(icp->common_attr.input_style & XIMPreeditCallbacks))
return;
/* check encoding and format */
if (arg->encoding != ctext || arg->format != 8) {
/*
* since every conversion object must support COMPOUND_TEXT,
* it is a serious error.
*/
String params[2];
Cardinal num_params;
WidgetClass ioc = icp->im->converter->input_object_class;
params[0] = XtClass(proto)->core_class.class_name;
params[1] = ioc->core_class.class_name;
num_params = 2;
XtAppErrorMsg(XtWidgetToApplicationContext(proto),
"encodingError", "preeditString", "WidgetError",
"%s: encoding of the preedit string is not COMPOUND_STRING. check inputObject %s",
params, &num_params);
}
preeditDraw(icp, arg);
}
/*- preeditCaretCallback: preedit caret -*/
/* ARGSUSED */
static void
preeditCaretCallback(w, client_data, call_data)
Widget w;
XtPointer client_data;
XtPointer call_data;
{
IMIC *icp = (IMIC *)client_data;
int caret = (int)call_data;
TRACE(("preeditCaretCallback(icp=0x%lx, caret=%d)\n", icp, caret));
if (!(icp->common_attr.input_style & XIMPreeditCallbacks))
return;
preeditCaret(icp, caret);
}
/*- statusStartCallback: status start -*/
/* ARGSUSED */
static void
statusStartCallback(w, client_data, call_data)
Widget w;
XtPointer client_data;
XtPointer call_data;
{
IMIC *icp = (IMIC *)client_data;
TRACE(("statusStartCallback(icp=0x%lx)\n", icp));
if (!(icp->common_attr.input_style & XIMStatusCallbacks))
return;
statusStart(icp);
}
/*- statusDoneCallback: status done -*/
/* ARGSUSED */
static void
statusDoneCallback(w, client_data, call_data)
Widget w;
XtPointer client_data;
XtPointer call_data;
{
IMIC *icp = (IMIC *)client_data;
TRACE(("statusDoneCallback(icp=0x%lx)\n", icp));
if (!(icp->common_attr.input_style & XIMStatusCallbacks))
return;
statusDone(icp);
}
/*- statusDrawCallback: status draw -*/
/* ARGSUSED */
static void
statusDrawCallback(w, client_data, call_data)
Widget w;
XtPointer client_data;
XtPointer call_data;
{
IMIC *icp = (IMIC *)client_data;
OCCPreeditDrawArg *arg = (OCCPreeditDrawArg *)call_data;
IMConnection *conn = icp->im->connection;
Widget proto = conn->proto_widget;
Atom ctext = IMCtextAtom(proto);
TRACE(("statusDrawCallback(icp=0x%lx, length=%d)\n", icp,arg->text_length));
if (!(icp->common_attr.input_style & XIMStatusCallbacks))
return;
/* check encoding and format */
if (arg->encoding != ctext || arg->format != 8) {
/*
* since every conversion object must support COMPOUND_TEXT,
* it is a serious error.
*/
String params[2];
Cardinal num_params;
WidgetClass ioc = icp->im->converter->input_object_class;
params[0] = XtClass(proto)->core_class.class_name;
params[1] = ioc->core_class.class_name;
num_params = 2;
XtAppErrorMsg(XtWidgetToApplicationContext(proto),
"encodingError", "statusString", "WidgetError",
"%s: encoding of the status string is not COMPOUND_STRING. check inputObject %s",
params, &num_params);
}
statusDraw(icp, arg);
}
/*- preeditStart: do preedit start -*/
static void
preeditStart(icp)
IMIC *icp;
{
if (!icp->in_preedit) {
int offset;
IMConnection *conn = icp->im->connection;
TRACE(("imlib:preeditStart()\n"));
offset = IMPutHeader(conn, XIM_PREEDIT_START, 0, 0);
IMPutC16(conn, icp->im->id);
IMPutC16(conn, icp->id);
IMFinishRequest(conn, offset);
icp->in_preedit = True;
}
}
/*- preeditDone: do preedit done -*/
static void
preeditDone(icp)
IMIC *icp;
{
if (icp->in_preedit) {
int offset;
IMConnection *conn = icp->im->connection;
TRACE(("imlib:preeditDone()\n"));
offset = IMPutHeader(conn, XIM_PREEDIT_DONE, 0, 0);
IMPutC16(conn, icp->im->id);
IMPutC16(conn, icp->id);
IMFinishRequest(conn, offset);
icp->in_preedit = False;
}
}
/*- preeditDraw: do actual preedit draw -*/
static void
preeditDraw(icp, data)
IMIC *icp;
OCCPreeditDrawArg *data;
{
IMConnection *conn = icp->im->connection;
int offset;
unsigned int status;
XIMFeedback feedback;
int i;
if (icp->resetting) return;
preeditStart(icp);
TRACE(("imlib:preeditDraw()\n"));
if (DDEBUG_CONDITION(5)) {
unsigned char *p = (unsigned char *)data->text;
/*
* Dump preedit string.
*/
printf("* preedit string:\n\t");
for (i = 0; i < data->text_length; i++, p++) {
if (*p == '\033') {
printf("ESC ");
} else if (*p < ' ') {
printf("^%c ", *p + '@');
} else if (*p == ' ') {
printf("sp ");
} else if (*p >= 0x7f) {
printf("%x ", *p);
} else {
printf("%c ", *p);
}
}
printf("\n");
}
offset = IMPutHeader(conn, XIM_PREEDIT_DRAW, 0, 0);
IMPutC16(conn, icp->im->id);
IMPutC16(conn, icp->id);
IMPutC32(conn, data->caret);
IMPutC32(conn, data->chg_first);
IMPutC32(conn, data->chg_length);
status = 0;
if (data->text_length == 0) status |= 0x1; /* no string */
if (data->attrs_length == 0) status |= 0x2; /* no feedback */
IMPutC32(conn, status);
IMPutC16(conn, (unsigned int)data->text_length);
if (data->text_length > 0) {
IMPutString(conn, data->text, data->text_length);
}
IMPutPad(conn);
IMPutC16(conn, (unsigned int)(data->attrs_length * 4));
IMPutC16(conn, 0L); /* unused */
if (data->attrs_length > 0) {
for (i = 0; i < data->attrs_length; i++) {
IMPutC32(conn, data->attrs[i]);
}
}
IMFinishRequest(conn, offset);
}
/*- preeditCaret: do actual preedit caret -*/
static void
preeditCaret(icp, caret)
IMIC *icp;
int caret;
{
IMConnection *conn = icp->im->connection;
int offset;
if (icp->resetting) return;
preeditStart(icp);
TRACE(("imlib:preeditCaret()\n"));
offset = IMPutHeader(conn, XIM_PREEDIT_CARET, 0, 0);
IMPutC16(conn, icp->im->id);
IMPutC16(conn, icp->id);
IMPutC32(conn, caret);
IMPutC32(conn, (long)XIMAbsolutePosition);
IMPutC32(conn, (long)XIMPrimary);
IMFinishRequest(conn, offset);
}
/*- statusStart: do status start -*/
static void
statusStart(icp)
IMIC *icp;
{
if (!icp->in_status) {
int offset;
IMConnection *conn = icp->im->connection;
TRACE(("imlib:statusStart()\n"));
offset = IMPutHeader(conn, XIM_STATUS_START, 0, 0);
IMPutC16(conn, icp->im->id);
IMPutC16(conn, icp->id);
IMFinishRequest(conn, offset);
icp->in_status = True;
}
}
/*- statusDone: do status done -*/
static void
statusDone(icp)
IMIC *icp;
{
if (icp->in_status) {
int offset;
IMConnection *conn = icp->im->connection;
TRACE(("imlib:statusDone()\n"));
offset = IMPutHeader(conn, XIM_STATUS_DONE, 0, 0);
IMPutC16(conn, icp->im->id);
IMPutC16(conn, icp->id);
IMFinishRequest(conn, offset);
icp->in_status = False;
}
}
/*- statusDraw: do actual status draw -*/
static void
statusDraw(icp, data)
IMIC *icp;
OCCPreeditDrawArg *data;
{
IMConnection *conn = icp->im->connection;
int offset;
unsigned int status;
if (icp->resetting) return;
statusStart(icp);
TRACE(("imlib:statusDraw()\n"));
offset = IMPutHeader(conn, XIM_STATUS_DRAW, 0, 0);
IMPutC16(conn, icp->im->id);
IMPutC16(conn, icp->id);
IMPutC32(conn, 0L); /* text type */
status = 0;
if (data->text_length == 0) status |= 0x1; /* no string */
if (data->attrs_length == 0) status |= 0x2; /* no feedback */
IMPutC32(conn, status);
IMPutC16(conn, (unsigned int)data->text_length);
if (data->text_length > 0) {
IMPutString(conn, data->text, data->text_length);
}
IMPutPad(conn);
IMPutC16(conn, (unsigned int)(data->attrs_length * 32));
IMPutC16(conn, 0L); /* unused */
if (data->attrs_length > 0) {
int i;
for (i = 0; i < data->attrs_length; i++) {
IMPutC32(conn, 0L);
}
}
IMFinishRequest(conn, offset);
}
/*
* Public functions
*/
int
IMStartConversion(icp)
IMIC *icp;
{
IMIM *imp = icp->im;
Widget proto = imp->connection->proto_widget;
Widget converter;
WidgetClass class;
unsigned long attrmask;
ConversionAttributes attrs;
TRACE(("IMStartConversion()\n"));
if (icp->state & IC_CONVERTING) return 0;
/*
* Check required attributes i.e. client window.
*/
if (!(icp->common_attr.set_mask & ATTR_MASK_CLIENT)) {
IMSendError(icp->im->connection, IMBadSomething, icp->im->id, icp->id,
"client window required");
return -1;
}
/*
* Fill in default values for unspecified attributes.
*/
fillDefaultAttributesForStartup(icp);
/*
* Get appropriate converter class.
*/
if (icp->style == IMSTYLE_OVER_THE_SPOT) {
class = overTheSpotConversionWidgetClass;
} else if (icp->style == IMSTYLE_OFF_THE_SPOT) {
class = offTheSpotConversionWidgetClass;
} else if (icp->style == IMSTYLE_ON_THE_SPOT) {
class = onTheSpotConversionWidgetClass;
} else {
class = separateConversionWidgetClass;
}
/*
* Compute conversion attributes to be passed to the converter.
*/
attrmask = makeConvAttributesForStartup(icp, &attrs);
icp->resetting = False;
/*
* Attach converter to this IC.
*/
converter = CMGetConverter(XtParent(proto),
icp->common_attr.client, class,
imp->converter->input_object_class,
imp->converter->display_object_class);
if (converter == NULL) {
IMSendError(imp->connection, IMBadSomething, imp->id, icp->id,
"can't attach converter to this IC");
return -1;
}
icp->conversion = converter;
/*
* Add callback functions.
*/
XtAddCallback(converter, XtNtextCallback, fixCallback, (XtPointer)icp);
XtAddCallback(converter, XtNendCallback, endCallback, (XtPointer)icp);
XtAddCallback(converter, XtNunusedEventCallback, unusedEventCallback, (XtPointer)icp);
if (icp->style == IMSTYLE_ON_THE_SPOT) {
XtAddCallback(converter, XtNpreeditStartCallback, preeditStartCallback,
(XtPointer)icp);
XtAddCallback(converter, XtNpreeditDoneCallback, preeditDoneCallback,
(XtPointer)icp);
XtAddCallback(converter, XtNpreeditDrawCallback, preeditDrawCallback,
(XtPointer)icp);
XtAddCallback(converter, XtNpreeditCaretCallback, preeditCaretCallback,
(XtPointer)icp);
XtAddCallback(converter, XtNstatusStartCallback, statusStartCallback,
(XtPointer)icp);
XtAddCallback(converter, XtNstatusDoneCallback, statusDoneCallback,
(XtPointer)icp);
XtAddCallback(converter, XtNstatusDrawCallback, statusDrawCallback,
(XtPointer)icp);
}
/*
* Start conversion
*/
/* !!! if front-end method is used, ESMethodSelectFocus should be used */
XtVaSetValues(converter, XtNeventSelectMethod, ESMethodNone, NULL);
CControlStartConversion(converter, icp->common_attr.client,
attrmask, &attrs);
icp->state |= IC_CONVERTING;
if (icp->common_attr.input_style & XIMPreeditCallbacks)
preeditStart(icp);
return 0;
}
void
IMStopConversion(icp)
IMIC *icp;
{
TRACE(("IMStopConversion()\n"));
if (!(icp->state & IC_CONVERTING)) return;
/*
* Terminate conversion.
*/
CControlEndConversion(icp->conversion);
if (icp->common_attr.input_style & XIMPreeditCallbacks)
preeditDone(icp);
IMStatusDone(icp);
/*
* Detach converter.
*/
detachConverter(icp);
icp->state &= ~IC_CONVERTING;
}
int
IMResetIC(icp, preedit_strp)
IMIC *icp;
char **preedit_strp;
{
int num_bytes = 0;
TRACE(("IMResetIC()\n"));
*preedit_strp = NULL;
if (icp->state & IC_CONVERTING) {
/*
* get input object by asking conversion widget of XtNinputObject
* resource. however, it is not recommended since protocol widget
* should interact with input object only through conversion
* widget.
*/
CCTextCallbackArg arg;
Widget input_obj;
Widget w = icp->im->connection->proto_widget;
XtVaGetValues(icp->conversion, XtNinputObject, &input_obj, NULL);
arg.encoding = IMCtextAtom(w);
if (ICGetConvertedString(input_obj, &arg.encoding, &arg.format,
&arg.length, &arg.text) >= 0) {
num_bytes = arg.length;
*preedit_strp = (char *)arg.text;
}
ICClearConversion(input_obj);
TRACE(("\twas converting. %d bytes left\n", num_bytes));
}
return num_bytes;
}
void
IMForwardEvent(icp, ev)
IMIC *icp;
XEvent *ev;
{
TRACE(("IMForwardEvent()\n"));
if (icp->conversion == NULL) return;
XtCallActionProc(icp->conversion, "to-inputobj", ev,
(String *)NULL, (Cardinal)0);
}
/* ARGSUSED */
void
IMSetFocus(icp)
IMIC *icp;
{
TRACE(("IMSetFocus(ic%d)\n", icp->id));
if (icp->conversion != NULL) {
CControlChangeFocus(icp->conversion, 1);
}
}
/* ARGSUSED */
void
IMUnsetFocus(icp)
IMIC *icp;
{
TRACE(("IMUnsetFocus(ic%d)\n", icp->id));
if (icp->conversion != NULL) {
CControlChangeFocus(icp->conversion, 0);
}
}
/* ARGSUSED */
void
IMStatusStart(icp)
IMIC *icp;
{
TRACE(("IMStatusStart(ic%d)\n", icp->id));
if (!(icp->common_attr.input_style & XIMStatusCallbacks))
return;
statusStart(icp);
}
/* ARGSUSED */
void
IMStatusDone(icp)
IMIC *icp;
{
TRACE(("IMStatusDone(ic%d)\n", icp->id));
if (!(icp->common_attr.input_style & XIMStatusCallbacks))
return;
statusDone(icp);
}
|