~wjaguar/mtpaint/trunk

« back to all changes in this revision

Viewing changes to src/vcode.c

  • Committer: Dmitry Groshev
  • Date: 2020-02-19 18:57:06 UTC
  • Revision ID: git-v1:e55eb7d3d14bc17ea92f5e5f00ecc538dced0aeb
Version 3.49.20

Added Normalize filter to Effects menu
Added extended variable interpolation mode to file actions: ">% echo Width %W Height %H Bytes/pixel %B" etc.
Made Image->Information work in script mode, interpolating a pattern given to it
Fixed quoting in file actions for filenames that contain nastier special chars
Fixed threshold window ignoring input when preview disabled

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*      vcode.c
2
 
        Copyright (C) 2013-2019 Dmitry Groshev
 
2
        Copyright (C) 2013-2020 Dmitry Groshev
3
3
 
4
4
        This file is part of mtPaint.
5
5
 
1227
1227
 
1228
1228
#define CLIPMASK 3 /* 2 clipboards */
1229
1229
 
 
1230
enum {
 
1231
        TEXT_STRING = 0,
 
1232
        TEXT_TEXT,
 
1233
        TEXT_COMPOUND,
 
1234
        TEXT_CNT
 
1235
};
 
1236
 
 
1237
static GtkTargetEntry text_targets[] = {
 
1238
        { "STRING", 0, TEXT_STRING },
 
1239
        { "TEXT", 0, TEXT_TEXT }, 
 
1240
        { "COMPOUND_TEXT", 0, TEXT_COMPOUND }
 
1241
};
 
1242
static GtkTargetList *text_tlist;
 
1243
 
 
1244
typedef struct {
 
1245
        char *what;
 
1246
        int where;
 
1247
} text_offer;
 
1248
static text_offer text_on_offer[2];
 
1249
 
 
1250
static void clear_text_offer(int nw)
 
1251
{
 
1252
        int i;
 
1253
 
 
1254
        for (i = 0; i < 2; i++)
 
1255
        {
 
1256
                if (text_on_offer[i].where &= ~nw) continue;
 
1257
                free(text_on_offer[i].what);
 
1258
                text_on_offer[i].what = NULL;
 
1259
        }
 
1260
}
 
1261
 
1230
1262
static void selection_callback(GtkWidget *widget, GtkSelectionData *sel,
1231
1263
        guint time, gpointer user_data)
1232
1264
{
1281
1313
{
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)
 
1318
        {
 
1319
                char *s;
 
1320
                int i, which;
 
1321
 
 
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))
 
1330
                {
 
1331
                        guchar *ns;
 
1332
                        GdkAtom target;
 
1333
                        gint format, len;
 
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);
 
1337
                }
 
1338
        }
 
1339
        /* Other kinds get handled outside */
 
1340
        else if (slot) clip_evt(sel, info, slot);
1285
1341
}
1286
1342
 
1287
1343
static void selection_clear_callback(GtkWidget *widget, GdkEventSelection *event,
1289
1345
{
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);
1293
1351
}
1294
1352
 
1295
1353
// !!! GTK+ 1.2 internal type (gtk/gtkselection.c)
1298
1356
        GtkTargetList *list;
1299
1357
} GtkSelectionTargetList;
1300
1358
 
1301
 
static int offer_clipboard(void **slot)
 
1359
static int offer_clipboard(void **slot, int text)
1302
1360
{
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;
1308
1368
        GdkAtom sel;
1309
 
        int which, res = FALSE, nw = (int)desc[2] & CLIPMASK;
1310
 
 
 
1369
        int which, res = FALSE, nw = (int)desc[2] & CLIPMASK, ntargets = cd->n;
 
1370
 
 
1371
 
 
1372
        if (text) targets = text_targets , ntargets = TEXT_CNT , info = text_on_offer;
1311
1373
        for (which = 0; (1 << which) <= nw; which++)
1312
1374
        {
1313
1375
                if (!((1 << which) & nw)) continue;
1331
1393
                        "gtk-selection-handlers", list);
1332
1394
 
1333
1395
                // !!! Have to resort to this to allow for multiple X clipboards
1334
 
                g_dataset_set_data(main_window, which ? "PRIMARY" : "CLIPBOARD",
1335
 
                        (gpointer)slot);
 
1396
                g_dataset_set_data(main_window, which ? "PRIMARY" : "CLIPBOARD", info);
1336
1397
                if (!connected)
1337
1398
                {
1338
1399
                        gtk_signal_connect(GTK_OBJECT(main_window), "selection_get",
1342
1403
                        connected = TRUE;
1343
1404
                }
1344
1405
 
1345
 
                gtk_selection_add_targets(main_window, sel, cd->ent, cd->n);
 
1406
                gtk_selection_add_targets(main_window, sel, targets, ntargets);
1346
1407
                res = TRUE;
1347
1408
        }
1348
1409
 
1349
1410
        return (res);
1350
1411
}
1351
1412
 
 
1413
static void offer_text(void **slot, char *s)
 
1414
{
 
1415
        void **desc = slot[1];
 
1416
        int i, nw = (int)desc[2] & CLIPMASK;
 
1417
 
 
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;
 
1422
 
 
1423
        if (!text_tlist) text_tlist = gtk_target_list_new(text_targets, TEXT_CNT);
 
1424
 
 
1425
        offer_clipboard(slot, TRUE);
 
1426
}
 
1427
 
1352
1428
#else /* if GTK_MAJOR_VERSION == 2 */
1353
1429
 
1354
1430
#ifdef GDK_WINDOWING_X11
1426
1502
        clip_evt(NULL, 0, user_data);
1427
1503
}
1428
1504
 
1429
 
static int offer_clipboard(void **slot)
 
1505
static int offer_clipboard(void **slot, int unused)
1430
1506
{
1431
1507
        void **desc = slot[1];
1432
1508
        clipform_data *cd = slot[0];
1449
1525
        return (res);
1450
1526
}
1451
1527
 
 
1528
static void offer_text(void **slot, char *s)
 
1529
{
 
1530
        void **desc = slot[1];
 
1531
        int which, nw = (int)desc[2] & CLIPMASK;
 
1532
 
 
1533
        for (which = 0; (1 << which) <= nw; which++)
 
1534
        {
 
1535
                if (!((1 << which) & nw)) continue;
 
1536
                gtk_clipboard_set_text(gtk_clipboard_get(which ?
 
1537
                        GDK_SELECTION_PRIMARY : GDK_SELECTION_CLIPBOARD), s, -1);
 
1538
        }
 
1539
}
 
1540
 
1452
1541
#endif
1453
1542
 
1454
1543
#undef CLIPMASK
8643
8732
                        pp[0], pp[1] - pp[0]);
8644
8733
                break;
8645
8734
        }
 
8735
        case op_CLIPBOARD:
 
8736
                offer_text(slot, res);
 
8737
                break;
8646
8738
#if GTK_MAJOR_VERSION == 2
8647
8739
        case op_FONTSEL:
8648
8740
        {
8722
8814
                (op == op_MENURITEM) || (op == op_uMENURITEM));
8723
8815
        if (op == op_CLIPBOARD)
8724
8816
        {
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));
8727
8819
        }
8728
8820
        else if (op == op_EV_MOUSE)