[gnome-builder/wip/gtk4-port] gui: port headers to GTK 4



commit cf948418b8ed7fa0f0ffc9e12e1a8a0868c2818d
Author: Christian Hergert <chergert redhat com>
Date:   Fri Sep 24 14:10:13 2021 -0700

    gui: port headers to GTK 4
    
    This doesn't actually port the widgets, that would be too difficult to get
    right at this point. It just gets the headers prepared so that we can
    start compiling some things.

 src/libide/gui/ide-header-bar.h | 27 +++++++++---------
 src/libide/gui/ide-page.c       |  7 +++--
 src/libide/gui/ide-page.h       | 61 +++++++++++++++++++++-------------------
 src/libide/gui/ide-surface.c    | 54 ++++++-----------------------------
 src/libide/gui/ide-surface.h    | 54 +++++++++++++++++++----------------
 src/libide/gui/ide-workbench.h  |  4 +--
 src/libide/gui/ide-workspace.h  | 62 ++++++++++++++++++++++-------------------
 7 files changed, 125 insertions(+), 144 deletions(-)
---
diff --git a/src/libide/gui/ide-header-bar.h b/src/libide/gui/ide-header-bar.h
index f02cb14fd..822ad38a9 100644
--- a/src/libide/gui/ide-header-bar.h
+++ b/src/libide/gui/ide-header-bar.h
@@ -24,43 +24,44 @@
 # error "Only <libide-gui.h> can be included directly."
 #endif
 
-#include <gtk/gtk.h>
+#include <adwaita.h>
+
 #include <libide-core.h>
 
 G_BEGIN_DECLS
 
 #define IDE_TYPE_HEADER_BAR (ide_header_bar_get_type())
 
-IDE_AVAILABLE_IN_3_32
-G_DECLARE_DERIVABLE_TYPE (IdeHeaderBar, ide_header_bar, IDE, HEADER_BAR, GtkHeaderBar)
+IDE_AVAILABLE_IN_ALL
+G_DECLARE_DERIVABLE_TYPE (IdeHeaderBar, ide_header_bar, IDE, HEADER_BAR, GtkWidget)
 
 struct _IdeHeaderBarClass
 {
-  GtkHeaderBarClass parent_class;
+  GtkWidgetClass parent_class;
 
   /*< private >*/
-  gpointer _reserved[16];
+  gpointer _reserved[8];
 };
 
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 GtkWidget   *ide_header_bar_new                        (void);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 void         ide_header_bar_add_primary                (IdeHeaderBar *self,
                                                         GtkWidget    *widget);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 void         ide_header_bar_add_center_left            (IdeHeaderBar *self,
                                                         GtkWidget    *widget);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 void         ide_header_bar_add_secondary              (IdeHeaderBar *self,
                                                         GtkWidget    *widget);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 const gchar *ide_header_bar_get_menu_id                (IdeHeaderBar *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 void         ide_header_bar_set_menu_id                (IdeHeaderBar *self,
                                                         const gchar  *menu_id);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 gboolean     ide_header_bar_get_show_fullscreen_button (IdeHeaderBar *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 void         ide_header_bar_set_show_fullscreen_button (IdeHeaderBar *self,
                                                         gboolean      show_fullscreen_button);
 
diff --git a/src/libide/gui/ide-page.c b/src/libide/gui/ide-page.c
index a52bfd89b..dd083db23 100644
--- a/src/libide/gui/ide-page.c
+++ b/src/libide/gui/ide-page.c
@@ -22,9 +22,10 @@
 
 #include "config.h"
 
-#include <libide-threading.h>
 #include <string.h>
 
+#include <libide-threading.h>
+
 #include "ide-gui-global.h"
 #include "ide-gui-private.h"
 #include "ide-page.h"
@@ -68,7 +69,7 @@ enum {
   N_SIGNALS
 };
 
-G_DEFINE_TYPE_WITH_PRIVATE (IdePage, ide_page, GTK_TYPE_BOX)
+G_DEFINE_TYPE_WITH_PRIVATE (IdePage, ide_page, GTK_TYPE_WIDGET)
 
 static GParamSpec *properties [N_PROPS];
 static guint signals [N_SIGNALS];
@@ -411,6 +412,8 @@ ide_page_class_init (IdePageClass *klass)
                   G_STRUCT_OFFSET (IdePageClass, create_split),
                   g_signal_accumulator_first_wins, NULL,
                   NULL, IDE_TYPE_PAGE, 0);
+
+  gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BOX_LAYOUT);
 }
 
 static void
