Commit | Line | Data |
---|---|---|
07bf635f | 1 | /* Defines some widget utility functions. |
67f02b82 | 2 | |
4424d48a | 3 | Copyright (C) 1992 Lucid, Inc. |
acaf905b | 4 | Copyright (C) 1994, 2001-2012 Free Software Foundation, Inc. |
07bf635f RS |
5 | |
6 | This file is part of the Lucid Widget Library. | |
7 | ||
177c0ea7 | 8 | The Lucid Widget Library is free software; you can redistribute it and/or |
07bf635f RS |
9 | modify it under the terms of the GNU General Public License as published by |
10 | the Free Software Foundation; either version 1, or (at your option) | |
11 | any later version. | |
12 | ||
13 | The Lucid Widget Library is distributed in the hope that it will be useful, | |
177c0ea7 | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
07bf635f RS |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with GNU Emacs; see the file COPYING. If not, write to | |
364c38d3 LK |
20 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
21 | Boston, MA 02110-1301, USA. */ | |
07bf635f | 22 | |
d6c5b98a | 23 | #include <config.h> |
d6c5b98a | 24 | |
d7306fe6 | 25 | #include <setjmp.h> |
67f02b82 | 26 | #include <lisp.h> |
2f96293d | 27 | |
07bf635f RS |
28 | #include <X11/Xatom.h> |
29 | #include <X11/IntrinsicP.h> | |
30 | #include <X11/ObjectP.h> | |
31 | #include "lwlib-utils.h" | |
123c6301 | 32 | #include "lwlib.h" |
07bf635f RS |
33 | |
34 | /* Redisplay the contents of the widget, without first clearing it. */ | |
35 | void | |
c3174d16 | 36 | XtNoClearRefreshWidget (Widget widget) |
07bf635f RS |
37 | { |
38 | XEvent event; | |
39 | ||
40 | event.type = Expose; | |
41 | event.xexpose.serial = 0; | |
42 | event.xexpose.send_event = 0; | |
43 | event.xexpose.display = XtDisplay (widget); | |
44 | event.xexpose.window = XtWindow (widget); | |
45 | event.xexpose.x = 0; | |
46 | event.xexpose.y = 0; | |
47 | event.xexpose.width = widget->core.width; | |
48 | event.xexpose.height = widget->core.height; | |
49 | event.xexpose.count = 0; | |
50 | ||
51 | (*widget->core.widget_class->core_class.expose) | |
52 | (widget, &event, (Region)NULL); | |
53 | } | |
54 | ||
55 | ||
177c0ea7 | 56 | /* |
07bf635f RS |
57 | * Apply a function to all the subwidgets of a given widget recursively. |
58 | */ | |
59 | void | |
c3174d16 | 60 | XtApplyToWidgets (Widget w, XtApplyToWidgetsProc proc, XtPointer arg) |
07bf635f RS |
61 | { |
62 | if (XtIsComposite (w)) | |
63 | { | |
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. | |
67 | */ | |
68 | int nkids = cw->composite.num_children; | |
3370edca | 69 | Widget *kids = (Widget *) xmalloc (sizeof (Widget) * nkids); |
07bf635f | 70 | int i; |
72af86bd AS |
71 | memcpy ((char *) kids, (char *) cw->composite.children, |
72 | sizeof (Widget) * nkids); | |
07bf635f RS |
73 | for (i = 0; i < nkids; i++) |
74 | /* This prevent us from using gadgets, why is it here? */ | |
75 | /* if (XtIsWidget (kids [i])) */ | |
76 | { | |
77 | /* do the kiddies first in case we're destroying */ | |
78 | XtApplyToWidgets (kids [i], proc, arg); | |
79 | proc (kids [i], arg); | |
80 | } | |
81d40c92 | 81 | xfree (kids); |
07bf635f RS |
82 | } |
83 | } | |
84 | ||
85 | ||
86 | /* | |
87 | * Apply a function to all the subwidgets of a given widget recursively. | |
88 | * Stop as soon as the function returns non NULL and returns this as a value. | |
89 | */ | |
90 | void * | |
c3174d16 | 91 | XtApplyUntilToWidgets (Widget w, XtApplyUntilToWidgetsProc proc, XtPointer arg) |
07bf635f RS |
92 | { |
93 | void* result; | |
94 | if (XtIsComposite (w)) | |
95 | { | |
96 | CompositeWidget cw = (CompositeWidget)w; | |
97 | int i; | |
98 | for (i = 0; i < cw->composite.num_children; i++) | |
99 | if (XtIsWidget (cw->composite.children [i])){ | |
100 | result = proc (cw->composite.children [i], arg); | |
101 | if (result) | |
102 | return result; | |
103 | result = XtApplyUntilToWidgets (cw->composite.children [i], proc, | |
104 | arg); | |
105 | if (result) | |
106 | return result; | |
107 | } | |
108 | } | |
109 | return NULL; | |
110 | } | |
111 | ||
112 | ||
113 | /* | |
114 | * Returns a copy of the list of all children of a composite widget | |
115 | */ | |
116 | Widget * | |
c3174d16 | 117 | XtCompositeChildren (Widget widget, unsigned int *number) |
07bf635f RS |
118 | { |
119 | CompositeWidget cw = (CompositeWidget)widget; | |
120 | Widget* result; | |
121 | int n; | |
122 | int i; | |
123 | ||
124 | if (!XtIsComposite (widget)) | |
125 | { | |
126 | *number = 0; | |
127 | return NULL; | |
128 | } | |
129 | n = cw->composite.num_children; | |
b165261a | 130 | result = (Widget*)(void*)XtMalloc (n * sizeof (Widget)); |
07bf635f RS |
131 | *number = n; |
132 | for (i = 0; i < n; i++) | |
133 | result [i] = cw->composite.children [i]; | |
134 | return result; | |
135 | } | |
136 | ||
137 | Boolean | |
c3174d16 | 138 | XtWidgetBeingDestroyedP (Widget widget) |
07bf635f RS |
139 | { |
140 | return widget->core.being_destroyed; | |
141 | } |