1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635
|
/*
* Motif
*
* Copyright (c) 1987-2012, The Open Group. All rights reserved.
*
* These libraries and programs are free software; you can
* redistribute them and/or modify them under the terms of the GNU
* Lesser General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* These libraries and programs are distributed in the hope that
* they will be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with these librararies and programs; if not, write
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
* Floor, Boston, MA 02110-1301 USA
*/
#ifdef REV_INFO
#ifndef lint
static char rcsid[] = "$XConsortium: DropTrans.c /main/15 1996/05/02 13:50:19 pascale $"
#endif
#endif
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <Xm/DropTransP.h>
#include <Xm/DragCP.h>
#include "XmI.h"
#include "DragCI.h"
#include "DragICCI.h"
#include <Xm/AtomMgr.h>
#include <stdio.h>
/* Deactivated the fix, since it causes crash.
For details see http://bugs.motifzone.net/long_list.cgi?buglist=1361
#define CR1146
*/
#ifdef CR1146
static int isValidStartDropTimerId = 0;
#endif
/******** Static Function Declarations ********/
static void ClassPartInit(
WidgetClass wc) ;
static void Initialize(
Widget rw,
Widget nw,
ArgList args,
Cardinal *num_args) ;
static Boolean SetValues(
Widget cw,
Widget rw,
Widget nw,
ArgList args,
Cardinal *num_args) ;
static void Destroy(
Widget w) ;
static void SourceNotifiedCB(
Widget w,
XtPointer client_data,
Atom *selection,
Atom *type,
XtPointer value,
unsigned long *length,
int *format) ;
static void TerminateTransfer(
XmDropTransferObject dt,
Atom *selection) ;
static void ProcessTransferEntry(
XmDropTransferObject dt,
Cardinal which) ;
static void DropTransferSelectionCB(
Widget w,
XtPointer client_data,
Atom *selection,
Atom *type,
XtPointer value,
unsigned long *length,
int *format) ;
static Widget StartDropTransfer(
Widget refWidget,
ArgList args,
Cardinal argCount) ;
static void AddDropTransfer(
Widget widget,
XmDropTransferEntry transfers,
Cardinal num_transfers) ;
static void DragContextDestroyCB(
Widget widget,
XtPointer client,
XtPointer call) ;
/******** End Static Function Declarations ********/
static XtResource resources[] = {
{ XmNdropTransfers, XmCDropTransfers,
XmRDropTransfers, sizeof(XmDropTransferEntry),
XtOffsetOf( struct _XmDropTransferRec,
dropTransfer.drop_transfers),
XmRImmediate, (XtPointer) NULL
},
{ XmNnumDropTransfers, XmCNumDropTransfers,
XmRCardinal, sizeof(Cardinal),
XtOffsetOf( struct _XmDropTransferRec,
dropTransfer.num_drop_transfers),
XmRImmediate, (XtPointer) 0
},
{ XmNincremental, XmCIncremental, XmRBoolean, sizeof(Boolean),
XtOffsetOf( struct _XmDropTransferRec, dropTransfer.incremental),
XmRImmediate, (XtPointer) FALSE
},
{ XmNtransferProc, XmCTransferProc,
XmRCallbackProc, sizeof(XtSelectionCallbackProc),
XtOffsetOf( struct _XmDropTransferRec, dropTransfer.transfer_callback),
XmRImmediate, (XtPointer) 0
},
{ XmNtransferStatus, XmCTransferStatus, XmRTransferStatus,
sizeof(unsigned char),
XtOffsetOf( struct _XmDropTransferRec, dropTransfer.transfer_status),
XmRImmediate, (XtPointer) XmTRANSFER_SUCCESS
},
};
/* class record definition */
externaldef(xmgadgetclassrec) XmDropTransferClassRec
xmDropTransferClassRec = {
{
(WidgetClass) &objectClassRec, /* superclass */
"XmDropTransfer", /* class_name */
sizeof(XmDropTransferRec), /* widget_size */
NULL, /* class_initialize */
ClassPartInit, /* class part initialize */
False, /* class_inited */
Initialize, /* initialize */
NULL, /* initialize_hook */
NULL, /* obj1 */
NULL, /* obj2 */
0, /* obj3 */
resources, /* resources */
XtNumber(resources), /* num_resources */
NULLQUARK, /* xrm_class */
True, /* obj4 */
XtExposeCompressSeries, /* obj5 */
True, /* obj6 */
False, /* obj7 */
Destroy, /* destroy */
NULL, /* obj8 */
NULL, /* obj9 */
SetValues, /* set_values */
NULL, /* set_values_hook */
NULL, /* obj10 */
NULL, /* get_values_hook */
NULL, /* obj11 */
XtVersion, /* version */
NULL, /* callback private */
NULL, /* obj12 */
NULL, /* obj13 */
NULL, /* obj14 */
NULL, /* extension */
},
{
StartDropTransfer, /* start_drop_transfer */
AddDropTransfer, /* add_drop_transfer */
NULL, /* extension */
},
};
externaldef(xmdroptransferobjectclass) WidgetClass
xmDropTransferObjectClass = (WidgetClass)
&xmDropTransferClassRec;
/*ARGSUSED*/
static void
ClassPartInit(
WidgetClass wc )
{
}
/*ARGSUSED*/
static void
Initialize(
Widget rw,
Widget nw,
ArgList args,
Cardinal *num_args )
{
XmDropTransferObject new_w = (XmDropTransferObject) nw;
XmDropTransferPart *dtp =
(XmDropTransferPart *) &(new_w->dropTransfer);
if (dtp->num_drop_transfers != 0)
{
dtp->num_drop_transfer_lists = 1;
dtp->drop_transfer_lists = (XmDropTransferList)
XtMalloc(sizeof(XmDropTransferListRec) *
dtp->num_drop_transfer_lists);
dtp->drop_transfer_lists[0].transfer_list =
(XmDropTransferEntry)_XmAllocAndCopy(
dtp->drop_transfers, sizeof(XmDropTransferEntryRec)
* dtp->num_drop_transfers);
dtp->drop_transfer_lists[0].num_transfers =
dtp->num_drop_transfers;
/* strictly for hygene... */
dtp->drop_transfers = dtp->drop_transfer_lists[0].transfer_list;
}
else
{
dtp->drop_transfer_lists = NULL;
dtp->num_drop_transfer_lists = 0;
}
dtp->motif_drop_atom = XInternAtom(
XtDisplayOfObject(nw), XmS_MOTIF_DROP, False);
dtp->cur_drop_transfer_list = (Cardinal) -1;
dtp->cur_xfer = (Cardinal) -1;
dtp->cur_targets = (Atom *) NULL;
dtp->cur_client_data = (XtPointer *) NULL;
}
/*ARGSUSED*/
static Boolean
SetValues(
Widget cw,
Widget rw,
Widget nw,
ArgList args,
Cardinal *num_args )
{
/* Stub */
/* !!! Should disallow any changes !!! */
return True;
}
static void
Destroy(
Widget w )
{
XmDropTransferObject new_w = (XmDropTransferObject) w;
Cardinal i;
XmDragContext dc;
/*
* clean up the hanging dragContext
*/
dc = (XmDragContext)XmGetDragContext((Widget)new_w,
new_w->dropTransfer.timestamp);
if (dc && dc->drag.sourceIsExternal)
XtDestroyWidget((Widget)dc);
for (i = 0; i < new_w->dropTransfer.num_drop_transfer_lists; i++)
{
XmDropTransferList currEntry =
&(new_w->dropTransfer.drop_transfer_lists[i]);
XtFree((char *)currEntry->transfer_list);
}
XtFree((char *)new_w->dropTransfer.drop_transfer_lists);
}
/*ARGSUSED*/
static void
SourceNotifiedCB(
Widget w,
XtPointer client_data,
Atom *selection,
Atom *type,
XtPointer value,
unsigned long *length,
int *format )
{
XmDropTransferObject dt = (XmDropTransferObject)client_data;
if (value != NULL)
XtFree((char *) value);
/* self-immolution aaaaaaiii */
XtDestroyWidget((Widget)dt);
}
static void
TerminateTransfer(
XmDropTransferObject dt,
Atom *selection )
{
Atom status;
XmDropTransferPart *dtp =
(XmDropTransferPart *) &(dt->dropTransfer);
XmDragContext dc = (XmDragContext) dtp->dragContext;
if (dtp->transfer_status == XmTRANSFER_SUCCESS)
status = XInternAtom(XtDisplayOfObject((Widget)dt),
XmSTRANSFER_SUCCESS, False);
else /* XmTRANSFER_FAILURE */
status = XInternAtom(XtDisplayOfObject((Widget)dt),
XmSTRANSFER_FAILURE, False);
/*
* we need to pass in the shell since that is the only widget
* visible to the initiator.
*/
XtGetSelectionValue(dc->drag.currReceiverInfo->shell,
*selection, status,
SourceNotifiedCB, (XtPointer)dt,
dtp->timestamp);
}
static void
ProcessTransferEntry(
XmDropTransferObject dt,
Cardinal which )
{
XmDropTransferPart *dtp =
(XmDropTransferPart *) &(dt->dropTransfer);
XmDropTransferList tl = &(dtp->drop_transfer_lists[which]);
XmDragContext dc = (XmDragContext)dtp->dragContext;
Cardinal i;
Arg args[1];
Atom real_selection_atom;
dtp->cur_drop_transfer_list = which;
dtp->cur_targets = (Atom *)
XtMalloc((tl->num_transfers * sizeof(Atom)));
dtp->cur_client_data = (XtPointer *)
XtMalloc((tl->num_transfers * sizeof(XtPointer)));
i = 0;
XtSetArg(args[i], XmNiccHandle, &real_selection_atom); i++;
XtGetValues(dtp->dragContext, args, i);
for (i=0; i < tl->num_transfers; i++)
{
dtp->cur_targets[i] = tl->transfer_list[i].target;
/*
* all of the client data have to point to us so that we can
* bootstrap
*/
dtp->cur_client_data[i] = (XtPointer)dt;
}
dtp->cur_xfer = 0;
/*
* we need to pass in the destShell since that is the only widget
* visible to the initiator.
*/
/*
* As both an optimization and workaround for an Xt bug,
* if the number of transfers is just one then call the
* singular version of XtGetSelectionValue{,Incremental}.
* If there is only one item there is no need to call
* the plural version; XtGetSelectionValues
* Also there is a bug in some Xt's which fail to handle
* both MULTIPLE and INCR together correctly and can hang
* the drop transfer forever. By adding this special case
* we allow knowledgeable clients to request any target that
* might be large enough to trigger an INCR as a single item
* that would avoid the MULTIPLE case.
*/
if (dtp->incremental)
{
if (tl->num_transfers == 1) {
XtGetSelectionValueIncremental(
dc->drag.currReceiverInfo->shell,
real_selection_atom, dtp->cur_targets[0],
DropTransferSelectionCB,
(XtPointer)dtp->cur_client_data[0],
dtp->timestamp);
} else {
XtGetSelectionValuesIncremental(
dc->drag.currReceiverInfo->shell,
real_selection_atom, dtp->cur_targets,
tl->num_transfers, DropTransferSelectionCB,
(XtPointer *)dtp->cur_client_data,
dtp->timestamp);
}
}
else
{
if (tl->num_transfers == 1) {
XtGetSelectionValue(dc->drag.currReceiverInfo->shell,
real_selection_atom, dtp->cur_targets[0],
DropTransferSelectionCB,
(XtPointer)dtp->cur_client_data[0],
dtp->timestamp);
} else {
XtGetSelectionValues(dc->drag.currReceiverInfo->shell,
real_selection_atom, dtp->cur_targets,
tl->num_transfers, DropTransferSelectionCB,
(XtPointer *)dtp->cur_client_data,
dtp->timestamp);
}
}
}
/*
* This routine is called with the shell as the widget and us as the
* client data. We can't pass ourselves since we're not windowed
*/
/*ARGSUSED*/
static void
DropTransferSelectionCB(
Widget w,
XtPointer client_data,
Atom *selection,
Atom *type,
XtPointer value,
unsigned long *length,
int *format )
{
XmDropTransferObject dt = (XmDropTransferObject) client_data;
XmDropTransferPart *dtp =
(XmDropTransferPart *) &(dt->dropTransfer);
XmDropTransferList tl =
&(dtp->drop_transfer_lists[dtp->cur_drop_transfer_list]);
(*(dtp->transfer_callback))
((Widget)dt, tl->transfer_list[dtp->cur_xfer].client_data,
selection, type, value, length, format);
/* The transfer list needs to be reassigned at this point in case
* an XmDropTransferAdd() was called in the callback.
*/
tl = &(dtp->drop_transfer_lists[dtp->cur_drop_transfer_list]);
if ( !(dtp->incremental)
||
((dtp->incremental) && (value != NULL) && (*length == 0)))
{
dtp->cur_xfer++;
if (dtp->cur_xfer == tl->num_transfers)
{
XtFree((char *)dtp->cur_targets);
XtFree((char *)dtp->cur_client_data);
if (++(dtp->cur_drop_transfer_list) <
dtp->num_drop_transfer_lists)
{
/* Get the next transfer entry in the list and process it */
ProcessTransferEntry(dt, dtp->cur_drop_transfer_list);
}
else /* notify the source that we're done */
TerminateTransfer(dt, selection);
}
}
}
/*ARGSUSED*/
static void
StartDropTimer(
XtPointer clientData,
XtIntervalId *id )
{
XmDropTransferObject dt = (XmDropTransferObject)clientData;
XmDropTransferPart *dtp;
Arg my_args[1];
int i;
Atom selection;
#ifdef CR1146
isValidStartDropTimerId = 0;
#endif
dtp = (XmDropTransferPart *) &(dt->dropTransfer);
if (dtp->num_drop_transfer_lists)
{
/* Get the first transfer entry in the list and process it */
ProcessTransferEntry(dt, 0);
}
else /* notify the source that we've changed our mind */
{
i = 0;
XtSetArg(my_args[i], XmNiccHandle, &selection); i++;
XtGetValues(dtp->dragContext, my_args, i);
TerminateTransfer(dt, &selection);
}
}
static void
DragContextDestroyCB(
Widget widget,
XtPointer client,
XtPointer call)
{
XtIntervalId timer = (XtIntervalId) client;
#ifdef CR1146
if (!isValidStartDropTimerId) return;
#endif
XtRemoveTimeOut(timer);
}
static Widget
StartDropTransfer(
Widget refWidget,
ArgList args,
Cardinal argCount )
{
static int which = 0;
XmDropTransferObject dt;
char buf[30];
XtIntervalId timer;
_XmProcessLock();
sprintf(buf, "Transfer%d", which++);
_XmProcessUnlock();
dt = (XmDropTransferObject) XtCreateWidget(buf,
xmDropTransferObjectClass,
(Widget) XmGetXmDisplay(XtDisplayOfObject(refWidget)),
args, argCount);
dt->dropTransfer.dragContext = refWidget;
dt->dropTransfer.timestamp =
((XmDragContext)refWidget)->drag.dragFinishTime;
/*
* The processing of the dropTransfer should happen after the
* dropStart message is echoed to the initiator. Since we're
* being called out of the dropProc of the receiver we can't
* just proceed or else the entire transfer could happen
* inline. We therefore add ourselves as a zero length timer
* which will allow us to get called after the dropProc has
* returned.
* To prevent against this code's being called twice by disparate
* parts of the drag/drop code (especially on failure) self-guard by
* watching for destruction of the widget and avoid the rest of the
* operations.
*/
timer = XtAppAddTimeOut(XtWidgetToApplicationContext( (Widget)dt),
0, StartDropTimer, (XtPointer)dt);
#ifdef CR1146
if (isValidStartDropTimerId) {
printf("Motif Error in file %s at line %d: A DropTimer is already active,\n", __FILE__, __LINE__);
}
isValidStartDropTimerId = 1;
#endif
XtAddCallback(refWidget, XmNdestroyCallback, DragContextDestroyCB,
(XtPointer)timer);
return((Widget) dt);
}
Widget
XmDropTransferStart(
Widget refWidget,
ArgList args,
Cardinal argCount )
{
Widget ddo = (Widget) XmGetXmDisplay(XtDisplayOfObject(refWidget));
XmDropTransferObjectClass wc;
Arg lclArgs[1];
int n;
Widget ret_val;
_XmWidgetToAppContext(refWidget);
_XmAppLock(app);
n = 0;
XtSetArg(lclArgs[n], XmNdropTransferClass, &wc); n++;
XtGetValues(ddo, lclArgs, n);
ret_val = (*(wc->dropTransfer_class.start_drop_transfer))
(refWidget, args, argCount);
_XmAppUnlock(app);
return ret_val;
}
static void
AddDropTransfer(
Widget widget,
XmDropTransferEntry transfers,
Cardinal num_transfers )
{
XmDropTransferObject dto = (XmDropTransferObject) widget;
XmDropTransferPart *dtp =
(XmDropTransferPart *) &(dto->dropTransfer);
Cardinal index = dtp->num_drop_transfer_lists++;
dtp->drop_transfer_lists = (XmDropTransferList)
XtRealloc((char *)dtp->drop_transfer_lists,
sizeof(XmDropTransferListRec) *
dtp->num_drop_transfer_lists);
dtp->drop_transfer_lists[index].transfer_list =
(XmDropTransferEntry)_XmAllocAndCopy(
transfers, sizeof(XmDropTransferEntryRec) * num_transfers);
dtp->drop_transfer_lists[index].num_transfers = num_transfers;
}
void
XmDropTransferAdd(
Widget widget,
XmDropTransferEntry transfers,
Cardinal num_transfers )
{
XmDropTransferObject dt = (XmDropTransferObject) widget;
XmDropTransferObjectClass wc;
_XmWidgetToAppContext(widget);
_XmAppLock(app);
wc = (XmDropTransferObjectClass) XtClass(dt);
((*(wc->dropTransfer_class.add_drop_transfer))
(widget, transfers, num_transfers));
_XmAppUnlock(app);
}
|