1 /* Helper Functions for GTK Stamp Config!
2 Eric Werner - 19 FEB 1999
3 ebw@city-net.com
4 */
5 #include <sys/shm.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <unistd.h>
9 #include "gstamp.h"
10
11 extern char *stamperror[] ;
12
13
set_status(UI_Struct * ui,char * str)14 void set_status(UI_Struct *ui, char *str){
15 gtk_label_set(GTK_LABEL(ui->Status), str);
16 gtk_widget_hide(ui->Status);
17 gtk_widget_show(ui->Status);
18 }
19
20 /* this forks and runs stamp_main and potentially Transfer_File. It forks so that
21 the ui is kept active */
gstmp_stampit(UI_Struct * ui,struct ArgStruct * args,int send)22 int gstmp_stampit(UI_Struct *ui, struct ArgStruct *args, int send){
23 int stamp_return;
24 int pid;
25 int *shm;
26 int shmid;
27 char tmpstr[1024];
28
29 if (ui->GSTMP_STAMPING) {
30 return 0;
31 }
32
33 shmid = create_shm();
34
35 if (shmid == -1) {
36 message_set_text(ui, "Error Creating Shared Memory.\n Contact Authors.");
37 message_show(ui);
38 return 0;
39 }
40
41 shm = (int *) shmat(shmid, 0, 0);
42 shm[0] = -1;
43
44 pid = fork();
45
46 if (pid){
47 /* then we're the parent */
48 ui->GSTMP_STAMPING = 1;
49 gtk_pixmap_set ((GtkPixmap *)ui->stamp_pix, ui->yes_stamp, ui->yes_stamp_mask);
50 gtk_widget_hide(ui->stamp_pix);
51 gtk_widget_show(ui->stamp_pix);
52 strcpy(tmpstr, "Stamping...");
53 set_status(ui, tmpstr);
54 while ((shm[0]) == -1) {
55 if (gtk_events_pending()){
56 gtk_main_iteration();
57 }
58 }
59 stamp_return = shm[0];
60 gtk_pixmap_set ((GtkPixmap *)ui->stamp_pix, ui->no_stamp, ui->no_stamp_mask);
61 gtk_widget_hide(ui->stamp_pix);
62 gtk_widget_show(ui->stamp_pix);
63 if (send && !stamp_return) {
64 shm[0] = -1;
65 gtk_pixmap_set ((GtkPixmap *)ui->transfer_pix, ui->yes_transfer, ui->yes_transfer_mask);
66 gtk_widget_hide(ui->transfer_pix);
67 gtk_widget_show(ui->transfer_pix);
68 strcpy(tmpstr, "Sending to ");
69 strcat(tmpstr, ui->args->Host);
70 strcat(tmpstr, "...");
71 set_status(ui, tmpstr);
72 while ((shm[0]) == -1) {
73 if (gtk_events_pending()){
74 gtk_main_iteration();
75 }
76 }
77 gtk_pixmap_set ((GtkPixmap *)ui->transfer_pix, ui->no_transfer, ui->no_transfer_mask);
78 gtk_widget_hide(ui->transfer_pix);
79 gtk_widget_show(ui->transfer_pix);
80 stamp_return = shm[0];
81 }
82 set_status(ui, "Idle");
83 shmdt(shm);
84 ui->GSTMP_STAMPING = 0;
85 }
86
87 /* BEGIN CHILD PROCESS */
88 else {
89 stamp_return = stamp_main(args);
90 shm[0] = stamp_return;
91 if (send && !stamp_return) {
92 while(shm[0] != -1){ usleep(1); };
93 stamp_return = Transfer_File(args) ;
94 }
95 shm[0] = stamp_return;
96 shmdt(shm);
97 _exit(0);
98 }
99 /* END CHILD PROCESS */
100
101 if (remove_shm(shmid) == -1){
102 message_set_text(ui, "Error Removing Shared Memory.\n Contact Authors.");
103 message_show(ui);
104 return 0;
105 }
106 return stamp_return;
107 }
108
109 /* create shared memory segment */
create_shm()110 int create_shm(){
111 key_t key;
112 char *shm;
113 int shmid;
114
115 key = ftok(".", 'h');
116 if (key == -1) {
117 return -1;
118 }
119 shmid = shmget(key,0,0);
120 shmctl(shmid, 0, IPC_RMID);
121 shmid = shmget(key, 2 * sizeof(int), 0700 | IPC_CREAT | IPC_EXCL);
122 return shmid;
123 }
124
remove_shm(int shmid)125 int remove_shm(int shmid){
126 if (shmctl(shmid, 0, IPC_RMID) == -1) {
127 return -1;
128 }
129 return 0;
130 }
131
132 /* this actually displays a jpeg in the preview window */
display_jpeg(gchar * filename,UI_Struct * ui)133 void display_jpeg(gchar *filename, UI_Struct *ui){
134 GdkColorContext *gcc;
135 guint32 pixel;
136 struct ImageStruct *jpg;
137 struct ScanLine *scanline;
138 int x, y,i;
139 guint32 red, green, blue;
140 gint bgcolor_red, bgcolor_green, bgcolor_blue;
141 gint bits_red, bits_green, bits_blue;
142 gint mask_red, mask_green, mask_blue;
143 guint32 bgcolor;
144
145 jpg = g_malloc ( sizeof(struct ImageStruct) );
146 bzero(jpg, sizeof(struct ImageStruct));
147
148 gtk_widget_realize(ui->preview->window);
149
150 if (jpg==NULL){
151 message_set_text(ui, "Could not allocate memory for jpg!");
152 message_show(ui);
153 return;
154 }
155
156 JPG_Load(filename, jpg);
157
158 /* make a gcc if we dont have one, and set it. */
159 if (!ui->preview->gcc) {
160 gcc = ui->preview->gcc =
161 gdk_color_context_new(
162 gdk_window_get_visual(ui->preview->window->window),
163 gdk_window_get_colormap(ui->preview->window->window));
164 } else {
165 gcc = ui->preview->gcc;
166 }
167
168 /* if there was an image, kill it */
169 if (ui->preview->gdk_image){
170 gdk_image_destroy(ui->preview->gdk_image);
171 }
172
173 /* now make our gdk image */
174 ui->preview->gdk_image =
175 gdk_image_new(GDK_IMAGE_NORMAL,
176 gdk_window_get_visual(ui->preview->window->window),
177 jpg->image_width,
178 jpg->image_height);
179
180 /* if there's not a gtk_image, make one. */
181 if (!ui->preview->gtk_image){
182 ui->preview->gtk_image = gtk_image_new (ui->preview->gdk_image, (GdkBitmap *)NULL);
183 gtk_container_add (GTK_CONTAINER (ui->preview->vbox), ui->preview->gtk_image);
184 gtk_widget_show (ui->preview->gtk_image);
185 }
186
187 /* set the image in the gtk_image */
188 gtk_image_set (GTK_IMAGE(ui->preview->gtk_image), ui->preview->gdk_image, (GdkBitmap *)NULL);
189
190 /* set the window size */
191 gtk_widget_set_usize (ui->preview->window, jpg->image_width+5, jpg->image_height+5);
192
193 /* do some magic with the bits to fit them into out colormap */
194 bits_red = gcc->bits.red + gcc->bits.green + gcc->bits.blue - 8;
195 bits_green = gcc->bits.green + gcc->bits.blue - 8;
196 bits_blue = 8 - gcc->bits.blue;
197
198 mask_red = ((1 << gcc->bits.red) - 1) << (gcc->bits.green + gcc->bits.blue);
199 mask_green = ((1 << gcc->bits.green) - 1) << gcc->bits.blue;
200 mask_blue = ((1 << gcc->bits.blue) - 1);
201
202 /* loop thru the jpeg */
203 scanline = jpg->FirstLine;
204 for (y = 0; y< jpg->image_height; y++){
205 for (x = 0; x< jpg->image_width; x++){
206
207 red = scanline->line[x * BYTES_PER_PIXEL + 0];
208 green = scanline->line[x * BYTES_PER_PIXEL + 1];
209 blue = scanline->line[x * BYTES_PER_PIXEL + 2];
210
211 pixel = (red << bits_red) & mask_red;
212 pixel |= (green << bits_green) & mask_green;
213 pixel |= (blue >> bits_blue);
214
215 gdk_image_put_pixel(ui->preview->gdk_image, x, y, pixel);
216 }
217 scanline = scanline->next;
218 }
219
220 JPG_Free(jpg);
221 gtk_widget_show(ui->preview->window);
222 }
223
224 /* this runs stamp and then calls show_jpeg */
Preview(UI_Struct * ui)225 void Preview(UI_Struct *ui){
226
227 /* these are to hold the original values in the Args structure */
228 char *outfile;
229 char *infile;
230 char tmpoutfile[255];
231 int pid; /* our pid */
232 int stamp_return; /* return value for the call to stamp */
233 struct ArgStruct *a;
234
235 /* save what is originally in the stamp args struct */
236 a = ui->args;
237
238 /* put what we have into the stamp args struct */
239 ui_to_args(ui, a);
240
241 /* save that which we must temporarily change for our preview */
242 infile = a->Infile;
243 outfile = a->Outfile;
244
245 /* make a unique rcfile in tmp */
246 pid = getpid();
247
248 /* make a unique outputfile in /tmp */
249 sprintf(tmpoutfile, "/tmp/stamp.%d.jpg", pid);
250 a->Outfile = tmpoutfile;
251
252 /* set the infile */
253 a->Infile = a->Previewfile;
254
255 /* run stamp on the image.
256 this should eventually be a call to the stamp_main */
257
258 stamp_return = gstmp_stampit(ui, a, 0);
259
260 /* put the rc structure back to the way is 'twas */
261 a->Infile = infile;
262 a->Outfile = outfile;
263
264 if (stamp_return) {
265 message_set_text(ui, stamperror[stamp_return]);
266 message_show(ui);
267 } else {
268 /* now we actually display the damn jpeg */
269 display_jpeg(tmpoutfile, ui);
270 }
271 /* get rid of our mess in /tmp */
272 remove(tmpoutfile);
273 }
274
275
276 /* Funtion to copy strings and handle memory allocation.
277 Goofy - yes, but makes the code look a bit nicer
278 */
Nice_String_Copy(char ** s1,char * s2)279 void Nice_String_Copy(char **s1, char *s2){
280 if (!s2) {
281 if (!*s1) {
282 return;
283 } else {
284 free(*s1);
285 s1 = NULL;
286 return;
287 }
288 } else {
289 if (*s1) {
290 free (*s1);
291 }
292 *s1 = (char *)g_malloc (sizeof (char) * strlen(s2) + 1);
293 if(*s1) {
294 strcpy (*s1, s2);
295 } else {
296 }
297 }
298 }
299
300
301 /* Fills up the Stamp Args Structure using the information contained in the GUI. */
ui_to_args(UI_Struct * ui,struct ArgStruct * a)302 gint ui_to_args(UI_Struct *ui, struct ArgStruct *a){
303 GtkStyle *style;
304
305 bzero((void *)a, sizeof(struct ArgStruct));
306
307 Nice_String_Copy(&a->RCFile, (char *)ui->RCFile);
308 Nice_String_Copy(&a->Previewfile, (char *)gtk_entry_get_text (GTK_ENTRY(ui->Previewfile)));
309 Nice_String_Copy(&a->Infile, (char *)gtk_entry_get_text (GTK_ENTRY(ui->Infile)));
310 Nice_String_Copy(&a->Outfile, (char *)gtk_entry_get_text (GTK_ENTRY(ui->Outfile)));
311 Nice_String_Copy(&a->UpperString, (char *)gtk_entry_get_text (GTK_ENTRY(ui->UpperString)));
312 Nice_String_Copy(&a->LowerString, (char *)gtk_entry_get_text (GTK_ENTRY(ui->LowerString)));
313 Nice_String_Copy(&a->UpperFont, (char *)gtk_entry_get_text (GTK_ENTRY(ui->UpperFont)));
314 Nice_String_Copy(&a->LowerFont, (char *)gtk_entry_get_text (GTK_ENTRY(ui->LowerFont)));
315
316 a->UStringExec = (int)GTK_TOGGLE_BUTTON(ui->UStringExec)->active ;
317 a->LStringExec = (int)GTK_TOGGLE_BUTTON(ui->LStringExec)->active ;
318 a->Use3D = (int)GTK_TOGGLE_BUTTON(ui->Use3D)->active ;
319 a->Rotate = (int)GTK_TOGGLE_BUTTON(ui->Rotate)->active ;
320
321 a->UseColors = (int)GTK_TOGGLE_BUTTON(ui->UseColors)->active;
322
323 a->ShadeRate = (int)gtk_range_get_adjustment(GTK_RANGE(ui->ShadeRate))->value;
324 a->Quality = (int)gtk_range_get_adjustment(GTK_RANGE(ui->Quality))->value;
325
326 /* FTP Related */
327 Nice_String_Copy(&a->Host, (char *)gtk_entry_get_text (GTK_ENTRY(ui->Host)));
328 Nice_String_Copy(&a->Path, (char *)gtk_entry_get_text (GTK_ENTRY(ui->Path)));
329 Nice_String_Copy(&a->Upload, (char *)gtk_entry_get_text (GTK_ENTRY(ui->Upload)));
330 Nice_String_Copy(&a->Login, (char *)gtk_entry_get_text (GTK_ENTRY(ui->Login)));
331 Nice_String_Copy(&a->Passwd, (char *)gtk_entry_get_text (GTK_ENTRY(ui->Passwd)));
332
333
334 /* the colors stored in the styles are from 0..65535, and we need them to
335 be from 0..255, so we have to mult by a constant */
336 /* please note that anything to do with colors in this program is completely insane. */
337 style = gtk_widget_get_style(ui->ColorButton1);
338 a->Colors[0] = (int) (style->bg[GTK_STATE_NORMAL].red * (255.0/65535.0) );
339 a->Colors[1] = (int) (style->bg[GTK_STATE_NORMAL].green * (255.0/65535.0) );
340 a->Colors[2] = (int) (style->bg[GTK_STATE_NORMAL].blue * (255.0/65535.0) );
341
342 style = gtk_widget_get_style(ui->ColorButton2);
343 a->Colors[3] = (int) (style->bg[GTK_STATE_NORMAL].red * (255.0/65535.0) );
344 a->Colors[4] = (int) (style->bg[GTK_STATE_NORMAL].green * (255.0/65535.0) );
345 a->Colors[5] = (int) (style->bg[GTK_STATE_NORMAL].blue * (255.0/65535.0) );
346
347 return 1;
348 }
349
350
351 /* converts a NULL string to a "" string, because gtk doesnt like
352 when you set things inside widgets to NULL */
check_str(char * s)353 gchar *check_str(char *s){
354 return (gchar *)((s==NULL)?"":s);
355 }
356
357 /* Fills up the GUI structure using info contained in the Stamp Args Structure */
args_to_ui(struct ArgStruct * a,UI_Struct * ui)358 gint args_to_ui(struct ArgStruct *a, UI_Struct *ui) {
359
360 gdouble colors[3];
361 ui->args = a;
362
363 Nice_String_Copy(&ui->RCFile, a->RCFile);
364
365 gtk_entry_set_text (GTK_ENTRY(ui->Previewfile), check_str(a->Previewfile));
366 gtk_entry_set_text (GTK_ENTRY(ui->Infile), check_str(a->Infile));
367 gtk_entry_set_text (GTK_ENTRY(ui->Outfile), check_str(a->Outfile));
368 gtk_entry_set_text (GTK_ENTRY(ui->UpperString), check_str(a->UpperString));
369 gtk_entry_set_text (GTK_ENTRY(ui->LowerString), check_str(a->LowerString));
370 gtk_entry_set_text (GTK_ENTRY(ui->UpperFont), check_str(a->UpperFont));
371 gtk_entry_set_text (GTK_ENTRY(ui->LowerFont), check_str(a->LowerFont));
372
373
374 GTK_TOGGLE_BUTTON(ui->UStringExec)->active = a->UStringExec;
375 GTK_TOGGLE_BUTTON(ui->LStringExec)->active = a->LStringExec;
376 GTK_TOGGLE_BUTTON(ui->Use3D)->active = a->Use3D;
377 GTK_TOGGLE_BUTTON(ui->Rotate)->active = a->Rotate;
378
379
380 colors[0] = ((gdouble)a->Colors[0])/255.0;
381 colors[1] = ((gdouble)a->Colors[1])/255.0;
382 colors[2] = ((gdouble)a->Colors[2])/255.0;
383 set_color(ui->ColorButton1, colors);
384
385
386 colors[0] = ((gdouble)a->Colors[3])/255.0;
387 colors[1] = ((gdouble)a->Colors[4])/255.0;
388 colors[2] = ((gdouble)a->Colors[5])/255.0;
389 set_color(ui->ColorButton2, colors);
390
391
392 GTK_TOGGLE_BUTTON(ui->UseColors)->active = a->UseColors;
393 gtk_range_get_adjustment(GTK_RANGE(ui->ShadeRate))->value = a->ShadeRate;
394 gtk_range_get_adjustment(GTK_RANGE(ui->Quality))->value = a->Quality ;
395
396 /* FTP Related */
397
398 gtk_entry_set_text (GTK_ENTRY(ui->Host), check_str(a->Host));
399 gtk_entry_set_text (GTK_ENTRY(ui->Path), check_str(a->Path));
400 gtk_entry_set_text (GTK_ENTRY(ui->Upload), check_str(a->Upload));
401 gtk_entry_set_text (GTK_ENTRY(ui->Login), check_str(a->Login));
402 gtk_entry_set_text (GTK_ENTRY(ui->Passwd), check_str(a->Passwd));
403
404 return 1;
405 }
406
407
408
409 /* This is called by the save button callback and sets things
410 up from the gui end to write the config file */
write_config_file(char * filename,UI_Struct * ui)411 void write_config_file(char *filename, UI_Struct *ui){
412 if(ui->RCFile) { free (ui->RCFile); }
413 ui->RCFile = (char *)g_malloc ( sizeof(char) * strlen(filename) + 1);
414 strcpy(ui->RCFile, filename);
415 ui_to_args(ui, ui->args);
416 RC_save(ui->args);
417 }
418
419 /* shows the Yes/No Dialog */
yes_no_show(UI_Struct * ui)420 void yes_no_show(UI_Struct *ui) {
421 gtk_widget_show (ui->yesno->window);
422 gtk_grab_add(ui->yesno->window);
423 }
424
425 /* sets the yes/no title */
yes_no_set_title(UI_Struct * ui,gchar * title)426 void yes_no_set_title(UI_Struct *ui, gchar *title){
427 gtk_window_set_title (GTK_WINDOW(ui->yesno->window), title);
428 }
429
430 /* sets the yes/no question */
yes_no_set_question(UI_Struct * ui,gchar * question)431 void yes_no_set_question(UI_Struct *ui, gchar *question){
432 gtk_label_set (GTK_LABEL(ui->yesno->label), question);
433 }
434
435 /* initializes our yes/no dialog */
make_yes_no_dialog(UI_Struct * ui)436 void make_yes_no_dialog(UI_Struct *ui) {
437 GtkWidget *window;
438 GtkWidget *button;
439 GtkWidget *table;
440 GtkWidget *label;
441 Yes_No_Dialog *yn;
442
443 yn = (Yes_No_Dialog *)g_malloc(sizeof(Yes_No_Dialog));
444
445 window = gtk_window_new(GTK_WINDOW_DIALOG);
446 yn->window = window;
447 gtk_window_position (GTK_WINDOW(yn->window), GTK_WIN_POS_CENTER);
448
449 gtk_signal_connect (GTK_OBJECT (window), "delete_event",
450 GTK_SIGNAL_FUNC (yes_no_delete_event), ui);
451 gtk_container_border_width (GTK_CONTAINER (window), 20);
452
453 table = gtk_table_new (3, 2, TRUE);
454 gtk_container_add (GTK_CONTAINER (window), table);
455 gtk_table_set_row_spacings(GTK_TABLE(table), 2 );
456 button = gtk_button_new_with_label ("Yes");
457 gtk_signal_connect (GTK_OBJECT (button), "clicked",
458 GTK_SIGNAL_FUNC (yes_no_yes_sel), ui);
459 gtk_table_attach_defaults (GTK_TABLE(table), button, 0, 1, 1, 2);
460 gtk_widget_show (button);
461 button = gtk_button_new_with_label ("No");
462 gtk_signal_connect (GTK_OBJECT (button), "clicked",
463 GTK_SIGNAL_FUNC (yes_no_no_sel), ui);
464 gtk_table_attach_defaults (GTK_TABLE(table), button, 1, 2, 1, 2);
465 gtk_widget_show (button);
466 button = gtk_button_new_with_label ("Cancel");
467 gtk_signal_connect (GTK_OBJECT (button), "clicked",
468 GTK_SIGNAL_FUNC (yes_no_cancel_sel), ui);
469 gtk_table_attach_defaults (GTK_TABLE(table), button, 2, 3, 1, 2);
470 gtk_widget_show (button);
471 label = gtk_label_new ("");
472 yn->label = label;
473 gtk_table_attach_defaults(GTK_TABLE(table), label, 0,2,0,1);
474
475 gtk_widget_show(label);
476 gtk_widget_show (table);
477
478 ui->yesno = yn;
479 }
480
481 /* This builds and initilizes the File Dialog, and adds it into the ui structure */
make_file_dialog(UI_Struct * ui)482 void make_file_dialog(UI_Struct *ui){
483 GtkWidget *filew;
484
485 ui->GSTMP_FILE_VISIBLE = FALSE;
486 ui->GSTMP_FILE_BUTTON = 0;
487
488 filew = gtk_file_selection_new ("File selection");
489 gtk_signal_connect (GTK_OBJECT (filew), "destroy",
490 (GtkSignalFunc) file_delete_event, ui);
491 gtk_signal_connect (GTK_OBJECT (filew), "delete_event",
492 (GtkSignalFunc) file_delete_event, ui);
493 /* Connect the ok_button to file_ok_sel function */
494 gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->ok_button),
495 "clicked", (GtkSignalFunc) file_ok_sel, ui );
496 /* Connect the cancel_button to destroy the widget */
497 gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->cancel_button),
498 "clicked", (GtkSignalFunc) file_cancel_sel, ui);
499 ui->filew = filew;
500 }
501
502 /* this changes the color of a widget */
503 /* the color is an array of doubles from 0..1 and they are R G B */
set_color(GtkWidget * w,gdouble color[])504 void set_color(GtkWidget *w, gdouble color[])
505 {
506
507 /* this is insane - ebw */
508
509 GdkColor gdk_color;
510 GdkColormap *colormap;
511 GtkStyle *fgstyle;
512
513 /* get the current colormap of the widget so we can add in the new
514 color and it will be displayed properly */
515 colormap = gtk_widget_get_colormap (w);
516
517 /* the Gtk color selector uses RGB from 0..1 as doubles,
518 the GdkColor object uses RGB from 0..65535, so we have to convert */
519 gdk_color.red = (guint16)(color[0]*65535.0);
520 gdk_color.green = (guint16)(color[1]*65535.0);
521 gdk_color.blue = (guint16)(color[2]*65535.0);
522
523 /* not really sure what this does, but i know we need it. */
524 gdk_color.pixel = (gulong)(gdk_color.red*65536 + gdk_color.green*256 + gdk_color.blue);
525
526 /* Allocate color */
527 gdk_color_alloc (colormap, &gdk_color);
528
529 /* Set window background color */
530 fgstyle = gtk_style_new();
531
532 /* this sets the color for EVERY STATE which may not be what you want
533 if you're reusing this, but it's what i need for my color picker
534 buttons */
535 fgstyle->bg[GTK_STATE_NORMAL] = gdk_color;
536 fgstyle->bg[GTK_STATE_ACTIVE] = gdk_color;
537 fgstyle->bg[GTK_STATE_PRELIGHT] = gdk_color;
538 fgstyle->bg[GTK_STATE_SELECTED] = gdk_color;
539 fgstyle->bg[GTK_STATE_INSENSITIVE] = gdk_color;
540
541 /* add the new style (with the new color we made) into the widget */
542 gtk_widget_set_style(w, fgstyle);
543
544 /* dunno if we need this or not. */
545 gtk_widget_show(w);
546 }
547
548
549 /* this builds the Color Selection Dialog and adds it into the ui */
make_colorsel_dialog(UI_Struct * ui)550 void make_colorsel_dialog(UI_Struct *ui){
551
552 ui->GSTMP_COLOR_VISIBLE = FALSE;
553 ui->GSTMP_CURRENT_COLOR_BUTTON = 0;
554
555 ui->ColorSel = gtk_color_selection_dialog_new("Select a Color");
556 gtk_color_selection_set_update_policy(GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(ui->ColorSel)->colorsel),
557 GTK_UPDATE_CONTINUOUS);
558
559 gtk_signal_connect (GTK_OBJECT (GTK_COLOR_SELECTION_DIALOG (ui->ColorSel)->ok_button),
560 "clicked", (GtkSignalFunc) color_changed, ui );
561
562 gtk_signal_connect (GTK_OBJECT (GTK_COLOR_SELECTION_DIALOG (ui->ColorSel)->cancel_button),
563 "clicked", (GtkSignalFunc) color_cancel_sel, ui );
564
565 gtk_signal_connect (
566 GTK_OBJECT (GTK_COLOR_SELECTION_DIALOG (ui->ColorSel)->colorsel),
567 "color_changed",
568 GTK_SIGNAL_FUNC(color_selection_changed), ui->ColorSel );
569
570 gtk_signal_connect (
571 GTK_OBJECT (GTK_COLOR_SELECTION_DIALOG (ui->ColorSel)),
572 "delete_event",
573 GTK_SIGNAL_FUNC (color_delete_event), ui);
574
575 gtk_widget_hide (GTK_WIDGET(GTK_COLOR_SELECTION_DIALOG(ui->ColorSel)->help_button));
576 }
577
578 /* this builds the Image Preview Dialog and adds it into the ui */
make_preview_dialog(UI_Struct * ui)579 void make_preview_dialog(UI_Struct *ui){
580
581 GtkWidget *window;
582 GtkStyle *style;
583 GtkWidget *gtk_image;
584 GdkImage *gdk_image;
585 GdkColorContext *gcc;
586
587 ui->preview = (Gstmp_Preview *)g_malloc(sizeof (Gstmp_Preview));
588 ui->preview->window = window = gtk_window_new (GTK_WINDOW_DIALOG);
589 gtk_window_position (GTK_WINDOW(window), GTK_WIN_POS_CENTER);
590 gtk_container_border_width (GTK_CONTAINER (window), 20);
591 gtk_window_set_title (GTK_WINDOW(window), "Stamp! Preview");
592
593 ui->preview->vbox = gtk_vbox_new(FALSE, 5);
594 gtk_widget_show (ui->preview->vbox);
595
596 gtk_container_add (GTK_CONTAINER (window), ui->preview->vbox);
597
598 style = ui->preview->style = gtk_widget_get_style(window);
599
600 ui->preview->gdk_image = NULL;
601 ui->preview->gtk_image = NULL;
602 ui->preview->gcc = NULL;
603
604
605 gtk_signal_connect (GTK_OBJECT (window), "delete_event",
606 GTK_SIGNAL_FUNC (preview_delete_event), ui);
607
608
609 }
610
make_message_dialog(UI_Struct * ui)611 void make_message_dialog(UI_Struct *ui){
612 Message_Dialog *m;
613 GtkWidget *window;
614 GtkWidget *label;
615 GtkWidget *button;
616 GtkWidget *vbox;
617 GtkWidget *hbox;
618
619 m = g_malloc(sizeof(Message_Dialog));
620 ui->message = m;
621
622 window = gtk_window_new(GTK_WINDOW_DIALOG);
623 m->window = window;
624 gtk_window_position (GTK_WINDOW(window), GTK_WIN_POS_CENTER);
625 gtk_signal_connect (GTK_OBJECT (window), "delete_event",
626 GTK_SIGNAL_FUNC (message_delete_event), ui);
627 gtk_container_border_width (GTK_CONTAINER (window), 20);
628
629 vbox = gtk_vbox_new(TRUE, 5);
630 gtk_widget_show (vbox);
631 gtk_container_add (GTK_CONTAINER (window), vbox);
632
633 label = gtk_label_new("");
634 m->label = label;
635 gtk_box_pack_start_defaults(GTK_BOX(vbox), label);
636 gtk_widget_show (label);
637
638 hbox = gtk_hbox_new(FALSE, 5);
639 gtk_widget_show (hbox);
640 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, FALSE, 5);
641
642 button = gtk_button_new_with_label ("Ok");
643 gtk_signal_connect (GTK_OBJECT (button), "clicked",
644 GTK_SIGNAL_FUNC (message_ok_sel), ui);
645 gtk_widget_set_usize (button, 50, 0);
646 gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, FALSE, 5);
647 gtk_widget_show (button);
648 m->button = button;
649 }
650
message_set_text(UI_Struct * ui,gchar * t)651 void message_set_text(UI_Struct *ui, gchar *t) {
652 gtk_label_set (GTK_LABEL(ui->message->label), t);
653 }
message_show(UI_Struct * ui)654 void message_show(UI_Struct *ui) {
655 gtk_widget_show(GTK_WIDGET(ui->message->window));
656 gtk_grab_add(GTK_WIDGET(ui->message->window));
657 }
658
659
660
661
662
663
664
665
666
667