jcs
/textview
/amendments
/42
TVGetText: Add function to read all text slabs into a single buffer
Since users can't access the text directly like a TextEdit control,
provide this so all of the text can be copied somewhere.
jcs made amendment 42 over 2 years ago
--- textview.c Tue Oct 29 08:58:59 2024
+++ textview.c Tue Oct 29 13:39:30 2024
@@ -490,6 +490,35 @@ TVGetOffsetCallback(struct TVRec *tv, struct TVFindInR
return true;
}
+unsigned long
+TVGetText(TVHandle tvh, char *dst, unsigned long start, unsigned long end)
+{
+ struct TVRec *tv;
+ struct TVSlab *slab;
+ unsigned long slabstart, slabend, read, size;
+
+ tv = TVLock(tvh);
+
+ while (read < end - start) {
+ slab = TVGetTextSlab(tv, start + read);
+ slabend = slab->base + slab->size;
+ slabstart = slab->base;
+
+ if (start > slabstart)
+ slabstart = start;
+ if (end - read < slabend)
+ slabend = end - read;
+
+ size = slabend - slabstart;
+ memcpy(dst, slab->data + (slabstart - slab->base), size);
+
+ dst += size;
+ read += size;
+ }
+
+ return read;
+}
+
long
TVGetOffset(TVHandle tvh, Point p)
{
--- textview.h Mon Oct 28 12:38:08 2024
+++ textview.h Tue Oct 29 13:32:56 2024
@@ -153,6 +153,8 @@ Boolean TVResize(TVHandle tvh);
void TVUpdate(TVHandle tvh);
void TVUpdateScrollbar(TVHandle tvh, ControlHandle scroller);
void TVClick(TVHandle tvh, Point p, Boolean extend);
+unsigned long TVGetText(TVHan mJ my mè m™ m— mÔ n n<