ebrowse.c (check_namespace): Fix indentation.
[bpt/emacs.git] / lwlib / lwlib-utils.c
CommitLineData
07bf635f 1/* Defines some widget utility functions.
4424d48a 2Copyright (C) 1992 Lucid, Inc.
114f9c96
GM
3Copyright (C) 1994, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
4 2010 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
5750ebd8
KH
27/* Definitions of these in config.h can cause
28 declaration conflicts later on between declarations for index
29 and declarations for strchr. This file doesn't use
30 index and rindex, so cancel them. */
31#undef index
32#undef rindex
33
d7306fe6 34#include <setjmp.h>
2f96293d
RS
35#include "../src/lisp.h"
36
07bf635f
RS
37#include <X11/Xatom.h>
38#include <X11/IntrinsicP.h>
39#include <X11/ObjectP.h>
40#include "lwlib-utils.h"
123c6301 41#include "lwlib.h"
07bf635f
RS
42
43/* Redisplay the contents of the widget, without first clearing it. */
44void
345a94f9
RS
45XtNoClearRefreshWidget (widget)
46 Widget widget;
07bf635f
RS
47{
48 XEvent event;
49
50 event.type = Expose;
51 event.xexpose.serial = 0;
52 event.xexpose.send_event = 0;
53 event.xexpose.display = XtDisplay (widget);
54 event.xexpose.window = XtWindow (widget);
55 event.xexpose.x = 0;
56 event.xexpose.y = 0;
57 event.xexpose.width = widget->core.width;
58 event.xexpose.height = widget->core.height;
59 event.xexpose.count = 0;
60
61 (*widget->core.widget_class->core_class.expose)
62 (widget, &event, (Region)NULL);
63}
64
65
177c0ea7 66/*
07bf635f
RS
67 * Apply a function to all the subwidgets of a given widget recursively.
68*/
69void
345a94f9
RS
70XtApplyToWidgets (w, proc, arg)
71 Widget w;
72 XtApplyToWidgetsProc proc;
73 XtPointer arg;
07bf635f
RS
74{
75 if (XtIsComposite (w))
76 {
77 CompositeWidget cw = (CompositeWidget) w;
78 /* We have to copy the children list before mapping over it, because
79 the procedure might add/delete elements, which would lose badly.
80 */
81 int nkids = cw->composite.num_children;
82 Widget *kids = (Widget *) malloc (sizeof (Widget) * nkids);
83 int i;
cdefcd82
DL
84 lwlib_bcopy ((char *) cw->composite.children, (char *) kids,
85 sizeof (Widget) * nkids);
07bf635f
RS
86 for (i = 0; i < nkids; i++)
87/* This prevent us from using gadgets, why is it here? */
88/* if (XtIsWidget (kids [i])) */
89 {
90 /* do the kiddies first in case we're destroying */
91 XtApplyToWidgets (kids [i], proc, arg);
92 proc (kids [i], arg);
93 }
94 free (kids);
95 }
96}
97
98
99/*
100 * Apply a function to all the subwidgets of a given widget recursively.
101 * Stop as soon as the function returns non NULL and returns this as a value.
102 */
103void *
345a94f9
RS
104XtApplyUntilToWidgets (w, proc, arg)
105 Widget w;
106 XtApplyUntilToWidgetsProc proc;
107 XtPointer arg;
07bf635f
RS
108{
109 void* result;
110 if (XtIsComposite (w))
111 {
112 CompositeWidget cw = (CompositeWidget)w;
113 int i;
114 for (i = 0; i < cw->composite.num_children; i++)
115 if (XtIsWidget (cw->composite.children [i])){
116 result = proc (cw->composite.children [i], arg);
117 if (result)
118 return result;
119 result = XtApplyUntilToWidgets (cw->composite.children [i], proc,
120 arg);
121 if (result)
122 return result;
123 }
124 }
125 return NULL;
126}
127
128
129/*
130 * Returns a copy of the list of all children of a composite widget
131 */
132Widget *
345a94f9
RS
133XtCompositeChildren (widget, number)
134 Widget widget;
135 unsigned int* number;
07bf635f
RS
136{
137 CompositeWidget cw = (CompositeWidget)widget;
138 Widget* result;
139 int n;
140 int i;
141
142 if (!XtIsComposite (widget))
143 {
144 *number = 0;
145 return NULL;
146 }
147 n = cw->composite.num_children;
148 result = (Widget*)XtMalloc (n * sizeof (Widget));
149 *number = n;
150 for (i = 0; i < n; i++)
151 result [i] = cw->composite.children [i];
152 return result;
153}
154
155Boolean
345a94f9
RS
156XtWidgetBeingDestroyedP (widget)
157 Widget widget;
07bf635f
RS
158{
159 return widget->core.being_destroyed;
160}
161
162void
345a94f9
RS
163XtSafelyDestroyWidget (widget)
164 Widget widget;
07bf635f
RS
165{
166#if 0
167
168 /* this requires IntrinsicI.h (actually, InitialI.h) */
169
170 XtAppContext app = XtWidgetToApplicationContext(widget);
171
172 if (app->dispatch_level == 0)
173 {
174 app->dispatch_level = 1;
175 XtDestroyWidget (widget);
176 /* generates an event so that the event loop will be called */
177 XChangeProperty (XtDisplay (widget), XtWindow (widget),
178 XA_STRING, XA_STRING, 32, PropModeAppend, NULL, 0);
179 app->dispatch_level = 0;
180 }
181 else
182 XtDestroyWidget (widget);
177c0ea7 183
07bf635f
RS
184#else
185 abort ();
186#endif
187}
ab5796a9
MB
188
189/* arch-tag: f21f0a1f-2a4e-44e1-8715-7f234fe2d159
190 (do not change this comment) */