summaryrefslogtreecommitdiffstats
path: root/mdk-stage1
ModeNameSize
-rw-r--r--.cvsignore171logstatsplain
-rw-r--r--Makefile7246logstatsplain
-rw-r--r--Makefile.common1616logstatsplain
-rw-r--r--Makefile.mkinitrd_helper723logstatsplain
-rw-r--r--adsl.c4603logstatsplain
-rw-r--r--adsl.h780logstatsplain
-rw-r--r--automatic.c4286logstatsplain
-rw-r--r--automatic.h1093logstatsplain
d---------bzlib380logstatsplain
-rw-r--r--cdrom.c5376logstatsplain
-rw-r--r--cdrom.h580logstatsplain
-rw-r--r--config-stage1.h1693logstatsplain
-rw-r--r--dhcp.c17815logstatsplain
-rw-r--r--dhcp.h810logstatsplain
d---------dietlibc1546logstatsplain
-rw-r--r--disk.c13703logstatsplain
-rw-r--r--disk.h584logstatsplain
-rw-r--r--dns.c4673logstatsplain
-rw-r--r--dns.h634logstatsplain
d---------doc238logstatsplain
-rw-r--r--frontend-common.c1009logstatsplain
-rw-r--r--frontend.h1786logstatsplain
d---------init-data256logstatsplain
-rw-r--r--init-libc-headers.h1046logstatsplain
-rw-r--r--init.c14634logstatsplain
d---------insmod-busybox371logstatsplain
d---------insmod-modutils212logstatsplain
-rw-r--r--insmod.h502logstatsplain
d---------linux-2.272logstatsplain
-rw-r--r--log.c1636logstatsplain
-rw-r--r--log.h744logstatsplain
-rw-r--r--lomount.c4479logstatsplain
-rw-r--r--lomount.h522logstatsplain
d---------mar241logstatsplain
-rw-r--r--minilibc.c5672logstatsplain
-rw-r--r--minilibc.h5229logstatsplain
d---------mkinitrd_helper81logstatsplain
-rw-r--r--modules.c16191logstatsplain
-rw-r--r--modules.h964logstatsplain
-rw-r--r--modules_descr.h2287logstatsplain
-rw-r--r--mount.c5604logstatsplain
-rw-r--r--mount.h681logstatsplain
-rw-r--r--mount_rpcgen.h6175logstatsplain
-rw-r--r--network.c23748logstatsplain
-rw-r--r--network.h1335logstatsplain
-rw-r--r--newt-frontend.c9251logstatsplain
d---------newt619logstatsplain
-rw-r--r--nfs_mount4.h1510logstatsplain
-rw-r--r--nfsmount.c19033logstatsplain
-rw-r--r--nfsmount.h10466logstatsplain
d---------pci-resource119logstatsplain
d---------pcmcia_743logstatsplain
d---------ppp946logstatsplain
-rw-r--r--probing.c20002logstatsplain
-rw-r--r--probing.h1072logstatsplain
-rw-r--r--rescue-gui.c5810logstatsplain
d---------rp-pppoe410logstatsplain
d---------slang2495logstatsplain
d---------stage1-data149logstatsplain
-rw-r--r--stage1.c19890logstatsplain
-rw-r--r--stage1.h1970logstatsplain
-rw-r--r--stdio-frontend.c7208logstatsplain
-rw-r--r--tools.c12688logstatsplain
-rw-r--r--tools.h1607logstatsplain
-rw-r--r--url.c10667logstatsplain
-rw-r--r--url.h1305logstatsplain
d---------usb-resource119logstatsplain
a id='n1136' href='#n1136'>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
package mygtk2;

use diagnostics;
use strict;
use feature 'state';

our @ISA = qw(Exporter);
our @EXPORT = qw(gtknew gtkset gtkadd gtkval_register gtkval_modify);

use c;
use log;
use common;

use Gtk2;

