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 21 forks source link

Replace two calls of gtk_container_add with gtk_button_set_image #175

Closed sedwards closed 1 year ago

sedwards commented 1 year ago

Replace two calls of gtk_container_add with gtk_button_set_image for compatibility with gtk2/3/(mostly)4

wdlkmpx commented 1 year ago

gtk4 removed quite a lot of functions and widgets, a gtk layer is becoming a necessity to implement forward and backwards support.. libwgtk

fortunately gftp doesn't rely on gobject classes. I must admit that C is too primitive, C++ is too ugly, somewhere in between lies the real C programming

some new gtk4 functions can be used to implement backwards compatibility and those functions can become the preferred method, something like this:

#if GTK_MAJOR_VERSION < 4
void gtk_scrolled_window_set_child (GtkScrolledWindow* scrolled_window,  GtkWidget* child)
{
# if GTK_CHECK_VERSION(3,8,0)
    // 3.8+: gtk_container_add() automatically adds a GtkViewPort
    // if the child doesn't implement GtkScrollable
    gtk_container_add (GTK_CONTAINER(scrolled_window), child);
# elif GTK_CHECK_VERSION(3,0,0)
    // 3.0+: GtkScrollable is an interface that is implemented by widgets with native scrolling
    if (GTK_IS_SCROLLABLE(child)) {
        gtk_container_add (GTK_CONTAINER(scrolled_window), child);
    } else {
        gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW(scrolled_window), child);
    }
# else // GTK2 & 1
    GtkWidgetClass *widget_class;
    widget_class = GTK_WIDGET_GET_CLASS(child);
    if (widget_class->set_scroll_adjustments_signal) {
        gtk_container_add (GTK_CONTAINER(scrolled_window), child);
    } else {
        gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW(scrolled_window), child);
    }
# endif
}
#endif