Commit 50cc709f authored by Owen Taylor's avatar Owen Taylor Committed by Owen Taylor

gtk/gtktext.c

Fri Feb 27 01:11:55 1998  Owen Taylor  <owt1@cornell.edu>

	* gtk/gtktext.c

	- gtk_text_delete and gtk_text_insert now update caches
	and refresh screen correctly if the text widget isn't frozen.

	- Fixed bug where text->first_line_start_index wasn't
	being updated correctly on insertion and deletion.

	- Added new public macro GTK_TEXT_INDEX (text, ind), and
	function gtk_text_get_chars(text, index, nchars);

Thu Feb 26 22:36:46 1998  Owen Taylor  <owt1@cornell.edu>

	* gtk/gtkhandlebox.c (gtk_handle_box_realize): Use MWM hints
	to undecorate window.

	* gtk/testgtk.c gtk/circles.xbm: new test for WM hints.
parent 473c1d4d
Fri Feb 27 01:11:55 1998 Owen Taylor <owt1@cornell.edu>
* gtk/gtktext.c
- gtk_text_delete and gtk_text_insert now update caches
and refresh screen correctly if the text widget isn't frozen.
- Fixed bug where text->first_line_start_index wasn't
being updated correctly on insertion and deletion.
- Added new public macro GTK_TEXT_INDEX (text, ind), and
function gtk_text_get_chars(text, index, nchars);
Thu Feb 26 22:36:46 1998 Owen Taylor <owt1@cornell.edu>
* gdk/gdkwindow.c gdktypes.c gdk.h:
new functions for setting WM hints
gdk_window_set_icon()
gdk_window_set_icon_name()
gdk_window_set_group()
gdk_window_set_decorations()
gdk_window_set_functions()
* gdk/MwmUtil.h: new uninstalled header file from lesstif
distribution, used for setting MWM hints.
* gdk/gdkdnd.c Makefile.am: renamed from gdk/gdk_dnd.c
* gtk/gtkhandlebox.c (gtk_handle_box_realize): Use MWM hints
to undecorate window.
* gtk/testgtk.c gtk/circles.xbm: new test for WM hints.
Wed Feb 25 22:56:42 1998 Tim Janik <timj@gimp.org>
* gtk/gtkspinbutton.h:
......
Fri Feb 27 01:11:55 1998 Owen Taylor <owt1@cornell.edu>
* gtk/gtktext.c
- gtk_text_delete and gtk_text_insert now update caches
and refresh screen correctly if the text widget isn't frozen.
- Fixed bug where text->first_line_start_index wasn't
being updated correctly on insertion and deletion.
- Added new public macro GTK_TEXT_INDEX (text, ind), and
function gtk_text_get_chars(text, index, nchars);
Thu Feb 26 22:36:46 1998 Owen Taylor <owt1@cornell.edu>
* gdk/gdkwindow.c gdktypes.c gdk.h:
new functions for setting WM hints
gdk_window_set_icon()
gdk_window_set_icon_name()
gdk_window_set_group()
gdk_window_set_decorations()
gdk_window_set_functions()
* gdk/MwmUtil.h: new uninstalled header file from lesstif
distribution, used for setting MWM hints.
* gdk/gdkdnd.c Makefile.am: renamed from gdk/gdk_dnd.c
* gtk/gtkhandlebox.c (gtk_handle_box_realize): Use MWM hints
to undecorate window.
* gtk/testgtk.c gtk/circles.xbm: new test for WM hints.
Wed Feb 25 22:56:42 1998 Tim Janik <timj@gimp.org>
* gtk/gtkspinbutton.h:
......
Fri Feb 27 01:11:55 1998 Owen Taylor <owt1@cornell.edu>
* gtk/gtktext.c
- gtk_text_delete and gtk_text_insert now update caches
and refresh screen correctly if the text widget isn't frozen.
- Fixed bug where text->first_line_start_index wasn't
being updated correctly on insertion and deletion.
- Added new public macro GTK_TEXT_INDEX (text, ind), and
function gtk_text_get_chars(text, index, nchars);
Thu Feb 26 22:36:46 1998 Owen Taylor <owt1@cornell.edu>
* gdk/gdkwindow.c gdktypes.c gdk.h:
new functions for setting WM hints
gdk_window_set_icon()
gdk_window_set_icon_name()
gdk_window_set_group()
gdk_window_set_decorations()
gdk_window_set_functions()
* gdk/MwmUtil.h: new uninstalled header file from lesstif
distribution, used for setting MWM hints.
* gdk/gdkdnd.c Makefile.am: renamed from gdk/gdk_dnd.c
* gtk/gtkhandlebox.c (gtk_handle_box_realize): Use MWM hints
to undecorate window.
* gtk/testgtk.c gtk/circles.xbm: new test for WM hints.
Wed Feb 25 22:56:42 1998 Tim Janik <timj@gimp.org>
* gtk/gtkspinbutton.h:
......
Fri Feb 27 01:11:55 1998 Owen Taylor <owt1@cornell.edu>
* gtk/gtktext.c
- gtk_text_delete and gtk_text_insert now update caches
and refresh screen correctly if the text widget isn't frozen.
- Fixed bug where text->first_line_start_index wasn't
being updated correctly on insertion and deletion.
- Added new public macro GTK_TEXT_INDEX (text, ind), and
function gtk_text_get_chars(text, index, nchars);
Thu Feb 26 22:36:46 1998 Owen Taylor <owt1@cornell.edu>
* gdk/gdkwindow.c gdktypes.c gdk.h:
new functions for setting WM hints
gdk_window_set_icon()
gdk_window_set_icon_name()
gdk_window_set_group()
gdk_window_set_decorations()
gdk_window_set_functions()
* gdk/MwmUtil.h: new uninstalled header file from lesstif
distribution, used for setting MWM hints.
* gdk/gdkdnd.c Makefile.am: renamed from gdk/gdk_dnd.c
* gtk/gtkhandlebox.c (gtk_handle_box_realize): Use MWM hints
to undecorate window.
* gtk/testgtk.c gtk/circles.xbm: new test for WM hints.
Wed Feb 25 22:56:42 1998 Tim Janik <timj@gimp.org>
* gtk/gtkspinbutton.h:
......
Fri Feb 27 01:11:55 1998 Owen Taylor <owt1@cornell.edu>
* gtk/gtktext.c
- gtk_text_delete and gtk_text_insert now update caches
and refresh screen correctly if the text widget isn't frozen.
- Fixed bug where text->first_line_start_index wasn't
being updated correctly on insertion and deletion.
- Added new public macro GTK_TEXT_INDEX (text, ind), and
function gtk_text_get_chars(text, index, nchars);
Thu Feb 26 22:36:46 1998 Owen Taylor <owt1@cornell.edu>
* gdk/gdkwindow.c gdktypes.c gdk.h:
new functions for setting WM hints
gdk_window_set_icon()
gdk_window_set_icon_name()
gdk_window_set_group()
gdk_window_set_decorations()
gdk_window_set_functions()
* gdk/MwmUtil.h: new uninstalled header file from lesstif
distribution, used for setting MWM hints.
* gdk/gdkdnd.c Makefile.am: renamed from gdk/gdk_dnd.c
* gtk/gtkhandlebox.c (gtk_handle_box_realize): Use MWM hints
to undecorate window.
* gtk/testgtk.c gtk/circles.xbm: new test for WM hints.
Wed Feb 25 22:56:42 1998 Tim Janik <timj@gimp.org>
* gtk/gtkspinbutton.h:
......
Fri Feb 27 01:11:55 1998 Owen Taylor <owt1@cornell.edu>
* gtk/gtktext.c
- gtk_text_delete and gtk_text_insert now update caches
and refresh screen correctly if the text widget isn't frozen.
- Fixed bug where text->first_line_start_index wasn't
being updated correctly on insertion and deletion.
- Added new public macro GTK_TEXT_INDEX (text, ind), and
function gtk_text_get_chars(text, index, nchars);
Thu Feb 26 22:36:46 1998 Owen Taylor <owt1@cornell.edu>
* gdk/gdkwindow.c gdktypes.c gdk.h:
new functions for setting WM hints
gdk_window_set_icon()
gdk_window_set_icon_name()
gdk_window_set_group()
gdk_window_set_decorations()
gdk_window_set_functions()
* gdk/MwmUtil.h: new uninstalled header file from lesstif
distribution, used for setting MWM hints.
* gdk/gdkdnd.c Makefile.am: renamed from gdk/gdk_dnd.c
* gtk/gtkhandlebox.c (gtk_handle_box_realize): Use MWM hints
to undecorate window.
* gtk/testgtk.c gtk/circles.xbm: new test for WM hints.
Wed Feb 25 22:56:42 1998 Tim Janik <timj@gimp.org>
* gtk/gtkspinbutton.h:
......
Fri Feb 27 01:11:55 1998 Owen Taylor <owt1@cornell.edu>
* gtk/gtktext.c
- gtk_text_delete and gtk_text_insert now update caches
and refresh screen correctly if the text widget isn't frozen.
- Fixed bug where text->first_line_start_index wasn't
being updated correctly on insertion and deletion.
- Added new public macro GTK_TEXT_INDEX (text, ind), and
function gtk_text_get_chars(text, index, nchars);
Thu Feb 26 22:36:46 1998 Owen Taylor <owt1@cornell.edu>
* gdk/gdkwindow.c gdktypes.c gdk.h:
new functions for setting WM hints
gdk_window_set_icon()
gdk_window_set_icon_name()
gdk_window_set_group()
gdk_window_set_decorations()
gdk_window_set_functions()
* gdk/MwmUtil.h: new uninstalled header file from lesstif
distribution, used for setting MWM hints.
* gdk/gdkdnd.c Makefile.am: renamed from gdk/gdk_dnd.c
* gtk/gtkhandlebox.c (gtk_handle_box_realize): Use MWM hints
to undecorate window.
* gtk/testgtk.c gtk/circles.xbm: new test for WM hints.
Wed Feb 25 22:56:42 1998 Tim Janik <timj@gimp.org>
* gtk/gtkspinbutton.h:
......
#define circles_width 64
#define circles_height 64
static unsigned char circles_bits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xff, 0x00, 0x00, 0x00,
0x00, 0x00, 0xfc, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff,
0xff, 0x1f, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00,
0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xf0, 0xff, 0xff,
0xff, 0xff, 0x01, 0x00, 0x00, 0xfc, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00,
0x00, 0xfe, 0xff, 0x01, 0xf0, 0xff, 0x0f, 0x00, 0x00, 0xff, 0x3f, 0x00,
0x80, 0xff, 0x1f, 0x00, 0x80, 0xff, 0x0f, 0x00, 0x00, 0xfe, 0x3f, 0x00,
0x80, 0xff, 0x03, 0x00, 0x00, 0xf8, 0x3f, 0x00, 0xc0, 0xff, 0x01, 0x00,
0x00, 0xf0, 0x7f, 0x00, 0xe0, 0x7f, 0x00, 0x00, 0x00, 0xc0, 0xff, 0x00,
0xf0, 0x3f, 0x00, 0x00, 0x00, 0x80, 0xff, 0x01, 0xf0, 0x1f, 0x00, 0x00,
0x00, 0x00, 0xff, 0x01, 0xf8, 0x1f, 0x00, 0x20, 0x00, 0x00, 0xff, 0x03,
0xf8, 0x0f, 0x00, 0xff, 0x07, 0x00, 0xfe, 0x03, 0xfc, 0x07, 0xc0, 0xff,
0x1f, 0x00, 0xfc, 0x07, 0xfc, 0x07, 0xf0, 0xff, 0x7f, 0x00, 0xfc, 0x07,
0xfc, 0x03, 0xf8, 0xff, 0xff, 0x00, 0xf8, 0x07, 0xfe, 0x03, 0xfc, 0xff,
0xff, 0x01, 0xf8, 0x0f, 0xfe, 0x01, 0xfe, 0x8f, 0xff, 0x03, 0xf0, 0x0f,
0xfe, 0x01, 0xfe, 0x01, 0xfc, 0x03, 0xf0, 0x0f, 0xff, 0x01, 0xff, 0x00,
0xf8, 0x07, 0xf0, 0x1f, 0xff, 0x00, 0x7f, 0x00, 0xf0, 0x07, 0xe0, 0x1f,
0xff, 0x80, 0x3f, 0x00, 0xe0, 0x0f, 0xe0, 0x1f, 0xff, 0x80, 0x1f, 0x00,
0xc0, 0x0f, 0xe0, 0x1f, 0xff, 0x80, 0x1f, 0x00, 0xc0, 0x0f, 0xe0, 0x1f,
0xff, 0x80, 0x1f, 0x00, 0xc0, 0x0f, 0xe0, 0x1f, 0xff, 0x80, 0x0f, 0x00,
0x80, 0x0f, 0xe0, 0x1f, 0xff, 0xc0, 0x0f, 0x00, 0x80, 0x1f, 0xe0, 0x1f,
0xff, 0x80, 0x0f, 0x00, 0x80, 0x0f, 0xe0, 0x1f, 0xff, 0x80, 0x1f, 0x00,
0xc0, 0x0f, 0xe0, 0x1f, 0xff, 0x80, 0x1f, 0x00, 0xc0, 0x0f, 0xe0, 0x1f,
0xff, 0x80, 0x1f, 0x00, 0xc0, 0x0f, 0xe0, 0x1f, 0xff, 0x81, 0x3f, 0x00,
0xe0, 0x0f, 0xf0, 0x1f, 0xfe, 0x01, 0x7f, 0x00, 0xf0, 0x07, 0xf0, 0x0f,
0xfe, 0x01, 0xff, 0x00, 0xf8, 0x07, 0xf0, 0x0f, 0xfe, 0x03, 0xfe, 0x01,
0xfc, 0x03, 0xf8, 0x0f, 0xfc, 0x03, 0xfe, 0x8f, 0xff, 0x03, 0xf8, 0x07,
0xfc, 0x07, 0xfc, 0xff, 0xff, 0x01, 0xfc, 0x07, 0xfc, 0x07, 0xf8, 0xff,
0xff, 0x00, 0xfc, 0x07, 0xf8, 0x0f, 0xf0, 0xff, 0x7f, 0x00, 0xfe, 0x03,
0xf8, 0x1f, 0xc0, 0xff, 0x1f, 0x00, 0xff, 0x03, 0xf0, 0x1f, 0x00, 0xff,
0x07, 0x00, 0xff, 0x01, 0xf0, 0x3f, 0x00, 0x20, 0x00, 0x80, 0xff, 0x01,
0xe0, 0x7f, 0x00, 0x00, 0x00, 0xc0, 0xff, 0x00, 0xc0, 0xff, 0x01, 0x00,
0x00, 0xf0, 0x7f, 0x00, 0x80, 0xff, 0x03, 0x00, 0x00, 0xf8, 0x3f, 0x00,
0x80, 0xff, 0x0f, 0x00, 0x00, 0xfe, 0x3f, 0x00, 0x00, 0xff, 0x3f, 0x00,
0x80, 0xff, 0x1f, 0x00, 0x00, 0xfe, 0xff, 0x01, 0xf0, 0xff, 0x0f, 0x00,
0x00, 0xfc, 0xff, 0xff, 0xff, 0xff, 0x07, 0x00, 0x00, 0xf0, 0xff, 0xff,
0xff, 0xff, 0x01, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00,
0x00, 0xc0, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff,
0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0xfc, 0xff, 0xff, 0x07, 0x00, 0x00,
0x00, 0x00, 0xe0, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
......@@ -206,18 +206,14 @@ gtk_handle_box_realize (GtkWidget *widget)
GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
/* FIXME: we need a property that would tell the window manager not
* to put decoration on this window. This is not part of the ICCCM,
* so we'll have to define our own (a la KWM) and hack some window
* managers to support it.
*/
hb->float_window = gtk_window_new (GTK_WINDOW_DIALOG);
gtk_window_set_policy (GTK_WINDOW (hb->float_window), FALSE, FALSE, TRUE);
gtk_container_border_width (GTK_CONTAINER (hb->float_window), 0);
gtk_signal_connect (GTK_OBJECT (hb->float_window), "delete_event",
(GtkSignalFunc) gtk_handle_box_delete_float,
hb);
gtk_widget_realize (hb->float_window);
gdk_window_set_decorations (hb->float_window->window, 0);
attributes.x = widget->allocation.x;
attributes.y = widget->allocation.y;
......
......@@ -58,8 +58,6 @@
#define MARK_CURRENT_FORE(mark) (&((TextProperty*)(mark)->property->data)->fore_color)
#define MARK_CURRENT_BACK(mark) (&((TextProperty*)(mark)->property->data)->back_color)
#define MARK_CURRENT_TEXT_FONT(m) (((TextProperty*)(m)->property->data)->font)
#define TEXT_INDEX(t, index) ((index) < (t)->gap_position ? (t)->text[index] : \
(t)->text[(index) + (t)->gap_size])
#define TEXT_LENGTH(t) ((t)->text_end - (t)->gap_size)
#define FONT_HEIGHT(f) ((f)->ascent + (f)->descent)
#define LINE_HEIGHT(l) ((l).font_ascent + (l).font_descent)
......@@ -212,6 +210,9 @@ static void find_line_containing_point (GtkText* text, guint point);
static TextProperty* new_text_property (GdkFont* font, GdkColor* fore, GdkColor* back, guint length);
/* Display */
static void compute_lines_pixels (GtkText* text, gint char_count,
guint *lines, guint *pixels);
static gint total_line_height (GtkText* text,
GList* line,
gint line_count);
......@@ -220,8 +221,11 @@ static LineParams find_line_params (GtkText* text,
const PrevTabCont *tab_cont,
PrevTabCont *next_cont);
static void recompute_geometry (GtkText* text);
static void insert_char_line_expose (GtkText* text, gchar key, guint old_pixels);
static void delete_char_line_expose (GtkText* text, gchar key, guint old_pixels);
static void insert_expose (GtkText* text, guint old_pixels, gint nchars, guint new_line_count);
static void delete_expose (GtkText* text,
gint nchars,
guint old_lines,
guint old_pixels);
static void clear_area (GtkText *text, GdkRectangle *area);
static void draw_line (GtkText* text,
gint pixel_height,
......@@ -258,7 +262,7 @@ static void move_cursor_page_ver (GtkText *text, int dir);
static void move_cursor_ver (GtkText *text, int count);
static void move_cursor_hor (GtkText *text, int count);
/* #define DEBUG_GTK_TEXT */
#define DEBUG_GTK_TEXT
#if defined(DEBUG_GTK_TEXT) && defined(__GNUC__)
/* Debugging utilities. */
......@@ -538,6 +542,11 @@ gtk_text_insert (GtkText *text,
const char *chars,
gint length)
{
gint i;
gint new_line_count = 1;
guint old_height = 0;
g_return_if_fail (text != NULL);
g_return_if_fail (GTK_IS_TEXT (text));
......@@ -557,6 +566,18 @@ gtk_text_insert (GtkText *text,
if (length == 0)
return;
if (!text->freeze && (text->line_start_cache != NULL))
{
find_line_containing_point (text, text->point.index);
old_height = total_line_height (text, text->current_line, 1);
for (i=0; i<length; i++)
if (chars[i] == '\n')
new_line_count++;
}
if (text->point.index < text->first_line_start_index)
text->first_line_start_index += length;
move_gap_to_point (text);
if (font == NULL)
......@@ -572,6 +593,9 @@ gtk_text_insert (GtkText *text,
text->gap_position += length;
advance_mark_n (&text->point, length);
if (!text->freeze && (text->line_start_cache != NULL))
insert_expose (text, old_height, length, new_line_count);
}
gint
......@@ -593,21 +617,78 @@ gint
gtk_text_forward_delete (GtkText *text,
guint nchars)
{
guint old_lines, old_height;
g_return_val_if_fail (text != NULL, 0);
g_return_val_if_fail (GTK_IS_TEXT (text), 0);
if (text->point.index + nchars > TEXT_LENGTH (text) || nchars <= 0)
return FALSE;
if (!text->freeze && (text->line_start_cache != NULL))
{
find_line_containing_point (text, text->point.index);
compute_lines_pixels (text, nchars, &old_lines, &old_height);
}
if (text->point.index < text->first_line_start_index)
text->first_line_start_index -= MIN(nchars,
text->first_line_start_index -
text->point.index);
move_gap_to_point (text);
text->gap_size += nchars;
delete_text_property (text, nchars);
if (!text->freeze && (text->line_start_cache != NULL))
delete_expose (text, nchars, old_lines, old_height);
return TRUE;
}
gchar *
gtk_text_get_chars (GtkText *text,
guint index,
guint nchars)
{
gchar *retval;
gchar *p;
guint n;
if (index+nchars > TEXT_LENGTH (text))
return NULL;
if (nchars < 0)
nchars = TEXT_LENGTH (text) - index;
retval = g_new (gchar, nchars+1);
p = retval;
if (index < text->gap_position)
{
n = MIN (text->gap_position - index, nchars);
memcpy (p, text->text + GTK_TEXT_INDEX(text, index), n);
p += n;
index += n;
nchars -= n;
}
if (index+nchars >= text->gap_position)
{
memcpy (p,
text->text + MAX (text->gap_position + text->gap_size,
index + text->gap_size),
nchars);
}
retval[nchars+1] = 0;
return retval;
}
static void
gtk_text_finalize (GtkObject *object)
{
......@@ -1117,47 +1198,23 @@ gtk_text_motion_notify (GtkWidget *widget,
static void
gtk_text_insert_1_at_point (GtkText* text, gchar key)
{
guint old_height= total_line_height (text, text->current_line, 1);
gtk_text_insert (text,
MARK_CURRENT_FONT (&text->point),
MARK_CURRENT_FORE (&text->point),
MARK_CURRENT_BACK (&text->point),
&key, 1);
insert_char_line_expose (text, key, old_height );
}
static void
gtk_text_backward_delete_1_at_point (GtkText* text)
{
guint old_height;
gchar key= TEXT_INDEX(text,text->cursor_mark.index-1);
if (1 > text->point.index )
return;
gtk_text_set_point (text, text->point.index - 1);
find_line_containing_point (text, text->cursor_mark.index-1);
old_height= total_line_height (text, text->current_line, 1 + (key == LINE_DELIM));
gtk_text_forward_delete (text, 1);
delete_char_line_expose (text, key, old_height);
gtk_text_backward_delete (text, 1);
}
static void
gtk_text_forward_delete_1_at_point (GtkText* text)
{
guint old_height;
gchar key= TEXT_INDEX(text,text->cursor_mark.index);
old_height= total_line_height (text, text->current_line, 1 + (key == LINE_DELIM));
gtk_text_forward_delete (text, 1);
delete_char_line_expose (text, key, old_height);
}
static gint
......@@ -1386,7 +1443,7 @@ find_this_line_start_mark (GtkText* text, guint point_position, const GtkPropert
mark = find_mark_near (text, point_position, near);
while (mark.index > 0 &&
TEXT_INDEX (text, mark.index - 1) != LINE_DELIM)
GTK_TEXT_INDEX (text, mark.index - 1) != LINE_DELIM)
decrement_mark (&mark);
return mark;
......@@ -1536,6 +1593,41 @@ fetch_lines_forward (GtkText* text, gint line_count)
line->next->prev = line;
}
/* Compute the number of lines, and vertical pixels for n characters
* starting from the point
*/
static void
compute_lines_pixels (GtkText* text, gint char_count,
guint *lines, guint *pixels)
{
GList *line = text->current_line;
*lines = 0;
*pixels = 0;
/* If char_count == 0, that means we're joining two lines in a
* deletion, so add in the values for the next line as well
*/
for (; line && char_count >= 0; line = line->next)
{
*pixels += LINE_HEIGHT(CACHE_DATA(line));
if (line == text->current_line)
char_count -= CACHE_DATA(line).end.index - text->point.index + 1;
else
char_count -= CACHE_DATA(line).end.index -CACHE_DATA(line).end.index + 1;
if (!text->line_wrap || !CACHE_DATA(line).wraps)
*lines += 1;
else
if (char_count < 0)
char_count = 0; /* force another loop */
if (!line->next)
fetch_lines_forward (text, 1);
}
}
static gint
total_line_height (GtkText* text, GList* line, gint line_count)
{
......@@ -1610,7 +1702,7 @@ swap_lines (GtkText* text, GList* old, GList* new, gint old_line_count)
}
static void
correct_cache_delete (GtkText* text, gint lines)
correct_cache_delete (GtkText* text, gint nchars, gint lines)
{
GList* cache = text->current_line;
gint i;
......@@ -1623,8 +1715,8 @@ correct_cache_delete (GtkText* text, gint lines)
GtkPropertyMark *start = &CACHE_DATA(cache).start;
GtkPropertyMark *end = &CACHE_DATA(cache).end;
start->index -= 1;
end->index -= 1;
start->index -= nchars;
end->index -= nchars;
if (start->property == text->point.property)
start->offset = start->index - (text->point.index - text->point.offset);
......@@ -1638,11 +1730,10 @@ correct_cache_delete (GtkText* text, gint lines)
}
static void
delete_char_line_expose (GtkText* text, gchar key, guint old_pixels)
delete_expose (GtkText* text, gint nchars, guint old_lines, guint old_pixels)
{
gint pixel_height;
guint new_pixels = 0;
gint old_line_count = 1 + (key == LINE_DELIM);
GdkRectangle rect;
GList* new_line = NULL;
gint width, height;
......@@ -1651,7 +1742,7 @@ delete_char_line_expose (GtkText* text, gchar key, guint old_pixels)
undraw_cursor (text, FALSE);
correct_cache_delete (text, old_line_count);
correct_cache_delete (text, nchars, old_lines);
pixel_height = pixel_height_of(text, text->current_line) -
LINE_HEIGHT(CACHE_DATA(text->current_line));
......@@ -1665,7 +1756,7 @@ delete_char_line_expose (GtkText* text, gchar key, guint old_pixels)
FetchLinesCount,
1);
swap_lines (text, text->current_line, new_line, old_line_count);
swap_lines (text, text->current_line, new_line, old_lines);
text->current_line = new_line;
......@@ -1711,30 +1802,31 @@ delete_char_line_expose (GtkText* text, gchar key, guint old_pixels)
TEXT_SHOW(text);
}
/* note, the point has already been moved forward */
static void
correct_cache_insert (GtkText* text)
correct_cache_insert (GtkText* text, gint nchars)
{
GList* cache = text->current_line;
GList* cache = text->current_line->next;
for (; cache; cache = cache->next)
{
GtkPropertyMark *start = &CACHE_DATA(cache).start;
GtkPropertyMark *end = &CACHE_DATA(cache).end;
if (start->index >= text->point.index)
if (start->index >= text->point.index - nchars)
{
if (start->property == text->point.property)
move_mark_n(start, 1);
move_mark_n(start, nchars);
else
start->index += 1;
start->index += nchars;
}
if (end->index >= text->point.index)
if (end->index >= text->point.index - nchars)
{
if (end->property == text->point.property)
move_mark_n(end, 1);
move_mark_n(end, nchars);
else
end->index += 1;
end->index += nchars;
}
/*TEXT_ASSERT_MARK(text, start, "start");*/
......@@ -1744,37 +1836,37 @@ correct_cache_insert (GtkText* text)
static void
insert_char_line_expose (GtkText* text, gchar key, guint old_pixels)
insert_expose (GtkText* text, guint old_pixels, gint nchars,
guint new_line_count)
{
gint pixel_height;
guint new_pixels = 0;
guint new_line_count = 1 + (key == LINE_DELIM);
GdkRectangle rect;
GList* new_line = NULL;
GList* new_lines = NULL;
gint width, height;
text->cursor_virtual_x = 0;
undraw_cursor (text, FALSE);
correct_cache_insert (text);
correct_cache_insert (text, nchars);
TEXT_SHOW_ADJ (text, text->vadj, "vadj");
pixel_height = pixel_height_of(text, text->current_line) -
LINE_HEIGHT(CACHE_DATA(text->current_line));
new_line = fetch_lines (text,
&CACHE_DATA(text->current_line).start,
&CACHE_DATA(text->current_line).tab_cont,
FetchLinesCount,
new_line_count);
new_lines = fetch_lines (text,
&CACHE_DATA(text->current_line).start,
&CACHE_DATA(text->current_line).tab_cont,
FetchLinesCount,
new_line_count);
swap_lines (text, text->current_line, new_line, 1);
swap_lines (text, text->current_line, new_lines, 1);
text->current_line = new_line;
text->current_line = new_lines;
new_pixels = total_line_height (text, new_line, new_line_count);
new_pixels = total_line_height (text, new_lines, new_line_count);
gdk_window_get_size (text->text_area, &width, &height);
......@@ -2275,7 +2367,7 @@ find_line_containing_point (GtkText* text, guint point)
}
}
g_assert (FALSE); /* Must set text->current_line here */
g_assert_not_reached (); /* Must set text->current_line here */
}
static guint
......@@ -2303,7 +2395,7 @@ pixel_height_of (GtkText* text, GList* cache_line)
static gint
find_char_width (GtkText* text, const GtkPropertyMark *mark, const TabStopMark *tab_mark)
{
gchar ch = TEXT_INDEX (text, mark->index);
gchar ch = GTK_TEXT_INDEX (text, mark->index);
gint16* char_widths = MARK_CURRENT_TEXT_FONT (mark)->char_widths;
if (ch == '\t')
......@@ -2358,7 +2450,7 @@ find_cursor_at_line (GtkText* text, const LineParams* start_line, gint pixel_hei
{
pixel_width += find_char_width (text, &mark, &tab_mark);
advance_tab_mark (text, &tab_mark, TEXT_INDEX(text, mark.index));
advance_tab_mark (text, &tab_mark, GTK_TEXT_INDEX(text, mark.index));
advance_mark (&mark);
}
......@@ -2367,7 +2459,7 @@ find_cursor_at_line (GtkText* text, const LineParams* start_line, gint pixel_hei
text->cursor_char_offset = start_line->font_descent;
text->cursor_mark = mark;
ch = TEXT_INDEX (text, mark.index);