Well here is a little description of what DrakX needs to work in comparison to the RH newt install. ******************************************************************************** * CVS ************************************************************************** ******************************************************************************** Like all good free software, DrakX is in CVS :) You can access it at http://www.mandrakelinux.com/cgi-bin/cvsweb.cgi/gi or via export CVS_RSH=ssh export CVSROOT=:ext:anoncvs@cvs.mandrakesoft.com:/cooker cvs checkout gi (enter password 'cvs') This is only read-only access. If you want more, tell me (pixel@mandrakesoft.com) Alas, all is not in CVS, a lot of things come from rpm packages which you must install. Please note that redoing *all* the stuff is not for the faint of heart. I myself sometimes wonder what the whole make does :-% Instead, changing some .pm files is quite easy (nice interpreted language) ******************************************************************************** * Making your custom install *************************************************** ******************************************************************************** If you have your own rpms you want to add, or make your own updated cdrom, you just have to issue: % gendistrib --noclean --distrib Where is the root of all the media that the install will see, this first one is the main one : (1) network or 1-cdrom installs DIRS == the root directory of the Distribution (2) multi-cdrom install DIRS == the root directories of all the media that the install will see ``gendistrib'' will scan the file Mandrake/base/hdlists in the main root directory (the first one in DIRS) to search for all media used. Typically you use Mandrake/RPMS* for RPM packages repository. For multi-cd, please use Mandrake/RPMS or Mandrake/RPMS1, Mandrake/RPMS2, etc. For one CD or a network/hd volume, please use Mandrake/RPMS. Optionnally, you can modify ``Mandrake/base/rpmsrate''; this file manages the relative importance of the files, and thus their installation or not. Also, mdkinst_stage2.gz must be remade if you modify files in Mandrake/mdkinst. See below for information about these files. ******************************************************************************** * FILES ************************************************************************ ******************************************************************************** First here are the different things needed : Mandrake/base/hdlists description of the available install media. format is one line for one medium as should be match regexp /hdlist\S*.cz2?/ for example (two cd install) you get hdlist1.cz Mandrake/RPMS1 Boot CD hdlist2.cz Mandrake/RPMS2 Extension CD Mandrake/base/hdlist*.cz table of rpm's headers, referred by ``hdlists'' their contents can be listed using ``packdrake -l '' or or ``parsehdlist ''. ! Need to be remade when Mandrake/RPMS* changes (with ``gendistrib'') ! Mandrake/base/depslist.ordered for each packages, tell which package it depends on. Also contains the size for some (obscure) bloody reasons. ! Need to be remade when Mandrake/RPMS* changes ! (with ``gendistrib --noclean --distrib .'') Mandrake/base/compss obsoletes comps. It store packages in different categories, generated from the %{GROUP} field ! Need to be remade when Mandrake/RPMS* changes ! (with ``gendistrib --noclean --distrib .'') Mandrake/base/rpmsrate ranks and classify packages, so that the installer will know which ones to install. format is : where is a symbolic name used in Mandrake/base/compssUsers* files, and defines importance level as described below : 5 must have 4 important 3 very nice 2 nice 1 maybe by default (for non expert), group selects packages for level 4 (important) and 5 (must have). export mode add 3 (very nice) level. other level (below 2) can only be selected using individual package selection. Mandrake/mdkinst live system used on certain installs. See ``Ramdisk or not'' below for more. Mandrake/base/mdkinst_stage2.bz2 for the ramdisk. live sytem in ext2 filesystem bzipped2. generated from Mandrake/mdkinst tree using misc/make_mdkinst_stage2 See ``Ramdisk or not'' below for more. Mandrake/base/rescue_stage2.bz2 rescue ramdisk. live sytem in ext2 filesystem bzipped2. this is the ramdisk loaded when typing rescue on boot prompt. there is no live system available, only the ramdisk is used. images/*.img boot images to use with DrakX. Use: - cdrom for cdrom install - network for ftp/nfs install (non-pcmcia devices) - hd for hard-disk install - pcmcia for pcmcia install (see ``PCMCIA install'' below for more) the following modules have been removed from: network.img: acenic sk98lin de4x5 cdrom.img and hd.img: BusLogic seagate fdomain g_NCR5380 dc395x_trm tmscsim hd.img: dpt_i2o eata eata_pio eata_dma cdrom.img: aztcd gscd isp16 mcd mcdx optcd cm206 sjcd pcmcia.img: apa1480_cb they are now in "other.img", blank.img is a blank boot image without a kernel nor initrd. this image can be used to generate custom boot disk (to use it: compile your custom kernel with everything needed compiled in the kernel, not as a module (loop.o, ext3.o if needed, usb stuff, etc) and put the "vmlinuz" on the blank.img, then boot on it) if you think one of those modules is used a lot, tell me, i may find some room to put it back on the main floppies. ******************************************************************************** * logs ************************************************************************* ******************************************************************************** During install, a lot of interesting stuff can be found in different places: in consoles and in files. To switch to console 2 for example, do Ctrl-Alt-F2 from the X install. - alt-F1: the stdout of the install. Not very interesting stuff - alt-F2: simple shell. Quite a lot of commands are available but as they are written in perl (for space), they do not handle the very same options as normal. After install, you can do ``chroot /mnt'' to see your system just like after rebooting. ``rpm -qa'' works for example. - alt-F3: a lot of interesting things. Be carefull, some ``ERROR'' messages are not interesting. - alt-F4: kernel's place. aka the output of dmesg. - alt-F7: the graphical install lives there - command "bug" puts on floppy lots of interesting stuff. - /tmp/stage1.log: same as alt-F3 part when stage1 run (e.g. actions before graphical install really begins) - /tmp/ddebug.log: (nearly the) same as latter alt-F3 part - /tmp/syslog: same as alt-F4 - /mnt/root/drakx/ddebug.log: at the end of each step, DrakX tries to backup /tmp/ddebug.log to /mnt/root/drakx. Available only after mounting of /. - /mnt/root/drakx/install.log: the log of the installation (or upgrade) of the rpms (just like rpm's /mnt/tmp/(install|upgrade).log) - /mnt/root/drakx/auto_inst.cfg.pl: a kickstart file generated at the end of each step. Can be used in 2 ways: kickstart install or ``defcfg'' install. Hopefully you know about kickstart. ``defcfg'' is a way to customize the default values in install. For example, French can be the default language with a qwerty keyboard, the auto-partitionning partitions can be changed, the default user class can be set to developer (!)... ******************************************************************************** * po translation files ********************************************************* ******************************************************************************** DrakX uses .po files for its translation. A script takes the different strings out of the .pm files. It generates the DrakX.pot file which contains all the english strings to translate. To add a new language, you just have to add it to lang.pm (if it's not there already) and put the .po in the perl-install/po directory (see ``Ramdisk or not'' to know if you have to regenerate the mdkinst_stage2.gz) ******************************************************************************** * PCMCIA install *************************************************************** ******************************************************************************** If the media you use to install is a pcmcia device, use the pcmcia boot disk. ******************************************************************************** * Ramdisk or not *************************************************************** ******************************************************************************** The DrakX install is much bigger than the newt one. So the ramdisk which was used is getting big, and costs a lot in memory (eg: the mdkinst_stage2 is 14MB - 23/09/99) (update! now size is 21MB - 24/01/01) (update! now size is 19MB - 26/04/01) | | newt | DrakX |-------+---------+---------------------------------------------------------- | nfs | live | live | ftp | ramdisk | ramdisk | http | ramdisk | ramdisk | hd | ramdisk | live if Mandrake/mdkinst/usr/bin/runinstall2 is a link, | | | ramdisk otherwise | cdrom | ramdisk | live if memory < 52MB, ramdisk otherwise Where ramdisk is needed, if detected memory is below the limit allowed for ramdisk (maintained in file gi/mdk-stage1/config-stage1.h; currently 52 Mb), a failure dialog will be printed explaining that there is not enough memory to perform the installation. When i say live, it means that the stage1 will *mount* the Mandrake/mdkinst and use it that way. The ramdisk is used in place of the live in some cases. This ramdisk is filled with mdkinst_stage2.gz For cdrom install, the ramdisk is used to speed up things (access time is quite high on cdrom drives) For pcmcia, it depends on the type of install. ******************************************************************************** * modules ********************************************************************** ******************************************************************************** Modules can be found in at least 2 places: - in /modules/modules.mar - in /lib/modules.cz /modules/modules.mar is used in mdk-stage1. It contains only modules interesting for one kind of install. For example in an hd install, it contains scsi modules. For a network install, it contains network card modules. (To create, extract or view files in a ``mar'' archive, please use gi/mdk-stage1/mar/mar; this is basically an archive format meant to be minimalistic) /lib/modules.cz contains all modules, it is used in stage2. To manually install a module during install, switch to console #2 and type "modprobe ". The modprobe program is a perl wrapper around /usr/bin/insmod. It uses the dependencies found in /modules/modules.dep (stage1). /usr/bin/insmod is a wrapper around /usr/bin/insmod_. It just extracts the module out of /lib/modules.cz in /tmp. Then it calls insmod_. /usr/bin/insmod_ is the real prog (which you usually find in /sbin/). You need to give it the complete path. ******************************************************************************** * Making screenshots *********************************************************** ******************************************************************************** 1. easy solution: press "F2"! 2. On a test machine, make a network install, switch to console (ctrl-alt-F2), enter: % xhost+ then, on another computer: % DISPLAY=test_machine:0 xwd -root | convert - screenshot.png ******************************************************************************** * Auto install ***************************************************************** ******************************************************************************** A powerful auto-install system is available. It allows performing an install without any human interaction. To feed automatic parameters to the stage1 part (the textmode part - might not be necessary for you if you plan to do cdrom-based auto-installs, but mostly highly needed when doing network installs), please refer to ../mdk-stage1/doc/TECH-INFOS. About the stage2 part (the actual installer, at the time you're (usually) running in graphical mode), please refer to the nice documentation written by David Eastcott. Either install the package "drakx-autoinstall-doc" from contrib, or browse: http://members.shaw.ca/mandrake/drakx/9.0/HTML/ The previous document will explain you how to setup the contents of the auto_inst.cfg file. Note that you have 3 alternatives for providing this file: - from a floppy disk; use "kickstart=floppy" as kernel parameter, as explained in the document - from the installation volume itself; put the file in the "Mandrake/base" directory of the installation volume; use "kickstart" only, or "kickstart=filename" to specify another filename than auto_inst.cfg - specified by the network; setup your DHCP server to provide the "bootfile" parameter, this file will be used as the "auto_inst.cfg" file, in the case you also provide the "netauto" boot parameter In any case, if the specified file ends with -IP or -IP.pl, IP will be substituted by the IP address of the machine, when doing a network install. Might be useful so that you can control all your auto installs from your server. ******************************************************************************** * Miscellaneous **************************************************************** ******************************************************************************** > o Media access methods: nfs, ftp, http, hd, cdrom > o Stages: init, stage1, stage2 > - What exactly each stage does init loads stage1 stage1 loads stage2, from various medium type stage2 is too big to fit on a floppy, that's why stage1 exists > - How each stage relates to the various media access methods stage1 knows only how to access to the media is compiled for. It contains only the kernel modules needed for that media. For eg, the nfs/ftp/http stage1 (network.img floppy) doesn't contain scsi modules nor ide. > - How one stage terminates and another begins. i.e., How does > stage1 find, mount, and launch stage2? /sbin/init just starts /sbin/stage1, and monitors its execution; it's here to cleanly umount the partitions when stage1 or stage2 dies/finished /sbin/stage1 takes care of mounting stage2 (in ramdisk if necessary) then it execs /usr/bin/runinstall2 (thus, stage2 replaces stage1, and init then monitors stage2) > o Text and Graphic mode installers > - Architectural overview of each have a look at gi/docs/object_class.fig ******************************************************************************** * OEM ************************************************************************** ******************************************************************************** > I am a system OEM in Bangalore,India selling systems bundled with > Mandrake Linux. The problem is that with every system I sell, I need to > install & configure the system which takes HOURS!. Can I do a diskcopy > instead? > > Please Help. This is a major bottleneck for me. many solutions: - make an install on drive hdb, then : dd if=/dev/hdb of=/dev/hdc but you should make sure the hardware is *REALLY* identical. - try the oem feature 3. - burn a cd out of *latest* cooker or 8.0 and above. - boot on it telling "oem" to syslinux !! it will destroy every data on the harddrive or resize (or use free space) if *ONLY* one fat partition is defined !! - you now have a very automated install matrix (duplicate it with "dd if=/dev/hdb of=/dev/hdc bs=1M count=730") put the harddrive in the oem box, the user will now have an *very* automated install, just asking the root password and user password, and some other question according its hardware. 4. just like 3. but you may have to mount /cdrom after typing rescue on syslinux prompt (oem script do it automatically if a automatic boot nfs network has been done as server is known). under /cdrom may be anything as long as it provides an installation tree of Mandrake Linux. after that run oem script by typing "/etc/oem -f" for normal installation or "/etc/oem -f server" for server installation (normal with server installed). 5. (just like 3. without burning a cd, doing the first part by hand) have a look at the /etc/oem script on the rescue and do it by hand... cu Pixel, fpons. comments: 1. maybe copy unnecessary things -> take too long solution -> use bs=8k count=xxxx 2. kernel_reread can be found on the new rescue, source is also at end of this mail. This solution works with one partition. Can be easily enhanced to many primary partitions... For extended partitions, more complicated, but not much :) 3. has just been added in latest cooker. It may still have some pb. The main current limitation is IDE only, though it can be fixed easily for special cases. -------------------------------------------------------------------------------- #include #include #include void die(char *msg) { perror(msg); exit(1); } void kernel_read(char *dev) { int fd; if ((fd = open(dev, O_RDONLY)) == -1) die("can't open device"); ioctl(fd, BLKRRPART, 0); close(fd); } int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, "usage: kernel_read_part \n"); exit(1); } kernel_read(argv[1]); } a> 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
package ugtk2;

