1444c061aSmrg/***********************************************************
2fdf6a26fSmrgCopyright (c) 1993, Oracle and/or its affiliates.
31477040fSmrg
41477040fSmrgPermission is hereby granted, free of charge, to any person obtaining a
51477040fSmrgcopy of this software and associated documentation files (the "Software"),
61477040fSmrgto deal in the Software without restriction, including without limitation
71477040fSmrgthe rights to use, copy, modify, merge, publish, distribute, sublicense,
81477040fSmrgand/or sell copies of the Software, and to permit persons to whom the
91477040fSmrgSoftware is furnished to do so, subject to the following conditions:
101477040fSmrg
111477040fSmrgThe above copyright notice and this permission notice (including the next
121477040fSmrgparagraph) shall be included in all copies or substantial portions of the
131477040fSmrgSoftware.
141477040fSmrg
151477040fSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
161477040fSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
171477040fSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
181477040fSmrgTHE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
191477040fSmrgLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
201477040fSmrgFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
211477040fSmrgDEALINGS IN THE SOFTWARE.
221477040fSmrg
231477040fSmrgCopyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
24444c061aSmrg
25444c061aSmrg                        All Rights Reserved
26444c061aSmrg
27444c061aSmrgPermission to use, copy, modify, and distribute this software and its
28444c061aSmrgdocumentation for any purpose and without fee is hereby granted,
29444c061aSmrgprovided that the above copyright notice appear in all copies and that
30444c061aSmrgboth that copyright notice and this permission notice appear in
311477040fSmrgsupporting documentation, and that the name of Digital not be
32444c061aSmrgused in advertising or publicity pertaining to distribution of the
33444c061aSmrgsoftware without specific, written prior permission.
34444c061aSmrg
35444c061aSmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
36444c061aSmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
37444c061aSmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
38444c061aSmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
39444c061aSmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
40444c061aSmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
41444c061aSmrgSOFTWARE.
42444c061aSmrg
43444c061aSmrg******************************************************************/
44444c061aSmrg/*
45444c061aSmrg
46444c061aSmrgCopyright 1987, 1988, 1998  The Open Group
47444c061aSmrg
48444c061aSmrgPermission to use, copy, modify, distribute, and sell this software and its
49444c061aSmrgdocumentation for any purpose is hereby granted without fee, provided that
50444c061aSmrgthe above copyright notice appear in all copies and that both that
51444c061aSmrgcopyright notice and this permission notice appear in supporting
52444c061aSmrgdocumentation.
53444c061aSmrg
54444c061aSmrgThe above copyright notice and this permission notice shall be included in
55444c061aSmrgall copies or substantial portions of the Software.
56444c061aSmrg
57444c061aSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
58444c061aSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
59444c061aSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
60444c061aSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
61444c061aSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
62444c061aSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
63444c061aSmrg
64444c061aSmrgExcept as contained in this notice, the name of The Open Group shall not be
65444c061aSmrgused in advertising or otherwise to promote the sale, use or other dealings
66444c061aSmrgin this Software without prior written authorization from The Open Group.
67444c061aSmrg
68444c061aSmrg*/
699e7bcd65Smrg/*
70444c061aSmrg * Contains XtAppAddActionHook, XtRemoveActionHook
71444c061aSmrg */
72444c061aSmrg#ifdef HAVE_CONFIG_H
73444c061aSmrg#include <config.h>
74444c061aSmrg#endif
75444c061aSmrg#include "IntrinsicI.h"
76444c061aSmrg
77a3bd7f05Smrgstatic void
78a3bd7f05SmrgFreeActionHookList(Widget widget _X_UNUSED,
79a3bd7f05Smrg		   XtPointer closure,  /* ActionHook* */
80a3bd7f05Smrg                   XtPointer call_data _X_UNUSED)
81444c061aSmrg{
82a3bd7f05Smrg    ActionHook list = *(ActionHook *) closure;
83a3bd7f05Smrg
84444c061aSmrg    while (list != NULL) {
85a3bd7f05Smrg        ActionHook next = list->next;
86a3bd7f05Smrg
87a3bd7f05Smrg        XtFree((XtPointer) list);
88a3bd7f05Smrg        list = next;
89444c061aSmrg    }
90444c061aSmrg}
91444c061aSmrg
92a3bd7f05SmrgXtActionHookId
93a3bd7f05SmrgXtAppAddActionHook(XtAppContext app, XtActionHookProc proc, XtPointer closure)
94444c061aSmrg{
95444c061aSmrg    ActionHook hook = XtNew(ActionHookRec);
96a3bd7f05Smrg
97444c061aSmrg    LOCK_APP(app);
98444c061aSmrg    hook->next = app->action_hook_list;
99444c061aSmrg    hook->app = app;
100444c061aSmrg    hook->proc = proc;
101444c061aSmrg    hook->closure = closure;
102444c061aSmrg    if (app->action_hook_list == NULL) {
103a3bd7f05Smrg        _XtAddCallback(&app->destroy_callbacks,
104a3bd7f05Smrg                       FreeActionHookList, (XtPointer) &app->action_hook_list);
105444c061aSmrg    }
106444c061aSmrg    app->action_hook_list = hook;
107444c061aSmrg    UNLOCK_APP(app);
108a3bd7f05Smrg    return (XtActionHookId) hook;
109444c061aSmrg}
110444c061aSmrg
111a3bd7f05Smrgvoid
112a3bd7f05SmrgXtRemoveActionHook(XtActionHookId id)
113444c061aSmrg{
114a3bd7f05Smrg    ActionHook *p, hook = (ActionHook) id;
115444c061aSmrg    XtAppContext app = hook->app;
116a3bd7f05Smrg
117444c061aSmrg    LOCK_APP(app);
118444c061aSmrg    for (p = &app->action_hook_list; p != NULL && *p != hook; p = &(*p)->next);
119444c061aSmrg    if (p) {
120a3bd7f05Smrg        *p = hook->next;
121a3bd7f05Smrg        XtFree((XtPointer) hook);
122a3bd7f05Smrg        if (app->action_hook_list == NULL)
123a3bd7f05Smrg            _XtRemoveCallback(&app->destroy_callbacks, FreeActionHookList,
124a3bd7f05Smrg                              (XtPointer) &app->action_hook_list);
125444c061aSmrg    }
126444c061aSmrg#ifdef DEBUG
127444c061aSmrg    else {
128a3bd7f05Smrg        XtAppWarningMsg(app, "badId", "xtRemoveActionHook", XtCXtToolkitError,
129a3bd7f05Smrg                        "XtRemoveActionHook called with bad or old hook id",
130a3bd7f05Smrg                        NULL, NULL);
131444c061aSmrg    }
132444c061aSmrg#endif /*DEBUG*/
133a3bd7f05Smrg        UNLOCK_APP(app);
134444c061aSmrg}
135