27
27
* Author: Ralph Swick, DEC/Project Athena
28
28
* Updated for R4: Chris D. Peterson, MIT X Consortium.
29
29
* Reauthored by: Keith Packard, MIT X Consortium.
30
* UTF-8 and CTEXT support: Stanislav Maslovski <stanislav.maslovski@gmail.com>
31
32
/* $XFree86: xc/programs/xclipboard/xclipboard.c,v 1.8tsi Exp $ */
428
XtActionsRec xclipboard_actions[] = {
434
static XtActionsRec xclipboard_actions[] = {
429
435
{ "NewClip", NewCurrentClip },
430
436
{ "NextClip", NextCurrentClip },
431
437
{ "PrevClip", PrevCurrentClip },
456
462
Atom *type, XtPointer value, unsigned long *length,
459
if (*type != XT_CONVERT_FAIL)
460
NewCurrentClipContents ((char *) value, *length);
465
Display *d = XtDisplay(w);
466
Atom target = (Atom)client_data;
467
Boolean convert_failed = (*type == XT_CONVERT_FAIL);
464
XtSetArg (arg, XtNlabel, "CLIPBOARD selection conversion failed");
465
XtSetValues (failDialog, &arg, 1);
466
CenterWidgetOnWidget (failDialogShell, text);
467
XtPopup (failDialogShell, XtGrabNone);
476
prop.nitems = *length;
477
prop.format = *format;
478
prop.encoding = *type;
479
ret = XmbTextPropertyToTextList(d, &prop, &list, &count);
482
/* manuals say something about multiple strings in a disjoint
483
text selection (?), it should be harmless to get them all */
484
for (i = 0; i < count; i++)
485
NewCurrentClipContents(list[i], strlen(list[i]));
486
XFreeStringList(list);
488
convert_failed = True;
492
if (convert_failed) {
493
/* if UTF8_STRING failed try COMPOUND_TEXT */
494
if (target == XA_UTF8_STRING(d))
496
XtGetSelectionValue(w, *selection, XA_COMPOUND_TEXT(d),
498
(XtPointer)(XA_COMPOUND_TEXT(d)),
502
/* if COMPOUND_TEXT failed try STRING */
503
else if (target == XA_COMPOUND_TEXT(d))
505
XtGetSelectionValue(w, *selection, XA_STRING,
511
/* all conversions failed */
515
XtSetArg (arg, XtNlabel, "CLIPBOARD selection conversion failed");
516
XtSetValues (failDialog, &arg, 1);
517
CenterWidgetOnWidget (failDialogShell, text);
518
XtPopup (failDialogShell, XtGrabNone);
469
XkbStdBell( XtDisplay(w), XtWindow(w), 0, XkbBI_MinorError );
520
XkbStdBell (d, XtWindow(w), 0, XkbBI_MinorError);
471
XBell( XtDisplay(w), 0 );
475
527
XtOwnSelection(top, ClipboardAtom, CurrentTime,
476
528
ConvertSelection, LoseSelection, NULL);
493
544
XmuConvertStandardSelection(w, req->time, selection, target, type,
494
545
(XPointer*)&std_targets, &std_length,
496
*value = XtMalloc(sizeof(Atom)*(std_length + 5));
547
*value = XtMalloc(sizeof(Atom)*(std_length + 7));
497
548
targetP = *(Atom**)value;
498
549
*targetP++ = XA_STRING;
499
550
*targetP++ = XA_TEXT(d);
551
*targetP++ = XA_UTF8_STRING(d);
552
*targetP++ = XA_COMPOUND_TEXT(d);
500
553
*targetP++ = XA_LENGTH(d);
501
554
*targetP++ = XA_LIST_LENGTH(d);
502
555
*targetP++ = XA_CHARACTER_POSITION(d);
543
596
if (*target == XA_STRING ||
544
*target == XA_TEXT(d) ||
545
*target == XA_COMPOUND_TEXT(d))
597
*target == XA_TEXT(d) ||
598
*target == XA_UTF8_STRING(d) ||
599
*target == XA_COMPOUND_TEXT(d))
547
if (*target == XA_COMPOUND_TEXT(d))
551
*length = TextLength (text);
552
*value = _XawTextGetSTRING((TextWidget) text, 0, *length);
604
int ret, style = XStdICCTextStyle; /* a safe default for TEXT */
607
source = XawTextGetSource (text);
608
XtSetArg (args[0], XtNstring, &data);
609
XtGetValues (source, args, 1);
611
if (*target == XA_UTF8_STRING(d))
612
style = XUTF8StringStyle;
613
else if (*target == XA_COMPOUND_TEXT(d))
614
style = XCompoundTextStyle;
615
else if (*target == XA_STRING)
616
style = XStringStyle;
618
ret = XmbTextListToTextProperty (d, &data, 1, style, &prop);
619
if (ret >= Success) {
620
*length = prop.nitems;
622
*type = prop.encoding;
623
*format = prop.format;
557
629
if (XmuConvertStandardSelection(w, req->time, selection, target, type,
558
630
(XPointer *) value, length, format))
565
637
LoseSelection(Widget w, Atom *selection)
567
XtGetSelectionValue(w, *selection, XA_STRING, InsertClipboard,
639
Display *d = XtDisplay(w);
640
XtGetSelectionValue(w, *selection, XA_UTF8_STRING(d), InsertClipboard,
641
(XtPointer)(XA_UTF8_STRING(d)), CurrentTime);
593
666
#define Offset(field) XtOffsetOf(ResourceData, field)
595
XtResource resources[] = {
668
static XtResource resources[] = {
596
669
{"wrap", "Wrap", XtRBoolean, sizeof(Boolean),
597
670
Offset(wrap), XtRImmediate, (XtPointer)False}
610
683
XtSetLanguageProc(NULL, NULL, NULL);
612
685
top = XtAppInitialize( &xtcontext, "XClipboard", table, XtNumber(table),
613
&argc, argv, NULL, NULL, 0);
686
&argc, argv, fallback_resources, NULL, 0);
615
688
XtGetApplicationResources(top, (XtPointer)&userOptions, resources,
616
689
XtNumber(resources), NULL, 0);