use diagnostics;
use strict;
use vars qw(@ISA %EXPORT_TAGS @EXPORT_OK @icon_paths $wm_icon $grab $border); #- leave it on one line, for automatic removal of the line at package creation
use locale;

@ISA = qw(Exporter);
%EXPORT_TAGS = (
    wrappers => [ qw(gtkadd gtkadd_widget gtkappend gtkappend_page gtkappenditems gtkcombo_setpopdown_strings gtkdestroy
                     gtkentry gtkflush gtkhide gtkmodify_font gtkmove gtkpack gtkpack2 gtkpack2_
                     gtkpack2__ gtkpack_ gtkpack__ gtkpowerpack gtkput gtkradio gtkresize gtkroot
                     gtkset_active gtkset_border_width gtkset_editable gtkset_justify gtkset_alignment gtkset_layout gtkset_line_wrap
                     gtkset_markup gtkset_modal gtkset_mousecursor gtkset_mousecursor_normal gtkset_mousecursor_wait gtkset_name
                     gtkset_property gtkset_relief gtkset_selectable gtkset_sensitive gtkset_shadow_type gtkset_size_request
                     gtkset_text gtkset_tip gtkset_visibility gtksetstyle gtkshow gtksignal_connect gtksize gtktext_append
                     gtktext_insert ) ],

    helpers => [ qw(add2notebook add_icon_path escape_text_for_TextView_markup_format gtkcolor gtkcreate_img
                    gtkcreate_pixbuf gtkfontinfo gtkset_background gtktreeview_children set_back_pixmap
                    get_default_step_items set_default_step_items
                    string_size string_width) ],

    create => [ qw(create_adjustment create_box_with_title create_dialog create_factory_menu create_factory_popup_menu
                   create_hbox create_hpaned create_menu create_notebook create_okcancel create_packtable
                   create_scrolled_window create_vbox create_vpaned _create_dialog gtkcreate_frame) ],

    ask => [ qw(ask_browse_tree_info ask_browse_tree_info_given_widgets ask_dir ask_from_entry ask_okcancel ask_warn
                ask_yesorno) ],
    dialogs => [ qw(err_dialog info_dialog warn_dialog) ],

);
$EXPORT_TAGS{all} = [ map { @$_ } values %EXPORT_TAGS ];
@EXPORT_OK = map { @$_ } values %EXPORT_TAGS;

