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. */
20 #include <X11/Xatom.h>
21 #include <X11/IntrinsicP.h>
22 #include <X11/ObjectP.h>
23 #include "lwlib-utils.h"
25 /* Redisplay the contents of the widget, without first clearing it. */
27 XtNoClearRefreshWidget (widget
)
33 event
.xexpose
.serial
= 0;
34 event
.xexpose
.send_event
= 0;
35 event
.xexpose
.display
= XtDisplay (widget
);
36 event
.xexpose
.window
= XtWindow (widget
);
39 event
.xexpose
.width
= widget
->core
.width
;
40 event
.xexpose
.height
= widget
->core
.height
;
41 event
.xexpose
.count
= 0;
43 (*widget
->core
.widget_class
->core_class
.expose
)
44 (widget
, &event
, (Region
)NULL
);
49 * Apply a function to all the subwidgets of a given widget recursively.
52 XtApplyToWidgets (w
, proc
, arg
)
54 XtApplyToWidgetsProc proc
;
57 if (XtIsComposite (w
))
59 CompositeWidget cw
= (CompositeWidget
) w
;
60 /* We have to copy the children list before mapping over it, because
61 the procedure might add/delete elements, which would lose badly.
63 int nkids
= cw
->composite
.num_children
;
64 Widget
*kids
= (Widget
*) malloc (sizeof (Widget
) * nkids
);
66 lwlib_bcopy (cw
->composite
.children
, kids
, sizeof (Widget
) * nkids
);
67 for (i
= 0; i
< nkids
; i
++)
68 /* This prevent us from using gadgets, why is it here? */
69 /* if (XtIsWidget (kids [i])) */
71 /* do the kiddies first in case we're destroying */
72 XtApplyToWidgets (kids
[i
], proc
, arg
);
81 * Apply a function to all the subwidgets of a given widget recursively.
82 * Stop as soon as the function returns non NULL and returns this as a value.
85 XtApplyUntilToWidgets (w
, proc
, arg
)
87 XtApplyUntilToWidgetsProc proc
;
91 if (XtIsComposite (w
))
93 CompositeWidget cw
= (CompositeWidget
)w
;
95 for (i
= 0; i
< cw
->composite
.num_children
; i
++)
96 if (XtIsWidget (cw
->composite
.children
[i
])){
97 result
= proc (cw
->composite
.children
[i
], arg
);
100 result
= XtApplyUntilToWidgets (cw
->composite
.children
[i
], proc
,
111 * Returns a copy of the list of all children of a composite widget
114 XtCompositeChildren (widget
, number
)
116 unsigned int* number
;
118 CompositeWidget cw
= (CompositeWidget
)widget
;
123 if (!XtIsComposite (widget
))
128 n
= cw
->composite
.num_children
;
129 result
= (Widget
*)XtMalloc (n
* sizeof (Widget
));
131 for (i
= 0; i
< n
; i
++)
132 result
[i
] = cw
->composite
.children
[i
];
137 XtWidgetBeingDestroyedP (widget
)
140 return widget
->core
.being_destroyed
;
144 XtSafelyDestroyWidget (widget
)
149 /* this requires IntrinsicI.h (actually, InitialI.h) */
151 XtAppContext app
= XtWidgetToApplicationContext(widget
);
153 if (app
->dispatch_level
== 0)
155 app
->dispatch_level
= 1;
156 XtDestroyWidget (widget
);
157 /* generates an event so that the event loop will be called */
158 XChangeProperty (XtDisplay (widget
), XtWindow (widget
),
159 XA_STRING
, XA_STRING
, 32, PropModeAppend
, NULL
, 0);
160 app
->dispatch_level
= 0;
163 XtDestroyWidget (widget
);