diff --git a/scintilla/src/PropSetSimple.h b/scintilla/src/PropSetSimple.h new file mode 100644 index 00000000..057e7e66 --- /dev/null +++ b/scintilla/src/PropSetSimple.h @@ -0,0 +1,33 @@ +// Scintilla source code edit control +/** @file PropSetSimple.h + ** A basic string to string map. + **/ +// Copyright 1998-2009 by Neil Hodgson +// The License.txt file describes the conditions under which this software may be distributed. + +#ifndef PROPSETSIMPLE_H +#define PROPSETSIMPLE_H + +#ifdef SCI_NAMESPACE +namespace Scintilla { +#endif + +class PropSetSimple : public PropertyGet { + void *impl; + void Set(const char *keyVal); +public: + PropSetSimple(); + virtual ~PropSetSimple(); + void Set(const char *key, const char *val, int lenKey=-1, int lenVal=-1); + void SetMultiple(const char *); + const char *Get(const char *key) const; + char *Expanded(const char *key) const; + char *ToString() const; + int GetInt(const char *key, int defaultValue=0) const; +}; + +#ifdef SCI_NAMESPACE +} +#endif + +#endif diff --git a/scintilla/src/Selection.cxx b/scintilla/src/Selection.cxx new file mode 100644 index 00000000..667940a6 --- /dev/null +++ b/scintilla/src/Selection.cxx @@ -0,0 +1,345 @@ +// Scintilla source code edit control +/** @file Selection.cxx + ** Classes maintaining the selection. + **/ +// Copyright 2009 by Neil Hodgson +// The License.txt file describes the conditions under which this software may be distributed. + +#include + +#include + +#include "Platform.h" + +#include "Scintilla.h" + +#include "Selection.h" + +#ifdef SCI_NAMESPACE +using namespace Scintilla; +#endif + +void SelectionPosition::MoveForInsertDelete(bool insertion, int startChange, int length) { + if (insertion) { + if (position > startChange) { + position += length; + } + } else { + if (position > startChange) { + int endDeletion = startChange + length; + if (position > endDeletion) { + position -= length; + } else { + position = startChange; + } + } + } +} + +bool SelectionPosition::operator <(const SelectionPosition &other) const { + if (position == other.position) + return virtualSpace < other.virtualSpace; + else + return position < other.position; +} + +bool SelectionPosition::operator >(const SelectionPosition &other) const { + if (position == other.position) + return virtualSpace > other.virtualSpace; + else + return position > other.position; +} + +bool SelectionPosition::operator <=(const SelectionPosition &other) const { + if (position == other.position && virtualSpace == other.virtualSpace) + return true; + else + return other > *this; +} + +bool SelectionPosition::operator >=(const SelectionPosition &other) const { + if (position == other.position && virtualSpace == other.virtualSpace) + return true; + else + return *this > other; +} + +int SelectionRange::Length() const { + if (anchor > caret) { + return anchor.Position() - caret.Position(); + } else { + return caret.Position() - anchor.Position(); + } +} + +bool SelectionRange::Contains(int pos) const { + if (anchor > caret) + return (pos >= caret.Position()) && (pos <= anchor.Position()); + else + return (pos >= anchor.Position()) && (pos <= caret.Position()); +} + +bool SelectionRange::Contains(SelectionPosition sp) const { + if (anchor > caret) + return (sp >= caret) && (sp <= anchor); + else + return (sp >= anchor) && (sp <= caret); +} + +bool SelectionRange::ContainsCharacter(int posCharacter) const { + if (anchor > caret) + return (posCharacter >= caret.Position()) && (posCharacter < anchor.Position()); + else + return (posCharacter >= anchor.Position()) && (posCharacter < caret.Position()); +} + +SelectionSegment SelectionRange::Intersect(SelectionSegment check) const { + SelectionSegment inOrder(caret, anchor); + if ((inOrder.start <= check.end) || (inOrder.end >= check.start)) { + SelectionSegment portion = check; + if (portion.start < inOrder.start) + portion.start = inOrder.start; + if (portion.end > inOrder.end) + portion.end = inOrder.end; + if (portion.start > portion.end) + return SelectionSegment(); + else + return portion; + } else { + return SelectionSegment(); + } +} + +bool SelectionRange::Trim(SelectionRange range) { + SelectionPosition startRange = range.Start(); + SelectionPosition endRange = range.End(); + SelectionPosition start = Start(); + SelectionPosition end = End(); + PLATFORM_ASSERT(start <= end); + PLATFORM_ASSERT(startRange <= endRange); + if ((startRange <= end) && (endRange >= start)) { + if ((start > startRange) && (end < endRange)) { + // Completely covered by range -> empty at start + end = start; + } else if ((start < startRange) && (end > endRange)) { + // Completely covers range -> empty at start + end = start; + } else if (start <= startRange) { + // Trim end + end = startRange; + } else { // + PLATFORM_ASSERT(end >= endRange); + // Trim start + start = endRange; + } + if (anchor > caret) { + caret = start; + anchor = end; + } else { + anchor = start; + caret = end; + } + return Empty(); + } else { + return false; + } +} + +// If range is all virtual collapse to start of virtual space +void SelectionRange::MinimizeVirtualSpace() { + if (caret.Position() == anchor.Position()) { + int virtualSpace = caret.VirtualSpace(); + if (virtualSpace > anchor.VirtualSpace()) + virtualSpace = anchor.VirtualSpace(); + caret.SetVirtualSpace(virtualSpace); + anchor.SetVirtualSpace(virtualSpace); + } +} + +Selection::Selection() : mainRange(0), moveExtends(false), tentativeMain(false), selType(selStream) { + AddSelection(SelectionPosition(0)); +} + +Selection::~Selection() { +} + +bool Selection::IsRectangular() const { + return (selType == selRectangle) || (selType == selThin); +} + +int Selection::MainCaret() const { + return ranges[mainRange].caret.Position(); +} + +int Selection::MainAnchor() const { + return ranges[mainRange].anchor.Position(); +} + +SelectionRange &Selection::Rectangular() { + return rangeRectangular; +} + +size_t Selection::Count() const { + return ranges.size(); +} + +size_t Selection::Main() const { + return mainRange; +} + +void Selection::SetMain(size_t r) { + PLATFORM_ASSERT(r < ranges.size()); + mainRange = r; +} + +SelectionRange &Selection::Range(size_t r) { + return ranges[r]; +} + +SelectionRange &Selection::RangeMain() { + return ranges[mainRange]; +} + +bool Selection::MoveExtends() const { + return moveExtends; +} + +void Selection::SetMoveExtends(bool moveExtends_) { + moveExtends = moveExtends_; +} + +bool Selection::Empty() const { + for (size_t i=0; i ranges[i].Start().Position()) && (pos <= ranges[i].End().Position())) + return i == mainRange ? 1 : 2; + } + return 0; +} + +int Selection::VirtualSpaceFor(int pos) const { + int virtualSpace = 0; + for (size_t i=0; i= j) + mainRange--; + } else { + j++; + } + } + } + } +} + +void Selection::RotateMain() { + mainRange = (mainRange + 1) % ranges.size(); +} + diff --git a/scintilla/src/Selection.h b/scintilla/src/Selection.h new file mode 100644 index 00000000..67f9eb32 --- /dev/null +++ b/scintilla/src/Selection.h @@ -0,0 +1,176 @@ +// Scintilla source code edit control +/** @file Selection.h + ** Classes maintaining the selection. + **/ +// Copyright 2009 by Neil Hodgson +// 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 { + int position; + int virtualSpace; +public: + explicit SelectionPosition(int position_=INVALID_POSITION, int 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, int startChange, int 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; + int Position() const { + return position; + } + void SetPosition(int position_) { + position = position_; + virtualSpace = 0; + } + int VirtualSpace() const { + return virtualSpace; + } + void SetVirtualSpace(int virtualSpace_) { + PLATFORM_ASSERT(virtualSpace_ < 800000); + if (virtualSpace_ >= 0) + virtualSpace = virtualSpace_; + } + void Add(int increment) { + position = position + increment; + } + bool IsValid() const { + return position >= 0; + } +}; + +// Ordered range to make drawing simpler +struct SelectionSegment { + SelectionPosition start; + SelectionPosition end; + SelectionSegment() { + } + SelectionSegment(SelectionPosition a, SelectionPosition b) { + if (a < b) { + start = a; + end = b; + } else { + start = b; + end = a; + } + } + bool Empty() const { + return start == end; + } +}; + +struct SelectionRange { + SelectionPosition caret; + SelectionPosition anchor; + + SelectionRange() { + } + SelectionRange(SelectionPosition single) : caret(single), anchor(single) { + } + SelectionRange(int single) : caret(single), anchor(single) { + } + SelectionRange(SelectionPosition caret_, SelectionPosition anchor_) : caret(caret_), anchor(anchor_) { + } + SelectionRange(int caret_, int anchor_) : caret(caret_), anchor(anchor_) { + } + bool Empty() const { + return anchor == caret; + } + int Length() const; + // int 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); + } + bool Contains(int pos) const; + bool Contains(SelectionPosition sp) const; + bool ContainsCharacter(int posCharacter) const; + SelectionSegment Intersect(SelectionSegment check) const; + SelectionPosition Start() const { + return (anchor < caret) ? anchor : caret; + } + SelectionPosition End() const { + return (anchor < caret) ? caret : anchor; + } + bool Trim(SelectionRange range); + // If range is all virtual collapse to start of virtual space + void MinimizeVirtualSpace(); +}; + +class Selection { + std::vector ranges; + std::vector 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; + int MainCaret() const; + int MainAnchor() const; + SelectionRange &Rectangular(); + size_t Count() const; + size_t Main() const; + void SetMain(size_t r); + SelectionRange &Range(size_t r); + SelectionRange &RangeMain(); + bool MoveExtends() const; + void SetMoveExtends(bool moveExtends_); + bool Empty() const; + SelectionPosition Last() const; + int Length() const; + void MovePositions(bool insertion, int startChange, int length); + void TrimSelection(SelectionRange range); + void SetSelection(SelectionRange range); + void AddSelection(SelectionRange range); + void TentativeSelection(SelectionRange range); + void CommitTentative(); + int CharacterInSelection(int posCharacter) const; + int InSelectionForEOL(int pos) const; + int VirtualSpaceFor(int pos) const; + void Clear(); + void RemoveDuplicates(); + void RotateMain(); + bool Tentative() const { return tentativeMain; } + std::vector RangesCopy() const { + return ranges; + } +}; + +#ifdef SCI_NAMESPACE +} +#endif + +#endif