sub init() {
    !check_for_xserver() and print("Cannot be run in console mode.\n"), c::_exit(0);
    $::one_message_has_been_translated and warn("N() was called from $::one_message_has_been_translated BEFORE gtk2 initialisation, replace it with a N_() AND a translate() later.\n"), c::_exit(1);

    Gtk2->init;
    Locale::gettext::bind_textdomain_codeset($_, 'UTF8') foreach 'libDrakX', if_(!$::isInstall, 'libDrakX-standalone'),
        if_($::isRestore, 'draksnapshot'), if_($::isInstall, 'urpmi'),
        'drakx-net', 'drakx-kbd-mouse-x11', # shared translation
          @::textdomains;
    Glib->enable_exceptions2;
}
init() unless $::no_ugtk_init;
Glib->enable_exceptions2 if $::isInstall;



sub gtknew {
    my $class = shift;
    if (@_ % 2 != 0) {
	internal_error("gtknew $class: bad options @_");
    }
    if (my $r = find { ref $_->[0] } group_by2(@_)) {
	internal_error("gtknew $class: $r should be a string in @_");
    }
    my %opts = @_;
    _gtk(undef, $class, 'gtknew', \%opts);
}

sub gtkset {
    my $w = shift;
    my $class = ref($w);
    if (@_ % 2 != 0) {
	internal_error("gtkset $class: bad options @_");
    }
    if (my $r = find { ref $_->[0] } group_by2(@_)) {
	internal_error("gtkset $class: $r should be a string in @_");
    }
    my %opts = @_;

    $class =~ s/^(Gtk2|Gtk2::Gdk|mygtk2)::// or internal_error("gtkset unknown class $class");
    
    _gtk($w, $class, 'gtkset', \%opts);
}

sub gtkadd {
    my $w = shift;
    my $class = ref($w);
    if (@_ % 2 != 0) {
	internal_error("gtkadd $class: bad options @_");
    }
    if (my $r = find { ref $_->[0] } group_by2(@_)) {
	internal_error("gtkadd $class: $r should be a string in @_");
    }
    my %opts = @_;
    $class =~ s/^(Gtk2|Gtk2::Gdk|mygtk2)::// or internal_error("gtkadd unknown class $class");
    
    _gtk($w, $class, 'gtkadd', \%opts);
}


my %refs;

sub gtkval_register {
    my ($w, $ref, $sub) = @_;
    push @{$w->{_ref}}, $ref;
    $w->signal_connect(destroy => sub { 
	@{$refs{$ref}} = grep { $_->[1] != $w } @{$refs{$ref}};
	delete $refs{$ref} if !@{$refs{$ref}};
    });
    push @{$refs{$ref}}, [ $sub, $w ];
}
sub gtkval_modify {
    my ($ref, $val, @to_skip) = @_;
    my $prev = '' . $ref;
    $$ref = $val;
    if ($prev ne '' . $ref) {
	internal_error();
    }
    foreach (@{$refs{$ref} || []}) {	
	my ($f, @para) = @$_;
	$f->(@para) if !member($f, @to_skip);
    }
}

my $global_tooltips;

sub _gtk {
    my ($w, $class, $action, $opts) = @_;

    if (my $f = $mygtk2::{"_gtk__$class"}) {
	$w = $f->($w, $opts, $class, $action);
    } else {
	internal_error("$action $class: unknown class");
    }

    $w->set_size_request(delete $opts->{width} || -1, delete $opts->{height} || -1) if exists $opts->{width} || exists $opts->{height};
    if (my $position = delete $opts->{position}) {
	$w->move($position->[0], $position->[1]);
    }
    $w->set_name(delete $opts->{widget_name}) if exists $opts->{widget_name};
    $w->can_focus(delete $opts->{can_focus}) if exists $opts->{can_focus};
    $w->can_default(delete $opts->{can_default}) if exists $opts->{can_default};
    $w->grab_focus if delete $opts->{grab_focus};
    $w->set_padding(@{delete $opts->{padding}}) if exists $opts->{padding};
    $w->set_sensitive(delete $opts->{sensitive}) if exists $opts->{sensitive};
    $w->signal_connect(expose_event => delete $opts->{expose_event}) if exists $opts->{expose_event};
    $w->signal_connect(realize => delete $opts->{realize}) if exists $opts->{realize};
    (delete $opts->{size_group})->add_widget($w) if $opts->{size_group};
    if (my $tip = delete $opts->{tip}) {
	$global_tooltips ||= Gtk2::Tooltips->new;
	$global_tooltips->set_tip($w, $tip);
    }

    #- WARNING: hide_ref and show_ref are not effective until you gtkval_modify the ref
    if (my $hide_ref = delete $opts->{hide_ref}) {
	gtkval_register($w, $hide_ref, sub { $$hide_ref ? $w->hide : $w->show });
    } elsif (my $show_ref = delete $opts->{show_ref}) {
	gtkval_register($w, $show_ref, sub { $$show_ref ? $w->show : $w->hide });
    }

    if (my $sensitive_ref = delete $opts->{sensitive_ref}) {
	my $set = sub { $w->set_sensitive($$sensitive_ref) };
	gtkval_register($w, $sensitive_ref, $set);
	$set->();
    }

    if (%$opts && !$opts->{allow_unknown_options}) {
	internal_error("$action $class: unknown option(s) " . join(', ', keys %$opts));
    }
    $w;
}

