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