/usr/share/doc/xviewg/examples/dnd/dest.c is in xview-examples 3.2p1.4-28.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | /*
* dest.c - Example of how to register interest in receiving drag and drop
* events and how to complete a drag and drop operation.
*
*/
#include <stdio.h>
#include <xview/xview.h>
#include <xview/frame.h>
#include <xview/canvas.h>
#include <xview/panel.h>
#include <xview/font.h>
#include <xview/dragdrop.h>
#include <xview/xv_xrect.h>
#include <X11/Xlib.h>
#define DROP_WIDTH 65
#define DROP_HEIGHT 65
#define BULLSEYE_SITE 1
Frame frame;
Canvas canvas;
Panel panel;
Xv_drop_site drop_site;
Server_image drop_image;
Server_image drop_image_inv;
Panel_item p_string,
p_length,
p_host;
Selection_requestor sel;
int inverted;
main(argc, argv)
int argc;
char **argv;
{
void EventProc(),
PaintCanvas(),
ResizeCanvas();
Xv_Font font;
xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, 0);
frame = xv_create((Window)NULL, FRAME,
XV_X, 330,
XV_Y, 10,
XV_WIDTH, 10,
XV_LABEL, "Drag & Drop Destination",
0);
font = (Xv_Font)xv_find(frame, FONT, FONT_NAME, "lucida-12", NULL);
if (!font) {
fprintf(stderr, "Cannot use font: lucida-12.\n");
font = (Xv_Font)xv_get(frame, XV_FONT);
}
panel = xv_create(frame, PANEL,
PANEL_LAYOUT, PANEL_VERTICAL,
XV_FONT, font,
0);
p_string = xv_create(panel, PANEL_TEXT,
PANEL_LABEL_STRING, "Dropped Text:",
PANEL_VALUE_DISPLAY_LENGTH, 50,
0);
p_host = xv_create(panel, PANEL_TEXT,
PANEL_LABEL_STRING, "From host:",
PANEL_VALUE_DISPLAY_LENGTH, 15,
0);
p_length = xv_create(panel, PANEL_TEXT,
PANEL_LABEL_STRING, "Length:",
PANEL_VALUE_DISPLAY_LENGTH, 6,
0);
window_fit(panel);
canvas = xv_create(frame, CANVAS,
XV_HEIGHT, 100,
XV_WIDTH, WIN_EXTEND_TO_EDGE,
XV_X, 0,
WIN_BELOW, panel,
CANVAS_REPAINT_PROC, PaintCanvas,
CANVAS_RESIZE_PROC, ResizeCanvas,
CANVAS_X_PAINT_WINDOW, TRUE,
0);
xv_set(canvas_paint_window(canvas),
WIN_BIT_GRAVITY, ForgetGravity,
WIN_CONSUME_EVENTS,
WIN_RESIZE,
0,
WIN_EVENT_PROC, EventProc,
0);
drop_image = xv_create(NULL, SERVER_IMAGE,
SERVER_IMAGE_BITMAP_FILE, "./bullseye.bm",
0);
drop_image_inv = xv_create(NULL, SERVER_IMAGE,
SERVER_IMAGE_BITMAP_FILE, "./bullseyeI.bm",
0);
/* Selection requestor object that will be
* passed into dnd_decode_drop() and later used
* to make requests to the source of the
* drop.
*/
sel = xv_create(canvas, SELECTION_REQUESTOR, 0);
/* This application has one drop site with
* site id BULLSEYE_SITE and whose shape will
* be described by a rectangle. If
* animation is supported, it would like to
* receive LOC_DRAG, LOC_WINENTER and
* LOC_WINEXIT events.
*/
drop_site = xv_create(canvas_paint_window(canvas), DROP_SITE_ITEM,
DROP_SITE_ID, BULLSEYE_SITE,
DROP_SITE_EVENT_MASK, DND_ENTERLEAVE,
0);
inverted = False;
window_fit(frame);
xv_main_loop(frame);
exit(0);
}
void
EventProc(window, event)
Xv_Window window;
Event *event;
{
void PaintCanvas();
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 source's selection to our
* requestor selection object, we call
* dnd_decode_drop().
*/
if ((ds = dnd_decode_drop(sel, event)) != XV_ERROR) {
/* We can use the macro dnd_site_id() to access
* the site id of the drop site that was
* dropped on.
*/
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.
*/
if (event_action(event) == ACTION_DRAG_MOVE) {
int length, format;
xv_set(sel, SEL_TYPE_NAME, "DELETE", 0);
(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, 0);
string = (char *)xv_get(sel, SEL_DATA, &length, &format);
if (length != SEL_ERROR) {
xv_set(p_string, PANEL_VALUE, string, 0);
free (string);
}
xv_set(sel, SEL_TYPE, xv_get(server, SERVER_ATOM, "LENGTH"), 0);
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, 0);
free ((char *)string_length);
}
xv_set(sel, SEL_TYPE, xv_get(server, SERVER_ATOM, "HOST_NAME"), 0);
hostname = (char *)xv_get(sel, SEL_DATA, &length, &format);
if (length != SEL_ERROR) {
xv_set(p_host, PANEL_VALUE, hostname, 0);
free (hostname);
}
xv_set(sel, SEL_TYPE_NAME, "_SUN_SELECTION_END", 0);
(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;
{
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,
0);
}
|