sub _gtk__Install_Button {
    my ($w, $opts, $_class) = @_;
    $opts->{child} = gtknew('HBox', spacing => 5, 
                             children_tight => [
                                 # FIXME: not RTL compliant (lang::text_direction_rtl() ? ...)
                                 gtknew('Image', file => 'advanced_expander'),
                                 gtknew('Label', text => delete $opts->{text}),
                             ],
                         );
    $opts->{relief} = 'none';
    _gtk__Button($w, $opts, 'Button');
}

sub _gtk__Button       { &_gtk_any_Button }
sub _gtk__ToggleButton { &_gtk_any_Button }
sub _gtk__CheckButton  { &_gtk_any_Button }
sub _gtk__RadioButton  { &_gtk_any_Button }
sub _gtk_any_Button {
    my ($w, $opts, $class) = @_;

    if (!$w) {
        my @radio_options;
        if ($class eq 'RadioButton') {
            @radio_options = delete $opts->{group};
	}
	$w = $opts->{child} ? "Gtk2::$class"->new(@radio_options) :
	  delete $opts->{mnemonic} ? "Gtk2::$class"->new_with_mnemonic(@radio_options, delete $opts->{text} || '') :
	    $opts->{text} ? "Gtk2::$class"->new_with_label(@radio_options, delete $opts->{text} || '') :
           "Gtk2::$class"->new(@radio_options);

	$w->{format} = delete $opts->{format} if exists $opts->{format};
    }

    if (my $widget = delete $opts->{child}) {
	$w->add($widget);
	$widget->show;
    }
    $w->set_image(delete $opts->{image}) if exists $opts->{image};
    $w->set_relief(delete $opts->{relief}) if exists $opts->{relief};

    if (my $text_ref = delete $opts->{text_ref}) {
	my $set = sub {
	    eval { $w->set_label(may_apply($w->{format}, $$text_ref)) };
	};
	gtkval_register($w, $text_ref, $set);
	$set->();
    } elsif (exists $opts->{text}) {
	$w->set_label(delete $opts->{text});
    } elsif (exists $opts->{stock}) {
	$w->set_label(delete $opts->{stock});
	$w->set_use_stock(1);
    }

    if ($class eq 'Button') {
	$w->signal_connect(clicked => delete $opts->{clicked}) if exists $opts->{clicked};
    } else {
	if (my $active_ref = delete $opts->{active_ref}) {
	    my $set = sub { $w->set_active($$active_ref) };
	    $w->signal_connect(toggled => sub {
		gtkval_modify($active_ref, $w->get_active, $set);
	    });
	    gtkval_register($w, $active_ref, $set);
	    gtkval_register($w, $active_ref, delete $opts->{toggled}) if exists $opts->{toggled};
	    $set->();
	} else {
	    $w->set_active(delete $opts->{active}) if exists $opts->{active};
	    $w->signal_connect(toggled => delete $opts->{toggled}) if exists $opts->{toggled};
	}
    }
    $w;
}

