Patch from ICS to do proper subclassing - this will make it more immune to
[nedit.git] / Xlt / SlideC.c
blobb35af70841ccab951b92160f31086359730eff27
1 /**
3 * $Id: SlideC.c,v 1.4 2005/11/30 17:48:04 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) XmPartOffset(XltSlideContext, 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
107 XmOffsetPtr XltSlideContext_offsets;
109 XltSlideContextClassRec xltSlideContextClassRec = {
110 /* Object Class Part */
112 /* pointer to superclass ClassRec WidgetClass */ (WidgetClass) &objectClassRec,
113 /* widget resource class name String */ "XltSlideContext",
114 /* size in bytes of widget record Cardinal */ sizeof(XltSlideContextRec),
115 /* class initialization proc XtProc */ class_initialize,
116 /* dynamic initialization XtWidgetClassProc */ class_part_initialize,
117 /* has class been initialized? XtEnum */ False,
118 /* initialize subclass fields XtInitProc */ initialize,
119 /* notify that initialize called XtArgsProc */ NULL,
120 /* NULL XtProc */ NULL,
121 /* NULL XtPointer */ NULL,
122 /* NULL Cardinal */ (Cardinal)NULL,
123 /* resources for subclass fields XtResourceList */ resources,
124 /* number of entries in resources Cardinal */ XtNumber(resources),
125 /* resource class quarkified XrmClass */ NULLQUARK,
126 /* NULL Boolean */ (Boolean)NULL,
127 /* NULL XtEnum */ (XtEnum)NULL,
128 /* NULL Boolean */ (Boolean)NULL,
129 /* NULL Boolean */ (Boolean)NULL,
130 /* free data for subclass pointers XtWidgetProc */ destroy,
131 /* NULL XtProc */ NULL,
132 /* NULL XtProc */ NULL,
133 /* set subclass resource values XtSetValuesFunc */ set_values,
134 /* notify that set_values called XtArgsFunc */ NULL,
135 /* NULL XtProc */ NULL,
136 /* notify that get_values called XtArgsProc */ get_values_hook,
137 /* NULL XtProc */ NULL,
138 /* version of intrinsics used XtVersionType */ XtVersion,
139 /* list of callback offsets XtPointer */ NULL,
140 /* NULL String */ NULL,
141 /* NULL XtProc */ NULL,
142 /* NULL XtProc */ NULL,
143 /* pointer to extension record XtPointer */ NULL
145 /* SlideContext Class Part */
147 NULL
151 WidgetClass xltSlideContextWidgetClass = (WidgetClass)&xltSlideContextClassRec;
153 static void
154 class_initialize(void)
156 XmeResolvePartOffsets(xltSlideContextWidgetClass,
157 &XltSlideContext_offsets,
158 NULL);
161 static void
162 class_part_initialize(WidgetClass widget_class)
166 static void
167 initialize(Widget request, Widget new_w, ArgList args, Cardinal *num_args)
170 printf("%s:%s(%d) - %s %li\n", __FILE__, __FUNCTION__, __LINE__,
171 XtName(new_w),
172 Slide_Interval(new_w));
175 if (Slide_DestWidth(new_w) == (Dimension)XmUNSPECIFIED)
177 Slide_DestWidth(new_w) = XtWidth(Slide_Widget(new_w));
179 if (Slide_DestHeight(new_w) == (Dimension)XmUNSPECIFIED)
181 Slide_DestHeight(new_w) = XtHeight(Slide_Widget(new_w));
183 if (Slide_DestX(new_w) == XmUNSPECIFIED_POSITION)
185 Slide_DestX(new_w) = XtX(Slide_Widget(new_w));
187 if (Slide_DestY(new_w) == XmUNSPECIFIED_POSITION)
189 Slide_DestY(new_w) = XtY(Slide_Widget(new_w));
191 Slide_Id(new_w) = XtAppAddTimeOut(XtWidgetToApplicationContext(new_w),
192 Slide_Interval(new_w),
193 (XtTimerCallbackProc)_XltSlideProc,
194 new_w);
195 XtAddCallback(Slide_Widget(new_w), XmNdestroyCallback, (XtCallbackProc)targetDestroy, new_w);
198 static void
199 destroy(Widget w)
201 if (Slide_Id(w) != (XtIntervalId)NULL)
203 XtRemoveTimeOut(Slide_Id(w));
204 Slide_Id(w) = (XtIntervalId)NULL;
206 XtRemoveCallback(Slide_Widget(w), XmNdestroyCallback, (XtCallbackProc)targetDestroy, w);
209 static Boolean
210 set_values(Widget old, Widget request, Widget new_w, ArgList args, Cardinal *num_args)
212 if (Slide_Widget(old) != Slide_Widget(new_w))
214 XtRemoveCallback(Slide_Widget(old), XmNdestroyCallback, (XtCallbackProc)targetDestroy, old);
215 XtAddCallback(Slide_Widget(new_w), XmNdestroyCallback, (XtCallbackProc)targetDestroy, new_w);
217 return(False);
220 static void
221 get_values_hook(Widget w, ArgList args, Cardinal *num_args)
225 static void
226 targetDestroy(Widget target, Widget w)
228 XtDestroyWidget(w);
231 static void
232 _XltSlideProc(Widget w)
234 Dimension width, height;
235 Position x, y;
238 printf("%s:%s(%d) - %s %li\n", __FILE__, __FUNCTION__, __LINE__,
239 XtName(w),
240 Slide_Interval(w));
243 width = XtWidth(Slide_Widget(w));
244 height = XtHeight(Slide_Widget(w));
245 x = XtX(Slide_Widget(w));
246 y = XtY(Slide_Widget(w));
248 height = height - (((height - Slide_DestHeight(w)) * 10) / 100);
249 if (height < Slide_DestHeight(w))
251 height++;
253 if (height > Slide_DestHeight(w))
255 height--;
257 width = width - (((width - Slide_DestWidth(w)) * 10) / 100);
258 if (width < Slide_DestWidth(w))
260 width++;
262 if (width > Slide_DestWidth(w))
264 width--;
268 y = y - ((((y - Slide_DestY(w)) * 10) / 100) + 0);
269 if (y < Slide_DestY(w))
271 y++;
273 if (y > Slide_DestY(w))
275 y--;
277 x = x - ((((x - Slide_DestX(w)) * 10) / 100) + 0);
278 if (x < Slide_DestX(w))
280 x++;
282 if (x > Slide_DestX(w))
284 x--;
288 XtCallCallbackList(w, Slide_MotionCallback(w), NULL);
290 XtVaSetValues(Slide_Widget(w),
291 XmNx, x,
292 XmNy, y,
293 XmNwidth, width,
294 XmNheight, height,
295 NULL);
296 if (Slide_DestX(w) == XtX(Slide_Widget(w)) &&
297 Slide_DestY(w) == XtY(Slide_Widget(w)) &&
298 Slide_DestWidth(w) == XtWidth(Slide_Widget(w)) &&
299 Slide_DestHeight(w) == XtHeight(Slide_Widget(w)))
301 XtCallCallbackList(w, Slide_FinishCallback(w), NULL);
302 XtRemoveCallback(Slide_Widget(w), XmNdestroyCallback, (XtCallbackProc)targetDestroy, w);
303 XtDestroyWidget(w);
305 else
307 Slide_Id(w) = XtAppAddTimeOut(XtWidgetToApplicationContext(w),
308 Slide_Interval(w),
309 (XtTimerCallbackProc)_XltSlideProc,