use c;
use log;
use common;
use mygtk2 qw(gtknew); #- do not import gtkadd which conflicts with ugtk2 version

use Gtk2;
use Gtk2::Gdk::Keysyms;


$border = 5;

sub wm_icon() { $wm_icon || $::Wizard_pix_up || "wiz_default_up.png" }

# -=-=---=-=---=-=---=-=---=-=---=-=---=-=---=-=---=-=---=-=---=-=---=-=---
#                 wrappers
#
# Functional-style wrappers to existing Gtk functions; allows to program in
# a more functional way, and especially, first, to avoid using temp
# variables, and second, to "see" directly in the code the user interface
# you're building.

sub gtkdestroy                { mygtk2::may_destroy($_[0]) }
sub gtkflush()                { mygtk2::flush() }
sub gtkhide                   { $_[0]->hide; $_[0] }
sub gtkmove                   { $_[0]->window->move($_[1], $_[2]); $_[0] }
sub gtkpack                   { gtkpowerpack(1, 1, @_) }
sub gtkpack_                  { gtkpowerpack('arg', 1, @_) }
sub gtkpack__                 { gtkpowerpack(0, 1, @_) }
sub gtkpack2                  { gtkpowerpack(1, 0, @_) }
sub gtkpack2_                 { gtkpowerpack('arg', 0, @_) }
sub gtkpack2__                { gtkpowerpack(0, 0, @_) }
sub gtkput                    { $_[0]->put(gtkshow($_[1]), $_[2], $_[3]); $_[0] }
sub gtkresize                 { $_[0]->window->resize($_[1], $_[2]); $_[0] }
sub gtkset_active             { $_[0]->set_active($_[1]); $_[0] }
sub gtkset_border_width       { $_[0]->set_border_width($_[1]); $_[0] }
sub gtkset_editable           { $_[0]->set_editable($_[1]); $_[0] }
sub gtkset_selectable         { $_[0]->set_selectable($_[1]); $_[0] }
sub gtkset_justify            { $_[0]->set_justify($_[1]); $_[0] }
sub gtkset_alignment          { $_[0]->set_alignment($_[1], $_[2]); $_[0] }
sub gtkset_layout             { $_[0]->set_layout($_[1]); $_[0] }
sub gtkset_modal              { $_[0]->set_modal($_[1]); $_[0] }
sub gtkset_mousecursor_normal { gtkset_mousecursor('left-ptr', @_) }
sub gtkset_mousecursor_wait   { gtkset_mousecursor('watch', @_) }
sub gtkset_relief             { $_[0]->set_relief($_[1]); $_[0] }
sub gtkset_sensitive          { $_[0]->set_sensitive($_[1]); $_[0] }
sub gtkset_visibility         { $_[0]->set_visibility($_[1]); $_[0] }
sub gtkset_tip                { $_[0]->set_tip($_[1], $_[2]) if $_[2]; $_[1] }
sub gtkset_shadow_type        { $_[0]->set_shadow_type($_[1]); $_[0] }
sub gtkset_style              { $_[0]->set_style($_[1]); $_[0] }
sub gtkset_size_request       { $_[0]->set_size_request($_[1], $_[2]); $_[0] }
sub gtkshow                   { $_[0]->show; $_[0] }
sub gtksize                   { $_[0]->size($_[1], $_[2]); $_[0] }
sub gtkset_markup             { $_[0]->set_markup($_[1]); $_[0] }
sub gtkset_line_wrap          { $_[0]->set_line_wrap($_[1]); $_[0] }

