Fix #1076: webp images show up as black
[geeqie.git] / src / window.cc
index b0706d7..7aa437c 100644 (file)
 #include "ui-misc.h"
 #include "ui-utildlg.h"
 
-GtkWidget *window_new(GtkWindowType type, const gchar *role, const gchar *icon,
-                     const gchar *icon_file, const gchar *subtitle)
+GtkWidget *window_new(const gchar *role, const gchar *icon, const gchar *icon_file, const gchar *subtitle)
 {
        gchar *title;
        GtkWidget *window;
 
-       window = gtk_window_new(type);
-       if (!window) return NULL;
+#ifdef HAVE_GTK4
+       window = gtk_window_new();
+#else
+       window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+#endif
+       if (!window) return nullptr;
 
        if (subtitle)
                {
@@ -72,7 +75,7 @@ void window_set_icon(GtkWidget *window, const gchar *icon, const gchar *file)
                }
        else
                {
-               gtk_window_set_icon_from_file(GTK_WINDOW(window), file, NULL);
+               gtk_window_set_icon_from_file(GTK_WINDOW(window), file, nullptr);
                }
 }
 
@@ -94,19 +97,19 @@ gboolean window_maximized(GtkWidget *window)
 
 static gchar *command_result(const gchar *binary, const gchar *command)
 {
-       gchar *result = NULL;
+       gchar *result = nullptr;
        FILE *f;
        gchar buf[2048];
        gint l;
 
-       if (!binary || binary[0] == '\0') return NULL;
-       if (!file_in_path(binary)) return NULL;
+       if (!binary || binary[0] == '\0') return nullptr;
+       if (!file_in_path(binary)) return nullptr;
 
        if (!command || command[0] == '\0') return g_strdup(binary);
        if (command[0] == '!') return g_strdup(command + 1);
 
        f = popen(command, "r");
-       if (!f) return NULL;
+       if (!f) return nullptr;
 
        while ((l = fread(buf, sizeof(gchar), sizeof(buf), f)) > 0)
                {
@@ -172,29 +175,29 @@ static int help_browser_command(const gchar *command, const gchar *path)
 static const gchar *html_browsers[] =
 {
        /* Our specific script */
-       GQ_APPNAME_LC "_html_browser", NULL,
+       GQ_APPNAME_LC "_html_browser", nullptr,
        /* Redhat has a nifty htmlview script to start the user's preferred browser */
-       "htmlview",     NULL,
+       "htmlview",     nullptr,
        /* Debian has even better approach with alternatives */
-       "sensible-browser", NULL,
+       "sensible-browser", nullptr,
        /* GNOME 2 */
        "gconftool-2",  "gconftool-2 -g /desktop/gnome/url-handlers/http/command",
        /* KDE */
        "kfmclient",    "!kfmclient exec \"%s\"",
        /* use fallbacks */
-       "firefox",      NULL,
-       "mozilla",      NULL,
-       "konqueror",    NULL,
-       "netscape",     NULL,
+       "firefox",      nullptr,
+       "mozilla",      nullptr,
+       "konqueror",    nullptr,
+       "netscape",     nullptr,
        "opera",        "!opera --remote 'openURL(%s,new-page)'",
-       NULL,           NULL
+       nullptr,                nullptr
 };
 
 static void help_browser_run(const gchar *path)
 {
-       gchar *name = options->helpers.html_browser.command_name;
-       gchar *cmd = options->helpers.html_browser.command_line;
-       gchar *result = NULL;
+       const gchar *name = options->helpers.html_browser.command_name;
+       const gchar *cmd = options->helpers.html_browser.command_line;
+       gchar *result = nullptr;
        gint i;
 
        i = 0;
@@ -210,7 +213,7 @@ static void help_browser_run(const gchar *path)
 
                                if (ret == 0) break;
                                g_free(result);
-                               result = NULL;
+                               result = nullptr;
                        }
                }
                if (!html_browsers[i]) break;
@@ -233,18 +236,18 @@ static void help_browser_run(const gchar *path)
  *-----------------------------------------------------------------------------
  */
 
-static GtkWidget *help_window = NULL;
+static GtkWidget *help_window = nullptr;
 
-static void help_window_destroy_cb(GtkWidget *UNUSED(window), gpointer UNUSED(data))
+static void help_window_destroy_cb(GtkWidget *, gpointer)
 {
-       help_window = NULL;
+       help_window = nullptr;
 }
 
 void help_window_show(const gchar *key)
 {
        gchar *path;
 
-       if (key && strstr(key, ".html") != 0)
+       if (key && strstr(key, ".html") != nullptr)
                {
                path = g_build_filename(gq_htmldir, key, NULL);
                if (!isfile(path))
@@ -321,30 +324,28 @@ void help_window_show(const gchar *key)
  *-----------------------------------------------------------------------------
  */
 
-typedef struct _HelpSearchData HelpSearchData;
-struct _HelpSearchData {
+struct HelpSearchData {
        GenericDialog *gd;
        GtkWidget *edit_widget;
        gchar *text_entry;
 };
 
-static void help_search_window_show_icon_press(GtkEntry *UNUSED(entry), GtkEntryIconPosition UNUSED(pos),
-                                                                       GdkEvent *UNUSED(event), gpointer userdata)
+static void help_search_window_show_icon_press(GtkEntry *, GtkEntryIconPosition, GdkEvent *, gpointer userdata)
 {
-       HelpSearchData *hsd = static_cast<HelpSearchData *>(userdata);
+       auto hsd = static_cast<HelpSearchData *>(userdata);
 
        g_free(hsd->text_entry);
        hsd->text_entry = g_strdup("");
-       gtk_entry_set_text(GTK_ENTRY(hsd->edit_widget), hsd->text_entry);
+       gq_gtk_entry_set_text(GTK_ENTRY(hsd->edit_widget), hsd->text_entry);
 }
 
-static void help_search_window_ok_cb(GenericDialog *UNUSED(gd), gpointer data)
+static void help_search_window_ok_cb(GenericDialog *, gpointer data)
 {
-       HelpSearchData *hsd = static_cast<HelpSearchData *>(data);
+       auto hsd = static_cast<HelpSearchData *>(data);
        gchar *search_command;
 
        search_command = g_strconcat(options->help_search_engine,
-                                               gtk_entry_get_text(GTK_ENTRY(hsd->edit_widget)),
+                                               gq_gtk_entry_get_text(GTK_ENTRY(hsd->edit_widget)),
                                                NULL);
        help_browser_run(search_command);
        g_free(search_command);
@@ -352,28 +353,27 @@ static void help_search_window_ok_cb(GenericDialog *UNUSED(gd), gpointer data)
        g_free(hsd);
 }
 
-static void help_search_window_cancel_cb(GenericDialog *UNUSED(gd), gpointer data)
+static void help_search_window_cancel_cb(GenericDialog *, gpointer data)
 {
-       HelpSearchData *hsd = static_cast<HelpSearchData *>(data);
+       auto hsd = static_cast<HelpSearchData *>(data);
 
        g_free(hsd);
 }
 
 void help_search_window_show()
 {
-       HelpSearchData *hsd;
        GenericDialog *gd;
        GtkWidget *table;
        GtkWidget *label1;
        GtkWidget *label2;
 
-       hsd = g_new0(HelpSearchData, 1);
+       auto hsd = g_new0(HelpSearchData, 1);
        hsd->gd = gd = generic_dialog_new(_("On-line help search"), "help_search",
-                               NULL, TRUE,
+                               nullptr, TRUE,
                                help_search_window_cancel_cb, hsd);
-       generic_dialog_add_message(gd, NULL, _("Search the on-line help files.\n"), NULL, FALSE);
+       generic_dialog_add_message(gd, nullptr, _("Search the on-line help files.\n"), nullptr, FALSE);
 
-       generic_dialog_add_button(gd, GTK_STOCK_OK, NULL,
+       generic_dialog_add_button(gd, GQ_ICON_OK, "OK",
                                  help_search_window_ok_cb, TRUE);
 
        label1 = pref_label_new(GENERIC_DIALOG(gd)->vbox, _("Search engine:"));
@@ -387,15 +387,15 @@ void help_search_window_show()
        pref_spacer(GENERIC_DIALOG(gd)->vbox, 0);
 
        table = pref_table_new(gd->vbox, 3, 1, FALSE, TRUE);
-       pref_table_label(table, 0, 0, _("Search terms:"), 1.0);
+       pref_table_label(table, 0, 0, _("Search terms:"), GTK_ALIGN_END);
        hsd->edit_widget = gtk_entry_new();
        gtk_widget_set_size_request(hsd->edit_widget, 300, -1);
-       gtk_table_attach_defaults(GTK_TABLE(table), hsd->edit_widget, 1, 2, 0, 1);
+       gq_gtk_grid_attach_default(GTK_GRID(table), hsd->edit_widget, 1, 2, 0, 1);
        generic_dialog_attach_default(gd, hsd->edit_widget);
        gtk_widget_show(hsd->edit_widget);
 
-       gtk_entry_set_icon_from_stock(GTK_ENTRY(hsd->edit_widget),
-                                               GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CLEAR);
+       gtk_entry_set_icon_from_icon_name(GTK_ENTRY(hsd->edit_widget),
+                                               GTK_ENTRY_ICON_SECONDARY, GQ_ICON_CLEAR);
        gtk_entry_set_icon_tooltip_text (GTK_ENTRY(hsd->edit_widget),
                                                GTK_ENTRY_ICON_SECONDARY, _("Clear"));
        g_signal_connect(GTK_ENTRY(hsd->edit_widget), "icon-press",