jcs
/textview
/amendments
/46
TVTrackScrollControl: Use TVFindInRect
Now with everything using TVFindInRect, we just need to speed up
that one function...
jcs made amendment 46 over 2 years ago
--- textview.c Fri Nov 8 17:34:08 2024
+++ textview.c Fri Nov 8 22:48:46 2024
@@ -66,6 +66,8 @@ Boolean TVFindInRect(struct TVRec *tv, BigRect *findre
TVFindInRectCallback callback, void *cookie);
Boolean TVDrawMatch(struct TVRec *tv, struct TVFindInRectMatch *match,
void *cookie);
+Boolean TVSetTopBottomMatch(struct TVRec *tv,
+ struct TVFindInRectMatch *match, void *cookie);
void TVUseCanvas(struct TVRec *tv);
void TVRevealCanvas(struct TVRec *tv);
@@ -618,8 +620,9 @@ TVTrackScrollControl(ControlHandle control, short part
{
struct TVRec *tv;
struct TVChunk *chunk, *top_chunk = NULL;
- struct TVLine *line, *oline, *top_line, *bottom_line;
+ struct TVLine *line, *oline;
KeyMap km;
+ BigRect visible;
long n, top;
unsigned short nline;
Boolean horiz, cmd_down;
@@ -637,34 +640,23 @@ TVTrackScrollControl(ControlHandle control, short part
GetKeys(&km);
cmd_down = (km[1] & (1 << 15)) != 0;
- top_line = NULL;
- bottom_line = NULL;
- for (nline = 1; nline <= tv->nlines; nline++) {
- line = TVGetLine(tv, nline);
- if (line == NULL)
- break;
-
- if (tv->scrolled.top + line->rect.bottom < 0L)
- /* is not in the view at all yet */
- continue;
-
- if (tv->scrolled.top + line->rect.top >= tv->frame.bottom)
- /* is further down than the view, we've done enough lines */
- break;
-
- if (top_line == NULL)
- top_line = line;
-
- bottom_line = line;
- }
- if (top_line == NULL) {
- top_line = TVGetLine(tv, nline);
- if (top_line == NULL)
+ tv->top_line = NULL;
+ tv->bottom_line = NULL;
+
+ visible.top = -(tv->scrolled.top);
+ visible.left = -(tv->scrolled.left);
+ visible.bottom = visible.top + tv->frame.bottom;
+ visible.right = visible.left + tv->frame.right;
+ TVFindInRect(tv, &visible, 1, TVSetTopBottomMatch, NULL);
+
+ if (tv->top_line == NULL) {
+ tv->top_line = TVGetLine(tv, nline);
+ if (tv->top_line == NULL)
return;
}
- if (bottom_line == NULL) {
- bottom_line = TVGetLine(tv, tv->nlines);
- if (bottom_line == NULL)
+ if (tv->bottom_line == NULL) {
+ tv->bottom_line = TVGetLine(tv, tv->nlines);
+ if (tv->bottom_line == NULL)
return;
}
@@ -676,11 +668,11 @@ TVTrackScrollControl(ControlHandle control, short part
}
/* scroll to the line before the top-most line */
- if (top_line->nline > 1) {
- oline = TVGetLine(tv, top_line->nline - 1);
+ if (tv->top_line->nline > 1) {
+ oline = TVGetLine(tv, tv->top_line->nline - 1);
if (oline == NULL)
break;
- TVScrollUnlocked(tv, 0, top_line->rect.top -
+ TVScrollUnlocked(tv, 0, tv->top_line->rect.top -
oline->rect.top + 1);
break;
}
@@ -691,7 +683,7 @@ TVTrackScrollControl(ControlHandle control, short part
case inPageUp:
/* scroll to put the top mostly-visible line at the bottom */
TVScrollUnlocked(tv, 0, (long)tv->frame.bottom -
- (tv->scrolled.top + top_line->rect.bottom) - 1);
+ (tv->scrolled.top + tv->top_line->rect.bottom) - 1);
break;
case inDownButton:
if (cmd_down) {
@@ -700,8 +692,8 @@ TVTrackScrollControl(ControlHandle control, short part
}
/* scroll to the line after the bottom-most line */
- if (bottom_line->nline < tv->nlines) {
- line = TVGetLine(tv, bottom_line->nline + 1);
+ if (tv->bottom_line->nline < tv->nlines) {
+ line = TVGetLine(tv, tv->bottom_line->nline + 1);
TVScrollUnlocked(tv, 0,
-(tv->scrolled.top - tv->frame.bottom + line->rect.bottom));
break;
@@ -712,8 +704,8 @@ TVTrackScrollControl(ControlHandle control, short part
break;
case inPageDown:
/* scroll to put the bottom mostly-visible line at the top */
- if (bottom_line->nline < tv->nlines) {
- line = TVGetLine(tv, bottom_line->nline + 1);
+ if (tv->bottom_line->nline < tv->nlines) {
+ line = TVGetLine(tv, tv->bottom_line->nline + 1);
if (line == NULL)
break;
TVScrollUnlocked(tv, 0, -(line->rect.top + tv->scrolled.top) +
@@ -1561,6 +1553,18 @@ prep_chunk:
draw_done:
TVRevealCanvas(tv);
return ret;
+}
+
+Boolean
+TVSetTopBottomMatch(struct TVRec *tv, struct TVFindInRectMatch *match,
+ void *cookie)
+{
+ if (tv->top_line == NULL)
+ tv->top_line = match->line;
+
+ tv->bottom_line = match->line;
+
+ return true;
}
void
--- textview.h Fri Nov 8 17:13:17 2024
+++ textview.h Fri Nov 8 22:24:25 2024
@@ -141,6 +141,9 @@ struct TVRec {
Boolean linewrap;
unsigned char tabstop;
char unlock_refcnt;
+
+ struct TVLine *top_line;
+ struct TVLine *bottom_line;
};
typedef struct TVRec ** TVHandle;