(Fml_provide_prefix_argument, Fml_prefix_argument_loop): Use perdisplay.
[emacs.git] / lwlib / lwlib-utils.c
blob9e535c1996d488c745659b2547935f79e0d295b1
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 #include <X11/Xatom.h>
21 #include <X11/IntrinsicP.h>
22 #include <X11/ObjectP.h>
23 #include "lwlib-utils.h"
25 /* Redisplay the contents of the widget, without first clearing it. */
26 void
27 XtNoClearRefreshWidget (widget)
28 Widget widget;
30 XEvent event;
32 event.type = Expose;
33 event.xexpose.serial = 0;
34 event.xexpose.send_event = 0;
35 event.xexpose.display = XtDisplay (widget);
36 event.xexpose.window = XtWindow (widget);
37 event.xexpose.x = 0;
38 event.xexpose.y = 0;
39 event.xexpose.width = widget->core.width;
40 event.xexpose.height = widget->core.height;
41 event.xexpose.count = 0;
43 (*widget->core.widget_class->core_class.expose)
44 (widget, &event, (Region)NULL);
48 /*
49 * Apply a function to all the subwidgets of a given widget recursively.
51 void
52 XtApplyToWidgets (w, proc, arg)
53 Widget w;
54 XtApplyToWidgetsProc proc;
55 XtPointer arg;
57 if (XtIsComposite (w))
59 CompositeWidget cw = (CompositeWidget) w;
60 /* We have to copy the children list before mapping over it, because
61 the procedure might add/delete elements, which would lose badly.
63 int nkids = cw->composite.num_children;
64 Widget *kids = (Widget *) malloc (sizeof (Widget) * nkids);
65 int i;
66 lwlib_bcopy (cw->composite.children, kids, sizeof (Widget) * nkids);
67 for (i = 0; i < nkids; i++)
68 /* This prevent us from using gadgets, why is it here? */
69 /* if (XtIsWidget (kids [i])) */
71 /* do the kiddies first in case we're destroying */
72 XtApplyToWidgets (kids [i], proc, arg);
73 proc (kids [i], arg);
75 free (kids);
81 * Apply a function to all the subwidgets of a given widget recursively.
82 * Stop as soon as the function returns non NULL and returns this as a value.
84 void *
85 XtApplyUntilToWidgets (w, proc, arg)
86 Widget w;
87 XtApplyUntilToWidgetsProc proc;
88 XtPointer arg;
90 void* result;
91 if (XtIsComposite (w))
93 CompositeWidget cw = (CompositeWidget)w;
94 int i;
95 for (i = 0; i < cw->composite.num_children; i++)
96 if (XtIsWidget (cw->composite.children [i])){
97 result = proc (cw->composite.children [i], arg);
98 if (result)
99 return result;
100 result = XtApplyUntilToWidgets (cw->composite.children [i], proc,
101 arg);
102 if (result)
103 return result;
106 return NULL;
111 * Returns a copy of the list of all children of a composite widget
113 Widget *
114 XtCompositeChildren (widget, number)
115 Widget widget;
116 unsigned int* number;
118 CompositeWidget cw = (CompositeWidget)widget;
119 Widget* result;
120 int n;
121 int i;
123 if (!XtIsComposite (widget))
125 *number = 0;
126 return NULL;
128 n = cw->composite.num_children;
129 result = (Widget*)XtMalloc (n * sizeof (Widget));
130 *number = n;
131 for (i = 0; i < n; i++)
132 result [i] = cw->composite.children [i];
133 return result;
136 Boolean
137 XtWidgetBeingDestroyedP (widget)
138 Widget widget;
140 return widget->core.being_destroyed;
143 void
144 XtSafelyDestroyWidget (widget)
145 Widget widget;
147 #if 0
149 /* this requires IntrinsicI.h (actually, InitialI.h) */
151 XtAppContext app = XtWidgetToApplicationContext(widget);
153 if (app->dispatch_level == 0)
155 app->dispatch_level = 1;
156 XtDestroyWidget (widget);
157 /* generates an event so that the event loop will be called */
158 XChangeProperty (XtDisplay (widget), XtWindow (widget),
159 XA_STRING, XA_STRING, 32, PropModeAppend, NULL, 0);
160 app->dispatch_level = 0;
162 else
163 XtDestroyWidget (widget);
165 #else
166 abort ();
167 #endif