summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorgraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2007-08-16 14:22:17 +0000
committergraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2007-08-16 14:22:17 +0000
commit3dd56613512accb42a9cb8a986bad0e8f2635eae (patch)
treec12b50c0f6783053355b098ad9893b7db8bbe6b3 /src/gui
parentba207d0e5ca65ab32a5435143aaa24d57f19d89a (diff)
downloadfpGUI-3dd56613512accb42a9cb8a986bad0e8f2635eae.tar.xz
* Added images, Owner, Group and file attribute support to TfpgFileGrid.
I still need to try and get rid of the IFDEF's. * New executable image added to standard images. * IsSymLink help function added to gfx_utils unit. * Extended the FileGrid example project a bit more.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/gui_grid.pas103
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;