Trim trailing white spaces.
[geeqie.git] / src / layout_util.c
index d8b5503..79193b0 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Geeqie
  * (C) 2004 John Ellis
- * Copyright (C) 2008 - 2010 The Geeqie Team
+ * Copyright (C) 2008 - 2012 The Geeqie Team
  *
  * Author: John Ellis
  *
@@ -64,10 +64,10 @@ static void layout_util_sync_views(LayoutWindow *lw);
  */
 
 static guint tree_key_overrides[] = {
-       GDK_Page_Up,    GDK_KP_Page_Up,
-       GDK_Page_Down,  GDK_KP_Page_Down,
-       GDK_Home,       GDK_KP_Home,
-       GDK_End,        GDK_KP_End
+       GDK_KEY_Page_Up,        GDK_KEY_KP_Page_Up,
+       GDK_KEY_Page_Down,      GDK_KEY_KP_Page_Down,
+       GDK_KEY_Home,   GDK_KEY_KP_Home,
+       GDK_KEY_End,    GDK_KEY_KP_End
 };
 
 static gboolean layout_key_match(guint keyval)
@@ -85,17 +85,14 @@ static gboolean layout_key_match(guint keyval)
 gboolean layout_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
 {
        LayoutWindow *lw = data;
+       GtkWidget *focused;
        gboolean stop_signal = FALSE;
        gint x = 0;
        gint y = 0;
 
-#if GTK_CHECK_VERSION(2,20,0)
        if (lw->path_entry && gtk_widget_has_focus(lw->path_entry))
-#else
-       if (lw->path_entry && GTK_WIDGET_HAS_FOCUS(lw->path_entry))
-#endif
                {
-               if (event->keyval == GDK_Escape && lw->dir_fd)
+               if (event->keyval == GDK_KEY_Escape && lw->dir_fd)
                        {
                        gtk_entry_set_text(GTK_ENTRY(lw->path_entry), lw->dir_fd->path);
                        }
@@ -108,11 +105,7 @@ gboolean layout_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer dat
                        return TRUE;
                        }
                }
