- Fixed a nasty regression which made the control unusable

- Fixed the "caret looks like a point" bug
- More work on the Styling code


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8638 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2004-08-25 06:49:43 +00:00
parent b9c2cb3cd1
commit 2a346d67a6
3 changed files with 161 additions and 132 deletions
+102 -90
View File
@@ -227,90 +227,6 @@ _BStyleBuffer_::GetNullStyle(const BFont **font,
*color = &fNullStyle.color;
}
//------------------------------------------------------------------------------
bool
_BStyleBuffer_::IsContinuousStyle(uint32 *ioMode, STEStylePtr outStyle,
int32 fromOffset, int32 toOffset)
{
if (fStyleRunDesc.ItemCount() < 1) {
SetStyle(*ioMode, &fNullStyle.font, &outStyle->font,
&fNullStyle.color, &outStyle->color);
return true;
}
bool result = true;
int32 fromIndex = OffsetToRun(fromOffset);
int32 toIndex = OffsetToRun(toOffset - 1);
if (fromIndex == toIndex) {
int32 styleIndex = fStyleRunDesc[fromIndex]->index;
STEStylePtr style = &fStyleRecord[styleIndex]->style;
SetStyle(*ioMode, &style->font, &outStyle->font, &style->color,
&outStyle->color);
result = true;
}
else {
int32 styleIndex = fStyleRunDesc[toIndex]->index;
STEStyle theStyle = fStyleRecord[styleIndex]->style;
//STEStylePtr style = NULL;
/* for (int32 i = fromIndex; i < toIndex; i++) {
styleIndex = fStyleRunDesc[i]->index;
style = &fStyleRecord[styleIndex]->style;
if (*ioMode & doFont) {
if (strcmp(theStyle.font, style->font) != 0) {
*ioMode &= ~doFont;
result = false;
}
}
if (*ioMode & doSize) {
if (theStyle.size != style->size) {
*ioMode &= ~doSize;
result = false;
}
}
if (*ioMode & doShear) {
if (theStyle.shear != style->shear) {
*ioMode &= ~doShear;
result = false;
}
}
if (*ioMode & doUnderline) {
if (theStyle.underline != style->underline) {
*ioMode &= ~doUnderline;
result = false;
}
}
if (*ioMode & doColor) {
if ( (theStyle.color.red != style->color.red) ||
(theStyle.color.green != style->color.green) ||
(theStyle.color.blue != style->color.blue) ||
(theStyle.color.alpha != style->color.alpha) ) {
*ioMode &= ~doColor;
result = false;
}
}
if (*ioMode & doExtra) {
if (theStyle.extra != style->extra) {
*ioMode &= ~doExtra;
result = false;
}
}
}*/
SetStyle(*ioMode, &theStyle.font, &outStyle->font, &theStyle.color,
&outStyle->color);
}
return result;
}
//------------------------------------------------------------------------------
void
_BStyleBuffer_::SetStyleRange(int32 fromOffset, int32 toOffset,
int32 textLen, uint32 inMode,
@@ -484,9 +400,10 @@ _BStyleBuffer_::Iterate(int32 fromOffset, int32 length, _BInlineInput_ *input,
const BFont **outFont, const rgb_color **outColor,
float *outAscent, float *outDescent, uint32 *) const
{
// TODO: Handle the _BInlineInput_ style here in some way
int32 numRuns = fStyleRunDesc.ItemCount();
if ((length < 1) || (numRuns < 1))
return (0);
if (length < 1 || numRuns < 1)
return 0;
int32 result = length;
int32 runIndex = fStyleRunDesc.OffsetToRun(fromOffset);
@@ -506,6 +423,7 @@ _BStyleBuffer_::Iterate(int32 fromOffset, int32 length, _BInlineInput_ *input,
result = (result > nextOffset) ? nextOffset : result;
}
return result;
}
//------------------------------------------------------------------------------
@@ -564,11 +482,105 @@ _BStyleBuffer_::operator[](int32 index) const
return run;
}
//------------------------------------------------------------------------------
/*void _BStyleBuffer_::ContinuousGetStyle(BFont *, uint32 *, rgb_color *, bool *,
int32, int32) const
void
_BStyleBuffer_::ContinuousGetStyle(BFont *outFont, uint32 *ioMode,
rgb_color *outColor, bool *sameColor, int32 fromOffset, int32 toOffset) const
{
}*/
uint32 mode = doAll;
if (fStyleRunDesc.ItemCount() < 1) {
if (ioMode)
*ioMode = mode;
if (outFont)
*outFont = fNullStyle.font;
if (outColor)
*outColor = fNullStyle.color;
if (sameColor)
*sameColor = true;
return;
}
int32 fromIndex = OffsetToRun(fromOffset);
int32 toIndex = OffsetToRun(toOffset - 1);
bool result = true;
if (fromIndex == toIndex) {
int32 styleIndex = fStyleRunDesc[fromIndex]->index;
STEStylePtr style = &fStyleRecord[styleIndex]->style;
if (ioMode)
*ioMode = mode;
if (outFont)
*outFont = style->font;
if (outColor)
*outColor = style->color;
if (sameColor)
*sameColor = true;
} else {
int32 styleIndex = fStyleRunDesc[toIndex]->index;
STEStyle theStyle = fStyleRecord[styleIndex]->style;
STEStylePtr style = NULL;
for (int32 i = fromIndex; i < toIndex; i++) {
styleIndex = fStyleRunDesc[i]->index;
style = &fStyleRecord[styleIndex]->style;
if (mode & doFont) {
if (theStyle.font != style->font) {
mode &= ~doFont;
result = false;
}
}
if (mode & doSize) {
if (theStyle.font.Size() != style->font.Size()) {
mode &= ~doSize;
result = false;
}
}
if (mode & doShear) {
if (theStyle.font.Shear() != style->font.Shear()) {
mode &= ~doShear;
result = false;
}
}
if (mode & doUnderline) {
// if (theStyle.underline != style->font.underline) {
mode &= ~doUnderline;
// result = false;
// }
}
if (mode & doColor) {
if ( (theStyle.color.red != style->color.red) ||
(theStyle.color.green != style->color.green) ||
(theStyle.color.blue != style->color.blue) ||
(theStyle.color.alpha != style->color.alpha) ) {
mode &= ~doColor;
result = false;
}
}
if (mode & doExtra) {
// if (theStyle.extra != style->font.extra) {
mode &= ~doExtra;
// result = false;
// }
}
}
if (ioMode)
*ioMode = mode;
if (outFont)
*outFont = theStyle.font;
if (outColor)
*outColor = theStyle.color;
if (sameColor)
*sameColor = result;
}
}
/*
* $Log $
+2 -2
View File
@@ -139,13 +139,13 @@ public:
void GetNullStyle(const BFont **font,
const rgb_color **color) const;
bool IsContinuousStyle(uint32 *ioMode, STEStylePtr outStyle,
int32 fromOffset, int32 toOffset);
void SetStyleRange(int32 fromOffset, int32 toOffset,
int32 textLen, uint32 inMode,
const BFont *inFont, const rgb_color *inColor);
void GetStyle(int32 inOffset, BFont *outFont,
rgb_color *outColor) const;
void ContinuousGetStyle(BFont *, uint32 *, rgb_color *,
bool *, int32, int32) const;
STEStyleRangePtr GetStyleRange(int32 startOffset, int32 endOffset) const;
void RemoveStyleRange(int32 fromOffset, int32 toOffset);
+57 -40
View File
@@ -1610,6 +1610,8 @@ BTextView::SetFontAndColor(int32 startOffset, int32 endOffset,
const rgb_color *inColor)
{
CALLED();
printf("SetFontAndColor(%ld, %ld, %p, mode: 0x%x, %p)\n",
startOffset, endOffset, inFont, inMode, inColor);
// hide the caret/unhilite the selection
if (fActive) {
if (startOffset != endOffset)
@@ -1660,12 +1662,9 @@ BTextView::GetFontAndColor(BFont *outFont, uint32 *outMode,
rgb_color *outColor, bool *outEqColor) const
{
CALLED();
// TODO fill in outMode and outEqColor
fStyles->GetStyle(fSelStart, outFont, outColor);
// TODO: This is a hack to make beshare work.
// We should use _BStyleBuffer_::ContinuousGetStyle() here.
*outMode = doSize;
fStyles->ContinuousGetStyle(outFont, outMode, outColor, outEqColor,
fSelStart, fSelEnd);
}
@@ -1781,43 +1780,57 @@ BTextView::PointAt(int32 inOffset, float *outHeight) const
BPoint result;
int32 textLength = fText->Length();
int32 lineNum = LineAt(inOffset);
// TODO: This looks broken. line + 1 could go outside the line buffer
STELinePtr line = (*fLines)[lineNum];
float height = (line + 1)->origin - line->origin;
float height = 0;
result.x = 0.0;
result.y = line->origin + fTextRect.top;
// special case: go down one line if inOffset is a newline
if (inOffset == textLength && (*fText)[textLength - 1] == '\n') {
float ascent, descent;
StyledWidth(inOffset, 1, &ascent, &descent);
// Handle the case where there is only one line
// (no text inserted)
// TODO: See if we can do this better
if (fStyles->NumRuns() == 0) {
const rgb_color *color = NULL;
const BFont *font = NULL;
fStyles->GetNullStyle(&font, &color);
result.y += height;
height = ascent + descent;
} else {
int32 offset = line->offset;
int32 length = inOffset - line->offset;
int32 numChars = length;
bool foundTab = false;
do {
foundTab = fText->FindChar(B_TAB, offset, &numChars);
font_height fontHeight;
font->GetHeight(&fontHeight);
height = fontHeight.ascent + fontHeight.descent;
result.x += StyledWidth(offset, numChars);
} else {
height = (line + 1)->origin - line->origin;
if (foundTab) {
result.x += ActualTabWidth(result.x);
numChars++;
}
// special case: go down one line if inOffset is a newline
if (inOffset == textLength && (*fText)[textLength - 1] == '\n') {
float ascent, descent;
StyledWidth(inOffset, 1, &ascent, &descent);
offset += numChars;
length -= numChars;
numChars = length;
} while (foundTab && length > 0);
}
result.y += height;
height = ascent + descent;
} else {
int32 offset = line->offset;
int32 length = inOffset - line->offset;
int32 numChars = length;
bool foundTab = false;
do {
foundTab = fText->FindChar(B_TAB, offset, &numChars);
result.x += StyledWidth(offset, numChars);
if (foundTab) {
result.x += ActualTabWidth(result.x);
numChars++;
}
offset += numChars;
length -= numChars;
numChars = length;
} while (foundTab && length > 0);
}
}
// convert from text rect coordinates
result.x += fTextRect.left - 1.0;
@@ -1888,7 +1901,7 @@ BTextView::OffsetAt(BPoint point) const
foundTab = fText->FindChar(B_TAB, offset, &numChars);
delta = numChars / 2;
delta = min_c(delta, 1);
delta = max_c(delta, 1);
if (numChars > 1) {
do {
@@ -1908,7 +1921,7 @@ BTextView::OffsetAt(BPoint point) const
// still too far to the left, measure some more
offset += delta;
delta /= 2;
delta = min_c(delta, 1);
delta = max_c(delta, 1);
}
} else {
// oops, we overshot the point, go back some
@@ -3038,13 +3051,17 @@ BTextView::HandlePageKey(uint32 inPageKey)
case B_PAGE_UP:
case B_PAGE_DOWN:
// TODO: Fix this
{
if (ScrollBar(B_VERTICAL) != NULL) {
float delta = Bounds().Height();
delta = (inPageKey == B_PAGE_UP) ? -delta : delta;
int32 currentOffset = OffsetAt(fClickOffset);
float delta = Bounds().Height();
delta = (inPageKey == B_PAGE_UP) ? -delta : delta;
if (ScrollBar(B_VERTICAL) != NULL)
ScrollBar(B_VERTICAL)->SetValue(ScrollBar(B_VERTICAL)->Value() + delta);
}
// TODO: Selection
GoToLine(LineAt(PointAt(currentOffset + delta)));
break;
}
}