Initial import of the CDE 2.1.30 sources from the Open Group.

This commit is contained in:
Peter Howkins
2012-03-10 18:21:40 +00:00
commit 83b6996daa
18978 changed files with 3945623 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
!##########################################################################
!# (c) Copyright 1993, 1994 Hewlett-Packard Company
!# (c) Copyright 1993, 1994 International Business Machines Corp.
!# (c) Copyright 1993, 1994 Sun Microsystems, Inc.
!# (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of
!# Novell, Inc.
!##########################################################################
! DnDDemo app-defaults file
*Dtdnddemo.title: CDE Drag & Drop Demo
*Dtdnddemo*outerRowColumn.orientation: VERTICAL
*Dtdnddemo*outerRowColumn.spacing: 15
*Dtdnddemo*outerRowColumn.marginHeight: 15
*Dtdnddemo*outerRowColumn.marginWidth: 15
*Dtdnddemo*upperRowColumn.orientation: HORIZONTAL
*Dtdnddemo*upperRowColumn.packing: PACK_COLUMN
*Dtdnddemo*upperRowColumn.spacing: 15
*Dtdnddemo*upperRowColumn.marginHeight: 0
*Dtdnddemo*upperRowColumn.marginWidth: 0
*Dtdnddemo*fileDraw.height: 175
*Dtdnddemo*fileDraw.resizePolicy: RESIZE_NONE
*Dtdnddemo*fruitList.listSizePolicy: CONSTANT
*Dtdnddemo*fruitList.scrollBarDisplayPolicy: STATIC
*Dtdnddemo*apptList.listSizePolicy: CONSTANT
*Dtdnddemo*apptList.scrollBarDisplayPolicy: STATIC
*Dtdnddemo*apptList.selectionPolicy: MULTIPLE_SELECT
*Dtdnddemo*textRowColumn.orientation: HORIZONTAL
*Dtdnddemo*textRowColumn.packing: PACK_TIGHT
*Dtdnddemo*textRowColumn*textLabel.labelString: Name:
*Dtdnddemo*textRowColumn*textField.width: 550
*Dtdnddemo*textRowColumn.marginWidth: 0
*Dtdnddemo*dropDraw.height: 100
*Dtdnddemo*dropDraw.resizePolicy: RESIZE_NONE

View File

@@ -0,0 +1,45 @@
# $XConsortium: Makefile.hp /main/2 1996/05/13 11:45:18 drk $
##########################################################################
#
# Makefile for dtdnddemo
#
# HP Platform
#
# (c) Copyright 1993, 1994 Hewlett-Packard Company
# (c) Copyright 1993, 1994 International Business Machines Corp.
# (c) Copyright 1993, 1994 Sun Microsystems, Inc.
# (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of
# Novell, Inc.
##########################################################################
PROGRAM = dtdnddemo
SOURCES = demo.c icon.c text.c file.c buff.c
OBJECTS = demo.o icon.o text.o file.o buff.o
APPDEFAULTS = Dtdnddemo
DEFINES = -D_HPUX_SOURCE
CDEBUGFLAGS = -O
CFLAGS = -Aa -z $(DEFINES) $(CDEBUGFLAGS)
DTINCLUDE = -I/usr/dt/include
X11INCLUDE = -I/usr/include/X11R5
INCLUDES = $(DTINCLUDE) $(X11INCLUDE)
DTLIBS = -L/usr/dt/lib -lDtSvc -ltt -lXm
X11LIBS = -L/usr/lib/X11R5 -lXt -lX11
SYSLIBS =
LIBRARIES = $(DTLIBS) $(X11LIBS) $(SYSLIBS)
LDFLAGS =
.c.o:
${CC} -c $(CFLAGS) $(INCLUDES) $<
all:: $(PROGRAM)
$(PROGRAM):: $(OBJECTS) $(APPDEFAULTS)
${CC} -o $(PROGRAM) $(LDFLAGS) $(OBJECTS) $(LIBRARIES)
clean::
rm -f $(PROGRAM) $(OBJECTS)

View File

@@ -0,0 +1,45 @@
# $XConsortium: Makefile.ibm /main/2 1996/05/13 11:45:35 drk $
##########################################################################
#
# Makefile for dtdnddemo
#
# IBM Platform
#
# (c) Copyright 1993, 1994 Hewlett-Packard Company
# (c) Copyright 1993, 1994 International Business Machines Corp.
# (c) Copyright 1993, 1994 Sun Microsystems, Inc.
# (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of
# Novell, Inc.
##########################################################################
PROGRAM = dtdnddemo
SOURCES = demo.c icon.c text.c file.c buff.c
OBJECTS = demo.o icon.o text.o file.o buff.o
APPDEFAULTS = Dtdnddemo
DEFINES =
CDEBUGFLAGS = -O
CFLAGS = $(DEFINES) $(CDEBUGFLAGS)
DTINCLUDE = -I/usr/dt/include
X11INCLUDE = -I/usr/include
INCLUDES = $(DTINCLUDE) $(X11INCLUDE)
DTLIBS = -L/usr/dt/lib -lDtSvc -ltt -lXm
X11LIBS = -L/usr/lib -lXt -lX11
SYSLIBS =
LIBRARIES = $(DTLIBS) $(X11LIBS) $(SYSLIBS)
LDFLAGS =
.c.o:
${CC} -c $(CFLAGS) $(INCLUDES) $<
all:: $(PROGRAM)
$(PROGRAM):: $(OBJECTS) $(APPDEFAULTS)
${CC} -o $(PROGRAM) $(LDFLAGS) $(OBJECTS) $(LIBRARIES)
clean::
rm -f $(PROGRAM) $(OBJECTS)

View File

@@ -0,0 +1,65 @@
# $XConsortium: Makefile.simple /main/2 1996/05/13 11:45:52 drk $
##########################################################################
#
# Makefile for dtdnddemo
#
# SUN Platform (debug/purify/sentinel support)
#
# (c) Copyright 1993, 1994 Hewlett-Packard Company
# (c) Copyright 1993, 1994 International Business Machines Corp.
# (c) Copyright 1993, 1994 Sun Microsystems, Inc.
# (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of
# Novell, Inc.
##########################################################################
PROGRAM = dtdnddemo
SOURCES = demo.c icon.c text.c file.c buff.c
OBJECTS = demo.o icon.o text.o file.o buff.o
APPDEFAULTS = Dtdnddemo
DEFINES =
CDEBUGFLAGS = -O
CFLAGS = -Xa $(DEFINES) $(CDEBUGFLAGS)
DTHOME = /usr/dt
DTINCLUDE = -I$(DTHOME)/include
X11INCLUDE = -I/usr/openwin/include
INCLUDES = $(DTINCLUDE) $(X11INCLUDE)
DTLIBS = -L$(DTHOME)/lib -lDtSvc -ltt -lXm
X11LIBS = -L/usr/openwin/lib -lXt -lX11
SYSLIBS = -ldl -lw -lgen
LIBRARIES = $(DTLIBS) $(X11LIBS) $(SYSLIBS)
LDFLAGS = -R$(DTHOME)/lib:/usr/openwin/lib
LINKCC = ${CC}
.c.o:
${CC} -c $(CFLAGS) $(INCLUDES) $<
all:: $(PROGRAM)
$(PROGRAM):: $(OBJECTS) $(APPDEFAULTS)
${LINKCC} -o $(PROGRAM) $(LDFLAGS) $(OBJECTS) $(LIBRARIES)
clean::
${RM} $(PROGRAM) $(OBJECTS)
debug: ${PROGRAM}
debug := CDEBUGFLAGS = -g
debug := DEFINES += -DDEBUG
purify: debug
purify := PURIFY = ${PURIFYHOME}/purify
purify := LINKCC = ${PURIFY} ${CC}
sentinel: debug
sentinel := SENTINEL = ${SE_HOME}/sentinel
sentinel := LINKCC = ${SENTINEL} ${CC}
tags: ${SOURCES} ${HEADERS}
ctags -tw ${SOURCES} ${HEADERS}
.KEEP_STATE:

View File

@@ -0,0 +1,45 @@
# $XConsortium: Makefile.sun /main/2 1996/05/13 11:46:10 drk $
##########################################################################
#
# Makefile for dtdnddemo
#
# SUN Platform
#
# (c) Copyright 1993, 1994 Hewlett-Packard Company
# (c) Copyright 1993, 1994 International Business Machines Corp.
# (c) Copyright 1993, 1994 Sun Microsystems, Inc.
# (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of
# Novell, Inc.
##########################################################################
PROGRAM = dtdnddemo
SOURCES = demo.c icon.c text.c file.c buff.c
OBJECTS = demo.o icon.o text.o file.o buff.o
APPDEFAULTS = Dtdnddemo
DEFINES =
CDEBUGFLAGS = -O
CFLAGS = -Xa $(DEFINES) $(CDEBUGFLAGS)
DTINCLUDE = -I/usr/dt/include
X11INCLUDE = -I/usr/openwin/include
INCLUDES = $(DTINCLUDE) $(X11INCLUDE)
DTLIBS = -L/usr/dt/lib -lDtSvc -ltt -lXm
X11LIBS = -L/usr/openwin/lib -lXt -lX11
SYSLIBS = -ldl -lw -lgen
LIBRARIES = $(DTLIBS) $(X11LIBS) $(SYSLIBS)
LDFLAGS = -R/usr/dt/lib:/usr/openwin/lib
.c.o:
${CC} -c $(CFLAGS) $(INCLUDES) $<
all:: $(PROGRAM)
$(PROGRAM):: $(OBJECTS) $(APPDEFAULTS)
${CC} -o $(PROGRAM) $(LDFLAGS) $(OBJECTS) $(LIBRARIES)
clean::
${RM} $(PROGRAM) $(OBJECTS)

View File

@@ -0,0 +1,45 @@
# $XConsortium: Makefile.usl /main/2 1996/05/13 11:46:28 drk $
##########################################################################
#
# Makefile for dtdnddemo
#
# USL Platform
#
# (c) Copyright 1993, 1994 Hewlett-Packard Company
# (c) Copyright 1993, 1994 International Business Machines Corp.
# (c) Copyright 1993, 1994 Sun Microsystems, Inc.
# (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of
# Novell, Inc.
##########################################################################
PROGRAM = dtdnddemo
SOURCES = demo.c icon.c text.c file.c buff.c
OBJECTS = demo.o icon.o text.o file.o buff.o
APPDEFAULTS = Dtdnddemo
DEFINES =
CDEBUGFLAGS = -O
CFLAGS = -Xc $(DEFINES) $(CDEBUGFLAGS)
DTINCLUDE = -I/usr/dt/include
X11INCLUDE = -I/usr/X/include
INCLUDES = $(DTINCLUDE) $(X11INCLUDE)
DTLIBS = -L/usr/dt/lib -lDtSvc -ltt -lXm
X11LIBS = -L/usr/X/lib -lXt -lX11
SYSLIBS = -lw -lgen -lnsl -lresolv -lsocket -lXIM
LIBRARIES = $(DTLIBS) $(X11LIBS) $(SYSLIBS)
LDFLAGS =
.c.o:
${CC} -c $(CFLAGS) $(INCLUDES) $<
all:: $(PROGRAM)
$(PROGRAM):: $(OBJECTS) $(APPDEFAULTS)
${CC} -o $(PROGRAM) $(LDFLAGS) $(OBJECTS) $(LIBRARIES)
clean::
rm -f $(PROGRAM) $(OBJECTS)

View File

