Home | History | Annotate | Line # | Download | only in src
      1 /***********************************************************
      2 Copyright (c) 1993, Oracle and/or its affiliates.
      3 
      4 Permission is hereby granted, free of charge, to any person obtaining a
      5 copy of this software and associated documentation files (the "Software"),
      6 to deal in the Software without restriction, including without limitation
      7 the rights to use, copy, modify, merge, publish, distribute, sublicense,
      8 and/or sell copies of the Software, and to permit persons to whom the
      9 Software is furnished to do so, subject to the following conditions:
     10 
     11 The above copyright notice and this permission notice (including the next
     12 paragraph) shall be included in all copies or substantial portions of the
     13 Software.
     14 
     15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     18 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     20 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
     21 DEALINGS IN THE SOFTWARE.
     22 
     23 Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
     24 
     25                         All Rights Reserved
     26 
     27 Permission to use, copy, modify, and distribute this software and its
     28 documentation for any purpose and without fee is hereby granted,
     29 provided that the above copyright notice appear in all copies and that
     30 both that copyright notice and this permission notice appear in
     31 supporting documentation, and that the name of Digital not be
     32 used in advertising or publicity pertaining to distribution of the
     33 software without specific, written prior permission.
     34 
     35 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
     36 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
     37 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
     38 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
     39 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
     40 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
     41 SOFTWARE.
     42 
     43 ******************************************************************/
     44 /*
     45 
     46 Copyright 1987, 1988, 1998  The Open Group
     47 
     48 Permission to use, copy, modify, distribute, and sell this software and its
     49 documentation for any purpose is hereby granted without fee, provided that
     50 the above copyright notice appear in all copies and that both that
     51 copyright notice and this permission notice appear in supporting
     52 documentation.
     53 
     54 The above copyright notice and this permission notice shall be included in
     55 all copies or substantial portions of the Software.
     56 
     57 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     58 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     59 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
     60 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
     61 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
     62 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     63 
     64 Except as contained in this notice, the name of The Open Group shall not be
     65 used in advertising or otherwise to promote the sale, use or other dealings
     66 in this Software without prior written authorization from The Open Group.
     67 
     68 */
     69 /*
     70  * Contains XtAppAddActionHook, XtRemoveActionHook
     71  */
     72 #ifdef HAVE_CONFIG_H
     73 #include <config.h>
     74 #endif
     75 #include "IntrinsicI.h"
     76 
     77 static void
     78 FreeActionHookList(Widget widget _X_UNUSED,
     79 		   XtPointer closure,  /* ActionHook* */
     80                    XtPointer call_data _X_UNUSED)
     81 {
     82     ActionHook list = *(ActionHook *) closure;
     83 
     84     while (list != NULL) {
     85         ActionHook next = list->next;
     86 
     87         XtFree((XtPointer) list);
     88         list = next;
     89     }
     90 }
     91 
     92 XtActionHookId
     93 XtAppAddActionHook(XtAppContext app, XtActionHookProc proc, XtPointer closure)
     94 {
     95     ActionHook hook = XtNew(ActionHookRec);
     96 
     97     LOCK_APP(app);
     98     hook->next = app->action_hook_list;
     99     hook->app = app;
    100     hook->proc = proc;
    101     hook->closure = closure;
    102     if (app->action_hook_list == NULL) {
    103         _XtAddCallback(&app->destroy_callbacks,
    104                        FreeActionHookList, (XtPointer) &app->action_hook_list);
    105     }
    106     app->action_hook_list = hook;
    107     UNLOCK_APP(app);
    108     return (XtActionHookId) hook;
    109 }
    110 
    111 void
    112 XtRemoveActionHook(XtActionHookId id)
    113 {
    114     ActionHook *p, hook = (ActionHook) id;
    115     XtAppContext app = hook->app;
    116 
    117     LOCK_APP(app);
    118     for (p = &app->action_hook_list; p != NULL && *p != hook; p = &(*p)->next);
    119     if (p) {
    120         *p = hook->next;
    121         XtFree((XtPointer) hook);
    122         if (app->action_hook_list == NULL)
    123             _XtRemoveCallback(&app->destroy_callbacks, FreeActionHookList,
    124                               (XtPointer) &app->action_hook_list);
    125     }
    126 #ifdef DEBUG
    127     else {
    128         XtAppWarningMsg(app, "badId", "xtRemoveActionHook", XtCXtToolkitError,
    129                         "XtRemoveActionHook called with bad or old hook id",
    130                         NULL, NULL);
    131     }
    132 #endif /*DEBUG*/
    133         UNLOCK_APP(app);
    134 }
    135