~peter-pearse/ubuntu/oneiric/x11-apps/prop001

« back to all changes in this revision

Viewing changes to xclipboard/xclipboard.c

  • Committer: Bazaar Package Importer
  • Author(s): Brice Goglin, Julien Cristau, Brice Goglin
  • Date: 2009-12-06 12:23:46 UTC
  • Revision ID: james.westby@ubuntu.com-20091206122346-7r0tbgnaby4qdh82
Tags: 7.5+1
[ Julien Cristau ]
* Update xload config.{guess,sub}, adding avr32 support (closes: #536410)
* Improve the long description using patch from Justin B Rye (closes:
  #549457).  Thanks!

[ Brice Goglin ]
* Add ico 1.0.2, closes: #518383.
* bitmap 1.0.4.
* xclipboard 1.1.0.
  + Add UTF8 support, closes: #489998.
* xclock 1.0.4.
  + Drop 06_xclock_geometry.diff, applied upstream.
* xcursorgen 1.0.3.
* xeyes 1.0.991.
* xgc 1.0.2.
* xmag 1.0.3.
* xman 1.1.0.
* xwd 1.0.3.
  + Drop 01_xwd_do_not_spew_usage_on_connection_error.diff, applied upstream.
* xwud 1.0.2.
* Refresh patches.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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>
30
31
 */
31
32
/* $XFree86: xc/programs/xclipboard/xclipboard.c,v 1.8tsi Exp $ */
32
33
 
74
75
static void EraseTextWidget ( void );
75
76
static void NewCurrentClipContents ( char *data, int len );
76
77
 
 
78
static String fallback_resources[] = {
 
79
    "*international: true",
 
80
    NULL
 
81
};
 
82
 
77
83
static long 
78
84
TextLength(Widget w)
79
85
{
130
136
    newClip = (ClipPtr) malloc (sizeof (ClipRec));
131
137
    if (!newClip)
132
138
        return newClip;
133
 
    newClip->clip = 0;
 
139
    newClip->clip = NULL;
134
140
    newClip->avail = 0;
135
141
    newClip->prev = old;
136
142
    newClip->next = NULL;
425
431
}
426
432
 
427
433
 
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, 
457
463
                int *format)
458
464
{
459
 
    if (*type != XT_CONVERT_FAIL)
460
 
        NewCurrentClipContents ((char *) value, *length);
461
 
    else
 
465
    Display *d = XtDisplay(w);
 
466
    Atom target = (Atom)client_data;
 
467
    Boolean convert_failed = (*type == XT_CONVERT_FAIL);
 
468
 
 
469
    if (!convert_failed)
462
470
    {
463
 
        Arg arg;
464
 
        XtSetArg (arg, XtNlabel, "CLIPBOARD selection conversion failed");
465
 
        XtSetValues (failDialog, &arg, 1);
466
 
        CenterWidgetOnWidget (failDialogShell, text);
467
 
        XtPopup (failDialogShell, XtGrabNone);
 
471
        char **list;
 
472
        int i, ret, count;
 
473
 
 
474
        XTextProperty prop;
 
475
        prop.value = value;
 
476
        prop.nitems = *length;
 
477
        prop.format = *format;
 
478
        prop.encoding = *type;
 
479
        ret = XmbTextPropertyToTextList(d, &prop, &list, &count);
 
480
        if (ret >= Success)
 
481
        {
 
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);
 
487
        } else
 
488
            convert_failed = True;
 
489
        XFree(value);
 
490
    }
 
491
 
 
492
    if (convert_failed) {
 
493
        /* if UTF8_STRING failed try COMPOUND_TEXT */
 
494
        if (target == XA_UTF8_STRING(d))
 
495
        {
 
496
            XtGetSelectionValue(w, *selection, XA_COMPOUND_TEXT(d),
 
497
                                InsertClipboard,
 
498
                                (XtPointer)(XA_COMPOUND_TEXT(d)),
 
499
                                CurrentTime);
 
500
            return;
 
501
        }
 
502
        /* if COMPOUND_TEXT failed try STRING */
 
503
        else if (target == XA_COMPOUND_TEXT(d))
 
504
        {
 
505
            XtGetSelectionValue(w, *selection, XA_STRING,
 
506
                                InsertClipboard,
 
507
                                NULL,
 
508
                                CurrentTime);
 
509
            return;
 
510
        }
 
511
        /* all conversions failed */
 
512
        else
 
513
        {
 
514
            Arg arg;
 
515
            XtSetArg (arg, XtNlabel, "CLIPBOARD selection conversion failed");
 
516
            XtSetValues (failDialog, &arg, 1);
 
517
            CenterWidgetOnWidget (failDialogShell, text);
 
518
            XtPopup (failDialogShell, XtGrabNone);
468
519
#ifdef XKB
469
 
        XkbStdBell( XtDisplay(w), XtWindow(w), 0, XkbBI_MinorError );
 
520
            XkbStdBell (d, XtWindow(w), 0, XkbBI_MinorError);
470
521
#else
471
 
        XBell( XtDisplay(w), 0 );
 
522
            XBell (d, 0);
472
523
#endif
 
524
        }
473
525
    }
474
526
    
475
527
    XtOwnSelection(top, ClipboardAtom, CurrentTime,
476
528
                   ConvertSelection, LoseSelection, NULL);
477
 
    XFree(value);
478
529
}
479
530
 
