Now it checks (on KeyDown()) if the entered charachter is allowed, and it doesn't insert (and beeps) if not.

More documentation,
some more cleanups,
started implementing input methods messages handling (but don't hold your breath)


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8157 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2004-06-25 10:00:29 +00:00
parent 55a855f813
commit 5a5aa2e3c5
+323 -97
View File
@@ -26,7 +26,11 @@
// Description: BTextView displays and manages styled text. // Description: BTextView displays and manages styled text.
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// TODO: Finish documenting this class // TODO:
// - Finish documenting this class
// - Consider using _PointerList_/BObjectList instead of BList
// for disallowed charachters (it would remove a lot of reinterpret_casts)
// Standard Includes ----------------------------------------------------------- // Standard Includes -----------------------------------------------------------
#include <cstdlib> #include <cstdlib>
@@ -34,9 +38,11 @@
// System Includes ------------------------------------------------------------- // System Includes -------------------------------------------------------------
#include <Application.h> #include <Application.h>
#include <Beep.h>
#include <Bitmap.h> #include <Bitmap.h>
#include <Clipboard.h> #include <Clipboard.h>
#include <Errors.h> #include <Errors.h>
#include <Input.h>
#include <Message.h> #include <Message.h>
#include <PropertyInfo.h> #include <PropertyInfo.h>
#include <Region.h> #include <Region.h>
@@ -166,7 +172,6 @@ sem_id BTextView::sWidthSem = B_BAD_SEM_ID;
int32 BTextView::sWidthAtom = 0; 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,
@@ -209,7 +214,8 @@ BTextView::BTextView(BRect frame, const char *name, BRect textRect,
CALLED(); CALLED();
InitObject(textRect, NULL, NULL); InitObject(textRect, NULL, NULL);
} }
//------------------------------------------------------------------------------
BTextView::BTextView(BRect frame, const char *name, BRect textRect, BTextView::BTextView(BRect frame, const char *name, BRect textRect,
const BFont *initialFont, const rgb_color *initialColor, const BFont *initialFont, const rgb_color *initialColor,
uint32 resizeMask, uint32 flags) uint32 resizeMask, uint32 flags)
@@ -344,11 +350,11 @@ BTextView::~BTextView()
delete fStyles; delete fStyles;
delete fDisallowedChars; delete fDisallowedChars;
delete fUndo; delete fUndo;
delete fOffscreen;
DeleteOffscreen();
} }
/*! \brief Static function used to istantiate a BTextView object from the given BMessage. /*! \brief Static function used to istantiate a BTextView object from the given BMessage.
\param archive The BMessage from which the object shall be created. \param archive The BMessage from which the object shall be created.
\return A constructed BTextView as a BArchivable object. \return A constructed BTextView as a BArchivable object.
@@ -519,6 +525,10 @@ BTextView::MouseDown(BPoint where)
bigtime_t clickSpeed = 0; bigtime_t clickSpeed = 0;
get_click_speed(&clickSpeed); get_click_speed(&clickSpeed);
// TODO: it looks like the input server sends the number of clicks in the
// B_MOUSE_DOWN message (the "clicks" field), so we could use it instead
// of doing this mess.
// is this a double/triple click, or is it a new click? // is this a double/triple click, or is it a new click?
if (clickSpeed > (system_time() - fClickTime) && if (clickSpeed > (system_time() - fClickTime) &&
mouseOffset == fClickOffset ) { mouseOffset == fClickOffset ) {
@@ -710,6 +720,13 @@ BTextView::KeyDown(const char *bytes, int32 numBytes)
const char keyPressed = bytes[0]; const char keyPressed = bytes[0];
// if the charachter is not allowed, bail out.
if (fDisallowedChars
&& fDisallowedChars->HasItem(reinterpret_cast<void *>((uint32)keyPressed))) {
beep();
return;
}
// hide the cursor and caret // hide the cursor and caret
be_app->ObscureCursor(); be_app->ObscureCursor();
if (fCaretVisible) if (fCaretVisible)
@@ -851,7 +868,15 @@ BTextView::MessageReceived(BMessage *message)
case B_SELECT_ALL: case B_SELECT_ALL:
SelectAll(); SelectAll();
break; break;
case B_INPUT_METHOD_CHANGED:
HandleInputMethodChanged(message);
break;
case B_INPUT_METHOD_LOCATION_REQUEST:
HandleInputMethodLocationRequest();
break;
case B_SET_PROPERTY: case B_SET_PROPERTY:
case B_GET_PROPERTY: case B_GET_PROPERTY:
case B_COUNT_PROPERTIES: case B_COUNT_PROPERTIES:
@@ -932,20 +957,8 @@ BTextView::ResolveSpecifier(BMessage *message, int32 index,
BPropertyInfo propInfo(sPropertyList); BPropertyInfo propInfo(sPropertyList);
BHandler *target = NULL; BHandler *target = NULL;
switch (propInfo.FindMatch(message, index, specifier, what, property)) { if (propInfo.FindMatch(message, index, specifier, what, property) != B_ERROR)
case 0: target = this;
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
target = this;
break;
case B_ERROR:
default:
break;
}
if (!target) if (!target)
target = BView::ResolveSpecifier(message, index, specifier, what, target = BView::ResolveSpecifier(message, index, specifier, what,
@@ -1150,7 +1163,10 @@ BTextView::Insert(int32 startOffset, const char *inText, int32 inLength,
} }
} }
} }
//------------------------------------------------------------------------------
/*! \brief Deletes the selected text.
*/
void void
BTextView::Delete() BTextView::Delete()
{ {
@@ -1184,7 +1200,12 @@ BTextView::Delete()
InvertCaret(); InvertCaret();
} }
} }
//------------------------------------------------------------------------------
/*! \brief Delets the text comprised within the given offsets.
\param startOffset The offset of the text to delete.
\param endOffset The offset where the text to delete ends.
*/
void void
BTextView::Delete(int32 startOffset, int32 endOffset) BTextView::Delete(int32 startOffset, int32 endOffset)
{ {
@@ -1215,14 +1236,26 @@ BTextView::Delete(int32 startOffset, int32 endOffset)
InvertCaret(); InvertCaret();
} }
} }
//------------------------------------------------------------------------------
/*! \brief Returns the BTextView text as a C string.
\return A pointer to the text.
It is possible that the BTextView object had to do some operations
on the text, to be able to return it as a C string.
If you need to call Text() repeatedly, you'd better use GetText().
*/
const char * const char *
BTextView::Text() const BTextView::Text() const
{ {
CALLED(); CALLED();
return fText->Text(); return fText->Text();
} }
//------------------------------------------------------------------------------
/*! \brief Returns the length of the BTextView's text.
\return The length of the text.
*/
int32 int32
BTextView::TextLength() const BTextView::TextLength() const
{ {
@@ -1248,7 +1281,12 @@ BTextView::GetText(int32 offset, int32 length, char *buffer) const
buffer[i] = (*fText)[i + offset]; buffer[i] = (*fText)[i + offset];
buffer[length] = '\0'; buffer[length] = '\0';
} }
//------------------------------------------------------------------------------
/*! \brief Returns the charachter at the given offset.
\param offset The offset of the wanted charachter.
\return The charachter at the given offset.
*/
uchar uchar
BTextView::ByteAt(int32 offset) const BTextView::ByteAt(int32 offset) const
{ {
@@ -1265,21 +1303,30 @@ BTextView::CountLines() const
CALLED(); CALLED();
return fLines->NumLines(); return fLines->NumLines();
} }
//------------------------------------------------------------------------------
/*! \brief Returns the index of the current line.
\return The index of the current line.
*/
int32 int32
BTextView::CurrentLine() const BTextView::CurrentLine() const
{ {
CALLED(); CALLED();
return LineAt(fSelStart); return LineAt(fSelStart);
} }
//------------------------------------------------------------------------------
void void
BTextView::GoToLine(int32 index) BTextView::GoToLine(int32 index)
{ {
CALLED(); CALLED();
fSelStart = fSelEnd = OffsetAt(index); fSelStart = fSelEnd = OffsetAt(index);
} }
//------------------------------------------------------------------------------
/*! \brief Cuts the current selection to the clipboard.
\param clipboard The clipboard where to copy the cutted text.
*/
void void
BTextView::Cut(BClipboard *clipboard) BTextView::Cut(BClipboard *clipboard)
{ {
@@ -1291,7 +1338,11 @@ BTextView::Cut(BClipboard *clipboard)
Copy(clipboard); Copy(clipboard);
Delete(); Delete();
} }
//------------------------------------------------------------------------------
/*! \brief Copies the current selection to the clipboard.
\param clipboard The clipboard where to copy the selected text.
*/
void void
BTextView::Copy(BClipboard *clipboard) BTextView::Copy(BClipboard *clipboard)
{ {
@@ -1317,7 +1368,11 @@ BTextView::Copy(BClipboard *clipboard)
clipboard->Unlock(); clipboard->Unlock();
} }
} }
//------------------------------------------------------------------------------
/*! \brief Paste the text contained in the clipboard to the BTextView.
\param clipboard A pointer to the clipboard.
*/
void void
BTextView::Paste(BClipboard *clipboard) BTextView::Paste(BClipboard *clipboard)
{ {
@@ -1343,6 +1398,7 @@ BTextView::Paste(BClipboard *clipboard)
delete fUndo; delete fUndo;
fUndo = new _BPasteUndoBuffer_(this, text, len, runArray, runLen); fUndo = new _BPasteUndoBuffer_(this, text, len, runArray, runLen);
} }
if (fSelStart != fSelEnd) if (fSelStart != fSelEnd)
Delete(); Delete();
@@ -1353,14 +1409,16 @@ BTextView::Paste(BClipboard *clipboard)
clipboard->Unlock(); clipboard->Unlock();
} }
} }
//------------------------------------------------------------------------------
void void
BTextView::Clear() BTextView::Clear()
{ {
CALLED(); CALLED();
Delete(); Delete();
} }
//------------------------------------------------------------------------------
bool bool
BTextView::AcceptsPaste(BClipboard *clipboard) BTextView::AcceptsPaste(BClipboard *clipboard)
{ {
@@ -1378,7 +1436,8 @@ BTextView::AcceptsPaste(BClipboard *clipboard)
return result; return result;
} }
//------------------------------------------------------------------------------
bool bool
BTextView::AcceptsDrop(const BMessage *inMessage) BTextView::AcceptsDrop(const BMessage *inMessage)
{ {
@@ -1388,7 +1447,12 @@ BTextView::AcceptsDrop(const BMessage *inMessage)
return false; return false;
} }
//------------------------------------------------------------------------------
/*! \brief Selects the text within the given offsets.
\param startOffset The offset of the text to select.
\param endOffset The offset where the text ends.
*/
void void
BTextView::Select(int32 startOffset, int32 endOffset) BTextView::Select(int32 startOffset, int32 endOffset)
{ {
@@ -1454,14 +1518,22 @@ BTextView::Select(int32 startOffset, int32 endOffset)
fSelEnd = endOffset; fSelEnd = endOffset;
} }
} }
//------------------------------------------------------------------------------
/*! \brief Selects all the text in the BTextView.
*/
void void
BTextView::SelectAll() BTextView::SelectAll()
{ {
CALLED(); CALLED();
Select(0, fText->Length()); Select(0, fText->Length());
} }
//------------------------------------------------------------------------------
/*! \brief Gets the current selection.
\param outStart A pointer to an int32 which will contain the selection start's offset.
\param outEnd A pointer to an int32 which will contain the selection end's offset.
*/
void void
BTextView::GetSelection(int32 *outStart, int32 *outEnd) const BTextView::GetSelection(int32 *outStart, int32 *outEnd) const
{ {
@@ -1474,7 +1546,8 @@ BTextView::GetSelection(int32 *outStart, int32 *outEnd) const
*outEnd = 0; *outEnd = 0;
} }
} }
//------------------------------------------------------------------------------
void void
BTextView::SetFontAndColor(const BFont *inFont, uint32 inMode, BTextView::SetFontAndColor(const BFont *inFont, uint32 inMode,
const rgb_color *inColor) const rgb_color *inColor)
@@ -1514,7 +1587,8 @@ BTextView::SetFontAndColor(const BFont *inFont, uint32 inMode,
} }
} }
} }
//------------------------------------------------------------------------------
void void
BTextView::SetFontAndColor(int32 startOffset, int32 endOffset, BTextView::SetFontAndColor(int32 startOffset, int32 endOffset,
const BFont *inFont, uint32 inMode, const BFont *inFont, uint32 inMode,
@@ -1555,7 +1629,8 @@ BTextView::SetFontAndColor(int32 startOffset, int32 endOffset,
} }
} }
} }
//------------------------------------------------------------------------------
void void
BTextView::GetFontAndColor(int32 inOffset, BFont *outFont, BTextView::GetFontAndColor(int32 inOffset, BFont *outFont,
rgb_color *outColor) const rgb_color *outColor) const
@@ -1563,7 +1638,8 @@ BTextView::GetFontAndColor(int32 inOffset, BFont *outFont,
CALLED(); CALLED();
fStyles->GetStyle(inOffset, outFont, outColor); fStyles->GetStyle(inOffset, outFont, outColor);
} }
//------------------------------------------------------------------------------
void void
BTextView::GetFontAndColor(BFont *outFont, uint32 *outMode, BTextView::GetFontAndColor(BFont *outFont, uint32 *outMode,
rgb_color *outColor, bool *outEqColor) const rgb_color *outColor, bool *outEqColor) const
@@ -1576,7 +1652,8 @@ BTextView::GetFontAndColor(BFont *outFont, uint32 *outMode,
// We should use _BStyleBuffer_::ContinuousGetStyle() here. // We should use _BStyleBuffer_::ContinuousGetStyle() here.
*outMode = doSize; *outMode = doSize;
} }
//------------------------------------------------------------------------------
void void
BTextView::SetRunArray(int32 startOffset, int32 endOffset, BTextView::SetRunArray(int32 startOffset, int32 endOffset,
const text_run_array *inRuns) const text_run_array *inRuns)
@@ -1609,7 +1686,18 @@ BTextView::SetRunArray(int32 startOffset, int32 endOffset,
Refresh(startOffset, endOffset, true, false); Refresh(startOffset, endOffset, true, false);
} }
} }
//------------------------------------------------------------------------------
/*! \brief Returns a RunArray for the text within the given offsets.
\param startOffset The offset where to start.
\param endOffset The offset where the wanted text ends.
\param outSize A pointer to an int32 which will contain the size
of the run array.
\return A text_run_array for the text in the given offsets.
The returned text_run_array belongs to the caller, so you better
free it as soon as you don't need it.
*/
text_run_array * text_run_array *
BTextView::RunArray(int32 startOffset, int32 endOffset, BTextView::RunArray(int32 startOffset, int32 endOffset,
int32 *outSize) const int32 *outSize) const
@@ -1636,14 +1724,24 @@ BTextView::RunArray(int32 startOffset, int32 endOffset,
return res; return res;
} }
//------------------------------------------------------------------------------
/*! \brief Returns the line number for the charachter at the given offset.
\param offset The offset of the wanted charachter.
\return A line number.
*/
int32 int32
BTextView::LineAt(int32 offset) const BTextView::LineAt(int32 offset) const
{ {
CALLED(); CALLED();
return fLines->OffsetToLine(offset); return fLines->OffsetToLine(offset);
} }
//------------------------------------------------------------------------------
/*! \brief Returns the line number for the given point.
\param point A point.
\return A line number.
*/
int32 int32
BTextView::LineAt(BPoint point) const BTextView::LineAt(BPoint point) const
{ {
@@ -1863,14 +1961,15 @@ BTextView::FindWord(int32 inOffset, int32 *outFromOffset,
*outToOffset = offset; *outToOffset = offset;
} }
//------------------------------------------------------------------------------
bool bool
BTextView::CanEndLine(int32 offset) BTextView::CanEndLine(int32 offset)
{ {
CALLED(); CALLED();
return (CharClassification(offset) == B_SEPARATOR_CHARACTER); return (CharClassification(offset) == B_SEPARATOR_CHARACTER);
} }
//------------------------------------------------------------------------------
float float
BTextView::LineWidth(int32 lineNum) const BTextView::LineWidth(int32 lineNum) const
{ {
@@ -1882,7 +1981,8 @@ BTextView::LineWidth(int32 lineNum) const
else else
return (*fLines)[lineNum]->width; return (*fLines)[lineNum]->width;
} }
//------------------------------------------------------------------------------
float float
BTextView::LineHeight(int32 lineNum) const BTextView::LineHeight(int32 lineNum) const
{ {
@@ -1894,7 +1994,8 @@ BTextView::LineHeight(int32 lineNum) const
else else
return (*fLines)[lineNum]->ascent; return (*fLines)[lineNum]->ascent;
} }
//------------------------------------------------------------------------------
float float
BTextView::TextHeight(int32 startLine, int32 endLine) const BTextView::TextHeight(int32 startLine, int32 endLine) const
{ {
@@ -1911,7 +2012,8 @@ BTextView::TextHeight(int32 startLine, int32 endLine) const
return height; return height;
} }
//------------------------------------------------------------------------------
void void
BTextView::GetTextRegion(int32 startOffset, int32 endOffset, BTextView::GetTextRegion(int32 startOffset, int32 endOffset,
BRegion *outRegion) const BRegion *outRegion) const
@@ -1932,14 +2034,15 @@ BTextView::GetTextRegion(int32 startOffset, int32 endOffset,
if (startPt.y == endPt.y) { if (startPt.y == endPt.y) {
// this is a one-line region // this is a one-line region
selRect.left = (startPt.x < fTextRect.left) ? fTextRect.left : startPt.x; selRect.left = max_c(startPt.x, fTextRect.left);
selRect.top = startPt.y; selRect.top = startPt.y;
selRect.right = endPt.x - 1.0; selRect.right = endPt.x - 1.0;
selRect.bottom = endPt.y + endLineHeight - 1.0; selRect.bottom = endPt.y + endLineHeight - 1.0;
outRegion->Include(selRect); outRegion->Include(selRect);
} else { } else {
// more than one line in the specified offset range // more than one line in the specified offset range
selRect.left = (startPt.x < fTextRect.left) ? fTextRect.left : startPt.x; selRect.left = max_c(startPt.x, fTextRect.left);
selRect.top = startPt.y; selRect.top = startPt.y;
selRect.right = fTextRect.right; selRect.right = fTextRect.right;
selRect.bottom = startPt.y + startLineHeight - 1.0; selRect.bottom = startPt.y + startLineHeight - 1.0;
@@ -1988,7 +2091,12 @@ BTextView::ScrollToSelection()
CALLED(); CALLED();
ScrollToOffset(fSelStart); ScrollToOffset(fSelStart);
} }
//------------------------------------------------------------------------------
/*! \brief Highlight the text comprised between the given offset.
\param startOffset The offset of the text to highlight.
\param endOffset The offset where the text to highlight ends.
*/
void void
BTextView::Highlight(int32 startOffset, int32 endOffset) BTextView::Highlight(int32 startOffset, int32 endOffset)
{ {
@@ -2031,7 +2139,12 @@ BTextView::SetStylable(bool stylable)
CALLED(); CALLED();
fStylable = stylable; fStylable = stylable;
} }
//------------------------------------------------------------------------------
/*! \brief Tells if the object is stylable.
\return true if the object is stylable, false otherwise.
If the object is stylable, it can show multiple fonts at the same time.
*/
bool bool
BTextView::IsStylable() const BTextView::IsStylable() const
{ {
@@ -2051,14 +2164,23 @@ BTextView::SetTabWidth(float width)
if (Window() != NULL) if (Window() != NULL)
Refresh(0, fLines->NumLines(), true, false); Refresh(0, fLines->NumLines(), true, false);
} }
//------------------------------------------------------------------------------
/*! \brief Returns the BTextView's tab width.
\return The BTextView's tab width.
*/
float float
BTextView::TabWidth() const BTextView::TabWidth() const
{ {
CALLED(); CALLED();
return fTabWidth; return fTabWidth;
} }
//------------------------------------------------------------------------------
/*! \brief Makes the object selectable, or not selectable.
\param selectable If true, the object will be selectable from now on.
if false, it won't be selectable anymore.
*/
void void
BTextView::MakeSelectable(bool selectable) BTextView::MakeSelectable(bool selectable)
{ {
@@ -2078,14 +2200,24 @@ BTextView::MakeSelectable(bool selectable)
} }
} }
} }
//------------------------------------------------------------------------------
/*! \brief Tells if the object is selectable
\return \c true if the object is selectable,
\c false if not.
*/
bool bool
BTextView::IsSelectable() const BTextView::IsSelectable() const
{ {
CALLED(); CALLED();
return fSelectable; return fSelectable;
} }
//------------------------------------------------------------------------------
/*! \brief Set (or remove) the editable property for the object.
\param editable If true, will make the object editable,
if false, will make it not editable.
*/
void void
BTextView::MakeEditable(bool editable) BTextView::MakeEditable(bool editable)
{ {
@@ -2102,14 +2234,23 @@ BTextView::MakeEditable(bool editable)
} }
} }
} }
//------------------------------------------------------------------------------
/*! \brief Tells if the object is editable.
\return \c true if the object is editable,
\c false if not.
*/
bool bool
BTextView::IsEditable() const BTextView::IsEditable() const
{ {
CALLED(); CALLED();
return fEditable; return fEditable;
} }
//------------------------------------------------------------------------------
/*! \brief Set (or unset) word wrapping mode.
\param wrap Specifies if you want word wrapping active or not.
*/
void void
BTextView::SetWordWrap(bool wrap) BTextView::SetWordWrap(bool wrap)
{ {
@@ -2143,7 +2284,11 @@ BTextView::SetWordWrap(bool wrap)
} }
} }
} }
//------------------------------------------------------------------------------
/*! \brief Tells if word wrapping is activated.
\return true if word wrapping is active, false otherwise.
*/
bool bool
BTextView::DoesWordWrap() const BTextView::DoesWordWrap() const
{ {
@@ -2164,7 +2309,14 @@ BTextView::MaxBytes() const
CALLED(); CALLED();
return fMaxBytes; return fMaxBytes;
} }
//------------------------------------------------------------------------------
/*! \brief Adds the given char to the disallowed chars list.
\param aChar The charachter to add to the list.
After this function returns, the given charachter won't be accepted
by the textview anymore.
*/
void void
BTextView::DisallowChar(uint32 aChar) BTextView::DisallowChar(uint32 aChar)
{ {
@@ -2174,7 +2326,11 @@ BTextView::DisallowChar(uint32 aChar)
if (!fDisallowedChars->HasItem(reinterpret_cast<void *>(aChar))) if (!fDisallowedChars->HasItem(reinterpret_cast<void *>(aChar)))
fDisallowedChars->AddItem(reinterpret_cast<void *>(aChar)); fDisallowedChars->AddItem(reinterpret_cast<void *>(aChar));
} }
//------------------------------------------------------------------------------
/*! \brief Removes the given charachter from the disallowed list.
\param aChar The charachter to remove from the list.
*/
void void
BTextView::AllowChar(uint32 aChar) BTextView::AllowChar(uint32 aChar)
{ {
@@ -2221,7 +2377,11 @@ BTextView::DoesAutoindent() const
CALLED(); CALLED();
return fAutoindent; return fAutoindent;
} }
//------------------------------------------------------------------------------
/*! \brief Set the color space for the offscreen BBitmap.
\param colors The new colorspace for the offscreen BBitmap.
*/
void void
BTextView::SetColorSpace(color_space colors) BTextView::SetColorSpace(color_space colors)
{ {
@@ -2232,7 +2392,11 @@ BTextView::SetColorSpace(color_space colors)
NewOffscreen(); NewOffscreen();
} }
} }
//------------------------------------------------------------------------------
/*! \brief Returns the colorspace of the offscreen BBitmap, if any.
\return The colorspace of the BTextView's offscreen BBitmap.
*/
color_space color_space
BTextView::ColorSpace() const BTextView::ColorSpace() const
{ {
@@ -2540,7 +2704,13 @@ void BTextView::_ReservedTextView9() {}
void BTextView::_ReservedTextView10() {} void BTextView::_ReservedTextView10() {}
void BTextView::_ReservedTextView11() {} void BTextView::_ReservedTextView11() {}
void BTextView::_ReservedTextView12() {} void BTextView::_ReservedTextView12() {}
//------------------------------------------------------------------------------
/*! \brief Inits the BTextView object.
\param textRect The BTextView's text rect.
\param initialFont The font which the BTextView will use.
\param initialColor The initial color of the text.
*/
void void
BTextView::InitObject(BRect textRect, const BFont *initialFont, BTextView::InitObject(BRect textRect, const BFont *initialFont,
const rgb_color *initialColor) const rgb_color *initialColor)
@@ -2564,7 +2734,10 @@ BTextView::InitObject(BRect textRect, const BFont *initialFont,
fLines = new _BLineBuffer_; fLines = new _BLineBuffer_;
fStyles = new _BStyleBuffer_(&font, initialColor); fStyles = new _BStyleBuffer_(&font, initialColor);
} }
//------------------------------------------------------------------------------
/*! \brief Called when Backspace key is pressed.
*/
void void
BTextView::HandleBackspace() BTextView::HandleBackspace()
{ {
@@ -2591,7 +2764,11 @@ BTextView::HandleBackspace()
Refresh(fSelStart, fSelEnd, true, false); Refresh(fSelStart, fSelEnd, true, false);
} }
//------------------------------------------------------------------------------
/*! \brief Called when any arrow key is pressed.
\param inArrowKey The code for the pressed key.
*/
void void
BTextView::HandleArrowKey(uint32 inArrowKey) BTextView::HandleArrowKey(uint32 inArrowKey)
{ {
@@ -2668,7 +2845,10 @@ BTextView::HandleArrowKey(uint32 inArrowKey)
// scroll if needed // scroll if needed
ScrollToOffset(scrollToOffset); ScrollToOffset(scrollToOffset);
} }
//------------------------------------------------------------------------------
/*! \brief Called when the Delete key is pressed.
*/
void void
BTextView::HandleDelete() BTextView::HandleDelete()
{ {
@@ -2764,7 +2944,16 @@ BTextView::HandleAlphaKey(const char *bytes, int32 numBytes)
Refresh(fSelStart, fSelEnd, refresh, true); Refresh(fSelStart, fSelEnd, refresh, true);
} }
//------------------------------------------------------------------------------
/*! \brief Redraw the text comprised between the two given offsets,
recalculating linebreaks if needed.
\param fromOffset The offset from where to refresh.
\param toOffset The offset where to refresh to.
\param erase If true, the function will also erase the textview content
in the parts where text isn't present.
\param scroll If true, function will scroll the view to the end offset.
*/
void void
BTextView::Refresh(int32 fromOffset, int32 toOffset, bool erase, BTextView::Refresh(int32 fromOffset, int32 toOffset, bool erase,
bool scroll) bool scroll)
@@ -2799,8 +2988,8 @@ BTextView::Refresh(int32 fromOffset, int32 toOffset, bool erase,
// draw only those lines that are visible // draw only those lines that are visible
int32 fromVisible = LineAt(BPoint(0.0f, bounds.top)); int32 fromVisible = LineAt(BPoint(0.0f, bounds.top));
int32 toVisible = LineAt(BPoint(0.0f, bounds.bottom)); int32 toVisible = LineAt(BPoint(0.0f, bounds.bottom));
fromLine = (fromVisible > fromLine) ? fromVisible : fromLine; fromLine = max_c(fromVisible, fromLine);
toLine = (toLine > toVisible) ? toVisible : toLine; toLine = min_c(toLine, toVisible);
int32 drawOffset = fromOffset; int32 drawOffset = fromOffset;
if ( LineHeight(fromLine) != saveLineHeight || if ( LineHeight(fromLine) != saveLineHeight ||
@@ -2903,7 +3092,7 @@ BTextView::RecalLineBreaks(int32 *startLine, int32 *endLine)
fTextRect.bottom = fTextRect.top + newHeight; fTextRect.bottom = fTextRect.top + newHeight;
*endLine = lineIndex - 1; *endLine = lineIndex - 1;
*startLine = (*startLine > *endLine) ? *endLine : *startLine; *startLine = min_c(*startLine, *endLine);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int32 int32
@@ -2957,8 +3146,8 @@ BTextView::FindLineBreak(int32 fromOffset, float *outAscent,
int32 startOffset = fromOffset; int32 startOffset = fromOffset;
int32 numChars; int32 numChars;
while ((numChars = fStyles->Iterate(startOffset, length, NULL, NULL, &ascent, &descent)) != 0) { while ((numChars = fStyles->Iterate(startOffset, length, NULL, NULL, &ascent, &descent)) != 0) {
*outAscent = (ascent > *outAscent) ? ascent : *outAscent; *outAscent = max_c(ascent, *outAscent);
*outDescent = (descent > *outDescent) ? descent : *outDescent; *outDescent = max_c(descent, *outDescent);
startOffset += numChars; startOffset += numChars;
length -= numChars; length -= numChars;
@@ -3001,7 +3190,7 @@ BTextView::FindLineBreak(int32 fromOffset, float *outAscent,
} }
} }
} }
delta = (delta < 1) ? 1 : delta; delta = max_c(delta, 1);
deltaWidth = StyledWidth(offset, delta, &ascent, &descent); deltaWidth = StyledWidth(offset, delta, &ascent, &descent);
strWidth += deltaWidth; strWidth += deltaWidth;
@@ -3057,14 +3246,14 @@ BTextView::FindLineBreak(int32 fromOffset, float *outAscent,
StyledWidth(offset, delta, &ascent, &descent); StyledWidth(offset, delta, &ascent, &descent);
} }
*outAscent = (ascent > *outAscent) ? ascent : *outAscent; *outAscent = max_c(ascent, *outAscent);
*outDescent = (descent > *outDescent) ? descent : *outDescent; *outDescent = max_c(descent, *outDescent);
offset += delta; offset += delta;
delta = 0; delta = 0;
} while (offset < limit && !done); } while (offset < limit && !done);
if ((offset - fromOffset) < 1) { if (offset - fromOffset < 1) {
// there weren't any words that fit entirely in this line // there weren't any words that fit entirely in this line
// force a break in the middle of a word // force a break in the middle of a word
*outAscent = 0.0; *outAscent = 0.0;
@@ -3077,16 +3266,24 @@ BTextView::FindLineBreak(int32 fromOffset, float *outAscent,
if (strWidth >= *ioWidth) if (strWidth >= *ioWidth)
break; break;
*outAscent = (ascent > *outAscent) ? ascent : *outAscent; *outAscent = max_c(ascent, *outAscent);
*outDescent = (descent > *outDescent) ? descent : *outDescent; *outDescent = max_c(descent, *outDescent);
} }
} }
offset = (offset < limit) ? offset : limit; offset = min_c(offset, limit);
return offset; return offset;
} }
//------------------------------------------------------------------------------
/*! \brief Calculate the width of the text within the given limits.
\param fromOffset The offset where to start.
\param length The length of the text to examine.
\param outAscent A pointer to a float which will contain the maximum ascent.
\param outDescent A pointer to a float which will contain the maximum descent.
\return The width for the text within the given limits.
*/
float float
BTextView::StyledWidth(int32 fromOffset, int32 length, float *outAscent, BTextView::StyledWidth(int32 fromOffset, int32 length, float *outAscent,
float *outDescent) const float *outDescent) const
@@ -3102,11 +3299,13 @@ BTextView::StyledWidth(int32 fromOffset, int32 length, float *outAscent,
const BFont *font = NULL; const BFont *font = NULL;
int32 numChars; int32 numChars;
while ((numChars = fStyles->Iterate(fromOffset, length, &font, NULL, &ascent, &descent)) != 0) { while ((numChars = fStyles->Iterate(fromOffset, length, &font, NULL, &ascent, &descent)) != 0) {
maxAscent = (ascent > maxAscent) ? ascent : maxAscent; maxAscent = max_c(ascent, maxAscent);
maxDescent = (descent > maxDescent) ? descent : maxDescent; maxDescent = max_c(descent, maxDescent);
// TODO: Change this with a call to _BWidthBuffer_::StringWidth()
// as soon as everything else work
result += font->StringWidth(fText->Text() + fromOffset, numChars); result += font->StringWidth(fText->Text() + fromOffset, numChars);
fromOffset += numChars; fromOffset += numChars;
length -= numChars; length -= numChars;
} }
@@ -3118,7 +3317,12 @@ BTextView::StyledWidth(int32 fromOffset, int32 length, float *outAscent,
return result; return result;
} }
//------------------------------------------------------------------------------
/*! \brief Calculate the actual tab width for the given location.
\param location The location to calculate the tab width of.
\return The actual tab width for the given location
*/
float float
BTextView::ActualTabWidth(float location) const BTextView::ActualTabWidth(float location) const
{ {
@@ -3363,7 +3567,10 @@ BTextView::TrackDrag(BPoint where)
{ {
CALLED(); CALLED();
} }
//------------------------------------------------------------------------------
/*! \brief Function called to initiate a drag operation.
*/
void void
BTextView::InitiateDrag() BTextView::InitiateDrag()
{ {
@@ -3397,9 +3604,10 @@ BTextView::MessageDropped(BMessage *inMessage, BPoint where, BPoint offset)
CALLED(); CALLED();
void *from = NULL; void *from = NULL;
inMessage->FindPointer("be:originator", &from); bool internalDrop = false;
if (inMessage->FindPointer("be:originator", &from) == B_OK
bool internalDrop = (from == this && fSelEnd != fSelStart); && from == this && fSelEnd != fSelStart)
internalDrop = true;
if (fActive) if (fActive)
SetViewCursor(B_CURSOR_I_BEAM); SetViewCursor(B_CURSOR_I_BEAM);
@@ -3465,7 +3673,7 @@ BTextView::UpdateScrollbars()
dataWidth += (long)ceil(fTextRect.left) + 1; dataWidth += (long)ceil(fTextRect.left) + 1;
long maxRange = dataWidth - viewWidth; long maxRange = dataWidth - viewWidth;
maxRange = (maxRange < 0) ? 0 : maxRange; maxRange = max_c(maxRange, 0);
hsb->SetRange(0, (float)maxRange); hsb->SetRange(0, (float)maxRange);
hsb->SetProportion((float)viewWidth / (float)dataWidth); hsb->SetProportion((float)viewWidth / (float)dataWidth);
@@ -3479,7 +3687,7 @@ BTextView::UpdateScrollbars()
dataHeight += (long)ceil(fTextRect.top) + 1; dataHeight += (long)ceil(fTextRect.top) + 1;
long maxRange = dataHeight - viewHeight; long maxRange = dataHeight - viewHeight;
maxRange = (maxRange < 0) ? 0 : maxRange; maxRange = max_c(maxRange, 0);
vsb->SetRange(0, maxRange); vsb->SetRange(0, maxRange);
vsb->SetProportion((float)viewHeight / (float)dataHeight); vsb->SetProportion((float)viewHeight / (float)dataHeight);
@@ -3532,7 +3740,11 @@ BTextView::DeleteOffscreen()
fOffscreen = NULL; fOffscreen = NULL;
} }
} }
//------------------------------------------------------------------------------
/*! \brief Creates a new offscreen bitmap, highlight the selection, and set the
cursor to B_CURSOR_I_BEAM.
*/
void void
BTextView::Activate() BTextView::Activate()
{ {
@@ -3556,7 +3768,10 @@ BTextView::Activate()
if (Bounds().Contains(where)) if (Bounds().Contains(where))
SetViewCursor(B_CURSOR_I_BEAM); SetViewCursor(B_CURSOR_I_BEAM);
} }
//------------------------------------------------------------------------------
/*! \brief Unhilights the selection, set the cursor to B_CURSOR_SYSTEM_DEFAULT.
*/
void void
BTextView::Deactivate() BTextView::Deactivate()
{ {
@@ -3763,22 +3978,33 @@ BTextView::CountProperties(BMessage *specifier, int32 form,
} else } else
return false; return false;
} }
//------------------------------------------------------------------------------
/*! \brief Called when the object receives a B_INPUT_METHOD_CHANGE message.
*/
void void
BTextView::HandleInputMethodChanged(BMessage *message) BTextView::HandleInputMethodChanged(BMessage *message)
{ {
CALLED(); CALLED();
// TODO: Implement me
message->PrintToStream();
} }
//------------------------------------------------------------------------------
/*! \brief Called when the object receives a B_INPUT_METHOD_LOCATION_REQUEST message.
*/
void void
BTextView::HandleInputMethodLocationRequest() BTextView::HandleInputMethodLocationRequest()
{ {
// TODO: Implement me
CALLED(); CALLED();
} }
//------------------------------------------------------------------------------
void void
BTextView::CancelInputMethod() BTextView::CancelInputMethod()
{ {
// TODO: Implement me
CALLED(); CALLED();
} }