summaryrefslogtreecommitdiff
path: root/src/Fl_Tree.cxx
diff options
context:
space:
mode:
authorGreg Ercolano <erco@seriss.com>2010-11-25 18:52:37 +0000
committerGreg Ercolano <erco@seriss.com>2010-11-25 18:52:37 +0000
commitd3e0d030f0646f1b67f2850520b95d76958fab64 (patch)
tree0aa555146e6e03c08621111e52db7b3b14760599 /src/Fl_Tree.cxx
parent7eb27fa4bd313e4c9f83df5aa8b774f54a7aaca2 (diff)
Changes to solve STR#2426;
1) Hitting ENTER to select an item should make sure the item is displayed if off-screen (Mayank Malik, pointing out similar behavior in Fl_Browser_) 2) show_item() without a positional argument will invoke show_item_top() if the item is off-screen. 3) Added new method displayed() (to match Fl_Browser_'s) git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7893 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_Tree.cxx')
-rw-r--r--src/Fl_Tree.cxx22
1 files changed, 22 insertions, 0 deletions
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();