Merge branch 'matthiasc/for-master' into 'master'

Various columnview fixes

Closes #3265, #3272, and #3276

See merge request GNOME/gtk!2717
This commit is contained in:
Matthias Clasen 2020-10-19 15:00:17 +00:00
commit 2359510b1f
5 changed files with 105 additions and 17 deletions

View File

@ -41,6 +41,7 @@
#include "gtkeventcontrollermotion.h"
#include "gtkdragsource.h"
#include "gtkeventcontrollerkey.h"
#include "gtkgestureclick.h"
/**
* SECTION:gtkcolumnview
@ -852,7 +853,7 @@ update_autoscroll (GtkColumnView *self,
}
#define DRAG_WIDTH 6
#define DRAG_WIDTH 8
static gboolean
gtk_column_view_in_resize_rect (GtkColumnView *self,
@ -862,12 +863,16 @@ gtk_column_view_in_resize_rect (GtkColumnView *self,
{
GtkWidget *header;
graphene_rect_t rect;
int width;
header = gtk_column_view_column_get_header (column);
if (!gtk_widget_compute_bounds (header, self->header, &rect))
return FALSE;
gtk_column_view_column_get_allocation (column, NULL, &width);
rect.size.width = width;
rect.origin.x += rect.size.width - DRAG_WIDTH / 2;
rect.size.width = DRAG_WIDTH;
@ -891,6 +896,25 @@ header = gtk_column_view_column_get_header (column);
return graphene_rect_contains_point (&rect, &(graphene_point_t) { x, y});
}
static void
set_resize_cursor (GtkColumnView *self,
gboolean set)
{
int i, n;
n = g_list_model_get_n_items (G_LIST_MODEL (self->columns));
for (i = 0; i < n; i++)
{
GtkColumnViewColumn *column = g_list_model_get_item (G_LIST_MODEL (self->columns), i);
GtkWidget *header = gtk_column_view_column_get_header (column);
if (set)
gtk_widget_set_cursor_from_name (header, "col-resize");
else
gtk_widget_set_cursor (header, NULL);
g_object_unref (column);
}
}
static void
header_drag_begin (GtkGestureDrag *gesture,
double start_x,
@ -902,7 +926,7 @@ header_drag_begin (GtkGestureDrag *gesture,
self->drag_pos = -1;
n = g_list_model_get_n_items (G_LIST_MODEL (self->columns));
for (i = 0; !self->in_column_resize && i < n; i++)
for (i = n - 1; !self->in_column_resize && i >= 0; i--)
{
GtkColumnViewColumn *column = g_list_model_get_item (G_LIST_MODEL (self->columns), i);
@ -929,9 +953,23 @@ header_drag_begin (GtkGestureDrag *gesture,
self->drag_x = start_x - size;
self->in_column_resize = TRUE;
set_resize_cursor (self, TRUE);
g_object_unref (column);
break;
}
}
for (i = 0; !self->in_column_resize && i < n; i++)
{
GtkColumnViewColumn *column = g_list_model_get_item (G_LIST_MODEL (self->columns), i);
if (!gtk_column_view_column_get_visible (column))
{
g_object_unref (column);
continue;
}
if (gtk_column_view_get_reorderable (self) &&
gtk_column_view_in_header (self, column, start_x, start_y))
@ -966,6 +1004,7 @@ header_drag_end (GtkGestureDrag *gesture,
if (self->in_column_resize)
{
set_resize_cursor (self, FALSE);
self->in_column_resize = FALSE;
}
else if (self->in_column_reorder)
@ -1102,6 +1141,9 @@ header_motion (GtkEventControllerMotion *controller,
gboolean cursor_set = FALSE;
int i, n;
if (self->in_column_resize)
return;
n = g_list_model_get_n_items (G_LIST_MODEL (self->columns));
for (i = 0; i < n; i++)
{
@ -1145,6 +1187,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,
@ -1180,6 +1252,11 @@ 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);
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);

View File

@ -124,15 +124,15 @@ gtk_column_view_cell_size_allocate (GtkWidget *widget,
int height,
int baseline)
{
GtkColumnViewCell *self = GTK_COLUMN_VIEW_CELL (widget);
GtkWidget *child = gtk_widget_get_first_child (widget);
if (child)
{
if (gtk_column_view_column_get_fixed_width (self->column) > -1)
gtk_widget_measure (child, GTK_ORIENTATION_HORIZONTAL, height, NULL, &width, NULL, NULL);
int min;
gtk_widget_allocate (child, width, height, baseline, NULL);
gtk_widget_measure (child, GTK_ORIENTATION_HORIZONTAL, height, &min, NULL, NULL, NULL);
gtk_widget_allocate (child, MAX (min, width), height, baseline, NULL);
}
}

View File

@ -136,10 +136,11 @@ gtk_column_view_title_size_allocate (GtkWidget *widget,
if (child)
{
if (gtk_column_view_column_get_fixed_width (self->column) > -1)
gtk_widget_measure (child, GTK_ORIENTATION_HORIZONTAL, height, NULL, &width, NULL, NULL);
int min;
gtk_widget_allocate (child, width, height, baseline, NULL);
gtk_widget_measure (child, GTK_ORIENTATION_HORIZONTAL, height, &min, NULL, NULL, NULL);
gtk_widget_allocate (child, MAX (min, width), height, baseline, NULL);
}
if (self->popup_menu)

View File

@ -1069,13 +1069,11 @@ gtk_inspector_visual_constructed (GObject *object)
}
static void
gtk_inspector_visual_dispose (GObject *object)
gtk_inspector_visual_unroot (GtkWidget *widget)
{
GtkInspectorVisual *vis = GTK_INSPECTOR_VISUAL (object);
GtkInspectorVisual *vis = GTK_INSPECTOR_VISUAL (widget);
GtkInspectorWindow *iw = GTK_INSPECTOR_WINDOW (gtk_widget_get_root (GTK_WIDGET (vis)));
g_clear_pointer (&vis->swin, gtk_widget_unparent);
if (vis->layout_overlay)
{
gtk_inspector_window_remove_overlay (iw, vis->layout_overlay);
@ -1097,6 +1095,16 @@ gtk_inspector_visual_dispose (GObject *object)
vis->focus_overlay = NULL;
}
GTK_WIDGET_CLASS (gtk_inspector_visual_parent_class)->unroot (widget);
}
static void
gtk_inspector_visual_dispose (GObject *object)
{
GtkInspectorVisual *vis = GTK_INSPECTOR_VISUAL (object);
g_clear_pointer (&vis->swin, gtk_widget_unparent);
G_OBJECT_CLASS (gtk_inspector_visual_parent_class)->dispose (object);
}
@ -1109,6 +1117,8 @@ gtk_inspector_visual_class_init (GtkInspectorVisualClass *klass)
object_class->constructed = gtk_inspector_visual_constructed;
object_class->dispose = gtk_inspector_visual_dispose;
widget_class->unroot = gtk_inspector_visual_unroot;
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/inspector/visual.ui");
gtk_widget_class_bind_template_child (widget_class, GtkInspectorVisual, swin);
gtk_widget_class_bind_template_child (widget_class, GtkInspectorVisual, box);

View File

@ -1772,7 +1772,7 @@ treeview.view {
%column_header_button {
padding: 0 6px;
background-image: none;
border-style: none solid solid none;
border-style: none none solid solid;
border-color: $_treeview_borders_color;
border-radius: 0;
text-shadow: none;
@ -3141,15 +3141,15 @@ columnview {
> cell {
padding: 8px 6px;
&:not(:last-child) {
border-right: 1px solid transparent;
&:not(:first-child) {
border-left: 1px solid transparent;
}
}
}
// make column separators visible when :show-column-separators is true
&.column-separators > listview > row > cell {
border-right-color: $_treeview_borders_color;
border-left-color: $_treeview_borders_color;
}
// shrink vertically for .data-table