2 * Copyright 2003-2006, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Stefano Ceccherini (burton666@libero.it)
9 // For a deeper understanding of this class, see the BeBook, sez.
10 // "The Input Server".
11 // TODO: the bebook says we should highlight in blue/red different "clauses".
12 // Though it looks like what really matters is the "selection" field in
13 // the BMessage sent by the input method addon. Have I missed something ?
15 #include "InlineInput.h"
26 /*! \brief Constructs a InlineInput object.
27 \param messenger The BMessenger of the input server method addon.
29 BTextView::InlineInput::InlineInput(BMessenger messenger
)
31 fMessenger(messenger
),
43 /*! \brief Destructs the object, free the allocated memory.
45 BTextView::InlineInput::~InlineInput()
51 /*! \brief Returns a pointer to the Input Server Method BMessenger
52 which requested the transaction.
55 BTextView::InlineInput::Method() const
62 BTextView::InlineInput::IsActive() const
69 BTextView::InlineInput::SetActive(bool active
)
75 /*! \brief Return the length of the inputted text.
78 BTextView::InlineInput::Length() const
84 /*! \brief Sets the length of the text inputted with the input method.
85 \param len The length of the text, extracted from the
86 B_INPUT_METHOD_CHANGED BMessage.
89 BTextView::InlineInput::SetLength(int32 len
)
95 /*! \brief Returns the offset into the BTextView of the text.
98 BTextView::InlineInput::Offset() const
104 /*! \brief Sets the offset into the BTextView of the text.
105 \param offset The offset where the text has been inserted.
108 BTextView::InlineInput::SetOffset(int32 offset
)
114 /*! \brief Returns the length of the selection, if any.
117 BTextView::InlineInput::SelectionLength() const
119 return fSelectionLength
;
123 /*! \brief Sets the length of the selection.
124 \param length The length of the selection.
127 BTextView::InlineInput::SetSelectionLength(int32 length
)
129 fSelectionLength
= length
;
133 /*! \brief Returns the offset into the method string of the selection.
136 BTextView::InlineInput::SelectionOffset() const
138 return fSelectionOffset
;
142 /*! \brief Sets the offset into the method string of the selection.
143 \param offset The offset where the selection starts.
146 BTextView::InlineInput::SetSelectionOffset(int32 offset
)
148 fSelectionOffset
= offset
;
152 /*! \brief Adds a clause (see "The Input Server" sez. for details).
153 \param start The offset into the string where the clause starts.
154 \param end The offset into the string where the clause finishes.
157 BTextView::InlineInput::AddClause(int32 start
, int32 end
)
159 void *newData
= realloc(fClauses
, (fNumClauses
+ 1) * sizeof(clause
));
163 fClauses
= (clause
*)newData
;
164 fClauses
[fNumClauses
].start
= start
;
165 fClauses
[fNumClauses
].end
= end
;
171 /*! \brief Gets the clause at the given index.
172 \param index The index of the clause to get.
173 \param start A pointer to an integer which will contain the clause's start offset.
174 \param end A pointer to an integer which will contain the clause's end offset.
175 \return \c true if the clause exists, \c false if not.
178 BTextView::InlineInput::GetClause(int32 index
, int32
*start
, int32
*end
) const
181 if (index
>= 0 && index
< fNumClauses
) {
183 clause
*clause
= &fClauses
[index
];
185 *start
= clause
->start
;
195 BTextView::InlineInput::CountClauses() const
201 /*! \brief Deletes any added clause.
204 BTextView::InlineInput::ResetClauses()