*** empty log message ***
[emacs.git] / lwlib / lwlib-utils.c
blobc6899b57af72b17028f6add1dd4cea26328121e4
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 <stdlib.h>
21 #include <unistd.h>
22 #include <string.h>
23 #include <memory.h>
25 #include <X11/Xatom.h>
26 #include <X11/IntrinsicP.h>
27 #include <X11/ObjectP.h>
28 #include "lwlib-utils.h"
30 /* Redisplay the contents of the widget, without first clearing it. */
31 void
32 XtNoClearRefreshWidget (widget)
33 Widget widget;
35 XEvent event;
37 event.type = Expose;
38 event.xexpose.serial = 0;
39 event.xexpose.send_event = 0;
40 event.xexpose.display = XtDisplay (widget);
41 event.xexpose.window = XtWindow (widget);
42 event.xexpose.x = 0;
43 event.xexpose.y = 0;
44 event.xexpose.width = widget->core.width;
45 event.xexpose.height = widget->core.height;
46 event.xexpose.count = 0;
48 (*widget->core.widget_class->core_class.expose)
49 (widget, &event, (Region)NULL);
53 /*
54 * Apply a function to all the subwidgets of a given widget recursively.
56 void
57 XtApplyToWidgets (w, proc, arg)
58 Widget w;
59 XtApplyToWidgetsProc proc;
60 XtPointer arg;
62 if (XtIsComposite (w))
64 CompositeWidget cw = (CompositeWidget) w;
65 /* We have to copy the children list before mapping over it, because
66 the procedure might add/delete elements, which would lose badly.
68 int nkids = cw->composite.num_children;
69 Widget *kids = (Widget *) malloc (sizeof (Widget) * nkids);
70 int i;
71 memcpy (kids, cw->composite.children, sizeof (Widget) * nkids);
72 for (i = 0; i < nkids; i++)
73 /* This prevent us from using gadgets, why is it here? */
74 /* if (XtIsWidget (kids [i])) */
76 /* do the kiddies first in case we're destroying */
77 XtApplyToWidgets (kids [i], proc, arg);
78 proc (kids [i], arg);
80 free (kids);
86 * Apply a function to all the subwidgets of a given widget recursively.
87 * Stop as soon as the function returns non NULL and returns this as a value.
89 void *
90 XtApplyUntilToWidgets (w, proc, arg)
91 Widget w;
92 XtApplyUntilToWidgetsProc proc;
93 XtPointer arg;
95 void* result;
96 if (XtIsComposite (w))
98 CompositeWidget cw = (CompositeWidget)w;
99 int i;
100 for (i = 0; i < cw->composite.num_children; i++)
101 if (XtIsWidget (cw->composite.children [i])){
102 result = proc (cw->composite.children [i], arg);
103 if (result)
104 return result;
105 result = XtApplyUntilToWidgets (cw->composite.children [i], proc,
106 arg);
107 if (result)
108 return result;
111 return NULL;
116 * Returns a copy of the list of all children of a composite widget
118 Widget *
119 XtCompositeChildren (widget, number)
120 Widget widget;
121 unsigned int* number;
123 CompositeWidget cw = (CompositeWidget)widget;
124 Widget* result;
125 int n;
126 int i;
128 if (!XtIsComposite (widget))
130 *number = 0;
131 return NULL;
133 n = cw->composite.num_children;
134 result = (Widget*)XtMalloc (n * sizeof (Widget));
135 *number = n;
136 for (i = 0; i < n; i++)
137 result [i] = cw->composite.children [i];
138 return result;
141 Boolean
142 XtWidgetBeingDestroyedP (widget)
143 Widget widget;
145 return widget->core.being_destroyed;
148 void
149 XtSafelyDestroyWidget (widget)
150 Widget widget;
152 #if 0
154 /* this requires IntrinsicI.h (actually, InitialI.h) */
156 XtAppContext app = XtWidgetToApplicationContext(widget);
158 if (app->dispatch_level == 0)
160 app->dispatch_level = 1;
161 XtDestroyWidget (widget);
162 /* generates an event so that the event loop will be called */
163 XChangeProperty (XtDisplay (widget), XtWindow (widget),
164 XA_STRING, XA_STRING, 32, PropModeAppend, NULL, 0);
165 app->dispatch_level = 0;
167 else
168 XtDestroyWidget (widget);
170 #else
171 abort ();
172 #endif