summaryrefslogtreecommitdiff
path: root/gtk/gtkcolumnviewtitle.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2019-12-04 08:52:12 -0500
committerMatthias Clasen <mclasen@redhat.com>2020-05-30 19:28:30 -0400
commit1ba1eda8ab36491dc7568732a0013f8ed8e9da6e (patch)
treed0f78a42339ec34879b9c3f815385627e6a12d3a /gtk/gtkcolumnviewtitle.c
parent2945430ad7fdfd7be303ea6d32d35cf632e8937e (diff)
downloadgtk+-1ba1eda8ab36491dc7568732a0013f8ed8e9da6e.tar.gz
column view title: Show sort indicators
Diffstat (limited to 'gtk/gtkcolumnviewtitle.c')
-rw-r--r--gtk/gtkcolumnviewtitle.c74
1 files changed, 70 insertions, 4 deletions
diff --git a/gtk/gtkcolumnviewtitle.c b/gtk/gtkcolumnviewtitle.c
index 7170018eb4..306064bcd8 100644
--- a/gtk/gtkcolumnviewtitle.c
+++ b/gtk/gtkcolumnviewtitle.c
@@ -21,10 +21,15 @@
#include "gtkcolumnviewtitleprivate.h"
+#include "gtkcolumnviewprivate.h"
#include "gtkcolumnviewcolumnprivate.h"
+#include "gtkcolumnviewsorterprivate.h"
#include "gtkintl.h"
#include "gtklabel.h"
#include "gtkwidgetprivate.h"
+#include "gtkbox.h"
+#include "gtkimage.h"
+#include "gtkgestureclick.h"
struct _GtkColumnViewTitle
{
@@ -32,7 +37,9 @@ struct _GtkColumnViewTitle
GtkColumnViewColumn *column;
+ GtkWidget *box;
GtkWidget *title;
+ GtkWidget *sort;
};
struct _GtkColumnViewTitleClass
@@ -74,7 +81,7 @@ gtk_column_view_title_dispose (GObject *object)
{
GtkColumnViewTitle *self = GTK_COLUMN_VIEW_TITLE (object);
- g_clear_pointer(&self->title, gtk_widget_unparent);
+ g_clear_pointer (&self->box, gtk_widget_unparent);
g_clear_object (&self->column);
@@ -105,14 +112,46 @@ gtk_column_view_title_resize_func (GtkWidget *widget)
}
static void
+click_pressed_cb (GtkGestureClick *gesture,
+ guint n_press,
+ gdouble x,
+ gdouble y,
+ GtkWidget *widget)
+{
+ GtkColumnViewTitle *self = GTK_COLUMN_VIEW_TITLE (widget);
+ GtkSorter *sorter;
+ GtkColumnView *view;
+ GtkColumnViewSorter *view_sorter;
+
+ sorter = gtk_column_view_column_get_sorter (self->column);
+ if (sorter == NULL)
+ return;
+
+ view = gtk_column_view_column_get_column_view (self->column);
+ view_sorter = GTK_COLUMN_VIEW_SORTER (gtk_column_view_get_sorter (view));
+ gtk_column_view_sorter_add_column (view_sorter, self->column);
+}
+
+static void
gtk_column_view_title_init (GtkColumnViewTitle *self)
{
GtkWidget *widget = GTK_WIDGET (self);
+ GtkGesture *gesture;
widget->priv->resize_func = gtk_column_view_title_resize_func;
+ self->box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+ gtk_widget_set_parent (self->box, widget);
+
self->title = gtk_label_new (NULL);
- gtk_widget_set_parent (self->title, widget);
+ gtk_box_append (GTK_BOX (self->box), self->title);
+
+ self->sort = gtk_image_new ();
+ gtk_box_append (GTK_BOX (self->box), self->sort);
+
+ gesture = gtk_gesture_click_new ();
+ g_signal_connect (gesture, "pressed", G_CALLBACK (click_pressed_cb), self);
+ gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (gesture));
}
GtkWidget *
@@ -120,8 +159,7 @@ gtk_column_view_title_new (GtkColumnViewColumn *column)
{
GtkColumnViewTitle *title;
- title = g_object_new (GTK_TYPE_COLUMN_VIEW_TITLE,
- NULL);
+ title = g_object_new (GTK_TYPE_COLUMN_VIEW_TITLE, NULL);
title->column = g_object_ref (column);
gtk_column_view_title_update (title);
@@ -132,7 +170,35 @@ gtk_column_view_title_new (GtkColumnViewColumn *column)
void
gtk_column_view_title_update (GtkColumnViewTitle *self)
{
+ GtkSorter *sorter;
+ GtkColumnView *view;
+ GtkColumnViewSorter *view_sorter;
+ gboolean inverted;
+ GtkColumnViewColumn *active;
+
gtk_label_set_label (GTK_LABEL (self->title), gtk_column_view_column_get_title (self->column));
+
+ sorter = gtk_column_view_column_get_sorter (self->column);
+
+ if (sorter)
+ {
+ view = gtk_column_view_column_get_column_view (self->column);
+ view_sorter = GTK_COLUMN_VIEW_SORTER (gtk_column_view_get_sorter (view));
+ active = gtk_column_view_sorter_get_sort_column (view_sorter, &inverted);
+
+ gtk_widget_show (self->sort);
+ if (self->column == active)
+ {
+ if (inverted)
+ gtk_image_set_from_icon_name (GTK_IMAGE (self->sort), "pan-down-symbolic");
+ else
+ gtk_image_set_from_icon_name (GTK_IMAGE (self->sort), "pan-up-symbolic");
+ }
+ else
+ gtk_image_clear (GTK_IMAGE (self->sort));
+ }
+ else
+ gtk_widget_hide (self->sort);
}
GtkColumnViewColumn *