diff --git a/src/libide/gui/ide-page.h b/src/libide/gui/ide-page.h
index 90a29cf7f..0a9dfe5c1 100644
--- a/src/libide/gui/ide-page.h
+++ b/src/libide/gui/ide-page.h
@@ -31,12 +31,15 @@ G_BEGIN_DECLS
 
 #define IDE_TYPE_PAGE (ide_page_get_type())
 
-IDE_AVAILABLE_IN_3_32
-G_DECLARE_DERIVABLE_TYPE (IdePage, ide_page, IDE, PAGE, GtkBox)
+IDE_AVAILABLE_IN_ALL
+G_DECLARE_DERIVABLE_TYPE (IdePage, ide_page, IDE, PAGE, GtkWidget)
+
+typedef void (*IdePageCallback) (IdePage  *page,
+                                 gpointer  user_data);
 
 struct _IdePageClass
 {
-  GtkBoxClass parent_class;
+  GtkWidgetClass parent_class;
 
   void           (*agree_to_close_async)  (IdePage              *self,
                                            GCancellable         *cancellable,
@@ -49,74 +52,74 @@ struct _IdePageClass
   GFile         *(*get_file_or_directory) (IdePage              *self);
 
   /*< private >*/
-  gpointer _reserved[16];
+  gpointer _reserved[8];
 };
 
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 GtkWidget     *ide_page_new                   (void);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 gboolean       ide_page_get_can_split         (IdePage              *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 void           ide_page_set_can_split         (IdePage              *self,
                                                gboolean              can_split);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 IdePage       *ide_page_create_split          (IdePage              *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 const gchar   *ide_page_get_icon_name         (IdePage              *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 void           ide_page_set_icon_name         (IdePage              *self,
                                                const gchar          *icon_name);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 GIcon         *ide_page_get_icon              (IdePage              *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 void           ide_page_set_icon              (IdePage              *self,
                                                GIcon                *icon);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 gboolean       ide_page_get_failed            (IdePage              *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 void           ide_page_set_failed            (IdePage              *self,
                                                gboolean              failed);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 const gchar   *ide_page_get_menu_id           (IdePage              *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 void           ide_page_set_menu_id           (IdePage              *self,
                                                const gchar          *menu_id);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 gboolean       ide_page_get_modified          (IdePage              *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 void           ide_page_set_modified          (IdePage              *self,
                                                gboolean              modified);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 const gchar   *ide_page_get_title             (IdePage              *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 void           ide_page_set_title             (IdePage              *self,
                                                const gchar          *title);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 const GdkRGBA *ide_page_get_primary_color_bg  (IdePage              *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 void           ide_page_set_primary_color_bg  (IdePage              *self,
                                                const GdkRGBA        *primary_color_bg);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 const GdkRGBA *ide_page_get_primary_color_fg  (IdePage              *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 void           ide_page_set_primary_color_fg  (IdePage              *self,
                                                const GdkRGBA        *primary_color_fg);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 void           ide_page_agree_to_close_async  (IdePage              *self,
                                                GCancellable         *cancellable,
                                                GAsyncReadyCallback   callback,
                                                gpointer              user_data);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 gboolean       ide_page_agree_to_close_finish (IdePage              *self,
                                                GAsyncResult         *result,
                                                GError              **error);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 void           ide_page_mark_used             (IdePage              *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 void           ide_page_report_error          (IdePage              *self,
                                                const gchar          *format,
                                                ...) G_GNUC_PRINTF (2, 3);
-IDE_AVAILABLE_IN_3_40
+IDE_AVAILABLE_IN_ALL
 GFile         *ide_page_get_file_or_directory (IdePage              *self);
 
 G_END_DECLS
diff --git a/src/libide/gui/ide-surface.c b/src/libide/gui/ide-surface.c
index 43224679c..89fee1c56 100644
--- a/src/libide/gui/ide-surface.c
+++ b/src/libide/gui/ide-surface.c
@@ -27,8 +27,8 @@
 
 typedef struct
 {
-  gchar *icon_name;
-  gchar *title;
+  char *icon_name;
+  char *title;
 } IdeSurfacePrivate;
 
 enum {
@@ -38,11 +38,7 @@ enum {
   N_PROPS
 };
 
-static void dock_item_iface_init (DzlDockItemInterface *iface);
-
-G_DEFINE_TYPE_WITH_CODE (IdeSurface, ide_surface, DZL_TYPE_DOCK_BIN,
-                         G_ADD_PRIVATE (IdeSurface)
-                         G_IMPLEMENT_INTERFACE (DZL_TYPE_DOCK_ITEM, dock_item_iface_init))
+G_DEFINE_TYPE_WITH_PRIVATE (IdeSurface, ide_surface, GTK_TYPE_WIDGET)
 
 static GParamSpec *properties [N_PROPS];
 
@@ -65,15 +61,16 @@ ide_surface_get_property (GObject    *object,
                           GParamSpec *pspec)
 {
   IdeSurface *self = IDE_SURFACE (object);
+  IdeSurfacePrivate *priv = ide_surface_get_instance_private (self);
 
   switch (prop_id)
     {
     case PROP_ICON_NAME:
-      g_value_set_string (value, dzl_dock_item_get_icon_name (DZL_DOCK_ITEM (self)));
+      g_value_set_string (value, priv->icon_name);
       break;
 
     case PROP_TITLE:
-      g_value_set_string (value, dzl_dock_item_get_title (DZL_DOCK_ITEM (self)));
+      g_value_set_string (value, priv->title);
       break;
 
     default:
@@ -145,8 +142,6 @@ ide_surface_init (IdeSurface *self)
  * and the user can switch between them.
  *
  * Returns: (transfer full): an #IdeSurface or %NULL
- *
- * Since: 3.32
  */
 GtkWidget *
 ide_surface_new (void)
@@ -193,13 +188,11 @@ ide_surface_set_title (IdeSurface  *self,
  * @user_data: closure data for @callback
  *
  * Calls @callback for every page found within the surface @self.
- *
- * Since: 3.32
  */
 void
-ide_surface_foreach_page (IdeSurface  *self,
-                          GtkCallback  callback,
-                          gpointer     user_data)
+ide_surface_foreach_page (IdeSurface      *self,
+                          IdePageCallback  callback,
+                          gpointer         user_data)
 {
   g_return_if_fail (IDE_IS_SURFACE (self));
   g_return_if_fail (callback != NULL);
@@ -208,35 +201,6 @@ ide_surface_foreach_page (IdeSurface  *self,
     IDE_SURFACE_GET_CLASS (self)->foreach_page (self, callback, user_data);
 }
 
-static gchar *
-ide_surface_real_get_icon_name (DzlDockItem *item)
-{
-  IdeSurface *self = (IdeSurface *)item;
-  IdeSurfacePrivate *priv = ide_surface_get_instance_private (self);
-
-  g_return_val_if_fail (IDE_IS_SURFACE (self), NULL);
-
-  return g_strdup (priv->icon_name);
-}
-
-static gchar *
-ide_surface_real_get_title (DzlDockItem *item)
-{
-  IdeSurface *self = (IdeSurface *)item;
-  IdeSurfacePrivate *priv = ide_surface_get_instance_private (self);
-
-  g_return_val_if_fail (IDE_IS_SURFACE (self), NULL);
-
-  return g_strdup (priv->title);
-}
-
-static void
-dock_item_iface_init (DzlDockItemInterface *iface)
-{
-  iface->get_icon_name = ide_surface_real_get_icon_name;
-  iface->get_title = ide_surface_real_get_title;
-}
-
 gboolean
 ide_surface_agree_to_shutdown (IdeSurface *self)
 {
diff --git a/src/libide/gui/ide-surface.h b/src/libide/gui/ide-surface.h
index 2be97c69f..c81c9de98 100644
--- a/src/libide/gui/ide-surface.h
+++ b/src/libide/gui/ide-surface.h
@@ -24,44 +24,50 @@
 # error "Only <libide-gui.h> can be included directly."
 #endif
 
-#include <dazzle.h>
+#include <gtk/gtk.h>
+
 #include <libide-core.h>
 
+#include "ide-page.h"
+
 G_BEGIN_DECLS
 
 #define IDE_TYPE_SURFACE (ide_surface_get_type())
 
-IDE_AVAILABLE_IN_3_32
-G_DECLARE_DERIVABLE_TYPE (IdeSurface, ide_surface, IDE, SURFACE, DzlDockBin)
+IDE_AVAILABLE_IN_ALL
+G_DECLARE_DERIVABLE_TYPE (IdeSurface, ide_surface, IDE, SURFACE, GtkWidget)
+
+typedef void (*IdeSurfaceCallback) (IdeSurface *surface,
+                                    gpointer    user_data);
 
 struct _IdeSurfaceClass
 {
-  DzlDockBinClass parent_class;
+  GtkWidget parent_class;
 
-  void     (*foreach_page)        (IdeSurface  *self,
-                                   GtkCallback  callback,
-                                   gpointer     user_data);
-  gboolean (*agree_to_shutdown)   (IdeSurface  *self);
-  void     (*set_fullscreen)      (IdeSurface  *self,
-                                   gboolean     fullscreen);
+  void     (*foreach_page)        (IdeSurface      *self,
+                                   IdePageCallback  callback,
+                                   gpointer         user_data);
+  gboolean (*agree_to_shutdown)   (IdeSurface      *self);
+  void     (*set_fullscreen)      (IdeSurface      *self,
+                                   gboolean         fullscreen);
 
   /*< private >*/
-  gpointer _reserved[16];
+  gpointer _reserved[8];
 };
 
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 GtkWidget *ide_surface_new               (void);
-IDE_AVAILABLE_IN_3_32
-void       ide_surface_set_icon_name     (IdeSurface  *self,
-                                          const gchar *icon_name);
-IDE_AVAILABLE_IN_3_32
-void       ide_surface_set_title         (IdeSurface  *self,
-                                          const gchar *title);
-IDE_AVAILABLE_IN_3_32
-void       ide_surface_foreach_page      (IdeSurface  *self,
-                                          GtkCallback  callback,
-                                          gpointer     user_data);
-IDE_AVAILABLE_IN_3_32
-gboolean   ide_surface_agree_to_shutdown (IdeSurface  *self);
+IDE_AVAILABLE_IN_ALL
+void       ide_surface_set_icon_name     (IdeSurface      *self,
+                                          const gchar     *icon_name);
+IDE_AVAILABLE_IN_ALL
+void       ide_surface_set_title         (IdeSurface      *self,
+                                          const gchar     *title);
+IDE_AVAILABLE_IN_ALL
+void       ide_surface_foreach_page      (IdeSurface      *self,
+                                          IdePageCallback  callback,
+                                          gpointer         user_data);
+IDE_AVAILABLE_IN_ALL
+gboolean   ide_surface_agree_to_shutdown (IdeSurface      *self);
 
 G_END_DECLS
diff --git a/src/libide/gui/ide-workbench.h b/src/libide/gui/ide-workbench.h
index 3014a8ab0..abadf871d 100644
--- a/src/libide/gui/ide-workbench.h
+++ b/src/libide/gui/ide-workbench.h
@@ -73,11 +73,11 @@ void             ide_workbench_focus_workspace       (IdeWorkbench         *self
                                                       IdeWorkspace         *workspace);
 IDE_AVAILABLE_IN_3_32
 void             ide_workbench_foreach_workspace     (IdeWorkbench         *self,
-                                                      GtkCallback           callback,
+                                                      IdeWorkspaceCallback  callback,
                                                       gpointer              user_data);
 IDE_AVAILABLE_IN_3_32
 void             ide_workbench_foreach_page          (IdeWorkbench         *self,
-                                                      GtkCallback           callback,
+                                                      IdePageCallback       callback,
                                                       gpointer              user_data);
 IDE_AVAILABLE_IN_3_32
 void             ide_workbench_load_project_async    (IdeWorkbench         *self,
diff --git a/src/libide/gui/ide-workspace.h b/src/libide/gui/ide-workspace.h
index 9e899c9d0..5b0fcf1a9 100644
--- a/src/libide/gui/ide-workspace.h
+++ b/src/libide/gui/ide-workspace.h
@@ -24,7 +24,8 @@
 # error "Only <libide-gui.h> can be included directly."
 #endif
 
-#include <dazzle.h>
+#include <adwaita.h>
+
 #include <libide-core.h>
 #include <libide-projects.h>
 
@@ -36,61 +37,64 @@ G_BEGIN_DECLS
 
 #define IDE_TYPE_WORKSPACE (ide_workspace_get_type())
 
-IDE_AVAILABLE_IN_3_32
-G_DECLARE_DERIVABLE_TYPE (IdeWorkspace, ide_workspace, IDE, WORKSPACE, DzlApplicationWindow)
+IDE_AVAILABLE_IN_ALL
+G_DECLARE_DERIVABLE_TYPE (IdeWorkspace, ide_workspace, IDE, WORKSPACE, AdwApplicationWindow)
+
+typedef void (*IdeWorkspaceCallback) (IdeWorkspace *workspace,
+                                      gpointer      user_data);
 
 struct _IdeWorkspaceClass
 {
-  DzlApplicationWindowClass parent_class;
+  AdwApplicationWindowClass parent_class;
 
   const gchar *kind;
 
-  void (*context_set)  (IdeWorkspace *self,
-                        IdeContext   *context);
-  void (*foreach_page) (IdeWorkspace *self,
-                        GtkCallback   callback,
-                        gpointer      user_data);
-  void (*surface_set)  (IdeWorkspace *self,
-                        IdeSurface   *surface);
+  void (*context_set)  (IdeWorkspace    *self,
+                        IdeContext      *context);
+  void (*foreach_page) (IdeWorkspace    *self,
+                        IdePageCallback  callback,
+                        gpointer         user_data);
+  void (*surface_set)  (IdeWorkspace    *self,
+                        IdeSurface      *surface);
 
   /*< private >*/
-  gpointer _reserved[32];
+  gpointer _reserved[8];
 };
 
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 void          ide_workspace_class_set_kind           (IdeWorkspaceClass *klass,
                                                       const gchar       *kind);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 IdeHeaderBar *ide_workspace_get_header_bar           (IdeWorkspace      *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 IdeContext   *ide_workspace_get_context              (IdeWorkspace      *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 GCancellable *ide_workspace_get_cancellable          (IdeWorkspace      *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 void          ide_workspace_foreach_page             (IdeWorkspace      *self,
-                                                      GtkCallback        callback,
-                                                      gpointer           user_data);
-IDE_AVAILABLE_IN_3_32
-void          ide_workspace_foreach_surface          (IdeWorkspace      *self,
-                                                      GtkCallback        callback,
+                                                      IdePageCallback    callback,
                                                       gpointer           user_data);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
+void          ide_workspace_foreach_surface          (IdeWorkspace       *self,
+                                                      IdeSurfaceCallback  callback,
+                                                      gpointer            user_data);
+IDE_AVAILABLE_IN_ALL
 void          ide_workspace_add_surface              (IdeWorkspace      *self,
                                                       IdeSurface        *surface);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 IdeSurface   *ide_workspace_get_surface_by_name      (IdeWorkspace      *self,
                                                       const gchar       *name);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 void          ide_workspace_set_visible_surface_name (IdeWorkspace      *self,
                                                       const gchar       *visible_surface_name);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 IdeSurface   *ide_workspace_get_visible_surface      (IdeWorkspace      *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 void          ide_workspace_set_visible_surface      (IdeWorkspace      *self,
                                                       IdeSurface        *surface);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 GtkOverlay   *ide_workspace_get_overlay              (IdeWorkspace      *self);
-IDE_AVAILABLE_IN_3_32
+IDE_AVAILABLE_IN_ALL
 IdePage      *ide_workspace_get_most_recent_page     (IdeWorkspace      *self);
 
 G_END_DECLS


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]