00001
00025 #include <stdio.h>
00026 #include <stdlib.h>
00027 #include <gtk/gtk.h>
00028 #include <glib.h>
00029
00030 #include "dimensions.h"
00031
00035 static void
00036 dimensions_window_close_cb
00037 (
00038 GtkWidget *widget,
00040 GtkWidget *dimensions_window
00042 )
00043 {
00044 gtk_widget_destroy (dimensions_window);
00045 }
00046
00047
00051 void
00052 dimensions_window_delete_event
00053 (
00054 GtkWidget *widget,
00056 GdkEvent *event
00058 )
00059 {
00060 gtk_widget_destroy (widget);
00061 }
00062
00063
00067 void
00068 dimensions_window_expose_event
00069 (
00070 GtkWidget *widget,
00072 GdkEventExpose *event,
00074 GdkPixbuf *buf
00076 )
00077 {
00078 gdk_draw_pixbuf
00079 (
00080 widget->window,
00081 NULL,
00082 buf,
00083 0,
00084 0,
00085 0,
00086 0,
00087 -1,
00088 -1,
00089 GDK_RGB_DITHER_NONE,
00090 0,
00091 0
00092 );
00093 }
00094
00095
00104 int
00105 dimensions_create_window
00106 (
00107 gchar *image_filename,
00110 gchar *footprint_type
00112 )
00113 {
00114
00115 GtkWidget *dimensions_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
00116
00117
00118 gtk_window_set_destroy_with_parent (GTK_WINDOW (dimensions_window),
00119 TRUE);
00120
00121 gchar *dimensions_window_title = g_strdup_printf (_("dimensions of %s"),
00122 footprint_type);
00123 gtk_window_set_title (GTK_WINDOW (dimensions_window),
00124 dimensions_window_title);
00125 g_free (dimensions_window_title);
00126 gtk_container_set_border_width (GTK_CONTAINER (dimensions_window), 10);
00127
00128 g_signal_connect
00129 (
00130 GTK_OBJECT (dimensions_window),
00131 "delete_event",
00132 (GtkSignalFunc) dimensions_window_delete_event,
00133 NULL
00134 );
00135
00136 GtkWidget *vbox = gtk_vbox_new (FALSE, 10);
00137 gtk_container_add (GTK_CONTAINER (dimensions_window), vbox);
00138
00139
00140 GdkPixbuf *dimensions_image = gdk_pixbuf_new_from_file (image_filename, NULL);
00141 GtkWidget *drawing_area = gtk_drawing_area_new ();
00142 gtk_widget_set_app_paintable (drawing_area, TRUE);
00143
00144 g_signal_connect
00145 (
00146 GTK_OBJECT (drawing_area),
00147 "expose-event",
00148 (GtkSignalFunc) dimensions_window_expose_event,
00149 dimensions_image
00150 );
00151
00152 gint width = gdk_pixbuf_get_width (dimensions_image);
00153 gint height = gdk_pixbuf_get_height (dimensions_image);
00154 gtk_widget_set_size_request (GTK_WIDGET (drawing_area), width, height);
00155 gtk_container_add (GTK_CONTAINER (vbox), drawing_area);
00156
00157 GtkWidget *hbox = gtk_hbutton_box_new ();
00158 gtk_button_box_set_layout (GTK_BUTTON_BOX (hbox), GTK_BUTTONBOX_END);
00159
00160 GtkWidget *button = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
00161 g_signal_connect
00162 (
00163 G_OBJECT (button),
00164 "clicked",
00165 G_CALLBACK (dimensions_window_close_cb),
00166 dimensions_window
00167 );
00168
00169 gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
00170
00171 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
00172
00173 gtk_window_set_resizable (GTK_WINDOW (dimensions_window), FALSE);
00174 gtk_widget_realize (dimensions_window);
00175 gtk_widget_show_all (dimensions_window);
00176
00177 gtk_main ();
00178 return 0;
00179 }
00180
00181
00182