CutPaste.c revision 0c7e83b2
19aa228fdSmrg/*
29aa228fdSmrg
39aa228fdSmrgCopyright 1989, 1998  The Open Group
49aa228fdSmrg
59aa228fdSmrgPermission to use, copy, modify, distribute, and sell this software and its
69aa228fdSmrgdocumentation for any purpose is hereby granted without fee, provided that
79aa228fdSmrgthe above copyright notice appear in all copies and that both that
89aa228fdSmrgcopyright notice and this permission notice appear in supporting
99aa228fdSmrgdocumentation.
109aa228fdSmrg
119aa228fdSmrgThe above copyright notice and this permission notice shall be included
129aa228fdSmrgin all copies or substantial portions of the Software.
139aa228fdSmrg
149aa228fdSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
159aa228fdSmrgOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
169aa228fdSmrgMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
179aa228fdSmrgIN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
189aa228fdSmrgOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
199aa228fdSmrgARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
209aa228fdSmrgOTHER DEALINGS IN THE SOFTWARE.
219aa228fdSmrg
229aa228fdSmrgExcept as contained in this notice, the name of The Open Group shall
239aa228fdSmrgnot be used in advertising or otherwise to promote the sale, use or
249aa228fdSmrgother dealings in this Software without prior written authorization
259aa228fdSmrgfrom The Open Group.
269aa228fdSmrg
279aa228fdSmrg*/
289aa228fdSmrg/*
299aa228fdSmrg * Author:  Davor Matic, MIT X Consortium
309aa228fdSmrg */
319aa228fdSmrg
329aa228fdSmrg#include <X11/IntrinsicP.h>
339aa228fdSmrg#include <X11/Xmu/StdSel.h>
349aa228fdSmrg#include <X11/Xmu/Atoms.h>
359aa228fdSmrg#include <X11/Xatom.h>
369aa228fdSmrg#include "ScaleP.h"	/* This file should be part of the Scale widget */
379aa228fdSmrg#include "Scale.h"
389aa228fdSmrg#include "CutPaste.h"
399aa228fdSmrg#include <stdio.h>
409aa228fdSmrg
419aa228fdSmrg
429aa228fdSmrg/*ARGSUSED*/
439aa228fdSmrgstatic Boolean
440c7e83b2SmrgConvertSelection(Widget w, Atom *selection, Atom *target, Atom *type,
459aa228fdSmrg		 XtPointer *value, unsigned long *length, int *format)
469aa228fdSmrg{
479aa228fdSmrg    Boolean success;
489aa228fdSmrg
499aa228fdSmrg    if (*target == XA_PIXMAP || *target == XA_BITMAP) {
509aa228fdSmrg	ScaleWidget sw = (ScaleWidget) w;
519aa228fdSmrg	Pixmap *pixmap = (Pixmap *) XtMalloc(sizeof(Pixmap));
529aa228fdSmrg	*pixmap = XCreatePixmap(XtDisplay(w), XtWindow(w),
530c7e83b2Smrg				sw->scale.image->width,
540c7e83b2Smrg				sw->scale.image->height,
559aa228fdSmrg				sw->scale.image->depth);
569aa228fdSmrg	XPutImage(XtDisplay(w), *pixmap, sw->scale.gc, sw->scale.image,
579aa228fdSmrg		  0, 0, 0, 0, sw->scale.image->width, sw->scale.image->height);
589aa228fdSmrg	*type = XA_PIXMAP;
599aa228fdSmrg	*value = (XtPointer) pixmap;
609aa228fdSmrg	*length = 1;
619aa228fdSmrg	*format = 32;
629aa228fdSmrg	success = True;
639aa228fdSmrg    } else {
649aa228fdSmrg	/* Xt will always respond to selection requests for the TIMESTAMP
659aa228fdSmrg	   target, so we can pass a bogus time to XmuConvertStandardSelection.
669aa228fdSmrg	   In addition to the targets provided by XmuConvertStandardSelection,
679aa228fdSmrg	   Xt converts MULTIPLE, and we convert PIXMAP and BITMAP.
689aa228fdSmrg	 */
699aa228fdSmrg	success = XmuConvertStandardSelection(w, (Time)0, selection, target,
709aa228fdSmrg					      type, (XPointer *)value, length,
719aa228fdSmrg					      format);
729aa228fdSmrg	if (success && *target == XA_TARGETS(XtDisplay(w))) {
739aa228fdSmrg	    Atom* tmp;
749aa228fdSmrg	    tmp = (Atom *) XtRealloc(*value, (*length + 3) * sizeof(Atom));
759aa228fdSmrg	    tmp[(*length)++] = XInternAtom(XtDisplay(w), "MULTIPLE", False);
769aa228fdSmrg	    tmp[(*length)++] = XA_PIXMAP;
779aa228fdSmrg	    tmp[(*length)++] = XA_BITMAP;
789aa228fdSmrg	    *value = (XtPointer) tmp;
799aa228fdSmrg	}
809aa228fdSmrg    }
819aa228fdSmrg    return success;
829aa228fdSmrg}
839aa228fdSmrg
840c7e83b2Smrgvoid
859aa228fdSmrgSWGrabSelection(Widget w, Time time)
869aa228fdSmrg{
879aa228fdSmrg    (void) XtOwnSelection(w, XA_PRIMARY, time, ConvertSelection, NULL, NULL);
889aa228fdSmrg}
899aa228fdSmrg
909aa228fdSmrg
919aa228fdSmrg/*ARGSUSED*/
929aa228fdSmrgstatic void
930c7e83b2SmrgSelectionCallback(Widget w, XtPointer client_data, Atom *selection,
940c7e83b2Smrg		  Atom *type, XtPointer value, unsigned long *length,
959aa228fdSmrg		  int *format)
969aa228fdSmrg{
979aa228fdSmrg
989aa228fdSmrg    if  (*type == XA_PIXMAP) {
999aa228fdSmrg	Pixmap *pixmap;
1009aa228fdSmrg	XImage *image;
1019aa228fdSmrg	Window root;
1029aa228fdSmrg	int x, y;
1039aa228fdSmrg	unsigned int width, height, border_width, depth;
1049aa228fdSmrg
1059aa228fdSmrg	pixmap = (Pixmap *) value;
1069aa228fdSmrg	XGetGeometry(XtDisplay(w), *pixmap, &root, &x, &y,
1079aa228fdSmrg		     &width, &height, &border_width, &depth);
1080c7e83b2Smrg	image = XGetImage(XtDisplay(w), *pixmap, 0, 0, width, height,
1099aa228fdSmrg			  AllPlanes, ZPixmap);
1109aa228fdSmrg	SWAutoscale(w, NULL, NULL, NULL);
1119aa228fdSmrg	SWSetImage(w, image);
1129aa228fdSmrg	XtFree(value);
1139aa228fdSmrg	XDestroyImage(image);
1149aa228fdSmrg    }
1159aa228fdSmrg}
1169aa228fdSmrg
1170c7e83b2Smrgvoid
1189aa228fdSmrgSWRequestSelection(Widget w, Time time)
1199aa228fdSmrg{
1209aa228fdSmrg    XtGetSelectionValue(w, XA_PRIMARY, XA_PIXMAP, SelectionCallback, NULL,
1219aa228fdSmrg			time);
1229aa228fdSmrg}
123