diff options
author | Søren Sandmann <sandmann@redhat.com> | 2008-03-09 14:27:04 -0400 |
---|---|---|
committer | Søren Sandmann <sandmann@redhat.com> | 2008-03-09 14:27:04 -0400 |
commit | 0edb4abff46d5a8eb72607434c24627911935be6 (patch) | |
tree | b8aa57472da8b3db22d36ee2e6e565c6535feb18 | |
parent | f81f250c08495e1b6e6fe22f6d2213ef1e6351bf (diff) |
Sensitivity
-rw-r--r-- | siv.c | 43 | ||||
-rw-r--r-- | window.c | 55 |
2 files changed, 65 insertions, 33 deletions
@@ -54,12 +54,6 @@ app_unregister_window (App *app, Window *window) } MetaData * -app_get_meta_info (App *app, const char *file) -{ - /* FIXME */ -} - -MetaData * app_get_meta_data (App *app, const char *file) { @@ -239,26 +233,31 @@ app_new (int argc, char **argv) app->meta_data = load_meta_data (); g_hash_table_new (g_str_hash, g_str_equal); - for (list = filenames; list != NULL; list = list->next) + if (filenames) { - Window *window = window_new (app); - GError *err = NULL; - char *filename = list->data; - - if (!window_load_file (window, list->data, &err)) - { - g_print ("Could not open %s: %s\n", filename, err->message); - window_free (window); - } - else + for (list = filenames; list != NULL; list = list->next) { - window_show (window); + Window *window = window_new (app); + GError *err = NULL; + char *filename = list->data; + + if (!window_load_file (window, list->data, &err)) + { + g_print ("Could not open %s: %s\n", filename, err->message); + window_free (window); + } + else + { + window_show (window); + } } - } - - g_list_free (filenames); - return; + g_list_free (filenames); + } + else + { + window_show (window_new (app)); + } } int @@ -132,11 +132,52 @@ adjust_adjustment (GtkAdjustment *adj, int old_size, int new_size) } static void -rebuild (Window *window) -{ +set_sensitivity (Window *window) +{ gboolean can_zoom_out = FALSE; gboolean can_zoom_in = FALSE; + int i; + + /* List of widgets that are sensitive if and only if a file is loaded */ + const char insensitive[][32] = + { + "menu_save", "menu_save_as", "menu_rotate_left", "menu_rotate_right", + "menu_white", "menu_checkerboard", "menu_no", "menu_smooth_image", + "menu_zoom_normal", "zoom_normal", "rotate_left", "rotate_right" + }; + + for (i = 0; i < G_N_ELEMENTS (insensitive); ++i) + { + GtkWidget *widget = GET_WIDGET (window, insensitive[i]); + + if (window->original) + gtk_widget_set_sensitive (widget, TRUE); + else + gtk_widget_set_sensitive (widget, FALSE); + } + if (window->original) + { + int w, h; + + compute_size (window, &w, &h); + + can_zoom_in = window->zoom_level < MAX_ZOOM; + + can_zoom_out = window->zoom_level > MIN_ZOOM; + if (window->zoom_level <= 0 && (w < 16 || h < 16)) + can_zoom_out = FALSE; + } + + gtk_widget_set_sensitive (GET_WIDGET (window, "menu_zoom_out"), can_zoom_out); + gtk_widget_set_sensitive (GET_WIDGET (window, "zoom_out"), can_zoom_out); + gtk_widget_set_sensitive (GET_WIDGET (window, "menu_zoom_in"), can_zoom_in); + gtk_widget_set_sensitive (GET_WIDGET (window, "zoom_in"), can_zoom_in); +} + +static void +rebuild (Window *window) +{ if (window->zoom_level < MIN_ZOOM) window->zoom_level = MIN_ZOOM; @@ -176,17 +217,9 @@ rebuild (Window *window) window->width = w; window->height = h; - - can_zoom_in = window->zoom_level < MAX_ZOOM; - can_zoom_out = window->zoom_level > MIN_ZOOM; - if (window->zoom_level <= 0 && (w < 16 || h < 16)) - can_zoom_out = FALSE; } - gtk_widget_set_sensitive (GET_WIDGET (window, "menu_zoom_out"), can_zoom_out); - gtk_widget_set_sensitive (GET_WIDGET (window, "zoom_out"), can_zoom_out); - gtk_widget_set_sensitive (GET_WIDGET (window, "menu_zoom_in"), can_zoom_in); - gtk_widget_set_sensitive (GET_WIDGET (window, "zoom_in"), can_zoom_in); + set_sensitivity (window); gtk_widget_queue_draw (GET_WIDGET (window, "drawing_area")); } |