ecere/gui/ListBox: Debugging code
authorJerome St-Louis <jerome@ecere.com>
Mon, 25 Apr 2016 11:51:28 +0000 (07:51 -0400)
committerJerome St-Louis <jerome@ecere.com>
Sat, 2 Jul 2016 20:40:43 +0000 (16:40 -0400)
- Setting current row does not check whether a row belongs to the ListBox;
  this can be the source of obscure bugs

ecere/src/gui/controls/ListBox.ec

index cb5cb37..b0d0664 100644 (file)
@@ -1986,8 +1986,52 @@ private:
       }
    }
 
+#ifdef _DEBUG
+   static bool DebugFindRow(DataRow parent, DataRow row)
+   {
+      bool found = false;
+      DataRow r;
+      for(r = parent.subRows.first; r; r = r.next)
+      {
+         if(r == row)
+         {
+            found = true;
+            break;
+         }
+         if(DebugFindRow(r, row))
+         {
+            found = true;
+            break;
+         }
+      }
+      return found;
+   }
+#endif
+
    void SetCurrentRow(DataRow row, bool notify)
    {
+#if _DEBUG
+      if(this && row)
+      {
+         bool found = false;
+         DataRow r;
+         for(r = rows.first; r; r = r.next)
+         {
+            if(r == row)
+            {
+               found = true;
+               break;
+            }
+            if(DebugFindRow(r, row))
+            {
+               found = true;
+               break;
+            }
+         }
+         if(!found)
+            PrintLn("ERROR: Setting currentRow to a row not found in ListBox!!");
+      }
+#endif
       if(this && (currentRow != row || (currentRow && currentRow.selectedFlag == unselected)))
       {
          int headerSize = ((style.header) ? rowHeight : 0);