Menu

[r1152]: / trunk / ext / scintilla / src / Selection.h  Maximize  Restore  History

Download this file

197 lines (186 with data), 5.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// Scintilla source code edit control
/** @file Selection.h
** Classes maintaining the selection.
**/
// Copyright 2009 by Neil Hodgson <neilh@scintilla.org>
// The License.txt file describes the conditions under which this software may be distributed.
#ifndef SELECTION_H
#define SELECTION_H
#ifdef SCI_NAMESPACE
namespace Scintilla {
#endif
class SelectionPosition {
Sci::Position position;
Sci::Position virtualSpace;
public:
explicit SelectionPosition(Sci::Position position_=INVALID_POSITION, Sci::Position virtualSpace_=0) : position(position_), virtualSpace(virtualSpace_) {
PLATFORM_ASSERT(virtualSpace < 800000);
if (virtualSpace < 0)
virtualSpace = 0;
}
void Reset() {
position = 0;
virtualSpace = 0;
}
void MoveForInsertDelete(bool insertion, Sci::Position startChange, Sci::Position length);
bool operator ==(const SelectionPosition &other) const {
return position == other.position && virtualSpace == other.virtualSpace;
}
bool operator <(const SelectionPosition &other) const;
bool operator >(const SelectionPosition &other) const;
bool operator <=(const SelectionPosition &other) const;
bool operator >=(const SelectionPosition &other) const;
Sci::Position Position() const {
return position;
}
void SetPosition(Sci::Position position_) {
position = position_;
virtualSpace = 0;
}
Sci::Position VirtualSpace() const {
return virtualSpace;
}
void SetVirtualSpace(Sci::Position virtualSpace_) {
PLATFORM_ASSERT(virtualSpace_ < 800000);
if (virtualSpace_ >= 0)
virtualSpace = virtualSpace_;
}
void Add(Sci::Position increment) {
position = position + increment;
}
bool IsValid() const {
return position >= 0;
}
};
// Ordered range to make drawing simpler
struct SelectionSegment {
SelectionPosition start;
SelectionPosition end;
SelectionSegment() : start(), end() {
}
SelectionSegment(SelectionPosition a, SelectionPosition b) {
if (a < b) {
start = a;
end = b;
} else {
start = b;
end = a;
}
}
bool Empty() const {
return start == end;
}
void Extend(SelectionPosition p) {
if (start > p)
start = p;
if (end < p)
end = p;
}
};
struct SelectionRange {
SelectionPosition caret;
SelectionPosition anchor;
SelectionRange() : caret(), anchor() {
}
explicit SelectionRange(SelectionPosition single) : caret(single), anchor(single) {
}
explicit SelectionRange(Sci::Position single) : caret(single), anchor(single) {
}
SelectionRange(SelectionPosition caret_, SelectionPosition anchor_) : caret(caret_), anchor(anchor_) {
}
SelectionRange(Sci::Position caret_, Sci::Position anchor_) : caret(caret_), anchor(anchor_) {
}
bool Empty() const {
return anchor == caret;
}
Sci::Position Length() const;
// Sci::Position Width() const; // Like Length but takes virtual space into account
bool operator ==(const SelectionRange &other) const {
return caret == other.caret && anchor == other.anchor;
}
bool operator <(const SelectionRange &other) const {
return caret < other.caret || ((caret == other.caret) && (anchor < other.anchor));
}
void Reset() {
anchor.Reset();
caret.Reset();
}
void ClearVirtualSpace() {
anchor.SetVirtualSpace(0);
caret.SetVirtualSpace(0);
}
void MoveForInsertDelete(bool insertion, Sci::Position startChange, Sci::Position length);
bool Contains(Sci::Position pos) const;
bool Contains(SelectionPosition sp) const;
bool ContainsCharacter(Sci::Position posCharacter) const;
SelectionSegment Intersect(SelectionSegment check) const;
SelectionPosition Start() const {
return (anchor < caret) ? anchor : caret;
}
SelectionPosition End() const {
return (anchor < caret) ? caret : anchor;
}
void Swap();
bool Trim(SelectionRange range);
// If range is all virtual collapse to start of virtual space
void MinimizeVirtualSpace();
};
class Selection {
std::vector<SelectionRange> ranges;
std::vector<SelectionRange> rangesSaved;
SelectionRange rangeRectangular;
size_t mainRange;
bool moveExtends;
bool tentativeMain;
public:
enum selTypes { noSel, selStream, selRectangle, selLines, selThin };
selTypes selType;
Selection();
~Selection();
bool IsRectangular() const;
Sci::Position MainCaret() const;
Sci::Position MainAnchor() const;
SelectionRange &Rectangular();
SelectionSegment Limits() const;
// This is for when you want to move the caret in response to a
// user direction command - for rectangular selections, use the range
// that covers all selected text otherwise return the main selection.
SelectionSegment LimitsForRectangularElseMain() const;
size_t Count() const;
size_t Main() const;
void SetMain(size_t r);
SelectionRange &Range(size_t r);
const SelectionRange &Range(size_t r) const;
SelectionRange &RangeMain();
const SelectionRange &RangeMain() const;
SelectionPosition Start() const;
bool MoveExtends() const;
void SetMoveExtends(bool moveExtends_);
bool Empty() const;
SelectionPosition Last() const;
Sci::Position Length() const;
void MovePositions(bool insertion, Sci::Position startChange, Sci::Position length);
void TrimSelection(SelectionRange range);
void TrimOtherSelections(size_t r, SelectionRange range);
void SetSelection(SelectionRange range);
void AddSelection(SelectionRange range);
void AddSelectionWithoutTrim(SelectionRange range);
void DropSelection(size_t r);
void DropAdditionalRanges();
void TentativeSelection(SelectionRange range);
void CommitTentative();
int CharacterInSelection(Sci::Position posCharacter) const;
int InSelectionForEOL(Sci::Position pos) const;
Sci::Position VirtualSpaceFor(Sci::Position pos) const;
void Clear();
void RemoveDuplicates();
void RotateMain();
bool Tentative() const { return tentativeMain; }
std::vector<SelectionRange> RangesCopy() const {
return ranges;
}
};
#ifdef SCI_NAMESPACE
}
#endif
#endif
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.