static Boolean nav_sel_convert_cb(
    Widget  w,
    Atom    *selection,
    Atom    *target,
    Atom    *type_return,
    XtPointer	*value_return,
    unsigned long   *length_return,
    int	    *format_return)
{
  NavMotif      *nav;
  brow_tCtx	browctx;
  char		name[200];
  int 		sts;

  BrowCtxFromWidget( w, (void **) &browctx);
  brow_GetCtxUserData( browctx, (void **) &nav);

  if (*target == XA_TARGETS(flow_Display(nav->brow_widget))) {
    Atom *targetP;
    Atom *std_targets;
    unsigned long std_length;
    XSelectionRequestEvent *req = XtGetSelectionRequest( w, *selection, 
       (XtRequestId)NULL);

    XmuConvertStandardSelection( w, req->time, selection, target, type_return,
		(caddr_t *)&std_targets, &std_length, format_return);

    *value_return = XtMalloc( sizeof(Atom) * (std_length + 2));
    targetP = *(Atom **) value_return;
    *targetP++ = XA_STRING;
    *targetP++ = XA_TEXT(flow_Display(nav->brow_widget));
    *length_return = std_length + (targetP - (*(Atom **) value_return));
    bcopy((char *)std_targets, (char *)targetP, sizeof(Atom) * std_length);
    XtFree( (char *)std_targets);
    *type_return = XA_ATOM;
    *format_return = 32;
    return True;
  }

  if (*target == XA_STRING)
  {
    if ( !nav->get_plant_select_cb)
      return FALSE;

    sts = nav->get_plant_select_cb( nav->parent_ctx, name, sizeof(name));
    if ( EVEN(sts)) return FALSE;
    *value_return = XtNewString(name);      
    *length_return = strlen(name) + 1;

    *type_return = XA_STRING;
    *format_return = 8;

    return TRUE;
  }
  return FALSE;
}
Beispiel #2
0
const char *
visibleSelectionTarget(Display * d, Atom a)
{
    const char *result = "?";

    if (a == XA_STRING) {
	result = "XA_STRING";
    } else if (a == XA_TEXT(d)) {
	result = "XA_TEXT()";
    } else if (a == XA_COMPOUND_TEXT(d)) {
	result = "XA_COMPOUND_TEXT()";
    } else if (a == XA_UTF8_STRING(d)) {
	result = "XA_UTF8_STRING()";
    } else if (a == XA_TARGETS(d)) {
	result = "XA_TARGETS()";
    }

    return result;
}
/*ARGSUSED*/
static Boolean
ConvertSelection(Widget w, Atom *selection, Atom *target, Atom *type,
		 XtPointer *value, unsigned long *length, int *format)
{
    Boolean success;

    if (*target == XA_PIXMAP || *target == XA_BITMAP) {
	ScaleWidget sw = (ScaleWidget) w;
	Pixmap *pixmap = (Pixmap *) XtMalloc(sizeof(Pixmap));
	*pixmap = XCreatePixmap(XtDisplay(w), XtWindow(w),
				sw->scale.image->width,
				sw->scale.image->height,
				sw->scale.image->depth);
	XPutImage(XtDisplay(w), *pixmap, sw->scale.gc, sw->scale.image,
		  0, 0, 0, 0, sw->scale.image->width, sw->scale.image->height);
	*type = XA_PIXMAP;
	*value = (XtPointer) pixmap;
	*length = 1;
	*format = 32;
	success = True;
    } else {
	/* Xt will always respond to selection requests for the TIMESTAMP
	   target, so we can pass a bogus time to XmuConvertStandardSelection.
	   In addition to the targets provided by XmuConvertStandardSelection,
	   Xt converts MULTIPLE, and we convert PIXMAP and BITMAP.
	 */
	success = XmuConvertStandardSelection(w, (Time)0, selection, target,
					      type, (XPointer *)value, length,
					      format);
	if (success && *target == XA_TARGETS(XtDisplay(w))) {
	    Atom* tmp;
	    tmp = (Atom *) XtRealloc(*value, (*length + 3) * sizeof(Atom));
	    tmp[(*length)++] = XInternAtom(XtDisplay(w), "MULTIPLE", False);
	    tmp[(*length)++] = XA_PIXMAP;
	    tmp[(*length)++] = XA_BITMAP;
	    *value = (XtPointer) tmp;
	}
    }
    return success;
}
Beispiel #4
0
static Boolean
ConvertSelection(Widget w, Atom *selection, Atom *target, Atom *type,
		 XtPointer *value, unsigned long *length, int *format)
{
    Display* d = XtDisplay(w);
    XSelectionRequestEvent* req =
	XtGetSelectionRequest(w, *selection, (XtRequestId)NULL);

    if (*target == XA_TARGETS(d))
    {
	Atom* targetP;
	Atom* std_targets;
	unsigned long std_length;
	XmuConvertStandardSelection(w, req->time, selection, target, type,
				    (XPointer *)&std_targets, &std_length,
				    format);
	*value = (XtPointer)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));
	memmove( (char*)targetP, (char*)std_targets, 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) TextLength (text);

	*value = (XtPointer) 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] = TextLength (text);
	*value = (XtPointer) 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;
	*length = TextLength (text);
	*value = (XtPointer)_XawTextGetSTRING((TextWidget) text, 0, *length);
	*format = 8;
	/*
	 * Drop our connection to the file; the new console program
	 * will open as soon as it receives the selection contents; there
	 * is a small window where console output will not be redirected,
	 * but I see no way of avoiding that without having two programs
	 * attempt to redirect console output at the same time, which seems
	 * worse
	 */
	CloseConsole ();
	return True;
    }

    if (XmuConvertStandardSelection(w, req->time, selection, target, type,
				    (XPointer *)value, length, format))
	return True;

    return False;
}
static Boolean 
ConvertSelection(Widget w, Atom *selection, Atom *target,
		 Atom *type, XtPointer *value, unsigned long *length, 
		 int *format)
{
    Display* d = XtDisplay(w);
    XSelectionRequestEvent* req =
	XtGetSelectionRequest(w, *selection, (XtRequestId)NULL);

    if (*target == XA_TARGETS(d)) {
	Atom* targetP;
	Atom* std_targets;
	unsigned long std_length;
	XmuConvertStandardSelection(w, req->time, selection, target, type,
				    (XPointer*)&std_targets, &std_length,
				    format);
	*value = XtMalloc(sizeof(Atom)*(std_length + 7));
	targetP = *(Atom**)value;
	*targetP++ = XA_STRING;
	*targetP++ = XA_TEXT(d);
	*targetP++ = XA_UTF8_STRING(d);
	*targetP++ = XA_COMPOUND_TEXT(d);
	*targetP++ = XA_LENGTH(d);
	*targetP++ = XA_LIST_LENGTH(d);
	*targetP++ = XA_CHARACTER_POSITION(d);
	*length = std_length + (targetP - (*(Atom **) value));
	memmove( (char*)targetP, (char*)std_targets, 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) TextLength (text);
    	
    	*value = (XPointer) 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] = TextLength (text);
    	*value = (XPointer) temp;
    	*type = XA_SPAN(d);
    	*length = 2L;
    	*format = 32;
    	return True;
    }
    
    if (*target == XA_STRING ||
	*target == XA_TEXT(d) ||
	*target == XA_UTF8_STRING(d) ||
	*target == XA_COMPOUND_TEXT(d))
    {
	Arg args[1];
	Widget source;
	XTextProperty prop;
	int ret, style = XStdICCTextStyle; /* a safe default for TEXT */
	char *data;

	source = XawTextGetSource (text);
	XtSetArg (args[0], XtNstring, &data);
	XtGetValues (source, args, 1);

	if (*target == XA_UTF8_STRING(d))
	    style = XUTF8StringStyle;
	else if (*target == XA_COMPOUND_TEXT(d))
	    style = XCompoundTextStyle;
	else if (*target == XA_STRING)
	    style = XStringStyle;

	ret = XmbTextListToTextProperty (d, &data, 1, style, &prop);
	if (ret >= Success) {
	    *length = prop.nitems;
	    *value = prop.value;
	    *type = prop.encoding;
	    *format = prop.format;
	    return True;
	} else
	    return False;
    }

    if (XmuConvertStandardSelection(w, req->time, selection, target, type,
				    (XPointer *) value, length, format))
	return True;

    return False;
}
Beispiel #6
0
// called when someone requests the selection value
Boolean ConvertSelection(Widget w, Atom *selection, Atom *target,
                                Atom *type, XtPointer *value,
                                unsigned long *length, int *format)
{
  Display* d = XtDisplay(w);
  XSelectionRequestEvent* req =
    XtGetSelectionRequest(w, *selection, (XtRequestId)NULL);
  Atom utf8_string = XInternAtom(d, "UTF8_STRING", False);
  
  if (options.debug) {
    printf("Window 0x%lx requested %s of selection %s.\n",
      req->requestor,
      XGetAtomName(d, *target),
      XGetAtomName(d, *selection));
  }
  
  if (*target == XA_TARGETS(d)) {
    Atom *targetP, *atoms;
    XPointer std_targets;
    unsigned long std_length;
    int i;
    
    XmuConvertStandardSelection(w, req->time, selection, target, type,
        &std_targets, &std_length, format);
    *value = XtMalloc(sizeof(Atom)*(std_length + 4));
    targetP = *(Atom**)value;
    atoms = targetP;
    *length = std_length + 5;
    *targetP++ = utf8_string;
    *targetP++ = XA_STRING;
    *targetP++ = XA_TEXT(d);
    *targetP++ = XA_LENGTH(d);
    *targetP++ = XA_LIST_LENGTH(d);
    memmove( (char*)targetP, (char*)std_targets, sizeof(Atom)*std_length);
    XtFree((char*)std_targets);
    *type = XA_ATOM;
    *format = 32;
    
    if (options.debug) {
      printf("Targets are: ");
      for (i=0; i<*length; i++)
        printf("%s ", XGetAtomName(d, atoms[i]));
      printf("\n");
    }

    return True;
  }
  
  if (*target == utf8_string || *target == XA_STRING || *target == XA_TEXT(d)) {
    *type = *target;
    *value = XtMalloc((Cardinal) options.length);
    memmove((char *)*value, options.value, options.length);
    *length = options.length;
    *format = 8;

    if (options.debug) {
      printf("Returning %s ", XGetAtomName(d, *target));
      PrintValue((char*)*value, *length);
      printf("\n");
    }
   
    return True;
  }
  
  if (*target == XA_LIST_LENGTH(d)) {
    CARD32 *temp = (CARD32 *) XtMalloc(sizeof(CARD32));
    *temp = 1L;
    *value = (XtPointer) temp;
    *type = XA_INTEGER;
    *length = 1;
    *format = 32;

    if (options.debug)
      printf("Returning %" PRIx32 "\n", *temp);

    return True;
  }
  
  if (*target == XA_LENGTH(d)) {
    CARD32 *temp = (CARD32 *) XtMalloc(sizeof(CARD32));
    *temp = options.length;
    *value = (XtPointer) temp;
    *type = XA_INTEGER;
    *length = 1;
    *format = 32;

    if (options.debug)
      printf("Returning %" PRIx32 "\n", *temp);

    return True;
  }
  
  if (XmuConvertStandardSelection(w, req->time, selection, target, type,
          (XPointer *)value, length, format)) {
    printf("Returning conversion of standard selection\n");
    return True;
  }
   
  /* else */
  if (options.debug)
    printf("Target not supported\n");

  return False;
}
Beispiel #7
0
static Boolean 
ConvertSelection(Widget w, Atom *selection, Atom *target,
		 Atom *type, XtPointer *value, unsigned long *length, 
		 int *format)
{
    Display* d = XtDisplay(w);
    XSelectionRequestEvent* req =
	XtGetSelectionRequest(w, *selection, (XtRequestId)NULL);
	
    if (*target == XA_TARGETS(d)) {
	Atom* targetP;
	Atom* std_targets;
	unsigned long std_length;
	XmuConvertStandardSelection(w, req->time, selection, target, type,
				    (XPointer*)&std_targets, &std_length,
				    format);
	*value = XtMalloc(sizeof(Atom)*(std_length + 4));
	targetP = *(Atom**)value;
	*length = std_length + 4;
	*targetP++ = XA_STRING;
	*targetP++ = XA_TEXT(d);
	*targetP++ = XA_LENGTH(d);
	*targetP++ = XA_LIST_LENGTH(d);
/*
	*targetP++ = XA_CHARACTER_POSITION(d);
*/
	memmove( (char*)targetP, (char*)std_targets, sizeof(Atom)*std_length);
	XtFree((char*)std_targets);
	*type = XA_ATOM;
	*format = 32;
	return True;
    }
    if (*target == XA_STRING || *target == XA_TEXT(d)) {
	*type = XA_STRING;
	*value = XtMalloc((Cardinal) options.length);
	memmove( (char *) *value, options.value, options.length);
	*length = options.length;
	*format = 8;
	return True;
    }
    if (*target == XA_LIST_LENGTH(d)) {
	long *temp = (long *) XtMalloc (sizeof(long));
	*temp = 1L;
	*value = (XtPointer) temp;
	*type = XA_INTEGER;
	*length = 1;
	*format = 32;
	return True;
    }
    if (*target == XA_LENGTH(d)) {
	long *temp = (long *) XtMalloc (sizeof(long));
	*temp = options.length;
	*value = (XtPointer) temp;
	*type = XA_INTEGER;
	*length = 1;
	*format = 32;
	return True;
    }
#ifdef notdef
    if (*target == XA_CHARACTER_POSITION(d)) {
	long *temp = (long *) XtMalloc (2 * sizeof(long));
	temp[0] = ctx->text.s.left + 1;
	temp[1] = ctx->text.s.right;
	*value = (XtPointer) temp;
	*type = XA_SPAN(d);
	*length = 2;
	*format = 32;
	return True;
    }
#endif /* notdef */
    if (XmuConvertStandardSelection(w, req->time, selection, target, type,
				    (XPointer *)value, length, format))
	return True;

    /* else */
    return False;
}
Beispiel #8
0
Boolean WNavMotif::sel_convert_cb(
    Widget  w,
    Atom    *selection,
    Atom    *target,
    Atom    *type_return,
    XtPointer	*value_return,
    unsigned long   *length_return,
    int	    *format_return)
{
    WNavMotif    	*wnav;
    brow_tCtx	browctx;
    int 		sts;
    int		size;
    WItem		*item;
    pwr_tAName   	attr_str;
    pwr_sAttrRef attrref;
    char          name[200];
    char		*buffp;

    BrowCtxFromWidget( w, (void **) &browctx);
    brow_GetCtxUserData( browctx, (void **) &wnav);

    if (*target == XA_TARGETS(flow_Display(wnav->brow_widget))) {
        Atom *targetP;
        Atom *std_targets;
        unsigned long std_length;
        XSelectionRequestEvent *req = XtGetSelectionRequest( w, *selection,
                                      (XtRequestId)NULL);

        XmuConvertStandardSelection( w, req->time, selection, target, type_return,
                                     (caddr_t *)&std_targets, &std_length, format_return);

        *value_return = XtMalloc( sizeof(Atom) * (std_length + 2));
        targetP = *(Atom **) value_return;
        *targetP++ = XA_STRING;
        *targetP++ = XA_TEXT(flow_Display(wnav->brow_widget));
        *length_return = std_length + (targetP - (*(Atom **) value_return));
        bcopy((char *)std_targets, (char *)targetP, sizeof(Atom) * std_length);
        XtFree( (char *)std_targets);
        *type_return = XA_ATOM;
        *format_return = 32;
        return True;
    }

    if (*target == XA_STRING ||
            *target == XA_TEXT(flow_Display(wnav->brow_widget)) ||
            *target == XA_COMPOUND_TEXT(flow_Display(wnav->brow_widget)) ||
            *target == wnav->graph_atom ||
            *target == wnav->objid_atom ||
            *target == wnav->attrref_atom)
    {
        brow_tNode	*node_list;
        int		node_count;
        wnav_eSelectionFormat format;

        if ( *target == wnav->graph_atom)
            format = wnav_eSelectionFormat_Graph;
        else if ( *target == wnav->objid_atom)
            format = wnav_eSelectionFormat_Objid;
        else if ( *target == wnav->attrref_atom)
            format = wnav_eSelectionFormat_Attrref;
        else
            format = wnav_eSelectionFormat_User;


        brow_GetSelectedNodes( wnav->brow->ctx, &node_list, &node_count);
        if ( !node_count)
            return FALSE;

        brow_GetUserData( node_list[0], (void **)&item);

        switch( item->type) {
        case wnav_eItemType_Attr:
        case wnav_eItemType_AttrInput:
        case wnav_eItemType_AttrInputInv:
        case wnav_eItemType_AttrInputF:
        case wnav_eItemType_AttrOutput:
        case wnav_eItemType_AttrArray:
        case wnav_eItemType_AttrArrayOutput:
        case wnav_eItemType_AttrArrayElem:
        case wnav_eItemType_AttrObject: {
            WItemBaseAttr *aitem = (WItemBaseAttr *)item;

            sts = ldh_ObjidToName( wnav->ldhses, item->objid, ldh_eName_Hierarchy,
                                   attr_str, sizeof(attr_str), &size);
            if ( EVEN(sts)) return FALSE;

            strcat( attr_str, ".");
            strcat( attr_str, aitem->name);
            sts = ldh_NameToAttrRef( wnav->ldhses, attr_str, &attrref);
            if ( EVEN(sts)) return FALSE;
            sts = (wnav->format_selection_cb)( wnav->parent_ctx, attrref,
                                               &buffp, 0, 1, format);
            *value_return = XtNewString(buffp);
            *length_return = strlen(buffp) + 1;
            if ( !sts) return FALSE;
            break;
        }
        case wnav_eItemType_Object:
            memset( &attrref, 0, sizeof(attrref));
            attrref.Objid = item->objid;
            sts = (wnav->format_selection_cb)( wnav->parent_ctx, attrref,
                                               &buffp, 0, 0, format);
            *value_return = XtNewString(buffp);
            *length_return = strlen(buffp) + 1;
            if ( !sts) return FALSE;
            break;
        default:
            brow_GetAnnotation( node_list[0], 0, name, sizeof(name));
            *value_return = XtNewString(name);
            *length_return = strlen(name) + 1;
        }
        free( node_list);

        if ( *target == XA_COMPOUND_TEXT(flow_Display(wnav->brow_widget)) ||
                *target == wnav->graph_atom ||
                *target == wnav->objid_atom ||
                *target == wnav->attrref_atom)
            *type_return = *target;
        else
            *type_return = XA_STRING;
        *format_return = 8;

        return TRUE;
    }
    return FALSE;
}
Beispiel #9
0
static Boolean pal_sel_convert_cb(
    Widget  w,
    Atom    *selection,
    Atom    *target,
    Atom    *type_return,
    XtPointer	*value_return,
    unsigned long   *length_return,
    int	    *format_return)
{
  PalMotif     	*pal;
  brow_tCtx	browctx;
  char		name[200];
  PalItem	*item;

  BrowCtxFromWidget( w, (void **) &browctx);
  brow_GetCtxUserData( browctx, (void **) &pal);

  if (*target == XA_TARGETS(flow_Display(pal->brow_widget))) {
    Atom *targetP;
    Atom *std_targets;
    unsigned long std_length;
    XSelectionRequestEvent *req = XtGetSelectionRequest( w, *selection, 
       (XtRequestId)NULL);

    XmuConvertStandardSelection( w, req->time, selection, target, type_return,
		(caddr_t *)&std_targets, &std_length, format_return);

    *value_return = XtMalloc( sizeof(Atom) * (std_length + 2));
    targetP = *(Atom **) value_return;
    *targetP++ = XA_STRING;
    *targetP++ = XA_TEXT(flow_Display(pal->brow_widget));
    *length_return = std_length + (targetP - (*(Atom **) value_return));
    bcopy((char *)std_targets, (char *)targetP, sizeof(Atom) * std_length);
    XtFree( (char *)std_targets);
    *type_return = XA_ATOM;
    *format_return = 32;
    return True;
  }

  if (*target == XA_STRING ||
      *target == XA_TEXT(flow_Display(pal->brow_widget)) ||
      *target == XA_COMPOUND_TEXT(flow_Display(pal->brow_widget))) {
    brow_tNode	*node_list;
    int		node_count;
  
    brow_GetSelectedNodes( pal->brow_ctx, &node_list, &node_count);
    if ( !node_count)
      return FALSE;

    brow_GetUserData( node_list[0], (void **)&item);

    switch( item->type) {
      case pal_ePalItemType_ClassVolume: 
      case pal_ePalItemType_Class: 
      case pal_ePalItemType_Object: 
      default:
        brow_GetAnnotation( node_list[0], 0, name, sizeof(name));
        *value_return = XtNewString(name);      
        *length_return = strlen(name) + 1;
    }
    free( node_list);

    *type_return = XA_STRING;
    *format_return = 8;

    return TRUE;
  }
  return FALSE;
}