[balsa/gtk4: 193/288] cite-bar: Build with gtk4




commit fa71fc227eb383e3156e5622fe7d0c866e829f24
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Sat Oct 10 12:30:25 2020 -0400

    cite-bar: Build with gtk4

 src/balsa-cite-bar.c | 90 +++++++++++++++++++++++++---------------------------
 1 file changed, 44 insertions(+), 46 deletions(-)
---
diff --git a/src/balsa-cite-bar.c b/src/balsa-cite-bar.c
index 28290f11a..71312f425 100644
--- a/src/balsa-cite-bar.c
+++ b/src/balsa-cite-bar.c
@@ -1,20 +1,20 @@
 /* -*-mode:c; c-style:k&r; c-basic-offset:4; -*- */
 /* Balsa E-Mail Client
- * Copyright (C) 1997-2019 Stuart Parmenter and others
+ * Copyright (C) 1997-2020 Stuart Parmenter and others
  * Written by (C) Albrecht Dre� <albrecht dress arcor de> 2007
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option) 
+ * the Free Software Foundation; either version 2, or (at your option)
  * any later version.
- *  
+ *
  * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of 
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *  
+ *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, see <https://www.gnu.org/licenses/>.
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
 #include "balsa-cite-bar.h"
@@ -31,14 +31,15 @@ struct _BalsaCiteBar {
     gint space;
 };
 
-static void balsa_cite_bar_get_preferred_width (GtkWidget * widget,
-                                                gint      * minimum_width,
-                                                gint      * natural_width);
-static void balsa_cite_bar_get_preferred_height(GtkWidget * widget,
-                                                gint      * minimum_height,
-                                                gint      * natural_height);
-static gboolean balsa_cite_bar_draw            (GtkWidget * widget,
-                                                cairo_t   * cr);
+static void balsa_cite_bar_measure  (GtkWidget    * widget,
+                                     GtkOrientation orientation,
+                                     gint           for_size,
+                                     gint         * minimum,
+                                     gint         * natural,
+                                     gint         * minimum_baseline,
+                                     gint         * natural_baseline);
+static void balsa_cite_bar_snapshot (GtkWidget * widget,
+                                     GtkSnapshot * snapshot);
 
 G_DEFINE_TYPE(BalsaCiteBar, balsa_cite_bar, GTK_TYPE_WIDGET)
 
@@ -49,15 +50,13 @@ balsa_cite_bar_class_init(BalsaCiteBarClass * class)
 
     widget_class = (GtkWidgetClass *) class;
 
-    widget_class->get_preferred_width  = balsa_cite_bar_get_preferred_width;
-    widget_class->get_preferred_height = balsa_cite_bar_get_preferred_height;
-    widget_class->draw                 = balsa_cite_bar_draw;
+    widget_class->measure  = balsa_cite_bar_measure;
+    widget_class->snapshot = balsa_cite_bar_snapshot;
 }
 
 static void
 balsa_cite_bar_init(BalsaCiteBar * cite_bar)
 {
-    gtk_widget_set_has_window(GTK_WIDGET(cite_bar), FALSE);
 }
 
 GtkWidget *
@@ -92,47 +91,46 @@ balsa_cite_bar_resize(BalsaCiteBar * cite_bar, gint height)
 }
 
 static void
-balsa_cite_bar_get_preferred_width(GtkWidget * widget,
-                                   gint      * minimum_width,
-                                   gint      * natural_width)
+balsa_cite_bar_measure(GtkWidget    * widget,
+                       GtkOrientation orientation,
+                       gint           for_size,
+                       gint         * minimum,
+                       gint         * natural,
+                       gint         * minimum_baseline,
+                       gint         * natural_baseline)
 {
     BalsaCiteBar *cite_bar;
 
     cite_bar = BALSA_CITE_BAR(widget);
-    *minimum_width = *natural_width =
-        cite_bar->bars * (cite_bar->width + cite_bar->space) -
-        cite_bar->space;
-}
-
-static void
-balsa_cite_bar_get_preferred_height(GtkWidget * widget,
-                                    gint      * minimum_height,
-                                    gint      * natural_height)
-{
-    BalsaCiteBar *cite_bar;
 
-    cite_bar = BALSA_CITE_BAR(widget);
-    *minimum_height = *natural_height = cite_bar->height;
+    if (orientation == GTK_ORIENTATION_HORIZONTAL) {
+        *minimum = *natural =
+            cite_bar->bars * (cite_bar->width + cite_bar->space) -
+            cite_bar->space;
+    } else {
+        *minimum = *natural = cite_bar->height;
+        *minimum_baseline = *natural_baseline = 0;
+    }
 }
 
-static gboolean
-balsa_cite_bar_draw(GtkWidget * widget, cairo_t * cr)
+static void
+balsa_cite_bar_snapshot(GtkWidget * widget, GtkSnapshot * snapshot)
 {
     GtkStyleContext *context;
     GdkRGBA rgba;
+    int n;
     BalsaCiteBar *cite_bar;
-    int n, x;
+    graphene_rect_t bounds;
 
     context = gtk_widget_get_style_context(widget);
-    gtk_style_context_get_color(context, GTK_STATE_FLAG_NORMAL, &rgba);
-    gdk_cairo_set_source_rgba(cr, &rgba);
+    gtk_style_context_get_color(context, &rgba);
 
     cite_bar = BALSA_CITE_BAR(widget);
-    for (n = x = 0; n < cite_bar->bars; n++) {
-        cairo_rectangle(cr, x, 0, cite_bar->width, cite_bar->height);
-        cairo_fill(cr);
-        x += cite_bar->width + cite_bar->space;
-    }
+    graphene_rect_init(&bounds, 0.0, 0.0,
+                       (float) cite_bar->width, (float) cite_bar->height);
 
-    return FALSE;
+    for (n = 0; n < cite_bar->bars; n++) {
+        gtk_snapshot_append_color(snapshot, &rgba, &bounds);
+        bounds.origin.x += (float) (cite_bar->width + cite_bar->space);
+    }
 }


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