summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2008-07-11 13:42:39 +0000
committergraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2008-07-11 13:42:39 +0000
commit34abe19ad2877ca470c75cbad2e9189ba346d54f (patch)
treedc0a3a787ef1f1e6931026f93d918531dcca9868 /src
parent3920a40d796da321010cc456fc864e552b97e398 (diff)
downloadfpGUI-34abe19ad2877ca470c75cbad2e9189ba346d54f.tar.xz
* 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.
Diffstat (limited to 'src')
-rw-r--r--src/corelib/fpgfx.pas2
-rw-r--r--src/corelib/gfx_imagelist.pas46
-rw-r--r--src/corelib/gfx_imgfmt_bmp.pas17
-rw-r--r--src/corelib/x11/gfx_x11.pas1
-rw-r--r--src/gui/gui_tree.pas36
5 files changed, 57 insertions, 45 deletions
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;