diff options
author | Søren Sandmann <sandmann@redhat.com> | 2008-06-19 23:41:56 -0400 |
---|---|---|
committer | Søren Sandmann <sandmann@redhat.com> | 2008-06-19 23:41:56 -0400 |
commit | 5a5f9f4917240b77ca329ef93f863a72434bd0c4 (patch) | |
tree | 32ec7d226fbc919c24ccf4ee7bfbc298a108ae3c | |
parent | 3d48ddca660d96024c0e35a9534d666888fe2447 (diff) |
Better defaults when no image is loaded
-rw-r--r-- | window.c | 117 |
1 files changed, 65 insertions, 52 deletions
@@ -877,11 +877,17 @@ set_defaults (SivWindow *window) gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor); - g_assert (window->original); - - width = gdk_pixbuf_get_width (window->original) + 48; - height = gdk_pixbuf_get_height (window->original) + 96; - + if (window->original) + { + width = gdk_pixbuf_get_width (window->original) + 48; + height = gdk_pixbuf_get_height (window->original) + 96; + } + else + { + width = monitor.width / 3; + height = (width * 4) / 3; + } + if (width > monitor.width) width = monitor.width - 32; @@ -889,6 +895,9 @@ set_defaults (SivWindow *window) height = monitor.height - 32; 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); @@ -980,7 +989,55 @@ canonicalize_filename (const char *filename) return canon; } - + +static void +apply_meta_data (SivWindow *window, const char *filename) +{ + + const MetaData *data = app_get_meta_data (window->app, filename); + GtkCheckMenuItem *item; + + if (data) + { + 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); + + 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); + } +} + gboolean window_load_file (SivWindow *window, const char *filename, GError **err) { @@ -996,53 +1053,9 @@ window_load_file (SivWindow *window, const char *filename, GError **err) } else { - const MetaData *data; - window->original = pixbuf; - data = app_get_meta_data (window->app, window->filename); - - if (data) - { - GtkCheckMenuItem *item; - - 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); - - 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); - } + apply_meta_data (window, window->filename); rebuild (window); @@ -1074,7 +1087,7 @@ window_new (App *app) window->zoom_level = 0; window->first = TRUE; - gtk_window_set_default_size (get_widget (window, "main_window"), 640, 480); + set_defaults (window); rebuild (window); |