From 150fd736e1d54b7577ede1a6613570c0b294f60a Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Sun, 1 Aug 2021 17:04:52 -0500 Subject: [PATCH] (libinterface) Add SetText() to UrlTextView --- libs/libinterface/UrlTextView.cpp | 74 +++++++++++++++++-------------- libs/libinterface/UrlTextView.h | 7 +-- 2 files changed, 45 insertions(+), 36 deletions(-) diff --git a/libs/libinterface/UrlTextView.cpp b/libs/libinterface/UrlTextView.cpp index df2ef7e..270c374 100644 --- a/libs/libinterface/UrlTextView.cpp +++ b/libs/libinterface/UrlTextView.cpp @@ -87,39 +87,6 @@ UrlTextView::MessageReceived(BMessage* msg) } -void -UrlTextView::Insert(const char* text, const text_run_array* runs) -{ - BString buf(text); - - int32 specStart = 0; - int32 specEnd = 0; - int32 lastEnd = 0; - int32 length = buf.CountChars(); - - while (_FindUrlString(buf, &specStart, &specEnd, lastEnd) == true) { - if (lastEnd < specStart) { - BString normie; - buf.CopyCharsInto(normie, lastEnd, specStart - lastEnd); - BTextView::Insert(TextLength(), normie.String(), normie.Length(), - runs); - } - BString special; - buf.CopyCharsInto(special, specStart, specEnd - specStart); - BTextView::Insert(TextLength(), special.String(), special.Length(), - &fUrlRun); - - lastEnd = specEnd; - } - if (lastEnd < length) { - BString remaining; - buf.CopyCharsInto(remaining, lastEnd, length - lastEnd); - BTextView::Insert(TextLength(), remaining.String(), remaining.Length(), - runs); - } -} - - void UrlTextView::MouseDown(BPoint where) { @@ -180,6 +147,47 @@ UrlTextView::Select(int32 startOffset, int32 endOffset) } +void +UrlTextView::Insert(const char* text, const text_run_array* runs) +{ + BString buf(text); + + int32 specStart = 0; + int32 specEnd = 0; + int32 lastEnd = 0; + int32 length = buf.CountChars(); + + while (_FindUrlString(buf, &specStart, &specEnd, lastEnd) == true) { + if (lastEnd < specStart) { + BString normie; + buf.CopyCharsInto(normie, lastEnd, specStart - lastEnd); + BTextView::Insert(TextLength(), normie.String(), normie.Length(), + runs); + } + BString special; + buf.CopyCharsInto(special, specStart, specEnd - specStart); + BTextView::Insert(TextLength(), special.String(), special.Length(), + &fUrlRun); + + lastEnd = specEnd; + } + if (lastEnd < length) { + BString remaining; + buf.CopyCharsInto(remaining, lastEnd, length - lastEnd); + BTextView::Insert(TextLength(), remaining.String(), remaining.Length(), + runs); + } +} + + +void +UrlTextView::SetText(const char* text, const text_run_array* runs) +{ + BTextView::SetText(""); + Insert(text, runs); +} + + BString UrlTextView::WordAt(BPoint point) { diff --git a/libs/libinterface/UrlTextView.h b/libs/libinterface/UrlTextView.h index a30a10d..ead3814 100644 --- a/libs/libinterface/UrlTextView.h +++ b/libs/libinterface/UrlTextView.h @@ -22,15 +22,16 @@ public: virtual void MessageReceived(BMessage* msg); - // Only differs in that it changes font face and color of any URLs - virtual void Insert(const char* text, const text_run_array* runs = NULL); - virtual void MouseDown(BPoint where); virtual void MouseUp(BPoint where); virtual void MouseMoved(BPoint where, uint32 code, const BMessage* drag); virtual void Select(int32 startOffset, int32 endOffset); + // Only differs in that it changes font face and color of any URLs + void Insert(const char* text, const text_run_array* runs = NULL); + void SetText(const char* text, const text_run_array* runs = NULL); + BString WordAt(BPoint point); void FindWordAround(int32 offset, int32* start, int32* end, BString* _word = NULL);