1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 #ifdef HAVE_CONFIG_H
27 #include "../config.h"
28 #endif
29
30 #include <Xm/XmP.h>
31
32 #include "SlideCP.h"
33
34 #ifdef WITH_DMALLOC
35 #include <dmalloc.h>
36 #endif
37
38 #include <inttypes.h>
39
40
41
42
43
44 static void class_initialize(
void);
45 static void class_part_initialize(WidgetClass widget_class);
46 static void initialize(Widget request, Widget new_w, ArgList args, Cardinal *num_args);
47 static void destroy(Widget w);
48 static Boolean set_values(Widget old, Widget request, Widget new_w, ArgList args, Cardinal *num_args);
49 static void get_values_hook(Widget w, ArgList args, Cardinal *num_args);
50
51 static void _XltSlideProc(Widget w);
52 static void targetDestroy(Widget target, Widget w);
53
54
55
56
57
58 #define Offset(field) XtOffsetOf(XltSlideContextRec, slide.field)
59 static XtResource resources[] =
60 {
61 {
62 XltNslideFinishCallback, XtCCallback, XtRCallback,
63 sizeof(XtCallbackList), Offset(slideFinishCallback),
64 XtRCallback,
NULL
65 },
66 {
67 XltNslideMotionCallback, XtCCallback, XtRCallback,
68 sizeof(XtCallbackList), Offset(slideMotionCallback),
69 XtRCallback,
NULL
70 },
71 {
72 XltNslideWidget, XltCSlideWidget, XtRWidget,
73 sizeof(Widget), Offset(slide_widget),
74 XtRImmediate,
NULL
75 },
76 {
77 XltNslideInterval, XltCSlideInterval, XtRInt,
78 sizeof(
int), Offset(interval),
79 XtRImmediate, (XtPointer)
5
80 },
81 {
82 XltNslideDestWidth, XltCSlideDestWidth, XtRDimension,
83 sizeof(Dimension), Offset(dest_width),
84 XtRImmediate, (XtPointer)XmUNSPECIFIED
85 },
86 {
87 XltNslideDestHeight, XltCSlideDestHeight, XtRDimension,
88 sizeof(Dimension), Offset(dest_height),
89 XtRImmediate, (XtPointer)XmUNSPECIFIED
90 },
91 {
92 XltNslideDestX, XltCSlideDestX, XtRPosition,
93 sizeof(Position), Offset(dest_x),
94 XtRImmediate, (XtPointer)XmUNSPECIFIED_POSITION
95 },
96 {
97 XltNslideDestY, XltCSlideDestY, XtRPosition,
98 sizeof(Position), Offset(dest_y),
99 XtRImmediate, (XtPointer)XmUNSPECIFIED_POSITION
100 },
101 };
102 #undef Offset
103
104
105
106
107 XltSlideContextClassRec xltSlideContextClassRec = {
108
109 {
110 (WidgetClass) &objectClassRec,
111 "XltSlideContext",
112 sizeof(XltSlideContextRec),
113 class_initialize,
114 class_part_initialize,
115 False,
116 initialize,
117 NULL,
118 NULL,
119 NULL,
120 (Cardinal)(
intptr_t)
NULL,
121 resources,
122 XtNumber(resources),
123 NULLQUARK,
124 (Boolean)(
intptr_t)
NULL,
125 (XtEnum)(
intptr_t)
NULL,
126 (Boolean)(
intptr_t)
NULL,
127 (Boolean)(
intptr_t)
NULL,
128 destroy,
129 NULL,
130 NULL,
131 set_values,
132 NULL,
133 NULL,
134 get_values_hook,
135 NULL,
136 XtVersion,
137 NULL,
138 NULL,
139 NULL,
140 NULL,
141 NULL
142 },
143
144 {
145 NULL
146 }
147 };
148
149 WidgetClass xltSlideContextWidgetClass = (WidgetClass)&xltSlideContextClassRec;
150
151 static void
152 class_initialize(
void)
153 {
154 }
155
156 static void
157 class_part_initialize(WidgetClass widget_class)
158 {
159 }
160
161 static void
162 initialize(Widget request, Widget new_w, ArgList args, Cardinal *num_args)
163 {
164
165
166
167
168
169
170 if (Slide_DestWidth(new_w) == (Dimension)XmUNSPECIFIED)
171 {
172 Slide_DestWidth(new_w) = XtWidth(Slide_Widget(new_w));
173 }
174 if (Slide_DestHeight(new_w) == (Dimension)XmUNSPECIFIED)
175 {
176 Slide_DestHeight(new_w) = XtHeight(Slide_Widget(new_w));
177 }
178 if (Slide_DestX(new_w) == XmUNSPECIFIED_POSITION)
179 {
180 Slide_DestX(new_w) = XtX(Slide_Widget(new_w));
181 }
182 if (Slide_DestY(new_w) == XmUNSPECIFIED_POSITION)
183 {
184 Slide_DestY(new_w) = XtY(Slide_Widget(new_w));
185 }
186 Slide_Id(new_w) = XtAppAddTimeOut(XtWidgetToApplicationContext(new_w),
187 Slide_Interval(new_w),
188 (XtTimerCallbackProc)_XltSlideProc,
189 new_w);
190 XtAddCallback(Slide_Widget(new_w), XmNdestroyCallback, (XtCallbackProc)targetDestroy, new_w);
191 }
192
193 static void
194 destroy(Widget w)
195 {
196 if (Slide_Id(w) != (XtIntervalId)
NULL)
197 {
198 XtRemoveTimeOut(Slide_Id(w));
199 Slide_Id(w) = (XtIntervalId)
NULL;
200 }
201 XtRemoveCallback(Slide_Widget(w), XmNdestroyCallback, (XtCallbackProc)targetDestroy, w);
202 }
203
204 static Boolean
205 set_values(Widget old, Widget request, Widget new_w, ArgList args, Cardinal *num_args)
206 {
207 if (Slide_Widget(old) != Slide_Widget(new_w))
208 {
209 XtRemoveCallback(Slide_Widget(old), XmNdestroyCallback, (XtCallbackProc)targetDestroy, old);
210 XtAddCallback(Slide_Widget(new_w), XmNdestroyCallback, (XtCallbackProc)targetDestroy, new_w);
211 }
212 return(False);
213 }
214
215 static void
216 get_values_hook(Widget w, ArgList args, Cardinal *num_args)
217 {
218 }
219
220 static void
221 targetDestroy(Widget target, Widget w)
222 {
223 XtDestroyWidget(w);
224 }
225
226 static void
227 _XltSlideProc(Widget w)
228 {
229 Dimension width, height;
230 Position x, y;
231
232
233
234
235
236
237
238 width = XtWidth(Slide_Widget(w));
239 height = XtHeight(Slide_Widget(w));
240 x = XtX(Slide_Widget(w));
241 y = XtY(Slide_Widget(w));
242 {
243 height = height - (((height - Slide_DestHeight(w)) *
10) /
100);
244 if (height < Slide_DestHeight(w))
245 {
246 height++;
247 }
248 if (height > Slide_DestHeight(w))
249 {
250 height--;
251 }
252 width = width - (((width - Slide_DestWidth(w)) *
10) /
100);
253 if (width < Slide_DestWidth(w))
254 {
255 width++;
256 }
257 if (width > Slide_DestWidth(w))
258 {
259 width--;
260 }
261 }
262 {
263 y = y - ((((y - Slide_DestY(w)) *
10) /
100) +
0);
264 if (y < Slide_DestY(w))
265 {
266 y++;
267 }
268 if (y > Slide_DestY(w))
269 {
270 y--;
271 }
272 x = x - ((((x - Slide_DestX(w)) *
10) /
100) +
0);
273 if (x < Slide_DestX(w))
274 {
275 x++;
276 }
277 if (x > Slide_DestX(w))
278 {
279 x--;
280 }
281 }
282
283
284
285 XtVaSetValues(Slide_Widget(w),
286 XmNx, x,
287 XmNy, y,
288 XmNwidth, width,
289 XmNheight, height,
290 NULL);
291 if (Slide_DestX(w) == XtX(Slide_Widget(w)) &&
292 Slide_DestY(w) == XtY(Slide_Widget(w)) &&
293 Slide_DestWidth(w) == XtWidth(Slide_Widget(w)) &&
294 Slide_DestHeight(w) == XtHeight(Slide_Widget(w)))
295 {
296 XtCallCallbackList(w, Slide_FinishCallback(w),
NULL);
297 XtRemoveCallback(Slide_Widget(w), XmNdestroyCallback, (XtCallbackProc)targetDestroy, w);
298 XtDestroyWidget(w);
299 }
300 else
301 {
302 Slide_Id(w) = XtAppAddTimeOut(XtWidgetToApplicationContext(w),
303 Slide_Interval(w),
304 (XtTimerCallbackProc)_XltSlideProc,
305 w);
306 }
307 }
308