From f6cd639a4bb6d8b2408a16eb69d2c9d26653e29f Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Tue, 31 Aug 2004 07:08:49 +0000 Subject: [PATCH] Sheesh! No wonder the styling code wasn't fully working, as we were using different constants for font attributes than the ones used by BeOS R5. Now we use those constants directly. Still not ok, but we are on the right track now (I hope :)) git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8738 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/BTextView/StyleBuffer.cpp | 65 ++++++++------------ src/kits/interface/BTextView/StyleBuffer.h | 20 +----- src/kits/interface/BTextView/TextView.cpp | 10 +-- 3 files changed, 33 insertions(+), 62 deletions(-) diff --git a/src/kits/interface/BTextView/StyleBuffer.cpp b/src/kits/interface/BTextView/StyleBuffer.cpp index cc0f50de1f..b8da9f5fb8 100644 --- a/src/kits/interface/BTextView/StyleBuffer.cpp +++ b/src/kits/interface/BTextView/StyleBuffer.cpp @@ -27,6 +27,8 @@ #include "InlineInput.h" #include "StyleBuffer.h" +#include // For B_FONT_FAMILY_AND_STYLE, B_FONT_SIZE, etc. + // _BStyleRunDescBuffer_ @@ -459,24 +461,17 @@ _BStyleBuffer_::SetStyle(uint32 mode, const BFont *fromFont, BFont *toFont, const rgb_color *fromColor, rgb_color *toColor) { - if (mode & doFont) + if (mode & B_FONT_FAMILY_AND_STYLE) toFont->SetFamilyAndStyle(fromFont->FamilyAndStyle()); - if (mode & doSize) { - if (mode & addSize) - toFont->SetSize(fromFont->Size()); - else - toFont->SetSize(fromFont->Size()); - } + if (mode & B_FONT_SIZE) + toFont->SetSize(fromFont->Size()); - if (mode & doShear) + if (mode & B_FONT_SHEAR) toFont->SetShear(fromFont->Shear()); - if (mode & doUnderline) - toFont->SetFace(fromFont->Face()); - - if (mode & doColor) - *toColor = *fromColor; + //if (mode & doColor) + // *toColor = *fromColor; } @@ -503,7 +498,8 @@ void _BStyleBuffer_::ContinuousGetStyle(BFont *outFont, uint32 *ioMode, rgb_color *outColor, bool *sameColor, int32 fromOffset, int32 toOffset) const { - uint32 mode = doAll; + uint32 mode = B_FONT_ALL; + if (fStyleRunDesc.ItemCount() < 1) { if (ioMode) *ioMode = mode; @@ -542,42 +538,31 @@ _BStyleBuffer_::ContinuousGetStyle(BFont *outFont, uint32 *ioMode, styleIndex = fStyleRunDesc[i]->index; style = &fStyleRecord[styleIndex]->style; - if (mode & doFont) { + if (mode & B_FONT_FAMILY_AND_STYLE) { if (theStyle.font != style->font) - mode &= ~doFont; + mode &= ~B_FONT_FAMILY_AND_STYLE; } - if (mode & doSize) { + if (mode & B_FONT_SIZE) { if (theStyle.font.Size() != style->font.Size()) - mode &= ~doSize; + mode &= ~B_FONT_SIZE; } - if (mode & doShear) { + if (mode & B_FONT_SHEAR) { if (theStyle.font.Shear() != style->font.Shear()) - mode &= ~doShear; + mode &= ~B_FONT_SHEAR; } - - if (mode & doUnderline) { - // if (theStyle.underline != style->font.underline) { - mode &= ~doUnderline; - // } - } - - 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; - oneColor = false; - } + + 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) ) { + oneColor = false; } - if (mode & doExtra) { - // if (theStyle.extra != style->font.extra) { - mode &= ~doExtra; - // } - } + // TODO: Finish this: handle B_FONT_FACE, B_FONT_FLAGS, etc. + // if needed + } if (ioMode) diff --git a/src/kits/interface/BTextView/StyleBuffer.h b/src/kits/interface/BTextView/StyleBuffer.h index 78a5b42839..a41b7b1696 100644 --- a/src/kits/interface/BTextView/StyleBuffer.h +++ b/src/kits/interface/BTextView/StyleBuffer.h @@ -27,26 +27,12 @@ // Standard Includes ----------------------------------------------------------- // System Includes ------------------------------------------------------------- -#include -#include -#include "TextViewSupportBuffer.h" #include +#include +#include -// Project Includes ------------------------------------------------------------ +#include "TextViewSupportBuffer.h" -// Local Includes -------------------------------------------------------------- - -// Local Defines --------------------------------------------------------------- -enum { - doFont = 0x00000001, // set font - doSize = 0x00000002, // set size - doShear = 0x00000004, // set shear - doUnderline = 0x00000008, // set underline - doColor = 0x00000010, // set color - doExtra = 0x00000020, // set the extra field - doAll = 0x0000003F, // set everything - addSize = 0x00010000 // add size value -}; typedef struct STEStyle { BFont font; // font diff --git a/src/kits/interface/BTextView/TextView.cpp b/src/kits/interface/BTextView/TextView.cpp index be5d0be84d..b958e398fa 100644 --- a/src/kits/interface/BTextView/TextView.cpp +++ b/src/kits/interface/BTextView/TextView.cpp @@ -1095,7 +1095,7 @@ BTextView::SetText(BFile *inFile, int32 inOffset, int32 inLength, // apply nullStyle to inserted text fStyles->SyncNullStyle(inOffset); fStyles->SetStyleRange(inOffset, inOffset + inLength, - fText->Length(), doAll, NULL, NULL); + fText->Length(), B_FONT_ALL, NULL, NULL); } fClickOffset = fSelStart = fSelEnd = 0; @@ -1605,7 +1605,7 @@ BTextView::SetFontAndColor(const BFont *inFont, uint32 inMode, fStyles->SetStyleRange(fSelStart, fSelEnd, fText->Length(), inMode, &newFont, inColor); - if (inMode & doFont || inMode & doSize) + if (inMode & B_FONT_FAMILY_AND_STYLE || inMode & B_FONT_SIZE) // recalc the line breaks and redraw with new style Refresh(fSelStart, fSelEnd, fSelStart != fSelEnd, false); else @@ -1647,7 +1647,7 @@ BTextView::SetFontAndColor(int32 startOffset, int32 endOffset, fStyles->SetStyleRange(startOffset, endOffset, fText->Length(), inMode, &newFont, inColor); - if (inMode & doFont || inMode & doSize) + if (inMode & B_FONT_FAMILY_AND_STYLE || inMode & B_FONT_SIZE) // recalc the line breaks and redraw with new style Refresh(startOffset, endOffset, startOffset != endOffset, false); else @@ -1712,7 +1712,7 @@ BTextView::SetRunArray(int32 startOffset, int32 endOffset, } fStyles->SetStyleRange(fromOffset, toOffset, textLength, - doAll, &theRun->font, &theRun->color); + B_FONT_ALL, &theRun->font, &theRun->color); theRun++; } @@ -2727,7 +2727,7 @@ BTextView::InsertText(const char *inText, int32 inLength, int32 inOffset, // apply nullStyle to inserted text fStyles->SyncNullStyle(inOffset); fStyles->SetStyleRange(inOffset, inOffset + inLength, - fText->Length(), doAll, NULL, NULL); + fText->Length(), B_FONT_ALL, NULL, NULL); } } //------------------------------------------------------------------------------