sub gtkadd {
    my $w = shift;
    foreach my $l (@_) {
	ref $l or $l = gtknew('WrappedLabel', text => $l);
	$w->add(gtkshow($l));
    }
    $w;
}

sub gtkadd_widget {
    my $sg = shift;
    map {
        my $l = $_;
        ref $l or $l = gtknew('WrappedLabel', text => $l);
        $sg->add_widget($l);
        $l;
    } @_;
}

sub gtkappend {
    my $w = shift;
    foreach my $l (@_) {
	ref $l or $l = gtknew('WrappedLabel', text => $l);
	$w->append(gtkshow($l));
    }
    $w;
}

sub gtkappenditems {
    my $w = shift;
    $_->show foreach @_;
    $w->append_items(@_);
    $w;
}

# append page to a notebook
sub gtkappend_page {
    my ($notebook, $page, $o_title) = @_;
    $notebook->append_page($page, $o_title);
    $notebook;
}

sub gtkentry {
    my ($o_text) = @_;
    my $e = gtknew('Entry');
    $o_text and $e->set_text($o_text);
    $e;
}

sub gtksetstyle { 
    my ($w, $s) = @_;
    $w->set_style($s);
    $w;
}

sub gtkradio {
    my $def = shift;
    my $radio;
    map {
        my $w = gtkset_active($radio = Gtk2::RadioButton->new_with_label($radio ? $radio->get_group : undef, $_), $_ eq $def);
        $w->child->set_size_request((mygtk2::get_main_window_size())[0] - 50, -1);
        $w->get_child->set_line_wrap(1);
        $w;
      } @_;
}

