imRm.c revision eb411b4b
1/****************************************************************** 2 3 Copyright 1990, 1991, 1992,1993, 1994 by FUJITSU LIMITED 4 Copyright 1994 by Sony Corporation 5 6Permission to use, copy, modify, distribute, and sell this software 7and its documentation for any purpose is hereby granted without fee, 8provided that the above copyright notice appear in all copies and 9that both that copyright notice and this permission notice appear 10in supporting documentation, and that the name of FUJITSU LIMITED 11and Sony Corporation not be used in advertising or publicity 12pertaining to distribution of the software without specific, 13written prior permission. FUJITSU LIMITED and Sony Corporation make 14no representations about the suitability of this software for any 15purpose. It is provided "as is" without express or implied warranty. 16 17FUJITSU LIMITED AND SONY CORPORATION DISCLAIM ALL WARRANTIES WITH 18REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF 19MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL FUJITSU LIMITED AND 20SONY CORPORATION BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 21DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 22PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 23TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 24PERFORMANCE OF THIS SOFTWARE. 25 26 Author: Takashi Fujiwara FUJITSU LIMITED 27 fujiwara@a80.tech.yk.fujitsu.co.jp 28 Modifier: Makoto Wakamatsu Sony Corporation 29 makoto@sm.sony.co.jp 30 31******************************************************************/ 32 33#ifdef HAVE_CONFIG_H 34#include <config.h> 35#endif 36#include <stdio.h> 37#include <X11/Xlib.h> 38#include "Xlibint.h" 39#include "Xlcint.h" 40#include "Ximint.h" 41#include "Xresource.h" 42 43#define GET_NAME(x) name_table + x.name_offset 44 45typedef struct _XimValueOffsetInfo { 46 unsigned short name_offset; 47 XrmQuark quark; 48 unsigned int offset; 49 Bool (*defaults)( 50 struct _XimValueOffsetInfo *, XPointer, XPointer, unsigned long 51 ); 52 Bool (*encode)( 53 struct _XimValueOffsetInfo *, XPointer, XPointer 54 ); 55 Bool (*decode)( 56 struct _XimValueOffsetInfo *, XPointer, XPointer 57 ); 58} XimValueOffsetInfoRec, *XimValueOffsetInfo; 59 60#ifdef XIM_CONNECTABLE 61static Bool 62_XimCheckBool(str) 63 char *str; 64{ 65 if(!strcmp(str, "True") || !strcmp(str, "true") || 66 !strcmp(str, "Yes") || !strcmp(str, "yes") || 67 !strcmp(str, "ON") || !strcmp(str, "on")) 68 return True; 69 return False; 70} 71 72void 73_XimSetProtoResource(im) 74 Xim im; 75{ 76 char res_name_buf[256]; 77 char* res_name; 78 char res_class_buf[256]; 79 char* res_class; 80 char* str_type; 81 XrmValue value; 82 XIMStyle preedit_style = 0; 83 XIMStyle status_style = 0; 84 XIMStyles* imstyles; 85 char* dotximdot = ".xim."; 86 char* ximdot = "xim."; 87 char* dotXimdot = ".Xim."; 88 char* Ximdot = "Xim."; 89 90 if (!im->core.rdb) 91 return; 92 93 if (strlen (im->core.res_name) < 200) res_name = res_name_buf; 94 else res_name = Xmalloc (strlen (im->core.res_name) + 50); 95 if (strlen (im->core.res_class) < 200) res_class = res_class_buf; 96 else res_class = Xmalloc (strlen (im->core.res_class) + 50); 97 /* pretend malloc always works */ 98 99 (void) sprintf (res_name, "%s%s%s", 100 im->core.res_name != NULL ? im->core.res_name : "*", 101 im->core.res_name != NULL ? dotximdot : ximdot, 102 "useAuth"); 103 (void) sprintf (res_class, "%s%s%s", 104 im->core.res_class != NULL ? im->core.res_class : "*", 105 im->core.res_class != NULL ? dotXimdot : Ximdot, 106 "UseAuth"); 107 bzero(&value, sizeof(XrmValue)); 108 if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) { 109 if(_XimCheckBool(value.addr)) { 110 MARK_USE_AUTHORIZATION_FUNC(im); 111 } 112 } 113 114 (void) sprintf (res_name, "%s%s%s", 115 im->core.res_name != NULL ? im->core.res_name : "*", 116 im->core.res_name != NULL ? dotximdot : ximdot, 117 "delaybinding"); 118 (void) sprintf (res_class, "%s%s%s", 119 im->core.res_class != NULL ? im->core.res_class : "*", 120 im->core.res_class != NULL ? dotXimdot : Ximdot, 121 "Delaybinding"); 122 bzero(&value, sizeof(XrmValue)); 123 if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) { 124 if(_XimCheckBool(value.addr)) { 125 MARK_DELAYBINDABLE(im); 126 } 127 } 128 129 (void) sprintf (res_name, "%s%s%s", 130 im->core.res_name != NULL ? im->core.res_name : "*", 131 im->core.res_name != NULL ? dotximdot : ximdot, 132 "reconnect"); 133 (void) sprintf (res_class, "%s%s%s", 134 im->core.res_class != NULL ? im->core.res_class : "*", 135 im->core.res_class != NULL ? dotXimdot : Ximdot, 136 "Reconnect"); 137 bzero(&value, sizeof(XrmValue)); 138 if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) { 139 if(_XimCheckBool(value.addr)) { 140 MARK_RECONNECTABLE(im); 141 } 142 } 143 144 if(!IS_CONNECTABLE(im)) { 145 if (res_name != res_name_buf) Xfree (res_name); 146 if (res_class != res_class_buf) Xfree (res_class); 147 return; 148 } 149 150 (void) sprintf (res_name, "%s%s%s", 151 im->core.res_name != NULL ? im->core.res_name : "*", 152 im->core.res_name != NULL ? dotximdot : ximdot, 153 "preeditDefaultStyle"); 154 (void) sprintf (res_class, "%s%s%s", 155 im->core.res_class != NULL ? im->core.res_class : "*", 156 im->core.res_class != NULL ? dotXimdot : Ximdot, 157 "PreeditDefaultStyle"); 158 if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) { 159 if(!strcmp(value.addr, "XIMPreeditArea")) 160 preedit_style = XIMPreeditArea; 161 else if(!strcmp(value.addr, "XIMPreeditCallbacks")) 162 preedit_style = XIMPreeditCallbacks; 163 else if(!strcmp(value.addr, "XIMPreeditPosition")) 164 preedit_style = XIMPreeditPosition; 165 else if(!strcmp(value.addr, "XIMPreeditNothing")) 166 preedit_style = XIMPreeditNothing; 167 else if(!strcmp(value.addr, "XIMPreeditNone")) 168 preedit_style = XIMPreeditNone; 169 } 170 if(!preedit_style) 171 preedit_style = XIMPreeditNothing; 172 173 (void) sprintf (res_name, "%s%s%s", 174 im->core.res_name != NULL ? im->core.res_name : "*", 175 im->core.res_name != NULL ? dotximdot : ximdot, 176 "statusDefaultStyle"); 177 (void) sprintf (res_class, "%s%s%s", 178 im->core.res_class != NULL ? im->core.res_class : "*", 179 im->core.res_class != NULL ? dotXimdot : Ximdot, 180 "StatusDefaultStyle"); 181 if(XrmGetResource(im->core.rdb, res_name, res_class, &str_type, &value)) { 182 if(!strcmp(value.addr, "XIMStatusArea")) 183 status_style = XIMStatusArea; 184 else if(!strcmp(value.addr, "XIMStatusCallbacks")) 185 status_style = XIMStatusCallbacks; 186 else if(!strcmp(value.addr, "XIMStatusNothing")) 187 status_style = XIMStatusNothing; 188 else if(!strcmp(value.addr, "XIMStatusNone")) 189 status_style = XIMStatusNone; 190 } 191 if(!status_style) 192 status_style = XIMStatusNothing; 193 194 if(!(imstyles = (XIMStyles *)Xmalloc(sizeof(XIMStyles) + sizeof(XIMStyle)))){ 195 if (res_name != res_name_buf) Xfree (res_name); 196 if (res_class != res_class_buf) Xfree (res_class); 197 return; 198 } 199 imstyles->count_styles = 1; 200 imstyles->supported_styles = 201 (XIMStyle *)((char *)imstyles + sizeof(XIMStyles)); 202 imstyles->supported_styles[0] = preedit_style | status_style; 203 im->private.proto.default_styles = imstyles; 204 if (res_name != res_name_buf) Xfree (res_name); 205 if (res_class != res_class_buf) Xfree (res_class); 206} 207#endif /* XIM_CONNECTABLE */ 208 209static const char name_table[] = 210 /* 0 */ XNQueryInputStyle"\0" 211 /* 16 */ XNClientWindow"\0" 212 /* 29 */ XNInputStyle"\0" 213 /* 40 */ XNFocusWindow"\0" 214 /* 52 */ XNResourceName"\0" 215 /* 65 */ XNResourceClass"\0" 216 /* 79 */ XNGeometryCallback"\0" 217 /* 96 */ XNDestroyCallback"\0" 218 /* 112 */ XNFilterEvents"\0" 219 /* 125 */ XNPreeditStartCallback"\0" 220 /* 146 */ XNPreeditDoneCallback"\0" 221 /* 166 */ XNPreeditDrawCallback"\0" 222 /* 186 */ XNPreeditCaretCallback"\0" 223 /* 207 */ XNPreeditStateNotifyCallback"\0" 224 /* 234 */ XNPreeditAttributes"\0" 225 /* 252 */ XNStatusStartCallback"\0" 226 /* 272 */ XNStatusDoneCallback"\0" 227 /* 291 */ XNStatusDrawCallback"\0" 228 /* 310 */ XNStatusAttributes"\0" 229 /* 327 */ XNArea"\0" 230 /* 332 */ XNAreaNeeded"\0" 231 /* 343 */ XNSpotLocation"\0" 232 /* 356 */ XNColormap"\0" 233 /* 365 */ XNStdColormap"\0" 234 /* 377 */ XNForeground"\0" 235 /* 388 */ XNBackground"\0" 236 /* 399 */ XNBackgroundPixmap"\0" 237 /* 416 */ XNFontSet"\0" 238 /* 424 */ XNLineSpace"\0" 239 /* 434 */ XNCursor"\0" 240 /* 441 */ XNQueryIMValuesList"\0" 241 /* 459 */ XNQueryICValuesList"\0" 242 /* 477 */ XNVisiblePosition"\0" 243 /* 493 */ XNStringConversionCallback"\0" 244 /* 518 */ XNStringConversion"\0" 245 /* 535 */ XNResetState"\0" 246 /* 546 */ XNHotKey"\0" 247 /* 553 */ XNHotKeyState"\0" 248 /* 565 */ XNPreeditState 249; 250 251#define OFFSET_XNQUERYINPUTSTYLE 0 252#define OFFSET_XNCLIENTWINDOW 16 253#define OFFSET_XNINPUTSTYLE 29 254#define OFFSET_XNFOCUSWINDOW 40 255#define OFFSET_XNRESOURCENAME 52 256#define OFFSET_XNRESOURCECLASS 65 257#define OFFSET_XNGEOMETRYCALLBACK 79 258#define OFFSET_XNDESTROYCALLBACK 96 259#define OFFSET_XNFILTEREVENTS 112 260#define OFFSET_XNPREEDITSTARTCALLBACK 125 261#define OFFSET_XNPREEDITDONECALLBACK 146 262#define OFFSET_XNPREEDITDRAWCALLBACK 166 263#define OFFSET_XNPREEDITCARETCALLBACK 186 264#define OFFSET_XNPREEDITSTATENOTIFYCALLBACK 207 265#define OFFSET_XNPREEDITATTRIBUTES 234 266#define OFFSET_XNSTATUSSTARTCALLBACK 252 267#define OFFSET_XNSTATUSDONECALLBACK 272 268#define OFFSET_XNSTATUSDRAWCALLBACK 291 269#define OFFSET_XNSTATUSATTRIBUTES 310 270#define OFFSET_XNAREA 327 271#define OFFSET_XNAREANEEDED 332 272#define OFFSET_XNSPOTLOCATION 343 273#define OFFSET_XNCOLORMAP 356 274#define OFFSET_XNSTDCOLORMAP 365 275#define OFFSET_XNFOREGROUND 377 276#define OFFSET_XNBACKGROUND 388 277#define OFFSET_XNBACKGROUNDPIXMAP 399 278#define OFFSET_XNFONTSET 416 279#define OFFSET_XNLINESPACE 424 280#define OFFSET_XNCURSOR 434 281#define OFFSET_XNQUERYIMVALUESLIST 441 282#define OFFSET_XNQUERYICVALUESLIST 459 283#define OFFSET_XNVISIBLEPOSITION 477 284#define OFFSET_XNSTRINGCONVERSIONCALLBACK 493 285#define OFFSET_XNSTRINGCONVERSION 518 286#define OFFSET_XNRESETSTATE 535 287#define OFFSET_XNHOTKEY 546 288#define OFFSET_XNHOTKEYSTATE 553 289#define OFFSET_XNPREEDITSTATE 565 290 291/* offsets into name_table */ 292static const unsigned short supported_local_im_values_list[] = { 293 OFFSET_XNQUERYINPUTSTYLE, 294 OFFSET_XNRESOURCENAME, 295 OFFSET_XNRESOURCECLASS, 296 OFFSET_XNDESTROYCALLBACK, 297 OFFSET_XNQUERYIMVALUESLIST, 298 OFFSET_XNQUERYICVALUESLIST, 299 OFFSET_XNVISIBLEPOSITION 300}; 301 302/* offsets into name_table */ 303static const unsigned short supported_local_ic_values_list[] = { 304 OFFSET_XNINPUTSTYLE, 305 OFFSET_XNCLIENTWINDOW, 306 OFFSET_XNFOCUSWINDOW, 307 OFFSET_XNRESOURCENAME, 308 OFFSET_XNRESOURCECLASS, 309 OFFSET_XNGEOMETRYCALLBACK, 310 OFFSET_XNFILTEREVENTS, 311 OFFSET_XNDESTROYCALLBACK, 312 OFFSET_XNSTRINGCONVERSIONCALLBACK, 313 OFFSET_XNSTRINGCONVERSIONCALLBACK, 314 OFFSET_XNRESETSTATE, 315 OFFSET_XNHOTKEY, 316 OFFSET_XNHOTKEYSTATE, 317 OFFSET_XNPREEDITATTRIBUTES, 318 OFFSET_XNSTATUSATTRIBUTES, 319 OFFSET_XNAREA, 320 OFFSET_XNAREANEEDED, 321 OFFSET_XNSPOTLOCATION, 322 OFFSET_XNCOLORMAP, 323 OFFSET_XNSTDCOLORMAP, 324 OFFSET_XNFOREGROUND, 325 OFFSET_XNBACKGROUND, 326 OFFSET_XNBACKGROUNDPIXMAP, 327 OFFSET_XNFONTSET, 328 OFFSET_XNLINESPACE, 329 OFFSET_XNCURSOR, 330 OFFSET_XNPREEDITSTARTCALLBACK, 331 OFFSET_XNPREEDITDONECALLBACK, 332 OFFSET_XNPREEDITDRAWCALLBACK, 333 OFFSET_XNPREEDITCARETCALLBACK, 334 OFFSET_XNSTATUSSTARTCALLBACK, 335 OFFSET_XNSTATUSDONECALLBACK, 336 OFFSET_XNSTATUSDRAWCALLBACK, 337 OFFSET_XNPREEDITSTATE, 338 OFFSET_XNPREEDITSTATENOTIFYCALLBACK 339}; 340 341static XIMStyle const supported_local_styles[] = { 342 XIMPreeditNone | XIMStatusNone, 343 XIMPreeditNothing | XIMStatusNothing, 344 0 /* dummy */ 345}; 346 347static Bool 348_XimDefaultStyles( 349 XimValueOffsetInfo info, 350 XPointer top, 351 XPointer parm, /* unused */ 352 unsigned long mode) /* unused */ 353{ 354 XIMStyles *styles; 355 XIMStyles **out; 356 register int i; 357 unsigned int n; 358 int len; 359 XPointer tmp; 360 361 n = XIMNumber(supported_local_styles) - 1; 362 len = sizeof(XIMStyles) + sizeof(XIMStyle) * n; 363 if(!(tmp = Xcalloc(1, len))) { 364 return False; 365 } 366 367 styles = (XIMStyles *)tmp; 368 if (n > 0) { 369 styles->count_styles = (unsigned short)n; 370 styles->supported_styles = 371 (XIMStyle *)((char *)tmp + sizeof(XIMStyles)); 372 for(i = 0; i < n; i++) { 373 styles->supported_styles[i] = supported_local_styles[i]; 374 } 375 } 376 377 out = (XIMStyles **)((char *)top + info->offset); 378 *out = styles; 379 return True; 380} 381 382static Bool 383_XimDefaultIMValues( 384 XimValueOffsetInfo info, 385 XPointer top, 386 XPointer parm, /* unused */ 387 unsigned long mode) /* unused */ 388{ 389 XIMValuesList *values_list; 390 XIMValuesList **out; 391 register int i; 392 unsigned int n; 393 int len; 394 XPointer tmp; 395 396 n = XIMNumber(supported_local_im_values_list); 397 len = sizeof(XIMValuesList) + sizeof(char **) * n; 398 if(!(tmp = Xcalloc(1, len))) { 399 return False; 400 } 401 402 values_list = (XIMValuesList *)tmp; 403 if (n > 0) { 404 values_list->count_values = (unsigned short)n; 405 values_list->supported_values 406 = (char **)((char *)tmp + sizeof(XIMValuesList)); 407 for(i = 0; i < n; i++) { 408 values_list->supported_values[i] = 409 (char *)name_table + supported_local_im_values_list[i]; 410 } 411 } 412 413 out = (XIMValuesList **)((char *)top + info->offset); 414 *out = values_list; 415 return True; 416} 417 418static Bool 419_XimDefaultICValues( 420 XimValueOffsetInfo info, 421 XPointer top, 422 XPointer parm, /* unused */ 423 unsigned long mode) /* unused */ 424{ 425 XIMValuesList *values_list; 426 XIMValuesList **out; 427 register int i; 428 unsigned int n; 429 int len; 430 XPointer tmp; 431 432 n = XIMNumber(supported_local_ic_values_list); 433 len = sizeof(XIMValuesList) + sizeof(char **) * n; 434 if(!(tmp = Xcalloc(1, len))) { 435 return False; 436 } 437 438 values_list = (XIMValuesList *)tmp; 439 if (n > 0) { 440 values_list->count_values = (unsigned short)n; 441 values_list->supported_values 442 = (char **)((char *)tmp + sizeof(XIMValuesList)); 443 for(i = 0; i < n; i++) { 444 values_list->supported_values[i] = 445 (char *)name_table + supported_local_ic_values_list[i]; 446 } 447 } 448 449 out = (XIMValuesList **)((char *)top + info->offset); 450 *out = values_list; 451 return True; 452} 453 454static Bool 455_XimDefaultVisiblePos( 456 XimValueOffsetInfo info, 457 XPointer top, 458 XPointer parm, /* unused */ 459 unsigned long mode) /* unused */ 460{ 461 Bool *out; 462 463 out = (Bool *)((char *)top + info->offset); 464 *out = False; 465 return True; 466} 467 468static Bool 469_XimDefaultFocusWindow( 470 XimValueOffsetInfo info, 471 XPointer top, 472 XPointer parm, 473 unsigned long mode) 474{ 475 Xic ic = (Xic)parm; 476 Window *out; 477 478 if(ic->core.client_window == (Window)NULL) { 479 return True; 480 } 481 482 out = (Window *)((char *)top + info->offset); 483 *out = ic->core.client_window; 484 return True; 485} 486 487static Bool 488_XimDefaultResName( 489 XimValueOffsetInfo info, 490 XPointer top, 491 XPointer parm, 492 unsigned long mode) 493{ 494 Xic ic = (Xic)parm; 495 Xim im = (Xim)ic->core.im; 496 char **out; 497 498 if(im->core.res_name == (char *)NULL) { 499 return True; 500 } 501 502 out = (char **)((char *)top + info->offset); 503 *out = im->core.res_name; 504 return True; 505} 506 507static Bool 508_XimDefaultResClass( 509 XimValueOffsetInfo info, 510 XPointer top, 511 XPointer parm, 512 unsigned long mode) 513{ 514 Xic ic = (Xic)parm; 515 Xim im = (Xim)ic->core.im; 516 char **out; 517 518 if(im->core.res_class == (char *)NULL) { 519 return True; 520 } 521 522 out = (char **)((char *)top + info->offset); 523 *out = im->core.res_class; 524 return True; 525} 526 527static Bool 528_XimDefaultDestroyCB( 529 XimValueOffsetInfo info, 530 XPointer top, 531 XPointer parm, 532 unsigned long mode) 533{ 534 Xic ic = (Xic)parm; 535 Xim im = (Xim)ic->core.im; 536 XIMCallback *out; 537 538 out = (XIMCallback *)((char *)top + info->offset); 539 *out = im->core.destroy_callback; 540 return True; 541} 542 543static Bool 544_XimDefaultResetState( 545 XimValueOffsetInfo info, 546 XPointer top, 547 XPointer parm, 548 unsigned long mode) 549{ 550 XIMResetState *out; 551 552 out = (XIMResetState *)((char *)top + info->offset); 553 *out = XIMInitialState; 554 return True; 555} 556 557static Bool 558_XimDefaultHotKeyState( 559 XimValueOffsetInfo info, 560 XPointer top, 561 XPointer parm, 562 unsigned long mode) 563{ 564 XIMHotKeyState *out; 565 566 out = (XIMHotKeyState *)((char *)top + info->offset); 567 *out = XIMHotKeyStateOFF; 568 return True; 569} 570 571static Bool 572_XimDefaultArea( 573 XimValueOffsetInfo info, 574 XPointer top, 575 XPointer parm, 576 unsigned long mode) 577{ 578 Xic ic = (Xic)parm; 579 Xim im = (Xim)ic->core.im; 580 Window root_return; 581 int x_return, y_return; 582 unsigned int width_return, height_return; 583 unsigned int border_width_return; 584 unsigned int depth_return; 585 XRectangle area; 586 XRectangle *out; 587 588 if(ic->core.focus_window == (Window)NULL) { 589 return True; 590 } 591 if(XGetGeometry(im->core.display, (Drawable)ic->core.focus_window, 592 &root_return, &x_return, &y_return, &width_return, 593 &height_return, &border_width_return, &depth_return) 594 == (Status)Success) { 595 return True; 596 } 597 area.x = 0; 598 area.y = 0; 599 area.width = width_return; 600 area.height = height_return; 601 602 out = (XRectangle *)((char *)top + info->offset); 603 *out = area; 604 return True; 605} 606 607static Bool 608_XimDefaultColormap( 609 XimValueOffsetInfo info, 610 XPointer top, 611 XPointer parm, 612 unsigned long mode) 613{ 614 Xic ic = (Xic)parm; 615 Xim im = (Xim)ic->core.im; 616 XWindowAttributes win_attr; 617 Colormap *out; 618 619 if(ic->core.client_window == (Window)NULL) { 620 return True; 621 } 622 if(XGetWindowAttributes(im->core.display, ic->core.client_window, 623 &win_attr) == (Status)Success) { 624 return True; 625 } 626 627 out = (Colormap *)((char *)top + info->offset); 628 *out = win_attr.colormap; 629 return True; 630} 631 632static Bool 633_XimDefaultStdColormap( 634 XimValueOffsetInfo info, 635 XPointer top, 636 XPointer parm, 637 unsigned long mode) 638{ 639 Atom *out; 640 641 out = (Atom *)((char *)top + info->offset); 642 *out = (Atom)0; 643 return True; 644} 645 646static Bool 647_XimDefaultFg( 648 XimValueOffsetInfo info, 649 XPointer top, 650 XPointer parm, 651 unsigned long mode) 652{ 653 Xic ic = (Xic)parm; 654 Xim im = (Xim)ic->core.im; 655 unsigned long fg; 656 unsigned long *out; 657 658 fg = WhitePixel(im->core.display, DefaultScreen(im->core.display)); 659 out = (unsigned long *)((char *)top + info->offset); 660 *out = fg; 661 return True; 662} 663 664static Bool 665_XimDefaultBg( 666 XimValueOffsetInfo info, 667 XPointer top, 668 XPointer parm, 669 unsigned long mode) 670{ 671 Xic ic = (Xic)parm; 672 Xim im = (Xim)ic->core.im; 673 unsigned long bg; 674 unsigned long *out; 675 676 bg = BlackPixel(im->core.display, DefaultScreen(im->core.display)); 677 out = (unsigned long *)((char *)top + info->offset); 678 *out = bg; 679 return True; 680} 681 682static Bool 683_XimDefaultBgPixmap( 684 XimValueOffsetInfo info, 685 XPointer top, 686 XPointer parm, 687 unsigned long mode) 688{ 689 Pixmap *out; 690 691 out = (Pixmap *)((char *)top + info->offset); 692 *out = (Pixmap)0; 693 return True; 694} 695 696static Bool 697_XimDefaultFontSet( 698 XimValueOffsetInfo info, 699 XPointer top, 700 XPointer parm, 701 unsigned long mode) 702{ 703 XFontSet *out; 704 705 out = (XFontSet *)((char *)top + info->offset); 706 *out = 0; 707 return True; 708} 709 710static Bool 711_XimDefaultLineSpace( 712 XimValueOffsetInfo info, 713 XPointer top, 714 XPointer parm, 715 unsigned long mode) 716{ 717 Xic ic = (Xic)parm; 718 XFontSet fontset; 719 XFontSetExtents *fset_extents; 720 int line_space = 0; 721 int *out; 722 723 if(mode & XIM_PREEDIT_ATTR) { 724 fontset = ic->core.preedit_attr.fontset; 725 } else if(mode & XIM_STATUS_ATTR) { 726 fontset = ic->core.status_attr.fontset; 727 } else { 728 return True; 729 } 730 if (fontset) { 731 fset_extents = XExtentsOfFontSet(fontset); 732 line_space = fset_extents->max_logical_extent.height; 733 } 734 out = (int *)((char *)top + info->offset); 735 *out = line_space; 736 return True; 737} 738 739static Bool 740_XimDefaultCursor( 741 XimValueOffsetInfo info, 742 XPointer top, 743 XPointer parm, 744 unsigned long mode) 745{ 746 Cursor *out; 747 748 out = (Cursor *)((char *)top + info->offset); 749 *out = (Cursor)0; 750 return True; 751} 752 753static Bool 754_XimDefaultPreeditState( 755 XimValueOffsetInfo info, 756 XPointer top, 757 XPointer parm, 758 unsigned long mode) 759{ 760 XIMPreeditState *out; 761 762 out = (XIMPreeditState *)((char *)top + info->offset); 763 *out = XIMPreeditDisable; 764 return True; 765} 766 767static Bool 768_XimDefaultNest( 769 XimValueOffsetInfo info, 770 XPointer top, 771 XPointer parm, 772 unsigned long mode) 773{ 774 return True; 775} 776 777static Bool 778_XimEncodeCallback( 779 XimValueOffsetInfo info, 780 XPointer top, 781 XPointer val) 782{ 783 XIMCallback *out; 784 785 out = (XIMCallback *)((char *)top + info->offset); 786 *out = *((XIMCallback *)val); 787 return True; 788} 789 790static Bool 791_XimEncodeString( 792 XimValueOffsetInfo info, 793 XPointer top, 794 XPointer val) 795{ 796 char *string; 797 char **out; 798 799 if(val == (XPointer)NULL) { 800 return False; 801 } 802 if (!(string = strdup((char *)val))) { 803 return False; 804 } 805 806 out = (char **)((char *)top + info->offset); 807 if(*out) { 808 Xfree(*out); 809 } 810 *out = string; 811 return True; 812} 813 814static Bool 815_XimEncodeStyle( 816 XimValueOffsetInfo info, 817 XPointer top, 818 XPointer val) 819{ 820 XIMStyle *out; 821 822 out = (XIMStyle *)((char *)top + info->offset); 823 *out = (XIMStyle)val; 824 return True; 825} 826 827static Bool 828_XimEncodeWindow( 829 XimValueOffsetInfo info, 830 XPointer top, 831 XPointer val) 832{ 833 Window *out; 834 835 out = (Window *)((char *)top + info->offset); 836 *out = (Window)val; 837 return True; 838} 839 840static Bool 841_XimEncodeStringConv( 842 XimValueOffsetInfo info, 843 XPointer top, 844 XPointer val) 845{ 846 /* 847 * Not yet 848 */ 849 return True; 850} 851 852static Bool 853_XimEncodeResetState( 854 XimValueOffsetInfo info, 855 XPointer top, 856 XPointer val) 857{ 858 XIMResetState *out; 859 860 out = (XIMResetState *)((char *)top + info->offset); 861 *out = (XIMResetState)val; 862 return True; 863} 864 865static Bool 866_XimEncodeHotKey( 867 XimValueOffsetInfo info, 868 XPointer top, 869 XPointer val) 870{ 871 XIMHotKeyTriggers *hotkey = (XIMHotKeyTriggers *)val; 872 XIMHotKeyTriggers **out; 873 XIMHotKeyTriggers *key_list; 874 XIMHotKeyTrigger *key; 875 XPointer tmp; 876 int num; 877 int len; 878 register int i; 879 880 if(hotkey == (XIMHotKeyTriggers *)NULL) { 881 return True; 882 } 883 884 if((num = hotkey->num_hot_key) == 0) { 885 return True; 886 } 887 888 len = sizeof(XIMHotKeyTriggers) + sizeof(XIMHotKeyTrigger) * num; 889 if(!(tmp = (XPointer)Xmalloc(len))) { 890 return False; 891 } 892 893 key_list = (XIMHotKeyTriggers *)tmp; 894 key = (XIMHotKeyTrigger *)((char *)tmp + sizeof(XIMHotKeyTriggers)); 895 896 for(i = 0; i < num; i++) { 897 key[i] = hotkey->key[i]; 898 } 899 900 key_list->num_hot_key = num; 901 key_list->key = key; 902 903 out = (XIMHotKeyTriggers **)((char *)top + info->offset); 904 *out = key_list; 905 return True; 906} 907 908static Bool 909_XimEncodeHotKetState( 910 XimValueOffsetInfo info, 911 XPointer top, 912 XPointer val) 913{ 914 XIMHotKeyState *out; 915 916 out = (XIMHotKeyState *)((char *)top + info->offset); 917 *out = (XIMHotKeyState)val; 918 return True; 919} 920 921static Bool 922_XimEncodeRectangle( 923 XimValueOffsetInfo info, 924 XPointer top, 925 XPointer val) 926{ 927 XRectangle *out; 928 929 out = (XRectangle *)((char *)top + info->offset); 930 *out = *((XRectangle *)val); 931 return True; 932} 933 934static Bool 935_XimEncodeSpot( 936 XimValueOffsetInfo info, 937 XPointer top, 938 XPointer val) 939{ 940 XPoint *out; 941 942 out = (XPoint *)((char *)top + info->offset); 943 *out = *((XPoint *)val); 944 return True; 945} 946 947static Bool 948_XimEncodeColormap( 949 XimValueOffsetInfo info, 950 XPointer top, 951 XPointer val) 952{ 953 Colormap *out; 954 955 out = (Colormap *)((char *)top + info->offset); 956 *out = (Colormap)val; 957 return True; 958} 959 960static Bool 961_XimEncodeStdColormap( 962 XimValueOffsetInfo info, 963 XPointer top, 964 XPointer val) 965{ 966 Atom *out; 967 968 out = (Atom *)((char *)top + info->offset); 969 *out = (Atom)val; 970 return True; 971} 972 973static Bool 974_XimEncodeLong( 975 XimValueOffsetInfo info, 976 XPointer top, 977 XPointer val) 978{ 979 unsigned long *out; 980 981 out = (unsigned long *)((char *)top + info->offset); 982 *out = (unsigned long)val; 983 return True; 984} 985 986static Bool 987_XimEncodeBgPixmap( 988 XimValueOffsetInfo info, 989 XPointer top, 990 XPointer val) 991{ 992 Pixmap *out; 993 994 out = (Pixmap *)((char *)top + info->offset); 995 *out = (Pixmap)val; 996 return True; 997} 998 999static Bool 1000_XimEncodeFontSet( 1001 XimValueOffsetInfo info, 1002 XPointer top, 1003 XPointer val) 1004{ 1005 XFontSet *out; 1006 1007 out = (XFontSet *)((char *)top + info->offset); 1008 *out = (XFontSet)val; 1009 return True; 1010} 1011 1012static Bool 1013_XimEncodeLineSpace( 1014 XimValueOffsetInfo info, 1015 XPointer top, 1016 XPointer val) 1017{ 1018 int *out; 1019 1020 out = (int *)((char *)top + info->offset); 1021 *out = (long)val; 1022 return True; 1023} 1024 1025static Bool 1026_XimEncodeCursor( 1027 XimValueOffsetInfo info, 1028 XPointer top, 1029 XPointer val) 1030{ 1031 Cursor *out; 1032 1033 out = (Cursor *)((char *)top + info->offset); 1034 *out = (Cursor)val; 1035 return True; 1036} 1037 1038static Bool 1039_XimEncodePreeditState( 1040 XimValueOffsetInfo info, 1041 XPointer top, 1042 XPointer val) 1043{ 1044 XIMPreeditState *out; 1045 1046 out = (XIMPreeditState *)((char *)top + info->offset); 1047 *out = (XIMPreeditState)val; 1048 return True; 1049} 1050 1051static Bool 1052_XimEncodeNest( 1053 XimValueOffsetInfo info, 1054 XPointer top, 1055 XPointer val) 1056{ 1057 return True; 1058} 1059 1060static Bool 1061_XimDecodeStyles( 1062 XimValueOffsetInfo info, 1063 XPointer top, 1064 XPointer val) 1065{ 1066 XIMStyles *styles; 1067 XIMStyles *out; 1068 register int i; 1069 unsigned int num; 1070 int len; 1071 XPointer tmp; 1072 1073 if(val == (XPointer)NULL) { 1074 return False; 1075 } 1076 1077 styles = *((XIMStyles **)((char *)top + info->offset)); 1078 num = styles->count_styles; 1079 1080 len = sizeof(XIMStyles) + sizeof(XIMStyle) * num; 1081 if(!(tmp = Xcalloc(1, len))) { 1082 return False; 1083 } 1084 1085 out = (XIMStyles *)tmp; 1086 if(num >0) { 1087 out->count_styles = (unsigned short)num; 1088 out->supported_styles = (XIMStyle *)((char *)tmp + sizeof(XIMStyles)); 1089 1090 for(i = 0; i < num; i++) { 1091 out->supported_styles[i] = styles->supported_styles[i]; 1092 } 1093 } 1094 *((XIMStyles **)val) = out; 1095 return True; 1096} 1097 1098static Bool 1099_XimDecodeValues( 1100 XimValueOffsetInfo info, 1101 XPointer top, 1102 XPointer val) 1103{ 1104 XIMValuesList *values_list; 1105 XIMValuesList *out; 1106 register int i; 1107 unsigned int num; 1108 int len; 1109 XPointer tmp; 1110 1111 if(val == (XPointer)NULL) { 1112 return False; 1113 } 1114 1115 values_list = *((XIMValuesList **)((char *)top + info->offset)); 1116 num = values_list->count_values; 1117 1118 len = sizeof(XIMValuesList) + sizeof(char **) * num; 1119 if(!(tmp = Xcalloc(1, len))) { 1120 return False; 1121 } 1122 1123 out = (XIMValuesList *)tmp; 1124 if(num) { 1125 out->count_values = (unsigned short)num; 1126 out->supported_values = (char **)((char *)tmp + sizeof(XIMValuesList)); 1127 1128 for(i = 0; i < num; i++) { 1129 out->supported_values[i] = values_list->supported_values[i]; 1130 } 1131 } 1132 *((XIMValuesList **)val) = out; 1133 return True; 1134} 1135 1136static Bool 1137_XimDecodeCallback( 1138 XimValueOffsetInfo info, 1139 XPointer top, 1140 XPointer val) 1141{ 1142 XIMCallback *in; 1143 XIMCallback *callback; 1144 1145 in = (XIMCallback *)((char *)top + info->offset); 1146 if(!(callback = (XIMCallback *)Xmalloc(sizeof(XIMCallback)))) { 1147 return False; 1148 } 1149 callback->client_data = in->client_data; 1150 callback->callback = in->callback; 1151 1152 *((XIMCallback **)val) = callback; 1153 return True; 1154} 1155 1156static Bool 1157_XimDecodeString( 1158 XimValueOffsetInfo info, 1159 XPointer top, 1160 XPointer val) 1161{ 1162 char *in; 1163 char *string; 1164 1165 in = *((char **)((char *)top + info->offset)); 1166 if (in != NULL) { 1167 string = strdup(in); 1168 } else { 1169 string = Xcalloc(1, 1); /* strdup("") */ 1170 } 1171 if (string == NULL) { 1172 return False; 1173 } 1174 *((char **)val) = string; 1175 return True; 1176} 1177 1178static Bool 1179_XimDecodeBool( 1180 XimValueOffsetInfo info, 1181 XPointer top, 1182 XPointer val) 1183{ 1184 Bool *in; 1185 1186 in = (Bool *)((char *)top + info->offset); 1187 *((Bool *)val) = *in; 1188 return True; 1189} 1190 1191static Bool 1192_XimDecodeStyle( 1193 XimValueOffsetInfo info, 1194 XPointer top, 1195 XPointer val) 1196{ 1197 XIMStyle *in; 1198 1199 in = (XIMStyle *)((char *)top + info->offset); 1200 *((XIMStyle *)val) = *in; 1201 return True; 1202} 1203 1204static Bool 1205_XimDecodeWindow( 1206 XimValueOffsetInfo info, 1207 XPointer top, 1208 XPointer val) 1209{ 1210 Window *in; 1211 1212 in = (Window *)((char *)top + info->offset); 1213 *((Window *)val) = *in; 1214 return True; 1215} 1216 1217static Bool 1218_XimDecodeStringConv( 1219 XimValueOffsetInfo info, 1220 XPointer top, 1221 XPointer val) 1222{ 1223 /* 1224 * Not yet 1225 */ 1226 return True; 1227} 1228 1229static Bool 1230_XimDecodeResetState( 1231 XimValueOffsetInfo info, 1232 XPointer top, 1233 XPointer val) 1234{ 1235 XIMResetState *in; 1236 1237 in = (XIMResetState *)((char *)top + info->offset); 1238 *((XIMResetState *)val) = *in; 1239 return True; 1240} 1241 1242static Bool 1243_XimDecodeHotKey( 1244 XimValueOffsetInfo info, 1245 XPointer top, 1246 XPointer val) 1247{ 1248 XIMHotKeyTriggers *in; 1249 XIMHotKeyTriggers *hotkey; 1250 XIMHotKeyTrigger *key; 1251 XPointer tmp; 1252 int num; 1253 int len; 1254 register int i; 1255 1256 in = *((XIMHotKeyTriggers **)((char *)top + info->offset)); 1257 num = in->num_hot_key; 1258 len = sizeof(XIMHotKeyTriggers) + sizeof(XIMHotKeyTrigger) * num; 1259 if(!(tmp = (XPointer)Xmalloc(len))) { 1260 return False; 1261 } 1262 1263 hotkey = (XIMHotKeyTriggers *)tmp; 1264 key = (XIMHotKeyTrigger *)((char *)tmp + sizeof(XIMHotKeyTriggers)); 1265 1266 for(i = 0; i < num; i++) { 1267 key[i] = in->key[i]; 1268 } 1269 hotkey->num_hot_key = num; 1270 hotkey->key = key; 1271 1272 *((XIMHotKeyTriggers **)val) = hotkey; 1273 return True; 1274} 1275 1276static Bool 1277_XimDecodeHotKetState( 1278 XimValueOffsetInfo info, 1279 XPointer top, 1280 XPointer val) 1281{ 1282 XIMHotKeyState *in; 1283 1284 in = (XIMHotKeyState *)((char *)top + info->offset); 1285 *((XIMHotKeyState *)val) = *in; 1286 return True; 1287} 1288 1289static Bool 1290_XimDecodeRectangle( 1291 XimValueOffsetInfo info, 1292 XPointer top, 1293 XPointer val) 1294{ 1295 XRectangle *in; 1296 XRectangle *rect; 1297 1298 in = (XRectangle *)((char *)top + info->offset); 1299 if(!(rect = (XRectangle *)Xmalloc(sizeof(XRectangle)))) { 1300 return False; 1301 } 1302 *rect = *in; 1303 *((XRectangle **)val) = rect; 1304 return True; 1305} 1306 1307static Bool 1308_XimDecodeSpot( 1309 XimValueOffsetInfo info, 1310 XPointer top, 1311 XPointer val) 1312{ 1313 XPoint *in; 1314 XPoint *spot; 1315 1316 in = (XPoint *)((char *)top + info->offset); 1317 if(!(spot = (XPoint *)Xmalloc(sizeof(XPoint)))) { 1318 return False; 1319 } 1320 *spot = *in; 1321 *((XPoint **)val) = spot; 1322 return True; 1323} 1324 1325static Bool 1326_XimDecodeColormap( 1327 XimValueOffsetInfo info, 1328 XPointer top, 1329 XPointer val) 1330{ 1331 Colormap *in; 1332 1333 in = (Colormap *)((char *)top + info->offset); 1334 *((Colormap *)val) = *in; 1335 return True; 1336} 1337 1338static Bool 1339_XimDecodeStdColormap( 1340 XimValueOffsetInfo info, 1341 XPointer top, 1342 XPointer val) 1343{ 1344 Atom *in; 1345 1346 in = (Atom *)((char *)top + info->offset); 1347 *((Atom *)val) = *in; 1348 return True; 1349} 1350 1351static Bool 1352_XimDecodeLong( 1353 XimValueOffsetInfo info, 1354 XPointer top, 1355 XPointer val) 1356{ 1357 unsigned long *in; 1358 1359 in = (unsigned long *)((char *)top + info->offset); 1360 *((unsigned long *)val) = *in; 1361 return True; 1362} 1363 1364static Bool 1365_XimDecodeBgPixmap( 1366 XimValueOffsetInfo info, 1367 XPointer top, 1368 XPointer val) 1369{ 1370 Pixmap *in; 1371 1372 in = (Pixmap *)((char *)top + info->offset); 1373 *((Pixmap *)val) = *in; 1374 return True; 1375} 1376 1377static Bool 1378_XimDecodeFontSet( 1379 XimValueOffsetInfo info, 1380 XPointer top, 1381 XPointer val) 1382{ 1383 XFontSet *in; 1384 1385 in = (XFontSet *)((char *)top + info->offset); 1386 *((XFontSet *)val) = *in; 1387 return True; 1388} 1389 1390static Bool 1391_XimDecodeLineSpace( 1392 XimValueOffsetInfo info, 1393 XPointer top, 1394 XPointer val) 1395{ 1396 int *in; 1397 1398 in = (int *)((char *)top + info->offset); 1399 *((int *)val) = *in; 1400 return True; 1401} 1402 1403static Bool 1404_XimDecodeCursor( 1405 XimValueOffsetInfo info, 1406 XPointer top, 1407 XPointer val) 1408{ 1409 Cursor *in; 1410 1411 in = (Cursor *)((char *)top + info->offset); 1412 *((Cursor *)val) = *in; 1413 return True; 1414} 1415 1416static Bool 1417_XimDecodePreeditState( 1418 XimValueOffsetInfo info, 1419 XPointer top, 1420 XPointer val) 1421{ 1422 XIMPreeditState *in; 1423 1424 in = (XIMPreeditState *)((char *)top + info->offset); 1425 *((XIMPreeditState *)val) = *in; 1426 return True; 1427} 1428 1429static Bool 1430_XimDecodeNest( 1431 XimValueOffsetInfo info, 1432 XPointer top, 1433 XPointer val) 1434{ 1435 return True; 1436} 1437 1438static XIMResource im_resources[] = { 1439 {XNQueryInputStyle, 0, XimType_XIMStyles, 0, 0, 0}, 1440 {XNDestroyCallback, 0, 0, 0, 0, 0}, 1441 {XNResourceName, 0, XimType_STRING8, 0, 0, 0}, 1442 {XNResourceClass, 0, XimType_STRING8, 0, 0, 0}, 1443 {XNQueryIMValuesList, 0, 0, 0, 0, 0}, 1444 {XNQueryICValuesList, 0, 0, 0, 0, 0}, 1445 {XNVisiblePosition, 0, 0, 0, 0, 0} 1446}; 1447 1448static XIMResource im_inner_resources[] = { 1449 {XNDestroyCallback, 0, 0, 0, 0, 0}, 1450 {XNResourceName, 0, XimType_STRING8, 0, 0, 0}, 1451 {XNResourceClass, 0, XimType_STRING8, 0, 0, 0}, 1452 {XNQueryIMValuesList, 0, 0, 0, 0, 0}, 1453 {XNQueryICValuesList, 0, 0, 0, 0, 0}, 1454 {XNVisiblePosition, 0, 0, 0, 0, 0} 1455}; 1456 1457static XIMResource ic_resources[] = { 1458 {XNInputStyle, 0, XimType_CARD32, 0, 0, 0}, 1459 {XNClientWindow, 0, XimType_Window, 0, 0, 0}, 1460 {XNFocusWindow, 0, XimType_Window, 0, 0, 0}, 1461 {XNResourceName, 0, XimType_STRING8, 0, 0, 0}, 1462 {XNResourceClass, 0, XimType_STRING8, 0, 0, 0}, 1463 {XNGeometryCallback, 0, 0, 0, 0, 0}, 1464 {XNFilterEvents, 0, XimType_CARD32, 0, 0, 0}, 1465 {XNDestroyCallback, 0, 0, 0, 0, 0}, 1466 {XNStringConversionCallback, 0, 0, 0, 0, 0}, 1467 {XNStringConversion, 0, XimType_XIMStringConversion,0, 0, 0}, 1468 {XNResetState, 0, 0, 0, 0, 0}, 1469 {XNHotKey, 0, XimType_XIMHotKeyTriggers,0, 0, 0}, 1470 {XNHotKeyState, 0, XimType_XIMHotKeyState, 0, 0, 0}, 1471 {XNPreeditAttributes, 0, XimType_NEST, 0, 0, 0}, 1472 {XNStatusAttributes, 0, XimType_NEST, 0, 0, 0}, 1473 {XNArea, 0, XimType_XRectangle, 0, 0, 0}, 1474 {XNAreaNeeded, 0, XimType_XRectangle, 0, 0, 0}, 1475 {XNSpotLocation, 0, XimType_XPoint, 0, 0, 0}, 1476 {XNColormap, 0, XimType_CARD32, 0, 0, 0}, 1477 {XNStdColormap, 0, XimType_CARD32, 0, 0, 0}, 1478 {XNForeground, 0, XimType_CARD32, 0, 0, 0}, 1479 {XNBackground, 0, XimType_CARD32, 0, 0, 0}, 1480 {XNBackgroundPixmap, 0, XimType_CARD32, 0, 0, 0}, 1481 {XNFontSet, 0, XimType_XFontSet, 0, 0, 0}, 1482 {XNLineSpace, 0, XimType_CARD32, 0, 0, 0}, 1483 {XNCursor, 0, XimType_CARD32, 0, 0, 0}, 1484 {XNPreeditStartCallback, 0, 0, 0, 0, 0}, 1485 {XNPreeditDoneCallback, 0, 0, 0, 0, 0}, 1486 {XNPreeditDrawCallback, 0, 0, 0, 0, 0}, 1487 {XNPreeditCaretCallback, 0, 0, 0, 0, 0}, 1488 {XNStatusStartCallback, 0, 0, 0, 0, 0}, 1489 {XNStatusDoneCallback, 0, 0, 0, 0, 0}, 1490 {XNStatusDrawCallback, 0, 0, 0, 0, 0}, 1491 {XNPreeditState, 0, 0, 0, 0, 0}, 1492 {XNPreeditStateNotifyCallback, 0, 0, 0, 0, 0}, 1493}; 1494 1495static XIMResource ic_inner_resources[] = { 1496 {XNResourceName, 0, XimType_STRING8, 0, 0, 0}, 1497 {XNResourceClass, 0, XimType_STRING8, 0, 0, 0}, 1498 {XNGeometryCallback, 0, 0, 0, 0, 0}, 1499 {XNDestroyCallback, 0, 0, 0, 0, 0}, 1500 {XNStringConversionCallback, 0, 0, 0, 0, 0}, 1501 {XNPreeditStartCallback, 0, 0, 0, 0, 0}, 1502 {XNPreeditDoneCallback, 0, 0, 0, 0, 0}, 1503 {XNPreeditDrawCallback, 0, 0, 0, 0, 0}, 1504 {XNPreeditCaretCallback, 0, 0, 0, 0, 0}, 1505 {XNStatusStartCallback, 0, 0, 0, 0, 0}, 1506 {XNStatusDoneCallback, 0, 0, 0, 0, 0}, 1507 {XNStatusDrawCallback, 0, 0, 0, 0, 0}, 1508 {XNPreeditStateNotifyCallback, 0, 0, 0, 0, 0}, 1509}; 1510 1511static XimValueOffsetInfoRec im_attr_info[] = { 1512 {OFFSET_XNQUERYINPUTSTYLE, 0, 1513 XOffsetOf(XimDefIMValues, styles), 1514 _XimDefaultStyles, NULL, _XimDecodeStyles}, 1515 1516 {OFFSET_XNDESTROYCALLBACK, 0, 1517 XOffsetOf(XimDefIMValues, destroy_callback), 1518 NULL, _XimEncodeCallback, _XimDecodeCallback}, 1519 1520 {OFFSET_XNRESOURCENAME, 0, 1521 XOffsetOf(XimDefIMValues, res_name), 1522 NULL, _XimEncodeString, _XimDecodeString}, 1523 1524 {OFFSET_XNRESOURCECLASS, 0, 1525 XOffsetOf(XimDefIMValues, res_class), 1526 NULL, _XimEncodeString, _XimDecodeString}, 1527 1528 {OFFSET_XNQUERYIMVALUESLIST, 0, 1529 XOffsetOf(XimDefIMValues, im_values_list), 1530 _XimDefaultIMValues, NULL, _XimDecodeValues}, 1531 1532 {OFFSET_XNQUERYICVALUESLIST, 0, 1533 XOffsetOf(XimDefIMValues, ic_values_list), 1534 _XimDefaultICValues, NULL, _XimDecodeValues}, 1535 1536 {OFFSET_XNVISIBLEPOSITION, 0, 1537 XOffsetOf(XimDefIMValues, visible_position), 1538 _XimDefaultVisiblePos, NULL, _XimDecodeBool} 1539}; 1540 1541static XimValueOffsetInfoRec ic_attr_info[] = { 1542 {OFFSET_XNINPUTSTYLE, 0, 1543 XOffsetOf(XimDefICValues, input_style), 1544 NULL, _XimEncodeStyle, _XimDecodeStyle}, 1545 1546 {OFFSET_XNCLIENTWINDOW, 0, 1547 XOffsetOf(XimDefICValues, client_window), 1548 NULL, _XimEncodeWindow, _XimDecodeWindow}, 1549 1550 {OFFSET_XNFOCUSWINDOW, 0, 1551 XOffsetOf(XimDefICValues, focus_window), 1552 _XimDefaultFocusWindow, _XimEncodeWindow, _XimDecodeWindow}, 1553 1554 {OFFSET_XNRESOURCENAME, 0, 1555 XOffsetOf(XimDefICValues, res_name), 1556 _XimDefaultResName, _XimEncodeString, _XimDecodeString}, 1557 1558 {OFFSET_XNRESOURCECLASS, 0, 1559 XOffsetOf(XimDefICValues, res_class), 1560 _XimDefaultResClass, _XimEncodeString, _XimDecodeString}, 1561 1562 {OFFSET_XNGEOMETRYCALLBACK, 0, 1563 XOffsetOf(XimDefICValues, geometry_callback), 1564 NULL, _XimEncodeCallback, _XimDecodeCallback}, 1565 1566 {OFFSET_XNFILTEREVENTS, 0, 1567 XOffsetOf(XimDefICValues, filter_events), 1568 NULL, NULL, _XimDecodeLong}, 1569 1570 {OFFSET_XNDESTROYCALLBACK, 0, 1571 XOffsetOf(XimDefICValues, destroy_callback), 1572 _XimDefaultDestroyCB, _XimEncodeCallback, _XimDecodeCallback}, 1573 1574 {OFFSET_XNSTRINGCONVERSIONCALLBACK, 0, 1575 XOffsetOf(XimDefICValues, string_conversion_callback), 1576 NULL, _XimEncodeCallback, _XimDecodeCallback}, 1577 1578 {OFFSET_XNSTRINGCONVERSION, 0, 1579 XOffsetOf(XimDefICValues, string_conversion), 1580 NULL, _XimEncodeStringConv, _XimDecodeStringConv}, 1581 1582 {OFFSET_XNRESETSTATE, 0, 1583 XOffsetOf(XimDefICValues, reset_state), 1584 _XimDefaultResetState, _XimEncodeResetState, _XimDecodeResetState}, 1585 1586 {OFFSET_XNHOTKEY, 0, 1587 XOffsetOf(XimDefICValues, hotkey), 1588 NULL, _XimEncodeHotKey, _XimDecodeHotKey}, 1589 1590 {OFFSET_XNHOTKEYSTATE, 0, 1591 XOffsetOf(XimDefICValues, hotkey_state), 1592 _XimDefaultHotKeyState, _XimEncodeHotKetState, _XimDecodeHotKetState}, 1593 1594 {OFFSET_XNPREEDITATTRIBUTES, 0, 1595 XOffsetOf(XimDefICValues, preedit_attr), 1596 _XimDefaultNest, _XimEncodeNest, _XimDecodeNest}, 1597 1598 {OFFSET_XNSTATUSATTRIBUTES, 0, 1599 XOffsetOf(XimDefICValues, status_attr), 1600 _XimDefaultNest, _XimEncodeNest, _XimDecodeNest}, 1601}; 1602 1603static XimValueOffsetInfoRec ic_pre_attr_info[] = { 1604 {OFFSET_XNAREA, 0, 1605 XOffsetOf(ICPreeditAttributes, area), 1606 _XimDefaultArea, _XimEncodeRectangle, _XimDecodeRectangle}, 1607 1608 {OFFSET_XNAREANEEDED, 0, 1609 XOffsetOf(ICPreeditAttributes, area_needed), 1610 NULL, _XimEncodeRectangle, _XimDecodeRectangle}, 1611 1612 {OFFSET_XNSPOTLOCATION, 0, 1613 XOffsetOf(ICPreeditAttributes, spot_location), 1614 NULL, _XimEncodeSpot, _XimDecodeSpot}, 1615 1616 {OFFSET_XNCOLORMAP, 0, 1617 XOffsetOf(ICPreeditAttributes, colormap), 1618 _XimDefaultColormap, _XimEncodeColormap, _XimDecodeColormap}, 1619 1620 {OFFSET_XNSTDCOLORMAP, 0, 1621 XOffsetOf(ICPreeditAttributes, std_colormap), 1622 _XimDefaultStdColormap, _XimEncodeStdColormap, _XimDecodeStdColormap}, 1623 1624 {OFFSET_XNFOREGROUND, 0, 1625 XOffsetOf(ICPreeditAttributes, foreground), 1626 _XimDefaultFg, _XimEncodeLong, _XimDecodeLong}, 1627 1628 {OFFSET_XNBACKGROUND, 0, 1629 XOffsetOf(ICPreeditAttributes, background), 1630 _XimDefaultBg, _XimEncodeLong, _XimDecodeLong}, 1631 1632 {OFFSET_XNBACKGROUNDPIXMAP, 0, 1633 XOffsetOf(ICPreeditAttributes, background_pixmap), 1634 _XimDefaultBgPixmap, _XimEncodeBgPixmap, _XimDecodeBgPixmap}, 1635 1636 {OFFSET_XNFONTSET, 0, 1637 XOffsetOf(ICPreeditAttributes, fontset), 1638 _XimDefaultFontSet, _XimEncodeFontSet, _XimDecodeFontSet}, 1639 1640 {OFFSET_XNLINESPACE, 0, 1641 XOffsetOf(ICPreeditAttributes, line_spacing), 1642 _XimDefaultLineSpace, _XimEncodeLineSpace, _XimDecodeLineSpace}, 1643 1644 {OFFSET_XNCURSOR, 0, 1645 XOffsetOf(ICPreeditAttributes, cursor), 1646 _XimDefaultCursor, _XimEncodeCursor, _XimDecodeCursor}, 1647 1648 {OFFSET_XNPREEDITSTARTCALLBACK, 0, 1649 XOffsetOf(ICPreeditAttributes, start_callback), 1650 NULL, _XimEncodeCallback, _XimDecodeCallback}, 1651 1652 {OFFSET_XNPREEDITDONECALLBACK, 0, 1653 XOffsetOf(ICPreeditAttributes, done_callback), 1654 NULL, _XimEncodeCallback, _XimDecodeCallback}, 1655 1656 {OFFSET_XNPREEDITDRAWCALLBACK, 0, 1657 XOffsetOf(ICPreeditAttributes, draw_callback), 1658 NULL, _XimEncodeCallback, _XimDecodeCallback}, 1659 1660 {OFFSET_XNPREEDITCARETCALLBACK, 0, 1661 XOffsetOf(ICPreeditAttributes, caret_callback), 1662 NULL, _XimEncodeCallback, _XimDecodeCallback}, 1663 1664 {OFFSET_XNPREEDITSTATE, 0, 1665 XOffsetOf(ICPreeditAttributes, preedit_state), 1666 _XimDefaultPreeditState, _XimEncodePreeditState,_XimDecodePreeditState}, 1667 1668 {OFFSET_XNPREEDITSTATENOTIFYCALLBACK, 0, 1669 XOffsetOf(ICPreeditAttributes, state_notify_callback), 1670 NULL, _XimEncodeCallback, _XimDecodeCallback}, 1671}; 1672 1673static XimValueOffsetInfoRec ic_sts_attr_info[] = { 1674 {OFFSET_XNAREA, 0, 1675 XOffsetOf(ICStatusAttributes, area), 1676 _XimDefaultArea, _XimEncodeRectangle, _XimDecodeRectangle}, 1677 1678 {OFFSET_XNAREANEEDED, 0, 1679 XOffsetOf(ICStatusAttributes, area_needed), 1680 NULL, _XimEncodeRectangle, _XimDecodeRectangle}, 1681 1682 {OFFSET_XNCOLORMAP, 0, 1683 XOffsetOf(ICStatusAttributes, colormap), 1684 _XimDefaultColormap, _XimEncodeColormap, _XimDecodeColormap}, 1685 1686 {OFFSET_XNSTDCOLORMAP, 0, 1687 XOffsetOf(ICStatusAttributes, std_colormap), 1688 _XimDefaultStdColormap, _XimEncodeStdColormap, _XimDecodeStdColormap}, 1689 1690 {OFFSET_XNFOREGROUND, 0, 1691 XOffsetOf(ICStatusAttributes, foreground), 1692 _XimDefaultFg, _XimEncodeLong, _XimDecodeLong}, 1693 1694 {OFFSET_XNBACKGROUND, 0, 1695 XOffsetOf(ICStatusAttributes, background), 1696 _XimDefaultBg, _XimEncodeLong, _XimDecodeLong}, 1697 1698 {OFFSET_XNBACKGROUNDPIXMAP, 0, 1699 XOffsetOf(ICStatusAttributes, background_pixmap), 1700 _XimDefaultBgPixmap, _XimEncodeBgPixmap, _XimDecodeBgPixmap}, 1701 1702 {OFFSET_XNFONTSET, 0, 1703 XOffsetOf(ICStatusAttributes, fontset), 1704 _XimDefaultFontSet, _XimEncodeFontSet, _XimDecodeFontSet}, 1705 1706 {OFFSET_XNLINESPACE, 0, 1707 XOffsetOf(ICStatusAttributes, line_spacing), 1708 _XimDefaultLineSpace, _XimEncodeLineSpace, _XimDecodeLineSpace}, 1709 1710 {OFFSET_XNCURSOR, 0, 1711 XOffsetOf(ICStatusAttributes, cursor), 1712 _XimDefaultCursor, _XimEncodeCursor, _XimDecodeCursor}, 1713 1714 {OFFSET_XNSTATUSSTARTCALLBACK, 0, 1715 XOffsetOf(ICStatusAttributes, start_callback), 1716 NULL, _XimEncodeCallback, _XimDecodeCallback}, 1717 1718 {OFFSET_XNSTATUSDONECALLBACK, 0, 1719 XOffsetOf(ICStatusAttributes, done_callback), 1720 NULL, _XimEncodeCallback, _XimDecodeCallback}, 1721 1722 {OFFSET_XNSTATUSDRAWCALLBACK, 0, 1723 XOffsetOf(ICStatusAttributes, draw_callback), 1724 NULL, _XimEncodeCallback, _XimDecodeCallback} 1725}; 1726 1727typedef struct _XimIMMode { 1728 unsigned short name_offset; 1729 unsigned short mode; 1730} XimIMMode; 1731 1732static const XimIMMode im_mode[] = { 1733 {OFFSET_XNQUERYINPUTSTYLE, 1734 (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_GET)}, 1735 {OFFSET_XNDESTROYCALLBACK, 1736 (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_SET | XIM_MODE_IM_GET)}, 1737 {OFFSET_XNRESOURCENAME, 1738 (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_SET | XIM_MODE_IM_GET)}, 1739 {OFFSET_XNRESOURCECLASS, 1740 (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_SET | XIM_MODE_IM_GET)}, 1741 {OFFSET_XNQUERYIMVALUESLIST, 1742 (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_GET)}, 1743 {OFFSET_XNQUERYICVALUESLIST, 1744 (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_GET)}, 1745 {OFFSET_XNVISIBLEPOSITION, 1746 (XIM_MODE_IM_DEFAULT | XIM_MODE_IM_GET)} 1747}; 1748 1749typedef struct _XimICMode { 1750 unsigned short name_offset; 1751 unsigned short preedit_callback_mode; 1752 unsigned short preedit_position_mode; 1753 unsigned short preedit_area_mode; 1754 unsigned short preedit_nothing_mode; 1755 unsigned short preedit_none_mode; 1756 unsigned short status_callback_mode; 1757 unsigned short status_area_mode; 1758 unsigned short status_nothing_mode; 1759 unsigned short status_none_mode; 1760} XimICMode; 1761 1762static const XimICMode ic_mode[] = { 1763 {OFFSET_XNINPUTSTYLE, 1764 (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_GET), 1765 (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_GET), 1766 (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_GET), 1767 (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_GET), 1768 (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_GET), 1769 (XIM_MODE_STS_CREATE | XIM_MODE_STS_GET), 1770 (XIM_MODE_STS_CREATE | XIM_MODE_STS_GET), 1771 (XIM_MODE_STS_CREATE | XIM_MODE_STS_GET), 1772 (XIM_MODE_STS_CREATE | XIM_MODE_STS_GET)}, 1773 {OFFSET_XNCLIENTWINDOW, 1774 (XIM_MODE_PRE_ONCE | XIM_MODE_PRE_GET), 1775 (XIM_MODE_PRE_ONCE | XIM_MODE_PRE_GET), 1776 (XIM_MODE_PRE_ONCE | XIM_MODE_PRE_GET), 1777 (XIM_MODE_PRE_ONCE | XIM_MODE_PRE_GET), 1778 0, 1779 (XIM_MODE_STS_ONCE | XIM_MODE_STS_GET), 1780 (XIM_MODE_STS_ONCE | XIM_MODE_STS_GET), 1781 (XIM_MODE_STS_ONCE | XIM_MODE_STS_GET), 1782 0}, 1783 {OFFSET_XNFOCUSWINDOW, 1784 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1785 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1786 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1787 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1788 0, 1789 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1790 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1791 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1792 0}, 1793 {OFFSET_XNRESOURCENAME, 1794 0, 1795 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1796 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1797 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1798 0, 1799 0, 1800 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1801 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1802 0}, 1803 {OFFSET_XNRESOURCECLASS, 1804 0, 1805 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1806 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1807 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1808 0, 1809 0, 1810 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1811 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1812 0}, 1813 {OFFSET_XNGEOMETRYCALLBACK, 1814 0, 1815 0, 1816 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1817 0, 1818 0, 1819 0, 1820 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1821 0, 1822 0}, 1823 {OFFSET_XNFILTEREVENTS, 1824 XIM_MODE_PRE_GET, 1825 XIM_MODE_PRE_GET, 1826 XIM_MODE_PRE_GET, 1827 XIM_MODE_PRE_GET, 1828 0, 1829 XIM_MODE_STS_GET, 1830 XIM_MODE_STS_GET, 1831 XIM_MODE_STS_GET, 1832 XIM_MODE_STS_GET}, 1833 {OFFSET_XNDESTROYCALLBACK, 1834 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1835 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1836 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1837 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1838 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1839 0, 1840 0, 1841 0, 1842 0}, 1843 {OFFSET_XNSTRINGCONVERSIONCALLBACK, 1844 (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1845 (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1846 (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1847 (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1848 (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1849 0, 1850 0, 1851 0, 1852 0}, 1853 {OFFSET_XNSTRINGCONVERSION, 1854 XIM_MODE_PRE_SET, 1855 XIM_MODE_PRE_SET, 1856 XIM_MODE_PRE_SET, 1857 XIM_MODE_PRE_SET, 1858 XIM_MODE_PRE_SET, 1859 0, 1860 0, 1861 0, 1862 0}, 1863 {OFFSET_XNRESETSTATE, 1864 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1865 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1866 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1867 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1868 0, 1869 0, 1870 0, 1871 0, 1872 0}, 1873 {OFFSET_XNHOTKEY, 1874 (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1875 (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1876 (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1877 (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1878 0, 1879 0, 1880 0, 1881 0, 1882 0}, 1883 {OFFSET_XNHOTKEYSTATE, 1884 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1885 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1886 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1887 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1888 0, 1889 0, 1890 0, 1891 0, 1892 0}, 1893 {OFFSET_XNPREEDITATTRIBUTES, 1894 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1895 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1896 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1897 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1898 0, 1899 0, 1900 0, 1901 0, 1902 0}, 1903 {OFFSET_XNSTATUSATTRIBUTES, 1904 0, 1905 0, 1906 0, 1907 0, 1908 0, 1909 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1910 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1911 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1912 0}, 1913 {OFFSET_XNAREA, 1914 0, 1915 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1916 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1917 0, 1918 0, 1919 0, 1920 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1921 0, 1922 0}, 1923 {OFFSET_XNAREANEEDED, 1924 0, 1925 0, 1926 (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1927 0, 1928 0, 1929 0, 1930 (XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1931 0, 1932 0}, 1933 {OFFSET_XNSPOTLOCATION, 1934 0, /*(XIM_MODE_PRE_SET | XIM_MODE_PRE_GET),*/ 1935 (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1936 0, 1937 (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1938 (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1939 0, 1940 0, 1941 0, 1942 0}, 1943 {OFFSET_XNCOLORMAP, 1944 0, 1945 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1946 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1947 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1948 0, 1949 0, 1950 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1951 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1952 0}, 1953 {OFFSET_XNSTDCOLORMAP, 1954 0, 1955 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1956 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1957 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1958 0, 1959 0, 1960 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1961 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1962 0}, 1963 {OFFSET_XNFOREGROUND, 1964 0, 1965 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1966 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1967 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1968 0, 1969 0, 1970 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1971 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1972 0}, 1973 {OFFSET_XNBACKGROUND, 1974 0, 1975 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1976 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1977 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1978 0, 1979 0, 1980 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1981 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1982 0}, 1983 {OFFSET_XNBACKGROUNDPIXMAP, 1984 0, 1985 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1986 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1987 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1988 0, 1989 0, 1990 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1991 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 1992 0}, 1993 {OFFSET_XNFONTSET, 1994 0, 1995 (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1996 (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1997 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 1998 0, 1999 0, 2000 (XIM_MODE_STS_CREATE | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 2001 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 2002 0}, 2003 {OFFSET_XNLINESPACE, 2004 0, 2005 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2006 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2007 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2008 0, 2009 0, 2010 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 2011 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 2012 0}, 2013 {OFFSET_XNCURSOR, 2014 0, 2015 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2016 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2017 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2018 0, 2019 0, 2020 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 2021 (XIM_MODE_STS_DEFAULT | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 2022 0}, 2023 {OFFSET_XNPREEDITSTARTCALLBACK, 2024 (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2025 0, 2026 0, 2027 0, 2028 0, 2029 0, 2030 0, 2031 0, 2032 0}, 2033 {OFFSET_XNPREEDITDONECALLBACK, 2034 (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2035 0, 2036 0, 2037 0, 2038 0, 2039 0, 2040 0, 2041 0, 2042 0}, 2043 {OFFSET_XNPREEDITDRAWCALLBACK, 2044 (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2045 0, 2046 0, 2047 0, 2048 0, 2049 0, 2050 0, 2051 0, 2052 0}, 2053 {OFFSET_XNPREEDITCARETCALLBACK, 2054 (XIM_MODE_PRE_CREATE | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2055 0, 2056 0, 2057 0, 2058 0, 2059 0, 2060 0, 2061 0, 2062 0}, 2063 {OFFSET_XNPREEDITSTATE, 2064 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2065 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2066 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2067 (XIM_MODE_PRE_DEFAULT | XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2068 0, 2069 0, 2070 0, 2071 0, 2072 0}, 2073 {OFFSET_XNPREEDITSTATENOTIFYCALLBACK, 2074 (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2075 (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2076 (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2077 (XIM_MODE_PRE_SET | XIM_MODE_PRE_GET), 2078 0, 2079 0, 2080 0, 2081 0, 2082 0}, 2083 {OFFSET_XNSTATUSSTARTCALLBACK, 2084 0, 2085 0, 2086 0, 2087 0, 2088 0, 2089 (XIM_MODE_STS_CREATE | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 2090 0, 2091 0, 2092 0}, 2093 {OFFSET_XNSTATUSDONECALLBACK, 2094 0, 2095 0, 2096 0, 2097 0, 2098 0, 2099 (XIM_MODE_STS_CREATE | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 2100 0, 2101 0, 2102 0}, 2103 {OFFSET_XNSTATUSDRAWCALLBACK, 2104 0, 2105 0, 2106 0, 2107 0, 2108 0, 2109 (XIM_MODE_STS_CREATE | XIM_MODE_STS_SET | XIM_MODE_STS_GET), 2110 0, 2111 0, 2112 0} 2113}; 2114 2115/* the quarks are separated from im_mode/ic_mode so those arrays 2116 * can be const. 2117 */ 2118static XrmQuark im_mode_quark[sizeof(im_mode) / sizeof(im_mode[0])]; 2119static XrmQuark ic_mode_quark[sizeof(ic_mode) / sizeof(ic_mode[0])]; 2120 2121static Bool 2122_XimSetResourceList( 2123 XIMResourceList *res_list, 2124 unsigned int *list_num, 2125 XIMResourceList resource, 2126 unsigned int num_resource, 2127 unsigned short id) 2128{ 2129 register int i; 2130 int len; 2131 XIMResourceList res; 2132 2133 len = sizeof(XIMResource) * num_resource; 2134 if(!(res = Xcalloc(1, len))) { 2135 return False; 2136 } 2137 2138 for(i = 0; i < num_resource; i++, id++) { 2139 res[i] = resource[i]; 2140 res[i].id = id; 2141 } 2142 2143 _XIMCompileResourceList(res, num_resource); 2144 *res_list = res; 2145 *list_num = num_resource; 2146 return True; 2147} 2148 2149Bool 2150_XimSetIMResourceList( 2151 XIMResourceList *res_list, 2152 unsigned int *list_num) 2153{ 2154 return _XimSetResourceList(res_list, list_num, 2155 im_resources, XIMNumber(im_resources), 100); 2156} 2157 2158Bool 2159_XimSetICResourceList( 2160 XIMResourceList *res_list, 2161 unsigned int *list_num) 2162{ 2163 return _XimSetResourceList(res_list, list_num, 2164 ic_resources, XIMNumber(ic_resources), 200); 2165} 2166 2167Bool 2168_XimSetInnerIMResourceList( 2169 XIMResourceList *res_list, 2170 unsigned int *list_num) 2171{ 2172 return _XimSetResourceList(res_list, list_num, 2173 im_inner_resources, XIMNumber(im_inner_resources), 100); 2174} 2175 2176Bool 2177_XimSetInnerICResourceList( 2178 XIMResourceList *res_list, 2179 unsigned int *list_num) 2180{ 2181 return _XimSetResourceList(res_list, list_num, 2182 ic_inner_resources, XIMNumber(ic_inner_resources), 200); 2183} 2184 2185static XIMResourceList 2186_XimGetResourceListRecByMode( 2187 XIMResourceList res_list, 2188 unsigned int list_num, 2189 unsigned short mode) 2190{ 2191 register int i; 2192 2193 for(i = 0; i < list_num; i++) { 2194 if (res_list[i].mode & mode) { 2195 return (XIMResourceList)&res_list[i]; 2196 } 2197 } 2198 return (XIMResourceList)NULL; 2199} 2200 2201Bool 2202_XimCheckCreateICValues( 2203 XIMResourceList res_list, 2204 unsigned int list_num) 2205{ 2206 if (!_XimGetResourceListRecByMode(res_list, list_num, XIM_MODE_IC_CREATE)) { 2207 return True; 2208 } 2209 return False; 2210} 2211 2212XIMResourceList 2213_XimGetResourceListRecByQuark( 2214 XIMResourceList res_list, 2215 unsigned int list_num, 2216 XrmQuark quark) 2217{ 2218 register int i; 2219 2220 for(i = 0; i < list_num; i++) { 2221 if (res_list[i].xrm_name == quark) { 2222 return (XIMResourceList)&res_list[i]; 2223 } 2224 } 2225 return (XIMResourceList)NULL; 2226} 2227 2228XIMResourceList 2229_XimGetResourceListRec( 2230 XIMResourceList res_list, 2231 unsigned int list_num, 2232 const char *name) 2233{ 2234 XrmQuark quark = XrmStringToQuark(name); 2235 2236 return _XimGetResourceListRecByQuark(res_list, list_num, quark); 2237} 2238 2239char * 2240_XimSetIMValueData( 2241 Xim im, 2242 XPointer top, 2243 XIMArg *values, 2244 XIMResourceList res_list, 2245 unsigned int list_num) 2246{ 2247 register XIMArg *p; 2248 XIMResourceList res; 2249 int check; 2250 2251 for(p = values; p->name != NULL; p++) { 2252 if(!(res = _XimGetResourceListRec(res_list, list_num, p->name))) { 2253 return p->name; 2254 } 2255 check = _XimCheckIMMode(res, XIM_SETIMVALUES); 2256 if(check == XIM_CHECK_INVALID) { 2257 continue; 2258 } else if (check == XIM_CHECK_ERROR) { 2259 return p->name; 2260 } 2261 2262 if(!_XimEncodeLocalIMAttr(res, top, p->value)) { 2263 return p->name; 2264 } 2265 } 2266 return NULL; 2267} 2268 2269char * 2270_XimGetIMValueData( 2271 Xim im, 2272 XPointer top, 2273 XIMArg *values, 2274 XIMResourceList res_list, 2275 unsigned int list_num) 2276{ 2277 register XIMArg *p; 2278 XIMResourceList res; 2279 int check; 2280 2281 for(p = values; p->name != NULL; p++) { 2282 if(!(res = _XimGetResourceListRec(res_list, list_num, p->name))) { 2283 return p->name; 2284 } 2285 check = _XimCheckIMMode(res, XIM_GETIMVALUES); 2286 if(check == XIM_CHECK_INVALID) { 2287 continue; 2288 } else if (check == XIM_CHECK_ERROR) { 2289 return p->name; 2290 } 2291 2292 if(!_XimDecodeLocalIMAttr(res, top, p->value)) { 2293 return p->name; 2294 } 2295 } 2296 return NULL; 2297} 2298 2299void 2300_XimSetIMMode( 2301 XIMResourceList res_list, 2302 unsigned int list_num) 2303{ 2304 XIMResourceList res; 2305 unsigned int n = XIMNumber(im_mode); 2306 register int i; 2307 2308 for(i = 0; i < n; i++) { 2309 if(!(res = _XimGetResourceListRecByQuark(res_list, 2310 list_num, im_mode_quark[i]))) { 2311 continue; 2312 } 2313 res->mode = im_mode[i].mode; 2314 } 2315 return; 2316} 2317 2318static int 2319_XimCheckSetIMDefaultsMode( 2320 XIMResourceList res) 2321{ 2322 if(res->mode & XIM_MODE_IM_DEFAULT) { 2323 return XIM_CHECK_VALID; 2324 } 2325 return XIM_CHECK_INVALID; 2326} 2327 2328static int 2329_XimCheckSetIMValuesMode( 2330 XIMResourceList res) 2331{ 2332 if(res->mode & XIM_MODE_IM_SET) { 2333 return XIM_CHECK_VALID; 2334 } 2335 return XIM_CHECK_INVALID; 2336} 2337 2338static int 2339 _XimCheckGetIMValuesMode( 2340 XIMResourceList res) 2341{ 2342 if(res->mode & XIM_MODE_IM_GET) { 2343 return XIM_CHECK_VALID; 2344 } 2345 return XIM_CHECK_INVALID; 2346} 2347 2348int 2349 _XimCheckIMMode( 2350 XIMResourceList res, 2351 unsigned long mode) 2352{ 2353 if(res->mode == 0) { 2354 return XIM_CHECK_INVALID; 2355 } 2356 if(mode & XIM_SETIMDEFAULTS) { 2357 return _XimCheckSetIMDefaultsMode(res); 2358 } else if (mode & XIM_SETIMVALUES) { 2359 return _XimCheckSetIMValuesMode(res); 2360 } else if (mode & XIM_GETIMVALUES) { 2361 return _XimCheckGetIMValuesMode(res); 2362 } else { 2363 return XIM_CHECK_ERROR; 2364 } 2365} 2366 2367void 2368_XimSetICMode(XIMResourceList res_list, unsigned int list_num, XIMStyle style) 2369{ 2370 XIMResourceList res; 2371 unsigned int n = XIMNumber(ic_mode); 2372 register int i; 2373 unsigned int pre_offset; 2374 unsigned int sts_offset; 2375 2376 if(style & XIMPreeditArea) { 2377 pre_offset = XOffsetOf(XimICMode, preedit_area_mode); 2378 } else if(style & XIMPreeditCallbacks) { 2379 pre_offset = XOffsetOf(XimICMode, preedit_callback_mode); 2380 } else if(style & XIMPreeditPosition) { 2381 pre_offset = XOffsetOf(XimICMode, preedit_position_mode); 2382 } else if(style & XIMPreeditNothing) { 2383 pre_offset = XOffsetOf(XimICMode, preedit_nothing_mode); 2384 } else { 2385 pre_offset = XOffsetOf(XimICMode, preedit_none_mode); 2386 } 2387 2388 if(style & XIMStatusArea) { 2389 sts_offset = XOffsetOf(XimICMode, status_area_mode); 2390 } else if(style & XIMStatusCallbacks) { 2391 sts_offset = XOffsetOf(XimICMode, status_callback_mode); 2392 } else if(style & XIMStatusNothing) { 2393 sts_offset = XOffsetOf(XimICMode, status_nothing_mode); 2394 } else { 2395 sts_offset = XOffsetOf(XimICMode, status_none_mode); 2396 } 2397 2398 for(i = 0; i < n; i++) { 2399 if(!(res = _XimGetResourceListRecByQuark(res_list, 2400 list_num, ic_mode_quark[i]))) { 2401 continue; 2402 } 2403 res->mode = ( (*(unsigned short *)((char *)&ic_mode[i] + pre_offset)) 2404 | (*(unsigned short *)((char *)&ic_mode[i] + sts_offset))); 2405 } 2406 return; 2407} 2408 2409static int 2410_XimCheckSetICDefaultsMode( 2411 XIMResourceList res, 2412 unsigned long mode) 2413{ 2414 if(mode & XIM_PREEDIT_ATTR) { 2415 if(!(res->mode & XIM_MODE_PRE_MASK)) { 2416 return XIM_CHECK_INVALID; 2417 } 2418 2419 if(res->mode & XIM_MODE_PRE_CREATE) { 2420 return XIM_CHECK_ERROR; 2421 } else if (!(res->mode & XIM_MODE_PRE_DEFAULT)) { 2422 return XIM_CHECK_INVALID; 2423 } 2424 2425 } else if(mode & XIM_STATUS_ATTR) { 2426 if(!(res->mode & XIM_MODE_STS_MASK)) { 2427 return XIM_CHECK_INVALID; 2428 } 2429 2430 if(res->mode & XIM_MODE_STS_CREATE) { 2431 return XIM_CHECK_ERROR; 2432 } 2433 if(!(res->mode & XIM_MODE_STS_DEFAULT)) { 2434 return XIM_CHECK_INVALID; 2435 } 2436 2437 } else { 2438 if(!res->mode) { 2439 return XIM_CHECK_INVALID; 2440 } 2441 2442 if(res->mode & XIM_MODE_IC_CREATE) { 2443 return XIM_CHECK_ERROR; 2444 } 2445 if(!(res->mode & XIM_MODE_IC_DEFAULT)) { 2446 return XIM_CHECK_INVALID; 2447 } 2448 } 2449 return XIM_CHECK_VALID; 2450} 2451 2452static int 2453_XimCheckCreateICMode( 2454 XIMResourceList res, 2455 unsigned long mode) 2456{ 2457 if(mode & XIM_PREEDIT_ATTR) { 2458 if(!(res->mode & XIM_MODE_PRE_MASK)) { 2459 return XIM_CHECK_INVALID; 2460 } 2461 2462 if(res->mode & XIM_MODE_PRE_CREATE) { 2463 res->mode &= ~XIM_MODE_PRE_CREATE; 2464 } else if(res->mode & XIM_MODE_PRE_ONCE) { 2465 res->mode &= ~XIM_MODE_PRE_ONCE; 2466 } else if(res->mode & XIM_MODE_PRE_DEFAULT) { 2467 res->mode &= ~XIM_MODE_PRE_DEFAULT; 2468 } else if (!(res->mode & XIM_MODE_PRE_SET)) { 2469 return XIM_CHECK_ERROR; 2470 } 2471 2472 } else if(mode & XIM_STATUS_ATTR) { 2473 if(!(res->mode & XIM_MODE_STS_MASK)) { 2474 return XIM_CHECK_INVALID; 2475 } 2476 2477 if(res->mode & XIM_MODE_STS_CREATE) { 2478 res->mode &= ~XIM_MODE_STS_CREATE; 2479 } else if(res->mode & XIM_MODE_STS_ONCE) { 2480 res->mode &= ~XIM_MODE_STS_ONCE; 2481 } else if(res->mode & XIM_MODE_STS_DEFAULT) { 2482 res->mode &= ~XIM_MODE_STS_DEFAULT; 2483 } else if (!(res->mode & XIM_MODE_STS_SET)) { 2484 return XIM_CHECK_ERROR; 2485 } 2486 2487 } else { 2488 if(!res->mode) { 2489 return XIM_CHECK_INVALID; 2490 } 2491 2492 if(res->mode & XIM_MODE_IC_CREATE) { 2493 res->mode &= ~XIM_MODE_IC_CREATE; 2494 } else if(res->mode & XIM_MODE_IC_ONCE) { 2495 res->mode &= ~XIM_MODE_IC_ONCE; 2496 } else if(res->mode & XIM_MODE_IC_DEFAULT) { 2497 res->mode &= ~XIM_MODE_IC_DEFAULT; 2498 } else if (!(res->mode & XIM_MODE_IC_SET)) { 2499 return XIM_CHECK_ERROR; 2500 } 2501 } 2502 return XIM_CHECK_VALID; 2503} 2504 2505static int 2506_XimCheckSetICValuesMode( 2507 XIMResourceList res, 2508 unsigned long mode) 2509{ 2510 if(mode & XIM_PREEDIT_ATTR) { 2511 if(!(res->mode & XIM_MODE_PRE_MASK)) { 2512 return XIM_CHECK_INVALID; 2513 } 2514 2515 if(res->mode & XIM_MODE_PRE_ONCE) { 2516 res->mode &= ~XIM_MODE_PRE_ONCE; 2517 } else if(!(res->mode & XIM_MODE_PRE_SET)) { 2518 return XIM_CHECK_ERROR; 2519 } 2520 2521 } else if(mode & XIM_STATUS_ATTR) { 2522 if(!(res->mode & XIM_MODE_STS_MASK)) { 2523 return XIM_CHECK_INVALID; 2524 } 2525 2526 if(res->mode & XIM_MODE_STS_ONCE) { 2527 res->mode &= ~XIM_MODE_STS_ONCE; 2528 } else if(!(res->mode & XIM_MODE_STS_SET)) { 2529 return XIM_CHECK_ERROR; 2530 } 2531 2532 } else { 2533 if(!res->mode) { 2534 return XIM_CHECK_INVALID; 2535 } 2536 2537 if(res->mode & XIM_MODE_IC_ONCE) { 2538 res->mode &= ~XIM_MODE_IC_ONCE; 2539 } else if(!(res->mode & XIM_MODE_IC_SET)) { 2540 return XIM_CHECK_ERROR; 2541 } 2542 } 2543 return XIM_CHECK_VALID; 2544} 2545 2546static int 2547_XimCheckGetICValuesMode( 2548 XIMResourceList res, 2549 unsigned long mode) 2550{ 2551 if(mode & XIM_PREEDIT_ATTR) { 2552 if(!(res->mode & XIM_MODE_PRE_MASK)) { 2553 return XIM_CHECK_INVALID; 2554 } 2555 2556 if(!(res->mode & XIM_MODE_PRE_GET)) { 2557 return XIM_CHECK_ERROR; 2558 } 2559 2560 } else if(mode & XIM_STATUS_ATTR) { 2561 if(!(res->mode & XIM_MODE_STS_MASK)) { 2562 return XIM_CHECK_INVALID; 2563 } 2564 2565 if(!(res->mode & XIM_MODE_STS_GET)) { 2566 return XIM_CHECK_ERROR; 2567 } 2568 2569 } else { 2570 if(!res->mode) { 2571 return XIM_CHECK_INVALID; 2572 } 2573 2574 if(!(res->mode & XIM_MODE_IC_GET)) { 2575 return XIM_CHECK_ERROR; 2576 } 2577 } 2578 return XIM_CHECK_VALID; 2579} 2580 2581int 2582 _XimCheckICMode( 2583 XIMResourceList res, 2584 unsigned long mode) 2585{ 2586 if(mode &XIM_SETICDEFAULTS) { 2587 return _XimCheckSetICDefaultsMode(res, mode); 2588 } else if (mode & XIM_CREATEIC) { 2589 return _XimCheckCreateICMode(res, mode); 2590 } else if (mode & XIM_SETICVALUES) { 2591 return _XimCheckSetICValuesMode(res, mode); 2592 } else if (mode & XIM_GETICVALUES) { 2593 return _XimCheckGetICValuesMode(res, mode); 2594 } else { 2595 return XIM_CHECK_ERROR; 2596 } 2597} 2598 2599Bool 2600_XimSetLocalIMDefaults( 2601 Xim im, 2602 XPointer top, 2603 XIMResourceList res_list, 2604 unsigned int list_num) 2605{ 2606 XimValueOffsetInfo info; 2607 unsigned int num; 2608 register int i; 2609 XIMResourceList res; 2610 int check; 2611 2612 info = im_attr_info; 2613 num = XIMNumber(im_attr_info); 2614 2615 for(i = 0; i < num; i++) { 2616 if((res = _XimGetResourceListRecByQuark( res_list, list_num, 2617 info[i].quark)) == (XIMResourceList)NULL) { 2618 return False; 2619 } 2620 2621 check = _XimCheckIMMode(res, XIM_SETIMDEFAULTS); 2622 if(check == XIM_CHECK_INVALID) { 2623 continue; 2624 } else if (check == XIM_CHECK_ERROR) { 2625 return False; 2626 } 2627 2628 if(!info[i].defaults) { 2629 continue; 2630 } 2631 if(!(info[i].defaults(&info[i], top, (XPointer)NULL, 0))) { 2632 return False; 2633 } 2634 } 2635 return True; 2636} 2637 2638Bool 2639_XimSetICDefaults( 2640 Xic ic, 2641 XPointer top, 2642 unsigned long mode, 2643 XIMResourceList res_list, 2644 unsigned int list_num) 2645{ 2646 unsigned int num; 2647 XimValueOffsetInfo info; 2648 register int i; 2649 XIMResourceList res; 2650 int check; 2651 XrmQuark pre_quark; 2652 XrmQuark sts_quark; 2653 2654 pre_quark = XrmStringToQuark(XNPreeditAttributes); 2655 sts_quark = XrmStringToQuark(XNStatusAttributes); 2656 2657 if(mode & XIM_PREEDIT_ATTR) { 2658 info = ic_pre_attr_info; 2659 num = XIMNumber(ic_pre_attr_info); 2660 } else if(mode & XIM_STATUS_ATTR) { 2661 info = ic_sts_attr_info; 2662 num = XIMNumber(ic_sts_attr_info); 2663 } else { 2664 info = ic_attr_info; 2665 num = XIMNumber(ic_attr_info); 2666 } 2667 2668 for(i = 0; i < num; i++) { 2669 if(info[i].quark == pre_quark) { 2670 if(!_XimSetICDefaults(ic, (XPointer)((char *)top + info[i].offset), 2671 (mode | XIM_PREEDIT_ATTR), res_list, list_num)) { 2672 return False; 2673 } 2674 } else if (info[i].quark == sts_quark) { 2675 if(!_XimSetICDefaults(ic, (XPointer)((char *)top + info[i].offset), 2676 (mode | XIM_STATUS_ATTR), res_list, list_num)) { 2677 return False; 2678 } 2679 } else { 2680 if(!(res = _XimGetResourceListRecByQuark(res_list, list_num, 2681 info[i].quark))) { 2682 return False; 2683 } 2684 2685 check = _XimCheckICMode(res, mode); 2686 if (check == XIM_CHECK_INVALID) { 2687 continue; 2688 } else if (check == XIM_CHECK_ERROR) { 2689 return False; 2690 } 2691 2692 if (!info[i].defaults) { 2693 continue; 2694 } 2695 if (!(info[i].defaults(&info[i], top, (XPointer)ic, mode))) { 2696 return False; 2697 } 2698 } 2699 } 2700 return True; 2701} 2702 2703static Bool 2704_XimEncodeAttr( 2705 XimValueOffsetInfo info, 2706 unsigned int num, 2707 XIMResourceList res, 2708 XPointer top, 2709 XPointer val) 2710{ 2711 register int i; 2712 2713 for(i = 0; i < num; i++ ) { 2714 if(info[i].quark == res->xrm_name) { 2715 if(!info[i].encode) { 2716 return False; 2717 } 2718 return (*info[i].encode)(&info[i], top, val); 2719 } 2720 } 2721 return False; 2722} 2723 2724Bool 2725_XimEncodeLocalIMAttr( 2726 XIMResourceList res, 2727 XPointer top, 2728 XPointer val) 2729{ 2730 return _XimEncodeAttr(im_attr_info, XIMNumber(im_attr_info), 2731 res, top, val); 2732} 2733 2734Bool 2735_XimEncodeLocalICAttr( 2736 Xic ic, 2737 XIMResourceList res, 2738 XPointer top, 2739 XIMArg *arg, 2740 unsigned long mode) 2741{ 2742 unsigned int num; 2743 XimValueOffsetInfo info; 2744 2745 if(mode & XIM_PREEDIT_ATTR) { 2746 info = ic_pre_attr_info; 2747 num = XIMNumber(ic_pre_attr_info); 2748 } else if(mode & XIM_STATUS_ATTR) { 2749 info = ic_sts_attr_info; 2750 num = XIMNumber(ic_sts_attr_info); 2751 } else { 2752 info = ic_attr_info; 2753 num = XIMNumber(ic_attr_info); 2754 } 2755 2756 return _XimEncodeAttr(info, num, res, top, arg->value); 2757} 2758 2759static Bool 2760_XimEncodeLocalTopValue( 2761 Xic ic, 2762 XIMResourceList res, 2763 XPointer val, 2764 Bool flag) 2765{ 2766 XIMArg *p = (XIMArg *)val; 2767 2768 if (res->xrm_name == XrmStringToQuark(XNClientWindow)) { 2769 ic->core.client_window = (Window)p->value; 2770 if (ic->core.focus_window == (Window)0) 2771 ic->core.focus_window = ic->core.client_window; 2772 if (flag) { 2773 _XRegisterFilterByType(ic->core.im->core.display, 2774 ic->core.focus_window, 2775 KeyPress, KeyRelease, _XimLocalFilter, (XPointer)ic); 2776 } 2777 } else if (res->xrm_name == XrmStringToQuark(XNFocusWindow)) { 2778 if (ic->core.client_window) { 2779 if (flag) { 2780 _XUnregisterFilter(ic->core.im->core.display, 2781 ic->core.focus_window, _XimLocalFilter, (XPointer)ic); 2782 } 2783 ic->core.focus_window = (Window)p->value; 2784 if (flag) { 2785 _XRegisterFilterByType(ic->core.im->core.display, 2786 ic->core.focus_window, KeyPress, KeyRelease, 2787 _XimLocalFilter, (XPointer)ic); 2788 } 2789 } else 2790 ic->core.focus_window = (Window)p->value; 2791 } 2792 return True; 2793} 2794 2795static Bool 2796_XimEncodeLocalPreeditValue( 2797 Xic ic, 2798 XIMResourceList res, 2799 XPointer val) 2800{ 2801 XIMArg *p = (XIMArg *)val; 2802 2803 if (res->xrm_name == XrmStringToQuark(XNStdColormap)) { 2804 XStandardColormap *colormap_ret; 2805 int count; 2806 2807 if (!(XGetRGBColormaps(ic->core.im->core.display, 2808 ic->core.focus_window, &colormap_ret, 2809 &count, (Atom)p->value))) 2810 return False; 2811 2812 Xfree(colormap_ret); 2813 } 2814 return True; 2815} 2816 2817static Bool 2818_XimEncodeLocalStatusValue( 2819 Xic ic, 2820 XIMResourceList res, 2821 XPointer val) 2822{ 2823 XIMArg *p = (XIMArg *)val; 2824 2825 if (res->xrm_name == XrmStringToQuark(XNStdColormap)) { 2826 XStandardColormap *colormap_ret; 2827 int count; 2828 2829 if (!(XGetRGBColormaps(ic->core.im->core.display, 2830 ic->core.focus_window, &colormap_ret, 2831 &count, (Atom)p->value))) 2832 return False; 2833 2834 Xfree(colormap_ret); 2835 } 2836 return True; 2837} 2838 2839char * 2840_XimSetICValueData( 2841 Xic ic, 2842 XPointer top, 2843 XIMResourceList res_list, 2844 unsigned int list_num, 2845 XIMArg *values, 2846 unsigned long mode, 2847 Bool flag) 2848{ 2849 register XIMArg *p; 2850 XIMResourceList res; 2851 char *name; 2852 int check; 2853 XrmQuark pre_quark; 2854 XrmQuark sts_quark; 2855 2856 pre_quark = XrmStringToQuark(XNPreeditAttributes); 2857 sts_quark = XrmStringToQuark(XNStatusAttributes); 2858 2859 for(p = values; p->name != NULL; p++) { 2860 if((res = _XimGetResourceListRec(res_list, list_num, 2861 p->name)) == (XIMResourceList)NULL) { 2862 return p->name; 2863 } 2864 if(res->xrm_name == pre_quark) { 2865 if(((name = _XimSetICValueData(ic, 2866 (XPointer)(&((XimDefICValues *)top)->preedit_attr), 2867 res_list, list_num, (XIMArg *)p->value, 2868 (mode | XIM_PREEDIT_ATTR), flag)))) { 2869 return name; 2870 } 2871 } else if(res->xrm_name == sts_quark) { 2872 if(((name = _XimSetICValueData(ic, 2873 (XPointer)(&((XimDefICValues *)top)->status_attr), 2874 res_list, list_num, (XIMArg *)p->value, 2875 (mode | XIM_STATUS_ATTR), flag)))) { 2876 return name; 2877 } 2878 } else { 2879 check = _XimCheckICMode(res, mode); 2880 if(check == XIM_CHECK_INVALID) { 2881 continue; 2882 } else if(check == XIM_CHECK_ERROR) { 2883 return p->name; 2884 } 2885 2886 if(mode & XIM_PREEDIT_ATTR) { 2887 if (!_XimEncodeLocalPreeditValue(ic, res, (XPointer)p)) 2888 return p->name; 2889 } else if(mode & XIM_STATUS_ATTR) { 2890 if (!_XimEncodeLocalStatusValue(ic, res, (XPointer)p)) 2891 return p->name; 2892 } else { 2893 if (!_XimEncodeLocalTopValue(ic, res, (XPointer)p, flag)) 2894 return p->name; 2895 } 2896 if(_XimEncodeLocalICAttr(ic, res, top, p, mode) == False) { 2897 return p->name; 2898 } 2899 } 2900 } 2901 return NULL; 2902} 2903 2904static Bool 2905_XimCheckInputStyle( 2906 XIMStyles *styles, 2907 XIMStyle style) 2908{ 2909 int num = styles->count_styles; 2910 register int i; 2911 2912 for(i = 0; i < num; i++) { 2913 if(styles->supported_styles[i] == style) { 2914 return True; 2915 } 2916 } 2917 return False; 2918} 2919 2920Bool 2921_XimCheckLocalInputStyle( 2922 Xic ic, 2923 XPointer top, 2924 XIMArg *values, 2925 XIMStyles *styles, 2926 XIMResourceList res_list, 2927 unsigned int list_num) 2928{ 2929 XrmQuark quark = XrmStringToQuark(XNInputStyle); 2930 register XIMArg *p; 2931 XIMResourceList res; 2932 2933 for(p = values; p && p->name != NULL; p++) { 2934 if(quark == XrmStringToQuark(p->name)) { 2935 if(!(res = _XimGetResourceListRec(res_list, list_num, p->name))) { 2936 return False; 2937 } 2938 if(!_XimEncodeLocalICAttr(ic, res, top, p, 0)) { 2939 return False; 2940 } 2941 if (_XimCheckInputStyle(styles, 2942 ((XimDefICValues *)top)->input_style)) { 2943 return True; 2944 } 2945 return False; 2946 } 2947 } 2948 return False; 2949} 2950 2951static Bool 2952_XimDecodeAttr( 2953 XimValueOffsetInfo info, 2954 unsigned int num, 2955 XIMResourceList res, 2956 XPointer top, 2957 XPointer val) 2958{ 2959 register int i; 2960 2961 for(i = 0; i < num; i++ ) { 2962 if(info[i].quark == res->xrm_name) { 2963 if(!info[i].decode) { 2964 return False; 2965 } 2966 return (*info[i].decode)(&info[i], top, val); 2967 } 2968 } 2969 return False; 2970} 2971 2972Bool 2973_XimDecodeLocalIMAttr( 2974 XIMResourceList res, 2975 XPointer top, 2976 XPointer val) 2977{ 2978 return _XimDecodeAttr(im_attr_info, XIMNumber(im_attr_info), 2979 res, top, val); 2980} 2981 2982Bool 2983_XimDecodeLocalICAttr( 2984 XIMResourceList res, 2985 XPointer top, 2986 XPointer val, 2987 unsigned long mode) 2988{ 2989 unsigned int num; 2990 XimValueOffsetInfo info; 2991 2992 if(mode & XIM_PREEDIT_ATTR) { 2993 info = ic_pre_attr_info; 2994 num = XIMNumber(ic_pre_attr_info); 2995 } else if(mode & XIM_STATUS_ATTR) { 2996 info = ic_sts_attr_info; 2997 num = XIMNumber(ic_sts_attr_info); 2998 } else { 2999 info = ic_attr_info; 3000 num = XIMNumber(ic_attr_info); 3001 } 3002 3003 return _XimDecodeAttr(info, num, res, top, val); 3004} 3005 3006char * 3007_XimGetICValueData(Xic ic, XPointer top, XIMResourceList res_list, 3008 unsigned int list_num, XIMArg *values, unsigned long mode) 3009{ 3010 register XIMArg *p; 3011 XIMResourceList res; 3012 char *name; 3013 int check; 3014 XrmQuark pre_quark; 3015 XrmQuark sts_quark; 3016 3017 pre_quark = XrmStringToQuark(XNPreeditAttributes); 3018 sts_quark = XrmStringToQuark(XNStatusAttributes); 3019 3020 for(p = values; p->name != NULL; p++) { 3021 if((res = _XimGetResourceListRec(res_list, list_num, 3022 p->name)) == (XIMResourceList)NULL) { 3023 return p->name; 3024 } 3025 if(res->xrm_name == pre_quark) { 3026 if((name = _XimGetICValueData(ic, 3027 (XPointer)(&((XimDefICValues *)top)->preedit_attr), 3028 res_list, list_num, (XIMArg *)p->value, 3029 (mode | XIM_PREEDIT_ATTR)))) { 3030 return name; 3031 } 3032 } else if(res->xrm_name == sts_quark) { 3033 if((name = _XimGetICValueData(ic, 3034 (XPointer)(&((XimDefICValues *)top)->status_attr), 3035 res_list, list_num, (XIMArg *)p->value, 3036 (mode | XIM_STATUS_ATTR)))) { 3037 return name; 3038 } 3039 } else { 3040 check = _XimCheckICMode(res, mode); 3041 if(check == XIM_CHECK_INVALID) { 3042 continue; 3043 } else if(check == XIM_CHECK_ERROR) { 3044 return p->name; 3045 } 3046 3047 if(_XimDecodeLocalICAttr(res, top, p->value, mode) == False) { 3048 return p->name; 3049 } 3050 } 3051 } 3052 return NULL; 3053} 3054 3055void 3056_XimGetCurrentIMValues(Xim im, XimDefIMValues *im_values) 3057{ 3058 bzero((char *)im_values, sizeof(XimDefIMValues)); 3059 3060 im_values->styles = im->core.styles; 3061 im_values->im_values_list = im->core.im_values_list; 3062 im_values->ic_values_list = im->core.ic_values_list; 3063 im_values->destroy_callback = im->core.destroy_callback; 3064 im_values->res_name = im->core.res_name; 3065 im_values->res_class = im->core.res_class; 3066 im_values->visible_position = im->core.visible_position; 3067} 3068 3069void 3070_XimSetCurrentIMValues(Xim im, XimDefIMValues *im_values) 3071{ 3072 im->core.styles = im_values->styles; 3073 im->core.im_values_list = im_values->im_values_list; 3074 im->core.ic_values_list = im_values->ic_values_list; 3075 im->core.destroy_callback = im_values->destroy_callback; 3076 im->core.res_name = im_values->res_name; 3077 im->core.res_class = im_values->res_class; 3078 im->core.visible_position = im_values->visible_position; 3079} 3080 3081void 3082_XimGetCurrentICValues(Xic ic, XimDefICValues *ic_values) 3083{ 3084 bzero((char *)ic_values, sizeof(XimDefICValues)); 3085 3086 ic_values->input_style = ic->core.input_style; 3087 ic_values->client_window = ic->core.client_window; 3088 ic_values->focus_window = ic->core.focus_window; 3089 ic_values->filter_events = ic->core.filter_events; 3090 ic_values->geometry_callback = ic->core.geometry_callback; 3091 ic_values->res_name = ic->core.res_name; 3092 ic_values->res_class = ic->core.res_class; 3093 ic_values->destroy_callback = ic->core.destroy_callback; 3094 ic_values->string_conversion_callback 3095 = ic->core.string_conversion_callback; 3096 ic_values->string_conversion = ic->core.string_conversion; 3097 ic_values->reset_state = ic->core.reset_state; 3098 ic_values->hotkey = ic->core.hotkey; 3099 ic_values->hotkey_state = ic->core.hotkey_state; 3100 ic_values->preedit_attr = ic->core.preedit_attr; 3101 ic_values->status_attr = ic->core.status_attr; 3102} 3103 3104void 3105_XimSetCurrentICValues( 3106 Xic ic, 3107 XimDefICValues *ic_values) 3108{ 3109 ic->core.input_style = ic_values->input_style; 3110 ic->core.client_window = ic_values->client_window; 3111 if (ic_values->focus_window) 3112 ic->core.focus_window = ic_values->focus_window; 3113 ic->core.filter_events = ic_values->filter_events; 3114 ic->core.geometry_callback = ic_values->geometry_callback; 3115 ic->core.res_name = ic_values->res_name; 3116 ic->core.res_class = ic_values->res_class; 3117 ic->core.destroy_callback = ic_values->destroy_callback; 3118 ic->core.string_conversion_callback 3119 = ic_values->string_conversion_callback; 3120 ic->core.string_conversion = ic_values->string_conversion; 3121 ic->core.reset_state = ic_values->reset_state; 3122 ic->core.hotkey = ic_values->hotkey; 3123 ic->core.hotkey_state = ic_values->hotkey_state; 3124 ic->core.preedit_attr = ic_values->preedit_attr; 3125 ic->core.status_attr = ic_values->status_attr; 3126} 3127 3128static void 3129_XimInitialIMOffsetInfo(void) 3130{ 3131 unsigned int n = XIMNumber(im_attr_info); 3132 register int i; 3133 3134 for(i = 0; i < n; i++) { 3135 im_attr_info[i].quark = XrmStringToQuark(GET_NAME(im_attr_info[i])); 3136 } 3137} 3138 3139static void 3140_XimInitialICOffsetInfo(void) 3141{ 3142 unsigned int n; 3143 register int i; 3144 3145 n = XIMNumber(ic_attr_info); 3146 for(i = 0; i < n; i++) { 3147 ic_attr_info[i].quark = XrmStringToQuark(GET_NAME(ic_attr_info[i])); 3148 } 3149 3150 n = XIMNumber(ic_pre_attr_info); 3151 for(i = 0; i < n; i++) { 3152 ic_pre_attr_info[i].quark = XrmStringToQuark(GET_NAME(ic_pre_attr_info[i])); 3153 } 3154 3155 n = XIMNumber(ic_sts_attr_info); 3156 for(i = 0; i < n; i++) { 3157 ic_sts_attr_info[i].quark = XrmStringToQuark(GET_NAME(ic_sts_attr_info[i])); 3158 } 3159} 3160 3161static void 3162_XimInitialIMMode(void) 3163{ 3164 unsigned int n = XIMNumber(im_mode); 3165 register int i; 3166 3167 for(i = 0; i < n; i++) { 3168 im_mode_quark[i] = XrmStringToQuark(GET_NAME(im_mode[i])); 3169 } 3170} 3171 3172static void 3173_XimInitialICMode(void) 3174{ 3175 unsigned int n = XIMNumber(ic_mode); 3176 register int i; 3177 3178 for(i = 0; i < n; i++) { 3179 ic_mode_quark[i] = XrmStringToQuark(GET_NAME(ic_mode[i])); 3180 } 3181} 3182 3183void 3184_XimInitialResourceInfo(void) 3185{ 3186 static Bool init_flag = False; 3187 3188 if(init_flag == True) { 3189 return; 3190 } 3191 _XimInitialIMOffsetInfo(); 3192 _XimInitialICOffsetInfo(); 3193 _XimInitialIMMode(); 3194 _XimInitialICMode(); 3195 init_flag = True; 3196} 3197