1 /* Defines some widget utility functions.
2 Copyright (C) 1992 Lucid, Inc.
4 This file is part of the Lucid Widget Library.
6 The Lucid Widget Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 1, or (at your option)
11 The Lucid Widget Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
25 #include <X11/Xatom.h>
26 #include <X11/IntrinsicP.h>
27 #include <X11/ObjectP.h>
28 #include "lwlib-utils.h"
30 /* Redisplay the contents of the widget, without first clearing it. */
32 XtNoClearRefreshWidget (widget
)
38 event
.xexpose
.serial
= 0;
39 event
.xexpose
.send_event
= 0;
40 event
.xexpose
.display
= XtDisplay (widget
);
41 event
.xexpose
.window
= XtWindow (widget
);
44 event
.xexpose
.width
= widget
->core
.width
;
45 event
.xexpose
.height
= widget
->core
.height
;
46 event
.xexpose
.count
= 0;
48 (*widget
->core
.widget_class
->core_class
.expose
)
49 (widget
, &event
, (Region
)NULL
);
54 * Apply a function to all the subwidgets of a given widget recursively.
57 XtApplyToWidgets (w
, proc
, arg
)
59 XtApplyToWidgetsProc proc
;
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
*) malloc (sizeof (Widget
) * nkids
);
71 memcpy (kids
, cw
->composite
.children
, sizeof (Widget
) * nkids
);
72 for (i
= 0; i
< nkids
; i
++)
73 /* This prevent us from using gadgets, why is it here? */
74 /* if (XtIsWidget (kids [i])) */
76 /* do the kiddies first in case we're destroying */
77 XtApplyToWidgets (kids
[i
], proc
, arg
);
86 * Apply a function to all the subwidgets of a given widget recursively.
87 * Stop as soon as the function returns non NULL and returns this as a value.
90 XtApplyUntilToWidgets (w
, proc
, arg
)
92 XtApplyUntilToWidgetsProc proc
;
96 if (XtIsComposite (w
))
98 CompositeWidget cw
= (CompositeWidget
)w
;
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
);
105 result
= XtApplyUntilToWidgets (cw
->composite
.children
[i
], proc
,
116 * Returns a copy of the list of all children of a composite widget
119 XtCompositeChildren (widget
, number
)
121 unsigned int* number
;
123 CompositeWidget cw
= (CompositeWidget
)widget
;
128 if (!XtIsComposite (widget
))
133 n
= cw
->composite
.num_children
;
134 result
= (Widget
*)XtMalloc (n
* sizeof (Widget
));
136 for (i
= 0; i
< n
; i
++)
137 result
[i
] = cw
->composite
.children
[i
];
142 XtWidgetBeingDestroyedP (widget
)
145 return widget
->core
.being_destroyed
;
149 XtSafelyDestroyWidget (widget
)
154 /* this requires IntrinsicI.h (actually, InitialI.h) */
156 XtAppContext app
= XtWidgetToApplicationContext(widget
);
158 if (app
->dispatch_level
== 0)
160 app
->dispatch_level
= 1;
161 XtDestroyWidget (widget
);
162 /* generates an event so that the event loop will be called */
163 XChangeProperty (XtDisplay (widget
), XtWindow (widget
),
164 XA_STRING
, XA_STRING
, 32, PropModeAppend
, NULL
, 0);
165 app
->dispatch_level
= 0;
168 XtDestroyWidget (widget
);