#include "gtkmenuitem.h"
#include "gtkseparatormenuitem.h"
#include "gtksettings.h"
+#include "gtkselectionprivate.h"
#include "gtkstock.h"
#include "gtktextbufferrichtext.h"
#include "gtktextdisplay.h"
GtkMovementStep step,
gint count,
gboolean extend_selection);
-static gboolean gtk_text_view_move_viewport (GtkTextView *text_view,
+static void gtk_text_view_move_viewport (GtkTextView *text_view,
GtkScrollStep step,
gint count);
static void gtk_text_view_set_anchor (GtkTextView *text_view);
static void gtk_text_view_stop_cursor_blink (GtkTextView *text_view);
static void gtk_text_view_reset_blink_time (GtkTextView *text_view);
-static void gtk_text_view_value_changed (GtkAdjustment *adj,
+static void gtk_text_view_value_changed (GtkAdjustment *adjustment,
GtkTextView *view);
static void gtk_text_view_commit_handler (GtkIMContext *context,
const gchar *str,
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,
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
line_top);
}
-static gboolean
-set_adjustment_clamped (GtkAdjustment *adj, gdouble val)
-{
- DV (g_print (" Setting adj to raw value %g\n", val));
-
- /* We don't really want to clamp to upper; we want to clamp to
- upper - page_size which is the highest value the scrollbar
- will let us reach. */
- if (val > (adj->upper - adj->page_size))
- val = adj->upper - adj->page_size;
-
- if (val < adj->lower)
- val = adj->lower;
-
- if (val != adj->value)
- {
- DV (g_print (" Setting adj to clamped value %g\n", val));
- gtk_adjustment_set_value (adj, val);
- return TRUE;
- }
- else
- return FALSE;
-}
-
/**
* gtk_text_view_scroll_to_iter:
* @text_view: a #GtkTextView
if (scroll_inc != 0)
{
- retval = set_adjustment_clamped (text_view->priv->vadjustment,
- current_y_scroll + scroll_inc);
+ gtk_adjustment_set_value (text_view->priv->vadjustment,
+ current_y_scroll + scroll_inc);
DV (g_print (" vert increment %d\n", scroll_inc));
}
if (scroll_inc != 0)
{
- retval = set_adjustment_clamped (text_view->priv->hadjustment,
- current_x_scroll + scroll_inc);
+ gtk_adjustment_set_value (text_view->priv->hadjustment,
+ current_x_scroll + scroll_inc);
DV (g_print (" horiz increment %d\n", scroll_inc));
}
+ retval = (current_y_scroll != gtk_adjustment_get_value (text_view->priv->vadjustment))
+ || (current_x_scroll != gtk_adjustment_get_value (text_view->priv->hadjustment));
+
if (retval)
{
DV(g_print (">Actually scrolled ("G_STRLOC")\n"));
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
{
priv->wrap_mode = wrap_mode;
- if (priv->layout)
+ if (priv->layout && priv->layout->default_style)
{
priv->layout->default_style->wrap_mode = wrap_mode;
gtk_text_layout_default_style_changed (priv->layout);
if (setting && gtk_widget_has_focus (GTK_WIDGET (text_view)))
gtk_im_context_focus_in (priv->im_context);
- if (priv->layout)
+ if (priv->layout && priv->layout->default_style)
{
gtk_text_layout_set_overwrite_mode (priv->layout,
priv->overwrite_mode && priv->editable);
{
priv->pixels_above_lines = pixels_above_lines;
- if (priv->layout)
+ if (priv->layout && priv->layout->default_style)
{
priv->layout->default_style->pixels_above_lines = pixels_above_lines;
gtk_text_layout_default_style_changed (priv->layout);
{
priv->pixels_below_lines = pixels_below_lines;
- if (priv->layout)
+ if (priv->layout && priv->layout->default_style)
{
priv->layout->default_style->pixels_below_lines = pixels_below_lines;
gtk_text_layout_default_style_changed (priv->layout);
{
priv->pixels_inside_wrap = pixels_inside_wrap;
- if (priv->layout)
+ if (priv->layout && priv->layout->default_style)
{
priv->layout->default_style->pixels_inside_wrap = pixels_inside_wrap;
gtk_text_layout_default_style_changed (priv->layout);
{
priv->justify = justification;
- if (priv->layout)
+ if (priv->layout && priv->layout->default_style)
{
priv->layout->default_style->justification = justification;
gtk_text_layout_default_style_changed (priv->layout);
{
priv->left_margin = left_margin;
- if (priv->layout)
+ if (priv->layout && priv->layout->default_style)
{
priv->layout->default_style->left_margin = left_margin;
gtk_text_layout_default_style_changed (priv->layout);
{
priv->right_margin = right_margin;
- if (priv->layout)
+ if (priv->layout && priv->layout->default_style)
{
priv->layout->default_style->right_margin = right_margin;
gtk_text_layout_default_style_changed (priv->layout);
{
priv->indent = indent;
- if (priv->layout)
+ if (priv->layout && priv->layout->default_style)
{
priv->layout->default_style->indent = indent;
gtk_text_layout_default_style_changed (priv->layout);
priv->tabs = tabs ? pango_tab_array_copy (tabs) : NULL;
- if (priv->layout)
+ if (priv->layout && priv->layout->default_style)
{
/* some unkosher futzing in internal struct details... */
if (priv->layout->default_style->tabs)
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);
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);
{
GtkTextViewPrivate *priv = GTK_TEXT_VIEW (widget)->priv;
- if (priv->layout)
+ if (priv->layout && priv->layout->default_style)
{
priv->layout->default_style->direction = gtk_widget_get_direction (widget);
if (!priv->cursor_visible)
{
GtkScrollStep scroll_step;
+ gdouble old_xpos, old_ypos;
switch (step)
{
break;
}
- if (!gtk_text_view_move_viewport (text_view, scroll_step, count))
+ 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) &&
+ leave_direction != -1 &&
+ !gtk_widget_keynav_failed (GTK_WIDGET (text_view),
+ leave_direction))
{
- if (leave_direction != -1 &&
- !gtk_widget_keynav_failed (GTK_WIDGET (text_view),
- leave_direction))
- {
- g_signal_emit_by_name (text_view, "move-focus", leave_direction);
- }
+ g_signal_emit_by_name (text_view, "move-focus", leave_direction);
}
return;
gtk_text_view_move_cursor_internal (text_view, step, count, extend_selection);
}
-static gboolean
+static void
gtk_text_view_move_viewport (GtkTextView *text_view,
GtkScrollStep step,
gint count)
break;
}
- return set_adjustment_clamped (adjustment, gtk_adjustment_get_value (adjustment) + count * increment);
+ gtk_adjustment_set_value (adjustment, gtk_adjustment_get_value (adjustment) + count * increment);
}
static void
gboolean extend_selection)
{
GtkTextViewPrivate *priv;
- GtkAdjustment *adj;
+ GtkAdjustment *adjustment;
gint cursor_x_pos, cursor_y_pos;
GtkTextMark *insert_mark;
GtkTextIter old_insert;
g_return_val_if_fail (priv->vadjustment != NULL, FALSE);
- adj = priv->vadjustment;
+ adjustment = priv->vadjustment;
insert_mark = gtk_text_buffer_get_insert (get_buffer (text_view));
if (count < 0)
{
gtk_text_view_get_first_para_iter (text_view, &anchor);
- y0 = adj->page_size;
- y1 = adj->page_size + count * adj->page_increment;
+ y0 = gtk_adjustment_get_page_size (adjustment);
+ y1 = gtk_adjustment_get_page_size (adjustment) + count * gtk_adjustment_get_page_increment (adjustment);
}
else
{
gtk_text_view_get_first_para_iter (text_view, &anchor);
- y0 = count * adj->page_increment + adj->page_size;
+ y0 = count * gtk_adjustment_get_page_increment (adjustment) + gtk_adjustment_get_page_size (adjustment);
y1 = 0;
}
new_insert = old_insert;
- if (count < 0 && adj->value <= (adj->lower + 1e-12))
+ if (count < 0 && gtk_adjustment_get_value (adjustment) <= (gtk_adjustment_get_lower (adjustment) + 1e-12))
{
/* already at top, just be sure we are at offset 0 */
gtk_text_buffer_get_start_iter (get_buffer (text_view), &new_insert);
move_cursor (text_view, &new_insert, extend_selection);
}
- else if (count > 0 && adj->value >= (adj->upper - adj->page_size - 1e-12))
+ else if (count > 0 && gtk_adjustment_get_value (adjustment) >= (gtk_adjustment_get_upper (adjustment) - gtk_adjustment_get_page_size (adjustment) - 1e-12))
{
/* already at bottom, just be sure we are at the end */
gtk_text_buffer_get_end_iter (get_buffer (text_view), &new_insert);
{
gtk_text_view_get_virtual_cursor_pos (text_view, NULL, &cursor_x_pos, &cursor_y_pos);
- oldval = adj->value;
- newval = adj->value;
+ oldval = gtk_adjustment_get_value (adjustment);
+ newval = gtk_adjustment_get_value (adjustment);
- newval += count * adj->page_increment;
+ newval += count * gtk_adjustment_get_page_increment (adjustment);
- set_adjustment_clamped (adj, newval);
- cursor_y_pos += adj->value - oldval;
+ gtk_adjustment_set_value (adjustment, newval);
+ cursor_y_pos += gtk_adjustment_get_value (adjustment) - oldval;
gtk_text_layout_get_iter_at_pixel (priv->layout, &new_insert, cursor_x_pos, cursor_y_pos);
clamp_iter_onscreen (text_view, &new_insert);
gboolean extend_selection)
{
GtkTextViewPrivate *priv;
- GtkAdjustment *adj;
+ GtkAdjustment *adjustment;
gint cursor_x_pos, cursor_y_pos;
GtkTextMark *insert_mark;
GtkTextIter old_insert;
g_return_val_if_fail (priv->hadjustment != NULL, FALSE);
- adj = priv->hadjustment;
+ adjustment = priv->hadjustment;
insert_mark = gtk_text_buffer_get_insert (get_buffer (text_view));
new_insert = old_insert;
- if (count < 0 && adj->value <= (adj->lower + 1e-12))
+ if (count < 0 && gtk_adjustment_get_value (adjustment) <= (gtk_adjustment_get_lower (adjustment) + 1e-12))
{
/* already at far left, just be sure we are at offset 0 */
gtk_text_iter_set_line_offset (&new_insert, 0);
move_cursor (text_view, &new_insert, extend_selection);
}
- else if (count > 0 && adj->value >= (adj->upper - adj->page_size - 1e-12))
+ else if (count > 0 && gtk_adjustment_get_value (adjustment) >= (gtk_adjustment_get_upper (adjustment) - gtk_adjustment_get_page_size (adjustment) - 1e-12))
{
/* already at far right, just be sure we are at the end */
if (!gtk_text_iter_ends_line (&new_insert))
{
gtk_text_view_get_virtual_cursor_pos (text_view, NULL, &cursor_x_pos, &cursor_y_pos);
- oldval = adj->value;
- newval = adj->value;
+ oldval = gtk_adjustment_get_value (adjustment);
+ newval = gtk_adjustment_get_value (adjustment);
- newval += count * adj->page_increment;
+ newval += count * gtk_adjustment_get_page_increment (adjustment);
- set_adjustment_clamped (adj, newval);
- cursor_x_pos += adj->value - oldval;
+ gtk_adjustment_set_value (adjustment, newval);
+ cursor_x_pos += gtk_adjustment_get_value (adjustment) - oldval;
gtk_text_layout_get_iter_at_pixel (priv->layout, &new_insert, cursor_x_pos, cursor_y_pos);
clamp_iter_onscreen (text_view, &new_insert);
#define LOWER_OFFSET_ANCHOR 0.2
static gboolean
-check_scroll (gdouble offset, GtkAdjustment *adj)
+check_scroll (gdouble offset, GtkAdjustment *adjustment)
{
if ((offset > UPPER_OFFSET_ANCHOR &&
- adj->value + adj->page_size < adj->upper) ||
+ gtk_adjustment_get_value (adjustment) + gtk_adjustment_get_page_size (adjustment) < gtk_adjustment_get_upper (adjustment)) ||
(offset < LOWER_OFFSET_ANCHOR &&
- adj->value > adj->lower))
+ gtk_adjustment_get_value (adjustment) > gtk_adjustment_get_lower (adjustment)))
return TRUE;
return FALSE;
context = gtk_widget_get_style_context (GTK_WIDGET (text_view));
state = gtk_widget_get_state_flags (GTK_WIDGET (text_view));
+ gtk_style_context_save (context);
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_VIEW);
+
gtk_style_context_get_background_color (context, state, &bg_color);
gtk_style_context_get_color (context, state, &fg_color);
pango_font_description_free (values->font);
values->font = pango_font_description_copy (gtk_style_context_get_font (context, state));
+
+ gtk_style_context_restore (context);
}
static void
}
static void
-gtk_text_view_value_changed (GtkAdjustment *adj,
+gtk_text_view_value_changed (GtkAdjustment *adjustment,
GtkTextView *text_view)
{
GtkTextViewPrivate *priv;
priv = text_view->priv;
- /* Note that we oddly call this function with adj == NULL
+ /* Note that we oddly call this function with adjustment == NULL
* sometimes
*/
priv->onscreen_validated = FALSE;
DV(g_print(">Scroll offset changed %s/%g, onscreen_validated = FALSE ("G_STRLOC")\n",
- adj == priv->hadjustment ? "hadj" : adj == priv->vadjustment ? "vadj" : "none",
- adj ? adj->value : 0.0));
+ adjustment == priv->hadjustment ? "hadjustment" : adjustment == priv->vadjustment ? "vadjustment" : "none",
+ adjustment ? gtk_adjustment_get_value (adjustment) : 0.0));
- if (adj == priv->hadjustment)
+ if (adjustment == priv->hadjustment)
{
- dx = priv->xoffset - (gint)adj->value;
- priv->xoffset = adj->value;
+ dx = priv->xoffset - (gint)gtk_adjustment_get_value (adjustment);
+ priv->xoffset = gtk_adjustment_get_value (adjustment);
/* If the change is due to a size change we need
* to invalidate the entire text window because there might be
priv->width_changed = FALSE;
}
}
- else if (adj == priv->vadjustment)
+ else if (adjustment == priv->vadjustment)
{
- dy = priv->yoffset - (gint)adj->value;
- priv->yoffset = adj->value;
+ dy = priv->yoffset - (gint)gtk_adjustment_get_value (adjustment);
+ priv->yoffset = gtk_adjustment_get_value (adjustment);
if (priv->layout)
{
- gtk_text_layout_get_line_at_y (priv->layout, &iter, adj->value, &line_top);
+ gtk_text_layout_get_line_at_y (priv->layout, &iter, gtk_adjustment_get_value (adjustment), &line_top);
gtk_text_buffer_move_mark (get_buffer (text_view), priv->first_para_mark, &iter);
- priv->first_para_pixels = adj->value - line_top;
+ priv->first_para_pixels = gtk_adjustment_get_value (adjustment) - line_top;
}
}
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;