summaryrefslogtreecommitdiffstats
path: root/gtk/src/ghbcompat.h
diff options
context:
space:
mode:
authorJohn Stebbins <[email protected]>2019-07-24 15:03:22 -0700
committerJohn Stebbins <[email protected]>2019-07-26 12:57:20 -0700
commita1d064d2f01d963213b1336c0aeda9e7a1a6817f (patch)
tree3857d6faaa5c61a71d1106403f1cbf74ba93d992 /gtk/src/ghbcompat.h
parent30b59112b75ef6572615db032fb461d9e9c51fa2 (diff)
LinGui: WIP gtk4 support
Known issues and todo: notebooks, use GtkNotebookPage semantics in ui file fix keypress delete in queue_list fix dest_file grab-focus? (highlight of filename for editing) focus-in/out with GtkEventControllerKey preview_state_cb how to handle icon-ified preview? preview_configure_cb, saving preview window size? accelerator alt-d grab-focus destination key-press-event in chapter list, ghbcellrenderertext -> GtkEventControllerKey Why doesn't summary preview image scale correctly? "System" in about dialog? why is the tab there when "system" prop not set? GtkSeparatorToolitem seems to ignore "draw" prop?
Diffstat (limited to 'gtk/src/ghbcompat.h')
-rw-r--r--gtk/src/ghbcompat.h246
1 files changed, 216 insertions, 30 deletions
diff --git a/gtk/src/ghbcompat.h b/gtk/src/ghbcompat.h
index 382125132..44ef7f4e0 100644
--- a/gtk/src/ghbcompat.h
+++ b/gtk/src/ghbcompat.h
@@ -34,6 +34,31 @@
#define GHB_UNSAFE_FILENAME_CHARS "/"
#endif
+#if GTK_CHECK_VERSION(3, 90, 0)
+#define GHB_ICON_SIZE_BUTTON GTK_ICON_SIZE_NORMAL
+#else
+#define GHB_ICON_SIZE_BUTTON GTK_ICON_SIZE_BUTTON
+#endif
+
+#if !GTK_CHECK_VERSION(3, 10, 0)
+#define gtk_image_set_from_icon_name gtk_image_set_from_stock
+#define GHB_PLAY_ICON "gtk-media-play"
+#define GHB_PAUSE_ICON "gtk-media-pause"
+#else
+#define GHB_PLAY_ICON "media-playback-start"
+#define GHB_PAUSE_ICON "media-playback-pause"
+#endif
+
+#if !GTK_CHECK_VERSION(3, 10, 0)
+#define GHB_STOCK_OPEN GTK_STOCK_OPEN
+#define GHB_STOCK_CANCEL GTK_STOCK_CANCEL
+#define GHB_STOCK_SAVE GTK_STOCK_SAVE
+#else
+#define GHB_STOCK_OPEN "_Open"
+#define GHB_STOCK_CANCEL "_Cancel"
+#define GHB_STOCK_SAVE "_Save"
+#endif
+
static inline void ghb_widget_get_preferred_width(
GtkWidget *widget, gint *min_width, gint * natural_width)
{
@@ -103,10 +128,13 @@ static inline void ghb_get_expand_fill(GtkBox * box, GtkWidget * child,
}
}
-static inline void ghb_box_pack_start(GtkBox * box, GtkWidget * child)
+static inline void ghb_box_append_child(GtkBox * box, GtkWidget * child)
{
#if GTK_CHECK_VERSION(3, 90, 0)
- gtk_box_pack_start(box, child);
+ GtkWidget * sibling = NULL;
+
+ sibling = gtk_widget_get_last_child(GTK_WIDGET(box));
+ gtk_box_insert_child_after(box, child, sibling);
#else
gboolean expand, fill;
@@ -177,28 +205,71 @@ static inline PangoFontDescription* ghb_widget_get_font(GtkWidget *widget)
return font;
}
-static inline void ghb_monitor_get_size(GdkWindow *window, gint *w, gint *h)
+#if GTK_CHECK_VERSION(3, 90, 0)
+typedef GdkSurface GhbSurface;
+typedef GdkSurfaceHints GhbSurfaceHints;
+
+static inline GhbSurface * ghb_widget_get_surface(GtkWidget * widget)
+{
+ return gtk_widget_get_surface(widget);
+}
+
+static inline GdkMonitor *
+ghb_display_get_monitor_at_surface(GdkDisplay * display, GhbSurface * surface)
+{
+ return gdk_display_get_monitor_at_surface(display, surface);
+}
+
+static inline void
+ghb_surface_set_geometry_hints(GhbSurface * surface,
+ const GdkGeometry * geometry,
+ GhbSurfaceHints geom_mask)
+{
+ gdk_surface_set_geometry_hints(surface, geometry, geom_mask);
+}
+#else
+typedef GdkWindow GhbSurface;
+typedef GdkWindowHints GhbSurfaceHints;
+
+static inline GhbSurface * ghb_widget_get_surface(GtkWidget * widget)
+{
+ return gtk_widget_get_window(widget);
+}
+
+static inline GdkMonitor *
+ghb_display_get_monitor_at_surface(GdkDisplay * display, GhbSurface * surface)
+{
+ return gdk_display_get_monitor_at_window(display, surface);
+}
+
+static inline void
+ghb_surface_set_geometry_hints(GhbSurface * surface,
+ const GdkGeometry * geometry,
+ GhbSurfaceHints geom_mask)
+{
+ gdk_window_set_geometry_hints(surface, geometry, geom_mask);
+}
+#endif
+
+static inline void ghb_monitor_get_size(GtkWidget *widget, gint *w, gint *h)
{
*w = *h = 0;
#if GTK_CHECK_VERSION(3, 22, 0)
- if (window != NULL)
+ GdkDisplay * display = gtk_widget_get_display(widget);
+ GhbSurface * surface = ghb_widget_get_surface(widget);
+ if (surface != NULL && display != NULL)
{
- GdkMonitor *mm;
- GdkDisplay *dd;
+ GdkMonitor * monitor;
- dd = gdk_display_get_default();
- if (dd != NULL)
+ monitor = ghb_display_get_monitor_at_surface(display, surface);
+ if (monitor != NULL)
{
- mm = gdk_display_get_monitor_at_window(dd, window);
- if (mm != NULL)
- {
- GdkRectangle rr;
-
- gdk_monitor_get_geometry(mm, &rr);
- *w = rr.width;
- *h = rr.height;
- }
+ GdkRectangle rect;
+
+ gdk_monitor_get_geometry(monitor, &rect);
+ *w = rect.width;
+ *h = rect.height;
}
}
#else
@@ -235,23 +306,138 @@ static inline gboolean ghb_strv_contains(const char ** strv, const char * str)
#endif
}
-#if !GTK_CHECK_VERSION(3, 10, 0)
-#define gtk_image_set_from_icon_name gtk_image_set_from_stock
-#define GHB_PLAY_ICON "gtk-media-play"
-#define GHB_PAUSE_ICON "gtk-media-pause"
+#if GTK_CHECK_VERSION(3, 90, 0)
+static inline const gchar * ghb_entry_get_text(GtkEntry * entry)
+{
+ GtkEntryBuffer * buf = gtk_entry_get_buffer(entry);
+ if (buf != NULL)
+ {
+ return gtk_entry_buffer_get_text(buf);
+ }
+ return NULL;
+}
+
+static inline void ghb_entry_set_text(GtkEntry * entry, const gchar * text)
+{
+ GtkEntryBuffer * buf = gtk_entry_get_buffer(entry);
+ if (buf == NULL)
+ {
+ buf = gtk_entry_buffer_new(text, -1);
+ gtk_entry_set_buffer(entry, buf);
+ }
+ else
+ {
+ return gtk_entry_buffer_set_text(buf, text, -1);
+ }
+}
#else
-#define GHB_PLAY_ICON "media-playback-start"
-#define GHB_PAUSE_ICON "media-playback-pause"
+static inline const gchar * ghb_entry_get_text(GtkEntry * entry)
+{
+ return gtk_entry_get_text(entry);
+}
+
+static inline void ghb_entry_set_text(GtkEntry * entry, const gchar * text)
+{
+ return gtk_entry_set_text(entry, text);
+}
#endif
-#if !GTK_CHECK_VERSION(3, 10, 0)
-#define GHB_STOCK_OPEN GTK_STOCK_OPEN
-#define GHB_STOCK_CANCEL GTK_STOCK_CANCEL
-#define GHB_STOCK_SAVE GTK_STOCK_SAVE
+#if GTK_CHECK_VERSION(3, 90, 0)
+static inline void
+ghb_image_set_from_icon_name(GtkImage * image, const gchar * name,
+ GtkIconSize size)
+{
+ gtk_image_set_from_icon_name(image, name);
+ gtk_image_set_icon_size(image, size);
+}
+
+static inline GtkWidget *
+ghb_image_new_from_icon_name(const gchar * name, GtkIconSize size)
+{
+ GtkWidget * image;
+
+ image = gtk_image_new_from_icon_name(name);
+ gtk_image_set_icon_size(GTK_IMAGE(image), size);
+
+ return image;
+}
+
+static inline GtkWidget *
+ghb_button_new_from_icon_name(const gchar * name)
+{
+ return gtk_button_new_from_icon_name(name);
+}
+
+static inline GtkWidget *
+ghb_scale_button_new(gdouble min, gdouble max, gdouble step,
+ const gchar ** icons)
+{
+ return gtk_scale_button_new(min, max, step, icons);
+}
#else
-#define GHB_STOCK_OPEN "_Open"
-#define GHB_STOCK_CANCEL "_Cancel"
-#define GHB_STOCK_SAVE "_Save"
+static inline void
+ghb_image_set_from_icon_name(GtkImage * image, const gchar * name,
+ GtkIconSize size)
+{
+ gtk_image_set_from_icon_name(image, name, size);
+}
+
+static inline GtkWidget *
+ghb_image_new_from_icon_name(const gchar * name, GtkIconSize size)
+{
+ return gtk_image_new_from_icon_name(name, size);
+}
+
+static inline GtkWidget *
+ghb_button_new_from_icon_name(const gchar * name)
+{
+ return gtk_button_new_from_icon_name(name, GHB_ICON_SIZE_BUTTON);
+}
+
+static inline GtkWidget *
+ghb_scale_button_new(gdouble min, gdouble max, gdouble step,
+ const gchar ** icons)
+{
+ return gtk_scale_button_new(GHB_ICON_SIZE_BUTTON, min, max, step, icons);
+}
+#endif
+
+#if GTK_CHECK_VERSION(3, 90, 0)
+static inline void ghb_drag_status(GdkDrop * ctx, GdkDragAction action,
+ guint32 time)
+{
+ gdk_drop_status(ctx, action);
+}
+#else
+static inline void ghb_drag_status(GdkDragContext * ctx, GdkDragAction action,
+ guint32 time)
+{
+ gdk_drag_status(ctx, action, time);
+}
+#endif
+
+#if GTK_CHECK_VERSION(3, 90, 0)
+static inline void ghb_entry_set_width_chars(GtkEntry * entry, gint n_chars)
+{
+ gtk_editable_set_width_chars(GTK_EDITABLE(entry), n_chars);
+}
+#else
+static inline void ghb_entry_set_width_chars(GtkEntry * entry, gint n_chars)
+{
+ gtk_entry_set_width_chars(entry, n_chars);
+}
+#endif
+
+#if GTK_CHECK_VERSION(3, 90, 0)
+static inline GdkAtom ghb_atom_string(const char * str)
+{
+ return g_intern_static_string(str);
+}
+#else
+static inline GdkAtom ghb_atom_string(const char * str)
+{
+ return gdk_atom_intern_static_string(str);
+}
#endif
#endif // _GHB_COMPAT_H_