home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
m
/
master12.zip
/
mastering
/
buttondnd.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-08-18
|
5KB
|
177 lines
/* include files */
#include <stdio.h>
#include <Xm/PushB.h>
#include <Xm/BulletinB.h>
#include <Xm/Form.h>
#include <Xm/DragDrop.h>
/* Functions defined in this program */
void main();
void activateCB(); /* Callback for the pushbutton */
void TransferData(); /* Transfers information from initiator */
void ProcessDrop(); /* Handles the drop */
/* Global variables */
XmString btn_text; /* button label pointer for compound string */
Atom COMPOUND_TEXT;
/*-------------------------------------------------------------
** TransferData
*
* This routine transfers information from the initiator */
static void TransferData(w, client_data, selection, type, value, length,
format)
Widget w;
XtPointer client_data;
Atom *selection;
Atom *type;
XtPointer value;
unsigned long *length;
int *format;
{
int n;
Arg args[10];
/* Information from the drag initiator is passed in compound
* text format. Convert it to compound string and replace the button
* label. */
if (*type == COMPOUND_TEXT) {
n = 0;
XtSetArg(args[n], XmNlabelString, XmCvtCTToXmString(value)); n++;
XtSetValues(client_data, args, n);
}
}
/*-------------------------------------------------------------
** ProcessDrop
*
* This routine is performed when a drop is made. It decides what
information it wants and uses TransferData to transfer the data
from the initiator */
static void ProcessDrop(w, client_data, call_data)
Widget w;
XtPointer client_data, call_data;
{
XmDropProcCallback DropData;
XmDropTransferEntryRec transferEntries[1];
XmDropTransferEntry transferList;
Arg args[10];
int n;
DropData = (XmDropProcCallback)call_data;
/* set the transfer resources */
n = 0;
/* if the action is not Drop or the operation is not Copy,
* cancel the drop */
if ((DropData->dropAction != XmDROP) ||
(DropData->operation != XmDROP_COPY)) {
XtSetArg(args[n], XmNtransferStatus, XmTRANSFER_FAILURE); n++;
}
else {
transferEntries[0].target = COMPOUND_TEXT;
transferEntries[0].client_data = (XtPointer)w;
transferList = transferEntries;
XtSetArg(args[n], XmNdropTransfers, transferList); n++;
XtSetArg(args[n], XmNnumDropTransfers, 1); n++;
XtSetArg(args[n], XmNtransferProc, TransferData); n++;
}
/* start the transfer or cancel */
XmDropTransferStart(DropData->dragContext, args, n);
}
/*-------------------------------------------------------------
** activateCB - callback for button
*/
void activateCB (w, client_data, call_data)
Widget w; /* widget id */
XtPointer client_data; /* data from application */
XtPointer call_data; /* data from widget class */
{
/* Print message and terminate program */
printf ("Pushbutton Activated.\n");
exit (0);
}
/*-------------------------------------------------------------
** main - Main logic for xmbutton
*/
void main (argc,argv)
unsigned int argc;
char **argv;
{
Widget toplevel; /* Shell widget */
Widget bboard; /* Bulletin board widget */
Widget form1; /* Form widget */
Widget button; /* Pushbutton widget */
Arg args[10]; /* arg list */
register int n; /* arg count */
XtAppContext app_context; /* application context */
Atom import_list[1]; /* compound text */
/* Initialize the toolkit, create application context, open display,
and create a toplevel shell */
toplevel = XtAppInitialize (&app_context, "Buttondnd", NULL, 0, &argc,
argv, NULL, args, 0);
/* Create a bulletin board widget in which to place the pushbutton
n = 0;
bboard = XmCreateBulletinBoard (toplevel, "bboard", args, n); */
n = 0;
form1 = XmCreateForm (toplevel, "form1", args, n);
/* Manage the bulletin board widget */
XtManageChild (form1);
/* Create a compound string for the button label */
btn_text = XmStringCreateLtoR("Push Here", XmSTRING_DEFAULT_CHARSET);
/* Set up an arglist for the pushbutton */
n = 0;
XtSetArg(args[n], XmNlabelString, btn_text); n++;
/* Create the push button */
button = XtCreateManagedWidget ("button", xmPushButtonWidgetClass, form1,
args, n);
/* Create compound text for the button label */
COMPOUND_TEXT = XmInternAtom(XtDisplay(toplevel), "COMPOUND_TEXT", False);
/* register the button as a drop site */
import_list[0] = COMPOUND_TEXT;
n = 0;
XtSetArg(args[n], XmNimportTargets, import_list); n++;
XtSetArg(args[n], XmNnumImportTargets, 1); n++;
XtSetArg(args[n], XmNdropSiteOperations, XmDROP_COPY); n++;
XtSetArg(args[n], XmNdropProc, ProcessDrop); n++;
XmDropSiteRegister(button, args, n);
/* Free the compound string memory */
XmStringFree (btn_text);
/* Add a callback */
XtAddCallback (button, XmNactivateCallback, activateCB, NULL);
/* Realize widgets */
XtRealizeWidget (toplevel);
/* Process events */
XtAppMainLoop (app_context);
}