diff options
Diffstat (limited to 'generic')
-rw-r--r-- | generic/Item.c | 277 |
1 files changed, 184 insertions, 93 deletions
diff --git a/generic/Item.c b/generic/Item.c index 1aaa2e0..f268880 100644 --- a/generic/Item.c +++ b/generic/Item.c @@ -196,6 +196,7 @@ static void FieldImageChange(ClientData client_data, int x, int y, int width, int height, int image_width, int image_height); static void FieldTileChange(ClientData client_data, int x, int y, int width, int height, int image_width, int image_height); +static void GetLabelBBox(FieldSet field_set, ZnDim *w, ZnDim *h); /* @@ -1000,6 +1001,53 @@ ConfigureAttributes(char *record, } } break; + case ZN_CONFIG_WINDOW: + { + ZnWindow win, ancestor, parent; + if (strlen(LangString(args[i+1])) == 0) { + win = NULL; + } + else { + win = Tk_NameToWindow(wi->interp, args[i+1], wi->win); + if (win == NULL) { + return ZN_ERROR; + } + else { + /* + * Make sure that the zinc widget is either the parent of the + * window associated with the item or a descendant of that + * parent. Also, don't allow a toplevel window or the widget + * itself to be managed. + */ + parent = Tk_Parent(win); + for (ancestor = wi->win; ; ancestor = Tk_Parent(ancestor)) { + if (ancestor == parent) { + break; + } + if (((Tk_FakeWin *) (ancestor))->flags & TK_TOP_LEVEL) { + badWindow: + Tcl_AppendResult(wi->interp, "can't use ", + Tk_PathName(win), + " in a window item of this zinc widget", + (char *) NULL); + win = NULL; + return TCL_ERROR; + } + } + if (((Tk_FakeWin *) (win))->flags & TK_TOP_LEVEL) { + goto badWindow; + } + if (win == wi->win) { + goto badWindow; + } + if (win != *((ZnWindow *) valp)) { + *((ZnWindow *) valp) = win; + *flags |= desc->flags; + } + } + } + } + break; case ZN_CONFIG_INT: case ZN_CONFIG_UINT: case ZN_CONFIG_ANGLE: @@ -1543,6 +1591,15 @@ AttributeToString(WidgetInfo *wi, LangSetString(&result, buffer); } break; + case ZN_CONFIG_WINDOW: + if (*((ZnWindow *) valp) == NULL) { + LangSetString(&result, ""); + } + else { + *free_proc = TCL_VOLATILE; + LangSetString(&result, Tk_PathName(*((ZnWindow *) valp))); + } + break; case ZN_CONFIG_INT: case ZN_CONFIG_UINT: case ZN_CONFIG_DIM: @@ -1766,6 +1823,7 @@ GlobalModuleInit() AddItemClass(ZnGroup); AddItemClass(ZnIcon); AddItemClass(ZnText); + AddItemClass(ZnWind); /*AddItemClass(ZnMosaic);*/ InitAttrDesc(field_attrs); } @@ -1804,6 +1862,16 @@ ComputeFieldAttachment(FieldSet field_set, return; } + /* + * Preset this field to a default position/size and pretend + * its cache is ok to break any deadlocks. + */ + field_ptr->orig_x = field_ptr->orig_y = 0; + field_ptr->corner_x = field_ptr->corner_y = 0; + field_bbox->orig.x = field_bbox->orig.y = 0; + field_bbox->corner.x = field_bbox->corner.y = 0; + SET(field_ptr->flags, CACHE_OK); + num_fields = LabelFormatNumFields(field_set->label_format); LabelFormatGetField(field_set->label_format, field, &x_attach, &y_attach, &x_dim, &y_dim, @@ -1842,6 +1910,13 @@ ComputeFieldAttachment(FieldSet field_set, real_width += (ZnDim) width_spec; break; } + case LF_DIM_LABEL: + { + ZnDim lh; + + GetLabelBBox(field_set, &real_width, &lh); + break; + } case LF_DIM_PIXEL: default: real_width = (ZnDim) width_spec; @@ -1875,6 +1950,13 @@ ComputeFieldAttachment(FieldSet field_set, real_height += (ZnDim) height_spec; break; } + case LF_DIM_LABEL: + { + ZnDim lw; + + GetLabelBBox(field_set, &lw, &real_height); + break; + } case LF_DIM_PIXEL: default: real_height = (ZnDim) height_spec; @@ -1883,122 +1965,125 @@ ComputeFieldAttachment(FieldSet field_set, /*printf("field %d, height = %g\n", field, real_height);*/ /* - * Then try to deduce the position, resolving any attachments - * if needed. + * Update the cache with the newly computed infos + * (breaking of deadlocks). */ + field_bbox->corner.x = field_ptr->corner_x = real_width; + field_bbox->corner.y = field_ptr->corner_y = real_height; + /* - * Preset this field to a default position/size and pretend - * its cache is ok to break any deadlocks. + * Then try to deduce the position, resolving any attachments + * if needed. */ - field_ptr->orig_x = field_ptr->orig_y = 0; - field_ptr->corner_x = real_width; - field_ptr->corner_y = real_height; - SET(field_ptr->flags, CACHE_OK); /* * Do the x axis. */ - if (x_attach == LF_ATTACH_PIXEL) { - field_bbox->orig.x = (ZnPos) x_spec; - field_bbox->corner.x = field_bbox->orig.x + real_width; - } - else { - ref_field = x_spec; - field_bbox->orig.x = field_bbox->corner.x = 0; - if ((ref_field < 0) || (ref_field >= num_fields)) { - ZnWarning ("Attached (x) to an inexistant field geometry"); + if (x_dim != LF_DIM_LABEL) { + if (x_attach == LF_ATTACH_PIXEL) { + field_bbox->orig.x = (ZnPos) x_spec; + field_bbox->corner.x = field_bbox->orig.x + real_width; } else { - ComputeFieldAttachment(field_set, ref_field, &ref_bbox); - switch (x_attach) { - case LF_ATTACH_FWD: - if (ISSET(field_set->fields[ref_field].flags, FIELD_VISIBLE_BIT)) { - field_bbox->orig.x = ref_bbox.corner.x; - } - else { + ref_field = x_spec; + field_bbox->orig.x = field_bbox->corner.x = 0; + if ((ref_field < 0) || (ref_field >= num_fields)) { + ZnWarning ("Attached (x) to an inexistant field geometry"); + } + else { + ComputeFieldAttachment(field_set, ref_field, &ref_bbox); + switch (x_attach) { + case LF_ATTACH_FWD: + if (ISSET(field_set->fields[ref_field].flags, FIELD_VISIBLE_BIT)) { + field_bbox->orig.x = ref_bbox.corner.x; + } + else { + field_bbox->orig.x = ref_bbox.orig.x; + } + field_bbox->corner.x = field_bbox->orig.x + real_width; + break; + case LF_ATTACH_BWD: + if (ISSET(field_set->fields[ref_field].flags, FIELD_VISIBLE_BIT)) { + field_bbox->corner.x = ref_bbox.orig.x; + } + else { + field_bbox->corner.x = ref_bbox.corner.x; + } + field_bbox->orig.x = field_bbox->corner.x - real_width; + break; + case LF_ATTACH_LEFT: field_bbox->orig.x = ref_bbox.orig.x; + field_bbox->corner.x = field_bbox->orig.x + real_width; + break; + case LF_ATTACH_RIGHT: + if (ISSET(field_set->fields[ref_field].flags, FIELD_VISIBLE_BIT)) { + field_bbox->corner.x = ref_bbox.corner.x; + } + else { + field_bbox->corner.x = ref_bbox.orig.x; + } + field_bbox->orig.x = field_bbox->corner.x - real_width; + break; } - field_bbox->corner.x = field_bbox->orig.x + real_width; - break; - case LF_ATTACH_BWD: - if (ISSET(field_set->fields[ref_field].flags, FIELD_VISIBLE_BIT)) { - field_bbox->corner.x = ref_bbox.orig.x; - } - else { - field_bbox->corner.x = ref_bbox.corner.x; - } - field_bbox->orig.x = field_bbox->corner.x - real_width; - break; - case LF_ATTACH_LEFT: - field_bbox->orig.x = ref_bbox.orig.x; - field_bbox->corner.x = field_bbox->orig.x + real_width; - break; - case LF_ATTACH_RIGHT: - if (ISSET(field_set->fields[ref_field].flags, FIELD_VISIBLE_BIT)) { - field_bbox->corner.x = ref_bbox.corner.x; - } - else { - field_bbox->corner.x = ref_bbox.orig.x; - } - field_bbox->orig.x = field_bbox->corner.x - real_width; - break; } } + /*printf("field %d, x = %g\n", field, field_bbox->orig.x);*/ } - /*printf("field %d, x = %g\n", field, field_bbox->orig.x);*/ - + /* * Then the y axis. */ - if (y_attach == LF_ATTACH_PIXEL) { - field_bbox->orig.y = (ZnPos) y_spec; - field_bbox->corner.y = field_bbox->orig.y + real_height; - } - else { - ref_field = y_spec; - field_bbox->orig.y = field_bbox->corner.y = 0; - if ((ref_field < 0) || (ref_field >= num_fields)) { - ZnWarning ("Attached (y) to an inexistant field geometry"); + if (y_dim != LF_DIM_LABEL) { + if (y_attach == LF_ATTACH_PIXEL) { + field_bbox->orig.y = (ZnPos) y_spec; + field_bbox->corner.y = field_bbox->orig.y + real_height; } else { - ComputeFieldAttachment(field_set, ref_field, &ref_bbox); - switch (y_attach) { - case LF_ATTACH_FWD: - if (ISSET(field_set->fields[ref_field].flags, FIELD_VISIBLE_BIT)) { - field_bbox->orig.y = ref_bbox.corner.y; - } - else { + ref_field = y_spec; + field_bbox->orig.y = field_bbox->corner.y = 0; + if ((ref_field < 0) || (ref_field >= num_fields)) { + ZnWarning ("Attached (y) to an inexistant field geometry"); + } + else { + ComputeFieldAttachment(field_set, ref_field, &ref_bbox); + switch (y_attach) { + case LF_ATTACH_FWD: + if (ISSET(field_set->fields[ref_field].flags, FIELD_VISIBLE_BIT)) { + field_bbox->orig.y = ref_bbox.corner.y; + } + else { + field_bbox->orig.y = ref_bbox.orig.y; + } + field_bbox->corner.y = field_bbox->orig.y + real_height; + break; + case LF_ATTACH_BWD: + if (ISSET(field_set->fields[ref_field].flags, FIELD_VISIBLE_BIT)) { + field_bbox->corner.y = ref_bbox.orig.y; + } + else { + field_bbox->corner.y = ref_bbox.corner.y; + } + field_bbox->orig.y = field_bbox->corner.y - real_height; + break; + case LF_ATTACH_LEFT: field_bbox->orig.y = ref_bbox.orig.y; + field_bbox->corner.y = field_bbox->orig.y + real_height; + break; + case LF_ATTACH_RIGHT: + if (ISSET(field_set->fields[ref_field].flags, FIELD_VISIBLE_BIT)) { + field_bbox->corner.y = ref_bbox.corner.y; + } + else { + field_bbox->corner.y = ref_bbox.orig.y; + } + field_bbox->orig.y = field_bbox->corner.y - real_height; + break; } - field_bbox->corner.y = field_bbox->orig.y + real_height; - break; - case LF_ATTACH_BWD: - if (ISSET(field_set->fields[ref_field].flags, FIELD_VISIBLE_BIT)) { - field_bbox->corner.y = ref_bbox.orig.y; - } - else { - field_bbox->corner.y = ref_bbox.corner.y; - } - field_bbox->orig.y = field_bbox->corner.y - real_height; - break; - case LF_ATTACH_LEFT: - field_bbox->orig.y = ref_bbox.orig.y; - field_bbox->corner.y = field_bbox->orig.y + real_height; - break; - case LF_ATTACH_RIGHT: - if (ISSET(field_set->fields[ref_field].flags, FIELD_VISIBLE_BIT)) { - field_bbox->corner.y = ref_bbox.corner.y; - } - else { - field_bbox->corner.y = ref_bbox.orig.y; - } - field_bbox->orig.y = field_bbox->corner.y - real_height; - break; } } + /*printf("field %d, y = %g\n", field, field_bbox->orig.y);*/ } - /*printf("field %d, y = %g\n", field, field_bbox->orig.y);*/ - + field_ptr->orig_x = (short) field_bbox->orig.x; field_ptr->orig_y = (short) field_bbox->orig.y; field_ptr->corner_x = (short) field_bbox->corner.x; @@ -3675,7 +3760,13 @@ DestroyItem(Item item) wi->new_item = ZN_NO_ITEM; wi->new_part = ZN_NO_PART; } - + if (wi->text_info.sel_item == item) { + wi->text_info.sel_item = ZN_NO_ITEM; + } + if (wi->text_info.sel_item == item) { + wi->text_info.focus_item = ZN_NO_ITEM; + } + /* * Call per class removal code. */ |