/*ARGSUSED*/ static void ClearToBackground(Widget w, int x, int y, unsigned int width, unsigned int height) { /* * Don't clear in height or width are zero * XClearArea() has special semantic for these values */ TextWidget xaw = (TextWidget)XtParent(w); Position x1, y1, x2, y2; x1 = XawMax(x, xaw->text.r_margin.left); y1 = XawMax(y, xaw->text.r_margin.top); x2 = XawMin(x + (int)width, (int)XtWidth(xaw) - xaw->text.r_margin.right); y2 = XawMin(y + (int)height, (int)XtHeight(xaw) - xaw->text.r_margin.bottom); x = x1; y = y1; width = XawMax(0, x2 - x1); height = XawMax(0, y2 - y1); if (height != 0 && width != 0) XClearArea(XtDisplayOfObject(w), XtWindowOfObject(w), x, y, width, height, False); }
/* Paint the thumb in the area specified by w->top and w->shown. The old area is erased. The painting and erasing is done cleverly so that no flickering will occur. */ static void PaintThumb(ScrollbarWidget w) { Position oldtop, oldbot, newtop, newbot; oldtop = w->scrollbar.topLoc; oldbot = oldtop + w->scrollbar.shownLength; newtop = w->scrollbar.length * w->scrollbar.top; newbot = newtop + (int)(w->scrollbar.length * w->scrollbar.shown); if (newbot < newtop + (int)w->scrollbar.min_thumb) newbot = newtop + w->scrollbar.min_thumb; w->scrollbar.topLoc = newtop; w->scrollbar.shownLength = newbot - newtop; if (XtIsRealized((Widget)w)) { if (newtop < oldtop) FillArea(w, newtop, XawMin(newbot, oldtop), 1); if (newtop > oldtop) FillArea(w, oldtop, XawMin(newtop, oldbot), 0); if (newbot < oldbot) FillArea(w, XawMax(newbot, oldtop), oldbot, 0); if (newbot > oldbot) FillArea(w, XawMax(newtop, oldbot), newbot, 1); } }
static void LoadPieces(AsciiSrcObject src, FILE *file, char *string) { char *ptr; Piece *piece = NULL; XawTextPosition left; if (string == NULL) { if (src->ascii_src.type == XawAsciiFile) { if (src->ascii_src.length != 0) { int len; left = 0; fseek(file, 0, 0); while (left < src->ascii_src.length) { ptr = XtMalloc((unsigned)src->ascii_src.piece_size); if ((len = fread(ptr, (Size_t)sizeof(unsigned char), (Size_t)src->ascii_src.piece_size, file)) < 0) XtErrorMsg("readError", "asciiSourceCreate", "XawError", "fread returned error.", NULL, NULL); piece = AllocNewPiece(src, piece); piece->text = ptr; piece->used = XawMin(len, src->ascii_src.piece_size); left += piece->used; } } else { piece = AllocNewPiece(src, NULL); piece->text = XtMalloc((unsigned)src->ascii_src.piece_size); piece->used = 0; } return; } else string = src->ascii_src.string; } if (src->ascii_src.use_string_in_place) { piece = AllocNewPiece(src, piece); piece->used = XawMin(src->ascii_src.length, src->ascii_src.piece_size); piece->text = src->ascii_src.string; return; } ptr = string; left = src->ascii_src.length; do { piece = AllocNewPiece(src, piece); piece->text = XtMalloc((unsigned)src->ascii_src.piece_size); piece->used = XawMin(left, src->ascii_src.piece_size); if (piece->used != 0) memcpy(piece->text, ptr, (unsigned)piece->used); left -= piece->used; ptr += piece->used; } while (left > 0); }
static void FillArea(ScrollbarWidget w, int top, int bottom, int thumb) { Dimension length; top = XawMax(1, top); if (w->scrollbar.orientation == XtorientHorizontal) bottom = XawMin(bottom, XtWidth(w) - 1); else bottom = XawMin(bottom, XtHeight(w) - 1); if (bottom <= top) return; length = bottom - top; switch(thumb) { /* Fill the new Thumb location */ case 1: if (w->scrollbar.orientation == XtorientHorizontal) XFillRectangle(XtDisplay(w), XtWindow(w), w->scrollbar.gc, top, 1, length, XtHeight(w) - 2); else XFillRectangle(XtDisplay(w), XtWindow(w), w->scrollbar.gc, 1, top, XtWidth(w) - 2, length); break; /* Clear the old Thumb location */ case 0: if (w->scrollbar.orientation == XtorientHorizontal) XClearArea(XtDisplay(w), XtWindow(w), top, 1, length, XtHeight(w) - 2, False); else XClearArea(XtDisplay(w), XtWindow(w), 1, top, XtWidth(w) - 2, length, False); break; } }
/* * Function: * WritePiecesToFile * * Parameters: * src - ascii source object * name - name of the file * * Description: * Almost identical to WriteToFile, but only works for ascii src objects * of type XawAsciiFile. This function avoids allocating temporary memory, * what can be useful when editing very large files. * * Returns: * returns True if sucessful, False otherwise */ static Bool WritePiecesToFile(AsciiSrcObject src, String name) { Piece *piece; int fd; if (src->ascii_src.data_compression) { Piece *tmp; piece = src->ascii_src.first_piece; while (piece) { int bytes = src->ascii_src.piece_size - piece->used; if (bytes > 0 && (tmp = piece->next) != NULL) { bytes = XawMin(bytes, tmp->used); memcpy(piece->text + piece->used, tmp->text, bytes); memmove(tmp->text, tmp->text + bytes, tmp->used - bytes); piece->used += bytes; if ((tmp->used -= bytes) == 0) { RemovePiece(src, tmp); continue; } } piece = piece->next; } } if ((fd = creat(name, 0666)) == -1) return (False); for (piece = src->ascii_src.first_piece; piece; piece = piece->next) if (write(fd, piece->text, piece->used) == -1) return (False); if (close(fd) == -1) return (False); return (True); }
static Bool GradientLoader(XawParams *params, Screen *screen, Colormap colormap, int depth, Pixmap *pixmap_return, Pixmap *mask_return, Dimension *width_return, Dimension *height_return) { double ired, igreen, iblue, red, green, blue; XColor start, end, color; XGCValues values; GC gc; double i, inc, x, y, xend, yend; Pixmap pixmap; XawArgVal *argval; int orientation, dimension, steps; char *value; if (XmuCompareISOLatin1(params->name, "vertical") == 0) orientation = VERTICAL; else if (XmuCompareISOLatin1(params->name, "horizontal") == 0) orientation = HORIZONTAL; else return (False); if ((argval = XawFindArgVal(params, "dimension")) != NULL && argval->value) { dimension = atoi(argval->value); if (dimension <= 0) return (False); } else dimension = 50; if ((argval = XawFindArgVal(params, "steps")) != NULL && argval->value) { steps = atoi(argval->value); if (steps <= 0) return (False); } else steps = dimension; steps = XawMin(steps, dimension); value = NULL; if ((argval = XawFindArgVal(params, "start")) != NULL) value = argval->value; if (value && !XAllocNamedColor(DisplayOfScreen(screen), colormap, value, &start, &color)) return (False); else if (!value) { start.pixel = WhitePixelOfScreen(screen); XQueryColor(DisplayOfScreen(screen), colormap, &start); } value = NULL; if ((argval = XawFindArgVal(params, "end")) != NULL) value = argval->value; if (value && !XAllocNamedColor(DisplayOfScreen(screen), colormap, value, &end, &color)) return (False); else if (!value) { end.pixel = BlackPixelOfScreen(screen); XQueryColor(DisplayOfScreen(screen), colormap, &end); } if ((pixmap = XCreatePixmap(DisplayOfScreen(screen), RootWindowOfScreen(screen), orientation == VERTICAL ? 1 : dimension, orientation == VERTICAL ? dimension : 1, depth)) == 0) return (False); ired = (double)(end.red - start.red) / (double)steps; igreen = (double)(end.green - start.green) / (double)steps; iblue = (double)(end.blue - start.blue) / (double)steps; red = color.red = start.red; green = color.green = start.green; blue = color.blue = start.blue; inc = (double)dimension / (double)steps; gc = XCreateGC(DisplayOfScreen(screen), pixmap, 0, &values); x = y = 0.0; if (orientation == VERTICAL) { xend = 1; yend = 0; } else { xend = 0; yend = 1; } color.flags = DoRed | DoGreen | DoBlue; XSetForeground(DisplayOfScreen(screen), gc, start.pixel); for (i = 0.0; i < dimension; i += inc) { if ((int)color.red != (int)red || (int)color.green != (int)green || (int)color.blue != (int)blue) { XFillRectangle(DisplayOfScreen(screen), pixmap, gc, (int)x, (int)y, (unsigned int)xend, (unsigned int)yend); color.red = (unsigned short)red; color.green = (unsigned short)green; color.blue = (unsigned short)blue; if (!XAllocColor(DisplayOfScreen(screen), colormap, &color)) { XFreePixmap(DisplayOfScreen(screen), pixmap); return (False); } XSetForeground(DisplayOfScreen(screen), gc, color.pixel); if (orientation == VERTICAL) y = yend; else x = xend; } red += ired; green += igreen; blue += iblue; if (orientation == VERTICAL) yend += inc; else xend += inc; } XFillRectangle(DisplayOfScreen(screen), pixmap, gc, (int)x, (int)y, (unsigned int)xend, (unsigned int)yend); *pixmap_return = pixmap; *mask_return = None; *width_return = orientation == VERTICAL ? 1 : dimension; *height_return = orientation == VERTICAL ? dimension : 1; XFreeGC(DisplayOfScreen(screen), gc); return (True); }
/* * Function: * ReadText * * Parameters: * w - AsciiSource widget * pos - position of the text to retreive. * text - text block that will contain returned text * length - maximum number of characters to read * * Description: * This function reads the source. * * Returns: * The character position following the retrieved text. */ static XawTextPosition ReadText(Widget w, XawTextPosition pos, XawTextBlock *text, int length) { AsciiSrcObject src = (AsciiSrcObject)w; XawTextPosition count, start; Piece *piece; #ifndef OLDXAW XawTextAnchor *anchor; XawTextEntity *entity; XawTextPosition offset, end = pos + length; Bool state; end = XawMin(end, src->ascii_src.length); while ((state = XawTextSourceAnchorAndEntity(w, pos, &anchor, &entity)) && (entity->flags & XAW_TENTF_HIDE)) pos = anchor->position + entity->offset + entity->length; if (state == False || !(entity->flags & XAW_TENTF_REPLACE)) { while (entity) { offset = anchor->position + entity->offset; if (offset >= end) break; if (offset > pos && (entity->flags & (XAW_TENTF_HIDE | XAW_TENTF_REPLACE))) { end = XawMin(end, offset); break; } if ((entity = entity->next) == NULL && (anchor = XawTextSourceNextAnchor(w, anchor)) != NULL) entity = anchor->entities; } } else if (state && (entity->flags & XAW_TENTF_REPLACE) && pos < end) { XawTextBlock *block = (XawTextBlock*)entity->data; offset = anchor->position + entity->offset; end = XawMin(end, offset + block->length); if ((length = end - pos) < 0) length = 0; text->length = length; text->format = XawFmt8Bit; if (length == 0) { text->firstPos = end = offset + entity->length; text->ptr = ""; } else { text->firstPos = pos; text->ptr = block->ptr + (pos - offset); if (pos + length < offset + block->length) end = pos + length; /* there is data left to be read */ else end = offset + entity->length; } return (end); } if ((length = end - pos) < 0) length = 0; #endif piece = FindPiece(src, pos, &start); text->firstPos = pos; text->ptr = piece->text + (pos - start); count = piece->used - (pos - start); text->length = Max(0, (length > count) ? count : length); text->format = XawFmt8Bit; return (pos + text->length); }