/*
- * (SLIK) SimpLIstic sKin functions
- * (C) 2004 John Ellis
- * Copyright (C) 2008 - 2012 The Geeqie Team
+ * Copyright (C) 2004 John Ellis
+ * Copyright (C) 2008 - 2016 The Geeqie Team
*
* Author: John Ellis
*
- * This software is released under the GNU General Public License (GNU GPL).
- * Please read the included file COPYING for more information.
- * This software comes with no warranty of any kind, use at your own risk!
+ * 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifdef HAVE_CONFIG_H
#include "ui_utildlg.h"
#include "filedata.h"
+#include "rcfile.h"
#include "ui_fileops.h"
#include "ui_misc.h"
#include "ui_pathsel.h"
*-----------------------------------------------------------------------------
*/
+typedef struct _DialogWindow DialogWindow;
+struct _DialogWindow
+{
+ gint x;
+ gint y;
+ gint w;
+ gint h;
+ gchar *title;
+ gchar *role;
+};
+
+static GList *dialog_windows = NULL;
+
+static void generic_dialog_save_window(const gchar *title, const gchar *role, gint x, gint y, gint h, gint w)
+{
+ GList *work;
+
+ work = g_list_first(dialog_windows);
+ while (work)
+ {
+ DialogWindow *dw = work->data;
+ if (g_strcmp0(dw->title ,title) == 0 && g_strcmp0(dw->role, role) == 0)
+ {
+ dw->x = x;
+ dw->y = y;
+ dw->w = w;
+ dw->h = h;
+ return;
+ }
+ work = work->next;
+ }
+
+ DialogWindow *dw = g_new0(DialogWindow, 1);
+ dw->title = g_strdup(title);
+ dw->role = g_strdup(role);
+ dw->x = x;
+ dw->y = y;
+ dw->w = w;
+ dw->h = h;
+
+ dialog_windows = g_list_append(dialog_windows, dw);
+}
+
+static gboolean generic_dialog_find_window(const gchar *title, const gchar *role, gint *x, gint *y, gint *h, gint *w)
+{
+ GList *work;
+
+ work = g_list_first(dialog_windows);
+ while (work)
+ {
+ DialogWindow *dw = work->data;
+
+ if (g_strcmp0(dw->title,title) == 0 && g_strcmp0(dw->role, role) == 0)
+ {
+ *x = dw->x;
+ *y = dw->y;
+ *w = dw->w;
+ *h = dw->h;
+ return TRUE;
+ }
+ work = work->next;
+ }
+ return FALSE;
+}
+
void generic_dialog_close(GenericDialog *gd)
{
+ gchar *ident_string;
+ gchar *full_title;
+ gchar *actual_title;
+ gint x, y, h, w;
+
+ gdk_window_get_root_origin(gtk_widget_get_window (gd->dialog), &x, &y);
+ w = gdk_window_get_width(gtk_widget_get_window (gd->dialog));
+ h = gdk_window_get_height(gtk_widget_get_window (gd->dialog));
+
+ /* The window title is modified in window.c: window_new()
+ * by appending the string " - Geeqie"
+ */
+ ident_string = g_strconcat(" - ", GQ_APPNAME, NULL);
+ full_title = g_strdup(gtk_window_get_title(GTK_WINDOW(gd->dialog)));
+ actual_title = strndup(full_title, g_strrstr(full_title, ident_string) - full_title);
+
+ generic_dialog_save_window(actual_title, gtk_window_get_role(GTK_WINDOW(gd->dialog)), x, y, w, h);
+
gtk_widget_destroy(gd->dialog);
g_free(gd);
+ g_free(ident_string);
+ g_free(full_title);
+ g_free(actual_title);
}
static void generic_dialog_click_cb(GtkWidget *widget, gpointer data)
{
GenericDialog *gd = data;
-#if GTK_CHECK_VERSION(2,20,0)
- if (event->keyval == GDK_Return && gtk_widget_has_focus(widget)
-#else
- if (event->keyval == GDK_Return && GTK_WIDGET_HAS_FOCUS(widget)
-#endif
+ if (event->keyval == GDK_KEY_Return && gtk_widget_has_focus(widget)
&& gd->default_cb)
{
gboolean auto_close;
static gboolean generic_dialog_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
{
GenericDialog *gd = data;
+ gboolean auto_close = gd->auto_close;
- if (event->keyval == GDK_Escape)
+ if (event->keyval == GDK_KEY_Escape)
{
- if (gd->cancel_cb) gd->cancel_cb(gd, gd->data);
- if (gd->auto_close) generic_dialog_click_cb(widget, data);
+ if (gd->cancel_cb)
+ {
+ gd->cancel_cb(gd, gd->data);
+ if (auto_close) generic_dialog_close(gd);
+ }
+ else
+ {
+ if (auto_close) generic_dialog_click_cb(widget, data);
+ }
return TRUE;
}
return FALSE;
return button;
}
+/**
+ * @brief
+ * @param gd
+ * @param icon_stock_id
+ * @param heading
+ * @param text
+ * @param expand Used as the "expand" and "fill" parameters in the eventual call to gtk_box_pack_start()
+ * @returns
+ *
+ *
+ */
GtkWidget *generic_dialog_add_message(GenericDialog *gd, const gchar *icon_stock_id,
- const gchar *heading, const gchar *text)
+ const gchar *heading, const gchar *text, gboolean expand)
{
GtkWidget *hbox;
GtkWidget *vbox;
GtkWidget *label;
- hbox = pref_box_new(gd->vbox, TRUE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE);
+ hbox = pref_box_new(gd->vbox, expand, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE);
if (icon_stock_id)
{
GtkWidget *image;
image = gtk_image_new_from_stock(icon_stock_id, GTK_ICON_SIZE_DIALOG);
+#if GTK_CHECK_VERSION(3,16,0)
+ gtk_widget_set_halign(GTK_WIDGET(image), GTK_ALIGN_CENTER);
+ gtk_widget_set_valign(GTK_WIDGET(image), GTK_ALIGN_START);
+#else
gtk_misc_set_alignment(GTK_MISC(image), 0.5, 0.0);
+#endif
gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0);
gtk_widget_show(image);
}
{
label = pref_label_new(vbox, heading);
pref_label_bold(label, TRUE, TRUE);
+#if GTK_CHECK_VERSION(3,16,0)
+ gtk_label_set_xalign(GTK_LABEL(label), 0.0);
+ gtk_label_set_yalign(GTK_LABEL(label), 0.5);
+#else
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
+#endif
}
if (text)
{
label = pref_label_new(vbox, text);
+#if GTK_CHECK_VERSION(3,16,0)
+ gtk_label_set_xalign(GTK_LABEL(label), 0.0);
+ gtk_label_set_yalign(GTK_LABEL(label), 0.5);
+#else
gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
+#endif
gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
}
return vbox;
}
+void generic_dialog_windows_load_config(const gchar **attribute_names, const gchar **attribute_values)
+{
+ DialogWindow *dw = g_new0(DialogWindow, 1);
+ gchar *title = NULL;
+ gchar *role = NULL;
+ gint x = 0;
+ gint y = 0;
+ gint w = 0;
+ gint h = 0;
+
+ while (*attribute_names)
+ {
+ const gchar *option = *attribute_names++;
+ const gchar *value = *attribute_values++;
+ if (READ_CHAR_FULL("title", title)) continue;
+ if (READ_CHAR_FULL("role", role)) continue;
+ if (READ_INT_FULL("x", x)) continue;
+ if (READ_INT_FULL("y", y)) continue;
+ if (READ_INT_FULL("w", w)) continue;
+ if (READ_INT_FULL("h", h)) continue;
+
+ log_printf("unknown attribute %s = %s\n", option, value);
+ }
+
+ if (title && title[0] != 0)
+ {
+ dw->title = g_strdup(title);
+ dw->role = g_strdup(role);
+ dw->x = x;
+ dw->y = y;
+ dw->w = w;
+ dw->h = h;
+
+ dialog_windows = g_list_append(dialog_windows, dw);
+ }
+}
+
+void generic_dialog_windows_write_config(GString *outstr, gint indent)
+{
+ GList *work;
+
+ if (options->save_dialog_window_positions && dialog_windows)
+ {
+ WRITE_NL(); WRITE_STRING("<%s>", "dialogs");
+ indent++;
+
+ work = g_list_first(dialog_windows);
+ while (work)
+ {
+ DialogWindow *dw = work->data;
+ WRITE_NL(); WRITE_STRING("<window ");
+ write_char_option(outstr, indent + 1, "title", dw->title);
+ write_char_option(outstr, indent + 1, "role", dw->role);
+ WRITE_INT(*dw, x);
+ WRITE_INT(*dw, y);
+ WRITE_INT(*dw, w);
+ WRITE_INT(*dw, h);
+ WRITE_STRING("/>");
+ work = work->next;
+ }
+ indent--;
+ WRITE_NL(); WRITE_STRING("</%s>", "dialogs");
+
+ dialog_windows = NULL;
+ }
+}
+
static void generic_dialog_setup(GenericDialog *gd,
const gchar *title,
const gchar *role,
void (*cancel_cb)(GenericDialog *, gpointer), gpointer data)
{
GtkWidget *vbox;
+ gint x, y, w, h;
+ GtkWidget *scrolled;
gd->auto_close = auto_close;
gd->data = data;
gd->cancel_cb = cancel_cb;
gd->dialog = window_new(GTK_WINDOW_TOPLEVEL, role, NULL, NULL, title);
+ DEBUG_NAME(gd->dialog);
gtk_window_set_type_hint(GTK_WINDOW(gd->dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
+ if (options->save_dialog_window_positions)
+ {
+ if (generic_dialog_find_window(title, role, &x, &y, &w, &h))
+ {
+ gtk_window_set_default_size(GTK_WINDOW(gd->dialog), w, h);
+ gtk_window_move(GTK_WINDOW(gd->dialog), x, y);
+ }
+ }
+
if (parent)
{
GtkWindow *window = NULL;
GtkWidget *top;
top = gtk_widget_get_toplevel(parent);
-#if GTK_CHECK_VERSION(2,20,0)
if (GTK_IS_WINDOW(top) && gtk_widget_is_toplevel(top)) window = GTK_WINDOW(top);
-#else
- if (GTK_IS_WINDOW(top) && GTK_WIDGET_TOPLEVEL(top)) window = GTK_WINDOW(top);
-#endif
}
if (window) gtk_window_set_transient_for(GTK_WINDOW(gd->dialog), window);
gtk_window_set_resizable(GTK_WINDOW(gd->dialog), TRUE);
gtk_container_set_border_width(GTK_CONTAINER(gd->dialog), PREF_PAD_BORDER);
+ scrolled = gtk_scrolled_window_new(NULL, NULL);
+ gtk_scrolled_window_set_propagate_natural_height(GTK_SCROLLED_WINDOW(scrolled), TRUE);
+ gtk_scrolled_window_set_propagate_natural_width(GTK_SCROLLED_WINDOW(scrolled), TRUE);
vbox = gtk_vbox_new(FALSE, PREF_PAD_BUTTON_SPACE);
- gtk_container_add(GTK_CONTAINER(gd->dialog), vbox);
+ gtk_container_add(GTK_CONTAINER(scrolled), vbox);
+ gtk_container_add(GTK_CONTAINER(gd->dialog), scrolled);
+ gtk_widget_show(scrolled);
gtk_widget_show(vbox);
gd->vbox = gtk_vbox_new(FALSE, PREF_PAD_GAP);
gd = generic_dialog_new(heading, "warning", parent, TRUE, NULL, NULL);
generic_dialog_add_button(gd, GTK_STOCK_OK, NULL, warning_dialog_ok_cb, TRUE);
- generic_dialog_add_message(gd, icon_stock_id, heading, text);
+ generic_dialog_add_message(gd, icon_stock_id, heading, text, TRUE);
gtk_widget_show(gd->dialog);