HaikuDepot: notify work status from main window
[haiku.git] / src / apps / terminal / InlineInput.cpp
blob28d0f992ab5a1c7ef84cb6e3a101ab4c3b8285bc
1 /*
2 * Copyright 2003-2009, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Stefano Ceccherini (stefano.ceccherini@gmail.com)
7 */
9 #include "InlineInput.h"
11 #include <cstdlib>
13 struct clause
15 int32 start;
16 int32 end;
20 InlineInput::InlineInput(BMessenger messenger)
22 fMessenger(messenger),
23 fActive(false),
24 fSelectionOffset(0),
25 fSelectionLength(0),
26 fNumClauses(0),
27 fClauses(NULL)
32 InlineInput::~InlineInput()
34 ResetClauses();
38 const BMessenger *
39 InlineInput::Method() const
41 return &fMessenger;
45 const char *
46 InlineInput::String() const
48 return fString.String();
52 void
53 InlineInput::SetString(const char *string)
55 fString = string;
59 bool
60 InlineInput::IsActive() const
62 return fActive;
66 void
67 InlineInput::SetActive(bool active)
69 fActive = active;
73 int32
74 InlineInput::SelectionLength() const
76 return fSelectionLength;
80 void
81 InlineInput::SetSelectionLength(int32 length)
83 fSelectionLength = length;
87 int32
88 InlineInput::SelectionOffset() const
90 return fSelectionOffset;
94 void
95 InlineInput::SetSelectionOffset(int32 offset)
97 fSelectionOffset = offset;
101 bool
102 InlineInput::AddClause(int32 start, int32 end)
104 void *newData = realloc(fClauses, (fNumClauses + 1) * sizeof(clause));
105 if (newData == NULL)
106 return false;
108 fClauses = (clause *)newData;
109 fClauses[fNumClauses].start = start;
110 fClauses[fNumClauses].end = end;
111 fNumClauses++;
112 return true;
116 bool
117 InlineInput::GetClause(int32 index, int32 *start, int32 *end) const
119 bool result = false;
120 if (index >= 0 && index < fNumClauses) {
121 result = true;
122 clause *clause = &fClauses[index];
123 if (start)
124 *start = clause->start;
125 if (end)
126 *end = clause->end;
129 return result;
133 int32
134 InlineInput::CountClauses() const
136 return fNumClauses;
140 void
141 InlineInput::ResetClauses()
143 fNumClauses = 0;
144 free(fClauses);
145 fClauses = NULL;