From 3d5eed1096262e5fdfcfe0c5c6f6f426d2d02ea6 Mon Sep 17 00:00:00 2001 From: lecoanet Date: Fri, 15 Mar 2002 13:33:30 +0000 Subject: ajout de ValidateImage qui permet de centraliser la validate d'une image Tk et sont affectation � un attribut. --- generic/Image.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) (limited to 'generic/Image.c') diff --git a/generic/Image.c b/generic/Image.c index 80d8f8d..c402c11 100644 --- a/generic/Image.c +++ b/generic/Image.c @@ -67,7 +67,66 @@ static Tcl_HashTable bitmap_masks; static Tcl_HashTable font_textures; #endif + +/* + ********************************************************************************** + * + * ValidateImage -- + * Make sure an image is ok for use in an attribute + * and do any needed housekeeping. + * + ********************************************************************************** + */ +int +ValidateImage(WidgetInfo *wi, + void *item_or_field, + char *image_name, + Tk_ImageChangedProc *image_proc, + Tk_Image *image_ref, + char *msg) +{ + Tk_Image image; + int w, h, status = ZN_OK; + + if (strcmp(image_name, "") != 0) { + image = Tk_GetImage(wi->interp, wi->win, image_name, + image_proc, (ClientData) item_or_field); + /* + * The name will not be in sync with the image in + * these cases. + */ + if (image == NULL) { + im_val_err: + image = ZnUnspecifiedImage; + /*Tcl_AppendResult(wi->interp, "unknown or bogus image \"", + image_name, "\" in ", msg, NULL); + status = ZN_ERROR; */ + ZnWarning("unknown or bogus image \""); + ZnWarning(image_name); + ZnWarning("\" in "); + ZnWarning(msg); + ZnWarning("\n"); + status = ZN_OK; + } + else { + Tk_SizeOfImage(image, &w, &h); + if ((w == 0) || (h == 0)) { + goto im_val_err; + } + } + } + else { + image = ZnUnspecifiedImage; + } + if (*image_ref != ZnUnspecifiedImage) { + Tk_FreeImage(*image_ref); + } + *image_ref = image; + + return status; +} + /* ********************************************************************************** * @@ -91,7 +150,8 @@ GetImageBits(ZnWindow win, GC gc; ImageBits *im_bits; ZnBool full_mask=True; - + + /* printf("GetImageBits: %s\n", image_name);*/ if (!image_bits_inited) { Tcl_InitHashTable(&image_bits, TCL_STRING_KEYS); image_bits_inited = 1; @@ -788,7 +848,7 @@ GetTexFont(ZnWindow win, } else { /* Overflowed texture space */ - ZnWarning("Font texture overflow"); + ZnWarning("Font texture overflow\n"); goto error; } } -- cgit v1.1