[gtksourceview/wip/chergert/gsv-gtk4: 183/192] gtk: track removal of GtkContainer
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/gsv-gtk4: 183/192] gtk: track removal of GtkContainer
- Date: Fri, 7 Aug 2020 18:31:11 +0000 (UTC)
commit 2de59de6d199756a24dc07cdb01284a104bb8cfa
Author: Christian Hergert <chergert redhat com>
Date: Tue May 12 13:33:22 2020 -0700
gtk: track removal of GtkContainer
gtksourceview/gtksourcegutter.c | 69 +++--------------------
gtksourceview/gtksourcegutter.h | 5 +-
gtksourceview/gtksourcestyleschemechooserbutton.c | 4 +-
gtksourceview/gtksourcestyleschemechooserwidget.c | 32 ++++-------
tests/test-search.c | 4 +-
tests/test-space-drawing.c | 16 +++---
tests/test-widget.c | 60 ++++++++++++--------
7 files changed, 74 insertions(+), 116 deletions(-)
---
diff --git a/gtksourceview/gtksourcegutter.c b/gtksourceview/gtksourcegutter.c
index fcedee35f..456f24984 100644
--- a/gtksourceview/gtksourcegutter.c
+++ b/gtksourceview/gtksourcegutter.c
@@ -69,7 +69,7 @@ typedef struct
struct _GtkSourceGutter
{
- GtkContainer parent_instance;
+ GtkWidget parent_instance;
GtkSourceView *view;
GList *renderers;
@@ -84,12 +84,8 @@ struct _GtkSourceGutter
guint is_drawing : 1;
};
-G_DEFINE_TYPE (GtkSourceGutter, gtk_source_gutter, GTK_TYPE_CONTAINER)
+G_DEFINE_TYPE (GtkSourceGutter, gtk_source_gutter, GTK_TYPE_WIDGET)
-static void gtk_source_gutter_add (GtkContainer *container,
- GtkWidget *widget);
-static void gtk_source_gutter_remove (GtkContainer *container,
- GtkWidget *widget);
static void on_gutter_pressed_cb (GtkSourceGutter *gutter,
gint n_presses,
gdouble x,
@@ -329,24 +325,6 @@ gtk_source_gutter_measure (GtkWidget *widget,
*natural_baseline = -1;
}
-static void
-gtk_source_gutter_forall (GtkContainer *container,
- GtkCallback callback,
- gpointer callback_data)
-{
- GtkSourceGutter *gutter = GTK_SOURCE_GUTTER (container);
- const GList *list = gutter->renderers;
-
- while (list != NULL)
- {
- Renderer *renderer = list->data;
-
- list = list->next;
-
- callback (GTK_WIDGET (renderer->renderer), callback_data);
- }
-}
-
static void
gtk_source_gutter_set_property (GObject *object,
guint prop_id,
@@ -396,7 +374,6 @@ gtk_source_gutter_class_init (GtkSourceGutterClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
- GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
object_class->constructed = gtk_source_gutter_constructed;
object_class->get_property = gtk_source_gutter_get_property;
@@ -407,10 +384,6 @@ gtk_source_gutter_class_init (GtkSourceGutterClass *klass)
widget_class->size_allocate = gtk_source_gutter_size_allocate;
widget_class->snapshot = gtk_source_gutter_snapshot;
- container_class->forall = gtk_source_gutter_forall;
- container_class->add = gtk_source_gutter_add;
- container_class->remove = gtk_source_gutter_remove;
-
/**
* GtkSourceGutter:view:
*
@@ -608,43 +581,19 @@ renderer_find (GtkSourceGutter *gutter,
return FALSE;
}
-static void
-gtk_source_gutter_add (GtkContainer *container,
- GtkWidget *widget)
-{
- if (!GTK_SOURCE_IS_GUTTER_RENDERER (widget))
- {
- g_warning ("Cannot add %s to %s as it is not a GtkSourceGutterRenderer",
- G_OBJECT_TYPE_NAME (widget),
- G_OBJECT_TYPE_NAME (container));
- }
- else
- {
- gtk_source_gutter_insert (GTK_SOURCE_GUTTER (container),
- GTK_SOURCE_GUTTER_RENDERER (widget),
- 0);
- }
-}
-
-static void
-gtk_source_gutter_remove (GtkContainer *container,
- GtkWidget *widget)
+void
+gtk_source_gutter_remove (GtkSourceGutter *gutter,
+ GtkSourceGutterRenderer *renderer)
{
- GtkSourceGutterRenderer *renderer;
- GtkSourceGutter *gutter;
Renderer *ret;
GList *retlist;
- g_return_if_fail (GTK_SOURCE_IS_GUTTER (container));
- g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (widget));
-
- gutter = GTK_SOURCE_GUTTER (container);
- renderer = GTK_SOURCE_GUTTER_RENDERER (widget);
+ g_return_if_fail (GTK_SOURCE_IS_GUTTER (gutter));
+ g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
if (renderer_find (gutter, renderer, &ret, &retlist))
{
- gutter->renderers =
- g_list_delete_link (gutter->renderers, retlist);
+ gutter->renderers = g_list_delete_link (gutter->renderers, retlist);
gtk_widget_unparent (GTK_WIDGET (renderer));
renderer_free (ret);
gtk_widget_queue_resize (GTK_WIDGET (gutter));
@@ -652,7 +601,7 @@ gtk_source_gutter_remove (GtkContainer *container,
else
{
g_warning ("Failed to locate %s within %s",
- G_OBJECT_TYPE_NAME (widget),
+ G_OBJECT_TYPE_NAME (renderer),
G_OBJECT_TYPE_NAME (gutter));
}
}
diff --git a/gtksourceview/gtksourcegutter.h b/gtksourceview/gtksourcegutter.h
index d5f4f5e9f..bb27722b9 100644
--- a/gtksourceview/gtksourcegutter.h
+++ b/gtksourceview/gtksourcegutter.h
@@ -32,7 +32,7 @@ G_BEGIN_DECLS
#define GTK_SOURCE_TYPE_GUTTER (gtk_source_gutter_get_type())
GTK_SOURCE_AVAILABLE_IN_ALL
-G_DECLARE_FINAL_TYPE (GtkSourceGutter, gtk_source_gutter, GTK_SOURCE, GUTTER, GtkContainer)
+G_DECLARE_FINAL_TYPE (GtkSourceGutter, gtk_source_gutter, GTK_SOURCE, GUTTER, GtkWidget)
GTK_SOURCE_AVAILABLE_IN_3_24
GtkSourceView *gtk_source_gutter_get_view (GtkSourceGutter *gutter);
@@ -44,5 +44,8 @@ GTK_SOURCE_AVAILABLE_IN_ALL
void gtk_source_gutter_reorder (GtkSourceGutter *gutter,
GtkSourceGutterRenderer *renderer,
gint position);
+GTK_SOURCE_AVAILABLE_IN_ALL
+void gtk_source_gutter_remove (GtkSourceGutter *gutter,
+ GtkSourceGutterRenderer *renderer);
G_END_DECLS
diff --git a/gtksourceview/gtksourcestyleschemechooserbutton.c
b/gtksourceview/gtksourcestyleschemechooserbutton.c
index 1ea4633ae..55a059eaf 100644
--- a/gtksourceview/gtksourcestyleschemechooserbutton.c
+++ b/gtksourceview/gtksourcestyleschemechooserbutton.c
@@ -193,14 +193,14 @@ ensure_dialog (GtkSourceStyleSchemeChooserButton *button)
gtk_widget_set_hexpand (scrolled_window, TRUE);
gtk_widget_set_vexpand (scrolled_window, TRUE);
content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
- gtk_container_add (GTK_CONTAINER (content_area), scrolled_window);
+ gtk_box_append (GTK_BOX (content_area), scrolled_window);
priv->chooser = GTK_SOURCE_STYLE_SCHEME_CHOOSER_WIDGET (gtk_source_style_scheme_chooser_widget_new
());
gtk_widget_show (GTK_WIDGET (priv->chooser));
gtk_source_style_scheme_chooser_set_style_scheme (GTK_SOURCE_STYLE_SCHEME_CHOOSER (priv->chooser),
priv->scheme);
- gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET (priv->chooser));
+ gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (scrolled_window), GTK_WIDGET (priv->chooser));
if (GTK_IS_ROOT (parent) && GTK_IS_WINDOW (parent))
{
diff --git a/gtksourceview/gtksourcestyleschemechooserwidget.c
b/gtksourceview/gtksourcestyleschemechooserwidget.c
index efec119bf..10807efc0 100644
--- a/gtksourceview/gtksourcestyleschemechooserwidget.c
+++ b/gtksourceview/gtksourcestyleschemechooserwidget.c
@@ -162,7 +162,7 @@ make_row (GtkSourceStyleScheme *scheme,
g_free (text);
overlay = gtk_overlay_new ();
- gtk_container_add (GTK_CONTAINER (row), overlay);
+ gtk_list_box_row_set_child (GTK_LIST_BOX_ROW (row), overlay);
view = g_object_new (GTK_SOURCE_TYPE_VIEW,
"buffer", buffer,
@@ -177,7 +177,7 @@ make_row (GtkSourceStyleScheme *scheme,
"margin-start", 2,
"margin-end", 2,
NULL);
- gtk_container_add (GTK_CONTAINER (overlay), view);
+ gtk_overlay_set_child (GTK_OVERLAY (overlay), view);
label = g_object_new (GTK_TYPE_LABEL,
"can-focus", FALSE,
@@ -210,13 +210,6 @@ on_row_selected (GtkListBox *list_box,
}
}
-static void
-destroy_child_cb (GtkWidget *widget,
- gpointer data)
-{
- gtk_container_remove (GTK_CONTAINER (data), widget);
-}
-
static void
gtk_source_style_scheme_chooser_widget_populate (GtkSourceStyleSchemeChooserWidget *widget)
{
@@ -225,14 +218,16 @@ gtk_source_style_scheme_chooser_widget_populate (GtkSourceStyleSchemeChooserWidg
GtkSourceLanguage *lang;
GtkSourceStyleSchemeManager *manager;
const gchar * const *scheme_ids;
+ GtkWidget *child;
guint i;
gboolean row_selected = FALSE;
g_signal_handlers_block_by_func (priv->list_box, on_row_selected, widget);
- gtk_container_foreach (GTK_CONTAINER (priv->list_box),
- destroy_child_cb,
- NULL);
+ while ((child = gtk_widget_get_first_child (GTK_WIDGET (priv->list_box))))
+ {
+ gtk_list_box_remove (priv->list_box, child);
+ }
manager = gtk_source_style_scheme_manager_get_default ();
scheme_ids = gtk_source_style_scheme_manager_get_scheme_ids (manager);
@@ -318,14 +313,13 @@ gtk_source_style_scheme_chooser_widget_set_style_scheme (GtkSourceStyleSchemeCho
if (g_set_object (&priv->scheme, scheme))
{
- GList *children;
- GList *l;
+ GtkWidget *child;
- children = gtk_container_get_children (GTK_CONTAINER (priv->list_box));
-
- for (l = children; l != NULL; l = g_list_next (l))
+ for (child = gtk_widget_get_first_child (GTK_WIDGET (priv->list_box));
+ child != NULL;
+ child = gtk_widget_get_next_sibling (child))
{
- GtkListBoxRow *row = l->data;
+ GtkListBoxRow *row = GTK_LIST_BOX_ROW (child);
GtkSourceStyleScheme *cur;
cur = g_object_get_data (G_OBJECT (row), "scheme");
@@ -339,8 +333,6 @@ gtk_source_style_scheme_chooser_widget_set_style_scheme (GtkSourceStyleSchemeCho
}
}
- g_list_free (children);
-
g_object_notify (G_OBJECT (chooser), "style-scheme");
}
}
diff --git a/tests/test-search.c b/tests/test-search.c
index 4083c85d7..fce86eb0f 100644
--- a/tests/test-search.c
+++ b/tests/test-search.c
@@ -477,9 +477,9 @@ main (gint argc, gchar *argv[])
main_loop);
search = test_search_new ();
- gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (search));
+ gtk_window_set_child (GTK_WINDOW (window), GTK_WIDGET (search));
- gtk_widget_show (window);
+ gtk_window_present (GTK_WINDOW (window));
g_main_loop_run (main_loop);
diff --git a/tests/test-space-drawing.c b/tests/test-space-drawing.c
index 52e6412f5..441ccebcd 100644
--- a/tests/test-space-drawing.c
+++ b/tests/test-space-drawing.c
@@ -102,7 +102,7 @@ create_window (void)
panel_grid = gtk_grid_new ();
gtk_orientable_set_orientation (GTK_ORIENTABLE (panel_grid), GTK_ORIENTATION_VERTICAL);
- gtk_container_add (GTK_CONTAINER (hgrid), panel_grid);
+ gtk_grid_attach (GTK_GRID (hgrid), panel_grid, 0, 0, 1, 1);
gtk_grid_set_row_spacing (GTK_GRID (panel_grid), 6);
g_object_set (panel_grid,
@@ -113,21 +113,21 @@ create_window (void)
NULL);
matrix_checkbutton = gtk_check_button_new_with_label ("GtkSourceSpaceDrawer enable-matrix");
- gtk_container_add (GTK_CONTAINER (panel_grid), matrix_checkbutton);
+ gtk_grid_attach (GTK_GRID (panel_grid), matrix_checkbutton, 0, 0, 1, 1);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (matrix_checkbutton), TRUE);
g_object_bind_property (matrix_checkbutton, "active",
space_drawer, "enable-matrix",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
tag_set_checkbutton = gtk_check_button_new_with_label ("GtkSourceTag draw-spaces-set");
- gtk_container_add (GTK_CONTAINER (panel_grid), tag_set_checkbutton);
+ gtk_grid_attach (GTK_GRID (panel_grid), tag_set_checkbutton, 0, 1, 1, 1);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (tag_set_checkbutton), TRUE);
g_object_bind_property (tag_set_checkbutton, "active",
tag, "draw-spaces-set",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
tag_checkbutton = gtk_check_button_new_with_label ("GtkSourceTag draw-spaces");
- gtk_container_add (GTK_CONTAINER (panel_grid), tag_checkbutton);
+ gtk_grid_attach (GTK_GRID (panel_grid), tag_checkbutton, 0, 2, 1, 1);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (tag_checkbutton), FALSE);
g_object_bind_property (tag_checkbutton, "active",
tag, "draw-spaces",
@@ -135,16 +135,16 @@ create_window (void)
implicit_trailing_newline_checkbutton = gtk_check_button_new_with_label ("Implicit trailing newline");
gtk_widget_set_margin_top (implicit_trailing_newline_checkbutton, 12);
- gtk_container_add (GTK_CONTAINER (panel_grid), implicit_trailing_newline_checkbutton);
+ gtk_grid_attach (GTK_GRID (panel_grid), implicit_trailing_newline_checkbutton, 0, 3, 1, 1);
g_object_bind_property (buffer, "implicit-trailing-newline",
implicit_trailing_newline_checkbutton, "active",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
- gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET (view));
- gtk_container_add (GTK_CONTAINER (hgrid), scrolled_window);
+ gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (scrolled_window), GTK_WIDGET (view));
+ gtk_grid_attach (GTK_GRID (hgrid), scrolled_window, 1, 0, 1, 1);
- gtk_container_add (GTK_CONTAINER (window), hgrid);
+ gtk_window_set_child (GTK_WINDOW (window), hgrid);
gtk_window_present (GTK_WINDOW (window));
}
diff --git a/tests/test-widget.c b/tests/test-widget.c
index b2ca3b1e6..1380f8f14 100644
--- a/tests/test-widget.c
+++ b/tests/test-widget.c
@@ -71,6 +71,7 @@ G_DEFINE_TYPE_WITH_PRIVATE (TestWidget, test_widget, GTK_TYPE_GRID)
#define MARK_TYPE_2 "two"
static GMainLoop *main_loop;
+static gchar *last_dir;
static void
remove_all_marks (GtkSourceBuffer *buffer)
@@ -462,13 +463,41 @@ forward_string_clicked_cb (TestWidget *self)
gtk_widget_grab_focus (GTK_WIDGET (self->priv->view));
}
+static void
+on_chooser_response_cb (TestWidget *self,
+ gint response,
+ GtkFileChooserDialog *chooser)
+{
+ g_assert (TEST_IS_WIDGET (self));
+ g_assert (GTK_IS_FILE_CHOOSER_DIALOG (chooser));
+
+ if (response == GTK_RESPONSE_OK)
+ {
+ GFile *folder;
+ GFile *file;
+
+ file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (chooser));
+ folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (chooser));
+
+ if (file != NULL && folder != NULL)
+ {
+ g_free (last_dir);
+ last_dir = g_file_get_path (folder);
+ open_file (self, file);
+ }
+
+ g_clear_object (&folder);
+ g_clear_object (&file);
+ }
+
+ gtk_window_destroy (GTK_WINDOW (chooser));
+}
+
static void
open_button_clicked_cb (TestWidget *self)
{
GtkWidget *main_window;
GtkWidget *chooser;
- gint response;
- static gchar *last_dir;
main_window = GTK_WIDGET (gtk_widget_get_root (GTK_WIDGET (self->priv->view)));
@@ -493,28 +522,13 @@ open_button_clicked_cb (TestWidget *self)
g_object_unref (folder);
}
- response = gtk_dialog_run (GTK_DIALOG (chooser));
-
- if (response == GTK_RESPONSE_OK)
- {
- GFile *folder;
- GFile *file;
-
- file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (chooser));
- folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (chooser));
-
- if (file != NULL && folder != NULL)
- {
- g_free (last_dir);
- last_dir = g_file_get_path (folder);
- open_file (self, file);
- }
+ g_signal_connect_object (chooser,
+ "response",
+ G_CALLBACK (on_chooser_response_cb),
+ self,
+ G_CONNECT_SWAPPED);
- g_clear_object (&folder);
- g_clear_object (&file);
- }
-
- gtk_window_destroy (GTK_WINDOW (chooser));
+ gtk_window_present (GTK_WINDOW (chooser));
}
#define NON_BLOCKING_PAGINATION
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]