jcs
/textview
/amendments
/37
If our total bounds length is more than SHRT_MAX, divide it down
The scrollbar control can only take a max of SHRT_MAX, so if we need
to deal with more lines than that, calculate divided down by 10
jcs made amendment 37 over 2 years ago
--- textview.c Fri Oct 25 10:26:36 2024
+++ textview.c Fri Oct 25 12:04:47 2024
@@ -53,6 +53,7 @@ struct TVSlab * TVGetTextSlab(struct TVRec *tv, unsign
struct TVChunk * TVGetChunk(struct TVRec *tv, TVChunkPtr ptr);
struct TVChunk * TVCreateChunk(struct TVRec *tv);
struct TVLine * TVGetLine(struct TVRec *tv, unsigned long line);
+short TVScrollDivisor(struct TVRec *tv);
Boolean TVCalcLinesLocked(struct TVRec *tv, Boolean ignore_dirty);
void TVApplyStyle(struct TVStyle *style);
struct TVStyle * TVFindStyle(struct TVRec *tv, struct TVStyle *style);
@@ -391,18 +392,12 @@ TVUpdateScrollbar(TVHandle tvh, ControlHandle scroller
* redraw again, which can cause a jump if we're trying to keep the
* scrollbar position in the same place (like at the bottom).
*/
- max = tv->bounds.bottom - tv->bounds.top -
- (tv->view.bottom - tv->view.top);
- if (max > SHRT_MAX) {
- /* TODO: shift to /10 scale? */
- TVUnlock(tv);
- Debugger();
- return;
- }
+ max = (tv->bounds.bottom - tv->bounds.top -
+ (tv->view.bottom - tv->view.top)) / TVScrollDivisor(tv);
HLock(scroller);
(*scroller)->contrlMin = 0;
(*scroller)->contrlMax = (max > 0 ? max : 0);
- SetCtlValue(scroller, -(tv->scrolled.top));
+ SetCtlValue(scroller, -(tv->scrolled.top) / TVScrollDivisor(tv));
HUnlock(scroller);
rgn = NewRgn();
@@ -615,7 +610,7 @@ TVTrackScrollControl(ControlHandle control, short part
break;
}
- SetCtlValue(control, -(tv->scrolled.top));
+ SetCtlValue(control, -(tv->scrolled.top) / TVScrollDivisor(tv));
TVUnlock(tv);
}
@@ -625,7 +620,8 @@ TVScroll(TVHandle tvh, short horiz, short vert)
struct TVRec *tv;
tv = TVLock(tvh);
- TVScrollUnlocked(tv, horiz, vert);
+ TVScrollUnlocked(tv, (long)horiz * TVScrollDivisor(tv),
+ (long)vert * TVScrollDivisor(tv));
TVUnlock(tv);
}
@@ -1079,6 +1075,22 @@ TVFindStyle(struct TVRec *tv, struct TVStyle *style)
/* no slots left */
return NULL;
+}
+
+short
+TVScrollDivisor(struct TVRec *tv)
+{
+ short div;
+ long max;
+
+ div = 1;
+ max = tv->bounds.bottom - tv->bounds.top -
+ (tv->view.bottom - tv->view.top);
+ while (max > SHRT_MAX) {
+ div *= 10;
+ max /= 10;
+ }
+ return div;
}
Boolean