ActionHook.c revision 444c061a
1444c061aSmrg/* $Xorg: ActionHook.c,v 1.4 2001/02/09 02:03:53 xorgcvs Exp $ */ 2444c061aSmrg 3444c061aSmrg/*LINTLIBRARY*/ 4444c061aSmrg 5444c061aSmrg/*********************************************************** 6444c061aSmrgCopyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts, 7444c061aSmrgCopyright 1993 by Sun Microsystems, Inc. Mountain View, CA. 8444c061aSmrg 9444c061aSmrg All Rights Reserved 10444c061aSmrg 11444c061aSmrgPermission to use, copy, modify, and distribute this software and its 12444c061aSmrgdocumentation for any purpose and without fee is hereby granted, 13444c061aSmrgprovided that the above copyright notice appear in all copies and that 14444c061aSmrgboth that copyright notice and this permission notice appear in 15444c061aSmrgsupporting documentation, and that the names of Digital or Sun not be 16444c061aSmrgused in advertising or publicity pertaining to distribution of the 17444c061aSmrgsoftware without specific, written prior permission. 18444c061aSmrg 19444c061aSmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 20444c061aSmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 21444c061aSmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 22444c061aSmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 23444c061aSmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 24444c061aSmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 25444c061aSmrgSOFTWARE. 26444c061aSmrg 27444c061aSmrgSUN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 28444c061aSmrgINCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT- 29444c061aSmrgNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE LI- 30444c061aSmrgABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 31444c061aSmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 32444c061aSmrgPROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 33444c061aSmrgOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH 34444c061aSmrgTHE USE OR PERFORMANCE OF THIS SOFTWARE. 35444c061aSmrg 36444c061aSmrg******************************************************************/ 37444c061aSmrg 38444c061aSmrg/* 39444c061aSmrg 40444c061aSmrgCopyright 1987, 1988, 1998 The Open Group 41444c061aSmrg 42444c061aSmrgPermission to use, copy, modify, distribute, and sell this software and its 43444c061aSmrgdocumentation for any purpose is hereby granted without fee, provided that 44444c061aSmrgthe above copyright notice appear in all copies and that both that 45444c061aSmrgcopyright notice and this permission notice appear in supporting 46444c061aSmrgdocumentation. 47444c061aSmrg 48444c061aSmrgThe above copyright notice and this permission notice shall be included in 49444c061aSmrgall copies or substantial portions of the Software. 50444c061aSmrg 51444c061aSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 52444c061aSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 53444c061aSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 54444c061aSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 55444c061aSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 56444c061aSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 57444c061aSmrg 58444c061aSmrgExcept as contained in this notice, the name of The Open Group shall not be 59444c061aSmrgused in advertising or otherwise to promote the sale, use or other dealings 60444c061aSmrgin this Software without prior written authorization from The Open Group. 61444c061aSmrg 62444c061aSmrg*/ 63444c061aSmrg/* $XFree86: xc/lib/Xt/ActionHook.c,v 1.2 2001/08/22 22:52:17 dawes Exp $ */ 64444c061aSmrg 65444c061aSmrg/* 66444c061aSmrg * Contains XtAppAddActionHook, XtRemoveActionHook 67444c061aSmrg */ 68444c061aSmrg 69444c061aSmrg#ifdef HAVE_CONFIG_H 70444c061aSmrg#include <config.h> 71444c061aSmrg#endif 72444c061aSmrg#include "IntrinsicI.h" 73444c061aSmrg 74444c061aSmrg 75444c061aSmrg/*ARGSUSED*/ 76444c061aSmrgstatic void FreeActionHookList( 77444c061aSmrg Widget widget, /* unused (and invalid) */ 78444c061aSmrg XtPointer closure, /* ActionHook* */ 79444c061aSmrg XtPointer call_data) /* unused */ 80444c061aSmrg{ 81444c061aSmrg ActionHook list = *(ActionHook*)closure; 82444c061aSmrg while (list != NULL) { 83444c061aSmrg ActionHook next = list->next; 84444c061aSmrg XtFree( (XtPointer)list ); 85444c061aSmrg list = next; 86444c061aSmrg } 87444c061aSmrg} 88444c061aSmrg 89444c061aSmrg 90444c061aSmrgXtActionHookId XtAppAddActionHook( 91444c061aSmrg XtAppContext app, 92444c061aSmrg XtActionHookProc proc, 93444c061aSmrg XtPointer closure) 94444c061aSmrg{ 95444c061aSmrg ActionHook hook = XtNew(ActionHookRec); 96444c061aSmrg LOCK_APP(app); 97444c061aSmrg hook->next = app->action_hook_list; 98444c061aSmrg hook->app = app; 99444c061aSmrg hook->proc = proc; 100444c061aSmrg hook->closure = closure; 101444c061aSmrg if (app->action_hook_list == NULL) { 102444c061aSmrg _XtAddCallback( &app->destroy_callbacks, 103444c061aSmrg FreeActionHookList, 104444c061aSmrg (XtPointer)&app->action_hook_list 105444c061aSmrg ); 106444c061aSmrg } 107444c061aSmrg app->action_hook_list = hook; 108444c061aSmrg UNLOCK_APP(app); 109444c061aSmrg return (XtActionHookId)hook; 110444c061aSmrg} 111444c061aSmrg 112444c061aSmrg 113444c061aSmrgvoid XtRemoveActionHook( 114444c061aSmrg XtActionHookId id) 115444c061aSmrg{ 116444c061aSmrg ActionHook *p, hook = (ActionHook)id; 117444c061aSmrg XtAppContext app = hook->app; 118444c061aSmrg LOCK_APP(app); 119444c061aSmrg for (p = &app->action_hook_list; p != NULL && *p != hook; p = &(*p)->next); 120444c061aSmrg if (p) { 121444c061aSmrg *p = hook->next; 122444c061aSmrg XtFree( (XtPointer)hook ); 123444c061aSmrg if (app->action_hook_list == NULL) 124444c061aSmrg _XtRemoveCallback(&app->destroy_callbacks, FreeActionHookList, 125444c061aSmrg (XtPointer) &app->action_hook_list); 126444c061aSmrg } 127444c061aSmrg#ifdef DEBUG 128444c061aSmrg else { 129444c061aSmrg XtAppWarningMsg(app, "badId", "xtRemoveActionHook", XtCXtToolkitError, 130444c061aSmrg "XtRemoveActionHook called with bad or old hook id", 131444c061aSmrg (String*)NULL, (Cardinal*)NULL); 132444c061aSmrg } 133444c061aSmrg#endif /*DEBUG*/ 134444c061aSmrg UNLOCK_APP(app); 135444c061aSmrg} 136