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