* 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, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
/*
#include "gtkscrollable.h"
#include "gtktypebuiltins.h"
+#include "a11y/gtktextviewaccessible.h"
/**
* SECTION:gtktextview
GdkDevice *dnd_device;
gulong selection_drag_handler;
- guint scroll_timeout;
GtkTextWindow *text_window;
GtkTextWindow *left_window;
GtkTextMark *first_para_mark; /* Mark at the beginning of the first onscreen paragraph */
gint first_para_pixels; /* Offset of top of screen in the first onscreen paragraph */
- GtkTextMark *dnd_mark;
guint blink_timeout;
+ guint scroll_timeout;
guint first_validate_idle; /* Idle to revalidate onscreen portion, runs before resize */
guint incremental_validate_idle; /* Idle to revalidate offscreen portions, runs after redraw */
+ gint pending_place_cursor_button;
+
+ GtkTextMark *dnd_mark;
+
GtkIMContext *im_context;
GtkWidget *popup_menu;
GtkTextPendingScroll *pending_scroll;
- gint pending_place_cursor_button;
-
/* Default style settings */
gint pixels_above_lines;
gint pixels_below_lines;
guint overwrite_mode : 1;
guint cursor_visible : 1;
- /* if we have reset the IM since the last character entered */
+ /* if we have reset the IM since the last character entered */
guint need_im_reset : 1;
guint accepts_tab : 1;
static void gtk_text_view_paste_done_handler (GtkTextBuffer *buffer,
GtkClipboard *clipboard,
gpointer data);
-static void gtk_text_view_get_cursor_location (GtkTextView *text_view,
- GdkRectangle *pos);
static void gtk_text_view_get_virtual_cursor_pos (GtkTextView *text_view,
GtkTextIter *cursor,
gint *x,
GTK_TYPE_DIRECTION_TYPE, GTK_DIR_TAB_BACKWARD);
g_type_class_add_private (gobject_class, sizeof (GtkTextViewPrivate));
+
+ gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_TEXT_VIEW_ACCESSIBLE);
}
static void
GtkTextBuffer *buffer)
{
GtkTextViewPrivate *priv;
+ GtkTextBuffer *old_buffer;
g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
g_return_if_fail (buffer == NULL || GTK_IS_TEXT_BUFFER (buffer));
if (priv->buffer == buffer)
return;
+ old_buffer = priv->buffer;
if (priv->buffer != NULL)
{
/* Destroy all anchored children */
if (priv->layout)
gtk_text_layout_set_buffer (priv->layout, NULL);
- g_object_unref (priv->buffer);
priv->dnd_mark = NULL;
priv->first_para_mark = NULL;
cancel_pending_scroll (text_view);
}
}
+ _gtk_text_view_accessible_set_buffer (text_view, old_buffer);
+ if (old_buffer)
+ g_object_unref (old_buffer);
+
g_object_notify (G_OBJECT (text_view), "buffer");
if (gtk_widget_get_visible (GTK_WIDGET (text_view)))
return get_buffer (text_view);
}
+/**
+ * gtk_text_view_get_cursor_locations:
+ * @text_view: a #GtkTextView
+ * @iter: (allow-none): a #GtkTextIter
+ * @strong: (out) (allow-none): location to store the strong
+ * cursor position (may be %NULL)
+ * @weak: (out) (allow-none): location to store the weak
+ * cursor position (may be %NULL)
+ *
+ * Given an @iter within a text layout, determine the positions of the
+ * strong and weak cursors if the insertion point is at that
+ * iterator. The position of each cursor is stored as a zero-width
+ * rectangle. The strong cursor location is the location where
+ * characters of the directionality equal to the base direction of the
+ * paragraph are inserted. The weak cursor location is the location
+ * where characters of the directionality opposite to the base
+ * direction of the paragraph are inserted.
+ *
+ * If @iter is %NULL, the actual cursor position is used.
+ *
+ * Note that if @iter happens to be the actual cursor position, and
+ * there is currently an IM preedit sequence being entered, the
+ * returned locations will be adjusted to account for the preedit
+ * cursor's offset within the preedit sequence.
+ *
+ * The rectangle position is in buffer coordinates; use
+ * gtk_text_view_buffer_to_window_coords() to convert these
+ * coordinates to coordinates for one of the windows in the text view.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_text_view_get_cursor_locations (GtkTextView *text_view,
+ const GtkTextIter *iter,
+ GdkRectangle *strong,
+ GdkRectangle *weak)
+{
+ GtkTextIter insert;
+
+ g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
+ g_return_if_fail (iter == NULL ||
+ gtk_text_iter_get_buffer (iter) == get_buffer (text_view));
+
+ gtk_text_view_ensure_layout (text_view);
+
+ if (iter)
+ insert = *iter;
+ else
+ gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
+ gtk_text_buffer_get_insert (get_buffer (text_view)));
+
+ gtk_text_layout_get_cursor_locations (text_view->priv->layout, &insert,
+ strong, weak);
+}
+
/**
* gtk_text_view_get_iter_at_location:
* @text_view: a #GtkTextView
if (text_view->priv->layout == NULL)
return;
- gtk_text_view_get_cursor_location (text_view, &area);
+ gtk_text_view_get_cursor_locations (text_view, NULL, &area, NULL);
area.x -= text_view->priv->xoffset;
area.y -= text_view->priv->yoffset;
/* Width returned by Pango indicates direction of cursor,
- * by it's sign more than the size of cursor.
+ * by its sign more than the size of cursor.
*/
area.width = 0;
/**
* gtk_text_view_get_visible_rect:
* @text_view: a #GtkTextView
- * @visible_rect: rectangle to fill
+ * @visible_rect: (out): rectangle to fill
*
* Fills @visible_rect with the currently-visible
* region of the buffer, in buffer coordinates. Convert to window coordinates
text_view = GTK_TEXT_VIEW (object);
priv = text_view->priv;
- g_assert (priv->buffer == NULL);
-
gtk_text_view_destroy_layout (text_view);
gtk_text_view_set_buffer (text_view, NULL);
+
+ /* at this point, no "notify::buffer" handler should recreate the buffer. */
+ g_assert (priv->buffer == NULL);
cancel_pending_scroll (text_view);
GtkTextView *text_view;
GtkTextViewPrivate *priv;
GtkStyleContext *context;
- GtkStateFlags state;
GdkWindow *window;
GdkWindowAttr attributes;
gint attributes_mask;
GSList *tmp_list;
- GdkRGBA color;
text_view = GTK_TEXT_VIEW (widget);
priv = text_view->priv;
gdk_window_set_user_data (window, widget);
context = gtk_widget_get_style_context (widget);
- state = gtk_widget_get_state_flags (widget);
- gtk_style_context_get_background_color (context, state, &color);
- gdk_window_set_background_rgba (window, &color);
+ gtk_style_context_save (context);
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
+ gtk_style_context_set_background (context, window);
+ gtk_style_context_restore (context);
text_window_realize (priv->text_window, widget);
text_window_realize (priv->bottom_window, widget);
gtk_text_view_ensure_layout (text_view);
+ gtk_text_view_invalidate (text_view);
if (priv->buffer)
{
if (priv->bottom_window)
text_window_unrealize (priv->bottom_window);
- gtk_text_view_destroy_layout (text_view);
-
GTK_WIDGET_CLASS (gtk_text_view_parent_class)->unrealize (widget);
}
gtk_style_context_save (context);
gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
- gtk_style_context_get_background_color (context, state, &color);
- gdk_window_set_background_rgba (priv->text_window->bin_window, &color);
+ gtk_style_context_set_background (context, priv->text_window->bin_window);
+ gtk_style_context_set_background (context, gtk_widget_get_window (widget));
gtk_style_context_restore (context);
/* Set lateral panes background */
gtk_style_context_get_background_color (context, state, &color);
- gdk_window_set_background_rgba (gtk_widget_get_window (widget), &color);
-
if (priv->left_window)
gdk_window_set_background_rgba (priv->left_window->bin_window, &color);
text_view = GTK_TEXT_VIEW (widget);
priv = text_view->priv;
+ GTK_WIDGET_CLASS (gtk_text_view_parent_class)->style_updated (widget);
+
if (gtk_widget_get_realized (widget))
{
gtk_text_view_set_background (text_view);
if (priv->grab_device &&
gtk_widget_device_is_shadowed (widget, priv->grab_device))
{
+ if (priv->drag_start_x >= 0)
+ {
+ priv->drag_start_x = -1;
+ priv->drag_start_y = -1;
+ }
+
gtk_text_view_end_selection_drag (GTK_TEXT_VIEW (widget));
gtk_text_view_unobscure_mouse_cursor (GTK_TEXT_VIEW (widget));
+ priv->grab_device = NULL;
}
}
#if 0
/* debug hack */
- if (event->button == 3 && (event->state & GDK_CONTROL_MASK) != 0)
+ if (event->button == GDK_BUTTON_SECONDARY && (event->state & GDK_CONTROL_MASK) != 0)
_gtk_text_buffer_spew (GTK_TEXT_VIEW (widget)->buffer);
- else if (event->button == 3)
+ else if (event->button == GDK_BUTTON_SECONDARY)
gtk_text_layout_spew (GTK_TEXT_VIEW (widget)->layout);
#endif
{
gtk_text_view_reset_im_context (text_view);
- if (event->button == 1)
+ if (gdk_event_triggers_context_menu ((GdkEvent *) event))
+ {
+ gtk_text_view_do_popup (text_view, event);
+ return TRUE;
+ }
+ else if (event->button == GDK_BUTTON_PRIMARY)
{
/* If we're in the selection, start a drag copy/move of the
* selection; otherwise, start creating a new selection.
if (gtk_text_buffer_get_selection_bounds (get_buffer (text_view),
&start, &end) &&
gtk_text_iter_in_range (&iter, &start, &end) &&
- !(event->state & GDK_SHIFT_MASK))
+ !(event->state &
+ gtk_widget_get_modifier_mask (widget,
+ GDK_MODIFIER_INTENT_EXTEND_SELECTION)))
{
+ priv->grab_device = event->device;
priv->drag_start_x = event->x;
priv->drag_start_y = event->y;
priv->pending_place_cursor_button = event->button;
return TRUE;
}
- else if (event->button == 2)
+ else if (event->button == GDK_BUTTON_MIDDLE)
{
GtkTextIter iter;
priv->editable);
return TRUE;
}
- else if (event->button == 3)
- {
- gtk_text_view_do_popup (text_view, event);
- return TRUE;
- }
}
else if ((event->type == GDK_2BUTTON_PRESS ||
event->type == GDK_3BUTTON_PRESS) &&
- event->button == 1)
+ event->button == GDK_BUTTON_PRIMARY)
{
GtkTextIter iter;
if (event->window != priv->text_window->bin_window)
return FALSE;
- if (event->button == 1)
+ if (event->button == GDK_BUTTON_PRIMARY)
{
if (priv->drag_start_x >= 0)
{
"interior-focus", &interior_focus,
NULL);
- if (gtk_widget_has_focus (widget) && !interior_focus)
+ if (gtk_widget_has_visible_focus (widget) && !interior_focus)
{
GtkStyleContext *context;
old_xpos = priv->xoffset;
old_ypos = priv->yoffset;
gtk_text_view_move_viewport (text_view, scroll_step, count);
- if ((old_xpos != priv->xoffset || old_ypos != priv->yoffset) &&
+ if ((old_xpos == priv->xoffset && old_ypos == priv->yoffset) &&
leave_direction != -1 &&
!gtk_widget_keynav_failed (GTK_WIDGET (text_view),
leave_direction))
orig_start = ins;
orig_end = bound;
- if (button->state & GDK_SHIFT_MASK)
+ if (button->state &
+ gtk_widget_get_modifier_mask (GTK_WIDGET (text_view),
+ GDK_MODIFIER_INTENT_EXTEND_SELECTION))
{
/* Extend selection */
GtkTextIter old_ins, old_bound;
tmp_list = g_slist_next (tmp_list);
}
-
- gtk_text_view_invalidate (text_view);
}
}
* into widget->allocation if the widget is not realized.
* FIXME someone figure out why this was.
*/
+ gtk_widget_get_allocation (widget, &allocation);
+
if (!gtk_widget_get_realized (widget))
{
if (gtk_widget_get_visible (widget))
adjust_allocation_recurse (widget, &scroll_data);
}
-
+
static void
gtk_text_view_value_changed (GtkAdjustment *adjustment,
GtkTextView *text_view)
gtk_target_list_unref (view_list);
}
-static void
-gtk_text_view_get_cursor_location (GtkTextView *text_view,
- GdkRectangle *pos)
-{
- GtkTextIter insert;
-
- gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &insert,
- gtk_text_buffer_get_insert (get_buffer (text_view)));
-
- gtk_text_layout_get_cursor_locations (text_view->priv->layout, &insert, pos, NULL);
-}
-
static void
gtk_text_view_get_virtual_cursor_pos (GtkTextView *text_view,
GtkTextIter *cursor,
return;
if (x == -1 || y == -1)
- gtk_text_view_get_cursor_location (text_view, &pos);
+ gtk_text_view_get_cursor_locations (text_view, NULL, &pos, NULL);
text_view->priv->virtual_cursor_x = (x == -1) ? pos.x : x;
text_view->priv->virtual_cursor_y = (y == -1) ? pos.y + pos.height / 2 : y;
monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y);
gtk_menu_set_monitor (menu, monitor_num);
- gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
+ gdk_screen_get_monitor_workarea (screen, monitor_num, &monitor);
*x = CLAMP (*x, monitor.x, monitor.x + MAX (0, monitor.width - req.width));
*y = CLAMP (*y, monitor.y, monitor.y + MAX (0, monitor.height - req.height));
GtkTextView *text_view;
gint button;
guint time;
+ GdkDevice *device;
} PopupInfo;
static gboolean
gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), menuitem);
menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_SELECT_ALL, NULL);
+ gtk_widget_set_sensitive (menuitem,
+ gtk_text_buffer_get_char_count (priv->buffer) > 0);
g_signal_connect (menuitem, "activate",
G_CALLBACK (select_all_cb), text_view);
gtk_widget_show (menuitem);
0,
priv->popup_menu);
- if (info->button)
- gtk_menu_popup (GTK_MENU (priv->popup_menu), NULL, NULL,
- NULL, NULL,
+ if (info->device)
+ gtk_menu_popup_for_device (GTK_MENU (priv->popup_menu),
+ info->device, NULL, NULL, NULL, NULL, NULL,
info->button, info->time);
else
{
{
info->button = event->button;
info->time = event->time;
+ info->device = event->device;
}
else
{
info->button = 0;
info->time = gtk_get_current_event_time ();
+ info->device = NULL;
}
gtk_clipboard_request_contents (gtk_widget_get_clipboard (GTK_WIDGET (text_view),
gtk_text_layout_get_cursor_locations (priv->layout, &iter,
&strong, &weak);
- /* cursor width calculation as in gtkstyle.c:draw_insertion_cursor(),
+ /* cursor width calculation as in gtkstylecontext.c:draw_insertion_cursor(),
* ignoring the text direction be exposing both sides of the cursor
*/