summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--FL/Fl_Tree.H4
-rw-r--r--src/Fl_Tree.cxx22
-rw-r--r--test/tree.fl30
3 files changed, 45 insertions, 11 deletions
diff --git a/FL/Fl_Tree.H b/FL/Fl_Tree.H
index c0d2b55ba..85ab27aa7 100644
--- a/FL/Fl_Tree.H
+++ b/FL/Fl_Tree.H
@@ -803,7 +803,9 @@ public:
void selectmode(Fl_Tree_Select val) {
_prefs.selectmode(val);
}
- void show_item(Fl_Tree_Item *item, int yoff=0);
+ int displayed(Fl_Tree_Item *item);
+ void show_item(Fl_Tree_Item *item, int yoff);
+ void show_item(Fl_Tree_Item *item);
void show_item_bottom(Fl_Tree_Item *item);
void show_item_middle(Fl_Tree_Item *item);
void show_item_top(Fl_Tree_Item *item);
diff --git a/src/Fl_Tree.cxx b/src/Fl_Tree.cxx
index 7704de04d..7b8ffdc75 100644
--- a/src/Fl_Tree.cxx
+++ b/src/Fl_Tree.cxx
@@ -520,6 +520,7 @@ int Fl_Tree::handle(int e) {
case FL_KP_Enter:
if ( when() & ~FL_WHEN_ENTER_KEY) {
select_only(_item_focus);
+ show_item(_item_focus); // STR #2426
return(1);
}
break;
@@ -789,6 +790,27 @@ void Fl_Tree::show_item(Fl_Tree_Item *item, int yoff) {
redraw();
}
+/// See if \p item is currently displayed on-screen (visible within the widget).
+/// This can be used to detect if the item is scrolled off-screen.
+/// Checks to see if the item's vertical position is within the top and bottom
+/// edges of the display window. This does NOT take into account the hide()/show()
+/// status of the item.
+///
+int Fl_Tree::displayed(Fl_Tree_Item *item) {
+ return( (item->y() >= y() && item->y() <= (y()+h()-item->h())) ? 1 : 0);
+}
+
+/// Adjust the vertical scroll bar to show \p item at the top
+/// of the display IF it is currently off-screen (eg. show_item_top()).
+/// If it is already on-screen, no change is made.
+///
+/// \see show_item_top(), show_item_middle(), show_item_bottom()
+///
+void Fl_Tree::show_item(Fl_Tree_Item *item) {
+ if ( displayed(item) ) return;
+ show_item_top(item);
+}
+
/// Adjust the vertical scrollbar so that \p item is at the top of the display.
void Fl_Tree::show_item_top(Fl_Tree_Item *item) {
item = item ? item : first();
diff --git a/test/tree.fl b/test/tree.fl
index bb15058a5..a184e6c91 100644
--- a/test/tree.fl
+++ b/test/tree.fl
@@ -142,7 +142,7 @@ Function {} {open
} {
Fl_Window window {
label tree open
- xywh {1099 53 580 695} type Double visible
+ xywh {1153 115 580 695} type Double visible
} {
Fl_Group tree {
user_data 1234
@@ -538,38 +538,49 @@ switch ( whenmode_chooser->value() ) {
Fl_Box showitem_box {
label {show_item()
}
- xywh {468 423 60 77} box GTK_DOWN_BOX color 47 labelsize 11 align 1
+ xywh {480 425 70 82} box GTK_DOWN_BOX color 47 labelsize 11 align 1
+ }
+ Fl_Button {} {
+ label Show
+ callback {Fl_Tree_Item *item = tree->next_selected_item();
+tree->show_item(item);} selected
+ tooltip {Tests show_item() with no position specified.
+Makes the selected item visible IF it is off-screen.
+No change made if it is not off-screen.} xywh {495 434 40 17} labelsize 11
}
Fl_Button {} {
label Top
callback {Fl_Tree_Item *item = tree->next_selected_item();
tree->show_item_top(item);}
- tooltip {Scrolls selected item to the top of the display
+ tooltip {Test show_item_top().
+Scrolls selected item to the top of the display
(only works if scrollbar showing)
To use:
1) open '500 items'
2) select item 0010
-3) Hit Top/Mid/Bot} xywh {478 433 40 16} labelsize 11
+3) Hit Top/Mid/Bot} xywh {495 451 40 16} labelsize 11
}
Fl_Button {} {
label Mid
callback {Fl_Tree_Item *item = tree->next_selected_item();
tree->show_item_middle(item);}
- tooltip {Scrolls the selected item to the middle of the display
+ tooltip {Tests show_item_middle().
+Scrolls the selected item to the middle of the display
To use:
1) open '500 items'
2) select 'item 0010'
- 3) Hit Top/Mid/Bot} xywh {478 453 40 16} labelsize 11
+ 3) Hit Top/Mid/Bot} xywh {495 467 40 16} labelsize 11
}
Fl_Button {} {
label Bot
callback {Fl_Tree_Item *item = tree->next_selected_item();
tree->show_item_bottom(item);}
- tooltip {Scrolls the selected item to the bottom of the display
+ tooltip {Tests show_item_bottom().
+Scrolls the selected item to the bottom of the display
To use:
1) open '500 items'
2) select 'item 0010'
- 3) Hit Top/Mid/Bot} xywh {478 473 40 16} labelsize 11
+ 3) Hit Top/Mid/Bot} xywh {495 483 40 16} labelsize 11
}
Fl_Box docallback_box {
label {Selection State Changes}
@@ -848,6 +859,5 @@ window->size_range(window->w(), window->h(), 0, 0);
if ( tree->when() == FL_WHEN_CHANGED ) whenmode_chooser->value(0);
else if ( tree->when() == FL_WHEN_RELEASE ) whenmode_chooser->value(1);
-else if ( tree->when() == FL_WHEN_NEVER ) whenmode_chooser->value(2);} {selected
- }
+else if ( tree->when() == FL_WHEN_NEVER ) whenmode_chooser->value(2);} {}
}