⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test1.c

📁 安装DDD之前
💻 C
📖 第 1 页 / 共 2 页
字号:
/* $Header: /cvsroot/lesstif/lesstif/test/extra/daniel/test1.c,v 1.2 2002/05/15 10:55:06 amai Exp $ *//***********************************************************//* Copyright 1996 Daniel Dardailler.  Permission to use, copy, modify, distribute, and sell this softwarefor any purpose is hereby granted without fee, provided that the abovecopyright notice appear in all copies and that both that copyrightnotice and this permission notice appear in supporting documentation,and that the name of Daniel Dardailler not be used in advertising orpublicity pertaining to distribution of the software without specific,written prior permission.  Daniel Dardailler makes no representationsabout the suitability of this software for any purpose.  It isprovided "as is" without express or implied warranty.************************************************************/#include <stdlib.h>#include <stdio.h>#include <X11/Xlib.h>#include <X11/Intrinsic.h>#include <X11/StringDefs.h>#include <X11/Xos.h>#include <X11/Xatom.h>#include <X11/Shell.h>#include <X11/Xaw/Label.h>#include <X11/Xaw/Box.h>#include <X11/cursorfont.h>#include "Dnd.h"/************************************************************  This demo program creates two Aw labels, one is draggrable,   the other is a drop site (change the label when you drop)  It does a bunch of tracing.************************************************************/static void StartDrag(Widget w, XEvent *event,		      String *params, Cardinal *num_params);static Atom Dnd_wm_state, Dnd_selection, Dnd_transfer_success ;static Cursor valid_cursor, invalid_cursor;static String drag_trans = "<Btn2Down>: StartDrag()" ;static Atom my_targets[] = { XA_STRING } ;static Atom cv_targets[3] ;static XtPointer closures[3] ;static Boolean in_drag = False ;static Widget drag_label, drop_label, top_level, box ;static XtActionsRec drag_actions [] = {{"StartDrag", StartDrag}} ;static voidSelectTopLevels(        Display *dpy,        Window win){    Window 		root, parent;    Window 		*children;    unsigned int 	nchildren;    int		 	i;    Atom 		type = None;    int 		format;    unsigned long 	nitems, after;    unsigned char 	*data;    if (win != DefaultRootWindow(dpy)) {	/* only ask property kid of the root */	XGetWindowProperty(dpy, win, Dnd_wm_state , 0, 0, False, 			   AnyPropertyType,			   &type, &format, &nitems, &after, &data);	XFree(data);    } else {	printf ("WM_STATE on: ");    }     /* if the window has the WM_STATE property, select D&D events for it */    if (type) {	XSelectInput(dpy, win, EnterWindowMask | LeaveWindowMask		     | Button2MotionMask);	printf("%d ",win);    } else {	if (!XQueryTree(dpy, win, &root, &parent, &children, &nchildren) ||	    (nchildren == 0))	  return ;	for (i = nchildren - 1; i >= 0; i--) {	    SelectTopLevels(dpy, children[i]) ;	}	XFree(children);    }        if (win == DefaultRootWindow(dpy)) printf("\n----------\n");}static void ChangeCursorInvalid(Display * dpy, Time time){    printf("ChangeCursorInvalid\n");    XChangeActivePointerGrab(dpy, 			     ButtonMotionMask|ButtonReleaseMask|			     EnterWindowMask|LeaveWindowMask,			     invalid_cursor, time);}static void ChangeCursorValid(Display * dpy, Time time){    printf("ChangeCursorValid\n");    XChangeActivePointerGrab(dpy, 			     ButtonMotionMask|ButtonReleaseMask|			     EnterWindowMask|LeaveWindowMask,			     valid_cursor, time);}static void StartDrag(	  Widget	w,	  XEvent	*event,	  String *params, Cardinal *num_params){    printf("StartDrag\n");    /* grab the pointer so that we get all crossing events */    XGrabPointer(XtDisplay(w), DefaultRootWindow(XtDisplay(w)), True,		 ButtonMotionMask|ButtonReleaseMask|		 EnterWindowMask|LeaveWindowMask,		 GrabModeSync, GrabModeAsync,		 None, invalid_cursor,		 event->xbutton.time);    in_drag = True ;    XAllowEvents(XtDisplay(w), SyncPointer, event->xbutton.time);}static Boolean SourceConvert(        Widget w,        Atom *selection,        Atom *target,        Atom *type,        XtPointer *value,        unsigned long *length,        int *format ){    printf("SourceConvert %d %s\n", *target, 	   XGetAtomName(XtDisplay(w),*target));    if (*target == XA_STRING) {	String label ;	*type   = XA_STRING;	XtVaGetValues(drag_label, XtNlabel, &label, NULL);	*value = XtNewString(label);	*length = strlen(label);	printf("value %s length %d\n", *value, *length);	*format = 8;	return True;    } else     if (*target == Dnd_transfer_success) {	printf("transfer success\n");	*type   = Dnd_transfer_success;	*length = 0 ;	*value = NULL ;	*format = 32;	return True;    } else     if (*target == XInternAtom(XtDisplay(w), "DELETE", False)) {	*type = XInternAtom(XtDisplay(w), "NULL", False);	*value = NULL;	*length = 0;	*format = 8;	return True;    }  return False;}static void ReceiverConvert(        Widget w,        XtPointer client_data,	        Atom *selection,        Atom *type,		        XtPointer val,        unsigned long *length,	        int *format )		{    printf("ReceiverConvert selection %d %s\n",	   *selection, XGetAtomName(XtDisplay(w), *selection));    printf("type %d %s\n",*type, 	   (*type)?XGetAtomName(XtDisplay(w), *type):"00");    printf("format %d\n",*format);    printf("length %d\n",*length);    if (*type != 0 && *type != Dnd_transfer_success) {	XtVaSetValues(drop_label, XtNlabel, val, NULL);	/* copy data received in our drop site */	/* indicate success by asking the source to convert 	   XmTRANSFER_SUCCESS */	XtGetSelectionValue(w, *selection,			    Dnd_transfer_success, ReceiverConvert, NULL, 			    CurrentTime);	/* we should get called again with this target */    }     /* else, got transfer success back, free whatever we want */ /* Note: I get some weird     Warning:       Name: dd      Class: ApplicationShell      We lost the drop selection    on a (real) Motif initiator side when I get to this point...     No time to investigate right now */    }intmain(argc, argv)	int argc;	char **argv;{    XtAppContext app_context;    unsigned char src_protocol_style = DND_DRAG_DYNAMIC ;    char my_dnd_selection_name[30] ;    Boolean do_messaging = False, do_drop = False, in_drop_site = False ;    Window cur_window = 0 ;    Atom * src_targets ;    unsigned short num_src_targets ;    Position dropx, dropy ;    Dimension dropw, droph ;    top_level = XtVaAppInitialize(&app_context, "DndTest", 				  NULL, 0, &argc, argv, NULL, 				  XtNallowShellResize, True, NULL);     XtAppAddActions(app_context, (XtActionList)drag_actions, 		    XtNumber(drag_actions));    /* Init atoms */    Dnd_wm_state =   XInternAtom(XtDisplay(top_level), "WM_STATE", False);    Dnd_transfer_success =   XInternAtom(XtDisplay(top_level), 					 "XmTRANSFER_SUCCESS", False);    /* This one needs to be unique for each drag, not just for each client,       as there can be race condition with drag transfer not finish while       another drag is started */    sprintf(my_dnd_selection_name, "_MY_DND_SELECTION_%d", getpid());    Dnd_selection =  XInternAtom(XtDisplay(top_level), 				 my_dnd_selection_name, False);    invalid_cursor = XCreateFontCursor(XtDisplay(top_level),XC_pirate);    valid_cursor = XCreateFontCursor(XtDisplay(top_level), XC_target);    box = XtCreateManagedWidget("box",				boxWidgetClass, top_level, NULL, 0);    drag_label = XtVaCreateManagedWidget("drag",				  labelWidgetClass, box, NULL);    XtOverrideTranslations(drag_label, XtParseTranslationTable(drag_trans));    drop_label = XtVaCreateManagedWidget("drop",				    labelWidgetClass, box, NULL);    XtRealizeWidget(top_level); /* need the windows right below */     /* register as a drag source. In real life, one would have to 	update the property per drag source, for real target indication */    DndWriteSourceProperty(XtDisplay(top_level), XtWindow(top_level),			   Dnd_selection, my_targets, 1);    /* gotta be ready to convert our selection - same thing */    XtOwnSelection(top_level, Dnd_selection, CurrentTime, 		   SourceConvert, NULL, NULL);		     if (argc > 1) {	if (strcmp(argv[1], "none") == 0) 	    src_protocol_style = DND_DRAG_NONE ;	else	if (strcmp(argv[1], "drop_only") == 0) 	    src_protocol_style = DND_DRAG_DROP_ONLY;	else	if (strcmp(argv[1], "dynamic") == 0) 	    src_protocol_style = DND_DRAG_DYNAMIC ;    }    /* register the top_level as a drop site too */    DndWriteReceiverProperty(XtDisplay(top_level), XtWindow(top_level),			     src_protocol_style);    /* really just need to be done on start drag (and tracked too as window       are added, destroyed. Motif uses private properties to find these */    SelectTopLevels(XtDisplay(top_level), 		   DefaultRootWindow(XtDisplay(top_level)));     /* for now use my own loop for tracking events directly,        rather messy... */    while(1) {	XEvent event ;	unsigned char receiv_protocol_style;	XClientMessageEvent cm ;	DndData dnd_data ;	char receiver ;	XtAppNextEvent(app_context, &event);	switch(event.type) {	case EnterNotify:	    if (!in_drag) break ;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -