mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-09 01:48:03 +02:00
added TlistView.SubItem improvements from Olivier Guilbaud
git-svn-id: trunk@3873 -
This commit is contained in:
parent
1b117827d1
commit
bb7c7166b1
@ -28,6 +28,11 @@
|
||||
01/28/2003 OG - Create
|
||||
18/02/2003 OG - First release
|
||||
19/02/2003 OG - Add ObjInspStrConsts unit
|
||||
24/02/2003 OG - Replace TListBox with TTreeView
|
||||
Include suItems property
|
||||
|
||||
ToDo :
|
||||
Select the first item on show editor ... dont work :o(
|
||||
}
|
||||
unit ListViewPropEdit;
|
||||
|
||||
@ -49,19 +54,22 @@ Type
|
||||
private
|
||||
edtLabel : TEdit;
|
||||
edtIndex : TEdit;
|
||||
LB : TListBox;
|
||||
LstIndex : TStringList;
|
||||
|
||||
TV : TTreeView;
|
||||
btnSub : TButton;
|
||||
fBuild : Boolean;
|
||||
|
||||
Procedure btnAddOnClick(Sender : TObject);
|
||||
Procedure btnDelOnClick(Sender : TObject);
|
||||
procedure btnAddSubOnClick(Sender : TObject);
|
||||
Procedure LBOnClick(Sender: TObject);
|
||||
procedure EdtLabelOnChange(Sender: TObject);
|
||||
procedure EdtIndexOnChange(Sender: TObject);
|
||||
|
||||
procedure OnDlgShow(Sender: TObject);
|
||||
procedure RefreshEdts;
|
||||
|
||||
public
|
||||
constructor Create(aOwner : TComponent); override;
|
||||
destructor Destroy; override;
|
||||
end;
|
||||
|
||||
TListViewComponentEditor = class(TDefaultComponentEditor)
|
||||
@ -134,12 +142,13 @@ end;
|
||||
{ TListViewComponentEditor }
|
||||
|
||||
procedure TListViewComponentEditor.DoShowEditor;
|
||||
Var Dlg : TListViewItemsPropertyEditorDlg;
|
||||
LV : TListView;
|
||||
C : TPersistent;
|
||||
i : Integer;
|
||||
Li : TListItem;
|
||||
Hook: TPropertyEditorHook;
|
||||
Var Dlg : TListViewItemsPropertyEditorDlg;
|
||||
LV : TListView;
|
||||
C : TPersistent;
|
||||
i,j : Integer;
|
||||
Li : TListItem;
|
||||
Hook : TPropertyEditorHook;
|
||||
TN,TN2 : TTreeNode;
|
||||
begin
|
||||
Dlg:=TListViewItemsPropertyEditorDlg.Create(Application);
|
||||
try
|
||||
@ -147,21 +156,24 @@ begin
|
||||
if C is TListView then LV:=TListView(C);
|
||||
if C is TListItems then LV:=TListView(TListItems(C).Owner);
|
||||
GetHook(Hook);
|
||||
|
||||
if Assigned(LV) then
|
||||
begin
|
||||
//Initialize the listbox items with ListView items
|
||||
for i:=0 to LV.Items.Count-1 do
|
||||
begin
|
||||
Dlg.fBuild:=True;
|
||||
Dlg.LB.Items.Add(LV.Items.Item[i].Caption);
|
||||
Dlg.LstIndex.Add(IntToStr(LV.Items[i].ImageIndex));
|
||||
end;
|
||||
if LV.Items.Count>0 then
|
||||
begin
|
||||
Dlg.LB.ItemIndex:=0;
|
||||
Dlg.LB.OnClick(nil);
|
||||
end;
|
||||
TN:=Dlg.TV.Items.add(nil,LV.Items.Item[i].Caption);
|
||||
TN.ImageIndex:=LV.Items[i].ImageIndex;
|
||||
|
||||
//sub items
|
||||
for j:=0 to LV.Items.Item[i].SubItems.Count-1 do
|
||||
begin
|
||||
TN2:=Dlg.TV.Items.AddChild(TN,LV.Items.Item[i].SubItems.Strings[j]);
|
||||
TN2.ImageIndex:=LV.Items.Item[i].SubItemImages[j];
|
||||
end;
|
||||
end;
|
||||
|
||||
//ShowEditor
|
||||
if (Dlg.ShowModal=mrOk) then
|
||||
begin
|
||||
@ -171,11 +183,23 @@ begin
|
||||
LV.Items.Clear;
|
||||
|
||||
//Recreate new items or modify
|
||||
for i:=0 to Dlg.LB.Items.Count-1 do
|
||||
for i:=0 to Dlg.TV.Items.Count-1 do
|
||||
begin
|
||||
Li:=LV.Items.Add;
|
||||
Li.Caption:=Dlg.LB.Items.Strings[i];
|
||||
Li.ImageIndex:=StrToInt(Dlg.LstIndex.Strings[i]);
|
||||
TN:=Dlg.TV.Items.Items[i];
|
||||
If not Assigned(TN.Parent) then
|
||||
begin
|
||||
Li:=LV.Items.Add;
|
||||
Li.Caption:=TN.Text;;
|
||||
Li.ImageIndex:=TN.ImageIndex;
|
||||
|
||||
//Sub items if exists
|
||||
for j:=0 to TN.Count-1 do
|
||||
begin
|
||||
TN2:=TN.Items[j];
|
||||
Li.SubItems.Add(TN2.Text);
|
||||
Li.SubItemImages[j]:=TN.ImageIndex;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
finally
|
||||
LV.EndUpdate;
|
||||
@ -212,8 +236,8 @@ constructor TListViewItemsPropertyEditorDlg.Create(aOwner: TComponent);
|
||||
Var Cmp : TWinControl;
|
||||
begin
|
||||
inherited Create(aOwner);
|
||||
OnShow:=@OnDlgShow;
|
||||
|
||||
LstIndex:=TStringList.Create;
|
||||
fBuild:=False;
|
||||
|
||||
//Sise of window
|
||||
@ -268,33 +292,52 @@ begin
|
||||
Parent :=Cmp;
|
||||
Left :=192;
|
||||
Width :=121;
|
||||
Top :=32;
|
||||
Top :=22;
|
||||
Caption:=sccsLvEdtBtnAdd;
|
||||
OnClick:=@btnAddOnClick;
|
||||
end;
|
||||
|
||||
btnSub:=TButton.Create(self);
|
||||
With btnSub do
|
||||
begin
|
||||
Parent :=Cmp;
|
||||
Enabled:=False;
|
||||
Left :=192;
|
||||
Width :=121;
|
||||
Top :=52;
|
||||
Caption:=sccsLvEdtBtnAddSub;
|
||||
OnClick:=@btnAddSubOnClick;
|
||||
end;
|
||||
|
||||
With TButton.Create(self) do
|
||||
begin
|
||||
Parent :=Cmp;
|
||||
Left :=192;
|
||||
Width :=121;
|
||||
Top :=72;
|
||||
Top :=82;
|
||||
Caption:=sccsLvEdtBtnDel;
|
||||
OnClick:=@btnDelOnClick;
|
||||
end;
|
||||
|
||||
LB:=TListBox.Create(self);
|
||||
With LB do
|
||||
TV:=TTreeView.Create(self);
|
||||
With TV do
|
||||
begin
|
||||
Parent :=Cmp;
|
||||
Top :=3;
|
||||
Width :=164;
|
||||
Left :=5;
|
||||
Height :=190;
|
||||
ExtendedSelect:=True;
|
||||
|
||||
//Options of TV
|
||||
RightClickSelect:=True;
|
||||
ReadOnly:=True;
|
||||
ShowButtons:=False;
|
||||
AutoExpand:=True;
|
||||
HideSelection:=False;
|
||||
|
||||
OnClick :=@LBOnClick;
|
||||
end;
|
||||
|
||||
|
||||
//Right group box
|
||||
Cmp:=TGroupBox.Create(self);
|
||||
With TgroupBox(Cmp) do
|
||||
@ -349,23 +392,45 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
destructor TListViewItemsPropertyEditorDlg.Destroy;
|
||||
//Initialze the TEdit with selected node
|
||||
procedure TListViewItemsPropertyEditorDlg.RefreshEdts;
|
||||
Var TN : TTreeNode;
|
||||
begin
|
||||
LstIndex.Free;
|
||||
inherited Destroy;
|
||||
TN:=TV.Selected;
|
||||
fbuild:=True;
|
||||
try
|
||||
if Assigned(TN) then
|
||||
begin
|
||||
edtLabel.Text:=TN.Text;
|
||||
edtIndex.Text:=IntToStr(TN.ImageIndex);
|
||||
edtLabel.Enabled:=True;
|
||||
edtIndex.Enabled:=True;
|
||||
btnSub.Enabled :=True;
|
||||
end
|
||||
else
|
||||
begin
|
||||
EdtLabel.Text:='';
|
||||
EdtIndex.Text:='';
|
||||
btnSub.Enabled:=False;
|
||||
edtLabel.Enabled:=False;
|
||||
edtIndex.Enabled:=False;
|
||||
end;
|
||||
finally
|
||||
fbuild:=false;
|
||||
end;
|
||||
end;
|
||||
|
||||
//Créate new item
|
||||
procedure TListViewItemsPropertyEditorDlg.btnAddOnClick(Sender: TObject);
|
||||
Var TN : TTreeNode;
|
||||
begin
|
||||
fBuild:=True;
|
||||
try
|
||||
LB.Items.Add(sccsLvEdtBtnAdd);
|
||||
LstIndex.Add('-1');
|
||||
LB.ItemIndex:=LB.Items.Count-1;
|
||||
TN:=TV.Items.Add(nil,sccsLvEdtBtnAdd);
|
||||
TN.ImageIndex:=-1;
|
||||
TV.Selected:=TN;
|
||||
|
||||
edtLabel.Text:=LB.Items.Strings[LB.ItemIndex];
|
||||
edtIndex.Text:=LstIndex.Strings[LB.ItemIndex];
|
||||
RefreshEdts;
|
||||
finally
|
||||
fbuild:=False;
|
||||
end;
|
||||
@ -380,32 +445,41 @@ end;
|
||||
|
||||
//Delete the selected item
|
||||
procedure TListViewItemsPropertyEditorDlg.btnDelOnClick(Sender: TObject);
|
||||
Var i : Integer;
|
||||
Var TN,TN2 : TTreeNode;
|
||||
begin
|
||||
If LB.ItemIndex<>-1 then
|
||||
TN:=TV.Selected;
|
||||
If Assigned(TN) then
|
||||
begin
|
||||
i:=LB.ItemIndex;
|
||||
LB.Items.Delete(i);
|
||||
LstIndex.Delete(i);
|
||||
if LB.Items.Count=0 then
|
||||
i:=-1
|
||||
else
|
||||
begin
|
||||
If i>LB.Items.Count-1 then
|
||||
i:=LB.Items.Count-1;
|
||||
end;
|
||||
TN2:=TN.GetPrev;
|
||||
TN.Delete;
|
||||
TV.Selected:=TN2;
|
||||
|
||||
try
|
||||
if i=-1 then
|
||||
begin
|
||||
EdtLabel.Text:='';
|
||||
EdtIndex.Text:='';
|
||||
end;
|
||||
|
||||
LB.ItemIndex:=i;
|
||||
except
|
||||
end;
|
||||
LBOnClick(nil);
|
||||
RefreshEdts;
|
||||
end;
|
||||
end;
|
||||
|
||||
//Add an sub item
|
||||
procedure TListViewItemsPropertyEditorDlg.btnAddSubOnClick(Sender: TObject);
|
||||
Var TN,TN2 : TTreeNode;
|
||||
begin
|
||||
TN:=TV.Selected;
|
||||
If Assigned(TN) then
|
||||
begin
|
||||
If Assigned(TN.Parent) then
|
||||
TN:=TN.Parent;
|
||||
|
||||
TN2:=TV.Items.AddChild(TN,sccsLvEdtBtnAdd);
|
||||
TN2.ImageIndex:=-1;
|
||||
TV.Selected:=TN2;
|
||||
|
||||
RefreshEdts;
|
||||
end;
|
||||
|
||||
//Select the label editor
|
||||
if EdtLabel.CanFocus then
|
||||
begin
|
||||
EdtLabel.SetFocus;
|
||||
EdtLabel.SelectAll;
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -413,39 +487,43 @@ end;
|
||||
//Modify the TEdit for the Label and Image index
|
||||
procedure TListViewItemsPropertyEditorDlg.LBOnClick(Sender: TObject);
|
||||
begin
|
||||
If LB.ItemIndex<>-1 then
|
||||
begin
|
||||
fBuild:=True;
|
||||
try
|
||||
edtLabel.Text:=LB.Items.Strings[LB.ItemIndex];
|
||||
edtIndex.Text:=LstIndex.Strings[LB.ItemIndex];
|
||||
finally
|
||||
fBuild:=False;
|
||||
end;
|
||||
end;
|
||||
RefreshEdts;
|
||||
end;
|
||||
|
||||
//Refrsh the label list
|
||||
procedure TListViewItemsPropertyEditorDlg.EdtLabelOnChange(Sender: TObject);
|
||||
Var i : Integer;
|
||||
Var TN : TTreeNode;
|
||||
begin
|
||||
If (LB.ItemIndex<>-1) and not fBuild then
|
||||
begin
|
||||
i:=LB.ItemIndex;
|
||||
LB.Items.Strings[LB.ItemIndex]:=edtLabel.Text;
|
||||
LB.ItemIndex:=i;
|
||||
end;
|
||||
if fBuild then Exit;
|
||||
TN:=TV.Selected;
|
||||
if Assigned(TN) then
|
||||
TN.Text:=edtLabel.Text;
|
||||
end;
|
||||
|
||||
//Refresh the index list
|
||||
procedure TListViewItemsPropertyEditorDlg.EdtIndexOnChange(Sender: TObject);
|
||||
Var i,E : Integer;
|
||||
TN : TTreeNode;
|
||||
begin
|
||||
If (LB.ItemIndex<>-1) and not fBuild then
|
||||
if fBuild then Exit;
|
||||
TN:=TV.Selected;
|
||||
if Assigned(TN) then
|
||||
begin
|
||||
Val(edtIndex.Text,i,E);
|
||||
if E<>0 then i:=-1;
|
||||
LstIndex.Strings[LB.ItemIndex]:=IntToStr(i);
|
||||
TN.ImageIndex:=i;
|
||||
end;
|
||||
end;
|
||||
|
||||
//Initialize the dialog
|
||||
procedure TListViewItemsPropertyEditorDlg.OnDlgShow(Sender: TObject);
|
||||
Var TN : TTReeNode;
|
||||
begin
|
||||
TN:=TV.TopItem;
|
||||
If Assigned(TN) then
|
||||
begin
|
||||
TV.Selected:=TN;
|
||||
RefreshEdts;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -36,7 +36,8 @@ resourcestring
|
||||
sccsLvEdtImgIndexCaption= 'Image index';
|
||||
sccsLvEdtBtnAdd = 'New';
|
||||
sccsLvEdtBtnDel = 'Delete';
|
||||
|
||||
sccsLvEdtBtnAddSub = 'Sub item';
|
||||
|
||||
implementation
|
||||
|
||||
end.
|
||||
|
@ -161,6 +161,8 @@ type
|
||||
procedure SetCaption(const AValue : String);
|
||||
// Procedure SetSubItems(Value : TStrings);
|
||||
function GetIndex : Integer;
|
||||
function GetSubItemImages(aIndex: Integer): Integer;
|
||||
procedure SetSubItemImages(aIndex: Integer; const AValue: Integer);
|
||||
protected
|
||||
Procedure ItemChanged(sender : TObject); //called by the onchange of the tstringlist in TListItem
|
||||
function IsEqual(Item : TListItem) : Boolean;
|
||||
@ -168,16 +170,19 @@ type
|
||||
constructor Create(AOwner : TListItems);
|
||||
destructor Destroy; override;
|
||||
procedure Delete;
|
||||
public
|
||||
property Caption : String read FCaption write SetCaption;
|
||||
property Cut: Boolean index 0 read GetState write SetState;
|
||||
property Data: Pointer read FData write SetData;
|
||||
property DropTarget: Boolean index 1 read GetState write SetState;
|
||||
property Focused: Boolean index 2 read GetState write SetState;
|
||||
property Index : Integer read GetIndex;
|
||||
property ImageIndex : Integer read FImageIndex write SetImageIndex default -1;
|
||||
property Owner : TListItems read FOwner;
|
||||
property Selected: Boolean index 3 read GetState write SetState;
|
||||
property SubItems : TStrings read FSubItems write FSubItems;//SetSubItems;
|
||||
property ImageIndex : Integer read FImageIndex write SetImageIndex default -1;
|
||||
property SubItemImages[Index: Integer]: Integer
|
||||
read GetSubItemImages write SetSubItemImages;
|
||||
end;
|
||||
|
||||
|
||||
@ -1719,6 +1724,9 @@ end.
|
||||
{ =============================================================================
|
||||
|
||||
$Log$
|
||||
Revision 1.64 2003/02/24 19:00:42 mattias
|
||||
added TlistView.SubItem improvements from Olivier Guilbaud
|
||||
|
||||
Revision 1.63 2003/02/18 23:22:56 mattias
|
||||
added listview items property editor
|
||||
|
||||
|
@ -56,6 +56,15 @@ begin
|
||||
Result := -1;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------}
|
||||
{ TListItem SetSubItemImages }
|
||||
{------------------------------------------------------------------------------}
|
||||
procedure TListItem.SetSubItemImages(aIndex: Integer; const AValue: Integer);
|
||||
begin
|
||||
if (aIndex >= 0) and (aIndex < SubItems.Count) then
|
||||
SubItems.Objects[aIndex] := TObject(Pointer(aValue));
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------}
|
||||
{ TListItem Delete }
|
||||
{------------------------------------------------------------------------------}
|
||||
@ -72,6 +81,9 @@ begin
|
||||
FOwner.ItemChanged(self);
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------}
|
||||
{ TListItem IsEqual }
|
||||
{------------------------------------------------------------------------------}
|
||||
function TListItem.IsEqual(Item: TListItem): Boolean;
|
||||
begin
|
||||
Result:=(Caption = Item.Caption) and (Data = Item.Data);
|
||||
@ -90,6 +102,9 @@ begin
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------}
|
||||
{ TListItem SetImageIndex }
|
||||
{------------------------------------------------------------------------------}
|
||||
procedure TListItem.SetImageIndex(const AValue: Integer);
|
||||
begin
|
||||
if AValue <> FImageIndex then
|
||||
@ -107,6 +122,17 @@ begin
|
||||
Result := ((FState AND (1 shl AnIndex))<>0);
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------}
|
||||
{ TListItem GetSubItemImages }
|
||||
{------------------------------------------------------------------------------}
|
||||
function TListItem.GetSubItemImages(aIndex: Integer): Integer;
|
||||
begin
|
||||
if (aIndex >= 0) and (aIndex < SubItems.Count) then
|
||||
Result := Integer(SubItems.Objects[aIndex])
|
||||
else
|
||||
Result := -1;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------}
|
||||
{ TListItem SetState }
|
||||
{------------------------------------------------------------------------------}
|
||||
@ -121,6 +147,9 @@ end;
|
||||
{ =============================================================================
|
||||
|
||||
$Log$
|
||||
Revision 1.14 2003/02/24 19:00:42 mattias
|
||||
added TlistView.SubItem improvements from Olivier Guilbaud
|
||||
|
||||
Revision 1.13 2003/02/18 23:22:56 mattias
|
||||
added listview items property editor
|
||||
|
||||
|
@ -187,7 +187,8 @@ type
|
||||
end;
|
||||
ShortStr = string[255];
|
||||
PShortStr = ^ShortStr;
|
||||
|
||||
PInteger = ^Integer;
|
||||
|
||||
procedure TListItems.ReadData(Stream: TStream);
|
||||
var
|
||||
I, J, Size, L, Len: Integer;
|
||||
@ -195,6 +196,7 @@ var
|
||||
ItemInfo : PItemInfo;
|
||||
PStr : PShortStr;
|
||||
Flag : Boolean;
|
||||
PInt : PInteger;
|
||||
begin
|
||||
Clear;
|
||||
Flag:=False;
|
||||
@ -226,6 +228,20 @@ begin
|
||||
end;
|
||||
Inc(Integer(ItemInfo), SizeOf(TItemInfo)-255+Length(ItemInfo^.Caption)+Len);
|
||||
end;
|
||||
|
||||
//read subitem images
|
||||
if PChar(PStr) - PChar(ItemHeader) < Size then
|
||||
begin
|
||||
PInt := Pointer(PStr);
|
||||
for I := 0 to Count - 1 do
|
||||
begin
|
||||
for J := 0 to Item[I].SubItems.Count - 1 do
|
||||
begin
|
||||
Item[I].SubItemImages[J] := PInt^;
|
||||
Inc(PInt);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
finally
|
||||
FreeMem(ItemHeader, Size);
|
||||
Owner.EndUpdate;
|
||||
@ -237,11 +253,12 @@ end;
|
||||
|
||||
procedure TListItems.WriteData(Stream: TStream);
|
||||
var
|
||||
I, J, Size, L, Len: Integer;
|
||||
ItemHeader: PItemHeader;
|
||||
ItemInfo: PItemInfo;
|
||||
PStr: PShortStr;
|
||||
|
||||
I, J, Size, L, Len : Integer;
|
||||
ItemHeader : PItemHeader;
|
||||
ItemInfo : PItemInfo;
|
||||
PStr : PShortStr;
|
||||
PInt : PInteger;
|
||||
|
||||
function GetLength(const S: string): Integer;
|
||||
begin
|
||||
Result := Length(S);
|
||||
@ -290,6 +307,18 @@ begin
|
||||
Inc(Integer(ItemInfo), SizeOf(TItemInfo) - 255 +
|
||||
Length(ItemInfo^.Caption) + Len);
|
||||
end;
|
||||
|
||||
//write SubItem images.
|
||||
PInt := Pointer(PStr);
|
||||
for I := 0 to Count - 1 do
|
||||
begin
|
||||
for J := 0 to Item[I].SubItems.Count - 1 do
|
||||
begin
|
||||
PInt^ := Item[I].SubItemImages[J];
|
||||
Inc(PInt);
|
||||
end;
|
||||
end;
|
||||
|
||||
Stream.WriteBuffer(ItemHeader^, Size);
|
||||
finally
|
||||
FreeMem(ItemHeader, Size);
|
||||
@ -299,6 +328,9 @@ end;
|
||||
{ =============================================================================
|
||||
|
||||
$Log$
|
||||
Revision 1.17 2003/02/24 19:00:42 mattias
|
||||
added TlistView.SubItem improvements from Olivier Guilbaud
|
||||
|
||||
Revision 1.16 2003/02/18 23:22:56 mattias
|
||||
added listview items property editor
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user