1 /*
2 * Chemtool version 1.6.14
3 *
4 * written by Thomas Volk
5 * Jan 1998
6 * extensions and GTK-based rewrite by Martin Kroeker 1999-2007,2010,2011,2013
7 * with contributions by Radek Liboska and Michael Banck
8 * You can use Chemtool under the terms
9 * of the GNU General Public License
10 *
11 * This software comes with ABSOLUTELY NO WARRANTY
12 */
13
14 #ifdef HAVE_CONFIG_H
15 #include <config.h>
16 #endif
17 #include <ctype.h>
18 #include <gdk/gdkx.h>
19 #include "bitmap1.h"
20 #include "templates.h"
21 #include "chemcurs.h"
22 #include "chemtool.xpm"
23 #include <gdk/gdkkeysyms.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #if 0
27 #include <unistd.h> /* memmove*/
28 #endif
29 #include <strings.h>
30 #include <string.h>
31 #include <signal.h>
32 #include <locale.h>
33 #include "ct.h"
34 #ifndef ENABLE_NLS
35 #define _(Text) Text
36 #else
37 #include <libintl.h>
38 #define _(Text) gettext(Text)
39 #endif
40
41
42 GtkWidget *filew;
43 GtkWidget *templates;
44 GtkWidget *messagew, *message;
45 GtkWidget *expw;
46 GtkWidget *mainw;
47 GtkWidget *window;
48 GtkWidget *scrolled_window;
49 GtkWidget *hexbutton, *pent1button, *pent2button, *octbutton, *ltextbutton,
50 *ctextbutton, *rtextbutton, *bondbutton, *movebutton, *markbutton,*colorbutton,
51 *rotatebutton, *hflipbutton, *vflipbutton, *copybutton, *addbutton,
52 *tempbutton, *cleanbutton, *rescalebutton, *splinebutton,*fontbutton,
53 *bgcolorbutton;
54 #if 0
55 GtkWidget *fontsel,*fontselw;
56 #endif
57 GtkWidget *textlabel;
58 GtkStyle *normalfontstyle,*seriffontstyle;
59 GtkWidget *scale, *pscale;
60 GtkWidget *bracketbutton, *rbracketbutton, *r2bracketbutton, *bracebutton, *box1button,
61 *box2button, *box3button, *box4button, *boxbutton;
62 GtkWidget *boxmenu,*penmenu;
63 GtkWidget *drawing_area, *preview_area;
64
65
66 #if (GTK_MINOR_VERSION >2)
67 /* --- Widgets used by the Configurable Options dialog --- */
68
69 GtkWidget *printer_dialog;
70
71 /* Widgets used for layout structure */
72
73 GtkWidget *master_vbox;
74 GtkWidget *notebook;
75 GtkWidget *table;
76
77 /* Widgets that contain data and are accessed from elsewhere */
78
79 GtkWidget *color_button;
80 GtkWidget *printer_name_entry;
81 GtkWidget *print_scale_spin;
82 GtkWidget *datadir_entry;
83 GtkWidget *datamask_entry;
84 GtkWidget *whiteout_check;
85 GtkWidget *intl_check;
86 GtkWidget *paper_size_combo;
87 GtkWidget *orientation_combo;
88 GtkWidget *print_cmd_combo;
89 GtkWidget *eps_preview_combo;
90 GtkWidget *bond_length_entry;
91 GtkWidget *dbond_dist_spin;
92
93 #else
94 GtkWidget *papermenu, *papersizes, *orientmenu, *orientations, *printcmdmenu,
95 *printcmds, *prqueue;
96 GtkWidget *epsoptionmenu,*epsoptions,*whiteoutbutton,*intlbutton;
97 GtkWidget *colorsel;
98 GtkWidget *colorseldialog;
99 GtkWidget *defaultdir, *defaultext,*base_bondlen,*doubledist;
100 #endif
101
102 GtkWidget *bondomenu, *bondmenu, *menuitem;
103 GtkWidget *fontmenu,*fontsizes;
104 GtkWidget *msgtext;
105 GtkWidget *pdbhbox, *labbutton[5],*sdfhbox,*sdflabel,*sdfbutton[3];
106 GtkWidget *babelcmds,*babelcmdmenu;
107 GtkWidget *babelexpcmds,*babelexpmenu;
108 GdkCursor *cursor_pencil, *cursor_text, *cursor_bonds, *cursor_markTLC,
109 *cursor_markBRC, *cursor_move, *cursor_rescale, *cursor_rotate,
110 *cursor_busy;
111 GdkBitmap *source, *mask;
112 GtkWidget *oldpixmap;
113 GdkColor fg = { 0, 0, 0, 0 }; /* Black */
114 GdkColor bg = { 0, 32767, 32767, 65535 }; /* Blue */
115 GdkColor wh = { 0, 65535, 65535, 65535 }; /* White */
116 GdkColor background={0,0xeeee,0x0000,0x0000};
117 #ifdef GTK2
118 GtkTextBuffer *msgtextbuffer;
119 GtkTextIter iter;
120 GtkAdjustment *msgadjustment;
121 #endif
122 char filename[512];
123 char expname[512];
124 static int loadsave = 1;
125 static int expmode = 0;
126 static int curbond = 0;
127 static int ringtype = 0;
128 int newpapersize = 0;
129 int neworientation = 0;
130 int newprintcommand = 0;
131 int newepsoption = 0;
132 int splinepoint = 0;
133 int oldwhiteout = 0;
134 int oldintlchars= 0;
135 int textentry=-1;
136
137 int pendown = 0;
138 int batchmode = 0;
139
140 struct
141 {
142 int x;
143 int y;
144 }
145 spline[4];
146
147 static gint
configure_event(GtkWidget * mainw,GdkEventConfigure * event)148 configure_event (GtkWidget * mainw, GdkEventConfigure * event)
149 /* callback function to create an empty white drawing area on startup */
150 {
151
152 if (picture)
153 gdk_pixmap_unref (picture);
154
155 picture = gdk_pixmap_new (mainw->window,
156 mainw->allocation.width + 100,
157 mainw->allocation.height + 100, -1);
158
159 gdk_draw_rectangle (picture,
160 mainw->style->white_gc,
161 (gint) TRUE, 0, 0,
162 (gint) mainw->allocation.width,
163 (gint) mainw->allocation.height);
164 Display_Mol ();
165 return (gint) TRUE;
166 }
167
168 static gint
configure_preview(GtkWidget * mainw,GdkEventConfigure * event)169 configure_preview (GtkWidget * mainw, GdkEventConfigure * event)
170 /* callback function to create an empty white drawing area on startup */
171 {
172 if (preview) {
173 gdk_pixmap_unref (preview);
174 preview=NULL;
175 }
176 preview = gdk_pixmap_new (mainw->window, 200, 100, -1);
177
178 gdk_draw_rectangle (preview,
179 mainw->style->white_gc,
180 (gint) TRUE, 0, 0, (gint) 200, (gint) 100);
181 return (gint) TRUE;
182 }
183
184 static gint
expose_event(GtkWidget * mainw,GdkEventExpose * event)185 expose_event (GtkWidget * mainw, GdkEventExpose * event)
186 /* callback function to redraw parts of the drawing area */
187 {
188
189 gdk_draw_pixmap (mainw->window,
190 mainw->style->fg_gc[GTK_WIDGET_STATE (mainw)],
191 picture,
192 event->area.x, event->area.y,
193 event->area.x, event->area.y,
194 (gint) event->area.width, (gint) event->area.height);
195 return (gint) FALSE;
196 }
197
198
199 void
yesnodialog(void (* YesFunc)(void))200 yesnodialog (void (*YesFunc) (void))
201 /* Popup to show a warning message when unsaved changes are about to be
202 destroyed by Load or Quit (Modal toplevel dialog) */
203 {
204 GtkWidget *button, *label;
205 GtkWidget *yesno_window;
206
207 yesno_window = gtk_dialog_new ();
208 (void)gtk_signal_connect_object (GTK_OBJECT (yesno_window), "destroy",
209 GTK_SIGNAL_FUNC (gtk_grab_remove),
210 GTK_OBJECT (yesno_window));
211 (void)gtk_signal_connect_object (GTK_OBJECT (yesno_window), "destroy",
212 GTK_SIGNAL_FUNC (gtk_widget_destroy),
213 GTK_OBJECT (yesno_window));
214 gtk_container_border_width (GTK_CONTAINER (yesno_window), 5);
215
216 label =
217 gtk_label_new (_
218 ("The current drawing is not saved !\nDo you really wish to continue ?"));
219
220 gtk_misc_set_padding (GTK_MISC (label), 10, 10);
221
222 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (yesno_window)->vbox), label, TRUE,
223 (gboolean) TRUE, 0);
224 gtk_widget_show (label);
225
226 button = gtk_button_new_with_label (_("Yes"));
227
228 (void)gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
229 GTK_SIGNAL_FUNC (gtk_grab_remove),
230 GTK_OBJECT (yesno_window));
231 (void)gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
232 GTK_SIGNAL_FUNC (YesFunc),
233 GTK_OBJECT (yesno_window));
234 (void)gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
235 GTK_SIGNAL_FUNC (gtk_widget_destroy),
236 GTK_OBJECT (yesno_window));
237 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (yesno_window)->action_area),
238 button, (gboolean) TRUE, (gboolean) TRUE, 0);
239 gtk_widget_show (button);
240
241 button = gtk_button_new_with_label (_("No"));
242
243 (void)gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
244 GTK_SIGNAL_FUNC (gtk_grab_remove),
245 GTK_OBJECT (yesno_window));
246 (void)gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
247 GTK_SIGNAL_FUNC (gtk_widget_destroy),
248 GTK_OBJECT (yesno_window));
249 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (yesno_window)->action_area),
250 button, (gboolean) TRUE, (gboolean) TRUE, 0);
251 gtk_widget_show (button);
252
253 gtk_widget_realize (yesno_window);
254 gtk_grab_add (yesno_window);
255 #ifdef GTK2
256 gtk_window_set_transient_for (GTK_WINDOW (yesno_window),
257 GTK_WINDOW(mainw));
258 #else
259 gtk_window_set_transient_for (GTK_WINDOW (yesno_window),
260 GTK_WINDOW (gtk_widget_get_toplevel
261 (yesno_window)));
262 #endif
263 gtk_window_set_position (GTK_WINDOW (yesno_window), GTK_WIN_POS_MOUSE);
264 gtk_widget_show (yesno_window);
265 }
266
267 void
yesnodialog2(void (* YesFunc)(void),char * somefile)268 yesnodialog2 (void (*YesFunc) (void), char *somefile)
269 /* Popup to show a warning message when unsaved changes are about to be
270 destroyed by Load or Quit (Modal toplevel dialog) */
271 {
272 GtkWidget *button, *label;
273 GtkWidget *yesno_window;
274 char tmpstr[512];
275
276 yesno_window = gtk_dialog_new ();
277 (void)gtk_signal_connect_object (GTK_OBJECT (yesno_window), "destroy",
278 GTK_SIGNAL_FUNC (gtk_grab_remove),
279 GTK_OBJECT (yesno_window));
280 (void)gtk_signal_connect_object (GTK_OBJECT (yesno_window), "destroy",
281 GTK_SIGNAL_FUNC (gtk_widget_destroy),
282 GTK_OBJECT (yesno_window));
283 gtk_container_border_width (GTK_CONTAINER (yesno_window), 5);
284
285 snprintf (tmpstr,512, _("File\n%s\nalready exists !\nOverwrite it ?"), somefile);
286 label = gtk_label_new (tmpstr);
287
288 gtk_misc_set_padding (GTK_MISC (label), 10, 10);
289
290 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (yesno_window)->vbox), label, TRUE,
291 (gboolean) TRUE, 0);
292 gtk_widget_show (label);
293
294 button = gtk_button_new_with_label (_("Yes"));
295
296 (void)gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
297 GTK_SIGNAL_FUNC (gtk_grab_remove),
298 GTK_OBJECT (yesno_window));
299 (void)gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
300 GTK_SIGNAL_FUNC (YesFunc),
301 GTK_OBJECT (yesno_window));
302 (void)gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
303 GTK_SIGNAL_FUNC (gtk_widget_destroy),
304 GTK_OBJECT (yesno_window));
305 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (yesno_window)->action_area),
306 button, (gboolean) TRUE, (gboolean) TRUE, 0);
307 gtk_widget_show (button);
308
309 button = gtk_button_new_with_label (_("No"));
310
311 (void)gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
312 GTK_SIGNAL_FUNC (gtk_grab_remove),
313 GTK_OBJECT (yesno_window));
314 (void)gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
315 GTK_SIGNAL_FUNC (gtk_widget_destroy),
316 GTK_OBJECT (yesno_window));
317 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (yesno_window)->action_area),
318 button, (gboolean) TRUE, (gboolean) TRUE, 0);
319 gtk_widget_show (button);
320
321 gtk_widget_realize (yesno_window);
322 gtk_grab_add (yesno_window);
323 #ifdef GTK2
324 gtk_window_set_transient_for (GTK_WINDOW (yesno_window),
325 GTK_WINDOW(mainw));
326 #else
327 gtk_window_set_transient_for (GTK_WINDOW (yesno_window),
328 GTK_WINDOW (gtk_widget_get_toplevel
329 (yesno_window)));
330 #endif
331 gtk_window_set_position (GTK_WINDOW (yesno_window), GTK_WIN_POS_MOUSE);
332 gtk_widget_show (yesno_window);
333 }
334
335 static gint
button_press_event(GtkWidget * mainw,GdkEventButton * event)336 button_press_event (GtkWidget * mainw, GdkEventButton * event)
337 /* Handle mouse button presses depending on current drawing mode */
338 {
339 int event_x, event_y;
340 int i, spt;
341 char *tmpstr;
342
343 mainw = mainw; /* Avoid gcc unused parameter warning */
344
345 draw_ok= 1; /* valid data, allow drawing */
346 if (event->button == 1 && picture != NULL) /* Button 1 actions: */
347 {
348 event_x = (int) event->x;
349 event_y = (int) event->y;
350
351 switch (drawmode)
352 {
353 case 1:
354 /* Text mode: Insert a label */
355 if (event->state & GDK_CONTROL_MASK)
356 Add_number (event_x, event_y);
357 else
358 Add_atom (event_x, event_y);
359 #ifdef LIBUNDO
360 undo_snapshot ();
361 #endif
362 break;
363 case 0:
364 /* Line mode: show marker boxes around current position */
365 default:
366 Set_vector (event_x, event_y, curbond);
367 break;
368 case 2:
369 /* Bondtype mode: change bond at cursor to current default */
370 Set_bondtype (event_x, event_y, curbond);
371 #ifdef LIBUNDO
372 undo_snapshot ();
373 #endif
374 break;
375 case 3:
376 case 6:
377 case 7:
378 /* Move and rotate modes : initialize operation */
379 Set_pmove (event_x, event_y);
380 break;
381 case 4:
382 /* Mark mode : Set corner of rectangle */
383 gdk_window_set_cursor (drawing_area->window, cursor_markBRC);
384 Set_start_rec (event_x, event_y);
385 break;
386 case 8:
387 spline[splinepoint].x = round_coord (event_x, size_factor);
388 spline[splinepoint].y = round_coord (event_y, size_factor);
389 splinepoint++;
390 modify = 1;
391 if (splinepoint < 4)
392 {
393 for (i = 1; i < splinepoint; i++)
394 gdk_draw_line (picture, mygc[curpen],
395 (gint) (spline[i - 1].x * size_factor),
396 (gint) (spline[i - 1].y * size_factor),
397 (gint) (spline[i].x * size_factor),
398 (gint) (spline[i].y * size_factor));
399 CopyPlane ();
400 }
401 else
402 {
403 spt = 0;
404 if (curbond == 8)
405 spt = 1;
406 if (curbond == 9)
407 spt = 2;
408 if (curbond == 10)
409 spt = -1;
410 if (curbond == 12)
411 spt = -2;
412 add_spline (spline[0].x, spline[0].y, spline[1].x, spline[1].y,
413 spline[2].x, spline[2].y, spline[3].x, spline[3].y,
414 spt, 0, curpen);
415 splinepoint = 0;
416 Display_Mol ();
417 }
418 break;
419 ;;
420 }
421 }
422 if (event->button == 2 && picture != NULL)
423 /* Second (middle) button */
424 {
425 event_x = (int) event->x;
426 event_y = (int) event->y;
427 if (drawmode == 2)
428 {
429 /* in bondtype mode, reverse direction of current bond */
430 Invert_vector (event_x, event_y);
431 #ifdef LIBUNDO
432 undo_snapshot ();
433 #endif
434 }
435 else if (drawmode == 1){
436 if (event->state & GDK_CONTROL_MASK){
437 tmpstr=(char*)gtk_entry_get_text (GTK_ENTRY (textbox));
438 atnum=atoi(tmpstr);
439 if (atnum>0)atnum--;
440 }
441 else
442 Fetch_atom (event_x, event_y);
443 }
444 else
445 {
446 /* in all other modes, set bondtype of current bond to next in list */
447 Add_double (event_x, event_y);
448 #ifdef LIBUNDO
449 undo_snapshot ();
450 #endif
451 }
452 }
453 if (event->button == 3 && picture != NULL)
454 /* Button 3 */
455 {
456 event_x = (int) event->x;
457 event_y = (int) event->y;
458 switch (drawmode)
459 {
460 case 0:
461 /* in line mode, delete bond at cursor */
462 if (event->state & GDK_CONTROL_MASK)
463 Del_rec ();
464 else
465 Del_vector (event_x, event_y);
466 #ifdef LIBUNDO
467 undo_snapshot ();
468 #endif
469 break;
470 case 1:
471 if (event->state & GDK_CONTROL_MASK)
472 atnum=0;
473 else
474 /* in text mode, deletes label at cursor */
475 Del_atom (event_x, event_y);
476 #ifdef LIBUNDO
477 undo_snapshot ();
478 #endif
479 break;
480 case 4:
481 #ifdef LIBUNDO
482 undo_snapshot ();
483 #endif
484 Del_rec ();
485 break;
486 case 3:
487 case 6:
488 /* in move and rotate modes - abort operation */
489 #ifdef LIBUNDO
490 do_undo();
491 #endif
492 break;
493 case 8:
494 /* in spline mode, abort current spline */
495 splinepoint = 0;
496 Display_Mol ();
497 break;
498 default:
499 break;
500 }
501 }
502 return (gint) TRUE;
503 }
504
505 static gint
button_release_event(GtkWidget * mainw,GdkEventButton * event)506 button_release_event (GtkWidget * mainw, GdkEventButton * event)
507 /* completes drawing actions upon release of the mouse button */
508 {
509 int event_x, event_y;
510
511 mainw = mainw; /* Avoid gcc unused parameter warning */
512
513 draw_ok = 0;
514 if (event->button == 1 && picture != NULL)
515 /* release of the first (left) button */
516 {
517 event_x = (int) event->x;
518 event_y = (int) event->y;
519 if (drawmode == 0)
520 {
521 /* in line mode, adds bond from previous to current position */
522 if (event->state & GDK_CONTROL_MASK)
523 {
524 Add_ring (draw_angle, curbond, ringtype);
525 #ifdef GTK2
526 gtk_text_buffer_insert (msgtextbuffer,&iter, "\n", -1);
527 gtk_adjustment_set_value(msgadjustment,gtk_adjustment_get_value(msgadjustment)+12.);
528 #else
529 gtk_text_insert (GTK_TEXT (msgtext), NULL, NULL, NULL, "\n", 1);
530 #endif
531 ringtype = 0;
532 }
533 else
534 Add_vector (curbond); /* add bond, redisplay */
535
536 #ifdef LIBUNDO
537 undo_snapshot ();
538 #endif
539 }
540 else
541 {
542 if (drawmode == 4)
543 {
544 /* in mark mode, defines final position for opposite corner of rectangle */
545 if (event->state & GDK_CONTROL_MASK)
546 {
547 Mark_rec (1);
548 }
549 else
550 {
551 Mark_rec (0);
552 }
553 gdk_window_set_cursor (drawing_area->window, cursor_markTLC);
554 FreePix ();
555 CreatePix ();
556 Display_Mol ();
557 #if 0
558 Movemode(mainw);
559 #endif
560 }
561 #ifdef LIBUNDO
562 if (drawmode > 2)
563 undo_snapshot ();
564 #endif
565 }
566 }
567 return (gint) TRUE;
568 }
569
570
571 static gint
motion_notify_event(GtkWidget * widget,GdkEventMotion * event)572 motion_notify_event (GtkWidget * widget, GdkEventMotion * event)
573 /* handles mouse movement while a button is down */
574 {
575 gint x, y;
576 GdkModifierType state;
577
578 if (event->is_hint != 0)
579 (void) gdk_window_get_pointer (event->window, &x, &y, &state);
580 else
581 {
582 x = (gint) event->x;
583 y = (gint) event->y;
584 state = event->state;
585 }
586
587 if (( (state & GDK_BUTTON1_MASK)|| pendown==1) && picture != NULL)
588 {
589 /* dragging with button 1 (usually left) down */
590 switch (drawmode)
591 {
592 case 0:
593 /* in line mode, draw bond from last to current cursor position */
594 if (draw_ok) Put_vector (x, y);
595 break;
596
597 case 3:
598 /* in move mode, shift marked fragment to current cursor position */
599 if (event->state & GDK_CONTROL_MASK)
600 {
601 Put_pmove (x, y, 1);
602 }
603 else if (event->state & GDK_SHIFT_MASK)
604 {
605 Put_pmove (x, y, 2);
606 }
607 else
608 {
609 Put_pmove (x, y, 0);
610 }
611 break;
612 case 4:
613 /* in mark mode, draw rectangle between initial and current position */
614 if (draw_ok) Put_rec (x, y);
615 break;
616 case 6:
617 /* in rotate mode, rotate marked fragment by an amount proportional to
618 the distance between initial and current cursor position */
619 if (event->state & GDK_CONTROL_MASK)
620 {
621 Put_protate (x, y, 1);
622 }
623 else
624 {
625 Put_protate (x, y, 0);
626 }
627 break;
628 case 7:
629 if (state & GDK_CONTROL_MASK)
630 Put_pscale (x, y, 1);
631 else
632 Put_pscale (x, y, 0);
633 break;
634 default:
635 break;
636 }
637 }
638 return (gint) TRUE;
639 }
640
641
642 static gint
key_press_event(GtkWidget * mainw,GdkEventKey * event)643 key_press_event (GtkWidget * mainw, GdkEventKey * event)
644 /* Handle key presses depending on current drawing mode */
645 {
646 struct dc *hpc;
647 static char label[MAXCL];
648 int direction=0;
649 int dx=0;
650 char errtext[101];
651 int x,y;
652
653 #ifdef GTK2
654 if (gtk_widget_is_focus(textbox)) return FALSE;
655 #endif
656
657 if (event->state & GDK_CONTROL_MASK)
658 {
659 if (!isdigit ((int) event->keyval))
660 return ((gint) FALSE);
661 ringtype = (int) (event->keyval - 48);
662 if (ringtype < 3)
663 ringtype += 10;
664 snprintf (errtext, 100,
665 _("\nNext ring drawn will have %d sides"), ringtype);
666 #ifdef GTK2
667 gtk_text_buffer_insert (msgtextbuffer, &iter, errtext, -1);
668 gtk_adjustment_set_value(msgadjustment, gtk_adjustment_get_value(msgadjustment)+12.);
669 #else
670 gtk_text_insert (GTK_TEXT (msgtext), NULL, NULL, NULL, errtext,
671 (gint) strlen (errtext));
672 #endif
673 return ((gint) TRUE);
674 }
675 if (event->state & GDK_MOD1_MASK) /* ALT+Cursor shifts grid */
676 {
677 if (gridtype == 0) return TRUE; /* nothing to do */
678 switch (event->keyval){
679 case GDK_Left:
680 gridx--;
681 if (gridx<-50) gridx=0;
682 gtk_signal_emit_stop_by_name (GTK_OBJECT(mainw),
683 "key_press_event");
684 break;
685 case GDK_Right:
686 gridx++;
687 if (gridx>50) gridx=0;
688 gtk_signal_emit_stop_by_name (GTK_OBJECT(mainw),
689 "key_press_event");
690 break;
691 case GDK_Up:
692 gridy--;
693 if (gridy<-50) gridy=0;
694 gtk_signal_emit_stop_by_name (GTK_OBJECT(mainw),
695 "key_press_event");
696 break;
697 case GDK_Down:
698 gridy++;
699 if (gridy>50) gridy=0;
700 gtk_signal_emit_stop_by_name (GTK_OBJECT(mainw),
701 "key_press_event");
702 break;
703 default:
704 return (gint) FALSE;
705 }
706 Display_Mol ();
707 return TRUE;
708 }
709 if (drawmode == 0 && picture != NULL) /* Button 1 actions: */
710 {
711 if (textentry >-1){ /* label input in progress */
712 if (event->keyval == GDK_Return) {
713 label[textentry] = '\0';
714 add_char (hp->tx, hp->ty, label, direction, 0, curpen,0,curfontsize);
715 textentry=-1;
716 Display_Mol ();
717 return(TRUE);
718 } else if (isprint((int)event->keyval)) {
719 label[textentry++]=(char)event->keyval;
720 gtk_entry_set_text(GTK_ENTRY(textbox),label);
721 return(TRUE);
722 }
723 if (event->keyval == GDK_BackSpace) {
724 label[--textentry]='\0';
725 gtk_entry_set_text(GTK_ENTRY(textbox),label);
726 }
727 }
728 switch (event->keyval)
729 {
730 case 'c':
731 case 'o':
732 case 'n':
733 case 's':
734 case 'p':
735 case 'h':
736 case 'f':
737 case 'i':
738 case 'r':
739 case 'b':
740 case 'd':
741 direction = Middle_Text;
742 label[0] = toupper ((int) event->keyval);
743 label[1] = '\0';
744 add_char (hp->tx, hp->ty, label, direction, 0,curpen,0,curfontsize);
745 break;
746 case 'l':
747 direction = Left_Text;
748 strcpy (label, "Cl");
749 add_char (hp->tx, hp->ty, label, direction, 0,curpen,0,curfontsize);
750 break;
751 case '1':
752 direction = Left_Text;
753 strcpy (label, "CH");
754 add_char (hp->tx, hp->ty, label, direction, 0, curpen,0,curfontsize);
755 break;
756 case '2':
757 direction = Left_Text;
758 strcpy (label, "CH_2");
759 add_char (hp->tx, hp->ty, label, direction, 0, curpen,0,curfontsize);
760 break;
761 case '3':
762 direction = Left_Text;
763 strcpy (label, "CH_3");
764 add_char (hp->tx, hp->ty, label, direction, 0, curpen,0,curfontsize);
765 break;
766 case '*':
767 direction = Middle_Text;
768 label[0] = '@';
769 label[1] = '\267';
770 label[2] = '\0';
771 add_char (hp->tx, hp->ty, label, direction, 0, curpen,0,curfontsize);
772 break;
773 case '+':
774 direction = Middle_Text;
775 label[0] = '@';
776 label[1] = '+';
777 label[2] = '\0';
778 add_char (hp->tx, hp->ty, label, direction, 0, curpen,0,curfontsize);
779 break;
780 case '-':
781 direction = Middle_Text;
782 label[0] = '@';
783 label[1] = '-';
784 label[2] = '\0';
785 add_char (hp->tx, hp->ty, label, direction, 0, curpen,0,curfontsize);
786 break;
787 case ' ':
788 direction=Left_Text;
789 /* fprintf(stderr,"start label entering\n");*/
790 memset(label,0,25);
791 textentry=0;
792 break;
793
794 case GDK_KP_Left:
795 case GDK_KP_4:
796 hpc=select_char(hp->tx,hp->ty,1);
797 if (hpc ) {
798 dx =3*hpc->direct *(int)strlen(hpc->c);
799 if (event->state & GDK_SHIFT_MASK) {/* dots */
800 add_char (hp->tx-15+dx,hp->ty-4,"@\267",Middle_Text,0,curpen,0,curfontsize);
801 add_char (hp->tx-15+dx,hp->ty+4,"@\267",Middle_Text,0,curpen,0,curfontsize);
802 }else{
803 add_struct(hp->tx-15+dx,hp->ty-12,hp->tx-15+dx,hp->ty+8,0,0,0,1,curpen);
804 }
805 }
806 break;
807 case GDK_KP_Up:
808 case GDK_KP_8:
809 hpc=select_char(hp->tx,hp->ty,1);
810 if (hpc ) {
811 dx =3*hpc->direct *(int)strlen(hpc->c);
812 if (event->state & GDK_SHIFT_MASK) {/* dots */
813 add_char (hp->tx-4+dx,hp->ty-20,"@\267",Middle_Text,0,curpen,0,curfontsize);
814 add_char (hp->tx+8+dx,hp->ty-20,"@\267",Middle_Text,0,curpen,0,curfontsize);
815 }else{
816 add_struct(hp->tx-10+dx,hp->ty-20,hp->tx+10+dx,hp->ty-20,0,0,0,1,curpen);
817 }
818 }
819 break;
820 case GDK_KP_Right:
821 case GDK_KP_6:
822 hpc=select_char(hp->tx,hp->ty,1);
823 if (hpc ) {
824 dx =5 *((int)strlen(hpc->c)-1);
825 if (event->state & GDK_SHIFT_MASK) {/* dots */
826 add_char (hp->tx+13+dx,hp->ty-4,"@\267",Middle_Text,0,curpen,0,curfontsize);
827 add_char (hp->tx+13+dx,hp->ty+4,"@\267",Middle_Text,0,curpen,0,curfontsize);
828 }else{
829 add_struct(hp->tx+15+dx,hp->ty-12,hp->tx+15+dx,hp->ty+8,0,0,0,1,curpen);
830 }
831 }
832 break;
833 case GDK_KP_Down:
834 case GDK_KP_2:
835 hpc=select_char(hp->tx,hp->ty,1);
836 if (hpc ) {
837 dx =3*hpc->direct *(int)strlen(hpc->c);
838 if (event->state & GDK_SHIFT_MASK) {/* dots */
839 add_char (hp->tx-4+dx,hp->ty+15,"@\267",Middle_Text,0,curpen,0,curfontsize);
840 add_char (hp->tx+8+dx,hp->ty+15,"@\267",Middle_Text,0,curpen,0,curfontsize);
841 }else{
842 add_struct(hp->tx-10+dx,hp->ty+15,hp->tx+10+dx,hp->ty+15,0,0,0,1,curpen);
843 }
844 }
845 break;
846 case GDK_KP_Home:
847 case GDK_KP_7:
848 hpc=select_char(hp->tx,hp->ty,1);
849 if (hpc ) {
850 dx =3*hpc->direct *(int)strlen(hpc->c);
851 if (event->state & GDK_SHIFT_MASK) {/* dots */
852 add_char (hp->tx-20+dx,hp->ty-10,"@\267",Middle_Text,0,curpen,0,curfontsize);
853 add_char (hp->tx-5+dx,hp->ty-20,"@\267",Middle_Text,0,curpen,0,curfontsize);
854 }else{
855 add_struct(hp->tx-20+dx,hp->ty-10,hp->tx-5+dx,hp->ty-20,0,0,0,1,curpen);
856 }
857 }
858 break;
859 case GDK_KP_Page_Up:
860 case GDK_KP_9:
861 hpc=select_char(hp->tx,hp->ty,1);
862 if (hpc) {
863 dx =5 *(int)strlen(hpc->c);
864 if (event->state & GDK_SHIFT_MASK) {/* dots */
865 add_char (hp->tx+20+dx,hp->ty-10,"@\267",Middle_Text,0,curpen,0,curfontsize);
866 add_char (hp->tx+5+dx,hp->ty-20,"@\267",Middle_Text,0,curpen,0,curfontsize);
867 }else{
868 add_struct(hp->tx+20+dx,hp->ty-10,hp->tx+5+dx,hp->ty-20,0,0,0,1,curpen);
869 }
870 }
871 break;
872 case GDK_KP_End:
873 case GDK_KP_1:
874 hpc=select_char(hp->tx,hp->ty,1);
875 if (hpc ) {
876 dx =3*hpc->direct *(int)strlen(hpc->c);
877 if (event->state & GDK_SHIFT_MASK) {/* dots */
878 add_char (hp->tx-20+dx,hp->ty+5,"@\267",Middle_Text,0,curpen,0,curfontsize);
879 add_char (hp->tx-5+dx,hp->ty+15,"@\267",Middle_Text,0,curpen,0,curfontsize);
880 }else{
881 add_struct(hp->tx-20+dx,hp->ty+5,hp->tx-5+dx,hp->ty+15,0,0,0,1,curpen);
882 }
883 }
884 break;
885 case GDK_KP_Page_Down:
886 case GDK_KP_3:
887 hpc=select_char(hp->tx,hp->ty,1);
888 if (hpc ) {
889 dx =5 *((int)strlen(hpc->c)-1);
890 if (event->state & GDK_SHIFT_MASK) {/* dots */
891 add_char (hp->tx+20+dx,hp->ty+5,"@\267",Middle_Text,0,curpen,0,curfontsize);
892 add_char (hp->tx+5+dx,hp->ty+15,"@\267",Middle_Text,0,curpen,0,curfontsize);
893 }else{
894 add_struct(hp->tx+20+dx,hp->ty+5,hp->tx+5+dx,hp->ty+15,0,0,0,1,curpen);
895 }
896 }
897 break;
898 case GDK_Left:
899 if (event->state & GDK_SHIFT_MASK){
900 pendown=1;
901 draw_ok=1;
902 XWarpPointer(GDK_DISPLAY(),None,None,0,0,0,0,-1,0);
903 (void)gdk_window_get_pointer(drawing_area->window,&x,&y,NULL);
904 Put_vector(x,y);
905 }else{
906 pendown=0;
907 draw_ok=0;
908 XWarpPointer(GDK_DISPLAY(),None,None,0,0,0,0,-1,0);
909 }
910 gtk_signal_emit_stop_by_name (GTK_OBJECT(mainw),
911 "key_press_event");
912 break;
913 case GDK_Right:
914 if (event->state & GDK_SHIFT_MASK){
915 pendown=1;
916 draw_ok=1;
917 XWarpPointer(GDK_DISPLAY(),None,None,0,0,0,0,1,0);
918 (void)gdk_window_get_pointer(drawing_area->window,&x,&y,NULL);
919 Put_vector(x,y);
920 }else{
921 pendown=0;
922 draw_ok=0;
923 }
924 XWarpPointer(GDK_DISPLAY(),None,None,0,0,0,0,1,0);
925 gtk_signal_emit_stop_by_name (GTK_OBJECT(mainw),
926 "key_press_event");
927 break;
928 case GDK_Up:
929 if (event->state & GDK_SHIFT_MASK){
930 pendown=1;
931 draw_ok=1;
932 XWarpPointer(GDK_DISPLAY(),None,None,0,0,0,0,0,-1);
933 (void)gdk_window_get_pointer(drawing_area->window,&x,&y,NULL);
934 Put_vector(x,y);
935 }else{
936 pendown=0;
937 draw_ok=0;
938 XWarpPointer(GDK_DISPLAY(),None,None,0,0,0,0,0,-1);
939 }
940 gtk_signal_emit_stop_by_name (GTK_OBJECT(mainw),
941 "key_press_event");
942 break;
943 case GDK_Down:
944 if (event->state & GDK_SHIFT_MASK){
945 pendown=1;
946 draw_ok=1;
947 (void)gdk_window_get_pointer(drawing_area->window,&x,&y,NULL);
948 Put_vector(x,y);
949 XWarpPointer(GDK_DISPLAY(),None,None,0,0,0,0,0,1);
950 }
951 else
952 {
953 pendown=0;
954 draw_ok=0;
955 XWarpPointer(GDK_DISPLAY(),None,None,0,0,0,0,0,1);
956 }
957 gtk_signal_emit_stop_by_name (GTK_OBJECT(mainw),
958 "key_press_event");
959 break;
960 case GDK_Return:
961 (void)gdk_window_get_pointer(drawing_area->window,&x,&y,NULL);
962 if (pendown==0){
963 Set_vector(x,y,curbond);
964 }else{
965 draw_ok=1;
966 Add_vector(curbond);
967 pendown=0;
968 Set_vector(x,y,curbond);
969 }
970 break;
971 default:
972 return (gint) FALSE;
973 }
974
975 Display_Mol ();
976
977 #ifdef LIBUNDO
978 undo_snapshot ();
979 #endif
980 }
981 else if (drawmode == 3 && picture != NULL)
982 {
983 switch (event->keyval){
984 case GDK_Left:
985 if (event->state & GDK_SHIFT_MASK)
986 XWarpPointer(GDK_DISPLAY(),None,None,0,0,0,0,-5,0);
987 else
988 XWarpPointer(GDK_DISPLAY(),None,None,0,0,0,0,-1,0);
989 gtk_signal_emit_stop_by_name (GTK_OBJECT(mainw),
990 "key_press_event");
991 (void)gdk_window_get_pointer(drawing_area->window,&x,&y,NULL);
992 Put_pmove(x,y,0);
993 break;
994 case GDK_Right:
995 if (event->state & GDK_SHIFT_MASK)
996 XWarpPointer(GDK_DISPLAY(),None,None,0,0,0,0,5,0);
997 else
998 XWarpPointer(GDK_DISPLAY(),None,None,0,0,0,0,1,0);
999 gtk_signal_emit_stop_by_name (GTK_OBJECT(mainw),
1000 "key_press_event");
1001 (void)gdk_window_get_pointer(drawing_area->window,&x,&y,NULL);
1002 Put_pmove(x,y,0);
1003 break;
1004 case GDK_Up:
1005 if (event->state & GDK_SHIFT_MASK)
1006 XWarpPointer(GDK_DISPLAY(),None,None,0,0,0,0,0,-5);
1007 else
1008 XWarpPointer(GDK_DISPLAY(),None,None,0,0,0,0,0,-1);
1009 gtk_signal_emit_stop_by_name (GTK_OBJECT(mainw),
1010 "key_press_event");
1011 (void)gdk_window_get_pointer(drawing_area->window,&x,&y,NULL);
1012 Put_pmove(x,y,0);
1013 break;
1014 case GDK_Down:
1015 if (event->state & GDK_SHIFT_MASK)
1016 XWarpPointer(GDK_DISPLAY(),None,None,0,0,0,0,0,5);
1017 else
1018 XWarpPointer(GDK_DISPLAY(),None,None,0,0,0,0,0,1);
1019 gtk_signal_emit_stop_by_name (GTK_OBJECT(mainw),
1020 "key_press_event");
1021 (void)gdk_window_get_pointer(drawing_area->window,&x,&y,NULL);
1022 Put_pmove(x,y,0);
1023 break;
1024 case GDK_Return:
1025 Unmark_all();
1026 break;
1027 default:
1028 return (gint) FALSE;
1029 }
1030
1031 Display_Mol ();
1032 }
1033 else if (importflag != 0 && event->keyval == GDK_Return)
1034 {
1035 pdbstore ();
1036 gtk_toggle_button_set_active ((GtkToggleButton *) hexbutton, TRUE);
1037 snprintf (errtext, 100,
1038 _("\nImported %d bonds and %d labels"), hp->n, hp->nc);
1039 #ifdef GTK2
1040 gtk_text_buffer_insert (msgtextbuffer, &iter, errtext, -1);
1041 gtk_adjustment_set_value (msgadjustment, gtk_adjustment_get_value(msgadjustment)+12.);
1042 #else
1043 gtk_text_insert (GTK_TEXT (msgtext), NULL, NULL, NULL, errtext,
1044 (gint) strlen (errtext));
1045 #endif
1046 }
1047
1048
1049 return (gint) TRUE;
1050 }
1051
1052 #ifdef LIBUNDO
1053 void
do_undo()1054 do_undo ()
1055 {
1056 int d;
1057 struct data *hp_b;
1058 struct dc *hp_c;
1059 struct spline *hp_sp;
1060 if (undo_get_undo_count () < 1)
1061 return;
1062
1063 undo_undo ();
1064
1065 if (hp->n > 0)
1066 {
1067 hp_b = da_root.next;
1068 if (hp_b->prev != &da_root)
1069 {
1070 for (d = 0; d < hp->n; d++)
1071 {
1072 hp_b = hp_b->prev;
1073 if (hp_b->prev == &da_root)
1074 {
1075 da_root.next = hp_b;
1076 break;
1077 }
1078 da_root.next = hp_b;
1079 }
1080 }
1081 for (d = 0; d < hp->n; d++)
1082 hp_b = hp_b->next;
1083 new = hp_b;
1084 }
1085 else
1086 {
1087 new = da_root.next;
1088 new->prev = &da_root;
1089 }
1090
1091 if (hp->nc > 0)
1092 {
1093 hp_c = dac_root.next;
1094 if (hp_c->prev != &dac_root)
1095 {
1096 for (d = 0; d < hp->nc; d++)
1097 {
1098 hp_c = hp_c->prev;
1099 if (hp_c->prev == &dac_root)
1100 {
1101 dac_root.next = hp_c;
1102 break;
1103 }
1104 dac_root.next = hp_c;
1105 }
1106 }
1107 for (d = 0; d < hp->nc; d++)
1108 hp_c = hp_c->next;
1109 new_c = hp_c;
1110 }
1111 else
1112 {
1113
1114 new_c = dac_root.next;
1115 new_c->prev = &dac_root;
1116 }
1117
1118 if (hp->nsp > 0)
1119 {
1120 hp_sp = sp_root.next;
1121 if (hp_sp->prev != &sp_root)
1122 {
1123 for (d = 0; d < hp->nsp; d++)
1124 {
1125 hp_sp = hp_sp->prev;
1126 if (hp_sp->prev == &sp_root)
1127 {
1128 sp_root.next = hp_sp;
1129 break;
1130 }
1131 sp_root.next = hp_sp;
1132 }
1133 }
1134 for (d = 0; d < hp->nsp; d++)
1135 hp_sp = hp_sp->next;
1136 sp_new = hp_sp;
1137 }
1138 else
1139 {
1140 sp_new = sp_root.next;
1141 sp_new->prev = &sp_root;
1142 }
1143 FreePix ();
1144 CreatePix ();
1145 Display_Mol ();
1146 }
1147
1148 void
do_redo()1149 do_redo ()
1150 {
1151 int d;
1152 struct data *hp_b;
1153 struct dc *hp_c;
1154 struct spline *hp_sp;
1155
1156 if (undo_get_redo_count () > 0)
1157 undo_redo ();
1158
1159 if (hp->n > 0)
1160 {
1161 hp_b = da_root.next;
1162 if (hp_b->prev != &da_root)
1163 {
1164 for (d = 0; d < hp->n; d++)
1165 {
1166 hp_b = hp_b->prev;
1167 if (hp_b->prev == &da_root)
1168 {
1169 da_root.next = hp_b;
1170 break;
1171 }
1172 da_root.next = hp_b;
1173 }
1174 }
1175 for (d = 0; d < hp->n; d++)
1176 hp_b = hp_b->next;
1177 new = hp_b;
1178 }
1179 else
1180 {
1181 new = da_root.next;
1182 new->prev = &da_root;
1183 }
1184
1185 if (hp->nc > 0)
1186 {
1187 hp_c = dac_root.next;
1188 if (hp_c->prev != &dac_root)
1189 {
1190 for (d = 0; d < hp->nc; d++)
1191 {
1192 hp_c = hp_c->prev;
1193 if (hp_c->prev == &dac_root)
1194 {
1195 dac_root.next = hp_c;
1196 break;
1197 }
1198 dac_root.next = hp_c;
1199 }
1200 }
1201 for (d = 0; d < hp->nc; d++)
1202 hp_c = hp_c->next;
1203 new_c = hp_c;
1204 }
1205 else
1206 {
1207 new_c = dac_root.next;
1208 new_c->prev = &dac_root;
1209 }
1210
1211 if (hp->nsp > 0)
1212 {
1213 hp_sp = sp_root.next;
1214 if (hp_sp->prev != &sp_root)
1215 {
1216 for (d = 0; d < hp->nsp; d++)
1217 {
1218 hp_sp = hp_sp->prev;
1219 if (hp_sp->prev == &sp_root)
1220 {
1221 sp_root.next = hp_sp;
1222 break;
1223 }
1224 sp_root.next = hp_sp;
1225 }
1226 }
1227 for (d = 0; d < hp->nsp; d++)
1228 hp_sp = hp_sp->next;
1229 sp_new = hp_sp;
1230 }
1231 else
1232 {
1233 sp_new = sp_root.next;
1234 sp_new->prev = &sp_root;
1235 }
1236
1237 FreePix ();
1238 CreatePix ();
1239 Display_Mol ();
1240 }
1241 #endif
1242
1243 void
Zoom(GtkWidget * mainw,gpointer inout)1244 Zoom (GtkWidget * mainw, gpointer inout)
1245 /* increase or decrease zoom scale (two steps to either side ) */
1246 {
1247 if (inout && !strcmp ((char *) inout , "1"))
1248 {
1249 if (zoom_factor != 0)
1250 zoom_factor--;
1251 }
1252 else if (!strcmp( (char*)inout ,"0"))
1253 {
1254 if (zoom_factor < 4)
1255 zoom_factor++;
1256 }
1257 if (batchmode==1) return;
1258 gtk_option_menu_set_history(GTK_OPTION_MENU(fontmenu), (guint)zoom_factor+1);
1259 curfontsize=zoom_factor+1;
1260 FreePix ();
1261 CreatePix ();
1262 Display_Mol ();
1263
1264 if (importflag != 0)
1265 pdbrotate (0, 0, 2);
1266 }
1267 void
Grid(GtkWidget * mainw)1268 Grid (GtkWidget * mainw)
1269 /* show or hide grid */
1270 {
1271 if (gridtype < 2)
1272 gridtype ++;
1273 else
1274 gridtype = 0;
1275 FreePix ();
1276 CreatePix ();
1277 Display_Mol ();
1278
1279 if (importflag != 0)
1280 pdbrotate (0, 0, 2);
1281 }
1282
1283 void
change_color(GtkWidget * mainw,gpointer data)1284 change_color (GtkWidget * mainw, gpointer data)
1285 /* update current pencolor and color selection button */
1286 {
1287 GdkPixmap *pixmap;
1288 GtkWidget *pixmapwid;
1289 GtkStyle *style=gtk_widget_get_style (mainw);;
1290
1291 curpen=atoi(data);
1292 pixmap = gdk_pixmap_create_from_xpm_d (mainw->window, &mask,
1293 &style->bg[GTK_STATE_NORMAL],
1294 (gchar **) xpm_color[curpen]);
1295 pixmapwid = gtk_pixmap_new (pixmap, mask);
1296 gtk_widget_show (pixmapwid);
1297 gdk_pixmap_unref (pixmap);
1298 gtk_container_remove (GTK_CONTAINER (colorbutton),oldpixmap);
1299 gtk_container_add (GTK_CONTAINER (colorbutton), pixmapwid);
1300 oldpixmap=pixmapwid;
1301 }
1302
1303 void
CheckAndClear()1304 CheckAndClear ()
1305 /* called by Clear button, pops up an "are you sure" dialog if the current
1306 drawing changed since last save, or calls real Clear function directly */
1307 {
1308 if (modify == 0 || hp->n + hp->nc + hp->nsp == 0)
1309 {
1310 Clear ();
1311 }
1312 else
1313 {
1314 yesnodialog (Clear);
1315 }
1316 }
1317 void
Clear()1318 Clear ()
1319 /* deletes all atoms and bonds from memory and reinitializes drawing area */
1320 {
1321 char msgtmp[100];
1322 clear_data ();
1323 modify = 0;
1324 atnum = 0;
1325 mark.x = 300;
1326 mark.y = 300;
1327 hp->n = 0;
1328 hp->nc = 0;
1329 hp->nsp = 0;
1330 hp->x = 200;
1331 hp->y = 200;
1332 hp->tx = 200;
1333 hp->ty = 200;
1334 if (pdbn)
1335 {
1336 free (pdbx);
1337 free (pdby);
1338 free (pdbz);
1339 free (bondfrom);
1340 free (bondto);
1341 free (bondtype);
1342 bondfrom = NULL;
1343 bondto = NULL;
1344 bondtype = NULL;
1345 pdbx = NULL;
1346 pdby = NULL;
1347 pdbz = NULL;
1348 free (atjust);
1349 atjust = NULL;
1350 free (atcode);
1351 atcode = NULL;
1352 pdbn = 0;
1353 }
1354 importflag = 0;
1355 addflag = 0;
1356 refx=refy=0;
1357 #ifdef LIBUNDO
1358 undo_snapshot ();
1359 new = da_root.next;
1360 new->prev = &da_root;
1361 #endif
1362 strcpy (filename, _("unnamed"));
1363 gtk_window_set_title (GTK_WINDOW (window), "Chemtool 1.6.14");
1364 snprintf(msgtmp,99,_("\nReady"));
1365 #ifdef GTK2
1366 gtk_text_buffer_insert (msgtextbuffer, &iter, msgtmp, -1);
1367 gtk_adjustment_set_value (msgadjustment, gtk_adjustment_get_value (msgadjustment)+12.);
1368 #else
1369 gtk_text_insert (GTK_TEXT (msgtext), NULL, NULL, NULL, msgtmp,
1370 (gint)strlen(msgtmp));
1371 #endif
1372 FreePix ();
1373 CreatePix ();
1374 Display_Mol ();
1375 }
1376
1377 void
do_fw()1378 do_fw ()
1379 {
1380 int error;
1381 char errtext[255];
1382 size_t msglen = 254;
1383
1384 strcpy (formula, "program cht not available or unable to write to");
1385 strcpy (weight, filename);
1386 strcat (weight, ".rad");
1387 strcpy (eweight, " ?");
1388 strcpy (compos, " ?");
1389 error = export_fw (filename);
1390 if (error != 0)
1391 {
1392 snprintf (errtext, msglen, _("\nHelper process failed - %s %s %s %s!"),
1393 formula, weight, eweight, compos);
1394 }
1395 else
1396 {
1397 snprintf (errtext, msglen, _("\n%s %s %s %s"), formula, weight,
1398 eweight, compos);
1399 }
1400 #ifdef GTK2
1401 gtk_text_buffer_insert(msgtextbuffer, &iter, errtext, -1);
1402 gtk_adjustment_set_value(msgadjustment,gtk_adjustment_get_value(msgadjustment)+12.);
1403 #else
1404 gtk_text_insert (GTK_TEXT (msgtext), NULL, NULL, NULL, errtext,
1405 (gint) strlen (errtext));
1406 #endif
1407 }
1408
1409 void
print_ps()1410 print_ps ()
1411 {
1412 char errtext[255];
1413 size_t msglen = 254;
1414
1415 if (hp->n + hp->nc + hp->nsp == 0)
1416 return;
1417 if (print_ps_pic() == 0)
1418 {
1419 snprintf(errtext,msglen,_("\nDrawing printed!"));
1420 }
1421 else
1422 {
1423 snprintf(errtext,msglen,_("\nFailed to print drawing !"));
1424 }
1425 #ifdef GTK2
1426 gtk_text_buffer_insert (msgtextbuffer, &iter, errtext, -1);
1427 gtk_adjustment_set_value (msgadjustment, gtk_adjustment_get_value(msgadjustment)+12.);
1428 #else
1429 gtk_text_insert (GTK_TEXT (msgtext), NULL, NULL, NULL,
1430 errtext,(gint)strlen(errtext));
1431 #endif
1432 }
1433
1434 #if (GTK_MINOR_VERSION >2)
1435 /* ************** Callback for Configurable Options Dialog ************** */
1436
options_dialog_ok(GtkWidget * widget,gpointer data)1437 int options_dialog_ok (GtkWidget *widget, gpointer data) {
1438 int newint;
1439 GdkColor color;
1440
1441 papersize = gtk_combo_box_get_active (GTK_COMBO_BOX (paper_size_combo));
1442 orient = gtk_combo_box_get_active (GTK_COMBO_BOX (orientation_combo));
1443 printcmd = gtk_combo_box_get_active (GTK_COMBO_BOX (print_cmd_combo));
1444 epsoption = gtk_combo_box_get_active (GTK_COMBO_BOX (eps_preview_combo));
1445 use_whiteout = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (whiteout_check));
1446 use_intlchars = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (intl_check));
1447 strcpy (queuename, gtk_entry_get_text (GTK_ENTRY (printer_name_entry)));
1448 printscale =
1449 gtk_spin_button_get_value_as_float (GTK_SPIN_BUTTON (print_scale_spin)) / 100.0;
1450 strcpy (datadir, gtk_entry_get_text (GTK_ENTRY (datadir_entry)));
1451 strcpy (datamask, gtk_entry_get_text (GTK_ENTRY (datamask_entry)));
1452
1453 newint = atof(gtk_entry_get_text (GTK_ENTRY (bond_length_entry)));
1454 if (newint != 0 && newint != bondlen_mm) {
1455 size_factor /= bondlen_mm/10.668;
1456 bondlen_mm = newint;
1457 size_factor *= bondlen_mm/10.668;
1458 }
1459 newint = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (dbond_dist_spin));
1460 if (newint >= 0 && db_dist != newint) {
1461 db_dist = newint;
1462 mb_dist = (int) ( ((float)db_dist) * 2.5);
1463 }
1464
1465 gtk_color_button_get_color (GTK_COLOR_BUTTON (color_button), &color);
1466 gdk_colormap_alloc_color(gdk_colormap_get_system(), &color, FALSE, TRUE);
1467 gdk_gc_set_foreground(background_gc, &color);
1468 gdk_gc_set_background(background_gc, &color);
1469 snprintf(bghexcolor,10,"#%2.2x%2.2x%2.2x",(unsigned char)(color.red/256.),(unsigned char)(color.green/256.),(unsigned char)(color.blue/256.));
1470
1471 FreePix();
1472 CreatePix();
1473 Display_Mol();
1474
1475 gtk_widget_hide (printer_dialog);
1476 return TRUE;
1477 }
1478
prepare_options_dialog()1479 void prepare_options_dialog () {
1480 char msgtmp[100];
1481
1482 gtk_color_button_set_color (GTK_COLOR_BUTTON (color_button), &background);
1483 if (use_whiteout == 1) {
1484 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (whiteout_check), TRUE);
1485 }
1486 else {
1487 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (whiteout_check), FALSE);
1488 }
1489 if (use_intlchars == 1) {
1490 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (intl_check), TRUE);
1491 }
1492 else {
1493 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (intl_check), FALSE);
1494 }
1495
1496 gtk_entry_set_text (GTK_ENTRY (datadir_entry), datadir);
1497 gtk_entry_set_text (GTK_ENTRY (datamask_entry), datamask);
1498 gtk_combo_box_set_active (GTK_COMBO_BOX (eps_preview_combo), epsoption);
1499
1500
1501 snprintf (msgtmp, 100, "%6.4f", bondlen_mm);
1502 gtk_entry_set_text (GTK_ENTRY (bond_length_entry), msgtmp);
1503 gtk_spin_button_set_value (GTK_SPIN_BUTTON (dbond_dist_spin), db_dist);
1504
1505 gtk_combo_box_set_active (GTK_COMBO_BOX (print_cmd_combo), printcmd);
1506 gtk_entry_set_text (GTK_ENTRY (printer_name_entry), queuename);
1507 gtk_combo_box_set_active (GTK_COMBO_BOX (paper_size_combo), papersize);
1508 gtk_combo_box_set_active (GTK_COMBO_BOX (orientation_combo), orient);
1509 gtk_spin_button_set_value (GTK_SPIN_BUTTON (print_scale_spin),
1510 printscale * 100);
1511 }
1512
print_setup_menu_activate(GtkWidget * widget,gpointer data)1513 int print_setup_menu_activate (GtkWidget *widget, gpointer data) {
1514 prepare_options_dialog ();
1515 gtk_widget_show (printer_dialog);
1516 return TRUE;
1517 }
1518
1519 #else
1520 void
setup_printer(GtkWidget * mainw,gpointer change)1521 setup_printer (GtkWidget * mainw, gpointer change)
1522 {
1523 char tmpstr[10];
1524 double bondlen_new;
1525 int doubledist_new;
1526
1527 mainw = mainw; /* Avoid gcc unused parameter warning */
1528
1529 if (atoi (change) == 1)
1530 {
1531 papersize = newpapersize;
1532 orient = neworientation;
1533 printcmd = newprintcommand;
1534 epsoption = newepsoption;
1535 oldwhiteout = use_whiteout;
1536 oldintlchars = use_intlchars;
1537 printscale =
1538 gtk_spin_button_get_value_as_float ((GtkSpinButton *) pscale) / 100.;
1539 queuename = (char*)gtk_entry_get_text (GTK_ENTRY (prqueue));
1540 strcpy (datadir, gtk_entry_get_text (GTK_ENTRY (defaultdir)));
1541 strcpy (datamask, gtk_entry_get_text (GTK_ENTRY (defaultext)));
1542 bondlen_new=atof(gtk_entry_get_text (GTK_ENTRY(base_bondlen)));
1543 if (bondlen_new != 0 && bondlen_mm != bondlen_new){
1544 size_factor /= bondlen_mm/10.668;
1545 bondlen_mm = bondlen_new;
1546 size_factor *= bondlen_mm/10.668;
1547 }
1548 doubledist_new=atoi(gtk_entry_get_text (GTK_ENTRY(doubledist)));
1549 if (doubledist_new >= 0 && db_dist != doubledist_new){
1550 db_dist = doubledist_new;
1551 mb_dist = (int) ( ((float)db_dist) * 2.5);
1552 }
1553 }
1554 else
1555 {
1556 gtk_option_menu_set_history (GTK_OPTION_MENU (papermenu), (guint)papersize);
1557 gtk_option_menu_set_history (GTK_OPTION_MENU (orientmenu), (guint)orient);
1558 gtk_spin_button_set_value ((GtkSpinButton *) pscale, printscale * 100.);
1559 gtk_option_menu_set_history (GTK_OPTION_MENU (epsoptionmenu), (guint)epsoption);
1560 gtk_option_menu_set_history (GTK_OPTION_MENU (printcmdmenu), (guint)printcmd);
1561 gtk_entry_set_text (GTK_ENTRY (prqueue), queuename);
1562 gtk_entry_set_text (GTK_ENTRY (defaultdir), datadir);
1563 gtk_entry_set_text (GTK_ENTRY (defaultext), datamask);
1564 snprintf(tmpstr,10,"%6.4f",bondlen_mm);
1565 gtk_entry_set_text (GTK_ENTRY (base_bondlen),tmpstr);
1566 snprintf(tmpstr,10,"%d",db_dist);
1567 gtk_entry_set_text (GTK_ENTRY (doubledist),tmpstr);
1568 if (oldwhiteout != use_whiteout) {
1569 /* toggle button triggers immediately, and resetting
1570 the button state fires another event, which we use
1571 here to actually reset the value */
1572 if (use_whiteout == 1) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(whiteoutbutton),FALSE);
1573 else
1574 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(whiteoutbutton),TRUE);
1575 }
1576 if (oldintlchars != use_intlchars) {
1577 /* toggle button triggers immediately, and resetting
1578 the button state fires another event, which we use
1579 here to actually reset the value */
1580 if (use_intlchars == 1) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(intlbutton),FALSE);
1581 else
1582 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(intlbutton),TRUE);
1583 }
1584 }
1585 }
1586
1587 int
newpaper(GtkWidget * mainw,gpointer newpaper)1588 newpaper (GtkWidget * mainw, gpointer newpaper)
1589 {
1590 int i;
1591
1592 mainw = mainw; /* Avoid gcc unused parameter warning */
1593
1594 for (i = 0; i < 11; i++)
1595 {
1596 if (!strcmp (newpaper, paper[i]))
1597 {
1598 newpapersize = i;
1599 return TRUE;
1600 }
1601 }
1602 return TRUE;
1603 }
1604
1605 int
neworient(GtkWidget * mainw,gpointer newo)1606 neworient (GtkWidget * mainw, gpointer newo)
1607 {
1608
1609 mainw = mainw; /* Avoid gcc unused parameter warning */
1610 neworientation = atoi (newo);
1611 return TRUE;
1612 }
1613
1614 int
newprcmd(GtkWidget * mainw,gpointer newc)1615 newprcmd (GtkWidget * mainw, gpointer newc)
1616 {
1617
1618 mainw = mainw; /* Avoid gcc unused parameter warning */
1619 newprintcommand = atoi (newc);
1620 return TRUE;
1621 }
1622
1623 int
newepsopt(GtkWidget * mainw,gpointer newo)1624 newepsopt (GtkWidget * mainw, gpointer newo)
1625 {
1626
1627 mainw = mainw; /* Avoid gcc unused parameter warning */
1628 newepsoption = atoi (newo);
1629 return TRUE;
1630 }
1631
1632 int
toggle_whiteout(GtkWidget * mainw,gpointer dummy)1633 toggle_whiteout (GtkWidget *mainw, gpointer dummy)
1634 {
1635
1636 mainw = mainw; /* Avoid gcc unused parameter warning */
1637 if (use_whiteout==0)
1638 use_whiteout=1;
1639 else
1640 use_whiteout=0;
1641 return TRUE;
1642 }
1643
1644 int
toggle_intlchars(GtkWidget * mainw,gpointer dummy)1645 toggle_intlchars (GtkWidget *mainw, gpointer dummy)
1646 {
1647
1648 mainw = mainw; /* Avoid gcc unused parameter warning */
1649 if (use_intlchars==0)
1650 use_intlchars=1;
1651 else
1652 use_intlchars=0;
1653 return TRUE;
1654 }
1655
1656 static void
set_bgcolor(GtkWidget * mainw,GtkColorSelection * colorsel)1657 set_bgcolor (GtkWidget * mainw, GtkColorSelection *colorsel)
1658 /* Handle color data provided by the standard GTK color selector widget */
1659 {
1660 gdouble thecolor[4];
1661
1662 mainw = mainw; /* Avoid gcc unused parameter warning */
1663
1664 gtk_color_selection_get_color(colorsel,thecolor);
1665 bgred=(int)(thecolor[0]*65535);
1666 bggreen=(int)(thecolor[1]*65535);
1667 bgblue=(int)(thecolor[2]*65535);
1668 background.red=(gushort)bgred;
1669 background.green=(gushort)bggreen;
1670 background.blue=(gushort)bgblue;
1671 (void)gdk_color_alloc(gdk_colormap_get_system(),&background);
1672 gdk_gc_set_foreground(background_gc,&background);
1673 gdk_gc_set_background(background_gc,&background);
1674 snprintf(bghexcolor,10,"#%2.2x%2.2x%2.2x",(unsigned char)(bgred/256.),(unsigned char)(bggreen/256.),(unsigned char)(bgblue/256.));
1675 #ifdef GTK2
1676 gtk_label_set_text(GTK_LABEL(GTK_BIN(bgcolorbutton)->child),bghexcolor);
1677 #else
1678 gtk_label_set_text(GTK_LABEL(GTK_BUTTON(bgcolorbutton)->child),bghexcolor);
1679 #endif
1680 FreePix();
1681 CreatePix();
1682 Display_Mol();
1683 }
1684
1685 #endif
1686
1687 static void
set_fontsize(GtkWidget * mainw,gpointer newfont)1688 set_fontsize (GtkWidget *mainw, gpointer newfont)
1689 {
1690
1691 mainw = mainw; /* Avoid gcc unused parameter warning */
1692
1693 curfontsize=GPOINTER_TO_INT(newfont);
1694 }
1695
babelcmd(GtkWidget * mainw,gpointer newc)1696 int babelcmd (GtkWidget *mainw, gpointer newc)
1697 {
1698 /*@ignore@ splint does not recognize strdup */
1699 babel=strdup(newc);
1700 /*@end@*/
1701
1702 mainw = mainw; /* Avoid gcc unused parameter warning */
1703
1704 if (loadsave==7){
1705 char expn[512];
1706 int n,i;
1707
1708 strcpy(expn,filename);
1709 n = (int) strlen (expn);
1710 for (i = 0; i < (int) strlen (expn); i++)
1711 {
1712 if (expn[i] == '.')
1713 n = i;
1714 if (expn[i] == '/')
1715 n = (int) strlen (expn);
1716 }
1717 expn[n] = '\0';
1718 strcat(expn,".");
1719 strcat(expn,babel);
1720 gtk_file_selection_set_filename (GTK_FILE_SELECTION (filew), expn);
1721 }
1722 return TRUE;
1723 }
1724
1725 void
Set_Textmode(GtkWidget * mainw,GdkEvent * the_event)1726 Set_Textmode (GtkWidget * mainw, GdkEvent * the_event)
1727 /* callback to force (left-justified) textmode when the text entry
1728 widget acquires the focus in one of the drawing modes. This is
1729 necessary to prevent interpretation of the typed text as shortcuts */
1730 {
1731
1732 mainw = mainw; /* Avoid gcc unused parameter warning */
1733
1734 if (drawmode != 1)
1735 gtk_toggle_button_set_active ((GtkToggleButton *) ltextbutton,
1736 (gboolean) TRUE);
1737 }
1738
1739 void
Change_Font(GtkWidget * mainw)1740 Change_Font (GtkWidget * mainw)
1741 {
1742
1743 mainw = mainw; /* Avoid gcc unused parameter warning */
1744
1745 if (serif_flag == 0) {
1746 serif_flag=1;
1747 gtk_widget_set_style(GTK_WIDGET(textlabel),seriffontstyle);
1748 }
1749 else
1750 {
1751 serif_flag=0;
1752 gtk_widget_set_style(GTK_WIDGET(textlabel),normalfontstyle);
1753 }
1754 }
1755
1756 void
Change_Text(GtkWidget * mainw,gpointer textdir)1757 Change_Text (GtkWidget * mainw, gpointer textdir)
1758 /* callback function for the (left, centered,right) text buttons,
1759 sets drawmode to text with appropriate justification mode and handles
1760 'radio button' status of the toolbar line - this is rather messy, as
1761 we have to find out which button to deactivate */
1762 {
1763
1764 mainw = mainw; /* Avoid gcc unused parameter warning */
1765
1766 if (importflag != 0)
1767 return;
1768 if (drawmode == 3)
1769 {
1770 gtk_toggle_button_set_active ((GtkToggleButton *) movebutton,
1771 (gboolean) FALSE);
1772 }
1773 if (drawmode == 4)
1774 {
1775 gtk_toggle_button_set_active ((GtkToggleButton *) markbutton,
1776 (gboolean) FALSE);
1777 }
1778 if (drawmode == 6)
1779 {
1780 gtk_toggle_button_set_active ((GtkToggleButton *) rotatebutton,
1781 (gboolean) FALSE);
1782 }
1783 if (drawmode == 7)
1784 {
1785 gtk_toggle_button_set_active ((GtkToggleButton *) rescalebutton,
1786 (gboolean) FALSE);
1787 }
1788 if (drawmode == 8)
1789 {
1790 gtk_toggle_button_set_active ((GtkToggleButton *) splinebutton,
1791 (gboolean) FALSE);
1792 }
1793 if (drawmode == 2)
1794 {
1795 gtk_toggle_button_set_active ((GtkToggleButton *) bondbutton,
1796 (gboolean) FALSE);
1797 }
1798 if (drawmode == 0)
1799 {
1800 switch (draw_angle)
1801 {
1802 case 1:
1803 gtk_toggle_button_set_active ((GtkToggleButton *) hexbutton,
1804 (gboolean) FALSE);
1805 break;
1806 case 2:
1807 gtk_toggle_button_set_active ((GtkToggleButton *) pent1button,
1808 (gboolean) FALSE);
1809 break;
1810 case 3:
1811 gtk_toggle_button_set_active ((GtkToggleButton *) pent2button,
1812 (gboolean) FALSE);
1813 break;
1814 case 4:
1815 gtk_toggle_button_set_active ((GtkToggleButton *) octbutton,
1816 (gboolean) FALSE);
1817 break;
1818 default:
1819 fprintf (stderr, _("invalid angle mode %d\n"), draw_angle);
1820 }
1821 }
1822 if (drawmode == 1)
1823 {
1824 switch (text_direct)
1825 {
1826 case 0:
1827 gtk_toggle_button_set_active ((GtkToggleButton *) ltextbutton,
1828 (gboolean) FALSE);
1829 break;
1830 case -1:
1831 gtk_toggle_button_set_active ((GtkToggleButton *) ctextbutton,
1832 (gboolean) FALSE);
1833 break;
1834 case -2:
1835 gtk_toggle_button_set_active ((GtkToggleButton *) rtextbutton,
1836 (gboolean) FALSE);
1837 break;
1838 default:
1839 fprintf (stderr, _("invalid text mode %d\n"), text_direct);
1840 }
1841 }
1842 drawmode = 1;
1843 text_direct = atoi (textdir);
1844
1845 gdk_window_set_cursor (drawing_area->window, cursor_text);
1846 }
1847
1848 void
set_bond(GtkWidget * mainw,gpointer bondnum)1849 set_bond (GtkWidget * mainw, gpointer bondnum)
1850 {
1851
1852 mainw = mainw; /* Avoid gcc unused parameter warning */
1853
1854 curbond = atoi (bondnum);
1855 }
1856
1857 void
Bondmode(GtkWidget * mainw)1858 Bondmode (GtkWidget * mainw)
1859 /* Callback to enter bondtype changing mode - handles 'radio button'
1860 status of the toolbar after checking which button to deactivate */
1861 {
1862
1863 mainw = mainw; /* Avoid gcc unused parameter warning */
1864
1865 if (importflag != 0)
1866 return;
1867 if (drawmode == 8)
1868 {
1869 gtk_toggle_button_set_active ((GtkToggleButton *) splinebutton,
1870 (gboolean) FALSE);
1871 }
1872 if (drawmode == 7)
1873 {
1874 gtk_toggle_button_set_active ((GtkToggleButton *) rescalebutton,
1875 (gboolean) FALSE);
1876 }
1877 if (drawmode == 6)
1878 {
1879 gtk_toggle_button_set_active ((GtkToggleButton *) rotatebutton,
1880 (gboolean) FALSE);
1881 }
1882 if (drawmode == 3)
1883 {
1884 gtk_toggle_button_set_active ((GtkToggleButton *) movebutton,
1885 (gboolean) FALSE);
1886 }
1887 if (drawmode == 4)
1888 {
1889 gtk_toggle_button_set_active ((GtkToggleButton *) markbutton,
1890 (gboolean) FALSE);
1891 }
1892
1893 if (drawmode == 0)
1894 {
1895 switch (draw_angle)
1896 {
1897 case 1:
1898 gtk_toggle_button_set_active ((GtkToggleButton *) hexbutton,
1899 (gboolean) FALSE);
1900 break;
1901 case 2:
1902 gtk_toggle_button_set_active ((GtkToggleButton *) pent1button,
1903 (gboolean) FALSE);
1904 break;
1905 case 3:
1906 gtk_toggle_button_set_active ((GtkToggleButton *) pent2button,
1907 (gboolean) FALSE);
1908 break;
1909 case 4:
1910 gtk_toggle_button_set_active ((GtkToggleButton *) octbutton,
1911 (gboolean) FALSE);
1912 }
1913 }
1914 if (drawmode == 1)
1915 {
1916 switch (text_direct)
1917 {
1918 case 0:
1919 gtk_toggle_button_set_active ((GtkToggleButton *) ltextbutton,
1920 (gboolean) FALSE);
1921 break;
1922 case -1:
1923 gtk_toggle_button_set_active ((GtkToggleButton *) ctextbutton,
1924 (gboolean) FALSE);
1925 break;
1926 case -2:
1927 gtk_toggle_button_set_active ((GtkToggleButton *) rtextbutton,
1928 (gboolean) FALSE);
1929 }
1930 }
1931 drawmode = 2;
1932 gdk_window_set_cursor (drawing_area->window, cursor_bonds);
1933 }
1934
1935 void
Movemode(GtkWidget * mainw)1936 Movemode (GtkWidget * mainw)
1937 /* Callback function to enter 'move marked fragment' mode - checks and
1938 updates radio button status of the toolbar */
1939 {
1940
1941 mainw = mainw; /* Avoid gcc unused parameter warning */
1942
1943 if (importflag != 0)
1944 return;
1945 if (drawmode == 8)
1946 {
1947 gtk_toggle_button_set_active ((GtkToggleButton *) splinebutton,
1948 (gboolean) FALSE);
1949 }
1950 if (drawmode == 7)
1951 {
1952 gtk_toggle_button_set_active ((GtkToggleButton *) rescalebutton,
1953 (gboolean) FALSE);
1954 }
1955 if (drawmode == 6)
1956 {
1957 gtk_toggle_button_set_active ((GtkToggleButton *) rotatebutton,
1958 (gboolean) FALSE);
1959 }
1960 if (drawmode == 4)
1961 {
1962 gtk_toggle_button_set_active ((GtkToggleButton *) markbutton,
1963 (gboolean) FALSE);
1964 }
1965 if (drawmode == 2)
1966 {
1967 gtk_toggle_button_set_active ((GtkToggleButton *) bondbutton,
1968 (gboolean) FALSE);
1969 }
1970 if (drawmode == 0)
1971 {
1972 switch (draw_angle)
1973 {
1974 case 1:
1975 gtk_toggle_button_set_active ((GtkToggleButton *) hexbutton,
1976 (gboolean) FALSE);
1977 break;
1978 case 2:
1979 gtk_toggle_button_set_active ((GtkToggleButton *) pent1button,
1980 (gboolean) FALSE);
1981 break;
1982 case 3:
1983 gtk_toggle_button_set_active ((GtkToggleButton *) pent2button,
1984 (gboolean) FALSE);
1985 break;
1986 case 4:
1987 gtk_toggle_button_set_active ((GtkToggleButton *) octbutton,
1988 (gboolean) FALSE);
1989 }
1990 }
1991 if (drawmode == 1)
1992 {
1993 switch (text_direct)
1994 {
1995 case 0:
1996 gtk_toggle_button_set_active ((GtkToggleButton *) ltextbutton,
1997 (gboolean) FALSE);
1998 break;
1999 case -1:
2000 gtk_toggle_button_set_active ((GtkToggleButton *) ctextbutton,
2001 (gboolean) FALSE);
2002 break;
2003 case -2:
2004 gtk_toggle_button_set_active ((GtkToggleButton *) rtextbutton,
2005 (gboolean) FALSE);
2006 }
2007 }
2008 drawmode = 3;
2009 gdk_window_set_cursor (drawing_area->window, cursor_move);
2010 Display_Mol ();
2011 }
2012
2013 void
Markmode(GtkWidget * mainw)2014 Markmode (GtkWidget * mainw)
2015 /* Callback function to set 'mark fragment' mode, checks and updates
2016 radio button state of the toolbar */
2017 {
2018
2019 mainw = mainw; /* Avoid gcc unused parameter warning */
2020
2021 if (importflag != 0)
2022 return;
2023
2024 if (drawmode == 8)
2025 {
2026 gtk_toggle_button_set_active ((GtkToggleButton *) splinebutton,
2027 (gboolean) FALSE);
2028 }
2029 if (drawmode == 7)
2030 {
2031 gtk_toggle_button_set_active ((GtkToggleButton *) rescalebutton,
2032 (gboolean) FALSE);
2033 }
2034 if (drawmode == 6)
2035 {
2036 gtk_toggle_button_set_active ((GtkToggleButton *) rotatebutton,
2037 (gboolean) FALSE);
2038 }
2039 if (drawmode == 3)
2040 {
2041 gtk_toggle_button_set_active ((GtkToggleButton *) movebutton,
2042 (gboolean) FALSE);
2043 }
2044 if (drawmode == 2)
2045 {
2046 gtk_toggle_button_set_active ((GtkToggleButton *) bondbutton,
2047 (gboolean) FALSE);
2048 }
2049 if (drawmode == 0)
2050 {
2051 switch (draw_angle)
2052 {
2053 case 1:
2054 gtk_toggle_button_set_active ((GtkToggleButton *) hexbutton,
2055 (gboolean) FALSE);
2056 break;
2057 case 2:
2058 gtk_toggle_button_set_active ((GtkToggleButton *) pent1button,
2059 (gboolean) FALSE);
2060 break;
2061 case 3:
2062 gtk_toggle_button_set_active ((GtkToggleButton *) pent2button,
2063 (gboolean) FALSE);
2064 break;
2065 case 4:
2066 gtk_toggle_button_set_active ((GtkToggleButton *) octbutton,
2067 (gboolean) FALSE);
2068 }
2069 }
2070 if (drawmode == 1)
2071 {
2072 switch (text_direct)
2073 {
2074 case 0:
2075 gtk_toggle_button_set_active ((GtkToggleButton *) ltextbutton,
2076 (gboolean) FALSE);
2077 break;
2078 case -1:
2079 gtk_toggle_button_set_active ((GtkToggleButton *) ctextbutton,
2080 (gboolean) FALSE);
2081 break;
2082 case -2:
2083 gtk_toggle_button_set_active ((GtkToggleButton *) rtextbutton,
2084 (gboolean) FALSE);
2085 }
2086 }
2087 drawmode = 4;
2088 gdk_window_set_cursor (drawing_area->window, cursor_markTLC);
2089 }
2090
2091 void
Rotatemode(GtkWidget * mainw)2092 Rotatemode (GtkWidget * mainw)
2093 /* Callback function to set 'rotate marked fragment' mode - checks and
2094 updates radio button state of the toolbar */
2095 {
2096
2097 mainw = mainw; /* Avoid gcc unused parameter warning */
2098
2099 if (drawmode == 8)
2100 {
2101 gtk_toggle_button_set_active ((GtkToggleButton *) splinebutton,
2102 (gboolean) FALSE);
2103 }
2104 if (drawmode == 7)
2105 {
2106 gtk_toggle_button_set_active ((GtkToggleButton *) rescalebutton,
2107 (gboolean) FALSE);
2108 }
2109 if (drawmode == 3)
2110 {
2111 gtk_toggle_button_set_active ((GtkToggleButton *) movebutton,
2112 (gboolean) FALSE);
2113 }
2114 if (drawmode == 4)
2115 {
2116 gtk_toggle_button_set_active ((GtkToggleButton *) markbutton,
2117 (gboolean) FALSE);
2118 }
2119
2120 if (drawmode == 2)
2121 {
2122 gtk_toggle_button_set_active ((GtkToggleButton *) bondbutton,
2123 (gboolean) FALSE);
2124 }
2125 if (drawmode == 0)
2126 {
2127 switch (draw_angle)
2128 {
2129 case 1:
2130 gtk_toggle_button_set_active ((GtkToggleButton *) hexbutton,
2131 (gboolean) FALSE);
2132 break;
2133 case 2:
2134 gtk_toggle_button_set_active ((GtkToggleButton *) pent1button,
2135 (gboolean) FALSE);
2136 break;
2137 case 3:
2138 gtk_toggle_button_set_active ((GtkToggleButton *) pent2button,
2139 (gboolean) FALSE);
2140 break;
2141 case 4:
2142 gtk_toggle_button_set_active ((GtkToggleButton *) octbutton,
2143 (gboolean) FALSE);
2144 }
2145 }
2146 if (drawmode == 1)
2147 {
2148 switch (text_direct)
2149 {
2150 case 0:
2151 gtk_toggle_button_set_active ((GtkToggleButton *) ltextbutton,
2152 (gboolean) FALSE);
2153 break;
2154 case -1:
2155 gtk_toggle_button_set_active ((GtkToggleButton *) ctextbutton,
2156 (gboolean) FALSE);
2157 break;
2158 case -2:
2159 gtk_toggle_button_set_active ((GtkToggleButton *) rtextbutton,
2160 (gboolean) FALSE);
2161 }
2162 }
2163 drawmode = 6;
2164 gdk_window_set_cursor (drawing_area->window, cursor_rotate);
2165 }
2166
2167 void
Rescalemode(GtkWidget * mainw)2168 Rescalemode (GtkWidget * mainw)
2169 /* Callback function to set 'rescale marked fragment' mode - checks and
2170 updates radio button state of the toolbar */
2171 {
2172
2173 mainw = mainw; /* Avoid gcc unused parameter warning */
2174
2175 if (importflag != 0)
2176 return;
2177 if (drawmode == 8)
2178 {
2179 gtk_toggle_button_set_active ((GtkToggleButton *) splinebutton,
2180 (gboolean) FALSE);
2181 }
2182 if (drawmode == 3)
2183 {
2184 gtk_toggle_button_set_active ((GtkToggleButton *) movebutton,
2185 (gboolean) FALSE);
2186 }
2187 if (drawmode == 4)
2188 {
2189 gtk_toggle_button_set_active ((GtkToggleButton *) markbutton,
2190 (gboolean) FALSE);
2191 }
2192
2193 if (drawmode == 2)
2194 {
2195 gtk_toggle_button_set_active ((GtkToggleButton *) bondbutton,
2196 (gboolean) FALSE);
2197 }
2198
2199 if (drawmode == 6)
2200 {
2201 gtk_toggle_button_set_active ((GtkToggleButton *) rotatebutton,
2202 (gboolean) FALSE);
2203 }
2204
2205 if (drawmode == 0)
2206 {
2207 switch (draw_angle)
2208 {
2209 case 1:
2210 gtk_toggle_button_set_active ((GtkToggleButton *) hexbutton,
2211 (gboolean) FALSE);
2212 break;
2213 case 2:
2214 gtk_toggle_button_set_active ((GtkToggleButton *) pent1button,
2215 (gboolean) FALSE);
2216 break;
2217 case 3:
2218 gtk_toggle_button_set_active ((GtkToggleButton *) pent2button,
2219 (gboolean) FALSE);
2220 break;
2221 case 4:
2222 gtk_toggle_button_set_active ((GtkToggleButton *) octbutton,
2223 (gboolean) FALSE);
2224 }
2225 }
2226 if (drawmode == 1)
2227 {
2228 switch (text_direct)
2229 {
2230 case 0:
2231 gtk_toggle_button_set_active ((GtkToggleButton *) ltextbutton,
2232 (gboolean) FALSE);
2233 break;
2234 case -1:
2235 gtk_toggle_button_set_active ((GtkToggleButton *) ctextbutton,
2236 (gboolean) FALSE);
2237 break;
2238 case -2:
2239 gtk_toggle_button_set_active ((GtkToggleButton *) rtextbutton,
2240 (gboolean) FALSE);
2241 }
2242 }
2243 drawmode = 7;
2244 gdk_window_set_cursor (drawing_area->window, cursor_rescale);
2245 }
2246
2247 void
Splinemode(GtkWidget * mainw)2248 Splinemode (GtkWidget * mainw)
2249 /* Callback function to set 'rescale marked fragment' mode - checks and
2250 updates radio button state of the toolbar */
2251 {
2252
2253 mainw = mainw; /* Avoid gcc unused parameter warning */
2254
2255 if (drawmode == 3)
2256 {
2257 gtk_toggle_button_set_active ((GtkToggleButton *) movebutton,
2258 (gboolean) FALSE);
2259 }
2260 if (drawmode == 4)
2261 {
2262 gtk_toggle_button_set_active ((GtkToggleButton *) markbutton,
2263 (gboolean) FALSE);
2264 }
2265
2266 if (drawmode == 2)
2267 {
2268 gtk_toggle_button_set_active ((GtkToggleButton *) bondbutton,
2269 (gboolean) FALSE);
2270 }
2271
2272 if (drawmode == 6)
2273 {
2274 gtk_toggle_button_set_active ((GtkToggleButton *) rotatebutton,
2275 (gboolean) FALSE);
2276 }
2277
2278 if (drawmode == 0)
2279 {
2280 switch (draw_angle)
2281 {
2282 case 1:
2283 gtk_toggle_button_set_active ((GtkToggleButton *) hexbutton,
2284 (gboolean) FALSE);
2285 break;
2286 case 2:
2287 gtk_toggle_button_set_active ((GtkToggleButton *) pent1button,
2288 (gboolean) FALSE);
2289 break;
2290 case 3:
2291 gtk_toggle_button_set_active ((GtkToggleButton *) pent2button,
2292 (gboolean) FALSE);
2293 break;
2294 case 4:
2295 gtk_toggle_button_set_active ((GtkToggleButton *) octbutton,
2296 (gboolean) FALSE);
2297 }
2298 }
2299 if (drawmode == 1)
2300 {
2301 switch (text_direct)
2302 {
2303 case 0:
2304 gtk_toggle_button_set_active ((GtkToggleButton *) ltextbutton,
2305 (gboolean) FALSE);
2306 break;
2307 case -1:
2308 gtk_toggle_button_set_active ((GtkToggleButton *) ctextbutton,
2309 (gboolean) FALSE);
2310 break;
2311 case -2:
2312 gtk_toggle_button_set_active ((GtkToggleButton *) rtextbutton,
2313 (gboolean) FALSE);
2314 }
2315 }
2316 drawmode = 8;
2317 gdk_window_set_cursor (drawing_area->window, cursor_pencil);
2318 }
2319
2320 void
Change_Angle(GtkWidget * mainw,gpointer newangle)2321 Change_Angle (GtkWidget * mainw, gpointer newangle)
2322 /* Callback function to set 'line drawing' mode and appropriate grid
2323 definition - checks and updates radio button state of the toolbar */
2324 {
2325 gboolean activate = (gboolean) FALSE;
2326
2327 mainw = mainw; /* Avoid gcc unused parameter warning */
2328
2329 if (importflag != 0)
2330 return;
2331 if (drawmode == 3)
2332 {
2333 gtk_toggle_button_set_active ((GtkToggleButton *) movebutton, activate);
2334 }
2335 if (drawmode == 4)
2336 {
2337 gtk_toggle_button_set_active ((GtkToggleButton *) markbutton, activate);
2338 }
2339 if (drawmode == 6)
2340 {
2341 gtk_toggle_button_set_active ((GtkToggleButton *) rotatebutton,
2342 activate);
2343 }
2344 if (drawmode == 7)
2345 {
2346 gtk_toggle_button_set_active ((GtkToggleButton *) rescalebutton,
2347 activate);
2348 }
2349 if (drawmode == 8)
2350 {
2351 gtk_toggle_button_set_active ((GtkToggleButton *) splinebutton,
2352 activate);
2353 }
2354 if (drawmode == 2)
2355 {
2356 gtk_toggle_button_set_active ((GtkToggleButton *) bondbutton, activate);
2357 }
2358 if (drawmode == 1)
2359 {
2360 gtk_toggle_button_set_active ((GtkToggleButton *) ltextbutton,
2361 activate);
2362 gtk_toggle_button_set_active ((GtkToggleButton *) ctextbutton,
2363 activate);
2364 gtk_toggle_button_set_active ((GtkToggleButton *) rtextbutton,
2365 activate);
2366 }
2367
2368 drawmode = 0;
2369 gdk_window_set_cursor (drawing_area->window, cursor_pencil);
2370
2371 switch (draw_angle)
2372 {
2373 case 1:
2374 gtk_toggle_button_set_active ((GtkToggleButton *) hexbutton, activate);
2375 break;
2376 case 2:
2377 gtk_toggle_button_set_active ((GtkToggleButton *) pent1button,
2378 activate);
2379 break;
2380 case 3:
2381 gtk_toggle_button_set_active ((GtkToggleButton *) pent2button,
2382 activate);
2383 break;
2384 case 4:
2385 gtk_toggle_button_set_active ((GtkToggleButton *) octbutton, activate);
2386 }
2387 draw_angle = atoi (newangle);
2388
2389 }
2390
2391 void
CheckAndLoad()2392 CheckAndLoad ()
2393 /* Callback function for 'Load' button - pops up an 'are you sure' dialog
2394 if unsaved changes exist, else calls real load function directly */
2395 {
2396 if (modify == 0 || hp->n + hp->nc + hp->nsp == 0)
2397 {
2398 Load ();
2399 }
2400 else
2401 {
2402 yesnodialog (Load);
2403 }
2404 }
2405
2406 void
Load()2407 Load ()
2408 /* called for loading drawings from file - sets i/o mode to loading and
2409 pops up the file selection widget, making it modal */
2410 {
2411 loadsave = 1;
2412 gtk_window_set_title (GTK_WINDOW (filew), _("Load from file..."));
2413 savedpicture = gdk_pixmap_ref(picture);
2414 if (preview){
2415 gdk_pixmap_unref (preview);
2416 preview=NULL;
2417 }
2418 preview = gdk_pixmap_new (filew->window, 200, 100, -1);
2419
2420 gdk_draw_rectangle (preview,
2421 filew->style->white_gc,
2422 (gint) TRUE, 0, 0, (gint) 200, (gint) 100);
2423
2424 picture = gdk_pixmap_ref(preview);
2425 gtk_widget_show (preview_area);
2426 gtk_widget_hide (pdbhbox);
2427 gtk_widget_hide (sdfhbox);
2428 if (babelin>-1) gtk_widget_hide (babelcmdmenu);
2429 if (babelout>-1) gtk_widget_hide (babelexpmenu);
2430 #ifndef GTK2
2431 strcpy (datadir, gtk_entry_get_text (GTK_ENTRY (defaultdir)));
2432 if (datamask!=NULL && (int)strlen (datamask))
2433 gtk_file_selection_complete (GTK_FILE_SELECTION (filew),
2434 strcat (datadir, datamask));
2435 else
2436 gtk_file_selection_complete (GTK_FILE_SELECTION (filew),
2437 strcat (datadir, "*"));
2438 #endif
2439 gtk_widget_show (filew);
2440 gtk_window_set_modal (GTK_WINDOW (filew), (gboolean) TRUE);
2441 }
2442
2443 void
Import()2444 Import ()
2445 /* called for loading ISIS drawings from file - sets i/o mode to loading and
2446 pops up the file selection widget, making it modal */
2447 {
2448 #if (GTK_MINOR_VERSION >2)
2449 GtkFileFilter *mdlfilter;
2450 #endif
2451 loadsave = 4;
2452 savedpicture = gdk_pixmap_ref(picture);
2453 gtk_window_set_title (GTK_WINDOW (filew), _("Import MDL file..."));
2454 if (preview) {
2455 gdk_pixmap_unref (preview);
2456 preview=NULL;
2457 }
2458 preview = gdk_pixmap_new (filew->window, 200, 100, -1);
2459 gdk_draw_rectangle (preview, filew->style->white_gc,
2460 (gint)TRUE, 0, 0, (gint)200, (gint)100);
2461 picture = gdk_pixmap_ref(preview);
2462 gtk_widget_show (preview_area);
2463 gtk_widget_hide (pdbhbox);
2464 gtk_widget_show (sdfhbox);
2465 if (babelin >-1) gtk_widget_hide (babelcmdmenu);
2466 if (babelout>-1) gtk_widget_hide (babelexpmenu);
2467 #ifndef GTK2
2468 strcpy (datadir, gtk_entry_get_text (GTK_ENTRY (defaultdir)));
2469 #endif
2470 #if (GTK_MINOR_VERSION >2)
2471 mdlfilter = gtk_file_filter_new();
2472 gtk_file_filter_add_pattern(mdlfilter,"*.mol");
2473 gtk_file_filter_add_pattern(mdlfilter,"*.mdl");
2474 gtk_file_filter_add_pattern(mdlfilter,"*.MOL");
2475 gtk_file_filter_add_pattern(mdlfilter,"*.MDL");
2476 gtk_file_filter_add_pattern(mdlfilter,"*.sdf");
2477 gtk_file_filter_add_pattern(mdlfilter,"*.SDF");
2478 #else
2479 gtk_file_selection_complete (GTK_FILE_SELECTION (filew),
2480 strcat (datadir, "*.mol,*.mdl,*.sdf"));
2481 #endif
2482 gtk_widget_show (filew);
2483 gtk_window_set_modal (GTK_WINDOW (filew), (gboolean) TRUE);
2484 }
2485
2486 void
Import_Babel()2487 Import_Babel ()
2488 /* called for BABEL-based import of foreign files - sets i/o mode
2489 and pops up the file selection widget, making it modal */
2490 {
2491 loadsave = 6;
2492 savedpicture = gdk_pixmap_ref(picture);
2493 gtk_window_set_title (GTK_WINDOW (filew), _("Import via BABEL..."));
2494 gtk_widget_hide (preview_area);
2495 gtk_widget_hide (pdbhbox);
2496 gtk_widget_hide (sdfhbox);
2497 gtk_widget_hide (babelexpmenu);
2498 gtk_widget_show (babelcmdmenu);
2499 #ifndef GTK2
2500 strcpy (datadir, gtk_entry_get_text (GTK_ENTRY (defaultdir)));
2501 gtk_file_selection_complete (GTK_FILE_SELECTION (filew),
2502 strcat (datadir, "*"));
2503 #endif
2504 gtk_widget_show (filew);
2505 gtk_window_set_modal (GTK_WINDOW (filew), (gboolean) TRUE);
2506 }
2507
2508 void
Export_Babel()2509 Export_Babel ()
2510 /* called for BABEL-based export of foreign files - sets i/o mode
2511 and pops up the file selection widget, making it modal */
2512 {
2513 loadsave = 7;
2514 savedpicture = gdk_pixmap_ref(picture);
2515 gtk_window_set_title (GTK_WINDOW (filew), _("Export via BABEL..."));
2516 gtk_widget_hide (preview_area);
2517 gtk_widget_hide (pdbhbox);
2518 gtk_widget_hide (sdfhbox);
2519 gtk_widget_hide (babelcmdmenu);
2520 gtk_widget_show (babelexpmenu);
2521 #ifndef GTK2
2522 strcpy (datadir, gtk_entry_get_text (GTK_ENTRY (defaultdir)));
2523 gtk_file_selection_complete (GTK_FILE_SELECTION (filew),
2524 strcat (datadir, "*"));
2525 #endif
2526 gtk_widget_show (filew);
2527 gtk_window_set_modal (GTK_WINDOW (filew), (gboolean) TRUE);
2528 }
2529
2530 void
Import_PDB()2531 Import_PDB ()
2532 /* called for loading drawings from file - sets i/o mode to loading and
2533 pops up the file selection widget, making it modal */
2534 {
2535 loadsave = 5;
2536 savedpicture = gdk_pixmap_ref(picture);
2537 gtk_window_set_title (GTK_WINDOW (filew), _("Import PDB file..."));
2538 gtk_widget_hide (preview_area);
2539 if (babelin >-1) gtk_widget_hide (babelcmdmenu);
2540 if (babelout>-1) gtk_widget_hide (babelexpmenu);
2541 gtk_widget_show (pdbhbox);
2542 gtk_widget_hide (sdfhbox);
2543 #ifndef GTK2
2544 strcpy (datadir, gtk_entry_get_text (GTK_ENTRY (defaultdir)));
2545 gtk_file_selection_complete (GTK_FILE_SELECTION (filew),
2546 strcat (datadir, "*.pdb,*.ent"));
2547 #endif
2548 gtk_widget_show (filew);
2549 gtk_window_set_modal (GTK_WINDOW (filew), (gboolean) TRUE);
2550 }
2551
2552 void
Add()2553 Add ()
2554 /* called for inserting drawings at the currently marked position - sets
2555 i/o mode to adding and pops up the (modal) file selection dialog */
2556 {
2557 if (addflag == 0)
2558 {
2559 refx = hp->tx;
2560 refy = hp->ty;
2561 }
2562
2563 loadsave = 3;
2564 if(picture != NULL)savedpicture = gdk_pixmap_ref(picture);
2565 if (preview != NULL)picture = gdk_pixmap_ref(preview);
2566 if (picture) {
2567 gdk_pixmap_unref (picture);
2568 picture=NULL;
2569 }
2570 picture = gdk_pixmap_new (filew->window, 200, 100, -1);
2571
2572 gdk_draw_rectangle (picture,
2573 filew->style->white_gc,
2574 (gint) TRUE, 0, 0, (gint) 200, (gint) 100);
2575 gtk_widget_show (preview_area);
2576 gtk_widget_hide (pdbhbox);
2577 gtk_widget_hide (sdfhbox);
2578 if (babelin >-1) gtk_widget_hide (babelcmdmenu);
2579 if (babelout>-1) gtk_widget_hide (babelexpmenu);
2580 gtk_window_set_title (GTK_WINDOW (filew), _("Add from file..."));
2581 #ifndef GTK2
2582 strcpy (datadir, gtk_entry_get_text (GTK_ENTRY (defaultdir)));
2583 if (datamask!=NULL && (int)strlen (datamask))
2584 gtk_file_selection_complete (GTK_FILE_SELECTION (filew),
2585 strcat (datadir, datamask));
2586 else
2587 gtk_file_selection_complete (GTK_FILE_SELECTION (filew),
2588 strcat (datadir, "*"));
2589 #endif
2590 gtk_widget_show (filew);
2591 gtk_window_set_modal (GTK_WINDOW (filew), (gboolean) TRUE);
2592 }
2593
2594 void
show_or_raise(GtkWidget * thewidget)2595 show_or_raise (GtkWidget * thewidget)
2596 {
2597 if (!GTK_WIDGET_MAPPED (thewidget))
2598 gtk_widget_show (thewidget);
2599 else
2600 gdk_window_raise (thewidget->window);
2601 }
2602
2603
2604
2605 void
Add_template(GtkWidget * mainw,gpointer template)2606 Add_template (GtkWidget * mainw, gpointer template)
2607 {
2608 int i, j, n;
2609 int xdiff, ydiff;
2610 int x, y, tx, ty, b;
2611 int x1, y1, x2, y2;
2612
2613 if (addflag == 0)
2614 {
2615 refx = hp->tx;
2616 refy = hp->ty;
2617 }
2618 Unmark_all();
2619 xdiff = 0;
2620 ydiff = 0;
2621 xref = 0;
2622 yref = 0;
2623 i = GPOINTER_TO_INT(template) / 10;
2624 j = GPOINTER_TO_INT(template) - i * 10;
2625 if (template_refx[i][j] != 0 && template_refy[i][j]!=0)
2626 {
2627 xdiff = refx - template_refx[i][j];
2628 ydiff = refy - template_refy[i][j];
2629 }
2630 for (n = 0; n < template_nb[i][j]; n++)
2631 {
2632 x = template_x[i][j][n];
2633 y = template_y[i][j][n];
2634 tx = template_tx[i][j][n];
2635 ty = template_ty[i][j][n];
2636 b = template_b[i][j][n];
2637
2638
2639 x = x + xdiff;
2640 y = y + ydiff;
2641 tx = tx + xdiff;
2642 ty = ty + ydiff;
2643 if (GPOINTER_TO_INT(template) <175) /* templates beyond the 4th page are decoration */
2644 add_struct (x, y, tx, ty, b, 1, 1, 0,curpen);
2645 else
2646 add_struct (x, y, tx, ty, b, 1, 1, 1,curpen);
2647 }
2648 for (n = 0; n < template_nl[i][j]; n++)
2649 {
2650 x = template_lx[i][j][n] + xdiff;
2651 y = template_ly[i][j][n] + ydiff;
2652 add_char (x, y, template_lt[i][j][n], template_lo[i][j][n], 1,curpen,0,curfontsize);
2653 }
2654 for (n = 0; n < template_ncrv[i][j]; n++)
2655 {
2656 x = template_crv[i][j][n][0] + xdiff;
2657 y = template_crv[i][j][n][1] + ydiff;
2658 x1 = template_crv[i][j][n][2] + xdiff;
2659 y1 = template_crv[i][j][n][3] + ydiff;
2660 x2 = template_crv[i][j][n][4] + xdiff;
2661 y2 = template_crv[i][j][n][5] + ydiff;
2662 tx = template_crv[i][j][n][6] + xdiff;
2663 ty = template_crv[i][j][n][7] + ydiff;
2664 b = template_crv[i][j][n][8];
2665 add_spline (x, y, x1, y1, x2, y2, tx, ty, b, 1,curpen);
2666 }
2667
2668 #ifdef LIBUNDO
2669 undo_snapshot ();
2670 #endif
2671
2672 mark.flag = 1;
2673 mark.x = refx;
2674 mark.y = refy;
2675 mark.w = 200;
2676 mark.h = 200;
2677
2678 Movemode (mainw);
2679 gtk_toggle_button_set_active ((GtkToggleButton *) movebutton,
2680 (gboolean) TRUE);
2681 CreatePix ();
2682 Display_Mol ();
2683 }
2684
2685 void
SaveAs()2686 SaveAs ()
2687 /* Callback for saving a drawing to file - sets i/o mode to saving and pops
2688 up the (modal) file selection dialog with the current filename as the default */
2689 {
2690 if (hp->n + hp->nc + hp->nsp == 0)
2691 return;
2692 loadsave = 2;
2693 savedpicture = gdk_pixmap_ref(picture);
2694 if (filename != NULL)
2695 gtk_file_selection_set_filename (GTK_FILE_SELECTION (filew), filename);
2696 gtk_window_set_title (GTK_WINDOW (filew), _("Save as..."));
2697 gtk_widget_hide (preview_area);
2698 gtk_widget_hide (pdbhbox);
2699 gtk_widget_hide (sdfhbox);
2700 if (babelin >-1) gtk_widget_hide (babelcmdmenu);
2701 if (babelout>-1) gtk_widget_hide (babelexpmenu);
2702 gtk_widget_show (filew);
2703 gtk_window_set_modal (GTK_WINDOW (filew), (gboolean) TRUE);
2704 }
2705
2706 void
Save()2707 Save ()
2708 /* Callback for saving drawing to file - uses current filename */
2709 {
2710 int error;
2711 char errtext[255];
2712
2713 if (hp->n + hp->nc + hp->nsp == 0)
2714 {
2715 snprintf(errtext,255,_("\nNothing to save") );
2716 #ifdef GTK2
2717 gtk_text_buffer_insert(msgtextbuffer, &iter, errtext, -1);
2718 gtk_adjustment_set_value(msgadjustment, gtk_adjustment_get_value(msgadjustment)+12.);
2719 #else
2720 gtk_text_insert (GTK_TEXT (msgtext), NULL, NULL, NULL, errtext,
2721 (gint) strlen (errtext));
2722 #endif
2723 return;
2724 }
2725
2726 if (strcmp (filename, _("unnamed")) != 0)
2727 {
2728 {
2729 FILE *fp;
2730 if ((fp = fopen (filename, "w")) == NULL)
2731 error = 1;
2732 else
2733 {
2734 error = save_mol (fp, 0);
2735 if (!error)
2736 fclose (fp);
2737 }
2738 }
2739 if (error != 0)
2740 {
2741 snprintf (errtext,255, _("\nWriting to %s failed !"), filename);
2742 }
2743 else
2744 {
2745 snprintf (errtext,255,
2746 _("\nDrawing saved in %s (%d bonds, %d labels)"),
2747 filename, hp->n, hp->nc);
2748 modify = 0;
2749 }
2750 #ifdef GTK2
2751 gtk_text_buffer_insert (msgtextbuffer, &iter, errtext, -1);
2752 gtk_adjustment_set_value (msgadjustment, gtk_adjustment_get_value(msgadjustment)+12.);
2753 #else
2754 gtk_text_insert (GTK_TEXT (msgtext), NULL, NULL, NULL, errtext, (gint) strlen (errtext));
2755 #endif
2756 }
2757 else
2758 SaveAs ();
2759 return;
2760 }
2761
2762 void
Export()2763 Export ()
2764 /* Callback for exporting a drawing to file - pops
2765 up the (modal) file selection dialog with the current filename as the default */
2766 {
2767 char expn[512];
2768 char *exten[10] = { ".fig", ".tex", ".eps", ".xbm", ".svg", ".mol",".emf",".sxd",".png",".asy"};
2769 int i, n;
2770
2771 if (hp->n + hp->nc + hp->nsp == 0)
2772 return;
2773
2774 strcpy (expn, filename);
2775 n = (int) strlen (expn);
2776 for (i = 0; i < (int) strlen (expn); i++)
2777 {
2778 if (expn[i] == '.')
2779 n = i;
2780 if (expn[i] == '/')
2781 n = (int) strlen (expn);
2782 }
2783 expn[n] = '\0';
2784 strcat (expn, exten[expmode]);
2785 gtk_file_selection_set_filename (GTK_FILE_SELECTION (expw), expn);
2786 gtk_widget_show (expw);
2787 gtk_window_set_modal (GTK_WINDOW (filew), (gboolean) TRUE);
2788 }
2789
2790 void
do_export(GtkWidget * mainw,GtkFileSelection * exp)2791 do_export (GtkWidget * mainw, GtkFileSelection * exp)
2792 /* initiates export of current drawing to the foreign format selected via
2793 the export popup - pops down export dialog, calls appropriate function
2794 and displays messagebox with file statistics or error message afterwards */
2795 {
2796 struct stat stbuf;
2797
2798 mainw = mainw; /* Avoid gcc unused parameter warning */
2799
2800 gtk_widget_hide (expw);
2801 if (hp->n + hp->nc + hp->nsp == 0)
2802 return;
2803 strcpy (expname,
2804 gtk_file_selection_get_filename (GTK_FILE_SELECTION (exp)));
2805 if (stat (expname, &stbuf) == 0)
2806 yesnodialog2 (really_export, expname);
2807 else
2808 really_export ();
2809 }
2810
2811 void
really_export()2812 really_export ()
2813 {
2814 size_t msglen = 255;
2815 float expscale;
2816 int error = 0;
2817 char errtext[255];
2818 FILE *fp;
2819
2820 expscale =
2821 gtk_spin_button_get_value_as_int ((GtkSpinButton *) scale) / 100.;
2822
2823 switch (expmode)
2824 {
2825 case 0:
2826 error = export_xfig (expname);
2827 break;
2828 case 1:
2829 error = export_latex_pic (expname, expscale);
2830 break;
2831 case 2:
2832 error = export_ps_pic (expname, expscale);
2833 break;
2834 case 3:
2835 /* xbm output is slow - set 'busy' watch-shaped cursor */
2836 /* gdk_window_set_cursor (drawing_area->window, cursor_busy);*/
2837 /* while (g_main_iteration (FALSE));*/
2838 /* allow gtk to redraw after the popup,
2839 which may have obscured parts of our molecule */
2840 if (mark.flag == 1)
2841 {
2842 xbmflag = 1;
2843 FreePix ();
2844 CreatePix ();
2845 Display_Mol ();
2846 }
2847 error = export_bitmap (expname);
2848 if (mark.flag == 1)
2849 {
2850 xbmflag = 0;
2851 FreePix ();
2852 CreatePix ();
2853 Display_Mol ();
2854 }
2855 /* gdk_window_set_cursor (drawing_area->window, previous_cursor);*/
2856 break;
2857 case 4:
2858 error = export_svg (expname);
2859 break;
2860 case 5:
2861 if (!(fp = fopen (expname,"w"))) {
2862 error = 1;
2863 break;
2864 }
2865 error = export_mdl_mol (fp,0);
2866 break;
2867 case 6:
2868 #ifdef EMF
2869 error = export_emf (expname);
2870 #else
2871 if (figversion >= 3) error = export_emf (expname);
2872 #endif
2873 break;
2874 case 7:
2875 error = export_sxd (expname);
2876 break;
2877 case 8:
2878 error = export_png_pic (expname, expscale);
2879 break;
2880 case 9:
2881 error = export_asy (expname);
2882 break;
2883 }
2884 if (error != 0)
2885 {
2886 snprintf (errtext, msglen, _("Writing to\n %s\nfailed !\n"), expname);
2887 gtk_label_set_text (GTK_LABEL (message), errtext);
2888 gtk_widget_show (messagew);
2889 gtk_grab_add (messagew);
2890 }
2891 else
2892 {
2893 snprintf (errtext, msglen,
2894 _("\nDrawing exported as %s (%d bonds, %d labels)"),
2895 expname, hp->n, hp->nc);
2896 #ifdef GTK2
2897 gtk_text_buffer_insert (msgtextbuffer, &iter, errtext, -1);
2898 gtk_adjustment_set_value (msgadjustment, gtk_adjustment_get_value(msgadjustment)+12.);
2899 #else
2900 gtk_text_insert (GTK_TEXT (msgtext), NULL, NULL, NULL, errtext,
2901 (gint) strlen (errtext));
2902 #endif
2903 }
2904 }
2905
2906 void
exp_mode(GtkWidget * mainw,gpointer mode)2907 exp_mode (GtkWidget * mainw, gpointer mode)
2908 /* callback function to set export format selected in the export dialog */
2909 {
2910 char expn[255];
2911 char *exten[10] = { ".fig", ".tex", ".eps", ".xbm", ".svg", ".mol", ".emf", ".sxd", ".png", ".asy" };
2912 int i, n;
2913
2914 mainw = mainw; /* Avoid gcc unused parameter warning */
2915
2916 strcpy (expn, gtk_file_selection_get_filename (GTK_FILE_SELECTION (expw)));
2917 n = (int) strlen (expn);
2918 for (i = 0; i < (int) strlen (expn); i++)
2919 {
2920 if (expn[i] == '.')
2921 n = i;
2922 if (expn[i] == '/')
2923 n = (int) strlen (expn);
2924 }
2925 expn[n] = '\0';
2926 expmode = atoi (mode);
2927 if (expmode < 0 || expmode > 9)
2928 expmode = 0;
2929 strcat (expn, exten[expmode]);
2930
2931 gtk_file_selection_set_filename (GTK_FILE_SELECTION (expw), expn);
2932 }
2933
2934 void
pdb_mode(GtkWidget * mainw,gpointer mode)2935 pdb_mode (GtkWidget * mainw, gpointer mode)
2936 /* callback function to set pdb label handling */
2937 {
2938 mainw = mainw; /* Avoid gcc unused parameter warning */
2939
2940 pdbmode = atoi (mode);
2941 if (pdbmode < 0 || pdbmode > 4)
2942 pdbmode = 0;
2943 }
2944
2945 void
sdf_mode(GtkWidget * mainw,gpointer mode)2946 sdf_mode (GtkWidget * mainw, gpointer mode)
2947 /* callback function to set current sdf index and update preview */
2948 {
2949 char myfile[255];
2950 char labeltext[40];
2951
2952 mainw = mainw; /* Avoid gcc unused parameter warning */
2953
2954 switch ( atoi (mode)) {
2955 case 0:
2956 default:
2957 sdfindex=0;
2958 break;
2959 case 1:
2960 sdfindex--;
2961 if (sdfindex <0 ) sdfindex = 0;
2962 break;
2963 case 2:
2964 sdfindex++;
2965 break;
2966 }
2967 if (picture) {
2968 gdk_pixmap_unref (picture);
2969 picture = NULL;
2970 }
2971 picture = gdk_pixmap_new (filew->window, 200, 100, -1);
2972 gdk_draw_rectangle (picture, filew->style->white_gc,
2973 (gint)TRUE, 0, 0, (gint)200, (gint)100);
2974 strcpy (myfile,
2975 gtk_file_selection_get_filename (GTK_FILE_SELECTION(filew)));
2976 preview_mdl_mol (myfile, sdfindex);
2977 snprintf (labeltext,39,_("SDF entry: %d"),sdfindex+1);
2978 gtk_label_set_text(GTK_LABEL(sdflabel),labeltext);
2979 }
2980
2981 int
CheckAndQuit()2982 CheckAndQuit ()
2983 /* Callback function for the Quit button - pops up an 'are you sure' dialog
2984 if unsaved changes exist, or calls the real quit function directly */
2985 {
2986 if (modify == 0 || hp->n + hp->nc + hp->nsp == 0)
2987 {
2988 Quit ();
2989 return ((int) FALSE);
2990 }
2991 else
2992 {
2993 yesnodialog (Quit);
2994 return ((int) TRUE);
2995 }
2996 }
2997
2998 void
Quit()2999 Quit ()
3000 /* close down gtk function processing and terminate program */
3001 {
3002 gtk_main_quit ();
3003 }
3004
3005 void
file_ok_sel(GtkWidget * mainw,GtkFileSelection * fs)3006 file_ok_sel (GtkWidget * mainw, GtkFileSelection * fs)
3007 /* callback function for the Ok button of the file selection dialog - pops
3008 down the file dialog, gets the name of the selected file, initiates load
3009 or save operations as defined by the current i/o mode and displays error
3010 message dialog if necessary */
3011 {
3012 int error;
3013 char errtext[255];
3014 char oldname[512];
3015 char *tempstr;
3016 struct stat stbuf;
3017
3018 gtk_widget_hide (filew);
3019 gtk_grab_remove (filew);
3020 picture = gdk_pixmap_ref(savedpicture);
3021 strcpy (oldname, filename);
3022 strcpy (filename,
3023 gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs)));
3024 if (datadir == NULL || (int)strlen (datadir) == 0)
3025 {
3026 tempstr = strrchr (filename, '/');
3027 strncpy (datadir, filename, strlen (filename) - strlen (tempstr) + 1);
3028 #if (GTK_MINOR_VERSION >2)
3029 gtk_entry_set_text (GTK_ENTRY (datadir_entry), datadir);
3030 #else
3031 gtk_entry_set_text (GTK_ENTRY (defaultdir), datadir);
3032 #endif
3033 }
3034 switch (loadsave)
3035 {
3036 case 1:
3037 error = load_mol (filename);
3038 switch (error)
3039 {
3040 case 0:
3041 modify = 0;
3042 mark.flag = 0;
3043 snprintf (errtext,255, "Chemtool %s (%s)", VERSION, filename);
3044 gtk_window_set_title (GTK_WINDOW (window), errtext);
3045 #ifdef LIBUNDO
3046 undo_snapshot ();
3047 #endif
3048 break;
3049 case 1:
3050 snprintf (errtext,255, _("Unable to open %s\n"), filename);
3051 strcpy (filename, oldname);
3052 gtk_label_set_text (GTK_LABEL (message), errtext);
3053 gtk_widget_show (messagew);
3054 gtk_grab_add (messagew);
3055 break;
3056 case 2:
3057 snprintf (errtext,255, _("%s\n does not appear to be a Chemtool file\n"),
3058 filename);
3059 strcpy (filename, oldname);
3060 gtk_label_set_text (GTK_LABEL (message), errtext);
3061 gtk_widget_show (messagew);
3062 gtk_grab_add (messagew);
3063 break;
3064 case 3:
3065 modify = 0;
3066 snprintf (errtext,255,
3067 _("%s was created by a newer version.\nSome features may be lost.\n"),
3068 filename);
3069 gtk_label_set_text (GTK_LABEL (message), errtext);
3070 gtk_widget_show (messagew);
3071 gtk_grab_add (messagew);
3072 snprintf (errtext,255, "Chemtool %s (%s)", VERSION, filename);
3073 gtk_window_set_title (GTK_WINDOW (window), errtext);
3074 #ifdef LIBUNDO
3075 undo_snapshot ();
3076 #endif
3077 break;
3078 default:
3079 clear_data ();
3080 snprintf (errtext,255, _("Error loading %s \n"), filename);
3081 gtk_label_set_text (GTK_LABEL (message), errtext);
3082 gtk_widget_show (messagew);
3083 gtk_grab_add (messagew);
3084 }
3085 CreatePix ();
3086 Display_Mol ();
3087 break;
3088 case 2:
3089 if (datamask!=NULL && (int)strlen (datamask)) {
3090 tempstr = strrchr (filename,'.');
3091 if (!tempstr || strcmp(tempstr,datamask)) {
3092 strcat (filename,".");
3093 strcat (filename,datamask);
3094 }
3095 }
3096 if (stat (filename, &stbuf) == 0)
3097 yesnodialog2 (reallysave, filename);
3098 else
3099 reallysave ();
3100 break;
3101 case 3:
3102 error = add_mol (filename);
3103 strcpy (filename, oldname);
3104 Movemode (mainw);
3105 gtk_toggle_button_set_active ((GtkToggleButton *) movebutton,
3106 (gboolean) TRUE);
3107 CreatePix ();
3108 Display_Mol ();
3109 break;
3110 case 4:
3111 error = import_mdl_mol (filename,sdfindex);
3112 switch (error)
3113 {
3114 case 0:
3115 modify = 0;
3116 if (strrchr (filename, '.')
3117 && strrchr (filename, '.') > strrchr (filename, '/'))
3118 filename[(int) (strrchr (filename, '.') - filename)] = '\0';
3119 snprintf (errtext,255, "Chemtool %s (%s)", VERSION, filename);
3120 gtk_window_set_title (GTK_WINDOW (window), errtext);
3121 #ifdef LIBUNDO
3122 undo_snapshot ();
3123 #endif
3124
3125 snprintf (errtext,255,
3126 _("\nChoose orientation (Ctrl-Mouse1 for z), press Enter when done"));
3127 #ifdef GTK2
3128 gtk_text_buffer_insert (msgtextbuffer, &iter, errtext, -1);
3129 gtk_adjustment_set_value(msgadjustment, gtk_adjustment_get_value(msgadjustment)+12.);
3130 #else
3131 gtk_text_insert (GTK_TEXT (msgtext), NULL, NULL, NULL, errtext,
3132 (gint)strlen (errtext));
3133 #endif
3134 gtk_toggle_button_set_active ((GtkToggleButton *) rotatebutton,
3135 TRUE);
3136 break;
3137 case 1:
3138 snprintf (errtext,255, _("Unable to open %s\n"), filename);
3139 strcpy (filename, oldname);
3140 gtk_label_set_text (GTK_LABEL (message), errtext);
3141 gtk_widget_show (messagew);
3142 gtk_grab_add (messagew);
3143 break;
3144 case 2:
3145 snprintf (errtext,255, _("Problems converting %s\n"), filename);
3146 gtk_label_set_text (GTK_LABEL (message), errtext);
3147 gtk_widget_show (messagew);
3148 gtk_grab_add (messagew);
3149 break;
3150 }
3151 break;
3152 case 5:
3153 error = import_pdb (filename);
3154 switch (error)
3155 {
3156 case 0:
3157 modify = 0;
3158 if (strrchr (filename, '.')
3159 && strrchr (filename, '.') > strrchr (filename, '/'))
3160 filename[(int) (strrchr (filename, '.') - filename)] = '\0';
3161 snprintf (errtext, 255, "Chemtool %s (%s)", VERSION, filename);
3162 gtk_window_set_title (GTK_WINDOW (window), errtext);
3163 #ifdef LIBUNDO
3164 undo_snapshot ();
3165 #endif
3166 snprintf (errtext,255,
3167 _("\nChoose orientation (Ctrl-Mouse1 for z), press Enter when done"));
3168 #ifdef GTK2
3169 gtk_text_buffer_insert (msgtextbuffer, &iter, errtext, -1);
3170 gtk_adjustment_set_value(msgadjustment, gtk_adjustment_get_value(msgadjustment)+12.);
3171 #else
3172 gtk_text_insert (GTK_TEXT (msgtext), NULL, NULL, NULL, errtext,
3173 (gint)strlen (errtext));
3174 #endif
3175 gtk_toggle_button_set_active ((GtkToggleButton *) rotatebutton,
3176 TRUE);
3177 break;
3178 case 1:
3179 snprintf (errtext,255, _("Unable to open %s\n"), filename);
3180 strcpy (filename, oldname);
3181 gtk_label_set_text (GTK_LABEL (message), errtext);
3182 gtk_widget_show (messagew);
3183 gtk_grab_add (messagew);
3184 break;
3185 }
3186 break;
3187 case 6:
3188 error = import_babel (filename);
3189 switch (error)
3190 {
3191 case 0:
3192 modify = 0;
3193 if (strrchr (filename, '.')
3194 && strrchr (filename, '.') > strrchr (filename, '/'))
3195 filename[(int) (strrchr (filename, '.') - filename)] = '\0';
3196 snprintf (errtext,255, "Chemtool %s (%s)", VERSION, filename);
3197 gtk_window_set_title (GTK_WINDOW (window), errtext);
3198 #ifdef LIBUNDO
3199 undo_snapshot ();
3200 #endif
3201
3202 snprintf (errtext,255,
3203 _
3204 ("\nChoose orientation (Ctrl-Mouse1 for z), press Enter when done"));
3205 #ifdef GTK2
3206 gtk_text_buffer_insert (msgtextbuffer, &iter, errtext, -1);
3207 gtk_adjustment_set_value(msgadjustment, gtk_adjustment_get_value(msgadjustment)+12.);
3208 #else
3209 gtk_text_insert (GTK_TEXT (msgtext), NULL, NULL, NULL, errtext,
3210 (gint)strlen (errtext));
3211 #endif
3212 gtk_toggle_button_set_active ((GtkToggleButton *) rotatebutton,
3213 TRUE);
3214 break;
3215 case 1:
3216 snprintf (errtext,255, _("Unable to open %s\n"), filename);
3217 strcpy (filename, oldname);
3218 gtk_label_set_text (GTK_LABEL (message), errtext);
3219 gtk_widget_show (messagew);
3220 gtk_grab_add (messagew);
3221 break;
3222 case 2:
3223 snprintf (errtext,255, _("Problems converting %s\n"), filename);
3224 gtk_label_set_text (GTK_LABEL (message), errtext);
3225 gtk_widget_show (messagew);
3226 gtk_grab_add (messagew);
3227 break;
3228 }
3229 break;
3230 case 7:
3231 error = export_babel(filename);
3232 default:
3233 break;
3234 }
3235 }
3236
3237 void
reallysave()3238 reallysave ()
3239 {
3240 int error;
3241 char errtext[255];
3242 FILE *fp;
3243
3244 if ((fp = fopen (filename, "w")) == NULL)
3245 error = 1;
3246 else
3247 {
3248 error = save_mol (fp, 0);
3249 if (!error)
3250 fclose (fp);
3251 }
3252 if (error != 0)
3253 {
3254 snprintf (errtext,255, _("Writing to\n %s\nfailed !\n"), filename);
3255 }
3256 else
3257 {
3258 snprintf (errtext,255,
3259 _("Drawing saved in\n %s\n (%d bonds, %d labels)\n"),
3260 filename, hp->n, hp->nc);
3261 modify = 0;
3262 }
3263 gtk_label_set_text (GTK_LABEL (message), errtext);
3264 gtk_widget_show (messagew);
3265 gtk_grab_add (messagew);
3266 snprintf (errtext,255, "Chemtool %s (%s)", VERSION, filename);
3267 gtk_window_set_title (GTK_WINDOW (window), errtext);
3268 }
3269
3270 int
main(int argc,char ** argv)3271 main (int argc, char **argv)
3272 /* Main program - initializes widgets and data structures */
3273 {
3274 int i, j;
3275 int tmplnum[125];
3276 int error;
3277 char bondnums[BONDTYPES][3];
3278 char bondcolors [BONDCOLORS][4];
3279 char msgtmp[100];
3280 const char *fontsizelabel[7]={"8","10","12","14","17","20","24"};
3281 GtkWidget *aboutw,*helpw,*helptext;
3282 GtkWidget *vbox;
3283 GtkWidget *hbox;
3284 GtkWidget *button;
3285 GtkWidget *expbutton[10];
3286 GtkWidget *tbutton[125];
3287 #ifdef MENU
3288 GtkAccelGroup *accel_group;
3289 GtkWidget *menu_bar;
3290 GtkWidget *file, *file_menu;
3291 GtkWidget *new, *open, *add, *import, *imppdb, *impany,*export, *expany,
3292 *printps, *save, *saveas, *quit;
3293 GtkWidget *edit, *edit_menu;
3294 GtkWidget *print_setup, *save_setup;
3295 GtkWidget *copy, *fliph, *flipv;
3296 #ifdef LIBUNDO
3297 GtkWidget *undo, *redo;
3298 #endif
3299 GtkWidget *view, *view_menu;
3300 GtkWidget *zoomin, *zoomout, *center,*grid;
3301 GtkWidget *tools, *tools_menu;
3302 GtkWidget *templatem, *cht, *clean;
3303 GtkWidget *help, *help_menu;
3304 GtkWidget *about,*using;
3305 #else
3306 GtkWidget *loadbutton, *savebutton, *importbutton, *imppdbbutton,
3307 *exportbutton, *printbutton, *zoominbutton;
3308 GtkWidget *psetupbutton, *savesetupbutton;
3309 GtkWidget *centerbutton, *zoomoutbutton, *clearbutton, *fwbutton,
3310 *quitbutton, *aboutbutton;
3311 #endif
3312 GtkWidget *label;
3313 GdkPixmap *pixmap;
3314 GtkWidget *pixmapwid;
3315 GtkAdjustment *adj_scale;
3316 GSList *group;
3317 GtkStyle *style;
3318 GtkTooltips *tooltips, *temptips;
3319 GtkWidget *templatebook, *page, *tvbox, *pbox;
3320 GtkWidget *vscroll,*textscroll;
3321 #if (GTK_MINOR_VERSION <4)
3322 GtkAdjustment *adj_pscale;
3323 GtkWidget *printer_dialog, *papersizeitem[11], *orientationitem,
3324 *printcmditem;
3325 GtkWidget *epsoptitem;
3326 GtkWidget *pokbutton, *pcabutton;
3327 #endif
3328 GtkWidget *fontsizeitem[7];
3329 GtkWidget *babelcmditem,*babelexpcmditem;
3330 GdkColor black={0,0x0000,0x0000,0x0000},blue={0,0x0000,0x0000,0xe000},
3331 green={0,0x0000,0xd000,0x0000},cyan={0,0,0xffff,0xffff},
3332 red={0,0xffff,0x0000,0x0000},magenta={0,0xffff,0x0000,0xffff},
3333 yellow={0,0xffff,0xffff,0x0000},white={0,0xffff,0xffff,0xffff};
3334 #ifdef GTK2
3335 GtkTextBuffer *helptextbuffer;
3336 GtkTextIter ht_iter;
3337 #endif
3338
3339 char *helpmessage = _("Click and drag the mouse to draw bonds on the canvas. \n"
3340 "The right mouse button is used to delete objects - either bonds\n"
3341 "or text depending on which drawing mode is active.\n\n"
3342 "The buttons with different ringtypes on them select drawing modes\n"
3343 "with preferred angles, but you can actually draw at any angle in all modes.\n\n"
3344 "The button with the segmented line on it lets you draw curves by marking\n"
3345 "control points along the curve (a cubic spline).\n"
3346 "You can select the bondtype and color using the appropriate button\n"
3347 "or change them later by clicking on the desired bond in Bonds mode.\n\n"
3348 "To draw a cyclic system, simply press the Ctrl key together with the\n"
3349 "number key corresponding to the number of sides for the polygon, and\n"
3350 "then draw one side while pressing the Ctrl button.\n\n"
3351 "For drawing labels, write them into the text box in the top right of the window\n"
3352 "and place them on the canvas with the mouse. You can also use a number of\n"
3353 "keyboard shortcuts for common labels while in bond drawing mode:\n"
3354 "Simply press the 'c' key, or n,o,p,s,f to add the element symbol at\n"
3355 " the current drawing position, 1,2 and 3 for CH, CH_2 and CH_3, l for Cl,\n"
3356 " * for a big dot.\n\n"
3357 "The keys of the numeric keypad each insert an 'electron pair' line\n"
3358 "around an atom symbol in the position corresponding to the location\n"
3359 "of the key around the center of the numeric keypad.\n\n"
3360 "The text mode uses the following prefixes for special text:\n"
3361 "_ for subscripts, ^ for superscripts, @ for symbols (greek characters),\n"
3362 "| for italic (slanted) characters and # for bold text.\n"
3363 "When the text box is empty, clicking on any label in the drawing area\n"
3364 "copies that label into the box for reuse.\n\n"
3365 "Drawing is best done with the mouse, but you can also use the\n"
3366 "cursor keys in combination with the Ctrl key for exact positioning.\n"
3367 "When used with the Alt key, the cursor keys move the rectangular\n"
3368 "or rhombic grid that can be projected on the drawing area.\n\n"
3369 "If you need general drawing functions not provided by chemtool,\n"
3370 "try exporting to fig format and editing your figure in Brian Smith's\n"
3371 "xfig program. Its companion transfig/fig2dev is required by chemtool\n"
3372 "for printing and for exporting to eps or LaTeX, while the fig, XBM and\n"
3373 "SVG output are generated directly. Another useful and highly recommended\n"
3374 "helper program is Babel - either in its original version, or in the form\n"
3375 "of the new OpenBabel project. Using either version, chemtool is able to\n"
3376 "import foreign data from a variety of file formats, while only molfile\n"
3377 "im- and export is built into chemtool.\n\n"
3378 "More help is available in the manual page for chemtool and in the file\n"
3379 " README included in the source distribution as well as on the website.\n"
3380 "This should normally get installed in /usr/share/doc/packages/chemtool.\n"
3381 "If you find any bugs or have a question or suggestion, please contact the\n"
3382 "main author, martin@ruby.chemie.uni-freiburg.de");
3383 #ifdef ENABLE_NLS
3384 (void) gtk_set_locale (); /* newer glibc requires this */
3385 /* but we have to guard against locales that use a comma in numbers */
3386 (void) setlocale (LC_NUMERIC, "C");
3387 /*@ignore@*/
3388 (void) bindtextdomain ("chemtool", LOCALEDIR);
3389 /*@end@*/
3390
3391 #ifdef GTK2
3392 bind_textdomain_codeset ("chemtool", "UTF-8");
3393 (void) setlocale (LC_NUMERIC, "C");
3394 #endif
3395
3396 (void) textdomain ("chemtool");
3397 #endif
3398
3399 #ifdef LIBUNDO
3400 undo_new ("chemtool");
3401 undo_set_memory_limit (65536);
3402 #endif
3403 setup_data (); /*initialize chemtool structs */
3404 #ifdef LIBUNDO
3405 undo_snapshot ();
3406 #endif
3407
3408 check_fig2dev ();
3409 check_fig2sxd();
3410
3411 if ( (strstr(argv[0],"chemtoolbg") && argc <3) || (argc==2 && !strcmp(argv[1],"-bg"))) {
3412 fprintf(stderr,"Usage: chemtoolbg [outtype] [infile]\n");
3413 fprintf(stderr," available outtypes: fig tex eps xbm svg mol emf sxd png asy\n");
3414 fprintf(stderr," Use \"-\" instead of infile in pipes, e.g. someprogram|chemtoolbg svg -\n\n");
3415 exit (1);
3416 }
3417 if (strstr(argv[0],"chemtoolbg") || (argc>1 && !strcmp(argv[1],"-bg"))) {
3418 char *mode[10] = { "fig", "tex", "eps", "xbm", "svg", "mol","emf","sxd","png","asy"};
3419 int shift=0;
3420 static int k;
3421 if (!strcmp(argv[1],"-bg")) shift = 1;
3422 batchmode = 1;
3423 mark.flag = False;
3424 head.width = 2000;
3425 head.height = 5000;
3426 zoom_factor = 2;
3427 size_factor = 0.8;
3428 pdbx = pdby = pdbz = NULL;
3429 atcode = NULL;
3430 atjust = bondtype = NULL;
3431 bondfrom = bondto = NULL;
3432 hp->x = hp->y = 200;
3433 hp->tx = hp->ty = 200;
3434 tmpx=(int*)NULL;
3435 tmpy=(int*)NULL;
3436 gridtype=0;
3437 gridx=gridy = 0;
3438 atnum = 0;
3439 queuename = malloc (33 * sizeof (char));
3440 bgred=bgblue=bggreen=65535;
3441 readrc();
3442 Load_Font();
3443 k=2+shift;
3444 if (k>=argc) exit(1);
3445 strcpy (filename, argv[k]);
3446 load_mol(filename);
3447 head.pix_width = 1600;
3448 head.pix_height = 1600;
3449
3450 strcpy(expname,filename);
3451 if (!strcmp(expname,"-"))
3452 strcpy(expname,"chemtool");
3453 fprintf(stderr,"chemtoolbg %s...\n",expname);
3454 char *dot=strrchr(expname,'.');
3455 if (dot) *dot='\0';
3456 j=-1;
3457 k=1+shift;
3458 if (k>=argc) exit(1);
3459 fprintf(stderr,"chemtoolbg mode %s...\n",argv[k]);
3460 for (i=0;i<10;i++) {
3461 if (!strcmp(mode[i],argv[k])) {
3462 j=i;
3463 break;
3464 }
3465 }
3466 if (j<0) exit(1);
3467 strcat (expname,".");
3468 strcat (expname, mode[j]);
3469 fprintf(stderr,"chemtoolbg %s...\n",expname);
3470 gtk_init (&argc, &argv); /*initialize GTK environment */
3471 switch(j) {
3472 case 0:
3473 drawing_area = gtk_drawing_area_new ();
3474 gtk_drawing_area_size (GTK_DRAWING_AREA (drawing_area), 1600, 1600);
3475 export_xfig(expname);
3476 break;
3477 case 1:
3478 drawing_area = gtk_drawing_area_new ();
3479 gtk_drawing_area_size (GTK_DRAWING_AREA (drawing_area), 1600, 1600);
3480 export_latex_pic(expname,1.);
3481 break;
3482 case 2:
3483 drawing_area = gtk_drawing_area_new ();
3484 gtk_drawing_area_size (GTK_DRAWING_AREA (drawing_area), 1600, 1600);
3485 snprintf(bghexcolor,10,"#%2.2x%2.2x%2.2x",(unsigned char)(bgred/256.),(unsigned char)(bggreen/256.),(unsigned char)(bgblue/256.));
3486 export_ps_pic(expname,1.);
3487 break;
3488 case 3:
3489 break;
3490 case 4:
3491 snprintf(bghexcolor,10,"#%2.2x%2.2x%2.2x",(unsigned char)(bgred/256.),(unsigned char)(bggreen/256.),(unsigned char)(bgblue/256.));
3492 export_svg(expname);
3493 break;
3494 case 5:
3495 break;
3496 case 6:
3497 #ifndef EMF
3498 drawing_area = gtk_drawing_area_new ();
3499 gtk_drawing_area_size (GTK_DRAWING_AREA (drawing_area), 1600, 1600);
3500 if (figversion>=3)
3501 #endif
3502 export_emf(expname);
3503 break;
3504 case 7:
3505 drawing_area = gtk_drawing_area_new ();
3506 gtk_drawing_area_size (GTK_DRAWING_AREA (drawing_area), 1600, 1600);
3507 if (have_fig2sxd) export_sxd(expname);
3508 break;
3509 case 8:
3510 drawing_area = gtk_drawing_area_new ();
3511 gtk_drawing_area_size (GTK_DRAWING_AREA (drawing_area), 1600, 1600);
3512 snprintf(bghexcolor,10,"#%2.2x%2.2x%2.2x",(unsigned char)(bgred/256.),(unsigned char)(bggreen/256.),(unsigned char)(bgblue/256.));
3513 export_png_pic(expname,1.);
3514 break;
3515 case 9:
3516 drawing_area = gtk_drawing_area_new ();
3517 gtk_drawing_area_size (GTK_DRAWING_AREA (drawing_area), 1600, 1600);
3518 snprintf(bghexcolor,10,"#%2.2x%2.2x%2.2x",(unsigned char)(bgred/256.),(unsigned char)(bggreen/256.),(unsigned char)(bgblue/256.));
3519 export_asy(expname);
3520 break;
3521 default:
3522 break;
3523 }
3524 exit(0);
3525 }
3526
3527 gtk_init (&argc, &argv); /*initialize GTK environment */
3528
3529
3530 /*
3531 * Create the 'About' pop-up
3532 */
3533 aboutw = gtk_dialog_new ();
3534 label =
3535 gtk_label_new (_
3536 (" Chemtool Version 1.6.14\nby\nMartin Kroeker,\nRadek Liboska,\nMichael Banck\nand\nThomas Volk\n\nhttp://ruby.chemie.uni-freiburg.de/~martin/chemtool/chemtool.html"));
3537 #ifdef GTK2
3538 gtk_label_set_justify(GTK_LABEL(label),GTK_JUSTIFY_CENTER);
3539 #endif
3540 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (aboutw)->vbox), label,
3541 (gboolean) TRUE, (gboolean) TRUE, 0);
3542 gtk_widget_show (label);
3543 button = gtk_button_new_with_label ("Ok");
3544 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (aboutw)->action_area), button,
3545 (gboolean) TRUE, (gboolean) TRUE, 0);
3546 (void)gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
3547 GTK_SIGNAL_FUNC (gtk_widget_hide),
3548 GTK_OBJECT (aboutw));
3549 (void)gtk_signal_connect_object (GTK_OBJECT (aboutw), "delete_event",
3550 GTK_SIGNAL_FUNC (gtk_widget_hide),
3551 GTK_OBJECT (aboutw));
3552 gtk_widget_show (button);
3553
3554
3555 helpw = gtk_dialog_new();
3556 gtk_widget_set_usize(helpw,480,500);
3557 textscroll=gtk_scrolled_window_new(NULL,NULL);
3558 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(textscroll),
3559 GTK_POLICY_NEVER,GTK_POLICY_ALWAYS);
3560 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (helpw)->vbox), textscroll,
3561 (gboolean) TRUE, (gboolean) TRUE, 0);
3562 #ifdef GTK2
3563 helptext = gtk_text_view_new();
3564 gtk_text_view_set_editable(GTK_TEXT_VIEW(helptext), FALSE);
3565 helptextbuffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW(helptext));
3566 gtk_text_buffer_get_iter_at_offset (helptextbuffer, &ht_iter, 0);
3567 #ifndef ENABLE_NLS
3568 gtk_text_buffer_insert (helptextbuffer, &ht_iter, helpmessage,-1);
3569 #else
3570 gtk_text_buffer_insert (helptextbuffer, &ht_iter, gettext(helpmessage),-1);
3571 #endif
3572 #else
3573 helptext = gtk_text_new(NULL,NULL);
3574 gtk_text_set_editable(GTK_TEXT(helptext), FALSE);
3575 gtk_text_freeze(GTK_TEXT(helptext));
3576 #ifndef ENABLE_NLS
3577 gtk_text_insert(GTK_TEXT(helptext),NULL,NULL,NULL,helpmessage,(gint)strlen(helpmessage));
3578 #else
3579 gtk_text_insert(GTK_TEXT(helptext),NULL,NULL,NULL,gettext(helpmessage),(gint)strlen(gettext(helpmessage)));
3580 #endif
3581 #endif
3582 gtk_widget_show(textscroll);
3583 gtk_container_add(GTK_CONTAINER(textscroll),helptext);
3584 button = gtk_button_new_with_label ("Ok");
3585 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (helpw)->action_area), button,
3586 (gboolean) TRUE, (gboolean) TRUE, 0);
3587 (void)gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
3588 GTK_SIGNAL_FUNC (gtk_widget_hide),
3589 GTK_OBJECT (helpw));
3590 (void)gtk_signal_connect_object (GTK_OBJECT (helpw), "delete_event",
3591 GTK_SIGNAL_FUNC (gtk_widget_hide),
3592 GTK_OBJECT (helpw));
3593 gtk_widget_show (button);
3594 gtk_widget_show (helptext);
3595 gtk_widget_realize(helpw);
3596 /*
3597 * Build the file selection pop-up
3598 */
3599
3600
3601 filew = gtk_file_selection_new ("File selection");
3602 (void)gtk_signal_connect (GTK_OBJECT (filew), "delete_event",
3603 (GtkSignalFunc) gtk_grab_remove, GTK_OBJECT (filew));
3604 (void)gtk_signal_connect (GTK_OBJECT (filew), "delete_event",
3605 (GtkSignalFunc) gtk_widget_hide, GTK_OBJECT (filew));
3606 (void)gtk_signal_connect (GTK_OBJECT (filew), "delete_event",
3607 restore_picture, NULL);
3608 (void)gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->ok_button),
3609 "clicked", (GtkSignalFunc) file_ok_sel, filew);
3610
3611 (void)gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION
3612 (filew)->cancel_button),
3613 "clicked", (GtkSignalFunc) gtk_grab_remove,
3614 GTK_OBJECT (filew));
3615 (void)gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION
3616 (filew)->cancel_button),
3617 "clicked", restore_picture, NULL);
3618
3619 (void)gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION
3620 (filew)->cancel_button),
3621 "clicked", (GtkSignalFunc) gtk_widget_hide,
3622 GTK_OBJECT (filew));
3623 #ifdef GTK2
3624 (void)gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->file_list),
3625 "cursor_changed", (GtkSignalFunc) getpreview,
3626 (gpointer) filew);
3627 #else
3628 (void)gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (filew)->file_list),
3629 "select_row", (GtkSignalFunc) getpreview,
3630 (gpointer) filew);
3631 #endif
3632
3633
3634
3635 preview_area = gtk_drawing_area_new ();
3636 gtk_drawing_area_size (GTK_DRAWING_AREA (preview_area), 200, 100);
3637 gtk_box_pack_start (GTK_BOX (GTK_FILE_SELECTION (filew)->action_area),
3638 preview_area, (gboolean) TRUE, (gboolean) FALSE, 0);
3639
3640 gtk_widget_show (preview_area);
3641
3642 /* Signals used to handle backing pixmap */
3643
3644 (void)gtk_signal_connect (GTK_OBJECT (preview_area), "expose_event",
3645 (GtkSignalFunc) expose_event, NULL);
3646 (void)gtk_signal_connect (GTK_OBJECT (preview_area), "configure_event",
3647 (GtkSignalFunc) configure_preview, NULL);
3648
3649 pdbhbox = gtk_hbox_new ((gboolean) FALSE, 0);
3650 label = gtk_label_new (_("PDB labels:"));
3651 gtk_widget_show (label);
3652 gtk_box_pack_start (GTK_BOX (pdbhbox), label, TRUE, TRUE, 0);
3653 labbutton[0] = gtk_radio_button_new_with_label (NULL, _("All"));
3654 gtk_box_pack_start (GTK_BOX (pdbhbox), labbutton[0], (gboolean) TRUE,
3655 (gboolean) TRUE, 0);
3656 (void)gtk_signal_connect (GTK_OBJECT (labbutton[0]), "clicked",
3657 GTK_SIGNAL_FUNC (pdb_mode), "0");
3658
3659 gtk_widget_show (labbutton[0]);
3660 group = gtk_radio_button_group (GTK_RADIO_BUTTON (labbutton[0]));
3661 labbutton[1] = gtk_radio_button_new_with_label (group, _("non-H"));
3662 gtk_box_pack_start (GTK_BOX (pdbhbox), labbutton[1], (gboolean) TRUE,
3663 (gboolean) TRUE, 0);
3664 (void)gtk_signal_connect (GTK_OBJECT (labbutton[1]), "clicked",
3665 GTK_SIGNAL_FUNC (pdb_mode), "1");
3666 gtk_widget_show (labbutton[1]);
3667 labbutton[2] =
3668 gtk_radio_button_new_with_label (gtk_radio_button_group
3669 (GTK_RADIO_BUTTON (labbutton[0])),
3670 _("no numbers"));
3671 gtk_box_pack_start (GTK_BOX (pdbhbox), labbutton[2], (gboolean) TRUE,
3672 (gboolean) TRUE, 0);
3673 (void)gtk_signal_connect (GTK_OBJECT (labbutton[2]), "clicked",
3674 GTK_SIGNAL_FUNC (pdb_mode), "2");
3675 gtk_widget_show (labbutton[2]);
3676 labbutton[3] =
3677 gtk_radio_button_new_with_label (gtk_radio_button_group
3678 (GTK_RADIO_BUTTON (labbutton[0])),
3679 _("non H,no numbers"));
3680 (void)gtk_signal_connect (GTK_OBJECT (labbutton[3]), "clicked",
3681 GTK_SIGNAL_FUNC (pdb_mode), "3");
3682 gtk_box_pack_start (GTK_BOX (pdbhbox), labbutton[3], (gboolean) TRUE,
3683 (gboolean) TRUE, 0);
3684 gtk_widget_show (labbutton[3]);
3685
3686 labbutton[4] =
3687 gtk_radio_button_new_with_label (gtk_radio_button_group
3688 (GTK_RADIO_BUTTON (labbutton[0])),
3689 _("None"));
3690 gtk_box_pack_start (GTK_BOX (pdbhbox), labbutton[4], (gboolean) TRUE,
3691 (gboolean) TRUE, 0);
3692 (void)gtk_signal_connect (GTK_OBJECT (labbutton[4]), "clicked",
3693 GTK_SIGNAL_FUNC (pdb_mode), "4");
3694 gtk_widget_show (labbutton[4]);
3695
3696 gtk_box_pack_start (GTK_BOX (GTK_FILE_SELECTION (filew)->main_vbox),
3697 pdbhbox, (gboolean) TRUE, (gboolean) TRUE, 0);
3698 gtk_widget_show (pdbhbox);
3699
3700 sdfhbox = gtk_hbox_new ((gboolean) FALSE, 0);
3701 sdflabel = gtk_label_new (_("SDF entry:"));
3702 gtk_widget_show (sdflabel);
3703 gtk_box_pack_start (GTK_BOX (sdfhbox), sdflabel, TRUE, TRUE, 0);
3704 sdfbutton[0] = gtk_button_new_with_label (_("First"));
3705 gtk_box_pack_start (GTK_BOX (sdfhbox), sdfbutton[0], (gboolean) TRUE,
3706 (gboolean) TRUE, 0);
3707 (void)gtk_signal_connect (GTK_OBJECT (sdfbutton[0]), "clicked",
3708 GTK_SIGNAL_FUNC (sdf_mode), "0");
3709
3710 gtk_widget_show (sdfbutton[0]);
3711 sdfbutton[1] = gtk_button_new_with_label (_("Previous"));
3712 gtk_box_pack_start (GTK_BOX (sdfhbox), sdfbutton[1], (gboolean) TRUE,
3713 (gboolean) TRUE, 0);
3714 (void)gtk_signal_connect (GTK_OBJECT (sdfbutton[1]), "clicked",
3715 GTK_SIGNAL_FUNC (sdf_mode), "1");
3716 gtk_widget_show (sdfbutton[1]);
3717 sdfbutton[2] =
3718 gtk_button_new_with_label (_("Next"));
3719 gtk_box_pack_start (GTK_BOX (sdfhbox), sdfbutton[2], (gboolean) TRUE,
3720 (gboolean) TRUE, 0);
3721 (void)gtk_signal_connect (GTK_OBJECT (sdfbutton[2]), "clicked",
3722 GTK_SIGNAL_FUNC (sdf_mode), "2");
3723 gtk_widget_show (sdfbutton[2]);
3724 gtk_box_pack_start (GTK_BOX (GTK_FILE_SELECTION (filew)->main_vbox),
3725 sdfhbox, (gboolean) TRUE, (gboolean) TRUE, 0);
3726 gtk_widget_show (sdfhbox);
3727 check_babel();
3728 if (babelin>-1){
3729 babelcmdmenu = gtk_option_menu_new ();
3730 babelcmds = gtk_menu_new ();
3731 for (i=0;i<=babelin;i++){
3732 snprintf(msgtmp,100,"%s ( %s )",intype[i],inmode[i]);
3733 babelcmditem = gtk_menu_item_new_with_label (msgtmp);
3734 gtk_menu_append (GTK_MENU (babelcmds), babelcmditem);
3735 gtk_widget_show (babelcmditem);
3736 (void)gtk_signal_connect_object (GTK_OBJECT (babelcmditem), "activate",
3737 GTK_SIGNAL_FUNC (gtk_menu_item_select),
3738 (gpointer) babelcmditem);
3739 (void)gtk_signal_connect (GTK_OBJECT (babelcmditem), "activate",
3740 GTK_SIGNAL_FUNC (babelcmd), inmode[i]);
3741 }
3742 gtk_option_menu_set_menu (GTK_OPTION_MENU (babelcmdmenu), babelcmds);
3743 gtk_widget_show (babelcmdmenu);
3744 gtk_box_pack_start(GTK_BOX(GTK_FILE_SELECTION(filew)->main_vbox),
3745 babelcmdmenu, (gboolean)TRUE,(gboolean)TRUE,0);
3746 }
3747 if (babelout>-1){
3748 babelexpmenu = gtk_option_menu_new ();
3749 babelexpcmds = gtk_menu_new ();
3750 for (i=0;i<=babelout;i++){
3751 snprintf(msgtmp,100,"%s ( %s )",outtype[i],outmode[i]);
3752 babelexpcmditem = gtk_menu_item_new_with_label (msgtmp);
3753 gtk_menu_append (GTK_MENU (babelexpcmds), babelexpcmditem);
3754 gtk_widget_show (babelexpcmditem);
3755 (void)gtk_signal_connect_object (GTK_OBJECT (babelexpcmditem), "activate",
3756 GTK_SIGNAL_FUNC (gtk_menu_item_select),
3757 (gpointer) babelexpcmditem);
3758 (void)gtk_signal_connect (GTK_OBJECT (babelexpcmditem), "activate",
3759 GTK_SIGNAL_FUNC (babelcmd), outmode[i]);
3760 }
3761 gtk_option_menu_set_menu (GTK_OPTION_MENU (babelexpmenu), babelexpcmds);
3762 gtk_widget_show (babelexpmenu);
3763 gtk_box_pack_start(GTK_BOX(GTK_FILE_SELECTION(filew)->main_vbox),
3764 babelexpmenu, (gboolean)TRUE,(gboolean)TRUE,0);
3765 }
3766 gtk_widget_realize (filew);
3767 /*
3768 * Build the export pop-up
3769 */
3770
3771
3772 expw = gtk_file_selection_new ("Export");
3773 (void)gtk_signal_connect (GTK_OBJECT (expw), "delete_event",
3774 (GtkSignalFunc) gtk_grab_remove, GTK_OBJECT (expw));
3775 (void)gtk_signal_connect (GTK_OBJECT (expw), "delete_event",
3776 (GtkSignalFunc) gtk_widget_hide, GTK_OBJECT (expw));
3777 (void)gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (expw)->ok_button),
3778 "clicked", (GtkSignalFunc) do_export, expw);
3779
3780 (void)gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION
3781 (expw)->cancel_button),
3782 "clicked", (GtkSignalFunc) gtk_grab_remove,
3783 GTK_OBJECT (expw));
3784 (void)gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION
3785 (expw)->cancel_button),
3786 "clicked", (GtkSignalFunc) gtk_widget_hide,
3787 GTK_OBJECT (expw));
3788 hbox = gtk_hbox_new (FALSE, 0);
3789 label = gtk_label_new (_("Latex / EPS scale factor :"));
3790 gtk_box_pack_start (GTK_BOX (hbox), label, (gboolean) TRUE,
3791 (gboolean) FALSE, 0);
3792 gtk_widget_show (label);
3793 adj_scale = (GtkAdjustment *) gtk_adjustment_new (100., 1., 200., 1., 10., 0.);
3794 scale = gtk_spin_button_new (adj_scale, 0., 0);
3795
3796 gtk_box_pack_start (GTK_BOX (hbox), scale, (gboolean) FALSE,
3797 (gboolean) FALSE, 0);
3798 gtk_widget_show (scale);
3799 label = gtk_label_new ("%");
3800 gtk_box_pack_start (GTK_BOX (hbox), label, (gboolean) FALSE,
3801 (gboolean) FALSE, 0);
3802 gtk_widget_show (label);
3803 label = gtk_label_new ("");
3804 gtk_box_pack_start (GTK_BOX (hbox), label, (gboolean) TRUE,
3805 (gboolean) FALSE, 0);
3806 gtk_widget_show (label);
3807
3808 gtk_widget_show (hbox);
3809 gtk_box_pack_start (GTK_BOX (GTK_FILE_SELECTION (expw)->main_vbox), hbox,
3810 (gboolean) TRUE, (gboolean) TRUE, 0);
3811 hbox = gtk_hbox_new ((gboolean) FALSE, 0);
3812 expbutton[0] = gtk_radio_button_new_with_label (NULL, "XFig");
3813 gtk_box_pack_start (GTK_BOX (hbox), expbutton[0], (gboolean) TRUE,
3814 (gboolean) TRUE, 0);
3815 (void)gtk_signal_connect (GTK_OBJECT (expbutton[0]), "clicked",
3816 GTK_SIGNAL_FUNC (exp_mode), "0");
3817
3818 gtk_widget_show (expbutton[0]);
3819 group = gtk_radio_button_group (GTK_RADIO_BUTTON (expbutton[0]));
3820 expbutton[1] = gtk_radio_button_new_with_label (group, "LaTeX");
3821 gtk_box_pack_start (GTK_BOX (hbox), expbutton[1], (gboolean) TRUE,
3822 (gboolean) TRUE, 0);
3823 (void)gtk_signal_connect (GTK_OBJECT (expbutton[1]), "clicked",
3824 GTK_SIGNAL_FUNC (exp_mode), "1");
3825 gtk_widget_show (expbutton[1]);
3826 expbutton[2] =
3827 gtk_radio_button_new_with_label (gtk_radio_button_group
3828 (GTK_RADIO_BUTTON (expbutton[0])),
3829 "EPS");
3830 gtk_box_pack_start (GTK_BOX (hbox), expbutton[2], (gboolean) TRUE,
3831 (gboolean) TRUE, 0);
3832 (void)gtk_signal_connect (GTK_OBJECT (expbutton[2]), "clicked",
3833 GTK_SIGNAL_FUNC (exp_mode), "2");
3834 gtk_widget_show (expbutton[2]);
3835 expbutton[3] =
3836 gtk_radio_button_new_with_label (gtk_radio_button_group
3837 (GTK_RADIO_BUTTON (expbutton[0])),
3838 "X Bitmap");
3839 (void)gtk_signal_connect (GTK_OBJECT (expbutton[3]), "clicked",
3840 GTK_SIGNAL_FUNC (exp_mode), "3");
3841 gtk_box_pack_start (GTK_BOX (hbox), expbutton[3], (gboolean) TRUE,
3842 (gboolean) TRUE, 0);
3843 gtk_widget_show (expbutton[3]);
3844 expbutton[4] =
3845 gtk_radio_button_new_with_label (gtk_radio_button_group
3846 (GTK_RADIO_BUTTON (expbutton[0])),
3847 "SVG");
3848 (void)gtk_signal_connect (GTK_OBJECT (expbutton[4]), "clicked",
3849 GTK_SIGNAL_FUNC (exp_mode), "4");
3850 gtk_box_pack_start (GTK_BOX (hbox), expbutton[4], (gboolean) TRUE,
3851 (gboolean) TRUE, 0);
3852 gtk_widget_show (expbutton[4]);
3853 expbutton[5] =
3854 gtk_radio_button_new_with_label (gtk_radio_button_group
3855 (GTK_RADIO_BUTTON (expbutton[0])),
3856 "MOL");
3857 (void)gtk_signal_connect (GTK_OBJECT (expbutton[5]), "clicked",
3858 GTK_SIGNAL_FUNC (exp_mode), "5");
3859 gtk_box_pack_start (GTK_BOX (hbox), expbutton[5], (gboolean) TRUE,
3860 (gboolean) TRUE, 0);
3861 gtk_widget_show (expbutton[5]);
3862 expbutton[6] =
3863 gtk_radio_button_new_with_label (gtk_radio_button_group
3864 (GTK_RADIO_BUTTON (expbutton[0])),
3865 "EMF");
3866 (void)gtk_signal_connect (GTK_OBJECT (expbutton[6]), "clicked",
3867 GTK_SIGNAL_FUNC (exp_mode), "6");
3868 gtk_box_pack_start (GTK_BOX (hbox), expbutton[6], (gboolean) TRUE,
3869 (gboolean) TRUE, 0);
3870 #ifdef EMF
3871 gtk_widget_show (expbutton[6]);
3872 #endif
3873 expbutton[7] =
3874 gtk_radio_button_new_with_label (gtk_radio_button_group
3875 (GTK_RADIO_BUTTON (expbutton[0])),
3876 "SXD");
3877 (void)gtk_signal_connect (GTK_OBJECT (expbutton[7]), "clicked",
3878 GTK_SIGNAL_FUNC (exp_mode), "7");
3879 gtk_box_pack_start (GTK_BOX (hbox), expbutton[7], (gboolean) TRUE,
3880 (gboolean) TRUE, 0);
3881 expbutton[8] =
3882 gtk_radio_button_new_with_label (gtk_radio_button_group
3883 (GTK_RADIO_BUTTON (expbutton[0])),
3884 "PNG");
3885 (void)gtk_signal_connect (GTK_OBJECT (expbutton[8]), "clicked",
3886 GTK_SIGNAL_FUNC (exp_mode), "8");
3887 gtk_box_pack_start (GTK_BOX (hbox), expbutton[8], (gboolean) TRUE,
3888 (gboolean) TRUE, 0);
3889 gtk_widget_show (expbutton[8]);
3890 expbutton[9] =
3891 gtk_radio_button_new_with_label (gtk_radio_button_group
3892 (GTK_RADIO_BUTTON (expbutton[0])),
3893 "ASY");
3894 (void)gtk_signal_connect (GTK_OBJECT (expbutton[9]), "clicked",
3895 GTK_SIGNAL_FUNC (exp_mode), "9");
3896 gtk_box_pack_start (GTK_BOX (hbox), expbutton[9], (gboolean) TRUE,
3897 (gboolean) TRUE, 0);
3898 gtk_widget_show (expbutton[9]);
3899 gtk_box_pack_start (GTK_BOX (GTK_FILE_SELECTION (expw)->main_vbox), hbox,
3900 (gboolean) TRUE, (gboolean) TRUE, 0);
3901 gtk_widget_show (hbox);
3902 /********************************************************************/
3903
3904 /*
3905 * Build the (error) message pop-up
3906 */
3907
3908 messagew = gtk_dialog_new ();
3909 (void)gtk_signal_connect_object (GTK_OBJECT (messagew), "destroy",
3910 (GtkSignalFunc) gtk_grab_remove,
3911 GTK_OBJECT (messagew));
3912
3913 (void)gtk_signal_connect_object (GTK_OBJECT (messagew), "destroy",
3914 (GtkSignalFunc) gtk_widget_hide,
3915 GTK_OBJECT (messagew));
3916
3917 message = gtk_label_new (_("Unknown error"));
3918 gtk_misc_set_padding (GTK_MISC (message), 10, 10);
3919 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (messagew)->vbox), message,
3920 (gboolean) TRUE, (gboolean) TRUE, 0);
3921
3922 gtk_widget_show (message);
3923
3924 button = gtk_button_new_with_label ("OK");
3925 /* Connect the ok_button */
3926 (void)gtk_signal_connect_object (GTK_OBJECT (button),
3927 "clicked", (GtkSignalFunc) gtk_grab_remove,
3928 GTK_OBJECT (messagew));
3929 (void)gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
3930 (GtkSignalFunc) gtk_widget_hide,
3931 GTK_OBJECT (messagew));
3932 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (messagew)->action_area), button,
3933 (gboolean) TRUE, (gboolean) TRUE, 0);
3934 gtk_widget_show (button);
3935 /********************************************************************/
3936
3937 /* Configurable options dialog */
3938
3939 #if (GTK_MINOR_VERSION >2)
3940 printer_dialog = gtk_window_new (GTK_WINDOW_TOPLEVEL);
3941 gtk_window_set_title (GTK_WINDOW (printer_dialog), _("Configurable options"));
3942 gtk_window_set_resizable (GTK_WINDOW (printer_dialog), FALSE);
3943 gtk_container_set_border_width (GTK_CONTAINER (printer_dialog), 12);
3944 master_vbox = gtk_vbox_new (FALSE, 12);
3945 gtk_container_add (GTK_CONTAINER (printer_dialog), master_vbox);
3946
3947 hbox = gtk_hbutton_box_new ();
3948 gtk_button_box_set_layout (GTK_BUTTON_BOX (hbox), GTK_BUTTONBOX_END);
3949 gtk_box_set_spacing (GTK_BOX (hbox), 12);
3950 gtk_box_pack_end (GTK_BOX (master_vbox), hbox, FALSE, FALSE, 0);
3951
3952 button = gtk_button_new_from_stock (GTK_STOCK_CANCEL);
3953 gtk_container_add (GTK_CONTAINER (hbox), button);
3954
3955 /* Thanks to using ...swapped, the callback_data gets passed as
3956 the first argument to the callback function, so when we click
3957 on the button, we hide the dialog, not the button. */
3958
3959 g_signal_connect_swapped (G_OBJECT (button), "clicked",
3960 G_CALLBACK (gtk_widget_hide), G_OBJECT (printer_dialog));
3961
3962 button = gtk_button_new_from_stock (GTK_STOCK_OK);
3963 gtk_container_add (GTK_CONTAINER (hbox), button);
3964 g_signal_connect (G_OBJECT (button), "clicked",
3965 G_CALLBACK (options_dialog_ok), NULL);
3966
3967 notebook = gtk_notebook_new ();
3968 gtk_box_pack_end (GTK_BOX (master_vbox), notebook, TRUE, TRUE, 0);
3969
3970 /* First page: General options */
3971
3972 table = gtk_table_new (10, 3, FALSE);
3973 gtk_container_set_border_width (GTK_CONTAINER (table), 12);
3974
3975 label = gtk_label_new (NULL);
3976 gtk_label_set_text_with_mnemonic (GTK_LABEL (label), _("_General"));
3977 gtk_notebook_append_page (GTK_NOTEBOOK (notebook), table, label);
3978
3979 /* Adjust the table spacing before section headings etc. */
3980
3981 gtk_table_set_col_spacing (GTK_TABLE (table), 1, 12);
3982 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
3983 gtk_table_set_row_spacing (GTK_TABLE (table), 0, 12);
3984 gtk_table_set_row_spacing (GTK_TABLE (table), 3, 12);
3985 gtk_table_set_row_spacing (GTK_TABLE (table), 7, 12);
3986 gtk_table_set_row_spacing (GTK_TABLE (table), 2, 18);
3987 gtk_table_set_row_spacing (GTK_TABLE (table), 6, 18);
3988
3989 /* Spacer label for left indent */
3990
3991 label = gtk_label_new (NULL);
3992 gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2, 0, 0, 6, 0);
3993
3994 /* The section headings */
3995
3996 label = gtk_label_new (NULL);
3997 gtk_label_set_markup (GTK_LABEL (label), _("<b>Display</b>"));
3998 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
3999 gtk_table_attach (GTK_TABLE (table), label, 0, 3, 0, 1, GTK_EXPAND|GTK_FILL,
4000 GTK_FILL, 0, 0);
4001
4002 label = gtk_label_new (NULL);
4003 gtk_label_set_markup (GTK_LABEL (label), _("<b>Saving and Exporting</b>"));
4004 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
4005 gtk_table_attach (GTK_TABLE (table), label, 0, 3, 3, 4, GTK_EXPAND|GTK_FILL,
4006 GTK_FILL, 0, 0);
4007
4008 label = gtk_label_new (NULL);
4009 gtk_label_set_markup (GTK_LABEL (label), _("<b>Other</b>"));
4010 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
4011 gtk_table_attach (GTK_TABLE (table), label, 0, 3, 8, 9, GTK_EXPAND|GTK_FILL,
4012 GTK_FILL, 0, 0);
4013
4014 /* First section, "Display" */
4015
4016 hbox = gtk_hbox_new (FALSE, 12);
4017 gtk_table_attach (GTK_TABLE (table), hbox, 1, 3, 1, 2, GTK_EXPAND|GTK_FILL,
4018 GTK_FILL, 0, 0);
4019 label = gtk_label_new (NULL);
4020 gtk_label_set_text_with_mnemonic (GTK_LABEL (label), _("_Background color:"));
4021 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
4022
4023 color_button = gtk_color_button_new ();
4024 gtk_box_pack_start (GTK_BOX (hbox), color_button, FALSE, FALSE, 0);
4025 gtk_label_set_mnemonic_widget (GTK_LABEL (label), color_button);
4026
4027 whiteout_check = gtk_check_button_new_with_mnemonic (
4028 _("Add filled _white rectangle under labels"));
4029 gtk_table_attach (GTK_TABLE (table), whiteout_check, 1, 3, 2, 3,
4030 GTK_EXPAND|GTK_FILL, GTK_FILL, 0, 0);
4031
4032 /* Second section, "Saving and exporting" */
4033
4034 datadir_entry = gtk_entry_new ();
4035 gtk_table_attach (GTK_TABLE (table), datadir_entry, 2, 3, 4, 5,
4036 GTK_EXPAND|GTK_FILL, GTK_FILL, 0, 0);
4037 datamask_entry = gtk_entry_new ();
4038 gtk_table_attach (GTK_TABLE (table), datamask_entry, 2, 3, 5, 6,
4039 GTK_EXPAND|GTK_FILL, GTK_FILL, 0, 0);
4040
4041 eps_preview_combo = gtk_combo_box_new_text ();
4042 gtk_combo_box_append_text (GTK_COMBO_BOX (eps_preview_combo), _("None"));
4043 gtk_combo_box_append_text (GTK_COMBO_BOX (eps_preview_combo), _("EPSI"));
4044 gtk_combo_box_append_text (GTK_COMBO_BOX (eps_preview_combo), _("TIFF mono"));
4045 gtk_combo_box_append_text (GTK_COMBO_BOX (eps_preview_combo), _("TIFF color"));
4046 gtk_table_attach (GTK_TABLE (table), eps_preview_combo, 2, 3, 6, 7,
4047 GTK_EXPAND|GTK_FILL, GTK_FILL, 0, 0);
4048
4049 label = gtk_label_new (NULL);
4050 gtk_label_set_text_with_mnemonic (GTK_LABEL (label), _("_Data directory:"));
4051 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
4052 gtk_label_set_mnemonic_widget (GTK_LABEL (label), datadir_entry);
4053 gtk_table_attach (GTK_TABLE (table), label, 1, 2, 4, 5, GTK_EXPAND|GTK_FILL,
4054 GTK_FILL, 0, 0);
4055
4056 label = gtk_label_new (NULL);
4057 gtk_label_set_text_with_mnemonic (GTK_LABEL (label), _("E_xtension:"));
4058 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
4059 gtk_label_set_mnemonic_widget (GTK_LABEL (label), datamask_entry);
4060 gtk_table_attach (GTK_TABLE (table), label, 1, 2, 5, 6, GTK_EXPAND|GTK_FILL,
4061 GTK_FILL, 0, 0);
4062
4063 label = gtk_label_new (NULL);
4064 gtk_label_set_text_with_mnemonic (GTK_LABEL (label),
4065 _("Preview image to add to _EPS files:"));
4066 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
4067 gtk_label_set_mnemonic_widget (GTK_LABEL (label), eps_preview_combo);
4068 gtk_table_attach (GTK_TABLE (table), label, 1, 2, 6, 7, GTK_EXPAND|GTK_FILL,
4069 GTK_FILL, 0, 0);
4070
4071 intl_check = gtk_check_button_new_with_mnemonic (
4072 _("Support national character sets in labels"));
4073 gtk_table_attach (GTK_TABLE (table), intl_check, 1, 3, 7, 8,
4074 GTK_EXPAND|GTK_FILL, GTK_FILL, 0, 0);
4075
4076 /* Third section, "Other" */
4077
4078 bond_length_entry = gtk_entry_new ();
4079 gtk_table_attach (GTK_TABLE (table), bond_length_entry, 2, 3, 9, 10,
4080 GTK_EXPAND|GTK_FILL, GTK_FILL, 0, 0);
4081
4082 hbox = gtk_hbox_new (FALSE, 6);
4083 gtk_table_attach (GTK_TABLE (table), hbox, 2, 3, 10, 11, GTK_EXPAND|GTK_FILL,
4084 GTK_FILL, 0, 0);
4085 dbond_dist_spin = gtk_spin_button_new_with_range (1, 100, 1);
4086 gtk_box_pack_start (GTK_BOX (hbox), dbond_dist_spin, FALSE, FALSE, 0);
4087 label = gtk_label_new ("px");
4088 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
4089 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
4090
4091 label = gtk_label_new (NULL);
4092 gtk_label_set_text_with_mnemonic (GTK_LABEL (label), _("Base bond _length:"));
4093 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
4094 gtk_label_set_mnemonic_widget (GTK_LABEL (label), bond_length_entry);
4095 gtk_table_attach (GTK_TABLE (table), label, 1, 2, 9, 10, GTK_EXPAND|GTK_FILL,
4096 GTK_FILL, 0, 0);
4097
4098 label = gtk_label_new (NULL);
4099 gtk_label_set_text_with_mnemonic (GTK_LABEL (label),
4100 _("Double bond _separation:"));
4101 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
4102 gtk_label_set_mnemonic_widget (GTK_LABEL (label), dbond_dist_spin);
4103 gtk_table_attach (GTK_TABLE (table), label, 1, 2, 10, 11, GTK_EXPAND|GTK_FILL,
4104 GTK_FILL, 0, 0);
4105
4106 /* Second page, printing */
4107
4108 table = gtk_table_new (5, 2, FALSE);
4109
4110 gtk_container_set_border_width (GTK_CONTAINER (table), 12);
4111
4112 label = gtk_label_new (NULL);
4113 gtk_label_set_text_with_mnemonic (GTK_LABEL (label), _("_Printing"));
4114 gtk_notebook_append_page (GTK_NOTEBOOK (notebook), table, label);
4115
4116 /* Table spacings */
4117
4118 gtk_table_set_col_spacing (GTK_TABLE (table), 0, 12);
4119 gtk_table_set_row_spacings (GTK_TABLE (table), 6);
4120
4121 /* No sections are necessary on this page */
4122
4123 print_cmd_combo = gtk_combo_box_new_text ();
4124 gtk_combo_box_append_text (GTK_COMBO_BOX (print_cmd_combo), "lpr");
4125 gtk_combo_box_append_text (GTK_COMBO_BOX (print_cmd_combo), "lp");
4126 gtk_combo_box_append_text (GTK_COMBO_BOX (print_cmd_combo), "kprinter");
4127 gtk_combo_box_append_text (GTK_COMBO_BOX (print_cmd_combo), "gtklp");
4128 gtk_table_attach (GTK_TABLE (table), print_cmd_combo, 1, 2, 0, 1,
4129 GTK_EXPAND|GTK_FILL, GTK_FILL, 0, 0);
4130
4131 printer_name_entry = gtk_entry_new ();
4132 gtk_table_attach (GTK_TABLE (table), printer_name_entry,
4133 1, 2, 1, 2, GTK_EXPAND|GTK_FILL, GTK_FILL, 0, 0);
4134
4135 paper_size_combo = gtk_combo_box_new_text ();
4136 for (i = 0; i < 11; i++)
4137 {
4138 gtk_combo_box_append_text (GTK_COMBO_BOX (paper_size_combo), paper[i]);
4139 }
4140 gtk_table_attach (GTK_TABLE (table), paper_size_combo, 1, 2, 2, 3,
4141 GTK_EXPAND|GTK_FILL, GTK_FILL, 0, 0);
4142
4143 orientation_combo = gtk_combo_box_new_text ();
4144 gtk_combo_box_append_text (GTK_COMBO_BOX (orientation_combo), _("Portrait"));
4145 gtk_combo_box_append_text (GTK_COMBO_BOX (orientation_combo), _("Landscape"));
4146 gtk_table_attach (GTK_TABLE (table), orientation_combo, 1, 2, 3, 4,
4147 GTK_EXPAND|GTK_FILL, GTK_FILL, 0, 0);
4148
4149 hbox = gtk_hbox_new (FALSE, 6);
4150 gtk_table_attach (GTK_TABLE (table), hbox, 1, 2, 4, 5, GTK_EXPAND|GTK_FILL,
4151 GTK_FILL, 0, 0);
4152 print_scale_spin = gtk_spin_button_new_with_range (1, 200, 1);
4153 gtk_box_pack_start (GTK_BOX (hbox), print_scale_spin, FALSE, FALSE, 0);
4154 label = gtk_label_new ("%");
4155 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
4156 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
4157
4158 label = gtk_label_new (NULL);
4159 gtk_label_set_text_with_mnemonic (GTK_LABEL (label), _("Print _command:"));
4160 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
4161 gtk_label_set_mnemonic_widget (GTK_LABEL (label), print_cmd_combo);
4162 gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1, GTK_EXPAND|GTK_FILL,
4163 GTK_FILL, 0, 0);
4164
4165 label = gtk_label_new (NULL);
4166 gtk_label_set_text_with_mnemonic (GTK_LABEL (label), _("Printer _name:"));
4167 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
4168 gtk_label_set_mnemonic_widget (GTK_LABEL (label), printer_name_entry);
4169 gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2, GTK_EXPAND|GTK_FILL,
4170 GTK_FILL, 0, 0);
4171
4172 label = gtk_label_new (NULL);
4173 gtk_label_set_text_with_mnemonic (GTK_LABEL (label), _("Paper si_ze:"));
4174 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
4175 gtk_label_set_mnemonic_widget (GTK_LABEL (label), paper_size_combo);
4176 gtk_table_attach (GTK_TABLE (table), label, 0, 1, 2, 3, GTK_EXPAND|GTK_FILL,
4177 GTK_FILL, 0, 0);
4178
4179 label = gtk_label_new (NULL);
4180 gtk_label_set_text_with_mnemonic (GTK_LABEL (label), _("_Orientation:"));
4181 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
4182 gtk_label_set_mnemonic_widget (GTK_LABEL (label), orientation_combo);
4183 gtk_table_attach (GTK_TABLE (table), label, 0, 1, 3, 4, GTK_EXPAND|GTK_FILL,
4184 GTK_FILL, 0, 0);
4185
4186 label = gtk_label_new (NULL);
4187 gtk_label_set_text_with_mnemonic (GTK_LABEL (label), _("Print sc_ale factor:"));
4188 gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
4189 gtk_label_set_mnemonic_widget (GTK_LABEL (label), print_scale_spin);
4190 gtk_table_attach (GTK_TABLE (table), label, 0, 1, 4, 5, GTK_EXPAND|GTK_FILL,
4191 GTK_FILL, 0, 0);
4192
4193 gtk_widget_show_all (GTK_WIDGET (master_vbox));
4194
4195 (void)gtk_signal_connect_object (GTK_OBJECT (printer_dialog), "delete_event",
4196 (GtkSignalFunc) gtk_widget_hide,
4197 GTK_OBJECT (printer_dialog));
4198
4199 #else
4200 /* old-style configuration menu for gtk1 builds */
4201
4202 /* Color selection dialog */
4203 colorseldialog= gtk_color_selection_dialog_new(_("Select background color"));
4204
4205 colorsel=GTK_COLOR_SELECTION_DIALOG(colorseldialog)->colorsel;
4206
4207 (void)gtk_signal_connect(GTK_OBJECT(colorsel), "color_changed",
4208 (GtkSignalFunc)set_bgcolor,(gpointer)colorsel);
4209 (void)gtk_signal_connect_object(GTK_OBJECT(GTK_COLOR_SELECTION_DIALOG(colorseldialog)->ok_button), "clicked",
4210 (GtkSignalFunc)gtk_widget_hide,GTK_OBJECT(colorseldialog));
4211 (void)gtk_signal_connect_object(GTK_OBJECT(GTK_COLOR_SELECTION_DIALOG(colorseldialog)->cancel_button), "clicked",
4212 (GtkSignalFunc)gtk_widget_hide,GTK_OBJECT(colorseldialog));
4213 gtk_widget_hide(GTK_COLOR_SELECTION_DIALOG(colorseldialog)->help_button);
4214 gtk_widget_realize(colorseldialog);
4215 /********************************************************************/
4216 /* Printer setup dialog */
4217
4218 printer_dialog = gtk_window_new (GTK_WINDOW_TOPLEVEL);
4219 gtk_window_set_title (GTK_WINDOW (printer_dialog),
4220 _("Configurable options"));
4221 gtk_widget_realize (printer_dialog);
4222 vbox = gtk_vbox_new (FALSE, 0);
4223 gtk_container_add (GTK_CONTAINER (printer_dialog), vbox);
4224 gtk_widget_show (vbox);
4225 hbox = gtk_hbox_new (FALSE, 10);
4226 gtk_container_set_border_width (GTK_CONTAINER (hbox), 10);
4227 gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
4228 gtk_widget_show (hbox);
4229 label = gtk_label_new (_("Paper size:"));
4230 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
4231 gtk_widget_show (label);
4232 papermenu = gtk_option_menu_new ();
4233 papersizes = gtk_menu_new ();
4234 for (i = 0; i < 11; i++)
4235 {
4236 papersizeitem[i] = gtk_menu_item_new_with_label (paper[i]);
4237 gtk_menu_append (GTK_MENU (papersizes), papersizeitem[i]);
4238 gtk_widget_show (papersizeitem[i]);
4239 (void)gtk_signal_connect_object (GTK_OBJECT (papersizeitem[i]), "activate",
4240 GTK_SIGNAL_FUNC (gtk_menu_item_select),
4241 (gpointer) papersizeitem[i]);
4242 (void)gtk_signal_connect (GTK_OBJECT (papersizeitem[i]), "activate",
4243 GTK_SIGNAL_FUNC (newpaper), (gpointer) paper[i]);
4244 }
4245 gtk_option_menu_set_menu (GTK_OPTION_MENU (papermenu), papersizes);
4246 gtk_widget_show (papermenu);
4247 gtk_box_pack_start (GTK_BOX (hbox), papermenu,
4248 (gboolean) TRUE, (gboolean) TRUE, 0);
4249
4250 hbox = gtk_hbox_new (FALSE, 10);
4251 gtk_container_set_border_width (GTK_CONTAINER (hbox), 10);
4252 gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
4253 gtk_widget_show (hbox);
4254 label = gtk_label_new (_("Orientation:"));
4255 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
4256 gtk_widget_show (label);
4257 orientmenu = gtk_option_menu_new ();
4258 orientations = gtk_menu_new ();
4259 orientationitem = gtk_menu_item_new_with_label (_("Portrait"));
4260 gtk_menu_append (GTK_MENU (orientations), orientationitem);
4261 gtk_widget_show (orientationitem);
4262 (void)gtk_signal_connect (GTK_OBJECT (orientationitem), "activate",
4263 GTK_SIGNAL_FUNC (neworient), "0");
4264 orientationitem = gtk_menu_item_new_with_label (_("Landscape"));
4265 gtk_menu_append (GTK_MENU (orientations), orientationitem);
4266 gtk_widget_show (orientationitem);
4267 (void)gtk_signal_connect (GTK_OBJECT (orientationitem), "activate",
4268 GTK_SIGNAL_FUNC (neworient), "1");
4269 gtk_option_menu_set_menu (GTK_OPTION_MENU (orientmenu), orientations);
4270 gtk_widget_show (orientmenu);
4271 gtk_box_pack_start (GTK_BOX (hbox), orientmenu,
4272 (gboolean) TRUE, (gboolean) TRUE, 0);
4273
4274 hbox = gtk_hbox_new (FALSE, 10);
4275 gtk_container_set_border_width (GTK_CONTAINER (hbox), 10);
4276 gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
4277 gtk_widget_show (hbox);
4278
4279 label = gtk_label_new (_("Print scale factor :"));
4280 gtk_box_pack_start (GTK_BOX (hbox), label, (gboolean) FALSE,
4281 (gboolean) FALSE, 0);
4282 gtk_widget_show (label);
4283
4284 adj_pscale = (GtkAdjustment *) gtk_adjustment_new (70., 1., 200., 1., 10., 0.);
4285 pscale = gtk_spin_button_new (adj_pscale, 0., 0);
4286
4287 gtk_box_pack_start (GTK_BOX (hbox), pscale, (gboolean) FALSE,
4288 (gboolean) FALSE, 0);
4289 gtk_widget_show (pscale);
4290 label = gtk_label_new ("%");
4291 gtk_box_pack_start (GTK_BOX (hbox), label, (gboolean) FALSE,
4292 (gboolean) FALSE, 0);
4293 gtk_widget_show (label);
4294 label = gtk_label_new ("");
4295 gtk_box_pack_start (GTK_BOX (hbox), label, (gboolean) TRUE,
4296 (gboolean) FALSE, 0);
4297 gtk_widget_show (label);
4298
4299
4300 hbox = gtk_hbox_new (FALSE, 10);
4301 gtk_container_set_border_width (GTK_CONTAINER (hbox), 10);
4302 gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
4303 gtk_widget_show (hbox);
4304 label = gtk_label_new (_("Print command:"));
4305 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
4306 gtk_widget_show (label);
4307 printcmdmenu = gtk_option_menu_new ();
4308 printcmds = gtk_menu_new ();
4309 printcmditem = gtk_menu_item_new_with_label ("lpr");
4310 gtk_menu_append (GTK_MENU (printcmds), printcmditem);
4311 gtk_widget_show (printcmditem);
4312 (void)gtk_signal_connect_object (GTK_OBJECT (printcmditem), "activate",
4313 GTK_SIGNAL_FUNC (gtk_menu_item_select),
4314 (gpointer) printcmditem);
4315 (void)gtk_signal_connect (GTK_OBJECT (printcmditem), "activate",
4316 GTK_SIGNAL_FUNC (newprcmd), "0");
4317 printcmditem = gtk_menu_item_new_with_label ("lp");
4318 gtk_menu_append (GTK_MENU (printcmds), printcmditem);
4319 gtk_widget_show (printcmditem);
4320 (void)gtk_signal_connect_object (GTK_OBJECT (printcmditem), "activate",
4321 GTK_SIGNAL_FUNC (gtk_menu_item_select),
4322 (gpointer) printcmditem);
4323
4324 (void)gtk_signal_connect (GTK_OBJECT (printcmditem), "activate",
4325 GTK_SIGNAL_FUNC (newprcmd), "1");
4326 printcmditem = gtk_menu_item_new_with_label ("kprinter");
4327 gtk_menu_append (GTK_MENU (printcmds), printcmditem);
4328 gtk_widget_show (printcmditem);
4329 (void)gtk_signal_connect_object (GTK_OBJECT (printcmditem), "activate",
4330 GTK_SIGNAL_FUNC (gtk_menu_item_select),
4331 (gpointer) printcmditem);
4332
4333 (void)gtk_signal_connect (GTK_OBJECT (printcmditem), "activate",
4334 GTK_SIGNAL_FUNC (newprcmd), "2");
4335
4336 printcmditem = gtk_menu_item_new_with_label ("gtklp");
4337 gtk_menu_append (GTK_MENU (printcmds), printcmditem);
4338 gtk_widget_show (printcmditem);
4339 (void)gtk_signal_connect_object (GTK_OBJECT (printcmditem), "activate",
4340 GTK_SIGNAL_FUNC (gtk_menu_item_select),
4341 (gpointer) printcmditem);
4342
4343 (void)gtk_signal_connect (GTK_OBJECT (printcmditem), "activate",
4344 GTK_SIGNAL_FUNC (newprcmd), "3");
4345 gtk_option_menu_set_menu (GTK_OPTION_MENU (printcmdmenu), printcmds);
4346 gtk_widget_show (printcmdmenu);
4347 gtk_box_pack_start (GTK_BOX (hbox), printcmdmenu,
4348 (gboolean) TRUE, (gboolean) TRUE, 0);
4349
4350 hbox = gtk_hbox_new (FALSE, 10);
4351 gtk_container_set_border_width (GTK_CONTAINER (hbox), 10);
4352 gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
4353 gtk_widget_show (hbox);
4354 label = gtk_label_new (_("Preview image to add to eps files :"));
4355 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
4356 gtk_widget_show (label);
4357 epsoptionmenu = gtk_option_menu_new ();
4358 epsoptions = gtk_menu_new ();
4359 epsoptitem = gtk_menu_item_new_with_label (_("None"));
4360 gtk_menu_append (GTK_MENU (epsoptions), epsoptitem);
4361 gtk_widget_show (epsoptitem);
4362 (void)gtk_signal_connect_object (GTK_OBJECT (epsoptitem), "activate",
4363 GTK_SIGNAL_FUNC (gtk_menu_item_select),
4364 (gpointer) epsoptitem);
4365 (void)gtk_signal_connect (GTK_OBJECT (epsoptitem), "activate",
4366 GTK_SIGNAL_FUNC (newepsopt), "0");
4367
4368 epsoptitem = gtk_menu_item_new_with_label (_("EPSI"));
4369 gtk_menu_append (GTK_MENU (epsoptions), epsoptitem);
4370 gtk_widget_show (epsoptitem);
4371 (void)gtk_signal_connect_object (GTK_OBJECT (epsoptitem), "activate",
4372 GTK_SIGNAL_FUNC (gtk_menu_item_select),
4373 (gpointer) epsoptitem);
4374 (void)gtk_signal_connect (GTK_OBJECT (epsoptitem), "activate",
4375 GTK_SIGNAL_FUNC (newepsopt), "1");
4376
4377 epsoptitem = gtk_menu_item_new_with_label (_("TIFF mono"));
4378 gtk_menu_append (GTK_MENU (epsoptions), epsoptitem);
4379 gtk_widget_show (epsoptitem);
4380 (void)gtk_signal_connect_object (GTK_OBJECT (epsoptitem), "activate",
4381 GTK_SIGNAL_FUNC (gtk_menu_item_select),
4382 (gpointer) epsoptitem);
4383 (void)gtk_signal_connect (GTK_OBJECT (epsoptitem), "activate",
4384 GTK_SIGNAL_FUNC (newepsopt), "2");
4385 epsoptitem = gtk_menu_item_new_with_label (_("TIFF color"));
4386 gtk_menu_append (GTK_MENU (epsoptions), epsoptitem);
4387 gtk_widget_show (epsoptitem);
4388 (void)gtk_signal_connect_object (GTK_OBJECT (epsoptitem), "activate",
4389 GTK_SIGNAL_FUNC (gtk_menu_item_select),
4390 (gpointer) epsoptitem);
4391
4392 (void)gtk_signal_connect (GTK_OBJECT (epsoptitem), "activate",
4393 GTK_SIGNAL_FUNC (newepsopt), "2");
4394
4395 gtk_option_menu_set_menu (GTK_OPTION_MENU (epsoptionmenu), epsoptions);
4396 gtk_widget_show (epsoptionmenu);
4397 gtk_box_pack_start (GTK_BOX (hbox), epsoptionmenu,
4398 (gboolean) TRUE, (gboolean) TRUE, 0);
4399
4400 hbox = gtk_hbox_new (FALSE, 10);
4401 gtk_container_set_border_width (GTK_CONTAINER (hbox), 10);
4402 gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
4403 gtk_widget_show (hbox);
4404 label = gtk_label_new (_("Support national character sets in labels"));
4405 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
4406 gtk_widget_show (label);
4407 intlbutton = gtk_check_button_new();
4408 gtk_box_pack_start (GTK_BOX (hbox), intlbutton, FALSE, FALSE, 0);
4409 (void)gtk_signal_connect (GTK_OBJECT(intlbutton), "toggled",
4410 GTK_SIGNAL_FUNC(toggle_intlchars), NULL);
4411 gtk_widget_show (intlbutton);
4412
4413 hbox = gtk_hbox_new (FALSE, 10);
4414 gtk_container_set_border_width (GTK_CONTAINER (hbox), 10);
4415 gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
4416 gtk_widget_show (hbox);
4417 snprintf(bghexcolor,10,"#%2.2x%2.2x%2.2x",(unsigned char)(bgred/256.),(unsigned char)(bggreen/256.),(unsigned char)(bgblue/256.));
4418 label = gtk_label_new (_("Background color :"));
4419 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
4420 gtk_widget_show (label);
4421 bgcolorbutton = gtk_button_new_with_label(bghexcolor);
4422 gtk_box_pack_start (GTK_BOX (hbox), bgcolorbutton, FALSE, FALSE, 0);
4423 (void)gtk_signal_connect_object (GTK_OBJECT(bgcolorbutton), "clicked",
4424 GTK_SIGNAL_FUNC(gtk_widget_show),
4425 GTK_OBJECT(colorseldialog));
4426 gtk_widget_show (bgcolorbutton);
4427
4428 hbox = gtk_hbox_new (FALSE, 10);
4429 gtk_container_set_border_width (GTK_CONTAINER (hbox), 10);
4430 gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
4431 gtk_widget_show (hbox);
4432 label = gtk_label_new (_("Add filled white rectangle under labels"));
4433 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
4434 gtk_widget_show (label);
4435 whiteoutbutton = gtk_check_button_new();
4436 gtk_box_pack_start (GTK_BOX (hbox), whiteoutbutton, FALSE, FALSE, 0);
4437 (void)gtk_signal_connect (GTK_OBJECT(whiteoutbutton), "toggled",
4438 GTK_SIGNAL_FUNC(toggle_whiteout), NULL);
4439 gtk_widget_show (whiteoutbutton);
4440
4441 hbox = gtk_hbox_new (FALSE, 10);
4442 gtk_container_set_border_width (GTK_CONTAINER (hbox), 10);
4443 gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
4444 gtk_widget_show (hbox);
4445 label = gtk_label_new (_("Printer name:"));
4446 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
4447 gtk_widget_show (label);
4448
4449 prqueue = gtk_entry_new_with_max_length (32);
4450 gtk_widget_show (prqueue);
4451 gtk_box_pack_start (GTK_BOX (hbox), prqueue,
4452 (gboolean) TRUE, (gboolean) TRUE, 0);
4453
4454 hbox = gtk_hbox_new (FALSE, 10);
4455 gtk_container_set_border_width (GTK_CONTAINER (hbox), 10);
4456 gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
4457 gtk_widget_show (hbox);
4458 label = gtk_label_new (_("Data directory:"));
4459 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
4460 gtk_widget_show (label);
4461
4462 defaultdir = gtk_entry_new_with_max_length ((guint16)PATH_MAX);
4463 gtk_widget_show (defaultdir);
4464 gtk_box_pack_start (GTK_BOX (hbox), defaultdir,
4465 (gboolean) TRUE, (gboolean) TRUE, 0);
4466
4467 hbox = gtk_hbox_new (FALSE, 10);
4468 gtk_container_set_border_width (GTK_CONTAINER (hbox), 10);
4469 gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
4470 gtk_widget_show (hbox);
4471 label = gtk_label_new (_("Extension:"));
4472 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
4473 gtk_widget_show (label);
4474
4475 defaultext = gtk_entry_new_with_max_length (32);
4476 gtk_widget_show (defaultext);
4477 gtk_box_pack_start (GTK_BOX (hbox), defaultext,
4478 (gboolean) TRUE, (gboolean) TRUE, 0);
4479
4480 hbox = gtk_hbox_new (FALSE, 10);
4481 gtk_container_set_border_width (GTK_CONTAINER (hbox), 10);
4482 gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
4483 gtk_widget_show (hbox);
4484 label = gtk_label_new (_("Base bondlength (10.668mm) :"));
4485 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
4486 gtk_widget_show (label);
4487 base_bondlen = gtk_entry_new_with_max_length (32);
4488 snprintf(msgtmp,100,"%6.4f",bondlen_mm);
4489 gtk_entry_set_text (GTK_ENTRY (base_bondlen),msgtmp);
4490 gtk_widget_show (base_bondlen);
4491 gtk_box_pack_start (GTK_BOX (hbox), base_bondlen,
4492 (gboolean) TRUE, (gboolean) TRUE, 0);
4493
4494 hbox = gtk_hbox_new (FALSE, 10);
4495 gtk_container_set_border_width (GTK_CONTAINER (hbox), 10);
4496 gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
4497 gtk_widget_show (hbox);
4498 label = gtk_label_new (_("Doublebond separation (4 pixel) :"));
4499 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
4500 gtk_widget_show (label);
4501 doubledist = gtk_entry_new_with_max_length (32);
4502 snprintf(msgtmp,100,"%d",db_dist);
4503 gtk_entry_set_text (GTK_ENTRY (doubledist),msgtmp);
4504 gtk_widget_show (doubledist);
4505 gtk_box_pack_start (GTK_BOX (hbox), doubledist,
4506 (gboolean) TRUE, (gboolean) TRUE, 0);
4507
4508
4509 (void)gtk_signal_connect_object (GTK_OBJECT (printer_dialog), "delete_event",
4510 (GtkSignalFunc) gtk_widget_hide,
4511 GTK_OBJECT (printer_dialog));
4512
4513 hbox = gtk_hbox_new (FALSE, 10);
4514 gtk_container_set_border_width (GTK_CONTAINER (hbox), 10);
4515 gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
4516 gtk_widget_show (hbox);
4517
4518 pokbutton = gtk_button_new_with_label (_("Ok"));
4519 gtk_box_pack_start (GTK_BOX (hbox), pokbutton,
4520 (gboolean) TRUE, (gboolean) TRUE, 0);
4521 (void)gtk_signal_connect_object (GTK_OBJECT (pokbutton), "clicked",
4522 GTK_SIGNAL_FUNC (gtk_widget_hide),
4523 GTK_OBJECT (printer_dialog));
4524 (void)gtk_signal_connect (GTK_OBJECT (pokbutton), "clicked",
4525 GTK_SIGNAL_FUNC (setup_printer), "1");
4526 gtk_widget_show (pokbutton);
4527
4528 pcabutton = gtk_button_new_with_label (_("Cancel"));
4529 gtk_box_pack_start (GTK_BOX (hbox), pcabutton,
4530 (gboolean) TRUE, (gboolean) TRUE, 0);
4531 (void)gtk_signal_connect_object (GTK_OBJECT (pcabutton), "clicked",
4532 GTK_SIGNAL_FUNC (gtk_widget_hide),
4533 GTK_OBJECT (printer_dialog));
4534 (void)gtk_signal_connect (GTK_OBJECT (pcabutton), "clicked",
4535 GTK_SIGNAL_FUNC (setup_printer), "0");
4536 gtk_widget_show (pcabutton);
4537
4538
4539 #endif
4540 /****************************************************************/
4541
4542
4543 /*************************************************************/
4544 /* Popup to show a selection of templates to insert into the drawing */
4545
4546 templates = gtk_window_new (GTK_WINDOW_TOPLEVEL);
4547 gtk_window_set_title (GTK_WINDOW (templates), _("Templates"));
4548 gtk_widget_realize (templates);
4549 tvbox = gtk_vbox_new (FALSE, 0);
4550 gtk_container_add (GTK_CONTAINER (templates), tvbox);
4551 gtk_widget_show (tvbox);
4552 (void)gtk_signal_connect_object (GTK_OBJECT (templates), "delete_event",
4553 (GtkSignalFunc) gtk_widget_hide,
4554 GTK_OBJECT (templates));
4555 temptips = gtk_tooltips_new ();
4556 templatebook = gtk_notebook_new ();
4557 gtk_notebook_set_tab_pos (GTK_NOTEBOOK (templatebook), GTK_POS_TOP);
4558 label = gtk_label_new (_("Carbocycles"));
4559 gtk_widget_show (label);
4560 page = gtk_frame_new (_("Carbocycles"));
4561 gtk_widget_show (page);
4562 gtk_notebook_append_page (GTK_NOTEBOOK (templatebook), page, label);
4563 pbox = gtk_table_new (5, 5, TRUE);
4564 gtk_widget_show (pbox);
4565 for (i = 0; i < 5; i++)
4566 {
4567 for (j = 0; j < 5; j++)
4568 {
4569 tbutton[5 * i + j] = gtk_button_new ();
4570 style = gtk_widget_get_style (templates);
4571 pixmap = gdk_pixmap_create_from_xpm_d (templates->window, &mask,
4572 &style->bg[GTK_STATE_NORMAL],
4573 (gchar **)
4574 template_xpm[i][j]);
4575 pixmapwid = gtk_pixmap_new (pixmap, mask);
4576 gtk_widget_show (pixmapwid);
4577 gdk_pixmap_unref (pixmap);
4578 gtk_container_add (GTK_CONTAINER (tbutton[5 * i + j]), pixmapwid);
4579 gtk_widget_show (tbutton[5 * i + j]);
4580 gtk_table_attach_defaults (GTK_TABLE (pbox), tbutton[5 * i + j], (guint)j,
4581 (guint)j + 1, (guint)i, (guint)i + 1);
4582 tmplnum[5 * i + j] = 10 * i + j;
4583 (void)gtk_signal_connect (GTK_OBJECT (tbutton[5 * i + j]), "clicked",
4584 GTK_SIGNAL_FUNC (Add_template),
4585 GINT_TO_POINTER(tmplnum[5 * i + j]) );
4586 if ((int)strlen(template_tip[i][j]) >0 ) {
4587 #ifndef ENABLE_NLS
4588 gtk_tooltips_set_tip (temptips, tbutton[5 * i + j],
4589 template_tip[i][j], NULL);
4590 #else
4591 gtk_tooltips_set_tip (temptips, tbutton[5 * i + j],
4592 gettext(template_tip[i][j]), NULL);
4593 #endif
4594 }
4595 }
4596 }
4597 gtk_container_add (GTK_CONTAINER (page), pbox);
4598 label = gtk_label_new (_("Sugars"));
4599 gtk_widget_show (label);
4600 page = gtk_frame_new (_("Sugars"));
4601 gtk_widget_show (page);
4602 gtk_notebook_append_page (GTK_NOTEBOOK (templatebook), page, label);
4603 pbox = gtk_table_new (5, 5, TRUE);
4604 gtk_widget_show (pbox);
4605 for (i = 0; i < 5; i++)
4606 {
4607 for (j = 0; j < 5; j++)
4608 {
4609 tbutton[25 + 5 * i + j] = gtk_button_new ();
4610 style = gtk_widget_get_style (templates);
4611 pixmap = gdk_pixmap_create_from_xpm_d (templates->window, &mask,
4612 &style->bg[GTK_STATE_NORMAL],
4613 (gchar **) template_xpm[i +
4614 5]
4615 [j]);
4616 pixmapwid = gtk_pixmap_new (pixmap, mask);
4617 gtk_widget_show (pixmapwid);
4618 gdk_pixmap_unref (pixmap);
4619 gtk_container_add (GTK_CONTAINER (tbutton[25 + 5 * i + j]),
4620 pixmapwid);
4621 gtk_widget_show (tbutton[25 + 5 * i + j]);
4622 gtk_table_attach_defaults (GTK_TABLE (pbox),
4623 tbutton[25 + 5 * i + j], (guint)j, (guint)j + 1,
4624 (guint)i, (guint)i + 1);
4625 tmplnum[25 + 5 * i + j] = 10 * (i + 5) + j;
4626 (void)gtk_signal_connect (GTK_OBJECT (tbutton[25 + 5 * i + j]), "clicked",
4627 GTK_SIGNAL_FUNC (Add_template),
4628 GINT_TO_POINTER(tmplnum[25 + 5 * i + j]) );
4629 if ((int)strlen(template_tip[i+5][j]) >0 ) {
4630 #ifndef ENABLE_NLS
4631 gtk_tooltips_set_tip (temptips, tbutton[25 + 5 * i + j],
4632 template_tip[i + 5][j], NULL);
4633 #else
4634 gtk_tooltips_set_tip (temptips, tbutton[25 + 5 * i + j],
4635 gettext(template_tip[i + 5][j]), NULL);
4636 #endif
4637 }
4638 }
4639 }
4640 gtk_container_add (GTK_CONTAINER (page), pbox);
4641
4642 label = gtk_label_new (_("Heterocycles"));
4643 gtk_widget_show (label);
4644 page = gtk_frame_new (_("Heterocycles"));
4645 gtk_widget_show (page);
4646 gtk_notebook_append_page (GTK_NOTEBOOK (templatebook), page, label);
4647 pbox = gtk_table_new (5, 5, TRUE);
4648 gtk_widget_show (pbox);
4649 for (i = 0; i < 5; i++)
4650 {
4651 for (j = 0; j < 5; j++)
4652 {
4653 tbutton[50 + 5 * i + j] = gtk_button_new ();
4654 style = gtk_widget_get_style (templates);
4655 pixmap = gdk_pixmap_create_from_xpm_d (templates->window, &mask,
4656 &style->bg[GTK_STATE_NORMAL],
4657 (gchar **) template_xpm[i +
4658 10]
4659 [j]);
4660 pixmapwid = gtk_pixmap_new (pixmap, mask);
4661 gtk_widget_show (pixmapwid);
4662 gdk_pixmap_unref (pixmap);
4663 gtk_container_add (GTK_CONTAINER (tbutton[50 + 5 * i + j]),
4664 pixmapwid);
4665 gtk_widget_show (tbutton[50 + 5 * i + j]);
4666 gtk_table_attach_defaults (GTK_TABLE (pbox),
4667 tbutton[50 + 5 * i + j], (guint)j,
4668 (guint)j + 1, (guint)i,(guint)i + 1);
4669 tmplnum[50 + 5 * i + j] = 10 * (i + 10) + j;
4670 (void)gtk_signal_connect (GTK_OBJECT (tbutton[50 + 5 * i + j]), "clicked",
4671 GTK_SIGNAL_FUNC (Add_template),
4672 GINT_TO_POINTER(tmplnum[50 + 5 * i + j]) );
4673 if ((int)strlen(template_tip[i+10][j]) >0 ) {
4674 #ifndef ENABLE_NLS
4675 gtk_tooltips_set_tip (temptips, tbutton[50 + 5 * i + j],
4676 template_tip[i + 10][j], NULL);
4677 #else
4678 gtk_tooltips_set_tip (temptips, tbutton[50 + 5 * i + j],
4679 gettext(template_tip[i + 10][j]), NULL);
4680 #endif
4681 }
4682 }
4683 }
4684 gtk_container_add (GTK_CONTAINER (page), pbox);
4685
4686 label = gtk_label_new (_("Amino Acids"));
4687 gtk_widget_show (label);
4688 page = gtk_frame_new (_("Amino Acids"));
4689 gtk_widget_show (page);
4690 gtk_notebook_append_page (GTK_NOTEBOOK (templatebook), page, label);
4691 pbox = gtk_table_new (5, 5, TRUE);
4692 gtk_widget_show (pbox);
4693 for (i = 0; i < 5; i++)
4694 {
4695 for (j = 0; j < 5; j++)
4696 {
4697 tbutton[75 + 5 * i + j] = gtk_button_new ();
4698 style = gtk_widget_get_style (templates);
4699 pixmap = gdk_pixmap_create_from_xpm_d (templates->window, &mask,
4700 &style->bg[GTK_STATE_NORMAL],
4701 (gchar **) template_xpm[i +
4702 15]
4703 [j]);
4704 pixmapwid = gtk_pixmap_new (pixmap, mask);
4705 gtk_widget_show (pixmapwid);
4706 gdk_pixmap_unref (pixmap);
4707 gtk_container_add (GTK_CONTAINER (tbutton[75 + 5 * i + j]),
4708 pixmapwid);
4709 gtk_widget_show (tbutton[75 + 5 * i + j]);
4710 gtk_table_attach_defaults (GTK_TABLE (pbox),
4711 tbutton[75 + 5 * i + j],
4712 (guint)j, (guint)j + 1, (guint)i,
4713 (guint)i + 1);
4714 tmplnum[75 + 5 * i + j] = 10 * (i + 15) + j;
4715 (void)gtk_signal_connect (GTK_OBJECT (tbutton[75 + 5 * i + j]), "clicked",
4716 GTK_SIGNAL_FUNC (Add_template),
4717 GINT_TO_POINTER(tmplnum[75 + 5 * i + j]) );
4718 if ((int)strlen(template_tip[i+15][j]) >0 ) {
4719 #ifndef ENABLE_NLS
4720 gtk_tooltips_set_tip (temptips, tbutton[75 + 5 * i + j],
4721 template_tip[i + 15][j], NULL);
4722 #else
4723 gtk_tooltips_set_tip (temptips, tbutton[75 + 5 * i + j],
4724 gettext(template_tip[i + 15][j]), NULL);
4725 #endif
4726 }
4727 }
4728 }
4729 gtk_container_add (GTK_CONTAINER (page), pbox);
4730
4731 label = gtk_label_new (_("Symbols"));
4732 gtk_widget_show (label);
4733 page = gtk_frame_new (_("Symbols"));
4734 gtk_widget_show (page);
4735 gtk_notebook_append_page (GTK_NOTEBOOK (templatebook), page, label);
4736 pbox = gtk_table_new (5, 5, TRUE);
4737 gtk_widget_show (pbox);
4738 for (i = 0; i < 5; i++)
4739 {
4740 for (j = 0; j < 5; j++)
4741 {
4742 tbutton[100 + 5 * i + j] = gtk_button_new ();
4743 style = gtk_widget_get_style (templates);
4744 pixmap = gdk_pixmap_create_from_xpm_d (templates->window, &mask,
4745 &style->bg[GTK_STATE_NORMAL],
4746 (gchar **) template_xpm[i +
4747 20]
4748 [j]);
4749 pixmapwid = gtk_pixmap_new (pixmap, mask);
4750 gtk_widget_show (pixmapwid);
4751 gdk_pixmap_unref (pixmap);
4752 gtk_container_add (GTK_CONTAINER (tbutton[100 + 5 * i + j]),
4753 pixmapwid);
4754 gtk_widget_show (tbutton[100 + 5 * i + j]);
4755 gtk_table_attach_defaults (GTK_TABLE (pbox),
4756 tbutton[100 + 5 * i + j],
4757 (guint)j, (guint)j + 1, (guint)i,
4758 (guint)i + 1);
4759 tmplnum[100 + 5 * i + j] = 10 * (i + 20) + j;
4760 (void)gtk_signal_connect (GTK_OBJECT (tbutton[100 + 5 * i + j]), "clicked",
4761 GTK_SIGNAL_FUNC (Add_template),
4762 GINT_TO_POINTER(tmplnum[100 + 5 * i + j]) );
4763 if ((int)strlen(template_tip[i+20][j]) >0 ) {
4764 #ifndef ENABLE_NLS
4765 gtk_tooltips_set_tip (temptips, tbutton[100 + 5 * i + j],
4766 template_tip[i + 20][j], NULL);
4767 #else
4768 gtk_tooltips_set_tip (temptips, tbutton[100 + 5 * i + j],
4769 gettext(template_tip[i + 20][j]), NULL);
4770 #endif
4771 }
4772 }
4773 }
4774 gtk_container_add (GTK_CONTAINER (page), pbox);
4775
4776 gtk_widget_show (templatebook);
4777 gtk_box_pack_start (GTK_BOX (tvbox), templatebook, (gboolean) TRUE,
4778 (gboolean) TRUE, 0);
4779 button = gtk_button_new_with_label (_("Close"));
4780 gtk_widget_show (button);
4781 gtk_box_pack_start (GTK_BOX (tvbox), button, (gboolean) TRUE,
4782 (gboolean) TRUE, 0);
4783 (void)gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
4784 GTK_SIGNAL_FUNC (gtk_widget_hide),
4785 GTK_OBJECT (templates));
4786
4787 /**************************************************************/
4788
4789
4790 /*
4791 * Create the main window
4792 */
4793
4794 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
4795 gtk_widget_set_name (window, "Chemtool");
4796 gtk_window_set_title (GTK_WINDOW (window), "Chemtool 1.6.14");
4797
4798 /* all pop-ups should appear topmost and at the current cursor position,
4799 that is, near their respective toolbar buttons */
4800 gtk_window_set_transient_for (GTK_WINDOW (filew), GTK_WINDOW (window));
4801 gtk_window_set_position (GTK_WINDOW (filew), GTK_WIN_POS_MOUSE);
4802 gtk_window_set_transient_for (GTK_WINDOW (expw), GTK_WINDOW (window));
4803 gtk_window_set_position (GTK_WINDOW (expw), GTK_WIN_POS_MOUSE);
4804 gtk_window_set_transient_for (GTK_WINDOW (messagew), GTK_WINDOW (window));
4805 gtk_window_set_position (GTK_WINDOW (messagew), GTK_WIN_POS_MOUSE);
4806
4807 tooltips = gtk_tooltips_new (); /* initialize tool-tip message boxes */
4808
4809 /* initialize vertical stacking of button rows and drawing area */
4810 vbox = gtk_vbox_new (FALSE, 0);
4811 gtk_container_add (GTK_CONTAINER (window), vbox);
4812 gtk_widget_show (vbox);
4813
4814 (void)gtk_signal_connect (GTK_OBJECT (window), "delete_event",
4815 GTK_SIGNAL_FUNC (CheckAndQuit), NULL);
4816
4817 #ifdef MENU
4818 /* build the menubar */
4819
4820 accel_group = gtk_accel_group_new ();
4821
4822 /* the menuitems of the file-menu */
4823 file = gtk_menu_new ();
4824
4825 new = gtk_menu_item_new_with_label (_("New"));
4826 gtk_menu_append (GTK_MENU (file), new);
4827 (void)gtk_signal_connect_object (GTK_OBJECT (new), "activate",
4828 GTK_SIGNAL_FUNC (CheckAndClear), NULL);
4829 gtk_widget_add_accelerator (new, "activate", accel_group,
4830 GDK_N, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
4831 gtk_widget_show (new);
4832
4833 open = gtk_menu_item_new_with_label (_("Open"));
4834 gtk_menu_append (GTK_MENU (file), open);
4835 (void)gtk_signal_connect_object (GTK_OBJECT (open), "activate",
4836 GTK_SIGNAL_FUNC (CheckAndLoad), NULL);
4837 gtk_widget_add_accelerator (open, "activate", accel_group,
4838 GDK_O, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
4839 gtk_widget_show (open);
4840
4841 add = gtk_menu_item_new_with_label (_("Add"));
4842 gtk_menu_append (GTK_MENU (file), add);
4843 (void)gtk_signal_connect_object (GTK_OBJECT (add), "activate",
4844 GTK_SIGNAL_FUNC (Add), NULL);
4845 gtk_widget_add_accelerator (add, "activate", accel_group,
4846 GDK_A, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
4847 gtk_widget_show (add);
4848
4849 import = gtk_menu_item_new_with_label (_("Import MOL"));
4850 gtk_menu_append (GTK_MENU (file), import);
4851 (void)gtk_signal_connect_object (GTK_OBJECT (import), "activate",
4852 GTK_SIGNAL_FUNC (Import), NULL);
4853 gtk_widget_add_accelerator (import, "activate", accel_group,
4854 GDK_I, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
4855 gtk_widget_show (import);
4856
4857 imppdb = gtk_menu_item_new_with_label (_("Import PDB"));
4858 gtk_menu_append (GTK_MENU (file), imppdb);
4859 (void)gtk_signal_connect_object (GTK_OBJECT (imppdb), "activate",
4860 GTK_SIGNAL_FUNC (Import_PDB), NULL);
4861 gtk_widget_add_accelerator (imppdb, "activate", accel_group,
4862 GDK_P, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
4863 gtk_widget_show (imppdb);
4864
4865 impany = gtk_menu_item_new_with_label (_("Import (Babel)"));
4866 gtk_menu_append (GTK_MENU (file), impany);
4867 (void)gtk_signal_connect_object (GTK_OBJECT (impany), "activate",
4868 GTK_SIGNAL_FUNC (Import_Babel), NULL);
4869 gtk_widget_add_accelerator (impany, "activate", accel_group,
4870 GDK_B, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
4871 gtk_widget_show (impany);
4872 if (babelin<0) gtk_widget_set_sensitive(impany,FALSE);
4873 export = gtk_menu_item_new_with_label (_("Export..."));
4874 gtk_menu_append (GTK_MENU (file), export);
4875 (void)gtk_signal_connect_object (GTK_OBJECT (export), "activate",
4876 GTK_SIGNAL_FUNC (Export), NULL);
4877 gtk_widget_add_accelerator (export, "activate", accel_group,
4878 GDK_E, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
4879 gtk_widget_show (export);
4880
4881 expany = gtk_menu_item_new_with_label (_("Export (Babel)"));
4882 gtk_menu_append (GTK_MENU (file), expany);
4883 (void)gtk_signal_connect_object (GTK_OBJECT (expany), "activate",
4884 GTK_SIGNAL_FUNC (Export_Babel), NULL);
4885 gtk_widget_add_accelerator (expany, "activate", accel_group,
4886 GDK_X, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
4887 gtk_widget_show (expany);
4888 if (babelout<0) gtk_widget_set_sensitive(expany,FALSE);
4889
4890 printps = gtk_menu_item_new_with_label (_("Print"));
4891 gtk_menu_append (GTK_MENU (file), printps);
4892 (void)gtk_signal_connect_object (GTK_OBJECT (printps), "activate",
4893 GTK_SIGNAL_FUNC (print_ps), NULL);
4894 gtk_widget_add_accelerator (printps, "activate", accel_group,
4895 GDK_P, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
4896 gtk_widget_show (printps);
4897
4898 print_setup = gtk_menu_item_new_with_label (_("Setup Defaults"));
4899 gtk_menu_append (GTK_MENU (file), print_setup);
4900 #if (GTK_MINOR_VERSION >2)
4901 (void)gtk_signal_connect_object (GTK_OBJECT (print_setup), "activate",
4902 GTK_SIGNAL_FUNC (print_setup_menu_activate),
4903 NULL);
4904 #else
4905 (void)gtk_signal_connect_object (GTK_OBJECT (print_setup), "activate",
4906 GTK_SIGNAL_FUNC (gtk_widget_show),
4907 GTK_OBJECT (printer_dialog));
4908 #endif
4909 gtk_widget_add_accelerator (print_setup, "activate", accel_group,
4910 GDK_D, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
4911 gtk_widget_show (print_setup);
4912
4913 save_setup = gtk_menu_item_new_with_label (_("Save Config"));
4914 gtk_menu_append (GTK_MENU (file), save_setup);
4915 (void)gtk_signal_connect_object (GTK_OBJECT (save_setup), "activate",
4916 GTK_SIGNAL_FUNC (writerc), NULL);
4917 gtk_widget_add_accelerator (save_setup, "activate", accel_group,
4918 GDK_numbersign, GDK_CONTROL_MASK,
4919 GTK_ACCEL_VISIBLE);
4920 gtk_widget_show (save_setup);
4921
4922 save = gtk_menu_item_new_with_label (_("Save"));
4923 gtk_menu_append (GTK_MENU (file), save);
4924 (void)gtk_signal_connect_object (GTK_OBJECT (save), "activate",
4925 GTK_SIGNAL_FUNC (Save), NULL);
4926 gtk_widget_add_accelerator (save, "activate", accel_group,
4927 GDK_S, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
4928 gtk_widget_show (save);
4929
4930 saveas = gtk_menu_item_new_with_label (_("Save As..."));
4931 gtk_menu_append (GTK_MENU (file), saveas);
4932 (void)gtk_signal_connect_object (GTK_OBJECT (saveas), "activate",
4933 GTK_SIGNAL_FUNC (SaveAs), NULL);
4934 /* gtk_widget_add_accelerator (saveas, "activate", accel_group,
4935 GDK_F4, 0,
4936 GTK_ACCEL_VISIBLE); */
4937 gtk_widget_show (saveas);
4938
4939 quit = gtk_menu_item_new_with_label (_("Quit"));
4940 gtk_menu_append (GTK_MENU (file), quit);
4941 (void)gtk_signal_connect_object (GTK_OBJECT (quit), "activate",
4942 GTK_SIGNAL_FUNC (CheckAndQuit), NULL);
4943 gtk_widget_add_accelerator (quit, "activate", accel_group,
4944 GDK_Q, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
4945 gtk_widget_show (quit);
4946
4947 file_menu = gtk_menu_item_new_with_label (_("File"));
4948 gtk_menu_item_set_submenu (GTK_MENU_ITEM (file_menu), file);
4949 gtk_widget_show (file_menu);
4950
4951 /* the menuitems of the edit-menu */
4952 edit = gtk_menu_new ();
4953
4954 copy = gtk_menu_item_new_with_label (_("Copy"));
4955 gtk_menu_append (GTK_MENU (edit), copy);
4956 (void)gtk_signal_connect (GTK_OBJECT (copy), "activate",
4957 GTK_SIGNAL_FUNC (copy_obj), GTK_OBJECT (window));
4958 /* (void)gtk_signal_connect (GTK_OBJECT (copy), "activate",
4959 GTK_SIGNAL_FUNC (gtk_toggle_button_set_active),
4960 GTK_OBJECT (movebutton));*/
4961
4962 gtk_widget_add_accelerator (copy, "activate", accel_group,
4963 GDK_V, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
4964 gtk_widget_show (copy);
4965
4966 fliph = gtk_menu_item_new_with_label (_("Flip horizontally"));
4967 gtk_menu_append (GTK_MENU (edit), fliph);
4968 (void)gtk_signal_connect (GTK_OBJECT (fliph), "activate",
4969 GTK_SIGNAL_FUNC (flip_horiz), GTK_OBJECT (window));
4970 gtk_widget_show (fliph);
4971
4972 flipv = gtk_menu_item_new_with_label (_("Flip vertically"));
4973 gtk_menu_append (GTK_MENU (edit), flipv);
4974 (void)gtk_signal_connect (GTK_OBJECT (flipv), "activate",
4975 GTK_SIGNAL_FUNC (flip_vert), GTK_OBJECT (window));
4976 gtk_widget_show (flipv);
4977
4978 #ifdef LIBUNDO
4979 undo = gtk_menu_item_new_with_label (_("Undo"));
4980 gtk_menu_append (GTK_MENU (edit), undo);
4981 (void)gtk_signal_connect (GTK_OBJECT (undo), "activate",
4982 GTK_SIGNAL_FUNC (do_undo), GTK_OBJECT (window));
4983
4984 gtk_widget_add_accelerator (undo, "activate", accel_group,
4985 GDK_U, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
4986 gtk_widget_show (undo);
4987 redo = gtk_menu_item_new_with_label (_("Redo"));
4988 gtk_menu_append (GTK_MENU (edit), redo);
4989 (void)gtk_signal_connect (GTK_OBJECT (redo), "activate",
4990 GTK_SIGNAL_FUNC (do_redo), GTK_OBJECT (window));
4991
4992 gtk_widget_add_accelerator (redo, "activate", accel_group,
4993 GDK_R, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
4994 gtk_widget_show (redo);
4995 #endif
4996
4997 edit_menu = gtk_menu_item_new_with_label (_("Edit"));
4998 gtk_menu_item_set_submenu (GTK_MENU_ITEM (edit_menu), edit);
4999 gtk_widget_show (edit_menu);
5000
5001 /* the menuitems of the view-menu */
5002 view = gtk_menu_new ();
5003
5004 zoomin = gtk_menu_item_new_with_label (_("Zoom in"));
5005 gtk_menu_append (GTK_MENU (view), zoomin);
5006 (void)gtk_signal_connect (GTK_OBJECT (zoomin), "activate",
5007 GTK_SIGNAL_FUNC (Zoom), "0");
5008 gtk_widget_show (zoomin);
5009
5010 zoomout = gtk_menu_item_new_with_label (_("Zoom out"));
5011 gtk_menu_append (GTK_MENU (view), zoomout);
5012 (void)gtk_signal_connect (GTK_OBJECT (zoomout), "activate",
5013 GTK_SIGNAL_FUNC (Zoom), "1");
5014 gtk_widget_show (zoomout);
5015
5016 gtk_widget_add_accelerator (zoomin, "activate", accel_group,
5017 GDK_equal, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
5018 gtk_widget_add_accelerator (zoomout, "activate", accel_group,
5019 GDK_minus, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
5020
5021 center = gtk_menu_item_new_with_label (_("Center"));
5022 gtk_menu_append (GTK_MENU (view), center);
5023 (void)gtk_signal_connect (GTK_OBJECT (center), "activate",
5024 GTK_SIGNAL_FUNC (Center), GTK_OBJECT (window));
5025 gtk_widget_add_accelerator (center, "activate", accel_group,
5026 GDK_C, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
5027 gtk_widget_show (center);
5028
5029 grid = gtk_menu_item_new_with_label (_("Grid rect/rhomb/off"));
5030 gtk_menu_append (GTK_MENU (view), grid);
5031 (void)gtk_signal_connect (GTK_OBJECT (grid), "activate",
5032 GTK_SIGNAL_FUNC (Grid), GTK_OBJECT (window));
5033 gtk_widget_show (grid);
5034
5035 view_menu = gtk_menu_item_new_with_label (_("View"));
5036 gtk_menu_item_set_submenu (GTK_MENU_ITEM (view_menu), view);
5037 gtk_widget_show (view_menu);
5038
5039 /* the menuitems of the tools-menu */
5040
5041 tools = gtk_menu_new ();
5042
5043 templatem = gtk_menu_item_new_with_label (_("Templates..."));
5044 gtk_menu_append (GTK_MENU (tools), templatem);
5045 (void)gtk_signal_connect_object (GTK_OBJECT (templatem), "activate",
5046 GTK_SIGNAL_FUNC (show_or_raise),
5047 GTK_OBJECT (templates));
5048 gtk_widget_add_accelerator (templatem, "activate", accel_group,
5049 GDK_T, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
5050 gtk_widget_show (templatem);
5051
5052 cht = gtk_menu_item_new_with_label (_("Calculate Formula Weight"));
5053 gtk_menu_append (GTK_MENU (tools), cht);
5054 (void)gtk_signal_connect (GTK_OBJECT (cht), "activate",
5055 GTK_SIGNAL_FUNC (do_fw), NULL);
5056 gtk_widget_add_accelerator (cht, "activate", accel_group,
5057 GDK_F, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
5058 gtk_widget_show (cht);
5059
5060 clean = gtk_menu_item_new_with_label (_("Clean up drawing"));
5061 gtk_menu_append (GTK_MENU (tools), clean);
5062 (void)gtk_signal_connect (GTK_OBJECT (clean), "activate",
5063 GTK_SIGNAL_FUNC (tidy_mol), NULL);
5064 gtk_widget_show (clean);
5065
5066 tools_menu = gtk_menu_item_new_with_label (_("Tools"));
5067 gtk_menu_item_set_submenu (GTK_MENU_ITEM (tools_menu), tools);
5068 gtk_widget_show (tools_menu);
5069
5070
5071 /* the menuitems of the help-menu */
5072 help = gtk_menu_new ();
5073
5074 about = gtk_menu_item_new_with_label (_("About"));
5075 gtk_menu_append (GTK_MENU (help), about);
5076 (void)gtk_signal_connect_object (GTK_OBJECT (about), "activate",
5077 GTK_SIGNAL_FUNC (gtk_widget_show),
5078 GTK_OBJECT (aboutw));
5079 /* gtk_widget_add_accelerator (about, "activate", accel_group,
5080 GDK_F1, 0, GTK_ACCEL_VISIBLE);*/
5081 gtk_widget_show (about);
5082
5083 using = gtk_menu_item_new_with_label (_("Help"));
5084 gtk_menu_append (GTK_MENU (help), using);
5085 (void)gtk_signal_connect_object (GTK_OBJECT (using), "activate",
5086 GTK_SIGNAL_FUNC (gtk_widget_show),
5087 GTK_OBJECT (helpw));
5088 gtk_widget_add_accelerator (using, "activate", accel_group,
5089 GDK_F1, 0, GTK_ACCEL_VISIBLE);
5090 gtk_widget_show (using);
5091
5092 help_menu = gtk_menu_item_new_with_label (_("Help"));
5093 gtk_menu_item_set_submenu (GTK_MENU_ITEM (help_menu), help);
5094 gtk_widget_show (help_menu);
5095
5096 /* build the menubar */
5097 menu_bar = gtk_menu_bar_new ();
5098 gtk_box_pack_start (GTK_BOX (vbox), menu_bar, (gboolean) FALSE,
5099 (gboolean) FALSE, 2);
5100 gtk_widget_show (menu_bar);
5101 gtk_menu_bar_append (GTK_MENU_BAR (menu_bar), file_menu);
5102 gtk_menu_bar_append (GTK_MENU_BAR (menu_bar), edit_menu);
5103 gtk_menu_bar_append (GTK_MENU_BAR (menu_bar), view_menu);
5104 gtk_menu_bar_append (GTK_MENU_BAR (menu_bar), tools_menu);
5105 gtk_menu_item_right_justify (GTK_MENU_ITEM (help_menu));
5106 gtk_menu_bar_append (GTK_MENU_BAR (menu_bar), help_menu);
5107
5108 gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
5109 #else
5110
5111 /* initialize horizontal packing of the first row of buttons */
5112 /* define the first row of buttons, with label,callback and tooltip text */
5113 /* Load | Add | Save | Import | Export | ZoomIn | Center | ZoomOut | Clear | Quit | About */
5114 hbox = gtk_hbox_new (TRUE, 0);
5115 loadbutton = gtk_button_new_with_label (_("Load"));
5116 gtk_box_pack_start (GTK_BOX (hbox), loadbutton, (gboolean) FALSE,
5117 (gboolean) TRUE, 0);
5118 (void)gtk_signal_connect_object (GTK_OBJECT (loadbutton), "clicked",
5119 GTK_SIGNAL_FUNC (CheckAndLoad), NULL);
5120 gtk_tooltips_set_tip (tooltips, loadbutton, _("Load a chemtool sketch"),
5121 NULL);
5122 gtk_widget_show (loadbutton);
5123
5124 addbutton = gtk_button_new_with_label (_("Add"));
5125 gtk_box_pack_start (GTK_BOX (hbox), addbutton, (gboolean) TRUE,
5126 (gboolean) TRUE, 0);
5127 (void)gtk_signal_connect_object (GTK_OBJECT (addbutton), "clicked",
5128 GTK_SIGNAL_FUNC (Add), NULL);
5129 gtk_tooltips_set_tip (tooltips, addbutton, _("Add fragment from file"),
5130 NULL);
5131 gtk_widget_show (addbutton);
5132 tempbutton = gtk_button_new_with_label (_("Templates"));
5133 gtk_box_pack_start (GTK_BOX (hbox), tempbutton, (gboolean) TRUE,
5134 (gboolean) TRUE, 0);
5135 (void)gtk_signal_connect_object (GTK_OBJECT (tempbutton), "clicked",
5136 GTK_SIGNAL_FUNC (show_or_raise),
5137 GTK_OBJECT (templates));
5138 gtk_tooltips_set_tip (tooltips, tempbutton, _("Add template structure"),
5139 NULL);
5140 gtk_widget_show (tempbutton);
5141 savebutton = gtk_button_new_with_label (_("Save"));
5142 gtk_box_pack_start (GTK_BOX (hbox), savebutton, (gboolean) TRUE,
5143 (gboolean) TRUE, 0);
5144 (void)gtk_signal_connect_object (GTK_OBJECT (savebutton), "clicked",
5145 GTK_SIGNAL_FUNC (Save), NULL);
5146 gtk_tooltips_set_tip (tooltips, savebutton, _("Save sketch to file"), NULL);
5147 gtk_widget_show (savebutton);
5148
5149 exportbutton = gtk_button_new_with_label (_("Export"));
5150 gtk_box_pack_start (GTK_BOX (hbox), exportbutton, (gboolean) TRUE,
5151 (gboolean) TRUE, 0);
5152 (void)gtk_signal_connect_object (GTK_OBJECT (exportbutton), "clicked",
5153 GTK_SIGNAL_FUNC (Export), NULL);
5154 (void)gtk_signal_connect (GTK_OBJECT (exportbutton), "clicked",
5155 GTK_SIGNAL_FUNC (gtk_file_selection_set_filename),
5156 GTK_OBJECT (expw));
5157 gtk_tooltips_set_tip (tooltips, exportbutton,
5158 _("Create EPS, XFig, PicTeX or XBM file"), NULL);
5159 gtk_widget_show (exportbutton);
5160
5161 printbutton = gtk_button_new_with_label (_("Print"));
5162 gtk_box_pack_start (GTK_BOX (hbox), printbutton, (gboolean) TRUE,
5163 (gboolean) TRUE, 0);
5164 (void)gtk_signal_connect_object (GTK_OBJECT (printbutton), "clicked",
5165 GTK_SIGNAL_FUNC (print_ps), NULL);
5166 gtk_tooltips_set_tip (tooltips, printbutton,
5167 _("Print file to a postscript printer"), NULL);
5168 gtk_widget_show (printbutton);
5169
5170 psetupbutton = gtk_button_new_with_label (_("Setup"));
5171 gtk_box_pack_start (GTK_BOX (hbox), psetupbutton, (gboolean) TRUE,
5172 (gboolean) TRUE, 0);
5173 (void)gtk_signal_connect_object (GTK_OBJECT (psetupbutton), "clicked",
5174 GTK_SIGNAL_FUNC (gtk_widget_show),
5175 GTK_OBJECT (printer_dialog));
5176 gtk_tooltips_set_tip (tooltips, psetupbutton,
5177 _("Setup default options"), NULL);
5178 gtk_widget_show (psetupbutton);
5179
5180 savesetupbutton = gtk_button_new_with_label (_("Save Config"));
5181 gtk_box_pack_start (GTK_BOX (hbox), savesetupbutton, (gboolean) TRUE,
5182 (gboolean) TRUE, 0);
5183 (void)gtk_signal_connect_object (GTK_OBJECT (savesetupbutton), "clicked",
5184 GTK_SIGNAL_FUNC (writerc), NULL);
5185 gtk_tooltips_set_tip (tooltips, savesetupbutton,
5186 _("Save default options"), NULL);
5187 gtk_widget_show (savesetupbutton);
5188
5189 importbutton = gtk_button_new_with_label (_("Import"));
5190 gtk_box_pack_start (GTK_BOX (hbox), importbutton, (gboolean) TRUE,
5191 (gboolean) TRUE, 0);
5192 (void)gtk_signal_connect_object (GTK_OBJECT (importbutton), "clicked",
5193 GTK_SIGNAL_FUNC (Import), NULL);
5194 gtk_tooltips_set_tip (tooltips, importbutton,
5195 _("Read a file written in MDL/molfile format"), NULL);
5196 gtk_widget_show (importbutton);
5197
5198 imppdbbutton = gtk_button_new_with_label (_("ImportPDB"));
5199 gtk_box_pack_start (GTK_BOX (hbox), imppdbbutton, (gboolean) TRUE,
5200 (gboolean) TRUE, 0);
5201 (void)gtk_signal_connect_object (GTK_OBJECT (imppdbbutton), "clicked",
5202 GTK_SIGNAL_FUNC (Import_PDB), NULL);
5203 gtk_tooltips_set_tip (tooltips, imppdbbutton,
5204 _("Read a file written in PDB format"), NULL);
5205 gtk_widget_show (imppdbbutton);
5206
5207 zoominbutton = gtk_button_new_with_label (_("Zoom In"));
5208 gtk_box_pack_start (GTK_BOX (hbox), zoominbutton, (gboolean) FALSE,
5209 (gboolean) TRUE, 0);
5210 (void)gtk_signal_connect (GTK_OBJECT (zoominbutton), "clicked",
5211 GTK_SIGNAL_FUNC (Zoom), "0");
5212 gtk_tooltips_set_tip (tooltips, zoominbutton, _("Increase zoom scale"),
5213 NULL);
5214 gtk_widget_show (zoominbutton);
5215
5216 centerbutton = gtk_button_new_with_label (_("Center"));
5217 gtk_box_pack_start (GTK_BOX (hbox), centerbutton, (gboolean) FALSE,
5218 (gboolean) TRUE, 0);
5219 (void)gtk_signal_connect (GTK_OBJECT (centerbutton), "clicked",
5220 GTK_SIGNAL_FUNC (Center), GTK_OBJECT (window));
5221 gtk_tooltips_set_tip (tooltips, centerbutton,
5222 _("Center molecule in drawing area"), NULL);
5223 gtk_widget_show (centerbutton);
5224
5225 zoomoutbutton = gtk_button_new_with_label (_("Zoom Out"));
5226 gtk_box_pack_start (GTK_BOX (hbox), zoomoutbutton, (gboolean) FALSE,
5227 (gboolean) TRUE, 0);
5228 (void)gtk_signal_connect (GTK_OBJECT (zoomoutbutton), "clicked",
5229 GTK_SIGNAL_FUNC (Zoom), "1");
5230 gtk_tooltips_set_tip (tooltips, zoomoutbutton, _("Decrease zoom scale"),
5231 NULL);
5232 gtk_widget_show (zoomoutbutton);
5233
5234 clearbutton = gtk_button_new_with_label (_("Clear"));
5235 gtk_box_pack_start (GTK_BOX (hbox), clearbutton, (gboolean) FALSE,
5236 (gboolean) TRUE, 0);
5237 (void)gtk_signal_connect (GTK_OBJECT (clearbutton), "clicked",
5238 GTK_SIGNAL_FUNC (CheckAndClear), NULL);
5239 gtk_tooltips_set_tip (tooltips, clearbutton, _("Remove molecule"), NULL);
5240 gtk_widget_show (clearbutton);
5241
5242 fwbutton = gtk_button_new_with_label (_("FW"));
5243 gtk_box_pack_start (GTK_BOX (hbox), fwbutton, (gboolean) FALSE,
5244 (gboolean) TRUE, 0);
5245 (void)gtk_signal_connect (GTK_OBJECT (fwbutton), "clicked",
5246 GTK_SIGNAL_FUNC (do_fw), NULL);
5247 gtk_tooltips_set_tip (tooltips, fwbutton, _("Calculate Formula Mass"),
5248 NULL);
5249 gtk_widget_show (fwbutton);
5250
5251 quitbutton = gtk_button_new_with_label (_("Quit"));
5252 gtk_box_pack_start (GTK_BOX (hbox), quitbutton, (gboolean) FALSE,
5253 (gboolean) TRUE, 0);
5254 (void)gtk_signal_connect (GTK_OBJECT (quitbutton), "clicked",
5255 GTK_SIGNAL_FUNC (CheckAndQuit), NULL);
5256 gtk_tooltips_set_tip (tooltips, quitbutton, _("Exit Chemtool"), NULL);
5257 gtk_widget_show (quitbutton);
5258
5259 aboutbutton = gtk_button_new_with_label (_("About"));
5260 gtk_box_pack_end (GTK_BOX (hbox), aboutbutton, (gboolean) FALSE,
5261 (gboolean) TRUE, 0);
5262 (void)gtk_signal_connect_object (GTK_OBJECT (aboutbutton), "clicked",
5263 GTK_SIGNAL_FUNC (gtk_widget_show),
5264 GTK_OBJECT (aboutw));
5265 gtk_tooltips_set_tip (tooltips, aboutbutton, _("About Chemtool"), NULL);
5266 gtk_widget_show (aboutbutton);
5267 gtk_box_pack_start (GTK_BOX (vbox), hbox, (gboolean) FALSE,
5268 (gboolean) FALSE, 0);
5269 gtk_widget_show (hbox);
5270
5271 #endif /* menubar or button row */
5272
5273 /* end top row */
5274 /* initialize horizontal packing of second row of buttons */
5275 #ifdef GTK2
5276 hbox = gtk_hbox_new (FALSE, 4);
5277 #else
5278 hbox = gtk_hbox_new (FALSE, 5);
5279 #endif
5280
5281 gtk_widget_realize (window);
5282 /* complete setup of base window, but do not show it yet - we just
5283 need a pointer to it and its color settings for the button pixmaps */
5284
5285 /* Second row has pixmap icons for line drawing on hexagonal, pentagonal
5286 (two orientations) and octagonal grid; left-justfied,centered and
5287 right-justified text; bondtype, move, mark and rotate mode;
5288 vertical and horizontal flipping; copying; and a text entry box */
5289
5290 style = gtk_widget_get_style (window);
5291
5292 pixmap = gdk_pixmap_create_from_xpm_d (window->window, &mask,
5293 &style->bg[GTK_STATE_NORMAL],
5294 (gchar **) xpm_hex);
5295 pixmapwid = gtk_pixmap_new (pixmap, mask);
5296 gtk_widget_show (pixmapwid);
5297 gdk_pixmap_unref (pixmap);
5298
5299 hexbutton = gtk_toggle_button_new ();
5300 gtk_container_add (GTK_CONTAINER (hexbutton), pixmapwid);
5301 gtk_box_pack_start (GTK_BOX (hbox), hexbutton, (gboolean) FALSE,
5302 (gboolean) TRUE, 0);
5303 (void)gtk_signal_connect (GTK_OBJECT (hexbutton), "clicked",
5304 GTK_SIGNAL_FUNC (Change_Angle), "1");
5305 gtk_tooltips_set_tip (tooltips, hexbutton,
5306 _("Draw at 0/30/60/90 degree angles"), NULL);
5307 gtk_widget_show (hexbutton);
5308
5309 pent1button = gtk_toggle_button_new ();
5310 pixmap = gdk_pixmap_create_from_xpm_d (window->window, &mask,
5311 &style->bg[GTK_STATE_NORMAL],
5312 (gchar **) xpm_pent1);
5313 pixmapwid = gtk_pixmap_new (pixmap, mask);
5314 gtk_widget_show (pixmapwid);
5315 gdk_pixmap_unref (pixmap);
5316 gtk_container_add (GTK_CONTAINER (pent1button), pixmapwid);
5317 gtk_box_pack_start (GTK_BOX (hbox), pent1button, (gboolean) FALSE,
5318 (gboolean) TRUE, 0);
5319 (void)gtk_signal_connect (GTK_OBJECT (pent1button), "clicked",
5320 GTK_SIGNAL_FUNC (Change_Angle), "2");
5321 gtk_tooltips_set_tip (tooltips, pent1button,
5322 _("Draw at 0/36/72/... degree angles"), NULL);
5323 #ifdef MENU
5324 gtk_widget_add_accelerator (pent1button, "clicked", accel_group,
5325 GDK_F5, 0, GTK_ACCEL_VISIBLE);
5326
5327 #endif
5328 gtk_widget_show (pent1button);
5329
5330 pent2button = gtk_toggle_button_new ();
5331 pixmap = gdk_pixmap_create_from_xpm_d (window->window, &mask,
5332 &style->bg[GTK_STATE_NORMAL],
5333 (gchar **) xpm_pent2);
5334 pixmapwid = gtk_pixmap_new (pixmap, mask);
5335 gtk_widget_show (pixmapwid);
5336 gdk_pixmap_unref (pixmap);
5337
5338 gtk_container_add (GTK_CONTAINER (pent2button), pixmapwid);
5339 gtk_box_pack_start (GTK_BOX (hbox), pent2button, (gboolean) FALSE,
5340 (gboolean) TRUE, 0);
5341 (void)gtk_signal_connect (GTK_OBJECT (pent2button), "clicked",
5342 GTK_SIGNAL_FUNC (Change_Angle), "3");
5343 gtk_tooltips_set_tip (tooltips, pent2button,
5344 _("Draw at 18/54/90/... degree angles"), NULL);
5345 gtk_widget_show (pent2button);
5346
5347 octbutton = gtk_toggle_button_new ();
5348 pixmap = gdk_pixmap_create_from_xpm_d (window->window, &mask,
5349 &style->bg[GTK_STATE_NORMAL],
5350 (gchar **) xpm_octa);
5351 pixmapwid = gtk_pixmap_new (pixmap, mask);
5352 gtk_widget_show (pixmapwid);
5353 gdk_pixmap_unref (pixmap);
5354
5355 gtk_container_add (GTK_CONTAINER (octbutton), pixmapwid);
5356 gtk_box_pack_start (GTK_BOX (hbox), octbutton, (gboolean) FALSE,
5357 (gboolean) TRUE, 0);
5358 (void)gtk_signal_connect (GTK_OBJECT (octbutton), "clicked",
5359 GTK_SIGNAL_FUNC (Change_Angle), "4");
5360 gtk_tooltips_set_tip (tooltips, octbutton,
5361 _("Draw at 0/45/90... degree angles"), NULL);
5362 gtk_widget_show (octbutton);
5363
5364 splinebutton = gtk_toggle_button_new ();
5365 pixmap = gdk_pixmap_create_from_xpm_d (window->window, &mask,
5366 &style->bg[GTK_STATE_NORMAL],
5367 (gchar **) xpm_spline);
5368 pixmapwid = gtk_pixmap_new (pixmap, mask);
5369 gtk_widget_show (pixmapwid);
5370 gdk_pixmap_unref (pixmap);
5371
5372 gtk_container_add (GTK_CONTAINER (splinebutton), pixmapwid);
5373 gtk_box_pack_start (GTK_BOX (hbox), splinebutton, (gboolean) FALSE,
5374 (gboolean) TRUE, 0);
5375 (void)gtk_signal_connect (GTK_OBJECT (splinebutton), "clicked",
5376 GTK_SIGNAL_FUNC (Splinemode), NULL);
5377 gtk_tooltips_set_tip (tooltips, splinebutton,
5378 _("Draw curves based on 4 control points"), NULL);
5379 gtk_widget_show (splinebutton);
5380
5381 ltextbutton = gtk_toggle_button_new ();
5382 pixmap = gdk_pixmap_create_from_xpm_d (window->window, &mask,
5383 &style->bg[GTK_STATE_NORMAL],
5384 (gchar **) xpm_ltext);
5385 pixmapwid = gtk_pixmap_new (pixmap, mask);
5386 gtk_widget_show (pixmapwid);
5387 gdk_pixmap_unref (pixmap);
5388
5389 gtk_container_add (GTK_CONTAINER (ltextbutton), pixmapwid);
5390 gtk_box_pack_start (GTK_BOX (hbox), ltextbutton, (gboolean) FALSE,
5391 (gboolean) TRUE, 0);
5392 (void)gtk_signal_connect (GTK_OBJECT (ltextbutton), "clicked",
5393 GTK_SIGNAL_FUNC (Change_Text), "0");
5394 gtk_tooltips_set_tip (tooltips, ltextbutton, _("Draw left-justified text"),
5395 NULL);
5396 gtk_widget_show (ltextbutton);
5397
5398 ctextbutton = gtk_toggle_button_new ();
5399 pixmap = gdk_pixmap_create_from_xpm_d (window->window, &mask,
5400 &style->bg[GTK_STATE_NORMAL],
5401 (gchar **) xpm_mtext);
5402 pixmapwid = gtk_pixmap_new (pixmap, mask);
5403 gtk_widget_show (pixmapwid);
5404 gdk_pixmap_unref (pixmap);
5405
5406 gtk_container_add (GTK_CONTAINER (ctextbutton), pixmapwid);
5407 gtk_box_pack_start (GTK_BOX (hbox), ctextbutton, (gboolean) FALSE,
5408 (gboolean) TRUE, 0);
5409 (void)gtk_signal_connect (GTK_OBJECT (ctextbutton), "clicked",
5410 GTK_SIGNAL_FUNC (Change_Text), "-1");
5411 gtk_tooltips_set_tip (tooltips, ctextbutton, _("Draw centered text"), NULL);
5412 gtk_widget_show (ctextbutton);
5413
5414
5415 rtextbutton = gtk_toggle_button_new ();
5416 pixmap = gdk_pixmap_create_from_xpm_d (window->window, &mask,
5417 &style->bg[GTK_STATE_NORMAL],
5418 (gchar **) xpm_rtext);
5419 pixmapwid = gtk_pixmap_new (pixmap, mask);
5420 gtk_widget_show (pixmapwid);
5421 gdk_pixmap_unref (pixmap);
5422
5423 gtk_container_add (GTK_CONTAINER (rtextbutton), pixmapwid);
5424 gtk_box_pack_start (GTK_BOX (hbox), rtextbutton, (gboolean) FALSE,
5425 (gboolean) TRUE, 0);
5426 (void)gtk_signal_connect (GTK_OBJECT (rtextbutton), "clicked",
5427 GTK_SIGNAL_FUNC (Change_Text), "-2");
5428 gtk_tooltips_set_tip (tooltips, rtextbutton, _("Draw right-justified text"),
5429 NULL);
5430 gtk_widget_show (rtextbutton);
5431
5432 fontbutton = gtk_button_new ();
5433 pixmap = gdk_pixmap_create_from_xpm_d (window->window, &mask,
5434 &style->bg[GTK_STATE_NORMAL],
5435 (gchar **) xpm_font);
5436 pixmapwid = gtk_pixmap_new (pixmap, mask);
5437 gtk_widget_show (pixmapwid);
5438 gdk_pixmap_unref (pixmap);
5439 #if 0
5440 fontselw=gtk_window_new(GTK_WINDOW_TOPLEVEL);
5441 fontsel=gtk_font_selection_new();
5442 gtk_widget_show(fontsel);
5443 gtk_container_add(GTK_CONTAINER(fontselw),fontsel);
5444 gtk_widget_realize(fontselw);
5445 #endif
5446 gtk_container_add (GTK_CONTAINER (fontbutton), pixmapwid);
5447 gtk_box_pack_start (GTK_BOX (hbox), fontbutton, (gboolean) FALSE,
5448 (gboolean) TRUE, 0);
5449 #if 0
5450 (void)gtk_signal_connect_object (GTK_OBJECT (fontbutton), "clicked",
5451 GTK_SIGNAL_FUNC(gtk_widget_show), GTK_OBJECT(fontselw));
5452 #else
5453 (void)gtk_signal_connect (GTK_OBJECT (fontbutton), "clicked",
5454 GTK_SIGNAL_FUNC (Change_Font), NULL);
5455 #endif
5456 gtk_tooltips_set_tip (tooltips, fontbutton, _("Set current textfont"),
5457 NULL);
5458 gtk_widget_show (fontbutton);
5459
5460 bondomenu = gtk_option_menu_new ();
5461 bondmenu = gtk_menu_new ();
5462 group = NULL;
5463 for (i = 0; i < BONDTYPES; i++)
5464 {
5465 int ii = i;
5466
5467 menuitem = gtk_menu_item_new();
5468 pixmap = gdk_pixmap_create_from_xpm_d (window->window, &mask,
5469 &style->bg[GTK_STATE_NORMAL],
5470 (gchar **) xpm_bond[i]);
5471 pixmapwid = gtk_pixmap_new (pixmap, mask);
5472 gtk_widget_show (pixmapwid);
5473 gdk_pixmap_unref (pixmap);
5474 gtk_container_add (GTK_CONTAINER (menuitem), pixmapwid);
5475 gtk_container_set_border_width (GTK_CONTAINER (menuitem), 0);
5476
5477 gtk_menu_append (GTK_MENU (bondmenu), menuitem);
5478 gtk_widget_show (menuitem);
5479 snprintf (bondnums[i],3, "%d", ii);
5480 (void)gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
5481 GTK_SIGNAL_FUNC (set_bond), bondnums[i]);
5482 }
5483 gtk_option_menu_set_menu (GTK_OPTION_MENU (bondomenu), bondmenu);
5484 gtk_box_pack_start (GTK_BOX (hbox), bondomenu, (gboolean) FALSE,
5485 (gboolean) TRUE, 0);
5486 gtk_tooltips_set_tip (tooltips, bondomenu, _("Choose default bond type"),
5487 NULL);
5488 gtk_widget_show (bondomenu);
5489
5490 penmenu = gtk_menu_new ();
5491 group = NULL;
5492 for (i = 0; i < BONDCOLORS; i++)
5493 {
5494 int ii = i;
5495
5496 menuitem = gtk_menu_item_new();
5497 pixmap = gdk_pixmap_create_from_xpm_d (window->window, &mask,
5498 &style->bg[GTK_STATE_NORMAL],
5499 (gchar **) xpm_color[i]);
5500 pixmapwid = gtk_pixmap_new (pixmap, mask);
5501 gtk_widget_show (pixmapwid);
5502 gdk_pixmap_unref (pixmap);
5503 gtk_container_add (GTK_CONTAINER (menuitem), pixmapwid);
5504 gtk_container_set_border_width (GTK_CONTAINER (menuitem), 0);
5505
5506 gtk_menu_append (GTK_MENU (penmenu), menuitem);
5507 gtk_widget_show (menuitem);
5508 snprintf (bondcolors[i],3, "%d", ii);
5509 (void)gtk_signal_connect (GTK_OBJECT (menuitem), "activate",
5510 GTK_SIGNAL_FUNC (change_color), bondcolors[i]);
5511 }
5512 colorbutton= gtk_button_new();
5513 pixmap = gdk_pixmap_create_from_xpm_d (window->window, &mask,
5514 &style->bg[GTK_STATE_NORMAL],
5515 (gchar **) xpm_color);
5516 pixmapwid = gtk_pixmap_new (pixmap, mask);
5517 gtk_widget_show (pixmapwid);
5518 gdk_pixmap_unref (pixmap);
5519 gtk_container_add (GTK_CONTAINER (colorbutton), pixmapwid);
5520 gtk_box_pack_start (GTK_BOX (hbox), colorbutton, (gboolean) FALSE,
5521 (gboolean) TRUE, 0);
5522 (void)gtk_signal_connect_object (GTK_OBJECT (colorbutton), "clicked",
5523 GTK_SIGNAL_FUNC (show_penmenu), NULL);
5524 gtk_tooltips_set_tip (tooltips, colorbutton,
5525 _("Select pen color"),
5526 NULL);
5527 oldpixmap=pixmapwid;
5528 gtk_widget_show (colorbutton);
5529
5530 bondbutton = gtk_toggle_button_new_with_label (_("Bonds"));
5531 gtk_box_pack_start (GTK_BOX (hbox), bondbutton, (gboolean) FALSE,
5532 (gboolean) TRUE, 0);
5533 (void)gtk_signal_connect (GTK_OBJECT (bondbutton), "clicked",
5534 GTK_SIGNAL_FUNC (Bondmode), NULL);
5535 gtk_tooltips_set_tip (tooltips, bondbutton, _("Toggle bond types"), NULL);
5536 gtk_widget_show (bondbutton);
5537
5538 markbutton = gtk_toggle_button_new ();
5539 pixmap = gdk_pixmap_create_from_xpm_d (window->window, &mask,
5540 &style->bg[GTK_STATE_NORMAL],
5541 (gchar **) xpm_mark);
5542 pixmapwid = gtk_pixmap_new (pixmap, mask);
5543 gtk_widget_show (pixmapwid);
5544 gdk_pixmap_unref (pixmap);
5545 gtk_container_add (GTK_CONTAINER (markbutton), pixmapwid);
5546 gtk_box_pack_start (GTK_BOX (hbox), markbutton, (gboolean) FALSE,
5547 (gboolean) TRUE, 0);
5548 (void)gtk_signal_connect (GTK_OBJECT (markbutton), "clicked",
5549 GTK_SIGNAL_FUNC (Markmode), NULL);
5550 gtk_tooltips_set_tip (tooltips, markbutton,
5551 _("Mark objects for moving, rotating or deleting"),
5552 NULL);
5553 gtk_widget_show (markbutton);
5554
5555
5556 movebutton = gtk_toggle_button_new ();
5557 pixmap = gdk_pixmap_create_from_xpm_d (window->window, &mask,
5558 &style->bg[GTK_STATE_NORMAL],
5559 (gchar **) xpm_mov);
5560 pixmapwid = gtk_pixmap_new (pixmap, mask);
5561 gtk_widget_show (pixmapwid);
5562 gdk_pixmap_unref (pixmap);
5563 gtk_container_add (GTK_CONTAINER (movebutton), pixmapwid);
5564 gtk_box_pack_start (GTK_BOX (hbox), movebutton, (gboolean) FALSE,
5565 (gboolean) TRUE, 0);
5566 (void)gtk_signal_connect (GTK_OBJECT (movebutton), "clicked",
5567 GTK_SIGNAL_FUNC (Movemode), NULL);
5568 gtk_tooltips_set_tip (tooltips, movebutton, _("Move marked object"), NULL);
5569 gtk_widget_show (movebutton);
5570
5571
5572
5573 rotatebutton = gtk_toggle_button_new ();
5574 pixmap = gdk_pixmap_create_from_xpm_d (window->window, &mask,
5575 &style->bg[GTK_STATE_NORMAL],
5576 (gchar **) xpm_rot);
5577 pixmapwid = gtk_pixmap_new (pixmap, mask);
5578 gtk_widget_show (pixmapwid);
5579 gdk_pixmap_unref (pixmap);
5580 gtk_container_add (GTK_CONTAINER (rotatebutton), pixmapwid);
5581 gtk_box_pack_start (GTK_BOX (hbox), rotatebutton, (gboolean) FALSE,
5582 (gboolean) TRUE, 0);
5583 (void)gtk_signal_connect (GTK_OBJECT (rotatebutton), "clicked",
5584 GTK_SIGNAL_FUNC (Rotatemode), NULL);
5585 gtk_tooltips_set_tip (tooltips, rotatebutton, _("Rotate marked object"),
5586 NULL);
5587 gtk_widget_show (rotatebutton);
5588
5589
5590
5591 hflipbutton = gtk_button_new ();
5592 pixmap = gdk_pixmap_create_from_xpm_d (window->window, &mask,
5593 &style->bg[GTK_STATE_NORMAL],
5594 (gchar **) xpm_horiz);
5595 pixmapwid = gtk_pixmap_new (pixmap, mask);
5596 gtk_widget_show (pixmapwid);
5597 gdk_pixmap_unref (pixmap);
5598 gtk_container_add (GTK_CONTAINER (hflipbutton), pixmapwid);
5599 gtk_box_pack_start (GTK_BOX (hbox), hflipbutton, (gboolean) FALSE,
5600 (gboolean) TRUE, 0);
5601 (void)gtk_signal_connect_object (GTK_OBJECT (hflipbutton), "clicked",
5602 GTK_SIGNAL_FUNC (flip_horiz),
5603 GTK_OBJECT (window));
5604 gtk_tooltips_set_tip (tooltips, hflipbutton, _("Flip object horizontally"),
5605 NULL);
5606 gtk_widget_show (hflipbutton);
5607
5608
5609 vflipbutton = gtk_button_new ();
5610 pixmap = gdk_pixmap_create_from_xpm_d (window->window, &mask,
5611 &style->bg[GTK_STATE_NORMAL],
5612 (gchar **) xpm_vert);
5613 pixmapwid = gtk_pixmap_new (pixmap, mask);
5614 gtk_widget_show (pixmapwid);
5615 gdk_pixmap_unref (pixmap);
5616 gtk_container_add (GTK_CONTAINER (vflipbutton), pixmapwid);
5617 gtk_box_pack_start (GTK_BOX (hbox), vflipbutton, (gboolean) FALSE,
5618 (gboolean) TRUE, 0);
5619 (void)gtk_signal_connect_object (GTK_OBJECT (vflipbutton), "clicked",
5620 GTK_SIGNAL_FUNC (flip_vert),
5621 GTK_OBJECT (window));
5622 gtk_tooltips_set_tip (tooltips, vflipbutton, _("Flip object vertically"),
5623 NULL);
5624 gtk_widget_show (vflipbutton);
5625
5626
5627
5628 copybutton = gtk_button_new ();
5629 pixmap = gdk_pixmap_create_from_xpm_d (window->window, &mask,
5630 &style->bg[GTK_STATE_NORMAL],
5631 (gchar **) xpm_copy);
5632 pixmapwid = gtk_pixmap_new (pixmap, mask);
5633 gtk_widget_show (pixmapwid);
5634 gdk_pixmap_unref (pixmap);
5635 gtk_container_add (GTK_CONTAINER (copybutton), pixmapwid);
5636 gtk_box_pack_start (GTK_BOX (hbox), copybutton, (gboolean) FALSE,
5637 (gboolean) TRUE, 0);
5638 (void)gtk_signal_connect_object (GTK_OBJECT (copybutton), "clicked",
5639 GTK_SIGNAL_FUNC (copy_obj), GTK_OBJECT (window));
5640 (void)gtk_signal_connect_object (GTK_OBJECT (copybutton), "clicked",
5641 GTK_SIGNAL_FUNC (gtk_toggle_button_set_active),
5642 GTK_OBJECT (movebutton));
5643 #ifdef MENU
5644 (void)gtk_signal_connect_object (GTK_OBJECT (copy), "activate",
5645 GTK_SIGNAL_FUNC (gtk_toggle_button_set_active),
5646 GTK_OBJECT (movebutton));
5647 #endif
5648 gtk_tooltips_set_tip (tooltips, copybutton, _("Copy marked object"), NULL);
5649 gtk_widget_show (copybutton);
5650
5651 rescalebutton = gtk_toggle_button_new ();
5652 pixmap = gdk_pixmap_create_from_xpm_d (window->window, &mask,
5653 &style->bg[GTK_STATE_NORMAL],
5654 (gchar **) xpm_scale);
5655 pixmapwid = gtk_pixmap_new (pixmap, mask);
5656 gtk_widget_show (pixmapwid);
5657 gdk_pixmap_unref (pixmap);
5658 gtk_container_add (GTK_CONTAINER (rescalebutton), pixmapwid);
5659 gtk_box_pack_start (GTK_BOX (hbox), rescalebutton, (gboolean) FALSE,
5660 (gboolean) TRUE, 0);
5661 (void)gtk_signal_connect (GTK_OBJECT (rescalebutton), "clicked",
5662 GTK_SIGNAL_FUNC (Rescalemode), NULL);
5663 gtk_tooltips_set_tip (tooltips, rescalebutton, _("Rescale marked object"),
5664 NULL);
5665 gtk_widget_show (rescalebutton);
5666
5667 boxmenu = gtk_menu_new ();
5668 bracketbutton = gtk_menu_item_new ();
5669 pixmap = gdk_pixmap_create_from_xpm_d (window->window, &mask,
5670 &style->bg[GTK_STATE_NORMAL],
5671 (gchar **) xpm_bracket);
5672 pixmapwid = gtk_pixmap_new (pixmap, mask);
5673 gtk_widget_show (pixmapwid);
5674 gdk_pixmap_unref (pixmap);
5675 gtk_container_add (GTK_CONTAINER (bracketbutton), pixmapwid);
5676
5677 gtk_menu_append (GTK_MENU (boxmenu), bracketbutton);
5678 (void)gtk_signal_connect_object (GTK_OBJECT (bracketbutton), "activate",
5679 GTK_SIGNAL_FUNC (add_bracket),
5680 GTK_OBJECT (window));
5681 gtk_tooltips_set_tip (tooltips, bracketbutton,
5682 _("Draw brackets around object"), NULL);
5683 gtk_widget_show (bracketbutton);
5684 rbracketbutton = gtk_menu_item_new ();
5685 pixmap = gdk_pixmap_create_from_xpm_d (window->window, &mask,
5686 &style->bg[GTK_STATE_NORMAL],
5687 (gchar **) xpm_r_bracket);
5688 pixmapwid = gtk_pixmap_new (pixmap, mask);
5689 gtk_widget_show (pixmapwid);
5690 gdk_pixmap_unref (pixmap);
5691 gtk_container_add (GTK_CONTAINER (rbracketbutton), pixmapwid);
5692 gtk_menu_append (GTK_MENU (boxmenu), rbracketbutton);
5693 (void)gtk_signal_connect_object (GTK_OBJECT (rbracketbutton), "activate",
5694 GTK_SIGNAL_FUNC (add_r_bracket),
5695 GTK_OBJECT (window));
5696 gtk_tooltips_set_tip (tooltips, rbracketbutton,
5697 _("Draw rounded brackets around object"), NULL);
5698 gtk_widget_show (rbracketbutton);
5699 r2bracketbutton = gtk_menu_item_new ();
5700 pixmap = gdk_pixmap_create_from_xpm_d (window->window, &mask,
5701 &style->bg[GTK_STATE_NORMAL],
5702 (gchar **) xpm_r2_bracket);
5703 pixmapwid = gtk_pixmap_new (pixmap, mask);
5704 gtk_widget_show (pixmapwid);
5705 gdk_pixmap_unref (pixmap);
5706 gtk_container_add (GTK_CONTAINER (r2bracketbutton), pixmapwid);
5707 gtk_menu_append (GTK_MENU (boxmenu), r2bracketbutton);
5708 (void)gtk_signal_connect_object (GTK_OBJECT (r2bracketbutton), "activate",
5709 GTK_SIGNAL_FUNC (add_r2_bracket),
5710 GTK_OBJECT (window));
5711 gtk_tooltips_set_tip (tooltips, r2bracketbutton,
5712 _("Draw round brackets around object"), NULL);
5713 gtk_widget_show (r2bracketbutton);
5714 bracebutton = gtk_menu_item_new ();
5715 pixmap = gdk_pixmap_create_from_xpm_d (window->window, &mask,
5716 &style->bg[GTK_STATE_NORMAL],
5717 (gchar **) xpm_brace);
5718 pixmapwid = gtk_pixmap_new (pixmap, mask);
5719 gtk_widget_show (pixmapwid);
5720 gdk_pixmap_unref (pixmap);
5721 gtk_container_add (GTK_CONTAINER (bracebutton), pixmapwid);
5722
5723 gtk_menu_append (GTK_MENU (boxmenu), bracebutton);
5724 (void)gtk_signal_connect_object (GTK_OBJECT (bracebutton), "activate",
5725 GTK_SIGNAL_FUNC (add_brace),
5726 GTK_OBJECT (window));
5727 gtk_tooltips_set_tip (tooltips, bracebutton, _("Draw braces around object"),
5728 NULL);
5729 gtk_widget_show (bracebutton);
5730 box1button = gtk_menu_item_new ();
5731 pixmap = gdk_pixmap_create_from_xpm_d (window->window, &mask,
5732 &style->bg[GTK_STATE_NORMAL],
5733 (gchar **) xpm_box1);
5734 pixmapwid = gtk_pixmap_new (pixmap, mask);
5735 gtk_widget_show (pixmapwid);
5736 gdk_pixmap_unref (pixmap);
5737 gtk_container_add (GTK_CONTAINER (box1button), pixmapwid);
5738 gtk_menu_append (GTK_MENU (boxmenu), box1button);
5739 (void)gtk_signal_connect_object (GTK_OBJECT (box1button), "activate",
5740 GTK_SIGNAL_FUNC (add_box1), GTK_OBJECT (window));
5741 gtk_tooltips_set_tip (tooltips, box1button,
5742 _("Draw simple box around object"), NULL);
5743 gtk_widget_show (box1button);
5744 box2button = gtk_menu_item_new ();
5745 pixmap = gdk_pixmap_create_from_xpm_d (window->window, &mask,
5746 &style->bg[GTK_STATE_NORMAL],
5747 (gchar **) xpm_box2);
5748 pixmapwid = gtk_pixmap_new (pixmap, mask);
5749 gtk_widget_show (pixmapwid);
5750 gdk_pixmap_unref (pixmap);
5751 gtk_container_add (GTK_CONTAINER (box2button), pixmapwid);
5752 gtk_menu_append (GTK_MENU (boxmenu), box2button);
5753 (void)gtk_signal_connect_object (GTK_OBJECT (box2button), "activate",
5754 GTK_SIGNAL_FUNC (add_box2), GTK_OBJECT (window));
5755 gtk_tooltips_set_tip (tooltips, box2button,
5756 _("Draw shaded box around object"), NULL);
5757 gtk_widget_show (box2button);
5758 box3button = gtk_menu_item_new ();
5759 pixmap = gdk_pixmap_create_from_xpm_d (window->window, &mask,
5760 &style->bg[GTK_STATE_NORMAL],
5761 (gchar **) xpm_box3);
5762 pixmapwid = gtk_pixmap_new (pixmap, mask);
5763 gtk_widget_show (pixmapwid);
5764 gdk_pixmap_unref (pixmap);
5765 gtk_container_add (GTK_CONTAINER (box3button), pixmapwid);
5766 gtk_menu_append (GTK_MENU (boxmenu), box3button);
5767 (void)gtk_signal_connect_object (GTK_OBJECT (box3button), "activate",
5768 GTK_SIGNAL_FUNC (add_box3), GTK_OBJECT (window));
5769 gtk_tooltips_set_tip (tooltips, box3button,
5770 _("Draw fancy box around object"), NULL);
5771 gtk_widget_show (box3button);
5772 box4button = gtk_menu_item_new ();
5773 pixmap = gdk_pixmap_create_from_xpm_d (window->window, &mask,
5774 &style->bg[GTK_STATE_NORMAL],
5775 (gchar **) xpm_box4);
5776 pixmapwid = gtk_pixmap_new (pixmap, mask);
5777 gtk_widget_show (pixmapwid);
5778 gdk_pixmap_unref (pixmap);
5779 gtk_container_add (GTK_CONTAINER (box4button), pixmapwid);
5780 gtk_menu_append (GTK_MENU (boxmenu), box4button);
5781 (void)gtk_signal_connect_object (GTK_OBJECT (box4button), "activate",
5782 GTK_SIGNAL_FUNC (add_box4), GTK_OBJECT (window));
5783 gtk_tooltips_set_tip (tooltips, box4button,
5784 _("Draw rounded box around object"), NULL);
5785 gtk_widget_show (box4button);
5786 gtk_widget_realize (boxmenu);
5787
5788 boxbutton = gtk_button_new ();
5789 pixmap = gdk_pixmap_create_from_xpm_d (window->window, &mask,
5790 &style->bg[GTK_STATE_NORMAL],
5791 (gchar **) xpm_bracket);
5792 pixmapwid = gtk_pixmap_new (pixmap, mask);
5793 gtk_widget_show (pixmapwid);
5794 gdk_pixmap_unref (pixmap);
5795 gtk_container_add (GTK_CONTAINER (boxbutton), pixmapwid);
5796 gtk_box_pack_start (GTK_BOX (hbox), boxbutton, (gboolean) FALSE,
5797 (gboolean) TRUE, 0);
5798 (void)gtk_signal_connect_object (GTK_OBJECT (boxbutton), "clicked",
5799 GTK_SIGNAL_FUNC (show_boxmenu), NULL);
5800 gtk_tooltips_set_tip (tooltips, boxbutton,
5801 _("Draw brackets and boxes around object"), NULL);
5802 gtk_widget_show (boxbutton);
5803
5804 cleanbutton = gtk_button_new ();
5805 pixmap = gdk_pixmap_create_from_xpm_d (window->window, &mask,
5806 &style->bg[GTK_STATE_NORMAL],
5807 (gchar **) xpm_clean);
5808 pixmapwid = gtk_pixmap_new (pixmap, mask);
5809 gtk_widget_show (pixmapwid);
5810 gdk_pixmap_unref (pixmap);
5811 gtk_container_add (GTK_CONTAINER (cleanbutton), pixmapwid);
5812 gtk_box_pack_start (GTK_BOX (hbox), cleanbutton, (gboolean) FALSE,
5813 (gboolean) TRUE, 0);
5814 (void)gtk_signal_connect (GTK_OBJECT (cleanbutton), "clicked",
5815 GTK_SIGNAL_FUNC (tidy_mol), NULL);
5816 gtk_tooltips_set_tip (tooltips, cleanbutton,
5817 _("Removes duplicate bonds, etc."), NULL);
5818
5819 gtk_widget_show (cleanbutton);
5820
5821 gtk_box_pack_start (GTK_BOX (vbox), hbox, (gboolean) FALSE, (gboolean) TRUE,
5822 0);
5823
5824 gtk_widget_show (hbox);
5825
5826
5827 /*end second row */
5828 hbox=gtk_hbox_new(FALSE,0);
5829 normalfontstyle=gtk_style_copy(gtk_widget_get_default_style());
5830 seriffontstyle=gtk_style_copy(gtk_widget_get_default_style());
5831 #ifdef GTK2
5832 pango_font_description_free(normalfontstyle->font_desc);
5833 normalfontstyle->font_desc=pango_font_description_from_string("Helvetica Bold 12");
5834 pango_font_description_free(seriffontstyle->font_desc);
5835 seriffontstyle->font_desc=pango_font_description_from_string("Times Medium 12");
5836 #else
5837 gdk_font_unref(normalfontstyle->font);
5838 normalfontstyle->font=gdk_font_load("*-helvetica-bold-r-normal--12-*");
5839 gdk_font_unref(seriffontstyle->font);
5840 seriffontstyle->font=gdk_font_load("*-times-medium-r-normal--12-*");
5841 if (!normalfontstyle->font)
5842 normalfontstyle=gtk_style_copy(gtk_widget_get_default_style());
5843 if (!seriffontstyle->font)
5844 seriffontstyle=gtk_style_copy(gtk_widget_get_default_style());
5845 #endif
5846 textlabel = gtk_label_new(_("Text :"));
5847 gtk_widget_set_style(GTK_WIDGET(textlabel),normalfontstyle);
5848 gtk_widget_show(textlabel);
5849 gtk_box_pack_start (GTK_BOX (hbox), textlabel, (gboolean) FALSE,
5850 (gboolean) TRUE, 0);
5851 textbox = gtk_entry_new_with_max_length (100);
5852 gtk_widget_set_usize(textbox,700,20);
5853 gtk_box_pack_start (GTK_BOX (hbox), textbox, (gboolean) FALSE,
5854 (gboolean) FALSE, 0);
5855 (void)gtk_signal_connect (GTK_OBJECT (textbox), "focus_in_event",
5856 (GtkSignalFunc) Set_Textmode, NULL);
5857
5858 gtk_tooltips_set_tip (tooltips, textbox,
5859 _
5860 ("Prefix a character with _ for subscript, ^ for superscript, @ for symbols, | for italic, # for bold text; e.g. H_2O, @a_D^2^0"),
5861 NULL);
5862 gtk_widget_show (textbox);
5863
5864 fontmenu = gtk_option_menu_new ();
5865 gtk_tooltips_set_tip (tooltips, fontmenu, _("Select current text size"), NULL);
5866 fontsizes = gtk_menu_new ();
5867 for (i = 0; i < 7; i++)
5868 {
5869 fontsizeitem[i] = gtk_menu_item_new_with_label (fontsizelabel[i]);
5870 gtk_menu_append (GTK_MENU (fontsizes), fontsizeitem[i]);
5871 gtk_widget_show (fontsizeitem[i]);
5872 (void)gtk_signal_connect (GTK_OBJECT (fontsizeitem[i]), "activate",
5873 GTK_SIGNAL_FUNC (set_fontsize),
5874 GINT_TO_POINTER(i));
5875 }
5876 gtk_option_menu_set_menu (GTK_OPTION_MENU (fontmenu), fontsizes);
5877 gtk_widget_show (fontmenu);
5878 gtk_option_menu_set_history(GTK_OPTION_MENU(fontmenu), (guint)3);
5879 gtk_box_pack_start (GTK_BOX (hbox), fontmenu,
5880 (gboolean) FALSE, (gboolean) FALSE, 0);
5881
5882 gtk_box_pack_start (GTK_BOX (vbox), hbox, (gboolean) FALSE, (gboolean) FALSE,
5883 0);
5884 gtk_widget_show (hbox);
5885
5886 /* drawing area */
5887 /***********************the canvas pixmap ***********************/
5888 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
5889 gtk_container_set_border_width (GTK_CONTAINER (scrolled_window), 10);
5890 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
5891 GTK_POLICY_ALWAYS, GTK_POLICY_ALWAYS);
5892 gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, (gboolean) TRUE,
5893 (gboolean) TRUE, 0);
5894 gtk_widget_show (scrolled_window);
5895
5896 /*fprintf(stderr,"screen dimensions %d x %d\n",gdk_screen_width(),gdk_screen_height() );*/
5897 int canvash=600;
5898 if (gdk_screen_height() < 600) canvash= 460;
5899
5900 gtk_widget_set_usize (window, 800, canvash-20);
5901
5902 if (!picture)
5903 picture = gdk_pixmap_new (window->window, 800, canvash, -1);
5904
5905 drawing_area = gtk_drawing_area_new ();
5906 gtk_drawing_area_size (GTK_DRAWING_AREA (drawing_area), 1600, 1600);
5907
5908 gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW
5909 (scrolled_window), drawing_area);
5910
5911 gtk_widget_show (drawing_area);
5912
5913 mygc[0]=gdk_gc_new(window->window);
5914 (void)gdk_color_alloc(gdk_colormap_get_system(),&black);
5915 gdk_gc_set_foreground(mygc[0],&black);
5916
5917 mygc[1]=gdk_gc_new(window->window);
5918 (void)gdk_color_alloc(gdk_colormap_get_system(),&blue);
5919 gdk_gc_set_foreground(mygc[1],&blue);
5920
5921 mygc[2]=gdk_gc_new(window->window);
5922 (void)gdk_color_alloc(gdk_colormap_get_system(),&green);
5923 gdk_gc_set_foreground(mygc[2],&green);
5924
5925 mygc[3]=gdk_gc_new(window->window);
5926 (void)gdk_color_alloc(gdk_colormap_get_system(),&cyan);
5927 gdk_gc_set_foreground(mygc[3],&cyan);
5928
5929 mygc[4]=gdk_gc_new(window->window);
5930 (void)gdk_color_alloc(gdk_colormap_get_system(),&red);
5931 gdk_gc_set_foreground(mygc[4],&red);
5932
5933 mygc[5]=gdk_gc_new(window->window);
5934 (void)gdk_color_alloc(gdk_colormap_get_system(),&magenta);
5935 gdk_gc_set_foreground(mygc[5],&magenta);
5936
5937 mygc[6]=gdk_gc_new(window->window);
5938 (void)gdk_color_alloc(gdk_colormap_get_system(),&yellow);
5939 gdk_gc_set_foreground(mygc[6],&yellow);
5940
5941 mygc[7]=gdk_gc_new(window->window);
5942 (void)gdk_color_alloc(gdk_colormap_get_system(),&white);
5943 gdk_gc_set_foreground(mygc[7],&white);
5944
5945 /* highlighting for mark/move/copy */
5946 hlgc=gdk_gc_new(window->window);
5947 gdk_gc_set_foreground(hlgc,&blue);
5948 gdk_gc_set_line_attributes(hlgc,
5949 3,GDK_LINE_SOLID,GDK_CAP_BUTT,GDK_JOIN_MITER);
5950
5951 /* Signals used to handle backing pixmap */
5952
5953 (void)gtk_signal_connect (GTK_OBJECT (drawing_area), "expose_event",
5954 (GtkSignalFunc) expose_event, NULL);
5955 (void)gtk_signal_connect (GTK_OBJECT (drawing_area), "configure_event",
5956 (GtkSignalFunc) configure_event, NULL);
5957
5958 (void)gtk_signal_connect (GTK_OBJECT (drawing_area), "motion_notify_event",
5959 (GtkSignalFunc) motion_notify_event, NULL);
5960
5961 (void)gtk_signal_connect (GTK_OBJECT (drawing_area), "button_press_event",
5962 (GtkSignalFunc) button_press_event, NULL);
5963
5964 (void)gtk_signal_connect (GTK_OBJECT (drawing_area), "button_release_event",
5965 (GtkSignalFunc) button_release_event, NULL);
5966
5967 (void)gtk_signal_connect (GTK_OBJECT (window), "key_press_event",
5968 (GtkSignalFunc) key_press_event, NULL);
5969
5970 gtk_widget_set_events (drawing_area, GDK_EXPOSURE_MASK
5971 | GDK_LEAVE_NOTIFY_MASK
5972 | GDK_BUTTON_PRESS_MASK
5973 | GDK_BUTTON_RELEASE_MASK
5974 | GDK_POINTER_MOTION_MASK
5975 | GDK_POINTER_MOTION_HINT_MASK);
5976
5977 /*status line - used for cht output*/
5978 hbox = gtk_hbox_new (FALSE, 5);
5979 gtk_widget_set_usize (hbox, 800, 20);
5980 #ifdef GTK2
5981 msgtext = gtk_text_view_new();
5982 gtk_text_view_set_editable(GTK_TEXT_VIEW(msgtext), (gboolean) FALSE);
5983 msgtextbuffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (msgtext));
5984 #else
5985 msgtext = gtk_text_new (NULL, NULL);
5986 gtk_text_set_editable (GTK_TEXT (msgtext), (gboolean) FALSE);
5987 gtk_box_pack_start (GTK_BOX (hbox), msgtext, (gboolean) TRUE,
5988 (gboolean) TRUE, 0);
5989 #endif
5990
5991 #ifdef GTK2
5992 vscroll = gtk_scrolled_window_new(NULL,NULL);
5993 msgadjustment = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW(vscroll));
5994 gtk_widget_set_usize(vscroll,790,12);
5995 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(vscroll),
5996 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
5997 gtk_container_add(GTK_CONTAINER(vscroll),msgtext);
5998 #else
5999 vscroll = gtk_vscrollbar_new (GTK_TEXT (msgtext)->vadj);
6000 #endif
6001
6002 gtk_box_pack_start (GTK_BOX (hbox), vscroll, (gboolean) FALSE,
6003 (gboolean) FALSE, 0);
6004 gtk_box_pack_start (GTK_BOX (vbox), hbox, (gboolean) FALSE,
6005 (gboolean) FALSE, 0);
6006 snprintf(msgtmp,99,_("Ready"));
6007 #ifdef GTK2
6008 gtk_text_buffer_get_iter_at_offset (msgtextbuffer, &iter, 0);
6009 gtk_text_buffer_insert (msgtextbuffer, &iter, msgtmp, -1);
6010 #else
6011 gtk_text_insert (GTK_TEXT (msgtext), NULL, NULL, NULL, msgtmp,(gint)strlen(msgtmp));
6012 #endif
6013 gtk_widget_show (msgtext);
6014 gtk_widget_show (vscroll);
6015 gtk_widget_show (hbox);
6016 gtk_widget_show (window);
6017 set_icon(window);
6018 /* initialize cursor shapes */
6019 source =
6020 gdk_bitmap_create_from_data (NULL, (gchar *) pencil_bits, pencil_width,
6021 pencil_height);
6022 mask =
6023 gdk_bitmap_create_from_data (NULL, (gchar *) pencil_mask_bits,
6024 pencil_width, pencil_height);
6025 cursor_pencil =
6026 gdk_cursor_new_from_pixmap (source, mask, &fg, &bg, pencil_x_hot,
6027 pencil_y_hot);
6028 gdk_pixmap_unref (source);
6029 gdk_pixmap_unref (mask);
6030 source =
6031 gdk_bitmap_create_from_data (NULL, (gchar *) text_bits, text_width,
6032 text_height);
6033 mask =
6034 gdk_bitmap_create_from_data (NULL, (gchar *) text_mask_bits, text_width,
6035 text_height);
6036 cursor_text =
6037 gdk_cursor_new_from_pixmap (source, mask, &fg, &bg, text_x_hot,
6038 text_y_hot);
6039 gdk_pixmap_unref (source);
6040 gdk_pixmap_unref (mask);
6041 source =
6042 gdk_bitmap_create_from_data (NULL, (gchar *) bonds_bits, bonds_width,
6043 bonds_height);
6044 mask =
6045 gdk_bitmap_create_from_data (NULL, (gchar *) bonds_mask_bits, bonds_width,
6046 bonds_height);
6047 cursor_bonds =
6048 gdk_cursor_new_from_pixmap (source, mask, &fg, &wh, bonds_x_hot,
6049 bonds_y_hot);
6050 gdk_pixmap_unref (source);
6051 gdk_pixmap_unref (mask);
6052 cursor_markTLC = gdk_cursor_new (GDK_TOP_LEFT_CORNER);
6053 cursor_markBRC = gdk_cursor_new (GDK_BOTTOM_RIGHT_CORNER);
6054 cursor_move = gdk_cursor_new (GDK_FLEUR);
6055 cursor_rescale = gdk_cursor_new (GDK_SIZING);
6056 cursor_rotate = gdk_cursor_new (GDK_EXCHANGE);
6057 /* cursor_busy = gdk_cursor_new (GDK_WATCH); */
6058
6059 /*@ignore@ splint does not know all signal names */
6060 (void) signal (SIGSEGV, ct_crash);
6061 (void) signal (SIGFPE, ct_crash);
6062 (void) signal (SIGBUS, ct_crash);
6063 (void) signal (SIGHUP, ct_crash);
6064 (void) signal (SIGPIPE, SIG_IGN);
6065 /*@end@*/
6066
6067 if (!Load_Font() )
6068 {
6069 fprintf (stderr, _("chemtool: can't load any font\n"));
6070 exit (1);
6071 }
6072
6073 gtk_toggle_button_set_active ((GtkToggleButton *) hexbutton, TRUE);
6074 /* default to linedrawing at hexagonal angles */
6075 text_direct = -1; /* and centered text */
6076 expmode = 0; /*default to xfig export */
6077 orient = 0;
6078 printcmd = 0;
6079 epsoption = 0;
6080 use_whiteout = 0;
6081 use_intlchars = 0;
6082 strcpy (filename, _("unnamed"));
6083 gtk_file_selection_set_filename (GTK_FILE_SELECTION (expw), filename);
6084 printscale = 0.7;
6085 papersize = 0;
6086 queuename = getenv ("PRINTER");
6087 if (queuename == (char *) NULL)
6088 {
6089 queuename = malloc (33 * sizeof (char));
6090 strcpy (queuename, "lp");
6091 }
6092 if (figversion ==0) {
6093
6094 #ifdef MENU
6095 gtk_widget_set_sensitive(printps,FALSE);
6096 #else
6097 gtk_widget_set_sensitive(printbutton,FALSE);
6098 #endif
6099
6100 gtk_widget_set_sensitive(expbutton[0],FALSE);
6101 gtk_widget_set_sensitive(expbutton[1],FALSE);
6102 gtk_widget_set_sensitive(expbutton[2],FALSE);
6103 gtk_widget_set_sensitive(expbutton[8],FALSE);
6104 }
6105 #ifndef EMF
6106 if (figversion >=3 )gtk_widget_show (expbutton[6]);
6107 #endif
6108 if (have_fig2sxd) gtk_widget_show(expbutton[7]);
6109 bgred=bgblue=bggreen=65535;
6110 readrc ();
6111 background.red=(gushort)bgred;
6112 background.green=(gushort)bggreen;
6113 background.blue=(gushort)bgblue;
6114 background_gc=gdk_gc_new(window->window);
6115 (void)gdk_color_alloc(gdk_colormap_get_system(),&background);
6116 gdk_gc_set_foreground(background_gc,&background);
6117 gdk_gc_set_background(background_gc,&background);
6118 snprintf(bghexcolor,10,"#%2.2x%2.2x%2.2x",(unsigned char)(bgred/256.),(unsigned char)(bggreen/256.),(unsigned char)(bgblue/256.));
6119
6120 #ifndef GTK2
6121 gtk_label_set_text(GTK_LABEL(GTK_BUTTON(bgcolorbutton)->child),bghexcolor);
6122 gtk_entry_set_text (GTK_ENTRY (prqueue), queuename);
6123 gtk_option_menu_set_history (GTK_OPTION_MENU (papermenu), (guint)papersize);
6124 gtk_option_menu_set_history (GTK_OPTION_MENU (printcmdmenu), (guint)printcmd);
6125 gtk_option_menu_set_history (GTK_OPTION_MENU (epsoptionmenu), (guint) epsoption);
6126 gtk_spin_button_set_value ((GtkSpinButton *) pscale, printscale * 100.);
6127 if (use_whiteout==1) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(whiteoutbutton),TRUE);
6128 if (use_intlchars==1) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(intlbutton),TRUE);
6129 snprintf(msgtmp,100,"%6.4f",bondlen_mm);
6130 gtk_entry_set_text (GTK_ENTRY (base_bondlen),msgtmp);
6131 if (datadir && (int)strlen (datadir) > 1)
6132 {
6133 gtk_entry_set_text (GTK_ENTRY (defaultdir), datadir);
6134 gtk_entry_set_text (GTK_ENTRY (defaultext), datamask);
6135 gtk_file_selection_complete (GTK_FILE_SELECTION (filew),
6136 strcat (datadir, datamask));
6137 strcpy (datadir, gtk_entry_get_text (GTK_ENTRY (defaultdir)));
6138 }
6139 #else
6140 if (datadir != NULL && (int)strlen (datadir) > 1)
6141 {
6142 char dir_mask[PATH_MAX];
6143 strcpy (dir_mask, datadir);
6144 strcat (dir_mask, datamask);
6145 gtk_file_selection_complete (GTK_FILE_SELECTION (filew), dir_mask);
6146 }
6147 #endif
6148
6149 mark.flag = False;
6150 head.width = 2000;
6151 head.height = 5000;
6152 zoom_factor = 2;
6153 pdbx = pdby = pdbz = NULL;
6154 atcode = NULL;
6155 atjust = bondtype = NULL;
6156 bondfrom = bondto = NULL;
6157 hp->x = hp->y = 200;
6158 hp->tx = hp->ty = 200;
6159 tmpx=(int*)NULL;
6160 tmpy=(int*)NULL;
6161 gridtype=0;
6162 gridx=gridy = 0;
6163 atnum = 0;
6164 if (argc == 2)
6165 {
6166 strcpy (filename, argv[1]);
6167 if (strstr(argv[0],"chemtoolsvg")) {
6168 load_mol(filename);
6169 strcpy(expname,filename);
6170 char *dot=strrchr(expname,'.');
6171 if (dot) *dot='\0';
6172 strcat(expname,".svg");
6173 export_svg(expname);
6174 exit(0);
6175 }
6176 #if 0
6177 if(strrchr(filename,'/')) { /* change working directory to obtain absolute path */
6178 char dirname[256];
6179 strcpy(dirname,filename); /* and strip path from filename - gtkfilesel may */
6180 char *start= strrchr(dirname,'/');
6181 *start='\0'; /* get confused by relative paths, stripping off */
6182 start++;
6183 chdir(dirname); /* a level with every invocation of the file dialog */
6184 memmove(filename,start,strlen(start)+1);
6185 }
6186 #endif
6187 error = load_mol (filename);
6188 switch (error)
6189 {
6190 case 0:
6191 modify = 0;
6192 mark.flag = 0;
6193 snprintf (msgtmp,99, "Chemtool %s (%s)", VERSION, filename);
6194 gtk_window_set_title (GTK_WINDOW (window), msgtmp);
6195 #ifdef LIBUNDO
6196 undo_snapshot ();
6197 #endif
6198 break;
6199 case 1:
6200 snprintf (msgtmp,99, _("Unable to open %s\n"), filename);
6201 strcpy (filename, "");
6202 gtk_label_set_text (GTK_LABEL (message), msgtmp);
6203 gtk_widget_show (messagew);
6204 gtk_grab_add (messagew);
6205 break;
6206 case 2:
6207 snprintf (msgtmp,99, _("%s\n does not appear to be a Chemtool file\n"),
6208 filename);
6209 strcpy (filename, "");
6210 gtk_label_set_text (GTK_LABEL (message), msgtmp);
6211 gtk_widget_show (messagew);
6212 gtk_grab_add (messagew);
6213 break;
6214 case 3:
6215 modify = 0;
6216 snprintf (msgtmp,99,
6217 _("%s was created by a newer version.\nSome features may be lost.\n"),
6218 filename);
6219 gtk_label_set_text (GTK_LABEL (message), msgtmp);
6220 gtk_widget_show (messagew);
6221 gtk_grab_add (messagew);
6222 snprintf (msgtmp,100, "Chemtool %s (%s)", VERSION, filename);
6223 gtk_window_set_title (GTK_WINDOW (window), msgtmp);
6224 #ifdef LIBUNDO
6225 undo_snapshot ();
6226 #endif
6227 break;
6228 default:
6229 clear_data ();
6230 snprintf (msgtmp,100, _("Error loading %s \n"), filename);
6231 gtk_label_set_text (GTK_LABEL (message), msgtmp);
6232 gtk_widget_show (messagew);
6233 gtk_grab_add (messagew);
6234 }
6235 }
6236 FreePix ();
6237 CreatePix ();
6238 Display_Mol ();
6239
6240 gtk_main (); /* enter the gtk eventloop */
6241
6242 return 0;
6243 }
6244
6245 void
show_boxmenu()6246 show_boxmenu ()
6247 {
6248 gtk_menu_popup (GTK_MENU (boxmenu), NULL, NULL, NULL, NULL, 0, 0);
6249 }
6250
6251 void
show_penmenu()6252 show_penmenu ()
6253 {
6254 gtk_menu_popup (GTK_MENU (penmenu), NULL, NULL, NULL, NULL, 0, 0);
6255 }
6256
6257 void
ct_crash(signal)6258 ct_crash (signal)
6259 int signal;
6260 {
6261 FILE *fp;
6262 fp = fopen ("crashdump.cht", "w");
6263 save_mol (fp, 0);
6264 switch (signal)
6265 {
6266 case SIGSEGV:
6267 fprintf (stderr, _("Memory allocation problem (SIGSEGV) -"));
6268 break;
6269 case SIGFPE:
6270 fprintf (stderr, _("Invalid math somewhere (SIGFPE) -"));
6271 break;
6272 case SIGBUS:
6273 fprintf (stderr, _("Memory access problem (SIGBUS) -"));
6274 break;
6275 case SIGHUP:
6276 fprintf (stderr, _("Ordered to quit (SIGHUP) - "));
6277 }
6278 fprintf (stderr, _(" dumping current drawing to file crashdump.cht\n"));
6279 fclose (fp);
6280 exit (1);
6281 }
6282
6283 void
restore_picture()6284 restore_picture ()
6285 {
6286 if (savedpicture)
6287 picture = gdk_pixmap_ref(savedpicture);
6288 }
6289
6290
6291 void
getpreview(GtkWidget * w,gint row,gint column,GdkEventButton * bevent,gpointer data)6292 getpreview (GtkWidget * w, gint row, gint column, GdkEventButton * bevent,
6293 gpointer data)
6294 {
6295 char myfile[255];
6296
6297 if (bevent && bevent->type == GDK_2BUTTON_PRESS)
6298 return;
6299 if (loadsave != 1 && loadsave != 3 && loadsave != 4)
6300 return;
6301
6302 strcpy (myfile,
6303 gtk_file_selection_get_filename (GTK_FILE_SELECTION (filew)));
6304 if (picture){
6305 gdk_pixmap_unref (picture);
6306 picture=NULL;
6307 }
6308 picture = gdk_pixmap_new (filew->window, 200, 100, -1);
6309
6310 gdk_draw_rectangle (picture,
6311 filew->style->white_gc,
6312 (gint) TRUE, 0, 0, (gint) 200, (gint) 100);
6313
6314 if (loadsave == 4) {
6315 sdfindex = 0;
6316 preview_mdl_mol(myfile,sdfindex);
6317 } else
6318 load_preview (myfile);
6319 }
6320
6321 void
set_icon(GtkWidget * w)6322 set_icon(GtkWidget *w) {
6323 /* Set icon for the main chemtool window */
6324 GdkWindow *win;
6325 GdkPixmap *icon;
6326 GdkBitmap *iconmask;
6327
6328 gtk_widget_realize(w);
6329 win = w->window;
6330 if (!win) return;
6331
6332 icon = gdk_pixmap_create_from_xpm_d(win, &iconmask, NULL, chemtool_xpm);
6333 gdk_window_set_icon(win, NULL, icon, iconmask);
6334 }
6335
6336