Lazarus

Programming => Widgetset => GTK => Topic started by: mm7 on December 24, 2019, 06:17:03 pm

Title: TListView vsIcon style word wrapping does not work
Post by: mm7 on December 24, 2019, 06:17:03 pm
Hi,
TListView does not wrap item text in icons mode.
I've set ListView1.IconOptions.WrapText to True or False. No impact.
IconOptions.AutoArrange is True or False. No impact as well.

I tried to set 'wrap-mode' and 'wrap-width' properties directly to GtkCellRendererText, that I get from GtkIconView backend object.
This also does not work for some reason.

Also tried gtk_icon_view_set_item_width(icon_view,120);
No luck.

Example is attached.

I did same in C++, all works there. Just to check if Gtk2 is working.

Ubuntu 16.04.6 LTS x86_64
Title: Re: TListView vsIcon style word wrapping does not work
Post by: mm7 on December 25, 2019, 04:30:45 pm
debugged it deeper.
I see   
Code: Pascal  [Select][+][-]
  1. lvpWrapText: begin
  2.         // TODO: implement ???
  3.  
in class procedure TGtk2WSCustomListView.SetPropertyInternal
in file gtk2wscustomlistview.inc

So, it is just not implemented. Which is Ok.

But why it does not work when I do it by calling
Code: Pascal  [Select][+][-]
  1.       g_object_set_data(G_OBJECT(text_renderer), PChar('wrap-mode'), gpointer(ptrint(PANGO_WRAP_WORD_CHAR)));
  2.       g_object_set_data(G_OBJECT(text_renderer), PChar('wrap-width'), gpointer(ptrint(120)));
  3.  

Does LCL overrides renderers or their properties somewhere?

No. It does not. I've read the properties next time before switching. The properties are there in the GtkCellRenderer object.
But they do not have any impact.


Title: Re: TListView vsIcon style word wrapping does not work
Post by: mm7 on December 27, 2019, 11:05:12 pm
OMG!
 :-[
I used g_object_set_data which is wrong!
Using g_object_set is the right way.

Code: Pascal  [Select][+][-]
  1.     g_object_set(G_OBJECT(text_renderer), PChar('wrap-mode'),  [gpointer(ptrint(PANGO_WRAP_WORD_CHAR)), nil]);
  2.     g_object_set(G_OBJECT(text_renderer), PChar('wrap-width'), [gpointer(ptrint(120)), nil]);
  3.  
Title: Re: TListView vsIcon style word wrapping does not work
Post by: mm7 on December 27, 2019, 11:48:55 pm
Here is correct code if someone needs it.

Code: Pascal  [Select][+][-]
  1. // this is not published in LCL. Copied here.
  2. procedure GetCommonTreeViewWidgets(ATreeViewHandle: PGtkWidget;
  3.   out TVWidgets: PTVWidgets);
  4. var
  5.   WidgetInfo: PWidgetInfo;
  6. begin
  7.   WidgetInfo := GetWidgetInfo(ATreeViewHandle);
  8.   TVWidgets := PTVWidgets(WidgetInfo^.UserData);
  9. end;
  10.  
  11. // this is not defined in LCL. Define here.
  12. function gtk_cell_layout_get_cells(cell_layout:PGtkCellLayout):PGlist;cdecl;
  13.           external gtklib name 'gtk_cell_layout_get_cells';
  14.  
  15. function Gtk2_GtkIconView_GetTextRenderer(icon_view:PGtkIconView):PGtkCellRendererText;
  16. var renderers, renderers_list: PGList;
  17.   renderer: PGtkCellRenderer;
  18. begin
  19.   renderers_list := gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(icon_view));
  20.   renderers := renderers_list;
  21.   while (renderers <> nil) and (renderers^.data <> nil) do
  22.   begin
  23.      renderer := renderers^.data;
  24.      if GTK_IS_CELL_RENDERER_TEXT(renderer) then
  25.      begin
  26.        result := GTK_CELL_RENDERER_TEXT(renderer);
  27.        break;
  28.      end;
  29.      if renderers^.next = nil then break;
  30.      renderers := renderers^.next;
  31.   end;
  32.   g_list_free(renderers_list);
  33. end;
  34.  
  35. procedure Gtk2WSCustomListView_IconView_SetWordWrap(const ALV: TCustomListView;
  36.   const AWordWrap: Boolean; AWrapWidth:integer );
  37. var
  38.   Widgets: PTVWidgets;
  39.   icon_view: PGtkIconView;
  40.   text_renderer : PGtkCellRendererText;
  41. begin
  42.   if not WSCheckHandleAllocated(ALV, 'TListViewTestForm')
  43.   then Exit;
  44.  
  45.   GetCommonTreeViewWidgets({%H-}PGtkWidget(ALV.Handle), Widgets);
  46.   if not GTK_IS_ICON_VIEW(Widgets^.MainView)
  47.   then Exit;
  48.  
  49.   icon_view := PGtkIconView(Widgets^.MainView);
  50.  
  51.   text_renderer := Gtk2_GtkIconView_GetTextRenderer(icon_view);
  52.  
  53.   if text_renderer = nil then exit;
  54.  
  55.   if AWordWrap then
  56.     begin
  57.     gtk_icon_view_set_item_width(icon_view,120);
  58.     g_object_set(G_OBJECT(text_renderer),
  59.       PChar('alignment'), [gpointer(ptrint(PANGO_ALIGN_CENTER)),
  60.       PChar('wrap-mode'),  gpointer(ptrint(PANGO_WRAP_WORD_CHAR)),
  61.       PChar('wrap-width'), gpointer(ptrint(AWrapWidth)), nil]);
  62.     end
  63.   else
  64.     begin
  65.     gtk_icon_view_set_item_width(icon_view, -1);
  66.     g_object_set(G_OBJECT(text_renderer),
  67.       PChar('alignment'), [gpointer(ptrint(PANGO_ALIGN_LEFT)),
  68.       PChar('wrap-mode'),  gpointer(ptrint(PANGO_WRAP_CHAR)),
  69.       PChar('wrap-width'), gpointer(ptrint(-1)), nil]);
  70.     end;
  71.   ALV.Invalidate;
  72. end;
  73.  
TinyPortal © 2005-2018