1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
29 #include "gdk/gdkkeysyms.h"
30 #include "gdk/gdki18n.h"
32 #include "gtkselection.h"
33 #include "gtksignal.h"
35 #include "line-wrap.xbm"
36 #include "line-arrow.xbm"
39 #define INITIAL_BUFFER_SIZE 1024
40 #define INITIAL_LINE_CACHE_SIZE 256
41 #define MIN_GAP_SIZE 256
42 #define LINE_DELIM '\n'
43 #define MIN_TEXT_WIDTH_LINES 20
44 #define MIN_TEXT_HEIGHT_LINES 10
45 #define TEXT_BORDER_ROOM 1
46 #define LINE_WRAP_ROOM 8 /* The bitmaps are 6 wide. */
47 #define DEFAULT_TAB_STOP_WIDTH 4
48 #define SCROLL_PIXELS 5
49 #define KEY_SCROLL_PIXELS 10
50 #define SCROLL_TIME 100
51 #define FREEZE_LENGTH 1024
52 /* Freeze text when inserting or deleting more than this many characters */
54 #define SET_PROPERTY_MARK(m, p, o) do { \
55 (m)->property = (p); \
58 #define MARK_CURRENT_PROPERTY(mark) ((TextProperty*)(mark)->property->data)
59 #define MARK_NEXT_PROPERTY(mark) ((TextProperty*)(mark)->property->next->data)
60 #define MARK_PREV_PROPERTY(mark) ((TextProperty*)((mark)->property->prev ? \
61 (mark)->property->prev->data \
63 #define MARK_PREV_LIST_PTR(mark) ((mark)->property->prev)
64 #define MARK_LIST_PTR(mark) ((mark)->property)
65 #define MARK_NEXT_LIST_PTR(mark) ((mark)->property->next)
66 #define MARK_OFFSET(mark) ((mark)->offset)
67 #define MARK_PROPERTY_LENGTH(mark) (MARK_CURRENT_PROPERTY(mark)->length)
70 #define MARK_CURRENT_FONT(text, mark) \
71 ((MARK_CURRENT_PROPERTY(mark)->flags & PROPERTY_FONT) ? \
72 MARK_CURRENT_PROPERTY(mark)->font->gdk_font : \
73 GTK_WIDGET (text)->style->font)
74 #define MARK_CURRENT_FORE(text, mark) \
75 ((MARK_CURRENT_PROPERTY(mark)->flags & PROPERTY_FOREGROUND) ? \
76 &MARK_CURRENT_PROPERTY(mark)->fore_color : \
77 &((GtkWidget *)text)->style->text[((GtkWidget *)text)->state])
78 #define MARK_CURRENT_BACK(text, mark) \
79 ((MARK_CURRENT_PROPERTY(mark)->flags & PROPERTY_BACKGROUND) ? \
80 &MARK_CURRENT_PROPERTY(mark)->back_color : \
81 &((GtkWidget *)text)->style->base[((GtkWidget *)text)->state])
82 #define MARK_CURRENT_TEXT_FONT(text, mark) \
83 ((MARK_CURRENT_PROPERTY(mark)->flags & PROPERTY_FONT) ? \
84 MARK_CURRENT_PROPERTY(mark)->font : \
87 #define TEXT_LENGTH(t) ((t)->text_end - (t)->gap_size)
88 #define FONT_HEIGHT(f) ((f)->ascent + (f)->descent)
89 #define LINE_HEIGHT(l) ((l).font_ascent + (l).font_descent)
90 #define LINE_CONTAINS(l, i) ((l).start.index <= (i) && (l).end.index >= (i))
91 #define LINE_STARTS_AT(l, i) ((l).start.index == (i))
92 #define LINE_START_PIXEL(l) ((l).tab_cont.pixel_offset)
93 #define LAST_INDEX(t, m) ((m).index == TEXT_LENGTH(t))
94 #define CACHE_DATA(c) (*(LineParams*)(c)->data)
104 typedef struct _TextProperty TextProperty;
105 typedef struct _TabStopMark TabStopMark;
106 typedef struct _PrevTabCont PrevTabCont;
107 typedef struct _FetchLinesData FetchLinesData;
108 typedef struct _LineParams LineParams;
109 typedef struct _SetVerticalScrollData SetVerticalScrollData;
111 typedef gint (*LineIteratorFunction) (GtkText* text, LineParams* lp, void* data);
119 struct _SetVerticalScrollData {
121 gint last_didnt_wrap;
122 gint last_line_start;
123 GtkPropertyMark mark;
128 /* The actual font. */
132 gint16 char_widths[256];
136 PROPERTY_FONT = 1 << 0,
137 PROPERTY_FOREGROUND = 1 << 1,
138 PROPERTY_BACKGROUND = 1 << 2
146 /* Background Color. */
149 /* Foreground Color. */
152 /* Show which properties are set */
153 TextPropertyFlags flags;
155 /* Length of this property. */
161 GList* tab_stops; /* Index into list containing the next tab position. If
162 * NULL, using default widths. */
169 TabStopMark tab_start;
172 struct _FetchLinesData
185 guint displayable_chars;
188 PrevTabCont tab_cont;
189 PrevTabCont tab_cont_next;
191 GtkPropertyMark start;
196 static void gtk_text_class_init (GtkTextClass *klass);
197 static void gtk_text_set_arg (GtkObject *object,
200 static void gtk_text_get_arg (GtkObject *object,
203 static void gtk_text_init (GtkText *text);
204 static void gtk_text_destroy (GtkObject *object);
205 static void gtk_text_finalize (GObject *object);
206 static void gtk_text_realize (GtkWidget *widget);
207 static void gtk_text_unrealize (GtkWidget *widget);
208 static void gtk_text_style_set (GtkWidget *widget,
209 GtkStyle *previous_style);
210 static void gtk_text_state_changed (GtkWidget *widget,
211 GtkStateType previous_state);
212 static void gtk_text_draw_focus (GtkWidget *widget);
213 static void gtk_text_size_request (GtkWidget *widget,
214 GtkRequisition *requisition);
215 static void gtk_text_size_allocate (GtkWidget *widget,
216 GtkAllocation *allocation);
217 static void gtk_text_adjustment (GtkAdjustment *adjustment,
219 static void gtk_text_disconnect (GtkAdjustment *adjustment,
222 static void gtk_text_insert_text (GtkOldEditable *old_editable,
223 const gchar *new_text,
224 gint new_text_length,
226 static void gtk_text_delete_text (GtkOldEditable *old_editable,
229 static void gtk_text_update_text (GtkOldEditable *old_editable,
232 static gchar *gtk_text_get_chars (GtkOldEditable *old_editable,
235 static void gtk_text_set_selection (GtkOldEditable *old_editable,
238 static void gtk_text_real_set_editable (GtkOldEditable *old_editable,
239 gboolean is_editable);
242 static void gtk_text_draw (GtkWidget *widget,
244 static gint gtk_text_expose (GtkWidget *widget,
245 GdkEventExpose *event);
246 static gint gtk_text_button_press (GtkWidget *widget,
247 GdkEventButton *event);
248 static gint gtk_text_button_release (GtkWidget *widget,
249 GdkEventButton *event);
250 static gint gtk_text_motion_notify (GtkWidget *widget,
251 GdkEventMotion *event);
252 static gint gtk_text_key_press (GtkWidget *widget,
254 static gint gtk_text_focus_in (GtkWidget *widget,
255 GdkEventFocus *event);
256 static gint gtk_text_focus_out (GtkWidget *widget,
257 GdkEventFocus *event);
259 static void move_gap (GtkText* text, guint index);
260 static void make_forward_space (GtkText* text, guint len);
262 /* Property management */
263 static GtkTextFont* get_text_font (GdkFont* gfont);
264 static void text_font_unref (GtkTextFont *text_font);
266 static void insert_text_property (GtkText* text, GdkFont* font,
267 GdkColor *fore, GdkColor* back, guint len);
268 static TextProperty* new_text_property (GtkText *text, GdkFont* font,
269 GdkColor* fore, GdkColor* back, guint length);
270 static void destroy_text_property (TextProperty *prop);
271 static void init_properties (GtkText *text);
272 static void realize_property (GtkText *text, TextProperty *prop);
273 static void realize_properties (GtkText *text);
274 static void unrealize_property (GtkText *text, TextProperty *prop);
275 static void unrealize_properties (GtkText *text);
277 static void delete_text_property (GtkText* text, guint len);
279 static guint pixel_height_of (GtkText* text, GList* cache_line);
281 /* Property Movement and Size Computations */
282 static void advance_mark (GtkPropertyMark* mark);
283 static void decrement_mark (GtkPropertyMark* mark);
284 static void advance_mark_n (GtkPropertyMark* mark, gint n);
285 static void decrement_mark_n (GtkPropertyMark* mark, gint n);
286 static void move_mark_n (GtkPropertyMark* mark, gint n);
287 static GtkPropertyMark find_mark (GtkText* text, guint mark_position);
288 static GtkPropertyMark find_mark_near (GtkText* text, guint mark_position, const GtkPropertyMark* near);
289 static void find_line_containing_point (GtkText* text, guint point,
293 static void compute_lines_pixels (GtkText* text, guint char_count,
294 guint *lines, guint *pixels);
296 static gint total_line_height (GtkText* text,
299 static LineParams find_line_params (GtkText* text,
300 const GtkPropertyMark *mark,
301 const PrevTabCont *tab_cont,
302 PrevTabCont *next_cont);
303 static void recompute_geometry (GtkText* text);
304 static void insert_expose (GtkText* text, guint old_pixels, gint nchars, guint new_line_count);
305 static void delete_expose (GtkText* text,
309 static GdkGC *create_bg_gc (GtkText *text);
310 static void clear_area (GtkText *text, GdkRectangle *area);
311 static void draw_line (GtkText* text,
314 static void draw_line_wrap (GtkText* text,
316 static void draw_cursor (GtkText* text, gint absolute);
317 static void undraw_cursor (GtkText* text, gint absolute);
318 static gint drawn_cursor_min (GtkText* text);
319 static gint drawn_cursor_max (GtkText* text);
320 static void expose_text (GtkText* text, GdkRectangle *area, gboolean cursor);
322 /* Search and Placement. */
323 static void find_cursor (GtkText* text,
325 static void find_cursor_at_line (GtkText* text,
326 const LineParams* start_line,
328 static void find_mouse_cursor (GtkText* text, gint x, gint y);
331 static void adjust_adj (GtkText* text, GtkAdjustment* adj);
332 static void scroll_up (GtkText* text, gint diff);
333 static void scroll_down (GtkText* text, gint diff);
334 static void scroll_int (GtkText* text, gint diff);
336 static void process_exposes (GtkText *text);
338 /* Cache Management. */
339 static void free_cache (GtkText* text);
340 static GList* remove_cache_line (GtkText* text, GList* list);
343 static void move_cursor_buffer_ver (GtkText *text, int dir);
344 static void move_cursor_page_ver (GtkText *text, int dir);
345 static void move_cursor_ver (GtkText *text, int count);
346 static void move_cursor_hor (GtkText *text, int count);
348 /* Binding actions */
349 static void gtk_text_move_cursor (GtkOldEditable *old_editable,
352 static void gtk_text_move_word (GtkOldEditable *old_editable,
354 static void gtk_text_move_page (GtkOldEditable *old_editable,
357 static void gtk_text_move_to_row (GtkOldEditable *old_editable,
359 static void gtk_text_move_to_column (GtkOldEditable *old_editable,
361 static void gtk_text_kill_char (GtkOldEditable *old_editable,
363 static void gtk_text_kill_word (GtkOldEditable *old_editable,
365 static void gtk_text_kill_line (GtkOldEditable *old_editable,
369 static void gtk_text_move_forward_character (GtkText *text);
370 static void gtk_text_move_backward_character (GtkText *text);
371 static void gtk_text_move_forward_word (GtkText *text);
372 static void gtk_text_move_backward_word (GtkText *text);
373 static void gtk_text_move_beginning_of_line (GtkText *text);
374 static void gtk_text_move_end_of_line (GtkText *text);
375 static void gtk_text_move_next_line (GtkText *text);
376 static void gtk_text_move_previous_line (GtkText *text);
378 static void gtk_text_delete_forward_character (GtkText *text);
379 static void gtk_text_delete_backward_character (GtkText *text);
380 static void gtk_text_delete_forward_word (GtkText *text);
381 static void gtk_text_delete_backward_word (GtkText *text);
382 static void gtk_text_delete_line (GtkText *text);
383 static void gtk_text_delete_to_line_end (GtkText *text);
384 static void gtk_text_select_word (GtkText *text,
386 static void gtk_text_select_line (GtkText *text,
389 static void gtk_text_set_position (GtkOldEditable *old_editable,
392 /* #define DEBUG_GTK_TEXT */
394 #if defined(DEBUG_GTK_TEXT) && defined(__GNUC__)
395 /* Debugging utilities. */
396 static void gtk_text_assert_mark (GtkText *text,
397 GtkPropertyMark *mark,
398 GtkPropertyMark *before,
399 GtkPropertyMark *after,
404 static void gtk_text_assert (GtkText *text,
407 static void gtk_text_show_cache_line (GtkText *text, GList *cache,
408 const char* what, const char* func, gint line);
409 static void gtk_text_show_cache (GtkText *text, const char* func, gint line);
410 static void gtk_text_show_adj (GtkText *text,
415 static void gtk_text_show_props (GtkText* test,
419 #define TDEBUG(args) g_message args
420 #define TEXT_ASSERT(text) gtk_text_assert (text,__PRETTY_FUNCTION__,__LINE__)
421 #define TEXT_ASSERT_MARK(text,mark,msg) gtk_text_assert_mark (text,mark, \
422 __PRETTY_FUNCTION__,msg,__LINE__)
423 #define TEXT_SHOW(text) gtk_text_show_cache (text, __PRETTY_FUNCTION__,__LINE__)
424 #define TEXT_SHOW_LINE(text,line,msg) gtk_text_show_cache_line (text,line,msg,\
425 __PRETTY_FUNCTION__,__LINE__)
426 #define TEXT_SHOW_ADJ(text,adj,msg) gtk_text_show_adj (text,adj,msg, \
427 __PRETTY_FUNCTION__,__LINE__)
430 #define TEXT_ASSERT(text)
431 #define TEXT_ASSERT_MARK(text,mark,msg)
432 #define TEXT_SHOW(text)
433 #define TEXT_SHOW_LINE(text,line,msg)
434 #define TEXT_SHOW_ADJ(text,adj,msg)
437 /* Memory Management. */
438 static GMemChunk *params_mem_chunk = NULL;
439 static GMemChunk *text_property_chunk = NULL;
441 static GtkWidgetClass *parent_class = NULL;
444 static const GtkTextFunction control_keys[26] =
446 (GtkTextFunction)gtk_text_move_beginning_of_line, /* a */
447 (GtkTextFunction)gtk_text_move_backward_character, /* b */
448 (GtkTextFunction)gtk_editable_copy_clipboard, /* c */
449 (GtkTextFunction)gtk_text_delete_forward_character, /* d */
450 (GtkTextFunction)gtk_text_move_end_of_line, /* e */
451 (GtkTextFunction)gtk_text_move_forward_character, /* f */
453 (GtkTextFunction)gtk_text_delete_backward_character, /* h */
456 (GtkTextFunction)gtk_text_delete_to_line_end, /* k */
459 (GtkTextFunction)gtk_text_move_next_line, /* n */
461 (GtkTextFunction)gtk_text_move_previous_line, /* p */
466 (GtkTextFunction)gtk_text_delete_line, /* u */
467 (GtkTextFunction)gtk_editable_paste_clipboard, /* v */
468 (GtkTextFunction)gtk_text_delete_backward_word, /* w */
469 (GtkTextFunction)gtk_editable_cut_clipboard, /* x */
474 static const GtkTextFunction alt_keys[26] =
477 (GtkTextFunction)gtk_text_move_backward_word, /* b */
479 (GtkTextFunction)gtk_text_delete_forward_word, /* d */
481 (GtkTextFunction)gtk_text_move_forward_word, /* f */
505 /**********************************************************************/
507 /**********************************************************************/
510 gtk_text_get_type (void)
512 static GtkType text_type = 0;
516 static const GtkTypeInfo text_info =
520 sizeof (GtkTextClass),
521 (GtkClassInitFunc) gtk_text_class_init,
522 (GtkObjectInitFunc) gtk_text_init,
523 /* reserved_1 */ NULL,
524 /* reserved_2 */ NULL,
525 (GtkClassInitFunc) NULL,
528 text_type = gtk_type_unique (GTK_TYPE_OLD_EDITABLE, &text_info);
535 gtk_text_class_init (GtkTextClass *class)
537 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
538 GtkObjectClass *object_class;
539 GtkWidgetClass *widget_class;
540 GtkOldEditableClass *old_editable_class;
542 object_class = (GtkObjectClass*) class;
543 widget_class = (GtkWidgetClass*) class;
544 old_editable_class = (GtkOldEditableClass*) class;
545 parent_class = gtk_type_class (GTK_TYPE_OLD_EDITABLE);
547 gobject_class->finalize = gtk_text_finalize;
549 object_class->set_arg = gtk_text_set_arg;
550 object_class->get_arg = gtk_text_get_arg;
551 object_class->destroy = gtk_text_destroy;
553 widget_class->realize = gtk_text_realize;
554 widget_class->unrealize = gtk_text_unrealize;
555 widget_class->style_set = gtk_text_style_set;
556 widget_class->state_changed = gtk_text_state_changed;
557 widget_class->draw_focus = gtk_text_draw_focus;
558 widget_class->size_request = gtk_text_size_request;
559 widget_class->size_allocate = gtk_text_size_allocate;
560 widget_class->draw = gtk_text_draw;
561 widget_class->expose_event = gtk_text_expose;
562 widget_class->button_press_event = gtk_text_button_press;
563 widget_class->button_release_event = gtk_text_button_release;
564 widget_class->motion_notify_event = gtk_text_motion_notify;
565 widget_class->key_press_event = gtk_text_key_press;
566 widget_class->focus_in_event = gtk_text_focus_in;
567 widget_class->focus_out_event = gtk_text_focus_out;
569 old_editable_class->set_editable = gtk_text_real_set_editable;
570 old_editable_class->insert_text = gtk_text_insert_text;
571 old_editable_class->delete_text = gtk_text_delete_text;
573 old_editable_class->move_cursor = gtk_text_move_cursor;
574 old_editable_class->move_word = gtk_text_move_word;
575 old_editable_class->move_page = gtk_text_move_page;
576 old_editable_class->move_to_row = gtk_text_move_to_row;
577 old_editable_class->move_to_column = gtk_text_move_to_column;
579 old_editable_class->kill_char = gtk_text_kill_char;
580 old_editable_class->kill_word = gtk_text_kill_word;
581 old_editable_class->kill_line = gtk_text_kill_line;
583 old_editable_class->update_text = gtk_text_update_text;
584 old_editable_class->get_chars = gtk_text_get_chars;
585 old_editable_class->set_selection = gtk_text_set_selection;
586 old_editable_class->set_position = gtk_text_set_position;
588 class->set_scroll_adjustments = gtk_text_set_adjustments;
590 gtk_object_add_arg_type ("GtkText::hadjustment",
594 gtk_object_add_arg_type ("GtkText::vadjustment",
598 gtk_object_add_arg_type ("GtkText::line_wrap",
602 gtk_object_add_arg_type ("GtkText::word_wrap",
607 widget_class->set_scroll_adjustments_signal =
608 gtk_signal_new ("set_scroll_adjustments",
610 GTK_CLASS_TYPE (object_class),
611 GTK_SIGNAL_OFFSET (GtkTextClass, set_scroll_adjustments),
612 gtk_marshal_VOID__POINTER_POINTER,
613 GTK_TYPE_NONE, 2, GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT);
617 gtk_text_set_arg (GtkObject *object,
623 text = GTK_TEXT (object);
627 case ARG_HADJUSTMENT:
628 gtk_text_set_adjustments (text,
629 GTK_VALUE_POINTER (*arg),
632 case ARG_VADJUSTMENT:
633 gtk_text_set_adjustments (text,
635 GTK_VALUE_POINTER (*arg));
638 gtk_text_set_line_wrap (text, GTK_VALUE_BOOL (*arg));
641 gtk_text_set_word_wrap (text, GTK_VALUE_BOOL (*arg));
649 gtk_text_get_arg (GtkObject *object,
655 text = GTK_TEXT (object);
659 case ARG_HADJUSTMENT:
660 GTK_VALUE_POINTER (*arg) = text->hadj;
662 case ARG_VADJUSTMENT:
663 GTK_VALUE_POINTER (*arg) = text->vadj;
666 GTK_VALUE_BOOL (*arg) = text->line_wrap;
669 GTK_VALUE_BOOL (*arg) = text->word_wrap;
672 arg->type = GTK_TYPE_INVALID;
678 gtk_text_init (GtkText *text)
680 GTK_WIDGET_SET_FLAGS (text, GTK_CAN_FOCUS);
682 text->text_area = NULL;
687 text->line_wrap_bitmap = NULL;
688 text->line_arrow_bitmap = NULL;
690 text->use_wchar = FALSE;
691 text->text.ch = g_new (guchar, INITIAL_BUFFER_SIZE);
692 text->text_len = INITIAL_BUFFER_SIZE;
694 text->scratch_buffer.ch = NULL;
695 text->scratch_buffer_len = 0;
697 text->freeze_count = 0;
699 if (!params_mem_chunk)
700 params_mem_chunk = g_mem_chunk_new ("LineParams",
702 256 * sizeof (LineParams),
705 text->default_tab_width = 4;
706 text->tab_stops = NULL;
708 text->tab_stops = g_list_prepend (text->tab_stops, (void*)8);
709 text->tab_stops = g_list_prepend (text->tab_stops, (void*)8);
711 text->line_start_cache = NULL;
712 text->first_cut_pixels = 0;
714 text->line_wrap = TRUE;
715 text->word_wrap = FALSE;
720 text->current_font = NULL;
722 init_properties (text);
724 GTK_OLD_EDITABLE (text)->editable = FALSE;
726 gtk_text_set_adjustments (text, NULL, NULL);
727 gtk_editable_set_position (GTK_EDITABLE (text), 0);
731 gtk_text_new (GtkAdjustment *hadj,
737 g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadj), NULL);
739 g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadj), NULL);
741 text = gtk_widget_new (GTK_TYPE_TEXT,
750 gtk_text_set_word_wrap (GtkText *text,
753 g_return_if_fail (text != NULL);
754 g_return_if_fail (GTK_IS_TEXT (text));
756 text->word_wrap = (word_wrap != FALSE);
758 if (GTK_WIDGET_REALIZED (text))
760 recompute_geometry (text);
761 gtk_widget_queue_draw (GTK_WIDGET (text));
766 gtk_text_set_line_wrap (GtkText *text,
769 g_return_if_fail (text != NULL);
770 g_return_if_fail (GTK_IS_TEXT (text));
772 text->line_wrap = (line_wrap != FALSE);
774 if (GTK_WIDGET_REALIZED (text))
776 recompute_geometry (text);
777 gtk_widget_queue_draw (GTK_WIDGET (text));
782 gtk_text_set_editable (GtkText *text,
783 gboolean is_editable)
785 g_return_if_fail (text != NULL);
786 g_return_if_fail (GTK_IS_TEXT (text));
788 gtk_editable_set_editable (GTK_EDITABLE (text), is_editable);
792 gtk_text_real_set_editable (GtkOldEditable *old_editable,
793 gboolean is_editable)
797 g_return_if_fail (old_editable != NULL);
798 g_return_if_fail (GTK_IS_TEXT (old_editable));
800 text = GTK_TEXT (old_editable);
802 old_editable->editable = (is_editable != FALSE);
805 draw_cursor (text, TRUE);
807 undraw_cursor (text, TRUE);
811 gtk_text_set_adjustments (GtkText *text,
815 g_return_if_fail (text != NULL);
816 g_return_if_fail (GTK_IS_TEXT (text));
818 g_return_if_fail (GTK_IS_ADJUSTMENT (hadj));
820 hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
822 g_return_if_fail (GTK_IS_ADJUSTMENT (vadj));
824 vadj = GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0));
826 if (text->hadj && (text->hadj != hadj))
828 gtk_signal_disconnect_by_data (GTK_OBJECT (text->hadj), text);
829 gtk_object_unref (GTK_OBJECT (text->hadj));
832 if (text->vadj && (text->vadj != vadj))
834 gtk_signal_disconnect_by_data (GTK_OBJECT (text->vadj), text);
835 gtk_object_unref (GTK_OBJECT (text->vadj));
838 if (text->hadj != hadj)
841 gtk_object_ref (GTK_OBJECT (text->hadj));
842 gtk_object_sink (GTK_OBJECT (text->hadj));
844 gtk_signal_connect (GTK_OBJECT (text->hadj), "changed",
845 (GtkSignalFunc) gtk_text_adjustment,
847 gtk_signal_connect (GTK_OBJECT (text->hadj), "value_changed",
848 (GtkSignalFunc) gtk_text_adjustment,
850 gtk_signal_connect (GTK_OBJECT (text->hadj), "disconnect",
851 (GtkSignalFunc) gtk_text_disconnect,
853 gtk_text_adjustment (hadj, text);
856 if (text->vadj != vadj)
859 gtk_object_ref (GTK_OBJECT (text->vadj));
860 gtk_object_sink (GTK_OBJECT (text->vadj));
862 gtk_signal_connect (GTK_OBJECT (text->vadj), "changed",
863 (GtkSignalFunc) gtk_text_adjustment,
865 gtk_signal_connect (GTK_OBJECT (text->vadj), "value_changed",
866 (GtkSignalFunc) gtk_text_adjustment,
868 gtk_signal_connect (GTK_OBJECT (text->vadj), "disconnect",
869 (GtkSignalFunc) gtk_text_disconnect,
871 gtk_text_adjustment (vadj, text);
876 gtk_text_set_point (GtkText *text,
879 g_return_if_fail (text != NULL);
880 g_return_if_fail (GTK_IS_TEXT (text));
881 g_return_if_fail (index <= TEXT_LENGTH (text));
883 text->point = find_mark (text, index);
887 gtk_text_get_point (GtkText *text)
889 g_return_val_if_fail (text != NULL, 0);
890 g_return_val_if_fail (GTK_IS_TEXT (text), 0);
892 return text->point.index;
896 gtk_text_get_length (GtkText *text)
898 g_return_val_if_fail (text != NULL, 0);
899 g_return_val_if_fail (GTK_IS_TEXT (text), 0);
901 return TEXT_LENGTH (text);
905 gtk_text_freeze (GtkText *text)
907 g_return_if_fail (text != NULL);
908 g_return_if_fail (GTK_IS_TEXT (text));
910 text->freeze_count++;
914 gtk_text_thaw (GtkText *text)
916 g_return_if_fail (text != NULL);
917 g_return_if_fail (GTK_IS_TEXT (text));
919 if (text->freeze_count)
920 if (!(--text->freeze_count) && GTK_WIDGET_REALIZED (text))
922 recompute_geometry (text);
923 gtk_widget_queue_draw (GTK_WIDGET (text));
928 gtk_text_insert (GtkText *text,
935 GtkOldEditable *old_editable = GTK_OLD_EDITABLE (text);
936 gboolean frozen = FALSE;
938 gint new_line_count = 1;
939 guint old_height = 0;
944 g_return_if_fail (text != NULL);
945 g_return_if_fail (GTK_IS_TEXT (text));
948 length = strlen (chars);
955 if (!text->freeze_count && (length > FREEZE_LENGTH))
957 gtk_text_freeze (text);
961 if (!text->freeze_count && (text->line_start_cache != NULL))
963 find_line_containing_point (text, text->point.index, TRUE);
964 old_height = total_line_height (text, text->current_line, 1);
967 if ((TEXT_LENGTH (text) == 0) && (text->use_wchar == FALSE))
970 widget = GTK_WIDGET (text);
971 gtk_widget_ensure_style (widget);
972 if ((widget->style) && (widget->style->font->type == GDK_FONT_FONTSET))
974 text->use_wchar = TRUE;
975 g_free (text->text.ch);
976 text->text.wc = g_new (GdkWChar, INITIAL_BUFFER_SIZE);
977 text->text_len = INITIAL_BUFFER_SIZE;
978 if (text->scratch_buffer.ch)
979 g_free (text->scratch_buffer.ch);
980 text->scratch_buffer.wc = NULL;
981 text->scratch_buffer_len = 0;
985 move_gap (text, text->point.index);
986 make_forward_space (text, length);
990 char *chars_nt = (char *)chars;
993 chars_nt = g_new (char, length+1);
994 memcpy (chars_nt, chars, length);
995 chars_nt[length] = 0;
997 numwcs = gdk_mbstowcs (text->text.wc + text->gap_position, chars_nt,
999 if (chars_nt != chars)
1007 memcpy(text->text.ch + text->gap_position, chars, length);
1010 if (!text->freeze_count && (text->line_start_cache != NULL))
1012 if (text->use_wchar)
1014 for (i=0; i<numwcs; i++)
1015 if (text->text.wc[text->gap_position + i] == '\n')
1020 for (i=0; i<numwcs; i++)
1021 if (text->text.ch[text->gap_position + i] == '\n')
1028 insert_text_property (text, font, fore, back, numwcs);
1030 text->gap_size -= numwcs;
1031 text->gap_position += numwcs;
1033 if (text->point.index < text->first_line_start_index)
1034 text->first_line_start_index += numwcs;
1035 if (text->point.index < old_editable->selection_start_pos)
1036 old_editable->selection_start_pos += numwcs;
1037 if (text->point.index < old_editable->selection_end_pos)
1038 old_editable->selection_end_pos += numwcs;
1039 /* We'll reset the cursor later anyways if we aren't frozen */
1040 if (text->point.index < text->cursor_mark.index)
1041 text->cursor_mark.index += numwcs;
1043 advance_mark_n (&text->point, numwcs);
1045 if (!text->freeze_count && (text->line_start_cache != NULL))
1046 insert_expose (text, old_height, numwcs, new_line_count);
1050 gtk_text_thaw (text);
1054 gtk_text_backward_delete (GtkText *text,
1057 g_return_val_if_fail (text != NULL, 0);
1058 g_return_val_if_fail (GTK_IS_TEXT (text), 0);
1060 if (nchars > text->point.index || nchars <= 0)
1063 gtk_text_set_point (text, text->point.index - nchars);
1065 return gtk_text_forward_delete (text, nchars);
1069 gtk_text_forward_delete (GtkText *text,
1072 guint old_lines, old_height;
1073 GtkOldEditable *old_editable = GTK_OLD_EDITABLE (text);
1074 gboolean frozen = FALSE;
1076 g_return_val_if_fail (text != NULL, 0);
1077 g_return_val_if_fail (GTK_IS_TEXT (text), 0);
1079 if (text->point.index + nchars > TEXT_LENGTH (text) || nchars <= 0)
1082 if (!text->freeze_count && nchars > FREEZE_LENGTH)
1084 gtk_text_freeze (text);
1088 if (!text->freeze_count && text->line_start_cache != NULL)
1090 /* We need to undraw the cursor here, since we may later
1091 * delete the cursor's property
1093 undraw_cursor (text, FALSE);
1094 find_line_containing_point (text, text->point.index, TRUE);
1095 compute_lines_pixels (text, nchars, &old_lines, &old_height);
1098 /* FIXME, or resizing after deleting will be odd */
1099 if (text->point.index < text->first_line_start_index)
1101 if (text->point.index + nchars >= text->first_line_start_index)
1103 text->first_line_start_index = text->point.index;
1104 while ((text->first_line_start_index > 0) &&
1105 (GTK_TEXT_INDEX (text, text->first_line_start_index - 1)
1107 text->first_line_start_index -= 1;
1111 text->first_line_start_index -= nchars;
1114 if (text->point.index < old_editable->selection_start_pos)
1115 old_editable->selection_start_pos -=
1116 MIN(nchars, old_editable->selection_start_pos - text->point.index);
1117 if (text->point.index < old_editable->selection_end_pos)
1118 old_editable->selection_end_pos -=
1119 MIN(nchars, old_editable->selection_end_pos - text->point.index);
1120 /* We'll reset the cursor later anyways if we aren't frozen */
1121 if (text->point.index < text->cursor_mark.index)
1122 move_mark_n (&text->cursor_mark,
1123 -MIN(nchars, text->cursor_mark.index - text->point.index));
1125 move_gap (text, text->point.index);
1127 text->gap_size += nchars;
1129 delete_text_property (text, nchars);
1131 if (!text->freeze_count && (text->line_start_cache != NULL))
1133 delete_expose (text, nchars, old_lines, old_height);
1134 draw_cursor (text, FALSE);
1138 gtk_text_thaw (text);
1144 gtk_text_set_position (GtkOldEditable *old_editable,
1147 GtkText *text = (GtkText *) old_editable;
1149 undraw_cursor (text, FALSE);
1150 text->cursor_mark = find_mark (text, position);
1151 find_cursor (text, TRUE);
1152 draw_cursor (text, FALSE);
1153 gtk_editable_select_region (GTK_EDITABLE (old_editable), 0, 0);
1157 gtk_text_get_chars (GtkOldEditable *old_editable,
1165 g_return_val_if_fail (old_editable != NULL, NULL);
1166 g_return_val_if_fail (GTK_IS_TEXT (old_editable), NULL);
1167 text = GTK_TEXT (old_editable);
1170 end_pos = TEXT_LENGTH (text);
1172 if ((start_pos < 0) ||
1173 (end_pos > TEXT_LENGTH (text)) ||
1174 (end_pos < start_pos))
1177 move_gap (text, TEXT_LENGTH (text));
1178 make_forward_space (text, 1);
1180 if (text->use_wchar)
1183 ch = text->text.wc[end_pos];
1184 text->text.wc[end_pos] = 0;
1185 retval = gdk_wcstombs (text->text.wc + start_pos);
1186 text->text.wc[end_pos] = ch;
1191 ch = text->text.ch[end_pos];
1192 text->text.ch[end_pos] = 0;
1193 retval = g_strdup (text->text.ch + start_pos);
1194 text->text.ch[end_pos] = ch;
1202 gtk_text_destroy (GtkObject *object)
1206 g_return_if_fail (GTK_IS_TEXT (object));
1208 text = GTK_TEXT (object);
1212 gtk_signal_disconnect_by_data (GTK_OBJECT (text->hadj), text);
1213 gtk_object_unref (GTK_OBJECT (text->hadj));
1218 gtk_signal_disconnect_by_data (GTK_OBJECT (text->vadj), text);
1219 gtk_object_unref (GTK_OBJECT (text->vadj));
1225 gtk_timeout_remove (text->timer);
1229 GTK_OBJECT_CLASS(parent_class)->destroy (object);
1233 gtk_text_finalize (GObject *object)
1238 g_return_if_fail (GTK_IS_TEXT (object));
1240 text = GTK_TEXT (object);
1242 /* Clean up the internal structures */
1243 if (text->use_wchar)
1244 g_free (text->text.wc);
1246 g_free (text->text.ch);
1248 tmp_list = text->text_properties;
1251 destroy_text_property (tmp_list->data);
1252 tmp_list = tmp_list->next;
1255 if (text->current_font)
1256 text_font_unref (text->current_font);
1258 g_list_free (text->text_properties);
1260 if (text->use_wchar)
1262 if (text->scratch_buffer.wc)
1263 g_free (text->scratch_buffer.wc);
1267 if (text->scratch_buffer.ch)
1268 g_free (text->scratch_buffer.ch);
1271 g_list_free (text->tab_stops);
1273 G_OBJECT_CLASS (parent_class)->finalize (object);
1277 gtk_text_realize (GtkWidget *widget)
1280 GtkOldEditable *old_editable;
1281 GdkWindowAttr attributes;
1282 gint attributes_mask;
1284 g_return_if_fail (widget != NULL);
1285 g_return_if_fail (GTK_IS_TEXT (widget));
1287 text = GTK_TEXT (widget);
1288 old_editable = GTK_OLD_EDITABLE (widget);
1289 GTK_WIDGET_SET_FLAGS (text, GTK_REALIZED);
1291 attributes.window_type = GDK_WINDOW_CHILD;
1292 attributes.x = widget->allocation.x;
1293 attributes.y = widget->allocation.y;
1294 attributes.width = widget->allocation.width;
1295 attributes.height = widget->allocation.height;
1296 attributes.wclass = GDK_INPUT_OUTPUT;
1297 attributes.visual = gtk_widget_get_visual (widget);
1298 attributes.colormap = gtk_widget_get_colormap (widget);
1299 attributes.event_mask = gtk_widget_get_events (widget);
1300 attributes.event_mask |= (GDK_EXPOSURE_MASK |
1301 GDK_BUTTON_PRESS_MASK |
1302 GDK_BUTTON_RELEASE_MASK |
1303 GDK_BUTTON_MOTION_MASK |
1304 GDK_ENTER_NOTIFY_MASK |
1305 GDK_LEAVE_NOTIFY_MASK |
1306 GDK_KEY_PRESS_MASK);
1307 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
1309 widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
1310 gdk_window_set_user_data (widget->window, text);
1312 attributes.x = (widget->style->xthickness + TEXT_BORDER_ROOM);
1313 attributes.y = (widget->style->ythickness + TEXT_BORDER_ROOM);
1314 attributes.width = MAX (1, (gint)widget->allocation.width - (gint)attributes.x * 2);
1315 attributes.height = MAX (1, (gint)widget->allocation.height - (gint)attributes.y * 2);
1317 text->text_area = gdk_window_new (widget->window, &attributes, attributes_mask);
1318 gdk_window_set_user_data (text->text_area, text);
1320 widget->style = gtk_style_attach (widget->style, widget->window);
1322 /* Can't call gtk_style_set_background here because it's handled specially */
1323 gdk_window_set_background (widget->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
1324 gdk_window_set_background (text->text_area, &widget->style->base[GTK_WIDGET_STATE (widget)]);
1326 if (widget->style->bg_pixmap[GTK_STATE_NORMAL])
1327 text->bg_gc = create_bg_gc (text);
1329 text->line_wrap_bitmap = gdk_bitmap_create_from_data (text->text_area,
1330 (gchar*) line_wrap_bits,
1334 text->line_arrow_bitmap = gdk_bitmap_create_from_data (text->text_area,
1335 (gchar*) line_arrow_bits,
1339 text->gc = gdk_gc_new (text->text_area);
1340 gdk_gc_set_exposures (text->gc, TRUE);
1341 gdk_gc_set_foreground (text->gc, &widget->style->text[GTK_STATE_NORMAL]);
1344 if (gdk_im_ready () && (old_editable->ic_attr = gdk_ic_attr_new ()) != NULL)
1347 GdkColormap *colormap;
1349 GdkICAttr *attr = old_editable->ic_attr;
1350 GdkICAttributesType attrmask = GDK_IC_ALL_REQ;
1352 GdkIMStyle supported_style = GDK_IM_PREEDIT_NONE |
1353 GDK_IM_PREEDIT_NOTHING |
1354 GDK_IM_PREEDIT_POSITION |
1355 GDK_IM_STATUS_NONE |
1356 GDK_IM_STATUS_NOTHING;
1358 if (widget->style && widget->style->font->type != GDK_FONT_FONTSET)
1359 supported_style &= ~GDK_IM_PREEDIT_POSITION;
1361 attr->style = style = gdk_im_decide_style (supported_style);
1362 attr->client_window = text->text_area;
1364 if ((colormap = gtk_widget_get_colormap (widget)) !=
1365 gtk_widget_get_default_colormap ())
1367 attrmask |= GDK_IC_PREEDIT_COLORMAP;
1368 attr->preedit_colormap = colormap;
1371 switch (style & GDK_IM_PREEDIT_MASK)
1373 case GDK_IM_PREEDIT_POSITION:
1374 if (widget->style && widget->style->font->type != GDK_FONT_FONTSET)
1376 g_warning ("over-the-spot style requires fontset");
1380 attrmask |= GDK_IC_PREEDIT_POSITION_REQ;
1381 gdk_window_get_size (text->text_area, &width, &height);
1382 attr->spot_location.x = 0;
1383 attr->spot_location.y = height;
1384 attr->preedit_area.x = 0;
1385 attr->preedit_area.y = 0;
1386 attr->preedit_area.width = width;
1387 attr->preedit_area.height = height;
1388 attr->preedit_fontset = widget->style->font;
1392 old_editable->ic = gdk_ic_new (attr, attrmask);
1394 if (old_editable->ic == NULL)
1395 g_warning ("Can't create input context.");
1398 mask = gdk_window_get_events (text->text_area);
1399 mask |= gdk_ic_get_events (old_editable->ic);
1400 gdk_window_set_events (text->text_area, mask);
1402 if (GTK_WIDGET_HAS_FOCUS (widget))
1403 gdk_im_begin (old_editable->ic, text->text_area);
1408 realize_properties (text);
1409 gdk_window_show (text->text_area);
1410 init_properties (text);
1412 if (old_editable->selection_start_pos != old_editable->selection_end_pos)
1413 gtk_old_editable_claim_selection (old_editable, TRUE, GDK_CURRENT_TIME);
1415 recompute_geometry (text);
1419 gtk_text_style_set (GtkWidget *widget,
1420 GtkStyle *previous_style)
1422 GtkText *text = GTK_TEXT (widget);
1424 if (GTK_WIDGET_REALIZED (widget))
1426 gdk_window_set_background (widget->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
1427 gdk_window_set_background (text->text_area, &widget->style->base[GTK_WIDGET_STATE (widget)]);
1431 gdk_gc_destroy (text->bg_gc);
1435 if (widget->style->bg_pixmap[GTK_STATE_NORMAL])
1436 text->bg_gc = create_bg_gc (text);
1438 recompute_geometry (text);
1441 if (text->current_font)
1442 text_font_unref (text->current_font);
1443 text->current_font = get_text_font (widget->style->font);
1447 gtk_text_state_changed (GtkWidget *widget,
1448 GtkStateType previous_state)
1450 GtkText *text = GTK_TEXT (widget);
1452 if (GTK_WIDGET_REALIZED (widget))
1454 gdk_window_set_background (widget->window, &widget->style->base[GTK_WIDGET_STATE (widget)]);
1455 gdk_window_set_background (text->text_area, &widget->style->base[GTK_WIDGET_STATE (widget)]);
1460 gtk_text_unrealize (GtkWidget *widget)
1464 g_return_if_fail (widget != NULL);
1465 g_return_if_fail (GTK_IS_TEXT (widget));
1467 text = GTK_TEXT (widget);
1470 if (GTK_OLD_EDITABLE (widget)->ic)
1472 gdk_ic_destroy (GTK_OLD_EDITABLE (widget)->ic);
1473 GTK_OLD_EDITABLE (widget)->ic = NULL;
1475 if (GTK_OLD_EDITABLE (widget)->ic_attr)
1477 gdk_ic_attr_destroy (GTK_OLD_EDITABLE (widget)->ic_attr);
1478 GTK_OLD_EDITABLE (widget)->ic_attr = NULL;
1482 gdk_window_set_user_data (text->text_area, NULL);
1483 gdk_window_destroy (text->text_area);
1484 text->text_area = NULL;
1486 gdk_gc_destroy (text->gc);
1491 gdk_gc_destroy (text->bg_gc);
1495 gdk_pixmap_unref (text->line_wrap_bitmap);
1496 gdk_pixmap_unref (text->line_arrow_bitmap);
1498 unrealize_properties (text);
1502 if (GTK_WIDGET_CLASS (parent_class)->unrealize)
1503 (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
1507 clear_focus_area (GtkText *text, gint area_x, gint area_y, gint area_width, gint area_height)
1509 GtkWidget *widget = GTK_WIDGET (text);
1511 gint ythick = TEXT_BORDER_ROOM + widget->style->ythickness;
1512 gint xthick = TEXT_BORDER_ROOM + widget->style->xthickness;
1516 gdk_window_get_size (widget->style->bg_pixmap[GTK_STATE_NORMAL], &width, &height);
1518 gdk_gc_set_ts_origin (text->bg_gc,
1519 (- text->first_onscreen_hor_pixel + xthick) % width,
1520 (- text->first_onscreen_ver_pixel + ythick) % height);
1522 gdk_draw_rectangle (GTK_WIDGET (text)->window, text->bg_gc, TRUE,
1523 area_x, area_y, area_width, area_height);
1527 gtk_text_draw_focus (GtkWidget *widget)
1533 g_return_if_fail (widget != NULL);
1534 g_return_if_fail (GTK_IS_TEXT (widget));
1536 text = GTK_TEXT (widget);
1538 if (GTK_WIDGET_DRAWABLE (widget))
1540 gint ythick = widget->style->ythickness;
1541 gint xthick = widget->style->xthickness;
1542 gint xextra = TEXT_BORDER_ROOM;
1543 gint yextra = TEXT_BORDER_ROOM;
1545 TDEBUG (("in gtk_text_draw_focus\n"));
1549 width = widget->allocation.width;
1550 height = widget->allocation.height;
1552 if (GTK_WIDGET_HAS_FOCUS (widget))
1561 gtk_paint_focus (widget->style, widget->window,
1562 NULL, widget, "text",
1564 widget->allocation.width - 1,
1565 widget->allocation.height - 1);
1568 gtk_paint_shadow (widget->style, widget->window,
1569 GTK_STATE_NORMAL, GTK_SHADOW_IN,
1570 NULL, widget, "text",
1571 x, y, width, height);
1575 width -= 2 * xthick;
1576 height -= 2 * ythick;
1578 if (widget->style->bg_pixmap[GTK_STATE_NORMAL])
1581 clear_focus_area (text, x, y, width, yextra);
1583 clear_focus_area (text, x, y + yextra,
1584 xextra, y + height - 2 * yextra);
1586 clear_focus_area (text, x + width - xextra, y + yextra,
1587 xextra, height - 2 * ythick);
1589 clear_focus_area (text, x, x + height - yextra, width, yextra);
1594 TDEBUG (("in gtk_text_draw_focus (undrawable !!!)\n"));
1599 gtk_text_size_request (GtkWidget *widget,
1600 GtkRequisition *requisition)
1607 g_return_if_fail (widget != NULL);
1608 g_return_if_fail (GTK_IS_TEXT (widget));
1609 g_return_if_fail (requisition != NULL);
1611 xthickness = widget->style->xthickness + TEXT_BORDER_ROOM;
1612 ythickness = widget->style->ythickness + TEXT_BORDER_ROOM;
1614 char_height = MIN_TEXT_HEIGHT_LINES * (widget->style->font->ascent +
1615 widget->style->font->descent);
1617 char_width = MIN_TEXT_WIDTH_LINES * (gdk_text_width (widget->style->font,
1618 "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
1622 requisition->width = char_width + xthickness * 2;
1623 requisition->height = char_height + ythickness * 2;
1627 gtk_text_size_allocate (GtkWidget *widget,
1628 GtkAllocation *allocation)
1631 GtkOldEditable *old_editable;
1633 g_return_if_fail (widget != NULL);
1634 g_return_if_fail (GTK_IS_TEXT (widget));
1635 g_return_if_fail (allocation != NULL);
1637 text = GTK_TEXT (widget);
1638 old_editable = GTK_OLD_EDITABLE (widget);
1640 widget->allocation = *allocation;
1641 if (GTK_WIDGET_REALIZED (widget))
1643 gdk_window_move_resize (widget->window,
1644 allocation->x, allocation->y,
1645 allocation->width, allocation->height);
1647 gdk_window_move_resize (text->text_area,
1648 widget->style->xthickness + TEXT_BORDER_ROOM,
1649 widget->style->ythickness + TEXT_BORDER_ROOM,
1650 MAX (1, (gint)widget->allocation.width - (gint)(widget->style->xthickness +
1651 (gint)TEXT_BORDER_ROOM) * 2),
1652 MAX (1, (gint)widget->allocation.height - (gint)(widget->style->ythickness +
1653 (gint)TEXT_BORDER_ROOM) * 2));
1656 if (old_editable->ic && (gdk_ic_get_style (old_editable->ic) & GDK_IM_PREEDIT_POSITION))
1660 gdk_window_get_size (text->text_area, &width, &height);
1661 old_editable->ic_attr->preedit_area.width = width;
1662 old_editable->ic_attr->preedit_area.height = height;
1664 gdk_ic_set_attr (old_editable->ic,
1665 old_editable->ic_attr, GDK_IC_PREEDIT_AREA);
1669 recompute_geometry (text);
1674 gtk_text_draw (GtkWidget *widget,
1677 g_return_if_fail (widget != NULL);
1678 g_return_if_fail (GTK_IS_TEXT (widget));
1679 g_return_if_fail (area != NULL);
1681 if (GTK_WIDGET_DRAWABLE (widget))
1683 expose_text (GTK_TEXT (widget), area, TRUE);
1684 gtk_widget_draw_focus (widget);
1689 gtk_text_expose (GtkWidget *widget,
1690 GdkEventExpose *event)
1692 g_return_val_if_fail (widget != NULL, FALSE);
1693 g_return_val_if_fail (GTK_IS_TEXT (widget), FALSE);
1694 g_return_val_if_fail (event != NULL, FALSE);
1696 if (event->window == GTK_TEXT (widget)->text_area)
1698 TDEBUG (("in gtk_text_expose (expose)\n"));
1699 expose_text (GTK_TEXT (widget), &event->area, TRUE);
1701 else if (event->count == 0)
1703 TDEBUG (("in gtk_text_expose (focus)\n"));
1704 gtk_widget_draw_focus (widget);
1711 gtk_text_scroll_timeout (gpointer data)
1714 GdkEventMotion event;
1716 GdkModifierType mask;
1718 GDK_THREADS_ENTER ();
1720 text = GTK_TEXT (data);
1723 gdk_window_get_pointer (text->text_area, &x, &y, &mask);
1725 if (mask & (GDK_BUTTON1_MASK | GDK_BUTTON3_MASK))
1732 gtk_text_motion_notify (GTK_WIDGET (text), &event);
1735 GDK_THREADS_LEAVE ();
1741 gtk_text_button_press (GtkWidget *widget,
1742 GdkEventButton *event)
1745 GtkOldEditable *old_editable;
1747 g_return_val_if_fail (widget != NULL, FALSE);
1748 g_return_val_if_fail (GTK_IS_TEXT (widget), FALSE);
1749 g_return_val_if_fail (event != NULL, FALSE);
1751 text = GTK_TEXT (widget);
1752 old_editable = GTK_OLD_EDITABLE (widget);
1754 if (text->button && (event->button != text->button))
1757 text->button = event->button;
1759 if (!GTK_WIDGET_HAS_FOCUS (widget))
1760 gtk_widget_grab_focus (widget);
1762 if (event->button == 1)
1764 switch (event->type)
1766 case GDK_BUTTON_PRESS:
1767 gtk_grab_add (widget);
1769 undraw_cursor (text, FALSE);
1770 find_mouse_cursor (text, (gint)event->x, (gint)event->y);
1771 draw_cursor (text, FALSE);
1773 /* Set it now, so we display things right. We'll unset it
1774 * later if things don't work out */
1775 old_editable->has_selection = TRUE;
1776 gtk_text_set_selection (GTK_OLD_EDITABLE (text),
1777 text->cursor_mark.index,
1778 text->cursor_mark.index);
1782 case GDK_2BUTTON_PRESS:
1783 gtk_text_select_word (text, event->time);
1786 case GDK_3BUTTON_PRESS:
1787 gtk_text_select_line (text, event->time);
1794 else if (event->type == GDK_BUTTON_PRESS)
1796 if ((event->button == 2) && old_editable->editable)
1798 if (old_editable->selection_start_pos == old_editable->selection_end_pos ||
1799 old_editable->has_selection)
1801 undraw_cursor (text, FALSE);
1802 find_mouse_cursor (text, (gint)event->x, (gint)event->y);
1803 draw_cursor (text, FALSE);
1807 gtk_selection_convert (widget, GDK_SELECTION_PRIMARY,
1808 gdk_atom_intern ("UTF8_STRING", FALSE),
1813 gtk_grab_add (widget);
1815 undraw_cursor (text, FALSE);
1816 find_mouse_cursor (text, event->x, event->y);
1817 draw_cursor (text, FALSE);
1819 gtk_text_set_selection (GTK_OLD_EDITABLE (text),
1820 text->cursor_mark.index,
1821 text->cursor_mark.index);
1823 old_editable->has_selection = FALSE;
1824 if (gdk_selection_owner_get (GDK_SELECTION_PRIMARY) == widget->window)
1825 gtk_selection_owner_set (NULL, GDK_SELECTION_PRIMARY, event->time);
1833 gtk_text_button_release (GtkWidget *widget,
1834 GdkEventButton *event)
1837 GtkOldEditable *old_editable;
1838 g_return_val_if_fail (widget != NULL, FALSE);
1839 g_return_val_if_fail (GTK_IS_TEXT (widget), FALSE);
1840 g_return_val_if_fail (event != NULL, FALSE);
1842 text = GTK_TEXT (widget);
1844 gtk_grab_remove (widget);
1846 if (text->button != event->button)
1853 gtk_timeout_remove (text->timer);
1857 if (event->button == 1)
1859 text = GTK_TEXT (widget);
1860 old_editable = GTK_OLD_EDITABLE (widget);
1862 gtk_grab_remove (widget);
1864 old_editable->has_selection = FALSE;
1865 if (old_editable->selection_start_pos != old_editable->selection_end_pos)
1867 if (gtk_selection_owner_set (widget,
1868 GDK_SELECTION_PRIMARY,
1870 old_editable->has_selection = TRUE;
1872 gtk_text_update_text (old_editable, old_editable->selection_start_pos,
1873 old_editable->selection_end_pos);
1877 if (gdk_selection_owner_get (GDK_SELECTION_PRIMARY) == widget->window)
1878 gtk_selection_owner_set (NULL, GDK_SELECTION_PRIMARY, event->time);
1881 else if (event->button == 3)
1883 gtk_grab_remove (widget);
1886 undraw_cursor (text, FALSE);
1887 find_cursor (text, TRUE);
1888 draw_cursor (text, FALSE);
1894 gtk_text_motion_notify (GtkWidget *widget,
1895 GdkEventMotion *event)
1900 GdkModifierType mask;
1902 g_return_val_if_fail (widget != NULL, FALSE);
1903 g_return_val_if_fail (GTK_IS_TEXT (widget), FALSE);
1904 g_return_val_if_fail (event != NULL, FALSE);
1906 text = GTK_TEXT (widget);
1910 mask = event->state;
1911 if (event->is_hint || (text->text_area != event->window))
1913 gdk_window_get_pointer (text->text_area, &x, &y, &mask);
1916 if ((text->button == 0) ||
1917 !(mask & (GDK_BUTTON1_MASK | GDK_BUTTON3_MASK)))
1920 gdk_window_get_size (text->text_area, NULL, &height);
1922 if ((y < 0) || (y > height))
1924 if (text->timer == 0)
1926 text->timer = gtk_timeout_add (SCROLL_TIME,
1927 gtk_text_scroll_timeout,
1931 scroll_int (text, y/2);
1933 scroll_int (text, (y - height)/2);
1939 undraw_cursor (GTK_TEXT (widget), FALSE);
1940 find_mouse_cursor (GTK_TEXT (widget), x, y);
1941 draw_cursor (GTK_TEXT (widget), FALSE);
1943 gtk_text_set_selection (GTK_OLD_EDITABLE (text),
1944 GTK_OLD_EDITABLE (text)->selection_start_pos,
1945 text->cursor_mark.index);
1951 gtk_text_insert_text (GtkOldEditable *old_editable,
1952 const gchar *new_text,
1953 gint new_text_length,
1956 GtkText *text = GTK_TEXT (old_editable);
1958 GdkColor *fore, *back;
1960 TextProperty *property;
1962 gtk_text_set_point (text, *position);
1964 property = MARK_CURRENT_PROPERTY (&text->point);
1965 font = property->flags & PROPERTY_FONT ? property->font->gdk_font : NULL;
1966 fore = property->flags & PROPERTY_FOREGROUND ? &property->fore_color : NULL;
1967 back = property->flags & PROPERTY_BACKGROUND ? &property->back_color : NULL;
1969 gtk_text_insert (text, font, fore, back, new_text, new_text_length);
1971 *position = text->point.index;
1975 gtk_text_delete_text (GtkOldEditable *old_editable,
1981 g_return_if_fail (start_pos >= 0);
1983 text = GTK_TEXT (old_editable);
1985 gtk_text_set_point (text, start_pos);
1987 end_pos = TEXT_LENGTH (text);
1989 if (end_pos > start_pos)
1990 gtk_text_forward_delete (text, end_pos - start_pos);
1994 gtk_text_key_press (GtkWidget *widget,
1998 GtkOldEditable *old_editable;
2003 g_return_val_if_fail (widget != NULL, FALSE);
2004 g_return_val_if_fail (GTK_IS_TEXT (widget), FALSE);
2005 g_return_val_if_fail (event != NULL, FALSE);
2009 text = GTK_TEXT (widget);
2010 old_editable = GTK_OLD_EDITABLE (widget);
2012 key = event->keyval;
2015 if ((GTK_OLD_EDITABLE(text)->editable == FALSE))
2017 switch (event->keyval)
2020 if (event->state & GDK_CONTROL_MASK)
2021 scroll_int (text, -text->vadj->value);
2026 if (event->state & GDK_CONTROL_MASK)
2027 scroll_int (text, +text->vadj->upper);
2031 case GDK_Page_Up: scroll_int (text, -text->vadj->page_increment); break;
2032 case GDK_Page_Down: scroll_int (text, +text->vadj->page_increment); break;
2033 case GDK_Up: scroll_int (text, -KEY_SCROLL_PIXELS); break;
2034 case GDK_Down: scroll_int (text, +KEY_SCROLL_PIXELS); break;
2036 if (event->state & GDK_CONTROL_MASK)
2037 gtk_signal_emit_by_name (GTK_OBJECT (text), "activate");
2048 gint extend_selection;
2050 guint initial_pos = old_editable->current_pos;
2052 text->point = find_mark (text, text->cursor_mark.index);
2054 extend_selection = event->state & GDK_SHIFT_MASK;
2055 extend_start = FALSE;
2057 if (extend_selection)
2059 old_editable->has_selection = TRUE;
2061 if (old_editable->selection_start_pos == old_editable->selection_end_pos)
2063 old_editable->selection_start_pos = text->point.index;
2064 old_editable->selection_end_pos = text->point.index;
2067 extend_start = (text->point.index == old_editable->selection_start_pos);
2070 switch (event->keyval)
2073 if (event->state & GDK_CONTROL_MASK)
2074 move_cursor_buffer_ver (text, -1);
2076 gtk_text_move_beginning_of_line (text);
2079 if (event->state & GDK_CONTROL_MASK)
2080 move_cursor_buffer_ver (text, +1);
2082 gtk_text_move_end_of_line (text);
2084 case GDK_Page_Up: move_cursor_page_ver (text, -1); break;
2085 case GDK_Page_Down: move_cursor_page_ver (text, +1); break;
2086 /* CUA has Ctrl-Up/Ctrl-Down as paragraph up down */
2087 case GDK_Up: move_cursor_ver (text, -1); break;
2088 case GDK_Down: move_cursor_ver (text, +1); break;
2090 if (event->state & GDK_CONTROL_MASK)
2091 gtk_text_move_backward_word (text);
2093 move_cursor_hor (text, -1);
2096 if (event->state & GDK_CONTROL_MASK)
2097 gtk_text_move_forward_word (text);
2099 move_cursor_hor (text, +1);
2103 if (event->state & GDK_CONTROL_MASK)
2104 gtk_text_delete_backward_word (text);
2106 gtk_text_delete_backward_character (text);
2109 gtk_text_delete_line (text);
2112 if (event->state & GDK_SHIFT_MASK)
2114 extend_selection = FALSE;
2115 gtk_editable_paste_clipboard (GTK_EDITABLE (old_editable));
2117 else if (event->state & GDK_CONTROL_MASK)
2119 gtk_editable_copy_clipboard (GTK_EDITABLE (old_editable));
2123 /* gtk_toggle_insert(text) -- IMPLEMENT */
2127 if (event->state & GDK_CONTROL_MASK)
2128 gtk_text_delete_forward_word (text);
2129 else if (event->state & GDK_SHIFT_MASK)
2131 extend_selection = FALSE;
2132 gtk_editable_cut_clipboard (GTK_EDITABLE (old_editable));
2135 gtk_text_delete_forward_character (text);
2138 position = text->point.index;
2139 gtk_editable_insert_text (GTK_EDITABLE (old_editable), "\t", 1, &position);
2142 if (event->state & GDK_CONTROL_MASK)
2143 gtk_signal_emit_by_name (GTK_OBJECT (text), "activate");
2146 position = text->point.index;
2147 gtk_editable_insert_text (GTK_EDITABLE (old_editable), "\n", 1, &position);
2151 /* Don't insert literally */
2158 if (event->state & GDK_CONTROL_MASK)
2160 if ((key >= 'A') && (key <= 'Z'))
2163 if ((key >= 'a') && (key <= 'z') && control_keys[(int) (key - 'a')])
2165 (* control_keys[(int) (key - 'a')]) (old_editable, event->time);
2171 else if (event->state & GDK_MOD1_MASK)
2173 if ((key >= 'A') && (key <= 'Z'))
2176 if ((key >= 'a') && (key <= 'z') && alt_keys[(int) (key - 'a')])
2178 (* alt_keys[(int) (key - 'a')]) (old_editable, event->time);
2184 else if (event->length > 0)
2186 extend_selection = FALSE;
2188 gtk_editable_delete_selection (GTK_EDITABLE (old_editable));
2189 position = text->point.index;
2190 gtk_editable_insert_text (GTK_EDITABLE (old_editable), event->string, event->length, &position);
2198 if (return_val && (old_editable->current_pos != initial_pos))
2200 if (extend_selection)
2202 if (old_editable->current_pos < old_editable->selection_start_pos)
2203 gtk_text_set_selection (old_editable, old_editable->current_pos,
2204 old_editable->selection_end_pos);
2205 else if (old_editable->current_pos > old_editable->selection_end_pos)
2206 gtk_text_set_selection (old_editable, old_editable->selection_start_pos,
2207 old_editable->current_pos);
2211 gtk_text_set_selection (old_editable, old_editable->current_pos,
2212 old_editable->selection_end_pos);
2214 gtk_text_set_selection (old_editable, old_editable->selection_start_pos,
2215 old_editable->current_pos);
2219 gtk_text_set_selection (old_editable, 0, 0);
2221 gtk_old_editable_claim_selection (old_editable,
2222 old_editable->selection_start_pos != old_editable->selection_end_pos,
2231 gtk_text_focus_in (GtkWidget *widget,
2232 GdkEventFocus *event)
2234 g_return_val_if_fail (widget != NULL, FALSE);
2235 g_return_val_if_fail (GTK_IS_TEXT (widget), FALSE);
2236 g_return_val_if_fail (event != NULL, FALSE);
2238 TDEBUG (("in gtk_text_focus_in\n"));
2240 GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS);
2241 gtk_widget_draw_focus (widget);
2244 if (GTK_OLD_EDITABLE (widget)->ic)
2245 gdk_im_begin (GTK_OLD_EDITABLE (widget)->ic, GTK_TEXT(widget)->text_area);
2248 draw_cursor (GTK_TEXT(widget), TRUE);
2254 gtk_text_focus_out (GtkWidget *widget,
2255 GdkEventFocus *event)
2257 g_return_val_if_fail (widget != NULL, FALSE);
2258 g_return_val_if_fail (GTK_IS_TEXT (widget), FALSE);
2259 g_return_val_if_fail (event != NULL, FALSE);
2261 TDEBUG (("in gtk_text_focus_out\n"));
2263 GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS);
2264 gtk_widget_draw_focus (widget);
2266 undraw_cursor (GTK_TEXT(widget), TRUE);
2276 gtk_text_adjustment (GtkAdjustment *adjustment,
2279 g_return_if_fail (adjustment != NULL);
2280 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
2281 g_return_if_fail (text != NULL);
2282 g_return_if_fail (GTK_IS_TEXT (text));
2284 /* Just ignore it if we haven't been size-allocated and realized yet */
2285 if (text->line_start_cache == NULL)
2288 if (adjustment == text->hadj)
2290 g_warning ("horizontal scrolling not implemented");
2294 gint diff = ((gint)adjustment->value) - text->last_ver_value;
2298 undraw_cursor (text, FALSE);
2301 scroll_down (text, diff);
2302 else /* if (diff < 0) */
2303 scroll_up (text, diff);
2305 draw_cursor (text, FALSE);
2307 text->last_ver_value = adjustment->value;
2313 gtk_text_disconnect (GtkAdjustment *adjustment,
2316 g_return_if_fail (adjustment != NULL);
2317 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
2318 g_return_if_fail (text != NULL);
2319 g_return_if_fail (GTK_IS_TEXT (text));
2321 if (adjustment == text->hadj)
2322 gtk_text_set_adjustments (text, NULL, text->vadj);
2323 if (adjustment == text->vadj)
2324 gtk_text_set_adjustments (text, text->hadj, NULL);
2328 static GtkPropertyMark
2329 find_this_line_start_mark (GtkText* text, guint point_position, const GtkPropertyMark* near)
2331 GtkPropertyMark mark;
2333 mark = find_mark_near (text, point_position, near);
2335 while (mark.index > 0 &&
2336 GTK_TEXT_INDEX (text, mark.index - 1) != LINE_DELIM)
2337 decrement_mark (&mark);
2343 init_tab_cont (GtkText* text, PrevTabCont* tab_cont)
2345 tab_cont->pixel_offset = 0;
2346 tab_cont->tab_start.tab_stops = text->tab_stops;
2347 tab_cont->tab_start.to_next_tab = (gulong) text->tab_stops->data;
2349 if (!tab_cont->tab_start.to_next_tab)
2350 tab_cont->tab_start.to_next_tab = text->default_tab_width;
2354 line_params_iterate (GtkText* text,
2355 const GtkPropertyMark* mark0,
2356 const PrevTabCont* tab_mark0,
2359 LineIteratorFunction iter)
2360 /* mark0 MUST be a real line start. if ALLOC, allocate line params
2361 * from a mem chunk. DATA is passed to ITER_CALL, which is called
2362 * for each line following MARK, iteration continues unless ITER_CALL
2365 GtkPropertyMark mark = *mark0;
2366 PrevTabCont tab_conts[2];
2367 LineParams *lp, lpbuf;
2368 gint tab_cont_index = 0;
2371 tab_conts[0] = *tab_mark0;
2373 init_tab_cont (text, tab_conts);
2378 lp = g_chunk_new (LineParams, params_mem_chunk);
2382 *lp = find_line_params (text, &mark, tab_conts + tab_cont_index,
2383 tab_conts + (tab_cont_index + 1) % 2);
2385 if ((*iter) (text, lp, data))
2388 if (LAST_INDEX (text, lp->end))
2392 advance_mark (&mark);
2393 tab_cont_index = (tab_cont_index + 1) % 2;
2398 fetch_lines_iterator (GtkText* text, LineParams* lp, void* data)
2400 FetchLinesData *fldata = (FetchLinesData*) data;
2402 fldata->new_lines = g_list_prepend (fldata->new_lines, lp);
2404 switch (fldata->fl_type)
2406 case FetchLinesCount:
2407 if (!text->line_wrap || !lp->wraps)
2410 if (fldata->data >= fldata->data_max)
2414 case FetchLinesPixels:
2416 fldata->data += LINE_HEIGHT(*lp);
2418 if (fldata->data >= fldata->data_max)
2428 fetch_lines (GtkText* text,
2429 const GtkPropertyMark* mark0,
2430 const PrevTabCont* tab_cont0,
2434 FetchLinesData fl_data;
2436 fl_data.new_lines = NULL;
2438 fl_data.data_max = data;
2439 fl_data.fl_type = fl_type;
2441 line_params_iterate (text, mark0, tab_cont0, TRUE, &fl_data, fetch_lines_iterator);
2443 return g_list_reverse (fl_data.new_lines);
2447 fetch_lines_backward (GtkText* text)
2449 GList* new_lines = NULL, *new_line_start;
2450 GtkPropertyMark mark;
2452 if (CACHE_DATA(text->line_start_cache).start.index == 0)
2455 mark = find_this_line_start_mark (text,
2456 CACHE_DATA(text->line_start_cache).start.index - 1,
2457 &CACHE_DATA(text->line_start_cache).start);
2459 new_line_start = new_lines = fetch_lines (text, &mark, NULL, FetchLinesCount, 1);
2461 while (new_line_start->next)
2462 new_line_start = new_line_start->next;
2464 new_line_start->next = text->line_start_cache;
2465 text->line_start_cache->prev = new_line_start;
2469 fetch_lines_forward (GtkText* text, gint line_count)
2471 GtkPropertyMark mark;
2472 GList* line = text->line_start_cache;
2477 mark = CACHE_DATA(line).end;
2479 if (LAST_INDEX (text, mark))
2482 advance_mark(&mark);
2484 line->next = fetch_lines (text, &mark, &CACHE_DATA(line).tab_cont_next, FetchLinesCount, line_count);
2487 line->next->prev = line;
2490 /* Compute the number of lines, and vertical pixels for n characters
2491 * starting from the point
2494 compute_lines_pixels (GtkText* text, guint char_count,
2495 guint *lines, guint *pixels)
2497 GList *line = text->current_line;
2498 gint chars_left = char_count;
2503 /* If chars_left == 0, that means we're joining two lines in a
2504 * deletion, so add in the values for the next line as well
2506 for (; line && chars_left >= 0; line = line->next)
2508 *pixels += LINE_HEIGHT(CACHE_DATA(line));
2510 if (line == text->current_line)
2511 chars_left -= CACHE_DATA(line).end.index - text->point.index + 1;
2513 chars_left -= CACHE_DATA(line).end.index - CACHE_DATA(line).start.index + 1;
2515 if (!text->line_wrap || !CACHE_DATA(line).wraps)
2519 chars_left = 0; /* force another loop */
2522 fetch_lines_forward (text, 1);
2527 total_line_height (GtkText* text, GList* line, gint line_count)
2531 for (; line && line_count > 0; line = line->next)
2533 height += LINE_HEIGHT(CACHE_DATA(line));
2535 if (!text->line_wrap || !CACHE_DATA(line).wraps)
2539 fetch_lines_forward (text, line_count);
2546 swap_lines (GtkText* text, GList* old, GList* new, guint old_line_count)
2548 if (old == text->line_start_cache)
2552 for (; old_line_count > 0; old_line_count -= 1)
2554 while (text->line_start_cache &&
2556 CACHE_DATA(text->line_start_cache).wraps)
2557 remove_cache_line(text, text->line_start_cache);
2559 remove_cache_line(text, text->line_start_cache);
2562 last = g_list_last (new);
2564 last->next = text->line_start_cache;
2566 if (text->line_start_cache)
2567 text->line_start_cache->prev = last;
2569 text->line_start_cache = new;
2575 g_assert (old->prev);
2579 for (; old_line_count > 0; old_line_count -= 1)
2581 while (old && text->line_wrap && CACHE_DATA(old).wraps)
2582 old = remove_cache_line (text, old);
2584 old = remove_cache_line (text, old);
2590 last = g_list_last (new);
2600 correct_cache_delete (GtkText* text, gint nchars, gint lines)
2602 GList* cache = text->current_line;
2605 for (i = 0; cache && i < lines; i += 1, cache = cache->next)
2608 for (; cache; cache = cache->next)
2610 GtkPropertyMark *start = &CACHE_DATA(cache).start;
2611 GtkPropertyMark *end = &CACHE_DATA(cache).end;
2613 start->index -= nchars;
2614 end->index -= nchars;
2616 if (LAST_INDEX (text, text->point) &&
2617 start->index == text->point.index)
2618 *start = text->point;
2619 else if (start->property == text->point.property)
2620 start->offset = start->index - (text->point.index - text->point.offset);
2622 if (LAST_INDEX (text, text->point) &&
2623 end->index == text->point.index)
2625 if (end->property == text->point.property)
2626 end->offset = end->index - (text->point.index - text->point.offset);
2628 /*TEXT_ASSERT_MARK(text, start, "start");*/
2629 /*TEXT_ASSERT_MARK(text, end, "end");*/
2634 delete_expose (GtkText* text, guint nchars, guint old_lines, guint old_pixels)
2636 GtkWidget *widget = GTK_WIDGET (text);
2639 guint new_pixels = 0;
2641 GList* new_line = NULL;
2644 text->cursor_virtual_x = 0;
2646 correct_cache_delete (text, nchars, old_lines);
2648 pixel_height = pixel_height_of(text, text->current_line) -
2649 LINE_HEIGHT(CACHE_DATA(text->current_line));
2651 if (CACHE_DATA(text->current_line).start.index == text->point.index)
2652 CACHE_DATA(text->current_line).start = text->point;
2654 new_line = fetch_lines (text,
2655 &CACHE_DATA(text->current_line).start,
2656 &CACHE_DATA(text->current_line).tab_cont,
2660 swap_lines (text, text->current_line, new_line, old_lines);
2662 text->current_line = new_line;
2664 new_pixels = total_line_height (text, new_line, 1);
2666 gdk_window_get_size (text->text_area, &width, &height);
2668 if (old_pixels != new_pixels)
2670 if (!widget->style->bg_pixmap[GTK_STATE_NORMAL])
2672 gdk_draw_pixmap (text->text_area,
2676 pixel_height + old_pixels,
2678 pixel_height + new_pixels,
2682 text->vadj->upper += new_pixels;
2683 text->vadj->upper -= old_pixels;
2684 adjust_adj (text, text->vadj);
2688 rect.y = pixel_height;
2690 rect.height = new_pixels;
2692 expose_text (text, &rect, FALSE);
2693 gtk_text_draw_focus ( (GtkWidget *) text);
2695 text->cursor_mark = text->point;
2697 find_cursor (text, TRUE);
2699 if (old_pixels != new_pixels)
2701 if (widget->style->bg_pixmap[GTK_STATE_NORMAL])
2704 rect.y = pixel_height + new_pixels;
2706 rect.height = height - rect.y;
2708 expose_text (text, &rect, FALSE);
2711 process_exposes (text);
2718 /* note, the point has already been moved forward */
2720 correct_cache_insert (GtkText* text, gint nchars)
2723 GtkPropertyMark *start;
2724 GtkPropertyMark *end;
2725 gboolean was_split = FALSE;
2727 /* We need to distinguish whether the property was split in the
2728 * insert or not, so we check if the point (which points after
2729 * the insertion here), points to the same character as the
2730 * point before. Ugh.
2734 GtkPropertyMark tmp_mark = text->point;
2735 move_mark_n (&tmp_mark, -1);
2737 if (tmp_mark.property != text->point.property)
2741 /* If we inserted a property exactly at the beginning of the
2742 * line, we have to correct here, or fetch_lines will
2745 start = &CACHE_DATA(text->current_line).start;
2747 /* Check if if we split exactly at the beginning of the line:
2748 * (was_split won't be set if we are inserting at the end of the text,
2749 * so we don't check)
2751 if (start->offset == MARK_CURRENT_PROPERTY (start)->length)
2752 SET_PROPERTY_MARK (start, start->property->next, 0);
2753 /* Check if we inserted a property at the beginning of the text: */
2754 else if (was_split &&
2755 (start->property == text->point.property) &&
2756 (start->index == text->point.index - nchars))
2757 SET_PROPERTY_MARK (start, start->property->prev, 0);
2759 /* Now correct the offsets, and check for start or end marks that
2760 * are after the point, yet point to a property before the point's
2761 * property. This indicates that they are meant to point to the
2762 * second half of a property we split in insert_text_property(), so
2763 * we fix them up that way.
2765 cache = text->current_line->next;
2767 for (; cache; cache = cache->next)
2769 start = &CACHE_DATA(cache).start;
2770 end = &CACHE_DATA(cache).end;
2772 if (LAST_INDEX (text, text->point) &&
2773 start->index == text->point.index)
2774 *start = text->point;
2775 else if (start->index >= text->point.index - nchars)
2777 if (!was_split && start->property == text->point.property)
2778 move_mark_n(start, nchars);
2781 if (start->property->next &&
2782 (start->property->next->next == text->point.property))
2784 g_assert (start->offset >= MARK_CURRENT_PROPERTY (start)->length);
2785 start->offset -= MARK_CURRENT_PROPERTY (start)->length;
2786 start->property = text->point.property;
2788 start->index += nchars;
2792 if (LAST_INDEX (text, text->point) &&
2793 end->index == text->point.index)
2795 if (end->index >= text->point.index - nchars)
2797 if (!was_split && end->property == text->point.property)
2798 move_mark_n(end, nchars);
2801 if (end->property->next &&
2802 (end->property->next->next == text->point.property))
2804 g_assert (end->offset >= MARK_CURRENT_PROPERTY (end)->length);
2805 end->offset -= MARK_CURRENT_PROPERTY (end)->length;
2806 end->property = text->point.property;
2808 end->index += nchars;
2812 /*TEXT_ASSERT_MARK(text, start, "start");*/
2813 /*TEXT_ASSERT_MARK(text, end, "end");*/
2819 insert_expose (GtkText* text, guint old_pixels, gint nchars,
2820 guint new_line_count)
2822 GtkWidget *widget = GTK_WIDGET (text);
2825 guint new_pixels = 0;
2827 GList* new_lines = NULL;
2830 text->cursor_virtual_x = 0;
2832 undraw_cursor (text, FALSE);
2834 correct_cache_insert (text, nchars);
2836 TEXT_SHOW_ADJ (text, text->vadj, "vadj");
2838 pixel_height = pixel_height_of(text, text->current_line) -
2839 LINE_HEIGHT(CACHE_DATA(text->current_line));
2841 new_lines = fetch_lines (text,
2842 &CACHE_DATA(text->current_line).start,
2843 &CACHE_DATA(text->current_line).tab_cont,
2847 swap_lines (text, text->current_line, new_lines, 1);
2849 text->current_line = new_lines;
2851 new_pixels = total_line_height (text, new_lines, new_line_count);
2853 gdk_window_get_size (text->text_area, &width, &height);
2855 if (old_pixels != new_pixels)
2857 if (!widget->style->bg_pixmap[GTK_STATE_NORMAL])
2859 gdk_draw_pixmap (text->text_area,
2863 pixel_height + old_pixels,
2865 pixel_height + new_pixels,
2867 height + (old_pixels - new_pixels) - pixel_height);
2870 text->vadj->upper += new_pixels;
2871 text->vadj->upper -= old_pixels;
2872 adjust_adj (text, text->vadj);
2876 rect.y = pixel_height;
2878 rect.height = new_pixels;
2880 expose_text (text, &rect, FALSE);
2881 gtk_text_draw_focus ( (GtkWidget *) text);
2883 text->cursor_mark = text->point;
2885 find_cursor (text, TRUE);
2887 draw_cursor (text, FALSE);
2889 if (old_pixels != new_pixels)
2891 if (widget->style->bg_pixmap[GTK_STATE_NORMAL])
2894 rect.y = pixel_height + new_pixels;
2896 rect.height = height - rect.y;
2898 expose_text (text, &rect, FALSE);
2901 process_exposes (text);
2904 TEXT_SHOW_ADJ (text, text->vadj, "vadj");
2909 /* Text property functions */
2912 font_hash (gconstpointer font)
2914 return gdk_font_id ((const GdkFont*) font);
2917 static GHashTable *font_cache_table = NULL;
2920 get_text_font (GdkFont* gfont)
2925 if (!font_cache_table)
2926 font_cache_table = g_hash_table_new (font_hash, (GEqualFunc) gdk_font_equal);
2928 tf = g_hash_table_lookup (font_cache_table, gfont);
2936 tf = g_new (GtkTextFont, 1);
2939 tf->gdk_font = gfont;
2940 gdk_font_ref (gfont);
2942 for(i = 0; i < 256; i += 1)
2943 tf->char_widths[i] = gdk_char_width (gfont, (char)i);
2945 g_hash_table_insert (font_cache_table, gfont, tf);
2951 text_font_unref (GtkTextFont *text_font)
2953 text_font->ref_count--;
2954 if (text_font->ref_count == 0)
2956 g_hash_table_remove (font_cache_table, text_font->gdk_font);
2957 gdk_font_unref (text_font->gdk_font);
2963 text_properties_equal (TextProperty* prop, GdkFont* font, GdkColor *fore, GdkColor *back)
2965 if (prop->flags & PROPERTY_FONT)
2968 GtkTextFont *text_font;
2973 text_font = get_text_font (font);
2975 retval = (prop->font == text_font);
2976 text_font_unref (text_font);
2985 if (prop->flags & PROPERTY_FOREGROUND)
2987 if (!fore || !gdk_color_equal (&prop->fore_color, fore))
2994 if (prop->flags & PROPERTY_BACKGROUND)
2996 if (!back || !gdk_color_equal (&prop->back_color, back))
3007 realize_property (GtkText *text, TextProperty *prop)
3009 GdkColormap *colormap = gtk_widget_get_colormap (GTK_WIDGET (text));
3011 if (prop->flags & PROPERTY_FOREGROUND)
3012 gdk_colormap_alloc_color (colormap, &prop->fore_color, FALSE, FALSE);
3014 if (prop->flags & PROPERTY_BACKGROUND)
3015 gdk_colormap_alloc_color (colormap, &prop->back_color, FALSE, FALSE);
3019 realize_properties (GtkText *text)
3021 GList *tmp_list = text->text_properties;
3025 realize_property (text, tmp_list->data);
3027 tmp_list = tmp_list->next;
3032 unrealize_property (GtkText *text, TextProperty *prop)
3034 GdkColormap *colormap = gtk_widget_get_colormap (GTK_WIDGET (text));
3036 if (prop->flags & PROPERTY_FOREGROUND)
3037 gdk_colormap_free_colors (colormap, &prop->fore_color, 1);
3039 if (prop->flags & PROPERTY_BACKGROUND)
3040 gdk_colormap_free_colors (colormap, &prop->back_color, 1);
3044 unrealize_properties (GtkText *text)
3046 GList *tmp_list = text->text_properties;
3050 unrealize_property (text, tmp_list->data);
3052 tmp_list = tmp_list->next;
3056 static TextProperty*
3057 new_text_property (GtkText *text, GdkFont *font, GdkColor* fore,
3058 GdkColor* back, guint length)
3062 if (text_property_chunk == NULL)
3064 text_property_chunk = g_mem_chunk_new ("text property mem chunk",
3065 sizeof(TextProperty),
3066 1024*sizeof(TextProperty),
3070 prop = g_chunk_new(TextProperty, text_property_chunk);
3075 prop->flags |= PROPERTY_FONT;
3076 prop->font = get_text_font (font);
3083 prop->flags |= PROPERTY_FOREGROUND;
3084 prop->fore_color = *fore;
3089 prop->flags |= PROPERTY_BACKGROUND;
3090 prop->back_color = *back;
3093 prop->length = length;
3095 if (GTK_WIDGET_REALIZED (text))
3096 realize_property (text, prop);
3102 destroy_text_property (TextProperty *prop)
3105 text_font_unref (prop->font);
3107 g_mem_chunk_free (text_property_chunk, prop);
3110 /* Flop the memory between the point and the gap around like a
3113 move_gap (GtkText* text, guint index)
3115 if (text->gap_position < index)
3117 gint diff = index - text->gap_position;
3119 if (text->use_wchar)
3120 g_memmove (text->text.wc + text->gap_position,
3121 text->text.wc + text->gap_position + text->gap_size,
3122 diff*sizeof (GdkWChar));
3124 g_memmove (text->text.ch + text->gap_position,
3125 text->text.ch + text->gap_position + text->gap_size,
3128 text->gap_position = index;
3130 else if (text->gap_position > index)
3132 gint diff = text->gap_position - index;
3134 if (text->use_wchar)
3135 g_memmove (text->text.wc + index + text->gap_size,
3136 text->text.wc + index,
3137 diff*sizeof (GdkWChar));
3139 g_memmove (text->text.ch + index + text->gap_size,
3140 text->text.ch + index,
3143 text->gap_position = index;
3147 /* Increase the gap size. */
3149 make_forward_space (GtkText* text, guint len)
3151 if (text->gap_size < len)
3153 guint sum = MAX(2*len, MIN_GAP_SIZE) + text->text_end;
3155 if (sum >= text->text_len)
3159 while (i <= sum) i <<= 1;
3161 if (text->use_wchar)
3162 text->text.wc = (GdkWChar *)g_realloc(text->text.wc,
3163 i*sizeof(GdkWChar));
3165 text->text.ch = (guchar *)g_realloc(text->text.ch, i);
3169 if (text->use_wchar)
3170 g_memmove (text->text.wc + text->gap_position + text->gap_size + 2*len,
3171 text->text.wc + text->gap_position + text->gap_size,
3172 (text->text_end - (text->gap_position + text->gap_size))
3175 g_memmove (text->text.ch + text->gap_position + text->gap_size + 2*len,
3176 text->text.ch + text->gap_position + text->gap_size,
3177 text->text_end - (text->gap_position + text->gap_size));
3179 text->text_end += len*2;
3180 text->gap_size += len*2;
3184 /* Inserts into the text property list a list element that guarantees
3185 * that for len characters following the point, text has the correct
3186 * property. does not move point. adjusts text_properties_point and
3187 * text_properties_point_offset relative to the current value of
3190 insert_text_property (GtkText* text, GdkFont* font,
3191 GdkColor *fore, GdkColor* back, guint len)
3193 GtkPropertyMark *mark = &text->point;
3194 TextProperty* forward_prop = MARK_CURRENT_PROPERTY(mark);
3195 TextProperty* backward_prop = MARK_PREV_PROPERTY(mark);
3197 if (MARK_OFFSET(mark) == 0)
3199 /* Point is on the boundary of two properties.
3200 * If it is the same as either, grow, else insert
3203 if (text_properties_equal(forward_prop, font, fore, back))
3205 /* Grow the property in front of us. */
3207 MARK_PROPERTY_LENGTH(mark) += len;
3209 else if (backward_prop &&
3210 text_properties_equal(backward_prop, font, fore, back))
3212 /* Grow property behind us, point property and offset
3215 SET_PROPERTY_MARK (&text->point,
3216 MARK_PREV_LIST_PTR (mark),
3217 backward_prop->length);
3219 backward_prop->length += len;
3221 else if ((MARK_NEXT_LIST_PTR(mark) == NULL) &&
3222 (forward_prop->length == 1))
3224 /* Next property just has last position, take it over */
3226 if (GTK_WIDGET_REALIZED (text))
3227 unrealize_property (text, forward_prop);
3229 forward_prop->flags = 0;
3232 forward_prop->flags |= PROPERTY_FONT;
3233 forward_prop->font = get_text_font (font);
3236 forward_prop->font = NULL;
3240 forward_prop->flags |= PROPERTY_FOREGROUND;
3241 forward_prop->fore_color = *fore;
3245 forward_prop->flags |= PROPERTY_BACKGROUND;
3246 forward_prop->back_color = *back;
3248 forward_prop->length += len;
3250 if (GTK_WIDGET_REALIZED (text))
3251 realize_property (text, forward_prop);
3255 /* Splice a new property into the list. */
3257 GList* new_prop = g_list_alloc();
3259 new_prop->next = MARK_LIST_PTR(mark);
3260 new_prop->prev = MARK_PREV_LIST_PTR(mark);
3261 new_prop->next->prev = new_prop;
3264 new_prop->prev->next = new_prop;
3266 new_prop->data = new_text_property (text, font, fore, back, len);
3268 SET_PROPERTY_MARK (mark, new_prop, 0);
3273 /* The following will screw up the line_start cache,
3274 * we'll fix it up in correct_cache_insert
3277 /* In the middle of forward_prop, if properties are equal,
3278 * just add to its length, else split it into two and splice
3280 if (text_properties_equal (forward_prop, font, fore, back))
3282 forward_prop->length += len;
3284 else if ((MARK_NEXT_LIST_PTR(mark) == NULL) &&
3285 (MARK_OFFSET(mark) + 1 == forward_prop->length))
3287 /* Inserting before only the last position in the text */
3290 forward_prop->length -= 1;
3292 new_prop = g_list_alloc();
3293 new_prop->data = new_text_property (text, font, fore, back, len+1);
3294 new_prop->prev = MARK_LIST_PTR(mark);
3295 new_prop->next = NULL;
3296 MARK_NEXT_LIST_PTR(mark) = new_prop;
3298 SET_PROPERTY_MARK (mark, new_prop, 0);
3302 GList* new_prop = g_list_alloc();
3303 GList* new_prop_forward = g_list_alloc();
3304 gint old_length = forward_prop->length;
3305 GList* next = MARK_NEXT_LIST_PTR(mark);
3307 /* Set the new lengths according to where they are split. Construct
3308 * two new properties. */
3309 forward_prop->length = MARK_OFFSET(mark);
3311 new_prop_forward->data =
3312 new_text_property(text,
3313 forward_prop->flags & PROPERTY_FONT ?
3314 forward_prop->font->gdk_font : NULL,
3315 forward_prop->flags & PROPERTY_FOREGROUND ?
3316 &forward_prop->fore_color : NULL,
3317 forward_prop->flags & PROPERTY_BACKGROUND ?
3318 &forward_prop->back_color : NULL,
3319 old_length - forward_prop->length);
3321 new_prop->data = new_text_property(text, font, fore, back, len);
3323 /* Now splice things in. */
3324 MARK_NEXT_LIST_PTR(mark) = new_prop;
3325 new_prop->prev = MARK_LIST_PTR(mark);
3327 new_prop->next = new_prop_forward;
3328 new_prop_forward->prev = new_prop;
3330 new_prop_forward->next = next;
3333 next->prev = new_prop_forward;
3335 SET_PROPERTY_MARK (mark, new_prop, 0);
3339 while (text->text_properties_end->next)
3340 text->text_properties_end = text->text_properties_end->next;
3342 while (text->text_properties->prev)
3343 text->text_properties = text->text_properties->prev;
3347 delete_text_property (GtkText* text, guint nchars)
3349 /* Delete nchars forward from point. */
3351 /* Deleting text properties is problematical, because we
3352 * might be storing around marks pointing to a property.
3354 * The marks in question and how we handle them are:
3356 * point: We know the new value, since it will be at the
3357 * end of the deleted text, and we move it there
3359 * cursor: We just remove the mark and set it equal to the
3360 * point after the operation.
3361 * line-start cache: We replace most affected lines.
3362 * The current line gets used to fetch the new
3363 * lines so, if necessary, (delete at the beginning
3364 * of a line) we fix it up by setting it equal to the
3372 for(; nchars; nchars -= 1)
3374 prop = MARK_CURRENT_PROPERTY(&text->point);
3378 if (prop->length == 0)
3380 tmp = MARK_LIST_PTR (&text->point);
3382 is_first = tmp == text->text_properties;
3384 MARK_LIST_PTR (&text->point) = g_list_remove_link (tmp, tmp);
3385 text->point.offset = 0;
3387 if (GTK_WIDGET_REALIZED (text))
3388 unrealize_property (text, prop);
3390 destroy_text_property (prop);
3391 g_list_free_1 (tmp);
3393 prop = MARK_CURRENT_PROPERTY (&text->point);
3396 text->text_properties = MARK_LIST_PTR (&text->point);
3398 g_assert (prop->length != 0);
3400 else if (prop->length == text->point.offset)
3402 MARK_LIST_PTR (&text->point) = MARK_NEXT_LIST_PTR (&text->point);
3403 text->point.offset = 0;
3407 /* Check to see if we have just the single final position remaining
3408 * along in a property; if so, combine it with the previous property
3410 if (LAST_INDEX (text, text->point) &&
3411 (MARK_OFFSET (&text->point) == 0) &&
3412 (MARK_PREV_LIST_PTR(&text->point) != NULL))
3414 tmp = MARK_LIST_PTR (&text->point);
3415 prop = MARK_CURRENT_PROPERTY(&text->point);
3417 MARK_LIST_PTR (&text->point) = MARK_PREV_LIST_PTR (&text->point);
3418 MARK_CURRENT_PROPERTY(&text->point)->length += 1;
3419 MARK_NEXT_LIST_PTR(&text->point) = NULL;
3421 text->point.offset = MARK_CURRENT_PROPERTY(&text->point)->length - 1;
3423 if (GTK_WIDGET_REALIZED (text))
3424 unrealize_property (text, prop);
3426 destroy_text_property (prop);
3427 g_list_free_1 (tmp);
3432 init_properties (GtkText *text)
3434 if (!text->text_properties)
3436 text->text_properties = g_list_alloc();
3437 text->text_properties->next = NULL;
3438 text->text_properties->prev = NULL;
3439 text->text_properties->data = new_text_property (text, NULL, NULL, NULL, 1);
3440 text->text_properties_end = text->text_properties;
3442 SET_PROPERTY_MARK (&text->point, text->text_properties, 0);
3444 text->point.index = 0;
3449 /**********************************************************************/
3450 /* Property Movement */
3451 /**********************************************************************/
3454 move_mark_n (GtkPropertyMark* mark, gint n)
3457 advance_mark_n(mark, n);
3459 decrement_mark_n(mark, -n);
3463 advance_mark (GtkPropertyMark* mark)
3465 TextProperty* prop = MARK_CURRENT_PROPERTY (mark);
3469 if (prop->length > mark->offset + 1)
3473 mark->property = MARK_NEXT_LIST_PTR (mark);
3479 advance_mark_n (GtkPropertyMark* mark, gint n)
3486 i = 0; /* otherwise it migth not be init. */
3487 prop = MARK_CURRENT_PROPERTY(mark);
3489 if ((prop->length - mark->offset - 1) < n) { /* if we need to change prop. */
3490 /* to make it easier */
3491 n += (mark->offset);
3492 mark->index -= mark->offset;
3494 /* first we take seven-mile-leaps to get to the right text
3496 while ((n-i) > prop->length - 1) {
3498 mark->index += prop->length;
3499 mark->property = MARK_NEXT_LIST_PTR (mark);
3500 prop = MARK_CURRENT_PROPERTY (mark);
3504 /* and then the rest */
3505 mark->index += n - i;
3506 mark->offset += n - i;
3510 decrement_mark (GtkPropertyMark* mark)
3514 if (mark->offset > 0)
3518 mark->property = MARK_PREV_LIST_PTR (mark);
3519 mark->offset = MARK_CURRENT_PROPERTY (mark)->length - 1;
3524 decrement_mark_n (GtkPropertyMark* mark, gint n)
3528 while (mark->offset < n) {
3529 /* jump to end of prev */
3530 n -= mark->offset + 1;
3531 mark->index -= mark->offset + 1;
3532 mark->property = MARK_PREV_LIST_PTR (mark);
3533 mark->offset = MARK_CURRENT_PROPERTY (mark)->length - 1;
3541 static GtkPropertyMark
3542 find_mark (GtkText* text, guint mark_position)
3544 return find_mark_near (text, mark_position, &text->point);
3548 * You can also start from the end, what a drag.
3550 static GtkPropertyMark
3551 find_mark_near (GtkText* text, guint mark_position, const GtkPropertyMark* near)
3556 GtkPropertyMark mark;
3559 diffa = mark_position + 1;
3561 diffa = mark_position - near->index;
3563 diffb = mark_position;
3575 mark.property = text->text_properties;
3579 move_mark_n (&mark, mark_position - mark.index);
3584 /* This routine must be called with scroll == FALSE, only when
3585 * point is at least partially on screen
3589 find_line_containing_point (GtkText* text, guint point,
3595 text->current_line = NULL;
3599 /* Scroll backwards until the point is on screen
3601 while (CACHE_DATA(text->line_start_cache).start.index > point)
3602 scroll_int (text, - LINE_HEIGHT(CACHE_DATA(text->line_start_cache)));
3604 /* Now additionally try to make sure that the point is fully on screen
3608 while (text->first_cut_pixels != 0 &&
3609 text->line_start_cache->next &&
3610 CACHE_DATA(text->line_start_cache->next).start.index > point)
3611 scroll_int (text, - LINE_HEIGHT(CACHE_DATA(text->line_start_cache->next)));
3614 gdk_window_get_size (text->text_area, NULL, &height);
3616 for (cache = text->line_start_cache; cache; cache = cache->next)
3620 if (CACHE_DATA(cache).end.index >= point ||
3621 LAST_INDEX(text, CACHE_DATA(cache).end))
3623 text->current_line = cache; /* LOOK HERE, this proc has an
3624 * important side effect. */
3628 TEXT_SHOW_LINE (text, cache, "cache");
3630 if (cache->next == NULL)
3631 fetch_lines_forward (text, 1);
3635 lph = pixel_height_of (text, cache->next);
3637 /* Scroll the bottom of the line is on screen, or until
3638 * the line is the first onscreen line.
3640 while (cache->next != text->line_start_cache && lph > height)
3642 TEXT_SHOW_LINE (text, cache, "cache");
3643 TEXT_SHOW_LINE (text, cache->next, "cache->next");
3644 scroll_int (text, LINE_HEIGHT(CACHE_DATA(cache->next)));
3645 lph = pixel_height_of (text, cache->next);
3650 g_assert_not_reached (); /* Must set text->current_line here */
3654 pixel_height_of (GtkText* text, GList* cache_line)
3656 gint pixels = - text->first_cut_pixels;
3657 GList *cache = text->line_start_cache;
3660 pixels += LINE_HEIGHT (CACHE_DATA(cache));
3662 if (cache->data == cache_line->data)
3665 cache = cache->next;
3671 /**********************************************************************/
3672 /* Search and Placement */
3673 /**********************************************************************/
3676 find_char_width (GtkText* text, const GtkPropertyMark *mark, const TabStopMark *tab_mark)
3679 gint16* char_widths;
3681 if (LAST_INDEX (text, *mark))
3684 ch = GTK_TEXT_INDEX (text, mark->index);
3685 char_widths = MARK_CURRENT_TEXT_FONT (text, mark)->char_widths;
3689 return tab_mark->to_next_tab * char_widths[' '];
3693 return char_widths[ch];
3697 return gdk_char_width_wc(MARK_CURRENT_TEXT_FONT(text, mark)->gdk_font, ch);
3702 advance_tab_mark (GtkText* text, TabStopMark* tab_mark, GdkWChar ch)
3704 if (tab_mark->to_next_tab == 1 || ch == '\t')
3706 if (tab_mark->tab_stops->next)
3708 tab_mark->tab_stops = tab_mark->tab_stops->next;
3709 tab_mark->to_next_tab = (gulong) tab_mark->tab_stops->data;
3713 tab_mark->to_next_tab = text->default_tab_width;
3718 tab_mark->to_next_tab -= 1;
3723 advance_tab_mark_n (GtkText* text, TabStopMark* tab_mark, gint n)
3727 advance_tab_mark (text, tab_mark, 0);
3731 find_cursor_at_line (GtkText* text, const LineParams* start_line, gint pixel_height)
3734 GtkOldEditable *old_editable = (GtkOldEditable *)text;
3736 GtkPropertyMark mark = start_line->start;
3737 TabStopMark tab_mark = start_line->tab_cont.tab_start;
3738 gint pixel_width = LINE_START_PIXEL (*start_line);
3740 while (mark.index < text->cursor_mark.index)
3742 pixel_width += find_char_width (text, &mark, &tab_mark);
3744 advance_tab_mark (text, &tab_mark, GTK_TEXT_INDEX(text, mark.index));
3745 advance_mark (&mark);
3748 text->cursor_pos_x = pixel_width;
3749 text->cursor_pos_y = pixel_height;
3750 text->cursor_char_offset = start_line->font_descent;
3751 text->cursor_mark = mark;
3753 ch = LAST_INDEX (text, mark) ?
3754 LINE_DELIM : GTK_TEXT_INDEX (text, mark.index);
3756 if ((text->use_wchar) ? gdk_iswspace (ch) : isspace (ch))
3757 text->cursor_char = 0;
3759 text->cursor_char = ch;
3762 if (GTK_WIDGET_HAS_FOCUS(text) && gdk_im_ready() && old_editable->ic &&
3763 (gdk_ic_get_style (old_editable->ic) & GDK_IM_PREEDIT_POSITION))
3765 GdkICAttributesType mask = GDK_IC_SPOT_LOCATION |
3766 GDK_IC_PREEDIT_FOREGROUND |
3767 GDK_IC_PREEDIT_BACKGROUND;
3769 old_editable->ic_attr->spot_location.x = text->cursor_pos_x;
3770 old_editable->ic_attr->spot_location.y
3771 = text->cursor_pos_y - text->cursor_char_offset;
3772 old_editable->ic_attr->preedit_foreground = *MARK_CURRENT_FORE (text, &mark);
3773 old_editable->ic_attr->preedit_background = *MARK_CURRENT_BACK (text, &mark);
3775 if (MARK_CURRENT_FONT (text, &mark)->type == GDK_FONT_FONTSET)
3777 mask |= GDK_IC_PREEDIT_FONTSET;
3778 old_editable->ic_attr->preedit_fontset = MARK_CURRENT_FONT (text, &mark);
3781 gdk_ic_set_attr (old_editable->ic, old_editable->ic_attr, mask);
3787 find_cursor (GtkText* text, gboolean scroll)
3789 if (GTK_WIDGET_REALIZED (text))
3791 find_line_containing_point (text, text->cursor_mark.index, scroll);
3793 if (text->current_line)
3794 find_cursor_at_line (text,
3795 &CACHE_DATA(text->current_line),
3796 pixel_height_of(text, text->current_line));
3799 GTK_OLD_EDITABLE (text)->current_pos = text->cursor_mark.index;
3803 find_mouse_cursor_at_line (GtkText *text, const LineParams* lp,
3804 guint line_pixel_height,
3807 GtkPropertyMark mark = lp->start;
3808 TabStopMark tab_mark = lp->tab_cont.tab_start;
3810 gint char_width = find_char_width(text, &mark, &tab_mark);
3811 gint pixel_width = LINE_START_PIXEL (*lp) + (char_width+1)/2;
3813 text->cursor_pos_y = line_pixel_height;
3817 GdkWChar ch = LAST_INDEX (text, mark) ?
3818 LINE_DELIM : GTK_TEXT_INDEX (text, mark.index);
3820 if (button_x < pixel_width || mark.index == lp->end.index)
3822 text->cursor_pos_x = pixel_width - (char_width+1)/2;
3823 text->cursor_mark = mark;
3824 text->cursor_char_offset = lp->font_descent;
3826 if ((text->use_wchar) ? gdk_iswspace (ch) : isspace (ch))
3827 text->cursor_char = 0;
3829 text->cursor_char = ch;
3834 advance_tab_mark (text, &tab_mark, ch);
3835 advance_mark (&mark);
3837 pixel_width += char_width/2;
3839 char_width = find_char_width (text, &mark, &tab_mark);
3841 pixel_width += (char_width+1)/2;
3846 find_mouse_cursor (GtkText* text, gint x, gint y)
3849 GList* cache = text->line_start_cache;
3853 pixel_height = - text->first_cut_pixels;
3855 for (; cache; cache = cache->next)
3857 pixel_height += LINE_HEIGHT(CACHE_DATA(cache));
3859 if (y < pixel_height || !cache->next)
3861 find_mouse_cursor_at_line (text, &CACHE_DATA(cache), pixel_height, x);
3863 find_cursor (text, FALSE);
3870 /**********************************************************************/
3872 /**********************************************************************/
3875 free_cache (GtkText* text)
3877 GList* cache = text->line_start_cache;
3882 cache = cache->prev;
3884 text->line_start_cache = cache;
3887 for (; cache; cache = cache->next)
3888 g_mem_chunk_free (params_mem_chunk, cache->data);
3890 g_list_free (text->line_start_cache);
3892 text->line_start_cache = NULL;
3896 remove_cache_line (GtkText* text, GList* member)
3903 if (member == text->line_start_cache)
3904 text->line_start_cache = text->line_start_cache->next;
3907 member->prev->next = member->next;
3910 member->next->prev = member->prev;
3912 list = member->next;
3914 g_mem_chunk_free (params_mem_chunk, member->data);
3915 g_list_free_1 (member);
3920 /**********************************************************************/
3922 /**********************************************************************/
3925 move_cursor_buffer_ver (GtkText *text, int dir)
3927 undraw_cursor (text, FALSE);
3931 scroll_int (text, text->vadj->upper);
3932 text->cursor_mark = find_this_line_start_mark (text,
3934 &text->cursor_mark);
3938 scroll_int (text, - text->vadj->value);
3939 text->cursor_mark = find_this_line_start_mark (text,
3941 &text->cursor_mark);
3944 find_cursor (text, TRUE);
3945 draw_cursor (text, FALSE);
3949 move_cursor_page_ver (GtkText *text, int dir)
3951 scroll_int (text, dir * text->vadj->page_increment);
3955 move_cursor_ver (GtkText *text, int count)
3958 GtkPropertyMark mark;
3961 mark = find_this_line_start_mark (text, text->cursor_mark.index, &text->cursor_mark);
3962 offset = text->cursor_mark.index - mark.index;
3964 if (offset > text->cursor_virtual_x)
3965 text->cursor_virtual_x = offset;
3969 if (mark.index == 0)
3972 decrement_mark (&mark);
3973 mark = find_this_line_start_mark (text, mark.index, &mark);
3977 mark = text->cursor_mark;
3979 while (!LAST_INDEX(text, mark) && GTK_TEXT_INDEX(text, mark.index) != LINE_DELIM)
3980 advance_mark (&mark);
3982 if (LAST_INDEX(text, mark))
3985 advance_mark (&mark);
3988 for (i=0; i < text->cursor_virtual_x; i += 1, advance_mark(&mark))
3989 if (LAST_INDEX(text, mark) ||
3990 GTK_TEXT_INDEX(text, mark.index) == LINE_DELIM)
3993 undraw_cursor (text, FALSE);
3995 text->cursor_mark = mark;
3997 find_cursor (text, TRUE);
3999 draw_cursor (text, FALSE);
4003 move_cursor_hor (GtkText *text, int count)
4005 /* count should be +-1. */
4006 if ( (count > 0 && text->cursor_mark.index + count > TEXT_LENGTH(text)) ||
4007 (count < 0 && text->cursor_mark.index < (- count)) ||
4011 text->cursor_virtual_x = 0;
4013 undraw_cursor (text, FALSE);
4015 move_mark_n (&text->cursor_mark, count);
4017 find_cursor (text, TRUE);
4019 draw_cursor (text, FALSE);
4023 gtk_text_move_cursor (GtkOldEditable *old_editable,
4030 move_cursor_hor (GTK_TEXT (old_editable), 1);
4035 move_cursor_hor (GTK_TEXT (old_editable), -1);
4041 move_cursor_ver (GTK_TEXT (old_editable), 1);
4046 move_cursor_ver (GTK_TEXT (old_editable), -1);
4051 gtk_text_move_forward_character (GtkText *text)
4053 move_cursor_hor (text, 1);
4057 gtk_text_move_backward_character (GtkText *text)
4059 move_cursor_hor (text, -1);
4063 gtk_text_move_next_line (GtkText *text)
4065 move_cursor_ver (text, 1);
4069 gtk_text_move_previous_line (GtkText *text)
4071 move_cursor_ver (text, -1);
4075 gtk_text_move_word (GtkOldEditable *old_editable,
4081 gtk_text_move_forward_word (GTK_TEXT (old_editable));
4086 gtk_text_move_backward_word (GTK_TEXT (old_editable));
4091 gtk_text_move_forward_word (GtkText *text)
4093 text->cursor_virtual_x = 0;
4095 undraw_cursor (text, FALSE);
4097 if (text->use_wchar)
4099 while (!LAST_INDEX (text, text->cursor_mark) &&
4100 !gdk_iswalnum (GTK_TEXT_INDEX(text, text->cursor_mark.index)))
4101 advance_mark (&text->cursor_mark);
4103 while (!LAST_INDEX (text, text->cursor_mark) &&
4104 gdk_iswalnum (GTK_TEXT_INDEX(text, text->cursor_mark.index)))
4105 advance_mark (&text->cursor_mark);
4109 while (!LAST_INDEX (text, text->cursor_mark) &&
4110 !isalnum (GTK_TEXT_INDEX(text, text->cursor_mark.index)))
4111 advance_mark (&text->cursor_mark);
4113 while (!LAST_INDEX (text, text->cursor_mark) &&
4114 isalnum (GTK_TEXT_INDEX(text, text->cursor_mark.index)))
4115 advance_mark (&text->cursor_mark);
4118 find_cursor (text, TRUE);
4119 draw_cursor (text, FALSE);
4123 gtk_text_move_backward_word (GtkText *text)
4125 text->cursor_virtual_x = 0;
4127 undraw_cursor (text, FALSE);
4129 if (text->use_wchar)
4131 while ((text->cursor_mark.index > 0) &&
4132 !gdk_iswalnum (GTK_TEXT_INDEX(text, text->cursor_mark.index-1)))
4133 decrement_mark (&text->cursor_mark);
4135 while ((text->cursor_mark.index > 0) &&
4136 gdk_iswalnum (GTK_TEXT_INDEX(text, text->cursor_mark.index-1)))
4137 decrement_mark (&text->cursor_mark);
4141 while ((text->cursor_mark.index > 0) &&
4142 !isalnum (GTK_TEXT_INDEX(text, text->cursor_mark.index-1)))
4143 decrement_mark (&text->cursor_mark);
4145 while ((text->cursor_mark.index > 0) &&
4146 isalnum (GTK_TEXT_INDEX(text, text->cursor_mark.index-1)))
4147 decrement_mark (&text->cursor_mark);
4150 find_cursor (text, TRUE);
4151 draw_cursor (text, FALSE);
4155 gtk_text_move_page (GtkOldEditable *old_editable,
4160 scroll_int (GTK_TEXT (old_editable),
4161 y * GTK_TEXT(old_editable)->vadj->page_increment);
4165 gtk_text_move_to_row (GtkOldEditable *old_editable,
4171 gtk_text_move_to_column (GtkOldEditable *old_editable,
4176 text = GTK_TEXT (old_editable);
4178 text->cursor_virtual_x = 0; /* FIXME */
4180 undraw_cursor (text, FALSE);
4182 /* Move to the beginning of the line */
4183 while ((text->cursor_mark.index > 0) &&
4184 (GTK_TEXT_INDEX (text, text->cursor_mark.index - 1) != LINE_DELIM))
4185 decrement_mark (&text->cursor_mark);
4187 while (!LAST_INDEX (text, text->cursor_mark) &&
4188 (GTK_TEXT_INDEX (text, text->cursor_mark.index) != LINE_DELIM))
4192 else if (column == 0)
4195 advance_mark (&text->cursor_mark);
4198 find_cursor (text, TRUE);
4199 draw_cursor (text, FALSE);
4203 gtk_text_move_beginning_of_line (GtkText *text)
4205 gtk_text_move_to_column (GTK_OLD_EDITABLE (text), 0);
4210 gtk_text_move_end_of_line (GtkText *text)
4212 gtk_text_move_to_column (GTK_OLD_EDITABLE (text), -1);
4216 gtk_text_kill_char (GtkOldEditable *old_editable,
4221 text = GTK_TEXT (old_editable);
4223 if (old_editable->selection_start_pos != old_editable->selection_end_pos)
4224 gtk_editable_delete_selection (GTK_EDITABLE (old_editable));
4229 if (text->point.index + 1 <= TEXT_LENGTH (text))
4230 gtk_editable_delete_text (GTK_EDITABLE (old_editable), text->point.index, text->point.index + 1);
4234 if (text->point.index > 0)
4235 gtk_editable_delete_text (GTK_EDITABLE (old_editable), text->point.index - 1, text->point.index);
4241 gtk_text_delete_forward_character (GtkText *text)
4243 gtk_text_kill_char (GTK_OLD_EDITABLE (text), 1);
4247 gtk_text_delete_backward_character (GtkText *text)
4249 gtk_text_kill_char (GTK_OLD_EDITABLE (text), -1);
4253 gtk_text_kill_word (GtkOldEditable *old_editable,
4256 if (old_editable->selection_start_pos != old_editable->selection_end_pos)
4257 gtk_editable_delete_selection (GTK_EDITABLE (old_editable));
4260 gint old_pos = old_editable->current_pos;
4263 gtk_text_move_word (old_editable, 1);
4264 gtk_editable_delete_text (GTK_EDITABLE (old_editable), old_pos, old_editable->current_pos);
4268 gtk_text_move_word (old_editable, -1);
4269 gtk_editable_delete_text (GTK_EDITABLE (old_editable), old_editable->current_pos, old_pos);
4275 gtk_text_delete_forward_word (GtkText *text)
4277 gtk_text_kill_word (GTK_OLD_EDITABLE (text), 1);
4281 gtk_text_delete_backward_word (GtkText *text)
4283 gtk_text_kill_word (GTK_OLD_EDITABLE (text), -1);
4287 gtk_text_kill_line (GtkOldEditable *old_editable,
4290 gint old_pos = old_editable->current_pos;
4293 gtk_text_move_to_column (old_editable, -1);
4294 gtk_editable_delete_text (GTK_EDITABLE (old_editable), old_pos, old_editable->current_pos);
4298 gtk_text_move_to_column (old_editable, 0);
4299 gtk_editable_delete_text (GTK_EDITABLE (old_editable), old_editable->current_pos, old_pos);
4304 gtk_text_delete_line (GtkText *text)
4306 gtk_text_move_to_column (GTK_OLD_EDITABLE (text), 0);
4307 gtk_text_kill_line (GTK_OLD_EDITABLE (text), 1);
4311 gtk_text_delete_to_line_end (GtkText *text)
4313 gtk_text_kill_line (GTK_OLD_EDITABLE (text), 1);
4317 gtk_text_select_word (GtkText *text, guint32 time)
4322 GtkOldEditable *old_editable;
4323 old_editable = GTK_OLD_EDITABLE (text);
4325 gtk_text_move_backward_word (text);
4326 start_pos = text->cursor_mark.index;
4328 gtk_text_move_forward_word (text);
4329 end_pos = text->cursor_mark.index;
4331 old_editable->has_selection = TRUE;
4332 gtk_text_set_selection (old_editable, start_pos, end_pos);
4333 gtk_old_editable_claim_selection (old_editable, start_pos != end_pos, time);
4337 gtk_text_select_line (GtkText *text, guint32 time)
4342 GtkOldEditable *old_editable;
4343 old_editable = GTK_OLD_EDITABLE (text);
4345 gtk_text_move_beginning_of_line (text);
4346 start_pos = text->cursor_mark.index;
4348 gtk_text_move_end_of_line (text);
4349 gtk_text_move_forward_character (text);
4350 end_pos = text->cursor_mark.index;
4352 old_editable->has_selection = TRUE;
4353 gtk_text_set_selection (old_editable, start_pos, end_pos);
4354 gtk_old_editable_claim_selection (old_editable, start_pos != end_pos, time);
4357 /**********************************************************************/
4359 /**********************************************************************/
4362 adjust_adj (GtkText* text, GtkAdjustment* adj)
4366 gdk_window_get_size (text->text_area, NULL, &height);
4368 adj->step_increment = MIN (adj->upper, (float) SCROLL_PIXELS);
4369 adj->page_increment = MIN (adj->upper, height - (float) KEY_SCROLL_PIXELS);
4370 adj->page_size = MIN (adj->upper, height);
4371 adj->value = MIN (adj->value, adj->upper - adj->page_size);
4372 adj->value = MAX (adj->value, 0.0);
4374 gtk_signal_emit_by_name (GTK_OBJECT (adj), "changed");
4378 set_vertical_scroll_iterator (GtkText* text, LineParams* lp, void* data)
4380 SetVerticalScrollData *svdata = (SetVerticalScrollData *) data;
4382 if ((text->first_line_start_index >= lp->start.index) &&
4383 (text->first_line_start_index <= lp->end.index))
4385 svdata->mark = lp->start;
4387 if (text->first_line_start_index == lp->start.index)
4389 text->first_onscreen_ver_pixel = svdata->pixel_height + text->first_cut_pixels;
4393 text->first_onscreen_ver_pixel = svdata->pixel_height;
4394 text->first_cut_pixels = 0;
4397 text->vadj->value = (float) text->first_onscreen_ver_pixel;
4400 svdata->pixel_height += LINE_HEIGHT (*lp);
4406 set_vertical_scroll_find_iterator (GtkText* text, LineParams* lp, void* data)
4408 SetVerticalScrollData *svdata = (SetVerticalScrollData *) data;
4411 if (svdata->pixel_height <= (gint) text->vadj->value &&
4412 svdata->pixel_height + LINE_HEIGHT(*lp) > (gint) text->vadj->value)
4414 svdata->mark = lp->start;
4416 text->first_cut_pixels = (gint)text->vadj->value - svdata->pixel_height;
4417 text->first_onscreen_ver_pixel = svdata->pixel_height;
4418 text->first_line_start_index = lp->start.index;
4424 svdata->pixel_height += LINE_HEIGHT (*lp);
4432 static GtkPropertyMark
4433 set_vertical_scroll (GtkText* text)
4435 GtkPropertyMark mark = find_mark (text, 0);
4436 SetVerticalScrollData data;
4440 data.pixel_height = 0;
4441 line_params_iterate (text, &mark, NULL, FALSE, &data, set_vertical_scroll_iterator);
4443 text->vadj->upper = (float) data.pixel_height;
4444 orig_value = (gint) text->vadj->value;
4446 gdk_window_get_size (text->text_area, NULL, &height);
4448 text->vadj->step_increment = MIN (text->vadj->upper, (float) SCROLL_PIXELS);
4449 text->vadj->page_increment = MIN (text->vadj->upper, height - (float) KEY_SCROLL_PIXELS);
4450 text->vadj->page_size = MIN (text->vadj->upper, height);
4451 text->vadj->value = MIN (text->vadj->value, text->vadj->upper - text->vadj->page_size);
4452 text->vadj->value = MAX (text->vadj->value, 0.0);
4454 text->last_ver_value = (gint)text->vadj->value;
4456 gtk_signal_emit_by_name (GTK_OBJECT (text->vadj), "changed");
4458 if (text->vadj->value != orig_value)
4460 /* We got clipped, and don't really know which line to put first. */
4461 data.pixel_height = 0;
4462 data.last_didnt_wrap = TRUE;
4464 line_params_iterate (text, &mark, NULL,
4466 set_vertical_scroll_find_iterator);
4473 scroll_int (GtkText* text, gint diff)
4477 text->vadj->value += diff;
4479 upper = text->vadj->upper - text->vadj->page_size;
4480 text->vadj->value = MIN (text->vadj->value, upper);
4481 text->vadj->value = MAX (text->vadj->value, 0.0);
4483 gtk_signal_emit_by_name (GTK_OBJECT (text->vadj), "value_changed");
4487 process_exposes (GtkText *text)
4491 /* Make sure graphics expose events are processed before scrolling
4494 while ((event = gdk_event_get_graphics_expose (text->text_area)) != NULL)
4496 gtk_widget_event (GTK_WIDGET (text), event);
4497 if (event->expose.count == 0)
4499 gdk_event_free (event);
4502 gdk_event_free (event);
4506 static gint last_visible_line_height (GtkText* text)
4508 GList *cache = text->line_start_cache;
4511 gdk_window_get_size (text->text_area, NULL, &height);
4513 for (; cache->next; cache = cache->next)
4514 if (pixel_height_of(text, cache->next) > height)
4518 return pixel_height_of(text, cache) - 1;
4523 static gint first_visible_line_height (GtkText* text)
4525 if (text->first_cut_pixels)
4526 return pixel_height_of(text, text->line_start_cache) + 1;
4532 scroll_down (GtkText* text, gint diff0)
4538 text->first_onscreen_ver_pixel += diff0;
4542 g_assert (text->line_start_cache);
4544 if (text->first_cut_pixels < LINE_HEIGHT(CACHE_DATA(text->line_start_cache)) - 1)
4546 text->first_cut_pixels += 1;
4550 text->first_cut_pixels = 0;
4552 text->line_start_cache = text->line_start_cache->next;
4554 text->first_line_start_index =
4555 CACHE_DATA(text->line_start_cache).start.index;
4557 if (!text->line_start_cache->next)
4558 fetch_lines_forward (text, 1);
4564 gdk_window_get_size (text->text_area, &width, &height);
4565 if (height > real_diff)
4566 gdk_draw_pixmap (text->text_area,
4574 height - real_diff);
4577 rect.y = MAX (0, height - real_diff);
4579 rect.height = MIN (height, real_diff);
4581 expose_text (text, &rect, FALSE);
4582 gtk_text_draw_focus ( (GtkWidget *) text);
4584 if (text->current_line)
4588 text->cursor_pos_y -= real_diff;
4589 cursor_min = drawn_cursor_min(text);
4592 find_mouse_cursor (text, text->cursor_pos_x,
4593 first_visible_line_height (text));
4596 if (height > real_diff)
4597 process_exposes (text);
4601 scroll_up (GtkText* text, gint diff0)
4607 text->first_onscreen_ver_pixel += diff0;
4611 g_assert (text->line_start_cache);
4613 if (text->first_cut_pixels > 0)
4615 text->first_cut_pixels -= 1;
4619 if (!text->line_start_cache->prev)
4620 fetch_lines_backward (text);
4622 text->line_start_cache = text->line_start_cache->prev;
4624 text->first_line_start_index =
4625 CACHE_DATA(text->line_start_cache).start.index;
4627 text->first_cut_pixels = LINE_HEIGHT(CACHE_DATA(text->line_start_cache)) - 1;
4633 gdk_window_get_size (text->text_area, &width, &height);
4634 if (height > real_diff)
4635 gdk_draw_pixmap (text->text_area,
4643 height - real_diff);
4648 rect.height = MIN (height, real_diff);
4650 expose_text (text, &rect, FALSE);
4651 gtk_text_draw_focus ( (GtkWidget *) text);
4653 if (text->current_line)
4658 text->cursor_pos_y += real_diff;
4659 cursor_max = drawn_cursor_max(text);
4660 gdk_window_get_size (text->text_area, NULL, &height);
4662 if (cursor_max >= height)
4663 find_mouse_cursor (text, text->cursor_pos_x,
4664 last_visible_line_height (text));
4667 if (height > real_diff)
4668 process_exposes (text);
4671 /**********************************************************************/
4673 /**********************************************************************/
4675 /* Assumes mark starts a line. Calculates the height, width, and
4676 * displayable character count of a single DISPLAYABLE line. That
4677 * means that in line-wrap mode, this does may not compute the
4678 * properties of an entire line. */
4680 find_line_params (GtkText* text,
4681 const GtkPropertyMark* mark,
4682 const PrevTabCont *tab_cont,
4683 PrevTabCont *next_cont)
4686 TabStopMark tab_mark = tab_cont->tab_start;
4687 guint max_display_pixels;
4692 gdk_window_get_size (text->text_area, (gint*) &max_display_pixels, NULL);
4693 max_display_pixels -= LINE_WRAP_ROOM;
4696 lp.tab_cont = *tab_cont;
4699 lp.pixel_width = tab_cont->pixel_offset;
4700 lp.displayable_chars = 0;
4702 lp.font_descent = 0;
4704 init_tab_cont (text, next_cont);
4706 while (!LAST_INDEX(text, lp.end))
4708 g_assert (lp.end.property);
4710 ch = GTK_TEXT_INDEX (text, lp.end.index);
4711 font = MARK_CURRENT_FONT (text, &lp.end);
4713 if (ch == LINE_DELIM)
4715 /* Newline doesn't count in computation of line height, even
4716 * if its in a bigger font than the rest of the line. Unless,
4717 * of course, there are no other characters. */
4719 if (!lp.font_ascent && !lp.font_descent)
4721 lp.font_ascent = font->ascent;
4722 lp.font_descent = font->descent;
4725 lp.tab_cont_next = *next_cont;
4730 ch_width = find_char_width (text, &lp.end, &tab_mark);
4732 if ((ch_width + lp.pixel_width > max_display_pixels) &&
4733 (lp.end.index > lp.start.index))
4737 if (text->line_wrap)
4739 next_cont->tab_start = tab_mark;
4740 next_cont->pixel_offset = 0;
4744 /* Here's the tough case, a tab is wrapping. */
4745 gint pixels_avail = max_display_pixels - lp.pixel_width;
4746 gint space_width = MARK_CURRENT_TEXT_FONT(text, &lp.end)->char_widths[' '];
4747 gint spaces_avail = pixels_avail / space_width;
4749 if (spaces_avail == 0)
4751 decrement_mark (&lp.end);
4755 advance_tab_mark (text, &next_cont->tab_start, '\t');
4756 next_cont->pixel_offset = space_width * (tab_mark.to_next_tab -
4758 lp.displayable_chars += 1;
4763 if (text->word_wrap)
4765 GtkPropertyMark saved_mark = lp.end;
4766 guint saved_characters = lp.displayable_chars;
4768 lp.displayable_chars += 1;
4770 if (text->use_wchar)
4772 while (!gdk_iswspace (GTK_TEXT_INDEX (text, lp.end.index)) &&
4773 (lp.end.index > lp.start.index))
4775 decrement_mark (&lp.end);
4776 lp.displayable_chars -= 1;
4781 while (!isspace(GTK_TEXT_INDEX (text, lp.end.index)) &&
4782 (lp.end.index > lp.start.index))
4784 decrement_mark (&lp.end);
4785 lp.displayable_chars -= 1;
4789 /* If whole line is one word, revert to char wrapping */
4790 if (lp.end.index == lp.start.index)
4792 lp.end = saved_mark;
4793 lp.displayable_chars = saved_characters;
4794 decrement_mark (&lp.end);
4799 /* Don't include this character, it will wrap. */
4800 decrement_mark (&lp.end);
4804 lp.tab_cont_next = *next_cont;
4811 lp.displayable_chars += 1;
4814 lp.font_ascent = MAX (font->ascent, lp.font_ascent);
4815 lp.font_descent = MAX (font->descent, lp.font_descent);
4816 lp.pixel_width += ch_width;
4818 advance_mark(&lp.end);
4819 advance_tab_mark (text, &tab_mark, ch);
4822 if (LAST_INDEX(text, lp.start))
4824 /* Special case, empty last line. */
4825 font = MARK_CURRENT_FONT (text, &lp.end);
4827 lp.font_ascent = font->ascent;
4828 lp.font_descent = font->descent;
4831 lp.tab_cont_next = *next_cont;
4837 expand_scratch_buffer (GtkText* text, guint len)
4839 if (len >= text->scratch_buffer_len)
4843 while (i <= len && i < MIN_GAP_SIZE) i <<= 1;
4845 if (text->use_wchar)
4847 if (text->scratch_buffer.wc)
4848 text->scratch_buffer.wc = g_new (GdkWChar, i);
4850 text->scratch_buffer.wc = g_realloc (text->scratch_buffer.wc,
4851 i*sizeof (GdkWChar));
4855 if (text->scratch_buffer.ch)
4856 text->scratch_buffer.ch = g_new (guchar, i);
4858 text->scratch_buffer.ch = g_realloc (text->scratch_buffer.ch, i);
4861 text->scratch_buffer_len = i;
4865 /* Side effect: modifies text->gc
4868 draw_bg_rect (GtkText* text, GtkPropertyMark *mark,
4869 gint x, gint y, gint width, gint height,
4870 gboolean already_cleared)
4872 GtkOldEditable *old_editable = GTK_OLD_EDITABLE (text);
4874 if ((mark->index >= MIN(old_editable->selection_start_pos, old_editable->selection_end_pos) &&
4875 mark->index < MAX(old_editable->selection_start_pos, old_editable->selection_end_pos)))
4877 gtk_paint_flat_box(GTK_WIDGET(text)->style, text->text_area,
4878 old_editable->has_selection ?
4879 GTK_STATE_SELECTED : GTK_STATE_ACTIVE,
4881 NULL, GTK_WIDGET(text), "text",
4882 x, y, width, height);
4884 else if (!gdk_color_equal(MARK_CURRENT_BACK (text, mark),
4885 >K_WIDGET(text)->style->base[GTK_WIDGET_STATE (text)]))
4887 gdk_gc_set_foreground (text->gc, MARK_CURRENT_BACK (text, mark));
4889 gdk_draw_rectangle (text->text_area,
4891 TRUE, x, y, width, height);
4893 else if (GTK_WIDGET (text)->style->bg_pixmap[GTK_STATE_NORMAL])
4900 rect.height = height;
4902 clear_area (text, &rect);
4904 else if (!already_cleared)
4905 gdk_window_clear_area (text->text_area, x, y, width, height);
4909 draw_line (GtkText* text,
4910 gint pixel_start_height,
4913 GdkGCValues gc_values;
4916 guint running_offset = lp->tab_cont.pixel_offset;
4917 union { GdkWChar *wc; guchar *ch; } buffer;
4920 GtkOldEditable *old_editable = GTK_OLD_EDITABLE (text);
4922 guint selection_start_pos = MIN (old_editable->selection_start_pos, old_editable->selection_end_pos);
4923 guint selection_end_pos = MAX (old_editable->selection_start_pos, old_editable->selection_end_pos);
4925 GtkPropertyMark mark = lp->start;
4926 TabStopMark tab_mark = lp->tab_cont.tab_start;
4927 gint pixel_height = pixel_start_height + lp->font_ascent;
4928 guint chars = lp->displayable_chars;
4930 /* First provide a contiguous segment of memory. This makes reading
4931 * the code below *much* easier, and only incurs the cost of copying
4932 * when the line being displayed spans the gap. */
4933 if (mark.index <= text->gap_position &&
4934 mark.index + chars > text->gap_position)
4936 expand_scratch_buffer (text, chars);
4938 if (text->use_wchar)
4940 for (i = 0; i < chars; i += 1)
4941 text->scratch_buffer.wc[i] = GTK_TEXT_INDEX(text, mark.index + i);
4942 buffer.wc = text->scratch_buffer.wc;
4946 for (i = 0; i < chars; i += 1)
4947 text->scratch_buffer.ch[i] = GTK_TEXT_INDEX(text, mark.index + i);
4948 buffer.ch = text->scratch_buffer.ch;
4953 if (text->use_wchar)
4955 if (mark.index >= text->gap_position)
4956 buffer.wc = text->text.wc + mark.index + text->gap_size;
4958 buffer.wc = text->text.wc + mark.index;
4962 if (mark.index >= text->gap_position)
4963 buffer.ch = text->text.ch + mark.index + text->gap_size;
4965 buffer.ch = text->text.ch + mark.index;
4970 if (running_offset > 0)
4972 draw_bg_rect (text, &mark, 0, pixel_start_height, running_offset,
4973 LINE_HEIGHT (*lp), TRUE);
4979 if ((text->use_wchar && buffer.wc[0] != '\t') ||
4980 (!text->use_wchar && buffer.ch[0] != '\t'))
4982 union { GdkWChar *wc; guchar *ch; } next_tab;
4987 if (text->use_wchar)
4988 for (i=0; i<chars; i++)
4990 if (buffer.wc[i] == '\t')
4992 next_tab.wc = buffer.wc + i;
4997 next_tab.ch = memchr (buffer.ch, '\t', chars);
4999 len = MIN (MARK_CURRENT_PROPERTY (&mark)->length - mark.offset, chars);
5001 if (text->use_wchar)
5004 len = MIN (len, next_tab.wc - buffer.wc);
5009 len = MIN (len, next_tab.ch - buffer.ch);
5012 if (mark.index < selection_start_pos)
5013 len = MIN (len, selection_start_pos - mark.index);
5014 else if (mark.index < selection_end_pos)
5015 len = MIN (len, selection_end_pos - mark.index);
5017 font = MARK_CURRENT_FONT (text, &mark);
5018 if (font->type == GDK_FONT_FONT)
5020 gdk_gc_set_font (text->gc, font);
5021 gdk_gc_get_values (text->gc, &gc_values);
5022 if (text->use_wchar)
5023 pixel_width = gdk_text_width_wc (gc_values.font,
5026 pixel_width = gdk_text_width (gc_values.font,
5031 if (text->use_wchar)
5032 pixel_width = gdk_text_width_wc (font, buffer.wc, len);
5034 pixel_width = gdk_text_width (font, buffer.ch, len);
5037 draw_bg_rect (text, &mark, running_offset, pixel_start_height,
5038 pixel_width, LINE_HEIGHT (*lp), TRUE);
5040 if ((mark.index >= selection_start_pos) &&
5041 (mark.index < selection_end_pos))
5043 if (old_editable->has_selection)
5044 fg_gc = GTK_WIDGET(text)->style->fg_gc[GTK_STATE_SELECTED];
5046 fg_gc = GTK_WIDGET(text)->style->fg_gc[GTK_STATE_ACTIVE];
5050 gdk_gc_set_foreground (text->gc, MARK_CURRENT_FORE (text, &mark));
5054 if (text->use_wchar)
5055 gdk_draw_text_wc (text->text_area, MARK_CURRENT_FONT (text, &mark),
5062 gdk_draw_text (text->text_area, MARK_CURRENT_FONT (text, &mark),
5069 running_offset += pixel_width;
5071 advance_tab_mark_n (text, &tab_mark, len);
5075 gint pixels_remaining;
5081 gdk_window_get_size (text->text_area, &pixels_remaining, NULL);
5082 pixels_remaining -= (LINE_WRAP_ROOM + running_offset);
5084 space_width = MARK_CURRENT_TEXT_FONT(text, &mark)->char_widths[' '];
5086 spaces_avail = pixels_remaining / space_width;
5087 spaces_avail = MIN (spaces_avail, tab_mark.to_next_tab);
5089 draw_bg_rect (text, &mark, running_offset, pixel_start_height,
5090 spaces_avail * space_width, LINE_HEIGHT (*lp), TRUE);
5092 running_offset += tab_mark.to_next_tab *
5093 MARK_CURRENT_TEXT_FONT(text, &mark)->char_widths[' '];
5095 advance_tab_mark (text, &tab_mark, '\t');
5098 advance_mark_n (&mark, len);
5099 if (text->use_wchar)
5108 draw_line_wrap (GtkText* text, guint height /* baseline height */)
5115 if (text->line_wrap)
5117 bitmap = text->line_wrap_bitmap;
5118 bitmap_width = line_wrap_width;
5119 bitmap_height = line_wrap_height;
5123 bitmap = text->line_arrow_bitmap;
5124 bitmap_width = line_arrow_width;
5125 bitmap_height = line_arrow_height;
5128 gdk_window_get_size (text->text_area, &width, NULL);
5129 width -= LINE_WRAP_ROOM;
5131 gdk_gc_set_stipple (text->gc,
5134 gdk_gc_set_fill (text->gc, GDK_STIPPLED);
5136 gdk_gc_set_foreground (text->gc, >K_WIDGET (text)->style->text[GTK_STATE_NORMAL]);
5138 gdk_gc_set_ts_origin (text->gc,
5140 height - bitmap_height - 1);
5142 gdk_draw_rectangle (text->text_area,
5146 height - bitmap_height - 1 /* one pixel above the baseline. */,
5150 gdk_gc_set_ts_origin (text->gc, 0, 0);
5152 gdk_gc_set_fill (text->gc, GDK_SOLID);
5156 undraw_cursor (GtkText* text, gint absolute)
5158 GtkOldEditable *old_editable = (GtkOldEditable *) text;
5160 TDEBUG (("in undraw_cursor\n"));
5163 text->cursor_drawn_level = 0;
5165 if ((text->cursor_drawn_level ++ == 0) &&
5166 (old_editable->selection_start_pos == old_editable->selection_end_pos) &&
5167 GTK_WIDGET_DRAWABLE (text) && text->line_start_cache)
5171 g_assert(text->cursor_mark.property);
5173 font = MARK_CURRENT_FONT(text, &text->cursor_mark);
5175 draw_bg_rect (text, &text->cursor_mark,
5177 text->cursor_pos_y - text->cursor_char_offset - font->ascent,
5178 1, font->ascent + 1, FALSE);
5180 if (text->cursor_char)
5182 if (font->type == GDK_FONT_FONT)
5183 gdk_gc_set_font (text->gc, font);
5185 gdk_gc_set_foreground (text->gc, MARK_CURRENT_FORE (text, &text->cursor_mark));
5187 gdk_draw_text_wc (text->text_area, font,
5190 text->cursor_pos_y - text->cursor_char_offset,
5198 drawn_cursor_min (GtkText* text)
5202 g_assert(text->cursor_mark.property);
5204 font = MARK_CURRENT_FONT(text, &text->cursor_mark);
5206 return text->cursor_pos_y - text->cursor_char_offset - font->ascent;
5210 drawn_cursor_max (GtkText* text)
5214 g_assert(text->cursor_mark.property);
5216 font = MARK_CURRENT_FONT(text, &text->cursor_mark);
5218 return text->cursor_pos_y - text->cursor_char_offset;
5222 draw_cursor (GtkText* text, gint absolute)
5224 GtkOldEditable *old_editable = (GtkOldEditable *)text;
5226 TDEBUG (("in draw_cursor\n"));
5229 text->cursor_drawn_level = 1;
5231 if ((--text->cursor_drawn_level == 0) &&
5232 old_editable->editable &&
5233 (old_editable->selection_start_pos == old_editable->selection_end_pos) &&
5234 GTK_WIDGET_DRAWABLE (text) && text->line_start_cache)
5238 g_assert (text->cursor_mark.property);
5240 font = MARK_CURRENT_FONT (text, &text->cursor_mark);
5242 gdk_gc_set_foreground (text->gc, >K_WIDGET (text)->style->text[GTK_STATE_NORMAL]);
5244 gdk_draw_line (text->text_area, text->gc, text->cursor_pos_x,
5245 text->cursor_pos_y - text->cursor_char_offset,
5247 text->cursor_pos_y - text->cursor_char_offset - font->ascent);
5252 create_bg_gc (GtkText *text)
5256 values.tile = GTK_WIDGET (text)->style->bg_pixmap[GTK_STATE_NORMAL];
5257 values.fill = GDK_TILED;
5259 return gdk_gc_new_with_values (text->text_area, &values,
5260 GDK_GC_FILL | GDK_GC_TILE);
5264 clear_area (GtkText *text, GdkRectangle *area)
5266 GtkWidget *widget = GTK_WIDGET (text);
5272 gdk_window_get_size (widget->style->bg_pixmap[GTK_STATE_NORMAL], &width, &height);
5274 gdk_gc_set_ts_origin (text->bg_gc,
5275 (- text->first_onscreen_hor_pixel) % width,
5276 (- text->first_onscreen_ver_pixel) % height);
5278 gdk_draw_rectangle (text->text_area, text->bg_gc, TRUE,
5279 area->x, area->y, area->width, area->height);
5282 gdk_window_clear_area (text->text_area, area->x, area->y, area->width, area->height);
5286 expose_text (GtkText* text, GdkRectangle *area, gboolean cursor)
5288 GList *cache = text->line_start_cache;
5289 gint pixels = - text->first_cut_pixels;
5290 gint min_y = MAX (0, area->y);
5291 gint max_y = MAX (0, area->y + area->height);
5294 gdk_window_get_size (text->text_area, NULL, &height);
5295 max_y = MIN (max_y, height);
5297 TDEBUG (("in expose x=%d y=%d w=%d h=%d\n", area->x, area->y, area->width, area->height));
5299 clear_area (text, area);
5301 for (; pixels < height; cache = cache->next)
5303 if (pixels < max_y && (pixels + (gint)LINE_HEIGHT(CACHE_DATA(cache))) >= min_y)
5305 draw_line (text, pixels, &CACHE_DATA(cache));
5307 if (CACHE_DATA(cache).wraps)
5308 draw_line_wrap (text, pixels + CACHE_DATA(cache).font_ascent);
5311 if (cursor && GTK_WIDGET_HAS_FOCUS (text))
5313 if (CACHE_DATA(cache).start.index <= text->cursor_mark.index &&
5314 CACHE_DATA(cache).end.index >= text->cursor_mark.index)
5316 /* We undraw and draw the cursor here to get the drawn
5317 * level right ... FIXME - maybe the second parameter
5318 * of draw_cursor should work differently
5320 undraw_cursor (text, FALSE);
5321 draw_cursor (text, FALSE);
5325 pixels += LINE_HEIGHT(CACHE_DATA(cache));
5329 fetch_lines_forward (text, 1);
5338 gtk_text_update_text (GtkOldEditable *old_editable,
5342 GtkText *text = GTK_TEXT (old_editable);
5344 GList *cache = text->line_start_cache;
5345 gint pixels = - text->first_cut_pixels;
5351 end_pos = TEXT_LENGTH (text);
5353 if (end_pos < start_pos)
5356 gdk_window_get_size (text->text_area, &width, &height);
5362 TDEBUG (("in expose span start=%d stop=%d\n", start_pos, end_pos));
5364 for (; pixels < height; cache = cache->next)
5366 if (CACHE_DATA(cache).start.index < end_pos)
5368 if (CACHE_DATA(cache).end.index >= start_pos)
5371 area.y = MAX(0,pixels);
5372 area.height = pixels + LINE_HEIGHT(CACHE_DATA(cache)) - area.y;
5378 pixels += LINE_HEIGHT(CACHE_DATA(cache));
5382 fetch_lines_forward (text, 1);
5390 expose_text (text, &area, TRUE);
5394 recompute_geometry (GtkText* text)
5396 GtkPropertyMark mark, start_mark;
5403 mark = start_mark = set_vertical_scroll (text);
5405 /* We need a real start of a line when calling fetch_lines().
5406 * not the start of a wrapped line.
5408 while (mark.index > 0 &&
5409 GTK_TEXT_INDEX (text, mark.index - 1) != LINE_DELIM)
5410 decrement_mark (&mark);
5412 gdk_window_get_size (text->text_area, &width, &height);
5414 /* Fetch an entire line, to make sure that we get all the text
5415 * we backed over above, in addition to enough text to fill up
5416 * the space vertically
5419 new_lines = fetch_lines (text,
5425 mark = CACHE_DATA (g_list_last (new_lines)).end;
5426 if (!LAST_INDEX (text, mark))
5428 advance_mark (&mark);
5430 new_lines = g_list_concat (new_lines,
5435 height + text->first_cut_pixels));
5438 /* Now work forward to the actual first onscreen line */
5440 while (CACHE_DATA (new_lines).start.index < start_mark.index)
5441 new_lines = new_lines->next;
5443 text->line_start_cache = new_lines;
5445 find_cursor (text, TRUE);
5448 /**********************************************************************/
5450 /**********************************************************************/
5453 gtk_text_set_selection (GtkOldEditable *old_editable,
5457 GtkText *text = GTK_TEXT (old_editable);
5459 guint start1, end1, start2, end2;
5462 end = TEXT_LENGTH (text);
5464 start1 = MIN(start,end);
5465 end1 = MAX(start,end);
5466 start2 = MIN(old_editable->selection_start_pos, old_editable->selection_end_pos);
5467 end2 = MAX(old_editable->selection_start_pos, old_editable->selection_end_pos);
5469 if (start2 < start1)
5473 tmp = start1; start1 = start2; start2 = tmp;
5474 tmp = end1; end1 = end2; end2 = tmp;
5477 undraw_cursor (text, FALSE);
5478 old_editable->selection_start_pos = start;
5479 old_editable->selection_end_pos = end;
5480 draw_cursor (text, FALSE);
5482 /* Expose only what changed */
5484 if (start1 < start2)
5485 gtk_text_update_text (old_editable, start1, MIN(end1, start2));
5488 gtk_text_update_text (old_editable, MAX(end1, start2), end2);
5489 else if (end2 < end1)
5490 gtk_text_update_text (old_editable, end2, end1);
5494 /**********************************************************************/
5496 /**********************************************************************/
5498 #ifdef DEBUG_GTK_TEXT
5500 gtk_text_show_cache_line (GtkText *text, GList *cache,
5501 const char* what, const char* func, gint line)
5503 LineParams *lp = &CACHE_DATA(cache);
5506 if (cache == text->line_start_cache)
5507 g_message ("Line Start Cache: ");
5509 if (cache == text->current_line)
5510 g_message("Current Line: ");
5512 g_message ("%s:%d: cache line %s s=%d,e=%d,lh=%d (",
5520 for (i = lp->start.index; i < (lp->end.index + lp->wraps); i += 1)
5521 g_message ("%c", GTK_TEXT_INDEX (text, i));
5527 gtk_text_show_cache (GtkText *text, const char* func, gint line)
5529 GList *l = text->line_start_cache;
5535 /* back up to the absolute beginning of the line cache */
5539 g_message ("*** line cache ***\n");
5540 for (; l; l = l->next)
5541 gtk_text_show_cache_line (text, l, "all", func, line);
5545 gtk_text_assert_mark (GtkText *text,
5546 GtkPropertyMark *mark,
5547 GtkPropertyMark *before,
5548 GtkPropertyMark *after,
5553 GtkPropertyMark correct_mark = find_mark (text, mark->index);
5555 if (mark->offset != correct_mark.offset ||
5556 mark->property != correct_mark.property)
5557 g_warning ("incorrect %s text property marker in %s:%d, index %d -- bad!", where, msg, line, mark->index);
5561 gtk_text_assert (GtkText *text,
5565 GList* cache = text->line_start_cache;
5566 GtkPropertyMark* before_mark = NULL;
5567 GtkPropertyMark* after_mark = NULL;
5569 gtk_text_show_props (text, msg, line);
5571 for (; cache->prev; cache = cache->prev)
5574 g_message ("*** line markers ***\n");
5576 for (; cache; cache = cache->next)
5578 after_mark = &CACHE_DATA(cache).end;
5579 gtk_text_assert_mark (text, &CACHE_DATA(cache).start, before_mark, after_mark, msg, "start", line);
5580 before_mark = &CACHE_DATA(cache).start;
5583 after_mark = &CACHE_DATA(cache->next).start;
5587 gtk_text_assert_mark (text, &CACHE_DATA(cache).end, before_mark, after_mark, msg, "end", line);
5588 before_mark = &CACHE_DATA(cache).end;
5593 gtk_text_show_adj (GtkText *text,
5599 g_message ("*** adjustment ***\n");
5601 g_message ("%s:%d: %s adjustment l=%.1f u=%.1f v=%.1f si=%.1f pi=%.1f ps=%.1f\n",
5608 adj->step_increment,
5609 adj->page_increment,
5614 gtk_text_show_props (GtkText *text,
5618 GList* props = text->text_properties;
5621 g_message ("%s:%d: ", msg, line);
5623 for (; props; props = props->next)
5625 TextProperty *p = (TextProperty*)props->data;
5627 proplen += p->length;
5629 g_message ("[%d,%p,", p->length, p);
5630 if (p->flags & PROPERTY_FONT)
5631 g_message ("%p,", p->font);
5634 if (p->flags & PROPERTY_FOREGROUND)
5635 g_message ("%ld, ", p->fore_color.pixel);
5638 if (p->flags & PROPERTY_BACKGROUND)
5639 g_message ("%ld] ", p->back_color.pixel);
5646 if (proplen - 1 != TEXT_LENGTH(text))
5647 g_warning ("incorrect property list length in %s:%d -- bad!", msg, line);