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 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481
|
/*
*
* Copyright (c) International Business Machines Corp., 2001
*
* 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
*
* Module: widget.c
*/
#include <frontend.h>
#include <gtk/gtk.h>
#include <string.h>
#include "support.h"
#include "value.h"
#include "widget.h"
#include "task.h"
#include "thing.h"
#include "readable.h"
#include "logging.h"
/* Forward function declaration */
void set_option_radio_button_active_from_boolean (GtkToggleButton *yes_button, GtkToggleButton *no_button,
gboolean is_yes, option_widget_info_t *info);
/*
*
* void display_set_option_value_error (gint, gchar *, GtkWidget *)
*
* Description:
* This routine displays a results window identifying problems setting
* an option value.
*
* Entry:
* rc - the return code from evms_option_set_value()
* option_name - the name of the option that could not be set
* widget - the option widget
*
* Exit:
* A results window is displayed communicating the problem to the user.
*
*/
void display_set_option_value_error (gint rc, gchar *option_name, GtkWidget *widget)
{
gchar *error_msg;
error_msg = g_strdup_printf (_("An error occurred communicating the value for %s to the plugin."),
option_name);
display_results_window (rc, NULL, error_msg, NULL, FALSE, NULL);
g_free (error_msg);
}
/*
*
* void set_widget_option_value (option_widget_info_t *, value_t)
*
* Description:
* This routine gets called by most of the option callback routines
* after they have retrieved and converted the input data into a
* value_t. We essentially retrieve the task handle from the top
* level widget and attempt to set the new value. If the set is
* accepted we clear the old value in the widget_info and copy
* in the new value and clear the given value.
*
* Entry:
* info - everything we need to know about widget and option
* value - address of new value (in proper form and cleared
* on exit)
* was_value_modified - address to write TRUE if value was fudged
*
* Exit:
* The option value is updated and callout routine invoked.
* We return TRUE if given value was modified by backend so
* caller can update widget in their respective way. This
* function returns the error code of the set API so that
* the signal emission can be stopped if an error occurred.
*
*/
gint set_widget_option_value (option_widget_info_t *info, value_t *value, gboolean *was_value_modified)
{
gint rc;
task_effect_t effect;
task_handle_t task;
*was_value_modified = FALSE;
task = retrieve_task_handle_from_toplevel_widget (info->widget);
rc = evms_set_option_value_by_name (task, info->option->name, value, &effect);
log_debug ("%s: Called evms_set_option_value_by_name() for option %s. rc == %d.\n",
__FUNCTION__, info->option->name, rc);
if (rc != SUCCESS)
{
display_set_option_value_error (rc, info->option->name, info->widget);
}
else
{
guint list_count=0;
gboolean is_list;
options_callback_callout callout;
info->has_value = TRUE;
log_debug ("%s: evms_set_option_value_by_name() side-effect was %d\n", __FUNCTION__, effect);
callout = retrieve_options_callout_from_toplevel_widget (info->widget);
if (callout != NULL)
(*callout) (info, *value, effect);
*was_value_modified = effect & EVMS_Effect_Inexact;
is_list = EVMS_OPTION_VALUE_IS_LIST (info->option->flags);
if (is_list)
list_count = info->option->constraint.list->count;
/*
* Keep info->value up-to-date on a successful set operation.
*/
clear_value (&(info->value), info->option->type, is_list, list_count);
duplicate_value (*value, info->option->type, is_list, list_count,
info->option->size, &(info->value));
}
return rc;
}
/*
*
* void on_option_entry_focus_out (GtkEditable *, GdkEventFocus *event, option_widget_info_t *)
*
* Description:
* This routine gets called when an option entry has lost its
* focus. If the widget had any updates then we generate the
* "activate" signal so that it can provide the current text
* value to the plugin,
*
* Entry:
* editable - the id of the GtkEntry widget that lost focus
* event - focus event information
* info - address of the option widget info associated with widget
*
* Exit:
* We compare entry value and current value to see if they match.
* If not, we issue an "activate" signal in order to have the
* value updated in the plugin's eyes.
*
*/
void on_option_entry_focus_out (GtkEditable *editable, GdkEventFocus *event, option_widget_info_t *info)
{
gchar *text;
value_t value;
gboolean value_changed;
text = gtk_editable_get_chars (editable, 0, -1);
if ((info->option->flags & EVMS_OPTION_FLAGS_NO_UNIT_CONVERSION) == 0 &&
info->option->unit == EVMS_Unit_Sectors)
convert_size_string_to_sector_value (text, info->option->type, &value);
else
convert_string_to_value (text, info->option->type, info->option->size, &value);
value_changed = !values_are_equal (value, info->value, info->option->type);
if (value_changed)
gtk_signal_emit_by_name (GTK_OBJECT (editable), "activate", editable, info);
clear_value (&value, info->option->type, FALSE, 0);
g_free (text);
}
/*
*
* void on_option_check_button_toggled (GtkToggleButton *, option_widget_info_t *)
*
* Description:
* This routine gets called when an option checkbutton is toggled.
* We basically check the state of the button, convert the state
* to the boolean value, retrieve the task handle and call
* evms_set_option_value() to update the current option value for
* the task.
*
* Entry:
* button - the id of the toggle button that was pressed
* info - address of the option widget info associated with widget
*
* Exit:
* The option value is updated and if necessary we notify our top
* level window of sideaffects of the value update.
*
*/
void on_option_check_button_toggled (GtkToggleButton *button, option_widget_info_t *info)
{
gint rc;
value_t value;
gboolean value_changed;
log_entry;
value.bool = gtk_toggle_button_get_active (button);
rc = set_widget_option_value (info, &value, &value_changed);
if ((rc == SUCCESS && value_changed) || (rc != SUCCESS && info->has_value))
{
gtk_signal_handler_block_by_func (GTK_OBJECT (button), on_option_check_button_toggled, info);
gtk_toggle_button_set_active (button, info->value.bool);
gtk_signal_handler_unblock_by_func (GTK_OBJECT (button), on_option_check_button_toggled, info);
}
log_exit;
}
/*
*
* void on_option_radio_button_toggled (GtkToggleButton *, option_widget_info_t *)
*
* Description:
* This routine gets called when an option radio button is toggled.
* This routine deals with boolean radio buttons only. We test to
* see which button we are (the Yes or the No button) and then
* determine whether we are active and if the boolean value should
* be changed.
*
* Entry:
* button - the id of the toggle button that was pressed
* info - address of the option widget info associated with widget
*
* Exit:
* The option value is updated if necessary and we notify our top
* level window of sideaffects of the value update.
*
*/
void on_option_radio_button_toggled (GtkToggleButton *button, option_widget_info_t *info)
{
log_entry;
if (gtk_toggle_button_get_active (button))
{
gint rc;
value_t value;
gboolean value_changed;
GtkToggleButton *no_button;
GtkToggleButton *yes_button;
no_button = gtk_object_get_data (GTK_OBJECT (button), "no_button");
yes_button = gtk_object_get_data (GTK_OBJECT (button), "yes_button");
value.bool = button == yes_button;
rc = set_widget_option_value (info, &value, &value_changed);
if ((rc == SUCCESS && value_changed) || (rc != SUCCESS && info->has_value))
set_option_radio_button_active_from_boolean (yes_button, no_button, info->value.bool, info);
}
log_exit;
}
/*
*
* void set_option_radio_button_active_from_boolean (GtkToggleButton *, GtkToggleButton *,
* gboolean, option_widget_info_t *)
*
* Description:
* This routine sets either the yes or no radio button active depending
* on the value for the is_yes boolean.
*
* Entry:
* yes_button - the id of the Yes radio button
* no_button - the id of the No radio button
* is_yes - TRUE if the Yes button should active, FALSE for No button
* info - address of the option widget info associated with widget
*
* Exit:
* Either the Yes or No button is made the active button.
*
*/
void set_option_radio_button_active_from_boolean (GtkToggleButton *yes_button, GtkToggleButton *no_button,
gboolean is_yes, option_widget_info_t *info)
{
GtkToggleButton *active_button;
if (is_yes)
active_button = yes_button;
else
active_button = no_button;
gtk_signal_handler_block_by_func (GTK_OBJECT (active_button), on_option_radio_button_toggled, info);
gtk_toggle_button_set_active (active_button, TRUE);
gtk_signal_handler_unblock_by_func (GTK_OBJECT (active_button), on_option_radio_button_toggled, info);
}
/*
*
* void set_option_menu_history (GtkMenuShell *, option_widget_info_t *, value_t)
*
* Description:
* This routine sets the selected item in an GtkOptionMenu to the
* menu item corresponding to the value provided.
*
* Entry:
* menu - the GtkMenu containing the menu items (labels)
* info - address of the option widget info associated with widget
* value - the value that corresponds to the menu item to select
*
* Exit:
* The menu item corresponding to the value provided is made the
* selected item.
*
*/
void set_option_menu_history (GtkMenuShell *menu, option_widget_info_t *info, value_t value)
{
gint count;
GList *children;
children = gtk_container_children (GTK_CONTAINER (menu));
count = g_list_length (children);
if (count > 0)
{
gint i;
gint index;
gchar *text;
value_t menu_value;
GtkMenuItem *menuitem;
for (i=0,index=0; i < count; i++)
{
menuitem = g_list_nth_data (children, i);
if (GTK_IS_MENU_ITEM (menuitem))
{
if (GTK_IS_LABEL (GTK_BIN (menuitem)->child))
{
gtk_label_get (GTK_LABEL (GTK_BIN (menuitem)->child), &text);
if (info->option->unit == EVMS_Unit_Sectors)
convert_size_string_to_sector_value (text, info->option->type, &menu_value);
else
convert_string_to_value (text, info->option->type, info->option->size, &menu_value);
if (values_are_equal (value, menu_value, info->option->type))
{
/*
* Save the index of the menu item that matches and
* set the loop index to count so we can terminate
* the loop.
*/
index = i;
i = count;
}
clear_value (&menu_value, info->option->type, FALSE, 0);
}
}
}
gtk_option_menu_set_history (gtk_object_get_data (GTK_OBJECT (menu), "option_menu"),
index);
}
}
/*
*
* void on_option_menu_item_selected (GtkMenuShell *, option_widget_info_t *)
*
* Description:
* This routine gets called when an option menu item has been activated
* and the selection is complete. We convert the label text of the item
* selected to the corresponding value and update it.
*
* Entry:
* menu - the menu on which the item was selected
* info - address of the option widget info associated with widget
*
* Exit:
* The option value is updated and if necessary we notify our top
* level window of sideaffects of the value update.
*
*/
void on_option_menu_item_selected (GtkMenuShell *menu, option_widget_info_t *info)
{
log_entry;
if (GTK_BIN (info->widget)->child)
{
GtkWidget *child = GTK_BIN (info->widget)->child;
if (GTK_IS_LABEL (child))
{
gchar *text;
value_t value;
gtk_label_get (GTK_LABEL (child), &text);
if (strcasecmp (text, OPTION_MENU_NO_SELECTION_TEXT) == 0 )
{
options_callback_callout callout;
/*
* If the special menu item is selected then we take
* this to mean that nothing is selected so we turn
* the has_value flag off and invoke the callout
* routine to hopefully check to see if this was
* required in order to make the "Next" button insensitive.
*/
info->has_value = FALSE;
clear_value (&(info->value), info->option->type, FALSE, 0);
callout = retrieve_options_callout_from_toplevel_widget (info->widget);
if (callout != NULL)
(*callout) (info, info->value, 0);
}
else
{
gint rc;
gboolean value_changed;
if (info->option->unit == EVMS_Unit_Sectors)
convert_size_string_to_sector_value (text, info->option->type, &value);
else
convert_string_to_value (text, info->option->type, info->option->size, &value);
rc = set_widget_option_value (info, &value, &value_changed);
if (rc == SUCCESS)
{
GtkWidget *no_selection_menuitem;
/*
* Check to see if we need to walk through the menu
* items and set the history to the one the plugin chose.
*/
if (value_changed)
{
gtk_signal_handler_block_by_func (GTK_OBJECT (menu),
on_option_menu_item_selected,
info);
set_option_menu_history (menu, info, value);
gtk_signal_handler_unblock_by_func (GTK_OBJECT (menu),
on_option_menu_item_selected,
info);
}
/*
* If we have made a successful selection and we had the special no-selection
* menu item on the menu then this meant that the option had been a required
* option with no initial value. Now we have a value so we should remove our
* visual cue menu item.
*/
no_selection_menuitem = gtk_object_get_data (GTK_OBJECT (menu), "no_selection_menuitem");
if (no_selection_menuitem != NULL)
{
gtk_container_remove (GTK_CONTAINER (menu), no_selection_menuitem);
gtk_object_set_data (GTK_OBJECT (menu), "no_selection_menuitem", NULL);
}
}
else if (info->has_value)
{
/*
* Revert value to original value on error.
*/
gtk_signal_handler_block_by_func (GTK_OBJECT (menu),
on_option_menu_item_selected,
info);
set_option_menu_history (menu, info, info->value);
gtk_signal_handler_unblock_by_func (GTK_OBJECT (menu),
on_option_menu_item_selected,
info);
}
clear_value (&value, info->option->type, FALSE, 0);
}
}
}
log_exit;
}
/*
*
* void static inline update_option_entry_text (GtkEntry *, value_t, option_widget_info_t *)
*
* Description:
* This routine basically takes a value_t and converts it to a string
* and updates the entry box text.
*
* Entry:
* editable - the entry box to contain the next text
* info - address of the option widget info associated with widget
*
* Exit:
* The entry text is updated.
*
*/
void static inline update_option_entry_text (GtkEntry *entry, value_t value, option_widget_info_t *info)
{
gchar *text;
if ((info->option->flags & EVMS_OPTION_FLAGS_NO_UNIT_CONVERSION) == 0 &&
info->option->unit == EVMS_Unit_Sectors)
text = make_sectors_readable_string (convert_value_to_ui64 (value, info->option->type));
else
text = convert_value_to_string (value, info->option->type, EVMS_Format_Normal);
gtk_entry_set_text (entry, text == NULL ? "" : text);
g_free (text);
}
/*
*
* void on_option_entry_text_entered (GtkEditable *, option_widget_info_t *)
*
* Description:
* This routine gets called when the Enter keystroke is pressed
* in an option entry box.
*
* Entry:
* editable - the entry box containing the text
* info - address of the option widget info associated with widget
*
* Exit:
* The option value is updated and if necessary we notify our toplevel
* window of any update sideaffects.
*
*/
void on_option_entry_text_entered (GtkEditable *editable, option_widget_info_t *info)
{
gint rc;
gchar *entry_text;
value_t value;
gboolean value_changed;
log_entry;
entry_text = gtk_editable_get_chars (editable, 0, -1);
if ((info->option->flags & EVMS_OPTION_FLAGS_NO_UNIT_CONVERSION) == 0 &&
info->option->unit == EVMS_Unit_Sectors)
convert_size_string_to_sector_value (entry_text, info->option->type, &value);
else
convert_string_to_value (entry_text, info->option->type, info->option->size, &value);
rc = set_widget_option_value (info, &value, &value_changed);
if ((rc == SUCCESS && value_changed) || (rc != SUCCESS && info->has_value))
{
gtk_signal_handler_block_by_func (GTK_OBJECT (editable), on_option_entry_text_entered, info);
update_option_entry_text (GTK_ENTRY (editable), info->value, info);
gtk_signal_handler_unblock_by_func (GTK_OBJECT (editable), on_option_entry_text_entered, info);
}
clear_value (&value, info->option->type, FALSE, 0);
g_free (entry_text);
log_exit;
}
/*
*
* void on_option_entry_text_inserted (GtkEditable *, const gchar *, gint, gint *,option_descriptor_t *)
*
* Description:
* This routine gets called when text is inserted in an option
* entry box. This callback routine does not call
* evms_set_option_value() like the other callbacks. Instead,
* it does simple validation on the current value based upon
* known constraints such as maximum string size for a string
* and maximum value for a numeric type.
*
* Entry:
* editable - the entry box that had characters inserted
* new_text - string with new text to be inserted
* new_text_length - length of new text to insert
* position - the position at which to insert the new text
* info - address of the option widget info associated with widget
*
* Exit:
* Current value is validated, if the value is not proper we disallow
* the characters inserted and display a popup giving acceptable
* value information, e.g. "Only text shorter than x characters
* are accepted" or "Only integers from 0 to 65535 are accepted.".
*
*/
void on_option_entry_text_inserted (GtkEditable *editable, const gchar *new_text,
gint new_text_length, gint *position,
option_widget_info_t *info)
{
gchar *string;
gchar *inserted_text;
gchar *pre_insertion_text;
gchar *post_insertion_text;
gchar *acceptable_values_msg = NULL;
/*
* Build the string as it would look if the new text got inserted.
* Use the generated string for the validation.
*/
inserted_text = g_malloc0 (new_text_length + 1);
pre_insertion_text = gtk_editable_get_chars (editable, 0, *position);
post_insertion_text = gtk_editable_get_chars (editable, (*position)+1, -1);
g_memmove (inserted_text, new_text, new_text_length);
string = g_strconcat (pre_insertion_text, inserted_text, post_insertion_text, NULL);
if (info->option->type == EVMS_Type_String)
{
if (info->option->size < strlen (string))
acceptable_values_msg = g_strdup_printf (_("Only text shorter than %d characters is acceptable."),
info->option->size + 1);
}
else
acceptable_values_msg = validate_string_as_numeric_value (string, info->option->type);
if (acceptable_values_msg != NULL)
{
gchar *title = g_strdup_printf (_("Invalid input for %s"), info->option->title);
/*
* Validation error has occurred. Create a popup with the name
* of the field and the acceptable values text. Stop the
* "insert-text" from being emitted as the new text inserted
* was unacceptable.
*/
display_popup_window (title, acceptable_values_msg);
gtk_signal_emit_stop_by_name (GTK_OBJECT (editable), "insert_text");
g_free (title);
}
else
{
value_t value;
options_callback_callout callout;
/*
* Just in case this is the last entry widget, we indicate it
* now has a value. This should allow the "Next" button to get
* sensitized. This should lead the user to click on it which
* causes the entry widget to lose focus and have its value
* set.
*/
if ((info->option->flags & EVMS_OPTION_FLAGS_NO_UNIT_CONVERSION) == 0 &&
info->option->unit == EVMS_Unit_Sectors)
convert_size_string_to_sector_value (string, info->option->type, &value);
else
convert_string_to_value (string, info->option->type, info->option->size, &value);
info->has_value = TRUE;
callout = retrieve_options_callout_from_toplevel_widget (info->widget);
if (callout != NULL)
(*callout) (info, value, 0);
}
g_free (string);
g_free (pre_insertion_text);
g_free (post_insertion_text);
}
/*
*
* void on_option_adjustment_changed (GtkAdjustment *, option_widget_info_t *)
*
* Description:
* This routine gets called when an option widget with an adjustment
* such as a GtkHScale or GtkSpinButton has its value changed.
*
* Entry:
* adjustment - GtkAdjustment that has been changed with a new value
* info - address of the option widget info associated with widget
*
* Exit:
* The option value is updated and if necessary we notify our top
* level window of sideaffects of the value update.
*
*/
void on_option_adjustment_changed (GtkAdjustment *adjustment, option_widget_info_t *info)
{
gint rc;
value_t value;
gboolean value_changed;
log_entry;
if (info->option->unit == EVMS_Unit_Sectors && info->unit_conversion != info->option->unit)
convert_float_to_sector_value (adjustment->value, info->option->type,
info->unit_conversion, &value);
else
convert_float_to_value (adjustment->value, info->option->type, &value);
rc = set_widget_option_value (info, &value, &value_changed);
if ((rc == SUCCESS && value_changed) || (rc != SUCCESS && info->has_value))
{
gfloat float_value;
if (info->option->unit == EVMS_Unit_Sectors && info->unit_conversion != info->option->unit)
float_value = convert_sector_value_to_float_with_unit (info->value, info->option->type,
info->unit_conversion);
else
float_value = convert_value_to_float (info->value, info->option->type);
gtk_signal_handler_block_by_func (GTK_OBJECT (adjustment), on_option_adjustment_changed, info);
gtk_adjustment_set_value (adjustment, float_value);
gtk_signal_handler_unblock_by_func (GTK_OBJECT (adjustment), on_option_adjustment_changed, info);
}
log_exit;
}
/*
*
* void set_listbox_selections_from_value_list (GtkCList *, option_widget_info_t *, value_list_t *)
*
* Description:
* This routine selects only the rows in a option listbox that
* match entries in the value list supplied.
*
* Entry:
* clist - the option listbox widget
* info - address of the option widget info associated with widget
* value_list - the list of values corresponding to rows that should be selected
*
* Exit:
* The listbox has the rows corresponding to values in value list
* selected.
*
*/
void set_listbox_selections_from_value_list (GtkCList *clist, option_widget_info_t *info, value_list_t *value_list)
{
gint i;
gchar *text;
value_t value;
for (i=0; i < clist->rows; i++)
{
if (gtk_clist_get_text (clist, i, 0, &text))
{
convert_string_to_value (text, info->option->type, info->option->size, &value);
if (value_in_value_list (value, value_list, info->option->type))
gtk_clist_select_row (clist, i, 0);
else
gtk_clist_unselect_row (clist, i, 0);
clear_value (&value, info->option->type, FALSE, 0);
}
}
}
/*
*
* void on_option_listbox_selection_change (GtkCList *, gint, gint, GdkEventButton *, option_widget_info_t *)
*
* Description:
* This routine gets called when a row is selected or deselected
* in an options listbox.
*
* Entry:
* clist - the option listbox widget
* row - the row that was (de)selected
* column - the column that was (de)selected (ignored)
* event - additional context information (ignored)
* info - address of the option widget info associated with widget
*
* Exit:
* The option value is updated and if necessary we notify our top
* level window of sideaffects of the value update.
*
*/
void on_option_listbox_selection_change (GtkCList *clist, gint row, gint column,
GdkEventButton *event, option_widget_info_t *info)
{
gint rc;
guint i;
guint j;
gint selection_row;
gchar *selection_string;
guint count;
value_t value;
gboolean value_changed;
log_entry;
/*
* Since it is possible that the backend may modify the selection
* list to add items up to the number of constraint list items, we
* must be prepared and always allocate enough space to match the
* constraint list count of items. If the value type is string then
* the strings need to be allocated with the max size as well.
*/
value.list = allocate_value_list (info->option->constraint.list->count,
info->option->type, info->option->size);
/*
* Walk through the currently selected rows and convert the strings
* representing the value to value_t to copy to the value list.
*/
count = g_list_length (clist->selection);
for (i=0, j=0; i < count; i++)
{
selection_row = GPOINTER_TO_INT (g_list_nth_data (clist->selection, i));
if (gtk_clist_get_text (clist, selection_row, 0, &selection_string))
{
if (info->option->type == EVMS_Type_String)
strcpy (value.list->value[j].s, selection_string);
else
convert_string_to_value (selection_string, info->option->type,
info->option->size, &(value.list->value[j]));
j++;
}
}
value.list->count = j;
rc = set_widget_option_value (info, &value, &value_changed);
if ((rc == SUCCESS && value_changed) || (rc != SUCCESS && info->has_value))
{
/*
* Rebuild the listbox selections here.
*/
gtk_signal_handler_block_by_func (GTK_OBJECT (clist), on_option_listbox_selection_change, info);
set_listbox_selections_from_value_list (clist, info, info->value.list);
gtk_signal_handler_unblock_by_func (GTK_OBJECT (clist), on_option_listbox_selection_change, info);
}
clear_value (&value, info->option->type, TRUE, info->option->constraint.list->count);
log_exit;
}
/*
*
* GtkWidget *create_check_button_widget (evms_value_descriptor_t *)
*
* Description:
* This routine is called when there is a boolean value to display.
*
* Entry:
* descriptor - address of structure that contains the boolean value
*
* Exit:
* A GtkCheckButton is created with the initial value set.
*
*/
GtkWidget *create_check_button_widget (evms_value_descriptor_t *descriptor)
{
GtkWidget *checkbutton;
checkbutton = gtk_check_button_new ();
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbutton), descriptor->value.bool);
return checkbutton;
}
/*
*
* GtkWidget *create_boolean_radio_button_widget_group (evms_value_descriptor_t *)
*
* Description:
* This routine is called when there is a boolean value to display using
* a couple of radio buttons rather than one check button.
*
* Entry:
* descriptor - address of structure that contains the boolean value
*
* Exit:
* A GtkHBox is created containing two radio buttons with the proper labels
* and the initial button activated.
*
*/
GtkWidget *create_boolean_radio_button_widget_group (evms_value_descriptor_t *descriptor)
{
GtkWidget *hbox;
GtkWidget *radiobutton;
GtkWidget *yes_button;
GtkWidget *no_button;
hbox = gtk_hbox_new (FALSE, 0);
yes_button = gtk_radio_button_new_with_label (NULL, _("Yes"));
no_button = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (yes_button)),
_("No"));
gtk_widget_show (yes_button);
gtk_widget_show (no_button);
gtk_box_pack_start (GTK_BOX (hbox), yes_button, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (hbox), no_button, FALSE, FALSE, 8);
/*
* Due to the fact we share a signal handler and the weirdness with
* how radio buttons work when one goes active, we save the address
* of the "Yes/No" radio buttons in case we need to reference them
* in the signal handler.
*/
gtk_object_set_data (GTK_OBJECT (yes_button), "yes_button", yes_button);
gtk_object_set_data (GTK_OBJECT (yes_button), "no_button", no_button);
gtk_object_set_data (GTK_OBJECT (no_button), "yes_button", yes_button);
gtk_object_set_data (GTK_OBJECT (no_button), "no_button", no_button);
if (descriptor->value.bool)
radiobutton = yes_button;
else
radiobutton = no_button;
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radiobutton), TRUE);
return hbox;
}
/*
*
* GtkWidget *create_entry_widget (evms_value_descriptor_t *)
*
* Description:
* This routine is called when a text entry box is needed.
*
* Entry:
* descriptor - address of structure that contains the initial
* value
*
* Exit:
* A GtkEntry is created with the initial value in the descriptor
* converted to text and placed in the entry box.
*
*/
GtkWidget *create_entry_widget (evms_value_descriptor_t *descriptor)
{
GtkWidget *entry;
entry = gtk_entry_new ();
if (descriptor->has_initial_value)
{
gchar *string;
/*
* When entry is being used for display purposes only, it is
* favorable to convert certain unit types, e.g. EVMS_Unit_Sectors,
* to a friendlier readable format and also append the unit measurement.
*/
if (descriptor->is_info_only)
string = make_value_readable_string (descriptor->value, descriptor->type, descriptor->unit,
descriptor->format, descriptor->ok_to_convert);
else
string = convert_value_to_string (descriptor->value, descriptor->type, descriptor->format);
gtk_entry_set_text (GTK_ENTRY (entry), string == NULL ? "" : string);
g_free (string);
}
return entry;
}
/*
*
* GtkWidget *create_adjustment_object (evms_value_descriptor_t *)
*
* Description:
* This routine is called when there is a range of numeric
* values to display and an adjustment object is needed to
* represent the range.
*
* Entry:
* descriptor - address of structure that contains the range of
* numeric values
*
* Exit:
* A GtkAdjustment is created with the numeric range provided.
*
*/
GtkAdjustment *create_adjustment_object (evms_value_descriptor_t *descriptor)
{
gfloat value;
gfloat lower;
gfloat upper;
gfloat increment;
if (descriptor->ok_to_convert && descriptor->unit == EVMS_Unit_Sectors)
{
descriptor->unit_conversion = select_readable_unit_for_sector_value (descriptor->collection.range->min,
descriptor->type);
value = convert_sector_value_to_float_with_unit (descriptor->value, descriptor->type,
descriptor->unit_conversion);
lower = convert_sector_value_to_float_with_unit (descriptor->collection.range->min, descriptor->type,
descriptor->unit_conversion);
upper = convert_sector_value_to_float_with_unit (descriptor->collection.range->max, descriptor->type,
descriptor->unit_conversion);
increment = convert_sector_value_to_float_with_unit (descriptor->collection.range->increment,
descriptor->type, descriptor->unit_conversion);
}
else
{
value = convert_value_to_float (descriptor->value, descriptor->type);
lower = convert_value_to_float (descriptor->collection.range->min, descriptor->type);
upper = convert_value_to_float (descriptor->collection.range->max, descriptor->type);
increment = convert_value_to_float (descriptor->collection.range->increment, descriptor->type);
}
return (GtkAdjustment *)gtk_adjustment_new (value, lower, upper, increment, 0.0, 0.0);
}
/*
*
* GtkWidget *create_spin_button_widget (evms_value_descriptor_t *)
*
* Description:
* This routine is called when there is a range of numeric
* values to display.
*
* Entry:
* descriptor - address of structure that contains the range of
* numeric values
*
* Exit:
* A GtkSpinButton is created with the numeric range provided
* and the entry field contains the initial value.
*
*/
GtkWidget *create_spin_button_widget (evms_value_descriptor_t *descriptor)
{
guint digits;
gfloat increment;
GtkWidget *spinbutton;
GtkAdjustment *adjustment;
adjustment = create_adjustment_object (descriptor);
if (descriptor->ok_to_convert && descriptor->unit == EVMS_Unit_Sectors &&
descriptor->unit_conversion != EVMS_Unit_Sectors)
{
increment = convert_sector_value_to_float_with_unit (descriptor->collection.range->increment,
descriptor->type, descriptor->unit_conversion);
digits = 1;
}
else
{
increment = convert_value_to_float (descriptor->collection.range->increment, descriptor->type);
if (descriptor->type == EVMS_Type_Real32 || descriptor->type == EVMS_Type_Real64)
digits = 1;
else
digits = 0;
}
spinbutton = gtk_spin_button_new (adjustment, increment, digits);
gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spinbutton), TRUE);
gtk_spin_button_set_snap_to_ticks (GTK_SPIN_BUTTON (spinbutton), TRUE);
// gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (spinbutton), GTK_UPDATE_IF_VALID);
return spinbutton;
}
/*
*
* GtkWidget *create_hscale_widget (evms_value_descriptor_t *)
*
* Description:
* This routine is called when there is a range of numeric
* values to display and the range is small (0 - 100).
*
* Entry:
* descriptor - address of structure that contains the range of
* numeric values
*
* Exit:
* A GtkHScale is created with the numeric range provided.
*
*/
GtkWidget *create_hscale_widget (evms_value_descriptor_t *descriptor)
{
GtkWidget *hscale;
GtkAdjustment *adjustment;
adjustment = create_adjustment_object (descriptor);
hscale = gtk_hscale_new (adjustment);
if (descriptor->type == EVMS_Type_Real32 || descriptor->type == EVMS_Type_Real64 ||
(descriptor->unit == EVMS_Unit_Sectors && descriptor->unit_conversion != EVMS_Unit_Sectors))
gtk_scale_set_digits (GTK_SCALE (hscale), 2);
else
gtk_scale_set_digits (GTK_SCALE (hscale), 0);
gtk_range_set_update_policy (GTK_RANGE (hscale), GTK_UPDATE_DISCONTINUOUS);
return hscale;
}
/*
*
* GtkWidget *create_list_box_widget (evms_value_descriptor_t *)
*
* Description:
* This routine is called when the backend requires multiple
* selections from a constraint list as input rather than
* just one value.
*
* Entry:
* descriptor - address of structure that contains the constraint
* list and the current selections.
*
* Exit:
* A one column GtkCList is created with the selection list
* provided.
*
*/
GtkWidget *create_list_box_widget (evms_value_descriptor_t *descriptor)
{
guint i;
gint row;
gchar *item;
guint count;
value_list_t *vlist;
GtkWidget *listbox;
listbox = gtk_clist_new (1);
gtk_clist_set_selection_mode (GTK_CLIST (listbox), GTK_SELECTION_MULTIPLE);
vlist = descriptor->collection.list;
count = descriptor->collection.list->count;
for (i=0; i < count; i++)
{
item = convert_value_to_string (vlist->value[i], descriptor->type, descriptor->format);
if (item != NULL)
{
row = gtk_clist_append (GTK_CLIST (listbox), &item);
/*
* If we have an initial value list then mark the value
* just appended as selected if it is in the initial
* value list.
*/
if (descriptor->has_initial_value &&
value_in_value_list (vlist->value[i], descriptor->value.list, descriptor->type))
gtk_clist_select_row (GTK_CLIST (listbox), row, 0);
g_free (item);
}
}
return listbox;
}
/*
*
* GtkWidget *create_combo_box_widget (evms_value_descriptor_t *)
*
* Description:
* This routine is called when there is a collection of valid
* values to display. It is typically created for long lists
* so that a scollbar can used.
*
* Entry:
* descriptor - address of structure that contains the list of
* valid values
*
* Exit:
* A GtkComboBox is created with the value list provided and the
* entry field contains the initial value.
*
*/
GtkWidget *create_combo_box_widget (evms_value_descriptor_t *descriptor)
{
guint i;
gchar *item;
guint count;
GList *glist;
GtkCombo *combo;
value_list_t *vlist;
g_return_val_if_fail (descriptor->collection_type == EVMS_Collection_List, NULL);
glist = NULL;
vlist = descriptor->collection.list;
count = descriptor->collection.list->count;
for (i = 0; i < count; i++)
{
if (descriptor->ok_to_convert && descriptor->unit == EVMS_Unit_Sectors)
item = make_sectors_readable_string (convert_value_to_ui64 (vlist->value[i], descriptor->type));
else
item = convert_value_to_string (vlist->value[i], descriptor->type, descriptor->format);
if (item != NULL)
glist = g_list_append (glist, item);
}
combo = GTK_COMBO (gtk_combo_new ());
/*
* Set the available selections. Set the properties for
* the list indicating that values entered must be in
* the list and that an empty value is not valid. Lastly,
* display the initial value in the entry.
*
* We may have converted some sector values to readable forms,
* e.g. KB or MB and in different units so that the label does
* not indicate a unit, turn off the original unit.
*/
if (descriptor->ok_to_convert && descriptor->unit == EVMS_Unit_Sectors)
descriptor->unit_conversion = EVMS_Unit_None;
gtk_combo_set_popdown_strings (combo, glist);
if (descriptor->has_initial_value)
{
gchar *choice;
if (descriptor->ok_to_convert && descriptor->unit == EVMS_Unit_Sectors)
choice = make_sectors_readable_string (convert_value_to_ui64 (descriptor->value, descriptor->type));
else
choice = convert_value_to_string (descriptor->value, descriptor->type, descriptor->format);
gtk_entry_set_text (GTK_ENTRY (combo->entry), choice);
g_free (choice);
}
else if (!descriptor->is_info_only)
gtk_entry_set_text (GTK_ENTRY (combo->entry), "");
gtk_combo_set_value_in_list (combo, TRUE, FALSE);
gtk_editable_set_editable (GTK_EDITABLE (combo->entry), FALSE);
return GTK_WIDGET (combo);
}
/*
*
* GtkWidget *create_option_menu_widget (evms_value_descriptor_t *)
*
* Description:
* This routine is called when there is a collection of valid
* values to display. It is typically created for short lists
* that allows the list to be viewable entirely on the screen
* without the aid of a scollbar.
*
* Entry:
* descriptor - address of structure that contains the list of
* valid values
*
* Exit:
* A GtkOptionMenu is created with the value list provided and the
* initial value it displays is set
*
*/
GtkWidget *create_option_menu_widget (evms_value_descriptor_t *descriptor)
{
guint i;
guint count;
guint init_value_index=0;
gchar *item;
value_list_t *vlist;
GtkWidget *menu;
GtkWidget *option_menu;
g_return_val_if_fail (descriptor->collection_type == EVMS_Collection_List, NULL);
vlist = descriptor->collection.list;
count = descriptor->collection.list->count;
/*
* Create the option menu and associated submenu and populate
* the menu items from the value list provided. Check to see
* if initial value matches one in the list and if so set the
* menu item index as the selected value.
*/
option_menu = gtk_option_menu_new ();
menu = gtk_menu_new ();
for (i = 0; i < count; i++)
{
if (descriptor->ok_to_convert && descriptor->unit == EVMS_Unit_Sectors)
item = make_sectors_readable_string (convert_value_to_ui64 (vlist->value[i], descriptor->type));
else
item = convert_value_to_string (vlist->value[i], descriptor->type, descriptor->format);
if (item != NULL)
{
GtkWidget *menuitem;
menuitem = gtk_menu_item_new_with_label (item);
if (descriptor->has_initial_value &&
values_are_equal (vlist->value[i], descriptor->value, descriptor->type))
init_value_index = i;
gtk_menu_append (GTK_MENU (menu), menuitem);
gtk_widget_show (menuitem);
g_free (item);
}
}
/*
* We may have converted some sector values to readable forms, e.g. KB or MB
* and in different units so that the label does not indicate a unit, turn
* off the original unit.
*/
if (descriptor->ok_to_convert && descriptor->unit == EVMS_Unit_Sectors)
descriptor->unit_conversion = EVMS_Unit_None;
/*
* If this widget will be used for required option input and
* no initial value was provided then insert a message that
* provides a cue to the user that something needs to be selected.
* The special menu item will be removed the first time the user
* selects some other menu item.
*/
if (descriptor->is_info_only == FALSE && descriptor->has_initial_value == FALSE)
{
if (descriptor->is_required)
{
GtkWidget *menuitem;
menuitem = gtk_menu_item_new_with_label (OPTION_MENU_NO_SELECTION_TEXT);
gtk_menu_prepend (GTK_MENU (menu), menuitem);
gtk_object_set_data (GTK_OBJECT (menu), "no_selection_menuitem", menuitem);
gtk_widget_show (menuitem);
}
else
{
/*
* Option widgets that are not required better have an initial value
* that points to their empty/null value or some other valid initial
* value.
*/
log_error ("%s: Option widget %s had no initial value.\n", descriptor->name);
}
}
gtk_option_menu_set_menu (GTK_OPTION_MENU (option_menu), menu);
gtk_option_menu_set_history (GTK_OPTION_MENU (option_menu), init_value_index);
return option_menu;
}
/*
*
* void remove_widget_properties (GtkWidget *, widget_properties_t *)
*
* Description:
* This routine takes a widget and the address of its associated
* widget properties structure and has the structure memory freed.
* The object data in the widget corresponding to the "widget_properties"
* key is also cleared.
*
* Entry:
* widget - the widget to have the widget properties structure removed
*
* Exit:
* The widget properties are freed and removed from the widget.
*
*/
void remove_widget_properties (GtkWidget *widget, widget_properties_t * properties)
{
log_entry;
if (gtk_object_get_data (GTK_OBJECT (widget), "widget_properties"))
{
if (properties->name != NULL)
g_free (properties->name);
if (properties->tip != NULL)
g_free (properties->tip);
if (properties->title != NULL)
g_free (properties->title);
if (properties->group.group_name != NULL)
g_free (properties->group.group_name);
g_free (properties);
gtk_object_set_data (GTK_OBJECT (widget), "widget_properties", NULL);
}
log_exit;
}
/*
*
* void bind_widget_properties_to_widget (evms_value_descriptor_t *, GtkWidget *)
*
* Description:
* This routine creates a widget properties structure that contain information
* used when creating additional widget notebook information such as the field
* label and the tooltip that contains a description of the field.
*
* Entry:
* descriptor - address of structure that fully describes the value the
* widget represents
* widget - widget that will have additional data bound to it
*
* Exit:
* A widget_properties_t structure is dynamically allocated and initialized and
* bound to the widget.
*
*/
void bind_widget_properties_to_widget (evms_value_descriptor_t *descriptor, GtkWidget *widget)
{
widget_properties_t *properties;
properties = g_new0 (widget_properties_t, 1);
properties->name = g_strdup (descriptor->name);
properties->unit = descriptor->unit_conversion;
properties->is_info_only = descriptor->is_info_only;
properties->more_data_avail = descriptor->more_data_avail;
properties->is_required = descriptor->is_required;
properties->group.group_level = descriptor->group.group_level;
properties->group.group_number = descriptor->group.group_number;
if (descriptor->group.group_number != 0 && descriptor->group.group_name != NULL)
properties->group.group_name = g_strdup (descriptor->group.group_name);
if (descriptor->desc != NULL)
properties->tip = g_strdup (descriptor->desc);
if (descriptor->title != NULL)
properties->title = g_strdup (descriptor->title);
gtk_object_set_data (GTK_OBJECT (widget), "widget_properties", properties);
gtk_signal_connect (GTK_OBJECT (widget), "destroy",
GTK_SIGNAL_FUNC (remove_widget_properties), properties);
}
/*
*
* GtkWidget* create_widget_from_value_descriptor (evms_value_descriptor_t *)
*
* Description:
* This routine creates a widget that will suitably represent the
* value described.
*
* Entry:
* descriptor - address of structure that fully describes the value the
* widget represents
*
* Exit:
* A suitable widget is created that can represent the value described.
*
*/
GtkWidget* create_widget_from_value_descriptor (evms_value_descriptor_t *descriptor)
{
GtkWidget *widget = NULL;
if (descriptor->collection_type == EVMS_Collection_None)
{
if (descriptor->type == EVMS_Type_Boolean)
{
if (descriptor->is_info_only)
widget = create_entry_widget (descriptor);
else
{
widget = create_boolean_radio_button_widget_group (descriptor);
}
}
else
widget = create_entry_widget (descriptor);
}
else
{
/*
* Select the proper widget that allows multiple
* selections for ranges and lists.
*/
if (descriptor->collection_type == EVMS_Collection_Range)
{
if (descriptor->type >= EVMS_Type_Real32 && descriptor->type <= EVMS_Type_Unsigned_Int64)
{
if (value_less_than_integer (descriptor->collection.range->max, descriptor->type, 101))
widget = create_hscale_widget (descriptor);
else
widget = create_spin_button_widget (descriptor);
}
else
{
log_error ("%s: A non-numeric range option descriptor was supplied!\n", __FUNCTION__);
}
}
else if (descriptor->collection_type == EVMS_Collection_List)
{
if (descriptor->type != EVMS_Type_Boolean)
{
if (descriptor->multi_input_list)
widget = create_list_box_widget (descriptor);
else if (descriptor->collection.list->count > 25)
widget = create_combo_box_widget (descriptor);
else
widget = create_option_menu_widget (descriptor);
}
else
log_error ("%s: An unsupported option descriptor list was supplied!\n", __FUNCTION__);
}
else
{
log_error ("%s: Unknown collection type supplied.\n", __FUNCTION__);
}
}
if (widget != NULL)
bind_widget_properties_to_widget (descriptor, widget);
return widget;
}
/*
*
* void connect_option_widget_callback (GtkWidget *, option_widget_info_t *)
*
* Description:
* This routine makes the connection(s) with the proper callback(s) for
* the corresponding widget input signals.
*
* Entry:
* widget - widget that needs callback connection(s) established
* info - address of the option widget info associated with the widget
*
* Exit:
* The corresponding callback function(s) is/are connected to allow
* handling input signals.
*
*/
void connect_option_adjustment_callback (GtkWidget *widget, option_widget_info_t *info)
{
GtkAdjustment *adjustment = NULL;
/*
* In order to find out when the value for a widget that
* uses an adjustment has been changed, we need to connect
* the "value_changed" signal with the GtkAdjustment object
* owned by the widget.
*/
if (GTK_IS_SPIN_BUTTON (widget))
adjustment = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (widget));
else if (GTK_IS_RANGE (widget))
adjustment = gtk_range_get_adjustment (GTK_RANGE (widget));
else
log_error ("%s: Not a range or spinbutton so don't know if it has an adjustment widget.\n", __FUNCTION__);
if (adjustment != NULL)
gtk_signal_connect (GTK_OBJECT (adjustment), "value_changed",
GTK_SIGNAL_FUNC (on_option_adjustment_changed), info);
}
/*
*
* void on_option_widget_destroy (GtkWidget *, option_widget_info_t *)
*
* Description:
* This routine frees the option descriptor, current value information
* and widget info structure as the widget gets destroyed.
*
* Entry:
* widget - the option widget
* info - address of the option widget info associated with the widget
*
* Exit:
* The option descriptor, value and widget info are freed.
*
*/
void on_option_widget_destroy (GtkWidget *widget, option_widget_info_t *info)
{
option_descriptor_t *option = info->option;
log_debug ("%s: Dude, I'm going to totally destroy this option widget info: %p!\n", __FUNCTION__, info);
if (info->has_value)
{
guint list_count=0;
if (EVMS_OPTION_VALUE_IS_LIST (option->flags))
list_count = option->constraint.list->count;
clear_value (&(info->value), option->type, EVMS_OPTION_VALUE_IS_LIST (option->flags), list_count);
}
evms_free (option);
g_free (info);
}
/*
*
* void connect_box_children_callbacks (GtkBox *, option_widget_info_t *)
*
* Description:
* This routine connects the callbacks for the widgets located in
* box container.
*
* Entry:
* box - the GtkBox container type
* info - address of the option widget info associated with the widget
*
* Exit:
* The signal handlers for the appropriate signals and widgets are connected.
*
*/
void connect_box_children_callbacks (GtkBox *box, option_widget_info_t *info)
{
if (g_list_length (box->children) > 0)
{
GList *child;
child = box->children;
while (child)
{
if (child->data)
connect_option_widget_callback (((GtkBoxChild *)(child->data))->widget, info, FALSE);
child = g_list_next (child);
}
}
else
{
log_warning ("%s: Box has no children.\n", __FUNCTION__);
}
}
/*
*
* void connect_option_widget_callback (GtkWidget *, option_widget_info_t *, gboolean)
*
* Description:
* This routine makes the connection(s) with the proper callback(s) for
* the corresponding widget input signals.
*
* Entry:
* widget - widget that needs callback connection(s) established
* info - address of the option widget info associated with the widget
* connect_destroy - TRUE to register signal handler to cleanup info during widget
* "destroy" event
*
* Exit:
* The corresponding callback function(s) is/are connected to allow
* handling input signals.
*
*/
void connect_option_widget_callback (GtkWidget *widget, option_widget_info_t *info, gboolean connect_destroy)
{
/*
* When doing widget class checks for connecting callbacks,
* start with subclasses and work your way up to something
* that "fits". Sorry to use if/else but this is the way
* it is done when checking what kind of widget we got
* due to GTK+'s inheritance model.
*/
if (GTK_IS_BOX (widget))
{
/*
* We have a container type, enumerate the children and connect
* callbacks appropriately.
*/
connect_box_children_callbacks (GTK_BOX (widget), info);
}
else if (GTK_IS_CLIST (widget))
{
gtk_signal_connect (GTK_OBJECT (widget), "select_row",
GTK_SIGNAL_FUNC (on_option_listbox_selection_change), info);
gtk_signal_connect (GTK_OBJECT (widget), "unselect_row",
GTK_SIGNAL_FUNC (on_option_listbox_selection_change), info);
}
else if (GTK_IS_HSCALE (widget) || GTK_IS_SPIN_BUTTON (widget))
{
connect_option_adjustment_callback (widget, info);
}
else if (GTK_IS_COMBO (widget))
{
gtk_signal_connect (GTK_OBJECT (GTK_COMBO (widget)->entry), "changed",
GTK_SIGNAL_FUNC (on_option_entry_text_entered), info);
}
else if (GTK_IS_OPTION_MENU (widget))
{
GtkWidget *menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (widget));
gtk_object_set_data (GTK_OBJECT (menu), "option_menu", widget);
gtk_signal_connect (GTK_OBJECT (menu), "selection_done",
GTK_SIGNAL_FUNC (on_option_menu_item_selected), info);
}
else if (GTK_IS_RADIO_BUTTON (widget))
{
gtk_signal_connect (GTK_OBJECT (widget), "toggled",
GTK_SIGNAL_FUNC (on_option_radio_button_toggled), info);
}
else if (GTK_IS_CHECK_BUTTON (widget))
{
gtk_signal_connect (GTK_OBJECT (widget), "toggled",
GTK_SIGNAL_FUNC (on_option_check_button_toggled), info);
}
else if (GTK_IS_ENTRY (widget))
{
/*
* Text entry widgets are a funny thing. We can't really call
* evms_set_option_value() on it whenever text in the box changes
* since we can't be sure when the user is done. We set a callback
* for the "insert-text" event simply to do simple validation such
* as ensure that the value is numeric and does not exceed the range
* for the numeric type according to the descriptor. Calling the
* evms_set_option_value() call for entry widgets will be delayed
* until the user presses Enter or the entry widget loses focus.
*/
gtk_signal_connect (GTK_OBJECT (widget), "insert-text",
GTK_SIGNAL_FUNC (on_option_entry_text_inserted), info);
gtk_signal_connect (GTK_OBJECT (widget), "activate",
GTK_SIGNAL_FUNC (on_option_entry_text_entered), info);
gtk_signal_connect (GTK_OBJECT (widget), "focus-out-event",
GTK_SIGNAL_FUNC (on_option_entry_focus_out), info);
}
else if (GTK_IS_LABEL (widget))
{
/*
* Bogus.
*/
}
else
{
log_error ("%s: Unexpected widget type was provided!\n", __FUNCTION__);
}
/*
* Bind the option widget info to the object user data to allow
* anyone passed this widget to extract it.
*/
gtk_object_set_user_data (GTK_OBJECT (widget), info);
/*
* Connect the destroy signal to each widget to allow cleaning up the
* option widget info, option descriptor and value at that time.
*/
if (connect_destroy)
gtk_signal_connect (GTK_OBJECT (widget), "destroy",
GTK_SIGNAL_FUNC (on_option_widget_destroy), info);
}
/*
*
* option_widget_info_t* create_widget_from_option_descriptor (option_descriptor_t *)
*
* Description:
* This routine creates a suitable input widget based on an option
* descriptor. The widget has the option_descriptor_t * information
* passed to the callback so that the callback function can call
* evms_set_option_value() when invoked.
*
* Once we get the widget, we make the connections with the proper
* wrapper callback for the corresponding widget input signals.
*
* Entry:
* option - address of the option descriptor to create an input widget for
*
* Exit:
* The suitable widget is created and a corresponding callback function
* is connected to allow handling input signals. A dynamically allocated
* option_widget_info_t is returned containing all necessary information
* about the option widget.
*
*/
option_widget_info_t* create_widget_from_option_descriptor (option_descriptor_t *option)
{
GtkWidget *widget;
option_widget_info_t *option_widget_info;
evms_value_descriptor_t descriptor;
/*
* Copy fields from option descriptor to the common structure used
* by the routines used to create a widget.
*/
descriptor.desc = option->tip;
descriptor.group = option->group;
descriptor.name = option->name;
descriptor.title = option->title;
descriptor.type = option->type;
descriptor.unit = option->unit;
descriptor.value = option->value;
descriptor.collection = option->constraint;
descriptor.collection_type = option->constraint_type;
descriptor.format = EVMS_Format_Normal;
descriptor.is_info_only = FALSE;
descriptor.has_initial_value = EVMS_OPTION_HAS_VALUE (option->flags);
descriptor.ok_to_convert = (option->flags & EVMS_OPTION_FLAGS_NO_UNIT_CONVERSION) == 0;
descriptor.more_data_avail = FALSE;
descriptor.multi_input_list = EVMS_OPTION_VALUE_IS_LIST (option->flags);
descriptor.is_required = EVMS_OPTION_IS_REQUIRED (option->flags);
descriptor.unit_conversion = option->unit;
widget = create_widget_from_value_descriptor (&descriptor);
option_widget_info = (option_widget_info_t *)g_malloc0 (sizeof (option_widget_info_t));
option_widget_info->widget = widget;
option_widget_info->option = option;
option_widget_info->unit_conversion = descriptor.unit_conversion;
option_widget_info->has_value = descriptor.has_initial_value;
if (option_widget_info->has_value)
{
guint list_count=0;
if (EVMS_OPTION_VALUE_IS_LIST (option->flags))
list_count = option->constraint.list->count;
duplicate_value (option->value, option->type,
EVMS_OPTION_VALUE_IS_LIST (option->flags),
list_count, option->size, &(option_widget_info->value));
}
/*
* Check to see if the option is active. If not, don't worry
* about setting up callbacks but do make the widget
* insensitive.
*/
if (EVMS_OPTION_IS_ACTIVE (option->flags))
{
connect_option_widget_callback (widget, option_widget_info, TRUE);
}
else
{
gtk_widget_set_sensitive (widget, FALSE);
}
return option_widget_info;
}
/*
*
* GtkWidget* create_widget_from_extended_info (extended_info_t *)
*
* Description:
* This routine creates a widget to be used to represent an
* extended info value for display purposes only (no input).
* This means text entry widgets are non-editable, no signal
* handlers are registered and some widgets are insensitive.
*
* Entry:
* info - address of an extended info description
*
* Exit:
* A widget is created representing the extended info field.
*
*/
GtkWidget* create_widget_from_extended_info (extended_info_t *info)
{
GtkWidget *widget;
evms_value_descriptor_t descriptor;
descriptor.desc = info->desc;
descriptor.group = info->group;
descriptor.name = info->name;
descriptor.title = info->title;
descriptor.type = info->type;
descriptor.unit = info->unit;
descriptor.value = info->value;
descriptor.collection = info->collection;
descriptor.collection_type = info->collection_type;
descriptor.format = info->format;
descriptor.is_info_only = TRUE;
descriptor.has_initial_value = info->collection_type == EVMS_Collection_None;
descriptor.ok_to_convert = (info->flags & EVMS_EINFO_FLAGS_NO_UNIT_CONVERSION) == 0;
descriptor.more_data_avail = info->flags & EVMS_EINFO_FLAGS_MORE_INFO_AVAILABLE;
descriptor.multi_input_list = FALSE;
descriptor.is_required = FALSE;
descriptor.unit_conversion = info->unit;
widget = create_widget_from_value_descriptor (&descriptor);
if (GTK_IS_ENTRY (widget))
gtk_editable_set_editable (GTK_EDITABLE (widget), FALSE);
else if (GTK_IS_COMBO (widget))
gtk_editable_set_editable (GTK_EDITABLE (GTK_COMBO (widget)->entry), FALSE);
else if (GTK_IS_CHECK_BUTTON (widget))
gtk_widget_set_sensitive (widget, FALSE);
return widget;
}
/*
*
* void inline add_label_to_notebook_table (GtkTable *, widget_properties_t *, GtkTooltips *,
* guint, guint, guint)
*
* Description:
* This routine inserts a label widget with descriptive text at the
* specified row between the starting and ending column. We also
* set the widget tooltip on this label.
*
* Entry:
* table - the table to contain the widgets
* properties - the widget properties
* tooltips - id of tooltips group
* row - the row in the table to place the widget at
* starting_column - the starting column in the table for the label
* ending_column - the ending column in the table for the label
*
* Exit:
* A label with the associated text is inserted at the given row and column
* and the field tooltip is set on it as well.
*
*/
void inline add_label_to_notebook_table (GtkTable *table, widget_properties_t *properties,
GtkTooltips *tooltips, guint row, guint starting_column,
guint ending_column)
{
GtkWidget *label;
GtkWidget *widget_to_attach;
if (properties->unit != EVMS_Unit_None && !properties->is_info_only)
{
gchar *unit;
gchar *text;
unit = make_unit_readable_string (properties->unit, TRUE);
text = g_strconcat (properties->title, " (", unit, ")", NULL);
label = gtk_label_new (text);
g_free (unit);
g_free (text);
}
else
{
label = gtk_label_new (properties->title);
}
gtk_widget_show (label);
/*
* If the widget has a tip, place it on the label to avoid
* extra events going to the widget plus allow tips to
* show in case the widget is insensitive. It also simplifies
* the code if we always do it on the field label.
*/
if (properties->tip != NULL)
{
GtkWidget *eventbox = gtk_event_box_new ();
gtk_widget_show (eventbox);
gtk_container_add (GTK_CONTAINER (eventbox), label);
gtk_tooltips_set_tip (tooltips, eventbox, properties->tip, NULL);
widget_to_attach = eventbox;
}
else
{
widget_to_attach = label;
}
gtk_table_attach (table, widget_to_attach, starting_column, ending_column, row, row+1,
(GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
}
/*
*
* void inline mark_field_as_required (GtkTable *, widget_properties_t *, GtkTooltips *,
* guint, guint, guint)
*
* Description:
* This routine inserts a label widget that contains an asterik
* that indicates that this field is required input. The tooltip
* for the label also indicates this fact.
*
* Entry:
* table - the table to contain the widgets
* properties - the widget properties
* tooltips - id of tooltips group
* row - the row in the table to place the widget at
* starting_column - the starting column in the table for the label
* ending_column - the ending column in the table for the label
*
* Exit:
* A label with the associated text is inserted at the given row and column
* and the field tooltip is set on it as well.
*
*/
void inline mark_field_as_required (GtkTable *table, widget_properties_t *properties,
GtkTooltips *tooltips, guint row, guint starting_column,
guint ending_column)
{
GtkWidget *label;
GtkWidget *eventbox;
label = gtk_label_new ("*");
eventbox = gtk_event_box_new ();
gtk_widget_show (label);
gtk_widget_show (eventbox);
gtk_container_add (GTK_CONTAINER (eventbox), label);
gtk_tooltips_set_tip (tooltips, eventbox, _("This is a required field"), NULL);
gtk_table_attach (table, eventbox, starting_column, ending_column, row, row+1,
(GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
}
/*
*
* void on_more_button_destroy (GtkWidget *, field_details_t *)
*
* Description:
* This routine frees the information used in obtaining
* additional extended info on a specific object field.
*
* Entry:
* widget - the option widget
* info - address of the field details info associated with widget
*
* Exit:
* The field_details_t structure and its contents are freed.
*
*/
void on_more_button_destroy (GtkWidget *widget, field_details_t *field)
{
g_free (field->name);
g_free (field->title);
g_free (field);
}
/*
*
* void inline add_more_button_to_notebook_table (GtkTable *, GtkTooltips *,
* widget_properties_t *,
* guint, guint, guint)
*
* Description:
* This routine inserts a button widget with the given text at the
* specified row between the starting and ending column.
*
* Entry:
* table - the table to contain the widgets
* tooltips - id of tooltips group
* properties - the widget properties
* row - the row in the table to place the widget at
* starting_column - the starting column in the table for the button
* ending_column - the ending column in the table for the button
*
* Exit:
* A button to allow displaying more info is inserted at the given row and column.
*
*/
void inline add_more_button_to_notebook_table (GtkTable *table, GtkTooltips *tooltips,
widget_properties_t *properties, guint row,
guint starting_column, guint ending_column)
{
GtkWidget *button = gtk_button_new_with_label (_("More.."));
field_details_t *field = g_new0 (field_details_t, 1);
field->name = g_strdup (properties->name);
if (properties->title != NULL)
field->title = g_strdup (properties->title);
gtk_widget_show (button);
gtk_tooltips_set_tip (tooltips, button, _("Display more detailed information..."), NULL);
gtk_table_attach (table, button, starting_column, ending_column, row, row+1,
(GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0);
/*
* Setup signal handler that displays more detail on a field when
* the "More" button is clicked. The second signal handler handles
* freeing the field_details_t structure and strings.
*/
gtk_signal_connect (GTK_OBJECT (button), "clicked",
GTK_SIGNAL_FUNC (on_display_more_thing_details_button_clicked), field);
gtk_signal_connect (GTK_OBJECT (button), "destroy",
GTK_SIGNAL_FUNC (on_more_button_destroy), field);
}
/*
*
* void add_widget_to_notebook_table (GtkTable *, GtkWidget *, GtkTooltips * guint, guint)
*
* Description:
* This routine takes a widget and places the widget at the given
* row in a table widget. The first column will contain a label for
* the field. The widget will begin at the column adjusted for indention
* level. If the widget has a full field description it will be set
* as the widget tooltip.
*
* Entry:
* table - the table to contain the widget
* widget - the widget to be added to the table
* tooltips - the tooltips object that to hold the field description
* row - the row in the table to place the widget at
* columns - the total number of columns in the table
*
* Exit:
* Notebook is created with one or more pages and the widgets
* organized within.
*
*/
void add_widget_to_notebook_table (GtkTable *table, GtkWidget *widget, GtkTooltips *tooltips,
guint *row, guint columns)
{
guint end_row;
guint starting_column;
GtkWidget *widget_to_attach;
widget_properties_t *properties;
properties = gtk_object_get_data (GTK_OBJECT (widget), "widget_properties");
/*
* If widget properties were not retrieved then create an empty
* properties structure to allow the widget to be displayed anyway.
*/
if (properties == NULL)
properties = g_new0 (widget_properties_t, 1);
if (GTK_WIDGET_SENSITIVE (widget) && properties->is_required)
mark_field_as_required (table, properties, tooltips, *row, VALUE_REQUIRED_COLUMN, WIDGET_LABEL_COLUMN);
if (properties->title != NULL)
add_label_to_notebook_table (table, properties, tooltips, *row, WIDGET_LABEL_COLUMN, WIDGET_COLUMN);
if (properties->group.group_number != 0)
starting_column = WIDGET_COLUMN + properties->group.group_level;
else
starting_column = WIDGET_COLUMN;
/*
* Do special handling for a list widget. It takes
* up additional rows in the table and it needs to
* be inside of a scrollbar widget.
*/
if (GTK_IS_CLIST (widget))
{
widget_to_attach = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (widget_to_attach),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_container_add (GTK_CONTAINER (widget_to_attach), widget);
gtk_widget_show (widget);
end_row = *row + CLIST_MAX_TABLE_ROWS;
}
else
{
end_row = *row + 1;
widget_to_attach = widget;
}
gtk_widget_show (widget_to_attach);
gtk_table_attach (table, widget_to_attach, starting_column, columns-1, *row, end_row,
(GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
(GtkAttachOptions) (0), 0, 0);
/*
* Check to see if this extended info widget indicates more data
* can be queried for this field. If so, place a "More" button
* next to the field.
*/
if (properties->more_data_avail)
add_more_button_to_notebook_table (table, tooltips, properties, *row, columns-1, columns);
*row = end_row;
}
/*
*
* guint get_max_indentation_level (GSList *, guint, guint)
*
* Description:
* This routine takes a list of widgets and determines the maximum
* indentation level for a widget that is part of a logical group.
* The indentation level help assists in the number of columns
* contained in the widget table and the starting column the widget
* will be placed.
*
* Entry:
* widgets - singly linked list containing widgets to be displayed
* first_widget - the index of the first widget to inspect
* last_widget - the index of the last widget to inspect
*
* Exit:
* The specified widget group structures are examined and the highest number
* indention level is returned.
*
*/
guint get_max_indentation_level (GSList *widgets, guint first_widget, guint last_widget)
{
guint i;
guint max_indentation_level = 0;
GtkWidget *widget;
widget_properties_t *properties;
for (i = first_widget; i <= last_widget; i++)
{
widget = g_slist_nth_data (widgets, i);
if (widget != NULL)
{
properties = gtk_object_get_data (GTK_OBJECT (widget), "widget_properties");
if (properties != NULL && properties->group.group_number != 0 &&
properties->group.group_level > max_indentation_level)
max_indentation_level = properties->group.group_level;
}
}
return max_indentation_level;
}
/*
*
* void add_widget_page_to_notebook (guint, GSList *, guint, guint, GtkNotebook *, GtkTooltips *, gchar *)
*
* Description:
* This routine takes a set of widgets with a list and creates a table
* to hold them within a new notebook page.
*
* Entry:
* page - our page number
* widgets - singly linked list containing widgets to be displayed
* first_widget - index in list of first widget to work with
* last_widget - index in list of last widget to work with
* rows - count of rows for the widget table
* notebook - address of notebook widget
* tooltips - address of tooltips data
* label - optional string for tab label
*
* Exit:
* A table of widgets is created and added to the notebook within
* a new page.
*
*/
void add_widget_page_to_notebook (gint page, GSList *widgets, guint first_widget, guint last_widget,
guint rows, GtkNotebook *notebook, GtkTooltips *tooltips, gchar *label)
{
guint i;
guint row;
guint columns;
GtkWidget *widget;
GtkWidget *widget_table;
/*
* The number of columns should be determined after making a pass
* through the descriptors and determining the indentation level.
* We also have at least four columns (one for required field
* marker (*), one for the field label, one for the widget, and
* one for any potential "More" button).
*/
columns = 4 + get_max_indentation_level (widgets, first_widget, last_widget);
widget_table = gtk_table_new (rows, columns, FALSE);
/*
* Add each widget with a text label in the first column. Start the
* widget at the indentation level and always end them at the last
* column.
*/
for (i = first_widget, row = 0; i <= last_widget; i++)
{
widget = g_slist_nth_data (widgets, i);
if (widget != NULL)
add_widget_to_notebook_table (GTK_TABLE (widget_table), widget, tooltips, &row, columns);
}
gtk_widget_show (widget_table);
gtk_container_add (GTK_CONTAINER (notebook), widget_table);
gtk_container_set_border_width (GTK_CONTAINER (widget_table), 15);
gtk_table_set_row_spacings (GTK_TABLE (widget_table), 10);
gtk_table_set_col_spacings (GTK_TABLE (widget_table), 5);
gtk_table_set_col_spacing (GTK_TABLE (widget_table), columns-1, 0);
if (label != NULL)
{
GtkWidget *tab_label;
tab_label = gtk_label_new (label);
gtk_widget_show (tab_label);
gtk_notebook_set_tab_label (notebook, gtk_notebook_get_nth_page (notebook, page), tab_label);
}
}
/*
*
* guint get_page_limits (GSList *, guint, guint, guint, guint *)
*
* Description:
* This routine determines the number of rows for the table in
* a notebook page to hold a certain number of widgets.
*
* Entry:
* widgets - singly linked list containing widgets to be displayed
* first_widget - index in list of first widget to work with
* actual_last - index in list of last widget in the list
* rows - address to write count of rows for the widget table
*
* Exit:
* Returns the index of the last widget to fit and the number of
* table rows required.
*
*/
guint get_page_limits (GSList *widgets, guint first_widget, guint actual_last, guint max_widgets_per_page, guint *row_count)
{
guint i;
guint last_widget;
guint max_widgets_this_page;
GtkWidget *widget;
max_widgets_this_page = MIN (max_widgets_per_page, (actual_last - first_widget + 1));
for (i=first_widget, last_widget=first_widget, *row_count=0; *row_count < max_widgets_this_page; i++)
{
widget = g_slist_nth_data (widgets, i);
if (GTK_IS_CLIST (widget))
*row_count += CLIST_MAX_TABLE_ROWS;
else
*row_count += 1;
if (*row_count <= max_widgets_per_page)
last_widget = i;
}
return last_widget;
}
/*
*
* GtkWidget* create_widget_notebook (GSList *, gchar *, guint)
*
* Description:
* This routine takes a list of widgets and creates a notebook
* with the widgets organized by group and laid out within
* a table container widget. Additional pages and tables are
* added to the notebook if necessary.
*
* Entry:
* widgets - singly linked list containing widgets to be
* displayed
* label - optional string for tab labels
* max_widgets_per_page - maximum number of widgets per page
* currpage - page to be made current page
*
* Exit:
* Notebook is created with one or more pages and the widgets
* organized within.
*
*/
GtkWidget* create_widget_notebook (GSList *widgets, gchar *label, guint max_widgets_per_page, gint currpage)
{
guint page=0;
guint first=0;
guint last;
guint row_count=0;
guint actual_last;
GtkWidget *notebook;
GtkTooltips *tooltips;
notebook = gtk_notebook_new ();
tooltips = gtk_tooltips_new ();
gtk_notebook_set_tab_hborder (GTK_NOTEBOOK (notebook), 14);
actual_last = g_slist_length (widgets) - 1;
do
{
last = get_page_limits (widgets, first, actual_last, max_widgets_per_page, &row_count);
add_widget_page_to_notebook (page, widgets, first, last, row_count, GTK_NOTEBOOK (notebook), tooltips, label);
/*
* If all the widgets have not been sunken into a page,
* setup to add the next set of widgets on another page.
*/
if (last < actual_last)
{
page += 1;
first = last + 1;
}
} while (last < actual_last);
gtk_notebook_set_page (GTK_NOTEBOOK (notebook), currpage);
return notebook;
}
/*
* The following routines are basically getter/setter functions
* that are used by most of the option widget callbacks.
*/
inline void bind_options_callout_to_toplevel_widget (GtkWidget *widget, options_callback_callout callout)
{
GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
gtk_object_set_data (GTK_OBJECT (toplevel), "callback_callout", callout);
}
inline options_callback_callout retrieve_options_callout_from_toplevel_widget (GtkWidget *widget)
{
GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
return (options_callback_callout) gtk_object_get_data (GTK_OBJECT (toplevel), "callback_callout");
}
|