-#if GTK_CHECK_VERSION(2,20,0)
        if (lw->vd && lw->options.dir_view_type == DIRVIEW_TREE && gtk_widget_has_focus(lw->vd->view) &&
-#else
-       if (lw->vd && lw->options.dir_view_type == DIRVIEW_TREE && GTK_WIDGET_HAS_FOCUS(lw->vd->view) &&
-#endif
            !layout_key_match(event->keyval) &&
            gtk_widget_event(lw->vd->view, (GdkEvent *)event))
                {
@@ -124,32 +117,23 @@ gboolean layout_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer dat
                return TRUE;
                }
 
-/*
-       if (event->type == GDK_KEY_PRESS && lw->full_screen &&
-           gtk_accel_groups_activate(G_OBJECT(lw->window), event->keyval, event->state))
-               return TRUE;
-*/
-
+       focused = gtk_container_get_focus_child(GTK_CONTAINER(lw->image->widget));
        if (lw->image &&
-#if GTK_CHECK_VERSION(2,20,0)
-           (gtk_widget_has_focus(lw->image->widget) || (lw->tools && widget == lw->window) || lw->full_screen) )
-#else
-           (GTK_WIDGET_HAS_FOCUS(lw->image->widget) || (lw->tools && widget == lw->window) || lw->full_screen) )
-#endif
+           ((focused && gtk_widget_has_focus(focused)) || (lw->tools && widget == lw->window) || lw->full_screen) )
                {
                stop_signal = TRUE;
                switch (event->keyval)
                        {
-                       case GDK_Left: case GDK_KP_Left:
+                       case GDK_KEY_Left: case GDK_KEY_KP_Left:
                                x -= 1;
                                break;
-                       case GDK_Right: case GDK_KP_Right:
+                       case GDK_KEY_Right: case GDK_KEY_KP_Right:
                                x += 1;
                                break;
-                       case GDK_Up: case GDK_KP_Up:
+                       case GDK_KEY_Up: case GDK_KEY_KP_Up:
                                y -= 1;
                                break;
-                       case GDK_Down: case GDK_KP_Down:
+                       case GDK_KEY_Down: case GDK_KEY_KP_Down:
                                y += 1;
                                break;
                        default:
@@ -163,7 +147,7 @@ gboolean layout_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer dat
                        stop_signal = TRUE;
                        switch (event->keyval)
                                {
-                               case GDK_Menu:
+                               case GDK_KEY_Menu:
                                        layout_image_menu_popup(lw);
                                        break;
                                default:
@@ -654,11 +638,6 @@ static void layout_menu_escape_cb(GtkAction *action, gpointer data)
        LayoutWindow *lw = data;
 
        layout_exit_fullscreen(lw);
-
-       /* FIXME:interrupting thumbs no longer allowed */
-#if 0
-       interrupt_thumbs();
-#endif
 }
 
 static void layout_menu_overlay_toggle_cb(GtkAction *action, gpointer data)
@@ -836,23 +815,32 @@ static void layout_menu_slideshow_pause_cb(GtkAction *action, gpointer data)
        layout_image_slideshow_pause_toggle(lw);
 }
 
-static void layout_menu_stereo_swap_cb(GtkAction *action, gpointer data)
+
+static void layout_menu_stereo_mode_next_cb(GtkAction *action, gpointer data)
 {
        LayoutWindow *lw = data;
+       gint mode = layout_image_stereo_pixbuf_get(lw);
+       
+       /* 0->1, 1->2, 2->3, 3->1 - disable auto, then cycle */
+       mode = mode % 3 + 1;
+       
+       GtkAction *radio = gtk_action_group_get_action(lw->action_group, "StereoAuto");
+       gtk_radio_action_set_current_value(GTK_RADIO_ACTION(radio), mode);
+       
+       /*
+       this is called via fallback in layout_menu_stereo_mode_cb
+       layout_image_stereo_pixbuf_set(lw, mode);
+       */
 
-       layout_image_stereo_swap(lw);
 }
 
 static void layout_menu_stereo_mode_cb(GtkRadioAction *action, GtkRadioAction *current, gpointer data)
 {
        LayoutWindow *lw = data;
        gint mode = gtk_radio_action_get_current_value(action);
-       layout_image_stereo_set(lw, (layout_image_stereo_get(lw) & ~(PR_STEREO_ANAGLYPH | PR_STEREO_HORIZ | PR_STEREO_VERT)) | mode);
+       layout_image_stereo_pixbuf_set(lw, mode);
 }
 
-
-
-
 static void layout_menu_help_cb(GtkAction *action, gpointer data)
 {
        LayoutWindow *lw = data;
@@ -1055,7 +1043,7 @@ static void layout_menu_back_cb(GtkAction *action, gpointer data)
        if (!path) return;
        
        /* Open previous path */
-       dir_fd = file_data_new_simple(path);
+       dir_fd = file_data_new_dir(path);
        layout_set_fd(lw, dir_fd);
        file_data_unref(dir_fd);
 }
@@ -1072,7 +1060,7 @@ static void layout_menu_home_cb(GtkAction *action, gpointer data)
 
        if (path)
                {
-               FileData *dir_fd = file_data_new_simple(path);
+               FileData *dir_fd = file_data_new_dir(path);
                layout_set_fd(lw, dir_fd);
                file_data_unref(dir_fd);
                }
@@ -1373,6 +1361,7 @@ static GtkActionEntry menu_entries[] = {
   { "About",           GTK_STOCK_ABOUT,        N_("_About"),                           NULL,                   N_("About"),                            CB(layout_menu_about_cb) },
   { "LogWindow",       NULL,                   N_("_Log Window"),                      NULL,                   N_("Log Window"),                       CB(layout_menu_log_window_cb) },
   { "ExifWin",         NULL,                   N_("_Exif window"),                     "<control>E",           N_("Exif window"),                      CB(layout_menu_bar_exif_cb) },
+  { "StereoCycle",     NULL,                   N_("_Cycle through stereo modes"),      NULL,                   N_("Cycle through stereo modes"),       CB(layout_menu_stereo_mode_next_cb) },
 
 };
 
@@ -1390,7 +1379,6 @@ static GtkToggleActionEntry menu_toggle_entries[] = {
   { "Grayscale",       NULL,                   N_("Toggle _grayscale"),                "<shift>G",             N_("Toggle grayscale"),                 CB(layout_menu_alter_desaturate_cb), FALSE},
   { "ImageOverlay",    NULL,                   N_("Image _Overlay"),                   NULL,                   N_("Image Overlay"),                    CB(layout_menu_overlay_cb),      FALSE },
   { "ImageHistogram",  NULL,                   N_("_Show Histogram"),                  NULL,                   N_("Show Histogram"),                   CB(layout_menu_histogram_cb),    FALSE },
-  { "StereoSwap",      NULL,                   N_("Swap stereo images"),               NULL,                   N_("Swap stereo images"),               CB(layout_menu_stereo_swap_cb),  FALSE },
 };
 
 static GtkRadioActionEntry menu_radio_entries[] = {
@@ -1433,10 +1421,10 @@ static GtkRadioActionEntry menu_histogram_mode[] = {
 };
 
 static GtkRadioActionEntry menu_stereo_mode_entries[] = {
-  { "StereoNone",      NULL,                   N_("_None"),                            NULL,                   N_("Stereo Off"),               PR_STEREO_NONE },
-  { "StereoAnaglyph",  NULL,                   N_("_Anaglyph"),                        NULL,                   N_("Stereo Anaglyph"),          PR_STEREO_ANAGLYPH },
-  { "StereoHoriz",     NULL,                   N_("_Side by Side"),                    NULL,                   N_("Stereo Side by Side"),      PR_STEREO_HORIZ },
-  { "StereoVert",      NULL,                   N_("Above-_Below"),                     NULL,                   N_("Stereo Above-Below"),       PR_STEREO_VERT }
+  { "StereoAuto",      NULL,                   N_("_Auto"),                            NULL,                   N_("Stereo Auto"),              STEREO_PIXBUF_DEFAULT },
+  { "StereoSBS",       NULL,                   N_("_Side by Side"),                    NULL,                   N_("Stereo Side by Side"),      STEREO_PIXBUF_SBS },
+  { "StereoCross",     NULL,                   N_("_Cross"),                           NULL,                   N_("Stereo Cross"),             STEREO_PIXBUF_CROSS },
+  { "StereoOff",       NULL,                   N_("_Off"),                             NULL,                   N_("Stereo Off"),               STEREO_PIXBUF_NONE }
 };
 
 
@@ -1578,12 +1566,12 @@ static const gchar *menu_ui_description =
 "        <menuitem action='SplitSingle'/>"
 "      </menu>"
 "      <menu action='StereoMenu'>"
-"        <menuitem action='StereoSwap'/>"
+"        <menuitem action='StereoAuto'/>"
+"        <menuitem action='StereoSBS'/>"
+"        <menuitem action='StereoCross'/>"
+"        <menuitem action='StereoOff'/>"
 "        <separator/>"
-"        <menuitem action='StereoNone'/>"
-"        <menuitem action='StereoAnaglyph'/>"
-"        <menuitem action='StereoHoriz'/>"
-"        <menuitem action='StereoVert'/>"
+"        <menuitem action='StereoCycle'/>"
 "      </menu>"
 "      <menu action='ColorMenu'>"
 "        <menuitem action='UseColorProfiles'/>"
@@ -1766,7 +1754,7 @@ static GList *layout_actions_editor_menu_path(EditorDescription *editor)
        gint i = 0;
        GList *ret = NULL;
        
-       if (split[0] == NULL) 
+       if (split[0] == NULL)
                {
                g_strfreev(split);
                return NULL;
@@ -1876,10 +1864,10 @@ static void layout_actions_setup_editors(LayoutWindow *lw)
                {
                GList *path;
                EditorDescription *editor = work->data;
-               GtkActionEntry entry = { editor->key, 
+               GtkActionEntry entry = { editor->key,
                                         NULL,
                                         editor->name,
-                                        editor->hotkey, 
+                                        editor->hotkey,
                                         editor->comment ? editor->comment : editor->name,
                                         G_CALLBACK(layout_menu_edit_cb) };
                
@@ -2030,8 +2018,6 @@ static gboolean layout_editors_reload_idle_cb(gpointer data)
 
 void layout_editors_reload_start(void)
 {
-       GList *work;
-
        DEBUG_1("%s layout_editors_reload_start", get_exec_time());
 
        if (layout_editors_reload_idle_id != -1)
@@ -2040,8 +2026,6 @@ void layout_editors_reload_start(void)
                string_list_free(layout_editors_desktop_files);
                }
 
-       work = layout_window_list;
-
        editor_table_clear();
        layout_editors_reload_idle_id = g_idle_add(layout_editors_reload_idle_cb, NULL);
 }
@@ -2102,7 +2086,7 @@ GtkWidget *layout_actions_toolbar(LayoutWindow *lw, ToolbarType type)
 
 void layout_toolbar_clear(LayoutWindow *lw, ToolbarType type)
 {
-       if (lw->toolbar_merge_id[type]) 
+       if (lw->toolbar_merge_id[type])
                {
                gtk_ui_manager_remove_ui(lw->ui_manager, lw->toolbar_merge_id[type]);
                gtk_ui_manager_ensure_update(lw->ui_manager);
@@ -2146,17 +2130,17 @@ void layout_toolbar_add(LayoutWindow *lw, ToolbarType type, const gchar *action)
                        }
                if (!gtk_action_group_get_action(lw->action_group_editors, action))
                        {
-                       GtkActionEntry entry = { action, 
+                       GtkActionEntry entry = { action,
                                                 GTK_STOCK_MISSING_IMAGE,
                                                 action,
-                                                NULL, 
+                                                NULL,
                                                 NULL,
                                                 NULL };
                        DEBUG_1("Creating temporary action %s", action);
                        gtk_action_group_add_actions(lw->action_group_editors, &entry, 1, lw);
                        }
                }
-       gtk_ui_manager_add_ui(lw->ui_manager, lw->toolbar_merge_id[type], path, action, action, GTK_UI_MANAGER_TOOLITEM, FALSE); 
+       gtk_ui_manager_add_ui(lw->ui_manager, lw->toolbar_merge_id[type], path, action, action, GTK_UI_MANAGER_TOOLITEM, FALSE);
        lw->toolbar_actions[type] = g_list_append(lw->toolbar_actions[type], g_strdup(action));
 }
 
@@ -2234,7 +2218,7 @@ void layout_toolbar_add_from_config(LayoutWindow *lw, ToolbarType type, const gc
                }
 
        layout_toolbar_add(lw, type, action);
-       g_free(action); 
+       g_free(action);
 }
 
 /*
@@ -2364,13 +2348,13 @@ static void layout_util_sync_views(LayoutWindow *lw)
        if (!lw->action_group) return;
 
        action = gtk_action_group_get_action(lw->action_group, "FolderTree");
-       radio_action_set_current_value(GTK_RADIO_ACTION(action), lw->options.dir_view_type);
+       gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), lw->options.dir_view_type);
 
        action = gtk_action_group_get_action(lw->action_group, "SplitSingle");
-       radio_action_set_current_value(GTK_RADIO_ACTION(action), lw->split_mode);
+       gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), lw->split_mode);
 
        action = gtk_action_group_get_action(lw->action_group, "ViewIcons");
-       radio_action_set_current_value(GTK_RADIO_ACTION(action), lw->options.file_view_type);
+       gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), lw->options.file_view_type);
 
        action = gtk_action_group_get_action(lw->action_group, "FloatTools");
        gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), lw->options.tools_float);
@@ -2402,15 +2386,18 @@ static void layout_util_sync_views(LayoutWindow *lw)
        if (osd_flags & OSD_SHOW_HISTOGRAM)
                {
                action = gtk_action_group_get_action(lw->action_group, "HistogramChanR");
-               radio_action_set_current_value(GTK_RADIO_ACTION(action), image_osd_histogram_get_channel(lw->image));
+               gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), image_osd_histogram_get_channel(lw->image));
 
                action = gtk_action_group_get_action(lw->action_group, "HistogramModeLin");
-               radio_action_set_current_value(GTK_RADIO_ACTION(action), image_osd_histogram_get_mode(lw->image));
+               gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), image_osd_histogram_get_mode(lw->image));
                }
 
        action = gtk_action_group_get_action(lw->action_group, "ConnectZoomMenu");
        gtk_action_set_sensitive(action, lw->split_mode != SPLIT_NONE);
 
+       action = gtk_action_group_get_action(lw->action_group, "StereoAuto");
+       gtk_radio_action_set_current_value(GTK_RADIO_ACTION(action), layout_image_stereo_pixbuf_get(lw));
+
        layout_util_sync_color(lw);
 }
 
@@ -2442,11 +2429,7 @@ void layout_util_sync(LayoutWindow *lw)
 
 static gboolean layout_bar_enabled(LayoutWindow *lw)
 {
-#if GTK_CHECK_VERSION(2,20,0)
        return lw->bar && gtk_widget_get_visible(lw->bar);
-#else
-       return lw->bar && GTK_WIDGET_VISIBLE(lw->bar);
-#endif
 }
 
 static void layout_bar_destroyed(GtkWidget *widget, gpointer data)
@@ -2454,7 +2437,7 @@ static void layout_bar_destroyed(GtkWidget *widget, gpointer data)
        LayoutWindow *lw = data;
 
        lw->bar = NULL;
-/* 
+/*
     do not call layout_util_sync_views(lw) here
     this is called either when whole layout is destroyed - no need for update
     or when the bar is replaced - sync is called by upper function at the end of whole operation
@@ -2499,7 +2482,7 @@ void layout_bar_set(LayoutWindow *lw, GtkWidget *bar)
 
 
 //     gtk_box_pack_start(GTK_BOX(lw->utility_box), lw->bar, FALSE, FALSE, 0);
-       gtk_paned_pack2(GTK_PANED(lw->utility_paned), lw->bar, FALSE, TRUE); 
+       gtk_paned_pack2(GTK_PANED(lw->utility_paned), lw->bar, FALSE, TRUE);
 
        bar_set_fd(lw->bar, layout_image_get_fd(lw));
 }
@@ -2539,11 +2522,7 @@ static void layout_bar_new_selection(LayoutWindow *lw, gint count)
 
 static gboolean layout_bar_sort_enabled(LayoutWindow *lw)
 {
-#if GTK_CHECK_VERSION(2,20,0)
        return lw->bar_sort && gtk_widget_get_visible(lw->bar_sort);
-#else
-       return lw->bar_sort && GTK_WIDGET_VISIBLE(lw->bar_sort);
-#endif
 }
 
 
@@ -2553,7 +2532,7 @@ static void layout_bar_sort_destroyed(GtkWidget *widget, gpointer data)
 
        lw->bar_sort = NULL;
 
-/* 
+/*
     do not call layout_util_sync_views(lw) here
     this is called either when whole layout is destroyed - no need for update
     or when the bar is replaced - sync is called by upper function at the end of whole operation
@@ -2636,7 +2615,7 @@ GtkWidget *layout_bars_prepare(LayoutWindow *lw, GtkWidget *image)
        lw->utility_paned = gtk_hpaned_new();
        gtk_box_pack_start(GTK_BOX(lw->utility_box), lw->utility_paned, TRUE, TRUE, 0);
 
-       gtk_paned_pack1(GTK_PANED(lw->utility_paned), image, TRUE, FALSE); 
+       gtk_paned_pack1(GTK_PANED(lw->utility_paned), image, TRUE, FALSE);
        gtk_widget_show(lw->utility_paned);
        
        gtk_widget_show(image);
@@ -2659,7 +2638,7 @@ static void layout_exif_window_destroy(GtkWidget *widget, gpointer data)
 
 void layout_exif_window_new(LayoutWindow *lw)
 {
-       if (lw->exif_window) return; 
+       if (lw->exif_window) return;
        
        lw->exif_window = advanced_exif_new();
        if (!lw->exif_window) return;