jcs
/textview
/amendments
/10
textview: Finalize scrolling
jcs made amendment 10 over 2 years ago
--- main.c Wed Dec 27 22:44:56 2023
+++ main.c Thu Dec 28 16:11:16 2023
@@ -241,6 +241,8 @@ if (1) {
val -= adj;
if (control == te_scroller)
TEScroll(0, adj * TEGetHeight(0, 0, te), te);
+ else if (control == tv_scroller)
+ TVScroll(tv, 0, adj);
SetCtlValue(control, val);
}
break;
--- textview.c Wed Dec 27 23:01:23 2023
+++ textview.c Thu Dec 28 16:14:29 2023
@@ -341,9 +341,7 @@ TVTrackScrollControl(ControlHandle control, short part
{
struct TVRec *tv;
struct TVChunk *chunk, *top_chunk = NULL;
- BigRect visRect;
- short page, val, adj, per_line;
- long n, visible, height, top;
+ long n, height, top;
Boolean horiz;
if (tv_track_control == NULL)
@@ -353,78 +351,91 @@ TVTrackScrollControl(ControlHandle control, short part
horiz = (((*control)->contrlRect.bottom - (*control)->contrlRect.top) <
((*control)->contrlRect.right - (*control)->contrlRect.left));
- adj = 0;
+ height = tv->view.bottom - tv->view.top - 2;
+
switch (part) {
case inUpButton:
+ /* scroll to the previous line that is not yet mostly-visible */
for (chunk = (struct TVChunk *)tv->last_chunk; chunk != NULL;
chunk = chunk->prev_chunk) {
- if (chunk->rect.bottom - ((chunk->rect.bottom -
- chunk->rect.top) / 2) > 0)
- /* already visible */
+ if (chunk->rect.top + (long)(chunk->baseline / 2) +
+ tv->scrollRect.top > 0)
continue;
- if (chunk->prev_chunk)
- /* scroll to make this line entirely visible at the top */
- TVScroll(tv, 0, tv->scrollRect.top + chunk->rect.top);
- else
- /* close enough, just scroll to the top */
- TVScroll(tv, 0, tv->scrollRect.top);
+ if (!chunk->prev_chunk)
+ break;
+
+ TVScroll(tv, 0, -(tv->scrollRect.top) - chunk->rect.top);
goto update_value;
}
/* nothing found, just scroll to the top */
- TVScroll(tv, 0, tv->scrollRect.top);
+ TVScroll(tv, 0, -(tv->scrollRect.top));
break;
case inPageUp:
- adj = -page;
+ /* scroll to put the top mostly-visible line at the bottom */
+ for (chunk = (struct TVChunk *)tv->chunks; chunk != NULL;
+ chunk = chunk->next_chunk) {
+ if (chunk->rect.top + (long)(chunk->baseline / 2) +
+ tv->scrollRect.top < 0)
+ continue;
+
+ top = tv->scrollRect.top + chunk->rect.top + height -
+ (chunk->rect.bottom - chunk->rect.top);
+ if (tv->scrollRect.top + top > 0)
+ break;
+
+ TVScroll(tv, 0, top);
+ goto update_value;
+ }
+
+ /* nothing found, just scroll to the top */
+ TVScroll(tv, 0, -(tv->scrollRect.top));
break;
case inDownButton:
- height = tv->view.bottom - tv->view.top - 2;
-
+ /* scroll to the line after the bottom-most line */
for (chunk = (struct TVChunk *)tv->chunks; chunk != NULL;
chunk = chunk->next_chunk) {
top = chunk->rect.top + (chunk->baseline / 2) +
tv->scrollRect.top;
-
if (top < height)
- /* already visible */
continue;
- /* scroll to make this line entirely visible at the bottom */
- TVScroll(tv, 0, -((chunk->rect.bottom - height) +
- tv->scrollRect.top));
- break;
+ TVScroll(tv, 0, -((chunk->rect.bottom - height) +
+ tv->scrollRect.top));
+ goto update_value;
}
+
+ /* nothing found, just scroll to the bottom */
+ TVScroll(tv, 0, height - tv->scrollRect.bottom);
break;
case inPageDown:
- adj = page;
+ /* scroll to put the bottom mostly-visible line at the top */
+ for (chunk = (struct TVChunk *)tv->last_chunk; chunk != NULL;
+ chunk = chunk->prev_chunk) {
+ if (chunk->rect.bottom - (long)(chunk->baseline / 2) +
+ tv->scrollRect.top > height)
+ continue;
+
+ TVScroll(tv, 0, -(tv->scrollRect.top) - chunk->rect.top);
+ goto update_value;
+ }
+
+ /* nothing found, just scroll to the bottom */
+ TVScroll(tv, 0, height - tv->scrollRect.bottom);
break;
}
update_value:
SetCtlValue(control, -(tv->scrollRect.top));
-
-#if 0
- val = GetCtlValue(control);
- if (val + adj < GetCtlMin(control))
- adj = -(val - GetCtlMin(control));
- if (val + adj > GetCtlMax(control))
- adj = (GetCtlMax(control) - val);
- if (adj == 0)
- return;
-
- if (horiz)
- TEScroll(-adj * fwidth, 0, track_control_te);
- else
- TEScroll(0, -adj * fheight, track_control_te);
-
- SetCtlValue(control, val + adj);
-#endif
}
void
TVScroll(struct TVRec *tv, long horiz, long vert)
{
+ if (!horiz && !vert)
+ return;
+
tv->scrollRect.top += vert;
tv->scrollRect.bottom += vert;