2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $TOG: Dnd.c /main/7 1998/10/23 13:47:10 mgreess $ */
24 /*********************************************************************
28 * Description: Implemenation of DND Convenience API.
30 *********************************************************************
34 * RESTRICTED CONFIDENTIAL INFORMATION:
36 * The information in this document is subject to special
37 * restrictions in a confidential disclosure agreement between
38 * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
39 * document outside HP, IBM, Sun, USL, SCO, or Univel without
40 * Sun's specific written approval. This documment and all copies
41 * and derivative works thereof must be returned or destroyed at
44 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
46 * (c) Copyright 1993, 1994 Hewlett-Packard Company
47 * (c) Copyright 1993, 1994 International Business Machines Corp.
48 * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
49 * (c) Copyright 1993, 1994 Novell, Inc.
56 #include <sys/utsname.h>
57 #include <X11/Intrinsic.h>
59 #include <Xm/DragDrop.h>
60 #include <Xm/DropTrans.h>
61 #include <Dt/UserMsg.h>
64 #include "DtSvcLock.h"
66 /*********************************************************************
68 * Data Transfer Selection Targets
70 *********************************************************************/
79 Atom XA_SUN_FILE_HOST_NAME;
80 Atom XA_SUN_ENUM_COUNT;
81 Atom XA_SUN_DATA_LABEL;
82 Atom XA_SUN_SELN_READONLY;
83 Atom XA_SUN_ATM_FILE_NAME;
84 Atom XA_SUN_ATM_METHODS;
91 if (XA_TARGETS != 0) {
92 _DtSvcProcessUnlock();
96 XA_TARGETS = DtGetAtom(dpy,"TARGETS");
97 XA_TIMESTAMP = DtGetAtom(dpy,"TIMESTAMP");
98 XA_MULTIPLE = DtGetAtom(dpy,"MULTIPLE");
99 XA_DELETE = DtGetAtom(dpy,"DELETE");
100 XA_NULL = DtGetAtom(dpy,"NULL");
101 XA_TEXT = DtGetAtom(dpy,"TEXT");
102 XA_HOST_NAME = DtGetAtom(dpy,"HOST_NAME");
103 XA_SUN_FILE_HOST_NAME = DtGetAtom(dpy,"_SUN_FILE_HOST_NAME");
104 XA_SUN_ENUM_COUNT = DtGetAtom(dpy,"_SUN_ENUMERATION_COUNT");
105 XA_SUN_DATA_LABEL = DtGetAtom(dpy,"_SUN_DATA_LABEL");
106 XA_SUN_SELN_READONLY = DtGetAtom(dpy,"_SUN_SELN_IS_READONLY");
107 XA_SUN_ATM_FILE_NAME = DtGetAtom(dpy,"_SUN_ATM_FILE_NAME");
108 XA_SUN_ATM_METHODS = DtGetAtom(dpy,
109 "_SUN_ALTERNATE_TRANSPORT_METHODS");
110 _DtSvcProcessUnlock();
113 /*********************************************************************
115 * Data Transfer Protocol Method Functions
117 *********************************************************************/
119 static DtDndProtocol dndProtocolList[] = {
120 DtDND_FILENAME_TRANSFER,
121 DtDND_BUFFER_TRANSFER,
126 extern DtDndMethods *_DtDndBuffTransferProtocolInitialize(Display*);
127 extern DtDndMethods *_DtDndFileTransferProtocolInitialize(Display*);
128 extern DtDndMethods *_DtDndTextTransferProtocolInitialize(Display*);
131 * dndGetTransferMethods
133 * Return the transfer methods for a particular protocol
135 static DtDndMethods *
136 dndGetTransferMethods(
138 DtDndProtocol protocol)
140 DtDndMethods * methods = NULL;
143 case DtDND_BUFFER_TRANSFER:
144 methods = _DtDndBuffTransferProtocolInitialize(display);
146 case DtDND_FILENAME_TRANSFER:
147 methods = _DtDndFileTransferProtocolInitialize(display);
149 case DtDND_TEXT_TRANSFER:
150 methods = _DtDndTextTransferProtocolInitialize(display);
158 * _DtDndCreateExportTransfer
160 * Returns a transfer suitable for use by a drag initiator
163 _DtDndCreateExportTransfer(
164 DtDragInfo * dtDragInfo)
166 Display * dpy = XtDisplayOfObject(dtDragInfo->dragInitiator);
167 DtDndTransfer * transfer;
171 transfer = (DtDndTransfer *)XtMalloc(sizeof(DtDndTransfer));
173 transfer->methods = dndGetTransferMethods(dpy,dtDragInfo->protocol);
175 (*transfer->methods->getExportTargets)(dtDragInfo,
176 &(transfer->targets), &(transfer->numTargets));
182 * _DtDndCreateImportTransfers
184 * Create the list of transfers specified by the protocols.
187 _DtDndCreateImportTransfers(
188 DtDropInfo * dtDropInfo,
189 Cardinal * numTransfers)
191 Display * dpy = XtDisplayOfObject(dtDropInfo->dropReceiver);
192 DtDndTransfer * transfers;
193 DtDndTransfer * transfer;
200 for (ii = 0; dndProtocolList[ii] != DtDND_NOOP_TRANSFER; ii++) {
201 if (dtDropInfo->protocols & dndProtocolList[ii]) {
206 if (*numTransfers == 0)
207 return (DtDndTransfer *)NULL;
209 transfers = (DtDndTransfer *)XtMalloc(
210 *numTransfers * sizeof(DtDndTransfer));
212 for (ii = 0, jj = 0; dndProtocolList[ii] != DtDND_NOOP_TRANSFER; ii++) {
213 if (dtDropInfo->protocols & dndProtocolList[ii]) {
214 transfer = &transfers[jj++];
216 dndGetTransferMethods(dpy,dndProtocolList[ii]);
217 (*transfer->methods->getImportTargets)(dtDropInfo,
218 &(transfer->targets), &(transfer->numTargets));
226 * _DtDndDestroyTransfers
228 * Destroy the transfer list created by
229 * _DtDndCreateExportTransfer() or _DtDndCreateImportTransfers()
232 _DtDndDestroyTransfers(
233 DtDndTransfer * transfers,
234 Cardinal numTransfers)
239 for (ii = 0; ii < numTransfers; ii++) {
240 XtFree((char *)transfers[ii].targets);
242 XtFree((char *)transfers);
246 * _DtDndTransferFromTargets
248 * Returns the transfer method that matches the target list
251 _DtDndTransferFromTargets(
252 DtDndTransfer * transfers,
253 Cardinal numTransfers,
259 for (ii = 0; ii < numTransfers; ii++) {
260 for (jj = 0; jj < transfers[ii].numTargets; jj++) {
261 for (kk = 0; kk < numTargets; kk++) {
262 if (transfers[ii].targets[jj] == targets[kk]) {
263 return &transfers[ii];
268 return (DtDndTransfer *)NULL;
274 * Add the targets to the requested transfer targets list
275 * and call XmDropTransferAdd() to request them
280 DtDropInfo * dtDropInfo,
281 Atom * transferTargets,
282 Cardinal numTransferTargets)
284 DtTransferInfo *transferInfo = dtDropInfo->transferInfo;
285 XmDropTransferEntryRec * transferEntries;
286 Cardinal numTransfers;
289 transferEntries = (XmDropTransferEntryRec *)
290 XtMalloc(numTransferTargets * sizeof(XmDropTransferEntryRec));
292 numTransfers = transferInfo->numTransferTargets + numTransferTargets;
294 transferInfo->transferTargets = (Atom *)XtRealloc(
295 (char *)transferInfo->transferTargets,
296 numTransfers * sizeof(Atom));
298 jj = transferInfo->numTransferTargets;
300 for (ii = 0; ii < numTransferTargets; ii++) {
301 transferEntries[ii].target = transferTargets[ii];
302 transferEntries[ii].client_data = (XtPointer)dtDropInfo;
304 transferInfo->transferTargets[ii+jj] = transferTargets[ii];
307 transferInfo->numTransferTargets = numTransfers;
309 XmDropTransferAdd(dropTransfer, transferEntries, numTransferTargets);
311 XtFree((char *)transferEntries);
314 /*********************************************************************
316 * Misc Debugging Functions
318 *********************************************************************/
330 for (ii = 0; ii < numTargets; ii++) {
331 name = XGetAtomName(display, targets[ii]);
343 _DtDndPrintTransfers(
345 DtDndTransfer *transfers,
346 Cardinal numTransfers)
350 for (ii = 0; ii < numTransfers; ii++) {
351 printf("%s\tTargets: ",transfers[ii].methods->name);
352 _DtDndPrintTargets(display,
353 transfers[ii].targets,transfers[ii].numTargets);
358 /*********************************************************************
360 * Misc Utility Functions
362 *********************************************************************/
368 _DtDndCopyCallbackList(
369 XtCallbackList callbacks)
374 if (callbacks == NULL)
378 for (cl = callbacks; cl->callback != NULL; cl++) {
382 cl = (XtCallbackList)XtMalloc(count * sizeof(XtCallbackRec));
384 for (ii = 0; ii < count; ii++) {
385 cl[ii].callback = callbacks[ii].callback;
386 cl[ii].closure = callbacks[ii].closure;
396 _DtDndCallCallbackList(
398 XtCallbackList callbacks,
403 if (callbacks == NULL)
406 for (cl = callbacks; cl->callback != NULL; cl++) {
407 (*cl->callback)(widget, cl->closure, calldata);
412 * Misc Varargs Utility Functions
423 for (argPtr = va_arg(vaList,String);
425 argPtr = va_arg(vaList,String)) {
427 va_arg(vaList, XtArgVal);
435 _DtDndArgListFromVarArgs(
438 ArgList *argListReturn,
439 Cardinal *argCountReturn)
447 *argListReturn = NULL;
452 argList = (ArgList)XtMalloc((unsigned)(maxArgs * sizeof(Arg)));
455 for (argPtr = va_arg(vaList,String);
457 argPtr = va_arg(vaList,String)) {
459 XtSetArg(argList[argCount], argPtr, va_arg(vaList,XtArgVal));
463 *argListReturn = argList;
464 *argCountReturn = argCount;
468 * Returns the network node/host name.
471 _DtDndGetHostName(void)
473 static char *nodename;
476 if (nodename == NULL) {
479 if (uname(&un) == -1) {
480 _DtSimpleError(DtProgName,DtError, NULL, "uname", NULL);
481 nodename = XtNewString("nodename");
483 nodename = XtNewString(un.nodename);
486 _DtSvcProcessUnlock();