ecere/gui/ListBox: Fixed moving rows updating with wrong index
[sdk] / ecere / src / gui / controls / ListBox.ec
index 2c00882..37cc0eb 100644 (file)
@@ -61,6 +61,7 @@ public:
       get { return dataType; }
    }
    property bool editable { set { editable = value; } };
+   property bool fixed { set { fixed = value; } get { return fixed; } };
    property Alignment alignment
    {
       set
@@ -169,7 +170,10 @@ public:
          Font font = listBox.fontObject;
          DataRow row;
          int width = 0;
-         for(row = listBox.firstRow; row; row = row.next)
+         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;
@@ -180,9 +184,9 @@ public:
                String string;
                int tw = 0;
                if(dataType.type == normalClass || dataType.type == noHeadClass)
-                  string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, cell.data[0], tempString, userData, null);
+                  string = ((char *(*)(void *, void *, char *, void *, bool *))(void *)dataType._vTbl[__ecereVMethodID_class_OnGetString])(dataType, cell.data[0], tempString, userData, null);
                else
-                  string = (char *)dataType._vTbl[__ecereVMethodID_class_OnGetString](dataType, cell.data, tempString, userData, null);
+                  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
@@ -244,6 +248,7 @@ private:
    bool defaultField;
    void * userData;
    bool freeData;
+   bool fixed;
 };
 
 public class DataRow
@@ -253,7 +258,7 @@ public class DataRow
    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; } };
@@ -396,7 +401,7 @@ public:
 #endif
             }
 
-            if(value.IsExpanded(this))
+            if(value.IsExpanded())
             {
                DataRow search;
 
@@ -517,10 +522,8 @@ public:
             {
                DataRow nextRow = GetNextRow();
                if(this == listBox.firstRowShown)
-               {
                   listBox.firstRowShown = nextRow;
-                  index = after ? (after.index + 1) : 0;
-               }
+               index = after.index;
 
                // All rows between ROW (exclusive) and AFTER (inclusive) are decremented by one
                // ROW is equal to AFTER's index
@@ -590,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;
@@ -630,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;
@@ -645,7 +648,7 @@ public:
       }
    }
 
-   DataRow FindRow(int tag)
+   DataRow FindRow(int64 tag)
    {
       DataRow row = null;
       for(row = subRows.first; row; row = row.next)
@@ -656,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)
@@ -704,7 +707,7 @@ public:
                }
             }
 
-            if(IsExpanded(this))
+            if(IsExpanded())
             {
                DataRow search;
 
@@ -755,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();
@@ -811,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;
@@ -851,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);
          }
@@ -937,7 +940,7 @@ private:
 
    DataRow prev, next;
    OldList cells;
-   int tag;
+   int64 tag;
    SelectedFlag selectedFlag;
    ListBox listBox;
    bool header;
@@ -1155,7 +1158,7 @@ public:
                stayOnTop = true;
                inactive = true;
                dontScrollVert = true;
-               id = (uint)addedField;
+               id = (uint64)addedField;
                text = addedField.header;
                bevel = (!guiApp.textMode && !style.clearHeader);
                ellipsis = true;
@@ -1225,6 +1228,9 @@ public:
             int index = field.index;
             DataRow row;
 
+            if(sortField == field)
+               sortField = null;
+
             for(row = rows.first; row; )
             {
                int c;
@@ -1239,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);
@@ -1444,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();
@@ -1538,7 +1545,7 @@ public:
       }
    }
 
-   DataRow FindRow(int tag)
+   DataRow FindRow(int64 tag)
    {
       if(this)
       {
@@ -1571,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;
@@ -1605,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;
@@ -1643,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;
@@ -1692,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;
@@ -1707,7 +1714,7 @@ public:
       return null;
    }
 
-   DataRow FindSubRow(int tag)
+   DataRow FindSubRow(int64 tag)
    {
       if(this)
       {
@@ -1831,7 +1838,7 @@ public:
       return (void *)currentRow.GetData(field);
    }
 
-   int GetTag()
+   int64 GetTag()
    {
       return currentRow ? currentRow.tag : 0;
    }
@@ -2285,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;
@@ -2344,8 +2352,12 @@ private:
          // Draw the current row background
          if(row.header)
          {
-            background = formColor;
-            surface.SetBackground(formColor);
+            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;
          }
@@ -2392,7 +2404,7 @@ 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
          {
@@ -2401,7 +2413,7 @@ private:
             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 };
@@ -2446,9 +2458,9 @@ 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)
@@ -2567,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;
@@ -2705,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;
@@ -2713,6 +2726,7 @@ private:
       }
       else if(field)
       {
+         if(field.fixed) return false;
          draggingField = field;
          if(style.moveFields)
             field.headButton.stayDown = true;
@@ -2808,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
@@ -3029,9 +3046,9 @@ private:
                         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);
+                           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);
@@ -4010,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;
@@ -4135,9 +4152,6 @@ private:
 
    bool OnKeyHit(Key key, unichar ch)
    {
-      if(key.code == up && key.alt == true && key.ctrl == false && key.shift == false)
-         return true;
-
       if(!ch && !key.alt && !key.ctrl)
       {
          key.code = (SmartKey)key.code;
@@ -4169,254 +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:
-                     currentRow = lastRow.GetLastRow();
-                     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;
 
@@ -4433,7 +4447,6 @@ private:
       return true;
    }
 
-
    void OnHScroll(ScrollBarAction action, int position, Key key)
    {
       Update(null);