diff options
author | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-08-16 14:22:17 +0000 |
---|---|---|
committer | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-08-16 14:22:17 +0000 |
commit | 3dd56613512accb42a9cb8a986bad0e8f2635eae (patch) | |
tree | c12b50c0f6783053355b098ad9893b7db8bbe6b3 | |
parent | ba207d0e5ca65ab32a5435143aaa24d57f19d89a (diff) | |
download | fpGUI-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.
-rw-r--r-- | examples/corelib/canvastest/fpgcanvas.lpi | 7 | ||||
-rw-r--r-- | examples/corelib/eventtest/eventtest.lpi | 8 | ||||
-rw-r--r-- | examples/gui/filegrid/filegrid.lpi | 7 | ||||
-rw-r--r-- | examples/gui/filegrid/filegrid.lpr | 32 | ||||
-rw-r--r-- | images/executable_16.bmp | bin | 0 -> 822 bytes | |||
-rw-r--r-- | src/corelib/gdi/fpgfx_package.lpk | 2 | ||||
-rw-r--r-- | src/corelib/gdi/gfx_utils.pas | 5 | ||||
-rw-r--r-- | src/corelib/gfx_stdimages.pas | 6 | ||||
-rw-r--r-- | src/corelib/gfx_utils_intf.inc | 1 | ||||
-rw-r--r-- | src/corelib/stdimages.inc | 52 | ||||
-rw-r--r-- | src/corelib/x11/fpgfx_package.lpk | 2 | ||||
-rw-r--r-- | src/corelib/x11/gfx_utils.pas | 6 | ||||
-rw-r--r-- | src/gui/gui_grid.pas | 103 |
13 files changed, 178 insertions, 53 deletions
diff --git a/examples/corelib/canvastest/fpgcanvas.lpi b/examples/corelib/canvastest/fpgcanvas.lpi index 7f1c6c21..71f908fb 100644 --- a/examples/corelib/canvastest/fpgcanvas.lpi +++ b/examples/corelib/canvastest/fpgcanvas.lpi @@ -1,7 +1,7 @@ <?xml version="1.0"?> <CONFIG> <ProjectOptions> - <PathDelim Value="\"/> + <PathDelim Value="/"/> <Version Value="5"/> <General> <Flags> @@ -9,7 +9,7 @@ </Flags> <SessionStorage Value="InProjectDir"/> <MainUnit Value="0"/> - <IconPath Value=".\"/> + <IconPath Value="./"/> <TargetFileExt Value=""/> <Title Value="fpcanvas"/> </General> @@ -24,7 +24,7 @@ <RunParams> <local> <FormatVersion Value="1"/> - <LaunchingApplication PathPlusParams="\usr\X11R6\bin\xterm -T 'Lazarus Run Output' -e $(LazarusDir)\tools\runwait.sh $(TargetCmdLine)"/> + <LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/> </local> </RunParams> <RequiredPackages Count="1"> @@ -43,7 +43,6 @@ </ProjectOptions> <CompilerOptions> <Version Value="5"/> - <PathDelim Value="\"/> <CodeGeneration> <Generate Value="Faster"/> </CodeGeneration> diff --git a/examples/corelib/eventtest/eventtest.lpi b/examples/corelib/eventtest/eventtest.lpi index 644a35ab..2565f331 100644 --- a/examples/corelib/eventtest/eventtest.lpi +++ b/examples/corelib/eventtest/eventtest.lpi @@ -1,7 +1,7 @@ <?xml version="1.0"?> <CONFIG> <ProjectOptions> - <PathDelim Value="\"/> + <PathDelim Value="/"/> <Version Value="5"/> <General> <Flags> @@ -9,7 +9,7 @@ </Flags> <SessionStorage Value="InProjectDir"/> <MainUnit Value="0"/> - <IconPath Value=".\"/> + <IconPath Value="./"/> <TargetFileExt Value=""/> </General> <VersionInfo> @@ -17,14 +17,13 @@ </VersionInfo> <PublishOptions> <Version Value="2"/> - <DestinationDirectory Value="$(TestDir)\publishedproject\"/> <IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/> <ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/> </PublishOptions> <RunParams> <local> <FormatVersion Value="1"/> - <LaunchingApplication PathPlusParams="\usr\X11R6\bin\xterm -T 'Lazarus Run Output' -e $(LazarusDir)\tools\runwait.sh $(TargetCmdLine)"/> + <LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/> </local> </RunParams> <RequiredPackages Count="1"> @@ -43,7 +42,6 @@ </ProjectOptions> <CompilerOptions> <Version Value="5"/> - <PathDelim Value="\"/> <CodeGeneration> <Optimizations> <OptimizationLevel Value="0"/> diff --git a/examples/gui/filegrid/filegrid.lpi b/examples/gui/filegrid/filegrid.lpi index a2420bb4..c02230ec 100644 --- a/examples/gui/filegrid/filegrid.lpi +++ b/examples/gui/filegrid/filegrid.lpi @@ -1,7 +1,7 @@ <?xml version="1.0"?> <CONFIG> <ProjectOptions> - <PathDelim Value="\"/> + <PathDelim Value="/"/> <Version Value="5"/> <General> <Flags> @@ -9,7 +9,7 @@ </Flags> <SessionStorage Value="InProjectDir"/> <MainUnit Value="0"/> - <IconPath Value=".\"/> + <IconPath Value="./"/> <TargetFileExt Value=""/> </General> <VersionInfo> @@ -23,7 +23,7 @@ <RunParams> <local> <FormatVersion Value="1"/> - <LaunchingApplication PathPlusParams="\usr\X11R6\bin\xterm -T 'Lazarus Run Output' -e $(LazarusDir)\tools\runwait.sh $(TargetCmdLine)"/> + <LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/> </local> </RunParams> <RequiredPackages Count="1"> @@ -42,7 +42,6 @@ </ProjectOptions> <CompilerOptions> <Version Value="5"/> - <PathDelim Value="\"/> <CodeGeneration> <Generate Value="Faster"/> </CodeGeneration> diff --git a/examples/gui/filegrid/filegrid.lpr b/examples/gui/filegrid/filegrid.lpr index 1f8fda95..cd8f68ea 100644 --- a/examples/gui/filegrid/filegrid.lpr +++ b/examples/gui/filegrid/filegrid.lpr @@ -8,19 +8,37 @@ uses {$ENDIF}{$ENDIF} Classes, fpgfx, + gfxbase, gui_form, - gui_grid; + gui_grid, + gui_checkbox, + gui_button; type TMainForm = class(TfpgForm) private FGrid: TfpgFileGrid; + chkShowHidden: TfpgCheckBox; + btnQuit: TfpgButton; + procedure chkShowHiddenChanged(Sender: TObject); + procedure btnQuitClicked(Sender: TObject); public constructor Create(AOwner: TComponent); override; end; { TMainForm } +procedure TMainForm.chkShowHiddenChanged(Sender: TObject); +begin + FGrid.FileList.ReadDirectory('*', chkShowHidden.Checked); + fpgSendMessage(self, FGrid, FPGM_PAINT); +end; + +procedure TMainForm.btnQuitClicked(Sender: TObject); +begin + Close; +end; + constructor TMainForm.Create(AOwner: TComponent); begin inherited Create(AOwner); @@ -28,9 +46,19 @@ begin SetPosition(100, 100, 620, 400); FGrid := TfpgFileGrid.Create(self); - FGrid.SetPosition(8, 8, 600, 370); + FGrid.SetPosition(8, 8, 600, 360); FGrid.FileList.ReadDirectory('*', True); FGrid.Anchors := [anLeft, anTop, anBottom, anRight]; + + chkShowHidden := CreateCheckBox(self, 8, Height - 25, 'Show Hidden'); + chkShowHidden.Checked := True; + chkShowHidden.OnChange := @chkShowHiddenChanged; + chkShowHidden.Anchors := [anLeft, anBottom]; + + btnQuit := CreateButton(self, Width - 88, Height - 30, 80, 'Quit', @btnQuitClicked); + btnQuit.ImageName := 'stdimg.Quit'; + btnQuit.ShowImage := True; + btnQuit.Anchors := [anRight, anBottom]; end; diff --git a/images/executable_16.bmp b/images/executable_16.bmp Binary files differnew file mode 100644 index 00000000..70bf7a05 --- /dev/null +++ b/images/executable_16.bmp diff --git a/src/corelib/gdi/fpgfx_package.lpk b/src/corelib/gdi/fpgfx_package.lpk index 8182a71d..2e5190a7 100644 --- a/src/corelib/gdi/fpgfx_package.lpk +++ b/src/corelib/gdi/fpgfx_package.lpk @@ -8,7 +8,7 @@ <Version Value="5"/>
<PathDelim Value="\"/>
<SearchPaths>
- <IncludeFiles Value="..\..\"/>
+ <IncludeFiles Value="..\"/>
<OtherUnitFiles Value="..\;..\..\gui\"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
diff --git a/src/corelib/gdi/gfx_utils.pas b/src/corelib/gdi/gfx_utils.pas index 70078859..f5822fc6 100644 --- a/src/corelib/gdi/gfx_utils.pas +++ b/src/corelib/gdi/gfx_utils.pas @@ -38,6 +38,11 @@ begin } end; +function FileIsSymlink(const AFilename: string): boolean; +begin + Result := False; +end; + end. diff --git a/src/corelib/gfx_stdimages.pas b/src/corelib/gfx_stdimages.pas index 7ed9fdb4..85deb0db 100644 --- a/src/corelib/gfx_stdimages.pas +++ b/src/corelib/gfx_stdimages.pas @@ -267,6 +267,12 @@ begin @stdimg_list_remove_16, sizeof(stdimg_list_remove_16), 0,0 ); + + img := fpgImages.AddMaskedBMP( + 'stdimg.executable', + @stdimg_executable_16, + sizeof(stdimg_executable_16), + 0, 0); // Dialog icons diff --git a/src/corelib/gfx_utils_intf.inc b/src/corelib/gfx_utils_intf.inc index 2bd3c72f..a133d2a4 100644 --- a/src/corelib/gfx_utils_intf.inc +++ b/src/corelib/gfx_utils_intf.inc @@ -2,6 +2,7 @@ // File utils function ExtractTargetSymLinkPath(ALink: string): string; +function FileIsSymlink(const AFilename: string): boolean; diff --git a/src/corelib/stdimages.inc b/src/corelib/stdimages.inc index 1ba60088..5dfbf7d8 100644 --- a/src/corelib/stdimages.inc +++ b/src/corelib/stdimages.inc @@ -1376,6 +1376,58 @@ Const 0, 0,198, 0, 0, 0,238, 0, 0, 0); Const + stdimg_executable_16 : Array[0..821] of byte = ( + 66, 77, 54, 3, 0, 0, 0, 0, 0, 0, 54, 0, 0, 0, 40, 0, 0, + 0, 16, 0, 0, 0, 16, 0, 0, 0, 1, 0, 24, 0, 0, 0, 0, 0, + 0, 3, 0, 0,215, 13, 0, 0,215, 13, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0, + 255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, + 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255, + 255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0, + 255,255, 0,255,120, 72, 54,255, 0,255,255, 0,255,255, 0,255,255, + 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255, + 255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,120, 72, + 54,153,111, 86,120, 72, 54,255, 0,255,255, 0,255,255, 0,255,255, + 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255, + 255, 0,255,255, 0,255,255, 0,255,120, 72, 54,218,199,195,195,159, + 157,153,111, 86,120, 72, 54,255, 0,255,255, 0,255,255, 0,255,255, + 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255, + 255, 0,255,120, 72, 54,218,199,195,188,151,145,204,176,172,221,202, + 200,153,111, 86,120, 72, 54,255, 0,255,255, 0,255,255, 0,255,255, + 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,120, 72, 54, + 218,199,195,181,142,133,182,144,135,183,145,137,217,197,193,190,154, + 148,153,111, 86,120, 72, 54,255, 0,255,255, 0,255,255, 0,255,255, + 0,255,255, 0,255,255, 0,255,120, 72, 54,218,199,195,174,136,122, + 175,135,122,176,137,124,193,162,152,216,196,191,188,153,144,181,143, + 133,153,111, 86,120, 72, 54,255, 0,255,255, 0,255,255, 0,255,255, + 0,255,120, 72, 54,218,199,195,201,177,167,200,176,165,187,155,143, + 183,149,136,171,131,116,198,170,161,194,163,153,175,136,123,177,137, + 125,153,111, 86,120, 72, 54,255, 0,255,255, 0,255,120, 72, 54,218, + 199,195,207,185,175,207,186,176,208,187,177,209,187,178,202,178,167, + 187,156,142,205,181,171,209,188,179,173,134,119,171,130,115,172,132, + 117,153,111, 86,120, 72, 54,255, 0,255,255, 0,255,120, 72, 54,218, + 199,195,204,182,171,205,183,172,206,184,173,206,185,174,199,174,162, + 176,140,124,191,162,149,203,179,169,170,130,113,153,111, 86,120, 72, + 54,255, 0,255,255, 0,255,255, 0,255,255, 0,255,120, 72, 54,218, + 199,195,202,180,167,203,180,168,203,181,169,204,182,170,176,142,124, + 180,148,131,177,144,127,153,111, 86,120, 72, 54,255, 0,255,255, 0, + 255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,120, 72, 54,218, + 199,195,200,177,163,200,178,164,201,178,165,186,158,141,150,106, 81, + 153,111, 86,120, 72, 54,255, 0,255,255, 0,255,255, 0,255,255, 0, + 255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,120, 72, 54,218, + 199,195,198,174,159,198,175,160,186,159,141,144,100, 72,120, 72, 54, + 255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0, + 255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,120, 72, 54,218, + 199,195,195,171,155,159,122, 95,120, 72, 54,255, 0,255,255, 0,255, + 255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0, + 255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,120, 72, 54,218, + 199,195,120, 72, 54,255, 0,255,255, 0,255,255, 0,255,255, 0,255, + 255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0, + 255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,120, 72, 54,255, + 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255, + 255, 0,255,255, 0,255); + +Const stdimg_dialog_information_32 : Array[0..3125] of byte = ( 66, 77, 54, 12, 0, 0, 0, 0, 0, 0, 54, 0, 0, 0, 40, 0, 0, 0, 32, 0, 0, 0, 32, 0, 0, 0, 1, 0, 24, 0, 0, 0, 0, 0, diff --git a/src/corelib/x11/fpgfx_package.lpk b/src/corelib/x11/fpgfx_package.lpk index 82e20e85..009c6ca3 100644 --- a/src/corelib/x11/fpgfx_package.lpk +++ b/src/corelib/x11/fpgfx_package.lpk @@ -6,7 +6,7 @@ <CompilerOptions> <Version Value="5"/> <SearchPaths> - <IncludeFiles Value="../../"/> + <IncludeFiles Value="../"/> <OtherUnitFiles Value="../;../../gui/"/> <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/> </SearchPaths> diff --git a/src/corelib/x11/gfx_utils.pas b/src/corelib/x11/gfx_utils.pas index b0fa283d..39ef7d86 100644 --- a/src/corelib/x11/gfx_utils.pas +++ b/src/corelib/x11/gfx_utils.pas @@ -43,6 +43,12 @@ begin } end; +function FileIsSymlink(const AFilename: string): boolean; +begin + Result := (FpReadLink(AFilename) <> ''); +end; + + end. 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; |