1 /* **************************************************************** */
2 /* functions to handle control panel (sliders, labels, etc.) */
7 #include <X11/Intrinsic.h>
8 #include <X11/StringDefs.h>
12 #include <X11/Xaw/Cardinals.h>
14 #include <X11/Xaw/Box.h>
15 #include <X11/Xaw/Command.h>
16 #include <X11/Xaw/Dialog.h>
17 #include <X11/Xaw/Form.h>
18 #include <X11/Xaw/Label.h>
19 #include <X11/Xaw/MenuButton.h>
20 #include <X11/Xaw/Scrollbar.h>
21 #include <X11/Xaw/SimpleMenu.h>
22 #include <X11/Xaw/Sme.h>
23 #include <X11/Xaw/SmeBSB.h>
24 #include <X11/Xaw/Toggle.h>
28 #define POPUPSHELLCLASS overrideShellWidgetClass
30 /* **************************************************************** */
33 typedef void (*InitFunc
)(Widget parent
);
37 XtCallbackProc exec_func
;
42 #define NBTN(a) (sizeof(a)/sizeof(ButtonStruct))
50 #define TGLCNT(x) (sizeof(x)/sizeof(ToggleStruct))
54 XtCallbackProc callback
;
55 ToggleStruct
*buttons
;
65 XtCallbackProc callback
;
74 /* **************************************************************** */
75 /* local prototypes */
77 PRIVATE
void SetSpeed(float percent
);
78 PRIVATE
void NewSpeed(Widget w
, XtPointer client_data
, XtPointer percent
);
79 PRIVATE
void SetPosition(float percent
);
80 PRIVATE
void NewPosition(Widget w
, XtPointer client_data
, XtPointer percent
);
81 PRIVATE
void SetThickness(float percent
);
82 PRIVATE
void NewThickness(Widget w
, XtPointer client_data
, XtPointer percent
);
84 PRIVATE
void AxisSelect(Widget w
, XtPointer client_data
, XtPointer call_data
);
85 PRIVATE
void DirectionSelect(Widget w
, XtPointer client_data
, XtPointer call_data
);
86 PRIVATE
void MotionSelect(Widget w
, XtPointer client_data
, XtPointer call_data
);
88 PRIVATE
void FindAndDisplaySlider(Widget w
, XtCallbackProc func
);
90 PRIVATE
void DrawAxes(void);
92 PRIVATE
void MakeRadioGroup(Widget parent
, RadioStruct
*radio
);
93 PRIVATE
void MakeSliderWithLabel(Widget parent
, SliderLabelStruct
*sl
);
95 PRIVATE
void SetRadio(RadioStruct
*radio
);
97 PRIVATE
void do_start(Widget w
, XtPointer client_data
, XtPointer call_data
);
98 PRIVATE
void do_stop(Widget w
, XtPointer client_data
, XtPointer call_data
);
99 PRIVATE
void do_restart(Widget w
, XtPointer client_data
, XtPointer call_data
);
100 PRIVATE
void do_step(Widget w
, XtPointer client_data
, XtPointer call_data
);
101 PRIVATE
void do_back(Widget w
, XtPointer client_data
, XtPointer call_data
);
103 PRIVATE
void do_save_off(Widget w
, XtPointer client_data
, XtPointer call_data
);
104 PRIVATE
void do_save_on(Widget w
, XtPointer client_data
, XtPointer call_data
);
105 PRIVATE
void do_save_one(Widget w
, XtPointer client_data
, XtPointer call_data
);
107 PRIVATE
void do_popup(Widget w
, XtPointer client_data
, XtPointer call_data
);
108 PRIVATE
void cancel_popup(Widget w
, XtPointer client_data
, XtPointer call_data
);
110 PRIVATE
void init_quit(Widget w
);
111 PRIVATE
void quit_ok(Widget w
, XtPointer client_data
, XtPointer call_data
);
113 PRIVATE
void init_atoms(Widget w
);
114 PRIVATE
void init_bonds(Widget w
);
115 PRIVATE
void init_bg(Widget w
);
116 PRIVATE
void init_file(Widget w
);
118 PRIVATE
void color_apply(Widget w
, XtPointer client_data
, XtPointer call_data
);
119 PRIVATE
void bond_apply(Widget w
, XtPointer client_data
, XtPointer call_data
);
120 PRIVATE
void bg_apply(Widget w
, XtPointer client_data
, XtPointer call_data
);
121 PRIVATE
void file_apply(Widget w
, XtPointer client_data
, XtPointer call_data
);
123 PRIVATE Pixel
ConvertColorToPixel(Widget w
, String color
);
124 PRIVATE XtActionProc
NoOp(Widget w
, XEvent event
, String
*params
,
127 PRIVATE
void visible_toggle(Widget w
, XtPointer client_data
, XtPointer
130 PRIVATE
void bvisible_toggle(Widget w
, XtPointer client_data
, XtPointer
133 /* **************************************************************** */
136 static Widget QuitPopup
= (Widget
) 0,
137 AtomPopup
= (Widget
) 0,
138 BondPopup
= (Widget
) 0,
139 BackgroundPopup
= (Widget
) 0,
140 FileColorPopup
= (Widget
) 0,
141 TimeLabel
= (Widget
) 0,
142 SpeedBar
= (Widget
) 0,
143 SpeedLabel
= (Widget
) 0,
144 PositionBar
= (Widget
) 0,
145 PositionLabel
= (Widget
) 0,
146 ThicknessBar
= (Widget
) 0,
147 ThicknessLabel
= (Widget
) 0,
149 ReadInfo
= (Widget
) 0;
151 static Widget BGDialog
= (Widget
) 0,
152 FileDialog
= (Widget
) 0,
153 *FGDialog
= (Widget
*) NULL
,
154 *Visible
= (Widget
*) NULL
,
155 *Invisible
= (Widget
*) NULL
,
156 *SizeDialog
= (Widget
*) NULL
,
157 *BFGDialog
= (Widget
*) NULL
,
158 *BVisible
= (Widget
*) NULL
,
159 *BInvisible
= (Widget
*) NULL
,
160 *ThicknessDialog
= (Widget
*) NULL
;
163 QuitData
= { &QuitPopup
, XtGrabExclusive
, True
},
164 AtomData
= { &AtomPopup
, XtGrabNone
, False
},
165 BondData
= { &BondPopup
, XtGrabNone
, False
},
166 BackgroundData
= { &BackgroundPopup
, XtGrabNone
, False
},
167 FileColorData
= { &FileColorPopup
, XtGrabNone
, False
};
169 static ButtonStruct Buttons
[] = {
170 { "quit", do_popup
, (XtPointer
) &QuitData
, init_quit
},
171 { "start", do_start
, NULL
, NULL
},
172 { "stop", do_stop
, NULL
, NULL
},
173 { "restart", do_restart
, NULL
, NULL
},
174 { "step", do_step
, NULL
, NULL
},
175 { "back", do_back
, NULL
, NULL
},
178 static ButtonStruct SaveButtons
[] = {
179 { "Off while animating", do_save_off
, NULL
, NULL
},
180 { "On while animating", do_save_on
, NULL
, NULL
},
181 { "This snapshot", do_save_one
, NULL
, NULL
},
184 static ButtonStruct ColorButtons
[] = {
185 { "atoms", do_popup
, (XtPointer
) &AtomData
, init_atoms
},
186 { "bonds", do_popup
, (XtPointer
) &BondData
, init_bonds
},
187 { "background", do_popup
, (XtPointer
) &BackgroundData
, init_bg
},
188 { "filecolor", do_popup
, (XtPointer
) &FileColorData
, init_file
}
191 static int in_motion
;
193 static SliderLabelStruct
195 "speed", &SpeedLabel
,
196 "speedbar", &SpeedBar
,
199 "position", &PositionLabel
,
200 "positionbar", &PositionBar
,
203 "thickness", &ThicknessLabel
,
204 "thicknessbar", &ThicknessBar
,
213 DirectionButtons
[] = {
226 TGLCNT(AxisButtons
) },
231 TGLCNT(DirectionButtons
) },
236 TGLCNT(MotionButtons
) }
239 static int normal
= 1;
240 static char *null_string
= "";
242 static XtActionsRec actions
[] = {
243 { "NoOp", (XtActionProc
) NoOp
},
246 /* **************************************************************** */
248 Widget
CreateControl(Widget parent
, char *name
)
250 Widget form
, command
, button
, menu
;
254 /* register the new actions */
256 XtAppAddActions(XtWidgetToApplicationContext(parent
),
257 actions
, XtNumber(actions
));
259 /* create a form widget to handle layout */
261 form
= XtCreateManagedWidget(name
, formWidgetClass
, parent
,
264 /* create all the command buttons */
266 for(bcnt
= NBTN(Buttons
), bptr
= Buttons
;bcnt
> 0; bcnt
--, bptr
++){
268 /* create a button */
270 command
= XtCreateManagedWidget(bptr
->name
,
271 commandWidgetClass
, form
, NULL
, ZERO
);
273 /* Add the function as a callback */
275 XtAddCallback(command
, XtNcallback
, bptr
->exec_func
,
278 /* call initialization routine */
280 if (bptr
->init_func
) (bptr
->init_func
)(command
);
284 /* create the save menu */
286 command
= XtCreateManagedWidget("save", menuButtonWidgetClass
,
289 menu
= XtCreatePopupShell("menu", simpleMenuWidgetClass
,
290 command
, NULL
, ZERO
);
292 for(bcnt
=NBTN(SaveButtons
), bptr
=SaveButtons
; bcnt
>0; bcnt
--,bptr
++){
293 button
= XtCreateManagedWidget(bptr
->name
, smeBSBObjectClass
,
295 XtAddCallback(button
, XtNcallback
, bptr
->exec_func
,bptr
->data
);
296 if (bptr
->init_func
) (bptr
->init_func
)(button
);
299 /* create the color menu */
301 command
= XtCreateManagedWidget("color", menuButtonWidgetClass
,
304 menu
= XtCreatePopupShell("menu", simpleMenuWidgetClass
,
305 command
, NULL
, ZERO
);
307 for(bcnt
=NBTN(ColorButtons
), bptr
=ColorButtons
; bcnt
>0; bcnt
--,bptr
++){
308 button
= XtCreateManagedWidget(bptr
->name
, smeBSBObjectClass
,
310 XtAddCallback(button
, XtNcallback
, bptr
->exec_func
,bptr
->data
);
311 if (bptr
->init_func
) (bptr
->init_func
)(button
);
314 /* create a label widget to display time */
316 TimeLabel
= XtCreateManagedWidget("time", labelWidgetClass
,
321 /* ************************************************ */
322 /* create all the sliders */
323 /* ************************************************ */
326 MakeSliderWithLabel(form
, &SpeedSL
);
327 MakeSliderWithLabel(form
, &PositionSL
);
328 MakeSliderWithLabel(form
, &ThicknessSL
);
330 /* ******************************************************** */
331 /* create a radio group for axis, view, motion directions */
332 /* ******************************************************** */
334 MakeRadioGroup(form
, &AxisRadio
);
335 MakeRadioGroup(form
, &DirectionRadio
);
336 MakeRadioGroup(form
, &MotionRadio
);
338 /* create a label widget to put axes in */
340 /* SJP - 10/02, had to add last NULL argument to each call */
342 Axes
= XtVaCreateManagedWidget("axes", labelWidgetClass
, form
,
343 XtNlabel
, null_string
,NULL
);
345 ReadInfo
= XtVaCreateManagedWidget("read", labelWidgetClass
,
346 form
, XtNlabel
, null_string
,NULL
);
350 PRIVATE XtActionProc
NoOp(Widget w
, XEvent event
, String
*params
,
356 void SetTime(char *s
)
358 XtVaSetValues(TimeLabel
, XtNlabel
, s
, NULL
);
361 PRIVATE
void SetSpeed(float percent
)
366 speed
= percent
* 100;
367 (void) sprintf(string
,"Speed: %i", speed
);
369 XtVaSetValues(SpeedLabel
, XtNlabel
, string
, NULL
);
372 PRIVATE
void NewSpeed(Widget w
, XtPointer client_data
, XtPointer percent_ptr
)
376 percent
= * (float *) percent_ptr
;
378 /* delay between frames in milliseconds */
380 Common
.delay
= 30 + 10.0/(0.01 + percent
);
385 PRIVATE
void SetPosition(float position
)
389 static char *axis
[] = { "X", "Y", "Z" };
391 (void) sprintf(string
,"%s Position: %6.3f", axis
[Common
.axis
],
394 XtVaSetValues(PositionLabel
, XtNlabel
, string
, NULL
);
397 PRIVATE
void NewPosition(Widget w
, XtPointer client_data
, XtPointer percent_ptr
)
403 percent
= * (float *) percent_ptr
;
407 old_pos
= Common
.position
;
410 (Common
.bounds
[i
].high
- Common
.bounds
[i
].low
) * percent
+
411 Common
.bounds
[i
].low
;
413 SetPosition(Common
.position
);
415 if (Common
.position
== old_pos
) return;
417 if (normal
) SceneUpdate();
420 PRIVATE
void SetThickness(float thickness
)
424 (void) sprintf(string
,"Thickness: %6.3f", thickness
);
426 XtVaSetValues(ThicknessLabel
, XtNlabel
, string
, NULL
);
429 PRIVATE
void NewThickness(Widget w
, XtPointer client_data
, XtPointer percent_ptr
)
435 percent
= * (float *) percent_ptr
;
438 old_thick
= Common
.thickness
;
440 (Common
.bounds
[i
].high
- Common
.bounds
[i
].low
) * percent
;
442 if (old_thick
== Common
.thickness
) return;
444 SetThickness(Common
.thickness
);
446 if (normal
) SceneUpdate();
449 /* **************************************************************** */
451 PRIVATE
void AxisSelect(Widget w
, XtPointer client_data
, XtPointer call_data
)
455 new_axis
= (int) client_data
;
457 if (new_axis
== Common
.axis
) return;
459 Common
.axis
= new_axis
;
465 FindAndDisplaySlider(PositionBar
, NewPosition
);
466 FindAndDisplaySlider(ThicknessBar
, NewThickness
);
473 PRIVATE
void DirectionSelect(Widget w
, XtPointer client_data
, XtPointer call_data
)
477 new_dir
= (int) client_data
;
479 if (new_dir
== Common
.direction
) return;
481 Common
.direction
= new_dir
;
487 PRIVATE
void MotionSelect(Widget w
, XtPointer client_data
, XtPointer call_data
)
491 new_dir
= (int) client_data
;
493 Common
.dstep
= new_dir
;
497 PRIVATE
void FindAndDisplaySlider(Widget w
, XtCallbackProc func
)
501 XtVaGetValues(w
, XtNtopOfThumb
, &percent
, NULL
);
503 (func
)(NULL
, NULL
, &percent
);
506 void PositionUpdate(void)
508 FindAndDisplaySlider(PositionBar
, NewPosition
);
511 void ThicknessUpdate(void)
513 FindAndDisplaySlider(ThicknessBar
, NewThickness
);
516 void SpeedUpdate(void)
518 FindAndDisplaySlider(SpeedBar
, NewSpeed
);
521 /* **************************************************************** */
534 static AXIS axis_data
[] = {
535 { { { 120, 120, 120, 30 }, { 115, 35, 120, 30 },
536 { 120, 30, 125, 35 }, { 120, 120, 30, 120 },
537 { 35, 125, 30, 120 }, { 30, 120, 35, 115 } },
538 { { 15, 127, "Z" }, { 115, 25, "Y" } },
540 { { { 20, 20, 20, 110 }, { 15, 105, 20, 110 },
541 { 20, 110, 25, 105 }, { 20, 20, 110, 20 },
542 { 105, 15, 110, 20 }, { 110, 20, 105, 25 } },
543 { { 115, 27, "X" }, { 15, 127, "Z" } },
545 { { { 20, 120, 20, 30 }, { 15, 35, 20, 30 },
546 { 20, 30, 25, 35 }, { 20, 120, 110, 120 },
547 { 105, 125, 110, 120 }, { 110, 120, 105, 115 } },
548 { { 115, 127, "X" }, { 15, 27, "Y" } },
550 { { { 20, 120, 20, 30 }, { 15, 35, 20, 30 },
551 { 20, 30, 25, 35 }, { 20, 120, 110, 120 },
552 { 105, 125, 110, 120 }, { 110, 120, 105, 115 } },
553 { { 115, 127, "Z" }, { 15, 27, "Y" } },
555 { { { 20, 120, 20, 30 }, { 15, 35, 20, 30 },
556 { 20, 30, 25, 35 }, { 20, 120, 110, 120 },
557 { 105, 125, 110, 120 }, { 110, 120, 105, 115 } },
558 { { 115, 127, "X" }, { 15, 27, "Z" } },
560 { { { 20, 20, 20, 110 }, { 15, 105, 20, 110 },
561 { 20, 110, 25, 105 }, { 20, 20, 110, 20 },
562 { 105, 15, 110, 20 }, { 110, 20, 105, 25 } },
563 { { 115, 27, "X" }, { 15, 127, "Y" } },
567 PRIVATE
void DrawAxes(void)
569 static int first
= 1;
571 static Dimension height
, width
;
577 if ( Common
.axis
< 0 ||
578 Common
.direction
< 0 ||
580 !XtIsRealized(Axes
) ) return;
583 xgc
.function
= GXcopy
;
586 XtNbackground
, &xgc
.background
,
587 XtNforeground
, &xgc
.foreground
,
593 xgc
.font
= font
->fid
;
595 gc
= XCreateGC(XtDisplay(Axes
), XtWindow(Axes
),
596 GCFunction
| GCBackground
| GCForeground
| GCFont
,
602 XClearWindow(XtDisplay(Axes
), XtWindow(Axes
));
604 a
= axis_data
+ Common
.axis
+ 3*Common
.direction
;
606 XDrawSegments(XtDisplay(Axes
), XtWindow(Axes
), gc
, a
->lines
, 6);
608 for(i
= 0; i
< 2; i
++)
609 XDrawString(XtDisplay(Axes
), XtWindow(Axes
), gc
,
610 a
->labels
[i
].x
, a
->labels
[i
].y
,
612 strlen(a
->labels
[i
].name
));
615 void ExposeAxes(Widget w
, XEvent
*event
, String
*strings
, Cardinal
*nstrings
)
621 /* **************************************************************** */
623 PRIVATE
void MakeRadioGroup(Widget parent
, RadioStruct
*radio
)
629 radio
->lw
= XtCreateManagedWidget(radio
->name
,
630 labelWidgetClass
, parent
, NULL
, ZERO
);
632 for(t
= radio
->buttons
, i
= radio
->nbuttons
; i
; i
--, t
++) {
633 t
->w
= XtCreateManagedWidget(t
->name
, toggleWidgetClass
,
635 XtAddCallback(t
->w
, XtNcallback
, radio
->callback
,
636 (XtPointer
) t
->value
);
641 /* **************************************************************** */
643 PRIVATE
void MakeSliderWithLabel(Widget parent
, SliderLabelStruct
*sl
)
645 /* create the slider */
647 *(sl
->slider
) = XtCreateManagedWidget(sl
->slidername
,
648 scrollbarWidgetClass
, parent
, NULL
, ZERO
);
650 /* add the callback */
652 XtAddCallback(*(sl
->slider
), XtNjumpProc
, sl
->callback
, NULL
);
654 /* create the label */
656 *(sl
->label
) = XtCreateManagedWidget(sl
->labelname
,
657 labelWidgetClass
, parent
, NULL
, ZERO
);
659 /* Initialize the display */
661 FindAndDisplaySlider(*(sl
->slider
), sl
->callback
);
665 void UpdateRadios(void)
667 SetRadio(&AxisRadio
);
668 SetRadio(&DirectionRadio
);
669 SetRadio(&MotionRadio
);
672 PRIVATE
void SetRadio(RadioStruct
*radio
)
676 char set_name
[80], *rg
;
680 /* find out which toggle is currently set */
681 strcpy(set_name
, (char *) XawToggleGetCurrent(t
->w
));
683 for(i
= radio
->nbuttons
; i
; i
--, t
++)
684 if (!strcmp(set_name
, t
->name
)) goto found_set
;
688 XtVaGetValues(t
->w
, XtNradioGroup
, &rg
, NULL
);
689 fprintf(stderr
,"Error: radioData for radioGroup %s inconsistent.\n",
691 XtDestroyApplicationContext(XtWidgetToApplicationContext(TopLevel
));
696 /* call the callback with the proper data */
698 (radio
->callback
)((Widget
) t
->w
, (XtPointer
) t
->value
, (XtPointer
) 0);
701 void SetReadString(char *s
)
703 if (ReadInfo
== (Widget
) 0) return;
705 XtVaSetValues(ReadInfo
, XtNlabel
, s
, NULL
);
708 /* **************************************************************** */
710 PRIVATE
void init_quit(Widget parent
)
714 /* create a popup shell */
716 QuitPopup
= XtCreatePopupShell("popup", POPUPSHELLCLASS
,
719 /* put a dialog box in it */
721 dialog
= XtCreateManagedWidget("dialog", dialogWidgetClass
,
722 QuitPopup
, NULL
, ZERO
);
724 XawDialogAddButton(dialog
, "ok", quit_ok
, (XtPointer
) dialog
);
725 XawDialogAddButton(dialog
, "cancel", cancel_popup
,
726 (XtPointer
) &QuitData
);
730 /* **************************************************************** */
732 PRIVATE
void do_popup(Widget w
, XtPointer client_data
, XtPointer call_data
)
737 pdata
= (PopupData
*) client_data
;
739 /* stop motion for now */
741 if (pdata
->stop_motion
) {
742 in_motion
= Common
.motion
;
746 /* translate to corner of calling widgets window */
748 XtTranslateCoords(w
, 0, 0, &x
, &y
);
750 /* Set us to pop up there */
752 XtVaSetValues(*(pdata
->w
), XtNx
, x
, XtNy
, y
, NULL
);
756 XtPopup(*(pdata
->w
), pdata
->grab
);
760 PRIVATE
void quit_ok(Widget w
, XtPointer client_data
, XtPointer call_data
)
762 XtDestroyApplicationContext(XtWidgetToApplicationContext(w
));
766 PRIVATE
void cancel_popup(Widget w
, XtPointer client_data
, XtPointer call_data
)
770 pdata
= (PopupData
*) client_data
;
772 if (pdata
->stop_motion
&& in_motion
) InstallMotion();
774 XtPopdown(*(pdata
->w
));
777 /* **************************************************************** */
779 PRIVATE
void do_start(Widget w
, XtPointer client_data
, XtPointer call_data
)
784 PRIVATE
void do_stop(Widget w
, XtPointer client_data
, XtPointer call_data
)
789 PRIVATE
void do_restart(Widget w
, XtPointer client_data
, XtPointer call_data
)
793 if (Common
.dstep
> 0)
796 Common
.step
= Common
.ndata
-1;
801 PRIVATE
void do_step(Widget w
, XtPointer client_data
, XtPointer call_data
)
805 Common
.step
= CoerceStep(Common
.step
+ 1);
810 PRIVATE
void do_back(Widget w
, XtPointer client_data
, XtPointer call_data
)
814 Common
.step
= CoerceStep(Common
.step
- 1);
819 PRIVATE
void do_save_off(Widget w
, XtPointer client_data
, XtPointer call_data
)
824 PRIVATE
void do_save_on(Widget w
, XtPointer client_data
, XtPointer call_data
)
829 PRIVATE
void do_save_one(Widget w
, XtPointer client_data
, XtPointer call_data
)
834 /* **************************************************************** */
836 PRIVATE
void init_atoms(Widget parent
)
838 Widget outerform
, form
;
839 Widget apply
, cancel
, last
;
840 char formname
[80], fglabel
[80], sizelabel
[80];
841 char fgname
[80], sizename
[80], vname
[80], iname
[80];
845 /* create a popup shell for atom colors */
847 AtomPopup
= XtCreatePopupShell("atomcolors",
848 transientShellWidgetClass
, TopLevel
, NULL
, ZERO
);
850 /* put a form widget in it for layout */
852 outerform
= XtCreateManagedWidget("form", formWidgetClass
, AtomPopup
,
855 /* add the buttons */
857 apply
= XtCreateManagedWidget("apply", commandWidgetClass
,
858 outerform
, NULL
, ZERO
);
859 XtAddCallback(apply
, XtNcallback
, color_apply
,
862 cancel
= XtVaCreateManagedWidget("cancel", commandWidgetClass
,
863 outerform
, XtNfromHoriz
, apply
, NULL
);
864 XtAddCallback(cancel
, XtNcallback
, cancel_popup
,
865 (XtPointer
) &AtomData
);
867 /* put the dialog boxes in it for the colors */
869 /* ************************************************ */
870 /* allocate all the widgets */
871 /* ************************************************ */
873 size
= Common
.natomcolors
* sizeof(Widget
);
875 FGDialog
= (Widget
*) XtMalloc(size
);
876 SizeDialog
= (Widget
*) XtMalloc(size
);
877 Visible
= (Widget
*) XtMalloc(size
);
878 Invisible
= (Widget
*) XtMalloc(size
);
880 /* ************************************************ */
881 /* build the rest of the panel */
882 /* ************************************************ */
886 for(i
= 0; i
< Common
.natomcolors
; i
++) {
889 sprintf(formname
, "colorform%i", j
);
890 sprintf(fgname
, "color%i", j
);
891 sprintf(fglabel
, "Type %i Color", j
);
892 sprintf(sizename
, "size%i", j
);
893 sprintf(sizelabel
, "Type %i Diameter", j
);
894 sprintf(vname
, "visible%i", j
);
895 sprintf(iname
, "invisible%i", j
);
897 form
= XtVaCreateManagedWidget(formname
, formWidgetClass
,
898 outerform
, XtNfromVert
, last
, NULL
);
900 FGDialog
[i
] = XtVaCreateManagedWidget(fgname
,
901 dialogWidgetClass
, form
, XtNlabel
, fglabel
,
902 XtNvalue
, "white", NULL
);
904 SizeDialog
[i
] = XtVaCreateManagedWidget(sizename
,
905 dialogWidgetClass
, form
, XtNlabel
, sizelabel
,
906 XtNvalue
, "10", XtNfromHoriz
, FGDialog
[i
], NULL
);
908 Visible
[i
] = XtVaCreateManagedWidget(vname
,
909 toggleWidgetClass
, form
, XtNlabel
, "Visible",
910 XtNstate
, True
, XtNfromVert
, FGDialog
[i
], NULL
);
912 Invisible
[i
] = XtVaCreateManagedWidget(iname
,
913 toggleWidgetClass
, form
, XtNlabel
, "Invisible",
914 XtNstate
, False
, XtNradioGroup
, Visible
[i
],
915 XtNfromHoriz
, Visible
[i
], XtNfromVert
, FGDialog
[i
],
918 XtAddCallback(Visible
[i
], XtNcallback
, visible_toggle
,
921 XtAddCallback(Invisible
[i
], XtNcallback
, visible_toggle
,
924 Common
.atoms_visible
[i
] = True
;
925 Common
.diameter
[i
] = 10;
930 /* **************************************************************** */
932 PRIVATE
void init_bg(Widget parent
)
935 Widget apply
, cancel
;
937 /* create a popup shell for background color */
939 BackgroundPopup
= XtCreatePopupShell("backcolors",
940 transientShellWidgetClass
, TopLevel
, NULL
, ZERO
);
942 /* put a form widget in it for layout */
944 outerform
= XtCreateManagedWidget("form", formWidgetClass
,
945 BackgroundPopup
, NULL
, ZERO
);
947 /* add the buttons */
949 apply
= XtCreateManagedWidget("apply", commandWidgetClass
,
950 outerform
, NULL
, ZERO
);
951 XtAddCallback(apply
, XtNcallback
, bg_apply
, (XtPointer
) NULL
);
953 cancel
= XtVaCreateManagedWidget("cancel", commandWidgetClass
,
954 outerform
, XtNfromHoriz
, apply
, NULL
);
955 XtAddCallback(cancel
, XtNcallback
, cancel_popup
,
956 (XtPointer
) &BackgroundData
);
958 /* put the dialog box in it for the color */
960 BGDialog
= XtVaCreateManagedWidget("bg", dialogWidgetClass
,
961 outerform
, XtNfromVert
, apply
, NULL
);
964 /* **************************************************************** */
966 PRIVATE
void init_file(Widget parent
)
969 Widget apply
, cancel
;
971 /* create a popup shell for color file */
973 FileColorPopup
= XtCreatePopupShell("filecolors",
974 transientShellWidgetClass
, TopLevel
, NULL
, ZERO
);
976 /* put a form widget in it for layout */
978 outerform
= XtCreateManagedWidget("form", formWidgetClass
,
979 FileColorPopup
, NULL
, ZERO
);
981 /* add the buttons */
983 apply
= XtCreateManagedWidget("apply", commandWidgetClass
,
984 outerform
, NULL
, ZERO
);
985 XtAddCallback(apply
, XtNcallback
, file_apply
, (XtPointer
) NULL
);
987 cancel
= XtVaCreateManagedWidget("cancel", commandWidgetClass
,
988 outerform
, XtNfromHoriz
, apply
, NULL
);
989 XtAddCallback(cancel
, XtNcallback
, cancel_popup
,
990 (XtPointer
) &FileColorData
);
992 /* put the dialog box in it for the filename */
994 FileDialog
= XtVaCreateManagedWidget("file", dialogWidgetClass
,
995 outerform
, XtNfromVert
, apply
, NULL
);
998 PRIVATE
void init_bonds(Widget parent
)
1000 Widget outerform
, form
;
1001 Widget apply
, cancel
, last
;
1002 char formname
[80], fglabel
[80], sizelabel
[80];
1003 char fgname
[80], sizename
[80], vname
[80], iname
[80];
1007 /* create a popup shell for bond colors */
1009 BondPopup
= XtCreatePopupShell("bondcolors",
1010 transientShellWidgetClass
,
1011 TopLevel
, NULL
, ZERO
);
1013 /* put a form widget in it for layout */
1015 outerform
= XtCreateManagedWidget("form", formWidgetClass
, BondPopup
,
1018 /* add the buttons */
1020 apply
= XtCreateManagedWidget("apply", commandWidgetClass
,
1021 outerform
, NULL
, ZERO
);
1022 XtAddCallback(apply
, XtNcallback
, bond_apply
,
1025 cancel
= XtVaCreateManagedWidget("cancel", commandWidgetClass
,
1026 outerform
, XtNfromHoriz
, apply
, NULL
);
1027 XtAddCallback(cancel
, XtNcallback
, cancel_popup
,
1028 (XtPointer
) &BondData
);
1030 /* ************************************************ */
1031 /* allocate all the widgets */
1032 /* ************************************************ */
1034 size
= Common
.nbondcolors
* sizeof(Widget
);
1036 BFGDialog
= (Widget
*) XtMalloc(size
);
1037 ThicknessDialog
= (Widget
*) XtMalloc(size
);
1038 BVisible
= (Widget
*) XtMalloc(size
);
1039 BInvisible
= (Widget
*) XtMalloc(size
);
1041 /* ************************************************ */
1042 /* build the rest of the panel */
1043 /* ************************************************ */
1047 for(i
= 0; i
< Common
.nbondcolors
; i
++) {
1050 sprintf(formname
, "bondform%i", j
);
1051 sprintf(fgname
, "color%i", j
);
1052 sprintf(fglabel
, "Bond Type %i Color", j
);
1053 sprintf(sizename
, "thickness%i", j
);
1054 sprintf(sizelabel
, "Bond Type %i Thickness",j
);
1055 sprintf(vname
, "visible%i", j
);
1056 sprintf(iname
, "invisible%i", j
);
1058 form
= XtVaCreateManagedWidget(formname
,
1059 formWidgetClass
, outerform
, XtNfromVert
,
1062 BFGDialog
[i
] = XtVaCreateManagedWidget(fgname
,
1063 dialogWidgetClass
, form
, XtNlabel
, fglabel
,
1064 XtNvalue
, "white", NULL
);
1066 ThicknessDialog
[i
] = XtVaCreateManagedWidget(sizename
,
1067 dialogWidgetClass
, form
, XtNlabel
, sizelabel
,
1068 XtNvalue
, "1", XtNfromHoriz
, BFGDialog
[i
], NULL
);
1070 BVisible
[i
] = XtVaCreateManagedWidget(vname
,
1071 toggleWidgetClass
, form
, XtNlabel
, "Visible",
1072 XtNstate
, True
, XtNfromVert
, BFGDialog
[i
], NULL
);
1074 BInvisible
[i
] = XtVaCreateManagedWidget(iname
,
1075 toggleWidgetClass
, form
, XtNlabel
, "Invisible",
1076 XtNstate
, False
, XtNradioGroup
, BVisible
[i
],
1077 XtNfromHoriz
, BVisible
[i
], XtNfromVert
, BFGDialog
[i
],
1080 XtAddCallback(BVisible
[i
], XtNcallback
, bvisible_toggle
,
1083 XtAddCallback(BInvisible
[i
], XtNcallback
, bvisible_toggle
,
1086 Common
.bonds_visible
[i
] = True
;
1091 /* **************************************************************** */
1093 PRIVATE
void color_apply(Widget w
, XtPointer client_data
, XtPointer call_data
)
1095 static String
*fg
, *size
;
1096 static Pixel
*fgpixel
;
1098 static Bool first
= True
;
1105 n
= Common
.natomcolors
;
1107 fg
= (String
*) XtMalloc( n
* sizeof(String
) );
1108 size
= (String
*) XtMalloc( n
* sizeof(String
) );
1109 fgpixel
= (Pixel
*) XtMalloc( n
* sizeof(Pixel
) );
1110 diam
= (int *) XtMalloc( n
* sizeof(int) );
1117 for(i
= 0; i
< Common
.natomcolors
; i
++) {
1118 fg
[i
] = XawDialogGetValueString(FGDialog
[i
]);
1119 fgpixel
[i
] = ConvertColorToPixel(FGDialog
[i
], fg
[i
]);
1121 if (fgpixel
[i
] == (Pixel
) -1) {
1123 XtVaSetValues(FGDialog
[i
], XtNvalue
,
1124 "-Invalid Color-", NULL
);
1127 size
[i
] = XawDialogGetValueString(SizeDialog
[i
]);
1128 diam
[i
] = atoi(size
[i
]);
1130 if (diam
[i
] < 1 || diam
[i
] > MAXDIAM
) {
1132 XtVaSetValues(SizeDialog
[i
], XtNvalue
,
1133 "-Invalid Size-", NULL
);
1138 XBell(XtDisplay(BGDialog
), 0);
1142 SetAtomColors(fgpixel
);
1144 for(i
= 0; i
< Common
.natomcolors
; i
++)
1145 Common
.diameter
[i
] = diam
[i
];
1150 /* **************************************************************** */
1152 PRIVATE
void bond_apply(Widget w
, XtPointer client_data
, XtPointer call_data
)
1154 static String
*fg
, *size
;
1155 static Pixel
*fgpixel
;
1156 static Dimension
*thick
;
1157 static Bool first
= True
;
1163 n
= Common
.nbondcolors
;
1165 fg
= (String
*) XtMalloc( n
* sizeof(String
) );
1166 size
= (String
*) XtMalloc( n
* sizeof(String
) );
1167 fgpixel
= (Pixel
*) XtMalloc( n
* sizeof(Pixel
) );
1168 thick
= (Dimension
*) XtMalloc( n
* sizeof(Dimension
) );
1175 for(i
= 0; i
< Common
.nbondcolors
; i
++) {
1176 fg
[i
] = XawDialogGetValueString(BFGDialog
[i
]);
1177 fgpixel
[i
] = ConvertColorToPixel(BFGDialog
[i
], fg
[i
]);
1179 if (fgpixel
[i
] == (Pixel
) -1) {
1181 XtVaSetValues(BFGDialog
[i
], XtNvalue
,
1182 "-Invalid Color-", NULL
);
1185 size
[i
] = XawDialogGetValueString(ThicknessDialog
[i
]);
1186 ithick
= atoi(size
[i
]);
1188 if (ithick
< 1 || ithick
> MAXTHICK
) {
1190 XtVaSetValues(ThicknessDialog
[i
], XtNvalue
,
1191 "-Invalid Size-", NULL
);
1197 XBell(XtDisplay(BGDialog
), 0);
1201 SetBondColors(fgpixel
, thick
);
1206 /* **************************************************************** */
1208 PRIVATE
void bg_apply(Widget w
, XtPointer client_data
, XtPointer call_data
)
1213 bg
= XawDialogGetValueString(BGDialog
);
1214 bgpixel
= ConvertColorToPixel(BGDialog
, bg
);
1216 if (bgpixel
== (Pixel
) -1) {
1217 XtVaSetValues(BGDialog
, XtNvalue
, "-Invalid Color-", NULL
);
1218 XBell(XtDisplay(BGDialog
), 0);
1222 SetBGColor(bgpixel
);
1227 PRIVATE Pixel
ConvertColorToPixel(Widget w
, String color
)
1232 from
.size
= strlen(color
) + 1;
1234 /* SJP - 10/02, new Linux couldn't fine caddr_t */
1235 /* to.addr = (caddr_t) &pixel; */
1236 to
.addr
= (char *) &pixel
;
1237 to
.size
= sizeof(pixel
);
1239 if (XtConvertAndStore(w
, XtRString
, (XrmValuePtr
) &from
,
1240 XtRPixel
, (XrmValuePtr
) &to
))
1243 return( (Pixel
) -1);
1247 PRIVATE
void file_apply(Widget w
, XtPointer client_data
, XtPointer call_data
)
1251 static String
*fg
, *size
;
1252 static Pixel
*fgpixel
;
1254 static Bool first
= True
;
1259 n
= Common
.natomcolors
;
1261 fg
= (String
*) XtMalloc( n
* sizeof(String
) );
1262 size
= (String
*) XtMalloc( n
* sizeof(String
) );
1263 fgpixel
= (Pixel
*) XtMalloc( n
* sizeof(Pixel
) );
1264 diam
= (int *) XtMalloc( n
* sizeof(int) );
1269 for(i
= 0; i
< Common
.natomcolors
; i
++) {
1271 fgpixel
[i
] = ConvertColorToPixel(FGDialog
[i
], fg
[i
]);
1273 if (fgpixel
[i
] == (Pixel
) -1) return;
1275 XtVaSetValues(FGDialog
[i
], XtNvalue
, fg
[i
], NULL
);
1278 diam
[i
] = atoi(size
[i
]);
1280 if (diam
[i
] < 1 || diam
[i
] > MAXDIAM
) return;
1281 XtVaSetValues(SizeDialog
[i
], XtNvalue
, size
[i
], NULL
);
1284 SetAtomColors(fgpixel
);
1286 for(i
= 0; i
< Common
.natomcolors
; i
++)
1287 Common
.diameter
[i
] = diam
[i
];
1290 Common.atoms_visible[0] = 0;
1291 Common.atoms_visible[1] = 0;
1292 Common.atoms_visible[2] = 0;
1293 Common.atoms_visible[3] = 0;
1297 bgpixel
= ConvertColorToPixel(BGDialog
, bg
);
1299 if (bgpixel
== (Pixel
) -1) {
1300 XtVaSetValues(BGDialog
, XtNvalue
, "-Invalid Color-", NULL
);
1301 XBell(XtDisplay(BGDialog
), 0);
1305 SetBGColor(bgpixel
);
1310 PRIVATE
void visible_toggle(Widget w
, XtPointer client_data
,
1311 XtPointer call_data
)
1317 i
= (int) client_data
;
1319 XtVaGetValues(w
, XtNradioData
, &data
, NULL
);
1321 c
= *((char *) data
);
1323 Common
.atoms_visible
[i
] = c
== 'v';
1326 PRIVATE
void bvisible_toggle(Widget w
, XtPointer client_data
,
1327 XtPointer call_data
)
1333 i
= (int) client_data
;
1335 XtVaGetValues(w
, XtNradioData
, &data
, NULL
);
1337 c
= *((char *) data
);
1339 Common
.bonds_visible
[i
] = c
== 'v';