sub _gtk__CheckMenuItem {
    my ($w, $opts, $class) = @_;

    if (!$w) {
	add2hash_($opts, { mnemonic => 1 });

	$w = $opts->{image} || !exists $opts->{text} ? "Gtk2::$class"->new :
	  delete $opts->{mnemonic} ? "Gtk2::$class"->new_with_label(delete $opts->{text}) :
	    "Gtk2::$class"->new_with_mnemonic(delete $opts->{text});
    }

    $w->set_active(delete $opts->{active}) if exists $opts->{active};
    $w->signal_connect(toggled => delete $opts->{toggled}) if exists $opts->{toggled};
    $w;
}

sub _gtk__SpinButton {
    my ($w, $opts) = @_;

    if (!$w) {
	$opts->{adjustment} ||= do {
	    add2hash_($opts, { step_increment => 1, page_increment => 5, page_size => 1, value => delete $opts->{lower} });
	    Gtk2::Adjustment->new(delete $opts->{value}, delete $opts->{lower}, delete $opts->{upper}, delete $opts->{step_increment}, delete $opts->{page_increment}, delete $opts->{page_size});
	};
	$w = Gtk2::SpinButton->new(delete $opts->{adjustment}, delete $opts->{climb_rate} || 0, delete $opts->{digits} || 0);
    }

    $w->signal_connect(value_changed => delete $opts->{value_changed}) if exists $opts->{value_changed};
    $w;
}

sub _gtk__HScale {
    my ($w, $opts) = @_;

    if (!$w) {
	$opts->{adjustment} ||= do {
	    add2hash_($opts, { step_increment => 1, page_increment => 5, page_size => 1 });
	    add2hash_($opts, { value => $opts->{lower} }) if !exists $opts->{value};
	    Gtk2::Adjustment->new(delete $opts->{value}, delete $opts->{lower}, (delete $opts->{upper}) + 1, delete $opts->{step_increment}, delete $opts->{page_increment}, delete $opts->{page_size});
	};
	$w = Gtk2::HScale->new(delete $opts->{adjustment});
    }

    $w->set_digits(delete $opts->{digits}) if exists $opts->{digits};
    if (my $value_ref = delete $opts->{value_ref}) {
	my $set = sub { $w->set_value($$value_ref) };
	gtkval_register($w, $value_ref, $set);
	$set->();
	$w->signal_connect(value_changed => sub {
		gtkval_modify($value_ref, $w->get_value, $set);
	});
    }
    $w->signal_connect(value_changed => delete $opts->{value_changed}) if exists $opts->{value_changed};
    $w;
}

sub _gtk__ProgressBar {
    my ($w, $opts) = @_;

    if (!$w) {
	$w = Gtk2::ProgressBar->new;
    }

    if (my $fraction_ref = delete $opts->{fraction_ref}) {
	my $set = sub { $w->set_fraction($$fraction_ref) };
	gtkval_register($w, $fraction_ref, $set);
	$set->();
    } elsif (exists $opts->{fraction}) {
	$w->set_fraction(delete $opts->{fraction});
    }

    $w;
}

sub _gtk__VSeparator { &_gtk_any_simple }
sub _gtk__HSeparator { &_gtk_any_simple }
sub _gtk__Calendar   { &_gtk_any_simple }

sub _gtk__DrawingArea {
    my ($w, $_opts) = @_;

    if (!$w) {
	$w = Gtk2::DrawingArea->new;
    }
    $w;
}

sub _gtk__Pixbuf {
    my ($w, $opts) = @_;

    if (!$w) {
	my $name = delete $opts->{file} or internal_error("missing file");
	my $file = _find_imgfile($name) or internal_error("cannot find image $name");
	if (my $size = delete $opts->{size}) {
	    $w = Gtk2::Gdk::Pixbuf->new_from_file_at_scale($file, $size, $size, 1);
	} else {
	    $w = Gtk2::Gdk::Pixbuf->new_from_file($file);
	}
        $w = $w->flip(1) if delete $opts->{flip};
    }
    $w;
}

