summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Sandmann <sandmann@redhat.com>2008-03-09 15:54:06 -0400
committerSøren Sandmann <sandmann@redhat.com>2008-03-09 15:54:06 -0400
commit53963d0f8097db9089c7e260296269f0f9b0bfb4 (patch)
tree749602bec3a34f90b9967c64a5f3850f90284431
parent85c008aec9d067ecfe22b0d6f36fbd6fd8c69ebb (diff)
Set title
-rw-r--r--window.c75
1 files changed, 51 insertions, 24 deletions
diff --git a/window.c b/window.c
index c230dbb..764972b 100644
--- a/window.c
+++ b/window.c
@@ -8,6 +8,7 @@
struct Window
{
GladeXML * xml;
+ char * filename;
GdkPixbuf * original;
int width;
@@ -20,7 +21,7 @@ struct Window
};
static void *
-GET_WIDGET (Window *window, const char *name)
+get_widget (Window *window, const char *name)
{
void *result = glade_xml_get_widget (window->xml, name);
@@ -64,7 +65,7 @@ on_expose (GtkWidget *drawing_area, GdkEventExpose *expose, Window *window)
if (!window->original)
return TRUE;
- if (!GTK_WIDGET_DRAWABLE (GET_WIDGET (window, "drawing_area")))
+ if (!GTK_WIDGET_DRAWABLE (get_widget (window, "drawing_area")))
return TRUE;
gdk_window_get_size (drawing_area->window, &window_width, &window_height);
@@ -83,7 +84,7 @@ on_expose (GtkWidget *drawing_area, GdkEventExpose *expose, Window *window)
tmp = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, dest.width, dest.height);
- if (gtk_check_menu_item_get_active (GET_WIDGET (window, "menu_no")))
+ if (gtk_check_menu_item_get_active (get_widget (window, "menu_no")))
{
GdkColor color = drawing_area->style->bg[GTK_STATE_NORMAL];
@@ -93,18 +94,18 @@ on_expose (GtkWidget *drawing_area, GdkEventExpose *expose, Window *window)
color2 = color1;
}
- else if (gtk_check_menu_item_get_active (GET_WIDGET (window, "menu_white")))
+ else if (gtk_check_menu_item_get_active (get_widget (window, "menu_white")))
{
color1 = 0x00ffffff;
color2 = 0x00ffffff;
}
else /* Checkerboard */
{
- color1 = 0x00808080;
- color2 = 0x00cccccc;
+ color1 = 0x008080ff;
+ color2 = 0x00ccccff;
}
- if (gtk_check_menu_item_get_active (GET_WIDGET (window, "menu_smooth_image")))
+ if (gtk_check_menu_item_get_active (get_widget (window, "menu_smooth_image")))
interp = GDK_INTERP_BILINEAR;
else
interp = GDK_INTERP_NEAREST;
@@ -155,7 +156,7 @@ set_sensitivity (Window *window)
for (i = 0; i < G_N_ELEMENTS (insensitive); ++i)
{
- GtkWidget *widget = GET_WIDGET (window, insensitive[i]);
+ GtkWidget *widget = get_widget (window, insensitive[i]);
if (window->original)
gtk_widget_set_sensitive (widget, TRUE);
@@ -176,10 +177,27 @@ set_sensitivity (Window *window)
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);
+ 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
+set_title (Window *window)
+{
+ if (window->filename && window->original)
+ {
+ gchar *basename = g_path_get_basename (window->filename);
+
+ gtk_window_set_title (get_widget (window, "main_window"), basename);
+
+ g_free (basename);
+ }
+ else
+ {
+ gtk_window_set_title (get_widget (window, "main_window"), APPLICATION_NAME);
+ }
}
static void
@@ -198,10 +216,10 @@ rebuild (Window *window)
compute_size (window, &w, &h);
- gtk_widget_hide (GET_WIDGET (window, "scrolled_window"));
+ gtk_widget_hide (get_widget (window, "scrolled_window"));
- hadj = gtk_scrolled_window_get_hadjustment (GET_WIDGET (window, "scrolled_window"));
- vadj = gtk_scrolled_window_get_vadjustment (GET_WIDGET (window, "scrolled_window"));
+ hadj = gtk_scrolled_window_get_hadjustment (get_widget (window, "scrolled_window"));
+ vadj = gtk_scrolled_window_get_vadjustment (get_widget (window, "scrolled_window"));
if (window->first)
{
@@ -218,17 +236,18 @@ rebuild (Window *window)
adjust_adjustment (vadj, window->height, h);
}
- gtk_widget_set_size_request (GET_WIDGET (window, "drawing_area"), w, h);
+ gtk_widget_set_size_request (get_widget (window, "drawing_area"), w, h);
+
+ gtk_widget_show (get_widget (window, "scrolled_window"));
- gtk_widget_show (GET_WIDGET (window, "scrolled_window"));
-
window->width = w;
window->height = h;
}
+ set_title (window);
set_sensitivity (window);
- gtk_widget_queue_draw (GET_WIDGET (window, "drawing_area"));
+ gtk_widget_queue_draw (get_widget (window, "drawing_area"));
}
static void
@@ -405,6 +424,8 @@ window_load_file (Window *window, const char *filename, GError **err)
{
GdkPixbuf *pixbuf;
+ window->filename = g_strdup (filename);
+
pixbuf = gdk_pixbuf_new_from_file (filename, err);
if (!pixbuf)
@@ -427,9 +448,9 @@ window_new (App *app)
window->xml = glade_xml_new (GLADE_FILE, NULL, NULL);
window->app = app;
- gtk_widget_add_events (GET_WIDGET (window, "drawing_area"), GDK_SCROLL_MASK);
+ gtk_widget_add_events (get_widget (window, "drawing_area"), GDK_SCROLL_MASK);
gtk_widget_set_redraw_on_allocate (
- GET_WIDGET (window, "drawing_area"), FALSE);
+ get_widget (window, "drawing_area"), FALSE);
/* Connect signals */
connect_signals (window);
@@ -450,17 +471,23 @@ window_free (Window *window)
{
app_unregister_window (window->app, window);
- gtk_widget_destroy (GET_WIDGET (window, "main_window"));
+ gtk_widget_destroy (get_widget (window, "main_window"));
g_object_unref (window->xml);
+ if (window->original)
+ g_object_unref (window->original);
+
+ if (window->filename)
+ g_free (window->filename);
+
g_free (window);
}
void
window_show (Window *window)
{
- gtk_widget_show (GET_WIDGET (window, "main_window"));
+ gtk_widget_show (get_widget (window, "main_window"));
- gtk_window_set_focus (GET_WIDGET (window, "main_window"), NULL);
+ gtk_window_set_focus (get_widget (window, "main_window"), NULL);
}