masneyb / gftp

gFTP is a free multithreaded file transfer client for *NIX based machines. 56 language translations available.
http://www.gftp.org
MIT License
116 stars 20 forks source link

gtk: replace references of GdkBitmap and GdkPixmap for GdkPixbuf #86

Closed sedwards closed 4 years ago

sedwards commented 4 years ago

I am not sure I understand the code here properly. I tested this on gtk2 and didn't encounter a visual regression with any of the images when doing transfers but perhaps I am failing to follow the logic.

This compiles with no warnings or errors....but my understanding is that it shouldn't work, and that this should be done via Cairo surfaces. Please advise.

wdlkmpx commented 4 years ago

The answer is: you can't. I don't see how it can compile without warnings.

There's the gftp_get_pixmap function that returns a gftp_graphic (GdkPixmap + GdkBitmap), this is what GTK1 widgets support.

GtkCList/GtkTCree requires GdkPixmap+GdkBitmap and it doesn't support GdkPixbuf.

GtkTreeView supports only GdkPixbuf... see gftp_get_pixbuf

By replacing the transfer window GtkCTree with GtkTreeView, the following functions can finally be deleted:

gftp_graphic * open_xpm (GtkWidget * widget, char *filename)
void gftp_free_pixmap (char *filename)
void gftp_get_pixmap (GtkWidget * widget, char *filename, GdkPixmap ** pix, GdkBitmap ** bitmap)
wdlkmpx commented 4 years ago

Ok, I have to admit you're [partially] right. It does compile with warnings.

I see the expected behavior, it doesn't crash. It doesn't make sense... it should segfauit.

It can replace GdkPixmap but it doesn't feel right at the moment. I remember testing something like that with GtkCList and the listbox would not display icons

misc-gtk.c: In function ‘open_xpm’:
misc-gtk.c:371:25: warning: passing argument 2 of ‘gdk_pixmap_create_from_xpm’ from incompatible pointer type [-Wincompatible-pointer-types]
                         &graphic->bitmap, &style->bg[GTK_STATE_NORMAL], exfile);
                         ^
In file included from /usr/include/gtk-2.0/gdk/gdk.h:49:0,
                 from /usr/include/gtk-2.0/gtk/gtk.h:32,
                 from gtkcompat.h:8,
                 from gftp-gtk.h:27,
                 from misc-gtk.c:20:
/usr/include/gtk-2.0/gdk/gdkpixmap.h:86:12: note: expected ‘GdkBitmap ** {aka struct _GdkDrawable **}’ but argument is of type ‘GdkPixbuf ** {aka struct _GdkPixbuf **}’
 GdkPixmap* gdk_pixmap_create_from_xpm            (GdkDrawable    *drawable,
            ^~~~~~~~~~~~~~~~~~~~~~~~~~
misc-gtk.c:370:19: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
   graphic->pixmap = gdk_pixmap_create_from_xpm (widget->window,
                   ^
  CC       options_dialog.o
  CC       transfer.o
transfer.c: In function ‘show_transfer’:
transfer.c:522:40: warning: passing argument 6 of ‘gtk_ctree_insert_node’ from incompatible pointer type [-Wincompatible-pointer-types]
                                        closedir_pixmap, closedir_bitmap,
                                        ^~~~~~~~~~~~~~~
In file included from /usr/include/gtk-2.0/gtk/gtk.h:229:0,
                 from gtkcompat.h:8,
                 from gftp-gtk.h:27,
                 from transfer.c:20:
/usr/include/gtk-2.0/gtk/gtkctree.h:181:16: note: expected ‘GdkPixmap * {aka struct _GdkDrawable *}’ but argument is of type ‘GdkPixbuf * {aka struct _GdkPixbuf *}’
 GtkCTreeNode * gtk_ctree_insert_node             (GtkCTree     *ctree,
                ^~~~~~~~~~~~~~~~~~~~~
transfer.c:522:57: warning: passing argument 7 of ‘gtk_ctree_insert_node’ from incompatible pointer type [-Wincompatible-pointer-types]
                                        closedir_pixmap, closedir_bitmap,
                                                         ^~~~~~~~~~~~~~~
In file included from /usr/include/gtk-2.0/gtk/gtk.h:229:0,
                 from gtkcompat.h:8,
                 from gftp-gtk.h:27,
                 from transfer.c:20:
/usr/include/gtk-2.0/gtk/gtkctree.h:181:16: note: expected ‘GdkBitmap * {aka struct _GdkDrawable *}’ but argument is of type ‘GdkPixbuf * {aka struct _GdkPixbuf *}’
 GtkCTreeNode * gtk_ctree_insert_node             (GtkCTree     *ctree,
                ^~~~~~~~~~~~~~~~~~~~~
transfer.c:523:40: warning: passing argument 8 of ‘gtk_ctree_insert_node’ from incompatible pointer type [-Wincompatible-pointer-types]
                                        opendir_pixmap, opendir_bitmap,
                                        ^~~~~~~~~~~~~~
In file included from /usr/include/gtk-2.0/gtk/gtk.h:229:0,
                 from gtkcompat.h:8,
                 from gftp-gtk.h:27,
                 from transfer.c:20:
/usr/include/gtk-2.0/gtk/gtkctree.h:181:16: note: expected ‘GdkPixmap * {aka struct _GdkDrawable *}’ but argument is of type ‘GdkPixbuf * {aka struct _GdkPixbuf *}’
 GtkCTreeNode * gtk_ctree_insert_node             (GtkCTree     *ctree,
                ^~~~~~~~~~~~~~~~~~~~~
transfer.c:523:56: warning: passing argument 9 of ‘gtk_ctree_insert_node’ from incompatible pointer type [-Wincompatible-pointer-types]
                                        opendir_pixmap, opendir_bitmap,
                                                        ^~~~~~~~~~~~~~
In file included from /usr/include/gtk-2.0/gtk/gtk.h:229:0,
                 from gtkcompat.h:8,
                 from gftp-gtk.h:27,
                 from transfer.c:20:
/usr/include/gtk-2.0/gtk/gtkctree.h:181:16: note: expected ‘GdkBitmap * {aka struct _GdkDrawable *}’ but argument is of type ‘GdkPixbuf * {aka struct _GdkPixbuf *}’
 GtkCTreeNode * gtk_ctree_insert_node             (GtkCTree     *ctree,
                ^~~~~~~~~~~~~~~~~~~~~
wdlkmpx commented 4 years ago

It now makes sense. This is what I think is happening.

The functions are operating on a GdkPixmap, but with a different pointer type.

gdk_pixmap_create_from_xpm returns a GdkPixmap, and there's no way to change that.

I remember using GdkPixbuf and replacing the functions that deal with GdkPixmaps... that resulted on compile-time warnings and runtime critical errors.

In this case it's only compile-time warnings.

wdlkmpx commented 4 years ago

The only way to replace GdkPixmap with GdkPixbuf is to remove GTK(1) widgets that don't support GdkPixbuf.. GtkCTree .. and this is really hard.

Discussion happening in issue #84