Add optional version as 4th element of specs and use it for several
[emacs.git] / lwlib / lwlib-utils.c
blob75aad733a39c040e08ea7ea7162507fdfc986b4c
1 /* Defines some widget utility functions.
2 Copyright (C) 1992 Lucid, Inc.
4 This file is part of the Lucid Widget Library.
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.
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.
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, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 #ifdef HAVE_CONFIG_H
22 #include <config.h>
23 #endif
25 /* Definitions of these in config.h can cause
26 declaration conflicts later on between declarations for index
27 and declarations for strchr. This file doesn't use
28 index and rindex, so cancel them. */
29 #undef index
30 #undef rindex
32 #include <X11/Xatom.h>
33 #include <X11/IntrinsicP.h>
34 #include <X11/ObjectP.h>
35 #include "lwlib-utils.h"
36 #include "lwlib.h"
38 /* Redisplay the contents of the widget, without first clearing it. */
39 void
40 XtNoClearRefreshWidget (widget)
41 Widget widget;
43 XEvent event;
45 event.type = Expose;
46 event.xexpose.serial = 0;
47 event.xexpose.send_event = 0;
48 event.xexpose.display = XtDisplay (widget);
49 event.xexpose.window = XtWindow (widget);
50 event.xexpose.x = 0;
51 event.xexpose.y = 0;
52 event.xexpose.width = widget->core.width;
53 event.xexpose.height = widget->core.height;
54 event.xexpose.count = 0;
56 (*widget->core.widget_class->core_class.expose)
57 (widget, &event, (Region)NULL);
61 /*
62 * Apply a function to all the subwidgets of a given widget recursively.
64 void
65 XtApplyToWidgets (w, proc, arg)
66 Widget w;
67 XtApplyToWidgetsProc proc;
68 XtPointer arg;
70 if (XtIsComposite (w))
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.
76 int nkids = cw->composite.num_children;
77 Widget *kids = (Widget *) malloc (sizeof (Widget) * nkids);
78 int i;
79 lwlib_bcopy (cw->composite.children, kids, sizeof (Widget) * nkids);
80 for (i = 0; i < nkids; i++)
81 /* This prevent us from using gadgets, why is it here? */
82 /* if (XtIsWidget (kids [i])) */
84 /* do the kiddies first in case we're destroying */
85 XtApplyToWidgets (kids [i], proc, arg);
86 proc (kids [i], arg);
88 free (kids);
94 * Apply a function to all the subwidgets of a given widget recursively.
95 * Stop as soon as the function returns non NULL and returns this as a value.
97 void *
98 XtApplyUntilToWidgets (w, proc, arg)
99 Widget w;
100 XtApplyUntilToWidgetsProc proc;
101 XtPointer arg;
103 void* result;
104 if (XtIsComposite (w))
106 CompositeWidget cw = (CompositeWidget)w;
107 int i;
108 for (i = 0; i < cw->composite.num_children; i++)
109 if (XtIsWidget (cw->composite.children [i])){
110 result = proc (cw->composite.children [i], arg);
111 if (result)
112 return result;
113 result = XtApplyUntilToWidgets (cw->composite.children [i], proc,
114 arg);
115 if (result)
116 return result;
119 return NULL;
124 * Returns a copy of the list of all children of a composite widget
126 Widget *
127 XtCompositeChildren (widget, number)
128 Widget widget;
129 unsigned int* number;
131 CompositeWidget cw = (CompositeWidget)widget;
132 Widget* result;
133 int n;
134 int i;
136 if (!XtIsComposite (widget))
138 *number = 0;
139 return NULL;
141 n = cw->composite.num_children;
142 result = (Widget*)XtMalloc (n * sizeof (Widget));
143 *number = n;
144 for (i = 0; i < n; i++)
145 result [i] = cw->composite.children [i];
146 return result;
149 Boolean
150 XtWidgetBeingDestroyedP (widget)
151 Widget widget;
153 return widget->core.being_destroyed;
156 void
157 XtSafelyDestroyWidget (widget)
158 Widget widget;
160 #if 0
162 /* this requires IntrinsicI.h (actually, InitialI.h) */
164 XtAppContext app = XtWidgetToApplicationContext(widget);
166 if (app->dispatch_level == 0)
168 app->dispatch_level = 1;
169 XtDestroyWidget (widget);
170 /* generates an event so that the event loop will be called */
171 XChangeProperty (XtDisplay (widget), XtWindow (widget),
172 XA_STRING, XA_STRING, 32, PropModeAppend, NULL, 0);
173 app->dispatch_level = 0;
175 else
176 XtDestroyWidget (widget);
178 #else
179 abort ();
180 #endif