# Image_using_pixmap is rendered using DITHER_MAX which is much better on 16bpp displays
sub _gtk__Image_using_pixmap { &_gtk__Image }
# Image_using_pixbuf is rendered using DITHER_MAX & transparency which is much better on 16bpp displays
sub _gtk__Image_using_pixbuf { &_gtk__Image }
sub _gtk__Image {
    my ($w, $opts, $class) = @_;

    if (!$w) {
	$w = Gtk2::Image->new;
	$w->{format} = delete $opts->{format} if exists $opts->{format};
        
        $w->set_from_stock(delete $opts->{stock}, 'button') if exists $opts->{stock};

        $w->{options} = { flip => delete $opts->{flip} };

        $w->{set_from_file} = $class =~ /using_pixmap/ ? sub { 
            my ($w, $file) = @_;
            my $pixmap = mygtk2::pixmap_from_pixbuf($w, gtknew('Pixbuf', file => $file));
	    $w->set_from_pixmap($pixmap, undef);
        } : $class =~ /using_pixbuf/ ? sub { 
            my ($w, $file) = @_;
            my $pixbuf = _pixbuf_render_alpha(gtknew('Pixbuf', file => $file, %{$w->{options}}), 255);
            my ($width, $height) = ($pixbuf->get_width, $pixbuf->get_height);
            $w->set_size_request($width, $height);
            $w->{pixbuf} = $pixbuf;
            $w->signal_connect(expose_event => sub {
                                   my (undef, $event) = @_;
                                   if (!$w->{x}) {
                                       my $alloc = $w->allocation;
                                       $w->{x} = $alloc->x;
                                       $w->{y} = $alloc->y;
                                   }
                                   # workaround Gtk+ bug: in installer, first event is not complete and rectables are bogus:
                                   if ($::isInstall) {
                                       $pixbuf->render_to_drawable($w->window, $w->style->fg_gc('normal'),
                                                                   0, 0, $w->{x}, $w->{y}, $width, $height, 'max', 0, 0);
                                       return;
                                   }
                                   foreach my $rect ($event->region->get_rectangles) {
                                       my @values = $rect->values;
                                       $pixbuf->render_to_drawable($w->window, $w->style->fg_gc('normal'),
                                                               @values[0..1], $w->{x}+$values[0], $w->{y}+$values[1], @values[2..3], 'max', 0, 0);
				   }
                               });
        } : sub { 
            my ($w, $file, $o_size) = @_;
            my $pixbuf = gtknew('Pixbuf', file => $file, if_($o_size, size => $o_size), %{$w->{options}});
            $w->set_from_pixbuf($pixbuf);
        };
    }

    if (my $name = delete $opts->{file}) {
	my $file = _find_imgfile(may_apply($w->{format}, $name)) or internal_error("cannot find image $name");
	$w->{set_from_file}->($w, $file, delete $opts->{size});
    } elsif (my $file_ref = delete $opts->{file_ref}) {
	my $set = sub {
	    my $file = _find_imgfile(may_apply($w->{format}, $$file_ref)) or internal_error("cannot find image $$file_ref");
	    $w->{set_from_file}->($w, $file, delete $opts->{size});
	};
	gtkval_register($w, $file_ref, $set);
	$set->() if $$file_ref;
    }
    $w;
}

sub _gtk__WrappedLabel {
    my ($w, $opts) = @_;
    
    $opts->{line_wrap} = 1 if !defined $opts->{line_wrap};
    _gtk__Label($w, $opts);
}

our $left_padding = 20;

sub _gtk__Label_Left {
    my ($w, $opts) = @_;
    $opts->{alignment} ||= [ 0, 0 ];
    $opts->{padding} ||= [ $left_padding, 0 ];
    _gtk__WrappedLabel($w, $opts);
}

sub _gtk__Label_Right {
    my ($w, $opts) = @_;
    $opts->{alignment} ||= [ 1, 0.5 ];
    _gtk__Label($w, $opts);
}


