home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1992, 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- #include <stdio.h>
-
- #include <X11/Intrinsic.h>
- #include <X11/StringDefs.h>
- #include <X11/Xatom.h>
- #include <X11/Xmu/Atoms.h>
- #include <X11/Xmu/StdSel.h>
-
- extern char *getSelection();
- char *xferSelection;
- extern short xRot, yRot;
-
- void LoseSelection();
-
- void SelValue();
- void TarValue();
-
- Boolean ConvertSelection();
-
- /* This is defined in X11/Xmu/Atomms.h
- * #define XA_CLIPBOARD(d) XInternAtom((d),"CLIPBOARD",False)
- */
-
- /* This was for playing around with Motif XmRString
- * Note XmRString != XA_STRING
- * #define XA_STRING2(d) XInternAtom((d),"String",False)
- */
-
- #define MXCHARS 30
-
- char *theSelection=NULL; /* the selection - mol as text */
- char *augSelection=NULL; /* the augmented selection - mol + rotation */
-
-
- /*
- * pasteCB()
- * paste call back
- *
- * request the data as a string
- */
- void pasteCB(Widget w) {
-
- Display *d = XtDisplay(w);
- Time time_of_request = XtLastTimestampProcessed(d);
-
- #ifdef EBUG
- fprintf(stderr,"in Paste\n");
-
- /* Get the timestamp value, just to try it */
- XtGetSelectionValue(w, XA_CLIPBOARD(d),
- XA_TIMESTAMP(d),
- TarValue,
- NULL,
- time_of_request);
-
- /* Playing with compatibility */
- XtGetSelectionValue(w, XA_CLIPBOARD(d),
- XA_STRING2(d),
- SelValue,
- NULL,
- time_of_request);
-
- #endif
-
- /* Get the targets values... could check which
- * targets are available and choose best suited for
- * this app, but this app only takes "STRING"
- */
- XtGetSelectionValue(w, XA_CLIPBOARD(d),
- XA_TARGETS(d),
- TarValue,
- NULL,
- time_of_request);
-
- /* Go ahead and get the String */
- XtGetSelectionValue(w, XA_CLIPBOARD(d),
- XA_STRING,
- SelValue,
- NULL,
- time_of_request);
-
- }
-
-
- void copyCB(Widget w) {
- int rv, incr;
- char arot[MXCHARS];
- Display *d = XtDisplay(w);
- Time time_of_request = XtLastTimestampProcessed(d);
-
- if (theSelection)
- free(theSelection);
- if (augSelection)
- free(augSelection);
- theSelection = getSelection();
- if (theSelection == NULL) {
- #ifdef EBUG
- fprintf(stderr,"Nothing selected\n");
- #endif
- XBell( d, 0);
- } else {
-
- #ifdef EBUG
- fprintf(stderr,"theSelection %s\n",theSelection);
- printf("\n%s\n", theSelection);
- #endif
-
- sprintf(arot,"_MOL\n%d\n%d\n",xRot,yRot);
- incr = strlen(arot);
- augSelection = (char *)malloc(sizeof(char)*strlen(theSelection)+incr+1);
- sprintf(augSelection,"%s%s",arot,theSelection);
- rv = XtOwnSelection(w, XA_CLIPBOARD(d), time_of_request, ConvertSelection, LoseSelection, NULL);
-
- if (rv == True) {
- #ifdef EBUG
- fprintf(stderr,"own selection %d\n",XA_CLIPBBOARD(d));
- #endif
- ;
- } else {
- XBell( d, 0);
- #ifdef EBUG
- fprintf(stderr,"not own selection %d\n",XA_CLIPBOARD(d));
- #endif
- }
-
-
- }
- }
-
- void LoseSelection(Widget w, Atom *selection)
- {
- #ifdef EBUG
- fprintf(stderr,"Giving up selection\n");
- #endif
- }
-
- Boolean ConvertSelection(Widget w,Atom *selection, Atom *target,
- Atom *type, caddr_t *value, unsigned long *length, int *format)
- {
- Display* d = XtDisplay(w);
- XSelectionRequestEvent* req =
- XtGetSelectionRequest(w, *selection, (XtRequestId)NULL);
-
- #ifdef EBUG
- fprintf(stderr,"In ConvertSelection\n");
- #endif
-
- if (*target == XA_TARGETS(d)) {
- Atom* targetP;
- Atom* std_targets;
- unsigned long std_length;
- XmuConvertStandardSelection(w, req->time, selection, target, type,
- (caddr_t*)&std_targets, &std_length, format);
- *value = XtMalloc(sizeof(Atom)*(std_length + 5));
- targetP = *(Atom**)value;
- *targetP++ = XA_STRING;
- *targetP++ = XA_TEXT(d);
- *targetP++ = XA_LENGTH(d);
- *targetP++ = XA_LIST_LENGTH(d);
- *targetP++ = XA_CHARACTER_POSITION(d);
- *length = std_length + (targetP - (*(Atom **) value));
- bcopy((char*)std_targets, (char*)targetP, sizeof(Atom)*std_length);
- XtFree((char*)std_targets);
- *type = XA_ATOM;
- *format = 32;
-
- return True;
- }
-
- if (*target == XA_LIST_LENGTH(d) ||
- *target == XA_LENGTH(d))
- {
- long * temp;
-
- temp = (long *) XtMalloc(sizeof(long));
- if (*target == XA_LIST_LENGTH(d))
- *temp = 1L;
- else /* *target == XA_LENGTH(d) */
- *temp = (long) strlen (augSelection);
-
- *value = (caddr_t) temp;
- *type = XA_INTEGER;
- *length = 1L;
- *format = 32;
- return True;
- }
-
- if (*target == XA_CHARACTER_POSITION(d))
- {
- long * temp;
-
- temp = (long *) XtMalloc(2 * sizeof(long));
- temp[0] = (long) 0;
- temp[1] = strlen (augSelection);
- *value = (caddr_t) temp;
- *type = XA_SPAN(d);
- *length = 2L;
- *format = 32;
- return True;
- }
-
- if (*target == XA_STRING ||
- *target == XA_TEXT(d) ||
- *target == XA_COMPOUND_TEXT(d))
- {
- if (*target == XA_COMPOUND_TEXT(d))
- *type = *target;
- else
- *type = XA_STRING;
- if (*selection == XA_CLIPBOARD(d) ) {
-
- *length = strlen(augSelection);
- *value =XtMalloc(sizeof(char)*(*length+1));
- strcpy(*value,augSelection);
-
- } else {
- *length = strlen (augSelection);
- *value = augSelection;
- fprintf(stderr,"value with 0 %s\n",value);
- *value = augSelection;
- fprintf(stderr,"value with 1 %s\n",value);
- }
- *format = 8;
- return True;
- }
-
- if (XmuConvertStandardSelection(w, req->time, selection, target, type,
- value, length, format))
- return True;
-
- return False;
-
- }
-
- void
- SelValue(Widget w, caddr_t client_data, Atom *selection, Atom *type,
- caddr_t value, unsigned long *length, int *format)
- {
- char *cptr;
- char axRot[MXCHARS], ayRot[MXCHARS];
- char head[MXCHARS];
- int i,j,k;
-
- if (*type == 0 /*XT_CONVERT_FAIL */ || *length ==0) {
- XBell( XtDisplay(w), 0);
- return;
- } else {
-
- /* got value, so interpret "_MOL" format */
- cptr = value;
- i = 0;
- while ((*(cptr+i) != '\n') && (i<MXCHARS)) {
- head[i++] = *(cptr+i);
- }
- head[i] = '\0';
- i++;
- if ( strcmp(head,"_MOL") ) {
- XBell( XtDisplay(w), 0);
- fprintf(stderr,"Paste not in _MOL format\n");
- return;
- }
-
- j=0;
- while ((*(cptr+i) != '\n') && (j<MXCHARS)) {
- axRot[j++] = *(cptr+i);
- i++;
- }
- axRot[j] = '\0';
- i++;
-
- k = 0;
- while ((*(cptr+i) != '\n') && (k<MXCHARS)) {
- ayRot[k++] = *(cptr+i);
- i++;
- }
- ayRot[k] = '\0';
- i++;
-
- xRot = (short) atoi(axRot);
- yRot = (short) atoi(ayRot);
-
-
- *length = strlen(value+i);
- xferSelection =(char *)XtMalloc(sizeof(char)*(*length+1));
- strcpy(xferSelection, (char *) (value+i));
- #ifdef EBUG
- fprintf(stderr,"xferSelection %s\n",xferSelection);
- #endif
- XtFree(value);
-
- buildMolecule(xferSelection);
-
- drawScene();
- return ;
- }
- }
-
-
- void
- TarValue(Widget w, caddr_t client_data, Atom *selection, Atom *type,
- caddr_t value, unsigned long *length, int *format)
- {
- int i,ii;
- Atom* targetP;
-
- if (*type == 0 /*XT_CONVERT_FAIL */ || *length ==0) {
- XBell( XtDisplay(w), 0);
- return;
- } else {
- targetP = (Atom *)value;
- fprintf(stderr,">>%d targets\n",*length);
- for (i=0; i< *length; i++) {
- ii = *targetP++;
- fprintf(stderr,"target %d is %d\n",i,ii);
- }
- fprintf(stderr,">>end targets\n");
- }
- return;
- }
-
-
- void cutCB(Widget w) {
- int rv, incr;
- char arot[MXCHARS];
- Display *d = XtDisplay(w);
- Time time_of_request = XtLastTimestampProcessed(d);
- char *empty;
-
- if (theSelection)
- free(theSelection);
- if (augSelection)
- free(augSelection);
- theSelection = getSelection();
- if (theSelection == NULL) {
- XBell( d, 0);
- #ifdef EBUG
- fprintf(stderr,"Nothing selected\n");
- #endif
- } else {
-
- #ifdef EBUG
- fprintf(stderr,"theSelection %s\n",theSelection);
- printf("\n%s\n", theSelection);
- #endif
-
- sprintf(arot,"_MOL\n%d\n%d\n",xRot,yRot);
- incr = strlen(arot);
- augSelection = (char *)malloc(sizeof(char)*strlen(theSelection)+incr+1);
- sprintf(augSelection,"%s%s",arot,theSelection);
- rv = XtOwnSelection(w, XA_CLIPBOARD(d), time_of_request, ConvertSelection, LoseSelection, NULL);
-
- if (rv == True) {
- #ifdef EBUG
- fprintf(stderr,"own selection\n");
- #endif
- ;
- } else {
- XBell( d, 0);
- #ifdef EBUG
- fprintf(stderr,"not own selection\n");
- #endif
- }
-
-
- }
-
-
- /* now draw no molecules */
- empty = (char *)malloc(sizeof(char));
- *empty = '\0';
- buildMolecule(empty);
-
- drawScene();
- return ;
-
- }
-
- void quitCB(Widget w) {
- Display *d = XtDisplay(w);
-
- XtCloseDisplay(d);
- exit(0);
- }
-