1 /* Defines some widget utility functions.
3 Copyright (C) 1992 Lucid, Inc.
4 Copyright (C) 1994, 2001-2017 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. If not, see <https://www.gnu.org/licenses/>. */
26 #include <X11/Xatom.h>
27 #include <X11/IntrinsicP.h>
28 #include <X11/ObjectP.h>
29 #include "lwlib-utils.h"
32 /* Redisplay the contents of the widget, without first clearing it. */
34 XtNoClearRefreshWidget (Widget widget
)
39 event
.xexpose
.serial
= 0;
40 event
.xexpose
.send_event
= 0;
41 event
.xexpose
.display
= XtDisplay (widget
);
42 event
.xexpose
.window
= XtWindow (widget
);
45 event
.xexpose
.width
= widget
->core
.width
;
46 event
.xexpose
.height
= widget
->core
.height
;
47 event
.xexpose
.count
= 0;
49 (*widget
->core
.widget_class
->core_class
.expose
)
50 (widget
, &event
, (Region
)NULL
);
55 * Apply a function to all the subwidgets of a given widget recursively.
58 XtApplyToWidgets (Widget w
, XtApplyToWidgetsProc proc
, XtPointer arg
)
60 if (XtIsComposite (w
))
62 CompositeWidget cw
= (CompositeWidget
) w
;
63 /* We have to copy the children list before mapping over it, because
64 the procedure might add/delete elements, which would lose badly.
66 int nkids
= cw
->composite
.num_children
;
67 Widget
*kids
= (Widget
*) xmalloc (sizeof (Widget
) * nkids
);
69 memcpy ((char *) kids
, (char *) cw
->composite
.children
,
70 sizeof (Widget
) * nkids
);
71 for (i
= 0; i
< nkids
; i
++)
72 /* This prevent us from using gadgets, why is it here? */
73 /* if (XtIsWidget (kids [i])) */
75 /* do the kiddies first in case we're destroying */
76 XtApplyToWidgets (kids
[i
], proc
, arg
);
85 * Apply a function to all the subwidgets of a given widget recursively.
86 * Stop as soon as the function returns non NULL and returns this as a value.
89 XtApplyUntilToWidgets (Widget w
, XtApplyUntilToWidgetsProc proc
, XtPointer arg
)
92 if (XtIsComposite (w
))
94 CompositeWidget cw
= (CompositeWidget
)w
;
96 for (i
= 0; i
< cw
->composite
.num_children
; i
++)
97 if (XtIsWidget (cw
->composite
.children
[i
])){
98 result
= proc (cw
->composite
.children
[i
], arg
);
101 result
= XtApplyUntilToWidgets (cw
->composite
.children
[i
], proc
,
112 * Returns a copy of the list of all children of a composite widget
115 XtCompositeChildren (Widget widget
, unsigned int *number
)
117 CompositeWidget cw
= (CompositeWidget
)widget
;
122 if (!XtIsComposite (widget
))
127 n
= cw
->composite
.num_children
;
128 result
= (Widget
*)(void*)XtMalloc (n
* sizeof (Widget
));
130 for (i
= 0; i
< n
; i
++)
131 result
[i
] = cw
->composite
.children
[i
];
136 XtWidgetBeingDestroyedP (Widget widget
)
138 return widget
->core
.being_destroyed
;