sub _gtk__Label {
    my ($w, $opts) = @_;

    if ($w) {
	$w->set_text(delete $opts->{text}) if exists $opts->{text};
    } else {
	$w = exists $opts->{text} ? Gtk2::Label->new(delete $opts->{text}) : Gtk2::Label->new;
	$w->set_selectable(delete $opts->{selectable}) if exists $opts->{selectable};
	$w->set_ellipsize(delete $opts->{ellipsize}) if exists $opts->{ellipsize};
	$w->set_justify(delete $opts->{justify}) if exists $opts->{justify};
	$w->set_line_wrap(delete $opts->{line_wrap}) if exists $opts->{line_wrap};
	$w->set_alignment(@{delete $opts->{alignment}}) if exists $opts->{alignment};
	$w->modify_font(Gtk2::Pango::FontDescription->from_string(delete $opts->{font})) if exists $opts->{font};
    }

    if (my $text_ref = delete $opts->{text_ref}) {
	my $set = sub { $w->set_text($$text_ref) };
	gtkval_register($w, $text_ref, $set);
	$set->();
    }

    if (my $t = delete $opts->{text_markup}) {
	$w->set_markup($t);
	if ($w->get_text eq '') {
	    log::l("invalid markup in $t. not using the markup");
	    $w->set_text($t);
	}
    }
    $w;
}


sub _gtk__Alignment {
    my ($w, $_opts) = @_;

    if (!$w) {
	$w = Gtk2::Alignment->new(0, 0, 0, 0);
    }
    $w;
}


sub title1_to_markup {
    my ($label) = @_;
    if ($::isInstall) {
        my $font = lang::l2pango_font($::o->{locale}{lang});
        if (my ($font_size) = $font =~ /(\d+)/) {
            $font_size++;
            $font =~ s/\d+/$font_size/;
        }
        qq(<span foreground="#5A8AD6" font="$font">$label</span>);
    } else {
        qq(<b><big>$label</big></b>);
  }
}

sub _gtk__Install_Title {
    my ($w, $opts) = @_;
    local $opts->{widget_name} = 'Banner';
    $opts->{text} = uc($opts->{text}) if $::isInstall;
    gtknew('HBox', widget_name => 'Banner', children => [
        0, gtknew('Label', padding => [ 6, 0 ]),
        1, gtknew('VBox', widget_name => 'Banner', children_tight => [
            _gtk__Title2($w, $opts),
            if_($::isInstall, Gtk2::HSeparator->new),
        ]),
        0, gtknew('Label', padding => [ 6, 0 ]),
    ]);
}

sub _gtk__Title1 {
    my ($w, $opts) = @_;
    $opts ||= {};
    $opts->{text_markup} = title1_to_markup(delete($opts->{label})) if $opts->{label};
    _gtk__WrappedLabel($w, $opts);
}

sub _gtk__Title2 {
    my ($w, $opts) = @_;
    $opts ||= {};
    $opts->{alignment} = [ 0, 0 ];
    _gtk__Title1($w, $opts);
}

sub _gtk__Sexy_IconEntry {
    my ($w, $opts) = @_;

    require Gtk2::Sexy;
    if (!$w) {
	$w = Gtk2::Sexy::IconEntry->new;
	$w->set_editable(delete $opts->{editable}) if exists $opts->{editable};
    }

    $w->add_clear_button if delete $opts->{clear_button};
    if (my $icon = delete $opts->{primary_icon}) {
        $w->set_icon('primary', $icon);
        $w->set_icon_highlight('primary', $icon);
    }
    if (my $icon = delete $opts->{secondary_icon}) {
        $w->set_icon('secondary', $icon);
        $w->set_icon_highlight('secondary', $icon);
    }

    $w->signal_connect('icon-released' => delete $opts->{'icon-released'}) if exists $opts->{'icon-released'};
    $w->signal_connect('icon-pressed' => delete $opts->{'icon-pressed'}) if exists $opts->{'icon-pressed'};

    _gtk__Entry($w, $opts);
}