@@ -0,0 +1,46 @@
# $XConsortium: Makefile.uxp /main/3 1996/05/13 11:46:45 drk $
##########################################################################
#
# Makefile for dtdnddemo
#
# UXP Platform
#
# (Fujitsu.patch applied)
#
# (c) Copyright 1993, 1994 Hewlett-Packard Company
# (c) Copyright 1993, 1994 International Business Machines Corp.
# (c) Copyright 1993, 1994 Sun Microsystems, Inc.
# (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of
# Novell, Inc.
##########################################################################
PROGRAM = dtdnddemo
SOURCES = demo.c icon.c text.c file.c buff.c
OBJECTS = demo.o icon.o text.o file.o buff.o
APPDEFAULTS = Dtdnddemo
DEFINES =
CDEBUGFLAGS = -O
CFLAGS = -Xc $(DEFINES) $(CDEBUGFLAGS)
DTINCLUDE = -I/usr/dt/include
INCLUDES = $(DTINCLUDE)
DTLIBS = -L/usr/dt/lib -lDtSvc -ltt -lXm
X11LIBS = -lXt -lX11
SYSLIBS = -lw -lgen -lnsl -lresolv -lsocket
LIBRARIES = $(DTLIBS) $(X11LIBS) $(SYSLIBS)
LDFLAGS =
.c.o:
${CC} -c $(CFLAGS) $(INCLUDES) $<
all:: $(PROGRAM)
$(PROGRAM):: $(OBJECTS) $(APPDEFAULTS)
${CC} -o $(PROGRAM) $(LDFLAGS) $(OBJECTS) $(LIBRARIES)
clean::
rm -f $(PROGRAM) $(OBJECTS)

17
cde/examples/dtdnd/README Normal file
View File

@@ -0,0 +1,17 @@
/* $XConsortium: README /main/2 1996/07/15 14:00:00 drk $ */
This directory contains demonstrations of the Dnd Drag and Drop API
dtdnddemo - The Drag-n-Drop Demo program demonstrates the
Dt DnD functions in the Desktop Services library:
DtDndDragStart.3x
DtDndDropRegister.3x
The demo consists of a row of three different
sources for text, filename and app-named data drags.
It also has a type-in field that can accept either
text or filename drops. Finally there is a data
area that accepts filename or data drops.

633
cde/examples/dtdnd/buff.c Normal file
View File

@@ -0,0 +1,633 @@
/* $TOG: buff.c /main/5 1999/07/20 14:48:23 mgreess $ */
/*****************************************************************************
*****************************************************************************
**
** File: buff.c
**
** Description: Buffer transfer functions for the CDE Drag & Drop Demo.
**
** (c) Copyright 1993, 1994 Hewlett-Packard Company
** (c) Copyright 1993, 1994 International Business Machines Corp.
** (c) Copyright 1993, 1994 Sun Microsystems, Inc.
** (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of
** Novell, Inc.
**
****************************************************************************
************************************<+>*************************************/
#include <time.h>
#include <X11/Intrinsic.h>
#include <Xm/Xm.h>
#include <Xm/List.h>
#include <Dt/Dt.h>
#include <Dt/Dnd.h>
#include "icon.h"
#include "file.h"
#include "demo.h"
#include "buff.h"
extern Widget topLevel;
/*************************************************************************
*
* Data Structures & Private Declarations For Appointment Buffers
*
**************************************************************************/
/*
* Appointment structure used to store appointments internally.
*/
typedef struct _Appointment {
char *date;
char *start;
char *end;
char *what;
} Appointment;
/*
* List of appointments which always appear to be for the current date.
*/
char today[9]; /* initialized in apptCreateList() */
Appointment todaysApptList[] = {
#ifdef TEST_APPT_NAMES
{ today, "", "", "Staff Meeting" }, /* no name */
{ today, " 9:30am", "10:00am", "Will's Party1" }, /* duplicate names */
{ today, " 9:30am", "10:00am", "Will's Party2" },
#else
{ today, " 9:00am", " 9:30am", "Staff Meeting" },
{ today, " 9:30am", "10:00am", "Will's Party" },
#endif
{ today, "10:00am", "10:30am", "Conference Call" },
{ today, "10:30am", "11:30am", "Work on Mail" },
{ today, "11:00am", "11:30pm", "B'fast w/ Robert" },
{ today, " 1:30pm", " 2:30pm", "Design Meeting" },
{ today, " 3:00pm", " 4:00pm", "Communications" },
{ today, " 4:00pm", " 4:30pm", "Pick up Dogs" },
{ today, " 5:00pm", " 6:30pm", "Beer Bust" },
{ today, " 7:00pm", " 9:00pm", "Dinner - Stuart" },
{ NULL, NULL, NULL, NULL }
};
/*
* CDE appointment format used to transfer the appointments via drag & drop.
*/
char *apptFormat =
" ** Calendar Appointment **\n\
\n\
Date: %s\n\
Start: %s\n\
End: %s\n\
What: %s\n";
/*
* Private Appointment Buffer Function Declarations
*/
static void apptConvertCallback(Widget, XtPointer, XtPointer);
static int apptCreateList(XmString**);
static void apptDestroyList(XmString*,int);
static Appointment* apptFromListEntry(XmString);
static char* apptGetLabel(char*);
/*************************************************************************
*
* Appointment Drag & Drop
*
**************************************************************************/
/*
* apptConvertCallback
*
* Fills in buffer structure with calendar appointment string based on which
* appointments are selected in the scrolled list when the drag is started.
* ihen no appointments are selected, the appointment under the pointer is
* used. Supply a label for the calendar appointment based on the contents
* of the appointment.
*/
static void
apptConvertCallback(
Widget dragContext,
XtPointer clientData,
XtPointer callData)
{
DtDndConvertCallbackStruct *convertInfo =
(DtDndConvertCallbackStruct *) callData;
DtDndBuffer *buffers = convertInfo->dragData->data.buffers;
Widget apptList = (Widget)clientData;
int selectedPos, ii,
selectedItemCount;
XmStringTable selectedItems;
char apptString[1024];
String labelString;
Appointment *appt;
if (convertInfo == NULL) {
return;
}
/*
* Verify the validity of the callback reason
*/
if (convertInfo->dragData->protocol != DtDND_BUFFER_TRANSFER ||
(convertInfo->reason != DtCR_DND_CONVERT_DATA &&
convertInfo->reason != DtCR_DND_CONVERT_DELETE)) {
return;
}
/*
* Get selected items from the list
*/
XtVaGetValues(apptList,
XmNuserData, &selectedPos,
XmNselectedItemCount, &selectedItemCount,
XmNselectedItems, &selectedItems,
NULL);
for (ii = 0; ii < convertInfo->dragData->numItems; ii++) {
/*
* Get the actual appointment(s)
*/
if (selectedItemCount == 0) {
appt = &todaysApptList[selectedPos-1+ii];
} else {
appt = apptFromListEntry(selectedItems[ii]);
}
sprintf(apptString, apptFormat,
appt->date, appt->start, appt->end, appt->what);
/*
* Supply the appointment(s) for transfer
*/
if (convertInfo->reason == DtCR_DND_CONVERT_DATA) {
/* Copy the appointment into the buffer for transfer */
buffers[ii].bp = XtNewString(apptString);
buffers[ii].size = strlen(buffers[ii].bp);
/* Supply the name for the appointment */
labelString = apptGetLabel(apptString);
if (labelString == NULL) {
buffers[ii].name = (char *)NULL;
} else {
buffers[ii].name = XtNewString(labelString);
XtFree(labelString);
}
/*
* Delete the moved appointment(s)
*/
} else if (convertInfo->reason == DtCR_DND_CONVERT_DELETE) {
printf("Delete appointment for %s\n", appt->what);
}
}
}
/*
* apptDragFinishCallback
*
* Free buffer data/names allocated in apptConvertCallback()
*/
void
apptDragFinishCallback(
Widget widget,
XtPointer clientData,
XtPointer callData)
{
DtDndDragFinishCallbackStruct *dropFinishInfo =
(DtDndDragFinishCallbackStruct *)callData;
DtDndContext *dragData = dropFinishInfo->dragData;
int ii;
for (ii = 0; ii < dragData->numItems; ii++) {
XtFree(dragData->data.buffers[ii].bp);
if (dragData->data.buffers[ii].name != NULL)
XtFree(dragData->data.buffers[ii].name);
}
}
/*
* apptTransferCallback
*
* Handles the transfer of an appointment to the draw area drop site.
* Adds the appropriate icon to the list of icons on the draw area.
*/
void
apptTransferCallback(
Widget widget,
XtPointer clientData,
XtPointer callData)
{
DtDndTransferCallbackStruct *transferInfo =
(DtDndTransferCallbackStruct*) callData;
DtDndBuffer *buffers;
IconInfo *iconList, *iconPtr;
char *name;
char *filename;
int ii;
if (transferInfo == NULL) {
return;
}
/*
* Verify the validity of the callback reason.
*/
if (transferInfo->dropData->protocol != DtDND_BUFFER_TRANSFER ||
transferInfo->reason != DtCR_DND_TRANSFER_DATA) {
return;
}
/*
* Use abbreviated method of refering to the data buffers.
*/
if (transferInfo != NULL && transferInfo->dropData != NULL) {
buffers = transferInfo->dropData->data.buffers;
} else {
return;
}
/*
* Process each item being transfered.
*/
XtVaGetValues(widget, XmNuserData, &iconList, NULL);
for (ii = 0; ii < transferInfo->dropData->numItems; ii++) {
/*
* Check format of buffer
*/
/*
* Transfer the buffer data. Here there is no actual transfer
* taking place. Only the icons representing the appointments
* are created to indicate the transfer.
*/
name = buffers[ii].name;
if (name == NULL)
name = "unnamed";
/* Create file from buffer */
filename = fileStoreBuffer(buffers[ii].name,
buffers[ii].bp, buffers[ii].size);
printf("Stored buffer into '%s'\n", filename);
XtFree(filename);
/* Create icon */
iconPtr = IconNew();
IconInitialize(widget, iconPtr,
transferInfo->x + ii * 10,
transferInfo->y + ii * 10,
buffers[ii].bp, buffers[ii].size, name, IconByData);
/* Add to icon list on drop site */
iconPtr->next = iconList;
if (iconList != NULL) {
iconList->prev = iconPtr;
}
iconList = iconPtr;
XtVaSetValues(widget, XmNuserData, iconList, NULL);
}
}
/*
* apptDragSetup
*
* Prepares the appointment list to source drags of appointments with button 1.
*/
void apptDragSetup(Widget apptDragSource)
{
static char translations[] = "\
~c ~s ~m ~a <Btn1Down>:\
demoProcessPress(ListBeginSelect,apptDragStart)\n\
c ~s ~m ~a <Btn1Down>:\
demoProcessPress(ListBeginToggle,apptDragStart)";
static char btn2_translations[] = "\
~c ~s ~m ~a <Btn2Down>:\
demoProcessPress(ListBeginSelect,apptDragStart)\n\
c ~s ~m ~a <Btn2Down>:\
demoProcessPress(ListBeginToggle,apptDragStart)\n\
<Btn2Motion>:ListButtonMotion()\n\
~c ~s ~m ~a <Btn2Up>:ListEndSelect()\n\
c ~s ~m ~a <Btn2Up>:ListEndToggle()";
static XtActionsRec actionTable[] =
{
{"apptDragStart", (XtActionProc) &apptDragStart},
{"demoProcessPress", (XtActionProc) &demoProcessPress}
};
int btn1_transfer = 0;
XtTranslations new_translations;
XtAppAddActions(
demoAppContext,
actionTable,
sizeof(actionTable)/sizeof(actionTable[0]));
new_translations = XtParseTranslationTable(translations);
XtOverrideTranslations(apptDragSource, new_translations);
XtVaGetValues(
(Widget) XmGetXmDisplay(XtDisplayOfObject(apptDragSource)),
"enableBtn1Transfer", &btn1_transfer,
NULL);
if (btn1_transfer != True)
{
new_translations = XtParseTranslationTable(btn2_translations);
XtOverrideTranslations(apptDragSource, new_translations);
}
#if 0
XtAddEventHandler(apptDragSource, Button1MotionMask, False,
(XtEventHandler)demoDragMotionHandler,
(XtPointer)DtDND_BUFFER_TRANSFER);
#endif
}
/*
* apptDropSetup
*
* Such a function is not needed since the demoDropSetup in demo.c registers
* the draw area as a drop site for drops of buffers such as appointments.
*/
/*
* apptDragStart
*
* Initiates a drag of an appointment from the appointment list provided
* the pointer is over an appointment in the list.
*/
void
apptDragStart(
Widget widget,
XEvent *event)
{
static XtCallbackRec convertCBRec[] = { {apptConvertCallback, NULL},
{NULL, NULL} };
static XtCallbackRec dragFinishCBRec[] =
{ {demoDragFinishCallback, NULL},
{apptDragFinishCallback, NULL},
{NULL, NULL} };
static IconInfo *iconPtr = NULL;
Widget dragIcon;
Display *display = XtDisplay(widget);
int itemCount,
selectedPos,
selectedItemCount;
char apptString[1024];
convertCBRec[0].closure = (XtPointer)widget;
/*
* Get list of selected items from the scrolled list of appointments
*/
XtVaGetValues(widget,
XmNitemCount, &itemCount,
XmNselectedItemCount, &selectedItemCount,
NULL);
/*
* Find out which item the pointer was over when the drag began
*/
selectedPos = XmListYToPos(widget, event->xmotion.y);
if (selectedPos == 0 || selectedPos > itemCount) {
return;
}
XtVaSetValues(widget, XmNuserData, selectedPos, NULL);
/*
* Copy the appointment information into an appointment string
*/
sprintf(apptString, apptFormat,
todaysApptList[1].date, todaysApptList[1].start,
todaysApptList[1].end, todaysApptList[1].what);
/*
* Create drag icon for appointment buffer drag
*/
if (iconPtr == NULL) {
iconPtr = IconNew();
IconInitialize(widget, iconPtr, 0, 0,
apptString, strlen(apptString), NULL, IconByData);
}
if (iconPtr->dragIcon == NULL) {
iconPtr->dragIcon = DtDndCreateSourceIcon(widget,
iconPtr->bitmap, iconPtr->mask);
}
if (selectedItemCount > 1) {
dragIcon = NULL;
itemCount = selectedItemCount;
} else {
dragIcon = iconPtr->dragIcon;
itemCount = 1;
}
/*
* Start the drag
*/
if (DtDndVaDragStart(widget, event, DtDND_BUFFER_TRANSFER, itemCount,
XmDROP_COPY,
convertCBRec, dragFinishCBRec,
DtNsourceIcon, dragIcon,
DtNbufferIsText, True,
NULL)
== NULL) {
printf("DragStart returned NULL.\n");
}
}
/*************************************************************************
*
* Appointment Creation, Initialization & Destruction
*
*************************************************************************/
/*
* apptCreateDragSource
*
* Create a scrolling list filled with appointments.
*/
Widget
apptCreateDragSource(
Widget parent)
{
Widget apptList;
XmString *apptListItems;
int apptCount;
apptCount = apptCreateList(&apptListItems);
apptList = XtVaCreateManagedWidget("apptList",
xmListWidgetClass, parent,
/*
* Uncomment the line specifying the selection policy to
* enable multiple buffer transfers from the scrolled list
* of appointments. WARNING: There is a bug in the interaction
* of the scrolled list and Drag and Drop which causes items
* in the scrolled list which are selected to appear unselected
* and vice versa.
*/
/* XmNselectionPolicy, XmMULTIPLE_SELECT, */
XmNitems, apptListItems,
XmNitemCount, apptCount,
NULL);
apptDestroyList(apptListItems, apptCount);
return apptList;
}
/*
* apptCreateDropSite
*
* Such a function is not needed since the drop site is the draw area which
* is created in demoCreateDropSite() in demo.c
*/
/*
* apptCreateList
*
* Creates a list of XmStrings with appointment data in them.
*/
static int
apptCreateList(
XmString **appts)
{
int ii, apptCount;
char tmpStr[256];
time_t now;
struct tm *tm;
now = time(&now);
tm = localtime(&now);
sprintf(today, "%2d/%2d/%2d", tm->tm_mon+1, tm->tm_mday, tm->tm_year);
for (ii = 0; todaysApptList[ii].date; ii++);
apptCount = ii;
*appts = (XmString *) XtMalloc(sizeof(XmString) * apptCount);
for (ii = 0; todaysApptList[ii].date; ii++) {
sprintf(tmpStr, "%s %s", todaysApptList[ii].start,
todaysApptList[ii].what);
(*appts)[ii] = XmStringCreate(tmpStr, XmFONTLIST_DEFAULT_TAG);
}
return apptCount;
}
/*
* apptDestroyList
*
* Destroys a list of XmStrings with appointment data in them.
*/
static void
apptDestroyList(
XmString *appts,
int apptCount)
{
int ii;
for (ii = 0; ii < apptCount; ii++) {
XmStringFree(appts[ii]);
}
XtFree((char *)appts);
}
/*************************************************************************
*
* Appointment Utility Functions
*
*************************************************************************/
/*
* apptFromListEntry
*
* Returns the full appointment based on the text of the appointment as
* given in the text entry from the scrolled list of appointments.
*/
static Appointment*
apptFromListEntry(
XmString listEntry)
{
int ii;
char *entryText,
*string;
/*
* Get text string from XmString for use in comparisons
*/
entryText = XmStringUnparse(listEntry, NULL, XmCHARSET_TEXT,
XmCHARSET_TEXT, NULL, 0, XmOUTPUT_ALL);
for (ii = 0; todaysApptList[ii].what != NULL; ii++) {
string = strstr(entryText, todaysApptList[ii].what);
if (string != NULL) {
XtFree(entryText);
return(&todaysApptList[ii]);
}
}
XtFree(entryText);
return NULL;
}
/*
* apptGetLabel
*
* Creates a label for an appointment icon given an appointment.
*/
static char*
apptGetLabel(
char *appt)
{
char start[128];
int count;
if (appt == NULL) {
return NULL;
}
appt = strstr(appt, "Start:");
count = sscanf(appt, "Start:%*[ \t]%[^\n]", start);
if (count != 1) {
return NULL;
}
return XtNewString(start);
}

