static void ide_frame_pan_update (IdeFrame *self, GdkEventSequence *sequence, GtkGestureSwipe *gesture) { IdeFramePrivate *priv = ide_frame_get_instance_private (self); GtkAllocation alloc; GtkWidget *grid; gdouble x, y; IDE_ENTRY; g_assert (IDE_IS_FRAME (self)); g_assert (GTK_IS_GESTURE_PAN (gesture)); g_assert (!priv->pan_theatric || DZL_IS_BOX_THEATRIC (priv->pan_theatric)); if (priv->pan_theatric == NULL) { if (sequence != NULL) gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_DENIED); IDE_EXIT; } gtk_gesture_drag_get_offset (GTK_GESTURE_DRAG (gesture), &x, &y); gtk_widget_get_allocation (GTK_WIDGET (self), &alloc); grid = gtk_widget_get_ancestor (GTK_WIDGET (self), IDE_TYPE_GRID); gtk_widget_translate_coordinates (GTK_WIDGET (priv->top_stack), grid, 0, 0, &alloc.x, &alloc.y); g_object_set (priv->pan_theatric, "x", alloc.x + (gint)x, NULL); IDE_EXIT; }
static void gstyle_color_widget_drag_gesture_update (GtkGestureDrag *gesture, gdouble offset_x, gdouble offset_y, GstyleColorWidget *self) { GdkDragContext *context; GdkEventSequence *sequence; const GdkEvent *event; gdouble start_x, start_y; GtkAllocation allocation; GstylePaletteWidgetDndLockFlags dnd_lock; GtkWidget *container; GdkDragAction drag_action; gint button; g_assert (GTK_IS_GESTURE (gesture)); g_assert (GSTYLE_IS_COLOR_WIDGET (self)); dnd_lock = get_palette_widget_dnd_lock (self); if ((dnd_lock & GSTYLE_PALETTE_WIDGET_DND_LOCK_FLAGS_DRAG) != 0) return; button = gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture)); if (!gtk_drag_check_threshold (GTK_WIDGET (self), 0, 0, offset_x, offset_y) || button != GDK_BUTTON_PRIMARY) return; gtk_widget_get_allocation (GTK_WIDGET (self), &allocation); self->dnd_color_widget = gstyle_color_widget_copy (self); if (self->filter_func != NULL && GSTYLE_IS_COLOR (self->filtered_color)) gstyle_color_widget_set_color (self->dnd_color_widget, self->filtered_color); self->dnd_window = gtk_window_new (GTK_WINDOW_POPUP); gtk_widget_set_size_request (self->dnd_window, allocation.width, allocation.height); gtk_window_set_screen (GTK_WINDOW (self->dnd_window), gtk_widget_get_screen (GTK_WIDGET (self))); gtk_container_add (GTK_CONTAINER (self->dnd_window), GTK_WIDGET (self->dnd_color_widget)); gtk_widget_show_all (self->dnd_window); gtk_widget_set_opacity (self->dnd_window, GSTYLE_COLOR_WIDGET_DRAG_ICON_OPACITY); sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture)); gtk_gesture_drag_get_start_point (GTK_GESTURE_DRAG (gesture), &start_x, &start_y); event = gtk_gesture_get_last_event (GTK_GESTURE (gesture), sequence); container = gtk_widget_get_ancestor (GTK_WIDGET (self), GSTYLE_TYPE_PALETTE_WIDGET); if (container != NULL && GSTYLE_IS_PALETTE_WIDGET (container)) drag_action = (GDK_ACTION_MOVE | GDK_ACTION_COPY); else drag_action = GDK_ACTION_COPY; context = gtk_drag_begin_with_coordinates (GTK_WIDGET (self), self->target_list, drag_action, button, (GdkEvent*)event, start_x, start_y); gtk_drag_set_icon_widget (context, self->dnd_window, 0, 0); }
static void ide_frame_pan_end (IdeFrame *self, GdkEventSequence *sequence, GtkGesturePan *gesture) { IdeFramePrivate *priv = ide_frame_get_instance_private (self); IdeFramePrivate *dest_priv; IdeFrame *dest; GtkAllocation alloc; GtkWidget *grid; GtkWidget *column; gdouble x, y; gint direction; gint index = 0; IDE_ENTRY; g_assert (IDE_IS_FRAME (self)); g_assert (GTK_IS_GESTURE_PAN (gesture)); if (priv->pan_theatric == NULL || priv->pan_page == NULL) IDE_GOTO (cleanup); gtk_widget_get_allocation (GTK_WIDGET (self), &alloc); gtk_gesture_drag_get_offset (GTK_GESTURE_DRAG (gesture), &x, &y); if (x > DISTANCE_THRESHOLD (&alloc)) direction = 1; else if (x < -DISTANCE_THRESHOLD (&alloc)) direction = -1; else direction = 0; grid = gtk_widget_get_ancestor (GTK_WIDGET (self), IDE_TYPE_GRID); g_assert (grid != NULL); g_assert (IDE_IS_GRID (grid)); column = gtk_widget_get_ancestor (GTK_WIDGET (self), IDE_TYPE_GRID_COLUMN); g_assert (column != NULL); g_assert (IDE_IS_GRID_COLUMN (column)); gtk_container_child_get (GTK_CONTAINER (grid), GTK_WIDGET (column), "index", &index, NULL); dest = _ide_grid_get_nth_stack (IDE_GRID (grid), index + direction); dest_priv = ide_frame_get_instance_private (dest); g_assert (dest != NULL); g_assert (IDE_IS_FRAME (dest)); gtk_widget_get_allocation (GTK_WIDGET (dest), &alloc); if (!is_uninitialized (&alloc)) { AnimationState *state; state = g_slice_new0 (AnimationState); state->source = g_object_ref (self); state->dest = g_object_ref (dest); state->page = g_object_ref (priv->pan_page); state->theatric = g_object_ref (priv->pan_theatric); gtk_widget_translate_coordinates (GTK_WIDGET (dest_priv->top_stack), grid, 0, 0, &alloc.x, &alloc.y); /* * Use EASE_OUT_CUBIC, because user initiated the beginning of the * acceleration curve just by swiping. No need to duplicate. */ dzl_object_animate_full (state->theatric, DZL_ANIMATION_EASE_OUT_CUBIC, TRANSITION_DURATION, gtk_widget_get_frame_clock (GTK_WIDGET (self)), animation_state_complete, state, "x", alloc.x, "width", alloc.width, NULL); if (dest != self) { g_ptr_array_add (priv->in_transition, g_object_ref (priv->pan_page)); gtk_container_remove (GTK_CONTAINER (priv->stack), GTK_WIDGET (priv->pan_page)); } IDE_TRACE_MSG ("Animating transition to %s column", dest != self ? "another" : "same"); } else { g_autoptr(IdePage) page = g_object_ref (priv->pan_page); IDE_TRACE_MSG ("Moving page to a previously non-existant column"); gtk_container_remove (GTK_CONTAINER (priv->stack), GTK_WIDGET (page)); gtk_widget_show (GTK_WIDGET (page)); gtk_container_add (GTK_CONTAINER (dest_priv->stack), GTK_WIDGET (page)); } cleanup: g_clear_object (&priv->pan_theatric); g_clear_object (&priv->pan_page); gtk_widget_queue_draw (gtk_widget_get_toplevel (GTK_WIDGET (self))); ide_frame_set_cursor (self, "arrow"); IDE_EXIT; }
static gboolean ide_frame_pan_begin (IdeFrame *self, GdkEventSequence *sequence, GtkGesturePan *gesture) { IdeFramePrivate *priv = ide_frame_get_instance_private (self); GtkAllocation alloc; cairo_surface_t *surface = NULL; IdePage *page; GdkWindow *window; GtkWidget *grid; cairo_t *cr; gdouble x, y; gboolean enable_animations; IDE_ENTRY; g_assert (IDE_IS_FRAME (self)); g_assert (GTK_IS_GESTURE_PAN (gesture)); g_assert (priv->pan_theatric == NULL); page = ide_frame_get_visible_child (self); if (page != NULL) gtk_widget_get_allocation (GTK_WIDGET (page), &alloc); g_object_get (gtk_settings_get_default (), "gtk-enable-animations", &enable_animations, NULL); if (sequence != NULL || page == NULL || !enable_animations || is_uninitialized (&alloc) || NULL == (window = gtk_widget_get_window (GTK_WIDGET (page))) || NULL == (surface = gdk_window_create_similar_surface (window, CAIRO_CONTENT_COLOR, alloc.width, alloc.height))) { if (sequence != NULL) gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_DENIED); IDE_RETURN (FALSE); } gtk_gesture_drag_get_offset (GTK_GESTURE_DRAG (gesture), &x, &y); cr = cairo_create (surface); gtk_widget_draw (GTK_WIDGET (page), cr); cairo_destroy (cr); grid = gtk_widget_get_ancestor (GTK_WIDGET (self), IDE_TYPE_GRID); gtk_widget_translate_coordinates (GTK_WIDGET (priv->top_stack), grid, 0, 0, &alloc.x, &alloc.y); priv->pan_page = g_object_ref (page); priv->pan_theatric = g_object_new (DZL_TYPE_BOX_THEATRIC, "surface", surface, "target", grid, "x", alloc.x + (gint)x, "y", alloc.y, "width", alloc.width, "height", alloc.height, NULL); g_clear_pointer (&surface, cairo_surface_destroy); /* Hide the page while we begin the possible transition to another * layout stack. */ gtk_widget_hide (GTK_WIDGET (priv->pan_page)); /* * Hide the mouse cursor until ide_frame_pan_end() is called. * It can be distracting otherwise (and we want to warp it to the new * grid column too). */ ide_frame_set_cursor (self, "none"); IDE_RETURN (TRUE); }