summaryrefslogtreecommitdiff
path: root/src/Repeater.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/Repeater.c')
-rw-r--r--src/Repeater.c375
1 files changed, 199 insertions, 176 deletions
diff --git a/src/Repeater.c b/src/Repeater.c
index a530615..6c89a1e 100644
--- a/src/Repeater.c
+++ b/src/Repeater.c
@@ -27,248 +27,271 @@ in this Software without prior written authorization from The Open Group.
*
* This widget is used for press-and-hold style buttons.
*/
+/* $XFree86: xc/lib/Xaw/Repeater.c,v 1.7 2001/12/14 19:54:41 dawes Exp $ */
#include <X11/IntrinsicP.h>
-#include <X11/StringDefs.h> /* for XtN and XtC defines */
-#include <X11/Xaw/XawInit.h> /* for XawInitializeWidgetSet() */
-#include <X11/Xaw/RepeaterP.h> /* us */
-
-static void tic(); /* clock timeout */
+#include <X11/StringDefs.h>
+#include <X11/Xaw/RepeaterP.h>
+#include <X11/Xaw/XawInit.h>
#define DO_CALLBACK(rw) \
- XtCallCallbackList ((Widget) rw, rw->command.callbacks, (XtPointer)NULL)
-
+XtCallCallbackList((Widget)rw, rw->command.callbacks, NULL)
-#define ADD_TIMEOUT(rw,delay) \
- XtAppAddTimeOut (XtWidgetToApplicationContext ((Widget) rw), \
- (unsigned long) delay, tic, (XtPointer) rw)
+#define ADD_TIMEOUT(rw, delay) \
+XtAppAddTimeOut(XtWidgetToApplicationContext((Widget)rw), \
+ delay, tic, (XtPointer)rw)
#define CLEAR_TIMEOUT(rw) \
- if ((rw)->repeater.timer) { \
- XtRemoveTimeOut ((rw)->repeater.timer); \
- (rw)->repeater.timer = 0; \
- }
+if ((rw)->repeater.timer) { \
+ XtRemoveTimeOut((rw)->repeater.timer); \
+ (rw)->repeater.timer = 0; \
+}
+/*
+ * Class Methods
+ */
+static void XawRepeaterInitialize(Widget, Widget, ArgList, Cardinal*);
+static void XawRepeaterDestroy(Widget);
+static Boolean XawRepeaterSetValues(Widget, Widget, Widget,
+ ArgList, Cardinal*);
/*
- * Translations to give user interface of press-notify...-release_or_leave
+ * Prototypes
*/
-static char defaultTranslations[] =
- "<EnterWindow>: highlight() \n\
- <LeaveWindow>: unhighlight() \n\
- <Btn1Down>: set() start() \n\
- <Btn1Up>: stop() unset() ";
+static void tic(XtPointer, XtIntervalId*);
+/*
+ * Actions
+ */
+static void ActionStart(Widget, XEvent*, String*, Cardinal*);
+static void ActionStop(Widget, XEvent*, String*, Cardinal*);
/*
- * Actions added by this widget
+ * Initialization
*/
-static void ActionStart(), ActionStop();
+static char defaultTranslations[] =
+"<Enter>:" "highlight()\n"
+"<Leave>:" "unhighlight()\n"
+"<Btn1Down>:" "set() start()\n"
+"<Btn1Up>:" "stop() unset()\n"
+;
static XtActionsRec actions[] = {
- { "start", ActionStart }, /* trigger timers */
- { "stop", ActionStop }, /* clear timers */
+ {"start", ActionStart},
+ {"stop", ActionStop},
};
-
-/*
- * New resources added by this widget
- */
+#define offset(field) XtOffsetOf(RepeaterRec, repeater.field)
static XtResource resources[] = {
-#define off(field) XtOffsetOf(RepeaterRec, repeater.field)
- { XtNdecay, XtCDecay, XtRInt, sizeof (int),
- off(decay), XtRImmediate, (XtPointer) REP_DEF_DECAY },
- { XtNinitialDelay, XtCDelay, XtRInt, sizeof (int),
- off(initial_delay), XtRImmediate, (XtPointer) REP_DEF_INITIAL_DELAY },
- { XtNminimumDelay, XtCMinimumDelay, XtRInt, sizeof (int),
- off(minimum_delay), XtRImmediate, (XtPointer) REP_DEF_MINIMUM_DELAY },
- { XtNrepeatDelay, XtCDelay, XtRInt, sizeof (int),
- off(repeat_delay), XtRImmediate, (XtPointer) REP_DEF_REPEAT_DELAY },
- { XtNflash, XtCBoolean, XtRBoolean, sizeof (Boolean),
- off(flash), XtRImmediate, (XtPointer) FALSE },
- { XtNstartCallback, XtCStartCallback, XtRCallback, sizeof (XtPointer),
- off(start_callbacks), XtRImmediate, (XtPointer) NULL },
- { XtNstopCallback, XtCStopCallback, XtRCallback, sizeof (XtPointer),
- off(stop_callbacks), XtRImmediate, (XtPointer) NULL },
-#undef off
+ {
+ XtNdecay,
+ XtCDecay,
+ XtRInt,
+ sizeof(int),
+ offset(decay),
+ XtRImmediate,
+ (XtPointer)REP_DEF_DECAY
+ },
+ {
+ XtNinitialDelay,
+ XtCDelay,
+ XtRInt,
+ sizeof(int),
+ offset(initial_delay),
+ XtRImmediate,
+ (XtPointer)REP_DEF_INITIAL_DELAY
+ },
+ {
+ XtNminimumDelay,
+ XtCMinimumDelay,
+ XtRInt,
+ sizeof(int),
+ offset(minimum_delay),
+ XtRImmediate,
+ (XtPointer)REP_DEF_MINIMUM_DELAY
+ },
+ {
+ XtNrepeatDelay,
+ XtCDelay,
+ XtRInt,
+ sizeof(int),
+ offset(repeat_delay),
+ XtRImmediate,
+ (XtPointer)REP_DEF_REPEAT_DELAY
+ },
+ {
+ XtNflash,
+ XtCBoolean,
+ XtRBoolean,
+ sizeof(Boolean),
+ offset(flash),
+ XtRImmediate,
+ (XtPointer)False
+ },
+ {
+ XtNstartCallback,
+ XtCStartCallback,
+ XtRCallback,
+ sizeof(XtPointer),
+ offset(start_callbacks),
+ XtRImmediate,
+ NULL
+ },
+ {
+ XtNstopCallback,
+ XtCStopCallback,
+ XtRCallback,
+ sizeof(XtPointer),
+ offset(stop_callbacks),
+ XtRImmediate,
+ NULL
+ },
};
+#undef offset
-
-/*
- * Class Methods
- */
-
-static void Initialize(); /* setup private data */
-static void Destroy(); /* clear timers */
-static Boolean SetValues(); /* set resources */
-
+#define Superclass (&commandClassRec)
RepeaterClassRec repeaterClassRec = {
- { /* core fields */
- /* superclass */ (WidgetClass) &commandClassRec,
- /* class_name */ "Repeater",
- /* widget_size */ sizeof(RepeaterRec),
- /* class_initialize */ XawInitializeWidgetSet,
- /* class_part_initialize */ NULL,
- /* class_inited */ FALSE,
- /* initialize */ Initialize,
- /* initialize_hook */ NULL,
- /* realize */ XtInheritRealize,
- /* actions */ actions,
- /* num_actions */ XtNumber(actions),
- /* resources */ resources,
- /* num_resources */ XtNumber(resources),
- /* xrm_class */ NULLQUARK,
- /* compress_motion */ TRUE,
- /* compress_exposure */ TRUE,
- /* compress_enterleave */ TRUE,
- /* visible_interest */ FALSE,
- /* destroy */ Destroy,
- /* resize */ XtInheritResize,
- /* expose */ XtInheritExpose,
- /* set_values */ SetValues,
- /* set_values_hook */ NULL,
- /* set_values_almost */ XtInheritSetValuesAlmost,
- /* get_values_hook */ NULL,
- /* accept_focus */ NULL,
- /* version */ XtVersion,
- /* callback_private */ NULL,
- /* tm_table */ defaultTranslations,
- /* query_geometry */ XtInheritQueryGeometry,
- /* display_accelerator */ XtInheritDisplayAccelerator,
- /* extension */ NULL
+ /* core */
+ {
+ (WidgetClass)Superclass, /* superclass */
+ "Repeater", /* class_name */
+ sizeof(RepeaterRec), /* widget_size */
+ XawInitializeWidgetSet, /* class_initialize */
+ NULL, /* class_part_initialize */
+ False, /* class_inited */
+ XawRepeaterInitialize, /* initialize */
+ NULL, /* initialize_hook */
+ XtInheritRealize, /* realize */
+ actions, /* actions */
+ XtNumber(actions), /* num_actions */
+ resources, /* resources */
+ XtNumber(resources), /* num_resources */
+ NULLQUARK, /* xrm_class */
+ True, /* compress_motion */
+ True, /* compress_exposure */
+ True, /* compress_enterleave */
+ False, /* visible_interest */
+ XawRepeaterDestroy, /* destroy */
+ XtInheritResize, /* resize */
+ XtInheritExpose, /* expose */
+ XawRepeaterSetValues, /* set_values */
+ NULL, /* set_values_hook */
+ XtInheritSetValuesAlmost, /* set_values_almost */
+ NULL, /* get_values_hook */
+ NULL, /* accept_focus */
+ XtVersion, /* version */
+ NULL, /* callback_private */
+ defaultTranslations, /* tm_table */
+ XtInheritQueryGeometry, /* query_geometry */
+ XtInheritDisplayAccelerator, /* display_accelerator */
+ NULL, /* extension */
+ },
+ /* simple */
+ {
+ XtInheritChangeSensitive, /* change_sensitive */
},
- { /* simple fields */
- /* change_sensitive */ XtInheritChangeSensitive
+ /* label */
+ {
+ NULL, /* extension */
},
- { /* label fields */
- /* ignore */ 0
+ /* command */
+ {
+ NULL, /* extension */
},
- { /* command fields */
- /* ignore */ 0
+ /* repeater */
+ {
+ NULL, /* extension */
},
- { /* repeater fields */
- /* ignore */ 0
- }
};
WidgetClass repeaterWidgetClass = (WidgetClass) &repeaterClassRec;
-/*****************************************************************************
- * *
- * repeater utility routines *
- * *
- *****************************************************************************/
-
-/* ARGSUSED */
-static void tic (client_data, id)
- XtPointer client_data;
- XtIntervalId *id;
+/*
+ * Implementation
+ */
+/*ARGSUSED*/
+static void
+tic(XtPointer client_data, XtIntervalId *id)
{
- RepeaterWidget rw = (RepeaterWidget) client_data;
+ RepeaterWidget rw = (RepeaterWidget)client_data;
rw->repeater.timer = 0; /* timer is removed */
if (rw->repeater.flash) {
- XtExposeProc expose;
- expose = repeaterWidgetClass->core_class.superclass->core_class.expose;
- XClearWindow (XtDisplay((Widget) rw), XtWindow((Widget) rw));
- rw->command.set = FALSE;
- (*expose) ((Widget) rw, (XEvent *) NULL, (Region) NULL);
- XClearWindow (XtDisplay((Widget) rw), XtWindow((Widget) rw));
- rw->command.set = TRUE;
- (*expose) ((Widget) rw, (XEvent *) NULL, (Region) NULL);
+ Widget w = (Widget)rw;
+
+ XClearWindow(XtDisplay(w), XtWindow(w));
+ XtCallActionProc(w, "reset", NULL, NULL, 0);
+ XClearWindow(XtDisplay(w), XtWindow(w));
+ XtCallActionProc(w, "set", NULL, NULL, 0);
}
- DO_CALLBACK (rw);
+ DO_CALLBACK(rw);
- rw->repeater.timer = ADD_TIMEOUT (rw, rw->repeater.next_delay);
+ rw->repeater.timer = ADD_TIMEOUT(rw, rw->repeater.next_delay);
- /* decrement delay time, but clamp */
if (rw->repeater.decay) {
rw->repeater.next_delay -= rw->repeater.decay;
if (rw->repeater.next_delay < rw->repeater.minimum_delay)
- rw->repeater.next_delay = rw->repeater.minimum_delay;
+ rw->repeater.next_delay = rw->repeater.minimum_delay;
}
}
-
-/*****************************************************************************
- * *
- * repeater class methods *
- * *
- *****************************************************************************/
-
-/* ARGSUSED */
-static void Initialize (greq, gnew, args, num_args)
- Widget greq, gnew;
- ArgList args;
- Cardinal *num_args;
+/*ARGSUSED*/
+static void
+XawRepeaterInitialize(Widget greq, Widget gnew,
+ ArgList args, Cardinal *num_args)
{
- RepeaterWidget new = (RepeaterWidget) gnew;
+ RepeaterWidget cnew = (RepeaterWidget)gnew;
- if (new->repeater.minimum_delay < 0) new->repeater.minimum_delay = 0;
- new->repeater.timer = (XtIntervalId) 0;
+ if (cnew->repeater.minimum_delay < 0)
+ cnew->repeater.minimum_delay = 0;
+ cnew->repeater.timer = 0;
}
-static void Destroy (gw)
- Widget gw;
+static void
+XawRepeaterDestroy(Widget gw)
{
- CLEAR_TIMEOUT ((RepeaterWidget) gw);
+ CLEAR_TIMEOUT((RepeaterWidget)gw);
}
-/* ARGSUSED */
-static Boolean SetValues (gcur, greq, gnew, args, num_args)
- Widget gcur, greq, gnew;
- ArgList args;
- Cardinal *num_args;
+/*ARGSUSED*/
+static Boolean
+XawRepeaterSetValues(Widget gcur, Widget greq, Widget gnew,
+ ArgList args, Cardinal *num_args)
{
- RepeaterWidget cur = (RepeaterWidget) gcur;
- RepeaterWidget new = (RepeaterWidget) gnew;
- Boolean redisplay = FALSE;
+ RepeaterWidget cur = (RepeaterWidget)gcur;
+ RepeaterWidget cnew = (RepeaterWidget)gnew;
- if (cur->repeater.minimum_delay != new->repeater.minimum_delay) {
- if (new->repeater.next_delay < new->repeater.minimum_delay)
- new->repeater.next_delay = new->repeater.minimum_delay;
+ if (cur->repeater.minimum_delay != cnew->repeater.minimum_delay) {
+ if (cnew->repeater.next_delay < cnew->repeater.minimum_delay)
+ cnew->repeater.next_delay = cnew->repeater.minimum_delay;
}
- return redisplay;
+ return (False);
}
-/*****************************************************************************
- * *
- * repeater action procs *
- * *
- *****************************************************************************/
-
-/* ARGSUSED */
-static void ActionStart (gw, event, params, num_params)
- Widget gw;
- XEvent *event;
- String *params; /* unused */
- Cardinal *num_params; /* unused */
+/*ARGSUSED*/
+static void
+ActionStart(Widget gw, XEvent *event, String *params, Cardinal *num_params)
{
- RepeaterWidget rw = (RepeaterWidget) gw;
+ RepeaterWidget rw = (RepeaterWidget)gw;
- CLEAR_TIMEOUT (rw);
+ CLEAR_TIMEOUT(rw);
if (rw->repeater.start_callbacks)
- XtCallCallbackList (gw, rw->repeater.start_callbacks, (XtPointer)NULL);
+ XtCallCallbackList(gw, rw->repeater.start_callbacks, NULL);
- DO_CALLBACK (rw);
- rw->repeater.timer = ADD_TIMEOUT (rw, rw->repeater.initial_delay);
+ DO_CALLBACK(rw);
+ rw->repeater.timer = ADD_TIMEOUT(rw, rw->repeater.initial_delay);
rw->repeater.next_delay = rw->repeater.repeat_delay;
}
-
-/* ARGSUSED */
-static void ActionStop (gw, event, params, num_params)
- Widget gw;
- XEvent *event;
- String *params; /* unused */
- Cardinal *num_params; /* unused */
+/*ARGSUSED*/
+static void
+ActionStop(Widget gw, XEvent *event, String *params, Cardinal *num_params)
{
- RepeaterWidget rw = (RepeaterWidget) gw;
+ RepeaterWidget rw = (RepeaterWidget)gw;
- CLEAR_TIMEOUT ((RepeaterWidget) gw);
+ CLEAR_TIMEOUT((RepeaterWidget)gw);
if (rw->repeater.stop_callbacks)
- XtCallCallbackList (gw, rw->repeater.stop_callbacks, (XtPointer)NULL);
+ XtCallCallbackList(gw, rw->repeater.stop_callbacks, NULL);
}
-