1 /* action.c
2 *
3 * $Id$
4 *
5 * Copyright 1990, 1991, 1992, 1993, 1994, 1995, Oliver Laumann, Berlin
6 * Copyright 2002, 2003 Sam Hocevar <sam@hocevar.net>, Paris
7 *
8 * This software was derived from Elk 1.2, which was Copyright 1987, 1988,
9 * 1989, Nixdorf Computer AG and TELES GmbH, Berlin (Elk 1.2 has been written
10 * by Oliver Laumann for TELES Telematic Services, Berlin, in a joint project
11 * between TELES and Nixdorf Microprocessor Engineering, Berlin).
12 *
13 * Oliver Laumann, TELES GmbH, Nixdorf Computer AG and Sam Hocevar, as co-
14 * owners or individual owners of copyright in this software, grant to any
15 * person or company a worldwide, royalty free, license to
16 *
17 * i) copy this software,
18 * ii) prepare derivative works based on this software,
19 * iii) distribute copies of this software or derivative works,
20 * iv) perform this software, or
21 * v) display this software,
22 *
23 * provided that this notice is not removed and that neither Oliver Laumann
24 * nor Teles nor Nixdorf are deemed to have made any representations as to
25 * the suitability of this software for any purpose nor are held responsible
26 * for any defects of this software.
27 *
28 * THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
29 */
30
31 #include "xt.h"
32
33 typedef struct action {
34 char *name;
35 int num;
36 XtAppContext con;
37 struct action *next;
38 } ACTION;
39
40 ACTION *actions;
41
42 /*ARGSUSED*/
Dummy_Action(Widget w,XEvent * ep,String * argv,int * argc)43 static void Dummy_Action (Widget w, XEvent *ep, String *argv, int *argc) {
44 }
45
Action_Hook(Widget w,XtPointer client_data,char * name,XEvent * ep,char ** argv,int * argc)46 void Action_Hook (Widget w, XtPointer client_data, char *name, XEvent *ep,
47 char **argv, int *argc) {
48 ACTION *ap;
49 Object args, params, tail;
50 register int i;
51 GC_Node3;
52
53 for (ap = actions; ap; ap = ap->next) {
54 if (strcmp (ap->name, name))
55 continue;
56 args = params = tail = Null;
57 GC_Link3 (args, params, tail);
58 params = P_Make_List (Make_Integer (*argc), Null);
59 for (i = 0, tail = params; i < *argc; tail = Cdr (tail), i++) {
60 Object tmp;
61
62 tmp = Make_String (argv[i], strlen (argv[i]));
63 Car (tail) = tmp;
64 }
65 args = Cons (params, Null);
66 params = Get_Event_Args (ep);
67 args = Cons (Copy_List (params), args);
68 Destroy_Event_Args (params);
69 args = Cons (Make_Widget_Foreign (w), args);
70 (void)Funcall (Get_Function (ap->num), args, 0);
71 GC_Unlink;
72 }
73 }
74
P_Context_Add_Action(Object c,Object s,Object p)75 static Object P_Context_Add_Action (Object c, Object s, Object p) {
76 ACTION *ap;
77 XtActionsRec a;
78
79 Check_Context (c);
80 Check_Procedure (p);
81 ap = (ACTION *)XtMalloc (sizeof (ACTION));
82 ap->num = Register_Function (p);
83 ap->name = XtNewString (Get_Strsym (s));
84 ap->con = CONTEXT(c)->context;
85 ap->next = actions;
86 actions = ap;
87 a.string = ap->name;
88 a.proc = (XtActionProc)Dummy_Action;
89 XtAppAddActions (ap->con, &a, 1);
90 return Void;
91 }
92
Free_Actions(XtAppContext con)93 void Free_Actions (XtAppContext con) {
94 register ACTION *p, **pp;
95
96 for (pp = &actions; (p = *pp); ) {
97 if (p->con == con) {
98 Deregister_Function (p->num);
99 XtFree (p->name);
100 *pp = p->next;
101 XtFree ((char *)p);
102 } else pp = &p->next;
103 }
104 }
105
elk_init_xt_action()106 void elk_init_xt_action () {
107 Define_Primitive (P_Context_Add_Action, "context-add-action", 3, 3, EVAL);
108 }
109