fix indentation

2000-09-29  Havoc Pennington  <hp@redhat.com>

	* gtk/gtktexttag.c (gtk_text_tag_set_priority): fix indentation

        * gtk/gtktextview.c: Implement drag thresholding; change functions
	that set border window size to have nicer name
	(gtk_text_view_mark_set_handler):  Fix this to have the
	right signature.

	* gtk/testtextbuffer.c (fill_buffer): Update with pixbuf changes

	* gtk/testtext.c: Update with API changes, put line numbers on
	both sides.

	* gtk/gtktextiter.c (gtk_text_iter_get_pixbuf): Replace get_pixmap
	with this

	* gtk/gtktextchild.h, gtk/gtktextchild.c: replace all pixmap with
	pixbuf; delete a big block of #if 0 Tk code

	* gtk/gtktextbuffer.c (gtk_text_buffer_insert_pixbuf): Replace
	insert_pixmap with insert_pixbuf
This commit is contained in:
Havoc Pennington 2000-09-30 00:17:22 +00:00 committed by Havoc Pennington
parent 0415b69e76
commit 244996ffec
29 changed files with 1030 additions and 1593 deletions

View File

@ -1,3 +1,26 @@
2000-09-29 Havoc Pennington <hp@redhat.com>
* gtk/gtktexttag.c (gtk_text_tag_set_priority): fix indentation
* gtk/gtktextview.c: Implement drag thresholding; change functions
that set border window size to have nicer name
(gtk_text_view_mark_set_handler): Fix this to have the
right signature.
* gtk/testtextbuffer.c (fill_buffer): Update with pixbuf changes
* gtk/testtext.c: Update with API changes, put line numbers on
both sides.
* gtk/gtktextiter.c (gtk_text_iter_get_pixbuf): Replace get_pixmap
with this
* gtk/gtktextchild.h, gtk/gtktextchild.c: replace all pixmap with
pixbuf; delete a big block of #if 0 Tk code
* gtk/gtktextbuffer.c (gtk_text_buffer_insert_pixbuf): Replace
insert_pixmap with insert_pixbuf
2000-09-29 Martin Baulig <baulig@suse.de>
* Makefile.am (pkgconfigdir): Set this to `$(libexecdir)/pkgconfig';

View File

@ -1,3 +1,26 @@
2000-09-29 Havoc Pennington <hp@redhat.com>
* gtk/gtktexttag.c (gtk_text_tag_set_priority): fix indentation
* gtk/gtktextview.c: Implement drag thresholding; change functions
that set border window size to have nicer name
(gtk_text_view_mark_set_handler): Fix this to have the
right signature.
* gtk/testtextbuffer.c (fill_buffer): Update with pixbuf changes
* gtk/testtext.c: Update with API changes, put line numbers on
both sides.
* gtk/gtktextiter.c (gtk_text_iter_get_pixbuf): Replace get_pixmap
with this
* gtk/gtktextchild.h, gtk/gtktextchild.c: replace all pixmap with
pixbuf; delete a big block of #if 0 Tk code
* gtk/gtktextbuffer.c (gtk_text_buffer_insert_pixbuf): Replace
insert_pixmap with insert_pixbuf
2000-09-29 Martin Baulig <baulig@suse.de>
* Makefile.am (pkgconfigdir): Set this to `$(libexecdir)/pkgconfig';

View File

@ -1,3 +1,26 @@
2000-09-29 Havoc Pennington <hp@redhat.com>
* gtk/gtktexttag.c (gtk_text_tag_set_priority): fix indentation
* gtk/gtktextview.c: Implement drag thresholding; change functions
that set border window size to have nicer name
(gtk_text_view_mark_set_handler): Fix this to have the
right signature.
* gtk/testtextbuffer.c (fill_buffer): Update with pixbuf changes
* gtk/testtext.c: Update with API changes, put line numbers on
both sides.
* gtk/gtktextiter.c (gtk_text_iter_get_pixbuf): Replace get_pixmap
with this
* gtk/gtktextchild.h, gtk/gtktextchild.c: replace all pixmap with
pixbuf; delete a big block of #if 0 Tk code
* gtk/gtktextbuffer.c (gtk_text_buffer_insert_pixbuf): Replace
insert_pixmap with insert_pixbuf
2000-09-29 Martin Baulig <baulig@suse.de>
* Makefile.am (pkgconfigdir): Set this to `$(libexecdir)/pkgconfig';

View File

@ -1,3 +1,26 @@
2000-09-29 Havoc Pennington <hp@redhat.com>
* gtk/gtktexttag.c (gtk_text_tag_set_priority): fix indentation
* gtk/gtktextview.c: Implement drag thresholding; change functions
that set border window size to have nicer name
(gtk_text_view_mark_set_handler): Fix this to have the
right signature.
* gtk/testtextbuffer.c (fill_buffer): Update with pixbuf changes
* gtk/testtext.c: Update with API changes, put line numbers on
both sides.
* gtk/gtktextiter.c (gtk_text_iter_get_pixbuf): Replace get_pixmap
with this
* gtk/gtktextchild.h, gtk/gtktextchild.c: replace all pixmap with
pixbuf; delete a big block of #if 0 Tk code
* gtk/gtktextbuffer.c (gtk_text_buffer_insert_pixbuf): Replace
insert_pixmap with insert_pixbuf
2000-09-29 Martin Baulig <baulig@suse.de>
* Makefile.am (pkgconfigdir): Set this to `$(libexecdir)/pkgconfig';

View File

@ -1,3 +1,26 @@
2000-09-29 Havoc Pennington <hp@redhat.com>
* gtk/gtktexttag.c (gtk_text_tag_set_priority): fix indentation
* gtk/gtktextview.c: Implement drag thresholding; change functions
that set border window size to have nicer name
(gtk_text_view_mark_set_handler): Fix this to have the
right signature.
* gtk/testtextbuffer.c (fill_buffer): Update with pixbuf changes
* gtk/testtext.c: Update with API changes, put line numbers on
both sides.
* gtk/gtktextiter.c (gtk_text_iter_get_pixbuf): Replace get_pixmap
with this
* gtk/gtktextchild.h, gtk/gtktextchild.c: replace all pixmap with
pixbuf; delete a big block of #if 0 Tk code
* gtk/gtktextbuffer.c (gtk_text_buffer_insert_pixbuf): Replace
insert_pixmap with insert_pixbuf
2000-09-29 Martin Baulig <baulig@suse.de>
* Makefile.am (pkgconfigdir): Set this to `$(libexecdir)/pkgconfig';

View File

@ -1,3 +1,26 @@
2000-09-29 Havoc Pennington <hp@redhat.com>
* gtk/gtktexttag.c (gtk_text_tag_set_priority): fix indentation
* gtk/gtktextview.c: Implement drag thresholding; change functions
that set border window size to have nicer name
(gtk_text_view_mark_set_handler): Fix this to have the
right signature.
* gtk/testtextbuffer.c (fill_buffer): Update with pixbuf changes
* gtk/testtext.c: Update with API changes, put line numbers on
both sides.
* gtk/gtktextiter.c (gtk_text_iter_get_pixbuf): Replace get_pixmap
with this
* gtk/gtktextchild.h, gtk/gtktextchild.c: replace all pixmap with
pixbuf; delete a big block of #if 0 Tk code
* gtk/gtktextbuffer.c (gtk_text_buffer_insert_pixbuf): Replace
insert_pixmap with insert_pixbuf
2000-09-29 Martin Baulig <baulig@suse.de>
* Makefile.am (pkgconfigdir): Set this to `$(libexecdir)/pkgconfig';

View File

