diff options
author | nyamatongwe <unknown> | 2009-07-14 03:28:22 +0000 |
---|---|---|
committer | nyamatongwe <unknown> | 2009-07-14 03:28:22 +0000 |
commit | 03cca7be7b6f7e1a2899c01bf50a7a61f9be1a21 (patch) | |
tree | 084abdf19b98d1571d40853b503bd05b723c243e | |
parent | 1231cf6c2eecdf6fdaba67c13d82a7cfb251ccbb (diff) | |
download | scintilla-mirror-03cca7be7b6f7e1a2899c01bf50a7a61f9be1a21.tar.gz |
Added controls for enabling multiple selection and multiple selection
typing. Renamed multiline options to reflect use on multiple selections.
Using std::vector for selections.
-rw-r--r-- | include/Scintilla.h | 10 | ||||
-rw-r--r-- | include/Scintilla.iface | 22 | ||||
-rw-r--r-- | src/Editor.cxx | 55 | ||||
-rw-r--r-- | src/Editor.h | 6 | ||||
-rw-r--r-- | src/PositionCache.cxx | 2 | ||||
-rw-r--r-- | src/ScintillaBase.cxx | 2 | ||||
-rw-r--r-- | src/Selection.cxx | 53 | ||||
-rw-r--r-- | src/Selection.h | 9 | ||||
-rw-r--r-- | win32/ScintillaWin.cxx | 2 |
9 files changed, 93 insertions, 68 deletions
diff --git a/include/Scintilla.h b/include/Scintilla.h index 877caa712..5986715a5 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -714,10 +714,12 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCI_ADDUNDOACTION 2560 #define SCI_CHARPOSITIONFROMPOINT 2561 #define SCI_CHARPOSITIONFROMPOINTCLOSE 2562 -#define SCI_SETMULTILINECARET 2563 -#define SCI_GETMULTILINECARET 2564 -#define SCI_SETMULTILINECARETBLINKS 2565 -#define SCI_GETMULTILINECARETBLINKS 2566 +#define SCI_SETMULTIPLESELECTION 2563 +#define SCI_GETMULTIPLESELECTION 2564 +#define SCI_SETADDITIONALSELECTIONTYPING 2565 +#define SCI_GETADDITIONALSELECTIONTYPING 2566 +#define SCI_SETADDITIONALCARETSBLINK 2567 +#define SCI_GETADDITIONALCARETSBLINK 2568 #define SCI_GETSELECTIONS 2570 #define SCI_CLEARSELECTIONS 2571 #define SCI_SETSELECTION 2572 diff --git a/include/Scintilla.iface b/include/Scintilla.iface index d17de8018..a4b16beea 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -1927,17 +1927,23 @@ fun position CharPositionFromPoint=2561(int x, int y) # Return INVALID_POSITION if not close to text. fun position CharPositionFromPointClose=2562(int x, int y) -# Set whether the caret will show on multiple lines for a rectangular selection -set void SetMultiLineCaret=2563(bool multiLine,) +# Set whether multiple selections can be made +set void SetMultipleSelection=2563(bool multipleSelection,) -# Whether the caret will show on multiple lines for a rectangular selection -get bool GetMultiLineCaret=2564(,) +# Whether multiple selections can be made +get bool GetMultipleSelection=2564(,) -# Set whether the multiline caret will blink -set void SetMultiLineCaretBlinks=2565(bool multiLineBlinks,) +# Set whether typing can be performed into multiple selections +set void SetAdditionalSelectionTyping=2565(bool additionalSelectionTyping,) -# Whether the multiline caret will blink -get bool GetMultiLineCaretBlinks=2566(,) +# Whether typing can be performed into multiple selections +get bool GetAdditionalSelectionTyping=2566(,) + +# Set whether additional carets will blink +set void SetAdditionalCaretsBlink=2567(bool additionalCaretsBlink,) + +# Whether additional carets will blink +get bool GetAdditionalCaretsBlink=2568(,) # How many selections are there? get int GetSelections=2570(,) diff --git a/src/Editor.cxx b/src/Editor.cxx index e8774c698..5effff931 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -11,6 +11,7 @@ #include <ctype.h> #include <string> +#include <vector> // With Borland C++ 5.5, including <string> includes Windows.h leading to defining // FindText to FindTextA which makes calls here to Document::FindText fail. @@ -146,8 +147,9 @@ Editor::Editor() { verticalScrollBarVisible = true; endAtLastLine = true; caretSticky = false; - multiLineCaret = false; - multiLineCaretBlinks = true; + multipleSelection = false; + additionalSelectionTyping = false; + additionalCaretsBlink = true; virtualSpaceOptions = SCVS_NONE; virtualSpaceOptions = SCVS_USERACCESSIBLE; @@ -3104,7 +3106,7 @@ void Editor::DrawCarets(Surface *surface, ViewStyle &vsDraw, int lineDoc, int xS xposCaret += ll->wrapIndent; } if ((xposCaret >= 0) && (vsDraw.caretWidth > 0) && (vsDraw.caretStyle != CARETSTYLE_INVISIBLE) && - ((posDrag.IsValid()) || ((caret.active && caret.on) || (!multiLineCaretBlinks && !mainCaret)))) { + ((posDrag.IsValid()) || ((caret.active && caret.on) || (!additionalCaretsBlink && !mainCaret)))) { bool caretAtEOF = false; bool caretAtEOL = false; bool drawBlockCaret = false; @@ -3663,8 +3665,18 @@ void Editor::AddChar(char ch) { AddCharUTF(s, 1); } +void Editor::FilterSelections() { + if (!additionalSelectionTyping && (sel.Count() > 1)) { + SelectionRange rangeOnly = sel.RangeMain(); + InvalidateSelection(rangeOnly, true); + sel.EmptyRanges(); + sel.AddSelection(rangeOnly); + } +} + // AddCharUTF inserts an array of bytes which may or may not be in UTF-8. void Editor::AddCharUTF(char *s, unsigned int len, bool treatAsDBCS) { + FilterSelections(); { UndoGroup ug(pdoc, (sel.Count() > 1) || !sel.Empty() || inOverstrike); for (size_t r=0; r<sel.Count(); r++) { @@ -3757,6 +3769,7 @@ void Editor::AddCharUTF(char *s, unsigned int len, bool treatAsDBCS) { } void Editor::ClearSelection() { + FilterSelections(); UndoGroup ug(pdoc); for (size_t r=0; r<sel.Count(); r++) { if (!sel.Range(r).Empty()) { @@ -3915,6 +3928,7 @@ void Editor::DelChar() { } void Editor::DelCharBack(bool allowLineStartDeletion) { + FilterSelections(); if (sel.IsRectangular()) allowLineStartDeletion = false; UndoGroup ug(pdoc, (sel.Count() > 1) || !sel.Empty()); @@ -3928,7 +3942,7 @@ void Editor::DelCharBack(bool allowLineStartDeletion) { int lineCurrentPos = pdoc->LineFromPosition(sel.Range(r).caret.Position()); if (allowLineStartDeletion || (pdoc->LineStart(lineCurrentPos) != sel.Range(r).caret.Position())) { if (pdoc->GetColumn(sel.Range(r).caret.Position()) <= pdoc->GetLineIndentation(lineCurrentPos) && - pdoc->GetColumn(sel.Range(r).caret.Position()) > 0 && pdoc->backspaceUnindents) { + pdoc->GetColumn(sel.Range(r).caret.Position()) > 0 && pdoc->backspaceUnindents) { UndoGroup ugInner(pdoc, !ug.Needed()); int indentation = pdoc->GetLineIndentation(lineCurrentPos); int indentationStep = pdoc->IndentSize(); @@ -5638,7 +5652,7 @@ void Editor::ButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, b SetMouseCapture(true); if (inDragDrop != ddInitial) { SetDragPosition(SelectionPosition(invalidPosition)); - if (ctrl) { + if (ctrl && multipleSelection) { InvalidateSelection(SelectionRange(newPos), true); sel.AddSelection(newPos); } else if (!shift) { @@ -5749,9 +5763,10 @@ void Editor::ButtonMove(Point pt) { sel.Rectangular() = SelectionRange(movePos, sel.Rectangular().anchor); SetSelection(movePos, sel.RangeMain().anchor); } else if (sel.Count() > 1) { - sel.TrimSelection(sel.RangeMain().anchor, movePos); - sel.RangeMain() = SelectionRange(movePos, sel.RangeMain().anchor); - InvalidateSelection(SelectionRange(movePos, sel.RangeMain().anchor), true); + SelectionRange range(movePos, sel.RangeMain().anchor); + sel.TrimSelection(range); + sel.RangeMain() = range; + InvalidateSelection(range, true); } else { SetSelection(movePos, sel.RangeMain().anchor); } @@ -8123,21 +8138,29 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { pdoc->AddUndoAction(wParam, lParam & UNDO_MAY_COALESCE); break; - case SCI_SETMULTILINECARET: - multiLineCaret = wParam != 0; + case SCI_SETMULTIPLESELECTION: + multipleSelection = wParam != 0; + InvalidateCaret(); + break; + + case SCI_GETMULTIPLESELECTION: + return multipleSelection; + + case SCI_SETADDITIONALSELECTIONTYPING: + additionalSelectionTyping = wParam != 0; InvalidateCaret(); break; - case SCI_GETMULTILINECARET: - return multiLineCaret; + case SCI_GETADDITIONALSELECTIONTYPING: + return additionalSelectionTyping; - case SCI_SETMULTILINECARETBLINKS: - multiLineCaretBlinks = wParam != 0; + case SCI_SETADDITIONALCARETSBLINK: + additionalCaretsBlink = wParam != 0; InvalidateCaret(); break; - case SCI_GETMULTILINECARETBLINKS: - return multiLineCaretBlinks; + case SCI_GETADDITIONALCARETSBLINK: + return additionalCaretsBlink; case SCI_GETSELECTIONS: return sel.Count(); diff --git a/src/Editor.h b/src/Editor.h index 79746477e..8f1ca9b7c 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -140,8 +140,9 @@ protected: // ScintillaBase subclass needs access to much of Editor bool verticalScrollBarVisible; bool endAtLastLine; bool caretSticky; - bool multiLineCaret; - bool multiLineCaretBlinks; + bool multipleSelection; + bool additionalSelectionTyping; + bool additionalCaretsBlink; int virtualSpaceOptions; @@ -351,6 +352,7 @@ protected: // ScintillaBase subclass needs access to much of Editor void SetScrollBars(); void ChangeSize(); + void FilterSelections(); int InsertSpace(int position, unsigned int spaces); void AddChar(char ch); virtual void AddCharUTF(char *s, unsigned int len, bool treatAsDBCS=false); diff --git a/src/PositionCache.cxx b/src/PositionCache.cxx index d3e19d4f4..580a1797c 100644 --- a/src/PositionCache.cxx +++ b/src/PositionCache.cxx @@ -10,6 +10,8 @@ #include <stdio.h> #include <ctype.h> +#include <vector> + #include "Platform.h" #include "Scintilla.h" diff --git a/src/ScintillaBase.cxx b/src/ScintillaBase.cxx index 0d25b248c..9247fce72 100644 --- a/src/ScintillaBase.cxx +++ b/src/ScintillaBase.cxx @@ -10,6 +10,8 @@ #include <stdio.h> #include <ctype.h> +#include <vector> + #include "Platform.h" #include "Scintilla.h" diff --git a/src/Selection.cxx b/src/Selection.cxx index d9c59cdb1..eada57d5e 100644 --- a/src/Selection.cxx +++ b/src/Selection.cxx @@ -7,6 +7,8 @@ #include <stdlib.h> +#include <vector> + #include "Platform.h" #include "Scintilla.h" @@ -128,13 +130,9 @@ SelectionSegment SelectionRange::Intersect(SelectionSegment check) const { } } -bool SelectionRange::Trim(SelectionPosition startPos, SelectionPosition endPos) { - SelectionPosition startRange = startPos; - SelectionPosition endRange = endPos; - if (startPos > endPos) { - startRange = endPos; - endRange = startPos; - } +bool SelectionRange::Trim(SelectionRange range) { + SelectionPosition startRange = range.Start(); + SelectionPosition endRange = range.End(); SelectionPosition start = Start(); SelectionPosition end = End(); PLATFORM_ASSERT(start <= end); @@ -178,24 +176,11 @@ void SelectionRange::MinimizeVirtualSpace() { } } -void Selection::Allocate() { - if (nRanges >= allocated) { - size_t allocateNew = (allocated + 1) * 2; - SelectionRange *rangesNew = new SelectionRange[allocateNew]; - for (size_t r=0; r<Count(); r++) - rangesNew[r] = ranges[r]; - delete []ranges; - ranges = rangesNew; - allocated = allocateNew; - } -} - -Selection::Selection() : ranges(0), allocated(0), nRanges(0), mainRange(0), moveExtends(false), selType(selStream) { +Selection::Selection() : ranges(0), nRanges(0), mainRange(0), moveExtends(false), selType(selStream) { AddSelection(SelectionPosition(0)); } Selection::~Selection() { - delete []ranges; } bool Selection::IsRectangular() const { @@ -281,9 +266,9 @@ void Selection::MovePositions(bool insertion, int startChange, int length) { } } -void Selection::TrimSelection(SelectionPosition startPos, SelectionPosition endPos) { +void Selection::TrimSelection(SelectionRange range) { for (size_t i=0; i<nRanges;) { - if ((i != mainRange) && (ranges[i].Trim(startPos, endPos))) { + if ((i != mainRange) && (ranges[i].Trim(range))) { // Trimmed to empty so remove for (size_t j=i;j<nRanges-1;j++) { ranges[j] = ranges[j+1]; @@ -297,21 +282,23 @@ void Selection::TrimSelection(SelectionPosition startPos, SelectionPosition endP } } -void Selection::AddSelection(SelectionPosition spPos) { - Allocate(); - TrimSelection(spPos, spPos); - ranges[nRanges] = SelectionRange(spPos); +void Selection::AddSelection(SelectionRange range) { + ranges.resize(nRanges + 1); + TrimSelection(range); + ranges[nRanges] = range; mainRange = nRanges; nRanges++; } +void Selection::AddSelection(SelectionPosition spPos) { + AddSelection(SelectionRange(spPos, spPos)); +} + void Selection::AddSelection(SelectionPosition spStartPos, SelectionPosition spEndPos, bool anchorLeft) { - Allocate(); - TrimSelection(spStartPos, spEndPos); - ranges[nRanges].caret = anchorLeft ? spEndPos : spStartPos; - ranges[nRanges].anchor = anchorLeft ? spStartPos : spEndPos; - mainRange = nRanges; - nRanges++; + if (anchorLeft) + AddSelection(SelectionRange(spEndPos, spStartPos)); + else + AddSelection(SelectionRange(spStartPos, spEndPos)); } int Selection::CharacterInSelection(int posCharacter) const { diff --git a/src/Selection.h b/src/Selection.h index 6fe828a2c..e98709312 100644 --- a/src/Selection.h +++ b/src/Selection.h @@ -116,19 +116,17 @@ struct SelectionRange { SelectionPosition End() const { return (anchor < caret) ? caret : anchor; } - bool Trim(SelectionPosition startPos, SelectionPosition endPos); + bool Trim(SelectionRange range); // If range is all virtual collapse to start of virtual space void MinimizeVirtualSpace(); }; class Selection { - SelectionRange *ranges; + std::vector<SelectionRange> ranges; SelectionRange rangeRectangular; - size_t allocated; size_t nRanges; size_t mainRange; bool moveExtends; - void Allocate(); public: enum selTypes { noSel, selStream, selRectangle, selLines, selThin }; selTypes selType; @@ -151,7 +149,8 @@ public: SelectionPosition Last() const; int Length() const; void MovePositions(bool insertion, int startChange, int length); - void TrimSelection(SelectionPosition startPos, SelectionPosition endPos); + void TrimSelection(SelectionRange range); + void AddSelection(SelectionRange range); void AddSelection(SelectionPosition spPos); void AddSelection(SelectionPosition spStartPos, SelectionPosition spEndPos, bool anchorLeft); int CharacterInSelection(int posCharacter) const; diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index e8ad20ef8..3687b86d0 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -13,6 +13,8 @@ #include <assert.h> #include <limits.h> +#include <vector> + #define _WIN32_WINNT 0x0500 #include <windows.h> #include <commctrl.h> |