37 Base::initialiseOverride();
39 std::string skinButtonEmpty;
51 mWidthSeparator = utility::parseValue<int>(
getUserString(
"WidthSeparator"));
55 mHeightButton = utility::parseValue<int>(
getUserString(
"HeightButton"));
56 if (mHeightButton < 0)
64 if (mClient !=
nullptr)
67 if (
nullptr == mClient)
73 if (mWidgetEmpty ==
nullptr)
78 if (!skinButtonEmpty.empty())
82 if (getUpdateByResize())
90 Base::shutdownOverride();
95 MYGUI_ASSERT_RANGE(_column, mVectorColumnInfo.size(),
"MultiListBox::setColumnNameAt");
96 mVectorColumnInfo[_column].name = _name;
104 MYGUI_ASSERT_RANGE(_column, mVectorColumnInfo.size(),
"MultiListBox::setColumnWidthAt");
105 mVectorColumnInfo[_column].width = _width;
111 MYGUI_ASSERT_RANGE(_column, mVectorColumnInfo.size(),
"MultiListBox::getColumnNameAt");
112 return mVectorColumnInfo[_column].name;
117 MYGUI_ASSERT_RANGE(_column, mVectorColumnInfo.size(),
"MultiListBox::getColumnWidthAt");
118 return mVectorColumnInfo[_column].width;
123 while (!mVectorColumnInfo.empty())
129 mSortColumnIndex = _column;
150 if (mVectorColumnInfo.empty())
152 return mVectorColumnInfo.front().list->getItemCount();
158 for (VectorColumnInfo::iterator iter = mVectorColumnInfo.begin(); iter != mVectorColumnInfo.end(); ++iter)
160 (*iter).list->removeAllItems();
166 void MultiListBox::updateBackSelected(
size_t _index)
170 for (VectorColumnInfo::iterator iter = mVectorColumnInfo.begin(); iter != mVectorColumnInfo.end(); ++iter)
172 (*iter).list->clearIndexSelected();
177 for (VectorColumnInfo::iterator iter = mVectorColumnInfo.begin(); iter != mVectorColumnInfo.end(); ++iter)
179 (*iter).list->setIndexSelected(_index);
186 if (_index == mItemSelected)
189 MYGUI_ASSERT(!mVectorColumnInfo.empty(),
"MultiListBox::setIndexSelected");
192 mItemSelected = _index;
198 MYGUI_ASSERT_RANGE(_index, mVectorColumnInfo.begin()->list->getItemCount(),
"MultiListBox::setSubItemAt");
204 if (_column == mSortColumnIndex)
210 MYGUI_ASSERT_RANGE(_index, mVectorColumnInfo.begin()->list->getItemCount(),
"MultiListBox::getSubItemNameAt");
222 int MultiListBox::getButtonHeight()
const
224 if (mHeaderPlace !=
nullptr)
226 return mHeightButton;
229 void MultiListBox::updateOnlyEmpty()
231 if (
nullptr == mWidgetEmpty)
235 if (mWidthBar >= mClient->
getWidth())
239 mWidgetEmpty->
setCoord(mWidthBar, 0, mClient->
getWidth() - mWidthBar, getButtonHeight());
244 void MultiListBox::notifyListChangePosition(ListBox* _sender,
size_t _position)
246 for (VectorColumnInfo::iterator iter = mVectorColumnInfo.begin(); iter != mVectorColumnInfo.end(); ++iter)
248 if (_sender != (*iter).list)
249 (*iter).list->setIndexSelected(_position);
252 updateBackSelected(_position);
260 void MultiListBox::notifyListSelectAccept(ListBox* _sender,
size_t _position)
266 void MultiListBox::notifyListChangeFocus(ListBox* _sender,
size_t _position)
268 for (VectorColumnInfo::iterator iter = mVectorColumnInfo.begin(); iter != mVectorColumnInfo.end(); ++iter)
270 if (_sender != (*iter).list)
273 (*iter).list->_setItemFocus(mLastMouseFocusIndex,
false);
275 (*iter).list->_setItemFocus(_position,
true);
278 mLastMouseFocusIndex = _position;
281 void MultiListBox::notifyListChangeScrollPosition(ListBox* _sender,
size_t _position)
283 for (VectorColumnInfo::iterator iter = mVectorColumnInfo.begin(); iter != mVectorColumnInfo.end(); ++iter)
285 if (_sender != (*iter).list)
286 (*iter).list->setScrollPosition(_position);
296 void MultiListBox::redrawButtons()
299 for (VectorColumnInfo::iterator iter = mVectorColumnInfo.begin(); iter != mVectorColumnInfo.end(); ++iter)
301 if (pos == mSortColumnIndex)
304 (*iter).button->setImageName(
"Up");
306 (*iter).button->setImageName(
"Down");
309 (*iter).button->setImageName(
"None");
311 (*iter).button->setCaption((*iter).name);
316 void MultiListBox::frameEntered(
float _frame)
321 void MultiListBox::frameAdvise(
bool _advise)
336 mFrameAdvise =
false;
341 Widget* MultiListBox::getSeparator(
size_t _index)
343 if (!mWidthSeparator || mSkinSeparator.empty())
346 if (_index == mVectorColumnInfo.size() - 1)
349 while (_index >= mSeparators.size())
352 mSeparators.push_back(separator);
355 return mSeparators[_index];
358 void MultiListBox::flipList()
363 size_t last = mVectorColumnInfo.front().list->getItemCount();
372 for (VectorColumnInfo::iterator iter = mVectorColumnInfo.begin(); iter != mVectorColumnInfo.end(); ++iter)
374 (*iter).list->swapItemsAt(first, last);
384 bool MultiListBox::compare(ListBox* _list,
size_t _left,
size_t _right)
388 std::swap(_left, _right);
390 result = _list->getItemNameAt(_left) < _list->getItemNameAt(_right);
392 requestOperatorLess(
this, mSortColumnIndex, _list->getItemNameAt(_left), _list->getItemNameAt(_right), result);
396 void MultiListBox::sortList()
401 ListBox* list = mVectorColumnInfo[mSortColumnIndex].list;
403 size_t count = list->getItemCount();
410 for (
size_t step = count >> 1; step > 0 ; step >>= 1)
412 for (
size_t i = 0; i < (count - step); i++)
418 if (compare(list, first, last))
421 for (VectorColumnInfo::iterator iter = mVectorColumnInfo.begin(); iter != mVectorColumnInfo.end(); ++iter)
423 (*iter).list->swapItemsAt(first, last);
438 MYGUI_ASSERT(!mVectorColumnInfo.empty(),
"MultiListBox::insertItemAt");
441 _index = mVectorColumnInfo.front().list->getItemCount();
445 if ((mItemSelected !=
ITEM_NONE) && (_index <= mItemSelected))
451 for (VectorColumnInfo::iterator iter = mVectorColumnInfo.begin(); iter != mVectorColumnInfo.end(); ++iter)
453 (*iter).list->insertItemAt(index,
"");
455 mVectorColumnInfo.front().list->setItemNameAt(index, _name);
456 mVectorColumnInfo.front().list->setItemDataAt(index, _data);
463 MYGUI_ASSERT(!mVectorColumnInfo.empty(),
"MultiListBox::removeItemAt");
464 MYGUI_ASSERT_RANGE(_index, mVectorColumnInfo.begin()->list->getItemCount(),
"MultiListBox::removeItemAt");
468 for (VectorColumnInfo::iterator iter = mVectorColumnInfo.begin(); iter != mVectorColumnInfo.end(); ++iter)
470 (*iter).list->removeItemAt(index);
474 size_t count = mVectorColumnInfo.begin()->list->getItemCount();
479 if (_index < mItemSelected)
481 else if ((_index == mItemSelected) && (mItemSelected == count))
489 MYGUI_ASSERT(!mVectorColumnInfo.empty(),
"MultiListBox::removeItemAt");
490 MYGUI_ASSERT_RANGE(_index1, mVectorColumnInfo.begin()->list->getItemCount(),
"MultiListBox::swapItemsAt");
491 MYGUI_ASSERT_RANGE(_index2, mVectorColumnInfo.begin()->list->getItemCount(),
"MultiListBox::swapItemsAt");
502 MYGUI_ASSERT_RANGE(_index, mVectorColumnInfo.size(),
"MultiListBox::setColumnDataAt");
503 mVectorColumnInfo[_index].data = _data;
508 MYGUI_ASSERT_RANGE(_index, mVectorColumnInfo.begin()->list->getItemCount(),
"MultiListBox::setSubItemDataAt");
516 return mVectorColumnInfo.size();
546 return mItemSelected;
569 ListBox* MultiListBox::getSubItemAt(
size_t _column)
572 return mVectorColumnInfo[_column].list;
605 _column = mVectorColumnInfo.size();
609 mVectorColumnInfo.back().width = _width;
611 mVectorColumnInfo.back().name = _name;
612 mVectorColumnInfo.back().data = _data;
613 mVectorColumnInfo.back().button->setCaption(_name);
615 if (_column == (mVectorColumnInfo.size() - 1))
619 mVectorColumnInfo.back().list->setScrollVisible(
true);
623 _swapColumnsAt(_column, mVectorColumnInfo.size() - 1);
629 MYGUI_ASSERT_RANGE(_column, mVectorColumnInfo.size(),
"MultiListBox::removeColumnAt");
631 ColumnInfo& info = mVectorColumnInfo[_column];
641 _swapColumnsAt(_index1, _index2);
644 void MultiListBox::_swapColumnsAt(
size_t _index1,
size_t _index2)
646 if (_index1 == _index2)
649 mVectorColumnInfo[_index1].list->setScrollVisible(
false);
650 mVectorColumnInfo[_index2].list->setScrollVisible(
false);
652 std::swap(mVectorColumnInfo[_index1], mVectorColumnInfo[_index2]);
656 mVectorColumnInfo.back().list->setScrollVisible(
true);
661 Base::onWidgetCreated(_widget);
664 if (child !=
nullptr)
672 Base::onWidgetDestroy(_widget);
675 if (child !=
nullptr)
681 for (VectorColumnInfo::iterator item = mVectorColumnInfo.begin(); item != mVectorColumnInfo.end(); ++item)
683 if ((*item).button == _widget)
684 (*item).button =
nullptr;
692 if (!mVectorColumnInfo.empty())
693 mVectorColumnInfo.back().list->setScrollVisible(
false);
703 column.list->eventListChangePosition +=
newDelegate(
this, &MultiListBox::notifyListChangePosition);
704 column.list->eventListMouseItemFocus +=
newDelegate(
this, &MultiListBox::notifyListChangeFocus);
705 column.list->eventListChangeScroll +=
newDelegate(
this, &MultiListBox::notifyListChangeScrollPosition);
706 column.list->eventListSelectAccept +=
newDelegate(
this, &MultiListBox::notifyListSelectAccept);
708 if (mHeaderPlace !=
nullptr)
716 if (!mVectorColumnInfo.empty())
718 size_t count = mVectorColumnInfo.front().list->getItemCount();
719 for (
size_t pos = 0; pos < count; ++pos)
720 column.list->addItem(
"");
723 mVectorColumnInfo.push_back(column);
728 mVectorColumnInfo.back().list->setScrollVisible(
true);
731 void MultiListBox::_unwrapItem(MultiListItem* _item)
733 for (VectorColumnInfo::iterator item = mVectorColumnInfo.begin(); item != mVectorColumnInfo.end(); ++item)
735 if ((*item).item == _item)
737 if ((*item).button !=
nullptr)
740 mVectorColumnInfo.erase(item);
745 if (mVectorColumnInfo.empty())
759 if (!mVectorColumnInfo.empty())
760 mVectorColumnInfo.back().list->setScrollVisible(
true);
766 return mVectorColumnInfo[_index].item;
781 for (
size_t index = 0; index < mVectorColumnInfo.size(); ++ index)
783 if (mVectorColumnInfo[index].item == _item)
797 MYGUI_ASSERT_RANGE(_index, mVectorColumnInfo.size(),
"MultiListBox::setColumnWidthAt");
798 mVectorColumnInfo[_index].sizeType = _value;
809 Base::setPosition(_point);
814 Base::setSize(_size);
816 if (getUpdateByResize())
822 Base::setCoord(_coord);
824 if (getUpdateByResize())
843 bool MultiListBox::getUpdateByResize()
845 if (mWidgetEmpty !=
nullptr)
848 for (VectorColumnInfo::iterator item = mVectorColumnInfo.begin(); item != mVectorColumnInfo.end(); ++item)
856 int MultiListBox::getColumnWidth(
size_t _index,
int _freeSpace,
size_t _countStars,
size_t _lastIndexStar,
int _starWidth)
const
858 const ColumnInfo& info = mVectorColumnInfo[_index];
862 return info.realWidth;
866 return info.realWidth;
870 if (_lastIndexStar == _index)
872 return _starWidth + _freeSpace - (_starWidth * _countStars);
882 int MultiListBox::updateWidthColumns(
size_t& _countStars,
size_t& _lastIndexStar)
889 for (
size_t index = 0; index < mVectorColumnInfo.size(); ++ index)
891 ColumnInfo& info = mVectorColumnInfo[index];
895 info.realWidth = info.button->getWidth() - info.button->getTextRegion().width + info.button->getTextSize().width;
899 info.realWidth = info.width < 0 ? 0 : info.width;
905 _lastIndexStar = index;
912 width += info.realWidth;
918 void MultiListBox::updateColumns()
920 size_t countStars = 0;
923 int allColumnsWidth = updateWidthColumns(countStars, lastIndexStar);
924 int clientWidth = mClient->
getWidth();
925 int separatorsWidth = mVectorColumnInfo.empty() ? 0 : (mVectorColumnInfo.size() - 1) * mWidthSeparator;
926 int freeSpace = clientWidth - separatorsWidth - allColumnsWidth;
927 int starWidth = (countStars != 0 && freeSpace > 0) ? (freeSpace / countStars) : 0;
930 for (
size_t index = 0; index < mVectorColumnInfo.size(); ++ index)
932 ColumnInfo& info = mVectorColumnInfo[index];
934 int columnWidth = getColumnWidth(index, freeSpace, countStars, lastIndexStar, starWidth);
936 if (mHeaderPlace !=
nullptr)
938 info.item->setCoord(mWidthBar, 0, columnWidth, mClient->
getHeight());
942 info.item->setCoord(mWidthBar, mHeightButton, columnWidth, mClient->
getHeight() - mHeightButton);
945 info.button->setCoord(mWidthBar, 0, columnWidth, getButtonHeight());
946 info.button->_setInternalData(index);
948 mWidthBar += columnWidth;
951 Widget* separator = getSeparator(index);
954 separator->setCoord(mWidthBar, 0, mWidthSeparator, mClient->
getHeight());
957 mWidthBar += mWidthSeparator;