26
cde/examples/dtdnd/buff.h Normal file
View File

@@ -0,0 +1,26 @@
/* $XConsortium: buff.h /main/3 1995/10/27 10:38:22 rswiston $ */
/*****************************************************************************
*****************************************************************************
**
** File: buff.h
**
** Description: Header for buffer transfer portion of CDE Drag & Drop Demo.
**
** (c) Copyright 1993, 1994 Hewlett-Packard Company
** (c) Copyright 1993, 1994 International Business Machines Corp.
** (c) Copyright 1993, 1994 Sun Microsystems, Inc.
** (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of
** Novell, Inc.
**
****************************************************************************
************************************<+>*************************************/
/*
* Public Appointment Buffer Transfer Function Declarations
*/
Widget apptCreateDragSource(Widget);
void apptDragSetup(Widget);
void apptDragStart(Widget, XEvent*);
void apptTransferCallback(Widget, XtPointer, XtPointer);

577
cde/examples/dtdnd/demo.c Normal file
View File

@@ -0,0 +1,577 @@
/* $TOG: demo.c /main/5 1999/07/20 14:48:53 mgreess $ */
/*****************************************************************************
*****************************************************************************
**
** File: demo.c
**
** Description: The Drag & Drop Demo program demonstrates the
** CDE DnD functions in the Desktop Services library:
**
** DtDndDragStart.3x
** DtDndDropRegister.3x
** DtDndCreateSourceIcon.3x
**
** The demo consists of a row of three different sources
** for text, filename and appointment buffer drags.
** It also has a text field that can accept either
** text or filename drops. Finally there is a data
** area that accepts filename or buffer drops.
**
** (c) Copyright 1993, 1994 Hewlett-Packard Company
** (c) Copyright 1993, 1994 International Business Machines Corp.
** (c) Copyright 1993, 1994 Sun Microsystems, Inc.
** (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of
** Novell, Inc.
**
****************************************************************************
************************************<+>*************************************/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include <X11/Intrinsic.h>
#include <Xm/Xm.h>
#include <Xm/DrawingA.h>
#include <Xm/Frame.h>
#include <Xm/List.h>
#include <Xm/MainW.h>
#include <Xm/MwmUtil.h>
#include <Xm/RowColumn.h>
#include <Xm/Separator.h>
#include <Xm/DragDrop.h>
#include <Xm/Screen.h>
#include <Dt/Dt.h>
#include <Dt/Dnd.h>
#include "icon.h"
#include "text.h"
#include "file.h"
#include "buff.h"
/*************************************************************************
*
* Data Structures & Declarations For Drag & Drop Demo
*
*************************************************************************/
/*
* The Drag Threshold is the distance, measured in pixels, over which the
* pointer must travel while the BSelect button (first mouse button) is held
* down in order to start a drag. CDE defines this to be 10 pixels.
*/
#define DRAG_THRESHOLD 10
/*
* Absolute value macro
*/
#ifndef ABS
#define ABS(x) (((x) > 0) ? (x) : (-(x)))
#endif
/*
* Global variables
*/
Widget demoTopLevel;
XtAppContext demoAppContext;
Boolean demoDoingDrag = False;
/*
* Private Drag & Drop Demo Function Declarations
*/
void demoTransferCallback(Widget, XtPointer, XtPointer);
/*************************************************************************
*
* General-Purpose Drag & Drop Functions
*
*************************************************************************/
/*
* demoDragFinishCallback
*
* Resets drag state to indicate the drag is over.
*/
void
demoDragFinishCallback(
Widget widget,
XtPointer clientData,
XtPointer callData)
{
demoDoingDrag = False;
}
/*
* demoDragMotionHandler
*
* Determine if the pointer has moved beyond the drag threshold while button 1
* was being held down.
*/
void
demoDragMotionHandler(
Widget dragInitiator,
XtPointer clientData,
XEvent *event)
{
static int initialX = -1;
static int initialY = -1;
int diffX, diffY;
long dragProtocol = (long)clientData;
if (!demoDoingDrag) {
/*
* If the drag is just starting, set initial button down coords
*/
if (initialX == -1 && initialY == -1) {
initialX = event->xmotion.x;
initialY = event->xmotion.y;
}
/*
* Find out how far pointer has moved since button press
*/
diffX = initialX - event->xmotion.x;
diffY = initialY - event->xmotion.y;
if ((ABS(diffX) >= DRAG_THRESHOLD) ||
(ABS(diffY) >= DRAG_THRESHOLD)) {
demoDoingDrag = True;
switch (dragProtocol) {
case DtDND_TEXT_TRANSFER:
textDragStart(dragInitiator, event);
break;
case DtDND_FILENAME_TRANSFER:
fileCheckForDrag(dragInitiator, event,
initialX, initialY);
break;
case DtDND_BUFFER_TRANSFER:
apptDragStart(dragInitiator, event);
break;
}
initialX = -1;
initialY = -1;
}
}
}
/*
* demoLookForButton
*/
/* ARGSUSED */
static Bool demoLookForButton(Display *d, XEvent *event, XPointer arg)
{
#define DAMPING 5
#define ABS_DELTA(x1, x2) (x1 < x2 ? x2 - x1 : x1 - x2)
if( event->type == MotionNotify)
{
XEvent * press = (XEvent *) arg;
if (ABS_DELTA(press->xbutton.x_root, event->xmotion.x_root) > DAMPING ||
ABS_DELTA(press->xbutton.y_root, event->xmotion.y_root) > DAMPING)
return(True);
}
else if (event->type == ButtonRelease) return(True);
return(False);
}
/*
* demoProcessPress
*/
void demoProcessPress(Widget w, XEvent *event, String *parms, Cardinal *nparms)
{
#define SELECTION_ACTION 0
#define TRANSFER_ACTION 1
int i, action, cur_item;
int *selected_positions, nselected_positions;
/*
* This action happens when Button1 is pressed and the Selection
* and Transfer are integrated on Button1. It is passed two
* parameters: the action to call when the event is a selection,
* and the action to call when the event is a transfer.
*/
if (*nparms != 2 || !XmIsList(w)) return;
action = SELECTION_ACTION;
cur_item = XmListYToPos(w, event->xbutton.y);
if (cur_item > 0)
{
XtVaGetValues(w,
XmNselectedPositions, &selected_positions,
XmNselectedPositionCount, &nselected_positions,
NULL);
for (i=0; i<nselected_positions; i++)
{
if (cur_item == selected_positions[i])
{
/*
* The determination of whether this is a transfer drag
* cannot be made until a Motion event comes in. It is
* not a drag as soon as a ButtonUp event happens.
*/
XEvent new_event;
XPeekIfEvent(
XtDisplay(w),
&new_event,
&demoLookForButton,
(XPointer) event);
switch (new_event.type)
{
case MotionNotify:
action = TRANSFER_ACTION;
break;
case ButtonRelease:
action = SELECTION_ACTION;
break;
}
break;
}
}
}
XtCallActionProc(w, parms[action], event, parms, *nparms);
}
/*
* demoDrawAnimateCallback
*
* Expands the icon melted into the draw area by Motif.
*/
void
demoDrawAnimateCallback(
Widget dragContext, /* WARNING: This is being destroyed. */
XtPointer clientData,
XtPointer callData)
{
DtDndDropAnimateCallbackStruct *animateInfo =
(DtDndDropAnimateCallbackStruct *) callData;
Widget dropDraw = (Widget)clientData;
Display *display = XtDisplayOfObject(dropDraw);
Screen *screen = XtScreen(dropDraw);
Window window = XtWindow(dropDraw);
int expandWidth, expandHeight,
sourceX, sourceY;
static GC graphicsContext = NULL;
XGCValues gcValues;
IconInfo *iconPtr;
/*
* Create graphics context if it doesn't yet exist
*/
if (graphicsContext == NULL) {
gcValues.foreground = BlackPixelOfScreen(screen);
gcValues.background = WhitePixelOfScreen(screen);
graphicsContext = XCreateGC(display, window,
GCForeground | GCBackground, &gcValues);
}
/*
* Get the dragged icon from the dropDraw area
*/
XtVaGetValues(dropDraw, XmNuserData, &iconPtr, NULL);
if (iconPtr == NULL) {
return;
}
/*
* Set clip mask and coordinates for this icon in the graphics context
*/
gcValues.clip_mask = iconPtr->mask;
gcValues.clip_x_origin = iconPtr->icon.x;
gcValues.clip_y_origin = iconPtr->icon.y;
XChangeGC(display, graphicsContext,
GCClipMask | GCClipXOrigin | GCClipYOrigin,
&gcValues);
/*
* Reconstitute the icon after Motif melts it
*/
for (expandWidth = expandHeight = 0;
expandWidth < (int)iconPtr->icon.width &&
expandHeight < (int)iconPtr->icon.height;
expandWidth += 2, expandHeight += 2) {
sourceX = ((int)iconPtr->icon.width - expandWidth)/2;
sourceY = ((int)iconPtr->icon.height - expandHeight)/2;
XCopyPlane(display, iconPtr->bitmap, window, graphicsContext,
sourceX, sourceY, expandWidth, expandHeight,
iconPtr->icon.x + sourceX, iconPtr->icon.y + sourceY,
1L);
XmeMicroSleep(25000L);
XFlush(display);
}
}
/*
* demoDrawExposeCallback
*
* Draws all the icons associated with the drawing area.
*/
void
demoDrawExposeCallback(
Widget widget,
XtPointer clientData,
XtPointer callData)
{
IconInfo *iconPtr;
XtVaGetValues(widget, XmNuserData, &iconPtr, NULL);
while (iconPtr != NULL) {
IconDraw(widget, iconPtr);
iconPtr = iconPtr->next;
}
}
/*
* demoDropSetup
*
* Registers draw area to accept drops of files or buffers such as appointments.
*/
void
demoDropSetup(
Widget dropDraw)
{
static XtCallbackRec transferCBRec[] = { {demoTransferCallback, NULL},
{NULL, NULL} };
static XtCallbackRec animateCBRec[] = { {demoDrawAnimateCallback, NULL},
{NULL, NULL} };
animateCBRec[0].closure = (XtPointer)dropDraw;
DtDndVaDropRegister(dropDraw,
DtDND_FILENAME_TRANSFER | DtDND_BUFFER_TRANSFER,
XmDROP_COPY | XmDROP_MOVE, transferCBRec,
DtNdropAnimateCallback, animateCBRec,
DtNtextIsBuffer, True,
DtNpreserveRegistration, False,
NULL);
}
/*
* demoTransferCallback
*
* Called when something is dropped on the drawing area drop site. If the
* transfer protocol is DtDND_FILENAME_TRANSFER or DtDND_BUFFER_TRANSFER
* the fileTransferCallback and apptTransferCallback are called respectively.
*/
void
demoTransferCallback(
Widget widget,
XtPointer clientData,
XtPointer callData)
{
DtDndTransferCallbackStruct *transferInfo =
(DtDndTransferCallbackStruct *) callData;
if (transferInfo == NULL) {
return;
}
switch (transferInfo->dropData->protocol) {
case DtDND_FILENAME_TRANSFER:
fileTransferCallback(widget, clientData, callData);
break;
case DtDND_BUFFER_TRANSFER:
apptTransferCallback(widget, clientData, callData);
break;
}
}
/*************************************************************************
*
* Demo Client Creation
*
*************************************************************************/
/*
* Fallback resources are used if app-defaults file is not found
*/
String fallbackResources[] = {
"title: CDE Drag & Drop Demo",
"*outerRowColumn.orientation: VERTICAL",
"*outerRowColumn.spacing: 15",
"*outerRowColumn.marginHeight: 15",
"*outerRowColumn.marginWidth: 15",
"*upperRowColumn.orientation: HORIZONTAL",
"*upperRowColumn.packing: PACK_COLUMN",
"*upperRowColumn.spacing: 15",
"*upperRowColumn.marginHeight: 0",
"*upperRowColumn.marginWidth: 0",
"*fileDraw.height: 175",
"*fileDraw.resizePolicy: RESIZE_NONE",
"*fruitList.listSizePolicy: CONSTANT",
"*fruitList.scrollBarDisplayPolicy: STATIC",
"*fruitList.selectionPolicy: MULTIPLE_SELECT",
"*apptList.listSizePolicy: CONSTANT",
"*apptList.scrollBarDisplayPolicy: STATIC",
"*apptList.selectionPolicy: MULTIPLE_SELECT",
"*textRowColumn.orientation: HORIZONTAL",
"*textRowColumn.packing: PACK_TIGHT",
"*textRowColumn*textLabel.labelString: Name:",
"*textRowColumn*textField.width: 550",
"*textRowColumn.marginWidth: 0",
"*dropDraw.height: 100",
"*dropDraw.resizePolicy: RESIZE_NONE",
NULL
};
/*
* demoCreateDropSite
*
* Creates the drawing area at the bottom of the demo which is used as a drop
* site for files and appointments.
*/
Widget
demoCreateDropSite(
Widget parent)
{
Widget dropFrame,
dropDraw;
dropFrame = XtVaCreateManagedWidget("dropFrame",
xmFrameWidgetClass, parent,
NULL);
dropDraw = XtVaCreateManagedWidget("dropDraw",
xmDrawingAreaWidgetClass, dropFrame,
NULL);
XtAddCallback(dropDraw,
XmNexposeCallback, demoDrawExposeCallback,
NULL);
return dropDraw;
}
/*
* main
*
* Create widgets for the demo program. Call protocol-specific functions
* to initialize the drag sources and drop sites.
*/
void
main(
int argc,
String *argv)
{
Widget outerRowColumn,
upperRowColumn,
textDragSource,
fileDragSource,
apptDragSource,
separator,
textDropSite,
drawDropSite;
/*
* Create basic widgets and layout widgets
*/
XtSetLanguageProc(NULL, NULL, NULL);
demoTopLevel = XtAppInitialize(&demoAppContext, "Dtdnddemo",
(XrmOptionDescList)NULL, 0, &argc, argv,
fallbackResources, (ArgList)NULL, 0);
DtAppInitialize(demoAppContext, XtDisplay(demoTopLevel),
demoTopLevel, argv[0], "Dtdnddemo");
outerRowColumn = XtVaCreateManagedWidget("outerRowColumn",
xmRowColumnWidgetClass, demoTopLevel,
NULL);
upperRowColumn = XtVaCreateManagedWidget("upperRowColumn",
xmRowColumnWidgetClass, outerRowColumn,
NULL);
/*
* Create the drag sources
*/
textDragSource = textCreateDragSource(upperRowColumn);
fileDragSource = fileCreateDragSource(upperRowColumn);
apptDragSource = apptCreateDragSource(upperRowColumn);
/*
* Create a line separating the drag sources from the drop sites
*/
separator = XtVaCreateManagedWidget("separator",
xmSeparatorWidgetClass, outerRowColumn,
NULL);
/*
* Create the drop sites
*/
textDropSite = textCreateDropSite(outerRowColumn);
drawDropSite = demoCreateDropSite(outerRowColumn);
/*
* Realize the widget tree
*/
XtRealizeWidget(demoTopLevel);
/*
* Load the data typing database which is used to get icons
*/
DtDtsLoadDataTypes();
/*
* Set up the drag sources
*/
textDragSetup(textDragSource);
fileDragSetup(fileDragSource);
apptDragSetup(apptDragSource);
/*
* Set up the drop sites
*/
textDropSetup(textDropSite);
demoDropSetup(drawDropSite);
/*
* Start the event processing loop
*/
XtAppMainLoop(demoAppContext);
}

