Fix ChangeLog entry of last commit.
[bpt/emacs.git] / lwlib / lwlib-utils.c
CommitLineData
07bf635f 1/* Defines some widget utility functions.
67f02b82 2
4424d48a 3Copyright (C) 1992 Lucid, Inc.
73b0cd50 4Copyright (C) 1994, 2001-2011 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
19along with GNU Emacs; see the file COPYING. If not, write to
364c38d3
LK
20the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21Boston, MA 02110-1301, USA. */
07bf635f 22
d6c5b98a
RS
23#ifdef HAVE_CONFIG_H
24#include <config.h>
25#endif
26
d7306fe6 27#include <setjmp.h>
67f02b82 28#include <lisp.h>
2f96293d 29
07bf635f
RS
30#include <X11/Xatom.h>
31#include <X11/IntrinsicP.h>
32#include <X11/ObjectP.h>
33#include "lwlib-utils.h"
123c6301 34#include "lwlib.h"
07bf635f
RS
35
36/* Redisplay the contents of the widget, without first clearing it. */
37void
c3174d16 38XtNoClearRefreshWidget (Widget widget)
07bf635f
RS
39{
40 XEvent event;
41
42 event.type = Expose;
43 event.xexpose.serial = 0;
44 event.xexpose.send_event = 0;
45 event.xexpose.display = XtDisplay (widget);
46 event.xexpose.window = XtWindow (widget);
47 event.xexpose.x = 0;
48 event.xexpose.y = 0;
49 event.xexpose.width = widget->core.width;
50 event.xexpose.height = widget->core.height;
51 event.xexpose.count = 0;
52
53 (*widget->core.widget_class->core_class.expose)
54 (widget, &event, (Region)NULL);
55}
56
57
177c0ea7 58/*
07bf635f
RS
59 * Apply a function to all the subwidgets of a given widget recursively.
60*/
61void
c3174d16 62XtApplyToWidgets (Widget w, XtApplyToWidgetsProc proc, XtPointer arg)
07bf635f
RS
63{
64 if (XtIsComposite (w))
65 {
66 CompositeWidget cw = (CompositeWidget) w;
67 /* We have to copy the children list before mapping over it, because
68 the procedure might add/delete elements, which would lose badly.
69 */
70 int nkids = cw->composite.num_children;
3370edca 71 Widget *kids = (Widget *) xmalloc (sizeof (Widget) * nkids);
07bf635f 72 int i;
72af86bd
AS
73 memcpy ((char *) kids, (char *) cw->composite.children,
74 sizeof (Widget) * nkids);
07bf635f
RS
75 for (i = 0; i < nkids; i++)
76/* This prevent us from using gadgets, why is it here? */
77/* if (XtIsWidget (kids [i])) */
78 {
79 /* do the kiddies first in case we're destroying */
80 XtApplyToWidgets (kids [i], proc, arg);
81 proc (kids [i], arg);
82 }
83 free (kids);
84 }
85}
86
87
88/*
89 * Apply a function to all the subwidgets of a given widget recursively.
90 * Stop as soon as the function returns non NULL and returns this as a value.
91 */
92void *
c3174d16 93XtApplyUntilToWidgets (Widget w, XtApplyUntilToWidgetsProc proc, XtPointer arg)
07bf635f
RS
94{
95 void* result;
96 if (XtIsComposite (w))
97 {
98 CompositeWidget cw = (CompositeWidget)w;
99 int i;
100 for (i = 0; i < cw->composite.num_children; i++)
101 if (XtIsWidget (cw->composite.children [i])){
102 result = proc (cw->composite.children [i], arg);
103 if (result)
104 return result;
105 result = XtApplyUntilToWidgets (cw->composite.children [i], proc,
106 arg);
107 if (result)
108 return result;
109 }
110 }
111 return NULL;
112}
113
114
115/*
116 * Returns a copy of the list of all children of a composite widget
117 */
118Widget *
c3174d16 119XtCompositeChildren (Widget widget, unsigned int *number)
07bf635f
RS
120{
121 CompositeWidget cw = (CompositeWidget)widget;
122 Widget* result;
123 int n;
124 int i;
125
126 if (!XtIsComposite (widget))
127 {
128 *number = 0;
129 return NULL;
130 }
131 n = cw->composite.num_children;
b165261a 132 result = (Widget*)(void*)XtMalloc (n * sizeof (Widget));
07bf635f
RS
133 *number = n;
134 for (i = 0; i < n; i++)
135 result [i] = cw->composite.children [i];
136 return result;
137}
138
139Boolean
c3174d16 140XtWidgetBeingDestroyedP (Widget widget)
07bf635f
RS
141{
142 return widget->core.being_destroyed;
143}