* Copyright 2003-2006, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stefano Ceccherini (burton666@libero.it)
*/
#include "InlineInput.h"
#include <cstdlib>
struct clause
{
int32 start;
int32 end;
};
\param messenger The BMessenger of the input server method addon.
*/
BTextView::InlineInput::InlineInput(BMessenger messenger)
:
fMessenger(messenger),
fActive(false),
fOffset(0),
fLength(0),
fSelectionOffset(0),
fSelectionLength(0),
fNumClauses(0),
fClauses(NULL)
{
}
*/
BTextView::InlineInput::~InlineInput()
{
ResetClauses();
}
which requested the transaction.
*/
const BMessenger *
BTextView::InlineInput::Method() const
{
return &fMessenger;
}
bool
BTextView::InlineInput::IsActive() const
{
return fActive;
}
void
BTextView::InlineInput::SetActive(bool active)
{
fActive = active;
}
*/
int32
BTextView::InlineInput::Length() const
{
return fLength;
}
\param len The length of the text, extracted from the
B_INPUT_METHOD_CHANGED BMessage.
*/
void
BTextView::InlineInput::SetLength(int32 len)
{
fLength = len;
}
*/
int32
BTextView::InlineInput::Offset() const
{
return fOffset;
}
\param offset The offset where the text has been inserted.
*/
void
BTextView::InlineInput::SetOffset(int32 offset)
{
fOffset = offset;
}
*/
int32
BTextView::InlineInput::SelectionLength() const
{
return fSelectionLength;
}
\param length The length of the selection.
*/
void
BTextView::InlineInput::SetSelectionLength(int32 length)
{
fSelectionLength = length;
}
*/
int32
BTextView::InlineInput::SelectionOffset() const
{
return fSelectionOffset;
}
\param offset The offset where the selection starts.
*/
void
BTextView::InlineInput::SetSelectionOffset(int32 offset)
{
fSelectionOffset = offset;
}
\param start The offset into the string where the clause starts.
\param end The offset into the string where the clause finishes.
*/
bool
BTextView::InlineInput::AddClause(int32 start, int32 end)
{
void *newData = realloc(fClauses, (fNumClauses + 1) * sizeof(clause));
if (newData == NULL)
return false;
fClauses = (clause *)newData;
fClauses[fNumClauses].start = start;
fClauses[fNumClauses].end = end;
fNumClauses++;
return true;
}
\param index The index of the clause to get.
\param start A pointer to an integer which will contain the clause's start offset.
\param end A pointer to an integer which will contain the clause's end offset.
\return \c true if the clause exists, \c false if not.
*/
bool
BTextView::InlineInput::GetClause(int32 index, int32 *start, int32 *end) const
{
bool result = false;
if (index >= 0 && index < fNumClauses) {
result = true;
clause *clause = &fClauses[index];
if (start)
*start = clause->start;
if (end)
*end = clause->end;
}
return result;
}
int32
BTextView::InlineInput::CountClauses() const
{
return fNumClauses;
}
*/
void
BTextView::InlineInput::ResetClauses()
{
fNumClauses = 0;
free(fClauses);
fClauses = NULL;
}