CutPaste.c revision 8f65982a
1/* 2 3Copyright 1989, 1998 The Open Group 4 5Permission to use, copy, modify, distribute, and sell this software and its 6documentation for any purpose is hereby granted without fee, provided that 7the above copyright notice appear in all copies and that both that 8copyright notice and this permission notice appear in supporting 9documentation. 10 11The above copyright notice and this permission notice shall be included 12in all copies or substantial portions of the Software. 13 14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 18OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20OTHER DEALINGS IN THE SOFTWARE. 21 22Except as contained in this notice, the name of The Open Group shall 23not be used in advertising or otherwise to promote the sale, use or 24other dealings in this Software without prior written authorization 25from The Open Group. 26 27*/ 28/* 29 * Author: Davor Matic, MIT X Consortium 30 */ 31 32#include <X11/IntrinsicP.h> 33#include <X11/Xmu/StdSel.h> 34#include <X11/Xmu/Atoms.h> 35#include <X11/Xatom.h> 36#include "ScaleP.h" /* This file should be part of the Scale widget */ 37#include "Scale.h" 38#include "CutPaste.h" 39#include <stdio.h> 40 41 42/*ARGSUSED*/ 43static Boolean 44ConvertSelection(Widget w, Atom *selection, Atom *target, Atom *type, 45 XtPointer *value, unsigned long *length, int *format) 46{ 47 Boolean success; 48 49 if (*target == XA_PIXMAP || *target == XA_BITMAP) { 50 ScaleWidget sw = (ScaleWidget) w; 51 Pixmap *pixmap = (Pixmap *) XtMalloc(sizeof(Pixmap)); 52 *pixmap = XCreatePixmap(XtDisplay(w), XtWindow(w), 53 sw->scale.image->width, 54 sw->scale.image->height, 55 sw->scale.image->depth); 56 XPutImage(XtDisplay(w), *pixmap, sw->scale.gc, sw->scale.image, 57 0, 0, 0, 0, sw->scale.image->width, sw->scale.image->height); 58 *type = XA_PIXMAP; 59 *value = (XtPointer) pixmap; 60 *length = 1; 61 *format = 32; 62 success = True; 63 } else { 64 /* Xt will always respond to selection requests for the TIMESTAMP 65 target, so we can pass a bogus time to XmuConvertStandardSelection. 66 In addition to the targets provided by XmuConvertStandardSelection, 67 Xt converts MULTIPLE, and we convert PIXMAP and BITMAP. 68 */ 69 success = XmuConvertStandardSelection(w, (Time)0, selection, target, 70 type, (XPointer *)value, length, 71 format); 72 if (success && *target == XA_TARGETS(XtDisplay(w))) { 73 Atom* tmp; 74 tmp = (Atom *) XtRealloc(*value, (*length + 3) * sizeof(Atom)); 75 tmp[(*length)++] = XInternAtom(XtDisplay(w), "MULTIPLE", False); 76 tmp[(*length)++] = XA_PIXMAP; 77 tmp[(*length)++] = XA_BITMAP; 78 *value = (XtPointer) tmp; 79 } 80 } 81 return success; 82} 83 84void 85SWGrabSelection(Widget w, Time time) 86{ 87 (void) XtOwnSelection(w, XA_PRIMARY, time, ConvertSelection, NULL, NULL); 88} 89 90 91/*ARGSUSED*/ 92static void 93SelectionCallback(Widget w, XtPointer client_data, Atom *selection, 94 Atom *type, XtPointer value, unsigned long *length, 95 int *format) 96{ 97 98 if (*type == XA_PIXMAP) { 99 Pixmap *pixmap; 100 XImage *image; 101 Window root; 102 int x, y; 103 unsigned int width, height, border_width, depth; 104 105 pixmap = (Pixmap *) value; 106 XGetGeometry(XtDisplay(w), *pixmap, &root, &x, &y, 107 &width, &height, &border_width, &depth); 108 image = XGetImage(XtDisplay(w), *pixmap, 0, 0, width, height, 109 AllPlanes, ZPixmap); 110 SWAutoscale(w, NULL, NULL, NULL); 111 SWSetImage(w, image); 112 XtFree(value); 113 XDestroyImage(image); 114 } 115} 116 117void 118SWRequestSelection(Widget w, Time time) 119{ 120 XtGetSelectionValue(w, XA_PRIMARY, XA_PIXMAP, SelectionCallback, NULL, 121 time); 122} 123