[gtk/matthiasc/for-master] columview: Implement double-click to reset headers
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/matthiasc/for-master] columview: Implement double-click to reset headers
- Date: Mon, 19 Oct 2020 02:35:39 +0000 (UTC)
commit c1fdc6dc3d5172a31f3c3f4b718da466a3de9444
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Oct 18 22:34:07 2020 -0400
columview: Implement double-click to reset headers
Implement the same behavior as GtkTreeView:
double-click on the header boundary resets the
header to its automatic width.
Fixes: #3272
gtk/gtkcolumnview.c | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
---
diff --git a/gtk/gtkcolumnview.c b/gtk/gtkcolumnview.c
index ae7ffd82aa..c68c3970cb 100644
--- a/gtk/gtkcolumnview.c
+++ b/gtk/gtkcolumnview.c
@@ -41,6 +41,7 @@
#include "gtkeventcontrollermotion.h"
#include "gtkdragsource.h"
#include "gtkeventcontrollerkey.h"
+#include "gtkgestureclick.h"
/**
* SECTION:gtkcolumnview
@@ -1171,6 +1172,36 @@ header_key_pressed (GtkEventControllerKey *controller,
return FALSE;
}
+static void
+header_pressed (GtkGestureClick *gesture,
+ int n_press,
+ double x,
+ double y,
+ GtkColumnView *self)
+{
+ int i, n;
+
+ if (n_press != 2)
+ return;
+
+ n = g_list_model_get_n_items (G_LIST_MODEL (self->columns));
+ for (i = n - 1; i >= 0; i--)
+ {
+ GtkColumnViewColumn *column = g_list_model_get_item (G_LIST_MODEL (self->columns), i);
+
+ g_object_unref (column);
+
+ if (i + 1 < n &&
+ gtk_column_view_column_get_resizable (column) &&
+ gtk_column_view_in_resize_rect (self, column, x, y))
+ {
+ gtk_gesture_set_state (self->drag_gesture, GTK_EVENT_SEQUENCE_DENIED);
+ gtk_column_view_column_set_fixed_width (column, -1);
+ break;
+ }
+ }
+}
+
static void
gtk_column_view_drag_motion (GtkDropControllerMotion *motion,
double x,
@@ -1206,6 +1237,12 @@ gtk_column_view_init (GtkColumnView *self)
gtk_widget_set_layout_manager (self->header, gtk_column_view_layout_new (self));
gtk_widget_set_parent (self->header, GTK_WIDGET (self));
+ controller = GTK_EVENT_CONTROLLER (gtk_gesture_click_new ());
+ g_signal_connect (controller, "pressed", G_CALLBACK (header_pressed), self);
+ gtk_event_controller_set_propagation_phase (controller, GTK_PHASE_CAPTURE);
+ gtk_widget_add_controller (self->header, controller);
+ gtk_gesture_group (GTK_GESTURE (controller), self->drag_gesture);
+
controller = GTK_EVENT_CONTROLLER (gtk_gesture_drag_new ());
g_signal_connect (controller, "drag-begin", G_CALLBACK (header_drag_begin), self);
g_signal_connect (controller, "drag-update", G_CALLBACK (header_drag_update), self);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]