diff --git a/ChangeLog b/ChangeLog index 1e87e489..47221742 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,5 @@ 2020-02-04 Markus Gans + * Fix in FListViewIterator * Add screenshorts to the first steps document 2020-02-02 Markus Gans diff --git a/src/flistview.cpp b/src/flistview.cpp index 9bb21669..8a3fad18 100644 --- a/src/flistview.cpp +++ b/src/flistview.cpp @@ -560,20 +560,27 @@ void FListViewIterator::nextElement (iterator& iter) } else { - ++iter; position++; + bool forward{}; - if ( ! iter_path.empty() ) + do { - const auto& parent_iter = iter_path.top(); + forward = false; // Reset forward + ++iter; - if ( iter == (*parent_iter)->end() ) + if ( ! iter_path.empty() ) { - iter = parent_iter; - iter_path.pop(); - ++iter; + const auto& parent_iter = iter_path.top(); + + if ( iter == (*parent_iter)->end() ) + { + iter = parent_iter; + iter_path.pop(); + forward = true; + } } } + while ( forward ); } } @@ -1142,7 +1149,7 @@ void FListView::onMouseUp (FMouseEvent* ev) else item->expand(); - adjustSize(); + adjustScrollbars (getCount()); if ( isShown() ) draw(); @@ -1225,11 +1232,12 @@ void FListView::onMouseDoubleClick (FMouseEvent* ev) const int mouse_x = ev->getX(); const int mouse_y = ev->getY(); + const std::size_t element_count = getCount(); if ( mouse_x > 1 && mouse_x < int(getWidth()) && mouse_y > 1 && mouse_y < int(getHeight()) ) { - if ( first_visible_line.getPosition() + mouse_y - 1 > int(getCount()) ) + if ( first_visible_line.getPosition() + mouse_y - 1 > int(element_count) ) return; if ( itemlist.empty() ) @@ -1244,7 +1252,7 @@ void FListView::onMouseDoubleClick (FMouseEvent* ev) else item->expand(); - adjustSize(); + adjustScrollbars (element_count); if ( isShown() ) draw(); @@ -1356,7 +1364,7 @@ void FListView::onFocusOut (FFocusEvent*) // protected methods of FListView //---------------------------------------------------------------------- -void FListView::adjustViewport (int element_count) +void FListView::adjustViewport (const int element_count) { const int height = int(getClientHeight()); @@ -1396,15 +1404,10 @@ void FListView::adjustViewport (int element_count) } //---------------------------------------------------------------------- -void FListView::adjustSize() +void FListView::adjustScrollbars (const std::size_t element_count) { - FWidget::adjustSize(); - const std::size_t element_count = getCount(); const std::size_t width = getClientWidth(); const std::size_t height = getClientHeight(); - - adjustViewport (int(element_count)); - const int vmax = ( element_count > height ) ? int(element_count - height) : 0; @@ -1437,6 +1440,15 @@ void FListView::adjustSize() } } +//---------------------------------------------------------------------- +void FListView::adjustSize() +{ + FWidget::adjustSize(); + const std::size_t element_count = getCount(); + adjustViewport (int(element_count)); + adjustScrollbars (element_count); +} + // private methods of FListView //---------------------------------------------------------------------- @@ -1512,8 +1524,8 @@ void FListView::sort (Compare cmp) //---------------------------------------------------------------------- std::size_t FListView::getAlignOffset ( const fc::text_alignment align - , std::size_t column_width - , std::size_t width ) + , const std::size_t column_width + , const std::size_t width ) { switch ( align ) { @@ -1536,6 +1548,22 @@ std::size_t FListView::getAlignOffset ( const fc::text_alignment align return 0; } +//---------------------------------------------------------------------- +FObject::iterator FListView::getListEnd (FListViewItem* item) +{ + auto parent = item->getParent(); + + if ( ! parent ) + return null_iter; + + if ( this == parent ) + return itemlist.end(); + else if ( parent->isInstanceOf("FListViewItem") ) + return static_cast(parent)->end(); + else + return null_iter; +} + //---------------------------------------------------------------------- void FListView::draw() { @@ -1643,14 +1671,17 @@ void FListView::drawList() uInt y{0}; const uInt page_height = uInt(getHeight()) - 2; + const auto& itemlist_end = itemlist.end(); + auto path_end = itemlist_end; auto iter = first_visible_line; - while ( iter != itemlist.end() && y < page_height ) + while ( iter != path_end && iter != itemlist_end && y < page_height ) { const bool is_current_line( iter == current_iter ); const auto& item = static_cast(*iter); const int tree_offset = ( tree_view ) ? int(item->getDepth() << 1) + 1 : 0; const int checkbox_offset = ( item->isCheckable() ) ? 1 : 0; + path_end = getListEnd(item); print() << FPoint(2, 2 + int(y)); // Draw one FListViewItem @@ -1758,8 +1789,15 @@ void FListView::drawListLine ( const FListViewItem* item for (std::size_t i{0}; i < len; i++) { - char_width += getColumnWidth(line[i]); - print() << line[i]; + try + { + char_width += getColumnWidth(line[i]); + print() << line[i]; + } + catch (const std::out_of_range&) + { + return; + } } for (std::size_t i = char_width; i < width; i++) @@ -2185,11 +2223,12 @@ void FListView::recalculateHorizontalBar (std::size_t len) //---------------------------------------------------------------------- void FListView::recalculateVerticalBar (std::size_t element_count) { - const int vmax = ( element_count + 2 > getHeight() ) - ? int(element_count - getHeight() + 2) + const std::size_t height = getClientHeight(); + const int vmax = ( element_count > height ) + ? int(element_count - height) : 0; vbar->setMaximum (vmax); - vbar->setPageSize (int(element_count), int(getHeight()) - 2); + vbar->setPageSize (int(element_count), int(height)); vbar->calculateSliderValues(); if ( isShown() ) @@ -2445,9 +2484,8 @@ inline void FListView::collapseAndScrollLeft() { // Collapse element item->collapse(); - adjustSize(); - const std::size_t element_count = getCount(); - recalculateVerticalBar (element_count); + adjustScrollbars (getCount()); + vbar->calculateSliderValues(); // Force vertical scrollbar redraw first_line_position_before = -1; } @@ -2498,7 +2536,7 @@ inline void FListView::expandAndScrollRight() { // Expand element item->expand(); - adjustSize(); + adjustScrollbars (getCount()); // Force vertical scrollbar redraw first_line_position_before = -1; } @@ -2549,7 +2587,7 @@ inline bool FListView::expandSubtree() if ( tree_view && item->isExpandable() && ! item->isExpand() ) { item->expand(); - adjustSize(); + adjustScrollbars (getCount()); return true; } @@ -2567,7 +2605,7 @@ inline bool FListView::collapseSubtree() if ( tree_view && item->isExpandable() && item->isExpand() ) { item->collapse(); - adjustSize(); + adjustScrollbars (getCount()); return true; } diff --git a/src/fmenu.cpp b/src/fmenu.cpp index 734418f1..a7844965 100644 --- a/src/fmenu.cpp +++ b/src/fmenu.cpp @@ -481,8 +481,8 @@ void FMenu::calculateDimensions() for (auto&& item : getItemList()) { std::size_t item_width = item->getTextWidth() + 2; - const FKey accel_key = item->accel_key; - const bool has_menu = item->hasMenu(); + const FKey accel_key = item->accel_key; + const bool has_menu = item->hasMenu(); if ( has_menu ) { diff --git a/src/fscrollbar.cpp b/src/fscrollbar.cpp index bbb52ed0..b7a78972 100644 --- a/src/fscrollbar.cpp +++ b/src/fscrollbar.cpp @@ -616,7 +616,7 @@ FScrollbar::sType FScrollbar::getClickedScrollType (int x, int y) { if ( bar_orientation == fc::vertical ) { - return getVerticalClickedScrollType(y); + return getVerticalClickedScrollType(y); } else // horizontal { diff --git a/src/fscrollview.cpp b/src/fscrollview.cpp index 26cce40f..caa11901 100644 --- a/src/fscrollview.cpp +++ b/src/fscrollview.cpp @@ -344,10 +344,10 @@ void FScrollView::scrollTo (int x, int y) { int& xoffset = viewport_geometry.x1_ref(); int& yoffset = viewport_geometry.y1_ref(); - const int xoffset_before = xoffset; - const int yoffset_before = yoffset; - const int xoffset_end = int(getScrollWidth() - getViewportWidth()); - const int yoffset_end = int(getScrollHeight() - getViewportHeight()); + const int xoffset_before = xoffset; + const int yoffset_before = yoffset; + const int xoffset_end = int(getScrollWidth() - getViewportWidth()); + const int yoffset_end = int(getScrollHeight() - getViewportHeight()); const std::size_t save_width = viewport_geometry.getWidth(); const std::size_t save_height = viewport_geometry.getHeight(); x--; diff --git a/src/fterm.cpp b/src/fterm.cpp index 228dd9cf..ad796b69 100644 --- a/src/fterm.cpp +++ b/src/fterm.cpp @@ -1333,7 +1333,7 @@ void FTerm::init_global_values (bool disable_alt_screen) void FTerm::init_terminal_device_path() { char termfilename[256]{}; - const int stdout_no = FTermios::getStdOut(); + const int stdout_no = FTermios::getStdOut(); if ( ttyname_r(stdout_no, termfilename, sizeof(termfilename)) ) termfilename[0] = '\0'; diff --git a/src/include/final/flistview.h b/src/include/final/flistview.h index 50881152..3ae1bc7b 100644 --- a/src/include/final/flistview.h +++ b/src/include/final/flistview.h @@ -353,7 +353,8 @@ class FListView : public FWidget protected: // Methods - void adjustViewport (int); + void adjustViewport (const int); + void adjustScrollbars (const std::size_t); void adjustSize() override; private: @@ -383,8 +384,9 @@ class FListView : public FWidget template void sort (Compare); std::size_t getAlignOffset ( const fc::text_alignment - , std::size_t - , std::size_t ); + , const std::size_t + , const std::size_t ); + iterator getListEnd (FListViewItem*); void draw() override; void drawBorder() override; void drawScrollbars(); diff --git a/test/fkeyboard-test.cpp b/test/fkeyboard-test.cpp index e8acd79c..124e8ab2 100644 --- a/test/fkeyboard-test.cpp +++ b/test/fkeyboard-test.cpp @@ -2595,7 +2595,7 @@ void FKeyboardTest::sequencesTest() CPPUNIT_ASSERT ( key_pressed == finalcut::fc::Fkey_sdc ); clear(); - // shifted end key + // shifted end key input("\033[1;2F"); processInput(); std::cout << " - Key: " << keyboard->getKeyName(key_pressed) << std::endl; @@ -2637,7 +2637,7 @@ void FKeyboardTest::sequencesTest() CPPUNIT_ASSERT ( key_pressed == finalcut::fc::Fkey_sprevious ); clear(); - // shifted right-arrow key + // shifted right-arrow key input("\033[1;2C"); processInput(); std::cout << " - Key: " << keyboard->getKeyName(key_pressed) << std::endl; diff --git a/test/ftermfreebsd-test.cpp b/test/ftermfreebsd-test.cpp index e0883872..22e29f1e 100644 --- a/test/ftermfreebsd-test.cpp +++ b/test/ftermfreebsd-test.cpp @@ -365,7 +365,7 @@ keymap_t FSystemTest::keymap = // static class attributes //---------------------------------------------------------------------- -keymap_t FSystemTest::terminal_keymap{}; +keymap_t FSystemTest::terminal_keymap{}; // constructors and destructor //----------------------------------------------------------------------