diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2022-09-25 16:15:16 -0400 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2022-09-25 16:15:16 -0400 |
commit | 650c20f1ca4e07591a727e1cfcc74b3363d15985 (patch) | |
tree | 85d11f6437cde22f410c25e0e5f71a3131ebd07d /lwlib/lwlib-Xaw.c | |
parent | 8869332684c2302b5ba1ead4568bbc7ba1c0183e (diff) | |
parent | 4b85ae6a24380fb67a3315eaec9233f17a872473 (diff) | |
download | emacs-650c20f1ca4e07591a727e1cfcc74b3363d15985.tar.gz emacs-650c20f1ca4e07591a727e1cfcc74b3363d15985.tar.bz2 emacs-650c20f1ca4e07591a727e1cfcc74b3363d15985.zip |
Merge 'master' into noverlay
Diffstat (limited to 'lwlib/lwlib-Xaw.c')
-rw-r--r-- | lwlib/lwlib-Xaw.c | 97 |
1 files changed, 52 insertions, 45 deletions
diff --git a/lwlib/lwlib-Xaw.c b/lwlib/lwlib-Xaw.c index ce007ae8b0b..b09795ec38c 100644 --- a/lwlib/lwlib-Xaw.c +++ b/lwlib/lwlib-Xaw.c @@ -1,7 +1,7 @@ /* The lwlib interface to Athena widgets. Copyright (C) 1993 Chuck Thompson <cthomp@cs.uiuc.edu> -Copyright (C) 1994, 2001-2017 Free Software Foundation, Inc. +Copyright (C) 1994, 2001-2022 Free Software Foundation, Inc. This file is part of the Lucid Widget Library. @@ -50,8 +50,13 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ #include <X11/Xatom.h> -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT +#ifdef USE_CAIRO +#include <stdlib.h> +#include "lwlib-utils.h" +#else /* HAVE_XFT */ #include <X11/Xft/Xft.h> +#endif struct widget_xft_data { @@ -79,7 +84,7 @@ lw_xaw_widget_p (Widget widget) } -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT static void fill_xft_data (struct widget_xft_data *data, Widget widget, XftFont *font) { @@ -113,6 +118,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) { @@ -154,7 +176,7 @@ get_text_width_and_height (Widget widget, char *text, &gi); bp = cp ? cp + 1 : NULL; h += xft_font->height; - if (w < gi.width) w = gi.width; + if (w < gi.xOff) w = gi.xOff; } *height = h; @@ -170,11 +192,12 @@ draw_text (struct widget_xft_data *data, char *lbl, int inverse) int x = inverse ? 0 : 2; char *bp = lbl; - data->xft_draw = XftDrawCreate (XtDisplay (data->widget), - data->p, - DefaultVisual (XtDisplay (data->widget), - screen), - DefaultColormapOfScreen (sc)); + if (!data->xft_draw) + data->xft_draw = XftDrawCreate (XtDisplay (data->widget), + data->p, + DefaultVisual (XtDisplay (data->widget), + screen), + DefaultColormapOfScreen (sc)); XftDrawRect (data->xft_draw, inverse ? &data->xft_fg : &data->xft_bg, 0, 0, data->p_width, data->p_height); @@ -192,6 +215,9 @@ draw_text (struct widget_xft_data *data, char *lbl, int inverse) /* 1.2 gives reasonable line spacing. */ y += data->xft_font->height * 1.2; } +#ifdef USE_CAIRO + cairo_surface_flush (cairo_get_target (data->xft_draw)); +#endif } @@ -229,7 +255,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]; @@ -289,7 +315,7 @@ xaw_update_one_widget (widget_instance *instance, if (XtIsSubclass (widget, dialogWidgetClass)) { -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT if (instance->xft_data && instance->xft_data[0].xft_font) { set_text (&instance->xft_data[0], instance->parent, @@ -321,15 +347,15 @@ xaw_update_one_widget (widget_instance *instance, XtSetArg (al[ac], XtNlabel, val->value);ac++; /* Force centered button text. Se above. */ XtSetArg (al[ac], XtNjustify, XtJustifyCenter);ac++; -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT if (instance->xft_data && instance->xft_data[0].xft_font) { 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); @@ -360,28 +386,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)); @@ -477,7 +481,7 @@ static XtActionsRec xaw_actions [] = { }; static Boolean actions_initted = False; -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT static XtActionsRec button_actions[] = { { "my_reset", command_reset }, @@ -510,7 +514,7 @@ make_dialog (char* name, Widget dialog; Widget button; XtTranslations override; -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT XftFont *xft_font = 0; XtTranslations button_override; #endif @@ -525,7 +529,7 @@ make_dialog (char* name, XtAppContext app = XtWidgetToApplicationContext (parent); XtAppAddActions (app, xaw_actions, sizeof (xaw_actions) / sizeof (xaw_actions[0])); -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT XtAppAddActions (app, button_actions, sizeof (button_actions) / sizeof (button_actions[0])); #endif @@ -550,7 +554,7 @@ make_dialog (char* name, override = XtParseTranslationTable (dialogOverride); XtOverrideTranslations (dialog, override); -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT { int num; Widget *ch = NULL; @@ -568,7 +572,6 @@ make_dialog (char* name, } } instance->xft_data = 0; - instance->nr_xft_data = 0; if (w) { XtResource rec[] = @@ -588,11 +591,15 @@ 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)); + if (!instance->xft_data) + memory_full ((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); } } @@ -621,7 +628,7 @@ make_dialog (char* name, sprintf (button_name, "button%d", ++bc); button = XtCreateManagedWidget (button_name, commandWidgetClass, dialog, av, ac); -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT if (xft_font) { fill_xft_data (&instance->xft_data[bc], button, xft_font); @@ -654,7 +661,7 @@ make_dialog (char* name, sprintf (button_name, "button%d", ++bc); button = XtCreateManagedWidget (button_name, commandWidgetClass, dialog, av, ac); -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT if (xft_font) { fill_xft_data (&instance->xft_data[bc], button, xft_font); |