[libhandy/wip/haecker-felix/flap-widget] Glade



commit 0bcec24db668b805576f7f63871b22e541c78be4
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Wed Nov 25 14:44:15 2020 +0500

    Glade

 glade/glade-hdy-flap.c | 131 +++++++++++++++++++++++++++++++++++++++++++++++++
 glade/glade-hdy-flap.h |  27 ++++++++++
 glade/libhandy.xml     |  34 +++++++++++++
 glade/meson.build      |   1 +
 4 files changed, 193 insertions(+)
---
diff --git a/glade/glade-hdy-flap.c b/glade/glade-hdy-flap.c
new file mode 100644
index 00000000..85115afb
--- /dev/null
+++ b/glade/glade-hdy-flap.c
@@ -0,0 +1,131 @@
+/*
+ * Copyright (C) 2020 Purism SPC
+ *
+ * SPDX-License-Identifier: LGPL-2.1+
+ *
+ * Based on
+ * glade-gtk-header-bar.c - GladeWidgetAdaptor for GtkHeaderBar
+ */
+
+#include <config.h>
+#include <glib/gi18n-lib.h>
+
+#include "glade-hdy-flap.h"
+
+#include <gladeui/glade.h>
+#include "glade-hdy-utils.h"
+
+void
+glade_hdy_flap_post_create (GladeWidgetAdaptor *adaptor,
+                            GObject            *container,
+                            GladeCreateReason   reason)
+{
+  GtkWidget *child;
+
+  if (!hdy_flap_get_flap (HDY_FLAP (container))) {
+    child = glade_placeholder_new ();
+    g_object_set_data (G_OBJECT (child), "special-child-type", "flap");
+    hdy_flap_set_flap (HDY_FLAP (container), child);
+  }
+
+  if (!hdy_flap_get_separator (HDY_FLAP (container))) {
+    child = glade_placeholder_new ();
+    g_object_set_data (G_OBJECT (child), "special-child-type", "separator");
+    hdy_flap_set_separator (HDY_FLAP (container), child);
+  }
+
+  if (!hdy_flap_get_content (HDY_FLAP (container))) {
+    child = glade_placeholder_new ();
+    gtk_container_add (GTK_CONTAINER (container), child);
+  }
+}
+
+void
+glade_hdy_flap_add_child (GladeWidgetAdaptor *adaptor,
+                          GObject            *parent,
+                          GObject            *child)
+{
+  gchar *special_child_type = g_object_get_data (child, "special-child-type");
+  GtkWidget *content;
+
+  if (special_child_type && !strcmp (special_child_type, "flap")) {
+    hdy_flap_set_flap (HDY_FLAP (parent), GTK_WIDGET (child));
+
+    return;
+  }
+
+  if (special_child_type && !strcmp (special_child_type, "separator")) {
+    hdy_flap_set_separator (HDY_FLAP (parent), GTK_WIDGET (child));
+
+    return;
+  }
+
+  /* Get a placeholder out of the way before adding the child */
+  content = hdy_flap_get_content (HDY_FLAP (parent));
+
+  if (content) {
+    if (GLADE_IS_PLACEHOLDER (content))
+      gtk_container_remove (GTK_CONTAINER (parent), content);
+    else {
+      g_critical ("Can't add more than one content widget to a HdyFlap");
+
+      return;
+    }
+  }
+
+  gtk_container_add (GTK_CONTAINER (parent), GTK_WIDGET (child));
+}
+
+void
+glade_hdy_flap_remove_child (GladeWidgetAdaptor *adaptor,
+                             GObject            *object,
+                             GObject            *child)
+{
+  gchar *special_child_type = g_object_get_data (child, "special-child-type");
+  GtkWidget *replacement = glade_placeholder_new ();
+
+  if (special_child_type && !strcmp (special_child_type, "flap")) {
+    g_object_set_data (G_OBJECT (replacement), "special-child-type", "flap");
+    hdy_flap_set_flap (HDY_FLAP (object), replacement);
+
+    return;
+  }
+
+  if (special_child_type && !strcmp (special_child_type, "separator")) {
+    g_object_set_data (G_OBJECT (replacement), "special-child-type", "separator");
+    hdy_flap_set_separator (HDY_FLAP (object), replacement);
+
+    return;
+  }
+
+  gtk_container_remove (GTK_CONTAINER (object), GTK_WIDGET (child));
+  gtk_container_add (GTK_CONTAINER (object), replacement);
+}
+
+void
+glade_hdy_flap_replace_child (GladeWidgetAdaptor *adaptor,
+                              GObject            *container,
+                              GObject            *current,
+                              GObject            *new_widget)
+{
+  gchar *special_child_type =
+    g_object_get_data (G_OBJECT (current), "special-child-type");
+
+  if (special_child_type && !strcmp (special_child_type, "flap")) {
+    g_object_set_data (G_OBJECT (new_widget), "special-child-type", "flap");
+    hdy_flap_set_flap (HDY_FLAP (container), GTK_WIDGET (new_widget));
+
+    return;
+  }
+
+  if (special_child_type && !strcmp (special_child_type, "separator")) {
+    g_object_set_data (G_OBJECT (new_widget), "special-child-type", "separator");
+    hdy_flap_set_separator (HDY_FLAP (container), GTK_WIDGET (new_widget));
+
+    return;
+  }
+
+  g_object_set_data (G_OBJECT (new_widget), "special-child-type", NULL);
+  gtk_container_remove (GTK_CONTAINER (container), GTK_WIDGET (current));
+  gtk_container_add (GTK_CONTAINER (container), GTK_WIDGET (new_widget));
+}
diff --git a/glade/glade-hdy-flap.h b/glade/glade-hdy-flap.h
new file mode 100644
index 00000000..4782e845
--- /dev/null
+++ b/glade/glade-hdy-flap.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2020 Purism SPC
+ *
+ * SPDX-License-Identifier: LGPL-2.1+
+ */
+
+#pragma once
+
+#include <gladeui/glade.h>
+
+#include <handy.h>
+
+
+void glade_hdy_flap_post_create (GladeWidgetAdaptor *adaptor,
+                                 GObject            *container,
+                                 GladeCreateReason   reason);
+
+void glade_hdy_flap_add_child (GladeWidgetAdaptor *adaptor,
+                               GObject            *parent,
+                               GObject            *child);
+void glade_hdy_flap_remove_child (GladeWidgetAdaptor *adaptor,
+                                  GObject            *object,
+                                  GObject            *child);
+void glade_hdy_flap_replace_child (GladeWidgetAdaptor *adaptor,
+                                   GObject            *container,
+                                   GObject            *current,
+                                   GObject            *new_widget);
diff --git a/glade/libhandy.xml b/glade/libhandy.xml
index 544c5268..c2247e3b 100644
--- a/glade/libhandy.xml
+++ b/glade/libhandy.xml
@@ -143,6 +143,39 @@
         <property id="enable-expansion" save="True" ignore="True"/>
       </properties>
     </glade-widget-class>
