ecere/gui/ListBox: Fixed moving rows updating with wrong index
[sdk] / ecere / src / gui / controls / ListBox.ec
index af732ed..37cc0eb 100644 (file)
@@ -57,10 +57,11 @@ public class DataField
 public:
    property Class dataType
    {
-      set { dataType = value; if(value) alignment = value.defaultAlignment; }
+      set { dataType = value; if(value) { alignment = (Alignment)value.defaultAlignment; } }  // NOTE: Class::defaultAlignment does not seem to be used anywhere
       get { return dataType; }
    }
    property bool editable { set { editable = value; } };
+   property bool fixed { set { fixed = value; } get { return fixed; } };
    property Alignment alignment
    {
       set
@@ -69,6 +70,7 @@ public:
          if(headButton) headButton.alignment = value;
          if(listBox) listBox.Update(null);
       }
+      get { return alignment; }
    };
    property int width
    {
@@ -112,8 +114,8 @@ public:
                }
                index++;
             }
-            return -1;
          }
+         return -1;
       }
    };
    property int sortOrder { get { return this ? sortOrder : 0; } };
@@ -159,6 +161,44 @@ public:
       }
    }
 
+   void AutoSize()
+   {
+      if(listBox && dataType)
+      {
+         Display display = listBox.display;
+         Font boldFont = listBox.boldFont.font;
+         Font font = listBox.fontObject;
+         DataRow row;
+         int width = 0;
+         if(header)
+            display.FontExtent(boldFont, header, strlen(header), &width, null);
+         width += EXTRA_SPACE;
+         for(row = listBox.firstRow; row; row = row.GetNextRow())
+         {
+            ListBoxCell cell;
+            uint i;
+            for(i = 0, cell = row.cells.first; i != index; i++, cell = cell.next);
+            if(cell && cell.isSet && dataType)
+            {
+               static char tempString[4096];
+               String string;
+               int tw = 0;
+               if(dataType.type == normalClass || dataType.type == noHeadClass)
+                  string = ((char *(*)(void *, void *, char *, void *, bool *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, cell.data[0], tempString, userData, null);
+               else
+                  string = ((char *(*)(void *, void *, char *, void *, bool *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, cell.data, tempString, userData, null);
+               if(string)
+                  display.FontExtent(row.header ? boldFont : font, string, strlen(string), &tw, null);
+               else
+                  display.FontExtent(row.header ? boldFont : font, "", 0, &tw, null);
+               if(tw > width) width = tw;
+            }
+         }
+         if(width)
+            property::width = width;
+      }
+   }
+
 private:
    DataField()
    {
@@ -202,19 +242,23 @@ private:
    int x;
    Button headButton;
    int sortOrder;
-   int alignment;
+   Alignment alignment;
    bool editable;
    ListBox listBox;
    bool defaultField;
    void * userData;
    bool freeData;
+   bool fixed;
 };
 
 public class DataRow
 {
    class_no_expansion
+#ifdef _DEBUG
+   bool skipCheck;
+#endif
 public:
-   property int tag { set { tag = value; } get { return tag; } };
+   property int64 tag { set { tag = value; } get { return tag; } };
    property DataRow previous { get { return prev; } };
    property DataRow next { get { return next; } };
    property int index { get { return (this && (!parent || parent.IsExpanded())) ? index : -1; } };
@@ -260,7 +304,6 @@ public:
                   }
                }
 
-               // TODO: FIX row indices
                index = this.index+1;
                for(search = GetNextRow(); search; search = search.GetNextRow())
                   search.index = index++;
@@ -277,6 +320,10 @@ public:
                listBox.NotifyCollapse(listBox.master, listBox, this, value);
             }
          }
+#ifdef _DEBUG
+         if(!skipCheck)
+            listBox.CheckConsistency();
+#endif
       }
       get { return this ? collapsed : false; }
    };
