Browse Source

ListView: unsigned to int (#3015)

Related: https://github.com/urho3d/Urho3D/issues/2940
1vanK 3 years ago
parent
commit
c176cff6c4

+ 44 - 44
Source/Urho3D/AngelScript/Generated_Members.h

@@ -22342,17 +22342,17 @@ template <class T> CScriptArray* ListView_VectorlesUIElementstargre_GetSelectedI
     return VectorToHandleArray(result, "Array<UIElement@>");
 }
 
-// const Vector<unsigned>& ListView::GetSelections() const
-template <class T> CScriptArray* ListView_constspVectorlesunsignedgreamp_GetSelections_void_template(T* _ptr)
+// const Vector<i32>& ListView::GetSelections() const
+template <class T> CScriptArray* ListView_constspVectorlesi32greamp_GetSelections_void_template(T* _ptr)
 {
-    const Vector<unsigned>& result = _ptr->GetSelections();
-    return VectorToArray(result, "Array<uint>");
+    const Vector<i32>& result = _ptr->GetSelections();
+    return VectorToArray(result, "Array<int>");
 }
 
-// void ListView::SetSelections(const Vector<unsigned>& indices)
-template <class T> void ListView_void_SetSelections_constspVectorlesunsignedgreamp_template(T* _ptr, CScriptArray* indices_conv)
+// void ListView::SetSelections(const Vector<i32>& indices)
+template <class T> void ListView_void_SetSelections_constspVectorlesi32greamp_template(T* _ptr, CScriptArray* indices_conv)
 {
-    Vector<unsigned> indices = ArrayToVector<unsigned>(indices_conv);
+    Vector<i32> indices = ArrayToVector<i32>(indices_conv);
     _ptr->SetSelections(indices);
 }
 
