From 3e4baae6fcb40c3a377c170af2f7698e18dc03e4 Mon Sep 17 00:00:00 2001 From: Albrecht Schlosser Date: Thu, 16 Jan 2020 17:11:32 +0100 Subject: Fix DND in read-only Fl_Input (Fl_Output) See report in fltk.coredev as of today (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(-) (limited to 'src/Fl_Input.cxx') diff --git a/src/Fl_Input.cxx b/src/Fl_Input.cxx index a6a7b53b8..96dfc0105 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-2018 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/str.php // // This is the "user interface", it decodes user actions into what to @@ -32,7 +32,7 @@ #include #include #include -#include "flstring.h" +#include "flstring.h" // this #includes "" ! #include #include @@ -613,27 +613,31 @@ int Fl_Input::handle(int event) { Fl::first_window()->cursor(FL_CURSOR_MOVE); 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)? -- cgit v1.2.3