From 34abe19ad2877ca470c75cbad2e9189ba346d54f Mon Sep 17 00:00:00 2001 From: graemeg Date: Fri, 11 Jul 2008 13:42:39 +0000 Subject: * Removed many compiler warnings from the gfx_imgfmt_bmp unit. * Minor fix in the ImageList class. * Minor fixes in the Tree and TreeNode classes. * GUI Test Runner: Added image support in the test treeview. * Started a project for unit testing fpGUI components - starting with the treeview. --- src/corelib/fpgfx.pas | 2 +- src/corelib/gfx_imagelist.pas | 46 ++++++++++++++++++++---------------------- src/corelib/gfx_imgfmt_bmp.pas | 17 +++++++--------- src/corelib/x11/gfx_x11.pas | 1 + src/gui/gui_tree.pas | 36 ++++++++++++++++++++++++--------- 5 files changed, 57 insertions(+), 45 deletions(-) (limited to 'src') diff --git a/src/corelib/fpgfx.pas b/src/corelib/fpgfx.pas index 59054a59..ddbee4d5 100644 --- a/src/corelib/fpgfx.pas +++ b/src/corelib/fpgfx.pas @@ -1736,7 +1736,7 @@ var i: integer; img: TfpgImage; begin - for i := FImages.Count-1 downto 0 do + for i := FImages.Count-1 downto 0 do begin img := TfpgImage(FImages.Objects[i]); FImages.Delete(i); diff --git a/src/corelib/gfx_imagelist.pas b/src/corelib/gfx_imagelist.pas index 044f951e..123cb09a 100644 --- a/src/corelib/gfx_imagelist.pas +++ b/src/corelib/gfx_imagelist.pas @@ -28,6 +28,7 @@ interface uses Classes, SysUtils, + gfxbase, fpgfx; type @@ -48,12 +49,12 @@ type public constructor Create; overload; constructor Create(AImageList: TfpgImageList; AIndex: integer; AImage: TfpgImage); overload; - constructor Create(AFileName: string; AIndex: integer); overload; + constructor Create(AFileName: TfpgString; AIndex: integer); overload; destructor Destroy; override; property Index: integer read FIndex write SetIndex; property Image: TfpgImage read FImage write SetImage; property ImageList: TfpgImageList read FImageList write SetImageList; - procedure LoadFromFile(AFileName: String); + procedure LoadFromFile(AFileName: TfpgString); end; @@ -66,7 +67,7 @@ type public constructor Create; destructor Destroy; override; - procedure AddItemFromFile(AFileName: String; AIndex: integer = -1); + procedure AddItemFromFile(AFileName: TfpgString; AIndex: integer = -1); procedure AddImage(AImage: TfpgImage; AIndex: integer = -1); procedure RemoveIndex(AIndex: integer); function GetMaxItem: integer; @@ -78,22 +79,23 @@ type implementation uses - gfx_imgfmt_bmp; + gfx_imgfmt_bmp, + gfx_utils; { TfpgImageList } function TfpgImageList.GetFListIndex(AIndex: Integer): Integer; var - ACounter: integer; + i: integer; begin {$IFDEF DEBUG} writeln('TfpgImageList.GetFListIndex'); {$ENDIF} result := -1; - for ACounter := 0 to FList.Count - 1 do - if TfpgImageItem(FList[ACounter]).Index = AIndex then + for i := 0 to FList.Count - 1 do + if TfpgImageItem(FList[i]).Index = AIndex then begin - result := ACounter; + result := i; Break; //==> end; end; @@ -133,13 +135,13 @@ destructor TfpgImageList.Destroy; var i: integer; begin - for i := 0 to FList.Count - 1 do + for i := FList.Count-1 downto 0 do TfpgImageItem(FList[i]).Destroy; // frees images FList.Destroy; inherited Destroy end; -procedure TfpgImageList.AddItemFromFile(AFileName: String; AIndex: integer); +procedure TfpgImageList.AddItemFromFile(AFileName: TfpgString; AIndex: integer); var AImageItem: TfpgImageItem; begin @@ -147,8 +149,8 @@ begin writeln('TfpgImageList.AddItemFromFile'); {$ENDIF} - if not FileExists(AFileName) then - Exit; + if not fpgFileExists(AFileName) then + Exit; //==> AImageItem := TfpgImageItem.Create; AImageItem.LoadFromFile(AFileName); @@ -191,12 +193,12 @@ end; function TfpgImageList.GetMaxItem: integer; var - ACounter: integer; + i: integer; begin result := -1; - for ACounter := 0 to FList.Count - 1 do - if TfpgImageItem(FList[ACounter]).Index > result then - result := TfpgImageItem(FList[ACounter]).Index; + for i := 0 to FList.Count - 1 do + if TfpgImageItem(FList[i]).Index > result then + result := TfpgImageItem(FList[i]).Index; end; { TfpgImageItem } @@ -234,17 +236,13 @@ begin {$IFDEF DEBUG} writeln('TfpgImageItem.SetImage'); {$ENDIF} - if AImage <> FImage then - begin - FImage := AImage; - FImage.CreateMaskFromSample(0,0); - end; + FImage := AImage; end; constructor TfpgImageItem.Create; begin ImageList := nil; - FIndex := 0; + FIndex := -1; FImage := nil; end; @@ -259,7 +257,7 @@ begin ImageList := AImageList; end; -constructor TfpgImageItem.Create(AFileName: string; AIndex: integer); +constructor TfpgImageItem.Create(AFileName: TfpgString; AIndex: integer); begin {$IFDEF DEBUG} writeln('TfpgImageItem.Create(', AFileName, ',', AIndex, ')'); @@ -275,7 +273,7 @@ begin inherited Destroy; end; -procedure TfpgImageItem.LoadFromFile(AFileName: String); +procedure TfpgImageItem.LoadFromFile(AFileName: TfpgString); begin {$IFDEF DEBUG} writeln('TfpgImageItem.LoadFromFile'); diff --git a/src/corelib/gfx_imgfmt_bmp.pas b/src/corelib/gfx_imgfmt_bmp.pas index 54d4bfd3..46e5f0a8 100644 --- a/src/corelib/gfx_imgfmt_bmp.pas +++ b/src/corelib/gfx_imgfmt_bmp.pas @@ -15,7 +15,7 @@ uses gfxbase{, fpcanvas}; procedure ReadImage_BMP(img: TfpgImage; bmp: Pointer; bmpsize: longword); -function LoadImage_BMP(const AFileName: string): TfpgImage; +function LoadImage_BMP(const AFileName: String): TfpgImage; function CreateImage_BMP(bmp: Pointer; bmpsize: longword): TfpgImage; implementation @@ -26,11 +26,11 @@ begin ReadImage_BMP(Result, bmp, bmpsize); end; -function LoadImage_BMP(const AFileName: string): TfpgImage; +function LoadImage_BMP(const AFileName: String): TfpgImage; var AFile: file of char; AImageData: Pointer; - AImageDataSize: longint; + AImageDataSize: integer; begin Result := nil; if not FileExists(AFileName) then @@ -40,6 +40,7 @@ begin FileMode := fmOpenRead; // read-only Reset(AFile); AImageDataSize := FileSize(AFile); + AImageData := nil; GetMem(AImageData, AImageDataSize); try BlockRead(AFile, AImageData^, AImageDataSize); @@ -92,10 +93,6 @@ type // Every line padded to 32 bits // The lines stored bottom-up -type - PByte = ^byte; - Pword = ^word; - Plongword = ^longword; procedure ReadImage_BMP(img: TfpgImage; bmp: Pointer; bmpsize: longword); var @@ -109,8 +106,8 @@ var b: byte; bit: byte; bcnt: byte; - linecnt: longword; - pixelcnt: longword; + linecnt: integer; + pixelcnt: integer; pdest: Plongword; depth: integer; @@ -168,7 +165,7 @@ begin pcol := ppal; pixelcnt := 0; - while integer(p) < integer(pdata) do + while (p) < (pdata) do begin pcol^ := Plongword(p)^; //Writeln('color: ',HexStr(pcol^,8)); diff --git a/src/corelib/x11/gfx_x11.pas b/src/corelib/x11/gfx_x11.pas index 1b5209c0..d485762c 100644 --- a/src/corelib/x11/gfx_x11.pas +++ b/src/corelib/x11/gfx_x11.pas @@ -650,6 +650,7 @@ function TfpgApplicationImpl.StartComposing(const Event: TXEvent): TKeySym; var l: integer; begin + // Xutf8LookupString returns the size of FComposeBuffer in bytes. l := Xutf8LookupString(InputContext, @Event.xkey, @FComposeBuffer[1], SizeOf(FComposeBuffer) - 1, @Result, @FComposeStatus); SetLength(FComposeBuffer, l); diff --git a/src/gui/gui_tree.pas b/src/gui/gui_tree.pas index db6e9e33..e308d77f 100644 --- a/src/gui/gui_tree.pas +++ b/src/gui/gui_tree.pas @@ -41,7 +41,8 @@ uses gfxbase, fpgfx, gfx_imagelist, - gui_scrollbar; + gui_scrollbar, + gui_menu; type @@ -169,9 +170,11 @@ type function GetNodeHeightSum: integer; function MaxNodeWidth: integer; function GetNodeHeight: integer; - function GetNodeWidth(ANode: TfpgTreeNode): integer; // width of a node inclusive image + // width of a node inclusive image + function GetNodeWidth(ANode: TfpgTreeNode): integer; function NodeIsVisible(ANode: TfpgTreeNode): boolean; - function GetAbsoluteNodeTop(ANode: TfpgTreeNode): integer; // returns the node-top in pixels + // returns the node-top in pixels + function GetAbsoluteNodeTop(ANode: TfpgTreeNode): integer; function GetColumnLeft(AIndex: integer): integer; procedure PreCalcColumnLeft; procedure VScrollbarScroll(Sender: TObject; position: integer); @@ -182,9 +185,11 @@ type procedure FreeAllTreeNodes; protected FColumnLeft: TList; + FPopupMenu: TfpgPopupMenu; procedure HandleResize(awidth, aheight: TfpgCoord); override; procedure HandleLMouseUp(x, y: integer; shiftstate: TShiftState); override; procedure HandleLMouseDown(x, y: integer; shiftstate: TShiftState); override; + procedure HandleRMouseDown(x, y: integer; shiftstate: TShiftState); override; procedure HandleDoubleClick(x, y: integer; button: word; shiftstate: TShiftState); override; procedure HandleKeyPress(var keycode: word; var shiftstate: TShiftState; var consumed: boolean); override; procedure HandleMouseScroll(x, y: integer; shiftstate: TShiftState; delta: smallint); override; @@ -195,17 +200,21 @@ type procedure DoExpand(ANode: TfpgTreeNode); virtual; function NextVisualNode(ANode: TfpgTreeNode): TfpgTreeNode; function PrevVisualNode(ANode: TfpgTreeNode): TfpgTreeNode; - function SpaceToVisibleNext(aNode: TfpgTreeNode): integer; // the nodes between the given node and the direct next node + // the nodes between the given node and the direct next node + function SpaceToVisibleNext(aNode: TfpgTreeNode): integer; function StepToRoot(aNode: TfpgTreeNode): integer; public constructor Create(AOwner: TComponent); override; destructor Destroy; override; procedure SetColumnWidth(AIndex, AWidth: word); - function GetColumnWidth(AIndex: word): word; // the width of a column - aIndex of the rootnode = 0 + // the width of a column - aIndex of the rootnode = 0 + function GetColumnWidth(AIndex: word): word; property Font: TfpgFont read FFont; + // Invisible node that starts the tree property RootNode: TfpgTreeNode read GetRootNode; property Selection: TfpgTreeNode read FSelection write SetSelection; property ImageList: TfpgImageList read FImageList write FImageList; + property PopupMenu: TfpgPopupMenu read FPopupMenu write FPopupMenu; published property DefaultColumnWidth: word read FDefaultColumnWidth write SetDefaultColumnWidth default 15; property FontDesc: string read GetFontDesc write SetFontDesc; @@ -393,6 +402,7 @@ begin h := FirstSubNode; while h <> nil do begin +// writeln('h.Text = ', h.Text); if h.Text = AText then begin result := h; @@ -529,8 +539,8 @@ begin i := 0; while h <> nil do begin - h := h.next; inc(i); + h := h.next; end; result := i; end; @@ -544,9 +554,9 @@ begin i := 0; while h <> nil do begin + inc(i); // current node i := i + h.CountRecursive; // increases i by the count of the subnodes of the subnode h := h.next; - inc(i); // and the subnode... end; result := i; end; @@ -1201,6 +1211,13 @@ begin RePaint; end; +procedure TfpgTreeView.HandleRMouseDown(x, y: integer; shiftstate: TShiftState); +begin + inherited HandleRMouseDown(x, y, shiftstate); + if Assigned(PopupMenu) then + PopupMenu.ShowAt(self, x, y); +end; + procedure TfpgTreeview.HandleDoubleClick(x, y: integer; button: word; shiftstate: TShiftState); begin @@ -1762,11 +1779,10 @@ end; destructor TfpgTreeView.Destroy; begin - ClearColumnLeft; + if Assigned(FColumnLeft) then + ClearColumnLeft; FFont.Free; - FreeAllTreeNodes; - inherited Destroy; end; -- cgit v1.2.3-70-g09d2