@@ -22364,8 +22364,8 @@ template <class T> void RegisterMembers_ListView(asIScriptEngine* engine, const
     // void ListView::AddItem(UIElement* item)
     engine->RegisterObjectMethod(className, "void AddItem(UIElement@+)", AS_METHODPR(T, AddItem, (UIElement*), void), AS_CALL_THISCALL);
 
-    // void ListView::AddSelection(unsigned index)
-    engine->RegisterObjectMethod(className, "void AddSelection(uint)", AS_METHODPR(T, AddSelection, (unsigned), void), AS_CALL_THISCALL);
+    // void ListView::AddSelection(i32 index)
+    engine->RegisterObjectMethod(className, "void AddSelection(int)", AS_METHODPR(T, AddSelection, (i32), void), AS_CALL_THISCALL);
 
     // void ListView::ChangeSelection(int delta, bool additive = false)
     engine->RegisterObjectMethod(className, "void ChangeSelection(int, bool = false)", AS_METHODPR(T, ChangeSelection, (int, bool), void), AS_CALL_THISCALL);
@@ -22382,17 +22382,17 @@ template <class T> void RegisterMembers_ListView(asIScriptEngine* engine, const
     // void ListView::EnableInternalLayoutUpdate()
     engine->RegisterObjectMethod(className, "void EnableInternalLayoutUpdate()", AS_METHODPR(T, EnableInternalLayoutUpdate, (), void), AS_CALL_THISCALL);
 
-    // void ListView::EnsureItemVisibility(unsigned index)
-    engine->RegisterObjectMethod(className, "void EnsureItemVisibility(uint)", AS_METHODPR(T, EnsureItemVisibility, (unsigned), void), AS_CALL_THISCALL);
+    // void ListView::EnsureItemVisibility(i32 index)
+    engine->RegisterObjectMethod(className, "void EnsureItemVisibility(int)", AS_METHODPR(T, EnsureItemVisibility, (i32), void), AS_CALL_THISCALL);
 
     // void ListView::EnsureItemVisibility(UIElement* item)
     engine->RegisterObjectMethod(className, "void EnsureItemVisibility(UIElement@+)", AS_METHODPR(T, EnsureItemVisibility, (UIElement*), void), AS_CALL_THISCALL);
 
-    // void ListView::Expand(unsigned index, bool enable, bool recursive = false)
-    engine->RegisterObjectMethod(className, "void Expand(uint, bool, bool = false)", AS_METHODPR(T, Expand, (unsigned, bool, bool), void), AS_CALL_THISCALL);
+    // void ListView::Expand(i32 index, bool enable, bool recursive = false)
+    engine->RegisterObjectMethod(className, "void Expand(int, bool, bool = false)", AS_METHODPR(T, Expand, (i32, bool, bool), void), AS_CALL_THISCALL);
 
-    // unsigned ListView::FindItem(UIElement* item) const
-    engine->RegisterObjectMethod(className, "uint FindItem(UIElement@+) const", AS_METHODPR(T, FindItem, (UIElement*) const, unsigned), AS_CALL_THISCALL);
+    // i32 ListView::FindItem(UIElement* item) const
+    engine->RegisterObjectMethod(className, "int FindItem(UIElement@+) const", AS_METHODPR(T, FindItem, (UIElement*) const, i32), AS_CALL_THISCALL);
 
     // int ListView::GetBaseIndent() const
     engine->RegisterObjectMethod(className, "int GetBaseIndent() const", AS_METHODPR(T, GetBaseIndent, () const, int), AS_CALL_THISCALL);
@@ -22410,9 +22410,9 @@ template <class T> void RegisterMembers_ListView(asIScriptEngine* engine, const
     engine->RegisterObjectMethod(className, "HighlightMode GetHighlightMode() const", AS_METHODPR(T, GetHighlightMode, () const, HighlightMode), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "HighlightMode get_highlightMode() const", AS_METHODPR(T, GetHighlightMode, () const, HighlightMode), AS_CALL_THISCALL);
 
-    // UIElement* ListView::GetItem(unsigned index) const
-    engine->RegisterObjectMethod(className, "UIElement@+ GetItem(uint) const", AS_METHODPR(T, GetItem, (unsigned) const, UIElement*), AS_CALL_THISCALL);
-    engine->RegisterObjectMethod(className, "UIElement@+ get_items(uint) const", AS_METHODPR(T, GetItem, (unsigned) const, UIElement*), AS_CALL_THISCALL);
+    // UIElement* ListView::GetItem(i32 index) const
+    engine->RegisterObjectMethod(className, "UIElement@+ GetItem(int) const", AS_METHODPR(T, GetItem, (i32) const, UIElement*), AS_CALL_THISCALL);
+    engine->RegisterObjectMethod(className, "UIElement@+ get_items(int) const", AS_METHODPR(T, GetItem, (i32) const, UIElement*), AS_CALL_THISCALL);
 
     // Vector<UIElement*> ListView::GetItems() const
     engine->RegisterObjectMethod(className, "Array<UIElement@>@ GetItems() const", AS_FUNCTION_OBJFIRST(ListView_VectorlesUIElementstargre_GetItems_void_template<ListView>), AS_CALL_CDECL_OBJFIRST);
@@ -22421,9 +22421,9 @@ template <class T> void RegisterMembers_ListView(asIScriptEngine* engine, const
     engine->RegisterObjectMethod(className, "bool GetMultiselect() const", AS_METHODPR(T, GetMultiselect, () const, bool), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "bool get_multiselect() const", AS_METHODPR(T, GetMultiselect, () const, bool), AS_CALL_THISCALL);
 
-    // unsigned ListView::GetNumItems() const
-    engine->RegisterObjectMethod(className, "uint GetNumItems() const", AS_METHODPR(T, GetNumItems, () const, unsigned), AS_CALL_THISCALL);
-    engine->RegisterObjectMethod(className, "uint get_numItems() const", AS_METHODPR(T, GetNumItems, () const, unsigned), AS_CALL_THISCALL);
+    // i32 ListView::GetNumItems() const
+    engine->RegisterObjectMethod(className, "int GetNumItems() const", AS_METHODPR(T, GetNumItems, () const, i32), AS_CALL_THISCALL);
+    engine->RegisterObjectMethod(className, "int get_numItems() const", AS_METHODPR(T, GetNumItems, () const, i32), AS_CALL_THISCALL);
 
     // UIElement* ListView::GetSelectedItem() const
     engine->RegisterObjectMethod(className, "UIElement@+ GetSelectedItem() const", AS_METHODPR(T, GetSelectedItem, () const, UIElement*), AS_CALL_THISCALL);
@@ -22433,13 +22433,13 @@ template <class T> void RegisterMembers_ListView(asIScriptEngine* engine, const
     engine->RegisterObjectMethod(className, "Array<UIElement@>@ GetSelectedItems() const", AS_FUNCTION_OBJFIRST(ListView_VectorlesUIElementstargre_GetSelectedItems_void_template<ListView>), AS_CALL_CDECL_OBJFIRST);
     engine->RegisterObjectMethod(className, "Array<UIElement@>@ get_selectedItems() const", AS_FUNCTION_OBJFIRST(ListView_VectorlesUIElementstargre_GetSelectedItems_void_template<ListView>), AS_CALL_CDECL_OBJFIRST);
 
-    // unsigned ListView::GetSelection() const
-    engine->RegisterObjectMethod(className, "uint GetSelection() const", AS_METHODPR(T, GetSelection, () const, unsigned), AS_CALL_THISCALL);
-    engine->RegisterObjectMethod(className, "uint get_selection() const", AS_METHODPR(T, GetSelection, () const, unsigned), AS_CALL_THISCALL);
+    // i32 ListView::GetSelection() const
+    engine->RegisterObjectMethod(className, "int GetSelection() const", AS_METHODPR(T, GetSelection, () const, i32), AS_CALL_THISCALL);
+    engine->RegisterObjectMethod(className, "int get_selection() const", AS_METHODPR(T, GetSelection, () const, i32), AS_CALL_THISCALL);
 
-    // const Vector<unsigned>& ListView::GetSelections() const
-    engine->RegisterObjectMethod(className, "Array<uint>@ GetSelections() const", AS_FUNCTION_OBJFIRST(ListView_constspVectorlesunsignedgreamp_GetSelections_void_template<ListView>), AS_CALL_CDECL_OBJFIRST);
-    engine->RegisterObjectMethod(className, "Array<uint>@ get_selections() const", AS_FUNCTION_OBJFIRST(ListView_constspVectorlesunsignedgreamp_GetSelections_void_template<ListView>), AS_CALL_CDECL_OBJFIRST);
+    // const Vector<i32>& ListView::GetSelections() const
+    engine->RegisterObjectMethod(className, "Array<int>@ GetSelections() const", AS_FUNCTION_OBJFIRST(ListView_constspVectorlesi32greamp_GetSelections_void_template<ListView>), AS_CALL_CDECL_OBJFIRST);
+    engine->RegisterObjectMethod(className, "Array<int>@ get_selections() const", AS_FUNCTION_OBJFIRST(ListView_constspVectorlesi32greamp_GetSelections_void_template<ListView>), AS_CALL_CDECL_OBJFIRST);
 
     // bool ListView::GetSelectOnClickEnd() const
     engine->RegisterObjectMethod(className, "bool GetSelectOnClickEnd() const", AS_METHODPR(T, GetSelectOnClickEnd, () const, bool), AS_CALL_THISCALL);
@@ -22448,23 +22448,23 @@ template <class T> void RegisterMembers_ListView(asIScriptEngine* engine, const
     // void ListView::InsertItem(i32 index, UIElement* item, UIElement* parentItem = nullptr)
     engine->RegisterObjectMethod(className, "void InsertItem(int, UIElement@+, UIElement@+ = null)", AS_METHODPR(T, InsertItem, (i32, UIElement*, UIElement*), void), AS_CALL_THISCALL);
 
-    // bool ListView::IsExpanded(unsigned index) const
-    engine->RegisterObjectMethod(className, "bool IsExpanded(uint) const", AS_METHODPR(T, IsExpanded, (unsigned) const, bool), AS_CALL_THISCALL);
+    // bool ListView::IsExpanded(i32 index) const
+    engine->RegisterObjectMethod(className, "bool IsExpanded(int) const", AS_METHODPR(T, IsExpanded, (i32) const, bool), AS_CALL_THISCALL);
 
-    // bool ListView::IsSelected(unsigned index) const
-    engine->RegisterObjectMethod(className, "bool IsSelected(uint) const", AS_METHODPR(T, IsSelected, (unsigned) const, bool), AS_CALL_THISCALL);
+    // bool ListView::IsSelected(i32 index) const
+    engine->RegisterObjectMethod(className, "bool IsSelected(int) const", AS_METHODPR(T, IsSelected, (i32) const, bool), AS_CALL_THISCALL);
 
     // void ListView::RemoveAllItems()
     engine->RegisterObjectMethod(className, "void RemoveAllItems()", AS_METHODPR(T, RemoveAllItems, (), void), AS_CALL_THISCALL);
 
-    // void ListView::RemoveItem(UIElement* item, unsigned index = 0)
-    engine->RegisterObjectMethod(className, "void RemoveItem(UIElement@+, uint = 0)", AS_METHODPR(T, RemoveItem, (UIElement*, unsigned), void), AS_CALL_THISCALL);
+    // void ListView::RemoveItem(UIElement* item, i32 index = 0)
+    engine->RegisterObjectMethod(className, "void RemoveItem(UIElement@+, int = 0)", AS_METHODPR(T, RemoveItem, (UIElement*, i32), void), AS_CALL_THISCALL);
 
     // void ListView::RemoveItem(i32 index)
     engine->RegisterObjectMethod(className, "void RemoveItem(int)", AS_METHODPR(T, RemoveItem, (i32), void), AS_CALL_THISCALL);
 
-    // void ListView::RemoveSelection(unsigned index)
-    engine->RegisterObjectMethod(className, "void RemoveSelection(uint)", AS_METHODPR(T, RemoveSelection, (unsigned), void), AS_CALL_THISCALL);
+    // void ListView::RemoveSelection(i32 index)
+    engine->RegisterObjectMethod(className, "void RemoveSelection(int)", AS_METHODPR(T, RemoveSelection, (i32), void), AS_CALL_THISCALL);
 
     // void ListView::SetBaseIndent(int baseIndent)
     engine->RegisterObjectMethod(className, "void SetBaseIndent(int)", AS_METHODPR(T, SetBaseIndent, (int), void), AS_CALL_THISCALL);
@@ -22486,22 +22486,22 @@ template <class T> void RegisterMembers_ListView(asIScriptEngine* engine, const
     engine->RegisterObjectMethod(className, "void SetMultiselect(bool)", AS_METHODPR(T, SetMultiselect, (bool), void), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "void set_multiselect(bool)", AS_METHODPR(T, SetMultiselect, (bool), void), AS_CALL_THISCALL);
 
-    // void ListView::SetSelection(unsigned index)
-    engine->RegisterObjectMethod(className, "void SetSelection(uint)", AS_METHODPR(T, SetSelection, (unsigned), void), AS_CALL_THISCALL);
-    engine->RegisterObjectMethod(className, "void set_selection(uint)", AS_METHODPR(T, SetSelection, (unsigned), void), AS_CALL_THISCALL);
+    // void ListView::SetSelection(i32 index)
+    engine->RegisterObjectMethod(className, "void SetSelection(int)", AS_METHODPR(T, SetSelection, (i32), void), AS_CALL_THISCALL);
+    engine->RegisterObjectMethod(className, "void set_selection(int)", AS_METHODPR(T, SetSelection, (i32), void), AS_CALL_THISCALL);
 
-    // void ListView::SetSelections(const Vector<unsigned>& indices)
-    engine->RegisterObjectMethod(className, "void SetSelections(Array<uint>@+)", AS_FUNCTION_OBJFIRST(ListView_void_SetSelections_constspVectorlesunsignedgreamp_template<ListView>), AS_CALL_CDECL_OBJFIRST);
+    // void ListView::SetSelections(const Vector<i32>& indices)
+    engine->RegisterObjectMethod(className, "void SetSelections(Array<int>@+)", AS_FUNCTION_OBJFIRST(ListView_void_SetSelections_constspVectorlesi32greamp_template<ListView>), AS_CALL_CDECL_OBJFIRST);
 
     // void ListView::SetSelectOnClickEnd(bool enable)
     engine->RegisterObjectMethod(className, "void SetSelectOnClickEnd(bool)", AS_METHODPR(T, SetSelectOnClickEnd, (bool), void), AS_CALL_THISCALL);
     engine->RegisterObjectMethod(className, "void set_selectOnClickEnd(bool)", AS_METHODPR(T, SetSelectOnClickEnd, (bool), void), AS_CALL_THISCALL);
 
-    // void ListView::ToggleExpand(unsigned index, bool recursive = false)
-    engine->RegisterObjectMethod(className, "void ToggleExpand(uint, bool = false)", AS_METHODPR(T, ToggleExpand, (unsigned, bool), void), AS_CALL_THISCALL);
+    // void ListView::ToggleExpand(i32 index, bool recursive = false)
+    engine->RegisterObjectMethod(className, "void ToggleExpand(int, bool = false)", AS_METHODPR(T, ToggleExpand, (i32, bool), void), AS_CALL_THISCALL);
 
-    // void ListView::ToggleSelection(unsigned index)
-    engine->RegisterObjectMethod(className, "void ToggleSelection(uint)", AS_METHODPR(T, ToggleSelection, (unsigned), void), AS_CALL_THISCALL);
+    // void ListView::ToggleSelection(i32 index)
+    engine->RegisterObjectMethod(className, "void ToggleSelection(int)", AS_METHODPR(T, ToggleSelection, (i32), void), AS_CALL_THISCALL);
 
     // void ListView::UpdateInternalLayout()
     engine->RegisterObjectMethod(className, "void UpdateInternalLayout()", AS_METHODPR(T, UpdateInternalLayout, (), void), AS_CALL_THISCALL);

+ 94 - 76
Source/Urho3D/UI/ListView.cpp

@@ -77,7 +77,7 @@ public:
         // Adjust the container size for child clipping effect
         overlayContainer_->SetSize(GetParent()->GetSize());
 
-        for (unsigned i = 0; i < children_.Size(); ++i)
+        for (i32 i = 0; i < children_.Size(); ++i)
         {
             const IntVector2& position = children_[i]->GetPosition();
             auto* overlay = overlayContainer_->GetChildStaticCast<CheckBox>(i);
@@ -114,12 +114,12 @@ public:
             const Vector<SharedPtr<UIElement>>& children = overlayContainer_->GetChildren();
             Vector<SharedPtr<UIElement>>::ConstIterator i = children.Find(SharedPtr<UIElement>(overlay));
             if (i != children.End())
-                listView_->ToggleExpand((unsigned)(i - children.Begin()));
+                listView_->ToggleExpand((i32)(i - children.Begin()));
         }
     }
 
     /// Insert a child element into a specific position in the child list.
-    void InsertChild(unsigned index, UIElement* element)
+    void InsertChild(i32 index, UIElement* element)
     {
         // Insert the overlay at the same index position to the overlay container
         CheckBox* overlay = static_cast<CheckBox*>(overlayContainer_->CreateChild(CheckBox::GetTypeStatic(), String::EMPTY, index));
@@ -187,8 +187,8 @@ void ListView::RegisterObject(Context* context)
 void ListView::OnKey(Key key, MouseButtonFlags buttons, QualifierFlags qualifiers)
 {
     // If no selection, can not move with keys
-    unsigned numItems = GetNumItems();
-    unsigned selection = GetSelection();
+    i32 numItems = GetNumItems();
+    i32 selection = GetSelection();
 
     // If either shift or ctrl held down, add to selection if multiselect enabled
     bool additive = multiselect_ && qualifiers & (QUAL_SHIFT | QUAL_CTRL);
@@ -197,7 +197,7 @@ void ListView::OnKey(Key key, MouseButtonFlags buttons, QualifierFlags qualifier
 
     if (numItems)
     {
-        if (selection != M_MAX_UNSIGNED && qualifiers & QUAL_CTRL && key == KEY_C)
+        if (selection != NINDEX && qualifiers & QUAL_CTRL && key == KEY_C)
         {
             CopySelectedItemsToClipboard();
             return;
@@ -207,7 +207,7 @@ void ListView::OnKey(Key key, MouseButtonFlags buttons, QualifierFlags qualifier
         {
         case KEY_LEFT:
         case KEY_RIGHT:
-            if (selection != M_MAX_UNSIGNED && hierarchyMode_)
+            if (selection != NINDEX && hierarchyMode_)
             {
                 Expand(selection, key == KEY_RIGHT);
                 return;
@@ -217,7 +217,7 @@ void ListView::OnKey(Key key, MouseButtonFlags buttons, QualifierFlags qualifier
         case KEY_RETURN:
         case KEY_RETURN2:
         case KEY_KP_ENTER:
-            if (selection != M_MAX_UNSIGNED && hierarchyMode_)
+            if (selection != NINDEX && hierarchyMode_)
             {
                 ToggleExpand(selection);
                 return;
@@ -239,13 +239,13 @@ void ListView::OnKey(Key key, MouseButtonFlags buttons, QualifierFlags qualifier
         case KEY_PAGEDOWN:
             {
                 // Convert page step to pixels and see how many items have to be skipped to reach that many pixels
-                if (selection == M_MAX_UNSIGNED)
+                if (selection == NINDEX)
                     selection = 0;      // Assume as if first item is selected
                 int stepPixels = ((int)(pageStep_ * scrollPanel_->GetHeight())) - contentElement_->GetChild(selection)->GetHeight();
-                unsigned newSelection = selection;
-                unsigned okSelection = selection;
-                unsigned invisible = 0;
-                while (newSelection < numItems)
+                i32 newSelection = selection;
+                i32 okSelection = selection;
+                i32 invisible = 0;
+                while (newSelection < numItems && newSelection >= 0)
                 {
                     UIElement* item = GetItem(newSelection);
                     int height = 0;
@@ -266,7 +266,7 @@ void ListView::OnKey(Key key, MouseButtonFlags buttons, QualifierFlags qualifier
             break;
 
         case KEY_HOME:
-            delta = -(int)GetNumItems();
+            delta = -GetNumItems();
             break;
 
         case KEY_END:
@@ -325,7 +325,7 @@ void ListView::EnableInternalLayoutUpdate()
 
 void ListView::AddItem(UIElement* item)
 {
-    InsertItem(M_MAX_UNSIGNED, item);
+    InsertItem(ENDPOS, item);
 }
 
 void ListView::InsertItem(i32 index, UIElement* item, UIElement* parentItem)
@@ -399,27 +399,29 @@ void ListView::InsertItem(i32 index, UIElement* item, UIElement* parentItem)
     }
 }
 
-void ListView::RemoveItem(UIElement* item, unsigned index)
+void ListView::RemoveItem(UIElement* item, i32 index/* = 0*/)
 {
+    assert(index >= 0);
+
     if (!item)
         return;
 
-    unsigned numItems = GetNumItems();
-    for (unsigned i = index; i < numItems; ++i)
+    i32 numItems = GetNumItems();
+    for (i32 i = index; i < numItems; ++i)
     {
         if (GetItem(i) == item)
         {
             item->SetSelected(false);
             selections_.Remove(i);
 
-            unsigned removed = 1;
+            i32 removed = 1;
             if (hierarchyMode_)
             {
                 // Remove any child items in hierarchy mode
                 if (GetItemHierarchyParent(item))
                 {
                     int baseIndent = item->GetIndent();
-                    for (unsigned j = i + 1; ; ++j)
+                    for (i32 j = i + 1; ; ++j)
                     {
                         UIElement* childItem = GetItem(i + 1);
                         if (!childItem)
@@ -461,7 +463,7 @@ void ListView::RemoveItem(UIElement* item, unsigned index)
             // If necessary, shift the following selections
             if (!selections_.Empty())
             {
-                for (unsigned j = 0; j < selections_.Size(); ++j)
+                for (i32 j = 0; j < selections_.Size(); ++j)
                 {
                     if (selections_[j] > i)
                         selections_[j] -= removed;
@@ -495,25 +497,26 @@ void ListView::RemoveAllItems()
     contentElement_->UpdateLayout();
 }
 
-void ListView::SetSelection(unsigned index)
+void ListView::SetSelection(i32 index)
 {
-    Vector<unsigned> indices;
+    assert(index >= 0);
+    Vector<i32> indices;
     indices.Push(index);
     SetSelections(indices);
     EnsureItemVisibility(index);
 }
 
-void ListView::SetSelections(const Vector<unsigned>& indices)
+void ListView::SetSelections(const Vector<i32>& indices)
 {
     // Make a weak pointer to self to check for destruction as a response to events
     WeakPtr<ListView> self(this);
 
-    unsigned numItems = GetNumItems();
+    i32 numItems = GetNumItems();
 
     // Remove first items that should no longer be selected
-    for (Vector<unsigned>::Iterator i = selections_.Begin(); i != selections_.End();)
+    for (Vector<i32>::Iterator i = selections_.Begin(); i != selections_.End();)
     {
-        unsigned index = *i;
+        i32 index = *i;
         if (!indices.Contains(index))
         {
             i = selections_.Erase(i);
@@ -535,9 +538,9 @@ void ListView::SetSelections(const Vector<unsigned>& indices)
     bool added = false;
 
     // Then add missing items
-    for (Vector<unsigned>::ConstIterator i = indices.Begin(); i != indices.End(); ++i)
+    for (Vector<i32>::ConstIterator i = indices.Begin(); i != indices.End(); ++i)
     {
-        unsigned index = *i;
+        i32 index = *i;
         if (index < numItems)
         {
             // In singleselect mode, resend the event even for the same selection
@@ -574,8 +577,10 @@ void ListView::SetSelections(const Vector<unsigned>& indices)
     SendEvent(E_SELECTIONCHANGED);
 }
 
-void ListView::AddSelection(unsigned index)
+void ListView::AddSelection(i32 index)
 {
+    assert(index >= 0);
+
     // Make a weak pointer to self to check for destruction as a response to events
     WeakPtr<ListView> self(this);
 
@@ -609,8 +614,10 @@ void ListView::AddSelection(unsigned index)
     }
 }
 
-void ListView::RemoveSelection(unsigned index)
+void ListView::RemoveSelection(i32 index)
 {
+    assert(index >= 0);
+
     if (index >= GetNumItems())
         return;
 
@@ -629,9 +636,12 @@ void ListView::RemoveSelection(unsigned index)
     SendEvent(E_SELECTIONCHANGED);
 }
 
-void ListView::ToggleSelection(unsigned index)
+void ListView::ToggleSelection(i32 index)
 {
-    unsigned numItems = GetNumItems();
+    assert(index >= 0);
+
+    i32 numItems = GetNumItems();
+
     if (index >= numItems)
         return;
 
@@ -643,7 +653,7 @@ void ListView::ToggleSelection(unsigned index)
 
 void ListView::ChangeSelection(int delta, bool additive)
 {
-    unsigned numItems = GetNumItems();
+    i32 numItems = GetNumItems();
     if (selections_.Empty())
     {
         // Select first item if there is no selection yet
@@ -656,16 +666,16 @@ void ListView::ChangeSelection(int delta, bool additive)
         additive = false;
 
     // If going downwards, use the last selection as a base. Otherwise use first
-    unsigned selection = delta > 0 ? selections_.Back() : selections_.Front();
+    i32 selection = delta > 0 ? selections_.Back() : selections_.Front();
     int direction = delta > 0 ? 1 : -1;
-    unsigned newSelection = selection;
-    unsigned okSelection = selection;
-    Vector<unsigned> indices = selections_;
+    i32 newSelection = selection;
+    i32 okSelection = selection;
+    Vector<i32> indices = selections_;
 
     while (delta != 0)
     {
         newSelection += direction;
-        if (newSelection >= numItems)
+        if (newSelection >= numItems || newSelection < 0)
             break;
 
         UIElement* item = GetItem(newSelection);
@@ -684,7 +694,7 @@ void ListView::ChangeSelection(int delta, bool additive)
 
 void ListView::ClearSelection()
 {
-    SetSelections(Vector<unsigned>());
+    SetSelections(Vector<i32>());
 }
 
 void ListView::SetHighlightMode(HighlightMode mode)
@@ -759,12 +769,14 @@ void ListView::SetSelectOnClickEnd(bool enable)
     }
 }
 
-void ListView::Expand(unsigned index, bool enable, bool recursive)
+void ListView::Expand(i32 index, bool enable, bool recursive)
 {
+    assert(index >= 0);
+
     if (!hierarchyMode_)
         return;
 
-    unsigned numItems = GetNumItems();
+    i32 numItems = GetNumItems();
     if (index >= numItems)
         return;
 
@@ -772,7 +784,7 @@ void ListView::Expand(unsigned index, bool enable, bool recursive)
     SetItemExpanded(item, enable);
     int baseIndent = item->GetIndent();
 
-    Vector<bool> expanded((unsigned)(baseIndent + 1));
+    Vector<bool> expanded(baseIndent + 1);
     expanded[baseIndent] = enable;
 
     contentElement_->DisableLayoutUpdate();
@@ -792,8 +804,8 @@ void ListView::Expand(unsigned index, bool enable, bool recursive)
         bool visible = enable && expanded[indent - 1];
         item->SetVisible(visible);
 
-        if (indent >= (int)expanded.Size())
-            expanded.Resize((unsigned)(indent + 1));
+        if (indent >= expanded.Size())
+            expanded.Resize(indent + 1);
         expanded[indent] = visible && GetItemExpanded(item);
     }
 
@@ -801,12 +813,14 @@ void ListView::Expand(unsigned index, bool enable, bool recursive)
     contentElement_->UpdateLayout();
 }
 
-void ListView::ToggleExpand(unsigned index, bool recursive)
+void ListView::ToggleExpand(i32 index, bool recursive)
 {
+    assert(index >= 0);
+
     if (!hierarchyMode_)
         return;
 
-    unsigned numItems = GetNumItems();
+    i32 numItems = GetNumItems();
     if (index >= numItems)
         return;
 
@@ -814,13 +828,14 @@ void ListView::ToggleExpand(unsigned index, bool recursive)
     Expand(index, !GetItemExpanded(item), recursive);
 }
 
-unsigned ListView::GetNumItems() const
+i32 ListView::GetNumItems() const
 {
     return contentElement_->GetNumChildren();
 }
 
-UIElement* ListView::GetItem(unsigned index) const
+UIElement* ListView::GetItem(i32 index) const
 {
+    assert(index >= 0 || index == NINDEX);
     return contentElement_->GetChild(index);
 }
 
@@ -831,14 +846,14 @@ Vector<UIElement*> ListView::GetItems() const
     return items;
 }
 
-unsigned ListView::FindItem(UIElement* item) const
+i32 ListView::FindItem(UIElement* item) const
 {
     if (!item)
-        return M_MAX_UNSIGNED;
+        return NINDEX;
 
     // Early-out by checking if the item belongs to the listview hierarchy at all
     if (item->GetParent() != contentElement_)
-        return M_MAX_UNSIGNED;
+        return NINDEX;
 
     const Vector<SharedPtr<UIElement>>& children = contentElement_->GetChildren();
 
@@ -852,7 +867,7 @@ unsigned ListView::FindItem(UIElement* item) const
         {
             int mid = (left + right) / 2;
             if (children[mid] == item)
-                return (unsigned)mid;
+                return mid;
             if (itemY < children[mid]->GetScreenPosition().y_)
                 right = mid - 1;
             else
@@ -861,19 +876,19 @@ unsigned ListView::FindItem(UIElement* item) const
     }
 
     // Fallback to linear search in case the coordinates/sizes were not yet initialized
-    for (unsigned i = 0; i < children.Size(); ++i)
+    for (i32 i = 0; i < children.Size(); ++i)
     {
         if (children[i] == item)
             return i;
     }
 
-    return M_MAX_UNSIGNED;
+    return NINDEX;
 }
 
-unsigned ListView::GetSelection() const
+i32 ListView::GetSelection() const
 {
     if (selections_.Empty())
-        return M_MAX_UNSIGNED;
+        return NINDEX;
     else
         return GetSelections().Front();
 }
@@ -887,7 +902,7 @@ Vector<UIElement*> ListView::GetSelectedItems() const
 {
     Vector<UIElement*> ret;
 
-    for (Vector<unsigned>::ConstIterator i = selections_.Begin(); i != selections_.End(); ++i)
+    for (Vector<i32>::ConstIterator i = selections_.Begin(); i != selections_.End(); ++i)
     {
         UIElement* item = GetItem(*i);
         if (item)
@@ -901,7 +916,7 @@ void ListView::CopySelectedItemsToClipboard() const
 {
     String selectedText;
 
-    for (Vector<unsigned>::ConstIterator i = selections_.Begin(); i != selections_.End(); ++i)
+    for (Vector<i32>::ConstIterator i = selections_.Begin(); i != selections_.End(); ++i)
     {
         // Only handle Text UI element
         auto* text = dynamic_cast<Text*>(GetItem(*i));
@@ -912,13 +927,15 @@ void ListView::CopySelectedItemsToClipboard() const
     GetSubsystem<UI>()->SetClipboardText(selectedText);
 }
 
-bool ListView::IsSelected(unsigned index) const
+bool ListView::IsSelected(i32 index) const
 {
+    assert(index >= 0);
     return selections_.Contains(index);
 }
 
-bool ListView::IsExpanded(unsigned index) const
+bool ListView::IsExpanded(i32 index) const
 {
+    assert(index >= 0);
     return GetItemExpanded(contentElement_->GetChild(index));
 }
 
@@ -967,10 +984,10 @@ bool ListView::FilterImplicitAttributes(XMLElement& dest) const
 
 void ListView::UpdateSelectionEffect()
 {
-    unsigned numItems = GetNumItems();
+    i32 numItems = GetNumItems();
     bool highlighted = highlightMode_ == HM_ALWAYS || HasFocus();
 
-    for (unsigned i = 0; i < numItems; ++i)
+    for (i32 i = 0; i < numItems; ++i)
     {
         UIElement* item = GetItem(i);
         if (highlightMode_ != HM_NEVER && selections_.Contains(i))
@@ -980,8 +997,9 @@ void ListView::UpdateSelectionEffect()
     }
 }
 
-void ListView::EnsureItemVisibility(unsigned index)
+void ListView::EnsureItemVisibility(i32 index)
 {
+    assert(index >= 0);
     EnsureItemVisibility(GetItem(index));
 }
 
@@ -1017,8 +1035,8 @@ void ListView::HandleUIMouseClick(StringHash eventType, VariantMap& eventData)
     auto* element = static_cast<UIElement*>(eventData[UIMouseClick::P_ELEMENT].GetPtr());
 
     // Check if the clicked element belongs to the list
-    unsigned i = FindItem(element);
-    if (i >= GetNumItems())
+    i32 i = FindItem(element);
+    if (i >= GetNumItems() || i == NINDEX)
         return;
 
     // If not editable, repeat the previous selection. This will send an event and allow eg. a dropdownlist to close
@@ -1043,35 +1061,35 @@ void ListView::HandleUIMouseClick(StringHash eventType, VariantMap& eventData)
                     SetSelection(i);
                 else
                 {
-                    unsigned first = selections_.Front();
-                    unsigned last = selections_.Back();
-                    Vector<unsigned> newSelections = selections_;
+                    i32 first = selections_.Front();
+                    i32 last = selections_.Back();
+                    Vector<i32> newSelections = selections_;
                     if (i == first || i == last)
                     {
-                        for (unsigned j = first; j <= last; ++j)
+                        for (i32 j = first; j <= last; ++j)
                             newSelections.Push(j);
                     }
                     else if (i < first)
                     {
-                        for (unsigned j = i; j <= first; ++j)
+                        for (i32 j = i; j <= first; ++j)
                             newSelections.Push(j);
                     }
                     else if (i < last)
                     {
-                        if ((abs((int)i - (int)first)) <= (abs((int)i - (int)last)))
+                        if ((abs(i - first)) <= (abs(i - last)))
                         {
-                            for (unsigned j = first; j <= i; ++j)
+                            for (i32 j = first; j <= i; ++j)
                                 newSelections.Push(j);
                         }
                         else
                         {
-                            for (unsigned j = i; j <= last; ++j)
+                            for (i32 j = i; j <= last; ++j)
                                 newSelections.Push(j);
                         }
                     }
                     else if (i > last)
                     {
-                        for (unsigned j = last; j <= i; ++j)
+                        for (i32 j = last; j <= i; ++j)
                             newSelections.Push(j);
                     }
                     SetSelections(newSelections);
@@ -1101,7 +1119,7 @@ void ListView::HandleUIMouseDoubleClick(StringHash eventType, VariantMap& eventD
 
     auto* element = static_cast<UIElement*>(eventData[UIMouseClick::P_ELEMENT].GetPtr());
     // Check if the clicked element belongs to the list
-    unsigned i = FindItem(element);
+    i32 i = FindItem(element);
     if (i >= GetNumItems())
         return;
 

+ 19 - 19
Source/Urho3D/UI/ListView.h

@@ -59,22 +59,22 @@ public:
     void InsertItem(i32 index, UIElement* item, UIElement* parentItem = nullptr);
 
     /// Remove specific item, starting search at the specified index if provided. In hierarchy mode will also remove any children.
-    void RemoveItem(UIElement* item, unsigned index = 0);
+    void RemoveItem(UIElement* item, i32 index = 0);
     /// Remove item at index. In hierarchy mode will also remove any children.
     void RemoveItem(i32 index);
     /// Remove all items.
     void RemoveAllItems();
     /// Set selection.
     /// @property
-    void SetSelection(unsigned index);
+    void SetSelection(i32 index);
     /// Set multiple selected items. If multiselect disabled, sets only the first.
-    void SetSelections(const Vector<unsigned>& indices);
+    void SetSelections(const Vector<i32>& indices);
     /// Add item to the selection, multiselect mode only.
-    void AddSelection(unsigned index);
+    void AddSelection(i32 index);
     /// Remove item from the selection.
-    void RemoveSelection(unsigned index);
+    void RemoveSelection(i32 index);
     /// Toggle selection of an item.
-    void ToggleSelection(unsigned index);
+    void ToggleSelection(i32 index);
     /// Move selection by a delta and clamp at list ends. If additive (multiselect only), will add to the existing selection.
     void ChangeSelection(int delta, bool additive = false);
     /// Clear selection.
@@ -100,27 +100,27 @@ public:
     void SetSelectOnClickEnd(bool enable);
 
     /// Expand item at index. Only has effect in hierarchy mode.
-    void Expand(unsigned index, bool enable, bool recursive = false);
+    void Expand(i32 index, bool enable, bool recursive = false);
     /// Toggle item's expanded flag at index. Only has effect in hierarchy mode.
-    void ToggleExpand(unsigned index, bool recursive = false);
+    void ToggleExpand(i32 index, bool recursive = false);
 
     /// Return number of items.
     /// @property
-    unsigned GetNumItems() const;
+    i32 GetNumItems() const;
     /// Return item at index.
     /// @property{get_items}
-    UIElement* GetItem(unsigned index) const;
+    UIElement* GetItem(i32 index) const;
     /// Return all items.
     Vector<UIElement*> GetItems() const;
-    /// Return index of item, or M_MAX_UNSIGNED If not found.
-    unsigned FindItem(UIElement* item) const;
-    /// Return first selected index, or M_MAX_UNSIGNED if none selected.
+    /// Return index of item, or NINDEX If not found.
+    i32 FindItem(UIElement* item) const;
+    /// Return first selected index, or NINDEX if none selected.
     /// @property
-    unsigned GetSelection() const;
+    i32 GetSelection() const;
 
     /// Return all selected indices.
     /// @property
-    const Vector<unsigned>& GetSelections() const { return selections_; }
+    const Vector<i32>& GetSelections() const { return selections_; }
 
     /// Copy selected items to system clipboard. Currently only applicable to Text items.
     void CopySelectedItemsToClipboard() const;
@@ -131,9 +131,9 @@ public:
     /// @property
     Vector<UIElement*> GetSelectedItems() const;
     /// Return whether an item at index is selected.
-    bool IsSelected(unsigned index) const;
+    bool IsSelected(i32 index) const;
     /// Return whether an item at index has its children expanded (in hierarchy mode only).
-    bool IsExpanded(unsigned index) const;
+    bool IsExpanded(i32 index) const;
 
     /// Return highlight mode.
     /// @property
@@ -160,7 +160,7 @@ public:
     int GetBaseIndent() const { return baseIndent_; }
 
     /// Ensure full visibility of the item.
-    void EnsureItemVisibility(unsigned index);
+    void EnsureItemVisibility(i32 index);
     /// Ensure full visibility of the item.
     void EnsureItemVisibility(UIElement* item);
 
@@ -171,7 +171,7 @@ protected:
     void UpdateSelectionEffect();
 
     /// Current selection.
-    Vector<unsigned> selections_;
+    Vector<i32> selections_;
     /// Highlight mode.
     HighlightMode highlightMode_;
     /// Multiselect flag.

+ 6 - 6
bin/Data/Scripts/Editor/EditorHierarchyWindow.as

@@ -31,7 +31,7 @@ const uint UI_ELEMENT_BASE_ID = 1;
 uint uiElementNextID = UI_ELEMENT_BASE_ID;
 bool showInternalUIElement = false;
 bool showTemporaryObject = false;
-Array<uint> hierarchyUpdateSelections;
+Array<int> hierarchyUpdateSelections;
 
 Variant GetUIElementID(UIElement@ element)
 {
@@ -122,7 +122,7 @@ void ExpandCollapseHierarchy(StringHash eventType, VariantMap& eventData)
     bool all = checkBox.checked;
     checkBox.checked = false;    // Auto-reset
 
-    Array<uint> selections = hierarchyList.selections;
+    Array<int> selections = hierarchyList.selections;
     for (uint i = 0; i < selections.length; ++i)
         hierarchyList.Expand(selections[i], enable, all);
 }
@@ -190,7 +190,7 @@ uint UpdateHierarchyItem(uint itemIndex, Serializable@ serializable, UIElement@
     Variant id = GetID(serializable, itemType);
 
     // Remove old item if exists
-    if (itemIndex < hierarchyList.numItems && MatchID(hierarchyList.items[itemIndex], id, itemType))
+    if (itemIndex < hierarchyList.numItems && itemIndex != NINDEX && MatchID(hierarchyList.items[itemIndex], id, itemType))
         hierarchyList.RemoveItem(itemIndex);
 
     Text@ text = Text();
@@ -689,7 +689,7 @@ void HandleHierarchyListSelectionChange()
     ClearSceneSelection();
     ClearUIElementSelection();
 
-    Array<uint> indices = hierarchyList.selections;
+    Array<int> indices = hierarchyList.selections;
 
     // Enable Expand/Collapse button when there is selection
     EnableExpandCollapseButtons(indices.length > 0);
@@ -1917,8 +1917,8 @@ void HandleHierarchyContextUIElementCloseAllUILayouts()
 
 void CollapseHierarchy()
 {
-    Array<uint> oldSelections = hierarchyList.selections;
-    Array<uint> selections = {0};
+    Array<int> oldSelections = hierarchyList.selections;
+    Array<int> selections = {0};
 
     hierarchyList.SetSelections(selections);
 

+ 1 - 1
bin/Data/Scripts/Editor/EditorScene.as

@@ -1244,7 +1244,7 @@ bool SceneSelectAll()
 {
     BeginSelectionModify();
     Array<Node@> rootLevelNodes = editorScene.GetChildren();
-    Array<uint> indices;
+    Array<int> indices;
     for (uint i = 0; i < rootLevelNodes.length; ++i)
         indices.Push(GetListIndex(rootLevelNodes[i]));
     hierarchyList.SetSelections(indices);

+ 1 - 1
bin/Data/Scripts/Editor/EditorUIElement.as

@@ -635,7 +635,7 @@ bool UIElementDelete()
 bool UIElementSelectAll()
 {
     BeginSelectionModify();
-    Array<uint> indices;
+    Array<int> indices;
     uint baseIndex = GetListIndex(editorUIElement);
     indices.Push(baseIndex);
     int baseIndent = hierarchyList.items[baseIndex].indent;