Trim trailing white spaces.
[geeqie.git] / src / layout.c
index 8eb2ce1..08a8f69 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Geeqie
  * (C) 2006 John Ellis
- * Copyright (C) 2008 - 2009 The Geeqie Team
+ * Copyright (C) 2008 - 2012 The Geeqie Team
  *
  * Author: John Ellis
  *
@@ -284,7 +284,7 @@ static GtkWidget *layout_tool_setup(LayoutWindow *lw)
        gtk_box_pack_start(GTK_BOX(box), tabcomp, FALSE, FALSE, 0);
        gtk_widget_show(tabcomp);
 
-       g_signal_connect(G_OBJECT(lw->path_entry->parent), "changed",
+       g_signal_connect(G_OBJECT(gtk_widget_get_parent(lw->path_entry)), "changed",
                         G_CALLBACK(layout_path_entry_changed_cb), lw);
 
        lw->vd = vd_new(lw->options.dir_view_type, lw->dir_fd);
@@ -332,11 +332,7 @@ static void layout_sort_menu_ascend_cb(GtkWidget *widget, gpointer data)
 static void layout_sort_menu_hide_cb(GtkWidget *widget, gpointer data)
 {
        /* destroy the menu */
-#if GTK_CHECK_VERSION(2,12,0)
        g_object_unref(widget);
-#else
-       gtk_widget_unref(GTK_WIDGET(widget));
-#endif
 }
 
 static void layout_sort_button_press_cb(GtkWidget *widget, gpointer data)
@@ -484,6 +480,7 @@ void layout_status_update_image(LayoutWindow *lw)
        guint64 n;
        
        if (!layout_valid(&lw) || !lw->image) return;
+       if (!lw->info_zoom || !lw->info_details) return; /*called from layout_style_set */
 
        n = layout_list_count(lw, NULL);
        
@@ -686,9 +683,6 @@ static void layout_list_sync_marks(LayoutWindow *lw)
 static void layout_list_scroll_to_subpart(LayoutWindow *lw, const gchar *needle)
 {
        if (!lw) return;
-#if 0
-       if (lw->vf) vf_scroll_to_subpart(lw->vf, needle);
-#endif
 }
 
 GList *layout_list(LayoutWindow *lw)
@@ -851,7 +845,7 @@ gboolean layout_set_path(LayoutWindow *lw, const gchar *path)
 
        if (!path) return FALSE;
        
-       fd = file_data_new_simple(path);
+       fd = file_data_new_group(path);
        ret = layout_set_fd(lw, fd);
        file_data_unref(fd);
        return ret;
@@ -898,7 +892,7 @@ gboolean layout_set_fd(LayoutWindow *lw, FileData *fd)
                                file_data_unregister_real_time_monitor(lw->dir_fd);
                                file_data_unref(lw->dir_fd);
                                }
-                       lw->dir_fd = file_data_new_simple(base);
+                       lw->dir_fd = file_data_new_dir(base);
                        file_data_register_real_time_monitor(lw->dir_fd);
                        g_free(base);
                        }
@@ -1007,7 +1001,7 @@ void layout_sort_set(LayoutWindow *lw, SortType type, gboolean ascend)
        lw->sort_method = type;
        lw->sort_ascend = ascend;
 
-       if (lw->info_sort) gtk_label_set_text(GTK_LABEL(GTK_BIN(lw->info_sort)->child),
+       if (lw->info_sort) gtk_label_set_text(GTK_LABEL(gtk_bin_get_child(GTK_BIN(lw->info_sort))),
                                              sort_type_get_text(type));
        layout_list_sync_sort(lw);
 }
