Remove duplicate free.
[nedit.git] / Xlt / SlideC.c
blobe9f573fef61b2a5a1fc81869bcc1f35bf049bf6e
1 /**
3 * $Id: SlideC.c,v 1.5 2005/12/01 14:31:43 tringali Exp $
5 * Copyright (C) 1996 Free Software Foundation, Inc.
6 * Copyright © 1999-2001 by the LessTif developers.
8 * This file is part of the GNU LessTif Extension Library.
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Library General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Library General Public License for more details.
20 * You should have received a copy of the GNU Library General Public
21 * License along with this library; if not, write to the Free
22 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 **/
26 #ifdef HAVE_CONFIG_H
27 #include "../config.h"
28 #endif
30 #include <Xm/XmP.h>
32 #include "SlideCP.h"
34 #ifdef WITH_DMALLOC
35 #include <dmalloc.h>
36 #endif
40 Widget methods, forward declarations
43 static void class_initialize(void);
44 static void class_part_initialize(WidgetClass widget_class);
45 static void initialize(Widget request, Widget new_w, ArgList args, Cardinal *num_args);
46 static void destroy(Widget w);
47 static Boolean set_values(Widget old, Widget request, Widget new_w, ArgList args, Cardinal *num_args);
48 static void get_values_hook(Widget w, ArgList args, Cardinal *num_args);
50 static void _XltSlideProc(Widget w);
51 static void targetDestroy(Widget target, Widget w);
54 Widget default resources
57 #define Offset(field) XtOffsetOf(XltSlideContextRec, slide.field)
58 static XtResource resources[] =
61 XltNslideFinishCallback, XtCCallback, XtRCallback,
62 sizeof(XtCallbackList), Offset(slideFinishCallback),
63 XtRCallback, NULL
66 XltNslideMotionCallback, XtCCallback, XtRCallback,
67 sizeof(XtCallbackList), Offset(slideMotionCallback),
68 XtRCallback, NULL
71 XltNslideWidget, XltCSlideWidget, XtRWidget,
72 sizeof(Widget), Offset(slide_widget),
73 XtRImmediate, NULL
76 XltNslideInterval, XltCSlideInterval, XtRInt,
77 sizeof(int), Offset(interval),
78 XtRImmediate, (XtPointer)5
81 XltNslideDestWidth, XltCSlideDestWidth, XtRDimension,
82 sizeof(Dimension), Offset(dest_width),
83 XtRImmediate, (XtPointer)XmUNSPECIFIED
86 XltNslideDestHeight, XltCSlideDestHeight, XtRDimension,
87 sizeof(Dimension), Offset(dest_height),
88 XtRImmediate, (XtPointer)XmUNSPECIFIED
91 XltNslideDestX, XltCSlideDestX, XtRPosition,
92 sizeof(Position), Offset(dest_x),
93 XtRImmediate, (XtPointer)XmUNSPECIFIED_POSITION
96 XltNslideDestY, XltCSlideDestY, XtRPosition,
97 sizeof(Position), Offset(dest_y),
98 XtRImmediate, (XtPointer)XmUNSPECIFIED_POSITION
101 #undef Offset
104 Widget class record
106 XltSlideContextClassRec xltSlideContextClassRec = {
107 /* Object Class Part */
109 /* pointer to superclass ClassRec WidgetClass */ (WidgetClass) &objectClassRec,
110 /* widget resource class name String */ "XltSlideContext",
111 /* size in bytes of widget record Cardinal */ sizeof(XltSlideContextRec),
112 /* class initialization proc XtProc */ class_initialize,
113 /* dynamic initialization XtWidgetClassProc */ class_part_initialize,
114 /* has class been initialized? XtEnum */ False,
115 /* initialize subclass fields XtInitProc */ initialize,
116 /* notify that initialize called XtArgsProc */ NULL,
117 /* NULL XtProc */ NULL,
118 /* NULL XtPointer */ NULL,
119 /* NULL Cardinal */ (Cardinal)NULL,
120 /* resources for subclass fields XtResourceList */ resources,
121 /* number of entries in resources Cardinal */ XtNumber(resources),
122 /* resource class quarkified XrmClass */ NULLQUARK,
123 /* NULL Boolean */ (Boolean)NULL,
124 /* NULL XtEnum */ (XtEnum)NULL,
125 /* NULL Boolean */ (Boolean)NULL,
126 /* NULL Boolean */ (Boolean)NULL,
127 /* free data for subclass pointers XtWidgetProc */ destroy,
128 /* NULL XtProc */ NULL,
129 /* NULL XtProc */ NULL,
130 /* set subclass resource values XtSetValuesFunc */ set_values,
131 /* notify that set_values called XtArgsFunc */ NULL,
132 /* NULL XtProc */ NULL,
133 /* notify that get_values called XtArgsProc */ get_values_hook,
134 /* NULL XtProc */ NULL,
135 /* version of intrinsics used XtVersionType */ XtVersion,
136 /* list of callback offsets XtPointer */ NULL,
137 /* NULL String */ NULL,
138 /* NULL XtProc */ NULL,
139 /* NULL XtProc */ NULL,
140 /* pointer to extension record XtPointer */ NULL
142 /* SlideContext Class Part */
144 NULL
148 WidgetClass xltSlideContextWidgetClass = (WidgetClass)&xltSlideContextClassRec;
150 static void
151 class_initialize(void)
155 static void
156 class_part_initialize(WidgetClass widget_class)
160 static void
161 initialize(Widget request, Widget new_w, ArgList args, Cardinal *num_args)
164 printf("%s:%s(%d) - %s %li\n", __FILE__, __FUNCTION__, __LINE__,
165 XtName(new_w),
166 Slide_Interval(new_w));
169 if (Slide_DestWidth(new_w) == (Dimension)XmUNSPECIFIED)
171 Slide_DestWidth(new_w) = XtWidth(Slide_Widget(new_w));
173 if (Slide_DestHeight(new_w) == (Dimension)XmUNSPECIFIED)
175 Slide_DestHeight(new_w) = XtHeight(Slide_Widget(new_w));
177 if (Slide_DestX(new_w) == XmUNSPECIFIED_POSITION)
179 Slide_DestX(new_w) = XtX(Slide_Widget(new_w));
181 if (Slide_DestY(new_w) == XmUNSPECIFIED_POSITION)
183 Slide_DestY(new_w) = XtY(Slide_Widget(new_w));
185 Slide_Id(new_w) = XtAppAddTimeOut(XtWidgetToApplicationContext(new_w),
186 Slide_Interval(new_w),
187 (XtTimerCallbackProc)_XltSlideProc,
188 new_w);
189 XtAddCallback(Slide_Widget(new_w), XmNdestroyCallback, (XtCallbackProc)targetDestroy, new_w);
192 static void
193 destroy(Widget w)
195 if (Slide_Id(w) != (XtIntervalId)NULL)
197 XtRemoveTimeOut(Slide_Id(w));
198 Slide_Id(w) = (XtIntervalId)NULL;
200 XtRemoveCallback(Slide_Widget(w), XmNdestroyCallback, (XtCallbackProc)targetDestroy, w);
203 static Boolean
204 set_values(Widget old, Widget request, Widget new_w, ArgList args, Cardinal *num_args)
206 if (Slide_Widget(old) != Slide_Widget(new_w))
208 XtRemoveCallback(Slide_Widget(old), XmNdestroyCallback, (XtCallbackProc)targetDestroy, old);
209 XtAddCallback(Slide_Widget(new_w), XmNdestroyCallback, (XtCallbackProc)targetDestroy, new_w);
211 return(False);
214 static void
215 get_values_hook(Widget w, ArgList args, Cardinal *num_args)
219 static void
220 targetDestroy(Widget target, Widget w)
222 XtDestroyWidget(w);
225 static void
226 _XltSlideProc(Widget w)
228 Dimension width, height;
229 Position x, y;
232 printf("%s:%s(%d) - %s %li\n", __FILE__, __FUNCTION__, __LINE__,
233 XtName(w),
234 Slide_Interval(w));
237 width = XtWidth(Slide_Widget(w));
238 height = XtHeight(Slide_Widget(w));
239 x = XtX(Slide_Widget(w));
240 y = XtY(Slide_Widget(w));
242 height = height - (((height - Slide_DestHeight(w)) * 10) / 100);
243 if (height < Slide_DestHeight(w))
245 height++;
247 if (height > Slide_DestHeight(w))
249 height--;
251 width = width - (((width - Slide_DestWidth(w)) * 10) / 100);
252 if (width < Slide_DestWidth(w))
254 width++;
256 if (width > Slide_DestWidth(w))
258 width--;
262 y = y - ((((y - Slide_DestY(w)) * 10) / 100) + 0);
263 if (y < Slide_DestY(w))
265 y++;
267 if (y > Slide_DestY(w))
269 y--;
271 x = x - ((((x - Slide_DestX(w)) * 10) / 100) + 0);
272 if (x < Slide_DestX(w))
274 x++;
276 if (x > Slide_DestX(w))
278 x--;
282 XtCallCallbackList(w, Slide_MotionCallback(w), NULL);
284 XtVaSetValues(Slide_Widget(w),
285 XmNx, x,
286 XmNy, y,
287 XmNwidth, width,
288 XmNheight, height,
289 NULL);
290 if (Slide_DestX(w) == XtX(Slide_Widget(w)) &&
291 Slide_DestY(w) == XtY(Slide_Widget(w)) &&
292 Slide_DestWidth(w) == XtWidth(Slide_Widget(w)) &&
293 Slide_DestHeight(w) == XtHeight(Slide_Widget(w)))
295 XtCallCallbackList(w, Slide_FinishCallback(w), NULL);
296 XtRemoveCallback(Slide_Widget(w), XmNdestroyCallback, (XtCallbackProc)targetDestroy, w);
297 XtDestroyWidget(w);
299 else
301 Slide_Id(w) = XtAppAddTimeOut(XtWidgetToApplicationContext(w),
302 Slide_Interval(w),
303 (XtTimerCallbackProc)_XltSlideProc,