[UPDATE] commit forgotten files.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@526 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
Don Ho 2009-08-23 20:43:22 +00:00
parent c84437b0d1
commit d37b20de07
3 changed files with 554 additions and 0 deletions

View File

@ -0,0 +1,33 @@
// Scintilla source code edit control
/** @file PropSetSimple.h
** A basic string to string map.
**/
// Copyright 1998-2009 by Neil Hodgson <neilh@scintilla.org>
// 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

345
scintilla/src/Selection.cxx Normal file
View File

@ -0,0 +1,345 @@
// Scintilla source code edit control
/** @file Selection.cxx
** 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.
#include <stdlib.h>
#include <vector>
#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.size(); i++) {
if (!ranges[i].Empty())
return false;
}
return true;
}
SelectionPosition Selection::Last() const {
SelectionPosition lastPosition;
for (size_t i=0; i<ranges.size(); i++) {
if (lastPosition < ranges[i].caret)
lastPosition = ranges[i].caret;
if (lastPosition < ranges[i].anchor)
lastPosition = ranges[i].anchor;
}
return lastPosition;
}
int Selection::Length() const {
int len = 0;
for (size_t i=0; i<ranges.size(); i++) {
len += ranges[i].Length();
}
return len;
}
void Selection::MovePositions(bool insertion, int startChange, int length) {
for (size_t i=0; i<ranges.size(); i++) {
ranges[i].caret.MoveForInsertDelete(insertion, startChange, length);
ranges[i].anchor.MoveForInsertDelete(insertion, startChange, length);
}
}
void Selection::TrimSelection(SelectionRange range) {
for (size_t i=0; i<ranges.size();) {
if ((i != mainRange) && (ranges[i].Trim(range))) {
// Trimmed to empty so remove
for (size_t j=i;j<ranges.size()-1;j++) {
ranges[j] = ranges[j+1];
if (j == mainRange-1)
mainRange--;
}
ranges.pop_back();
} else {
i++;
}
}
}
void Selection::SetSelection(SelectionRange range) {
ranges.clear();
ranges.push_back(range);
mainRange = ranges.size() - 1;
}
void Selection::AddSelection(SelectionRange range) {
TrimSelection(range);
ranges.push_back(range);
mainRange = ranges.size() - 1;
}
void Selection::TentativeSelection(SelectionRange range) {
if (!tentativeMain) {
rangesSaved = ranges;
}
ranges = rangesSaved;
AddSelection(range);
TrimSelection(ranges[mainRange]);
tentativeMain = true;
}
void Selection::CommitTentative() {
rangesSaved.clear();
tentativeMain = false;
}
int Selection::CharacterInSelection(int posCharacter) const {
for (size_t i=0; i<ranges.size(); i++) {
if (ranges[i].ContainsCharacter(posCharacter))
return i == mainRange ? 1 : 2;
}
return 0;
}
int Selection::InSelectionForEOL(int pos) const {
for (size_t i=0; i<ranges.size(); i++) {
if (!ranges[i].Empty() && (pos > 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<ranges.size(); i++) {
if ((ranges[i].caret.Position() == pos) && (virtualSpace < ranges[i].caret.VirtualSpace()))
virtualSpace = ranges[i].caret.VirtualSpace();
if ((ranges[i].anchor.Position() == pos) && (virtualSpace < ranges[i].anchor.VirtualSpace()))
virtualSpace = ranges[i].anchor.VirtualSpace();
}
return virtualSpace;
}
void Selection::Clear() {
ranges.clear();
ranges.push_back(SelectionRange());
mainRange = ranges.size() - 1;
selType = selStream;
moveExtends = false;
ranges[mainRange].Reset();
rangeRectangular.Reset();
}
void Selection::RemoveDuplicates() {
for (size_t i=0; i<ranges.size()-1; i++) {
if (ranges[i].Empty()) {
size_t j=i+1;
while (j<ranges.size()) {
if (ranges[i] == ranges[j]) {
ranges.erase(ranges.begin() + j);
if (mainRange >= j)
mainRange--;
} else {
j++;
}
}
}
}
}
void Selection::RotateMain() {
mainRange = (mainRange + 1) % ranges.size();
}

176
scintilla/src/Selection.h Normal file
View File

@ -0,0 +1,176 @@
// 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 {
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<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;
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<SelectionRange> RangesCopy() const {
return ranges;
}
};
#ifdef SCI_NAMESPACE
}
#endif
#endif