Fixes STR #3527: Fl_Tree small drags on open/close icons change selection

This commit is contained in:
Greg Ercolano 2019-08-24 23:07:21 -07:00
parent 1b77967823
commit 521a5ef17c
2 changed files with 12 additions and 4 deletions

View File

@ -292,7 +292,8 @@ class FL_EXPORT Fl_Tree : public Fl_Group {
Fl_Tree_Reason _callback_reason; // reason for the callback
Fl_Tree_Prefs _prefs; // all the tree's settings
int _scrollbar_size; // size of scrollbar trough
Fl_Tree_Item *_lastselect;
Fl_Tree_Item *_lastselect; // last selected item
char _lastpushed; // entity FL_PUSH occurred on: 0=nothing, 1=open/close, 2=item
void fix_scrollbar_order();
protected:

View File

@ -219,7 +219,7 @@ int Fl_Tree::extend_selection(Fl_Tree_Item *from, Fl_Tree_Item *to,
return(changed);
}
enum { PushedNothing=0, PushedOpenClose, PushedItem };
/// Standard FLTK event handler for this widget.
/// \todo add Fl_Widget_Tracker (see Fl_Browser_.cxx::handle())
int Fl_Tree::handle(int e) {
@ -385,6 +385,10 @@ int Fl_Tree::handle(int e) {
last_my = Fl::event_y(); // save for dragging direction..
if (Fl::visible_focus() && handle(FL_FOCUS)) Fl::focus(this);
Fl_Tree_Item *item = _root->find_clicked(_prefs, 0);
// Tell FL_DRAG what was pushed
_lastpushed = item ? (item->event_on_collapse_icon(_prefs) ? PushedOpenClose // open/close icon clicked
: PushedItem) // item clicked
: PushedNothing; // none of the above
if ( !item ) { // clicked, but not on an item?
_lastselect = 0;
switch ( _prefs.selectmode() ) {
@ -404,7 +408,7 @@ int Fl_Tree::handle(int e) {
if ( item->event_on_collapse_icon(_prefs) ) { // collapse icon clicked?
open_toggle(item); // toggle open (handles redraw)
} else if ( item->event_on_label(_prefs) && // label clicked?
(!item->widget() || !Fl::event_inside(item->widget())) ) { // not inside widget
(!item->widget() || !Fl::event_inside(item->widget())) ) { // not inside widget
switch ( _prefs.selectmode() ) {
case FL_TREE_SELECT_NONE:
break;
@ -436,7 +440,10 @@ int Fl_Tree::handle(int e) {
break;
}
case FL_DRAG: {
// Do scrolling first..
// FL_PUSH not on item? Ignore drag to prevent unexpected selections (STR #3527)
if ( _lastpushed != PushedItem ) return 0;
// Do scrolling first
// Detect up/down dragging
int my = Fl::event_y();