480
531
static Boolean 
493
544
        XmuConvertStandardSelection(w, req->time, selection, target, type,
494
545
                                    (XPointer*)&std_targets, &std_length,
495
546
                                    format);
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);
541
594
    }
542
595
    
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))
546
600
    {
547
 
        if (*target == XA_COMPOUND_TEXT(d))
548
 
            *type = *target;
549
 
        else
550
 
            *type = XA_STRING;
551
 
        *length = TextLength (text);
552
 
        *value = _XawTextGetSTRING((TextWidget) text, 0, *length);
553
 
        *format = 8;
554
 
        return True;
 
601
        Arg args[1];
 
602
        Widget source;
 
603
        XTextProperty prop;
 
604
        int ret, style = XStdICCTextStyle; /* a safe default for TEXT */
 
605
        char *data;
 
606
 
 
607
        source = XawTextGetSource (text);
 
608
        XtSetArg (args[0], XtNstring, &data);
 
609
        XtGetValues (source, args, 1);
 
610
 
 
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;
 
617
 
 
618
        ret = XmbTextListToTextProperty (d, &data, 1, style, &prop);
 
619
        if (ret >= Success) {
 
620
            *length = prop.nitems;
 
621
            *value = prop.value;
 
622
            *type = prop.encoding;
 
623
            *format = prop.format;
 
624
            return True;
 
625
        } else
 
626
            return False;
555
627
    }
556
 
    
 
628
 
557
629
    if (XmuConvertStandardSelection(w, req->time, selection, target, type,
558
630
                                    (XPointer *) value, length, format))
559
631
        return True;
564
636
static void 
565
637
LoseSelection(Widget w, Atom *selection)
566
638
{
567
 
    XtGetSelectionValue(w, *selection, XA_STRING, InsertClipboard,
568
 
                        NULL, CurrentTime);
 
639
    Display *d = XtDisplay(w);
 
640
    XtGetSelectionValue(w, *selection, XA_UTF8_STRING(d), InsertClipboard,
 
641
                        (XtPointer)(XA_UTF8_STRING(d)), CurrentTime);
569
642
}
570
643
 
571
644
/*ARGSUSED*/
592
665
 
593
666
#define Offset(field) XtOffsetOf(ResourceData, field)
594
667
 
595
 
XtResource resources[] = {
 
668
static XtResource resources[] = {
596
669
  {"wrap", "Wrap", XtRBoolean, sizeof(Boolean),
597
670
     Offset(wrap), XtRImmediate, (XtPointer)False}
598
671
};
610
683
    XtSetLanguageProc(NULL, NULL, NULL);
611
684
 
612
685
    top = XtAppInitialize( &xtcontext, "XClipboard", table, XtNumber(table),
613
 
                          &argc, argv, NULL, NULL, 0);
 
686
                          &argc, argv, fallback_resources, NULL, 0);
614
687
 
615
688
    XtGetApplicationResources(top, (XtPointer)&userOptions, resources, 
616
689
                              XtNumber(resources), NULL, 0);