Xref: utzoo comp.windows.open-look:1139 alt.toolkits.xview:168 comp.windows.x:34979 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!think.com!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!winsoft!leif From: leif@winsoft.se (Leif Samuelsson) Newsgroups: comp.windows.open-look,alt.toolkits.xview,comp.windows.x Subject: Re: ICC with OpenLook Desktop print tool Message-ID: <157@winsoft.SE> Date: 7 Apr 91 15:53:41 GMT References: <25276@ttidca.TTI.COM> Followup-To: comp.windows.open-look Organization: Winsoft Data AB, Solna, Sweden Lines: 213 In article <25276@ttidca.TTI.COM> kevin@drogges.tti.com writes: >whew! Now MY question: > > does anybody know how I can DUPLICATE" the drag-n-drop protocol sequence above > without actually *DOING* a drag-n-drop, such that printtool will act on the > XClientMessage? I had the same need with PageView a while back and came up with the following program. It sends an ACTION_DRAG_LOAD event to the receiving application and passes on a filename. It is a bit kludgey and will most definitely not work on any version of OpenWindows other than 2.0. It can be used with other applications as well, the problem is just to find out which subwindow to send the message to. I suggest using xlswins for browsing. Does anyone know of an easier way of finding the id of the receiving window? ---- Leif Samuelsson Winsoft Data AB Phone: +46 8 7301240 Lidgatan 18 Fax: +46 8 7303102 S-171 58 SOLNA E-mail: leif@winsoft.se Sweden ----Cut---here---- /* * dragload.c -- Send an ACTION_DRAG_LOAD event to predefined application * * Only works with OpenWindows 2.0 * * Compile with: cc -o dragload dragload.c -lxview -lolgx -lX11 */ #include #include enum apptype { PageView, PrintTool }; enum apptype app = PrintTool; char *filename; static Seln_result request_proc(); static Window get_child_by_name(), get_nth_child(); main(argc, argv) int argc; char *argv[]; { Frame frame; Window window = 0; Window root, w; Display *dpy; Seln_client client; int data[4]; if (argc != 2) { fprintf(stderr, "Usage: %s filename\n", argv[0]); exit(1); } filename = argv[1]; /* Create a frame just to make XView happy */ frame = xv_create(0, FRAME, 0); dpy = (Display *)xv_get(frame, XV_DISPLAY); root = (Window)xv_get(xv_get(frame, XV_ROOT), XV_XID); /* Now find the window to send the event to */ switch (app) { case PageView: window = get_child_by_name(dpy, root, "PageView"); if (window) window = get_nth_child(dpy, window, 1); if (window) window = get_nth_child(dpy, window, 0); if (window) window = get_nth_child(dpy, window, 0); break; case PrintTool: window = get_child_by_name(dpy, root, "Print Tool"); if (window) window = get_nth_child(dpy, window, 0); break; default: fprintf(stderr, "%s: Unknown application.\n", argv[0]); exit(1); } if (!window) { fprintf(stderr, "%s: Can not talk to application.\n", argv[0]); exit(1); } /* Set up selection service */ client = seln_create(0, request_proc, &client); seln_acquire(client, SELN_PRIMARY); /* Send the event */ data[0] = window; data[3] = xv_get(frame, XV_XID); xv_send_message(frame, window, "XV_DO_DRAG_LOAD", 32, data, 16); notify_start(); } static Window get_child_by_name(dpy, w, name) /* Recursively search tree for win by name */ Display *dpy; Window w; char *name; { Window root, parent; Window *children; int i, nchildren; char *win_name; XQueryTree(dpy, w, &root, &parent, &children, &nchildren); for (i = 0; i < nchildren; i++) { w = children[i]; if (XFetchName(dpy, w, &win_name)) { if (!strcmp(win_name, name)) { XFree(win_name); XFree(children); return (w); } XFree(win_name); } w = get_child_by_name(dpy, w, name); /* recursive call */ if (w) { XFree(children); return (w); } } XFree(children); return ((Window)NULL); } static Window get_nth_child(dpy, w, i) /* Return child i of window w */ Display *dpy; Window w; int i; { Window root, parent; Window *children; int nchildren; XQueryTree(dpy, w, &root, &parent, &children, &nchildren); if (nchildren > i) w = children[i]; else w = (Window)NULL; XFree(children); return (w); } static Seln_result request_proc(attr, context, max_length) int attr; Seln_replier_data *context; int max_length; { int i; static char buf[256]; char *p; switch (attr) { case SELN_REQ_BYTESIZE: *context->response_pointer++ = (char *)strlen(filename); return SELN_SUCCESS; case SELN_REQ_CONTENTS_ASCII: strcpy(context->response_pointer, filename); context->response_pointer += strlen(filename) / 4; if ((strlen(filename) % 4) > 0) context->response_pointer++; *context->response_pointer++ = 0; /* Null terminate value */ return SELN_SUCCESS; case SELN_REQ_END_REQUEST: notify_stop(); return SELN_FAILED; case SELN_REQ_IS_READONLY: return SELN_FAILED; default: printf("request_proc 0x%x 0x%x %d\n", attr, context, max_length); fflush(stdout); return SELN_FAILED; } /*NOTREACHED*/ }