28
cde/examples/dtdnd/demo.h Normal file
View File

@@ -0,0 +1,28 @@
/* $TOG: demo.h /main/4 1999/07/20 14:49:21 mgreess $ */
/*****************************************************************************
*****************************************************************************
**
** File: demo.h
**
** Description: Header for foundation of CDE Drag & Drop Demo.
**
** (c) Copyright 1993, 1994 Hewlett-Packard Company
** (c) Copyright 1993, 1994 International Business Machines Corp.
** (c) Copyright 1993, 1994 Sun Microsystems, Inc.
** (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of
** Novell, Inc.
**
****************************************************************************
************************************<+>*************************************/
/*
* Public General-Purpose Demo Function Declarations
*/
extern void demoDragFinishCallback(Widget, XtPointer, XtPointer);
extern void demoDragMotionHandler(Widget, XtPointer, XtPointer, XEvent*);
extern void demoProcessPress(Widget, XEvent*, String*, Cardinal*);
extern void demoDrawExposeCallback(Widget, XtPointer, XtPointer);
extern XtAppContext demoAppContext;
extern Widget demoTopLevel;

759
cde/examples/dtdnd/file.c Normal file
View File

@@ -0,0 +1,759 @@
/* $TOG: file.c /main/4 1999/07/20 14:49:49 mgreess $ */
/*****************************************************************************
*****************************************************************************
**
** File: file.c
**
** Description: File transfer functions for the CDE Drag & Drop Demo.
**
** (c) Copyright 1993, 1994 Hewlett-Packard Company
** (c) Copyright 1993, 1994 International Business Machines Corp.
** (c) Copyright 1993, 1994 Sun Microsystems, Inc.
** (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of
** Novell, Inc.
**
****************************************************************************
************************************<+>*************************************/
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <X11/Intrinsic.h>
#include <Xm/Xm.h>
#include <Xm/DrawingA.h>
#include <Xm/Frame.h>
#include <Xm/Protocols.h>
#include <Dt/Dt.h>
#include <Dt/Dnd.h>
#include "icon.h"
#include "demo.h"
#include "file.h"
/*************************************************************************
*
* Data Structures & Private Declarations For Appointment Buffers
*
**************************************************************************/
/*
* Specification of drag or drop directory
*/
typedef enum {
DragDirectory,
DropDirectory
} DragOrDrop;
/*
* File names and contents. The contents are the minimal required by the
* data typing service to correctly type the file via content-based typing.
* The file names are appropriate to the type of the contents as well. This
* demo uses content-based typing to get the appropriate icons for these files.
*/
#define FILE_NAME_CSH "runit"
#define FILE_DATA_CSH "#! /bin/csh"
#define FILE_NAME_PS "map.ps"
#define FILE_DATA_PS "%!PS-Adobe-2.0"
#define FILE_NAME_TEXT "tasks"
#define FILE_DATA_TEXT "Nothing"
/*
* Private file function declarations
*/
static XtActionProc fileCheckForDragProc(Widget, XEvent*, String*,
Cardinal*);
static void fileConvertCallback(Widget, XtPointer, XtPointer);
static void fileCreateDirectory(char*);
static void fileCreateFile(char*, char*, char*);
static void fileCreateFiles(Widget);
static void fileDragStart(Widget, XEvent*, IconInfo*, int);
static char* fileGetContents(char*);
static char* fileGetDemoDirectory();
static char* fileGetDirectoryName(DragOrDrop);
static void fileRemoveDirectory(char*);
static void fileShutdown(Widget, XtPointer, XtPointer);
/*************************************************************************
*
* File Name Drag & Drop
*
**************************************************************************/
/*
* fileConvertCallback
*
* When converting the data, fills in the file structure with the name(s) of
* the file(s). When converting DELETE, removes the given file(s) and icon(s)
* from the filesystem and drawing area respectively.
*/
static void
fileConvertCallback(
Widget dragContext,
XtPointer clientData,
XtPointer callData)
{
DtDndConvertCallbackStruct *convertInfo =
(DtDndConvertCallbackStruct *) callData;
IconInfo *iconArray = (IconInfo *) clientData;
char filePath[MAXPATHLEN + 1],
command[MAXPATHLEN + 4];
int ii;
Widget fileDraw;
if (convertInfo == NULL) {
return;
}
/*
* Verify the protocol and callback reason
*/
if (convertInfo->dragData->protocol != DtDND_FILENAME_TRANSFER ||
(convertInfo->reason != DtCR_DND_CONVERT_DATA &&
convertInfo->reason != DtCR_DND_CONVERT_DELETE)) {
return;
}
switch (convertInfo->reason) {
case DtCR_DND_CONVERT_DATA:
/*
* Supply the file names of the dragged files
*/
for (ii = 0; ii < convertInfo->dragData->numItems; ii++) {
sprintf(filePath, "%s/%s",
fileGetDirectoryName(DragDirectory),
iconArray[ii].name);
convertInfo->dragData->data.files[ii] =
XtNewString(filePath);
}
break;
case DtCR_DND_CONVERT_DELETE:
/*
* Delete dragged files as second part of a move operation
*/
fileDraw = XtNameToWidget(demoTopLevel, "*fileDraw");
for (ii = 0; ii < convertInfo->dragData->numItems; ii++) {
/* Remove file(s) */
sprintf(filePath, "%s/%s",
fileGetDirectoryName(DragDirectory),
iconArray[ii].name);
sprintf(command, "rm %s", filePath);
if (system(command) != 0) {
printf("Unable to remove file \"%s\".\n",
filePath);
}
/* Remove icon(s) */
if (fileDraw != NULL) {
IconDelete(fileDraw, &iconArray[ii]);
XClearWindow(XtDisplayOfObject(fileDraw),
(XtWindow(fileDraw)));
XtCallCallbacks(fileDraw, XmNexposeCallback,
NULL);
}
}
break;
}
}
/*
* fileDragFinishCallback
*
* Free the file names allocated in fileConvertCallback()
*/
void
fileDragFinishCallback(
Widget widget,
XtPointer clientData,
XtPointer callData)
{
DtDndDragFinishCallbackStruct *dragFinishInfo =
(DtDndDragFinishCallbackStruct *)callData;
DtDndContext *dragData = dragFinishInfo->dragData;
int ii;
for (ii = 0; ii < dragData->numItems; ii++) {
XtFree(dragData->data.files[ii]);
}
}
/*
* fileTransferCallback
*
* Handles the transfer of a file or appointment to the draw area.
* Adds the appropriate icon to the list of icons on the draw area.
*/
void
fileTransferCallback(
Widget widget,
XtPointer clientData,
XtPointer callData)
{
DtDndTransferCallbackStruct *transferInfo =
(DtDndTransferCallbackStruct *) callData;
IconInfo *iconList = NULL, *iconPtr;
char *filePath, *name, *contents,
command[2*MAXPATHLEN + 5];
int ii;
if (transferInfo == NULL) {
return;
}
/*
* Verify the protocol and callback reasons
*/
if (transferInfo->dropData->protocol != DtDND_FILENAME_TRANSFER ||
transferInfo->reason != DtCR_DND_TRANSFER_DATA) {
return;
}
if (widget != NULL) {
XtVaGetValues(widget, XmNuserData, &iconList, NULL);
}
/*
* Copy the dropped file(s) to the drop directory
*/
for (ii = 0; ii < transferInfo->dropData->numItems; ii++) {
/* Copy the file(s) */
filePath = transferInfo->dropData->data.files[ii];
contents = fileGetContents(filePath);
if ((name = strrchr(filePath,'/')) == NULL) {
name = filePath;
} else {
name++;
}
sprintf(command, "cp %s %s", filePath,
fileGetDirectoryName(DropDirectory));
if (system(command) != 0) {
printf("Could not copy file \"%s\" to \"%s\".\n",
filePath, fileGetDirectoryName(DropDirectory));
transferInfo->status = DtDND_FAILURE;
return;
}
/* Create icon(s) for new file(s) at the drop site */
iconPtr = IconNew();
IconInitialize(widget, iconPtr,
transferInfo->x + ii * 10,
transferInfo->y + ii * 10,
contents, strlen(contents), name, IconByData);
iconPtr->next = iconList;
if (iconList != NULL) {
iconList->prev = iconPtr;
}
iconList = iconPtr;
XtVaSetValues(widget, XmNuserData, iconList, NULL);
XtFree(contents);
}
}
/*
* fileDragSetup
*
* Prepares the file draw area to be a drag source.
*/
void
fileDragSetup(
Widget fileDraw)
{
char translations[] = "<Btn2Down>: fileCheckForDragProc()";
XtTranslations newTranslations;
XtActionsRec actionTable[] = {
{"fileCheckForDragProc", (XtActionProc)fileCheckForDragProc},
};
XtAppAddActions(demoAppContext, actionTable, 1);
newTranslations = XtParseTranslationTable(translations);
XtVaSetValues(fileDraw, XmNtranslations, newTranslations, NULL);
XtAddEventHandler(fileDraw, Button1MotionMask, False,
(XtEventHandler)demoDragMotionHandler,
(XtPointer)DtDND_FILENAME_TRANSFER);
fileCreateFiles(fileDraw);
}
/*
* fileDropSetup
*
* Such a function is not needed since the demoDropSetup() in demo.c registers
* the draw area as a drop site for drops of file names.
*/
/*
* fileDragStart
*
* Initiates a file drag. The function fileCheckForDrag() first determines
* if the pointer is over a file icon before calling this function.
*/
static void
fileDragStart(
Widget widget,
XEvent *event,
IconInfo *iconArray,
int numFiles)
{
static XtCallbackRec convertCBRec[] = { {fileConvertCallback, NULL},
{NULL, NULL} };
static XtCallbackRec dragFinishCBRec[] =
{ {demoDragFinishCallback, NULL},
{fileDragFinishCallback, NULL},
{NULL, NULL} };
Widget dragIcon;
Arg arg[1];
convertCBRec[0].closure = (XtPointer) iconArray;
/*
* Set up drag icon
*/
if (numFiles == 1) {
if (iconArray[0].dragIcon == NULL) {
iconArray[0].dragIcon = DtDndCreateSourceIcon(widget,
iconArray[0].bitmap, iconArray[0].mask);
}
dragIcon = iconArray[0].dragIcon;
} else {
dragIcon = NULL; /* Use default multiple provided by library */
}
XtSetArg(arg[0], DtNsourceIcon, (XtArgVal)dragIcon);
/*
* Start the drag
*/
if (DtDndDragStart(widget, event, DtDND_FILENAME_TRANSFER, numFiles,
XmDROP_COPY | XmDROP_MOVE,
convertCBRec, dragFinishCBRec, arg, 1)
== NULL) {
printf("DragStart returned NULL.\n");
}
}
/*
* fileCheckForDragProc
*
* Called when button 2 is pressed in the file drag area. Calls
* fileCheckForDrag() to determine if the button was pressed over a file
* icon in which case a drag is started.
*/
static XtActionProc
fileCheckForDragProc(
Widget widget,
XEvent *event,
String *params,
Cardinal *numParams)
{
fileCheckForDrag(widget, event, event->xbutton.x, event->xbutton.y);
}
/*
* fileCheckForDrag
*
* Determine if the pointer is over a file icon (within the drag threshold)
* when button 2 is pressed or when button 1 was pressed and the drag
* threshold has been exceeded.
*/
void
fileCheckForDrag(
Widget widget,
XEvent *event,
int initialX,
int initialY)
{
IconInfo *iconList, *iconPtr, *iconArray;
XtVaGetValues(widget, XmNuserData, &iconList, NULL);
if (iconList == NULL) {
printf("Unable to locate icon list.\n");
}
for (iconPtr = iconList; iconPtr != NULL; iconPtr = iconPtr->next) {
if ((initialX > (int)iconPtr->icon.x &&
initialX < (int)(iconPtr->icon.x + iconPtr->icon.width)) &&
(initialY > (int)iconPtr->icon.y &&
initialY < (int)(iconPtr->icon.y + iconPtr->icon.height))){
/*
* This starts a single file drag. To start a multiple
* file drag add elements to the icon array here. The
* convert and transfer callbacks are already written
* to handle multiple file transfers.
*/
iconArray = (IconInfo *)XtCalloc(1,sizeof(IconInfo));
iconArray[0] = *iconPtr;
fileDragStart(widget, event, iconArray, 1);
}
}
}
/*************************************************************************
*
* File Creation, Initialization & Destruction
*
*************************************************************************/
/*
* fileCreateDragSource
*
* Create draw area with a frame to serve as the drag source for files.
*/
Widget
fileCreateDragSource(
Widget parent)
{
Widget fileFrame,
fileDraw;
fileFrame = XtVaCreateManagedWidget("fileFrame",
xmFrameWidgetClass, parent,
NULL);
fileDraw = XtVaCreateManagedWidget("fileDraw",
xmDrawingAreaWidgetClass, fileFrame,
NULL);
XtAddCallback(fileDraw, XmNexposeCallback, demoDrawExposeCallback,NULL);
return fileDraw;
}
/*
* fileCreateDropSite
*
* Such a function is not needed since the drop site is the draw area which
* is created in demoCreateDropSite() in demo.c
*/
/*
* fileCreateDirectory
*
* Create the given directory.
*/
static void
fileCreateDirectory(
char *directory)
{
char command[MAXPATHLEN + 8];
sprintf(command, "mkdir %s", directory);
if (system(command) != 0) {
printf("Unable to create directory \"%s\"\n", directory);
exit(1);
}
}
/*
* fileCreateFile
*
* Given a path (partial or absolute), a file name and data create a file
* containing the given data using the given path.
*/
static void
fileCreateFile(
char *filePath,
char *fileName,
char *fileData)
{
FILE *fp;
char filePathAndName[MAXPATHLEN];
sprintf(filePathAndName, "%s/%s", filePath, fileName);
if ((fp = fopen(filePathAndName, "w")) == NULL) {
printf("Cannot create file \"%s\" in current directory.\n"
"Exiting...\n", filePathAndName);
exit(1);
}
if (fwrite(fileData, strlen(fileData), 1, fp) != 1) {
printf("Cannot write file \"%s\" in current directory.\n"
"Exiting...\n", filePathAndName);
exit(1);
}
fclose(fp);
}
/*
* fileCreateFiles
*
* Create drag and drop directories and the files to drag.
*/
static void
fileCreateFiles(
Widget fileDraw)
{
IconInfo *iconList,
*iconPtr;
char *dragDirectory,
*dropDirectory;
Atom WM_DELETE_WINDOW;
WM_DELETE_WINDOW =
XmInternAtom(XtDisplay(demoTopLevel), "WM_DELETE_WINDOW", False);
XmAddWMProtocolCallback(demoTopLevel, WM_DELETE_WINDOW, fileShutdown,
(XtPointer)NULL);
dragDirectory = fileGetDirectoryName(DragDirectory);
dropDirectory = fileGetDirectoryName(DropDirectory);
fileRemoveDirectory(dragDirectory);
fileCreateDirectory(dragDirectory);
fileRemoveDirectory(dropDirectory);
fileCreateDirectory(dropDirectory);
fileCreateFile(dragDirectory, FILE_NAME_TEXT, FILE_DATA_TEXT);
fileCreateFile(dragDirectory, FILE_NAME_CSH, FILE_DATA_CSH);
fileCreateFile(dragDirectory, FILE_NAME_PS, FILE_DATA_PS);
iconPtr = IconNew();
IconInitialize(fileDraw, iconPtr, 40, 25,
FILE_DATA_TEXT, strlen(FILE_DATA_TEXT),
FILE_NAME_TEXT, IconByData);
iconList = iconPtr;
iconPtr = IconNew();
iconPtr->next = iconList;
iconList->prev = iconPtr;
IconInitialize(fileDraw, iconPtr, 105, 25,
FILE_DATA_CSH, strlen(FILE_DATA_CSH),
FILE_NAME_CSH, IconByData);
iconList = iconPtr;
iconPtr = IconNew();
iconPtr->next = iconList;
iconList->prev = iconPtr;
IconInitialize(fileDraw, iconPtr, 75, 95,
FILE_DATA_PS, strlen(FILE_DATA_PS),
FILE_NAME_PS, IconByData);
iconList = iconPtr;
XtVaSetValues(fileDraw, XmNuserData, iconList, NULL);
}
/*
* fileRemoveDirectory
*
* Remove the given directory and its contents if the directory exists.
*/
static void
fileRemoveDirectory(
char *directory)
{
struct stat fileStatus;
char command[MAXPATHLEN + 8];
if (stat(directory, &fileStatus) == 0) { /* directory exists */
sprintf(command, "rm -rf %s", directory);
if (system(command) != 0) {
printf("Unable to remove directory \"%s\"\n"
"Please remove this directory by hand "
"and try again.\n", directory);
exit(1);
}
}
}
/*
* fileShutdown
*
* Remove the temporary file
*/
static void
fileShutdown(
Widget widget,
XtPointer clientData,
XtPointer callData)
{
fileRemoveDirectory(fileGetDirectoryName(DragDirectory));
fileRemoveDirectory(fileGetDirectoryName(DropDirectory));
}
/*************************************************************************
*
* File Utility Functions
*
*************************************************************************/
/*
* fileGetContents
*
* Open the specified file and read the contents into a buffer which is
* returned.
*/
static char*
fileGetContents(
char *filePath)
{
char *contents = NULL;
struct stat fileStatus;
FILE *fp;
if (stat(filePath, &fileStatus) == 0) { /* file exists */
contents = (char *) XtMalloc(fileStatus.st_size + 1);
if ((fp = fopen(filePath, "r")) == NULL) {
printf("Cannot open file \"%s\" for reading.\n",
filePath);
XtFree(contents);
contents = NULL;
} else if (fread(contents, fileStatus.st_size, 1, fp) != 1) {
printf("Cannot read file \"%s\".\n", filePath);
XtFree(contents);
contents = NULL;
}
if (contents != NULL) {
contents[fileStatus.st_size] = NULL;
}
fclose(fp);
}
return contents;
}
/*
* fileGetDemoDirectory
*
* Return the directory where the demo directories reside.
*/
static char*
fileGetDemoDirectory()
{
static char *demoDirectory = NULL;
char currentDirectory[MAXPATHLEN];
int status;
if (demoDirectory == NULL) {
demoDirectory = (char *) getenv("DNDDEMODIR");
if (demoDirectory == NULL) {
demoDirectory = (char *) getcwd(NULL, MAXPATHLEN);
if (demoDirectory == NULL) {
sprintf(
"getcwd() could not get current directory.\n"
"\tUsing \".\" instead.\n",
NULL);
demoDirectory = ".";
} else {
/* strip off the /tmp_mnt */
if (strncmp(demoDirectory, "/tmp_mnt/", 9) == 0) {
demoDirectory += 8;
}
}
}
}
return demoDirectory;
}
/*
* fileGetDirectoryName
*
* Gets the name of the directory where the files are dragged from or dropped
* to depending on which is requested.
*/
static char*
fileGetDirectoryName(
DragOrDrop dragOrDrop)
{
static char *dragDirectory = NULL;
static char *dropDirectory = NULL;
switch (dragOrDrop) {
case DragDirectory:
if (dragDirectory == NULL) {
dragDirectory = (char *) XtMalloc(MAXPATHLEN + 1);
sprintf(dragDirectory, "%s/FileDragDir",
fileGetDemoDirectory());
}
return dragDirectory;
break;
case DropDirectory:
if (dropDirectory == NULL) {
dropDirectory = (char *) XtMalloc(MAXPATHLEN + 1);
sprintf(dropDirectory, "%s/FileDropDir",
fileGetDemoDirectory());
}
return dropDirectory;
break;
default:
return NULL;
}
}
/*
* fileStoreBuffer
*
* Store a buffer into a file in the drop directory.
* A temporary file may be created if required.
*/
char *
fileStoreBuffer(
char *name,
void *buf,
int len)
{
char path[MAXPATHLEN];
char *dir = fileGetDirectoryName(DropDirectory);
struct stat statInfo;
FILE *fp;
if (name == NULL)
name = "unnamed";
sprintf(path, "%s/%s", dir, name);
if (stat(path, &statInfo) == 0) {
char *tPath;
if ((tPath = tempnam(dir, name)) == NULL)
return (char *)NULL;
strcpy(path, tPath);
free(tPath);
}
if ((fp = fopen(path, "w")) == NULL) {
printf("Cannot create file \"%s\"\n", path);
return (char *)NULL;
}
if (fwrite(buf, len, 1, fp) != 1) {
printf("Cannot write to file \"%s\".\n", path);
return (char *)NULL;
}
fclose(fp);
return XtNewString(path);
}

26
cde/examples/dtdnd/file.h Normal file
View File

@@ -0,0 +1,26 @@
/* $XConsortium: file.h /main/3 1995/10/27 10:39:01 rswiston $ */
/*****************************************************************************
*****************************************************************************
**
** File: file.h
**
** Description: Header for file transfer portion of CDE Drag & Drop Demo.
**
** (c) Copyright 1993, 1994 Hewlett-Packard Company
** (c) Copyright 1993, 1994 International Business Machines Corp.
** (c) Copyright 1993, 1994 Sun Microsystems, Inc.
** (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of
** Novell, Inc.
**
****************************************************************************
************************************<+>*************************************/
/*
* Public File Transfer Function Declarations
*/
void fileCheckForDrag(Widget, XEvent*, int, int);
Widget fileCreateDragSource(Widget);
void fileDragSetup(Widget);
void fileTransferCallback(Widget, XtPointer, XtPointer);
char * fileStoreBuffer(char*, void*, int);

538
cde/examples/dtdnd/icon.c Normal file
View File

@@ -0,0 +1,538 @@
/* $XConsortium: icon.c /main/3 1995/10/27 10:39:09 rswiston $ */
/*****************************************************************************
*****************************************************************************
**
** File: icon.c
**
** Description: Icon support functions for the CDE Drag & Drop Demo.
**
** (c) Copyright 1993, 1994 Hewlett-Packard Company
** (c) Copyright 1993, 1994 International Business Machines Corp.
** (c) Copyright 1993, 1994 Sun Microsystems, Inc.
** (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of
** Novell, Inc.
**
****************************************************************************
************************************<+>*************************************/
#include <stdio.h>
#include <Xm/Screen.h>
#include <Dt/Dts.h>
#include <Dt/Dnd.h>
#include "icon.h"
/*************************************************************************
*
* Data Structures & Private Declarations For Icon Handling Functions
*
**************************************************************************/
#define ICON_TEXT_YGAP 2
#define ICON_PATH "/usr/dt/appconfig/icons/C"
#define ICON_BITMAP_SUFFIX "m.bm"
#define ICON_MASK_SUFFIX "m_m.bm"
/*
* Default Generic Icon Bitmap & Mask
*/
#define iconWidth 32
#define iconHeight 32
static unsigned char iconBits[] = {
0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0x0f, 0x08, 0x00, 0x00, 0x08,
0x08, 0x00, 0x00, 0x08, 0x08, 0x00, 0x00, 0x08, 0x88, 0x9d, 0x6d, 0x08,
0x08, 0x00, 0x00, 0x08, 0x08, 0x00, 0x00, 0x08, 0x88, 0xf9, 0xed, 0x08,
0x08, 0x00, 0x00, 0x08, 0xc8, 0x6e, 0x7d, 0x08, 0x08, 0x00, 0x00, 0x08,
0xc8, 0x9d, 0xef, 0x09, 0x08, 0x00, 0x00, 0x08, 0xc8, 0xdd, 0xb3, 0x08,
0x08, 0x00, 0x00, 0x08, 0xc8, 0xdf, 0xfd, 0x09, 0x08, 0x00, 0x00, 0x08,
0xc8, 0xf6, 0xde, 0x08, 0x08, 0x00, 0x00, 0x08, 0x08, 0x00, 0x00, 0x08,
0x88, 0xed, 0xd2, 0x08, 0x08, 0x00, 0x00, 0x08, 0xc8, 0xbb, 0xf3, 0x08,
0x08, 0x00, 0x00, 0x08, 0x48, 0xdf, 0x5e, 0x08, 0x08, 0x00, 0x00, 0x08,
0xc8, 0x36, 0x00, 0x08, 0x08, 0x00, 0x00, 0x08, 0x08, 0x00, 0x00, 0x08,
0x08, 0x00, 0x00, 0x08, 0xf8, 0xff, 0xff, 0x0f};
#define iconMaskWidth 32
#define iconMaskHeight 32
static unsigned char iconMaskBits[] = {
0x00, 0x00, 0x00, 0x00, 0xf8, 0xff, 0xff, 0x0f, 0xf8, 0xff, 0xff, 0x0f,
0xf8, 0xff, 0xff, 0x0f, 0xf8, 0xff, 0xff, 0x0f, 0xf8, 0xff, 0xff, 0x0f,
0xf8, 0xff, 0xff, 0x0f, 0xf8, 0xff, 0xff, 0x0f, 0xf8, 0xff, 0xff, 0x0f,
0xf8, 0xff, 0xff, 0x0f, 0xf8, 0xff, 0xff, 0x0f, 0xf8, 0xff, 0xff, 0x0f,
0xf8, 0xff, 0xff, 0x0f, 0xf8, 0xff, 0xff, 0x0f, 0xf8, 0xff, 0xff, 0x0f,
0xf8, 0xff, 0xff, 0x0f, 0xf8, 0xff, 0xff, 0x0f, 0xf8, 0xff, 0xff, 0x0f,
0xf8, 0xff, 0xff, 0x0f, 0xf8, 0xff, 0xff, 0x0f, 0xf8, 0xff, 0xff, 0x0f,
0xf8, 0xff, 0xff, 0x0f, 0xf8, 0xff, 0xff, 0x0f, 0xf8, 0xff, 0xff, 0x0f,
0xf8, 0xff, 0xff, 0x0f, 0xf8, 0xff, 0xff, 0x0f, 0xf8, 0xff, 0xff, 0x0f,
0xf8, 0xff, 0xff, 0x0f, 0xf8, 0xff, 0xff, 0x0f, 0xf8, 0xff, 0xff, 0x0f,
0xf8, 0xff, 0xff, 0x0f, 0xf8, 0xff, 0xff, 0x0f};
/*
* Blank Bitmap
*/
#define blankWidth 16
#define blankHeight 16
static unsigned char blankBits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
/*
* Private Icon Handling Function Declarations
*/
static void iconClearBitmap(Display*, Window, GC, Pixmap, int, int);
static Pixmap iconDefaultBitmap(Display*, Window, IconBitmapPart,
unsigned short*, unsigned short*);
static void iconFree(IconInfo*);
static Pixmap iconGetBitmap(Widget, char*, IconBitmapPart, unsigned short*,
unsigned short*);
static char *iconGetIconPath(void*, int, IconTyping, IconBitmapPart);
static Pixmap iconMergeBitmaps(Widget, Pixmap, int, int, Pixmap, int, int,
int, int, Boolean);
/*************************************************************************
*
* Public Icon Handling Functions
*
**************************************************************************/
/*
* IconCreateDouble
*
* Create a double icon from a single icon. The double icon has a bitmap
* consisting of 2 images of the original bitmap offset from one another.
*/
void
IconCreateDouble(
Widget widget,
IconInfo *oldIcon,
int xOffset,
int yOffset,
IconInfo *newIcon,
short xx,
short yy)
{
newIcon->bitmap = iconMergeBitmaps(widget,
oldIcon->bitmap, oldIcon->icon.width, oldIcon->icon.height,
oldIcon->bitmap, oldIcon->icon.width, oldIcon->icon.height,
xOffset, yOffset, False);
newIcon->mask = iconMergeBitmaps(widget,
oldIcon->mask, oldIcon->icon.width, oldIcon->icon.height,
oldIcon->mask, oldIcon->icon.width, oldIcon->icon.height,
xOffset, yOffset, True);
newIcon->icon.width = oldIcon->icon.width + 10;
newIcon->icon.height = oldIcon->icon.height + 10;
newIcon->name = XtNewString("Multiple");
newIcon->icon.x = xx;
newIcon->icon.y = yy;
newIcon->dragIcon = DtDndCreateSourceIcon(widget,
newIcon->bitmap, newIcon->mask);
}
/*
* IconDelete
*
* Remove the icon from its list and deallocate memory used by the icon.
*/
void
IconDelete(
Widget drawArea,
IconInfo *iconPtr)
{
IconInfo *iconList;
if (iconPtr == NULL || drawArea == NULL) {
return;
}
if (iconPtr->next != NULL) { /* iconPtr is not the tail of the list */
iconPtr->next->prev = iconPtr->prev;
}
if (iconPtr->prev != NULL) { /* iconPtr is not the head of the list */
iconPtr->prev->next = iconPtr->next;
}
if (iconPtr->next == NULL) { /* iconPtr is the tail of the list */
iconList = iconPtr->prev;
} else {
iconList = iconPtr->next;
}
while (iconList != NULL && iconList->prev != NULL) {
iconList = iconList->prev;
}
iconFree(iconPtr);
XtVaSetValues(drawArea, XmNuserData, iconList, NULL);
}
/*
* IconDraw
*
* Render given icon in the window of the given widget.
*/
void
IconDraw(
Widget widget,
IconInfo *iconPtr)
{
static GC graphicsContext = NULL;
static XFontStruct *fontStruct;
Display *display = XtDisplayOfObject(widget);
Window window = XtWindow(widget);
int screen = DefaultScreen(display);
XGCValues gcValues;
if (graphicsContext == NULL) {
gcValues.foreground = BlackPixel(display, screen);
gcValues.background = WhitePixel(display, screen);
graphicsContext = XCreateGC(display, window,
GCForeground | GCBackground, &gcValues);
}
/*
* Draw icon
*/
gcValues.clip_mask = iconPtr->mask;
gcValues.clip_x_origin = iconPtr->icon.x;
gcValues.clip_y_origin = iconPtr->icon.y;
XChangeGC(display, graphicsContext,
GCClipMask | GCClipXOrigin | GCClipYOrigin, &gcValues);
XCopyPlane(display, iconPtr->bitmap, window, graphicsContext, 0, 0,
iconPtr->icon.width, iconPtr->icon.height,
iconPtr->icon.x, iconPtr->icon.y, 1L);
/*
* Draw icon name centered below icon
*/
if (iconPtr->name != NULL) {
int nameX, nameY;
int direction, ascent, decent;
XCharStruct overall;
Widget xmScreen;
if (fontStruct == NULL) {
xmScreen = XmGetXmScreen(XtScreen(widget));
XtVaGetValues(xmScreen, XmNfont, &fontStruct, NULL);
}
XTextExtents(fontStruct, iconPtr->name, strlen(iconPtr->name),
&direction, &ascent, &decent, &overall);
nameX = (iconPtr->icon.x + (iconPtr->icon.width/2)) -
(overall.width/2);
nameY = iconPtr->icon.y + iconPtr->icon.height +
ICON_TEXT_YGAP + ascent;
gcValues.font = fontStruct->fid;
gcValues.clip_mask = None;
XChangeGC(display, graphicsContext,
GCFont | GCClipMask, &gcValues);
XDrawString(display, window, graphicsContext, nameX, nameY,
iconPtr->name, strlen(iconPtr->name));
}
}
/*
* IconInitialize
*
* Initialize given icon with given data. Get icon bitmap based on data
* associated with the icon. This data may be a file name, a buffer or
* a type name. Create source icon for dragging based on the bitmap and mask.
*/
void
IconInitialize(
Widget widget,
IconInfo *iconPtr,
short x,
short y,
void *data,
int dataLen,
char *name,
IconTyping typing)
{
char *iconPath;
iconPath = iconGetIconPath(data, dataLen, typing, IconMask);
iconPtr->mask = iconGetBitmap(widget, iconPath, IconMask,
&(iconPtr->icon.width), &(iconPtr->icon.height));
XtFree(iconPath);
iconPath = iconGetIconPath(data, dataLen, typing, IconBitmap);
iconPtr->bitmap = iconGetBitmap(widget, iconPath, IconBitmap,
&(iconPtr->icon.width), &(iconPtr->icon.height));
XtFree(iconPath);
iconPtr->icon.x = x;
iconPtr->icon.y = y;
iconPtr->name = XtNewString(name);
iconPtr->dragIcon = DtDndCreateSourceIcon(widget,
iconPtr->bitmap, iconPtr->mask);
}
/*
* IconNew
*
* Allocate memory for a new icon structure and clear.
*/
IconInfo*
IconNew()
{
IconInfo *iconPtr;
iconPtr = (IconInfo*) XtMalloc(sizeof(IconInfo));
memset(iconPtr, 0x00, sizeof(IconInfo));
return iconPtr;
}
/*************************************************************************
*
* Private Icon Handling Functions
*
**************************************************************************/
/*
* iconClearBitmap
*
* Clear a bitmap by filling it with zeros.
*/
static void
iconClearBitmap(
Display *display,
Window window,
GC graphicsContext,
Pixmap bitmap,
int width,
int height)
{
int xx, yy;
static Pixmap blankBitmap = NULL;
if (blankBitmap == NULL) {
blankBitmap = XCreateBitmapFromData(display, window,
(char *)blankBits, blankWidth, blankHeight);
}
for (xx = 0; xx < width + blankWidth; xx += blankWidth) {
for (yy = 0; yy < height + blankHeight; yy += blankHeight) {
XCopyArea(display, blankBitmap, bitmap,
graphicsContext, 0, 0,
blankWidth, blankHeight, xx, yy);
}
}
}
/*
* iconDefaultBitmap
*
* Create default icon bitmap or mask and set width and height accordingly.
*/
static Pixmap
iconDefaultBitmap(
Display *display,
Window window,
IconBitmapPart iconPart,
unsigned short *width,
unsigned short *height)
{
static Pixmap bitmap;
static Pixmap mask;
if (iconPart == IconMask) { /* create default mask */
if (mask == NULL) {
mask = XCreateBitmapFromData(display, window,
(char *)iconMaskBits, iconMaskWidth, iconMaskHeight);
}
*width = iconMaskWidth;
*height = iconMaskHeight;
return mask;
} else { /* create default bitmap */
if (bitmap == NULL) {
bitmap = XCreateBitmapFromData(display, window,
(char *)iconBits, iconWidth, iconHeight);
}
*width = iconWidth;
*height = iconHeight;
return bitmap;
}
}
/*
* iconFree
*
* Deallocate the icon and associated resources.
*/
static void
iconFree(
IconInfo *iconPtr)
{
Display *display = XtDisplayOfObject(iconPtr->dragIcon);
if (iconPtr == NULL) {
return;
}
XtFree(iconPtr->name);
/*
* REMIND: This needs to free other things too...
* XFreePixmap(display, iconPtr->bitmap);
* XFreePixmap(display, iconPtr->mask);
* Free(iconPtr->dragIcon);
*/
XtFree((char *)iconPtr);
}
/*
* iconGetBitmap
*
* Get a bitmap for the icon based on the path and name of the icon.
* If no bitmap file is found use a built-in default.
*/
static Pixmap
iconGetBitmap(
Widget widget,
char *iconPath,
IconBitmapPart iconPart,
unsigned short *returnWidth,
unsigned short *returnHeight)
{
Display *display = XtDisplayOfObject(widget);
Window window = DefaultRootWindow(display);
int status;
int xHot, yHot;
Pixmap bitmap;
unsigned int width, height;
*returnWidth = *returnHeight = 0;
if (iconPath != NULL) {
status = XReadBitmapFile(display, window, iconPath,
&width, &height, &bitmap, &xHot, &yHot);
if (status == BitmapSuccess) {
*returnWidth = (unsigned short) width;
*returnHeight = (unsigned short) height;
} else {
printf(
"Unable to read icon from bitmap file \"%s\".\n"
"Using default icon bitmap.\n",
iconPath, NULL);
bitmap = iconDefaultBitmap(display, window, iconPart,
returnWidth, returnHeight);
}
} else {
bitmap = iconDefaultBitmap(display, window, iconPart,
returnWidth, returnHeight);
}
return bitmap;
}
/*
* iconGetIconPath
*
* Get the file path and name for an icon based on the given data and
* method of typing that data. This function assumes the data typing
* database has been loaded with DtDtsLoadDataTypes().
*/
static char*
iconGetIconPath(
void *data,
int dataLen,
IconTyping typing,
IconBitmapPart iconPart)
{
char iconPath[MAXPATHLEN + 1],
*iconName,
*iconSuffix;
switch (typing) {
case IconByFile:
iconName = DtDtsFileToAttributeValue(data, "ICON");
break;
case IconByData:
iconName = DtDtsBufferToAttributeValue(data, dataLen,
"ICON", NULL);
break;
case IconByType:
iconName = DtDtsDataTypeToAttributeValue(data, "ICON", NULL);
break;
default:
iconName = NULL;
}
if (iconName != NULL) {
if (iconPart == IconMask) {
iconSuffix = ICON_MASK_SUFFIX;
} else {
iconSuffix = ICON_BITMAP_SUFFIX;
}
sprintf(iconPath, "%s/%s.%s", ICON_PATH, iconName, iconSuffix);
DtDtsFreeAttributeValue(iconName);
}
return XtNewString(iconPath);
}
/*
* iconMergeBitmaps
*
* Create new bitmap consisting of the offset composition of the given bitmaps.
*/
static Pixmap
iconMergeBitmaps(
Widget widget,
Pixmap bitmap1,
int width1,
int height1,
Pixmap bitmap2,
int width2,
int height2,
int xOffset,
int yOffset,
Boolean clear)
{
Display *display = XtDisplayOfObject(widget);
Window window = DefaultRootWindow(display);
int screen = DefaultScreen(display);
Pixmap mergedBitmap, blankBitmap;
int extraX, extraY, width, height;
static GC graphicsContext = NULL;
XGCValues gcValues;
extraX = width2 - width1 + xOffset + 1;
if (extraX < 0) extraX = 0;
width = width1 + extraX;
extraY = height2 - height1 + yOffset + 1;
if (extraY < 0) extraY = 0;
height = height1 + extraY;
mergedBitmap = XCreatePixmap(display, window, width, height, 1);
if (graphicsContext == NULL) {
graphicsContext = XCreateGC(display, mergedBitmap, 0L, NULL);
}
if (clear) {
iconClearBitmap(display, window, graphicsContext, mergedBitmap,
width, height);
}
XCopyArea(display, bitmap2, mergedBitmap, graphicsContext, 0, 0,
width2, height2, xOffset, yOffset);
XCopyArea(display, bitmap1, mergedBitmap, graphicsContext, 0, 0,
width1, height1, 0, 0);
return mergedBitmap;
}

