UNIXworkcode

1 /** 2 * 3 * $Id: SlideC.c,v 1.5 2005/12/01 14:31:43 tringali Exp $ 4 * 5 * Copyright (C) 1996 Free Software Foundation, Inc. 6 * Copyright © 1999-2001 by the LessTif developers. 7 * 8 * This file is part of the GNU LessTif Extension Library. 9 * 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. 14 * 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. 19 * 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. 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 Widget methods, forward declarations 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 Widget default resources 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 Widget class record 106 */ 107 XltSlideContextClassRec xltSlideContextClassRec = { 108 /* Object Class Part */ 109 { 110 /* pointer to superclass ClassRec WidgetClass */ (WidgetClass) &objectClassRec, 111 /* widget resource class name String */ "XltSlideContext", 112 /* size in bytes of widget record Cardinal */ sizeof(XltSlideContextRec), 113 /* class initialization proc XtProc */ class_initialize, 114 /* dynamic initialization XtWidgetClassProc */ class_part_initialize, 115 /* has class been initialized? XtEnum */ False, 116 /* initialize subclass fields XtInitProc */ initialize, 117 /* notify that initialize called XtArgsProc */ NULL, 118 /* NULL XtProc */ NULL, 119 /* NULL XtPointer */ NULL, 120 /* NULL Cardinal */ (Cardinal)(intptr_t)NULL, 121 /* resources for subclass fields XtResourceList */ resources, 122 /* number of entries in resources Cardinal */ XtNumber(resources), 123 /* resource class quarkified XrmClass */ NULLQUARK, 124 /* NULL Boolean */ (Boolean)(intptr_t)NULL, 125 /* NULL XtEnum */ (XtEnum)(intptr_t)NULL, 126 /* NULL Boolean */ (Boolean)(intptr_t)NULL, 127 /* NULL Boolean */ (Boolean)(intptr_t)NULL, 128 /* free data for subclass pointers XtWidgetProc */ destroy, 129 /* NULL XtProc */ NULL, 130 /* NULL XtProc */ NULL, 131 /* set subclass resource values XtSetValuesFunc */ set_values, 132 /* notify that set_values called XtArgsFunc */ NULL, 133 /* NULL XtProc */ NULL, 134 /* notify that get_values called XtArgsProc */ get_values_hook, 135 /* NULL XtProc */ NULL, 136 /* version of intrinsics used XtVersionType */ XtVersion, 137 /* list of callback offsets XtPointer */ NULL, 138 /* NULL String */ NULL, 139 /* NULL XtProc */ NULL, 140 /* NULL XtProc */ NULL, 141 /* pointer to extension record XtPointer */ NULL 142 }, 143 /* SlideContext Class Part */ 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 printf("%s:%s(%d) - %s %li\n", __FILE__, __FUNCTION__, __LINE__, 166 XtName(new_w), 167 Slide_Interval(new_w)); 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 printf("%s:%s(%d) - %s %li\n", __FILE__, __FUNCTION__, __LINE__, 234 XtName(w), 235 Slide_Interval(w)); 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 XtCallCallbackList(w, Slide_MotionCallback(w), NULL); 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