1 /* Defines some widget utility functions.
2 Copyright (C) 1992 Lucid, Inc.
3 Copyright (C) 1994, 2001-2011 Free Software Foundation, Inc.
5 This file is part of the Lucid Widget Library.
7 The Lucid Widget Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 1, or (at your option)
12 The Lucid Widget Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
26 /* Definitions of these in config.h can cause
27 declaration conflicts later on between declarations for index
28 and declarations for strchr. This file doesn't use
29 index and rindex, so cancel them. */
34 #include "../src/lisp.h"
36 #include <X11/Xatom.h>
37 #include <X11/IntrinsicP.h>
38 #include <X11/ObjectP.h>
39 #include "lwlib-utils.h"
42 /* Redisplay the contents of the widget, without first clearing it. */
44 XtNoClearRefreshWidget (Widget widget
)
49 event
.xexpose
.serial
= 0;
50 event
.xexpose
.send_event
= 0;
51 event
.xexpose
.display
= XtDisplay (widget
);
52 event
.xexpose
.window
= XtWindow (widget
);
55 event
.xexpose
.width
= widget
->core
.width
;
56 event
.xexpose
.height
= widget
->core
.height
;
57 event
.xexpose
.count
= 0;
59 (*widget
->core
.widget_class
->core_class
.expose
)
60 (widget
, &event
, (Region
)NULL
);
65 * Apply a function to all the subwidgets of a given widget recursively.
68 XtApplyToWidgets (Widget w
, XtApplyToWidgetsProc proc
, XtPointer arg
)
70 if (XtIsComposite (w
))
72 CompositeWidget cw
= (CompositeWidget
) w
;
73 /* We have to copy the children list before mapping over it, because
74 the procedure might add/delete elements, which would lose badly.
76 int nkids
= cw
->composite
.num_children
;
77 Widget
*kids
= (Widget
*) xmalloc (sizeof (Widget
) * nkids
);
79 memcpy ((char *) kids
, (char *) cw
->composite
.children
,
80 sizeof (Widget
) * nkids
);
81 for (i
= 0; i
< nkids
; i
++)
82 /* This prevent us from using gadgets, why is it here? */
83 /* if (XtIsWidget (kids [i])) */
85 /* do the kiddies first in case we're destroying */
86 XtApplyToWidgets (kids
[i
], proc
, arg
);
95 * Apply a function to all the subwidgets of a given widget recursively.
96 * Stop as soon as the function returns non NULL and returns this as a value.
99 XtApplyUntilToWidgets (Widget w
, XtApplyUntilToWidgetsProc proc
, XtPointer arg
)
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 widget
, unsigned int *number
)
127 CompositeWidget cw
= (CompositeWidget
)widget
;
132 if (!XtIsComposite (widget
))
137 n
= cw
->composite
.num_children
;
138 result
= (Widget
*)XtMalloc (n
* sizeof (Widget
));
140 for (i
= 0; i
< n
; i
++)
141 result
[i
] = cw
->composite
.children
[i
];
146 XtWidgetBeingDestroyedP (Widget widget
)
148 return widget
->core
.being_destroyed
;
152 XtSafelyDestroyWidget (Widget widget
)
156 /* this requires IntrinsicI.h (actually, InitialI.h) */
158 XtAppContext app
= XtWidgetToApplicationContext(widget
);
160 if (app
->dispatch_level
== 0)
162 app
->dispatch_level
= 1;
163 XtDestroyWidget (widget
);
164 /* generates an event so that the event loop will be called */
165 XChangeProperty (XtDisplay (widget
), XtWindow (widget
),
166 XA_STRING
, XA_STRING
, 32, PropModeAppend
, NULL
, 0);
167 app
->dispatch_level
= 0;
170 XtDestroyWidget (widget
);