0
|
1 /* Defines some widget utility functions.
|
|
2 Copyright (C) 1992 Lucid, Inc.
|
|
3
|
|
4 This file is part of the Lucid Widget Library.
|
|
5
|
|
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.
|
|
10
|
|
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.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
80
|
17 along with XEmacs; see the file COPYING. If not, write to
|
78
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
80
|
19 Boston, MA 02111-1307, USA. */
|
0
|
20
|
|
21 #include <stdlib.h>
|
|
22 #include <unistd.h>
|
|
23 #include <string.h>
|
|
24 #include <memory.h>
|
|
25
|
|
26 #include <X11/Xatom.h>
|
|
27 #include <X11/IntrinsicP.h>
|
|
28 #include <X11/ObjectP.h>
|
|
29 #include "lwlib-utils.h"
|
|
30
|
|
31 /* Redisplay the contents of the widget, without first clearing it. */
|
|
32 void
|
|
33 XtNoClearRefreshWidget (Widget widget)
|
|
34 {
|
|
35 XEvent event;
|
|
36
|
|
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;
|
|
47
|
|
48 (*widget->core.widget_class->core_class.expose)
|
|
49 (widget, &event, (Region)NULL);
|
|
50 }
|
|
51
|
|
52
|
|
53 /*
|
|
54 * Apply a function to all the subwidgets of a given widget recursively.
|
|
55 */
|
|
56 void
|
|
57 XtApplyToWidgets (Widget w, XtApplyToWidgetsProc proc, XtPointer arg)
|
|
58 {
|
|
59 if (XtIsComposite (w))
|
|
60 {
|
|
61 CompositeWidget cw = (CompositeWidget) w;
|
|
62 /* We have to copy the children list before mapping over it, because
|
|
63 the procedure might add/delete elements, which would lose badly.
|
|
64 */
|
|
65 int nkids = cw->composite.num_children;
|
|
66 Widget *kids = (Widget *) malloc (sizeof (Widget) * nkids);
|
|
67 int i;
|
|
68 memcpy (kids, cw->composite.children, sizeof (Widget) * nkids);
|
|
69 for (i = 0; i < nkids; i++)
|
|
70 /* This prevent us from using gadgets, why is it here? */
|
|
71 /* if (XtIsWidget (kids [i])) */
|
|
72 {
|
|
73 /* do the kiddies first in case we're destroying */
|
|
74 XtApplyToWidgets (kids [i], proc, arg);
|
|
75 proc (kids [i], arg);
|
|
76 }
|
|
77 free (kids);
|
|
78 }
|
|
79 }
|
|
80
|
|
81
|
|
82 /*
|
|
83 * Apply a function to all the subwidgets of a given widget recursively.
|
|
84 * Stop as soon as the function returns non NULL and returns this as a value.
|
|
85 */
|
|
86 void *
|
|
87 XtApplyUntilToWidgets (Widget w, XtApplyUntilToWidgetsProc proc, XtPointer arg)
|
|
88 {
|
|
89 void* result;
|
|
90 if (XtIsComposite (w))
|
|
91 {
|
|
92 CompositeWidget cw = (CompositeWidget)w;
|
|
93 int i;
|
|
94 for (i = 0; i < cw->composite.num_children; i++)
|
|
95 if (XtIsWidget (cw->composite.children [i])){
|
|
96 result = proc (cw->composite.children [i], arg);
|
|
97 if (result)
|
|
98 return result;
|
|
99 result = XtApplyUntilToWidgets (cw->composite.children [i], proc,
|
|
100 arg);
|
|
101 if (result)
|
|
102 return result;
|
|
103 }
|
|
104 }
|
|
105 return NULL;
|
|
106 }
|
|
107
|
|
108
|
|
109 /*
|
|
110 * Returns a copy of the list of all children of a composite widget
|
|
111 */
|
|
112 Widget *
|
|
113 XtCompositeChildren (Widget widget, unsigned int* number)
|
|
114 {
|
|
115 CompositeWidget cw = (CompositeWidget)widget;
|
|
116 Widget* result;
|
|
117 int n;
|
|
118 int i;
|
|
119
|
|
120 if (!XtIsComposite (widget))
|
|
121 {
|
|
122 *number = 0;
|
|
123 return NULL;
|
|
124 }
|
|
125 n = cw->composite.num_children;
|
|
126 result = (Widget*)XtMalloc (n * sizeof (Widget));
|
|
127 *number = n;
|
|
128 for (i = 0; i < n; i++)
|
|
129 result [i] = cw->composite.children [i];
|
|
130 return result;
|
|
131 }
|
|
132
|
|
133 Boolean
|
|
134 XtWidgetBeingDestroyedP (Widget widget)
|
|
135 {
|
|
136 return widget->core.being_destroyed;
|
|
137 }
|
|
138
|
|
139 void
|
|
140 XtSafelyDestroyWidget (Widget widget)
|
|
141 {
|
|
142 #if 0
|
|
143
|
|
144 /* this requires IntrinsicI.h (actually, InitialI.h) */
|
|
145
|
|
146 XtAppContext app = XtWidgetToApplicationContext(widget);
|
|
147
|
|
148 if (app->dispatch_level == 0)
|
|
149 {
|
|
150 app->dispatch_level = 1;
|
|
151 XtDestroyWidget (widget);
|
|
152 /* generates an event so that the event loop will be called */
|
|
153 XChangeProperty (XtDisplay (widget), XtWindow (widget),
|
|
154 XA_STRING, XA_STRING, 32, PropModeAppend, NULL, 0);
|
|
155 app->dispatch_level = 0;
|
|
156 }
|
|
157 else
|
|
158 XtDestroyWidget (widget);
|
|
159
|
|
160 #else
|
|
161 abort ();
|
|
162 #endif
|
|
163 }
|