1 /* Defines some widget utility functions.
3 Copyright (C) 1992 Lucid, Inc.
4 Copyright (C) 1994, 2001-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. */
30 #include <X11/Xatom.h>
31 #include <X11/IntrinsicP.h>
32 #include <X11/ObjectP.h>
33 #include "lwlib-utils.h"
36 /* Redisplay the contents of the widget, without first clearing it. */
38 XtNoClearRefreshWidget (Widget widget
)
43 event
.xexpose
.serial
= 0;
44 event
.xexpose
.send_event
= 0;
45 event
.xexpose
.display
= XtDisplay (widget
);
46 event
.xexpose
.window
= XtWindow (widget
);
49 event
.xexpose
.width
= widget
->core
.width
;
50 event
.xexpose
.height
= widget
->core
.height
;
51 event
.xexpose
.count
= 0;
53 (*widget
->core
.widget_class
->core_class
.expose
)
54 (widget
, &event
, (Region
)NULL
);
59 * Apply a function to all the subwidgets of a given widget recursively.
62 XtApplyToWidgets (Widget w
, XtApplyToWidgetsProc proc
, XtPointer arg
)
64 if (XtIsComposite (w
))
66 CompositeWidget cw
= (CompositeWidget
) w
;
67 /* We have to copy the children list before mapping over it, because
68 the procedure might add/delete elements, which would lose badly.
70 int nkids
= cw
->composite
.num_children
;
71 Widget
*kids
= (Widget
*) xmalloc (sizeof (Widget
) * nkids
);
73 memcpy ((char *) kids
, (char *) cw
->composite
.children
,
74 sizeof (Widget
) * nkids
);
75 for (i
= 0; i
< nkids
; i
++)
76 /* This prevent us from using gadgets, why is it here? */
77 /* if (XtIsWidget (kids [i])) */
79 /* do the kiddies first in case we're destroying */
80 XtApplyToWidgets (kids
[i
], proc
, arg
);
89 * Apply a function to all the subwidgets of a given widget recursively.
90 * Stop as soon as the function returns non NULL and returns this as a value.
93 XtApplyUntilToWidgets (Widget w
, XtApplyUntilToWidgetsProc proc
, XtPointer arg
)
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 widget
, unsigned int *number
)
121 CompositeWidget cw
= (CompositeWidget
)widget
;
126 if (!XtIsComposite (widget
))
131 n
= cw
->composite
.num_children
;
132 result
= (Widget
*)XtMalloc (n
* sizeof (Widget
));
134 for (i
= 0; i
< n
; i
++)
135 result
[i
] = cw
->composite
.children
[i
];
140 XtWidgetBeingDestroyedP (Widget widget
)
142 return widget
->core
.being_destroyed
;
146 XtSafelyDestroyWidget (Widget widget
)
150 /* this requires IntrinsicI.h (actually, InitialI.h) */
152 XtAppContext app
= XtWidgetToApplicationContext(widget
);
154 if (app
->dispatch_level
== 0)
156 app
->dispatch_level
= 1;
157 XtDestroyWidget (widget
);
158 /* generates an event so that the event loop will be called */
159 XChangeProperty (XtDisplay (widget
), XtWindow (widget
),
160 XA_STRING
, XA_STRING
, 32, PropModeAppend
, NULL
, 0);
161 app
->dispatch_level
= 0;
164 XtDestroyWidget (widget
);