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 widget
)
37 event
.xexpose
.serial
= 0;
38 event
.xexpose
.send_event
= 0;
39 event
.xexpose
.display
= XtDisplay (widget
);
40 event
.xexpose
.window
= XtWindow (widget
);
43 event
.xexpose
.width
= widget
->core
.width
;
44 event
.xexpose
.height
= widget
->core
.height
;
45 event
.xexpose
.count
= 0;
47 (*widget
->core
.widget_class
->core_class
.expose
)
48 (widget
, &event
, (Region
)NULL
);
53 * Apply a function to all the subwidgets of a given widget recursively.
56 XtApplyToWidgets (Widget w
, XtApplyToWidgetsProc proc
, XtPointer arg
)
58 if (XtIsComposite (w
))
60 CompositeWidget cw
= (CompositeWidget
) w
;
61 /* We have to copy the children list before mapping over it, because
62 the procedure might add/delete elements, which would lose badly.
64 int nkids
= cw
->composite
.num_children
;
65 Widget
*kids
= (Widget
*) malloc (sizeof (Widget
) * nkids
);
67 memcpy (kids
, cw
->composite
.children
, sizeof (Widget
) * nkids
);
68 for (i
= 0; i
< nkids
; i
++)
69 /* This prevent us from using gadgets, why is it here? */
70 /* if (XtIsWidget (kids [i])) */
72 /* do the kiddies first in case we're destroying */
73 XtApplyToWidgets (kids
[i
], proc
, arg
);
82 * Apply a function to all the subwidgets of a given widget recursively.
83 * Stop as soon as the function returns non NULL and returns this as a value.
86 XtApplyUntilToWidgets (Widget w
, XtApplyUntilToWidgetsProc proc
, XtPointer arg
)
89 if (XtIsComposite (w
))
91 CompositeWidget cw
= (CompositeWidget
)w
;
93 for (i
= 0; i
< cw
->composite
.num_children
; i
++)
94 if (XtIsWidget (cw
->composite
.children
[i
])){
95 result
= proc (cw
->composite
.children
[i
], arg
);
98 result
= XtApplyUntilToWidgets (cw
->composite
.children
[i
], proc
,
109 * Returns a copy of the list of all children of a composite widget
112 XtCompositeChildren (Widget widget
, unsigned int* number
)
114 CompositeWidget cw
= (CompositeWidget
)widget
;
119 if (!XtIsComposite (widget
))
124 n
= cw
->composite
.num_children
;
125 result
= (Widget
*)XtMalloc (n
* sizeof (Widget
));
127 for (i
= 0; i
< n
; i
++)
128 result
[i
] = cw
->composite
.children
[i
];
133 XtWidgetBeingDestroyedP (Widget widget
)
135 return widget
->core
.being_destroyed
;
139 XtSafelyDestroyWidget (Widget widget
)
143 /* this requires IntrinsicI.h (actually, InitialI.h) */
145 XtAppContext app
= XtWidgetToApplicationContext(widget
);
147 if (app
->dispatch_level
== 0)
149 app
->dispatch_level
= 1;
150 XtDestroyWidget (widget
);
151 /* generates an event so that the event loop will be called */
152 XChangeProperty (XtDisplay (widget
), XtWindow (widget
),
153 XA_STRING
, XA_STRING
, 32, PropModeAppend
, NULL
, 0);
154 app
->dispatch_level
= 0;
157 XtDestroyWidget (widget
);