declare smobs in alloc.c
[bpt/emacs.git] / lwlib / lwlib-utils.c
CommitLineData
07bf635f 1/* Defines some widget utility functions.
67f02b82 2
4424d48a 3Copyright (C) 1992 Lucid, Inc.
ba318903 4Copyright (C) 1994, 2001-2014 Free Software Foundation, Inc.
07bf635f
RS
5
6This file is part of the Lucid Widget Library.
7
177c0ea7 8The Lucid Widget Library is free software; you can redistribute it and/or
07bf635f
RS
9modify it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 1, or (at your option)
11any later version.
12
13The Lucid Widget Library is distributed in the hope that it will be useful,
177c0ea7 14but WITHOUT ANY WARRANTY; without even the implied warranty of
07bf635f
RS
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
fee0bd5f 19along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
07bf635f 20
d6c5b98a 21#include <config.h>
d6c5b98a 22
d7306fe6 23#include <setjmp.h>
67f02b82 24#include <lisp.h>
2f96293d 25
07bf635f
RS
26#include <X11/Xatom.h>
27#include <X11/IntrinsicP.h>
28#include <X11/ObjectP.h>
29#include "lwlib-utils.h"
123c6301 30#include "lwlib.h"
07bf635f
RS
31
32/* Redisplay the contents of the widget, without first clearing it. */
33void
c3174d16 34XtNoClearRefreshWidget (Widget widget)
07bf635f
RS
35{
36 XEvent event;
37
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;
48
49 (*widget->core.widget_class->core_class.expose)
50 (widget, &event, (Region)NULL);
51}
52
53
177c0ea7 54/*
07bf635f
RS
55 * Apply a function to all the subwidgets of a given widget recursively.
56*/
57void
c3174d16 58XtApplyToWidgets (Widget w, XtApplyToWidgetsProc proc, XtPointer arg)
07bf635f
RS
59{
60 if (XtIsComposite (w))
61 {
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.
65 */
66 int nkids = cw->composite.num_children;
3370edca 67 Widget *kids = (Widget *) xmalloc (sizeof (Widget) * nkids);
07bf635f 68 int i;
72af86bd
AS
69 memcpy ((char *) kids, (char *) cw->composite.children,
70 sizeof (Widget) * nkids);
07bf635f
RS
71 for (i = 0; i < nkids; i++)
72/* This prevent us from using gadgets, why is it here? */
73/* if (XtIsWidget (kids [i])) */
74 {
75 /* do the kiddies first in case we're destroying */
76 XtApplyToWidgets (kids [i], proc, arg);
77 proc (kids [i], arg);
78 }
81d40c92 79 xfree (kids);
07bf635f
RS
80 }
81}
82
83
84/*
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.
87 */
88void *
c3174d16 89XtApplyUntilToWidgets (Widget w, XtApplyUntilToWidgetsProc proc, XtPointer arg)
07bf635f
RS
90{
91 void* result;
92 if (XtIsComposite (w))
93 {
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;
105 }
106 }
107 return NULL;
108}
109
110
111/*
112 * Returns a copy of the list of all children of a composite widget
113 */
114Widget *
c3174d16 115XtCompositeChildren (Widget widget, unsigned int *number)
07bf635f
RS
116{
117 CompositeWidget cw = (CompositeWidget)widget;
118 Widget* result;
119 int n;
120 int i;
121
122 if (!XtIsComposite (widget))
123 {
124 *number = 0;
125 return NULL;
126 }
127 n = cw->composite.num_children;
b165261a 128 result = (Widget*)(void*)XtMalloc (n * sizeof (Widget));
07bf635f
RS
129 *number = n;
130 for (i = 0; i < n; i++)
131 result [i] = cw->composite.children [i];
132 return result;
133}
134
135Boolean
c3174d16 136XtWidgetBeingDestroyedP (Widget widget)
07bf635f
RS
137{
138 return widget->core.being_destroyed;
139}