sub gtkroot() { mygtk2::root_window() }
sub gtkcolor { &mygtk2::rgb2color }
sub gtkset_background { &mygtk2::set_root_window_background }

sub gtkset_text {
    my ($w, $s) = @_;
    $w->set_text($s);
    $w;
}

sub gtkcombo_setpopdown_strings {
    my $w = shift;
    $w->set_popdown_strings(@_);
    $w;
}

sub gtkset_mousecursor {
    my ($type, $w) = @_;
    ($w || gtkroot())->set_cursor(Gtk2::Gdk::Cursor->new($type));
    $w;
}

sub gtksignal_connect {
    my $w = shift;
    $w->signal_connect(@_);
    $w;
}

sub gtkset_name {
    my ($widget, $name) = @_;
    $widget->set_name($name);
    $widget;
}


sub gtkpowerpack {
    #- Get Default Attributes (if any). 2 syntaxes allowed :
    #- gtkpowerpack( {expand => 1, fill => 0}, $box...) : the attributes are picked from a specified hash ref
    #- gtkpowerpack(1, 0, 1, $box, ...) : the attributes are picked from the non-ref list, in the order (expand, fill, padding, pack_end).
    my @attributes_list = qw(expand fill padding pack_end);
    my $default_attrs = {};
    if (ref($_[0]) eq 'HASH') {
	$default_attrs = shift;
    } elsif (!ref($_[0])) {
	foreach (@attributes_list) {
	    ref($_[0]) and last;
	    $default_attrs->{$_} = shift;
	}
    }
    my $box = shift;

    while (@_) {
	#- Get attributes (if specified). 4 syntaxes allowed (default values are undef ie. false...) :
	#- gtkpowerpack({defaultattrs}, $box, $widget1, $widget2, ...) : the attrs are picked from the default ones (if they exist)
	#- gtkpowerpack($box, {fill=>1, expand=>0, ...}, $widget1, ...) : the attributes are picked from a specified hash ref
	#- gtkpowerpack($box, [1,0,1], $widget1, ...) : the attributes are picked from the array ref : (expand, fill, padding, pack_end).
	#- gtkpowerpack({attr=>'arg'}, $box, 1, $widget1, 0, $widget2, etc...) : the 'arg' value will tell gtkpowerpack to always read the 
	#- attr value directly in the arg list (avoiding confusion between value 0 and Gtk::Label("0"). That can simplify some writings but
	#- this arg(s) MUST then be present...
	my (%attr, $attrs);
	ref($_[0]) eq 'HASH' || ref($_[0]) eq 'ARRAY' and $attrs = shift;
	foreach (@attributes_list) {
	    if (($default_attrs->{$_} || '') eq 'arg') {
		ref($_[0]) and internal_error "error in packing definition\n";
		$attr{$_} = shift;
		ref($attrs) eq 'ARRAY' and shift @$attrs;
	    } elsif (ref($attrs) eq 'HASH' && defined($attrs->{$_})) {
		$attr{$_} = $attrs->{$_};
	    } elsif (ref($attrs) eq 'ARRAY') {
		$attr{$_} = shift @$attrs;
	    } elsif (defined($default_attrs->{$_})) {
		$attr{$_} = int $default_attrs->{$_};
	    } else {
		$attr{$_} = 0;
	    }
	}
	#- Get and pack the widget (create it if necessary to  a label...)
	my $widget = ref($_[0]) ? shift : gtknew('WrappedLabel', text => shift);
	my $pack_call = 'pack_' . ($attr{pack_end} ? 'end' : 'start');
	$box->$pack_call($widget, $attr{expand}, $attr{fill}, $attr{padding});
	$widget->show;
    }
    return $box;
}