64
cde/examples/dtdnd/icon.h Normal file
View File

@@ -0,0 +1,64 @@
/* $XConsortium: icon.h /main/3 1995/10/27 10:39:18 rswiston $ */
/*****************************************************************************
*****************************************************************************
**
** File: icon.h
**
** Description: Header for icon handling portion of CDE Drag & Drop Demo.
**
** (c) Copyright 1993, 1994 Hewlett-Packard Company
** (c) Copyright 1993, 1994 International Business Machines Corp.
** (c) Copyright 1993, 1994 Sun Microsystems, Inc.
** (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of
** Novell, Inc.
**
****************************************************************************
************************************<+>*************************************/
#include <sys/param.h>
#include <stdio.h>
/*
* Icon Information Structure
*/
typedef struct _IconInfo {
XRectangle icon;
char *name;
void *data;
int dataCount;
Pixmap bitmap;
Pixmap mask;
Widget dragIcon;
int type;
struct _IconInfo *next;
struct _IconInfo *prev;
} IconInfo;
/*
* Icon Typedefs
*/
typedef enum {
IconBitmap,
IconMask
} IconBitmapPart;
typedef enum {
IconByFile,
IconByData,
IconByType
} IconTyping;
/*
* Public Icon Handling Function Declarations
*/
void IconCreateDouble(Widget, IconInfo*, int, int, IconInfo*,
short, short);
void IconDelete(Widget, IconInfo*);
void IconDraw(Widget, IconInfo*);
void IconInitialize(Widget, IconInfo*, short, short, void*, int,
char*, IconTyping);
IconInfo *IconNew();

