(libinterface) Add SetText() to UrlTextView

This commit is contained in:
Jaidyn Ann 2021-08-01 17:04:52 -05:00
parent 5dcf59a7e9
commit 150fd736e1
2 changed files with 45 additions and 36 deletions

View File

@ -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 void
UrlTextView::MouseDown(BPoint where) 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 BString
UrlTextView::WordAt(BPoint point) UrlTextView::WordAt(BPoint point)
{ {

View File

@ -22,15 +22,16 @@ public:
virtual void MessageReceived(BMessage* msg); 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 MouseDown(BPoint where);
virtual void MouseUp(BPoint where); virtual void MouseUp(BPoint where);
virtual void MouseMoved(BPoint where, uint32 code, const BMessage* drag); virtual void MouseMoved(BPoint where, uint32 code, const BMessage* drag);
virtual void Select(int32 startOffset, int32 endOffset); 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); BString WordAt(BPoint point);
void FindWordAround(int32 offset, int32* start, int32* end, void FindWordAround(int32 offset, int32* start, int32* end,
BString* _word = NULL); BString* _word = NULL);