mirror of
https://github.com/fltk/fltk.git
synced 2026-06-04 15:32:12 +08:00
Fl_Browser_::display() speedup patch from Stephen Davies.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@2540 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
CHANGES IN FLTK 1.1.0
|
CHANGES IN FLTK 1.1.0
|
||||||
|
|
||||||
|
- Improved speed of Fl_Browser_::display() method with
|
||||||
|
large lists (patch from Stephen Davies.)
|
||||||
- Fl_Help_View didn't properly handle NULL from the link
|
- Fl_Help_View didn't properly handle NULL from the link
|
||||||
callback (the original filename/directory name were
|
callback (the original filename/directory name were
|
||||||
not preserved...)
|
not preserved...)
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ OTHER CONTRIBUTORS
|
|||||||
|
|
||||||
Teun Burgers
|
Teun Burgers
|
||||||
Fabien Costantini
|
Fabien Costantini
|
||||||
|
Stephen Davies
|
||||||
Greg Ercolano
|
Greg Ercolano
|
||||||
Stuart Levy
|
Stuart Levy
|
||||||
Mike Lindner
|
Mike Lindner
|
||||||
|
|||||||
+52
-8
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// "$Id: Fl_Browser_.cxx,v 1.10.2.16.2.12 2002/06/27 20:52:44 easysw Exp $"
|
// "$Id: Fl_Browser_.cxx,v 1.10.2.16.2.13 2002/07/18 15:43:48 easysw Exp $"
|
||||||
//
|
//
|
||||||
// Base Browser widget class for the Fast Light Tool Kit (FLTK).
|
// Base Browser widget class for the Fast Light Tool Kit (FLTK).
|
||||||
//
|
//
|
||||||
@@ -23,6 +23,8 @@
|
|||||||
// Please report all bugs and problems to "fltk-bugs@fltk.org".
|
// Please report all bugs and problems to "fltk-bugs@fltk.org".
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#define DISPLAY_SEARCH_BOTH_WAYS_AT_ONCE
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <FL/Fl.H>
|
#include <FL/Fl.H>
|
||||||
#include <FL/Fl_Widget.H>
|
#include <FL/Fl_Widget.H>
|
||||||
@@ -192,21 +194,62 @@ int Fl_Browser_::displayed(void* x) const {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insure this item is displayed:
|
// Ensure this item is displayed:
|
||||||
// Messy because we have no idea if it is before top or after bottom:
|
// Messy because we have no idea if it is before top or after bottom:
|
||||||
void Fl_Browser_::display(void* x) {
|
void Fl_Browser_::display(void* x) {
|
||||||
|
|
||||||
|
// First special case - want to display first item in the list?
|
||||||
update_top();
|
update_top();
|
||||||
if (x == item_first()) {position(0); return;}
|
if (x == item_first()) {position(0); return;}
|
||||||
int X, Y, W, H; bbox(X, Y, W, H);
|
|
||||||
|
int X, Y, W, H, Yp; bbox(X, Y, W, H);
|
||||||
void* l = top_;
|
void* l = top_;
|
||||||
Y = -offset_;
|
Y = Yp = -offset_;
|
||||||
// see if it is at the top or just above it:
|
int h1;
|
||||||
|
|
||||||
|
// 2nd special case - want to display item already displayed at top of browser?
|
||||||
if (l == x) {position(real_position_+Y); return;} // scroll up a bit
|
if (l == x) {position(real_position_+Y); return;} // scroll up a bit
|
||||||
|
|
||||||
|
// 3rd special case - want to display item just above top of browser?
|
||||||
void* lp = item_prev(l);
|
void* lp = item_prev(l);
|
||||||
if (lp == x) {position(real_position_+Y-item_quick_height(lp)); return;}
|
if (lp == x) {position(real_position_+Y-item_quick_height(lp)); return;}
|
||||||
|
|
||||||
|
#ifdef DISPLAY_SEARCH_BOTH_WAYS_AT_ONCE
|
||||||
|
// search for item. We search both up and down the list at the same time,
|
||||||
|
// this evens up the execution time for the two cases - the old way was
|
||||||
|
// much slower for going up than for going down.
|
||||||
|
while (l || lp) {
|
||||||
|
if (l) {
|
||||||
|
h1 = item_quick_height(l);
|
||||||
|
if (l == x) {
|
||||||
|
if (Y <= H) { // it is visible or right at bottom
|
||||||
|
Y = Y+h1-H; // find where bottom edge is
|
||||||
|
if (Y > 0) position(real_position_+Y); // scroll down a bit
|
||||||
|
} else {
|
||||||
|
position(real_position_+Y-(H-h1)/2); // center it
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Y += h1;
|
||||||
|
l = item_next(l);
|
||||||
|
}
|
||||||
|
if (lp) {
|
||||||
|
h1 = item_quick_height(lp);
|
||||||
|
Yp -= h1;
|
||||||
|
if (lp == x) {
|
||||||
|
if ((Yp + h1) >= 0) position(real_position_+Yp);
|
||||||
|
else position(real_position_+Yp-(H-h1)/2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lp = item_prev(lp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
// Old version went forwards and then backwards:
|
||||||
// search forward for it:
|
// search forward for it:
|
||||||
|
l = top_;
|
||||||
for (; l; l = item_next(l)) {
|
for (; l; l = item_next(l)) {
|
||||||
int h1 = item_quick_height(l);
|
h1 = item_quick_height(l);
|
||||||
if (l == x) {
|
if (l == x) {
|
||||||
if (Y <= H) { // it is visible or right at bottom
|
if (Y <= H) { // it is visible or right at bottom
|
||||||
Y = Y+h1-H; // find where bottom edge is
|
Y = Y+h1-H; // find where bottom edge is
|
||||||
@@ -222,7 +265,7 @@ void Fl_Browser_::display(void* x) {
|
|||||||
l = lp;
|
l = lp;
|
||||||
Y = -offset_;
|
Y = -offset_;
|
||||||
for (; l; l = item_prev(l)) {
|
for (; l; l = item_prev(l)) {
|
||||||
int h1 = item_quick_height(l);
|
h1 = item_quick_height(l);
|
||||||
Y -= h1;
|
Y -= h1;
|
||||||
if (l == x) {
|
if (l == x) {
|
||||||
if ((Y + h1) >= 0) position(real_position_+Y);
|
if ((Y + h1) >= 0) position(real_position_+Y);
|
||||||
@@ -230,6 +273,7 @@ void Fl_Browser_::display(void* x) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// redraw, has side effect of updating top and setting scrollbar:
|
// redraw, has side effect of updating top and setting scrollbar:
|
||||||
@@ -711,5 +755,5 @@ void Fl_Browser_::item_select(void*, int) {}
|
|||||||
int Fl_Browser_::item_selected(void* l) const {return l==selection_;}
|
int Fl_Browser_::item_selected(void* l) const {return l==selection_;}
|
||||||
|
|
||||||
//
|
//
|
||||||
// End of "$Id: Fl_Browser_.cxx,v 1.10.2.16.2.12 2002/06/27 20:52:44 easysw Exp $".
|
// End of "$Id: Fl_Browser_.cxx,v 1.10.2.16.2.13 2002/07/18 15:43:48 easysw Exp $".
|
||||||
//
|
//
|
||||||
|
|||||||
Reference in New Issue
Block a user