23 mFirstVisibleIndex(0),
43 mDragLayer =
"DragAndDrop";
108 void ItemBox::requestItemSize()
115 mSizeItem = coord.size();
116 MYGUI_ASSERT((mSizeItem.
width > 0 && mSizeItem.
height > 0),
"(mSizeItem.width > 0 && mSizeItem.height > 0) at requestCoordWidgetItem");
132 int count_visible = 0;
135 count_visible = (_getClientWidget()->
getHeight() / mSizeItem.
height) + 2;
139 count_visible = (_getClientWidget()->
getWidth() / mSizeItem.
width) + 2;
142 size_t start = (mFirstVisibleIndex * mCountItemInLine);
143 size_t count = (count_visible * mCountItemInLine) + start;
146 for (
size_t pos = start; pos < count; ++pos, ++index)
149 if (pos >= mItemsInfo.size())
break;
155 (((
int)index / mCountItemInLine) * mSizeItem.
height) - mFirstOffsetIndex);
159 item->
setPosition((((
int)index / mCountItemInLine) * mSizeItem.
width) - mFirstOffsetIndex,
160 ((
int)index % mCountItemInLine) * mSizeItem.
height - mContentPosition.
top);
168 IBDrawItemInfo data(pos, mIndexSelect, mIndexActive, mIndexAccept, mIndexRefuse,
true,
false);
175 while (index < mVectorItems.size())
177 mVectorItems[index]->setVisible(
false);
185 if (_index == mVectorItems.size())
206 mVectorItems.push_back(item);
212 return mVectorItems[_index];
241 size_t start = (size_t)(mFirstVisibleIndex * mCountItemInLine);
242 size_t index = mIndexActive;
246 if ((mIndexActive >= start) && (mIndexActive < (start + mVectorItems.size())))
248 IBDrawItemInfo data(index, mIndexSelect, mIndexActive, mIndexAccept, mIndexRefuse,
false,
false);
262 const IntRect& rect = _getClientAbsoluteRect();
268 for (
size_t pos = 0; pos < mVectorItems.size(); ++pos)
270 Widget* item = mVectorItems[pos];
275 size_t index = calcIndexByWidget(item);
277 if (index < mItemsInfo.size())
280 mIndexActive = index;
281 IBDrawItemInfo data(index, mIndexSelect, mIndexActive, mIndexAccept, mIndexRefuse,
false,
false);
293 if (_item == _getClientWidget())
295 size_t index = calcIndexByWidget(_item);
296 if (index < mItemsInfo.size())
306 mIndexAccept = (_set && _accept ) ? _index :
ITEM_NONE;
307 mIndexRefuse = (_set && !_accept) ? _index :
ITEM_NONE;
309 size_t start = (size_t)(mFirstVisibleIndex * mCountItemInLine);
310 if ((_index >= start) && (_index < (start + mVectorItems.size())))
312 IBDrawItemInfo data(_index, mIndexSelect, mIndexActive, mIndexAccept, mIndexRefuse,
false,
false);
320 mItemsInfo[_index].data = _data;
322 size_t start = (size_t)(mFirstVisibleIndex * mCountItemInLine);
323 if ((_index >= start) && (_index < (start + mVectorItems.size())))
325 IBDrawItemInfo data(_index, mIndexSelect, mIndexActive, mIndexAccept, mIndexRefuse,
true,
false);
335 if (_index ==
ITEM_NONE) _index = mItemsInfo.size();
341 mItemsInfo.insert(mItemsInfo.begin() + _index,
ItemDataInfo(_data));
346 if (mIndexSelect >= _index)
367 mItemsInfo.erase(mItemsInfo.begin() + _index);
372 if (mItemsInfo.empty())
376 else if ((mIndexSelect > _index) || (mIndexSelect == mItemsInfo.size()))
392 if (mItemsInfo.empty())
411 size_t start = (size_t)(mFirstVisibleIndex * mCountItemInLine);
412 if ((_index >= start) && (_index < (start + mVectorItems.size())))
414 IBDrawItemInfo data(_index, mIndexSelect, mIndexActive, mIndexAccept, mIndexRefuse,
true,
false);
422 if (_index == mIndexSelect)
return;
424 size_t start = (size_t)(mFirstVisibleIndex * mCountItemInLine);
429 size_t index = mIndexSelect;
432 if ((index >= start) && (index < (start + mVectorItems.size())))
434 IBDrawItemInfo data(index, mIndexSelect, mIndexActive, mIndexAccept, mIndexRefuse,
false,
false);
439 mIndexSelect = _index;
442 if ((_index >= start) && (_index < (start + mVectorItems.size())))
444 IBDrawItemInfo data(_index, mIndexSelect, mIndexActive, mIndexAccept, mIndexRefuse,
false,
false);
460 if (mAlignVert == _vert)
464 mCountItemInLine = -1;
480 MYGUI_ASSERT(_widget,
"ItemBox::getIndexByWidget : Widget == nullptr");
481 if (_widget == _getClientWidget())
return ITEM_NONE;
482 MYGUI_ASSERT(_widget->
getParent() == _getClientWidget(),
"ItemBox::getIndexByWidget : Widget is not child");
484 size_t index = calcIndexByWidget(_widget);
492 for (VectorWidgetPtr::iterator iter = mVectorItems.begin(); iter != mVectorItems.end(); ++iter)
494 if ((*iter)->getVisible())
496 if ((*iter)->getAbsoluteRect().inside(_point))
513 for (VectorWidgetPtr::iterator iter = mVectorItems.begin(); iter != mVectorItems.end(); ++iter)
522 for (VectorWidgetPtr::iterator iter = mVectorItems.begin(); iter != mVectorItems.end(); ++iter)
524 if ((*iter)->getVisible())
528 if (index == _index)
return (*iter);
556 if (
nullptr == mItemDrag)
563 mPointDragOffset = coord.
point();
603 size_t old = mIndexSelect;
605 if (_sender == _getClientWidget())
642 size_t index = calcIndexByWidget(_sender);
650 size_t old_index = mIndexActive;
652 IBDrawItemInfo data(old_index, mIndexSelect, mIndexActive, mIndexAccept, mIndexRefuse,
false,
false);
653 requestDrawItem(
this, mVectorItems[old_index - (mFirstVisibleIndex * mCountItemInLine)], data);
656 mIndexActive = index;
657 IBDrawItemInfo data(index, mIndexSelect, mIndexActive, mIndexAccept, mIndexRefuse,
false,
false);
664 if (index < mItemsInfo.size() && mIndexActive == index)
667 IBDrawItemInfo data(index, mIndexSelect, mIndexActive, mIndexAccept, mIndexRefuse,
false,
false);
678 mCountItemInLine = _getClientWidget()->
getWidth() / mSizeItem.
width;
686 if (1 > mCountItemInLine) mCountItemInLine = 1;
689 mCountLines = mItemsInfo.size() / mCountItemInLine;
690 if (0 != (mItemsInfo.size() % mCountItemInLine)) mCountLines ++;
694 mContentSize.
width = (mSizeItem.
width * mCountItemInLine);
699 mContentSize.
width = (mSizeItem.
width * mCountLines);
700 mContentSize.
height = (mSizeItem.
height * mCountItemInLine);
708 mContentPosition.
top = (int)_index;
712 mContentPosition.
left = (int)_index;
715 setContentPosition(mContentPosition);
722 if (mContentSize.
height <= 0)
725 int offset = mContentPosition.
top;
727 offset += mSizeItem.
height;
729 offset -= mSizeItem.
height;
733 else if (offset >= mContentSize.
height - _getClientWidget()->
getHeight())
738 if (mContentPosition.
top == offset)
745 mContentPosition.
top = offset;
749 if (mContentSize.
width <= 0)
752 int offset = mContentPosition.
left;
754 offset += mSizeItem.
width;
756 offset -= mSizeItem.
width;
760 else if (offset >= mContentSize.
width - _getClientWidget()->
getWidth())
761 offset = mContentSize.
width - _getClientWidget()->
getWidth();
765 if (mContentPosition.
left == offset)
772 mContentPosition.
left = offset;
775 setContentPosition(mContentPosition);
787 void ItemBox::setContentPosition(
const IntPoint& _point)
789 mContentPosition = _point;
791 int old = mFirstVisibleIndex;
795 mFirstVisibleIndex = mContentPosition.
top / mSizeItem.
height;
796 mFirstOffsetIndex = mContentPosition.
top % mSizeItem.
height;
800 mFirstVisibleIndex = mContentPosition.
left / mSizeItem.
width;
801 mFirstOffsetIndex = mContentPosition.
left % mSizeItem.
width;
818 size_t ItemBox::calcIndexByWidget(
Widget* _widget)
820 return *_widget->
_getInternalData<
size_t>() + (mFirstVisibleIndex * mCountItemInLine);
823 IntSize ItemBox::getContentSize()
828 IntPoint ItemBox::getContentPosition()
830 return mContentPosition;
835 return _getClientWidget()->
getSize();
838 void ItemBox::eraseContent()
843 size_t ItemBox::getHScrollPage()
845 return mSizeItem.
width;
848 size_t ItemBox::getVScrollPage()
853 Align ItemBox::getContentAlign()
858 IntRect ItemBox::_getClientAbsoluteRect()
863 Widget* ItemBox::_getClientWidget()
870 return mItemsInfo.size();
921 if (_key ==
"VerticalAlignment")
937 if (mContentSize.
height <= 0)
940 int offset = _value.
top;
944 else if (offset >= mContentSize.
height - _getClientWidget()->
getHeight())
949 if (mContentPosition.
top == offset)
956 mContentPosition.
top = offset;
960 if (mContentSize.
width <= 0)
963 int offset = _value.
left;
967 else if (offset >= mContentSize.
width - _getClientWidget()->
getWidth())
968 offset = mContentSize.
width - _getClientWidget()->
getWidth();
972 if (mContentPosition.
left == offset)
979 mContentPosition.
left = offset;
982 setContentPosition(mContentPosition);
996 return getContentPosition();