diff options
author | nyamatongwe <unknown> | 2001-09-01 03:01:09 +0000 |
---|---|---|
committer | nyamatongwe <unknown> | 2001-09-01 03:01:09 +0000 |
commit | 2551486092fa6cd68a1881b84c502f0bb7e74892 (patch) | |
tree | a90dfa88218a698f1a689abd2caa2e0b54772405 | |
parent | 111ae4b1a706e2daf7c6e561a5389b57d4b7ea2b (diff) | |
download | scintilla-mirror-2551486092fa6cd68a1881b84c502f0bb7e74892.tar.gz |
Using new SelectionText type to handle text that is the subject of copy,
cut, paste and drag operations.
Mouse wheel scrolling moved into platform subclasses.
Macro support always included so MACRO_SUPPORT definition and use removed.
Allowing menu popup moved from Editor to ScintillaBase.
-rw-r--r-- | gtk/ScintillaGTK.cxx | 127 | ||||
-rw-r--r-- | include/Scintilla.h | 13 | ||||
-rw-r--r-- | src/Editor.cxx | 117 | ||||
-rw-r--r-- | src/Editor.h | 40 | ||||
-rw-r--r-- | src/ScintillaBase.cxx | 5 | ||||
-rw-r--r-- | src/ScintillaBase.h | 1 | ||||
-rw-r--r-- | win32/ScintillaWin.cxx | 31 |
7 files changed, 138 insertions, 196 deletions
diff --git a/gtk/ScintillaGTK.cxx b/gtk/ScintillaGTK.cxx index 254648080..271fddf88 100644 --- a/gtk/ScintillaGTK.cxx +++ b/gtk/ScintillaGTK.cxx @@ -52,12 +52,15 @@ class ScintillaGTK : public ScintillaBase { GtkObject *adjustmenth; int scrollBarWidth; int scrollBarHeight; - char *pasteBuffer; - bool pasteBufferIsRectangular; + + // Because clipboard access is asynchronous, copyText is created by Copy + SelectionText copyText; + + SelectionText primary; + GdkEventButton evbtn; bool capturedMouse; bool dragWasDropped; - char *primarySelectionCopy; GtkWidgetClass *parentClass; @@ -72,6 +75,7 @@ class ScintillaGTK : public ScintillaBase { GdkICAttr *ic_attr; // Wheel mouse support + unsigned int linesPerScroll; GTimeVal lastWheelMouseTime; gint lastWheelMouseDirection; gint wheelMouseIntensity; @@ -118,7 +122,7 @@ private: virtual void ClaimSelection(); void ReceivedSelection(GtkSelectionData *selection_data); void ReceivedDrop(GtkSelectionData *selection_data); - void GetSelection(GtkSelectionData *selection_data, guint info, char *text, bool isRectangular); + void GetSelection(GtkSelectionData *selection_data, guint info, SelectionText *selected); void UnclaimSelection(GdkEventSelection *selection_event); void Resize(int width, int height); @@ -142,6 +146,7 @@ private: static void ScrollSignal(GtkAdjustment *adj, ScintillaGTK *sciThis); static void ScrollHSignal(GtkAdjustment *adj, ScintillaGTK *sciThis); + gint PressThis(GdkEventButton *event); static gint Press(GtkWidget *widget, GdkEventButton *event); static gint MouseRelease(GtkWidget *widget, GdkEventButton *event); #if PLAT_GTK_WIN32 @@ -201,9 +206,8 @@ static ScintillaGTK *ScintillaFromWidget(GtkWidget *widget) { ScintillaGTK::ScintillaGTK(_ScintillaObject *sci_) : adjustmentv(0), adjustmenth(0), scrollBarWidth(30), scrollBarHeight(30), - pasteBuffer(0), pasteBufferIsRectangular(false), capturedMouse(false), dragWasDropped(false), - primarySelectionCopy(0), parentClass(0), + parentClass(0), ic(NULL), ic_attr(NULL), lastWheelMouseDirection(0), wheelMouseIntensity(0) { sci = sci_; @@ -220,7 +224,7 @@ ScintillaGTK::ScintillaGTK(_ScintillaObject *sci_) : #ifndef SPI_GETWHEELSCROLLLINES #define SPI_GETWHEELSCROLLLINES 104 #endif - ::SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &ucWheelScrollLines, 0); + ::SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &linesPerScroll, 0); #else ucWheelScrollLines = 4; #endif @@ -231,7 +235,6 @@ ScintillaGTK::ScintillaGTK(_ScintillaObject *sci_) : } ScintillaGTK::~ScintillaGTK() { - delete []primarySelectionCopy; } void ScintillaGTK::RealizeThis(GtkWidget *widget) { @@ -457,9 +460,6 @@ void ScintillaGTK::Initialise() { parentClass = reinterpret_cast<GtkWidgetClass *>( gtk_type_class(gtk_container_get_type())); - pasteBuffer = 0; - pasteBufferIsRectangular = false; - GTK_WIDGET_SET_FLAGS(wMain.GetID(), GTK_CAN_FOCUS); GTK_WIDGET_SET_FLAGS(GTK_WIDGET(wMain.GetID()), GTK_SENSITIVE); gtk_widget_set_events(wMain.GetID(), @@ -764,9 +764,7 @@ int ScintillaGTK::KeyDefault(int key, int modifiers) { void ScintillaGTK::Copy() { if (currentPos != anchor) { - delete []pasteBuffer; - pasteBuffer = CopySelectionRange(); - pasteBufferIsRectangular = selType == selRectangle; + CopySelectionRange(©Text); gtk_selection_owner_set(GTK_WIDGET(wMain.GetID()), clipboard_atom, GDK_CURRENT_TIME); @@ -829,16 +827,14 @@ void ScintillaGTK::ClaimSelection() { primarySelection = true; gtk_selection_owner_set(GTK_WIDGET(wMain.GetID()), GDK_SELECTION_PRIMARY, GDK_CURRENT_TIME); - delete []primarySelectionCopy; - primarySelectionCopy = NULL; + primary.Set(0, 0); } else if (OwnPrimarySelection()) { - if (primarySelectionCopy == NULL) - gtk_selection_owner_set(NULL, GDK_SELECTION_PRIMARY, GDK_CURRENT_TIME); primarySelection = true; + if (primary.s == NULL) + gtk_selection_owner_set(NULL, GDK_SELECTION_PRIMARY, GDK_CURRENT_TIME); } else { - delete []primarySelectionCopy; - primarySelectionCopy = NULL; primarySelection = false; + primary.Set(0, 0); } } @@ -927,30 +923,21 @@ void ScintillaGTK::ReceivedDrop(GtkSelectionData *selection_data) { Redraw(); } -// Preprocessor used to avoid warnings here -#if PLAT_GTK_WIN32 -void ScintillaGTK::GetSelection(GtkSelectionData *selection_data, guint info, char *text, bool) -#else -void ScintillaGTK::GetSelection(GtkSelectionData *selection_data, guint info, char *text, bool isRectangular) -#endif -{ - char *selBuffer = text; - char *tmpBuffer = NULL; // Buffer to be freed - +void ScintillaGTK::GetSelection(GtkSelectionData *selection_data, guint info, SelectionText *text) { if (selection_data->selection == GDK_SELECTION_PRIMARY) { - if (primarySelectionCopy != NULL) { - selBuffer = primarySelectionCopy; - } else { - tmpBuffer = CopySelectionRange(); - selBuffer = tmpBuffer; + if (primary.s == NULL) { + CopySelectionRange(&primary); } + text = &primary; } + char *selBuffer = text->s; + #if PLAT_GTK_WIN32 // win32gtk requires \n delimited lines and doesn't work right with // other line formats, so make a copy of the clip text now with // newlines converted - char *tmpstr = new char[strlen(selBuffer) + 1]; + char *tmpstr = new char[text->len + 1]; char *sptr = selBuffer; char *dptr = tmpstr; while (*sptr != '\0') { @@ -979,7 +966,7 @@ void ScintillaGTK::GetSelection(GtkSelectionData *selection_data, guint info, ch // The #if is here because on Windows cfColumnSelect clip entry is used // instead as standard indicator of rectangularness (so no need to kludge) #if PLAT_GTK_WIN32 == 0 - if (isRectangular) + if (text->rectangular) len++; #endif gtk_selection_data_set(selection_data, GDK_SELECTION_TYPE_STRING, @@ -997,7 +984,6 @@ void ScintillaGTK::GetSelection(GtkSelectionData *selection_data, guint info, ch gdk_free_compound_text(text); } - delete []tmpBuffer; #if PLAT_GTK_WIN32 delete []tmpstr; #endif @@ -1008,8 +994,7 @@ void ScintillaGTK::UnclaimSelection(GdkEventSelection *selection_event) { if (selection_event->selection == GDK_SELECTION_PRIMARY) { //Platform::DebugPrintf("UnclaimPrimarySelection\n"); if (!OwnPrimarySelection()) { - delete []primarySelectionCopy; - primarySelectionCopy = NULL; + primary.Set(0, 0); primarySelection = false; FullPaint(); } @@ -1053,20 +1038,17 @@ void ScintillaGTK::Resize(int width, int height) { SetScrollBars(); } -gint ScintillaGTK::Press(GtkWidget *widget, GdkEventButton *event) { - ScintillaGTK *sciThis = ScintillaFromWidget(widget); - //Platform::DebugPrintf("Press %x time=%d state = %x button = %x\n",sciThis,event->time, event->state, event->button); +gint ScintillaGTK::PressThis(GdkEventButton *event) { + //Platform::DebugPrintf("Press %x time=%d state = %x button = %x\n",this,event->time, event->state, event->button); // Do not use GTK+ double click events as Scintilla has its own double click detection if (event->type != GDK_BUTTON_PRESS) return FALSE; - sciThis->evbtn = *event; + evbtn = *event; Point pt; pt.x = int(event->x); pt.y = int(event->y); - if (event->window != widget->window) - return FALSE; - PRectangle rcClient = sciThis->GetClientRectangle(); + PRectangle rcClient = GetClientRectangle(); //Platform::DebugPrintf("Press %0d,%0d in %0d,%0d %0d,%0d\n", // pt.x, pt.y, rcClient.left, rcClient.top, rcClient.right, rcClient.bottom); if ((pt.x > rcClient.right) || (pt.y > rcClient.bottom)) { @@ -1076,54 +1058,61 @@ gint ScintillaGTK::Press(GtkWidget *widget, GdkEventButton *event) { bool ctrl = event->state & GDK_CONTROL_MASK; - gtk_widget_grab_focus(sciThis->wMain.GetID()); + gtk_widget_grab_focus(wMain.GetID()); if (event->button == 1) { - //sciThis->ButtonDown(pt, event->time, + //ButtonDown(pt, event->time, // event->state & GDK_SHIFT_MASK, // event->state & GDK_CONTROL_MASK, // event->state & GDK_MOD1_MASK); // Instead of sending literal modifiers use control instead of alt // This is because all the window managers seem to grab alt + click for moving - sciThis->ButtonDown(pt, event->time, + ButtonDown(pt, event->time, event->state & GDK_SHIFT_MASK, event->state & GDK_CONTROL_MASK, event->state & GDK_CONTROL_MASK); } else if (event->button == 2) { // Grab the primary selection if it exists - Position pos = sciThis->PositionFromLocation(pt); - if (sciThis->OwnPrimarySelection() && sciThis->primarySelectionCopy == NULL) - sciThis->primarySelectionCopy = sciThis->CopySelectionRange(); + Position pos = PositionFromLocation(pt); + if (OwnPrimarySelection() && primary.s == NULL) + CopySelectionRange(&primary); - sciThis->SetSelection(pos, pos); - gtk_selection_convert(GTK_WIDGET(sciThis->wMain.GetID()), GDK_SELECTION_PRIMARY, + SetSelection(pos, pos); + gtk_selection_convert(GTK_WIDGET(wMain.GetID()), GDK_SELECTION_PRIMARY, gdk_atom_intern("STRING", FALSE), event->time); - } else if (event->button == 3 && sciThis->displayPopupMenu) { + } else if (event->button == 3 && displayPopupMenu) { // PopUp menu // Convert to screen int ox = 0; int oy = 0; - gdk_window_get_origin(sciThis->wMain.GetID()->window, &ox, &oy); - sciThis->ContextMenu(Point(pt.x + ox, pt.y + oy)); + gdk_window_get_origin(wMain.GetID()->window, &ox, &oy); + ContextMenu(Point(pt.x + ox, pt.y + oy)); } else if (event->button == 4) { // Wheel scrolling up (only xwin gtk does it this way) if (ctrl) - gtk_adjustment_set_value(GTK_ADJUSTMENT(sciThis->adjustmenth), ( - (sciThis->xOffset) / 2 ) - 6); + gtk_adjustment_set_value(GTK_ADJUSTMENT(adjustmenth), ( + (xOffset) / 2 ) - 6); else - gtk_adjustment_set_value(GTK_ADJUSTMENT(sciThis->adjustmentv), - sciThis->topLine - 3); + gtk_adjustment_set_value(GTK_ADJUSTMENT(adjustmentv), + topLine - 3); } else if ( event->button == 5 ) { // Wheel scrolling down (only xwin gtk does it this way) if (ctrl) - gtk_adjustment_set_value(GTK_ADJUSTMENT(sciThis->adjustmenth), ( - (sciThis->xOffset) / 2 ) + 6); + gtk_adjustment_set_value(GTK_ADJUSTMENT(adjustmenth), ( + (xOffset) / 2 ) + 6); else - gtk_adjustment_set_value(GTK_ADJUSTMENT(sciThis->adjustmentv), - sciThis->topLine + 3); + gtk_adjustment_set_value(GTK_ADJUSTMENT(adjustmentv), + topLine + 3); } return FALSE; } +gint ScintillaGTK::Press(GtkWidget *widget, GdkEventButton *event) { + if (event->window != widget->window) + return FALSE; + ScintillaGTK *sciThis = ScintillaFromWidget(widget); + return sciThis->PressThis(event); +} + gint ScintillaGTK::MouseRelease(GtkWidget *widget, GdkEventButton *event) { ScintillaGTK *sciThis = ScintillaFromWidget(widget); //Platform::DebugPrintf("Release %x %d %d\n",sciThis,event->time,event->state); @@ -1170,7 +1159,7 @@ gint ScintillaGTK::ScrollEvent(GtkWidget *widget, sciThis->wheelMouseIntensity++; cLineScroll = sciThis->wheelMouseIntensity; } else { - cLineScroll = sciThis->ucWheelScrollLines; + cLineScroll = sciThis->linesPerScroll; if (cLineScroll == 0) cLineScroll = 4; sciThis->wheelMouseIntensity = cLineScroll; @@ -1420,7 +1409,7 @@ void ScintillaGTK::SelectionGet(GtkWidget *widget, GtkSelectionData *selection_data, guint info, guint) { ScintillaGTK *sciThis = ScintillaFromWidget(widget); //Platform::DebugPrintf("Selection get\n"); - sciThis->GetSelection(selection_data, info, sciThis->pasteBuffer, sciThis->pasteBufferIsRectangular); + sciThis->GetSelection(selection_data, info, &sciThis->copyText); } gint ScintillaGTK::SelectionClear(GtkWidget *widget, GdkEventSelection *selection_event) { @@ -1486,7 +1475,7 @@ void ScintillaGTK::DragDataGet(GtkWidget *widget, GdkDragContext *context, ScintillaGTK *sciThis = ScintillaFromWidget(widget); sciThis->dragWasDropped = true; if (sciThis->currentPos != sciThis->anchor) { - sciThis->GetSelection(selection_data, info, sciThis->dragChars, sciThis->dragIsRectangle); + sciThis->GetSelection(selection_data, info, &sciThis->drag); } if (context->action == GDK_ACTION_MOVE) { int selStart = sciThis->SelectionStart(); diff --git a/include/Scintilla.h b/include/Scintilla.h index 0185d3e5b..285f81a96 100644 --- a/include/Scintilla.h +++ b/include/Scintilla.h @@ -11,9 +11,6 @@ #ifndef SCINTILLA_H #define SCINTILLA_H -// Compile-time configuration options -#define MACRO_SUPPORT 1 // Comment out to remove macro hooks - #if PLAT_WIN #ifdef STATIC_BUILD void Scintilla_RegisterClasses(HINSTANCE hInstance); @@ -507,12 +504,6 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCN_DWELLEND 2017 //--Autogenerated -- end of section automatically generated from Scintilla.iface -// Optional module for macro recording -#ifdef MACRO_SUPPORT -typedef void (tMacroRecorder)(unsigned int iMessage, unsigned long wParam, - long lParam, void *userData); -#endif - // These structures are defined to be exactly the same shape as the Win32 // CHARRANGE, TEXTRANGE, FINDTEXTEX, FORMATRANGE, and NMHDR structs. // So older code that treats Scintilla as a RichEdit will work. @@ -566,11 +557,9 @@ struct SCNotification { const char *text; // SCN_MODIFIED int length; // SCN_MODIFIED int linesAdded; // SCN_MODIFIED -#ifdef MACRO_SUPPORT int message; // SCN_MACRORECORD uptr_t wParam; // SCN_MACRORECORD - sptr_t lParam; // SCN_MACRORECORD -#endif + sptr_t lParam; // SCN_MACRORECORD int line; // SCN_MODIFIED int foldLevelNow; // SCN_MODIFIED int foldLevelPrev; // SCN_MODIFIED diff --git a/src/Editor.cxx b/src/Editor.cxx index 346d1e1fd..73114f103 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -58,7 +58,6 @@ Editor::Editor() { dwelling = false; ptMouseLast.x = 0; ptMouseLast.y = 0; - firstExpose = true; inDragDrop = false; dropWentOutside = false; posDrag = invalidPosition; @@ -69,9 +68,6 @@ Editor::Editor() { lineAnchor = 0; originalAnchorPos = 0; - dragChars = 0; - lenDrag = 0; - dragIsRectangle = false; selType = selStream; xStartSelect = 0; xEndSelect = 0; @@ -111,15 +107,11 @@ Editor::Editor() { modEventMask = SC_MODEVENTMASKALL; - displayPopupMenu = true; - pdoc = new Document(); pdoc ->AddRef(); pdoc->AddWatcher(this, 0); -#ifdef MACRO_SUPPORT - recordingMacro = 0; -#endif + recordingMacro = false; foldFlags = 0; } @@ -128,10 +120,6 @@ Editor::~Editor() { pdoc->Release(); pdoc = 0; DropGraphics(); - - delete []dragChars; - dragChars = 0; - lenDrag = 0; } void Editor::Finalise() { @@ -1914,14 +1902,12 @@ void Editor::NotifyChar(int ch) { scn.nmhdr.code = SCN_CHARADDED; scn.ch = ch; NotifyParent(scn); -#ifdef MACRO_SUPPORT if (recordingMacro) { char txt[2]; txt[0] = static_cast<char>(ch); txt[1] = '\0'; NotifyMacroRecord(SCI_REPLACESEL, 0, reinterpret_cast<long>(txt)); } -#endif } void Editor::NotifySavePoint(bool isSavePoint) { @@ -2147,7 +2133,6 @@ void Editor::NotifyDeleted(Document *, void *) { /* Do nothing */ } -#ifdef MACRO_SUPPORT void Editor::NotifyMacroRecord(unsigned int iMessage, unsigned long wParam, long lParam) { // Enumerates all macroable messages @@ -2233,7 +2218,6 @@ void Editor::NotifyMacroRecord(unsigned int iMessage, unsigned long wParam, long scn.lParam = lParam; NotifyParent(scn); } -#endif // Force scroll and keep position relative to top of window void Editor::PageMove(int direction, bool extend) { @@ -2797,33 +2781,23 @@ char *Editor::CopyRange(int start, int end) { return text; } -int Editor::SelectionRangeLength() { +void Editor::CopySelectionRange(SelectionText *ss) { + char *text = 0; + int size = 0; if (selType == selRectangle) { int lineStart = pdoc->LineFromPosition(SelectionStart()); int lineEnd = pdoc->LineFromPosition(SelectionEnd()); - int totalSize = 0; - for (int line = lineStart; line <= lineEnd; line++) { - totalSize += SelectionEnd(line) - SelectionStart(line) + 1; + int line; + for (line = lineStart; line <= lineEnd; line++) { + size += SelectionEnd(line) - SelectionStart(line) + 1; if (pdoc->eolMode == SC_EOL_CRLF) - totalSize++; + size++; } - return totalSize; - } else { - return SelectionEnd() - SelectionStart(); - } -} - -char *Editor::CopySelectionRange() { - if (selType == selRectangle) { - char *text = 0; - int lineStart = pdoc->LineFromPosition(SelectionStart()); - int lineEnd = pdoc->LineFromPosition(SelectionEnd()); - int totalSize = SelectionRangeLength(); - if (totalSize > 0) { - text = new char[totalSize + 1]; + if (size > 0) { + text = new char[size + 1]; if (text) { int j = 0; - for (int line = lineStart; line <= lineEnd; line++) { + for (line = lineStart; line <= lineEnd; line++) { for (int i = SelectionStart(line);i < SelectionEnd(line);i++) { text[j++] = pdoc->CharAt(i); } @@ -2832,24 +2806,14 @@ char *Editor::CopySelectionRange() { if (pdoc->eolMode != SC_EOL_CR) text[j++] = '\n'; } - text[totalSize] = '\0'; + text[size] = '\0'; } } - return text; } else { - return CopyRange(SelectionStart(), SelectionEnd()); - } -} - -void Editor::CopySelectionIntoDrag() { - delete []dragChars; - dragChars = 0; - lenDrag = SelectionRangeLength(); - dragChars = CopySelectionRange(); - dragIsRectangle = selType == selRectangle; - if (!dragChars) { - lenDrag = 0; + size = SelectionEnd() - SelectionStart(); + text = CopyRange(SelectionStart(), SelectionEnd()); } + ss->Set(text, size, selType == selRectangle); } void Editor::SetDragPosition(int newPos) { @@ -2879,8 +2843,6 @@ void Editor::StartDrag() { //DisplayCursor(Window::cursorArrow); } - - void Editor::DropAt(int position, const char *value, bool moving, bool rectangular) { //Platform::DebugPrintf("DropAt %d\n", inDragDrop); if (inDragDrop) @@ -3112,7 +3074,7 @@ void Editor::ButtonDown(Point pt, unsigned int curTime, bool shift, bool ctrl, b if (inDragDrop) { SetMouseCapture(false); SetDragPosition(newPos); - CopySelectionIntoDrag(); + CopySelectionRange(&drag); StartDrag(); } else { xStartSelect = pt.x - vs.fixedColumnWidth + xOffset; @@ -3217,25 +3179,23 @@ void Editor::ButtonUp(Point pt, unsigned int curTime, bool ctrl) { int selStart = SelectionStart(); int selEnd = SelectionEnd(); if (selStart < selEnd) { - if (dragChars && lenDrag) { + if (drag.len) { if (ctrl) { - pdoc->InsertString(newPos, dragChars, lenDrag); - SetSelection(newPos, newPos + lenDrag); + pdoc->InsertString(newPos, drag.s, drag.len); + SetSelection(newPos, newPos + drag.len); } else if (newPos < selStart) { - pdoc->DeleteChars(selStart, lenDrag); - pdoc->InsertString(newPos, dragChars, lenDrag); - SetSelection(newPos, newPos + lenDrag); + pdoc->DeleteChars(selStart, drag.len); + pdoc->InsertString(newPos, drag.s, drag.len); + SetSelection(newPos, newPos + drag.len); } else if (newPos > selEnd) { - pdoc->DeleteChars(selStart, lenDrag); - newPos -= lenDrag; - pdoc->InsertString(newPos, dragChars, lenDrag); - SetSelection(newPos, newPos + lenDrag); + pdoc->DeleteChars(selStart, drag.len); + newPos -= drag.len; + pdoc->InsertString(newPos, drag.s, drag.len); + SetSelection(newPos, newPos + drag.len); } else { SetEmptySelection(newPos); } - delete []dragChars; - dragChars = 0; - lenDrag = 0; + drag.Set(0, 0); } selectionType = selChar; } @@ -3542,10 +3502,8 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { //Platform::DebugPrintf("S start wnd proc %d %d %d\n",iMessage, wParam, lParam); // Optional macro recording hook -#ifdef MACRO_SUPPORT if (recordingMacro) NotifyMacroRecord(iMessage, wParam, lParam); -#endif switch (iMessage) { @@ -3777,15 +3735,14 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { case SCI_GETSELTEXT: { if (lParam == 0) return 0; + SelectionText selectedText; + CopySelectionRange(&selectedText); char *ptr = reinterpret_cast<char *>(lParam); - int selSize = SelectionRangeLength(); - char *text = CopySelectionRange(); int iChar = 0; - if (text) { - for (; iChar < selSize; iChar++) - ptr[iChar] = text[iChar]; + if (selectedText.len) { + for (; iChar < selectedText.len; iChar++) + ptr[iChar] = selectedText.s[iChar]; ptr[iChar] = '\0'; - delete []text; } else { ptr[0] = '\0'; } @@ -4664,10 +4621,6 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { case SCI_LINESONSCREEN: return LinesOnScreen(); - case SCI_USEPOPUP: - displayPopupMenu = wParam; - break; - case SCI_SETSELFORE: vs.selforeset = wParam; vs.selforeground.desired = Colour(lParam); @@ -4912,15 +4865,13 @@ sptr_t Editor::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) { case SCI_GETCURSOR: return cursorMode; -#ifdef MACRO_SUPPORT case SCI_STARTRECORD: - recordingMacro = 1; + recordingMacro = true; return 0; case SCI_STOPRECORD: - recordingMacro = 0; + recordingMacro = false; return 0; -#endif case SCI_MOVECARETINSIDEVIEW: MoveCaretInsideView(); diff --git a/src/Editor.h b/src/Editor.h index 1c1a13660..658161088 100644 --- a/src/Editor.h +++ b/src/Editor.h @@ -50,6 +50,26 @@ public: int positions[maxLineLength+1]; }; +class SelectionText { +public: + char *s; + int len; + bool rectangular; + SelectionText() : s(0), len(0), rectangular(false) {} + ~SelectionText() { + Set(0, 0); + } + void Set(char *s_, int len_, bool rectangular_=false) { + delete []s; + s = s_; + if (s) + len = len_; + else + len = 0; + rectangular = rectangular_; + } +}; + /** */ class Editor : public DocWatcher { @@ -68,6 +88,7 @@ protected: // ScintillaBase subclass needs access to much of Editor bool stylesValid; ViewStyle vs; Palette palette; + int printMagnification; int printColourMode; int cursorMode; @@ -106,7 +127,6 @@ protected: // ScintillaBase subclass needs access to much of Editor bool dwelling; enum { selChar, selWord, selLine } selectionType; Point ptMouseLast; - bool firstExpose; bool inDragDrop; bool dropWentOutside; int posDrag; @@ -135,9 +155,7 @@ protected: // ScintillaBase subclass needs access to much of Editor int modEventMask; - char *dragChars; - int lenDrag; - bool dragIsRectangle; + SelectionText drag; enum { selStream, selRectangle, selRectangleFixed } selType; int xStartSelect; int xEndSelect; @@ -151,11 +169,7 @@ protected: // ScintillaBase subclass needs access to much of Editor int searchAnchor; - int displayPopupMenu; - -#ifdef MACRO_SUPPORT - int recordingMacro; -#endif + bool recordingMacro; int foldFlags; ContractionState cs; @@ -267,11 +281,7 @@ protected: // ScintillaBase subclass needs access to much of Editor void NotifyModified(Document *document, DocModification mh, void *userData); void NotifyDeleted(Document *document, void *userData); void NotifyStyleNeeded(Document *doc, void *userData, int endPos); - - -#ifdef MACRO_SUPPORT void NotifyMacroRecord(unsigned int iMessage, unsigned long wParam, long lParam); -#endif void PageMove(int direction, bool extend=false); void ChangeCaseOfSelection(bool makeUpperCase); @@ -293,9 +303,7 @@ protected: // ScintillaBase subclass needs access to much of Editor void GoToLine(int lineNo); char *CopyRange(int start, int end); - int SelectionRangeLength(); - char *CopySelectionRange(); - void CopySelectionIntoDrag(); + void CopySelectionRange(SelectionText *ss); void SetDragPosition(int newPos); void DisplayCursor(Window::Cursor c); virtual void StartDrag(); diff --git a/src/ScintillaBase.cxx b/src/ScintillaBase.cxx index 707f59b9f..75a8ffffa 100644 --- a/src/ScintillaBase.cxx +++ b/src/ScintillaBase.cxx @@ -35,6 +35,7 @@ #include "ScintillaBase.h" ScintillaBase::ScintillaBase() { + displayPopupMenu = true; listType = 0; #ifdef SCI_LEXER lexLanguage = SCLEX_CONTAINER; @@ -514,6 +515,10 @@ sptr_t ScintillaBase::WndProc(unsigned int iMessage, uptr_t wParam, sptr_t lPara InvalidateStyleRedraw(); break; + case SCI_USEPOPUP: + displayPopupMenu = wParam; + break; + #ifdef SCI_LEXER case SCI_SETLEXER: SetLexer(wParam); diff --git a/src/ScintillaBase.h b/src/ScintillaBase.h index d5b1e8ba0..acf70e000 100644 --- a/src/ScintillaBase.h +++ b/src/ScintillaBase.h @@ -30,6 +30,7 @@ protected: idcmdSelectAll=16 }; + bool displayPopupMenu; Menu popup; AutoComplete ac; diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index de1e8fc34..a26dcb9fd 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -231,7 +231,7 @@ public: friend class DataObject; friend class DropTarget; bool DragIsRectangularOK(CLIPFORMAT fmt) { - return dragIsRectangle && (fmt == cfColumnSelect); + return drag.rectangular && (fmt == cfColumnSelect); } }; @@ -1320,34 +1320,33 @@ void ScintillaWin::GetIntelliMouseParameters() { } void ScintillaWin::CopySelTextToClipboard() { - int bytes = SelectionRangeLength(); - char *selChars = CopySelectionRange(); - if (!selChars) + SelectionText selectedText; + CopySelectionRange(&selectedText); + if (selectedText.len == 0) return; HGLOBAL hand = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, - bytes + 1); + selectedText.len + 1); if (hand) { char *ptr = static_cast<char *>(::GlobalLock(hand)); - memcpy(ptr, selChars, bytes); - ptr[bytes] = '\0'; + memcpy(ptr, selectedText.s, selectedText.len); + ptr[selectedText.len] = '\0'; ::GlobalUnlock(hand); } ::SetClipboardData(CF_TEXT, hand); if (IsUnicodeMode()) { - int uchars = UCS2Length(selChars, bytes); + int uchars = UCS2Length(selectedText.s, selectedText.len); HGLOBAL uhand = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, 2 * (uchars + 1)); if (uhand) { wchar_t *uptr = static_cast<wchar_t *>(::GlobalLock(uhand)); - UCS2FromUTF8(selChars, bytes, uptr, uchars); + UCS2FromUTF8(selectedText.s, selectedText.len, uptr, uchars); uptr[uchars] = 0; ::GlobalUnlock(uhand); } ::SetClipboardData(CF_UNICODETEXT, uhand); } - delete []selChars; } void ScintillaWin::ScrollMessage(WPARAM wParam) { @@ -1627,21 +1626,21 @@ STDMETHODIMP ScintillaWin::GetData(FORMATETC *pFEIn, STGMEDIUM *pSTM) { HGLOBAL hand; if (pFEIn->cfFormat == CF_UNICODETEXT) { - int uchars = UCS2Length(dragChars, lenDrag); + int uchars = UCS2Length(drag.s, drag.len); hand = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, 2 * (uchars + 1)); if (hand) { wchar_t *uptr = static_cast<wchar_t *>(::GlobalLock(hand)); - UCS2FromUTF8(dragChars, lenDrag, uptr, uchars); + UCS2FromUTF8(drag.s, drag.len, uptr, uchars); uptr[uchars] = 0; } } else { - hand = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, lenDrag + 1); + hand = ::GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, drag.len + 1); if (hand) { char *ptr = static_cast<char *>(::GlobalLock(hand)); - for (int i = 0; i < lenDrag; i++) { - ptr[i] = dragChars[i]; + for (int i = 0; i < drag.len; i++) { + ptr[i] = drag.s[i]; } - ptr[lenDrag] = '\0'; + ptr[drag.len] = '\0'; } } ::GlobalUnlock(hand); |