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