File: SlideC.c

package info (click to toggle)
motif 2.3.8-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 36,432 kB
  • sloc: ansic: 452,643; sh: 4,613; makefile: 2,030; yacc: 1,604; lex: 352; cpp: 348
file content (323 lines) | stat: -rw-r--r-- 9,347 bytes parent folder | download | duplicates (4)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
/*
 * Motif
 *
 * Copyright (c) 1987-2012, The Open Group. All rights reserved.
 *
 * These libraries and programs are free software; you can
 * redistribute them and/or modify them under the terms of the GNU
 * Lesser General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option)
 * any later version.
 *
 * These libraries and programs are distributed in the hope that
 * they will be useful, but WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE. See the GNU Lesser General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with these librararies and programs; if not, write
 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
 * Floor, Boston, MA 02110-1301 USA
*/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "XmI.h"
#include "SlideCP.h"
#include <Xm/XmP.h>

/*
   Widget methods, forward declarations
 */

static void class_initialize(void);
static void class_part_initialize(WidgetClass widget_class);
static void initialize(Widget request, Widget new_w, ArgList args, Cardinal *num_args);
static void destroy(Widget w);
static Boolean set_values(Widget old, Widget request, Widget new_w, ArgList args, Cardinal *num_args);
static void get_values_hook(Widget w, ArgList args, Cardinal *num_args);

static void _XmSlideProc(Widget w);
static void targetDestroy(Widget target, XtPointer client_data, XtPointer call_data);

/*
   Widget default resources
 */

#define Offset(field) XtOffsetOf(XmSlideContextRec, slide.field)
static XtResource resources[] =
{
    {
	XmNslideFinishCallback, XtCCallback, XtRCallback,
	sizeof(XtCallbackList), Offset(slideFinishCallback),
	XtRCallback, NULL
    },
    {
	XmNslideMotionCallback, XtCCallback, XtRCallback,
	sizeof(XtCallbackList), Offset(slideMotionCallback),
	XtRCallback, NULL
    },
    {
	XmNslideWidget, XmCSlideWidget, XtRWidget,
	sizeof(Widget), Offset(slide_widget),
	XtRImmediate, NULL
    },
    {
	XmNslideInterval, XmCSlideInterval, XtRInt,
	sizeof(int), Offset(interval),
	XtRImmediate, (XtPointer)5
    },
    {
	XmNslideDestWidth, XmCSlideDestWidth, XtRDimension,
	sizeof(Dimension), Offset(dest_width),
	XtRImmediate, (XtPointer)XmUNSPECIFIED
    },
    {
	XmNslideDestHeight, XmCSlideDestHeight, XtRDimension,
	sizeof(Dimension), Offset(dest_height),
	XtRImmediate, (XtPointer)XmUNSPECIFIED
    },
    {
	XmNslideDestX, XmCSlideDestX, XtRPosition,
	sizeof(Position), Offset(dest_x),
	XtRImmediate, (XtPointer)XmUNSPECIFIED_POSITION
    },
    {
	XmNslideDestY, XmCSlideDestY, XtRPosition,
	sizeof(Position), Offset(dest_y),
	XtRImmediate, (XtPointer)XmUNSPECIFIED_POSITION
    },
};
#undef Offset

/*
   Widget class record
 */
/* *INDENT-OFF* */
XmSlideContextClassRec xmSlideContextClassRec = {
	/* Object Class Part */
	{
/* pointer to superclass ClassRec   WidgetClass       */ (WidgetClass) &objectClassRec,
/* widget resource class name       String            */ "XmSlideContext",
/* size in bytes of widget record   Cardinal          */ sizeof(XmSlideContextRec),
/* class initialization proc        XtProc            */ class_initialize,
/* dynamic initialization           XtWidgetClassProc */ class_part_initialize,
/* has class been initialized?      XtEnum            */ False,
/* initialize subclass fields       XtInitProc        */ initialize,
/* notify that initialize called    XtArgsProc        */ NULL,
/* NULL                             XtProc            */ NULL,
/* NULL                             XtPointer         */ NULL,
/* NULL                             Cardinal          */ (Cardinal)NULL,
/* resources for subclass fields    XtResourceList    */ resources,
/* number of entries in resources   Cardinal          */ XtNumber(resources),
/* resource class quarkified        XrmClass          */ NULLQUARK,
/* NULL                             Boolean           */ (Boolean)(unsigned)NULL,
/* NULL                             XtEnum            */ (XtEnum)(unsigned)NULL,
/* NULL				    Boolean           */ (Boolean)(unsigned)NULL,
/* NULL                             Boolean           */ (Boolean)(unsigned)NULL,
/* free data for subclass pointers  XtWidgetProc      */ destroy,
/* NULL                             XtProc            */ NULL,
/* NULL			            XtProc            */ NULL,
/* set subclass resource values     XtSetValuesFunc   */ set_values,
/* notify that set_values called    XtArgsFunc        */ NULL,
/* NULL                             XtProc            */ NULL,
/* notify that get_values called    XtArgsProc        */ get_values_hook,
/* NULL                             XtProc            */ NULL,
/* version of intrinsics used       XtVersionType     */ XtVersion,
/* list of callback offsets         XtPointer         */ NULL,
/* NULL                             String            */ NULL,
/* NULL                             XtProc            */ NULL,
/* NULL                             XtProc            */ NULL,
/* pointer to extension record      XtPointer         */ NULL
	},
	/* SlideContext Class Part */
	{
		NULL
	}
};
/* *INDENT-ON* */

WidgetClass xmSlideContextWidgetClass = (WidgetClass)&xmSlideContextClassRec;

static void 
class_initialize(void)
{
}