@@ -1024,30 +1018,48 @@ gboolean layout_sort_get(LayoutWindow *lw, SortType *type, gboolean *ascend)
 
 gboolean layout_geometry_get(LayoutWindow *lw, gint *x, gint *y, gint *w, gint *h)
 {
+       GdkWindow *window;
        if (!layout_valid(&lw)) return FALSE;
-
-       gdk_window_get_root_origin(lw->window->window, x, y);
-       gdk_drawable_get_size(lw->window->window, w, h);
+       
+       window = gtk_widget_get_window(lw->window);
+       gdk_window_get_root_origin(window, x, y);
+       *w = gdk_window_get_width(window);
+       *h = gdk_window_get_height(window);
 
        return TRUE;
 }
 
 gboolean layout_geometry_get_dividers(LayoutWindow *lw, gint *h, gint *v)
 {
+       GtkAllocation h_allocation;
+       GtkAllocation v_allocation;
+       
        if (!layout_valid(&lw)) return FALSE;
+       
+       if (lw->h_pane)
+               {
+               GtkWidget *child = gtk_paned_get_child1(GTK_PANED(lw->h_pane));
+               gtk_widget_get_allocation(child, &h_allocation);
+               }
 
-       if (lw->h_pane && GTK_PANED(lw->h_pane)->child1->allocation.x >= 0)
+       if (lw->v_pane)
                {
-               *h = GTK_PANED(lw->h_pane)->child1->allocation.width;
+               GtkWidget *child = gtk_paned_get_child1(GTK_PANED(lw->v_pane));
+               gtk_widget_get_allocation(child, &v_allocation);
+               }
+
+       if (lw->h_pane && h_allocation.x >= 0)
+               {
+               *h = h_allocation.width;
                }
        else if (h != &lw->options.main_window.hdivider_pos)
                {
                *h = lw->options.main_window.hdivider_pos;
                }
 
-       if (lw->v_pane && GTK_PANED(lw->v_pane)->child1->allocation.x >= 0)
+       if (lw->v_pane && v_allocation.x >= 0)
                {
-               *v = GTK_PANED(lw->v_pane)->child1->allocation.height;
+               *v = v_allocation.height;
                }
        else if (v != &lw->options.main_window.vdivider_pos)
                {
@@ -1141,9 +1153,11 @@ static void layout_location_compute(LayoutLocation l1, LayoutLocation l2,
 
 gboolean layout_geometry_get_tools(LayoutWindow *lw, gint *x, gint *y, gint *w, gint *h, gint *divider_pos)
 {
+       GdkWindow *window;
+       GtkAllocation allocation;
        if (!layout_valid(&lw)) return FALSE;
 
-       if (!lw->tools || !GTK_WIDGET_VISIBLE(lw->tools))
+       if (!lw->tools || !gtk_widget_get_visible(lw->tools))
                {
                /* use the stored values (sort of breaks success return value) */
 
@@ -1152,16 +1166,19 @@ gboolean layout_geometry_get_tools(LayoutWindow *lw, gint *x, gint *y, gint *w,
                return FALSE;
                }
 
-       gdk_window_get_root_origin(lw->tools->window, x, y);
-       gdk_drawable_get_size(lw->tools->window, w, h);
+       window = gtk_widget_get_window(lw->window);
+       gdk_window_get_root_origin(window, x, y);
+       *w = gdk_window_get_width(window);
+       *h = gdk_window_get_height(window);
+       gtk_widget_get_allocation(gtk_paned_get_child1(GTK_PANED(lw->tools_pane)), &allocation);
 
        if (GTK_IS_VPANED(lw->tools_pane))
                {
-               *divider_pos = GTK_PANED(lw->tools_pane)->child1->allocation.height;
+               *divider_pos = allocation.height;
                }
        else
                {
-               *divider_pos = GTK_PANED(lw->tools_pane)->child1->allocation.width;
+               *divider_pos = allocation.width;
                }
 
        return TRUE;
@@ -1179,7 +1196,7 @@ static void layout_tools_hide(LayoutWindow *lw, gboolean hide)
 
        if (hide)
                {
-               if (GTK_WIDGET_VISIBLE(lw->tools))
+               if (gtk_widget_get_visible(lw->tools))
                        {
                        layout_tools_geometry_sync(lw);
                        gtk_widget_hide(lw->tools);
@@ -1187,7 +1204,7 @@ static void layout_tools_hide(LayoutWindow *lw, gboolean hide)
                }
        else
                {
-               if (!GTK_WIDGET_VISIBLE(lw->tools))
+               if (!gtk_widget_get_visible(lw->tools))
                        {
                        gtk_widget_show(lw->tools);
                        if (lw->vf) vf_refresh(lw->vf);
@@ -1215,10 +1232,6 @@ static void layout_tools_setup(LayoutWindow *lw, GtkWidget *tools, GtkWidget *fi
 
        vertical = (layout_location_single(lw->image_location) && !layout_location_vertical(lw->image_location)) ||
                   (!layout_location_single(lw->image_location) && layout_location_vertical(layout_grid_compass(lw)));
-#if 0
-       layout_location_compute(lw->dir_location, lw->file_location,
-                               tools, files, &w1, &w2);
-#endif
        /* for now, tools/dir are always first in order */
        w1 = tools;
        w2 = files;
@@ -1259,7 +1272,7 @@ static void layout_tools_setup(LayoutWindow *lw, GtkWidget *tools, GtkWidget *fi
                {
                layout_tools_geometry_sync(lw);
                /* dump the contents */
-               gtk_widget_destroy(GTK_BIN(lw->tools)->child);
+               gtk_widget_destroy(gtk_bin_get_child(GTK_BIN(lw->tools)));
                }
 
        layout_actions_add_window(lw, lw->tools);
@@ -1388,18 +1401,17 @@ void layout_split_change(LayoutWindow *lw, ImageSplitMode mode)
                if (lw->split_images[i])
                        {
                        gtk_widget_hide(lw->split_images[i]->widget);
-                       if (lw->split_images[i]->widget->parent != lw->utility_paned)
-                               gtk_container_remove(GTK_CONTAINER(lw->split_images[i]->widget->parent), lw->split_images[i]->widget);
+                       if (gtk_widget_get_parent(lw->split_images[i]->widget) != lw->utility_paned)
+                               gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(lw->split_images[i]->widget)), lw->split_images[i]->widget);
                        }
                }
        gtk_container_remove(GTK_CONTAINER(lw->utility_paned), lw->split_image_widget);
 
        image = layout_image_setup_split(lw, mode);
 
-//     gtk_box_pack_start(GTK_BOX(lw->utility_box), image, TRUE, TRUE, 0);
-//     gtk_box_reorder_child(GTK_BOX(lw->utility_box), image, 0);
        gtk_paned_pack1(GTK_PANED(lw->utility_paned), image, TRUE, FALSE);
        gtk_widget_show(image);
+       layout_util_sync(lw);
 }
 
 static void layout_grid_setup(LayoutWindow *lw)
@@ -1538,7 +1550,7 @@ void layout_style_set(LayoutWindow *lw, gint style, const gchar *order)
 
        /* remember state */
 
-       /* layout_image_slideshow_stop(lw); slideshow should survive */ 
+       /* layout_image_slideshow_stop(lw); slideshow should survive */
        layout_image_full_screen_stop(lw);
 
        dir_fd = lw->dir_fd;
@@ -1549,10 +1561,10 @@ void layout_style_set(LayoutWindow *lw, gint style, const gchar *order)
 
        /* preserve utility_box (image + sidebars), menu_bar and toolbars to be reused later in layout_grid_setup */
        /* lw->image is preserved together with lw->utility_box */
-       if (lw->utility_box) gtk_container_remove(GTK_CONTAINER(lw->utility_box->parent), lw->utility_box);
-       if (lw->menu_bar) gtk_container_remove(GTK_CONTAINER(lw->menu_bar->parent), lw->menu_bar);
+       if (lw->utility_box) gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(lw->utility_box)), lw->utility_box);
+       if (lw->menu_bar) gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(lw->menu_bar)), lw->menu_bar);
        for (i = 0; i < TOOLBAR_COUNT; i++)
-               if (lw->toolbar[i]) gtk_container_remove(GTK_CONTAINER(lw->toolbar[i]->parent), lw->toolbar[i]);
+               if (lw->toolbar[i]) gtk_container_remove(GTK_CONTAINER(gtk_widget_get_parent(lw->toolbar[i])), lw->toolbar[i]);
 
        /* clear it all */
 
@@ -1714,11 +1726,11 @@ void layout_toolbar_toggle(LayoutWindow *lw)
 
        if (lw->options.toolbar_hidden)
                {
-               if (GTK_WIDGET_VISIBLE(lw->toolbar[TOOLBAR_MAIN])) gtk_widget_hide(lw->toolbar[TOOLBAR_MAIN]);
+               if (gtk_widget_get_visible(lw->toolbar[TOOLBAR_MAIN])) gtk_widget_hide(lw->toolbar[TOOLBAR_MAIN]);
                }
        else
                {
-               if (!GTK_WIDGET_VISIBLE(lw->toolbar[TOOLBAR_MAIN])) gtk_widget_show(lw->toolbar[TOOLBAR_MAIN]);
+               if (!gtk_widget_get_visible(lw->toolbar[TOOLBAR_MAIN])) gtk_widget_show(lw->toolbar[TOOLBAR_MAIN]);
                }
 }
 
@@ -1874,7 +1886,7 @@ void layout_show_config_window(LayoutWindow *lw)
        button = pref_button_new(NULL, GTK_STOCK_OK, NULL, FALSE,
                                 G_CALLBACK(layout_config_ok_cb), lc);
        gtk_container_add(GTK_CONTAINER(hbox), button);
-       GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
+       gtk_widget_set_can_default(button, TRUE);
        gtk_widget_grab_default(button);
        gtk_widget_show(button);
 
@@ -1885,17 +1897,17 @@ void layout_show_config_window(LayoutWindow *lw)
        gtk_container_add(GTK_CONTAINER(hbox), button);
        GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
        gtk_widget_show(button);
-*/     
+*/
        button = pref_button_new(NULL, GTK_STOCK_APPLY, NULL, FALSE,
                                 G_CALLBACK(layout_config_apply_cb), lc);
        gtk_container_add(GTK_CONTAINER(hbox), button);
-       GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
+       gtk_widget_set_can_default(button, TRUE);
        gtk_widget_show(button);
 
        button = pref_button_new(NULL, GTK_STOCK_CANCEL, NULL, FALSE,
                                 G_CALLBACK(layout_config_close_cb), lc);
        gtk_container_add(GTK_CONTAINER(hbox), button);
-       GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT);
+       gtk_widget_set_can_default(button, TRUE);
        gtk_widget_show(button);
 
        if (!generic_dialog_get_alternative_button_order(lc->configwindow))
@@ -2074,6 +2086,7 @@ LayoutWindow *layout_new_with_geometry(FileData *dir_fd, LayoutOptions *lop,
        GdkWindowHints hint_mask;
        Histogram *histogram;
 
+       DEBUG_1("%s layout_new: start", get_exec_time());
        lw = g_new0(LayoutWindow, 1);
 
        if (lop)
@@ -2201,6 +2214,8 @@ LayoutWindow *layout_new_with_geometry(FileData *dir_fd, LayoutOptions *lop,
 
        file_data_register_notify_func(layout_image_notify_cb, lw, NOTIFY_PRIORITY_LOW);
 
+       DEBUG_1("%s layout_new: end", get_exec_time());
+
        return lw;
 }
 
@@ -2350,7 +2365,7 @@ static void layout_config_startup_path(LayoutOptions *lop, gchar **path)
                        *path = get_current_dir();
                        break;
                }
-}      
+}
 
 
 static void layout_config_commandline(LayoutOptions *lop, gchar **path)
@@ -2394,7 +2409,7 @@ LayoutWindow *layout_new_from_config(const gchar **attribute_names, const gchar
                {
                layout_config_commandline(&lop, &path);
                }
-       else 
+       else
                {
                layout_config_startup_path(&lop, &path);
                }