diff options
Diffstat (limited to 'window.c')
-rw-r--r-- | window.c | 153 |
1 files changed, 90 insertions, 63 deletions
@@ -336,7 +336,7 @@ save_meta_data (SivWindow *window) smooth = gtk_check_menu_item_get_active (get_widget (window, "menu_smooth_image")); show_toolbar = gtk_check_menu_item_get_active (get_widget (window, "menu_toolbar")); - + app_set_meta_data (window->app, filename, x, y, width, height, @@ -951,13 +951,16 @@ connect_signals (SivWindow *window) } static void -set_defaults (SivWindow *window) +compute_default_window_geometry (SivWindow *window, + int *x, + int *y, + int *width, + int *height) { GtkWidget *widget = get_widget (window, "main_window"); GdkScreen *screen = gtk_widget_get_screen (widget); GdkRectangle monitor; int monitor_num; - int width, height; monitor_num = gdk_screen_get_monitor_at_window (screen, widget->window); @@ -965,93 +968,117 @@ set_defaults (SivWindow *window) if (window->original) { - width = gdk_pixbuf_get_width (window->original) + 48; - height = gdk_pixbuf_get_height (window->original) + 96; + *width = gdk_pixbuf_get_width (window->original) + 48; + *height = gdk_pixbuf_get_height (window->original) + 96; } else { if (monitor.height < monitor.width) { - height = (monitor.height * 3) / 4; - width = (3 * height) / 4; + *height = (monitor.height * 3) / 4; + *width = (*height * 3) / 4; } else { - width = (monitor.width) / 3; - height = (width * 4) / 3; + *width = (monitor.width) / 3; + *height = (*width * 4) / 3; } } - if (width > monitor.width) - width = monitor.width - 32; + if (*width > monitor.width) + *width = monitor.width - 32; - if (height > monitor.height) - height = monitor.height - 32; + if (*height > monitor.height) + *height = monitor.height - 32; - if (GTK_WIDGET_REALIZED (get_widget (window, "main_window"))) - gtk_window_resize (get_widget (window, "main_window"), width, height); - else - gtk_window_set_default_size (get_widget (window, "main_window"), width, height); - - gtk_window_move (get_widget (window, "main_window"), - (monitor.width - width) / 2, - (monitor.height - height) / 2); - - gtk_check_menu_item_set_active (get_widget (window, "menu_smooth_image"), TRUE); - gtk_check_menu_item_set_active (get_widget (window, "menu_no"), TRUE); - gtk_check_menu_item_set_active (get_widget (window, "menu_toolbar"), TRUE); - + *x = (monitor.width - *width) / 2; + *y = (monitor.height - *height) / 2; } static void apply_meta_data (SivWindow *window, const char *filename) { - - GtkCheckMenuItem *item; MetaData data; + char *item_name; + int b; + App *app = window->app; - if (app_get_meta_data (window->app, filename, &data)) + /* Read values */ + + if (!app_get_meta_data (app, filename, "window_width", &(data.window_width)) || + !app_get_meta_data (app, filename, "window_height", &(data.window_height)) || + !app_get_meta_data (app, filename, "window_x", &(data.window_x)) || + !app_get_meta_data (app, filename, "window_y", &(data.window_y))) + { + compute_default_window_geometry ( + window, &data.window_x, &data.window_y, &data.window_width, &data.window_height); + } + + if (!app_get_meta_data (app, filename, "background", &b)) + b = BG_NONE; + + if (!app_get_meta_data (app, filename, "smooth_image", &(data.smooth_image))) + data.smooth_image = TRUE; + + if (!app_get_meta_data (app, filename, "zoom_level", &(data.zoom_level))) + data.zoom_level = 0; + + if (!app_get_meta_data (app, filename, "vadj", &(data.vadj))) + data.vadj = 0; + + if (!app_get_meta_data (app, filename, "hadj", &(data.hadj))) + data.hadj = 0; + + if (!app_get_meta_data (app, filename, "show_toolbar", &(data.show_toolbar))) + data.show_toolbar = TRUE; + + /* Apply them */ + + if (GTK_WIDGET_REALIZED (get_widget (window, "main_window"))) { - gtk_window_move (get_widget (window, "main_window"), - data.window_x, data.window_y); - gtk_window_resize (get_widget (window, "main_window"), data.window_width, data.window_height); - - switch (data.background) - { - default: - case BG_NONE: - item = get_widget (window, "menu_no"); - break; - - case BG_CHECKERBOARD: - item = get_widget (window, "menu_checkerboard"); - break; - - case BG_WHITE: - item = get_widget (window, "menu_white"); - break; - } - - gtk_check_menu_item_set_active (item, TRUE); - - gtk_check_menu_item_set_active (get_widget (window, "menu_smooth_image"), - data.smooth_image); - - gtk_check_menu_item_set_active (get_widget (window, "menu_toolbar"), - data.show_toolbar); - - window->zoom_level = data.zoom_level; - - /* Adjustments have to be set after the window is shown */ - window->hadj = data.hadj; - window->vadj = data.vadj; } else { - set_defaults (window); + gtk_window_set_default_size (get_widget (window, "main_window"), + data.window_width, data.window_height); + } + + gtk_window_move (get_widget (window, "main_window"), + data.window_x, data.window_y); + + switch (b) + { + default: + case BG_NONE: + item_name = "menu_no"; + break; + + case BG_CHECKERBOARD: + item_name = "menu_checkerboard"; + break; + + case BG_WHITE: + item_name = "menu_white"; + break; } + + gtk_check_menu_item_set_active (get_widget (window, item_name), TRUE); + + gtk_check_menu_item_set_active (get_widget (window, "menu_smooth_image"), + data.smooth_image); + + gtk_check_menu_item_set_active (get_widget (window, "menu_toolbar"), + data.show_toolbar); + + window->zoom_level = data.zoom_level; + + /* Adjustments have to be set after the window is shown, so we + * store them in variables here, and apply them later + */ + window->hadj = data.hadj; + window->vadj = data.vadj; } gboolean |