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)
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. */
28 #include <X11/Xatom.h>
29 #include <X11/IntrinsicP.h>
30 #include <X11/ObjectP.h>
31 #include "lwlib-utils.h"
34 /* Redisplay the contents of the widget, without first clearing it. */
36 XtNoClearRefreshWidget (Widget widget
)
41 event
.xexpose
.serial
= 0;
42 event
.xexpose
.send_event
= 0;
43 event
.xexpose
.display
= XtDisplay (widget
);
44 event
.xexpose
.window
= XtWindow (widget
);
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.
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
);
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
);
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.
91 XtApplyUntilToWidgets (Widget w
, XtApplyUntilToWidgetsProc proc
, XtPointer arg
)
94 if (XtIsComposite (w
))
96 CompositeWidget cw
= (CompositeWidget
)w
;
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
);
103 result
= XtApplyUntilToWidgets (cw
->composite
.children
[i
], proc
,
114 * Returns a copy of the list of all children of a composite widget
117 XtCompositeChildren (Widget widget
, unsigned int *number
)
119 CompositeWidget cw
= (CompositeWidget
)widget
;
124 if (!XtIsComposite (widget
))
129 n
= cw
->composite
.num_children
;
130 result
= (Widget
*)(void*)XtMalloc (n
* sizeof (Widget
));
132 for (i
= 0; i
< n
; i
++)
133 result
[i
] = cw
->composite
.children
[i
];
138 XtWidgetBeingDestroyedP (Widget widget
)
140 return widget
->core
.being_destroyed
;