@@ -300,11 +347,12 @@ public:
          {
             DataRow search;
             DataRow after = value ? value.subRows.last : listBox.rows.last;
+            int ixCount = (!collapsed && subRows.count) ? GetLastRow().index - index + 1 : 1;
             if(parent.IsExpanded())
             {
                for(search = GetNextRow(); search; search = search.GetNextRow())
-                  search.index--;         
-               listBox.rowCount--;
+                  search.index -= ixCount;
+               listBox.rowCount -= ixCount;
             }
 
             listBox.HideEditBox(false, false, true);
@@ -343,25 +391,35 @@ public:
             parent = value;
 
             if(value && listBox.style.expandOnAdd)
+            {
+#ifdef _DEBUG
+               value.skipCheck = true;
+#endif
                value.collapsed = false;
+#ifdef _DEBUG
+               value.skipCheck = false;
+#endif
+            }
 
-            if(value.IsExpanded(this))
+            if(value.IsExpanded())
             {
                DataRow search;
 
                if(after && after.subRows.first && !after.collapsed)
                {
-                  for(search = after.subRows.last; !search.collapsed && search.subRows.last; )
-                     search = search.subRows.last;
+                  search = after.GetLastRow();
                   index = search.index + 1;
                }
                else
                   index = after ? (after.index + 1) : (index + 1);
 
-               listBox.rowCount++;
+               listBox.rowCount += ixCount;
 
-               for(search = GetNextRow(); search; search = search.GetNextRow())
-                  search.index++;            
+               {
+                  int ix = index+1;
+                  for(search = GetNextRow(); search; search = search.GetNextRow())
+                     search.index = ix++;
+               }
 
                listBox.SetScrollArea(
                   listBox.width,
@@ -419,6 +477,7 @@ public:
       }
    }
 
+   // NOTE: This does not support reparenting (Use row.parent = first)
    void Move(DataRow after)
    {
       if(this)
@@ -430,6 +489,7 @@ public:
             int afterIndex = -1;
             int headerSize = ((listBox.style.header) ? listBox.rowHeight : 0);
             int height = listBox.clientSize.h + 1 - headerSize;
+            int ixCount = (!collapsed && subRows.count) ? GetLastRow().index - index + 1 : 1;
 
             if(!after || after.index < index)
             {
@@ -439,39 +499,47 @@ public:
                // All rows between AFTER (exclusive) and ROW (exclusive) are incremented by one
                // ROW is equal to AFTER's index + 1
 
-               // TODO: Fix indices
                for(search = after ? after.next : listBox.rows.first; search && search != this; search = search.GetNextRow())
-                  search.index++;
+                  search.index += ixCount;
 
                if(after && after.subRows.first && !after.collapsed)
                {
-                  for(search = after.subRows.last; !search.collapsed && search.subRows.last; )
-                     search = search.subRows.last;
+                  search = after.GetLastRow();
                   index = search.index + 1;
                }
                else
                   index = after ? (after.index + 1) : 0;
+
+               // Fix indices of sub rows
+               if(!collapsed)
+               {
+                  int c, ix = index+1;
+                  for(c = 1, search = GetNextRow(); search && c < ixCount; c++, search = search.GetNextRow())
+                     search.index = ix++;
+               }
             }
             else
             {
+               DataRow nextRow = GetNextRow();
                if(this == listBox.firstRowShown)
-               {
-                  listBox.firstRowShown = GetNextRow();
-               }
+                  listBox.firstRowShown = nextRow;
+               index = after.index;
 
                // All rows between ROW (exclusive) and AFTER (inclusive) are decremented by one
                // ROW is equal to AFTER's index
 
-               // TODO: Fix indices
-               for(search = GetNextRow(); search; search = search.GetNextRow())
+               for(search = nextRow; search; search = search.GetNextRow())
                {
-                  search.index--;
+                  search.index -= ixCount;
                   if(search == after) break;
                }
-               index = after ? (after.index + 1) : 0;
             }
             listBox.rows.Move(this, after);
 
+#ifdef _DEBUG
+            listBox.CheckConsistency();
+#endif
+
             listBox.HideEditBox(true, false, true);
             if(listBox)
             {
@@ -525,18 +593,18 @@ public:
                if(dataType.type == normalClass || dataType.type == noHeadClass)
                {
                   if(cell.data[0] && field.freeData)
-                     dataType._vTbl[__ecereVMethodID_class_OnFree](dataType, cell.data[0]);
+                     ((void (*)(void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnFree])(dataType, cell.data[0]);
 
                   if(eClass_IsDerived(dataType, class(char *)) && field.freeData)
-                     dataType._vTbl[__ecereVMethodID_class_OnCopy](dataType, cell.data, newData);
+                     ((void (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCopy])(dataType, cell.data, newData);
                   else
                      cell.data[0] = (void *)newData;
                }
                else
                {
                   // Free old data first
-                  dataType._vTbl[__ecereVMethodID_class_OnFree](dataType, cell.data);
-                  dataType._vTbl[__ecereVMethodID_class_OnCopy](dataType, cell.data, newData);
+                  ((void (*)(void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnFree])(dataType, cell.data);
+                  ((void (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnCopy])(dataType, cell.data, newData);
                }
             }
             cell.isSet = true;
@@ -565,13 +633,13 @@ public:
                if(dataType.type == normalClass || dataType.type == noHeadClass)
                {
                   if(cell.data[0] && field.freeData)
-                     dataType._vTbl[__ecereVMethodID_class_OnFree](dataType, cell.data[0]);
+                     ((void (*)(void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnFree])(dataType, cell.data[0]);
                   cell.data[0] = null;
                }
                else
                {
                   // Free old data first
-                  dataType._vTbl[__ecereVMethodID_class_OnFree](dataType, cell.data);
+                  ((void (*)(void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnFree])(dataType, cell.data);
                }
             }
             cell.isSet = false;
@@ -580,7 +648,7 @@ public:
       }
    }
 
-   DataRow FindRow(int tag)
+   DataRow FindRow(int64 tag)
    {
       DataRow row = null;
       for(row = subRows.first; row; row = row.next)
@@ -591,7 +659,7 @@ public:
       return row;
    }
 
-   DataRow FindSubRow(int tag)
+   DataRow FindSubRow(int64 tag)
    {
       DataRow row = null;
       for(row = subRows.first; row; row = row.next)
@@ -639,7 +707,7 @@ public:
                }
             }
 
-            if(IsExpanded(this))
+            if(IsExpanded())
             {
                DataRow search;
 
@@ -654,7 +722,6 @@ public:
 
                listBox.rowCount++;
 
-               // TODO: Fix indices
                for(search = row.GetNextRow(); search; search = search.GetNextRow())
                   search.index++;            
 
@@ -669,6 +736,9 @@ public:
 
             listBox.modifiedDocument = true;
          }
+#ifdef _DEBUG
+         listBox.CheckConsistency();
+#endif
          return row;
       }
       return null;
@@ -688,9 +758,9 @@ public:
          DataRow row;
          char string[MAX_F_STRING];
          va_list args;
-
          va_start(args, format);
-         vsprintf(string, format, args);
+         vsnprintf(string, sizeof(string), format, args);
+         string[sizeof(string)-1] = 0;
          va_end(args);
 
          row = AddRow();
@@ -744,10 +814,10 @@ private:
                if(field.dataType.type == normalClass || field.dataType.type == noHeadClass)
                {
                   if(cell.data[0] && field.freeData)
-                     field.dataType._vTbl[__ecereVMethodID_class_OnFree](field.dataType, cell.data[0]);
+                     ((void (*)(void *, void *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnFree])(field.dataType, cell.data[0]);
                }
                else
-                  field.dataType._vTbl[__ecereVMethodID_class_OnFree](field.dataType, cell.data);
+                  ((void (*)(void *, void *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnFree])(field.dataType, cell.data);
             }
          }
          next = cell.next;
@@ -784,13 +854,13 @@ private:
       {
          if(sortField.dataType.type == normalClass || sortField.dataType.type == noHeadClass)
          {
-            result = sortField.dataType._vTbl[__ecereVMethodID_class_OnCompare](sortField.dataType, 
+            result = ((int (*)(void *, void *, void *))(void *)sortField.dataType._vTbl[__ecereVMethodID_class_OnCompare])(sortField.dataType, 
                (cell1.isSet && cell1.data) ? cell1.data[0] : null, 
                (cell2.isSet && cell2.data) ? cell2.data[0] : null);
          }
          else
          {
-            result = sortField.dataType._vTbl[__ecereVMethodID_class_OnCompare](sortField.dataType, 
+            result = ((int (*)(void *, void *, void *))(void *)sortField.dataType._vTbl[__ecereVMethodID_class_OnCompare])(sortField.dataType, 
                cell1.isSet ? cell1.data : null, 
                cell2.isSet ? cell2.data : null);
          }
@@ -812,7 +882,6 @@ private:
       {
          _SortSubRows(listBox.sortField, listBox.sortField.sortOrder);
 
-         // TODO: Recompute row indices
          {
             DataRow search;
             int index = this.index;
@@ -861,9 +930,17 @@ private:
       return row;
    }
 
+   private DataRow GetLastRow()
+   {
+      DataRow row = this;
+      while(row && !row.collapsed && row.subRows.last)
+         row = row.subRows.last;
+      return row;
+   }
+
    DataRow prev, next;
    OldList cells;
-   int tag;
+   int64 tag;
    SelectedFlag selectedFlag;
    ListBox listBox;
    bool header;
@@ -886,12 +963,12 @@ public class ListBox : CommonControl
 
 public:
    // Properties
-   property bool freeSelect { property_category "Behavior" set { style.freeSelect = value; } get { return style.freeSelect; } };
-   property DataRow currentRow { property_category "Private" /*"Behavior"*/ set { SetCurrentRow(value, false); } get { return currentRow; } };
+   property bool freeSelect { property_category $"Behavior" set { style.freeSelect = value; } get { return style.freeSelect; } };
+   property DataRow currentRow { property_category $"Private" /*"Behavior"*/ set { SetCurrentRow(value, false); } get { return currentRow; } };
    property DataField currentField
    {
       get { return currentField; }
-      // TODO: Needs definition of what this is, testing
+      // TODO: Document what this does
       set
       {
          currentField = value;
@@ -903,7 +980,7 @@ public:
 
    property int rowHeight
    {
-      property_category "Appearance" 
+      property_category $"Appearance" 
       isset { return style.heightSet; }
       set
       {
@@ -924,7 +1001,7 @@ public:
    };
    property Seconds typingTimeout
    {
-      property_category "Behavior" 
+      property_category $"Behavior" 
       set
       {
          typedString[0] = '\0';
@@ -933,15 +1010,15 @@ public:
       }
       get { return typingTimeOut; }
    };
-   property bool moveRows { property_category "Behavior" set { style.moveRows = value; } get { return style.moveRows; } };
-   property bool moveFields { property_category "Behavior" set { style.moveFields = value; } get { return style.moveFields; } };
-   property bool resizable { property_category "Behavior" set { style.resizable = value; } get { return style.resizable; } };
-   property bool autoScroll { property_category "Behavior" set { style.autoScroll = value; } get { return style.autoScroll; } };
-   property bool alwaysHighLight { property_category "Appearance" set { style.alwaysHL = value; } get { return style.alwaysHL; } };
-   property bool hasClearHeader { property_category "Appearance" set { style.clearHeader = value; if(value) property::hasHeader = true; } get { return style.clearHeader; } };
+   property bool moveRows { property_category $"Behavior" set { style.moveRows = value; } get { return style.moveRows; } };
+   property bool moveFields { property_category $"Behavior" set { style.moveFields = value; } get { return style.moveFields; } };
+   property bool resizable { property_category $"Behavior" set { style.resizable = value; } get { return style.resizable; } };
+   property bool autoScroll { property_category $"Behavior" set { style.autoScroll = value; } get { return style.autoScroll; } };
+   property bool alwaysHighLight { property_category $"Appearance" set { style.alwaysHL = value; } get { return style.alwaysHL; } };
+   property bool hasClearHeader { property_category $"Appearance" set { style.clearHeader = value; if(value) property::hasHeader = true; } get { return style.clearHeader; } };
    property bool hasHeader
    {
-      property_category "Appearance" 
+      property_category $"Appearance" 
       set
       {
          if(value && !style.header)
@@ -956,6 +1033,7 @@ public:
                size.h = rowHeight;
                NotifyPushed = HeaderPushed;
                NotifyClicked = HeaderClicked;
+               NotifyDoubleClick = HeaderDoubleClicked;
                NotifyReleased = HeaderReleased;
                NotifyMouseMove = HeaderMouseMove;
             };
@@ -967,17 +1045,17 @@ public:
       }
       get { return style.header; }
    };   
-   property bool multiSelect { property_category "Behavior" set { style.multiSelect = value; } get { return style.multiSelect; } };
-   property bool alwaysEdit { property_category "Behavior" set { style.alwaysEdit = value; } get { return style.alwaysEdit; } };
-   property bool fullRowSelect { property_category "Appearance" set { style.fullRowSelect = value; } get { return style.fullRowSelect; } };
-   property bool collapseControl { property_category "Appearance" set { style.collapse = value; } get { return style.collapse; } };
-   property bool treeBranches { property_category "Appearance" set { style.treeBranch = value; } get { return style.treeBranch; } };
-   property bool rootCollapseButton { property_category "Appearance" set { style.rootCollapse = value; } get { return style.rootCollapse; } };
-   property bool sortable { property_category "Behavior" set { style.sortable = value; } get { return style.sortable; } };
-   property bool noDragging { property_category "Behavior" set { style.noDragging = value; } get { return style.noDragging; } };
+   property bool multiSelect { property_category $"Behavior" set { style.multiSelect = value; } get { return style.multiSelect; } };
+   property bool alwaysEdit { property_category $"Behavior" set { style.alwaysEdit = value; } get { return style.alwaysEdit; } };
+   property bool fullRowSelect { property_category $"Appearance" set { style.fullRowSelect = value; } get { return style.fullRowSelect; } };
+   property bool collapseControl { property_category $"Appearance" set { style.collapse = value; } get { return style.collapse; } };
+   property bool treeBranches { property_category $"Appearance" set { style.treeBranch = value; } get { return style.treeBranch; } };
+   property bool rootCollapseButton { property_category $"Appearance" set { style.rootCollapse = value; } get { return style.rootCollapse; } };
+   property bool sortable { property_category $"Behavior" set { style.sortable = value; } get { return style.sortable; } };
+   property bool noDragging { property_category $"Behavior" set { style.noDragging = value; } get { return style.noDragging; } };
    property bool fillLastField
    {
-      property_category "Behavior" 
+      property_category $"Behavior" 
       set
       {
          style.fillLastField = value;
@@ -1031,6 +1109,21 @@ public:
    virtual bool Window::NotifyModified(ListBox listBox, DataRow row);   
    virtual bool Window::NotifyEditing(ListBox listBox, DataRow row);
 
+#ifdef _DEBUG
+   private void CheckConsistency()
+   {
+#if 0
+      DataRow r;
+      int index = 0;
+      for(r = rows.first; r; r = r.GetNextRow())
+      {
+         if(r.index != index++)
+            PrintLn("bug");
+      }
+#endif
+   }
+#endif
+
    // Methods
    void AddField(DataField addedField)
    {
@@ -1040,7 +1133,6 @@ public:
          if(fields.first && ((DataField)fields.first).defaultField)
          {
             DataField defaultField = fields.first;
-            // TODO:
             defaultField.Free();
             delete defaultField;
          }
@@ -1066,13 +1158,14 @@ public:
                stayOnTop = true;
                inactive = true;
                dontScrollVert = true;
-               id = (uint)addedField;
+               id = (uint64)addedField;
                text = addedField.header;
                bevel = (!guiApp.textMode && !style.clearHeader);
                ellipsis = true;
                alignment = addedField.alignment;
                NotifyPushed = HeaderPushed;
                NotifyClicked = HeaderClicked;
+               NotifyDoubleClick = HeaderDoubleClicked;
                NotifyReleased = HeaderReleased;
                NotifyMouseMove = HeaderMouseMove;
             };
@@ -1135,6 +1228,9 @@ public:
             int index = field.index;
             DataRow row;
 
+            if(sortField == field)
+               sortField = null;
+
             for(row = rows.first; row; )
             {
                int c;
@@ -1149,10 +1245,10 @@ public:
                      if(field.dataType.type == normalClass || field.dataType.type == noHeadClass)
                      {
                         if(cell.data[0] && field.freeData)
-                           field.dataType._vTbl[__ecereVMethodID_class_OnFree](field.dataType, cell.data[0]);
+                           ((void (*)(void *, void *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnFree])(field.dataType, cell.data[0]);
                      }
                      else
-                        field.dataType._vTbl[__ecereVMethodID_class_OnFree](field.dataType, cell.data);
+                        ((void (*)(void *, void *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnFree])(field.dataType, cell.data);
                   }
 
                   row.cells.Remove(cell);
@@ -1270,6 +1366,9 @@ public:
                   SetScrollPosition(0, MAXINT - rowHeight);
                modifiedDocument = true;
             }
+#ifdef _DEBUG
+            CheckConsistency();
+#endif
             return row;
          }
       }
@@ -1299,7 +1398,6 @@ public:
             rows.Insert(after, row);
             row.listBox = this;
 
-            // TODO: FIX row indices
             for(search = row.GetNextRow(); search; search = search.GetNextRow())
                search.index++;         
 
@@ -1333,6 +1431,9 @@ public:
             if(style.autoScroll)
                SetScrollPosition(0, MAXINT - rowHeight);
             modifiedDocument = true;
+#ifdef _DEBUG
+            CheckConsistency();
+#endif
             return row;
          }
       }
@@ -1349,7 +1450,8 @@ public:
          va_list args;
 
          va_start(args, format);
-         vsprintf(string, format ? format : "", args);
+         vsnprintf(string, sizeof(string), format ? format : "", args);
+         string[sizeof(string)-1] = 0;
          va_end(args);
 
          row = AddRow();
@@ -1381,12 +1483,19 @@ public:
       if(!row) row = currentRow;
       if(row)
       {
-         DataRow search;
+         DataRow sub, next, search;
          // Trying to move this here (Messed up deleting watches)
          //HideEditBox(false, false, true);
+
+         // Delete Sub Rows
+         for(sub = row.subRows.first; sub; sub = next)
+         {
+            next = sub.next;
+            DeleteRow(sub);
+         }
+
          if(row.parent.IsExpanded())
          {
-            // TODO: FIX row indices
             for(search = row.GetNextRow(); search; search = search.GetNextRow())
                search.index--;         
             this.rowCount--;
@@ -1430,10 +1539,13 @@ public:
          modifiedDocument = true;
 
          Update(null);
+#ifdef _DEBUG
+         CheckConsistency();
+#endif
       }
    }
 
-   DataRow FindRow(int tag)
+   DataRow FindRow(int64 tag)
    {
       if(this)
       {
@@ -1466,7 +1578,7 @@ public:
                   void * data = row.GetData(field);
                   char tempString[1024] = "";
                   bool needClass = false;
-                  char * string = (char *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString](field.dataType, data, tempString, null, &needClass);
+                  char * string = ((char *(*)(void *, void *, char *, void *, bool *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString])(field.dataType, data, tempString, null, &needClass);
 
                   if(string && string[0])
                      checkNextField = false;
@@ -1500,7 +1612,7 @@ public:
                      void * data = row.GetData(field);
                      char tempString[1024] = "";
                      bool needClass = false;
-                     char * string = (char *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString](field.dataType, data, tempString, null, &needClass);
+                     char * string = ((char *(*)(void *, void *, char *, void *, bool *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString])(field.dataType, data, tempString, null, &needClass);
 
                      if(string && string[0])
                         checkNextField = false;
@@ -1538,7 +1650,7 @@ public:
                      void * data = row.GetData(field);
                      char tempString[1024] = "";
                      bool needClass = false;
-                     char * string = (char *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString](field.dataType, data, tempString, null, &needClass);
+                     char * string = ((char *(*)(void *, void *, char *, void *, bool *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString])(field.dataType, data, tempString, null, &needClass);
 
                      if(string && string[0])
                         checkNextField = false;
@@ -1587,7 +1699,7 @@ public:
                      void * data = row.GetData(field);
                      char tempString[1024] = "";
                      bool needClass = false;
-                     char * string = (char *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString](field.dataType, data, tempString, null, &needClass);
+                     char * string = ((char *(*)(void *, void *, char *, void *, bool *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString])(field.dataType, data, tempString, null, &needClass);
 
                      if(string && string[0])
                         checkNextField = false;
@@ -1602,7 +1714,7 @@ public:
       return null;
    }
 
-   DataRow FindSubRow(int tag)
+   DataRow FindSubRow(int64 tag)
    {
       if(this)
       {
@@ -1675,7 +1787,6 @@ public:
          for(search = rows.first; search; search = search.next)
             search._SortSubRows(field, order);
 
-         // TODO: Recompute row indices
          {
             int index = 0;
             for(search = rows.first; search; search = search.GetNextRow())
@@ -1727,9 +1838,9 @@ public:
       return (void *)currentRow.GetData(field);
    }
 
-   int GetTag()
+   int64 GetTag()
    {
-      return currentRow.tag;
+      return currentRow ? currentRow.tag : 0;
    }
 
 private:
@@ -1776,6 +1887,7 @@ private:
    void ClearEx()
    {
       DataRow row;
+      clickedRow = null;
       while((row = rows.first))
       {
          rows.Remove(row);
@@ -1874,7 +1986,8 @@ private:
 
             for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
                selRow.selectedFlag = unselected;
-            currentRow.selectedFlag = selected;
+            if(currentRow)
+               currentRow.selectedFlag = selected;
 
             clickedRow = row;
          }
@@ -2033,6 +2146,7 @@ private:
       Font font = fontObject;
       Font boldFont = this.boldFont.font;
 
+
       // Draw gray grid
       if(style.alwaysEdit && style.fullRowSelect)
       {
@@ -2048,11 +2162,11 @@ private:
          if(style.collapse && !(style.treeBranch) && rows.first)
          {
             x += 15;
-            surface.SetBackground(activeBorder);
+            surface.SetBackground(formColor);
             surface.Area(-scroll.x, 0, x, clientSize.h);
          }
 
-         surface.SetForeground(activeBorder);
+         surface.SetForeground(formColor);
          for(row = firstRowShown; row; row = row.GetNextRow())
          {
             y += rowHeight;
@@ -2066,7 +2180,7 @@ private:
          {
             int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ? 
                clientSize.w - field.x : (field.width + EXTRA_SPACE);
-            if(field.prev)
+            if(field.prev && y > 0)
                surface.VLine(0, y-1, x);
             x += width;
          }
@@ -2178,10 +2292,11 @@ private:
          DataRow parent;
          Bitmap icon = row.icon ? row.icon.bitmap : null;
          int collapseRowStart;
+         bool lastWasHeader = row.header;
 
          for(parent = row.parent; parent; parent = parent.parent)
          {
-            if(!parent.header)
+            if(!parent.header || lastWasHeader)
             {
                if(style.treeBranch)
                   indent += 20;
@@ -2237,8 +2352,12 @@ private:
          // Draw the current row background
          if(row.header)
          {
-            background = activeBorder;
-            surface.SetBackground(activeBorder);
+            Color colors[] = { formColor, azure, mistyRose, linen, floralWhite, lavender, lavenderBlush, lemonChiffon };
+            int level = 0;
+            DataRow p = row;
+            while(p = p.parent) level++;
+            background = colors[(level % (sizeof(colors)/sizeof(colors[0]))];
+            surface.SetBackground(background);
             surface.Area(rowStart, y, clientSize.w, (y + rowHeight) - 1);
             foreground = branchesColor;
          }
@@ -2247,7 +2366,7 @@ private:
             if(dataDisplayFlags.selected && (isActive || style.alwaysHL || (style.alwaysEdit && style.fullRowSelect)))
             {
                if(!isActive && style.alwaysEdit)
-                  background = activeBorder;
+                  background = formColor;
                else
                   background = selectionColor ? selectionColor : SELECTION_COLOR;
                if(style.fullRowSelect)
@@ -2285,15 +2404,16 @@ private:
             surface.SetForeground(foreground);
             surface.SetBackground(background);
 
-            class(String)._vTbl[__ecereVMethodID_class_OnDisplay](class(String), "(none)", surface, x, y - 1 + (rowHeight - fontH)/2, width - EXTRA_SPACE/2, null, Alignment::left, dataDisplayFlags);
+            ((void (*)(void *, void *, void *, int, int, int, void *, uint, uint))(void *)class(String)._vTbl[__ecereVMethodID_class_OnDisplay])(class(String), "(none)", surface, x, y - 1 + (rowHeight - fontH)/2, width - EXTRA_SPACE/2, null, Alignment::left, dataDisplayFlags);
          }
          else
          {
+            if(!opacity) surface.TextOpacity(false);
             // Draw the rows
             for(field = fields.first; field; field = field.next)
             {
                uint index;
-               int width = (!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) ? 
+               int width = ((!field.next && style.fillLastField && (!hasHorzScroll || clientSize.w - field.x > field.width + EXTRA_SPACE)) || row.header) ?
                   clientSize.w - field.x : (field.width + EXTRA_SPACE);
 
                // Box clip = { x, y+1, x + field.width - EXTRA_SPACE - 1, y + rowHeight - 2 };
@@ -2312,7 +2432,7 @@ private:
                   foreground = this.foreground;
                }
 
-               if(!isActive && dataDisplayFlags.selected && style.alwaysEdit && field.editable)
+               if(!isActive && dataDisplayFlags.selected && style.alwaysEdit && field.editable && opacity)
                {
                   surface.Clip(null);
                   surface.SetBackground(background);
@@ -2338,17 +2458,17 @@ private:
                   surface.SetBackground(background);
 
                   if(field.dataType.type == noHeadClass || field.dataType.type == normalClass)
-                     field.dataType._vTbl[__ecereVMethodID_class_OnDisplay](field.dataType, cell.data[0], surface, x, y - 1 + (rowHeight - fontH)/2, width - EXTRA_SPACE/2, field.userData, field.alignment, dataDisplayFlags);
+                     ((void (*)(void *, void *, void *, int, int, int, void *, uint, uint))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnDisplay])(field.dataType, cell.data[0], surface, x, y - 1 + (rowHeight - fontH)/2, width - EXTRA_SPACE/2, field.userData, field.alignment, dataDisplayFlags);
                   else
-                     field.dataType._vTbl[__ecereVMethodID_class_OnDisplay](field.dataType, cell.data, surface, x, y - 1 + (rowHeight - fontH)/2, width - EXTRA_SPACE/2, field.userData, field.alignment, dataDisplayFlags);
+                     ((void (*)(void *, void *, void *, int, int, int, void *, uint, uint))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnDisplay])(field.dataType, cell.data, surface, x, y - 1 + (rowHeight - fontH)/2, width - EXTRA_SPACE/2, field.userData, field.alignment, dataDisplayFlags);
                }
 
                if(!isActive && dataDisplayFlags.selected && style.alwaysEdit && field.editable)
-                  background = activeBorder;
+                  background = formColor;
 
                if(!dataDisplayFlags.firstField && !dataDisplayFlags.fullRow)
                {
-                  background = activeBorder;
+                  background = formColor;
                   foreground = this.background;
                }
 
@@ -2367,7 +2487,7 @@ private:
                surface.SetForeground(row.header ? headerCollapseForeground : this.foreground);
                surface.Rectangle(collapseRowStart + 3 + plusIndent, y + PLUSY, collapseRowStart + 11 + plusIndent, y + PLUSY + 8);
 
-               surface.SetBackground(row.header ? (activeBorder) : (this.background)); //white
+               surface.SetBackground(row.header ? (formColor) : (this.background)); //white
                surface.Area(collapseRowStart + 4 + plusIndent, y + PLUSY + 1, collapseRowStart + 10 + plusIndent, y + PLUSY + 7);
 
                surface.HLine(collapseRowStart + 5 + plusIndent, collapseRowStart + 9 + plusIndent, y+PLUSY+4);
@@ -2459,7 +2579,7 @@ private:
             }
             else if(field.alignment == right)
             {
-               x = field.x + width - tw - EXTRA_SPACE - 4;
+               x = field.x + width - tw - 2*EXTRA_SPACE - 4;
                x = Max(x, field.x + 2);
             }
             x -= scroll.x;
@@ -2597,6 +2717,7 @@ private:
          else if(x < RESIZE_BORDER && field.prev)
             field = field.prev;
 
+         if(field.fixed) return false;
          resizingField = field;
          this.resizeX = x + control.position.x;
          this.startWidth = field.width;
@@ -2605,6 +2726,7 @@ private:
       }
       else if(field)
       {
+         if(field.fixed) return false;
          draggingField = field;
          if(style.moveFields)
             field.headButton.stayDown = true;
@@ -2700,7 +2822,10 @@ private:
          if(field)
          {
             if(x < RESIZE_BORDER && field.prev)
-               control.cursor = guiApp.GetCursor(sizeWE);
+            {
+               if(!field.prev.fixed)
+                  control.cursor = guiApp.GetCursor(sizeWE);
+            }
             else if(x >= control.clientSize.w - RESIZE_BORDER)
                control.cursor = guiApp.GetCursor(sizeWE);
             else
@@ -2797,6 +2922,32 @@ private:
       return true;
    }
 
+   bool HeaderDoubleClicked(Button control, int x, int y, Modifiers mods)
+   {
+      if(style.resizable)
+      {
+         DataField field = (DataField)control.id;
+         if(field)
+         {
+            if(x < RESIZE_BORDER && field.prev)
+               field = field.prev;
+            else if(x >= control.clientSize.w - RESIZE_BORDER);
+            else
+               field = null;
+         }
+         else
+         {
+            if(x < RESIZE_BORDER && fields.last)
+               field = fields.last;
+            else
+               field = null;
+         }
+         if(field)
+            field.AutoSize();
+      }
+      return false;
+   }
+
    watch(visible)
    {
       if(style.freeSelect)
@@ -2891,14 +3042,13 @@ private:
                      // Should always be as many cells in the row as fields in the listbox
                      if(cell && cell.isSet && field.dataType)
                      {
-                        Bitmap icon = null;
-                        char tempString[1024];
+                        static char tempString[4096];
                         char * string;
                         int tw, th;
-                        if(field.dataType.type == normalClass || field.dataType.type == noHeadClass)
-                           string = (char *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString](field.dataType, cell.data[0], tempString, field.userData, null);
+                        if(field.dataType.type == normalClass || field.dataType.type == noHeadClass)
+                           string = ((char *(*)(void *, void *, char *, void *, bool *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString])(field.dataType, cell.data[0], tempString, field.userData, null);
                         else
-                           string = (char *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString](field.dataType, cell.data, tempString, field.userData, null);
+                           string = ((char *(*)(void *, void *, char *, void *, bool *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString])(field.dataType, cell.data, tempString, field.userData, null);
                         /* GCC-4.4 Bug!
                        if(!string) string = "";
                         display.FontExtent(row.header ? boldFont : font, string, strlen(string), &tw, &th);
@@ -3877,7 +4027,7 @@ private:
                void * data = row.GetData(field);
                char tempString[1024] = "";
                bool needClass = false;
-               char * string = data ? (char *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString](field.dataType, data, tempString, null, &needClass) : null;
+               char * string = data ? ((char *(*)(void *, void *, char *, void *, bool *))(void *)field.dataType._vTbl[__ecereVMethodID_class_OnGetString])(field.dataType, data, tempString, null, &needClass) : null;
 
                if(string && string[0])
                   checkNextField = false;
@@ -4033,256 +4183,254 @@ private:
          }
       }
 
-      if(!(style.multiSelect) && (key.ctrl))
-         return true;
-
       if(editData && editData.visible && ch && !key.alt && !key.ctrl && editData.active)
          return false;
 
-      switch(key.code)
+      if(!key.alt && (style.multiSelect || !key.ctrl))
       {
-         case left:
-            if(style.alwaysEdit)
-            {
-               if(currentField)
+         switch(key.code)
+         {
+            case left:
+               if(style.alwaysEdit)
                {
-                  DataField field;
-                  for(field = currentField.prev; field; field = field.prev)
+                  if(currentField)
                   {
-                     if(field.editable)
+                     DataField field;
+                     for(field = currentField.prev; field; field = field.prev)
                      {
-                        currentField = field;
-                        HideEditBox(true, true, false);
-                        PopupEditBox(currentField, false);
-                        return false;
-                     }                     
+                        if(field.editable)
+                        {
+                           currentField = field;
+                           HideEditBox(true, true, false);
+                           PopupEditBox(currentField, false);
+                           return false;
+                        }
+                     }
                   }
                }
-            }
-            if(style.collapse && currentRow /*&& !currentField*/)  // THIS PREVENTED COLLAPSING THE PROPERTY SHEET
-            {
-               if(currentRow.subRows.first && !currentRow.collapsed)
+               if(style.collapse && currentRow /*&& !currentField*/)  // THIS PREVENTED COLLAPSING THE PROPERTY SHEET
                {
-                  currentRow.collapsed = true;
+                  if(currentRow.subRows.first && !currentRow.collapsed)
+                  {
+                     currentRow.collapsed = true;
+                  }
+                  else if(currentRow.parent)
+                     SetCurrentRow(currentRow.parent, true);
+                  return false;
                }
-               else if(currentRow.parent)
-                  SetCurrentRow(currentRow.parent, true);
-               return false;
-            }
-            break;
-         case right:
-            if(style.collapse && currentRow && currentRow.subRows.first)
-            {
-               if(currentRow.collapsed)
-                  currentRow.collapsed = false;
-               else
-                  SetCurrentRow(currentRow.subRows.first, true);
-               return false;
-            }
-            else if(style.alwaysEdit)
-            {
-               if(currentField)
+               break;
+            case right:
+               if(style.collapse && currentRow && currentRow.subRows.first)
+               {
+                  if(currentRow.collapsed)
+                     currentRow.collapsed = false;
+                  else
+                     SetCurrentRow(currentRow.subRows.first, true);
+                  return false;
+               }
+               else if(style.alwaysEdit)
                {
-                  DataField field;
-                  for(field = currentField.next; field; field = field.next)
+                  if(currentField)
                   {
-                     if(field.editable)
+                     DataField field;
+                     for(field = currentField.next; field; field = field.next)
                      {
-                        currentField = field;
-                        HideEditBox(true, true, false);
-                        PopupEditBox(currentField, false);
-                        break;
-                     }                     
+                        if(field.editable)
+                        {
+                           currentField = field;
+                           HideEditBox(true, true, false);
+                           PopupEditBox(currentField, false);
+                           break;
+                        }
+                     }
                   }
                }
-            }
-            break;
-         case down: case up:
-         case pageDown: case pageUp:
-         case end: case home:
-         {
-            int headerSize = ((style.header) ? rowHeight : 0);
-            int height = clientSize.h + 1 - headerSize;
-            DataRow oldRow;
+               break;
+            case down: case up:
+            case pageDown: case pageUp:
+            case end: case home:
+            {
+               int headerSize = ((style.header) ? rowHeight : 0);
+               int height = clientSize.h + 1 - headerSize;
+               DataRow oldRow;
 
-            // true: destroy edit box
-            // !!! TESTING true HERE !!!
-            HideEditBox(true, true, false);
-            // HideEditBox(false, true, false);
-            
-            oldRow = currentRow;
+               // true: destroy edit box
+               // !!! TESTING true HERE !!!
+               HideEditBox(true, true, false);
+               // HideEditBox(false, true, false);
 
-            SNAPDOWN(height, rowHeight);
-            if((!currentRow || key.code == home) && key.code != end)
-            {
-               currentRow = rows.first;
-            }
-            else
-            {
-               DataRow next;
-               switch(key.code)
+               oldRow = currentRow;
+
+               SNAPDOWN(height, rowHeight);
+               if((!currentRow || key.code == home) && key.code != end)
                {
-                  case down:
-                     if(!(style.multiSelect) && currentRow && !currentRow.selectedFlag)
-                        next = currentRow;
-                     else
-                        next = currentRow.GetNextRow();
-                     if(next)
+                  currentRow = rows.first;
+               }
+               else
+               {
+                  DataRow next;
+                  switch(key.code)
+                  {
+                     case down:
+                        if(!(style.multiSelect) && currentRow && !currentRow.selectedFlag)
+                           next = currentRow;
+                        else
+                           next = currentRow.GetNextRow();
+                        if(next)
+                        {
+                           currentRow = next;
+                        }
+                        break;
+                     case up:
+                        if(!(style.multiSelect) && currentRow && !currentRow.selectedFlag)
+                           next = currentRow;
+                        else
+                           next = currentRow.GetPrevRow();
+
+                        if(next)
+                        {
+                           currentRow = next;
+                        }
+                        break;
+                     case end:
+                        currentRow = lastRow.GetLastRow();
+                        break;
+                     case pageUp:
                      {
-                        currentRow = next;
+                        int c;
+                        for(c = 0;
+                        currentRow && (next = currentRow.GetPrevRow()) && c < height / rowHeight;
+                            c++, currentRow = next);
+                        break;
                      }
-                     break;
-                  case up:
-                     if(!(style.multiSelect) && currentRow && !currentRow.selectedFlag)
-                        next = currentRow;
-                     else
-                        next = currentRow.GetPrevRow();
-
-                     if(next)
+                     case pageDown:
                      {
-                        currentRow = next;
+                        int c;
+                        for(c = 0;
+                            currentRow && (next = currentRow.GetNextRow()) && c < height / rowHeight;
+                            c++, currentRow = next);
+                        break;
                      }
-                     break;
-                  case end:
-                     // TODO: Find very last row
-                     for(currentRow = rows.last; currentRow && !currentRow.collapsed && currentRow.subRows.last;)
-                        currentRow = currentRow.subRows.last;
-                     break;
-                  case pageUp:
-                  {
-                     int c;
-                     for(c = 0;
-                     currentRow && (next = currentRow.GetPrevRow()) && c < height / rowHeight;
-                         c++, currentRow = next);
-                     break;
-                  }
-                  case pageDown:
-                  {
-                     int c;
-                     for(c = 0;
-                         currentRow && (next = currentRow.GetNextRow()) && c < height / rowHeight;
-                         c++, currentRow = next);
-                     break;
                   }
                }
-            }
-            if(currentRow && currentRow.index * rowHeight > scroll.y + height - rowHeight)
-               SetScrollPosition(scroll.x, currentRow.index * rowHeight - height + rowHeight);
-            else if(!currentRow || currentRow.index * rowHeight < scroll.y)
-               SetScrollPosition(scroll.x, currentRow ? currentRow.index * rowHeight : 0);
-
-            if(style.multiSelect)
-            {
-               DataRow selRow;
+               if(currentRow && currentRow.index * rowHeight > scroll.y + height - rowHeight)
+                  SetScrollPosition(scroll.x, currentRow.index * rowHeight - height + rowHeight);
+               else if(!currentRow || currentRow.index * rowHeight < scroll.y)
+                  SetScrollPosition(scroll.x, currentRow ? currentRow.index * rowHeight : 0);
 
-               if(!(key.shift) && (key.ctrl))
+               if(style.multiSelect)
                {
-                  DataRow row;
-                  for(row = rows.first; row; row = row.GetNextRow())
+                  DataRow selRow;
+
+                  if(!(key.shift) && (key.ctrl))
                   {
-                     if(row.selectedFlag == tempSelected)
-                        row.selectedFlag = selected;
-                     else if(row.selectedFlag == tempUnselected)
-                        row.selectedFlag = unselected;
+                     DataRow row;
+                     for(row = rows.first; row; row = row.GetNextRow())
+                     {
+                        if(row.selectedFlag == tempSelected)
+                           row.selectedFlag = selected;
+                        else if(row.selectedFlag == tempUnselected)
+                           row.selectedFlag = unselected;
+                     }
                   }
-               }
 
-               if(!(key.ctrl))
-               {
-                  for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
-                     selRow.selectedFlag = unselected;
-               }
-               else
-               {
-                  for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
+                  if(!(key.ctrl))
                   {
-                     if(selRow.selectedFlag == tempUnselected) selRow.selectedFlag = selected;
-                     else if(selRow.selectedFlag == tempSelected) selRow.selectedFlag = unselected;
+                     for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
+                        selRow.selectedFlag = unselected;
+                  }
+                  else
+                  {
+                     for(selRow = rows.first; selRow; selRow = selRow.GetNextRow())
+                     {
+                        if(selRow.selectedFlag == tempUnselected) selRow.selectedFlag = selected;
+                        else if(selRow.selectedFlag == tempSelected) selRow.selectedFlag = unselected;
+                     }
                   }
-               }
 
-               if(key.shift)
-               {
-                  if(currentRow.index >= clickedRow.index)
+                  if(key.shift)
                   {
-                     for(selRow = clickedRow; selRow; selRow = selRow.GetNextRow())
+                     if(currentRow.index >= clickedRow.index)
                      {
-                        if(key.ctrl)
+                        for(selRow = clickedRow; selRow; selRow = selRow.GetNextRow())
                         {
-                           if(selRow.selectedFlag) selRow.selectedFlag = tempUnselected; else selRow.selectedFlag = tempSelected;
+                           if(key.ctrl)
+                           {
+                              if(selRow.selectedFlag) selRow.selectedFlag = tempUnselected; else selRow.selectedFlag = tempSelected;
+                           }
+                           else
+                              selRow.selectedFlag = selected;
+                           if(selRow == currentRow)
+                              break;
+                        }
+                     }
+                     else
+                     {
+                        for(selRow = currentRow; selRow; selRow = selRow.GetNextRow())
+                        {
+                           if(key.ctrl)
+                           {
+                              if(selRow.selectedFlag) selRow.selectedFlag = tempUnselected; else selRow.selectedFlag = tempSelected;
+                           }
+                           else
+                              selRow.selectedFlag = selected;
+                           if(selRow == clickedRow)
+                              break;
                         }
-                        else
-                           selRow.selectedFlag = selected;
-                        if(selRow == currentRow)
-                           break;
                      }
                   }
                   else
                   {
-                     for(selRow = currentRow; selRow; selRow = selRow.GetNextRow())
+                     if(!(key.ctrl) && currentRow)
                      {
-                        if(key.ctrl)
-                        {
-                           if(selRow.selectedFlag) selRow.selectedFlag = tempUnselected; else selRow.selectedFlag = tempSelected;
-                        }
-                        else
-                           selRow.selectedFlag = selected;
-                        if(selRow == clickedRow)
-                           break;
+                        currentRow.selectedFlag = selected;
                      }
+
+                     clickedRow = currentRow;
                   }
                }
                else
                {
-                  if(!(key.ctrl) && currentRow)
-                  {
-                     currentRow.selectedFlag = selected;
-                  }
-
-                  clickedRow = currentRow;
+                  if(oldRow) oldRow.selectedFlag = unselected;
+                  if(currentRow) currentRow.selectedFlag = selected;
                }
-            }
-            else
-            {
-               if(oldRow) oldRow.selectedFlag = unselected;
-               if(currentRow) currentRow.selectedFlag = selected;
-            }
 
-            if(currentRow)
-            {
-               if(style.freeSelect)
-                  NotifyHighlight(master, this, currentRow, 0);
-               else
-                  NotifySelect(master, this, currentRow, 0);
+               if(currentRow)
+               {
+                  if(style.freeSelect)
+                     NotifyHighlight(master, this, currentRow, 0);
+                  else
+                     NotifySelect(master, this, currentRow, 0);
 
-               if(style.alwaysEdit && currentRow)
-                  currentRow.Edit(currentField /*null*/);
+                  if(style.alwaysEdit && currentRow)
+                     currentRow.Edit(currentField /*null*/);
+               }
+               Update(null);
+               return false;
             }
-            Update(null);
-            return false;
-         }
-         case space:
-         {
-            if(style.multiSelect && currentRow)
+            case space:
             {
-               if(currentRow.selectedFlag)
+               if(style.multiSelect && currentRow)
                {
-                  if(key.ctrl)
-                     currentRow.selectedFlag = unselected;
-               }
-               else
-                  currentRow.selectedFlag = selected;
-               Update(null);
+                  if(currentRow.selectedFlag)
+                  {
+                     if(key.ctrl)
+                        currentRow.selectedFlag = unselected;
+                  }
+                  else
+                     currentRow.selectedFlag = selected;
+                  Update(null);
 
-               if(style.freeSelect)
-                  NotifyHighlight(master, this, currentRow, 0);
-               else
-                  NotifySelect(master, this, currentRow, 0);
+                  if(style.freeSelect)
+                     NotifyHighlight(master, this, currentRow, 0);
+                  else
+                     NotifySelect(master, this, currentRow, 0);
+               }
+               break;
             }
-            break;
          }
       }
+
       if(!NotifyKeyHit(master, this, currentRow, key, ch))
          return false;
 
@@ -4299,7 +4447,6 @@ private:
       return true;
    }
 
-
    void OnHScroll(ScrollBarAction action, int position, Key key)
    {
       Update(null);