#include "gtkwindow.h"
#include "gtkscrollable.h"
#include "gtktypebuiltins.h"
+#include "gtktexthandleprivate.h"
+#include "gtkstylecontextprivate.h"
+#include "gtkcssstylepropertyprivate.h"
+#include "gtkbubblewindowprivate.h"
+#include "gtktoolbar.h"
-#include "a11y/gtktextviewaccessible.h"
+#include "a11y/gtktextviewaccessibleprivate.h"
/**
* SECTION:gtktextview
GdkDevice *dnd_device;
gulong selection_drag_handler;
+ GtkTextHandle *text_handle;
+ GtkWidget *selection_bubble;
+ guint selection_bubble_timeout_id;
GtkTextWindow *text_window;
GtkTextWindow *left_window;
* driving the scrollable adjustment values */
guint hscroll_policy : 1;
guint vscroll_policy : 1;
+ guint cursor_handle_dragged : 1;
+ guint selection_handle_dragged : 1;
+ guint populate_all : 1;
};
struct _GtkTextPendingScroll
PROP_HSCROLL_POLICY,
PROP_VSCROLL_POLICY,
PROP_INPUT_PURPOSE,
- PROP_INPUT_HINTS
+ PROP_INPUT_HINTS,
+ PROP_POPULATE_ALL
};
static void gtk_text_view_finalize (GObject *object);
static void gtk_text_view_paste_done_handler (GtkTextBuffer *buffer,
GtkClipboard *clipboard,
gpointer data);
+static void gtk_text_view_buffer_changed_handler (GtkTextBuffer *buffer,
+ gpointer data);
static void gtk_text_view_get_virtual_cursor_pos (GtkTextView *text_view,
GtkTextIter *cursor,
gint *x,
GtkCallback callback,
gpointer callback_data);
+/* GtkTextHandle handlers */
+static void gtk_text_view_handle_dragged (GtkTextHandle *handle,
+ GtkTextHandlePosition pos,
+ gint x,
+ gint y,
+ GtkTextView *text_view);
+static void gtk_text_view_handle_drag_finished (GtkTextHandle *handle,
+ GtkTextHandlePosition pos,
+ GtkTextView *text_view);
+static void gtk_text_view_update_handles (GtkTextView *text_view,
+ GtkTextHandleMode mode);
+
+static void gtk_text_view_selection_bubble_popup_unset (GtkTextView *text_view);
+static void gtk_text_view_selection_bubble_popup_set (GtkTextView *text_view);
+
+
/* FIXME probably need the focus methods. */
typedef struct _GtkTextViewChild GtkTextViewChild;
static guint signals[LAST_SIGNAL] = { 0 };
+static gboolean test_touchscreen = FALSE;
G_DEFINE_TYPE_WITH_CODE (GtkTextView, gtk_text_view, GTK_TYPE_CONTAINER,
G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
GTK_INPUT_HINT_NONE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ /** GtkTextView:populate-all:
+ *
+ * If ::populate-all is %TRUE, the #GtkTextView::populate-popup
+ * signal is also emitted for touch popups.
+ *
+ * Since: 3.8
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_POPULATE_ALL,
+ g_param_spec_boolean ("populate-all",
+ P_("Populate all"),
+ P_("Whether to emit ::populate-popup for touch popups"),
+ FALSE,
+ GTK_PARAM_READWRITE));
+
+
/* GtkScrollable interface */
g_object_class_override_property (gobject_class, PROP_HADJUSTMENT, "hadjustment");
g_object_class_override_property (gobject_class, PROP_VADJUSTMENT, "vadjustment");
/**
* GtkTextView::populate-popup:
* @text_view: The text view on which the signal is emitted
- * @menu: the menu that is being populated
+ * @popup: the container that is being populated
*
- * The ::populate-popup signal gets emitted before showing the
+ * The ::populate-popup signal gets emitted before showing the
* context menu of the text view.
*
* If you need to add items to the context menu, connect
- * to this signal and append your menuitems to the @menu.
+ * to this signal and append your items to the @popup, which
+ * will be a #GtkMenu in this case.
+ *
+ * If #GtkEntry::populate-toolbar is %TRUE, this signal will
+ * also be emitted to populate touch popups. In this case,
+ * @popup will be a different container, e.g. a #GtkToolbar.
+ *
+ * The signal handler should not make assumptions about the
+ * type of @widget, but check whether @popup is a #GtkMenu
+ * or #GtkToolbar or another kind of container.
*/
signals[POPULATE_POPUP] =
g_signal_new (I_("populate-popup"),
NULL, NULL,
_gtk_marshal_VOID__OBJECT,
G_TYPE_NONE, 1,
- GTK_TYPE_MENU);
+ GTK_TYPE_WIDGET);
/**
* GtkTextView::select-all:
g_type_class_add_private (gobject_class, sizeof (GtkTextViewPrivate));
gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_TEXT_VIEW_ACCESSIBLE);
+ test_touchscreen = g_getenv ("GTK_TEST_TOUCHSCREEN") != NULL;
}
static void
/* We handle all our own redrawing */
gtk_widget_set_redraw_on_allocate (widget, FALSE);
+
+ priv->text_handle = _gtk_text_handle_new (widget);
+ g_signal_connect (priv->text_handle, "handle-dragged",
+ G_CALLBACK (gtk_text_view_handle_dragged), text_view);
+ g_signal_connect (priv->text_handle, "drag-finished",
+ G_CALLBACK (gtk_text_view_handle_drag_finished), text_view);
}
/**
g_signal_handlers_disconnect_by_func (priv->buffer,
gtk_text_view_paste_done_handler,
text_view);
+ g_signal_handlers_disconnect_by_func (priv->buffer,
+ gtk_text_view_buffer_changed_handler,
+ text_view);
if (gtk_widget_get_realized (GTK_WIDGET (text_view)))
{
g_signal_connect (priv->buffer, "paste-done",
G_CALLBACK (gtk_text_view_paste_done_handler),
text_view);
+ g_signal_connect (priv->buffer, "changed",
+ G_CALLBACK (gtk_text_view_buffer_changed_handler),
+ text_view);
gtk_text_view_target_list_notify (priv->buffer, NULL, text_view);
GDK_SELECTION_PRIMARY);
gtk_text_buffer_add_selection_clipboard (priv->buffer, clipboard);
}
+
+ gtk_text_view_update_handles (text_view, GTK_TEXT_HANDLE_MODE_NONE);
}
_gtk_text_view_accessible_set_buffer (text_view, old_buffer);
if (priv->bottom_window)
text_window_free (priv->bottom_window);
+ if (priv->selection_bubble)
+ gtk_widget_destroy (priv->selection_bubble);
+
+ g_object_unref (priv->text_handle);
g_object_unref (priv->im_context);
g_free (priv->im_module);
gtk_text_view_set_input_hints (text_view, g_value_get_flags (value));
break;
+ case PROP_POPULATE_ALL:
+ text_view->priv->populate_all = g_value_get_boolean (value);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
g_value_set_flags (value, gtk_text_view_get_input_hints (text_view));
break;
+ case PROP_POPULATE_ALL:
+ g_value_set_boolean (value, priv->populate_all);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
window = gdk_window_new (gtk_widget_get_parent_window (widget),
&attributes, attributes_mask);
gtk_widget_set_window (widget, window);
- gdk_window_set_user_data (window, widget);
+ gtk_widget_register_window (widget, window);
context = gtk_widget_get_style_context (widget);
/* Ensure updating the spot location. */
gtk_text_view_update_im_spot_location (text_view);
+
+ _gtk_text_handle_set_relative_to (priv->text_handle, priv->text_window->window);
}
static void
if (priv->bottom_window)
text_window_unrealize (priv->bottom_window);
+ _gtk_text_handle_set_relative_to (priv->text_handle, NULL);
+
GTK_WIDGET_CLASS (gtk_text_view_parent_class)->unrealize (widget);
}
GtkTextView *text_view;
GtkTextViewPrivate *priv;
PangoContext *ltr_context, *rtl_context;
+ GtkStyleContext *style_context;
+ const GtkBitmask *changes;
text_view = GTK_TEXT_VIEW (widget);
priv = text_view->priv;
gtk_text_view_set_background (text_view);
}
- if (priv->layout && priv->layout->default_style)
+
+ style_context = gtk_widget_get_style_context (widget);
+ changes = _gtk_style_context_get_changes (style_context);
+ if ((changes == NULL || _gtk_css_style_property_changes_affect_font (changes)) &&
+ priv->layout && priv->layout->default_style)
{
gtk_text_view_set_attributes_from_style (text_view,
priv->layout->default_style);
return retval;
}
+static void
+gtk_text_view_set_handle_position (GtkTextView *text_view,
+ GtkTextIter *iter,
+ GtkTextHandlePosition pos)
+{
+ GtkTextViewPrivate *priv;
+ GdkRectangle rect;
+ gint x, y;
+
+ priv = text_view->priv;
+ gtk_text_view_get_cursor_locations (text_view, iter, &rect, NULL);
+
+ x = rect.x - priv->xoffset;
+ y = rect.y - priv->yoffset;
+
+ if (!_gtk_text_handle_get_is_dragged (priv->text_handle, pos) &&
+ (x < 0 || x > SCREEN_WIDTH (text_view) ||
+ y < 0 || y > SCREEN_HEIGHT (text_view)))
+ {
+ /* Hide the handle if it's not being manipulated
+ * and fell outside of the visible text area.
+ */
+ _gtk_text_handle_set_visible (priv->text_handle, pos, FALSE);
+ }
+ else
+ {
+ _gtk_text_handle_set_visible (priv->text_handle, pos, TRUE);
+
+ rect.x = CLAMP (x, 0, SCREEN_WIDTH (text_view));
+ rect.y = CLAMP (y, 0, SCREEN_HEIGHT (text_view));
+ _gtk_text_handle_set_position (priv->text_handle, pos, &rect);
+ }
+}
+
+static void
+gtk_text_view_handle_dragged (GtkTextHandle *handle,
+ GtkTextHandlePosition pos,
+ gint x,
+ gint y,
+ GtkTextView *text_view)
+{
+ GtkTextViewPrivate *priv;
+ GtkTextIter old_cursor, old_bound;
+ GtkTextIter cursor, bound, iter;
+ GtkTextIter *min, *max;
+ GtkTextHandleMode mode;
+ GtkTextBuffer *buffer;
+ GtkTextHandlePosition cursor_pos;
+
+ priv = text_view->priv;
+ buffer = get_buffer (text_view);
+ mode = _gtk_text_handle_get_mode (handle);
+
+ gtk_text_view_selection_bubble_popup_unset (text_view);
+ gtk_text_layout_get_iter_at_pixel (priv->layout, &iter,
+ x + priv->xoffset,
+ y + priv->yoffset);
+ gtk_text_buffer_get_iter_at_mark (buffer, &old_cursor,
+ gtk_text_buffer_get_insert (buffer));
+ gtk_text_buffer_get_iter_at_mark (buffer, &old_bound,
+ gtk_text_buffer_get_selection_bound (buffer));
+ cursor = old_cursor;
+ bound = old_bound;
+
+ if (mode == GTK_TEXT_HANDLE_MODE_CURSOR ||
+ gtk_text_iter_compare (&cursor, &bound) >= 0)
+ {
+ cursor_pos = GTK_TEXT_HANDLE_POSITION_CURSOR;
+ max = &cursor;
+ min = &bound;
+ }
+ else
+ {
+ cursor_pos = GTK_TEXT_HANDLE_POSITION_SELECTION_START;
+ max = &bound;
+ min = &cursor;
+ }
+
+ if (pos == GTK_TEXT_HANDLE_POSITION_SELECTION_END)
+ {
+ if (mode == GTK_TEXT_HANDLE_MODE_SELECTION &&
+ gtk_text_iter_compare (&iter, min) <= 0)
+ {
+ iter = *min;
+ gtk_text_iter_forward_char (&iter);
+ }
+
+ *max = iter;
+ gtk_text_view_set_handle_position (text_view, &iter, pos);
+ }
+ else
+ {
+ if (mode == GTK_TEXT_HANDLE_MODE_SELECTION &&
+ gtk_text_iter_compare (&iter, max) >= 0)
+ {
+ iter = *max;
+ gtk_text_iter_backward_char (&iter);
+ }
+
+ *min = iter;
+ gtk_text_view_set_handle_position (text_view, &iter, pos);
+ }
+
+ if (gtk_text_iter_compare (&old_cursor, &cursor) != 0 ||
+ gtk_text_iter_compare (&old_bound, &bound) != 0)
+ {
+ if (mode == GTK_TEXT_HANDLE_MODE_CURSOR)
+ gtk_text_buffer_place_cursor (buffer, &cursor);
+ else
+ gtk_text_buffer_select_range (buffer, &cursor, &bound);
+
+ if (_gtk_text_handle_get_is_dragged (priv->text_handle, cursor_pos))
+ gtk_text_view_scroll_mark_onscreen (text_view,
+ gtk_text_buffer_get_insert (buffer));
+ else
+ gtk_text_view_scroll_mark_onscreen (text_view,
+ gtk_text_buffer_get_selection_bound (buffer));
+ }
+}
+
+static void
+gtk_text_view_handle_drag_finished (GtkTextHandle *handle,
+ GtkTextHandlePosition pos,
+ GtkTextView *text_view)
+{
+ gtk_text_view_selection_bubble_popup_set (text_view);
+}
+
+static void
+gtk_text_view_update_handles (GtkTextView *text_view,
+ GtkTextHandleMode mode)
+{
+ GtkTextViewPrivate *priv = text_view->priv;
+ GtkTextIter cursor, bound, min, max;
+ GtkTextBuffer *buffer;
+
+ buffer = get_buffer (text_view);
+
+ gtk_text_buffer_get_iter_at_mark (buffer, &cursor,
+ gtk_text_buffer_get_insert (buffer));
+ gtk_text_buffer_get_iter_at_mark (buffer, &bound,
+ gtk_text_buffer_get_selection_bound (buffer));
+
+ if (mode == GTK_TEXT_HANDLE_MODE_SELECTION &&
+ gtk_text_iter_compare (&cursor, &bound) == 0)
+ {
+ mode = GTK_TEXT_HANDLE_MODE_CURSOR;
+ }
+
+ if (mode == GTK_TEXT_HANDLE_MODE_CURSOR &&
+ (!gtk_widget_is_sensitive (GTK_WIDGET (text_view)) || !priv->cursor_visible))
+ {
+ mode = GTK_TEXT_HANDLE_MODE_NONE;
+ }
+
+ _gtk_text_handle_set_mode (priv->text_handle, mode);
+
+ if (gtk_text_iter_compare (&cursor, &bound) >= 0)
+ {
+ min = bound;
+ max = cursor;
+ }
+ else
+ {
+ min = cursor;
+ max = bound;
+ }
+
+ if (mode != GTK_TEXT_HANDLE_MODE_NONE)
+ gtk_text_view_set_handle_position (text_view, &max,
+ GTK_TEXT_HANDLE_POSITION_SELECTION_END);
+
+ if (mode == GTK_TEXT_HANDLE_MODE_SELECTION)
+ gtk_text_view_set_handle_position (text_view, &min,
+ GTK_TEXT_HANDLE_POSITION_SELECTION_START);
+}
+
static gint
gtk_text_view_event (GtkWidget *widget, GdkEvent *event)
{
gtk_text_view_reset_blink_time (text_view);
gtk_text_view_pend_cursor_blink (text_view);
+ if (!event->send_event)
+ _gtk_text_handle_set_mode (priv->text_handle,
+ GTK_TEXT_HANDLE_MODE_NONE);
+
+ gtk_text_view_selection_bubble_popup_unset (text_view);
+
return retval;
}
{
GtkTextView *text_view;
GtkTextViewPrivate *priv;
+ GdkDevice *device;
+ gboolean is_touchscreen;
text_view = GTK_TEXT_VIEW (widget);
priv = text_view->priv;
}
gtk_text_view_reset_blink_time (text_view);
+ gtk_text_view_selection_bubble_popup_unset (text_view);
#if 0
/* debug hack */
gtk_text_layout_spew (GTK_TEXT_VIEW (widget)->layout);
#endif
+ device = gdk_event_get_source_device ((GdkEvent *) event);
+ is_touchscreen = test_touchscreen ||
+ gdk_device_get_source (device) == GDK_SOURCE_TOUCHSCREEN;
+
if (event->type == GDK_BUTTON_PRESS)
{
gtk_text_view_reset_im_context (text_view);
}
else
{
+ GtkTextHandleMode mode;
+
gtk_text_view_start_selection_drag (text_view, &iter, event);
+
+ if (gtk_widget_is_sensitive (widget) && is_touchscreen)
+ mode = GTK_TEXT_HANDLE_MODE_CURSOR;
+ else
+ mode = GTK_TEXT_HANDLE_MODE_NONE;
+
+ gtk_text_view_update_handles (text_view, mode);
}
return TRUE;
event->button == GDK_BUTTON_PRIMARY)
{
GtkTextIter iter;
+ GtkTextHandleMode mode;
gtk_text_view_end_selection_drag (text_view);
&iter,
event->x + priv->xoffset,
event->y + priv->yoffset);
-
+
gtk_text_view_start_selection_drag (text_view, &iter, event);
+
+ if (gtk_widget_is_sensitive (widget) && is_touchscreen)
+ mode = GTK_TEXT_HANDLE_MODE_SELECTION;
+ else
+ mode = GTK_TEXT_HANDLE_MODE_NONE;
+
+ gtk_text_view_update_handles (text_view, mode);
return TRUE;
}
-
+
return FALSE;
}
{
GtkTextView *text_view;
GtkTextViewPrivate *priv;
+ GdkDevice *device;
text_view = GTK_TEXT_VIEW (widget);
priv = text_view->priv;
+ device = gdk_event_get_source_device ((GdkEvent *) event);
if (event->window != priv->text_window->bin_window)
return FALSE;
}
if (gtk_text_view_end_selection_drag (GTK_TEXT_VIEW (widget)))
- return TRUE;
+ {
+ if (test_touchscreen ||
+ gdk_device_get_source (device) == GDK_SOURCE_TOUCHSCREEN)
+ gtk_text_view_selection_bubble_popup_set (text_view);
+ return TRUE;
+ }
else if (priv->pending_place_cursor_button == event->button)
{
+ GtkTextHandleMode mode;
GtkTextIter iter;
/* Unselect everything; we clicked inside selection, but
gtk_text_buffer_place_cursor (get_buffer (text_view), &iter);
gtk_text_view_check_cursor_blink (text_view);
-
+
+ if (gtk_widget_is_sensitive (widget) &&
+ (test_touchscreen ||
+ gdk_device_get_source (device) == GDK_SOURCE_TOUCHSCREEN))
+ mode = GTK_TEXT_HANDLE_MODE_CURSOR;
+ else
+ mode = GTK_TEXT_HANDLE_MODE_NONE;
+
+ gtk_text_view_update_handles (text_view, mode);
priv->pending_place_cursor_button = 0;
-
+
return FALSE;
}
}
g_signal_handlers_disconnect_by_func (gdk_keymap_get_for_display (gtk_widget_get_display (widget)),
keymap_direction_changed,
text_view);
+ gtk_text_view_selection_bubble_popup_unset (text_view);
+ _gtk_text_handle_set_mode (priv->text_handle,
+ GTK_TEXT_HANDLE_MODE_NONE);
if (priv->editable)
{
{
GSList *tmp_list;
GdkWindow *window;
-
+ GtkStyleContext *context;
+
+ context = gtk_widget_get_style_context (widget);
+
if (gtk_cairo_should_draw_window (cr, gtk_widget_get_window (widget)))
- gtk_text_view_draw_focus (widget, cr);
+ {
+ gtk_style_context_save (context);
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
+ gtk_render_background (context, cr,
+ 0, 0,
+ gtk_widget_get_allocated_width (widget),
+ gtk_widget_get_allocated_height (widget));
+ gtk_style_context_restore (context);
+
+ gtk_text_view_draw_focus (widget, cr);
+ }
window = gtk_text_view_get_window (GTK_TEXT_VIEW (widget),
GTK_TEXT_WINDOW_TEXT);
{
GtkContainer *container;
gboolean result;
-
- container = GTK_CONTAINER (widget);
+
+ container = GTK_CONTAINER (widget);
if (!gtk_widget_is_focus (widget) &&
gtk_container_get_focus_child (container) == NULL)
{
- gtk_widget_grab_focus (widget);
- return TRUE;
+ if (gtk_widget_get_can_focus (widget))
+ {
+ gtk_widget_grab_focus (widget);
+ return TRUE;
+ }
+
+ return FALSE;
}
else
{
+ gboolean can_focus;
/*
* Unset CAN_FOCUS flag so that gtk_container_focus() allows
* children to get the focus
*/
+ can_focus = gtk_widget_get_can_focus (widget);
gtk_widget_set_can_focus (widget, FALSE);
result = GTK_WIDGET_CLASS (gtk_text_view_parent_class)->focus (widget, direction);
- gtk_widget_set_can_focus (widget, TRUE);
+ gtk_widget_set_can_focus (widget, can_focus);
return result;
}
DV(g_print (G_STRLOC": scrolling onscreen\n"));
gtk_text_view_scroll_mark_onscreen (text_view,
gtk_text_buffer_get_insert (get_buffer (text_view)));
+ gtk_text_view_selection_bubble_popup_unset (text_view);
}
static void
priv->scroll_after_paste = TRUE;
}
+static void
+gtk_text_view_buffer_changed_handler (GtkTextBuffer *buffer,
+ gpointer data)
+{
+ GtkTextView *text_view = data;
+ GtkTextViewPrivate *priv = text_view->priv;
+
+ gtk_text_view_update_handles (text_view,
+ _gtk_text_handle_get_mode (priv->text_handle));
+}
+
static void
gtk_text_view_toggle_overwrite (GtkTextView *text_view)
{
}
static void
-move_mark_to_pointer_and_scroll (GtkTextView *text_view,
- const gchar *mark_name,
- GdkDevice *device)
+move_mark_to_pointer_and_scroll (GtkTextView *text_view,
+ const gchar *mark_name,
+ GdkDevice *device,
+ GdkInputSource source)
{
GtkTextIter newplace;
+ GtkTextBuffer *buffer;
GtkTextMark *mark;
+ buffer = get_buffer (text_view);
get_iter_at_pointer (text_view, device, &newplace, NULL, NULL);
-
- mark = gtk_text_buffer_get_mark (get_buffer (text_view), mark_name);
-
+
+ mark = gtk_text_buffer_get_mark (buffer, mark_name);
+
/* This may invalidate the layout */
DV(g_print (G_STRLOC": move mark\n"));
-
- gtk_text_buffer_move_mark (get_buffer (text_view),
- mark,
- &newplace);
-
+
+ gtk_text_buffer_move_mark (buffer, mark, &newplace);
+
DV(g_print (G_STRLOC": scrolling onscreen\n"));
gtk_text_view_scroll_mark_onscreen (text_view, mark);
SelectionData *data)
{
GtkTextViewPrivate *priv;
+ GdkInputSource input_source;
+ GdkDevice *device;
priv = text_view->priv;
gdk_event_request_motions (event);
+ device = gdk_event_get_source_device ((GdkEvent *) event);
+ input_source = gdk_device_get_source (device);
+
if (priv->grab_device != event->device)
return FALSE;
if (data->granularity == SELECT_CHARACTERS)
{
- move_mark_to_pointer_and_scroll (text_view, "insert", event->device);
+ move_mark_to_pointer_and_scroll (text_view, "insert",
+ event->device, input_source);
}
else
{
else
gtk_text_buffer_select_range (buffer, &end, &orig_start);
- gtk_text_view_scroll_mark_onscreen (text_view,
+ gtk_text_view_scroll_mark_onscreen (text_view,
gtk_text_buffer_get_insert (buffer));
}
text_view->priv->scroll_timeout =
gdk_threads_add_timeout (50, selection_scan_timeout, text_view);
+ if (test_touchscreen || input_source == GDK_SOURCE_TOUCHSCREEN)
+ gtk_text_view_update_handles (text_view, GTK_TEXT_HANDLE_MODE_SELECTION);
+
return TRUE;
}
if (values->font)
pango_font_description_free (values->font);
- values->font = pango_font_description_copy (gtk_style_context_get_font (context, state));
+ gtk_style_context_get (context, state, "font", &values->font, NULL);
gtk_style_context_restore (context);
}
* changes made by the validation are pushed through.
*/
gtk_text_view_update_im_spot_location (text_view);
-
+
+ gtk_text_view_update_handles (text_view,
+ _gtk_text_handle_get_mode (priv->text_handle));
+
DV(g_print(">End scroll offset changed handler ("G_STRLOC")\n"));
}
}
if (need_reset)
- gtk_text_view_reset_im_context (text_view);
+ {
+ gtk_text_view_reset_im_context (text_view);
+ gtk_text_view_update_handles (text_view,
+ _gtk_text_handle_get_mode (text_view->priv->text_handle));
+ }
}
static void
return TRUE;
}
+static void
+gtk_text_view_get_selection_rect (GtkTextView *text_view,
+ cairo_rectangle_int_t *rect)
+{
+ cairo_rectangle_int_t rect_cursor, rect_bound;
+ GtkTextIter cursor, bound;
+ GtkTextBuffer *buffer;
+ gint x1, y1, x2, y2;
+
+ buffer = get_buffer (text_view);
+ gtk_text_buffer_get_iter_at_mark (buffer, &cursor,
+ gtk_text_buffer_get_insert (buffer));
+ gtk_text_buffer_get_iter_at_mark (buffer, &bound,
+ gtk_text_buffer_get_selection_bound (buffer));
+
+ gtk_text_view_get_cursor_locations (text_view, &cursor, &rect_cursor, NULL);
+ gtk_text_view_get_cursor_locations (text_view, &bound, &rect_bound, NULL);
+
+ x1 = MIN (rect_cursor.x, rect_bound.x);
+ x2 = MAX (rect_cursor.x, rect_bound.x);
+ y1 = MIN (rect_cursor.y, rect_bound.y);
+ y2 = MAX (rect_cursor.y + rect_cursor.height, rect_bound.y + rect_bound.height);
+
+ rect->x = x1;
+ rect->y = y1;
+ rect->width = x2 - x1;
+ rect->height = y2 - y1;
+}
+
+static void
+activate_bubble_cb (GtkWidget *item,
+ GtkTextView *text_view)
+{
+ const gchar *signal = g_object_get_data (G_OBJECT (item), "gtk-signal");
+ g_signal_emit_by_name (text_view, signal);
+ _gtk_bubble_window_popdown (GTK_BUBBLE_WINDOW (text_view->priv->selection_bubble));
+}
+
+static void
+append_bubble_action (GtkTextView *text_view,
+ GtkWidget *toolbar,
+ const gchar *stock_id,
+ const gchar *signal,
+ gboolean sensitive)
+{
+ GtkToolItem *item = gtk_tool_button_new_from_stock (stock_id);
+ g_object_set_data (G_OBJECT (item), I_("gtk-signal"), (char *)signal);
+ g_signal_connect (item, "clicked", G_CALLBACK (activate_bubble_cb), text_view);
+ gtk_widget_set_sensitive (GTK_WIDGET (item), sensitive);
+ gtk_widget_show (GTK_WIDGET (item));
+ gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
+}
+
+static void
+bubble_targets_received (GtkClipboard *clipboard,
+ GtkSelectionData *data,
+ gpointer user_data)
+{
+ GtkTextView *text_view = user_data;
+ GtkTextViewPrivate *priv = text_view->priv;
+ cairo_rectangle_int_t rect;
+ gboolean has_selection;
+ gboolean has_clipboard;
+ gboolean can_insert;
+ GtkTextIter iter;
+ GtkTextIter sel_start, sel_end;
+ GdkWindow *window;
+ GtkWidget *toolbar;
+
+ has_selection = gtk_text_buffer_get_selection_bounds (get_buffer (text_view),
+ &sel_start, &sel_end);
+ if (!priv->editable && !has_selection)
+ {
+ priv->selection_bubble_timeout_id = 0;
+ return;
+ }
+
+ if (priv->selection_bubble)
+ gtk_widget_destroy (priv->selection_bubble);
+
+ window = gtk_widget_get_window (GTK_WIDGET (text_view));
+ priv->selection_bubble = _gtk_bubble_window_new ();
+ toolbar = GTK_WIDGET (gtk_toolbar_new ());
+ gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_TEXT);
+ gtk_toolbar_set_show_arrow (GTK_TOOLBAR (toolbar), FALSE);
+ gtk_widget_show (toolbar);
+ gtk_container_add (GTK_CONTAINER (priv->selection_bubble), toolbar);
+
+ gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &iter,
+ gtk_text_buffer_get_insert (get_buffer (text_view)));
+ can_insert = gtk_text_iter_can_insert (&iter, priv->editable);
+ has_clipboard = gtk_selection_data_targets_include_text (data);
+
+ append_bubble_action (text_view, toolbar, GTK_STOCK_CUT, "cut-clipboard",
+ has_selection &&
+ range_contains_editable_text (&sel_start, &sel_end,
+ priv->editable));
+ append_bubble_action (text_view, toolbar, GTK_STOCK_COPY, "copy-clipboard",
+ has_selection);
+ append_bubble_action (text_view, toolbar, GTK_STOCK_PASTE, "paste-clipboard",
+ can_insert && has_clipboard);
+
+ if (priv->populate_all)
+ g_signal_emit (text_view, signals[POPULATE_POPUP], 0, toolbar);
+
+ gtk_text_view_get_selection_rect (text_view, &rect);
+ rect.x -= priv->xoffset;
+ rect.y -= priv->yoffset;
+ _gtk_bubble_window_popup (GTK_BUBBLE_WINDOW (priv->selection_bubble),
+ window, &rect, GTK_POS_TOP);
+
+ priv->selection_bubble_timeout_id = 0;
+}
+
+static gboolean
+gtk_text_view_selection_bubble_popup_cb (gpointer user_data)
+{
+ GtkTextView *text_view = user_data;
+ gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (text_view),
+ GDK_SELECTION_CLIPBOARD),
+ gdk_atom_intern_static_string ("TARGETS"),
+ bubble_targets_received,
+ text_view);
+
+ return G_SOURCE_REMOVE;
+}
+
+static void
+gtk_text_view_selection_bubble_popup_unset (GtkTextView *text_view)
+{
+ GtkTextViewPrivate *priv;
+
+ priv = text_view->priv;
+
+ if (priv->selection_bubble)
+ _gtk_bubble_window_popdown (GTK_BUBBLE_WINDOW (priv->selection_bubble));
+
+ if (priv->selection_bubble_timeout_id)
+ {
+ g_source_remove (priv->selection_bubble_timeout_id);
+ priv->selection_bubble_timeout_id = 0;
+ }
+}
+
+static void
+gtk_text_view_selection_bubble_popup_set (GtkTextView *text_view)
+{
+ GtkTextViewPrivate *priv;
+
+ priv = text_view->priv;
+
+ if (priv->selection_bubble_timeout_id)
+ g_source_remove (priv->selection_bubble_timeout_id);
+
+ priv->selection_bubble_timeout_id =
+ gdk_threads_add_timeout (1000, gtk_text_view_selection_bubble_popup_cb,
+ text_view);
+}
+
/* Child GdkWindows */
&attributes, attributes_mask);
gdk_window_show (win->window);
- gdk_window_set_user_data (win->window, win->widget);
+ gtk_widget_register_window (win->widget, win->window);
gdk_window_lower (win->window);
attributes.x = 0;
attributes_mask);
gdk_window_show (win->bin_window);
- gdk_window_set_user_data (win->bin_window, win->widget);
+ gtk_widget_register_window (win->widget, win->bin_window);
context = gtk_widget_get_style_context (widget);
state = gtk_widget_get_state_flags (widget);
NULL);
}
- gdk_window_set_user_data (win->window, NULL);
- gdk_window_set_user_data (win->bin_window, NULL);
+ gtk_widget_unregister_window (win->widget, win->window);
+ gtk_widget_unregister_window (win->widget, win->bin_window);
gdk_window_destroy (win->bin_window);
gdk_window_destroy (win->window);
win->window = NULL;
gint dx,
gint dy)
{
+ GtkTextView *view = GTK_TEXT_VIEW (win->widget);
+ GtkTextViewPrivate *priv = view->priv;
+
if (dx != 0 || dy != 0)
{
+ if (priv->selection_bubble)
+ _gtk_bubble_window_popdown (GTK_BUBBLE_WINDOW (priv->selection_bubble));
gdk_window_scroll (win->bin_window, dx, dy);
}
}