1 /* Defines some widget utility functions.
2 Copyright (C) 1992 Lucid, Inc.
3 Copyright (C) 1994, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
4 2010, 2011 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)
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. */
27 /* Definitions of these in config.h can cause
28 declaration conflicts later on between declarations for index
29 and declarations for strchr. This file doesn't use
30 index and rindex, so cancel them. */
35 #include "../src/lisp.h"
37 #include <X11/Xatom.h>
38 #include <X11/IntrinsicP.h>
39 #include <X11/ObjectP.h>
40 #include "lwlib-utils.h"
43 /* Redisplay the contents of the widget, without first clearing it. */
45 XtNoClearRefreshWidget (widget
)
51 event
.xexpose
.serial
= 0;
52 event
.xexpose
.send_event
= 0;
53 event
.xexpose
.display
= XtDisplay (widget
);
54 event
.xexpose
.window
= XtWindow (widget
);
57 event
.xexpose
.width
= widget
->core
.width
;
58 event
.xexpose
.height
= widget
->core
.height
;
59 event
.xexpose
.count
= 0;
61 (*widget
->core
.widget_class
->core_class
.expose
)
62 (widget
, &event
, (Region
)NULL
);
67 * Apply a function to all the subwidgets of a given widget recursively.
70 XtApplyToWidgets (w
, proc
, arg
)
72 XtApplyToWidgetsProc proc
;
75 if (XtIsComposite (w
))
77 CompositeWidget cw
= (CompositeWidget
) w
;
78 /* We have to copy the children list before mapping over it, because
79 the procedure might add/delete elements, which would lose badly.
81 int nkids
= cw
->composite
.num_children
;
82 Widget
*kids
= (Widget
*) malloc (sizeof (Widget
) * nkids
);
84 lwlib_bcopy ((char *) cw
->composite
.children
, (char *) kids
,
85 sizeof (Widget
) * nkids
);
86 for (i
= 0; i
< nkids
; i
++)
87 /* This prevent us from using gadgets, why is it here? */
88 /* if (XtIsWidget (kids [i])) */
90 /* do the kiddies first in case we're destroying */
91 XtApplyToWidgets (kids
[i
], proc
, arg
);
100 * Apply a function to all the subwidgets of a given widget recursively.
101 * Stop as soon as the function returns non NULL and returns this as a value.
104 XtApplyUntilToWidgets (w
, proc
, arg
)
106 XtApplyUntilToWidgetsProc proc
;
110 if (XtIsComposite (w
))
112 CompositeWidget cw
= (CompositeWidget
)w
;
114 for (i
= 0; i
< cw
->composite
.num_children
; i
++)
115 if (XtIsWidget (cw
->composite
.children
[i
])){
116 result
= proc (cw
->composite
.children
[i
], arg
);
119 result
= XtApplyUntilToWidgets (cw
->composite
.children
[i
], proc
,
130 * Returns a copy of the list of all children of a composite widget
133 XtCompositeChildren (widget
, number
)
135 unsigned int* number
;
137 CompositeWidget cw
= (CompositeWidget
)widget
;
142 if (!XtIsComposite (widget
))
147 n
= cw
->composite
.num_children
;
148 result
= (Widget
*)XtMalloc (n
* sizeof (Widget
));
150 for (i
= 0; i
< n
; i
++)
151 result
[i
] = cw
->composite
.children
[i
];
156 XtWidgetBeingDestroyedP (widget
)
159 return widget
->core
.being_destroyed
;
163 XtSafelyDestroyWidget (widget
)
168 /* this requires IntrinsicI.h (actually, InitialI.h) */
170 XtAppContext app
= XtWidgetToApplicationContext(widget
);
172 if (app
->dispatch_level
== 0)
174 app
->dispatch_level
= 1;
175 XtDestroyWidget (widget
);
176 /* generates an event so that the event loop will be called */
177 XChangeProperty (XtDisplay (widget
), XtWindow (widget
),
178 XA_STRING
, XA_STRING
, 32, PropModeAppend
, NULL
, 0);
179 app
->dispatch_level
= 0;
182 XtDestroyWidget (widget
);
189 /* arch-tag: f21f0a1f-2a4e-44e1-8715-7f234fe2d159
190 (do not change this comment) */