@ -1,3 +1,26 @@
2000-09-29 Havoc Pennington <hp@redhat.com>
* gtk/gtktexttag.c (gtk_text_tag_set_priority): fix indentation
* gtk/gtktextview.c: Implement drag thresholding; change functions
that set border window size to have nicer name
(gtk_text_view_mark_set_handler): Fix this to have the
right signature.
* gtk/testtextbuffer.c (fill_buffer): Update with pixbuf changes
* gtk/testtext.c: Update with API changes, put line numbers on
both sides.
* gtk/gtktextiter.c (gtk_text_iter_get_pixbuf): Replace get_pixmap
with this
* gtk/gtktextchild.h, gtk/gtktextchild.c: replace all pixmap with
pixbuf; delete a big block of #if 0 Tk code
* gtk/gtktextbuffer.c (gtk_text_buffer_insert_pixbuf): Replace
insert_pixmap with insert_pixbuf
2000-09-29 Martin Baulig <baulig@suse.de>
* Makefile.am (pkgconfigdir): Set this to `$(libexecdir)/pkgconfig';

View File

@ -1043,9 +1043,8 @@ gtk_text_btree_insert (GtkTextIter *iter,
}
void
gtk_text_btree_insert_pixmap (GtkTextIter *iter,
GdkPixmap *pixmap,
GdkBitmap *mask)
gtk_text_btree_insert_pixbuf (GtkTextIter *iter,
GdkPixbuf *pixbuf)
{
GtkTextLineSegment *seg;
GtkTextIter start;
@ -1058,7 +1057,7 @@ gtk_text_btree_insert_pixmap (GtkTextIter *iter,
tree = gtk_text_iter_get_btree(iter);
start_byte_offset = gtk_text_iter_get_line_index(iter);
seg = gtk_text_pixmap_segment_new (pixmap, mask);
seg = gtk_text_pixbuf_segment_new (pixbuf);
prevPtr = gtk_text_line_segment_split(iter);
if (prevPtr == NULL)
@ -2037,7 +2036,7 @@ copy_segment(GString *string,
/* printf(" :%s\n", string->str); */
}
else if (seg->type == &gtk_text_pixmap_type)
else if (seg->type == &gtk_text_pixbuf_type)
{
gboolean copy = TRUE;
@ -3401,7 +3400,7 @@ gtk_text_line_byte_to_char (GtkTextLine *line,
gint
gtk_text_line_char_to_byte (GtkTextLine *line,
gint char_offset)
gint char_offset)
{
g_warning("FIXME not implemented");
}

View File

@ -31,9 +31,8 @@ void gtk_text_btree_delete (GtkTextIter *start,
void gtk_text_btree_insert (GtkTextIter *iter,
const gchar *text,
gint len);
void gtk_text_btree_insert_pixmap (GtkTextIter *iter,
GdkPixmap *pixmap,
GdkBitmap *mask);
void gtk_text_btree_insert_pixbuf (GtkTextIter *iter,
GdkPixbuf *pixbuf);

View File

@ -787,22 +787,21 @@ gtk_text_buffer_get_slice (GtkTextBuffer *buffer,
*/
void
gtk_text_buffer_insert_pixmap (GtkTextBuffer *buffer,
GtkTextIter *iter,
GdkPixmap *pixmap,
GdkBitmap *mask)
gtk_text_buffer_insert_pixbuf (GtkTextBuffer *buffer,
GtkTextIter *iter,
GdkPixbuf *pixbuf)
{
g_return_if_fail(GTK_IS_TEXT_BUFFER(buffer));
g_return_if_fail(iter != NULL);
g_return_if_fail(pixmap != NULL);
gtk_text_btree_insert_pixmap(iter, pixmap, mask);
/* FIXME pixmap-specific signal like insert_text */
g_return_if_fail (GTK_IS_TEXT_BUFFER(buffer));
g_return_if_fail (iter != NULL);
g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
gtk_signal_emit(GTK_OBJECT(buffer), signals[CHANGED]);
gtk_text_btree_insert_pixbuf (iter, pixbuf);
/* FIXME pixbuf-specific signal like insert_text */
gtk_text_buffer_set_modified(buffer, TRUE);
gtk_signal_emit (GTK_OBJECT(buffer), signals[CHANGED]);
gtk_text_buffer_set_modified (buffer, TRUE);
}
/*
@ -977,6 +976,22 @@ gtk_text_buffer_get_mark (GtkTextBuffer *buffer,
return mark;
}
GtkTextMark*
gtk_text_buffer_get_insert (GtkTextBuffer *buffer)
{
g_return_val_if_fail(GTK_IS_TEXT_BUFFER(buffer), NULL);
return gtk_text_buffer_get_mark (buffer, "insert");
}
GtkTextMark*
gtk_text_buffer_get_selection_bound (GtkTextBuffer *buffer)
{
g_return_val_if_fail(GTK_IS_TEXT_BUFFER(buffer), NULL);
return gtk_text_buffer_get_mark (buffer, "selection_bound");
}
/**
* gtk_text_buffer_place_cursor:
* @buffer: a #GtkTextBuffer

View File

@ -133,11 +133,10 @@ gchar *gtk_text_buffer_get_slice (GtkTextBuffer *buffer,
const GtkTextIter *end,
gboolean include_hidden_chars);
/* Insert a pixmap */
void gtk_text_buffer_insert_pixmap (GtkTextBuffer *buffer,
/* Insert a pixbuf */
void gtk_text_buffer_insert_pixbuf (GtkTextBuffer *buffer,
GtkTextIter *iter,
GdkPixmap *pixmap,
GdkBitmap *mask);
GdkPixbuf *pixbuf);
/* Mark manipulation */
GtkTextMark *gtk_text_buffer_create_mark (GtkTextBuffer *buffer,
@ -149,9 +148,12 @@ void gtk_text_buffer_move_mark (GtkTextBuffer *buffer,
const GtkTextIter *where);
void gtk_text_buffer_delete_mark (GtkTextBuffer *buffer,
GtkTextMark *mark);
GtkTextMark *gtk_text_buffer_get_mark (GtkTextBuffer *buffer,
GtkTextMark* gtk_text_buffer_get_mark (GtkTextBuffer *buffer,
const gchar *name);
GtkTextMark* gtk_text_buffer_get_insert (GtkTextBuffer *buffer);
GtkTextMark* gtk_text_buffer_get_selection_bound (GtkTextBuffer *buffer);
/* efficiently move insert and selection_bound to same location */
void gtk_text_buffer_place_cursor (GtkTextBuffer *buffer,

File diff suppressed because it is too large Load Diff

View File

@ -7,14 +7,13 @@
extern "C" {
#endif /* __cplusplus */
typedef struct _GtkTextPixmap GtkTextPixmap;
typedef struct _GtkTextPixbuf GtkTextPixbuf;
struct _GtkTextPixmap {
GdkPixmap *pixmap;
GdkBitmap *mask;
struct _GtkTextPixbuf {
GdkPixbuf *pixbuf;
};
GtkTextLineSegment *gtk_text_pixmap_segment_new(GdkPixmap *pixmap, GdkBitmap *mask);
GtkTextLineSegment *gtk_text_pixbuf_segment_new(GdkPixbuf *pixbuf);
#ifdef __cplusplus

View File

@ -159,7 +159,7 @@ static void
render_layout_line (GdkDrawable *drawable,
GtkTextRenderState *render_state,
PangoLayoutLine *line,
GSList **pixmap_pointer,
GSList **pixbuf_pointer,
int x,
int y,
gboolean selected)
@ -246,37 +246,67 @@ render_layout_line (GdkDrawable *drawable,
x_off += logical_rect.width;
}
else /* Pixmap segment */
else /* Pixbuf segment */
{
GtkTextPixmap *pixmap = (*pixmap_pointer)->data;
GtkTextPixbuf *pixbuf = (*pixbuf_pointer)->data;
gint width, height;
GdkRectangle pixmap_rect, draw_rect;
*pixmap_pointer = (*pixmap_pointer)->next;
GdkRectangle pixbuf_rect, draw_rect;
GdkBitmap *mask = NULL;
*pixbuf_pointer = (*pixbuf_pointer)->next;
gdk_drawable_get_size (pixmap->pixmap, &width, &height);
width = gdk_pixbuf_get_width (pixbuf->pixbuf);
height = gdk_pixbuf_get_height (pixbuf->pixbuf);
pixmap_rect.x = x + x_off / PANGO_SCALE;
pixmap_rect.y = y - height;
pixmap_rect.width = width;
pixmap_rect.height = height;
pixbuf_rect.x = x + x_off / PANGO_SCALE;
pixbuf_rect.y = y - height;
pixbuf_rect.width = width;
pixbuf_rect.height = height;
if (gdk_rectangle_intersect (&pixbuf_rect, &render_state->clip_rect,
&draw_rect))
{
if (gdk_pixbuf_get_has_alpha (pixbuf->pixbuf))
{
mask = gdk_pixmap_new (drawable,
gdk_pixbuf_get_width (pixbuf->pixbuf),
gdk_pixbuf_get_height (pixbuf->pixbuf),
1);
gdk_rectangle_intersect (&pixmap_rect, &render_state->clip_rect, &draw_rect);
gdk_pixbuf_render_threshold_alpha (pixbuf->pixbuf, mask,
0, 0, 0, 0,
gdk_pixbuf_get_width (pixbuf->pixbuf),
gdk_pixbuf_get_height (pixbuf->pixbuf),
128);
}
if (pixmap->mask)
{
gdk_gc_set_clip_mask (render_state->fg_gc, pixmap->mask);
gdk_gc_set_clip_origin (render_state->fg_gc,
pixmap_rect.x, pixmap_rect.y);
}
gdk_draw_drawable (drawable, render_state->fg_gc, pixmap->pixmap,
draw_rect.x - pixmap_rect.x, draw_rect.y - pixmap_rect.y,
draw_rect.x, draw_rect.y, draw_rect.width, draw_rect.height);
if (pixmap->mask)
gdk_gc_set_clip_rectangle (render_state->fg_gc, &render_state->clip_rect);
if (mask)
{
gdk_gc_set_clip_mask (render_state->fg_gc, mask);
gdk_gc_set_clip_origin (render_state->fg_gc,
pixbuf_rect.x, pixbuf_rect.y);
}
gdk_pixbuf_render_to_drawable (pixbuf->pixbuf,
drawable,
render_state->fg_gc,
draw_rect.x - pixbuf_rect.x,
draw_rect.y - pixbuf_rect.y,
draw_rect.x, draw_rect.y,
draw_rect.width,
draw_rect.height,
GDK_RGB_DITHER_NORMAL,
0, 0);
if (mask)
{
gdk_gc_set_clip_rectangle (render_state->fg_gc,
&render_state->clip_rect);
g_object_unref (G_OBJECT (mask));
}
}
x_off += width * PANGO_SCALE;
}
}
@ -292,7 +322,7 @@ render_para (GdkDrawable *drawable,
int selection_end_index)
{
PangoRectangle logical_rect;
GSList *pixmap_pointer = line_display->pixmaps;
GSList *pixbuf_pointer = line_display->pixbufs;
GSList *tmp_list;
PangoAlignment align;
PangoLayout *layout = line_display->layout;
@ -375,15 +405,15 @@ render_para (GdkDrawable *drawable,
TRUE,
x + line_display->left_margin, selection_y,
total_width / PANGO_SCALE, selection_height);
render_layout_line (drawable, render_state, line, &pixmap_pointer,
render_layout_line (drawable, render_state, line, &pixbuf_pointer,
x + x_offset / PANGO_SCALE, y + (y_offset - logical_rect.y) / PANGO_SCALE,
TRUE);
}
else
{
GSList *pixmap_pointer_tmp = pixmap_pointer;
GSList *pixbuf_pointer_tmp = pixbuf_pointer;
render_layout_line (drawable, render_state, line, &pixmap_pointer,
render_layout_line (drawable, render_state, line, &pixbuf_pointer,
x + x_offset / PANGO_SCALE, y + (y_offset - logical_rect.y) / PANGO_SCALE,
FALSE);
@ -405,7 +435,7 @@ render_para (GdkDrawable *drawable,
logical_rect.width / PANGO_SCALE,
selection_height);
render_layout_line (drawable, render_state, line, &pixmap_pointer_tmp,
render_layout_line (drawable, render_state, line, &pixbuf_pointer_tmp,
x + x_offset / PANGO_SCALE, y + (y_offset - logical_rect.y) / PANGO_SCALE,
TRUE);

View File

@ -794,34 +794,21 @@ gtk_text_iter_get_visible_text (const GtkTextIter *start,
}
/**
* gtk_text_iter_get_pixmap:
* gtk_text_iter_get_pixbuf:
* @iter: an iterator
* @pixmap: return location for the pixmap
* @mask: return location for the mask
*
* If the location pointed to by @iter contains a pixmap, the pixmap
* is placed in @pixmap, the mask is placed in @mask, and
* gtk_text_iter_get_pixmap() returns TRUE. If @iter points at
* something else, FALSE will be returned and @pixmap/@mask will
* remain unchanged. The pixmap and mask do not have their reference
* count incremented. If the pixmap has no mask, NULL is returned for
* the mask.
* If the location pointed to by @iter contains a pixbuf, the pixbuf
* is returned (with no new reference count added). Otherwise,
* NULL is returned.
*
* Return value: whether the iterator pointed at a pixmap
* Return value: the pixbuf at @iter
**/
gboolean
gtk_text_iter_get_pixmap (const GtkTextIter *iter,
GdkPixmap** pixmap,
GdkBitmap** mask)
GdkPixbuf*
gtk_text_iter_get_pixbuf (const GtkTextIter *iter)
{
GtkTextRealIter *real;
g_return_val_if_fail(iter != NULL, FALSE);
g_return_val_if_fail(pixmap != NULL, FALSE);
g_return_val_if_fail(mask != NULL, FALSE);
*pixmap = NULL;
*mask = NULL;
real = gtk_text_iter_make_real(iter);
@ -830,17 +817,10 @@ gtk_text_iter_get_pixmap (const GtkTextIter *iter,
check_invariants(iter);
if (real->segment->type != &gtk_text_pixmap_type)
if (real->segment->type != &gtk_text_pixbuf_type)
return FALSE;
else
{
if (pixmap)
*pixmap = real->segment->body.pixmap.pixmap;
if (mask)
*mask = real->segment->body.pixmap.pixmap;
return TRUE;
}
return real->segment->body.pixbuf.pixbuf;
}
/**

View File

@ -72,12 +72,8 @@ gchar *gtk_text_iter_get_visible_slice (const GtkTextIter *start,
gchar *gtk_text_iter_get_visible_text (const GtkTextIter *start,
const GtkTextIter *end);
/* Returns TRUE if the iterator pointed at a pixmap */
gboolean gtk_text_iter_get_pixmap (const GtkTextIter *iter,
GdkPixmap **pixmap,
GdkBitmap **mask);
GSList *gtk_text_iter_get_marks (const GtkTextIter *iter);
GdkPixbuf* gtk_text_iter_get_pixbuf (const GtkTextIter *iter);
GSList * gtk_text_iter_get_marks (const GtkTextIter *iter);
/* Return list of tags toggled at this point (toggled_on determines
whether the list is of on-toggles or off-toggles) */

View File

@ -1170,7 +1170,7 @@ add_text_attrs (GtkTextLayout *layout,
}
static void
add_pixmap_attrs (GtkTextLayout *layout,
add_pixbuf_attrs (GtkTextLayout *layout,
GtkTextLineDisplay *display,
GtkTextAttributes *style,
GtkTextLineSegment *seg,
@ -1179,10 +1179,12 @@ add_pixmap_attrs (GtkTextLayout *layout,
{
PangoAttribute *attr;
PangoRectangle logical_rect;
GtkTextPixmap *pixmap = &seg->body.pixmap;
GtkTextPixbuf *pixbuf = &seg->body.pixbuf;
gint width, height;
gdk_drawable_get_size (pixmap->pixmap, &width, &height);
width = gdk_pixbuf_get_width (pixbuf->pixbuf);
height = gdk_pixbuf_get_height (pixbuf->pixbuf);
logical_rect.x = 0;
logical_rect.y = -height * PANGO_SCALE;
logical_rect.width = width * PANGO_SCALE;
@ -1193,7 +1195,7 @@ add_pixmap_attrs (GtkTextLayout *layout,
attr->end_index = start + seg->byte_count;
pango_attr_list_insert (attrs, attr);
display->pixmaps = g_slist_append (display->pixmaps, pixmap);
display->pixbufs = g_slist_append (display->pixbufs, pixbuf);
}
static void
@ -1305,7 +1307,7 @@ gtk_text_layout_get_line_display (GtkTextLayout *layout,
{
/* Displayable segments */
if (seg->type == &gtk_text_char_type ||
seg->type == &gtk_text_pixmap_type)
seg->type == &gtk_text_pixbuf_type)
{
gtk_text_btree_get_iter_at_line (_gtk_text_buffer_get_btree (layout->buffer),
&iter, line,
@ -1313,7 +1315,7 @@ gtk_text_layout_get_line_display (GtkTextLayout *layout,
style = get_style (layout, &iter);
/* We have to delay setting the paragraph values until we
* hit the first pixmap or text segment because toggles at
* hit the first pixbuf or text segment because toggles at
* the beginning of the paragraph should affect the
* paragraph-global values
*/
@ -1367,7 +1369,7 @@ gtk_text_layout_get_line_display (GtkTextLayout *layout,
}
else
{
add_pixmap_attrs (layout, display, style, seg, attrs, byte_offset);
add_pixbuf_attrs (layout, display, style, seg, attrs, byte_offset);
memcpy (text + byte_offset, gtk_text_unknown_char_utf8, seg->byte_count);
byte_offset += seg->byte_count;
}
@ -1461,7 +1463,7 @@ gtk_text_layout_free_line_display (GtkTextLayout *layout,
{
g_slist_foreach (display->cursors, (GFunc)g_free, NULL);
g_slist_free (display->cursors);
g_slist_free (display->pixmaps);
g_slist_free (display->pixbufs);
}
g_free (display);

View File

@ -132,7 +132,7 @@ struct _GtkTextLineDisplay
{
PangoLayout *layout;
GSList *cursors;
GSList *pixmaps;
GSList *pixbufs;
GtkTextDirection direction;
@ -146,7 +146,7 @@ struct _GtkTextLineDisplay
gint bottom_margin;
gboolean size_only;
GtkTextLine *line;
GtkTextLine *line;
};
extern PangoAttrType gtk_text_attr_appearance_type;

View File

@ -25,14 +25,14 @@ gtk_text_mark_is_visible(GtkTextMark *mark)
return seg->body.mark.visible;
}
char *
const char *
gtk_text_mark_get_name (GtkTextMark *mark)
{
GtkTextLineSegment *seg;
seg = (GtkTextLineSegment*)mark;
return g_strdup (seg->body.mark.name);
return seg->body.mark.name;
}

View File

@ -9,17 +9,15 @@ extern "C" {
typedef struct _GtkTextMark GtkTextMark;
void gtk_text_mark_set_visible (GtkTextMark *mark,
gboolean setting);
void gtk_text_mark_set_visible (GtkTextMark *mark,
gboolean setting);
gboolean gtk_text_mark_is_visible (GtkTextMark *mark);
/* FIXME gconst */
const char * gtk_text_mark_get_name (GtkTextMark *mark);
GtkTextMark *gtk_text_mark_ref (GtkTextMark *mark);
void gtk_text_mark_unref (GtkTextMark *mark);
gboolean gtk_text_mark_deleted (GtkTextMark *mark);
gboolean gtk_text_mark_is_visible (GtkTextMark *mark);
/* Temporarily commented out until memory management behavior is figured out */
/* char * gtk_text_mark_get_name (GtkTextMark *mark); */
GtkTextMark *gtk_text_mark_ref (GtkTextMark *mark);
void gtk_text_mark_unref (GtkTextMark *mark);
gboolean gtk_text_mark_deleted (GtkTextMark *mark);
#ifdef __cplusplus
}

View File

@ -102,7 +102,7 @@ struct _GtkTextLineSegment {
* hold as many characters as needed.*/
GtkTextToggleBody toggle; /* Information about tag toggle. */
GtkTextMarkBody mark; /* Information about mark. */
GtkTextPixmap pixmap; /* Child pixmap */
GtkTextPixbuf pixbuf; /* Child pixbuf */
#if 0
GtkTextChild child; /* child widget */
#endif

View File

@ -945,43 +945,47 @@ delta_priority_foreach(GtkTextTag *tag, gpointer user_data)
gint
gtk_text_tag_get_priority (GtkTextTag *tag)
{
g_return_val_if_fail(GTK_IS_TEXT_TAG(tag), 0);
g_return_val_if_fail (GTK_IS_TEXT_TAG(tag), 0);
return tag->priority;
}
void
gtk_text_tag_set_priority(GtkTextTag *tag,
gint priority)
gtk_text_tag_set_priority (GtkTextTag *tag,
gint priority)
{
DeltaData dd;
g_return_if_fail(GTK_IS_TEXT_TAG(tag));
g_return_if_fail(tag->table != NULL);
g_return_if_fail(priority >= 0);
g_return_if_fail(priority < gtk_text_tag_table_size(tag->table));
g_return_if_fail (GTK_IS_TEXT_TAG (tag));
g_return_if_fail (tag->table != NULL);
g_return_if_fail (priority >= 0);
g_return_if_fail (priority < gtk_text_tag_table_size (tag->table));
if (priority == tag->priority)
return;
if (priority < tag->priority) {
dd.low = priority;
dd.high = tag->priority - 1;
dd.delta = 1;
} else {
dd.low = tag->priority + 1;
dd.high = priority;
dd.delta = -1;
}
if (priority < tag->priority)
{
dd.low = priority;
dd.high = tag->priority - 1;
dd.delta = 1;
}
else
{
dd.low = tag->priority + 1;
dd.high = priority;
dd.delta = -1;
}
gtk_text_tag_table_foreach(tag->table, delta_priority_foreach,
&dd);
gtk_text_tag_table_foreach (tag->table,
delta_priority_foreach,
&dd);
tag->priority = priority;
}
gint
gtk_text_tag_event(GtkTextTag *tag,
gtk_text_tag_event (GtkTextTag *tag,
GtkObject *event_object,
GdkEvent *event,
const GtkTextIter *iter)
@ -992,12 +996,12 @@ gtk_text_tag_event(GtkTextTag *tag,
g_return_val_if_fail(GTK_IS_OBJECT(event_object), FALSE);
g_return_val_if_fail(event != NULL, FALSE);
gtk_signal_emit(GTK_OBJECT(tag),
signals[EVENT],
event_object,
event,
iter,
&retval);
gtk_signal_emit (GTK_OBJECT(tag),
signals[EVENT],
event_object,
event,
iter,
&retval);
return retval;
}

View File

@ -31,7 +31,7 @@ extern GtkTextLineSegmentClass gtk_text_left_mark_type;
extern GtkTextLineSegmentClass gtk_text_right_mark_type;
/* In gtktextchild.c */
extern GtkTextLineSegmentClass gtk_text_pixmap_type;
extern GtkTextLineSegmentClass gtk_text_pixbuf_type;
extern GtkTextLineSegmentClass gtk_text_view_child_type;
/*

View File

@ -63,6 +63,7 @@
#include <string.h>
#define FOCUS_EDGE_WIDTH 25
#define DRAG_THRESHOLD 8
#define SCREEN_WIDTH(widget) text_window_get_width (GTK_TEXT_VIEW (widget)->text_window)
#define SCREEN_HEIGHT(widget) text_window_get_height (GTK_TEXT_VIEW (widget)->text_window)
@ -202,12 +203,12 @@ static void gtk_text_view_ensure_layout (GtkTextView *text_vi
static void gtk_text_view_destroy_layout (GtkTextView *text_view);
static void gtk_text_view_start_selection_drag (GtkTextView *text_view,
const GtkTextIter *iter,
GdkEventButton *event);
GdkEventButton *event);
static gboolean gtk_text_view_end_selection_drag (GtkTextView *text_view,
GdkEventButton *event);
static void gtk_text_view_start_selection_dnd (GtkTextView *text_view,
const GtkTextIter *iter,
GdkEventButton *event);
GdkEventMotion *event);
static void gtk_text_view_start_cursor_blink (GtkTextView *text_view);
static void gtk_text_view_stop_cursor_blink (GtkTextView *text_view);
@ -219,7 +220,7 @@ static void gtk_text_view_commit_handler (GtkIMContext *context,
static void gtk_text_view_mark_set_handler (GtkTextBuffer *buffer,
const GtkTextIter *location,
const char *mark_name,
GtkTextMark *mark,
gpointer data);
static void gtk_text_view_get_virtual_cursor_pos (GtkTextView *text_view,
gint *x,
@ -664,6 +665,9 @@ gtk_text_view_init (GtkTextView *text_view)
text_view->text_window = text_window_new (GTK_TEXT_WINDOW_TEXT,
widget, 200, 200);
text_view->drag_start_x = -1;
text_view->drag_start_y = -1;
}
GtkWidget*
@ -730,7 +734,7 @@ gtk_text_view_set_buffer (GtkTextView *text_view,
gtk_text_view_mark_set_handler, text_view);
}
if (GTK_WIDGET_VISIBLE (text_view))
if (GTK_WIDGET_VISIBLE (text_view))
gtk_widget_queue_draw (GTK_WIDGET (text_view));
}
@ -768,6 +772,35 @@ gtk_text_view_get_iter_location (GtkTextView *text_view,
gtk_text_layout_get_iter_location (text_view->layout, iter, location);
}
void
gtk_text_view_get_line_yrange (GtkTextView *text_view,
const GtkTextIter *iter,
gint *y,
gint *height)
{
g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
g_return_if_fail (gtk_text_iter_get_buffer (iter) == text_view->buffer);
gtk_text_layout_get_line_yrange (text_view->layout,
iter,
y,
height);
}
void
gtk_text_view_get_line_at_y (GtkTextView *text_view,
GtkTextIter *target_iter,
gint y,
gint *line_top)
{
g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
gtk_text_layout_get_line_at_y (text_view->layout,
target_iter,
y,
line_top);
}
static void
set_adjustment_clamped (GtkAdjustment *adj, gfloat val)
{
@ -1842,7 +1875,8 @@ gtk_text_view_button_press_event (GtkWidget *widget, GdkEventButton *event)
if (event->button == 1)
{
/* If we're in the selection, start a drag copy/move of the
selection; otherwise, start creating a new selection. */
* selection; otherwise, start creating a new selection.
*/
GtkTextIter iter;
GtkTextIter start, end;
@ -1855,7 +1889,8 @@ gtk_text_view_button_press_event (GtkWidget *widget, GdkEventButton *event)
&start, &end) &&
gtk_text_iter_in_region (&iter, &start, &end))
{
gtk_text_view_start_selection_dnd (text_view, &iter, event);
text_view->drag_start_x = event->x;
text_view->drag_start_y = event->y;
}
else
{
@ -1902,8 +1937,22 @@ gtk_text_view_button_release_event (GtkWidget *widget, GdkEventButton *event)
if (event->button == 1)
{
gtk_text_view_end_selection_drag (GTK_TEXT_VIEW (widget), event);
return TRUE;
if (text_view->drag_start_x >= 0)
{
text_view->drag_start_x = -1;
text_view->drag_start_y = -1;
}
if (gtk_text_view_end_selection_drag (GTK_TEXT_VIEW (widget), event))
return TRUE;
else
{
/* Unselect everything; probably we were dragging, or clicked
* outside the text.
*/
gtk_text_view_unselect (text_view);
return FALSE;
}
}
return FALSE;
@ -1950,6 +1999,41 @@ gtk_text_view_focus_out_event (GtkWidget *widget, GdkEventFocus *event)
static gint
gtk_text_view_motion_event (GtkWidget *widget, GdkEventMotion *event)
{
GtkTextView *text_view = GTK_TEXT_VIEW (widget);
if (event->window == text_view->text_window->bin_window &&
text_view->drag_start_x >= 0)
{
gint x, y;
gint dx, dy;
gdk_window_get_pointer (text_view->text_window->bin_window,
&x, &y, NULL);
dx = text_view->drag_start_x - x;
dy = text_view->drag_start_y - y;
if (ABS (dx) > DRAG_THRESHOLD ||
ABS (dy) > DRAG_THRESHOLD)
{
GtkTextIter iter;
gint buffer_x, buffer_y;
gtk_text_view_window_to_buffer_coords (text_view,
GTK_TEXT_WINDOW_TEXT,
text_view->drag_start_x,
text_view->drag_start_y,
&buffer_x,
&buffer_y);
gtk_text_layout_get_iter_at_pixel (text_view->layout,
&iter,
buffer_x, buffer_y);
gtk_text_view_start_selection_dnd (text_view, &iter, event);
return TRUE;
}
}
return FALSE;
}
@ -2645,9 +2729,9 @@ selection_motion_event_handler (GtkTextView *text_view, GdkEventMotion *event, g
}
static void
gtk_text_view_start_selection_drag (GtkTextView *text_view,
gtk_text_view_start_selection_drag (GtkTextView *text_view,
const GtkTextIter *iter,
GdkEventButton *event)
GdkEventButton *button)
{
GtkTextIter newplace;
@ -2876,11 +2960,14 @@ gtk_text_view_destroy_layout (GtkTextView *text_view)
static void
gtk_text_view_start_selection_dnd (GtkTextView *text_view,
const GtkTextIter *iter,
GdkEventButton *event)
const GtkTextIter *iter,
GdkEventMotion *event)
{
GdkDragContext *context;
GtkTargetList *target_list;
text_view->drag_start_x = -1;
text_view->drag_start_y = -1;
target_list = gtk_target_list_new (target_table, G_N_ELEMENTS (target_table));
@ -2953,6 +3040,10 @@ static void
gtk_text_view_drag_data_delete (GtkWidget *widget,
GdkDragContext *context)
{
GtkTextView *text_view;
text_view = GTK_TEXT_VIEW (widget);
gtk_text_buffer_delete_selection (GTK_TEXT_VIEW (widget)->buffer,
TRUE, GTK_TEXT_VIEW (widget)->editable);
}
@ -3277,12 +3368,12 @@ gtk_text_view_commit_handler (GtkIMContext *context,
static void
gtk_text_view_mark_set_handler (GtkTextBuffer *buffer,
const GtkTextIter *location,
const char *mark_name,
GtkTextMark *mark,
gpointer data)
{
GtkTextView *text_view = GTK_TEXT_VIEW (data);
if (!strcmp (mark_name, "insert"))
if (mark == gtk_text_buffer_get_insert (buffer))
{
text_view->virtual_cursor_x = -1;
text_view->virtual_cursor_y = -1;
@ -3918,45 +4009,64 @@ set_window_height (GtkTextView *text_view,
}
void
gtk_text_view_set_left_window_width (GtkTextView *text_view,
gint width)
gtk_text_view_set_border_window_size (GtkTextView *text_view,
GtkTextWindowType type,
gint size)
{
g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
g_return_if_fail (width >= 0);
set_window_width (text_view, width, GTK_TEXT_WINDOW_LEFT,
&text_view->left_window);
g_return_if_fail (size >= 0);
g_return_if_fail (type != GTK_TEXT_WINDOW_WIDGET);
g_return_if_fail (type != GTK_TEXT_WINDOW_TEXT);
switch (type)
{
case GTK_TEXT_WINDOW_LEFT:
set_window_width (text_view, size, GTK_TEXT_WINDOW_LEFT,
&text_view->left_window);
break;
case GTK_TEXT_WINDOW_RIGHT:
set_window_width (text_view, size, GTK_TEXT_WINDOW_RIGHT,
&text_view->right_window);
break;
case GTK_TEXT_WINDOW_TOP:
set_window_height (text_view, size, GTK_TEXT_WINDOW_TOP,
&text_view->top_window);
break;
case GTK_TEXT_WINDOW_BOTTOM:
set_window_height (text_view, size, GTK_TEXT_WINDOW_BOTTOM,
&text_view->bottom_window);
break;
default:
g_warning ("Unknown GtkTextWindowType in %s", G_STRLOC);
break;
}
}
void
gtk_text_view_set_right_window_width (GtkTextView *text_view,
gint width)
gtk_text_view_set_text_window_size (GtkTextView *text_view,
gint width,
gint height)
{
GtkTextWindow *win;
g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
g_return_if_fail (width >= 0);
g_return_if_fail (width > 0);
g_return_if_fail (height > 0);
set_window_width (text_view, width, GTK_TEXT_WINDOW_RIGHT,
&text_view->right_window);
win = text_view->text_window;
if (win->requisition.width == width &&
win->requisition.height == height)
return;
win->requisition.width = width;
win->requisition.height = height;
gtk_widget_queue_resize (GTK_WIDGET (text_view));
}
void
gtk_text_view_set_top_window_height (GtkTextView *text_view,
gint height)
{
g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
g_return_if_fail (height >= 0);
set_window_height (text_view, height, GTK_TEXT_WINDOW_TOP,
&text_view->top_window);
}
void
gtk_text_view_set_bottom_window_height (GtkTextView *text_view,
gint height)
{
g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
g_return_if_fail (height >= 0);
set_window_height (text_view, height, GTK_TEXT_WINDOW_BOTTOM,
&text_view->bottom_window);
}

View File

@ -86,6 +86,9 @@ struct _GtkTextView {
guint incremental_validate_idle; /* Idle to revalidate offscreen portions, runs after redraw */
GtkIMContext *im_context;
gint drag_start_x;
gint drag_start_y;
};
struct _GtkTextViewClass {
@ -145,7 +148,15 @@ void gtk_text_view_get_iter_at_location (GtkTextView *text_view,
GtkTextIter *iter,
gint x,
gint y);
void gtk_text_view_get_line_yrange (GtkTextView *text_view,
const GtkTextIter *iter,
gint *y,
gint *height);
void gtk_text_view_get_line_at_y (GtkTextView *text_view,
GtkTextIter *target_iter,
gint y,
gint *line_top);
void gtk_text_view_buffer_to_window_coords (GtkTextView *text_view,
GtkTextWindowType win,
@ -165,18 +176,13 @@ GdkWindow* gtk_text_view_get_window (GtkTextView *text_view,
GtkTextWindowType gtk_text_view_get_window_type (GtkTextView *text_view,
GdkWindow *window);
void gtk_text_view_set_left_window_width (GtkTextView *text_view,
gint width);
void gtk_text_view_set_right_window_width (GtkTextView *text_view,
gint width);
void gtk_text_view_set_top_window_height (GtkTextView *text_view,
gint height);
void gtk_text_view_set_bottom_window_height (GtkTextView *text_view,
gint height);
void gtk_text_view_set_border_window_size (GtkTextView *text_view,
GtkTextWindowType type,
gint size);
void gtk_text_view_set_text_window_size (GtkTextView *text_view,
gint width,
gint height);
void gtk_text_view_set_text_window_size (GtkTextView *text_view,
gint width,
gint height);
#ifdef __cplusplus
}

View File

@ -418,8 +418,7 @@ fill_example_buffer (GtkTextBuffer *buffer)
GtkTextTag *tag;
GdkColor color;
GdkColor color2;
GdkPixmap *pixmap;
GdkBitmap *mask;
GdkPixbuf *pixbuf;
int i;
char *str;
@ -500,13 +499,10 @@ fill_example_buffer (GtkTextBuffer *buffer)
"left_margin", 20,
"right_margin", 20,
NULL);
pixmap = gdk_pixmap_colormap_create_from_xpm_d (NULL,
gtk_widget_get_default_colormap (),
&mask,
NULL, book_closed_xpm);
g_assert (pixmap != NULL);
pixbuf = gdk_pixbuf_new_from_xpm_data (book_closed_xpm);
i = 0;
while (i < 100)
@ -515,7 +511,7 @@ fill_example_buffer (GtkTextBuffer *buffer)
gtk_text_buffer_get_iter_at_offset (buffer, &iter, 0);
gtk_text_buffer_insert_pixmap (buffer, &iter, pixmap, mask);
gtk_text_buffer_insert_pixbuf (buffer, &iter, pixbuf);
str = g_strdup_printf ("%d Hello World! blah blah blah blah blah blah blah blah blah blah blah blah\nwoo woo woo woo woo woo woo woo woo woo woo woo woo woo woo\n",
i);
@ -582,9 +578,7 @@ fill_example_buffer (GtkTextBuffer *buffer)
++i;
}
gdk_pixmap_unref (pixmap);
if (mask)
gdk_bitmap_unref (mask);
g_object_unref (G_OBJECT (pixbuf));
printf ("%d lines %d chars\n",
gtk_text_buffer_get_line_count (buffer),
@ -1408,29 +1402,170 @@ view_set_title (View *view)
g_free (title);
}
static void
cursor_set_callback (GtkTextBuffer *buffer,
const GtkTextIter *location,
GtkTextMark *mark,
gpointer user_data)
{
GtkTextView *text_view;
/* Redraw tab windows if the cursor moves
* on the mapped widget (windows may not exist before realization...
*/
text_view = GTK_TEXT_VIEW (user_data);
if (GTK_WIDGET_MAPPED (text_view) &&
mark == gtk_text_buffer_get_insert (buffer))
{
GdkWindow *tab_window;
tab_window = gtk_text_view_get_window (text_view,
GTK_TEXT_WINDOW_TOP);
gdk_window_invalidate_rect (tab_window, NULL, FALSE);
tab_window = gtk_text_view_get_window (text_view,
GTK_TEXT_WINDOW_BOTTOM);
gdk_window_invalidate_rect (tab_window, NULL, FALSE);
}
}
static gint
tab_stops_expose (GtkWidget *widget,
GdkEventExpose *event,
gpointer user_data)
{
gint first_x;
gint last_x;
gint i;
GdkWindow *top_win;
GdkWindow *bottom_win;
GtkTextView *text_view;
GtkTextWindowType type;
GdkDrawable *target;
gint *positions = NULL;
gint size;
GtkTextAttributes *attrs;
GtkTextIter insert;
GtkTextBuffer *buffer;
gboolean in_pixels;
text_view = GTK_TEXT_VIEW (widget);
/* See if this expose is on the tab stop window */
top_win = gtk_text_view_get_window (text_view,
GTK_TEXT_WINDOW_TOP);
bottom_win = gtk_text_view_get_window (text_view,
GTK_TEXT_WINDOW_BOTTOM);
if (event->window == top_win)
{
type = GTK_TEXT_WINDOW_TOP;
target = top_win;
}
else if (event->window == bottom_win)
{
type = GTK_TEXT_WINDOW_BOTTOM;
target = bottom_win;
}
else
return FALSE;
first_x = event->area.x;
last_x = first_x + event->area.width;
gtk_text_view_window_to_buffer_coords (text_view,
type,
first_x,
0,
&first_x,
NULL);
gtk_text_view_window_to_buffer_coords (text_view,
type,
last_x,
0,
&last_x,
NULL);
buffer = gtk_text_view_get_buffer (text_view);
gtk_text_buffer_get_iter_at_mark (buffer,
&insert,
gtk_text_buffer_get_mark (buffer,
"insert"));
attrs = gtk_text_attributes_new ();
gtk_text_iter_get_attributes (&insert, attrs);
if (attrs->tabs)
{
size = pango_tab_array_get_size (attrs->tabs);
pango_tab_array_get_tabs (attrs->tabs,
NULL,
&positions);
in_pixels = pango_tab_array_get_positions_in_pixels (attrs->tabs);
}
else
{
size = 0;
in_pixels = FALSE;
}
gtk_text_attributes_unref (attrs);
i = 0;
while (i < size)
{
gint pos;
if (!in_pixels)
positions[i] = PANGO_PIXELS (positions[i]);
gtk_text_view_buffer_to_window_coords (text_view,
type,
positions[i],
0,
&pos,
NULL);
gdk_draw_line (target,
widget->style->fg_gc [widget->state],
pos, 0,
pos, 15);
++i;
}
g_free (positions);
return TRUE;
}
static void
get_lines (GtkTextView *text_view,
gint first_y,
gint last_y,
gint **buffer_coords,
gint **numbers,
GArray *buffer_coords,
GArray *numbers,
gint *countp)
{
GtkTextIter iter;
gint count;
gint size;
if (buffer_coords)
*buffer_coords = NULL;
gint size;
if (numbers)
*numbers = NULL;
g_array_set_size (buffer_coords, 0);
g_array_set_size (numbers, 0);
/* Get iter at first y */
gtk_text_view_get_iter_at_location (text_view, &iter, 0, first_y);
/* Move back to start of its paragraph */
gtk_text_iter_set_line_offset (&iter, 0);
gtk_text_view_get_line_at_y (text_view, &iter, first_y, NULL);
/* For each iter, get its location and add it to the arrays.
* Stop when we pass last_y
@ -1440,34 +1575,20 @@ get_lines (GtkTextView *text_view,
while (!gtk_text_iter_is_last (&iter))
{
GdkRectangle loc;
gint y, height;
gint line_num;
gtk_text_view_get_line_yrange (text_view, &iter, &y, &height);
gtk_text_view_get_iter_location (text_view, &iter, &loc);
if (loc.y >= last_y)
break;
if (count >= size)
{
size = 2 * size + 2; /* + 2 handles size == 0 case */
if (buffer_coords)
*buffer_coords = g_realloc (*buffer_coords,
size * sizeof (gint));
if (numbers)
*numbers = g_realloc (*numbers,
size * sizeof (gint));
}
if (buffer_coords)
(*buffer_coords)[count] = loc.y;
if (numbers)
(*numbers)[count] = gtk_text_iter_get_line (&iter);
g_array_append_val (buffer_coords, y);
line_num = gtk_text_iter_get_line (&iter);
g_array_append_val (numbers, line_num);
++count;
if ((y + height) >= last_y)
break;
gtk_text_iter_forward_line (&iter);
}
@ -1480,42 +1601,67 @@ line_numbers_expose (GtkWidget *widget,
gpointer user_data)
{
gint count;
gint *numbers = NULL;
gint *pixels = NULL;
GArray *numbers;
GArray *pixels;
gint first_y;
gint last_y;
gint i;
GdkWindow *left_win;
GdkWindow *right_win;
PangoLayout *layout;
GtkTextView *text_view;
GtkTextWindowType type;
GdkDrawable *target;
text_view = GTK_TEXT_VIEW (widget);
/* See if this expose is on the line numbers window */
left_win = gtk_text_view_get_window (text_view,
GTK_TEXT_WINDOW_LEFT);
if (event->window != left_win)
right_win = gtk_text_view_get_window (text_view,
GTK_TEXT_WINDOW_RIGHT);
if (event->window == left_win)
{
type = GTK_TEXT_WINDOW_LEFT;
target = left_win;
}
else if (event->window == right_win)
{
type = GTK_TEXT_WINDOW_RIGHT;
target = right_win;
}
else
return FALSE;
first_y = event->area.y;
last_y = first_y + event->area.height;
gtk_text_view_window_to_buffer_coords (text_view,
GTK_TEXT_WINDOW_LEFT,
type,
0,
first_y,
NULL,
&first_y);
gtk_text_view_window_to_buffer_coords (text_view,
type,
0,
last_y,
&first_y,
NULL,
&last_y);
numbers = g_array_new (FALSE, FALSE, sizeof (gint));
pixels = g_array_new (FALSE, FALSE, sizeof (gint));
get_lines (text_view,
first_y,
last_y,
&pixels,
&numbers,
pixels,
numbers,
&count);
/* Draw fully internationalized numbers! */
layout = gtk_widget_create_pango_layout (widget, "");
@ -1527,17 +1673,18 @@ line_numbers_expose (GtkWidget *widget,
gchar *str;
gtk_text_view_buffer_to_window_coords (text_view,
GTK_TEXT_WINDOW_LEFT,
type,
0,
pixels[i],
g_array_index (pixels, gint, i),
NULL,
&pos);
str = g_strdup_printf ("%d", numbers[i]);
str = g_strdup_printf ("%d", g_array_index (numbers, gint, i));
pango_layout_set_text (layout, str, -1);
gdk_draw_layout (left_win,
gdk_draw_layout (target,
widget->style->fg_gc [widget->state],
/* 2 is just a random padding */
2, pos + 2,
@ -1548,8 +1695,8 @@ line_numbers_expose (GtkWidget *widget,
++i;
}
g_free (pixels);
g_free (numbers);
g_array_free (pixels, TRUE);
g_array_free (numbers, TRUE);
g_object_unref (G_OBJECT (layout));
@ -1601,22 +1748,36 @@ create_view (Buffer *buffer)
GTK_WRAPMODE_WORD);
/* Set sizes on these windows, just for debugging */
/* Draw tab stops in the top and bottom windows. */
gtk_text_view_set_right_window_width (GTK_TEXT_VIEW (view->text_view),
30);
gtk_text_view_set_border_window_size (GTK_TEXT_VIEW (view->text_view),
GTK_TEXT_WINDOW_TOP,
15);
gtk_text_view_set_border_window_size (GTK_TEXT_VIEW (view->text_view),
GTK_TEXT_WINDOW_BOTTOM,
15);
gtk_signal_connect (GTK_OBJECT (view->text_view),
"expose_event",
GTK_SIGNAL_FUNC (tab_stops_expose),
NULL);
gtk_signal_connect (GTK_OBJECT (view->buffer->buffer),
"mark_set",
GTK_SIGNAL_FUNC (cursor_set_callback),
view->text_view);
gtk_text_view_set_top_window_height (GTK_TEXT_VIEW (view->text_view),
15);
gtk_text_view_set_bottom_window_height (GTK_TEXT_VIEW (view->text_view),
23);
/* Draw line numbers in the left window; we should really be
* more scientific about what width we set it to.
/* Draw line numbers in the side windows; we should really be
* more scientific about what width we set them to.
*/
gtk_text_view_set_left_window_width (GTK_TEXT_VIEW (view->text_view),
30);
gtk_text_view_set_border_window_size (GTK_TEXT_VIEW (view->text_view),
GTK_TEXT_WINDOW_RIGHT,
30);
gtk_text_view_set_border_window_size (GTK_TEXT_VIEW (view->text_view),
GTK_TEXT_WINDOW_LEFT,
30);
gtk_signal_connect (GTK_OBJECT (view->text_view),
"expose_event",
@ -1645,7 +1806,6 @@ main (int argc, char** argv)
int i;
gtk_init (&argc, &argv);
gdk_rgb_init (); /* FIXME remove this */
buffer = create_buffer ();
view = create_view (buffer);

View File

@ -260,8 +260,7 @@ fill_buffer (GtkTextBuffer *buffer)
GdkColor color, color2;
GtkTextIter iter;
GtkTextIter iter2;
GdkPixmap *pixmap;
GdkBitmap *mask;
GdkPixbuf *pixbuf;
int i;
tag = gtk_text_buffer_create_tag (buffer, "fg_blue");
@ -295,12 +294,9 @@ fill_buffer (GtkTextBuffer *buffer)
"font", "-*-courier-bold-r-*-*-10-*-*-*-*-*-*-*",
NULL);
pixmap = gdk_pixmap_colormap_create_from_xpm_d (NULL,
gtk_widget_get_default_colormap (),
&mask,
NULL, book_closed_xpm);
pixbuf = gdk_pixbuf_new_from_xpm_data (book_closed_xpm);
g_assert (pixmap != NULL);
g_assert (pixbuf != NULL);
i = 0;
while (i < 10)
@ -309,11 +305,11 @@ fill_buffer (GtkTextBuffer *buffer)
gtk_text_buffer_get_iter_at_offset (buffer, &iter, 0);
gtk_text_buffer_insert_pixmap (buffer, &iter, pixmap, mask);
gtk_text_buffer_insert_pixbuf (buffer, &iter, pixbuf);
gtk_text_buffer_get_iter_at_offset (buffer, &iter, 1);
gtk_text_buffer_insert_pixmap (buffer, &iter, pixmap, mask);
gtk_text_buffer_insert_pixbuf (buffer, &iter, pixbuf);
str = g_strdup_printf ("%d Hello World!\nwoo woo woo woo woo woo woo woo\n",
i);
@ -329,20 +325,20 @@ fill_buffer (GtkTextBuffer *buffer)
"Spanish (Español) ¡Hola! / French (Français) Bonjour, Salut / German (Deutsch Süd) Grüß Gott (testing Latin-1 chars encoded in UTF8)\nThai (we can't display this, just making sure we don't crash) (ภาษาไทย) สวัสดีครับ, สวัสดีค่ะ\n",
-1);
gtk_text_buffer_insert_pixmap (buffer, &iter, pixmap, mask);
gtk_text_buffer_insert_pixmap (buffer, &iter, pixmap, mask);
gtk_text_buffer_insert_pixbuf (buffer, &iter, pixbuf);
gtk_text_buffer_insert_pixbuf (buffer, &iter, pixbuf);
gtk_text_buffer_get_iter_at_offset (buffer, &iter, 4);
gtk_text_buffer_insert_pixmap (buffer, &iter, pixmap, mask);
gtk_text_buffer_insert_pixbuf (buffer, &iter, pixbuf);
gtk_text_buffer_get_iter_at_offset (buffer, &iter, 7);
gtk_text_buffer_insert_pixmap (buffer, &iter, pixmap, mask);
gtk_text_buffer_insert_pixbuf (buffer, &iter, pixbuf);
gtk_text_buffer_get_iter_at_offset (buffer, &iter, 8);
gtk_text_buffer_insert_pixmap (buffer, &iter, pixmap, mask);
gtk_text_buffer_insert_pixbuf (buffer, &iter, pixbuf);
gtk_text_buffer_get_iter_at_line_offset (buffer, &iter, 0, 8);
iter2 = iter;
@ -387,9 +383,5 @@ fill_buffer (GtkTextBuffer *buffer)
++i;
}
gdk_pixmap_unref (pixmap);
if (mask)
gdk_bitmap_unref (mask);
gdk_pixbuf_unref (pixbuf);
}

View File

@ -418,8 +418,7 @@ fill_example_buffer (GtkTextBuffer *buffer)
GtkTextTag *tag;
GdkColor color;
GdkColor color2;
GdkPixmap *pixmap;
GdkBitmap *mask;
GdkPixbuf *pixbuf;
int i;
char *str;
@ -500,13 +499,10 @@ fill_example_buffer (GtkTextBuffer *buffer)
"left_margin", 20,
"right_margin", 20,
NULL);
pixmap = gdk_pixmap_colormap_create_from_xpm_d (NULL,
gtk_widget_get_default_colormap (),
&mask,
NULL, book_closed_xpm);
g_assert (pixmap != NULL);
pixbuf = gdk_pixbuf_new_from_xpm_data (book_closed_xpm);
i = 0;
while (i < 100)
@ -515,7 +511,7 @@ fill_example_buffer (GtkTextBuffer *buffer)
gtk_text_buffer_get_iter_at_offset (buffer, &iter, 0);
gtk_text_buffer_insert_pixmap (buffer, &iter, pixmap, mask);
gtk_text_buffer_insert_pixbuf (buffer, &iter, pixbuf);
str = g_strdup_printf ("%d Hello World! blah blah blah blah blah blah blah blah blah blah blah blah\nwoo woo woo woo woo woo woo woo woo woo woo woo woo woo woo\n",
i);
@ -582,9 +578,7 @@ fill_example_buffer (GtkTextBuffer *buffer)
++i;
}
gdk_pixmap_unref (pixmap);
if (mask)
gdk_bitmap_unref (mask);
g_object_unref (G_OBJECT (pixbuf));
printf ("%d lines %d chars\n",
gtk_text_buffer_get_line_count (buffer),
@ -1408,29 +1402,170 @@ view_set_title (View *view)
g_free (title);
}
static void
cursor_set_callback (GtkTextBuffer *buffer,
const GtkTextIter *location,
GtkTextMark *mark,
gpointer user_data)
{
GtkTextView *text_view;
/* Redraw tab windows if the cursor moves
* on the mapped widget (windows may not exist before realization...
*/
text_view = GTK_TEXT_VIEW (user_data);
if (GTK_WIDGET_MAPPED (text_view) &&
mark == gtk_text_buffer_get_insert (buffer))
{
GdkWindow *tab_window;
tab_window = gtk_text_view_get_window (text_view,
GTK_TEXT_WINDOW_TOP);
gdk_window_invalidate_rect (tab_window, NULL, FALSE);
tab_window = gtk_text_view_get_window (text_view,
GTK_TEXT_WINDOW_BOTTOM);
gdk_window_invalidate_rect (tab_window, NULL, FALSE);
}
}
static gint
tab_stops_expose (GtkWidget *widget,
GdkEventExpose *event,
gpointer user_data)
{
gint first_x;
gint last_x;
gint i;
GdkWindow *top_win;
GdkWindow *bottom_win;
GtkTextView *text_view;
GtkTextWindowType type;
GdkDrawable *target;
gint *positions = NULL;
gint size;
GtkTextAttributes *attrs;
GtkTextIter insert;
GtkTextBuffer *buffer;
gboolean in_pixels;
text_view = GTK_TEXT_VIEW (widget);
/* See if this expose is on the tab stop window */
top_win = gtk_text_view_get_window (text_view,
GTK_TEXT_WINDOW_TOP);
bottom_win = gtk_text_view_get_window (text_view,
GTK_TEXT_WINDOW_BOTTOM);
if (event->window == top_win)
{
type = GTK_TEXT_WINDOW_TOP;
target = top_win;
}
else if (event->window == bottom_win)
{
type = GTK_TEXT_WINDOW_BOTTOM;
target = bottom_win;
}
else
return FALSE;
first_x = event->area.x;
last_x = first_x + event->area.width;
gtk_text_view_window_to_buffer_coords (text_view,
type,
first_x,
0,
&first_x,
NULL);
gtk_text_view_window_to_buffer_coords (text_view,
type,
last_x,
0,
&last_x,
NULL);
buffer = gtk_text_view_get_buffer (text_view);
gtk_text_buffer_get_iter_at_mark (buffer,
&insert,
gtk_text_buffer_get_mark (buffer,
"insert"));
attrs = gtk_text_attributes_new ();
gtk_text_iter_get_attributes (&insert, attrs);
if (attrs->tabs)
{
size = pango_tab_array_get_size (attrs->tabs);
pango_tab_array_get_tabs (attrs->tabs,
NULL,
&positions);
in_pixels = pango_tab_array_get_positions_in_pixels (attrs->tabs);
}
else
{
size = 0;
in_pixels = FALSE;
}
gtk_text_attributes_unref (attrs);
i = 0;
while (i < size)
{
gint pos;
if (!in_pixels)
positions[i] = PANGO_PIXELS (positions[i]);
gtk_text_view_buffer_to_window_coords (text_view,
type,
positions[i],
0,
&pos,
NULL);
gdk_draw_line (target,
widget->style->fg_gc [widget->state],
pos, 0,
pos, 15);
++i;
}
g_free (positions);
return TRUE;
}
static void
get_lines (GtkTextView *text_view,
gint first_y,
gint last_y,
gint **buffer_coords,
gint **numbers,
GArray *buffer_coords,
GArray *numbers,
gint *countp)
{
GtkTextIter iter;
gint count;
gint size;
if (buffer_coords)
*buffer_coords = NULL;
gint size;
if (numbers)
*numbers = NULL;
g_array_set_size (buffer_coords, 0);
g_array_set_size (numbers, 0);
/* Get iter at first y */
gtk_text_view_get_iter_at_location (text_view, &iter, 0, first_y);
/* Move back to start of its paragraph */
gtk_text_iter_set_line_offset (&iter, 0);
gtk_text_view_get_line_at_y (text_view, &iter, first_y, NULL);
/* For each iter, get its location and add it to the arrays.
* Stop when we pass last_y
@ -1440,34 +1575,20 @@ get_lines (GtkTextView *text_view,
while (!gtk_text_iter_is_last (&iter))
{
GdkRectangle loc;
gint y, height;
gint line_num;
gtk_text_view_get_line_yrange (text_view, &iter, &y, &height);
gtk_text_view_get_iter_location (text_view, &iter, &loc);
if (loc.y >= last_y)
break;
if (count >= size)
{
size = 2 * size + 2; /* + 2 handles size == 0 case */
if (buffer_coords)
*buffer_coords = g_realloc (*buffer_coords,
size * sizeof (gint));
if (numbers)
*numbers = g_realloc (*numbers,
size * sizeof (gint));
}
if (buffer_coords)
(*buffer_coords)[count] = loc.y;
if (numbers)
(*numbers)[count] = gtk_text_iter_get_line (&iter);
g_array_append_val (buffer_coords, y);
line_num = gtk_text_iter_get_line (&iter);
g_array_append_val (numbers, line_num);
++count;
if ((y + height) >= last_y)
break;
gtk_text_iter_forward_line (&iter);
}
@ -1480,42 +1601,67 @@ line_numbers_expose (GtkWidget *widget,
gpointer user_data)
{
gint count;
gint *numbers = NULL;
gint *pixels = NULL;
GArray *numbers;
GArray *pixels;
gint first_y;
gint last_y;
gint i;
GdkWindow *left_win;
GdkWindow *right_win;
PangoLayout *layout;
GtkTextView *text_view;
GtkTextWindowType type;
GdkDrawable *target;
text_view = GTK_TEXT_VIEW (widget);
/* See if this expose is on the line numbers window */
left_win = gtk_text_view_get_window (text_view,
GTK_TEXT_WINDOW_LEFT);
if (event->window != left_win)
right_win = gtk_text_view_get_window (text_view,
GTK_TEXT_WINDOW_RIGHT);
if (event->window == left_win)
{
type = GTK_TEXT_WINDOW_LEFT;
target = left_win;
}
else if (event->window == right_win)
{
type = GTK_TEXT_WINDOW_RIGHT;
target = right_win;
}
else
return FALSE;
first_y = event->area.y;
last_y = first_y + event->area.height;
gtk_text_view_window_to_buffer_coords (text_view,
GTK_TEXT_WINDOW_LEFT,
type,
0,
first_y,
NULL,
&first_y);
gtk_text_view_window_to_buffer_coords (text_view,
type,
0,
last_y,
&first_y,
NULL,
&last_y);
numbers = g_array_new (FALSE, FALSE, sizeof (gint));
pixels = g_array_new (FALSE, FALSE, sizeof (gint));
get_lines (text_view,
first_y,
last_y,
&pixels,
&numbers,
pixels,
numbers,
&count);
/* Draw fully internationalized numbers! */
layout = gtk_widget_create_pango_layout (widget, "");
@ -1527,17 +1673,18 @@ line_numbers_expose (GtkWidget *widget,
gchar *str;
gtk_text_view_buffer_to_window_coords (text_view,
GTK_TEXT_WINDOW_LEFT,
type,
0,
pixels[i],
g_array_index (pixels, gint, i),
NULL,
&pos);
str = g_strdup_printf ("%d", numbers[i]);
str = g_strdup_printf ("%d", g_array_index (numbers, gint, i));
pango_layout_set_text (layout, str, -1);
gdk_draw_layout (left_win,
gdk_draw_layout (target,
widget->style->fg_gc [widget->state],
/* 2 is just a random padding */
2, pos + 2,
@ -1548,8 +1695,8 @@ line_numbers_expose (GtkWidget *widget,
++i;
}
g_free (pixels);
g_free (numbers);
g_array_free (pixels, TRUE);
g_array_free (numbers, TRUE);
g_object_unref (G_OBJECT (layout));
@ -1601,22 +1748,36 @@ create_view (Buffer *buffer)
GTK_WRAPMODE_WORD);
/* Set sizes on these windows, just for debugging */
/* Draw tab stops in the top and bottom windows. */
gtk_text_view_set_right_window_width (GTK_TEXT_VIEW (view->text_view),
30);
gtk_text_view_set_border_window_size (GTK_TEXT_VIEW (view->text_view),
GTK_TEXT_WINDOW_TOP,
15);
gtk_text_view_set_border_window_size (GTK_TEXT_VIEW (view->text_view),
GTK_TEXT_WINDOW_BOTTOM,
15);
gtk_signal_connect (GTK_OBJECT (view->text_view),
"expose_event",
GTK_SIGNAL_FUNC (tab_stops_expose),
NULL);
gtk_signal_connect (GTK_OBJECT (view->buffer->buffer),
"mark_set",
GTK_SIGNAL_FUNC (cursor_set_callback),
view->text_view);
gtk_text_view_set_top_window_height (GTK_TEXT_VIEW (view->text_view),
15);
gtk_text_view_set_bottom_window_height (GTK_TEXT_VIEW (view->text_view),
23);
/* Draw line numbers in the left window; we should really be
* more scientific about what width we set it to.
/* Draw line numbers in the side windows; we should really be
* more scientific about what width we set them to.
*/
gtk_text_view_set_left_window_width (GTK_TEXT_VIEW (view->text_view),
30);
gtk_text_view_set_border_window_size (GTK_TEXT_VIEW (view->text_view),
GTK_TEXT_WINDOW_RIGHT,
30);
gtk_text_view_set_border_window_size (GTK_TEXT_VIEW (view->text_view),
GTK_TEXT_WINDOW_LEFT,
30);
gtk_signal_connect (GTK_OBJECT (view->text_view),
"expose_event",
@ -1645,7 +1806,6 @@ main (int argc, char** argv)
int i;
gtk_init (&argc, &argv);
gdk_rgb_init (); /* FIXME remove this */
buffer = create_buffer ();
view = create_view (buffer);

View File

@ -260,8 +260,7 @@ fill_buffer (GtkTextBuffer *buffer)
GdkColor color, color2;
GtkTextIter iter;
GtkTextIter iter2;
GdkPixmap *pixmap;
GdkBitmap *mask;
GdkPixbuf *pixbuf;
int i;
tag = gtk_text_buffer_create_tag (buffer, "fg_blue");
@ -295,12 +294,9 @@ fill_buffer (GtkTextBuffer *buffer)
"font", "-*-courier-bold-r-*-*-10-*-*-*-*-*-*-*",
NULL);
pixmap = gdk_pixmap_colormap_create_from_xpm_d (NULL,
gtk_widget_get_default_colormap (),
&mask,
NULL, book_closed_xpm);
pixbuf = gdk_pixbuf_new_from_xpm_data (book_closed_xpm);
g_assert (pixmap != NULL);
g_assert (pixbuf != NULL);
i = 0;
while (i < 10)
@ -309,11 +305,11 @@ fill_buffer (GtkTextBuffer *buffer)
gtk_text_buffer_get_iter_at_offset (buffer, &iter, 0);
gtk_text_buffer_insert_pixmap (buffer, &iter, pixmap, mask);
gtk_text_buffer_insert_pixbuf (buffer, &iter, pixbuf);
gtk_text_buffer_get_iter_at_offset (buffer, &iter, 1);
gtk_text_buffer_insert_pixmap (buffer, &iter, pixmap, mask);
gtk_text_buffer_insert_pixbuf (buffer, &iter, pixbuf);
str = g_strdup_printf ("%d Hello World!\nwoo woo woo woo woo woo woo woo\n",
i);
@ -329,20 +325,20 @@ fill_buffer (GtkTextBuffer *buffer)
"Spanish (Español) ¡Hola! / French (Français) Bonjour, Salut / German (Deutsch Süd) Grüß Gott (testing Latin-1 chars encoded in UTF8)\nThai (we can't display this, just making sure we don't crash) (ภาษาไทย) สวัสดีครับ, สวัสดีค่ะ\n",
-1);
gtk_text_buffer_insert_pixmap (buffer, &iter, pixmap, mask);
gtk_text_buffer_insert_pixmap (buffer, &iter, pixmap, mask);
gtk_text_buffer_insert_pixbuf (buffer, &iter, pixbuf);
gtk_text_buffer_insert_pixbuf (buffer, &iter, pixbuf);
gtk_text_buffer_get_iter_at_offset (buffer, &iter, 4);
gtk_text_buffer_insert_pixmap (buffer, &iter, pixmap, mask);
gtk_text_buffer_insert_pixbuf (buffer, &iter, pixbuf);
gtk_text_buffer_get_iter_at_offset (buffer, &iter, 7);
gtk_text_buffer_insert_pixmap (buffer, &iter, pixmap, mask);
gtk_text_buffer_insert_pixbuf (buffer, &iter, pixbuf);
gtk_text_buffer_get_iter_at_offset (buffer, &iter, 8);
gtk_text_buffer_insert_pixmap (buffer, &iter, pixmap, mask);
gtk_text_buffer_insert_pixbuf (buffer, &iter, pixbuf);
gtk_text_buffer_get_iter_at_line_offset (buffer, &iter, 0, 8);
iter2 = iter;
@ -387,9 +383,5 @@ fill_buffer (GtkTextBuffer *buffer)
++i;
}
gdk_pixmap_unref (pixmap);
if (mask)
gdk_bitmap_unref (mask);
gdk_pixbuf_unref (pixbuf);
}