diff options
| author | Manolo Gouy <Manolo> | 2013-12-13 16:28:38 +0000 |
|---|---|---|
| committer | Manolo Gouy <Manolo> | 2013-12-13 16:28:38 +0000 |
| commit | 34c69d3922fec8be57b2cd5aaededfc2a0828f23 (patch) | |
| tree | c41b2deba23256100c0da2ffb5fda40d69d8233c | |
| parent | f7e88141c3db591149d4d569e6852843b61d9c92 (diff) | |
Fix for STR#3016: Fl_Input and Fl_Text_Editor have now the standard behavior when doing
drag-n-drop of text: if the dragged text is dropped in the widget it comes from, it's cut and pasted.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10031 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
| -rw-r--r-- | src/Fl_Input.cxx | 28 | ||||
| -rw-r--r-- | src/Fl_Text_Editor.cxx | 2 |
2 files changed, 24 insertions, 6 deletions
diff --git a/src/Fl_Input.cxx b/src/Fl_Input.cxx index 30231be5c..9dcc0eed8 100644 --- a/src/Fl_Input.cxx +++ b/src/Fl_Input.cxx @@ -588,7 +588,7 @@ int Fl_Input::handle_key() { int Fl_Input::handle(int event) { static int dnd_save_position, dnd_save_mark, drag_start = -1, newpos; - static Fl_Widget *dnd_save_focus; + static Fl_Widget *dnd_save_focus = NULL; switch (event) { #ifdef __APPLE__ case FL_UNFOCUS: @@ -676,6 +676,7 @@ int Fl_Input::handle(int event) { // save the position because sometimes we don't get DND_ENTER: dnd_save_position = position(); dnd_save_mark = mark(); + dnd_save_focus = this; // drag the data: copy(0); Fl::dnd(); return 1; @@ -707,10 +708,10 @@ int Fl_Input::handle(int event) { case FL_DND_ENTER: Fl::belowmouse(this); // send the leave events first - dnd_save_position = position(); - dnd_save_mark = mark(); - dnd_save_focus = Fl::focus(); if (dnd_save_focus != this) { + dnd_save_position = position(); + dnd_save_mark = mark(); + dnd_save_focus = Fl::focus(); Fl::focus(this); handle(FL_FOCUS); } @@ -736,16 +737,33 @@ int Fl_Input::handle(int event) { #if DND_OUT_XXXX if (!focused()) #endif - if (dnd_save_focus != this) { + if (dnd_save_focus && dnd_save_focus != this) { Fl::focus(dnd_save_focus); handle(FL_UNFOCUS); } #if !(defined(__APPLE__) || defined(WIN32)) Fl::first_window()->cursor(FL_CURSOR_MOVE); #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; + } + 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) { + dnd_save_focus->handle(FL_UNFOCUS); + } + dnd_save_focus = NULL; take_focus(); return 1; diff --git a/src/Fl_Text_Editor.cxx b/src/Fl_Text_Editor.cxx index 03e4b22bd..2854bfa88 100644 --- a/src/Fl_Text_Editor.cxx +++ b/src/Fl_Text_Editor.cxx @@ -646,7 +646,7 @@ int Fl_Text_Editor::handle(int event) { insert_position(dndCursorPos); return 1; case FL_DND_RELEASE: // keep insertion cursor and wait for the FL_PASTE event - buffer()->unselect(); // FL_PASTE must not destroy current selection! + if (!dragging) buffer()->unselect(); // FL_PASTE must not destroy current selection if drag comes from outside return 1; } |
