Repeater.c

Go to the documentation of this file.
00001 /*
00002  * $XConsortium: Repeater.c,v 1.11 94/04/17 20:12:37 kaleb Exp $
00003  *
00004 Copyright (c) 1990, 1994  X Consortium
00005 
00006 Permission is hereby granted, free of charge, to any person obtaining a copy
00007 of this software and associated documentation files (the "Software"), to deal
00008 in the Software without restriction, including without limitation the rights
00009 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00010 copies of the Software, and to permit persons to whom the Software is
00011 furnished to do so, subject to the following conditions:
00012 
00013 The above copyright notice and this permission notice shall be included in
00014 all copies or substantial portions of the Software.
00015 
00016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
00019 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00020 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00021 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00022 
00023 Except as contained in this notice, the name of the X Consortium shall not be
00024 used in advertising or otherwise to promote the sale, use or other dealings
00025 in this Software without prior written authorization from the X Consortium.
00026  *
00027  * Author:  Jim Fulton, MIT X Consortium
00028  * 
00029  * This widget is used for press-and-hold style buttons.
00030  */
00031 
00032 #include <X11/IntrinsicP.h>
00033 #include <X11/StringDefs.h>             /* for XtN and XtC defines */
00034 #include <X11/Xaw3d/XawInit.h>          /* for XawInitializeWidgetSet() */
00035 #include <X11/Xaw3d/RepeaterP.h>                /* us */
00036 
00037 static void tic();                      /* clock timeout */
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  * Translations to give user interface of press-notify...-release_or_leave
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  * Actions added by this widget
00066  */
00067 static void ActionStart(), ActionStop();
00068 
00069 static XtActionsRec actions[] = {
00070     { "start", ActionStart },           /* trigger timers */
00071     { "stop", ActionStop },             /* clear timers */
00072 };
00073 
00074 
00075 /*
00076  * New resources added by this widget
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  * Class Methods
00100  */
00101 
00102 static void Initialize();               /* setup private data */
00103 static void Destroy();                  /* clear timers */
00104 static Boolean SetValues();             /* set resources */
00105 
00106 RepeaterClassRec repeaterClassRec = {
00107   { /* core fields */
00108     /* superclass               */      (WidgetClass) &commandClassRec,
00109     /* class_name               */      "Repeater",
00110     /* widget_size              */      sizeof(RepeaterRec),
00111     /* class_initialize         */      XawInitializeWidgetSet,
00112     /* class_part_initialize    */      NULL,
00113     /* class_inited             */      FALSE,
00114     /* initialize               */      Initialize,
00115     /* initialize_hook          */      NULL,
00116     /* realize                  */      XtInheritRealize,
00117     /* actions                  */      actions,
00118     /* num_actions              */      XtNumber(actions),
00119     /* resources                */      resources,
00120     /* num_resources            */      XtNumber(resources),
00121     /* xrm_class                */      NULLQUARK,
00122     /* compress_motion          */      TRUE,
00123     /* compress_exposure        */      TRUE,
00124     /* compress_enterleave      */      TRUE,
00125     /* visible_interest         */      FALSE,
00126     /* destroy                  */      Destroy,
00127     /* resize                   */      XtInheritResize,
00128     /* expose                   */      XtInheritExpose,
00129     /* set_values               */      SetValues,
00130     /* set_values_hook          */      NULL,
00131     /* set_values_almost        */      XtInheritSetValuesAlmost,
00132     /* get_values_hook          */      NULL,
00133     /* accept_focus             */      NULL,
00134     /* version                  */      XtVersion,
00135     /* callback_private         */      NULL,
00136     /* tm_table                 */      defaultTranslations,
00137     /* query_geometry           */      XtInheritQueryGeometry,
00138     /* display_accelerator      */      XtInheritDisplayAccelerator,
00139     /* extension                */      NULL
00140   },
00141   { /* simple fields */
00142     /* change_sensitive         */      XtInheritChangeSensitive
00143   },
00144   { /* threeD fields */
00145     /* shadowdraw               */      XtInheritXaw3dShadowDraw
00146   },
00147   { /* label fields */
00148     /* ignore                   */      0
00149   },
00150   { /* command fields */
00151     /* ignore                   */      0
00152   },
00153   { /* repeater fields */
00154     /* ignore                   */      0
00155   }
00156 };
00157 
00158 WidgetClass repeaterWidgetClass = (WidgetClass) &repeaterClassRec;
00159 
00160 
00161 /*****************************************************************************
00162  *                                                                           *
00163  *                         repeater utility routines                         *
00164  *                                                                           *
00165  *****************************************************************************/
00166 
00167 /* ARGSUSED */
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;             /* timer is removed */
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                                         /* decrement delay time, but clamp */
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  *                          repeater class methods                           *
00201  *                                                                           *
00202  *****************************************************************************/
00203 
00204 /* ARGSUSED */
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 /* ARGSUSED */
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  *                           repeater action procs                           *
00243  *                                                                           *
00244  *****************************************************************************/
00245 
00246 /* ARGSUSED */
00247 static void ActionStart (gw, event, params, num_params)
00248     Widget gw;
00249     XEvent *event;
00250     String *params;                     /* unused */
00251     Cardinal *num_params;               /* unused */
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 /* ARGSUSED */
00266 static void ActionStop (gw, event, params, num_params)
00267     Widget gw;
00268     XEvent *event;
00269     String *params;                     /* unused */
00270     Cardinal *num_params;               /* unused */
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 

Generated on Sun Mar 4 15:03:55 2007 for Scilab [trunk] by  doxygen 1.5.1