annotate lwlib/lwlib-utils.c @ 7281:d14d537ce03c

(${archlibdir}): Be lenient about wc output format.
author Karl Heuer <kwzh@gnu.org>
date Mon, 02 May 1994 20:56:25 +0000
parents 4870efc489ea
children 4a5d0d109242
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5626
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 /* Defines some widget utility functions.
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2 Copyright (C) 1992 Lucid, Inc.
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4 This file is part of the Lucid Widget Library.
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 The Lucid Widget Library is free software; you can redistribute it and/or
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 modify it under the terms of the GNU General Public License as published by
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 the Free Software Foundation; either version 1, or (at your option)
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 any later version.
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 The Lucid Widget Library is distributed in the hope that it will be useful,
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 GNU General Public License for more details.
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 along with GNU Emacs; see the file COPYING. If not, write to
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 #include <stdlib.h>
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 #include <unistd.h>
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 #include <string.h>
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 #include <memory.h>
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 #include <X11/Xatom.h>
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 #include <X11/IntrinsicP.h>
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 #include <X11/ObjectP.h>
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 #include "lwlib-utils.h"
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 /* Redisplay the contents of the widget, without first clearing it. */
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 void
5708
4870efc489ea *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 5626
diff changeset
32 XtNoClearRefreshWidget (widget)
4870efc489ea *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 5626
diff changeset
33 Widget widget;
5626
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 {
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 XEvent event;
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 event.type = Expose;
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 event.xexpose.serial = 0;
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 event.xexpose.send_event = 0;
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 event.xexpose.display = XtDisplay (widget);
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 event.xexpose.window = XtWindow (widget);
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 event.xexpose.x = 0;
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 event.xexpose.y = 0;
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 event.xexpose.width = widget->core.width;
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 event.xexpose.height = widget->core.height;
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 event.xexpose.count = 0;
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 (*widget->core.widget_class->core_class.expose)
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 (widget, &event, (Region)NULL);
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 }
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 /*
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 * Apply a function to all the subwidgets of a given widget recursively.
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 */
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 void
5708
4870efc489ea *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 5626
diff changeset
57 XtApplyToWidgets (w, proc, arg)
4870efc489ea *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 5626
diff changeset
58 Widget w;
4870efc489ea *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 5626
diff changeset
59 XtApplyToWidgetsProc proc;
4870efc489ea *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 5626
diff changeset
60 XtPointer arg;
5626
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 {
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 if (XtIsComposite (w))
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 {
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 CompositeWidget cw = (CompositeWidget) w;
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 /* We have to copy the children list before mapping over it, because
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 the procedure might add/delete elements, which would lose badly.
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 */
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 int nkids = cw->composite.num_children;
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 Widget *kids = (Widget *) malloc (sizeof (Widget) * nkids);
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 int i;
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 memcpy (kids, cw->composite.children, sizeof (Widget) * nkids);
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 for (i = 0; i < nkids; i++)
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 /* This prevent us from using gadgets, why is it here? */
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 /* if (XtIsWidget (kids [i])) */
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 {
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 /* do the kiddies first in case we're destroying */
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 XtApplyToWidgets (kids [i], proc, arg);
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 proc (kids [i], arg);
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 }
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 free (kids);
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 }
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 }
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 /*
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 * Apply a function to all the subwidgets of a given widget recursively.
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 * Stop as soon as the function returns non NULL and returns this as a value.
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 */
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 void *
5708
4870efc489ea *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 5626
diff changeset
90 XtApplyUntilToWidgets (w, proc, arg)
4870efc489ea *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 5626
diff changeset
91 Widget w;
4870efc489ea *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 5626
diff changeset
92 XtApplyUntilToWidgetsProc proc;
4870efc489ea *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 5626
diff changeset
93 XtPointer arg;
5626
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 {
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 void* result;
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 if (XtIsComposite (w))
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 {
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 CompositeWidget cw = (CompositeWidget)w;
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 int i;
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 for (i = 0; i < cw->composite.num_children; i++)
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 if (XtIsWidget (cw->composite.children [i])){
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 result = proc (cw->composite.children [i], arg);
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 if (result)
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 return result;
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 result = XtApplyUntilToWidgets (cw->composite.children [i], proc,
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 arg);
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 if (result)
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 return result;
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 }
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 }
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 return NULL;
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 }
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 /*
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 * Returns a copy of the list of all children of a composite widget
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 */
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 Widget *
5708
4870efc489ea *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 5626
diff changeset
119 XtCompositeChildren (widget, number)
4870efc489ea *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 5626
diff changeset
120 Widget widget;
4870efc489ea *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 5626
diff changeset
121 unsigned int* number;
5626
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 {
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 CompositeWidget cw = (CompositeWidget)widget;
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 Widget* result;
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 int n;
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 int i;
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 if (!XtIsComposite (widget))
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 {
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 *number = 0;
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 return NULL;
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 }
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 n = cw->composite.num_children;
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 result = (Widget*)XtMalloc (n * sizeof (Widget));
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 *number = n;
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 for (i = 0; i < n; i++)
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 result [i] = cw->composite.children [i];
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 return result;
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 }
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 Boolean
5708
4870efc489ea *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 5626
diff changeset
142 XtWidgetBeingDestroyedP (widget)
4870efc489ea *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 5626
diff changeset
143 Widget widget;
5626
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 {
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 return widget->core.being_destroyed;
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 }
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 void
5708
4870efc489ea *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 5626
diff changeset
149 XtSafelyDestroyWidget (widget)
4870efc489ea *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 5626
diff changeset
150 Widget widget;
5626
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 {
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 #if 0
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 /* this requires IntrinsicI.h (actually, InitialI.h) */
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 XtAppContext app = XtWidgetToApplicationContext(widget);
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 if (app->dispatch_level == 0)
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 {
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 app->dispatch_level = 1;
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 XtDestroyWidget (widget);
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 /* generates an event so that the event loop will be called */
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 XChangeProperty (XtDisplay (widget), XtWindow (widget),
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 XA_STRING, XA_STRING, 32, PropModeAppend, NULL, 0);
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 app->dispatch_level = 0;
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 }
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 else
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 XtDestroyWidget (widget);
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 #else
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 abort ();
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 #endif
93bb7e0935ba Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 }