+    <glade-widget-class name="HdyFlap" generic-name="flap" title="Flap" since="1.1" use-placeholders="False">
+      <post-create-function>glade_hdy_flap_post_create</post-create-function>
+      <add-child-function>glade_hdy_flap_add_child</add-child-function>
+      <remove-child-function>glade_hdy_flap_remove_child</remove-child-function>
+      <replace-child-function>glade_hdy_flap_replace_child</replace-child-function>
+      <special-child-type>type</special-child-type>
+      <properties>
+        <property id="flap" disabled="True"/>
+        <property id="separator" disabled="True"/>
+        <property id="fold-policy">
+          <displayable-values>
+            <!-- HdyFlapFoldPolicy enumeration value -->
+            <value id="HDY_FLAP_FOLD_POLICY_NEVER" name="Never"/>
+            <!-- HdyFlapFoldPolicy enumeration value -->
+            <value id="HDY_FLAP_FOLD_POLICY_ALWAYS" name="Always"/>
+            <!-- HdyFlapFoldPolicy enumeration value -->
+            <value id="HDY_FLAP_FOLD_POLICY_AUTO" name="Auto"/>
+          </displayable-values>
+        </property>
+        <property id="transition-type">
+          <displayable-values>
+            <!-- HdyFlapTransitionType enumeration value -->
+            <value id="HDY_FLAP_TRANSITION_TYPE_OVER" name="Over"/>
+            <!-- HdyFlapTransitionType enumeration value -->
+            <value id="HDY_FLAP_TRANSITION_TYPE_UNDER" name="Under"/>
+            <!-- HdyFlapTransitionType enumeration value -->
+            <value id="HDY_FLAP_TRANSITION_TYPE_SLIDE" name="Slide"/>
+            <!-- HdyFlapTransitionType enumeration value -->
+            <value id="HDY_FLAP_TRANSITION_TYPE_OVER_TRANSPARENT" name="Over (transparent)"/>
+          </displayable-values>
+        </property>
+      </properties>
+    </glade-widget-class>
     <glade-widget-class name="HdyHeaderBar" generic-name="headerbar" title="Header Bar" since="0.0.10">
       <post-create-function>glade_hdy_header_bar_post_create</post-create-function>
       <add-child-function>glade_hdy_header_bar_add_child</add-child-function>
@@ -401,6 +434,7 @@
     <glade-widget-class-ref name="HdyComboRow"/>
     <glade-widget-class-ref name="HdyDeck"/>
     <glade-widget-class-ref name="HdyExpanderRow"/>
+    <glade-widget-class-ref name="HdyFlap"/>
     <glade-widget-class-ref name="HdyHeaderBar"/>
     <glade-widget-class-ref name="HdyHeaderGroup"/>
     <glade-widget-class-ref name="HdyKeypad"/>
diff --git a/glade/meson.build b/glade/meson.build
index cba9a364..946cd76a 100644
--- a/glade/meson.build
+++ b/glade/meson.build
@@ -10,6 +10,7 @@ glade_catalogdir   = gladeui_dep.get_pkgconfig_variable('catalogdir',
 libglade_hdy_sources = [
   'glade-hdy-carousel.c',
   'glade-hdy-expander-row.c',
+  'glade-hdy-flap.c',
   'glade-hdy-header-bar.c',
   'glade-hdy-header-group.c',
   'glade-hdy-leaflet.c',


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