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 /* Definitions of these in config.h can cause
25 declaration conflicts later on between declarations for index
26 and declarations for strchr. This file doesn't use
27 index and rindex, so cancel them. */
31 #include <X11/Xatom.h>
32 #include <X11/IntrinsicP.h>
33 #include <X11/ObjectP.h>
34 #include "lwlib-utils.h"
36 /* Redisplay the contents of the widget, without first clearing it. */
38 XtNoClearRefreshWidget (widget
)
44 event
.xexpose
.serial
= 0;
45 event
.xexpose
.send_event
= 0;
46 event
.xexpose
.display
= XtDisplay (widget
);
47 event
.xexpose
.window
= XtWindow (widget
);
50 event
.xexpose
.width
= widget
->core
.width
;
51 event
.xexpose
.height
= widget
->core
.height
;
52 event
.xexpose
.count
= 0;
54 (*widget
->core
.widget_class
->core_class
.expose
)
55 (widget
, &event
, (Region
)NULL
);
60 * Apply a function to all the subwidgets of a given widget recursively.
63 XtApplyToWidgets (w
, proc
, arg
)
65 XtApplyToWidgetsProc proc
;
68 if (XtIsComposite (w
))
70 CompositeWidget cw
= (CompositeWidget
) w
;
71 /* We have to copy the children list before mapping over it, because
72 the procedure might add/delete elements, which would lose badly.
74 int nkids
= cw
->composite
.num_children
;
75 Widget
*kids
= (Widget
*) malloc (sizeof (Widget
) * nkids
);
77 lwlib_bcopy (cw
->composite
.children
, kids
, sizeof (Widget
) * nkids
);
78 for (i
= 0; i
< nkids
; i
++)
79 /* This prevent us from using gadgets, why is it here? */
80 /* if (XtIsWidget (kids [i])) */
82 /* do the kiddies first in case we're destroying */
83 XtApplyToWidgets (kids
[i
], proc
, arg
);
92 * Apply a function to all the subwidgets of a given widget recursively.
93 * Stop as soon as the function returns non NULL and returns this as a value.
96 XtApplyUntilToWidgets (w
, proc
, arg
)
98 XtApplyUntilToWidgetsProc proc
;
102 if (XtIsComposite (w
))
104 CompositeWidget cw
= (CompositeWidget
)w
;
106 for (i
= 0; i
< cw
->composite
.num_children
; i
++)
107 if (XtIsWidget (cw
->composite
.children
[i
])){
108 result
= proc (cw
->composite
.children
[i
], arg
);
111 result
= XtApplyUntilToWidgets (cw
->composite
.children
[i
], proc
,
122 * Returns a copy of the list of all children of a composite widget
125 XtCompositeChildren (widget
, number
)
127 unsigned int* number
;
129 CompositeWidget cw
= (CompositeWidget
)widget
;
134 if (!XtIsComposite (widget
))
139 n
= cw
->composite
.num_children
;
140 result
= (Widget
*)XtMalloc (n
* sizeof (Widget
));
142 for (i
= 0; i
< n
; i
++)
143 result
[i
] = cw
->composite
.children
[i
];
148 XtWidgetBeingDestroyedP (widget
)
151 return widget
->core
.being_destroyed
;
155 XtSafelyDestroyWidget (widget
)
160 /* this requires IntrinsicI.h (actually, InitialI.h) */
162 XtAppContext app
= XtWidgetToApplicationContext(widget
);
164 if (app
->dispatch_level
== 0)
166 app
->dispatch_level
= 1;
167 XtDestroyWidget (widget
);
168 /* generates an event so that the event loop will be called */
169 XChangeProperty (XtDisplay (widget
), XtWindow (widget
),
170 XA_STRING
, XA_STRING
, 32, PropModeAppend
, NULL
, 0);
171 app
->dispatch_level
= 0;
174 XtDestroyWidget (widget
);