sub gtktreeview_children {
    my ($model, $iter) = @_;
    my @l;
    $model or return;
    for (my $p = $model->iter_children($iter); $p; $p = $model->iter_next($p)) {
	push @l, $p;
    }
    @l;
}



# -=-=---=-=---=-=---=-=---=-=---=-=---=-=---=-=---=-=---=-=---=-=---=-=---
#                 create
#
# Helpers that allow omitting common operations on common widgets
# (e.g. create widgets with good default properties)

sub create_pixbutton {
    my ($label, $pix, $reverse_order) = @_;
    my @label_and_pix = (0, $label, if_($pix, 0, $pix));
    gtkadd(gtknew('Button'),
	   gtknew('HBox', spacing => 3, children => [
		    1, "",
		    $reverse_order ? reverse(@label_and_pix) : @label_and_pix,
		    1, "",
		]));
}

sub create_adjustment {
    my ($val, $min, $max) = @_;
    Gtk2::Adjustment->new($val, $min, $max + 1, 1, ($max - $min + 1) / 10, 1);
}

sub create_scrolled_window {
    my ($W, $o_policy, $o_viewport_shadow) = @_;
    gtknew('ScrolledWindow', ($o_policy ? (h_policy => $o_policy->[0], v_policy => $o_policy->[1]) : ()),
               child => $W, if_($o_viewport_shadow, shadow_type => $o_viewport_shadow));