static void 
class_part_initialize(WidgetClass widget_class)
{
}

static void 
initialize(Widget request, Widget new_w, ArgList args, Cardinal *num_args)
{
    /*
    printf("%s:%s(%d) - %s %li\n", __FILE__, __FUNCTION__, __LINE__,
    	XtName(new_w),
    	Slide_Interval(new_w));
    	*/

    if (Slide_Widget(new_w) == NULL)
    {
	_XmWarningMsg(new_w, 
	    "Invalid parameter",
	    XmNslideWidget " must be specified during creation",
	    NULL, 0);
    }
    else
    {
	if (Slide_DestWidth(new_w) == (Dimension)XmUNSPECIFIED)
	{
	    Slide_DestWidth(new_w) = XtWidth(Slide_Widget(new_w));
	}
	if (Slide_DestHeight(new_w) == (Dimension)XmUNSPECIFIED)
	{
	    Slide_DestHeight(new_w) = XtHeight(Slide_Widget(new_w));
	}
	if (Slide_DestX(new_w) == XmUNSPECIFIED_POSITION)
	{
	    Slide_DestX(new_w) = XtX(Slide_Widget(new_w));
	}
	if (Slide_DestY(new_w) == XmUNSPECIFIED_POSITION)
	{
	    Slide_DestY(new_w) = XtY(Slide_Widget(new_w));
	}
	Slide_Id(new_w) = XtAppAddTimeOut(XtWidgetToApplicationContext(new_w),
		Slide_Interval(new_w),
		(XtTimerCallbackProc)_XmSlideProc,
		new_w);
	XtAddCallback(Slide_Widget(new_w), XmNdestroyCallback, (XtCallbackProc)targetDestroy, new_w);
    }
}

static void 
destroy(Widget w)
{
    if (Slide_Id(w) != (XtIntervalId)NULL)
    {
    	XtRemoveTimeOut(Slide_Id(w));
	Slide_Id(w) = (XtIntervalId)NULL;
    }
    XtRemoveCallback(Slide_Widget(w), XmNdestroyCallback, (XtCallbackProc)targetDestroy, w);
}

static Boolean 
set_values(Widget old, Widget request, Widget new_w, ArgList args, Cardinal *num_args)
{
    if (Slide_Widget(old) != Slide_Widget(new_w))
    {
	XtRemoveCallback(Slide_Widget(old), XmNdestroyCallback, (XtCallbackProc)targetDestroy, old);
	XtAddCallback(Slide_Widget(new_w), XmNdestroyCallback, (XtCallbackProc)targetDestroy, new_w);
    }
    return(False);
}

static void 
get_values_hook(Widget w, ArgList args, Cardinal *num_args)
{
}

static void
targetDestroy(Widget target, XtPointer client_data, XtPointer call_data)
{
Widget w = (Widget)client_data;

    XtDestroyWidget(w);
}

static void
_XmSlideProc(Widget w)
{
Dimension width, height;
Position x, y;

    /*
    printf("%s:%s(%d) - %s %li\n", __FILE__, __FUNCTION__, __LINE__,
    	XtName(w),
    	Slide_Interval(w));
    	*/

    if (Slide_Interval(w) == 0)
    {
	width = Slide_DestWidth(w);
	height = Slide_DestHeight(w);
	x = Slide_DestX(w);
	y = Slide_DestY(w);
    }
    else
    {
	width = XtWidth(Slide_Widget(w));
	height = XtHeight(Slide_Widget(w));
	x = XtX(Slide_Widget(w));
	y = XtY(Slide_Widget(w));
	{
	    height = height - (((height - Slide_DestHeight(w)) * 10) / 100);
	    if (height < Slide_DestHeight(w))
	    {
		height++;
	    }
	    if (height > Slide_DestHeight(w))
	    {
		height--;
	    }
	    width = width - (((width - Slide_DestWidth(w)) * 10) / 100);
	    if (width < Slide_DestWidth(w))
	    {
		width++;
	    }
	    if (width > Slide_DestWidth(w))
	    {
		width--;
	    }
	}
	{
	    y = y - ((((y - Slide_DestY(w)) * 10) / 100) + 0);
	    if (y < Slide_DestY(w))
	    {
		y++;
	    }
	    if (y > Slide_DestY(w))
	    {
		y--;
	    }
	    x = x - ((((x - Slide_DestX(w)) * 10) / 100) + 0);
	    if (x < Slide_DestX(w))
	    {
		x++;
	    }
	    if (x > Slide_DestX(w))
	    {
		x--;
	    }
	}
    }
    /*
    XtCallCallbackList(w, Slide_MotionCallback(w), NULL);
    */
    XtVaSetValues(Slide_Widget(w),
    	XmNx, x,
    	XmNy, y,
    	XmNwidth, width,
    	XmNheight, height,
    	NULL);
    if (Slide_DestX(w) == XtX(Slide_Widget(w)) &&
        Slide_DestY(w) == XtY(Slide_Widget(w)) &&
        Slide_DestWidth(w) == XtWidth(Slide_Widget(w)) &&
        Slide_DestHeight(w) == XtHeight(Slide_Widget(w)))
    {
    	XtCallCallbackList(w, Slide_FinishCallback(w), NULL);
	XtRemoveCallback(Slide_Widget(w), XmNdestroyCallback, (XtCallbackProc)targetDestroy, w);
    	XtDestroyWidget(w);
    }
    else
    {
    	Slide_Id(w) = XtAppAddTimeOut(XtWidgetToApplicationContext(w),
    		Slide_Interval(w),
    		(XtTimerCallbackProc)_XmSlideProc,
    		w);
    }
}