diff options
author | nyamatongwe <devnull@localhost> | 2013-05-26 18:23:09 +1000 |
---|---|---|
committer | nyamatongwe <devnull@localhost> | 2013-05-26 18:23:09 +1000 |
commit | 8e023d0ca853019b90d0dcb02533eab32f7e6e79 (patch) | |
tree | 91bc7d85c68a826653417ee942177db2a857f866 /src | |
parent | 0168d3feab947066c2e9cfba3140f0a24be1b5fc (diff) | |
download | scintilla-mirror-8e023d0ca853019b90d0dcb02533eab32f7e6e79.tar.gz |
Switch SelectionText to use a std::string to hold the data and to provide accessors to this data.
Add a length argument to DropAt, although previous signature still available.
Diffstat (limited to 'src')
-rw-r--r-- | src/Editor.cxx | 48 | ||||
-rw-r--r-- | src/Editor.h | 54 | ||||
-rw-r--r-- | src/ScintillaBase.cxx | 1 |
3 files changed, 51 insertions, 52 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx index 8081dcdd6..389b25346 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -1137,7 +1137,7 @@ void Editor::MoveSelectedLines(int lineDelta) { pdoc->InsertCString(pdoc->Length(), eol); GoToLine(currentLine + lineDelta); - pdoc->InsertCString(CurrentPosition(), selectedText.s); + pdoc->InsertCString(CurrentPosition(), selectedText.Data()); if (appendEol) { pdoc->InsertCString(CurrentPosition() + selectionLength, eol); selectionLength += istrlen(eol); @@ -6053,7 +6053,7 @@ void Editor::CopyRangeToClipboard(int start, int end) { void Editor::CopyText(int length, const char *text) { SelectionText selectedText; - selectedText.Copy(text, length + 1, + selectedText.Copy(std::string(text, length), pdoc->dbcsCodePage, vs.styles[STYLE_DEFAULT].characterSet, false, false); CopyToClipboard(selectedText); } @@ -6092,7 +6092,7 @@ void Editor::StartDrag() { //DisplayCursor(Window::cursorArrow); } -void Editor::DropAt(SelectionPosition position, const char *value, bool moving, bool rectangular) { +void Editor::DropAt(SelectionPosition position, const char *value, size_t lengthValue, bool moving, bool rectangular) { //Platform::DebugPrintf("DropAt %d %d\n", inDragDrop, position); if (inDragDrop == ddDragging) dropWentOutside = false; @@ -6133,15 +6133,15 @@ void Editor::DropAt(SelectionPosition position, const char *value, bool moving, position = positionAfterDeletion; if (rectangular) { - PasteRectangular(position, value, istrlen(value)); + PasteRectangular(position, value, static_cast<int>(lengthValue)); // Should try to select new rectangle but it may not be a rectangle now so just select the drop position SetEmptySelection(position); } else { position = MovePositionOutsideChar(position, sel.MainCaret() - position.Position()); position = SelectionPosition(InsertSpace(position.Position(), position.VirtualSpace())); - if (pdoc->InsertCString(position.Position(), value)) { + if (pdoc->InsertString(position.Position(), value, static_cast<int>(lengthValue))) { SelectionPosition posAfterInsertion = position; - posAfterInsertion.Add(istrlen(value)); + posAfterInsertion.Add(static_cast<int>(lengthValue)); SetSelection(posAfterInsertion, position); } } @@ -6150,6 +6150,10 @@ void Editor::DropAt(SelectionPosition position, const char *value, bool moving, } } +void Editor::DropAt(SelectionPosition position, const char *value, bool moving, bool rectangular) { + DropAt(position, value, strlen(value), moving, rectangular); +} + /** * @return true if given position is inside the selection, */ @@ -6655,26 +6659,26 @@ void Editor::ButtonUp(Point pt, unsigned int curTime, bool ctrl) { SelectionPosition selStart = SelectionStart(); SelectionPosition selEnd = SelectionEnd(); if (selStart < selEnd) { - if (drag.len) { + if (drag.Length()) { if (ctrl) { - if (pdoc->InsertString(newPos.Position(), drag.s, drag.len)) { - SetSelection(newPos.Position(), newPos.Position() + drag.len); + if (pdoc->InsertString(newPos.Position(), drag.Data(), static_cast<int>(drag.Length()))) { + SetSelection(newPos.Position(), newPos.Position() + static_cast<int>(drag.Length())); } } else if (newPos < selStart) { - pdoc->DeleteChars(selStart.Position(), drag.len); - if (pdoc->InsertString(newPos.Position(), drag.s, drag.len)) { - SetSelection(newPos.Position(), newPos.Position() + drag.len); + pdoc->DeleteChars(selStart.Position(), static_cast<int>(drag.Length())); + if (pdoc->InsertString(newPos.Position(), drag.Data(), static_cast<int>(drag.Length()))) { + SetSelection(newPos.Position(), newPos.Position() + static_cast<int>(drag.Length())); } } else if (newPos > selEnd) { - pdoc->DeleteChars(selStart.Position(), drag.len); - newPos.Add(-drag.len); - if (pdoc->InsertString(newPos.Position(), drag.s, drag.len)) { - SetSelection(newPos.Position(), newPos.Position() + drag.len); + pdoc->DeleteChars(selStart.Position(), static_cast<int>(drag.Length())); + newPos.Add(-static_cast<int>(drag.Length())); + if (pdoc->InsertString(newPos.Position(), drag.Data(), static_cast<int>(drag.Length()))) { + SetSelection(newPos.Position(), newPos.Position() + static_cast<int>(drag.Length())); } } else { SetEmptySelection(newPos.Position()); } - drag.Free(); + drag.Clear(); } selectionType = selChar; } @@ -7512,13 +7516,13 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { SelectionText selectedText; CopySelectionRange(&selectedText); if (lParam == 0) { - return selectedText.len ? selectedText.len : 1; + return selectedText.LengthWithTerminator(); } else { char *ptr = CharPtrFromSPtr(lParam); - int iChar = 0; - if (selectedText.len) { - for (; iChar < selectedText.len; iChar++) - ptr[iChar] = selectedText.s[iChar]; + unsigned int iChar = 0; + if (selectedText.Length()) { + for (; iChar < selectedText.LengthWithTerminator(); iChar++) + ptr[iChar] = selectedText.Data()[iChar]; } else { ptr[0] = '\0'; } diff --git a/src/Editor.h b/src/Editor.h index 46167cf4a..86b6acd9e 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -75,60 +75,53 @@ public: }; /** - * Hold a piece of text selected for copying or dragging. - * The text is expected to hold a terminating '\0' and this is counted in len. + * Hold a piece of text selected for copying or dragging, along with encoding and selection format information. */ class SelectionText { + std::string s; public: - char *s; - int len; bool rectangular; bool lineCopy; int codePage; int characterSet; - SelectionText() : s(0), len(0), rectangular(false), lineCopy(false), codePage(0), characterSet(0) {} + SelectionText() : rectangular(false), lineCopy(false), codePage(0), characterSet(0) {} ~SelectionText() { - Free(); } - void Free() { - delete []s; - s = 0; - len = 0; + void Clear() { + s.clear(); rectangular = false; lineCopy = false; codePage = 0; characterSet = 0; } - void Copy(const char *s_, int len_, int codePage_, int characterSet_, bool rectangular_, bool lineCopy_) { - delete []s; - s = 0; - s = new char[len_]; - len = len_; - for (int i = 0; i < len_; i++) { - s[i] = s_[i]; - } + void Copy(const std::string &s_, int codePage_, int characterSet_, bool rectangular_, bool lineCopy_) { + s = s_; codePage = codePage_; characterSet = characterSet_; rectangular = rectangular_; lineCopy = lineCopy_; FixSelectionForClipboard(); } - void Copy(const std::string &s, int codePage_, int characterSet_, bool rectangular_, bool lineCopy_) { - Copy(s.c_str(), s.length()+1, codePage_, characterSet_, rectangular_, lineCopy_); - } void Copy(const SelectionText &other) { - Copy(other.s, other.len, other.codePage, other.characterSet, other.rectangular, other.lineCopy); + Copy(other.s, other.codePage, other.characterSet, other.rectangular, other.lineCopy); + } + const char *Data() const { + return s.c_str(); + } + size_t Length() const { + return s.length(); + } + size_t LengthWithTerminator() const { + return s.length() + 1; + } + bool Empty() const { + return s.empty(); } - private: void FixSelectionForClipboard() { - // Replace null characters by spaces. - // To avoid that the content of the clipboard is truncated in the paste operation - // when the clipboard contains null characters. - for (int i = 0; i < len - 1; ++i) { - if (s[i] == '\0') - s[i] = ' '; - } + // To avoid truncating the contents of the clipboard when pasted where the + // clipboard contains NUL characters, replace NUL characters by spaces. + std::replace(s.begin(), s.end(), '\0', ' '); } }; @@ -527,6 +520,7 @@ protected: // ScintillaBase subclass needs access to much of Editor virtual void DisplayCursor(Window::Cursor c); virtual bool DragThreshold(Point ptStart, Point ptNow); virtual void StartDrag(); + void DropAt(SelectionPosition position, const char *value, size_t lengthValue, bool moving, bool rectangular); void DropAt(SelectionPosition position, const char *value, bool moving, bool rectangular); /** PositionInSelection returns true if position in selection. */ bool PositionInSelection(int pos); diff --git a/src/ScintillaBase.cxx b/src/ScintillaBase.cxx index 31db93eca..5d886f5a5 100644 --- a/src/ScintillaBase.cxx +++ b/src/ScintillaBase.cxx @@ -14,6 +14,7 @@ #include <string> #include <vector> #include <map> +#include <algorithm> #include "Platform.h" |