Undo my previous commit, as per Stefan.
[bpt/emacs.git] / lwlib / lwlib-utils.c
CommitLineData
07bf635f 1/* Defines some widget utility functions.
4424d48a 2Copyright (C) 1992 Lucid, Inc.
73b0cd50 3Copyright (C) 1994, 2001-2011 Free Software Foundation, Inc.
07bf635f
RS
4
5This file is part of the Lucid Widget Library.
6
177c0ea7 7The Lucid Widget Library is free software; you can redistribute it and/or
07bf635f
RS
8modify it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 1, or (at your option)
10any later version.
11
12The Lucid Widget Library is distributed in the hope that it will be useful,
177c0ea7 13but WITHOUT ANY WARRANTY; without even the implied warranty of
07bf635f
RS
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU Emacs; see the file COPYING. If not, write to
364c38d3
LK
19the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20Boston, MA 02110-1301, USA. */
07bf635f 21
d6c5b98a
RS
22#ifdef HAVE_CONFIG_H
23#include <config.h>
24#endif
25
5750ebd8
KH
26/* Definitions of these in config.h can cause
27 declaration conflicts later on between declarations for index
28 and declarations for strchr. This file doesn't use
29 index and rindex, so cancel them. */
30#undef index
31#undef rindex
32
d7306fe6 33#include <setjmp.h>
2f96293d
RS
34#include "../src/lisp.h"
35
07bf635f
RS
36#include <X11/Xatom.h>
37#include <X11/IntrinsicP.h>
38#include <X11/ObjectP.h>
39#include "lwlib-utils.h"
123c6301 40#include "lwlib.h"
07bf635f
RS
41
42/* Redisplay the contents of the widget, without first clearing it. */
43void
c3174d16 44XtNoClearRefreshWidget (Widget widget)
07bf635f
RS
45{
46 XEvent event;
47
48 event.type = Expose;
49 event.xexpose.serial = 0;
50 event.xexpose.send_event = 0;
51 event.xexpose.display = XtDisplay (widget);
52 event.xexpose.window = XtWindow (widget);
53 event.xexpose.x = 0;
54 event.xexpose.y = 0;
55 event.xexpose.width = widget->core.width;
56 event.xexpose.height = widget->core.height;
57 event.xexpose.count = 0;
58
59 (*widget->core.widget_class->core_class.expose)
60 (widget, &event, (Region)NULL);
61}
62
63
177c0ea7 64/*
07bf635f
RS
65 * Apply a function to all the subwidgets of a given widget recursively.
66*/
67void
c3174d16 68XtApplyToWidgets (Widget w, XtApplyToWidgetsProc proc, XtPointer arg)
07bf635f
RS
69{
70 if (XtIsComposite (w))
71 {
72 CompositeWidget cw = (CompositeWidget) w;
73 /* We have to copy the children list before mapping over it, because
74 the procedure might add/delete elements, which would lose badly.
75 */
76 int nkids = cw->composite.num_children;
3370edca 77 Widget *kids = (Widget *) xmalloc (sizeof (Widget) * nkids);
07bf635f 78 int i;
72af86bd
AS
79 memcpy ((char *) kids, (char *) cw->composite.children,
80 sizeof (Widget) * nkids);
07bf635f
RS
81 for (i = 0; i < nkids; i++)
82/* This prevent us from using gadgets, why is it here? */
83/* if (XtIsWidget (kids [i])) */
84 {
85 /* do the kiddies first in case we're destroying */
86 XtApplyToWidgets (kids [i], proc, arg);
87 proc (kids [i], arg);
88 }
89 free (kids);
90 }
91}
92
93
94/*
95 * Apply a function to all the subwidgets of a given widget recursively.
96 * Stop as soon as the function returns non NULL and returns this as a value.
97 */
98void *
c3174d16 99XtApplyUntilToWidgets (Widget w, XtApplyUntilToWidgetsProc proc, XtPointer arg)
07bf635f
RS
100{
101 void* result;
102 if (XtIsComposite (w))
103 {
104 CompositeWidget cw = (CompositeWidget)w;
105 int i;
106 for (i = 0; i < cw->composite.num_children; i++)
107 if (XtIsWidget (cw->composite.children [i])){
108 result = proc (cw->composite.children [i], arg);
109 if (result)
110 return result;
111 result = XtApplyUntilToWidgets (cw->composite.children [i], proc,
112 arg);
113 if (result)
114 return result;
115 }
116 }
117 return NULL;
118}
119
120
121/*
122 * Returns a copy of the list of all children of a composite widget
123 */
124Widget *
c3174d16 125XtCompositeChildren (Widget widget, unsigned int *number)
07bf635f
RS
126{
127 CompositeWidget cw = (CompositeWidget)widget;
128 Widget* result;
129 int n;
130 int i;
131
132 if (!XtIsComposite (widget))
133 {
134 *number = 0;
135 return NULL;
136 }
137 n = cw->composite.num_children;
138 result = (Widget*)XtMalloc (n * sizeof (Widget));
139 *number = n;
140 for (i = 0; i < n; i++)
141 result [i] = cw->composite.children [i];
142 return result;
143}
144
145Boolean
c3174d16 146XtWidgetBeingDestroyedP (Widget widget)
07bf635f
RS
147{
148 return widget->core.being_destroyed;
149}
150
151void
c3174d16 152XtSafelyDestroyWidget (Widget widget)
07bf635f
RS
153{
154#if 0
155
156 /* this requires IntrinsicI.h (actually, InitialI.h) */
157
158 XtAppContext app = XtWidgetToApplicationContext(widget);
159
160 if (app->dispatch_level == 0)
161 {
162 app->dispatch_level = 1;
163 XtDestroyWidget (widget);
164 /* generates an event so that the event loop will be called */
165 XChangeProperty (XtDisplay (widget), XtWindow (widget),
166 XA_STRING, XA_STRING, 32, PropModeAppend, NULL, 0);
167 app->dispatch_level = 0;
168 }
169 else
170 XtDestroyWidget (widget);
177c0ea7 171
07bf635f
RS
172#else
173 abort ();
174#endif
175}
ab5796a9 176