[gtksourceview/wip/chergert/gsv-gtk4: 169/175] track gtk_widget_destroy() and container changes in GTK
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/gsv-gtk4: 169/175] track gtk_widget_destroy() and container changes in GTK
- Date: Thu, 25 Jun 2020 19:57:29 +0000 (UTC)
commit 32e9388be36d9826f8eece2423a66ef98bdbd0ff
Author: Christian Hergert <chergert redhat com>
Date: Mon May 11 13:40:35 2020 -0700
track gtk_widget_destroy() and container changes in GTK
gtksourceview/gtksourcecompletion.c | 17 +++++------------
gtksourceview/gtksourcecompletioninfo.c | 6 +++---
gtksourceview/gtksourcemap.c | 12 +++++-------
gtksourceview/gtksourcestyleschemechooserwidget.c | 16 +++++++++-------
gtksourceview/gtksourcestyleschemechooserwidget.h | 4 ++--
gtksourceview/gtksourcestyleschemechooserwidget.ui | 11 +++++++++++
gtksourceview/gtksourceview.gresource.xml | 1 +
tests/test-widget.c | 4 ++--
tests/test-widget.ui | 4 ++--
testsuite/test-printcompositor.c | 4 ++--
10 files changed, 42 insertions(+), 37 deletions(-)
---
diff --git a/gtksourceview/gtksourcecompletion.c b/gtksourceview/gtksourcecompletion.c
index f3e7147a..0fcc1d88 100644
--- a/gtksourceview/gtksourcecompletion.c
+++ b/gtksourceview/gtksourcecompletion.c
@@ -497,19 +497,12 @@ static void
set_info_widget (GtkSourceCompletion *completion,
GtkWidget *new_widget)
{
- GtkWidget *cur_widget = gtk_bin_get_child (GTK_BIN (completion->info_window));
+ GtkWidget *cur_widget = gtk_window_get_child (GTK_WINDOW (completion->info_window));
- if (cur_widget == new_widget)
+ if (cur_widget != new_widget)
{
- return;
+ gtk_window_set_child (GTK_WINDOW (completion->info_window), new_widget);
}
-
- if (cur_widget != NULL)
- {
- gtk_container_remove (GTK_CONTAINER (completion->info_window), cur_widget);
- }
-
- gtk_container_add (GTK_CONTAINER (completion->info_window), new_widget);
}
static void
@@ -1641,13 +1634,13 @@ gtk_source_completion_dispose (GObject *object)
if (completion->info_window != NULL)
{
- gtk_widget_destroy (GTK_WIDGET (completion->info_window));
+ gtk_window_destroy (GTK_WINDOW (completion->info_window));
completion->info_window = NULL;
}
if (completion->main_window != NULL)
{
- gtk_widget_destroy (GTK_WIDGET (completion->main_window));
+ gtk_window_destroy (GTK_WINDOW (completion->main_window));
completion->main_window = NULL;
}
diff --git a/gtksourceview/gtksourcecompletioninfo.c b/gtksourceview/gtksourcecompletioninfo.c
index baffb233..ffe01863 100644
--- a/gtksourceview/gtksourcecompletioninfo.c
+++ b/gtksourceview/gtksourcecompletioninfo.c
@@ -28,7 +28,7 @@
* current completion proposal.
*
* The info window has always the same size as the natural size of its child
- * widget, added with gtk_container_add(). If you want a fixed size instead, a
+ * widget, added with gtk_widget_set_child(). If you want a fixed size instead, a
* possibility is to use a scrolled window, as the following example
* demonstrates.
*
@@ -40,8 +40,8 @@
* GtkWidget *scrolled_window = gtk_scrolled_window_new (NULL, NULL);
*
* gtk_widget_set_size_request (scrolled_window, 300, 200);
- * gtk_container_add (GTK_CONTAINER (scrolled_window), your_widget);
- * gtk_container_add (GTK_CONTAINER (info), scrolled_window);
+ * gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (scrolled_window), your_widget);
+ * gtk_window_set_child (GTK_WINDOW (info), scrolled_window);
* </programlisting>
* </example>
*/
diff --git a/gtksourceview/gtksourcemap.c b/gtksourceview/gtksourcemap.c
index 8379a195..b6ac7c83 100644
--- a/gtksourceview/gtksourcemap.c
+++ b/gtksourceview/gtksourcemap.c
@@ -782,12 +782,10 @@ disconnect_view (GtkSourceMap *map)
}
static void
-gtk_source_map_destroy (GtkWidget *widget)
+gtk_source_map_dispose (GObject *object)
{
- GtkSourceMap *map = GTK_SOURCE_MAP (widget);
- GtkSourceMapPrivate *priv;
-
- priv = gtk_source_map_get_instance_private (map);
+ GtkSourceMap *map = GTK_SOURCE_MAP (object);
+ GtkSourceMapPrivate *priv = gtk_source_map_get_instance_private (map);
disconnect_buffer (map);
disconnect_view (map);
@@ -795,7 +793,7 @@ gtk_source_map_destroy (GtkWidget *widget)
g_clear_object (&priv->css_provider);
g_clear_pointer (&priv->font_desc, pango_font_description_free);
- GTK_WIDGET_CLASS (gtk_source_map_parent_class)->destroy (widget);
+ G_OBJECT_CLASS (gtk_source_map_parent_class)->dispose (object);
}
static void
@@ -1048,10 +1046,10 @@ gtk_source_map_class_init (GtkSourceMapClass *klass)
GtkTextViewClass *text_view_class = GTK_TEXT_VIEW_CLASS (klass);
object_class->constructed = gtk_source_map_constructed;
+ object_class->dispose = gtk_source_map_dispose;
object_class->get_property = gtk_source_map_get_property;
object_class->set_property = gtk_source_map_set_property;
- widget_class->destroy = gtk_source_map_destroy;
widget_class->measure = gtk_source_map_measure;
widget_class->hide = gtk_source_map_hide;
widget_class->size_allocate = gtk_source_map_size_allocate;
diff --git a/gtksourceview/gtksourcestyleschemechooserwidget.c
b/gtksourceview/gtksourcestyleschemechooserwidget.c
index de8bf6e3..efec119b 100644
--- a/gtksourceview/gtksourcestyleschemechooserwidget.c
+++ b/gtksourceview/gtksourcestyleschemechooserwidget.c
@@ -57,7 +57,7 @@ static void style_scheme_chooser_interface_init (GtkSourceStyleSchemeChooserInte
G_DEFINE_TYPE_WITH_CODE (GtkSourceStyleSchemeChooserWidget,
gtk_source_style_scheme_chooser_widget,
- GTK_TYPE_BIN,
+ GTK_TYPE_WIDGET,
G_ADD_PRIVATE (GtkSourceStyleSchemeChooserWidget)
G_IMPLEMENT_INTERFACE (GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER,
style_scheme_chooser_interface_init))
@@ -119,11 +119,16 @@ static void
gtk_source_style_scheme_chooser_widget_class_init (GtkSourceStyleSchemeChooserWidgetClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->dispose = gtk_source_style_scheme_chooser_widget_dispose;
object_class->get_property = gtk_source_style_scheme_chooser_widget_get_property;
object_class->set_property = gtk_source_style_scheme_chooser_widget_set_property;
+ gtk_widget_class_set_template_from_resource (widget_class,
+
"/org/gnome/gtksourceview/ui/gtksourcestyleschemechooserwidget.ui");
+ gtk_widget_class_bind_template_child_private (widget_class, GtkSourceStyleSchemeChooserWidget,
list_box);
+
g_object_class_override_property (object_class, PROP_STYLE_SCHEME, "style-scheme");
}
@@ -209,7 +214,7 @@ static void
destroy_child_cb (GtkWidget *widget,
gpointer data)
{
- gtk_widget_destroy (widget);
+ gtk_container_remove (GTK_CONTAINER (data), widget);
}
static void
@@ -242,7 +247,7 @@ gtk_source_style_scheme_chooser_widget_populate (GtkSourceStyleSchemeChooserWidg
scheme = gtk_source_style_scheme_manager_get_scheme (manager, scheme_ids [i]);
row = make_row (scheme, lang);
- gtk_container_add (GTK_CONTAINER (priv->list_box), GTK_WIDGET (row));
+ gtk_list_box_insert (priv->list_box, GTK_WIDGET (row), -1);
if (scheme == priv->scheme)
{
@@ -276,10 +281,7 @@ gtk_source_style_scheme_chooser_widget_init (GtkSourceStyleSchemeChooserWidget *
GtkSourceStyleSchemeChooserWidgetPrivate *priv =
gtk_source_style_scheme_chooser_widget_get_instance_private (widget);
GtkSourceStyleSchemeManager *manager;
- priv->list_box = GTK_LIST_BOX (gtk_list_box_new ());
- gtk_list_box_set_selection_mode (priv->list_box, GTK_SELECTION_BROWSE);
- gtk_widget_show (GTK_WIDGET (priv->list_box));
- gtk_container_add (GTK_CONTAINER (widget), GTK_WIDGET (priv->list_box));
+ gtk_widget_init_template (GTK_WIDGET (widget));
manager = gtk_source_style_scheme_manager_get_default ();
g_signal_connect (manager,
diff --git a/gtksourceview/gtksourcestyleschemechooserwidget.h
b/gtksourceview/gtksourcestyleschemechooserwidget.h
index 7eaac12b..76b0e08b 100644
--- a/gtksourceview/gtksourcestyleschemechooserwidget.h
+++ b/gtksourceview/gtksourcestyleschemechooserwidget.h
@@ -33,14 +33,14 @@ G_BEGIN_DECLS
struct _GtkSourceStyleSchemeChooserWidgetClass
{
- GtkBinClass parent;
+ GtkWidgetClass parent;
/*< private >*/
gpointer _reserved[10];
};
GTK_SOURCE_AVAILABLE_IN_3_16
-G_DECLARE_DERIVABLE_TYPE (GtkSourceStyleSchemeChooserWidget, gtk_source_style_scheme_chooser_widget,
GTK_SOURCE, STYLE_SCHEME_CHOOSER_WIDGET, GtkBin)
+G_DECLARE_DERIVABLE_TYPE (GtkSourceStyleSchemeChooserWidget, gtk_source_style_scheme_chooser_widget,
GTK_SOURCE, STYLE_SCHEME_CHOOSER_WIDGET, GtkWidget)
GTK_SOURCE_AVAILABLE_IN_3_16
GtkWidget *gtk_source_style_scheme_chooser_widget_new (void);
diff --git a/gtksourceview/gtksourcestyleschemechooserwidget.ui
b/gtksourceview/gtksourcestyleschemechooserwidget.ui
new file mode 100644
index 00000000..a818e2c3
--- /dev/null
+++ b/gtksourceview/gtksourcestyleschemechooserwidget.ui
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <requires lib="gtk+" version="3.98"/>
+ <template class="GtkSourceStyleSchemeChooserWidget" parent="GtkWidget">
+ <child>
+ <object class="GtkListBox" id="list_box">
+ <property name="selection-mode">browse</property>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/gtksourceview/gtksourceview.gresource.xml b/gtksourceview/gtksourceview.gresource.xml
index 8c8d5f05..9321b920 100644
--- a/gtksourceview/gtksourceview.gresource.xml
+++ b/gtksourceview/gtksourceview.gresource.xml
@@ -2,5 +2,6 @@
<gresources>
<gresource prefix="/org/gnome/gtksourceview/ui">
<file preprocess="xml-stripblanks">gtksourcecompletion.ui</file>
+ <file preprocess="xml-stripblanks">gtksourcestyleschemechooserwidget.ui</file>
</gresource>
</gresources>
diff --git a/tests/test-widget.c b/tests/test-widget.c
index 5ab4556a..b2ca3b1e 100644
--- a/tests/test-widget.c
+++ b/tests/test-widget.c
@@ -514,7 +514,7 @@ open_button_clicked_cb (TestWidget *self)
g_clear_object (&file);
}
- gtk_widget_destroy (chooser);
+ gtk_window_destroy (GTK_WINDOW (chooser));
}
#define NON_BLOCKING_PAGINATION
@@ -1115,7 +1115,7 @@ main (int argc, char *argv[])
g_signal_connect_swapped (window, "destroy", G_CALLBACK (g_main_loop_quit), main_loop);
test_widget = test_widget_new ();
- gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (test_widget));
+ gtk_window_set_child (GTK_WINDOW (window), GTK_WIDGET (test_widget));
gtk_widget_show (window);
diff --git a/tests/test-widget.ui b/tests/test-widget.ui
index a04c9c77..d5e0222a 100644
--- a/tests/test-widget.ui
+++ b/tests/test-widget.ui
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
- <requires lib="gtk+" version="3.10"/>
- <requires lib="gtksourceview" version="3.0"/>
+ <requires lib="gtk+" version="3.98"/>
+ <requires lib="gtksourceview" version="5.0"/>
<object class="GtkAdjustment" id="adjustment_indent_width">
<property name="lower">1</property>
<property name="upper">16</property>
diff --git a/testsuite/test-printcompositor.c b/testsuite/test-printcompositor.c
index 49ea3090..08ac78d7 100644
--- a/testsuite/test-printcompositor.c
+++ b/testsuite/test-printcompositor.c
@@ -45,12 +45,12 @@ test_buffer_view_ref (void)
GtkWidget *view = NULL;
GtkSourceBuffer *buffer = NULL;
- view = gtk_source_view_new ();
+ view = g_object_ref_sink (gtk_source_view_new ());
compositor = gtk_source_print_compositor_new_from_view (GTK_SOURCE_VIEW (view));
buffer = gtk_source_print_compositor_get_buffer (compositor);
g_assert_true (GTK_SOURCE_IS_BUFFER (buffer));
- gtk_widget_destroy (view);
+ g_object_unref (view);
buffer = gtk_source_print_compositor_get_buffer (compositor);
g_assert_true (GTK_SOURCE_IS_BUFFER (buffer));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]