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 | |
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.
-rw-r--r-- | cocoa/ScintillaCocoa.mm | 20 | ||||
-rw-r--r-- | gtk/ScintillaGTK.cxx | 29 | ||||
-rw-r--r-- | qt/ScintillaEditBase/ScintillaQt.cpp | 14 | ||||
-rw-r--r-- | qt/ScintillaEditBase/ScintillaQt.h | 1 | ||||
-rw-r--r-- | src/Editor.cxx | 48 | ||||
-rw-r--r-- | src/Editor.h | 54 | ||||
-rw-r--r-- | src/ScintillaBase.cxx | 1 | ||||
-rw-r--r-- | win32/ScintillaWin.cxx | 33 |
8 files changed, 104 insertions, 96 deletions
diff --git a/cocoa/ScintillaCocoa.mm b/cocoa/ScintillaCocoa.mm index 01310e9aa..b8c948dda 100644 --- a/cocoa/ScintillaCocoa.mm +++ b/cocoa/ScintillaCocoa.mm @@ -956,20 +956,20 @@ void ScintillaCocoa::Paste(bool forceRectangular) if (forceRectangular) selectedText.rectangular = forceRectangular; - if (!ok || !selectedText.s) + if (!ok || selectedText.Empty()) // No data or no flavor we support. return; pdoc->BeginUndoAction(); ClearSelection(false); - int length = selectedText.len - 1; // One less to avoid inserting the terminating 0 character. + int length = selectedText.Length(); if (selectedText.rectangular) { SelectionPosition selStart = sel.RangeMain().Start(); - PasteRectangular(selStart, selectedText.s, length); + PasteRectangular(selStart, selectedText.Data(), length); } else - if (pdoc->InsertString(sel.RangeMain().caret.Position(), selectedText.s, length)) + if (pdoc->InsertString(sel.RangeMain().caret.Position(), selectedText.Data(), length)) SetEmptySelection(sel.RangeMain().caret.Position() + length); pdoc->EndUndoAction(); @@ -1410,12 +1410,12 @@ bool ScintillaCocoa::PerformDragOperation(id <NSDraggingInfo> info) SelectionText text; GetPasteboardData(pasteboard, &text); - if (text.len > 0) + if (text.Length() > 0) { NSDragOperation operation = [info draggingSourceOperationMask]; bool moving = (operation & NSDragOperationMove) != 0; - DropAt(posDrag, text.s, moving, text.rectangular); + DropAt(posDrag, text.Data(), text.Length(), moving, text.rectangular); }; } @@ -1426,14 +1426,14 @@ bool ScintillaCocoa::PerformDragOperation(id <NSDraggingInfo> info) void ScintillaCocoa::SetPasteboardData(NSPasteboard* board, const SelectionText &selectedText) { - if (selectedText.len == 0) + if (selectedText.Length() == 0) return; CFStringEncoding encoding = EncodingFromCharacterSet(selectedText.codePage == SC_CP_UTF8, selectedText.characterSet); CFStringRef cfsVal = CFStringCreateWithBytes(kCFAllocatorDefault, - reinterpret_cast<const UInt8 *>(selectedText.s), - selectedText.len-1, encoding, false); + reinterpret_cast<const UInt8 *>(selectedText.Data()), + selectedText.Length(), encoding, false); NSArray *pbTypes = selectedText.rectangular ? [NSArray arrayWithObjects: NSStringPboardType, ScintillaRecPboardType, nil] : @@ -1486,7 +1486,7 @@ bool ScintillaCocoa::GetPasteboardData(NSPasteboard* board, SelectionText* selec int len = static_cast<int>(usedLen); std::string dest = Document::TransformLineEnds((char *)buffer.data(), len, pdoc->eolMode); - selectedText->Copy(dest.c_str(), dest.length()+1, pdoc->dbcsCodePage, + selectedText->Copy(dest, pdoc->dbcsCodePage, vs.styles[STYLE_DEFAULT].characterSet , rectangular, false); } return true; diff --git a/gtk/ScintillaGTK.cxx b/gtk/ScintillaGTK.cxx index f0fc63310..7b039dc3c 100644 --- a/gtk/ScintillaGTK.cxx +++ b/gtk/ScintillaGTK.cxx @@ -14,6 +14,7 @@ #include <string> #include <vector> #include <map> +#include <algorithm> #include <gtk/gtk.h> #include <gdk/gdkkeysyms.h> @@ -1449,14 +1450,14 @@ void ScintillaGTK::ClaimSelection() { primarySelection = true; gtk_selection_owner_set(GTK_WIDGET(PWidget(wMain)), GDK_SELECTION_PRIMARY, GDK_CURRENT_TIME); - primary.Free(); + primary.Clear(); } else if (OwnPrimarySelection()) { primarySelection = true; - if (primary.s == NULL) + if (primary.Empty()) gtk_selection_owner_set(NULL, GDK_SELECTION_PRIMARY, GDK_CURRENT_TIME); } else { primarySelection = false; - primary.Free(); + primary.Clear(); } } @@ -1480,7 +1481,7 @@ void ScintillaGTK::GetGtkSelectionText(GtkSelectionData *selectionData, Selectio // Return empty string if selection is not a string if ((selectionTypeData != GDK_TARGET_STRING) && (selectionTypeData != atomUTF8)) { - selText.Copy("", 1, SC_CP_UTF8, 0, false, false); + selText.Clear(); return; } @@ -1540,9 +1541,9 @@ void ScintillaGTK::ReceivedSelection(GtkSelectionData *selection_data) { sel.Range(sel.Main()).Start(); if (selText.rectangular) { - PasteRectangular(selStart, selText.s, selText.len-1); + PasteRectangular(selStart, selText.Data(), selText.Length()); } else { - InsertPaste(selStart, selText.s, selText.len-1); + InsertPaste(selStart, selText.Data(), selText.Length()); } EnsureCaretVisible(); } @@ -1566,7 +1567,7 @@ void ScintillaGTK::ReceivedDrop(GtkSelectionData *selection_data) { if (TypeOfGSD(selection_data) > 0) { SelectionText selText; GetGtkSelectionText(selection_data, selText); - DropAt(posDrop, selText.s, false, selText.rectangular); + DropAt(posDrop, selText.Data(), selText.Length(), false, selText.rectangular); } } else if (LengthOfGSD(selection_data) > 0) { //~ fprintf(stderr, "ReceivedDrop other %p\n", static_cast<void *>(selection_data->type)); @@ -1583,7 +1584,7 @@ void ScintillaGTK::GetSelection(GtkSelectionData *selection_data, guint info, Se // from code below SelectionText *newline_normalized = NULL; { - std::string tmpstr = Document::TransformLineEnds(text->s, text->len, SC_EOL_LF); + std::string tmpstr = Document::TransformLineEnds(text->Data(), text->Length(), SC_EOL_LF); newline_normalized = new SelectionText(); newline_normalized->Copy(tmpstr, SC_CP_UTF8, 0, text->rectangular, false); text = newline_normalized; @@ -1595,7 +1596,7 @@ void ScintillaGTK::GetSelection(GtkSelectionData *selection_data, guint info, Se if ((text->codePage != SC_CP_UTF8) && (info == TARGET_UTF8_STRING)) { const char *charSet = ::CharacterSetID(text->characterSet); if (*charSet) { - std::string tmputf = ConvertText(text->s, text->len-1, "UTF-8", charSet, false); + std::string tmputf = ConvertText(text->Data(), text->Length(), "UTF-8", charSet, false); converted = new SelectionText(); converted->Copy(tmputf, SC_CP_UTF8, 0, text->rectangular, false); text = converted; @@ -1609,8 +1610,8 @@ void ScintillaGTK::GetSelection(GtkSelectionData *selection_data, guint info, Se // All other tested aplications behave benignly by ignoring the \0. // The #if is here because on Windows cfColumnSelect clip entry is used // instead as standard indicator of rectangularness (so no need to kludge) - const char *textData = text->s ? text->s : ""; - int len = strlen(textData); + const char *textData = text->Data(); + int len = text->Length(); #if PLAT_GTK_WIN32 == 0 if (text->rectangular) len++; @@ -1657,7 +1658,7 @@ void ScintillaGTK::UnclaimSelection(GdkEventSelection *selection_event) { if (selection_event->selection == GDK_SELECTION_PRIMARY) { //Platform::DebugPrintf("UnclaimPrimarySelection\n"); if (!OwnPrimarySelection()) { - primary.Free(); + primary.Clear(); primarySelection = false; FullPaint(); } @@ -1798,7 +1799,7 @@ gint ScintillaGTK::PressThis(GdkEventButton *event) { } else if (event->button == 2) { // Grab the primary selection if it exists SelectionPosition pos = SPositionFromLocation(pt, false, false, UserVirtualSpace()); - if (OwnPrimarySelection() && primary.s == NULL) + if (OwnPrimarySelection() && primary.Empty()) CopySelectionRange(&primary); sel.Clear(); @@ -2544,7 +2545,7 @@ void ScintillaGTK::SelectionGet(GtkWidget *widget, try { //Platform::DebugPrintf("Selection get\n"); if (SelectionOfGSD(selection_data) == GDK_SELECTION_PRIMARY) { - if (sciThis->primary.s == NULL) { + if (sciThis->primary.Empty()) { sciThis->CopySelectionRange(&sciThis->primary); } sciThis->GetSelection(selection_data, info, &sciThis->primary); diff --git a/qt/ScintillaEditBase/ScintillaQt.cpp b/qt/ScintillaEditBase/ScintillaQt.cpp index 8c6e89e60..4d0d62082 100644 --- a/qt/ScintillaEditBase/ScintillaQt.cpp +++ b/qt/ScintillaEditBase/ScintillaQt.cpp @@ -171,11 +171,11 @@ bool ScintillaQt::DragThreshold(Point ptStart, Point ptNow) static QString StringFromSelectedText(const SelectionText &selectedText) { if (selectedText.codePage == SC_CP_UTF8) { - return QString::fromUtf8(selectedText.s, selectedText.len-1); + return QString::fromUtf8(selectedText.Data(), selectedText.Length()); } else { QTextCodec *codec = QTextCodec::codecForName( CharacterSetID(selectedText.characterSet)); - return codec->toUnicode(selectedText.s, selectedText.len-1); + return codec->toUnicode(selectedText.Data(), selectedText.Length()); } } @@ -341,7 +341,7 @@ void ScintillaQt::PasteFromMode(QClipboard::Mode clipboardMode_) int len = utext.length(); std::string dest = Document::TransformLineEnds(utext, len, pdoc->eolMode); SelectionText selText; - selText.Copy(dest.c_str(), dest.length(), pdoc->dbcsCodePage, CharacterSetOfDocument(), isRectangular, false); + selText.Copy(dest, pdoc->dbcsCodePage, CharacterSetOfDocument(), isRectangular, false); UndoGroup ug(pdoc); ClearSelection(multiPasteMode == SC_MULTIPASTE_EACH); @@ -349,9 +349,9 @@ void ScintillaQt::PasteFromMode(QClipboard::Mode clipboardMode_) sel.Rectangular().Start() : sel.Range(sel.Main()).Start(); if (selText.rectangular) { - PasteRectangular(selStart, selText.s, selText.len); + PasteRectangular(selStart, selText.Data(), selText.Length()); } else { - InsertPaste(selStart, selText.s, selText.len); + InsertPaste(selStart, selText.Data(), selText.Length()); } EnsureCaretVisible(); } @@ -613,7 +613,7 @@ void ScintillaQt::StartDrag() { inDragDrop = ddDragging; dropWentOutside = true; - if (drag.len) { + if (drag.Length()) { QMimeData *mimeData = new QMimeData; QString sText = StringFromSelectedText(drag); mimeData->setText(sText); @@ -768,5 +768,5 @@ void ScintillaQt::Drop(const Point &point, const QMimeData *data, bool move) SelectionPosition movePos = SPositionFromLocation(point, false, false, UserVirtualSpace()); - DropAt(movePos, dest.c_str(), move, rectangular); + DropAt(movePos, dest.c_str(), dest.length(), move, rectangular); } diff --git a/qt/ScintillaEditBase/ScintillaQt.h b/qt/ScintillaEditBase/ScintillaQt.h index 608367782..f7f7fe3ee 100644 --- a/qt/ScintillaEditBase/ScintillaQt.h +++ b/qt/ScintillaEditBase/ScintillaQt.h @@ -19,6 +19,7 @@ #include <string> #include <vector> #include <map> +#include <algorithm> #include "Scintilla.h" #include "Platform.h" 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" diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index 3bdc4a1cc..dca98d5ed 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -16,6 +16,7 @@ #include <string> #include <vector> #include <map> +#include <algorithm> #undef _WIN32_WINNT #define _WIN32_WINNT 0x0500 @@ -2267,20 +2268,24 @@ void ScintillaWin::CopyToClipboard(const SelectionText &selectedText) { // Default Scintilla behaviour in Unicode mode if (IsUnicodeMode()) { - int uchars = UTF16Length(selectedText.s, selectedText.len); + int uchars = UTF16Length(selectedText.Data(), + static_cast<int>(selectedText.LengthWithTerminator())); uniText.Allocate(2 * uchars); if (uniText) { - UTF16FromUTF8(selectedText.s, selectedText.len, static_cast<wchar_t *>(uniText.ptr), uchars); + UTF16FromUTF8(selectedText.Data(), static_cast<int>(selectedText.LengthWithTerminator()), + static_cast<wchar_t *>(uniText.ptr), uchars); } } else { // Not Unicode mode // Convert to Unicode using the current Scintilla code page UINT cpSrc = CodePageFromCharSet( selectedText.characterSet, selectedText.codePage); - int uLen = ::MultiByteToWideChar(cpSrc, 0, selectedText.s, selectedText.len, 0, 0); + int uLen = ::MultiByteToWideChar(cpSrc, 0, selectedText.Data(), + static_cast<int>(selectedText.LengthWithTerminator()), 0, 0); uniText.Allocate(2 * uLen); if (uniText) { - ::MultiByteToWideChar(cpSrc, 0, selectedText.s, selectedText.len, + ::MultiByteToWideChar(cpSrc, 0, selectedText.Data(), + static_cast<int>(selectedText.LengthWithTerminator()), static_cast<wchar_t *>(uniText.ptr), uLen); } } @@ -2292,10 +2297,11 @@ void ScintillaWin::CopyToClipboard(const SelectionText &selectedText) { // paste the text // Windows NT, 2k, XP automatically generates CF_TEXT GlobalMemory ansiText; - ansiText.Allocate(selectedText.len); + ansiText.Allocate(selectedText.LengthWithTerminator()); if (ansiText) { ::WideCharToMultiByte(CP_ACP, 0, static_cast<wchar_t *>(uniText.ptr), -1, - static_cast<char *>(ansiText.ptr), selectedText.len, NULL, NULL); + static_cast<char *>(ansiText.ptr), + static_cast<int>(selectedText.LengthWithTerminator()), NULL, NULL); ansiText.SetClip(CF_TEXT); } } @@ -2303,9 +2309,9 @@ void ScintillaWin::CopyToClipboard(const SelectionText &selectedText) { } else { // There was a failure - try to copy at least ANSI text GlobalMemory ansiText; - ansiText.Allocate(selectedText.len); + ansiText.Allocate(selectedText.LengthWithTerminator()); if (ansiText) { - memcpy(static_cast<char *>(ansiText.ptr), selectedText.s, selectedText.len); + memcpy(static_cast<char *>(ansiText.ptr), selectedText.Data(), selectedText.LengthWithTerminator()); ansiText.SetClip(CF_TEXT); } } @@ -2619,7 +2625,7 @@ STDMETHODIMP ScintillaWin::Drop(LPDATAOBJECT pIDataSource, DWORD grfKeyState, ::ScreenToClient(MainHWND(), &rpt); SelectionPosition movePos = SPositionFromLocation(Point(rpt.x, rpt.y), false, false, UserVirtualSpace()); - DropAt(movePos, &data[0], *pdwEffect == DROPEFFECT_MOVE, hrRectangular == S_OK); + DropAt(movePos, &data[0], data.size() - 1, *pdwEffect == DROPEFFECT_MOVE, hrRectangular == S_OK); // Free data if (medium.pUnkForRelease != NULL) @@ -2652,15 +2658,16 @@ STDMETHODIMP ScintillaWin::GetData(FORMATETC *pFEIn, STGMEDIUM *pSTM) { GlobalMemory text; if (pFEIn->cfFormat == CF_UNICODETEXT) { - int uchars = UTF16Length(drag.s, drag.len); + int uchars = UTF16Length(drag.Data(), static_cast<int>(drag.LengthWithTerminator())); text.Allocate(2 * uchars); if (text) { - UTF16FromUTF8(drag.s, drag.len, static_cast<wchar_t *>(text.ptr), uchars); + UTF16FromUTF8(drag.Data(), static_cast<int>(drag.LengthWithTerminator()), + static_cast<wchar_t *>(text.ptr), uchars); } } else { - text.Allocate(drag.len); + text.Allocate(drag.LengthWithTerminator()); if (text) { - memcpy(static_cast<char *>(text.ptr), drag.s, drag.len); + memcpy(static_cast<char *>(text.ptr), drag.Data(), drag.LengthWithTerminator()); } } pSTM->hGlobal = text ? text.Unlock() : 0; |