summaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@src.gnome.org>2000-06-09 07:26:37 +0000
committerFederico Mena Quintero <federico@src.gnome.org>2000-06-09 07:26:37 +0000
commitea69b2d27c28a722dbce4de7a385b154d992277b (patch)
tree3b0a402f4d5adaf1306cbe68a45c8b3a0acd3d01 /shell
parent0d4de7a9071e74dd90683c41d3d726c65d450b89 (diff)
downloadeog-ea69b2d27c28a722dbce4de7a385b154d992277b.tar.gz
I forgot to commit this a loooooong time ago - Federico
Diffstat (limited to 'shell')
-rw-r--r--shell/preferences-dialog.glade32
-rw-r--r--shell/preferences.c354
-rw-r--r--shell/preferences.h3
3 files changed, 371 insertions, 18 deletions
diff --git a/shell/preferences-dialog.glade b/shell/preferences-dialog.glade
index 31c84c4d..93e71c7a 100644
--- a/shell/preferences-dialog.glade
+++ b/shell/preferences-dialog.glade
@@ -27,7 +27,7 @@
<widget>
<class>GnomePropertyBox</class>
- <name>PreferencesDialog</name>
+ <name>preferences-dialog</name>
<cxx_use_heap>True</cxx_use_heap>
<widget>
@@ -155,7 +155,7 @@
<widget>
<class>GtkOptionMenu</class>
- <name>TransparencyType</name>
+ <name>transparency-type</name>
<cxx_use_heap>True</cxx_use_heap>
<can_focus>True</can_focus>
<items>Dark checks
@@ -184,7 +184,7 @@ White only
<widget>
<class>GtkOptionMenu</class>
- <name>CheckSize</name>
+ <name>check-size</name>
<cxx_use_heap>True</cxx_use_heap>
<can_focus>True</can_focus>
<items>Small
@@ -210,7 +210,7 @@ Large
<widget>
<class>GtkOptionMenu</class>
- <name>InterpolationType</name>
+ <name>interpolation-type</name>
<cxx_use_heap>True</cxx_use_heap>
<can_focus>True</can_focus>
<items>Nearest neighbor
@@ -236,7 +236,7 @@ Hyperbolic
<widget>
<class>GtkCheckButton</class>
- <name>TwoPassScrolling</name>
+ <name>two-pass-scrolling</name>
<cxx_use_heap>True</cxx_use_heap>
<can_focus>True</can_focus>
<label>Two-pass scrolling</label>
@@ -287,7 +287,7 @@ Hyperbolic
<widget>
<class>GtkOptionMenu</class>
- <name>DitherType</name>
+ <name>dither-type</name>
<cxx_use_heap>True</cxx_use_heap>
<can_focus>True</can_focus>
<items>None
@@ -388,7 +388,7 @@ Maximum (high color)
<widget>
<class>GtkOptionMenu</class>
- <name>WindowScrollbars</name>
+ <name>window-scrollbars</name>
<cxx_use_heap>True</cxx_use_heap>
<can_focus>True</can_focus>
<items>Never
@@ -406,7 +406,7 @@ Only if image does not fit
<widget>
<class>GtkCheckButton</class>
- <name>WindowAutoSize</name>
+ <name>window-auto-size</name>
<cxx_use_heap>True</cxx_use_heap>
<can_focus>True</can_focus>
<label>Pick window size and zoom factor automatically</label>
@@ -421,7 +421,7 @@ Only if image does not fit
<widget>
<class>GtkCheckButton</class>
- <name>OpenNewWindow</name>
+ <name>open-new-window</name>
<cxx_use_heap>True</cxx_use_heap>
<can_focus>True</can_focus>
<label>Open images in a new window</label>
@@ -489,7 +489,7 @@ Only if image does not fit
<widget>
<class>GtkOptionMenu</class>
- <name>FullScreenScrollbars</name>
+ <name>full-screen-scrollbars</name>
<cxx_use_heap>True</cxx_use_heap>
<can_focus>True</can_focus>
<items>Never
@@ -507,13 +507,13 @@ Only if image does not fit
<widget>
<class>GtkRadioButton</class>
- <name>radiobutton1</name>
+ <name>full-screen-zoom-radio</name>
<cxx_use_heap>True</cxx_use_heap>
<can_focus>True</can_focus>
<label>Use 1:1 zoom factor</label>
<active>False</active>
<draw_indicator>True</draw_indicator>
- <group>FullScreenZoom</group>
+ <group>full-screen-zoom</group>
<child>
<padding>0</padding>
<expand>False</expand>
@@ -529,7 +529,7 @@ Only if image does not fit
<label>Use same zoom factor as image window</label>
<active>False</active>
<draw_indicator>True</draw_indicator>
- <group>FullScreenZoom</group>
+ <group>full-screen-zoom</group>
<child>
<padding>0</padding>
<expand>False</expand>
@@ -545,7 +545,7 @@ Only if image does not fit
<label>Fit all images to screen</label>
<active>False</active>
<draw_indicator>True</draw_indicator>
- <group>FullScreenZoom</group>
+ <group>full-screen-zoom</group>
<child>
<padding>0</padding>
<expand>False</expand>
@@ -566,7 +566,7 @@ Only if image does not fit
<widget>
<class>GtkCheckButton</class>
- <name>FullScreenFitStandard</name>
+ <name>full-screen-fit-standard</name>
<cxx_use_heap>True</cxx_use_heap>
<can_focus>True</can_focus>
<label>Fit standard-sized images to screen</label>
@@ -581,7 +581,7 @@ Only if image does not fit
<widget>
<class>GtkCheckButton</class>
- <name>FullScreenBevel</name>
+ <name>full-screen-bevel</name>
<cxx_use_heap>True</cxx_use_heap>
<can_focus>True</can_focus>
<label>Put a bevel around the edge of the screen</label>
diff --git a/shell/preferences.c b/shell/preferences.c
index 82e38aeb..9db11d6f 100644
--- a/shell/preferences.c
+++ b/shell/preferences.c
@@ -20,8 +20,14 @@
*/
#include <config.h>
-#include <libgnome/gnome-defs.h>
-#include <libgnome/gnome-config.h>
+#include <libgnome/libgnome.h>
+#include <gtk/gtkmenu.h>
+#include <gtk/gtkmenuitem.h>
+#include <gtk/gtkoptionmenu.h>
+#include <gtk/gtkradiobutton.h>
+#include <gtk/gtksignal.h>
+#include <libgnomeui/gnome-propertybox.h>
+#include <glade/glade.h>
#include "preferences.h"
@@ -82,3 +88,347 @@ prefs_init (void)
gnome_config_pop_prefix ();
}
+
+
+
+/* Glade definition and contents of the preferences dialog */
+
+static GladeXML *p_xml;
+
+static GtkWidget *p_dialog;
+static GtkWidget *p_interp_type;
+static GtkWidget *p_check_type;
+static GtkWidget *p_check_size;
+static GtkWidget *p_dither;
+static GtkWidget *p_scroll;
+static GtkWidget *p_window_sb_policy;
+static GtkWidget *p_window_auto_size;
+static GtkWidget *p_open_new_window;
+static GtkWidget *p_full_screen_sb_policy;
+static GtkWidget *p_full_screen_zoom_radio;
+static GSList *p_full_screen_zoom;
+static GtkWidget *p_full_screen_fit_standard;
+static GtkWidget *p_full_screen_bevel;
+
+/* Brings attention to a window by raising it and giving it focus */
+static void
+raise_and_focus (GtkWidget *widget)
+{
+ g_assert (GTK_WIDGET_REALIZED (widget));
+ gdk_window_show (widget->window);
+ gtk_widget_grab_focus (widget);
+}
+
+/* Loads the preferences dialog from the Glade file */
+static gboolean
+load_prefs_dialog (void)
+{
+ p_xml = glade_xml_new (EOG_GLADEDIR "/preferences-dialog.glade", NULL);
+ if (!p_xml) {
+ g_message ("load_prefs_dialog(): Could not load the Glade XML file!");
+ return FALSE;
+ }
+
+ p_dialog = glade_xml_get_widget (p_xml, "preferences-dialog");
+ p_interp_type = glade_xml_get_widget (p_xml, "interpolation-type");
+ p_check_type = glade_xml_get_widget (p_xml, "transparency-type");
+ p_check_size = glade_xml_get_widget (p_xml, "check-size");
+ p_dither = glade_xml_get_widget (p_xml, "dither-type");
+ p_scroll = glade_xml_get_widget (p_xml, "two-pass-scrolling");
+ p_window_sb_policy = glade_xml_get_widget (p_xml, "window-scrollbars");
+ p_window_auto_size = glade_xml_get_widget (p_xml, "window-auto-size");
+ p_open_new_window = glade_xml_get_widget (p_xml, "open-new-window");
+ p_full_screen_sb_policy = glade_xml_get_widget (p_xml, "full-screen-scrollbars");
+ p_full_screen_zoom_radio = glade_xml_get_widget (p_xml, "full-screen-zoom-radio");
+ p_full_screen_fit_standard = glade_xml_get_widget (p_xml, "full-screen-fit-standard");
+ p_full_screen_bevel = glade_xml_get_widget (p_xml, "full-screen-bevel");
+
+ if (!(p_dialog && p_interp_type && p_check_type && p_check_size && p_dither
+ && p_scroll && p_window_sb_policy && p_window_auto_size && p_open_new_window
+ && p_full_screen_sb_policy && p_full_screen_zoom_radio && p_full_screen_fit_standard
+ && p_full_screen_bevel)) {
+ g_message ("load_prefs_dialog(): Could not find all widgets in Glade file!");
+
+ gtk_object_unref (GTK_OBJECT (p_xml));
+ p_xml = NULL;
+
+ if (p_dialog) {
+ gtk_widget_destroy (p_dialog);
+ p_dialog = NULL;
+ }
+
+ return FALSE;
+ }
+
+ p_full_screen_zoom = gtk_radio_button_group (GTK_RADIO_BUTTON (p_full_screen_zoom_radio));
+ g_assert (p_full_screen_zoom != NULL);
+
+ gtk_window_set_title (GTK_WINDOW (p_dialog), _("Preferences"));
+
+ return TRUE;
+}
+
+/* Returns the index of the active item in an option menu. GTK+ sucks for not
+ * providing this already!
+ */
+static int
+option_menu_get_active (GtkOptionMenu *omenu)
+{
+ GtkMenu *menu;
+ GtkMenuItem *item;
+ GList *l;
+ int i;
+
+ menu = GTK_MENU (gtk_option_menu_get_menu (omenu));
+ item = GTK_MENU_ITEM (gtk_menu_get_active (menu));
+
+ l = GTK_MENU_SHELL (menu)->children;
+
+ for (i = 0; l; l = l->next) {
+ if (GTK_MENU_ITEM (l->data) == item)
+ return i;
+
+ i++;
+ }
+
+ return -1;
+}
+
+/* Converts an enumeration value to the appropriate index in an item group. The
+ * enumeration values for the items are provided as a -1-terminated array.
+ */
+static int
+enum_to_index (const int *enum_vals, int enum_val)
+{
+ int i;
+
+ for (i = 0; enum_vals[i] != -1; i++)
+ if (enum_vals[i] == enum_val)
+ return i;
+
+ return -1;
+}
+
+/* Converts an index in an item group to the appropriate enum value. See the
+ * function above.
+ */
+static int
+index_to_enum (const int *enum_vals, int index)
+{
+ int i;
+
+ /* We do this the hard way, i.e. not as a simple array reference, to
+ * check for correctness.
+ */
+
+ for (i = 0; enum_vals[i] != -1; i++)
+ if (i == index)
+ return enum_vals[i];
+
+ return -1;
+}
+
+/* Interpolation types for the index-mapping functions */
+static const int interp_types[] = {
+ GDK_INTERP_NEAREST,
+ GDK_INTERP_BILINEAR,
+ GDK_INTERP_HYPER,
+ -1
+};
+
+/* Check types for the index-mapping functions */
+static const int check_types[] = {
+ CHECK_TYPE_DARK,
+ CHECK_TYPE_MIDTONE,
+ CHECK_TYPE_LIGHT,
+ CHECK_TYPE_BLACK,
+ CHECK_TYPE_GRAY,
+ CHECK_TYPE_WHITE,
+ -1
+};
+
+/* Check sizes for the index-mapping functions */
+static const int check_sizes[] = {
+ CHECK_SIZE_SMALL,
+ CHECK_SIZE_MEDIUM,
+ CHECK_SIZE_LARGE,
+ -1
+};
+
+/* Dither types for the index-mapping functions */
+static const int dither_types[] = {
+ GDK_RGB_DITHER_NONE,
+ GDK_RGB_DITHER_NORMAL,
+ GDK_RGB_DITHER_MAX,
+ -1
+};
+
+/* Scrolling types for the index-mapping functions */
+static const int scroll_types[] = {
+ SCROLL_NORMAL,
+ SCROLL_TWO_PASS,
+ -1
+};
+
+/* Scrollbar policies for the index-mapping functions */
+static const int sb_policies[] = {
+ GTK_POLICY_NEVER,
+ GTK_POLICY_AUTOMATIC,
+ -1
+};
+
+/* Full screen zoom modes for the index-mapping functions */
+static const int full_screen_zooms[] = {
+ FULL_SCREEN_ZOOM_1,
+ FULL_SCREEN_ZOOM_SAME_AS_WINDOW,
+ FULL_SCREEN_ZOOM_FIT,
+ -1
+};
+
+#define omenu_set(omenu, enum_map, enum_val) \
+ gtk_option_menu_set_history (GTK_OPTION_MENU (omenu), enum_to_index ((enum_map), (enum_val)));
+
+#define toggle_set(toggle, val) \
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), (val));
+
+/* Sets the active item in a radio group according to the index-mapping tables */
+static void
+radio_set (GSList *group, const int *enum_vals, int enum_val)
+{
+ int i;
+ GSList *l;
+
+ i = enum_to_index (enum_vals, enum_val);
+ g_return_if_fail (i != -1);
+
+ l = g_slist_nth (group, i);
+ g_return_if_fail (l != NULL);
+
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (l->data), TRUE);
+}
+
+/* Sets the current preferences values to the widgets in the dialog */
+static void
+set_prefs_widgets (void)
+{
+ omenu_set (p_interp_type, interp_types, prefs_interp_type);
+ omenu_set (p_check_type, check_types, prefs_check_type);
+ omenu_set (p_check_size, check_sizes, prefs_check_size);
+ omenu_set (p_dither, dither_types, prefs_dither);
+ toggle_set (p_scroll, (prefs_scroll == SCROLL_NORMAL) ? FALSE : TRUE);
+
+ omenu_set (p_window_sb_policy, sb_policies, prefs_window_sb_policy);
+ toggle_set (p_window_auto_size, prefs_window_auto_size);
+ toggle_set (p_open_new_window, prefs_open_new_window);
+
+ omenu_set (p_full_screen_sb_policy, sb_policies, prefs_full_screen_sb_policy);
+ radio_set (p_full_screen_zoom, full_screen_zooms, prefs_full_screen_zoom);
+ toggle_set (p_full_screen_fit_standard, prefs_full_screen_fit_standard);
+ toggle_set (p_full_screen_bevel, prefs_full_screen_bevel);
+}
+
+/* Callback used to tell the property box that some value changed */
+static void
+activate_cb (GtkWidget *widget, gpointer data)
+{
+ gnome_property_box_changed (GNOME_PROPERTY_BOX (p_dialog));
+}
+
+/* Hooks an option menu's items the property box */
+static void
+omenu_hook (GtkOptionMenu *omenu)
+{
+ GtkMenu *menu;
+ GList *l;
+
+ menu = GTK_MENU (gtk_option_menu_get_menu (omenu));
+
+ for (l = GTK_MENU_SHELL (menu)->children; l; l = l->next)
+ gtk_signal_connect (GTK_OBJECT (l->data), "activate",
+ GTK_SIGNAL_FUNC (activate_cb), NULL);
+}
+
+/* Callback used to tell the property box that some value changed */
+static void
+toggled_cb (GtkToggleButton *toggle, gpointer data)
+{
+ /* For radio buttons, only notify the property box when they are active,
+ * since we'll get called once per item in the radio group. Sigh.
+ */
+ if (!GTK_IS_RADIO_BUTTON (toggle) || toggle->active)
+ gnome_property_box_changed (GNOME_PROPERTY_BOX (p_dialog));
+}
+
+/* Hooks a toggle button to the property box */
+static void
+toggle_hook (GtkToggleButton *toggle)
+{
+ gtk_signal_connect (GTK_OBJECT (toggle), "toggled",
+ GTK_SIGNAL_FUNC (toggled_cb), NULL);
+}
+
+/* Hooks a radio group to the property box */
+static void
+radio_hook (GSList *group)
+{
+ GSList *l;
+
+ for (l = group; l; l = l->next)
+ toggle_hook (GTK_TOGGLE_BUTTON (l->data));
+}
+
+/* Hooks the widgets so that they notify the property box when they change */
+static void
+hook_prefs_widgets (void)
+{
+ omenu_hook (GTK_OPTION_MENU (p_interp_type));
+ omenu_hook (GTK_OPTION_MENU (p_check_type));
+ omenu_hook (GTK_OPTION_MENU (p_check_size));
+ omenu_hook (GTK_OPTION_MENU (p_dither));
+ toggle_hook (GTK_TOGGLE_BUTTON (p_scroll));
+
+ omenu_hook (GTK_OPTION_MENU (p_window_sb_policy));
+ toggle_hook (GTK_TOGGLE_BUTTON (p_window_auto_size));
+ toggle_hook (GTK_TOGGLE_BUTTON (p_open_new_window));
+
+ omenu_hook (GTK_OPTION_MENU (p_full_screen_sb_policy));
+ radio_hook (p_full_screen_zoom);
+ toggle_hook (GTK_TOGGLE_BUTTON (p_full_screen_fit_standard));
+ toggle_hook (GTK_TOGGLE_BUTTON (p_full_screen_bevel));
+}
+
+/**
+ * prefs_dialog:
+ * @void:
+ *
+ * Runs the preferences dialog.
+ **/
+void
+prefs_dialog (void)
+{
+ /* Bring up the dialog if it is already running */
+ if (p_xml) {
+ g_assert (p_dialog != NULL);
+ raise_and_focus (p_dialog);
+ return;
+ }
+
+ g_assert (p_dialog == NULL);
+
+ if (!load_prefs_dialog ())
+ return;
+
+ set_prefs_widgets ();
+ hook_prefs_widgets ();
+
+ /* FIXME: run and get value */
+ gnome_dialog_run (GNOME_DIALOG (p_dialog));
+
+ gtk_object_unref (GTK_OBJECT (p_xml));
+ p_xml = NULL;
+
+#if 0
+ gtk_widget_destroy (p_dialog);
+#endif
+ p_dialog = NULL;
+}
diff --git a/shell/preferences.h b/shell/preferences.h
index 77ace1aa..cc0696ee 100644
--- a/shell/preferences.h
+++ b/shell/preferences.h
@@ -89,9 +89,12 @@ extern gboolean prefs_full_screen_fit_standard;
/* Put a bevel around the edge of the screen */
extern gboolean prefs_full_screen_bevel;
+
void prefs_init (void);
+void prefs_dialog (void);
+
#endif