Beispiel #1
0
/*ARGSUSED*/
static Boolean
XawCvtCompoundTextToString(Display *dpy, XrmValuePtr args, Cardinal *num_args,
			   XrmValue *fromVal, XrmValue *toVal,
			   XtPointer *cvt_data)
{
    XTextProperty prop;
    char **list;
    int count;
    static char *mbs = NULL;
    int len;

    prop.value = (unsigned char *)fromVal->addr;
    prop.encoding = XA_COMPOUND_TEXT(dpy);
    prop.format = 8;
    prop.nitems = fromVal->size;

    if(XmbTextPropertyToTextList(dpy, &prop, &list, &count) < Success) {
	XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
	"converter", "XmbTextPropertyToTextList", "XawError",
	"conversion from CT to MB failed.", NULL, 0);
	return False;
    }
    len = strlen(*list);
    toVal->size = len;
    mbs = XtRealloc(mbs, len + 1); /* keep buffer because no one call free :( */
    strcpy(mbs, *list);
    XFreeStringList(list);
    toVal->addr = (XtPointer)mbs;
    return True;
}
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;
}
Beispiel #3
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;
}
/*ARGSUSED*/
static void 
InsertClipboard(Widget w, XtPointer client_data, Atom *selection, 
		Atom *type, XtPointer value, unsigned long *length, 
		int *format)
{
    Display *d = XtDisplay(w);
    Atom target = (Atom)client_data;
    Boolean convert_failed = (*type == XT_CONVERT_FAIL);

    if (!convert_failed)
    {
	char **list;
	int i, ret, count;

	XTextProperty prop;
	prop.value = value;
	prop.nitems = *length;
	prop.format = *format;
	prop.encoding = *type;
	ret = XmbTextPropertyToTextList(d, &prop, &list, &count);
	if (ret >= Success)
	{
	    /* manuals say something about multiple strings in a disjoint
	    text selection (?), it should be harmless to get them all */
	    for (i = 0; i < count; i++)
		NewCurrentClipContents(list[i], strlen(list[i]));
	    XFreeStringList(list);
	} else
	    convert_failed = True;
	XFree(value);
    }

    if (convert_failed) {
	/* if UTF8_STRING failed try COMPOUND_TEXT */
	if (target == XA_UTF8_STRING(d))
	{
	    XtGetSelectionValue(w, *selection, XA_COMPOUND_TEXT(d),
				InsertClipboard,
				(XtPointer)(XA_COMPOUND_TEXT(d)),
				CurrentTime);
	    return;
	}
	/* if COMPOUND_TEXT failed try STRING */
	else if (target == XA_COMPOUND_TEXT(d))
	{
	    XtGetSelectionValue(w, *selection, XA_STRING,
				InsertClipboard,
				NULL,
				CurrentTime);
	    return;
	}
	/* all conversions failed */
	else
	{
	    Arg arg;
	    XtSetArg (arg, XtNlabel, "CLIPBOARD selection conversion failed");
	    XtSetValues (failDialog, &arg, 1);
	    CenterWidgetOnWidget (failDialogShell, text);
	    XtPopup (failDialogShell, XtGrabNone);
#ifdef XKB
	    XkbStdBell (d, XtWindow(w), 0, XkbBI_MinorError);
#else
	    XBell (d, 0);
#endif
	}
    }
    
    XtOwnSelection(top, ClipboardAtom, CurrentTime,
		   ConvertSelection, LoseSelection, NULL);
}
Beispiel #6
0
XawCvtCompoundTextToString(
			      Display *dpy,
			      XrmValuePtr args GCC_UNUSED,
			      Cardinal *num_args GCC_UNUSED,
			      XrmValue * fromVal,
			      XrmValue * toVal,
			      XtPointer *cvt_data GCC_UNUSED)
{
    XTextProperty prop;
    char **list;
    int count;
    static char *mbs = NULL;
    int len;

    prop.value = (unsigned char *) fromVal->addr;
    prop.encoding = XA_COMPOUND_TEXT(dpy);
    prop.format = 8;
    prop.nitems = fromVal->size;

    if (XmbTextPropertyToTextList(dpy, &prop, &list, &count) < Success) {
	XtAppWarningMsg(XtDisplayToApplicationContext(dpy),
			"converter", "XmbTextPropertyToTextList", "XawError",
			"conversion from CT to MB failed.", NULL, 0);
	return False;
    }
    len = (int) strlen(*list);
    toVal->size = (unsigned) len;
    mbs = XtRealloc(mbs, (unsigned) (len + 1));
    /* keep buffer because no one calls free... */
    strcpy(mbs, *list);
    XFreeStringList(list);
Beispiel #7
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 #8
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;
}