1 /***********************************************************************/
2 /* Open Visualization Data Explorer                                    */
3 /* (C) Copyright IBM Corp. 1989,1999                                   */
4 /* ALL RIGHTS RESERVED                                                 */
5 /* This code licensed under the                                        */
6 /*    "IBM PUBLIC LICENSE - Open Visualization Data Explorer"          */
7 /***********************************************************************/
8 
9 #include <dxconfig.h>
10 #include "../base/defines.h"
11 
12 
13 #include <X11/StringDefs.h>
14 
15 #include <Xm/Xm.h>
16 #include <Xm/DialogS.h>
17 #include <Xm/Form.h>
18 #include <Xm/PushB.h>
19 #include <Xm/SeparatoG.h>
20 #include <Xm/Label.h>
21 #include <Xm/BulletinB.h>
22 
23 #include "ThrottleDialog.h"
24 #include "ImageWindow.h"
25 #include "../widgets/Number.h"
26 
27 boolean ThrottleDialog::ClassInitialized = FALSE;
28 
29 String  ThrottleDialog::DefaultResources[] = {
30 	"*dialogTitle:			Throttle...",
31         "*accelerators:              	#augment\n"
32           "<Key>Return:                 BulletinBoardReturn()",
33 	"*closeButton.labelString:	Close",
34 	"*closeButton.width:		60",
35 	"*closeButton.height:		30",
36 	".width:			280",
37 	".height:			100",
38 	"*label.labelString:		Seconds per Frame:",
39         NULL
40 };
41 
ThrottleDialog(char * name,ImageWindow * image)42 ThrottleDialog::ThrottleDialog(char *name, ImageWindow* image)
43                        		: Dialog(name, image->getRootWidget())
44 {
45     this->image = image;
46 }
47 
~ThrottleDialog()48 ThrottleDialog::~ThrottleDialog()
49 {
50 }
51 
initialize()52 void ThrottleDialog::initialize()
53 {
54     if (!ThrottleDialog::ClassInitialized) {
55 	ThrottleDialog::ClassInitialized = TRUE;
56         this->setDefaultResources(image->getRootWidget(),
57 			ThrottleDialog::DefaultResources);
58     }
59 
60 }
61 
createDialog(Widget parent)62 Widget ThrottleDialog::createDialog(Widget parent)
63 {
64     int n;
65     Arg arg[4];
66     Widget separator;
67 
68     n = 0;
69     XtSetArg(arg[n],XmNautoUnmanage,    True); n++;
70     XtSetArg(arg[n],XmNnoResize,        True); n++;
71 //    Widget dialog = XmCreateFormDialog(parent, this->name, arg, n);
72     Widget dialog = this->CreateMainForm(parent, this->name, arg, n);
73 #ifdef PASSDOUBLEVALUE
74 	XtArgVal dx_l1, dx_l2;
75 #endif
76 
77     this->closebtn = XtVaCreateManagedWidget("closeButton",
78 	xmPushButtonWidgetClass, dialog,
79         XmNleftAttachment,   XmATTACH_FORM,
80         XmNleftOffset,        5,
81         XmNbottomAttachment,  XmATTACH_FORM,
82         XmNbottomOffset,      10,
83         NULL);
84 
85     separator = XtVaCreateManagedWidget("separator",
86 	xmSeparatorGadgetClass, dialog,
87         XmNleftAttachment,    XmATTACH_FORM,
88         XmNleftOffset,        2,
89         XmNrightAttachment,   XmATTACH_FORM,
90         XmNrightOffset,       2,
91         XmNbottomAttachment,  XmATTACH_WIDGET,
92         XmNbottomWidget,      this->closebtn,
93         XmNbottomOffset,      10,
94         NULL);
95 
96 
97     this->label = XtVaCreateManagedWidget("label",
98 	xmLabelWidgetClass, dialog,
99 	XmNbottomAttachment,  XmATTACH_WIDGET,
100 	XmNbottomWidget,      separator,
101 	XmNbottomOffset,      10,
102 	XmNleftAttachment,    XmATTACH_FORM,
103 	XmNleftOffset,        5,
104 	XmNtopAttachment,     XmATTACH_FORM,
105 	XmNtopOffset,         10,
106 	NULL);
107 
108     double min=0.0, max = 100.0;
109     this->seconds = XtVaCreateManagedWidget("seconds",
110 	xmNumberWidgetClass, dialog,
111         XmNbottomAttachment, XmATTACH_WIDGET,
112 	XmNbottomWidget,     separator,
113 	XmNbottomOffset,     10,
114 	XmNrightAttachment,  XmATTACH_FORM,
115 	XmNrightOffset,      5,
116 	XmNtopAttachment,    XmATTACH_FORM,
117 	XmNtopOffset,        10,
118 	XmNdataType,         DOUBLE,
119 	XmNdecimalPlaces,    3,
120 	XmNcharPlaces,       5,
121 	XmNeditable,         True,
122         XmNfixedNotation,    False,
123 	XmNdMinimum,         DoubleVal(min, dx_l1),
124 	XmNdMaximum,         DoubleVal(max, dx_l2),
125 	NULL);
126 
127 #if 0
128     XtAddCallback(dialog,
129 		      XmNmapCallback,
130 		      (XtCallbackProc)ThrottleDialog_DoAllCB,
131 		      (XtPointer)this);
132 #endif
133 
134     XtAddCallback(this->seconds,
135 		      XmNactivateCallback,
136 		      (XtCallbackProc)ThrottleDialog_DoAllCB,
137 		      (XtPointer)this);
138     return dialog;
139 }
140 
141 
142 
manage()143 void ThrottleDialog::manage()
144 {
145     Dimension dialogWidth;
146 
147     if (!XtIsRealized(this->getRootWidget()))
148 	XtRealizeWidget(this->getRootWidget());
149 
150     XtVaGetValues(this->getRootWidget(),
151 	XmNwidth, &dialogWidth,
152 	NULL);
153 
154     Position x;
155     Position y;
156     Dimension width;
157     XtVaGetValues(parent,
158 	XmNx, &x,
159 	XmNy, &y,
160 	XmNwidth, &width,
161 	NULL);
162 
163     if (x > dialogWidth + 10)
164 	x -= dialogWidth + 10;
165     else
166 	x += width + 10;
167 
168     Display *dpy = XtDisplay(this->getRootWidget());
169     if (x > WidthOfScreen(DefaultScreenOfDisplay(dpy)) - dialogWidth)
170 	x = WidthOfScreen(DefaultScreenOfDisplay(dpy)) - dialogWidth;
171     XtVaSetValues(this->getRootWidget(),
172 	XmNdefaultPosition, False,
173 	NULL);
174     XtVaSetValues(XtParent(this->getRootWidget()),
175 	XmNdefaultPosition, False,
176 	XmNx, x,
177 	XmNy, y,
178 	NULL);
179 
180     this->Dialog::manage();
181     double	value;
182     this->image->getThrottle(value);
183     XmChangeNumberValue((XmNumberWidget)this->seconds, value);
184 
185 }
186 
installThrottleValue(double value)187 void ThrottleDialog::installThrottleValue(double value)
188 {
189     XmChangeNumberValue((XmNumberWidget)this->seconds, value);
190 }
191 
ThrottleDialog_DoAllCB(Widget widget,XtPointer clientData,XtPointer callData)192 extern "C" void ThrottleDialog_DoAllCB(Widget    widget,
193                                 XtPointer clientData,
194                                 XtPointer callData)
195 {
196 
197     ASSERT(clientData);
198     ThrottleDialog *dialog = (ThrottleDialog*) clientData;
199     XmAnyCallbackStruct* cbs = (XmAnyCallbackStruct*) callData;
200     double	value;
201 
202     switch(cbs->reason)
203     {
204 #if 0
205 	case XmCR_MAP:
206 
207 	     dialog->image->getThrottle(value);
208 	     XmChangeNumberValue((XmNumberWidget)dialog->seconds, value);
209 
210 	     break;
211 #endif
212 
213 	default:
214 
215 	     XtVaGetValues(dialog->seconds, XmNdValue, &value, NULL);
216 	     dialog->image->setThrottle(value);
217 
218 	     break;
219 
220     }
221 
222 }
223