diff options
Diffstat (limited to 'src/gui/gui_grid.pas')
-rw-r--r-- | src/gui/gui_grid.pas | 103 |
1 files changed, 67 insertions, 36 deletions
diff --git a/src/gui/gui_grid.pas b/src/gui/gui_grid.pas index 24427483..f69bd964 100644 --- a/src/gui/gui_grid.pas +++ b/src/gui/gui_grid.pas @@ -99,6 +99,7 @@ type function CurrentEntry: TFileEntry; property FixedFont: TfpgFont read FFixedFont; property FileList: TFileList read FFileList; + property DefaultRowHeight; end; @@ -110,6 +111,10 @@ uses {$IFDEF MSWINDOWS} ,Windows // Graeme: temporary, just to see how the grid looks under Windows. {$ENDIF} + {$IFDEF UNIX} + ,libc // Graeme: temporary, just to see how the grid looks under Windows. + ,baseunix + {$ENDIF} ; @@ -183,6 +188,28 @@ begin until result or (cpat = ''); end; +{$IFDEF UNIX} +function GetGroupName(gid: integer): string; +var + p: PGroup; +begin + p := getgrgid(gid); + if p <> nil then + result := p^.gr_name; +end; + +function GetUserName(uid: integer): string; +var + p: PPasswd; +begin + p := getpwuid(uid); + if p <> nil then + result := p^.pw_name + else + result := ''; +end; +{$ENDIF} + { TFileEntry } @@ -237,34 +264,31 @@ function TFileList.ReadDirectory(const AFilemask: string; AShowHidden: boolean): var e: TFileEntry; fullname: string; + {$IFDEF UNIX} + info: Tstat; + {$ENDIF} begin -// if HasAttrib(sr.Attr, faDirectory) or (sr.Name = '.') or (sr.Name = '..') then -// Exit; //==> - e := TFileEntry.Create; - e.Name := sr.Name; - e.Extention := ExtractFileExt(e.Name); - e.Size := sr.Size; - e.Attributes := sr.Attr; // this is incorrect and needs to improve! - e.EntryType := etFile; + e.Name := sr.Name; + e.Extention := ExtractFileExt(e.Name); + e.Size := sr.Size; + e.Attributes := sr.Attr; // this is incorrect and needs to improve! + e.EntryType := etFile; + fullname := FDirectoryName + e.Name; {$IFDEF UNIX} - e.mode := sr.Mode; + e.mode := sr.Mode; + Fpstat(PChar(fullname), info); + e.GroupID := info.st_gid; + e.OwnerID := info.st_uid; {$ENDIF} - e.IsLink := HasAttrib(sr.Attr, faSymLink); - fullname := FDirectoryName + e.Name; - e.LinkTarget := ExtractTargetSymLinkPath(fullname); - e.ModTime := FileDateToDateTime(sr.Time); + e.IsLink := FileIsSymlink(fullname); + e.LinkTarget := ExtractTargetSymLinkPath(fullname); + e.ModTime := FileDateToDateTime(sr.Time); if HasAttrib(sr.Attr, faDirectory) then e.EntryType := etDir else e.EntryType := etFile; -{ - if (e.mode and $F000) = $4000 then - e.etype := etDir - else - e.etype := etFile; -} if (e.Name = '.') or ((e.Name = '..') and (FDirectoryName = '/')) or @@ -375,7 +399,7 @@ end; procedure TfpgFileGrid.DrawCell(ARow, ACol: integer; ARect: TfpgRect; AFlags: integer); const - modestring: string[9] = 'rwxrwxrwx'; + modestring: string[9] = 'xwrxwrxwr'; // must be in reverse order var e: TFileEntry; x: integer; @@ -390,7 +414,7 @@ begin Exit; //==> x := ARect.Left + 2; - y := ARect.Top + 1; + y := ARect.Top;// + 1; s := ''; if (e.EntryType = etDir) and (ACol = 1) then @@ -401,26 +425,30 @@ begin case ACol of 1: begin if e.EntryType = etDir then - fpgImages.GetImage('stdimg.folder') + img := fpgImages.GetImage('stdimg.folder') else begin img := fpgImages.GetImage('stdimg.document'); {$IFDEF UNIX} - if (e.Mode and $40) <> 0 then - img := fpgImages.GetImage('stdimg.yes'); // executable + if (e.Mode and $40) <> 0 then + img := fpgImages.GetImage('stdimg.executable'); {$ENDIF} + {$IFDEF MSWINDOWS} + if lowercase(e.Extention) = 'exe' then + img := fpgImages.GetImage('stdimg.executable'); + {$ENDIF} end; -// if img <> nil then -// Canvas.DrawImage(ARect.Left+1, y, img); -// if e.IsLink then -// Canvas.DrawImage(ARect.Left+1, y, fpgImages.GetImage('stdimg.link')); + if img <> nil then + Canvas.DrawImage(ARect.Left+1, y, img); + if e.IsLink then + Canvas.DrawImage(ARect.Left+1, y, fpgImages.GetImage('stdimg.link')); x := ARect.Left + 20; s := e.Name; end; 2: begin - s := FormatFloat('###,###,###,##0',e.size); + s := FormatFloat('###,###,###,##0', e.size); x := ARect.Right - Font.TextWidth(s) - 1; if x < (ARect.Left + 2) then x := ARect.Left + 2; @@ -447,10 +475,10 @@ begin s := ''; while n <= 9 do begin - if (e.mode and b) = 0 then - s := '-'+s + if (e.Mode and b) = 0 then + s := '-' + s else - s := modestring[n]+s; + s := modestring[n] + s; inc(n); b := b shl 1; end; @@ -460,14 +488,16 @@ begin end; {$IFDEF UNIX} -// 5: s := GetUserName(e.ownerid); // use getpwuid(); for the name of this user + 5: s := GetUserName(e.ownerid); // use getpwuid(); for the name of this user {$ENDIF} {$IFDEF UNIX} -// 6: s := GetGroupName(e.groupid); // use getgrgid(); for the name of this group + 6: s := GetGroupName(e.groupid); // use getgrgid(); for the name of this group {$ENDIF} end; - canvas.DrawString(x, y, s); + // centre text in row height + y := y + ((DefaultRowHeight - Canvas.Font.Height) div 2); + Canvas.DrawString(x, y, s); end; constructor TfpgFileGrid.Create(AOwner: TComponent); @@ -475,7 +505,7 @@ begin FFileList := TFileList.Create; inherited Create(AOwner); ColumnCount := 0; - FFixedFont := fpgGetFont('Courier New-9:antialias=true'); + FFixedFont := fpgGetFont('Courier New-9'); {$Note Abstract this! No IFDEF's allowed!!! } {$ifdef MSWINDOWS} @@ -495,6 +525,7 @@ begin {$endif} RowSelect := True; + DefaultRowHeight := fpgImages.GetImage('stdimg.document').Height + 2; end; destructor TfpgFileGrid.Destroy; |