home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / clients / xmag / CutPaste.c next >
Encoding:
C/C++ Source or Header  |  1991-07-19  |  4.2 KB  |  166 lines

  1. /*
  2.  * $XConsortium: CutPaste.c,v 1.3 91/07/19 18:29:10 dave Exp $
  3.  *
  4.  * Copyright 1989 Massachusetts Institute of Technology
  5.  *
  6.  * Permission to use, copy, modify, distribute, and sell this software and its
  7.  * documentation for any purpose is hereby granted without fee, provided that
  8.  * the above copyright notice appear in all copies and that both that
  9.  * copyright notice and this permission notice appear in supporting
  10.  * documentation, and that the name of M.I.T. not be used in advertising or
  11.  * publicity pertaining to distribution of the software without specific,
  12.  * written prior permission.  M.I.T. makes no representations about the
  13.  * suitability of this software for any purpose.  It is provided "as is"
  14.  * without express or implied warranty.
  15.  *
  16.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  17.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  18.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  21.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  *
  23.  * Author:  Davor Matic, MIT X Consortium
  24.  */
  25.  
  26. #include <stdio.h>
  27. #include <X11/Xatom.h>
  28. #include <X11/IntrinsicP.h>
  29. #include "ScaleP.h"
  30. #include "Scale.h"
  31.  
  32. #define XtStrlen(s) ((s) ? strlen(s) : 0)
  33.  
  34. extern Pixmap SWGetPixmap();
  35.  
  36. /* ARGSUSED */
  37. Boolean ConvertSelection(w, selection, target, type, vret, length, format)
  38.     Widget w;
  39.     Atom *selection, *target, *type;
  40.     XtPointer *vret;
  41.     unsigned long *length;
  42.     int *format;
  43. {
  44.     caddr_t *value = (caddr_t *)vret;
  45.     ScaleWidget sw = (ScaleWidget) w;
  46.     Pixmap *pixmap;
  47.  
  48.     switch (*target) {
  49. /*
  50.     case XA_TARGETS:
  51.     *type = XA_ATOM;
  52.     *value = (caddr_t) scaleClassRec.scale_class.targets;
  53.     *length = scaleClassRec.scale_class.num_targets;
  54.     *format = 32;
  55.     return True;
  56. */
  57.  
  58.     case XA_PIXMAP:
  59.     case XA_BITMAP:
  60.     pixmap = (Pixmap *) XtMalloc(sizeof(Pixmap));
  61.     *pixmap = XCreatePixmap(XtDisplay(w), XtWindow(w),
  62.                 sw->scale.image->width, 
  63.                 sw->scale.image->height, 
  64.                 sw->scale.image->depth);
  65.     XPutImage(XtDisplay(w), *pixmap, sw->scale.gc, sw->scale.image,
  66.           0, 0, 0, 0, sw->scale.image->width, sw->scale.image->height);
  67.     *type = XA_PIXMAP;
  68.     *value = (caddr_t) pixmap;
  69.     *length = 1;
  70.     *format = 32;
  71.     return True;
  72.     
  73.     case XA_STRING:
  74.     *type = XA_STRING;
  75.     *value = (caddr_t)"Hello world!";
  76.     *length = XtStrlen(*value);
  77.     *format = 8;
  78.     return True;
  79.     
  80.     default:
  81.     return False;
  82.     }
  83. }
  84.  
  85. /* ARGSUSED */
  86. void LoseSelection(w, selection)
  87.     Widget w;
  88.     Atom *selection;
  89. {
  90.  
  91.     /*fprintf(stderr, "Lost Selection\n");*/
  92. }
  93.  
  94. /* ARGSUSED */
  95. void SelectionDone(w, selection, target)
  96.     Widget w;
  97.     Atom *selection, *target;
  98. {
  99. /*  
  100.     ScaleWidget sw = (ScaleWidget) w;
  101.     if (*target != XA_TARGETS)
  102.     XtFree(sw->scale.value);
  103. */
  104. }
  105.  
  106. void SWGrabSelection(w, time)
  107.     Widget w;
  108.     Time time;
  109. {
  110.     
  111.     if (XtOwnSelection(w, XA_PRIMARY, time,
  112.                ConvertSelection, LoseSelection, SelectionDone))
  113.  
  114.         /*fprintf(stderr, "Own the selection\n")*/;
  115. }
  116.  
  117. /* ARGSUSED */
  118. void SelectionCallback(w, clientData, selection, type, v, length, format)
  119.     Widget w;
  120.     XtPointer clientData; 
  121.     Atom *selection, *type;
  122.     XtPointer v;
  123.     unsigned long *length;
  124.     int *format;
  125. {
  126.     caddr_t value = (caddr_t)v;
  127.     Pixmap *pixmap;
  128.     XImage *image;
  129.     Window root;
  130.     int x, y;
  131.     unsigned int width, height, border_width, depth;
  132.  
  133.     switch (*type) {
  134.     
  135.     case XA_PIXMAP:
  136.     pixmap = (Pixmap *) value;
  137.     XGetGeometry(XtDisplay(w), *pixmap, &root, &x, &y,
  138.              &width, &height, &border_width, &depth);
  139.     image = XGetImage(XtDisplay(w), *pixmap, 0, 0, width, height, 
  140.               AllPlanes, ZPixmap);
  141.     SWAutoscale(w);
  142.     SWSetImage(w, image);
  143.     XFree((char *)pixmap);
  144.     XDestroyImage(image);
  145.     break;
  146.     
  147.     case XA_STRING:
  148.         /*fprintf(stderr, "Received:%s\n", value);*/
  149.     break;
  150.  
  151.     default:
  152.     XtWarning(" selection request failed.  ScaleWidget");
  153.     break;
  154.     }
  155. }
  156.  
  157. void SWRequestSelection(w, time)
  158.     Widget w;
  159.     Time time;
  160. {
  161.     /*fprintf(stderr, "------------------------------------------>\n");*/
  162.     XtGetSelectionValue(w, XA_PRIMARY, XA_PIXMAP,
  163.             SelectionCallback, NULL, time);
  164. }
  165.  
  166.