Slight RunView reformatting

This commit is contained in:
Jaidyn Ann 2021-06-07 13:34:20 -05:00
parent c8a62610ca
commit 2d34b4edde

View File

@ -30,33 +30,35 @@
#define ABS(x) (x * ((x<0) ? -1 : 1)) #define ABS(x) (x * ((x<0) ? -1 : 1))
#define SOFTBREAK_STEP 5 #define SOFTBREAK_STEP 5
#include <string.h> #include "RunView.h"
#include <stdio.h>
#include <time.h>
#include <ctype.h>
#include <assert.h> #include <assert.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <Bitmap.h> #include <Bitmap.h>
#include <Clipboard.h> #include <Clipboard.h>
#include <Cursor.h> #include <Cursor.h>
#include <MenuItem.h>
#include <Message.h> #include <Message.h>
#include <Messenger.h> #include <Messenger.h>
#include <MessageRunner.h> #include <MessageRunner.h>
#include <PopUpMenu.h>
#include <MenuItem.h>
#include <ObjectList.h> #include <ObjectList.h>
#include <ScrollView.h> #include <PopUpMenu.h>
#include <ScrollBar.h> #include <ScrollBar.h>
#include <ScrollView.h>
#include <Region.h> #include <Region.h>
#include <Window.h> #include <Window.h>
#include <Roster.h>
#include "Theme.h" #include "Theme.h"
#include "RunView.h"
#include "URLCrunch.h" #include "URLCrunch.h"
#include "Utilities.h" #include "Utilities.h"
#include <Roster.h>
#include <stdlib.h>
#define _T(str) (str) #define _T(str) (str)
@ -69,40 +71,44 @@ static unsigned char URLCursorData[] = {16, 1, 2, 2,
15, 255, 63, 255, 127, 255, 127, 255, 63, 255, 15, 255, 3, 254, 1, 248 15, 255, 63, 255, 127, 255, 127, 255, 63, 255, 15, 255, 3, 254, 1, 248
}; };
struct SoftBreak { struct SoftBreak {
int fOffset; int fOffset;
float fHeight; float fHeight;
float fAscent; float fAscent;
}; };
struct URL { struct URL {
int fOffset; int fOffset;
int fLength; int fLength;
BString fUrl; BString fUrl;
URL(const char* address, int off, int len) URL(const char* address, int off, int len)
: : fOffset (off), fLength (len), fUrl (address)
fOffset (off), { }
fLength (len),
fUrl (address) {}
}; };
typedef BObjectList<URL> urllist; typedef BObjectList<URL> urllist;
struct SoftBreakEnd { struct SoftBreakEnd {
float fOffset; float fOffset;
SoftBreakEnd(float offset) SoftBreakEnd(float offset)
: : fOffset(offset)
fOffset(offset) {} { }
}; };
struct FontColor { struct FontColor {
int fOffset; int fOffset;
int fWhich; int fWhich;
int fIndex; int fIndex;
}; };
struct Line { struct Line {
char* fText; char* fText;
time_t fStamp; time_t fStamp;
@ -121,41 +127,34 @@ struct Line {
int fSoftie_size; int fSoftie_size;
int fSoftie_used; int fSoftie_used;
Line ( Line(const char* buffer, int fLength, float top, float width, Theme* fTheme,
const char* buffer, const char* fStamp_format, int fore, int back, int font);
int fLength,
float top,
float width,
Theme* fTheme,
const char* fStamp_format,
int fore,
int back,
int font);
~Line (void); ~Line ();
void Append(const char* buffer, int len, void Append(const char* buffer, int len, float width,
float width, Theme* fTheme, Theme* fTheme, int fore, int back, int font);
int fore, int back, int font);
void FigureSpaces (void); void FigureSpaces();
void FigureFontColors(int pos, int fore, int back, int font); void FigureFontColors(int pos, int fore, int back, int font);
void FigureEdges(Theme* fTheme, float width); void FigureEdges(Theme* fTheme, float width);
void SoftBreaks(Theme* fTheme, float width); void SoftBreaks(Theme* fTheme, float width);
void AddSoftBreak(SoftBreakEnd , float&, void AddSoftBreak(SoftBreakEnd, float&, int&, int16&, float&,
int&, int16&, float&, float&, Theme*); float&, Theme*);
int CountChars(int pos, int len); int CountChars(int pos, int len);
size_t SetStamp(const char*, bool); size_t SetStamp(const char*, bool);
void SelectWord(int*, int*); void SelectWord(int*, int*);
}; };
inline int32 inline int32
UTF8_CHAR_LEN (uchar c) UTF8_CHAR_LEN (uchar c)
{ {
return (((0xE5000000 >> (((c) >> 3) & 0x1E)) & 3) + 1); return (((0xE5000000 >> (((c) >> 3) & 0x1E)) & 3) + 1);
} }
RunView::RunView(BRect frame, const char* name, Theme* theme, RunView::RunView(BRect frame, const char* name, Theme* theme,
uint32 resizingMode, uint32 flags) uint32 resizingMode, uint32 flags)
: :
@ -178,7 +177,6 @@ RunView::RunView(BRect frame, const char* name, Theme* theme,
fLastClick (0, 0), fLastClick (0, 0),
fLastClickTime (0) fLastClickTime (0)
{ {
memset (fLines, 0, sizeof (fLines)); memset (fLines, 0, sizeof (fLines));
fURLCursor = new BCursor (URLCursorData); fURLCursor = new BCursor (URLCursorData);
@ -190,7 +188,7 @@ RunView::RunView(BRect frame, const char* name, Theme* theme,
} }
RunView::~RunView (void) RunView::~RunView()
{ {
for (int16 i = 0; i < fLine_count; ++i) for (int16 i = 0; i < fLine_count; ++i)
delete fLines[i]; delete fLines[i];
@ -201,8 +199,9 @@ RunView::~RunView (void)
delete [] fClipping_name; delete [] fClipping_name;
} }
void void
RunView::AttachedToWindow (void) RunView::AttachedToWindow()
{ {
BView::AttachedToWindow(); BView::AttachedToWindow();
RecalcScrollBar (false); RecalcScrollBar (false);
@ -211,14 +210,16 @@ RunView::AttachedToWindow (void)
fTheme->WriteUnlock(); fTheme->WriteUnlock();
} }
void void
RunView::DetachedFromWindow (void) RunView::DetachedFromWindow()
{ {
fTheme->WriteLock(); fTheme->WriteLock();
fTheme->RemoveView (this); fTheme->RemoveView (this);
fTheme->WriteUnlock(); fTheme->WriteUnlock();
} }
void void
RunView::FrameResized(float start_width, float height) RunView::FrameResized(float start_width, float height)
{ {
@ -231,6 +232,7 @@ RunView::FrameResized (float start_width, float height)
ResizeRecalc(); ResizeRecalc();
} }
void void
RunView::TargetedByScrollView (BScrollView* s) RunView::TargetedByScrollView (BScrollView* s)
{ {
@ -238,8 +240,9 @@ RunView::TargetedByScrollView (BScrollView* s)
BView::TargetedByScrollView (fScroller); BView::TargetedByScrollView (fScroller);
} }
void void
RunView::Show (void) RunView::Show()
{ {
if (fFontsdirty) { if (fFontsdirty) {
FontChangeRecalc(); FontChangeRecalc();
@ -254,6 +257,7 @@ RunView::Show (void)
BView::Show(); BView::Show();
} }
void void
RunView::Draw(BRect frame) RunView::Draw(BRect frame)
{ {
@ -274,23 +278,22 @@ RunView::Draw (BRect frame)
fTheme->ReadLock(); fTheme->ReadLock();
view_color = fTheme->BackgroundAt (Theme::NormalBack); view_color = fTheme->BackgroundAt (Theme::NormalBack);
sel_color = fTheme->BackgroundAt (Theme::SelectionBack); sel_color = fTheme->BackgroundAt (Theme::SelectionBack);
if (((sel_color.red + sel_color.blue + sel_color.green) / 3) >= 127) { if (((sel_color.red + sel_color.blue + sel_color.green) / 3) >= 127) {
sel_fText.red = sel_fText.green = sel_fText.blue = 0; sel_fText.red = sel_fText.green = sel_fText.blue = 0;
sel_fText.alpha = 255; sel_fText.alpha = 255;
} else { }
else {
sel_fText.red = sel_fText.green = sel_fText.blue = sel_fText.alpha = 255; sel_fText.red = sel_fText.green = sel_fText.blue = sel_fText.alpha = 255;
} }
BRect remains; BRect remains;
if (fLine_count == 0) if (fLine_count == 0)
remains = frame; remains = frame;
else if (frame.bottom >= fLines[fLine_count - 1]->fBottom + 1.0) else if (frame.bottom >= fLines[fLine_count - 1]->fBottom + 1.0)
remains.Set ( remains.Set(frame.left, fLines[fLine_count - 1]->fBottom + 1,
frame.left, frame.right, frame.bottom);
fLines[fLine_count - 1]->fBottom + 1,
frame.right,
frame.bottom);
if (remains.IsValid()) { if (remains.IsValid()) {
SetLowColor (view_color); SetLowColor (view_color);
@ -437,10 +440,7 @@ RunView::Draw (BRect frame)
while (line->fEdges[k] == 0) while (line->fEdges[k] == 0)
--k; --k;
r.Set ( r.Set(left, height, line->fEdges[k] + indent - start,
left,
height,
line->fEdges[k] + indent - start,
height + line->fSofties[sit].fHeight - 1); height + line->fSofties[sit].fHeight - 1);
SetDrawingMode (B_OP_COPY); SetDrawingMode (B_OP_COPY);
@ -456,15 +456,12 @@ RunView::Draw (BRect frame)
SetDrawingMode (B_OP_OVER); SetDrawingMode (B_OP_OVER);
if ( sit >= line->fSoftie_used ) { if ( sit >= line->fSoftie_used )
printf("bah. sit is %d and fSoftie_used is %d\n", sit, line->fSoftie_used); printf("bah. sit is %d and fSoftie_used is %d\n", sit, line->fSoftie_used);
} else { else
tr->Render(this, line->fText + place,
tr->Render(this,
line->fText + place,
min_c(fLength, line->fLength - place - 1), min_c(fLength, line->fLength - place - 1),
BPoint(left, height + line->fSofties[sit].fAscent)); BPoint(left, height + line->fSofties[sit].fAscent));
}
left = line->fEdges[k] + indent - start; left = line->fEdges[k] + indent - start;
@ -476,11 +473,7 @@ RunView::Draw (BRect frame)
// Margin after fText // Margin after fText
SetDrawingMode(B_OP_COPY); SetDrawingMode(B_OP_COPY);
SetLowColor(view_color); SetLowColor(view_color);
FillRect ( FillRect(BRect(left + 1, height, bounds.right,
BRect (
left + 1,
height,
bounds.right,
height + line->fSofties[sit].fHeight - 1), height + line->fSofties[sit].fHeight - 1),
B_SOLID_LOW); B_SOLID_LOW);
@ -497,6 +490,7 @@ RunView::Draw (BRect frame)
ConstrainClippingRegion (NULL); ConstrainClippingRegion (NULL);
} }
void void
RunView::SetViewColor(rgb_color color) RunView::SetViewColor(rgb_color color)
{ {
@ -504,8 +498,9 @@ RunView::SetViewColor (rgb_color color)
BView::SetViewColor(color); BView::SetViewColor(color);
} }
void void
RunView::BuildPopUp (void) RunView::BuildPopUp()
{ {
// This function checks certain criteria (fText is selected, // This function checks certain criteria (fText is selected,
// TextView is editable, etc) to determine fWhich MenuItems // TextView is editable, etc) to determine fWhich MenuItems
@ -574,6 +569,7 @@ RunView::BuildPopUp (void)
fMyPopUp->SetFont(be_plain_font); fMyPopUp->SetFont(be_plain_font);
} }
bool bool
RunView::CheckClickBounds(const SelectPos& s, const BPoint& point) const RunView::CheckClickBounds(const SelectPos& s, const BPoint& point) const
{ {
@ -581,6 +577,7 @@ RunView::CheckClickBounds (const SelectPos& s, const BPoint& point) const
&& (point.y <= fLines[s.fLine]->fBottom)); && (point.y <= fLines[s.fLine]->fBottom));
} }
void void
RunView::MouseDown(BPoint point) RunView::MouseDown(BPoint point)
{ {
@ -640,7 +637,6 @@ RunView::MouseDown (BPoint point)
if (inBounds) { if (inBounds) {
// select word // select word
fLines[s.fLine]->SelectWord(&start.fOffset, &end.fOffset); fLines[s.fLine]->SelectWord(&start.fOffset, &end.fOffset);
Select(start, end); Select(start, end);
return; return;
} }
@ -685,6 +681,7 @@ RunView::MouseDown (BPoint point)
} }
} }
void void
RunView::CheckURLCursor(BPoint point) RunView::CheckURLCursor(BPoint point)
{ {
@ -713,6 +710,7 @@ RunView::CheckURLCursor (BPoint point)
SetViewCursor (B_CURSOR_SYSTEM_DEFAULT); SetViewCursor (B_CURSOR_SYSTEM_DEFAULT);
} }
void void
RunView::MouseMoved(BPoint point, uint32 transit, const BMessage* msg) RunView::MouseMoved(BPoint point, uint32 transit, const BMessage* msg)
{ {
@ -861,6 +859,7 @@ RunView::MouseMoved (BPoint point, uint32 transit, const BMessage* msg)
} }
} }
void void
RunView::MouseUp(BPoint point) RunView::MouseUp(BPoint point)
{ {
@ -896,9 +895,9 @@ RunView::MouseUp (BPoint point)
} }
fTracking = 0; fTracking = 0;
} }
void void
RunView::ExtendTrackingSelect(BPoint point) RunView::ExtendTrackingSelect(BPoint point)
{ {
@ -913,6 +912,7 @@ RunView::ExtendTrackingSelect (BPoint point)
} }
} }
void void
RunView::ShiftTrackingSelect(BPoint point, bool move, bigtime_t timer) RunView::ShiftTrackingSelect(BPoint point, bool move, bigtime_t timer)
{ {
@ -997,30 +997,33 @@ RunView::ShiftTrackingSelect (BPoint point, bool move, bigtime_t timer)
ExtendTrackingSelect (point); ExtendTrackingSelect (point);
} }
void void
RunView::MessageReceived(BMessage* msg) RunView::MessageReceived(BMessage* msg)
{ {
switch (msg->what) { switch (msg->what)
{
case M_THEME_FOREGROUND_CHANGE: case M_THEME_FOREGROUND_CHANGE:
case M_THEME_BACKGROUND_CHANGE: case M_THEME_BACKGROUND_CHANGE:
{
if (!IsHidden()) if (!IsHidden())
Invalidate (Bounds()); Invalidate (Bounds());
break; break;
}
case M_THEME_FONT_CHANGE: { case M_THEME_FONT_CHANGE:
{
Theme* save (fTheme); Theme* save (fTheme);
fTheme = NULL; fTheme = NULL;
SetTheme (save); SetTheme (save);
break; break;
} }
case B_SELECT_ALL: case B_SELECT_ALL:
SelectAll(); SelectAll();
break; break;
case B_COPY: case B_COPY:
{
if (fSp_start != fSp_end if (fSp_start != fSp_end
&& be_clipboard->Lock()) { && be_clipboard->Lock()) {
BString fText; BString fText;
@ -1035,8 +1038,9 @@ RunView::MessageReceived (BMessage* msg)
be_clipboard->Unlock(); be_clipboard->Unlock();
} }
break; break;
}
case M_OFFVIEW_SELECTION: { case M_OFFVIEW_SELECTION:
{
BPoint point; BPoint point;
float delta; float delta;
bool bottom; bool bottom;
@ -1053,38 +1057,36 @@ RunView::MessageReceived (BMessage* msg)
ShiftTrackingSelect (point, true, OFFVIEW_TIMER); ShiftTrackingSelect (point, true, OFFVIEW_TIMER);
break; break;
} }
case M_LOOKUP_WEBSTER:
case M_LOOKUP_WEBSTER: { {
BString lookup; BString lookup;
msg->FindString ("string", &lookup); msg->FindString ("string", &lookup);
lookup = StringToURI (lookup.String()); lookup = StringToURI (lookup.String());
lookup.Prepend ("http://www.m-w.com/cgi-bin/dictionary?va="); lookup.Prepend ("http://www.m-w.com/cgi-bin/dictionary?va=");
LoadURL (lookup.String()); LoadURL (lookup.String());
}
break; break;
}
case M_LOOKUP_GOOGLE: { case M_LOOKUP_GOOGLE:
{
BString lookup; BString lookup;
msg->FindString ("string", &lookup); msg->FindString ("string", &lookup);
lookup = StringToURI (lookup.String()); lookup = StringToURI (lookup.String());
lookup.Prepend ("http://www.google.com/search?q="); lookup.Prepend ("http://www.google.com/search?q=");
LoadURL (lookup.String()); LoadURL (lookup.String());
}
break; break;
}
case M_LOOKUP_ACRONYM: { case M_LOOKUP_ACRONYM:
{
BString lookup; BString lookup;
msg->FindString ("string", &lookup); msg->FindString ("string", &lookup);
lookup = StringToURI (lookup.String()); lookup = StringToURI (lookup.String());
lookup.Prepend ("http://www.acronymfinder.com/af-query.asp?String=exact&Acronym="); lookup.Prepend ("http://www.acronymfinder.com/af-query.asp?String=exact&Acronym=");
lookup.Append ("&Find=Find"); lookup.Append ("&Find=Find");
LoadURL (lookup.String()); LoadURL (lookup.String());
}
break; break;
case M_CLEAR: {
Clear();
} }
case M_CLEAR:
Clear();
break; break;
default: default:
@ -1092,8 +1094,9 @@ RunView::MessageReceived (BMessage* msg)
} }
} }
void void
RunView::ResizeRecalc (void) RunView::ResizeRecalc()
{ {
float width (Bounds().Width() - (fTheme->TextMargin() * 2)); float width (Bounds().Width() - (fTheme->TextMargin() * 2));
int fSoftie_size (0), fSoftie_used (0); int fSoftie_size (0), fSoftie_used (0);
@ -1153,8 +1156,9 @@ RunView::ResizeRecalc (void)
delete [] fSofties; delete [] fSofties;
} }
void void
RunView::FontChangeRecalc (void) RunView::FontChangeRecalc()
{ {
float width (Bounds().Width() - (fTheme->TextMargin() * 2)); float width (Bounds().Width() - (fTheme->TextMargin() * 2));
float top (0.0); float top (0.0);
@ -1177,6 +1181,7 @@ RunView::FontChangeRecalc (void)
if (Window()) Window()->UpdateIfNeeded(); if (Window()) Window()->UpdateIfNeeded();
} }
bool bool
RunView::RecalcScrollBar(bool constrain) RunView::RecalcScrollBar(bool constrain)
{ {
@ -1227,33 +1232,24 @@ RunView::RecalcScrollBar (bool constrain)
return changed; return changed;
} }
void void
RunView::Append ( RunView::Append(const char* buffer, int fore, int back, int font)
const char* buffer,
int fore,
int back,
int font)
{ {
Append(buffer, strlen(buffer), fore, back, font); Append(buffer, strlen(buffer), fore, back, font);
} }
void void
RunView::Append ( RunView::Append(const char* buffer, int32 len, int fore, int back, int font)
const char* buffer,
int32 len,
int fore,
int back,
int font)
{ {
if (buffer == NULL) if (buffer == NULL)
return; return;
float width(Bounds().Width() - 10); float width(Bounds().Width() - 10);
int32 place(0); int32 place(0);
assert (fore != Theme::TimestampFore);
assert(back != Theme::TimestampBack); assert(back != Theme::TimestampBack);
assert(font != Theme::TimestampFont); assert(font != Theme::TimestampFont);
assert (fore != Theme::TimespaceFore);
assert(back != Theme::TimespaceBack); assert(back != Theme::TimespaceBack);
assert(font != Theme::TimespaceFont); assert(font != Theme::TimespaceFont);
assert(back != Theme::SelectionBack); assert(back != Theme::SelectionBack);
@ -1266,63 +1262,39 @@ RunView::Append (
while (end < len && buffer[end] != '\n') while (end < len && buffer[end] != '\n')
++end; ++end;
if (end < len) ++end; if (end < len)
++end;
if (fWorking) { if (fWorking) {
URLCrunch crunch (buffer + place, end - place); URLCrunch crunch (buffer + place, end - place);
BString temp; BString temp;
int32 url_offset (0), int32 url_offset (0),
last_offset (0); last_offset (0);
while ((url_offset = crunch.Crunch (&temp)) != B_ERROR) { while ((url_offset = crunch.Crunch (&temp)) != B_ERROR) {
fWorking->Append (buffer + place, fWorking->Append(buffer + place, (url_offset - last_offset),
(url_offset - last_offset), width, fTheme, fore, back, font);
width,
fTheme,
fore,
back,
font);
fWorking->Append (temp.String(), fWorking->Append(temp.String(), temp.Length(), width, fTheme,
temp.Length(), C_URL, back, F_URL);
width,
fTheme,
C_URL,
back,
F_URL);
place += (url_offset - last_offset) + temp.Length(); place += (url_offset - last_offset) + temp.Length();
last_offset = url_offset + temp.Length(); last_offset = url_offset + temp.Length();
} }
if (place < end) if (place < end)
fWorking->Append ( fWorking->Append(buffer + place, end - place, width,
buffer + place, fTheme, fore, back, font);
end - place, }
width, else {
fTheme,
fore,
back,
font);
} else {
float top(0.0); float top(0.0);
if (fLine_count > 0) if (fLine_count > 0)
top = fLines[fLine_count - 1]->fBottom + (float) 1.0; top = fLines[fLine_count - 1]->fBottom + (float) 1.0;
//HERE //HERE
fWorking = new Line ( fWorking = new Line(buffer + place, 0, top, width, fTheme,
buffer + place, fStamp_format, fore, back, font);
0,
top,
width,
fTheme,
fStamp_format,
fore,
back,
font);
URLCrunch crunch(buffer + place, end - place); URLCrunch crunch(buffer + place, end - place);
BString temp; BString temp;
@ -1330,33 +1302,18 @@ RunView::Append (
last_offset(0); last_offset(0);
while ((url_offset = crunch.Crunch(&temp)) != B_ERROR) { while ((url_offset = crunch.Crunch(&temp)) != B_ERROR) {
fWorking->Append (buffer + place, fWorking->Append(buffer + place, (url_offset - last_offset),
(url_offset - last_offset), width, fTheme, fore, back, font);
width, fWorking->Append(temp.String(), temp.Length(),
fTheme, width, fTheme, C_URL, back, F_URL);
fore,
back,
font);
fWorking->Append (temp.String(),
temp.Length(),
width,
fTheme,
C_URL,
back,
F_URL);
place += (url_offset - last_offset) + temp.Length(); place += (url_offset - last_offset) + temp.Length();
last_offset = url_offset + temp.Length(); last_offset = url_offset + temp.Length();
} }
if (place < end) if (place < end)
fWorking->Append (buffer + place, fWorking->Append(buffer + place, end - place, width,
end - place, fTheme, fore, back, font);
width,
fTheme,
fore,
back,
font);
} }
if (fWorking->fLength if (fWorking->fLength
@ -1416,8 +1373,9 @@ RunView::Append (
fTheme->ReadUnlock(); fTheme->ReadUnlock();
} }
void void
RunView::Clear (void) RunView::Clear()
{ {
for (int16 i = 0; i < fLine_count; ++i) for (int16 i = 0; i < fLine_count; ++i)
delete fLines[i]; delete fLines[i];
@ -1434,12 +1392,14 @@ RunView::Clear (void)
fWorking->fTop = 0.0; fWorking->fTop = 0.0;
} }
int16 int16
RunView::LineCount (void) const RunView::LineCount() const
{ {
return fLine_count; return fLine_count;
} }
const char * const char *
RunView::LineAt(int which) const RunView::LineAt(int which) const
{ {
@ -1449,6 +1409,7 @@ RunView::LineAt (int which) const
return fLines[which]->fText; return fLines[which]->fText;
} }
void void
RunView::SetTimeStampFormat(const char* format) RunView::SetTimeStampFormat(const char* format)
{ {
@ -1495,6 +1456,7 @@ RunView::SetTimeStampFormat (const char* format)
if (Window()) Window()->UpdateIfNeeded(); if (Window()) Window()->UpdateIfNeeded();
} }
void void
RunView::SetTheme(Theme* t) RunView::SetTheme(Theme* t)
{ {
@ -1510,6 +1472,7 @@ RunView::SetTheme (Theme* t)
FontChangeRecalc(); FontChangeRecalc();
} }
SelectPos SelectPos
RunView::PositionAt(BPoint point) const RunView::PositionAt(BPoint point) const
{ {
@ -1566,12 +1529,14 @@ RunView::PositionAt (BPoint point) const
return pos; return pos;
} }
BPoint BPoint
RunView::PointAt(SelectPos s) const RunView::PointAt(SelectPos s) const
{ {
return BPoint(fLines[s.fLine]->fTop + fLines[s.fLine]->fBottom / 2, fLines[s.fLine]->fEdges[s.fOffset]); return BPoint(fLines[s.fLine]->fTop + fLines[s.fLine]->fBottom / 2, fLines[s.fLine]->fEdges[s.fOffset]);
} }
void void
RunView::GetSelectionText(BString& string) const RunView::GetSelectionText(BString& string) const
{ {
@ -1597,6 +1562,7 @@ RunView::GetSelectionText (BString& string) const
} }
} }
bool bool
RunView::IntersectSelection(const SelectPos& start, const SelectPos& end) const RunView::IntersectSelection(const SelectPos& start, const SelectPos& end) const
{ {
@ -1623,6 +1589,7 @@ RunView::IntersectSelection (const SelectPos& start, const SelectPos& end) const
return false; return false;
} }
BRect BRect
RunView::GetTextFrame(const SelectPos& start, const SelectPos& end) const RunView::GetTextFrame(const SelectPos& start, const SelectPos& end) const
{ {
@ -1630,6 +1597,7 @@ RunView::GetTextFrame(const SelectPos& start, const SelectPos& end) const
Bounds().Width(), fLines[end.fLine]->fBottom); Bounds().Width(), fLines[end.fLine]->fBottom);
} }
void void
RunView::Select(const SelectPos& start, const SelectPos& end) RunView::Select(const SelectPos& start, const SelectPos& end)
{ {
@ -1683,8 +1651,9 @@ RunView::Select (const SelectPos& start, const SelectPos& end)
} }
} }
void void
RunView::SelectAll (void) RunView::SelectAll()
{ {
if (fLine_count) { if (fLine_count) {
fSp_start = SelectPos (0, 0); fSp_start = SelectPos (0, 0);
@ -1693,6 +1662,7 @@ RunView::SelectAll (void)
} }
} }
void void
RunView::SetClippingName(const char* name) RunView::SetClippingName(const char* name)
{ {
@ -1702,17 +1672,84 @@ RunView::SetClippingName (const char* name)
fClipping_name[strlen(name)] = '\0'; fClipping_name[strlen(name)] = '\0';
} }
Line::Line (
const char* buffer, bool
int len, RunView::FindText(const char* text)
float top, {
float width, bool result (false);
Theme* theme, if (text != NULL) {
const char* stamp_format, for (int32 i = 0; i < fLine_count; i++) {
int fore, char* offset (NULL);
int back, if ((offset = strstr((const char*)fLines[i], text)) != NULL) {
int font) SelectPos start (i, offset - text),
: fText (NULL), end (i, (offset - text) + strlen(text));
Select(start, end);
ScrollTo(0.0, fLines[i]->fTop);
result = true;
break;
}
}
}
return result;
}
void RunView::LoadURL(const char* url)
{
BString argument (url);
if (argument.FindFirst ("://") == B_ERROR) {
if (argument.IFindFirst ("www") == 0)
argument.Prepend ("http://");
else if (argument.IFindFirst ("ftp") == 0)
argument.Prepend ("ftp://");
}
const char* args[] = { argument.String(), 0 };
if (argument.IFindFirst ("file:") == 0) {
// The URL is guaranteed to be at least "file:/"
BString file(argument.String() + 5);
// todo: Should probably see if the file exists before going through
// all this, but, oh well... ;)
file.Prepend("/boot/beos/system/Tracker ");
file += " &"; // just in case
system(file.String());
} else if (argument.IFindFirst ("mailto:") == 0) {
be_roster->Launch ("text/x-email", 1, const_cast<char**>(args));
} else {
be_roster->Launch ("text/html", 1, const_cast<char**>(args));
}
}
void RunView::ScrollToBottom()
{
if (fLine_count != 0) {
BScrollBar* scroll = fScroller->ScrollBar(B_VERTICAL);
if (scroll != NULL) scroll->SetValue(fLines[fLine_count - 1]->fBottom);
ScrollTo(0.0, fLines[fLine_count - 1]->fBottom);
};
};
void RunView::ScrollToSelection()
{
if (fLine_count == 0) return;
if (fSp_start != fSp_end)
ScrollTo(0.0, fLines[fSp_start.fLine]->fTop);
};
Line::Line(const char* buffer, int len, float top, float width, Theme* theme,
const char* stamp_format, int fore, int back, int font)
:
fText (NULL),
fStamp (time(NULL)), fStamp (time(NULL)),
fUrls (NULL), fUrls (NULL),
fSpaces (NULL), fSpaces (NULL),
@ -1730,11 +1767,11 @@ Line::Line (
{ {
// Very important to call SetStamp before Append, It would look real funny otherwise! // Very important to call SetStamp before Append, It would look real funny otherwise!
SetStamp(stamp_format, false ); SetStamp(stamp_format, false );
Append(buffer, len, width, theme, fore, back, font ); Append(buffer, len, width, theme, fore, back, font );
} }
Line::~Line (void)
Line::~Line()
{ {
delete [] fSpaces; delete [] fSpaces;
delete [] fEdges; delete [] fEdges;
@ -1749,15 +1786,10 @@ Line::~Line (void)
} }
} }
void void
Line::Append ( Line::Append(const char* buffer, int len, float width, Theme* theme,
const char* buffer, int fore, int back, int font)
int len,
float width,
Theme* theme,
int fore,
int back,
int font)
{ {
int save (fLength); int save (fLength);
char* new_fText; char* new_fText;
@ -1798,8 +1830,9 @@ Line::Append (
} }
} }
void void
Line::FigureSpaces (void) Line::FigureSpaces()
{ {
const char spacers[] = " \t\n-\\/"; const char spacers[] = " \t\n-\\/";
const char* buffer (fText); const char* buffer (fText);
@ -1822,12 +1855,9 @@ Line::FigureSpaces (void)
} }
} }
void void
Line::FigureFontColors ( Line::FigureFontColors(int pos, int fore, int back, int font)
int pos,
int fore,
int back,
int font)
{ {
if (fFc_count) { if (fFc_count) {
int last_fore = -1; int last_fore = -1;
@ -1904,10 +1934,9 @@ Line::FigureFontColors (
} }
} }
void void
Line::FigureEdges ( Line::FigureEdges(Theme* theme, float width)
Theme* theme,
float width)
{ {
delete [] fEdges; delete [] fEdges;
fEdges = new float [fLength]; fEdges = new float [fLength];
@ -2100,6 +2129,7 @@ Line::AddSoftBreak (SoftBreakEnd sbe, float& start, int& fText_place,
width = start_width - (theme->SoftLineIndent()); width = start_width - (theme->SoftLineIndent());
} }
void void
Line::SoftBreaks(Theme* theme, float start_width) Line::SoftBreaks(Theme* theme, float start_width)
{ {
@ -2191,6 +2221,7 @@ Line::SoftBreaks (Theme* theme, float start_width)
fBottom -= 1; fBottom -= 1;
} }
int int
Line::CountChars(int pos, int len) Line::CountChars(int pos, int len)
{ {
@ -2211,6 +2242,7 @@ Line::CountChars (int pos, int len)
return ccount; return ccount;
} }
size_t size_t
Line::SetStamp(const char* format, bool was_on) Line::SetStamp(const char* format, bool was_on)
{ {
@ -2301,6 +2333,7 @@ Line::SetStamp (const char* format, bool was_on)
return size; return size;
} }
void void
Line::SelectWord(int* start, int* end) Line::SelectWord(int* start, int* end)
{ {
@ -2319,71 +2352,4 @@ Line::SelectWord (int* start, int* end)
*end = end_tmp; *end = end_tmp;
} }
bool
RunView::FindText(const char* text)
{
bool result (false);
if (text != NULL) {
for (int32 i = 0; i < fLine_count; i++) {
char* offset (NULL);
if ((offset = strstr((const char*)fLines[i], text)) != NULL) {
SelectPos start (i, offset - text),
end (i, (offset - text) + strlen(text));
Select(start, end);
ScrollTo(0.0, fLines[i]->fTop);
result = true;
break;
}
}
}
return result;
}
void RunView::LoadURL(const char* url)
{
BString argument (url);
if (argument.FindFirst ("://") == B_ERROR) {
if (argument.IFindFirst ("www") == 0)
argument.Prepend ("http://");
else if (argument.IFindFirst ("ftp") == 0)
argument.Prepend ("ftp://");
}
const char* args[] = { argument.String(), 0 };
if (argument.IFindFirst ("file:") == 0) {
// The URL is guaranteed to be at least "file:/"
BString file(argument.String() + 5);
// todo: Should probably see if the file exists before going through
// all this, but, oh well... ;)
file.Prepend("/boot/beos/system/Tracker ");
file += " &"; // just in case
system(file.String());
} else if (argument.IFindFirst ("mailto:") == 0) {
be_roster->Launch ("text/x-email", 1, const_cast<char**>(args));
} else {
be_roster->Launch ("text/html", 1, const_cast<char**>(args));
}
}
void RunView::ScrollToBottom(void)
{
if (fLine_count != 0) {
BScrollBar* scroll = fScroller->ScrollBar(B_VERTICAL);
if (scroll != NULL) scroll->SetValue(fLines[fLine_count - 1]->fBottom);
ScrollTo(0.0, fLines[fLine_count - 1]->fBottom);
};
};
void RunView::ScrollToSelection(void)
{
if (fLine_count == 0) return;
if (fSp_start != fSp_end)
ScrollTo(0.0, fLines[fSp_start.fLine]->fTop);
};