Fix in FListViewIterator

This commit is contained in:
Markus Gans 2020-02-05 08:57:13 +01:00
parent b05513a8f8
commit b810b51e65
9 changed files with 86 additions and 45 deletions

View File

@ -1,4 +1,5 @@
2020-02-04 Markus Gans <guru.mail@muenster.de> 2020-02-04 Markus Gans <guru.mail@muenster.de>
* Fix in FListViewIterator
* Add screenshorts to the first steps document * Add screenshorts to the first steps document
2020-02-02 Markus Gans <guru.mail@muenster.de> 2020-02-02 Markus Gans <guru.mail@muenster.de>

View File

@ -560,20 +560,27 @@ void FListViewIterator::nextElement (iterator& iter)
} }
else else
{ {
++iter;
position++; 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; const auto& parent_iter = iter_path.top();
iter_path.pop();
++iter; 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 else
item->expand(); item->expand();
adjustSize(); adjustScrollbars (getCount());
if ( isShown() ) if ( isShown() )
draw(); draw();
@ -1225,11 +1232,12 @@ void FListView::onMouseDoubleClick (FMouseEvent* ev)
const int mouse_x = ev->getX(); const int mouse_x = ev->getX();
const int mouse_y = ev->getY(); const int mouse_y = ev->getY();
const std::size_t element_count = getCount();
if ( mouse_x > 1 && mouse_x < int(getWidth()) if ( mouse_x > 1 && mouse_x < int(getWidth())
&& mouse_y > 1 && mouse_y < int(getHeight()) ) && 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; return;
if ( itemlist.empty() ) if ( itemlist.empty() )
@ -1244,7 +1252,7 @@ void FListView::onMouseDoubleClick (FMouseEvent* ev)
else else
item->expand(); item->expand();
adjustSize(); adjustScrollbars (element_count);
if ( isShown() ) if ( isShown() )
draw(); draw();
@ -1356,7 +1364,7 @@ void FListView::onFocusOut (FFocusEvent*)
// protected methods of FListView // protected methods of FListView
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListView::adjustViewport (int element_count) void FListView::adjustViewport (const int element_count)
{ {
const int height = int(getClientHeight()); 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 width = getClientWidth();
const std::size_t height = getClientHeight(); const std::size_t height = getClientHeight();
adjustViewport (int(element_count));
const int vmax = ( element_count > height ) const int vmax = ( element_count > height )
? int(element_count - height) ? int(element_count - height)
: 0; : 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 // 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 FListView::getAlignOffset ( const fc::text_alignment align
, std::size_t column_width , const std::size_t column_width
, std::size_t width ) , const std::size_t width )
{ {
switch ( align ) switch ( align )
{ {
@ -1536,6 +1548,22 @@ std::size_t FListView::getAlignOffset ( const fc::text_alignment align
return 0; 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<FListViewItem*>(parent)->end();
else
return null_iter;
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FListView::draw() void FListView::draw()
{ {
@ -1643,14 +1671,17 @@ void FListView::drawList()
uInt y{0}; uInt y{0};
const uInt page_height = uInt(getHeight()) - 2; const uInt page_height = uInt(getHeight()) - 2;
const auto& itemlist_end = itemlist.end();
auto path_end = itemlist_end;
auto iter = first_visible_line; 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 bool is_current_line( iter == current_iter );
const auto& item = static_cast<FListViewItem*>(*iter); const auto& item = static_cast<FListViewItem*>(*iter);
const int tree_offset = ( tree_view ) ? int(item->getDepth() << 1) + 1 : 0; const int tree_offset = ( tree_view ) ? int(item->getDepth() << 1) + 1 : 0;
const int checkbox_offset = ( item->isCheckable() ) ? 1 : 0; const int checkbox_offset = ( item->isCheckable() ) ? 1 : 0;
path_end = getListEnd(item);
print() << FPoint(2, 2 + int(y)); print() << FPoint(2, 2 + int(y));
// Draw one FListViewItem // Draw one FListViewItem
@ -1758,8 +1789,15 @@ void FListView::drawListLine ( const FListViewItem* item
for (std::size_t i{0}; i < len; i++) for (std::size_t i{0}; i < len; i++)
{ {
char_width += getColumnWidth(line[i]); try
print() << line[i]; {
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++) 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) void FListView::recalculateVerticalBar (std::size_t element_count)
{ {
const int vmax = ( element_count + 2 > getHeight() ) const std::size_t height = getClientHeight();
? int(element_count - getHeight() + 2) const int vmax = ( element_count > height )
? int(element_count - height)
: 0; : 0;
vbar->setMaximum (vmax); vbar->setMaximum (vmax);
vbar->setPageSize (int(element_count), int(getHeight()) - 2); vbar->setPageSize (int(element_count), int(height));
vbar->calculateSliderValues(); vbar->calculateSliderValues();
if ( isShown() ) if ( isShown() )
@ -2445,9 +2484,8 @@ inline void FListView::collapseAndScrollLeft()
{ {
// Collapse element // Collapse element
item->collapse(); item->collapse();
adjustSize(); adjustScrollbars (getCount());
const std::size_t element_count = getCount(); vbar->calculateSliderValues();
recalculateVerticalBar (element_count);
// Force vertical scrollbar redraw // Force vertical scrollbar redraw
first_line_position_before = -1; first_line_position_before = -1;
} }
@ -2498,7 +2536,7 @@ inline void FListView::expandAndScrollRight()
{ {
// Expand element // Expand element
item->expand(); item->expand();
adjustSize(); adjustScrollbars (getCount());
// Force vertical scrollbar redraw // Force vertical scrollbar redraw
first_line_position_before = -1; first_line_position_before = -1;
} }
@ -2549,7 +2587,7 @@ inline bool FListView::expandSubtree()
if ( tree_view && item->isExpandable() && ! item->isExpand() ) if ( tree_view && item->isExpandable() && ! item->isExpand() )
{ {
item->expand(); item->expand();
adjustSize(); adjustScrollbars (getCount());
return true; return true;
} }
@ -2567,7 +2605,7 @@ inline bool FListView::collapseSubtree()
if ( tree_view && item->isExpandable() && item->isExpand() ) if ( tree_view && item->isExpandable() && item->isExpand() )
{ {
item->collapse(); item->collapse();
adjustSize(); adjustScrollbars (getCount());
return true; return true;
} }

View File

@ -481,8 +481,8 @@ void FMenu::calculateDimensions()
for (auto&& item : getItemList()) for (auto&& item : getItemList())
{ {
std::size_t item_width = item->getTextWidth() + 2; std::size_t item_width = item->getTextWidth() + 2;
const FKey accel_key = item->accel_key; const FKey accel_key = item->accel_key;
const bool has_menu = item->hasMenu(); const bool has_menu = item->hasMenu();
if ( has_menu ) if ( has_menu )
{ {

View File

@ -616,7 +616,7 @@ FScrollbar::sType FScrollbar::getClickedScrollType (int x, int y)
{ {
if ( bar_orientation == fc::vertical ) if ( bar_orientation == fc::vertical )
{ {
return getVerticalClickedScrollType(y); return getVerticalClickedScrollType(y);
} }
else // horizontal else // horizontal
{ {

View File

@ -344,10 +344,10 @@ void FScrollView::scrollTo (int x, int y)
{ {
int& xoffset = viewport_geometry.x1_ref(); int& xoffset = viewport_geometry.x1_ref();
int& yoffset = viewport_geometry.y1_ref(); int& yoffset = viewport_geometry.y1_ref();
const int xoffset_before = xoffset; const int xoffset_before = xoffset;
const int yoffset_before = yoffset; const int yoffset_before = yoffset;
const int xoffset_end = int(getScrollWidth() - getViewportWidth()); const int xoffset_end = int(getScrollWidth() - getViewportWidth());
const int yoffset_end = int(getScrollHeight() - getViewportHeight()); const int yoffset_end = int(getScrollHeight() - getViewportHeight());
const std::size_t save_width = viewport_geometry.getWidth(); const std::size_t save_width = viewport_geometry.getWidth();
const std::size_t save_height = viewport_geometry.getHeight(); const std::size_t save_height = viewport_geometry.getHeight();
x--; x--;

View File

@ -1333,7 +1333,7 @@ void FTerm::init_global_values (bool disable_alt_screen)
void FTerm::init_terminal_device_path() void FTerm::init_terminal_device_path()
{ {
char termfilename[256]{}; char termfilename[256]{};
const int stdout_no = FTermios::getStdOut(); const int stdout_no = FTermios::getStdOut();
if ( ttyname_r(stdout_no, termfilename, sizeof(termfilename)) ) if ( ttyname_r(stdout_no, termfilename, sizeof(termfilename)) )
termfilename[0] = '\0'; termfilename[0] = '\0';

View File

@ -353,7 +353,8 @@ class FListView : public FWidget
protected: protected:
// Methods // Methods
void adjustViewport (int); void adjustViewport (const int);
void adjustScrollbars (const std::size_t);
void adjustSize() override; void adjustSize() override;
private: private:
@ -383,8 +384,9 @@ class FListView : public FWidget
template <typename Compare> template <typename Compare>
void sort (Compare); void sort (Compare);
std::size_t getAlignOffset ( const fc::text_alignment std::size_t getAlignOffset ( const fc::text_alignment
, std::size_t , const std::size_t
, std::size_t ); , const std::size_t );
iterator getListEnd (FListViewItem*);
void draw() override; void draw() override;
void drawBorder() override; void drawBorder() override;
void drawScrollbars(); void drawScrollbars();

View File

@ -2595,7 +2595,7 @@ void FKeyboardTest::sequencesTest()
CPPUNIT_ASSERT ( key_pressed == finalcut::fc::Fkey_sdc ); CPPUNIT_ASSERT ( key_pressed == finalcut::fc::Fkey_sdc );
clear(); clear();
// shifted end key // shifted end key
input("\033[1;2F"); input("\033[1;2F");
processInput(); processInput();
std::cout << " - Key: " << keyboard->getKeyName(key_pressed) << std::endl; std::cout << " - Key: " << keyboard->getKeyName(key_pressed) << std::endl;
@ -2637,7 +2637,7 @@ void FKeyboardTest::sequencesTest()
CPPUNIT_ASSERT ( key_pressed == finalcut::fc::Fkey_sprevious ); CPPUNIT_ASSERT ( key_pressed == finalcut::fc::Fkey_sprevious );
clear(); clear();
// shifted right-arrow key // shifted right-arrow key
input("\033[1;2C"); input("\033[1;2C");
processInput(); processInput();
std::cout << " - Key: " << keyboard->getKeyName(key_pressed) << std::endl; std::cout << " - Key: " << keyboard->getKeyName(key_pressed) << std::endl;

View File

@ -365,7 +365,7 @@ keymap_t FSystemTest::keymap =
// static class attributes // static class attributes
//---------------------------------------------------------------------- //----------------------------------------------------------------------
keymap_t FSystemTest::terminal_keymap{}; keymap_t FSystemTest::terminal_keymap{};
// constructors and destructor // constructors and destructor
//---------------------------------------------------------------------- //----------------------------------------------------------------------