2012-07-11 13:51:43 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* Copyright © 2012 Carlos Garnacho <carlosg@gnome.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "gtkprivatetypebuiltins.h"
|
|
|
|
#include "gtktexthandleprivate.h"
|
|
|
|
#include "gtkmarshalers.h"
|
|
|
|
#include "gtkprivate.h"
|
2014-01-22 15:33:47 +00:00
|
|
|
#include "gtkwindowprivate.h"
|
2015-11-10 04:33:54 +00:00
|
|
|
#include "gtkcssnodeprivate.h"
|
|
|
|
#include "gtkwidgetprivate.h"
|
2018-06-12 10:33:03 +00:00
|
|
|
#include "gtkgizmoprivate.h"
|
|
|
|
#include "gtkrendericonprivate.h"
|
2012-07-11 13:51:43 +00:00
|
|
|
#include "gtkintl.h"
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
typedef struct _GtkTextHandlePrivate GtkTextHandlePrivate;
|
|
|
|
typedef struct _HandleWindow HandleWindow;
|
|
|
|
|
|
|
|
enum {
|
2015-06-07 16:45:34 +00:00
|
|
|
DRAG_STARTED,
|
2012-07-11 13:51:43 +00:00
|
|
|
HANDLE_DRAGGED,
|
|
|
|
DRAG_FINISHED,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PROP_0,
|
2013-12-23 18:15:30 +00:00
|
|
|
PROP_PARENT
|
2012-07-11 13:51:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _HandleWindow
|
|
|
|
{
|
2013-12-23 18:09:10 +00:00
|
|
|
GtkWidget *widget;
|
2012-07-11 13:51:43 +00:00
|
|
|
GdkRectangle pointing_to;
|
2015-06-10 01:19:17 +00:00
|
|
|
GtkBorder border;
|
2012-07-11 13:51:43 +00:00
|
|
|
gint dx;
|
|
|
|
gint dy;
|
2015-06-10 18:52:02 +00:00
|
|
|
GtkTextDirection dir;
|
2012-07-11 13:51:43 +00:00
|
|
|
guint dragged : 1;
|
2012-11-07 13:23:04 +00:00
|
|
|
guint mode_visible : 1;
|
|
|
|
guint user_visible : 1;
|
|
|
|
guint has_point : 1;
|
2012-07-11 13:51:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GtkTextHandlePrivate
|
|
|
|
{
|
|
|
|
HandleWindow windows[2];
|
2019-02-23 05:46:44 +00:00
|
|
|
GtkWidget *toplevel;
|
2012-07-11 13:51:43 +00:00
|
|
|
GtkWidget *parent;
|
2014-01-22 15:39:10 +00:00
|
|
|
GtkScrollable *parent_scrollable;
|
|
|
|
GtkAdjustment *vadj;
|
|
|
|
GtkAdjustment *hadj;
|
2014-01-22 15:33:47 +00:00
|
|
|
guint hierarchy_changed_id;
|
2014-01-22 15:39:10 +00:00
|
|
|
guint scrollable_notify_id;
|
2012-07-11 13:51:43 +00:00
|
|
|
guint mode : 2;
|
|
|
|
};
|
|
|
|
|
2013-06-27 19:02:52 +00:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GtkTextHandle, _gtk_text_handle, G_TYPE_OBJECT)
|
2012-07-11 13:51:43 +00:00
|
|
|
|
|
|
|
static guint signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
2013-12-23 18:09:10 +00:00
|
|
|
static void _gtk_text_handle_update (GtkTextHandle *handle,
|
|
|
|
GtkTextHandlePosition pos);
|
|
|
|
|
2012-07-11 13:51:43 +00:00
|
|
|
static void
|
2016-10-04 19:13:29 +00:00
|
|
|
_gtk_text_handle_get_size (GtkTextHandle *handle,
|
|
|
|
GtkTextHandlePosition pos,
|
|
|
|
gint *width,
|
|
|
|
gint *height)
|
2012-07-11 13:51:43 +00:00
|
|
|
{
|
2016-10-04 19:13:29 +00:00
|
|
|
GtkTextHandlePrivate *priv = handle->priv;
|
|
|
|
GtkWidget *widget = priv->windows[pos].widget;
|
|
|
|
GtkStyleContext *context;
|
2012-07-11 13:51:43 +00:00
|
|
|
|
2016-10-04 19:13:29 +00:00
|
|
|
context = gtk_widget_get_style_context (widget);
|
|
|
|
|
|
|
|
gtk_style_context_get (context,
|
2016-10-08 03:07:23 +00:00
|
|
|
"min-width", width,
|
|
|
|
"min-height", height,
|
|
|
|
NULL);
|
2012-07-11 13:51:43 +00:00
|
|
|
}
|
|
|
|
|
2013-12-23 18:09:10 +00:00
|
|
|
static gint
|
|
|
|
_text_handle_pos_from_widget (GtkTextHandle *handle,
|
|
|
|
GtkWidget *widget)
|
2012-07-11 13:51:43 +00:00
|
|
|
{
|
2013-12-23 18:09:10 +00:00
|
|
|
GtkTextHandlePrivate *priv = handle->priv;
|
2012-07-11 13:51:43 +00:00
|
|
|
|
2013-12-23 18:09:10 +00:00
|
|
|
if (widget == priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_START].widget)
|
|
|
|
return GTK_TEXT_HANDLE_POSITION_SELECTION_START;
|
|
|
|
else if (widget == priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_END].widget)
|
|
|
|
return GTK_TEXT_HANDLE_POSITION_SELECTION_END;
|
2012-07-11 13:51:43 +00:00
|
|
|
else
|
2013-12-23 18:09:10 +00:00
|
|
|
return -1;
|
2012-07-11 13:51:43 +00:00
|
|
|
}
|
|
|
|
|
2018-06-12 10:33:03 +00:00
|
|
|
static void
|
|
|
|
handle_drag_begin (GtkGestureDrag *gesture,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
GtkTextHandle *handle)
|
2012-07-11 13:51:43 +00:00
|
|
|
{
|
2018-06-12 10:33:03 +00:00
|
|
|
GtkTextHandlePrivate *priv = handle->priv;
|
|
|
|
GtkWidget *widget;
|
2013-12-23 18:09:10 +00:00
|
|
|
gint pos;
|
2012-07-11 13:51:43 +00:00
|
|
|
|
2018-06-12 10:33:03 +00:00
|
|
|
widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture));
|
2013-12-23 18:09:10 +00:00
|
|
|
pos = _text_handle_pos_from_widget (handle, widget);
|
2012-07-11 13:51:43 +00:00
|
|
|
|
2018-06-12 10:33:03 +00:00
|
|
|
if (pos == GTK_TEXT_HANDLE_POSITION_CURSOR &&
|
|
|
|
priv->mode == GTK_TEXT_HANDLE_MODE_CURSOR)
|
|
|
|
x -= gtk_widget_get_width (widget) / 2;
|
|
|
|
else if ((pos == GTK_TEXT_HANDLE_POSITION_CURSOR &&
|
|
|
|
priv->windows[pos].dir == GTK_TEXT_DIR_RTL) ||
|
|
|
|
(pos == GTK_TEXT_HANDLE_POSITION_SELECTION_START &&
|
|
|
|
priv->windows[pos].dir != GTK_TEXT_DIR_RTL))
|
|
|
|
x -= gtk_widget_get_width (widget);
|
|
|
|
|
|
|
|
y += priv->windows[pos].border.top / 2;
|
|
|
|
|
|
|
|
priv->windows[pos].dx = x;
|
|
|
|
priv->windows[pos].dy = y;
|
|
|
|
priv->windows[pos].dragged = TRUE;
|
|
|
|
g_signal_emit (handle, signals[DRAG_STARTED], 0, pos);
|
|
|
|
}
|
2012-07-11 13:51:43 +00:00
|
|
|
|
2018-06-12 10:33:03 +00:00
|
|
|
static void
|
|
|
|
handle_drag_update (GtkGestureDrag *gesture,
|
|
|
|
gdouble offset_x,
|
|
|
|
gdouble offset_y,
|
|
|
|
GtkTextHandle *handle)
|
|
|
|
{
|
|
|
|
GtkTextHandlePrivate *priv = handle->priv;
|
|
|
|
gdouble start_x, start_y;
|
|
|
|
gint pos, x, y;
|
|
|
|
|
|
|
|
pos = _text_handle_pos_from_widget (handle,
|
|
|
|
gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture)));
|
|
|
|
gtk_gesture_drag_get_start_point (gesture, &start_x, &start_y);
|
|
|
|
|
|
|
|
gtk_widget_translate_coordinates (priv->windows[pos].widget, priv->parent,
|
|
|
|
start_x + offset_x - priv->windows[pos].dx,
|
|
|
|
start_y + offset_y - priv->windows[pos].dy,
|
|
|
|
&x, &y);
|
|
|
|
g_signal_emit (handle, signals[HANDLE_DRAGGED], 0, pos, x, y);
|
2012-07-11 13:51:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-06-12 10:33:03 +00:00
|
|
|
handle_drag_end (GtkGestureDrag *gesture,
|
|
|
|
gdouble offset_x,
|
|
|
|
gdouble offset_y,
|
|
|
|
GtkTextHandle *handle)
|
2013-12-23 18:09:10 +00:00
|
|
|
{
|
2018-06-12 10:33:03 +00:00
|
|
|
GtkTextHandlePrivate *priv = handle->priv;
|
|
|
|
gint pos;
|
2014-11-20 12:41:24 +00:00
|
|
|
|
2018-06-12 10:33:03 +00:00
|
|
|
pos = _text_handle_pos_from_widget (handle,
|
|
|
|
gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture)));
|
|
|
|
g_signal_emit (handle, signals[DRAG_FINISHED], 0, pos);
|
|
|
|
priv->windows[pos].dragged = FALSE;
|
|
|
|
}
|
|
|
|
|
2019-01-18 07:01:40 +00:00
|
|
|
static void
|
2018-06-12 10:33:03 +00:00
|
|
|
snapshot_func (GtkGizmo *gizmo,
|
|
|
|
GtkSnapshot *snapshot)
|
|
|
|
{
|
|
|
|
GtkCssStyle *style = gtk_css_node_get_style (gtk_widget_get_css_node (GTK_WIDGET (gizmo)));
|
2014-11-20 12:41:24 +00:00
|
|
|
|
2018-06-12 10:33:03 +00:00
|
|
|
gtk_css_style_snapshot_icon (style,
|
|
|
|
snapshot,
|
|
|
|
gtk_widget_get_width (GTK_WIDGET (gizmo)),
|
|
|
|
gtk_widget_get_height (GTK_WIDGET (gizmo)),
|
|
|
|
GTK_CSS_IMAGE_BUILTIN_HANDLE);
|
2013-12-23 18:09:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget *
|
|
|
|
_gtk_text_handle_ensure_widget (GtkTextHandle *handle,
|
|
|
|
GtkTextHandlePosition pos)
|
2012-07-11 13:51:43 +00:00
|
|
|
{
|
|
|
|
GtkTextHandlePrivate *priv;
|
|
|
|
|
|
|
|
priv = handle->priv;
|
|
|
|
|
2013-12-23 18:09:10 +00:00
|
|
|
if (!priv->windows[pos].widget)
|
2012-07-11 13:51:43 +00:00
|
|
|
{
|
2013-12-23 18:09:10 +00:00
|
|
|
GtkWidget *widget, *window;
|
2015-11-10 04:33:54 +00:00
|
|
|
GtkStyleContext *context;
|
2018-06-12 10:33:03 +00:00
|
|
|
GtkEventController *controller;
|
2013-12-23 18:09:10 +00:00
|
|
|
|
2018-06-12 10:33:03 +00:00
|
|
|
widget = gtk_gizmo_new (I_("cursor-handle"),
|
|
|
|
NULL, NULL, snapshot_func);
|
2013-12-23 18:09:10 +00:00
|
|
|
|
2015-06-10 18:52:02 +00:00
|
|
|
gtk_widget_set_direction (widget, priv->windows[pos].dir);
|
|
|
|
|
2018-06-12 10:33:03 +00:00
|
|
|
controller = GTK_EVENT_CONTROLLER (gtk_gesture_drag_new ());
|
|
|
|
g_signal_connect (controller, "drag-begin",
|
|
|
|
G_CALLBACK (handle_drag_begin), handle);
|
|
|
|
g_signal_connect (controller, "drag-update",
|
|
|
|
G_CALLBACK (handle_drag_update), handle);
|
|
|
|
g_signal_connect (controller, "drag-end",
|
|
|
|
G_CALLBACK (handle_drag_end), handle);
|
|
|
|
gtk_widget_add_controller (widget, controller);
|
2013-12-23 18:09:10 +00:00
|
|
|
|
popover: Fix memory management of popovers
Popovers are strange in the sense that they aren't attached to a
parent directly, they rely on the relative_to widget so the toplevel
is shared, and when they have a parent, it is the toplevel itself,
not relative_to. This also means that there are conditions where the
popover loses it's parent, so they must survive unparenting.
The previous code would be floating the last reference as soon as the
parent is gone, but it was non-obvious who'd own that reference. So
fix this situation by granting the ownership of popovers to their
relative_to widget, an extra reference may be held by the toplevel
when the popover has a parent, but the popover object will be
guaranteed to be alive as long as the parent lives.
This way, memory management of popovers is as hidden from the user
as regular widgets within containers are, users are free to call
gtk_widget_destroy() on a popover, but it'd eventually become
destructed when relative_to is.
2014-01-09 16:21:43 +00:00
|
|
|
priv->windows[pos].widget = g_object_ref_sink (widget);
|
2019-02-23 05:46:44 +00:00
|
|
|
priv->toplevel = window = gtk_widget_get_ancestor (priv->parent, GTK_TYPE_WINDOW);
|
2015-07-06 14:39:06 +00:00
|
|
|
_gtk_window_add_popover (GTK_WINDOW (window), widget, priv->parent, FALSE);
|
2014-11-20 12:41:24 +00:00
|
|
|
|
2015-11-10 04:33:54 +00:00
|
|
|
context = gtk_widget_get_style_context (widget);
|
|
|
|
gtk_style_context_set_parent (context, gtk_widget_get_style_context (priv->parent));
|
|
|
|
if (pos == GTK_TEXT_HANDLE_POSITION_SELECTION_END)
|
|
|
|
{
|
|
|
|
gtk_style_context_add_class (context, GTK_STYLE_CLASS_BOTTOM);
|
|
|
|
if (priv->mode == GTK_TEXT_HANDLE_MODE_CURSOR)
|
|
|
|
gtk_style_context_add_class (context, GTK_STYLE_CLASS_INSERTION_CURSOR);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
gtk_style_context_add_class (context, GTK_STYLE_CLASS_TOP);
|
2012-07-11 13:51:43 +00:00
|
|
|
}
|
2013-12-23 18:09:10 +00:00
|
|
|
|
|
|
|
return priv->windows[pos].widget;
|
2012-11-07 13:23:04 +00:00
|
|
|
}
|
2012-07-11 13:51:43 +00:00
|
|
|
|
2014-01-22 15:41:00 +00:00
|
|
|
static void
|
|
|
|
_handle_update_child_visible (GtkTextHandle *handle,
|
|
|
|
GtkTextHandlePosition pos)
|
|
|
|
{
|
|
|
|
HandleWindow *handle_window;
|
|
|
|
GtkTextHandlePrivate *priv;
|
|
|
|
cairo_rectangle_int_t rect;
|
|
|
|
GtkAllocation allocation;
|
|
|
|
GtkWidget *parent;
|
|
|
|
|
|
|
|
priv = handle->priv;
|
|
|
|
handle_window = &priv->windows[pos];
|
|
|
|
|
|
|
|
if (!priv->parent_scrollable)
|
|
|
|
{
|
|
|
|
gtk_widget_set_child_visible (handle_window->widget, TRUE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
parent = gtk_widget_get_parent (GTK_WIDGET (priv->parent_scrollable));
|
|
|
|
rect = handle_window->pointing_to;
|
|
|
|
|
|
|
|
gtk_widget_translate_coordinates (priv->parent, parent,
|
|
|
|
rect.x, rect.y, &rect.x, &rect.y);
|
|
|
|
|
|
|
|
gtk_widget_get_allocation (GTK_WIDGET (parent), &allocation);
|
|
|
|
|
|
|
|
if (rect.x < 0 || rect.x + rect.width > allocation.width ||
|
|
|
|
rect.y < 0 || rect.y + rect.height > allocation.height)
|
|
|
|
gtk_widget_set_child_visible (handle_window->widget, FALSE);
|
|
|
|
else
|
|
|
|
gtk_widget_set_child_visible (handle_window->widget, TRUE);
|
|
|
|
}
|
|
|
|
|
2012-11-07 13:23:04 +00:00
|
|
|
static void
|
2013-12-23 18:09:10 +00:00
|
|
|
_gtk_text_handle_update (GtkTextHandle *handle,
|
|
|
|
GtkTextHandlePosition pos)
|
2012-11-07 13:23:04 +00:00
|
|
|
{
|
|
|
|
GtkTextHandlePrivate *priv;
|
|
|
|
HandleWindow *handle_window;
|
2015-06-10 01:19:17 +00:00
|
|
|
GtkBorder *border;
|
2012-07-11 13:51:43 +00:00
|
|
|
|
2012-11-07 13:23:04 +00:00
|
|
|
priv = handle->priv;
|
|
|
|
handle_window = &priv->windows[pos];
|
2015-06-10 01:19:17 +00:00
|
|
|
border = &handle_window->border;
|
2012-07-11 13:51:43 +00:00
|
|
|
|
2013-12-23 18:09:10 +00:00
|
|
|
if (!priv->parent || !gtk_widget_is_drawable (priv->parent))
|
2012-11-07 13:23:04 +00:00
|
|
|
return;
|
|
|
|
|
2013-12-23 18:09:10 +00:00
|
|
|
if (handle_window->has_point &&
|
|
|
|
handle_window->mode_visible && handle_window->user_visible)
|
2012-07-11 13:51:43 +00:00
|
|
|
{
|
2013-12-23 18:09:10 +00:00
|
|
|
cairo_rectangle_int_t rect;
|
|
|
|
gint width, height;
|
|
|
|
GtkWidget *window;
|
2015-06-10 01:19:17 +00:00
|
|
|
GtkAllocation alloc;
|
|
|
|
gint w, h;
|
2013-12-23 18:09:10 +00:00
|
|
|
|
|
|
|
_gtk_text_handle_ensure_widget (handle, pos);
|
2016-10-04 19:13:29 +00:00
|
|
|
_gtk_text_handle_get_size (handle, pos, &width, &height);
|
2014-01-22 15:41:00 +00:00
|
|
|
|
2015-10-14 15:21:25 +00:00
|
|
|
border->top = height;
|
|
|
|
border->bottom = height;
|
2015-06-10 01:19:17 +00:00
|
|
|
border->left = width;
|
|
|
|
border->right = width;
|
2014-05-16 17:59:31 +00:00
|
|
|
|
2015-10-14 15:21:25 +00:00
|
|
|
rect.x = handle_window->pointing_to.x;
|
|
|
|
rect.y = handle_window->pointing_to.y + handle_window->pointing_to.height - handle_window->border.top;
|
|
|
|
rect.width = width;
|
|
|
|
rect.height = 0;
|
|
|
|
|
2014-01-22 15:41:00 +00:00
|
|
|
_handle_update_child_visible (handle, pos);
|
2012-11-07 13:23:04 +00:00
|
|
|
|
2013-12-23 18:09:10 +00:00
|
|
|
window = gtk_widget_get_parent (handle_window->widget);
|
|
|
|
gtk_widget_translate_coordinates (priv->parent, window,
|
|
|
|
rect.x, rect.y, &rect.x, &rect.y);
|
2012-07-11 13:51:43 +00:00
|
|
|
|
2015-06-10 17:54:34 +00:00
|
|
|
if (pos == GTK_TEXT_HANDLE_POSITION_CURSOR &&
|
|
|
|
priv->mode == GTK_TEXT_HANDLE_MODE_CURSOR)
|
|
|
|
rect.x -= rect.width / 2;
|
2015-06-10 18:52:02 +00:00
|
|
|
else if ((pos == GTK_TEXT_HANDLE_POSITION_CURSOR &&
|
|
|
|
handle_window->dir == GTK_TEXT_DIR_RTL) ||
|
|
|
|
(pos == GTK_TEXT_HANDLE_POSITION_SELECTION_START &&
|
|
|
|
handle_window->dir != GTK_TEXT_DIR_RTL))
|
2015-06-10 17:54:34 +00:00
|
|
|
rect.x -= rect.width;
|
|
|
|
|
2015-06-10 01:19:17 +00:00
|
|
|
/* The goal is to make the window 3 times as wide and high. The handle
|
|
|
|
* will be rendered in the center, making the rest an invisible border.
|
|
|
|
* If we hit the edge of the toplevel, we shrink the border to avoid
|
|
|
|
* mispositioning the handle, if at all possible. This calculation uses
|
|
|
|
* knowledge about how popover_get_rect() works.
|
|
|
|
*/
|
|
|
|
|
|
|
|
gtk_widget_get_allocation (window, &alloc);
|
|
|
|
|
|
|
|
w = width + border->left + border->right;
|
|
|
|
h = height + border->top + border->bottom;
|
|
|
|
|
|
|
|
if (rect.x + rect.width/2 - w/2 < alloc.x)
|
|
|
|
border->left = MAX (0, border->left - (alloc.x - (rect.x + rect.width/2 - w/2)));
|
|
|
|
if (rect.y + rect.height/2 - h/2 < alloc.y)
|
|
|
|
border->top = MAX (0, border->top - (alloc.y - (rect.y + rect.height/2 - h/2)));
|
|
|
|
if (rect.x + rect.width/2 + w/2 > alloc.x + alloc.width)
|
|
|
|
border->right = MAX (0, border->right - (rect.x + rect.width/2 + w/2 - (alloc.x + alloc.width)));
|
|
|
|
if (rect.y + rect.height/2 + h/2 > alloc.y + alloc.height)
|
|
|
|
border->bottom = MAX (0, border->bottom - (rect.y + rect.height/2 + h/2 - (alloc.y + alloc.height)));
|
|
|
|
|
|
|
|
width += border->left + border->right;
|
|
|
|
height += border->top + border->bottom;
|
2013-12-23 18:09:10 +00:00
|
|
|
|
|
|
|
gtk_widget_set_size_request (handle_window->widget, width, height);
|
|
|
|
gtk_widget_show (handle_window->widget);
|
2015-10-22 16:14:01 +00:00
|
|
|
_gtk_window_raise_popover (GTK_WINDOW (window), handle_window->widget);
|
2014-01-17 17:12:57 +00:00
|
|
|
_gtk_window_set_popover_position (GTK_WINDOW (window),
|
|
|
|
handle_window->widget,
|
2015-06-10 17:54:34 +00:00
|
|
|
GTK_POS_BOTTOM, &rect);
|
2013-12-23 18:09:10 +00:00
|
|
|
}
|
|
|
|
else if (handle_window->widget)
|
|
|
|
gtk_widget_hide (handle_window->widget);
|
2012-07-11 13:51:43 +00:00
|
|
|
}
|
|
|
|
|
2014-01-22 15:39:10 +00:00
|
|
|
static void
|
|
|
|
adjustment_changed_cb (GtkAdjustment *adjustment,
|
|
|
|
GtkTextHandle *handle)
|
|
|
|
{
|
|
|
|
_gtk_text_handle_update (handle, GTK_TEXT_HANDLE_POSITION_SELECTION_START);
|
|
|
|
_gtk_text_handle_update (handle, GTK_TEXT_HANDLE_POSITION_SELECTION_END);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_gtk_text_handle_set_scrollable (GtkTextHandle *handle,
|
|
|
|
GtkScrollable *scrollable)
|
|
|
|
{
|
|
|
|
GtkTextHandlePrivate *priv;
|
|
|
|
|
|
|
|
priv = handle->priv;
|
|
|
|
|
2016-11-23 18:55:28 +00:00
|
|
|
if (priv->vadj)
|
2014-01-22 15:39:10 +00:00
|
|
|
{
|
2016-11-23 18:55:28 +00:00
|
|
|
g_signal_handlers_disconnect_by_data (priv->vadj, handle);
|
|
|
|
g_clear_object (&priv->vadj);
|
|
|
|
}
|
2014-01-22 15:39:10 +00:00
|
|
|
|
2016-11-23 18:55:28 +00:00
|
|
|
if (priv->hadj)
|
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_data (priv->hadj, handle);
|
|
|
|
g_clear_object (&priv->hadj);
|
2014-01-22 15:39:10 +00:00
|
|
|
}
|
|
|
|
|
2016-11-23 18:55:28 +00:00
|
|
|
if (priv->parent_scrollable)
|
|
|
|
g_object_remove_weak_pointer (G_OBJECT (priv->parent_scrollable), (gpointer *) &priv->parent_scrollable);
|
|
|
|
|
2014-01-22 15:39:10 +00:00
|
|
|
priv->parent_scrollable = scrollable;
|
|
|
|
|
|
|
|
if (scrollable)
|
|
|
|
{
|
2014-02-18 03:27:35 +00:00
|
|
|
g_object_add_weak_pointer (G_OBJECT (priv->parent_scrollable), (gpointer *) &priv->parent_scrollable);
|
|
|
|
|
2014-01-22 15:39:10 +00:00
|
|
|
priv->vadj = gtk_scrollable_get_vadjustment (scrollable);
|
|
|
|
priv->hadj = gtk_scrollable_get_hadjustment (scrollable);
|
|
|
|
|
|
|
|
if (priv->vadj)
|
|
|
|
{
|
|
|
|
g_object_ref (priv->vadj);
|
|
|
|
g_signal_connect (priv->vadj, "changed",
|
|
|
|
G_CALLBACK (adjustment_changed_cb), handle);
|
|
|
|
g_signal_connect (priv->vadj, "value-changed",
|
|
|
|
G_CALLBACK (adjustment_changed_cb), handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->hadj)
|
|
|
|
{
|
|
|
|
g_object_ref (priv->hadj);
|
|
|
|
g_signal_connect (priv->hadj, "changed",
|
|
|
|
G_CALLBACK (adjustment_changed_cb), handle);
|
|
|
|
g_signal_connect (priv->hadj, "value-changed",
|
|
|
|
G_CALLBACK (adjustment_changed_cb), handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_gtk_text_handle_scrollable_notify (GObject *object,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GtkTextHandle *handle)
|
|
|
|
{
|
|
|
|
if (pspec->value_type == GTK_TYPE_ADJUSTMENT)
|
|
|
|
_gtk_text_handle_set_scrollable (handle, GTK_SCROLLABLE (object));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_gtk_text_handle_update_scrollable (GtkTextHandle *handle,
|
|
|
|
GtkScrollable *scrollable)
|
|
|
|
{
|
|
|
|
GtkTextHandlePrivate *priv;
|
|
|
|
|
|
|
|
priv = handle->priv;
|
|
|
|
|
|
|
|
if (priv->parent_scrollable == scrollable)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (priv->parent_scrollable && priv->scrollable_notify_id &&
|
|
|
|
g_signal_handler_is_connected (priv->parent_scrollable,
|
|
|
|
priv->scrollable_notify_id))
|
|
|
|
g_signal_handler_disconnect (priv->parent_scrollable,
|
|
|
|
priv->scrollable_notify_id);
|
|
|
|
|
|
|
|
_gtk_text_handle_set_scrollable (handle, scrollable);
|
|
|
|
|
|
|
|
if (priv->parent_scrollable)
|
|
|
|
priv->scrollable_notify_id =
|
|
|
|
g_signal_connect (priv->parent_scrollable, "notify",
|
|
|
|
G_CALLBACK (_gtk_text_handle_scrollable_notify),
|
|
|
|
handle);
|
|
|
|
}
|
|
|
|
|
2016-02-24 16:19:48 +00:00
|
|
|
static GtkWidget *
|
|
|
|
gtk_text_handle_lookup_scrollable (GtkTextHandle *handle)
|
|
|
|
{
|
|
|
|
GtkTextHandlePrivate *priv;
|
|
|
|
GtkWidget *scrolled_window;
|
|
|
|
|
|
|
|
priv = handle->priv;
|
|
|
|
scrolled_window = gtk_widget_get_ancestor (priv->parent,
|
|
|
|
GTK_TYPE_SCROLLED_WINDOW);
|
|
|
|
if (!scrolled_window)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return gtk_bin_get_child (GTK_BIN (scrolled_window));
|
|
|
|
}
|
|
|
|
|
2014-01-22 15:33:47 +00:00
|
|
|
static void
|
|
|
|
_gtk_text_handle_parent_hierarchy_changed (GtkWidget *widget,
|
2019-02-23 05:46:44 +00:00
|
|
|
GParamSpec *pspec,
|
2014-01-22 15:33:47 +00:00
|
|
|
GtkTextHandle *handle)
|
|
|
|
{
|
2014-01-22 15:39:10 +00:00
|
|
|
GtkWidget *toplevel, *scrollable;
|
2014-01-22 15:33:47 +00:00
|
|
|
GtkTextHandlePrivate *priv;
|
|
|
|
|
|
|
|
priv = handle->priv;
|
|
|
|
toplevel = gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW);
|
|
|
|
|
2019-02-23 05:46:44 +00:00
|
|
|
if (priv->toplevel && !toplevel)
|
2014-01-22 15:33:47 +00:00
|
|
|
{
|
|
|
|
if (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_START].widget)
|
|
|
|
{
|
2019-02-23 05:46:44 +00:00
|
|
|
_gtk_window_remove_popover (GTK_WINDOW (priv->toplevel),
|
2014-01-22 15:33:47 +00:00
|
|
|
priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_START].widget);
|
|
|
|
g_object_unref (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_START].widget);
|
|
|
|
priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_START].widget = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_END].widget)
|
|
|
|
{
|
2019-02-23 05:46:44 +00:00
|
|
|
_gtk_window_remove_popover (GTK_WINDOW (priv->toplevel),
|
2014-01-22 15:33:47 +00:00
|
|
|
priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_END].widget);
|
|
|
|
g_object_unref (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_END].widget);
|
|
|
|
priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_END].widget = NULL;
|
|
|
|
}
|
2019-02-23 05:46:44 +00:00
|
|
|
|
|
|
|
priv->toplevel = NULL;
|
2014-01-22 15:33:47 +00:00
|
|
|
}
|
2014-01-22 15:39:10 +00:00
|
|
|
|
2016-02-24 16:19:48 +00:00
|
|
|
scrollable = gtk_text_handle_lookup_scrollable (handle);
|
2014-01-22 15:39:10 +00:00
|
|
|
_gtk_text_handle_update_scrollable (handle, GTK_SCROLLABLE (scrollable));
|
2014-01-22 15:33:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_gtk_text_handle_set_parent (GtkTextHandle *handle,
|
|
|
|
GtkWidget *parent)
|
|
|
|
{
|
|
|
|
GtkTextHandlePrivate *priv;
|
2014-01-22 15:39:10 +00:00
|
|
|
GtkWidget *scrollable = NULL;
|
2014-01-22 15:33:47 +00:00
|
|
|
|
|
|
|
priv = handle->priv;
|
|
|
|
|
|
|
|
if (priv->parent == parent)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (priv->parent && priv->hierarchy_changed_id &&
|
|
|
|
g_signal_handler_is_connected (priv->parent, priv->hierarchy_changed_id))
|
|
|
|
g_signal_handler_disconnect (priv->parent, priv->hierarchy_changed_id);
|
|
|
|
|
|
|
|
priv->parent = parent;
|
|
|
|
|
|
|
|
if (parent)
|
|
|
|
{
|
|
|
|
priv->hierarchy_changed_id =
|
2019-02-23 05:46:44 +00:00
|
|
|
g_signal_connect (parent, "notify::root",
|
2014-01-22 15:33:47 +00:00
|
|
|
G_CALLBACK (_gtk_text_handle_parent_hierarchy_changed),
|
|
|
|
handle);
|
2014-01-22 15:39:10 +00:00
|
|
|
|
2016-02-24 16:19:48 +00:00
|
|
|
scrollable = gtk_text_handle_lookup_scrollable (handle);
|
2014-01-22 15:33:47 +00:00
|
|
|
}
|
2014-01-22 15:39:10 +00:00
|
|
|
|
|
|
|
_gtk_text_handle_update_scrollable (handle, GTK_SCROLLABLE (scrollable));
|
2014-01-22 15:33:47 +00:00
|
|
|
}
|
|
|
|
|
2012-07-11 13:51:43 +00:00
|
|
|
static void
|
|
|
|
gtk_text_handle_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkTextHandlePrivate *priv;
|
|
|
|
|
|
|
|
priv = GTK_TEXT_HANDLE (object)->priv;
|
|
|
|
|
2014-01-22 15:33:47 +00:00
|
|
|
_gtk_text_handle_set_parent (GTK_TEXT_HANDLE (object), NULL);
|
|
|
|
|
popover: Fix memory management of popovers
Popovers are strange in the sense that they aren't attached to a
parent directly, they rely on the relative_to widget so the toplevel
is shared, and when they have a parent, it is the toplevel itself,
not relative_to. This also means that there are conditions where the
popover loses it's parent, so they must survive unparenting.
The previous code would be floating the last reference as soon as the
parent is gone, but it was non-obvious who'd own that reference. So
fix this situation by granting the ownership of popovers to their
relative_to widget, an extra reference may be held by the toplevel
when the popover has a parent, but the popover object will be
guaranteed to be alive as long as the parent lives.
This way, memory management of popovers is as hidden from the user
as regular widgets within containers are, users are free to call
gtk_widget_destroy() on a popover, but it'd eventually become
destructed when relative_to is.
2014-01-09 16:21:43 +00:00
|
|
|
/* We sank the references, unref here */
|
2013-12-23 18:09:10 +00:00
|
|
|
if (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_START].widget)
|
popover: Fix memory management of popovers
Popovers are strange in the sense that they aren't attached to a
parent directly, they rely on the relative_to widget so the toplevel
is shared, and when they have a parent, it is the toplevel itself,
not relative_to. This also means that there are conditions where the
popover loses it's parent, so they must survive unparenting.
The previous code would be floating the last reference as soon as the
parent is gone, but it was non-obvious who'd own that reference. So
fix this situation by granting the ownership of popovers to their
relative_to widget, an extra reference may be held by the toplevel
when the popover has a parent, but the popover object will be
guaranteed to be alive as long as the parent lives.
This way, memory management of popovers is as hidden from the user
as regular widgets within containers are, users are free to call
gtk_widget_destroy() on a popover, but it'd eventually become
destructed when relative_to is.
2014-01-09 16:21:43 +00:00
|
|
|
g_object_unref (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_START].widget);
|
2012-07-11 13:51:43 +00:00
|
|
|
|
2013-12-23 18:09:10 +00:00
|
|
|
if (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_END].widget)
|
popover: Fix memory management of popovers
Popovers are strange in the sense that they aren't attached to a
parent directly, they rely on the relative_to widget so the toplevel
is shared, and when they have a parent, it is the toplevel itself,
not relative_to. This also means that there are conditions where the
popover loses it's parent, so they must survive unparenting.
The previous code would be floating the last reference as soon as the
parent is gone, but it was non-obvious who'd own that reference. So
fix this situation by granting the ownership of popovers to their
relative_to widget, an extra reference may be held by the toplevel
when the popover has a parent, but the popover object will be
guaranteed to be alive as long as the parent lives.
This way, memory management of popovers is as hidden from the user
as regular widgets within containers are, users are free to call
gtk_widget_destroy() on a popover, but it'd eventually become
destructed when relative_to is.
2014-01-09 16:21:43 +00:00
|
|
|
g_object_unref (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_END].widget);
|
2012-07-11 13:51:43 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (_gtk_text_handle_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_text_handle_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkTextHandle *handle;
|
|
|
|
|
|
|
|
handle = GTK_TEXT_HANDLE (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_PARENT:
|
2014-01-22 15:33:47 +00:00
|
|
|
_gtk_text_handle_set_parent (handle, g_value_get_object (value));
|
2012-07-11 13:51:43 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_text_handle_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkTextHandlePrivate *priv;
|
|
|
|
|
|
|
|
priv = GTK_TEXT_HANDLE (object)->priv;
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_PARENT:
|
|
|
|
g_value_set_object (value, priv->parent);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_gtk_text_handle_class_init (GtkTextHandleClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->finalize = gtk_text_handle_finalize;
|
|
|
|
object_class->set_property = gtk_text_handle_set_property;
|
|
|
|
object_class->get_property = gtk_text_handle_get_property;
|
|
|
|
|
|
|
|
signals[HANDLE_DRAGGED] =
|
|
|
|
g_signal_new (I_("handle-dragged"),
|
|
|
|
G_OBJECT_CLASS_TYPE (object_class),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GtkTextHandleClass, handle_dragged),
|
|
|
|
NULL, NULL,
|
|
|
|
_gtk_marshal_VOID__ENUM_INT_INT,
|
|
|
|
G_TYPE_NONE, 3,
|
|
|
|
GTK_TYPE_TEXT_HANDLE_POSITION,
|
|
|
|
G_TYPE_INT, G_TYPE_INT);
|
2015-06-07 16:45:34 +00:00
|
|
|
signals[DRAG_STARTED] =
|
|
|
|
g_signal_new (I_("drag-started"),
|
|
|
|
G_OBJECT_CLASS_TYPE (object_class),
|
|
|
|
G_SIGNAL_RUN_LAST, 0,
|
|
|
|
NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__ENUM,
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
GTK_TYPE_TEXT_HANDLE_POSITION);
|
2012-07-11 13:51:43 +00:00
|
|
|
signals[DRAG_FINISHED] =
|
|
|
|
g_signal_new (I_("drag-finished"),
|
|
|
|
G_OBJECT_CLASS_TYPE (object_class),
|
|
|
|
G_SIGNAL_RUN_LAST, 0,
|
|
|
|
NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__ENUM,
|
|
|
|
G_TYPE_NONE, 1,
|
|
|
|
GTK_TYPE_TEXT_HANDLE_POSITION);
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_PARENT,
|
|
|
|
g_param_spec_object ("parent",
|
|
|
|
P_("Parent widget"),
|
|
|
|
P_("Parent widget"),
|
|
|
|
GTK_TYPE_WIDGET,
|
|
|
|
GTK_PARAM_READWRITE |
|
|
|
|
G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_gtk_text_handle_init (GtkTextHandle *handle)
|
|
|
|
{
|
2013-10-01 13:08:30 +00:00
|
|
|
handle->priv = _gtk_text_handle_get_instance_private (handle);
|
2012-07-11 13:51:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkTextHandle *
|
|
|
|
_gtk_text_handle_new (GtkWidget *parent)
|
|
|
|
{
|
|
|
|
return g_object_new (GTK_TYPE_TEXT_HANDLE,
|
|
|
|
"parent", parent,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gtk_text_handle_set_mode (GtkTextHandle *handle,
|
|
|
|
GtkTextHandleMode mode)
|
|
|
|
{
|
|
|
|
GtkTextHandlePrivate *priv;
|
2015-10-14 15:41:12 +00:00
|
|
|
HandleWindow *start, *end;
|
2012-07-11 13:51:43 +00:00
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_TEXT_HANDLE (handle));
|
|
|
|
|
|
|
|
priv = handle->priv;
|
|
|
|
|
|
|
|
if (priv->mode == mode)
|
|
|
|
return;
|
|
|
|
|
2012-11-07 13:23:04 +00:00
|
|
|
priv->mode = mode;
|
2015-10-14 15:41:12 +00:00
|
|
|
start = &priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_START];
|
|
|
|
end = &priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_END];
|
2012-11-07 13:23:04 +00:00
|
|
|
|
2012-07-11 13:51:43 +00:00
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case GTK_TEXT_HANDLE_MODE_CURSOR:
|
2015-10-14 15:41:12 +00:00
|
|
|
start->mode_visible = FALSE;
|
|
|
|
/* end = cursor */
|
|
|
|
end->mode_visible = TRUE;
|
2012-07-11 13:51:43 +00:00
|
|
|
break;
|
2012-11-07 13:23:04 +00:00
|
|
|
case GTK_TEXT_HANDLE_MODE_SELECTION:
|
2015-10-14 15:41:12 +00:00
|
|
|
start->mode_visible = TRUE;
|
|
|
|
end->mode_visible = TRUE;
|
2012-07-11 13:51:43 +00:00
|
|
|
break;
|
|
|
|
case GTK_TEXT_HANDLE_MODE_NONE:
|
|
|
|
default:
|
2015-10-14 15:41:12 +00:00
|
|
|
start->mode_visible = FALSE;
|
|
|
|
end->mode_visible = FALSE;
|
2012-07-11 13:51:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-11-10 04:33:54 +00:00
|
|
|
if (end->widget)
|
|
|
|
{
|
|
|
|
if (mode == GTK_TEXT_HANDLE_MODE_CURSOR)
|
|
|
|
gtk_style_context_add_class (gtk_widget_get_style_context (end->widget), GTK_STYLE_CLASS_INSERTION_CURSOR);
|
|
|
|
else
|
|
|
|
gtk_style_context_remove_class (gtk_widget_get_style_context (end->widget), GTK_STYLE_CLASS_INSERTION_CURSOR);
|
|
|
|
}
|
|
|
|
|
2013-12-23 18:09:10 +00:00
|
|
|
_gtk_text_handle_update (handle, GTK_TEXT_HANDLE_POSITION_SELECTION_START);
|
|
|
|
_gtk_text_handle_update (handle, GTK_TEXT_HANDLE_POSITION_SELECTION_END);
|
2015-10-14 15:27:53 +00:00
|
|
|
|
|
|
|
if (start->widget && start->mode_visible)
|
|
|
|
gtk_widget_queue_draw (start->widget);
|
|
|
|
if (end->widget && end->mode_visible)
|
|
|
|
gtk_widget_queue_draw (end->widget);
|
2012-07-11 13:51:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkTextHandleMode
|
|
|
|
_gtk_text_handle_get_mode (GtkTextHandle *handle)
|
|
|
|
{
|
|
|
|
GtkTextHandlePrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_TEXT_HANDLE (handle), GTK_TEXT_HANDLE_MODE_NONE);
|
|
|
|
|
|
|
|
priv = handle->priv;
|
|
|
|
return priv->mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gtk_text_handle_set_position (GtkTextHandle *handle,
|
|
|
|
GtkTextHandlePosition pos,
|
|
|
|
GdkRectangle *rect)
|
|
|
|
{
|
|
|
|
GtkTextHandlePrivate *priv;
|
|
|
|
HandleWindow *handle_window;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_TEXT_HANDLE (handle));
|
|
|
|
|
|
|
|
priv = handle->priv;
|
|
|
|
pos = CLAMP (pos, GTK_TEXT_HANDLE_POSITION_CURSOR,
|
|
|
|
GTK_TEXT_HANDLE_POSITION_SELECTION_START);
|
2012-11-07 13:23:04 +00:00
|
|
|
handle_window = &priv->windows[pos];
|
2012-07-11 13:51:43 +00:00
|
|
|
|
|
|
|
if (priv->mode == GTK_TEXT_HANDLE_MODE_NONE ||
|
|
|
|
(priv->mode == GTK_TEXT_HANDLE_MODE_CURSOR &&
|
|
|
|
pos != GTK_TEXT_HANDLE_POSITION_CURSOR))
|
|
|
|
return;
|
|
|
|
|
2012-11-07 13:23:04 +00:00
|
|
|
handle_window->pointing_to = *rect;
|
|
|
|
handle_window->has_point = TRUE;
|
2013-01-11 16:22:02 +00:00
|
|
|
|
2013-12-23 18:09:10 +00:00
|
|
|
if (gtk_widget_is_visible (priv->parent))
|
|
|
|
_gtk_text_handle_update (handle, pos);
|
2012-07-11 13:51:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gtk_text_handle_set_visible (GtkTextHandle *handle,
|
|
|
|
GtkTextHandlePosition pos,
|
|
|
|
gboolean visible)
|
|
|
|
{
|
|
|
|
GtkTextHandlePrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_TEXT_HANDLE (handle));
|
|
|
|
|
|
|
|
priv = handle->priv;
|
|
|
|
pos = CLAMP (pos, GTK_TEXT_HANDLE_POSITION_CURSOR,
|
|
|
|
GTK_TEXT_HANDLE_POSITION_SELECTION_START);
|
|
|
|
|
2012-11-07 13:23:04 +00:00
|
|
|
priv->windows[pos].user_visible = visible;
|
2013-12-23 18:09:10 +00:00
|
|
|
|
|
|
|
if (gtk_widget_is_visible (priv->parent))
|
|
|
|
_gtk_text_handle_update (handle, pos);
|
2012-07-11 13:51:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
_gtk_text_handle_get_is_dragged (GtkTextHandle *handle,
|
|
|
|
GtkTextHandlePosition pos)
|
|
|
|
{
|
|
|
|
GtkTextHandlePrivate *priv;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_TEXT_HANDLE (handle), FALSE);
|
|
|
|
|
|
|
|
priv = handle->priv;
|
|
|
|
pos = CLAMP (pos, GTK_TEXT_HANDLE_POSITION_CURSOR,
|
|
|
|
GTK_TEXT_HANDLE_POSITION_SELECTION_START);
|
|
|
|
|
|
|
|
return priv->windows[pos].dragged;
|
|
|
|
}
|
2015-06-10 18:52:02 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
_gtk_text_handle_set_direction (GtkTextHandle *handle,
|
|
|
|
GtkTextHandlePosition pos,
|
|
|
|
GtkTextDirection dir)
|
|
|
|
{
|
|
|
|
GtkTextHandlePrivate *priv;
|
|
|
|
|
2015-06-13 05:44:24 +00:00
|
|
|
g_return_if_fail (GTK_IS_TEXT_HANDLE (handle));
|
2015-06-10 18:52:02 +00:00
|
|
|
|
|
|
|
priv = handle->priv;
|
|
|
|
pos = CLAMP (pos, GTK_TEXT_HANDLE_POSITION_CURSOR,
|
|
|
|
GTK_TEXT_HANDLE_POSITION_SELECTION_START);
|
|
|
|
priv->windows[pos].dir = dir;
|
|
|
|
|
|
|
|
if (priv->windows[pos].widget)
|
|
|
|
{
|
|
|
|
gtk_widget_set_direction (priv->windows[pos].widget, dir);
|
|
|
|
_gtk_text_handle_update (handle, pos);
|
|
|
|
}
|
|
|
|
}
|