Rudimentary support for vc-pull and vc-merge in Git and Mercurial.
[emacs.git] / lwlib / lwlib-utils.c
blob4e095d33fad5a55e227540e1df640fcd49380857
1 /* Defines some widget utility functions.
2 Copyright (C) 1992 Lucid, Inc.
3 Copyright (C) 1994, 2001-2011 Free Software Foundation, Inc.
5 This file is part of the Lucid Widget Library.
7 The Lucid Widget Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 1, or (at your option)
10 any later version.
12 The Lucid Widget Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
26 /* Definitions of these in config.h can cause
27 declaration conflicts later on between declarations for index
28 and declarations for strchr. This file doesn't use
29 index and rindex, so cancel them. */
30 #undef index
31 #undef rindex
33 #include <setjmp.h>
34 #include "../src/lisp.h"
36 #include <X11/Xatom.h>
37 #include <X11/IntrinsicP.h>
38 #include <X11/ObjectP.h>
39 #include "lwlib-utils.h"
40 #include "lwlib.h"
42 /* Redisplay the contents of the widget, without first clearing it. */
43 void
44 XtNoClearRefreshWidget (Widget widget)
46 XEvent event;
48 event.type = Expose;
49 event.xexpose.serial = 0;
50 event.xexpose.send_event = 0;
51 event.xexpose.display = XtDisplay (widget);
52 event.xexpose.window = XtWindow (widget);
53 event.xexpose.x = 0;
54 event.xexpose.y = 0;
55 event.xexpose.width = widget->core.width;
56 event.xexpose.height = widget->core.height;
57 event.xexpose.count = 0;
59 (*widget->core.widget_class->core_class.expose)
60 (widget, &event, (Region)NULL);
65 * Apply a function to all the subwidgets of a given widget recursively.
67 void
68 XtApplyToWidgets (Widget w, XtApplyToWidgetsProc proc, XtPointer arg)
70 if (XtIsComposite (w))
72 CompositeWidget cw = (CompositeWidget) w;
73 /* We have to copy the children list before mapping over it, because
74 the procedure might add/delete elements, which would lose badly.
76 int nkids = cw->composite.num_children;
77 Widget *kids = (Widget *) malloc (sizeof (Widget) * nkids);
78 int i;
79 memcpy ((char *) kids, (char *) cw->composite.children,
80 sizeof (Widget) * nkids);
81 for (i = 0; i < nkids; i++)
82 /* This prevent us from using gadgets, why is it here? */
83 /* if (XtIsWidget (kids [i])) */
85 /* do the kiddies first in case we're destroying */
86 XtApplyToWidgets (kids [i], proc, arg);
87 proc (kids [i], arg);
89 free (kids);
95 * Apply a function to all the subwidgets of a given widget recursively.
96 * Stop as soon as the function returns non NULL and returns this as a value.
98 void *
99 XtApplyUntilToWidgets (Widget w, XtApplyUntilToWidgetsProc proc, XtPointer arg)
101 void* result;
102 if (XtIsComposite (w))
104 CompositeWidget cw = (CompositeWidget)w;
105 int i;
106 for (i = 0; i < cw->composite.num_children; i++)
107 if (XtIsWidget (cw->composite.children [i])){
108 result = proc (cw->composite.children [i], arg);
109 if (result)
110 return result;
111 result = XtApplyUntilToWidgets (cw->composite.children [i], proc,
112 arg);
113 if (result)
114 return result;
117 return NULL;
122 * Returns a copy of the list of all children of a composite widget
124 Widget *
125 XtCompositeChildren (Widget widget, unsigned int *number)
127 CompositeWidget cw = (CompositeWidget)widget;
128 Widget* result;
129 int n;
130 int i;
132 if (!XtIsComposite (widget))
134 *number = 0;
135 return NULL;
137 n = cw->composite.num_children;
138 result = (Widget*)XtMalloc (n * sizeof (Widget));
139 *number = n;
140 for (i = 0; i < n; i++)
141 result [i] = cw->composite.children [i];
142 return result;
145 Boolean
146 XtWidgetBeingDestroyedP (Widget widget)
148 return widget->core.being_destroyed;
151 void
152 XtSafelyDestroyWidget (Widget widget)
154 #if 0
156 /* this requires IntrinsicI.h (actually, InitialI.h) */
158 XtAppContext app = XtWidgetToApplicationContext(widget);
160 if (app->dispatch_level == 0)
162 app->dispatch_level = 1;
163 XtDestroyWidget (widget);
164 /* generates an event so that the event loop will be called */
165 XChangeProperty (XtDisplay (widget), XtWindow (widget),
166 XA_STRING, XA_STRING, 32, PropModeAppend, NULL, 0);
167 app->dispatch_level = 0;
169 else
170 XtDestroyWidget (widget);
172 #else
173 abort ();
174 #endif