Fixed calendar-string-spread to allow 0 or 1 string; this simplified several
[emacs.git] / lwlib / lwlib-utils.c
blob1164482e182ca08c4a4c10f5165520c4fda93993
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, 675 Mass Ave, Cambridge, MA 02139, USA. */
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
24 #include <X11/Xatom.h>
25 #include <X11/IntrinsicP.h>
26 #include <X11/ObjectP.h>
27 #include "lwlib-utils.h"
29 /* Redisplay the contents of the widget, without first clearing it. */
30 void
31 XtNoClearRefreshWidget (widget)
32 Widget widget;
34 XEvent event;
36 event.type = Expose;
37 event.xexpose.serial = 0;
38 event.xexpose.send_event = 0;
39 event.xexpose.display = XtDisplay (widget);
40 event.xexpose.window = XtWindow (widget);
41 event.xexpose.x = 0;
42 event.xexpose.y = 0;
43 event.xexpose.width = widget->core.width;
44 event.xexpose.height = widget->core.height;
45 event.xexpose.count = 0;
47 (*widget->core.widget_class->core_class.expose)
48 (widget, &event, (Region)NULL);
52 /*
53 * Apply a function to all the subwidgets of a given widget recursively.
55 void
56 XtApplyToWidgets (w, proc, arg)
57 Widget w;
58 XtApplyToWidgetsProc proc;
59 XtPointer arg;
61 if (XtIsComposite (w))
63 CompositeWidget cw = (CompositeWidget) w;
64 /* We have to copy the children list before mapping over it, because
65 the procedure might add/delete elements, which would lose badly.
67 int nkids = cw->composite.num_children;
68 Widget *kids = (Widget *) malloc (sizeof (Widget) * nkids);
69 int i;
70 lwlib_bcopy (cw->composite.children, kids, sizeof (Widget) * nkids);
71 for (i = 0; i < nkids; i++)
72 /* This prevent us from using gadgets, why is it here? */
73 /* if (XtIsWidget (kids [i])) */
75 /* do the kiddies first in case we're destroying */
76 XtApplyToWidgets (kids [i], proc, arg);
77 proc (kids [i], arg);
79 free (kids);
85 * Apply a function to all the subwidgets of a given widget recursively.
86 * Stop as soon as the function returns non NULL and returns this as a value.
88 void *
89 XtApplyUntilToWidgets (w, proc, arg)
90 Widget w;
91 XtApplyUntilToWidgetsProc proc;
92 XtPointer arg;
94 void* result;
95 if (XtIsComposite (w))
97 CompositeWidget cw = (CompositeWidget)w;
98 int i;
99 for (i = 0; i < cw->composite.num_children; i++)
100 if (XtIsWidget (cw->composite.children [i])){
101 result = proc (cw->composite.children [i], arg);
102 if (result)
103 return result;
104 result = XtApplyUntilToWidgets (cw->composite.children [i], proc,
105 arg);
106 if (result)
107 return result;
110 return NULL;
115 * Returns a copy of the list of all children of a composite widget
117 Widget *
118 XtCompositeChildren (widget, number)
119 Widget widget;
120 unsigned int* number;
122 CompositeWidget cw = (CompositeWidget)widget;
123 Widget* result;
124 int n;
125 int i;
127 if (!XtIsComposite (widget))
129 *number = 0;
130 return NULL;
132 n = cw->composite.num_children;
133 result = (Widget*)XtMalloc (n * sizeof (Widget));
134 *number = n;
135 for (i = 0; i < n; i++)
136 result [i] = cw->composite.children [i];
137 return result;
140 Boolean
141 XtWidgetBeingDestroyedP (widget)
142 Widget widget;
144 return widget->core.being_destroyed;
147 void
148 XtSafelyDestroyWidget (widget)
149 Widget widget;
151 #if 0
153 /* this requires IntrinsicI.h (actually, InitialI.h) */
155 XtAppContext app = XtWidgetToApplicationContext(widget);
157 if (app->dispatch_level == 0)
159 app->dispatch_level = 1;
160 XtDestroyWidget (widget);
161 /* generates an event so that the event loop will be called */
162 XChangeProperty (XtDisplay (widget), XtWindow (widget),
163 XA_STRING, XA_STRING, 32, PropModeAppend, NULL, 0);
164 app->dispatch_level = 0;
166 else
167 XtDestroyWidget (widget);
169 #else
170 abort ();
171 #endif