Author: greg.ercolano
Date: 2010-11-25 10:52:37 -0800 (Thu, 25 Nov 2010)
New Revision: 7893
Log:
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)
Modified:
branches/branch-1.3/FL/Fl_Tree.H
branches/branch-1.3/src/Fl_Tree.cxx
branches/branch-1.3/test/tree.fl
Modified: branches/branch-1.3/FL/Fl_Tree.H
===================================================================
--- branches/branch-1.3/FL/Fl_Tree.H 2010-11-25 18:21:21 UTC (rev 7892)
+++ branches/branch-1.3/FL/Fl_Tree.H 2010-11-25 18:52:37 UTC (rev 7893)
@@ -803,7 +803,9 @@
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);
Modified: branches/branch-1.3/src/Fl_Tree.cxx
===================================================================
--- branches/branch-1.3/src/Fl_Tree.cxx 2010-11-25 18:21:21 UTC (rev 7892)
+++ branches/branch-1.3/src/Fl_Tree.cxx 2010-11-25 18:52:37 UTC (rev 7893)
@@ -520,6 +520,7 @@
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 @@
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();
Modified: branches/branch-1.3/test/tree.fl
===================================================================
--- branches/branch-1.3/test/tree.fl 2010-11-25 18:21:21 UTC (rev 7892)
+++ branches/branch-1.3/test/tree.fl 2010-11-25 18:52:37 UTC (rev 7893)
@@ -142,7 +142,7 @@
} {
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 @@
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 @@
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);} {}
}
_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit