Provide command for deleting processes from list-processes buffer
[emacs.git] / lwlib / lwlib-utils.c
blobf16d487a979768026ffc5c3191faafdfc5f671b0
1 /* Defines some widget utility functions.
3 Copyright (C) 1992 Lucid, Inc.
4 Copyright (C) 1994, 2001-2014 Free Software Foundation, Inc.
6 This file is part of the Lucid Widget Library.
8 The Lucid Widget Library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 1, or (at your option)
11 any later version.
13 The Lucid Widget Library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21 #include <config.h>
23 #include <setjmp.h>
24 #include <lisp.h>
26 #include <X11/Xatom.h>
27 #include <X11/IntrinsicP.h>
28 #include <X11/ObjectP.h>
29 #include "lwlib-utils.h"
30 #include "lwlib.h"
32 /* Redisplay the contents of the widget, without first clearing it. */
33 void
34 XtNoClearRefreshWidget (Widget widget)
36 XEvent event;
38 event.type = Expose;
39 event.xexpose.serial = 0;
40 event.xexpose.send_event = 0;
41 event.xexpose.display = XtDisplay (widget);
42 event.xexpose.window = XtWindow (widget);
43 event.xexpose.x = 0;
44 event.xexpose.y = 0;
45 event.xexpose.width = widget->core.width;
46 event.xexpose.height = widget->core.height;
47 event.xexpose.count = 0;
49 (*widget->core.widget_class->core_class.expose)
50 (widget, &event, (Region)NULL);
55 * Apply a function to all the subwidgets of a given widget recursively.
57 void
58 XtApplyToWidgets (Widget w, XtApplyToWidgetsProc proc, XtPointer arg)
60 if (XtIsComposite (w))
62 CompositeWidget cw = (CompositeWidget) w;
63 /* We have to copy the children list before mapping over it, because
64 the procedure might add/delete elements, which would lose badly.
66 int nkids = cw->composite.num_children;
67 Widget *kids = (Widget *) xmalloc (sizeof (Widget) * nkids);
68 int i;
69 memcpy ((char *) kids, (char *) cw->composite.children,
70 sizeof (Widget) * nkids);
71 for (i = 0; i < nkids; i++)
72 /* This prevent us from using gadgets, why is it here? */
73 /* if (XtIsWidget (kids [i])) */
75 /* do the kiddies first in case we're destroying */
76 XtApplyToWidgets (kids [i], proc, arg);
77 proc (kids [i], arg);
79 xfree (kids);
85 * Apply a function to all the subwidgets of a given widget recursively.
86 * Stop as soon as the function returns non NULL and returns this as a value.
88 void *
89 XtApplyUntilToWidgets (Widget w, XtApplyUntilToWidgetsProc proc, XtPointer arg)
91 void* result;
92 if (XtIsComposite (w))
94 CompositeWidget cw = (CompositeWidget)w;
95 int i;
96 for (i = 0; i < cw->composite.num_children; i++)
97 if (XtIsWidget (cw->composite.children [i])){
98 result = proc (cw->composite.children [i], arg);
99 if (result)
100 return result;
101 result = XtApplyUntilToWidgets (cw->composite.children [i], proc,
102 arg);
103 if (result)
104 return result;
107 return NULL;
112 * Returns a copy of the list of all children of a composite widget
114 Widget *
115 XtCompositeChildren (Widget widget, unsigned int *number)
117 CompositeWidget cw = (CompositeWidget)widget;
118 Widget* result;
119 int n;
120 int i;
122 if (!XtIsComposite (widget))
124 *number = 0;
125 return NULL;
127 n = cw->composite.num_children;
128 result = (Widget*)(void*)XtMalloc (n * sizeof (Widget));
129 *number = n;
130 for (i = 0; i < n; i++)
131 result [i] = cw->composite.children [i];
132 return result;
135 Boolean
136 XtWidgetBeingDestroyedP (Widget widget)
138 return widget->core.being_destroyed;