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. */
24 #include <X11/Xatom.h>
25 #include <X11/IntrinsicP.h>
26 #include <X11/ObjectP.h>
27 #include "lwlib-utils.h"
29 /* Redisplay the contents of the widget, without first clearing it. */
31 XtNoClearRefreshWidget (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 (w
, proc
, arg
)
58 XtApplyToWidgetsProc proc
;
61 if (XtIsComposite (w
))
63 CompositeWidget cw
= (CompositeWidget
) w
;
64 /* We have to copy the children list before mapping over it, because
65 the procedure might add/delete elements, which would lose badly.
67 int nkids
= cw
->composite
.num_children
;
68 Widget
*kids
= (Widget
*) malloc (sizeof (Widget
) * nkids
);
70 lwlib_bcopy (cw
->composite
.children
, kids
, 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 (w
, proc
, arg
)
91 XtApplyUntilToWidgetsProc proc
;
95 if (XtIsComposite (w
))
97 CompositeWidget cw
= (CompositeWidget
)w
;
99 for (i
= 0; i
< cw
->composite
.num_children
; i
++)
100 if (XtIsWidget (cw
->composite
.children
[i
])){
101 result
= proc (cw
->composite
.children
[i
], arg
);
104 result
= XtApplyUntilToWidgets (cw
->composite
.children
[i
], proc
,
115 * Returns a copy of the list of all children of a composite widget
118 XtCompositeChildren (widget
, number
)
120 unsigned int* number
;
122 CompositeWidget cw
= (CompositeWidget
)widget
;
127 if (!XtIsComposite (widget
))
132 n
= cw
->composite
.num_children
;
133 result
= (Widget
*)XtMalloc (n
* sizeof (Widget
));
135 for (i
= 0; i
< n
; i
++)
136 result
[i
] = cw
->composite
.children
[i
];
141 XtWidgetBeingDestroyedP (widget
)
144 return widget
->core
.being_destroyed
;
148 XtSafelyDestroyWidget (widget
)
153 /* this requires IntrinsicI.h (actually, InitialI.h) */
155 XtAppContext app
= XtWidgetToApplicationContext(widget
);
157 if (app
->dispatch_level
== 0)
159 app
->dispatch_level
= 1;
160 XtDestroyWidget (widget
);
161 /* generates an event so that the event loop will be called */
162 XChangeProperty (XtDisplay (widget
), XtWindow (widget
),
163 XA_STRING
, XA_STRING
, 32, PropModeAppend
, NULL
, 0);
164 app
->dispatch_level
= 0;
167 XtDestroyWidget (widget
);