+ textOffset = indent * indentSize + (icon ? (icon.width + 6) : 0);
+
+ if(info)
+ sprintf(label, "%s [%s]", name, info);
+ else
+ strcpy(label, name);
+ len = strlen(label);
+
+ surface.WriteTextDots
+ (alignment, x + textOffset, y + 2, width - textOffset, label, len);
+ if(type == pictureFile && control.previewPictures && bitmap)
+ {
+#ifndef __linux__
+ //surface.Filter(bitmap, (clientSize.w - w) / 2,(clientSize.h - h) / 2, 0,0, w, h, bitmap.width, bitmap.height);
+ surface.Filter(bitmap, x + indent * indentSize + 2, y, 0, 0, w, h, bitmap.width, bitmap.height);
+#else
+ // Until Filter / Stretch works with X
+ //surface.Blit(bitmap, (clientSize.w - bitmap.width) / 2,(clientSize.h - bitmap.height) / 2, 0,0, bitmap.width, bitmap.height);
+ surface.blend = true;
+ surface.Blit(bitmap, x + indent * indentSize + 2, y,0,0, w, h);
+#endif
+ //bitmap.Free();
+ //delete bitmap;
+ }
+ else if(icon)
+ surface.Blit(icon, x + indent * indentSize + 2, y,0,0, icon.width, icon.height);
+ }
+
+ int OnCompare(ExplorerFileItem b)
+ {
+ int result;
+ if(type == b.type || (type < folder && b.type < folder) || (type >= drive))
+ result = strcmpi(name, b.name);
+ else
+ {
+ if(type == folder && b.type < folder) result = -1;
+ else if(type < folder && b.type == folder) result = 1;
+ }
+ return result;
+ }
+
+ void OnCopy(ExplorerFileItem newData)
+ {
+ type = newData.type;
+ indent = newData.indent;
+ if(newData.name)
+ {
+ int len = strlen(newData.name) + 1;
+ name = new char[len];
+ CopyBytes(name, newData.name, len);
+ }
+ }
+
+ bool OnGetDataFromString(char * string)
+ {
+ int len = strlen(string) + 1;
+ name = new char[len];
+ CopyBytes(name, string, len);
+ return true;
+ }
+
+ void OnFree()
+ {
+ delete path;
+ delete name;
+ delete info;
+ delete extension;
+ if(bitmap)
+ bitmap.Free();
+ }
+
+ char * OnGetString(char * string, void * fieldData, bool * needClass)
+ {
+ return name;
+ }
+};
+
+public class ExplorerFileItemArray : RedjArray
+{
+ type = class(ExplorerFileItem);
+public:
+ ExplorerFileItem * const _;
+ ExplorerFileItem * Add(ExplorerFileItem item)
+ {
+ uint pos = _count;
+ Append(1);
+ _[pos] = item;
+ return &_[pos];
+ }
+ ExplorerFileItem * AddBefore(uint position, ExplorerFileItem item)
+ {
+ Insert(position, 1);
+ _[position] = item;
+ return &_[position];
+ }
+ void Clear()
+ {
+ int c;
+ for(c = 0; c < _count; c++)
+ {
+ //_[c].Free()
+ delete _[c];
+ }
+ count = 0;
+ size = 0;
+ }
+}
+
+ExplorerFileItem MakeFileItem(const FileAttribs attribs, const char * fileName, const char * filePath, const bool previewPicture, const DisplaySystem displaySystem)
+{
+ int len = strlen(fileName);
+ char info[MAX_LOCATION];
+ char name[MAX_LOCATION];
+ char extension[MAX_EXTENSION];
+
+ ExplorerFileItem item { };
+
+ //if(stats.attribs.isFile) // -- should work now
+ if(attribs.isDirectory)
+ {
+ extension[0] = 0;
+
+ item.type = (attribs.isDrive) ? drive : folder;
+ if(attribs.isServer)
+ item.type = server;
+ if(attribs.isShare)
+ item.type = share;
+ if(attribs.isCDROM)
+ item.type = cdrom;
+ if(attribs.isRemote)
+ item.type = netDrive;
+ if(attribs.isRemovable)
+ {
+ if(fileName[0] == 'A' || fileName[0] == 'B')
+ item.type = floppy;
+ else
+ item.type = removable;
+ }
+ }
+ else
+ {
+ GetExtension(fileName, extension);
+ //strupr(extension);
+ strlwr(extension);
+
+ item.type = _FileType::SelectByExtension(extension);
+ }
+
+ if(attribs.isDrive &&
+ len > 3 && !strncmp(&fileName[1], ": [", 3))
+ {
+ strncpy(name, fileName, 2);
+ name[2] = 0;
+ strncpy(info, &fileName[4], len - 5);
+ info[len - 5] = 0;
+ }
+ else
+ {
+ strcpy(name, fileName);
+ info[0] = 0;
+ }
+
+ item.path = CopyString(filePath);
+ item.name = CopyString(name);
+ if(info[0])
+ item.info = CopyString(info);
+ item.extension = CopyString(extension);
+
+ if(item.type == pictureFile && previewPicture)
+ {
+ item.bitmap = Bitmap { };
+ item.bitmap.Load(filePath, null, displaySystem);
+ }
+
+ return item;
+}
+#endif
+*/
+
+public class FileSystemNode : struct
+{
+public:
+ /*//LinkElement<FileSystemNode> link;
+ FileSystemNode parent;
+
+ FileSystemNodeType type;
+
+ char * name;*/
+
+ FileSystemNode prev, next;
+
+ bool loaded, childrenLoaded;
+ int indent;
+ char * path;
+ char * name;
+ char * label;
+ char * extension;
+ char * info;
+ DataRow row;
+ OldList children;
+ _FileType type;
+ FileSystemNode parent;
+
+ FileStats stats;
+
+ Bitmap bitmap;
+
+ void GetPath(String outputPath)
+ {
+ FileSystemNode up;
+ if(parent)
+ {
+ if(name)
+ strcpy(outputPath, name);
+ for(up = parent; up; up = up.parent)
+ {
+ char temp[MAX_LOCATION];
+ strcpy(temp, up.name);
+ PathCat(temp, outputPath);
+ strcpy(outputPath, temp);
+ }
+ }
+ else
+/*#ifdef __WIN32__
+ strcpy(outputPath, "/");
+#else*/
+ strcpy(outputPath, name);
+//#endif
+
+ }
+
+ bool IsChildOf(FileSystemNode node)
+ {
+ FileSystemNode test;
+ for(test = parent; test; test = test.parent)
+ if(test == node)
+ return true;
+ return false;
+ }
+
+ void DuplicateChildren(bool recursive, bool forceExpanded, FileSystemNode addTo, FileSystemBox fsb)
+ {
+ if(children.first)
+ {
+ FileSystemNode child;
+
+ for(child = children.first; child; child = child.next)
+ {
+ FileSystemNode copy { };
+ copy.name = CopyString(child.name);
+ copy.type = child.type;
+ fsb.AddTreeNode(copy, child.loaded, false, addTo);
+ if(forceExpanded)
+ copy.row.collapsed = false;
+ if(recursive)
+ child.DuplicateChildren(recursive, forceExpanded, copy, fsb);
+ }
+ }
+ }
+
+ void EnsureVisible(bool expand)
+ {
+ if(parent)
+ parent.EnsureVisible(true);
+ if(expand)
+ row.collapsed = false;
+ // TODO: row.EnsureVisible(); // making the row visible by scrolling
+ }
+
+ void OnFree()
+ {
+ //delete name;
+ }
+
+ void Free()
+ {
+ FileSystemNode child;
+ for(; (child = children.first); )
+ {
+ child.Free();
+ children.Delete(child);
+ }
+ //if(name)
+ delete name;
+ delete label;
+ delete info;
+ }
+
+ void Delete()
+ {
+ Free();
+ if(parent)
+ parent.children.Delete(this);
+ }
+
+ void OnDisplay(Surface surface, int x, int y, int width, FileSystemBox fsb, Alignment alignment, DataDisplayFlags displayFlags)
+ {
+ //int indentSize = (displayFlags.dropBox) ? 0 : 10;
+ int indent = 16;
+ int xStart;
+ int len;
+ int w, h;
+ //int textOffset;
+ char string[MAX_FILENAME];
+
+ Bitmap icon;
+
+ if(!this)
+ return;
+
+ icon = fsb.fileIcons[type].bitmap;
+ //xStart = indent * indent + x + (icon ? (icon.width + 5) : 0);
+ xStart = x + (icon ? (icon.width + 5) : 0);
+
+ if(!name)
+ return;
+
+ if(info)
+ sprintf(string, "%s [%s]", label ? label : name, info);
+ else
+ strcpy(string, label ? label : name);
+ len = strlen(string);
+
+ if(!icon)
+ {
+ if(type == folder || type == folderOpen)
+ surface.SetForeground(yellow);
+ //indentSize = 8;
+ indent = 8;
+ }
+ //textOffset = indent * indentSize + (icon ? (icon.width + 4) : 0);
+
+ surface.TextOpacity(false);
+ surface.TextExtent(string, len, &w, &h);
+ h = Max(h, 16);
+
+ // Draw the current row stipple
+ if(displayFlags.selected)
+ //surface.Area(xStart - 1, y, xStart - 1, y + h - 1);
+ //surface.Area(xStart + w - 1, y, xStart + w + 1, y + h - 1);
+ surface.Area(xStart - 3, y, xStart + w + 1, y + h - 1);
+
+ //surface.WriteTextDots(alignment, x + textOffset, y + 2, width - textOffset, name, strlen(name));
+ surface.WriteTextDots(alignment, xStart, y + 2, width, string, len);
+
+ if(!guiApp.textMode)