Lines Matching defs:ctx
75 #define IsValidLine(ctx, num) ( ((num) == 0) || \
76 ((ctx)->text.lt.info[(num)].position != 0) )
90 void _XawTextPrepareToUpdate(TextWidget ctx);
338 * Arguments: ctx - the text widget.
343 PositionHScrollBar(ctx)
344 TextWidget ctx;
346 Widget vbar = ctx->text.vbar, hbar = ctx->text.hbar;
349 if (ctx->text.hbar == NULL) return;
354 XtResizeWidget( hbar, ctx->core.width - left, hbar->core.height,
359 top = ctx->core.height - ( hbar->core.height + hbar->core.border_width);
365 * Arguments: ctx - the text widget.
370 PositionVScrollBar(ctx)
371 TextWidget ctx;
373 Widget vbar = ctx->text.vbar;
379 XtResizeWidget( vbar, vbar->core.width, ctx->core.height, bw);
384 CreateVScrollBar(ctx)
385 TextWidget ctx;
389 if (ctx->text.vbar != NULL) return;
391 ctx->text.vbar = vbar =
392 XtCreateWidget("vScrollbar", scrollbarWidgetClass, (Widget)ctx, NULL, ZERO);
393 XtAddCallback( vbar, XtNscrollProc, VScroll, (caddr_t)ctx );
394 XtAddCallback( vbar, XtNjumpProc, VJump, (caddr_t)ctx );
396 ctx->text.r_margin.left += vbar->core.width + vbar->core.border_width;
397 ctx->text.margin.left = ctx->text.r_margin.left;
399 PositionVScrollBar(ctx);
400 PositionHScrollBar(ctx); /* May modify location of Horiz. Bar. */
402 if (XtIsRealized((Widget)ctx)) {
410 * Arguments: ctx - the parent text widget.
415 DestroyVScrollBar(ctx)
416 TextWidget ctx;
418 Widget vbar = ctx->text.vbar;
422 ctx->text.r_margin.left -= vbar->core.width + vbar->core.border_width;
423 ctx->text.margin.left = ctx->text.r_margin.left;
425 ctx->text.vbar = NULL;
426 PositionHScrollBar(ctx);
430 CreateHScrollBar(ctx)
431 TextWidget ctx;
436 if (ctx->text.hbar != NULL) return;
439 ctx->text.hbar = hbar =
440 XtCreateWidget("hScrollbar", scrollbarWidgetClass, (Widget)ctx, args, ONE);
441 XtAddCallback( hbar, XtNscrollProc, HScroll, (caddr_t)ctx );
442 XtAddCallback( hbar, XtNjumpProc, HJump, (caddr_t)ctx );
444 PositionHScrollBar(ctx);
445 if (XtIsRealized((Widget)ctx)) {
453 * Arguments: ctx - the parent text widget.
458 DestroyHScrollBar(ctx)
459 TextWidget ctx;
461 Widget hbar = ctx->text.hbar;
466 ctx->text.r_margin.bottom -= hbar->core.height + hbar->core.border_width;
467 ctx->text.margin.bottom = ctx->text.r_margin.bottom;
471 ctx->text.hbar = NULL;
481 TextWidget ctx = (TextWidget) new;
487 ctx->text.lt.lines = 0;
488 ctx->text.lt.info = NULL;
489 bzero((char *) &(ctx->text.origSel), sizeof(XawTextSelection));
490 bzero((char *) &(ctx->text.s), sizeof(XawTextSelection));
491 ctx->text.s.type = XawselectPosition;
492 ctx->text.hbar = ctx->text.vbar = (Widget) NULL;
493 ctx->text.lasttime = 0; /* ||| correct? */
494 ctx->text.time = 0; /* ||| correct? */
495 ctx->text.showposition = TRUE;
496 ctx->text.lastPos = (ctx->text.source != NULL) ? GETLASTPOS : 0;
497 ctx->text.file_insert = NULL;
498 ctx->text.search = NULL;
499 ctx->text.updateFrom = (XawTextPosition *) XtMalloc(ONE);
500 ctx->text.updateTo = (XawTextPosition *) XtMalloc(ONE);
501 ctx->text.numranges = ctx->text.maxranges = 0;
502 ctx->text.gc = DefaultGCOfScreen(XtScreen(ctx));
503 ctx->text.hasfocus = FALSE;
504 ctx->text.margin = ctx->text.r_margin; /* Strucure copy. */
505 ctx->text.update_disabled = FALSE;
506 ctx->text.old_insert = -1;
507 ctx->text.mult = 1;
508 ctx->text.single_char = FALSE;
514 if (ctx->text.options != 0)
515 XawTextChangeOptions((Widget) ctx, ctx->text.options);
519 if (ctx->core.height == DEFAULT_TEXT_HEIGHT) {
520 ctx->core.height = VMargins(ctx);
521 if (ctx->text.sink != NULL)
522 ctx->core.height += XawTextSinkMaxHeight(ctx->text.sink, 1);
525 if (ctx->text.scroll_vert != XawtextScrollNever)
526 if ( (ctx->text.resize == XawtextResizeHeight) ||
527 (ctx->text.resize == XawtextResizeBoth) ) {
528 sprintf(error_buf, "Text Widget (%s):\n %s %s.", ctx->core.name,
532 ctx->text.scroll_vert = XawtextScrollNever;
534 else if (ctx->text.scroll_vert == XawtextScrollAlways)
535 CreateVScrollBar(ctx);
537 if (ctx->text.scroll_horiz != XawtextScrollNever)
538 if (ctx->text.wrap != XawtextWrapNever) {
539 sprintf(error_buf, "Text Widget (%s):\n %s %s.", ctx->core.name,
543 ctx->text.scroll_horiz = XawtextScrollNever;
545 else if ( (ctx->text.resize == XawtextResizeWidth) ||
546 (ctx->text.resize == XawtextResizeBoth) ) {
547 sprintf(error_buf, "Text Widget (%s):\n %s %s.", ctx->core.name,
551 ctx->text.scroll_horiz = XawtextScrollNever;
553 else if (ctx->text.scroll_horiz == XawtextScrollAlways)
554 CreateHScrollBar(ctx);
563 TextWidget ctx = (TextWidget)w;
568 if (ctx->text.hbar != NULL) { /* Put up Hbar -- Must be first. */
569 XtRealizeWidget(ctx->text.hbar);
570 XtMapWidget(ctx->text.hbar);
573 if (ctx->text.vbar != NULL) { /* Put up Vbar. */
574 XtRealizeWidget(ctx->text.vbar);
575 XtMapWidget(ctx->text.vbar);
578 _XawTextBuildLineTable(ctx, ctx->text.lt.top, TRUE);
579 _XawTextSetScrollBars(ctx);
620 * the value of ctx->insertPos and an implicit argument. In the event that
629 TextWidget ctx = (TextWidget)w;
633 if (ctx->text.lt.lines < 1) return;
635 if ( LineAndXYForPosition(ctx, ctx->text.insertPos, &line, &x, &y) ) {
636 if (line < ctx->text.lt.lines)
637 y += (ctx->text.lt.info[line + 1].y - ctx->text.lt.info[line].y) + 1;
639 y += (ctx->text.lt.info[line].y - ctx->text.lt.info[line - 1].y) + 1;
641 if (ctx->text.display_caret)
642 XawTextSinkInsertCursor(ctx->text.sink, x, y, state);
644 ctx->text.ev_x = x;
645 ctx->text.ev_y = y;
655 _XawTextNeedsUpdating(ctx, left, right)
656 TextWidget ctx;
661 for (i = 0; i < ctx->text.numranges; i++) {
662 if (left <= ctx->text.updateTo[i] && right >= ctx->text.updateFrom[i]) {
663 ctx->text.updateFrom[i] = Min(left, ctx->text.updateFrom[i]);
664 ctx->text.updateTo[i] = Max(right, ctx->text.updateTo[i]);
668 ctx->text.numranges++;
669 if (ctx->text.numranges > ctx->text.maxranges) {
670 ctx->text.maxranges = ctx->text.numranges;
671 i = ctx->text.maxranges * sizeof(XawTextPosition);
672 ctx->text.updateFrom = (XawTextPosition *)
673 XtRealloc((char *)ctx->text.updateFrom, (unsigned) i);
674 ctx->text.updateTo = (XawTextPosition *)
675 XtRealloc((char *)ctx->text.updateTo, (unsigned) i);
677 ctx->text.updateFrom[ctx->text.numranges - 1] = left;
678 ctx->text.updateTo[ctx->text.numranges - 1] = right;
689 _XawTextGetText(ctx, left, right)
690 TextWidget ctx;
699 left = SrcRead(ctx->text.source, left, &text, right - left);
710 _XawTextGetSTRING(ctx, left, right)
711 TextWidget ctx;
718 s = (unsigned char *)_XawTextGetText(ctx, left, right);
744 PositionForXY (ctx, x, y)
745 TextWidget ctx;
751 if (ctx->text.lt.lines == 0) return 0;
753 for (line = 0; line < ctx->text.lt.lines - 1; line++) {
754 if (y <= ctx->text.lt.info[line + 1].y)
757 position = ctx->text.lt.info[line].position;
758 if (position >= ctx->text.lastPos)
759 return(ctx->text.lastPos);
760 fromx = (int) ctx->text.margin.left;
761 XawTextSinkFindPosition( ctx->text.sink, position, fromx, x - fromx,
763 if (position >= ctx->text.lt.info[line + 1].position)
764 position = SrcScan(ctx->text.source, ctx->text.lt.info[line + 1].position,
766 if (position > ctx->text.lastPos) position = ctx->text.lastPos;
778 LineForPosition (ctx, position)
779 TextWidget ctx;
784 for (line = 0; line < ctx->text.lt.lines; line++)
785 if (position < ctx->text.lt.info[line + 1].position)
798 LineAndXYForPosition (ctx, pos, line, x, y)
799 TextWidget ctx;
809 *x = ctx->text.margin.left;
810 *y = ctx->text.margin.top;
811 if (visible = IsPositionVisible(ctx, pos)) {
812 *line = LineForPosition(ctx, pos);
813 *y = ctx->text.lt.info[*line].y;
814 *x = ctx->text.margin.left;
815 linePos = ctx->text.lt.info[*line].position;
816 XawTextSinkFindDistance( ctx->text.sink, linePos,
832 _XawTextBuildLineTable (ctx, position, force_rebuild)
833 TextWidget ctx;
841 if (ctx->core.height > VMargins(ctx)) {
842 height = ctx->core.height - VMargins(ctx);
843 lines = XawTextSinkMaxLines(ctx->text.sink, height);
847 if ( (lines != ctx->text.lt.lines) || (ctx->text.lt.info == NULL) ) {
848 ctx->text.lt.info = (XawTextLineTableEntry *) XtRealloc((char *) ctx->text.
850 ctx->text.lt.lines = lines;
854 if ( force_rebuild || (position != ctx->text.lt.top) ) {
855 bzero((char *) ctx->text.lt.info, size);
856 (void) _BuildLineTable(ctx, ctx->text.lt.top = position, zeroPosition, 0);
865 _BuildLineTable(ctx, position, min_pos, line)
866 TextWidget ctx;
870 XawTextLineTableEntry * lt = ctx->text.lt.info + line;
874 Widget src = ctx->text.source;
876 if ( ((ctx->text.resize == XawtextResizeWidth) ||
877 (ctx->text.resize == XawtextResizeBoth) ) ||
878 (ctx->text.wrap == XawtextWrapNever) )
881 width = Max(0, (ctx->core.width - HMargins(ctx)));
883 y = ( (line == 0) ? ctx->text.margin.top : lt->y );
889 XawTextSinkFindPosition( ctx->text.sink, position, ctx->text.margin.left,
890 width, ctx->text.wrap == XawtextWrapWord,
895 if (ctx->text.wrap == XawtextWrapNever)
898 if ( endPos == ctx->text.lastPos) { /* We have reached the end. */
905 if ( (line > ctx->text.lt.lines) ||
926 if (line++ < ctx->text.lt.lines) { /* make sure not to run of the end. */
927 (++lt)->y = (count == 0) ? y : ctx->core.height;
929 lt->position = ctx->text.lastPos + 100;
932 if (line < ctx->text.lt.lines) /* Clear out rest of table. */
934 (ctx->text.lt.lines - line) * sizeof(XawTextLineTableEntry) );
936 ctx->text.lt.info[ctx->text.lt.lines].position = lt->position;
944 * Arguments: ctx - the text widget.
951 GetWidestLine(ctx)
952 TextWidget ctx;
956 XawTextLineTablePtr lt = &(ctx->text.lt);
966 CheckVBarScrolling(ctx)
967 TextWidget ctx;
970 Boolean temp = (ctx->text.vbar == NULL);
972 if (ctx->text.scroll_vert == XawtextScrollNever) return;
974 if ( (ctx->text.lastPos > 0) && (ctx->text.lt.lines > 0)) {
975 first = ctx->text.lt.top;
976 first /= (float) ctx->text.lastPos;
977 last = ctx->text.lt.info[ctx->text.lt.lines].position;
978 if ( ctx->text.lt.info[ctx->text.lt.lines].position <= ctx->text.lastPos)
979 last /= (float) ctx->text.lastPos;
983 if (ctx->text.scroll_vert == XawtextScrollWhenNeeded)
985 CreateVScrollBar(ctx);
987 DestroyVScrollBar(ctx);
989 if (ctx->text.vbar != NULL)
990 XawScrollbarSetThumb(ctx->text.vbar, first, last - first);
992 if ( (ctx->text.vbar == NULL) != temp) {
993 _XawTextNeedsUpdating(ctx, zeroPosition, ctx->text.lastPos);
994 if (ctx->text.vbar == NULL)
995 _XawTextBuildLineTable (ctx, zeroPosition, FALSE);
998 else if (ctx->text.vbar != NULL)
999 if (ctx->text.scroll_vert == XawtextScrollWhenNeeded)
1000 DestroyVScrollBar(ctx);
1001 else if (ctx->text.scroll_vert == XawtextScrollAlways)
1002 XawScrollbarSetThumb(ctx->text.vbar, 0.0, 1.0);
1012 _XawTextSetScrollBars(ctx)
1013 TextWidget ctx;
1016 Boolean temp = (ctx->text.hbar == NULL);
1018 CheckVBarScrolling(ctx);
1020 if (ctx->text.scroll_horiz == XawtextScrollNever) return;
1022 if (ctx->text.vbar != NULL)
1023 widest = (ctx->core.width - ctx->text.vbar->core.width -
1024 ctx->text.vbar->core.border_width);
1026 widest = ctx->core.width;
1027 widest /= (last = GetWidestLine(ctx));
1028 if (ctx->text.scroll_horiz == XawtextScrollWhenNeeded)
1030 CreateHScrollBar(ctx);
1032 DestroyHScrollBar(ctx);
1034 if (ctx->text.hbar != NULL) {
1035 first = ctx->text.r_margin.left - ctx->text.margin.left;
1037 XawScrollbarSetThumb(ctx->text.hbar, first, widest);
1039 else if (ctx->text.margin.left != ctx->text.r_margin.left) {
1040 ctx->text.margin.left = ctx->text.r_margin.left;
1041 _XawTextNeedsUpdating(ctx, zeroPosition, ctx->text.lastPos);
1044 if ( (ctx->text.hbar == NULL) != temp ) {
1045 _XawTextBuildLineTable (ctx, ctx->text.lt.top, TRUE);
1046 CheckVBarScrolling(ctx);
1057 _XawTextVScroll(ctx, n)
1058 TextWidget ctx;
1063 XawTextLineTable * lt = &(ctx->text.lt);
1065 if (abs(n) > ctx->text.lt.lines)
1066 n = (n > 0) ? ctx->text.lt.lines : -ctx->text.lt.lines;
1071 if ( IsValidLine(ctx, n) )
1072 top = Min(lt->info[n].position, ctx->text.lastPos);
1074 top = ctx->text.lastPos;
1076 y = IsValidLine(ctx, n) ? lt->info[n].y : ctx->core.height;
1077 _XawTextBuildLineTable(ctx, top, FALSE);
1078 if (top >= ctx->text.lastPos)
1079 DisplayTextWindow( (Widget) ctx);
1081 XCopyArea(XtDisplay(ctx), XtWindow(ctx), XtWindow(ctx), ctx->text.gc,
1082 0, y, (int)ctx->core.width, (int)ctx->core.height - y,
1083 0, ctx->text.margin.top);
1084 SinkClearToBG(ctx->text.sink,
1086 (Position) (ctx->text.margin.top + ctx->core.height - y),
1087 (Dimension) ctx->core.width, (Dimension) ctx->core.height);
1090 _XawTextNeedsUpdating(ctx, lt->info[lt->lines - n].position,
1091 ctx->text.lastPos);
1092 _XawTextSetScrollBars(ctx);
1101 top = SrcScan(ctx->text.source, target, XawstEOL,
1104 _XawTextBuildLineTable(ctx, top, FALSE);
1105 y = IsValidLine(ctx, n) ? lt->info[n].y : ctx->core.height;
1106 updateTo = IsValidLine(ctx, n) ? lt->info[n].position : ctx->text.lastPos;
1107 if (IsValidLine(ctx, lt->lines - n))
1108 height = lt->info[lt->lines-n].y - ctx->text.margin.top;
1109 else if (ctx->core.height - HMargins(ctx))
1110 height = ctx->core.height - HMargins(ctx);
1113 if (y > (int) ctx->text.margin.top)
1114 clear_height = y - ctx->text.margin.top;
1119 XCopyArea(XtDisplay(ctx), XtWindow(ctx), XtWindow(ctx), ctx->text.gc,
1120 0, ctx->text.margin.top, (int) ctx->core.width, height, 0, y);
1121 SinkClearToBG(ctx->text.sink, (Position) 0, ctx->text.margin.top,
1122 (Dimension) ctx->core.width, (Dimension) clear_height);
1124 _XawTextNeedsUpdating(ctx, lt->info[0].position, updateTo);
1125 _XawTextSetScrollBars(ctx);
1128 DisplayTextWindow((Widget)ctx);
1139 TextWidget ctx = (TextWidget) closure;
1140 Widget tw = (Widget) ctx;
1144 _XawTextPrepareToUpdate(ctx);
1146 old_left = ctx->text.margin.left;
1147 ctx->text.margin.left -= pixels;
1148 if (ctx->text.margin.left > ctx->text.r_margin.left) {
1149 ctx->text.margin.left = ctx->text.r_margin.left;
1150 pixels = old_left - ctx->text.margin.left;
1154 rect.width = (unsigned short) pixels + ctx->text.margin.right;
1155 rect.x = (short) ctx->core.width - (short) rect.width;
1156 rect.y = (short) ctx->text.margin.top;
1157 rect.height = (unsigned short) ctx->core.height - rect.y;
1159 XCopyArea(XtDisplay(tw), XtWindow(tw), XtWindow(tw), ctx->text.gc,
1161 (unsigned int) rect.x, (unsigned int) ctx->core.height,
1167 if (ctx->text.vbar != NULL)
1168 rect.x += (short) (ctx->text.vbar->core.width +
1169 ctx->text.vbar->core.border_width);
1172 rect.y = ctx->text.margin.top;
1173 rect.height = ctx->core.height - rect.y;
1175 XCopyArea(XtDisplay(tw), XtWindow(tw), XtWindow(tw), ctx->text.gc,
1177 (unsigned int) ctx->core.width - rect.width,
1185 t_rect.x = ctx->core.width - ctx->text.margin.right;
1186 t_rect.width = ctx->text.margin.right;
1190 SinkClearToBG(ctx->text.sink, (Position) t_rect.x, (Position) t_rect.y,
1193 UpdateTextInRectangle(ctx, &t_rect);
1201 SinkClearToBG(ctx->text.sink, (Position) rect.x, (Position) rect.y,
1204 UpdateTextInRectangle(ctx, &rect);
1206 _XawTextExecuteUpdate(ctx);
1207 _XawTextSetScrollBars(ctx);
1216 TextWidget ctx = (TextWidget) closure;
1218 Position move, new_left, old_left = ctx->text.margin.left;
1220 new_left = ctx->text.r_margin.left;
1221 new_left -= (Position) (*percent * GetWidestLine(ctx));
1224 if (abs(move) < ctx->core.width) {
1225 HScroll(w, (caddr_t) ctx, (caddr_t) move);
1228 _XawTextPrepareToUpdate(ctx);
1229 ctx->text.margin.left = new_left;
1230 if (XtIsRealized((Widget) ctx)) DisplayTextWindow((Widget) ctx);
1231 _XawTextExecuteUpdate(ctx);
1236 * Arguments: ctx - the text widget.
1244 UpdateTextInLine(ctx, line, left, right)
1245 TextWidget ctx;
1251 XawTextLineTableEntry * lt = ctx->text.lt.info + line;
1253 if ( ((lt->textWidth + ctx->text.margin.left) < left) ||
1254 ( ctx->text.margin.left > right ) )
1257 local_width = left - ctx->text.margin.left;
1258 XawTextSinkFindPosition(ctx->text.sink, lt->position,
1259 (int) ctx->text.margin.left,
1262 if (right >= (Position) lt->textWidth - ctx->text.margin.left)
1263 if ( (IsValidLine(ctx, line + 1)) &&
1264 (ctx->text.lt.info[line + 1].position <= ctx->text.lastPos) )
1265 pos2 = SrcScan( ctx->text.source, (lt + 1)->position, XawstPositions,
1272 local_left = ctx->text.margin.left + width;
1274 XawTextSinkFindPosition(ctx->text.sink, pos1, local_left,
1277 t_pos = SrcScan( ctx->text.source, pos2,
1283 _XawTextNeedsUpdating(ctx, pos1, pos2);
1298 TextWidget ctx = (TextWidget)closure;
1301 height = ctx->core.height - VMargins(ctx);
1304 lines = (int) (lines * (int) ctx->text.lt.lines) / height;
1305 _XawTextPrepareToUpdate(ctx);
1306 _XawTextVScroll(ctx, lines);
1307 _XawTextExecuteUpdate(ctx);
1329 TextWidget ctx = (TextWidget)closure;
1331 XawTextLineTable * lt = &(ctx->text.lt);
1333 _XawTextPrepareToUpdate(ctx);
1335 if ( (lt->lines > 0) && (IsValidLine(ctx, lt->lines - 1)) )
1338 old_bot = ctx->text.lastPos;
1340 position = (long) (*percent * (float) ctx->text.lastPos);
1341 position= SrcScan(ctx->text.source, position, XawstEOL, XawsdLeft, 1, FALSE);
1345 _XawTextVScroll(ctx, line);
1349 _XawTextBuildLineTable(ctx, position, FALSE);
1350 new_bot = IsValidLine(ctx, lt->lines-1) ? lt->info[lt->lines-1].position
1351 : ctx->text.lastPos;
1356 _XawTextBuildLineTable(ctx, old_top, FALSE);
1357 _XawTextVScroll(ctx, -line);
1360 DisplayTextWindow( (Widget) ctx);
1362 _XawTextExecuteUpdate(ctx);
1375 TextWidget ctx = (TextWidget)w;
1376 Widget src = ctx->text.source;
1387 XmuConvertStandardSelection(w, ctx->text.time, selection,
1425 *value = _XawTextGetSTRING(ctx, ctx->text.s.left, ctx->text.s.right);
1438 *temp = (long) (ctx->text.s.right - ctx->text.s.left);
1451 temp[0] = (long) (ctx->text.s.left + 1);
1452 temp[1] = ctx->text.s.right;
1463 _XawTextZapSelection( ctx, (XEvent *) NULL, TRUE);
1471 if (XmuConvertStandardSelection(w, ctx->text.time, selection, target, type,
1508 TextWidget ctx = (TextWidget) w;
1512 _XawTextPrepareToUpdate(ctx);
1514 atomP = ctx->text.s.selections;
1515 for (i = 0 ; i < ctx->text.s.atom_count; i++, atomP++)
1520 while (ctx->text.s.atom_count &&
1521 ctx->text.s.selections[ctx->text.s.atom_count-1] == 0)
1522 ctx->text.s.atom_count--;
1528 atomP = ctx->text.s.selections;
1529 for (i = 0 ; i < ctx->text.s.atom_count; i++, atomP++)
1531 *atomP = ctx->text.s.selections[--ctx->text.s.atom_count];
1532 while (ctx->text.s.atom_count &&
1533 ctx->text.s.selections[ctx->text.s.atom_count-1] == 0)
1534 ctx->text.s.atom_count--;
1537 if (ctx->text.s.atom_count == 0)
1538 ModifySelection(ctx, ctx->text.insertPos, ctx->text.insertPos);
1540 if (ctx->text.old_insert >= 0) /* Update in progress. */
1541 _XawTextExecuteUpdate(ctx);
1545 _SetSelection(ctx, left, right, selections, count)
1546 TextWidget ctx;
1553 if (left < ctx->text.s.left) {
1554 pos = Min(right, ctx->text.s.left);
1555 _XawTextNeedsUpdating(ctx, left, pos);
1557 if (left > ctx->text.s.left) {
1558 pos = Min(left, ctx->text.s.right);
1559 _XawTextNeedsUpdating(ctx, ctx->text.s.left, pos);
1561 if (right < ctx->text.s.right) {
1562 pos = Max(right, ctx->text.s.left);
1563 _XawTextNeedsUpdating(ctx, pos, ctx->text.s.right);
1565 if (right > ctx->text.s.right) {
1566 pos = Max(left, ctx->text.s.right);
1567 _XawTextNeedsUpdating(ctx, pos, right);
1570 ctx->text.s.left = left;
1571 ctx->text.s.right = right;
1573 SrcSetSelection(ctx->text.source, left, right,
1577 Widget w = (Widget) ctx;
1588 ptr = _XawTextGetSTRING(ctx, ctx->text.s.left, ctx->text.s.right);
1597 XtOwnSelection(w, selection, ctx->text.time,
1603 XawTextUnsetSelection((Widget)ctx);
1615 _XawTextReplace (ctx, pos1, pos2, text)
1616 TextWidget ctx;
1622 Widget src = ctx->text.source;
1626 ctx->text.update_disabled = True; /* No redisplay during replacement. */
1635 if ((pos1 == ctx->text.insertPos) && (edit_mode == XawtextAppend)) {
1636 ctx->text.insertPos = ctx->text.lastPos;
1637 pos2 = SrcScan(src, ctx->text.insertPos, XawstPositions, XawsdRight,
1638 (ctx->text.insertPos - pos1), TRUE);
1639 pos1 = ctx->text.insertPos;
1641 ctx->text.update_disabled = FALSE; /* rearm redisplay. */
1648 updateFrom = Max(updateFrom, ctx->text.lt.top);
1650 line1 = LineForPosition(ctx, updateFrom);
1652 ctx->text.update_disabled = FALSE; /* rearm redisplay. */
1656 XawTextUnsetSelection((Widget)ctx);
1658 ctx->text.lastPos = GETLASTPOS;
1659 if (ctx->text.lt.top >= ctx->text.lastPos) {
1660 _XawTextBuildLineTable(ctx, ctx->text.lastPos, FALSE);
1661 ClearWindow( (Widget) ctx);
1662 ctx->text.update_disabled = FALSE; /* rearm redisplay. */
1669 ctx->text.single_char = TRUE;
1671 ctx->text.single_char = FALSE;
1673 if (delta < ctx->text.lastPos) {
1674 for (pos2 += delta, i = 0; i < ctx->text.numranges; i++) {
1675 if (ctx->text.updateFrom[i] > pos1)
1676 ctx->text.updateFrom[i] += delta;
1677 if (ctx->text.updateTo[i] >= pos1)
1678 ctx->text.updateTo[i] += delta;
1689 i = LineForPosition(ctx, pos1) + 1;
1690 for (lineP = ctx->text.lt.info + i; i <= ctx->text.lt.lines; i++, lineP++)
1700 if (IsPositionVisible(ctx, updateFrom)) {
1701 updateTo = _BuildLineTable(ctx,
1702 ctx->text.lt.info[line1].position, pos1, line1);
1703 _XawTextNeedsUpdating(ctx, updateFrom, updateTo);
1706 ctx->text.update_disabled = FALSE; /* rearm redisplay. */
1724 TextWidget ctx = (TextWidget)w;
1726 int height, line, i, lastPos = ctx->text.lastPos;
1730 pos1 = (pos1 < ctx->text.lt.top) ? ctx->text.lt.top : pos1;
1731 pos2 = FindGoodPosition(ctx, pos2);
1732 if ( (pos1 >= pos2) || !LineAndXYForPosition(ctx, pos1, &line, &x, &y) )
1735 for ( startPos = pos1, i = line; IsValidLine(ctx, i) &&
1736 (i < ctx->text.lt.lines) ; i++) {
1739 if ( (endPos = ctx->text.lt.info[i + 1].position) > pos2 ) {
1741 done_painting = (!clear_eol || ctx->text.single_char);
1748 height = ctx->text.lt.info[i + 1].y - ctx->text.lt.info[i].y;
1751 if ( (x == (Position) ctx->text.margin.left) && (x > 0) )
1752 SinkClearToBG (ctx->text.sink,
1754 (Dimension) ctx->text.margin.left, (Dimension)height);
1756 if ( (startPos >= ctx->text.s.right) || (endPos <= ctx->text.s.left) )
1757 XawTextSinkDisplayText(ctx->text.sink, x, y, startPos, endPos, FALSE);
1758 else if ((startPos >= ctx->text.s.left) && (endPos <= ctx->text.s.right))
1759 XawTextSinkDisplayText(ctx->text.sink, x, y, startPos, endPos, TRUE);
1761 DisplayText(w, startPos, ctx->text.s.left);
1762 DisplayText(w, Max(startPos, ctx->text.s.left),
1763 Min(endPos, ctx->text.s.right));
1764 DisplayText(w, ctx->text.s.right, endPos);
1769 SinkClearToBG(ctx->text.sink,
1770 (Position) (ctx->text.lt.info[i].textWidth +
1771 ctx->text.margin.left),
1787 SinkClearToBG(ctx->text.sink,
1788 (Position) ctx->text.margin.left, (Position) y,
1795 x = (Position) ctx->text.margin.left;
1796 y = ctx->text.lt.info[i + 1].y;
1797 if ( done_painting || (y >= ctx->core.height - ctx->text.margin.bottom) )
1800 ctx->text.single_char = FALSE;
1814 DoSelection (ctx, pos, time, motion)
1815 TextWidget ctx;
1822 Widget src = ctx->text.source;
1825 newType = ctx->text.s.type;
1827 if ( (abs((long) time - (long) ctx->text.lasttime) < MULTI_CLICK_TIME) &&
1828 ((pos >= ctx->text.s.left) && (pos <= ctx->text.s.right))) {
1829 sarray = ctx->text.sarray;
1830 for (;*sarray != XawselectNull && *sarray != ctx->text.s.type; sarray++);
1833 newType = *(ctx->text.sarray);
1837 newType = *(ctx->text.sarray);
1841 newType = *(ctx->text.sarray);
1843 ctx->text.lasttime = time;
1870 XtAppWarning(XtWidgetToApplicationContext((Widget) ctx),
1875 if ( (newLeft != ctx->text.s.left) || (newRight != ctx->text.s.right)
1876 || (newType != ctx->text.s.type)) {
1877 ModifySelection(ctx, newLeft, newRight);
1878 if (pos - ctx->text.s.left < ctx->text.s.right - pos)
1879 ctx->text.insertPos = newLeft;
1881 ctx->text.insertPos = newRight;
1882 ctx->text.s.type = newType;
1885 ctx->text.origSel.type = ctx->text.s.type;
1886 ctx->text.origSel.left = ctx->text.s.left;
1887 ctx->text.origSel.right = ctx->text.s.right;
1889 if (pos >= ctx->text.s.left + ((ctx->text.s.right - ctx->text.s.left) / 2))
1890 ctx->text.extendDir = XawsdRight;
1892 ctx->text.extendDir = XawsdLeft;
1908 ExtendSelection (ctx, pos, motion)
1909 TextWidget ctx;
1916 ctx->text.origSel.type = ctx->text.s.type;
1917 ctx->text.origSel.left = ctx->text.s.left;
1918 ctx->text.origSel.right = ctx->text.s.right;
1919 if (pos >= ctx->text.s.left + ((ctx->text.s.right - ctx->text.s.left) / 2))
1920 ctx->text.extendDir = XawsdRight;
1922 ctx->text.extendDir = XawsdLeft;
1925 if ((ctx->text.extendDir == XawsdRight && pos < ctx->text.origSel.left) ||
1926 (ctx->text.extendDir == XawsdLeft && pos > ctx->text.origSel.right)) {
1927 ctx->text.extendDir = (ctx->text.extendDir == XawsdRight) ?
1929 ModifySelection(ctx, ctx->text.origSel.left, ctx->text.origSel.right);
1932 dir = ctx->text.extendDir;
1933 switch (ctx->text.s.type) {
1935 pos = SrcScan(ctx->text.source, pos, XawstWhiteSpace, dir, 1, FALSE);
1938 pos = SrcScan(ctx->text.source, pos, XawstEOL, dir, 1, dir == XawsdRight);
1941 pos = SrcScan(ctx->text.source, pos, XawstParagraph, dir, 1, FALSE);
1944 pos = ctx->text.insertPos;
1950 if (ctx->text.extendDir == XawsdRight)
1951 ModifySelection(ctx, ctx->text.s.left, pos);
1953 ModifySelection(ctx, pos, ctx->text.s.right);
1955 ctx->text.insertPos = pos;
1966 TextWidget ctx = (TextWidget) w;
1969 SinkClearToBG(ctx->text.sink,
1977 * Arguments: ctx - the text widget.
1982 _XawTextClearAndCenterDisplay(ctx)
1983 TextWidget ctx;
1985 int insert_line = LineForPosition(ctx, ctx->text.insertPos);
1986 int scroll_by = insert_line - ctx->text.lt.lines/2;
1988 _XawTextVScroll(ctx, scroll_by);
1989 DisplayTextWindow( (Widget) ctx);
2001 TextWidget ctx = (TextWidget) w;
2003 _XawTextBuildLineTable(ctx, ctx->text.lt.top, FALSE);
2004 _XawTextNeedsUpdating(ctx, zeroPosition, ctx->text.lastPos);
2005 _XawTextSetScrollBars(ctx);
2015 _XawTextCheckResize(ctx)
2016 TextWidget ctx;
2018 Widget w = (Widget) ctx;
2022 if ( (ctx->text.resize == XawtextResizeWidth) ||
2023 (ctx->text.resize == XawtextResizeBoth) ) {
2026 for (lt = ctx->text.lt.info;
2027 IsValidLine(ctx, line) && (line < ctx->text.lt.lines) ; line++, lt++)
2028 AssignMax(rbox.width, lt->textWidth + ctx->text.margin.left);
2030 rbox.width += ctx->text.margin.right;
2031 if (rbox.width > ctx->core.width) { /* Only get wider. */
2038 if ( !((ctx->text.resize == XawtextResizeHeight) ||
2039 (ctx->text.resize == XawtextResizeBoth)) )
2042 if (IsPositionVisible(ctx, ctx->text.lastPos))
2043 line = LineForPosition(ctx, ctx->text.lastPos);
2045 line = ctx->text.lt.lines;
2047 if ( (line + 1) == ctx->text.lt.lines ) return;
2049 old_height = ctx->core.height;
2051 rbox.height = XawTextSinkMaxHeight(ctx->text.sink, line + 1) + VMargins(ctx);
2059 _XawTextBuildLineTable(ctx, ctx->text.lt.top, TRUE);
2068 _XawTextSelectionList(ctx, list, nelems)
2069 TextWidget ctx;
2073 Atom * sel = ctx->text.s.selections;
2075 if (nelems > ctx->text.s.array_size) {
2077 ctx->text.s.array_size = nelems;
2079 XmuInternStrings(XtDisplay((Widget)ctx), list, nelems, sel);
2080 ctx->text.s.atom_count = nelems;
2081 return(ctx->text.s.selections = sel);
2086 * Arguments: ctx - the text widget.
2092 * NOTE: if (ctx->text.s.left >= ctx->text.s.right) then the selection
2097 _XawTextSetSelection(ctx, l, r, list, nelems)
2098 TextWidget ctx;
2108 _SetSelection(ctx, l, r, _XawTextSelectionList(ctx, list, nelems), nelems);
2114 * Arguments: ctx - the text widget.
2118 * NOTE: if (ctx->text.s.left >= ctx->text.s.right) then the selection
2123 ModifySelection(ctx, left, right)
2124 TextWidget ctx;
2128 ctx->text.insertPos = left;
2129 _SetSelection( ctx, left, right, (Atom *)NULL, ZERO);
2139 _XawTextAlterSelection (ctx, mode, action, params, num_params)
2140 TextWidget ctx;
2155 if (ctx->text.search != NULL)
2156 ctx->text.search->selection_changed = TRUE;
2158 position = PositionForXY (ctx, (int) ctx->text.ev_x, (int) ctx->text.ev_y);
2162 DoSelection (ctx, position, ctx->text.time, flag);
2164 ExtendSelection (ctx, position, flag);
2167 _XawTextSetSelection(ctx, ctx->text.s.left, ctx->text.s.right,
2189 * Arguments: ctx - the text widget.
2195 UpdateTextInRectangle(ctx, rect)
2196 TextWidget ctx;
2199 XawTextLineTableEntry *info = ctx->text.lt.info;
2203 for (line = 0;( (line < ctx->text.lt.lines) &&
2204 IsValidLine(ctx, line) && (info->y < bottom)); line++, info++)
2206 UpdateTextInLine(ctx, line, x, right);
2222 TextWidget ctx = (TextWidget) w;
2238 _XawTextPrepareToUpdate(ctx);
2239 UpdateTextInRectangle(ctx, &expose);
2240 XawTextSinkGetCursorBounds(ctx->text.sink, &cursor);
2242 SinkClearToBG(ctx->text.sink, (Position) cursor.x, (Position) cursor.y,
2244 UpdateTextInRectangle(ctx, &cursor);
2246 _XawTextExecuteUpdate(ctx);
2254 _XawTextPrepareToUpdate(ctx)
2255 TextWidget ctx;
2257 if (ctx->text.old_insert < 0) {
2258 InsertCursor((Widget)ctx, XawisOff);
2259 ctx->text.numranges = 0;
2260 ctx->text.showposition = FALSE;
2261 ctx->text.old_insert = ctx->text.insertPos;
2272 void FlushUpdate(ctx)
2273 TextWidget ctx;
2277 if (!XtIsRealized((Widget)ctx)) {
2278 ctx->text.numranges = 0;
2281 while (ctx->text.numranges > 0) {
2282 updateFrom = ctx->text.updateFrom[0];
2284 for (i = 1 ; i < ctx->text.numranges ; i++) {
2285 if (ctx->text.updateFrom[i] < updateFrom) {
2286 updateFrom = ctx->text.updateFrom[i];
2290 updateTo = ctx->text.updateTo[w];
2291 ctx->text.numranges--;
2292 ctx->text.updateFrom[w] = ctx->text.updateFrom[ctx->text.numranges];
2293 ctx->text.updateTo[w] = ctx->text.updateTo[ctx->text.numranges];
2294 for (i = ctx->text.numranges - 1 ; i >= 0 ; i--) {
2295 while (ctx->text.updateFrom[i] <= updateTo && i < ctx->text.numranges) {
2296 updateTo = ctx->text.updateTo[i];
2297 ctx->text.numranges--;
2298 ctx->text.updateFrom[i] = ctx->text.updateFrom[ctx->text.numranges];
2299 ctx->text.updateTo[i] = ctx->text.updateTo[ctx->text.numranges];
2302 DisplayText((Widget)ctx, updateFrom, updateTo);
2314 void _XawTextShowPosition(ctx)
2315 TextWidget ctx;
2320 if ( (!XtIsRealized((Widget)ctx)) || (ctx->text.lt.lines <= 0) )
2324 lines = ctx->text.lt.lines;
2325 if ( IsValidLine(ctx, lines))
2326 max_pos = ctx->text.lt.info[lines].position;
2328 max_pos = ctx->text.lastPos + 1;
2339 x = ctx->text.margin.left;
2340 y = ctx->core.height - ctx->text.margin.left;
2341 if (ctx->text.hbar != NULL)
2342 y -= ctx->text.hbar->core.height - 2 * ctx->text.hbar->core.border_width;
2344 max_pos = PositionForXY (ctx, x, y);
2345 max_pos = SrcScan(ctx->text.source, max_pos, XawstEOL, XawsdRight, 1, FALSE);
2347 lines = LineForPosition(ctx, max_pos); /* number of visable lines. */
2350 if ( (ctx->text.insertPos >= ctx->text.lt.top) &&
2351 ((ctx->text.insertPos < max_pos) || ( max_pos > ctx->text.lastPos)) )
2354 first = ctx->text.lt.top;
2355 if (IsValidLine(ctx, 1))
2356 second = ctx->text.lt.info[1].position;
2360 if (ctx->text.insertPos < first)
2365 top = SrcScan(ctx->text.source, ctx->text.insertPos,
2368 _XawTextBuildLineTable(ctx, top, FALSE);
2369 while (ctx->text.insertPos >= ctx->text.lt.info[lines].position) {
2370 if (ctx->text.lt.info[lines].position > ctx->text.lastPos)
2372 _XawTextBuildLineTable(ctx, ctx->text.lt.info[1].position, FALSE);
2374 if (ctx->text.lt.top == second) {
2375 _XawTextBuildLineTable(ctx, first, FALSE);
2376 _XawTextVScroll(ctx, 1);
2377 } else if (ctx->text.lt.info[1].position == first) {
2378 _XawTextBuildLineTable(ctx, first, FALSE);
2379 _XawTextVScroll(ctx, -1);
2381 ctx->text.numranges = 0;
2382 if (ctx->text.lt.top != first)
2383 DisplayTextWindow((Widget)ctx);
2392 _XawTextExecuteUpdate(ctx)
2393 TextWidget ctx;
2395 if ( ctx->text.update_disabled || (ctx->text.old_insert < 0) )
2398 if((ctx->text.old_insert != ctx->text.insertPos) || (ctx->text.showposition))
2399 _XawTextShowPosition(ctx);
2400 FlushUpdate(ctx);
2401 InsertCursor((Widget)ctx, XawisOn);
2402 ctx->text.old_insert = -1;
2410 TextWidget ctx = (TextWidget)w;
2412 if (ctx->text.file_insert != NULL)
2413 XtDestroyWidget(ctx->text.file_insert);
2415 DestroyHScrollBar(ctx);
2416 DestroyVScrollBar(ctx);
2418 XtFree((char *)ctx->text.updateFrom);
2419 XtFree((char *)ctx->text.updateTo);
2431 TextWidget ctx = (TextWidget) w;
2433 PositionVScrollBar(ctx);
2434 PositionHScrollBar(ctx);
2436 _XawTextBuildLineTable(ctx, ctx->text.lt.top, TRUE);
2437 _XawTextSetScrollBars(ctx);
2556 FindGoodPosition(ctx, pos)
2557 TextWidget ctx;
2561 return ( ((pos > ctx->text.lastPos) ? ctx->text.lastPos : pos) );
2608 TextWidget ctx = (TextWidget) w;
2610 ctx->text.source = source;
2611 ctx->text.lt.top = startPos;
2612 ctx->text.s.left = ctx->text.s.right = 0;
2613 ctx->text.insertPos = startPos;
2614 ctx->text.lastPos = GETLASTPOS;
2616 _XawTextBuildLineTable(ctx, ctx->text.lt.top, TRUE);
2633 TextWidget ctx = (TextWidget) w;
2636 _XawTextPrepareToUpdate(ctx);
2637 endPos = FindGoodPosition(ctx, endPos);
2638 startPos = FindGoodPosition(ctx, startPos);
2639 if ((result = _XawTextReplace(ctx, startPos, endPos, text)) == XawEditDone) {
2641 if (ctx->text.insertPos >= (endPos + delta)) {
2643 ctx->text.insertPos = SrcScan(ctx->text.source, ctx->text.insertPos,
2648 _XawTextCheckResize(ctx);
2649 _XawTextExecuteUpdate(ctx);
2650 _XawTextSetScrollBars(ctx);
2667 TextWidget ctx = (TextWidget) w;
2669 _XawTextPrepareToUpdate(ctx);
2670 ctx->text.insertPos = FindGoodPosition(ctx, position);
2671 ctx->text.showposition = TRUE;
2672 _XawTextExecuteUpdate(ctx);
2690 register TextWidget ctx = (TextWidget)w;
2692 while (ctx->text.s.atom_count != 0) {
2693 Atom sel = ctx->text.s.selections[ctx->text.s.atom_count - 1];
2699 XtDisownSelection(w, sel, ctx->text.time);
2712 TextWidget ctx = (TextWidget) w;
2714 ctx->text.options = options;
2716 if (ctx->text.options & scrollVertical)
2717 ctx->text.scroll_vert = XawtextScrollAlways;
2719 ctx->text.scroll_vert = XawtextScrollNever;
2721 if (ctx->text.options & scrollHorizontal)
2722 ctx->text.scroll_horiz = XawtextScrollAlways;
2724 ctx->text.scroll_horiz = XawtextScrollNever;
2726 if (ctx->text.options & resizeWidth) /* Set up resize options. */
2727 if (ctx->text.options & resizeHeight)
2728 ctx->text.resize = XawtextResizeBoth;
2730 ctx->text.resize = XawtextResizeWidth;
2731 else if (ctx->text.options & resizeHeight)
2732 ctx->text.resize = XawtextResizeHeight;
2734 ctx->text.resize = XawtextResizeNever;
2736 if (ctx->text.options & wordBreak)
2737 ctx->text.wrap = XawtextWrapWord;
2739 ctx->text.wrap = XawtextWrapNever;
2755 TextWidget ctx = (TextWidget) w;
2757 _XawTextPrepareToUpdate(ctx);
2758 _XawTextSetSelection(ctx, FindGoodPosition(ctx, left),
2759 FindGoodPosition(ctx, right), (String *)NULL, ZERO);
2760 _XawTextExecuteUpdate(ctx);
2768 TextWidget ctx = (TextWidget) w;
2770 from = FindGoodPosition(ctx, from);
2771 to = FindGoodPosition(ctx, to);
2772 ctx->text.lastPos = GETLASTPOS;
2773 _XawTextPrepareToUpdate(ctx);
2774 _XawTextNeedsUpdating(ctx, from, to);
2775 _XawTextBuildLineTable(ctx, ctx->text.lt.top, TRUE);
2776 _XawTextExecuteUpdate(ctx);
2792 register TextWidget ctx = (TextWidget)w;
2795 if (!ctx->text.update_disabled) return;
2797 ctx->text.update_disabled = False;
2798 lastPos = ctx->text.lastPos = GETLASTPOS;
2799 ctx->text.lt.top = FindGoodPosition(ctx, ctx->text.lt.top);
2800 ctx->text.insertPos = FindGoodPosition(ctx, ctx->text.insertPos);
2801 if ( (ctx->text.s.left > lastPos) || (ctx->text.s.right > lastPos) )
2802 ctx->text.s.left = ctx->text.s.right = 0;
2804 _XawTextBuildLineTable(ctx, ctx->text.lt.top, TRUE);
2807 _XawTextExecuteUpdate(ctx);
2822 TextWidget ctx = (TextWidget) w;
2824 if (ctx->text.display_caret == display_caret) return;
2827 _XawTextPrepareToUpdate(ctx);
2828 ctx->text.display_caret = display_caret;
2829 _XawTextExecuteUpdate(ctx);
2832 ctx->text.display_caret = display_caret;
2851 TextWidget ctx = (TextWidget) w;
2853 return(SrcSearch(ctx->text.source, ctx->text.insertPos, dir, text));