summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Fl_Tree.cxx19
-rw-r--r--src/Fl_Tree_Item.cxx25
2 files changed, 36 insertions, 8 deletions
diff --git a/src/Fl_Tree.cxx b/src/Fl_Tree.cxx
index cb6d2e774..aa99e737d 100644
--- a/src/Fl_Tree.cxx
+++ b/src/Fl_Tree.cxx
@@ -219,7 +219,7 @@ int Fl_Tree::extend_selection(Fl_Tree_Item *from, Fl_Tree_Item *to,
return(changed);
}
-enum { PushedNothing=0, PushedOpenClose, PushedItem };
+enum { PUSHED_NONE=0, PUSHED_OPEN_CLOSE, PUSHED_USER_ICON, PUSHED_LABEL };
/// Standard FLTK event handler for this widget.
/// \todo add Fl_Widget_Tracker (see Fl_Browser_.cxx::handle())
int Fl_Tree::handle(int e) {
@@ -386,9 +386,10 @@ int Fl_Tree::handle(int e) {
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
+ _lastpushed = item ? item->event_on_collapse_icon(_prefs) ? PUSHED_OPEN_CLOSE // open/close icon clicked
+ : item->event_on_user_icon(_prefs) ? PUSHED_USER_ICON // usericon clicked
+ : PUSHED_LABEL // label clicked
+ : PUSHED_NONE; // none of the above
if ( !item ) { // clicked, but not on an item?
_lastselect = 0;
switch ( _prefs.selectmode() ) {
@@ -407,8 +408,7 @@ int Fl_Tree::handle(int e) {
if ( Fl::event_button() == FL_LEFT_MOUSE ) {
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
+ } else if ( !item->widget() || !Fl::event_inside(item->widget()) ) { // not inside widget()
switch ( _prefs.selectmode() ) {
case FL_TREE_SELECT_NONE:
break;
@@ -440,8 +440,11 @@ int Fl_Tree::handle(int e) {
break;
}
case FL_DRAG: {
- // FL_PUSH not on item? Ignore drag to prevent unexpected selections (STR #3527)
- if ( _lastpushed != PushedItem ) return 0;
+ // FL_PUSH outside item or on open/close?
+ // Ignore drag to prevent unexpected selections (STR #3527)
+ //
+ if ( _lastpushed == PUSHED_NONE ||
+ _lastpushed == PUSHED_OPEN_CLOSE ) return 0;
// Do scrolling first
diff --git a/src/Fl_Tree_Item.cxx b/src/Fl_Tree_Item.cxx
index d78c3427c..e6819a8ef 100644
--- a/src/Fl_Tree_Item.cxx
+++ b/src/Fl_Tree_Item.cxx
@@ -1190,6 +1190,31 @@ int Fl_Tree_Item::event_on_collapse_icon(const Fl_Tree_Prefs &prefs) const {
}
}
+/// Was the event on the 'user icon' of this item, if any?
+///
+int Fl_Tree_Item::event_on_user_icon(const Fl_Tree_Prefs &prefs) const {
+ // NOTE: Fl_Tree_Item doesn't keep an _xywh[] for usericon, but we can derive it as
+ // by elimitation of all other possibilities.
+ if ( !is_visible() ) return 0; // item not visible? not us
+ if ( !event_inside(_xywh) ) return 0; // not inside item? not us
+ if ( event_on_collapse_icon(prefs) ) return 0; // inside collapse icon? not us
+ if ( Fl::event_x() >= _label_xywh[0] ) return 0; // inside label or beyond (e.g. widget())? not us
+ // Is a user icon being shown?
+ // TBD: Determining usericon xywh and 'if displayed' should be class methods used here and by draw_*()
+ Fl_Image *ui = 0;
+ if ( is_active() ) {
+ if ( usericon() ) ui = usericon(); // user icon for item?
+ else if ( prefs.usericon() ) ui = prefs.usericon(); // user icon for tree?
+ } else {
+ if ( userdeicon() ) ui = userdeicon(); // user deicon for this item?
+ else if ( prefs.userdeicon() ) ui = prefs.userdeicon(); // user deicon for tree?
+ }
+ if ( !ui ) return 0; // no user icon? not us
+ int uix = _label_xywh[0]-ui->w(); // find x position of usericon
+ if ( Fl::event_x() < uix ) return 0; // event left of usericon? not us
+ return 1; // must be inside usericon by elimination
+}
+
/// Was event on the label() of this item?
///
int Fl_Tree_Item::event_on_label(const Fl_Tree_Prefs &prefs) const {