sub _gtk__Entry {
    my ($w, $opts) = @_;

    if (!$w) {
	$w = Gtk2::Entry->new;
	$w->set_editable(delete $opts->{editable}) if exists $opts->{editable};
    }

    if (my $icon = delete $opts->{primary_icon}) {
        $w->set_icon_from_stock('primary', $icon);
        #$w->set_icon_highlight('primary', $icon);
    }
    if (my $icon = delete $opts->{secondary_icon}) {
        $w->set_icon_from_stock('secondary', $icon);
        #$w->set_icon_highlight('secondary', $icon);
    }

    $w->signal_connect('icon-release' => delete $opts->{'icon-release'}) if exists $opts->{'icon-release'};
    $w->signal_connect('icon-press' => delete $opts->{'icon-press'}) if exists $opts->{'icon-press'};

    $w->set_text(delete $opts->{text}) if exists $opts->{text};
    $w->signal_connect(key_press_event => delete $opts->{key_press_event}) if exists $opts->{key_press_event};

    if (my $text_ref = delete $opts->{text_ref}) {
	my $set = sub { $w->set_text($$text_ref) };
	gtkval_register($w, $text_ref, $set);
	$set->();
	$w->signal_connect(changed => sub {
		gtkval_modify($text_ref, $w->get_text, $set);
	});
    }

    $w;
}

sub _gtk__WeaknessCheckEntry {
    my ($w, $opts) = @_;

    if (!$w) {
	$w = _gtk__Entry($w, $opts);
    }

    $w->signal_connect('changed' => sub {
	require authentication;
	my $password_weakness = authentication::compute_password_weakness($w->get_text);
	$w->set_icon_from_pixbuf('GTK_ENTRY_ICON_SECONDARY', _get_weakness_icon($password_weakness));
	$w->set_icon_tooltip_text('GTK_ENTRY_ICON_SECONDARY', _get_weakness_tooltip($password_weakness));
    });

    $w;
}

sub _gtk__TextView {
    my ($w, $opts, $_class, $action) = @_;
	
    if (!$w) {
	$w = Gtk2::TextView->new;
	$w->set_editable(delete $opts->{editable}) if exists $opts->{editable};
	$w->set_wrap_mode(delete $opts->{wrap_mode}) if exists $opts->{wrap_mode};
	$w->set_cursor_visible(delete $opts->{cursor_visible}) if exists $opts->{cursor_visible};
    }

    _text_insert($w, delete $opts->{text}, append => $action eq 'gtkadd') if exists $opts->{text};
    $w;
}

sub _gtk__WebKit_View {
    my ($w, $opts, $_class, $_action) = @_;
    if (!$w) {
        $w = Gtk2::WebKit::WebView->new;
    }

    # disable contextual menu:
    if (delete $opts->{no_popup_menu}) {
        $w->signal_connect('populate-popup' => sub {
                               my (undef, $menu) = @_;
                               $menu->destroy if $menu;
                               1;
                           });
    }

    $w;
}

sub _gtk__ComboBox {
    my ($w, $opts, $_class, $action) = @_;

    if (!$w) {
	$w = Gtk2::ComboBox->new_text;
	$w->{format} = delete $opts->{format} if exists $opts->{format};

    }
    my $set_list = sub {
	$w->{formatted_list} = $w->{format} ? [ map { $w->{format}($_) } @{$w->{list}} ] : $w->{list};
	$w->get_model->clear;
	$w->{strings} = $w->{formatted_list};  # used by Gtk2::ComboBox wrappers such as get_text() in ugtk2
	$w->append_text($_) foreach @{$w->{formatted_list}};
    };
    if (my $list_ref = delete $opts->{list_ref}) {
	!$opts->{list} or internal_error("both list and list_ref");
	my $set = sub {
	    $w->{list} = $$list_ref;
	    $set_list->();
	};
	gtkval_register($w, $list_ref, $set);
	$set->();
    } elsif (exists $opts->{list}) {
	$w->{list} = delete $opts->{list};
	$set_list->();
    }

    if ($action eq 'gtknew') {
	if (my $text_ref = delete $opts->{text_ref}) {
	    my $set = sub {
		my $val = may_apply($w->{format}, $$text_ref);
		eval { $w->set_active(find_index { $_ eq $val } @{$w->{formatted_list}}) };
	    };
	    $w->signal_connect(changed => sub {
		gtkval_modify($text_ref, $w->{list}[$w->get_active], $set);
	    });
	    gtkval_register($w, $text_ref, $set);
	    gtkval_register($w, $text_ref, delete $opts->{changed}) if exists $opts->{changed};
	    $set->();
	} else {
	    my $val = delete $opts->{text};
	    eval { $w->set_active(find_index { $_ eq $val } @{$w->{formatted_list}}) } if defined $val;
	    $w->signal_connect(changed => delete $opts->{changed}) if exists $opts->{changed};
	}
    }
    $w;
}

