From: Denis M. <de...@li...> - 2000-10-17 12:23:09
|
This patch allow auto size of filer window on open, it look at o_initial_window_height and try to set the size as large as needed but setting width and height <= 2/3 screen sizes. It change filer.h and filer.c, to obtain scrollbar width I've added a scrollbar GtkWidget field into the FilerWindow definition and to avoid window opening out of screen the gtk_show of filer was moved after the autosize function. Here the patch : diff -c rox/ROX-Filer/src/filer.c roxautosize/ROX-Filer/src/filer.c *** rox/ROX-Filer/src/filer.c Sun Oct 15 18:52:56 2000 --- roxautosize/ROX-Filer/src/filer.c Tue Oct 17 01:13:57 2000 *************** *** 168,173 **** --- 168,212 ---- g_warning("Failed to find '%s'\n", item->leafname); } + /* filer_window_set_size : Set the window size in number of icons, it + * takes care of toolbar and scrollbar too */ + static void filer_window_set_size(FilerWindow *filer, int w, int h) + + { + if (w <= 0) w = 1; + if (h <= 0) h = 1; + w *= filer->collection->item_width; + h *= filer->collection->item_height; + w += filer->scrollbar->allocation.width; + if (o_toolbar != TOOLBAR_NONE) + h += filer->toolbar_frame->allocation.height; + gtk_window_set_default_size(GTK_WINDOW(filer->window), w, h); + } + + + + /* filer_window_autosize : Set a size using o_initial_window_height option + * and assuming not go over 2/3 screen width or + * height */ + static void filer_window_autosize(FilerWindow *filer) + + { + int n; + int nx, ny; + int maxw, maxh; + + n = filer->collection->number_of_items; + maxw = (2 * gdk_screen_width()) / (filer->collection->item_width * 3); + maxh = (2 * gdk_screen_height()) / (filer->collection->item_height * 3); + nx = (n + 1) / o_initial_window_height; + if (nx > maxw) nx = maxw; + if (nx <= 0) nx = 1; + ny = (n + 1) / nx; + if (ny > maxh) ny = maxh; + filer_window_set_size(filer, nx, ny); + } + + static void update_display(Directory *dir, DirAction action, GPtrArray *items, *************** *** 233,238 **** --- 272,279 ---- collection_set_cursor_item(collection, 0); filer_window->had_cursor = FALSE; } + filer_window_autosize(filer_window); /* Must be after shrink */ + gtk_widget_show(filer_window->window); set_scanning_display(filer_window, FALSE); break; case DIR_UPDATE: *************** *** 866,872 **** /* Make the window visible */ number_of_windows++; all_filer_windows = g_list_prepend(all_filer_windows, filer_window); - gtk_widget_show(filer_window->window); return filer_window; } --- 907,912 ---- *************** *** 876,882 **** */ static void filer_add_widgets(FilerWindow *filer_window) { ! GtkWidget *hbox, *vbox, *scrollbar, *collection; int col_height = ROW_HEIGHT_LARGE * o_initial_window_height; /* Create the top-level window widget */ --- 916,922 ---- */ static void filer_add_widgets(FilerWindow *filer_window) { ! GtkWidget *hbox, *vbox, *collection; int col_height = ROW_HEIGHT_LARGE * o_initial_window_height; /* Create the top-level window widget */ *************** *** 939,946 **** FALSE, TRUE, 0); /* Put the scrollbar on the left of everything else... */ ! scrollbar = gtk_vscrollbar_new(COLLECTION(collection)->vadj); ! gtk_box_pack_start(GTK_BOX(hbox), scrollbar, FALSE, TRUE, 0); /* Connect the menu's accelerator group to the window */ gtk_accel_group_attach(filer_keys, GTK_OBJECT(filer_window->window)); --- 979,986 ---- FALSE, TRUE, 0); /* Put the scrollbar on the left of everything else... */ ! filer_window->scrollbar = gtk_vscrollbar_new(COLLECTION(collection)->vadj); ! gtk_box_pack_start(GTK_BOX(hbox), filer_window->scrollbar, FALSE, TRUE, 0); /* Connect the menu's accelerator group to the window */ gtk_accel_group_attach(filer_keys, GTK_OBJECT(filer_window->window)); *************** *** 949,955 **** gtk_widget_show(hbox); gtk_widget_show(vbox); ! gtk_widget_show(scrollbar); gtk_widget_show(collection); gtk_widget_realize(filer_window->window); --- 989,995 ---- gtk_widget_show(hbox); gtk_widget_show(vbox); ! gtk_widget_show(filer_window->scrollbar); gtk_widget_show(collection); gtk_widget_realize(filer_window->window); diff -c rox/ROX-Filer/src/filer.h roxautosize/ROX-Filer/src/filer.h *** rox/ROX-Filer/src/filer.h Sun Oct 15 18:52:56 2000 --- roxautosize/ROX-Filer/src/filer.h Tue Oct 17 00:47:33 2000 *************** *** 66,71 **** --- 66,72 ---- GtkWidget *toolbar_frame; GtkWidget *toolbar_text; + GtkWidget *scrollbar; }; extern FilerWindow *window_with_focus; |