394
cde/examples/dtdnd/text.c Normal file
View File

@@ -0,0 +1,394 @@
/* $TOG: text.c /main/5 1999/07/20 14:50:18 mgreess $ */
/*****************************************************************************
*****************************************************************************
**
** File: text.c
**
** Description: Text transfer functions for the CDE Drag & Drop Demo.
**
** (c) Copyright 1993, 1994 Hewlett-Packard Company
** (c) Copyright 1993, 1994 International Business Machines Corp.
** (c) Copyright 1993, 1994 Sun Microsystems, Inc.
** (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of
** Novell, Inc.
**
****************************************************************************
************************************<+>*************************************/
#include <X11/Intrinsic.h>
#include <Xm/Xm.h>
#include <Xm/Label.h>
#include <Xm/List.h>
#include <Xm/RowColumn.h>
#include <Xm/Text.h>
#include <Dt/Dt.h>
#include <Dt/Dnd.h>
#include "demo.h"
#include "text.h"
/*************************************************************************
*
* Data Structures & Private Declarations For Text Transfers
*
**************************************************************************/
/*
* Data for text list of fruit
*/
char *todaysFruit[] = {
"Oranges",
"Peaches",
"Lemons",
"Watermelons",
"Apples",
"Bananas",
"Plums",
"Limes",
"Cantaloupes",
"Nectarines",
"Papayas",
"Mangos",
NULL
};
/*************************************************************************
*
* Text Drag & Drop
*
*************************************************************************/
/*
* textConvertCallback
*
* Sets the text object's text to the text in the fruit list based on where
* the pointer was when the drag started.
*/
void
textConvertCallback(
Widget dragContext,
XtPointer clientData,
XtPointer callData)
{
DtDndConvertCallbackStruct *convertInfo =
(DtDndConvertCallbackStruct *) callData;
Widget fruitList = (Widget) clientData;
int selectedPos;
XmString *items;
Cardinal itemCount;
if (convertInfo == NULL) {
return;
}
/*
* Verify protocol and callback reason
*/
if (convertInfo->dragData->protocol != DtDND_TEXT_TRANSFER ||
(convertInfo->reason != DtCR_DND_CONVERT_DATA &&
convertInfo->reason != DtCR_DND_CONVERT_DELETE) ||
fruitList == NULL) {
return;
}
switch (convertInfo->reason) {
case DtCR_DND_CONVERT_DATA:
/*
* Provide the text from the fruit list
*/
XtVaGetValues(fruitList,
XmNuserData, &selectedPos,
XmNitems, &items,
XmNitemCount, &itemCount,
NULL);
if (itemCount > 0 && selectedPos < itemCount) {
convertInfo->dragData->data.strings[0] =
items[selectedPos-1];
} else {
convertInfo->status = DtDND_FAILURE;
}
break;
DtCR_DND_CONVERT_DELETE:
/*
* Delete the text from the fruit list. If the fruit list
* were set up to be dynamic, deletion from the list would
* occur here.
*/
printf("Delete fruit item #%d\n",
convertInfo->dragData->data.strings[0]);
break;
}
}
/*
* textDragFinishCallback
*
* Normally would free any memory allocated by textConvertCallback
* but none was allocated so this is just a placeholder.
*/
void
textDragFinishCallback(
Widget widget,
XtPointer clientData,
XtPointer callData)
{
}
/*
* textTransferCallback
*
* Handles transfer of files or text to the text edit. Files are transfered
* by placing their name in the field, text by inserting the text into the
* field.
*/
void
textTransferCallback(
Widget widget,
XtPointer clientData,
XtPointer callData)
{
DtDndTransferCallbackStruct *transferInfo =
(DtDndTransferCallbackStruct *) callData;
String text;
/*
* Verify callback reason
*/
if (transferInfo == NULL ||
transferInfo->reason != DtCR_DND_TRANSFER_DATA) {
return;
}
switch (transferInfo->dropData->protocol) {
case DtDND_FILENAME_TRANSFER:
/*
* Copy the file name into the text field
*/
XtVaSetValues(widget,
XmNvalue, transferInfo->dropData->data.files[0],
NULL);
break;
case DtDND_TEXT_TRANSFER:
/*
* Copy the fruit name into the text field
*/
text = XmStringUnparse(transferInfo->dropData->data.strings[0],
NULL, XmCHARSET_TEXT, XmCHARSET_TEXT, NULL, 0, XmOUTPUT_ALL);
XtVaSetValues(widget, XmNvalue, text, NULL);
XtFree (text);
break;
}
}
/*
* textDragSetup
*
* Prepares the fruit list to source drags of text with button 1.
*/
void textDragSetup(Widget fruitList)
{
static char translations[] = "\
~c ~s ~m ~a <Btn1Down>:\
demoProcessPress(ListBeginSelect,textDragStart)\n\
c ~s ~m ~a <Btn1Down>:\
demoProcessPress(ListBeginToggle,textDragStart)";
static char btn2_translations[] = "\
~c ~s ~m ~a <Btn2Down>:\
demoProcessPress(ListBeginSelect,textDragStart)\n\
c ~s ~m ~a <Btn2Down>:\
demoProcessPress(ListBeginToggle,textDragStart)\n\
<Btn2Motion>:ListButtonMotion()\n\
~c ~s ~m ~a <Btn2Up>:ListEndSelect()\n\
c ~s ~m ~a <Btn2Up>:ListEndToggle()";
static XtActionsRec actionTable[] =
{
{"textDragStart", (XtActionProc) &textDragStart},
{"demoProcessPress", (XtActionProc) &demoProcessPress}
};
int btn1_transfer = 0;
XtTranslations new_translations;
XtAppAddActions(
demoAppContext,
actionTable,
sizeof(actionTable)/sizeof(actionTable[0]));
new_translations = XtParseTranslationTable(translations);
XtOverrideTranslations(fruitList, new_translations);
XtVaGetValues(
(Widget) XmGetXmDisplay(XtDisplayOfObject(fruitList)),
"enableBtn1Transfer", &btn1_transfer,
NULL);
if (btn1_transfer != True)
{
new_translations = XtParseTranslationTable(btn2_translations);
XtOverrideTranslations(fruitList, new_translations);
}
#if 0
XtAddEventHandler(fruitList, Button1MotionMask, False,
(XtEventHandler)demoDragMotionHandler,
(XtPointer)DtDND_TEXT_TRANSFER);
#endif
}
/*
* textDropSetup
*
* Registers text field to accept drops of files.
*/
void
textDropSetup(
Widget textField)
{
static XtCallbackRec transferCBRec[] = { {textTransferCallback, NULL},
{NULL, NULL} };
DtDndDropRegister(textField, DtDND_FILENAME_TRANSFER,
XmDROP_COPY, transferCBRec, NULL, 0);
}
/*
* textDragStart
*
* Initiates a drag of a text item from the fruit list provided the pointer
* is over an item in the list.
*/
void
textDragStart(
Widget widget,
XEvent *event)
{
int itemCount,
selectedPos;
static XtCallbackRec convertCBRec[] = { {textConvertCallback, NULL},
{NULL, NULL} };
static XtCallbackRec dragFinishCBRec[] =
{ {demoDragFinishCallback, NULL},
{textDragFinishCallback, NULL},
{NULL, NULL} };
/*
* Determine which item to drag from the text list
*/
XtVaGetValues(widget, XmNitemCount, &itemCount, NULL);
selectedPos = XmListYToPos(widget, event->xmotion.y);
if (selectedPos == 0 || selectedPos > itemCount) {
return;
}
XtVaSetValues(widget, XmNuserData, selectedPos, NULL);
convertCBRec[0].closure = (XtPointer)widget;
/*
* Start the drag
*/
if (DtDndDragStart(widget, event, DtDND_TEXT_TRANSFER, 1,
XmDROP_COPY, convertCBRec, dragFinishCBRec, NULL, 0)
== NULL) {
printf("DragStart returned NULL.\n");
}
}
/*************************************************************************
*
* Text Creation & Initialization
*
*************************************************************************/
/*
* textCreateDragSource
*
* Creates a scrolling list filled with fruit names.
*/
Widget
textCreateDragSource(
Widget parent)
{
Widget fruitList;
XmString *fruits;
Arg args[2];
int ii, fruitCount;
for (ii = 0; todaysFruit[ii] != NULL; ii++)
;
fruitCount = ii;
fruits = (XmString *) XtMalloc(sizeof(XmString) * fruitCount);
for (ii = 0; ii < fruitCount; ii++) {
fruits[ii] = XmStringCreate(todaysFruit[ii],
XmFONTLIST_DEFAULT_TAG);
}
ii = 0;
XtSetArg(args[ii], XmNitems, fruits); ii++;
XtSetArg(args[ii], XmNitemCount, fruitCount); ii++;
fruitList = XmCreateScrolledList(parent, "fruitList", args, ii);
XtManageChild(fruitList);
for (ii = 0; ii < fruitCount; ii++) {
XmStringFree(fruits[ii]);
}
XtFree((char *)fruits);
return fruitList;
}
/*
* textCreateDropSite
*
* Creates a text field with a label.
*/
Widget
textCreateDropSite(
Widget parent)
{
Widget textRowColumn,
textLabel,
textField;
textRowColumn = XtVaCreateManagedWidget("textRowColumn",
xmRowColumnWidgetClass, parent,
NULL);
textLabel = XtVaCreateManagedWidget("textLabel",
xmLabelWidgetClass, textRowColumn,
NULL);
textField = XtVaCreateManagedWidget("textField",
xmTextWidgetClass, textRowColumn,
NULL);
return textField;
}

27
cde/examples/dtdnd/text.h Normal file
View File

@@ -0,0 +1,27 @@
/* $XConsortium: text.h /main/3 1995/10/27 10:39:35 rswiston $ */
/*****************************************************************************
*****************************************************************************
**
** File: text.h
**
** Description: Header for text transfer portion of CDE Drag & Drop Demo.
**
** (c) Copyright 1993, 1994 Hewlett-Packard Company
** (c) Copyright 1993, 1994 International Business Machines Corp.
** (c) Copyright 1993, 1994 Sun Microsystems, Inc.
** (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of
** Novell, Inc.
**
****************************************************************************
************************************<+>*************************************/
/*
* Public Text Transfer Function Declarations
*/
void textDragSetup(Widget);
void textDropSetup(Widget);
void textDragStart(Widget, XEvent*);
Widget textCreateDragSource(Widget);
Widget textCreateDropSite(Widget);