sub _gtk__ScrolledWindow {
    my ($w, $opts, $_class, $action) = @_;
	
    if (!$w) {
	$w = Gtk2::ScrolledWindow->new(undef, undef);
	$w->set_policy(delete $opts->{h_policy} || 'automatic', delete $opts->{v_policy} || 'automatic');
    }

    my $faked_w = $w;

    if (my $child = delete $opts->{child}) {
	if (member(ref($child), qw(Gtk2::Layout Gtk2::Html2::View  Gtk2::SimpleList Gtk2::SourceView::View Gtk2::Text Gtk2::TextView Gtk2::TreeView Gtk2::WebKit::WebView))) {
	    $w->add($child);
	} else {
	    $w->add_with_viewport($child);
	}
	$child->set_focus_vadjustment($w->get_vadjustment) if $child->can('set_focus_vadjustment');
	$child->set_left_margin(6) if ref($child) =~ /Gtk2::TextView/ && $child->get_left_margin <= 6;
	$child->show;

	$w->child->set_shadow_type(delete $opts->{shadow_type}) if exists $opts->{shadow_type};

	if (ref($child) eq 'Gtk2::TextView' && delete $opts->{to_bottom}) {
	    $child->{to_bottom} = _allow_scroll_TextView_to_bottom($w, $child);
	}

	if (!delete $opts->{no_shadow} && $action eq 'gtknew' && ref($child) =~ /Gtk2::(Html2|SimpleList|TextView|TreeView|WebKit::WebView)/) {
	    $faked_w = gtknew('Frame', shadow_type => 'in', child => $w);
	}
    }
    $faked_w;
}

sub _gtk__Frame {
    my ($w, $opts) = @_;

    if ($w) {
	$w->set_label(delete $opts->{text}) if exists $opts->{text};
    } else {
	$w = Gtk2::Frame->new(delete $opts->{text});
	$w->set_border_width(delete $opts->{border_width}) if exists $opts->{border_width};
	$w->set_shadow_type(delete $opts->{shadow_type}) if exists $opts->{shadow_type};
    }

    if (my $child = delete $opts->{child}) {
	$w->add($child);
	$child->show;
    }
    $w;
}

sub _gtk__Expander {
    my ($w, $opts) = @_;

    if ($w) {
	$w->set_label(delete $opts->{text}) if exists $opts->{text};
    } else {
	$w = Gtk2::Expander->new(delete $opts->{text});
    }

    $w->signal_connect(activate => delete $opts->{activate}) if exists $opts->{activate};

    if (my $child = delete $opts->{child}) {
	$w->add($child);
	$child->show;
    }
    $w;
}



sub _gtk__MDV_Notebook {
    my ($w, $opts, $_class, $_action) = @_;
    if (!$w) {
        import_style_ressources();

        my ($layout, $selection_arrow, $selection_bar);
        my $parent_window = delete $opts->{parent_window} || root_window();
        my $root_height = first($parent_window->get_size);
        my $suffix = $root_height == 800 && !$::isStandalone ? '_600' : '_768';
        # the white square is a little bit above the actual left sidepanel:
        my $offset = 20;
        my $is_flip_needed = text_direction_rtl();
        my $filler = gtknew('Image', file => 'left-background-filler.png');
        my $filler_height = $filler->get_pixbuf->get_height;
        my $left_background = gtknew('Image_using_pixbuf', file => 'left-background.png');