[gnome-calendar/gbsneto/gtk4: 12/46] event-editor/multi-choice: Port to GTK4
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar/gbsneto/gtk4: 12/46] event-editor/multi-choice: Port to GTK4
- Date: Sat, 12 Feb 2022 16:25:50 +0000 (UTC)
commit 4506fb747730fc15abf81dd952c58a517b913b0e
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Mon Jan 10 18:43:52 2022 -0300
event-editor/multi-choice: Port to GTK4
src/gui/event-editor/gcal-multi-choice.c | 107 ++----------------------------
src/gui/event-editor/gcal-multi-choice.ui | 61 ++++++-----------
2 files changed, 28 insertions(+), 140 deletions(-)
---
diff --git a/src/gui/event-editor/gcal-multi-choice.c b/src/gui/event-editor/gcal-multi-choice.c
index 559824d9..4199b9b5 100644
--- a/src/gui/event-editor/gcal-multi-choice.c
+++ b/src/gui/event-editor/gcal-multi-choice.c
@@ -16,17 +16,17 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "config.h"
-
#define G_LOG_DOMAIN "GcalMultiChoice"
+#include "config.h"
+
#include "gcal-multi-choice.h"
struct _GcalMultiChoice
{
GtkBox parent;
GtkWidget *down_button;
- GtkWidget *stack;
+ GtkStack *stack;
GtkWidget *up_button;
gint value;
gint min_value;
@@ -35,7 +35,6 @@ struct _GcalMultiChoice
gboolean animate;
GtkWidget **choices;
gint n_choices;
- guint click_id;
GtkWidget *active;
GtkWidget *label1;
GtkWidget *label2;
@@ -173,9 +172,9 @@ go_down (GcalMultiChoice *self)
g_signal_emit (self, signals[WRAPPED], 0);
}
-static gboolean
-button_activate (GcalMultiChoice *self,
- GtkWidget *button)
+static void
+button_clicked_cb (GtkWidget *button,
+ GcalMultiChoice *self)
{
if (button == self->down_button)
go_down (self);
@@ -183,90 +182,6 @@ button_activate (GcalMultiChoice *self,
go_up (self);
else
g_assert_not_reached ();
-
- return TRUE;
-}
-
-static gboolean
-button_timeout (gpointer user_data)
-{
- GcalMultiChoice *self = GCAL_MULTI_CHOICE (user_data);
- gboolean res;
-
- if (self->click_id == 0)
- return G_SOURCE_REMOVE;
-
- if (!gtk_widget_get_mapped (self->down_button) && !gtk_widget_get_mapped (self->up_button))
- {
- if (self->click_id)
- g_source_remove (self->click_id);
- self->click_id = 0;
- self->active = NULL;
- return G_SOURCE_REMOVE;
- }
-
- res = button_activate (self, self->active);
- if (!res)
- {
- g_source_remove (self->click_id);
- self->click_id = 0;
- }
-
- return res;
-}
-
-static gboolean
-button_press_cb (GtkWidget *widget,
- GdkEventButton *button,
- GcalMultiChoice *self)
-{
- gint double_click_time;
-
- if (button->type != GDK_BUTTON_PRESS)
- return TRUE;
-
- g_object_get (gtk_widget_get_settings (widget),
- "gtk-double-click-time", &double_click_time,
- NULL);
-
- if (self->click_id != 0)
- g_source_remove (self->click_id);
-
- self->active = widget;
-
- self->click_id = gdk_threads_add_timeout (double_click_time,
- button_timeout,
- self);
- g_source_set_name_by_id (self->click_id, "[gtk+] button_timeout");
- button_timeout (self);
-
- return TRUE;
-}
-
-static gboolean
-button_release_cb (GtkWidget *widget,
- GdkEventButton *event,
- GcalMultiChoice *self)
-{
- if (self->click_id != 0)
- {
- g_source_remove (self->click_id);
- self->click_id = 0;
- }
-
- self->active = NULL;
-
- return TRUE;
-}
-
-static void
-button_clicked_cb (GtkWidget *button,
- GcalMultiChoice *self)
-{
- if (self->click_id != 0)
- return;
-
- button_activate (self, button);
}
static void
@@ -280,12 +195,6 @@ gcal_multi_choice_dispose (GObject *object)
{
GcalMultiChoice *self = GCAL_MULTI_CHOICE (object);
- if (self->click_id != 0)
- {
- g_source_remove (self->click_id);
- self->click_id = 0;
- }
-
g_free (self->choices);
self->choices = NULL;
@@ -435,8 +344,6 @@ gcal_multi_choice_class_init (GcalMultiChoiceClass *class)
gtk_widget_class_bind_template_child (widget_class, GcalMultiChoice, label2);
gtk_widget_class_bind_template_callback (widget_class, button_clicked_cb);
- gtk_widget_class_bind_template_callback (widget_class, button_press_cb);
- gtk_widget_class_bind_template_callback (widget_class, button_release_cb);
gtk_widget_class_set_css_name (widget_class, "navigator");
}
@@ -467,7 +374,7 @@ gcal_multi_choice_set_choices (GcalMultiChoice *self,
gint i;
for (i = 0; i < self->n_choices; i++)
- gtk_container_remove (GTK_CONTAINER (self->stack), self->choices[i]);
+ gtk_stack_remove (self->stack, self->choices[i]);
g_free (self->choices);
self->n_choices = g_strv_length ((gchar **)choices);
diff --git a/src/gui/event-editor/gcal-multi-choice.ui b/src/gui/event-editor/gcal-multi-choice.ui
index 8376567d..5f0460f8 100644
--- a/src/gui/event-editor/gcal-multi-choice.ui
+++ b/src/gui/event-editor/gcal-multi-choice.ui
@@ -1,70 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
-<interface domain="gtk30">
- <requires lib="gtk+" version="3.16"/>
+<interface>
<template class="GcalMultiChoice" parent="GtkBox">
- <property name="visible">True</property>
<child>
<object class="GtkButton" id="down_button">
- <property name="visible">True</property>
- <property name="relief">none</property>
- <signal name="button-press-event" handler="button_press_cb"/>
- <signal name="button-release-event" handler="button_release_cb"/>
+ <property name="icon-name">pan-start-symbolic</property>
<signal name="clicked" handler="button_clicked_cb"/>
<style>
- <class name="image-button"/>
<class name="back-button"/>
<class name="circular"/>
+ <class name="flat"/>
</style>
- <child>
- <object class="GtkImage">
- <property name="visible">True</property>
- <property name="icon_name">pan-start-symbolic</property>
- </object>
- </child>
</object>
</child>
<child>
<object class="GtkStack" id="stack">
- <property name="visible">True</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+
<child>
- <object class="GtkLabel" id="label1">
- <property name="visible">True</property>
- </object>
- <packing>
+ <object class="GtkStackPage">
<property name="name">label1</property>
- </packing>
+ <property name="child">
+ <object class="GtkLabel" id="label1" />
+ </property>
+ </object>
</child>
+
<child>
- <object class="GtkLabel" id="label2">
- <property name="visible">True</property>
- </object>
- <packing>
+ <object class="GtkStackPage">
<property name="name">label2</property>
- </packing>
+ <property name="child">
+ <object class="GtkLabel" id="label2" />
+ </property>
+ </object>
</child>
+
</object>
- <packing>
- <property name="expand">True</property>
- </packing>
</child>
<child>
<object class="GtkButton" id="up_button">
- <property name="visible">True</property>
- <property name="relief">none</property>
- <signal name="button-press-event" handler="button_press_cb"/>
- <signal name="button-release-event" handler="button_release_cb"/>
+ <property name="icon-name">pan-end-symbolic</property>
<signal name="clicked" handler="button_clicked_cb"/>
<style>
- <class name="image-button"/>
- <class name="forward-button"/>
<class name="circular"/>
+ <class name="flat"/>
+ <class name="forward-button"/>
</style>
- <child>
- <object class="GtkImage">
- <property name="visible">True</property>
- <property name="icon_name">pan-end-symbolic</property>
- </object>
- </child>
</object>
</child>
</template>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]