cropper

annotate interface.c @ 15:7dbf3879939a

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