From d4859abe669db503303685dbcd30782d826c8f8b Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Mon, 20 Jul 2020 13:45:16 +0200 Subject: [PATCH] Fix DND in read-only Fl_Input (Fl_Output) (#113) Cherry-picking fix from FLTK 1.4 (master). See report in fltk.coredev as of Jan 16, 2020: "Fl_Input in readonly mode - wrong behaviour". Summary: Drag and drop within a read-only Fl_Input (i.e. Fl_Output) widget would not insert the dragged text (correct) but removed the dragged text from the widget (error). This is now fixed. --- src/Fl_Input.cxx | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/Fl_Input.cxx b/src/Fl_Input.cxx index 17e978a74..00fdbbccb 100644 --- a/src/Fl_Input.cxx +++ b/src/Fl_Input.cxx @@ -3,17 +3,17 @@ // // Input widget for the Fast Light Tool Kit (FLTK). // -// Copyright 1998-2016 by Bill Spitzak and others. +// Copyright 1998-2020 by Bill Spitzak and others. // // This library is free software. Distribution and use rights are outlined in // the file "COPYING" which should have been included with this file. If this // file is missing or damaged, see the license at: // -// http://www.fltk.org/COPYING.php +// https://www.fltk.org/COPYING.php // // Please report all bugs and problems on the following page: // -// http://www.fltk.org/str.php +// https://www.fltk.org/bugs.php // // This is the "user interface", it decodes user actions into what to @@ -29,7 +29,7 @@ #include #include #include -#include "flstring.h" +#include "flstring.h" // this #includes "" ! #include #include @@ -751,27 +751,31 @@ int Fl_Input::handle(int event) { #endif dnd_save_focus = NULL; return 1; - + case FL_DND_RELEASE: if (dnd_save_focus == this) { // if the dragged text comes from the same widget - // remove the selected text - int old_position = position(); - if (dnd_save_mark > dnd_save_position) { - int tmp = dnd_save_mark; - dnd_save_mark = dnd_save_position; - dnd_save_position = tmp; + if (!readonly()) { + // remove the selected text + int old_position = position(); + if (dnd_save_mark > dnd_save_position) { + int tmp = dnd_save_mark; + dnd_save_mark = dnd_save_position; + dnd_save_position = tmp; } - replace(dnd_save_mark, dnd_save_position, NULL, 0); - if (old_position > dnd_save_position) position(old_position - (dnd_save_position - dnd_save_mark)); - else position(old_position); - } - else if(dnd_save_focus) { + replace(dnd_save_mark, dnd_save_position, NULL, 0); + if (old_position > dnd_save_position) + position(old_position - (dnd_save_position - dnd_save_mark)); + else + position(old_position); + } // !readonly() + } // from the same widget + else if (dnd_save_focus) { dnd_save_focus->handle(FL_UNFOCUS); - } + } dnd_save_focus = NULL; take_focus(); return 1; - + /* TODO: this will scroll the area, but stop if the cursor would become invisible. That clipping happens in drawtext(). Do we change the clipping or should we move the cursor (ouch)?