00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <X11/IntrinsicP.h>
00033 #include <X11/StringDefs.h>
00034 #include <X11/Xaw3d/XawInit.h>
00035 #include <X11/Xaw3d/RepeaterP.h>
00036
00037 static void tic();
00038
00039 #define DO_CALLBACK(rw) \
00040 XtCallCallbackList ((Widget) rw, rw->command.callbacks, (XtPointer)NULL)
00041
00042
00043 #define ADD_TIMEOUT(rw,delay) \
00044 XtAppAddTimeOut (XtWidgetToApplicationContext ((Widget) rw), \
00045 (unsigned long) delay, tic, (XtPointer) rw)
00046
00047 #define CLEAR_TIMEOUT(rw) \
00048 if ((rw)->repeater.timer) { \
00049 XtRemoveTimeOut ((rw)->repeater.timer); \
00050 (rw)->repeater.timer = 0; \
00051 }
00052
00053
00054
00055
00056
00057 static char defaultTranslations[] =
00058 "<EnterWindow>: highlight() \n\
00059 <LeaveWindow>: unhighlight() \n\
00060 <Btn1Down>: set() start() \n\
00061 <Btn1Up>: stop() unset() ";
00062
00063
00064
00065
00066
00067 static void ActionStart(), ActionStop();
00068
00069 static XtActionsRec actions[] = {
00070 { "start", ActionStart },
00071 { "stop", ActionStop },
00072 };
00073
00074
00075
00076
00077
00078 static XtResource resources[] = {
00079 #define off(field) XtOffsetOf(RepeaterRec, repeater.field)
00080 { XtNdecay, XtCDecay, XtRInt, sizeof (int),
00081 off(decay), XtRImmediate, (XtPointer) REP_DEF_DECAY },
00082 { XtNinitialDelay, XtCDelay, XtRInt, sizeof (int),
00083 off(initial_delay), XtRImmediate, (XtPointer) REP_DEF_INITIAL_DELAY },
00084 { XtNminimumDelay, XtCMinimumDelay, XtRInt, sizeof (int),
00085 off(minimum_delay), XtRImmediate, (XtPointer) REP_DEF_MINIMUM_DELAY },
00086 { XtNrepeatDelay, XtCDelay, XtRInt, sizeof (int),
00087 off(repeat_delay), XtRImmediate, (XtPointer) REP_DEF_REPEAT_DELAY },
00088 { XtNflash, XtCBoolean, XtRBoolean, sizeof (Boolean),
00089 off(flash), XtRImmediate, (XtPointer) FALSE },
00090 { XtNstartCallback, XtCStartCallback, XtRCallback, sizeof (XtPointer),
00091 off(start_callbacks), XtRImmediate, (XtPointer) NULL },
00092 { XtNstopCallback, XtCStopCallback, XtRCallback, sizeof (XtPointer),
00093 off(stop_callbacks), XtRImmediate, (XtPointer) NULL },
00094 #undef off
00095 };
00096
00097
00098
00099
00100
00101
00102 static void Initialize();
00103 static void Destroy();
00104 static Boolean SetValues();
00105
00106 RepeaterClassRec repeaterClassRec = {
00107 {
00108 (WidgetClass) &commandClassRec,
00109 "Repeater",
00110 sizeof(RepeaterRec),
00111 XawInitializeWidgetSet,
00112 NULL,
00113 FALSE,
00114 Initialize,
00115 NULL,
00116 XtInheritRealize,
00117 actions,
00118 XtNumber(actions),
00119 resources,
00120 XtNumber(resources),
00121 NULLQUARK,
00122 TRUE,
00123 TRUE,
00124 TRUE,
00125 FALSE,
00126 Destroy,
00127 XtInheritResize,
00128 XtInheritExpose,
00129 SetValues,
00130 NULL,
00131 XtInheritSetValuesAlmost,
00132 NULL,
00133 NULL,
00134 XtVersion,
00135 NULL,
00136 defaultTranslations,
00137 XtInheritQueryGeometry,
00138 XtInheritDisplayAccelerator,
00139 NULL
00140 },
00141 {
00142 XtInheritChangeSensitive
00143 },
00144 {
00145 XtInheritXaw3dShadowDraw
00146 },
00147 {
00148 0
00149 },
00150 {
00151 0
00152 },
00153 {
00154 0
00155 }
00156 };
00157
00158 WidgetClass repeaterWidgetClass = (WidgetClass) &repeaterClassRec;
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168 static void tic (client_data, id)
00169 XtPointer client_data;
00170 XtIntervalId *id;
00171 {
00172 RepeaterWidget rw = (RepeaterWidget) client_data;
00173
00174 rw->repeater.timer = 0;
00175 if (rw->repeater.flash) {
00176 XtExposeProc expose;
00177 expose = repeaterWidgetClass->core_class.superclass->core_class.expose;
00178 XClearWindow (XtDisplay((Widget) rw), XtWindow((Widget) rw));
00179 rw->command.set = FALSE;
00180 (*expose) ((Widget) rw, (XEvent *) NULL, (Region) NULL);
00181 XClearWindow (XtDisplay((Widget) rw), XtWindow((Widget) rw));
00182 rw->command.set = TRUE;
00183 (*expose) ((Widget) rw, (XEvent *) NULL, (Region) NULL);
00184 }
00185 DO_CALLBACK (rw);
00186
00187 rw->repeater.timer = ADD_TIMEOUT (rw, rw->repeater.next_delay);
00188
00189
00190 if (rw->repeater.decay) {
00191 rw->repeater.next_delay -= rw->repeater.decay;
00192 if (rw->repeater.next_delay < rw->repeater.minimum_delay)
00193 rw->repeater.next_delay = rw->repeater.minimum_delay;
00194 }
00195 }
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205 static void Initialize (greq, gnew, args, num_args)
00206 Widget greq, gnew;
00207 ArgList args;
00208 Cardinal *num_args;
00209 {
00210 RepeaterWidget new = (RepeaterWidget) gnew;
00211
00212 if (new->repeater.minimum_delay < 0) new->repeater.minimum_delay = 0;
00213 new->repeater.timer = (XtIntervalId) 0;
00214 }
00215
00216 static void Destroy (gw)
00217 Widget gw;
00218 {
00219 CLEAR_TIMEOUT ((RepeaterWidget) gw);
00220 }
00221
00222
00223 static Boolean SetValues (gcur, greq, gnew, args, num_args)
00224 Widget gcur, greq, gnew;
00225 ArgList args;
00226 Cardinal *num_args;
00227 {
00228 RepeaterWidget cur = (RepeaterWidget) gcur;
00229 RepeaterWidget new = (RepeaterWidget) gnew;
00230 Boolean redisplay = FALSE;
00231
00232 if (cur->repeater.minimum_delay != new->repeater.minimum_delay) {
00233 if (new->repeater.next_delay < new->repeater.minimum_delay)
00234 new->repeater.next_delay = new->repeater.minimum_delay;
00235 }
00236
00237 return redisplay;
00238 }
00239
00240
00241
00242
00243
00244
00245
00246
00247 static void ActionStart (gw, event, params, num_params)
00248 Widget gw;
00249 XEvent *event;
00250 String *params;
00251 Cardinal *num_params;
00252 {
00253 RepeaterWidget rw = (RepeaterWidget) gw;
00254
00255 CLEAR_TIMEOUT (rw);
00256 if (rw->repeater.start_callbacks)
00257 XtCallCallbackList (gw, rw->repeater.start_callbacks, (XtPointer)NULL);
00258
00259 DO_CALLBACK (rw);
00260 rw->repeater.timer = ADD_TIMEOUT (rw, rw->repeater.initial_delay);
00261 rw->repeater.next_delay = rw->repeater.repeat_delay;
00262 }
00263
00264
00265
00266 static void ActionStop (gw, event, params, num_params)
00267 Widget gw;
00268 XEvent *event;
00269 String *params;
00270 Cardinal *num_params;
00271 {
00272 RepeaterWidget rw = (RepeaterWidget) gw;
00273
00274 CLEAR_TIMEOUT ((RepeaterWidget) gw);
00275 if (rw->repeater.stop_callbacks)
00276 XtCallCallbackList (gw, rw->repeater.stop_callbacks, (XtPointer)NULL);
00277 }
00278