diff --git a/ChangeLog b/ChangeLog index 46bc95f8..7bd5cbc3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2017-09-15 Markus Gans + * Fix byte access in data type char_data + 2017-09-11 Markus Gans * Some code improvements * Fix handling of negative numbers in FString::toLong() diff --git a/src/fbuttongroup.cpp b/src/fbuttongroup.cpp index 7c874a93..2dce30d1 100644 --- a/src/fbuttongroup.cpp +++ b/src/fbuttongroup.cpp @@ -34,7 +34,7 @@ FButtonGroup::FButtonGroup (const FString& txt, FWidget* parent) //---------------------------------------------------------------------- FButtonGroup::~FButtonGroup() // destructor { - FObjectList::iterator iter; + FObjectIterator iter; if ( buttonlist.empty() ) return; @@ -54,7 +54,7 @@ FButtonGroup::~FButtonGroup() // destructor //---------------------------------------------------------------------- FToggleButton* FButtonGroup::getButton(int index) const { - FObjectList::const_iterator iter; + constFObjectIterator iter; index--; if ( buttonlist.empty() ) @@ -126,7 +126,7 @@ bool FButtonGroup::hasFocusedButton() const if ( buttonlist.empty() ) return false; - FObjectList::const_iterator iter, end; + constFObjectIterator iter, end; iter = buttonlist.begin(); end = buttonlist.end(); @@ -149,7 +149,7 @@ bool FButtonGroup::hasCheckedButton() const if ( buttonlist.empty() ) return false; - FObjectList::const_iterator iter, end; + constFObjectIterator iter, end; iter = buttonlist.begin(); end = buttonlist.end(); @@ -177,7 +177,7 @@ void FButtonGroup::hide() if ( ! buttonlist.empty() ) { - FObjectList::const_iterator iter, end; + constFObjectIterator iter, end; iter = buttonlist.begin(); end = buttonlist.end(); @@ -260,7 +260,7 @@ void FButtonGroup::insert (FToggleButton* button) //---------------------------------------------------------------------- void FButtonGroup::remove (FToggleButton* button) { - FObjectList::iterator iter; + FObjectIterator iter; if ( ! button || buttonlist.empty() ) return; @@ -325,7 +325,7 @@ void FButtonGroup::onFocusIn (FFocusEvent* in_ev) { if ( hasCheckedButton() && ! buttonlist.empty() ) { - FObjectList::const_iterator iter, end; + constFObjectIterator iter, end; iter = buttonlist.begin(); end = buttonlist.end(); @@ -389,7 +389,7 @@ void FButtonGroup::onFocusIn (FFocusEvent* in_ev) void FButtonGroup::cb_buttonToggled (FWidget* widget, data_ptr) { FToggleButton* button = static_cast(widget); - FObjectList::const_iterator iter, end; + constFObjectIterator iter, end; if ( ! button->isChecked() ) return; @@ -600,7 +600,7 @@ void FButtonGroup::directFocus() if ( hasCheckedButton() && ! buttonlist.empty() ) { - FObjectList::const_iterator iter, end; + constFObjectIterator iter, end; iter = buttonlist.begin(); end = buttonlist.end(); diff --git a/src/flistbox.cpp b/src/flistbox.cpp index 5d058f73..52756fef 100644 --- a/src/flistbox.cpp +++ b/src/flistbox.cpp @@ -71,7 +71,7 @@ FListBoxItem& FListBoxItem::operator = (const FListBoxItem& item) FListBox::FListBox (FWidget* parent) : FWidget(parent) , convertToItem(0) - , data() + , itemlist() , source_container(0) , conv_type(FListBox::no_convert) , vbar(0) @@ -135,7 +135,7 @@ void FListBox::setCurrentItem (int index) //---------------------------------------------------------------------- void FListBox::setCurrentItem (listBoxItems::iterator iter) { - int index = int(std::distance(data.begin(), iter) + 1); + int index = int(std::distance(itemlist.begin(), iter) + 1); setCurrentItem(index); } @@ -274,7 +274,7 @@ void FListBox::insert (FListBoxItem listItem) bool has_brackets = bool(listItem.brackets); recalculateHorizontalBar (len, has_brackets); - data.push_back (listItem); + itemlist.push_back (listItem); int element_count = int(getCount()); recalculateVerticalBar (element_count); @@ -309,13 +309,13 @@ void FListBox::remove (int item) if ( int(getCount()) < item ) return; - data.erase (data.begin() + item - 1); + itemlist.erase (itemlist.begin() + item - 1); element_count = int(getCount()); max_line_width = 0; - listBoxItems::iterator iter = data.begin(); + listBoxItems::iterator iter = itemlist.begin(); - while ( iter != data.end() ) + while ( iter != itemlist.end() ) { int len = int(iter->getText().getLength()); @@ -356,7 +356,7 @@ void FListBox::clear() int size; char* blank; - data.clear(); + itemlist.clear(); current = 0; xoffset = 0; @@ -556,9 +556,9 @@ void FListBox::onKeyPress (FKeyEvent* ev) { inc_search += L' '; bool inc_found = false; - listBoxItems::iterator iter = data.begin(); + listBoxItems::iterator iter = itemlist.begin(); - while ( iter != data.end() ) + while ( iter != itemlist.end() ) { if ( ! inc_found && inc_search.toLower() @@ -605,9 +605,9 @@ void FListBox::onKeyPress (FKeyEvent* ev) if ( inc_len > 1 ) { - listBoxItems::iterator iter = data.begin(); + listBoxItems::iterator iter = itemlist.begin(); - while ( iter != data.end() ) + while ( iter != itemlist.end() ) { if ( inc_search.toLower() == iter->getText().left(inc_len - 1).toLower() ) @@ -647,9 +647,9 @@ void FListBox::onKeyPress (FKeyEvent* ev) uInt inc_len = inc_search.getLength(); bool inc_found = false; - listBoxItems::iterator iter = data.begin(); + listBoxItems::iterator iter = itemlist.begin(); - while ( iter != data.end() ) + while ( iter != itemlist.end() ) { if ( ! inc_found && inc_search.toLower() @@ -1376,7 +1376,7 @@ void FListBox::drawList() bool isFocus; listBoxItems::iterator iter; - if ( data.empty() || getHeight() <= 2 || getWidth() <= 4 ) + if ( itemlist.empty() || getHeight() <= 2 || getWidth() <= 4 ) return; isFocus = ((flags & fc::focus) != 0); diff --git a/src/flistbox.h b/src/flistbox.h index a81e0905..4d1b39b0 100644 --- a/src/flistbox.h +++ b/src/flistbox.h @@ -233,7 +233,7 @@ class FListBox : public FWidget , int index ); // Data Members - listBoxItems data; + listBoxItems itemlist; FWidget::data_ptr source_container; convert_type conv_type; FScrollbar* vbar; @@ -267,7 +267,7 @@ inline FListBox::FListBox ( Iterator first , FWidget* parent ) : FWidget(parent) , convertToItem(0) - , data() + , itemlist() , source_container(0) , conv_type(FListBox::no_convert) , vbar(0) @@ -305,7 +305,7 @@ inline FListBox::FListBox ( Container container , FWidget* parent ) : FWidget(parent) , convertToItem(0) - , data() + , itemlist() , source_container(0) , conv_type(FListBox::no_convert) , vbar(0) @@ -337,7 +337,7 @@ inline const char* FListBox::getClassName() const //---------------------------------------------------------------------- inline uInt FListBox::getCount() const -{ return uInt(data.size()); } +{ return uInt(itemlist.size()); } //---------------------------------------------------------------------- inline FListBoxItem FListBox::getItem (int index) @@ -451,7 +451,7 @@ void FListBox::insert (Container container, LazyConverter convert) size_t size = container->size(); if ( size > 0 ) - data.resize(size); + itemlist.resize(size); recalculateVerticalBar(int(size)); } @@ -459,7 +459,7 @@ void FListBox::insert (Container container, LazyConverter convert) //---------------------------------------------------------------------- inline FListBox::listBoxItems::iterator FListBox::index2iterator (int index) { - listBoxItems::iterator iter = data.begin(); + listBoxItems::iterator iter = itemlist.begin(); std::advance (iter, index); return iter; } diff --git a/src/flistview.cpp b/src/flistview.cpp index cdc4e438..c2cafc4e 100644 --- a/src/flistview.cpp +++ b/src/flistview.cpp @@ -18,7 +18,7 @@ //---------------------------------------------------------------------- FListViewItem::FListViewItem (const FListViewItem& item) : FObject(item.getParent()) - , column_value(item.column_value) + , column_list(item.column_list) , data_pointer(item.data_pointer) , visible_lines(1) , expandable(false) @@ -31,83 +31,76 @@ FListViewItem::FListViewItem (const FListViewItem& item) } //---------------------------------------------------------------------- -FListViewItem::FListViewItem (FListViewItem* parent) - : FObject(parent) - , column_value() +FListViewItem::FListViewItem (FObjectIterator parent_iter) + : FObject(0) + , column_list() , data_pointer(0) , visible_lines(1) , expandable(false) , is_expand(false) { - // Add the FListViewItem to the parent - if ( ! parent ) + if ( *parent_iter ) + { + if ( (*parent_iter)->isInstanceOf("FListView") ) + { + // Add FListViewItem to a FListView parent + FListView* parent = static_cast(*parent_iter); + parent->addChild (this); + parent->insert (this); + } + else if ( (*parent_iter)->isInstanceOf("FListViewItem") ) + { + // Add FListViewItem to a FListViewItem parent + FListViewItem* parent = static_cast(*parent_iter); + parent->addChild (this); + parent->expandable = true; + } + } +} + +//---------------------------------------------------------------------- +FListViewItem::FListViewItem ( const std::vector& cols + , FWidget::data_ptr data + , FObjectIterator parent_iter ) + : FObject(0) + , column_list(cols) + , data_pointer(data) + , visible_lines(1) + , expandable(false) + , is_expand(false) +{ + if ( cols.empty() ) return; - parent->addChild (this); - parent->expandable = true; -} - -//---------------------------------------------------------------------- -FListViewItem::FListViewItem (FListView* parent) - : FObject(parent) - , column_value() - , data_pointer(0) - , visible_lines(1) - , expandable(false) - , is_expand(false) -{ - // Add the FListViewItem to the parent - if ( parent ) - parent->insert (this); -} - -//---------------------------------------------------------------------- -FListViewItem::FListViewItem ( const std::vector& cols - , FWidget::data_ptr data - , FListView* parent ) - : FObject(parent) - , column_value(cols) - , data_pointer(data) - , visible_lines(1) - , expandable(false) - , is_expand(false) -{ // Replace the control codes characters - std::vector::iterator iter = column_value.begin(); + std::vector::iterator iter = column_list.begin(); - while ( iter != column_value.end() ) + while ( iter != column_list.end() ) { *iter = iter->replaceControlCodes(); ++iter; } - // Add the FListViewItem to the parent - if ( parent ) - parent->insert (this); -} + if ( parent_iter == FObjectIterator(0) ) + return; -//---------------------------------------------------------------------- -FListViewItem::FListViewItem ( const std::vector& cols - , FWidget::data_ptr data - , FListViewItem* parent ) - : FObject(parent) - , column_value(cols) - , data_pointer(data) - , visible_lines(1) - , expandable(false) - , is_expand(false) -{ - // Replace the control codes characters - std::vector::iterator iter = column_value.begin(); - - while ( iter != column_value.end() ) + if ( *parent_iter ) { - *iter = iter->replaceControlCodes(); - ++iter; + if ( (*parent_iter)->isInstanceOf("FListView") ) + { + // Add FListViewItem to a FListView parent + FListView* parent = static_cast(*parent_iter); + parent->addChild (this); + parent->insert (this); + } + else if ( (*parent_iter)->isInstanceOf("FListViewItem") ) + { + // Add FListViewItem to a FListViewItem parent + FListViewItem* parent = static_cast(*parent_iter); + parent->addChild (this); + parent->expandable = true; + } } - - if ( parent ) - parent->expandable = true; } //---------------------------------------------------------------------- @@ -120,20 +113,20 @@ FListViewItem::~FListViewItem() // destructor FString FListViewItem::getText (int column) const { if ( column < 1 - || column_value.empty() - || column > int(column_value.size()) ) + || column_list.empty() + || column > int(column_list.size()) ) return *fc::empty_string; column--; // Convert column position to address offset (index) - return column_value[uInt(column)]; + return column_list[uInt(column)]; } //---------------------------------------------------------------------- void FListViewItem::setText (int column, const FString& text) { if ( column < 1 - || column_value.empty() - || column > int(column_value.size()) ) + || column_list.empty() + || column > int(column_list.size()) ) return; FObject* parent = getParent(); @@ -152,7 +145,7 @@ void FListViewItem::setText (int column, const FString& text) } } - column_value[uInt(column)] = text; + column_list[uInt(column)] = text; } //---------------------------------------------------------------------- @@ -197,7 +190,7 @@ int FListViewItem::getVisibleLines() } FObjectList children = this->getChildren(); - FObjectList::const_iterator iter = children.begin(); + constFObjectIterator iter = children.begin(); while ( iter != children.end() ) { @@ -218,7 +211,9 @@ int FListViewItem::getVisibleLines() //---------------------------------------------------------------------- FListView::FListView (FWidget* parent) : FWidget(parent) - , data() + , root() + , selflist() + , itemlist() , header() , headerline() , vbar(0) @@ -295,7 +290,7 @@ void FListView::setColumnAlignment (int column, fc::text_alignment align) // Set the alignment for a column if ( column < 1 || header.empty() || column > int(header.size()) ) - {beep();return;} + return; column--; // Convert column position to address offset (index) header[uInt(column)].alignment = align; @@ -342,70 +337,107 @@ int FListView::addColumn (const FString& label, int width) } //---------------------------------------------------------------------- -void FListView::insert (FListViewItem* item) +FObject::FObjectIterator FListView::insert ( FListViewItem* item + , FObjectIterator parent_iter ) { static const int padding_space = 1; int line_width = padding_space; // leading space uInt column_idx = 0; - uInt entries = uInt(item->column_value.size()); - headerItems::iterator iter; + uInt entries = uInt(item->column_list.size()); + FObjectIterator item_iter; + headerItems::iterator header_iter; - iter = header.begin(); + if ( parent_iter == FObjectIterator(0) ) + return FObjectIterator(0); - while ( iter != header.end() ) + header_iter = header.begin(); + + while ( header_iter != header.end() ) { - int width = (*iter).width; - bool fixed_width = (*iter).fixed_width; + int width = (*header_iter).width; + bool fixed_width = (*header_iter).fixed_width; if ( ! fixed_width ) { int len; if ( column_idx < entries ) - len = int(item->column_value[column_idx].getLength()); + len = int(item->column_list[column_idx].getLength()); else len = 0; if ( len > width ) - (*iter).width = len; + (*header_iter).width = len; } - line_width += (*iter).width + padding_space; // width + tailing space + line_width += (*header_iter).width + padding_space; // width + tailing space column_idx++; - ++iter; + ++header_iter; } recalculateHorizontalBar (line_width); - data.push_back (item); - int element_count = int(data.size()); + if ( parent_iter == root ) + { + addChild (item); + itemlist.push_back (item); + item_iter = --itemlist.end(); + } + else if ( *parent_iter ) + { + if ( (*parent_iter)->isInstanceOf("FListView") ) + { + // Add FListViewItem to a FListView parent + addChild (item); + FListView* parent = static_cast(*parent_iter); + parent->itemlist.push_back (item); + item_iter = --parent->itemlist.end(); + } + else if ( (*parent_iter)->isInstanceOf("FListViewItem") ) + { + // Add FListViewItem to a FListViewItem parent + FListViewItem* parent = static_cast(*parent_iter); + parent->expandable = true; + parent->addChild (item); + FObjectList parent_obj = parent->getChildren(); + item_iter = --parent_obj.end(); + } + } + + int element_count = int(itemlist.size()); recalculateVerticalBar (element_count); + return item_iter; } //---------------------------------------------------------------------- -void FListView::insert ( const std::vector& cols - , data_ptr d - , FListView* parent ) +FObject::FObjectIterator FListView::insert ( const std::vector& cols + , data_ptr d + , FObjectIterator parent_iter ) { + FListViewItem* item; + + if ( ! *parent_iter ) + parent_iter = root; + try { - if ( parent == 0 ) - new FListViewItem (cols, d, this); - else - new FListViewItem (cols, d, parent); + item = new FListViewItem (cols, d, FObjectIterator(0)); } catch (const std::bad_alloc& ex) { std::cerr << "not enough memory to alloc " << ex.what() << std::endl; - return; + return FObjectIterator(0); } + + return insert(item, parent_iter); } //---------------------------------------------------------------------- -void FListView::insert ( const std::vector& cols - , data_ptr d - , FListView* parent ) +FObject::FObjectIterator FListView::insert ( const std::vector& cols + , data_ptr d + , FObjectIterator parent_iter ) { + FObjectIterator item_iter; std::vector str_cols; if ( ! cols.empty() ) @@ -414,16 +446,15 @@ void FListView::insert ( const std::vector& cols str_cols.push_back (FString().setNumber(cols[i])); } - if ( parent == 0 ) - insert (str_cols, d, this); - else - insert (str_cols, d, parent); + item_iter = insert (str_cols, d, parent_iter); + + return item_iter; } //---------------------------------------------------------------------- void FListView::onKeyPress (FKeyEvent* ev) { - int element_count = int(data.size()); + int element_count = int(itemlist.size()); int current_before = current; int xoffset_before = xoffset; int xoffset_end = max_line_width - getClientWidth(); @@ -600,8 +631,8 @@ void FListView::onMouseDown (FMouseEvent* ev) { current = yoffset + mouse_y - 1; - if ( current > int(data.size()) ) - current = int(data.size()); + if ( current > int(itemlist.size()) ) + current = int(itemlist.size()); if ( isVisible() ) drawList(); @@ -663,8 +694,8 @@ void FListView::onMouseMove (FMouseEvent* ev) { current = yoffset + mouse_y - 1; - if ( current > int(data.size()) ) - current = int(data.size()); + if ( current > int(itemlist.size()) ) + current = int(itemlist.size()); if ( isVisible() ) drawList(); @@ -710,7 +741,7 @@ void FListView::onMouseMove (FMouseEvent* ev) && scroll_distance < getClientHeight() ) scroll_distance++; - if ( ! scroll_timer && current < int(data.size()) ) + if ( ! scroll_timer && current < int(itemlist.size()) ) { scroll_timer = true; addTimer(scroll_repeat); @@ -721,7 +752,7 @@ void FListView::onMouseMove (FMouseEvent* ev) drag_scroll = fc::scrollDown; } - if ( current == int(data.size()) ) + if ( current == int(itemlist.size()) ) { delOwnTimer(); drag_scroll = fc::noScroll; @@ -751,7 +782,7 @@ void FListView::onMouseDoubleClick (FMouseEvent* ev) if ( mouse_x > 1 && mouse_x < getWidth() && mouse_y > 1 && mouse_y < getHeight() ) { - if ( yoffset + mouse_y - 1 > int(data.size()) ) + if ( yoffset + mouse_y - 1 > int(itemlist.size()) ) return; processClick(); @@ -761,7 +792,7 @@ void FListView::onMouseDoubleClick (FMouseEvent* ev) //---------------------------------------------------------------------- void FListView::onTimer (FTimerEvent*) { - int element_count = int(data.size()); + int element_count = int(itemlist.size()); int current_before = current; int yoffset_before = yoffset; int yoffset_end = element_count - getClientHeight(); @@ -832,7 +863,7 @@ void FListView::onTimer (FTimerEvent*) void FListView::onWheel (FWheelEvent* ev) { int element_count, current_before, yoffset_before, yoffset_end, wheel; - element_count = int(data.size()); + element_count = int(itemlist.size()); current_before = current; yoffset_before = yoffset; yoffset_end = element_count - getClientHeight(); @@ -933,7 +964,7 @@ void FListView::onFocusOut (FFocusEvent*) //---------------------------------------------------------------------- void FListView::adjustYOffset() { - int element_count = int(data.size()); + int element_count = int(itemlist.size()); if ( yoffset > element_count - getClientHeight() ) yoffset = element_count - getClientHeight(); @@ -955,7 +986,7 @@ void FListView::adjustSize() FWidget::adjustSize(); adjustYOffset(); - element_count = int(data.size()); + element_count = int(itemlist.size()); vbar->setMaximum (element_count - getClientHeight()); vbar->setPageSize (element_count, getClientHeight()); vbar->setX (getWidth()); @@ -984,6 +1015,9 @@ void FListView::adjustSize() //---------------------------------------------------------------------- void FListView::init() { + selflist.push_back(this); + root = selflist.begin(); + setForegroundColor (wc.dialog_fg); setBackgroundColor (wc.dialog_bg); @@ -1203,17 +1237,17 @@ void FListView::drawList() { uInt start, end; bool isFocus; - listViewItems::const_iterator iter; + constFObjectIterator iter; - if ( data.empty() || getHeight() <= 2 || getWidth() <= 4 ) + if ( itemlist.empty() || getHeight() <= 2 || getWidth() <= 4 ) return; isFocus = ((flags & fc::focus) != 0); start = 0; end = uInt(getHeight() - 2); - if ( end > data.size() ) - end = uInt(data.size()); + if ( end > itemlist.size() ) + end = uInt(itemlist.size()); iter = index2iterator(int(start) + yoffset); @@ -1222,6 +1256,7 @@ void FListView::drawList() bool isCurrentLine = bool( y + uInt(yoffset) + 1 == uInt(current) ); setPrintPos (2, 2 + int(y)); setColor (wc.list_fg, wc.list_bg); + FListViewItem* item = static_cast(*iter); if ( isCurrentLine ) { @@ -1253,22 +1288,30 @@ void FListView::drawList() } // print the entry - FString line = " "; + FString line; - if ( tree_view /*&& (*iter)->expandable*/ ) + if ( tree_view ) { - line += "► "; + if ( item->expandable ) + { + line = wchar_t(fc::BlackRightPointingPointer); + line += L' '; + } + else + line = L" "; } + else + line = L" "; // print columns - if ( ! (*iter)->column_value.empty() ) + if ( ! item->column_list.empty() ) { - for (uInt i = 0; i < (*iter)->column_value.size(); ) + for (uInt i = 0; i < item->column_list.size(); ) { static const int leading_space = 1; static const int ellipsis_length = 2; - const FString& text = (*iter)->column_value[i]; + const FString& text = item->column_list[i]; int width = header[i].width; uInt txt_length = text.getLength(); // Increment the value of i for the column position @@ -1277,29 +1320,34 @@ void FListView::drawList() fc::text_alignment align = getColumnAlignment(int(i)); uInt align_offset = getAlignOffset (align, txt_length, uInt(width)); + if ( tree_view && i == 1 ) + { + width--; + } + // Insert alignment spaces if ( align_offset > 0 ) - line += FString(align_offset, ' '); + line += FString(align_offset, L' '); if ( align_offset + txt_length <= uInt(width) ) { // Insert text and tailing space line += text.left(width); line += FString ( leading_space + width - - int(align_offset + txt_length), ' '); + - int(align_offset + txt_length), L' '); } else if ( align == fc::alignRight ) { // Ellipse right align text - line += FString (".."); + line += FString (L".."); line += text.right(width - ellipsis_length); - line += ' '; + line += L' '; } else { // Ellipse left align text and center text line += text.left(width - ellipsis_length); - line += FString (".. "); + line += FString (L".. "); } } } @@ -1367,7 +1415,7 @@ void FListView::cb_VBarChange (FWidget*, data_ptr) { FScrollbar::sType scrollType; int distance = 1; - int element_count = int(data.size()); + int element_count = int(itemlist.size()); int yoffset_before = yoffset; int yoffset_end = element_count - getClientHeight(); scrollType = vbar->getScrollType(); diff --git a/src/flistview.h b/src/flistview.h index 3b0016ce..db57b840 100644 --- a/src/flistview.h +++ b/src/flistview.h @@ -54,12 +54,10 @@ class FListViewItem : public FObject FListViewItem (const FListViewItem&); // copy constructor explicit FListViewItem (FListViewItem*); explicit FListViewItem (FListView*); + explicit FListViewItem (FObjectIterator); FListViewItem ( const std::vector& - , FWidget::data_ptr = 0 - , FListView* = 0 ); - FListViewItem ( const std::vector& - , FWidget::data_ptr = 0 - , FListViewItem* = 0 ); + , FWidget::data_ptr + , FObjectIterator ); // Destructor ~FListViewItem(); @@ -91,7 +89,7 @@ class FListViewItem : public FObject int getVisibleLines(); // Data Member - std::vector column_value; + std::vector column_list; FWidget::data_ptr data_pointer; int visible_lines; bool expandable; @@ -110,7 +108,7 @@ inline const char* FListViewItem::getClassName() const //---------------------------------------------------------------------- inline uInt FListViewItem::getColumnCount() const -{ return uInt(column_value.size()); } +{ return uInt(column_list.size()); } //---------------------------------------------------------------------- inline bool FListViewItem::isExpand() @@ -131,9 +129,6 @@ inline bool FListViewItem::isExpandable() class FListView : public FWidget { public: - // Typedef - typedef std::vector listViewItems; - // Using-declaration using FWidget::setGeometry; @@ -147,7 +142,7 @@ class FListView : public FWidget const char* getClassName() const; fc::text_alignment getColumnAlignment (int) const; FString getColumnText (int) const; - FListViewItem* getCurrentItem() const; + FListViewItem* getCurrentItem(); // Mutators void setGeometry (int, int, int, int, bool = true); @@ -159,13 +154,22 @@ class FListView : public FWidget // Methods virtual int addColumn (const FString&, int = USE_MAX_SIZE); - void insert (FListViewItem*); - void insert ( const std::vector& - , data_ptr = 0 - , FListView* = 0 ); - void insert ( const std::vector& - , data_ptr = 0 - , FListView* = 0 ); + FObjectIterator insert (FListViewItem*); + FObjectIterator insert (FListViewItem*, FObjectIterator); + FObjectIterator insert ( const std::vector& + , data_ptr = 0 ); + FObjectIterator insert ( const std::vector& + , FObjectIterator ); + FObjectIterator insert ( const std::vector& + , data_ptr + , FObjectIterator ); + FObjectIterator insert ( const std::vector& + , data_ptr = 0 ); + FObjectIterator insert ( const std::vector& + , FObjectIterator ); + FObjectIterator insert ( const std::vector& + , data_ptr + , FObjectIterator ); // Event handlers void onKeyPress (FKeyEvent*); @@ -225,14 +229,16 @@ class FListView : public FWidget void recalculateVerticalBar (int); void processClick(); void processChanged(); - listViewItems::iterator index2iterator (int); + FObjectIterator index2iterator (int); // Callback methods void cb_VBarChange (FWidget*, data_ptr); void cb_HBarChange (FWidget*, data_ptr); // Data Members - listViewItems data; + FObjectIterator root; + FObjectList selflist; + FObjectList itemlist; headerItems header; FTermBuffer headerline; FScrollbar* vbar; @@ -260,8 +266,12 @@ inline const char* FListView::getClassName() const { return "FListView"; } //---------------------------------------------------------------------- -inline FListViewItem* FListView::getCurrentItem() const -{ return data[uInt(current-1)]; } +inline FListViewItem* FListView::getCurrentItem() +{ + FObjectIterator iter = itemlist.begin(); + std::advance (iter, current - 1); + return static_cast(*iter); +} //---------------------------------------------------------------------- inline bool FListView::setTreeView (bool on) @@ -276,9 +286,35 @@ inline bool FListView::unsetTreeView() { return setTreeView(false); } //---------------------------------------------------------------------- -inline FListView::listViewItems::iterator FListView::index2iterator (int index) +inline FObject::FObjectIterator FListView::insert (FListViewItem* item) +{ return insert (item, root); } + +//---------------------------------------------------------------------- +inline FObject::FObjectIterator + FListView::insert ( const std::vector& cols, data_ptr d ) +{ return insert (cols, d, root); } + +//---------------------------------------------------------------------- +inline FObject::FObjectIterator + FListView::insert ( const std::vector& cols + , FObjectIterator parent_iter ) +{ return insert (cols, 0, parent_iter); } + +//---------------------------------------------------------------------- +inline FObject::FObjectIterator + FListView::insert ( const std::vector& cols, data_ptr d ) +{ return insert (cols, d, root); } + +//---------------------------------------------------------------------- +inline FObject::FObjectIterator + FListView::insert ( const std::vector& cols + , FObjectIterator parent_iter ) +{ return insert (cols, 0, parent_iter); } + +//---------------------------------------------------------------------- +inline FObject::FObjectIterator FListView::index2iterator (int index) { - listViewItems::iterator iter = data.begin(); + FObjectIterator iter = itemlist.begin(); std::advance (iter, index); return iter; } diff --git a/src/fmenulist.h b/src/fmenulist.h index 89ba2eeb..70e4568b 100644 --- a/src/fmenulist.h +++ b/src/fmenulist.h @@ -89,7 +89,7 @@ inline uInt FMenuList::getCount() const //---------------------------------------------------------------------- inline FMenuItem* FMenuList::getItem (int index) const -{ return (index > 0) ? item_list[uInt(index-1)] : 0; } +{ return (index > 0) ? item_list[uInt(index - 1)] : 0; } //---------------------------------------------------------------------- inline FMenuItem* FMenuList::getSelectedItem() const @@ -97,11 +97,11 @@ inline FMenuItem* FMenuList::getSelectedItem() const //---------------------------------------------------------------------- inline void FMenuList::enableItem (int index) -{ item_list[uInt(index-1)]->setEnable(); } +{ item_list[uInt(index - 1)]->setEnable(); } //---------------------------------------------------------------------- inline void FMenuList::disableItem (int index) -{ item_list[uInt(index-1)]->unsetEnable(); } +{ item_list[uInt(index - 1)]->unsetEnable(); } //---------------------------------------------------------------------- inline void FMenuList::setSelectedItem (FMenuItem* menuitem) @@ -109,7 +109,7 @@ inline void FMenuList::setSelectedItem (FMenuItem* menuitem) //---------------------------------------------------------------------- inline bool FMenuList::isSelected(int index) const -{ return (index > 0) ? item_list[uInt(index-1)]->isSelected() : false; } +{ return (index > 0) ? item_list[uInt(index - 1)]->isSelected() : false; } //---------------------------------------------------------------------- inline bool FMenuList::hasSelectedItem() const diff --git a/src/fobject.cpp b/src/fobject.cpp index 5ec7fc29..a5aabce1 100644 --- a/src/fobject.cpp +++ b/src/fobject.cpp @@ -85,7 +85,7 @@ FObject::~FObject() // destructor if ( ! children.empty() ) { - FObjectList::const_iterator iter; + constFObjectIterator iter; iter = children.begin(); while ( iter != children.end() ) @@ -108,7 +108,7 @@ FObject* FObject::getChild (int index) const if ( index < 0 || index >= numOfChildren() ) return 0; - FObjectList::const_iterator iter; + constFObjectIterator iter; iter = children_list.begin(); std::advance (iter, index); return *iter; diff --git a/src/fobject.h b/src/fobject.h index b2a5e9b6..e84e3766 100644 --- a/src/fobject.h +++ b/src/fobject.h @@ -35,6 +35,8 @@ class FObject public: // Typedef typedef std::list FObjectList; + typedef FObjectList::iterator FObjectIterator; + typedef FObjectList::const_iterator constFObjectIterator; // Constructor explicit FObject (FObject* = 0); diff --git a/src/foptiattr.h b/src/foptiattr.h index c7a5c56d..5aa5a7d5 100644 --- a/src/foptiattr.h +++ b/src/foptiattr.h @@ -40,33 +40,31 @@ class FOptiAttr { struct { + // Attribute byte #0 + uInt8 bold : 1; // bold + uInt8 dim : 1; // dim + uInt8 italic : 1; // italic + uInt8 underline : 1; // underline + uInt8 blink : 1; // blink + uInt8 reverse : 1; // reverse + uInt8 standout : 1; // standout + uInt8 invisible : 1; // invisible // Attribute byte #1 - uChar bold : 1; // bold - uChar dim : 1; // dim - uChar italic : 1; // italic - uChar underline : 1; // underline - uChar blink : 1; // blink - uChar reverse : 1; // reverse - uChar standout : 1; // standout - uChar invisible : 1; // invisible + uInt8 protect : 1; // protect mode + uInt8 crossed_out : 1; // crossed out + uInt8 dbl_underline : 1; // double underline + uInt8 alt_charset : 1; // alternate character set (vt100) + uInt8 pc_charset : 1; // pc character set (CP437) + uInt8 transparent : 1; // transparent + uInt8 trans_shadow : 1; // transparent shadow + uInt8 inherit_bg : 1; // inherit background // Attribute byte #2 - uChar protect : 1; // protect mode - uChar crossed_out : 1; // crossed out - uChar dbl_underline : 1; // double underline - uChar alt_charset : 1; // alternate character set (vt100) - uChar pc_charset : 1; // pc character set (CP437) - uChar transparent : 1; // transparent - uChar trans_shadow : 1; // transparent shadow - uChar inherit_bg : 1; // inherit background - // Attribute byte #3 - uChar no_changes : 1; // no changes required - uChar printed : 1; // is printed to VTerm - uChar : 6; // padding bits + uInt8 no_changes : 1; // no changes required + uInt8 printed : 1; // is printed to VTerm + uInt8 : 6; // padding bits } bit; - uChar byte1; - uChar byte2; - uChar byte3; + uInt8 byte[3]; } attr; } char_data; @@ -277,8 +275,8 @@ inline bool operator == ( const FOptiAttr::char_data& lhs, return lhs.code == rhs.code && lhs.fg_color == rhs.fg_color && lhs.bg_color == rhs.bg_color - && lhs.attr.byte1 == rhs.attr.byte1 - && lhs.attr.byte2 == rhs.attr.byte2; + && lhs.attr.byte[0] == rhs.attr.byte[0] + && lhs.attr.byte[1] == rhs.attr.byte[1]; } //---------------------------------------------------------------------- diff --git a/src/fpoint.h b/src/fpoint.h index 897715aa..272f7fdc 100644 --- a/src/fpoint.h +++ b/src/fpoint.h @@ -92,11 +92,11 @@ inline bool operator != (const FPoint& p1, const FPoint& p2) //---------------------------------------------------------------------- inline FPoint operator + (const FPoint& p1, const FPoint& p2) -{ return FPoint(p1.xpos+p2.xpos, p1.ypos+p2.ypos); } +{ return FPoint(p1.xpos + p2.xpos, p1.ypos + p2.ypos); } //---------------------------------------------------------------------- inline FPoint operator - (const FPoint& p1, const FPoint& p2) -{ return FPoint(p1.xpos-p2.xpos, p1.ypos-p2.ypos); } +{ return FPoint(p1.xpos - p2.xpos, p1.ypos - p2.ypos); } //---------------------------------------------------------------------- inline FPoint operator - (const FPoint& p) diff --git a/src/fstatusbar.h b/src/fstatusbar.h index 387f423b..b108658a 100644 --- a/src/fstatusbar.h +++ b/src/fstatusbar.h @@ -242,7 +242,7 @@ inline const char* FStatusBar::getClassName() const //---------------------------------------------------------------------- inline FStatusKey* FStatusBar::getStatusKey (int index) const -{ return key_list[uInt(index-1)]; } +{ return key_list[uInt(index - 1)]; } //---------------------------------------------------------------------- inline uInt FStatusBar::getCount() const @@ -250,15 +250,15 @@ inline uInt FStatusBar::getCount() const //---------------------------------------------------------------------- inline void FStatusBar::activateKey (int index) -{ key_list[uInt(index-1)]->setActive(); } +{ key_list[uInt(index - 1)]->setActive(); } //---------------------------------------------------------------------- inline void FStatusBar::deactivateKey (int index) -{ key_list[uInt(index-1)]->unsetActive(); } +{ key_list[uInt(index - 1)]->unsetActive(); } //---------------------------------------------------------------------- inline bool FStatusBar::isActivated(int index) const -{ return key_list[uInt(index-1)]->isActivated(); } +{ return key_list[uInt(index - 1)]->isActivated(); } //---------------------------------------------------------------------- inline FString FStatusBar::getMessage() const diff --git a/src/fstring.h b/src/fstring.h index 45a44aff..2605f579 100644 --- a/src/fstring.h +++ b/src/fstring.h @@ -360,7 +360,7 @@ inline wchar_t FString::front() const inline wchar_t FString::back() const { assert( ! isEmpty() ); - return string[length-1]; + return string[length - 1]; } //---------------------------------------------------------------------- diff --git a/src/fvterm.cpp b/src/fvterm.cpp index 851cf863..a7bf8038 100644 --- a/src/fvterm.cpp +++ b/src/fvterm.cpp @@ -480,27 +480,12 @@ int FVTerm::print (term_area* area, const FString& s) int ay = area->cursor_y - 1; char_data nc; // next character - nc.code = *p; - nc.fg_color = next_attribute.fg_color; - nc.bg_color = next_attribute.bg_color; - nc.attr.bit.bold = next_attribute.attr.bit.bold; - nc.attr.bit.dim = next_attribute.attr.bit.dim; - nc.attr.bit.italic = next_attribute.attr.bit.italic; - nc.attr.bit.underline = next_attribute.attr.bit.underline; - nc.attr.bit.blink = next_attribute.attr.bit.blink; - nc.attr.bit.reverse = next_attribute.attr.bit.reverse; - nc.attr.bit.standout = next_attribute.attr.bit.standout; - nc.attr.bit.invisible = next_attribute.attr.bit.invisible; - nc.attr.bit.protect = next_attribute.attr.bit.protect; - nc.attr.bit.crossed_out = next_attribute.attr.bit.crossed_out; - nc.attr.bit.dbl_underline = next_attribute.attr.bit.dbl_underline; - nc.attr.bit.alt_charset = next_attribute.attr.bit.alt_charset; - nc.attr.bit.pc_charset = next_attribute.attr.bit.pc_charset; - nc.attr.bit.transparent = next_attribute.attr.bit.transparent; - nc.attr.bit.trans_shadow = next_attribute.attr.bit.trans_shadow; - nc.attr.bit.inherit_bg = next_attribute.attr.bit.inherit_bg; - nc.attr.bit.no_changes = false; - nc.attr.bit.printed = false; + nc.code = *p; + nc.fg_color = next_attribute.fg_color; + nc.bg_color = next_attribute.bg_color; + nc.attr.byte[0] = next_attribute.attr.byte[0]; + nc.attr.byte[1] = next_attribute.attr.byte[1]; + nc.attr.byte[2] = 0; if ( area->cursor_x > 0 && area->cursor_y > 0 @@ -730,27 +715,12 @@ int FVTerm::print (term_area* area, register int c) ax = area->cursor_x - 1; ay = area->cursor_y - 1; - nc.code = c; - nc.fg_color = next_attribute.fg_color; - nc.bg_color = next_attribute.bg_color; - nc.attr.bit.bold = next_attribute.attr.bit.bold; - nc.attr.bit.dim = next_attribute.attr.bit.dim; - nc.attr.bit.italic = next_attribute.attr.bit.italic; - nc.attr.bit.underline = next_attribute.attr.bit.underline; - nc.attr.bit.blink = next_attribute.attr.bit.blink; - nc.attr.bit.reverse = next_attribute.attr.bit.reverse; - nc.attr.bit.standout = next_attribute.attr.bit.standout; - nc.attr.bit.invisible = next_attribute.attr.bit.invisible; - nc.attr.bit.protect = next_attribute.attr.bit.protect; - nc.attr.bit.crossed_out = next_attribute.attr.bit.crossed_out; - nc.attr.bit.dbl_underline = next_attribute.attr.bit.dbl_underline; - nc.attr.bit.alt_charset = next_attribute.attr.bit.alt_charset; - nc.attr.bit.pc_charset = next_attribute.attr.bit.pc_charset; - nc.attr.bit.transparent = next_attribute.attr.bit.transparent; - nc.attr.bit.trans_shadow = next_attribute.attr.bit.trans_shadow; - nc.attr.bit.inherit_bg = next_attribute.attr.bit.inherit_bg; - nc.attr.bit.no_changes = false; - nc.attr.bit.printed = false; + nc.code = c; + nc.fg_color = next_attribute.fg_color; + nc.bg_color = next_attribute.bg_color; + nc.attr.byte[0] = next_attribute.attr.byte[0]; + nc.attr.byte[1] = next_attribute.attr.byte[1]; + nc.attr.byte[2] = 0; if ( area->cursor_x > 0 && area->cursor_y > 0 @@ -1024,27 +994,12 @@ void FVTerm::resizeArea ( int offset_left, int offset_top area->bottom_shadow = bsh; area->has_changes = false; - default_char.code = ' '; - default_char.fg_color = fc::Default; - default_char.bg_color = fc::Default; - default_char.attr.bit.bold = 0; - default_char.attr.bit.dim = 0; - default_char.attr.bit.italic = 0; - default_char.attr.bit.underline = 0; - default_char.attr.bit.blink = 0; - default_char.attr.bit.reverse = 0; - default_char.attr.bit.standout = 0; - default_char.attr.bit.invisible = 0; - default_char.attr.bit.protect = 0; - default_char.attr.bit.crossed_out = 0; - default_char.attr.bit.dbl_underline = 0; - default_char.attr.bit.alt_charset = 0; - default_char.attr.bit.pc_charset = 0; - default_char.attr.bit.transparent = 0; - default_char.attr.bit.trans_shadow = 0; - default_char.attr.bit.inherit_bg = 0; - default_char.attr.bit.no_changes = 0; - default_char.attr.bit.printed = 0; + default_char.code = ' '; + default_char.fg_color = fc::Default; + default_char.bg_color = fc::Default; + default_char.attr.byte[0] = 0; + default_char.attr.byte[1] = 0; + default_char.attr.byte[3] = 0; std::fill_n (area->text, area_size, default_char); diff --git a/src/fwidget.cpp b/src/fwidget.cpp index e8ac7fe3..8017db74 100644 --- a/src/fwidget.cpp +++ b/src/fwidget.cpp @@ -172,7 +172,7 @@ FWidget* FWidget::getFirstFocusableWidget (FObjectList children) if ( children.empty() ) return 0; - FObjectList::const_iterator iter, end; + constFObjectIterator iter, end; iter = children.begin(); end = children.end(); @@ -198,7 +198,7 @@ FWidget* FWidget::getLastFocusableWidget (FObjectList children) if ( children.empty() ) return 0; - FObjectList::const_iterator iter, begin; + constFObjectIterator iter, begin; begin = children.begin(); iter = children.end(); @@ -839,7 +839,7 @@ FWidget* FWidget::childWidgetAt (FWidget* p, int x, int y) if ( p && p->hasChildren() ) { FObjectList children; - FObjectList::const_iterator iter, end; + constFObjectIterator iter, end; children = p->getChildren(); iter = children.begin(); @@ -875,7 +875,7 @@ FWidget* FWidget::childWidgetAt (FWidget* p, int x, int y) int FWidget::numOfFocusableChildren() { FObjectList children; - FObjectList::const_iterator iter, end; + constFObjectIterator iter, end; if ( ! this->hasChildren() ) return 0; @@ -1100,25 +1100,11 @@ void FWidget::redraw() { // draw windows FOptiAttr::char_data default_char; - default_char.code = ' '; - default_char.fg_color = fc::Black; - default_char.bg_color = fc::Black; - default_char.attr.bit.bold = 0; - default_char.attr.bit.dim = 0; - default_char.attr.bit.italic = 0; - default_char.attr.bit.underline = 0; - default_char.attr.bit.blink = 0; - default_char.attr.bit.reverse = 0; - default_char.attr.bit.standout = 0; - default_char.attr.bit.invisible = 0; - default_char.attr.bit.protect = 0; - default_char.attr.bit.crossed_out = 0; - default_char.attr.bit.dbl_underline = 0; - default_char.attr.bit.alt_charset = 0; - default_char.attr.bit.pc_charset = 0; - default_char.attr.bit.transparent = 0; - default_char.attr.bit.trans_shadow = 0; - default_char.attr.bit.inherit_bg = 0; + default_char.code = ' '; + default_char.fg_color = fc::Black; + default_char.bg_color = fc::Black; + default_char.attr.byte[0] = 0; + default_char.attr.byte[1] = 0; if ( window_list && ! window_list->empty() ) { @@ -1148,7 +1134,7 @@ void FWidget::redraw() if ( this->hasChildren() ) { FObjectList children; - FObjectList::const_iterator iter, end; + constFObjectIterator iter, end; children = this->getChildren(); iter = children.begin(); @@ -1246,7 +1232,7 @@ void FWidget::show() if ( this->hasChildren() ) { FObjectList children; - FObjectList::const_iterator iter, end; + constFObjectIterator iter, end; children = this->getChildren(); iter = children.begin(); @@ -1303,7 +1289,7 @@ void FWidget::hide() bool FWidget::focusFirstChild() { FObjectList children; - FObjectList::const_iterator iter, end; + constFObjectIterator iter, end; if ( ! this->hasChildren() ) return false; @@ -1349,7 +1335,7 @@ bool FWidget::focusFirstChild() bool FWidget::focusLastChild() { FObjectList children; - FObjectList::const_iterator iter, begin; + constFObjectIterator iter, begin; if ( ! this->hasChildren() ) return false; @@ -1840,7 +1826,7 @@ void FWidget::adjustSize() if ( this->hasChildren() ) { FObjectList children; - FObjectList::const_iterator iter, end; + constFObjectIterator iter, end; children = this->getChildren(); iter = children.begin(); @@ -1896,7 +1882,7 @@ bool FWidget::focusNextChild() if ( parent->hasChildren() && parent->numOfFocusableChildren() > 1 ) { FObjectList children; - FObjectList::iterator iter, end; + FObjectIterator iter, end; children = parent->getChildren(); iter = children.begin(); @@ -1915,7 +1901,7 @@ bool FWidget::focusNextChild() if ( w == this ) { FWidget* next = 0; - FObjectList::const_iterator next_element; + constFObjectIterator next_element; next_element = iter; do @@ -1990,7 +1976,7 @@ bool FWidget::focusPrevChild() if ( parent->hasChildren() && parent->numOfFocusableChildren() > 1 ) { FObjectList children; - FObjectList::iterator iter, begin; + FObjectIterator iter, begin; children = parent->getChildren(); iter = children.end(); @@ -2008,7 +1994,7 @@ bool FWidget::focusPrevChild() if ( w == this ) { FWidget* prev = 0; - FObjectList::const_iterator prev_element; + constFObjectIterator prev_element; prev_element = iter; do diff --git a/test/treeview.cpp b/test/treeview.cpp index f7a74b0b..03ae2d84 100644 --- a/test/treeview.cpp +++ b/test/treeview.cpp @@ -57,6 +57,9 @@ Treeview::Treeview (FWidget* parent) listView->setColumnAlignment (2, fc::alignRight); listView->setColumnAlignment (3, fc::alignRight); + // Activate tree view + listView->setTreeView(); + // Populate FListView with a list of items std::string continent[][3] = { @@ -77,8 +80,11 @@ Treeview::Treeview (FWidget* parent) listView->insert (line); } - // Enable the tree view - listView->setTreeView(); + std::string egypt[3] = { "Egypt", "94,666,000", "87" }; + std::vector egypt_line (&egypt[0], &egypt[0] + 3); + FObjectIterator iter_africa = listView->insert (egypt_line); + listView->insert (egypt_line, iter_africa); + // Quit button FButton* Quit = new FButton (this);