aboutsummaryrefslogtreecommitdiff
path: root/generic/Image.c
diff options
context:
space:
mode:
authorlecoanet2002-03-15 13:33:30 +0000
committerlecoanet2002-03-15 13:33:30 +0000
commit3d5eed1096262e5fdfcfe0c5c6f6f426d2d02ea6 (patch)
tree36921c7f67b1c1fb6562329ac652ed2375b8e938 /generic/Image.c
parent8974bed91f8ec9e26552da4040448c65d8963383 (diff)
downloadtkzinc-3d5eed1096262e5fdfcfe0c5c6f6f426d2d02ea6.zip
tkzinc-3d5eed1096262e5fdfcfe0c5c6f6f426d2d02ea6.tar.gz
tkzinc-3d5eed1096262e5fdfcfe0c5c6f6f426d2d02ea6.tar.bz2
tkzinc-3d5eed1096262e5fdfcfe0c5c6f6f426d2d02ea6.tar.xz
ajout de ValidateImage qui permet de centraliser la validate
d'une image Tk et sont affectation � un attribut.
Diffstat (limited to 'generic/Image.c')
-rw-r--r--generic/Image.c64
1 files changed, 62 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;
}
}