1228
1228
#define CLIPMASK 3 /* 2 clipboards */
1237
static GtkTargetEntry text_targets[] = {
1238
{ "STRING", 0, TEXT_STRING },
1239
{ "TEXT", 0, TEXT_TEXT },
1240
{ "COMPOUND_TEXT", 0, TEXT_COMPOUND }
1242
static GtkTargetList *text_tlist;
1248
static text_offer text_on_offer[2];
1250
static void clear_text_offer(int nw)
1254
for (i = 0; i < 2; i++)
1256
if (text_on_offer[i].where &= ~nw) continue;
1257
free(text_on_offer[i].what);
1258
text_on_offer[i].what = NULL;
1230
1262
static void selection_callback(GtkWidget *widget, GtkSelectionData *sel,
1231
1263
guint time, gpointer user_data)
1282
1314
void **slot = g_dataset_get_data(main_window,
1283
1315
gdk_atom_name(sel->selection));
1284
if (slot) clip_evt(sel, info, slot);
1316
/* Text clipboard is handled right here */
1317
if (slot == (void *)text_on_offer)
1322
which = sel->selection == gdk_atom_intern("PRIMARY", FALSE) ? 2 : 1;
1323
for (i = 0; i < 2; i++) if (text_on_offer[i].where & which) break;
1324
if (i > 1) return; // No text for this clipboard
1325
s = text_on_offer[i].what;
1326
if (!s) return; // Paranoia
1327
if (info == TEXT_STRING)
1328
gtk_selection_data_set(sel, sel->target, 8, s, strlen(s));
1329
else if ((info == TEXT_TEXT) || (info == TEXT_COMPOUND))
1334
gdk_string_to_compound_text(s, &target, &format, &ns, &len);
1335
gtk_selection_data_set(sel, target, format, ns, len);
1336
gdk_free_compound_text(ns);
1339
/* Other kinds get handled outside */
1340
else if (slot) clip_evt(sel, info, slot);
1287
1343
static void selection_clear_callback(GtkWidget *widget, GdkEventSelection *event,
1290
1346
void **slot = g_dataset_get_data(main_window,
1291
1347
gdk_atom_name(event->selection));
1292
if (slot) clip_evt(NULL, 0, slot);
1348
if (slot == (void *)text_on_offer) clear_text_offer(
1349
event->selection == gdk_atom_intern("PRIMARY", FALSE) ? 2 : 1);
1350
else if (slot) clip_evt(NULL, 0, slot);
1295
1353
// !!! GTK+ 1.2 internal type (gtk/gtkselection.c)
1298
1356
GtkTargetList *list;
1299
1357
} GtkSelectionTargetList;
1301
static int offer_clipboard(void **slot)
1359
static int offer_clipboard(void **slot, int text)
1303
1361
static int connected;
1304
1362
void **desc = slot[1];
1305
1363
clipform_data *cd = slot[0];
1364
GtkTargetEntry *targets = cd->ent;
1365
gpointer info = slot;
1306
1366
GtkSelectionTargetList *slist;
1307
1367
GList *list, *tmp;
1309
int which, res = FALSE, nw = (int)desc[2] & CLIPMASK;
1369
int which, res = FALSE, nw = (int)desc[2] & CLIPMASK, ntargets = cd->n;
1372
if (text) targets = text_targets , ntargets = TEXT_CNT , info = text_on_offer;
1311
1373
for (which = 0; (1 << which) <= nw; which++)
1313
1375
if (!((1 << which) & nw)) continue;
1331
1393
"gtk-selection-handlers", list);
1333
1395
// !!! Have to resort to this to allow for multiple X clipboards
1334
g_dataset_set_data(main_window, which ? "PRIMARY" : "CLIPBOARD",
1396
g_dataset_set_data(main_window, which ? "PRIMARY" : "CLIPBOARD", info);
1336
1397
if (!connected)
1338
1399
gtk_signal_connect(GTK_OBJECT(main_window), "selection_get",
1342
1403
connected = TRUE;
1345
gtk_selection_add_targets(main_window, sel, cd->ent, cd->n);
1406
gtk_selection_add_targets(main_window, sel, targets, ntargets);
1413
static void offer_text(void **slot, char *s)
1415
void **desc = slot[1];
1416
int i, nw = (int)desc[2] & CLIPMASK;
1418
clear_text_offer(nw);
1419
i = !!text_on_offer[0].what;
1420
text_on_offer[i].what = strdup(s);
1421
text_on_offer[i].where = nw;
1423
if (!text_tlist) text_tlist = gtk_target_list_new(text_targets, TEXT_CNT);
1425
offer_clipboard(slot, TRUE);
1352
1428
#else /* if GTK_MAJOR_VERSION == 2 */
1354
1430
#ifdef GDK_WINDOWING_X11
1426
1502
clip_evt(NULL, 0, user_data);
1429
static int offer_clipboard(void **slot)
1505
static int offer_clipboard(void **slot, int unused)
1431
1507
void **desc = slot[1];
1432
1508
clipform_data *cd = slot[0];
1528
static void offer_text(void **slot, char *s)
1530
void **desc = slot[1];
1531
int which, nw = (int)desc[2] & CLIPMASK;
1533
for (which = 0; (1 << which) <= nw; which++)
1535
if (!((1 << which) & nw)) continue;
1536
gtk_clipboard_set_text(gtk_clipboard_get(which ?
1537
GDK_SELECTION_PRIMARY : GDK_SELECTION_CLIPBOARD), s, -1);
1454
1543
#undef CLIPMASK
8722
8814
(op == op_MENURITEM) || (op == op_uMENURITEM));
8723
8815
if (op == op_CLIPBOARD)
8725
if (idx == CLIP_OFFER) return (offer_clipboard(slot));
8817
if (idx == CLIP_OFFER) return (offer_clipboard(slot, FALSE));
8726
8818
if (idx == CLIP_PROCESS) return (process_clipboard(slot));
8728
8820
else if (op == op_EV_MOUSE)