View Issue Details

IDProjectCategoryView StatusLast Update
0038942LazarusWidgetsetpublic2021-06-15 13:16
ReporterAnton Kavalenka Assigned ToJuha Manninen  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version2.1 (SVN) 
Summary0038942: gtk3: Make Listview display icons in vsIcon mode
DescriptionImplemented showing icon in vsIcon mode

Original approach designed by @Zeljiko with renderer interception still present, but code path not working
TagsNo tags attached.
Fixed in Revisionr65215
LazTarget-
WidgetsetGTK 3
Attached Files

Relationships

related to 0038941 closedJuha Manninen GTK3: TPanel never fires MouseUp event 

Activities

Anton Kavalenka

2021-05-28 14:26

reporter  

gtk3listview.diff (2,854 bytes)   
Index: lcl/interfaces/gtk3/gtk3widgets.pas
===================================================================
--- lcl/interfaces/gtk3/gtk3widgets.pas	(revision 65143)
+++ lcl/interfaces/gtk3/gtk3widgets.pas	(working copy)
@@ -2579,7 +2579,11 @@
 procedure TGtk3Widget.DestroyWidget;
 begin
   if IsValidHandle and FOwnWidget then
+  begin
+    DbgOut(#10'destroying '+Classname+' ... ');
     FWidget^.destroy_;
+    DbgOut(Classname+' destroyed.'+#10);
+  end;
   FWidget := nil;
 end;
 
@@ -5799,6 +5803,9 @@
   AScrollStyle: TPoint;
   PtrType: GType;
   TreeModel: PGtkTreeModel;
+  iter:TGtkTreeIter;
+  pxb:PGdkPixbuf;
+  err:gint;
 begin
   FImages := nil;
   FScrollX := 0;
@@ -5810,12 +5817,24 @@
 
   PtrType := G_TYPE_POINTER;
 
-  TreeModel := PGtkTreeModel(gtk_list_store_newv(1, @PtrType));
 
+
   if TListView(AListView).ViewStyle in [vsIcon,vsSmallIcon] then
-    FCentralWidget := TGtkIconView.new_with_model(TreeModel)
+  begin
+    TreeModel := PGtkTreeModel(gtk_list_store_new(3, [
+      G_TYPE_POINTER, // ListItem pointer
+      G_TYPE_STRING, // text
+     gdk_pixbuf_get_type() // pixbuf
+     ]));
+    FCentralWidget := TGtkIconView.new_with_model(TreeModel);
+    PGtkIconView(FCentralWidget)^.set_text_column(1);
+    PGtkIconView(FCentralWidget)^.set_pixbuf_column(2);
+  end
   else
+  begin
+    TreeModel := PGtkTreeModel(gtk_list_store_newv(1, @PtrType));
     FCentralWidget := TGtkTreeView.new_with_model(TreeModel);
+  end;
 
   FIsTreeView := not (TListView(AListView).ViewStyle in [vsIcon,vsSmallIcon]);
 
@@ -6195,6 +6214,8 @@
   AModel: PGtkTreeModel;
   Iter: TGtkTreeIter;
   NewIndex: Integer;
+  bmp:TBitmap;
+  pxb:PGdkPixbuf;
 begin
   if not IsWidgetOK then
     exit;
@@ -6207,10 +6228,22 @@
     NewIndex := AModel^.iter_n_children(nil)
   else
     NewIndex := AIndex;
-  // AGValue.g_type := G_TYPE_POINTER;
-  // AGValue.set_pointer(AItem);
-  gtk_list_store_insert_with_values(PGtkListStore(AModel), @Iter, NewIndex, [0, Pointer(AItem), -1]);
-  // PGtkListStore(AModel)^.insert_with_valuesv(@Iter, NewIndex, @AColumns, @AGValue, 1);
+
+  if IsTreeView then
+    gtk_list_store_insert_with_values(PGtkListStore(AModel), @Iter, NewIndex,
+      [0, Pointer(AItem), -1])
+  else
+  begin
+    bmp:=TBitmap.Create;
+    TListView(LCLObject).LargeImages.GetBitmap(AIndex,bmp);
+    pxb:=TGtk3Image(bmp.Handle).Handle;
+    gtk_list_store_insert_with_values(PGtkListStore(AModel), @Iter, NewIndex,
+      [0, Pointer(AItem),
+       1, PChar(AItem.Caption),
+       2, pxb, -1] );
+    fImages.Add(bmp);
+  end;
+
 end;
 
 procedure TGtk3ListView.ItemSetText(AIndex, ASubIndex: Integer;
@@ -6221,8 +6254,7 @@
 begin
   if not IsWidgetOK then
     exit;
-  if not getContainerWidget^.get_realized then
-    exit;
+
   if IsTreeView then
   begin
     Path := gtk_tree_path_new_from_indices(AIndex, [-1]);
gtk3listview.diff (2,854 bytes)   
project1.zip (108,902 bytes)

Anton Kavalenka

2021-05-28 14:27

reporter   ~0131071

Juha Manninen

2021-06-10 20:37

developer   ~0131231

Last edited: 2021-06-10 20:38

View 2 revisions

Solved together with 0038941.

Anton Kavalenka

2021-06-11 06:31

reporter   ~0131242

Applied gtk3listview.diff instead of newer gtk3listview-2.diff

New patch upon current tree state.
gtk3listview-3.diff (4,477 bytes)   
Index: lcl/interfaces/gtk3/gtk3widgets.pas
===================================================================
--- lcl/interfaces/gtk3/gtk3widgets.pas	(revision 65213)
+++ lcl/interfaces/gtk3/gtk3widgets.pas	(working copy)
@@ -592,9 +592,11 @@
     procedure SetColumnVisible(AIndex: Integer; {%H-}AColumn: TListColumn; AVisible: Boolean);
     procedure ColumnSetSortIndicator(const AIndex: Integer; const {%H-}AColumn: TListColumn; const ASortIndicator: TSortIndicator);
 
+    procedure UpdateItem(AIndex:integer;AItem: TListItem);
     procedure ItemDelete(AIndex: Integer);
     procedure ItemInsert(AIndex: Integer; AItem: TListItem);
     procedure ItemSetText(AIndex, ASubIndex: Integer; AItem: TListItem; const AText: String);
+    procedure ItemSetImage(AIndex, ASubIndex: Integer; AItem: TListItem);
     procedure ItemSetState(const AIndex: Integer; const {%H-}AItem: TListItem; const AState: TListItemState;
       const AIsSet: Boolean);
     function ItemGetState(const AIndex: Integer; const {%H-}AItem: TListItem; const AState: TListItemState;
@@ -1153,8 +1155,7 @@
       if TGtk3Widget(Data).LCLObject is TButtonControl then exit;
 
 
-      TGtk3Widget(Data).GtkEventMouse(Widget , Event);
-      Result:=true;
+      Result:=TGtk3Widget(Data).GtkEventMouse(Widget , Event);
     end;
   GDK_2BUTTON_PRESS:
     begin
@@ -6261,11 +6262,46 @@
 
 end;
 
+procedure TGtk3ListView.UpdateItem(AIndex:integer;AItem: TListItem);
+var
+  Path: PGtkTreePath;
+  ItemRect: TGdkRectangle;
+  AModel: PGtkTreeModel;
+  Iter: TGtkTreeIter;
+  bmp:TBitmap;
+  pxb:PGdkPixbuf;
+begin
+  if IsTreeView then
+  begin
+    Path := gtk_tree_path_new_from_indices(AIndex, [-1]);
+    PGtkTreeView(GetContainerWidget)^.get_cell_area(Path, nil, @ItemRect);
+    gtk_tree_path_free(Path);
+  end else
+  begin
+    Path := gtk_tree_path_new_from_indices(AIndex, [-1]);
+    AModel:=PGtkIconView(GetContainerWidget)^.get_model;
+    AModel^.get_iter(@iter,path);
+
+    bmp:=TBitmap.Create;
+    TListView(LCLObject).LargeImages.GetBitmap(AItem.ImageIndex,bmp);
+    pxb:=TGtk3Image(bmp.Handle).Handle;
+    gtk_list_store_set(PGtkListStore(AModel), @Iter,
+      [0, Pointer(AItem),
+       1, PChar(AItem.Caption),
+       2, pxb, -1] );
+    fImages.Add(bmp);
+
+    gtk_tree_path_free(Path);
+  end;
+end;
+
 procedure TGtk3ListView.ItemSetText(AIndex, ASubIndex: Integer;
   AItem: TListItem; const AText: String);
 var
   Path: PGtkTreePath;
   ItemRect: TGdkRectangle;
+  AModel: PGtkTreeModel;
+  Iter: TGtkTreeIter;
 begin
   if not IsWidgetOK then
     exit;
@@ -6276,11 +6312,36 @@
     PGtkTreeView(GetContainerWidget)^.get_cell_area(Path, nil, @ItemRect);
     gtk_tree_path_free(Path);
   end else
-    ItemRect.Height := 1;
+  begin
+    UpdateItem(AIndex,AItem);
+  end;
   if GetContainerWidget^.get_visible and (ItemRect.height <> 0) then // item is visible
     GetContainerWidget^.queue_draw;
 end;
 
+procedure TGtk3ListView.ItemSetImage(AIndex, ASubIndex: Integer; AItem: TListItem);
+var
+  Path: PGtkTreePath;
+  ItemRect: TGdkRectangle;
+  AModel: PGtkTreeModel;
+  Iter: TGtkTreeIter;
+begin
+  if not IsWidgetOK then
+    exit;
+
+  if IsTreeView then
+  begin
+    Path := gtk_tree_path_new_from_indices(AIndex, [-1]);
+    PGtkTreeView(GetContainerWidget)^.get_cell_area(Path, nil, @ItemRect);
+    gtk_tree_path_free(Path);
+  end else
+  begin
+    UpdateItem(AIndex,AItem);
+  end;
+  if GetContainerWidget^.get_visible and (ItemRect.height <> 0) then // item is visible
+    GetContainerWidget^.queue_draw;
+end;
+
 procedure TGtk3ListView.ItemSetState(const AIndex: Integer;
   const AItem: TListItem; const AState: TListItemState; const AIsSet: Boolean);
 var
Index: lcl/interfaces/gtk3/gtk3wscomctrls.pp
===================================================================
--- lcl/interfaces/gtk3/gtk3wscomctrls.pp	(revision 65213)
+++ lcl/interfaces/gtk3/gtk3wscomctrls.pp	(working copy)
@@ -689,8 +689,11 @@
   const AIndex: Integer; const AItem: TListItem; const ASubIndex,
   AImageIndex: Integer);
 begin
-  // DebugLn('TGtk3WSCustomListView.ItemSetImage ');
-  // inherited ItemSetImage(ALV, AIndex, AItem, ASubIndex, AImageIndex);
+  if not WSCheckHandleAllocated(ALV, 'ItemSetImage') then
+    Exit;
+  TGtk3ListView(ALV.Handle).BeginUpdate;
+  TGtk3ListView(ALV.Handle).ItemSetImage(AIndex,ASubIndex, AItem);
+  TGtk3ListView(ALV.Handle).EndUpdate;
 end;
 
 class procedure TGtk3WSCustomListView.ItemSetState(const ALV: TCustomListView;
gtk3listview-3.diff (4,477 bytes)   

Anton Kavalenka

2021-06-11 06:33

reporter   ~0131243

Used the 1st version of patch, please use recent-one

Juha Manninen

2021-06-11 07:08

developer   ~0131244

Ok, I applied gtk3listview-3.diff in r65215. Thanks.

Issue History

Date Modified Username Field Change
2021-05-28 14:26 Anton Kavalenka New Issue
2021-05-28 14:26 Anton Kavalenka File Added: gtk3listview.diff
2021-05-28 14:26 Anton Kavalenka File Added: project1.zip
2021-05-28 14:27 Anton Kavalenka Note Added: 0131071
2021-05-28 14:27 Anton Kavalenka File Added: Здымак экрана, 2021-05-28 17-26-55.png
2021-05-29 07:57 Juha Manninen Assigned To => Juha Manninen
2021-05-29 07:57 Juha Manninen Status new => assigned
2021-06-10 20:30 Juha Manninen Relationship added related to 0038941
2021-06-10 20:37 Juha Manninen Status assigned => resolved
2021-06-10 20:37 Juha Manninen Resolution open => fixed
2021-06-10 20:37 Juha Manninen LazTarget => -
2021-06-10 20:37 Juha Manninen Widgetset GTK 3 => GTK 3
2021-06-10 20:37 Juha Manninen Note Added: 0131231
2021-06-10 20:38 Juha Manninen Note Edited: 0131231 View Revisions
2021-06-11 06:31 Anton Kavalenka Note Added: 0131242
2021-06-11 06:31 Anton Kavalenka File Added: gtk3listview-3.diff
2021-06-11 06:33 Anton Kavalenka Status resolved => assigned
2021-06-11 06:33 Anton Kavalenka Resolution fixed => open
2021-06-11 06:33 Anton Kavalenka Note Added: 0131243
2021-06-11 07:08 Juha Manninen Status assigned => resolved
2021-06-11 07:08 Juha Manninen Resolution open => fixed
2021-06-11 07:08 Juha Manninen Fixed in Revision => r65215
2021-06-11 07:08 Juha Manninen Widgetset GTK 3 => GTK 3
2021-06-11 07:08 Juha Manninen Note Added: 0131244
2021-06-15 13:16 Anton Kavalenka Status resolved => closed