Merge branch 'cherrypick-for-4-6' into 'gtk-4-6'

Cherry-pick changes from main for gtk-4-6

See merge request GNOME/gtk!4894
This commit is contained in:
Matthias Clasen 2022-07-28 18:10:14 +00:00
commit 2f138ce93b
5 changed files with 173 additions and 107 deletions

View File

@ -208,6 +208,21 @@ gtk_drop_target_end_drop (GtkDropTarget *self)
g_object_thaw_notify (G_OBJECT (self));
}
static GdkDragAction
make_action_unique (GdkDragAction actions)
{
if (actions & GDK_ACTION_COPY)
return GDK_ACTION_COPY;
if (actions & GDK_ACTION_MOVE)
return GDK_ACTION_MOVE;
if (actions & GDK_ACTION_LINK)
return GDK_ACTION_LINK;
return 0;
}
static void
gtk_drop_target_do_drop (GtkDropTarget *self)
{
@ -219,7 +234,7 @@ gtk_drop_target_do_drop (GtkDropTarget *self)
g_signal_emit (self, signals[DROP], 0, &self->value, self->coords.x, self->coords.y, &success);
if (success)
gdk_drop_finish (self->drop, gdk_drop_get_actions (self->drop));
gdk_drop_finish (self->drop, make_action_unique (self->actions & gdk_drop_get_actions (self->drop)));
else
gdk_drop_finish (self->drop, 0);
@ -348,21 +363,6 @@ gtk_drop_target_accept (GtkDropTarget *self,
return gdk_content_formats_match_gtype (self->formats, gdk_drop_get_formats (drop)) != G_TYPE_INVALID;
}
static GdkDragAction
make_action_unique (GdkDragAction actions)
{
if (actions & GDK_ACTION_COPY)
return GDK_ACTION_COPY;
if (actions & GDK_ACTION_MOVE)
return GDK_ACTION_MOVE;
if (actions & GDK_ACTION_LINK)
return GDK_ACTION_LINK;
return 0;
}
static GdkDragAction
gtk_drop_target_enter (GtkDropTarget *self,
double x,

View File

@ -5726,8 +5726,35 @@ drag_scroll_timeout (gpointer data)
return TRUE;
}
static GdkDragAction
gtk_icon_view_get_action (GtkWidget *widget,
GdkDrop *drop)
{
GtkIconView *iconview = GTK_ICON_VIEW (widget);
GdkDrag *drag = gdk_drop_get_drag (drop);
GdkDragAction actions;
actions = gdk_drop_get_actions (drop);
if (drag == iconview->priv->drag &&
actions & GDK_ACTION_MOVE)
return GDK_ACTION_MOVE;
if (actions & GDK_ACTION_COPY)
return GDK_ACTION_COPY;
if (actions & GDK_ACTION_MOVE)
return GDK_ACTION_MOVE;
if (actions & GDK_ACTION_LINK)
return GDK_ACTION_LINK;
return 0;
}
static gboolean
set_destination (GtkIconView *icon_view,
GdkDrop *drop,
GtkDropTargetAsync *dest,
int x,
int y,
@ -5814,7 +5841,7 @@ set_destination (GtkIconView *icon_view,
out:
if (can_drop)
{
*suggested_action = GDK_ACTION_ALL;
*suggested_action = gtk_icon_view_get_action (widget, drop);
gtk_icon_view_set_drag_dest_item (GTK_ICON_VIEW (widget),
path, pos);
@ -6054,7 +6081,7 @@ gtk_icon_view_drag_motion (GtkDropTargetAsync *dest,
gboolean empty;
GdkDragAction result;
if (!set_destination (icon_view, dest, x, y, &suggested_action, &target))
if (!set_destination (icon_view, drop, dest, x, y, &suggested_action, &target))
return 0;
gtk_icon_view_get_drag_dest_item (icon_view, &path, &pos);
@ -6119,7 +6146,7 @@ gtk_icon_view_drag_drop (GtkDropTargetAsync *dest,
if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drop"))
return FALSE;
if (!set_destination (icon_view, dest, x, y, &suggested_action, &target))
if (!set_destination (icon_view, drop, dest, x, y, &suggested_action, &target))
return FALSE;
path = get_logical_destination (icon_view, &drop_append_mode);
@ -6149,32 +6176,6 @@ gtk_icon_view_drag_drop (GtkDropTargetAsync *dest,
return FALSE;
}
static GdkDragAction
gtk_icon_view_get_action (GtkWidget *widget,
GdkDrop *drop)
{
GtkIconView *iconview = GTK_ICON_VIEW (widget);
GdkDrag *drag = gdk_drop_get_drag (drop);
GdkDragAction actions;
actions = gdk_drop_get_actions (drop);
if (drag == iconview->priv->drag &&
actions & GDK_ACTION_MOVE)
return GDK_ACTION_MOVE;
if (actions & GDK_ACTION_COPY)
return GDK_ACTION_COPY;
if (actions & GDK_ACTION_MOVE)
return GDK_ACTION_MOVE;
if (actions & GDK_ACTION_LINK)
return GDK_ACTION_LINK;
return 0;
}
static void
gtk_icon_view_drag_data_received (GObject *source,
GAsyncResult *result,

View File

@ -30,6 +30,8 @@
#include "gtkgizmoprivate.h"
#include "gtkwidgetprivate.h"
#include "gtkbuiltiniconprivate.h"
#include "gtkscrolledwindow.h"
#include "gtkviewport.h"
// TODO
// positioning + sizing
@ -226,12 +228,22 @@ gtk_tree_popover_class_init (GtkTreePopoverClass *class)
G_TYPE_NONE, 1, G_TYPE_STRING);
}
static GtkWidget *
gtk_tree_popover_get_stack (GtkTreePopover *popover)
{
GtkWidget *sw = gtk_popover_get_child (GTK_POPOVER (popover));
GtkWidget *vp = gtk_scrolled_window_get_child (GTK_SCROLLED_WINDOW (sw));
GtkWidget *stack = gtk_viewport_get_child (GTK_VIEWPORT (vp));
return stack;
}
static void
gtk_tree_popover_add_submenu (GtkTreePopover *popover,
GtkWidget *submenu,
const char *name)
{
GtkWidget *stack = gtk_popover_get_child (GTK_POPOVER (popover));
GtkWidget *stack = gtk_tree_popover_get_stack (popover);
gtk_stack_add_named (GTK_STACK (stack), submenu, name);
}
@ -239,7 +251,7 @@ static GtkWidget *
gtk_tree_popover_get_submenu (GtkTreePopover *popover,
const char *name)
{
GtkWidget *stack = gtk_popover_get_child (GTK_POPOVER (popover));
GtkWidget *stack = gtk_tree_popover_get_stack (popover);
return gtk_stack_get_child_by_name (GTK_STACK (stack), name);
}
@ -247,20 +259,27 @@ void
gtk_tree_popover_open_submenu (GtkTreePopover *popover,
const char *name)
{
GtkWidget *stack = gtk_popover_get_child (GTK_POPOVER (popover));
GtkWidget *stack = gtk_tree_popover_get_stack (popover);
gtk_stack_set_visible_child_name (GTK_STACK (stack), name);
}
static void
gtk_tree_popover_init (GtkTreePopover *popover)
{
GtkWidget *sw;
GtkWidget *stack;
sw = gtk_scrolled_window_new ();
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_propagate_natural_width (GTK_SCROLLED_WINDOW (sw), TRUE);
gtk_scrolled_window_set_propagate_natural_height (GTK_SCROLLED_WINDOW (sw), TRUE);
gtk_popover_set_child (GTK_POPOVER (popover), sw);
stack = gtk_stack_new ();
gtk_stack_set_vhomogeneous (GTK_STACK (stack), FALSE);
gtk_stack_set_transition_type (GTK_STACK (stack), GTK_STACK_TRANSITION_TYPE_SLIDE_LEFT_RIGHT);
gtk_stack_set_interpolate_size (GTK_STACK (stack), TRUE);
gtk_popover_set_child (GTK_POPOVER (popover), stack);
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), stack);
gtk_widget_add_css_class (GTK_WIDGET (popover), "menu");
}
@ -465,7 +484,7 @@ static GtkWidget *
gtk_tree_popover_get_path_item (GtkTreePopover *popover,
GtkTreePath *search)
{
GtkWidget *stack = gtk_popover_get_child (GTK_POPOVER (popover));
GtkWidget *stack = gtk_tree_popover_get_stack (popover);
GtkWidget *item = NULL;
GtkWidget *stackchild;
GtkWidget *child;
@ -779,7 +798,7 @@ rebuild_menu (GtkTreePopover *popover)
GtkWidget *stack;
GtkWidget *child;
stack = gtk_popover_get_child (GTK_POPOVER (popover));
stack = gtk_tree_popover_get_stack (popover);
while ((child = gtk_widget_get_first_child (stack)))
gtk_stack_remove (GTK_STACK (stack), child);

View File

@ -2770,6 +2770,13 @@ gtk_tree_view_click_gesture_pressed (GtkGestureClick *gesture,
gboolean rtl;
GtkWidget *target;
gtk_tree_view_convert_widget_to_bin_window_coords (tree_view, x, y,
&bin_x, &bin_y);
/* Are we clicking a column header? */
if (bin_y < 0)
return;
/* check if this is a click in a child widget */
target = gtk_event_controller_get_target (GTK_EVENT_CONTROLLER (gesture));
if (gtk_widget_is_ancestor (target, widget))
@ -2785,11 +2792,6 @@ gtk_tree_view_click_gesture_pressed (GtkGestureClick *gesture,
return;
}
/* Because grab_focus can cause reentrancy, we delay grab_focus until after
* we're done handling the button press.
*/
gtk_tree_view_convert_widget_to_bin_window_coords (tree_view, x, y,
&bin_x, &bin_y);
gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
if (n_press > 1)
@ -3036,6 +3038,11 @@ gtk_tree_view_drag_gesture_begin (GtkGestureDrag *gesture,
gtk_tree_view_convert_widget_to_bin_window_coords (tree_view, start_x, start_y,
&bin_x, &bin_y);
/* Are we dragging a column header? */
if (bin_y < 0)
return;
priv->press_start_x = priv->rubber_band_x = bin_x;
priv->press_start_y = priv->rubber_band_y = bin_y;
gtk_tree_rbtree_find_offset (priv->tree, bin_y + priv->dy,
@ -6845,9 +6852,36 @@ scroll_row_timeout (gpointer data)
return TRUE;
}
static GdkDragAction
gtk_tree_view_get_action (GtkWidget *widget,
GdkDrop *drop)
{
GtkTreeView *tree_view = GTK_TREE_VIEW (widget);
TreeViewDragInfo *di;
GdkDrag *drag = gdk_drop_get_drag (drop);
GdkDragAction actions;
di = get_info (tree_view);
actions = gdk_drop_get_actions (drop);
if (di && di->drag == drag &&
actions & GDK_ACTION_MOVE)
return GDK_ACTION_MOVE;
if (actions & GDK_ACTION_COPY)
return GDK_ACTION_COPY;
if (actions & GDK_ACTION_MOVE)
return GDK_ACTION_MOVE;
return 0;
}
/* Returns TRUE if event should not be propagated to parent widgets */
static gboolean
set_destination_row (GtkTreeView *tree_view,
GdkDrop *drop,
GtkDropTargetAsync *dest,
/* coordinates relative to the widget */
int x,
@ -6953,7 +6987,7 @@ set_destination_row (GtkTreeView *tree_view,
out:
if (can_drop)
{
*suggested_action = GDK_ACTION_COPY | GDK_ACTION_MOVE;
*suggested_action = gtk_tree_view_get_action (widget, drop);
gtk_tree_view_set_drag_dest_row (GTK_TREE_VIEW (widget),
path, pos);
@ -7218,7 +7252,7 @@ gtk_tree_view_drag_motion (GtkDropTargetAsync *dest,
GdkDragAction suggested_action = 0;
GType target;
if (!set_destination_row (tree_view, dest, x, y, &suggested_action, &target))
if (!set_destination_row (tree_view, drop, dest, x, y, &suggested_action, &target))
return 0;
priv->event_last_x = x;
@ -7298,7 +7332,7 @@ gtk_tree_view_drag_drop (GtkDropTargetAsync *dest,
if (!check_model_dnd (model, GTK_TYPE_TREE_DRAG_DEST, "drag_drop"))
return FALSE;
if (!set_destination_row (tree_view, dest, x, y, &suggested_action, &target))
if (!set_destination_row (tree_view, drop, dest, x, y, &suggested_action, &target))
return FALSE;
path = get_logical_dest_row (tree_view, &path_down_mode, &drop_append_mode);
@ -7331,32 +7365,6 @@ gtk_tree_view_drag_drop (GtkDropTargetAsync *dest,
return FALSE;
}
static GdkDragAction
gtk_tree_view_get_action (GtkWidget *widget,
GdkDrop *drop)
{
GtkTreeView *tree_view = GTK_TREE_VIEW (widget);
TreeViewDragInfo *di;
GdkDrag *drag = gdk_drop_get_drag (drop);
GdkDragAction actions;
di = get_info (tree_view);
actions = gdk_drop_get_actions (drop);
if (di && di->drag == drag &&
actions & GDK_ACTION_MOVE)
return GDK_ACTION_MOVE;
if (actions & GDK_ACTION_COPY)
return GDK_ACTION_COPY;
if (actions & GDK_ACTION_MOVE)
return GDK_ACTION_MOVE;
return 0;
}
static void
gtk_tree_view_drag_data_received (GObject *source,
GAsyncResult *result,

View File

@ -8,17 +8,36 @@ window.background:dir(ltr)
arrow:dir(ltr)
[popover.background.menu:dir(ltr)]
contents:dir(ltr)
stack:dir(ltr)
box.vertical:dir(ltr)
modelbutton.flat:dir(ltr)
cellview:dir(ltr)
none.right:dir(ltr)
modelbutton.flat:dir(ltr)
cellview:dir(ltr)
none.right:dir(ltr)
modelbutton.flat:dir(ltr)
cellview:dir(ltr)
none.right:dir(ltr)
scrolledwindow:dir(ltr)
viewport:dir(ltr)
stack:dir(ltr)
box.vertical:dir(ltr)
modelbutton.flat:dir(ltr)
cellview:dir(ltr)
none.right:dir(ltr)
modelbutton.flat:dir(ltr)
cellview:dir(ltr)
none.right:dir(ltr)
modelbutton.flat:dir(ltr)
cellview:dir(ltr)
none.right:dir(ltr)
scrollbar.bottom.horizontal:dir(ltr)
range.horizontal:dir(ltr)
trough:dir(ltr)
slider:dir(ltr)
scrollbar.right.vertical:dir(ltr)
range.vertical:dir(ltr)
trough:dir(ltr)
slider:dir(ltr)
overshoot.left:dir(ltr)
undershoot.left:dir(ltr)
overshoot.right:dir(ltr)
undershoot.right:dir(ltr)
overshoot.top:dir(ltr)
undershoot.top:dir(ltr)
overshoot.bottom:dir(ltr)
undershoot.bottom:dir(ltr)
junction:dir(ltr)
arrow:dir(ltr)
combobox:dir(ltr)
box.horizontal.linked:dir(ltr)
@ -31,15 +50,34 @@ window.background:dir(ltr)
arrow:dir(ltr)
[popover.background.menu:dir(ltr)]
contents:dir(ltr)
stack:dir(ltr)
box.vertical:dir(ltr)
modelbutton.flat:dir(ltr)
cellview:dir(ltr)
none.right:dir(ltr)
modelbutton.flat:dir(ltr)
cellview:dir(ltr)
none.right:dir(ltr)
modelbutton.flat:dir(ltr)
cellview:dir(ltr)
none.right:dir(ltr)
scrolledwindow:dir(ltr)
viewport:dir(ltr)
stack:dir(ltr)
box.vertical:dir(ltr)
modelbutton.flat:dir(ltr)
cellview:dir(ltr)
none.right:dir(ltr)
modelbutton.flat:dir(ltr)
cellview:dir(ltr)
none.right:dir(ltr)
modelbutton.flat:dir(ltr)
cellview:dir(ltr)
none.right:dir(ltr)
scrollbar.bottom.horizontal:dir(ltr)
range.horizontal:dir(ltr)
trough:dir(ltr)
slider:dir(ltr)
scrollbar.right.vertical:dir(ltr)
range.vertical:dir(ltr)
trough:dir(ltr)
slider:dir(ltr)
overshoot.left:dir(ltr)
undershoot.left:dir(ltr)
overshoot.right:dir(ltr)
undershoot.right:dir(ltr)
overshoot.top:dir(ltr)
undershoot.top:dir(ltr)
overshoot.bottom:dir(ltr)
undershoot.bottom:dir(ltr)
junction:dir(ltr)
arrow:dir(ltr)