ActionHook.c revision 9e7bcd65
1444c061aSmrg/*LINTLIBRARY*/ 2444c061aSmrg 3444c061aSmrg/*********************************************************** 4249c3046SmrgCopyright (c) 1993, Oracle and/or its affiliates. All rights reserved. 51477040fSmrg 61477040fSmrgPermission is hereby granted, free of charge, to any person obtaining a 71477040fSmrgcopy of this software and associated documentation files (the "Software"), 81477040fSmrgto deal in the Software without restriction, including without limitation 91477040fSmrgthe rights to use, copy, modify, merge, publish, distribute, sublicense, 101477040fSmrgand/or sell copies of the Software, and to permit persons to whom the 111477040fSmrgSoftware is furnished to do so, subject to the following conditions: 121477040fSmrg 131477040fSmrgThe above copyright notice and this permission notice (including the next 141477040fSmrgparagraph) shall be included in all copies or substantial portions of the 151477040fSmrgSoftware. 161477040fSmrg 171477040fSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 181477040fSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 191477040fSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 201477040fSmrgTHE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 211477040fSmrgLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 221477040fSmrgFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 231477040fSmrgDEALINGS IN THE SOFTWARE. 241477040fSmrg 251477040fSmrgCopyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts. 26444c061aSmrg 27444c061aSmrg All Rights Reserved 28444c061aSmrg 29444c061aSmrgPermission to use, copy, modify, and distribute this software and its 30444c061aSmrgdocumentation for any purpose and without fee is hereby granted, 31444c061aSmrgprovided that the above copyright notice appear in all copies and that 32444c061aSmrgboth that copyright notice and this permission notice appear in 331477040fSmrgsupporting documentation, and that the name of Digital not be 34444c061aSmrgused in advertising or publicity pertaining to distribution of the 35444c061aSmrgsoftware without specific, written prior permission. 36444c061aSmrg 37444c061aSmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 38444c061aSmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 39444c061aSmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 40444c061aSmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 41444c061aSmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 42444c061aSmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 43444c061aSmrgSOFTWARE. 44444c061aSmrg 45444c061aSmrg******************************************************************/ 46444c061aSmrg 47444c061aSmrg/* 48444c061aSmrg 49444c061aSmrgCopyright 1987, 1988, 1998 The Open Group 50444c061aSmrg 51444c061aSmrgPermission to use, copy, modify, distribute, and sell this software and its 52444c061aSmrgdocumentation for any purpose is hereby granted without fee, provided that 53444c061aSmrgthe above copyright notice appear in all copies and that both that 54444c061aSmrgcopyright notice and this permission notice appear in supporting 55444c061aSmrgdocumentation. 56444c061aSmrg 57444c061aSmrgThe above copyright notice and this permission notice shall be included in 58444c061aSmrgall copies or substantial portions of the Software. 59444c061aSmrg 60444c061aSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 61444c061aSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 62444c061aSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 63444c061aSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 64444c061aSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 65444c061aSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 66444c061aSmrg 67444c061aSmrgExcept as contained in this notice, the name of The Open Group shall not be 68444c061aSmrgused in advertising or otherwise to promote the sale, use or other dealings 69444c061aSmrgin this Software without prior written authorization from The Open Group. 70444c061aSmrg 71444c061aSmrg*/ 72444c061aSmrg 739e7bcd65Smrg/* 74444c061aSmrg * Contains XtAppAddActionHook, XtRemoveActionHook 75444c061aSmrg */ 76444c061aSmrg 77444c061aSmrg#ifdef HAVE_CONFIG_H 78444c061aSmrg#include <config.h> 79444c061aSmrg#endif 80444c061aSmrg#include "IntrinsicI.h" 81444c061aSmrg 82444c061aSmrg 83444c061aSmrg/*ARGSUSED*/ 84444c061aSmrgstatic void FreeActionHookList( 85444c061aSmrg Widget widget, /* unused (and invalid) */ 86444c061aSmrg XtPointer closure, /* ActionHook* */ 87444c061aSmrg XtPointer call_data) /* unused */ 88444c061aSmrg{ 89444c061aSmrg ActionHook list = *(ActionHook*)closure; 90444c061aSmrg while (list != NULL) { 91444c061aSmrg ActionHook next = list->next; 92444c061aSmrg XtFree( (XtPointer)list ); 93444c061aSmrg list = next; 94444c061aSmrg } 95444c061aSmrg} 96444c061aSmrg 97444c061aSmrg 98444c061aSmrgXtActionHookId XtAppAddActionHook( 99444c061aSmrg XtAppContext app, 100444c061aSmrg XtActionHookProc proc, 101444c061aSmrg XtPointer closure) 102444c061aSmrg{ 103444c061aSmrg ActionHook hook = XtNew(ActionHookRec); 104444c061aSmrg LOCK_APP(app); 105444c061aSmrg hook->next = app->action_hook_list; 106444c061aSmrg hook->app = app; 107444c061aSmrg hook->proc = proc; 108444c061aSmrg hook->closure = closure; 109444c061aSmrg if (app->action_hook_list == NULL) { 110444c061aSmrg _XtAddCallback( &app->destroy_callbacks, 111444c061aSmrg FreeActionHookList, 112444c061aSmrg (XtPointer)&app->action_hook_list 113444c061aSmrg ); 114444c061aSmrg } 115444c061aSmrg app->action_hook_list = hook; 116444c061aSmrg UNLOCK_APP(app); 117444c061aSmrg return (XtActionHookId)hook; 118444c061aSmrg} 119444c061aSmrg 120444c061aSmrg 121444c061aSmrgvoid XtRemoveActionHook( 122444c061aSmrg XtActionHookId id) 123444c061aSmrg{ 124444c061aSmrg ActionHook *p, hook = (ActionHook)id; 125444c061aSmrg XtAppContext app = hook->app; 126444c061aSmrg LOCK_APP(app); 127444c061aSmrg for (p = &app->action_hook_list; p != NULL && *p != hook; p = &(*p)->next); 128444c061aSmrg if (p) { 129444c061aSmrg *p = hook->next; 130444c061aSmrg XtFree( (XtPointer)hook ); 131444c061aSmrg if (app->action_hook_list == NULL) 132444c061aSmrg _XtRemoveCallback(&app->destroy_callbacks, FreeActionHookList, 133444c061aSmrg (XtPointer) &app->action_hook_list); 134444c061aSmrg } 135444c061aSmrg#ifdef DEBUG 136444c061aSmrg else { 137444c061aSmrg XtAppWarningMsg(app, "badId", "xtRemoveActionHook", XtCXtToolkitError, 138444c061aSmrg "XtRemoveActionHook called with bad or old hook id", 139444c061aSmrg (String*)NULL, (Cardinal*)NULL); 140444c061aSmrg } 141444c061aSmrg#endif /*DEBUG*/ 142444c061aSmrg UNLOCK_APP(app); 143444c061aSmrg} 144