summaryrefslogtreecommitdiff
path: root/lwlib/lwlib-Xaw.c
diff options
context:
space:
mode:
Diffstat (limited to 'lwlib/lwlib-Xaw.c')
-rw-r--r--lwlib/lwlib-Xaw.c52
1 files changed, 24 insertions, 28 deletions
diff --git a/lwlib/lwlib-Xaw.c b/lwlib/lwlib-Xaw.c
index 9655076da9d..a00f8aa73f9 100644
--- a/lwlib/lwlib-Xaw.c
+++ b/lwlib/lwlib-Xaw.c
@@ -113,6 +113,23 @@ fill_xft_data (struct widget_xft_data *data, Widget widget, XftFont *font)
data->p_width = data->p_height = 0;
}
+static void
+destroy_xft_data (Widget widget, XtPointer closure, XtPointer call_data)
+{
+ struct widget_xft_data *xft_data = closure;
+
+ for (int i = 0; xft_data[i].widget; ++i)
+ {
+ if (xft_data[i].xft_draw)
+ XftDrawDestroy (xft_data[i].xft_draw);
+ if (xft_data[i].p != None)
+ XFreePixmap (XtDisplay (widget), xft_data[i].p);
+ }
+ if (xft_data[0].xft_font)
+ XftFontClose (XtDisplay (widget), xft_data[0].xft_font);
+ xfree (xft_data);
+}
+
static XftFont*
openFont (Widget widget, char *name)
{
@@ -230,7 +247,7 @@ find_xft_data (Widget widget)
}
if (!inst || !inst->xft_data || !inst->xft_data[0].xft_font) return 0;
- for (nr = 0; data == NULL && nr < inst->nr_xft_data; ++nr)
+ for (nr = 0; data == NULL && inst->xft_data[nr].widget; ++nr)
{
if (inst->xft_data[nr].widget == widget)
data = &inst->xft_data[nr];
@@ -327,10 +344,10 @@ xaw_update_one_widget (widget_instance *instance,
{
int th;
int nr;
- for (nr = 0; nr < instance->nr_xft_data; ++nr)
+ for (nr = 0; instance->xft_data[nr].widget; ++nr)
if (instance->xft_data[nr].widget == widget)
break;
- if (nr < instance->nr_xft_data)
+ if (instance->xft_data[nr].widget)
{
set_text (&instance->xft_data[nr], instance->parent,
val->value, 6);
@@ -361,28 +378,6 @@ xaw_update_one_value (widget_instance *instance,
void
xaw_destroy_instance (widget_instance *instance)
{
-#ifdef HAVE_XFT
- if (instance->xft_data)
- {
- int i;
- for (i = 0; i < instance->nr_xft_data; ++i)
- {
- if (instance->xft_data[i].xft_draw)
- XftDrawDestroy (instance->xft_data[i].xft_draw);
- if (instance->xft_data[i].p != None)
- {
- XtVaSetValues (instance->xft_data[i].widget, XtNbitmap, None,
- NULL);
- XFreePixmap (XtDisplay (instance->widget),
- instance->xft_data[i].p);
- }
- }
- if (instance->xft_data[0].xft_font)
- XftFontClose (XtDisplay (instance->widget),
- instance->xft_data[0].xft_font);
- xfree (instance->xft_data);
- }
-#endif
if (XtIsSubclass (instance->widget, dialogWidgetClass))
/* Need to destroy the Shell too. */
XtDestroyWidget (XtParent (instance->widget));
@@ -569,7 +564,6 @@ make_dialog (char* name,
}
}
instance->xft_data = 0;
- instance->nr_xft_data = 0;
if (w)
{
XtResource rec[] =
@@ -589,11 +583,13 @@ make_dialog (char* name,
if (xft_font)
{
- instance->nr_xft_data = left_buttons + right_buttons + 1;
- instance->xft_data = calloc (instance->nr_xft_data,
+ int nr_xft_data = left_buttons + right_buttons + 1;
+ instance->xft_data = calloc (nr_xft_data + 1,
sizeof(*instance->xft_data));
fill_xft_data (&instance->xft_data[0], w, xft_font);
+ XtAddCallback (dialog, XtNdestroyCallback, destroy_xft_data,
+ instance->xft_data);
}
}