XawTextProperty * XawTextSinkCopyProperty(Widget w, XrmQuark property) { XawTextProperty *cur, *ret; if ((cur = XawTextSinkGetProperty(w, property)) == NULL) cur = XawTextSinkGetProperty(w, Qdefault); ret = (XawTextProperty*)XtCalloc(1, sizeof(XawTextProperty)); if (cur) memcpy(ret, cur, sizeof(XawTextProperty)); ret->identifier = NULLQUARK; ret->mask &= ~XAW_TPROP_FONT; return (ret); }
/*ARGSUSED*/ static int ReplaceText(Widget w, XawTextPosition startPos, XawTextPosition endPos, XawTextBlock *text) { AsciiSrcObject src = (AsciiSrcObject)w; Piece *start_piece, *end_piece, *temp_piece; XawTextPosition start_first, end_first; int length, firstPos; /* * Editing a read only source is not allowed */ if (src->text_src.edit_mode == XawtextRead) return (XawEditError); start_piece = FindPiece(src, startPos, &start_first); end_piece = FindPiece(src, endPos, &end_first); #ifndef OLDXAW /* * This is a big hack, but I can't think about a clever way to know * if the character being moved forward has a negative lbearing. * */ if (start_piece->used) { int i; for (i = 0; i < src->text_src.num_text; i++) { int line; TextWidget ctx = (TextWidget)src->text_src.text[i]; for (line = 0; line < ctx->text.lt.lines; line++) if (startPos < ctx->text.lt.info[line + 1].position) break; if (i < ctx->text.lt.lines && startPos > ctx->text.lt.info[i].position) { AsciiSinkObject sink = (AsciiSinkObject)ctx->text.sink; XawTextAnchor *anchor; XawTextEntity *entity; XawTextProperty *property; XFontStruct *font; if (XawTextSourceAnchorAndEntity(w, startPos, &anchor, &entity) && (property = XawTextSinkGetProperty(ctx->text.sink, entity->property)) != NULL && (property->mask & XAW_TPROP_FONT)) font = property->font; else font = sink->ascii_sink.font; if (font->min_bounds.lbearing < 0) { int lbearing = font->min_bounds.lbearing; unsigned char c = *(unsigned char*) (start_piece->text + (startPos - start_first)); if (c == '\t' || c == '\n') c = ' '; else if ((c & 0177) < XawSP || c == 0177) { if (sink->ascii_sink.display_nonprinting) c = c > 0177 ? '\\' : c + '^'; else c = ' '; } if (font->per_char && (c >= font->min_char_or_byte2 && c <= font->max_char_or_byte2)) lbearing = font->per_char[c - font->min_char_or_byte2].lbearing; if (lbearing < 0) _XawTextNeedsUpdating(ctx, startPos - 1, startPos); } } } } #endif /* * Remove Old Stuff */ if (start_piece != end_piece) { temp_piece = start_piece->next; /* * If empty and not the only piece then remove it. */ if (((start_piece->used = startPos - start_first) == 0) && !(start_piece->next == NULL && start_piece->prev == NULL)) RemovePiece(src, start_piece); while (temp_piece != end_piece) { temp_piece = temp_piece->next; RemovePiece(src, temp_piece->prev); } end_piece->used -= endPos - end_first; if (end_piece->used != 0) memmove(end_piece->text, end_piece->text + endPos - end_first, (unsigned)end_piece->used); } else { /* We are fully in one piece */ if ((start_piece->used -= endPos - startPos) == 0) { if (!(start_piece->next == NULL && start_piece->prev == NULL)) RemovePiece(src, start_piece); } else { memmove(start_piece->text + (startPos - start_first), start_piece->text + (endPos - start_first), (unsigned)(start_piece->used - (startPos - start_first))); if (src->ascii_src.use_string_in_place && src->ascii_src.length - (endPos - startPos) < src->ascii_src.piece_size - 1) start_piece->text[src->ascii_src.length - (endPos - startPos)] = '\0'; } } src->ascii_src.length += -(endPos - startPos) + text->length; if ( text->length != 0) { /* * Put in the New Stuff */ start_piece = FindPiece(src, startPos, &start_first); length = text->length; firstPos = text->firstPos; while (length > 0) { char *ptr; int fill; if (src->ascii_src.use_string_in_place) { if (start_piece->used == src->ascii_src.piece_size - 1) { /* * If we are in ascii string emulation mode. Then the * string is not allowed to grow */ start_piece->used = src->ascii_src.length = src->ascii_src.piece_size - 1; start_piece->text[src->ascii_src.length] = '\0'; return (XawEditError); } } if (start_piece->used == src->ascii_src.piece_size) { BreakPiece(src, start_piece); start_piece = FindPiece(src, startPos, &start_first); } fill = Min((int)(src->ascii_src.piece_size - start_piece->used), length); ptr = start_piece->text + (startPos - start_first); memmove(ptr + fill, ptr, (unsigned)(start_piece->used - (startPos - start_first))); memcpy(ptr, text->ptr + firstPos, (unsigned)fill); startPos += fill; firstPos += fill; start_piece->used += fill; length -= fill; } } if (src->ascii_src.use_string_in_place) start_piece->text[start_piece->used] = '\0'; #ifdef OLDXAW src->ascii_src.changes = True; XtCallCallbacks(w, XtNcallback, NULL); #endif return (XawEditDone); }