43 mNeedVisibleScroll(true)
49 Base::_initialise(_style, _coord, _align, _info, _parent, _croppedParent, _creator, _name);
51 initialiseWidgetSkin(_info);
63 initialiseWidgetSkin(_info);
73 if (*(*iter)->_getInternalData<std::string>() ==
"VScroll")
80 else if (*(*iter)->_getInternalData<std::string>() ==
"Client")
92 MapString::const_iterator iterS = properties.find(
"SkinLine");
93 if (iterS != properties.end()) mSkinLine = iterS->second;
96 iterS = properties.find(
"HeightLine");
98 if (mHeightLine < 1) mHeightLine = 1;
101 if (mWidgetScroll !=
nullptr)
111 void List::shutdownWidgetSkin()
113 mWidgetScroll =
nullptr;
149 size_t sel = mIndexSelect;
174 if (sel != 0) sel = 0;
192 size_t page = _getClientWidget()->
getHeight() / mHeightLine;
193 if (sel <= page) sel = 0;
206 sel += _getClientWidget()->
getHeight() / mHeightLine;
226 if (sel != mIndexSelect)
231 if (mWidgetScroll !=
nullptr)
246 if (mRangeIndex <= 0)
249 if (mWidgetScroll ==
nullptr)
253 if (_rel < 0) offset += mHeightLine;
254 else offset -= mHeightLine;
256 if (offset >= mRangeIndex) offset = mRangeIndex;
257 else if (offset < 0) offset = 0;
277 if (_sender == mWidgetScroll)
281 if (_sender == _getClientWidget())
297 #if MYGUI_DEBUG_MODE == 1
298 _checkMapping(
"List::notifyMousePressed");
305 if (mIndexSelect != index)
309 mIndexSelect = index;
346 mRangeIndex = (mHeightLine * (int)mItemsInfo.size()) - _getClientWidget()->
getHeight();
348 if (mWidgetScroll ==
nullptr)
351 if ( (!mNeedVisibleScroll) || (mRangeIndex < 1) || (mWidgetScroll->
getLeft() <= _getClientWidget()->
getLeft()) )
369 if ((
int)mItemsInfo.size()) mWidgetScroll->
setTrackSize( mWidgetScroll->
getLineSize() * _getClientWidget()->
getHeight() / mHeightLine / (int)mItemsInfo.size() );
382 int position = mTopIndex * mHeightLine + mOffsetTop;
387 int height = (int)mWidgetLines.size() * mHeightLine - mOffsetTop;
390 while ( (height <= (_getClientWidget()->
getHeight() + mHeightLine)) && (mWidgetLines.size() < mItemsInfo.size()) )
403 mWidgetLines.push_back(line);
404 height += mHeightLine;
408 if (position >= mRangeIndex)
411 if (mRangeIndex <= 0)
414 if (position || mOffsetTop || mTopIndex)
423 for (
size_t pos=0; pos<mWidgetLines.size(); pos++)
425 mWidgetLines[pos]->setPosition(0, offset);
426 offset += mHeightLine;
434 int count = _getClientWidget()->
getHeight() / mHeightLine;
435 mOffsetTop = mHeightLine - (_getClientWidget()->
getHeight() % mHeightLine);
437 if (mOffsetTop == mHeightLine)
443 int top = (int)mItemsInfo.size() - count - 1;
446 int offset = 0 - mOffsetTop;
447 for (
size_t pos=0; pos<mWidgetLines.size(); pos++)
449 mWidgetLines[pos]->setPosition(0, offset);
450 offset += mHeightLine;
454 position = top * mHeightLine + mOffsetTop;
457 if (top != mTopIndex)
472 if (mWidgetScroll !=
nullptr)
478 #if MYGUI_DEBUG_MODE == 1
479 _checkMapping(
"List::updateLine");
488 for (; pos<mWidgetLines.size(); pos++)
491 size_t index = pos + (size_t)mTopIndex;
494 if (index >= mItemsInfo.size())
497 mLastRedrawLine = pos;
503 mLastRedrawLine = pos;
508 mWidgetLines[pos]->setVisible(
true);
510 mWidgetLines[pos]->setCaption(mItemsInfo[index].first);
513 static_cast<Button*
>(mWidgetLines[pos])->setButtonPressed(index == mIndexSelect);
517 if (pos >= mWidgetLines.size()) mLastRedrawLine = pos;
521 for (; pos<mWidgetLines.size(); pos++)
523 static_cast<Button*
>(mWidgetLines[pos])->setButtonPressed(
false);
529 #if MYGUI_DEBUG_MODE == 1
530 _checkMapping(
"List::_redrawItemRange");
539 if (_index < (
size_t)mTopIndex)
return;
540 _index -= (size_t)mTopIndex;
542 if (_index >= mLastRedrawLine)
return;
546 mWidgetLines[_index]->setCaption(mItemsInfo[_index + mTopIndex].first);
548 #if MYGUI_DEBUG_MODE == 1
549 _checkMapping(
"List::_redrawItem");
557 if (_index ==
ITEM_NONE) _index = mItemsInfo.size();
560 mItemsInfo.insert(mItemsInfo.begin() + _index, PairItem(_name, _data));
563 if ( (mIndexSelect !=
ITEM_NONE) && (_index <= mIndexSelect) ) mIndexSelect++;
566 if ((_index <= (
size_t)mTopIndex) && (mRangeIndex > 0))
570 if (mWidgetScroll !=
nullptr)
573 if ((
int)mItemsInfo.size()) mWidgetScroll->
setTrackSize( mWidgetScroll->
getLineSize() * _getClientWidget()->
getHeight() / mHeightLine / (int)mItemsInfo.size() );
576 mRangeIndex += mHeightLine;
581 int offset = ((int)_index - mTopIndex) * mHeightLine - mOffsetTop;
584 if (_getClientWidget()->
getHeight() < (offset - mHeightLine))
587 if (mWidgetScroll !=
nullptr)
590 if ((
int)mItemsInfo.size()) mWidgetScroll->
setTrackSize( mWidgetScroll->
getLineSize() * _getClientWidget()->
getHeight() / mHeightLine / (int)mItemsInfo.size() );
593 mRangeIndex += mHeightLine;
607 #if MYGUI_DEBUG_MODE == 1
608 _checkMapping(
"List::insertItemAt");
618 mItemsInfo.erase(mItemsInfo.begin() + _index);
621 if (mItemsInfo.empty()) mIndexSelect =
ITEM_NONE;
624 if (_index < mIndexSelect) mIndexSelect--;
625 else if ( (_index == mIndexSelect) && (mIndexSelect == (mItemsInfo.size())) ) mIndexSelect--;
629 if (mWidgetLines.size() > mItemsInfo.size())
631 mWidgetLines[mItemsInfo.size()]->setVisible(
false);
635 if (_index < (
size_t)mTopIndex)
639 if (mWidgetScroll !=
nullptr)
642 if ((
int)mItemsInfo.size()) mWidgetScroll->
setTrackSize( mWidgetScroll->
getLineSize() * _getClientWidget()->
getHeight() / mHeightLine / (int)mItemsInfo.size() );
645 mRangeIndex -= mHeightLine;
650 int offset = ((int)_index - mTopIndex) * mHeightLine - mOffsetTop;
653 if (_getClientWidget()->
getHeight() < offset)
656 if (mWidgetScroll !=
nullptr)
659 if ((
int)mItemsInfo.size()) mWidgetScroll->
setTrackSize( mWidgetScroll->
getLineSize() * _getClientWidget()->
getHeight() / mHeightLine / (int)mItemsInfo.size() );
662 mRangeIndex -= mHeightLine;
676 #if MYGUI_DEBUG_MODE == 1
677 _checkMapping(
"List::removeItemAt");
685 if (mIndexSelect != _index)
689 mIndexSelect = _index;
697 if (_index < (
size_t)mTopIndex)
return;
699 int offset = ((int)_index - mTopIndex) * mHeightLine - mOffsetTop;
701 if (_getClientWidget()->
getHeight() < offset)
return;
703 size_t index = _index - mTopIndex;
704 if (index < mWidgetLines.size())
705 static_cast<Button*>(mWidgetLines[index])->setButtonPressed(_select);
707 #if MYGUI_DEBUG_MODE == 1
708 _checkMapping(
"List::_selectIndex");
716 if (mRangeIndex <= 0)
return;
718 int offset = (int)_index * mHeightLine;
719 if (offset >= mRangeIndex) offset = mRangeIndex;
721 if (mWidgetScroll !=
nullptr)
728 #if MYGUI_DEBUG_MODE == 1
729 _checkMapping(
"List::beginToItemAt");
738 if (_index >= mItemsInfo.size())
return false;
740 if (mRangeIndex <= 0)
return true;
743 if (_index < (
size_t)mTopIndex)
return false;
746 if (_index == (
size_t)mTopIndex)
748 if ( (mOffsetTop != 0) && (_fill) )
return false;
753 int offset = ((int)_index - mTopIndex) * mHeightLine - mOffsetTop;
756 if (_getClientWidget()->
getHeight() < offset)
return false;
759 if ((_getClientWidget()->
getHeight() < (offset + mHeightLine)) && (_fill) )
return false;
773 for (
size_t pos=0; pos<mWidgetLines.size(); pos++)
775 mWidgetLines[pos]->setVisible(
false);
776 mWidgetLines[pos]->setPosition(0, offset);
777 offset += mHeightLine;
784 #if MYGUI_DEBUG_MODE == 1
785 _checkMapping(
"List::removeAllItems");
793 mItemsInfo[_index].first =_name;
800 mItemsInfo[_index].second = _data;
807 return mItemsInfo[_index].first;
813 #if MYGUI_DEBUG_MODE == 1
823 if ((
nullptr == _new) || (_new->
getParent() != _getClientWidget()))
833 static_cast<Button*
>(mWidgetLines[_index])->_setMouseFocus(_focus);
838 if (mNeedVisibleScroll == _visible)
return;
839 mNeedVisibleScroll = _visible;
845 if (mWidgetScroll !=
nullptr)
857 mOffsetTop = ((int)_position % mHeightLine);
860 int offset = 0 - mOffsetTop;
862 for (
size_t pos=0; pos<mWidgetLines.size(); pos++)
864 mWidgetLines[pos]->setPosition(
IntPoint(0, offset));
865 offset += mHeightLine;
869 int top = ((int)_position / mHeightLine);
870 if (top != mTopIndex)
891 if (_index1 == _index2)
return;
893 std::swap(mItemsInfo[_index1], mItemsInfo[_index2]);
899 void List::_checkMapping(
const std::string& _owner)
901 size_t count_pressed = 0;
902 size_t count_show = 0;
904 for (
size_t pos=0; pos<mWidgetLines.size(); pos++)
906 MYGUI_ASSERT(pos == *mWidgetLines[pos]->_getInternalData<size_t>(), _owner);
907 static_cast<Button*
>(mWidgetLines[pos])->getButtonPressed() ? count_pressed ++ : 0;
908 static_cast<Button*
>(mWidgetLines[pos])->
isVisible() ? count_show ++ : 0;
917 int max_height = mItemsInfo.size() * mHeightLine;
919 int visible_height = _getClientWidget()->
getHeight();
922 if (visible_height >= max_height)
927 for (
size_t pos=0; pos<mWidgetLines.size(); pos++)
929 if (pos >= mItemsInfo.size())
break;
930 MYGUI_ASSERT(mWidgetLines[pos]->
getTop() == height,
"mWidgetLines[pos]->getTop() == height");
931 height += mWidgetLines[pos]->getHeight();
938 for (
size_t pos=0; pos<mItemsInfo.size(); pos++)
940 if (mItemsInfo[pos].first == _name)
return pos;
952 if (_key ==
"List_AddItem")
addItem(_value);
961 Widget* List::_getClientWidget()
966 const Widget* List::_getClientWidget()
const