Restore missing hints on widgets
[clawsker.git] / clawsker
index d1d666d42e4d171d3ff5e357d962d8e83e3bcdd2..38d8c11256c73a7b1666dc1db1eca2f27121aad4 100755 (executable)
--- a/clawsker
+++ b/clawsker
@@ -42,9 +42,6 @@ setlocale (LC_ALL, $locale);
 bindtextdomain ($NAME, sprintf ('%s/share/locale', $PREFIX));
 textdomain ($NAME);
 
-my $SHOWHINTS = FALSE;
-$SHOWHINTS = TRUE if ($Gtk3::VERSION >= 1.040 and Gtk3->CHECK_VERSION (2, 12, 0));
-
 sub _ {
     my $str = shift;
     my %par = @_;
@@ -65,6 +62,8 @@ sub _ {
     about_license => _('License:'),
     about_version => _('Version:'),
 
+    error_title => _('Clawsker error'),
+
     exit_title => _('Clawsker warning'),
     exit_fact => _('There are unapplied modifications.'),
     exit_question => _('Do you really want to quit?'),
@@ -383,32 +382,32 @@ sub handle_nchar_value {
         if defined $$dataref->[IVALUE];
 }
 
-sub gdk_color_from_str {
+sub gdk_rgba_from_str {
     my ($str) = @_;
     my ($rr, $gg, $bb) = (0, 0 ,0);
     $_ = uc ($str);
     if (/\#([A-F0-9][A-F0-9])([A-F0-9][A-F0-9])([A-F0-9][A-F0-9])/) {
-        $rr = hex($1) * 256;
-        $gg = hex($2) * 256;
-        $bb = hex($3) * 256;
+        $rr = hex($1) / 256;
+        $gg = hex($2) / 256;
+        $bb = hex($3) / 256;
     }
-    my $color = Gtk3::Gdk::Color->new ($rr, $gg, $bb);
+    my $color = Gtk3::Gdk::RGBA->new ($rr, $gg, $bb, 1.0);
     return $color;
 }
 
-sub str_from_gdk_color {
+sub str_from_gdk_rgba {
     my ($color) = @_;
-    my $rr = $color->red / 256;
-    my $gg = $color->green / 256;
-    my $bb = $color->blue / 256;
+    my $rr = $color->red * 256;
+    my $gg = $color->green * 256;
+    my $bb = $color->blue * 256;
     my $str = sprintf ("#%.2x%.2x%.2x", $rr, $gg, $bb);
     return $str;
 }
 
 sub handle_color_value {
     my ($widget, $event, $dataref) = @_;
-    my $newcol = $widget->get_color;
-    $$dataref->[VALUE] = str_from_gdk_color ($newcol);
+    my $newcol = $widget->get_rgba;
+    $$dataref->[VALUE] = str_from_gdk_rgba ($newcol);
     $MODIFIED += $$dataref->[VALUE] ne $$dataref->[IVALUE]? 1: -1
         if defined $$dataref->[IVALUE];
 }
@@ -450,12 +449,37 @@ sub log_message {
     }
 }
 
+sub message_dialog {
+    my ($parent, $title, $markup, $type, $buttons) = @_;
+    my $flags = [qw/modal destroy-with-parent/];
+    my $dialog = Gtk3::Dialog->new_with_buttons (
+        $title, $parent, $flags, @$buttons
+    );
+    my $label = Gtk3::Label->new;
+    $label->set_markup ($markup);
+    my $icon = undef;
+    if ($type eq 'error') {
+      $icon = Gtk3::Image->new_from_icon_name('dialog-error', 'GTK_ICON_SIZE_DIALOG');
+    } elsif ($type eq 'warning') {
+      $icon = Gtk3::Image->new_from_icon_name('dialog-warning', 'GTK_ICON_SIZE_DIALOG');
+    } elsif ($type eq 'question') {
+      $icon = Gtk3::Image->new_from_icon_name('dialog-question', 'GTK_ICON_SIZE_DIALOG');
+    }
+    my $hbox = Gtk3::Box->new ('horizontal', 5);
+    $hbox->pack_start ($icon, FALSE, FALSE, 5) if defined $icon;
+    $hbox->pack_start ($label, FALSE, FALSE, 5);
+    my $dialogbox = $dialog->get_content_area;
+    $dialogbox->add ($hbox);
+    $dialogbox->show_all;
+    return $dialog;
+}
+
 sub error_dialog {
     my ($emsg) = @_;
     my $markup = "<span weight=\"bold\" size=\"large\">" . $emsg . "</span>";
-    my $errordlg = Gtk3::MessageDialog->new ($main_window, 'modal', 'error', 'cancel');
-    $errordlg->set_markup ($markup);
-    $errordlg->set_title (_('Clawsker error'));
+    my $errordlg = message_dialog (
+        $main_window, $xl::s{error_title}, $markup, 'error', [ 'gtk-cancel', 0 ]
+    );
     $errordlg->run;
     $errordlg->destroy;
 }
@@ -493,11 +517,9 @@ sub check_rc_file {
 }
 
 sub set_widget_hint {
-    if ($SHOWHINTS) {
-        my ($wdgt, $hint) = @_;
-        $wdgt->set_tooltip_text ($hint);
-        $wdgt->set_has_tooltip (TRUE);
-    }
+    my ($wdgt, $hint) = @_;
+    $wdgt->set_tooltip_text ($hint);
+    $wdgt->set_has_tooltip (TRUE);
 }
 
 sub set_widget_sens {
@@ -606,9 +628,9 @@ sub new_color_button_for($$$) {
     #
     my $value = $$vhash{$name}[VALUE];
     $value //= $$hash{$key}[CMDEF];
-    my $col = gdk_color_from_str ($value);
+    my $col = gdk_rgba_from_str ($value);
     my $glabel = Gtk3::Label->new ($label);
-    my $button = Gtk3::ColorButton->new_with_color ($col);
+    my $button = Gtk3::ColorButton->new_with_rgba ($col);
     $button->set_title ($label);
     $button->set_relief ('none');
     $button->signal_connect ('color-set' => sub {
@@ -2794,16 +2816,15 @@ along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.";
 sub exit_handler {
   my ($parent) = @_;
   if ($MODIFIED != 0 and not $READONLY) {
-    my $fact = $xl::s{exit_fact};
-    my $question = $xl::s{exit_question};
-    my $dialog = Gtk3::MessageDialog->new ($parent,
-        [qw/modal destroy-with-parent/], 'warning', 'yes-no');
-    $dialog->set_markup ("<span>$fact</span>\n\n"
-        . "<span weight=\"bold\">$question</span>");
-    $dialog->set_title ($xl::s{exit_title});
+    my $markup = "<span>" . $xl::s{exit_fact} . "</span>\n\n"
+        . "<span weight=\"bold\">" . $xl::s{exit_question} . "</span>\n";
+    my $dialog = message_dialog (
+        $parent, $xl::s{exit_title}, $markup, 'question',
+        [ 'gtk-no', 1, 'gtk-yes', 0 ]
+    );
     my $resp = $dialog->run;
     $dialog->hide;
-    return TRUE if ($resp eq 'no');
+    return TRUE if ($resp == 1);
   }
   Gtk3->main_quit;
 }
@@ -2855,7 +2876,7 @@ sub get_app_icons {
 
 sub escape_key_handler {
     my ($widget, $event) = @_;
-    if ($event->keyval == Gtk3::Gdk->keyval_from_name('Escape')) {
+    if ($event->keyval == Gtk3::Gdk::keyval_from_name('Escape')) {
         exit_handler($widget);
     }
 }
@@ -2869,7 +2890,7 @@ exit unless init_hidden_preferences ();
 # create main GUI
 my $box = Gtk3::VBox->new (FALSE, 5);
 $box->set_border_width(3);
-my $about = new_about_dialog ();
+my $about = new_about_dialog ($main_window);
 $box->pack_start (new_notebook (), TRUE, TRUE, 0);
 $box->pack_end (new_button_box ($main_window, $about), FALSE, FALSE, 0);
 $main_window->signal_connect (delete_event => sub { exit_handler($main_window) });