Example 19-2. A drop-site item example (continued)
window_fit(frame);
xv_main_loop(frame);
exit(0);
}
void
EventProc(window, event)
Xv_Window window;
Event *event;
{
switch (event_action(event)) {
/* When drop previewing is available, if
* the drop site has selected for previewing
* events (DROP_SITE_EVENT_MASK) then it will
* receive ACTION_DRAG_PREVIEW events from
* the source as requested.
*/
case ACTION_DRAG_PREVIEW:
switch(event_id(event)) {
case LOC_WINENTER:
inverted = True;
break;
case LOC_WINEXIT:
inverted = False;
break;
case LOC_DRAG:
break;
}
PaintCanvas(NULL, window, XV_DISPLAY_FROM_WINDOW(window),
xv_get(window, XV_XID), NULL);
break;
case ACTION_DRAG_COPY:
case ACTION_DRAG_MOVE: {
Xv_drop_site ds;
Xv_Server server = XV_SERVER_FROM_WINDOW(event_window(event));
/* If the user dropped over an acceptable
* drop site, the owner of the drop site will
* be sent an ACTION_DROP_{COPY, MOVE} event.
*/
/* To acknowledge the drop and to associate the
* rank of the sources selection to our
* requestor selection object, we call
* dnd_decode_drop().
*/
if ((ds = dnd_decode_drop(sel, event)) != XV_ERROR) {
if (xv_get(ds, DROP_SITE_ID) == BULLSEYE_SITE)
UpdatePanel(server, sel);
/* If this is a move operation, we must ask
* the source to delete the selection object.
* We should only do this if the transfer of
* data was successful.
*/
Drag and Drop
Drag and Drop 453
Example 19-2. A drop-site item example (continued)
if (event_action(event) == ACTION_DRAG_MOVE) {
int length, format;
xv_set(sel, SEL_TYPE_NAME, "DELETE", NULL);
(void)xv_get(sel, SEL_DATA, &length, &format);
}
/* To complete the drag and drop operation,
* we tell the source that we are all done.
*/
dnd_done(sel);
inverted = False;
PaintCanvas(NULL, window, XV_DISPLAY_FROM_WINDOW(window),
xv_get(window, XV_XID), NULL);
} else
printf ("drop error\n");
break;
}
default:
break;
}
}
UpdatePanel(server, sel)
Xv_Server server;
Selection_requestor sel;
{
int length,
format,
*string_length;
char buf[7],
*string,
*hostname;
xv_set(sel, SEL_TYPE, XA_STRING, NULL);
string = (char *)xv_get(sel, SEL_DATA, &length, &format);
if (length != SEL_ERROR) {
xv_set(p_string, PANEL_VALUE, string, NULL);
free (string);
}
xv_set(sel,
SEL_TYPE, xv_get(server, SERVER_ATOM, "LENGTH"), NULL);
string_length = (int *)xv_get(sel, SEL_DATA, &length, &format);
if (length != SEL_ERROR) {
sprintf(buf, "%d", *string_length);
xv_set(p_length, PANEL_VALUE, buf, NULL);
free ((char *)string_length);
}
xv_set(sel, SEL_TYPE, xv_get(server, SERVER_ATOM, "HOST_NAME"), NULL);
hostname = (char *)xv_get(sel, SEL_DATA, &length, &format);
if (length != SEL_ERROR) {
xv_set(p_host, PANEL_VALUE, hostname, NULL);
454 XView Programming Manual
Example 19-2. A drop-site item example (continued)
free (hostname);
}
xv_set(sel, SEL_TYPE_NAME, "_SUN_SELECTION_END", NULL);
(void)xv_get(sel, SEL_DATA, &length, &format);
}
void
PaintCanvas(canvas, paint_window, dpy, xwin, xrects)
Canvas canvas; /* unused */
Xv_Window paint_window; /* unused */
Display *dpy;
Window xwin;
Xv_xrectlist *xrects; /* unused */
{
static GC gc;
static int gcCreated = False;
static int lastMode = False;
int width, height;
int x, y;
Rect *r;
if (!gcCreated) {
XGCValues gcv;
gcv.stipple = (Pixmap) xv_get(drop_image, XV_XID);
gcv.foreground = BlackPixel(dpy, XDefaultScreen(dpy));
gcv.background = WhitePixel(dpy, XDefaultScreen(dpy));
gcv.fill_style = FillStippled;
gc = XCreateGC(dpy, xwin, GCStipple|GCForeground|GCBackground|
GCFillStyle, &gcv);
}
if (lastMode != inverted) {
if (!inverted)
XSetStipple(dpy, gc, (Pixmap) xv_get(drop_image, XV_XID));
else
XSetStipple(dpy, gc, (Pixmap) xv_get(drop_image_inv,
XV_XID));
lastMode = inverted;
}
width = xv_get(paint_window, XV_WIDTH);
height = xv_get(paint_window, XV_HEIGHT);
x = (width/2)-(DROP_WIDTH/2);
y = (height/2)-(DROP_HEIGHT/2);
XClearArea(dpy, xwin, x, y, DROP_WIDTH, DROP_HEIGHT, False);
XSetTSOrigin(dpy, gc, x, y);
XFillRectangle(dpy, xwin, gc, x, y, DROP_WIDTH, DROP_HEIGHT);
}
void
ResizeCanvas(canvas, width, height)
Canvas canvas;
int width;
int height;
Drag and Drop
Drag and Drop 455
Example 19-2. A drop-site item example (continued)
{
int x, y;
Rect rect;
x = (width/2)-(DROP_WIDTH/2);
y = (height/2)-(DROP_HEIGHT/2);
rect.r_left = x;
rect.r_top = y;
rect.r_width = DROP_WIDTH;
rect.r_height = DROP_HEIGHT;
/* Update the drop site information. */
xv_set(drop_site, DROP_SITE_DELETE_REGION_PTR, NULL,
DROP_SITE_REGION, &rect,
NULL);
}
19.7 Drag and Drop Package Summary
Table 19-3 lists the procedures and macros used for dragging and dropping. Table 19-4 lists
the DROP_SITE_ITEM and DRAGDROP package attributes. These attributes, procedures, and
macros are described fully in the XView Reference Manual.
Table 19-3. DROP_SITE_ITEM and DRAGDROP Procedures and Macros
dnd_decode_drop()
dnd_done()
dnd_is_forwarded()
dnd_is_local()
dnd_send_drop()
Table 19-4. DROP_SITE_ITEM and DRAGDROP Attributes
DROP_SITE_ITEM Attributes DRAGDROP Attributes
DROP_SITE_DEFAULT DND_ACCEPT_CURSOR
DROP_SITE_DELETE_REGION DND_ACCEPT_X_CURSOR
DROP_SITE_DELETE_REGION_PTR DND_CURSOR
DROP_SITE_EVENT_MASK DND_TIMEOUT_VALUE
DROP_SITE_ID DND_TYPE
DROP_SITE_REGION DND_X_CURSOR
DROP_SITE_REGION_PTR
456 XView Programming Manual
This page intentionally left blank
to preserve original page counts.

Get Volume 7A: XView Programming Manual now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.