* net/tramp-compat.el (tramp-compat-temporary-file-directory):
[emacs.git] / lwlib / lwlib-utils.c
blob9286691639f88e1652b5247450adf2ead3d1780f
1 /* Defines some widget utility functions.
3 Copyright (C) 1992 Lucid, Inc.
4 Copyright (C) 1994, 2001-2012 Free Software Foundation, Inc.
6 This file is part of the Lucid Widget Library.
8 The Lucid Widget Library is free software; you can redistribute it and/or
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.
13 The Lucid Widget Library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
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
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
27 #include <setjmp.h>
28 #include <lisp.h>
30 #include <X11/Xatom.h>
31 #include <X11/IntrinsicP.h>
32 #include <X11/ObjectP.h>
33 #include "lwlib-utils.h"
34 #include "lwlib.h"
36 /* Redisplay the contents of the widget, without first clearing it. */
37 void
38 XtNoClearRefreshWidget (Widget widget)
40 XEvent event;
42 event.type = Expose;
43 event.xexpose.serial = 0;
44 event.xexpose.send_event = 0;
45 event.xexpose.display = XtDisplay (widget);
46 event.xexpose.window = XtWindow (widget);
47 event.xexpose.x = 0;
48 event.xexpose.y = 0;
49 event.xexpose.width = widget->core.width;
50 event.xexpose.height = widget->core.height;
51 event.xexpose.count = 0;
53 (*widget->core.widget_class->core_class.expose)
54 (widget, &event, (Region)NULL);
59 * Apply a function to all the subwidgets of a given widget recursively.
61 void
62 XtApplyToWidgets (Widget w, XtApplyToWidgetsProc proc, XtPointer arg)
64 if (XtIsComposite (w))
66 CompositeWidget cw = (CompositeWidget) w;
67 /* We have to copy the children list before mapping over it, because
68 the procedure might add/delete elements, which would lose badly.
70 int nkids = cw->composite.num_children;
71 Widget *kids = (Widget *) xmalloc (sizeof (Widget) * nkids);
72 int i;
73 memcpy ((char *) kids, (char *) cw->composite.children,
74 sizeof (Widget) * nkids);
75 for (i = 0; i < nkids; i++)
76 /* This prevent us from using gadgets, why is it here? */
77 /* if (XtIsWidget (kids [i])) */
79 /* do the kiddies first in case we're destroying */
80 XtApplyToWidgets (kids [i], proc, arg);
81 proc (kids [i], arg);
83 xfree (kids);
89 * Apply a function to all the subwidgets of a given widget recursively.
90 * Stop as soon as the function returns non NULL and returns this as a value.
92 void *
93 XtApplyUntilToWidgets (Widget w, XtApplyUntilToWidgetsProc proc, 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 widget, unsigned int *number)
121 CompositeWidget cw = (CompositeWidget)widget;
122 Widget* result;
123 int n;
124 int i;
126 if (!XtIsComposite (widget))
128 *number = 0;
129 return NULL;
131 n = cw->composite.num_children;
132 result = (Widget*)(void*)XtMalloc (n * sizeof (Widget));
133 *number = n;
134 for (i = 0; i < n; i++)
135 result [i] = cw->composite.children [i];
136 return result;
139 Boolean
140 XtWidgetBeingDestroyedP (Widget widget)
142 return widget->core.being_destroyed;