1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473
|
/* gap_fmac_main.c
* 2003.11.08 hof (Wolfgang Hofer)
*
* GAP ... Gimp Animation Plugins
*
* This Module contains:
* - filtermacros
*
* the GIMP-GAP filtermacro implementation introduces
* LIMITED macro features into GIMP-1.3.x
*
* WARNING:
* filtermacros are a temporary solution, useful for animations
* but do not expect support for filtermacros in future releases of GIMP-GAP
* because GIMP may have real makro features in the future ...
*
*
*/
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* SYTEM (UNIX) includes */
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <glib/gstdio.h>
/* GIMP includes */
#include "gtk/gtk.h"
#include "libgimp/gimp.h"
#include "libgimp/gimpui.h"
/* GAP includes */
#include "config.h"
#include "gap-intl.h"
#include "gap_lib.h"
#include "gap_val_file.h"
#include "gap_filter.h"
#include "gap_filter_pdb.h"
#include "gap_fmac_name.h"
#include "gap_fmac_base.h"
#include "gap_dbbrowser_utils.h"
#include "gap_lastvaldesc.h"
#include "gap_fmac_context.h"
/* revision history:
* gimp 1.3.26b; 2004/02/29 hof: bugfix NONINTERACTIVE call did crash
* gimp 1.3.22c; 2003/11/12 hof: button sensitivity
* gimp 1.3.22b; 2003/11/09 hof: created (based on old unpublished patches for gimp-1.2)
*/
/* from gap_fmac_name.h: GAP_FMACNAME_PLUG_IN_NAME_FMAC */
#define HELP_ID_NAME_FMAC "plug-in-filter-macro"
#define GAP_DB_BROWSER_FMAC_HELP_ID "gap-filtermacro-db-browser"
#define FMAC_FILE_LENGTH 1500
/* ------------------------
* global gap DEBUG switch
* ------------------------
*/
/* int gap_debug = 1; */ /* print debug infos */
/* int gap_debug = 0; */ /* 0: dont print debug infos */
int gap_debug = 0;
/* ############################################################# */
typedef struct
{
GtkWidget *dialog;
GtkListStore *store;
GtkWidget *tv;
GtkTreeSelection *sel;
gint selected_number;
GtkWidget *file_entry;
GtkWidget *filesel;
GtkWidget *ok_button;
GtkWidget *add_button;
GtkWidget *delete_button;
GtkWidget *delete_all_button;
gchar filtermacro_file[FMAC_FILE_LENGTH];
gint32 image_id;
gint32 drawable_id;
gboolean run_flag;
} fmac_globalparams_t; /* gpp */
gint gap_fmac_dialog(GimpRunMode run_mode, gint32 image_id, gint32 drawable_id);
static gchar * p_get_filtername(const char *line);
static void p_procedure_select_callback (GtkTreeSelection *sel, fmac_globalparams_t *gpp);
static void p_tree_fill (fmac_globalparams_t *gpp);
static void p_close_callback (GtkWidget *widget, fmac_globalparams_t *gpp);
static void p_ok_callback (GtkWidget *widget, fmac_globalparams_t *gpp);
static void p_help_callback (GtkWidget *widget, fmac_globalparams_t *gpp);
static void p_add_callback (GtkWidget *widget, fmac_globalparams_t *gpp);
static void p_delete_callback (GtkWidget *widget, fmac_globalparams_t *gpp);
static void p_delete_all_callback (GtkWidget *widget, fmac_globalparams_t *gpp);
static void p_filebrowser_button_callback (GtkWidget *widget, fmac_globalparams_t *gpp);
static void p_filesel_ok_callback(GtkWidget *widget, fmac_globalparams_t *gpp);
static void p_file_entry_update_callback(GtkWidget *widget, fmac_globalparams_t *gpp);
static void p_filesel_close_callback(GtkWidget *widget, fmac_globalparams_t *gpp);
static void p_create_action_area_buttons(fmac_globalparams_t *gpp);
static void p_setbutton_sensitivity(fmac_globalparams_t *gpp);
static gboolean p_chk_filtermacro_file(const char *filtermacro_file);
static void p_print_and_free_msg(char *msg, GimpRunMode run_mode);
static gchar * p_get_gap_filter_data_string(const char *plugin_name);
static gchar * p_get_mapped_gap_filter_data_string(const char *plugin_name, const char *filtermacro_file);
static gint p_fmac_add_filter_to_file(const char *filtermacro_file, const char *plugin_name);
static gint p_fmac_add_filter(const char *filtermacro_file, gint32 image_id);
static int p_fmac_pdb_constraint_proc(gchar *proc_name, gint32 image_id);
static int p_fmac_pdb_constraint_proc_sel1(gchar *proc_name, gint32 image_id);
static int p_fmac_pdb_constraint_proc_sel2(gchar *proc_name, gint32 image_id);
/* ############################################################# */
static void query(void);
static void run(const gchar *name
, gint n_params
, const GimpParam *param
, gint *nreturn_vals
, GimpParam **return_vals);
GimpPlugInInfo PLUG_IN_INFO =
{
NULL, /* init_proc */
NULL, /* quit_proc */
query, /* query_proc */
run, /* run_proc */
};
MAIN ()
static void
query ()
{
static gchar filtermacro_file[FMAC_FILE_LENGTH];
static GimpLastvalDef lastvals[] =
{
GIMP_LASTVALDEF_ARRAY (GIMP_ITER_FALSE, filtermacro_file, "filtermacro_scriptname"),
GIMP_LASTVALDEF_GCHAR (GIMP_ITER_FALSE, filtermacro_file[0], "filtermacro_scriptname"),
};
static GimpParamDef args_fmac_dialog[] =
{
{GIMP_PDB_INT32, "run_mode", "Interactive"},
{GIMP_PDB_IMAGE, "image", "Input image"},
{GIMP_PDB_DRAWABLE, "drawable", "Input drawable to be affected by the filtermacro"},
{GIMP_PDB_STRING, "filtermacro_name", "Name of the filtermacro_file to execute on the input drawable)"},
};
static GimpParamDef *return_vals = NULL;
static int nreturn_vals = 0;
gimp_plugin_domain_register (GETTEXT_PACKAGE, LOCALEDIR);
/* registration for last values buffer structure (useful for animated filter apply) */
gimp_lastval_desc_register(GAP_FMACNAME_PLUG_IN_NAME_FMAC,
&filtermacro_file[0],
sizeof(filtermacro_file),
G_N_ELEMENTS (lastvals),
lastvals);
gimp_install_procedure(GAP_FMACNAME_PLUG_IN_NAME_FMAC,
"This plug-in can create and execute filtermacro scriptfiles",
"This plug-in allows the user to pick one or more filters "
"that have already been called before in the current Gimp session. "
"The internal PDB-name of the picked filter is stored in a "
"filtermacro scriptfile, along with the parameter buffer that was "
"used at the last call.\n"
"You can execute a filtermacro scriptfile on the Input drawable "
"(in the current or in any further Gimp session). "
"The non-interactive API is limited to filtermacro script execution "
"and does not allow creation or modification of filtermacro scripts "
"WARNING: filtermacro scriptfiles are a temporary solution. "
"They are machine dependent. Support may be dropped in future gimp "
"versions.",
"Wolfgang Hofer (hof@gimp.org)",
"Wolfgang Hofer",
GAP_VERSION_WITH_DATE,
N_("Filtermacro..."),
"RGB*, INDEXED*, GRAY*",
GIMP_PLUGIN,
G_N_ELEMENTS (args_fmac_dialog), nreturn_vals,
args_fmac_dialog, return_vals);
gimp_plugin_menu_register (GAP_FMACNAME_PLUG_IN_NAME_FMAC, N_("<Image>/Filters/"));
} /* end query */
static void
run(const gchar *name
, gint n_params
, const GimpParam *param
, gint *nreturn_vals
, GimpParam **return_vals)
{
static GimpParam values[1];
GimpRunMode run_mode;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
gint32 image_id;
gint32 drawable_id;
char *filtermacro_file;
gint32 l_rc;
const char *l_env;
*nreturn_vals = 1;
*return_vals = values;
l_rc = 0;
l_env = g_getenv("GAP_DEBUG");
if(l_env != NULL)
{
if((*l_env != 'n') && (*l_env != 'N')) gap_debug = 1;
}
run_mode = param[0].data.d_int32;
image_id = param[1].data.d_image;
drawable_id = param[2].data.d_drawable;
filtermacro_file = NULL;
INIT_I18N ();
if(gap_debug) fprintf(stderr, "\n\ngap_filter_main: debug name = %s\n", name);
if (strcmp (name, GAP_FMACNAME_PLUG_IN_NAME_FMAC) == 0)
{
if (run_mode == GIMP_RUN_INTERACTIVE)
{
l_rc = gap_fmac_dialog(run_mode, image_id, drawable_id);
}
else
{
if (run_mode == GIMP_RUN_NONINTERACTIVE)
{
if(n_params == 4)
{
filtermacro_file = param[3].data.d_string;
if(filtermacro_file == NULL)
{
status = GIMP_PDB_CALLING_ERROR;
}
}
else
{
status = GIMP_PDB_CALLING_ERROR;
}
}
else
{
gint l_len;
l_len = gimp_get_data_size(GAP_FMACNAME_PLUG_IN_NAME_FMAC);
if(l_len > 0)
{
filtermacro_file = g_malloc0(l_len);
gimp_get_data(GAP_FMACNAME_PLUG_IN_NAME_FMAC, filtermacro_file);
}
else
{
filtermacro_file = g_strdup("\0");
}
}
if(status == GIMP_PDB_SUCCESS)
{
l_rc = gap_fmac_execute(run_mode, image_id, drawable_id
, filtermacro_file
, NULL /* filtermacro_file2 */
, 1.0 /* current_step */
, 1 /* total_steps */
);
}
}
}
else
{
status = GIMP_PDB_CALLING_ERROR;
}
if(l_rc < 0)
{
status = GIMP_PDB_EXECUTION_ERROR;
}
if (run_mode != GIMP_RUN_NONINTERACTIVE)
gimp_displays_flush();
values[0].type = GIMP_PDB_STATUS;
values[0].data.d_status = status;
} /* end run */
/* ----------------------
* p_chk_filtermacro_file
* ----------------------
*/
static gboolean
p_chk_filtermacro_file(const char *filtermacro_file)
{
FILE *l_fp;
char l_buf[400];
gboolean l_rc;
l_buf[0] = '\0';
l_rc = FALSE;
l_fp = g_fopen(filtermacro_file, "r");
if (l_fp)
{
/* file exists, check for header */
fgets(l_buf, sizeof(l_buf)-1, l_fp);
if (strncmp(l_buf, "# FILTERMACRO FILE", strlen("# FILTERMACRO FILE")) == 0)
{
l_rc = TRUE;
}
fclose(l_fp);
}
return l_rc;
} /* end p_chk_filtermacro_file */
/* --------------------
* p_print_and_free_msg
* --------------------
*/
static void
p_print_and_free_msg(char *msg, GimpRunMode run_mode)
{
if(run_mode == GIMP_RUN_INTERACTIVE)
{
g_message("%s", msg);
}
printf("%s\n", msg);
g_free(msg);
} /* end p_print_and_free_msg */
/* ----------------------------
* p_get_gap_filter_data_string
* ----------------------------
* return a textstring with the plugin_name
* and its values as textstring
* that has format like this:
* "plug_in_name" len hexbyte1 hexbyte2 .......\n
* example:
* "plug_in_sharpen" 4 0a 00 00 00
*
* return data_string or NULL pointer if nothing was found.
* the returned data_string should be g_free'd by the caller (if it was not NULL)
*/
static gchar *
p_get_gap_filter_data_string(const char *plugin_name)
{
gint plugin_data_len;
int l_byte;
gint l_idx;
gchar *l_str;
gchar *l_str_tmp;
guchar *plugin_data;
gchar *data_string;
data_string = NULL;
plugin_data = NULL;
if(gap_debug)
{
printf("p_get_gap_filter_data_string: plugin_name:%s:\n", plugin_name);
}
plugin_data_len = gimp_get_data_size (plugin_name);
if (plugin_data_len > 0)
{
/* retrieve the data */
plugin_data = g_malloc0(plugin_data_len);
gimp_get_data(plugin_name, plugin_data);
/* build the textstring, starting with quoted plug_in name and decimal datalength field
*/
l_str_tmp = g_strdup_printf("\"%s\" %4d ", plugin_name, (int)plugin_data_len);
/* add hex databytes */
for (l_idx = 0; l_idx < plugin_data_len; l_idx++)
{
l_byte = plugin_data[l_idx];
l_str = g_strdup_printf("%s %02x", l_str_tmp, l_byte);
g_free(l_str_tmp);
l_str_tmp = g_strdup(l_str);
g_free(l_str);
}
/* add terminating newline character */
l_str = g_strdup_printf("%s\n", l_str_tmp);
g_free(l_str_tmp);
if (gap_debug)
{
printf("p_get_gap_filter_data_string: %s", l_str);
}
data_string = l_str;
g_free(plugin_data);
}
return (data_string);
} /* end p_get_gap_filter_data_string */
/* -----------------------------------
* p_get_mapped_gap_filter_data_string
* -----------------------------------
* return a textstring with the plugin_name
* and its values as textstring
* that has format like this:
* "plug_in_name" len hexbyte1 hexbyte2 .......\n
* example:
* "plug_in_sharpen" 4 0a 00 00 00
*
*
* In case the plugin has at least one iterable drawable id within its last values parameters
* those values are mapped to persistent_drawable_id's with the help of a special
* iterator call with a filtermacro context and a corresponding .fmref file in recording mode.
*
* return data_string or NULL pointer if nothing was found.
* the returned data_string should be g_free'd by the caller (if it was not NULL)
*
*/
static gchar *
p_get_mapped_gap_filter_data_string(const char *plugin_name, const char *filtermacro_file)
{
static char l_key_from[512];
static char l_key_to[512];
gint plugin_data_len;
guchar *plugin_data_bck;
gchar *data_string;
const char *l_iteratorname;
gint l_count;
data_string = NULL;
if(plugin_name == NULL)
{
return (NULL);
}
plugin_data_len = gimp_get_data_size (plugin_name);
if(gap_debug)
{
printf("p_get_mapped_gap_filter_data_string: plugin_name:%s: plugin_data_len:%d\n"
, plugin_name
, plugin_data_len
);
}
/* assign the matching Iterator PluginProcedures (if there is any) */
l_iteratorname = gap_filt_pdb_get_iterator_proc(plugin_name, &l_count);
if ((plugin_data_len > 0) && (l_iteratorname != NULL))
{
GapFmacContext theFmacContext;
GapFmacContext *fmacContext;
fmacContext = &theFmacContext;
if(gap_debug)
{
printf("p_get_mapped_gap_filter_data_string: l_iteratorname:%s:\n"
, l_iteratorname
);
}
gap_fmct_setup_GapFmacContext(fmacContext
, TRUE /* recording_mode */
, filtermacro_file
);
/* retrieve the data (to backup original data) */
plugin_data_bck = g_malloc0(plugin_data_len);
gimp_get_data(plugin_name, plugin_data_bck);
/* Set FROM and TO buffers.
* (in recording mode we use all the same data as the backup of the original buffer)
* those buffers are not relevant in recording mode, but are required
* for the iterator call interface.
*/
g_snprintf(l_key_from, sizeof(l_key_from), "%s%s", plugin_name, GAP_ITER_TO_SUFFIX);
gimp_set_data(l_key_from, plugin_data_bck, plugin_data_len);
g_snprintf(l_key_to, sizeof(l_key_to), "%s%s", plugin_name, GAP_ITER_FROM_SUFFIX);
gimp_set_data(l_key_to, plugin_data_bck, plugin_data_len);
/* call the iterator in recording mode
* this triggers the mapping of drawable ids in the persistent .fmref file.
* (but only in case the called plugin has at least one an iterable drawable_id in its last_values paramters,
* otherwise the las values buffer shall not change by the iteratorcall,
* due to same settings for from and to values)
*/
gap_filter_iterator_call(l_iteratorname
, 1 /* total_steps */
, 1.0 /* current_step */
, plugin_name
, plugin_data_len
);
data_string = p_get_gap_filter_data_string(plugin_name);
/* restore original data from backup buffer */
gimp_set_data(plugin_name, plugin_data_bck, plugin_data_len);
g_free(plugin_data_bck);
/* disable the sessionwide filtermacro context */
gap_fmct_disable_GapFmacContext();
}
return (data_string);
} /* end p_get_mapped_gap_filter_data_string */
/* -------------------------
* p_fmac_add_filter_to_file
* -------------------------
*/
static gint
p_fmac_add_filter_to_file(const char *filtermacro_file, const char *plugin_name)
{
FILE *fp;
gint l_rc;
l_rc = -1;
if(gap_lib_file_exists(filtermacro_file) == 0 )
{
/* file does not exist, or is empty */
fp = g_fopen(filtermacro_file, "w");
if(fp)
{
fprintf(fp, "# FILTERMACRO FILE (GIMP-GAP-1.3)\n");
fprintf(fp, "# lineformat: \n");
fprintf(fp, "# 1.st item plug-in PDB name in double quotes\n");
fprintf(fp, "# 2.nd item decimal length of lastvalue data plug-in PDB name in double quotes\n");
fprintf(fp, "# 3.rd until N items hex bytevalues of lastvalue data buffer\n");
fprintf(fp, "#\n");
}
}
else
{
fp = g_fopen(filtermacro_file, "a");
}
if (fp)
{
char *data_string;
char *canonical_plugin_name;
canonical_plugin_name = gimp_canonicalize_identifier(plugin_name);
data_string = p_get_mapped_gap_filter_data_string(canonical_plugin_name, filtermacro_file);
g_free(canonical_plugin_name);
if(data_string)
{
fprintf(fp, "%s", data_string);
l_rc = 0; /* OK */
g_free(data_string);
}
fclose(fp);
}
return (l_rc);
} /* end p_fmac_add_filter_to_file */
/* -----------------
* p_fmac_add_filter
* -----------------
* pick a filter via GAP-DB-Browser dialog and add its name
* and its last_values buffer (parameter settings of last call in the
* current GIMP-session) to the end of thefiltermacro_file
*/
static gint
p_fmac_add_filter(const char *filtermacro_file, gint32 image_id)
{
GapDbBrowserResult l_browser_result;
if(gap_db_browser_dialog( _("Select Filtercalls of Current GIMP Session")
, NULL /* dont use the 1.st action button at all */
, _("Add Filter")
, p_fmac_pdb_constraint_proc
, p_fmac_pdb_constraint_proc_sel1
, p_fmac_pdb_constraint_proc_sel2
, &l_browser_result
, image_id
, GAP_DB_BROWSER_FMAC_HELP_ID
)
< 0)
{
if(gap_debug) printf("DEBUG: gap_db_browser_dialog cancelled\n");
return -1;
}
return(p_fmac_add_filter_to_file(filtermacro_file, l_browser_result.selected_proc_name));
} /* end p_fmac_add_filter */
/* ---------------
* gap_fmac_dialog
* ---------------
* create and perform the flitermacro dialog
*/
gint
gap_fmac_dialog(GimpRunMode run_mode, gint32 image_id, gint32 drawable_id)
{
GtkWidget *table;
GtkWidget *vbox;
GtkWidget *label;
GtkWidget *entry;
GtkWidget *button;
GtkWidget *scrolled_window;
GtkCellRenderer *renderer;
fmac_globalparams_t *gpp;
gint row;
gimp_ui_init ("gap-filter-macro", FALSE);
gpp = g_new0 (fmac_globalparams_t, 1);
gpp->run_flag = FALSE;
gpp->filtermacro_file[0] = '\0';
gpp->selected_number = -1;
/* probably get filtermacro_file (form a previous call in the same GIMP-session) */
gimp_get_data(GAP_FMACNAME_PLUG_IN_NAME_FMAC, gpp->filtermacro_file);
gpp->filesel = NULL;
gpp->image_id = image_id;
gpp->drawable_id = drawable_id;
/* the dialog box */
gpp->dialog = gtk_dialog_new ();
gtk_window_set_title (GTK_WINDOW (gpp->dialog), _("Filter Macro Script"));
gtk_window_set_position (GTK_WINDOW (gpp->dialog), GTK_WIN_POS_MOUSE);
g_signal_connect (gpp->dialog, "destroy",
G_CALLBACK (p_close_callback), gpp);
/* vbox : the list and the search entry */
vbox = gtk_vbox_new (FALSE, 4);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (gpp->dialog)->vbox),
vbox, TRUE, TRUE, 0);
gtk_widget_show (vbox);
/* table */
table = gtk_table_new (1, 3, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (table), 4);
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
gtk_container_set_border_width (GTK_CONTAINER (table), 4);
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
gtk_widget_show (table);
row = 0;
/* label */
label = gtk_label_new(_("Filename:"));
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
gtk_table_attach(GTK_TABLE(table), label, 0, 1, row, row + 1, 0, 0, 0, 0);
gtk_widget_show(label);
/* entry */
entry = gtk_entry_new();
gpp->file_entry = entry;
gtk_widget_set_size_request(entry, 300, -1);
gtk_entry_set_text(GTK_ENTRY(entry), gpp->filtermacro_file);
gtk_table_attach(GTK_TABLE(table), entry, 1, 2, row, row + 1, GTK_FILL | GTK_EXPAND, GTK_FILL, 4, 0);
gimp_help_set_help_data(entry
, _("Name of the filtermacro scriptfile")
,NULL);
gtk_widget_show(entry);
g_signal_connect(G_OBJECT(entry), "changed",
G_CALLBACK (p_file_entry_update_callback),
gpp);
/* Button to invoke filebrowser */
button = gtk_button_new_with_label ("...");
gimp_help_set_help_data(button
, _("Open filebrowser window to select a filename")
,NULL);
gtk_table_attach( GTK_TABLE(table), button, 2, 3, row, row +1,
0, 0, 0, 0 );
gtk_widget_show (button);
g_signal_connect (G_OBJECT (button), "clicked",
G_CALLBACK (p_filebrowser_button_callback),
gpp);
/* list : list in a scrolled_win */
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
GTK_SHADOW_IN);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_ALWAYS);
gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, TRUE, TRUE, 0);
gtk_widget_show (scrolled_window);
gpp->tv = gtk_tree_view_new ();
renderer = gtk_cell_renderer_text_new ();
gtk_cell_renderer_text_set_fixed_height_from_font
(GTK_CELL_RENDERER_TEXT (renderer), 1);
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (gpp->tv),
-1, _("Nr"),
renderer,
"text", 1,
NULL);
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (gpp->tv),
-1, _("PDB Name"),
renderer,
"text", 2,
NULL);
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (gpp->tv),
-1, _("Menu Path"),
renderer,
"text", 3,
NULL);
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (gpp->tv), TRUE);
gtk_widget_set_size_request (gpp->tv, 320 /*WIDTH*/, 100 /*HEIGHT*/);
gtk_container_add (GTK_CONTAINER (scrolled_window), gpp->tv);
gtk_widget_show (gpp->tv);
gpp->sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (gpp->tv));
g_signal_connect (gpp->sel, "changed",
G_CALLBACK (p_procedure_select_callback), gpp);
/* buttons in action_aera */
p_create_action_area_buttons(gpp);
gtk_widget_show (gpp->dialog);
/* now build the list */
p_tree_fill (gpp);
/* GTK Main Loop */
gtk_main ();
gdk_flush ();
if(gpp->filtermacro_file[0] != '\0')
{
gimp_set_data(GAP_FMACNAME_PLUG_IN_NAME_FMAC, gpp->filtermacro_file, FMAC_FILE_LENGTH);
if(gpp->run_flag)
{
if(gap_debug) printf("gap_fmac_dialog: RUN image_id:%d drawable_id:%d, filtermacro_file:%s\n"
,(int)image_id
,(int)drawable_id
,gpp->filtermacro_file
);
return(gap_fmac_execute(run_mode, image_id, drawable_id
, gpp->filtermacro_file
, NULL /* filtermacro_file2 */
, 1.0 /* current_step */
, 1 /* total_steps */
));
}
}
return 0;
} /* end gap_fmac_dialog */
/* ----------------------------
* p_get_filtername
* ----------------------------
* input is a typical filtermacro file line
* if the line contains a filtername (starting with double quotes character)
* the return a copy of the extracted filtername (without quotes)
* else: return NULL
*/
static gchar *
p_get_filtername(const char *line)
{
if(*line == '"')
{
gchar *filtername;
gchar *ptr;
filtername = g_strdup(&line[1]);
ptr = filtername;
while(ptr)
{
if((*ptr == '\n') || (*ptr == '\0') || (*ptr == '"'))
{
*ptr = '\0';
break;
}
ptr++;
}
return(filtername);
}
return NULL;
} /* end p_get_filtername */
/* ----------------------------
* p_procedure_select_callback
* ----------------------------
* fill filternames into the treeview
*/
static void
p_procedure_select_callback (GtkTreeSelection *sel, fmac_globalparams_t *gpp)
{
GtkTreeIter iter;
gchar *numtxt;
g_return_if_fail (sel != NULL);
g_return_if_fail (gpp != NULL);
if (gtk_tree_selection_get_selected (sel, NULL, &iter))
{
/* get column 0 (the invisible intenal number) from the store */
gtk_tree_model_get (GTK_TREE_MODEL (gpp->store), &iter
,0, &numtxt
, -1);
if (gap_debug) printf("p_procedure_select_callback (3) numtxt:%s\n", numtxt);
gpp->selected_number = atoi(numtxt);
g_free (numtxt);
}
}
/* ----------------------------
* p_tree_fill
* ----------------------------
* fill filternames into the treeview
*/
static void
p_tree_fill (fmac_globalparams_t *gpp)
{
GtkTreeIter iter;
gint count_elem;
gboolean parse_file;
GapValTextFileLines *txf_ptr;
GapValTextFileLines *txf_ptr_root;
gpp->store = gtk_list_store_new (4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
gtk_tree_view_set_model (GTK_TREE_VIEW (gpp->tv)
,GTK_TREE_MODEL (gpp->store)
);
g_object_unref (gpp->store);
/* read filternames from filtermacro_file
* and add them to the treeview widget
*/
count_elem = 0;
parse_file = FALSE;
if(gpp->filtermacro_file[0] != '\0')
{
if(p_chk_filtermacro_file(gpp->filtermacro_file))
{
parse_file = TRUE;
}
}
if(parse_file)
{
txf_ptr_root = gap_val_load_textfile(gpp->filtermacro_file);
for(txf_ptr = txf_ptr_root; txf_ptr != NULL; txf_ptr = (GapValTextFileLines *) txf_ptr->next)
{
gchar *pdb_name;
pdb_name = p_get_filtername(txf_ptr->line);
if(pdb_name)
{
gchar *numtxt;
gchar *label;
gchar *menu_path;
menu_path = gap_db_get_plugin_menupath(pdb_name);
if(menu_path == NULL)
{
menu_path = g_strdup(_("** No menu path available **"));
}
label = g_strdup_printf("%3d.", (int)count_elem +1);
numtxt = g_strdup_printf("%d", (int)count_elem);
gtk_list_store_append (gpp->store, &iter);
gtk_list_store_set (gpp->store, &iter
,0, numtxt /* internal invisible number starting at 0 */
,1, label /* visible number starting at 1 */
,2, pdb_name
,3, menu_path
,-1);
g_free (numtxt);
g_free (label);
g_free (menu_path);
g_free (pdb_name);
count_elem++;
}
}
if(txf_ptr_root)
{
gap_val_free_textfile_lines(txf_ptr_root);
}
}
if (count_elem == 0)
{
gtk_list_store_append (gpp->store, &iter);
if((p_chk_filtermacro_file(gpp->filtermacro_file))
|| (gap_lib_file_exists(gpp->filtermacro_file) == 0 ))
{
gtk_list_store_set (gpp->store, &iter
,0, "-1"
,1, " "
,2, _("** Empty **")
,3, " "
,-1);
}
else
{
gtk_list_store_set (gpp->store, &iter
,0, "-1"
,1, " "
,2, _("** File is not a filtermacro **")
,3, " "
,-1);
}
}
gtk_tree_model_get_iter_first (GTK_TREE_MODEL (gpp->store), &iter);
gtk_tree_selection_select_iter (gpp->sel, &iter);
p_setbutton_sensitivity (gpp);
} /* end p_tree_fill */
/* ----------------------------
* p_create_action_area_buttons
* ----------------------------
* create action area buttons for the flitermacro dialog
*/
static void
p_create_action_area_buttons(fmac_globalparams_t *gpp)
{
GtkWidget *button;
GtkWidget *hbox;
hbox = gtk_hbutton_box_new ();
gtk_box_set_spacing (GTK_BOX (hbox), 2);
gtk_box_pack_end (GTK_BOX (GTK_DIALOG (gpp->dialog)->action_area), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG(gpp->dialog)->action_area), 0);
/* Button HELP */
if (gimp_show_help_button ())
{
button = gtk_button_new_from_stock ( GTK_STOCK_HELP);
gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
gimp_help_set_help_data(button
,_("Show help page")
, NULL);
g_signal_connect (G_OBJECT (button), "clicked"
,G_CALLBACK (p_help_callback)
,gpp
);
gtk_widget_show (button);
}
/* Button Delete All */
button = gtk_button_new_with_label (_("Delete All"));
gpp->delete_all_button = button;
gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
gimp_help_set_help_data(button
,_("Delete the filtermacro scriptfile")
, NULL);
g_signal_connect (G_OBJECT (button), "clicked"
,G_CALLBACK (p_delete_all_callback)
,gpp
);
gtk_widget_show (button);
/* Button Delete */
button = gtk_button_new_with_label (_("Delete"));
gpp->delete_button = button;
gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
gimp_help_set_help_data(button
,_("Delete the selected filtercall")
, NULL);
g_signal_connect (G_OBJECT (button), "clicked"
,G_CALLBACK (p_delete_callback)
,gpp
);
gtk_widget_show (button);
/* Button Add */
button = gtk_button_new_with_label (_("Add"));
gpp->add_button = button;
gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
gimp_help_set_help_data(button
,_("Open PDB-browser window to add a new filter "
"to the filtermacro scriptfile.\n"
"Important:\n"
"The PDB-browser shows only filters "
"that have already been used in the current session "
"and have setup the internal buffer with the "
"parameter settings of the last call")
, NULL);
g_signal_connect (G_OBJECT (button), "clicked"
,G_CALLBACK (p_add_callback)
,gpp
);
gtk_widget_show (button);
/* Button Cancel */
button = gtk_button_new_from_stock ( GTK_STOCK_CANCEL);
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
gimp_help_set_help_data(button
,_("Close window")
, NULL);
g_signal_connect (G_OBJECT (button), "clicked"
,G_CALLBACK (p_close_callback)
,gpp
);
gtk_widget_show (button);
/* Button OK */
button = gtk_button_new_from_stock ( GTK_STOCK_OK);
gpp->ok_button = button;
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
gimp_help_set_help_data(button
,_("Apply filtermacro script on current drawable and close window")
, NULL);
g_signal_connect (G_OBJECT (button), "clicked"
,G_CALLBACK (p_ok_callback)
,gpp
);
gtk_widget_show (button);
p_setbutton_sensitivity(gpp);
} /* end p_create_action_area_buttons */
/* ----------------------------
* p_setbutton_sensitivity
* ----------------------------
*/
static void
p_setbutton_sensitivity(fmac_globalparams_t *gpp)
{
gboolean sensitive_1;
gboolean sensitive_2;
sensitive_1 = FALSE;
sensitive_2 = FALSE;
if((gpp->filtermacro_file[0] != '\0')
&& (gpp->filtermacro_file[0] != ' '))
{
sensitive_2 = TRUE;
if(p_chk_filtermacro_file(gpp->filtermacro_file))
{
sensitive_1 = TRUE;
}
}
gtk_widget_set_sensitive(gpp->ok_button, sensitive_1);
gtk_widget_set_sensitive(gpp->delete_all_button, sensitive_1);
gtk_widget_set_sensitive(gpp->delete_button, sensitive_1);
gtk_widget_set_sensitive(gpp->add_button, sensitive_2);
} /* end p_setbutton_sensitivity */
/* ----------------------------
* p_close_callback
* ----------------------------
*/
static void
p_close_callback (GtkWidget *widget, fmac_globalparams_t *gpp)
{
GtkWidget *dlg;
if(gpp)
{
dlg = gpp->dialog;
gpp->dialog = NULL;
if(dlg)
{
gtk_widget_destroy (GTK_WIDGET (dlg)); /* close & destroy dialog window */
gtk_main_quit ();
}
}
else
{
gtk_main_quit ();
}
}
/* ----------------------------
* p_ok_callback
* ----------------------------
*/
static void
p_ok_callback (GtkWidget *widget, fmac_globalparams_t *gpp)
{
if(gpp)
{
gpp->run_flag = TRUE;
}
p_close_callback(NULL, gpp);
}
/* ----------------------------
* p_help_callback
* ----------------------------
*/
static void
p_help_callback (GtkWidget *widget, fmac_globalparams_t *gpp)
{
if(gpp)
{
gimp_standard_help_func(HELP_ID_NAME_FMAC, gpp->dialog);
}
}
/* ----------------------------
* p_delete_callback
* ----------------------------
* delete the selected line in the filtermacro_file
* the selcted_number counts only lines with filtercalls.
* (comment lines are kept, but are not counted)
*
* negative values in gpp->selected_number represent the
* "** Empty **" Label (if no valid filtermacro file is present)
* this line can not be deleted.
*/
static void
p_delete_callback (GtkWidget *widget, fmac_globalparams_t *gpp)
{
if(gpp)
{
if(gap_lib_file_exists(gpp->filtermacro_file) != 0 )
{
if(gap_debug) printf("p_delete_callback: selected_number:%d\n", (int)gpp->selected_number);
if(gpp->selected_number >= 0)
{
GapValTextFileLines *txf_ptr;
GapValTextFileLines *txf_ptr_root;
gint count_elem;
gchar *label;
FILE *fp;
gboolean copy_line;
/* rewrite the filtermacro file
* without the line that corresponds to gpp->selected_number
*/
txf_ptr_root = gap_val_load_textfile(gpp->filtermacro_file);
fp = g_fopen(gpp->filtermacro_file, "w");
if(fp)
{
count_elem = 0;
for(txf_ptr = txf_ptr_root; txf_ptr != NULL; txf_ptr = (GapValTextFileLines *) txf_ptr->next)
{
copy_line = TRUE;
label = p_get_filtername(txf_ptr->line);
if(label)
{
if(count_elem == gpp->selected_number)
{
copy_line = FALSE;
}
g_free(label);
count_elem++;
}
if(gap_debug) printf("%4d %s", (int)count_elem, txf_ptr->line);
if(copy_line)
{
fprintf(fp, "%s", txf_ptr->line);
}
}
fclose(fp);
}
if(txf_ptr_root)
{
gap_val_free_textfile_lines(txf_ptr_root);
}
}
}
p_tree_fill (gpp);
}
}
/* ----------------------------
* p_delete_all_callback
* ----------------------------
*/
static void
p_delete_all_callback (GtkWidget *widget, fmac_globalparams_t *gpp)
{
if(gpp)
{
if(p_chk_filtermacro_file(gpp->filtermacro_file))
{
g_remove(gpp->filtermacro_file);
}
p_tree_fill (gpp);
}
}
/* ----------------------------
* p_add_callback
* ----------------------------
*/
static void
p_add_callback (GtkWidget *widget, fmac_globalparams_t *gpp)
{
if(gpp)
{
if(gpp->filtermacro_file[0] != '\0')
{
gint l_rc;
errno = 0;
l_rc = p_fmac_add_filter(gpp->filtermacro_file, gpp->image_id);
if((l_rc < 0) && (errno != 0))
{
g_message(_("ERROR: Could not write filtermacro script\n"
"filename: '%s'\n%s")
,gpp->filtermacro_file, g_strerror (errno));
}
}
p_tree_fill (gpp);
}
}
/* -----------------------------
* p_filebrowser_button_callback
* -----------------------------
*/
static void
p_filebrowser_button_callback (GtkWidget *widget, fmac_globalparams_t *gpp)
{
GtkWidget *filesel;
if(gpp->filesel != NULL)
{
gtk_window_present(GTK_WINDOW(gpp->filesel));
return; /* filesel is already open */
}
filesel = gtk_file_selection_new ( _("Select Filtermacro Scriptfile"));
gpp->filesel = filesel;
gtk_window_set_position (GTK_WINDOW (filesel), GTK_WIN_POS_MOUSE);
g_signal_connect (G_OBJECT (GTK_FILE_SELECTION (filesel)->ok_button),
"clicked",
G_CALLBACK (p_filesel_ok_callback),
gpp);
g_signal_connect(G_OBJECT (GTK_FILE_SELECTION (filesel)->cancel_button),
"clicked",
G_CALLBACK (p_filesel_close_callback),
gpp);
gtk_file_selection_set_filename (GTK_FILE_SELECTION (filesel),
gpp->filtermacro_file);
gtk_widget_show (filesel);
/* "destroy" has to be the last signal,
* (otherwise the other callbacks are never called)
*/
g_signal_connect (G_OBJECT (filesel), "destroy",
G_CALLBACK (p_filesel_close_callback),
gpp);
}
/* ----------------------------
* p_filesel_close_callback
* ----------------------------
*/
static void
p_filesel_close_callback(GtkWidget *widget,
fmac_globalparams_t *gpp)
{
GtkWidget *filesel;
if(gpp == NULL) return;
filesel = gpp->filesel;
if(filesel == NULL) return;
gpp->filesel = NULL; /* now filesel is closed */
gtk_widget_destroy(GTK_WIDGET(filesel));
}
/* ----------------------------
* p_filesel_ok_callback
* ----------------------------
*/
static void
p_filesel_ok_callback(GtkWidget *widget,
fmac_globalparams_t *gpp)
{
const gchar *filename;
if(gpp == NULL) return;
filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (gpp->filesel));
g_snprintf(&gpp->filtermacro_file[0], sizeof(gpp->filtermacro_file), "%s", filename);
gtk_entry_set_text(GTK_ENTRY(gpp->file_entry), filename);
if (gap_debug) printf("p_filesel_ok_callback: %s\n", gpp->filtermacro_file);
p_filesel_close_callback(gpp->filesel, gpp);
}
/* ----------------------------
* p_file_entry_update_callback
* ----------------------------
*/
static void
p_file_entry_update_callback(GtkWidget *widget,
fmac_globalparams_t *gpp)
{
if(gpp)
{
g_snprintf(gpp->filtermacro_file, sizeof(gpp->filtermacro_file), "%s"
, gtk_entry_get_text(GTK_ENTRY(widget))
);
p_tree_fill (gpp);
}
}
/* ---------------------------------
* p_fmac_pdb_constraint_proc_sel1
* ---------------------------------
*/
static int
p_fmac_pdb_constraint_proc(gchar *proc_name, gint32 image_id)
{
int l_rc;
if(strncmp(proc_name, "file", 4) == 0)
{
/* Do not add file Plugins (check if name starts with "file") */
return 0;
}
if(strncmp(proc_name, "plug_in_gap_", 12) == 0)
{
/* Do not add GAP Plugins (check if name starts with "plug_in_gap_") */
return 0;
}
if(strcmp(proc_name, GAP_FMACNAME_PLUG_IN_NAME_FMAC) == 0)
{
/* Do not add the filtermacro plugin itself */
return 0;
}
l_rc = gap_filt_pdb_procedure_available(proc_name, GAP_PTYP_CAN_OPERATE_ON_DRAWABLE);
if(l_rc < 0)
{
/* Do not add, Plug-in not available or wrong type */
return 0;
}
return(p_fmac_pdb_constraint_proc_sel1(proc_name, image_id));
}
/* ---------------------------------
* p_fmac_pdb_constraint_proc_sel1
* ---------------------------------
*/
static int
p_fmac_pdb_constraint_proc_sel1(gchar *proc_name, gint32 image_id)
{
char *data_string;
data_string = p_get_gap_filter_data_string(proc_name);
if(data_string)
{
g_free(data_string);
return 1; /* 1 .. set "Add Filter" Button sensitive */
}
return 0; /* 0 .. set "Add Filter" Button insensitive */
}
/* ---------------------------------
* p_fmac_pdb_constraint_proc_sel2
* ---------------------------------
*/
static int
p_fmac_pdb_constraint_proc_sel2(gchar *proc_name, gint32 image_id)
{
return (p_fmac_pdb_constraint_proc_sel1 (proc_name, image_id));
}
|