Project

General

Profile

Bug #6774 » issue_6774.patch

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

View differences:

src/Wt/WTreeView.C
335 335
  nodeWidget_->bindEmpty("no-expand");
336 336
  nodeWidget_->bindEmpty("col0");
337 337

  
338
  int selfHeight = 0;
338
// TF: Although it seems, that this ctor never gets called with childrenheight == -1
339
//     for non-root nodes, the variable 'selfheight' does not make any sense here,
340
//     if not properly initialized *before* its one and only usage below...
341
  int selfHeight = index == view_->rootIndex() ? 0 : 1;
342
//  int selfHeight = 0;
339 343
  bool needLoad = view_->isExpanded(index_);
340 344

  
341 345
  if (index_ != view_->rootIndex() && !needLoad)
......
355 359
    updateGraphics(isLast, !view_->model()->hasChildren(index_));
356 360
    insertColumns(0, view_->columnCount());
357 361

  
358
    selfHeight = 1;
362
// TF: Too late for initialization. Variable never referenced again...
363
//    selfHeight = 1;
359 364

  
360 365
    if (view_->selectionBehavior() == SelectionBehavior::Rows &&
361 366
	view_->isSelected(index_))
......
2336 2341
  }
2337 2342
}
2338 2343

  
2339
int WTreeView::getIndexRow(const WModelIndex& child,
2340
			   const WModelIndex& ancestor,
2341
			   int lowerBound, int upperBound) const
2344
// TF: This function returns the zero-based numerical index of the table row
2345
//     for 'child' under 'ancestor', given that the parent of 'child' is expanded and
2346
//     using 'ancestor' as the (invisible) root.
2347
int WTreeView::getIndexRow( const WModelIndex& child,
2348
                            const WModelIndex& ancestor,
2349
                            int lowerBound, int upperBound ) const
2342 2350
{
2343 2351
  if (!child.isValid() || child == ancestor)
2344 2352
    return 0;
......
2353 2361
	return result;
2354 2362
    }
2355 2363

  
2356
    return result + getIndexRow(parent, ancestor,
2357
				lowerBound - result, upperBound - result);
2364
    // TF: Adjustment with the position of parent within its siblings,
2365
    //     only if parent is not the (invisible) root...
2366
    //     getIndexRow() will deliver strange results anyway, if the
2367
    //     parent of the initial child was not expanded!
2368
    if ( parent != ancestor )
2369
      result += 1 + getIndexRow( parent, ancestor,
2370
                                 lowerBound - result, upperBound - result );
2371
    return result;
2372
    //    return result + getIndexRow(parent, ancestor,
2373
    //				lowerBound - result, upperBound - result);
2358 2374
  }
2359 2375
}
2360 2376

  
......
2968 2984

  
2969 2985
void WTreeView::scrollTo(const WModelIndex& index, ScrollHint hint)
2970 2986
{
2971
  int row = getIndexRow(index, rootIndex(), 0,
2972
			std::numeric_limits<int>::max()) + 1;
2987
  // TF: Numeric index of table row for 'index', given that 'index' is visible,
2988
  //     i.e. all of its parents are expanded.
2989
  //     (This should not be increased by 1! s. getIndexRow())
2990
  int row = getIndexRow( index, rootIndex(), 0,
2991
                         std::numeric_limits<int>::max() );
2992
  //  int row = getIndexRow(index, rootIndex(), 0,
2993
  //                        std::numeric_limits<int>::max()) + 1;
2973 2994

  
2974 2995
  WApplication *app = WApplication::instance();
2975 2996

  
2976
  if (app->environment().ajax()) {
2977
    if (viewportHeight_ != UNKNOWN_VIEWPORT_HEIGHT) {
2978
      if (hint == ScrollHint::EnsureVisible) {
2979
	if (viewportTop_ + viewportHeight_ < row)
2980
	  hint = ScrollHint::PositionAtTop;
2981
	else if (row < viewportTop_)
2982
	  hint = ScrollHint::PositionAtBottom;
2997
  if ( app->environment().ajax() ) {
2998
    if ( viewportHeight_ != UNKNOWN_VIEWPORT_HEIGHT ) {
2999
      // TF: If 'EnsureVisible' then scroll to bottom, if 'row' is below
3000
      //     the bottom visible entry, and scroll to top, if 'row' is above
3001
      //     the first visible entry (minimal scrolling).
3002
      //     'viewportTop_' and 'viewportHeight_' may include partially visible rows!
3003
      if ( hint == ScrollHint::EnsureVisible ) {
3004
        if ( viewportTop_ + viewportHeight_ <= row )
3005
          hint = ScrollHint::PositionAtBottom;
3006
        else if ( row <= viewportTop_ )
3007
          hint = ScrollHint::PositionAtTop;
2983 3008
      }
3009
      /*
3010
            if (hint == ScrollHint::EnsureVisible) {
3011
              if (viewportTop_ + viewportHeight_ < row)
3012
                hint = ScrollHint::PositionAtTop;
3013
              else if (row < viewportTop_)
3014
                hint = ScrollHint::PositionAtBottom;
3015
            }
3016
      */
2984 3017

  
2985
      switch (hint) {
2986
      case ScrollHint::PositionAtTop:
2987
	viewportTop_ = row; break;
2988
      case ScrollHint::PositionAtBottom:
2989
	viewportTop_ = row - viewportHeight_ + 1; break;
2990
      case ScrollHint::PositionAtCenter:
2991
	viewportTop_ = row - viewportHeight_/2 + 1; break;
2992
      default:
2993
	break;
2994
      }
3018
      // TF: Adjust viewport, if still required...
3019
      if ( hint != ScrollHint::EnsureVisible ) {
3020
        switch ( hint ) {
3021
        case ScrollHint::PositionAtTop:
3022
          viewportTop_ = row; break;
3023
        case ScrollHint::PositionAtBottom:
3024
          viewportTop_ = row - viewportHeight_ + 1; break;
3025
        case ScrollHint::PositionAtCenter:
3026
          viewportTop_ = row - viewportHeight_ / 2 + 1; break;
3027
        default:
3028
          break;
3029
        }
2995 3030

  
2996
      if (hint != ScrollHint::EnsureVisible) {
2997
	scheduleRerender(RenderState::NeedAdjustViewPort);
3031
        scheduleRerender( RenderState::NeedAdjustViewPort );
2998 3032
      }
2999 3033
    }
3000 3034

  
(4-4/4)