diff options
-rw-r--r-- | generic/Image.c | 64 | ||||
-rw-r--r-- | generic/Image.h | 10 |
2 files changed, 72 insertions, 2 deletions
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; } } diff --git a/generic/Image.h b/generic/Image.h index caa5443..4dfa20e 100644 --- a/generic/Image.h +++ b/generic/Image.h @@ -66,6 +66,16 @@ typedef struct _ImageBits { struct _ImagePixmap *pixmaps; } ImageBits; +struct _WidgetInfo; + +int +ValidateImage(struct _WidgetInfo */* wi */, + void */* item_or_field */, + char */* image_name */, + Tk_ImageChangedProc */* image_proc */, + Tk_Image */* image_ref */, + char */* msg */); + ImageBits * GetImageBits(ZnWindow /* win */, char */* image_name */, |