Added images to TListView.

Shane

git-svn-id: trunk@573 -
This commit is contained in:
lazarus 2002-01-04 20:29:04 +00:00
parent 86d5fa5b9c
commit f6d5703573
4 changed files with 87 additions and 7 deletions

View File

@ -2653,6 +2653,8 @@ begin
X := ColumnDlg.Add(ViewColumns.Item[i].Caption);
ColumnDlg.Item[x].Width :=ViewColumns.Item[i].Width;
ColumnDlg.Item[x].Alignment :=ViewColumns.Item[i].Alignment;
ColumnDlg.Item[x].Visible :=ViewColumns.Item[i].Visible;
ColumnDlg.Item[x].AutoSize :=ViewColumns.Item[i].AutoSize;
end;
if ColumnDlg.ShowModal = mrOK then
@ -2664,6 +2666,8 @@ begin
X := ViewColumns.Add(Column.Caption);
ViewColumns.Item[x].Width := Column.Width;
ViewColumns.Item[x].Alignment := Column.Alignment;
ViewColumns.Item[x].Visible := Column.Visible;
ViewColumns.Item[x].AutoSize := Column.AutoSize;
End;
end;
finally

View File

@ -482,14 +482,15 @@ type
TCustomListView = class(TWinControl)
private
//FReadOnly : Boolean;
FImages : TCustomImageList;
FListItems : TListItems;
FColumns : TViewColumns;
FViewStyle : TViewStyle;
FSorted : Boolean;
FSortColumn : Integer;
FMultiSelect: Boolean;
FImageList: TImageList;
procedure SetImageList(const AValue: TImageList);
FImageChangeLink : TChangeLink;
procedure SetImages(const AValue: TCustomImageList);
procedure SetMultiSElect(const AValue: Boolean);
procedure SetItems(Value : TListItems);
protected
@ -502,6 +503,7 @@ type
Procedure ItemChanged(Index : Integer); //called by TListItems
Procedure ItemDeleted(Index : Integer); //called by TListItems
Procedure ColumnsChanged(Sender : TObject); //called by TViewColumns
Procedure ImageChanged(Sender : TObject);
Procedure ItemAdded; //called by TListItems
public
constructor Create(Aowner: TComponent); override;
@ -512,13 +514,14 @@ type
property Sorted : Boolean read FSorted write SetSorted;
property SortColumn : Integer read FSortColumn write SetSortColumn;
property MultiSelect : Boolean read FMultiSelect write SetMultiSelect default False;
property ImageList : TImageList read FImageList write SetImageList;
property Images : TCustomImageList read FImages write SetImages;
end;
TListView = class(TCustomListView)
published
property Columns;
property Items;
property Images;
property Visible;
property ViewStyle;
property OnMOuseMOve;
@ -1034,6 +1037,10 @@ end.
{ =============================================================================
$Log$
Revision 1.14 2002/01/04 20:29:04 lazarus
Added images to TListView.
Shane
Revision 1.13 2002/01/03 21:17:08 lazarus
added column visible and autosize settings.
Shane

View File

@ -12,10 +12,13 @@ begin
Columns := TViewColumns.Create(self);
Columns.OnChange := @ColumnsChanged;
FListItems := TListITems.Create(self);
FImages := NIL;
fCompStyle := csListView;
fViewStyle := vsList;
fSorted := False;
fSortColumn := 0;
FImageChangeLink := TChangeLink.Create;
FImageChangeLink.OnChange := @ImageChanged;
Setbounds(2,2,300,300);
end;
@ -120,6 +123,7 @@ end;
destructor TCustomListView.Destroy;
begin
Columns.Free;
FImageChangeLink.Free;
inherited Destroy;
end;
@ -133,11 +137,29 @@ begin
end;
procedure TCustomListView.SetImageList(const AValue: TImageList);
procedure TCustomListView.SetImages(const AValue: TCustomImageList);
begin
if AValue <> FImageList then
if AValue <> FImages then
Begin
FImageList := AValue;
if FImages <> nil then
FImages.UnregisterChanges(FImageChangeLink);
FImages := AValue;
if FImages <> nil then
FImages.RegisterChanges(FImageChangeLink);
FImages.FreeNotification(self);
CNSendMessage(LM_SETPROPERTIES,self,nil);
end;
end;
Procedure TCustomListView.ImageChanged(Sender : TObject);
begin
Writeln('IMAGE CHANGED!!!!');
//image changed so redraw it all....
CNSendMessage(LM_SETPROPERTIES,self,nil);
end;

View File

@ -382,6 +382,7 @@ var
MsgPtr : PMsg; // currently only used by LM_DESTROY
Count : Integer; //Used in TListView LM_LV_CHANGEITEM
Titles : Array [0..255] of PChar;
BitImage : TBitmap;
begin
Result := 0; //default value just in case nothing sets it
@ -491,7 +492,24 @@ begin
pStr := StrAlloc(length(AddItemListItem.Caption) + 1);
StrPCopy(pStr, AddItemListItem.Caption);
gtk_clist_set_text(PgtkCList(Handle),num,0,pStr);
if (TCustomListView(sender).Images <> nil) and (TListItem(TCustomListView(sender).Items[Num]).ImageIndex > -1) then
Begin
Writeln('Checking images');
if (TListItem(TCustomListView(sender).Items[Num]).ImageIndex < TCustomListView(sender).Images.Count) then
begin
//draw image
Writeln('drawing image');
Writeln('TListItem(TCustomListView(sender).Items[i]).ImageIndex is ',TListItem(TCustomListView(sender).Items[Num]).ImageIndex);
BitImage := TBitmap.Create;
TCustomListView(sender).Images.GetBitmap(TListItem(TCustomListView(sender).Items[Num]).ImageIndex,BitImage);
gtk_clist_set_pixtext(Pgtkclist(handle),Num,0,pStr,3,pgdkPixmap(PgdiObject(BitImage.handle)^.GDIBitmapObject),nil);
end;
end;
StrDispose(pStr);
for count := 0 to AddItemListItem.SubItems.Count-1 do
Begin
pStr := StrAlloc(length(AddItemListItem.SubItems.Strings[Count]) + 1);
@ -3026,7 +3044,7 @@ var
pColName : PChar;
pRowText : PChar;
Image : PgdkImage;
BitImage : TBitMap;
begin
result := 0; // default if nobody sets it
@ -3182,8 +3200,33 @@ begin
GetMem(pRowText,Length(TListItem(TCustomListView(sender).Items[i]).Caption)+1);
pRowText := StrPcopy(pRowText,TListItem(TCustomListView(sender).Items[i]).Caption);
gtk_clist_set_text(Pgtkclist(Handle),0,I+1,pRowText);
//do image if one is assigned....
Writeln('Starting image section');
if (TCustomListView(sender).Images <> nil) and (TListItem(TCustomListView(sender).Items[i]).ImageIndex > -1) then
Begin
Writeln('Checking images');
if (TListItem(TCustomListView(sender).Items[i]).ImageIndex < TCustomListView(sender).Images.Count) then
begin
//draw image
Writeln('drawing image');
Writeln('TListItem(TCustomListView(sender).Items[i]).ImageIndex is ',TListItem(TCustomListView(sender).Items[i]).ImageIndex);
BitImage := TBitmap.Create;
TCustomListView(sender).Images.GetBitmap(TListItem(TCustomListView(sender).Items[i]).ImageIndex,BitImage);
gtk_clist_set_pixmap(Pgtkclist(handle),I,0,pgdkPixmap(PgdiObject(BitImage.handle)^.GDIBitmapObject),nil);
gtk_clist_set_pixtext(Pgtkclist(handle),I,0,pRowText,3,pgdkPixmap(PgdiObject(BitImage.handle)^.GDIBitmapObject),nil);
// bitimage.Free;
end;
end;
freemem(pRowText);
//
if (TCustomListView(sender).ViewStyle = vsReport) then //columns showing
For X := 1 to Columns.Count-1 do
begin
@ -3666,6 +3709,10 @@ end;
{ =============================================================================
$Log$
Revision 1.100 2002/01/04 20:29:04 lazarus
Added images to TListView.
Shane
Revision 1.99 2002/01/03 21:17:08 lazarus
added column visible and autosize settings.
Shane