]> code.delx.au - gnu-emacs/blob - lwlib/lwlib-utils.c
Convert consecutive FSF copyright years to ranges.
[gnu-emacs] / lwlib / lwlib-utils.c
1 /* Defines some widget utility functions.
2 Copyright (C) 1992 Lucid, Inc.
3 Copyright (C) 1994, 2001-2011 Free Software Foundation, Inc.
4
5 This file is part of the Lucid Widget Library.
6
7 The Lucid Widget Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 1, or (at your option)
10 any later version.
11
12 The Lucid Widget Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 /* Definitions of these in config.h can cause
27 declaration conflicts later on between declarations for index
28 and declarations for strchr. This file doesn't use
29 index and rindex, so cancel them. */
30 #undef index
31 #undef rindex
32
33 #include <setjmp.h>
34 #include "../src/lisp.h"
35
36 #include <X11/Xatom.h>
37 #include <X11/IntrinsicP.h>
38 #include <X11/ObjectP.h>
39 #include "lwlib-utils.h"
40 #include "lwlib.h"
41
42 /* Redisplay the contents of the widget, without first clearing it. */
43 void
44 XtNoClearRefreshWidget (Widget widget)
45 {
46 XEvent event;
47
48 event.type = Expose;
49 event.xexpose.serial = 0;
50 event.xexpose.send_event = 0;
51 event.xexpose.display = XtDisplay (widget);
52 event.xexpose.window = XtWindow (widget);
53 event.xexpose.x = 0;
54 event.xexpose.y = 0;
55 event.xexpose.width = widget->core.width;
56 event.xexpose.height = widget->core.height;
57 event.xexpose.count = 0;
58
59 (*widget->core.widget_class->core_class.expose)
60 (widget, &event, (Region)NULL);
61 }
62
63
64 /*
65 * Apply a function to all the subwidgets of a given widget recursively.
66 */
67 void
68 XtApplyToWidgets (Widget w, XtApplyToWidgetsProc proc, XtPointer arg)
69 {
70 if (XtIsComposite (w))
71 {
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.
75 */
76 int nkids = cw->composite.num_children;
77 Widget *kids = (Widget *) malloc (sizeof (Widget) * nkids);
78 int i;
79 memcpy ((char *) kids, (char *) cw->composite.children,
80 sizeof (Widget) * nkids);
81 for (i = 0; i < nkids; i++)
82 /* This prevent us from using gadgets, why is it here? */
83 /* if (XtIsWidget (kids [i])) */
84 {
85 /* do the kiddies first in case we're destroying */
86 XtApplyToWidgets (kids [i], proc, arg);
87 proc (kids [i], arg);
88 }
89 free (kids);
90 }
91 }
92
93
94 /*
95 * Apply a function to all the subwidgets of a given widget recursively.
96 * Stop as soon as the function returns non NULL and returns this as a value.
97 */
98 void *
99 XtApplyUntilToWidgets (Widget w, XtApplyUntilToWidgetsProc proc, XtPointer arg)
100 {
101 void* result;
102 if (XtIsComposite (w))
103 {
104 CompositeWidget cw = (CompositeWidget)w;
105 int i;
106 for (i = 0; i < cw->composite.num_children; i++)
107 if (XtIsWidget (cw->composite.children [i])){
108 result = proc (cw->composite.children [i], arg);
109 if (result)
110 return result;
111 result = XtApplyUntilToWidgets (cw->composite.children [i], proc,
112 arg);
113 if (result)
114 return result;
115 }
116 }
117 return NULL;
118 }
119
120
121 /*
122 * Returns a copy of the list of all children of a composite widget
123 */
124 Widget *
125 XtCompositeChildren (Widget widget, unsigned int *number)
126 {
127 CompositeWidget cw = (CompositeWidget)widget;
128 Widget* result;
129 int n;
130 int i;
131
132 if (!XtIsComposite (widget))
133 {
134 *number = 0;
135 return NULL;
136 }
137 n = cw->composite.num_children;
138 result = (Widget*)XtMalloc (n * sizeof (Widget));
139 *number = n;
140 for (i = 0; i < n; i++)
141 result [i] = cw->composite.children [i];
142 return result;
143 }
144
145 Boolean
146 XtWidgetBeingDestroyedP (Widget widget)
147 {
148 return widget->core.being_destroyed;
149 }
150
151 void
152 XtSafelyDestroyWidget (Widget widget)
153 {
154 #if 0
155
156 /* this requires IntrinsicI.h (actually, InitialI.h) */
157
158 XtAppContext app = XtWidgetToApplicationContext(widget);
159
160 if (app->dispatch_level == 0)
161 {
162 app->dispatch_level = 1;
163 XtDestroyWidget (widget);
164 /* generates an event so that the event loop will be called */
165 XChangeProperty (XtDisplay (widget), XtWindow (widget),
166 XA_STRING, XA_STRING, 32, PropModeAppend, NULL, 0);
167 app->dispatch_level = 0;
168 }
169 else
170 XtDestroyWidget (widget);
171
172 #else
173 abort ();
174 #endif
175 }
176