Project

General

Profile

Bug #6774 » issue_6774.patch

Roel Standaert, 02/03/2020 06:20 PM

View differences:

src/Wt/WTreeView.C
nodeWidget_->bindEmpty("no-expand");
nodeWidget_->bindEmpty("col0");
int selfHeight = 0;
// TF: Although it seems, that this ctor never gets called with childrenheight == -1
// for non-root nodes, the variable 'selfheight' does not make any sense here,
// if not properly initialized *before* its one and only usage below...
int selfHeight = index == view_->rootIndex() ? 0 : 1;
// int selfHeight = 0;
bool needLoad = view_->isExpanded(index_);
if (index_ != view_->rootIndex() && !needLoad)
......
updateGraphics(isLast, !view_->model()->hasChildren(index_));
insertColumns(0, view_->columnCount());
selfHeight = 1;
// TF: Too late for initialization. Variable never referenced again...
// selfHeight = 1;
if (view_->selectionBehavior() == SelectionBehavior::Rows &&
view_->isSelected(index_))
......
}
}
int WTreeView::getIndexRow(const WModelIndex& child,
const WModelIndex& ancestor,
int lowerBound, int upperBound) const
// TF: This function returns the zero-based numerical index of the table row
// for 'child' under 'ancestor', given that the parent of 'child' is expanded and
// using 'ancestor' as the (invisible) root.
int WTreeView::getIndexRow( const WModelIndex& child,
const WModelIndex& ancestor,
int lowerBound, int upperBound ) const
{
if (!child.isValid() || child == ancestor)
return 0;
......
return result;
}
return result + getIndexRow(parent, ancestor,
lowerBound - result, upperBound - result);
// TF: Adjustment with the position of parent within its siblings,
// only if parent is not the (invisible) root...
// getIndexRow() will deliver strange results anyway, if the
// parent of the initial child was not expanded!
if ( parent != ancestor )
result += 1 + getIndexRow( parent, ancestor,
lowerBound - result, upperBound - result );
return result;
// return result + getIndexRow(parent, ancestor,
// lowerBound - result, upperBound - result);
}
}
......
void WTreeView::scrollTo(const WModelIndex& index, ScrollHint hint)
{
int row = getIndexRow(index, rootIndex(), 0,
std::numeric_limits<int>::max()) + 1;
// TF: Numeric index of table row for 'index', given that 'index' is visible,
// i.e. all of its parents are expanded.
// (This should not be increased by 1! s. getIndexRow())
int row = getIndexRow( index, rootIndex(), 0,
std::numeric_limits<int>::max() );
// int row = getIndexRow(index, rootIndex(), 0,
// std::numeric_limits<int>::max()) + 1;
WApplication *app = WApplication::instance();
if (app->environment().ajax()) {
if (viewportHeight_ != UNKNOWN_VIEWPORT_HEIGHT) {
if (hint == ScrollHint::EnsureVisible) {
if (viewportTop_ + viewportHeight_ < row)
hint = ScrollHint::PositionAtTop;
else if (row < viewportTop_)
hint = ScrollHint::PositionAtBottom;
if ( app->environment().ajax() ) {
if ( viewportHeight_ != UNKNOWN_VIEWPORT_HEIGHT ) {
// TF: If 'EnsureVisible' then scroll to bottom, if 'row' is below
// the bottom visible entry, and scroll to top, if 'row' is above
// the first visible entry (minimal scrolling).
// 'viewportTop_' and 'viewportHeight_' may include partially visible rows!
if ( hint == ScrollHint::EnsureVisible ) {
if ( viewportTop_ + viewportHeight_ <= row )
hint = ScrollHint::PositionAtBottom;
else if ( row <= viewportTop_ )
hint = ScrollHint::PositionAtTop;
}
/*
if (hint == ScrollHint::EnsureVisible) {
if (viewportTop_ + viewportHeight_ < row)
hint = ScrollHint::PositionAtTop;
else if (row < viewportTop_)
hint = ScrollHint::PositionAtBottom;
}
*/
switch (hint) {
case ScrollHint::PositionAtTop:
viewportTop_ = row; break;
case ScrollHint::PositionAtBottom:
viewportTop_ = row - viewportHeight_ + 1; break;
case ScrollHint::PositionAtCenter:
viewportTop_ = row - viewportHeight_/2 + 1; break;
default:
break;
}
// TF: Adjust viewport, if still required...
if ( hint != ScrollHint::EnsureVisible ) {
switch ( hint ) {
case ScrollHint::PositionAtTop:
viewportTop_ = row; break;
case ScrollHint::PositionAtBottom:
viewportTop_ = row - viewportHeight_ + 1; break;
case ScrollHint::PositionAtCenter:
viewportTop_ = row - viewportHeight_ / 2 + 1; break;
default:
break;
}
if (hint != ScrollHint::EnsureVisible) {
scheduleRerender(RenderState::NeedAdjustViewPort);
scheduleRerender( RenderState::NeedAdjustViewPort );
}
}
(4-4/4)