cropper

view interface.c @ 15:7dbf3879939a

removed support.*
author meillo@marmaro.de
date Thu, 04 Mar 2010 19:16:10 +0100
parents da18f2d4f92f
children 88b8856fccf5
line source
1 #include <sys/types.h>
2 #include <sys/stat.h>
3 #include <unistd.h>
4 #include <string.h>
5 #include <stdio.h>
7 #include <gdk/gdkkeysyms.h>
8 #include <gtk/gtk.h>
9 #include <gdk-pixbuf/gdk-pixbuf.h>
11 #include "main.h"
12 #include "callbacks.h"
14 #define GLADE_HOOKUP_OBJECT(component,widget,name) \
15 g_object_set_data_full(G_OBJECT(component), name, \
16 gtk_widget_ref(widget),(GDestroyNotify) gtk_widget_unref)
18 #define GLADE_HOOKUP_OBJECT_NO_REF(component,widget,name) \
19 g_object_set_data(G_OBJECT(component), name, widget)
22 /*
23 * This function returns a widget in a component created by Glade.
24 * Call it with the toplevel widget in the component (i.e. a window/dialog),
25 * or alternatively any widget in the component, and the name of the widget
26 * you want returned.
27 */
28 GtkWidget*
29 lookup_widget(GtkWidget* widget, const gchar* widget_name)
30 {
31 GtkWidget* parent;
32 GtkWidget* found_widget;
34 for (;;) {
35 if (GTK_IS_MENU(widget)) {
36 parent = gtk_menu_get_attach_widget(GTK_MENU(widget));
37 } else {
38 parent = widget->parent;
39 }
40 if (!parent) {
41 parent = (GtkWidget*) g_object_get_data(G_OBJECT(widget), "GladeParentKey");
42 }
43 if (parent == NULL) {
44 break;
45 }
46 widget = parent;
47 }
49 found_widget = (GtkWidget*) g_object_get_data(G_OBJECT(widget), widget_name);
50 if (!found_widget) {
51 g_warning("Widget not found: %s", widget_name);
52 }
53 return found_widget;
54 }
58 GtkWidget*
59 create_cropper_window(void)
60 {
61 GtkWidget *cropper_window;
62 GtkWidget *dialog_vbox1;
63 GtkWidget *status;
64 GtkWidget *label1;
65 GtkWidget *label2;
68 cropper_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
69 gtk_widget_set_name(cropper_window, "cropper_window");
70 gtk_container_set_border_width(GTK_CONTAINER(cropper_window), 6);
71 gtk_window_set_title(GTK_WINDOW(cropper_window), "cropper-0.2");
73 dialog_vbox1 = gtk_vbox_new(FALSE, 6);
74 gtk_widget_set_name(dialog_vbox1, "dialog_vbox1");
75 gtk_widget_show(dialog_vbox1);
76 gtk_container_add(GTK_CONTAINER(cropper_window), dialog_vbox1);
79 status = gtk_hbox_new(FALSE, 0);
80 gtk_widget_set_name(status, "status");
81 gtk_widget_show(status);
82 gtk_box_pack_end(GTK_BOX(dialog_vbox1), status, FALSE, FALSE, 0);
84 label1 = gtk_label_new("zoom:");
85 gtk_widget_set_name(label1, "label1");
86 gtk_widget_show(label1);
87 gtk_box_pack_start(GTK_BOX(status), label1, FALSE, FALSE, 0);
89 label2 = gtk_label_new("1.0");
90 gtk_widget_set_name(label2, "label2");
91 gtk_widget_show(label2);
92 gtk_box_pack_start(GTK_BOX(status), label2, FALSE, FALSE, 0);
94 /* image_area */
95 image_buffer = gdk_pixbuf_new_from_file(image_filename, NULL);
96 image_area = gtk_image_new_from_pixbuf(image_buffer);
98 gtk_widget_set_name(image_area, "image_area");
99 gtk_widget_show(image_area);
100 gtk_box_pack_start(GTK_BOX(dialog_vbox1), image_area, TRUE, TRUE, 0);
106 g_signal_connect(G_OBJECT(cropper_window), "show",
107 G_CALLBACK(on_cropper_window_create), NULL);
109 g_signal_connect(G_OBJECT(cropper_window), "destroy",
110 G_CALLBACK(on_cropper_window_destroy), NULL);
112 g_signal_connect(cropper_window, "key-press-event",
113 G_CALLBACK(on_key_press), NULL);
116 /* Store pointers to all widgets, for use by lookup_widget(). */
118 GLADE_HOOKUP_OBJECT_NO_REF(cropper_window, cropper_window, "cropper_window");
119 GLADE_HOOKUP_OBJECT(cropper_window, dialog_vbox1, "dialog_vbox1");
121 GLADE_HOOKUP_OBJECT(cropper_window, label1, "label1");
122 GLADE_HOOKUP_OBJECT(cropper_window, label2, "label2");
123 GLADE_HOOKUP_OBJECT(cropper_window, status, "status");
124 GLADE_HOOKUP_OBJECT(cropper_window, image_area, "image_area");
125 GLADE_HOOKUP_OBJECT(cropper_window,(GtkWidget*) image_buffer, "image_buffer");
128 return cropper_window;
129 }
139 /*
140 gtk_container_set_border_width(GTK_CONTAINER(hbox1), 5);
142 label1 = gtk_label_new("<b>Selection</b>");
143 gtk_label_set_use_markup(GTK_LABEL(label1), TRUE);
144 gtk_misc_set_alignment(GTK_MISC(label1), 0, 0.5);
146 gtk_table_set_row_spacings(GTK_TABLE(table2), 6);
147 gtk_table_set_col_spacings(GTK_TABLE(table2), 6);
149 gtk_table_attach(GTK_TABLE(table2), label3, 0, 1, 0, 1,(GtkAttachOptions)(GTK_FILL),
150 (GtkAttachOptions)(0), 0, 0);
151 gtk_misc_set_alignment(GTK_MISC(label3), 0, 0.5);
153 frame1 = gtk_frame_new(NULL);
154 gtk_widget_set_name(frame1, "frame1");
155 gtk_widget_show(frame1);
156 gtk_box_pack_start(GTK_BOX(vbox5), frame1, TRUE, TRUE, 0);
157 gtk_frame_set_shadow_type(GTK_FRAME(frame1), GTK_SHADOW_NONE);
159 vbox7 = gtk_vbox_new(FALSE, 6);
160 gtk_widget_set_name(vbox7, "vbox7");
161 gtk_widget_show(vbox7);
162 gtk_container_add(GTK_CONTAINER(frame1), vbox7);
164 g_signal_connect(G_OBJECT(lookup_widget(cropper_window, "crop_x_spinbutton")), "value_changed",
165 G_CALLBACK(selection_x_value_changed_cb), data);
166 g_signal_connect(G_OBJECT(lookup_widget(cropper_window, "crop_image")), "selection_changed",
167 G_CALLBACK(selection_changed_cb), data);
168 g_signal_connect(G_OBJECT(lookup_widget(cropper_window, "ratio_swap_button")), "clicked",
169 G_CALLBACK(ratio_swap_button_cb), NULL);
170 g_signal_connect(G_OBJECT(lookup_widget(cropper_window, "ratio_optionmenu")), "changed",
171 G_CALLBACK(ratio_optionmenu_changed_cb), NULL);
172 g_signal_connect(G_OBJECT(ratio_none), "activate",
173 G_CALLBACK(on_ratio_none_activate), NULL);
174 */