| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#include "tkInt.h" |
| 18 |
#include "tkSelect.h" |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
typedef struct { |
| 27 |
Tcl_Interp *interp; |
| 28 |
int cmdLength; |
| 29 |
int charOffset; |
| 30 |
int byteOffset; |
| 31 |
|
| 32 |
char buffer[TCL_UTF_MAX]; |
| 33 |
|
| 34 |
LangCallback *command; |
| 35 |
|
| 36 |
|
| 37 |
} CommandInfo; |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
typedef struct LostCommand { |
| 46 |
Tcl_Interp *interp; |
| 47 |
LangCallback *command; |
| 48 |
|
| 49 |
|
| 50 |
} LostCommand; |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
typedef struct ThreadSpecificData { |
| 58 |
TkSelInProgress *pendingPtr; |
| 59 |
|
| 60 |
|
| 61 |
} ThreadSpecificData; |
| 62 |
static Tcl_ThreadDataKey dataKey; |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
static int HandleTclCommand _ANSI_ARGS_((ClientData clientData, |
| 69 |
int offset, char *buffer, int maxBytes)); |
| 70 |
static void LostSelection _ANSI_ARGS_((ClientData clientData)); |
| 71 |
static int SelGetProc _ANSI_ARGS_((ClientData clientData, |
| 72 |
Tcl_Interp *interp, char *portion)); |
| 73 |
|
| 74 |
static void SelRcvIncrProc _ANSI_ARGS_((ClientData clientData, |
| 75 |
XEvent *eventPtr)); |
| 76 |
static void SelTimeoutProc _ANSI_ARGS_((ClientData clientData)); |
| 77 |
static void FreeHandler _ANSI_ARGS_((ClientData clientData)); |
| 78 |
static int HandleCompat _ANSI_ARGS_((ClientData clientData, |
| 79 |
int offset, long *buffer, int maxBytes, |
| 80 |
Atom type, Tk_Window tkwin)); |
| 81 |
static int CompatXSelProc _ANSI_ARGS_((ClientData clientData, |
| 82 |
Tcl_Interp *interp, long *portion, |
| 83 |
int numItems, int format, |
| 84 |
Atom type, Tk_Window tkwin)); |
| 85 |
static void FreeLost _ANSI_ARGS_((ClientData clientData)); |
| 86 |
|
| 87 |
typedef struct CompatHandler |
| 88 |
{ |
| 89 |
Tk_SelectionProc *proc; |
| 90 |
|
| 91 |
ClientData clientData; |
| 92 |
} CompatHandler; |
| 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 |
void |
| 142 |
Tk_CreateXSelHandler(tkwin, selection, target, proc, clientData, format) |
| 143 |
Tk_Window tkwin; |
| 144 |
Atom selection; |
| 145 |
Atom target; |
| 146 |
|
| 147 |
|
| 148 |
Tk_XSelectionProc *proc; |
| 149 |
|
| 150 |
ClientData clientData; |
| 151 |
Atom format; |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
{ |
| 157 |
register TkSelHandler *selPtr; |
| 158 |
TkWindow *winPtr = (TkWindow *) tkwin; |
| 159 |
TkDisplay *dispPtr = winPtr->dispPtr; |
| 160 |
|
| 161 |
if (winPtr->dispPtr->multipleAtom == None) { |
| 162 |
TkSelInit(tkwin); |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
for (selPtr = winPtr->selHandlerList; ; selPtr = selPtr->nextPtr) { |
| 171 |
if (selPtr == NULL) { |
| 172 |
selPtr = (TkSelHandler *) ckalloc(sizeof(TkSelHandler)); |
| 173 |
selPtr->nextPtr = winPtr->selHandlerList; |
| 174 |
winPtr->selHandlerList = selPtr; |
| 175 |
break; |
| 176 |
} |
| 177 |
if ((selPtr->selection == selection) && (selPtr->target == target)) { |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
if (selPtr->proc == HandleCompat) { |
| 186 |
FreeHandler(selPtr->clientData); |
| 187 |
} |
| 188 |
break; |
| 189 |
} |
| 190 |
} |
| 191 |
selPtr->selection = selection; |
| 192 |
selPtr->target = target; |
| 193 |
selPtr->format = format; |
| 194 |
selPtr->proc = proc; |
| 195 |
selPtr->clientData = clientData; |
| 196 |
if ((target == XA_STRING) |
| 197 |
|| (target==dispPtr->utf8Atom) |
| 198 |
|| (target==dispPtr->textAtom) |
| 199 |
|| (target==dispPtr->compoundTextAtom)) { |
| 200 |
selPtr->size = 8; |
| 201 |
} else { |
| 202 |
selPtr->size = 32; |
| 203 |
} |
| 204 |
|
| 205 |
if ((target == XA_STRING) && (winPtr->dispPtr->utf8Atom != (Atom) NULL)) { |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
target = winPtr->dispPtr->utf8Atom; |
| 212 |
for (selPtr = winPtr->selHandlerList; ; |
| 213 |
selPtr = selPtr->nextPtr) { |
| 214 |
if (selPtr == NULL) { |
| 215 |
selPtr = (TkSelHandler *) ckalloc(sizeof(TkSelHandler)); |
| 216 |
selPtr->nextPtr = winPtr->selHandlerList; |
| 217 |
winPtr->selHandlerList = selPtr; |
| 218 |
selPtr->selection = selection; |
| 219 |
selPtr->target = target; |
| 220 |
selPtr->format = target; |
| 221 |
selPtr->proc = proc; |
| 222 |
#ifndef _LANG |
| 223 |
if (selPtr->proc == HandleTclCommand) { |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
unsigned cmdInfoLen = sizeof(CommandInfo) + |
| 229 |
((CommandInfo*)clientData)->cmdLength - 3; |
| 230 |
selPtr->clientData = (ClientData)ckalloc(cmdInfoLen); |
| 231 |
memcpy(selPtr->clientData, clientData, cmdInfoLen); |
| 232 |
} |
| 233 |
#else |
| 234 |
if (selPtr->proc == HandleCompat) { |
| 235 |
CompatHandler *cd = (CompatHandler *) ckalloc(sizeof(CompatHandler)); |
| 236 |
*cd = *((CompatHandler *) clientData); |
| 237 |
if (cd->proc == HandleTclCommand) { |
| 238 |
CommandInfo *src = (CommandInfo *) cd->clientData; |
| 239 |
CommandInfo *dst = (CommandInfo *) ckalloc(sizeof(*src)); |
| 240 |
*dst = *src; |
| 241 |
cd->clientData = (ClientData) dst; |
| 242 |
dst->command = LangCopyCallback(src->command); |
| 243 |
} |
| 244 |
selPtr->clientData = (ClientData) cd; |
| 245 |
} |
| 246 |
#endif |
| 247 |
else { |
| 248 |
selPtr->clientData = clientData; |
| 249 |
} |
| 250 |
selPtr->size = 8; |
| 251 |
break; |
| 252 |
} |
| 253 |
if ((selPtr->selection == selection) |
| 254 |
&& (selPtr->target == target)) { |
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
break; |
| 260 |
} |
| 261 |
} |
| 262 |
} |
| 263 |
} |
| 264 |
|
| 265 |
|
| 266 |
static int |
| 267 |
HandleCompat(clientData, offset, Xbuffer, maxBytes, type, tkwin) |
| 268 |
ClientData clientData; |
| 269 |
int offset; |
| 270 |
long *Xbuffer; |
| 271 |
int maxBytes; |
| 272 |
Atom type; |
| 273 |
Tk_Window tkwin; |
| 274 |
{ |
| 275 |
CompatHandler *cd = (CompatHandler *) clientData; |
| 276 |
|
| 277 |
if (type == XA_STRING) { |
| 278 |
return (*cd->proc)(cd->clientData, offset, (char *) Xbuffer, maxBytes); |
| 279 |
} |
| 280 |
else { |
| 281 |
TkWindow *winPtr = (TkWindow *) tkwin; |
| 282 |
if (winPtr && winPtr->dispPtr->utf8Atom != None && type == winPtr->dispPtr->utf8Atom) { |
| 283 |
return (*cd->proc)(cd->clientData, offset, (char *) Xbuffer, maxBytes); |
| 284 |
} |
| 285 |
else { |
| 286 |
#ifdef WIN32 |
| 287 |
return -1; |
| 288 |
#else |
| 289 |
char buffer[TK_SEL_BYTES_AT_ONCE]; |
| 290 |
int count = (*cd->proc)(cd->clientData, offset, buffer, maxBytes); |
| 291 |
buffer[count] = '\0'; |
| 292 |
return TkSelCvtToX(Xbuffer, buffer, type, tkwin, maxBytes); |
| 293 |
#endif |
| 294 |
} |
| 295 |
} |
| 296 |
} |
| 297 |
|
| 298 |
|
| 299 |
void |
| 300 |
Tk_CreateSelHandler(tkwin, selection, target, proc, clientData, format) |
| 301 |
Tk_Window tkwin; |
| 302 |
Atom selection; |
| 303 |
Atom target; |
| 304 |
|
| 305 |
|
| 306 |
Tk_SelectionProc *proc; |
| 307 |
|
| 308 |
ClientData clientData; |
| 309 |
Atom format; |
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
{ |
| 315 |
CompatHandler *cd = (CompatHandler *) ckalloc(sizeof(CompatHandler)); |
| 316 |
cd->clientData = clientData; |
| 317 |
cd->proc = proc; |
| 318 |
Tk_CreateXSelHandler(tkwin, selection, target, HandleCompat, |
| 319 |
(ClientData) cd, format); |
| 320 |
} |
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
void |
| 341 |
Tk_DeleteSelHandler(tkwin, selection, target) |
| 342 |
Tk_Window tkwin; |
| 343 |
Atom selection; |
| 344 |
|
| 345 |
Atom target; |
| 346 |
|
| 347 |
{ |
| 348 |
TkWindow *winPtr = (TkWindow *) tkwin; |
| 349 |
register TkSelHandler *selPtr, *prevPtr; |
| 350 |
register TkSelInProgress *ipPtr; |
| 351 |
ThreadSpecificData *tsdPtr = (ThreadSpecificData *) |
| 352 |
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); |
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
for (selPtr = winPtr->selHandlerList, prevPtr = NULL; ; |
| 360 |
prevPtr = selPtr, selPtr = selPtr->nextPtr) { |
| 361 |
if (selPtr == NULL) { |
| 362 |
return; |
| 363 |
} |
| 364 |
if ((selPtr->selection == selection) && (selPtr->target == target)) { |
| 365 |
break; |
| 366 |
} |
| 367 |
} |
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
for (ipPtr = tsdPtr->pendingPtr; ipPtr != NULL; |
| 375 |
ipPtr = ipPtr->nextPtr) { |
| 376 |
if (ipPtr->selPtr == selPtr) { |
| 377 |
ipPtr->selPtr = NULL; |
| 378 |
} |
| 379 |
} |
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
if (prevPtr == NULL) { |
| 386 |
winPtr->selHandlerList = selPtr->nextPtr; |
| 387 |
} else { |
| 388 |
prevPtr->nextPtr = selPtr->nextPtr; |
| 389 |
} |
| 390 |
|
| 391 |
if ((target == XA_STRING) && (winPtr->dispPtr->utf8Atom != None)) { |
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
TkSelHandler *utf8selPtr; |
| 398 |
|
| 399 |
target = winPtr->dispPtr->utf8Atom; |
| 400 |
for (utf8selPtr = winPtr->selHandlerList; utf8selPtr != NULL; |
| 401 |
utf8selPtr = utf8selPtr->nextPtr) { |
| 402 |
if ((utf8selPtr->selection == selection) |
| 403 |
&& (utf8selPtr->target == target)) { |
| 404 |
break; |
| 405 |
} |
| 406 |
} |
| 407 |
if (utf8selPtr != NULL) { |
| 408 |
if ((utf8selPtr->format == target) |
| 409 |
&& (utf8selPtr->proc == selPtr->proc) |
| 410 |
&& (utf8selPtr->size == selPtr->size)) { |
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
Tk_DeleteSelHandler(tkwin, selection, target); |
| 416 |
} |
| 417 |
} |
| 418 |
} |
| 419 |
|
| 420 |
#ifndef _LANG |
| 421 |
if (selPtr->proc == HandleTclCommand) { |
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
((CommandInfo*)selPtr->clientData)->interp = NULL; |
| 427 |
Tcl_EventuallyFree(selPtr->clientData, TCL_DYNAMIC); |
| 428 |
} |
| 429 |
#else |
| 430 |
if (selPtr->proc == HandleCompat) { |
| 431 |
FreeHandler(selPtr->clientData); |
| 432 |
} |
| 433 |
#endif |
| 434 |
ckfree((char *) selPtr); |
| 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 |
void |
| 461 |
Tk_OwnSelection(tkwin, selection, proc, clientData) |
| 462 |
Tk_Window tkwin; |
| 463 |
|
| 464 |
Atom selection; |
| 465 |
Tk_LostSelProc *proc; |
| 466 |
|
| 467 |
ClientData clientData; |
| 468 |
|
| 469 |
{ |
| 470 |
register TkWindow *winPtr = (TkWindow *) tkwin; |
| 471 |
TkDisplay *dispPtr = winPtr->dispPtr; |
| 472 |
TkSelectionInfo *infoPtr; |
| 473 |
Tk_LostSelProc *clearProc = NULL; |
| 474 |
ClientData clearData = NULL; |
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
if (dispPtr->multipleAtom == None) { |
| 479 |
TkSelInit(tkwin); |
| 480 |
} |
| 481 |
Tk_MakeWindowExist(tkwin); |
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
for (infoPtr = dispPtr->selectionInfoPtr; infoPtr != NULL; |
| 494 |
infoPtr = infoPtr->nextPtr) { |
| 495 |
if (infoPtr->selection == selection) { |
| 496 |
break; |
| 497 |
} |
| 498 |
} |
| 499 |
if (infoPtr == NULL) { |
| 500 |
infoPtr = (TkSelectionInfo*) ckalloc(sizeof(TkSelectionInfo)); |
| 501 |
infoPtr->selection = selection; |
| 502 |
infoPtr->nextPtr = dispPtr->selectionInfoPtr; |
| 503 |
dispPtr->selectionInfoPtr = infoPtr; |
| 504 |
} else if (infoPtr->clearProc != NULL) { |
| 505 |
if (infoPtr->owner != tkwin) { |
| 506 |
clearProc = infoPtr->clearProc; |
| 507 |
clearData = infoPtr->clearData; |
| 508 |
} else if (infoPtr->clearProc == LostSelection) { |
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
FreeLost(infoPtr->clearData); |
| 516 |
} |
| 517 |
} |
| 518 |
|
| 519 |
infoPtr->owner = tkwin; |
| 520 |
infoPtr->serial = NextRequest(winPtr->display); |
| 521 |
infoPtr->clearProc = proc; |
| 522 |
infoPtr->clearData = clientData; |
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
infoPtr->time = TkCurrentTime(dispPtr,True); |
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
XSetSelectionOwner(winPtr->display, infoPtr->selection, winPtr->window, |
| 546 |
infoPtr->time); |
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
if (clearProc != NULL) { |
| 554 |
(*clearProc)(clearData); |
| 555 |
} |
| 556 |
} |
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
void |
| 578 |
Tk_ClearSelection(tkwin, selection) |
| 579 |
Tk_Window tkwin; |
| 580 |
Atom selection; |
| 581 |
{ |
| 582 |
register TkWindow *winPtr = (TkWindow *) tkwin; |
| 583 |
TkDisplay *dispPtr = winPtr->dispPtr; |
| 584 |
TkSelectionInfo *infoPtr; |
| 585 |
TkSelectionInfo *prevPtr; |
| 586 |
TkSelectionInfo *nextPtr; |
| 587 |
Tk_LostSelProc *clearProc = NULL; |
| 588 |
ClientData clearData = NULL; |
| 589 |
|
| 590 |
|
| 591 |
if (dispPtr->multipleAtom == None) { |
| 592 |
TkSelInit(tkwin); |
| 593 |
} |
| 594 |
|
| 595 |
for (infoPtr = dispPtr->selectionInfoPtr, prevPtr = NULL; |
| 596 |
infoPtr != NULL; infoPtr = nextPtr) { |
| 597 |
nextPtr = infoPtr->nextPtr; |
| 598 |
if (infoPtr->selection == selection) { |
| 599 |
if (prevPtr == NULL) { |
| 600 |
dispPtr->selectionInfoPtr = nextPtr; |
| 601 |
} else { |
| 602 |
prevPtr->nextPtr = nextPtr; |
| 603 |
} |
| 604 |
break; |
| 605 |
} |
| 606 |
prevPtr = infoPtr; |
| 607 |
} |
| 608 |
|
| 609 |
if (infoPtr != NULL) { |
| 610 |
clearProc = infoPtr->clearProc; |
| 611 |
clearData = infoPtr->clearData; |
| 612 |
ckfree((char *) infoPtr); |
| 613 |
} |
| 614 |
XSetSelectionOwner(winPtr->display, selection, None, |
| 615 |
|
| 616 |
TkCurrentTime(dispPtr,True)); |
| 617 |
|
| 618 |
if (clearProc != NULL) { |
| 619 |
(*clearProc)(clearData); |
| 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 |
int |
| 667 |
Tk_GetXSelection(interp, tkwin, selection, target, proc, clientData) |
| 668 |
Tcl_Interp *interp; |
| 669 |
|
| 670 |
Tk_Window tkwin; |
| 671 |
|
| 672 |
|
| 673 |
Atom selection; |
| 674 |
Atom target; |
| 675 |
|
| 676 |
Tk_GetXSelProc *proc; |
| 677 |
|
| 678 |
ClientData clientData; |
| 679 |
{ |
| 680 |
TkWindow *winPtr = (TkWindow *) tkwin; |
| 681 |
TkDisplay *dispPtr = winPtr->dispPtr; |
| 682 |
TkSelectionInfo *infoPtr; |
| 683 |
ThreadSpecificData *tsdPtr = (ThreadSpecificData *) |
| 684 |
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); |
| 685 |
|
| 686 |
if (dispPtr->multipleAtom == None) { |
| 687 |
TkSelInit(tkwin); |
| 688 |
} |
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
for (infoPtr = dispPtr->selectionInfoPtr; infoPtr != NULL; |
| 699 |
infoPtr = infoPtr->nextPtr) { |
| 700 |
if (infoPtr->selection == selection) |
| 701 |
break; |
| 702 |
} |
| 703 |
if (infoPtr != NULL) { |
| 704 |
register TkSelHandler *selPtr; |
| 705 |
int offset, result, count; |
| 706 |
long buffer[TK_SEL_WORDS_AT_ONCE+1]; |
| 707 |
TkSelInProgress ip; |
| 708 |
|
| 709 |
for (selPtr = ((TkWindow *) infoPtr->owner)->selHandlerList; |
| 710 |
selPtr != NULL; selPtr = selPtr->nextPtr) { |
| 711 |
if ((selPtr->target == target) |
| 712 |
&& (selPtr->selection == selection)) { |
| 713 |
break; |
| 714 |
} |
| 715 |
} |
| 716 |
if (selPtr == NULL) { |
| 717 |
Atom type = XA_STRING; |
| 718 |
int format = 8; |
| 719 |
|
| 720 |
count = TkSelDefaultSelection(infoPtr, target, buffer, |
| 721 |
TK_SEL_BYTES_AT_ONCE, &type, &format); |
| 722 |
if (count > TK_SEL_BYTES_AT_ONCE) { |
| 723 |
panic("selection handler returned too many bytes"); |
| 724 |
} |
| 725 |
if (count < 0) { |
| 726 |
goto cantget; |
| 727 |
} |
| 728 |
result = (*proc)(clientData, interp, buffer, count, format, type, tkwin); |
| 729 |
} else { |
| 730 |
Atom type = selPtr->format; |
| 731 |
int format = 32; |
| 732 |
if ((type == XA_STRING) |
| 733 |
|| (type==dispPtr->utf8Atom) |
| 734 |
|| (type==dispPtr->textAtom) |
| 735 |
|| (type==dispPtr->compoundTextAtom)) { |
| 736 |
format = 8; |
| 737 |
} |
| 738 |
offset = 0; |
| 739 |
result = TCL_OK; |
| 740 |
ip.selPtr = selPtr; |
| 741 |
ip.nextPtr = tsdPtr->pendingPtr; |
| 742 |
tsdPtr->pendingPtr = &ip; |
| 743 |
while (1) { |
| 744 |
count = (selPtr->proc)(selPtr->clientData, offset, buffer, |
| 745 |
TK_SEL_BYTES_AT_ONCE, type, tkwin); |
| 746 |
if ((count < 0) || (ip.selPtr == NULL)) { |
| 747 |
tsdPtr->pendingPtr = ip.nextPtr; |
| 748 |
goto cantget; |
| 749 |
} |
| 750 |
if (count > TK_SEL_BYTES_AT_ONCE) { |
| 751 |
panic("selection handler returned too many bytes"); |
| 752 |
} |
| 753 |
((char *) buffer)[count] = '\0'; |
| 754 |
result = (*proc)(clientData, interp, buffer, count, format, type, tkwin); |
| 755 |
if ((result != TCL_OK) || (count < TK_SEL_BYTES_AT_ONCE) |
| 756 |
|| (ip.selPtr == NULL)) { |
| 757 |
break; |
| 758 |
} |
| 759 |
offset += count; |
| 760 |
} |
| 761 |
tsdPtr->pendingPtr = ip.nextPtr; |
| 762 |
} |
| 763 |
return result; |
| 764 |
} |
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
return TkSelGetSelection(interp, tkwin, selection, target, proc, |
| 771 |
clientData); |
| 772 |
|
| 773 |
cantget: |
| 774 |
Tcl_AppendResult(interp, Tk_GetAtomName(tkwin, selection), |
| 775 |
" selection doesn't exist or form \"", Tk_GetAtomName(tkwin, target), |
| 776 |
"\" not defined", (char *) NULL); |
| 777 |
return TCL_ERROR; |
| 778 |
|
| 779 |
} |
| 780 |
|
| 781 |
|
| 782 |
typedef struct CompatInfo |
| 783 |
{ |
| 784 |
Tk_GetSelProc *proc; |
| 785 |
|
| 786 |
ClientData clientData; |
| 787 |
} CompatInfo; |
| 788 |
|
| 789 |
static int |
| 790 |
CompatXSelProc(clientData,interp,portion,numItems,format,type,tkwin) |
| 791 |
ClientData clientData; |
| 792 |
Tcl_Interp *interp; |
| 793 |
long *portion; |
| 794 |
int numItems; |
| 795 |
int format; |
| 796 |
Atom type; |
| 797 |
Tk_Window tkwin; |
| 798 |
{CompatInfo *info = (CompatInfo *) clientData; |
| 799 |
TkWindow *winPtr = (TkWindow *) tkwin; |
| 800 |
TkDisplay *dispPtr = winPtr->dispPtr; |
| 801 |
if ((type == XA_STRING) |
| 802 |
|| (type==dispPtr->utf8Atom) |
| 803 |
|| (type==dispPtr->textAtom) |
| 804 |
|| (type==dispPtr->compoundTextAtom)) { |
| 805 |
if (format != 8) { |
| 806 |
sprintf(interp->result, |
| 807 |
"bad format for string selection: wanted \"8\", got \"%d\"", |
| 808 |
format); |
| 809 |
return TCL_ERROR; |
| 810 |
} |
| 811 |
portion[numItems] = '\0'; |
| 812 |
return (*info->proc)(info->clientData, interp, (char *) portion); |
| 813 |
} else { |
| 814 |
#ifdef WIN32 |
| 815 |
return TCL_ERROR; |
| 816 |
#else |
| 817 |
char *string; |
| 818 |
int result; |
| 819 |
if (format != 32) { |
| 820 |
sprintf(interp->result, |
| 821 |
"bad format for selection: wanted \"32\", got \"%d\"", |
| 822 |
format); |
| 823 |
return TCL_ERROR; |
| 824 |
} |
| 825 |
string = TkSelCvtFromX(portion, (int) numItems, type, tkwin); |
| 826 |
result = (*info->proc)(info->clientData, interp, string); |
| 827 |
ckfree(string); |
| 828 |
return result; |
| 829 |
#endif |
| 830 |
} |
| 831 |
} |
| 832 |
|
| 833 |
int |
| 834 |
Tk_GetSelection(interp, tkwin, selection, target, proc, clientData) |
| 835 |
Tcl_Interp *interp; |
| 836 |
|
| 837 |
Tk_Window tkwin; |
| 838 |
|
| 839 |
|
| 840 |
Atom selection; |
| 841 |
Atom target; |
| 842 |
|
| 843 |
Tk_GetSelProc *proc; |
| 844 |
|
| 845 |
ClientData clientData; |
| 846 |
{ |
| 847 |
CompatInfo cd; |
| 848 |
cd.clientData = clientData; |
| 849 |
cd.proc = proc; |
| 850 |
return Tk_GetXSelection(interp, tkwin, selection, target, CompatXSelProc, (ClientData) &cd); |
| 851 |
} |
| 852 |
|
| 853 |
static void |
| 854 |
FreeHandler(clientData) |
| 855 |
ClientData clientData; |
| 856 |
{ |
| 857 |
CompatHandler *cd = (CompatHandler *) clientData; |
| 858 |
if (cd->proc == HandleTclCommand) |
| 859 |
{ |
| 860 |
CommandInfo *cmdInfoPtr = (CommandInfo *) cd->clientData; |
| 861 |
cmdInfoPtr->interp = NULL; |
| 862 |
LangFreeCallback(cmdInfoPtr->command); |
| 863 |
ckfree((char *) cmdInfoPtr); |
| 864 |
} |
| 865 |
ckfree((char *) cd); |
| 866 |
} |
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
int |
| 887 |
Tk_SelectionObjCmd(clientData, interp, objc, objv) |
| 888 |
ClientData clientData; |
| 889 |
|
| 890 |
Tcl_Interp *interp; |
| 891 |
int objc; |
| 892 |
Tcl_Obj *CONST objv[]; |
| 893 |
{ |
| 894 |
Tk_Window tkwin = (Tk_Window) clientData; |
| 895 |
char *path = NULL; |
| 896 |
Atom selection; |
| 897 |
char *selName = NULL, *string; |
| 898 |
int count, index; |
| 899 |
Tcl_Obj **objs; |
| 900 |
static CONST char *optionStrings[] = { |
| 901 |
"clear", "exists", "get", "handle", "own", (char *) NULL |
| 902 |
}; |
| 903 |
enum options { SELECTION_CLEAR, SELECTION_EXISTS, SELECTION_GET, SELECTION_HANDLE, |
| 904 |
SELECTION_OWN }; |
| 905 |
|
| 906 |
if (objc < 2) { |
| 907 |
Tcl_WrongNumArgs(interp, 1, objv, "option ?arg arg ...?"); |
| 908 |
return TCL_ERROR; |
| 909 |
} |
| 910 |
|
| 911 |
if (Tcl_GetIndexFromObj(interp, objv[1], optionStrings, "option", 0, |
| 912 |
&index) != TCL_OK) { |
| 913 |
return TCL_ERROR; |
| 914 |
} |
| 915 |
|
| 916 |
switch ((enum options) index) { |
| 917 |
case SELECTION_CLEAR: { |
| 918 |
static CONST char *clearOptionStrings[] = { |
| 919 |
"-displayof", "-selection", (char *) NULL |
| 920 |
}; |
| 921 |
enum clearOptions { CLEAR_DISPLAYOF, CLEAR_SELECTION }; |
| 922 |
int clearIndex; |
| 923 |
|
| 924 |
for (count = objc-2, objs = ((Tcl_Obj **)objv)+2; count > 0; |
| 925 |
count-=2, objs+=2) { |
| 926 |
string = Tcl_GetString(objs[0]); |
| 927 |
if (string[0] != '-') { |
| 928 |
break; |
| 929 |
} |
| 930 |
if (count < 2) { |
| 931 |
Tcl_AppendResult(interp, "value for \"", string, |
| 932 |
"\" missing", (char *) NULL); |
| 933 |
return TCL_ERROR; |
| 934 |
} |
| 935 |
|
| 936 |
if (Tcl_GetIndexFromObj(interp, objs[0], clearOptionStrings, |
| 937 |
"option", 0, &clearIndex) != TCL_OK) { |
| 938 |
return TCL_ERROR; |
| 939 |
} |
| 940 |
switch ((enum clearOptions) clearIndex) { |
| 941 |
case CLEAR_DISPLAYOF: |
| 942 |
path = Tcl_GetString(objs[1]); |
| 943 |
break; |
| 944 |
case CLEAR_SELECTION: |
| 945 |
selName = Tcl_GetString(objs[1]); |
| 946 |
break; |
| 947 |
} |
| 948 |
} |
| 949 |
if (count == 1) { |
| 950 |
path = Tcl_GetString(objs[0]); |
| 951 |
} else if (count > 1) { |
| 952 |
Tcl_WrongNumArgs(interp, 2, objv, "?options?"); |
| 953 |
return TCL_ERROR; |
| 954 |
} |
| 955 |
if (path != NULL) { |
| 956 |
tkwin = Tk_NameToWindow(interp, path, tkwin); |
| 957 |
} |
| 958 |
if (tkwin == NULL) { |
| 959 |
return TCL_ERROR; |
| 960 |
} |
| 961 |
if (selName != NULL) { |
| 962 |
selection = Tk_InternAtom(tkwin, selName); |
| 963 |
} else { |
| 964 |
selection = XA_PRIMARY; |
| 965 |
} |
| 966 |
|
| 967 |
Tk_ClearSelection(tkwin, selection); |
| 968 |
break; |
| 969 |
} |
| 970 |
|
| 971 |
case SELECTION_EXISTS: { |
| 972 |
Tcl_DString selBytes; |
| 973 |
int result; |
| 974 |
Window win; |
| 975 |
static CONST char *getOptionStrings[] = { |
| 976 |
"-displayof", "-selection", (char *) NULL |
| 977 |
}; |
| 978 |
enum getOptions { GET_DISPLAYOF, GET_SELECTION }; |
| 979 |
int getIndex; |
| 980 |
|
| 981 |
for (count = objc-2, objs = ((Tcl_Obj **)objv)+2; count>0; |
| 982 |
count-=2, objs+=2) { |
| 983 |
string = Tcl_GetString(objs[0]); |
| 984 |
if (string[0] != '-') { |
| 985 |
break; |
| 986 |
} |
| 987 |
if (count < 2) { |
| 988 |
Tcl_AppendResult(interp, "value for \"", string, |
| 989 |
"\" missing", (char *) NULL); |
| 990 |
return TCL_ERROR; |
| 991 |
} |
| 992 |
|
| 993 |
if (Tcl_GetIndexFromObj(interp, objs[0], getOptionStrings, |
| 994 |
"option", 0, &getIndex) != TCL_OK) { |
| 995 |
return TCL_ERROR; |
| 996 |
} |
| 997 |
|
| 998 |
switch ((enum getOptions) getIndex) { |
| 999 |
case GET_DISPLAYOF: |
| 1000 |
path = Tcl_GetString(objs[1]); |
| 1001 |
break; |
| 1002 |
case GET_SELECTION: |
| 1003 |
selName = Tcl_GetString(objs[1]); |
| 1004 |
break; |
| 1005 |
} |
| 1006 |
} |
| 1007 |
if (path != NULL) { |
| 1008 |
tkwin = Tk_NameToWindow(interp, path, tkwin); |
| 1009 |
} |
| 1010 |
if (tkwin == NULL) { |
| 1011 |
return TCL_ERROR; |
| 1012 |
} |
| 1013 |
if (selName != NULL) { |
| 1014 |
selection = Tk_InternAtom(tkwin, selName); |
| 1015 |
} else { |
| 1016 |
selection = XA_PRIMARY; |
| 1017 |
} |
| 1018 |
if (count > 0) { |
| 1019 |
Tcl_WrongNumArgs(interp, 2, objv, "?options?"); |
| 1020 |
return TCL_ERROR; |
| 1021 |
} |
| 1022 |
|
| 1023 |
win = XGetSelectionOwner(Tk_Display(tkwin), selection); |
| 1024 |
if (win != None) { |
| 1025 |
TkWindow *winPtr = (TkWindow *) tkwin; |
| 1026 |
tkwin = Tk_IdToWindow(Tk_Display(tkwin), win); |
| 1027 |
if (tkwin != NULL && tkwin != winPtr->dispPtr->clipWindow) { |
| 1028 |
Tcl_SetObjResult(interp,LangWidgetObj(interp,tkwin)); |
| 1029 |
} else { |
| 1030 |
Tcl_SetObjResult(interp,Tcl_NewIntObj(win)); |
| 1031 |
} |
| 1032 |
} |
| 1033 |
return TCL_OK; |
| 1034 |
} |
| 1035 |
|
| 1036 |
case SELECTION_GET: { |
| 1037 |
Atom target; |
| 1038 |
char *targetName = NULL; |
| 1039 |
Tcl_DString selBytes; |
| 1040 |
int result; |
| 1041 |
static CONST char *getOptionStrings[] = { |
| 1042 |
"-displayof", "-selection", "-type", (char *) NULL |
| 1043 |
}; |
| 1044 |
enum getOptions { GET_DISPLAYOF, GET_SELECTION, GET_TYPE }; |
| 1045 |
int getIndex; |
| 1046 |
|
| 1047 |
for (count = objc-2, objs = ((Tcl_Obj **)objv)+2; count>0; |
| 1048 |
count-=2, objs+=2) { |
| 1049 |
string = Tcl_GetString(objs[0]); |
| 1050 |
if (string[0] != '-') { |
| 1051 |
break; |
| 1052 |
} |
| 1053 |
if (count < 2) { |
| 1054 |
Tcl_AppendResult(interp, "value for \"", string, |
| 1055 |
"\" missing", (char *) NULL); |
| 1056 |
return TCL_ERROR; |
| 1057 |
} |
| 1058 |
|
| 1059 |
if (Tcl_GetIndexFromObj(interp, objs[0], getOptionStrings, |
| 1060 |
"option", 0, &getIndex) != TCL_OK) { |
| 1061 |
return TCL_ERROR; |
| 1062 |
} |
| 1063 |
|
| 1064 |
switch ((enum getOptions) getIndex) { |
| 1065 |
case GET_DISPLAYOF: |
| 1066 |
path = Tcl_GetString(objs[1]); |
| 1067 |
break; |
| 1068 |
case GET_SELECTION: |
| 1069 |
selName = Tcl_GetString(objs[1]); |
| 1070 |
break; |
| 1071 |
case GET_TYPE: |
| 1072 |
targetName = Tcl_GetString(objs[1]); |
| 1073 |
break; |
| 1074 |
} |
| 1075 |
} |
| 1076 |
if (path != NULL) { |
| 1077 |
tkwin = Tk_NameToWindow(interp, path, tkwin); |
| 1078 |
} |
| 1079 |
if (tkwin == NULL) { |
| 1080 |
return TCL_ERROR; |
| 1081 |
} |
| 1082 |
if (selName != NULL) { |
| 1083 |
selection = Tk_InternAtom(tkwin, selName); |
| 1084 |
} else { |
| 1085 |
selection = XA_PRIMARY; |
| 1086 |
} |
| 1087 |
if (count > 1) { |
| 1088 |
Tcl_WrongNumArgs(interp, 2, objv, "?options?"); |
| 1089 |
return TCL_ERROR; |
| 1090 |
} else if (count == 1) { |
| 1091 |
target = Tk_InternAtom(tkwin, Tcl_GetString(objs[0])); |
| 1092 |
} else if (targetName != NULL) { |
| 1093 |
target = Tk_InternAtom(tkwin, targetName); |
| 1094 |
} else { |
| 1095 |
target = XA_STRING; |
| 1096 |
} |
| 1097 |
|
| 1098 |
Tcl_DStringInit(&selBytes); |
| 1099 |
result = Tk_GetSelection(interp, tkwin, selection, target, |
| 1100 |
SelGetProc, (ClientData) &selBytes); |
| 1101 |
if (result == TCL_OK) { |
| 1102 |
Tcl_DStringResult(interp, &selBytes); |
| 1103 |
} else { |
| 1104 |
Tcl_DStringFree(&selBytes); |
| 1105 |
} |
| 1106 |
return result; |
| 1107 |
} |
| 1108 |
|
| 1109 |
case SELECTION_HANDLE: { |
| 1110 |
Atom target, format; |
| 1111 |
char *targetName = NULL; |
| 1112 |
char *formatName = NULL; |
| 1113 |
register CommandInfo *cmdInfoPtr; |
| 1114 |
int cmdLength; |
| 1115 |
static CONST char *handleOptionStrings[] = { |
| 1116 |
"-format", "-selection", "-type", (char *) NULL |
| 1117 |
}; |
| 1118 |
enum handleOptions { HANDLE_FORMAT, HANDLE_SELECTION, |
| 1119 |
HANDLE_TYPE }; |
| 1120 |
int handleIndex; |
| 1121 |
|
| 1122 |
for (count = objc-2, objs = ((Tcl_Obj **)objv)+2; count > 0; |
| 1123 |
count-=2, objs+=2) { |
| 1124 |
string = Tcl_GetString(objs[0]); |
| 1125 |
if (string[0] != '-') { |
| 1126 |
break; |
| 1127 |
} |
| 1128 |
if (count < 2) { |
| 1129 |
Tcl_AppendResult(interp, "value for \"", string, |
| 1130 |
"\" missing", (char *) NULL); |
| 1131 |
return TCL_ERROR; |
| 1132 |
} |
| 1133 |
|
| 1134 |
if (Tcl_GetIndexFromObj(interp, objs[0],handleOptionStrings, |
| 1135 |
"option", 0, &handleIndex) != TCL_OK) { |
| 1136 |
return TCL_ERROR; |
| 1137 |
} |
| 1138 |
|
| 1139 |
switch ((enum handleOptions) handleIndex) { |
| 1140 |
case HANDLE_FORMAT: |
| 1141 |
formatName = Tcl_GetString(objs[1]); |
| 1142 |
break; |
| 1143 |
case HANDLE_SELECTION: |
| 1144 |
selName = Tcl_GetString(objs[1]); |
| 1145 |
break; |
| 1146 |
case HANDLE_TYPE: |
| 1147 |
targetName = Tcl_GetString(objs[1]); |
| 1148 |
break; |
| 1149 |
} |
| 1150 |
} |
| 1151 |
|
| 1152 |
if ((count < 2) || (count > 4)) { |
| 1153 |
Tcl_WrongNumArgs(interp, 2, objv, "?options? window command"); |
| 1154 |
return TCL_ERROR; |
| 1155 |
} |
| 1156 |
tkwin = Tk_NameToWindow(interp, Tcl_GetString(objs[0]), tkwin); |
| 1157 |
if (tkwin == NULL) { |
| 1158 |
return TCL_ERROR; |
| 1159 |
} |
| 1160 |
if (selName != NULL) { |
| 1161 |
selection = Tk_InternAtom(tkwin, selName); |
| 1162 |
} else { |
| 1163 |
selection = XA_PRIMARY; |
| 1164 |
} |
| 1165 |
|
| 1166 |
if (count > 2) { |
| 1167 |
target = Tk_InternAtom(tkwin, Tcl_GetString(objs[2])); |
| 1168 |
} else if (targetName != NULL) { |
| 1169 |
target = Tk_InternAtom(tkwin, targetName); |
| 1170 |
} else { |
| 1171 |
target = XA_STRING; |
| 1172 |
} |
| 1173 |
if (count > 3) { |
| 1174 |
format = Tk_InternAtom(tkwin, Tcl_GetString(objs[3])); |
| 1175 |
} else if (formatName != NULL) { |
| 1176 |
format = Tk_InternAtom(tkwin, formatName); |
| 1177 |
} else { |
| 1178 |
format = XA_STRING; |
| 1179 |
} |
| 1180 |
string = Tcl_GetStringFromObj(objs[1], &cmdLength); |
| 1181 |
if (cmdLength == 0) { |
| 1182 |
Tk_DeleteSelHandler(tkwin, selection, target); |
| 1183 |
} else { |
| 1184 |
cmdInfoPtr = (CommandInfo *) ckalloc((unsigned) ( |
| 1185 |
sizeof(CommandInfo) - 3 + cmdLength)); |
| 1186 |
cmdInfoPtr->interp = interp; |
| 1187 |
cmdInfoPtr->charOffset = 0; |
| 1188 |
cmdInfoPtr->byteOffset = 0; |
| 1189 |
cmdInfoPtr->buffer[0] = '\0'; |
| 1190 |
cmdInfoPtr->cmdLength = cmdLength; |
| 1191 |
cmdInfoPtr->command = LangMakeCallback(objs[1]); |
| 1192 |
Tk_CreateSelHandler(tkwin, selection, target, HandleTclCommand, |
| 1193 |
(ClientData) cmdInfoPtr, format); |
| 1194 |
} |
| 1195 |
return TCL_OK; |
| 1196 |
} |
| 1197 |
|
| 1198 |
case SELECTION_OWN: { |
| 1199 |
register LostCommand *lostPtr; |
| 1200 |
Tcl_Obj *script = NULL; |
| 1201 |
int cmdLength; |
| 1202 |
static CONST char *ownOptionStrings[] = { |
| 1203 |
"-command", "-displayof", "-selection", (char *) NULL |
| 1204 |
}; |
| 1205 |
enum ownOptions { OWN_COMMAND, OWN_DISPLAYOF, OWN_SELECTION }; |
| 1206 |
int ownIndex; |
| 1207 |
|
| 1208 |
for (count = objc-2, objs = ((Tcl_Obj **)objv)+2; count > 0; |
| 1209 |
count-=2, objs+=2) { |
| 1210 |
string = Tcl_GetString(objs[0]); |
| 1211 |
if (string[0] != '-') { |
| 1212 |
break; |
| 1213 |
} |
| 1214 |
if (count < 2) { |
| 1215 |
Tcl_AppendResult(interp, "value for \"", string, |
| 1216 |
"\" missing", (char *) NULL); |
| 1217 |
return TCL_ERROR; |
| 1218 |
} |
| 1219 |
|
| 1220 |
if (Tcl_GetIndexFromObj(interp, objs[0], ownOptionStrings, |
| 1221 |
"option", 0, &ownIndex) != TCL_OK) { |
| 1222 |
return TCL_ERROR; |
| 1223 |
} |
| 1224 |
|
| 1225 |
switch ((enum ownOptions) ownIndex) { |
| 1226 |
case OWN_COMMAND: |
| 1227 |
script = objs[1]; |
| 1228 |
break; |
| 1229 |
case OWN_DISPLAYOF: |
| 1230 |
path = Tcl_GetString(objs[1]); |
| 1231 |
break; |
| 1232 |
case OWN_SELECTION: |
| 1233 |
selName = Tcl_GetString(objs[1]); |
| 1234 |
break; |
| 1235 |
} |
| 1236 |
} |
| 1237 |
|
| 1238 |
if (count > 2) { |
| 1239 |
Tcl_WrongNumArgs(interp, 2, objv, "?options? ?window?"); |
| 1240 |
return TCL_ERROR; |
| 1241 |
} |
| 1242 |
if (selName != NULL) { |
| 1243 |
selection = Tk_InternAtom(tkwin, selName); |
| 1244 |
} else { |
| 1245 |
selection = XA_PRIMARY; |
| 1246 |
} |
| 1247 |
if (count == 0) { |
| 1248 |
TkSelectionInfo *infoPtr; |
| 1249 |
TkWindow *winPtr; |
| 1250 |
if (path != NULL) { |
| 1251 |
tkwin = Tk_NameToWindow(interp, path, tkwin); |
| 1252 |
} |
| 1253 |
if (tkwin == NULL) { |
| 1254 |
return TCL_ERROR; |
| 1255 |
} |
| 1256 |
winPtr = (TkWindow *)tkwin; |
| 1257 |
for (infoPtr = winPtr->dispPtr->selectionInfoPtr; |
| 1258 |
infoPtr != NULL; infoPtr = infoPtr->nextPtr) { |
| 1259 |
if (infoPtr->selection == selection) |
| 1260 |
break; |
| 1261 |
} |
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
|
| 1267 |
if ((infoPtr != NULL) |
| 1268 |
&& (infoPtr->owner != winPtr->dispPtr->clipWindow)) { |
| 1269 |
Tcl_SetResult(interp, Tk_PathName(infoPtr->owner), |
| 1270 |
TCL_STATIC); |
| 1271 |
} |
| 1272 |
return TCL_OK; |
| 1273 |
} |
| 1274 |
tkwin = Tk_NameToWindow(interp, Tcl_GetString(objs[0]), tkwin); |
| 1275 |
if (tkwin == NULL) { |
| 1276 |
return TCL_ERROR; |
| 1277 |
} |
| 1278 |
if (count == 2) { |
| 1279 |
if (!LangNull(objs[1])) { |
| 1280 |
script = objs[1]; |
| 1281 |
} |
| 1282 |
} |
| 1283 |
if (script == NULL) { |
| 1284 |
Tk_OwnSelection(tkwin, selection, (Tk_LostSelProc *) NULL, |
| 1285 |
(ClientData) NULL); |
| 1286 |
return TCL_OK; |
| 1287 |
} |
| 1288 |
#ifndef _LANG |
| 1289 |
cmdLength = strlen(Tcl_GetString(script)); |
| 1290 |
lostPtr = (LostCommand *) ckalloc((unsigned) (sizeof(LostCommand) |
| 1291 |
-3 + cmdLength)); |
| 1292 |
strcpy(lostPtr->command, Tcl_GetString(script)); |
| 1293 |
#else |
| 1294 |
lostPtr = (LostCommand *) ckalloc((unsigned) (sizeof(LostCommand))); |
| 1295 |
lostPtr->command = LangMakeCallback(script); |
| 1296 |
#endif |
| 1297 |
lostPtr->interp = interp; |
| 1298 |
Tk_OwnSelection(tkwin, selection, LostSelection, |
| 1299 |
(ClientData) lostPtr); |
| 1300 |
return TCL_OK; |
| 1301 |
} |
| 1302 |
} |
| 1303 |
return TCL_OK; |
| 1304 |
} |
| 1305 |
|
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
|
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
TkSelInProgress * |
| 1325 |
TkSelGetInProgress _ANSI_ARGS_((void)) |
| 1326 |
{ |
| 1327 |
ThreadSpecificData *tsdPtr = (ThreadSpecificData *) |
| 1328 |
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); |
| 1329 |
|
| 1330 |
return tsdPtr->pendingPtr; |
| 1331 |
} |
| 1332 |
|
| 1333 |
|
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
|
| 1349 |
|
| 1350 |
void |
| 1351 |
TkSelSetInProgress(pendingPtr) |
| 1352 |
TkSelInProgress *pendingPtr; |
| 1353 |
{ |
| 1354 |
ThreadSpecificData *tsdPtr = (ThreadSpecificData *) |
| 1355 |
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); |
| 1356 |
|
| 1357 |
tsdPtr->pendingPtr = pendingPtr; |
| 1358 |
} |
| 1359 |
|
| 1360 |
|
| 1361 |
|
| 1362 |
|
| 1363 |
|
| 1364 |
|
| 1365 |
|
| 1366 |
|
| 1367 |
|
| 1368 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
|
| 1372 |
|
| 1373 |
|
| 1374 |
|
| 1375 |
|
| 1376 |
|
| 1377 |
void |
| 1378 |
TkSelDeadWindow(winPtr) |
| 1379 |
register TkWindow *winPtr; |
| 1380 |
{ |
| 1381 |
register TkSelHandler *selPtr; |
| 1382 |
register TkSelInProgress *ipPtr; |
| 1383 |
TkSelectionInfo *infoPtr, *prevPtr, *nextPtr; |
| 1384 |
ThreadSpecificData *tsdPtr = (ThreadSpecificData *) |
| 1385 |
Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); |
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
while (winPtr->selHandlerList != NULL) { |
| 1394 |
selPtr = winPtr->selHandlerList; |
| 1395 |
winPtr->selHandlerList = selPtr->nextPtr; |
| 1396 |
for (ipPtr = tsdPtr->pendingPtr; ipPtr != NULL; |
| 1397 |
ipPtr = ipPtr->nextPtr) { |
| 1398 |
if (ipPtr->selPtr == selPtr) { |
| 1399 |
ipPtr->selPtr = NULL; |
| 1400 |
} |
| 1401 |
} |
| 1402 |
if (selPtr->proc == HandleCompat) { |
| 1403 |
FreeHandler(selPtr->clientData); |
| 1404 |
} |
| 1405 |
ckfree((char *) selPtr); |
| 1406 |
} |
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
|
| 1412 |
for (infoPtr = winPtr->dispPtr->selectionInfoPtr, prevPtr = NULL; |
| 1413 |
infoPtr != NULL; infoPtr = nextPtr) { |
| 1414 |
nextPtr = infoPtr->nextPtr; |
| 1415 |
if (infoPtr->owner == (Tk_Window) winPtr) { |
| 1416 |
if (infoPtr->clearProc == LostSelection) { |
| 1417 |
FreeLost(infoPtr->clearData); |
| 1418 |
} |
| 1419 |
ckfree((char *) infoPtr); |
| 1420 |
infoPtr = prevPtr; |
| 1421 |
if (prevPtr == NULL) { |
| 1422 |
winPtr->dispPtr->selectionInfoPtr = nextPtr; |
| 1423 |
} else { |
| 1424 |
prevPtr->nextPtr = nextPtr; |
| 1425 |
} |
| 1426 |
} |
| 1427 |
prevPtr = infoPtr; |
| 1428 |
} |
| 1429 |
} |
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
|
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
|
| 1447 |
void |
| 1448 |
TkSelInit(tkwin) |
| 1449 |
Tk_Window tkwin; |
| 1450 |
|
| 1451 |
{ |
| 1452 |
register TkDisplay *dispPtr = ((TkWindow *) tkwin)->dispPtr; |
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
|
| 1457 |
|
| 1458 |
dispPtr->multipleAtom = Tk_InternAtom(tkwin, "MULTIPLE"); |
| 1459 |
dispPtr->incrAtom = Tk_InternAtom(tkwin, "INCR"); |
| 1460 |
dispPtr->targetsAtom = Tk_InternAtom(tkwin, "TARGETS"); |
| 1461 |
dispPtr->timestampAtom = Tk_InternAtom(tkwin, "TIMESTAMP"); |
| 1462 |
dispPtr->textAtom = Tk_InternAtom(tkwin, "TEXT"); |
| 1463 |
dispPtr->compoundTextAtom = Tk_InternAtom(tkwin, "COMPOUND_TEXT"); |
| 1464 |
dispPtr->applicationAtom = Tk_InternAtom(tkwin, "TK_APPLICATION"); |
| 1465 |
dispPtr->windowAtom = Tk_InternAtom(tkwin, "TK_WINDOW"); |
| 1466 |
dispPtr->clipboardAtom = Tk_InternAtom(tkwin, "CLIPBOARD"); |
| 1467 |
|
| 1468 |
|
| 1469 |
|
| 1470 |
|
| 1471 |
|
| 1472 |
|
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 |
#if !(defined(__WIN32__) || defined(MAC_TCL) || defined(MAC_OSX_TK)) |
| 1477 |
dispPtr->utf8Atom = Tk_InternAtom(tkwin, "UTF8_STRING"); |
| 1478 |
#else |
| 1479 |
dispPtr->utf8Atom = (Atom) NULL; |
| 1480 |
#endif |
| 1481 |
} |
| 1482 |
|
| 1483 |
|
| 1484 |
|
| 1485 |
|
| 1486 |
|
| 1487 |
|
| 1488 |
|
| 1489 |
|
| 1490 |
|
| 1491 |
|
| 1492 |
|
| 1493 |
|
| 1494 |
|
| 1495 |
|
| 1496 |
|
| 1497 |
|
| 1498 |
|
| 1499 |
|
| 1500 |
void |
| 1501 |
TkSelClearSelection(tkwin, eventPtr) |
| 1502 |
Tk_Window tkwin; |
| 1503 |
register XEvent *eventPtr; |
| 1504 |
{ |
| 1505 |
register TkWindow *winPtr = (TkWindow *) tkwin; |
| 1506 |
TkDisplay *dispPtr = winPtr->dispPtr; |
| 1507 |
TkSelectionInfo *infoPtr; |
| 1508 |
TkSelectionInfo *prevPtr; |
| 1509 |
|
| 1510 |
|
| 1511 |
|
| 1512 |
|
| 1513 |
|
| 1514 |
|
| 1515 |
|
| 1516 |
|
| 1517 |
|
| 1518 |
|
| 1519 |
for (infoPtr = dispPtr->selectionInfoPtr, prevPtr = NULL; |
| 1520 |
infoPtr != NULL; infoPtr = infoPtr->nextPtr) { |
| 1521 |
if (infoPtr->selection == eventPtr->xselectionclear.selection) { |
| 1522 |
break; |
| 1523 |
} |
| 1524 |
prevPtr = infoPtr; |
| 1525 |
} |
| 1526 |
|
| 1527 |
if (infoPtr != NULL && (infoPtr->owner == tkwin) |
| 1528 |
&& (eventPtr->xselectionclear.serial >= (unsigned) infoPtr->serial)) { |
| 1529 |
if (prevPtr == NULL) { |
| 1530 |
dispPtr->selectionInfoPtr = infoPtr->nextPtr; |
| 1531 |
} else { |
| 1532 |
prevPtr->nextPtr = infoPtr->nextPtr; |
| 1533 |
} |
| 1534 |
|
| 1535 |
|
| 1536 |
|
| 1537 |
|
| 1538 |
|
| 1539 |
|
| 1540 |
|
| 1541 |
|
| 1542 |
if (infoPtr->clearProc != NULL) { |
| 1543 |
(*infoPtr->clearProc)(infoPtr->clearData); |
| 1544 |
} |
| 1545 |
ckfree((char *) infoPtr); |
| 1546 |
} |
| 1547 |
} |
| 1548 |
|
| 1549 |
|
| 1550 |
|
| 1551 |
|
| 1552 |
|
| 1553 |
|
| 1554 |
|
| 1555 |
|
| 1556 |
|
| 1557 |
|
| 1558 |
|
| 1559 |
|
| 1560 |
|
| 1561 |
|
| 1562 |
|
| 1563 |
|
| 1564 |
|
| 1565 |
|
| 1566 |
|
| 1567 |
|
| 1568 |
static int |
| 1569 |
SelGetProc(clientData, interp, portion) |
| 1570 |
ClientData clientData; |
| 1571 |
|
| 1572 |
Tcl_Interp *interp; |
| 1573 |
|
| 1574 |
char *portion; |
| 1575 |
{ |
| 1576 |
Tcl_DStringAppend((Tcl_DString *) clientData, portion, -1); |
| 1577 |
return TCL_OK; |
| 1578 |
} |
| 1579 |
|
| 1580 |
|
| 1581 |
|
| 1582 |
|
| 1583 |
|
| 1584 |
|
| 1585 |
|
| 1586 |
|
| 1587 |
|
| 1588 |
|
| 1589 |
|
| 1590 |
|
| 1591 |
|
| 1592 |
|
| 1593 |
|
| 1594 |
|
| 1595 |
|
| 1596 |
|
| 1597 |
|
| 1598 |
static int |
| 1599 |
HandleTclCommand(clientData, offset, buffer, maxBytes) |
| 1600 |
ClientData clientData; |
| 1601 |
int offset; |
| 1602 |
|
| 1603 |
char *buffer; |
| 1604 |
int maxBytes; |
| 1605 |
{ |
| 1606 |
CommandInfo *cmdInfoPtr = (CommandInfo *) clientData; |
| 1607 |
int spaceNeeded, length; |
| 1608 |
#define MAX_STATIC_SIZE 100 |
| 1609 |
char staticSpace[MAX_STATIC_SIZE]; |
| 1610 |
char *command, *string; |
| 1611 |
Tcl_Interp *interp = cmdInfoPtr->interp; |
| 1612 |
Tcl_Obj *savePtr; |
| 1613 |
Tcl_Obj *objPtr; |
| 1614 |
int extraBytes, charOffset, count, numChars; |
| 1615 |
CONST char *p; |
| 1616 |
|
| 1617 |
|
| 1618 |
|
| 1619 |
|
| 1620 |
|
| 1621 |
|
| 1622 |
Tcl_Preserve(clientData); |
| 1623 |
Tcl_Preserve((ClientData) interp); |
| 1624 |
|
| 1625 |
|
| 1626 |
|
| 1627 |
|
| 1628 |
|
| 1629 |
|
| 1630 |
if (offset == cmdInfoPtr->byteOffset) { |
| 1631 |
charOffset = cmdInfoPtr->charOffset; |
| 1632 |
extraBytes = strlen(cmdInfoPtr->buffer); |
| 1633 |
if (extraBytes > 0) { |
| 1634 |
strcpy(buffer, cmdInfoPtr->buffer); |
| 1635 |
maxBytes -= extraBytes; |
| 1636 |
buffer += extraBytes; |
| 1637 |
} |
| 1638 |
} else { |
| 1639 |
cmdInfoPtr->byteOffset = 0; |
| 1640 |
cmdInfoPtr->charOffset = 0; |
| 1641 |
extraBytes = 0; |
| 1642 |
charOffset = 0; |
| 1643 |
} |
| 1644 |
|
| 1645 |
savePtr = Tcl_GetObjResult(interp); |
| 1646 |
Tcl_IncrRefCount(savePtr); |
| 1647 |
Tcl_ResetResult(interp); |
| 1648 |
|
| 1649 |
#ifndef _LANG |
| 1650 |
|
| 1651 |
|
| 1652 |
|
| 1653 |
|
| 1654 |
|
| 1655 |
spaceNeeded = cmdInfoPtr->cmdLength + 30; |
| 1656 |
if (spaceNeeded < MAX_STATIC_SIZE) { |
| 1657 |
command = staticSpace; |
| 1658 |
} else { |
| 1659 |
command = (char *) ckalloc((unsigned) spaceNeeded); |
| 1660 |
} |
| 1661 |
sprintf(command, "%s %d %d", cmdInfoPtr->command, charOffset, maxBytes); |
| 1662 |
|
| 1663 |
|
| 1664 |
|
| 1665 |
|
| 1666 |
|
| 1667 |
|
| 1668 |
Tcl_DStringInit(&oldResult); |
| 1669 |
Tcl_DStringGetResult(interp, &oldResult); |
| 1670 |
if (TkCopyAndGlobalEval(interp, command) == TCL_OK) { |
| 1671 |
#else |
| 1672 |
if (LangDoCallback(interp, cmdInfoPtr->command,1,2,"%d %d", charOffset, maxBytes) == TCL_OK) { |
| 1673 |
#endif |
| 1674 |
objPtr = Tcl_GetObjResult(interp); |
| 1675 |
string = Tcl_GetStringFromObj(objPtr, &length); |
| 1676 |
count = (length > maxBytes) ? maxBytes : length; |
| 1677 |
memcpy((VOID *) buffer, (VOID *) string, (size_t) count); |
| 1678 |
buffer[count] = '\0'; |
| 1679 |
|
| 1680 |
|
| 1681 |
|
| 1682 |
|
| 1683 |
|
| 1684 |
|
| 1685 |
if (cmdInfoPtr->interp != NULL) { |
| 1686 |
if (length <= maxBytes) { |
| 1687 |
cmdInfoPtr->charOffset += Tcl_NumUtfChars(string, -1); |
| 1688 |
cmdInfoPtr->buffer[0] = '\0'; |
| 1689 |
} else { |
| 1690 |
p = string; |
| 1691 |
string += count; |
| 1692 |
numChars = 0; |
| 1693 |
while (p < string) { |
| 1694 |
p = Tcl_UtfNext(p); |
| 1695 |
numChars++; |
| 1696 |
} |
| 1697 |
cmdInfoPtr->charOffset += numChars; |
| 1698 |
length = p - string; |
| 1699 |
if (length > 0) { |
| 1700 |
strncpy(cmdInfoPtr->buffer, string, (size_t) length); |
| 1701 |
} |
| 1702 |
cmdInfoPtr->buffer[length] = '\0'; |
| 1703 |
} |
| 1704 |
cmdInfoPtr->byteOffset += count + extraBytes; |
| 1705 |
} |
| 1706 |
count += extraBytes; |
| 1707 |
} else { |
| 1708 |
count = -1; |
| 1709 |
} |
| 1710 |
Tcl_SetObjResult(interp,savePtr); |
| 1711 |
|
| 1712 |
#ifndef _LANG |
| 1713 |
if (command != staticSpace) { |
| 1714 |
ckfree(command); |
| 1715 |
} |
| 1716 |
#endif |
| 1717 |
|
| 1718 |
|
| 1719 |
Tcl_Release(clientData); |
| 1720 |
Tcl_Release((ClientData) interp); |
| 1721 |
return count; |
| 1722 |
} |
| 1723 |
|
| 1724 |
|
| 1725 |
|
| 1726 |
|
| 1727 |
|
| 1728 |
|
| 1729 |
|
| 1730 |
|
| 1731 |
|
| 1732 |
|
| 1733 |
|
| 1734 |
|
| 1735 |
|
| 1736 |
|
| 1737 |
|
| 1738 |
|
| 1739 |
|
| 1740 |
|
| 1741 |
|
| 1742 |
|
| 1743 |
|
| 1744 |
|
| 1745 |
|
| 1746 |
|
| 1747 |
|
| 1748 |
|
| 1749 |
|
| 1750 |
int |
| 1751 |
TkSelDefaultSelection(infoPtr, target, lbuffer, maxBytes, typePtr, formatPtr) |
| 1752 |
TkSelectionInfo *infoPtr; |
| 1753 |
Atom target; |
| 1754 |
long *lbuffer; |
| 1755 |
int maxBytes; |
| 1756 |
Atom *typePtr; |
| 1757 |
|
| 1758 |
int *formatPtr; |
| 1759 |
{ |
| 1760 |
register TkWindow *winPtr = (TkWindow *) infoPtr->owner; |
| 1761 |
TkDisplay *dispPtr = winPtr->dispPtr; |
| 1762 |
char *buffer = (char *) lbuffer; |
| 1763 |
|
| 1764 |
if (target == dispPtr->timestampAtom) { |
| 1765 |
if (maxBytes < 20) { |
| 1766 |
return -1; |
| 1767 |
} |
| 1768 |
*((long *) buffer) = (long) infoPtr->time; |
| 1769 |
*typePtr = XA_INTEGER; |
| 1770 |
*formatPtr = 32; |
| 1771 |
return 1; |
| 1772 |
} |
| 1773 |
|
| 1774 |
if (target == dispPtr->targetsAtom) { |
| 1775 |
register TkSelHandler *selPtr; |
| 1776 |
Atom *ap = (Atom *) buffer; |
| 1777 |
|
| 1778 |
if ((char *)ap >= buffer + maxBytes - sizeof(Atom)) |
| 1779 |
return -1; |
| 1780 |
*ap++ = Tk_InternAtom((Tk_Window) winPtr,"MULTIPLE"); |
| 1781 |
if ((char *)ap >= buffer + maxBytes - sizeof(Atom)) |
| 1782 |
return -1; |
| 1783 |
*ap++ = Tk_InternAtom((Tk_Window) winPtr,"TARGETS"); |
| 1784 |
if ((char *)ap >= buffer + maxBytes - sizeof(Atom)) |
| 1785 |
return -1; |
| 1786 |
*ap++ = Tk_InternAtom((Tk_Window) winPtr,"TIMESTAMP"); |
| 1787 |
if ((char *)ap >= buffer + maxBytes - sizeof(Atom)) |
| 1788 |
return -1; |
| 1789 |
*ap++ = Tk_InternAtom((Tk_Window) winPtr,"TK_APPLICATION"); |
| 1790 |
if ((char *)ap >= buffer + maxBytes - sizeof(Atom)) |
| 1791 |
return -1; |
| 1792 |
*ap++ = Tk_InternAtom((Tk_Window) winPtr,"TK_WINDOW"); |
| 1793 |
|
| 1794 |
for (selPtr = winPtr->selHandlerList; selPtr != NULL; |
| 1795 |
selPtr = selPtr->nextPtr) { |
| 1796 |
if (selPtr->selection == infoPtr->selection) { |
| 1797 |
if ((char *)ap >= buffer + maxBytes - sizeof(Atom)) |
| 1798 |
return -1; |
| 1799 |
*ap++ = selPtr->target; |
| 1800 |
} |
| 1801 |
} |
| 1802 |
*typePtr = XA_ATOM; |
| 1803 |
*formatPtr = 32; |
| 1804 |
return (ap - ((Atom *) buffer)); |
| 1805 |
} |
| 1806 |
|
| 1807 |
if (target == dispPtr->applicationAtom) { |
| 1808 |
int length; |
| 1809 |
Tk_Uid name = winPtr->mainPtr->winPtr->nameUid; |
| 1810 |
|
| 1811 |
length = strlen(name); |
| 1812 |
if (maxBytes <= length) { |
| 1813 |
return -1; |
| 1814 |
} |
| 1815 |
strcpy(buffer, name); |
| 1816 |
*typePtr = XA_STRING; |
| 1817 |
*formatPtr = 8; |
| 1818 |
return length; |
| 1819 |
} |
| 1820 |
|
| 1821 |
if (target == dispPtr->windowAtom) { |
| 1822 |
int length; |
| 1823 |
char *name = winPtr->pathName; |
| 1824 |
|
| 1825 |
length = strlen(name); |
| 1826 |
if (maxBytes <= length) { |
| 1827 |
return -1; |
| 1828 |
} |
| 1829 |
strcpy(buffer, name); |
| 1830 |
*typePtr = XA_STRING; |
| 1831 |
*formatPtr = 8; |
| 1832 |
return length; |
| 1833 |
} |
| 1834 |
|
| 1835 |
return -1; |
| 1836 |
} |
| 1837 |
|
| 1838 |
|
| 1839 |
|
| 1840 |
|
| 1841 |
|
| 1842 |
|
| 1843 |
|
| 1844 |
|
| 1845 |
|
| 1846 |
|
| 1847 |
|
| 1848 |
|
| 1849 |
|
| 1850 |
|
| 1851 |
|
| 1852 |
|
| 1853 |
|
| 1854 |
|
| 1855 |
|
| 1856 |
static void |
| 1857 |
LostSelection(clientData) |
| 1858 |
ClientData clientData; |
| 1859 |
{ |
| 1860 |
LostCommand *lostPtr = (LostCommand *) clientData; |
| 1861 |
Tcl_Obj *objPtr; |
| 1862 |
Tcl_Interp *interp; |
| 1863 |
|
| 1864 |
interp = lostPtr->interp; |
| 1865 |
Tcl_Preserve((ClientData) interp); |
| 1866 |
|
| 1867 |
|
| 1868 |
|
| 1869 |
|
| 1870 |
|
| 1871 |
|
| 1872 |
objPtr = Tcl_GetObjResult(interp); |
| 1873 |
Tcl_IncrRefCount(objPtr); |
| 1874 |
Tcl_ResetResult(interp); |
| 1875 |
|
| 1876 |
#ifndef _LANG |
| 1877 |
if (TkCopyAndGlobalEval(interp, lostPtr->command) != TCL_OK) { |
| 1878 |
#else |
| 1879 |
if (LangDoCallback(interp, lostPtr->command,0,0) != TCL_OK) { |
| 1880 |
#endif |
| 1881 |
Tcl_BackgroundError(interp); |
| 1882 |
} |
| 1883 |
|
| 1884 |
Tcl_SetObjResult(interp, objPtr); |
| 1885 |
|
| 1886 |
Tcl_Release((ClientData) interp); |
| 1887 |
|
| 1888 |
|
| 1889 |
|
| 1890 |
|
| 1891 |
FreeLost(clientData); |
| 1892 |
} |
| 1893 |
|
| 1894 |
static void |
| 1895 |
FreeLost(clientData) |
| 1896 |
ClientData clientData; |
| 1897 |
{ |
| 1898 |
LostCommand *lostPtr = (LostCommand *) clientData; |
| 1899 |
LangFreeCallback(lostPtr->command); |
| 1900 |
ckfree((char *) lostPtr); |
| 1901 |
} |
| 1902 |
|
| 1903 |
|
| 1904 |
|
| 1905 |
|
| 1906 |
|