Add a bit more about profiling to the lispref
[emacs.git] / lwlib / lwlib-utils.c
blob65cda72fdd803cd2d292356e65f22314e4ef02a4
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 #include <config.h>
25 #include <setjmp.h>
26 #include <lisp.h>
28 #include <X11/Xatom.h>
29 #include <X11/IntrinsicP.h>
30 #include <X11/ObjectP.h>
31 #include "lwlib-utils.h"
32 #include "lwlib.h"
34 /* Redisplay the contents of the widget, without first clearing it. */
35 void
36 XtNoClearRefreshWidget (Widget widget)
38 XEvent event;
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;
51 (*widget->core.widget_class->core_class.expose)
52 (widget, &event, (Region)NULL);
57 * Apply a function to all the subwidgets of a given widget recursively.
59 void
60 XtApplyToWidgets (Widget w, XtApplyToWidgetsProc proc, XtPointer arg)
62 if (XtIsComposite (w))
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.
68 int nkids = cw->composite.num_children;
69 Widget *kids = (Widget *) xmalloc (sizeof (Widget) * nkids);
70 int i;
71 memcpy ((char *) kids, (char *) cw->composite.children,
72 sizeof (Widget) * nkids);
73 for (i = 0; i < nkids; i++)
74 /* This prevent us from using gadgets, why is it here? */
75 /* if (XtIsWidget (kids [i])) */
77 /* do the kiddies first in case we're destroying */
78 XtApplyToWidgets (kids [i], proc, arg);
79 proc (kids [i], arg);
81 xfree (kids);
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.
90 void *
91 XtApplyUntilToWidgets (Widget w, XtApplyUntilToWidgetsProc proc, XtPointer arg)
93 void* result;
94 if (XtIsComposite (w))
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;
109 return NULL;
114 * Returns a copy of the list of all children of a composite widget
116 Widget *
117 XtCompositeChildren (Widget widget, unsigned int *number)
119 CompositeWidget cw = (CompositeWidget)widget;
120 Widget* result;
121 int n;
122 int i;
124 if (!XtIsComposite (widget))
126 *number = 0;
127 return NULL;
129 n = cw->composite.num_children;
130 result = (Widget*)(void*)XtMalloc (n * sizeof (Widget));
131 *number = n;
132 for (i = 0; i < n; i++)
133 result [i] = cw->composite.children [i];
134 return result;
137 Boolean
138 XtWidgetBeingDestroyedP (Widget widget)
140 return widget->core.being_destroyed;