Fixed some refresh bug I introduced in one of the latest commits. "Where are those millions open source code reviewers when you need them?". Word wrapping should work again. Some small style changes. Added some more TODO items and some comments.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8491 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -31,6 +31,8 @@
|
|||||||
// - Consider using BObjectList instead of BList
|
// - Consider using BObjectList instead of BList
|
||||||
// for disallowed charachters (it would remove a lot of reinterpret_casts)
|
// for disallowed charachters (it would remove a lot of reinterpret_casts)
|
||||||
// - Asynchronous mouse tracking
|
// - Asynchronous mouse tracking
|
||||||
|
// - Check for correctness and possible optimizations the calls to Refresh(),
|
||||||
|
// to refresh only changed parts of text (currently we often redraw the whole text)
|
||||||
|
|
||||||
// Standard Includes -----------------------------------------------------------
|
// Standard Includes -----------------------------------------------------------
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
@@ -101,6 +103,8 @@ enum {
|
|||||||
class _BTextTrackState_ {
|
class _BTextTrackState_ {
|
||||||
|
|
||||||
// TODO: Implement ?
|
// TODO: Implement ?
|
||||||
|
// It's most probably used to keep track of asynchronous mouse
|
||||||
|
// movements
|
||||||
public:
|
public:
|
||||||
_BTextTrackState_(bool inSelection)
|
_BTextTrackState_(bool inSelection)
|
||||||
: fMoved(false),
|
: fMoved(false),
|
||||||
@@ -112,7 +116,12 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Globals ---------------------------------------------------------------------
|
// Initialized/finalized by init/fini_interface_kit
|
||||||
|
_BWidthBuffer_* BTextView::sWidths = NULL;
|
||||||
|
sem_id BTextView::sWidthSem = B_BAD_SEM_ID;
|
||||||
|
int32 BTextView::sWidthAtom = 0;
|
||||||
|
|
||||||
|
|
||||||
static property_info
|
static property_info
|
||||||
sPropertyList[] = {
|
sPropertyList[] = {
|
||||||
{
|
{
|
||||||
@@ -168,12 +177,6 @@ sPropertyList[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Initialized/finalized by init/fini_interface_kit
|
|
||||||
_BWidthBuffer_* BTextView::sWidths = NULL;
|
|
||||||
sem_id BTextView::sWidthSem = B_BAD_SEM_ID;
|
|
||||||
int32 BTextView::sWidthAtom = 0;
|
|
||||||
|
|
||||||
|
|
||||||
BTextView::BTextView(BRect frame, const char *name, BRect textRect,
|
BTextView::BTextView(BRect frame, const char *name, BRect textRect,
|
||||||
uint32 resizeMask, uint32 flags)
|
uint32 resizeMask, uint32 flags)
|
||||||
: BView(frame, name, resizeMask,
|
: BView(frame, name, resizeMask,
|
||||||
@@ -995,7 +998,7 @@ BTextView::SetText(const char *inText, const text_run_array *inRuns)
|
|||||||
if (fText->Length() > 0)
|
if (fText->Length() > 0)
|
||||||
DeleteText(0, fText->Length()); // TODO: was fText->Length() - 1
|
DeleteText(0, fText->Length()); // TODO: was fText->Length() - 1
|
||||||
|
|
||||||
int len = (inText) ? strlen(inText) : 0;
|
int32 len = inText ? strlen(inText) : 0;
|
||||||
|
|
||||||
if (inText != NULL && len > 0)
|
if (inText != NULL && len > 0)
|
||||||
InsertText(inText, len, 0, inRuns);
|
InsertText(inText, len, 0, inRuns);
|
||||||
@@ -2143,7 +2146,7 @@ BTextView::SetTextRect(BRect rect)
|
|||||||
fTextRect = rect;
|
fTextRect = rect;
|
||||||
|
|
||||||
if (Window() != NULL)
|
if (Window() != NULL)
|
||||||
Refresh(0, fLines->NumLines(), true, false);
|
Refresh(0, fText->Length(), true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -2186,7 +2189,7 @@ BTextView::SetTabWidth(float width)
|
|||||||
fTabWidth = width;
|
fTabWidth = width;
|
||||||
|
|
||||||
if (Window() != NULL)
|
if (Window() != NULL)
|
||||||
Refresh(0, fLines->NumLines(), true, false);
|
Refresh(0, fText->Length(), true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -2296,7 +2299,7 @@ BTextView::SetWordWrap(bool wrap)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Refresh(0, fLines->NumLines(), true, false);
|
Refresh(0, fText->Length(), true, true);
|
||||||
|
|
||||||
if (fActive) {
|
if (fActive) {
|
||||||
// show the caret, hilite the selection
|
// show the caret, hilite the selection
|
||||||
@@ -2320,14 +2323,19 @@ BTextView::DoesWordWrap() const
|
|||||||
CALLED();
|
CALLED();
|
||||||
return fWrap;
|
return fWrap;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BTextView::SetMaxBytes(int32 max)
|
BTextView::SetMaxBytes(int32 max)
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
|
// TODO: Finish this:
|
||||||
|
// We probably have to check if the existing text is longer than the new
|
||||||
|
// fMaxBytes, and truncate if it's the case
|
||||||
fMaxBytes = max;
|
fMaxBytes = max;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
int32
|
int32
|
||||||
BTextView::MaxBytes() const
|
BTextView::MaxBytes() const
|
||||||
{
|
{
|
||||||
@@ -2363,7 +2371,8 @@ BTextView::AllowChar(uint32 aChar)
|
|||||||
if (fDisallowedChars != NULL)
|
if (fDisallowedChars != NULL)
|
||||||
fDisallowedChars->RemoveItem(reinterpret_cast<void *>(aChar));
|
fDisallowedChars->RemoveItem(reinterpret_cast<void *>(aChar));
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BTextView::SetAlignment(alignment flag)
|
BTextView::SetAlignment(alignment flag)
|
||||||
{
|
{
|
||||||
@@ -2381,21 +2390,24 @@ BTextView::SetAlignment(alignment flag)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
alignment
|
alignment
|
||||||
BTextView::Alignment() const
|
BTextView::Alignment() const
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
return fAlignment;
|
return fAlignment;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BTextView::SetAutoindent(bool state)
|
BTextView::SetAutoindent(bool state)
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
fAutoindent = state;
|
fAutoindent = state;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
BTextView::DoesAutoindent() const
|
BTextView::DoesAutoindent() const
|
||||||
{
|
{
|
||||||
@@ -2428,7 +2440,8 @@ BTextView::ColorSpace() const
|
|||||||
CALLED();
|
CALLED();
|
||||||
return fColorSpace;
|
return fColorSpace;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BTextView::MakeResizable(bool resize, BView *resizeView)
|
BTextView::MakeResizable(bool resize, BView *resizeView)
|
||||||
{
|
{
|
||||||
@@ -2447,7 +2460,7 @@ BTextView::MakeResizable(bool resize, BView *resizeView)
|
|||||||
|
|
||||||
else if (fCaretVisible) {
|
else if (fCaretVisible) {
|
||||||
InvertCaret();
|
InvertCaret();
|
||||||
Refresh(0, fLines->NumLines(), true, false);
|
Refresh(0, fText->Length(), true, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2459,33 +2472,38 @@ BTextView::MakeResizable(bool resize, BView *resizeView)
|
|||||||
NewOffscreen();
|
NewOffscreen();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
BTextView::IsResizable() const
|
BTextView::IsResizable() const
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
return fResizable;
|
return fResizable;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BTextView::SetDoesUndo(bool undo)
|
BTextView::SetDoesUndo(bool undo)
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
if (undo && fUndo == NULL)
|
if (undo && fUndo == NULL)
|
||||||
fUndo = new _BUndoBuffer_(this, B_UNDO_UNAVAILABLE);
|
fUndo = new _BUndoBuffer_(this, B_UNDO_UNAVAILABLE);
|
||||||
|
|
||||||
else if (!undo && fUndo != NULL) {
|
else if (!undo && fUndo != NULL) {
|
||||||
delete fUndo;
|
delete fUndo;
|
||||||
fUndo = NULL;
|
fUndo = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
BTextView::DoesUndo() const
|
BTextView::DoesUndo() const
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
return fUndo != NULL;
|
return fUndo != NULL;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BTextView::HideTyping(bool enabled)
|
BTextView::HideTyping(bool enabled)
|
||||||
{
|
{
|
||||||
@@ -2493,14 +2511,16 @@ BTextView::HideTyping(bool enabled)
|
|||||||
//TODO: Implement ?
|
//TODO: Implement ?
|
||||||
//fText->SetPasswordMode(enabled);
|
//fText->SetPasswordMode(enabled);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
BTextView::IsTypingHidden() const
|
BTextView::IsTypingHidden() const
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
return fText->PasswordMode();
|
return fText->PasswordMode();
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BTextView::ResizeToPreferred()
|
BTextView::ResizeToPreferred()
|
||||||
{
|
{
|
||||||
@@ -2509,28 +2529,32 @@ BTextView::ResizeToPreferred()
|
|||||||
GetPreferredSize(&widht, &height);
|
GetPreferredSize(&widht, &height);
|
||||||
BView::ResizeTo(widht, height);
|
BView::ResizeTo(widht, height);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BTextView::GetPreferredSize(float *width, float *height)
|
BTextView::GetPreferredSize(float *width, float *height)
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
BView::GetPreferredSize(width, height);
|
BView::GetPreferredSize(width, height);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BTextView::AllAttached()
|
BTextView::AllAttached()
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
BView::AllAttached();
|
BView::AllAttached();
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BTextView::AllDetached()
|
BTextView::AllDetached()
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
BView::AllDetached();
|
BView::AllDetached();
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
void *
|
void *
|
||||||
BTextView::FlattenRunArray(const text_run_array *inArray, int32 *outSize)
|
BTextView::FlattenRunArray(const text_run_array *inArray, int32 *outSize)
|
||||||
{
|
{
|
||||||
@@ -2573,7 +2597,8 @@ BTextView::FlattenRunArray(const text_run_array *inArray, int32 *outSize)
|
|||||||
|
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
text_run_array *
|
text_run_array *
|
||||||
BTextView::UnflattenRunArray(const void *data, int32 *outSize)
|
BTextView::UnflattenRunArray(const void *data, int32 *outSize)
|
||||||
{
|
{
|
||||||
@@ -2694,7 +2719,8 @@ BTextView::GetDragParameters(BMessage *drag, BBitmap **bitmap,
|
|||||||
if (drag == NULL)
|
if (drag == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// What is this for ?
|
// Add originator and action
|
||||||
|
drag->AddPointer("be:originator", this);
|
||||||
drag->AddInt32("be_actions", B_TRASH_TARGET);
|
drag->AddInt32("be_actions", B_TRASH_TARGET);
|
||||||
|
|
||||||
// add the text
|
// add the text
|
||||||
@@ -2708,9 +2734,6 @@ BTextView::GetDragParameters(BMessage *drag, BBitmap **bitmap,
|
|||||||
drag->AddData("application/x-vnd.Be-text_run_array", B_MIME_TYPE,
|
drag->AddData("application/x-vnd.Be-text_run_array", B_MIME_TYPE,
|
||||||
styles, size);
|
styles, size);
|
||||||
|
|
||||||
// add the message originator
|
|
||||||
drag->AddPointer("be:originator", this);
|
|
||||||
|
|
||||||
free(styles);
|
free(styles);
|
||||||
|
|
||||||
if (bitmap != NULL)
|
if (bitmap != NULL)
|
||||||
@@ -3467,6 +3490,8 @@ void
|
|||||||
BTextView::DrawLines(int32 startLine, int32 endLine, int32 startOffset,
|
BTextView::DrawLines(int32 startLine, int32 endLine, int32 startOffset,
|
||||||
bool erase)
|
bool erase)
|
||||||
{
|
{
|
||||||
|
// TODO: Draw on the "fOffscreen" BBitmap, then draw it on the view
|
||||||
|
|
||||||
CALLED();
|
CALLED();
|
||||||
// clip the text
|
// clip the text
|
||||||
BRect clipRect = Bounds() & fTextRect;
|
BRect clipRect = Bounds() & fTextRect;
|
||||||
@@ -4034,7 +4059,7 @@ BTextView::PreviousInitialByte(int32 offset) const
|
|||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
const char *text = Text();
|
const char *text = Text();
|
||||||
int count = 6;
|
int32 count = 6;
|
||||||
|
|
||||||
for (--offset; (text + offset) > text && count; --offset, --count) {
|
for (--offset; (text + offset) > text && count; --offset, --count) {
|
||||||
if ((*(text + offset) & 0xc0 ) != 0x80)
|
if ((*(text + offset) & 0xc0 ) != 0x80)
|
||||||
@@ -4060,12 +4085,11 @@ BTextView::GetProperty(BMessage *specifier, int32 form,
|
|||||||
|
|
||||||
} else if (strcmp(property, "Text") == 0) {
|
} else if (strcmp(property, "Text") == 0) {
|
||||||
int32 index, range;
|
int32 index, range;
|
||||||
char *buffer;
|
|
||||||
|
|
||||||
specifier->FindInt32("index", &index);
|
specifier->FindInt32("index", &index);
|
||||||
specifier->FindInt32("range", &range);
|
specifier->FindInt32("range", &range);
|
||||||
|
|
||||||
buffer = new char[range + 1];
|
char *buffer = new char[range + 1];
|
||||||
GetText(index, range, buffer);
|
GetText(index, range, buffer);
|
||||||
|
|
||||||
reply->what = B_REPLY;
|
reply->what = B_REPLY;
|
||||||
@@ -4102,11 +4126,11 @@ BTextView::SetProperty(BMessage *specifier, int32 form,
|
|||||||
|
|
||||||
} else if (strcmp(property, "Text") == 0) {
|
} else if (strcmp(property, "Text") == 0) {
|
||||||
int32 index, range;
|
int32 index, range;
|
||||||
const char *buffer;
|
|
||||||
|
|
||||||
specifier->FindInt32("index", &index);
|
specifier->FindInt32("index", &index);
|
||||||
specifier->FindInt32("range", &range);
|
specifier->FindInt32("range", &range);
|
||||||
|
|
||||||
|
const char *buffer = NULL;
|
||||||
if (specifier->FindString("data", &buffer) == B_OK)
|
if (specifier->FindString("data", &buffer) == B_OK)
|
||||||
InsertText(buffer, range, index, NULL);
|
InsertText(buffer, range, index, NULL);
|
||||||
else
|
else
|
||||||
@@ -4175,7 +4199,7 @@ BTextView::HandleInputMethodChanged(BMessage *message)
|
|||||||
fSelStart += stringLen;
|
fSelStart += stringLen;
|
||||||
fClickOffset = fSelEnd = fSelStart;
|
fClickOffset = fSelEnd = fSelStart;
|
||||||
|
|
||||||
Refresh(0, fLines->NumLines(), true, false);
|
Refresh(0, fSelEnd, true, false);
|
||||||
|
|
||||||
// If we find the "be:confirmed" boolean (and the boolean is true),
|
// If we find the "be:confirmed" boolean (and the boolean is true),
|
||||||
// it means it's over for now, so the current _BInlineInput_ object
|
// it means it's over for now, so the current _BInlineInput_ object
|
||||||
|
|||||||
Reference in New Issue
Block a user